@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,686 @@
|
|
|
1
|
+
import { getTokenById } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import {
|
|
3
|
+
AmountRequired,
|
|
4
|
+
InvalidAddress,
|
|
5
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
6
|
+
NotEnoughBalance,
|
|
7
|
+
RecipientRequired,
|
|
8
|
+
} from "@ledgerhq/errors";
|
|
9
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
10
|
+
import { findSubAccountById } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { ChainAPI } from "./api";
|
|
12
|
+
import {
|
|
13
|
+
getMaybeTokenAccount,
|
|
14
|
+
getMaybeVoteAccount,
|
|
15
|
+
getStakeAccountAddressWithSeed,
|
|
16
|
+
getStakeAccountMinimumBalanceForRentExemption,
|
|
17
|
+
} from "./api/chain/web3";
|
|
18
|
+
import {
|
|
19
|
+
SolanaAccountNotFunded,
|
|
20
|
+
SolanaAddressOffEd25519,
|
|
21
|
+
SolanaInvalidValidator,
|
|
22
|
+
SolanaMemoIsTooLong,
|
|
23
|
+
SolanaRecipientAssociatedTokenAccountWillBeFunded,
|
|
24
|
+
SolanaStakeAccountIsNotDelegatable,
|
|
25
|
+
SolanaStakeAccountIsNotUndelegatable,
|
|
26
|
+
SolanaStakeAccountNotFound,
|
|
27
|
+
SolanaStakeAccountNothingToWithdraw,
|
|
28
|
+
SolanaStakeAccountRequired,
|
|
29
|
+
SolanaStakeAccountValidatorIsUnchangeable,
|
|
30
|
+
SolanaStakeNoStakeAuth,
|
|
31
|
+
SolanaStakeNoWithdrawAuth,
|
|
32
|
+
SolanaTokenAccounNotInitialized,
|
|
33
|
+
SolanaTokenAccountHoldsAnotherToken,
|
|
34
|
+
SolanaTokenRecipientIsSenderATA,
|
|
35
|
+
SolanaValidatorRequired,
|
|
36
|
+
} from "./errors";
|
|
37
|
+
import {
|
|
38
|
+
decodeAccountIdWithTokenAccountAddress,
|
|
39
|
+
isEd25519Address,
|
|
40
|
+
isValidBase58Address,
|
|
41
|
+
MAX_MEMO_LENGTH,
|
|
42
|
+
} from "./logic";
|
|
43
|
+
import type {
|
|
44
|
+
CommandDescriptor,
|
|
45
|
+
SolanaAccount,
|
|
46
|
+
SolanaStake,
|
|
47
|
+
StakeCreateAccountTransaction,
|
|
48
|
+
StakeDelegateTransaction,
|
|
49
|
+
StakeSplitTransaction,
|
|
50
|
+
StakeUndelegateTransaction,
|
|
51
|
+
StakeWithdrawTransaction,
|
|
52
|
+
TokenCreateATATransaction,
|
|
53
|
+
TokenRecipientDescriptor,
|
|
54
|
+
TokenTransferTransaction,
|
|
55
|
+
Transaction,
|
|
56
|
+
TransactionModel,
|
|
57
|
+
TransferCommand,
|
|
58
|
+
TransferTransaction,
|
|
59
|
+
} from "./types";
|
|
60
|
+
import { assertUnreachable } from "./utils";
|
|
61
|
+
import { defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
62
|
+
import { estimateFeeAndSpendable } from "./js-estimateMaxSpendable";
|
|
63
|
+
|
|
64
|
+
async function deriveCommandDescriptor(
|
|
65
|
+
mainAccount: SolanaAccount,
|
|
66
|
+
tx: Transaction,
|
|
67
|
+
api: ChainAPI,
|
|
68
|
+
): Promise<CommandDescriptor> {
|
|
69
|
+
const { model } = tx;
|
|
70
|
+
|
|
71
|
+
switch (model.kind) {
|
|
72
|
+
case "transfer":
|
|
73
|
+
return deriveTransferCommandDescriptor(mainAccount, tx, model, api);
|
|
74
|
+
case "token.transfer":
|
|
75
|
+
return deriveTokenTransferCommandDescriptor(mainAccount, tx, model, api);
|
|
76
|
+
case "token.createATA":
|
|
77
|
+
return deriveCreateAssociatedTokenAccountCommandDescriptor(mainAccount, tx, model, api);
|
|
78
|
+
case "stake.createAccount":
|
|
79
|
+
return deriveStakeCreateAccountCommandDescriptor(mainAccount, tx, model, api);
|
|
80
|
+
case "stake.delegate":
|
|
81
|
+
return deriveStakeDelegateCommandDescriptor(mainAccount, tx, model, api);
|
|
82
|
+
case "stake.undelegate":
|
|
83
|
+
return deriveStakeUndelegateCommandDescriptor(mainAccount, tx, model, api);
|
|
84
|
+
case "stake.withdraw":
|
|
85
|
+
return deriveStakeWithdrawCommandDescriptor(mainAccount, tx, model, api);
|
|
86
|
+
case "stake.split":
|
|
87
|
+
return deriveStakeSplitCommandDescriptor(mainAccount, tx, model, api);
|
|
88
|
+
default:
|
|
89
|
+
return assertUnreachable(model);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const prepareTransaction = async (
|
|
94
|
+
mainAccount: SolanaAccount,
|
|
95
|
+
tx: Transaction,
|
|
96
|
+
api: ChainAPI,
|
|
97
|
+
): Promise<Transaction> => {
|
|
98
|
+
const txToDeriveFrom = updateModelIfSubAccountIdPresent(tx);
|
|
99
|
+
|
|
100
|
+
const commandDescriptor = await deriveCommandDescriptor(mainAccount, txToDeriveFrom, api);
|
|
101
|
+
|
|
102
|
+
const model: TransactionModel = {
|
|
103
|
+
...tx.model,
|
|
104
|
+
commandDescriptor,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const patch: Partial<Transaction> = {
|
|
108
|
+
model,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return defaultUpdateTransaction(tx, patch);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const deriveTokenTransferCommandDescriptor = async (
|
|
115
|
+
mainAccount: Account,
|
|
116
|
+
tx: Transaction,
|
|
117
|
+
model: TransactionModel & { kind: TokenTransferTransaction["kind"] },
|
|
118
|
+
api: ChainAPI,
|
|
119
|
+
): Promise<CommandDescriptor> => {
|
|
120
|
+
const errors: Record<string, Error> = {};
|
|
121
|
+
const warnings: Record<string, Error> = {};
|
|
122
|
+
|
|
123
|
+
const subAccount = findSubAccountById(mainAccount, model.uiState.subAccountId);
|
|
124
|
+
|
|
125
|
+
if (!subAccount || subAccount.type !== "TokenAccount") {
|
|
126
|
+
throw new Error("subaccount not found");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
await validateRecipientCommon(mainAccount, tx, errors, warnings, api);
|
|
130
|
+
|
|
131
|
+
const memo = model.uiState.memo;
|
|
132
|
+
|
|
133
|
+
if (typeof memo === "string" && memo.length > 0) {
|
|
134
|
+
validateMemoCommon(memo, errors);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const tokenIdParts = subAccount.token.id.split("/");
|
|
138
|
+
const mintAddress = tokenIdParts[tokenIdParts.length - 1];
|
|
139
|
+
const mintDecimals = subAccount.token.units[0].magnitude;
|
|
140
|
+
|
|
141
|
+
const senderAssociatedTokenAccountAddress = decodeAccountIdWithTokenAccountAddress(
|
|
142
|
+
subAccount.id,
|
|
143
|
+
).address;
|
|
144
|
+
|
|
145
|
+
if (!errors.recipient && tx.recipient === senderAssociatedTokenAccountAddress) {
|
|
146
|
+
errors.recipient = new SolanaTokenRecipientIsSenderATA();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const defaultRecipientDescriptor: TokenRecipientDescriptor = {
|
|
150
|
+
shouldCreateAsAssociatedTokenAccount: false,
|
|
151
|
+
tokenAccAddress: "",
|
|
152
|
+
walletAddress: "",
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const recipientDescriptorOrError = errors.recipient
|
|
156
|
+
? defaultRecipientDescriptor
|
|
157
|
+
: await getTokenRecipient(tx.recipient, mintAddress, api);
|
|
158
|
+
|
|
159
|
+
if (!errors.recipient && recipientDescriptorOrError instanceof Error) {
|
|
160
|
+
errors.recipient = recipientDescriptorOrError;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const recipientDescriptor: TokenRecipientDescriptor =
|
|
164
|
+
recipientDescriptorOrError instanceof Error
|
|
165
|
+
? defaultRecipientDescriptor
|
|
166
|
+
: recipientDescriptorOrError;
|
|
167
|
+
|
|
168
|
+
const assocAccRentExempt = recipientDescriptor.shouldCreateAsAssociatedTokenAccount
|
|
169
|
+
? await api.getAssocTokenAccMinNativeBalance()
|
|
170
|
+
: 0;
|
|
171
|
+
|
|
172
|
+
if (recipientDescriptor.shouldCreateAsAssociatedTokenAccount) {
|
|
173
|
+
warnings.recipient = new SolanaRecipientAssociatedTokenAccountWillBeFunded();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const { fee, spendable: spendableSol } = await estimateFeeAndSpendable(api, mainAccount, tx);
|
|
177
|
+
|
|
178
|
+
if (spendableSol.lt(assocAccRentExempt)) {
|
|
179
|
+
errors.fee = new NotEnoughBalance();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!tx.useAllAmount && tx.amount.lte(0)) {
|
|
183
|
+
errors.amount = new AmountRequired();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const txAmount = tx.useAllAmount ? subAccount.spendableBalance.toNumber() : tx.amount.toNumber();
|
|
187
|
+
|
|
188
|
+
if (!errors.amount && txAmount > subAccount.spendableBalance.toNumber()) {
|
|
189
|
+
errors.amount = new NotEnoughBalance();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
command: {
|
|
194
|
+
kind: "token.transfer",
|
|
195
|
+
ownerAddress: mainAccount.freshAddress,
|
|
196
|
+
ownerAssociatedTokenAccountAddress: senderAssociatedTokenAccountAddress,
|
|
197
|
+
amount: txAmount,
|
|
198
|
+
mintAddress,
|
|
199
|
+
mintDecimals,
|
|
200
|
+
recipientDescriptor: recipientDescriptor,
|
|
201
|
+
memo: model.uiState.memo,
|
|
202
|
+
},
|
|
203
|
+
fee: fee + assocAccRentExempt,
|
|
204
|
+
warnings,
|
|
205
|
+
errors,
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
async function getTokenRecipient(
|
|
210
|
+
recipientAddress: string,
|
|
211
|
+
mintAddress: string,
|
|
212
|
+
api: ChainAPI,
|
|
213
|
+
): Promise<TokenRecipientDescriptor | Error> {
|
|
214
|
+
const recipientTokenAccount = await getMaybeTokenAccount(recipientAddress, api);
|
|
215
|
+
|
|
216
|
+
if (recipientTokenAccount instanceof Error) {
|
|
217
|
+
throw recipientTokenAccount;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (recipientTokenAccount === undefined) {
|
|
221
|
+
if (!isEd25519Address(recipientAddress)) {
|
|
222
|
+
return new SolanaAddressOffEd25519();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const recipientAssociatedTokenAccountAddress = await api.findAssocTokenAccAddress(
|
|
226
|
+
recipientAddress,
|
|
227
|
+
mintAddress,
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
const shouldCreateAsAssociatedTokenAccount = !(await isAccountFunded(
|
|
231
|
+
recipientAssociatedTokenAccountAddress,
|
|
232
|
+
api,
|
|
233
|
+
));
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
walletAddress: recipientAddress,
|
|
237
|
+
shouldCreateAsAssociatedTokenAccount,
|
|
238
|
+
tokenAccAddress: recipientAssociatedTokenAccountAddress,
|
|
239
|
+
};
|
|
240
|
+
} else {
|
|
241
|
+
if (recipientTokenAccount.mint.toBase58() !== mintAddress) {
|
|
242
|
+
return new SolanaTokenAccountHoldsAnotherToken();
|
|
243
|
+
}
|
|
244
|
+
if (recipientTokenAccount.state !== "initialized") {
|
|
245
|
+
return new SolanaTokenAccounNotInitialized();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
walletAddress: recipientTokenAccount.owner.toBase58(),
|
|
251
|
+
shouldCreateAsAssociatedTokenAccount: false,
|
|
252
|
+
tokenAccAddress: recipientAddress,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function deriveCreateAssociatedTokenAccountCommandDescriptor(
|
|
257
|
+
mainAccount: Account,
|
|
258
|
+
tx: Transaction,
|
|
259
|
+
model: TransactionModel & { kind: TokenCreateATATransaction["kind"] },
|
|
260
|
+
api: ChainAPI,
|
|
261
|
+
): Promise<CommandDescriptor> {
|
|
262
|
+
const errors: Record<string, Error> = {};
|
|
263
|
+
|
|
264
|
+
const token = getTokenById(model.uiState.tokenId);
|
|
265
|
+
const tokenIdParts = token.id.split("/");
|
|
266
|
+
const mint = tokenIdParts[tokenIdParts.length - 1];
|
|
267
|
+
|
|
268
|
+
const associatedTokenAccountAddress = await api.findAssocTokenAccAddress(
|
|
269
|
+
mainAccount.freshAddress,
|
|
270
|
+
mint,
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const { fee } = await estimateFeeAndSpendable(api, mainAccount, tx);
|
|
274
|
+
|
|
275
|
+
if (mainAccount.spendableBalance.lt(fee)) {
|
|
276
|
+
errors.fee = new NotEnoughBalance();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
fee,
|
|
281
|
+
command: {
|
|
282
|
+
kind: model.kind,
|
|
283
|
+
mint: mint,
|
|
284
|
+
owner: mainAccount.freshAddress,
|
|
285
|
+
associatedTokenAccountAddress,
|
|
286
|
+
},
|
|
287
|
+
warnings: {},
|
|
288
|
+
errors,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async function deriveTransferCommandDescriptor(
|
|
293
|
+
mainAccount: Account,
|
|
294
|
+
tx: Transaction,
|
|
295
|
+
model: TransactionModel & { kind: TransferTransaction["kind"] },
|
|
296
|
+
api: ChainAPI,
|
|
297
|
+
): Promise<CommandDescriptor> {
|
|
298
|
+
const errors: Record<string, Error> = {};
|
|
299
|
+
const warnings: Record<string, Error> = {};
|
|
300
|
+
|
|
301
|
+
await validateRecipientCommon(mainAccount, tx, errors, warnings, api);
|
|
302
|
+
|
|
303
|
+
const memo = model.uiState.memo;
|
|
304
|
+
|
|
305
|
+
if (typeof memo === "string" && memo.length > 0) {
|
|
306
|
+
validateMemoCommon(memo, errors);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const { fee, spendable } = await estimateFeeAndSpendable(api, mainAccount, tx);
|
|
310
|
+
const txAmount = tx.useAllAmount ? spendable : tx.amount;
|
|
311
|
+
|
|
312
|
+
if (tx.useAllAmount) {
|
|
313
|
+
if (txAmount.eq(0)) {
|
|
314
|
+
errors.amount = new NotEnoughBalance();
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
if (txAmount.lte(0)) {
|
|
318
|
+
errors.amount = new AmountRequired();
|
|
319
|
+
} else if (txAmount.gt(spendable)) {
|
|
320
|
+
errors.amount = new NotEnoughBalance();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const command: TransferCommand = {
|
|
325
|
+
kind: "transfer",
|
|
326
|
+
amount: txAmount.toNumber(),
|
|
327
|
+
sender: mainAccount.freshAddress,
|
|
328
|
+
recipient: tx.recipient,
|
|
329
|
+
memo: model.uiState.memo,
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
return {
|
|
333
|
+
command,
|
|
334
|
+
fee,
|
|
335
|
+
warnings,
|
|
336
|
+
errors,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async function deriveStakeCreateAccountCommandDescriptor(
|
|
341
|
+
mainAccount: Account,
|
|
342
|
+
tx: Transaction,
|
|
343
|
+
model: TransactionModel & { kind: StakeCreateAccountTransaction["kind"] },
|
|
344
|
+
api: ChainAPI,
|
|
345
|
+
): Promise<CommandDescriptor> {
|
|
346
|
+
const errors: Record<string, Error> = {};
|
|
347
|
+
const warnings: Record<string, Error> = {};
|
|
348
|
+
|
|
349
|
+
const { fee, spendable } = await estimateFeeAndSpendable(api, mainAccount, tx);
|
|
350
|
+
const txAmount = tx.useAllAmount ? spendable : tx.amount;
|
|
351
|
+
|
|
352
|
+
if (tx.useAllAmount) {
|
|
353
|
+
if (txAmount.eq(0)) {
|
|
354
|
+
errors.amount = new NotEnoughBalance();
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
if (txAmount.lte(0)) {
|
|
358
|
+
errors.amount = new AmountRequired();
|
|
359
|
+
} else if (txAmount.gt(spendable)) {
|
|
360
|
+
errors.amount = new NotEnoughBalance();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const {
|
|
365
|
+
uiState: { delegate },
|
|
366
|
+
} = model;
|
|
367
|
+
|
|
368
|
+
await validateValidatorCommon(delegate.voteAccAddress, errors, api);
|
|
369
|
+
|
|
370
|
+
const stakeAccAddressSeed = `stake:${Math.random().toString()}`;
|
|
371
|
+
const stakeAccAddress = await getStakeAccountAddressWithSeed({
|
|
372
|
+
fromAddress: mainAccount.freshAddress,
|
|
373
|
+
seed: stakeAccAddressSeed,
|
|
374
|
+
});
|
|
375
|
+
const stakeAccRentExemptAmount = await getStakeAccountMinimumBalanceForRentExemption(api);
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
command: {
|
|
379
|
+
kind: "stake.createAccount",
|
|
380
|
+
amount: txAmount.toNumber(),
|
|
381
|
+
stakeAccRentExemptAmount,
|
|
382
|
+
fromAccAddress: mainAccount.freshAddress,
|
|
383
|
+
stakeAccAddress,
|
|
384
|
+
delegate,
|
|
385
|
+
seed: stakeAccAddressSeed,
|
|
386
|
+
},
|
|
387
|
+
fee,
|
|
388
|
+
warnings,
|
|
389
|
+
errors,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
async function deriveStakeDelegateCommandDescriptor(
|
|
394
|
+
mainAccount: SolanaAccount,
|
|
395
|
+
tx: Transaction,
|
|
396
|
+
model: TransactionModel & { kind: StakeDelegateTransaction["kind"] },
|
|
397
|
+
api: ChainAPI,
|
|
398
|
+
): Promise<CommandDescriptor> {
|
|
399
|
+
const errors: Record<string, Error> = {};
|
|
400
|
+
|
|
401
|
+
const { uiState } = model;
|
|
402
|
+
|
|
403
|
+
const stake = validateAndTryGetStakeAccount(mainAccount, uiState.stakeAccAddr, errors);
|
|
404
|
+
|
|
405
|
+
if (stake !== undefined && !stake.hasStakeAuth && !stake.hasWithdrawAuth) {
|
|
406
|
+
errors.stakeAccAddr = new SolanaStakeNoStakeAuth();
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
await validateValidatorCommon(uiState.voteAccAddr, errors, api);
|
|
410
|
+
|
|
411
|
+
if (!errors.voteAccAddr && stake !== undefined) {
|
|
412
|
+
switch (stake.activation.state) {
|
|
413
|
+
case "active":
|
|
414
|
+
case "activating":
|
|
415
|
+
errors.stakeAccAddr = new SolanaStakeAccountIsNotDelegatable();
|
|
416
|
+
break;
|
|
417
|
+
case "inactive":
|
|
418
|
+
break;
|
|
419
|
+
case "deactivating":
|
|
420
|
+
if (stake.delegation?.voteAccAddr !== uiState.voteAccAddr) {
|
|
421
|
+
errors.stakeAccAddr = new SolanaStakeAccountValidatorIsUnchangeable();
|
|
422
|
+
}
|
|
423
|
+
break;
|
|
424
|
+
default:
|
|
425
|
+
return assertUnreachable(stake.activation.state);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const { fee } = await estimateFeeAndSpendable(api, mainAccount, tx);
|
|
430
|
+
|
|
431
|
+
if (mainAccount.spendableBalance.lt(fee)) {
|
|
432
|
+
errors.fee = new NotEnoughBalance();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return {
|
|
436
|
+
command: {
|
|
437
|
+
kind: "stake.delegate",
|
|
438
|
+
authorizedAccAddr: mainAccount.freshAddress,
|
|
439
|
+
stakeAccAddr: uiState.stakeAccAddr,
|
|
440
|
+
voteAccAddr: uiState.voteAccAddr,
|
|
441
|
+
},
|
|
442
|
+
fee,
|
|
443
|
+
warnings: {},
|
|
444
|
+
errors,
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
async function deriveStakeUndelegateCommandDescriptor(
|
|
449
|
+
mainAccount: SolanaAccount,
|
|
450
|
+
tx: Transaction,
|
|
451
|
+
model: TransactionModel & { kind: StakeUndelegateTransaction["kind"] },
|
|
452
|
+
api: ChainAPI,
|
|
453
|
+
): Promise<CommandDescriptor> {
|
|
454
|
+
const errors: Record<string, Error> = {};
|
|
455
|
+
|
|
456
|
+
const { uiState } = model;
|
|
457
|
+
|
|
458
|
+
const stake = validateAndTryGetStakeAccount(mainAccount, uiState.stakeAccAddr, errors);
|
|
459
|
+
|
|
460
|
+
if (stake !== undefined) {
|
|
461
|
+
switch (stake.activation.state) {
|
|
462
|
+
case "active":
|
|
463
|
+
case "activating":
|
|
464
|
+
break;
|
|
465
|
+
case "inactive":
|
|
466
|
+
case "deactivating":
|
|
467
|
+
errors.stakeAccAddr = new SolanaStakeAccountIsNotUndelegatable();
|
|
468
|
+
break;
|
|
469
|
+
default:
|
|
470
|
+
return assertUnreachable(stake.activation.state);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (!errors.stakeAccAddr && !stake.hasStakeAuth && !stake.hasWithdrawAuth) {
|
|
474
|
+
errors.stakeAccAddr = new SolanaStakeNoStakeAuth();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const { fee } = await estimateFeeAndSpendable(api, mainAccount, tx);
|
|
479
|
+
if (mainAccount.solanaResources.unstakeReserve.lt(fee)) {
|
|
480
|
+
errors.fee = new NotEnoughBalance();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return {
|
|
484
|
+
command: {
|
|
485
|
+
kind: "stake.undelegate",
|
|
486
|
+
authorizedAccAddr: mainAccount.freshAddress,
|
|
487
|
+
stakeAccAddr: uiState.stakeAccAddr,
|
|
488
|
+
},
|
|
489
|
+
fee,
|
|
490
|
+
warnings: {},
|
|
491
|
+
errors,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
async function deriveStakeWithdrawCommandDescriptor(
|
|
496
|
+
mainAccount: SolanaAccount,
|
|
497
|
+
tx: Transaction,
|
|
498
|
+
model: TransactionModel & { kind: StakeWithdrawTransaction["kind"] },
|
|
499
|
+
api: ChainAPI,
|
|
500
|
+
): Promise<CommandDescriptor> {
|
|
501
|
+
const errors: Record<string, Error> = {};
|
|
502
|
+
const { uiState } = model;
|
|
503
|
+
|
|
504
|
+
const stake = validateAndTryGetStakeAccount(mainAccount, uiState.stakeAccAddr, errors);
|
|
505
|
+
|
|
506
|
+
if (!errors.stakeAccAddr && stake !== undefined) {
|
|
507
|
+
if (!stake.hasWithdrawAuth) {
|
|
508
|
+
errors.stakeAccAddr = new SolanaStakeNoWithdrawAuth();
|
|
509
|
+
} else if (stake.withdrawable <= 0) {
|
|
510
|
+
errors.stakeAccAddr = new SolanaStakeAccountNothingToWithdraw();
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const { fee } = await estimateFeeAndSpendable(api, mainAccount, tx);
|
|
515
|
+
if (mainAccount.solanaResources.unstakeReserve.lt(fee)) {
|
|
516
|
+
errors.fee = new NotEnoughBalance();
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return {
|
|
520
|
+
command: {
|
|
521
|
+
kind: "stake.withdraw",
|
|
522
|
+
authorizedAccAddr: mainAccount.freshAddress,
|
|
523
|
+
stakeAccAddr: uiState.stakeAccAddr,
|
|
524
|
+
amount: stake?.withdrawable ?? 0,
|
|
525
|
+
toAccAddr: mainAccount.freshAddress,
|
|
526
|
+
},
|
|
527
|
+
fee,
|
|
528
|
+
warnings: {},
|
|
529
|
+
errors,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
async function deriveStakeSplitCommandDescriptor(
|
|
534
|
+
mainAccount: SolanaAccount,
|
|
535
|
+
tx: Transaction,
|
|
536
|
+
model: TransactionModel & { kind: StakeSplitTransaction["kind"] },
|
|
537
|
+
api: ChainAPI,
|
|
538
|
+
): Promise<CommandDescriptor> {
|
|
539
|
+
const errors: Record<string, Error> = {};
|
|
540
|
+
|
|
541
|
+
// TODO: find stake account in the main acc when synced
|
|
542
|
+
const { uiState } = model;
|
|
543
|
+
|
|
544
|
+
// TODO: use all amount
|
|
545
|
+
if (tx.amount.lte(0)) {
|
|
546
|
+
errors.amount = new AmountRequired();
|
|
547
|
+
}
|
|
548
|
+
// TODO: else if amount > stake balance
|
|
549
|
+
|
|
550
|
+
if (!isValidBase58Address(uiState.stakeAccAddr)) {
|
|
551
|
+
errors.stakeAccAddr = new InvalidAddress("", {
|
|
552
|
+
currencyName: mainAccount.currency.name,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
mainAccount.solanaResources?.stakes ?? [];
|
|
557
|
+
|
|
558
|
+
const commandFees = await getStakeAccountMinimumBalanceForRentExemption(api);
|
|
559
|
+
|
|
560
|
+
const splitStakeAccAddrSeed = `stake:${Math.random().toString()}`;
|
|
561
|
+
const splitStakeAccAddr = await getStakeAccountAddressWithSeed({
|
|
562
|
+
fromAddress: mainAccount.freshAddress,
|
|
563
|
+
seed: splitStakeAccAddrSeed,
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
return {
|
|
567
|
+
command: {
|
|
568
|
+
kind: "stake.split",
|
|
569
|
+
authorizedAccAddr: mainAccount.freshAddress,
|
|
570
|
+
stakeAccAddr: uiState.stakeAccAddr,
|
|
571
|
+
amount: tx.amount.toNumber(),
|
|
572
|
+
seed: splitStakeAccAddrSeed,
|
|
573
|
+
splitStakeAccAddr,
|
|
574
|
+
},
|
|
575
|
+
fee: commandFees,
|
|
576
|
+
warnings: {},
|
|
577
|
+
errors: {},
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// if subaccountid present - it's a token transfer
|
|
582
|
+
function updateModelIfSubAccountIdPresent(tx: Transaction): Transaction {
|
|
583
|
+
if (tx.subAccountId) {
|
|
584
|
+
return {
|
|
585
|
+
...tx,
|
|
586
|
+
model: {
|
|
587
|
+
kind: "token.transfer",
|
|
588
|
+
uiState: {
|
|
589
|
+
...tx.model.uiState,
|
|
590
|
+
subAccountId: tx.subAccountId,
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
return tx;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
async function isAccountFunded(address: string, api: ChainAPI): Promise<boolean> {
|
|
600
|
+
const balance = await api.getBalance(address);
|
|
601
|
+
return balance > 0;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
async function validateRecipientCommon(
|
|
605
|
+
mainAccount: Account,
|
|
606
|
+
tx: Transaction,
|
|
607
|
+
errors: Record<string, Error>,
|
|
608
|
+
warnings: Record<string, Error>,
|
|
609
|
+
api: ChainAPI,
|
|
610
|
+
) {
|
|
611
|
+
if (!tx.recipient) {
|
|
612
|
+
errors.recipient = new RecipientRequired();
|
|
613
|
+
} else if (mainAccount.freshAddress === tx.recipient) {
|
|
614
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
615
|
+
} else if (!isValidBase58Address(tx.recipient)) {
|
|
616
|
+
errors.recipient = new InvalidAddress("", {
|
|
617
|
+
currencyName: mainAccount.currency.name,
|
|
618
|
+
});
|
|
619
|
+
} else {
|
|
620
|
+
const recipientWalletIsUnfunded = !(await isAccountFunded(tx.recipient, api));
|
|
621
|
+
|
|
622
|
+
if (recipientWalletIsUnfunded) {
|
|
623
|
+
warnings.recipient = new SolanaAccountNotFunded();
|
|
624
|
+
}
|
|
625
|
+
if (!isEd25519Address(tx.recipient)) {
|
|
626
|
+
warnings.recipientOffCurve = new SolanaAddressOffEd25519();
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function validateMemoCommon(memo: string, errors: Record<string, Error>) {
|
|
632
|
+
const memoBytes = Buffer.from(memo, "utf-8");
|
|
633
|
+
if (memoBytes.byteLength > MAX_MEMO_LENGTH) {
|
|
634
|
+
errors.memo = errors.memo = new SolanaMemoIsTooLong(undefined, {
|
|
635
|
+
maxLength: MAX_MEMO_LENGTH,
|
|
636
|
+
});
|
|
637
|
+
// LLM expects <transaction> as error key to disable continue button
|
|
638
|
+
errors.transaction = errors.memo;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
async function validateValidatorCommon(addr: string, errors: Record<string, Error>, api: ChainAPI) {
|
|
643
|
+
if (addr.length === 0) {
|
|
644
|
+
errors.voteAccAddr = new SolanaValidatorRequired();
|
|
645
|
+
} else if (!isValidBase58Address(addr)) {
|
|
646
|
+
errors.voteAccAddr = new InvalidAddress("", {
|
|
647
|
+
currencyName: "Solana",
|
|
648
|
+
});
|
|
649
|
+
} else {
|
|
650
|
+
const voteAcc = await getMaybeVoteAccount(addr, api);
|
|
651
|
+
|
|
652
|
+
if (voteAcc instanceof Error || voteAcc === undefined) {
|
|
653
|
+
errors.voteAccAddr = new SolanaInvalidValidator();
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function validateAndTryGetStakeAccount(
|
|
659
|
+
account: SolanaAccount,
|
|
660
|
+
stakeAccAddr: string,
|
|
661
|
+
errors: Record<string, Error>,
|
|
662
|
+
): SolanaStake | undefined {
|
|
663
|
+
if (stakeAccAddr.length === 0) {
|
|
664
|
+
errors.stakeAccAddr = new SolanaStakeAccountRequired();
|
|
665
|
+
} else if (!isValidBase58Address(stakeAccAddr)) {
|
|
666
|
+
errors.stakeAccAddr = new InvalidAddress("", {
|
|
667
|
+
currencyName: account.currency.name,
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (!errors.stakeAccAddr) {
|
|
672
|
+
const stake = account.solanaResources?.stakes.find(
|
|
673
|
+
stake => stake.stakeAccAddr === stakeAccAddr,
|
|
674
|
+
);
|
|
675
|
+
|
|
676
|
+
if (stake === undefined) {
|
|
677
|
+
errors.stakeAccAddr = new SolanaStakeAccountNotFound();
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
return stake;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
return undefined;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
export { prepareTransaction };
|