@allbridge/bridge-core-sdk 3.31.0-alpha.1 → 3.31.0-alpha.2
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 +2 -2
- package/dist/browser/index.js.map +3 -3
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +3 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +3 -3
- package/dist/src/services/bridge/sol/payer-with-token-service.d.ts +1 -0
- package/dist/src/services/bridge/sol/payer-with-token-service.js +76 -18
- package/dist/src/services/bridge/sol/payer-with-token-service.js.map +1 -1
- package/dist/src/services/models/sol/types/payer_with_token.d.ts +1343 -597
- package/dist/src/services/models/sol/types/payer_with_token.js.map +1 -1
- package/dist/src/services/models/sol/types/payer_with_token.json +378 -0
- package/dist/src/tokens-info/tokens-info.model.d.ts +8 -8
- package/dist/src/tokens-info/tokens-info.model.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 +1 -1
|
@@ -31,7 +31,6 @@ const core_api_model_1 = require("../../../client/core-api/core-api.model");
|
|
|
31
31
|
const exceptions_1 = require("../../../exceptions");
|
|
32
32
|
const utils_1 = require("../../../utils/utils");
|
|
33
33
|
const bridgeIdl = __importStar(require("../../models/sol/types/bridge.json"));
|
|
34
|
-
const cctpBridgeIdl = __importStar(require("../../models/sol/types/cctp_bridge.json"));
|
|
35
34
|
const payerWithTokenIdl = __importStar(require("../../models/sol/types/payer_with_token.json"));
|
|
36
35
|
const sol_1 = require("../../utils/sol");
|
|
37
36
|
const accounts_1 = require("../../utils/sol/accounts");
|
|
@@ -60,11 +59,14 @@ class PayerWithTokenService {
|
|
|
60
59
|
const swapAndBridgeData = await this.prepareSwapAndBridgeWormholeData(params, solTxSendParams);
|
|
61
60
|
return await this.buildSwapAndBridgeWormholeTx(swapAndBridgeData);
|
|
62
61
|
}
|
|
63
|
-
case core_api_model_1.Messenger.CCTP:
|
|
64
|
-
case core_api_model_1.Messenger.CCTP_V2: {
|
|
62
|
+
case core_api_model_1.Messenger.CCTP: {
|
|
65
63
|
const bridgeCctpData = await this.prepareBridgeCctpData(params, solTxSendParams);
|
|
66
64
|
return this.buildBridgeCctpTx(bridgeCctpData);
|
|
67
65
|
}
|
|
66
|
+
case core_api_model_1.Messenger.CCTP_V2: {
|
|
67
|
+
const bridgeCctpData = await this.prepareBridgeCctpData(params, solTxSendParams);
|
|
68
|
+
return this.buildBridgeCctpV2Tx(bridgeCctpData);
|
|
69
|
+
}
|
|
68
70
|
case core_api_model_1.Messenger.X_RESERVE:
|
|
69
71
|
throw new exceptions_1.SdkError("Messenger xReserve is not supported yet.");
|
|
70
72
|
case core_api_model_1.Messenger.OFT:
|
|
@@ -232,30 +234,44 @@ class PayerWithTokenService {
|
|
|
232
234
|
}
|
|
233
235
|
async prepareBridgeCctpData(params, solTxSendParams) {
|
|
234
236
|
const baseData = await this.prepareSwapAndBridgeBaseData(params, solTxSendParams);
|
|
235
|
-
const { mintAccount
|
|
237
|
+
const { mintAccount } = baseData;
|
|
236
238
|
const { amount, toChainId } = solTxSendParams;
|
|
237
|
-
const cctpAddress = params.sourceToken.cctpAddress;
|
|
238
|
-
if (!cctpAddress) {
|
|
239
|
-
throw new exceptions_1.CCTPDoesNotSupportedError("Such route does not support CCTP protocol");
|
|
240
|
-
}
|
|
241
|
-
const cctpBridge = new anchor_1.Program({ ...cctpBridgeIdl, address: cctpAddress }, provider);
|
|
242
|
-
const chainBridgeAccount = await (0, accounts_1.getChainBridgeAccount)(toChainId, cctpBridge.programId);
|
|
243
|
-
const cctpBridgeProgramId = cctpBridge.programId;
|
|
244
|
-
const cctpBridgeConfigAccount = await (0, accounts_1.getCctpBridgeAccount)(mintAccount, cctpBridge.programId);
|
|
245
|
-
const cctpBridgeAuthorityAccount = await (0, accounts_1.getCctpAuthorityAccount)(cctpBridgeConfigAccount, cctpBridge.programId);
|
|
246
|
-
const cctpBridgeTokenAccount = await (0, accounts_1.getBridgeTokenAccount)(mintAccount, cctpBridge.programId);
|
|
247
239
|
const destinationChainSymbol = params.destinationToken.chainSymbol;
|
|
248
240
|
const domain = this.params.cctpParams.cctpDomains[destinationChainSymbol];
|
|
249
|
-
|
|
250
|
-
|
|
241
|
+
let cctpVersion;
|
|
242
|
+
let cctpAddress;
|
|
243
|
+
let cctpTransmitterProgramIdAddress;
|
|
244
|
+
let cctpTokenMessengerMinterAddress;
|
|
245
|
+
if (params.messenger === core_api_model_1.Messenger.CCTP) {
|
|
246
|
+
cctpVersion = 1;
|
|
247
|
+
cctpAddress = params.sourceToken.cctpAddress;
|
|
248
|
+
cctpTransmitterProgramIdAddress = this.params.cctpParams.cctpTransmitterProgramId;
|
|
249
|
+
cctpTokenMessengerMinterAddress = this.params.cctpParams.cctpTokenMessengerMinter;
|
|
250
|
+
}
|
|
251
|
+
else if (params.messenger === core_api_model_1.Messenger.CCTP_V2) {
|
|
252
|
+
cctpVersion = 2;
|
|
253
|
+
cctpAddress = params.sourceToken.cctpV2Address;
|
|
254
|
+
cctpTransmitterProgramIdAddress = this.params.cctpParams.cctpV2TransmitterProgramId;
|
|
255
|
+
cctpTokenMessengerMinterAddress = this.params.cctpParams.cctpV2TokenMessengerMinter;
|
|
256
|
+
}
|
|
251
257
|
if (domain == undefined || !cctpTransmitterProgramIdAddress || !cctpTokenMessengerMinterAddress) {
|
|
252
|
-
throw new exceptions_1.SdkError(
|
|
258
|
+
throw new exceptions_1.SdkError(`CCTP ${cctpVersion} is not configured`);
|
|
259
|
+
}
|
|
260
|
+
if (!cctpAddress) {
|
|
261
|
+
throw new exceptions_1.CCTPDoesNotSupportedError(`Such route does not support CCTP ${cctpVersion} protocol`);
|
|
253
262
|
}
|
|
263
|
+
const cctpBridgeProgramId = new web3_js_1.PublicKey(cctpAddress);
|
|
264
|
+
const cctpBridgeConfigAccount = cctpVersion === 1
|
|
265
|
+
? await (0, accounts_1.getCctpBridgeAccount)(mintAccount, cctpBridgeProgramId)
|
|
266
|
+
: (0, accounts_1.getCctpV2BridgeConfigAccount)(mintAccount, cctpBridgeProgramId);
|
|
267
|
+
const chainBridgeAccount = await (0, accounts_1.getChainBridgeAccount)(toChainId, cctpBridgeProgramId);
|
|
268
|
+
const cctpBridgeAuthorityAccount = await (0, accounts_1.getCctpAuthorityAccount)(cctpBridgeConfigAccount, cctpBridgeProgramId);
|
|
269
|
+
const cctpBridgeTokenAccount = await (0, accounts_1.getBridgeTokenAccount)(mintAccount, cctpBridgeProgramId);
|
|
254
270
|
const cctpTransmitterProgramId = new web3_js_1.PublicKey(cctpTransmitterProgramIdAddress);
|
|
255
271
|
const cctpTokenMessengerMinter = new web3_js_1.PublicKey(cctpTokenMessengerMinterAddress);
|
|
256
272
|
const { messageTransmitterAccount, tokenMessenger, tokenMessengerEventAuthority, tokenMinter, localToken, remoteTokenMessengerKey, authorityPda, } = (0, accounts_1.getCctpAccounts)(domain, mintAccount, cctpTransmitterProgramId, cctpTokenMessengerMinter);
|
|
257
273
|
const messageSentEventDataKeypair = web3_js_1.Keypair.generate();
|
|
258
|
-
const lockAccount = (0, accounts_1.getCctpLockAccount)(
|
|
274
|
+
const lockAccount = (0, accounts_1.getCctpLockAccount)(cctpBridgeProgramId, messageSentEventDataKeypair.publicKey);
|
|
259
275
|
return {
|
|
260
276
|
...baseData,
|
|
261
277
|
lockAccount,
|
|
@@ -400,6 +416,48 @@ class PayerWithTokenService {
|
|
|
400
416
|
requiredMessageSigner: messageSentEventDataKeypair,
|
|
401
417
|
};
|
|
402
418
|
}
|
|
419
|
+
async buildBridgeCctpV2Tx(bridgeCctpData) {
|
|
420
|
+
const { provider, payerProgram, amount, recipient, recipientToken, userAccount, recipientChain, maxFeeAmount, extraGasAmountInFeeToken, lockAccount, mintAccount, feeTokenMintAccount, userTokenAccount, userFeeTokenAccount, gasPriceAccount, thisGasPriceAccount, chainBridgeAccount, cctpBridgeProgramId, cctpBridgeAuthorityAccount, cctpBridgeConfigAccount, cctpBridgeTokenAccount, cctpTokenMessengerMinter, cctpTransmitterProgramId, messageTransmitterAccount, tokenMessenger, tokenMessengerEventAuthority, tokenMinter, localToken, remoteTokenMessengerKey, authorityPda, messageSentEventDataKeypair, } = bridgeCctpData;
|
|
421
|
+
const transaction = await payerProgram.methods
|
|
422
|
+
.bridgeCctpV2({
|
|
423
|
+
amount,
|
|
424
|
+
recipient,
|
|
425
|
+
receiveToken: recipientToken,
|
|
426
|
+
destinationChainId: recipientChain,
|
|
427
|
+
maxFeeAmount,
|
|
428
|
+
extraGasAmountInFeeToken,
|
|
429
|
+
})
|
|
430
|
+
.accounts({
|
|
431
|
+
mint: mintAccount,
|
|
432
|
+
feeTokenMint: feeTokenMintAccount,
|
|
433
|
+
userFeeTokenAccount,
|
|
434
|
+
bridgeToken: cctpBridgeTokenAccount,
|
|
435
|
+
cctpBridge: cctpBridgeProgramId,
|
|
436
|
+
tokenMessengerMinterProgram: cctpTokenMessengerMinter,
|
|
437
|
+
messageTransmitterProgram: cctpTransmitterProgramId,
|
|
438
|
+
messageTransmitterAccount: messageTransmitterAccount,
|
|
439
|
+
tokenMessenger,
|
|
440
|
+
tokenMinter,
|
|
441
|
+
localToken,
|
|
442
|
+
remoteTokenMessenger: remoteTokenMessengerKey,
|
|
443
|
+
authorityPda,
|
|
444
|
+
eventAuthority: tokenMessengerEventAuthority,
|
|
445
|
+
messageSentEventData: messageSentEventDataKeypair.publicKey,
|
|
446
|
+
lock: lockAccount,
|
|
447
|
+
cctpBridgeConfig: cctpBridgeConfigAccount,
|
|
448
|
+
gasPrice: gasPriceAccount,
|
|
449
|
+
thisGasPrice: thisGasPriceAccount,
|
|
450
|
+
chainBridge: chainBridgeAccount,
|
|
451
|
+
bridgeAuthority: cctpBridgeAuthorityAccount,
|
|
452
|
+
userTokenAccount,
|
|
453
|
+
})
|
|
454
|
+
.preInstructions([this.getComputeUnitLimitInstruction()])
|
|
455
|
+
.transaction();
|
|
456
|
+
return {
|
|
457
|
+
tx: await this.finalizeTransaction(transaction, provider, userAccount),
|
|
458
|
+
requiredMessageSigner: messageSentEventDataKeypair,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
403
461
|
async finalizeTransaction(transaction, provider, userAccount) {
|
|
404
462
|
const connection = provider.connection;
|
|
405
463
|
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payer-with-token-service.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/payer-with-token-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAgE;AAChE,6CAAkH;AAClH,6DAAwD;AACxD,4EAAoE;AAEpE,oDAK6B;AAC7B,gDAAmD;AAEnD,8EAAgE;AAEhE,uFAAyE;AAEzE,gGAAkF;AAClF,yCAA4D;AAC5D,uDAekC;AAClC,qEAAsE;AAEtE,oCAAoC;AAEpC,mCAAyE;AAiFzE,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAErC,MAAa,qBAAqB;IAIvB;IACA;IACA;IALT,SAAS,GAAqB,uBAAS,CAAC,MAAM,CAAC;IAE/C,YACS,YAAoB,EACpB,MAA0B,EAC1B,GAAwB;QAFxB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,WAAM,GAAN,MAAM,CAAoB;QAC1B,QAAG,GAAH,GAAG,CAAqB;IAC9B,CAAC;IAEJ,KAAK,CAAC,uBAAuB,CAC3B,MAAkB,EAClB,eAAgC;QAEhC,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC;YACzB,KAAK,0BAAS,CAAC,SAAS,CAAC,CAAC,CAAC;gBACzB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,iCAAiC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;gBAChG,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;gBAC9D,OAAO,EAAE,EAAE,EAAE,CAAC;YA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GAAG,CAAC,MAAM,UAAU,CAAC,kBAAkB,EAAE,CAAC,CAAC,SAAS,CAAC;QAChF,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC;QACnC,OAAO,MAAM,IAAA,qCAA6B,EAAC,WAAW,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACrG,CAAC;CACF;AAplBD,sDAolBC","sourcesContent":["import { BN, Program, Provider, web3 } from \"@coral-xyz/anchor\";\nimport { Keypair, PublicKey, SystemProgram, TransactionInstruction, VersionedTransaction } from \"@solana/web3.js\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { Messenger } from \"../../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n CCTPDoesNotSupportedError,\n InvalidGasFeePaymentOptionError,\n OFTDoesNotSupportedError,\n SdkError,\n} from \"../../../exceptions\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { Bridge as BridgeType } from \"../../models/sol/types/bridge\";\nimport * as bridgeIdl from \"../../models/sol/types/bridge.json\";\nimport { CctpBridge as CctpBridgeType } from \"../../models/sol/types/cctp_bridge\";\nimport * as cctpBridgeIdl from \"../../models/sol/types/cctp_bridge.json\";\nimport { PayerWithToken as PayerWithTokenType } from \"../../models/sol/types/payer_with_token\";\nimport * as payerWithTokenIdl from \"../../models/sol/types/payer_with_token.json\";\nimport { getMessage, getVUsdAmount } from \"../../utils/sol\";\nimport {\n getAssociatedAccount,\n getAuthorityAccount,\n getBridgeTokenAccount,\n getCctpAccounts,\n getCctpAuthorityAccount,\n getCctpBridgeAccount,\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 { SendParams } from \"../models\";\nimport { getNonce } from \"../utils\";\nimport { SolanaBridgeParams } from \"./bridge-tx-service\";\nimport { convertToVersionedTransaction, SolTxSendParams } from \"./utils\";\n\ntype BridgeConfigInfo = Awaited<ReturnType<Program<BridgeType>[\"account\"][\"config\"][\"fetch\"]>>;\n\ninterface SwapAndBridgeBaseData {\n provider: Provider;\n payerProgram: Program<PayerWithTokenType>;\n bridgeProgram: Program<BridgeType>;\n userAccount: PublicKey;\n\n recipient: number[];\n recipientChain: number;\n recipientToken: number[];\n maxFeeAmount: BN;\n extraGasAmountInFeeToken: BN;\n\n mintAccount: PublicKey;\n feeTokenMintAccount: PublicKey;\n userTokenAccount: PublicKey;\n userFeeTokenAccount: PublicKey;\n gasPriceAccount: PublicKey;\n thisGasPriceAccount: PublicKey;\n\n poolAccount: PublicKey;\n bridgeConfigAccount: PublicKey;\n bridgeConfigInfo: BridgeConfigInfo;\n}\n\ninterface SwapAndBridgeCommonData extends SwapAndBridgeBaseData {\n vusdAmount: BN;\n nonce: number[];\n lockAccount: PublicKey;\n chainBridgeAccount: PublicKey;\n bridgeProgramId: PublicKey;\n bridgeAuthorityAccount: PublicKey;\n bridgeTokenAccount: PublicKey;\n otherBridgeTokenAccount: PublicKey;\n}\n\ninterface SwapAndBridgeAllbridgeData extends SwapAndBridgeCommonData {\n sentMessageAccount: PublicKey;\n messengerProgramId: PublicKey;\n messengerConfigAccount: PublicKey;\n messengerGasUsageAccount: PublicKey;\n}\n\ninterface SwapAndBridgeWormholeData extends SwapAndBridgeCommonData {\n wormholeMessengerAccount: PublicKey;\n wormholeMessengerConfigAccount: PublicKey;\n wormholeProgramId: string;\n sequenceAccount: PublicKey;\n feeCollectorAccount: PublicKey;\n messengerGasUsageAccount: PublicKey;\n wormholeBridgeAccount: PublicKey;\n\n messageAccount: Keypair;\n feeInstruction: TransactionInstruction;\n}\n\ninterface BridgeCctpData extends SwapAndBridgeBaseData {\n amount: BN;\n lockAccount: PublicKey;\n\n chainBridgeAccount: PublicKey;\n cctpBridgeProgramId: PublicKey;\n cctpBridgeAuthorityAccount: PublicKey;\n cctpBridgeTokenAccount: PublicKey;\n cctpBridgeConfigAccount: PublicKey;\n cctpTokenMessengerMinter: PublicKey;\n cctpTransmitterProgramId: PublicKey;\n messageTransmitterAccount: PublicKey;\n tokenMessenger: PublicKey;\n tokenMessengerEventAuthority: PublicKey;\n tokenMinter: PublicKey;\n localToken: PublicKey;\n remoteTokenMessengerKey: PublicKey;\n authorityPda: PublicKey;\n\n messageSentEventDataKeypair: Keypair;\n}\n\nconst COMPUTE_UNIT_LIMIT = 1_000_000;\n\nexport class PayerWithTokenService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n\n constructor(\n public solanaRpcUrl: string,\n public params: SolanaBridgeParams,\n public api: AllbridgeCoreClient\n ) {}\n\n async buildRawTransactionSend(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner?: Keypair }> {\n switch (params.messenger) {\n case Messenger.ALLBRIDGE: {\n const swapAndBridgeData = await this.prepareSwapAndBridgeAllbridgeData(params, solTxSendParams);\n const tx = await this.buildSwapAndBridgeTx(swapAndBridgeData);\n return { tx };\n }\n case Messenger.WORMHOLE: {\n const swapAndBridgeData = await this.prepareSwapAndBridgeWormholeData(params, solTxSendParams);\n return await this.buildSwapAndBridgeWormholeTx(swapAndBridgeData);\n }\n case Messenger.CCTP:\n case Messenger.CCTP_V2: {\n const bridgeCctpData = await this.prepareBridgeCctpData(params, solTxSendParams);\n return this.buildBridgeCctpTx(bridgeCctpData);\n }\n case Messenger.X_RESERVE:\n throw new SdkError(\"Messenger xReserve is not supported yet.\");\n case Messenger.OFT:\n throw new OFTDoesNotSupportedError(\"Messenger OFT is not supported yet.\");\n default: {\n return assertNever(params.messenger, \"Unhandled Messenger type\");\n }\n }\n }\n\n private async prepareSwapAndBridgeBaseData(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<SwapAndBridgeBaseData> {\n const {\n fromChainId,\n fromAccountAddress,\n fromTokenAddress,\n poolAddress,\n toAccountAddress,\n toTokenAddress,\n toChainId,\n fee,\n extraGas = \"0\",\n } = solTxSendParams;\n\n const userAccount = new PublicKey(fromAccountAddress);\n const recipient = Array.from(toAccountAddress);\n const recipientToken = Array.from(toTokenAddress);\n const maxFeeAmount = new BN(fee);\n const extraGasAmountInFeeToken = new BN(extraGas);\n\n const provider = buildAnchorProvider(this.solanaRpcUrl, fromAccountAddress);\n const payerProgram = this.getPayerProgram(params, provider);\n const bridgeProgram = new Program<BridgeType>(\n { ...bridgeIdl, address: params.sourceToken.bridgeAddress },\n provider\n );\n const poolAccount = new PublicKey(poolAddress);\n\n const bridgeConfigAccount = await getConfigAccount(bridgeProgram.programId);\n const bridgeConfigInfo = await bridgeProgram.account.config.fetch(bridgeConfigAccount);\n\n const mintAccount = new PublicKey(fromTokenAddress);\n const feeTokenMintAccount = new PublicKey(this.getAbrFeeTokenMintAddress(params));\n const userTokenAccount = getAssociatedAccount(userAccount, mintAccount);\n const userFeeTokenAccount = getAssociatedAccount(userAccount, feeTokenMintAccount);\n\n const gasPriceAccount = await getPriceAccount(toChainId, bridgeConfigInfo.gasOracleProgramId);\n const thisGasPriceAccount = await getPriceAccount(fromChainId, bridgeConfigInfo.gasOracleProgramId);\n\n return {\n provider,\n payerProgram,\n bridgeProgram,\n userAccount,\n\n recipient,\n recipientToken,\n recipientChain: toChainId,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n poolAccount,\n bridgeConfigAccount,\n bridgeConfigInfo,\n };\n }\n\n private getComputeUnitLimitInstruction(): TransactionInstruction {\n return web3.ComputeBudgetProgram.setComputeUnitLimit({ units: COMPUTE_UNIT_LIMIT });\n }\n\n private getPayerProgram(params: SendParams, provider: Provider): Program<PayerWithTokenType> {\n const payerAddress = params.sourceToken.abrPayer?.payerAddress;\n if (!payerAddress) {\n throw new InvalidGasFeePaymentOptionError(\"Payer with token not supported yet for ABR tokens\");\n }\n return new Program<PayerWithTokenType>({ ...payerWithTokenIdl, address: payerAddress }, provider);\n }\n\n private getAbrFeeTokenMintAddress(params: SendParams): string {\n const abrTokenAddress = params.sourceToken.abrPayer?.abrToken.tokenAddress;\n if (!abrTokenAddress) {\n throw new InvalidGasFeePaymentOptionError(\"Payer with token not supported yet for ABR tokens\");\n }\n return abrTokenAddress;\n }\n\n private async prepareSwapAndBridgeCommonData(\n baseData: SwapAndBridgeBaseData,\n solTxSendParams: SolTxSendParams\n ): Promise<SwapAndBridgeCommonData> {\n const { amount, toChainId, toTokenAddress } = solTxSendParams;\n const { bridgeProgram, poolAccount, mintAccount } = baseData;\n\n const vUsdAmount = await getVUsdAmount(amount, bridgeProgram, poolAccount);\n\n const nonce = Array.from(getNonce());\n const lockAccount = await getLockAccount(nonce, bridgeProgram.programId);\n const bridgeProgramId = bridgeProgram.programId;\n const chainBridgeAccount = await getChainBridgeAccount(toChainId, bridgeProgramId);\n const bridgeAuthorityAccount = await getAuthorityAccount(bridgeProgramId);\n const bridgeTokenAccount = await getBridgeTokenAccount(mintAccount, bridgeProgramId);\n const otherBridgeTokenAccount = await getOtherChainTokenAccount(\n toChainId,\n Buffer.from(toTokenAddress),\n bridgeProgramId\n );\n\n return {\n ...baseData,\n vusdAmount: new BN(vUsdAmount),\n nonce,\n lockAccount,\n chainBridgeAccount,\n bridgeProgramId,\n bridgeAuthorityAccount,\n bridgeTokenAccount,\n otherBridgeTokenAccount,\n };\n }\n\n private getWormholeProgramAddresses(\n wormholeProgramId: string,\n bridgeAuthorityAccount: PublicKey\n ): {\n wormholeBridgeAccount: PublicKey;\n wormholeSequenceAccount: PublicKey;\n wormholeFeeCollectorAccount: PublicKey;\n } {\n const programId = new PublicKey(wormholeProgramId);\n const [wormholeBridgeAccount] = PublicKey.findProgramAddressSync([Buffer.from(\"Bridge\")], programId);\n const [wormholeSequenceAccount] = PublicKey.findProgramAddressSync(\n [Buffer.from(\"Sequence\"), bridgeAuthorityAccount.toBuffer()],\n programId\n );\n const [wormholeFeeCollectorAccount] = PublicKey.findProgramAddressSync([Buffer.from(\"fee_collector\")], programId);\n\n return {\n wormholeBridgeAccount,\n wormholeSequenceAccount,\n wormholeFeeCollectorAccount,\n };\n }\n\n private async getWormholeFeeInstruction(\n provider: Provider,\n wormholeBridgeAccount: PublicKey,\n userAccount: PublicKey,\n wormholeFeeCollectorAccount: PublicKey\n ): Promise<TransactionInstruction> {\n const bridgeAccountInfo = await provider.connection.getAccountInfo(wormholeBridgeAccount);\n if (bridgeAccountInfo == null) {\n throw new SdkError(\"Cannot fetch wormhole bridge account info\");\n }\n\n const feeLamports = new BN(bridgeAccountInfo.data.slice(16, 24), \"le\").toString();\n return SystemProgram.transfer({\n fromPubkey: userAccount,\n toPubkey: wormholeFeeCollectorAccount,\n lamports: +feeLamports,\n });\n }\n private async prepareSwapAndBridgeAllbridgeData(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<SwapAndBridgeAllbridgeData> {\n const baseData = await this.prepareSwapAndBridgeBaseData(params, solTxSendParams);\n const commonData = await this.prepareSwapAndBridgeCommonData(baseData, solTxSendParams);\n\n const { recipient, recipientToken, recipientChain, bridgeConfigInfo } = baseData;\n const { vusdAmount, nonce, bridgeAuthorityAccount } = commonData;\n const { fromChainId, toChainId } = solTxSendParams;\n\n const message = getMessage({\n amount: vusdAmount.toString(),\n recipient: Buffer.from(recipient),\n nonce: Buffer.from(nonce),\n receiveToken: Buffer.from(recipientToken),\n destinationChainId: recipientChain,\n sourceChainId: fromChainId,\n chainBridge: bridgeAuthorityAccount.toBuffer(),\n });\n\n const messengerProgramId = bridgeConfigInfo.allbridgeMessengerProgramId;\n const sentMessageAccount = await getSendMessageAccount(message, messengerProgramId);\n const messengerConfigAccount = await getConfigAccount(messengerProgramId);\n const messengerGasUsageAccount = await getGasUsageAccount(toChainId, messengerProgramId);\n\n return {\n ...commonData,\n sentMessageAccount,\n messengerProgramId,\n messengerConfigAccount,\n messengerGasUsageAccount,\n };\n }\n\n private async prepareSwapAndBridgeWormholeData(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<SwapAndBridgeWormholeData> {\n const baseData = await this.prepareSwapAndBridgeBaseData(params, solTxSendParams);\n const commonData = await this.prepareSwapAndBridgeCommonData(baseData, solTxSendParams);\n\n const { provider, userAccount, bridgeConfigInfo } = baseData;\n const { bridgeAuthorityAccount } = commonData;\n const { toChainId } = solTxSendParams;\n\n const wormholeMessengerAccount = bridgeConfigInfo.wormholeMessengerProgramId;\n const wormholeMessengerConfigAccount = await getConfigAccount(wormholeMessengerAccount);\n const messengerGasUsageAccount = await getGasUsageAccount(toChainId, wormholeMessengerAccount);\n\n const wormholeProgramId = this.params.wormholeMessengerProgramId;\n const { wormholeBridgeAccount, wormholeSequenceAccount, wormholeFeeCollectorAccount } =\n this.getWormholeProgramAddresses(wormholeProgramId, bridgeAuthorityAccount);\n\n const messageAccount = Keypair.generate();\n const feeInstruction = await this.getWormholeFeeInstruction(\n provider,\n wormholeBridgeAccount,\n userAccount,\n wormholeFeeCollectorAccount\n );\n\n return {\n ...commonData,\n wormholeMessengerAccount,\n wormholeMessengerConfigAccount,\n wormholeProgramId,\n sequenceAccount: wormholeSequenceAccount,\n feeCollectorAccount: wormholeFeeCollectorAccount,\n messengerGasUsageAccount,\n messageAccount,\n wormholeBridgeAccount,\n feeInstruction,\n };\n }\n\n private async prepareBridgeCctpData(params: SendParams, solTxSendParams: SolTxSendParams): Promise<BridgeCctpData> {\n const baseData = await this.prepareSwapAndBridgeBaseData(params, solTxSendParams);\n\n const { mintAccount, provider } = baseData;\n const { amount, toChainId } = solTxSendParams;\n\n const cctpAddress = params.sourceToken.cctpAddress;\n if (!cctpAddress) {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n\n const cctpBridge: Program<CctpBridgeType> = new Program<CctpBridgeType>(\n { ...cctpBridgeIdl, address: cctpAddress },\n provider\n );\n const chainBridgeAccount = await getChainBridgeAccount(toChainId, cctpBridge.programId);\n const cctpBridgeProgramId = cctpBridge.programId;\n const cctpBridgeConfigAccount = await getCctpBridgeAccount(mintAccount, cctpBridge.programId);\n\n const cctpBridgeAuthorityAccount = await getCctpAuthorityAccount(cctpBridgeConfigAccount, cctpBridge.programId);\n const cctpBridgeTokenAccount = await getBridgeTokenAccount(mintAccount, cctpBridge.programId);\n\n const destinationChainSymbol = params.destinationToken.chainSymbol;\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, mintAccount, cctpTransmitterProgramId, cctpTokenMessengerMinter);\n\n const messageSentEventDataKeypair = Keypair.generate();\n const lockAccount = getCctpLockAccount(cctpBridge.programId, messageSentEventDataKeypair.publicKey);\n\n return {\n ...baseData,\n lockAccount,\n messageSentEventDataKeypair,\n\n amount: new BN(amount),\n chainBridgeAccount,\n cctpBridgeProgramId,\n cctpBridgeAuthorityAccount,\n cctpBridgeConfigAccount,\n cctpBridgeTokenAccount,\n cctpTokenMessengerMinter,\n cctpTransmitterProgramId,\n messageTransmitterAccount,\n tokenMessenger,\n tokenMessengerEventAuthority,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n };\n }\n\n private async buildSwapAndBridgeTx(\n swapAndBridgeAllbridgeData: SwapAndBridgeAllbridgeData\n ): Promise<VersionedTransaction> {\n const {\n provider,\n payerProgram,\n userAccount,\n vusdAmount,\n recipient,\n recipientChain,\n recipientToken,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n nonce,\n\n lockAccount,\n chainBridgeAccount,\n bridgeProgramId,\n bridgeAuthorityAccount,\n bridgeTokenAccount,\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n sentMessageAccount,\n messengerProgramId,\n messengerConfigAccount,\n messengerGasUsageAccount,\n bridgeConfigAccount,\n otherBridgeTokenAccount,\n poolAccount,\n } = swapAndBridgeAllbridgeData;\n\n const transaction = await payerProgram.methods\n .swapAndBridge({\n vusdAmount,\n recipient,\n recipientToken,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n nonce,\n destinationChainId: recipientChain,\n })\n .accountsPartial({\n lock: lockAccount,\n chainBridge: chainBridgeAccount,\n bridge: bridgeProgramId,\n bridgeAuthority: bridgeAuthorityAccount,\n bridgeToken: bridgeTokenAccount,\n mint: mintAccount,\n feeTokenMint: feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPrice: gasPriceAccount,\n thisGasPrice: thisGasPriceAccount,\n sentMessageAccount,\n messenger: messengerProgramId,\n messengerConfig: messengerConfigAccount,\n messengerGasUsage: messengerGasUsageAccount,\n bridgeConfig: bridgeConfigAccount,\n otherBridgeToken: otherBridgeTokenAccount,\n pool: poolAccount,\n })\n .preInstructions([this.getComputeUnitLimitInstruction()])\n .transaction();\n\n return await this.finalizeTransaction(transaction, provider, userAccount);\n }\n\n private async buildSwapAndBridgeWormholeTx(\n swapAndBridgeWormholeData: SwapAndBridgeWormholeData\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner: Keypair }> {\n const {\n provider,\n payerProgram,\n userAccount,\n vusdAmount,\n recipient,\n recipientChain,\n recipientToken,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n nonce,\n\n lockAccount,\n chainBridgeAccount,\n bridgeProgramId,\n bridgeAuthorityAccount,\n bridgeTokenAccount,\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n messengerGasUsageAccount,\n bridgeConfigAccount,\n otherBridgeTokenAccount,\n poolAccount,\n\n wormholeMessengerAccount,\n wormholeMessengerConfigAccount,\n wormholeProgramId,\n sequenceAccount,\n feeCollectorAccount,\n messageAccount,\n wormholeBridgeAccount,\n\n feeInstruction,\n } = swapAndBridgeWormholeData;\n\n const transaction = await payerProgram.methods\n .swapAndBridgeWormhole({\n vusdAmount,\n recipient,\n recipientToken,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n nonce,\n destinationChainId: recipientChain,\n })\n .accounts({\n lock: lockAccount,\n chainBridge: chainBridgeAccount,\n bridge: bridgeProgramId,\n bridgeAuthority: bridgeAuthorityAccount,\n bridgeToken: bridgeTokenAccount,\n mint: mintAccount,\n feeTokenMint: feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPrice: gasPriceAccount,\n thisGasPrice: thisGasPriceAccount,\n messengerGasUsage: messengerGasUsageAccount,\n bridgeConfig: bridgeConfigAccount,\n otherBridgeToken: otherBridgeTokenAccount,\n pool: poolAccount,\n wormholeMessenger: wormholeMessengerAccount,\n wormholeMessengerConfig: wormholeMessengerConfigAccount,\n wormholeProgram: wormholeProgramId,\n sequence: sequenceAccount,\n feeCollector: feeCollectorAccount,\n message: messageAccount.publicKey,\n wormholeBridge: wormholeBridgeAccount,\n // user: user.publicKey,\n })\n .preInstructions([this.getComputeUnitLimitInstruction(), feeInstruction])\n .signers([messageAccount])\n .transaction();\n\n return {\n tx: await this.finalizeTransaction(transaction, provider, userAccount),\n requiredMessageSigner: messageAccount,\n };\n }\n\n private async buildBridgeCctpTx(\n bridgeCctpData: BridgeCctpData\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner: Keypair }> {\n const {\n provider,\n payerProgram,\n\n amount,\n recipient,\n recipientToken,\n\n userAccount,\n recipientChain,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n\n lockAccount,\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n chainBridgeAccount,\n cctpBridgeProgramId,\n cctpBridgeAuthorityAccount,\n cctpBridgeConfigAccount,\n cctpBridgeTokenAccount,\n cctpTokenMessengerMinter,\n cctpTransmitterProgramId,\n messageTransmitterAccount,\n tokenMessenger,\n tokenMessengerEventAuthority,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n\n messageSentEventDataKeypair,\n } = bridgeCctpData;\n\n const transaction = await payerProgram.methods\n .bridgeCctp({\n amount,\n recipient,\n receiveToken: recipientToken,\n destinationChainId: recipientChain,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n })\n .accounts({\n lock: lockAccount,\n messageSentEventData: messageSentEventDataKeypair.publicKey,\n mint: mintAccount,\n feeTokenMint: feeTokenMintAccount,\n userFeeTokenAccount,\n bridgeToken: cctpBridgeTokenAccount,\n cctpBridge: cctpBridgeProgramId,\n cctpBridgeConfig: cctpBridgeConfigAccount,\n cctpMessenger: cctpTokenMessengerMinter,\n messageTransmitterProgram: cctpTransmitterProgramId,\n messageTransmitterAccount: messageTransmitterAccount,\n tokenMessenger,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n eventAuthority: tokenMessengerEventAuthority,\n gasPrice: gasPriceAccount,\n thisGasPrice: thisGasPriceAccount,\n chainBridge: chainBridgeAccount,\n bridgeAuthority: cctpBridgeAuthorityAccount,\n userTokenAccount,\n })\n .preInstructions([this.getComputeUnitLimitInstruction()])\n .transaction();\n\n return {\n tx: await this.finalizeTransaction(transaction, provider, userAccount),\n requiredMessageSigner: messageSentEventDataKeypair,\n };\n }\n\n private async finalizeTransaction(\n transaction: web3.Transaction,\n provider: Provider,\n userAccount: PublicKey\n ): Promise<VersionedTransaction> {\n const connection = provider.connection;\n transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n transaction.feePayer = userAccount;\n return await convertToVersionedTransaction(transaction, connection, this.params.solanaLookUpTable);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"payer-with-token-service.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/payer-with-token-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAgE;AAChE,6CAAkH;AAClH,6DAAwD;AACxD,4EAAoE;AAEpE,oDAK6B;AAC7B,gDAAmD;AAEnD,8EAAgE;AAEhE,gGAAkF;AAClF,yCAA4D;AAC5D,uDAgBkC;AAClC,qEAAsE;AAEtE,oCAAoC;AAEpC,mCAAyE;AAiFzE,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAErC,MAAa,qBAAqB;IAIvB;IACA;IACA;IALT,SAAS,GAAqB,uBAAS,CAAC,MAAM,CAAC;IAE/C,YACS,YAAoB,EACpB,MAA0B,EAC1B,GAAwB;QAFxB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,WAAM,GAAN,MAAM,CAAoB;QAC1B,QAAG,GAAH,GAAG,CAAqB;IAC9B,CAAC;IAEJ,KAAK,CAAC,uBAAuB,CAC3B,MAAkB,EAClB,eAAgC;QAEhC,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC;YACzB,KAAK,0BAAS,CAAC,SAAS,CAAC,CAAC,CAAC;gBACzB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,iCAAiC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;gBAChG,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;gBAC9D,OAAO,EAAE,EAAE,EAAE,CAAC;YAChB,CAAC;YACD,KAAK,0BAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACxB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,gCAAgC,CAAC,MAAM,EAAE,eAAe,CAAC,CA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ACpD,cAAc;YACd,WAAW;YACX,UAAU;YACV,oBAAoB,EAAE,uBAAuB;YAC7C,YAAY;YACZ,cAAc,EAAE,4BAA4B;YAC5C,oBAAoB,EAAE,2BAA2B,CAAC,SAAS;YAC3D,IAAI,EAAE,WAAW;YACjB,gBAAgB,EAAE,uBAAuB;YACzC,QAAQ,EAAE,eAAe;YACzB,YAAY,EAAE,mBAAmB;YACjC,WAAW,EAAE,kBAAkB;YAC/B,eAAe,EAAE,0BAA0B;YAC3C,gBAAgB;SACjB,CAAC;aACD,eAAe,CAAC,CAAC,IAAI,CAAC,8BAA8B,EAAE,CAAC,CAAC;aACxD,WAAW,EAAE,CAAC;QAEjB,OAAO;YACL,EAAE,EAAE,MAAM,IAAI,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC;YACtE,qBAAqB,EAAE,2BAA2B;SACnD,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAC/B,WAA6B,EAC7B,QAAkB,EAClB,WAAsB;QAEtB,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACvC,WAAW,CAAC,eAAe,GAAG,CAAC,MAAM,UAAU,CAAC,kBAAkB,EAAE,CAAC,CAAC,SAAS,CAAC;QAChF,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC;QACnC,OAAO,MAAM,IAAA,qCAA6B,EAAC,WAAW,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACrG,CAAC;CACF;AAtrBD,sDAsrBC","sourcesContent":["import { BN, Program, Provider, web3 } from \"@coral-xyz/anchor\";\nimport { Keypair, PublicKey, SystemProgram, TransactionInstruction, VersionedTransaction } from \"@solana/web3.js\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { Messenger } from \"../../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n CCTPDoesNotSupportedError,\n InvalidGasFeePaymentOptionError,\n OFTDoesNotSupportedError,\n SdkError,\n} from \"../../../exceptions\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { Bridge as BridgeType } from \"../../models/sol/types/bridge\";\nimport * as bridgeIdl from \"../../models/sol/types/bridge.json\";\nimport { PayerWithToken as PayerWithTokenType } from \"../../models/sol/types/payer_with_token\";\nimport * as payerWithTokenIdl from \"../../models/sol/types/payer_with_token.json\";\nimport { getMessage, getVUsdAmount } from \"../../utils/sol\";\nimport {\n getAssociatedAccount,\n getAuthorityAccount,\n getBridgeTokenAccount,\n getCctpAccounts,\n getCctpAuthorityAccount,\n getCctpBridgeAccount,\n getCctpLockAccount,\n getCctpV2BridgeConfigAccount,\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 { SendParams } from \"../models\";\nimport { getNonce } from \"../utils\";\nimport { SolanaBridgeParams } from \"./bridge-tx-service\";\nimport { convertToVersionedTransaction, SolTxSendParams } from \"./utils\";\n\ntype BridgeConfigInfo = Awaited<ReturnType<Program<BridgeType>[\"account\"][\"config\"][\"fetch\"]>>;\n\ninterface SwapAndBridgeBaseData {\n provider: Provider;\n payerProgram: Program<PayerWithTokenType>;\n bridgeProgram: Program<BridgeType>;\n userAccount: PublicKey;\n\n recipient: number[];\n recipientChain: number;\n recipientToken: number[];\n maxFeeAmount: BN;\n extraGasAmountInFeeToken: BN;\n\n mintAccount: PublicKey;\n feeTokenMintAccount: PublicKey;\n userTokenAccount: PublicKey;\n userFeeTokenAccount: PublicKey;\n gasPriceAccount: PublicKey;\n thisGasPriceAccount: PublicKey;\n\n poolAccount: PublicKey;\n bridgeConfigAccount: PublicKey;\n bridgeConfigInfo: BridgeConfigInfo;\n}\n\ninterface SwapAndBridgeCommonData extends SwapAndBridgeBaseData {\n vusdAmount: BN;\n nonce: number[];\n lockAccount: PublicKey;\n chainBridgeAccount: PublicKey;\n bridgeProgramId: PublicKey;\n bridgeAuthorityAccount: PublicKey;\n bridgeTokenAccount: PublicKey;\n otherBridgeTokenAccount: PublicKey;\n}\n\ninterface SwapAndBridgeAllbridgeData extends SwapAndBridgeCommonData {\n sentMessageAccount: PublicKey;\n messengerProgramId: PublicKey;\n messengerConfigAccount: PublicKey;\n messengerGasUsageAccount: PublicKey;\n}\n\ninterface SwapAndBridgeWormholeData extends SwapAndBridgeCommonData {\n wormholeMessengerAccount: PublicKey;\n wormholeMessengerConfigAccount: PublicKey;\n wormholeProgramId: string;\n sequenceAccount: PublicKey;\n feeCollectorAccount: PublicKey;\n messengerGasUsageAccount: PublicKey;\n wormholeBridgeAccount: PublicKey;\n\n messageAccount: Keypair;\n feeInstruction: TransactionInstruction;\n}\n\ninterface BridgeCctpData extends SwapAndBridgeBaseData {\n amount: BN;\n lockAccount: PublicKey;\n\n chainBridgeAccount: PublicKey;\n cctpBridgeProgramId: PublicKey;\n cctpBridgeAuthorityAccount: PublicKey;\n cctpBridgeTokenAccount: PublicKey;\n cctpBridgeConfigAccount: PublicKey;\n cctpTokenMessengerMinter: PublicKey;\n cctpTransmitterProgramId: PublicKey;\n messageTransmitterAccount: PublicKey;\n tokenMessenger: PublicKey;\n tokenMessengerEventAuthority: PublicKey;\n tokenMinter: PublicKey;\n localToken: PublicKey;\n remoteTokenMessengerKey: PublicKey;\n authorityPda: PublicKey;\n\n messageSentEventDataKeypair: Keypair;\n}\n\nconst COMPUTE_UNIT_LIMIT = 1_000_000;\n\nexport class PayerWithTokenService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n\n constructor(\n public solanaRpcUrl: string,\n public params: SolanaBridgeParams,\n public api: AllbridgeCoreClient\n ) {}\n\n async buildRawTransactionSend(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner?: Keypair }> {\n switch (params.messenger) {\n case Messenger.ALLBRIDGE: {\n const swapAndBridgeData = await this.prepareSwapAndBridgeAllbridgeData(params, solTxSendParams);\n const tx = await this.buildSwapAndBridgeTx(swapAndBridgeData);\n return { tx };\n }\n case Messenger.WORMHOLE: {\n const swapAndBridgeData = await this.prepareSwapAndBridgeWormholeData(params, solTxSendParams);\n return await this.buildSwapAndBridgeWormholeTx(swapAndBridgeData);\n }\n case Messenger.CCTP: {\n const bridgeCctpData = await this.prepareBridgeCctpData(params, solTxSendParams);\n return this.buildBridgeCctpTx(bridgeCctpData);\n }\n case Messenger.CCTP_V2: {\n const bridgeCctpData = await this.prepareBridgeCctpData(params, solTxSendParams);\n return this.buildBridgeCctpV2Tx(bridgeCctpData);\n }\n case Messenger.X_RESERVE:\n throw new SdkError(\"Messenger xReserve is not supported yet.\");\n case Messenger.OFT:\n throw new OFTDoesNotSupportedError(\"Messenger OFT is not supported yet.\");\n default: {\n return assertNever(params.messenger, \"Unhandled Messenger type\");\n }\n }\n }\n\n private async prepareSwapAndBridgeBaseData(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<SwapAndBridgeBaseData> {\n const {\n fromChainId,\n fromAccountAddress,\n fromTokenAddress,\n poolAddress,\n toAccountAddress,\n toTokenAddress,\n toChainId,\n fee,\n extraGas = \"0\",\n } = solTxSendParams;\n\n const userAccount = new PublicKey(fromAccountAddress);\n const recipient = Array.from(toAccountAddress);\n const recipientToken = Array.from(toTokenAddress);\n const maxFeeAmount = new BN(fee);\n const extraGasAmountInFeeToken = new BN(extraGas);\n\n const provider = buildAnchorProvider(this.solanaRpcUrl, fromAccountAddress);\n const payerProgram = this.getPayerProgram(params, provider);\n const bridgeProgram = new Program<BridgeType>(\n { ...bridgeIdl, address: params.sourceToken.bridgeAddress },\n provider\n );\n const poolAccount = new PublicKey(poolAddress);\n\n const bridgeConfigAccount = await getConfigAccount(bridgeProgram.programId);\n const bridgeConfigInfo = await bridgeProgram.account.config.fetch(bridgeConfigAccount);\n\n const mintAccount = new PublicKey(fromTokenAddress);\n const feeTokenMintAccount = new PublicKey(this.getAbrFeeTokenMintAddress(params));\n const userTokenAccount = getAssociatedAccount(userAccount, mintAccount);\n const userFeeTokenAccount = getAssociatedAccount(userAccount, feeTokenMintAccount);\n\n const gasPriceAccount = await getPriceAccount(toChainId, bridgeConfigInfo.gasOracleProgramId);\n const thisGasPriceAccount = await getPriceAccount(fromChainId, bridgeConfigInfo.gasOracleProgramId);\n\n return {\n provider,\n payerProgram,\n bridgeProgram,\n userAccount,\n\n recipient,\n recipientToken,\n recipientChain: toChainId,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n poolAccount,\n bridgeConfigAccount,\n bridgeConfigInfo,\n };\n }\n\n private getComputeUnitLimitInstruction(): TransactionInstruction {\n return web3.ComputeBudgetProgram.setComputeUnitLimit({ units: COMPUTE_UNIT_LIMIT });\n }\n\n private getPayerProgram(params: SendParams, provider: Provider): Program<PayerWithTokenType> {\n const payerAddress = params.sourceToken.abrPayer?.payerAddress;\n if (!payerAddress) {\n throw new InvalidGasFeePaymentOptionError(\"Payer with token not supported yet for ABR tokens\");\n }\n return new Program<PayerWithTokenType>({ ...payerWithTokenIdl, address: payerAddress }, provider);\n }\n\n private getAbrFeeTokenMintAddress(params: SendParams): string {\n const abrTokenAddress = params.sourceToken.abrPayer?.abrToken.tokenAddress;\n if (!abrTokenAddress) {\n throw new InvalidGasFeePaymentOptionError(\"Payer with token not supported yet for ABR tokens\");\n }\n return abrTokenAddress;\n }\n\n private async prepareSwapAndBridgeCommonData(\n baseData: SwapAndBridgeBaseData,\n solTxSendParams: SolTxSendParams\n ): Promise<SwapAndBridgeCommonData> {\n const { amount, toChainId, toTokenAddress } = solTxSendParams;\n const { bridgeProgram, poolAccount, mintAccount } = baseData;\n\n const vUsdAmount = await getVUsdAmount(amount, bridgeProgram, poolAccount);\n\n const nonce = Array.from(getNonce());\n const lockAccount = await getLockAccount(nonce, bridgeProgram.programId);\n const bridgeProgramId = bridgeProgram.programId;\n const chainBridgeAccount = await getChainBridgeAccount(toChainId, bridgeProgramId);\n const bridgeAuthorityAccount = await getAuthorityAccount(bridgeProgramId);\n const bridgeTokenAccount = await getBridgeTokenAccount(mintAccount, bridgeProgramId);\n const otherBridgeTokenAccount = await getOtherChainTokenAccount(\n toChainId,\n Buffer.from(toTokenAddress),\n bridgeProgramId\n );\n\n return {\n ...baseData,\n vusdAmount: new BN(vUsdAmount),\n nonce,\n lockAccount,\n chainBridgeAccount,\n bridgeProgramId,\n bridgeAuthorityAccount,\n bridgeTokenAccount,\n otherBridgeTokenAccount,\n };\n }\n\n private getWormholeProgramAddresses(\n wormholeProgramId: string,\n bridgeAuthorityAccount: PublicKey\n ): {\n wormholeBridgeAccount: PublicKey;\n wormholeSequenceAccount: PublicKey;\n wormholeFeeCollectorAccount: PublicKey;\n } {\n const programId = new PublicKey(wormholeProgramId);\n const [wormholeBridgeAccount] = PublicKey.findProgramAddressSync([Buffer.from(\"Bridge\")], programId);\n const [wormholeSequenceAccount] = PublicKey.findProgramAddressSync(\n [Buffer.from(\"Sequence\"), bridgeAuthorityAccount.toBuffer()],\n programId\n );\n const [wormholeFeeCollectorAccount] = PublicKey.findProgramAddressSync([Buffer.from(\"fee_collector\")], programId);\n\n return {\n wormholeBridgeAccount,\n wormholeSequenceAccount,\n wormholeFeeCollectorAccount,\n };\n }\n\n private async getWormholeFeeInstruction(\n provider: Provider,\n wormholeBridgeAccount: PublicKey,\n userAccount: PublicKey,\n wormholeFeeCollectorAccount: PublicKey\n ): Promise<TransactionInstruction> {\n const bridgeAccountInfo = await provider.connection.getAccountInfo(wormholeBridgeAccount);\n if (bridgeAccountInfo == null) {\n throw new SdkError(\"Cannot fetch wormhole bridge account info\");\n }\n\n const feeLamports = new BN(bridgeAccountInfo.data.slice(16, 24), \"le\").toString();\n return SystemProgram.transfer({\n fromPubkey: userAccount,\n toPubkey: wormholeFeeCollectorAccount,\n lamports: +feeLamports,\n });\n }\n private async prepareSwapAndBridgeAllbridgeData(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<SwapAndBridgeAllbridgeData> {\n const baseData = await this.prepareSwapAndBridgeBaseData(params, solTxSendParams);\n const commonData = await this.prepareSwapAndBridgeCommonData(baseData, solTxSendParams);\n\n const { recipient, recipientToken, recipientChain, bridgeConfigInfo } = baseData;\n const { vusdAmount, nonce, bridgeAuthorityAccount } = commonData;\n const { fromChainId, toChainId } = solTxSendParams;\n\n const message = getMessage({\n amount: vusdAmount.toString(),\n recipient: Buffer.from(recipient),\n nonce: Buffer.from(nonce),\n receiveToken: Buffer.from(recipientToken),\n destinationChainId: recipientChain,\n sourceChainId: fromChainId,\n chainBridge: bridgeAuthorityAccount.toBuffer(),\n });\n\n const messengerProgramId = bridgeConfigInfo.allbridgeMessengerProgramId;\n const sentMessageAccount = await getSendMessageAccount(message, messengerProgramId);\n const messengerConfigAccount = await getConfigAccount(messengerProgramId);\n const messengerGasUsageAccount = await getGasUsageAccount(toChainId, messengerProgramId);\n\n return {\n ...commonData,\n sentMessageAccount,\n messengerProgramId,\n messengerConfigAccount,\n messengerGasUsageAccount,\n };\n }\n\n private async prepareSwapAndBridgeWormholeData(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<SwapAndBridgeWormholeData> {\n const baseData = await this.prepareSwapAndBridgeBaseData(params, solTxSendParams);\n const commonData = await this.prepareSwapAndBridgeCommonData(baseData, solTxSendParams);\n\n const { provider, userAccount, bridgeConfigInfo } = baseData;\n const { bridgeAuthorityAccount } = commonData;\n const { toChainId } = solTxSendParams;\n\n const wormholeMessengerAccount = bridgeConfigInfo.wormholeMessengerProgramId;\n const wormholeMessengerConfigAccount = await getConfigAccount(wormholeMessengerAccount);\n const messengerGasUsageAccount = await getGasUsageAccount(toChainId, wormholeMessengerAccount);\n\n const wormholeProgramId = this.params.wormholeMessengerProgramId;\n const { wormholeBridgeAccount, wormholeSequenceAccount, wormholeFeeCollectorAccount } =\n this.getWormholeProgramAddresses(wormholeProgramId, bridgeAuthorityAccount);\n\n const messageAccount = Keypair.generate();\n const feeInstruction = await this.getWormholeFeeInstruction(\n provider,\n wormholeBridgeAccount,\n userAccount,\n wormholeFeeCollectorAccount\n );\n\n return {\n ...commonData,\n wormholeMessengerAccount,\n wormholeMessengerConfigAccount,\n wormholeProgramId,\n sequenceAccount: wormholeSequenceAccount,\n feeCollectorAccount: wormholeFeeCollectorAccount,\n messengerGasUsageAccount,\n messageAccount,\n wormholeBridgeAccount,\n feeInstruction,\n };\n }\n\n private async prepareBridgeCctpData(params: SendParams, solTxSendParams: SolTxSendParams): Promise<BridgeCctpData> {\n const baseData = await this.prepareSwapAndBridgeBaseData(params, solTxSendParams);\n\n const { mintAccount } = baseData;\n const { amount, toChainId } = solTxSendParams;\n\n const destinationChainSymbol = params.destinationToken.chainSymbol;\n const domain = this.params.cctpParams.cctpDomains[destinationChainSymbol];\n\n let cctpVersion: number | undefined;\n let cctpAddress: string | undefined;\n let cctpTransmitterProgramIdAddress: string | undefined;\n let cctpTokenMessengerMinterAddress: string | undefined;\n if (params.messenger === Messenger.CCTP) {\n cctpVersion = 1;\n cctpAddress = params.sourceToken.cctpAddress;\n cctpTransmitterProgramIdAddress = this.params.cctpParams.cctpTransmitterProgramId;\n cctpTokenMessengerMinterAddress = this.params.cctpParams.cctpTokenMessengerMinter;\n } else if (params.messenger === Messenger.CCTP_V2) {\n cctpVersion = 2;\n cctpAddress = params.sourceToken.cctpV2Address;\n cctpTransmitterProgramIdAddress = this.params.cctpParams.cctpV2TransmitterProgramId;\n cctpTokenMessengerMinterAddress = this.params.cctpParams.cctpV2TokenMessengerMinter;\n }\n if (domain == undefined || !cctpTransmitterProgramIdAddress || !cctpTokenMessengerMinterAddress) {\n throw new SdkError(`CCTP ${cctpVersion} is not configured`);\n }\n if (!cctpAddress) {\n throw new CCTPDoesNotSupportedError(`Such route does not support CCTP ${cctpVersion} protocol`);\n }\n\n const cctpBridgeProgramId = new PublicKey(cctpAddress);\n const cctpBridgeConfigAccount =\n cctpVersion === 1\n ? await getCctpBridgeAccount(mintAccount, cctpBridgeProgramId)\n : getCctpV2BridgeConfigAccount(mintAccount, cctpBridgeProgramId);\n const chainBridgeAccount = await getChainBridgeAccount(toChainId, cctpBridgeProgramId);\n const cctpBridgeAuthorityAccount = await getCctpAuthorityAccount(cctpBridgeConfigAccount, cctpBridgeProgramId);\n const cctpBridgeTokenAccount = await getBridgeTokenAccount(mintAccount, cctpBridgeProgramId);\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, mintAccount, cctpTransmitterProgramId, cctpTokenMessengerMinter);\n\n const messageSentEventDataKeypair = Keypair.generate();\n const lockAccount = getCctpLockAccount(cctpBridgeProgramId, messageSentEventDataKeypair.publicKey);\n\n return {\n ...baseData,\n lockAccount,\n messageSentEventDataKeypair,\n\n amount: new BN(amount),\n chainBridgeAccount,\n cctpBridgeProgramId,\n cctpBridgeAuthorityAccount,\n cctpBridgeConfigAccount,\n cctpBridgeTokenAccount,\n cctpTokenMessengerMinter,\n cctpTransmitterProgramId,\n messageTransmitterAccount,\n tokenMessenger,\n tokenMessengerEventAuthority,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n };\n }\n\n private async buildSwapAndBridgeTx(\n swapAndBridgeAllbridgeData: SwapAndBridgeAllbridgeData\n ): Promise<VersionedTransaction> {\n const {\n provider,\n payerProgram,\n userAccount,\n vusdAmount,\n recipient,\n recipientChain,\n recipientToken,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n nonce,\n\n lockAccount,\n chainBridgeAccount,\n bridgeProgramId,\n bridgeAuthorityAccount,\n bridgeTokenAccount,\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n sentMessageAccount,\n messengerProgramId,\n messengerConfigAccount,\n messengerGasUsageAccount,\n bridgeConfigAccount,\n otherBridgeTokenAccount,\n poolAccount,\n } = swapAndBridgeAllbridgeData;\n\n const transaction = await payerProgram.methods\n .swapAndBridge({\n vusdAmount,\n recipient,\n recipientToken,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n nonce,\n destinationChainId: recipientChain,\n })\n .accountsPartial({\n lock: lockAccount,\n chainBridge: chainBridgeAccount,\n bridge: bridgeProgramId,\n bridgeAuthority: bridgeAuthorityAccount,\n bridgeToken: bridgeTokenAccount,\n mint: mintAccount,\n feeTokenMint: feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPrice: gasPriceAccount,\n thisGasPrice: thisGasPriceAccount,\n sentMessageAccount,\n messenger: messengerProgramId,\n messengerConfig: messengerConfigAccount,\n messengerGasUsage: messengerGasUsageAccount,\n bridgeConfig: bridgeConfigAccount,\n otherBridgeToken: otherBridgeTokenAccount,\n pool: poolAccount,\n })\n .preInstructions([this.getComputeUnitLimitInstruction()])\n .transaction();\n\n return await this.finalizeTransaction(transaction, provider, userAccount);\n }\n\n private async buildSwapAndBridgeWormholeTx(\n swapAndBridgeWormholeData: SwapAndBridgeWormholeData\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner: Keypair }> {\n const {\n provider,\n payerProgram,\n userAccount,\n vusdAmount,\n recipient,\n recipientChain,\n recipientToken,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n nonce,\n\n lockAccount,\n chainBridgeAccount,\n bridgeProgramId,\n bridgeAuthorityAccount,\n bridgeTokenAccount,\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n messengerGasUsageAccount,\n bridgeConfigAccount,\n otherBridgeTokenAccount,\n poolAccount,\n\n wormholeMessengerAccount,\n wormholeMessengerConfigAccount,\n wormholeProgramId,\n sequenceAccount,\n feeCollectorAccount,\n messageAccount,\n wormholeBridgeAccount,\n\n feeInstruction,\n } = swapAndBridgeWormholeData;\n\n const transaction = await payerProgram.methods\n .swapAndBridgeWormhole({\n vusdAmount,\n recipient,\n recipientToken,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n nonce,\n destinationChainId: recipientChain,\n })\n .accounts({\n lock: lockAccount,\n chainBridge: chainBridgeAccount,\n bridge: bridgeProgramId,\n bridgeAuthority: bridgeAuthorityAccount,\n bridgeToken: bridgeTokenAccount,\n mint: mintAccount,\n feeTokenMint: feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPrice: gasPriceAccount,\n thisGasPrice: thisGasPriceAccount,\n messengerGasUsage: messengerGasUsageAccount,\n bridgeConfig: bridgeConfigAccount,\n otherBridgeToken: otherBridgeTokenAccount,\n pool: poolAccount,\n wormholeMessenger: wormholeMessengerAccount,\n wormholeMessengerConfig: wormholeMessengerConfigAccount,\n wormholeProgram: wormholeProgramId,\n sequence: sequenceAccount,\n feeCollector: feeCollectorAccount,\n message: messageAccount.publicKey,\n wormholeBridge: wormholeBridgeAccount,\n // user: user.publicKey,\n })\n .preInstructions([this.getComputeUnitLimitInstruction(), feeInstruction])\n .signers([messageAccount])\n .transaction();\n\n return {\n tx: await this.finalizeTransaction(transaction, provider, userAccount),\n requiredMessageSigner: messageAccount,\n };\n }\n\n private async buildBridgeCctpTx(\n bridgeCctpData: BridgeCctpData\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner: Keypair }> {\n const {\n provider,\n payerProgram,\n\n amount,\n recipient,\n recipientToken,\n\n userAccount,\n recipientChain,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n\n lockAccount,\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n chainBridgeAccount,\n cctpBridgeProgramId,\n cctpBridgeAuthorityAccount,\n cctpBridgeConfigAccount,\n cctpBridgeTokenAccount,\n cctpTokenMessengerMinter,\n cctpTransmitterProgramId,\n messageTransmitterAccount,\n tokenMessenger,\n tokenMessengerEventAuthority,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n\n messageSentEventDataKeypair,\n } = bridgeCctpData;\n\n const transaction = await payerProgram.methods\n .bridgeCctp({\n amount,\n recipient,\n receiveToken: recipientToken,\n destinationChainId: recipientChain,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n })\n .accounts({\n lock: lockAccount,\n messageSentEventData: messageSentEventDataKeypair.publicKey,\n mint: mintAccount,\n feeTokenMint: feeTokenMintAccount,\n userFeeTokenAccount,\n bridgeToken: cctpBridgeTokenAccount,\n cctpBridge: cctpBridgeProgramId,\n cctpBridgeConfig: cctpBridgeConfigAccount,\n cctpMessenger: cctpTokenMessengerMinter,\n messageTransmitterProgram: cctpTransmitterProgramId,\n messageTransmitterAccount: messageTransmitterAccount,\n tokenMessenger,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n eventAuthority: tokenMessengerEventAuthority,\n gasPrice: gasPriceAccount,\n thisGasPrice: thisGasPriceAccount,\n chainBridge: chainBridgeAccount,\n bridgeAuthority: cctpBridgeAuthorityAccount,\n userTokenAccount,\n })\n .preInstructions([this.getComputeUnitLimitInstruction()])\n .transaction();\n\n return {\n tx: await this.finalizeTransaction(transaction, provider, userAccount),\n requiredMessageSigner: messageSentEventDataKeypair,\n };\n }\n\n private async buildBridgeCctpV2Tx(\n bridgeCctpData: BridgeCctpData\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner: Keypair }> {\n const {\n provider,\n payerProgram,\n\n amount,\n recipient,\n recipientToken,\n\n userAccount,\n recipientChain,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n\n lockAccount,\n mintAccount,\n feeTokenMintAccount,\n userTokenAccount,\n userFeeTokenAccount,\n gasPriceAccount,\n thisGasPriceAccount,\n\n chainBridgeAccount,\n cctpBridgeProgramId,\n cctpBridgeAuthorityAccount,\n cctpBridgeConfigAccount,\n cctpBridgeTokenAccount,\n cctpTokenMessengerMinter,\n cctpTransmitterProgramId,\n messageTransmitterAccount,\n tokenMessenger,\n tokenMessengerEventAuthority,\n tokenMinter,\n localToken,\n remoteTokenMessengerKey,\n authorityPda,\n\n messageSentEventDataKeypair,\n } = bridgeCctpData;\n\n const transaction = await payerProgram.methods\n .bridgeCctpV2({\n amount,\n recipient,\n receiveToken: recipientToken,\n destinationChainId: recipientChain,\n maxFeeAmount,\n extraGasAmountInFeeToken,\n })\n .accounts({\n mint: mintAccount,\n feeTokenMint: feeTokenMintAccount,\n userFeeTokenAccount,\n bridgeToken: cctpBridgeTokenAccount,\n cctpBridge: cctpBridgeProgramId,\n tokenMessengerMinterProgram: cctpTokenMessengerMinter,\n messageTransmitterProgram: cctpTransmitterProgramId,\n messageTransmitterAccount: messageTransmitterAccount,\n tokenMessenger,\n tokenMinter,\n localToken,\n remoteTokenMessenger: remoteTokenMessengerKey,\n authorityPda,\n eventAuthority: tokenMessengerEventAuthority,\n messageSentEventData: messageSentEventDataKeypair.publicKey,\n lock: lockAccount,\n cctpBridgeConfig: cctpBridgeConfigAccount,\n gasPrice: gasPriceAccount,\n thisGasPrice: thisGasPriceAccount,\n chainBridge: chainBridgeAccount,\n bridgeAuthority: cctpBridgeAuthorityAccount,\n userTokenAccount,\n })\n .preInstructions([this.getComputeUnitLimitInstruction()])\n .transaction();\n\n return {\n tx: await this.finalizeTransaction(transaction, provider, userAccount),\n requiredMessageSigner: messageSentEventDataKeypair,\n };\n }\n\n private async finalizeTransaction(\n transaction: web3.Transaction,\n provider: Provider,\n userAccount: PublicKey\n ): Promise<VersionedTransaction> {\n const connection = provider.connection;\n transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n transaction.feePayer = userAccount;\n return await convertToVersionedTransaction(transaction, connection, this.params.solanaLookUpTable);\n }\n}\n"]}
|