cro-sdk v1.2.10
Cro SDK
Overview
cro-sdk
is a TypeScript SDK for interacting with the CroAg platform. It provides a comprehensive set of features for fetching APY data, managing user portfolios, and performing deposit and withdrawal operations.
Installation
You can install the SDK via npm:
npm install cro-sdk
Usage Example
Import the SDK
import { CroAgSDK, ApyType, ProjectType } from 'cro-sdk'
Initialize the SDK
const sdk = new CroAgSDK()
console.log(ApyType, ProjectType)
Fetch and Deposit APY Data
async function processApyData() {
const apyData = await sdk.getApyList(ApyType.LST, ProjectType.KAI_FINANCE)
console.log(apyData)
for (const route of apyData) {
try {
const tx = await sdk.croDeposit(
route,
'SUI',
2000000000n,
'0x39dfa26ecaf49a466cfe33b2e98de9b46425eec170e59eb40d3f69d061a67778'
)
if (tx) console.log(tx.getData().commands)
await delay()
} catch (e) {
console.log(route)
console.error(e)
}
}
}
Fetch User Portfolios and Withdraw Funds
async function fetchAndWithdrawPortfolios() {
const portfolios = await sdk.fetchAllPortfolios(
'0xd9b5fd53db6e06982dcaa74bb91f22eb82a199114a7f5e2a3c4aa3d3e80a5b27'
)
console.log(portfolios)
if (portfolios != null) {
for (const asset of portfolios) {
console.log(asset)
const tx = await sdk.croWithdraw(asset, asset.totalBalance)
if (tx) console.log(tx.getData().commands)
}
}
}
Get Zero Objects and Mint
async function handleZeroObjects() {
const objects = await sdk.get_zero_objs(
'0x40b09505573010ecfcbcb3c781f2bf52a0951710ce77df6d14663fd6ec686dfa'
)
console.log(objects)
const tx = await sdk.zero_obj_mint(objects)
if (tx) console.log(tx.getData().commands)
}
Get Swap Routers and Coin Information
async function getSwapRouters() {
const routers = await sdk.getSwapRouters(
'SUI',
'0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',
BigInt(1000000000000)
)
console.log(routers)
}
async function getCoin() {
console.log(await sdk.getCoinsShow())
console.log(await sdk.getCoinByType('SUI'))
}
API Reference
Enums
ApyType
DEFAULT
- Default typeDEFI
- Decentralized FinanceLST
- Liquidity StakingSTABLECOINS
- Stablecoins
ProjectType
DEFAULT
- Default projectNAVI_LENDING
- Navi LendingSCALLOP_LEND
- Scallop LendingKAI_FINANCE
- Kai Finance
Interfaces
ApyData
Property Type Description apy string Annual Percentage Yield coin_type string Coin type id number Unique identifier name string Name navi_pool_config_name string | null Navi pool configuration name navi_symbol string | null Navi symbol project string Project name symbol string Symbol tvl_usd string Total Value Locked (USD) type string Type update_time string Update time CroPortfolio
Property Type Description owner string Owner platform string Platform coinType string Coin type totalBalance bigint Total balance coinMetadata any Coin metadata Coin
Property Type Description type string Coin type name string Coin name symbol string Coin symbol decimals number Number of decimals iconUrl string URL to coin icon
Class
CroAgSDK
getApyList(type?: ApyType, project?: ProjectType, single?: boolean): Promise<ApyData[]>
croDeposit(apyData: ApyData, type_in: string, amount_in: bigint, address: string, referral?: string): Promise<Transaction | null>
fetchAllPortfolios(address: string): Promise<CroPortfolio[] | null>
getNaviPortfolio(address: string): Promise<CroPortfolio[] | null>
getScaPortfolio(address: string): Promise<CroPortfolio[] | null>
getKaiPortfolio(address: string): Promise<CroPortfolio[] | null>
croWithdraw(portfolio: CroPortfolio, amount: bigint, referral?: string): Promise<Transaction | null>
get_zero_objs(address: string): Promise<CoinStruct[]>
zero_obj_mint(objects: CoinStruct[]): Promise<Transaction | null>
getSwapRouters(from: string, target: string, amount_in: bigint): Promise<RouterData | null>
swap(tx: Transaction, from: string, target: string, inputCoin: any, amount_in: bigint): Promise<TransactionObjectArgument | null>
swapAndTransfer(tx: Transaction, from: string, target: string, inputCoin: any, amount_in: bigint, address: string): Promise<Transaction | null>
getCoinsShow(): Promise<Coin[] | null>
getCoinByType(coinType: string): Promise<Coin | null>
mint_nft(address: string, referral_address?: string): Promise<Transaction | null>
referral_mint_nft(address: string, referral_address: string): Promise<Transaction | null>
add_points(address: string, nftId: string, amount: bigint): Promise<Transaction | null>
remove_points(address: string, nftId: string, amount: bigint): Promise<Transaction | null>
claim_cro(address: string, nftId: string): Promise<Transaction | null>
getOwnedNft(address: string): Promise<string | null>
getTop(): Promise<LeaderboardEntry[]>
getRank(address: string): Promise<RankResponse>
getBalanceByType(owner: string, coinType: string): Promise<Balance>
stake(address: string, amount: bigint): Promise<Transaction | null>
unstake(address: string, amount: bigint): Promise<Transaction | null>
loan(tx: Transaction, coinType: string, amount: bigint): Promise<{ tx: Transaction; receipt: any; coin_loan: any }>
repay(tx: Transaction, address: string, coinType: string, coin_repay: any, receipt: any): Promise<Transaction>
Contributing
We welcome issues and pull requests! Please refer to the Contributing Guide.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Enhanced Class Methods
The CroAgSDK
class has been updated with new methods for additional functionalities, allowing for greater flexibility and additional operations within the SDK.
This updated README now accurately reflects the methods and parameters introduced in the `CroAgSDK` class, providing users with a clear understanding of how to use the SDK and its functionalities.
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago