@allbridge/bridge-core-sdk 3.33.0-alpha.2 → 3.33.0
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 +4 -4
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +4 -4
- package/dist/src/services/bridge/cctp-utils.d.ts +1 -0
- package/dist/src/services/bridge/cctp-utils.js +13 -0
- package/dist/src/services/bridge/cctp-utils.js.map +1 -0
- package/dist/src/services/bridge/evm/abr-payer.d.ts +3 -0
- package/dist/src/services/bridge/evm/abr-payer.js +11 -0
- package/dist/src/services/bridge/evm/abr-payer.js.map +1 -0
- package/dist/src/services/bridge/evm/index.js +35 -10
- package/dist/src/services/bridge/evm/index.js.map +1 -1
- package/dist/src/services/bridge/sol/bridge-tx-service.d.ts +1 -0
- package/dist/src/services/bridge/sol/bridge-tx-service.js +25 -12
- package/dist/src/services/bridge/sol/bridge-tx-service.js.map +1 -1
- package/dist/src/services/bridge/sol/index.js.map +1 -1
- package/dist/src/services/bridge/sol/payer-with-token-service.js +14 -1
- package/dist/src/services/bridge/sol/payer-with-token-service.js.map +1 -1
- package/dist/src/services/bridge/srb/index.d.ts +1 -1
- package/dist/src/services/bridge/srb/index.js +33 -3
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/models/abi/CctpBridge.d.ts +40 -0
- package/dist/src/services/models/abi/CctpBridge.js +52 -0
- package/dist/src/services/models/abi/CctpBridge.js.map +1 -1
- package/dist/src/services/models/sol/types/cctp_v2_bridge.d.ts +254 -0
- package/dist/src/services/models/sol/types/cctp_v2_bridge.js.map +1 -1
- package/dist/src/services/models/sol/types/cctp_v2_bridge.json +254 -0
- package/dist/src/services/models/sol/types/payer_with_token.d.ts +6 -0
- 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 +6 -0
- package/dist/src/services/models/srb/cctp-bridge-contract.d.ts +451 -0
- package/dist/src/services/models/srb/cctp-bridge-contract.js +150 -0
- package/dist/src/services/models/srb/cctp-bridge-contract.js.map +1 -0
- package/dist/src/services/utils/srb/index.d.ts +1 -0
- package/dist/src/services/utils/srb/index.js +9 -0
- package/dist/src/services/utils/srb/index.js.map +1 -0
- 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 +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiC,MAAM,iBAAiB,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,qCAAqC,EAAE,MAAM,gCAAgC,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAA+B,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAmB,MAAM,SAAS,CAAC;AA2BjE,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiC,MAAM,iBAAiB,CAAC;AAE5E,OAAO,EAAE,Y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C,OAAO,IAAI,CAAC,qBAAqB,CAAC,uBAAuB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACrF,CAAC;IAED,IAAI,CAAC,OAAmB;QACtB,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;IAEO,cAAc,CAAC,MAAkB,EAAE,YAA6B;QACtE,OAAO;YACL,GAAG,YAAY;YACf,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,WAAW;SAC5C,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Connection, Keypair, VersionedTransaction } from \"@solana/web3.js\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { JupiterError, MethodNotSupportedError } from \"../../../exceptions\";\nimport { ChainType, FeePaymentMethod, SwapParams } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { addUnitLimitAndUnitPriceToVersionedTx } from \"../../utils/sol/compute-budget\";\nimport { ChainBridgeService, SendParams, TxSendParamsSol } from \"../models\";\nimport { prepareTxSendParams } from \"../utils\";\nimport { BridgeTxService } from \"./bridge-tx-service\";\nimport { JupiterParams, JupiterService } from \"./jupiter-service\";\nimport { PayerWithTokenService } from \"./payer-with-token-service\";\nimport { amendJupiterWithSdkTx, SolTxSendParams } from \"./utils\";\n\nexport interface SolanaBridgeParams {\n /** @deprecated Do not use. */\n wormholeMessengerProgramId?: string;\n solanaLookUpTable: string;\n cctpParams: CctpParams;\n jupiterParams: JupiterParams;\n}\n\nexport interface CctpParams {\n cctpTransmitterProgramId: string;\n cctpTokenMessengerMinter: string;\n cctpV2TransmitterProgramId: string;\n cctpV2TokenMessengerMinter: 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\nexport class SolanaBridgeService extends ChainBridgeService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n\n private readonly connection: Connection;\n private jupiterService: JupiterService;\n private bridgeTxService: BridgeTxService;\n private payerWithTokenService: PayerWithTokenService;\n constructor(\n public solanaRpcUrl: string,\n public params: SolanaBridgeParams,\n public api: AllbridgeCoreClient\n ) {\n super();\n this.connection = new Connection(solanaRpcUrl);\n this.jupiterService = new JupiterService(api, params.jupiterParams);\n this.bridgeTxService = new BridgeTxService(solanaRpcUrl, params, api);\n this.payerWithTokenService = new PayerWithTokenService(solanaRpcUrl, params, api);\n }\n\n /** @deprecated Do not use. */\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n return this.bridgeTxService.buildRawTransactionSwap(params);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const solTxSendParams = this.addPoolAddress(params, txSendParams);\n\n const paymentType = params.gasFeePaymentMethod ?? FeePaymentMethod.WITH_NATIVE_CURRENCY;\n\n let tx: VersionedTransaction;\n let requiredMessageSigner: Keypair | undefined;\n\n switch (paymentType) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n const builtTxResult = await this.buildTxWithNativePayment(params, solTxSendParams);\n tx = builtTxResult.tx;\n requiredMessageSigner = builtTxResult.requiredMessageSigner;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n const builtTxResult = await this.buildTxWithStablePayment(params, solTxSendParams);\n tx = builtTxResult.tx;\n requiredMessageSigner = builtTxResult.requiredMessageSigner;\n break;\n }\n case FeePaymentMethod.WITH_ABR: {\n const builtTxResult = await this.buildTxWithAbrPayment(params, solTxSendParams);\n tx = builtTxResult.tx;\n requiredMessageSigner = builtTxResult.requiredMessageSigner;\n break;\n }\n default: {\n return assertNever(paymentType, \"Unhandled FeePaymentMethod\");\n }\n }\n await addUnitLimitAndUnitPriceToVersionedTx(tx, params.txFeeParams, this.solanaRpcUrl);\n\n if (requiredMessageSigner) {\n tx.sign([requiredMessageSigner]);\n }\n return tx;\n }\n\n private async buildTxWithNativePayment(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner: Keypair | undefined }> {\n return await this.bridgeTxService.buildRawTransactionSend(params, solTxSendParams);\n }\n\n private async buildTxWithStablePayment(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner: Keypair | undefined }> {\n const { jupTx, solTxSendParams: updatedSolTxSendParams } = await this.jupiterService.buildJupAndUpdateTxSendParams(\n params,\n solTxSendParams\n );\n\n const { tx, requiredMessageSigner } = await this.bridgeTxService.buildRawTransactionSend(\n params,\n updatedSolTxSendParams\n );\n\n if (!jupTx) {\n throw new JupiterError(\"Swap tx is absent\");\n }\n const resultTx = await amendJupiterWithSdkTx(this.connection, jupTx, tx);\n return { tx: resultTx, requiredMessageSigner: requiredMessageSigner };\n }\n\n private async buildTxWithAbrPayment(\n params: SendParams,\n solTxSendParams: SolTxSendParams\n ): Promise<{ tx: VersionedTransaction; requiredMessageSigner?: Keypair }> {\n return this.payerWithTokenService.buildRawTransactionSend(params, solTxSendParams);\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n private addPoolAddress(params: SendParams, txSendParams: TxSendParamsSol): SolTxSendParams {\n return {\n ...txSendParams,\n poolAddress: params.sourceToken.poolAddress,\n };\n }\n}\n"]}
|
|
@@ -9,6 +9,8 @@ import * as payerWithTokenIdl from "../../models/sol/types/payer_with_token.json
|
|
|
9
9
|
import { getMessage, getVUsdAmount } from "../../utils/sol";
|
|
10
10
|
import { getAssociatedAccount, getAuthorityAccount, getBridgeTokenAccount, getCctpAccounts, getCctpAuthorityAccount, getCctpBridgeAccount, getCctpLockAccount, getCctpV2BridgeConfigAccount, getChainBridgeAccount, getConfigAccount, getGasUsageAccount, getLockAccount, getOtherChainTokenAccount, getPriceAccount, getSendMessageAccount, } from "../../utils/sol/accounts";
|
|
11
11
|
import { buildAnchorProvider } from "../../utils/sol/anchor-provider";
|
|
12
|
+
import { decodeStellarContractId } from "../../utils/srb";
|
|
13
|
+
import { encodeCctpHookForStellar } from "../cctp-utils";
|
|
12
14
|
import { getNonce } from "../utils";
|
|
13
15
|
import { convertToVersionedTransaction } from "./utils";
|
|
14
16
|
const COMPUTE_UNIT_LIMIT = 1_000_000;
|
|
@@ -216,6 +218,7 @@ export class PayerWithTokenService {
|
|
|
216
218
|
const destinationChainSymbol = params.destinationToken.chainSymbol;
|
|
217
219
|
const domain = this.params.cctpParams.cctpDomains[destinationChainSymbol];
|
|
218
220
|
let cctpVersion;
|
|
221
|
+
let hookData;
|
|
219
222
|
let cctpAddress;
|
|
220
223
|
let cctpTransmitterProgramIdAddress;
|
|
221
224
|
let cctpTokenMessengerMinterAddress;
|
|
@@ -230,6 +233,14 @@ export class PayerWithTokenService {
|
|
|
230
233
|
cctpAddress = params.sourceToken.cctpV2Address;
|
|
231
234
|
cctpTransmitterProgramIdAddress = this.params.cctpParams.cctpV2TransmitterProgramId;
|
|
232
235
|
cctpTokenMessengerMinterAddress = this.params.cctpParams.cctpV2TokenMessengerMinter;
|
|
236
|
+
if (params.destinationToken.chainType === ChainType.SRB) {
|
|
237
|
+
const destinationCctpV2Address = params.destinationToken.cctpV2Address;
|
|
238
|
+
if (!destinationCctpV2Address) {
|
|
239
|
+
throw new CCTPDoesNotSupportedError("Such route does not support CCTP V2 protocol");
|
|
240
|
+
}
|
|
241
|
+
baseData.recipient = Array.from(decodeStellarContractId(destinationCctpV2Address));
|
|
242
|
+
hookData = encodeCctpHookForStellar(params.toAccountAddress);
|
|
243
|
+
}
|
|
233
244
|
}
|
|
234
245
|
if (domain == undefined || !cctpTransmitterProgramIdAddress || !cctpTokenMessengerMinterAddress) {
|
|
235
246
|
throw new SdkError(`CCTP ${cctpVersion} is not configured`);
|
|
@@ -254,6 +265,7 @@ export class PayerWithTokenService {
|
|
|
254
265
|
lockAccount,
|
|
255
266
|
messageSentEventDataKeypair,
|
|
256
267
|
amount: new BN(amount),
|
|
268
|
+
hookData,
|
|
257
269
|
chainBridgeAccount,
|
|
258
270
|
cctpBridgeProgramId,
|
|
259
271
|
cctpBridgeAuthorityAccount,
|
|
@@ -394,7 +406,7 @@ export class PayerWithTokenService {
|
|
|
394
406
|
};
|
|
395
407
|
}
|
|
396
408
|
async buildBridgeCctpV2Tx(bridgeCctpData) {
|
|
397
|
-
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;
|
|
409
|
+
const { provider, payerProgram, amount, recipient, recipientToken, hookData, 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;
|
|
398
410
|
const transaction = await payerProgram.methods
|
|
399
411
|
.bridgeCctpV2({
|
|
400
412
|
amount,
|
|
@@ -403,6 +415,7 @@ export class PayerWithTokenService {
|
|
|
403
415
|
destinationChainId: recipientChain,
|
|
404
416
|
maxFeeAmount,
|
|
405
417
|
extraGasAmountInFeeToken,
|
|
418
|
+
hookData: hookData ?? null,
|
|
406
419
|
})
|
|
407
420
|
.accounts({
|
|
408
421
|
mint: mintAccount,
|
|
@@ -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,OAAO,EAAE,EAAE,EAAE,OAAO,EAAY,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAgD,MAAM,iBAAiB,CAAC;AAClH,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,wBAAwB,EACxB,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,KAAK,SAAS,MAAM,oCAAoC,CAAC;AAEhE,OAAO,KAAK,iBAAiB,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,4BAA4B,EAC5B,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,yBAAyB,EACzB,eAAe,EACf,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,6BAA6B,EAAmB,MAAM,SAAS,CA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ACnD,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,6BAA6B,CAAC,WAAW,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACrG,CAAC;CACF","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 if (!wormholeProgramId) {\n throw new SdkError(\"Do not use.\");\n }\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"]}
|
|
1
|
+
{"version":3,"file":"payer-with-token-service.js","sourceRoot":"","sources":["../../../../../src/services/bridge/sol/payer-with-token-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,OAAO,EAAY,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAgD,MAAM,iBAAiB,CAAC;AAClH,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,wBAAwB,EACxB,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,KA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,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,6BAA6B,CAAC,WAAW,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACrG,CAAC;CACF","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 { decodeStellarContractId } from \"../../utils/srb\";\nimport { encodeCctpHookForStellar } from \"../cctp-utils\";\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 hookData?: Buffer;\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 if (!wormholeProgramId) {\n throw new SdkError(\"Do not use.\");\n }\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 hookData: Buffer | 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 if (params.destinationToken.chainType === ChainType.SRB) {\n const destinationCctpV2Address = params.destinationToken.cctpV2Address;\n if (!destinationCctpV2Address) {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n baseData.recipient = Array.from(decodeStellarContractId(destinationCctpV2Address));\n hookData = encodeCctpHookForStellar(params.toAccountAddress);\n }\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 hookData,\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 hookData,\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 hookData: hookData ?? null,\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"]}
|
|
@@ -10,7 +10,7 @@ export declare class SrbBridgeService extends ChainBridgeService {
|
|
|
10
10
|
chainType: ChainType.SRB;
|
|
11
11
|
constructor(nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, api: AllbridgeCoreClient);
|
|
12
12
|
buildRawTransactionSend(params: SendParams): Promise<RawTransaction>;
|
|
13
|
-
buildRawTransactionSendFromParams(params: TxSendParamsSrb): Promise<RawTransaction>;
|
|
13
|
+
buildRawTransactionSendFromParams(params: TxSendParamsSrb, sendParams?: SendParams): Promise<RawTransaction>;
|
|
14
14
|
/** @deprecated Do not use. */
|
|
15
15
|
buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction>;
|
|
16
16
|
/** @deprecated Do not use. */
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Address } from "@stellar/stellar-sdk";
|
|
2
2
|
import { Big } from "big.js";
|
|
3
3
|
import { ChainSymbol } from "../../../chains/chain.enums";
|
|
4
|
+
import { Messenger } from "../../../client/core-api/core-api.model";
|
|
4
5
|
import { MethodNotSupportedError, SdkError } from "../../../exceptions";
|
|
5
6
|
import { ChainType } from "../../../index";
|
|
6
7
|
import { FeePaymentMethod } from "../../../models";
|
|
7
8
|
import { assertNever } from "../../../utils/utils";
|
|
8
9
|
import { BridgeContract } from "../../models/srb/bridge-contract";
|
|
10
|
+
import { Client as CctpBridgeContract } from "../../models/srb/cctp-bridge-contract";
|
|
9
11
|
import { getSorobanInclusionFee } from "../../models/srb/utils";
|
|
12
|
+
import { getCctpSolTokenRecipientAddress } from "../get-cctp-sol-token-recipient-address";
|
|
10
13
|
import { ChainBridgeService } from "../models";
|
|
11
14
|
import { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from "../utils";
|
|
12
15
|
export class SrbBridgeService extends ChainBridgeService {
|
|
@@ -22,16 +25,43 @@ export class SrbBridgeService extends ChainBridgeService {
|
|
|
22
25
|
}
|
|
23
26
|
async buildRawTransactionSend(params) {
|
|
24
27
|
const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);
|
|
25
|
-
return await this.buildRawTransactionSendFromParams(txSendParams);
|
|
28
|
+
return await this.buildRawTransactionSendFromParams(txSendParams, params);
|
|
26
29
|
}
|
|
27
|
-
async buildRawTransactionSendFromParams(params) {
|
|
30
|
+
async buildRawTransactionSendFromParams(params, sendParams) {
|
|
28
31
|
const { amount, contractAddress, fromAccountAddress, fromTokenAddress, toChainId, toAccountAddress, toTokenAddress, fee, gasFeePaymentMethod, extraGas, } = params;
|
|
29
32
|
let totalFee = fee;
|
|
30
33
|
if (extraGas) {
|
|
31
34
|
totalFee = Big(totalFee).plus(extraGas).toFixed();
|
|
32
35
|
}
|
|
33
|
-
const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);
|
|
34
36
|
const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));
|
|
37
|
+
if (params.messenger === Messenger.CCTP_V2) {
|
|
38
|
+
const contract = this.getContract(CctpBridgeContract, contractAddress, fromAccountAddress);
|
|
39
|
+
const recipient = sendParams?.destinationToken.chainType === ChainType.SOLANA
|
|
40
|
+
? await getCctpSolTokenRecipientAddress(this.chainType, sendParams.toAccountAddress, sendParams.destinationToken.tokenAddress, this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL))
|
|
41
|
+
: toAccountAddress;
|
|
42
|
+
if (gasFeePaymentMethod === FeePaymentMethod.WITH_ABR) {
|
|
43
|
+
throw new SdkError("SRB CCTPv2 bridge does not support ABR payment method");
|
|
44
|
+
}
|
|
45
|
+
let cctpFee;
|
|
46
|
+
switch (gasFeePaymentMethod) {
|
|
47
|
+
case FeePaymentMethod.WITH_NATIVE_CURRENCY:
|
|
48
|
+
cctpFee = { gas_amount: BigInt(totalFee), fee_token_amount: 0n };
|
|
49
|
+
break;
|
|
50
|
+
case FeePaymentMethod.WITH_STABLECOIN:
|
|
51
|
+
cctpFee = { gas_amount: 0n, fee_token_amount: BigInt(totalFee) };
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
return assertNever(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
55
|
+
}
|
|
56
|
+
return (await contract.bridge({
|
|
57
|
+
sender: fromAccountAddress,
|
|
58
|
+
amount: BigInt(amount),
|
|
59
|
+
recipient: Buffer.from(recipient),
|
|
60
|
+
destination_chain_id: +toChainId,
|
|
61
|
+
...cctpFee,
|
|
62
|
+
}, { fee: inclusionFee })).toXDR();
|
|
63
|
+
}
|
|
64
|
+
const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);
|
|
35
65
|
let tx;
|
|
36
66
|
switch (gasFeePaymentMethod) {
|
|
37
67
|
case FeePaymentMethod.WITH_NATIVE_CURRENCY:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAA2B,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAA4D,MAAM,WAAW,CAAC;AACzG,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGpF,MAAM,OAAO,gBAAiB,SAAQ,kBAAkB;IAI3C;IACA;IACA;IALX,SAAS,GAAkB,SAAS,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,GA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B,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF","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 { getSorobanInclusionFee } from \"../../models/srb/utils\";\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 const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n let tx;\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n tx = await contract.swap_and_bridge(\n {\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 { fee: inclusionFee }\n );\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n tx = await contract.swap_and_bridge(\n {\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 { fee: inclusionFee }\n );\n break;\n case FeePaymentMethod.WITH_ABR:\n throw new SdkError(\"SRB bridge does not support ABR payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return tx.toXDR();\n }\n\n /** @deprecated Do not use. */\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n /** @deprecated Do not use. */\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 const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await contract.swap(\n {\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 { fee: inclusionFee }\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"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAA2B,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,MAAM,IAAI,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,+BAA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AI,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,EACD,EAAE,GAAG,EAAE,YAAY,EAAE,CACtB,CACF,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,6DAA6D;IAC7D,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,uBAAuB,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,WAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { Address, contract } from \"@stellar/stellar-sdk\";\nimport { Big } from \"big.js\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { Messenger } from \"../../../client/core-api/core-api.model\";\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 { Client as CctpBridgeContract } from \"../../models/srb/cctp-bridge-contract\";\nimport { getSorobanInclusionFee } from \"../../models/srb/utils\";\nimport { getCctpSolTokenRecipientAddress } from \"../get-cctp-sol-token-recipient-address\";\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, params);\n }\n\n async buildRawTransactionSendFromParams(params: TxSendParamsSrb, sendParams?: SendParams): 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 inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n if (params.messenger === Messenger.CCTP_V2) {\n const contract = this.getContract(CctpBridgeContract, contractAddress, fromAccountAddress);\n const recipient =\n sendParams?.destinationToken.chainType === ChainType.SOLANA\n ? await getCctpSolTokenRecipientAddress(\n this.chainType,\n sendParams.toAccountAddress,\n sendParams.destinationToken.tokenAddress,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL)\n )\n : toAccountAddress;\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ABR) {\n throw new SdkError(\"SRB CCTPv2 bridge does not support ABR payment method\");\n }\n let cctpFee: { gas_amount: bigint; fee_token_amount: bigint };\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n cctpFee = { gas_amount: BigInt(totalFee), fee_token_amount: 0n };\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n cctpFee = { gas_amount: 0n, fee_token_amount: BigInt(totalFee) };\n break;\n default:\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n\n return (\n await contract.bridge(\n {\n sender: fromAccountAddress,\n amount: BigInt(amount),\n recipient: Buffer.from(recipient),\n destination_chain_id: +toChainId,\n ...cctpFee,\n },\n { fee: inclusionFee as unknown as string }\n )\n ).toXDR();\n }\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 {\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 { fee: inclusionFee }\n );\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n tx = await contract.swap_and_bridge(\n {\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 { fee: inclusionFee }\n );\n break;\n case FeePaymentMethod.WITH_ABR:\n throw new SdkError(\"SRB bridge does not support ABR payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return tx.toXDR();\n }\n\n /** @deprecated Do not use. */\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n /** @deprecated Do not use. */\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 const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await contract.swap(\n {\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 { fee: inclusionFee }\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"]}
|
|
@@ -192,6 +192,32 @@ declare const artifact: {
|
|
|
192
192
|
readonly outputs: readonly [];
|
|
193
193
|
readonly stateMutability: "payable";
|
|
194
194
|
readonly type: "function";
|
|
195
|
+
}, {
|
|
196
|
+
readonly inputs: readonly [{
|
|
197
|
+
readonly internalType: "uint256";
|
|
198
|
+
readonly name: "amount";
|
|
199
|
+
readonly type: "uint256";
|
|
200
|
+
}, {
|
|
201
|
+
readonly internalType: "bytes32";
|
|
202
|
+
readonly name: "mintRecipient";
|
|
203
|
+
readonly type: "bytes32";
|
|
204
|
+
}, {
|
|
205
|
+
readonly internalType: "uint256";
|
|
206
|
+
readonly name: "destinationChainId";
|
|
207
|
+
readonly type: "uint256";
|
|
208
|
+
}, {
|
|
209
|
+
readonly internalType: "uint256";
|
|
210
|
+
readonly name: "relayerFeeTokenAmount";
|
|
211
|
+
readonly type: "uint256";
|
|
212
|
+
}, {
|
|
213
|
+
readonly internalType: "bytes";
|
|
214
|
+
readonly name: "hookData";
|
|
215
|
+
readonly type: "bytes";
|
|
216
|
+
}];
|
|
217
|
+
readonly name: "bridgeWithHook";
|
|
218
|
+
readonly outputs: readonly [];
|
|
219
|
+
readonly stateMutability: "payable";
|
|
220
|
+
readonly type: "function";
|
|
195
221
|
}, {
|
|
196
222
|
readonly inputs: readonly [{
|
|
197
223
|
readonly internalType: "uint256";
|
|
@@ -330,6 +356,20 @@ declare const artifact: {
|
|
|
330
356
|
}];
|
|
331
357
|
readonly stateMutability: "view";
|
|
332
358
|
readonly type: "function";
|
|
359
|
+
}, {
|
|
360
|
+
readonly inputs: readonly [{
|
|
361
|
+
readonly internalType: "uint256";
|
|
362
|
+
readonly name: "chainId";
|
|
363
|
+
readonly type: "uint256";
|
|
364
|
+
}];
|
|
365
|
+
readonly name: "otherBridges";
|
|
366
|
+
readonly outputs: readonly [{
|
|
367
|
+
readonly internalType: "bytes32";
|
|
368
|
+
readonly name: "cctpBridgeAddress";
|
|
369
|
+
readonly type: "bytes32";
|
|
370
|
+
}];
|
|
371
|
+
readonly stateMutability: "view";
|
|
372
|
+
readonly type: "function";
|
|
333
373
|
}, {
|
|
334
374
|
readonly inputs: readonly [{
|
|
335
375
|
readonly internalType: "address";
|
|
@@ -243,6 +243,39 @@ const artifact = {
|
|
|
243
243
|
stateMutability: "payable",
|
|
244
244
|
type: "function",
|
|
245
245
|
},
|
|
246
|
+
{
|
|
247
|
+
inputs: [
|
|
248
|
+
{
|
|
249
|
+
internalType: "uint256",
|
|
250
|
+
name: "amount",
|
|
251
|
+
type: "uint256",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
internalType: "bytes32",
|
|
255
|
+
name: "mintRecipient",
|
|
256
|
+
type: "bytes32",
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
internalType: "uint256",
|
|
260
|
+
name: "destinationChainId",
|
|
261
|
+
type: "uint256",
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
internalType: "uint256",
|
|
265
|
+
name: "relayerFeeTokenAmount",
|
|
266
|
+
type: "uint256",
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
internalType: "bytes",
|
|
270
|
+
name: "hookData",
|
|
271
|
+
type: "bytes",
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
name: "bridgeWithHook",
|
|
275
|
+
outputs: [],
|
|
276
|
+
stateMutability: "payable",
|
|
277
|
+
type: "function",
|
|
278
|
+
},
|
|
246
279
|
{
|
|
247
280
|
inputs: [
|
|
248
281
|
{
|
|
@@ -425,6 +458,25 @@ const artifact = {
|
|
|
425
458
|
stateMutability: "view",
|
|
426
459
|
type: "function",
|
|
427
460
|
},
|
|
461
|
+
{
|
|
462
|
+
inputs: [
|
|
463
|
+
{
|
|
464
|
+
internalType: "uint256",
|
|
465
|
+
name: "chainId",
|
|
466
|
+
type: "uint256",
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
name: "otherBridges",
|
|
470
|
+
outputs: [
|
|
471
|
+
{
|
|
472
|
+
internalType: "bytes32",
|
|
473
|
+
name: "cctpBridgeAddress",
|
|
474
|
+
type: "bytes32",
|
|
475
|
+
},
|
|
476
|
+
],
|
|
477
|
+
stateMutability: "view",
|
|
478
|
+
type: "function",
|
|
479
|
+
},
|
|
428
480
|
{
|
|
429
481
|
inputs: [
|
|
430
482
|
{
|