diff --git a/ts-client/README.md b/ts-client/README.md index ba8baa54..1ac65d76 100644 --- a/ts-client/README.md +++ b/ts-client/README.md @@ -22,7 +22,7 @@ Discord: https://discord.com/channels/841152225564950528/864859354335412224 1. Install deps ``` -npm i @mercurial-finance/dynamic-amm-sdk @project-serum/anchor @solana/web3.js @solana/spl-token @solana/spl-token-registry +npm i @mercurial-finance/dynamic-amm-sdk @project-serum/anchor @solana/web3.js @solana/spl-token ``` 2. Initialize AmmImpl instance diff --git a/ts-client/package.json b/ts-client/package.json index 9e314148..e6f56533 100644 --- a/ts-client/package.json +++ b/ts-client/package.json @@ -20,7 +20,6 @@ "@saberhq/stableswap-sdk": "1.13.32", "@saberhq/token-utils": "1.13.32", "@solana/spl-token": "0.1.8", - "@solana/spl-token-registry": "0.2.1105", "@solana/web3.js": "^1.42.0", "bn-sqrt": "^1.0.0", "bn.js": "5.2.1", diff --git a/ts-client/pnpm-lock.yaml b/ts-client/pnpm-lock.yaml index 921f82cc..89ba541c 100644 --- a/ts-client/pnpm-lock.yaml +++ b/ts-client/pnpm-lock.yaml @@ -26,9 +26,6 @@ dependencies: '@solana/spl-token': specifier: 0.1.8 version: 0.1.8 - '@solana/spl-token-registry': - specifier: 0.2.1105 - version: 0.2.1105 '@solana/web3.js': specifier: ^1.42.0 version: 1.75.0 diff --git a/ts-client/src/amm/constants.ts b/ts-client/src/amm/constants.ts index b187765e..8f5d2d75 100644 --- a/ts-client/src/amm/constants.ts +++ b/ts-client/src/amm/constants.ts @@ -1,6 +1,6 @@ -import { ENV, TokenInfo } from '@solana/spl-token-registry'; import { PublicKey } from '@solana/web3.js'; import { BN } from 'bn.js'; +import { TokenInfo } from './types'; export const ERROR = { POOL_NOT_LOAD: 'Pool not loaded', @@ -12,7 +12,7 @@ export const PROGRAM_ID = 'Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB'; export const DEVNET_COIN: Array = [ { - chainId: ENV.Devnet, + chainId: 103, address: 'So11111111111111111111111111111111111111112', decimals: 9, name: 'Wrapped SOL', @@ -27,7 +27,7 @@ export const DEVNET_COIN: Array = [ }, }, { - chainId: ENV.Devnet, + chainId: 103, address: 'zVzi5VAf4qMEwzv7NXECVx5v2pQ7xnqVVjCXZwS9XzA', decimals: 6, name: 'USD Coin', @@ -41,7 +41,7 @@ export const DEVNET_COIN: Array = [ }, }, { - chainId: ENV.Devnet, + chainId: 103, address: '9NGDi2tZtNmCCp8SVLKNuGjuWAVwNF3Vap5tT8km5er9', decimals: 9, name: 'USDT', @@ -56,7 +56,7 @@ export const DEVNET_COIN: Array = [ }, }, { - chainId: ENV.Devnet, + chainId: 103, address: 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So', decimals: 9, symbol: 'mSOL', diff --git a/ts-client/src/amm/index.ts b/ts-client/src/amm/index.ts index 857fcc21..010a1fa4 100644 --- a/ts-client/src/amm/index.ts +++ b/ts-client/src/amm/index.ts @@ -12,7 +12,6 @@ import { SystemProgram, ComputeBudgetProgram, } from '@solana/web3.js'; -import { TokenInfo } from '@solana/spl-token-registry'; import { AccountLayout, ASSOCIATED_TOKEN_PROGRAM_ID, @@ -31,6 +30,7 @@ import { DepositQuote, PoolInformation, PoolState, + TokenInfo, VaultProgram, WithdrawQuote, } from './types'; diff --git a/ts-client/src/amm/tests/index.test.ts b/ts-client/src/amm/tests/index.test.ts index 81d4152e..0fbdc81a 100644 --- a/ts-client/src/amm/tests/index.test.ts +++ b/ts-client/src/amm/tests/index.test.ts @@ -1,11 +1,11 @@ import { AnchorProvider, BN } from '@project-serum/anchor'; -import { TokenInfo, TokenListProvider } from '@solana/spl-token-registry'; import { Cluster, Keypair, PublicKey } from '@solana/web3.js'; import { DEFAULT_SLIPPAGE, DEVNET_COIN, DEVNET_POOL, MAINNET_POOL } from '../constants'; import AmmImpl from '../index'; import { calculateSwapQuote, getOnchainTime } from '../utils'; -import { DEVNET, MAINNET, airDropSol, getOrCreateATA, mockWallet } from './utils'; +import { DEVNET, MAINNET, airDropSol, getOrCreateATA, getValidatedTokens, mockWallet } from './utils'; import { NATIVE_MINT } from '@solana/spl-token'; +import { TokenInfo } from '../types'; describe('Interact with Devnet pool', () => { const provider = new AnchorProvider(DEVNET.connection, mockWallet, { @@ -676,10 +676,9 @@ describe('Staging pool', () => { const jitoSolDepegPool = new PublicKey('HcHN59j1xArjLuqfCMJ96yJ2CKatxHMFABEZWvcfPrYZ'); beforeAll(async () => { - const tokenMap = await new TokenListProvider().resolve().then((tokens) => { - return tokens.filterByClusterSlug('mainnet-beta').getList(); - }); - const SOL = tokenMap.find((token) => token.address === 'So11111111111111111111111111111111111111112'); + const tokenList = await getValidatedTokens(); + + const SOL = tokenList.find((token) => token.address === 'So11111111111111111111111111111111111111112'); const jitoSOL: TokenInfo = { chainId: SOL!.chainId, address: 'J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn', @@ -724,13 +723,12 @@ describe('Interact with Mainnet pool', () => { let depegPool: AmmImpl; beforeAll(async () => { - const tokenListContainer = await new TokenListProvider().resolve(); - const tokenMap = tokenListContainer.filterByClusterSlug(MAINNET.cluster).getList(); + const tokenList = await getValidatedTokens(); - const USDT = tokenMap.find((token) => token.address === 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'); - const USDC = tokenMap.find((token) => token.address === 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'); - const SOL = tokenMap.find((token) => token.address === 'So11111111111111111111111111111111111111112'); - const STSOL = tokenMap.find((token) => token.address === '7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj'); + const USDT = tokenList.find((token) => token.address === 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'); + const USDC = tokenList.find((token) => token.address === 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'); + const SOL = tokenList.find((token) => token.address === 'So11111111111111111111111111111111111111112'); + const STSOL = tokenList.find((token) => token.address === '7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj'); const pools = [ { pool: MAINNET_POOL.USDC_SOL, tokenInfoA: USDC!, tokenInfoB: SOL! }, diff --git a/ts-client/src/amm/tests/utils/index.ts b/ts-client/src/amm/tests/utils/index.ts index 80728a41..b75a893d 100644 --- a/ts-client/src/amm/tests/utils/index.ts +++ b/ts-client/src/amm/tests/utils/index.ts @@ -2,6 +2,7 @@ import { Wallet } from '@project-serum/anchor'; import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes'; import { TOKEN_PROGRAM_ID, Token } from '@solana/spl-token'; import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'; +import { TokenInfo } from '../../types'; export const airDropSol = async (connection: Connection, publicKey: PublicKey, amount = 1) => { try { @@ -40,3 +41,17 @@ export const DEVNET = { }), cluster: 'devnet', }; + +export async function getValidatedTokens(): Promise { + try { + const tokensList: TokenInfo[] = []; + const data = await fetch(`https://token.jup.ag/strict`) + const tokens = await data.json() + tokens.forEach((token: TokenInfo) => { + tokensList.push(token); + }); + return tokensList; + } catch (error: any) { + throw new Error("Failed to fetch validated tokens"); + } +}; \ No newline at end of file diff --git a/ts-client/src/amm/types/index.ts b/ts-client/src/amm/types/index.ts index 0a2d7853..0abd6a35 100644 --- a/ts-client/src/amm/types/index.ts +++ b/ts-client/src/amm/types/index.ts @@ -1,5 +1,4 @@ import { AccountInfo, PublicKey, Transaction } from '@solana/web3.js'; -import { TokenInfo } from '@solana/spl-token-registry'; import { IdlAccounts, IdlTypes, Program } from '@project-serum/anchor'; import BN from 'bn.js'; import { Amm as AmmIdl } from '../idl'; @@ -10,6 +9,36 @@ import { publicKey, struct, u64, u8, option } from '@project-serum/borsh'; export type AmmProgram = Program; export type VaultProgram = Program; +export interface TokenExtensions { + readonly website?: string; + readonly bridgeContract?: string; + readonly assetContract?: string; + readonly address?: string; + readonly explorer?: string; + readonly twitter?: string; + readonly github?: string; + readonly medium?: string; + readonly tgann?: string; + readonly tggroup?: string; + readonly discord?: string; + readonly serumV3Usdt?: string; + readonly serumV3Usdc?: string; + readonly coingeckoId?: string; + readonly imageUrl?: string; + readonly description?: string; +} + +export interface TokenInfo { + address: string; + chainId: number; + name: string; + symbol: string; + decimals: number; + logoURI?: string; + tags?: string[]; + extensions?: TokenExtensions; +} + export interface AmmImplementation { tokenA: TokenInfo; tokenB: TokenInfo; diff --git a/ts-client/src/amm/utils.ts b/ts-client/src/amm/utils.ts index 30eae345..711788eb 100644 --- a/ts-client/src/amm/utils.ts +++ b/ts-client/src/amm/utils.ts @@ -51,10 +51,10 @@ import { StableSwapCurve, SwapQuoteParam, SwapResult, + TokenInfo, TokenMultiplier, } from './types'; import { Amm as AmmIdl, IDL as AmmIDL } from './idl'; -import { TokenInfo } from '@solana/spl-token-registry'; export const createProgram = (connection: Connection, programId?: string) => { const provider = new AnchorProvider(connection, {} as any, AnchorProvider.defaultOptions());