@allbridge/bridge-core-sdk 3.23.0-beta.1 → 3.23.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +8 -8
  2. package/dist/browser/index.js +1 -1
  3. package/dist/browser/index.js.map +4 -4
  4. package/dist/cjs/index.js +1 -1
  5. package/dist/cjs/index.js.map +4 -4
  6. package/dist/esm/index.js +1 -1
  7. package/dist/esm/index.js.map +4 -4
  8. package/dist/src/client/core-api/api-client-caching.js +1 -1
  9. package/dist/src/client/core-api/api-client-caching.js.map +1 -1
  10. package/dist/src/client/core-api/api-client.js +6 -0
  11. package/dist/src/client/core-api/api-client.js.map +1 -1
  12. package/dist/src/client/core-api/core-api-mapper.js +3 -0
  13. package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
  14. package/dist/src/client/core-api/core-api.model.d.ts +8 -2
  15. package/dist/src/client/core-api/core-api.model.js +2 -0
  16. package/dist/src/client/core-api/core-api.model.js.map +1 -1
  17. package/dist/src/exceptions/exceptions.d.ts +4 -0
  18. package/dist/src/exceptions/exceptions.js +8 -1
  19. package/dist/src/exceptions/exceptions.js.map +1 -1
  20. package/dist/src/index.d.ts +10 -17
  21. package/dist/src/index.js +34 -26
  22. package/dist/src/index.js.map +1 -1
  23. package/dist/src/models/index.d.ts +1 -0
  24. package/dist/src/models/index.js.map +1 -1
  25. package/dist/src/services/bridge/evm/index.d.ts +3 -1
  26. package/dist/src/services/bridge/evm/index.js +46 -14
  27. package/dist/src/services/bridge/evm/index.js.map +1 -1
  28. package/dist/src/services/bridge/index.d.ts +1 -1
  29. package/dist/src/services/bridge/index.js +26 -19
  30. package/dist/src/services/bridge/index.js.map +1 -1
  31. package/dist/src/services/bridge/models/bridge.model.d.ts +4 -0
  32. package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
  33. package/dist/src/services/bridge/sol/index.d.ts +2 -2
  34. package/dist/src/services/bridge/sol/index.js +7 -4
  35. package/dist/src/services/bridge/sol/index.js.map +1 -1
  36. package/dist/src/services/bridge/sui/index.js +2 -0
  37. package/dist/src/services/bridge/sui/index.js.map +1 -1
  38. package/dist/src/services/bridge/trx/index.d.ts +1 -1
  39. package/dist/src/services/bridge/trx/index.js +84 -53
  40. package/dist/src/services/bridge/trx/index.js.map +1 -1
  41. package/dist/src/services/bridge/utils.d.ts +2 -2
  42. package/dist/src/services/bridge/utils.js +64 -36
  43. package/dist/src/services/bridge/utils.js.map +1 -1
  44. package/dist/src/services/index.d.ts +13 -7
  45. package/dist/src/services/index.js +129 -48
  46. package/dist/src/services/index.js.map +1 -1
  47. package/dist/src/services/models/abi/OftBridge.d.ts +386 -0
  48. package/dist/src/services/models/abi/OftBridge.js +500 -0
  49. package/dist/src/services/models/abi/OftBridge.js.map +1 -0
  50. package/dist/src/tokens-info/tokens-info.model.d.ts +14 -0
  51. package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
  52. package/dist/src/version.d.ts +1 -1
  53. package/dist/src/version.js +1 -1
  54. package/dist/src/version.js.map +1 -1
  55. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/trx/index.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAE7B,6DAAwD;AAExD,oDAA+C;AAC/C,4CAA+F;AAE/F,yCAAqD;AAErD,6CAAsD;AACtD,oCAAoF;AAEpF,MAAa,iBAAkB,SAAQ,2BAAkB;IAI9C;IACA;IAJT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IAEzC,YACS,OAAgB,EAChB,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAHD,YAAO,GAAP,OAAO,CAAS;QAChB,QAAG,GAAH,GAAG,CAAqB;IAGjC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAkB;QAC3B,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,I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EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE;oBACjC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE;oBACnC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE;iBAC9B,CAAC;gBACF,KAAK,GAAG,QAAQ,CAAC;YACnB,CAAC;YACD,eAAe,GAAG,8EAA8E,CAAC;QACnG,CAAC;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IAC3G,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAC/B,eAAuB,EACvB,eAAuB,EACvB,UAA0C,EAC1C,KAAa,EACb,WAAmB;QAEnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,oBAAoB,CAClF,eAAe,EACf,eAAe,EACf;YACE,SAAS,EAAE,CAAC,KAAK;SAClB,EACD,UAAU,EACV,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,qBAAQ,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,iBAAiB,CAAC,WAAW,CAAC;IACvC,CAAC;CACF;AA/ID,8CA+IC","sourcesContent":["import { Big } from \"big.js\";\nimport { TronWeb } from \"tronweb\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { FeePaymentMethod, Messenger, SwapParams, TransactionResponse } from \"../../../models\";\nimport { RawTransaction, SmartContractMethodParameter } from \"../../models\";\nimport { sendRawTransaction } from \"../../utils/trx\";\nimport { SendParams, TxSendParamsTrx, TxSwapParamsTrx } from \"../models\";\nimport { ChainBridgeService } from \"../models/bridge\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class TronBridgeService extends ChainBridgeService {\n chainType: ChainType.TRX = ChainType.TRX;\n\n constructor(\n public tronWeb: TronWeb,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async send(params: SendParams): Promise<TransactionResponse> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const rawTransaction = await this.buildRawTransactionSendFromParams(txSendParams);\n return await sendRawTransaction(this.tronWeb, 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: TxSwapParamsTrx): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n\n const parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"address\", value: toAccountAddress },\n { type: \"uint256\", value: minimumReceiveAmount },\n ];\n const methodSignature = \"swap(uint256,bytes32,bytes32,address,uint256)\";\n return this.buildRawTransaction(contractAddress, methodSignature, parameters, \"0\", fromAccountAddress);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return this.buildRawTransactionSendFromParams(txSendParams);\n }\n\n async buildRawTransactionSendFromParams(params: TxSendParamsTrx): Promise<RawTransaction> {\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 } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n const nonce = getNonceBigInt().toString();\n let parameters;\n let value: string;\n let methodSignature: string;\n if (messenger == Messenger.CCTP || messenger == Messenger.CCTP_V2) {\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: totalFee },\n ];\n value = \"0\";\n } else {\n parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: 0 },\n ];\n value = totalFee;\n }\n methodSignature = \"bridge(uint256,bytes32,uint256,uint256)\";\n } else {\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n parameters = [\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"uint256\", value: nonce },\n { type: \"uint8\", value: messenger },\n { type: \"uint256\", value: totalFee },\n ];\n value = \"0\";\n } else {\n parameters = [\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"uint256\", value: nonce },\n { type: \"uint8\", value: messenger },\n { type: \"uint256\", value: 0 },\n ];\n value = totalFee;\n }\n methodSignature = \"swapAndBridge(bytes32,uint256,bytes32,uint256,bytes32,uint256,uint8,uint256)\";\n }\n return this.buildRawTransaction(contractAddress, methodSignature, parameters, value, fromAccountAddress);\n }\n\n private async buildRawTransaction(\n contractAddress: string,\n methodSignature: string,\n parameters: SmartContractMethodParameter[],\n value: string,\n fromAddress: string\n ): Promise<RawTransaction> {\n const transactionObject = await this.tronWeb.transactionBuilder.triggerSmartContract(\n contractAddress,\n methodSignature,\n {\n callValue: +value,\n },\n parameters,\n fromAddress\n );\n if (!transactionObject?.result?.result) {\n throw new SdkError(\"Unknown error: \" + JSON.stringify(transactionObject, null, 2));\n }\n return transactionObject.transaction;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/trx/index.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAE7B,6DAAwD;AAExD,oDAA+C;AAC/C,4CAA+F;AAE/F,yCAAqD;AAErD,6CAAsD;AACtD,oCAAoF;AAEpF,MAAa,iBAAkB,SAAQ,2BAAkB;IAI9C;IACA;IAJT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IAEzC,YACS,OAAgB,EAChB,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAHD,YAAO,GAAP,OAAO,CAAS;QAChB,QAAG,GAAH,GAAG,CAAqB;IAGjC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAkB;QAC3B,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjF,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,iCAAiC,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC1F,OAAO,MAAM,IAAA,wBAAkB,EAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACjE,OAAO,MAAM,IAAI,CAAC,iCAAiC,CAAC,YAAY,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,iCAAiC,CAAC,MAAuB;QAC7D,MAAM,EACJ,MAAM,EACN,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,GACrB,GAAG,MAAM,CA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EACvB,eAAuB,EACvB,UAA0C,EAC1C,KAAa,EACb,WAAmB;QAEnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,oBAAoB,CAClF,eAAe,EACf,eAAe,EACf;YACE,SAAS,EAAE,CAAC,KAAK;SAClB,EACD,UAAU,EACV,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,qBAAQ,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,iBAAiB,CAAC,WAAW,CAAC;IACvC,CAAC;CACF;AA/KD,8CA+KC","sourcesContent":["import { Big } from \"big.js\";\nimport { TronWeb } from \"tronweb\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { FeePaymentMethod, Messenger, SwapParams, TransactionResponse } from \"../../../models\";\nimport { RawTransaction, SmartContractMethodParameter } from \"../../models\";\nimport { sendRawTransaction } from \"../../utils/trx\";\nimport { SendParams, TxSendParamsTrx, TxSwapParamsTrx } from \"../models\";\nimport { ChainBridgeService } from \"../models/bridge\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class TronBridgeService extends ChainBridgeService {\n chainType: ChainType.TRX = ChainType.TRX;\n\n constructor(\n public tronWeb: TronWeb,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async send(params: SendParams): Promise<TransactionResponse> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const rawTransaction = await this.buildRawTransactionSendFromParams(params, txSendParams);\n return await sendRawTransaction(this.tronWeb, 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: TxSwapParamsTrx): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n\n const parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"address\", value: toAccountAddress },\n { type: \"uint256\", value: minimumReceiveAmount },\n ];\n const methodSignature = \"swap(uint256,bytes32,bytes32,address,uint256)\";\n return this.buildRawTransaction(contractAddress, methodSignature, parameters, \"0\", fromAccountAddress);\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return this.buildRawTransactionSendFromParams(params, txSendParams);\n }\n\n async buildRawTransactionSendFromParams(sendParams: SendParams, params: TxSendParamsTrx): Promise<RawTransaction> {\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 } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n const nonce = getNonceBigInt().toString();\n let parameters;\n let value: string;\n let methodSignature: string;\n switch (messenger) {\n case Messenger.CCTP:\n case Messenger.CCTP_V2:\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: totalFee },\n ];\n value = \"0\";\n } else {\n parameters = [\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: 0 },\n ];\n value = totalFee;\n }\n methodSignature = \"bridge(uint256,bytes32,uint256,uint256)\";\n break;\n case Messenger.OFT:\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n parameters = [\n { type: \"address\", value: sendParams.sourceToken.tokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: totalFee },\n { type: \"uint256\", value: extraGasDest ?? \"0\" },\n { type: \"uint256\", value: \"10\" },\n ];\n value = \"0\";\n } else {\n parameters = [\n { type: \"address\", value: sendParams.sourceToken.tokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"uint256\", value: 0 },\n { type: \"uint256\", value: extraGasDest ?? \"0\" },\n { type: \"uint256\", value: \"10\" },\n ];\n value = totalFee;\n }\n methodSignature = \"bridge(address,uint256,bytes32,uint256,uint256,uint256,uint256)\";\n break;\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n parameters = [\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"uint256\", value: nonce },\n { type: \"uint8\", value: messenger },\n { type: \"uint256\", value: totalFee },\n ];\n value = \"0\";\n } else {\n parameters = [\n { type: \"bytes32\", value: fromTokenAddress },\n { type: \"uint256\", value: amount },\n { type: \"bytes32\", value: toAccountAddress },\n { type: \"uint256\", value: toChainId },\n { type: \"bytes32\", value: toTokenAddress },\n { type: \"uint256\", value: nonce },\n { type: \"uint8\", value: messenger },\n { type: \"uint256\", value: 0 },\n ];\n value = totalFee;\n }\n methodSignature = \"swapAndBridge(bytes32,uint256,bytes32,uint256,bytes32,uint256,uint8,uint256)\";\n break;\n }\n return this.buildRawTransaction(contractAddress, methodSignature, parameters, value, fromAccountAddress);\n }\n\n private async buildRawTransaction(\n contractAddress: string,\n methodSignature: string,\n parameters: SmartContractMethodParameter[],\n value: string,\n fromAddress: string\n ): Promise<RawTransaction> {\n const transactionObject = await this.tronWeb.transactionBuilder.triggerSmartContract(\n contractAddress,\n methodSignature,\n {\n callValue: +value,\n },\n parameters,\n fromAddress\n );\n if (!transactionObject?.result?.result) {\n throw new SdkError(\"Unknown error: \" + JSON.stringify(transactionObject, null, 2));\n }\n return transactionObject.transaction;\n }\n}\n"]}
@@ -23,6 +23,6 @@ export declare function prepareTxSendParams(bridgeChainType: ChainType.EVM | Cha
23
23
  export declare function prepareTxSendParams(bridgeChainType: ChainType.TRX, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsTrx>;
24
24
  export declare function prepareTxSendParams(bridgeChainType: ChainType.SOLANA | ChainType.SRB, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParamsSol | TxSendParamsSrb>;
25
25
  export declare function prepareTxSendParams(bridgeChainType: ChainType, params: SendParams, api: AllbridgeCoreClient): Promise<TxSendParams>;
26
- export declare function getGasFeeOptions(sourceAllbridgeChainId: number, sourceChainType: ChainType, destinationAllbridgeChainId: number, sourceChainTokenDecimals: number, messenger: Messenger, api: AllbridgeCoreClient): Promise<GasFeeOptions>;
27
- export declare function getExtraGasMaxLimits(sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, api: AllbridgeCoreClient): Promise<ExtraGasMaxLimitResponse>;
26
+ export declare function getGasFeeOptions(sourceChainToken: TokenWithChainDetails, destinationAllbridgeChainId: number, messenger: Messenger, api: AllbridgeCoreClient): Promise<GasFeeOptions>;
27
+ export declare function getExtraGasMaxLimits(sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger, api: AllbridgeCoreClient): Promise<ExtraGasMaxLimitResponse>;
28
28
  export declare function isSendParams(params: SwapParams | SendParams): params is SendParams;
@@ -177,20 +177,31 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
177
177
  txSendParams.gasFeePaymentMethod = models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY;
178
178
  }
179
179
  const sourceToken = params.sourceToken;
180
- if (params.messenger === core_api_model_1.Messenger.CCTP) {
181
- if (!sourceToken.cctpAddress || !params.destinationToken.cctpAddress) {
182
- throw new exceptions_1.CCTPDoesNotSupportedError("Such route does not support CCTP protocol");
183
- }
184
- txSendParams.contractAddress = sourceToken.cctpAddress;
185
- }
186
- else if (params.messenger === core_api_model_1.Messenger.CCTP_V2) {
187
- if (!sourceToken.cctpV2Address || !params.destinationToken.cctpV2Address) {
188
- throw new exceptions_1.CCTPDoesNotSupportedError("Such route does not support CCTP V2 protocol");
189
- }
190
- txSendParams.contractAddress = sourceToken.cctpV2Address;
191
- }
192
- else {
193
- txSendParams.contractAddress = sourceToken.bridgeAddress;
180
+ switch (params.messenger) {
181
+ case core_api_model_1.Messenger.CCTP:
182
+ if (!sourceToken.cctpAddress || !params.destinationToken.cctpAddress) {
183
+ throw new exceptions_1.CCTPDoesNotSupportedError("Such route does not support CCTP protocol");
184
+ }
185
+ txSendParams.contractAddress = sourceToken.cctpAddress;
186
+ break;
187
+ case core_api_model_1.Messenger.CCTP_V2:
188
+ if (!sourceToken.cctpV2Address || !params.destinationToken.cctpV2Address) {
189
+ throw new exceptions_1.CCTPDoesNotSupportedError("Such route does not support CCTP V2 protocol");
190
+ }
191
+ txSendParams.contractAddress = sourceToken.cctpV2Address;
192
+ break;
193
+ case core_api_model_1.Messenger.OFT:
194
+ if (!sourceToken.oftBridgeAddress ||
195
+ !params.destinationToken.oftBridgeAddress ||
196
+ sourceToken.oftId !== params.destinationToken.oftId) {
197
+ throw new exceptions_1.OFTDoesNotSupportedError("Such route does not support OFT protocol");
198
+ }
199
+ txSendParams.contractAddress = sourceToken.oftBridgeAddress;
200
+ break;
201
+ case core_api_model_1.Messenger.ALLBRIDGE:
202
+ case core_api_model_1.Messenger.WORMHOLE:
203
+ txSendParams.contractAddress = sourceToken.bridgeAddress;
204
+ break;
194
205
  }
195
206
  txSendParams.messenger = params.messenger;
196
207
  txSendParams.fromAccountAddress = params.fromAccountAddress;
@@ -198,7 +209,7 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
198
209
  //Fee
199
210
  let { fee, feeFormat } = params;
200
211
  if (!fee) {
201
- const gasFeeOptions = await getGasFeeOptions(txSendParams.fromChainId, params.sourceToken.chainType, txSendParams.toChainId, sourceToken.decimals, txSendParams.messenger, api);
212
+ const gasFeeOptions = await getGasFeeOptions(params.sourceToken, txSendParams.toChainId, txSendParams.messenger, api);
202
213
  const gasFeeOption = gasFeeOptions[txSendParams.gasFeePaymentMethod];
203
214
  if (!gasFeeOption) {
204
215
  throw new exceptions_1.InvalidGasFeePaymentOptionError();
@@ -222,20 +233,35 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
222
233
  //ExtraGas
223
234
  const { extraGas, extraGasFormat } = params;
224
235
  if (extraGas && +extraGas > 0) {
225
- if (extraGasFormat == models_1.AmountFormat.FLOAT) {
226
- switch (txSendParams.gasFeePaymentMethod) {
227
- case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY:
228
- txSendParams.extraGas = (0, calculation_1.convertFloatAmountToInt)(extraGas, chains_1.Chains.getChainDecimalsByType(sourceToken.chainType)).toFixed(0);
229
- break;
230
- case models_1.FeePaymentMethod.WITH_STABLECOIN:
231
- txSendParams.extraGas = (0, calculation_1.convertFloatAmountToInt)(extraGas, sourceToken.decimals).toFixed(0);
232
- break;
233
- }
236
+ const extraGasLimits = await getExtraGasMaxLimits(sourceToken, params.destinationToken, txSendParams.messenger, api);
237
+ let extraGasDecimals;
238
+ let extraGasDestRate;
239
+ switch (txSendParams.gasFeePaymentMethod) {
240
+ case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY:
241
+ extraGasDecimals = chains_1.Chains.getChainDecimalsByType(sourceToken.chainType);
242
+ extraGasDestRate = (0, big_js_1.Big)(extraGasLimits.exchangeRate);
243
+ break;
244
+ case models_1.FeePaymentMethod.WITH_STABLECOIN:
245
+ extraGasDecimals = sourceToken.decimals;
246
+ extraGasDestRate = (0, big_js_1.Big)(extraGasLimits.exchangeRate).div(extraGasLimits.sourceNativeTokenPrice);
247
+ break;
234
248
  }
235
- else {
236
- txSendParams.extraGas = extraGas;
249
+ switch (extraGasFormat ?? models_1.AmountFormat.INT) {
250
+ case models_1.AmountFormat.FLOAT: {
251
+ txSendParams.extraGas = (0, calculation_1.convertFloatAmountToInt)(extraGas, extraGasDecimals).toFixed(0);
252
+ const extraGasDestFloat = extraGasDestRate.mul(extraGas);
253
+ txSendParams.extraGasDest = (0, calculation_1.convertFloatAmountToInt)(extraGasDestFloat, chains_1.Chains.getChainDecimalsByType(params.destinationToken.chainType)).toFixed(0, big_js_1.Big.roundDown);
254
+ break;
255
+ }
256
+ case models_1.AmountFormat.INT: {
257
+ txSendParams.extraGas = extraGas;
258
+ const extraGasFloat = (0, calculation_1.convertIntAmountToFloat)(txSendParams.extraGas, chains_1.Chains.getChainDecimalsByType(sourceToken.chainType));
259
+ const extraGasDestFloat = extraGasDestRate.mul(extraGasFloat);
260
+ txSendParams.extraGasDest = (0, calculation_1.convertFloatAmountToInt)(extraGasDestFloat, chains_1.Chains.getChainDecimalsByType(params.destinationToken.chainType)).toFixed(0, big_js_1.Big.roundDown);
261
+ break;
262
+ }
237
263
  }
238
- await validateExtraGasNotExceeded(txSendParams.extraGas, txSendParams.gasFeePaymentMethod, sourceToken, params.destinationToken, api);
264
+ validateExtraGasNotExceeded(txSendParams.extraGas, txSendParams.gasFeePaymentMethod, extraGasLimits);
239
265
  }
240
266
  if (bridgeChainType !== models_1.ChainType.SUI) {
241
267
  txSendParams.fromTokenAddress = formatAddress(txSendParams.fromTokenAddress, bridgeChainType, bridgeChainType);
@@ -255,29 +281,30 @@ function validateAmountEnough(amountInt, decimals, feeInt, extraGasInt) {
255
281
  throw new exceptions_1.AmountNotEnoughError(`Amount not enough to pay fee, ${(0, calculation_1.convertIntAmountToFloat)((0, big_js_1.Big)(amountTotal).minus(1).neg(), decimals).toFixed()} stables is missing`);
256
282
  }
257
283
  }
258
- async function getGasFeeOptions(sourceAllbridgeChainId, sourceChainType, destinationAllbridgeChainId, sourceChainTokenDecimals, messenger, api) {
284
+ async function getGasFeeOptions(sourceChainToken, destinationAllbridgeChainId, messenger, api) {
259
285
  const transactionCostResponse = await api.getReceiveTransactionCost({
260
- sourceChainId: sourceAllbridgeChainId,
286
+ sourceChainId: sourceChainToken.allbridgeChainId,
261
287
  destinationChainId: destinationAllbridgeChainId,
262
288
  messenger,
289
+ sourceToken: sourceChainToken.tokenAddress,
263
290
  });
264
291
  const gasFeeOptions = {
265
292
  [models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY]: {
266
293
  [models_1.AmountFormat.INT]: transactionCostResponse.fee,
267
- [models_1.AmountFormat.FLOAT]: (0, calculation_1.convertIntAmountToFloat)(transactionCostResponse.fee, chains_1.Chains.getChainDecimalsByType(sourceChainType)).toFixed(),
294
+ [models_1.AmountFormat.FLOAT]: (0, calculation_1.convertIntAmountToFloat)(transactionCostResponse.fee, chains_1.Chains.getChainDecimalsByType(sourceChainToken.chainType)).toFixed(),
268
295
  },
296
+ adminFeeShareWithExtras: transactionCostResponse.adminFeeShareWithExtras,
269
297
  };
270
298
  if (transactionCostResponse.sourceNativeTokenPrice) {
271
- const gasFeeIntWithStables = (0, calculation_1.convertAmountPrecision)(new big_js_1.Big(transactionCostResponse.fee).mul(transactionCostResponse.sourceNativeTokenPrice), chains_1.Chains.getChainDecimalsByType(sourceChainType), sourceChainTokenDecimals).toFixed(0, big_js_1.Big.roundUp);
299
+ const gasFeeIntWithStables = (0, calculation_1.convertAmountPrecision)(new big_js_1.Big(transactionCostResponse.fee).mul(transactionCostResponse.sourceNativeTokenPrice), chains_1.Chains.getChainDecimalsByType(sourceChainToken.chainType), sourceChainToken.decimals).toFixed(0, big_js_1.Big.roundUp);
272
300
  gasFeeOptions[models_1.FeePaymentMethod.WITH_STABLECOIN] = {
273
301
  [models_1.AmountFormat.INT]: gasFeeIntWithStables,
274
- [models_1.AmountFormat.FLOAT]: (0, calculation_1.convertIntAmountToFloat)(gasFeeIntWithStables, sourceChainTokenDecimals).toFixed(),
302
+ [models_1.AmountFormat.FLOAT]: (0, calculation_1.convertIntAmountToFloat)(gasFeeIntWithStables, sourceChainToken.decimals).toFixed(),
275
303
  };
276
304
  }
277
305
  return gasFeeOptions;
278
306
  }
279
- async function validateExtraGasNotExceeded(extraGasInt, gasFeePaymentMethod, sourceToken, destinationToken, api) {
280
- const extraGasLimits = await getExtraGasMaxLimits(sourceToken, destinationToken, api);
307
+ function validateExtraGasNotExceeded(extraGasInt, gasFeePaymentMethod, extraGasLimits) {
281
308
  const extraGasMaxLimit = extraGasLimits.extraGasMax[gasFeePaymentMethod];
282
309
  if (!extraGasMaxLimit) {
283
310
  throw new exceptions_1.InvalidGasFeePaymentOptionError(`Impossible to pay extra gas by '${gasFeePaymentMethod}' payment method`);
@@ -287,12 +314,13 @@ async function validateExtraGasNotExceeded(extraGasInt, gasFeePaymentMethod, sou
287
314
  throw new exceptions_1.ExtraGasMaxLimitExceededError(`Extra gas ${extraGasInt} in int format, exceeded limit ${extraGasMaxIntLimit} for '${gasFeePaymentMethod}' payment method`);
288
315
  }
289
316
  }
290
- async function getExtraGasMaxLimits(sourceChainToken, destinationChainToken, api) {
317
+ async function getExtraGasMaxLimits(sourceChainToken, destinationChainToken, messenger, api) {
291
318
  const extraGasMaxLimits = {};
292
319
  const transactionCostResponse = await api.getReceiveTransactionCost({
293
320
  sourceChainId: sourceChainToken.allbridgeChainId,
294
321
  destinationChainId: destinationChainToken.allbridgeChainId,
295
- messenger: core_api_model_1.Messenger.ALLBRIDGE,
322
+ messenger,
323
+ sourceToken: sourceChainToken.tokenAddress,
296
324
  });
297
325
  const maxAmount = destinationChainToken.txCostAmount.maxAmount;
298
326
  const maxAmountFloat = (0, calculation_1.convertIntAmountToFloat)(maxAmount, chains_1.Chains.getChainDecimalsByType(destinationChainToken.chainType)).toFixed();
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/services/bridge/utils.ts"],"names":[],"mappings":";;;;;AAiDA,sCA0CC;AAED,0CAEC;AAED,kCAEC;AAED,oDAIC;AAED,sDAIC;AAED,0DAIC;AAWD,wDAcC;AAED,4BAEC;AAED,wCAMC;AAeD,kDA2BC;AAyBD,kDAsHC;AAqBD,4CAoCC;AAsBD,oDA6DC;AAED,oCAEC;AAneD,6CAA4C;AAC5C,sDAA+C;AAC/C,mCAAwC;AACxC,8DAAsC;AACtC,qCAAgD;AAChD,yCAAsC;AACtC,yEAAiE;AAEjE,iDAM0B;AAC1B,yCAQsB;AAEtB,yDAAmH;AAuBnH,wBAAwB;AACxB,SAAgB,aAAa,CAAC,OAAe,EAAE,IAAe,EAAE,EAAa;IAC3E,IAAI,MAAc,CAAC;IACnB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;YACvC,MAAM;QACR,CAAC;QACD,KAAK,kBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YACtB,MAAM,GAAG,IAAI,mBAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC3C,MAAM;QACR,CAAC;QACD,KAAK,kBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM;QACR,CAAC;QACD,KAAK,kBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,GAAG,IAAI,qBAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;YACzC,MAAM;QACR,CAAC;QACD,KAAK,kBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAC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CAAC,SAAS,CAAC,CAC/D,CAAC,OAAO,EAAE;aACZ;SACF;QACD,YAAY,EAAE,uBAAuB,CAAC,YAAY;QAClD,sBAAsB,EAAE,uBAAuB,CAAC,sBAAsB;KACvE,CAAC;AACJ,CAAC;AAED,SAAgB,YAAY,CAAC,MAA+B;IAC1D,OAAO,MAAM,CAAC,WAAW,CAAC,WAAW,KAAK,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC;AAChF,CAAC","sourcesContent":["import { PublicKey } from \"@solana/web3.js\";\nimport { Address } from \"@stellar/stellar-sdk\";\nimport { Big, BigSource } from \"big.js\";\nimport randomBytes from \"randombytes\";\nimport { utils as TronWebUtils } from \"tronweb\";\nimport { Chains } from \"../../chains\";\nimport { Messenger } from \"../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport {\n AmountNotEnoughError,\n CCTPDoesNotSupportedError,\n ExtraGasMaxLimitExceededError,\n InvalidGasFeePaymentOptionError,\n SdkError,\n} from \"../../exceptions\";\nimport {\n AmountFormat,\n ChainType,\n ExtraGasMaxLimitResponse,\n ExtraGasMaxLimits,\n FeePaymentMethod,\n GasFeeOptions,\n SwapParams,\n} from \"../../models\";\nimport { ChainDetailsMap, TokenWithChainDetails } from \"../../tokens-info\";\nimport { convertAmountPrecision, convertFloatAmountToInt, convertIntAmountToFloat } from \"../../utils/calculation\";\nimport {\n SendParams,\n TxSendParams,\n TxSendParamsEvm,\n TxSendParamsSol,\n TxSendParamsSrb,\n TxSendParamsSui,\n TxSendParamsTrx,\n TxSwapParams,\n TxSwapParamsEvm,\n TxSwapParamsSol,\n TxSwapParamsSrb,\n TxSwapParamsSui,\n TxSwapParamsTrx,\n} from \"./models\"; // 1. OVERLOADS\n\n// 1. OVERLOADS\nexport function formatAddress(address: string, from: ChainType, to: ChainType.EVM | ChainType.SUI): string;\nexport function formatAddress(address: string, from: ChainType, to: ChainType.TRX): Buffer;\nexport function formatAddress(address: string, from: ChainType, to: ChainType.SOLANA | ChainType.SRB): number[];\nexport function formatAddress(address: string, from: ChainType, to: ChainType): string | number[] | Buffer;\n\n// 2. COMMON Realization\nexport function formatAddress(address: string, from: ChainType, to: ChainType): string | number[] | Buffer {\n let buffer: Buffer;\n switch (from) {\n case ChainType.EVM: {\n buffer = evmAddressToBuffer32(address);\n break;\n }\n case ChainType.SOLANA: {\n buffer = new PublicKey(address).toBuffer();\n break;\n }\n case ChainType.TRX: {\n buffer = tronAddressToBuffer32(address);\n break;\n }\n case ChainType.SRB: {\n buffer = new Address(address).toBuffer();\n break;\n }\n case ChainType.SUI: {\n buffer = evmAddressToBuffer32(address);\n break;\n }\n }\n\n switch (to) {\n case ChainType.EVM: {\n return \"0x\" + buffer.toString(\"hex\");\n }\n case ChainType.SOLANA: {\n return Array.from(buffer);\n }\n case ChainType.TRX: {\n return buffer;\n }\n case ChainType.SRB: {\n return buffer.toJSON().data;\n }\n case ChainType.SUI: {\n return \"0x\" + buffer.toString(\"hex\");\n }\n }\n}\n\nexport function normalizeSuiHex(hex: string): string {\n return hex.replace(/^0x/i, \"\");\n}\n\nexport function hexToBuffer(hex: string): Buffer {\n return Buffer.from(hex.replace(/^0x/i, \"\"), \"hex\");\n}\n\nexport function evmAddressToBuffer32(address: string): Buffer {\n const length = 32;\n const buff = hexToBuffer(address);\n return Buffer.concat([Buffer.alloc(length - buff.length, 0), buff], length);\n}\n\nexport function tronAddressToBuffer32(address: string): Buffer {\n const ethAddress = tronAddressToEthAddress(address);\n const buffer = hexToBuffer(ethAddress);\n return bufferToSize(buffer, 32);\n}\n\nexport function tronAddressToEthAddress(address: string): string {\n const bytes = TronWebUtils.crypto.decodeBase58Address(address);\n if (!bytes) return \"\";\n return TronWebUtils.bytes.byteArray2hexStr(bytes).replace(/^41/, \"0x\");\n}\n\nfunction bufferToSize(buffer: Buffer, size: number): Buffer {\n if (buffer.length >= size) {\n return buffer;\n }\n const result = Buffer.alloc(size, 0);\n buffer.copy(result, size - buffer.length);\n return result;\n}\n\nexport function getTokenByTokenAddress(\n chainDetailsMap: ChainDetailsMap,\n chainSymbol: string,\n tokenAddress: string\n): TokenWithChainDetails {\n const chainDetail = chainDetailsMap[chainSymbol];\n if (!chainDetail) {\n throw new SdkError(\"Cannot find chain detail for \" + chainSymbol);\n }\n const token = chainDetail.tokens.find((value) => value.tokenAddress.toUpperCase() === tokenAddress.toUpperCase());\n if (!token) {\n throw new SdkError(\"Cannot find token info about token \" + tokenAddress + \" on chain \" + chainSymbol);\n }\n return token;\n}\n\nexport function getNonce(): Buffer {\n return randomBytes(32);\n}\n\nexport function getNonceBigInt(): bigint {\n const bigint = randomBytes(32).readBigInt64BE();\n if (bigint < 0) {\n return bigint * -1n;\n }\n return bigint;\n}\n\n// 1. OVERLOADS\nexport function prepareTxSwapParams(\n bridgeChainType: ChainType.EVM | ChainType.SUI,\n params: SwapParams\n): TxSwapParamsEvm | TxSwapParamsSui;\nexport function prepareTxSwapParams(bridgeChainType: ChainType.TRX, params: SwapParams): TxSwapParamsTrx;\nexport function prepareTxSwapParams(\n bridgeChainType: ChainType.SOLANA | ChainType.SRB,\n params: SwapParams\n): TxSwapParamsSol | TxSwapParamsSrb;\nexport function prepareTxSwapParams(bridgeChainType: ChainType, params: SwapParams): TxSwapParams;\n\n// 2. COMMON Realization\nexport function prepareTxSwapParams(bridgeChainType: ChainType, params: SwapParams): TxSwapParams {\n const txSwapParams = {} as TxSwapParams;\n const sourceToken = params.sourceToken;\n txSwapParams.amount = convertFloatAmountToInt(params.amount, sourceToken.decimals).toFixed();\n txSwapParams.contractAddress = sourceToken.bridgeAddress;\n txSwapParams.fromAccountAddress = params.fromAccountAddress;\n if (bridgeChainType === ChainType.SUI) {\n if (!sourceToken.originTokenAddress) {\n throw new SdkError(\"SUI sourceToken must contain 'originTokenAddress'\");\n }\n txSwapParams.fromTokenAddress = sourceToken.originTokenAddress;\n } else {\n txSwapParams.fromTokenAddress = formatAddress(sourceToken.tokenAddress, bridgeChainType, bridgeChainType);\n }\n txSwapParams.toAccountAddress = params.toAccountAddress;\n if (bridgeChainType === ChainType.SUI) {\n if (!params.destinationToken.originTokenAddress) {\n throw new SdkError(\"SUI destinationToken must contain 'originTokenAddress'\");\n }\n txSwapParams.toTokenAddress = params.destinationToken.originTokenAddress;\n } else {\n txSwapParams.toTokenAddress = formatAddress(params.destinationToken.tokenAddress, bridgeChainType, bridgeChainType);\n }\n txSwapParams.minimumReceiveAmount = params.minimumReceiveAmount\n ? convertFloatAmountToInt(params.minimumReceiveAmount, params.destinationToken.decimals).toFixed()\n : \"0\";\n return txSwapParams;\n}\n\n// 1. OVERLOADS\nexport function prepareTxSendParams(\n bridgeChainType: ChainType.EVM | ChainType.SUI,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParamsEvm | TxSendParamsSui>;\nexport function prepareTxSendParams(\n bridgeChainType: ChainType.TRX,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParamsTrx>;\nexport function prepareTxSendParams(\n bridgeChainType: ChainType.SOLANA | ChainType.SRB,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParamsSol | TxSendParamsSrb>;\nexport function prepareTxSendParams(\n bridgeChainType: ChainType,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParams>;\n\n// 2. COMMON Realization\nexport async function prepareTxSendParams(\n bridgeChainType: ChainType,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParams> {\n const txSendParams = {} as TxSendParams;\n\n txSendParams.fromChainId = params.sourceToken.allbridgeChainId;\n txSendParams.fromChainSymbol = params.sourceToken.chainSymbol;\n const toChainType = Chains.getChainProperty(params.destinationToken.chainSymbol).chainType;\n if (bridgeChainType === ChainType.SUI) {\n if (!params.sourceToken.originTokenAddress) {\n throw new SdkError(\"SUI token must contain 'originTokenAddress'\");\n }\n txSendParams.fromTokenAddress = params.sourceToken.originTokenAddress;\n } else {\n txSendParams.fromTokenAddress = params.sourceToken.tokenAddress;\n }\n\n txSendParams.toChainId = params.destinationToken.allbridgeChainId;\n txSendParams.toTokenAddress = params.destinationToken.tokenAddress;\n\n if (params.gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n txSendParams.gasFeePaymentMethod = FeePaymentMethod.WITH_STABLECOIN;\n } else {\n // default FeePaymentMethod.WITH_NATIVE_CURRENCY\n txSendParams.gasFeePaymentMethod = FeePaymentMethod.WITH_NATIVE_CURRENCY;\n }\n const sourceToken = params.sourceToken;\n\n if (params.messenger === Messenger.CCTP) {\n if (!sourceToken.cctpAddress || !params.destinationToken.cctpAddress) {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n txSendParams.contractAddress = sourceToken.cctpAddress;\n } else if (params.messenger === Messenger.CCTP_V2) {\n if (!sourceToken.cctpV2Address || !params.destinationToken.cctpV2Address) {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n txSendParams.contractAddress = sourceToken.cctpV2Address;\n } else {\n txSendParams.contractAddress = sourceToken.bridgeAddress;\n }\n\n txSendParams.messenger = params.messenger;\n txSendParams.fromAccountAddress = params.fromAccountAddress;\n txSendParams.amount = convertFloatAmountToInt(params.amount, sourceToken.decimals).toFixed();\n\n //Fee\n let { fee, feeFormat } = params;\n if (!fee) {\n const gasFeeOptions = await getGasFeeOptions(\n txSendParams.fromChainId,\n params.sourceToken.chainType,\n txSendParams.toChainId,\n sourceToken.decimals,\n txSendParams.messenger,\n api\n );\n\n const gasFeeOption = gasFeeOptions[txSendParams.gasFeePaymentMethod];\n if (!gasFeeOption) {\n throw new InvalidGasFeePaymentOptionError();\n }\n fee = gasFeeOption[AmountFormat.INT];\n feeFormat = AmountFormat.INT;\n }\n if (feeFormat == AmountFormat.FLOAT) {\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n txSendParams.fee = convertFloatAmountToInt(fee, Chains.getChainDecimalsByType(sourceToken.chainType)).toFixed(\n 0\n );\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n txSendParams.fee = convertFloatAmountToInt(fee, sourceToken.decimals).toFixed(0);\n break;\n }\n } else {\n txSendParams.fee = fee;\n }\n\n //ExtraGas\n const { extraGas, extraGasFormat } = params;\n if (extraGas && +extraGas > 0) {\n if (extraGasFormat == AmountFormat.FLOAT) {\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n txSendParams.extraGas = convertFloatAmountToInt(\n extraGas,\n Chains.getChainDecimalsByType(sourceToken.chainType)\n ).toFixed(0);\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n txSendParams.extraGas = convertFloatAmountToInt(extraGas, sourceToken.decimals).toFixed(0);\n break;\n }\n } else {\n txSendParams.extraGas = extraGas;\n }\n await validateExtraGasNotExceeded(\n txSendParams.extraGas,\n txSendParams.gasFeePaymentMethod,\n sourceToken,\n params.destinationToken,\n api\n );\n }\n\n if (bridgeChainType !== ChainType.SUI) {\n txSendParams.fromTokenAddress = formatAddress(txSendParams.fromTokenAddress, bridgeChainType, bridgeChainType);\n }\n txSendParams.toAccountAddress = formatAddress(params.toAccountAddress, toChainType, bridgeChainType);\n txSendParams.toTokenAddress = formatAddress(txSendParams.toTokenAddress, toChainType, bridgeChainType);\n if (txSendParams.gasFeePaymentMethod == FeePaymentMethod.WITH_STABLECOIN) {\n validateAmountEnough(txSendParams.amount, sourceToken.decimals, txSendParams.fee, txSendParams.extraGas);\n }\n return txSendParams;\n}\n\nfunction validateAmountEnough(\n amountInt: BigSource,\n decimals: number,\n feeInt: BigSource,\n extraGasInt: BigSource | undefined\n) {\n const amountTotal = Big(amountInt)\n .minus(feeInt)\n .minus(extraGasInt ?? 0);\n if (amountTotal.lte(0)) {\n throw new AmountNotEnoughError(\n `Amount not enough to pay fee, ${convertIntAmountToFloat(\n Big(amountTotal).minus(1).neg(),\n decimals\n ).toFixed()} stables is missing`\n );\n }\n}\n\nexport async function getGasFeeOptions(\n sourceAllbridgeChainId: number,\n sourceChainType: ChainType,\n destinationAllbridgeChainId: number,\n sourceChainTokenDecimals: number,\n messenger: Messenger,\n api: AllbridgeCoreClient\n): Promise<GasFeeOptions> {\n const transactionCostResponse = await api.getReceiveTransactionCost({\n sourceChainId: sourceAllbridgeChainId,\n destinationChainId: destinationAllbridgeChainId,\n messenger,\n });\n\n const gasFeeOptions: GasFeeOptions = {\n [FeePaymentMethod.WITH_NATIVE_CURRENCY]: {\n [AmountFormat.INT]: transactionCostResponse.fee,\n [AmountFormat.FLOAT]: convertIntAmountToFloat(\n transactionCostResponse.fee,\n Chains.getChainDecimalsByType(sourceChainType)\n ).toFixed(),\n },\n };\n if (transactionCostResponse.sourceNativeTokenPrice) {\n const gasFeeIntWithStables = convertAmountPrecision(\n new Big(transactionCostResponse.fee).mul(transactionCostResponse.sourceNativeTokenPrice),\n Chains.getChainDecimalsByType(sourceChainType),\n sourceChainTokenDecimals\n ).toFixed(0, Big.roundUp);\n gasFeeOptions[FeePaymentMethod.WITH_STABLECOIN] = {\n [AmountFormat.INT]: gasFeeIntWithStables,\n [AmountFormat.FLOAT]: convertIntAmountToFloat(gasFeeIntWithStables, sourceChainTokenDecimals).toFixed(),\n };\n }\n\n return gasFeeOptions;\n}\n\nasync function validateExtraGasNotExceeded(\n extraGasInt: string,\n gasFeePaymentMethod: FeePaymentMethod,\n sourceToken: TokenWithChainDetails,\n destinationToken: TokenWithChainDetails,\n api: AllbridgeCoreClient\n) {\n const extraGasLimits = await getExtraGasMaxLimits(sourceToken, destinationToken, api);\n const extraGasMaxLimit = extraGasLimits.extraGasMax[gasFeePaymentMethod];\n if (!extraGasMaxLimit) {\n throw new InvalidGasFeePaymentOptionError(`Impossible to pay extra gas by '${gasFeePaymentMethod}' payment method`);\n }\n const extraGasMaxIntLimit = extraGasMaxLimit[AmountFormat.INT];\n if (Big(extraGasInt).gt(extraGasMaxIntLimit)) {\n throw new ExtraGasMaxLimitExceededError(\n `Extra gas ${extraGasInt} in int format, exceeded limit ${extraGasMaxIntLimit} for '${gasFeePaymentMethod}' payment method`\n );\n }\n}\n\nexport async function getExtraGasMaxLimits(\n sourceChainToken: TokenWithChainDetails,\n destinationChainToken: TokenWithChainDetails,\n api: AllbridgeCoreClient\n): Promise<ExtraGasMaxLimitResponse> {\n const extraGasMaxLimits: ExtraGasMaxLimits = {};\n const transactionCostResponse = await api.getReceiveTransactionCost({\n sourceChainId: sourceChainToken.allbridgeChainId,\n destinationChainId: destinationChainToken.allbridgeChainId,\n messenger: Messenger.ALLBRIDGE,\n });\n const maxAmount = destinationChainToken.txCostAmount.maxAmount;\n const maxAmountFloat = convertIntAmountToFloat(\n maxAmount,\n Chains.getChainDecimalsByType(destinationChainToken.chainType)\n ).toFixed();\n const maxAmountFloatInSourceNative = Big(maxAmountFloat)\n .div(transactionCostResponse.exchangeRate)\n .toFixed(Chains.getChainDecimalsByType(sourceChainToken.chainType), Big.roundDown);\n const maxAmountInSourceNative = convertFloatAmountToInt(\n maxAmountFloatInSourceNative,\n Chains.getChainDecimalsByType(sourceChainToken.chainType)\n ).toFixed(0);\n extraGasMaxLimits[FeePaymentMethod.WITH_NATIVE_CURRENCY] = {\n [AmountFormat.INT]: maxAmountInSourceNative,\n [AmountFormat.FLOAT]: maxAmountFloatInSourceNative,\n };\n if (transactionCostResponse.sourceNativeTokenPrice) {\n const maxAmountFloatInStable = Big(maxAmountFloatInSourceNative)\n .mul(transactionCostResponse.sourceNativeTokenPrice)\n .toFixed(sourceChainToken.decimals, Big.roundDown);\n extraGasMaxLimits[FeePaymentMethod.WITH_STABLECOIN] = {\n [AmountFormat.INT]: convertFloatAmountToInt(maxAmountFloatInStable, sourceChainToken.decimals).toFixed(0),\n [AmountFormat.FLOAT]: maxAmountFloatInStable,\n };\n }\n return {\n extraGasMax: extraGasMaxLimits,\n destinationChain: {\n gasAmountMax: {\n [AmountFormat.INT]: maxAmount,\n [AmountFormat.FLOAT]: maxAmountFloat,\n },\n swap: {\n [AmountFormat.INT]: destinationChainToken.txCostAmount.swap,\n [AmountFormat.FLOAT]: convertIntAmountToFloat(\n destinationChainToken.txCostAmount.swap,\n Chains.getChainDecimalsByType(destinationChainToken.chainType)\n ).toFixed(),\n },\n transfer: {\n [AmountFormat.INT]: destinationChainToken.txCostAmount.transfer,\n [AmountFormat.FLOAT]: convertIntAmountToFloat(\n destinationChainToken.txCostAmount.transfer,\n Chains.getChainDecimalsByType(destinationChainToken.chainType)\n ).toFixed(),\n },\n },\n exchangeRate: transactionCostResponse.exchangeRate,\n sourceNativeTokenPrice: transactionCostResponse.sourceNativeTokenPrice,\n };\n}\n\nexport function isSendParams(params: SwapParams | SendParams): params is SendParams {\n return params.sourceToken.chainSymbol !== params.destinationToken.chainSymbol;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/services/bridge/utils.ts"],"names":[],"mappings":";;;;;AAkDA,sCA0CC;AAED,0CAEC;AAED,kCAEC;AAED,oDAIC;AAED,sDAIC;AAED,0DAIC;AAWD,wDAcC;AAED,4BAEC;AAED,wCAMC;AAeD,kDA2BC;AAyBD,kDA8JC;AAqBD,4CAoCC;AAmBD,oDA+DC;AAED,oCAEC;AA3gBD,6CAA4C;AAC5C,sDAA+C;AAC/C,mCAAwC;AACxC,8DAAsC;AACtC,qCAAgD;AAChD,yCAAsC;AACtC,yEAAiE;AAEjE,iDAO0B;AAC1B,yCAQsB;AAEtB,yDAAmH;AAuBnH,wBAAwB;AACxB,SAAgB,aAAa,CAAC,OAAe,EAAE,IAAe,EAAE,EAAa;IAC3E,IAAI,MAAc,CAAC;IACnB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;YACvC,MAAM;QACR,CAAC;QACD,KAAK,kBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YACtB,MAAM,GAAG,IAAI,mBAAS,CAAC,OAAO,CAAC,CAA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AE,SAAS;gBAC7B,CAAC,qBAAY,CAAC,KAAK,CAAC,EAAE,cAAc;aACrC;YACD,IAAI,EAAE;gBACJ,CAAC,qBAAY,CAAC,GAAG,CAAC,EAAE,qBAAqB,CAAC,YAAY,CAAC,IAAI;gBAC3D,CAAC,qBAAY,CAAC,KAAK,CAAC,EAAE,IAAA,qCAAuB,EAC3C,qBAAqB,CAAC,YAAY,CAAC,IAAI,EACvC,eAAM,CAAC,sBAAsB,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAC/D,CAAC,OAAO,EAAE;aACZ;YACD,QAAQ,EAAE;gBACR,CAAC,qBAAY,CAAC,GAAG,CAAC,EAAE,qBAAqB,CAAC,YAAY,CAAC,QAAQ;gBAC/D,CAAC,qBAAY,CAAC,KAAK,CAAC,EAAE,IAAA,qCAAuB,EAC3C,qBAAqB,CAAC,YAAY,CAAC,QAAQ,EAC3C,eAAM,CAAC,sBAAsB,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAC/D,CAAC,OAAO,EAAE;aACZ;SACF;QACD,YAAY,EAAE,uBAAuB,CAAC,YAAY;QAClD,sBAAsB,EAAE,uBAAuB,CAAC,sBAAsB;KACvE,CAAC;AACJ,CAAC;AAED,SAAgB,YAAY,CAAC,MAA+B;IAC1D,OAAO,MAAM,CAAC,WAAW,CAAC,WAAW,KAAK,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC;AAChF,CAAC","sourcesContent":["import { PublicKey } from \"@solana/web3.js\";\nimport { Address } from \"@stellar/stellar-sdk\";\nimport { Big, BigSource } from \"big.js\";\nimport randomBytes from \"randombytes\";\nimport { utils as TronWebUtils } from \"tronweb\";\nimport { Chains } from \"../../chains\";\nimport { Messenger } from \"../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport {\n AmountNotEnoughError,\n CCTPDoesNotSupportedError,\n ExtraGasMaxLimitExceededError,\n InvalidGasFeePaymentOptionError,\n OFTDoesNotSupportedError,\n SdkError,\n} from \"../../exceptions\";\nimport {\n AmountFormat,\n ChainType,\n ExtraGasMaxLimitResponse,\n ExtraGasMaxLimits,\n FeePaymentMethod,\n GasFeeOptions,\n SwapParams,\n} from \"../../models\";\nimport { ChainDetailsMap, TokenWithChainDetails } from \"../../tokens-info\";\nimport { convertAmountPrecision, convertFloatAmountToInt, convertIntAmountToFloat } from \"../../utils/calculation\";\nimport {\n SendParams,\n TxSendParams,\n TxSendParamsEvm,\n TxSendParamsSol,\n TxSendParamsSrb,\n TxSendParamsSui,\n TxSendParamsTrx,\n TxSwapParams,\n TxSwapParamsEvm,\n TxSwapParamsSol,\n TxSwapParamsSrb,\n TxSwapParamsSui,\n TxSwapParamsTrx,\n} from \"./models\"; // 1. OVERLOADS\n\n// 1. OVERLOADS\nexport function formatAddress(address: string, from: ChainType, to: ChainType.EVM | ChainType.SUI): string;\nexport function formatAddress(address: string, from: ChainType, to: ChainType.TRX): Buffer;\nexport function formatAddress(address: string, from: ChainType, to: ChainType.SOLANA | ChainType.SRB): number[];\nexport function formatAddress(address: string, from: ChainType, to: ChainType): string | number[] | Buffer;\n\n// 2. COMMON Realization\nexport function formatAddress(address: string, from: ChainType, to: ChainType): string | number[] | Buffer {\n let buffer: Buffer;\n switch (from) {\n case ChainType.EVM: {\n buffer = evmAddressToBuffer32(address);\n break;\n }\n case ChainType.SOLANA: {\n buffer = new PublicKey(address).toBuffer();\n break;\n }\n case ChainType.TRX: {\n buffer = tronAddressToBuffer32(address);\n break;\n }\n case ChainType.SRB: {\n buffer = new Address(address).toBuffer();\n break;\n }\n case ChainType.SUI: {\n buffer = evmAddressToBuffer32(address);\n break;\n }\n }\n\n switch (to) {\n case ChainType.EVM: {\n return \"0x\" + buffer.toString(\"hex\");\n }\n case ChainType.SOLANA: {\n return Array.from(buffer);\n }\n case ChainType.TRX: {\n return buffer;\n }\n case ChainType.SRB: {\n return buffer.toJSON().data;\n }\n case ChainType.SUI: {\n return \"0x\" + buffer.toString(\"hex\");\n }\n }\n}\n\nexport function normalizeSuiHex(hex: string): string {\n return hex.replace(/^0x/i, \"\");\n}\n\nexport function hexToBuffer(hex: string): Buffer {\n return Buffer.from(hex.replace(/^0x/i, \"\"), \"hex\");\n}\n\nexport function evmAddressToBuffer32(address: string): Buffer {\n const length = 32;\n const buff = hexToBuffer(address);\n return Buffer.concat([Buffer.alloc(length - buff.length, 0), buff], length);\n}\n\nexport function tronAddressToBuffer32(address: string): Buffer {\n const ethAddress = tronAddressToEthAddress(address);\n const buffer = hexToBuffer(ethAddress);\n return bufferToSize(buffer, 32);\n}\n\nexport function tronAddressToEthAddress(address: string): string {\n const bytes = TronWebUtils.crypto.decodeBase58Address(address);\n if (!bytes) return \"\";\n return TronWebUtils.bytes.byteArray2hexStr(bytes).replace(/^41/, \"0x\");\n}\n\nfunction bufferToSize(buffer: Buffer, size: number): Buffer {\n if (buffer.length >= size) {\n return buffer;\n }\n const result = Buffer.alloc(size, 0);\n buffer.copy(result, size - buffer.length);\n return result;\n}\n\nexport function getTokenByTokenAddress(\n chainDetailsMap: ChainDetailsMap,\n chainSymbol: string,\n tokenAddress: string\n): TokenWithChainDetails {\n const chainDetail = chainDetailsMap[chainSymbol];\n if (!chainDetail) {\n throw new SdkError(\"Cannot find chain detail for \" + chainSymbol);\n }\n const token = chainDetail.tokens.find((value) => value.tokenAddress.toUpperCase() === tokenAddress.toUpperCase());\n if (!token) {\n throw new SdkError(\"Cannot find token info about token \" + tokenAddress + \" on chain \" + chainSymbol);\n }\n return token;\n}\n\nexport function getNonce(): Buffer {\n return randomBytes(32);\n}\n\nexport function getNonceBigInt(): bigint {\n const bigint = randomBytes(32).readBigInt64BE();\n if (bigint < 0) {\n return bigint * -1n;\n }\n return bigint;\n}\n\n// 1. OVERLOADS\nexport function prepareTxSwapParams(\n bridgeChainType: ChainType.EVM | ChainType.SUI,\n params: SwapParams\n): TxSwapParamsEvm | TxSwapParamsSui;\nexport function prepareTxSwapParams(bridgeChainType: ChainType.TRX, params: SwapParams): TxSwapParamsTrx;\nexport function prepareTxSwapParams(\n bridgeChainType: ChainType.SOLANA | ChainType.SRB,\n params: SwapParams\n): TxSwapParamsSol | TxSwapParamsSrb;\nexport function prepareTxSwapParams(bridgeChainType: ChainType, params: SwapParams): TxSwapParams;\n\n// 2. COMMON Realization\nexport function prepareTxSwapParams(bridgeChainType: ChainType, params: SwapParams): TxSwapParams {\n const txSwapParams = {} as TxSwapParams;\n const sourceToken = params.sourceToken;\n txSwapParams.amount = convertFloatAmountToInt(params.amount, sourceToken.decimals).toFixed();\n txSwapParams.contractAddress = sourceToken.bridgeAddress;\n txSwapParams.fromAccountAddress = params.fromAccountAddress;\n if (bridgeChainType === ChainType.SUI) {\n if (!sourceToken.originTokenAddress) {\n throw new SdkError(\"SUI sourceToken must contain 'originTokenAddress'\");\n }\n txSwapParams.fromTokenAddress = sourceToken.originTokenAddress;\n } else {\n txSwapParams.fromTokenAddress = formatAddress(sourceToken.tokenAddress, bridgeChainType, bridgeChainType);\n }\n txSwapParams.toAccountAddress = params.toAccountAddress;\n if (bridgeChainType === ChainType.SUI) {\n if (!params.destinationToken.originTokenAddress) {\n throw new SdkError(\"SUI destinationToken must contain 'originTokenAddress'\");\n }\n txSwapParams.toTokenAddress = params.destinationToken.originTokenAddress;\n } else {\n txSwapParams.toTokenAddress = formatAddress(params.destinationToken.tokenAddress, bridgeChainType, bridgeChainType);\n }\n txSwapParams.minimumReceiveAmount = params.minimumReceiveAmount\n ? convertFloatAmountToInt(params.minimumReceiveAmount, params.destinationToken.decimals).toFixed()\n : \"0\";\n return txSwapParams;\n}\n\n// 1. OVERLOADS\nexport function prepareTxSendParams(\n bridgeChainType: ChainType.EVM | ChainType.SUI,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParamsEvm | TxSendParamsSui>;\nexport function prepareTxSendParams(\n bridgeChainType: ChainType.TRX,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParamsTrx>;\nexport function prepareTxSendParams(\n bridgeChainType: ChainType.SOLANA | ChainType.SRB,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParamsSol | TxSendParamsSrb>;\nexport function prepareTxSendParams(\n bridgeChainType: ChainType,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParams>;\n\n// 2. COMMON Realization\nexport async function prepareTxSendParams(\n bridgeChainType: ChainType,\n params: SendParams,\n api: AllbridgeCoreClient\n): Promise<TxSendParams> {\n const txSendParams = {} as TxSendParams;\n\n txSendParams.fromChainId = params.sourceToken.allbridgeChainId;\n txSendParams.fromChainSymbol = params.sourceToken.chainSymbol;\n const toChainType = Chains.getChainProperty(params.destinationToken.chainSymbol).chainType;\n if (bridgeChainType === ChainType.SUI) {\n if (!params.sourceToken.originTokenAddress) {\n throw new SdkError(\"SUI token must contain 'originTokenAddress'\");\n }\n txSendParams.fromTokenAddress = params.sourceToken.originTokenAddress;\n } else {\n txSendParams.fromTokenAddress = params.sourceToken.tokenAddress;\n }\n\n txSendParams.toChainId = params.destinationToken.allbridgeChainId;\n txSendParams.toTokenAddress = params.destinationToken.tokenAddress;\n\n if (params.gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n txSendParams.gasFeePaymentMethod = FeePaymentMethod.WITH_STABLECOIN;\n } else {\n // default FeePaymentMethod.WITH_NATIVE_CURRENCY\n txSendParams.gasFeePaymentMethod = FeePaymentMethod.WITH_NATIVE_CURRENCY;\n }\n const sourceToken = params.sourceToken;\n\n switch (params.messenger) {\n case Messenger.CCTP:\n if (!sourceToken.cctpAddress || !params.destinationToken.cctpAddress) {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n txSendParams.contractAddress = sourceToken.cctpAddress;\n break;\n case Messenger.CCTP_V2:\n if (!sourceToken.cctpV2Address || !params.destinationToken.cctpV2Address) {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n txSendParams.contractAddress = sourceToken.cctpV2Address;\n\n break;\n case Messenger.OFT:\n if (\n !sourceToken.oftBridgeAddress ||\n !params.destinationToken.oftBridgeAddress ||\n sourceToken.oftId !== params.destinationToken.oftId\n ) {\n throw new OFTDoesNotSupportedError(\"Such route does not support OFT protocol\");\n }\n txSendParams.contractAddress = sourceToken.oftBridgeAddress;\n break;\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n txSendParams.contractAddress = sourceToken.bridgeAddress;\n break;\n }\n\n txSendParams.messenger = params.messenger;\n txSendParams.fromAccountAddress = params.fromAccountAddress;\n txSendParams.amount = convertFloatAmountToInt(params.amount, sourceToken.decimals).toFixed();\n\n //Fee\n let { fee, feeFormat } = params;\n if (!fee) {\n const gasFeeOptions = await getGasFeeOptions(\n params.sourceToken,\n txSendParams.toChainId,\n txSendParams.messenger,\n api\n );\n\n const gasFeeOption = gasFeeOptions[txSendParams.gasFeePaymentMethod];\n if (!gasFeeOption) {\n throw new InvalidGasFeePaymentOptionError();\n }\n fee = gasFeeOption[AmountFormat.INT];\n feeFormat = AmountFormat.INT;\n }\n if (feeFormat == AmountFormat.FLOAT) {\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n txSendParams.fee = convertFloatAmountToInt(fee, Chains.getChainDecimalsByType(sourceToken.chainType)).toFixed(\n 0\n );\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n txSendParams.fee = convertFloatAmountToInt(fee, sourceToken.decimals).toFixed(0);\n break;\n }\n } else {\n txSendParams.fee = fee;\n }\n\n //ExtraGas\n const { extraGas, extraGasFormat } = params;\n if (extraGas && +extraGas > 0) {\n const extraGasLimits = await getExtraGasMaxLimits(\n sourceToken,\n params.destinationToken,\n txSendParams.messenger,\n api\n );\n\n let extraGasDecimals: number;\n let extraGasDestRate: Big;\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n extraGasDecimals = Chains.getChainDecimalsByType(sourceToken.chainType);\n extraGasDestRate = Big(extraGasLimits.exchangeRate);\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n extraGasDecimals = sourceToken.decimals;\n extraGasDestRate = Big(extraGasLimits.exchangeRate).div(extraGasLimits.sourceNativeTokenPrice);\n break;\n }\n\n switch (extraGasFormat ?? AmountFormat.INT) {\n case AmountFormat.FLOAT: {\n txSendParams.extraGas = convertFloatAmountToInt(extraGas, extraGasDecimals).toFixed(0);\n\n const extraGasDestFloat = extraGasDestRate.mul(extraGas);\n txSendParams.extraGasDest = convertFloatAmountToInt(\n extraGasDestFloat,\n Chains.getChainDecimalsByType(params.destinationToken.chainType)\n ).toFixed(0, Big.roundDown);\n break;\n }\n case AmountFormat.INT: {\n txSendParams.extraGas = extraGas;\n\n const extraGasFloat = convertIntAmountToFloat(\n txSendParams.extraGas,\n Chains.getChainDecimalsByType(sourceToken.chainType)\n );\n const extraGasDestFloat = extraGasDestRate.mul(extraGasFloat);\n txSendParams.extraGasDest = convertFloatAmountToInt(\n extraGasDestFloat,\n Chains.getChainDecimalsByType(params.destinationToken.chainType)\n ).toFixed(0, Big.roundDown);\n break;\n }\n }\n\n validateExtraGasNotExceeded(txSendParams.extraGas, txSendParams.gasFeePaymentMethod, extraGasLimits);\n }\n\n if (bridgeChainType !== ChainType.SUI) {\n txSendParams.fromTokenAddress = formatAddress(txSendParams.fromTokenAddress, bridgeChainType, bridgeChainType);\n }\n txSendParams.toAccountAddress = formatAddress(params.toAccountAddress, toChainType, bridgeChainType);\n txSendParams.toTokenAddress = formatAddress(txSendParams.toTokenAddress, toChainType, bridgeChainType);\n if (txSendParams.gasFeePaymentMethod == FeePaymentMethod.WITH_STABLECOIN) {\n validateAmountEnough(txSendParams.amount, sourceToken.decimals, txSendParams.fee, txSendParams.extraGas);\n }\n return txSendParams;\n}\n\nfunction validateAmountEnough(\n amountInt: BigSource,\n decimals: number,\n feeInt: BigSource,\n extraGasInt: BigSource | undefined\n) {\n const amountTotal = Big(amountInt)\n .minus(feeInt)\n .minus(extraGasInt ?? 0);\n if (amountTotal.lte(0)) {\n throw new AmountNotEnoughError(\n `Amount not enough to pay fee, ${convertIntAmountToFloat(\n Big(amountTotal).minus(1).neg(),\n decimals\n ).toFixed()} stables is missing`\n );\n }\n}\n\nexport async function getGasFeeOptions(\n sourceChainToken: TokenWithChainDetails,\n destinationAllbridgeChainId: number,\n messenger: Messenger,\n api: AllbridgeCoreClient\n): Promise<GasFeeOptions> {\n const transactionCostResponse = await api.getReceiveTransactionCost({\n sourceChainId: sourceChainToken.allbridgeChainId,\n destinationChainId: destinationAllbridgeChainId,\n messenger,\n sourceToken: sourceChainToken.tokenAddress,\n });\n\n const gasFeeOptions: GasFeeOptions = {\n [FeePaymentMethod.WITH_NATIVE_CURRENCY]: {\n [AmountFormat.INT]: transactionCostResponse.fee,\n [AmountFormat.FLOAT]: convertIntAmountToFloat(\n transactionCostResponse.fee,\n Chains.getChainDecimalsByType(sourceChainToken.chainType)\n ).toFixed(),\n },\n adminFeeShareWithExtras: transactionCostResponse.adminFeeShareWithExtras,\n };\n if (transactionCostResponse.sourceNativeTokenPrice) {\n const gasFeeIntWithStables = convertAmountPrecision(\n new Big(transactionCostResponse.fee).mul(transactionCostResponse.sourceNativeTokenPrice),\n Chains.getChainDecimalsByType(sourceChainToken.chainType),\n sourceChainToken.decimals\n ).toFixed(0, Big.roundUp);\n gasFeeOptions[FeePaymentMethod.WITH_STABLECOIN] = {\n [AmountFormat.INT]: gasFeeIntWithStables,\n [AmountFormat.FLOAT]: convertIntAmountToFloat(gasFeeIntWithStables, sourceChainToken.decimals).toFixed(),\n };\n }\n\n return gasFeeOptions;\n}\n\nfunction validateExtraGasNotExceeded(\n extraGasInt: string,\n gasFeePaymentMethod: FeePaymentMethod,\n extraGasLimits: ExtraGasMaxLimitResponse\n) {\n const extraGasMaxLimit = extraGasLimits.extraGasMax[gasFeePaymentMethod];\n if (!extraGasMaxLimit) {\n throw new InvalidGasFeePaymentOptionError(`Impossible to pay extra gas by '${gasFeePaymentMethod}' payment method`);\n }\n const extraGasMaxIntLimit = extraGasMaxLimit[AmountFormat.INT];\n if (Big(extraGasInt).gt(extraGasMaxIntLimit)) {\n throw new ExtraGasMaxLimitExceededError(\n `Extra gas ${extraGasInt} in int format, exceeded limit ${extraGasMaxIntLimit} for '${gasFeePaymentMethod}' payment method`\n );\n }\n}\n\nexport async function getExtraGasMaxLimits(\n sourceChainToken: TokenWithChainDetails,\n destinationChainToken: TokenWithChainDetails,\n messenger: Messenger,\n api: AllbridgeCoreClient\n): Promise<ExtraGasMaxLimitResponse> {\n const extraGasMaxLimits: ExtraGasMaxLimits = {};\n const transactionCostResponse = await api.getReceiveTransactionCost({\n sourceChainId: sourceChainToken.allbridgeChainId,\n destinationChainId: destinationChainToken.allbridgeChainId,\n messenger,\n sourceToken: sourceChainToken.tokenAddress,\n });\n const maxAmount = destinationChainToken.txCostAmount.maxAmount;\n const maxAmountFloat = convertIntAmountToFloat(\n maxAmount,\n Chains.getChainDecimalsByType(destinationChainToken.chainType)\n ).toFixed();\n const maxAmountFloatInSourceNative = Big(maxAmountFloat)\n .div(transactionCostResponse.exchangeRate)\n .toFixed(Chains.getChainDecimalsByType(sourceChainToken.chainType), Big.roundDown);\n const maxAmountInSourceNative = convertFloatAmountToInt(\n maxAmountFloatInSourceNative,\n Chains.getChainDecimalsByType(sourceChainToken.chainType)\n ).toFixed(0);\n extraGasMaxLimits[FeePaymentMethod.WITH_NATIVE_CURRENCY] = {\n [AmountFormat.INT]: maxAmountInSourceNative,\n [AmountFormat.FLOAT]: maxAmountFloatInSourceNative,\n };\n if (transactionCostResponse.sourceNativeTokenPrice) {\n const maxAmountFloatInStable = Big(maxAmountFloatInSourceNative)\n .mul(transactionCostResponse.sourceNativeTokenPrice)\n .toFixed(sourceChainToken.decimals, Big.roundDown);\n extraGasMaxLimits[FeePaymentMethod.WITH_STABLECOIN] = {\n [AmountFormat.INT]: convertFloatAmountToInt(maxAmountFloatInStable, sourceChainToken.decimals).toFixed(0),\n [AmountFormat.FLOAT]: maxAmountFloatInStable,\n };\n }\n return {\n extraGasMax: extraGasMaxLimits,\n destinationChain: {\n gasAmountMax: {\n [AmountFormat.INT]: maxAmount,\n [AmountFormat.FLOAT]: maxAmountFloat,\n },\n swap: {\n [AmountFormat.INT]: destinationChainToken.txCostAmount.swap,\n [AmountFormat.FLOAT]: convertIntAmountToFloat(\n destinationChainToken.txCostAmount.swap,\n Chains.getChainDecimalsByType(destinationChainToken.chainType)\n ).toFixed(),\n },\n transfer: {\n [AmountFormat.INT]: destinationChainToken.txCostAmount.transfer,\n [AmountFormat.FLOAT]: convertIntAmountToFloat(\n destinationChainToken.txCostAmount.transfer,\n Chains.getChainDecimalsByType(destinationChainToken.chainType)\n ).toFixed(),\n },\n },\n exchangeRate: transactionCostResponse.exchangeRate,\n sourceNativeTokenPrice: transactionCostResponse.sourceNativeTokenPrice,\n };\n}\n\nexport function isSendParams(params: SwapParams | SendParams): params is SendParams {\n return params.sourceToken.chainSymbol !== params.destinationToken.chainSymbol;\n}\n"]}
@@ -31,18 +31,24 @@ export declare class AllbridgeCoreSdkService {
31
31
  calculateFeePercentOnDestinationChain(amountFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails): Promise<number>;
32
32
  getAmountToBeReceivedAndGasFeeOptions(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger): Promise<AmountsAndGasFeeOptions>;
33
33
  getAmountToSendAndGasFeeOptions(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger): Promise<AmountsAndGasFeeOptions>;
34
- getAmountToBeReceived(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger?: Messenger): Promise<string>;
35
- getAmountToBeReceivedFromChain(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger?: Messenger, sourceProvider?: Provider, destinationProvider?: Provider): Promise<string>;
36
- getAmountToBeReceivedFromPools(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, sourcePool: PoolInfo, destinationPool: PoolInfo, messenger?: Messenger): string;
37
- getAmountToSend(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger?: Messenger): Promise<string>;
38
- getAmountToSendFromChain(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger?: Messenger, sourceProvider?: Provider, destinationProvider?: Provider): Promise<string>;
39
- getAmountToSendFromPools(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, sourcePool: PoolInfo, destinationPool: PoolInfo, messenger?: Messenger): string;
34
+ getAmountToBeReceived(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger): Promise<string>;
35
+ getAmountToBeReceivedFromChain(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger, sourceProvider?: Provider, destinationProvider?: Provider): Promise<string>;
36
+ getAmountToBeReceivedCompute(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger | undefined, sourcePool: () => Promise<PoolInfo>, destPool: () => Promise<PoolInfo>): Promise<string>;
37
+ getAmountToBeReceivedComputeWithPools(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, sourcePool: PoolInfo, destinationPool: PoolInfo): string;
38
+ getAmountToBeReceivedComputeCctp(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger.CCTP | Messenger.CCTP_V2): string;
39
+ getAmountToBeReceivedComputeOft(amountToSendFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails): Promise<string>;
40
+ getAmountToSend(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger): Promise<string>;
41
+ getAmountToSendFromChain(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger, sourceProvider?: Provider, destinationProvider?: Provider): Promise<string>;
42
+ getAmountToSendCompute(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger | undefined, sourcePool: () => Promise<PoolInfo>, destPool: () => Promise<PoolInfo>): Promise<string>;
43
+ getAmountToSendComputeWithPools(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, sourcePool: PoolInfo, destinationPool: PoolInfo): string;
44
+ getAmountToSendComputeCctp(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger.CCTP | Messenger.CCTP_V2): string;
45
+ getAmountToSendComputeOft(amountToBeReceivedFloat: number | string | Big, sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails): Promise<string>;
40
46
  getGasFeeOptions(sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger): Promise<GasFeeOptions>;
41
47
  getAverageTransferTime(sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger): number | null;
42
48
  getPoolInfoByToken(token: TokenWithChainDetails): Promise<PoolInfo>;
43
49
  refreshPoolInfo(tokens?: TokenWithChainDetails | TokenWithChainDetails[]): Promise<void>;
44
50
  aprInPercents(apr: string): string;
45
- getExtraGasMaxLimits(sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails): Promise<ExtraGasMaxLimitResponse>;
51
+ getExtraGasMaxLimits(sourceChainToken: TokenWithChainDetails, destinationChainToken: TokenWithChainDetails, messenger: Messenger): Promise<ExtraGasMaxLimitResponse>;
46
52
  getVUsdFromAmount(amount: string, amountFormat: AmountFormat, sourceToken: TokenWithChainDetails): Promise<AmountFormatted>;
47
53
  getAmountFromVUsd(vUsdAmount: string, destToken: TokenWithChainDetails): Promise<AmountFormatted>;
48
54
  private getAmountFromVUsdFormatted;