@ledgerhq/coin-solana 0.7.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/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +16 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +9 -0
- package/lib/api/cached.d.ts +3 -0
- package/lib/api/cached.d.ts.map +1 -0
- package/lib/api/cached.js +40 -0
- package/lib/api/cached.js.map +1 -0
- package/lib/api/chain/account/index.d.ts +2 -0
- package/lib/api/chain/account/index.d.ts.map +1 -0
- package/lib/api/chain/account/index.js +8 -0
- package/lib/api/chain/account/index.js.map +1 -0
- package/lib/api/chain/account/parser.d.ts +10 -0
- package/lib/api/chain/account/parser.d.ts.map +1 -0
- package/lib/api/chain/account/parser.js +56 -0
- package/lib/api/chain/account/parser.js.map +1 -0
- package/lib/api/chain/account/stake.d.ts +237 -0
- package/lib/api/chain/account/stake.d.ts.map +1 -0
- package/lib/api/chain/account/stake.js +38 -0
- package/lib/api/chain/account/stake.js.map +1 -0
- package/lib/api/chain/account/token.d.ts +116 -0
- package/lib/api/chain/account/token.d.ts.map +1 -0
- package/lib/api/chain/account/token.js +42 -0
- package/lib/api/chain/account/token.js.map +1 -0
- package/lib/api/chain/account/vote.d.ts +252 -0
- package/lib/api/chain/account/vote.d.ts.map +1 -0
- package/lib/api/chain/account/vote.js +44 -0
- package/lib/api/chain/account/vote.js.map +1 -0
- package/lib/api/chain/index.d.ts +29 -0
- package/lib/api/chain/index.d.ts.map +1 -0
- package/lib/api/chain/index.js +99 -0
- package/lib/api/chain/index.js.map +1 -0
- package/lib/api/chain/instruction/associated-token-account/index.d.ts +15 -0
- package/lib/api/chain/instruction/associated-token-account/index.d.ts.map +1 -0
- package/lib/api/chain/instruction/associated-token-account/index.js +21 -0
- package/lib/api/chain/instruction/associated-token-account/index.js.map +1 -0
- package/lib/api/chain/instruction/associated-token-account/types.d.ts +30 -0
- package/lib/api/chain/instruction/associated-token-account/types.d.ts.map +1 -0
- package/lib/api/chain/instruction/associated-token-account/types.js +19 -0
- package/lib/api/chain/instruction/associated-token-account/types.js.map +1 -0
- package/lib/api/chain/instruction/memo/index.d.ts +15 -0
- package/lib/api/chain/instruction/memo/index.d.ts.map +1 -0
- package/lib/api/chain/instruction/memo/index.js +14 -0
- package/lib/api/chain/instruction/memo/index.js.map +1 -0
- package/lib/api/chain/instruction/memo/types.d.ts +21 -0
- package/lib/api/chain/instruction/memo/types.d.ts.map +1 -0
- package/lib/api/chain/instruction/memo/types.js +16 -0
- package/lib/api/chain/instruction/memo/types.js.map +1 -0
- package/lib/api/chain/instruction/stake/index.d.ts +15 -0
- package/lib/api/chain/instruction/stake/index.d.ts.map +1 -0
- package/lib/api/chain/instruction/stake/index.js +20 -0
- package/lib/api/chain/instruction/stake/index.js.map +1 -0
- package/lib/api/chain/instruction/stake/types.d.ts +215 -0
- package/lib/api/chain/instruction/stake/types.d.ts.map +1 -0
- package/lib/api/chain/instruction/stake/types.js +80 -0
- package/lib/api/chain/instruction/stake/types.js.map +1 -0
- package/lib/api/chain/instruction/system/index.d.ts +15 -0
- package/lib/api/chain/instruction/system/index.d.ts.map +1 -0
- package/lib/api/chain/instruction/system/index.js +20 -0
- package/lib/api/chain/instruction/system/index.js.map +1 -0
- package/lib/api/chain/instruction/system/types.d.ts +298 -0
- package/lib/api/chain/instruction/system/types.d.ts.map +1 -0
- package/lib/api/chain/instruction/system/types.js +117 -0
- package/lib/api/chain/instruction/system/types.js.map +1 -0
- package/lib/api/chain/instruction/token/index.d.ts +15 -0
- package/lib/api/chain/instruction/token/index.d.ts.map +1 -0
- package/lib/api/chain/instruction/token/index.js +20 -0
- package/lib/api/chain/instruction/token/index.js.map +1 -0
- package/lib/api/chain/instruction/token/types.d.ts +497 -0
- package/lib/api/chain/instruction/token/types.d.ts.map +1 -0
- package/lib/api/chain/instruction/token/types.js +200 -0
- package/lib/api/chain/instruction/token/types.js.map +1 -0
- package/lib/api/chain/program/constants.d.ts +11 -0
- package/lib/api/chain/program/constants.d.ts.map +1 -0
- package/lib/api/chain/program/constants.js +14 -0
- package/lib/api/chain/program/constants.js.map +1 -0
- package/lib/api/chain/program/index.d.ts +2 -0
- package/lib/api/chain/program/index.d.ts.map +1 -0
- package/lib/api/chain/program/index.js +7 -0
- package/lib/api/chain/program/index.js.map +1 -0
- package/lib/api/chain/program/parser.d.ts +35 -0
- package/lib/api/chain/program/parser.d.ts.map +1 -0
- package/lib/api/chain/program/parser.js +66 -0
- package/lib/api/chain/program/parser.js.map +1 -0
- package/lib/api/chain/validators/bignum.d.ts +3 -0
- package/lib/api/chain/validators/bignum.d.ts.map +1 -0
- package/lib/api/chain/validators/bignum.js +11 -0
- package/lib/api/chain/validators/bignum.js.map +1 -0
- package/lib/api/chain/validators/index.d.ts +10 -0
- package/lib/api/chain/validators/index.d.ts.map +1 -0
- package/lib/api/chain/validators/index.js +10 -0
- package/lib/api/chain/validators/index.js.map +1 -0
- package/lib/api/chain/validators/pubkey.d.ts +3 -0
- package/lib/api/chain/validators/pubkey.d.ts.map +1 -0
- package/lib/api/chain/validators/pubkey.js +7 -0
- package/lib/api/chain/validators/pubkey.js.map +1 -0
- package/lib/api/chain/web3.d.ts +43 -0
- package/lib/api/chain/web3.d.ts.map +1 -0
- package/lib/api/chain/web3.js +274 -0
- package/lib/api/chain/web3.js.map +1 -0
- package/lib/api/index.d.ts +5 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +25 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/logged.d.ts +3 -0
- package/lib/api/logged.d.ts.map +1 -0
- package/lib/api/logged.js +69 -0
- package/lib/api/logged.js.map +1 -0
- package/lib/api/queued.d.ts +3 -0
- package/lib/api/queued.d.ts.map +1 -0
- package/lib/api/queued.js +27 -0
- package/lib/api/queued.js.map +1 -0
- package/lib/api/traced.d.ts +3 -0
- package/lib/api/traced.d.ts.map +1 -0
- package/lib/api/traced.js +80 -0
- package/lib/api/traced.js.map +1 -0
- package/lib/bridge/bridge.d.ts +15 -0
- package/lib/bridge/bridge.d.ts.map +1 -0
- package/lib/bridge/bridge.js +139 -0
- package/lib/bridge/bridge.js.map +1 -0
- package/lib/bridge/js.d.ts +7 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +28 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/bridge.integration.test.d.ts +4 -0
- package/lib/bridge.integration.test.d.ts.map +1 -0
- package/lib/bridge.integration.test.js +990 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/cli-transaction.d.ts +19 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +196 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/datasets/solana.scanAccounts.1.d.ts +6 -0
- package/lib/datasets/solana.scanAccounts.1.d.ts.map +1 -0
- package/lib/datasets/solana.scanAccounts.1.js +12 -0
- package/lib/datasets/solana.scanAccounts.1.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +10 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +228 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +61 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +25 -0
- package/lib/errors.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +28 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/js-broadcast.d.ts +7 -0
- package/lib/js-broadcast.d.ts.map +1 -0
- package/lib/js-broadcast.js +37 -0
- package/lib/js-broadcast.js.map +1 -0
- package/lib/js-buildTransaction.d.ts +5 -0
- package/lib/js-buildTransaction.d.ts.map +1 -0
- package/lib/js-buildTransaction.js +67 -0
- package/lib/js-buildTransaction.js.map +1 -0
- package/lib/js-createTransaction.d.ts +5 -0
- package/lib/js-createTransaction.d.ts.map +1 -0
- package/lib/js-createTransaction.js +19 -0
- package/lib/js-createTransaction.js.map +1 -0
- package/lib/js-estimateMaxSpendable.d.ts +11 -0
- package/lib/js-estimateMaxSpendable.d.ts.map +1 -0
- package/lib/js-estimateMaxSpendable.js +62 -0
- package/lib/js-estimateMaxSpendable.js.map +1 -0
- package/lib/js-getTransactionStatus.d.ts +5 -0
- package/lib/js-getTransactionStatus.d.ts.map +1 -0
- package/lib/js-getTransactionStatus.js +71 -0
- package/lib/js-getTransactionStatus.js.map +1 -0
- package/lib/js-preload-data.d.ts +7 -0
- package/lib/js-preload-data.d.ts.map +1 -0
- package/lib/js-preload-data.js +45 -0
- package/lib/js-preload-data.js.map +1 -0
- package/lib/js-preload.d.ts +7 -0
- package/lib/js-preload.d.ts.map +1 -0
- package/lib/js-preload.js +67 -0
- package/lib/js-preload.js.map +1 -0
- package/lib/js-preload.test.d.ts +2 -0
- package/lib/js-preload.test.d.ts.map +1 -0
- package/lib/js-preload.test.js +9 -0
- package/lib/js-preload.test.js.map +1 -0
- package/lib/js-prepareTransaction.d.ts +5 -0
- package/lib/js-prepareTransaction.d.ts.map +1 -0
- package/lib/js-prepareTransaction.js +500 -0
- package/lib/js-prepareTransaction.js.map +1 -0
- package/lib/js-signOperation.d.ts +7 -0
- package/lib/js-signOperation.d.ts.map +1 -0
- package/lib/js-signOperation.js +153 -0
- package/lib/js-signOperation.js.map +1 -0
- package/lib/js-synchronization.d.ts +5 -0
- package/lib/js-synchronization.d.ts.map +1 -0
- package/lib/js-synchronization.js +464 -0
- package/lib/js-synchronization.js.map +1 -0
- package/lib/logic.d.ts +29 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +102 -0
- package/lib/logic.js.map +1 -0
- package/lib/serialization.d.ts +9 -0
- package/lib/serialization.d.ts.map +1 -0
- package/lib/serialization.js +69 -0
- package/lib/serialization.js.map +1 -0
- package/lib/signer.d.ts +11 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +7 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +409 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +8 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +217 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +153 -0
- package/lib/transaction.js.map +1 -0
- package/lib/tx-fees.d.ts +4 -0
- package/lib/tx-fees.d.ts.map +1 -0
- package/lib/tx-fees.js +167 -0
- package/lib/tx-fees.js.map +1 -0
- package/lib/types.d.ts +222 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +24 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +172 -0
- package/lib/utils.js.map +1 -0
- package/lib/validator-app/index.d.ts +22 -0
- package/lib/validator-app/index.d.ts.map +1 -0
- package/lib/validator-app/index.js +62 -0
- package/lib/validator-app/index.js.map +1 -0
- package/lib-es/api/cached.d.ts +3 -0
- package/lib-es/api/cached.d.ts.map +1 -0
- package/lib-es/api/cached.js +33 -0
- package/lib-es/api/cached.js.map +1 -0
- package/lib-es/api/chain/account/index.d.ts +2 -0
- package/lib-es/api/chain/account/index.d.ts.map +1 -0
- package/lib-es/api/chain/account/index.js +2 -0
- package/lib-es/api/chain/account/index.js.map +1 -0
- package/lib-es/api/chain/account/parser.d.ts +10 -0
- package/lib-es/api/chain/account/parser.d.ts.map +1 -0
- package/lib-es/api/chain/account/parser.js +48 -0
- package/lib-es/api/chain/account/parser.js.map +1 -0
- package/lib-es/api/chain/account/stake.d.ts +237 -0
- package/lib-es/api/chain/account/stake.d.ts.map +1 -0
- package/lib-es/api/chain/account/stake.js +35 -0
- package/lib-es/api/chain/account/stake.js.map +1 -0
- package/lib-es/api/chain/account/token.d.ts +116 -0
- package/lib-es/api/chain/account/token.d.ts.map +1 -0
- package/lib-es/api/chain/account/token.js +39 -0
- package/lib-es/api/chain/account/token.js.map +1 -0
- package/lib-es/api/chain/account/vote.d.ts +252 -0
- package/lib-es/api/chain/account/vote.d.ts.map +1 -0
- package/lib-es/api/chain/account/vote.js +41 -0
- package/lib-es/api/chain/account/vote.js.map +1 -0
- package/lib-es/api/chain/index.d.ts +29 -0
- package/lib-es/api/chain/index.d.ts.map +1 -0
- package/lib-es/api/chain/index.js +95 -0
- package/lib-es/api/chain/index.js.map +1 -0
- package/lib-es/api/chain/instruction/associated-token-account/index.d.ts +15 -0
- package/lib-es/api/chain/instruction/associated-token-account/index.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/associated-token-account/index.js +17 -0
- package/lib-es/api/chain/instruction/associated-token-account/index.js.map +1 -0
- package/lib-es/api/chain/instruction/associated-token-account/types.d.ts +30 -0
- package/lib-es/api/chain/instruction/associated-token-account/types.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/associated-token-account/types.js +16 -0
- package/lib-es/api/chain/instruction/associated-token-account/types.js.map +1 -0
- package/lib-es/api/chain/instruction/memo/index.d.ts +15 -0
- package/lib-es/api/chain/instruction/memo/index.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/memo/index.js +10 -0
- package/lib-es/api/chain/instruction/memo/index.js.map +1 -0
- package/lib-es/api/chain/instruction/memo/types.d.ts +21 -0
- package/lib-es/api/chain/instruction/memo/types.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/memo/types.js +13 -0
- package/lib-es/api/chain/instruction/memo/types.js.map +1 -0
- package/lib-es/api/chain/instruction/stake/index.d.ts +15 -0
- package/lib-es/api/chain/instruction/stake/index.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/stake/index.js +16 -0
- package/lib-es/api/chain/instruction/stake/index.js.map +1 -0
- package/lib-es/api/chain/instruction/stake/types.d.ts +215 -0
- package/lib-es/api/chain/instruction/stake/types.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/stake/types.js +77 -0
- package/lib-es/api/chain/instruction/stake/types.js.map +1 -0
- package/lib-es/api/chain/instruction/system/index.d.ts +15 -0
- package/lib-es/api/chain/instruction/system/index.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/system/index.js +16 -0
- package/lib-es/api/chain/instruction/system/index.js.map +1 -0
- package/lib-es/api/chain/instruction/system/types.d.ts +298 -0
- package/lib-es/api/chain/instruction/system/types.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/system/types.js +114 -0
- package/lib-es/api/chain/instruction/system/types.js.map +1 -0
- package/lib-es/api/chain/instruction/token/index.d.ts +15 -0
- package/lib-es/api/chain/instruction/token/index.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/token/index.js +16 -0
- package/lib-es/api/chain/instruction/token/index.js.map +1 -0
- package/lib-es/api/chain/instruction/token/types.d.ts +497 -0
- package/lib-es/api/chain/instruction/token/types.d.ts.map +1 -0
- package/lib-es/api/chain/instruction/token/types.js +197 -0
- package/lib-es/api/chain/instruction/token/types.js.map +1 -0
- package/lib-es/api/chain/program/constants.d.ts +11 -0
- package/lib-es/api/chain/program/constants.d.ts.map +1 -0
- package/lib-es/api/chain/program/constants.js +11 -0
- package/lib-es/api/chain/program/constants.js.map +1 -0
- package/lib-es/api/chain/program/index.d.ts +2 -0
- package/lib-es/api/chain/program/index.d.ts.map +1 -0
- package/lib-es/api/chain/program/index.js +2 -0
- package/lib-es/api/chain/program/index.js.map +1 -0
- package/lib-es/api/chain/program/parser.d.ts +35 -0
- package/lib-es/api/chain/program/parser.d.ts.map +1 -0
- package/lib-es/api/chain/program/parser.js +61 -0
- package/lib-es/api/chain/program/parser.js.map +1 -0
- package/lib-es/api/chain/validators/bignum.d.ts +3 -0
- package/lib-es/api/chain/validators/bignum.d.ts.map +1 -0
- package/lib-es/api/chain/validators/bignum.js +8 -0
- package/lib-es/api/chain/validators/bignum.js.map +1 -0
- package/lib-es/api/chain/validators/index.d.ts +10 -0
- package/lib-es/api/chain/validators/index.d.ts.map +1 -0
- package/lib-es/api/chain/validators/index.js +7 -0
- package/lib-es/api/chain/validators/index.js.map +1 -0
- package/lib-es/api/chain/validators/pubkey.d.ts +3 -0
- package/lib-es/api/chain/validators/pubkey.d.ts.map +1 -0
- package/lib-es/api/chain/validators/pubkey.js +4 -0
- package/lib-es/api/chain/validators/pubkey.js.map +1 -0
- package/lib-es/api/chain/web3.d.ts +43 -0
- package/lib-es/api/chain/web3.d.ts.map +1 -0
- package/lib-es/api/chain/web3.js +251 -0
- package/lib-es/api/chain/web3.js.map +1 -0
- package/lib-es/api/index.d.ts +5 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +5 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/logged.d.ts +3 -0
- package/lib-es/api/logged.d.ts.map +1 -0
- package/lib-es/api/logged.js +65 -0
- package/lib-es/api/logged.js.map +1 -0
- package/lib-es/api/queued.d.ts +3 -0
- package/lib-es/api/queued.d.ts.map +1 -0
- package/lib-es/api/queued.js +23 -0
- package/lib-es/api/queued.js.map +1 -0
- package/lib-es/api/traced.d.ts +3 -0
- package/lib-es/api/traced.d.ts.map +1 -0
- package/lib-es/api/traced.js +76 -0
- package/lib-es/api/traced.js.map +1 -0
- package/lib-es/bridge/bridge.d.ts +15 -0
- package/lib-es/bridge/bridge.d.ts.map +1 -0
- package/lib-es/bridge/bridge.js +132 -0
- package/lib-es/bridge/bridge.js.map +1 -0
- package/lib-es/bridge/js.d.ts +7 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +24 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/bridge.integration.test.d.ts +4 -0
- package/lib-es/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/bridge.integration.test.js +988 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +19 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +190 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/datasets/solana.scanAccounts.1.d.ts +6 -0
- package/lib-es/datasets/solana.scanAccounts.1.d.ts.map +1 -0
- package/lib-es/datasets/solana.scanAccounts.1.js +10 -0
- package/lib-es/datasets/solana.scanAccounts.1.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +10 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +223 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/errors.d.ts +61 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +22 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +23 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/js-broadcast.d.ts +7 -0
- package/lib-es/js-broadcast.d.ts.map +1 -0
- package/lib-es/js-broadcast.js +33 -0
- package/lib-es/js-broadcast.js.map +1 -0
- package/lib-es/js-buildTransaction.d.ts +5 -0
- package/lib-es/js-buildTransaction.d.ts.map +1 -0
- package/lib-es/js-buildTransaction.js +63 -0
- package/lib-es/js-buildTransaction.js.map +1 -0
- package/lib-es/js-createTransaction.d.ts +5 -0
- package/lib-es/js-createTransaction.d.ts.map +1 -0
- package/lib-es/js-createTransaction.js +17 -0
- package/lib-es/js-createTransaction.js.map +1 -0
- package/lib-es/js-estimateMaxSpendable.d.ts +11 -0
- package/lib-es/js-estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/js-estimateMaxSpendable.js +55 -0
- package/lib-es/js-estimateMaxSpendable.js.map +1 -0
- package/lib-es/js-getTransactionStatus.d.ts +5 -0
- package/lib-es/js-getTransactionStatus.d.ts.map +1 -0
- package/lib-es/js-getTransactionStatus.js +69 -0
- package/lib-es/js-getTransactionStatus.js.map +1 -0
- package/lib-es/js-preload-data.d.ts +7 -0
- package/lib-es/js-preload-data.d.ts.map +1 -0
- package/lib-es/js-preload-data.js +39 -0
- package/lib-es/js-preload-data.js.map +1 -0
- package/lib-es/js-preload.d.ts +7 -0
- package/lib-es/js-preload.d.ts.map +1 -0
- package/lib-es/js-preload.js +62 -0
- package/lib-es/js-preload.js.map +1 -0
- package/lib-es/js-preload.test.d.ts +2 -0
- package/lib-es/js-preload.test.d.ts.map +1 -0
- package/lib-es/js-preload.test.js +7 -0
- package/lib-es/js-preload.test.js.map +1 -0
- package/lib-es/js-prepareTransaction.d.ts +5 -0
- package/lib-es/js-prepareTransaction.d.ts.map +1 -0
- package/lib-es/js-prepareTransaction.js +497 -0
- package/lib-es/js-prepareTransaction.js.map +1 -0
- package/lib-es/js-signOperation.d.ts +7 -0
- package/lib-es/js-signOperation.d.ts.map +1 -0
- package/lib-es/js-signOperation.js +146 -0
- package/lib-es/js-signOperation.js.map +1 -0
- package/lib-es/js-synchronization.d.ts +5 -0
- package/lib-es/js-synchronization.d.ts.map +1 -0
- package/lib-es/js-synchronization.js +457 -0
- package/lib-es/js-synchronization.js.map +1 -0
- package/lib-es/logic.d.ts +29 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +87 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/serialization.d.ts +9 -0
- package/lib-es/serialization.d.ts.map +1 -0
- package/lib-es/serialization.js +60 -0
- package/lib-es/serialization.js.map +1 -0
- package/lib-es/signer.d.ts +11 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +7 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +404 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +8 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +211 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/transaction.d.ts +15 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +147 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/tx-fees.d.ts +4 -0
- package/lib-es/tx-fees.d.ts.map +1 -0
- package/lib-es/tx-fees.js +160 -0
- package/lib-es/tx-fees.js.map +1 -0
- package/lib-es/types.d.ts +222 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +2 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/utils.d.ts +24 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +157 -0
- package/lib-es/utils.js.map +1 -0
- package/lib-es/validator-app/index.d.ts +22 -0
- package/lib-es/validator-app/index.d.ts.map +1 -0
- package/lib-es/validator-app/index.js +55 -0
- package/lib-es/validator-app/index.js.map +1 -0
- package/package.json +89 -0
- package/src/api/cached.ts +87 -0
- package/src/api/chain/account/index.ts +1 -0
- package/src/api/chain/account/parser.ts +63 -0
- package/src/api/chain/account/stake.ts +45 -0
- package/src/api/chain/account/token.ts +63 -0
- package/src/api/chain/account/vote.ts +55 -0
- package/src/api/chain/index.ts +203 -0
- package/src/api/chain/instruction/associated-token-account/index.ts +33 -0
- package/src/api/chain/instruction/associated-token-account/types.ts +23 -0
- package/src/api/chain/instruction/memo/index.ts +24 -0
- package/src/api/chain/instruction/memo/types.ts +18 -0
- package/src/api/chain/instruction/stake/index.ts +29 -0
- package/src/api/chain/instruction/stake/types.ts +95 -0
- package/src/api/chain/instruction/system/index.ts +30 -0
- package/src/api/chain/instruction/system/types.ts +141 -0
- package/src/api/chain/instruction/token/index.ts +30 -0
- package/src/api/chain/instruction/token/types.ts +222 -0
- package/src/api/chain/program/constants.ts +10 -0
- package/src/api/chain/program/index.ts +1 -0
- package/src/api/chain/program/parser.ts +120 -0
- package/src/api/chain/validators/bignum.ts +7 -0
- package/src/api/chain/validators/index.ts +9 -0
- package/src/api/chain/validators/pubkey.ts +8 -0
- package/src/api/chain/web3.ts +399 -0
- package/src/api/index.ts +4 -0
- package/src/api/logged.ts +70 -0
- package/src/api/queued.ts +25 -0
- package/src/api/traced.ts +89 -0
- package/src/bridge/bridge.ts +195 -0
- package/src/bridge/js.ts +44 -0
- package/src/bridge.integration.test.ts +1106 -0
- package/src/cli-transaction.ts +246 -0
- package/src/datasets/solana.scanAccounts.1.ts +9 -0
- package/src/deviceTransactionConfig.ts +302 -0
- package/src/errors.ts +61 -0
- package/src/hw-getAddress.ts +26 -0
- package/src/js-broadcast.ts +38 -0
- package/src/js-buildTransaction.ts +81 -0
- package/src/js-createTransaction.ts +20 -0
- package/src/js-estimateMaxSpendable.ts +72 -0
- package/src/js-getTransactionStatus.ts +72 -0
- package/src/js-preload-data.ts +46 -0
- package/src/js-preload.test.ts +14 -0
- package/src/js-preload.ts +74 -0
- package/src/js-prepareTransaction.ts +686 -0
- package/src/js-signOperation.ts +329 -0
- package/src/js-synchronization.ts +729 -0
- package/src/logic.ts +123 -0
- package/src/serialization.ts +81 -0
- package/src/signer.ts +21 -0
- package/src/specs.ts +514 -0
- package/src/speculos-deviceActions.ts +229 -0
- package/src/transaction.ts +194 -0
- package/src/tx-fees.ts +206 -0
- package/src/types.ts +284 -0
- package/src/utils.ts +176 -0
- package/src/validator-app/index.ts +79 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
|
|
2
|
+
import type { Transaction } from "./types";
|
|
3
|
+
import {
|
|
4
|
+
deviceActionFlow,
|
|
5
|
+
formatDeviceAmount,
|
|
6
|
+
SpeculosButton,
|
|
7
|
+
} from "@ledgerhq/coin-framework/bot/specs";
|
|
8
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
9
|
+
import BigNumber from "bignumber.js";
|
|
10
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
11
|
+
|
|
12
|
+
function getMainCurrency(currency: CryptoCurrency) {
|
|
13
|
+
if (currency.isTestnetFor !== undefined) {
|
|
14
|
+
return getCryptoCurrencyById(currency.isTestnetFor);
|
|
15
|
+
}
|
|
16
|
+
return currency;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function ellipsis(str: string) {
|
|
20
|
+
return `${str.slice(0, 7)}..${str.slice(-7)}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function formatAmount(c: CryptoCurrency, amount: number) {
|
|
24
|
+
const currency = getMainCurrency(c);
|
|
25
|
+
return formatDeviceAmount(currency, new BigNumber(amount), {
|
|
26
|
+
postfixCode: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const acceptTransferTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
31
|
+
steps: [
|
|
32
|
+
{
|
|
33
|
+
title: "Transfer",
|
|
34
|
+
button: SpeculosButton.RIGHT,
|
|
35
|
+
expectedValue: ({ account, transaction }) => {
|
|
36
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
37
|
+
if (command?.kind === "transfer") {
|
|
38
|
+
return formatAmount(account.currency, command.amount);
|
|
39
|
+
}
|
|
40
|
+
throwUnexpectedTransaction();
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
title: "Recipient",
|
|
45
|
+
button: SpeculosButton.RIGHT,
|
|
46
|
+
expectedValue: ({ transaction }) => {
|
|
47
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
48
|
+
if (command?.kind === "transfer") {
|
|
49
|
+
return ellipsis(command.recipient);
|
|
50
|
+
}
|
|
51
|
+
throwUnexpectedTransaction();
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
title: "Approve",
|
|
56
|
+
button: SpeculosButton.BOTH,
|
|
57
|
+
final: true,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const acceptStakeCreateAccountTransaction: DeviceAction<Transaction, any> = deviceActionFlow(
|
|
63
|
+
{
|
|
64
|
+
steps: [
|
|
65
|
+
{
|
|
66
|
+
title: "Delegate from",
|
|
67
|
+
button: SpeculosButton.RIGHT,
|
|
68
|
+
expectedValue: ({ transaction }) => {
|
|
69
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
70
|
+
if (command?.kind === "stake.createAccount") {
|
|
71
|
+
return ellipsis(command.stakeAccAddress);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throwUnexpectedTransaction();
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
title: "Deposit",
|
|
79
|
+
button: SpeculosButton.RIGHT,
|
|
80
|
+
expectedValue: ({ account, transaction }) => {
|
|
81
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
82
|
+
if (command?.kind === "stake.createAccount") {
|
|
83
|
+
return formatAmount(
|
|
84
|
+
account.currency,
|
|
85
|
+
command.amount + command.stakeAccRentExemptAmount,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
throwUnexpectedTransaction();
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
title: "New authority",
|
|
94
|
+
button: SpeculosButton.RIGHT,
|
|
95
|
+
expectedValue: ({ transaction }) => {
|
|
96
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
97
|
+
if (command?.kind === "stake.createAccount") {
|
|
98
|
+
return ellipsis(command.fromAccAddress);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
throwUnexpectedTransaction();
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
title: "Vote account",
|
|
106
|
+
button: SpeculosButton.RIGHT,
|
|
107
|
+
expectedValue: ({ transaction }) => {
|
|
108
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
109
|
+
if (command?.kind === "stake.createAccount") {
|
|
110
|
+
return ellipsis(command.delegate.voteAccAddress);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
throwUnexpectedTransaction();
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
title: "Approve",
|
|
118
|
+
button: SpeculosButton.BOTH,
|
|
119
|
+
final: true,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
export const acceptStakeDelegateTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
126
|
+
steps: [
|
|
127
|
+
{
|
|
128
|
+
title: "Delegate from",
|
|
129
|
+
button: SpeculosButton.RIGHT,
|
|
130
|
+
expectedValue: ({ transaction }) => {
|
|
131
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
132
|
+
if (command?.kind === "stake.delegate") {
|
|
133
|
+
return ellipsis(command.stakeAccAddr);
|
|
134
|
+
}
|
|
135
|
+
throwUnexpectedTransaction();
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
title: "Vote account",
|
|
140
|
+
button: SpeculosButton.RIGHT,
|
|
141
|
+
expectedValue: ({ transaction }) => {
|
|
142
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
143
|
+
if (command?.kind === "stake.delegate") {
|
|
144
|
+
return ellipsis(command.voteAccAddr);
|
|
145
|
+
}
|
|
146
|
+
throwUnexpectedTransaction();
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
title: "Approve",
|
|
151
|
+
button: SpeculosButton.BOTH,
|
|
152
|
+
final: true,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
export const acceptStakeUndelegateTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
158
|
+
steps: [
|
|
159
|
+
{
|
|
160
|
+
title: "Deactivate stake",
|
|
161
|
+
button: SpeculosButton.RIGHT,
|
|
162
|
+
expectedValue: ({ transaction }) => {
|
|
163
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
164
|
+
if (command?.kind === "stake.undelegate") {
|
|
165
|
+
return ellipsis(command.stakeAccAddr);
|
|
166
|
+
}
|
|
167
|
+
throwUnexpectedTransaction();
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
title: "Approve",
|
|
172
|
+
button: SpeculosButton.BOTH,
|
|
173
|
+
final: true,
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
export const acceptStakeWithdrawTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
179
|
+
steps: [
|
|
180
|
+
{
|
|
181
|
+
title: "Stake withdraw",
|
|
182
|
+
button: SpeculosButton.RIGHT,
|
|
183
|
+
expectedValue: ({ account, transaction }) => {
|
|
184
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
185
|
+
|
|
186
|
+
if (command?.kind === "stake.withdraw") {
|
|
187
|
+
return formatAmount(account.currency, command.amount);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
throwUnexpectedTransaction();
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
title: "From",
|
|
195
|
+
button: SpeculosButton.RIGHT,
|
|
196
|
+
expectedValue: ({ transaction }) => {
|
|
197
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
198
|
+
|
|
199
|
+
if (command?.kind === "stake.withdraw") {
|
|
200
|
+
return ellipsis(command.stakeAccAddr);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
throwUnexpectedTransaction();
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
title: "To",
|
|
208
|
+
button: SpeculosButton.RIGHT,
|
|
209
|
+
expectedValue: ({ transaction }) => {
|
|
210
|
+
const command = transaction.model.commandDescriptor?.command;
|
|
211
|
+
|
|
212
|
+
if (command?.kind === "stake.withdraw") {
|
|
213
|
+
return ellipsis(command.toAccAddr);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
throwUnexpectedTransaction();
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
title: "Approve",
|
|
221
|
+
button: SpeculosButton.BOTH,
|
|
222
|
+
final: true,
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
function throwUnexpectedTransaction(): never {
|
|
228
|
+
throw new Error("unexpected or unprepared transaction");
|
|
229
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type {
|
|
3
|
+
Command,
|
|
4
|
+
StakeCreateAccountCommand,
|
|
5
|
+
StakeDelegateCommand,
|
|
6
|
+
StakeSplitCommand,
|
|
7
|
+
StakeUndelegateCommand,
|
|
8
|
+
StakeWithdrawCommand,
|
|
9
|
+
TokenCreateATACommand,
|
|
10
|
+
TokenTransferCommand,
|
|
11
|
+
Transaction,
|
|
12
|
+
TransactionRaw,
|
|
13
|
+
TransferCommand,
|
|
14
|
+
} from "./types";
|
|
15
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
16
|
+
import {
|
|
17
|
+
fromTransactionCommonRaw,
|
|
18
|
+
fromTransactionStatusRawCommon as fromTransactionStatusRaw,
|
|
19
|
+
toTransactionCommonRaw,
|
|
20
|
+
toTransactionStatusRawCommon as toTransactionStatusRaw,
|
|
21
|
+
} from "@ledgerhq/coin-framework/serialization";
|
|
22
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
23
|
+
import { findSubAccountById, getAccountUnit } from "@ledgerhq/coin-framework/account/index";
|
|
24
|
+
import { formatCurrencyUnit, getTokenById } from "@ledgerhq/coin-framework/currencies/index";
|
|
25
|
+
import { assertUnreachable } from "./utils";
|
|
26
|
+
import { toTokenId } from "./logic";
|
|
27
|
+
|
|
28
|
+
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
29
|
+
const common = fromTransactionCommonRaw(tr);
|
|
30
|
+
const { family, model } = tr;
|
|
31
|
+
return {
|
|
32
|
+
...common,
|
|
33
|
+
family,
|
|
34
|
+
model: JSON.parse(model),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
39
|
+
const common = toTransactionCommonRaw(t);
|
|
40
|
+
const { family, model } = t;
|
|
41
|
+
return {
|
|
42
|
+
...common,
|
|
43
|
+
family,
|
|
44
|
+
model: JSON.stringify(model),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const lamportsToSOL = (account: Account, amount: number) => {
|
|
49
|
+
return formatCurrencyUnit(getAccountUnit(account), new BigNumber(amount), {
|
|
50
|
+
showCode: true,
|
|
51
|
+
disableRounding: true,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const formatTransaction = (tx: Transaction, mainAccount: Account): string => {
|
|
56
|
+
if (tx.model.commandDescriptor === undefined) {
|
|
57
|
+
throw new Error("can not format unprepared transaction");
|
|
58
|
+
}
|
|
59
|
+
const { commandDescriptor } = tx.model;
|
|
60
|
+
|
|
61
|
+
if (Object.keys(commandDescriptor.errors).length > 0) {
|
|
62
|
+
throw new Error("can not format invalid transaction");
|
|
63
|
+
}
|
|
64
|
+
return formatCommand(mainAccount, tx, commandDescriptor.command);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function formatCommand(mainAccount: Account, tx: Transaction, command: Command) {
|
|
68
|
+
switch (command.kind) {
|
|
69
|
+
case "transfer":
|
|
70
|
+
return formatTransfer(mainAccount, tx, command);
|
|
71
|
+
case "token.transfer":
|
|
72
|
+
return formatTokenTransfer(mainAccount, tx, command);
|
|
73
|
+
case "token.createATA":
|
|
74
|
+
return formatCreateATA(command);
|
|
75
|
+
case "stake.createAccount":
|
|
76
|
+
return formatStakeCreateAccount(mainAccount, tx, command);
|
|
77
|
+
case "stake.delegate":
|
|
78
|
+
return formatStakeDelegate(command);
|
|
79
|
+
case "stake.undelegate":
|
|
80
|
+
return formatStakeUndelegate(command);
|
|
81
|
+
case "stake.withdraw":
|
|
82
|
+
return formatStakeWithdraw(mainAccount, tx, command);
|
|
83
|
+
case "stake.split":
|
|
84
|
+
return formatStakeSplit(mainAccount, tx, command);
|
|
85
|
+
default:
|
|
86
|
+
return assertUnreachable(command);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function formatStakeCreateAccount(
|
|
91
|
+
mainAccount: Account,
|
|
92
|
+
tx: Transaction,
|
|
93
|
+
command: StakeCreateAccountCommand,
|
|
94
|
+
) {
|
|
95
|
+
const amount = lamportsToSOL(mainAccount, command.amount + command.stakeAccRentExemptAmount);
|
|
96
|
+
const str = [
|
|
97
|
+
` CREATE STAKE ACCOUNT: ${command.stakeAccAddress}`,
|
|
98
|
+
` FROM: ${command.fromAccAddress}`,
|
|
99
|
+
` AMOUNT: ${amount}${tx.useAllAmount ? " (ALL)" : ""}`,
|
|
100
|
+
` SEED: ${command.seed}`,
|
|
101
|
+
` VALIDATOR: ${command.delegate.voteAccAddress}`,
|
|
102
|
+
]
|
|
103
|
+
.filter(Boolean)
|
|
104
|
+
.join("\n");
|
|
105
|
+
|
|
106
|
+
return "\n" + str;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function formatTransfer(mainAccount: Account, tx: Transaction, command: TransferCommand) {
|
|
110
|
+
const amount = lamportsToSOL(mainAccount, command.amount);
|
|
111
|
+
const str = [
|
|
112
|
+
` SEND: ${amount}${tx.useAllAmount ? " (ALL)" : ""}`,
|
|
113
|
+
` TO: ${command.recipient}`,
|
|
114
|
+
command.memo ? ` MEMO: ${command.memo}` : "",
|
|
115
|
+
]
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.join("\n");
|
|
118
|
+
|
|
119
|
+
return "\n" + str;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function formatTokenTransfer(mainAccount: Account, tx: Transaction, command: TokenTransferCommand) {
|
|
123
|
+
if (!tx.subAccountId) {
|
|
124
|
+
throw new Error("expected subaccountId on transaction");
|
|
125
|
+
}
|
|
126
|
+
const subAccount = findSubAccountById(mainAccount, tx.subAccountId);
|
|
127
|
+
if (!subAccount || subAccount.type !== "TokenAccount") {
|
|
128
|
+
throw new Error("token subaccount expected");
|
|
129
|
+
}
|
|
130
|
+
const amount = formatCurrencyUnit(getAccountUnit(subAccount), new BigNumber(command.amount), {
|
|
131
|
+
showCode: true,
|
|
132
|
+
disableRounding: true,
|
|
133
|
+
});
|
|
134
|
+
const recipient = command.recipientDescriptor.walletAddress;
|
|
135
|
+
const str = [
|
|
136
|
+
` SEND: ${amount}${tx.useAllAmount ? " (ALL)" : ""}`,
|
|
137
|
+
` TO: ${recipient}`,
|
|
138
|
+
command.memo ? ` MEMO: ${command.memo}` : "",
|
|
139
|
+
]
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.join("\n");
|
|
142
|
+
return "\n" + str;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function formatCreateATA(command: TokenCreateATACommand) {
|
|
146
|
+
const token = getTokenById(toTokenId(command.mint));
|
|
147
|
+
const str = [` OPT IN TOKEN: ${token.ticker}`].filter(Boolean).join("\n");
|
|
148
|
+
return "\n" + str;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function formatStakeDelegate(command: StakeDelegateCommand) {
|
|
152
|
+
const str = [` DELEGATE: ${command.stakeAccAddr}`, ` TO: ${command.voteAccAddr}`]
|
|
153
|
+
.filter(Boolean)
|
|
154
|
+
.join("\n");
|
|
155
|
+
return "\n" + str;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function formatStakeUndelegate(command: StakeUndelegateCommand) {
|
|
159
|
+
const str = [` UNDELEGATE: ${command.stakeAccAddr}`].filter(Boolean).join("\n");
|
|
160
|
+
return "\n" + str;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function formatStakeWithdraw(mainAccount: Account, tx: Transaction, command: StakeWithdrawCommand) {
|
|
164
|
+
const amount = lamportsToSOL(mainAccount, command.amount);
|
|
165
|
+
const str = [
|
|
166
|
+
` WITHDRAW FROM: ${command.stakeAccAddr}`,
|
|
167
|
+
` AMOUNT: ${amount}${tx.useAllAmount ? " (ALL)" : ""}`,
|
|
168
|
+
` TO: ${command.toAccAddr}`,
|
|
169
|
+
]
|
|
170
|
+
.filter(Boolean)
|
|
171
|
+
.join("\n");
|
|
172
|
+
return "\n" + str;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function formatStakeSplit(mainAccount: Account, tx: Transaction, command: StakeSplitCommand) {
|
|
176
|
+
const amount = lamportsToSOL(mainAccount, command.amount);
|
|
177
|
+
const str = [
|
|
178
|
+
` SPLIT: ${command.stakeAccAddr}`,
|
|
179
|
+
` AMOUNT: ${amount}${tx.useAllAmount ? " (ALL)" : ""}`,
|
|
180
|
+
` TO: ${command.splitStakeAccAddr}`,
|
|
181
|
+
]
|
|
182
|
+
.filter(Boolean)
|
|
183
|
+
.join("\n");
|
|
184
|
+
return "\n" + str;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export default {
|
|
188
|
+
formatTransaction,
|
|
189
|
+
fromTransactionRaw,
|
|
190
|
+
toTransactionRaw,
|
|
191
|
+
fromTransactionStatusRaw,
|
|
192
|
+
toTransactionStatusRaw,
|
|
193
|
+
formatTransactionStatus,
|
|
194
|
+
};
|
package/src/tx-fees.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { ChainAPI } from "./api";
|
|
2
|
+
import { buildTransactionWithAPI } from "./js-buildTransaction";
|
|
3
|
+
import createTransaction from "./js-createTransaction";
|
|
4
|
+
import { Transaction, TransactionModel } from "./types";
|
|
5
|
+
import { assertUnreachable } from "./utils";
|
|
6
|
+
import { VersionedTransaction as OnChainTransaction } from "@solana/web3.js";
|
|
7
|
+
import { log } from "@ledgerhq/logs";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_TX_FEE = 5000;
|
|
10
|
+
|
|
11
|
+
export async function estimateTxFee(
|
|
12
|
+
api: ChainAPI,
|
|
13
|
+
address: string,
|
|
14
|
+
kind: TransactionModel["kind"],
|
|
15
|
+
) {
|
|
16
|
+
const tx = createDummyTx(address, kind);
|
|
17
|
+
const [onChainTx] = await buildTransactionWithAPI(address, tx, api);
|
|
18
|
+
|
|
19
|
+
let fee = await api.getFeeForMessage(onChainTx.message);
|
|
20
|
+
|
|
21
|
+
if (typeof fee !== "number") {
|
|
22
|
+
// Sometimes getFeeForMessage doesn't return valid fees, because onChainTx.message.recentBlockhash
|
|
23
|
+
// is outdated --> retrying with a next blockhash
|
|
24
|
+
log("debug", `Solana api.getFeeForMessage returned invalid fee: <${fee}>`);
|
|
25
|
+
fee = await retryWithNewBlockhash(api, onChainTx);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof fee !== "number") {
|
|
29
|
+
log(
|
|
30
|
+
"error",
|
|
31
|
+
`Solana unexpected fee: <${fee}>, after retry with a new blockhash. Fallback to the default.`,
|
|
32
|
+
);
|
|
33
|
+
// If still failing, fallback to a default fees value
|
|
34
|
+
fee = DEFAULT_TX_FEE;
|
|
35
|
+
}
|
|
36
|
+
return fee;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const createDummyTx = (address: string, kind: TransactionModel["kind"]) => {
|
|
40
|
+
switch (kind) {
|
|
41
|
+
case "transfer":
|
|
42
|
+
return createDummyTransferTx(address);
|
|
43
|
+
case "stake.createAccount":
|
|
44
|
+
return createDummyStakeCreateAccountTx(address);
|
|
45
|
+
case "stake.delegate":
|
|
46
|
+
return createDummyStakeDelegateTx(address);
|
|
47
|
+
case "stake.undelegate":
|
|
48
|
+
return createDummyStakeUndelegateTx(address);
|
|
49
|
+
case "stake.withdraw":
|
|
50
|
+
return createDummyStakeWithdrawTx(address);
|
|
51
|
+
case "stake.split":
|
|
52
|
+
case "token.createATA":
|
|
53
|
+
case "token.transfer":
|
|
54
|
+
throw new Error(`not implemented for <${kind}>`);
|
|
55
|
+
default:
|
|
56
|
+
return assertUnreachable(kind);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const createDummyTransferTx = (address: string): Transaction => {
|
|
61
|
+
return {
|
|
62
|
+
...createTransaction({} as any),
|
|
63
|
+
model: {
|
|
64
|
+
kind: "transfer",
|
|
65
|
+
uiState: {},
|
|
66
|
+
commandDescriptor: {
|
|
67
|
+
command: {
|
|
68
|
+
kind: "transfer",
|
|
69
|
+
amount: 0,
|
|
70
|
+
recipient: address,
|
|
71
|
+
sender: address,
|
|
72
|
+
},
|
|
73
|
+
...commandDescriptorCommons,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const createDummyStakeCreateAccountTx = (address: string): Transaction => {
|
|
80
|
+
return {
|
|
81
|
+
...createTransaction({} as any),
|
|
82
|
+
model: {
|
|
83
|
+
kind: "stake.createAccount",
|
|
84
|
+
uiState: {} as any,
|
|
85
|
+
commandDescriptor: {
|
|
86
|
+
command: {
|
|
87
|
+
kind: "stake.createAccount",
|
|
88
|
+
amount: 0,
|
|
89
|
+
delegate: {
|
|
90
|
+
voteAccAddress: randomAddresses[0],
|
|
91
|
+
},
|
|
92
|
+
fromAccAddress: address,
|
|
93
|
+
seed: "",
|
|
94
|
+
stakeAccAddress: randomAddresses[1],
|
|
95
|
+
stakeAccRentExemptAmount: 0,
|
|
96
|
+
},
|
|
97
|
+
...commandDescriptorCommons,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const createDummyStakeDelegateTx = (address: string): Transaction => {
|
|
104
|
+
return {
|
|
105
|
+
...createTransaction({} as any),
|
|
106
|
+
model: {
|
|
107
|
+
kind: "stake.delegate",
|
|
108
|
+
uiState: {} as any,
|
|
109
|
+
commandDescriptor: {
|
|
110
|
+
command: {
|
|
111
|
+
kind: "stake.delegate",
|
|
112
|
+
authorizedAccAddr: address,
|
|
113
|
+
stakeAccAddr: randomAddresses[0],
|
|
114
|
+
voteAccAddr: randomAddresses[1],
|
|
115
|
+
},
|
|
116
|
+
...commandDescriptorCommons,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const createDummyStakeUndelegateTx = (address: string): Transaction => {
|
|
123
|
+
return {
|
|
124
|
+
...createTransaction({} as any),
|
|
125
|
+
model: {
|
|
126
|
+
kind: "stake.undelegate",
|
|
127
|
+
uiState: {} as any,
|
|
128
|
+
commandDescriptor: {
|
|
129
|
+
command: {
|
|
130
|
+
kind: "stake.undelegate",
|
|
131
|
+
authorizedAccAddr: address,
|
|
132
|
+
stakeAccAddr: randomAddresses[0],
|
|
133
|
+
},
|
|
134
|
+
...commandDescriptorCommons,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const createDummyStakeWithdrawTx = (address: string): Transaction => {
|
|
141
|
+
return {
|
|
142
|
+
...createTransaction({} as any),
|
|
143
|
+
model: {
|
|
144
|
+
kind: "stake.withdraw",
|
|
145
|
+
uiState: {} as any,
|
|
146
|
+
commandDescriptor: {
|
|
147
|
+
command: {
|
|
148
|
+
kind: "stake.withdraw",
|
|
149
|
+
amount: 0,
|
|
150
|
+
authorizedAccAddr: address,
|
|
151
|
+
stakeAccAddr: randomAddresses[0],
|
|
152
|
+
toAccAddr: randomAddresses[1],
|
|
153
|
+
},
|
|
154
|
+
...commandDescriptorCommons,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const commandDescriptorCommons = {
|
|
161
|
+
errors: {},
|
|
162
|
+
fee: 0,
|
|
163
|
+
warnings: {},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// pregenerate for better caching
|
|
167
|
+
const randomAddresses = [
|
|
168
|
+
"HxCvgjSbF8HMt3fj8P3j49jmajNCMwKAqBu79HUDPtkM",
|
|
169
|
+
"AjmMiagw33Ad4WdPR3y2QWsDXaLxmsiSZEpMfpT1Q9uZ",
|
|
170
|
+
"AVHhsobqNw3b3XD43fz7Crq3d3UxFYZfHAByh7ogZoeN",
|
|
171
|
+
"FvbvvXMY4Rf1AtGG7UHJUesjt8FFgPnPy6o83Dna9mXK",
|
|
172
|
+
"AEtRo9MKfLqGtjvxdz8H93R7SQxXLEkibVSJbs9XKnD1",
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
async function retryWithNewBlockhash(api: ChainAPI, onChainTx: OnChainTransaction) {
|
|
176
|
+
if (onChainTx.message.recentBlockhash === undefined) {
|
|
177
|
+
throw new Error("expected recentBlockhash");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
onChainTx.message.recentBlockhash = await waitNextBlockhash(
|
|
181
|
+
api,
|
|
182
|
+
onChainTx.message.recentBlockhash,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
return api.getFeeForMessage(onChainTx.message);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function sleep(durationMS: number): Promise<void> {
|
|
189
|
+
return new Promise(res => setTimeout(res, durationMS));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function waitNextBlockhash(api: ChainAPI, currentBlockhash: string) {
|
|
193
|
+
const sleepTimeMS = 5000;
|
|
194
|
+
for (let i = 0; i < 5; i++) {
|
|
195
|
+
log("info", `sleeping for ${sleepTimeMS} ms, waiting for a new blockhash`);
|
|
196
|
+
await sleep(sleepTimeMS);
|
|
197
|
+
const blockhash = await api.getLatestBlockhash();
|
|
198
|
+
if (blockhash !== currentBlockhash) {
|
|
199
|
+
log("info", "got a new blockhash");
|
|
200
|
+
return blockhash;
|
|
201
|
+
}
|
|
202
|
+
log("info", "got same blockhash");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
throw new Error("next blockhash timeout");
|
|
206
|
+
}
|