-
Notifications
You must be signed in to change notification settings - Fork 201
feat: thorchain solana swapper integration #12036
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e88593c
feat: add SolanaChainId type and swapper Solana input types
gomesalexandre 8dd9e7b
feat: add SOL to asset map generation script and regenerate
gomesalexandre ee7e51c
feat: create thorchain-utils/solana module
gomesalexandre 228bc2e
feat: wire Solana case in getL1RateOrQuote.ts
gomesalexandre 8db140e
feat: wire Solana into ThorchainSwapper endpoints and execution
gomesalexandre 09fe1f6
feat: create unchained-client Solana THORChain parseTx parser
gomesalexandre de27393
fix: remove .toLowerCase() from pool asset id lookups (#12038)
gomes-bot 8bddb0b
Merge remote-tracking branch 'origin/develop' into feat/thorchain-solana
gomesalexandre 3abf7f4
chore: add sol to rune success screenshot
gomesalexandre c8a5010
fix: address coderabbit review comments on thorchain solana
gomesalexandre 69c5264
fix: add tokenId to solana getFeeData chainSpecific for spl token fee…
gomesalexandre cff2a12
Merge branch 'develop' into feat/thorchain-solana
gomesalexandre 7647d2e
Merge branch 'develop' into feat/thorchain-solana
gomesalexandre 0dc9b5d
Merge branch 'develop' into feat/thorchain-solana
gomesalexandre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/swapper/src/thorchain-utils/solana/getSolanaTransactionFees.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { contractAddressOrUndefined } from '@shapeshiftoss/utils' | ||
| import { PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js' | ||
|
|
||
| import type { GetUnsignedSolanaTransactionArgs, SwapperName } from '../../types' | ||
| import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils' | ||
| import type { ThorTradeQuote } from '../types' | ||
| import { getThorTxData } from './getThorTxData' | ||
|
|
||
| const MEMO_PROGRAM_ID = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr' | ||
|
|
||
| export const getSolanaTransactionFees = async ( | ||
| args: GetUnsignedSolanaTransactionArgs, | ||
| swapperName: SwapperName, | ||
| ): Promise<string> => { | ||
| const { tradeQuote, stepIndex, from, assertGetSolanaChainAdapter, config } = args | ||
|
|
||
| if (!isExecutableTradeQuote(tradeQuote)) throw new Error('Unable to execute a trade rate quote') | ||
|
|
||
| const { memo } = tradeQuote as ThorTradeQuote | ||
| if (!memo) throw new Error('Memo is required') | ||
|
|
||
| const step = getExecutableTradeStep(tradeQuote, stepIndex) | ||
| const { sellAmountIncludingProtocolFeesCryptoBaseUnit, sellAsset } = step | ||
|
|
||
| const { vault } = await getThorTxData({ sellAsset, config, swapperName }) | ||
|
|
||
| const adapter = assertGetSolanaChainAdapter(sellAsset.chainId) | ||
|
|
||
| const memoInstruction = new TransactionInstruction({ | ||
| keys: [], | ||
| programId: new PublicKey(MEMO_PROGRAM_ID), | ||
| data: Buffer.from(memo, 'utf8'), | ||
| }) | ||
|
|
||
| const transferInstruction = SystemProgram.transfer({ | ||
| fromPubkey: new PublicKey(from), | ||
| toPubkey: new PublicKey(vault), | ||
| lamports: BigInt(sellAmountIncludingProtocolFeesCryptoBaseUnit), | ||
| }) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const { fast } = await adapter.getFeeData({ | ||
| to: vault, | ||
| value: '0', | ||
| chainSpecific: { | ||
| from, | ||
| tokenId: contractAddressOrUndefined(sellAsset.assetId), | ||
| instructions: [memoInstruction, transferInstruction], | ||
| }, | ||
| }) | ||
|
|
||
| return fast.txFee | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
packages/swapper/src/thorchain-utils/solana/getThorTxData.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import type { Asset } from '@shapeshiftoss/types' | ||
|
|
||
| import type { SwapperConfig, SwapperName } from '../../types' | ||
| import { getInboundAddressDataForChain } from '../getInboundAddressDataForChain' | ||
| import { getDaemonUrl } from '../index' | ||
|
|
||
| type GetThorTxDataArgs = { | ||
| sellAsset: Asset | ||
| config: SwapperConfig | ||
| swapperName: SwapperName | ||
| } | ||
|
|
||
| type GetThorTxDataReturn = { | ||
| vault: string | ||
| } | ||
|
|
||
| export const getThorTxData = async ({ | ||
| sellAsset, | ||
| config, | ||
| swapperName, | ||
| }: GetThorTxDataArgs): Promise<GetThorTxDataReturn> => { | ||
| const daemonUrl = getDaemonUrl(config, swapperName) | ||
|
|
||
| const res = await getInboundAddressDataForChain(daemonUrl, sellAsset.assetId, false, swapperName) | ||
| if (res.isErr()) throw res.unwrapErr() | ||
|
|
||
| const { address: vault } = res.unwrap() | ||
|
|
||
| return { vault } | ||
| } |
81 changes: 81 additions & 0 deletions
81
packages/swapper/src/thorchain-utils/solana/getUnsignedSolanaTransaction.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import type { SolanaSignTx } from '@shapeshiftoss/hdwallet-core' | ||
| import { contractAddressOrUndefined } from '@shapeshiftoss/utils' | ||
| import { PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js' | ||
|
|
||
| import type { GetUnsignedSolanaTransactionArgs, SwapperName } from '../../types' | ||
| import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils' | ||
| import type { ThorTradeQuote } from '../types' | ||
| import { getThorTxData } from './getThorTxData' | ||
|
|
||
| const MEMO_PROGRAM_ID = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr' | ||
|
|
||
| // Each ComputeBudgetProgram instruction (setComputeUnitLimit, setComputeUnitPrice) costs 150 CU. | ||
| // Fee estimation doesn't include these, so we add a fixed buffer to cover them. | ||
| const COMPUTE_BUDGET_INSTRUCTION_OVERHEAD_CU = 300 | ||
|
|
||
| export const getUnsignedSolanaTransaction = async ( | ||
| args: GetUnsignedSolanaTransactionArgs, | ||
| swapperName: SwapperName, | ||
| ): Promise<SolanaSignTx> => { | ||
| const { tradeQuote, stepIndex, from, assertGetSolanaChainAdapter, config } = args | ||
|
|
||
| if (!isExecutableTradeQuote(tradeQuote)) throw new Error('Unable to execute a trade rate quote') | ||
|
|
||
| const { memo } = tradeQuote as ThorTradeQuote | ||
| if (!memo) throw new Error('Memo is required') | ||
|
|
||
| const step = getExecutableTradeStep(tradeQuote, stepIndex) | ||
|
|
||
| const { accountNumber, sellAmountIncludingProtocolFeesCryptoBaseUnit, sellAsset } = step | ||
|
|
||
| const { vault } = await getThorTxData({ | ||
| sellAsset, | ||
| config, | ||
| swapperName, | ||
| }) | ||
|
|
||
| const adapter = assertGetSolanaChainAdapter(sellAsset.chainId) | ||
|
|
||
| const memoInstruction = new TransactionInstruction({ | ||
| keys: [], | ||
| programId: new PublicKey(MEMO_PROGRAM_ID), | ||
| data: Buffer.from(memo, 'utf8'), | ||
| }) | ||
|
|
||
| const transferInstruction = SystemProgram.transfer({ | ||
| fromPubkey: new PublicKey(from), | ||
| toPubkey: new PublicKey(vault), | ||
| lamports: BigInt(sellAmountIncludingProtocolFeesCryptoBaseUnit), | ||
| }) | ||
|
|
||
| const { fast } = await adapter.getFeeData({ | ||
| to: vault, | ||
| value: '0', | ||
| chainSpecific: { | ||
| from, | ||
| tokenId: contractAddressOrUndefined(sellAsset.assetId), | ||
| instructions: [memoInstruction, transferInstruction], | ||
| }, | ||
| }) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const memoHdwalletInstruction = { | ||
| keys: [] as [], | ||
| programId: MEMO_PROGRAM_ID, | ||
| data: Buffer.from(memo, 'utf8'), | ||
| } | ||
|
|
||
| return adapter.buildSendApiTransaction({ | ||
| from, | ||
| to: vault, | ||
| value: sellAmountIncludingProtocolFeesCryptoBaseUnit, | ||
| accountNumber, | ||
| chainSpecific: { | ||
| instructions: [memoHdwalletInstruction], | ||
| computeUnitLimit: String( | ||
| Number(fast.chainSpecific.computeUnits) + COMPUTE_BUDGET_INSTRUCTION_OVERHEAD_CU, | ||
| ), | ||
| computeUnitPrice: fast.chainSpecific.priorityFee, | ||
| tokenId: contractAddressOrUndefined(sellAsset.assetId), | ||
| }, | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export * from './getThorTxData' | ||
| export * from './getUnsignedSolanaTransaction' | ||
| export * from './getSolanaTransactionFees' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.