@allbridge/bridge-core-sdk 3.36.0-beta.1 → 3.36.0-beta.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.
Files changed (103) hide show
  1. package/dist/browser/index.js +2 -2
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/index.js.map +4 -4
  5. package/dist/esm/index.js +2 -2
  6. package/dist/esm/index.js.map +4 -4
  7. package/dist/src/client/core-api/api-client-caching.d.ts +6 -1
  8. package/dist/src/client/core-api/api-client-caching.js +11 -0
  9. package/dist/src/client/core-api/api-client-caching.js.map +1 -1
  10. package/dist/src/client/core-api/api-client.d.ts +27 -1
  11. package/dist/src/client/core-api/api-client.js +68 -2
  12. package/dist/src/client/core-api/api-client.js.map +1 -1
  13. package/dist/src/client/core-api/core-api-mapper.d.ts +3 -1
  14. package/dist/src/client/core-api/core-api-mapper.js +6 -3
  15. package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
  16. package/dist/src/client/core-api/core-api.model.d.ts +100 -3
  17. package/dist/src/client/core-api/core-api.model.js +9 -0
  18. package/dist/src/client/core-api/core-api.model.js.map +1 -1
  19. package/dist/src/client/core-api/core-client-base.d.ts +7 -1
  20. package/dist/src/client/core-api/core-client-base.js +9 -0
  21. package/dist/src/client/core-api/core-client-base.js.map +1 -1
  22. package/dist/src/client/core-api/core-client-filtered.d.ts +4 -1
  23. package/dist/src/client/core-api/core-client-filtered.js +9 -0
  24. package/dist/src/client/core-api/core-client-filtered.js.map +1 -1
  25. package/dist/src/client/core-api/core-client-pool-info-caching.d.ts +4 -1
  26. package/dist/src/client/core-api/core-client-pool-info-caching.js +9 -0
  27. package/dist/src/client/core-api/core-client-pool-info-caching.js.map +1 -1
  28. package/dist/src/exceptions/exceptions.d.ts +41 -0
  29. package/dist/src/exceptions/exceptions.js +52 -0
  30. package/dist/src/exceptions/exceptions.js.map +1 -1
  31. package/dist/src/index.d.ts +19 -6
  32. package/dist/src/index.js +6 -1
  33. package/dist/src/index.js.map +1 -1
  34. package/dist/src/models/index.d.ts +4 -2
  35. package/dist/src/models/index.js.map +1 -1
  36. package/dist/src/services/bridge/alg/index.d.ts +5 -1
  37. package/dist/src/services/bridge/alg/index.js +7 -0
  38. package/dist/src/services/bridge/alg/index.js.map +1 -1
  39. package/dist/src/services/bridge/evm/index.d.ts +12 -2
  40. package/dist/src/services/bridge/evm/index.js +32 -0
  41. package/dist/src/services/bridge/evm/index.js.map +1 -1
  42. package/dist/src/services/bridge/index.d.ts +10 -3
  43. package/dist/src/services/bridge/index.js +27 -3
  44. package/dist/src/services/bridge/index.js.map +1 -1
  45. package/dist/src/services/bridge/models/bridge.d.ts +17 -1
  46. package/dist/src/services/bridge/models/bridge.js +6 -0
  47. package/dist/src/services/bridge/models/bridge.js.map +1 -1
  48. package/dist/src/services/bridge/models/bridge.model.d.ts +25 -0
  49. package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
  50. package/dist/src/services/bridge/raw-bridge-transaction-builder.d.ts +8 -1
  51. package/dist/src/services/bridge/raw-bridge-transaction-builder.js +11 -1
  52. package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
  53. package/dist/src/services/bridge/sol/bridge-tx-service.js +3 -0
  54. package/dist/src/services/bridge/sol/bridge-tx-service.js.map +1 -1
  55. package/dist/src/services/bridge/sol/index.d.ts +14 -1
  56. package/dist/src/services/bridge/sol/index.js +47 -2
  57. package/dist/src/services/bridge/sol/index.js.map +1 -1
  58. package/dist/src/services/bridge/sol/payer-with-token-service.js +3 -0
  59. package/dist/src/services/bridge/sol/payer-with-token-service.js.map +1 -1
  60. package/dist/src/services/bridge/spender.js +4 -0
  61. package/dist/src/services/bridge/spender.js.map +1 -1
  62. package/dist/src/services/bridge/srb/index.d.ts +9 -1
  63. package/dist/src/services/bridge/srb/index.js +45 -3
  64. package/dist/src/services/bridge/srb/index.js.map +1 -1
  65. package/dist/src/services/bridge/stx/index.d.ts +6 -2
  66. package/dist/src/services/bridge/stx/index.js +7 -0
  67. package/dist/src/services/bridge/stx/index.js.map +1 -1
  68. package/dist/src/services/bridge/sui/index.d.ts +8 -1
  69. package/dist/src/services/bridge/sui/index.js +24 -0
  70. package/dist/src/services/bridge/sui/index.js.map +1 -1
  71. package/dist/src/services/bridge/trx/index.d.ts +11 -1
  72. package/dist/src/services/bridge/trx/index.js +25 -0
  73. package/dist/src/services/bridge/trx/index.js.map +1 -1
  74. package/dist/src/services/bridge/utils.js +4 -1
  75. package/dist/src/services/bridge/utils.js.map +1 -1
  76. package/dist/src/services/index.d.ts +10 -0
  77. package/dist/src/services/index.js +36 -1
  78. package/dist/src/services/index.js.map +1 -1
  79. package/dist/src/services/near-intents/index.d.ts +62 -0
  80. package/dist/src/services/near-intents/index.js +115 -0
  81. package/dist/src/services/near-intents/index.js.map +1 -0
  82. package/dist/src/services/near-intents/models.d.ts +169 -0
  83. package/dist/src/services/near-intents/models.js +2 -0
  84. package/dist/src/services/near-intents/models.js.map +1 -0
  85. package/dist/src/services/near-intents/utils.d.ts +34 -0
  86. package/dist/src/services/near-intents/utils.js +53 -0
  87. package/dist/src/services/near-intents/utils.js.map +1 -0
  88. package/dist/src/services/token/evm/index.js +3 -0
  89. package/dist/src/services/token/evm/index.js.map +1 -1
  90. package/dist/src/services/token/sol/index.js +3 -0
  91. package/dist/src/services/token/sol/index.js.map +1 -1
  92. package/dist/src/services/token/srb/index.js +11 -0
  93. package/dist/src/services/token/srb/index.js.map +1 -1
  94. package/dist/src/services/token/sui/index.js +5 -0
  95. package/dist/src/services/token/sui/index.js.map +1 -1
  96. package/dist/src/services/token/trx/index.js +3 -0
  97. package/dist/src/services/token/trx/index.js.map +1 -1
  98. package/dist/src/tokens-info/tokens-info.model.d.ts +23 -1
  99. package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
  100. package/dist/src/version.d.ts +1 -1
  101. package/dist/src/version.js +1 -1
  102. package/dist/src/version.js.map +1 -1
  103. package/package.json +1 -1
@@ -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;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,6BAA6B,EAAmB,MAAM,SAAS,CAAC;AAkFzE,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAErC,MAAM,OAAO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AE,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,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"]}
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,kCAAkC,EAAE,MAAM,0BAA0B,CAAC;AAC9E,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,0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;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 { nearIntentsNotABridgeContractError } from \"../../near-intents/utils\";\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 case Messenger.NEAR_INTENTS:\n throw nearIntentsNotABridgeContractError();\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"]}
@@ -1,7 +1,11 @@
1
1
  import { Messenger } from "../../client/core-api/core-api.model";
2
2
  import { CCTPDoesNotSupportedError, OFTDoesNotSupportedError, SdkError } from "../../exceptions";
3
3
  import { FeePaymentMethod } from "../../models";
4
+ import { nearIntentsNoApprovalError } from "../near-intents/utils";
4
5
  export function resolveSpender(token, messenger, gasFeePaymentMethod = FeePaymentMethod.WITH_NATIVE_CURRENCY) {
6
+ if (messenger === Messenger.NEAR_INTENTS) {
7
+ throw nearIntentsNoApprovalError();
8
+ }
5
9
  if (gasFeePaymentMethod === FeePaymentMethod.WITH_ABR) {
6
10
  if (token.abrPayer) {
7
11
  return token.abrPayer.payerAddress;
@@ -1 +1 @@
1
- {"version":3,"file":"spender.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,KAAK,CAAC,QAAQ,EAAE,aAAa,EAAE,CAAC;gBAClC,OAAO,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;YACtC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,QAAQ,CAAC,+CAA+C,CAAC,CAAC;YACtE,CAAC;QACH,KAAK,SAAS,CAAC,SAAS,CAAC;QACzB,KAAK,SAAS,CAAC,QAAQ;YACrB,OAAO,KAAK,CAAC,aAAa,CAAC;IAC/B,CAAC;AACH,CAAC","sourcesContent":["import { Messenger } from \"../../client/core-api/core-api.model\";\nimport { CCTPDoesNotSupportedError, OFTDoesNotSupportedError, SdkError } from \"../../exceptions\";\nimport { FeePaymentMethod } from \"../../models\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\n\nexport function resolveSpender(\n token: TokenWithChainDetails,\n messenger: Messenger,\n gasFeePaymentMethod: FeePaymentMethod = FeePaymentMethod.WITH_NATIVE_CURRENCY\n): string {\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ABR) {\n if (token.abrPayer) {\n return token.abrPayer.payerAddress;\n }\n throw new SdkError(\"Token must contain 'abrPayer' for ABR payment method\");\n }\n switch (messenger) {\n case Messenger.CCTP:\n if (token.cctpAddress) {\n return token.cctpAddress;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n case Messenger.CCTP_V2:\n if (token.cctpV2Address) {\n return token.cctpV2Address;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n case Messenger.OFT:\n if (token.oftBridgeAddress) {\n return token.oftBridgeAddress;\n } else {\n throw new OFTDoesNotSupportedError(\"Such route does not support OFT protocol\");\n }\n case Messenger.X_RESERVE:\n if (token.xReserve?.bridgeAddress) {\n return token.xReserve.bridgeAddress;\n } else {\n throw new SdkError(\"Such route does not support xReserve protocol\");\n }\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n return token.bridgeAddress;\n }\n}\n"]}
1
+ {"version":3,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AO,KAAK,CAAC,gBAAgB,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,wBAAwB,CAAC,0CAA0C,CAAC,CAAC;YACjF,CAAC;QACH,KAAK,SAAS,CAAC,SAAS;YACtB,IAAI,KAAK,CAAC,QAAQ,EAAE,aAAa,EAAE,CAAC;gBAClC,OAAO,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;YACtC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,QAAQ,CAAC,+CAA+C,CAAC,CAAC;YACtE,CAAC;QACH,KAAK,SAAS,CAAC,SAAS,CAAC;QACzB,KAAK,SAAS,CAAC,QAAQ;YACrB,OAAO,KAAK,CAAC,aAAa,CAAC;IAC/B,CAAC;AACH,CAAC","sourcesContent":["import { Messenger } from \"../../client/core-api/core-api.model\";\nimport { CCTPDoesNotSupportedError, OFTDoesNotSupportedError, SdkError } from \"../../exceptions\";\nimport { FeePaymentMethod } from \"../../models\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\nimport { nearIntentsNoApprovalError } from \"../near-intents/utils\";\n\nexport function resolveSpender(\n token: TokenWithChainDetails,\n messenger: Messenger,\n gasFeePaymentMethod: FeePaymentMethod = FeePaymentMethod.WITH_NATIVE_CURRENCY\n): string {\n if (messenger === Messenger.NEAR_INTENTS) {\n throw nearIntentsNoApprovalError();\n }\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ABR) {\n if (token.abrPayer) {\n return token.abrPayer.payerAddress;\n }\n throw new SdkError(\"Token must contain 'abrPayer' for ABR payment method\");\n }\n switch (messenger) {\n case Messenger.CCTP:\n if (token.cctpAddress) {\n return token.cctpAddress;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n case Messenger.CCTP_V2:\n if (token.cctpV2Address) {\n return token.cctpV2Address;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n case Messenger.OFT:\n if (token.oftBridgeAddress) {\n return token.oftBridgeAddress;\n } else {\n throw new OFTDoesNotSupportedError(\"Such route does not support OFT protocol\");\n }\n case Messenger.X_RESERVE:\n if (token.xReserve?.bridgeAddress) {\n return token.xReserve.bridgeAddress;\n } else {\n throw new SdkError(\"Such route does not support xReserve protocol\");\n }\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n return token.bridgeAddress;\n }\n}\n"]}
@@ -2,7 +2,7 @@ import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
2
2
  import { AllbridgeCoreSdkOptions, ChainType } from "../../../index";
3
3
  import { NodeRpcUrlsConfig } from "../../index";
4
4
  import { RawTransaction, TransactionResponse } from "../../models";
5
- import { ChainBridgeService, SendParams, SwapParams, TxSendParamsSrb, TxSwapParamsSol } from "../models";
5
+ import { ChainBridgeService, SendParams, SwapParams, TxSendParamsSrb, TxSwapParamsSol, TxTransferParams } from "../models";
6
6
  export declare class SrbBridgeService extends ChainBridgeService {
7
7
  readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig;
8
8
  readonly params: AllbridgeCoreSdkOptions;
@@ -11,6 +11,14 @@ export declare class SrbBridgeService extends ChainBridgeService {
11
11
  constructor(nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, api: AllbridgeCoreClient);
12
12
  buildRawTransactionSend(params: SendParams): Promise<RawTransaction>;
13
13
  buildRawTransactionSendFromParams(params: TxSendParamsSrb, sendParams?: SendParams): Promise<RawTransaction>;
14
+ /**
15
+ * Builds a classic Stellar `payment` of `amount` to `params.toAddress` with `params.memo` as the text memo:
16
+ * XLM when `token.isNative`, otherwise the classic asset behind the Soroban token
17
+ * (`token.originTokenAddress` = `CODE:ISSUER`). Used for `Messenger.NEAR_INTENTS` deposits.
18
+ * @returns the transaction XDR
19
+ * @throws SdkError if `params.memo` is missing: NEAR Intents cannot attribute a Stellar deposit without it
20
+ */
21
+ buildRawTransactionTransfer(params: TxTransferParams): Promise<RawTransaction>;
14
22
  /** @deprecated Do not use. */
15
23
  buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction>;
16
24
  /** @deprecated Do not use. */
@@ -1,17 +1,22 @@
1
- import { Address } from "@stellar/stellar-sdk";
1
+ import { Address, Asset, Horizon, Memo, Operation, TransactionBuilder } from "@stellar/stellar-sdk";
2
2
  import { Big } from "big.js";
3
3
  import { ChainSymbol } from "../../../chains/chain.enums";
4
4
  import { Messenger } from "../../../client/core-api/core-api.model";
5
5
  import { MethodNotSupportedError, SdkError } from "../../../exceptions";
6
6
  import { ChainType } from "../../../index";
7
7
  import { FeePaymentMethod } from "../../../models";
8
+ import { convertIntAmountToFloat } from "../../../utils/calculation";
8
9
  import { assertNever } from "../../../utils/utils";
9
10
  import { BridgeContract } from "../../models/srb/bridge-contract";
10
11
  import { Client as CctpBridgeContract } from "../../models/srb/cctp-bridge-contract";
11
- import { getSorobanInclusionFee } from "../../models/srb/utils";
12
+ import { getSorobanInclusionFee, getStellarInclusionFee } from "../../models/srb/utils";
12
13
  import { getCctpSolTokenRecipientAddress } from "../get-cctp-sol-token-recipient-address";
13
- import { ChainBridgeService } from "../models";
14
+ import { ChainBridgeService, } from "../models";
14
15
  import { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from "../utils";
16
+ /**
17
+ * Validity window (seconds) of a classic Stellar transaction built by the SDK.
18
+ */
19
+ const STELLAR_TRANSACTION_TIMEOUT = 180;
15
20
  export class SrbBridgeService extends ChainBridgeService {
16
21
  nodeRpcUrlsConfig;
17
22
  params;
@@ -98,6 +103,36 @@ export class SrbBridgeService extends ChainBridgeService {
98
103
  }
99
104
  return tx.toXDR();
100
105
  }
106
+ /**
107
+ * Builds a classic Stellar `payment` of `amount` to `params.toAddress` with `params.memo` as the text memo:
108
+ * XLM when `token.isNative`, otherwise the classic asset behind the Soroban token
109
+ * (`token.originTokenAddress` = `CODE:ISSUER`). Used for `Messenger.NEAR_INTENTS` deposits.
110
+ * @returns the transaction XDR
111
+ * @throws SdkError if `params.memo` is missing: NEAR Intents cannot attribute a Stellar deposit without it
112
+ */
113
+ async buildRawTransactionTransfer(params) {
114
+ const { amount, token, fromAccountAddress, toAddress, memo } = params;
115
+ if (!memo) {
116
+ throw new SdkError("Stellar transfer requires a deposit memo");
117
+ }
118
+ const asset = token.isNative ? Asset.native() : getClassicAsset(token.originTokenAddress);
119
+ const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));
120
+ const sourceAccount = await stellar.loadAccount(fromAccountAddress);
121
+ const inclusionFee = await getStellarInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));
122
+ return new TransactionBuilder(sourceAccount, {
123
+ fee: inclusionFee.toString(10),
124
+ networkPassphrase: this.params.sorobanNetworkPassphrase,
125
+ })
126
+ .addOperation(Operation.payment({
127
+ destination: toAddress,
128
+ asset,
129
+ amount: convertIntAmountToFloat(amount, token.decimals).toFixed(),
130
+ }))
131
+ .addMemo(Memo.text(memo))
132
+ .setTimeout(STELLAR_TRANSACTION_TIMEOUT)
133
+ .build()
134
+ .toXDR();
135
+ }
101
136
  /** @deprecated Do not use. */
102
137
  async buildRawTransactionSwap(params) {
103
138
  const txSwapParams = prepareTxSwapParams(this.chainType, params);
@@ -131,4 +166,11 @@ export class SrbBridgeService extends ChainBridgeService {
131
166
  return new contract(config);
132
167
  }
133
168
  }
169
+ function getClassicAsset(originTokenAddress) {
170
+ const [code, issuer] = originTokenAddress?.split(":") ?? [];
171
+ if (!code || !issuer) {
172
+ throw new SdkError("SRB token must contain 'originTokenAddress' in the 'CODE:ISSUER' format");
173
+ }
174
+ return new Asset(code, issuer);
175
+ }
134
176
  //# sourceMappingURL=index.js.map
@@ -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,CAA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} 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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAY,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC9G,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,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,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,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EACL,kBAAkB,GAMnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGpF;;GAEG;AACH,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC,MAAM,OAAO,gBAAiB,SAAQ,kBAAkB;IAI3C;IACA;IACA;IALX,SAAS,GAAkB,SAAS,CAAC,GAAG,CAAC;IAE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7D,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;AAED,SAAS,eAAe,CAAC,kBAAsC;IAC7D,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,kBAAkB,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC5D,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,IAAI,QAAQ,CAAC,yEAAyE,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import { Address, Asset, contract, Horizon, Memo, Operation, TransactionBuilder } 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 { convertIntAmountToFloat } from \"../../../utils/calculation\";\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, getStellarInclusionFee } from \"../../models/srb/utils\";\nimport { getCctpSolTokenRecipientAddress } from \"../get-cctp-sol-token-recipient-address\";\nimport {\n ChainBridgeService,\n SendParams,\n SwapParams,\n TxSendParamsSrb,\n TxSwapParamsSol,\n TxTransferParams,\n} from \"../models\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\n\n/**\n * Validity window (seconds) of a classic Stellar transaction built by the SDK.\n */\nconst STELLAR_TRANSACTION_TIMEOUT = 180;\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 /**\n * Builds a classic Stellar `payment` of `amount` to `params.toAddress` with `params.memo` as the text memo:\n * XLM when `token.isNative`, otherwise the classic asset behind the Soroban token\n * (`token.originTokenAddress` = `CODE:ISSUER`). Used for `Messenger.NEAR_INTENTS` deposits.\n * @returns the transaction XDR\n * @throws SdkError if `params.memo` is missing: NEAR Intents cannot attribute a Stellar deposit without it\n */\n async buildRawTransactionTransfer(params: TxTransferParams): Promise<RawTransaction> {\n const { amount, token, fromAccountAddress, toAddress, memo } = params;\n if (!memo) {\n throw new SdkError(\"Stellar transfer requires a deposit memo\");\n }\n const asset = token.isNative ? Asset.native() : getClassicAsset(token.originTokenAddress);\n\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n const sourceAccount = await stellar.loadAccount(fromAccountAddress);\n const inclusionFee = await getStellarInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return new TransactionBuilder(sourceAccount, {\n fee: inclusionFee.toString(10),\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n })\n .addOperation(\n Operation.payment({\n destination: toAddress,\n asset,\n amount: convertIntAmountToFloat(amount, token.decimals).toFixed(),\n })\n )\n .addMemo(Memo.text(memo))\n .setTimeout(STELLAR_TRANSACTION_TIMEOUT)\n .build()\n .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\nfunction getClassicAsset(originTokenAddress: string | undefined): Asset {\n const [code, issuer] = originTokenAddress?.split(\":\") ?? [];\n if (!code || !issuer) {\n throw new SdkError(\"SRB token must contain 'originTokenAddress' in the 'CODE:ISSUER' format\");\n }\n return new Asset(code, issuer);\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { ChainType } from "../../../chains/chain.enums";
2
2
  import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
3
3
  import { AllbridgeCoreSdkOptions } from "../../../index";
4
- import { RawStxTransaction, TransactionResponse } from "../../models";
5
- import { ChainBridgeService, SendParams, SwapParams } from "../models";
4
+ import { RawStxTransaction, RawTransaction, TransactionResponse } from "../../models";
5
+ import { ChainBridgeService, SendParams, SwapParams, TxTransferParams } from "../models";
6
6
  export declare class StxBridgeService extends ChainBridgeService {
7
7
  nodeRpcUrl: string;
8
8
  params: AllbridgeCoreSdkOptions;
@@ -12,6 +12,10 @@ export declare class StxBridgeService extends ChainBridgeService {
12
12
  constructor(nodeRpcUrl: string, params: AllbridgeCoreSdkOptions, api: AllbridgeCoreClient);
13
13
  send(_params: SendParams): Promise<TransactionResponse>;
14
14
  buildRawTransactionSend(params: SendParams): Promise<RawStxTransaction>;
15
+ /**
16
+ * NEAR Intents deposit transfers are not supported from this chain yet.
17
+ */
18
+ buildRawTransactionTransfer(params: TxTransferParams): Promise<RawTransaction>;
15
19
  /** @deprecated Do not use. */
16
20
  buildRawTransactionSwap(params: SwapParams): Promise<RawStxTransaction>;
17
21
  }
@@ -6,6 +6,7 @@ import { MethodNotSupportedError, SdkError } from "../../../exceptions";
6
6
  import { FeePaymentMethod, Messenger } from "../../../models";
7
7
  import { assertNever } from "../../../utils/utils";
8
8
  import { stacksContracts as contracts } from "../../models/stx/clarigen-types";
9
+ import { nearIntentsChainNotSupportedError } from "../../near-intents/utils";
9
10
  import { getTokenName } from "../../utils/stx/get-token-name";
10
11
  import { getFungiblePostCondition, getStxPostCondition } from "../../utils/stx/post-conditions";
11
12
  import { ChainBridgeService } from "../models";
@@ -108,6 +109,12 @@ export class StxBridgeService extends ChainBridgeService {
108
109
  const transaction = await makeUnsignedContractCall(txOptions);
109
110
  return transaction.serialize();
110
111
  }
112
+ /**
113
+ * NEAR Intents deposit transfers are not supported from this chain yet.
114
+ */
115
+ buildRawTransactionTransfer(params) {
116
+ return Promise.reject(nearIntentsChainNotSupportedError(params.token.chainSymbol));
117
+ }
111
118
  /** @deprecated Do not use. */
112
119
  async buildRawTransactionSwap(params) {
113
120
  const txSwapParams = prepareTxSwapParams(this.chainType, params);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/stx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAEL,iBAAiB,EACjB,wBAAwB,EACxB,eAAe,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eAAe,EAAE,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,cAAc,EAAE,CAAC,qBAAqB,EAAE,+BAA+B,CAAC;YACxE,iBAAiB,EAAE,iBAAiB,CAAC,IAAI;SAC1C,CAAC;QACF,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAC9D,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["import { ClarigenClient, contractFactory } from \"@clarigen/core\";\nimport { createNetwork } from \"@stacks/network\";\nimport {\n ContractIdString,\n makeRandomPrivKey,\n makeUnsignedContractCall,\n parseContractId,\n PostCondition,\n PostConditionMode,\n privateKeyToPublic,\n} from \"@stacks/transactions\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { FeePaymentMethod, Messenger } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { RawStxTransaction, TransactionResponse } from \"../../models\";\nimport { stacksContracts as contracts } from \"../../models/stx/clarigen-types\";\nimport { getTokenName } from \"../../utils/stx/get-token-name\";\nimport { getFungiblePostCondition, getStxPostCondition } from \"../../utils/stx/post-conditions\";\nimport { ChainBridgeService, SendParams, SwapParams } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class StxBridgeService extends ChainBridgeService {\n chainType: ChainType.STX = ChainType.STX;\n\n private client: ClarigenClient;\n\n constructor(\n public nodeRpcUrl: string,\n public params: AllbridgeCoreSdkOptions,\n public api: AllbridgeCoreClient\n ) {\n super();\n const network = createNetwork({\n network: this.params.stxIsTestnet ? \"testnet\" : \"mainnet\",\n client: { baseUrl: this.nodeRpcUrl },\n apiKey: this.params.stxHeroApiKey,\n });\n this.client = new ClarigenClient(network, this.params.stxHeroApiKey);\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawStxTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;\n const amount = BigInt(txSendParams.amount);\n const sourceTokenName = getTokenName(params.sourceToken);\n\n const postFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n sourceTokenName\n );\n const postStxPostCondition = getStxPostCondition(0, \"gte\", bridgeAddress);\n const postConditions: PostCondition[] = [postFungiblePostCondition, postStxPostCondition];\n if (messenger === Messenger.X_RESERVE) {\n const postBridgeFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n bridgeAddress,\n params.sourceToken.tokenAddress,\n sourceTokenName\n );\n postConditions.push(postBridgeFungiblePostCondition);\n }\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n\n let feeTokenAmount: bigint;\n let feeNativeAmount: bigint;\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n feeTokenAmount = 0n;\n feeNativeAmount = totalFee;\n const postUserStxPostCondition = getStxPostCondition(totalFee, \"lte\", params.fromAccountAddress);\n postConditions.push(postUserStxPostCondition);\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n feeTokenAmount = totalFee;\n feeNativeAmount = 0n;\n break;\n }\n case FeePaymentMethod.WITH_ABR:\n throw new SdkError(\"STX bridge does not support ABR payment method\");\n default: {\n return assertNever(txSendParams.gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n const [contractPrincipal] = parseContractId(bridgeAddress as ContractIdString);\n\n const txCall =\n messenger === Messenger.X_RESERVE\n ? contractFactory(contracts.xReserveBridge, bridgeAddress).bridge({\n tokenRef: params.sourceToken.tokenAddress,\n burnRef: params.sourceToken.xReserve?.protocolAddress ?? params.sourceToken.tokenAddress,\n amount,\n recipient: Uint8Array.from(toAccountAddress),\n destinationChainId: toChainId,\n })\n : contractFactory(contracts.bridge, bridgeAddress).swapAndBridge({\n ftRef: params.sourceToken.tokenAddress,\n poolRef: params.sourceToken.poolAddress,\n messengerRef: `${contractPrincipal}.messenger`,\n gasOracleRef: `${contractPrincipal}.gas-oracle`,\n amount,\n recipient: Uint8Array.from(toAccountAddress),\n destinationChainId: toChainId,\n receiveToken: Uint8Array.from(toTokenAddress),\n nonce: Uint8Array.from(getNonce()),\n messengerId: messenger,\n feeNativeAmount: feeNativeAmount,\n feeTokenAmount: feeTokenAmount,\n });\n const { contractAddress, contractName, functionName, functionArgs } = txCall;\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions,\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n\n /** @deprecated Do not use. */\n async buildRawTransactionSwap(params: SwapParams): Promise<RawStxTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n const amount = BigInt(txSwapParams.amount);\n const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);\n\n const bridgeAddress = params.sourceToken.bridgeAddress;\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.swap({\n amount,\n sendPoolRef: params.sourceToken.poolAddress,\n sendFtRef: params.sourceToken.tokenAddress,\n receivePoolRef: params.destinationToken.poolAddress,\n receiveFtRef: params.destinationToken.tokenAddress,\n recipient: params.toAccountAddress,\n receiveAmountMin: minimumReceiveAmount,\n });\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const postFungibleCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n\n const postFungibleMinReceiveCondition = getFungiblePostCondition(\n minimumReceiveAmount,\n \"gte\",\n params.destinationToken.poolAddress,\n params.destinationToken.tokenAddress,\n getTokenName(params.destinationToken)\n );\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions: [postFungibleCondition, postFungibleMinReceiveCondition],\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/stx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAEL,iBAAiB,EACjB,wBAAwB,EACxB,eAAe,EAEf,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,eAAe,IAAI,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAChG,OAAO,EAAE,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port { createNetwork } from \"@stacks/network\";\nimport {\n ContractIdString,\n makeRandomPrivKey,\n makeUnsignedContractCall,\n parseContractId,\n PostCondition,\n PostConditionMode,\n privateKeyToPublic,\n} from \"@stacks/transactions\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { FeePaymentMethod, Messenger } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { RawStxTransaction, RawTransaction, TransactionResponse } from \"../../models\";\nimport { stacksContracts as contracts } from \"../../models/stx/clarigen-types\";\nimport { nearIntentsChainNotSupportedError } from \"../../near-intents/utils\";\nimport { getTokenName } from \"../../utils/stx/get-token-name\";\nimport { getFungiblePostCondition, getStxPostCondition } from \"../../utils/stx/post-conditions\";\nimport { ChainBridgeService, SendParams, SwapParams, TxTransferParams } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class StxBridgeService extends ChainBridgeService {\n chainType: ChainType.STX = ChainType.STX;\n\n private client: ClarigenClient;\n\n constructor(\n public nodeRpcUrl: string,\n public params: AllbridgeCoreSdkOptions,\n public api: AllbridgeCoreClient\n ) {\n super();\n const network = createNetwork({\n network: this.params.stxIsTestnet ? \"testnet\" : \"mainnet\",\n client: { baseUrl: this.nodeRpcUrl },\n apiKey: this.params.stxHeroApiKey,\n });\n this.client = new ClarigenClient(network, this.params.stxHeroApiKey);\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawStxTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;\n const amount = BigInt(txSendParams.amount);\n const sourceTokenName = getTokenName(params.sourceToken);\n\n const postFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n sourceTokenName\n );\n const postStxPostCondition = getStxPostCondition(0, \"gte\", bridgeAddress);\n const postConditions: PostCondition[] = [postFungiblePostCondition, postStxPostCondition];\n if (messenger === Messenger.X_RESERVE) {\n const postBridgeFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n bridgeAddress,\n params.sourceToken.tokenAddress,\n sourceTokenName\n );\n postConditions.push(postBridgeFungiblePostCondition);\n }\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n\n let feeTokenAmount: bigint;\n let feeNativeAmount: bigint;\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n feeTokenAmount = 0n;\n feeNativeAmount = totalFee;\n const postUserStxPostCondition = getStxPostCondition(totalFee, \"lte\", params.fromAccountAddress);\n postConditions.push(postUserStxPostCondition);\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n feeTokenAmount = totalFee;\n feeNativeAmount = 0n;\n break;\n }\n case FeePaymentMethod.WITH_ABR:\n throw new SdkError(\"STX bridge does not support ABR payment method\");\n default: {\n return assertNever(txSendParams.gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n const [contractPrincipal] = parseContractId(bridgeAddress as ContractIdString);\n\n const txCall =\n messenger === Messenger.X_RESERVE\n ? contractFactory(contracts.xReserveBridge, bridgeAddress).bridge({\n tokenRef: params.sourceToken.tokenAddress,\n burnRef: params.sourceToken.xReserve?.protocolAddress ?? params.sourceToken.tokenAddress,\n amount,\n recipient: Uint8Array.from(toAccountAddress),\n destinationChainId: toChainId,\n })\n : contractFactory(contracts.bridge, bridgeAddress).swapAndBridge({\n ftRef: params.sourceToken.tokenAddress,\n poolRef: params.sourceToken.poolAddress,\n messengerRef: `${contractPrincipal}.messenger`,\n gasOracleRef: `${contractPrincipal}.gas-oracle`,\n amount,\n recipient: Uint8Array.from(toAccountAddress),\n destinationChainId: toChainId,\n receiveToken: Uint8Array.from(toTokenAddress),\n nonce: Uint8Array.from(getNonce()),\n messengerId: messenger,\n feeNativeAmount: feeNativeAmount,\n feeTokenAmount: feeTokenAmount,\n });\n const { contractAddress, contractName, functionName, functionArgs } = txCall;\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions,\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n\n /**\n * NEAR Intents deposit transfers are not supported from this chain yet.\n */\n buildRawTransactionTransfer(params: TxTransferParams): Promise<RawTransaction> {\n return Promise.reject(nearIntentsChainNotSupportedError(params.token.chainSymbol));\n }\n\n /** @deprecated Do not use. */\n async buildRawTransactionSwap(params: SwapParams): Promise<RawStxTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n const amount = BigInt(txSwapParams.amount);\n const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);\n\n const bridgeAddress = params.sourceToken.bridgeAddress;\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.swap({\n amount,\n sendPoolRef: params.sourceToken.poolAddress,\n sendFtRef: params.sourceToken.tokenAddress,\n receivePoolRef: params.destinationToken.poolAddress,\n receiveFtRef: params.destinationToken.tokenAddress,\n recipient: params.toAccountAddress,\n receiveAmountMin: minimumReceiveAmount,\n });\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const postFungibleCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n\n const postFungibleMinReceiveCondition = getFungiblePostCondition(\n minimumReceiveAmount,\n \"gte\",\n params.destinationToken.poolAddress,\n params.destinationToken.tokenAddress,\n getTokenName(params.destinationToken)\n );\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions: [postFungibleCondition, postFungibleMinReceiveCondition],\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n}\n"]}
@@ -3,7 +3,7 @@ import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
3
3
  import { AllbridgeCoreSdkOptions } from "../../../index";
4
4
  import { ChainSymbol, ChainType, RawSuiTransaction, SwapParams, TransactionResponse } from "../../../models";
5
5
  import { NodeRpcUrlsConfig } from "../../index";
6
- import { ChainBridgeService, SendParams } from "../models";
6
+ import { ChainBridgeService, SendParams, TxTransferParams } from "../models";
7
7
  export declare class SuiBridgeService extends ChainBridgeService {
8
8
  private nodeRpcUrlsConfig;
9
9
  readonly params: AllbridgeCoreSdkOptions;
@@ -13,6 +13,13 @@ export declare class SuiBridgeService extends ChainBridgeService {
13
13
  private readonly client;
14
14
  constructor(nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, api: AllbridgeCoreClient);
15
15
  send(): Promise<TransactionResponse>;
16
+ /**
17
+ * Builds a coin transfer of `amount` to `params.toAddress`: SUI split from the gas coin when `token.isNative`,
18
+ * otherwise a coin of the `token.originTokenAddress` type taken from the sender's coins.
19
+ * Used for `Messenger.NEAR_INTENTS` deposits.
20
+ * @returns the transaction JSON
21
+ */
22
+ buildRawTransactionTransfer(params: TxTransferParams): Promise<RawSuiTransaction>;
16
23
  /** @deprecated Do not use. */
17
24
  buildRawTransactionSwap(params: SwapParams): Promise<RawSuiTransaction>;
18
25
  private buildRawTransactionSwapFromParams;
@@ -10,6 +10,7 @@ import { setAddress as setCctpAddress } from "../../models/sui/cctp-bridge";
10
10
  import { bridge } from "../../models/sui/cctp-bridge/cctp-bridge-interface/functions";
11
11
  import { setAddress as setUtilsAddress } from "../../models/sui/utils";
12
12
  import { fromHex } from "../../models/sui/utils/bytes32/functions";
13
+ import { nearIntentsNotABridgeContractError } from "../../near-intents/utils";
13
14
  import { fetchAllPagesRecursive } from "../../utils/sui/paginated";
14
15
  import { getCctpSolTokenRecipientAddress } from "../get-cctp-sol-token-recipient-address";
15
16
  import { ChainBridgeService } from "../models";
@@ -34,6 +35,27 @@ export class SuiBridgeService extends ChainBridgeService {
34
35
  send() {
35
36
  throw new SdkError("Method send not implemented.");
36
37
  }
38
+ /**
39
+ * Builds a coin transfer of `amount` to `params.toAddress`: SUI split from the gas coin when `token.isNative`,
40
+ * otherwise a coin of the `token.originTokenAddress` type taken from the sender's coins.
41
+ * Used for `Messenger.NEAR_INTENTS` deposits.
42
+ * @returns the transaction JSON
43
+ */
44
+ async buildRawTransactionTransfer(params) {
45
+ const { amount, token, fromAccountAddress, toAddress } = params;
46
+ let coinType;
47
+ if (!token.isNative) {
48
+ coinType = token.originTokenAddress;
49
+ if (!coinType) {
50
+ throw new SdkError("SUI token must contain 'originTokenAddress'");
51
+ }
52
+ }
53
+ const tx = new Transaction();
54
+ tx.setSender(fromAccountAddress);
55
+ const coin = coinWithBalance(coinType ? { balance: BigInt(amount), type: coinType } : { balance: BigInt(amount) });
56
+ tx.transferObjects([coin], toAddress);
57
+ return await tx.toJSON({ client: this.client });
58
+ }
37
59
  /** @deprecated Do not use. */
38
60
  async buildRawTransactionSwap(params) {
39
61
  const suiAddresses = params.sourceToken.suiAddresses;
@@ -95,6 +117,8 @@ export class SuiBridgeService extends ChainBridgeService {
95
117
  throw new SdkError("Messenger xReserve is not supported for SUI bridge");
96
118
  case Messenger.OFT:
97
119
  throw new OFTDoesNotSupportedError("Messenger OFT is not supported yet.");
120
+ case Messenger.NEAR_INTENTS:
121
+ throw nearIntentsNotABridgeContractError();
98
122
  }
99
123
  }
100
124
  async buildRawTransactionAllbridgeSend(txSendParams, suiAddresses, tx, inputCoin) {