@allbridge/bridge-core-sdk 3.22.0 → 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 -1
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +4 -4
- package/dist/src/services/bridge/evm/index.js +1 -1
- package/dist/src/services/bridge/evm/index.js.map +1 -1
- package/dist/src/services/bridge/get-cctp-sol-token-recipient-address.js +3 -3
- package/dist/src/services/bridge/get-cctp-sol-token-recipient-address.js.map +1 -1
- package/dist/src/services/bridge/index.d.ts +2 -2
- package/dist/src/services/bridge/index.js +7 -4
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js +2 -2
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
- package/dist/src/services/bridge/sol/index.js +1 -1
- package/dist/src/services/bridge/sol/index.js.map +1 -1
- package/dist/src/services/bridge/srb/index.js +1 -1
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/sui/index.js +1 -1
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.js +1 -1
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +10 -10
- package/dist/src/services/bridge/utils.js +15 -14
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.d.ts +1 -1
- package/dist/src/services/liquidity-pool/index.js +8 -5
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/raw-pool-transaction-builder.js +3 -3
- package/dist/src/services/liquidity-pool/raw-pool-transaction-builder.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 +12 -9
- package/dist/src/services/token/index.js.map +1 -1
- package/dist/src/utils/tronweb/lazy-load-tronweb-import.d.ts +1 -0
- package/dist/src/utils/tronweb/lazy-load-tronweb-import.js +35 -0
- package/dist/src/utils/tronweb/lazy-load-tronweb-import.js.map +1 -0
- 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
|
@@ -37,16 +37,16 @@ class DefaultRawPoolTransactionBuilder {
|
|
|
37
37
|
(0, utils_1.validateAmountGtZero)(params.amount);
|
|
38
38
|
(0, utils_1.validateAmountDecimals)("amount", params.amount, params.token.decimals);
|
|
39
39
|
params.amount = (0, calculation_1.convertFloatAmountToInt)(params.amount, params.token.decimals).toFixed();
|
|
40
|
-
return (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider).buildRawTransactionDeposit(params);
|
|
40
|
+
return (await (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)).buildRawTransactionDeposit(params);
|
|
41
41
|
}
|
|
42
42
|
async withdraw(params, provider) {
|
|
43
43
|
(0, utils_1.validateAmountGtZero)(params.amount);
|
|
44
44
|
(0, utils_1.validateAmountDecimals)("amount", params.amount, params.token.decimals);
|
|
45
45
|
params.amount = (0, calculation_1.convertFloatAmountToInt)(params.amount, constants_1.SYSTEM_PRECISION).toFixed();
|
|
46
|
-
return (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider).buildRawTransactionWithdraw(params);
|
|
46
|
+
return (await (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)).buildRawTransactionWithdraw(params);
|
|
47
47
|
}
|
|
48
48
|
async claimRewards(params, provider) {
|
|
49
|
-
return (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider).buildRawTransactionClaimRewards(params);
|
|
49
|
+
return (await (0, index_1.getChainPoolService)(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)).buildRawTransactionClaimRewards(params);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
exports.DefaultRawPoolTransactionBuilder = DefaultRawPoolTransactionBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-pool-transaction-builder.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/raw-pool-transaction-builder.ts"],"names":[],"mappings":";;;AAGA,yDAAkE;AAClE,iEAAqE;AACrE,6CAAiF;AAIjF,mCAA8C;AAqC9C,MAAa,gCAAgC;IAEjC;IACA;IACA;IACA;IAJV,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAAqB;QACxB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,CAA2B,EAAE,CAAiB;QAC1D,IAAI,CAAC,EAAE,CAAC;YACN,MAAM,QAAQ,GAAG,CAAa,CAAC;YAC/B,MAAM,WAAW,GAAkB,CAAC,CAAC;YACrC,OAAO,IAAI,CAAC,YAAY,CAAC,0BAA0B,CACjD;gBACE,GAAG,WAAW;gBACd,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,WAAW;aACvC,EACD,QAAQ,CACT,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,WAAW,GAAkB,CAAkB,CAAC;YACtD,OAAO,IAAI,CAAC,YAAY,CAAC,0BAA0B,CAAC;gBAClD,GAAG,WAAW;gBACd,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,WAAW;aACvC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAsC,EAAE,QAAmB;QACvE,IAAA,4BAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,IAAA,8BAAsB,EAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvE,MAAM,CAAC,MAAM,GAAG,IAAA,qCAAuB,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;QACxF,OAAO,IAAA,2BAAmB,
|
|
1
|
+
{"version":3,"file":"raw-pool-transaction-builder.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/raw-pool-transaction-builder.ts"],"names":[],"mappings":";;;AAGA,yDAAkE;AAClE,iEAAqE;AACrE,6CAAiF;AAIjF,mCAA8C;AAqC9C,MAAa,gCAAgC;IAEjC;IACA;IACA;IACA;IAJV,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,E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CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAsC,EAAE,QAAmB;QACxE,IAAA,4BAAoB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,IAAA,8BAAsB,EAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvE,MAAM,CAAC,MAAM,GAAG,IAAA,qCAAuB,EAAC,MAAM,CAAC,MAAM,EAAE,4BAAgB,CAAC,CAAC,OAAO,EAAE,CAAC;QACnF,OAAO,CACL,MAAM,IAAA,2BAAmB,EAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7G,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAA4B,EAAE,QAAmB;QAClE,OAAO,CACL,MAAM,IAAA,2BAAmB,EAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7G,CAAC,+BAA+B,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF;AAnDD,4EAmDC","sourcesContent":["import { NodeRpcUrlsConfig } from \"..\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions } from \"../../index\";\nimport { convertFloatAmountToInt } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, RawTransaction } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { ApproveParams, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount } from \"./models\";\nimport { getChainPoolService } from \"./index\";\n\nexport interface RawPoolTransactionBuilder {\n /**\n * Creates a Raw Transaction for approving tokens usage by the bridge\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<RawTransaction>;\n /**\n * Creates a Raw Transaction for approving tokens usage by the bridge\n * @param approveData\n */\n approve(approveData: ApproveParams): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for depositing tokens to Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for withdrawing tokens from Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for claiming rewards from Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n */\n claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction>;\n}\n\nexport class DefaultRawPoolTransactionBuilder implements RawPoolTransactionBuilder {\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {}\n\n async approve(a: Provider | ApproveParams, b?: ApproveParams): Promise<RawTransaction> {\n if (b) {\n const provider = a as Provider;\n const approveData: ApproveParams = b;\n return this.tokenService.buildRawTransactionApprove(\n {\n ...approveData,\n spender: approveData.token.poolAddress,\n },\n provider\n );\n } else {\n const approveData: ApproveParams = a as ApproveParams;\n return this.tokenService.buildRawTransactionApprove({\n ...approveData,\n spender: approveData.token.poolAddress,\n });\n }\n }\n\n async deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n params.amount = convertFloatAmountToInt(params.amount, params.token.decimals).toFixed();\n return (\n await getChainPoolService(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)\n ).buildRawTransactionDeposit(params);\n }\n\n async withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n params.amount = convertFloatAmountToInt(params.amount, SYSTEM_PRECISION).toFixed();\n return (\n await getChainPoolService(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)\n ).buildRawTransactionWithdraw(params);\n }\n\n async claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction> {\n return (\n await getChainPoolService(params.token.chainSymbol, this.api, this.nodeRpcUrlsConfig, this.params, provider)\n ).buildRawTransactionClaimRewards(params);\n }\n}\n"]}
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/trx/index.ts"],"names":[],"mappings":";;;;;;AACA,+BAA4B;AAC5B,6DAAwD;AAExD,oDAA+C;AAE/C,4DAAwE;AACxE,8CAA6D;AAE7D,iEAAyC;AACzC,sCAMmB;AAEnB,MAAa,eAAgB,SAAQ,yBAAgB;IAM1C;IACA;IANT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IACjC,CAAC,GAAG,EAAE,CAAC;IACP,IAAI,CAAmB;IAE/B,YACS,OAAgB,EAChB,GAAwB,EAC/B,WAA+B;QAE/B,KAAK,EAAE,CAAC;QAJD,YAAO,GAAP,OAAO,CAAS;QAChB,QAAG,GAAH,GAAG,CAAqB;QAI/B,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC,WAAW,CAAC,CAAC;QAC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CAAC;IAEO,KAAK,CAAC,mBAAmB,CAC/B,eAAuB,EACvB,eAAuB,EACvB,SAAyC,EACzC,KAAa,EACb,WAAmB;QAEnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,oBAAoB,CAClF,eAAe,EACf,eAAe,EACf;YACE,SAAS,EAAE,CAAC,KAAK;SAClB,EACD,SAAS,EACT,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,qBAAQ,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,iBAAiB,CAAC,WAAW,CAAC;IACvC,CAAC;IAEO,WAAW,CAAC,eAAuB;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IAC1D,CAAC;CACF;AA9OD,0CA8OC","sourcesContent":["import { TronWeb } from \"tronweb\";\nimport { Web3 } from \"web3\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { PoolInfo, TokenWithChainDetails } from \"../../../tokens-info\";\nimport { calculatePoolInfoImbalance } from \"../../../utils/calculation\";\nimport { tronAddressToEthAddress } from \"../../bridge/utils\";\nimport { RawTransaction, SmartContractMethodParameter } from \"../../models\";\nimport Pool from \"../../models/abi/Pool\";\nimport {\n LiquidityPoolsParams,\n LiquidityPoolsParamsWithAmount,\n UserBalance,\n UserBalanceInfo,\n ChainPoolService,\n} from \"../models\";\n\nexport class TronPoolService extends ChainPoolService {\n chainType: ChainType.TRX = ChainType.TRX;\n private P = 52;\n private web3: Web3 | undefined;\n\n constructor(\n public tronWeb: TronWeb,\n public api: AllbridgeCoreClient,\n tronJsonRpc: string | undefined\n ) {\n super();\n if (tronJsonRpc) {\n this.web3 = new Web3(tronJsonRpc);\n }\n }\n\n async getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo> {\n let userBalanceInfo;\n if (this.web3) {\n try {\n userBalanceInfo = await this.getUserBalanceInfoByBatch(this.web3, accountAddress, token);\n } catch (ignoreError) {\n userBalanceInfo = await this.getUserBalanceInfoPerProperty(accountAddress, token);\n }\n } else {\n userBalanceInfo = await this.getUserBalanceInfoPerProperty(accountAddress, token);\n }\n return userBalanceInfo;\n }\n\n private async getUserBalanceInfoByBatch(\n web3: Web3,\n accountAddress: string,\n token: TokenWithChainDetails\n ): Promise<UserBalanceInfo> {\n const batch = new web3.BatchRequest();\n const contract = new web3.eth.Contract(Pool.abi, tronAddressToEthAddress(token.poolAddress));\n\n const userRewardDebtAbi = contract.methods.userRewardDebt(accountAddress).encodeABI();\n const balanceOfAbi = contract.methods.balanceOf(accountAddress).encodeABI();\n\n batch.add({\n method: \"eth_call\",\n params: [{ to: token.poolAddress, data: userRewardDebtAbi }, \"latest\"],\n });\n batch.add({\n method: \"eth_call\",\n params: [{ to: token.poolAddress, data: balanceOfAbi }, \"latest\"],\n });\n\n const [rewardDebtResult, lpAmountResult] = await batch.execute();\n\n if (rewardDebtResult && lpAmountResult && !rewardDebtResult.error && !lpAmountResult.error) {\n return new UserBalance({\n lpAmount: Web3.utils.toBigInt(lpAmountResult.result).toString(),\n rewardDebt: Web3.utils.toBigInt(rewardDebtResult.result).toString(),\n });\n }\n throw new Error(\"Batched failed\");\n }\n\n private async getUserBalanceInfoPerProperty(\n accountAddress: string,\n token: TokenWithChainDetails\n ): Promise<UserBalanceInfo> {\n if (!this.tronWeb.defaultAddress.base58) {\n this.tronWeb.setAddress(accountAddress);\n }\n const contract = this.getContract(token.poolAddress);\n const rewardDebt = (await contract.methods.userRewardDebt(accountAddress).call()).toString();\n const lpAmount = (await contract.methods.balanceOf(accountAddress).call()).toString();\n return new UserBalance({ lpAmount, rewardDebt });\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo> {\n let poolInfo;\n if (this.web3) {\n try {\n poolInfo = await this.getPoolInfoByBatch(this.web3, token);\n } catch (ignoreError) {\n poolInfo = await this.getPoolInfoPerProperty(token);\n }\n } else {\n poolInfo = await this.getPoolInfoPerProperty(token);\n }\n return poolInfo;\n }\n\n private async getPoolInfoByBatch(web3: Web3, token: TokenWithChainDetails): Promise<PoolInfo> {\n const batch = new web3.BatchRequest();\n const contract = new web3.eth.Contract(Pool.abi, tronAddressToEthAddress(token.poolAddress), this.web3);\n\n const aAbi = contract.methods.a().encodeABI();\n const dAbi = contract.methods.d().encodeABI();\n const tokenBalanceAbi = contract.methods.tokenBalance().encodeABI();\n const vUsdBalanceAbi = contract.methods.vUsdBalance().encodeABI();\n const totalSupplyAbi = contract.methods.totalSupply().encodeABI();\n const accRewardPerSharePAbi = contract.methods.accRewardPerShareP().encodeABI();\n\n batch.add({\n method: \"eth_call\",\n params: [{ to: token.poolAddress, data: aAbi }, \"latest\"],\n });\n batch.add({\n method: \"eth_call\",\n params: [{ to: token.poolAddress, data: dAbi }, \"latest\"],\n });\n batch.add({\n method: \"eth_call\",\n params: [{ to: token.poolAddress, data: tokenBalanceAbi }, \"latest\"],\n });\n batch.add({\n method: \"eth_call\",\n params: [{ to: token.poolAddress, data: vUsdBalanceAbi }, \"latest\"],\n });\n batch.add({\n method: \"eth_call\",\n params: [{ to: token.poolAddress, data: totalSupplyAbi }, \"latest\"],\n });\n batch.add({\n method: \"eth_call\",\n params: [{ to: token.poolAddress, data: accRewardPerSharePAbi }, \"latest\"],\n });\n\n const [aResult, dResult, tokenBalanceResult, vUsdBalanceResult, totalSupplyResult, accRewardPerSharePResult] =\n await batch.execute();\n\n if (\n aResult &&\n dResult &&\n tokenBalanceResult &&\n vUsdBalanceResult &&\n totalSupplyResult &&\n accRewardPerSharePResult &&\n !aResult.error &&\n !dResult.error &&\n !tokenBalanceResult.error &&\n !vUsdBalanceResult.error &&\n !totalSupplyResult.error &&\n !accRewardPerSharePResult.error\n ) {\n const tokenBalanceStr = Web3.utils.toBigInt(tokenBalanceResult.result).toString();\n const vUsdBalanceStr = Web3.utils.toBigInt(vUsdBalanceResult.result).toString();\n const imbalance = calculatePoolInfoImbalance({ tokenBalance: tokenBalanceStr, vUsdBalance: vUsdBalanceStr });\n return {\n aValue: Web3.utils.toBigInt(aResult.result).toString(),\n dValue: Web3.utils.toBigInt(dResult.result).toString(),\n tokenBalance: tokenBalanceStr,\n vUsdBalance: vUsdBalanceStr,\n totalLpAmount: Web3.utils.toBigInt(totalSupplyResult.result).toString(),\n accRewardPerShareP: Web3.utils.toBigInt(accRewardPerSharePResult.result).toString(),\n p: this.P,\n imbalance,\n };\n }\n throw new Error(\"Batched failed\");\n }\n\n private async getPoolInfoPerProperty(token: TokenWithChainDetails): Promise<PoolInfo> {\n if (!this.tronWeb.defaultAddress.base58) {\n this.tronWeb.setAddress(token.poolAddress);\n }\n const poolContract = this.getContract(token.poolAddress);\n const [aValue, dValue, tokenBalance, vUsdBalance, totalLpAmount, accRewardPerShareP] = await Promise.all([\n poolContract.methods.a().call(),\n poolContract.methods.d().call(),\n poolContract.methods.tokenBalance().call(),\n poolContract.methods.vUsdBalance().call(),\n poolContract.methods.totalSupply().call(),\n poolContract.methods.accRewardPerShareP().call(),\n ]);\n const tokenBalanceStr = tokenBalance.toString();\n const vUsdBalanceStr = vUsdBalance.toString();\n const imbalance = calculatePoolInfoImbalance({ tokenBalance: tokenBalanceStr, vUsdBalance: vUsdBalanceStr });\n return {\n aValue: aValue.toString(),\n dValue: dValue.toString(),\n tokenBalance: tokenBalanceStr,\n vUsdBalance: vUsdBalanceStr,\n totalLpAmount: totalLpAmount.toString(),\n accRewardPerShareP: accRewardPerShareP.toString(),\n p: this.P,\n imbalance,\n };\n }\n\n buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const { amount, accountAddress } = params;\n\n const parameter = [{ type: \"uint256\", value: amount }];\n const methodSignature = \"deposit(uint256)\";\n\n return this.buildRawTransaction(params.token.poolAddress, methodSignature, parameter, \"0\", accountAddress);\n }\n\n buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const { amount, accountAddress } = params;\n\n const parameter = [{ type: \"uint256\", value: amount }];\n const methodSignature = \"withdraw(uint256)\";\n\n return this.buildRawTransaction(params.token.poolAddress, methodSignature, parameter, \"0\", accountAddress);\n }\n\n buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction> {\n const { accountAddress } = params;\n\n const parameter: SmartContractMethodParameter[] = [];\n const methodSignature = \"claimRewards()\";\n\n return this.buildRawTransaction(params.token.poolAddress, methodSignature, parameter, \"0\", accountAddress);\n }\n\n private async buildRawTransaction(\n contractAddress: string,\n methodSignature: string,\n parameter: SmartContractMethodParameter[],\n value: string,\n fromAddress: string\n ): Promise<RawTransaction> {\n const transactionObject = await this.tronWeb.transactionBuilder.triggerSmartContract(\n contractAddress,\n methodSignature,\n {\n callValue: +value,\n },\n parameter,\n fromAddress\n );\n if (!transactionObject?.result?.result) {\n throw new SdkError(\"Unknown error: \" + JSON.stringify(transactionObject, null, 2));\n }\n return transactionObject.transaction;\n }\n\n private getContract(contractAddress: string): any {\n return this.tronWeb.contract(Pool.abi, contractAddress);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/trx/index.ts"],"names":[],"mappings":";;;;;;AACA,+BAAqC;AACrC,+CAAkD;AAElD,6DAAwD;AAExD,oDAA+C;AAE/C,4DAAwE;AACxE,8CAA6D;AAE7D,iEAAyC;AACzC,sCAMmB;AAEnB,MAAa,eAAgB,SAAQ,yBAAgB;IAK1C;IACA;IACU;IANnB,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IACjC,CAAC,GAAG,EAAE,CAAC;IAEf,YACS,OAAgB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AE,MAAM,CAAC,CAAC;IACpE,CAAC;CACF;AAhRD,0CAgRC","sourcesContent":["import { TronWeb } from \"tronweb\";\nimport { AbiItem, Web3 } from \"web3\";\nimport { encodeFunctionCall } from \"web3-eth-abi\";\nimport { AbiFunctionFragment } from \"web3-types\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { PoolInfo, TokenWithChainDetails } from \"../../../tokens-info\";\nimport { calculatePoolInfoImbalance } from \"../../../utils/calculation\";\nimport { tronAddressToEthAddress } from \"../../bridge/utils\";\nimport { RawTransaction, SmartContractMethodParameter } from \"../../models\";\nimport Pool from \"../../models/abi/Pool\";\nimport {\n ChainPoolService,\n LiquidityPoolsParams,\n LiquidityPoolsParamsWithAmount,\n UserBalance,\n UserBalanceInfo,\n} from \"../models\";\n\nexport class TronPoolService extends ChainPoolService {\n chainType: ChainType.TRX = ChainType.TRX;\n private P = 52;\n\n constructor(\n public tronWeb: TronWeb,\n public api: AllbridgeCoreClient,\n private readonly tronJsonRpc: string | undefined\n ) {\n super();\n }\n\n async getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo> {\n let userBalanceInfo;\n if (this.tronJsonRpc) {\n try {\n userBalanceInfo = await this.getUserBalanceInfoByBatch(this.tronJsonRpc, accountAddress, token);\n } catch (ignoreError) {\n userBalanceInfo = await this.getUserBalanceInfoPerProperty(accountAddress, token);\n }\n } else {\n userBalanceInfo = await this.getUserBalanceInfoPerProperty(accountAddress, token);\n }\n return userBalanceInfo;\n }\n\n private async getUserBalanceInfoByBatch(\n tronJsonRpc: string,\n accountAddress: string,\n token: TokenWithChainDetails\n ): Promise<UserBalanceInfo> {\n const contractAddress = await tronAddressToEthAddress(token.poolAddress);\n const userAddress = await tronAddressToEthAddress(accountAddress);\n\n const payload = [\n {\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_call\",\n params: [{ to: contractAddress, data: this.getFunctionAbi(\"userRewardDebt\", userAddress) }, \"latest\"],\n },\n {\n jsonrpc: \"2.0\",\n id: 2,\n method: \"eth_call\",\n params: [{ to: contractAddress, data: this.getFunctionAbi(\"balanceOf\", userAddress) }, \"latest\"],\n },\n ];\n\n const response = await fetch(tronJsonRpc, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(payload),\n });\n\n const results = await response.json();\n\n if (Array.isArray(results) && results.length === 2) {\n const getResult = (id: number) => {\n const entry = results.find((r) => r.id === id);\n if (!entry || !entry.result) {\n throw new Error(`Missing or invalid result for id ${id}`);\n }\n return Web3.utils.toBigInt(entry.result).toString();\n };\n\n return new UserBalance({\n lpAmount: Web3.utils.toBigInt(getResult(2)).toString(),\n rewardDebt: Web3.utils.toBigInt(getResult(1)).toString(),\n });\n }\n\n throw new Error(\"Batched HTTP call failed\");\n }\n\n private async getUserBalanceInfoPerProperty(\n accountAddress: string,\n token: TokenWithChainDetails\n ): Promise<UserBalanceInfo> {\n if (!this.tronWeb.defaultAddress.base58) {\n this.tronWeb.setAddress(accountAddress);\n }\n const contract = this.getContract(token.poolAddress);\n const rewardDebt = (await contract.methods.userRewardDebt(accountAddress).call()).toString();\n const lpAmount = (await contract.methods.balanceOf(accountAddress).call()).toString();\n return new UserBalance({ lpAmount, rewardDebt });\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo> {\n let poolInfo;\n if (this.tronJsonRpc) {\n try {\n poolInfo = await this.getPoolInfoByBatch(this.tronJsonRpc, token);\n } catch (ignoreError) {\n poolInfo = await this.getPoolInfoPerProperty(token);\n }\n } else {\n poolInfo = await this.getPoolInfoPerProperty(token);\n }\n return poolInfo;\n }\n\n private async getPoolInfoByBatch(tronJsonRpc: string, token: TokenWithChainDetails): Promise<PoolInfo> {\n const contractAddress = await tronAddressToEthAddress(token.poolAddress);\n\n const payload = [\n {\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_call\",\n params: [{ to: contractAddress, data: this.getFunctionAbi(\"a\") }, \"latest\"],\n },\n {\n jsonrpc: \"2.0\",\n id: 2,\n method: \"eth_call\",\n params: [{ to: contractAddress, data: this.getFunctionAbi(\"d\") }, \"latest\"],\n },\n {\n jsonrpc: \"2.0\",\n id: 3,\n method: \"eth_call\",\n params: [{ to: contractAddress, data: this.getFunctionAbi(\"tokenBalance\") }, \"latest\"],\n },\n {\n jsonrpc: \"2.0\",\n id: 4,\n method: \"eth_call\",\n params: [{ to: contractAddress, data: this.getFunctionAbi(\"vUsdBalance\") }, \"latest\"],\n },\n {\n jsonrpc: \"2.0\",\n id: 5,\n method: \"eth_call\",\n params: [{ to: contractAddress, data: this.getFunctionAbi(\"totalSupply\") }, \"latest\"],\n },\n {\n jsonrpc: \"2.0\",\n id: 6,\n method: \"eth_call\",\n params: [{ to: contractAddress, data: this.getFunctionAbi(\"accRewardPerShareP\") }, \"latest\"],\n },\n ];\n\n const response = await fetch(tronJsonRpc, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(payload),\n });\n\n const results = await response.json();\n\n if (Array.isArray(results) && results.length === 6) {\n const getResult = (id: number) => {\n const entry = results.find((r) => r.id === id);\n if (!entry || !entry.result) {\n throw new Error(`Missing or invalid result for id ${id}`);\n }\n return Web3.utils.toBigInt(entry.result).toString();\n };\n\n const tokenBalanceStr = getResult(3);\n const vUsdBalanceStr = getResult(4);\n const imbalance = calculatePoolInfoImbalance({ tokenBalance: tokenBalanceStr, vUsdBalance: vUsdBalanceStr });\n\n return {\n aValue: getResult(1),\n dValue: getResult(2),\n tokenBalance: tokenBalanceStr,\n vUsdBalance: vUsdBalanceStr,\n totalLpAmount: getResult(5),\n accRewardPerShareP: getResult(6),\n p: this.P,\n imbalance,\n };\n }\n\n throw new Error(\"Batched pool info call failed\");\n }\n\n private async getPoolInfoPerProperty(token: TokenWithChainDetails): Promise<PoolInfo> {\n if (!this.tronWeb.defaultAddress.base58) {\n this.tronWeb.setAddress(token.poolAddress);\n }\n const poolContract = this.getContract(token.poolAddress);\n const [aValue, dValue, tokenBalance, vUsdBalance, totalLpAmount, accRewardPerShareP] = await Promise.all([\n poolContract.methods.a().call(),\n poolContract.methods.d().call(),\n poolContract.methods.tokenBalance().call(),\n poolContract.methods.vUsdBalance().call(),\n poolContract.methods.totalSupply().call(),\n poolContract.methods.accRewardPerShareP().call(),\n ]);\n const tokenBalanceStr = tokenBalance.toString();\n const vUsdBalanceStr = vUsdBalance.toString();\n const imbalance = calculatePoolInfoImbalance({ tokenBalance: tokenBalanceStr, vUsdBalance: vUsdBalanceStr });\n return {\n aValue: aValue.toString(),\n dValue: dValue.toString(),\n tokenBalance: tokenBalanceStr,\n vUsdBalance: vUsdBalanceStr,\n totalLpAmount: totalLpAmount.toString(),\n accRewardPerShareP: accRewardPerShareP.toString(),\n p: this.P,\n imbalance,\n };\n }\n\n buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const { amount, accountAddress } = params;\n\n const parameter = [{ type: \"uint256\", value: amount }];\n const methodSignature = \"deposit(uint256)\";\n\n return this.buildRawTransaction(params.token.poolAddress, methodSignature, parameter, \"0\", accountAddress);\n }\n\n buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const { amount, accountAddress } = params;\n\n const parameter = [{ type: \"uint256\", value: amount }];\n const methodSignature = \"withdraw(uint256)\";\n\n return this.buildRawTransaction(params.token.poolAddress, methodSignature, parameter, \"0\", accountAddress);\n }\n\n buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction> {\n const { accountAddress } = params;\n\n const parameter: SmartContractMethodParameter[] = [];\n const methodSignature = \"claimRewards()\";\n\n return this.buildRawTransaction(params.token.poolAddress, methodSignature, parameter, \"0\", accountAddress);\n }\n\n private async buildRawTransaction(\n contractAddress: string,\n methodSignature: string,\n parameter: SmartContractMethodParameter[],\n value: string,\n fromAddress: string\n ): Promise<RawTransaction> {\n const transactionObject = await this.tronWeb.transactionBuilder.triggerSmartContract(\n contractAddress,\n methodSignature,\n {\n callValue: +value,\n },\n parameter,\n fromAddress\n );\n if (!transactionObject?.result?.result) {\n throw new SdkError(\"Unknown error: \" + JSON.stringify(transactionObject, null, 2));\n }\n return transactionObject.transaction;\n }\n\n private getContract(contractAddress: string): any {\n return this.tronWeb.contract(Pool.abi, contractAddress);\n }\n\n private getFunctionAbi(name: string, ...params: string[]): string {\n const abiItem = (Pool.abi as ReadonlyArray<AbiItem>).find(\n (item) => item.type === \"function\" && \"name\" in item && item.name === name\n );\n\n if (!abiItem) {\n throw new Error(`${name} method not found in Pool ABI`);\n }\n\n return encodeFunctionCall(abiItem as AbiFunctionFragment, params);\n }\n}\n"]}
|
|
@@ -23,7 +23,7 @@ export declare class Char implements StructClass {
|
|
|
23
23
|
static get r(): reified.StructClassReified<Char, CharFields>;
|
|
24
24
|
static phantom(): PhantomReified<ToTypeStr<Char>>;
|
|
25
25
|
static get p(): reified.PhantomReified<string>;
|
|
26
|
-
static get bcs(): import("@mysten/sui/
|
|
26
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
27
27
|
byte: number;
|
|
28
28
|
}, {
|
|
29
29
|
byte: number;
|
|
@@ -65,7 +65,7 @@ export declare class String implements StructClass {
|
|
|
65
65
|
static get r(): reified.StructClassReified<String, StringFields>;
|
|
66
66
|
static phantom(): PhantomReified<ToTypeStr<String>>;
|
|
67
67
|
static get p(): reified.PhantomReified<string>;
|
|
68
|
-
static get bcs(): import("@mysten/sui/
|
|
68
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
69
69
|
bytes: number[];
|
|
70
70
|
}, {
|
|
71
71
|
bytes: Iterable<number> & {
|
|
@@ -25,7 +25,7 @@ export declare class BitVector implements StructClass {
|
|
|
25
25
|
static get r(): reified.StructClassReified<BitVector, BitVectorFields>;
|
|
26
26
|
static phantom(): PhantomReified<ToTypeStr<BitVector>>;
|
|
27
27
|
static get p(): reified.PhantomReified<string>;
|
|
28
|
-
static get bcs(): import("@mysten/sui/
|
|
28
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
29
29
|
length: string;
|
|
30
30
|
bit_field: boolean[];
|
|
31
31
|
}, {
|
|
@@ -21,7 +21,7 @@ export declare class FixedPoint32 implements StructClass {
|
|
|
21
21
|
static get r(): import("../../../../_framework/reified").StructClassReified<FixedPoint32, FixedPoint32Fields>;
|
|
22
22
|
static phantom(): PhantomReified<ToTypeStr<FixedPoint32>>;
|
|
23
23
|
static get p(): PhantomReified<string>;
|
|
24
|
-
static get bcs(): import("@mysten/sui/
|
|
24
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
25
25
|
value: string;
|
|
26
26
|
}, {
|
|
27
27
|
value: string | number | bigint;
|
|
@@ -23,7 +23,7 @@ export declare class String implements StructClass {
|
|
|
23
23
|
static get r(): reified.StructClassReified<String, StringFields>;
|
|
24
24
|
static phantom(): PhantomReified<ToTypeStr<String>>;
|
|
25
25
|
static get p(): reified.PhantomReified<string>;
|
|
26
|
-
static get bcs(): import("@mysten/sui/
|
|
26
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
27
27
|
bytes: number[];
|
|
28
28
|
}, {
|
|
29
29
|
bytes: Iterable<number> & {
|
|
@@ -22,7 +22,7 @@ export declare class TypeName implements StructClass {
|
|
|
22
22
|
static get r(): import("../../../../_framework/reified").StructClassReified<TypeName, TypeNameFields>;
|
|
23
23
|
static phantom(): PhantomReified<ToTypeStr<TypeName>>;
|
|
24
24
|
static get p(): PhantomReified<string>;
|
|
25
|
-
static get bcs(): import("@mysten/sui/
|
|
25
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
26
26
|
name: {
|
|
27
27
|
bytes: number[];
|
|
28
28
|
};
|
|
@@ -21,7 +21,7 @@ export declare class UQ32_32 implements StructClass {
|
|
|
21
21
|
static get r(): import("../../../../_framework/reified").StructClassReified<UQ32_32, UQ32_32Fields>;
|
|
22
22
|
static phantom(): PhantomReified<ToTypeStr<UQ32_32>>;
|
|
23
23
|
static get p(): PhantomReified<string>;
|
|
24
|
-
static get bcs(): import("@mysten/sui/
|
|
24
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
25
25
|
pos0: string;
|
|
26
26
|
}, {
|
|
27
27
|
pos0: string | number | bigint;
|
|
@@ -21,7 +21,7 @@ export declare class UQ64_64 implements StructClass {
|
|
|
21
21
|
static get r(): import("../../../../_framework/reified").StructClassReified<UQ64_64, UQ64_64Fields>;
|
|
22
22
|
static phantom(): PhantomReified<ToTypeStr<UQ64_64>>;
|
|
23
23
|
static get p(): PhantomReified<string>;
|
|
24
|
-
static get bcs(): import("@mysten/sui/
|
|
24
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
25
25
|
pos0: string;
|
|
26
26
|
}, {
|
|
27
27
|
pos0: string | number | bigint;
|
|
@@ -29,7 +29,7 @@ export declare class BurnMessage implements StructClass {
|
|
|
29
29
|
static get r(): import("../../../../_framework/reified").StructClassReified<BurnMessage, BurnMessageFields>;
|
|
30
30
|
static phantom(): PhantomReified<ToTypeStr<BurnMessage>>;
|
|
31
31
|
static get p(): PhantomReified<string>;
|
|
32
|
-
static get bcs(): import("@mysten/sui/
|
|
32
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
33
33
|
version: number;
|
|
34
34
|
burn_token: string;
|
|
35
35
|
mint_recipient: string;
|
|
@@ -26,7 +26,7 @@ export declare class StampReceiptTicketWithBurnMessage implements StructClass {
|
|
|
26
26
|
static get r(): import("../../../../_framework/reified").StructClassReified<StampReceiptTicketWithBurnMessage, StampReceiptTicketWithBurnMessageFields>;
|
|
27
27
|
static phantom(): PhantomReified<ToTypeStr<StampReceiptTicketWithBurnMessage>>;
|
|
28
28
|
static get p(): PhantomReified<string>;
|
|
29
|
-
static get bcs(): import("@mysten/sui/
|
|
29
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
30
30
|
stamp_receipt_ticket: {
|
|
31
31
|
auth: {
|
|
32
32
|
dummy_field: boolean;
|
|
@@ -21,7 +21,7 @@ export declare class MessageTransmitterAuthenticator implements StructClass {
|
|
|
21
21
|
static get r(): import("../../../../_framework/reified").StructClassReified<MessageTransmitterAuthenticator, MessageTransmitterAuthenticatorFields>;
|
|
22
22
|
static phantom(): PhantomReified<ToTypeStr<MessageTransmitterAuthenticator>>;
|
|
23
23
|
static get p(): PhantomReified<string>;
|
|
24
|
-
static get bcs(): import("@mysten/sui/
|
|
24
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
25
25
|
dummy_field: boolean;
|
|
26
26
|
}, {
|
|
27
27
|
dummy_field: boolean;
|
|
@@ -40,7 +40,7 @@ export declare class State implements StructClass {
|
|
|
40
40
|
static get r(): reified.StructClassReified<State, StateFields>;
|
|
41
41
|
static phantom(): PhantomReified<ToTypeStr<State>>;
|
|
42
42
|
static get p(): reified.PhantomReified<string>;
|
|
43
|
-
static get bcs(): import("@mysten/sui/
|
|
43
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
44
44
|
id: {
|
|
45
45
|
id: {
|
|
46
46
|
bytes: string;
|
|
@@ -21,7 +21,7 @@ export declare class MintAllowance<T extends PhantomTypeArgument> implements Str
|
|
|
21
21
|
static get r(): typeof MintAllowance.reified;
|
|
22
22
|
static phantom<T extends PhantomReified<PhantomTypeArgument>>(T: T): PhantomReified<ToTypeStr<MintAllowance<ToPhantomTypeArgument<T>>>>;
|
|
23
23
|
static get p(): typeof MintAllowance.phantom;
|
|
24
|
-
static get bcs(): import("@mysten/sui/
|
|
24
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
25
25
|
value: string;
|
|
26
26
|
}, {
|
|
27
27
|
value: string | number | bigint;
|
|
@@ -28,7 +28,7 @@ export declare class Burn<T extends PhantomTypeArgument> implements StructClass
|
|
|
28
28
|
static get r(): typeof Burn.reified;
|
|
29
29
|
static phantom<T extends PhantomReified<PhantomTypeArgument>>(T: T): PhantomReified<ToTypeStr<Burn<ToPhantomTypeArgument<T>>>>;
|
|
30
30
|
static get p(): typeof Burn.phantom;
|
|
31
|
-
static get bcs(): import("@mysten/sui/
|
|
31
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
32
32
|
mint_cap: {
|
|
33
33
|
bytes: string;
|
|
34
34
|
};
|
|
@@ -78,7 +78,7 @@ export declare class MintCap<T extends PhantomTypeArgument> implements StructCla
|
|
|
78
78
|
static get r(): typeof MintCap.reified;
|
|
79
79
|
static phantom<T extends PhantomReified<PhantomTypeArgument>>(T: T): PhantomReified<ToTypeStr<MintCap<ToPhantomTypeArgument<T>>>>;
|
|
80
80
|
static get p(): typeof MintCap.phantom;
|
|
81
|
-
static get bcs(): import("@mysten/sui/
|
|
81
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
82
82
|
id: {
|
|
83
83
|
id: {
|
|
84
84
|
bytes: string;
|
|
@@ -134,7 +134,7 @@ export declare class Treasury<T extends PhantomTypeArgument> implements StructCl
|
|
|
134
134
|
static get r(): typeof Treasury.reified;
|
|
135
135
|
static phantom<T extends PhantomReified<PhantomTypeArgument>>(T: T): PhantomReified<ToTypeStr<Treasury<ToPhantomTypeArgument<T>>>>;
|
|
136
136
|
static get p(): typeof Treasury.phantom;
|
|
137
|
-
static get bcs(): import("@mysten/sui/
|
|
137
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
138
138
|
id: {
|
|
139
139
|
id: {
|
|
140
140
|
bytes: string;
|
|
@@ -246,7 +246,7 @@ export declare class TreasuryCapKey implements StructClass {
|
|
|
246
246
|
static get r(): reified.StructClassReified<TreasuryCapKey, TreasuryCapKeyFields>;
|
|
247
247
|
static phantom(): PhantomReified<ToTypeStr<TreasuryCapKey>>;
|
|
248
248
|
static get p(): reified.PhantomReified<string>;
|
|
249
|
-
static get bcs(): import("@mysten/sui/
|
|
249
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
250
250
|
dummy_field: boolean;
|
|
251
251
|
}, {
|
|
252
252
|
dummy_field: boolean;
|
|
@@ -37,7 +37,7 @@ export declare class Message implements StructClass {
|
|
|
37
37
|
static get r(): reified.StructClassReified<Message, MessageFields>;
|
|
38
38
|
static phantom(): PhantomReified<ToTypeStr<Message>>;
|
|
39
39
|
static get p(): reified.PhantomReified<string>;
|
|
40
|
-
static get bcs(): import("@mysten/sui/
|
|
40
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
41
41
|
version: number;
|
|
42
42
|
source_domain: number;
|
|
43
43
|
destination_domain: number;
|
|
@@ -43,7 +43,7 @@ export declare class State implements StructClass {
|
|
|
43
43
|
static get r(): reified.StructClassReified<State, StateFields>;
|
|
44
44
|
static phantom(): PhantomReified<ToTypeStr<State>>;
|
|
45
45
|
static get p(): reified.PhantomReified<string>;
|
|
46
|
-
static get bcs(): import("@mysten/sui/
|
|
46
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
47
47
|
id: {
|
|
48
48
|
id: {
|
|
49
49
|
bytes: string;
|