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

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 (48) hide show
  1. package/dist/browser/index.js +1 -1
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/cjs/index.js +1 -5
  4. package/dist/cjs/index.js.map +4 -4
  5. package/dist/esm/index.js +1 -1
  6. package/dist/esm/index.js.map +4 -4
  7. package/dist/src/chains/chain.enums.d.ts +5 -1
  8. package/dist/src/chains/chain.enums.js +4 -0
  9. package/dist/src/chains/chain.enums.js.map +1 -1
  10. package/dist/src/chains/index.js +6 -0
  11. package/dist/src/chains/index.js.map +1 -1
  12. package/dist/src/services/bridge/evm/index.js +1 -1
  13. package/dist/src/services/bridge/evm/index.js.map +1 -1
  14. package/dist/src/services/bridge/get-cctp-sol-token-recipient-address.js +3 -3
  15. package/dist/src/services/bridge/get-cctp-sol-token-recipient-address.js.map +1 -1
  16. package/dist/src/services/bridge/index.d.ts +2 -2
  17. package/dist/src/services/bridge/index.js +4 -6
  18. package/dist/src/services/bridge/index.js.map +1 -1
  19. package/dist/src/services/bridge/raw-bridge-transaction-builder.js +2 -2
  20. package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
  21. package/dist/src/services/bridge/sol/index.js +1 -1
  22. package/dist/src/services/bridge/sol/index.js.map +1 -1
  23. package/dist/src/services/bridge/srb/index.js +1 -1
  24. package/dist/src/services/bridge/srb/index.js.map +1 -1
  25. package/dist/src/services/bridge/sui/index.js +1 -1
  26. package/dist/src/services/bridge/sui/index.js.map +1 -1
  27. package/dist/src/services/bridge/trx/index.js +1 -1
  28. package/dist/src/services/bridge/trx/index.js.map +1 -1
  29. package/dist/src/services/bridge/utils.d.ts +10 -10
  30. package/dist/src/services/bridge/utils.js +14 -15
  31. package/dist/src/services/bridge/utils.js.map +1 -1
  32. package/dist/src/services/liquidity-pool/index.d.ts +1 -1
  33. package/dist/src/services/liquidity-pool/index.js +5 -7
  34. package/dist/src/services/liquidity-pool/index.js.map +1 -1
  35. package/dist/src/services/liquidity-pool/raw-pool-transaction-builder.js +3 -3
  36. package/dist/src/services/liquidity-pool/raw-pool-transaction-builder.js.map +1 -1
  37. package/dist/src/services/liquidity-pool/trx/index.d.ts +3 -2
  38. package/dist/src/services/liquidity-pool/trx/index.js +107 -77
  39. package/dist/src/services/liquidity-pool/trx/index.js.map +1 -1
  40. package/dist/src/services/token/index.js +9 -11
  41. package/dist/src/services/token/index.js.map +1 -1
  42. package/dist/src/version.d.ts +1 -1
  43. package/dist/src/version.js +1 -1
  44. package/dist/src/version.js.map +1 -1
  45. package/package.json +3 -2
  46. package/dist/src/utils/tronweb/lazy-load-tronweb-import.d.ts +0 -1
  47. package/dist/src/utils/tronweb/lazy-load-tronweb-import.js +0 -35
  48. package/dist/src/utils/tronweb/lazy-load-tronweb-import.js.map +0 -1
@@ -21,14 +21,14 @@ const web3_js_1 = require("@solana/web3.js");
21
21
  const stellar_sdk_1 = require("@stellar/stellar-sdk");
22
22
  const big_js_1 = require("big.js");
23
23
  const randombytes_1 = __importDefault(require("randombytes"));
24
+ const tronweb_1 = require("tronweb");
24
25
  const chains_1 = require("../../chains");
25
26
  const core_api_model_1 = require("../../client/core-api/core-api.model");
26
27
  const exceptions_1 = require("../../exceptions");
27
28
  const models_1 = require("../../models");
28
29
  const calculation_1 = require("../../utils/calculation");
29
- const lazy_load_tronweb_import_1 = require("../../utils/tronweb/lazy-load-tronweb-import");
30
30
  // 2. COMMON Realization
31
- async function formatAddress(address, from, to) {
31
+ function formatAddress(address, from, to) {
32
32
  let buffer;
33
33
  switch (from) {
34
34
  case models_1.ChainType.EVM: {
@@ -40,7 +40,7 @@ async function formatAddress(address, from, to) {
40
40
  break;
41
41
  }
42
42
  case models_1.ChainType.TRX: {
43
- buffer = await tronAddressToBuffer32(address);
43
+ buffer = tronAddressToBuffer32(address);
44
44
  break;
45
45
  }
46
46
  case models_1.ChainType.SRB: {
@@ -81,17 +81,16 @@ function evmAddressToBuffer32(address) {
81
81
  const buff = hexToBuffer(address);
82
82
  return Buffer.concat([Buffer.alloc(length - buff.length, 0), buff], length);
83
83
  }
84
- async function tronAddressToBuffer32(address) {
85
- const ethAddress = await tronAddressToEthAddress(address);
84
+ function tronAddressToBuffer32(address) {
85
+ const ethAddress = tronAddressToEthAddress(address);
86
86
  const buffer = hexToBuffer(ethAddress);
87
87
  return bufferToSize(buffer, 32);
88
88
  }
89
- async function tronAddressToEthAddress(address) {
90
- const TronWeb = await (0, lazy_load_tronweb_import_1.getTronWeb)();
91
- const bytes = TronWeb.utils.crypto.decodeBase58Address(address);
89
+ function tronAddressToEthAddress(address) {
90
+ const bytes = tronweb_1.utils.crypto.decodeBase58Address(address);
92
91
  if (!bytes)
93
92
  return "";
94
- return TronWeb.utils.bytes.byteArray2hexStr(bytes).replace(/^41/, "0x");
93
+ return tronweb_1.utils.bytes.byteArray2hexStr(bytes).replace(/^41/, "0x");
95
94
  }
96
95
  function bufferToSize(buffer, size) {
97
96
  if (buffer.length >= size) {
@@ -123,7 +122,7 @@ function getNonceBigInt() {
123
122
  return bigint;
124
123
  }
125
124
  // 2. COMMON Realization
126
- async function prepareTxSwapParams(bridgeChainType, params) {
125
+ function prepareTxSwapParams(bridgeChainType, params) {
127
126
  const txSwapParams = {};
128
127
  const sourceToken = params.sourceToken;
129
128
  txSwapParams.amount = (0, calculation_1.convertFloatAmountToInt)(params.amount, sourceToken.decimals).toFixed();
@@ -136,7 +135,7 @@ async function prepareTxSwapParams(bridgeChainType, params) {
136
135
  txSwapParams.fromTokenAddress = sourceToken.originTokenAddress;
137
136
  }
138
137
  else {
139
- txSwapParams.fromTokenAddress = await formatAddress(sourceToken.tokenAddress, bridgeChainType, bridgeChainType);
138
+ txSwapParams.fromTokenAddress = formatAddress(sourceToken.tokenAddress, bridgeChainType, bridgeChainType);
140
139
  }
141
140
  txSwapParams.toAccountAddress = params.toAccountAddress;
142
141
  if (bridgeChainType === models_1.ChainType.SUI) {
@@ -146,7 +145,7 @@ async function prepareTxSwapParams(bridgeChainType, params) {
146
145
  txSwapParams.toTokenAddress = params.destinationToken.originTokenAddress;
147
146
  }
148
147
  else {
149
- txSwapParams.toTokenAddress = await formatAddress(params.destinationToken.tokenAddress, bridgeChainType, bridgeChainType);
148
+ txSwapParams.toTokenAddress = formatAddress(params.destinationToken.tokenAddress, bridgeChainType, bridgeChainType);
150
149
  }
151
150
  txSwapParams.minimumReceiveAmount = params.minimumReceiveAmount
152
151
  ? (0, calculation_1.convertFloatAmountToInt)(params.minimumReceiveAmount, params.destinationToken.decimals).toFixed()
@@ -239,10 +238,10 @@ async function prepareTxSendParams(bridgeChainType, params, api) {
239
238
  await validateExtraGasNotExceeded(txSendParams.extraGas, txSendParams.gasFeePaymentMethod, sourceToken, params.destinationToken, api);
240
239
  }
241
240
  if (bridgeChainType !== models_1.ChainType.SUI) {
242
- txSendParams.fromTokenAddress = await formatAddress(txSendParams.fromTokenAddress, bridgeChainType, bridgeChainType);
241
+ txSendParams.fromTokenAddress = formatAddress(txSendParams.fromTokenAddress, bridgeChainType, bridgeChainType);
243
242
  }
244
- txSendParams.toAccountAddress = await formatAddress(params.toAccountAddress, toChainType, bridgeChainType);
245
- txSendParams.toTokenAddress = await formatAddress(txSendParams.toTokenAddress, toChainType, bridgeChainType);
243
+ txSendParams.toAccountAddress = formatAddress(params.toAccountAddress, toChainType, bridgeChainType);
244
+ txSendParams.toTokenAddress = formatAddress(txSendParams.toTokenAddress, toChainType, bridgeChainType);
246
245
  if (txSendParams.gasFeePaymentMethod == models_1.FeePaymentMethod.WITH_STABLECOIN) {
247
246
  validateAmountEnough(txSendParams.amount, sourceToken.decimals, txSendParams.fee, txSendParams.extraGas);
248
247
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/services/bridge/utils.ts"],"names":[],"mappings":";;;;;AA6DA,sCA8CC;AAED,0CAEC;AAED,kC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AC/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 { 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 { getTronWeb } from \"../../utils/tronweb/lazy-load-tronweb-import\";\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\";\n\n// 1. OVERLOADS\nexport async function formatAddress(\n address: string,\n from: ChainType,\n to: ChainType.EVM | ChainType.SUI\n): Promise<string>;\nexport async function formatAddress(address: string, from: ChainType, to: ChainType.TRX): Promise<Buffer>;\nexport async function formatAddress(\n address: string,\n from: ChainType,\n to: ChainType.SOLANA | ChainType.SRB\n): Promise<number[]>;\nexport async function formatAddress(\n address: string,\n from: ChainType,\n to: ChainType\n): Promise<string | number[] | Buffer>;\n\n// 2. COMMON Realization\nexport async function formatAddress(\n address: string,\n from: ChainType,\n to: ChainType\n): Promise<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 = await 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 async function tronAddressToBuffer32(address: string): Promise<Buffer> {\n const ethAddress = await tronAddressToEthAddress(address);\n const buffer = hexToBuffer(ethAddress);\n return bufferToSize(buffer, 32);\n}\n\nexport async function tronAddressToEthAddress(address: string): Promise<string> {\n const TronWeb = await getTronWeb();\n const bytes = TronWeb.utils.crypto.decodeBase58Address(address);\n if (!bytes) return \"\";\n return TronWeb.utils.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 async function prepareTxSwapParams(\n bridgeChainType: ChainType.EVM | ChainType.SUI,\n params: SwapParams\n): Promise<TxSwapParamsEvm | TxSwapParamsSui>;\nexport async function prepareTxSwapParams(bridgeChainType: ChainType.TRX, params: SwapParams): Promise<TxSwapParamsTrx>;\nexport async function prepareTxSwapParams(\n bridgeChainType: ChainType.SOLANA | ChainType.SRB,\n params: SwapParams\n): Promise<TxSwapParamsSol | TxSwapParamsSrb>;\nexport async function prepareTxSwapParams(bridgeChainType: ChainType, params: SwapParams): Promise<TxSwapParams>;\n\n// 2. COMMON Realization\nexport async function prepareTxSwapParams(bridgeChainType: ChainType, params: SwapParams): Promise<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 = await 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 = await formatAddress(\n params.destinationToken.tokenAddress,\n bridgeChainType,\n bridgeChainType\n );\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 = await formatAddress(\n txSendParams.fromTokenAddress,\n bridgeChainType,\n bridgeChainType\n );\n }\n txSendParams.toAccountAddress = await formatAddress(params.toAccountAddress, toChainType, bridgeChainType);\n txSendParams.toTokenAddress = await 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":";;;;;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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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 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"]}
@@ -94,4 +94,4 @@ export declare class DefaultLiquidityPoolService implements LiquidityPoolService
94
94
  getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails, provider?: Provider): Promise<UserBalanceInfo>;
95
95
  getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<PoolInfo>;
96
96
  }
97
- export declare function getChainPoolService(chainSymbol: string, api: AllbridgeCoreClient, nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, provider?: Provider): Promise<ChainPoolService>;
97
+ export declare function getChainPoolService(chainSymbol: string, api: AllbridgeCoreClient, nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, provider?: Provider): ChainPoolService;
@@ -7,12 +7,12 @@ exports.DefaultLiquidityPoolService = void 0;
7
7
  exports.getChainPoolService = getChainPoolService;
8
8
  const big_js_1 = require("big.js");
9
9
  const timed_cache_1 = __importDefault(require("timed-cache"));
10
+ const tronweb_1 = require("tronweb");
10
11
  const web3_1 = require("web3");
11
12
  const chains_1 = require("../../chains");
12
13
  const index_1 = require("../../index");
13
14
  const calculation_1 = require("../../utils/calculation");
14
15
  const constants_1 = require("../../utils/calculation/constants");
15
- const lazy_load_tronweb_import_1 = require("../../utils/tronweb/lazy-load-tronweb-import");
16
16
  const utils_1 = require("../../utils/utils");
17
17
  const calculation_2 = require("../utils/calculation");
18
18
  const evm_1 = require("./evm");
@@ -82,7 +82,7 @@ class DefaultLiquidityPoolService {
82
82
  return (0, calculation_1.convertIntAmountToFloat)(commonAmount, token.decimals).toFixed();
83
83
  }
84
84
  async getUserBalanceInfo(accountAddress, token, provider) {
85
- return (await getChainPoolService(token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)).getUserBalanceInfo(accountAddress, token);
85
+ return getChainPoolService(token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider).getUserBalanceInfo(accountAddress, token);
86
86
  }
87
87
  async getPoolInfoFromChain(token, provider) {
88
88
  const poolKey = { chainSymbol: token.chainSymbol, poolAddress: token.poolAddress };
@@ -91,7 +91,7 @@ class DefaultLiquidityPoolService {
91
91
  return fromCache;
92
92
  }
93
93
  else {
94
- const poolInfo = await (await getChainPoolService(token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)).getPoolInfoFromChain(token);
94
+ const poolInfo = await getChainPoolService(token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider).getPoolInfoFromChain(token);
95
95
  this.cache.put(poolKey, poolInfo);
96
96
  this.api.cachePut({ chainSymbol: token.chainSymbol, poolAddress: token.poolAddress }, poolInfo);
97
97
  return poolInfo;
@@ -99,7 +99,7 @@ class DefaultLiquidityPoolService {
99
99
  }
100
100
  }
101
101
  exports.DefaultLiquidityPoolService = DefaultLiquidityPoolService;
102
- async function getChainPoolService(chainSymbol, api, nodeRpcUrlsConfig, params, provider) {
102
+ function getChainPoolService(chainSymbol, api, nodeRpcUrlsConfig, params, provider) {
103
103
  switch (chains_1.Chains.getChainProperty(chainSymbol).chainType) {
104
104
  case index_1.ChainType.EVM: {
105
105
  if (provider) {
@@ -116,12 +116,10 @@ async function getChainPoolService(chainSymbol, api, nodeRpcUrlsConfig, params,
116
116
  const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);
117
117
  const tronJsonRpc = params.tronJsonRpc;
118
118
  if (provider) {
119
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
120
- const TronWeb = await (0, lazy_load_tronweb_import_1.getTronWeb)();
121
119
  return new trx_1.TronPoolService(provider, api, tronJsonRpc);
122
120
  }
123
121
  else {
124
- const tronWeb = new (await (0, lazy_load_tronweb_import_1.getTronWeb)())({ fullHost: nodeRpcUrl });
122
+ const tronWeb = new tronweb_1.TronWeb({ fullHost: nodeRpcUrl });
125
123
  return new trx_1.TronPoolService(tronWeb, api, tronJsonRpc);
126
124
  }
127
125
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/index.ts"],"names":[],"mappings":";;;;;;AA+MA,kDAyCC;AAxPD,mCAA6B;AAC7B,8DAAgC;AAChC,+BAAmD;AAEnD,yCAAsC;AAGtC,uCAAgF;AAEhF,yDAAuF;AACvF,iEAAqE;AACrE,2FAA0E;AAC1E,6CAAiF;AAGjF,s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C;YACnB,OAAO,IAAI,oBAAc,CAAC,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { Big } from \"big.js\";\nimport Cache from \"timed-cache\";\nimport { FMT_BYTES, FMT_NUMBER, Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreClientFiltered } from \"../../client/core-api/core-client-filtered\";\nimport { AllbridgeCoreSdkOptions, ChainType, EssentialWeb3 } from \"../../index\";\nimport { PoolInfo, PoolKeyObject, TokenWithChainDetails } from \"../../tokens-info\";\nimport { convertIntAmountToFloat, fromSystemPrecision } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { getTronWeb } from \"../../utils/tronweb/lazy-load-tronweb-import\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { depositAmountToVUsd, vUsdToWithdrawalAmount } from \"../utils/calculation\";\nimport { EvmPoolService } from \"./evm\";\nimport { ApproveParams, ChainPoolService, CheckAllowanceParams, GetAllowanceParams, UserBalanceInfo } from \"./models\";\nimport { DefaultRawPoolTransactionBuilder, RawPoolTransactionBuilder } from \"./raw-pool-transaction-builder\";\nimport { SolanaPoolService } from \"./sol\";\nimport { SrbPoolService } from \"./srb\";\nimport { SuiPoolService } from \"./sui\";\nimport { TronPoolService } from \"./trx\";\n\nexport interface LiquidityPoolService {\n rawTxBuilder: RawPoolTransactionBuilder;\n\n /**\n * Get amount of tokens approved for poolInfo\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 for poolInfo\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\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\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 RawPoolTransactionBuilder.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 * Calculates the amount of LP tokens that will be deposited\n * @param amount The float amount of tokens that will be sent\n * @param token\n * @param provider - will be used to access the network\n * @returns amount\n */\n getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string>;\n\n /**\n * Calculates the amount of tokens will be withdrawn\n * @param amount The float amount of tokens that will be sent\n * @param accountAddress\n * @param token\n * @param provider - will be used to access the network\n * @returns amount\n */\n getAmountToBeWithdrawn(\n amount: string,\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<string>;\n\n /**\n * Get User Balance Info on Liquidity poolInfo\n * @param accountAddress\n * @param token\n * @param provider\n * @returns UserBalanceInfo\n */\n getUserBalanceInfo(\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<UserBalanceInfo>;\n\n /**\n * Gets information about the poolInfo from chain\n * @param token\n * @param provider - will be used to access the network\n * @returns poolInfo\n */\n getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<Required<PoolInfo>>;\n}\n\nexport class DefaultLiquidityPoolService implements LiquidityPoolService {\n public rawTxBuilder: RawPoolTransactionBuilder;\n private cache: Cache<PoolInfo>;\n\n constructor(\n private api: AllbridgeCoreClientFiltered,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawPoolTransactionBuilder(api, nodeRpcUrlsConfig, this.params, tokenService);\n const ttl = params.cachePoolInfoChainSec > 0 ? params.cachePoolInfoChainSec * 1000 : 20 * 1000;\n this.cache = new Cache<PoolInfo>({ defaultTtl: ttl });\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n if (b) {\n const provider = a as Provider;\n const params = b;\n return await this.tokenService.getAllowance({ ...params, spender: params.token.poolAddress }, provider);\n } else {\n const params = a as GetAllowanceParams;\n return await this.tokenService.getAllowance({ ...params, spender: params.token.poolAddress });\n }\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n if (b) {\n const provider = a as Provider;\n const params = b;\n return this.tokenService.checkAllowance({ ...params, spender: params.token.poolAddress }, provider);\n } else {\n const params = a as CheckAllowanceParams;\n return this.tokenService.checkAllowance({ ...params, spender: params.token.poolAddress });\n }\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n return this.tokenService.approve(provider, { ...approveData, spender: approveData.token.poolAddress });\n }\n\n async getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string> {\n validateAmountGtZero(amount);\n validateAmountDecimals(\"amount\", amount, token.decimals);\n const pool = await this.getPoolInfoFromChain(token, provider);\n const { vUsdBalance, tokenBalance, aValue, dValue } = pool;\n const vUsd = depositAmountToVUsd(amount, aValue, dValue, tokenBalance, vUsdBalance);\n return convertIntAmountToFloat(vUsd, SYSTEM_PRECISION).toFixed();\n }\n\n async getAmountToBeWithdrawn(\n amount: string,\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<string> {\n validateAmountGtZero(amount);\n validateAmountDecimals(\"amount\", amount, token.decimals);\n const pool = await this.getPoolInfoFromChain(token, provider);\n const tokenAmountInSP = vUsdToWithdrawalAmount(amount);\n const tokenAmount = fromSystemPrecision(tokenAmountInSP, token.decimals);\n const userBalanceInfo = await this.getUserBalanceInfo(accountAddress, token, provider);\n const earned = userBalanceInfo.earned(pool) || \"0\";\n const commonAmount = Big(tokenAmount).plus(earned).toFixed();\n return convertIntAmountToFloat(commonAmount, token.decimals).toFixed();\n }\n\n async getUserBalanceInfo(\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<UserBalanceInfo> {\n return (\n await getChainPoolService(token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)\n ).getUserBalanceInfo(accountAddress, token);\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<PoolInfo> {\n const poolKey: PoolKeyObject = { chainSymbol: token.chainSymbol, poolAddress: token.poolAddress };\n const fromCache = this.cache.get(poolKey);\n if (fromCache) {\n return fromCache;\n } else {\n const poolInfo = await (\n await getChainPoolService(token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)\n ).getPoolInfoFromChain(token);\n this.cache.put(poolKey, poolInfo);\n this.api.cachePut({ chainSymbol: token.chainSymbol, poolAddress: token.poolAddress }, poolInfo);\n return poolInfo;\n }\n }\n}\n\nexport async function getChainPoolService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): Promise<ChainPoolService> {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmPoolService(provider as EssentialWeb3, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const web3 = new Web3(nodeRpcUrl);\n web3.defaultReturnFormat = { number: FMT_NUMBER.STR, bytes: FMT_BYTES.HEX };\n return new EvmPoolService(web3, api);\n }\n }\n case ChainType.TRX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const tronJsonRpc = params.tronJsonRpc;\n if (provider) {\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\n const TronWeb = await getTronWeb();\n return new TronPoolService(provider as InstanceType<typeof TronWeb>, api, tronJsonRpc);\n } else {\n const tronWeb = new (await getTronWeb())({ fullHost: nodeRpcUrl });\n return new TronPoolService(tronWeb, api, tronJsonRpc);\n }\n }\n case ChainType.SOLANA: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new SolanaPoolService(nodeRpcUrl, api);\n }\n case ChainType.SRB: {\n return new SrbPoolService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiPoolService(nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol), api);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/index.ts"],"names":[],"mappings":";;;;;;AAuNA,kDAuCC;AA9PD,mCAA6B;AAC7B,8DAAgC;AAChC,qCAAkC;AAClC,+BAAmD;AAEnD,yCAAsC;AAGtC,uCAAgF;AAEhF,yDAAuF;AACvF,iEAAqE;AACrE,6CAAiF;AAGjF,sDAAmF;AACnF,+BAAuC;AAEvC,iFAA6G;AAC7G,+BAA0C;AAC1C,+BAAuC;AACvC,+BAAuC;AACvC,+BAAwC;AA4FxC,MAAa,2BAA2B;IAK5B;IACA;IACA;IACA;IAPH,YAAY,CAA4B;IACvC,KAAK,CAAkB;IAE/B,YACU,GAAgC,EAChC,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAA6B;QAChC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB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C;YAChE,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;YACvC,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,IAAI,qBAAe,CAAC,QAAmB,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;YACpE,CAAC;iBAAM,CAAC;gBACN,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;gBACtD,OAAO,IAAI,qBAAe,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;QACD,KAAK,iBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YACtB,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAChE,OAAO,IAAI,uBAAiB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAChD,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,oBAAc,CAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5D,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,oBAAc,CAAC,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { Big } from \"big.js\";\nimport Cache from \"timed-cache\";\nimport { TronWeb } from \"tronweb\";\nimport { FMT_BYTES, FMT_NUMBER, Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreClientFiltered } from \"../../client/core-api/core-client-filtered\";\nimport { AllbridgeCoreSdkOptions, ChainType, EssentialWeb3 } from \"../../index\";\nimport { PoolInfo, PoolKeyObject, TokenWithChainDetails } from \"../../tokens-info\";\nimport { convertIntAmountToFloat, fromSystemPrecision } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { depositAmountToVUsd, vUsdToWithdrawalAmount } from \"../utils/calculation\";\nimport { EvmPoolService } from \"./evm\";\nimport { ApproveParams, ChainPoolService, CheckAllowanceParams, GetAllowanceParams, UserBalanceInfo } from \"./models\";\nimport { DefaultRawPoolTransactionBuilder, RawPoolTransactionBuilder } from \"./raw-pool-transaction-builder\";\nimport { SolanaPoolService } from \"./sol\";\nimport { SrbPoolService } from \"./srb\";\nimport { SuiPoolService } from \"./sui\";\nimport { TronPoolService } from \"./trx\";\n\nexport interface LiquidityPoolService {\n rawTxBuilder: RawPoolTransactionBuilder;\n\n /**\n * Get amount of tokens approved for poolInfo\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 for poolInfo\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\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\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 RawPoolTransactionBuilder.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 * Calculates the amount of LP tokens that will be deposited\n * @param amount The float amount of tokens that will be sent\n * @param token\n * @param provider - will be used to access the network\n * @returns amount\n */\n getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string>;\n\n /**\n * Calculates the amount of tokens will be withdrawn\n * @param amount The float amount of tokens that will be sent\n * @param accountAddress\n * @param token\n * @param provider - will be used to access the network\n * @returns amount\n */\n getAmountToBeWithdrawn(\n amount: string,\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<string>;\n\n /**\n * Get User Balance Info on Liquidity poolInfo\n * @param accountAddress\n * @param token\n * @param provider\n * @returns UserBalanceInfo\n */\n getUserBalanceInfo(\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<UserBalanceInfo>;\n\n /**\n * Gets information about the poolInfo from chain\n * @param token\n * @param provider - will be used to access the network\n * @returns poolInfo\n */\n getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<Required<PoolInfo>>;\n}\n\nexport class DefaultLiquidityPoolService implements LiquidityPoolService {\n public rawTxBuilder: RawPoolTransactionBuilder;\n private cache: Cache<PoolInfo>;\n\n constructor(\n private api: AllbridgeCoreClientFiltered,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawPoolTransactionBuilder(api, nodeRpcUrlsConfig, this.params, tokenService);\n const ttl = params.cachePoolInfoChainSec > 0 ? params.cachePoolInfoChainSec * 1000 : 20 * 1000;\n this.cache = new Cache<PoolInfo>({ defaultTtl: ttl });\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n if (b) {\n const provider = a as Provider;\n const params = b;\n return await this.tokenService.getAllowance({ ...params, spender: params.token.poolAddress }, provider);\n } else {\n const params = a as GetAllowanceParams;\n return await this.tokenService.getAllowance({ ...params, spender: params.token.poolAddress });\n }\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n if (b) {\n const provider = a as Provider;\n const params = b;\n return this.tokenService.checkAllowance({ ...params, spender: params.token.poolAddress }, provider);\n } else {\n const params = a as CheckAllowanceParams;\n return this.tokenService.checkAllowance({ ...params, spender: params.token.poolAddress });\n }\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n return this.tokenService.approve(provider, { ...approveData, spender: approveData.token.poolAddress });\n }\n\n async getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string> {\n validateAmountGtZero(amount);\n validateAmountDecimals(\"amount\", amount, token.decimals);\n const pool = await this.getPoolInfoFromChain(token, provider);\n const { vUsdBalance, tokenBalance, aValue, dValue } = pool;\n const vUsd = depositAmountToVUsd(amount, aValue, dValue, tokenBalance, vUsdBalance);\n return convertIntAmountToFloat(vUsd, SYSTEM_PRECISION).toFixed();\n }\n\n async getAmountToBeWithdrawn(\n amount: string,\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<string> {\n validateAmountGtZero(amount);\n validateAmountDecimals(\"amount\", amount, token.decimals);\n const pool = await this.getPoolInfoFromChain(token, provider);\n const tokenAmountInSP = vUsdToWithdrawalAmount(amount);\n const tokenAmount = fromSystemPrecision(tokenAmountInSP, token.decimals);\n const userBalanceInfo = await this.getUserBalanceInfo(accountAddress, token, provider);\n const earned = userBalanceInfo.earned(pool) || \"0\";\n const commonAmount = Big(tokenAmount).plus(earned).toFixed();\n return convertIntAmountToFloat(commonAmount, token.decimals).toFixed();\n }\n\n async getUserBalanceInfo(\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<UserBalanceInfo> {\n return getChainPoolService(\n token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).getUserBalanceInfo(accountAddress, token);\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<PoolInfo> {\n const poolKey: PoolKeyObject = { chainSymbol: token.chainSymbol, poolAddress: token.poolAddress };\n const fromCache = this.cache.get(poolKey);\n if (fromCache) {\n return fromCache;\n } else {\n const poolInfo = await getChainPoolService(\n token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).getPoolInfoFromChain(token);\n this.cache.put(poolKey, poolInfo);\n this.api.cachePut({ chainSymbol: token.chainSymbol, poolAddress: token.poolAddress }, poolInfo);\n return poolInfo;\n }\n }\n}\n\nexport function getChainPoolService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): ChainPoolService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmPoolService(provider as EssentialWeb3, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const web3 = new Web3(nodeRpcUrl);\n web3.defaultReturnFormat = { number: FMT_NUMBER.STR, bytes: FMT_BYTES.HEX };\n return new EvmPoolService(web3, api);\n }\n }\n case ChainType.TRX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const tronJsonRpc = params.tronJsonRpc;\n if (provider) {\n return new TronPoolService(provider as TronWeb, api, tronJsonRpc);\n } else {\n const tronWeb = new TronWeb({ fullHost: nodeRpcUrl });\n return new TronPoolService(tronWeb, api, tronJsonRpc);\n }\n }\n case ChainType.SOLANA: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new SolanaPoolService(nodeRpcUrl, api);\n }\n case ChainType.SRB: {\n return new SrbPoolService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiPoolService(nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol), api);\n }\n }\n}\n"]}
@@ -37,16 +37,16 @@ class DefaultRawPoolTransactionBuilder {
37
37
  (0, utils_1.validateAmountGtZero)(params.amount);
38
38
  (0, utils_1.validateAmountDecimals)("amount", params.amount, params.token.decimals);
39
39
  params.amount = (0, calculation_1.convertFloatAmountToInt)(params.amount, params.token.decimals).toFixed();
40
- return (await (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)).buildRawTransactionDeposit(params);
40
+ return (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider).buildRawTransactionDeposit(params);
41
41
  }
42
42
  async withdraw(params, provider) {
43
43
  (0, utils_1.validateAmountGtZero)(params.amount);
44
44
  (0, utils_1.validateAmountDecimals)("amount", params.amount, params.token.decimals);
45
45
  params.amount = (0, calculation_1.convertFloatAmountToInt)(params.amount, constants_1.SYSTEM_PRECISION).toFixed();
46
- return (await (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)).buildRawTransactionWithdraw(params);
46
+ return (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider).buildRawTransactionWithdraw(params);
47
47
  }
48
48
  async claimRewards(params, provider) {
49
- return (await (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)).buildRawTransactionClaimRewards(params);
49
+ return (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider).buildRawTransactionClaimRewards(params);
50
50
  }
51
51
  }
52
52
  exports.DefaultRawPoolTransactionBuilder = DefaultRawPoolTransactionBuilder;
@@ -1 +1 @@
1
- {"version":3,"file":"raw-pool-transaction-builder.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/raw-pool-transaction-builder.ts"],"names":[],"mappings":";;;AAGA,yDAAkE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AC,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7G,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAsC,EAAE,QAAmB;QACxE,IAAA,4BAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,IAAA,8BAAsB,EAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvE,MAAM,CAAC,MAAM,GAAG,IAAA,qCAAuB,EAAC,MAAM,CAAC,MAAM,EAAE,4BAAgB,CAAC,CAAC,OAAO,EAAE,CAAC;QACnF,OAAO,CACL,MAAM,IAAA,2BAAmB,EAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7G,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAA4B,EAAE,QAAmB;QAClE,OAAO,CACL,MAAM,IAAA,2BAAmB,EAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7G,CAAC,+BAA+B,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF;AAnDD,4EAmDC","sourcesContent":["import { NodeRpcUrlsConfig } from \"..\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions } from \"../../index\";\nimport { convertFloatAmountToInt } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, RawTransaction } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { ApproveParams, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount } from \"./models\";\nimport { getChainPoolService } from \"./index\";\n\nexport interface RawPoolTransactionBuilder {\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 /**\n * Creates a Raw Transaction for depositing tokens to Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for withdrawing tokens from Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for claiming rewards from Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction>;\n}\n\nexport class DefaultRawPoolTransactionBuilder implements RawPoolTransactionBuilder {\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 if (b) {\n const provider = a as Provider;\n const approveData: ApproveParams = b;\n return this.tokenService.buildRawTransactionApprove(\n {\n ...approveData,\n spender: approveData.token.poolAddress,\n },\n provider\n );\n } else {\n const approveData: ApproveParams = a as ApproveParams;\n return this.tokenService.buildRawTransactionApprove({\n ...approveData,\n spender: approveData.token.poolAddress,\n });\n }\n }\n\n async deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n params.amount = convertFloatAmountToInt(params.amount, params.token.decimals).toFixed();\n return (\n await getChainPoolService(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)\n ).buildRawTransactionDeposit(params);\n }\n\n async withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n params.amount = convertFloatAmountToInt(params.amount, SYSTEM_PRECISION).toFixed();\n return (\n await getChainPoolService(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)\n ).buildRawTransactionWithdraw(params);\n }\n\n async claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction> {\n return (\n await getChainPoolService(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)\n ).buildRawTransactionClaimRewards(params);\n }\n}\n"]}
1
+ {"version":3,"file":"raw-pool-transaction-builder.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/raw-pool-transaction-builder.ts"],"names":[],"mappings":";;;AAGA,yDAAkE;AAClE,iEAAqE;AACrE,6CAAiF;AAIjF,mCAA8C;AAqC9C,MAAa,gCAAgC;IAEjC;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,CAAC,EAAE,CAAC;YACN,MAAM,QAAQ,GAAG,CAAa,CAAC;YAC/B,MAAM,WAAW,GAAkB,CAAC,CAAC;YACrC,OAAO,IAAI,CAAC,YAAY,CAAC,0BAA0B,CACj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M,CAAC,KAAK,CAAC,WAAW,EACxB,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,EACX,QAAQ,CACT,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAA4B,EAAE,QAAmB;QAClE,OAAO,IAAA,2BAAmB,EACxB,MAAM,CAAC,KAAK,CAAC,WAAW,EACxB,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,EACX,QAAQ,CACT,CAAC,+BAA+B,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF;AA/DD,4EA+DC","sourcesContent":["import { NodeRpcUrlsConfig } from \"..\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions } from \"../../index\";\nimport { convertFloatAmountToInt } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, RawTransaction } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { ApproveParams, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount } from \"./models\";\nimport { getChainPoolService } from \"./index\";\n\nexport interface RawPoolTransactionBuilder {\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 /**\n * Creates a Raw Transaction for depositing tokens to Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for withdrawing tokens from Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for claiming rewards from Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction>;\n}\n\nexport class DefaultRawPoolTransactionBuilder implements RawPoolTransactionBuilder {\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 if (b) {\n const provider = a as Provider;\n const approveData: ApproveParams = b;\n return this.tokenService.buildRawTransactionApprove(\n {\n ...approveData,\n spender: approveData.token.poolAddress,\n },\n provider\n );\n } else {\n const approveData: ApproveParams = a as ApproveParams;\n return this.tokenService.buildRawTransactionApprove({\n ...approveData,\n spender: approveData.token.poolAddress,\n });\n }\n }\n\n async deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n params.amount = convertFloatAmountToInt(params.amount, params.token.decimals).toFixed();\n return getChainPoolService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionDeposit(params);\n }\n\n async withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n params.amount = convertFloatAmountToInt(params.amount, SYSTEM_PRECISION).toFixed();\n return getChainPoolService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionWithdraw(params);\n }\n\n async claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction> {\n return getChainPoolService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionClaimRewards(params);\n }\n}\n"]}
@@ -3,13 +3,13 @@ import { ChainType } from "../../../chains/chain.enums";
3
3
  import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
4
4
  import { PoolInfo, TokenWithChainDetails } from "../../../tokens-info";
5
5
  import { RawTransaction } from "../../models";
6
- import { LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalanceInfo, ChainPoolService } from "../models";
6
+ import { ChainPoolService, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalanceInfo } from "../models";
7
7
  export declare class TronPoolService extends ChainPoolService {
8
8
  tronWeb: TronWeb;
9
9
  api: AllbridgeCoreClient;
10
+ private readonly tronJsonRpc;
10
11
  chainType: ChainType.TRX;
11
12
  private P;
12
- private web3;
13
13
  constructor(tronWeb: TronWeb, api: AllbridgeCoreClient, tronJsonRpc: string | undefined);
14
14
  getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo>;
15
15
  private getUserBalanceInfoByBatch;
@@ -22,4 +22,5 @@ export declare class TronPoolService extends ChainPoolService {
22
22
  buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction>;
23
23
  private buildRawTransaction;
24
24
  private getContract;
25
+ private getFunctionAbi;
25
26
  }