@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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ParsedInstruction, PartiallyDecodedInstruction } from "@solana/web3.js";
|
|
2
|
+
import { parseSplTokenInstruction, TokenInstructionDescriptor } from "../instruction/token";
|
|
3
|
+
import { PARSED_PROGRAMS } from "./constants";
|
|
4
|
+
import {
|
|
5
|
+
AssociatedTokenAccountInstructionDescriptor,
|
|
6
|
+
parseAssociatedTokenAccountInstruction,
|
|
7
|
+
} from "../instruction/associated-token-account";
|
|
8
|
+
import { MemoInstructionDescriptor, parseSplMemoInstruction } from "../instruction/memo";
|
|
9
|
+
import { parseStakeInstruction, StakeInstructionDescriptor } from "../instruction/stake";
|
|
10
|
+
import { parseSystemInstruction, SystemInstructionDescriptor } from "../instruction/system";
|
|
11
|
+
|
|
12
|
+
type ParsedProgram =
|
|
13
|
+
| {
|
|
14
|
+
program: "system";
|
|
15
|
+
title: string;
|
|
16
|
+
instruction: SystemInstructionDescriptor;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
program: "spl-associated-token-account";
|
|
20
|
+
title: string;
|
|
21
|
+
instruction: AssociatedTokenAccountInstructionDescriptor;
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
program: "spl-memo";
|
|
25
|
+
title: string;
|
|
26
|
+
instruction: MemoInstructionDescriptor;
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
program: "stake";
|
|
30
|
+
title: string;
|
|
31
|
+
instruction: StakeInstructionDescriptor;
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
program: "spl-token";
|
|
35
|
+
title: string;
|
|
36
|
+
instruction: TokenInstructionDescriptor;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
program: "unknown";
|
|
40
|
+
title: "Unknown";
|
|
41
|
+
instruction: undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const parse = (ix: ParsedInstruction | PartiallyDecodedInstruction): ParsedProgram => {
|
|
45
|
+
if ("parsed" in ix) {
|
|
46
|
+
const program: (typeof PARSED_PROGRAMS)[keyof typeof PARSED_PROGRAMS] = ix.program as any;
|
|
47
|
+
|
|
48
|
+
switch (program) {
|
|
49
|
+
case "system":
|
|
50
|
+
return {
|
|
51
|
+
program,
|
|
52
|
+
title: "System",
|
|
53
|
+
instruction: parseSystemInstruction({
|
|
54
|
+
...ix,
|
|
55
|
+
program,
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
case "spl-associated-token-account":
|
|
59
|
+
return {
|
|
60
|
+
program,
|
|
61
|
+
title: "Associated Token Account",
|
|
62
|
+
instruction: parseAssociatedTokenAccountInstruction({
|
|
63
|
+
...ix,
|
|
64
|
+
program,
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
case "spl-memo":
|
|
68
|
+
return {
|
|
69
|
+
program,
|
|
70
|
+
title: "Memo",
|
|
71
|
+
instruction: parseSplMemoInstruction({
|
|
72
|
+
...ix,
|
|
73
|
+
program,
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
case "stake":
|
|
77
|
+
return {
|
|
78
|
+
program,
|
|
79
|
+
title: "Stake",
|
|
80
|
+
instruction: parseStakeInstruction({
|
|
81
|
+
...ix,
|
|
82
|
+
program,
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
case "spl-token":
|
|
86
|
+
return {
|
|
87
|
+
program,
|
|
88
|
+
title: "Token",
|
|
89
|
+
instruction: parseSplTokenInstruction({
|
|
90
|
+
...ix,
|
|
91
|
+
program,
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
default:
|
|
95
|
+
return unknown();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return unknown();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const parseQuiet = (ix: ParsedInstruction | PartiallyDecodedInstruction): ParsedProgram => {
|
|
103
|
+
try {
|
|
104
|
+
return parse(ix);
|
|
105
|
+
} catch (_) {
|
|
106
|
+
return unknown();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
function unknown(): {
|
|
111
|
+
program: "unknown";
|
|
112
|
+
title: "Unknown";
|
|
113
|
+
instruction: undefined;
|
|
114
|
+
} {
|
|
115
|
+
return {
|
|
116
|
+
program: "unknown",
|
|
117
|
+
title: "Unknown",
|
|
118
|
+
instruction: undefined,
|
|
119
|
+
} as const;
|
|
120
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { coerce, instance, string } from "superstruct";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
export const BigNumFromString = coerce(instance(BigNumber), string(), value => {
|
|
5
|
+
if (typeof value === "string") return new BigNumber(value, 10);
|
|
6
|
+
throw new Error("invalid big num");
|
|
7
|
+
});
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAssociatedTokenAccountInstruction,
|
|
3
|
+
createTransferCheckedInstruction,
|
|
4
|
+
getAssociatedTokenAddress,
|
|
5
|
+
} from "@solana/spl-token";
|
|
6
|
+
import {
|
|
7
|
+
ConfirmedSignatureInfo,
|
|
8
|
+
Connection,
|
|
9
|
+
ParsedTransactionWithMeta,
|
|
10
|
+
PublicKey,
|
|
11
|
+
StakeProgram,
|
|
12
|
+
SystemProgram,
|
|
13
|
+
TransactionInstruction,
|
|
14
|
+
} from "@solana/web3.js";
|
|
15
|
+
import chunk from "lodash/chunk";
|
|
16
|
+
import { ChainAPI } from ".";
|
|
17
|
+
import { Awaited } from "../../logic";
|
|
18
|
+
import {
|
|
19
|
+
StakeCreateAccountCommand,
|
|
20
|
+
StakeDelegateCommand,
|
|
21
|
+
StakeSplitCommand,
|
|
22
|
+
StakeUndelegateCommand,
|
|
23
|
+
StakeWithdrawCommand,
|
|
24
|
+
TokenCreateATACommand,
|
|
25
|
+
TokenTransferCommand,
|
|
26
|
+
TransferCommand,
|
|
27
|
+
} from "../../types";
|
|
28
|
+
import { drainSeqAsyncGen } from "../../utils";
|
|
29
|
+
import { parseTokenAccountInfo, tryParseAsTokenAccount, tryParseAsVoteAccount } from "./account";
|
|
30
|
+
import { parseStakeAccountInfo } from "./account/parser";
|
|
31
|
+
import { StakeAccountInfo } from "./account/stake";
|
|
32
|
+
import { TokenAccountInfo } from "./account/token";
|
|
33
|
+
import { VoteAccountInfo } from "./account/vote";
|
|
34
|
+
|
|
35
|
+
const MEMO_PROGRAM_ID = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
|
|
36
|
+
|
|
37
|
+
type ParsedOnChainTokenAccount = Awaited<
|
|
38
|
+
ReturnType<Connection["getParsedTokenAccountsByOwner"]>
|
|
39
|
+
>["value"][number];
|
|
40
|
+
|
|
41
|
+
type ParsedOnChainStakeAccount = Awaited<
|
|
42
|
+
ReturnType<Connection["getParsedProgramAccounts"]>
|
|
43
|
+
>[number];
|
|
44
|
+
|
|
45
|
+
export type ParsedOnChainTokenAccountWithInfo = {
|
|
46
|
+
onChainAcc: ParsedOnChainTokenAccount;
|
|
47
|
+
info: TokenAccountInfo;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type ParsedOnChainStakeAccountWithInfo = {
|
|
51
|
+
onChainAcc: ParsedOnChainStakeAccount;
|
|
52
|
+
info: StakeAccountInfo;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export function toTokenAccountWithInfo(
|
|
56
|
+
onChainAcc: ParsedOnChainTokenAccount,
|
|
57
|
+
): ParsedOnChainTokenAccountWithInfo {
|
|
58
|
+
const parsedInfo = onChainAcc.account.data.parsed.info;
|
|
59
|
+
const info = parseTokenAccountInfo(parsedInfo);
|
|
60
|
+
return { onChainAcc, info };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function toStakeAccountWithInfo(
|
|
64
|
+
onChainAcc: ParsedOnChainStakeAccount,
|
|
65
|
+
): ParsedOnChainStakeAccountWithInfo | undefined {
|
|
66
|
+
if ("parsed" in onChainAcc.account.data) {
|
|
67
|
+
const parsedInfo = onChainAcc.account.data.parsed.info;
|
|
68
|
+
const info = parseStakeAccountInfo(parsedInfo);
|
|
69
|
+
return { onChainAcc, info };
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type TransactionDescriptor = {
|
|
75
|
+
parsed: ParsedTransactionWithMeta;
|
|
76
|
+
info: ConfirmedSignatureInfo;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
async function* getTransactionsBatched(
|
|
80
|
+
address: string,
|
|
81
|
+
untilTxSignature: string | undefined,
|
|
82
|
+
api: ChainAPI,
|
|
83
|
+
): AsyncGenerator<TransactionDescriptor[], void, unknown> {
|
|
84
|
+
// as per Ledger team - last 100 operations is a sane limit to begin with
|
|
85
|
+
const signatures = await api.getSignaturesForAddress(address, {
|
|
86
|
+
...(untilTxSignature ? { until: untilTxSignature } : {}),
|
|
87
|
+
limit: 100,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// max req payload is 50K, around 200 transactions atm
|
|
91
|
+
// requesting 100 at a time to give some space for payload to change in future
|
|
92
|
+
const batchSize = 100;
|
|
93
|
+
|
|
94
|
+
for (const signaturesInfoBatch of chunk(signatures, batchSize)) {
|
|
95
|
+
const transactions = await api.getParsedTransactions(
|
|
96
|
+
signaturesInfoBatch.map(tx => tx.signature),
|
|
97
|
+
);
|
|
98
|
+
const txsDetails = transactions.reduce((acc, tx, index) => {
|
|
99
|
+
if (tx && !tx.meta?.err && tx.blockTime) {
|
|
100
|
+
acc.push({
|
|
101
|
+
info: signaturesInfoBatch[index],
|
|
102
|
+
parsed: tx,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return acc;
|
|
106
|
+
}, [] as TransactionDescriptor[]);
|
|
107
|
+
|
|
108
|
+
yield txsDetails;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function* getTransactionsGen(
|
|
113
|
+
address: string,
|
|
114
|
+
untilTxSignature: string | undefined,
|
|
115
|
+
api: ChainAPI,
|
|
116
|
+
): AsyncGenerator<TransactionDescriptor, void, undefined> {
|
|
117
|
+
for await (const txDetailsBatch of getTransactionsBatched(address, untilTxSignature, api)) {
|
|
118
|
+
yield* txDetailsBatch;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function getTransactions(
|
|
123
|
+
address: string,
|
|
124
|
+
untilTxSignature: string | undefined,
|
|
125
|
+
api: ChainAPI,
|
|
126
|
+
): Promise<TransactionDescriptor[]> {
|
|
127
|
+
return drainSeqAsyncGen(getTransactionsGen(address, untilTxSignature, api));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const buildTransferInstructions = ({
|
|
131
|
+
sender,
|
|
132
|
+
recipient,
|
|
133
|
+
amount,
|
|
134
|
+
memo,
|
|
135
|
+
}: TransferCommand): TransactionInstruction[] => {
|
|
136
|
+
const fromPublicKey = new PublicKey(sender);
|
|
137
|
+
const toPublicKey = new PublicKey(recipient);
|
|
138
|
+
|
|
139
|
+
const instructions: TransactionInstruction[] = [
|
|
140
|
+
SystemProgram.transfer({
|
|
141
|
+
fromPubkey: fromPublicKey,
|
|
142
|
+
toPubkey: toPublicKey,
|
|
143
|
+
lamports: amount,
|
|
144
|
+
}),
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
if (memo) {
|
|
148
|
+
const memoIx = new TransactionInstruction({
|
|
149
|
+
keys: [],
|
|
150
|
+
programId: new PublicKey(MEMO_PROGRAM_ID),
|
|
151
|
+
data: Buffer.from(memo),
|
|
152
|
+
});
|
|
153
|
+
instructions.push(memoIx);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return instructions;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const buildTokenTransferInstructions = (
|
|
160
|
+
command: TokenTransferCommand,
|
|
161
|
+
): TransactionInstruction[] => {
|
|
162
|
+
const {
|
|
163
|
+
ownerAddress,
|
|
164
|
+
ownerAssociatedTokenAccountAddress,
|
|
165
|
+
amount,
|
|
166
|
+
recipientDescriptor,
|
|
167
|
+
mintAddress,
|
|
168
|
+
mintDecimals,
|
|
169
|
+
memo,
|
|
170
|
+
} = command;
|
|
171
|
+
const ownerPubkey = new PublicKey(ownerAddress);
|
|
172
|
+
|
|
173
|
+
const destinationPubkey = new PublicKey(recipientDescriptor.tokenAccAddress);
|
|
174
|
+
|
|
175
|
+
const instructions: TransactionInstruction[] = [];
|
|
176
|
+
|
|
177
|
+
const mintPubkey = new PublicKey(mintAddress);
|
|
178
|
+
|
|
179
|
+
if (recipientDescriptor.shouldCreateAsAssociatedTokenAccount) {
|
|
180
|
+
instructions.push(
|
|
181
|
+
createAssociatedTokenAccountInstruction(
|
|
182
|
+
ownerPubkey,
|
|
183
|
+
destinationPubkey,
|
|
184
|
+
ownerPubkey,
|
|
185
|
+
mintPubkey,
|
|
186
|
+
),
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
instructions.push(
|
|
191
|
+
createTransferCheckedInstruction(
|
|
192
|
+
new PublicKey(ownerAssociatedTokenAccountAddress),
|
|
193
|
+
mintPubkey,
|
|
194
|
+
destinationPubkey,
|
|
195
|
+
ownerPubkey,
|
|
196
|
+
amount,
|
|
197
|
+
mintDecimals,
|
|
198
|
+
),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
if (memo) {
|
|
202
|
+
instructions.push(
|
|
203
|
+
new TransactionInstruction({
|
|
204
|
+
keys: [],
|
|
205
|
+
programId: new PublicKey(MEMO_PROGRAM_ID),
|
|
206
|
+
data: Buffer.from(memo),
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return instructions;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export async function findAssociatedTokenAccountPubkey(
|
|
215
|
+
ownerAddress: string,
|
|
216
|
+
mintAddress: string,
|
|
217
|
+
): Promise<PublicKey> {
|
|
218
|
+
const ownerPubKey = new PublicKey(ownerAddress);
|
|
219
|
+
const mintPubkey = new PublicKey(mintAddress);
|
|
220
|
+
|
|
221
|
+
return getAssociatedTokenAddress(mintPubkey, ownerPubKey);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export const getMaybeTokenAccount = async (
|
|
225
|
+
address: string,
|
|
226
|
+
api: ChainAPI,
|
|
227
|
+
): Promise<TokenAccountInfo | undefined | Error> => {
|
|
228
|
+
const accInfo = await api.getAccountInfo(address);
|
|
229
|
+
|
|
230
|
+
const tokenAccount =
|
|
231
|
+
accInfo !== null && "parsed" in accInfo.data ? tryParseAsTokenAccount(accInfo.data) : undefined;
|
|
232
|
+
|
|
233
|
+
return tokenAccount;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export async function getMaybeVoteAccount(
|
|
237
|
+
address: string,
|
|
238
|
+
api: ChainAPI,
|
|
239
|
+
): Promise<VoteAccountInfo | undefined | Error> {
|
|
240
|
+
const accInfo = await api.getAccountInfo(address);
|
|
241
|
+
const voteAccount =
|
|
242
|
+
accInfo !== null && "parsed" in accInfo.data ? tryParseAsVoteAccount(accInfo.data) : undefined;
|
|
243
|
+
|
|
244
|
+
return voteAccount;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function getStakeAccountMinimumBalanceForRentExemption(api: ChainAPI) {
|
|
248
|
+
return api.getMinimumBalanceForRentExemption(StakeProgram.space);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export async function getAccountMinimumBalanceForRentExemption(api: ChainAPI, address: string) {
|
|
252
|
+
const accInfo = await api.getAccountInfo(address);
|
|
253
|
+
const accSpace = accInfo !== null && "parsed" in accInfo.data ? accInfo.data.space : 0;
|
|
254
|
+
|
|
255
|
+
return api.getMinimumBalanceForRentExemption(accSpace);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export async function getStakeAccountAddressWithSeed({
|
|
259
|
+
fromAddress,
|
|
260
|
+
seed,
|
|
261
|
+
}: {
|
|
262
|
+
fromAddress: string;
|
|
263
|
+
seed: string;
|
|
264
|
+
}) {
|
|
265
|
+
const pubkey = await PublicKey.createWithSeed(
|
|
266
|
+
new PublicKey(fromAddress),
|
|
267
|
+
seed,
|
|
268
|
+
StakeProgram.programId,
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
return pubkey.toBase58();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function buildCreateAssociatedTokenAccountInstruction({
|
|
275
|
+
mint,
|
|
276
|
+
owner,
|
|
277
|
+
associatedTokenAccountAddress,
|
|
278
|
+
}: TokenCreateATACommand): TransactionInstruction[] {
|
|
279
|
+
const ownerPubKey = new PublicKey(owner);
|
|
280
|
+
const mintPubkey = new PublicKey(mint);
|
|
281
|
+
const associatedTokenAccPubkey = new PublicKey(associatedTokenAccountAddress);
|
|
282
|
+
|
|
283
|
+
const instructions: TransactionInstruction[] = [
|
|
284
|
+
createAssociatedTokenAccountInstruction(
|
|
285
|
+
ownerPubKey,
|
|
286
|
+
associatedTokenAccPubkey,
|
|
287
|
+
ownerPubKey,
|
|
288
|
+
mintPubkey,
|
|
289
|
+
),
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
return instructions;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function buildStakeDelegateInstructions({
|
|
296
|
+
authorizedAccAddr,
|
|
297
|
+
stakeAccAddr,
|
|
298
|
+
voteAccAddr,
|
|
299
|
+
}: StakeDelegateCommand): TransactionInstruction[] {
|
|
300
|
+
const tx = StakeProgram.delegate({
|
|
301
|
+
authorizedPubkey: new PublicKey(authorizedAccAddr),
|
|
302
|
+
stakePubkey: new PublicKey(stakeAccAddr),
|
|
303
|
+
votePubkey: new PublicKey(voteAccAddr),
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
return tx.instructions;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function buildStakeUndelegateInstructions({
|
|
310
|
+
authorizedAccAddr,
|
|
311
|
+
stakeAccAddr,
|
|
312
|
+
}: StakeUndelegateCommand): TransactionInstruction[] {
|
|
313
|
+
const tx = StakeProgram.deactivate({
|
|
314
|
+
authorizedPubkey: new PublicKey(authorizedAccAddr),
|
|
315
|
+
stakePubkey: new PublicKey(stakeAccAddr),
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
return tx.instructions;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function buildStakeWithdrawInstructions({
|
|
322
|
+
authorizedAccAddr,
|
|
323
|
+
stakeAccAddr,
|
|
324
|
+
amount,
|
|
325
|
+
toAccAddr,
|
|
326
|
+
}: StakeWithdrawCommand): TransactionInstruction[] {
|
|
327
|
+
const tx = StakeProgram.withdraw({
|
|
328
|
+
authorizedPubkey: new PublicKey(authorizedAccAddr),
|
|
329
|
+
stakePubkey: new PublicKey(stakeAccAddr),
|
|
330
|
+
lamports: amount,
|
|
331
|
+
toPubkey: new PublicKey(toAccAddr),
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
return tx.instructions;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function buildStakeSplitInstructions({
|
|
338
|
+
authorizedAccAddr,
|
|
339
|
+
stakeAccAddr,
|
|
340
|
+
seed,
|
|
341
|
+
amount,
|
|
342
|
+
splitStakeAccAddr,
|
|
343
|
+
}: StakeSplitCommand): TransactionInstruction[] {
|
|
344
|
+
// HACK: switch to split_with_seed when supported by @solana/web3.js
|
|
345
|
+
const splitIx = StakeProgram.split({
|
|
346
|
+
authorizedPubkey: new PublicKey(authorizedAccAddr),
|
|
347
|
+
lamports: amount,
|
|
348
|
+
stakePubkey: new PublicKey(stakeAccAddr),
|
|
349
|
+
splitStakePubkey: new PublicKey(splitStakeAccAddr),
|
|
350
|
+
}).instructions[1];
|
|
351
|
+
|
|
352
|
+
if (splitIx === undefined) {
|
|
353
|
+
throw new Error("expected split instruction");
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const allocateIx = SystemProgram.allocate({
|
|
357
|
+
accountPubkey: new PublicKey(splitStakeAccAddr),
|
|
358
|
+
basePubkey: new PublicKey(authorizedAccAddr),
|
|
359
|
+
programId: StakeProgram.programId,
|
|
360
|
+
seed,
|
|
361
|
+
space: StakeProgram.space,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
return [allocateIx, splitIx];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export function buildStakeCreateAccountInstructions({
|
|
368
|
+
fromAccAddress,
|
|
369
|
+
stakeAccAddress,
|
|
370
|
+
seed,
|
|
371
|
+
amount,
|
|
372
|
+
stakeAccRentExemptAmount,
|
|
373
|
+
delegate,
|
|
374
|
+
}: StakeCreateAccountCommand): TransactionInstruction[] {
|
|
375
|
+
const fromPubkey = new PublicKey(fromAccAddress);
|
|
376
|
+
const stakePubkey = new PublicKey(stakeAccAddress);
|
|
377
|
+
|
|
378
|
+
const tx = StakeProgram.createAccountWithSeed({
|
|
379
|
+
fromPubkey,
|
|
380
|
+
stakePubkey,
|
|
381
|
+
basePubkey: fromPubkey,
|
|
382
|
+
seed,
|
|
383
|
+
lamports: amount + stakeAccRentExemptAmount,
|
|
384
|
+
authorized: {
|
|
385
|
+
staker: fromPubkey,
|
|
386
|
+
withdrawer: fromPubkey,
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
tx.add(
|
|
391
|
+
StakeProgram.delegate({
|
|
392
|
+
authorizedPubkey: fromPubkey,
|
|
393
|
+
stakePubkey,
|
|
394
|
+
votePubkey: new PublicKey(delegate.voteAccAddress),
|
|
395
|
+
}),
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
return tx.instructions;
|
|
399
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ChainAPI } from "./chain";
|
|
2
|
+
|
|
3
|
+
//import fs from "fs";
|
|
4
|
+
import { Message, PublicKey } from "@solana/web3.js";
|
|
5
|
+
import { LATEST_BLOCKHASH_MOCK } from "./chain";
|
|
6
|
+
|
|
7
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
8
|
+
function write(file: string, str: string) {
|
|
9
|
+
// fs is not available on mobile
|
|
10
|
+
//fs.appendFileSync(file, str);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function logged(api: ChainAPI, file: string): ChainAPI {
|
|
14
|
+
const proxy: ChainAPI = new Proxy(api, {
|
|
15
|
+
get(target, propKey, receiver) {
|
|
16
|
+
if (typeof propKey === "symbol") {
|
|
17
|
+
throw new Error("symbols not supported");
|
|
18
|
+
}
|
|
19
|
+
const targetValue = Reflect.get(target, propKey, receiver);
|
|
20
|
+
if (typeof targetValue === "function") {
|
|
21
|
+
const method: keyof ChainAPI = propKey as any;
|
|
22
|
+
return function (...args: unknown[]) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
+
// @ts-ignore: TS-2683
|
|
25
|
+
const result = targetValue.apply(this, args);
|
|
26
|
+
const log = (answer: unknown) => {
|
|
27
|
+
if (method === "getLatestBlockhash") {
|
|
28
|
+
// add getLatestBlockhash manually to mock data to with mocked block hash
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (method === "getFeeForMessage") {
|
|
33
|
+
// getFeeForMessage arg message must be serialized since it's a class
|
|
34
|
+
if (args.length === 1 && args[0] instanceof Message) {
|
|
35
|
+
args[0].recentBlockhash = LATEST_BLOCKHASH_MOCK;
|
|
36
|
+
(args as any) = [args[0].serialize().toString("base64")];
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error("unexpected getFeeForMessage function signature");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const paramsJson = JSON.stringify(args);
|
|
42
|
+
const publicKeytoJSON = PublicKey.prototype.toJSON;
|
|
43
|
+
// @ts-expect-error hack to temporary remove toJSON so it doesn't affect JSON.stringify
|
|
44
|
+
delete PublicKey.prototype.toJSON;
|
|
45
|
+
const answerJson = JSON.stringify(answer).replace(
|
|
46
|
+
/{"_bn":(".*?")}/g,
|
|
47
|
+
"new PublicKey(Buffer.from($1, 'hex'))",
|
|
48
|
+
);
|
|
49
|
+
PublicKey.prototype.toJSON = publicKeytoJSON;
|
|
50
|
+
const summaryJson = `{"method":"${method}", "params":${paramsJson},"answer":${answerJson}}`;
|
|
51
|
+
write(file, summaryJson + ",\n");
|
|
52
|
+
};
|
|
53
|
+
if (result instanceof Promise) {
|
|
54
|
+
return result.then(answer => {
|
|
55
|
+
log(answer);
|
|
56
|
+
return answer;
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
log(result);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
64
|
+
return targetValue;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return proxy;
|
|
70
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { asyncQueue } from "../utils";
|
|
2
|
+
import { ChainAPI } from "./chain";
|
|
3
|
+
|
|
4
|
+
export function queued(api: ChainAPI, delayBetweenRuns = 100): ChainAPI {
|
|
5
|
+
const q = asyncQueue({
|
|
6
|
+
delayBetweenRuns,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const proxy: ChainAPI = new Proxy(api, {
|
|
10
|
+
get(target, propKey, receiver) {
|
|
11
|
+
const targetValue = Reflect.get(target, propKey, receiver);
|
|
12
|
+
if (typeof targetValue === "function") {
|
|
13
|
+
return function (...args: unknown[]) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
15
|
+
// @ts-ignore: TS-2683
|
|
16
|
+
return q.submit(() => targetValue.apply(this, args));
|
|
17
|
+
};
|
|
18
|
+
} else {
|
|
19
|
+
return targetValue;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return proxy;
|
|
25
|
+
}
|