Skip to content

addition to the swap description of Tokens #24

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 27 additions & 3 deletions src/RaydiumSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,26 @@ class RaydiumSwap {
currencyOutDecimals = poolInfo.baseDecimals
}

const currencyIn = new Token(TOKEN_PROGRAM_ID, currencyInMint, currencyInDecimals)
// Getting the metadata of the tokens
const currencyInMeta = TOKEN_METADATA[currencyInMint.toString()] || { symbol: 'UNKNOWN', name: 'UNKNOWN' };
const currencyOutMeta = TOKEN_METADATA[currencyOutMint.toString()] || { symbol: 'UNKNOWN', name: 'UNKNOWN' };

// Creating Token objects with a symbol and a name
const currencyIn = new Token(
TOKEN_PROGRAM_ID,
currencyInMint,
currencyInDecimals,
currencyInMeta.symbol,
currencyInMeta.name
);
const amountIn = new TokenAmount(currencyIn, rawAmountIn, false)
const currencyOut = new Token(TOKEN_PROGRAM_ID, currencyOutMint, currencyOutDecimals)
const currencyOut = new Token(
TOKEN_PROGRAM_ID,
currencyOutMint,
currencyOutDecimals,
currencyOutMeta.symbol,
currencyOutMeta.name
);
const slippage = new Percent(5, 100) // 5% slippage

const { amountOut, minAmountOut, currentPrice, executionPrice, priceImpact, fee } = Liquidity.computeAmountOut({
Expand All @@ -278,4 +295,11 @@ class RaydiumSwap {
}
}

export default RaydiumSwap
// Mapping tokens by addresses
const TOKEN_METADATA: Record<string, { symbol: string; name: string }> = {
'So11111111111111111111111111111111111111112': { symbol: 'SOL', name: 'Solana' },
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v': { symbol: 'USDC', name: 'USD Coin' },
// Add other tokens if necessary. - mainnet.json
};

export default RaydiumSwap