Skip to content

Commit 82371ca

Browse files
committed
remove dependency add type
1 parent b2cdc9e commit 82371ca

File tree

11 files changed

+148
-25
lines changed

11 files changed

+148
-25
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Wallet } from '@project-serum/anchor';
2+
import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes';
3+
import { TOKEN_PROGRAM_ID, Token } from '@solana/spl-token';
4+
import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
5+
6+
export const airDropSol = async (connection: Connection, publicKey: PublicKey, amount = 1) => {
7+
try {
8+
const airdropSignature = await connection.requestAirdrop(publicKey, amount * LAMPORTS_PER_SOL);
9+
const latestBlockHash = await connection.getLatestBlockhash();
10+
await connection.confirmTransaction({
11+
blockhash: latestBlockHash.blockhash,
12+
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
13+
signature: airdropSignature,
14+
});
15+
} catch (error) {
16+
console.error(error);
17+
throw error;
18+
}
19+
};
20+
21+
export const getOrCreateATA = async (connection: Connection, mint: PublicKey, owner: PublicKey, payer: Keypair) => {
22+
const token = new Token(connection, mint, TOKEN_PROGRAM_ID, payer);
23+
const ata = await token.getOrCreateAssociatedAccountInfo(owner);
24+
25+
return ata.address;
26+
};
27+
28+
export const mockWallet = new Wallet(
29+
process.env.WALLET_PRIVATE_KEY ? Keypair.fromSecretKey(bs58.decode(process.env.WALLET_PRIVATE_KEY)) : new Keypair(),
30+
);
31+
32+
export const MAINNET = {
33+
connection: new Connection(process.env.MAINNET_RPC_ENDPOINT as string),
34+
cluster: 'mainnet-beta',
35+
};
36+
37+
export const DEVNET = {
38+
connection: new Connection('https://api.devnet.solana.com/', {
39+
commitment: 'confirmed',
40+
}),
41+
cluster: 'devnet',
42+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Wallet } from '@project-serum/anchor';
2+
import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes';
3+
import { TOKEN_PROGRAM_ID, Token } from '@solana/spl-token';
4+
import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
5+
6+
export const airDropSol = async (connection: Connection, publicKey: PublicKey, amount = 1) => {
7+
try {
8+
const airdropSignature = await connection.requestAirdrop(publicKey, amount * LAMPORTS_PER_SOL);
9+
const latestBlockHash = await connection.getLatestBlockhash();
10+
await connection.confirmTransaction({
11+
blockhash: latestBlockHash.blockhash,
12+
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
13+
signature: airdropSignature,
14+
});
15+
} catch (error) {
16+
console.error(error);
17+
throw error;
18+
}
19+
};
20+
21+
export const getOrCreateATA = async (connection: Connection, mint: PublicKey, owner: PublicKey, payer: Keypair) => {
22+
const token = new Token(connection, mint, TOKEN_PROGRAM_ID, payer);
23+
const ata = await token.getOrCreateAssociatedAccountInfo(owner);
24+
25+
return ata.address;
26+
};
27+
28+
export const mockWallet = new Wallet(
29+
process.env.WALLET_PRIVATE_KEY ? Keypair.fromSecretKey(bs58.decode(process.env.WALLET_PRIVATE_KEY)) : new Keypair(),
30+
);
31+
32+
export const MAINNET = {
33+
connection: new Connection(process.env.MAINNET_RPC_ENDPOINT as string),
34+
cluster: 'mainnet-beta',
35+
};
36+
37+
export const DEVNET = {
38+
connection: new Connection('https://api.devnet.solana.com/', {
39+
commitment: 'confirmed',
40+
}),
41+
cluster: 'devnet',
42+
};
43+

ts-client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Discord: https://discord.com/channels/841152225564950528/864859354335412224
2222
1. Install deps
2323

2424
```
25-
npm i @mercurial-finance/dynamic-amm-sdk @project-serum/anchor @solana/web3.js @solana/spl-token @solana/spl-token-registry
25+
npm i @mercurial-finance/dynamic-amm-sdk @project-serum/anchor @solana/web3.js @solana/spl-token
2626
```
2727

2828
2. Initialize AmmImpl instance

ts-client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@saberhq/stableswap-sdk": "1.13.32",
2121
"@saberhq/token-utils": "1.13.32",
2222
"@solana/spl-token": "0.1.8",
23-
"@solana/spl-token-registry": "0.2.1105",
2423
"@solana/web3.js": "^1.42.0",
2524
"bn-sqrt": "^1.0.0",
2625
"bn.js": "5.2.1",

ts-client/pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts-client/src/amm/constants.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ENV, TokenInfo } from '@solana/spl-token-registry';
21
import { PublicKey } from '@solana/web3.js';
32
import { BN } from 'bn.js';
3+
import { TokenInfo } from './types';
44

55
export const ERROR = {
66
POOL_NOT_LOAD: 'Pool not loaded',
@@ -12,7 +12,7 @@ export const PROGRAM_ID = 'Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB';
1212

1313
export const DEVNET_COIN: Array<TokenInfo> = [
1414
{
15-
chainId: ENV.Devnet,
15+
chainId: 103,
1616
address: 'So11111111111111111111111111111111111111112',
1717
decimals: 9,
1818
name: 'Wrapped SOL',
@@ -27,7 +27,7 @@ export const DEVNET_COIN: Array<TokenInfo> = [
2727
},
2828
},
2929
{
30-
chainId: ENV.Devnet,
30+
chainId: 103,
3131
address: 'zVzi5VAf4qMEwzv7NXECVx5v2pQ7xnqVVjCXZwS9XzA',
3232
decimals: 6,
3333
name: 'USD Coin',
@@ -41,7 +41,7 @@ export const DEVNET_COIN: Array<TokenInfo> = [
4141
},
4242
},
4343
{
44-
chainId: ENV.Devnet,
44+
chainId: 103,
4545
address: '9NGDi2tZtNmCCp8SVLKNuGjuWAVwNF3Vap5tT8km5er9',
4646
decimals: 9,
4747
name: 'USDT',
@@ -56,7 +56,7 @@ export const DEVNET_COIN: Array<TokenInfo> = [
5656
},
5757
},
5858
{
59-
chainId: ENV.Devnet,
59+
chainId: 103,
6060
address: 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So',
6161
decimals: 9,
6262
symbol: 'mSOL',

ts-client/src/amm/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
SystemProgram,
1313
ComputeBudgetProgram,
1414
} from '@solana/web3.js';
15-
import { TokenInfo } from '@solana/spl-token-registry';
1615
import {
1716
AccountLayout,
1817
ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -31,6 +30,7 @@ import {
3130
DepositQuote,
3231
PoolInformation,
3332
PoolState,
33+
TokenInfo,
3434
VaultProgram,
3535
WithdrawQuote,
3636
} from './types';

ts-client/src/amm/tests/index.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { AnchorProvider, BN } from '@project-serum/anchor';
2-
import { TokenInfo, TokenListProvider } from '@solana/spl-token-registry';
32
import { Cluster, Keypair, PublicKey } from '@solana/web3.js';
43
import { DEFAULT_SLIPPAGE, DEVNET_COIN, DEVNET_POOL, MAINNET_POOL } from '../constants';
54
import AmmImpl from '../index';
65
import { calculateSwapQuote, getOnchainTime } from '../utils';
7-
import { DEVNET, MAINNET, airDropSol, getOrCreateATA, mockWallet } from './utils';
6+
import { DEVNET, MAINNET, airDropSol, getOrCreateATA, getValidatedTokens, mockWallet } from './utils';
87
import { NATIVE_MINT } from '@solana/spl-token';
8+
import { TokenInfo } from '../types';
99

1010
describe('Interact with Devnet pool', () => {
1111
const provider = new AnchorProvider(DEVNET.connection, mockWallet, {
@@ -676,10 +676,9 @@ describe('Staging pool', () => {
676676
const jitoSolDepegPool = new PublicKey('HcHN59j1xArjLuqfCMJ96yJ2CKatxHMFABEZWvcfPrYZ');
677677

678678
beforeAll(async () => {
679-
const tokenMap = await new TokenListProvider().resolve().then((tokens) => {
680-
return tokens.filterByClusterSlug('mainnet-beta').getList();
681-
});
682-
const SOL = tokenMap.find((token) => token.address === 'So11111111111111111111111111111111111111112');
679+
const tokenList = await getValidatedTokens();
680+
681+
const SOL = tokenList.find((token) => token.address === 'So11111111111111111111111111111111111111112');
683682
const jitoSOL: TokenInfo = {
684683
chainId: SOL!.chainId,
685684
address: 'J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn',
@@ -724,13 +723,12 @@ describe('Interact with Mainnet pool', () => {
724723
let depegPool: AmmImpl;
725724

726725
beforeAll(async () => {
727-
const tokenListContainer = await new TokenListProvider().resolve();
728-
const tokenMap = tokenListContainer.filterByClusterSlug(MAINNET.cluster).getList();
726+
const tokenList = await getValidatedTokens();
729727

730-
const USDT = tokenMap.find((token) => token.address === 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB');
731-
const USDC = tokenMap.find((token) => token.address === 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
732-
const SOL = tokenMap.find((token) => token.address === 'So11111111111111111111111111111111111111112');
733-
const STSOL = tokenMap.find((token) => token.address === '7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj');
728+
const USDT = tokenList.find((token) => token.address === 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB');
729+
const USDC = tokenList.find((token) => token.address === 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
730+
const SOL = tokenList.find((token) => token.address === 'So11111111111111111111111111111111111111112');
731+
const STSOL = tokenList.find((token) => token.address === '7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj');
734732

735733
const pools = [
736734
{ pool: MAINNET_POOL.USDC_SOL, tokenInfoA: USDC!, tokenInfoB: SOL! },

ts-client/src/amm/tests/utils/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Wallet } from '@project-serum/anchor';
22
import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes';
33
import { TOKEN_PROGRAM_ID, Token } from '@solana/spl-token';
44
import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
5+
import { TokenInfo } from '../../types';
56

67
export const airDropSol = async (connection: Connection, publicKey: PublicKey, amount = 1) => {
78
try {
@@ -40,3 +41,17 @@ export const DEVNET = {
4041
}),
4142
cluster: 'devnet',
4243
};
44+
45+
export async function getValidatedTokens(): Promise<TokenInfo[]> {
46+
try {
47+
const tokensList: TokenInfo[] = [];
48+
const data = await fetch(`https://token.jup.ag/strict`)
49+
const tokens = await data.json()
50+
tokens.forEach((token: TokenInfo) => {
51+
tokensList.push(token);
52+
});
53+
return tokensList;
54+
} catch (error: any) {
55+
throw new Error("Failed to fetch validated tokens");
56+
}
57+
};

ts-client/src/amm/types/index.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AccountInfo, PublicKey, Transaction } from '@solana/web3.js';
2-
import { TokenInfo } from '@solana/spl-token-registry';
32
import { IdlAccounts, IdlTypes, Program } from '@project-serum/anchor';
43
import BN from 'bn.js';
54
import { Amm as AmmIdl } from '../idl';
@@ -10,6 +9,36 @@ import { publicKey, struct, u64, u8, option } from '@project-serum/borsh';
109
export type AmmProgram = Program<AmmIdl>;
1110
export type VaultProgram = Program<VaultIdl>;
1211

12+
export interface TokenExtensions {
13+
readonly website?: string;
14+
readonly bridgeContract?: string;
15+
readonly assetContract?: string;
16+
readonly address?: string;
17+
readonly explorer?: string;
18+
readonly twitter?: string;
19+
readonly github?: string;
20+
readonly medium?: string;
21+
readonly tgann?: string;
22+
readonly tggroup?: string;
23+
readonly discord?: string;
24+
readonly serumV3Usdt?: string;
25+
readonly serumV3Usdc?: string;
26+
readonly coingeckoId?: string;
27+
readonly imageUrl?: string;
28+
readonly description?: string;
29+
}
30+
31+
export interface TokenInfo {
32+
address: string;
33+
chainId: number;
34+
name: string;
35+
symbol: string;
36+
decimals: number;
37+
logoURI?: string;
38+
tags?: string[];
39+
extensions?: TokenExtensions;
40+
}
41+
1342
export interface AmmImplementation {
1443
tokenA: TokenInfo;
1544
tokenB: TokenInfo;

0 commit comments

Comments
 (0)