@ledgerhq/coin-aptos 2.0.0 → 2.1.0-nightly.0
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/CHANGELOG.md +14 -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 +187 -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.js +276 -9
- package/lib/__tests__/api/index.integ.test.js.map +1 -1
- package/lib/__tests__/api/index.test.js +1 -1
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/logic.test.js +8 -558
- package/lib/__tests__/bridge/logic.test.js.map +1 -1
- package/lib/__tests__/bridge/signOperation.test.js +7 -11
- package/lib/__tests__/bridge/signOperation.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 +14 -8
- 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 +1 -1
- 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/normalizeAddress.unit.test.d.ts +2 -0
- package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/logic/normalizeAddress.unit.test.js +12 -0
- package/lib/__tests__/logic/normalizeAddress.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.js +613 -9
- package/lib/__tests__/network/client.test.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +7 -12
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +1 -1
- package/lib/bridge/getFeesForTransaction.js.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 -17
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +12 -204
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +1 -1
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +1 -1
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/constants.d.ts +7 -4
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +8 -4
- package/lib/constants.js.map +1 -1
- package/lib/logic/buildTransaction.d.ts +9 -0
- package/lib/logic/buildTransaction.d.ts.map +1 -0
- package/lib/logic/buildTransaction.js +47 -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 +68 -0
- package/lib/logic/craftTransaction.js.map +1 -0
- package/lib/logic/createTransaction.d.ts.map +1 -0
- 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/normalizeAddress.d.ts +2 -0
- package/lib/logic/normalizeAddress.d.ts.map +1 -0
- package/lib/logic/normalizeAddress.js +12 -0
- package/lib/logic/normalizeAddress.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 +58 -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 +89 -0
- package/lib/logic/transactionsToOperations.js.map +1 -0
- package/lib/network/client.d.ts +6 -4
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +50 -14
- package/lib/network/client.js.map +1 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +4 -7
- package/lib/network/index.js.map +1 -1
- package/lib/types/assets.d.ts +5 -1
- package/lib/types/assets.d.ts.map +1 -1
- 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 +185 -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.js +277 -10
- package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
- package/lib-es/__tests__/api/index.test.js +1 -1
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/logic.test.js +8 -558
- package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
- package/lib-es/__tests__/bridge/signOperation.test.js +7 -11
- package/lib-es/__tests__/bridge/signOperation.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 +11 -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 +1 -1
- 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/normalizeAddress.unit.test.d.ts +2 -0
- package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/normalizeAddress.unit.test.js +10 -0
- package/lib-es/__tests__/logic/normalizeAddress.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.js +614 -10
- package/lib-es/__tests__/network/client.test.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +7 -12
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +1 -1
- package/lib-es/bridge/getFeesForTransaction.js.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 -17
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +6 -187
- package/lib-es/bridge/logic.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +1 -1
- 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 +1 -1
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/constants.d.ts +7 -4
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +7 -3
- package/lib-es/constants.js.map +1 -1
- package/lib-es/logic/buildTransaction.d.ts +9 -0
- 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 +38 -0
- package/lib-es/logic/craftTransaction.js.map +1 -0
- package/lib-es/logic/createTransaction.d.ts.map +1 -0
- 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/normalizeAddress.d.ts +2 -0
- package/lib-es/logic/normalizeAddress.d.ts.map +1 -0
- package/lib-es/logic/normalizeAddress.js +8 -0
- package/lib-es/logic/normalizeAddress.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 +54 -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 +81 -0
- package/lib-es/logic/transactionsToOperations.js.map +1 -0
- package/lib-es/network/client.d.ts +6 -4
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +50 -14
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +5 -8
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/types/assets.d.ts +5 -1
- package/lib-es/types/assets.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/__tests__/api/craftTransaction.unit.test.ts +243 -0
- package/src/__tests__/api/getBalance.unit.test.ts +44 -0
- package/src/__tests__/api/index.integ.test.ts +355 -12
- package/src/__tests__/api/index.test.ts +1 -1
- package/src/__tests__/bridge/logic.test.ts +9 -654
- package/src/__tests__/bridge/signOperation.test.ts +7 -11
- package/src/__tests__/index.test.ts +1 -1
- package/src/__tests__/{bridge → logic}/buildTransaction.test.ts +14 -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 +1 -1
- 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/normalizeAddress.unit.test.ts +15 -0
- package/src/__tests__/logic/processRecipients.unit.test.ts +95 -0
- package/src/__tests__/network/client.test.ts +650 -11
- package/src/api/index.ts +10 -13
- package/src/bridge/estimateMaxSpendable.ts +1 -1
- package/src/bridge/getFeesForTransaction.ts +1 -1
- package/src/bridge/index.ts +1 -1
- package/src/bridge/logic.ts +8 -279
- package/src/bridge/prepareTransaction.ts +1 -1
- package/src/bridge/signOperation.ts +1 -1
- package/src/config.ts +1 -1
- package/src/constants.ts +8 -4
- package/src/logic/buildTransaction.ts +70 -0
- package/src/logic/calculateAmount.ts +15 -0
- package/src/logic/combine.ts +51 -0
- package/src/logic/craftTransaction.ts +65 -0
- 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/normalizeAddress.ts +8 -0
- package/src/logic/normalizeTransactionOptions.ts +18 -0
- package/src/logic/processRecipients.ts +88 -0
- package/src/logic/transactionsToOperations.ts +106 -0
- package/src/network/client.ts +88 -29
- package/src/network/index.ts +4 -13
- package/src/types/assets.ts +6 -1
- 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/bridge/buildTransaction.d.ts +0 -7
- package/lib/bridge/buildTransaction.d.ts.map +0 -1
- package/lib/bridge/buildTransaction.js +0 -45
- 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/bridge/buildTransaction.d.ts +0 -7
- package/lib-es/bridge/buildTransaction.d.ts.map +0 -1
- package/lib-es/bridge/buildTransaction.js +0 -43
- 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/bridge/buildTransaction.ts +0 -62
- /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/{bridge → logic}/createTransaction.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/{bridge → logic}/createTransaction.js +0 -0
- /package/src/{bridge → logic}/createTransaction.ts +0 -0
package/src/api/index.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { Api } from "@ledgerhq/coin-framework/api/index";
|
|
2
2
|
import type { AptosConfig as AptosConfigApi } from "../config";
|
|
3
|
-
import type { Balance,
|
|
3
|
+
import type { Balance, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
4
4
|
import coinConfig from "../config";
|
|
5
5
|
import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
|
|
6
6
|
import { AptosAPI } from "../network";
|
|
7
|
+
import { combine } from "../logic/combine";
|
|
8
|
+
import { craftTransaction } from "../logic/craftTransaction";
|
|
9
|
+
import { getBalance } from "../logic/getBalance";
|
|
7
10
|
|
|
8
11
|
export function createApi(
|
|
9
12
|
config: AptosConfigApi,
|
|
@@ -14,20 +17,14 @@ export function createApi(
|
|
|
14
17
|
|
|
15
18
|
return {
|
|
16
19
|
broadcast: (tx: string) => client.broadcast(tx),
|
|
17
|
-
combine: (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
craftTransaction: (_transactionIntent, _customFees): Promise<string> => {
|
|
21
|
-
throw new Error("Not Implemented");
|
|
22
|
-
},
|
|
20
|
+
combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
|
|
21
|
+
craftTransaction: (transactionIntent, _customFees): Promise<string> =>
|
|
22
|
+
craftTransaction(client, transactionIntent),
|
|
23
23
|
estimateFees: (transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>) =>
|
|
24
24
|
client.estimateFees(transactionIntent),
|
|
25
|
-
getBalance: (
|
|
26
|
-
throw new Error("Not Implemented");
|
|
27
|
-
},
|
|
25
|
+
getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalance(client, address),
|
|
28
26
|
lastBlock: () => client.getLastBlock(),
|
|
29
|
-
listOperations: (
|
|
30
|
-
|
|
31
|
-
},
|
|
27
|
+
listOperations: (address: string, pagination: Pagination) =>
|
|
28
|
+
client.listOperations(address, pagination),
|
|
32
29
|
};
|
|
33
30
|
}
|
|
@@ -4,8 +4,8 @@ import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
|
4
4
|
import { AptosAPI } from "../network";
|
|
5
5
|
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
6
6
|
import { getMaxSendBalance } from "./logic";
|
|
7
|
-
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
8
7
|
import type { Transaction } from "../types";
|
|
8
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
9
9
|
|
|
10
10
|
const estimateMaxSpendable = async ({
|
|
11
11
|
account,
|
|
@@ -4,10 +4,10 @@ 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
6
|
import { AptosAPI } from "../network";
|
|
7
|
-
import buildTransaction from "./buildTransaction";
|
|
8
7
|
import { getTokenAccount } from "./logic";
|
|
9
8
|
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "../constants";
|
|
10
9
|
import type { Transaction, TransactionErrors } from "../types";
|
|
10
|
+
import buildTransaction from "../logic/buildTransaction";
|
|
11
11
|
|
|
12
12
|
type IGetEstimatedGasReturnType = {
|
|
13
13
|
fees: BigNumber;
|
package/src/bridge/index.ts
CHANGED
|
@@ -13,10 +13,10 @@ 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,31 +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
|
-
}
|
|
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";
|
|
44
19
|
|
|
45
20
|
export const getMaxSendBalance = (
|
|
46
21
|
gas: BigNumber,
|
|
@@ -60,23 +35,6 @@ export const getMaxSendBalance = (
|
|
|
60
35
|
: new BigNumber(0);
|
|
61
36
|
};
|
|
62
37
|
|
|
63
|
-
export function normalizeTransactionOptions(options: TransactionOptions): TransactionOptions {
|
|
64
|
-
// FIXME: this is wrong. TransactionOptions is
|
|
65
|
-
// {
|
|
66
|
-
// maxGasAmount: string;
|
|
67
|
-
// gasUnitPrice: string;
|
|
68
|
-
// sequenceNumber?: string;
|
|
69
|
-
// expirationTimestampSecs?: string;
|
|
70
|
-
// }
|
|
71
|
-
// meaning we can't return undefined in check method.
|
|
72
|
-
// This method is useless, not deleting as it breaks code and this iteration is coin modularisation.
|
|
73
|
-
const check = (v: any) => ((v ?? "").toString().trim() ? v : undefined);
|
|
74
|
-
return {
|
|
75
|
-
maxGasAmount: check(options.maxGasAmount),
|
|
76
|
-
gasUnitPrice: check(options.gasUnitPrice),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
38
|
export const getBlankOperation = (
|
|
81
39
|
tx: AptosTransaction,
|
|
82
40
|
id: string,
|
|
@@ -97,14 +55,6 @@ export const getBlankOperation = (
|
|
|
97
55
|
hasFailed: false,
|
|
98
56
|
});
|
|
99
57
|
|
|
100
|
-
const convertFunctionPayloadResponseToInputEntryFunctionData = (
|
|
101
|
-
payload: EntryFunctionPayloadResponse,
|
|
102
|
-
): InputEntryFunctionData => ({
|
|
103
|
-
function: payload.function,
|
|
104
|
-
typeArguments: payload.type_arguments,
|
|
105
|
-
functionArguments: payload.arguments,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
58
|
export const txsToOps = (
|
|
109
59
|
info: { address: string },
|
|
110
60
|
id: string,
|
|
@@ -169,227 +119,6 @@ export const txsToOps = (
|
|
|
169
119
|
return [ops, opsTokens];
|
|
170
120
|
};
|
|
171
121
|
|
|
172
|
-
export function compareAddress(addressA: string, addressB: string) {
|
|
173
|
-
return (
|
|
174
|
-
addressA.replace(CLEAN_HEX_REGEXP, "").toLowerCase() ===
|
|
175
|
-
addressB.replace(CLEAN_HEX_REGEXP, "").toLowerCase()
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function getFunctionAddress(payload: InputEntryFunctionData): string | undefined {
|
|
180
|
-
if (payload.function) {
|
|
181
|
-
const parts = payload.function.split("::");
|
|
182
|
-
return parts.length === 3 && parts[0].length ? parts[0] : undefined;
|
|
183
|
-
}
|
|
184
|
-
return undefined;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function processRecipients(
|
|
188
|
-
payload: InputEntryFunctionData,
|
|
189
|
-
address: string,
|
|
190
|
-
op: Operation,
|
|
191
|
-
function_address: string,
|
|
192
|
-
): void {
|
|
193
|
-
// get recipients buy 3 groups
|
|
194
|
-
if (
|
|
195
|
-
(COIN_TRANSFER_TYPES.includes(payload.function) ||
|
|
196
|
-
DELEGATION_POOL_TYPES.includes(payload.function)) &&
|
|
197
|
-
payload.functionArguments &&
|
|
198
|
-
payload.functionArguments.length > 0 &&
|
|
199
|
-
typeof payload.functionArguments[0] === "string"
|
|
200
|
-
) {
|
|
201
|
-
// 1. Transfer like functions (includes some delegation pool functions)
|
|
202
|
-
op.recipients.push(payload.functionArguments[0].toString());
|
|
203
|
-
} else if (
|
|
204
|
-
FA_TRANSFER_TYPES.includes(payload.function) &&
|
|
205
|
-
payload.functionArguments &&
|
|
206
|
-
payload.functionArguments.length > 1 &&
|
|
207
|
-
typeof payload.functionArguments[0] === "object" &&
|
|
208
|
-
typeof payload.functionArguments[1] === "string"
|
|
209
|
-
) {
|
|
210
|
-
// 1. Transfer like functions (includes some delegation pool functions)
|
|
211
|
-
op.recipients.push(payload.functionArguments[1].toString());
|
|
212
|
-
} else if (
|
|
213
|
-
BATCH_TRANSFER_TYPES.includes(payload.function) &&
|
|
214
|
-
payload.functionArguments &&
|
|
215
|
-
payload.functionArguments.length > 0 &&
|
|
216
|
-
Array.isArray(payload.functionArguments[0])
|
|
217
|
-
) {
|
|
218
|
-
// 2. Batch function, to validate we are in the recipients list
|
|
219
|
-
if (!compareAddress(op.senders[0], address)) {
|
|
220
|
-
for (const recipient of payload.functionArguments[0]) {
|
|
221
|
-
if (recipient && compareAddress(recipient.toString(), address)) {
|
|
222
|
-
op.recipients.push(recipient.toString());
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
227
|
-
// 3. other smart contracts, in this case smart contract will be treated as a recipient
|
|
228
|
-
op.recipients.push(function_address);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export function getEventCoinAddress(
|
|
233
|
-
change: WriteSetChangeWriteResource,
|
|
234
|
-
event: Event,
|
|
235
|
-
event_name: string,
|
|
236
|
-
): string | null {
|
|
237
|
-
const change_data = change.data;
|
|
238
|
-
|
|
239
|
-
const mr = change_data as MoveResource<AptosMoveResource>; // -> this is data that we want to parse
|
|
240
|
-
|
|
241
|
-
if (!(event_name in mr.data)) {
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const change_event_data = mr.data[event_name];
|
|
246
|
-
if (
|
|
247
|
-
change_event_data.guid.id.addr !== event.guid.account_address ||
|
|
248
|
-
change_event_data.guid.id.creation_num !== event.guid.creation_number
|
|
249
|
-
) {
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const address = extractAddress(mr.type);
|
|
254
|
-
|
|
255
|
-
return address;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export function getEventFAAddress(
|
|
259
|
-
change: WriteSetChangeWriteResource,
|
|
260
|
-
event: Event,
|
|
261
|
-
_event_name: string,
|
|
262
|
-
): string | null {
|
|
263
|
-
const change_data = change.data;
|
|
264
|
-
|
|
265
|
-
if (change_data.type !== APTOS_FUNGIBLE_STORE) {
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const mr = change_data as MoveResource<AptosFungibleStoreResourceData>;
|
|
270
|
-
|
|
271
|
-
if (change.address !== event.data.store) {
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return mr.data.metadata.inner;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export function getResourceAddress(
|
|
279
|
-
tx: AptosTransaction,
|
|
280
|
-
event: Event,
|
|
281
|
-
event_name: string,
|
|
282
|
-
getAddressProcessor: (
|
|
283
|
-
change: WriteSetChangeWriteResource,
|
|
284
|
-
event: Event,
|
|
285
|
-
event_name: string,
|
|
286
|
-
) => string | null,
|
|
287
|
-
): string | null {
|
|
288
|
-
for (const change of tx.changes) {
|
|
289
|
-
if (isWriteSetChangeWriteResource(change)) {
|
|
290
|
-
const address = getAddressProcessor(change, event, event_name);
|
|
291
|
-
if (address !== null) {
|
|
292
|
-
return address;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return null;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function isWriteSetChangeWriteResource(
|
|
300
|
-
change: WriteSetChange,
|
|
301
|
-
): change is WriteSetChangeWriteResource {
|
|
302
|
-
return (change as WriteSetChangeWriteResource).data !== undefined;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export function checkFAOwner(tx: AptosTransaction, event: Event, user_address: string): boolean {
|
|
306
|
-
for (const change of tx.changes) {
|
|
307
|
-
if (isWriteSetChangeWriteResource(change)) {
|
|
308
|
-
const storeData = change.data as MoveResource<AptosFungibleoObjectCoreResourceData>;
|
|
309
|
-
if (
|
|
310
|
-
change.address == event.data.store &&
|
|
311
|
-
storeData.type == APTOS_OBJECT_CORE &&
|
|
312
|
-
storeData.data.owner == user_address
|
|
313
|
-
) {
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export function getCoinAndAmounts(
|
|
322
|
-
tx: AptosTransaction,
|
|
323
|
-
address: string,
|
|
324
|
-
): { coin_id: string | null; amount_in: BigNumber; amount_out: BigNumber } {
|
|
325
|
-
let coin_id: string | null = null;
|
|
326
|
-
let amount_in = BigNumber(0);
|
|
327
|
-
let amount_out = BigNumber(0);
|
|
328
|
-
|
|
329
|
-
// collect all events related to the address and calculate the overall amounts
|
|
330
|
-
tx.events.forEach(event => {
|
|
331
|
-
switch (event.type) {
|
|
332
|
-
case "0x1::coin::WithdrawEvent":
|
|
333
|
-
if (compareAddress(event.guid.account_address, address)) {
|
|
334
|
-
coin_id = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
|
|
335
|
-
amount_out = amount_out.plus(event.data.amount);
|
|
336
|
-
}
|
|
337
|
-
break;
|
|
338
|
-
case "0x1::coin::DepositEvent":
|
|
339
|
-
if (compareAddress(event.guid.account_address, address)) {
|
|
340
|
-
coin_id = getResourceAddress(tx, event, "deposit_events", getEventCoinAddress);
|
|
341
|
-
amount_in = amount_in.plus(event.data.amount);
|
|
342
|
-
}
|
|
343
|
-
break;
|
|
344
|
-
case "0x1::fungible_asset::Withdraw":
|
|
345
|
-
if (checkFAOwner(tx, event, address)) {
|
|
346
|
-
coin_id = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
|
|
347
|
-
amount_out = amount_out.plus(event.data.amount);
|
|
348
|
-
}
|
|
349
|
-
break;
|
|
350
|
-
case "0x1::fungible_asset::Deposit":
|
|
351
|
-
if (checkFAOwner(tx, event, address)) {
|
|
352
|
-
coin_id = getResourceAddress(tx, event, "deposit_events", getEventFAAddress);
|
|
353
|
-
amount_in = amount_in.plus(event.data.amount);
|
|
354
|
-
}
|
|
355
|
-
break;
|
|
356
|
-
case "0x1::transaction_fee::FeeStatement":
|
|
357
|
-
if (tx.sender === address) {
|
|
358
|
-
if (coin_id === null) coin_id = APTOS_ASSET_ID;
|
|
359
|
-
if (coin_id === APTOS_ASSET_ID) {
|
|
360
|
-
const fees = BigNumber(tx.gas_unit_price).times(BigNumber(tx.gas_used));
|
|
361
|
-
amount_out = amount_out.plus(fees);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
return { coin_id, amount_in, amount_out }; // TODO: manage situation when there are several coinID from the events parsing
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
export function calculateAmount(
|
|
371
|
-
sender: string,
|
|
372
|
-
address: string,
|
|
373
|
-
amount_in: BigNumber,
|
|
374
|
-
amount_out: BigNumber,
|
|
375
|
-
): BigNumber {
|
|
376
|
-
const is_sender: boolean = compareAddress(sender, address);
|
|
377
|
-
// LL negates the amount for SEND transactions
|
|
378
|
-
// to show positive amount on the send transaction (ex: in "cancel" tx, when amount will be returned to our account)
|
|
379
|
-
// we need to make it negative
|
|
380
|
-
return is_sender ? amount_out.minus(amount_in) : amount_in.minus(amount_out);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Extracts the address from a string like "0x1::coin::CoinStore<address::module::type>"
|
|
385
|
-
* @param {string} str - The input string containing the address.
|
|
386
|
-
* @returns {string | null} - The extracted address or null if not found.
|
|
387
|
-
*/
|
|
388
|
-
function extractAddress(str: string): string | null {
|
|
389
|
-
const match = str.match(/<([^<>]+)>{1}$/);
|
|
390
|
-
return match ? match[1] : null;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
122
|
export function getTokenAccount(
|
|
394
123
|
account: Account,
|
|
395
124
|
transaction: Transaction,
|
|
@@ -5,7 +5,7 @@ import { AptosAPI } from "../network";
|
|
|
5
5
|
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
6
6
|
import type { Transaction } from "../types";
|
|
7
7
|
import { getMaxSendBalance } from "./logic";
|
|
8
|
-
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "
|
|
8
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
9
9
|
|
|
10
10
|
const prepareTransaction = async (
|
|
11
11
|
account: Account,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AptosAccount, Transaction } from "../types";
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
3
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
4
|
-
import buildTransaction from "./buildTransaction";
|
|
5
4
|
import BigNumber from "bignumber.js";
|
|
6
5
|
import type { Account, AccountBridge, Operation, OperationType } from "@ledgerhq/types-live";
|
|
7
6
|
import { AptosAPI } from "../network";
|
|
@@ -10,6 +9,7 @@ import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
|
10
9
|
import { AptosSigner } from "../types";
|
|
11
10
|
import { signTransaction } from "../network";
|
|
12
11
|
import { findSubAccountById } from "@ledgerhq/coin-framework/account/helpers";
|
|
12
|
+
import buildTransaction from "../logic/buildTransaction";
|
|
13
13
|
|
|
14
14
|
export const getAddress = (a: Account) => ({
|
|
15
15
|
address: a.freshAddress,
|
package/src/config.ts
CHANGED
package/src/constants.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { MoveStructId } from "@aptos-labs/ts-sdk";
|
|
1
|
+
import type { MoveStructId } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
|
|
4
|
-
export const DEFAULT_GAS = new BigNumber(200);
|
|
5
|
-
export const DEFAULT_GAS_PRICE = new BigNumber(100);
|
|
6
4
|
export const ESTIMATE_GAS_MUL = new BigNumber(1.0); // define buffer for gas estimation change here, if needed
|
|
7
5
|
|
|
8
6
|
export const LOAD_LIMIT = 10;
|
|
@@ -47,4 +45,10 @@ export enum DIRECTION {
|
|
|
47
45
|
UNKNOWN = "UNKNOWN",
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
export
|
|
48
|
+
export enum TOKEN_TYPE {
|
|
49
|
+
COIN = "coin",
|
|
50
|
+
FUNGIBLE_ASSET = "fungible_asset",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const DEFAULT_GAS = new BigNumber(200);
|
|
54
|
+
export const DEFAULT_GAS_PRICE = new BigNumber(100);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { InputEntryFunctionData, RawTransaction } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import { findSubAccountById } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
+
import { APTOS_ASSET_ID, TOKEN_TYPE } from "../constants";
|
|
5
|
+
import type { AptosAPI } from "../network";
|
|
6
|
+
import { normalizeTransactionOptions } from "./normalizeTransactionOptions";
|
|
7
|
+
import type { Transaction } from "../types";
|
|
8
|
+
import type BigNumber from "bignumber.js";
|
|
9
|
+
|
|
10
|
+
const buildTransaction = async (
|
|
11
|
+
account: Account,
|
|
12
|
+
transaction: Transaction,
|
|
13
|
+
aptosClient: AptosAPI,
|
|
14
|
+
contractAddress?: string,
|
|
15
|
+
tokenType?: TOKEN_TYPE,
|
|
16
|
+
): Promise<RawTransaction> => {
|
|
17
|
+
const subAccount = findSubAccountById(account, transaction.subAccountId ?? "");
|
|
18
|
+
|
|
19
|
+
const payloadContracAddress = subAccount ? subAccount.token.contractAddress : contractAddress;
|
|
20
|
+
const payloadTokenType = (subAccount?.token?.tokenType as TOKEN_TYPE) ?? tokenType;
|
|
21
|
+
|
|
22
|
+
const txPayload = getPayload({
|
|
23
|
+
amount: transaction.amount,
|
|
24
|
+
recipient: transaction.recipient,
|
|
25
|
+
contractAddress: payloadContracAddress,
|
|
26
|
+
tokenType: payloadTokenType,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const txOptions = normalizeTransactionOptions(transaction.options);
|
|
30
|
+
|
|
31
|
+
const tx = await aptosClient.generateTransaction(account.freshAddress, txPayload, txOptions);
|
|
32
|
+
|
|
33
|
+
return tx;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const getPayload = (args: {
|
|
37
|
+
amount: BigNumber;
|
|
38
|
+
recipient: string;
|
|
39
|
+
contractAddress?: string | undefined;
|
|
40
|
+
tokenType?: string;
|
|
41
|
+
}): InputEntryFunctionData => {
|
|
42
|
+
if (args.tokenType !== undefined && !isTokenType(args.tokenType)) {
|
|
43
|
+
throw new Error(`Token type ${args.tokenType} not supported`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (args.tokenType === TOKEN_TYPE.FUNGIBLE_ASSET) {
|
|
47
|
+
return {
|
|
48
|
+
function: "0x1::primary_fungible_store::transfer",
|
|
49
|
+
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
50
|
+
functionArguments: [args.contractAddress, args.recipient, args.amount.toString()],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let address = args.contractAddress ?? "";
|
|
55
|
+
if (address === "") {
|
|
56
|
+
address = APTOS_ASSET_ID;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
function: "0x1::aptos_account::transfer_coins",
|
|
61
|
+
typeArguments: [address],
|
|
62
|
+
functionArguments: [args.recipient, args.amount.toString()],
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const isTokenType = (value: string): boolean => {
|
|
67
|
+
return Object.values(TOKEN_TYPE).includes(value as TOKEN_TYPE);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
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,65 @@
|
|
|
1
|
+
import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
+
import type { AptosAsset, AptosExtra, AptosSender } from "../types/assets";
|
|
3
|
+
import type { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
4
|
+
import type { AptosAPI } from "../network";
|
|
5
|
+
import buildTransaction, { isTokenType } from "./buildTransaction";
|
|
6
|
+
import createTransaction from "./createTransaction";
|
|
7
|
+
import BigNumber from "bignumber.js";
|
|
8
|
+
import { APTOS_ASSET_ID, type TOKEN_TYPE } from "../constants";
|
|
9
|
+
import type { AptosBalance } from "../types";
|
|
10
|
+
|
|
11
|
+
export async function craftTransaction(
|
|
12
|
+
aptosClient: AptosAPI,
|
|
13
|
+
transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
14
|
+
): Promise<string> {
|
|
15
|
+
const newTx = createTransaction();
|
|
16
|
+
newTx.amount = BigNumber(transactionIntent.amount.toString());
|
|
17
|
+
newTx.recipient = transactionIntent.recipient;
|
|
18
|
+
newTx.mode = transactionIntent.type;
|
|
19
|
+
newTx.useAllAmount = transactionIntent.amount === BigInt(0);
|
|
20
|
+
|
|
21
|
+
const account = {
|
|
22
|
+
freshAddress: transactionIntent.sender.freshAddress,
|
|
23
|
+
xpub: transactionIntent.sender.xpub,
|
|
24
|
+
subAccounts: new Array<TokenAccount>(),
|
|
25
|
+
} as Account;
|
|
26
|
+
|
|
27
|
+
let tokenType: TOKEN_TYPE | undefined;
|
|
28
|
+
const contractAddress = getContractAddress(transactionIntent);
|
|
29
|
+
let balance: AptosBalance | undefined;
|
|
30
|
+
|
|
31
|
+
if (newTx.useAllAmount === true) {
|
|
32
|
+
const balances = await aptosClient.getBalances(transactionIntent.sender.freshAddress);
|
|
33
|
+
balance = balances?.find(
|
|
34
|
+
b => b.contractAddress.toLowerCase() === contractAddress?.toLowerCase(),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (balance !== undefined) {
|
|
38
|
+
newTx.amount = BigNumber(balance.amount.toString());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (transactionIntent.asset.type === "token") {
|
|
43
|
+
tokenType = transactionIntent.asset.standard as TOKEN_TYPE;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const aptosTx = await buildTransaction(
|
|
47
|
+
account,
|
|
48
|
+
newTx,
|
|
49
|
+
aptosClient,
|
|
50
|
+
contractAddress,
|
|
51
|
+
tokenType ?? undefined,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return aptosTx.bcsToHex().toString();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getContractAddress(
|
|
58
|
+
txIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
59
|
+
): string {
|
|
60
|
+
if (txIntent.asset.type === "token" && isTokenType(txIntent.asset.standard)) {
|
|
61
|
+
return txIntent.asset.contractAddress;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return APTOS_ASSET_ID;
|
|
65
|
+
}
|
|
@@ -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
|
+
}
|