1.0.6 • Published 5 months ago

cro-ag-ts-sdk v1.0.6

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

CroAgSDK Documentation

Welcome to the CroAgSDK! This SDK allows you to interact with token routers and perform various operations such as swapping, depositing, and withdrawing tokens on specified platforms. Below is a guide on how to use the SDK effectively.

Installation

To get started, install the SDK via npm:

npm install cro-ag-ts-sdk

Usage

Importing the SDK

Begin by importing the CroAgSDK class in your TypeScript or JavaScript file:

import { CroAgSDK } from 'cro-ag-ts-sdk';

Initializing the SDK

You can create an instance of the SDK:

const sdk = new CroAgSDK();

Methods

1. Finding Routers

To find available routers for a given exchange, use the findRouters method:

const routers = await sdk.findRouters(fromAddress, targetAddress, amountIn, byAmountIn);
  • Parameters:

    • from: The source address (string).
    • target: The target address (string).
    • amountIn: The amount to exchange (number).
    • byAmountIn: (Optional) A boolean indicating whether to use amount in.
  • Returns: A promise that resolves to RouterData or null.

2. Swapping Tokens

To swap tokens using a router, use the routerSwap method:

const swappedCoin = await sdk.routerSwap(transaction, routerData, inputCoin, byAmountIn, slippage);
  • Parameters:

    • tx: The transaction object (Transaction).
    • routerRes: The router data obtained from findRouters.
    • inputCoin: The coin to be swapped (TransactionObjectArgument).
    • byAmountIn: (Optional) A boolean indicating whether to use amount in.
    • slippage: (Optional) Slippage tolerance (number).
  • Returns: A promise that resolves to the target coin (TransactionObjectArgument) or null.

3. Depositing Tokens

To deposit tokens into a platform, use the deposit method:

await sdk.deposit(platform, transaction, coinType, amount, coinIn);
  • Parameters:

    • platform: The platform to deposit to (string).
    • tx: The transaction object (Transaction).
    • coinType: The type of coin to deposit (string).
    • amount: The amount to deposit (number).
    • coinIn: The input coin object (TransactionObjectArgument).
  • Returns: A promise that resolves when the deposit is complete.

4. Withdrawing Tokens

To withdraw tokens from a platform, use the withdraw method:

const withdrawnCoin = await sdk.withdraw(platform, transaction, coinType, amount);
  • Parameters:

    • platform: The platform to withdraw from (string).
    • tx: The transaction object (Transaction).
    • coinType: The type of coin to withdraw (string).
    • amount: The amount to withdraw (number).
  • Returns: A promise that resolves to the target coin (TransactionObjectArgument) or null.

Examples

Example Usage

Here's a basic example demonstrating how to use the SDK:

async function main() {
    const sdk = new CroAgSDK();
    
    const routers = await sdk.findRouters('0xFromAddress', '0xTargetAddress', 1000000000, true);
    
    if (routers) {
        const tx = new Transaction(); // Your transaction object
        // const inputCoin = tx.split(tx.object('0xobjectId'), [amount]); // for coins
        const inputCoin = tx.split(tx.gas, [amount]); // for sui
        const swappedCoin = await sdk.routerSwap(transaction, routers, inputCoin, true, 0.01);
        await sdk.deposit('navi-lending', tx, 'coinType', amount, swappedCoin)

        const dry = await client.devInspectTransactionBlock({
            sender: address,
            transactionBlock: tx,
        })
        console.log(dry)

        if (dry.effects.status.status == 'success') {
            console.log(
                await client.signAndExecuteTransaction({
                    signer: keyPair,
                    transaction: tx,
                })
            )
        }
    }
}

main().catch(console.error);

Conclusion

With the CroAgSDK, you can easily manage token transactions across different platforms. Follow the methods outlined above to integrate with your application and start interacting with token routers efficiently.

For further questions or issues, please refer to the SDK's GitHub repository or contact support. Happy coding!

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago