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, performing swaps, staking, NFT management, and more.
Install the SDK via npm:
npm install cro-sdk
import { CroAgSDK, ApyType, ProjectType } from 'cro-sdk'
const sdk = new CroAgSDK()
console.log(ApyType, ProjectType)
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,
'0x2::sui::Sui',
2000000000n,
'0x...'
)
if (tx) console.log(tx.getData().commands)
await delay()
} catch (e) {
console.log(route)
console.error(e)
}
}
}
async function fetchAndWithdrawPortfolios() {
const portfolios = await sdk.fetchAllPortfolios(
'0x...'
)
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)
}
}
}
async function handleZeroObjects() {
const objects = await sdk.get_zero_objs(
'0x...'
)
console.log(objects)
const tx = await sdk.zero_obj_mint(objects)
if (tx) console.log(tx.getData().commands)
}
async function getSwapRouters() {
const routers = await sdk.getSwapRouters(
'0x2::sui::Sui',
'0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',
BigInt(1000000000000)
)
console.log(routers)
}
async function getCoin() {
console.log(await sdk.getCoinsShow())
console.log(await sdk.getCoinByType('0x2::sui::Sui'))
}
async function stakeCRO() {
const tx = await sdk.stake(
'0x...',
BigInt(100000000)
)
if (tx) console.log(tx.getData().commands)
}
async function unstakeCRO() {
const tx = await sdk.unstake(
'0x...',
BigInt(50000000)
)
if (tx) console.log(tx.getData().commands)
}
async function manageNFTs() {
const mintedNFT = await sdk.mint_nft(
'0x...'
)
if (mintedNFT) console.log(mintedNFT.getData().commands)
const referralNFT = await sdk.referral_mint_nft(
'0x...',
'0x123456789abcdef'
)
if (referralNFT) console.log(referralNFT.getData().commands)
const addPointsTx = await sdk.add_points(
'0x...',
'nftId123',
BigInt(100)
)
if (addPointsTx) console.log(addPointsTx.getData().commands)
const claimCROTx = await sdk.claim_cro(
'0x...',
'nftId123'
)
if (claimCROTx) console.log(claimCROTx.getData().commands)
}
-
ApyType
-
DEFAULT
- Default type -
DEFI
- Decentralized Finance -
LST
- Liquidity Staking -
STABLECOINS
- Stablecoins
-
-
ProjectType
-
DEFAULT
- Default project -
NAVI_LENDING
- Navi Lending -
SCALLOP_LEND
- Scallop Lending -
KAI_FINANCE
- Kai Finance
-
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 |
Property | Type | Description |
---|---|---|
owner | string | Owner |
platform | string | Platform |
coinType | string | Coin type |
totalBalance | bigint | Total balance |
coinMetadata | any | Coin metadata |
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 |
The CroAgSDK
class contains all the methods required for interacting with the platform. Below is a list of available methods:
-
APY Management
getApyList(type?: ApyType, project?: ProjectType, single?: boolean): Promise<ApyData[]>
getApyListByType(coinType: string): Promise<ApyData[]>
-
Portfolio Management
fetchAllPortfolios(address: string): Promise<CroPortfolio[] | null>
fetchApyByPlatformAndCoinType(platform: string, coinType: string): Promise<ApyData | null>
-
Deposits and Withdrawals
croDeposit(apyData: ApyData, type_in: string, amount_in: bigint, address: string, referral?: string): Promise<Transaction | null>
croWithdraw(portfolio: CroPortfolio, amount: bigint, referral?: string): Promise<Transaction | null>
-
Zero Object Management
get_zero_objs(address: string): Promise<CoinStruct[]>
zero_obj_mint(objects: CoinStruct[]): Promise<Transaction | null>
-
Swap and Coin Management
getSwapRouters(from: string, target: string, amount_in: bigint): Promise<RouterData | null>
swap(tx: Transaction, from: string, target: string, inputCoin: any, amount_in: bigint, slippage: number): Promise<TransactionObjectArgument | null>
getCoinsShow(): Promise<Coin[] | null>
getCoinByType(coinType: string): Promise<Coin | null>
-
NFT Management
mint_nft(address: string, referral_address?: string): Promise<Transaction | null>
add_points(address: string, nftId: string, amount: bigint): Promise<Transaction | null>
claim_cro(address: string, nftId: string): Promise<Transaction | null>
-
Staking
stake(address: string, amount: bigint): Promise<Transaction | null>
unstake(address: string, amount: bigint): Promise<Transaction | null>
We welcome contributions! Please refer to the Contributing Guide.
This project is licensed under the MIT License. See the LICENSE file for details.