1.2.10 • Published 3 months ago

cro-sdk v1.2.10

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

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 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

Interfaces

  • ApyData

    PropertyTypeDescription
    apystringAnnual Percentage Yield
    coin_typestringCoin type
    idnumberUnique identifier
    namestringName
    navi_pool_config_namestring | nullNavi pool configuration name
    navi_symbolstring | nullNavi symbol
    projectstringProject name
    symbolstringSymbol
    tvl_usdstringTotal Value Locked (USD)
    typestringType
    update_timestringUpdate time
  • CroPortfolio

    PropertyTypeDescription
    ownerstringOwner
    platformstringPlatform
    coinTypestringCoin type
    totalBalancebigintTotal balance
    coinMetadataanyCoin metadata
  • Coin

    PropertyTypeDescription
    typestringCoin type
    namestringCoin name
    symbolstringCoin symbol
    decimalsnumberNumber of decimals
    iconUrlstringURL 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.
1.2.8

4 months ago

1.2.10

3 months ago

1.1.19

4 months ago

1.2.9

4 months ago

1.2.7

4 months ago

1.2.6

4 months ago

1.2.5

4 months ago

1.2.4

4 months ago

1.2.3

4 months ago

1.2.2

4 months ago

1.2.1

4 months ago

1.1.12

4 months ago

1.1.16

4 months ago

1.1.15

4 months ago

1.1.14

4 months ago

1.1.13

4 months ago

1.1.18

4 months ago

1.1.17

4 months ago

1.1.11

4 months ago

1.1.10

4 months ago

1.1.9

4 months ago

1.1.8

4 months ago

1.1.7

4 months ago

1.1.6

4 months ago

1.1.5

4 months ago

1.1.4

4 months ago

1.1.3

4 months ago

1.1.2

4 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.0.35

4 months ago

1.0.33

4 months ago

1.0.32

4 months ago

1.0.31

4 months ago

1.0.30

4 months ago

1.0.29

4 months ago

1.0.28

4 months ago

1.0.27

4 months ago

1.0.26

4 months ago

1.0.24

4 months ago

1.0.23

4 months ago

1.0.22

4 months ago

1.0.21

4 months ago

1.0.20

4 months ago

1.0.19

4 months ago

1.0.18

4 months ago

1.0.17

4 months ago

1.0.16

4 months ago

1.0.15

4 months ago

1.0.14

4 months ago

1.0.13

4 months ago

1.0.12

4 months ago

1.0.11

4 months ago

1.0.10

4 months ago

1.0.9

4 months ago

1.0.8

4 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago