@allbridge/bridge-core-sdk 3.22.1-alpha.1 → 3.22.1-alpha.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.
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +5 -5
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +3 -3
- package/dist/src/services/bridge/index.js +3 -2
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/utils.js +3 -3
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +3 -2
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/trx/index.d.ts +3 -2
- package/dist/src/services/liquidity-pool/trx/index.js +107 -77
- package/dist/src/services/liquidity-pool/trx/index.js.map +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x1/ascii/structs.d.ts +2 -2
- package/dist/src/services/models/sui/_dependencies/source/0x1/bit-vector/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x1/fixed-point32/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x1/string/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x1/type-name/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x1/uq32-32/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x1/uq64-64/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb/burn-message/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb/handle-receive-message/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb/message-transmitter-authenticator/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb/state/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917/mint-allowance/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917/treasury/structs.d.ts +4 -4
- package/dist/src/services/models/sui/_dependencies/source/0x4931e06dce648b3931f890035bd196920770e913e43e45990b383f6486fdd0a5/message/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0x4931e06dce648b3931f890035bd196920770e913e43e45990b383f6486fdd0a5/state/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes20/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed-vaas/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/emitter/structs.d.ts +2 -2
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external-address/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/fee-collector/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/guardian/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/guardian-set/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/publish-message/structs.d.ts +2 -2
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set/structs.d.ts +2 -2
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/state/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/vaa/structs.d.ts +1 -1
- package/dist/src/services/models/sui/_framework/util.d.ts +3 -30
- package/dist/src/services/models/sui/_framework/vector.d.ts +2 -2
- package/dist/src/services/models/sui/bridge/another-bridge/functions.d.ts +9 -9
- package/dist/src/services/models/sui/bridge/another-bridge/structs.d.ts +1 -1
- package/dist/src/services/models/sui/bridge/bridge/functions.d.ts +31 -31
- package/dist/src/services/models/sui/bridge/bridge/structs.d.ts +4 -4
- package/dist/src/services/models/sui/bridge/bridge-interface/functions.d.ts +54 -54
- package/dist/src/services/models/sui/bridge/events/functions.d.ts +9 -9
- package/dist/src/services/models/sui/bridge/events/structs.d.ts +9 -9
- package/dist/src/services/models/sui/bridge/pool/functions.d.ts +26 -26
- package/dist/src/services/models/sui/bridge/pool/structs.d.ts +3 -3
- package/dist/src/services/models/sui/bridge/pool-rewards/functions.d.ts +10 -10
- package/dist/src/services/models/sui/bridge/pool-rewards/structs.d.ts +1 -1
- package/dist/src/services/models/sui/bridge/pool-state/functions.d.ts +21 -21
- package/dist/src/services/models/sui/bridge/pool-state/structs.d.ts +1 -1
- package/dist/src/services/models/sui/bridge/user-deposit/functions.d.ts +7 -7
- package/dist/src/services/models/sui/bridge/user-deposit/structs.d.ts +1 -1
- package/dist/src/services/models/sui/cctp-bridge/cctp-bridge/functions.d.ts +19 -19
- package/dist/src/services/models/sui/cctp-bridge/cctp-bridge/structs.d.ts +3 -3
- package/dist/src/services/models/sui/cctp-bridge/cctp-bridge-interface/functions.d.ts +15 -15
- package/dist/src/services/models/sui/cctp-bridge/events/functions.d.ts +4 -4
- package/dist/src/services/models/sui/cctp-bridge/events/structs.d.ts +4 -4
- package/dist/src/services/models/sui/cctp-bridge/message-transmitter-authenticator/functions.d.ts +1 -1
- package/dist/src/services/models/sui/cctp-bridge/message-transmitter-authenticator/structs.d.ts +1 -1
- package/dist/src/services/models/sui/gas-oracle/gas-oracle/functions.d.ts +16 -16
- package/dist/src/services/models/sui/gas-oracle/gas-oracle/structs.d.ts +3 -3
- package/dist/src/services/models/sui/gas-oracle/gas-oracle-interface/functions.d.ts +13 -13
- package/dist/src/services/models/sui/messenger/events/functions.d.ts +2 -2
- package/dist/src/services/models/sui/messenger/events/structs.d.ts +2 -2
- package/dist/src/services/models/sui/messenger/messenger/functions.d.ts +18 -18
- package/dist/src/services/models/sui/messenger/messenger/structs.d.ts +2 -2
- package/dist/src/services/models/sui/messenger/messenger-interface/functions.d.ts +15 -15
- package/dist/src/services/models/sui/sui/address/functions.d.ts +10 -10
- package/dist/src/services/models/sui/sui/authenticator-state/functions.d.ts +13 -13
- package/dist/src/services/models/sui/sui/authenticator-state/structs.d.ts +5 -5
- package/dist/src/services/models/sui/sui/bag/functions.d.ts +10 -10
- package/dist/src/services/models/sui/sui/bag/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/balance/functions.d.ts +13 -13
- package/dist/src/services/models/sui/sui/balance/structs.d.ts +2 -2
- package/dist/src/services/models/sui/sui/bcs/functions.d.ts +29 -29
- package/dist/src/services/models/sui/sui/bcs/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/bls12381/functions.d.ts +43 -43
- package/dist/src/services/models/sui/sui/bls12381/structs.d.ts +5 -5
- package/dist/src/services/models/sui/sui/borrow/functions.d.ts +4 -4
- package/dist/src/services/models/sui/sui/clock/functions.d.ts +3 -3
- package/dist/src/services/models/sui/sui/clock/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/coin/functions.d.ts +45 -45
- package/dist/src/services/models/sui/sui/coin/structs.d.ts +7 -7
- package/dist/src/services/models/sui/sui/config/functions.d.ts +11 -11
- package/dist/src/services/models/sui/sui/deny-list/functions.d.ts +21 -21
- package/dist/src/services/models/sui/sui/deny-list/structs.d.ts +7 -7
- package/dist/src/services/models/sui/sui/display/functions.d.ts +13 -13
- package/dist/src/services/models/sui/sui/display/structs.d.ts +3 -3
- package/dist/src/services/models/sui/sui/dynamic-field/functions.d.ts +16 -16
- package/dist/src/services/models/sui/sui/dynamic-object-field/functions.d.ts +12 -12
- package/dist/src/services/models/sui/sui/ecdsa-k1/functions.d.ts +3 -3
- package/dist/src/services/models/sui/sui/ecdsa-r1/functions.d.ts +2 -2
- package/dist/src/services/models/sui/sui/ecvrf/functions.d.ts +1 -1
- package/dist/src/services/models/sui/sui/ed25519/functions.d.ts +1 -1
- package/dist/src/services/models/sui/sui/event/functions.d.ts +1 -1
- package/dist/src/services/models/sui/sui/groth16/functions.d.ts +10 -10
- package/dist/src/services/models/sui/sui/groth16/structs.d.ts +4 -4
- package/dist/src/services/models/sui/sui/group-ops/functions.d.ts +23 -23
- package/dist/src/services/models/sui/sui/group-ops/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/hash/functions.d.ts +2 -2
- package/dist/src/services/models/sui/sui/hex/functions.d.ts +3 -3
- package/dist/src/services/models/sui/sui/hmac/functions.d.ts +1 -1
- package/dist/src/services/models/sui/sui/kiosk/functions.d.ts +41 -41
- package/dist/src/services/models/sui/sui/kiosk/structs.d.ts +10 -10
- package/dist/src/services/models/sui/sui/kiosk-extension/functions.d.ts +14 -14
- package/dist/src/services/models/sui/sui/kiosk-extension/structs.d.ts +2 -2
- package/dist/src/services/models/sui/sui/linked-table/functions.d.ts +17 -17
- package/dist/src/services/models/sui/sui/math/functions.d.ts +7 -7
- package/dist/src/services/models/sui/sui/object/functions.d.ts +24 -24
- package/dist/src/services/models/sui/sui/object/structs.d.ts +2 -2
- package/dist/src/services/models/sui/sui/object-bag/functions.d.ts +11 -11
- package/dist/src/services/models/sui/sui/object-bag/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/object-table/functions.d.ts +10 -10
- package/dist/src/services/models/sui/sui/object-table/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/package/functions.d.ts +24 -24
- package/dist/src/services/models/sui/sui/package/structs.d.ts +4 -4
- package/dist/src/services/models/sui/sui/pay/functions.d.ts +8 -8
- package/dist/src/services/models/sui/sui/poseidon/functions.d.ts +2 -2
- package/dist/src/services/models/sui/sui/priority-queue/functions.d.ts +8 -8
- package/dist/src/services/models/sui/sui/random/functions.d.ts +23 -23
- package/dist/src/services/models/sui/sui/random/structs.d.ts +3 -3
- package/dist/src/services/models/sui/sui/sui/functions.d.ts +2 -2
- package/dist/src/services/models/sui/sui/sui/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/table/functions.d.ts +10 -10
- package/dist/src/services/models/sui/sui/table/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/table-vec/functions.d.ts +12 -12
- package/dist/src/services/models/sui/sui/table-vec/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/token/functions.d.ts +45 -45
- package/dist/src/services/models/sui/sui/token/structs.d.ts +6 -6
- package/dist/src/services/models/sui/sui/transfer/functions.d.ts +13 -13
- package/dist/src/services/models/sui/sui/transfer/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/transfer-policy/functions.d.ts +18 -18
- package/dist/src/services/models/sui/sui/transfer-policy/structs.d.ts +6 -6
- package/dist/src/services/models/sui/sui/tx-context/functions.d.ts +7 -7
- package/dist/src/services/models/sui/sui/tx-context/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/types/functions.d.ts +1 -1
- package/dist/src/services/models/sui/sui/url/functions.d.ts +4 -4
- package/dist/src/services/models/sui/sui/url/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/vdf/functions.d.ts +4 -4
- package/dist/src/services/models/sui/sui/vec-map/functions.d.ts +19 -19
- package/dist/src/services/models/sui/sui/vec-set/functions.d.ts +12 -12
- package/dist/src/services/models/sui/sui/versioned/functions.d.ts +7 -7
- package/dist/src/services/models/sui/sui/versioned/structs.d.ts +2 -2
- package/dist/src/services/models/sui/sui/zklogin-verified-id/functions.d.ts +9 -9
- package/dist/src/services/models/sui/sui/zklogin-verified-id/structs.d.ts +1 -1
- package/dist/src/services/models/sui/sui/zklogin-verified-issuer/functions.d.ts +6 -6
- package/dist/src/services/models/sui/sui/zklogin-verified-issuer/structs.d.ts +1 -1
- package/dist/src/services/models/sui/utils/bytes32/functions.d.ts +14 -14
- package/dist/src/services/models/sui/utils/bytes32/structs.d.ts +1 -1
- package/dist/src/services/models/sui/utils/fee-collector/functions.d.ts +5 -5
- package/dist/src/services/models/sui/utils/fee-collector/structs.d.ts +1 -1
- package/dist/src/services/models/sui/utils/message/functions.d.ts +9 -9
- package/dist/src/services/models/sui/utils/message/structs.d.ts +1 -1
- package/dist/src/services/models/sui/utils/messenger-protocol/functions.d.ts +3 -3
- package/dist/src/services/models/sui/utils/messenger-protocol/structs.d.ts +1 -1
- package/dist/src/services/models/sui/utils/set/functions.d.ts +5 -5
- package/dist/src/services/models/sui/utils/set/structs.d.ts +2 -2
- package/dist/src/services/models/sui/utils/version/functions.d.ts +3 -3
- package/dist/src/services/models/sui/utils/version/structs.d.ts +1 -1
- package/dist/src/services/models/sui/wormhole-messenger/events/functions.d.ts +2 -2
- package/dist/src/services/models/sui/wormhole-messenger/events/structs.d.ts +2 -2
- package/dist/src/services/models/sui/wormhole-messenger/wh-messenger-interface/functions.d.ts +15 -15
- package/dist/src/services/models/sui/wormhole-messenger/wormhole-messenger/functions.d.ts +20 -20
- package/dist/src/services/models/sui/wormhole-messenger/wormhole-messenger/structs.d.ts +2 -2
- package/dist/src/services/token/index.js +3 -2
- package/dist/src/services/token/index.js.map +1 -1
- package/dist/src/utils/tronweb/lazy-load-tronweb-import.d.ts +1 -1
- package/dist/src/utils/tronweb/lazy-load-tronweb-import.js +2 -2
- package/dist/src/utils/tronweb/lazy-load-tronweb-import.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +8 -8
|
@@ -101,12 +101,13 @@ async function getChainBridgeService(chainSymbol, api, nodeRpcUrlsConfig, params
|
|
|
101
101
|
case index_1.ChainType.TRX: {
|
|
102
102
|
if (provider) {
|
|
103
103
|
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
104
|
-
const TronWeb = await (0, lazy_load_tronweb_import_1.
|
|
104
|
+
const { TronWeb } = await (0, lazy_load_tronweb_import_1.getTronWebModuleDefault)();
|
|
105
105
|
return new trx_1.TronBridgeService(provider, api);
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
108
|
const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);
|
|
109
|
-
|
|
109
|
+
const { TronWeb } = await (0, lazy_load_tronweb_import_1.getTronWebModuleDefault)();
|
|
110
|
+
return new trx_1.TronBridgeService(new TronWeb({
|
|
110
111
|
fullHost: nodeRpcUrl,
|
|
111
112
|
solidityNode: nodeRpcUrl,
|
|
112
113
|
eventServer: nodeRpcUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/bridge/index.ts"],"names":[],"mappings":";;;AAmIA,gCAgBC;AAED,sDAwDC;AA7MD,+BAA4B;AAE5B,yCAAsC;AACtC,yEAAiE;AAEjE,iDAA6D;AAC7D,uCAA6F;AAE7F,2FAA0E;AAC1E,6CAAiF;AAGjF,+BAAyC;AAEzC,qFAAmH;AACnH,+BAA4C;AAC5C,+BAAyC;AACzC,+BAAyC;AACzC,+BAA0C;AAuD1C,MAAa,oBAAoB;IAIrB;IACA;IACA;IACA;IANH,YAAY,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M,CAAC,CAAC,CAAC;YACtB,OAAO,IAAI,yBAAmB,CAC5B,iBAAiB,CAAC,aAAa,CAAC,mBAAW,CAAC,GAAG,CAAC,EAChD;gBACE,0BAA0B,EAAE,MAAM,CAAC,0BAA0B;gBAC7D,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;gBAC3C,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,aAAa,EAAE;oBACb,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;oBAC/C,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;iBAC9C;aACF,EACD,GAAG,CACJ,CAAC;QACJ,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,sBAAgB,CAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,sBAAgB,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { Messenger } from \"../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { CCTPDoesNotSupportedError } from \"../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainSymbol, ChainType, EssentialWeb3 } from \"../../index\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\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 { EvmBridgeService } from \"./evm\";\nimport { ApproveParams, ChainBridgeService, CheckAllowanceParams, GetAllowanceParams, SendParams } from \"./models\";\nimport { DefaultRawBridgeTransactionBuilder, RawBridgeTransactionBuilder } from \"./raw-bridge-transaction-builder\";\nimport { SolanaBridgeService } from \"./sol\";\nimport { SrbBridgeService } from \"./srb\";\nimport { SuiBridgeService } from \"./sui\";\nimport { TronBridgeService } from \"./trx\";\n\nexport interface BridgeService {\n rawTxBuilder: RawBridgeTransactionBuilder;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param provider - will be used to access the network\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: GetAllowanceParams): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param provider - will be used to access the network\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.approve}<p>\n * Approve tokens usage by another address on chains\n * <p>\n * For ETH/USDT: due to specificity of the USDT contract:<br/>\n * If the current allowance is not 0, this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.send}<p>\n * Send tokens through the ChainBridgeService\n * @param provider - will be used to access the network\n * @param params\n */\n send(provider: Provider, params: SendParams): Promise<TransactionResponse>;\n}\n\nexport class DefaultBridgeService implements BridgeService {\n public rawTxBuilder: RawBridgeTransactionBuilder;\n\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawBridgeTransactionBuilder(api, nodeRpcUrlsConfig, params, tokenService);\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n let provider: Provider | undefined;\n let params: GetAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as GetAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger);\n return await this.tokenService.getAllowance({ ...params, spender }, provider);\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n let provider: Provider | undefined;\n let params: CheckAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as CheckAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger);\n return this.tokenService.checkAllowance({ ...params, spender }, provider);\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n const spender = getSpender(approveData.token, approveData.messenger);\n return this.tokenService.approve(provider, { ...approveData, spender });\n }\n\n async send(provider: Provider, params: SendParams): Promise<TransactionResponse> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.sourceToken.decimals);\n return (\n await getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n )\n ).send(params);\n }\n}\n\nexport function getSpender(token: TokenWithChainDetails, messenger?: Messenger): string {\n if (messenger && messenger == Messenger.CCTP) {\n if (token.cctpAddress) {\n return token.cctpAddress;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n } else if (messenger && messenger == Messenger.CCTP_V2) {\n if (token.cctpV2Address) {\n return token.cctpV2Address;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n } else {\n return token.bridgeAddress;\n }\n}\n\nexport async function getChainBridgeService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): Promise<ChainBridgeService> {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmBridgeService(provider as EssentialWeb3, api, nodeRpcUrlsConfig);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new EvmBridgeService(new Web3(nodeRpcUrl), api, nodeRpcUrlsConfig);\n }\n }\n case ChainType.TRX: {\n if (provider) {\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\n const TronWeb = await getTronWeb();\n return new TronBridgeService(provider as InstanceType<typeof TronWeb>, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new TronBridgeService(\n new (await getTronWeb())({\n fullHost: nodeRpcUrl,\n solidityNode: nodeRpcUrl,\n eventServer: nodeRpcUrl,\n }),\n api\n );\n }\n }\n case ChainType.SOLANA: {\n return new SolanaBridgeService(\n nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL),\n {\n wormholeMessengerProgramId: params.wormholeMessengerProgramId,\n solanaLookUpTable: params.solanaLookUpTable,\n cctpParams: params.cctpParams,\n jupiterParams: {\n jupiterUrl: params.jupiterUrl,\n jupiterApiKeyHeader: params.jupiterApiKeyHeader,\n jupiterMaxAccounts: params.jupiterMaxAccounts,\n },\n },\n api\n );\n }\n case ChainType.SRB: {\n return new SrbBridgeService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiBridgeService(nodeRpcUrlsConfig, api);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/bridge/index.ts"],"names":[],"mappings":";;;AAmIA,gCAgBC;AAED,sDAyDC;AA9MD,+BAA4B;A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;gBAChE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAA,kDAAuB,GAAE,CAAC;gBACpD,OAAO,IAAI,uBAAiB,CAC1B,IAAI,OAAO,CAAC;oBACV,QAAQ,EAAE,UAAU;oBACpB,YAAY,EAAE,UAAU;oBACxB,WAAW,EAAE,UAAU;iBACxB,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC;QACH,CAAC;QACD,KAAK,iBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YACtB,OAAO,IAAI,yBAAmB,CAC5B,iBAAiB,CAAC,aAAa,CAAC,mBAAW,CAAC,GAAG,CAAC,EAChD;gBACE,0BAA0B,EAAE,MAAM,CAAC,0BAA0B;gBAC7D,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;gBAC3C,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,aAAa,EAAE;oBACb,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;oBAC/C,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;iBAC9C;aACF,EACD,GAAG,CACJ,CAAC;QACJ,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,sBAAgB,CAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,sBAAgB,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { Messenger } from \"../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { CCTPDoesNotSupportedError } from \"../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainSymbol, ChainType, EssentialWeb3 } from \"../../index\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\nimport { getTronWebModuleDefault } from \"../../utils/tronweb/lazy-load-tronweb-import\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { EvmBridgeService } from \"./evm\";\nimport { ApproveParams, ChainBridgeService, CheckAllowanceParams, GetAllowanceParams, SendParams } from \"./models\";\nimport { DefaultRawBridgeTransactionBuilder, RawBridgeTransactionBuilder } from \"./raw-bridge-transaction-builder\";\nimport { SolanaBridgeService } from \"./sol\";\nimport { SrbBridgeService } from \"./srb\";\nimport { SuiBridgeService } from \"./sui\";\nimport { TronBridgeService } from \"./trx\";\n\nexport interface BridgeService {\n rawTxBuilder: RawBridgeTransactionBuilder;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param provider - will be used to access the network\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: GetAllowanceParams): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param provider - will be used to access the network\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.approve}<p>\n * Approve tokens usage by another address on chains\n * <p>\n * For ETH/USDT: due to specificity of the USDT contract:<br/>\n * If the current allowance is not 0, this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.send}<p>\n * Send tokens through the ChainBridgeService\n * @param provider - will be used to access the network\n * @param params\n */\n send(provider: Provider, params: SendParams): Promise<TransactionResponse>;\n}\n\nexport class DefaultBridgeService implements BridgeService {\n public rawTxBuilder: RawBridgeTransactionBuilder;\n\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawBridgeTransactionBuilder(api, nodeRpcUrlsConfig, params, tokenService);\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n let provider: Provider | undefined;\n let params: GetAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as GetAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger);\n return await this.tokenService.getAllowance({ ...params, spender }, provider);\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n let provider: Provider | undefined;\n let params: CheckAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as CheckAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger);\n return this.tokenService.checkAllowance({ ...params, spender }, provider);\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n const spender = getSpender(approveData.token, approveData.messenger);\n return this.tokenService.approve(provider, { ...approveData, spender });\n }\n\n async send(provider: Provider, params: SendParams): Promise<TransactionResponse> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.sourceToken.decimals);\n return (\n await getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n )\n ).send(params);\n }\n}\n\nexport function getSpender(token: TokenWithChainDetails, messenger?: Messenger): string {\n if (messenger && messenger == Messenger.CCTP) {\n if (token.cctpAddress) {\n return token.cctpAddress;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n } else if (messenger && messenger == Messenger.CCTP_V2) {\n if (token.cctpV2Address) {\n return token.cctpV2Address;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n } else {\n return token.bridgeAddress;\n }\n}\n\nexport async function getChainBridgeService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): Promise<ChainBridgeService> {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmBridgeService(provider as EssentialWeb3, api, nodeRpcUrlsConfig);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new EvmBridgeService(new Web3(nodeRpcUrl), api, nodeRpcUrlsConfig);\n }\n }\n case ChainType.TRX: {\n if (provider) {\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\n const { TronWeb } = await getTronWebModuleDefault();\n return new TronBridgeService(provider as InstanceType<typeof TronWeb>, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const { TronWeb } = await getTronWebModuleDefault();\n return new TronBridgeService(\n new TronWeb({\n fullHost: nodeRpcUrl,\n solidityNode: nodeRpcUrl,\n eventServer: nodeRpcUrl,\n }),\n api\n );\n }\n }\n case ChainType.SOLANA: {\n return new SolanaBridgeService(\n nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL),\n {\n wormholeMessengerProgramId: params.wormholeMessengerProgramId,\n solanaLookUpTable: params.solanaLookUpTable,\n cctpParams: params.cctpParams,\n jupiterParams: {\n jupiterUrl: params.jupiterUrl,\n jupiterApiKeyHeader: params.jupiterApiKeyHeader,\n jupiterMaxAccounts: params.jupiterMaxAccounts,\n },\n },\n api\n );\n }\n case ChainType.SRB: {\n return new SrbBridgeService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiBridgeService(nodeRpcUrlsConfig, api);\n }\n }\n}\n"]}
|
|
@@ -87,11 +87,11 @@ async function tronAddressToBuffer32(address) {
|
|
|
87
87
|
return bufferToSize(buffer, 32);
|
|
88
88
|
}
|
|
89
89
|
async function tronAddressToEthAddress(address) {
|
|
90
|
-
const
|
|
91
|
-
const bytes =
|
|
90
|
+
const { utils: TronWebUtils } = await (0, lazy_load_tronweb_import_1.getTronWebModuleDefault)();
|
|
91
|
+
const bytes = TronWebUtils.crypto.decodeBase58Address(address);
|
|
92
92
|
if (!bytes)
|
|
93
93
|
return "";
|
|
94
|
-
return
|
|
94
|
+
return TronWebUtils.bytes.byteArray2hexStr(bytes).replace(/^41/, "0x");
|
|
95
95
|
}
|
|
96
96
|
function bufferToSize(buffer, size) {
|
|
97
97
|
if (buffer.length >= size) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/services/bridge/utils.ts"],"names":[],"mappings":";;;;;AA6DA,sCA8CC;AAED,0CAEC;AAED,kCAEC;AAED,oDAIC;AAED,sDAIC;AAED,0DAKC;AAWD,wDAcC;AAED,4BAEC;AAED,wCAMC;AAeD,kDA+BC;AAyBD,kDA0HC;AAqBD,4CAoCC;AAsBD,oDA6DC;AAED,oCAEC;AA5fD,6CAA4C;AAC5C,sDAA+C;AAC/C,mCAAwC;AACxC,8DAAsC;AACtC,yCAAsC;AACtC,yEAAiE;AAEjE,iDAM0B;AAC1B,yCAQsB;AAEtB,yDAAmH;AACnH,2FAA0E;AAmC1E,wBAAwB;AACjB,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,IAAe,EACf,EAAa;IAEb,IAAI,MAAc,CAAC;IACnB,QAAQ,IAAI,EAAE,C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;YACzG,CAAC,qBAAY,CAAC,KAAK,CAAC,EAAE,sBAAsB;SAC7C,CAAC;IACJ,CAAC;IACD,OAAO;QACL,WAAW,EAAE,iBAAiB;QAC9B,gBAAgB,EAAE;YAChB,YAAY,EAAE;gBACZ,CAAC,qBAAY,CAAC,GAAG,CAAC,EAAE,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 { 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":";;;;;AA6DA,sCA8CC;AAED,0CAEC;AAED,kCAEC;AAED,oDAIC;AAED,sDAIC;AAED,0DAKC;AAWD,wDAcC;AAED,4BAEC;AAED,wCAMC;AAeD,kDA+BC;AAyBD,kDA0HC;AAqBD,4CAoCC;AAsBD,oDA6DC;AAED,oCAEC;AA5fD,6CAA4C;AAC5C,sDAA+C;AAC/C,mCAAwC;AACxC,8DAAsC;AACtC,yCAAsC;AACtC,yEAAiE;AAEjE,iDAM0B;AAC1B,yCAQsB;AAEtB,yDAAmH;AACnH,2FAAuF;AAmCvF,wBAAwB;AACjB,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,IAAe,EACf,EAAa;IAEb,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,MAAM,qBAAqB,CAAC,OAAO,CAAC,CAAC;YAC9C,MAAM;QACR,CAAC;QACD,KAAK,kBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,GAAG,IAAI,qBAAO,CAAC,O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,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 { 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 { getTronWebModuleDefault } 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 { utils: TronWebUtils } = await getTronWebModuleDefault();\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 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"]}
|
|
@@ -117,11 +117,12 @@ async function getChainPoolService(chainSymbol, api, nodeRpcUrlsConfig, params,
|
|
|
117
117
|
const tronJsonRpc = params.tronJsonRpc;
|
|
118
118
|
if (provider) {
|
|
119
119
|
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
120
|
-
const TronWeb = await (0, lazy_load_tronweb_import_1.
|
|
120
|
+
const { TronWeb } = await (0, lazy_load_tronweb_import_1.getTronWebModuleDefault)();
|
|
121
121
|
return new trx_1.TronPoolService(provider, api, tronJsonRpc);
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
|
-
const
|
|
124
|
+
const { TronWeb } = await (0, lazy_load_tronweb_import_1.getTronWebModuleDefault)();
|
|
125
|
+
const tronWeb = new TronWeb({ fullHost: nodeRpcUrl });
|
|
125
126
|
return new trx_1.TronPoolService(tronWeb, api, tronJsonRpc);
|
|
126
127
|
}
|
|
127
128
|
}
|
|
@@ -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,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;QAC/B,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,YAAY,GAAG,IAAI,+DAAgC,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC5G,MAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;QAC/F,IAAI,CAAC,KA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IAAI,CAAC,MAAM,IAAA,qCAAU,GAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;gBACnE,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 { 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,"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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 { 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 { getTronWebModuleDefault } 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 getTronWebModuleDefault();\n return new TronPoolService(provider as InstanceType<typeof TronWeb>, api, tronJsonRpc);\n } else {\n const { TronWeb } = await getTronWebModuleDefault();\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"]}
|
|
@@ -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
|
|
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
|
}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TronPoolService = void 0;
|
|
7
7
|
const web3_1 = require("web3");
|
|
8
|
+
const web3_eth_abi_1 = require("web3-eth-abi");
|
|
8
9
|
const chain_enums_1 = require("../../../chains/chain.enums");
|
|
9
10
|
const exceptions_1 = require("../../../exceptions");
|
|
10
11
|
const calculation_1 = require("../../../utils/calculation");
|
|
@@ -14,22 +15,20 @@ const models_1 = require("../models");
|
|
|
14
15
|
class TronPoolService extends models_1.ChainPoolService {
|
|
15
16
|
tronWeb;
|
|
16
17
|
api;
|
|
18
|
+
tronJsonRpc;
|
|
17
19
|
chainType = chain_enums_1.ChainType.TRX;
|
|
18
20
|
P = 52;
|
|
19
|
-
web3;
|
|
20
21
|
constructor(tronWeb, api, tronJsonRpc) {
|
|
21
22
|
super();
|
|
22
23
|
this.tronWeb = tronWeb;
|
|
23
24
|
this.api = api;
|
|
24
|
-
|
|
25
|
-
this.web3 = new web3_1.Web3(tronJsonRpc);
|
|
26
|
-
}
|
|
25
|
+
this.tronJsonRpc = tronJsonRpc;
|
|
27
26
|
}
|
|
28
27
|
async getUserBalanceInfo(accountAddress, token) {
|
|
29
28
|
let userBalanceInfo;
|
|
30
|
-
if (this.
|
|
29
|
+
if (this.tronJsonRpc) {
|
|
31
30
|
try {
|
|
32
|
-
userBalanceInfo = await this.getUserBalanceInfoByBatch(this.
|
|
31
|
+
userBalanceInfo = await this.getUserBalanceInfoByBatch(this.tronJsonRpc, accountAddress, token);
|
|
33
32
|
}
|
|
34
33
|
catch (ignoreError) {
|
|
35
34
|
userBalanceInfo = await this.getUserBalanceInfoPerProperty(accountAddress, token);
|
|
@@ -40,27 +39,43 @@ class TronPoolService extends models_1.ChainPoolService {
|
|
|
40
39
|
}
|
|
41
40
|
return userBalanceInfo;
|
|
42
41
|
}
|
|
43
|
-
async getUserBalanceInfoByBatch(
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
async getUserBalanceInfoByBatch(tronJsonRpc, accountAddress, token) {
|
|
43
|
+
const contractAddress = await (0, utils_1.tronAddressToEthAddress)(token.poolAddress);
|
|
44
|
+
const userAddress = await (0, utils_1.tronAddressToEthAddress)(accountAddress);
|
|
45
|
+
const payload = [
|
|
46
|
+
{
|
|
47
|
+
jsonrpc: "2.0",
|
|
48
|
+
id: 1,
|
|
49
|
+
method: "eth_call",
|
|
50
|
+
params: [{ to: contractAddress, data: this.getFunctionAbi("userRewardDebt", userAddress) }, "latest"],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
jsonrpc: "2.0",
|
|
54
|
+
id: 2,
|
|
55
|
+
method: "eth_call",
|
|
56
|
+
params: [{ to: contractAddress, data: this.getFunctionAbi("balanceOf", userAddress) }, "latest"],
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
const response = await fetch(tronJsonRpc, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: { "Content-Type": "application/json" },
|
|
62
|
+
body: JSON.stringify(payload),
|
|
55
63
|
});
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
64
|
+
const results = await response.json();
|
|
65
|
+
if (Array.isArray(results) && results.length === 2) {
|
|
66
|
+
const getResult = (id) => {
|
|
67
|
+
const entry = results.find((r) => r.id === id);
|
|
68
|
+
if (!entry || !entry.result) {
|
|
69
|
+
throw new Error(`Missing or invalid result for id ${id}`);
|
|
70
|
+
}
|
|
71
|
+
return web3_1.Web3.utils.toBigInt(entry.result).toString();
|
|
72
|
+
};
|
|
58
73
|
return new models_1.UserBalance({
|
|
59
|
-
lpAmount: web3_1.Web3.utils.toBigInt(
|
|
60
|
-
rewardDebt: web3_1.Web3.utils.toBigInt(
|
|
74
|
+
lpAmount: web3_1.Web3.utils.toBigInt(getResult(2)).toString(),
|
|
75
|
+
rewardDebt: web3_1.Web3.utils.toBigInt(getResult(1)).toString(),
|
|
61
76
|
});
|
|
62
77
|
}
|
|
63
|
-
throw new Error("Batched failed");
|
|
78
|
+
throw new Error("Batched HTTP call failed");
|
|
64
79
|
}
|
|
65
80
|
async getUserBalanceInfoPerProperty(accountAddress, token) {
|
|
66
81
|
if (!this.tronWeb.defaultAddress.base58) {
|
|
@@ -73,9 +88,9 @@ class TronPoolService extends models_1.ChainPoolService {
|
|
|
73
88
|
}
|
|
74
89
|
async getPoolInfoFromChain(token) {
|
|
75
90
|
let poolInfo;
|
|
76
|
-
if (this.
|
|
91
|
+
if (this.tronJsonRpc) {
|
|
77
92
|
try {
|
|
78
|
-
poolInfo = await this.getPoolInfoByBatch(this.
|
|
93
|
+
poolInfo = await this.getPoolInfoByBatch(this.tronJsonRpc, token);
|
|
79
94
|
}
|
|
80
95
|
catch (ignoreError) {
|
|
81
96
|
poolInfo = await this.getPoolInfoPerProperty(token);
|
|
@@ -86,67 +101,75 @@ class TronPoolService extends models_1.ChainPoolService {
|
|
|
86
101
|
}
|
|
87
102
|
return poolInfo;
|
|
88
103
|
}
|
|
89
|
-
async getPoolInfoByBatch(
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
async getPoolInfoByBatch(tronJsonRpc, token) {
|
|
105
|
+
const contractAddress = await (0, utils_1.tronAddressToEthAddress)(token.poolAddress);
|
|
106
|
+
const payload = [
|
|
107
|
+
{
|
|
108
|
+
jsonrpc: "2.0",
|
|
109
|
+
id: 1,
|
|
110
|
+
method: "eth_call",
|
|
111
|
+
params: [{ to: contractAddress, data: this.getFunctionAbi("a") }, "latest"],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
jsonrpc: "2.0",
|
|
115
|
+
id: 2,
|
|
116
|
+
method: "eth_call",
|
|
117
|
+
params: [{ to: contractAddress, data: this.getFunctionAbi("d") }, "latest"],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
jsonrpc: "2.0",
|
|
121
|
+
id: 3,
|
|
122
|
+
method: "eth_call",
|
|
123
|
+
params: [{ to: contractAddress, data: this.getFunctionAbi("tokenBalance") }, "latest"],
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
jsonrpc: "2.0",
|
|
127
|
+
id: 4,
|
|
128
|
+
method: "eth_call",
|
|
129
|
+
params: [{ to: contractAddress, data: this.getFunctionAbi("vUsdBalance") }, "latest"],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
jsonrpc: "2.0",
|
|
133
|
+
id: 5,
|
|
134
|
+
method: "eth_call",
|
|
135
|
+
params: [{ to: contractAddress, data: this.getFunctionAbi("totalSupply") }, "latest"],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
jsonrpc: "2.0",
|
|
139
|
+
id: 6,
|
|
140
|
+
method: "eth_call",
|
|
141
|
+
params: [{ to: contractAddress, data: this.getFunctionAbi("accRewardPerShareP") }, "latest"],
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
const response = await fetch(tronJsonRpc, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
headers: { "Content-Type": "application/json" },
|
|
147
|
+
body: JSON.stringify(payload),
|
|
113
148
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
tokenBalanceResult &&
|
|
126
|
-
vUsdBalanceResult &&
|
|
127
|
-
totalSupplyResult &&
|
|
128
|
-
accRewardPerSharePResult &&
|
|
129
|
-
!aResult.error &&
|
|
130
|
-
!dResult.error &&
|
|
131
|
-
!tokenBalanceResult.error &&
|
|
132
|
-
!vUsdBalanceResult.error &&
|
|
133
|
-
!totalSupplyResult.error &&
|
|
134
|
-
!accRewardPerSharePResult.error) {
|
|
135
|
-
const tokenBalanceStr = web3_1.Web3.utils.toBigInt(tokenBalanceResult.result).toString();
|
|
136
|
-
const vUsdBalanceStr = web3_1.Web3.utils.toBigInt(vUsdBalanceResult.result).toString();
|
|
149
|
+
const results = await response.json();
|
|
150
|
+
if (Array.isArray(results) && results.length === 6) {
|
|
151
|
+
const getResult = (id) => {
|
|
152
|
+
const entry = results.find((r) => r.id === id);
|
|
153
|
+
if (!entry || !entry.result) {
|
|
154
|
+
throw new Error(`Missing or invalid result for id ${id}`);
|
|
155
|
+
}
|
|
156
|
+
return web3_1.Web3.utils.toBigInt(entry.result).toString();
|
|
157
|
+
};
|
|
158
|
+
const tokenBalanceStr = getResult(3);
|
|
159
|
+
const vUsdBalanceStr = getResult(4);
|
|
137
160
|
const imbalance = (0, calculation_1.calculatePoolInfoImbalance)({ tokenBalance: tokenBalanceStr, vUsdBalance: vUsdBalanceStr });
|
|
138
161
|
return {
|
|
139
|
-
aValue:
|
|
140
|
-
dValue:
|
|
162
|
+
aValue: getResult(1),
|
|
163
|
+
dValue: getResult(2),
|
|
141
164
|
tokenBalance: tokenBalanceStr,
|
|
142
165
|
vUsdBalance: vUsdBalanceStr,
|
|
143
|
-
totalLpAmount:
|
|
144
|
-
accRewardPerShareP:
|
|
166
|
+
totalLpAmount: getResult(5),
|
|
167
|
+
accRewardPerShareP: getResult(6),
|
|
145
168
|
p: this.P,
|
|
146
169
|
imbalance,
|
|
147
170
|
};
|
|
148
171
|
}
|
|
149
|
-
throw new Error("Batched failed");
|
|
172
|
+
throw new Error("Batched pool info call failed");
|
|
150
173
|
}
|
|
151
174
|
async getPoolInfoPerProperty(token) {
|
|
152
175
|
if (!this.tronWeb.defaultAddress.base58) {
|
|
@@ -205,6 +228,13 @@ class TronPoolService extends models_1.ChainPoolService {
|
|
|
205
228
|
getContract(contractAddress) {
|
|
206
229
|
return this.tronWeb.contract(Pool_1.default.abi, contractAddress);
|
|
207
230
|
}
|
|
231
|
+
getFunctionAbi(name, ...params) {
|
|
232
|
+
const abiItem = Pool_1.default.abi.find((item) => item.type === "function" && "name" in item && item.name === name);
|
|
233
|
+
if (!abiItem) {
|
|
234
|
+
throw new Error(`${name} method not found in Pool ABI`);
|
|
235
|
+
}
|
|
236
|
+
return (0, web3_eth_abi_1.encodeFunctionCall)(abiItem, params);
|
|
237
|
+
}
|
|
208
238
|
}
|
|
209
239
|
exports.TronPoolService = TronPoolService;
|
|
210
240
|
//# sourceMappingURL=index.js.map
|