@ledgerhq/coin-tron 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +25 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/jest.integ.config.js +7 -0
- package/lib/bridge/broadcast.d.ts +7 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +26 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +101 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +19 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +20 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +65 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +30 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getEstimateFees.d.ts +6 -0
- package/lib/bridge/getEstimateFees.d.ts.map +1 -0
- package/lib/bridge/getEstimateFees.js +52 -0
- package/lib/bridge/getEstimateFees.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +218 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +10 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +60 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/preload.d.ts +8 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +32 -0
- package/lib/bridge/preload.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +19 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/serialization.d.ts +9 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +238 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +5 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +92 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/synchronization.d.ts +5 -0
- package/lib/bridge/synchronization.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.d.ts +3 -0
- package/lib/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.js +96 -0
- package/lib/bridge/synchronization.integ.test.js.map +1 -0
- package/lib/bridge/synchronization.js +216 -0
- package/lib/bridge/synchronization.js.map +1 -0
- package/lib/bridge/transaction.d.ts +15 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +61 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/config.d.ts +10 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +17 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/logic/constants.d.ts +4 -0
- package/lib/logic/constants.d.ts.map +1 -0
- package/lib/logic/constants.js +7 -0
- package/lib/logic/constants.js.map +1 -0
- package/lib/logic/pagination.d.ts +3 -0
- package/lib/logic/pagination.d.ts.map +1 -0
- package/lib/logic/pagination.js +19 -0
- package/lib/logic/pagination.js.map +1 -0
- package/lib/logic/utils.d.ts +12 -0
- package/lib/logic/utils.d.ts.map +1 -0
- package/lib/logic/utils.js +177 -0
- package/lib/logic/utils.js.map +1 -0
- package/lib/network/format.d.ts +9 -0
- package/lib/network/format.d.ts.map +1 -0
- package/lib/network/format.js +127 -0
- package/lib/network/format.js.map +1 -0
- package/lib/network/index.d.ts +30 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.integ.test.d.ts +2 -0
- package/lib/network/index.integ.test.d.ts.map +1 -0
- package/lib/network/index.integ.test.js +38 -0
- package/lib/network/index.integ.test.js.map +1 -0
- package/lib/network/index.js +555 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/index.test.d.ts +2 -0
- package/lib/network/index.test.d.ts.map +1 -0
- package/lib/network/index.test.js +66 -0
- package/lib/network/index.test.js.map +1 -0
- package/lib/network/superRepresentativesData.mock.d.ts +69 -0
- package/lib/network/superRepresentativesData.mock.d.ts.map +1 -0
- package/lib/network/superRepresentativesData.mock.js +2208 -0
- package/lib/network/superRepresentativesData.mock.js.map +1 -0
- package/lib/network/types.d.ts +122 -0
- package/lib/network/types.d.ts.map +1 -0
- package/lib/network/types.fixture.d.ts +498 -0
- package/lib/network/types.fixture.d.ts.map +1 -0
- package/lib/network/types.fixture.js +4375 -0
- package/lib/network/types.fixture.js.map +1 -0
- package/lib/network/types.js +13 -0
- package/lib/network/types.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +19 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +6 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +11 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-deviceActions.d.ts +4 -0
- package/lib/test/bot-deviceActions.d.ts.map +1 -0
- package/lib/test/bot-deviceActions.js +103 -0
- package/lib/test/bot-deviceActions.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +433 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +1284 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +52 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +155 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +6 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/types/bridge.d.ts +245 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +16 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/errors.d.ts +49 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +21 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +21 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +10 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +7 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +24 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +94 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +14 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +20 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +63 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +25 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getEstimateFees.d.ts +6 -0
- package/lib-es/bridge/getEstimateFees.d.ts.map +1 -0
- package/lib-es/bridge/getEstimateFees.js +47 -0
- package/lib-es/bridge/getEstimateFees.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +213 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +10 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +53 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/preload.d.ts +8 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +27 -0
- package/lib-es/bridge/preload.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +15 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/serialization.d.ts +9 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +229 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +5 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +85 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/synchronization.d.ts +5 -0
- package/lib-es/bridge/synchronization.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts +3 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.js +89 -0
- package/lib-es/bridge/synchronization.integ.test.js.map +1 -0
- package/lib-es/bridge/synchronization.js +209 -0
- package/lib-es/bridge/synchronization.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +15 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +55 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/config.d.ts +10 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +12 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/index.d.ts +3 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +3 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/logic/constants.d.ts +4 -0
- package/lib-es/logic/constants.d.ts.map +1 -0
- package/lib-es/logic/constants.js +4 -0
- package/lib-es/logic/constants.js.map +1 -0
- package/lib-es/logic/pagination.d.ts +3 -0
- package/lib-es/logic/pagination.d.ts.map +1 -0
- package/lib-es/logic/pagination.js +15 -0
- package/lib-es/logic/pagination.js.map +1 -0
- package/lib-es/logic/utils.d.ts +12 -0
- package/lib-es/logic/utils.d.ts.map +1 -0
- package/lib-es/logic/utils.js +167 -0
- package/lib-es/logic/utils.js.map +1 -0
- package/lib-es/network/format.d.ts +9 -0
- package/lib-es/network/format.d.ts.map +1 -0
- package/lib-es/network/format.js +117 -0
- package/lib-es/network/format.js.map +1 -0
- package/lib-es/network/index.d.ts +30 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.integ.test.d.ts +2 -0
- package/lib-es/network/index.integ.test.d.ts.map +1 -0
- package/lib-es/network/index.integ.test.js +36 -0
- package/lib-es/network/index.integ.test.js.map +1 -0
- package/lib-es/network/index.js +524 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/index.test.d.ts +2 -0
- package/lib-es/network/index.test.d.ts.map +1 -0
- package/lib-es/network/index.test.js +63 -0
- package/lib-es/network/index.test.js.map +1 -0
- package/lib-es/network/superRepresentativesData.mock.d.ts +69 -0
- package/lib-es/network/superRepresentativesData.mock.d.ts.map +1 -0
- package/lib-es/network/superRepresentativesData.mock.js +2206 -0
- package/lib-es/network/superRepresentativesData.mock.js.map +1 -0
- package/lib-es/network/types.d.ts +122 -0
- package/lib-es/network/types.d.ts.map +1 -0
- package/lib-es/network/types.fixture.d.ts +498 -0
- package/lib-es/network/types.fixture.d.ts.map +1 -0
- package/lib-es/network/types.fixture.js +4371 -0
- package/lib-es/network/types.fixture.js.map +1 -0
- package/lib-es/network/types.js +8 -0
- package/lib-es/network/types.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +17 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +6 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +6 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-deviceActions.d.ts +4 -0
- package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
- package/lib-es/test/bot-deviceActions.js +100 -0
- package/lib-es/test/bot-deviceActions.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +428 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +1278 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +52 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +149 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +6 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/types/bridge.d.ts +245 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +11 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/errors.d.ts +49 -0
- package/lib-es/types/errors.d.ts.map +1 -0
- package/lib-es/types/errors.js +18 -0
- package/lib-es/types/errors.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +5 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +10 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +133 -0
- package/src/bridge/broadcast.ts +24 -0
- package/src/bridge/buildOptimisticOperation.ts +133 -0
- package/src/bridge/createTransaction.ts +16 -0
- package/src/bridge/deviceTransactionConfig.ts +99 -0
- package/src/bridge/estimateMaxSpendable.ts +32 -0
- package/src/bridge/getEstimateFees.ts +52 -0
- package/src/bridge/getTransactionStatus.ts +263 -0
- package/src/bridge/index.ts +78 -0
- package/src/bridge/preload.ts +24 -0
- package/src/bridge/prepareTransaction.ts +12 -0
- package/src/bridge/serialization.ts +288 -0
- package/src/bridge/signOperation.ts +123 -0
- package/src/bridge/synchronization.integ.test.ts +105 -0
- package/src/bridge/synchronization.ts +284 -0
- package/src/bridge/transaction.ts +84 -0
- package/src/config.ts +24 -0
- package/src/index.ts +3 -0
- package/src/logic/constants.ts +4 -0
- package/src/logic/pagination.ts +21 -0
- package/src/logic/utils.ts +231 -0
- package/src/network/format.ts +148 -0
- package/src/network/index.integ.test.ts +33 -0
- package/src/network/index.test.ts +61 -0
- package/src/network/index.ts +747 -0
- package/src/network/superRepresentativesData.mock.ts +2205 -0
- package/src/network/types.fixture.ts +4476 -0
- package/src/network/types.ts +147 -0
- package/src/signer/getAddress.ts +13 -0
- package/src/signer/index.ts +7 -0
- package/src/test/bot-deviceActions.ts +121 -0
- package/src/test/bot-specs.ts +457 -0
- package/src/test/bridgeDatasetTest.ts +1343 -0
- package/src/test/cli.ts +219 -0
- package/src/test/index.ts +6 -0
- package/src/types/bridge.ts +304 -0
- package/src/types/errors.ts +22 -0
- package/src/types/index.ts +4 -0
- package/src/types/signer.ts +9 -0
- package/tsconfig.json +14 -0
- package/types/tronweb/index.d.ts +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC,0BAA0B,CAAC,CAAC;AAC3F,MAAM,CAAC,MAAM,qBAAqB,GAAG,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;AACrF,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,4BAA4B,GAAG,sBAAsB,CAAC,8BAA8B,CAAC,CAAC;AACnG,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC,sBAAsB,CAAC,CAAC;AACnF,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,sBAAsB,CAAC,cAAc,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC,yBAAyB,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,kCAAkC,GAAG,sBAAsB,CACtE,oCAAoC,CACrC,CAAC;AACF,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,qBAAqB,CAAC,CAAC;AACjF,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,mCAAmC,GAAG,sBAAsB,CACvE,qCAAqC,CACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAEzB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,2BAA2B;AAC3B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type TronAddress = {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
address: string;
|
|
4
|
+
};
|
|
5
|
+
export type TronSignature = string;
|
|
6
|
+
export interface TronSigner {
|
|
7
|
+
getAddress(path: string, boolDisplay?: boolean): Promise<TronAddress>;
|
|
8
|
+
sign(path: string, rawTxHex: string, tokenSignatures: string[]): Promise<TronSignature>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AACnC,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACtE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CACzF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ledgerhq/coin-tron",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Ledger Tron Coin integration",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ledger",
|
|
7
|
+
"LedgerWallet",
|
|
8
|
+
"trx",
|
|
9
|
+
"Tron",
|
|
10
|
+
"Hardware Wallet"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-tron",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"lib/*": [
|
|
26
|
+
"lib/*"
|
|
27
|
+
],
|
|
28
|
+
"lib-es/*": [
|
|
29
|
+
"lib-es/*"
|
|
30
|
+
],
|
|
31
|
+
"bridge": [
|
|
32
|
+
"lib/bridge/index"
|
|
33
|
+
],
|
|
34
|
+
"deviceTransactionConfig": [
|
|
35
|
+
"lib/bridge/deviceTransactionConfig"
|
|
36
|
+
],
|
|
37
|
+
"network": [
|
|
38
|
+
"lib/network/index"
|
|
39
|
+
],
|
|
40
|
+
"specs": [
|
|
41
|
+
"lib/test/bot-specs"
|
|
42
|
+
],
|
|
43
|
+
"signer": [
|
|
44
|
+
"lib/signer/index"
|
|
45
|
+
],
|
|
46
|
+
"transaction": [
|
|
47
|
+
"lib/bridge/transaction"
|
|
48
|
+
],
|
|
49
|
+
"types": [
|
|
50
|
+
"lib/types/index"
|
|
51
|
+
],
|
|
52
|
+
"*": [
|
|
53
|
+
"lib/*"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"exports": {
|
|
58
|
+
"./lib/*": "./lib/*.js",
|
|
59
|
+
"./lib-es/*": "./lib-es/*.js",
|
|
60
|
+
"./bridge": {
|
|
61
|
+
"require": "./lib/bridge/index.js",
|
|
62
|
+
"default": "./lib-es/bridge/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./deviceTransactionConfig": {
|
|
65
|
+
"require": "./lib/bridge/deviceTransactionConfig.js",
|
|
66
|
+
"default": "./lib-es/bridge/deviceTransactionConfig.js"
|
|
67
|
+
},
|
|
68
|
+
"./network": {
|
|
69
|
+
"require": "./lib/network/index.js",
|
|
70
|
+
"default": "./lib-es/network/index.js"
|
|
71
|
+
},
|
|
72
|
+
"./signer": {
|
|
73
|
+
"require": "./lib/signer/index.js",
|
|
74
|
+
"default": "./lib-es/signer/index.js"
|
|
75
|
+
},
|
|
76
|
+
"./specs": {
|
|
77
|
+
"require": "./lib/test/bot-specs.js",
|
|
78
|
+
"default": "./lib-es/bridge/transaction.js"
|
|
79
|
+
},
|
|
80
|
+
"./transaction": {
|
|
81
|
+
"require": "./lib/bridge/transaction.js",
|
|
82
|
+
"default": "./lib-es/bridge/transaction.js"
|
|
83
|
+
},
|
|
84
|
+
"./*": {
|
|
85
|
+
"require": "./lib/*.js",
|
|
86
|
+
"default": "./lib-es/*.js"
|
|
87
|
+
},
|
|
88
|
+
"./package.json": "./package.json"
|
|
89
|
+
},
|
|
90
|
+
"license": "Apache-2.0",
|
|
91
|
+
"dependencies": {
|
|
92
|
+
"bignumber.js": "^9.1.2",
|
|
93
|
+
"bs58check": "^2.1.2",
|
|
94
|
+
"expect": "^27.4.6",
|
|
95
|
+
"invariant": "^2.2.2",
|
|
96
|
+
"lodash": "^4.17.21",
|
|
97
|
+
"rxjs": "^7.8.1",
|
|
98
|
+
"tronweb": "^5.3.2",
|
|
99
|
+
"@ledgerhq/coin-framework": "^0.14.0",
|
|
100
|
+
"@ledgerhq/cryptoassets": "^13.1.0",
|
|
101
|
+
"@ledgerhq/devices": "^8.4.0",
|
|
102
|
+
"@ledgerhq/errors": "^6.17.0",
|
|
103
|
+
"@ledgerhq/live-env": "^2.1.0",
|
|
104
|
+
"@ledgerhq/live-network": "^1.3.0",
|
|
105
|
+
"@ledgerhq/live-promise": "^0.1.0",
|
|
106
|
+
"@ledgerhq/logs": "^6.12.0",
|
|
107
|
+
"@ledgerhq/types-live": "^6.48.0"
|
|
108
|
+
},
|
|
109
|
+
"devDependencies": {
|
|
110
|
+
"@agrozyme/types-tronweb": "^5.3.2",
|
|
111
|
+
"@types/bs58check": "^2.1.0",
|
|
112
|
+
"@types/invariant": "^2.2.2",
|
|
113
|
+
"@types/jest": "^29.5.10",
|
|
114
|
+
"@types/lodash": "^4.14.191",
|
|
115
|
+
"jest": "^29.7.0",
|
|
116
|
+
"msw": "^2.0.11",
|
|
117
|
+
"ts-jest": "^29.1.1",
|
|
118
|
+
"typescript": "^5.4.5"
|
|
119
|
+
},
|
|
120
|
+
"scripts": {
|
|
121
|
+
"clean": "rimraf lib lib-es",
|
|
122
|
+
"build": "tsc && tsc -m ES6 --outDir lib-es",
|
|
123
|
+
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-tron.json",
|
|
124
|
+
"prewatch": "pnpm build",
|
|
125
|
+
"watch": "tsc --watch",
|
|
126
|
+
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
127
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
128
|
+
"lint:fix": "pnpm lint --fix",
|
|
129
|
+
"test": "jest",
|
|
130
|
+
"test-integ": "jest --config=jest.integ.config.js",
|
|
131
|
+
"unimported": "unimported"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
|
|
2
|
+
import { broadcastTron } from "../network";
|
|
3
|
+
|
|
4
|
+
const broadcast = async ({
|
|
5
|
+
signedOperation: { signature, operation, rawData },
|
|
6
|
+
}: {
|
|
7
|
+
account: Account;
|
|
8
|
+
signedOperation: SignedOperation;
|
|
9
|
+
}): Promise<Operation> => {
|
|
10
|
+
const transaction = {
|
|
11
|
+
raw_data: rawData,
|
|
12
|
+
txID: operation.hash,
|
|
13
|
+
signature: [signature],
|
|
14
|
+
};
|
|
15
|
+
const submittedTransaction = await broadcastTron(transaction);
|
|
16
|
+
|
|
17
|
+
if (submittedTransaction.result !== true) {
|
|
18
|
+
throw new Error(submittedTransaction.resultMessage);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return operation;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default broadcast;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
2
|
+
import { TokenAccount } from "@ledgerhq/types-live";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import get from "lodash/get";
|
|
5
|
+
import { getOperationTypefromMode } from "../logic/utils";
|
|
6
|
+
import {
|
|
7
|
+
Transaction,
|
|
8
|
+
TronAccount,
|
|
9
|
+
TronOperation,
|
|
10
|
+
TronResource,
|
|
11
|
+
TrongridExtraTxInfo,
|
|
12
|
+
} from "../types";
|
|
13
|
+
|
|
14
|
+
const getValue = (
|
|
15
|
+
account: TronAccount,
|
|
16
|
+
subAccount: TokenAccount | undefined,
|
|
17
|
+
transaction: Transaction,
|
|
18
|
+
fee: BigNumber,
|
|
19
|
+
): BigNumber => {
|
|
20
|
+
switch (transaction.mode) {
|
|
21
|
+
case "send":
|
|
22
|
+
return subAccount ? fee : new BigNumber(transaction.amount || 0).plus(fee);
|
|
23
|
+
|
|
24
|
+
case "claimReward": {
|
|
25
|
+
return account.tronResources ? account.tronResources.unwithdrawnReward : new BigNumber(0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
default:
|
|
29
|
+
return new BigNumber(0);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getExtra = (
|
|
34
|
+
account: TronAccount,
|
|
35
|
+
transaction: Transaction,
|
|
36
|
+
resource: TronResource,
|
|
37
|
+
): TrongridExtraTxInfo | null | undefined => {
|
|
38
|
+
switch (transaction.mode) {
|
|
39
|
+
case "freeze":
|
|
40
|
+
return {
|
|
41
|
+
frozenAmount: transaction.amount,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
case "unfreeze":
|
|
45
|
+
return {
|
|
46
|
+
unfreezeAmount: transaction.amount,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
case "vote":
|
|
50
|
+
return {
|
|
51
|
+
votes: transaction.votes,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
case "unDelegateResource":
|
|
55
|
+
return {
|
|
56
|
+
unDelegatedAmount: transaction.amount,
|
|
57
|
+
receiverAddress: transaction.recipient,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
case "legacyUnfreeze":
|
|
61
|
+
return {
|
|
62
|
+
unfreezeAmount: get(
|
|
63
|
+
account.tronResources,
|
|
64
|
+
`frozen.${resource.toLocaleLowerCase()}.amount`,
|
|
65
|
+
new BigNumber(0),
|
|
66
|
+
),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
default:
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const buildOptimisticOperation = (
|
|
75
|
+
account: TronAccount,
|
|
76
|
+
subAccount: TokenAccount | undefined,
|
|
77
|
+
transaction: Transaction,
|
|
78
|
+
fee: BigNumber,
|
|
79
|
+
hash: string,
|
|
80
|
+
): TronOperation => {
|
|
81
|
+
const value = getValue(account, subAccount, transaction, fee);
|
|
82
|
+
const operationType = getOperationTypefromMode(transaction.mode);
|
|
83
|
+
const resource = transaction.resource || "BANDWIDTH";
|
|
84
|
+
const extra = getExtra(account, transaction, resource) || {};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* FIXME
|
|
88
|
+
*
|
|
89
|
+
* This is not working and cannot work simply because this "NONE" type doesn't exist during a sync,
|
|
90
|
+
* as well as subOperations which are never created either.
|
|
91
|
+
*
|
|
92
|
+
* And even after fixing this, we're getting wrong fee estimation for TRC20 transactions
|
|
93
|
+
* which are considered as 0 all the time, while it always being between 1 and 10 TRX.
|
|
94
|
+
*/
|
|
95
|
+
const operation: TronOperation = {
|
|
96
|
+
id: encodeOperationId(account.id, hash, operationType),
|
|
97
|
+
hash,
|
|
98
|
+
// if it's a token op and there is no fee, this operation does not exist and is a "NONE"
|
|
99
|
+
type: subAccount && value.eq(0) ? "NONE" : operationType,
|
|
100
|
+
value,
|
|
101
|
+
fee,
|
|
102
|
+
blockHash: null,
|
|
103
|
+
blockHeight: null,
|
|
104
|
+
senders: [account.freshAddress],
|
|
105
|
+
recipients: [transaction.recipient],
|
|
106
|
+
accountId: account.id,
|
|
107
|
+
date: new Date(),
|
|
108
|
+
extra,
|
|
109
|
+
subOperations: subAccount
|
|
110
|
+
? [
|
|
111
|
+
{
|
|
112
|
+
id: encodeOperationId(subAccount.id, hash, "OUT"),
|
|
113
|
+
hash,
|
|
114
|
+
type: "OUT",
|
|
115
|
+
value:
|
|
116
|
+
transaction.useAllAmount && subAccount
|
|
117
|
+
? subAccount.balance
|
|
118
|
+
: new BigNumber(transaction.amount || 0),
|
|
119
|
+
fee: new BigNumber(0),
|
|
120
|
+
blockHash: null,
|
|
121
|
+
blockHeight: null,
|
|
122
|
+
senders: [account.freshAddress],
|
|
123
|
+
recipients: [transaction.recipient],
|
|
124
|
+
accountId: subAccount.id,
|
|
125
|
+
date: new Date(),
|
|
126
|
+
extra: {},
|
|
127
|
+
},
|
|
128
|
+
]
|
|
129
|
+
: [],
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
return operation;
|
|
133
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Transaction } from "../types";
|
|
3
|
+
|
|
4
|
+
const createTransaction = (): Transaction => ({
|
|
5
|
+
family: "tron",
|
|
6
|
+
amount: new BigNumber(0),
|
|
7
|
+
useAllAmount: false,
|
|
8
|
+
mode: "send",
|
|
9
|
+
duration: 3,
|
|
10
|
+
recipient: "",
|
|
11
|
+
networkInfo: null,
|
|
12
|
+
resource: null,
|
|
13
|
+
votes: [],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export default createTransaction;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { AccountLike, Account } from "@ledgerhq/types-live";
|
|
2
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account";
|
|
3
|
+
import type { CommonDeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
4
|
+
import type { Transaction, TransactionStatus } from "../types";
|
|
5
|
+
|
|
6
|
+
export type ExtraDeviceTransactionField =
|
|
7
|
+
| {
|
|
8
|
+
type: "tron.resource";
|
|
9
|
+
label: string;
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
type: "tron.votes";
|
|
14
|
+
label: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type DeviceTransactionField = CommonDeviceTransactionField | ExtraDeviceTransactionField;
|
|
18
|
+
|
|
19
|
+
function getDeviceTransactionConfig({
|
|
20
|
+
transaction: { votes, resource, mode, recipient },
|
|
21
|
+
account,
|
|
22
|
+
parentAccount,
|
|
23
|
+
status: { amount },
|
|
24
|
+
}: {
|
|
25
|
+
account: AccountLike;
|
|
26
|
+
parentAccount: Account | null | undefined;
|
|
27
|
+
transaction: Transaction;
|
|
28
|
+
status: TransactionStatus;
|
|
29
|
+
}): Array<DeviceTransactionField> {
|
|
30
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
31
|
+
const fields: Array<DeviceTransactionField> = [];
|
|
32
|
+
|
|
33
|
+
if (resource) {
|
|
34
|
+
fields.push({
|
|
35
|
+
type: "tron.resource",
|
|
36
|
+
label: "Resource",
|
|
37
|
+
value: resource.slice(0, 1).toUpperCase() + resource.slice(1).toLowerCase(),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (votes && votes.length > 0) {
|
|
42
|
+
// NB in future if we unify UI with other coin, we could converge to a "votes" top level
|
|
43
|
+
fields.push({
|
|
44
|
+
type: "tron.votes",
|
|
45
|
+
label: "Votes",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!amount.isZero()) {
|
|
50
|
+
fields.push({
|
|
51
|
+
type: "amount",
|
|
52
|
+
label: "Amount",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (mode === "freeze") {
|
|
57
|
+
fields.push({
|
|
58
|
+
type: "address",
|
|
59
|
+
label: "Freeze To",
|
|
60
|
+
address: mainAccount.freshAddress,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (mode === "unfreeze" || mode === "legacyUnfreeze") {
|
|
65
|
+
fields.push({
|
|
66
|
+
type: "address",
|
|
67
|
+
label: "Unfreeze To",
|
|
68
|
+
address: mainAccount.freshAddress,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (mode === "withdrawExpireUnfreeze") {
|
|
73
|
+
fields.push({
|
|
74
|
+
type: "address",
|
|
75
|
+
label: "Withdraw unfrozen to",
|
|
76
|
+
address: mainAccount.freshAddress,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (mode === "unDelegateResource") {
|
|
81
|
+
fields.push({
|
|
82
|
+
type: "address",
|
|
83
|
+
label: "Undelegate from",
|
|
84
|
+
address: recipient,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (mode !== "send") {
|
|
89
|
+
fields.push({
|
|
90
|
+
type: "address",
|
|
91
|
+
label: "From Address",
|
|
92
|
+
address: mainAccount.freshAddress,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return fields;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default getDeviceTransactionConfig;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account";
|
|
3
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
4
|
+
import { fetchTronContract } from "../network";
|
|
5
|
+
import { Transaction, TronAccount } from "../types";
|
|
6
|
+
import createTransaction from "./createTransaction";
|
|
7
|
+
import getEstimatedFees from "./getEstimateFees";
|
|
8
|
+
|
|
9
|
+
const estimateMaxSpendable: AccountBridge<
|
|
10
|
+
Transaction,
|
|
11
|
+
TronAccount
|
|
12
|
+
>["estimateMaxSpendable"] = async ({ account, parentAccount, transaction }): Promise<BigNumber> => {
|
|
13
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
14
|
+
const fees = await getEstimatedFees(
|
|
15
|
+
mainAccount,
|
|
16
|
+
{
|
|
17
|
+
...createTransaction(),
|
|
18
|
+
subAccountId: account.type === "Account" ? null : account.id,
|
|
19
|
+
...transaction,
|
|
20
|
+
recipient: transaction?.recipient || "0x0000000000000000000000000000000000000000",
|
|
21
|
+
amount: new BigNumber(0),
|
|
22
|
+
},
|
|
23
|
+
transaction && transaction.recipient
|
|
24
|
+
? (await fetchTronContract(transaction.recipient)) !== undefined
|
|
25
|
+
: false,
|
|
26
|
+
);
|
|
27
|
+
return account.type === "Account"
|
|
28
|
+
? BigNumber.max(0, account.spendableBalance.minus(fees))
|
|
29
|
+
: account.balance;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default estimateMaxSpendable;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import { Transaction } from "../types";
|
|
4
|
+
import { fetchTronAccount } from "../network";
|
|
5
|
+
import { ACTIVATION_FEES } from "../logic/constants";
|
|
6
|
+
import { getEstimatedBlockSize, extractBandwidthInfo } from "../logic/utils";
|
|
7
|
+
|
|
8
|
+
// see : https://developers.tron.network/docs/bandwith#section-bandwidth-points-consumption
|
|
9
|
+
// 1. cost around 200 Bandwidth, if not enough check Free Bandwidth
|
|
10
|
+
// 2. If not enough, will cost some TRX
|
|
11
|
+
// 3. normal transfert cost around 0.002 TRX
|
|
12
|
+
const getFeesFromBandwidth = (account: Account, transaction: Transaction): BigNumber => {
|
|
13
|
+
const { freeUsed, freeLimit, gainedUsed, gainedLimit } = extractBandwidthInfo(
|
|
14
|
+
transaction.networkInfo,
|
|
15
|
+
);
|
|
16
|
+
const available = freeLimit.minus(freeUsed).plus(gainedLimit).minus(gainedUsed);
|
|
17
|
+
const estimatedBandwidthCost = getEstimatedBlockSize(account, transaction);
|
|
18
|
+
|
|
19
|
+
if (available.lt(estimatedBandwidthCost)) {
|
|
20
|
+
return new BigNumber(2000); // cost is around 0.002 TRX
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return new BigNumber(0); // no fee
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Special case: If activated an account, cost around 0.1 TRX
|
|
27
|
+
const getFeesFromAccountActivation = async (a: Account, t: Transaction): Promise<BigNumber> => {
|
|
28
|
+
const recipientAccount = await fetchTronAccount(t.recipient);
|
|
29
|
+
const { gainedUsed, gainedLimit } = extractBandwidthInfo(t.networkInfo);
|
|
30
|
+
const available = gainedLimit.minus(gainedUsed);
|
|
31
|
+
const estimatedBandwidthCost = getEstimatedBlockSize(a, t);
|
|
32
|
+
|
|
33
|
+
if (recipientAccount.length === 0 && available.lt(estimatedBandwidthCost)) {
|
|
34
|
+
return ACTIVATION_FEES; // cost is around 1 TRX
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return new BigNumber(0); // no fee
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const getEstimatedFees = async (a: Account, t: Transaction, isContract: boolean) => {
|
|
41
|
+
const feesFromAccountActivation =
|
|
42
|
+
t.mode === "send" && !isContract ? await getFeesFromAccountActivation(a, t) : new BigNumber(0);
|
|
43
|
+
|
|
44
|
+
if (feesFromAccountActivation.gt(0)) {
|
|
45
|
+
return feesFromAccountActivation;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const feesFromBandwidth = getFeesFromBandwidth(a, t);
|
|
49
|
+
return feesFromBandwidth;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default getEstimatedFees;
|