Skip to content

10000W/tacsdk-morpho-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TAC SDK with Morpho Integration Guide

Getting Started

  1. Install @tonappchain/sdk (assuming that ethers and @tonconnect/ui are already installed):

    npm i @tonappchain/sdk
  2. Initialize TAC SDK before using its methods:

    import { Network, TacSdk } from '@tonappchain/sdk';
    
    const tacSdk = await TacSdk.create({ network: Network.MAINNET });
  3. These constants will be used throughout examples below, copy them where you see fit:

    export const IS_TESTNET = false
    export const TON_ON_TAC_ADDRESS = IS_TESTNET
      ? '0xe3a2296bE422768a630eb35014978A808D106899'
      : '0xb76d91340F5CE3577f0a056D29f6e3Eb4E88B140'
    export const MORPHO_PROXY = IS_TESTNET 
      ? '0x001e29479B3DFbaA0c371EaA5E23E157e188871d'
      : '0x21b5562FEee5013379F8F79C5093EC294d535BEC'

Operations

General

Refer to Morpho docs. Some methods are not provided in script, i.e. withdraw for partial withdrawals, but implementation is straightforward enough with TacSdk - just describe EVM method (usually with (bytes,bytes) arguments), and provide assets if they are required.

Methods

Refer to index.ts. Does not work as-is, provide tacSdk and tonConnectUI instances.

Getting Relevant Information

General

Refer to Morpho API Guide. You can retrieve a list of vaults and detailed vault information by using their own GraphQL API.

Vaults Balances

You can use Toncenter API or any other indexer/RPC to fetch jetton balances that correspond to each vault. You can check the symbols to find corresponding balances or batch the EVM-TVM address conversions (safer):

// Better to use memoization
export const convertAddresses = async () => {
   const evmAddresses: string[] = []
   const batchSize = 5
   const convertedAddresses = new Map()
   for (let i = 0; i < evmAddresses.length; i += batchSize) {
      const batch = evmAddresses.slice(i, i + batchSize)
      const results = await Promise.allSettled(batch.map(addr => tacSdk.getTVMTokenAddress(addr)))

      batch.forEach((evmAddress, idx) => {
         const res = results[idx]
         const tvm = res.status === 'fulfilled' && res.value ? res.value : 'NONE'
         convertedAddresses.set(evmAddress, tvm)
      })
   }

   return convertedAddresses
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors