@ledgerhq/coin-solana 0.7.0-next.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 +27 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/cached.d.ts +3 -0
- package/lib/api/cached.d.ts.map +1 -0
- package/lib/api/cached.js +41 -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 +96 -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 +272 -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 +134 -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 +988 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/broadcast.d.ts +7 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +37 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/buildTransaction.d.ts +5 -0
- package/lib/buildTransaction.d.ts.map +1 -0
- package/lib/buildTransaction.js +67 -0
- package/lib/buildTransaction.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/createTransaction.d.ts +5 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +19 -0
- package/lib/createTransaction.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/estimateMaxSpendable.d.ts +11 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +63 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +5 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +73 -0
- package/lib/getTransactionStatus.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/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/preload-data.d.ts +7 -0
- package/lib/preload-data.d.ts.map +1 -0
- package/lib/preload-data.js +45 -0
- package/lib/preload-data.js.map +1 -0
- package/lib/preload.d.ts +7 -0
- package/lib/preload.d.ts.map +1 -0
- package/lib/preload.js +67 -0
- package/lib/preload.js.map +1 -0
- package/lib/preload.test.d.ts +2 -0
- package/lib/preload.test.d.ts.map +1 -0
- package/lib/preload.test.js +9 -0
- package/lib/preload.test.js.map +1 -0
- package/lib/prepareTransaction.d.ts +5 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +500 -0
- package/lib/prepareTransaction.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/signOperation.d.ts +7 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +153 -0
- package/lib/signOperation.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/synchronization.d.ts +5 -0
- package/lib/synchronization.d.ts.map +1 -0
- package/lib/synchronization.js +463 -0
- package/lib/synchronization.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +154 -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 +225 -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 +34 -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 +92 -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 +249 -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 +127 -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 +986 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/broadcast.d.ts +7 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +33 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/buildTransaction.d.ts +5 -0
- package/lib-es/buildTransaction.d.ts.map +1 -0
- package/lib-es/buildTransaction.js +63 -0
- package/lib-es/buildTransaction.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/createTransaction.d.ts +5 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +15 -0
- package/lib-es/createTransaction.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/estimateMaxSpendable.d.ts +11 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +55 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +5 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +69 -0
- package/lib-es/getTransactionStatus.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/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/preload-data.d.ts +7 -0
- package/lib-es/preload-data.d.ts.map +1 -0
- package/lib-es/preload-data.js +39 -0
- package/lib-es/preload-data.js.map +1 -0
- package/lib-es/preload.d.ts +7 -0
- package/lib-es/preload.d.ts.map +1 -0
- package/lib-es/preload.js +62 -0
- package/lib-es/preload.js.map +1 -0
- package/lib-es/preload.test.d.ts +2 -0
- package/lib-es/preload.test.d.ts.map +1 -0
- package/lib-es/preload.test.js +7 -0
- package/lib-es/preload.test.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +5 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +497 -0
- package/lib-es/prepareTransaction.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/signOperation.d.ts +7 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +146 -0
- package/lib-es/signOperation.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/synchronization.d.ts +5 -0
- package/lib-es/synchronization.d.ts.map +1 -0
- package/lib-es/synchronization.js +456 -0
- package/lib-es/synchronization.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 +148 -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 +225 -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 +90 -0
- package/src/api/cached.ts +79 -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 +212 -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 +192 -0
- package/src/bridge/js.ts +42 -0
- package/src/bridge.integration.test.ts +1104 -0
- package/src/broadcast.ts +38 -0
- package/src/buildTransaction.ts +81 -0
- package/src/cli-transaction.ts +246 -0
- package/src/createTransaction.ts +18 -0
- package/src/datasets/solana.scanAccounts.1.ts +9 -0
- package/src/deviceTransactionConfig.ts +302 -0
- package/src/errors.ts +61 -0
- package/src/estimateMaxSpendable.ts +72 -0
- package/src/getTransactionStatus.ts +79 -0
- package/src/hw-getAddress.ts +22 -0
- package/src/logic.ts +123 -0
- package/src/preload-data.ts +46 -0
- package/src/preload.test.ts +14 -0
- package/src/preload.ts +74 -0
- package/src/prepareTransaction.ts +686 -0
- package/src/serialization.ts +81 -0
- package/src/signOperation.ts +315 -0
- package/src/signer.ts +10 -0
- package/src/specs.ts +514 -0
- package/src/speculos-deviceActions.ts +229 -0
- package/src/synchronization.ts +729 -0
- package/src/transaction.ts +199 -0
- package/src/tx-fees.ts +206 -0
- package/src/types.ts +291 -0
- package/src/utils.ts +176 -0
- package/src/validator-app/index.ts +79 -0
- package/tsconfig.json +13 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createCustomErrorClass } from "@ledgerhq/errors";
|
|
2
|
+
|
|
3
|
+
export const SolanaAccountNotFunded = createCustomErrorClass("SolanaAccountNotFunded");
|
|
4
|
+
|
|
5
|
+
export const SolanaRecipientAssociatedTokenAccountWillBeFunded = createCustomErrorClass(
|
|
6
|
+
"SolanaAssociatedTokenAccountWillBeFunded",
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export const SolanaMemoIsTooLong = createCustomErrorClass("SolanaMemoIsTooLong");
|
|
10
|
+
|
|
11
|
+
export const SolanaTokenAccountHoldsAnotherToken = createCustomErrorClass(
|
|
12
|
+
"SolanaTokenAccountHoldsAnotherToken",
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const SolanaTokenAccounNotInitialized = createCustomErrorClass(
|
|
16
|
+
"SolanaTokenAccounNotInitialized",
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const SolanaAddressOffEd25519 = createCustomErrorClass("SolanaAddressOfEd25519");
|
|
20
|
+
|
|
21
|
+
export const SolanaTokenRecipientIsSenderATA = createCustomErrorClass(
|
|
22
|
+
"SolanaTokenRecipientIsSenderATA",
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const SolanaValidatorRequired = createCustomErrorClass("SolanaValidatorRequired");
|
|
26
|
+
|
|
27
|
+
export const SolanaInvalidValidator = createCustomErrorClass("SolanaInvalidValidator");
|
|
28
|
+
|
|
29
|
+
export const SolanaStakeAccountRequired = createCustomErrorClass("SolanaStakeAccountRequired");
|
|
30
|
+
|
|
31
|
+
export const SolanaStakeAccountNotFound = createCustomErrorClass("SolanaStakeAccountNotFound");
|
|
32
|
+
|
|
33
|
+
export const SolanaStakeAccountNothingToWithdraw = createCustomErrorClass(
|
|
34
|
+
"SolanaStakeAccountNothingToWithdraw",
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export const SolanaStakeAccountIsNotDelegatable = createCustomErrorClass(
|
|
38
|
+
"SolanaStakeAccountIsNotDelegatable",
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const SolanaStakeAccountIsNotUndelegatable = createCustomErrorClass(
|
|
42
|
+
"SolanaStakeAccountIsNotUndelegatable",
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export const SolanaStakeAccountValidatorIsUnchangeable = createCustomErrorClass(
|
|
46
|
+
"SolanaStakeAccountValidatorIsUnchangeable",
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
export const SolanaStakeNoWithdrawAuth = createCustomErrorClass("SolanaStakeNoWithdrawAuth");
|
|
50
|
+
|
|
51
|
+
export const SolanaStakeNoStakeAuth = createCustomErrorClass("SolanaStakeNoStakeAuth");
|
|
52
|
+
|
|
53
|
+
export const SolanaUseAllAmountStakeWarning = createCustomErrorClass(
|
|
54
|
+
"SolanaUseAllAmountStakeWarning",
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const SolanaTxSimulationFailedWhilePendingOp = createCustomErrorClass(
|
|
58
|
+
"SolanaTxSimulationFailedWhilePendingOp",
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export const SolanaTxConfirmationTimeout = createCustomErrorClass("SolanaTxConfirmationTimeout");
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Account, AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import type { Transaction } from "./types";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { ChainAPI } from "./api";
|
|
5
|
+
import { getStakeAccountMinimumBalanceForRentExemption } from "./api/chain/web3";
|
|
6
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
7
|
+
import { estimateTxFee } from "./tx-fees";
|
|
8
|
+
|
|
9
|
+
export const estimateFeeAndSpendable = async (
|
|
10
|
+
api: ChainAPI,
|
|
11
|
+
account: Account,
|
|
12
|
+
transaction?: Transaction | undefined | null,
|
|
13
|
+
): Promise<{ fee: number; spendable: BigNumber }> => {
|
|
14
|
+
const txKind = transaction?.model.kind ?? "transfer";
|
|
15
|
+
const txFee = await estimateTxFee(api, account.freshAddress, txKind);
|
|
16
|
+
|
|
17
|
+
const spendableBalance = BigNumber.max(account.spendableBalance.minus(txFee), 0);
|
|
18
|
+
|
|
19
|
+
switch (txKind) {
|
|
20
|
+
case "token.createATA": {
|
|
21
|
+
const assocAccRentExempt = await api.getAssocTokenAccMinNativeBalance();
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
fee: txFee + assocAccRentExempt,
|
|
25
|
+
spendable: BigNumber.max(spendableBalance.minus(assocAccRentExempt), 0),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
case "stake.createAccount": {
|
|
29
|
+
const stakeAccRentExempt = await getStakeAccountMinimumBalanceForRentExemption(api);
|
|
30
|
+
const unstakeReserve =
|
|
31
|
+
(await estimateTxFee(api, account.freshAddress, "stake.undelegate")) +
|
|
32
|
+
(await estimateTxFee(api, account.freshAddress, "stake.withdraw"));
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
fee: txFee + stakeAccRentExempt,
|
|
36
|
+
spendable: BigNumber.max(
|
|
37
|
+
spendableBalance.minus(stakeAccRentExempt).minus(unstakeReserve),
|
|
38
|
+
0,
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
default: {
|
|
44
|
+
return {
|
|
45
|
+
fee: txFee,
|
|
46
|
+
spendable: spendableBalance,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const estimateMaxSpendableWithAPI = async (
|
|
53
|
+
{
|
|
54
|
+
account,
|
|
55
|
+
parentAccount,
|
|
56
|
+
transaction,
|
|
57
|
+
}: Parameters<AccountBridge<Transaction>["estimateMaxSpendable"]>[0],
|
|
58
|
+
api: ChainAPI,
|
|
59
|
+
): Promise<BigNumber> => {
|
|
60
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
61
|
+
|
|
62
|
+
switch (account.type) {
|
|
63
|
+
case "Account":
|
|
64
|
+
return (await estimateFeeAndSpendable(api, mainAccount, transaction)).spendable;
|
|
65
|
+
case "TokenAccount":
|
|
66
|
+
return account.spendableBalance;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw new Error("not supported account type");
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default estimateMaxSpendableWithAPI;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import { assertUnreachable } from "./utils";
|
|
4
|
+
import type {
|
|
5
|
+
Command,
|
|
6
|
+
CommandDescriptor,
|
|
7
|
+
SolanaAccount,
|
|
8
|
+
Transaction,
|
|
9
|
+
TransactionStatus,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
export const getTransactionStatus: AccountBridge<
|
|
13
|
+
Transaction,
|
|
14
|
+
SolanaAccount,
|
|
15
|
+
TransactionStatus
|
|
16
|
+
>["getTransactionStatus"] = async (_account, tx) => {
|
|
17
|
+
const { commandDescriptor } = tx.model;
|
|
18
|
+
|
|
19
|
+
if (commandDescriptor === undefined) {
|
|
20
|
+
return {
|
|
21
|
+
amount: tx.amount,
|
|
22
|
+
estimatedFees: new BigNumber(0),
|
|
23
|
+
totalSpent: tx.amount,
|
|
24
|
+
errors: {},
|
|
25
|
+
warnings: {},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { command, fee, errors, warnings } = commandDescriptor;
|
|
30
|
+
|
|
31
|
+
const amount = new BigNumber(getAmount(command));
|
|
32
|
+
const estimatedFees = new BigNumber(fee);
|
|
33
|
+
const totalSpent = new BigNumber(getTotalSpent(commandDescriptor));
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
amount,
|
|
37
|
+
estimatedFees,
|
|
38
|
+
totalSpent,
|
|
39
|
+
warnings,
|
|
40
|
+
errors,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function getAmount(command: Command) {
|
|
45
|
+
switch (command.kind) {
|
|
46
|
+
case "transfer":
|
|
47
|
+
case "token.transfer":
|
|
48
|
+
case "stake.createAccount":
|
|
49
|
+
case "stake.withdraw":
|
|
50
|
+
return command.amount;
|
|
51
|
+
case "token.createATA":
|
|
52
|
+
case "stake.delegate":
|
|
53
|
+
case "stake.undelegate":
|
|
54
|
+
case "stake.split":
|
|
55
|
+
return 0;
|
|
56
|
+
default:
|
|
57
|
+
return assertUnreachable(command);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getTotalSpent({ command, fee }: CommandDescriptor) {
|
|
62
|
+
switch (command.kind) {
|
|
63
|
+
case "transfer":
|
|
64
|
+
case "stake.createAccount":
|
|
65
|
+
return command.amount < 0 ? 0 : command.amount + fee;
|
|
66
|
+
case "token.transfer":
|
|
67
|
+
return Math.max(command.amount, 0);
|
|
68
|
+
case "token.createATA":
|
|
69
|
+
case "stake.delegate":
|
|
70
|
+
case "stake.undelegate":
|
|
71
|
+
case "stake.withdraw":
|
|
72
|
+
case "stake.split":
|
|
73
|
+
return fee;
|
|
74
|
+
default:
|
|
75
|
+
return assertUnreachable(command);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default getTransactionStatus;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
4
|
+
import { SolanaSigner } from "./signer";
|
|
5
|
+
|
|
6
|
+
import bs58 from "bs58";
|
|
7
|
+
|
|
8
|
+
const resolver = (signerContext: SignerContext<SolanaSigner>): GetAddressFn => {
|
|
9
|
+
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
|
|
10
|
+
const { address } = await signerContext(deviceId, signer => signer.getAddress(path, verify));
|
|
11
|
+
|
|
12
|
+
const publicKey = bs58.encode(address);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
address: publicKey,
|
|
16
|
+
publicKey,
|
|
17
|
+
path,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default resolver;
|
package/src/logic.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { findTokenById } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { TokenAccount } from "@ledgerhq/types-live";
|
|
4
|
+
import { StakeMeta } from "./api/chain/account/stake";
|
|
5
|
+
import { SolanaStake, StakeAction } from "./types";
|
|
6
|
+
import { assertUnreachable } from "./utils";
|
|
7
|
+
|
|
8
|
+
export type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
|
9
|
+
|
|
10
|
+
export const MAX_MEMO_LENGTH = 500;
|
|
11
|
+
|
|
12
|
+
export const isValidBase58Address = (address: string): boolean => {
|
|
13
|
+
try {
|
|
14
|
+
return Boolean(new PublicKey(address));
|
|
15
|
+
} catch (_) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isEd25519Address = (address: string): boolean => {
|
|
21
|
+
return PublicKey.isOnCurve(new PublicKey(address).toBytes());
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function encodeAccountIdWithTokenAccountAddress(accountId: string, address: string): string {
|
|
25
|
+
return `${accountId}+${address}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function decodeAccountIdWithTokenAccountAddress(accountIdWithTokenAccountAddress: string): {
|
|
29
|
+
accountId: string;
|
|
30
|
+
address: string;
|
|
31
|
+
} {
|
|
32
|
+
const lastColonIndex = accountIdWithTokenAccountAddress.lastIndexOf("+");
|
|
33
|
+
return {
|
|
34
|
+
accountId: accountIdWithTokenAccountAddress.slice(0, lastColonIndex),
|
|
35
|
+
address: accountIdWithTokenAccountAddress.slice(lastColonIndex + 1),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function toTokenId(mint: string): string {
|
|
40
|
+
return `solana/spl/${mint}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function toTokenMint(tokenId: string): string {
|
|
44
|
+
return tokenId.split("/")[2];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function toSubAccMint(subAcc: TokenAccount): string {
|
|
48
|
+
return toTokenMint(subAcc.token.id);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function tokenIsListedOnLedger(mint: string): boolean {
|
|
52
|
+
return findTokenById(toTokenId(mint))?.type === "TokenCurrency";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function stakeActions(stake: SolanaStake): StakeAction[] {
|
|
56
|
+
const actions: StakeAction[] = [];
|
|
57
|
+
|
|
58
|
+
if (stake.withdrawable > 0) {
|
|
59
|
+
actions.push("withdraw");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
switch (stake.activation.state) {
|
|
63
|
+
case "active":
|
|
64
|
+
case "activating":
|
|
65
|
+
actions.push("deactivate");
|
|
66
|
+
break;
|
|
67
|
+
case "deactivating":
|
|
68
|
+
actions.push("reactivate");
|
|
69
|
+
break;
|
|
70
|
+
case "inactive":
|
|
71
|
+
actions.push("activate");
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
return assertUnreachable(stake.activation.state);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return actions;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function withdrawableFromStake({
|
|
81
|
+
stakeAccBalance,
|
|
82
|
+
activation,
|
|
83
|
+
rentExemptReserve,
|
|
84
|
+
}: {
|
|
85
|
+
stakeAccBalance: number;
|
|
86
|
+
activation: SolanaStake["activation"];
|
|
87
|
+
rentExemptReserve: number;
|
|
88
|
+
}) {
|
|
89
|
+
switch (activation.state) {
|
|
90
|
+
case "active":
|
|
91
|
+
case "activating":
|
|
92
|
+
return stakeAccBalance - rentExemptReserve - activation.active - activation.inactive;
|
|
93
|
+
case "deactivating":
|
|
94
|
+
return stakeAccBalance - rentExemptReserve - activation.active;
|
|
95
|
+
case "inactive":
|
|
96
|
+
return stakeAccBalance;
|
|
97
|
+
default:
|
|
98
|
+
return assertUnreachable(activation.state);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function isStakeLockUpInForce({
|
|
103
|
+
lockup,
|
|
104
|
+
custodianAddress,
|
|
105
|
+
epoch,
|
|
106
|
+
}: {
|
|
107
|
+
lockup: StakeMeta["lockup"];
|
|
108
|
+
custodianAddress: string;
|
|
109
|
+
epoch: number;
|
|
110
|
+
}) {
|
|
111
|
+
if (custodianAddress === lockup.custodian.toBase58()) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return lockup.unixTimestamp > Date.now() / 1000 || lockup.epoch > epoch;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function stakeActivePercent(stake: SolanaStake) {
|
|
118
|
+
const amount = stake.delegation?.stake;
|
|
119
|
+
if (amount === undefined || amount === 0) {
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
return (stake.activation.active / amount) * 100;
|
|
123
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
3
|
+
import { SolanaPreloadDataV1 } from "./types";
|
|
4
|
+
|
|
5
|
+
const initialData: SolanaPreloadDataV1 = {
|
|
6
|
+
version: "1",
|
|
7
|
+
validatorsWithMeta: [],
|
|
8
|
+
validators: [],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const dataByCurrency = new Map<string, SolanaPreloadDataV1>([
|
|
12
|
+
["solana", initialData],
|
|
13
|
+
["solana_testnet", initialData],
|
|
14
|
+
["solana_devnet", initialData],
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const dataUpdatesByCurrency = new Map([
|
|
18
|
+
["solana", new BehaviorSubject<SolanaPreloadDataV1>(initialData)],
|
|
19
|
+
["solana_testnet", new BehaviorSubject<SolanaPreloadDataV1>(initialData)],
|
|
20
|
+
["solana_devnet", new BehaviorSubject<SolanaPreloadDataV1>(initialData)],
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
export function setSolanaPreloadData(data: SolanaPreloadDataV1, currency: CryptoCurrency): void {
|
|
24
|
+
dataByCurrency.set(currency.id, data);
|
|
25
|
+
const subject = dataUpdatesByCurrency.get(currency.id);
|
|
26
|
+
if (subject === undefined) {
|
|
27
|
+
throw new Error(`unsupported currency ${currency.id}`);
|
|
28
|
+
}
|
|
29
|
+
subject.next(data);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getSolanaPreloadData(currency: CryptoCurrency): Observable<SolanaPreloadDataV1> {
|
|
33
|
+
const subject = dataUpdatesByCurrency.get(currency.id);
|
|
34
|
+
if (subject === undefined) {
|
|
35
|
+
throw new Error(`unsupported currency ${currency.id}`);
|
|
36
|
+
}
|
|
37
|
+
return subject.asObservable();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getCurrentSolanaPreloadData(currency: CryptoCurrency): SolanaPreloadDataV1 {
|
|
41
|
+
const data = dataByCurrency.get(currency.id);
|
|
42
|
+
if (data === undefined) {
|
|
43
|
+
throw new Error(`unsupported currency ${currency.id}`);
|
|
44
|
+
}
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { hydrate } from "./preload";
|
|
3
|
+
import { SolanaPreloadData } from "./types";
|
|
4
|
+
|
|
5
|
+
describe("hydrate", () => {
|
|
6
|
+
it.each([undefined, null, {}, { version: null }, { version: undefined }, {}])(
|
|
7
|
+
"should return undefined if data is corrupted (%p value)",
|
|
8
|
+
value => {
|
|
9
|
+
expect(hydrate(value as unknown as SolanaPreloadData, {} as CryptoCurrency)).toEqual(
|
|
10
|
+
undefined,
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
);
|
|
14
|
+
});
|
package/src/preload.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { flow } from "lodash/fp";
|
|
3
|
+
import { ChainAPI } from "./api";
|
|
4
|
+
import { setSolanaPreloadData as setPreloadData } from "./preload-data";
|
|
5
|
+
import { SolanaPreloadData, SolanaPreloadDataV1 } from "./types";
|
|
6
|
+
import {
|
|
7
|
+
assertUnreachable,
|
|
8
|
+
clusterByCurrencyId,
|
|
9
|
+
profitableValidators,
|
|
10
|
+
ledgerFirstValidators,
|
|
11
|
+
} from "./utils";
|
|
12
|
+
import { getValidators, ValidatorsAppValidator } from "./validator-app";
|
|
13
|
+
|
|
14
|
+
export const PRELOAD_MAX_AGE = 15 * 60 * 1000; // 15min
|
|
15
|
+
|
|
16
|
+
export async function preloadWithAPI(
|
|
17
|
+
currency: CryptoCurrency,
|
|
18
|
+
getAPI: () => Promise<ChainAPI>,
|
|
19
|
+
): Promise<SolanaPreloadDataV1> {
|
|
20
|
+
const api = await getAPI();
|
|
21
|
+
|
|
22
|
+
const cluster = clusterByCurrencyId(currency.id);
|
|
23
|
+
|
|
24
|
+
const validators: ValidatorsAppValidator[] =
|
|
25
|
+
cluster === "devnet" ? await loadDevnetValidators(api) : await getValidators(cluster);
|
|
26
|
+
|
|
27
|
+
const data: SolanaPreloadData = {
|
|
28
|
+
version: "1",
|
|
29
|
+
validatorsWithMeta: [],
|
|
30
|
+
validators: cluster === "mainnet-beta" ? preprocessMainnetValidators(validators) : validators,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
setPreloadData(data, currency);
|
|
34
|
+
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function preprocessMainnetValidators(
|
|
39
|
+
validators: ValidatorsAppValidator[],
|
|
40
|
+
): ValidatorsAppValidator[] {
|
|
41
|
+
return flow(() => validators, profitableValidators, ledgerFirstValidators)();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function loadDevnetValidators(api: ChainAPI) {
|
|
45
|
+
const voteAccs = await api.getVoteAccounts();
|
|
46
|
+
const validators: ValidatorsAppValidator[] = voteAccs.current.map(acc => ({
|
|
47
|
+
activeStake: acc.activatedStake,
|
|
48
|
+
commission: acc.commission,
|
|
49
|
+
totalScore: 0,
|
|
50
|
+
voteAccount: acc.votePubkey,
|
|
51
|
+
}));
|
|
52
|
+
return validators;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function hydrate(data: SolanaPreloadData | undefined, currency: CryptoCurrency): void {
|
|
56
|
+
// https://ledgerhq.atlassian.net/browse/LIVE-11568 covers unknown case where version is undefined
|
|
57
|
+
if (data == null || data.version == null) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
switch (data.version) {
|
|
62
|
+
case "1":
|
|
63
|
+
hydrateV1(data, currency);
|
|
64
|
+
return;
|
|
65
|
+
case "2":
|
|
66
|
+
throw new Error("version 2 for now exists only to support discriminated union");
|
|
67
|
+
default:
|
|
68
|
+
return assertUnreachable(data);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function hydrateV1(data: SolanaPreloadDataV1, currency: CryptoCurrency) {
|
|
73
|
+
setPreloadData(data, currency);
|
|
74
|
+
}
|