@ledgerhq/coin-aptos 1.9.6 → 1.10.0-nightly.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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +18 -6
- package/CHANGELOG.md +24 -0
- 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 -404
- 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 +115 -14
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getTransactionStatus.test.js +175 -37
- package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib/__tests__/bridge/logic.test.js +702 -478
- 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 +137 -14
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +1215 -68
- 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__/logic/buildTransaction.test.js +112 -0
- 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 -30
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +19 -170
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/bridge.fixture.d.ts +2 -0
- package/lib/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib/bridge/bridge.fixture.js +85 -13
- package/lib/bridge/bridge.fixture.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 +6 -5
- 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 +20 -14
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +28 -14
- package/lib/bridge/getTransactionStatus.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 +5 -19
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +50 -147
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +5 -4
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +21 -7
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts +15 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +129 -6
- 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 +10 -2
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +13 -2
- 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/logic/buildTransaction.js +45 -0
- 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/{api → network}/graphql/queries.js +6 -6
- package/lib/network/graphql/queries.js.map +1 -0
- package/lib/{api → network}/graphql/types.d.ts +9 -9
- 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/test/bot-specs.d.ts.map +1 -1
- package/lib/test/bot-specs.js +40 -1
- package/lib/test/bot-specs.js.map +1 -1
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +44 -62
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/speculos-deviceActions.d.ts +1 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib/test/speculos-deviceActions.js +37 -5
- package/lib/test/speculos-deviceActions.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 +22 -7
- 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 -408
- 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 +112 -11
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js +177 -39
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib-es/__tests__/bridge/logic.test.js +702 -478
- 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 +137 -14
- package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib-es/__tests__/bridge/synchronisation.test.js +1213 -69
- 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__/logic/buildTransaction.test.js +107 -0
- 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 -30
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +17 -168
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/bridge.fixture.d.ts +2 -0
- package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib-es/bridge/bridge.fixture.js +82 -12
- package/lib-es/bridge/bridge.fixture.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 +4 -3
- 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 +15 -9
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +28 -14
- package/lib-es/bridge/getTransactionStatus.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 +5 -19
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +44 -134
- 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 +5 -4
- 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 +19 -5
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts +15 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +124 -4
- 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 +10 -2
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +9 -1
- 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/logic/buildTransaction.js +43 -0
- 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/{api → network}/graphql/queries.js +6 -6
- package/lib-es/network/graphql/queries.js.map +1 -0
- package/lib-es/{api → network}/graphql/types.d.ts +9 -9
- 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/test/bot-specs.d.ts.map +1 -1
- package/lib-es/test/bot-specs.js +41 -2
- package/lib-es/test/bot-specs.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +44 -59
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/speculos-deviceActions.d.ts +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib-es/test/speculos-deviceActions.js +36 -4
- package/lib-es/test/speculos-deviceActions.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 +22 -7
- package/lib-es/types/index.d.ts.map +1 -1
- package/package.json +9 -7
- 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 -477
- package/src/__tests__/bridge/broadcast.test.ts +2 -2
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +146 -11
- package/src/__tests__/bridge/getTransactionStatus.test.ts +217 -38
- package/src/__tests__/bridge/logic.test.ts +727 -568
- package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
- package/src/__tests__/bridge/signOperation.test.ts +153 -15
- package/src/__tests__/bridge/synchronisation.test.ts +1265 -71
- package/src/__tests__/index.test.ts +1 -1
- package/src/__tests__/logic/buildTransaction.test.ts +148 -0
- 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 -224
- package/src/bridge/bridge.fixture.ts +91 -12
- package/src/bridge/broadcast.ts +7 -7
- package/src/bridge/estimateMaxSpendable.ts +4 -3
- package/src/bridge/getFeesForTransaction.ts +17 -11
- package/src/bridge/getTransactionStatus.ts +35 -13
- package/src/bridge/index.ts +2 -2
- package/src/bridge/logic.ts +58 -194
- package/src/bridge/prepareTransaction.ts +7 -4
- package/src/bridge/signOperation.ts +21 -5
- package/src/bridge/synchronisation.ts +171 -4
- package/src/config.ts +19 -0
- package/src/constants.ts +18 -2
- package/src/logic/buildTransaction.ts +62 -0
- 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/{api → network}/graphql/queries.ts +6 -6
- package/src/{api → network}/graphql/types.ts +9 -9
- package/src/network/index.ts +6 -14
- package/src/test/bot-specs.ts +63 -3
- package/src/test/bridgeDatasetTest.ts +46 -59
- package/src/test/speculos-deviceActions.ts +40 -4
- package/src/types/assets.ts +15 -0
- package/src/types/index.ts +20 -1
- package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/buildTransaction.test.js +0 -53
- 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 +0 -19
- 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 +0 -48
- 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 +0 -17
- 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/src/__tests__/bridge/buildTransaction.test.ts +0 -61
- package/src/bridge/buildTransaction.ts +0 -29
- /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/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/types.js +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { InputEntryFunctionData, RawTransaction } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import type { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
3
|
+
import { findSubAccountById, isTokenAccount } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
+
import { APTOS_ASSET_ID, SUPPORTED_TOKEN_TYPES } from "../constants";
|
|
5
|
+
import type { AptosAPI } from "../network";
|
|
6
|
+
import { normalizeTransactionOptions } from "./normalizeTransactionOptions";
|
|
7
|
+
import type { Transaction } from "../types";
|
|
8
|
+
|
|
9
|
+
const buildTransaction = async (
|
|
10
|
+
account: Account,
|
|
11
|
+
transaction: Transaction,
|
|
12
|
+
aptosClient: AptosAPI,
|
|
13
|
+
): Promise<RawTransaction> => {
|
|
14
|
+
const subAccount = findSubAccountById(account, transaction.subAccountId ?? "");
|
|
15
|
+
|
|
16
|
+
const txPayload = getPayload(subAccount, transaction);
|
|
17
|
+
const txOptions = normalizeTransactionOptions(transaction.options);
|
|
18
|
+
const tx = await aptosClient.generateTransaction(account.freshAddress, txPayload, txOptions);
|
|
19
|
+
|
|
20
|
+
return tx;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const getPayload = (
|
|
24
|
+
tokenAccount: TokenAccount | undefined,
|
|
25
|
+
transaction: Transaction,
|
|
26
|
+
): InputEntryFunctionData => {
|
|
27
|
+
if (tokenAccount && isTokenAccount(tokenAccount)) {
|
|
28
|
+
const { tokenType } = tokenAccount.token;
|
|
29
|
+
|
|
30
|
+
if (!SUPPORTED_TOKEN_TYPES.includes(tokenType)) {
|
|
31
|
+
throw new Error(`Token type ${tokenType} not supported`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (tokenType === "fungible_asset") {
|
|
35
|
+
return {
|
|
36
|
+
function: `0x1::primary_fungible_store::transfer`,
|
|
37
|
+
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
38
|
+
functionArguments: [
|
|
39
|
+
tokenAccount.token.contractAddress,
|
|
40
|
+
transaction.recipient,
|
|
41
|
+
transaction.amount.toString(),
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (tokenType === "coin") {
|
|
47
|
+
return {
|
|
48
|
+
function: `0x1::aptos_account::transfer_coins`,
|
|
49
|
+
typeArguments: [tokenAccount.token.contractAddress],
|
|
50
|
+
functionArguments: [transaction.recipient, transaction.amount.toString()],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
function: "0x1::aptos_account::transfer_coins",
|
|
57
|
+
typeArguments: [APTOS_ASSET_ID],
|
|
58
|
+
functionArguments: [transaction.recipient, transaction.amount.toString()],
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default buildTransaction;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { compareAddress } from "./getCoinAndAmounts";
|
|
3
|
+
|
|
4
|
+
export function calculateAmount(
|
|
5
|
+
sender: string,
|
|
6
|
+
address: string,
|
|
7
|
+
amount_in: BigNumber,
|
|
8
|
+
amount_out: BigNumber,
|
|
9
|
+
): BigNumber {
|
|
10
|
+
const is_sender: boolean = compareAddress(sender, address);
|
|
11
|
+
// LL negates the amount for SEND transactions
|
|
12
|
+
// to show positive amount on the send transaction (ex: in "cancel" tx, when amount will be returned to our account)
|
|
13
|
+
// we need to make it negative
|
|
14
|
+
return is_sender ? amount_out.minus(amount_in) : amount_in.minus(amount_out);
|
|
15
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccountAuthenticatorEd25519,
|
|
3
|
+
Deserializer,
|
|
4
|
+
Ed25519PublicKey,
|
|
5
|
+
Ed25519Signature,
|
|
6
|
+
Hex,
|
|
7
|
+
RawTransaction,
|
|
8
|
+
type SimpleTransaction,
|
|
9
|
+
generateSignedTransaction,
|
|
10
|
+
} from "@aptos-labs/ts-sdk";
|
|
11
|
+
|
|
12
|
+
export function combineSignedTransaction(
|
|
13
|
+
txRaw: RawTransaction,
|
|
14
|
+
signature: Ed25519Signature,
|
|
15
|
+
pubkey: Ed25519PublicKey,
|
|
16
|
+
): Uint8Array {
|
|
17
|
+
const authenticator = new AccountAuthenticatorEd25519(pubkey, signature);
|
|
18
|
+
|
|
19
|
+
return generateSignedTransaction({
|
|
20
|
+
transaction: { rawTransaction: txRaw } as SimpleTransaction,
|
|
21
|
+
senderAuthenticator: authenticator,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function combine(tx: string, signature: string, pubkey?: string) {
|
|
26
|
+
if (!Hex.isValid(tx).valid) {
|
|
27
|
+
throw new Error("tx must be a valid hex value");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!Hex.isValid(signature).valid) {
|
|
31
|
+
throw new Error("signature must be a valid hex value");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (pubkey === undefined) {
|
|
35
|
+
throw new Error("account must have a public key");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!Hex.isValid(pubkey).valid) {
|
|
39
|
+
throw new Error("pubkey must be a valid hex value");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ed25519Signature = new Ed25519Signature(signature);
|
|
43
|
+
const ed25519PubKey = new Ed25519PublicKey(pubkey);
|
|
44
|
+
|
|
45
|
+
const txBytes = Hex.fromHexString(tx).toUint8Array();
|
|
46
|
+
const txRaw = RawTransaction.deserialize(new Deserializer(txBytes));
|
|
47
|
+
|
|
48
|
+
const signedTxBytes = combineSignedTransaction(txRaw, ed25519Signature, ed25519PubKey);
|
|
49
|
+
|
|
50
|
+
return Hex.fromHexInput(signedTxBytes).toString();
|
|
51
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
+
import type { AptosAsset, AptosExtra, AptosSender } from "../types/assets";
|
|
3
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
4
|
+
import type { AptosAPI } from "../network";
|
|
5
|
+
import buildTransaction from "./buildTransaction";
|
|
6
|
+
import createTransaction from "./createTransaction";
|
|
7
|
+
import BigNumber from "bignumber.js";
|
|
8
|
+
|
|
9
|
+
export async function craftTransaction(
|
|
10
|
+
aptosClient: AptosAPI,
|
|
11
|
+
transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
12
|
+
): Promise<string> {
|
|
13
|
+
const account = {
|
|
14
|
+
freshAddress: transactionIntent.sender.freshAddress,
|
|
15
|
+
xpub: transactionIntent.sender.xpub,
|
|
16
|
+
} as Account;
|
|
17
|
+
|
|
18
|
+
const newTx = createTransaction();
|
|
19
|
+
newTx.amount = BigNumber(transactionIntent.amount.toString());
|
|
20
|
+
newTx.recipient = transactionIntent.recipient;
|
|
21
|
+
newTx.mode = transactionIntent.type;
|
|
22
|
+
|
|
23
|
+
const aptosTx = await buildTransaction(account, newTx, aptosClient);
|
|
24
|
+
|
|
25
|
+
return aptosTx.bcsToHex().toString();
|
|
26
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import type { Transaction } from "../types";
|
|
3
|
-
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "
|
|
3
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
4
4
|
|
|
5
5
|
const createTransaction = (): Transaction => ({
|
|
6
6
|
family: "aptos",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
+
import type { AptosAsset } from "../types/assets";
|
|
3
|
+
import type { AptosAPI } from "../network";
|
|
4
|
+
|
|
5
|
+
export async function getBalance(
|
|
6
|
+
aptosClient: AptosAPI,
|
|
7
|
+
address: string,
|
|
8
|
+
): Promise<Balance<AptosAsset>[]> {
|
|
9
|
+
const balance = await aptosClient.getBalances(address);
|
|
10
|
+
|
|
11
|
+
return balance.map(x => ({
|
|
12
|
+
value: BigInt(x.amount.toString()),
|
|
13
|
+
asset: { type: "native" },
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { APTOS_ASSET_ID, APTOS_FUNGIBLE_STORE, APTOS_OBJECT_CORE } from "../constants";
|
|
3
|
+
import {
|
|
4
|
+
AptosFungibleoObjectCoreResourceData,
|
|
5
|
+
AptosFungibleStoreResourceData,
|
|
6
|
+
AptosMoveResource,
|
|
7
|
+
AptosTransaction,
|
|
8
|
+
} from "../types";
|
|
9
|
+
import { MoveResource, WriteSetChangeWriteResource, Event } from "@aptos-labs/ts-sdk";
|
|
10
|
+
import { getResourceAddress } from "./getResourceAddress";
|
|
11
|
+
import { isWriteSetChangeWriteResource } from "./isWriteSetChangeWriteResource";
|
|
12
|
+
|
|
13
|
+
const CLEAN_HEX_REGEXP = /^0x0*|^0+/;
|
|
14
|
+
|
|
15
|
+
export function compareAddress(addressA: string, addressB: string) {
|
|
16
|
+
return (
|
|
17
|
+
addressA.replace(CLEAN_HEX_REGEXP, "").toLowerCase() ===
|
|
18
|
+
addressB.replace(CLEAN_HEX_REGEXP, "").toLowerCase()
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function checkFAOwner(tx: AptosTransaction, event: Event, user_address: string): boolean {
|
|
23
|
+
for (const change of tx.changes) {
|
|
24
|
+
if (isWriteSetChangeWriteResource(change)) {
|
|
25
|
+
const storeData = change.data as MoveResource<AptosFungibleoObjectCoreResourceData>;
|
|
26
|
+
if (
|
|
27
|
+
change.address == event.data.store &&
|
|
28
|
+
storeData.type == APTOS_OBJECT_CORE &&
|
|
29
|
+
storeData.data.owner == user_address
|
|
30
|
+
) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Extracts the address from a string like "0x1::coin::CoinStore<address::module::type>"
|
|
40
|
+
* @param {string} str - The input string containing the address.
|
|
41
|
+
* @returns {string | null} - The extracted address or null if not found.
|
|
42
|
+
*/
|
|
43
|
+
function extractAddress(str: string): string | null {
|
|
44
|
+
const match = /<([^<>]+)>$/.exec(str);
|
|
45
|
+
return match ? match[1] : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getEventCoinAddress(
|
|
49
|
+
change: WriteSetChangeWriteResource,
|
|
50
|
+
event: Event,
|
|
51
|
+
event_name: string,
|
|
52
|
+
): string | null {
|
|
53
|
+
const change_data = change.data;
|
|
54
|
+
|
|
55
|
+
const mr = change_data as MoveResource<AptosMoveResource>; // -> this is data that we want to parse
|
|
56
|
+
|
|
57
|
+
if (!(event_name in mr.data)) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const change_event_data = mr.data[event_name];
|
|
62
|
+
if (
|
|
63
|
+
change_event_data.guid.id.addr !== event.guid.account_address ||
|
|
64
|
+
change_event_data.guid.id.creation_num !== event.guid.creation_number
|
|
65
|
+
) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const address = extractAddress(mr.type);
|
|
70
|
+
|
|
71
|
+
return address;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function getEventFAAddress(
|
|
75
|
+
change: WriteSetChangeWriteResource,
|
|
76
|
+
event: Event,
|
|
77
|
+
_event_name: string,
|
|
78
|
+
): string | null {
|
|
79
|
+
const change_data = change.data;
|
|
80
|
+
|
|
81
|
+
if (change_data.type !== APTOS_FUNGIBLE_STORE) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const mr = change_data as MoveResource<AptosFungibleStoreResourceData>;
|
|
86
|
+
|
|
87
|
+
if (change.address !== event.data.store) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return mr.data.metadata.inner;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function getCoinAndAmounts(
|
|
95
|
+
tx: AptosTransaction,
|
|
96
|
+
address: string,
|
|
97
|
+
): { coin_id: string | null; amount_in: BigNumber; amount_out: BigNumber } {
|
|
98
|
+
let coin_id: string | null = null;
|
|
99
|
+
let amount_in = BigNumber(0);
|
|
100
|
+
let amount_out = BigNumber(0);
|
|
101
|
+
|
|
102
|
+
// collect all events related to the address and calculate the overall amounts
|
|
103
|
+
tx.events.forEach(event => {
|
|
104
|
+
switch (event.type) {
|
|
105
|
+
case "0x1::coin::WithdrawEvent":
|
|
106
|
+
if (compareAddress(event.guid.account_address, address)) {
|
|
107
|
+
coin_id = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
|
|
108
|
+
amount_out = amount_out.plus(event.data.amount);
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
case "0x1::coin::DepositEvent":
|
|
112
|
+
if (compareAddress(event.guid.account_address, address)) {
|
|
113
|
+
coin_id = getResourceAddress(tx, event, "deposit_events", getEventCoinAddress);
|
|
114
|
+
amount_in = amount_in.plus(event.data.amount);
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
case "0x1::fungible_asset::Withdraw":
|
|
118
|
+
if (checkFAOwner(tx, event, address)) {
|
|
119
|
+
coin_id = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
|
|
120
|
+
amount_out = amount_out.plus(event.data.amount);
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case "0x1::fungible_asset::Deposit":
|
|
124
|
+
if (checkFAOwner(tx, event, address)) {
|
|
125
|
+
coin_id = getResourceAddress(tx, event, "deposit_events", getEventFAAddress);
|
|
126
|
+
amount_in = amount_in.plus(event.data.amount);
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
case "0x1::transaction_fee::FeeStatement":
|
|
130
|
+
if (tx.sender === address) {
|
|
131
|
+
coin_id ??= APTOS_ASSET_ID;
|
|
132
|
+
if (coin_id === APTOS_ASSET_ID) {
|
|
133
|
+
const fees = BigNumber(tx.gas_unit_price).times(BigNumber(tx.gas_used));
|
|
134
|
+
amount_out = amount_out.plus(fees);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return { coin_id, amount_in, amount_out };
|
|
141
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
|
|
2
|
+
|
|
3
|
+
export function getFunctionAddress(payload: InputEntryFunctionData): string | undefined {
|
|
4
|
+
if (payload.function) {
|
|
5
|
+
const parts = payload.function.split("::");
|
|
6
|
+
return parts.length === 3 && parts[0].length ? parts[0] : undefined;
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WriteSetChangeWriteResource, Event } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import { AptosTransaction } from "../types";
|
|
3
|
+
import { isWriteSetChangeWriteResource } from "./isWriteSetChangeWriteResource";
|
|
4
|
+
|
|
5
|
+
export function getResourceAddress(
|
|
6
|
+
tx: AptosTransaction,
|
|
7
|
+
event: Event,
|
|
8
|
+
event_name: string,
|
|
9
|
+
getAddressProcessor: (
|
|
10
|
+
change: WriteSetChangeWriteResource,
|
|
11
|
+
event: Event,
|
|
12
|
+
event_name: string,
|
|
13
|
+
) => string | null,
|
|
14
|
+
): string | null {
|
|
15
|
+
for (const change of tx.changes) {
|
|
16
|
+
if (isWriteSetChangeWriteResource(change)) {
|
|
17
|
+
const address = getAddressProcessor(change, event, event_name);
|
|
18
|
+
if (address !== null) {
|
|
19
|
+
return address;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WriteSetChange, WriteSetChangeWriteResource } from "@aptos-labs/ts-sdk";
|
|
2
|
+
|
|
3
|
+
export function isWriteSetChangeWriteResource(
|
|
4
|
+
change: WriteSetChange,
|
|
5
|
+
): change is WriteSetChangeWriteResource {
|
|
6
|
+
return (change as WriteSetChangeWriteResource).data !== undefined;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TransactionOptions } from "../types";
|
|
2
|
+
|
|
3
|
+
export function normalizeTransactionOptions(options: TransactionOptions): TransactionOptions {
|
|
4
|
+
// FIXME: this is wrong. TransactionOptions is
|
|
5
|
+
// {
|
|
6
|
+
// maxGasAmount: string;
|
|
7
|
+
// gasUnitPrice: string;
|
|
8
|
+
// sequenceNumber?: string;
|
|
9
|
+
// expirationTimestampSecs?: string;
|
|
10
|
+
// }
|
|
11
|
+
// meaning we can't return undefined in check method.
|
|
12
|
+
// This method is useless, not deleting as it breaks code and this iteration is coin modularisation.
|
|
13
|
+
const check = (v: any) => ((v ?? "").toString().trim() ? v : undefined);
|
|
14
|
+
return {
|
|
15
|
+
maxGasAmount: check(options.maxGasAmount),
|
|
16
|
+
gasUnitPrice: check(options.gasUnitPrice),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import { Operation } from "@ledgerhq/types-live";
|
|
3
|
+
import { Operation as APIOperation } from "@ledgerhq/coin-framework/api/types";
|
|
4
|
+
import { AptosAsset } from "../types/assets";
|
|
5
|
+
import {
|
|
6
|
+
BATCH_TRANSFER_TYPES,
|
|
7
|
+
COIN_TRANSFER_TYPES,
|
|
8
|
+
DELEGATION_POOL_TYPES,
|
|
9
|
+
FA_TRANSFER_TYPES,
|
|
10
|
+
} from "../constants";
|
|
11
|
+
import { compareAddress } from "./getCoinAndAmounts";
|
|
12
|
+
|
|
13
|
+
const transferLikeFunctions = (payload: InputEntryFunctionData) =>
|
|
14
|
+
COIN_TRANSFER_TYPES.includes(payload.function) ||
|
|
15
|
+
DELEGATION_POOL_TYPES.includes(payload.function);
|
|
16
|
+
|
|
17
|
+
const addLikeFunctionsToRecipients = (
|
|
18
|
+
op: Operation | APIOperation<AptosAsset>,
|
|
19
|
+
payload: InputEntryFunctionData,
|
|
20
|
+
) => {
|
|
21
|
+
if (
|
|
22
|
+
payload.functionArguments &&
|
|
23
|
+
payload.functionArguments.length > 0 &&
|
|
24
|
+
typeof payload.functionArguments[0] === "string"
|
|
25
|
+
) {
|
|
26
|
+
op.recipients.push(payload.functionArguments[0].toString());
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const addFungibleToRecipients = (
|
|
31
|
+
op: Operation | APIOperation<AptosAsset>,
|
|
32
|
+
payload: InputEntryFunctionData,
|
|
33
|
+
) => {
|
|
34
|
+
if (
|
|
35
|
+
payload.functionArguments &&
|
|
36
|
+
payload.functionArguments.length > 1 &&
|
|
37
|
+
typeof payload.functionArguments[0] === "object" &&
|
|
38
|
+
typeof payload.functionArguments[1] === "string"
|
|
39
|
+
) {
|
|
40
|
+
op.recipients.push(payload.functionArguments[1].toString());
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const addBatchedFunctions = (
|
|
45
|
+
op: Operation | APIOperation<AptosAsset>,
|
|
46
|
+
payload: InputEntryFunctionData,
|
|
47
|
+
address: string,
|
|
48
|
+
) => {
|
|
49
|
+
if (
|
|
50
|
+
!(
|
|
51
|
+
payload.functionArguments &&
|
|
52
|
+
payload.functionArguments.length > 0 &&
|
|
53
|
+
Array.isArray(payload.functionArguments[0])
|
|
54
|
+
)
|
|
55
|
+
) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
for (const recipient of payload.functionArguments[0]) {
|
|
59
|
+
if (recipient && compareAddress(recipient.toString(), address)) {
|
|
60
|
+
op.recipients.push(recipient.toString());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export function processRecipients(
|
|
66
|
+
payload: InputEntryFunctionData,
|
|
67
|
+
address: string,
|
|
68
|
+
op: Operation | APIOperation<AptosAsset>,
|
|
69
|
+
function_address: string,
|
|
70
|
+
): void {
|
|
71
|
+
// get recipients by 3 groups
|
|
72
|
+
if (transferLikeFunctions(payload)) {
|
|
73
|
+
// 1. Transfer like functions (includes some delegation pool functions)
|
|
74
|
+
addLikeFunctionsToRecipients(op, payload);
|
|
75
|
+
} else if (FA_TRANSFER_TYPES.includes(payload.function)) {
|
|
76
|
+
// 1. Transfer like functions (includes some delegation pool functions)
|
|
77
|
+
addFungibleToRecipients(op, payload);
|
|
78
|
+
} else if (BATCH_TRANSFER_TYPES.includes(payload.function)) {
|
|
79
|
+
// 2. Batch function, to validate we are in the recipients list
|
|
80
|
+
if (!compareAddress(op.senders[0], address)) {
|
|
81
|
+
addBatchedFunctions(op, payload, address);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
// 3. other smart contracts, in this case smart contract will be treated as a recipient
|
|
85
|
+
op.recipients.push(function_address);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AptosTransaction } from "../types";
|
|
2
|
+
import { Operation } from "@ledgerhq/coin-framework/api/types";
|
|
3
|
+
import { AptosAsset } from "../types/assets";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
import { EntryFunctionPayloadResponse, InputEntryFunctionData } from "@aptos-labs/ts-sdk";
|
|
6
|
+
import { APTOS_ASSET_ID, DIRECTION } from "../constants";
|
|
7
|
+
import { compareAddress, getCoinAndAmounts } from "./getCoinAndAmounts";
|
|
8
|
+
import { calculateAmount } from "./calculateAmount";
|
|
9
|
+
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/index";
|
|
10
|
+
import { processRecipients } from "./processRecipients";
|
|
11
|
+
import { getFunctionAddress } from "./getFunctionAddress";
|
|
12
|
+
|
|
13
|
+
export const convertFunctionPayloadResponseToInputEntryFunctionData = (
|
|
14
|
+
payload: EntryFunctionPayloadResponse,
|
|
15
|
+
): InputEntryFunctionData => ({
|
|
16
|
+
function: payload.function,
|
|
17
|
+
typeArguments: payload.type_arguments,
|
|
18
|
+
functionArguments: payload.arguments,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const detectType = (address: string, tx: AptosTransaction, value: BigNumber): DIRECTION => {
|
|
22
|
+
let type = compareAddress(tx.sender, address) ? DIRECTION.OUT : DIRECTION.IN;
|
|
23
|
+
|
|
24
|
+
if (!value) {
|
|
25
|
+
// skip transaction that result no Aptos change
|
|
26
|
+
type = DIRECTION.UNKNOWN;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return type;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function transactionsToOperations(
|
|
33
|
+
address: string,
|
|
34
|
+
txs: (AptosTransaction | null)[],
|
|
35
|
+
): [Operation<AptosAsset>[], Operation<AptosAsset>[]] {
|
|
36
|
+
const operations: [Operation<AptosAsset>[], Operation<AptosAsset>[]] = [[], []];
|
|
37
|
+
|
|
38
|
+
return txs.reduce((acc, tx) => {
|
|
39
|
+
if (tx === null) {
|
|
40
|
+
return acc;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const payload = convertFunctionPayloadResponseToInputEntryFunctionData(
|
|
44
|
+
tx.payload as EntryFunctionPayloadResponse,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const function_address = getFunctionAddress(payload);
|
|
48
|
+
|
|
49
|
+
if (!function_address) {
|
|
50
|
+
return acc; // skip transaction without functions in payload
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const { coin_id, amount_in, amount_out } = getCoinAndAmounts(tx, address);
|
|
54
|
+
const value = calculateAmount(tx.sender, address, amount_in, amount_out);
|
|
55
|
+
const type = detectType(address, tx, value);
|
|
56
|
+
|
|
57
|
+
const op: Operation<AptosAsset> = {
|
|
58
|
+
id: tx.hash,
|
|
59
|
+
type,
|
|
60
|
+
senders: [],
|
|
61
|
+
recipients: [],
|
|
62
|
+
value: BigInt(0),
|
|
63
|
+
asset: { type: "native" },
|
|
64
|
+
details: {
|
|
65
|
+
hasFailed: !tx.success,
|
|
66
|
+
},
|
|
67
|
+
tx: {
|
|
68
|
+
hash: tx.hash,
|
|
69
|
+
block: { height: 0 },
|
|
70
|
+
fees: BigInt(0),
|
|
71
|
+
date: new Date(parseInt(tx.timestamp) / 1000),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const fees = new BigNumber(tx.gas_used).multipliedBy(new BigNumber(tx.gas_unit_price));
|
|
76
|
+
op.tx.fees = BigInt(fees.toString());
|
|
77
|
+
|
|
78
|
+
op.value = BigInt(value.isNaN() ? 0 : value.toString());
|
|
79
|
+
op.senders.push(tx.sender);
|
|
80
|
+
|
|
81
|
+
processRecipients(payload, address, op, function_address);
|
|
82
|
+
|
|
83
|
+
if (op.type !== DIRECTION.UNKNOWN && coin_id !== null) {
|
|
84
|
+
if (coin_id === APTOS_ASSET_ID) {
|
|
85
|
+
acc[0].push(op);
|
|
86
|
+
return acc;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const token = findTokenByAddressInCurrency(coin_id.toLowerCase(), "aptos");
|
|
90
|
+
|
|
91
|
+
if (token !== undefined) {
|
|
92
|
+
acc[1].push(op);
|
|
93
|
+
|
|
94
|
+
if (op.type === DIRECTION.OUT) {
|
|
95
|
+
acc[0].push({
|
|
96
|
+
...op,
|
|
97
|
+
value: op.tx.fees,
|
|
98
|
+
type: "FEES",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return acc;
|
|
104
|
+
}, operations);
|
|
105
|
+
}
|