@allbridge/bridge-core-sdk 3.27.0-alpha.2 → 3.27.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/browser/index.js +3 -3
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/cjs/index.js +3 -3
  4. package/dist/cjs/index.js.map +4 -4
  5. package/dist/esm/index.js +3 -3
  6. package/dist/esm/index.js.map +4 -4
  7. package/dist/src/chains/chain.enums.d.ts +7 -2
  8. package/dist/src/chains/chain.enums.js +5 -0
  9. package/dist/src/chains/chain.enums.js.map +1 -1
  10. package/dist/src/chains/index.js +6 -0
  11. package/dist/src/chains/index.js.map +1 -1
  12. package/dist/src/client/core-api/api-client.js +1 -0
  13. package/dist/src/client/core-api/api-client.js.map +1 -1
  14. package/dist/src/client/core-api/core-api-mapper.js +32 -0
  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 +13 -2
  17. package/dist/src/client/core-api/core-api.model.js.map +1 -1
  18. package/dist/src/configs/mainnet.js +1 -0
  19. package/dist/src/configs/mainnet.js.map +1 -1
  20. package/dist/src/index.d.ts +12 -4
  21. package/dist/src/index.js +11 -11
  22. package/dist/src/index.js.map +1 -1
  23. package/dist/src/models/index.d.ts +12 -4
  24. package/dist/src/models/index.js +4 -0
  25. package/dist/src/models/index.js.map +1 -1
  26. package/dist/src/services/bridge/alg/index.d.ts +1 -0
  27. package/dist/src/services/bridge/alg/index.js +79 -43
  28. package/dist/src/services/bridge/alg/index.js.map +1 -1
  29. package/dist/src/services/bridge/evm/index.d.ts +1 -0
  30. package/dist/src/services/bridge/evm/index.js +103 -33
  31. package/dist/src/services/bridge/evm/index.js.map +1 -1
  32. package/dist/src/services/bridge/index.d.ts +2 -2
  33. package/dist/src/services/bridge/index.js +15 -4
  34. package/dist/src/services/bridge/index.js.map +1 -1
  35. package/dist/src/services/bridge/models/bridge.model.d.ts +12 -4
  36. package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
  37. package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
  38. package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
  39. package/dist/src/services/bridge/sol/index.d.ts +2 -2
  40. package/dist/src/services/bridge/sol/index.js +19 -11
  41. package/dist/src/services/bridge/sol/index.js.map +1 -1
  42. package/dist/src/services/bridge/sol/jupiter.d.ts +1 -1
  43. package/dist/src/services/bridge/sol/jupiter.js +2 -1
  44. package/dist/src/services/bridge/sol/jupiter.js.map +1 -1
  45. package/dist/src/services/bridge/srb/index.js +36 -28
  46. package/dist/src/services/bridge/srb/index.js.map +1 -1
  47. package/dist/src/services/bridge/stx/index.d.ts +16 -0
  48. package/dist/src/services/bridge/stx/index.js +136 -0
  49. package/dist/src/services/bridge/stx/index.js.map +1 -0
  50. package/dist/src/services/bridge/sui/index.js +166 -138
  51. package/dist/src/services/bridge/sui/index.js.map +1 -1
  52. package/dist/src/services/bridge/trx/index.js +98 -70
  53. package/dist/src/services/bridge/trx/index.js.map +1 -1
  54. package/dist/src/services/bridge/utils.d.ts +3 -1
  55. package/dist/src/services/bridge/utils.js +92 -8
  56. package/dist/src/services/bridge/utils.js.map +1 -1
  57. package/dist/src/services/liquidity-pool/alg/index.js +10 -17
  58. package/dist/src/services/liquidity-pool/alg/index.js.map +1 -1
  59. package/dist/src/services/liquidity-pool/index.js +5 -0
  60. package/dist/src/services/liquidity-pool/index.js.map +1 -1
  61. package/dist/src/services/liquidity-pool/sol/index.js +6 -3
  62. package/dist/src/services/liquidity-pool/sol/index.js.map +1 -1
  63. package/dist/src/services/liquidity-pool/stx/index.d.ts +21 -0
  64. package/dist/src/services/liquidity-pool/stx/index.js +141 -0
  65. package/dist/src/services/liquidity-pool/stx/index.js.map +1 -0
  66. package/dist/src/services/models/abi/PayerWithAbr.d.ts +203 -0
  67. package/dist/src/services/models/abi/PayerWithAbr.js +266 -0
  68. package/dist/src/services/models/abi/PayerWithAbr.js.map +1 -0
  69. package/dist/src/services/models/alg/BridgeClient.d.ts +158 -133
  70. package/dist/src/services/models/alg/BridgeClient.js +182 -130
  71. package/dist/src/services/models/alg/BridgeClient.js.map +1 -1
  72. package/dist/src/services/models/alg/PaddingUtilClient.d.ts +639 -0
  73. package/dist/src/services/models/alg/PaddingUtilClient.js +425 -0
  74. package/dist/src/services/models/alg/PaddingUtilClient.js.map +1 -0
  75. package/dist/src/services/models/alg/PoolClient.d.ts +204 -201
  76. package/dist/src/services/models/alg/PoolClient.js +234 -215
  77. package/dist/src/services/models/alg/PoolClient.js.map +1 -1
  78. package/dist/src/services/models/index.d.ts +16 -3
  79. package/dist/src/services/models/index.js.map +1 -1
  80. package/dist/src/services/models/stx/clarigen-types.d.ts +657 -0
  81. package/dist/src/services/models/stx/clarigen-types.js +2296 -0
  82. package/dist/src/services/models/stx/clarigen-types.js.map +1 -0
  83. package/dist/src/services/token/index.js +7 -2
  84. package/dist/src/services/token/index.js.map +1 -1
  85. package/dist/src/services/token/models/token.model.d.ts +4 -4
  86. package/dist/src/services/token/models/token.model.js.map +1 -1
  87. package/dist/src/services/token/stx/index.d.ts +20 -0
  88. package/dist/src/services/token/stx/index.js +59 -0
  89. package/dist/src/services/token/stx/index.js.map +1 -0
  90. package/dist/src/services/utils/alg/index.d.ts +1 -10
  91. package/dist/src/services/utils/alg/index.js +0 -20
  92. package/dist/src/services/utils/alg/index.js.map +1 -1
  93. package/dist/src/services/utils/sol/compute-budget.d.ts +2 -1
  94. package/dist/src/services/utils/sol/compute-budget.js +36 -18
  95. package/dist/src/services/utils/sol/compute-budget.js.map +1 -1
  96. package/dist/src/services/utils/sol/index.d.ts +2 -0
  97. package/dist/src/services/utils/sol/index.js +12 -0
  98. package/dist/src/services/utils/sol/index.js.map +1 -1
  99. package/dist/src/services/utils/stx/get-token-name.d.ts +2 -0
  100. package/dist/src/services/utils/stx/get-token-name.js +15 -0
  101. package/dist/src/services/utils/stx/get-token-name.js.map +1 -0
  102. package/dist/src/services/utils/stx/post-conditions.d.ts +3 -0
  103. package/dist/src/services/utils/stx/post-conditions.js +27 -0
  104. package/dist/src/services/utils/stx/post-conditions.js.map +1 -0
  105. package/dist/src/services/yield/index.js +4 -0
  106. package/dist/src/services/yield/index.js.map +1 -1
  107. package/dist/src/tokens-info/tokens-info.model.d.ts +21 -0
  108. package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
  109. package/dist/src/utils/utils.d.ts +2 -0
  110. package/dist/src/utils/utils.js +11 -0
  111. package/dist/src/utils/utils.js.map +1 -1
  112. package/dist/src/version.d.ts +1 -1
  113. package/dist/src/version.js +1 -1
  114. package/dist/src/version.js.map +1 -1
  115. package/package.json +6 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/evm/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA6B;AAK7B,4CAQyB;AAGzB,qEAA6C;AAC7C,6EAAqD;AACrD,2EAAmD;AACnD,kGAA0F;AAC1F,sCAA6F;AAC7F,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAI7C;IACA;IACC;IALV,SAAS,GAAkB,kBAAS,CAAC,GAAG,CAAC;IAEzC,YACS,IAAmB,EACnB,GAAwB,EACvB,iBAAoC;QAE5C,KAAK,EAAE,CAAC;QAJD,SAAI,GAAJ,IAAI,CAAe;QACnB,QAAG,GAAH,GAAG,CAAqB;QACvB,sBAAiB,GAAjB,iBAAiB,CAAmB;IAG9C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAkB;QAC3B,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,IAAA,2BAAmB,EAAC,IAAI,CAAC,SA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ayableMethodObject } from \"web3-eth-contract\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n ChainSymbol,\n ChainType,\n EssentialWeb3,\n FeePaymentMethod,\n Messenger,\n SwapParams,\n TransactionResponse,\n} from \"../../../models\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction } from \"../../models\";\nimport Bridge from \"../../models/abi/Bridge\";\nimport CctpBridge from \"../../models/abi/CctpBridge\";\nimport OftBridge from \"../../models/abi/OftBridge\";\nimport { getCctpSolTokenRecipientAddress } from \"../get-cctp-sol-token-recipient-address\";\nimport { ChainBridgeService, SendParams, TxSendParamsEvm, TxSwapParamsEvm } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class EvmBridgeService extends ChainBridgeService {\n chainType: ChainType.EVM = ChainType.EVM;\n\n constructor(\n public web3: EssentialWeb3,\n public api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig\n ) {\n super();\n }\n\n async send(params: SendParams): Promise<TransactionResponse> {\n const rawTransaction = await this.buildRawTransactionSend(params);\n return this.sendRawTransaction(rawTransaction);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsEvm): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n\n const bridgeContract = this.getBridgeContract(contractAddress);\n\n const swapMethod = bridgeContract.methods.swap(\n amount,\n fromTokenAddress,\n toTokenAddress,\n toAccountAddress,\n minimumReceiveAmount\n );\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: contractAddress,\n data: swapMethod.encodeABI(),\n });\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n messenger,\n fee,\n gasFeePaymentMethod,\n extraGas,\n extraGasDest,\n } = txSendParams;\n\n const nonce = \"0x\" + getNonce().toString(\"hex\");\n let sendMethod: PayableMethodObject;\n let value: string;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n switch (messenger) {\n case Messenger.CCTP:\n case Messenger.CCTP_V2: {\n const cctp = await this.buildRawTransactionCctpSend(params, txSendParams, totalFee);\n sendMethod = cctp.sendMethod;\n value = cctp.value;\n break;\n }\n case Messenger.OFT: {\n const oft = this.buildRawTransactionOftSend(params, txSendParams, totalFee, extraGasDest);\n sendMethod = oft.sendMethod;\n value = oft.value;\n break;\n }\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n {\n const bridgeContract = this.getBridgeContract(contractAddress);\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n sendMethod = bridgeContract.methods.swapAndBridge(\n fromTokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n toTokenAddress,\n nonce,\n messenger,\n totalFee\n );\n value = \"0\";\n } else {\n sendMethod = bridgeContract.methods.swapAndBridge(\n fromTokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n toTokenAddress,\n nonce,\n messenger,\n 0\n );\n value = totalFee;\n }\n }\n break;\n }\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: contractAddress,\n value: value,\n data: sendMethod.encodeABI(),\n });\n }\n\n private async buildRawTransactionCctpSend(\n params: SendParams,\n txSendParams: TxSendParamsEvm,\n totalFee: string\n ): Promise<{\n sendMethod: PayableMethodObject;\n value: string;\n }> {\n const { amount, contractAddress, toChainId, toAccountAddress, gasFeePaymentMethod } = txSendParams;\n\n const cctpBridgeContract = this.getCctpBridgeContract(contractAddress);\n let sendMethod: PayableMethodObject;\n let value: string;\n\n if (params.destinationToken.chainType === ChainType.SOLANA) {\n const recipient = await getCctpSolTokenRecipientAddress(\n this.chainType,\n params.toAccountAddress,\n params.destinationToken.tokenAddress,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL)\n );\n\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(\n amount,\n recipient,\n toAccountAddress,\n toChainId,\n totalFee\n );\n value = \"0\";\n } else {\n sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(\n amount,\n recipient,\n toAccountAddress,\n toChainId,\n 0\n );\n value = totalFee;\n }\n } else {\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, totalFee);\n value = \"0\";\n } else {\n sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, 0);\n value = totalFee;\n }\n }\n return { sendMethod, value };\n }\n\n private buildRawTransactionOftSend(\n params: SendParams,\n txSendParams: TxSendParamsEvm,\n totalFee: string,\n extraGasDest?: string\n ): {\n sendMethod: PayableMethodObject;\n value: string;\n } {\n const { amount, contractAddress, toChainId, toAccountAddress, gasFeePaymentMethod } = txSendParams;\n\n const oftBridgeContract = this.getOftBridgeContract(contractAddress);\n let sendMethod: PayableMethodObject;\n let value: string;\n\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n sendMethod = oftBridgeContract.methods.bridge(\n params.sourceToken.tokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n totalFee,\n extraGasDest ?? \"0\",\n \"10\"\n );\n value = \"0\";\n } else {\n sendMethod = oftBridgeContract.methods.bridge(\n params.sourceToken.tokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n 0,\n extraGasDest ?? \"0\",\n \"10\"\n );\n value = totalFee;\n }\n\n return { sendMethod, value };\n }\n\n private async sendRawTransaction(rawTransaction: RawTransaction) {\n const estimateGas = await this.web3.eth.estimateGas(rawTransaction as Web3Transaction);\n\n // @ts-expect-error DISABLE SITE SUGGESTED GAS FEE IN METAMASK\n // prettier-ignore\n const feeOptions: { maxPriorityFeePerGas?: number | string | BN; maxFeePerGas?: number | string | BN } = { maxPriorityFeePerGas: null, maxFeePerGas: null };\n const { transactionHash } = await this.web3.eth.sendTransaction({\n ...(rawTransaction as object),\n gas: estimateGas,\n ...feeOptions,\n } as Web3Transaction);\n return { txId: transactionHash.toString() };\n }\n\n private getBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(Bridge.abi, contractAddress) as Contract<typeof Bridge.abi>;\n }\n\n private getCctpBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(CctpBridge.abi, contractAddress) as Contract<typeof CctpBridge.abi>;\n }\n\n private getOftBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(OftBridge.abi, contractAddress) as Contract<typeof OftBridge.abi>;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/evm/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA6B;AAI7B,4CAAyC;AAEzC,4CASyB;AACzB,4DAAoE;AACpE,gDAAmD;AAGnD,qEAA6C;AAC7C,6EAAqD;AACrD,2EAAmD;AACnD,iFAAyD;AACzD,kGAA0F;AAC1F,sCAA6F;AAC7F,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAI7C;IACA;IACC;IALV,SAAS,GAAkB,kBAAS,CAAC,GAAG,CAAC;IAEzC,YACS,IAAmB,EACnB,GAAwB,EACvB,iBAAoC;QAE5C,KAAK,EAAE,CAAC;QAJD,SAAI,GAAJ,IAAI,CAAe;QACnB,QAAG,GAAH,GAAG,CAAqB;QACvB,sBAAiB,GAAjB,iBAAiB,CAAmB;IAG9C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAkB;QAC3B,MAAM,cAAc,GAAG,MAAM,IAAI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C,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,oBAAU,CAAC,GAAG,EAAE,eAAe,CAAoC,CAAC;IACxG,CAAC;IAEO,oBAAoB,CAAC,eAAuB;QAClD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,mBAAS,CAAC,GAAG,EAAE,eAAe,CAAmC,CAAC;IACtG,CAAC;IAEO,mBAAmB,CAAC,eAAuB;QACjD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,sBAAY,CAAC,GAAG,EAAE,eAAe,CAAsC,CAAC;IAC5G,CAAC;CACF;AAlVD,4CAkVC","sourcesContent":["import { Big } from \"big.js\";\nimport BN from \"bn.js\";\nimport { Contract, Transaction as Web3Transaction } from \"web3\";\nimport { PayableMethodObject } from \"web3-eth-contract\";\nimport { Chains } from \"../../../chains\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n ChainSymbol,\n ChainType,\n EssentialWeb3,\n FeePaymentMethod,\n Messenger,\n SdkError,\n SwapParams,\n TransactionResponse,\n} from \"../../../models\";\nimport { convertAmountPrecision } from \"../../../utils/calculation\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction } from \"../../models\";\nimport Bridge from \"../../models/abi/Bridge\";\nimport CctpBridge from \"../../models/abi/CctpBridge\";\nimport OftBridge from \"../../models/abi/OftBridge\";\nimport PayerWithAbr from \"../../models/abi/PayerWithAbr\";\nimport { getCctpSolTokenRecipientAddress } from \"../get-cctp-sol-token-recipient-address\";\nimport { ChainBridgeService, SendParams, TxSendParamsEvm, TxSwapParamsEvm } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class EvmBridgeService extends ChainBridgeService {\n chainType: ChainType.EVM = ChainType.EVM;\n\n constructor(\n public web3: EssentialWeb3,\n public api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig\n ) {\n super();\n }\n\n async send(params: SendParams): Promise<TransactionResponse> {\n const rawTransaction = await this.buildRawTransactionSend(params);\n return this.sendRawTransaction(rawTransaction);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsEvm): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n\n const bridgeContract = this.getBridgeContract(contractAddress);\n\n const swapMethod = bridgeContract.methods.swap(\n amount,\n fromTokenAddress,\n toTokenAddress,\n toAccountAddress,\n minimumReceiveAmount\n );\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: contractAddress,\n data: swapMethod.encodeABI(),\n });\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n messenger,\n fee,\n gasFeePaymentMethod,\n extraGas,\n extraGasDest,\n abrExchangeRate,\n } = txSendParams;\n\n const nonce = \"0x\" + getNonce().toString(\"hex\");\n let sendMethod: PayableMethodObject;\n let value: string;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n let totalFeeInAbr: string | undefined;\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ARB) {\n if (!abrExchangeRate) {\n throw new SdkError(\"Cannot find 'abrExchangeRate' for ARB0 payment method\");\n }\n if (!params.sourceToken.abrPayer) {\n throw new SdkError(\"Source token must contain 'abrPayer' for ARB0 payment method\");\n }\n totalFeeInAbr = totalFee;\n const totalFeeInNativeRaw = Big(totalFee).div(abrExchangeRate);\n totalFee = convertAmountPrecision(\n totalFeeInNativeRaw,\n params.sourceToken.abrPayer.abrToken.decimals,\n Chains.getChainDecimalsByType(params.sourceToken.chainType)\n ).toFixed();\n }\n\n switch (messenger) {\n case Messenger.CCTP:\n case Messenger.CCTP_V2: {\n const cctp = await this.buildRawTransactionCctpSend(params, txSendParams, totalFee);\n sendMethod = cctp.sendMethod;\n value = cctp.value;\n break;\n }\n case Messenger.OFT: {\n const oft = this.buildRawTransactionOftSend(params, txSendParams, totalFee, extraGasDest);\n sendMethod = oft.sendMethod;\n value = oft.value;\n break;\n }\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n {\n const bridgeContract = this.getBridgeContract(contractAddress);\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_ARB:\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n sendMethod = bridgeContract.methods.swapAndBridge(\n fromTokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n toTokenAddress,\n nonce,\n messenger,\n 0\n );\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n sendMethod = bridgeContract.methods.swapAndBridge(\n fromTokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n toTokenAddress,\n nonce,\n messenger,\n totalFee\n );\n value = \"0\";\n break;\n }\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n }\n break;\n }\n\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ARB) {\n if (!params.sourceToken.abrPayer) {\n throw new SdkError(\"Source token must contain 'abrPayer' for ARB0 payment method\");\n }\n\n const abrPayerAddress = params.sourceToken.abrPayer.payerAddress;\n\n if (!totalFeeInAbr) {\n throw new SdkError(\"Failed to calculate totalFeeInAbr\");\n }\n const abrPayerContract = this.getAbrPayerContract(abrPayerAddress);\n\n const abi = sendMethod.encodeABI();\n const withoutSelector = \"0x\" + abi.slice(10);\n sendMethod = abrPayerContract.methods.transferTokensAndCallTarget(\n params.sourceToken.tokenAddress,\n amount,\n totalFeeInAbr,\n messenger,\n withoutSelector\n );\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: abrPayerAddress,\n value: \"0\",\n data: sendMethod.encodeABI(),\n });\n }\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: contractAddress,\n value: value,\n data: sendMethod.encodeABI(),\n });\n }\n\n private async buildRawTransactionCctpSend(\n params: SendParams,\n txSendParams: TxSendParamsEvm,\n totalFee: string\n ): Promise<{\n sendMethod: PayableMethodObject;\n value: string;\n }> {\n const { amount, contractAddress, toChainId, toAccountAddress, gasFeePaymentMethod } = txSendParams;\n\n const cctpBridgeContract = this.getCctpBridgeContract(contractAddress);\n let sendMethod: PayableMethodObject;\n let value: string;\n\n if (params.destinationToken.chainType === ChainType.SOLANA) {\n const recipient = await getCctpSolTokenRecipientAddress(\n this.chainType,\n params.toAccountAddress,\n params.destinationToken.tokenAddress,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL)\n );\n\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_ARB:\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(\n amount,\n recipient,\n toAccountAddress,\n toChainId,\n 0\n );\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(\n amount,\n recipient,\n toAccountAddress,\n toChainId,\n totalFee\n );\n value = \"0\";\n break;\n }\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n } else {\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_ARB:\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, 0);\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, totalFee);\n value = \"0\";\n break;\n }\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n }\n return { sendMethod, value };\n }\n\n private buildRawTransactionOftSend(\n params: SendParams,\n txSendParams: TxSendParamsEvm,\n totalFee: string,\n extraGasDest?: string\n ): {\n sendMethod: PayableMethodObject;\n value: string;\n } {\n const { amount, contractAddress, toChainId, toAccountAddress, gasFeePaymentMethod } = txSendParams;\n\n const oftBridgeContract = this.getOftBridgeContract(contractAddress);\n let sendMethod: PayableMethodObject;\n let value: string;\n\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_ARB:\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n sendMethod = oftBridgeContract.methods.bridge(\n params.sourceToken.tokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n 0,\n extraGasDest ?? \"0\",\n \"10\"\n );\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n sendMethod = oftBridgeContract.methods.bridge(\n params.sourceToken.tokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n totalFee,\n extraGasDest ?? \"0\",\n \"10\"\n );\n value = \"0\";\n break;\n }\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return { sendMethod, value };\n }\n\n private async sendRawTransaction(rawTransaction: RawTransaction) {\n const estimateGas = await this.web3.eth.estimateGas(rawTransaction as Web3Transaction);\n\n // @ts-expect-error DISABLE SITE SUGGESTED GAS FEE IN METAMASK\n // prettier-ignore\n const feeOptions: { maxPriorityFeePerGas?: number | string | BN; maxFeePerGas?: number | string | BN } = { maxPriorityFeePerGas: null, maxFeePerGas: null };\n const { transactionHash } = await this.web3.eth.sendTransaction({\n ...(rawTransaction as object),\n gas: estimateGas,\n ...feeOptions,\n } as Web3Transaction);\n return { txId: transactionHash.toString() };\n }\n\n private getBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(Bridge.abi, contractAddress) as Contract<typeof Bridge.abi>;\n }\n\n private getCctpBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(CctpBridge.abi, contractAddress) as Contract<typeof CctpBridge.abi>;\n }\n\n private getOftBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(OftBridge.abi, contractAddress) as Contract<typeof OftBridge.abi>;\n }\n\n private getAbrPayerContract(contractAddress: string) {\n return new this.web3.eth.Contract(PayerWithAbr.abi, contractAddress) as Contract<typeof PayerWithAbr.abi>;\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { NodeRpcUrlsConfig } from "..";
2
2
  import { Messenger } from "../../client/core-api/core-api.model";
3
3
  import { AllbridgeCoreClient } from "../../client/core-api/core-client-base";
4
- import { AllbridgeCoreSdkOptions } from "../../index";
4
+ import { AllbridgeCoreSdkOptions, FeePaymentMethod } from "../../index";
5
5
  import { TokenWithChainDetails } from "../../tokens-info";
6
6
  import { Provider, TransactionResponse } from "../models";
7
7
  import { TokenService } from "../token";
@@ -65,5 +65,5 @@ export declare class DefaultBridgeService implements BridgeService {
65
65
  approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;
66
66
  send(provider: Provider, params: SendParams): Promise<TransactionResponse>;
67
67
  }
68
- export declare function getSpender(token: TokenWithChainDetails, messenger?: Messenger): string;
68
+ export declare function getSpender(token: TokenWithChainDetails, messenger?: Messenger, gasFeePaymentMethod?: FeePaymentMethod): string;
69
69
  export declare function getChainBridgeService(chainSymbol: string, api: AllbridgeCoreClient, nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, provider?: Provider): ChainBridgeService;
@@ -16,6 +16,7 @@ const evm_1 = require("./evm");
16
16
  const raw_bridge_transaction_builder_1 = require("./raw-bridge-transaction-builder");
17
17
  const sol_1 = require("./sol");
18
18
  const srb_1 = require("./srb");
19
+ const stx_1 = require("./stx");
19
20
  const sui_1 = require("./sui");
20
21
  const trx_1 = require("./trx");
21
22
  class DefaultBridgeService {
@@ -41,7 +42,7 @@ class DefaultBridgeService {
41
42
  else {
42
43
  params = a;
43
44
  }
44
- const spender = getSpender(params.token, params.messenger);
45
+ const spender = getSpender(params.token, params.messenger, params.gasFeePaymentMethod);
45
46
  return await this.tokenService.getAllowance({ ...params, spender }, provider);
46
47
  }
47
48
  async checkAllowance(a, b) {
@@ -54,11 +55,11 @@ class DefaultBridgeService {
54
55
  else {
55
56
  params = a;
56
57
  }
57
- const spender = getSpender(params.token, params.messenger);
58
+ const spender = getSpender(params.token, params.messenger, params.gasFeePaymentMethod);
58
59
  return this.tokenService.checkAllowance({ ...params, spender }, provider);
59
60
  }
60
61
  async approve(provider, approveData) {
61
- const spender = getSpender(approveData.token, approveData.messenger);
62
+ const spender = getSpender(approveData.token, approveData.messenger, approveData.gasFeePaymentMethod);
62
63
  return this.tokenService.approve(provider, { ...approveData, spender });
63
64
  }
64
65
  async send(provider, params) {
@@ -68,7 +69,13 @@ class DefaultBridgeService {
68
69
  }
69
70
  }
70
71
  exports.DefaultBridgeService = DefaultBridgeService;
71
- function getSpender(token, messenger = core_api_model_1.Messenger.ALLBRIDGE) {
72
+ function getSpender(token, messenger = core_api_model_1.Messenger.ALLBRIDGE, gasFeePaymentMethod = index_1.FeePaymentMethod.WITH_NATIVE_CURRENCY) {
73
+ if (gasFeePaymentMethod === index_1.FeePaymentMethod.WITH_ARB) {
74
+ if (token.abrPayer) {
75
+ return token.abrPayer.payerAddress;
76
+ }
77
+ throw new exceptions_1.SdkError("Token must contain 'abrPayer' for ARB0 payment method");
78
+ }
72
79
  switch (messenger) {
73
80
  case core_api_model_1.Messenger.CCTP:
74
81
  if (token.cctpAddress) {
@@ -152,6 +159,10 @@ function getChainBridgeService(chainSymbol, api, nodeRpcUrlsConfig, params, prov
152
159
  return new alg_1.AlgBridgeService(algorand, api);
153
160
  }
154
161
  }
162
+ case index_1.ChainType.STX: {
163
+ const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);
164
+ return new stx_1.StxBridgeService(nodeRpcUrl, params, api);
165
+ }
155
166
  }
156
167
  }
157
168
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/bridge/index.ts"],"names":[],"mappings":";;;AAoIA,gCAwBC;AAED,sDAmEC;AAjOD,qEAAmE;AAEnE,qCAAkC;AAClC,+BAA4B;AAE5B,yCAAsC;AACtC,yEAAiE;AAEjE,iDAAuF;AACvF,uCAA6F;AAE7F,6CAAiF;AAGjF,+BAAyC;AACzC,+BAAyC;AAEzC,qFAAmH;AACnH,+BAA4C;AAC5C,+BAAyC;AACzC,+BAAyC;AACzC,+BAA0C;AAuD1C,MAAa,oBAAoB;IAIrB;IACA;IACA;IACA;IANH,YAAY,CAA8B;IAEjD,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAAqB;QACxB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,YAAY,GAAG,IAAI,mEAAkC,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAC3G,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,CAAgC,EAAE,CAAsB;QACzE,IAAI,QAA8B,CAAC;QACnC,IAAI,MAA0B,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC;YACN,QAAQ,GAAG,CAAa,CAAC;YACzB,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,CAAuB,CAAC;QACnC,CAAC;QACD,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3D,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,GAAG,MAAM,EAAE,OAA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EAAE,GAAG,CAAC,CAAC;QACtD,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,KAAK,GAAG,QAAmB,CAAC;gBAClC,MAAM,QAAQ,GAAG,8BAAc,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACvD,OAAO,IAAI,sBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAC7C,CAAC;iBAAM,CAAC;gBACN,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBAChE,MAAM,QAAQ,GAAG,8BAAc,CAAC,UAAU,CAAC;oBACzC,WAAW,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;iBACpC,CAAC,CAAC;gBACH,OAAO,IAAI,sBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { Algodv2 } from \"algosdk\";\nimport { TronWeb } from \"tronweb\";\nimport { Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { Messenger } from \"../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { CCTPDoesNotSupportedError, OFTDoesNotSupportedError } from \"../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainSymbol, ChainType, EssentialWeb3 } from \"../../index\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { AlgBridgeService } from \"./alg\";\nimport { EvmBridgeService } from \"./evm\";\nimport { ApproveParams, ChainBridgeService, CheckAllowanceParams, GetAllowanceParams, SendParams } from \"./models\";\nimport { DefaultRawBridgeTransactionBuilder, RawBridgeTransactionBuilder } from \"./raw-bridge-transaction-builder\";\nimport { SolanaBridgeService } from \"./sol\";\nimport { SrbBridgeService } from \"./srb\";\nimport { SuiBridgeService } from \"./sui\";\nimport { TronBridgeService } from \"./trx\";\n\nexport interface BridgeService {\n rawTxBuilder: RawBridgeTransactionBuilder;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param provider - will be used to access the network\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: GetAllowanceParams): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param provider - will be used to access the network\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.approve}<p>\n * Approve tokens usage by another address on chains\n * <p>\n * For ETH/USDT: due to specificity of the USDT contract:<br/>\n * If the current allowance is not 0, this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.send}<p>\n * Send tokens through the ChainBridgeService\n * @param provider - will be used to access the network\n * @param params\n */\n send(provider: Provider, params: SendParams): Promise<TransactionResponse>;\n}\n\nexport class DefaultBridgeService implements BridgeService {\n public rawTxBuilder: RawBridgeTransactionBuilder;\n\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawBridgeTransactionBuilder(api, nodeRpcUrlsConfig, params, tokenService);\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n let provider: Provider | undefined;\n let params: GetAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as GetAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger);\n return await this.tokenService.getAllowance({ ...params, spender }, provider);\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n let provider: Provider | undefined;\n let params: CheckAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as CheckAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger);\n return this.tokenService.checkAllowance({ ...params, spender }, provider);\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n const spender = getSpender(approveData.token, approveData.messenger);\n return this.tokenService.approve(provider, { ...approveData, spender });\n }\n\n async send(provider: Provider, params: SendParams): Promise<TransactionResponse> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.sourceToken.decimals);\n return getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).send(params);\n }\n}\n\nexport function getSpender(token: TokenWithChainDetails, messenger: Messenger = Messenger.ALLBRIDGE): string {\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.ALLBRIDGE:\n case Messenger.WORMHOLE:\n return token.bridgeAddress;\n }\n}\n\nexport function getChainBridgeService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): ChainBridgeService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmBridgeService(provider as EssentialWeb3, api, nodeRpcUrlsConfig);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new EvmBridgeService(new Web3(nodeRpcUrl), api, nodeRpcUrlsConfig);\n }\n }\n case ChainType.TRX: {\n if (provider) {\n return new TronBridgeService(provider as TronWeb, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new TronBridgeService(\n new TronWeb({\n fullHost: nodeRpcUrl,\n solidityNode: nodeRpcUrl,\n eventServer: nodeRpcUrl,\n }),\n api\n );\n }\n }\n case ChainType.SOLANA: {\n return new SolanaBridgeService(\n nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL),\n {\n wormholeMessengerProgramId: params.wormholeMessengerProgramId,\n solanaLookUpTable: params.solanaLookUpTable,\n cctpParams: params.cctpParams,\n jupiterParams: {\n jupiterUrl: params.jupiterUrl,\n jupiterApiKeyHeader: params.jupiterApiKeyHeader,\n jupiterMaxAccounts: params.jupiterMaxAccounts,\n },\n },\n api\n );\n }\n case ChainType.SRB: {\n return new SrbBridgeService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiBridgeService(nodeRpcUrlsConfig, api);\n }\n case ChainType.ALG: {\n if (provider) {\n const algod = provider as Algodv2;\n const algorand = AlgorandClient.fromClients({ algod });\n return new AlgBridgeService(algorand, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const algorand = AlgorandClient.fromConfig({\n algodConfig: { server: nodeRpcUrl },\n });\n return new AlgBridgeService(algorand, api);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/bridge/index.ts"],"names":[],"mappings":";;;AAqIA,gCAkCC;AAED,sDAuEC;AAhPD,qEAAmE;AAEnE,qCAAkC;AAClC,+BAA4B;AAE5B,yCAAsC;AACtC,yEAAiE;AAEjE,iDAAiG;AACjG,uCAA+G;AAE/G,6CAAiF;AAGjF,+BAAyC;AACzC,+BAAyC;AAEzC,qFAAmH;AACnH,+BAA4C;AAC5C,+BAAyC;AACzC,+BAAyC;AACzC,+BAAyC;AACzC,+BAA0C;AAuD1C,MAAa,oBAAoB;IAIrB;IACA;IACA;IACA;IANH,YAAY,CAA8B;IAEjD,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAAqB;QACxB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,YAAY,GAAG,IAAI,mEAAkC,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAC3G,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,CAAgC,EAAE,CAAsB;QACzE,IAAI,QAA8B,CAAC;QACnC,IAAI,MAA0B,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC;YACN,QAAQ,GAAG,CAAa,CAAC;YACzB,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,CAAuB,CAAC;QACnC,CAAC;QACD,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,C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C;IACH,CAAC;AACH,CAAC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { Algodv2 } from \"algosdk\";\nimport { TronWeb } from \"tronweb\";\nimport { Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { Messenger } from \"../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { CCTPDoesNotSupportedError, OFTDoesNotSupportedError, SdkError } from \"../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainSymbol, ChainType, EssentialWeb3, FeePaymentMethod } from \"../../index\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { AlgBridgeService } from \"./alg\";\nimport { EvmBridgeService } from \"./evm\";\nimport { ApproveParams, ChainBridgeService, CheckAllowanceParams, GetAllowanceParams, SendParams } from \"./models\";\nimport { DefaultRawBridgeTransactionBuilder, RawBridgeTransactionBuilder } from \"./raw-bridge-transaction-builder\";\nimport { SolanaBridgeService } from \"./sol\";\nimport { SrbBridgeService } from \"./srb\";\nimport { StxBridgeService } from \"./stx\";\nimport { SuiBridgeService } from \"./sui\";\nimport { TronBridgeService } from \"./trx\";\n\nexport interface BridgeService {\n rawTxBuilder: RawBridgeTransactionBuilder;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param provider - will be used to access the network\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: GetAllowanceParams): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param provider - will be used to access the network\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.approve}<p>\n * Approve tokens usage by another address on chains\n * <p>\n * For ETH/USDT: due to specificity of the USDT contract:<br/>\n * If the current allowance is not 0, this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.send}<p>\n * Send tokens through the ChainBridgeService\n * @param provider - will be used to access the network\n * @param params\n */\n send(provider: Provider, params: SendParams): Promise<TransactionResponse>;\n}\n\nexport class DefaultBridgeService implements BridgeService {\n public rawTxBuilder: RawBridgeTransactionBuilder;\n\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawBridgeTransactionBuilder(api, nodeRpcUrlsConfig, params, tokenService);\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n let provider: Provider | undefined;\n let params: GetAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as GetAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger, params.gasFeePaymentMethod);\n return await this.tokenService.getAllowance({ ...params, spender }, provider);\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n let provider: Provider | undefined;\n let params: CheckAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as CheckAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger, params.gasFeePaymentMethod);\n return this.tokenService.checkAllowance({ ...params, spender }, provider);\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n const spender = getSpender(approveData.token, approveData.messenger, approveData.gasFeePaymentMethod);\n return this.tokenService.approve(provider, { ...approveData, spender });\n }\n\n async send(provider: Provider, params: SendParams): Promise<TransactionResponse> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.sourceToken.decimals);\n return getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).send(params);\n }\n}\n\nexport function getSpender(\n token: TokenWithChainDetails,\n messenger: Messenger = Messenger.ALLBRIDGE,\n gasFeePaymentMethod: FeePaymentMethod = FeePaymentMethod.WITH_NATIVE_CURRENCY\n): string {\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ARB) {\n if (token.abrPayer) {\n return token.abrPayer.payerAddress;\n }\n throw new SdkError(\"Token must contain 'abrPayer' for ARB0 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.ALLBRIDGE:\n case Messenger.WORMHOLE:\n return token.bridgeAddress;\n }\n}\n\nexport function getChainBridgeService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): ChainBridgeService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmBridgeService(provider as EssentialWeb3, api, nodeRpcUrlsConfig);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new EvmBridgeService(new Web3(nodeRpcUrl), api, nodeRpcUrlsConfig);\n }\n }\n case ChainType.TRX: {\n if (provider) {\n return new TronBridgeService(provider as TronWeb, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new TronBridgeService(\n new TronWeb({\n fullHost: nodeRpcUrl,\n solidityNode: nodeRpcUrl,\n eventServer: nodeRpcUrl,\n }),\n api\n );\n }\n }\n case ChainType.SOLANA: {\n return new SolanaBridgeService(\n nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL),\n {\n wormholeMessengerProgramId: params.wormholeMessengerProgramId,\n solanaLookUpTable: params.solanaLookUpTable,\n cctpParams: params.cctpParams,\n jupiterParams: {\n jupiterUrl: params.jupiterUrl,\n jupiterApiKeyHeader: params.jupiterApiKeyHeader,\n jupiterMaxAccounts: params.jupiterMaxAccounts,\n },\n },\n api\n );\n }\n case ChainType.SRB: {\n return new SrbBridgeService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiBridgeService(nodeRpcUrlsConfig, api);\n }\n case ChainType.ALG: {\n if (provider) {\n const algod = provider as Algodv2;\n const algorand = AlgorandClient.fromClients({ algod });\n return new AlgBridgeService(algorand, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const algorand = AlgorandClient.fromConfig({\n algodConfig: { server: nodeRpcUrl },\n });\n return new AlgBridgeService(algorand, api);\n }\n }\n case ChainType.STX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new StxBridgeService(nodeRpcUrl, params, api);\n }\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { Big } from "big.js";
2
2
  import { Messenger } from "../../../client/core-api/core-api.model";
3
- import { AmountFormat, FeePaymentMethod, TxFeeParams } from "../../../models";
3
+ import { AmountFormat, FeePaymentMethod, TokenCoreFields, TxFeeParams } from "../../../models";
4
4
  import { TokenWithChainDetails } from "../../../tokens-info";
5
5
  export interface ApproveParams {
6
6
  /**
@@ -23,13 +23,14 @@ export interface ApproveParams {
23
23
  * The {@link Messenger.ALLBRIDGE}, {@link Messenger.WORMHOLE} by default.
24
24
  */
25
25
  messenger?: Messenger;
26
+ gasFeePaymentMethod?: FeePaymentMethod;
26
27
  }
27
28
  export interface GetTokenBalanceParams {
28
29
  /**
29
30
  * The address for which we will find out the token balance
30
31
  */
31
32
  account: string;
32
- token: TokenWithChainDetails;
33
+ token: TokenCoreFields;
33
34
  }
34
35
  export interface GetNativeTokenBalanceParams {
35
36
  /**
@@ -93,6 +94,8 @@ export interface SendParams extends BaseSendParams {
93
94
  * it is amount of the source chain currency.<p/>
94
95
  * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_STABLECOIN} then
95
96
  * it is amount of the source token.
97
+ * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_ARB} then
98
+ * it is amount of the ABR token.
96
99
  *
97
100
  * Optional.
98
101
  * If not defined, the default fee amount will be applied according to gasFeePaymentMethod.
@@ -113,6 +116,8 @@ export interface SendParams extends BaseSendParams {
113
116
  * it is amount of the source chain currency.<p/>
114
117
  * if gasFeePaymentMethod is {@link FeePaymentMethod#WITH_STABLECOIN} then
115
118
  * it is amount of the source token.
119
+ * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_ARB} then
120
+ * it is amount of the ABR token.
116
121
  *
117
122
  * Optional.
118
123
  */
@@ -126,8 +131,9 @@ export interface SendParams extends BaseSendParams {
126
131
  /**
127
132
  * Payment method for the gas fee and extra gas payment.
128
133
  *
129
- * WITH_NATIVE_CURRENCY - gas fee and extra gas will be added to transaction as native tokens value
130
- * WITH_STABLECOIN - gas fee and extra gas will be deducted from the transaction amount
134
+ * WITH_NATIVE_CURRENCY - gas fee and extra gas will be added to transaction as native tokens value</br>
135
+ * WITH_STABLECOIN - gas fee and extra gas will be deducted from the transaction amount</br>
136
+ * WITH_ABR - gas fee and extra gas will be added to transaction as ABR tokens value</br>
131
137
  *
132
138
  * Optional.
133
139
  * WITH_NATIVE_CURRENCY by default.
@@ -177,6 +183,7 @@ export type TxSendParamsEvm = TxSendParamsTyped<string>;
177
183
  export type TxSendParamsSui = TxSendParamsTyped<string>;
178
184
  export type TxSendParamsTrx = TxSendParamsTyped<Buffer>;
179
185
  export type TxSendParamsAlg = TxSendParamsTyped<Buffer>;
186
+ export type TxSendParamsStx = TxSendParamsTyped<Buffer>;
180
187
  export type TxSendParamsSol = TxSendParamsTyped<number[]>;
181
188
  export type TxSendParamsSrb = TxSendParamsTyped<number[]>;
182
189
  export interface TxSendParamsTyped<T> {
@@ -203,5 +210,6 @@ export interface TxSendParamsTyped<T> {
203
210
  */
204
211
  extraGasDest?: string;
205
212
  gasFeePaymentMethod: FeePaymentMethod;
213
+ abrExchangeRate?: string;
206
214
  }
207
215
  export type TxSendParams = TxSendParamsEvm | TxSendParamsTrx | TxSendParamsSol | TxSendParamsSrb | TxSendParamsSui;
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.model.js","sourceRoot":"","sources":["../../../../../src/services/bridge/models/bridge.model.ts"],"names":[],"mappings":"","sourcesContent":["import { Big } from \"big.js\";\nimport { Messenger } from \"../../../client/core-api/core-api.model\";\nimport { AmountFormat, FeePaymentMethod, TxFeeParams } from \"../../../models\";\nimport { TokenWithChainDetails } from \"../../../tokens-info\";\n\nexport interface ApproveParams {\n /**\n * The token info\n */\n token: TokenWithChainDetails;\n\n /**\n * The address of the token owner who is granting permission to use tokens\n */\n owner: string;\n\n /**\n * The integer amount of tokens to approve.\n * Optional.\n * The maximum amount by default.\n */\n amount?: string | number | Big;\n\n /**\n * The Messengers for different routes to approve.\n * Optional.\n * The {@link Messenger.ALLBRIDGE}, {@link Messenger.WORMHOLE} by default.\n */\n messenger?: Messenger;\n}\n\nexport interface GetTokenBalanceParams {\n /**\n * The address for which we will find out the token balance\n */\n account: string;\n token: TokenWithChainDetails;\n}\n\nexport interface GetNativeTokenBalanceParams {\n /**\n * The address for which we will find out the token balance\n */\n account: string;\n /**\n * The symbol of the chain representing one of the supported blockchain networks (e.g., \"ETH\" for Ethereum). For more details, see: {@link ChainSymbol}.\n */\n chainSymbol: string;\n}\n\nexport interface BaseSendParams {\n /**\n * The float amount of Total tokens to transfer.\n *\n * In Send case\n * If {@link SendParams#gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_STABLECOIN}:<br/>\n * Includes gas fee<br/>\n * Includes extra gas\n */\n amount: string;\n /**\n * The account address to transfer tokens from.\n */\n fromAccountAddress: string;\n /**\n * The account address to transfer tokens to.\n */\n toAccountAddress: string;\n /**\n * {@link TokenWithChainDetails |The token info object} on the source chain.\n */\n sourceToken: TokenWithChainDetails;\n /**\n * {@link TokenWithChainDetails |The token info object} on the destination chain.\n */\n destinationToken: TokenWithChainDetails;\n\n txFeeParams?: TxFeeParams;\n}\n\n/**\n * Required params to handle swap transfer (different tokens on the same chain)\n */\nexport interface SwapParams extends BaseSendParams {\n /**\n * minimum amount to receive including possible slippage, see {@link AllbridgeCoreSdk#getAmountToBeReceived}\n */\n minimumReceiveAmount?: string;\n}\n\n/**\n * Required params to handle bridge transfer (transfer between chains)\n */\nexport interface SendParams extends BaseSendParams {\n /**\n * The Messenger to use.\n */\n messenger: Messenger;\n /**\n * The amount of gas fee to pay for the transfer.\n *\n * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_NATIVE_CURRENCY} then\n * it is amount of the source chain currency.<p/>\n * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_STABLECOIN} then\n * it is amount of the source token.\n *\n * Optional.\n * If not defined, the default fee amount will be applied according to gasFeePaymentMethod.\n * See method {@link AllbridgeCoreSdk#getGasFeeOptions} to get required gas fee amount.\n */\n fee?: string;\n /**\n * Format of fee value.<p/>\n * Optional.\n * {@link AmountFormat.INT} by default.\n */\n feeFormat?: AmountFormat;\n /**\n * The amount of extra gas to transfer to gas on destination chain with the transfer.<br/>\n * To get maximum supported value, look {@link AllbridgeCoreSdk#getExtraGasMaxLimits}\n *\n * If gasFeePaymentMethod is {@link FeePaymentMethod#WITH_NATIVE_CURRENCY} then\n * it is amount of the source chain currency.<p/>\n * if gasFeePaymentMethod is {@link FeePaymentMethod#WITH_STABLECOIN} then\n * it is amount of the source token.\n *\n * Optional.\n */\n extraGas?: string;\n /**\n * Format of extra gas value.<p/>\n * Optional.\n * {@link AmountFormat.INT} by default.\n */\n extraGasFormat?: AmountFormat;\n /**\n * Payment method for the gas fee and extra gas payment.\n *\n * WITH_NATIVE_CURRENCY - gas fee and extra gas will be added to transaction as native tokens value\n * WITH_STABLECOIN - gas fee and extra gas will be deducted from the transaction amount\n *\n * Optional.\n * WITH_NATIVE_CURRENCY by default.\n */\n gasFeePaymentMethod?: FeePaymentMethod;\n}\n\nexport interface GetAllowanceParams {\n token: TokenWithChainDetails;\n owner: string;\n gasFeePaymentMethod?: FeePaymentMethod;\n /**\n * The Messengers for different routes.\n * Optional.\n * The {@link Messenger.ALLBRIDGE}, {@link Messenger.WORMHOLE} by default.\n */\n messenger?: Messenger;\n}\n\nexport type GetAllowanceParamsDto = GetAllowanceParams;\n\nexport interface CheckAllowanceParams extends GetAllowanceParams {\n /**\n * The float amount of tokens to check the allowance.\n */\n amount: string | number | Big;\n}\n\n/**\n * @internal\n */\nexport type TxSwapParamsEvm = TxSwapParamsTyped<string>;\nexport type TxSwapParamsSui = TxSwapParamsTyped<string>;\nexport type TxSwapParamsTrx = TxSwapParamsTyped<Buffer>;\nexport type TxSwapParamsSol = TxSwapParamsTyped<number[]>;\nexport type TxSwapParamsSrb = TxSwapParamsTyped<number[]>;\n\nexport interface TxSwapParamsTyped<T> {\n amount: string;\n contractAddress: string;\n fromAccountAddress: string;\n fromTokenAddress: T;\n toAccountAddress: string;\n toTokenAddress: T;\n minimumReceiveAmount: string;\n}\n\nexport type TxSwapParams = TxSwapParamsEvm | TxSwapParamsTrx | TxSwapParamsSol | TxSwapParamsSrb | TxSwapParamsSui;\n\n/**\n * @internal\n */\nexport type TxSendParamsEvm = TxSendParamsTyped<string>;\nexport type TxSendParamsSui = TxSendParamsTyped<string>;\nexport type TxSendParamsTrx = TxSendParamsTyped<Buffer>;\nexport type TxSendParamsAlg = TxSendParamsTyped<Buffer>;\nexport type TxSendParamsSol = TxSendParamsTyped<number[]>;\nexport type TxSendParamsSrb = TxSendParamsTyped<number[]>;\n\nexport interface TxSendParamsTyped<T> {\n amount: string;\n contractAddress: string;\n fromChainId: number;\n fromChainSymbol: string;\n fromAccountAddress: string;\n fromTokenAddress: T;\n toChainId: number;\n toAccountAddress: T;\n toTokenAddress: T;\n messenger: Messenger;\n /**\n * int format\n */\n fee: string;\n /**\n * int format\n */\n extraGas?: string;\n /**\n * int format\n */\n extraGasDest?: string;\n gasFeePaymentMethod: FeePaymentMethod;\n}\n\nexport type TxSendParams = TxSendParamsEvm | TxSendParamsTrx | TxSendParamsSol | TxSendParamsSrb | TxSendParamsSui;\n"]}
1
+ {"version":3,"file":"bridge.model.js","sourceRoot":"","sources":["../../../../../src/services/bridge/models/bridge.model.ts"],"names":[],"mappings":"","sourcesContent":["import { Big } from \"big.js\";\nimport { Messenger } from \"../../../client/core-api/core-api.model\";\nimport { AmountFormat, FeePaymentMethod, TokenCoreFields, TxFeeParams } from \"../../../models\";\nimport { TokenWithChainDetails } from \"../../../tokens-info\";\n\nexport interface ApproveParams {\n /**\n * The token info\n */\n token: TokenWithChainDetails;\n\n /**\n * The address of the token owner who is granting permission to use tokens\n */\n owner: string;\n\n /**\n * The integer amount of tokens to approve.\n * Optional.\n * The maximum amount by default.\n */\n amount?: string | number | Big;\n\n /**\n * The Messengers for different routes to approve.\n * Optional.\n * The {@link Messenger.ALLBRIDGE}, {@link Messenger.WORMHOLE} by default.\n */\n messenger?: Messenger;\n\n gasFeePaymentMethod?: FeePaymentMethod;\n}\n\nexport interface GetTokenBalanceParams {\n /**\n * The address for which we will find out the token balance\n */\n account: string;\n token: TokenCoreFields;\n}\n\nexport interface GetNativeTokenBalanceParams {\n /**\n * The address for which we will find out the token balance\n */\n account: string;\n /**\n * The symbol of the chain representing one of the supported blockchain networks (e.g., \"ETH\" for Ethereum). For more details, see: {@link ChainSymbol}.\n */\n chainSymbol: string;\n}\n\nexport interface BaseSendParams {\n /**\n * The float amount of Total tokens to transfer.\n *\n * In Send case\n * If {@link SendParams#gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_STABLECOIN}:<br/>\n * Includes gas fee<br/>\n * Includes extra gas\n */\n amount: string;\n /**\n * The account address to transfer tokens from.\n */\n fromAccountAddress: string;\n /**\n * The account address to transfer tokens to.\n */\n toAccountAddress: string;\n /**\n * {@link TokenWithChainDetails |The token info object} on the source chain.\n */\n sourceToken: TokenWithChainDetails;\n /**\n * {@link TokenWithChainDetails |The token info object} on the destination chain.\n */\n destinationToken: TokenWithChainDetails;\n\n txFeeParams?: TxFeeParams;\n}\n\n/**\n * Required params to handle swap transfer (different tokens on the same chain)\n */\nexport interface SwapParams extends BaseSendParams {\n /**\n * minimum amount to receive including possible slippage, see {@link AllbridgeCoreSdk#getAmountToBeReceived}\n */\n minimumReceiveAmount?: string;\n}\n\n/**\n * Required params to handle bridge transfer (transfer between chains)\n */\nexport interface SendParams extends BaseSendParams {\n /**\n * The Messenger to use.\n */\n messenger: Messenger;\n /**\n * The amount of gas fee to pay for the transfer.\n *\n * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_NATIVE_CURRENCY} then\n * it is amount of the source chain currency.<p/>\n * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_STABLECOIN} then\n * it is amount of the source token.\n * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_ARB} then\n * it is amount of the ABR token.\n *\n * Optional.\n * If not defined, the default fee amount will be applied according to gasFeePaymentMethod.\n * See method {@link AllbridgeCoreSdk#getGasFeeOptions} to get required gas fee amount.\n */\n fee?: string;\n /**\n * Format of fee value.<p/>\n * Optional.\n * {@link AmountFormat.INT} by default.\n */\n feeFormat?: AmountFormat;\n /**\n * The amount of extra gas to transfer to gas on destination chain with the transfer.<br/>\n * To get maximum supported value, look {@link AllbridgeCoreSdk#getExtraGasMaxLimits}\n *\n * If gasFeePaymentMethod is {@link FeePaymentMethod#WITH_NATIVE_CURRENCY} then\n * it is amount of the source chain currency.<p/>\n * if gasFeePaymentMethod is {@link FeePaymentMethod#WITH_STABLECOIN} then\n * it is amount of the source token.\n * If {@link gasFeePaymentMethod} is {@link FeePaymentMethod#WITH_ARB} then\n * it is amount of the ABR token.\n *\n * Optional.\n */\n extraGas?: string;\n /**\n * Format of extra gas value.<p/>\n * Optional.\n * {@link AmountFormat.INT} by default.\n */\n extraGasFormat?: AmountFormat;\n /**\n * Payment method for the gas fee and extra gas payment.\n *\n * WITH_NATIVE_CURRENCY - gas fee and extra gas will be added to transaction as native tokens value</br>\n * WITH_STABLECOIN - gas fee and extra gas will be deducted from the transaction amount</br>\n * WITH_ABR - gas fee and extra gas will be added to transaction as ABR tokens value</br>\n *\n * Optional.\n * WITH_NATIVE_CURRENCY by default.\n */\n gasFeePaymentMethod?: FeePaymentMethod;\n}\n\nexport interface GetAllowanceParams {\n token: TokenWithChainDetails;\n owner: string;\n gasFeePaymentMethod?: FeePaymentMethod;\n /**\n * The Messengers for different routes.\n * Optional.\n * The {@link Messenger.ALLBRIDGE}, {@link Messenger.WORMHOLE} by default.\n */\n messenger?: Messenger;\n}\n\nexport type GetAllowanceParamsDto = GetAllowanceParams;\n\nexport interface CheckAllowanceParams extends GetAllowanceParams {\n /**\n * The float amount of tokens to check the allowance.\n */\n amount: string | number | Big;\n}\n\n/**\n * @internal\n */\nexport type TxSwapParamsEvm = TxSwapParamsTyped<string>;\nexport type TxSwapParamsSui = TxSwapParamsTyped<string>;\nexport type TxSwapParamsTrx = TxSwapParamsTyped<Buffer>;\nexport type TxSwapParamsSol = TxSwapParamsTyped<number[]>;\nexport type TxSwapParamsSrb = TxSwapParamsTyped<number[]>;\n\nexport interface TxSwapParamsTyped<T> {\n amount: string;\n contractAddress: string;\n fromAccountAddress: string;\n fromTokenAddress: T;\n toAccountAddress: string;\n toTokenAddress: T;\n minimumReceiveAmount: string;\n}\n\nexport type TxSwapParams = TxSwapParamsEvm | TxSwapParamsTrx | TxSwapParamsSol | TxSwapParamsSrb | TxSwapParamsSui;\n\n/**\n * @internal\n */\nexport type TxSendParamsEvm = TxSendParamsTyped<string>;\nexport type TxSendParamsSui = TxSendParamsTyped<string>;\nexport type TxSendParamsTrx = TxSendParamsTyped<Buffer>;\nexport type TxSendParamsAlg = TxSendParamsTyped<Buffer>;\nexport type TxSendParamsStx = TxSendParamsTyped<Buffer>;\nexport type TxSendParamsSol = TxSendParamsTyped<number[]>;\nexport type TxSendParamsSrb = TxSendParamsTyped<number[]>;\n\nexport interface TxSendParamsTyped<T> {\n amount: string;\n contractAddress: string;\n fromChainId: number;\n fromChainSymbol: string;\n fromAccountAddress: string;\n fromTokenAddress: T;\n toChainId: number;\n toAccountAddress: T;\n toTokenAddress: T;\n messenger: Messenger;\n /**\n * int format\n */\n fee: string;\n /**\n * int format\n */\n extraGas?: string;\n /**\n * int format\n */\n extraGasDest?: string;\n gasFeePaymentMethod: FeePaymentMethod;\n abrExchangeRate?: string;\n}\n\nexport type TxSendParams = TxSendParamsEvm | TxSendParamsTrx | TxSendParamsSol | TxSendParamsSrb | TxSendParamsSui;\n"]}
@@ -25,7 +25,7 @@ class DefaultRawBridgeTransactionBuilder {
25
25
  else {
26
26
  approveData = a;
27
27
  }
28
- const spender = (0, index_1.getSpender)(approveData.token, approveData.messenger);
28
+ const spender = (0, index_1.getSpender)(approveData.token, approveData.messenger, approveData.gasFeePaymentMethod);
29
29
  return this.tokenService.buildRawTransactionApprove({
30
30
  ...approveData,
31
31
  spender,
@@ -1 +1 @@
1
- {"version":3,"file":"raw-bridge-transaction-builder.js","sourceRoot":"","sources":["../../../../src/services/bridge/raw-bridge-transaction-builder.ts"],"names":[],"mappings":";;;AAGA,6CAAiF;AAIjF,mCAAuC;AACvC,mCAA4D;AAsB5D,MAAa,kCAAkC;IAEnC;IACA;IACA;IACA;IAJV,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAAqB;QACxB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,CAA2B,EAAE,CAAiB;QAC1D,IAAI,QAA8B,CAAC;QACnC,IAAI,WAA0B,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC;YACN,QAAQ,GAAG,CAAa,CAAC;YACzB,WAAW,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,CAAkB,CAAC;QACnC,CAAC;QACD,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,YAAY,CAAC,0BAA0B,CACjD;YACE,GAAG,WAAW;YACd,OAAO;SACR,EACD,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAA+B,EAAE,QAAmB;QAC7D,IAAA,4BAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,IAAA,8BAAsB,EAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC7E,IAAI,IAAA,oBAAY,EAAC,MAAM,CAAC,EAAE,CAAC;YACzB,OAAO,IAAA,6BAAqB,EAC1B,MAAM,CAAC,WAAW,CAAC,WAAW,EAC9B,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,EACX,QAAQ,CACT,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,IAAA,6BAAqB,EAC1B,MAAM,CAAC,WAAW,CAAC,WAAW,EAC9B,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,EACX,QAAQ,CACT,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;CACF;AA/CD,gFA+CC","sourcesContent":["import { NodeRpcUrlsConfig } from \"..\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions } from \"../../index\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, RawTransaction } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { ApproveParams, SendParams, SwapParams } from \"./models\";\nimport { isSendParams } from \"./utils\";\nimport { getChainBridgeService, getSpender } from \"./index\";\n\nexport interface RawBridgeTransactionBuilder {\n /**\n * Creates a Raw Transaction for approving tokens usage by the bridge\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<RawTransaction>;\n /**\n * Creates a Raw Transaction for approving tokens usage by the bridge\n * @param approveData\n */\n approve(approveData: ApproveParams): Promise<RawTransaction>;\n /**\n * Creates a Raw Transaction for initiating the transfer of tokens\n * @param params\n * @param provider - will be used to access the network\n */\n send(params: SwapParams | SendParams, provider?: Provider): Promise<RawTransaction>;\n}\n\nexport class DefaultRawBridgeTransactionBuilder implements RawBridgeTransactionBuilder {\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {}\n\n async approve(a: Provider | ApproveParams, b?: ApproveParams): Promise<RawTransaction> {\n let provider: Provider | undefined;\n let approveData: ApproveParams;\n if (b) {\n provider = a as Provider;\n approveData = b;\n } else {\n approveData = a as ApproveParams;\n }\n const spender = getSpender(approveData.token, approveData.messenger);\n return this.tokenService.buildRawTransactionApprove(\n {\n ...approveData,\n spender,\n },\n provider\n );\n }\n\n async send(params: SwapParams | SendParams, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.sourceToken.decimals);\n if (isSendParams(params)) {\n return getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionSend(params);\n }\n return getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionSwap(params);\n }\n}\n"]}
1
+ {"version":3,"file":"raw-bridge-transaction-builder.js","sourceRoot":"","sources":["../../../../src/services/bridge/raw-bridge-transaction-builder.ts"],"names":[],"mappings":";;;AAGA,6CAAiF;AAIjF,mCAAuC;AACvC,mCAA4D;AAsB5D,MAAa,kCAAkC;IAEnC;IACA;IACA;IACA;IAJV,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAAqB;QACxB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,CAA2B,EAAE,CAAiB;QAC1D,IAAI,QAA8B,CAAC;QACnC,IAAI,WAA0B,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC;YACN,QAAQ,GAAG,CAAa,CAAC;YACzB,WAAW,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,CAAkB,CAAC;QACnC,CAAC;QACD,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAAC;QACtG,OAAO,IAAI,CAAC,YAAY,CAAC,0BAA0B,CACjD;YACE,GAAG,WAAW;YACd,OAAO;SACR,EACD,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAA+B,EAAE,QAAmB;QAC7D,IAAA,4BAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,IAAA,8BAAsB,EAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC7E,IAAI,IAAA,oBAAY,EAAC,MAAM,CAAC,EAAE,CAAC;YACzB,OAAO,IAAA,6BAAqB,EAC1B,MAAM,CAAC,WAAW,CAAC,WAAW,EAC9B,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,EACX,QAAQ,CACT,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,IAAA,6BAAqB,EAC1B,MAAM,CAAC,WAAW,CAAC,WAAW,EAC9B,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,EACX,QAAQ,CACT,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;CACF;AA/CD,gFA+CC","sourcesContent":["import { NodeRpcUrlsConfig } from \"..\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions } from \"../../index\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, RawTransaction } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { ApproveParams, SendParams, SwapParams } from \"./models\";\nimport { isSendParams } from \"./utils\";\nimport { getChainBridgeService, getSpender } from \"./index\";\n\nexport interface RawBridgeTransactionBuilder {\n /**\n * Creates a Raw Transaction for approving tokens usage by the bridge\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<RawTransaction>;\n /**\n * Creates a Raw Transaction for approving tokens usage by the bridge\n * @param approveData\n */\n approve(approveData: ApproveParams): Promise<RawTransaction>;\n /**\n * Creates a Raw Transaction for initiating the transfer of tokens\n * @param params\n * @param provider - will be used to access the network\n */\n send(params: SwapParams | SendParams, provider?: Provider): Promise<RawTransaction>;\n}\n\nexport class DefaultRawBridgeTransactionBuilder implements RawBridgeTransactionBuilder {\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {}\n\n async approve(a: Provider | ApproveParams, b?: ApproveParams): Promise<RawTransaction> {\n let provider: Provider | undefined;\n let approveData: ApproveParams;\n if (b) {\n provider = a as Provider;\n approveData = b;\n } else {\n approveData = a as ApproveParams;\n }\n const spender = getSpender(approveData.token, approveData.messenger, approveData.gasFeePaymentMethod);\n return this.tokenService.buildRawTransactionApprove(\n {\n ...approveData,\n spender,\n },\n provider\n );\n }\n\n async send(params: SwapParams | SendParams, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.sourceToken.decimals);\n if (isSendParams(params)) {\n return getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionSend(params);\n }\n return getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionSwap(params);\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { Keypair, VersionedTransaction } from "@solana/web3.js";
2
2
  import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
3
- import { ChainType, FeePaymentMethod, SwapParams, TokenWithChainDetails } from "../../../models";
3
+ import { ChainType, FeePaymentMethod, SwapParams, TokenWithChainDetails, TxFeeParams } from "../../../models";
4
4
  import { RawTransaction, TransactionResponse } from "../../models";
5
5
  import { SwapAndBridgeSolDataCctpData } from "../../models/sol";
6
6
  import { SendParams, TxSendParamsSol } from "../models";
@@ -53,7 +53,7 @@ export declare class SolanaBridgeService extends ChainBridgeService {
53
53
  private convertToVersionedTransaction;
54
54
  private buildSwapAndBridgeWormholeTransaction;
55
55
  private prepareSwapAndBridgeCctpData;
56
- buildSwapAndBridgeCctpTransaction(destinationChainSymbol: string, swapAndBridgeData: SwapAndBridgeSolDataCctpData): Promise<{
56
+ buildSwapAndBridgeCctpTransaction(destinationChainSymbol: string, swapAndBridgeData: SwapAndBridgeSolDataCctpData, txFeeParams?: TxFeeParams): Promise<{
57
57
  transaction: VersionedTransaction;
58
58
  messageSentEventDataKeypair: Keypair;
59
59
  }>;
@@ -66,6 +66,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
66
66
  units: COMPUTE_UNIT_LIMIT,
67
67
  }),
68
68
  ];
69
+ const feePayer = (0, sol_1.getFeePayer)(userAccount, txFeeParams);
69
70
  try {
70
71
  await (0, sol_1.getTokenAccountData)(receiveUserToken, provider);
71
72
  }
@@ -101,7 +102,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
101
102
  .transaction();
102
103
  const connection = provider.connection;
103
104
  transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
104
- transaction.feePayer = userAccount;
105
+ transaction.feePayer = feePayer;
105
106
  await (0, compute_budget_1.addUnitLimitAndUnitPriceToTx)(transaction, txFeeParams, this.solanaRpcUrl);
106
107
  return await this.convertToVersionedTransaction(transaction, connection);
107
108
  }
@@ -138,12 +139,12 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
138
139
  switch (txSendParams.messenger) {
139
140
  case core_api_model_1.Messenger.ALLBRIDGE: {
140
141
  const swapAndBridgeSolData = await this.prepareSwapAndBridgeData(solTxSendParams);
141
- swapAndBridgeTx = await this.buildSwapAndBridgeAllbridgeTransaction(swapAndBridgeSolData);
142
+ swapAndBridgeTx = await this.buildSwapAndBridgeAllbridgeTransaction(swapAndBridgeSolData, params.txFeeParams);
142
143
  break;
143
144
  }
144
145
  case core_api_model_1.Messenger.WORMHOLE: {
145
146
  const swapAndBridgeSolData = await this.prepareSwapAndBridgeData(solTxSendParams);
146
- const { transaction, messageAccount } = await this.buildSwapAndBridgeWormholeTransaction(swapAndBridgeSolData);
147
+ const { transaction, messageAccount } = await this.buildSwapAndBridgeWormholeTransaction(swapAndBridgeSolData, params.txFeeParams);
147
148
  swapAndBridgeTx = transaction;
148
149
  requiredMessageSigner = messageAccount;
149
150
  break;
@@ -151,7 +152,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
151
152
  case core_api_model_1.Messenger.CCTP:
152
153
  case core_api_model_1.Messenger.CCTP_V2: {
153
154
  const swapAndBridgeSolData = await this.prepareSwapAndBridgeCctpData(solTxSendParams);
154
- const { transaction, messageSentEventDataKeypair } = await this.buildSwapAndBridgeCctpTransaction(params.destinationToken.chainSymbol, swapAndBridgeSolData);
155
+ const { transaction, messageSentEventDataKeypair } = await this.buildSwapAndBridgeCctpTransaction(params.destinationToken.chainSymbol, swapAndBridgeSolData, params.txFeeParams);
155
156
  swapAndBridgeTx = transaction;
156
157
  requiredMessageSigner = messageSentEventDataKeypair;
157
158
  break;
@@ -180,7 +181,8 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
180
181
  if (!exactOut) {
181
182
  amountToProcess = amountToProcess.mul(JUP_ADD_INDEX);
182
183
  }
183
- const { tx, amountIn } = await this.jupiterService.getJupiterSwapTx(params.fromAccountAddress, params.sourceToken.tokenAddress, amountToProcess.toFixed(0), exactOut);
184
+ const feePayer = (0, sol_1.getFeePayer)(new web3_js_1.PublicKey(params.fromAccountAddress), params.txFeeParams);
185
+ const { tx, amountIn } = await this.jupiterService.getJupiterSwapTx(params.fromAccountAddress, params.sourceToken.tokenAddress, amountToProcess.toFixed(0), exactOut, feePayer.toString());
184
186
  let newAmount;
185
187
  if (exactOut) {
186
188
  if (!amountIn) {
@@ -305,7 +307,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
305
307
  }
306
308
  return swapAndBridgeData;
307
309
  }
308
- async buildSwapAndBridgeAllbridgeTransaction(swapAndBridgeData) {
310
+ async buildSwapAndBridgeAllbridgeTransaction(swapAndBridgeData, txFeeParams) {
309
311
  const { bridge, vusdAmount, nonce, recipient, receiveToken, poolAccount, lockAccount, bridgeAuthority, userToken, bridgeTokenAccount, chainBridgeAccount, otherBridgeTokenAccount, userAccount, destinationChainId, mint, config, configAccountInfo, gasPrice, thisGasPrice, message, extraGasInstruction, } = swapAndBridgeData;
310
312
  const allbridgeMessengerProgramId = configAccountInfo.allbridgeMessengerProgramId;
311
313
  const messengerGasUsageAccount = await (0, accounts_1.getGasUsageAccount)(destinationChainId, allbridgeMessengerProgramId);
@@ -315,6 +317,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
315
317
  if (extraGasInstruction) {
316
318
  instructions.push(extraGasInstruction);
317
319
  }
320
+ const feePayer = (0, sol_1.getFeePayer)(userAccount, txFeeParams);
318
321
  const transaction = await bridge.methods
319
322
  .swapAndBridge({
320
323
  vusdAmount,
@@ -324,6 +327,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
324
327
  receiveToken,
325
328
  })
326
329
  .accounts({
330
+ payer: userAccount,
327
331
  mint,
328
332
  user: userAccount,
329
333
  config,
@@ -350,7 +354,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
350
354
  .transaction();
351
355
  const connection = (0, anchor_provider_1.buildAnchorProvider)(this.solanaRpcUrl, userAccount.toString()).connection;
352
356
  transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
353
- transaction.feePayer = userAccount;
357
+ transaction.feePayer = feePayer;
354
358
  return await this.convertToVersionedTransaction(transaction, connection);
355
359
  }
356
360
  async convertToVersionedTransaction(tx, connection) {
@@ -367,7 +371,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
367
371
  }).compileToV0Message([allbridgeTableAccount]);
368
372
  return new anchor_1.web3.VersionedTransaction(messageV0);
369
373
  }
370
- async buildSwapAndBridgeWormholeTransaction(swapAndBridgeData) {
374
+ async buildSwapAndBridgeWormholeTransaction(swapAndBridgeData, txFeeParams) {
371
375
  const { bridge, vusdAmount, nonce, recipient, receiveToken, poolAccount, lockAccount, bridgeAuthority, userToken, bridgeTokenAccount, chainBridgeAccount, otherBridgeTokenAccount, userAccount, destinationChainId, mint, config, configAccountInfo, gasPrice, thisGasPrice, message, extraGasInstruction, } = swapAndBridgeData;
372
376
  const wormholeProgramId = this.params.wormholeMessengerProgramId;
373
377
  const [whBridgeAccount] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("Bridge")], new web3_js_1.PublicKey(wormholeProgramId));
@@ -391,7 +395,9 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
391
395
  if (extraGasInstruction) {
392
396
  instructions.push(extraGasInstruction);
393
397
  }
398
+ const feePayer = (0, sol_1.getFeePayer)(userAccount, txFeeParams);
394
399
  const accounts = {
400
+ payer: userAccount,
395
401
  mint,
396
402
  user: userAccount,
397
403
  config,
@@ -433,7 +439,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
433
439
  .signers([messageAccount])
434
440
  .transaction();
435
441
  transaction.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;
436
- transaction.feePayer = userAccount;
442
+ transaction.feePayer = feePayer;
437
443
  return { transaction: await this.convertToVersionedTransaction(transaction, provider.connection), messageAccount };
438
444
  }
439
445
  async prepareSwapAndBridgeCctpData(txSendParams) {
@@ -474,7 +480,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
474
480
  }
475
481
  return swapAndBridgeData;
476
482
  }
477
- async buildSwapAndBridgeCctpTransaction(destinationChainSymbol, swapAndBridgeData) {
483
+ async buildSwapAndBridgeCctpTransaction(destinationChainSymbol, swapAndBridgeData, txFeeParams) {
478
484
  const { cctpBridge, cctpBridgeAccount, amount, recipient, receiveToken, bridgeAuthority, userToken, bridgeTokenAccount, chainBridgeAccount, userAccount, destinationChainId, mint, gasPrice, thisGasPrice, extraGasInstruction, provider, } = swapAndBridgeData;
479
485
  const domain = this.params.cctpParams.cctpDomains[destinationChainSymbol];
480
486
  const cctpTransmitterProgramIdAddress = this.params.cctpParams.cctpTransmitterProgramId;
@@ -491,6 +497,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
491
497
  }
492
498
  const messageSentEventDataKeypair = web3_js_1.Keypair.generate();
493
499
  const lockAccount = (0, accounts_1.getCctpLockAccount)(cctpBridge.programId, messageSentEventDataKeypair.publicKey);
500
+ const feePayer = (0, sol_1.getFeePayer)(userAccount, txFeeParams);
494
501
  const tx = await cctpBridge.methods
495
502
  .bridge({
496
503
  amount,
@@ -502,6 +509,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
502
509
  mint: mint,
503
510
  user: userAccount,
504
511
  cctpBridge: cctpBridgeAccount,
512
+ payer: userAccount,
505
513
  messageSentEventData: messageSentEventDataKeypair.publicKey,
506
514
  lock: lockAccount,
507
515
  cctpMessenger: cctpTokenMessengerMinter,
@@ -529,7 +537,7 @@ class SolanaBridgeService extends bridge_2.ChainBridgeService {
529
537
  .transaction();
530
538
  const connection = provider.connection;
531
539
  tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
532
- tx.feePayer = userAccount;
540
+ tx.feePayer = feePayer;
533
541
  return { transaction: await this.convertToVersionedTransaction(tx, connection), messageSentEventDataKeypair };
534
542
  }
535
543
  send(params) {