Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on Deprecated SPL-Token Registry #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ts-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion ts-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions ts-client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions ts-client/src/amm/constants.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -12,7 +12,7 @@ export const PROGRAM_ID = 'Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB';

export const DEVNET_COIN: Array<TokenInfo> = [
{
chainId: ENV.Devnet,
chainId: 103,
address: 'So11111111111111111111111111111111111111112',
decimals: 9,
name: 'Wrapped SOL',
Expand All @@ -27,7 +27,7 @@ export const DEVNET_COIN: Array<TokenInfo> = [
},
},
{
chainId: ENV.Devnet,
chainId: 103,
address: 'zVzi5VAf4qMEwzv7NXECVx5v2pQ7xnqVVjCXZwS9XzA',
decimals: 6,
name: 'USD Coin',
Expand All @@ -41,7 +41,7 @@ export const DEVNET_COIN: Array<TokenInfo> = [
},
},
{
chainId: ENV.Devnet,
chainId: 103,
address: '9NGDi2tZtNmCCp8SVLKNuGjuWAVwNF3Vap5tT8km5er9',
decimals: 9,
name: 'USDT',
Expand All @@ -56,7 +56,7 @@ export const DEVNET_COIN: Array<TokenInfo> = [
},
},
{
chainId: ENV.Devnet,
chainId: 103,
address: 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So',
decimals: 9,
symbol: 'mSOL',
Expand Down
2 changes: 1 addition & 1 deletion ts-client/src/amm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
SystemProgram,
ComputeBudgetProgram,
} from '@solana/web3.js';
import { TokenInfo } from '@solana/spl-token-registry';
import {
AccountLayout,
ASSOCIATED_TOKEN_PROGRAM_ID,
Expand All @@ -31,6 +30,7 @@ import {
DepositQuote,
PoolInformation,
PoolState,
TokenInfo,
VaultProgram,
WithdrawQuote,
} from './types';
Expand Down
22 changes: 10 additions & 12 deletions ts-client/src/amm/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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! },
Expand Down
15 changes: 15 additions & 0 deletions ts-client/src/amm/tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -40,3 +41,17 @@ export const DEVNET = {
}),
cluster: 'devnet',
};

export async function getValidatedTokens(): Promise<TokenInfo[]> {
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");
}
};
31 changes: 30 additions & 1 deletion ts-client/src/amm/types/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,6 +9,36 @@ import { publicKey, struct, u64, u8, option } from '@project-serum/borsh';
export type AmmProgram = Program<AmmIdl>;
export type VaultProgram = Program<VaultIdl>;

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;
Expand Down
2 changes: 1 addition & 1 deletion ts-client/src/amm/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down