@allbridge/bridge-core-sdk 3.27.0-alpha.2 → 3.27.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +3 -3
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +4 -4
- package/dist/src/chains/chain.enums.d.ts +7 -2
- package/dist/src/chains/chain.enums.js +5 -0
- package/dist/src/chains/chain.enums.js.map +1 -1
- package/dist/src/chains/index.js +6 -0
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/client/core-api/api-client.js +1 -0
- package/dist/src/client/core-api/api-client.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.js +32 -0
- package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
- package/dist/src/client/core-api/core-api.model.d.ts +13 -2
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/configs/mainnet.js +1 -0
- package/dist/src/configs/mainnet.js.map +1 -1
- package/dist/src/index.d.ts +12 -4
- package/dist/src/index.js +11 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +12 -4
- package/dist/src/models/index.js +4 -0
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/services/bridge/alg/index.d.ts +1 -0
- package/dist/src/services/bridge/alg/index.js +79 -43
- package/dist/src/services/bridge/alg/index.js.map +1 -1
- package/dist/src/services/bridge/evm/index.d.ts +1 -0
- package/dist/src/services/bridge/evm/index.js +103 -33
- package/dist/src/services/bridge/evm/index.js.map +1 -1
- package/dist/src/services/bridge/index.d.ts +2 -2
- package/dist/src/services/bridge/index.js +15 -4
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +12 -4
- package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
- package/dist/src/services/bridge/sol/index.d.ts +2 -2
- package/dist/src/services/bridge/sol/index.js +19 -11
- package/dist/src/services/bridge/sol/index.js.map +1 -1
- package/dist/src/services/bridge/sol/jupiter.d.ts +1 -1
- package/dist/src/services/bridge/sol/jupiter.js +2 -1
- package/dist/src/services/bridge/sol/jupiter.js.map +1 -1
- package/dist/src/services/bridge/srb/index.js +36 -28
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/stx/index.d.ts +16 -0
- package/dist/src/services/bridge/stx/index.js +136 -0
- package/dist/src/services/bridge/stx/index.js.map +1 -0
- package/dist/src/services/bridge/sui/index.js +166 -138
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.js +98 -70
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +3 -1
- package/dist/src/services/bridge/utils.js +92 -8
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/alg/index.js +10 -17
- package/dist/src/services/liquidity-pool/alg/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +5 -0
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/sol/index.js +6 -3
- package/dist/src/services/liquidity-pool/sol/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/stx/index.d.ts +21 -0
- package/dist/src/services/liquidity-pool/stx/index.js +141 -0
- package/dist/src/services/liquidity-pool/stx/index.js.map +1 -0
- package/dist/src/services/models/abi/PayerWithAbr.d.ts +203 -0
- package/dist/src/services/models/abi/PayerWithAbr.js +266 -0
- package/dist/src/services/models/abi/PayerWithAbr.js.map +1 -0
- package/dist/src/services/models/alg/BridgeClient.d.ts +158 -133
- package/dist/src/services/models/alg/BridgeClient.js +182 -130
- package/dist/src/services/models/alg/BridgeClient.js.map +1 -1
- package/dist/src/services/models/alg/PaddingUtilClient.d.ts +639 -0
- package/dist/src/services/models/alg/PaddingUtilClient.js +425 -0
- package/dist/src/services/models/alg/PaddingUtilClient.js.map +1 -0
- package/dist/src/services/models/alg/PoolClient.d.ts +204 -201
- package/dist/src/services/models/alg/PoolClient.js +234 -215
- package/dist/src/services/models/alg/PoolClient.js.map +1 -1
- package/dist/src/services/models/index.d.ts +16 -3
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/services/models/stx/clarigen-types.d.ts +657 -0
- package/dist/src/services/models/stx/clarigen-types.js +2296 -0
- package/dist/src/services/models/stx/clarigen-types.js.map +1 -0
- package/dist/src/services/token/index.js +7 -2
- package/dist/src/services/token/index.js.map +1 -1
- package/dist/src/services/token/models/token.model.d.ts +4 -4
- package/dist/src/services/token/models/token.model.js.map +1 -1
- package/dist/src/services/token/stx/index.d.ts +20 -0
- package/dist/src/services/token/stx/index.js +59 -0
- package/dist/src/services/token/stx/index.js.map +1 -0
- package/dist/src/services/utils/alg/index.d.ts +1 -10
- package/dist/src/services/utils/alg/index.js +0 -20
- package/dist/src/services/utils/alg/index.js.map +1 -1
- package/dist/src/services/utils/sol/compute-budget.d.ts +2 -1
- package/dist/src/services/utils/sol/compute-budget.js +36 -18
- package/dist/src/services/utils/sol/compute-budget.js.map +1 -1
- package/dist/src/services/utils/sol/index.d.ts +2 -0
- package/dist/src/services/utils/sol/index.js +12 -0
- package/dist/src/services/utils/sol/index.js.map +1 -1
- package/dist/src/services/utils/stx/get-token-name.d.ts +2 -0
- package/dist/src/services/utils/stx/get-token-name.js +15 -0
- package/dist/src/services/utils/stx/get-token-name.js.map +1 -0
- package/dist/src/services/utils/stx/post-conditions.d.ts +3 -0
- package/dist/src/services/utils/stx/post-conditions.js +27 -0
- package/dist/src/services/utils/stx/post-conditions.js.map +1 -0
- package/dist/src/services/yield/index.js +4 -0
- package/dist/src/services/yield/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +21 -0
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/utils/utils.d.ts +2 -0
- package/dist/src/utils/utils.js +11 -0
- package/dist/src/utils/utils.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/index.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,sDAAsD;AACtD,kDAA+D;AAC/D,6CASyB;AACzB,mCAA6B;AAC7B,4CAAyC;AACzC,4EAAoE;AAEpE,oDAQ6B;AAC7B,4CAA8G;AAC9G,4DAAqE;AAGrE,0DAAuF;AACvF,oEAAwG;AACxG,yCAAiF;AACjF,uDAgBkC;AAClC,qEAAsE;AACtE,mEAAqH;AAErH,6CAAsD;AACtD,oCAA8E;AAC9E,uCAA2C;AA8B3C,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAEnC,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,MAAa,mBAAoB,SAAQ,2BAAkB;IAKhD;IACA;IACA;IANT,SAAS,GAAqB,kBAAS,CAAC,MAAM,CAAC;IAC/C,cAAc,CAAiB;IAE/B,YACS,YAAoB,EACpB,MAA0B,EAC1B,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAJD,iBAAY,GAAZ,YAAY,CAAQ;QACpB,WAAM,GAAN,MAAM,CAAoB;QAC1B,QAAG,GAAH,GAAG,CAAqB;QAG/B,IAAI,CAAC,cAAc,GAAG,IAAI,wBAAc,CAAC,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACjE,OAAO,MAAM,IAAI,CAAC,oBAAoB,CACpC,YAAY,EACZ,MAAM,CAAC,WAAW,CAAC,W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,CAAC,6BAA6B,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,2BAA2B,EAAE,CAAC;IAChH,CAAC;IAED,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;CACF;AAvuBD,kDAuuBC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { BN, Program, Spl, web3 } from \"@project-serum/anchor\";\nimport {\n Connection,\n Keypair,\n PublicKey,\n SystemProgram,\n Transaction,\n TransactionInstruction,\n TransactionMessageArgs,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { Big } from \"big.js\";\nimport { Chains } from \"../../../chains\";\nimport { Messenger } from \"../../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n AmountNotEnoughError,\n CCTPDoesNotSupportedError,\n JupiterError,\n MethodNotSupportedError,\n OFTDoesNotSupportedError,\n SdkError,\n SdkRootError,\n} from \"../../../exceptions\";\nimport { ChainType, FeePaymentMethod, SwapParams, TokenWithChainDetails, TxFeeParams } from \"../../../models\";\nimport { convertIntAmountToFloat } from \"../../../utils/calculation\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { SwapAndBridgeSolData, SwapAndBridgeSolDataCctpData } from \"../../models/sol\";\nimport { Bridge as BridgeType, IDL as bridgeIdl } from \"../../models/sol/types/bridge\";\nimport { CctpBridge as CctpBridgeType, IDL as cctpBridgeIdl } from \"../../models/sol/types/cctp_bridge\";\nimport { getMessage, getTokenAccountData, getVUsdAmount } from \"../../utils/sol\";\nimport {\n getAssociatedAccount,\n getAuthorityAccount,\n getBridgeTokenAccount,\n getCctpAccounts,\n getCctpAuthorityAccount,\n getCctpBridgeAccount,\n getCctpBridgeTokenAccount,\n getCctpLockAccount,\n getChainBridgeAccount,\n getConfigAccount,\n getGasUsageAccount,\n getLockAccount,\n getOtherChainTokenAccount,\n getPriceAccount,\n getSendMessageAccount,\n} from \"../../utils/sol/accounts\";\nimport { buildAnchorProvider } from \"../../utils/sol/anchor-provider\";\nimport { addUnitLimitAndUnitPriceToTx, addUnitLimitAndUnitPriceToVersionedTx } from \"../../utils/sol/compute-budget\";\nimport { SendParams, TxSendParamsSol, TxSwapParamsSol } from \"../models\";\nimport { ChainBridgeService } from \"../models/bridge\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport { JupiterService } from \"./jupiter\";\n\nexport interface SolanaBridgeParams {\n wormholeMessengerProgramId: string;\n solanaLookUpTable: string;\n cctpParams: CctpParams;\n jupiterParams: JupiterParams;\n}\n\nexport interface JupiterParams {\n jupiterUrl: string;\n jupiterApiKeyHeader?: string;\n jupiterMaxAccounts?: number;\n}\n\nexport interface CctpParams {\n cctpTransmitterProgramId: string;\n cctpTokenMessengerMinter: string;\n cctpDomains: CctpDomains;\n}\n\n/**\n * Type representing a map of CCTP domains to their corresponding numeric values.\n *\n * @typedef {Record<string, number>} CctpDomains\n * @property {string} chainSymbol - The symbol of the chain representing one of the supported blockchain networks (e.g., \"ETH\" for Ethereum). For more details, see: {@link ChainSymbol}.\n * @property {number} value - The numeric value associated with the specified chain.\n */\nexport type CctpDomains = Record<string, number>;\n\nconst COMPUTE_UNIT_LIMIT = 1000000;\n\nconst JUP_ADD_INDEX = 1.1;\n\nexport class SolanaBridgeService extends ChainBridgeService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n jupiterService: JupiterService;\n\n constructor(\n public solanaRpcUrl: string,\n public params: SolanaBridgeParams,\n public api: AllbridgeCoreClient\n ) {\n super();\n this.jupiterService = new JupiterService(solanaRpcUrl, params.jupiterParams);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildSwapTransaction(\n txSwapParams,\n params.sourceToken.poolAddress,\n params.destinationToken.poolAddress,\n params.txFeeParams\n );\n }\n\n private async buildSwapTransaction(\n params: TxSwapParamsSol,\n poolAddress: string,\n toPoolAddress: string,\n txFeeParams?: TxFeeParams\n ): Promise<VersionedTransaction> {\n const {\n fromAccountAddress,\n amount,\n contractAddress,\n fromTokenAddress,\n toTokenAddress,\n toAccountAddress,\n minimumReceiveAmount,\n } = params;\n const account = fromAccountAddress;\n const bridgeAddress = contractAddress;\n const tokenAddress = fromTokenAddress;\n const receiveTokenAddress = toTokenAddress;\n const receivePoolAddress = toPoolAddress;\n const receiverOriginal = toAccountAddress;\n\n const userAccount = new PublicKey(account);\n const provider = buildAnchorProvider(this.solanaRpcUrl, userAccount.toString());\n const bridge = new Program<BridgeType>(bridgeIdl, bridgeAddress, provider);\n\n const bridgeAuthority = await getAuthorityAccount(bridge.programId);\n const configAccount = await getConfigAccount(bridge.programId);\n\n const sendMint = new PublicKey(tokenAddress);\n const sendBridgeToken = await getBridgeTokenAccount(sendMint, bridge.programId);\n const sendPool = new PublicKey(poolAddress);\n const sendUserToken = await getAssociatedAccount(userAccount, sendMint);\n\n const receiverAccount = new PublicKey(receiverOriginal);\n const receiveMint = new PublicKey(receiveTokenAddress);\n const receiveBridgeToken = await getBridgeTokenAccount(receiveMint, bridge.programId);\n const receivePool = new PublicKey(receivePoolAddress);\n const receiveUserToken = await getAssociatedAccount(receiverAccount, receiveMint);\n\n const preInstructions: TransactionInstruction[] = [\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: COMPUTE_UNIT_LIMIT,\n }),\n ];\n\n try {\n await getTokenAccountData(receiveUserToken, provider);\n } catch (e) {\n const associatedProgram = Spl.associatedToken(provider);\n const createReceiveUserTokenInstruction: TransactionInstruction = await associatedProgram.methods\n .create()\n .accounts({\n mint: receiveMint,\n owner: receiverAccount,\n associatedAccount: receiveUserToken,\n })\n .instruction();\n preInstructions.push(createReceiveUserTokenInstruction);\n }\n const transaction = await bridge.methods\n .swap(new BN(amount), new BN(minimumReceiveAmount || 0))\n .accounts({\n payer: userAccount,\n config: configAccount,\n bridgeAuthority,\n user: userAccount,\n sendBridgeToken,\n sendMint,\n sendPool,\n sendUserToken,\n receiveBridgeToken,\n receiveMint,\n receivePool,\n receiveUserToken,\n })\n .preInstructions(preInstructions)\n .transaction();\n\n const connection = provider.connection;\n transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n transaction.feePayer = userAccount;\n await addUnitLimitAndUnitPriceToTx(transaction, txFeeParams, this.solanaRpcUrl);\n return await this.convertToVersionedTransaction(transaction, connection);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n let solTxSendParams = this.addPoolAddress(params, txSendParams);\n\n const isJupiterForStableCoin = solTxSendParams.gasFeePaymentMethod == FeePaymentMethod.WITH_STABLECOIN;\n\n let jupTx;\n if (isJupiterForStableCoin) {\n try {\n const { tx, solTxSendUpdatedParams } = await this.processJup(solTxSendParams, params, true);\n jupTx = tx;\n solTxSendParams = { ...solTxSendParams, ...solTxSendUpdatedParams };\n } catch (e) {\n try {\n const { tx, solTxSendUpdatedParams } = await this.processJup(solTxSendParams, params, false);\n jupTx = tx;\n solTxSendParams = { ...solTxSendParams, ...solTxSendUpdatedParams };\n } catch (e) {\n if (e instanceof SdkRootError) {\n throw e;\n }\n if (e instanceof Error && e.message) {\n throw new JupiterError(`Some error occurred during creation Jupiter swap transaction. ${e.message}`);\n }\n throw new JupiterError(\"Some error occurred during creation Jupiter swap transaction\");\n }\n }\n }\n\n let swapAndBridgeTx: VersionedTransaction;\n let requiredMessageSigner: Keypair | undefined = undefined;\n switch (txSendParams.messenger) {\n case Messenger.ALLBRIDGE: {\n const swapAndBridgeSolData = await this.prepareSwapAndBridgeData(solTxSendParams);\n swapAndBridgeTx = await this.buildSwapAndBridgeAllbridgeTransaction(swapAndBridgeSolData);\n break;\n }\n case Messenger.WORMHOLE: {\n const swapAndBridgeSolData = await this.prepareSwapAndBridgeData(solTxSendParams);\n const { transaction, messageAccount } = await this.buildSwapAndBridgeWormholeTransaction(swapAndBridgeSolData);\n swapAndBridgeTx = transaction;\n requiredMessageSigner = messageAccount;\n break;\n }\n case Messenger.CCTP:\n case Messenger.CCTP_V2: {\n const swapAndBridgeSolData = await this.prepareSwapAndBridgeCctpData(solTxSendParams);\n const { transaction, messageSentEventDataKeypair } = await this.buildSwapAndBridgeCctpTransaction(\n params.destinationToken.chainSymbol,\n swapAndBridgeSolData\n );\n swapAndBridgeTx = transaction;\n requiredMessageSigner = messageSentEventDataKeypair;\n break;\n }\n case Messenger.OFT:\n throw new OFTDoesNotSupportedError(\"Messenger OFT is not supported yet.\");\n }\n\n if (isJupiterForStableCoin) {\n if (!jupTx) {\n throw new JupiterError(\"Swap tx is absent\");\n }\n swapAndBridgeTx = await this.jupiterService.amendJupiterWithSdkTx(jupTx, swapAndBridgeTx);\n }\n\n await addUnitLimitAndUnitPriceToVersionedTx(swapAndBridgeTx, params.txFeeParams, this.solanaRpcUrl);\n\n if (requiredMessageSigner) {\n swapAndBridgeTx.sign([requiredMessageSigner]);\n }\n return swapAndBridgeTx;\n }\n\n private async processJup(\n solTxSendParams: SolTxSendParams,\n params: SendParams,\n exactOut: boolean\n ): Promise<{\n tx: VersionedTransaction;\n solTxSendUpdatedParams: {\n amount: string;\n fee: string;\n extraGas?: string;\n gasFeePaymentMethod: FeePaymentMethod;\n };\n }> {\n const { fee, extraGas, gasFeePaymentMethod } = await this.convertStableCoinFeeAndExtraGasToNativeCurrency(\n params.sourceToken,\n solTxSendParams\n );\n\n let amountToProcess = exactOut ? Big(fee) : Big(solTxSendParams.fee);\n if (extraGas) {\n amountToProcess = amountToProcess.plus(extraGas);\n }\n if (!exactOut) {\n amountToProcess = amountToProcess.mul(JUP_ADD_INDEX);\n }\n\n const { tx, amountIn } = await this.jupiterService.getJupiterSwapTx(\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n amountToProcess.toFixed(0),\n exactOut\n );\n\n let newAmount: string;\n if (exactOut) {\n if (!amountIn) {\n throw new JupiterError(\"Cannot get inAmount\");\n }\n newAmount = Big(solTxSendParams.amount).minus(Big(amountIn).mul(JUP_ADD_INDEX)).toFixed(0);\n } else {\n newAmount = Big(solTxSendParams.amount).minus(amountToProcess).toFixed(0);\n }\n if (Big(newAmount).lte(0)) {\n throw new AmountNotEnoughError(\n `Amount not enough to pay fee, ${convertIntAmountToFloat(\n Big(newAmount).minus(1).neg(),\n params.sourceToken.decimals\n ).toFixed()} stables is missing`\n );\n }\n return {\n tx: tx,\n solTxSendUpdatedParams: {\n amount: newAmount,\n fee: fee,\n extraGas: extraGas,\n gasFeePaymentMethod: gasFeePaymentMethod,\n },\n };\n }\n\n private addPoolAddress(params: SendParams, txSendParams: TxSendParamsSol): SolTxSendParams {\n return {\n ...txSendParams,\n poolAddress: params.sourceToken.poolAddress,\n };\n }\n\n async convertStableCoinFeeAndExtraGasToNativeCurrency(\n sourceToken: TokenWithChainDetails,\n solTxSendParams: SolTxSendParams\n ): Promise<{ fee: string; extraGas?: string; gasFeePaymentMethod: FeePaymentMethod }> {\n if (solTxSendParams.gasFeePaymentMethod == FeePaymentMethod.WITH_STABLECOIN) {\n const sourceNativeTokenPrice = (\n await this.api.getReceiveTransactionCost({\n sourceChainId: solTxSendParams.fromChainId,\n destinationChainId: solTxSendParams.toChainId,\n messenger: solTxSendParams.messenger,\n sourceToken: sourceToken.tokenAddress,\n })\n ).sourceNativeTokenPrice;\n const fee = Big(solTxSendParams.fee)\n .div(sourceNativeTokenPrice)\n .mul(Big(10).pow(Chains.getChainDecimalsByType(ChainType.SOLANA) - sourceToken.decimals))\n .toFixed(0);\n let extraGas;\n if (solTxSendParams.extraGas) {\n extraGas = Big(solTxSendParams.extraGas)\n .div(sourceNativeTokenPrice)\n .mul(Big(10).pow(Chains.getChainDecimalsByType(ChainType.SOLANA) - sourceToken.decimals))\n .toFixed(0);\n }\n return { fee, extraGas, gasFeePaymentMethod: FeePaymentMethod.WITH_NATIVE_CURRENCY };\n }\n return {\n fee: solTxSendParams.fee,\n extraGas: solTxSendParams.extraGas,\n gasFeePaymentMethod: FeePaymentMethod.WITH_NATIVE_CURRENCY,\n };\n }\n\n private getExtraGasInstruction(\n extraGas: string,\n userAccount: PublicKey,\n configAccount: PublicKey\n ): TransactionInstruction | undefined {\n return web3.SystemProgram.transfer({\n fromPubkey: userAccount,\n toPubkey: configAccount,\n lamports: +extraGas,\n });\n }\n\n private async prepareSwapAndBridgeData(txSendParams: SolTxSendParams): Promise<SwapAndBridgeSolData> {\n const {\n amount,\n contractAddress,\n fromChainId,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n poolAddress,\n extraGas,\n } = txSendParams;\n const tokenAddress = fromTokenAddress;\n const account = fromAccountAddress;\n const destinationChainId = toChainId;\n const receiveTokenAddress = toTokenAddress;\n const receiverInBuffer32 = toAccountAddress;\n const bridgeAddress = contractAddress;\n const sourceChainId = fromChainId;\n\n const provider = buildAnchorProvider(this.solanaRpcUrl, account);\n const bridge = new Program<BridgeType>(bridgeIdl, bridgeAddress, provider);\n const nonce = Array.from(getNonce());\n const poolAccount = new PublicKey(poolAddress);\n const vUsdAmount = await getVUsdAmount(amount, bridge, poolAccount);\n\n const lockAccount = await getLockAccount(nonce, bridge.programId);\n const bridgeAuthority = await getAuthorityAccount(bridge.programId);\n const userToken = await getAssociatedAccount(new PublicKey(account), new PublicKey(tokenAddress));\n const bridgeTokenAccount = await getBridgeTokenAccount(new PublicKey(tokenAddress), bridge.programId);\n const chainBridgeAccount = await getChainBridgeAccount(destinationChainId, bridge.programId);\n const otherBridgeTokenAccount = await getOtherChainTokenAccount(\n destinationChainId,\n Buffer.from(receiveTokenAddress),\n bridge.programId\n );\n\n const configAccount = await getConfigAccount(bridge.programId);\n const configAccountInfo = await bridge.account.config.fetch(configAccount);\n const priceAccount = await getPriceAccount(destinationChainId, configAccountInfo.gasOracleProgramId);\n const thisGasPriceAccount = await getPriceAccount(sourceChainId, configAccountInfo.gasOracleProgramId);\n\n const message = getMessage({\n amount: vUsdAmount,\n recipient: Buffer.from(receiverInBuffer32),\n nonce: Buffer.from(nonce),\n receiveToken: Buffer.from(receiveTokenAddress),\n destinationChainId,\n sourceChainId,\n chainBridge: (await getAuthorityAccount(bridge.programId)).toBuffer(),\n });\n\n const swapAndBridgeData = {} as SwapAndBridgeSolData;\n\n swapAndBridgeData.bridge = bridge;\n swapAndBridgeData.amount = new BN(amount);\n swapAndBridgeData.vusdAmount = new BN(vUsdAmount);\n swapAndBridgeData.nonce = nonce;\n swapAndBridgeData.recipient = Array.from(receiverInBuffer32);\n swapAndBridgeData.receiveToken = Array.from(receiveTokenAddress);\n swapAndBridgeData.poolAccount = poolAccount;\n swapAndBridgeData.lockAccount = lockAccount;\n swapAndBridgeData.bridgeAuthority = bridgeAuthority;\n swapAndBridgeData.userToken = userToken;\n swapAndBridgeData.bridgeTokenAccount = bridgeTokenAccount;\n swapAndBridgeData.chainBridgeAccount = chainBridgeAccount;\n swapAndBridgeData.otherBridgeTokenAccount = otherBridgeTokenAccount;\n swapAndBridgeData.userAccount = new PublicKey(account);\n swapAndBridgeData.destinationChainId = destinationChainId;\n // @ts-expect-error\n swapAndBridgeData.mint = new PublicKey(tokenAddress);\n swapAndBridgeData.config = configAccount;\n swapAndBridgeData.configAccountInfo = configAccountInfo;\n swapAndBridgeData.gasPrice = priceAccount;\n swapAndBridgeData.thisGasPrice = thisGasPriceAccount;\n swapAndBridgeData.message = message;\n\n if (extraGas) {\n swapAndBridgeData.extraGasInstruction = this.getExtraGasInstruction(\n extraGas,\n swapAndBridgeData.userAccount,\n configAccount\n );\n }\n return swapAndBridgeData;\n }\n\n private async buildSwapAndBridgeAllbridgeTransaction(\n swapAndBridgeData: SwapAndBridgeSolData\n ): Promise<VersionedTransaction> {\n const {\n bridge,\n vusdAmount,\n nonce,\n recipient,\n receiveToken,\n poolAccount,\n lockAccount,\n bridgeAuthority,\n userToken,\n bridgeTokenAccount,\n chainBridgeAccount,\n otherBridgeTokenAccount,\n userAccount,\n destinationChainId,\n mint,\n config,\n configAccountInfo,\n gasPrice,\n thisGasPrice,\n message,\n extraGasInstruction,\n } = swapAndBridgeData;\n const allbridgeMessengerProgramId = configAccountInfo.allbridgeMessengerProgramId;\n const messengerGasUsageAccount = await getGasUsageAccount(destinationChainId, allbridgeMessengerProgramId);\n const messengerConfig = await getConfigAccount(allbridgeMessengerProgramId);\n\n const sentMessageAccount = await getSendMessageAccount(message, allbridgeMessengerProgramId);\n\n const instructions: TransactionInstruction[] = [];\n if (extraGasInstruction) {\n instructions.push(extraGasInstruction);\n }\n\n const transaction = await bridge.methods\n .swapAndBridge({\n vusdAmount,\n nonce,\n destinationChainId,\n recipient,\n receiveToken,\n })\n .accounts({\n mint,\n user: userAccount,\n config,\n lock: lockAccount,\n pool: poolAccount,\n gasPrice,\n thisGasPrice,\n bridgeAuthority,\n userToken,\n bridgeToken: bridgeTokenAccount,\n chainBridge: chainBridgeAccount,\n messenger: allbridgeMessengerProgramId,\n messengerGasUsage: messengerGasUsageAccount,\n messengerConfig,\n sentMessageAccount,\n otherBridgeToken: otherBridgeTokenAccount,\n })\n .preInstructions([\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: COMPUTE_UNIT_LIMIT,\n }),\n ])\n .postInstructions(instructions)\n .transaction();\n const connection = buildAnchorProvider(this.solanaRpcUrl, userAccount.toString()).connection;\n transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n transaction.feePayer = userAccount;\n return await this.convertToVersionedTransaction(transaction, connection);\n }\n\n private async convertToVersionedTransaction(tx: Transaction, connection: Connection): Promise<VersionedTransaction> {\n const allbridgeTableAccount = await connection\n .getAddressLookupTable(new PublicKey(this.params.solanaLookUpTable))\n .then((res) => res.value);\n if (!allbridgeTableAccount) {\n throw new SdkError(\"Cannot find allbridgeLookupTableAccount\");\n }\n const messageV0 = new web3.TransactionMessage({\n payerKey: tx.feePayer,\n recentBlockhash: tx.recentBlockhash,\n instructions: tx.instructions,\n } as TransactionMessageArgs).compileToV0Message([allbridgeTableAccount]);\n return new web3.VersionedTransaction(messageV0);\n }\n\n private async buildSwapAndBridgeWormholeTransaction(\n swapAndBridgeData: SwapAndBridgeSolData\n ): Promise<{ transaction: VersionedTransaction; messageAccount: Keypair }> {\n const {\n bridge,\n vusdAmount,\n nonce,\n recipient,\n receiveToken,\n poolAccount,\n lockAccount,\n bridgeAuthority,\n userToken,\n bridgeTokenAccount,\n chainBridgeAccount,\n otherBridgeTokenAccount,\n userAccount,\n destinationChainId,\n mint,\n config,\n configAccountInfo,\n gasPrice,\n thisGasPrice,\n message,\n extraGasInstruction,\n } = swapAndBridgeData;\n const wormholeProgramId = this.params.wormholeMessengerProgramId;\n\n const [whBridgeAccount] = PublicKey.findProgramAddressSync(\n [Buffer.from(\"Bridge\")],\n new PublicKey(wormholeProgramId)\n );\n const [whFeeCollectorAccount] = PublicKey.findProgramAddressSync(\n [Buffer.from(\"fee_collector\")],\n new PublicKey(wormholeProgramId)\n );\n const [whSequenceAccount] = PublicKey.findProgramAddressSync(\n [Buffer.from(\"Sequence\"), bridgeAuthority.toBuffer()],\n new PublicKey(wormholeProgramId)\n );\n\n const messengerGasUsageAccount = await getGasUsageAccount(\n destinationChainId,\n configAccountInfo.wormholeMessengerProgramId\n );\n const wormholeMessengerConfigAccount = await getConfigAccount(configAccountInfo.wormholeMessengerProgramId);\n const messageAccount = Keypair.generate();\n\n const provider = buildAnchorProvider(this.solanaRpcUrl, userAccount.toString());\n\n const bridgeAccountInfo = await provider.connection.getAccountInfo(whBridgeAccount);\n if (bridgeAccountInfo == null) {\n throw new SdkError(\"Cannot fetch wormhole bridge account info\");\n }\n const feeLamports = new BN(bridgeAccountInfo.data.slice(16, 24), \"le\").toString();\n\n const feeInstruction = SystemProgram.transfer({\n fromPubkey: userAccount,\n toPubkey: whFeeCollectorAccount,\n lamports: +feeLamports,\n });\n\n const instructions: TransactionInstruction[] = [];\n if (extraGasInstruction) {\n instructions.push(extraGasInstruction);\n }\n\n const accounts = {\n mint,\n user: userAccount,\n config,\n lock: lockAccount,\n pool: poolAccount,\n gasPrice,\n thisGasPrice,\n bridgeAuthority,\n userToken,\n bridgeToken: bridgeTokenAccount,\n chainBridge: chainBridgeAccount,\n otherBridgeToken: otherBridgeTokenAccount,\n messengerGasUsage: messengerGasUsageAccount,\n wormholeProgram: wormholeProgramId,\n bridge: whBridgeAccount,\n message: messageAccount.publicKey,\n wormholeMessenger: configAccountInfo.wormholeMessengerProgramId,\n sequence: whSequenceAccount,\n feeCollector: whFeeCollectorAccount,\n wormholeMessengerConfig: wormholeMessengerConfigAccount,\n clock: web3.SYSVAR_CLOCK_PUBKEY,\n };\n\n const transaction = await bridge.methods\n .swapAndBridgeWormhole({\n vusdAmount,\n nonce: nonce,\n destinationChainId,\n recipient,\n receiveToken,\n })\n .accounts(accounts)\n .preInstructions([\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: COMPUTE_UNIT_LIMIT,\n }),\n feeInstruction,\n ])\n .postInstructions(instructions)\n .signers([messageAccount])\n .transaction();\n transaction.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;\n transaction.feePayer = userAccount;\n return { transaction: await this.convertToVersionedTransaction(transaction, provider.connection), messageAccount };\n }\n\n private async prepareSwapAndBridgeCctpData(txSendParams: SolTxSendParams): Promise<SwapAndBridgeSolDataCctpData> {\n const {\n contractAddress,\n amount,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n extraGas,\n } = txSendParams;\n const cctpAddress = contractAddress;\n if (!cctpAddress) {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n const CHAIN_ID = 4;\n\n const account = fromAccountAddress;\n const receiveTokenAddress = toTokenAddress;\n const receiverInBuffer32 = toAccountAddress;\n\n const provider = buildAnchorProvider(this.solanaRpcUrl, account);\n const cctpBridge: Program<CctpBridgeType> = new Program<CctpBridgeType>(cctpBridgeIdl, cctpAddress, provider);\n const mint = new PublicKey(fromTokenAddress);\n const cctpBridgeAccount = await getCctpBridgeAccount(mint, cctpBridge.programId);\n const userAccount = new PublicKey(account);\n\n const configAccountInfo = await cctpBridge.account.cctpBridge.fetch(cctpBridgeAccount);\n\n const swapAndBridgeData = {} as SwapAndBridgeSolDataCctpData;\n\n swapAndBridgeData.cctpBridge = cctpBridge;\n swapAndBridgeData.cctpBridgeAccount = cctpBridgeAccount;\n swapAndBridgeData.cctpAddressAccount = new PublicKey(cctpAddress);\n swapAndBridgeData.amount = new BN(amount);\n swapAndBridgeData.recipient = Array.from(receiverInBuffer32);\n swapAndBridgeData.receiveToken = Array.from(receiveTokenAddress);\n swapAndBridgeData.userToken = await getAssociatedAccount(userAccount, mint);\n swapAndBridgeData.bridgeAuthority = await getCctpAuthorityAccount(cctpBridgeAccount, cctpBridge.programId);\n swapAndBridgeData.bridgeTokenAccount = await getCctpBridgeTokenAccount(mint, cctpBridge.programId);\n swapAndBridgeData.chainBridgeAccount = await getChainBridgeAccount(toChainId, cctpBridge.programId);\n swapAndBridgeData.userAccount = userAccount;\n swapAndBridgeData.destinationChainId = toChainId;\n swapAndBridgeData.mint = mint;\n swapAndBridgeData.gasPrice = await getPriceAccount(toChainId, configAccountInfo.gasOracleProgramId);\n swapAndBridgeData.thisGasPrice = await getPriceAccount(CHAIN_ID, configAccountInfo.gasOracleProgramId);\n swapAndBridgeData.provider = provider;\n\n if (extraGas) {\n swapAndBridgeData.extraGasInstruction = this.getExtraGasInstruction(\n extraGas,\n swapAndBridgeData.userAccount,\n cctpBridgeAccount\n );\n }\n return swapAndBridgeData;\n }\n\n async buildSwapAndBridgeCctpTransaction(\n destinationChainSymbol: string,\n swapAndBridgeData: SwapAndBridgeSolDataCctpData\n ): Promise<{ transaction: VersionedTransaction; messageSentEventDataKeypair: Keypair }> {\n const {\n cctpBridge,\n cctpBridgeAccount,\n amount,\n recipient,\n receiveToken,\n bridgeAuthority,\n userToken,\n bridgeTokenAccount,\n chainBridgeAccount,\n userAccount,\n destinationChainId,\n mint,\n gasPrice,\n thisGasPrice,\n extraGasInstruction,\n provider,\n } = swapAndBridgeData;\n const domain = this.params.cctpParams.cctpDomains[destinationChainSymbol];\n const cctpTransmitterProgramIdAddress = this.params.cctpParams.cctpTransmitterProgramId;\n const cctpTokenMessengerMinterAddress = this.params.cctpParams.cctpTokenMessengerMinter;\n if (domain == undefined || !cctpTransmitterProgramIdAddress || !cctpTokenMessengerMinterAddress) {\n throw new SdkError(\"CCTP is not configured\");\n }\n const cctpTransmitterProgramId = new PublicKey(cctpTransmitterProgramIdAddress);\n const cctpTokenMessengerMinter = new PublicKey(cctpTokenMessengerMinterAddress);\n const {\n messageTransmitterAccount,\n tokenMessenger,\n tokenMessengerEventAuthority,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n } = getCctpAccounts(domain, mint, cctpTransmitterProgramId, cctpTokenMessengerMinter);\n\n const instructions: TransactionInstruction[] = [];\n if (extraGasInstruction) {\n instructions.push(extraGasInstruction);\n }\n\n const messageSentEventDataKeypair = Keypair.generate();\n const lockAccount = getCctpLockAccount(cctpBridge.programId, messageSentEventDataKeypair.publicKey);\n\n const tx = await cctpBridge.methods\n .bridge({\n amount,\n destinationChainId,\n recipient,\n receiveToken,\n })\n .accounts({\n mint: mint,\n user: userAccount,\n cctpBridge: cctpBridgeAccount,\n\n messageSentEventData: messageSentEventDataKeypair.publicKey,\n lock: lockAccount,\n\n cctpMessenger: cctpTokenMessengerMinter,\n messageTransmitterProgram: cctpTransmitterProgramId,\n messageTransmitterAccount: messageTransmitterAccount,\n tokenMessenger: tokenMessenger,\n tokenMinter: tokenMinter,\n localToken: localToken,\n remoteTokenMessengerKey: remoteTokenMessengerKey,\n authorityPda: authorityPda,\n eventAuthority: tokenMessengerEventAuthority,\n\n bridgeToken: bridgeTokenAccount,\n gasPrice: gasPrice,\n thisGasPrice: thisGasPrice,\n chainBridge: chainBridgeAccount,\n userToken,\n bridgeAuthority: bridgeAuthority,\n })\n .preInstructions([\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: 2000000,\n }),\n ])\n .postInstructions(instructions)\n .transaction();\n const connection = provider.connection;\n tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n tx.feePayer = userAccount;\n return { transaction: await this.convertToVersionedTransaction(tx, connection), messageSentEventDataKeypair };\n }\n\n send(params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n}\n\ninterface SolTxSendParams extends TxSendParamsSol {\n poolAddress: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/index.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,sDAAsD;AACtD,kDAA+D;AAC/D,6CASyB;AACzB,mCAA6B;AAC7B,4CAAyC;AACzC,4EAAoE;AAEpE,oDAQ6B;AAC7B,4CAA8G;AAC9G,4DAAqE;AAGrE,0DAAuF;AACvF,oEAAwG;AACxG,yCAA8F;AAC9F,uDAgBkC;AAClC,qEAAsE;AACtE,mEAAqH;AAErH,6CAAsD;AACtD,oCAA8E;AAC9E,uCAA2C;AA8B3C,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAEnC,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,MAAa,mBAAoB,SAAQ,2BAAkB;IAKhD;IACA;IACA;IANT,SAAS,GAAqB,kBAAS,CAAC,MAAM,CAAC;IAC/C,cAAc,CAAiB;IAE/B,YACS,YAAoB,EACpB,MAA0B,EAC1B,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAJD,iBAAY,GAAZ,YAAY,CAAQ;QACpB,WAAM,GAAN,MAAM,CAAoB;QAC1B,QAAG,GAAH,GAAG,CAAqB;QAG/B,IAAI,CAAC,cAAc,GAAG,IAAI,wBAAc,CAAC,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,IAAA,2BAAmB,EAA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EAAE,wBAAwB;YACvC,yBAAyB,EAAE,wBAAwB;YACnD,yBAAyB,EAAE,yBAAyB;YACpD,cAAc,EAAE,cAAc;YAC9B,WAAW,EAAE,WAAW;YACxB,UAAU,EAAE,UAAU;YACtB,uBAAuB,EAAE,uBAAuB;YAChD,YAAY,EAAE,YAAY;YAC1B,cAAc,EAAE,4BAA4B;YAE5C,WAAW,EAAE,kBAAkB;YAC/B,QAAQ,EAAE,QAAQ;YAClB,YAAY,EAAE,YAAY;YAC1B,WAAW,EAAE,kBAAkB;YAC/B,SAAS;YACT,eAAe,EAAE,eAAe;SACjC,CAAC;aACD,eAAe,CAAC;YACf,aAAI,CAAC,oBAAoB,CAAC,mBAAmB,CAAC;gBAC5C,KAAK,EAAE,OAAO;aACf,CAAC;SACH,CAAC;aACD,gBAAgB,CAAC,YAAY,CAAC;aAC9B,WAAW,EAAE,CAAC;QACjB,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACvC,EAAE,CAAC,eAAe,GAAG,CAAC,MAAM,UAAU,CAAC,kBAAkB,EAAE,CAAC,CAAC,SAAS,CAAC;QACvE,EAAE,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACvB,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC,6BAA6B,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,2BAA2B,EAAE,CAAC;IAChH,CAAC;IAED,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;CACF;AA3vBD,kDA2vBC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { BN, Program, Spl, web3 } from \"@project-serum/anchor\";\nimport {\n Connection,\n Keypair,\n PublicKey,\n SystemProgram,\n Transaction,\n TransactionInstruction,\n TransactionMessageArgs,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { Big } from \"big.js\";\nimport { Chains } from \"../../../chains\";\nimport { Messenger } from \"../../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n AmountNotEnoughError,\n CCTPDoesNotSupportedError,\n JupiterError,\n MethodNotSupportedError,\n OFTDoesNotSupportedError,\n SdkError,\n SdkRootError,\n} from \"../../../exceptions\";\nimport { ChainType, FeePaymentMethod, SwapParams, TokenWithChainDetails, TxFeeParams } from \"../../../models\";\nimport { convertIntAmountToFloat } from \"../../../utils/calculation\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { SwapAndBridgeSolData, SwapAndBridgeSolDataCctpData } from \"../../models/sol\";\nimport { Bridge as BridgeType, IDL as bridgeIdl } from \"../../models/sol/types/bridge\";\nimport { CctpBridge as CctpBridgeType, IDL as cctpBridgeIdl } from \"../../models/sol/types/cctp_bridge\";\nimport { getFeePayer, getMessage, getTokenAccountData, getVUsdAmount } from \"../../utils/sol\";\nimport {\n getAssociatedAccount,\n getAuthorityAccount,\n getBridgeTokenAccount,\n getCctpAccounts,\n getCctpAuthorityAccount,\n getCctpBridgeAccount,\n getCctpBridgeTokenAccount,\n getCctpLockAccount,\n getChainBridgeAccount,\n getConfigAccount,\n getGasUsageAccount,\n getLockAccount,\n getOtherChainTokenAccount,\n getPriceAccount,\n getSendMessageAccount,\n} from \"../../utils/sol/accounts\";\nimport { buildAnchorProvider } from \"../../utils/sol/anchor-provider\";\nimport { addUnitLimitAndUnitPriceToTx, addUnitLimitAndUnitPriceToVersionedTx } from \"../../utils/sol/compute-budget\";\nimport { SendParams, TxSendParamsSol, TxSwapParamsSol } from \"../models\";\nimport { ChainBridgeService } from \"../models/bridge\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport { JupiterService } from \"./jupiter\";\n\nexport interface SolanaBridgeParams {\n wormholeMessengerProgramId: string;\n solanaLookUpTable: string;\n cctpParams: CctpParams;\n jupiterParams: JupiterParams;\n}\n\nexport interface JupiterParams {\n jupiterUrl: string;\n jupiterApiKeyHeader?: string;\n jupiterMaxAccounts?: number;\n}\n\nexport interface CctpParams {\n cctpTransmitterProgramId: string;\n cctpTokenMessengerMinter: string;\n cctpDomains: CctpDomains;\n}\n\n/**\n * Type representing a map of CCTP domains to their corresponding numeric values.\n *\n * @typedef {Record<string, number>} CctpDomains\n * @property {string} chainSymbol - The symbol of the chain representing one of the supported blockchain networks (e.g., \"ETH\" for Ethereum). For more details, see: {@link ChainSymbol}.\n * @property {number} value - The numeric value associated with the specified chain.\n */\nexport type CctpDomains = Record<string, number>;\n\nconst COMPUTE_UNIT_LIMIT = 1000000;\n\nconst JUP_ADD_INDEX = 1.1;\n\nexport class SolanaBridgeService extends ChainBridgeService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n jupiterService: JupiterService;\n\n constructor(\n public solanaRpcUrl: string,\n public params: SolanaBridgeParams,\n public api: AllbridgeCoreClient\n ) {\n super();\n this.jupiterService = new JupiterService(solanaRpcUrl, params.jupiterParams);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildSwapTransaction(\n txSwapParams,\n params.sourceToken.poolAddress,\n params.destinationToken.poolAddress,\n params.txFeeParams\n );\n }\n\n private async buildSwapTransaction(\n params: TxSwapParamsSol,\n poolAddress: string,\n toPoolAddress: string,\n txFeeParams?: TxFeeParams\n ): Promise<VersionedTransaction> {\n const {\n fromAccountAddress,\n amount,\n contractAddress,\n fromTokenAddress,\n toTokenAddress,\n toAccountAddress,\n minimumReceiveAmount,\n } = params;\n const account = fromAccountAddress;\n const bridgeAddress = contractAddress;\n const tokenAddress = fromTokenAddress;\n const receiveTokenAddress = toTokenAddress;\n const receivePoolAddress = toPoolAddress;\n const receiverOriginal = toAccountAddress;\n\n const userAccount = new PublicKey(account);\n const provider = buildAnchorProvider(this.solanaRpcUrl, userAccount.toString());\n const bridge = new Program<BridgeType>(bridgeIdl, bridgeAddress, provider);\n\n const bridgeAuthority = await getAuthorityAccount(bridge.programId);\n const configAccount = await getConfigAccount(bridge.programId);\n\n const sendMint = new PublicKey(tokenAddress);\n const sendBridgeToken = await getBridgeTokenAccount(sendMint, bridge.programId);\n const sendPool = new PublicKey(poolAddress);\n const sendUserToken = await getAssociatedAccount(userAccount, sendMint);\n\n const receiverAccount = new PublicKey(receiverOriginal);\n const receiveMint = new PublicKey(receiveTokenAddress);\n const receiveBridgeToken = await getBridgeTokenAccount(receiveMint, bridge.programId);\n const receivePool = new PublicKey(receivePoolAddress);\n const receiveUserToken = await getAssociatedAccount(receiverAccount, receiveMint);\n\n const preInstructions: TransactionInstruction[] = [\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: COMPUTE_UNIT_LIMIT,\n }),\n ];\n\n const feePayer = getFeePayer(userAccount, txFeeParams);\n\n try {\n await getTokenAccountData(receiveUserToken, provider);\n } catch (e) {\n const associatedProgram = Spl.associatedToken(provider);\n const createReceiveUserTokenInstruction: TransactionInstruction = await associatedProgram.methods\n .create()\n .accounts({\n mint: receiveMint,\n owner: receiverAccount,\n associatedAccount: receiveUserToken,\n })\n .instruction();\n preInstructions.push(createReceiveUserTokenInstruction);\n }\n const transaction = await bridge.methods\n .swap(new BN(amount), new BN(minimumReceiveAmount || 0))\n .accounts({\n payer: userAccount,\n config: configAccount,\n bridgeAuthority,\n user: userAccount,\n sendBridgeToken,\n sendMint,\n sendPool,\n sendUserToken,\n receiveBridgeToken,\n receiveMint,\n receivePool,\n receiveUserToken,\n })\n .preInstructions(preInstructions)\n .transaction();\n\n const connection = provider.connection;\n transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n transaction.feePayer = feePayer;\n await addUnitLimitAndUnitPriceToTx(transaction, txFeeParams, this.solanaRpcUrl);\n return await this.convertToVersionedTransaction(transaction, connection);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n let solTxSendParams = this.addPoolAddress(params, txSendParams);\n\n const isJupiterForStableCoin = solTxSendParams.gasFeePaymentMethod == FeePaymentMethod.WITH_STABLECOIN;\n\n let jupTx;\n if (isJupiterForStableCoin) {\n try {\n const { tx, solTxSendUpdatedParams } = await this.processJup(solTxSendParams, params, true);\n jupTx = tx;\n solTxSendParams = { ...solTxSendParams, ...solTxSendUpdatedParams };\n } catch (e) {\n try {\n const { tx, solTxSendUpdatedParams } = await this.processJup(solTxSendParams, params, false);\n jupTx = tx;\n solTxSendParams = { ...solTxSendParams, ...solTxSendUpdatedParams };\n } catch (e) {\n if (e instanceof SdkRootError) {\n throw e;\n }\n if (e instanceof Error && e.message) {\n throw new JupiterError(`Some error occurred during creation Jupiter swap transaction. ${e.message}`);\n }\n throw new JupiterError(\"Some error occurred during creation Jupiter swap transaction\");\n }\n }\n }\n\n let swapAndBridgeTx: VersionedTransaction;\n let requiredMessageSigner: Keypair | undefined = undefined;\n switch (txSendParams.messenger) {\n case Messenger.ALLBRIDGE: {\n const swapAndBridgeSolData = await this.prepareSwapAndBridgeData(solTxSendParams);\n swapAndBridgeTx = await this.buildSwapAndBridgeAllbridgeTransaction(swapAndBridgeSolData, params.txFeeParams);\n break;\n }\n case Messenger.WORMHOLE: {\n const swapAndBridgeSolData = await this.prepareSwapAndBridgeData(solTxSendParams);\n const { transaction, messageAccount } = await this.buildSwapAndBridgeWormholeTransaction(\n swapAndBridgeSolData,\n params.txFeeParams\n );\n swapAndBridgeTx = transaction;\n requiredMessageSigner = messageAccount;\n break;\n }\n case Messenger.CCTP:\n case Messenger.CCTP_V2: {\n const swapAndBridgeSolData = await this.prepareSwapAndBridgeCctpData(solTxSendParams);\n const { transaction, messageSentEventDataKeypair } = await this.buildSwapAndBridgeCctpTransaction(\n params.destinationToken.chainSymbol,\n swapAndBridgeSolData,\n params.txFeeParams\n );\n swapAndBridgeTx = transaction;\n requiredMessageSigner = messageSentEventDataKeypair;\n break;\n }\n case Messenger.OFT:\n throw new OFTDoesNotSupportedError(\"Messenger OFT is not supported yet.\");\n }\n\n if (isJupiterForStableCoin) {\n if (!jupTx) {\n throw new JupiterError(\"Swap tx is absent\");\n }\n swapAndBridgeTx = await this.jupiterService.amendJupiterWithSdkTx(jupTx, swapAndBridgeTx);\n }\n\n await addUnitLimitAndUnitPriceToVersionedTx(swapAndBridgeTx, params.txFeeParams, this.solanaRpcUrl);\n\n if (requiredMessageSigner) {\n swapAndBridgeTx.sign([requiredMessageSigner]);\n }\n return swapAndBridgeTx;\n }\n\n private async processJup(\n solTxSendParams: SolTxSendParams,\n params: SendParams,\n exactOut: boolean\n ): Promise<{\n tx: VersionedTransaction;\n solTxSendUpdatedParams: {\n amount: string;\n fee: string;\n extraGas?: string;\n gasFeePaymentMethod: FeePaymentMethod;\n };\n }> {\n const { fee, extraGas, gasFeePaymentMethod } = await this.convertStableCoinFeeAndExtraGasToNativeCurrency(\n params.sourceToken,\n solTxSendParams\n );\n\n let amountToProcess = exactOut ? Big(fee) : Big(solTxSendParams.fee);\n if (extraGas) {\n amountToProcess = amountToProcess.plus(extraGas);\n }\n if (!exactOut) {\n amountToProcess = amountToProcess.mul(JUP_ADD_INDEX);\n }\n const feePayer = getFeePayer(new PublicKey(params.fromAccountAddress), params.txFeeParams);\n\n const { tx, amountIn } = await this.jupiterService.getJupiterSwapTx(\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n amountToProcess.toFixed(0),\n exactOut,\n feePayer.toString()\n );\n\n let newAmount: string;\n if (exactOut) {\n if (!amountIn) {\n throw new JupiterError(\"Cannot get inAmount\");\n }\n newAmount = Big(solTxSendParams.amount).minus(Big(amountIn).mul(JUP_ADD_INDEX)).toFixed(0);\n } else {\n newAmount = Big(solTxSendParams.amount).minus(amountToProcess).toFixed(0);\n }\n if (Big(newAmount).lte(0)) {\n throw new AmountNotEnoughError(\n `Amount not enough to pay fee, ${convertIntAmountToFloat(\n Big(newAmount).minus(1).neg(),\n params.sourceToken.decimals\n ).toFixed()} stables is missing`\n );\n }\n return {\n tx: tx,\n solTxSendUpdatedParams: {\n amount: newAmount,\n fee: fee,\n extraGas: extraGas,\n gasFeePaymentMethod: gasFeePaymentMethod,\n },\n };\n }\n\n private addPoolAddress(params: SendParams, txSendParams: TxSendParamsSol): SolTxSendParams {\n return {\n ...txSendParams,\n poolAddress: params.sourceToken.poolAddress,\n };\n }\n\n async convertStableCoinFeeAndExtraGasToNativeCurrency(\n sourceToken: TokenWithChainDetails,\n solTxSendParams: SolTxSendParams\n ): Promise<{ fee: string; extraGas?: string; gasFeePaymentMethod: FeePaymentMethod }> {\n if (solTxSendParams.gasFeePaymentMethod == FeePaymentMethod.WITH_STABLECOIN) {\n const sourceNativeTokenPrice = (\n await this.api.getReceiveTransactionCost({\n sourceChainId: solTxSendParams.fromChainId,\n destinationChainId: solTxSendParams.toChainId,\n messenger: solTxSendParams.messenger,\n sourceToken: sourceToken.tokenAddress,\n })\n ).sourceNativeTokenPrice;\n const fee = Big(solTxSendParams.fee)\n .div(sourceNativeTokenPrice)\n .mul(Big(10).pow(Chains.getChainDecimalsByType(ChainType.SOLANA) - sourceToken.decimals))\n .toFixed(0);\n let extraGas;\n if (solTxSendParams.extraGas) {\n extraGas = Big(solTxSendParams.extraGas)\n .div(sourceNativeTokenPrice)\n .mul(Big(10).pow(Chains.getChainDecimalsByType(ChainType.SOLANA) - sourceToken.decimals))\n .toFixed(0);\n }\n return { fee, extraGas, gasFeePaymentMethod: FeePaymentMethod.WITH_NATIVE_CURRENCY };\n }\n return {\n fee: solTxSendParams.fee,\n extraGas: solTxSendParams.extraGas,\n gasFeePaymentMethod: FeePaymentMethod.WITH_NATIVE_CURRENCY,\n };\n }\n\n private getExtraGasInstruction(\n extraGas: string,\n userAccount: PublicKey,\n configAccount: PublicKey\n ): TransactionInstruction | undefined {\n return web3.SystemProgram.transfer({\n fromPubkey: userAccount,\n toPubkey: configAccount,\n lamports: +extraGas,\n });\n }\n\n private async prepareSwapAndBridgeData(txSendParams: SolTxSendParams): Promise<SwapAndBridgeSolData> {\n const {\n amount,\n contractAddress,\n fromChainId,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n poolAddress,\n extraGas,\n } = txSendParams;\n const tokenAddress = fromTokenAddress;\n const account = fromAccountAddress;\n const destinationChainId = toChainId;\n const receiveTokenAddress = toTokenAddress;\n const receiverInBuffer32 = toAccountAddress;\n const bridgeAddress = contractAddress;\n const sourceChainId = fromChainId;\n\n const provider = buildAnchorProvider(this.solanaRpcUrl, account);\n const bridge = new Program<BridgeType>(bridgeIdl, bridgeAddress, provider);\n const nonce = Array.from(getNonce());\n const poolAccount = new PublicKey(poolAddress);\n const vUsdAmount = await getVUsdAmount(amount, bridge, poolAccount);\n\n const lockAccount = await getLockAccount(nonce, bridge.programId);\n const bridgeAuthority = await getAuthorityAccount(bridge.programId);\n const userToken = await getAssociatedAccount(new PublicKey(account), new PublicKey(tokenAddress));\n const bridgeTokenAccount = await getBridgeTokenAccount(new PublicKey(tokenAddress), bridge.programId);\n const chainBridgeAccount = await getChainBridgeAccount(destinationChainId, bridge.programId);\n const otherBridgeTokenAccount = await getOtherChainTokenAccount(\n destinationChainId,\n Buffer.from(receiveTokenAddress),\n bridge.programId\n );\n\n const configAccount = await getConfigAccount(bridge.programId);\n const configAccountInfo = await bridge.account.config.fetch(configAccount);\n const priceAccount = await getPriceAccount(destinationChainId, configAccountInfo.gasOracleProgramId);\n const thisGasPriceAccount = await getPriceAccount(sourceChainId, configAccountInfo.gasOracleProgramId);\n\n const message = getMessage({\n amount: vUsdAmount,\n recipient: Buffer.from(receiverInBuffer32),\n nonce: Buffer.from(nonce),\n receiveToken: Buffer.from(receiveTokenAddress),\n destinationChainId,\n sourceChainId,\n chainBridge: (await getAuthorityAccount(bridge.programId)).toBuffer(),\n });\n\n const swapAndBridgeData = {} as SwapAndBridgeSolData;\n\n swapAndBridgeData.bridge = bridge;\n swapAndBridgeData.amount = new BN(amount);\n swapAndBridgeData.vusdAmount = new BN(vUsdAmount);\n swapAndBridgeData.nonce = nonce;\n swapAndBridgeData.recipient = Array.from(receiverInBuffer32);\n swapAndBridgeData.receiveToken = Array.from(receiveTokenAddress);\n swapAndBridgeData.poolAccount = poolAccount;\n swapAndBridgeData.lockAccount = lockAccount;\n swapAndBridgeData.bridgeAuthority = bridgeAuthority;\n swapAndBridgeData.userToken = userToken;\n swapAndBridgeData.bridgeTokenAccount = bridgeTokenAccount;\n swapAndBridgeData.chainBridgeAccount = chainBridgeAccount;\n swapAndBridgeData.otherBridgeTokenAccount = otherBridgeTokenAccount;\n swapAndBridgeData.userAccount = new PublicKey(account);\n swapAndBridgeData.destinationChainId = destinationChainId;\n // @ts-expect-error\n swapAndBridgeData.mint = new PublicKey(tokenAddress);\n swapAndBridgeData.config = configAccount;\n swapAndBridgeData.configAccountInfo = configAccountInfo;\n swapAndBridgeData.gasPrice = priceAccount;\n swapAndBridgeData.thisGasPrice = thisGasPriceAccount;\n swapAndBridgeData.message = message;\n\n if (extraGas) {\n swapAndBridgeData.extraGasInstruction = this.getExtraGasInstruction(\n extraGas,\n swapAndBridgeData.userAccount,\n configAccount\n );\n }\n return swapAndBridgeData;\n }\n\n private async buildSwapAndBridgeAllbridgeTransaction(\n swapAndBridgeData: SwapAndBridgeSolData,\n txFeeParams?: TxFeeParams\n ): Promise<VersionedTransaction> {\n const {\n bridge,\n vusdAmount,\n nonce,\n recipient,\n receiveToken,\n poolAccount,\n lockAccount,\n bridgeAuthority,\n userToken,\n bridgeTokenAccount,\n chainBridgeAccount,\n otherBridgeTokenAccount,\n userAccount,\n destinationChainId,\n mint,\n config,\n configAccountInfo,\n gasPrice,\n thisGasPrice,\n message,\n extraGasInstruction,\n } = swapAndBridgeData;\n const allbridgeMessengerProgramId = configAccountInfo.allbridgeMessengerProgramId;\n const messengerGasUsageAccount = await getGasUsageAccount(destinationChainId, allbridgeMessengerProgramId);\n const messengerConfig = await getConfigAccount(allbridgeMessengerProgramId);\n\n const sentMessageAccount = await getSendMessageAccount(message, allbridgeMessengerProgramId);\n\n const instructions: TransactionInstruction[] = [];\n if (extraGasInstruction) {\n instructions.push(extraGasInstruction);\n }\n\n const feePayer = getFeePayer(userAccount, txFeeParams);\n\n const transaction = await bridge.methods\n .swapAndBridge({\n vusdAmount,\n nonce,\n destinationChainId,\n recipient,\n receiveToken,\n })\n .accounts({\n payer: userAccount,\n mint,\n user: userAccount,\n config,\n lock: lockAccount,\n pool: poolAccount,\n gasPrice,\n thisGasPrice,\n bridgeAuthority,\n userToken,\n bridgeToken: bridgeTokenAccount,\n chainBridge: chainBridgeAccount,\n messenger: allbridgeMessengerProgramId,\n messengerGasUsage: messengerGasUsageAccount,\n messengerConfig,\n sentMessageAccount,\n otherBridgeToken: otherBridgeTokenAccount,\n })\n .preInstructions([\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: COMPUTE_UNIT_LIMIT,\n }),\n ])\n .postInstructions(instructions)\n .transaction();\n const connection = buildAnchorProvider(this.solanaRpcUrl, userAccount.toString()).connection;\n transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n transaction.feePayer = feePayer;\n return await this.convertToVersionedTransaction(transaction, connection);\n }\n\n private async convertToVersionedTransaction(tx: Transaction, connection: Connection): Promise<VersionedTransaction> {\n const allbridgeTableAccount = await connection\n .getAddressLookupTable(new PublicKey(this.params.solanaLookUpTable))\n .then((res) => res.value);\n if (!allbridgeTableAccount) {\n throw new SdkError(\"Cannot find allbridgeLookupTableAccount\");\n }\n const messageV0 = new web3.TransactionMessage({\n payerKey: tx.feePayer,\n recentBlockhash: tx.recentBlockhash,\n instructions: tx.instructions,\n } as TransactionMessageArgs).compileToV0Message([allbridgeTableAccount]);\n return new web3.VersionedTransaction(messageV0);\n }\n\n private async buildSwapAndBridgeWormholeTransaction(\n swapAndBridgeData: SwapAndBridgeSolData,\n txFeeParams?: TxFeeParams\n ): Promise<{ transaction: VersionedTransaction; messageAccount: Keypair }> {\n const {\n bridge,\n vusdAmount,\n nonce,\n recipient,\n receiveToken,\n poolAccount,\n lockAccount,\n bridgeAuthority,\n userToken,\n bridgeTokenAccount,\n chainBridgeAccount,\n otherBridgeTokenAccount,\n userAccount,\n destinationChainId,\n mint,\n config,\n configAccountInfo,\n gasPrice,\n thisGasPrice,\n message,\n extraGasInstruction,\n } = swapAndBridgeData;\n const wormholeProgramId = this.params.wormholeMessengerProgramId;\n\n const [whBridgeAccount] = PublicKey.findProgramAddressSync(\n [Buffer.from(\"Bridge\")],\n new PublicKey(wormholeProgramId)\n );\n const [whFeeCollectorAccount] = PublicKey.findProgramAddressSync(\n [Buffer.from(\"fee_collector\")],\n new PublicKey(wormholeProgramId)\n );\n const [whSequenceAccount] = PublicKey.findProgramAddressSync(\n [Buffer.from(\"Sequence\"), bridgeAuthority.toBuffer()],\n new PublicKey(wormholeProgramId)\n );\n\n const messengerGasUsageAccount = await getGasUsageAccount(\n destinationChainId,\n configAccountInfo.wormholeMessengerProgramId\n );\n const wormholeMessengerConfigAccount = await getConfigAccount(configAccountInfo.wormholeMessengerProgramId);\n const messageAccount = Keypair.generate();\n\n const provider = buildAnchorProvider(this.solanaRpcUrl, userAccount.toString());\n\n const bridgeAccountInfo = await provider.connection.getAccountInfo(whBridgeAccount);\n if (bridgeAccountInfo == null) {\n throw new SdkError(\"Cannot fetch wormhole bridge account info\");\n }\n const feeLamports = new BN(bridgeAccountInfo.data.slice(16, 24), \"le\").toString();\n\n const feeInstruction = SystemProgram.transfer({\n fromPubkey: userAccount,\n toPubkey: whFeeCollectorAccount,\n lamports: +feeLamports,\n });\n\n const instructions: TransactionInstruction[] = [];\n if (extraGasInstruction) {\n instructions.push(extraGasInstruction);\n }\n\n const feePayer = getFeePayer(userAccount, txFeeParams);\n\n const accounts = {\n payer: userAccount,\n mint,\n user: userAccount,\n config,\n lock: lockAccount,\n pool: poolAccount,\n gasPrice,\n thisGasPrice,\n bridgeAuthority,\n userToken,\n bridgeToken: bridgeTokenAccount,\n chainBridge: chainBridgeAccount,\n otherBridgeToken: otherBridgeTokenAccount,\n messengerGasUsage: messengerGasUsageAccount,\n wormholeProgram: wormholeProgramId,\n bridge: whBridgeAccount,\n message: messageAccount.publicKey,\n wormholeMessenger: configAccountInfo.wormholeMessengerProgramId,\n sequence: whSequenceAccount,\n feeCollector: whFeeCollectorAccount,\n wormholeMessengerConfig: wormholeMessengerConfigAccount,\n clock: web3.SYSVAR_CLOCK_PUBKEY,\n };\n\n const transaction = await bridge.methods\n .swapAndBridgeWormhole({\n vusdAmount,\n nonce: nonce,\n destinationChainId,\n recipient,\n receiveToken,\n })\n .accounts(accounts)\n .preInstructions([\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: COMPUTE_UNIT_LIMIT,\n }),\n feeInstruction,\n ])\n .postInstructions(instructions)\n .signers([messageAccount])\n .transaction();\n transaction.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;\n transaction.feePayer = feePayer;\n return { transaction: await this.convertToVersionedTransaction(transaction, provider.connection), messageAccount };\n }\n\n private async prepareSwapAndBridgeCctpData(txSendParams: SolTxSendParams): Promise<SwapAndBridgeSolDataCctpData> {\n const {\n contractAddress,\n amount,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n extraGas,\n } = txSendParams;\n const cctpAddress = contractAddress;\n if (!cctpAddress) {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n const CHAIN_ID = 4;\n\n const account = fromAccountAddress;\n const receiveTokenAddress = toTokenAddress;\n const receiverInBuffer32 = toAccountAddress;\n\n const provider = buildAnchorProvider(this.solanaRpcUrl, account);\n const cctpBridge: Program<CctpBridgeType> = new Program<CctpBridgeType>(cctpBridgeIdl, cctpAddress, provider);\n const mint = new PublicKey(fromTokenAddress);\n const cctpBridgeAccount = await getCctpBridgeAccount(mint, cctpBridge.programId);\n const userAccount = new PublicKey(account);\n\n const configAccountInfo = await cctpBridge.account.cctpBridge.fetch(cctpBridgeAccount);\n\n const swapAndBridgeData = {} as SwapAndBridgeSolDataCctpData;\n\n swapAndBridgeData.cctpBridge = cctpBridge;\n swapAndBridgeData.cctpBridgeAccount = cctpBridgeAccount;\n swapAndBridgeData.cctpAddressAccount = new PublicKey(cctpAddress);\n swapAndBridgeData.amount = new BN(amount);\n swapAndBridgeData.recipient = Array.from(receiverInBuffer32);\n swapAndBridgeData.receiveToken = Array.from(receiveTokenAddress);\n swapAndBridgeData.userToken = await getAssociatedAccount(userAccount, mint);\n swapAndBridgeData.bridgeAuthority = await getCctpAuthorityAccount(cctpBridgeAccount, cctpBridge.programId);\n swapAndBridgeData.bridgeTokenAccount = await getCctpBridgeTokenAccount(mint, cctpBridge.programId);\n swapAndBridgeData.chainBridgeAccount = await getChainBridgeAccount(toChainId, cctpBridge.programId);\n swapAndBridgeData.userAccount = userAccount;\n swapAndBridgeData.destinationChainId = toChainId;\n swapAndBridgeData.mint = mint;\n swapAndBridgeData.gasPrice = await getPriceAccount(toChainId, configAccountInfo.gasOracleProgramId);\n swapAndBridgeData.thisGasPrice = await getPriceAccount(CHAIN_ID, configAccountInfo.gasOracleProgramId);\n swapAndBridgeData.provider = provider;\n\n if (extraGas) {\n swapAndBridgeData.extraGasInstruction = this.getExtraGasInstruction(\n extraGas,\n swapAndBridgeData.userAccount,\n cctpBridgeAccount\n );\n }\n return swapAndBridgeData;\n }\n\n async buildSwapAndBridgeCctpTransaction(\n destinationChainSymbol: string,\n swapAndBridgeData: SwapAndBridgeSolDataCctpData,\n txFeeParams?: TxFeeParams\n ): Promise<{ transaction: VersionedTransaction; messageSentEventDataKeypair: Keypair }> {\n const {\n cctpBridge,\n cctpBridgeAccount,\n amount,\n recipient,\n receiveToken,\n bridgeAuthority,\n userToken,\n bridgeTokenAccount,\n chainBridgeAccount,\n userAccount,\n destinationChainId,\n mint,\n gasPrice,\n thisGasPrice,\n extraGasInstruction,\n provider,\n } = swapAndBridgeData;\n const domain = this.params.cctpParams.cctpDomains[destinationChainSymbol];\n const cctpTransmitterProgramIdAddress = this.params.cctpParams.cctpTransmitterProgramId;\n const cctpTokenMessengerMinterAddress = this.params.cctpParams.cctpTokenMessengerMinter;\n if (domain == undefined || !cctpTransmitterProgramIdAddress || !cctpTokenMessengerMinterAddress) {\n throw new SdkError(\"CCTP is not configured\");\n }\n const cctpTransmitterProgramId = new PublicKey(cctpTransmitterProgramIdAddress);\n const cctpTokenMessengerMinter = new PublicKey(cctpTokenMessengerMinterAddress);\n const {\n messageTransmitterAccount,\n tokenMessenger,\n tokenMessengerEventAuthority,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n } = getCctpAccounts(domain, mint, cctpTransmitterProgramId, cctpTokenMessengerMinter);\n\n const instructions: TransactionInstruction[] = [];\n if (extraGasInstruction) {\n instructions.push(extraGasInstruction);\n }\n\n const messageSentEventDataKeypair = Keypair.generate();\n const lockAccount = getCctpLockAccount(cctpBridge.programId, messageSentEventDataKeypair.publicKey);\n\n const feePayer = getFeePayer(userAccount, txFeeParams);\n\n const tx = await cctpBridge.methods\n .bridge({\n amount,\n destinationChainId,\n recipient,\n receiveToken,\n })\n .accounts({\n mint: mint,\n user: userAccount,\n cctpBridge: cctpBridgeAccount,\n payer: userAccount,\n\n messageSentEventData: messageSentEventDataKeypair.publicKey,\n lock: lockAccount,\n\n cctpMessenger: cctpTokenMessengerMinter,\n messageTransmitterProgram: cctpTransmitterProgramId,\n messageTransmitterAccount: messageTransmitterAccount,\n tokenMessenger: tokenMessenger,\n tokenMinter: tokenMinter,\n localToken: localToken,\n remoteTokenMessengerKey: remoteTokenMessengerKey,\n authorityPda: authorityPda,\n eventAuthority: tokenMessengerEventAuthority,\n\n bridgeToken: bridgeTokenAccount,\n gasPrice: gasPrice,\n thisGasPrice: thisGasPrice,\n chainBridge: chainBridgeAccount,\n userToken,\n bridgeAuthority: bridgeAuthority,\n })\n .preInstructions([\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: 2000000,\n }),\n ])\n .postInstructions(instructions)\n .transaction();\n const connection = provider.connection;\n tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n tx.feePayer = feePayer;\n return { transaction: await this.convertToVersionedTransaction(tx, connection), messageSentEventDataKeypair };\n }\n\n send(params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n}\n\ninterface SolTxSendParams extends TxSendParamsSol {\n poolAddress: string;\n}\n"]}
|
|
@@ -6,7 +6,7 @@ export declare class JupiterService {
|
|
|
6
6
|
apiKeyHeader?: string;
|
|
7
7
|
maxAccounts?: number;
|
|
8
8
|
constructor(solanaRpcUrl: string, jupiterParams: JupiterParams);
|
|
9
|
-
getJupiterSwapTx(userAddress: string, stableTokenAddress: string, amount: string, exactOut: boolean): Promise<{
|
|
9
|
+
getJupiterSwapTx(userAddress: string, stableTokenAddress: string, amount: string, exactOut: boolean, payer?: string): Promise<{
|
|
10
10
|
tx: VersionedTransaction;
|
|
11
11
|
amountIn?: string;
|
|
12
12
|
}>;
|
|
@@ -40,7 +40,7 @@ class JupiterService {
|
|
|
40
40
|
this.apiKeyHeader = jupiterParams.jupiterApiKeyHeader;
|
|
41
41
|
this.maxAccounts = jupiterParams.jupiterMaxAccounts;
|
|
42
42
|
}
|
|
43
|
-
async getJupiterSwapTx(userAddress, stableTokenAddress, amount, exactOut) {
|
|
43
|
+
async getJupiterSwapTx(userAddress, stableTokenAddress, amount, exactOut, payer) {
|
|
44
44
|
let quoteResponse;
|
|
45
45
|
try {
|
|
46
46
|
const swapMode = exactOut ? "ExactOut" : "ExactIn";
|
|
@@ -71,6 +71,7 @@ class JupiterService {
|
|
|
71
71
|
quoteResponse: quoteResponse.data,
|
|
72
72
|
userPublicKey: userAddress,
|
|
73
73
|
wrapAndUnwrapSol: true,
|
|
74
|
+
payer: payer,
|
|
74
75
|
}, {
|
|
75
76
|
headers: this.apiKeyHeader ? { "x-api-key": this.apiKeyHeader } : undefined,
|
|
76
77
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jupiter.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/jupiter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAgD;AAChD,6CAAuF;AACvF,+CAA0C;AAC1C,oDAA6D;AAC7D,oDAAiF;AAGjF,MAAa,cAAc;IACzB,UAAU,CAAa;IACvB,UAAU,CAAS;IACnB,YAAY,CAAU;IACtB,WAAW,CAAU;IAErB,YAAY,YAAoB,EAAE,aAA4B;QAC5D,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAU,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,yBAAyB;QACxF,IAAI,CAAC,YAAY,GAAG,aAAa,CAAC,mBAAmB,CAAC;QACtD,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,kBAAkB,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,WAAmB,EACnB,kBAA0B,EAC1B,MAAc,EACd,QAAiB;
|
|
1
|
+
{"version":3,"file":"jupiter.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/jupiter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAgD;AAChD,6CAAuF;AACvF,+CAA0C;AAC1C,oDAA6D;AAC7D,oDAAiF;AAGjF,MAAa,cAAc;IACzB,UAAU,CAAa;IACvB,UAAU,CAAS;IACnB,YAAY,CAAU;IACtB,WAAW,CAAU;IAErB,YAAY,YAAoB,EAAE,aAA4B;QAC5D,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAU,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,yBAAyB;QACxF,IAAI,CAAC,YAAY,GAAG,aAAa,CAAC,mBAAmB,CAAC;QACtD,IAAI,CAAC,WAAW,GAAG,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IAAI,CAAC,SAAS,CAAC,CAAC;YACzC,CAAC;YACD,OAAO,WAAW,CAAC;QACrB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;gBACpC,MAAM,IAAI,yBAAY,CAAC,0EAA0E,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAChH,CAAC;YACD,MAAM,IAAI,yBAAY,CAAC,uEAAuE,CAAC,CAAC;QAClG,CAAC;IACH,CAAC;CACF;AAnHD,wCAmHC","sourcesContent":["import { NATIVE_MINT } from \"@solana/spl-token\";\nimport { Connection, TransactionMessage, VersionedTransaction } from \"@solana/web3.js\";\nimport axios, { AxiosError } from \"axios\";\nimport { JupiterError, SdkError } from \"../../../exceptions\";\nimport { fetchAddressLookupTableAccountsFromTx } from \"../../../utils/sol/utils\";\nimport { JupiterParams } from \"./index\";\n\nexport class JupiterService {\n connection: Connection;\n jupiterUrl: string;\n apiKeyHeader?: string;\n maxAccounts?: number;\n\n constructor(solanaRpcUrl: string, jupiterParams: JupiterParams) {\n this.connection = new Connection(solanaRpcUrl);\n this.jupiterUrl = jupiterParams.jupiterUrl.replace(/\\/$/, \"\"); // trim last \"/\" if exist\n this.apiKeyHeader = jupiterParams.jupiterApiKeyHeader;\n this.maxAccounts = jupiterParams.jupiterMaxAccounts;\n }\n\n async getJupiterSwapTx(\n userAddress: string,\n stableTokenAddress: string,\n amount: string,\n exactOut: boolean,\n payer?: string\n ): Promise<{ tx: VersionedTransaction; amountIn?: string }> {\n let quoteResponse: any;\n try {\n const swapMode = exactOut ? \"ExactOut\" : \"ExactIn\";\n let url = `${this.jupiterUrl}/quote?inputMint=${stableTokenAddress}&outputMint=${NATIVE_MINT.toString()}&amount=${amount}&swapMode=${swapMode}&slippageBps=100&onlyDirectRoutes=true`;\n\n if (this.maxAccounts) {\n url += `&maxAccounts=${this.maxAccounts}`;\n }\n quoteResponse = await axios.get(url, {\n headers: this.apiKeyHeader ? { \"x-api-key\": this.apiKeyHeader } : undefined,\n });\n } catch (err) {\n if (err instanceof AxiosError && err.response && err.response.data && err.response.data.error) {\n throw new JupiterError(err.response.data.error);\n }\n throw new JupiterError(\"Cannot get route\");\n }\n\n let inAmount;\n if (exactOut && quoteResponse?.data?.inAmount) {\n inAmount = quoteResponse.data.inAmount;\n } else if (exactOut) {\n throw new JupiterError(\"Cannot get inAmount\");\n }\n\n let transactionResponse: any;\n try {\n transactionResponse = await axios.post(\n `${this.jupiterUrl}/swap`,\n {\n quoteResponse: quoteResponse.data,\n userPublicKey: userAddress,\n wrapAndUnwrapSol: true,\n payer: payer,\n },\n {\n headers: this.apiKeyHeader ? { \"x-api-key\": this.apiKeyHeader } : undefined,\n }\n );\n } catch (err) {\n if (err instanceof AxiosError && err.response && err.response.data && err.response.data.error) {\n throw new JupiterError(err.response.data.error);\n }\n throw new JupiterError(\"Cannot get swap transaction\");\n }\n\n let swapTransaction;\n if (transactionResponse?.data?.swapTransaction) {\n swapTransaction = transactionResponse.data.swapTransaction;\n } else {\n throw new JupiterError(\"Cannot get swap transaction\");\n }\n\n const swapTransactionBuf = Buffer.from(swapTransaction, \"base64\");\n const tx = VersionedTransaction.deserialize(swapTransactionBuf);\n\n return exactOut ? { tx, amountIn: inAmount } : { tx };\n }\n\n async amendJupiterWithSdkTx(\n transaction: VersionedTransaction,\n sdkTx: VersionedTransaction\n ): Promise<VersionedTransaction> {\n try {\n const addressLookupTableAccounts = await fetchAddressLookupTableAccountsFromTx(transaction, this.connection);\n const sdkAddressLookupTableAccounts = await fetchAddressLookupTableAccountsFromTx(sdkTx, this.connection);\n\n const message = TransactionMessage.decompile(transaction.message, {\n addressLookupTableAccounts: addressLookupTableAccounts,\n });\n const sdkMessage = TransactionMessage.decompile(sdkTx.message, {\n addressLookupTableAccounts: sdkAddressLookupTableAccounts,\n });\n sdkMessage.instructions.shift();\n message.instructions.push(...sdkMessage.instructions);\n\n addressLookupTableAccounts.push(...sdkAddressLookupTableAccounts);\n\n transaction.message = message.compileToV0Message(addressLookupTableAccounts);\n\n if (sdkTx.message.header.numRequiredSignatures === 2 && transaction.signatures.length === 1) {\n const signature = sdkTx.signatures[0];\n if (!signature) {\n throw new SdkError(\"Signature is undefined\");\n }\n transaction.signatures.push(signature);\n }\n return transaction;\n } catch (e) {\n if (e instanceof Error && e.message) {\n throw new JupiterError(`Some error occurred during creation final swap and bridge transaction. ${e.message}`);\n }\n throw new JupiterError(\"Some error occurred during creation final swap and bridge transaction\");\n }\n }\n}\n"]}
|
|
@@ -7,9 +7,10 @@ const chain_enums_1 = require("../../../chains/chain.enums");
|
|
|
7
7
|
const exceptions_1 = require("../../../exceptions");
|
|
8
8
|
const index_1 = require("../../../index");
|
|
9
9
|
const models_1 = require("../../../models");
|
|
10
|
+
const utils_1 = require("../../../utils/utils");
|
|
10
11
|
const bridge_contract_1 = require("../../models/srb/bridge-contract");
|
|
11
12
|
const models_2 = require("../models");
|
|
12
|
-
const
|
|
13
|
+
const utils_2 = require("../utils");
|
|
13
14
|
class SrbBridgeService extends models_2.ChainBridgeService {
|
|
14
15
|
nodeRpcUrlsConfig;
|
|
15
16
|
params;
|
|
@@ -22,7 +23,7 @@ class SrbBridgeService extends models_2.ChainBridgeService {
|
|
|
22
23
|
this.api = api;
|
|
23
24
|
}
|
|
24
25
|
async buildRawTransactionSend(params) {
|
|
25
|
-
const txSendParams = await (0,
|
|
26
|
+
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
26
27
|
return await this.buildRawTransactionSendFromParams(txSendParams);
|
|
27
28
|
}
|
|
28
29
|
async buildRawTransactionSendFromParams(params) {
|
|
@@ -33,36 +34,43 @@ class SrbBridgeService extends models_2.ChainBridgeService {
|
|
|
33
34
|
}
|
|
34
35
|
const contract = this.getContract(bridge_contract_1.BridgeContract, contractAddress, fromAccountAddress);
|
|
35
36
|
let tx;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
37
|
+
switch (gasFeePaymentMethod) {
|
|
38
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY:
|
|
39
|
+
tx = await contract.swap_and_bridge({
|
|
40
|
+
sender: fromAccountAddress,
|
|
41
|
+
token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
|
|
42
|
+
amount: BigInt(amount),
|
|
43
|
+
recipient: Buffer.from(toAccountAddress),
|
|
44
|
+
destination_chain_id: +toChainId,
|
|
45
|
+
receive_token: Buffer.from(toTokenAddress),
|
|
46
|
+
nonce: (0, utils_2.getNonceBigInt)(),
|
|
47
|
+
gas_amount: BigInt(totalFee),
|
|
48
|
+
fee_token_amount: BigInt(0),
|
|
49
|
+
});
|
|
50
|
+
break;
|
|
51
|
+
case models_1.FeePaymentMethod.WITH_STABLECOIN:
|
|
52
|
+
tx = await contract.swap_and_bridge({
|
|
53
|
+
sender: fromAccountAddress,
|
|
54
|
+
token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
|
|
55
|
+
amount: BigInt(amount),
|
|
56
|
+
recipient: Buffer.from(toAccountAddress),
|
|
57
|
+
destination_chain_id: +toChainId,
|
|
58
|
+
receive_token: Buffer.from(toTokenAddress),
|
|
59
|
+
nonce: (0, utils_2.getNonceBigInt)(),
|
|
60
|
+
gas_amount: BigInt(0),
|
|
61
|
+
fee_token_amount: BigInt(totalFee),
|
|
62
|
+
});
|
|
63
|
+
break;
|
|
64
|
+
case models_1.FeePaymentMethod.WITH_ARB:
|
|
65
|
+
throw new exceptions_1.SdkError("SRB bridge does not support ARB0 payment method");
|
|
66
|
+
default: {
|
|
67
|
+
return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
68
|
+
}
|
|
61
69
|
}
|
|
62
70
|
return tx.toXDR();
|
|
63
71
|
}
|
|
64
72
|
async buildRawTransactionSwap(params) {
|
|
65
|
-
const txSwapParams = (0,
|
|
73
|
+
const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
|
|
66
74
|
return await this.buildRawTransactionSwapFromParams(txSwapParams);
|
|
67
75
|
}
|
|
68
76
|
async buildRawTransactionSwapFromParams(params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,mCAA6B;AAC7B,6DAA0D;AAE1D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,mCAA6B;AAC7B,6DAA0D;AAE1D,oDAAwE;AACxE,0CAAoE;AACpE,4CAAmD;AACnD,gDAAmD;AAGnD,sEAAkE;AAClE,sCAAyG;AACzG,oCAAoF;AAGpF,MAAa,gBAAiB,SAAQ,2BAAkB;IAI3C;IACA;IACA;IALX,SAAS,GAAkB,iBAAS,CAAC,GAAG,CAAC;IAEzC,YACW,iBAAoC,EACpC,MAA+B,EAC/B,GAAwB;QAEjC,KAAK,EAAE,CAAC;QAJC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,QAAG,GAAH,GAAG,CAAqB;IAGnC,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjF,OAAO,MAAM,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ACvF,OAAO,CACL,MAAM,QAAQ,CAAC,IAAI,CAAC;YAClB,MAAM,EAAE,kBAAkB;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,KAAK,EAAE,qBAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,QAAQ,EAAE;YACjE,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC;YAC1C,SAAS,EAAE,gBAAgB;YAC3B,kBAAkB,EAAE,MAAM,CAAC,oBAAoB,CAAC;SACjD,CAAC,CACH,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,6DAA6D;IAC7D,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;IAEO,WAAW,CAAI,QAAgD,EAAE,OAAe,EAAE,MAAe;QACvG,MAAM,MAAM,GAA0B;YACpC,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,yBAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AAnHD,4CAmHC","sourcesContent":["import { Address, contract } from \"@stellar/stellar-sdk\";\nimport { Big } from \"big.js\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainType } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeContract } from \"../../models/srb/bridge-contract\";\nimport { ChainBridgeService, SendParams, SwapParams, TxSendParamsSrb, TxSwapParamsSol } from \"../models\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\n\nexport class SrbBridgeService extends ChainBridgeService {\n chainType: ChainType.SRB = ChainType.SRB;\n\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions,\n readonly api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return await this.buildRawTransactionSendFromParams(txSendParams);\n }\n\n async buildRawTransactionSendFromParams(params: TxSendParamsSrb): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n let tx;\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(totalFee),\n fee_token_amount: BigInt(0),\n });\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(0),\n fee_token_amount: BigInt(totalFee),\n });\n break;\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"SRB bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return tx.toXDR();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsSol): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n return (\n await contract.swap({\n sender: fromAccountAddress,\n amount: BigInt(amount),\n token: Address.contract(Buffer.from(fromTokenAddress)).toBuffer(),\n receive_token: Buffer.from(toTokenAddress),\n recipient: toAccountAddress,\n receive_amount_min: BigInt(minimumReceiveAmount),\n })\n ).toXDR();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n send(params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n private getContract<T>(contract: new (args: ContractClientOptions) => T, address: string, sender?: string): T {\n const config: ContractClientOptions = {\n publicKey: sender,\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new contract(config);\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChainType } from "../../../chains/chain.enums";
|
|
2
|
+
import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
|
|
3
|
+
import { AllbridgeCoreSdkOptions } from "../../../index";
|
|
4
|
+
import { RawStxTransaction, TransactionResponse } from "../../models";
|
|
5
|
+
import { ChainBridgeService, SendParams, SwapParams } from "../models";
|
|
6
|
+
export declare class StxBridgeService extends ChainBridgeService {
|
|
7
|
+
nodeRpcUrl: string;
|
|
8
|
+
params: AllbridgeCoreSdkOptions;
|
|
9
|
+
api: AllbridgeCoreClient;
|
|
10
|
+
chainType: ChainType.STX;
|
|
11
|
+
private client;
|
|
12
|
+
constructor(nodeRpcUrl: string, params: AllbridgeCoreSdkOptions, api: AllbridgeCoreClient);
|
|
13
|
+
send(_params: SendParams): Promise<TransactionResponse>;
|
|
14
|
+
buildRawTransactionSend(params: SendParams): Promise<RawStxTransaction>;
|
|
15
|
+
buildRawTransactionSwap(params: SwapParams): Promise<RawStxTransaction>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StxBridgeService = void 0;
|
|
4
|
+
const core_1 = require("@clarigen/core");
|
|
5
|
+
const network_1 = require("@stacks/network");
|
|
6
|
+
const transactions_1 = require("@stacks/transactions");
|
|
7
|
+
const chain_enums_1 = require("../../../chains/chain.enums");
|
|
8
|
+
const exceptions_1 = require("../../../exceptions");
|
|
9
|
+
const models_1 = require("../../../models");
|
|
10
|
+
const utils_1 = require("../../../utils/utils");
|
|
11
|
+
const clarigen_types_1 = require("../../models/stx/clarigen-types");
|
|
12
|
+
const get_token_name_1 = require("../../utils/stx/get-token-name");
|
|
13
|
+
const post_conditions_1 = require("../../utils/stx/post-conditions");
|
|
14
|
+
const models_2 = require("../models");
|
|
15
|
+
const utils_2 = require("../utils");
|
|
16
|
+
class StxBridgeService extends models_2.ChainBridgeService {
|
|
17
|
+
nodeRpcUrl;
|
|
18
|
+
params;
|
|
19
|
+
api;
|
|
20
|
+
chainType = chain_enums_1.ChainType.STX;
|
|
21
|
+
client;
|
|
22
|
+
constructor(nodeRpcUrl, params, api) {
|
|
23
|
+
super();
|
|
24
|
+
this.nodeRpcUrl = nodeRpcUrl;
|
|
25
|
+
this.params = params;
|
|
26
|
+
this.api = api;
|
|
27
|
+
const network = (0, network_1.createNetwork)({
|
|
28
|
+
network: this.params.stxIsTestnet ? "testnet" : "mainnet",
|
|
29
|
+
client: { baseUrl: this.nodeRpcUrl },
|
|
30
|
+
apiKey: this.params.stxHeroApiKey,
|
|
31
|
+
});
|
|
32
|
+
this.client = new core_1.ClarigenClient(network, this.params.stxHeroApiKey);
|
|
33
|
+
}
|
|
34
|
+
send(_params) {
|
|
35
|
+
throw new exceptions_1.MethodNotSupportedError();
|
|
36
|
+
}
|
|
37
|
+
async buildRawTransactionSend(params) {
|
|
38
|
+
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
39
|
+
const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;
|
|
40
|
+
const amount = BigInt(txSendParams.amount);
|
|
41
|
+
const postFungiblePostCondition = (0, post_conditions_1.getFungiblePostCondition)(amount, "lte", params.fromAccountAddress, params.sourceToken.tokenAddress, (0, get_token_name_1.getTokenName)(params.sourceToken));
|
|
42
|
+
const postStxPostCondition = (0, post_conditions_1.getStxPostCondition)(0, "gte", params.sourceToken.bridgeAddress);
|
|
43
|
+
const postConditions = [postFungiblePostCondition, postStxPostCondition];
|
|
44
|
+
let totalFee = BigInt(txSendParams.fee);
|
|
45
|
+
if (txSendParams.extraGas) {
|
|
46
|
+
totalFee = totalFee + BigInt(txSendParams.extraGas);
|
|
47
|
+
}
|
|
48
|
+
let feeTokenAmount;
|
|
49
|
+
let feeNativeAmount;
|
|
50
|
+
switch (txSendParams.gasFeePaymentMethod) {
|
|
51
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
52
|
+
feeTokenAmount = 0n;
|
|
53
|
+
feeNativeAmount = totalFee;
|
|
54
|
+
const postUserStxPostCondition = (0, post_conditions_1.getStxPostCondition)(totalFee, "lte", params.fromAccountAddress);
|
|
55
|
+
postConditions.push(postUserStxPostCondition);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
59
|
+
feeTokenAmount = totalFee;
|
|
60
|
+
feeNativeAmount = 0n;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case models_1.FeePaymentMethod.WITH_ARB:
|
|
64
|
+
throw new exceptions_1.SdkError("STX bridge does not support ARB0 payment method");
|
|
65
|
+
default: {
|
|
66
|
+
return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const [contractPrincipal] = (0, transactions_1.parseContractId)(bridgeAddress);
|
|
70
|
+
const bridge = (0, core_1.contractFactory)(clarigen_types_1.stacksContracts.bridge, bridgeAddress);
|
|
71
|
+
const { contractAddress, contractName, functionName, functionArgs } = bridge.swapAndBridge({
|
|
72
|
+
ftRef: params.sourceToken.tokenAddress,
|
|
73
|
+
poolRef: params.sourceToken.poolAddress,
|
|
74
|
+
messengerRef: `${contractPrincipal}.messenger`,
|
|
75
|
+
gasOracleRef: `${contractPrincipal}.gas-oracle`,
|
|
76
|
+
amount,
|
|
77
|
+
recipient: Uint8Array.from(toAccountAddress),
|
|
78
|
+
destinationChainId: toChainId,
|
|
79
|
+
receiveToken: Uint8Array.from(toTokenAddress),
|
|
80
|
+
nonce: Uint8Array.from((0, utils_2.getNonce)()),
|
|
81
|
+
messengerId: messenger,
|
|
82
|
+
feeNativeAmount: feeNativeAmount,
|
|
83
|
+
feeTokenAmount: feeTokenAmount,
|
|
84
|
+
});
|
|
85
|
+
const privateKey = (0, transactions_1.makeRandomPrivKey)();
|
|
86
|
+
const publicKey = (0, transactions_1.privateKeyToPublic)(privateKey);
|
|
87
|
+
const txOptions = {
|
|
88
|
+
contractAddress,
|
|
89
|
+
contractName,
|
|
90
|
+
functionName,
|
|
91
|
+
functionArgs,
|
|
92
|
+
publicKey,
|
|
93
|
+
validateWithAbi: true,
|
|
94
|
+
network: this.client.network,
|
|
95
|
+
postConditions,
|
|
96
|
+
postConditionMode: transactions_1.PostConditionMode.Deny,
|
|
97
|
+
};
|
|
98
|
+
const transaction = await (0, transactions_1.makeUnsignedContractCall)(txOptions);
|
|
99
|
+
return transaction.serialize();
|
|
100
|
+
}
|
|
101
|
+
async buildRawTransactionSwap(params) {
|
|
102
|
+
const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
|
|
103
|
+
const amount = BigInt(txSwapParams.amount);
|
|
104
|
+
const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);
|
|
105
|
+
const bridgeAddress = params.sourceToken.bridgeAddress;
|
|
106
|
+
const bridge = (0, core_1.contractFactory)(clarigen_types_1.stacksContracts.bridge, bridgeAddress);
|
|
107
|
+
const { contractAddress, contractName, functionName, functionArgs } = bridge.swap({
|
|
108
|
+
amount,
|
|
109
|
+
sendPoolRef: params.sourceToken.poolAddress,
|
|
110
|
+
sendFtRef: params.sourceToken.tokenAddress,
|
|
111
|
+
receivePoolRef: params.destinationToken.poolAddress,
|
|
112
|
+
receiveFtRef: params.destinationToken.tokenAddress,
|
|
113
|
+
recipient: params.toAccountAddress,
|
|
114
|
+
receiveAmountMin: minimumReceiveAmount,
|
|
115
|
+
});
|
|
116
|
+
const privateKey = (0, transactions_1.makeRandomPrivKey)();
|
|
117
|
+
const publicKey = (0, transactions_1.privateKeyToPublic)(privateKey);
|
|
118
|
+
const postFungibleCondition = (0, post_conditions_1.getFungiblePostCondition)(amount, "lte", params.fromAccountAddress, params.sourceToken.tokenAddress, (0, get_token_name_1.getTokenName)(params.sourceToken));
|
|
119
|
+
const postFungibleMinReceiveCondition = (0, post_conditions_1.getFungiblePostCondition)(minimumReceiveAmount, "gte", params.destinationToken.poolAddress, params.destinationToken.tokenAddress, (0, get_token_name_1.getTokenName)(params.destinationToken));
|
|
120
|
+
const txOptions = {
|
|
121
|
+
contractAddress,
|
|
122
|
+
contractName,
|
|
123
|
+
functionName,
|
|
124
|
+
functionArgs,
|
|
125
|
+
publicKey,
|
|
126
|
+
validateWithAbi: true,
|
|
127
|
+
network: this.client.network,
|
|
128
|
+
postConditions: [postFungibleCondition, postFungibleMinReceiveCondition],
|
|
129
|
+
postConditionMode: transactions_1.PostConditionMode.Deny,
|
|
130
|
+
};
|
|
131
|
+
const transaction = await (0, transactions_1.makeUnsignedContractCall)(txOptions);
|
|
132
|
+
return transaction.serialize();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.StxBridgeService = StxBridgeService;
|
|
136
|
+
//# sourceMappingURL=index.js.map
|