@allbridge/bridge-core-sdk 3.27.0-beta.1 → 3.27.0-beta.3

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 (56) 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.js +1 -0
  8. package/dist/src/client/core-api/api-client.js.map +1 -1
  9. package/dist/src/client/core-api/core-api-mapper.js +31 -0
  10. package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
  11. package/dist/src/client/core-api/core-api.model.d.ts +12 -2
  12. package/dist/src/client/core-api/core-api.model.js.map +1 -1
  13. package/dist/src/index.d.ts +6 -0
  14. package/dist/src/index.js +6 -0
  15. package/dist/src/index.js.map +1 -1
  16. package/dist/src/models/index.d.ts +12 -4
  17. package/dist/src/models/index.js +4 -0
  18. package/dist/src/models/index.js.map +1 -1
  19. package/dist/src/services/bridge/alg/index.js +52 -43
  20. package/dist/src/services/bridge/alg/index.js.map +1 -1
  21. package/dist/src/services/bridge/evm/index.d.ts +1 -0
  22. package/dist/src/services/bridge/evm/index.js +103 -33
  23. package/dist/src/services/bridge/evm/index.js.map +1 -1
  24. package/dist/src/services/bridge/index.d.ts +2 -2
  25. package/dist/src/services/bridge/index.js +10 -4
  26. package/dist/src/services/bridge/index.js.map +1 -1
  27. package/dist/src/services/bridge/models/bridge.model.d.ts +11 -4
  28. package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
  29. package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
  30. package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
  31. package/dist/src/services/bridge/srb/index.js +36 -28
  32. package/dist/src/services/bridge/srb/index.js.map +1 -1
  33. package/dist/src/services/bridge/stx/index.js +23 -14
  34. package/dist/src/services/bridge/stx/index.js.map +1 -1
  35. package/dist/src/services/bridge/sui/index.js +166 -138
  36. package/dist/src/services/bridge/sui/index.js.map +1 -1
  37. package/dist/src/services/bridge/trx/index.js +98 -70
  38. package/dist/src/services/bridge/trx/index.js.map +1 -1
  39. package/dist/src/services/bridge/utils.js +69 -8
  40. package/dist/src/services/bridge/utils.js.map +1 -1
  41. package/dist/src/services/models/abi/PayerWithAbr.d.ts +203 -0
  42. package/dist/src/services/models/abi/PayerWithAbr.js +266 -0
  43. package/dist/src/services/models/abi/PayerWithAbr.js.map +1 -0
  44. package/dist/src/services/token/index.js +2 -2
  45. package/dist/src/services/token/index.js.map +1 -1
  46. package/dist/src/services/token/models/token.model.d.ts +4 -4
  47. package/dist/src/services/token/models/token.model.js.map +1 -1
  48. package/dist/src/tokens-info/tokens-info.model.d.ts +17 -0
  49. package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
  50. package/dist/src/utils/utils.d.ts +2 -0
  51. package/dist/src/utils/utils.js +11 -0
  52. package/dist/src/utils/utils.js.map +1 -1
  53. package/dist/src/version.d.ts +1 -1
  54. package/dist/src/version.js +1 -1
  55. package/dist/src/version.js.map +1 -1
  56. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/bridge/index.ts"],"names":[],"mappings":";;;AAqIA,gCAwBC;AAED,sDAuEC;AAtOD,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,+BAAyC;AACzC,+BAA0C;AAuD1C,MAAa,oBAAoB;IAIrB;IACA;IACA;IACA;IANH,YAAY,CAA8B;IAEjD,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH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,EAAE,GAAG,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAChE,OAAO,IAAI,sBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACvD,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 { 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);\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 case ChainType.STX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new StxBridgeService(nodeRpcUrl, params, api);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/bridge/index.ts"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AAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,sBAAgB,CAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,sBAAgB,CAAC,iBAAiB,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;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAChE,OAAO,IAAI,sBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACvD,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, 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.
@@ -204,5 +210,6 @@ export interface TxSendParamsTyped<T> {
204
210
  */
205
211
  extraGasDest?: string;
206
212
  gasFeePaymentMethod: FeePaymentMethod;
213
+ abrExchangeRate?: string;
207
214
  }
208
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 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}\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"]}
@@ -7,9 +7,10 @@ const chain_enums_1 = require("../../../chains/chain.enums");
7
7
  const exceptions_1 = require("../../../exceptions");
8
8
  const index_1 = require("../../../index");
9
9
  const models_1 = require("../../../models");
10
+ const utils_1 = require("../../../utils/utils");
10
11
  const bridge_contract_1 = require("../../models/srb/bridge-contract");
11
12
  const models_2 = require("../models");
12
- const utils_1 = require("../utils");
13
+ const utils_2 = require("../utils");
13
14
  class SrbBridgeService extends models_2.ChainBridgeService {
14
15
  nodeRpcUrlsConfig;
15
16
  params;
@@ -22,7 +23,7 @@ class SrbBridgeService extends models_2.ChainBridgeService {
22
23
  this.api = api;
23
24
  }
24
25
  async buildRawTransactionSend(params) {
25
- const txSendParams = await (0, utils_1.prepareTxSendParams)(this.chainType, params, this.api);
26
+ const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
26
27
  return await this.buildRawTransactionSendFromParams(txSendParams);
27
28
  }
28
29
  async buildRawTransactionSendFromParams(params) {
@@ -33,36 +34,43 @@ class SrbBridgeService extends models_2.ChainBridgeService {
33
34
  }
34
35
  const contract = this.getContract(bridge_contract_1.BridgeContract, contractAddress, fromAccountAddress);
35
36
  let tx;
36
- if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
37
- tx = await contract.swap_and_bridge({
38
- sender: fromAccountAddress,
39
- token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
40
- amount: BigInt(amount),
41
- recipient: Buffer.from(toAccountAddress),
42
- destination_chain_id: +toChainId,
43
- receive_token: Buffer.from(toTokenAddress),
44
- nonce: (0, utils_1.getNonceBigInt)(),
45
- gas_amount: BigInt(0),
46
- fee_token_amount: BigInt(totalFee),
47
- });
48
- }
49
- else {
50
- tx = await contract.swap_and_bridge({
51
- sender: fromAccountAddress,
52
- token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
53
- amount: BigInt(amount),
54
- recipient: Buffer.from(toAccountAddress),
55
- destination_chain_id: +toChainId,
56
- receive_token: Buffer.from(toTokenAddress),
57
- nonce: (0, utils_1.getNonceBigInt)(),
58
- gas_amount: BigInt(totalFee),
59
- fee_token_amount: BigInt(0),
60
- });
37
+ switch (gasFeePaymentMethod) {
38
+ case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY:
39
+ tx = await contract.swap_and_bridge({
40
+ sender: fromAccountAddress,
41
+ token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
42
+ amount: BigInt(amount),
43
+ recipient: Buffer.from(toAccountAddress),
44
+ destination_chain_id: +toChainId,
45
+ receive_token: Buffer.from(toTokenAddress),
46
+ nonce: (0, utils_2.getNonceBigInt)(),
47
+ gas_amount: BigInt(totalFee),
48
+ fee_token_amount: BigInt(0),
49
+ });
50
+ break;
51
+ case models_1.FeePaymentMethod.WITH_STABLECOIN:
52
+ tx = await contract.swap_and_bridge({
53
+ sender: fromAccountAddress,
54
+ token: stellar_sdk_1.Address.contract(Buffer.from(fromTokenAddress)).toString(),
55
+ amount: BigInt(amount),
56
+ recipient: Buffer.from(toAccountAddress),
57
+ destination_chain_id: +toChainId,
58
+ receive_token: Buffer.from(toTokenAddress),
59
+ nonce: (0, utils_2.getNonceBigInt)(),
60
+ gas_amount: BigInt(0),
61
+ fee_token_amount: BigInt(totalFee),
62
+ });
63
+ break;
64
+ case models_1.FeePaymentMethod.WITH_ARB:
65
+ throw new exceptions_1.SdkError("SRB bridge does not support ARB0 payment method");
66
+ default: {
67
+ return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
68
+ }
61
69
  }
62
70
  return tx.toXDR();
63
71
  }
64
72
  async buildRawTransactionSwap(params) {
65
- const txSwapParams = (0, utils_1.prepareTxSwapParams)(this.chainType, params);
73
+ const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
66
74
  return await this.buildRawTransactionSwapFromParams(txSwapParams);
67
75
  }
68
76
  async buildRawTransactionSwapFromParams(params) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,mCAA6B;AAC7B,6DAA0D;AAE1D,oDAA8D;AAC9D,0CAAoE;AACpE,4CAAmD;AAGnD,sEAAkE;AAClE,sCAAyG;AACzG,oCAAoF;AAGpF,MAAa,gBAAiB,SAAQ,2BAAkB;IAI3C;IACA;IACA;IALX,SAAS,GAAkB,iBAAS,CAAC,GAAG,CAAC;IAEzC,YACW,iBAAoC,EACpC,MAA+B,EAC/B,GAAwB;QAEjC,KAAK,EAAE,CAAC;QAJC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,QAAG,GAAH,GAAG,CAAqB;IAGnC,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjF,OAAO,MAAM,IAAI,CAAC,iCAAiC,CAAC,YAAY,CAAC,CAAC;IAC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,EAAE,gBAAgB;YAC3B,kBAAkB,EAAE,MAAM,CAAC,oBAAoB,CAAC;SACjD,CAAC,CACH,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,6DAA6D;IAC7D,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;IAEO,WAAW,CAAI,QAAgD,EAAE,OAAe,EAAE,MAAe;QACvG,MAAM,MAAM,GAA0B;YACpC,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,yBAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AA1GD,4CA0GC","sourcesContent":["import { Address, contract } from \"@stellar/stellar-sdk\";\nimport { Big } from \"big.js\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainType } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeContract } from \"../../models/srb/bridge-contract\";\nimport { ChainBridgeService, SendParams, SwapParams, TxSendParamsSrb, TxSwapParamsSol } from \"../models\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\n\nexport class SrbBridgeService extends ChainBridgeService {\n chainType: ChainType.SRB = ChainType.SRB;\n\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions,\n readonly api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return await this.buildRawTransactionSendFromParams(txSendParams);\n }\n\n async buildRawTransactionSendFromParams(params: TxSendParamsSrb): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n let tx;\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(0),\n fee_token_amount: BigInt(totalFee),\n });\n } else {\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(totalFee),\n fee_token_amount: BigInt(0),\n });\n }\n return tx.toXDR();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsSol): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n return (\n await contract.swap({\n sender: fromAccountAddress,\n amount: BigInt(amount),\n token: Address.contract(Buffer.from(fromTokenAddress)).toBuffer(),\n receive_token: Buffer.from(toTokenAddress),\n recipient: toAccountAddress,\n receive_amount_min: BigInt(minimumReceiveAmount),\n })\n ).toXDR();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n send(params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n private getContract<T>(contract: new (args: ContractClientOptions) => T, address: string, sender?: string): T {\n const config: ContractClientOptions = {\n publicKey: sender,\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new contract(config);\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,mCAA6B;AAC7B,6DAA0D;AAE1D,oDAAwE;AACxE,0CAAoE;AACpE,4CAAmD;AACnD,gDAAmD;AAGnD,sEAAkE;AAClE,sCAAyG;AACzG,oCAAoF;AAGpF,MAAa,gBAAiB,SAAQ,2BAAkB;IAI3C;IACA;IACA;IALX,SAAS,GAAkB,iBAAS,CAAC,GAAG,CAAC;IAEzC,YACW,iBAAoC,EACpC,MAA+B,EAC/B,GAAwB;QAEjC,KAAK,EAAE,CAAC;QAJC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,QAAG,GAAH,GAAG,CAAqB;IAGnC,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjF,OAAO,MAAM,IAAI,CAAC,iCAAiC,CAAC,YAAY,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,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AAkB;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,KAAK,EAAE,qBAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,QAAQ,EAAE;YACjE,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC;YAC1C,SAAS,EAAE,gBAAgB;YAC3B,kBAAkB,EAAE,MAAM,CAAC,oBAAoB,CAAC;SACjD,CAAC,CACH,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,6DAA6D;IAC7D,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;IAEO,WAAW,CAAI,QAAgD,EAAE,OAAe,EAAE,MAAe;QACvG,MAAM,MAAM,GAA0B;YACpC,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,yBAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AAnHD,4CAmHC","sourcesContent":["import { Address, contract } from \"@stellar/stellar-sdk\";\nimport { Big } from \"big.js\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainType } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeContract } from \"../../models/srb/bridge-contract\";\nimport { ChainBridgeService, SendParams, SwapParams, TxSendParamsSrb, TxSwapParamsSol } from \"../models\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\n\nexport class SrbBridgeService extends ChainBridgeService {\n chainType: ChainType.SRB = ChainType.SRB;\n\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions,\n readonly api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return await this.buildRawTransactionSendFromParams(txSendParams);\n }\n\n async buildRawTransactionSendFromParams(params: TxSendParamsSrb): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n let tx;\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(totalFee),\n fee_token_amount: BigInt(0),\n });\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n tx = await contract.swap_and_bridge({\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(0),\n fee_token_amount: BigInt(totalFee),\n });\n break;\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"SRB bridge does not support ARB0 payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return tx.toXDR();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsSol): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n return (\n await contract.swap({\n sender: fromAccountAddress,\n amount: BigInt(amount),\n token: Address.contract(Buffer.from(fromTokenAddress)).toBuffer(),\n receive_token: Buffer.from(toTokenAddress),\n recipient: toAccountAddress,\n receive_amount_min: BigInt(minimumReceiveAmount),\n })\n ).toXDR();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n send(params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n private getContract<T>(contract: new (args: ContractClientOptions) => T, address: string, sender?: string): T {\n const config: ContractClientOptions = {\n publicKey: sender,\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new contract(config);\n }\n}\n"]}
@@ -7,11 +7,12 @@ const transactions_1 = require("@stacks/transactions");
7
7
  const chain_enums_1 = require("../../../chains/chain.enums");
8
8
  const exceptions_1 = require("../../../exceptions");
9
9
  const models_1 = require("../../../models");
10
+ const utils_1 = require("../../../utils/utils");
10
11
  const clarigen_types_1 = require("../../models/stx/clarigen-types");
11
12
  const get_token_name_1 = require("../../utils/stx/get-token-name");
12
13
  const post_conditions_1 = require("../../utils/stx/post-conditions");
13
14
  const models_2 = require("../models");
14
- const utils_1 = require("../utils");
15
+ const utils_2 = require("../utils");
15
16
  class StxBridgeService extends models_2.ChainBridgeService {
16
17
  nodeRpcUrl;
17
18
  params;
@@ -34,7 +35,7 @@ class StxBridgeService extends models_2.ChainBridgeService {
34
35
  throw new exceptions_1.MethodNotSupportedError();
35
36
  }
36
37
  async buildRawTransactionSend(params) {
37
- const txSendParams = await (0, utils_1.prepareTxSendParams)(this.chainType, params, this.api);
38
+ const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
38
39
  const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;
39
40
  const amount = BigInt(txSendParams.amount);
40
41
  const postFungiblePostCondition = (0, post_conditions_1.getFungiblePostCondition)(amount, "lte", params.fromAccountAddress, params.sourceToken.tokenAddress, (0, get_token_name_1.getTokenName)(params.sourceToken));
@@ -44,18 +45,26 @@ class StxBridgeService extends models_2.ChainBridgeService {
44
45
  if (txSendParams.extraGas) {
45
46
  totalFee = totalFee + BigInt(txSendParams.extraGas);
46
47
  }
47
- const isPayWithStable = txSendParams.gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN;
48
48
  let feeTokenAmount;
49
49
  let feeNativeAmount;
50
- if (isPayWithStable) {
51
- feeTokenAmount = totalFee;
52
- feeNativeAmount = 0n;
53
- }
54
- else {
55
- feeTokenAmount = 0n;
56
- feeNativeAmount = totalFee;
57
- const postUserStxPostCondition = (0, post_conditions_1.getStxPostCondition)(totalFee, "lte", params.fromAccountAddress);
58
- postConditions.push(postUserStxPostCondition);
50
+ switch (txSendParams.gasFeePaymentMethod) {
51
+ case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
52
+ feeTokenAmount = 0n;
53
+ feeNativeAmount = totalFee;
54
+ const postUserStxPostCondition = (0, post_conditions_1.getStxPostCondition)(totalFee, "lte", params.fromAccountAddress);
55
+ postConditions.push(postUserStxPostCondition);
56
+ break;
57
+ }
58
+ case models_1.FeePaymentMethod.WITH_STABLECOIN: {
59
+ feeTokenAmount = totalFee;
60
+ feeNativeAmount = 0n;
61
+ break;
62
+ }
63
+ case models_1.FeePaymentMethod.WITH_ARB:
64
+ throw new exceptions_1.SdkError("STX bridge does not support ARB0 payment method");
65
+ default: {
66
+ return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
67
+ }
59
68
  }
60
69
  const [contractPrincipal] = (0, transactions_1.parseContractId)(bridgeAddress);
61
70
  const bridge = (0, core_1.contractFactory)(clarigen_types_1.stacksContracts.bridge, bridgeAddress);
@@ -68,7 +77,7 @@ class StxBridgeService extends models_2.ChainBridgeService {
68
77
  recipient: Uint8Array.from(toAccountAddress),
69
78
  destinationChainId: toChainId,
70
79
  receiveToken: Uint8Array.from(toTokenAddress),
71
- nonce: Uint8Array.from((0, utils_1.getNonce)()),
80
+ nonce: Uint8Array.from((0, utils_2.getNonce)()),
72
81
  messengerId: messenger,
73
82
  feeNativeAmount: feeNativeAmount,
74
83
  feeTokenAmount: feeTokenAmount,
@@ -90,7 +99,7 @@ class StxBridgeService extends models_2.ChainBridgeService {
90
99
  return transaction.serialize();
91
100
  }
92
101
  async buildRawTransactionSwap(params) {
93
- const txSwapParams = (0, utils_1.prepareTxSwapParams)(this.chainType, params);
102
+ const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
94
103
  const amount = BigInt(txSwapParams.amount);
95
104
  const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);
96
105
  const bridgeAddress = params.sourceToken.bridgeAddress;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/stx/index.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AACjE,6CAAgD;AAChD,uDAQ8B;AAC9B,6DAAwD;AAExD,oDAA8D;AAE9D,4CAAmD;AAEnD,oEAA+E;AAC/E,mEAA8D;AAC9D,qEAAgG;AAChG,sCAAuE;AACvE,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAM7C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AC9D,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;CACF;AA/ID,4CA+IC","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 } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\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\n const postFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n const postStxPostCondition = getStxPostCondition(0, \"gte\", params.sourceToken.bridgeAddress);\n const postConditions: PostCondition[] = [postFungiblePostCondition, postStxPostCondition];\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n\n const isPayWithStable = txSendParams.gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN;\n\n let feeTokenAmount: bigint;\n let feeNativeAmount: bigint;\n if (isPayWithStable) {\n feeTokenAmount = totalFee;\n feeNativeAmount = 0n;\n } else {\n feeTokenAmount = 0n;\n feeNativeAmount = totalFee;\n const postUserStxPostCondition = getStxPostCondition(totalFee, \"lte\", params.fromAccountAddress);\n postConditions.push(postUserStxPostCondition);\n }\n\n const [contractPrincipal] = parseContractId(bridgeAddress as ContractIdString);\n\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.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\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 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,yCAAiE;AACjE,6CAAgD;AAChD,uDAQ8B;AAC9B,6DAAwD;AAExD,oDAAwE;AAExE,4CAAmD;AACnD,gDAAmD;AAEnD,oEAA+E;AAC/E,mEAA8D;AAC9D,qEAAgG;AAChG,sCAAuE;AACvE,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAM7C;IACA;IACA;IAPT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;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;YACrB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,cAAc,EAAE,CAAC,qBAAqB,EAAE,+BAA+B,CAAC;YACxE,iBAAiB,EAAE,gCAAiB,CAAC,IAAI;SAC1C,CAAC;QACF,MAAM,WAAW,GAAG,MAAM,IAAA,uCAAwB,EAAC,SAAS,CAAC,CAAC;QAC9D,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;CACF;AAvJD,4CAuJC","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 } 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\n const postFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n const postStxPostCondition = getStxPostCondition(0, \"gte\", params.sourceToken.bridgeAddress);\n const postConditions: PostCondition[] = [postFungiblePostCondition, postStxPostCondition];\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_ARB:\n throw new SdkError(\"STX bridge does not support ARB0 payment method\");\n default: {\n return assertNever(txSendParams.gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n const [contractPrincipal] = parseContractId(bridgeAddress as ContractIdString);\n\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.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\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 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"]}