0.0.8 • Published 2 years ago

@aries-markets/aries-tssdk v0.0.8

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 years ago

SDK for Aptos Node API BY Aries Market

Discord

Aries Market

Quickstart

To start building, run below command in your project directory:

yarn add @aries-markets/aries-tssdk

If you are using the types in a commonjs module, like in a Node app, you just have to enable esModuleInterop and allowSyntheticDefaultImports in your tsconfig for types compatibility:

{
  	// ...
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
    // ...
  }
}

Usage

With Aries SDK, you can directly interact with aptos blockchain without worried about type compatibility.

The SDK Instance is extreamly well-typed, consumable for frontend, There's type defination in the idl directory that is generated from the aptos blockchain source code, which is written in move.

  • To get the SDK Instance, you need to provide two parameters:

    client:

    const nodeUrl = 'https://fullnode.mainnet.aptoslabs.com/v1';
    const client = new AptosClient(nodeUrl, { WITH_CREDENTIALS: false });

    program: program address start with '0x'

  • Now you can get the SDK instance:

    import { getAriesSDK } from '@aries-markets/aries-tssdk';
    
    const sdk = getAriesSDK(client, program);
  • There're several main usage with the sdk you've got

    1. fetch the reserves

      const reservesTable = await sdk.reserve.Reserves.fetch.fromProgram();

      you may need some extra operations to get the desired data structure:

      export const targetCoins = [
        ['0x1::aptos_coin::AptosCoin', 'aptos']
      ];
      
      const res = await reservesTable.stats.fromKeys(
              targetCoins.map(([coin]) => {
                const [address, module, struct] = coin.split('::');
                return {
                  module,
                  keyStructName: struct,
                  address,
                };
              }),
            );
      
      const reserves =  res.map(i => ({
        coinAddress: typeInfoToStr(i.key),
        ...i.value,
      }));
    2. fetch profileDetail

      • fetch Profile with profileAdress

        const res = await sdk.profile.Profile.fetch.fromAddress(
          profileAddress,
        );
      • then you can get your deposits and loans

            const rawDeposits = await res.depositedReserves.fetch();
            const rawLoans = await res.borrowedReserves.fetch();
    3. fetch profiles

      • fetch all of your profiles base on the wallet

        const res = await sdk.profile.Profiles.fetch.fromWallet();
      • map the result to desired data structure

        const list = res.profileSigners.map(v => ({
                  profileName: v.key.replace('profile', ''),
                  address: v.value.account,
                }));
    4. basic transactions

      • get the controller object, which can be used to addReserve, registerUser, deposit, withdraw, borrow, swap, etc.

        const controller = sdk.controller;
      • addReserve

        .addReserve({
            Coin0: coinAddress,
        });
      • registerUser:

        sdk.controller.registerUser({
          default_profile_name: profileName,
        });
      • addProfile/Acount

        sdk.controller.addSubaccount({ profile_name: profileName });
      • Basic transaction, take deposit as an example

        controller.deposit(
              {
                amount: lamports, // Big Type in big.js
                profile_name: 'profile name',
                repay_only: false,
              },
              { Coin0: coinAddress },
        );

Requirements

yarn install

References