@ledgerhq/coin-aptos 1.10.0-nightly.0 → 1.10.0-nightly.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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +18 -6
- package/CHANGELOG.md +40 -9
- package/jest.config.js +1 -1
- package/jest.integ.config.js +8 -0
- package/lib/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/api/craftTransaction.unit.test.js +50 -0
- package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/api/getBalance.unit.test.d.ts +2 -0
- package/lib/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
- package/lib/__tests__/api/getBalance.unit.test.js +41 -0
- package/lib/__tests__/api/getBalance.unit.test.js.map +1 -0
- package/lib/__tests__/api/index.integ.test.d.ts +2 -0
- package/lib/__tests__/api/index.integ.test.d.ts.map +1 -0
- package/lib/__tests__/api/index.integ.test.js +115 -0
- package/lib/__tests__/api/index.integ.test.js.map +1 -0
- package/lib/__tests__/api/index.test.js +48 -460
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/broadcast.test.js +5 -5
- package/lib/__tests__/bridge/broadcast.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +9 -9
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/logic.test.js +3 -553
- package/lib/__tests__/bridge/logic.test.js.map +1 -1
- package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
- package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/signOperation.test.js +9 -12
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +6 -6
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/__tests__/index.test.js +1 -1
- package/lib/__tests__/index.test.js.map +1 -1
- package/lib/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
- package/lib/__tests__/{bridge → logic}/buildTransaction.test.js +16 -12
- package/lib/__tests__/logic/buildTransaction.test.js.map +1 -0
- package/lib/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/calculateAmount.unit.test.js +45 -0
- package/lib/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
- package/lib/__tests__/logic/combine.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/combine.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/combine.unit.test.js +47 -0
- package/lib/__tests__/logic/combine.unit.test.js.map +1 -0
- package/lib/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/compareAddress.unit.test.js +26 -0
- package/lib/__tests__/logic/compareAddress.unit.test.js.map +1 -0
- package/lib/__tests__/logic/createTransaction.test.d.ts.map +1 -0
- package/lib/__tests__/{bridge → logic}/createTransaction.test.js +2 -2
- package/lib/__tests__/logic/createTransaction.test.js.map +1 -0
- package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js +186 -0
- package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
- package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/getFunctionAddress.unit.test.js +29 -0
- package/lib/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
- package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/getResourceAddress.unit.test.js +218 -0
- package/lib/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
- package/lib/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/isTestnet.unit.test.js +12 -0
- package/lib/__tests__/logic/isTestnet.unit.test.js.map +1 -0
- package/lib/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/processRecipients.unit.test.js +79 -0
- package/lib/__tests__/logic/processRecipients.unit.test.js.map +1 -0
- package/lib/__tests__/network/client.test.d.ts +2 -0
- package/lib/__tests__/network/client.test.d.ts.map +1 -0
- package/lib/__tests__/network/client.test.js +992 -0
- package/lib/__tests__/network/client.test.js.map +1 -0
- package/lib/api/index.d.ts +4 -33
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +19 -196
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/broadcast.d.ts +3 -2
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +4 -3
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +5 -4
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +8 -7
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/index.d.ts +1 -1
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +1 -1
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/logic.d.ts +1 -20
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +12 -207
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -3
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +4 -4
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.js +3 -3
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/config.d.ts +13 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +9 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +5 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +8 -1
- package/lib/constants.js.map +1 -1
- package/lib/{bridge → logic}/buildTransaction.d.ts +1 -1
- package/lib/logic/buildTransaction.d.ts.map +1 -0
- package/lib/{bridge → logic}/buildTransaction.js +2 -2
- package/lib/logic/buildTransaction.js.map +1 -0
- package/lib/logic/calculateAmount.d.ts +3 -0
- package/lib/logic/calculateAmount.d.ts.map +1 -0
- package/lib/logic/calculateAmount.js +13 -0
- package/lib/logic/calculateAmount.js.map +1 -0
- package/lib/logic/combine.d.ts +4 -0
- package/lib/logic/combine.d.ts.map +1 -0
- package/lib/logic/combine.js +34 -0
- package/lib/logic/combine.js.map +1 -0
- package/lib/logic/craftTransaction.d.ts +5 -0
- package/lib/logic/craftTransaction.d.ts.map +1 -0
- package/lib/logic/craftTransaction.js +23 -0
- package/lib/logic/craftTransaction.js.map +1 -0
- package/lib/logic/createTransaction.d.ts.map +1 -0
- package/lib/{bridge → logic}/createTransaction.js +3 -3
- package/lib/logic/createTransaction.js.map +1 -0
- package/lib/logic/getBalance.d.ts +5 -0
- package/lib/logic/getBalance.d.ts.map +1 -0
- package/lib/logic/getBalance.js +12 -0
- package/lib/logic/getBalance.js.map +1 -0
- package/lib/logic/getCoinAndAmounts.d.ts +13 -0
- package/lib/logic/getCoinAndAmounts.d.ts.map +1 -0
- package/lib/logic/getCoinAndAmounts.js +112 -0
- package/lib/logic/getCoinAndAmounts.js.map +1 -0
- package/lib/logic/getFunctionAddress.d.ts +3 -0
- package/lib/logic/getFunctionAddress.d.ts.map +1 -0
- package/lib/logic/getFunctionAddress.js +12 -0
- package/lib/logic/getFunctionAddress.js.map +1 -0
- package/lib/logic/getResourceAddress.d.ts +4 -0
- package/lib/logic/getResourceAddress.d.ts.map +1 -0
- package/lib/logic/getResourceAddress.js +17 -0
- package/lib/logic/getResourceAddress.js.map +1 -0
- package/lib/logic/isTestnet.d.ts +2 -0
- package/lib/logic/isTestnet.d.ts.map +1 -0
- package/lib/logic/isTestnet.js +9 -0
- package/lib/logic/isTestnet.js.map +1 -0
- package/lib/logic/isWriteSetChangeWriteResource.d.ts +3 -0
- package/lib/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
- package/lib/logic/isWriteSetChangeWriteResource.js +8 -0
- package/lib/logic/isWriteSetChangeWriteResource.js.map +1 -0
- package/lib/logic/normalizeTransactionOptions.d.ts +3 -0
- package/lib/logic/normalizeTransactionOptions.d.ts.map +1 -0
- package/lib/logic/normalizeTransactionOptions.js +21 -0
- package/lib/logic/normalizeTransactionOptions.js.map +1 -0
- package/lib/logic/processRecipients.d.ts +6 -0
- package/lib/logic/processRecipients.d.ts.map +1 -0
- package/lib/logic/processRecipients.js +57 -0
- package/lib/logic/processRecipients.js.map +1 -0
- package/lib/logic/transactionsToOperations.d.ts +7 -0
- package/lib/logic/transactionsToOperations.d.ts.map +1 -0
- package/lib/logic/transactionsToOperations.js +85 -0
- package/lib/logic/transactionsToOperations.js.map +1 -0
- package/lib/network/client.d.ts +38 -0
- package/lib/network/client.d.ts.map +1 -0
- package/lib/network/client.js +266 -0
- package/lib/network/client.js.map +1 -0
- package/lib/network/graphql/queries.d.ts.map +1 -0
- package/lib/network/graphql/queries.js.map +1 -0
- package/lib/network/graphql/types.d.ts.map +1 -0
- package/lib/{api → network}/graphql/types.js.map +1 -1
- package/lib/network/index.d.ts +2 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +19 -7
- package/lib/network/index.js.map +1 -1
- package/lib/types/assets.d.ts +12 -0
- package/lib/types/assets.d.ts.map +1 -0
- package/lib/types/assets.js +3 -0
- package/lib/types/assets.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/api/craftTransaction.unit.test.js +48 -0
- package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/api/getBalance.unit.test.d.ts +2 -0
- package/lib-es/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/api/getBalance.unit.test.js +36 -0
- package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -0
- package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
- package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
- package/lib-es/__tests__/api/index.integ.test.js +113 -0
- package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
- package/lib-es/__tests__/api/index.test.js +52 -464
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
- package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +2 -2
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/logic.test.js +3 -553
- package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
- package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
- package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/signOperation.test.js +9 -12
- package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib-es/__tests__/bridge/synchronisation.test.js +3 -3
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/__tests__/index.test.js +1 -1
- package/lib-es/__tests__/index.test.js.map +1 -1
- package/lib-es/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
- package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.js +9 -5
- package/lib-es/__tests__/logic/buildTransaction.test.js.map +1 -0
- package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/calculateAmount.unit.test.js +40 -0
- package/lib-es/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
- package/lib-es/__tests__/logic/combine.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/combine.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/combine.unit.test.js +45 -0
- package/lib-es/__tests__/logic/combine.unit.test.js.map +1 -0
- package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/compareAddress.unit.test.js +24 -0
- package/lib-es/__tests__/logic/compareAddress.unit.test.js.map +1 -0
- package/lib-es/__tests__/logic/createTransaction.test.d.ts.map +1 -0
- package/lib-es/__tests__/{bridge → logic}/createTransaction.test.js +2 -2
- package/lib-es/__tests__/logic/createTransaction.test.js.map +1 -0
- package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js +181 -0
- package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
- package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js +27 -0
- package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
- package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/getResourceAddress.unit.test.js +216 -0
- package/lib-es/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
- package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/isTestnet.unit.test.js +10 -0
- package/lib-es/__tests__/logic/isTestnet.unit.test.js.map +1 -0
- package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/processRecipients.unit.test.js +74 -0
- package/lib-es/__tests__/logic/processRecipients.unit.test.js.map +1 -0
- package/lib-es/__tests__/network/client.test.d.ts +2 -0
- package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
- package/lib-es/__tests__/network/client.test.js +987 -0
- package/lib-es/__tests__/network/client.test.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -33
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +17 -194
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts +3 -2
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +4 -3
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +3 -2
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +3 -2
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/index.d.ts +1 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +1 -1
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/logic.d.ts +1 -20
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +6 -190
- package/lib-es/bridge/logic.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +3 -2
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +2 -2
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.js +1 -1
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/config.d.ts +13 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +5 -1
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +4 -0
- package/lib-es/constants.js.map +1 -1
- package/lib-es/{bridge → logic}/buildTransaction.d.ts +1 -1
- package/lib-es/logic/buildTransaction.d.ts.map +1 -0
- package/lib-es/{bridge → logic}/buildTransaction.js +1 -1
- package/lib-es/logic/buildTransaction.js.map +1 -0
- package/lib-es/logic/calculateAmount.d.ts +3 -0
- package/lib-es/logic/calculateAmount.d.ts.map +1 -0
- package/lib-es/logic/calculateAmount.js +9 -0
- package/lib-es/logic/calculateAmount.js.map +1 -0
- package/lib-es/logic/combine.d.ts +4 -0
- package/lib-es/logic/combine.d.ts.map +1 -0
- package/lib-es/logic/combine.js +29 -0
- package/lib-es/logic/combine.js.map +1 -0
- package/lib-es/logic/craftTransaction.d.ts +5 -0
- package/lib-es/logic/craftTransaction.d.ts.map +1 -0
- package/lib-es/logic/craftTransaction.js +16 -0
- package/lib-es/logic/craftTransaction.js.map +1 -0
- package/lib-es/logic/createTransaction.d.ts.map +1 -0
- package/lib-es/{bridge → logic}/createTransaction.js +1 -1
- package/lib-es/logic/createTransaction.js.map +1 -0
- package/lib-es/logic/getBalance.d.ts +5 -0
- package/lib-es/logic/getBalance.d.ts.map +1 -0
- package/lib-es/logic/getBalance.js +8 -0
- package/lib-es/logic/getBalance.js.map +1 -0
- package/lib-es/logic/getCoinAndAmounts.d.ts +13 -0
- package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -0
- package/lib-es/logic/getCoinAndAmounts.js +101 -0
- package/lib-es/logic/getCoinAndAmounts.js.map +1 -0
- package/lib-es/logic/getFunctionAddress.d.ts +3 -0
- package/lib-es/logic/getFunctionAddress.d.ts.map +1 -0
- package/lib-es/logic/getFunctionAddress.js +8 -0
- package/lib-es/logic/getFunctionAddress.js.map +1 -0
- package/lib-es/logic/getResourceAddress.d.ts +4 -0
- package/lib-es/logic/getResourceAddress.d.ts.map +1 -0
- package/lib-es/logic/getResourceAddress.js +13 -0
- package/lib-es/logic/getResourceAddress.js.map +1 -0
- package/lib-es/logic/isTestnet.d.ts +2 -0
- package/lib-es/logic/isTestnet.d.ts.map +1 -0
- package/lib-es/logic/isTestnet.js +5 -0
- package/lib-es/logic/isTestnet.js.map +1 -0
- package/lib-es/logic/isWriteSetChangeWriteResource.d.ts +3 -0
- package/lib-es/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
- package/lib-es/logic/isWriteSetChangeWriteResource.js +4 -0
- package/lib-es/logic/isWriteSetChangeWriteResource.js.map +1 -0
- package/lib-es/logic/normalizeTransactionOptions.d.ts +3 -0
- package/lib-es/logic/normalizeTransactionOptions.d.ts.map +1 -0
- package/lib-es/logic/normalizeTransactionOptions.js +17 -0
- package/lib-es/logic/normalizeTransactionOptions.js.map +1 -0
- package/lib-es/logic/processRecipients.d.ts +6 -0
- package/lib-es/logic/processRecipients.d.ts.map +1 -0
- package/lib-es/logic/processRecipients.js +53 -0
- package/lib-es/logic/processRecipients.js.map +1 -0
- package/lib-es/logic/transactionsToOperations.d.ts +7 -0
- package/lib-es/logic/transactionsToOperations.d.ts.map +1 -0
- package/lib-es/logic/transactionsToOperations.js +77 -0
- package/lib-es/logic/transactionsToOperations.js.map +1 -0
- package/lib-es/network/client.d.ts +38 -0
- package/lib-es/network/client.d.ts.map +1 -0
- package/lib-es/network/client.js +259 -0
- package/lib-es/network/client.js.map +1 -0
- package/lib-es/network/graphql/queries.d.ts.map +1 -0
- package/lib-es/network/graphql/queries.js.map +1 -0
- package/lib-es/network/graphql/types.d.ts.map +1 -0
- package/lib-es/{api → network}/graphql/types.js.map +1 -1
- package/lib-es/network/index.d.ts +2 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +6 -8
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/types/assets.d.ts +12 -0
- package/lib-es/types/assets.d.ts.map +1 -0
- package/lib-es/types/assets.js +2 -0
- package/lib-es/types/assets.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/__tests__/api/craftTransaction.unit.test.ts +70 -0
- package/src/__tests__/api/getBalance.unit.test.ts +44 -0
- package/src/__tests__/api/index.integ.test.ts +139 -0
- package/src/__tests__/api/index.test.ts +60 -547
- package/src/__tests__/bridge/broadcast.test.ts +2 -2
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +2 -2
- package/src/__tests__/bridge/logic.test.ts +4 -649
- package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
- package/src/__tests__/bridge/signOperation.test.ts +12 -13
- package/src/__tests__/bridge/synchronisation.test.ts +4 -4
- package/src/__tests__/index.test.ts +1 -1
- package/src/__tests__/{bridge → logic}/buildTransaction.test.ts +12 -7
- package/src/__tests__/logic/calculateAmount.unit.test.ts +51 -0
- package/src/__tests__/logic/combine.unit.test.ts +65 -0
- package/src/__tests__/logic/compareAddress.unit.test.ts +27 -0
- package/src/__tests__/{bridge → logic}/createTransaction.test.ts +2 -2
- package/src/__tests__/logic/getCoinAndAmounts.unit.test.ts +195 -0
- package/src/__tests__/logic/getFunctionAddress.unit.test.ts +33 -0
- package/src/__tests__/logic/getResourceAddress.unit.test.ts +241 -0
- package/src/__tests__/logic/isTestnet.unit.test.ts +11 -0
- package/src/__tests__/logic/processRecipients.unit.test.ts +87 -0
- package/src/__tests__/network/client.test.ts +1107 -0
- package/src/api/index.ts +29 -251
- package/src/bridge/broadcast.ts +7 -7
- package/src/bridge/estimateMaxSpendable.ts +3 -2
- package/src/bridge/getFeesForTransaction.ts +4 -3
- package/src/bridge/index.ts +2 -2
- package/src/bridge/logic.ts +8 -283
- package/src/bridge/prepareTransaction.ts +4 -2
- package/src/bridge/signOperation.ts +2 -2
- package/src/bridge/synchronisation.ts +1 -1
- package/src/config.ts +19 -0
- package/src/constants.ts +6 -1
- package/src/{bridge → logic}/buildTransaction.ts +2 -2
- package/src/logic/calculateAmount.ts +15 -0
- package/src/logic/combine.ts +51 -0
- package/src/logic/craftTransaction.ts +26 -0
- package/src/{bridge → logic}/createTransaction.ts +1 -1
- package/src/logic/getBalance.ts +15 -0
- package/src/logic/getCoinAndAmounts.ts +141 -0
- package/src/logic/getFunctionAddress.ts +9 -0
- package/src/logic/getResourceAddress.ts +24 -0
- package/src/logic/isTestnet.ts +5 -0
- package/src/logic/isWriteSetChangeWriteResource.ts +7 -0
- package/src/logic/normalizeTransactionOptions.ts +18 -0
- package/src/logic/processRecipients.ts +87 -0
- package/src/logic/transactionsToOperations.ts +105 -0
- package/src/network/client.ts +351 -0
- package/src/network/index.ts +6 -14
- package/src/types/assets.ts +15 -0
- package/src/types/index.ts +5 -0
- package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
- package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
- package/lib/api/graphql/queries.d.ts.map +0 -1
- package/lib/api/graphql/queries.js.map +0 -1
- package/lib/api/graphql/types.d.ts.map +0 -1
- package/lib/bridge/buildTransaction.d.ts.map +0 -1
- package/lib/bridge/buildTransaction.js.map +0 -1
- package/lib/bridge/createTransaction.d.ts.map +0 -1
- package/lib/bridge/createTransaction.js.map +0 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
- package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
- package/lib-es/api/graphql/queries.d.ts.map +0 -1
- package/lib-es/api/graphql/queries.js.map +0 -1
- package/lib-es/api/graphql/types.d.ts.map +0 -1
- package/lib-es/bridge/buildTransaction.d.ts.map +0 -1
- package/lib-es/bridge/buildTransaction.js.map +0 -1
- package/lib-es/bridge/createTransaction.d.ts.map +0 -1
- package/lib-es/bridge/createTransaction.js.map +0 -1
- /package/lib/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
- /package/lib/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
- /package/lib/{bridge → logic}/createTransaction.d.ts +0 -0
- /package/lib/{api → network}/graphql/queries.d.ts +0 -0
- /package/lib/{api → network}/graphql/queries.js +0 -0
- /package/lib/{api → network}/graphql/types.d.ts +0 -0
- /package/lib/{api → network}/graphql/types.js +0 -0
- /package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
- /package/lib-es/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
- /package/lib-es/{bridge → logic}/createTransaction.d.ts +0 -0
- /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
- /package/lib-es/{api → network}/graphql/queries.js +0 -0
- /package/lib-es/{api → network}/graphql/types.d.ts +0 -0
- /package/lib-es/{api → network}/graphql/types.js +0 -0
- /package/src/{api → network}/graphql/queries.ts +0 -0
- /package/src/{api → network}/graphql/types.ts +0 -0
package/src/api/index.ts
CHANGED
|
@@ -1,252 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
GetAccountTransactionsDataQuery,
|
|
31
|
-
GetAccountTransactionsDataGtQueryVariables,
|
|
32
|
-
} from "./graphql/types";
|
|
33
|
-
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
34
|
-
|
|
35
|
-
const getApiEndpoint = (currencyId: string) =>
|
|
36
|
-
isTestnet(currencyId) ? getEnv("APTOS_TESTNET_API_ENDPOINT") : getEnv("APTOS_API_ENDPOINT");
|
|
37
|
-
const getIndexerEndpoint = (currencyId: string) =>
|
|
38
|
-
isTestnet(currencyId)
|
|
39
|
-
? getEnv("APTOS_TESTNET_INDEXER_ENDPOINT")
|
|
40
|
-
: getEnv("APTOS_INDEXER_ENDPOINT");
|
|
41
|
-
|
|
42
|
-
export class AptosAPI {
|
|
43
|
-
private apiUrl: string;
|
|
44
|
-
private indexerUrl: string;
|
|
45
|
-
private aptosConfig: AptosConfig;
|
|
46
|
-
private aptosClient: Aptos;
|
|
47
|
-
private apolloClient: ApolloClient<object>;
|
|
48
|
-
|
|
49
|
-
constructor(currencyId: string) {
|
|
50
|
-
this.apiUrl = getApiEndpoint(currencyId);
|
|
51
|
-
this.indexerUrl = getIndexerEndpoint(currencyId);
|
|
52
|
-
this.aptosConfig = new AptosConfig({
|
|
53
|
-
fullnode: this.apiUrl,
|
|
54
|
-
indexer: this.indexerUrl,
|
|
55
|
-
});
|
|
56
|
-
this.aptosClient = new Aptos(this.aptosConfig);
|
|
57
|
-
this.apolloClient = new ApolloClient({
|
|
58
|
-
uri: this.indexerUrl,
|
|
59
|
-
cache: new InMemoryCache(),
|
|
60
|
-
headers: {
|
|
61
|
-
"x-client": "ledger-live",
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async getAccount(address: string): Promise<AccountData> {
|
|
67
|
-
return this.aptosClient.getAccountInfo({ accountAddress: address });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async getAccountInfo(address: string, startAt?: string) {
|
|
71
|
-
const [balance, transactions, blockHeight] = await Promise.all([
|
|
72
|
-
this.getCoinBalance(address, APTOS_ASSET_ID),
|
|
73
|
-
this.fetchTransactions(address, startAt),
|
|
74
|
-
this.getHeight(),
|
|
75
|
-
]);
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
balance,
|
|
79
|
-
transactions,
|
|
80
|
-
blockHeight,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async estimateGasPrice(): Promise<GasEstimation> {
|
|
85
|
-
return this.aptosClient.getGasPriceEstimation();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async generateTransaction(
|
|
89
|
-
address: string,
|
|
90
|
-
payload: InputEntryFunctionData,
|
|
91
|
-
options: TransactionOptions,
|
|
92
|
-
): Promise<RawTransaction> {
|
|
93
|
-
const opts: Partial<InputGenerateTransactionOptions> = {};
|
|
94
|
-
if (!isUndefined(options.maxGasAmount)) {
|
|
95
|
-
opts.maxGasAmount = Number(options.maxGasAmount);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!isUndefined(options.gasUnitPrice)) {
|
|
99
|
-
opts.gasUnitPrice = Number(options.gasUnitPrice);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const { ledger_timestamp } = await this.aptosClient.getLedgerInfo();
|
|
104
|
-
opts.expireTimestamp = Number(Math.ceil(+ledger_timestamp / 1_000_000 + 2 * 60)); // in milliseconds
|
|
105
|
-
} catch {
|
|
106
|
-
// skip
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return this.aptosClient.transaction.build
|
|
110
|
-
.simple({
|
|
111
|
-
sender: address,
|
|
112
|
-
data: payload,
|
|
113
|
-
options: opts,
|
|
114
|
-
})
|
|
115
|
-
.then(t => t.rawTransaction)
|
|
116
|
-
.catch(error => {
|
|
117
|
-
throw error;
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async simulateTransaction(
|
|
122
|
-
address: Ed25519PublicKey,
|
|
123
|
-
tx: RawTransaction,
|
|
124
|
-
options = {
|
|
125
|
-
estimateGasUnitPrice: true,
|
|
126
|
-
estimateMaxGasAmount: true,
|
|
127
|
-
estimatePrioritizedGasUnitPrice: false,
|
|
128
|
-
},
|
|
129
|
-
): Promise<UserTransactionResponse[]> {
|
|
130
|
-
return this.aptosClient.transaction.simulate.simple({
|
|
131
|
-
signerPublicKey: address,
|
|
132
|
-
transaction: { rawTransaction: tx } as SimpleTransaction,
|
|
133
|
-
options,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async broadcast(signature: string): Promise<string> {
|
|
138
|
-
const txBytes = Uint8Array.from(Buffer.from(signature, "hex"));
|
|
139
|
-
const pendingTx = await post<PostRequestOptions, TransactionResponse>({
|
|
140
|
-
contentType: MimeType.BCS_SIGNED_TRANSACTION,
|
|
141
|
-
aptosConfig: this.aptosClient.config,
|
|
142
|
-
body: txBytes,
|
|
143
|
-
path: "transactions",
|
|
144
|
-
type: AptosApiType.FULLNODE,
|
|
145
|
-
originMethod: "",
|
|
146
|
-
});
|
|
147
|
-
return pendingTx.data.hash;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async getBalance(address: string, token: TokenCurrency): Promise<BigNumber> {
|
|
151
|
-
let balance = new BigNumber(0);
|
|
152
|
-
if (token.tokenType === "coin") {
|
|
153
|
-
balance = await this.getCoinBalance(address, token.contractAddress);
|
|
154
|
-
} else {
|
|
155
|
-
balance = await this.getFABalance(address, token.contractAddress);
|
|
156
|
-
}
|
|
157
|
-
return balance;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async getCoinBalance(address: string, contract_address: string): Promise<BigNumber> {
|
|
161
|
-
try {
|
|
162
|
-
const [balanceStr] = await this.aptosClient.view<[string]>({
|
|
163
|
-
payload: {
|
|
164
|
-
function: "0x1::coin::balance",
|
|
165
|
-
typeArguments: [contract_address],
|
|
166
|
-
functionArguments: [address],
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
const balance = parseInt(balanceStr, 10);
|
|
170
|
-
return new BigNumber(balance);
|
|
171
|
-
} catch (_) {
|
|
172
|
-
return new BigNumber(0);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async getFABalance(address: string, contract_address: string): Promise<BigNumber> {
|
|
177
|
-
try {
|
|
178
|
-
const [balanceStr] = await this.aptosClient.view<[string]>({
|
|
179
|
-
payload: {
|
|
180
|
-
function: "0x1::primary_fungible_store::balance",
|
|
181
|
-
typeArguments: ["0x1::object::ObjectCore"],
|
|
182
|
-
functionArguments: [address, contract_address],
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
const balance = parseInt(balanceStr, 10);
|
|
186
|
-
return new BigNumber(balance);
|
|
187
|
-
} catch (_) {
|
|
188
|
-
return new BigNumber(0);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private async fetchTransactions(address: string, gt?: string) {
|
|
193
|
-
if (!address) {
|
|
194
|
-
return [];
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
let query = GetAccountTransactionsData;
|
|
198
|
-
if (gt) {
|
|
199
|
-
query = GetAccountTransactionsDataGt;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const queryResponse = await this.apolloClient.query<
|
|
203
|
-
GetAccountTransactionsDataQuery,
|
|
204
|
-
GetAccountTransactionsDataGtQueryVariables
|
|
205
|
-
>({
|
|
206
|
-
query,
|
|
207
|
-
variables: {
|
|
208
|
-
address,
|
|
209
|
-
limit: 1000,
|
|
210
|
-
gt,
|
|
211
|
-
},
|
|
212
|
-
fetchPolicy: "network-only",
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
return Promise.all(
|
|
216
|
-
queryResponse.data.account_transactions.map(({ transaction_version }) => {
|
|
217
|
-
return this.richItemByVersion(transaction_version);
|
|
218
|
-
}),
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private async richItemByVersion(version: number): Promise<AptosTransaction | null> {
|
|
223
|
-
try {
|
|
224
|
-
const tx: TransactionResponse = await this.aptosClient.getTransactionByVersion({
|
|
225
|
-
ledgerVersion: version,
|
|
226
|
-
});
|
|
227
|
-
const block = await this.getBlock(version);
|
|
228
|
-
return {
|
|
229
|
-
...tx,
|
|
230
|
-
block,
|
|
231
|
-
} as AptosTransaction;
|
|
232
|
-
} catch (error) {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
private async getHeight(): Promise<number> {
|
|
238
|
-
const { data } = await network<Block>({
|
|
239
|
-
method: "GET",
|
|
240
|
-
url: this.apiUrl,
|
|
241
|
-
});
|
|
242
|
-
return parseInt(data.block_height);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
private async getBlock(version: number) {
|
|
246
|
-
const block = await this.aptosClient.getBlockByVersion({ ledgerVersion: version });
|
|
247
|
-
return {
|
|
248
|
-
height: parseInt(block.block_height),
|
|
249
|
-
hash: block.block_hash,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
1
|
+
import type { Api } from "@ledgerhq/coin-framework/api/index";
|
|
2
|
+
import type { AptosConfig as AptosConfigApi } from "../config";
|
|
3
|
+
import type { Balance, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
4
|
+
import coinConfig from "../config";
|
|
5
|
+
import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
|
|
6
|
+
import { AptosAPI } from "../network";
|
|
7
|
+
import { combine } from "../logic/combine";
|
|
8
|
+
import { craftTransaction } from "../logic/craftTransaction";
|
|
9
|
+
import { getBalance } from "../logic/getBalance";
|
|
10
|
+
|
|
11
|
+
export function createApi(
|
|
12
|
+
config: AptosConfigApi,
|
|
13
|
+
): Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> {
|
|
14
|
+
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
15
|
+
|
|
16
|
+
const client = new AptosAPI(config.aptosSettings);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
broadcast: (tx: string) => client.broadcast(tx),
|
|
20
|
+
combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
|
|
21
|
+
craftTransaction: (transactionIntent, _customFees): Promise<string> =>
|
|
22
|
+
craftTransaction(client, transactionIntent),
|
|
23
|
+
estimateFees: (transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>) =>
|
|
24
|
+
client.estimateFees(transactionIntent),
|
|
25
|
+
getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalance(client, address),
|
|
26
|
+
lastBlock: () => client.getLastBlock(),
|
|
27
|
+
listOperations: (address: string, pagination: Pagination) =>
|
|
28
|
+
client.listOperations(address, pagination),
|
|
29
|
+
};
|
|
252
30
|
}
|
package/src/bridge/broadcast.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
|
|
2
2
|
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
3
|
-
import { AptosAPI } from "../
|
|
3
|
+
import { AptosAPI } from "../network";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
signedOperation,
|
|
7
|
-
account,
|
|
8
|
-
}: {
|
|
5
|
+
type broadcastFunc = {
|
|
9
6
|
signedOperation: SignedOperation;
|
|
10
7
|
account: Account;
|
|
11
|
-
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const broadcast = async ({ signedOperation, account }: broadcastFunc): Promise<Operation> => {
|
|
12
11
|
const { signature, operation } = signedOperation;
|
|
13
|
-
const
|
|
12
|
+
const client = new AptosAPI(account.currency.id);
|
|
13
|
+
const hash = await client.broadcast(signature);
|
|
14
14
|
return patchOperationWithHash(operation, hash);
|
|
15
15
|
};
|
|
16
16
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
3
|
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
-
import { AptosAPI } from "../
|
|
4
|
+
import { AptosAPI } from "../network";
|
|
5
5
|
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
6
|
-
import {
|
|
6
|
+
import { getMaxSendBalance } from "./logic";
|
|
7
7
|
import type { Transaction } from "../types";
|
|
8
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
8
9
|
|
|
9
10
|
const estimateMaxSpendable = async ({
|
|
10
11
|
account,
|
|
@@ -3,10 +3,11 @@ import { log } from "@ledgerhq/logs";
|
|
|
3
3
|
import type { Account } from "@ledgerhq/types-live";
|
|
4
4
|
import BigNumber from "bignumber.js";
|
|
5
5
|
import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
|
|
6
|
-
import { AptosAPI } from "../
|
|
7
|
-
import
|
|
8
|
-
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL
|
|
6
|
+
import { AptosAPI } from "../network";
|
|
7
|
+
import { getTokenAccount } from "./logic";
|
|
8
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "../constants";
|
|
9
9
|
import type { Transaction, TransactionErrors } from "../types";
|
|
10
|
+
import buildTransaction from "../logic/buildTransaction";
|
|
10
11
|
|
|
11
12
|
type IGetEstimatedGasReturnType = {
|
|
12
13
|
fees: BigNumber;
|
package/src/bridge/index.ts
CHANGED
|
@@ -6,17 +6,17 @@ import {
|
|
|
6
6
|
updateTransaction,
|
|
7
7
|
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
8
8
|
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
9
|
-
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
9
|
+
import type { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
10
10
|
import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
11
11
|
import resolver from "../signer";
|
|
12
12
|
import type { Transaction, TransactionStatus, AptosSigner } from "../types";
|
|
13
13
|
import getTransactionStatus from "./getTransactionStatus";
|
|
14
14
|
import estimateMaxSpendable from "./estimateMaxSpendable";
|
|
15
15
|
import prepareTransaction from "./prepareTransaction";
|
|
16
|
-
import createTransaction from "./createTransaction";
|
|
17
16
|
import { getAccountShape } from "./synchronisation";
|
|
18
17
|
import buildSignOperation from "./signOperation";
|
|
19
18
|
import broadcast from "./broadcast";
|
|
19
|
+
import createTransaction from "../logic/createTransaction";
|
|
20
20
|
|
|
21
21
|
function buildCurrencyBridge(signerContext: SignerContext<AptosSigner>): CurrencyBridge {
|
|
22
22
|
const getAddress = resolver(signerContext);
|
package/src/bridge/logic.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EntryFunctionPayloadResponse,
|
|
3
|
-
Event,
|
|
4
|
-
InputEntryFunctionData,
|
|
5
|
-
MoveResource,
|
|
6
|
-
WriteSetChange,
|
|
7
|
-
WriteSetChangeWriteResource,
|
|
8
|
-
} from "@aptos-labs/ts-sdk";
|
|
9
|
-
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
1
|
+
import { EntryFunctionPayloadResponse } from "@aptos-labs/ts-sdk";
|
|
10
2
|
import type { Account, Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
|
|
11
3
|
import {
|
|
12
4
|
decodeTokenAccountId,
|
|
@@ -16,35 +8,14 @@ import {
|
|
|
16
8
|
} from "@ledgerhq/coin-framework/account/index";
|
|
17
9
|
import BigNumber from "bignumber.js";
|
|
18
10
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
APTOS_FUNGIBLE_STORE,
|
|
22
|
-
BATCH_TRANSFER_TYPES,
|
|
23
|
-
DELEGATION_POOL_TYPES,
|
|
24
|
-
DIRECTION,
|
|
25
|
-
COIN_TRANSFER_TYPES,
|
|
26
|
-
FA_TRANSFER_TYPES,
|
|
27
|
-
APTOS_OBJECT_CORE,
|
|
28
|
-
} from "../constants";
|
|
29
|
-
import type {
|
|
30
|
-
AptosFungibleoObjectCoreResourceData,
|
|
31
|
-
AptosFungibleStoreResourceData,
|
|
32
|
-
AptosMoveResource,
|
|
33
|
-
AptosTransaction,
|
|
34
|
-
Transaction,
|
|
35
|
-
TransactionOptions,
|
|
36
|
-
} from "../types";
|
|
11
|
+
import { APTOS_ASSET_ID, DIRECTION } from "../constants";
|
|
12
|
+
import type { AptosTransaction, Transaction } from "../types";
|
|
37
13
|
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const CLEAN_HEX_REGEXP = /^0x0*|^0+/;
|
|
44
|
-
|
|
45
|
-
export function isTestnet(currencyId: string): boolean {
|
|
46
|
-
return getCryptoCurrencyById(currencyId).isTestnetFor ? true : false;
|
|
47
|
-
}
|
|
14
|
+
import { convertFunctionPayloadResponseToInputEntryFunctionData } from "../logic/transactionsToOperations";
|
|
15
|
+
import { compareAddress, getCoinAndAmounts } from "../logic/getCoinAndAmounts";
|
|
16
|
+
import { calculateAmount } from "../logic/calculateAmount";
|
|
17
|
+
import { processRecipients } from "../logic/processRecipients";
|
|
18
|
+
import { getFunctionAddress } from "../logic/getFunctionAddress";
|
|
48
19
|
|
|
49
20
|
export const getMaxSendBalance = (
|
|
50
21
|
gas: BigNumber,
|
|
@@ -64,23 +35,6 @@ export const getMaxSendBalance = (
|
|
|
64
35
|
: new BigNumber(0);
|
|
65
36
|
};
|
|
66
37
|
|
|
67
|
-
export function normalizeTransactionOptions(options: TransactionOptions): TransactionOptions {
|
|
68
|
-
// FIXME: this is wrong. TransactionOptions is
|
|
69
|
-
// {
|
|
70
|
-
// maxGasAmount: string;
|
|
71
|
-
// gasUnitPrice: string;
|
|
72
|
-
// sequenceNumber?: string;
|
|
73
|
-
// expirationTimestampSecs?: string;
|
|
74
|
-
// }
|
|
75
|
-
// meaning we can't return undefined in check method.
|
|
76
|
-
// This method is useless, not deleting as it breaks code and this iteration is coin modularisation.
|
|
77
|
-
const check = (v: any) => ((v ?? "").toString().trim() ? v : undefined);
|
|
78
|
-
return {
|
|
79
|
-
maxGasAmount: check(options.maxGasAmount),
|
|
80
|
-
gasUnitPrice: check(options.gasUnitPrice),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
38
|
export const getBlankOperation = (
|
|
85
39
|
tx: AptosTransaction,
|
|
86
40
|
id: string,
|
|
@@ -101,14 +55,6 @@ export const getBlankOperation = (
|
|
|
101
55
|
hasFailed: false,
|
|
102
56
|
});
|
|
103
57
|
|
|
104
|
-
const convertFunctionPayloadResponseToInputEntryFunctionData = (
|
|
105
|
-
payload: EntryFunctionPayloadResponse,
|
|
106
|
-
): InputEntryFunctionData => ({
|
|
107
|
-
function: payload.function,
|
|
108
|
-
typeArguments: payload.type_arguments,
|
|
109
|
-
functionArguments: payload.arguments,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
58
|
export const txsToOps = (
|
|
113
59
|
info: { address: string },
|
|
114
60
|
id: string,
|
|
@@ -173,227 +119,6 @@ export const txsToOps = (
|
|
|
173
119
|
return [ops, opsTokens];
|
|
174
120
|
};
|
|
175
121
|
|
|
176
|
-
export function compareAddress(addressA: string, addressB: string) {
|
|
177
|
-
return (
|
|
178
|
-
addressA.replace(CLEAN_HEX_REGEXP, "").toLowerCase() ===
|
|
179
|
-
addressB.replace(CLEAN_HEX_REGEXP, "").toLowerCase()
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function getFunctionAddress(payload: InputEntryFunctionData): string | undefined {
|
|
184
|
-
if (payload.function) {
|
|
185
|
-
const parts = payload.function.split("::");
|
|
186
|
-
return parts.length === 3 && parts[0].length ? parts[0] : undefined;
|
|
187
|
-
}
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export function processRecipients(
|
|
192
|
-
payload: InputEntryFunctionData,
|
|
193
|
-
address: string,
|
|
194
|
-
op: Operation,
|
|
195
|
-
function_address: string,
|
|
196
|
-
): void {
|
|
197
|
-
// get recipients buy 3 groups
|
|
198
|
-
if (
|
|
199
|
-
(COIN_TRANSFER_TYPES.includes(payload.function) ||
|
|
200
|
-
DELEGATION_POOL_TYPES.includes(payload.function)) &&
|
|
201
|
-
payload.functionArguments &&
|
|
202
|
-
payload.functionArguments.length > 0 &&
|
|
203
|
-
typeof payload.functionArguments[0] === "string"
|
|
204
|
-
) {
|
|
205
|
-
// 1. Transfer like functions (includes some delegation pool functions)
|
|
206
|
-
op.recipients.push(payload.functionArguments[0].toString());
|
|
207
|
-
} else if (
|
|
208
|
-
FA_TRANSFER_TYPES.includes(payload.function) &&
|
|
209
|
-
payload.functionArguments &&
|
|
210
|
-
payload.functionArguments.length > 1 &&
|
|
211
|
-
typeof payload.functionArguments[0] === "object" &&
|
|
212
|
-
typeof payload.functionArguments[1] === "string"
|
|
213
|
-
) {
|
|
214
|
-
// 1. Transfer like functions (includes some delegation pool functions)
|
|
215
|
-
op.recipients.push(payload.functionArguments[1].toString());
|
|
216
|
-
} else if (
|
|
217
|
-
BATCH_TRANSFER_TYPES.includes(payload.function) &&
|
|
218
|
-
payload.functionArguments &&
|
|
219
|
-
payload.functionArguments.length > 0 &&
|
|
220
|
-
Array.isArray(payload.functionArguments[0])
|
|
221
|
-
) {
|
|
222
|
-
// 2. Batch function, to validate we are in the recipients list
|
|
223
|
-
if (!compareAddress(op.senders[0], address)) {
|
|
224
|
-
for (const recipient of payload.functionArguments[0]) {
|
|
225
|
-
if (recipient && compareAddress(recipient.toString(), address)) {
|
|
226
|
-
op.recipients.push(recipient.toString());
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
} else {
|
|
231
|
-
// 3. other smart contracts, in this case smart contract will be treated as a recipient
|
|
232
|
-
op.recipients.push(function_address);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export function getEventCoinAddress(
|
|
237
|
-
change: WriteSetChangeWriteResource,
|
|
238
|
-
event: Event,
|
|
239
|
-
event_name: string,
|
|
240
|
-
): string | null {
|
|
241
|
-
const change_data = change.data;
|
|
242
|
-
|
|
243
|
-
const mr = change_data as MoveResource<AptosMoveResource>; // -> this is data that we want to parse
|
|
244
|
-
|
|
245
|
-
if (!(event_name in mr.data)) {
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const change_event_data = mr.data[event_name];
|
|
250
|
-
if (
|
|
251
|
-
change_event_data.guid.id.addr !== event.guid.account_address ||
|
|
252
|
-
change_event_data.guid.id.creation_num !== event.guid.creation_number
|
|
253
|
-
) {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const address = extractAddress(mr.type);
|
|
258
|
-
|
|
259
|
-
return address;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export function getEventFAAddress(
|
|
263
|
-
change: WriteSetChangeWriteResource,
|
|
264
|
-
event: Event,
|
|
265
|
-
_event_name: string,
|
|
266
|
-
): string | null {
|
|
267
|
-
const change_data = change.data;
|
|
268
|
-
|
|
269
|
-
if (change_data.type !== APTOS_FUNGIBLE_STORE) {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const mr = change_data as MoveResource<AptosFungibleStoreResourceData>;
|
|
274
|
-
|
|
275
|
-
if (change.address !== event.data.store) {
|
|
276
|
-
return null;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return mr.data.metadata.inner;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export function getResourceAddress(
|
|
283
|
-
tx: AptosTransaction,
|
|
284
|
-
event: Event,
|
|
285
|
-
event_name: string,
|
|
286
|
-
getAddressProcessor: (
|
|
287
|
-
change: WriteSetChangeWriteResource,
|
|
288
|
-
event: Event,
|
|
289
|
-
event_name: string,
|
|
290
|
-
) => string | null,
|
|
291
|
-
): string | null {
|
|
292
|
-
for (const change of tx.changes) {
|
|
293
|
-
if (isWriteSetChangeWriteResource(change)) {
|
|
294
|
-
const address = getAddressProcessor(change, event, event_name);
|
|
295
|
-
if (address !== null) {
|
|
296
|
-
return address;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return null;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function isWriteSetChangeWriteResource(
|
|
304
|
-
change: WriteSetChange,
|
|
305
|
-
): change is WriteSetChangeWriteResource {
|
|
306
|
-
return (change as WriteSetChangeWriteResource).data !== undefined;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export function checkFAOwner(tx: AptosTransaction, event: Event, user_address: string): boolean {
|
|
310
|
-
for (const change of tx.changes) {
|
|
311
|
-
if (isWriteSetChangeWriteResource(change)) {
|
|
312
|
-
const storeData = change.data as MoveResource<AptosFungibleoObjectCoreResourceData>;
|
|
313
|
-
if (
|
|
314
|
-
change.address == event.data.store &&
|
|
315
|
-
storeData.type == APTOS_OBJECT_CORE &&
|
|
316
|
-
storeData.data.owner == user_address
|
|
317
|
-
) {
|
|
318
|
-
return true;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export function getCoinAndAmounts(
|
|
326
|
-
tx: AptosTransaction,
|
|
327
|
-
address: string,
|
|
328
|
-
): { coin_id: string | null; amount_in: BigNumber; amount_out: BigNumber } {
|
|
329
|
-
let coin_id: string | null = null;
|
|
330
|
-
let amount_in = BigNumber(0);
|
|
331
|
-
let amount_out = BigNumber(0);
|
|
332
|
-
|
|
333
|
-
// collect all events related to the address and calculate the overall amounts
|
|
334
|
-
tx.events.forEach(event => {
|
|
335
|
-
switch (event.type) {
|
|
336
|
-
case "0x1::coin::WithdrawEvent":
|
|
337
|
-
if (compareAddress(event.guid.account_address, address)) {
|
|
338
|
-
coin_id = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
|
|
339
|
-
amount_out = amount_out.plus(event.data.amount);
|
|
340
|
-
}
|
|
341
|
-
break;
|
|
342
|
-
case "0x1::coin::DepositEvent":
|
|
343
|
-
if (compareAddress(event.guid.account_address, address)) {
|
|
344
|
-
coin_id = getResourceAddress(tx, event, "deposit_events", getEventCoinAddress);
|
|
345
|
-
amount_in = amount_in.plus(event.data.amount);
|
|
346
|
-
}
|
|
347
|
-
break;
|
|
348
|
-
case "0x1::fungible_asset::Withdraw":
|
|
349
|
-
if (checkFAOwner(tx, event, address)) {
|
|
350
|
-
coin_id = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
|
|
351
|
-
amount_out = amount_out.plus(event.data.amount);
|
|
352
|
-
}
|
|
353
|
-
break;
|
|
354
|
-
case "0x1::fungible_asset::Deposit":
|
|
355
|
-
if (checkFAOwner(tx, event, address)) {
|
|
356
|
-
coin_id = getResourceAddress(tx, event, "deposit_events", getEventFAAddress);
|
|
357
|
-
amount_in = amount_in.plus(event.data.amount);
|
|
358
|
-
}
|
|
359
|
-
break;
|
|
360
|
-
case "0x1::transaction_fee::FeeStatement":
|
|
361
|
-
if (tx.sender === address) {
|
|
362
|
-
if (coin_id === null) coin_id = APTOS_ASSET_ID;
|
|
363
|
-
if (coin_id === APTOS_ASSET_ID) {
|
|
364
|
-
const fees = BigNumber(tx.gas_unit_price).times(BigNumber(tx.gas_used));
|
|
365
|
-
amount_out = amount_out.plus(fees);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
return { coin_id, amount_in, amount_out }; // TODO: manage situation when there are several coinID from the events parsing
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export function calculateAmount(
|
|
375
|
-
sender: string,
|
|
376
|
-
address: string,
|
|
377
|
-
amount_in: BigNumber,
|
|
378
|
-
amount_out: BigNumber,
|
|
379
|
-
): BigNumber {
|
|
380
|
-
const is_sender: boolean = compareAddress(sender, address);
|
|
381
|
-
// LL negates the amount for SEND transactions
|
|
382
|
-
// to show positive amount on the send transaction (ex: in "cancel" tx, when amount will be returned to our account)
|
|
383
|
-
// we need to make it negative
|
|
384
|
-
return is_sender ? amount_out.minus(amount_in) : amount_in.minus(amount_out);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Extracts the address from a string like "0x1::coin::CoinStore<address::module::type>"
|
|
389
|
-
* @param {string} str - The input string containing the address.
|
|
390
|
-
* @returns {string | null} - The extracted address or null if not found.
|
|
391
|
-
*/
|
|
392
|
-
function extractAddress(str: string): string | null {
|
|
393
|
-
const match = str.match(/<([^<>]+)>{1}$/);
|
|
394
|
-
return match ? match[1] : null;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
122
|
export function getTokenAccount(
|
|
398
123
|
account: Account,
|
|
399
124
|
transaction: Transaction,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Account } from "@ledgerhq/types-live";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import { AptosAPI } from "../network";
|
|
4
5
|
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
5
6
|
import type { Transaction } from "../types";
|
|
6
|
-
import {
|
|
7
|
+
import { getMaxSendBalance } from "./logic";
|
|
8
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
7
9
|
|
|
8
10
|
const prepareTransaction = async (
|
|
9
11
|
account: Account,
|