@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,729 @@
|
|
|
1
|
+
import { AccountShapeInfo, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
import { emptyHistoryCache, encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
5
|
+
import {
|
|
6
|
+
getAccountMinimumBalanceForRentExemption,
|
|
7
|
+
getTransactions,
|
|
8
|
+
ParsedOnChainStakeAccountWithInfo,
|
|
9
|
+
toStakeAccountWithInfo,
|
|
10
|
+
TransactionDescriptor,
|
|
11
|
+
} from "./api/chain/web3";
|
|
12
|
+
import { getTokenById } from "@ledgerhq/cryptoassets";
|
|
13
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
14
|
+
import {
|
|
15
|
+
Awaited,
|
|
16
|
+
encodeAccountIdWithTokenAccountAddress,
|
|
17
|
+
isStakeLockUpInForce,
|
|
18
|
+
tokenIsListedOnLedger,
|
|
19
|
+
toTokenId,
|
|
20
|
+
toTokenMint,
|
|
21
|
+
withdrawableFromStake,
|
|
22
|
+
} from "./logic";
|
|
23
|
+
import {
|
|
24
|
+
compact,
|
|
25
|
+
filter,
|
|
26
|
+
groupBy,
|
|
27
|
+
keyBy,
|
|
28
|
+
toPairs,
|
|
29
|
+
pipe,
|
|
30
|
+
map,
|
|
31
|
+
uniqBy,
|
|
32
|
+
flow,
|
|
33
|
+
sortBy,
|
|
34
|
+
sum,
|
|
35
|
+
} from "lodash/fp";
|
|
36
|
+
import { parseQuiet } from "./api/chain/program";
|
|
37
|
+
import {
|
|
38
|
+
InflationReward,
|
|
39
|
+
ParsedTransactionMeta,
|
|
40
|
+
ParsedMessageAccount,
|
|
41
|
+
ParsedTransaction,
|
|
42
|
+
StakeActivationData,
|
|
43
|
+
} from "@solana/web3.js";
|
|
44
|
+
import { ChainAPI } from "./api";
|
|
45
|
+
import {
|
|
46
|
+
ParsedOnChainTokenAccountWithInfo,
|
|
47
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
48
|
+
toTokenAccountWithInfo,
|
|
49
|
+
} from "./api/chain/web3";
|
|
50
|
+
import { drainSeq } from "./utils";
|
|
51
|
+
import { estimateTxFee } from "./tx-fees";
|
|
52
|
+
import { SolanaAccount, SolanaOperationExtra, SolanaStake } from "./types";
|
|
53
|
+
import { Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
|
|
54
|
+
import { DelegateInfo, WithdrawInfo } from "./api/chain/instruction/stake/types";
|
|
55
|
+
|
|
56
|
+
type OnChainTokenAccount = Awaited<ReturnType<typeof getAccount>>["tokenAccounts"][number];
|
|
57
|
+
|
|
58
|
+
export const getAccountShapeWithAPI = async (
|
|
59
|
+
info: AccountShapeInfo,
|
|
60
|
+
api: ChainAPI,
|
|
61
|
+
): Promise<Partial<SolanaAccount>> => {
|
|
62
|
+
const {
|
|
63
|
+
address: mainAccAddress,
|
|
64
|
+
initialAccount: mainInitialAcc,
|
|
65
|
+
currency,
|
|
66
|
+
derivationMode,
|
|
67
|
+
} = info;
|
|
68
|
+
|
|
69
|
+
const {
|
|
70
|
+
blockHeight,
|
|
71
|
+
balance: mainAccBalance,
|
|
72
|
+
tokenAccounts: onChaintokenAccounts,
|
|
73
|
+
stakes: onChainStakes,
|
|
74
|
+
} = await getAccount(mainAccAddress, api);
|
|
75
|
+
|
|
76
|
+
const mainAccountId = encodeAccountId({
|
|
77
|
+
type: "js",
|
|
78
|
+
version: "2",
|
|
79
|
+
currencyId: currency.id,
|
|
80
|
+
xpubOrAddress: mainAccAddress,
|
|
81
|
+
derivationMode,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const onChainTokenAccsByMint = pipe(
|
|
85
|
+
() => onChaintokenAccounts,
|
|
86
|
+
groupBy(({ info: { mint } }) => mint.toBase58()),
|
|
87
|
+
v => new Map(toPairs(v)),
|
|
88
|
+
)();
|
|
89
|
+
|
|
90
|
+
const subAccByMint = pipe(
|
|
91
|
+
() => mainInitialAcc?.subAccounts ?? [],
|
|
92
|
+
filter((subAcc): subAcc is TokenAccount => subAcc.type === "TokenAccount"),
|
|
93
|
+
keyBy(subAcc => toTokenMint(subAcc.token.id)),
|
|
94
|
+
v => new Map(toPairs(v)),
|
|
95
|
+
)();
|
|
96
|
+
|
|
97
|
+
const nextSubAccs: TokenAccount[] = [];
|
|
98
|
+
|
|
99
|
+
for (const [mint, accs] of onChainTokenAccsByMint.entries()) {
|
|
100
|
+
if (!tokenIsListedOnLedger(mint)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const assocTokenAccAddress = await api.findAssocTokenAccAddress(mainAccAddress, mint);
|
|
105
|
+
|
|
106
|
+
const assocTokenAcc = accs.find(
|
|
107
|
+
({ onChainAcc: { pubkey } }) => pubkey.toBase58() === assocTokenAccAddress,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (assocTokenAcc === undefined) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const subAcc = subAccByMint.get(mint);
|
|
115
|
+
|
|
116
|
+
const lastSyncedTxSignature = subAcc?.operations?.[0].hash;
|
|
117
|
+
|
|
118
|
+
const txs = await getTransactions(
|
|
119
|
+
assocTokenAcc.onChainAcc.pubkey.toBase58(),
|
|
120
|
+
lastSyncedTxSignature,
|
|
121
|
+
api,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const nextSubAcc =
|
|
125
|
+
subAcc === undefined
|
|
126
|
+
? newSubAcc({
|
|
127
|
+
mainAccountId,
|
|
128
|
+
assocTokenAcc,
|
|
129
|
+
txs,
|
|
130
|
+
})
|
|
131
|
+
: patchedSubAcc({
|
|
132
|
+
subAcc,
|
|
133
|
+
assocTokenAcc,
|
|
134
|
+
txs,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
nextSubAccs.push(nextSubAcc);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const { epoch } = await api.getEpochInfo();
|
|
141
|
+
|
|
142
|
+
const stakes: SolanaStake[] = onChainStakes.map(({ account, activation, reward }) => {
|
|
143
|
+
const {
|
|
144
|
+
info: { meta, stake },
|
|
145
|
+
} = account;
|
|
146
|
+
const rentExemptReserve = account.info.meta.rentExemptReserve.toNumber();
|
|
147
|
+
const stakeAccBalance = account.onChainAcc.account.lamports;
|
|
148
|
+
const hasWithdrawAuth =
|
|
149
|
+
meta.authorized.withdrawer.toBase58() === mainAccAddress &&
|
|
150
|
+
!isStakeLockUpInForce({
|
|
151
|
+
lockup: meta.lockup,
|
|
152
|
+
custodianAddress: mainAccAddress,
|
|
153
|
+
epoch,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
stakeAccAddr: account.onChainAcc.pubkey.toBase58(),
|
|
158
|
+
stakeAccBalance,
|
|
159
|
+
rentExemptReserve,
|
|
160
|
+
hasStakeAuth: meta.authorized.staker.toBase58() === mainAccAddress,
|
|
161
|
+
hasWithdrawAuth,
|
|
162
|
+
delegation:
|
|
163
|
+
stake === null
|
|
164
|
+
? undefined
|
|
165
|
+
: {
|
|
166
|
+
stake: activation.state === "inactive" ? 0 : stake.delegation.stake.toNumber(),
|
|
167
|
+
voteAccAddr: stake.delegation.voter.toBase58(),
|
|
168
|
+
},
|
|
169
|
+
activation,
|
|
170
|
+
withdrawable: hasWithdrawAuth
|
|
171
|
+
? withdrawableFromStake({
|
|
172
|
+
stakeAccBalance,
|
|
173
|
+
activation,
|
|
174
|
+
rentExemptReserve,
|
|
175
|
+
})
|
|
176
|
+
: 0,
|
|
177
|
+
reward:
|
|
178
|
+
reward === null
|
|
179
|
+
? undefined
|
|
180
|
+
: {
|
|
181
|
+
amount: reward.amount,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const sortedStakes = flow(
|
|
187
|
+
() => stakes,
|
|
188
|
+
sortBy([
|
|
189
|
+
stake => -(stake.delegation?.stake ?? 0),
|
|
190
|
+
stake => -stake.withdrawable,
|
|
191
|
+
stake => -stake.stakeAccAddr,
|
|
192
|
+
]),
|
|
193
|
+
)();
|
|
194
|
+
|
|
195
|
+
const mainAccountLastTxSignature = mainInitialAcc?.operations[0]?.hash;
|
|
196
|
+
|
|
197
|
+
const newMainAccTxs = await getTransactions(mainAccAddress, mainAccountLastTxSignature, api);
|
|
198
|
+
|
|
199
|
+
const lastOpSeqNumber = mainInitialAcc?.operations?.[0]?.transactionSequenceNumber ?? 0;
|
|
200
|
+
const newOpsCount = newMainAccTxs.length;
|
|
201
|
+
|
|
202
|
+
const newMainAccOps = newMainAccTxs
|
|
203
|
+
.map((tx, i) =>
|
|
204
|
+
txToMainAccOperation(
|
|
205
|
+
tx,
|
|
206
|
+
mainAccountId,
|
|
207
|
+
mainAccAddress,
|
|
208
|
+
// transactions are ordered by date (0'th - most recent tx)
|
|
209
|
+
lastOpSeqNumber + newOpsCount - i,
|
|
210
|
+
),
|
|
211
|
+
)
|
|
212
|
+
.filter((op): op is Operation => op !== undefined);
|
|
213
|
+
|
|
214
|
+
const mainAccTotalOperations = mergeOps(mainInitialAcc?.operations ?? [], newMainAccOps);
|
|
215
|
+
|
|
216
|
+
const totalStakedBalance = sum(stakes.map(s => s.stakeAccBalance));
|
|
217
|
+
|
|
218
|
+
const mainAccountRentExempt = await getAccountMinimumBalanceForRentExemption(api, mainAccAddress);
|
|
219
|
+
|
|
220
|
+
let unstakeReserve = 0;
|
|
221
|
+
if (stakes.length > 0) {
|
|
222
|
+
const undelegateFee = await estimateTxFee(api, mainAccAddress, "stake.undelegate");
|
|
223
|
+
const withdrawFee = await estimateTxFee(api, mainAccAddress, "stake.withdraw");
|
|
224
|
+
|
|
225
|
+
const activeStakes = stakes.filter(
|
|
226
|
+
s => s.activation.state == "active" || s.activation.state == "activating",
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// "active" and "activating" stakes require "deactivating" + "withdrawing" steps
|
|
230
|
+
// "inactive" and "deactivating" stakes require withdrawing only
|
|
231
|
+
unstakeReserve = stakes.length * withdrawFee + activeStakes.length * undelegateFee;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const shape: Partial<SolanaAccount> = {
|
|
235
|
+
// uncomment when tokens are supported
|
|
236
|
+
// subAccounts as undefined makes TokenList disappear in desktop
|
|
237
|
+
//subAccounts: nextSubAccs,
|
|
238
|
+
id: mainAccountId,
|
|
239
|
+
blockHeight,
|
|
240
|
+
balance: mainAccBalance.plus(totalStakedBalance),
|
|
241
|
+
spendableBalance: BigNumber.max(
|
|
242
|
+
mainAccBalance.minus(mainAccountRentExempt).minus(unstakeReserve),
|
|
243
|
+
0,
|
|
244
|
+
),
|
|
245
|
+
operations: mainAccTotalOperations,
|
|
246
|
+
operationsCount: mainAccTotalOperations.length,
|
|
247
|
+
solanaResources: {
|
|
248
|
+
stakes: sortedStakes,
|
|
249
|
+
unstakeReserve: BigNumber.min(
|
|
250
|
+
unstakeReserve,
|
|
251
|
+
BigNumber.max(mainAccBalance.minus(mainAccountRentExempt), 0),
|
|
252
|
+
),
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
return shape;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
function newSubAcc({
|
|
260
|
+
mainAccountId,
|
|
261
|
+
assocTokenAcc,
|
|
262
|
+
txs,
|
|
263
|
+
}: {
|
|
264
|
+
mainAccountId: string;
|
|
265
|
+
assocTokenAcc: OnChainTokenAccount;
|
|
266
|
+
txs: TransactionDescriptor[];
|
|
267
|
+
}): TokenAccount {
|
|
268
|
+
const firstTx = txs[txs.length - 1];
|
|
269
|
+
|
|
270
|
+
const creationDate = new Date((firstTx.info.blockTime ?? Date.now() / 1000) * 1000);
|
|
271
|
+
|
|
272
|
+
const tokenId = toTokenId(assocTokenAcc.info.mint.toBase58());
|
|
273
|
+
const tokenCurrency = getTokenById(tokenId);
|
|
274
|
+
|
|
275
|
+
const accosTokenAccPubkey = assocTokenAcc.onChainAcc.pubkey;
|
|
276
|
+
|
|
277
|
+
const accountId = encodeAccountIdWithTokenAccountAddress(
|
|
278
|
+
mainAccountId,
|
|
279
|
+
accosTokenAccPubkey.toBase58(),
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const balance = new BigNumber(assocTokenAcc.info.tokenAmount.amount);
|
|
283
|
+
|
|
284
|
+
const newOps = compact(txs.map(tx => txToTokenAccOperation(tx, assocTokenAcc, accountId)));
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
balance,
|
|
288
|
+
balanceHistoryCache: emptyHistoryCache,
|
|
289
|
+
creationDate,
|
|
290
|
+
id: accountId,
|
|
291
|
+
parentId: mainAccountId,
|
|
292
|
+
operations: mergeOps([], newOps),
|
|
293
|
+
operationsCount: txs.length,
|
|
294
|
+
pendingOperations: [],
|
|
295
|
+
spendableBalance: balance,
|
|
296
|
+
swapHistory: [],
|
|
297
|
+
token: tokenCurrency,
|
|
298
|
+
type: "TokenAccount",
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function patchedSubAcc({
|
|
303
|
+
subAcc,
|
|
304
|
+
assocTokenAcc,
|
|
305
|
+
txs,
|
|
306
|
+
}: {
|
|
307
|
+
subAcc: TokenAccount;
|
|
308
|
+
assocTokenAcc: OnChainTokenAccount;
|
|
309
|
+
txs: TransactionDescriptor[];
|
|
310
|
+
}): TokenAccount {
|
|
311
|
+
const balance = new BigNumber(assocTokenAcc.info.tokenAmount.amount);
|
|
312
|
+
|
|
313
|
+
const newOps = compact(txs.map(tx => txToTokenAccOperation(tx, assocTokenAcc, subAcc.id)));
|
|
314
|
+
|
|
315
|
+
const totalOps = mergeOps(subAcc.operations, newOps);
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
...subAcc,
|
|
319
|
+
balance,
|
|
320
|
+
spendableBalance: balance,
|
|
321
|
+
operations: totalOps,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function txToMainAccOperation(
|
|
326
|
+
tx: TransactionDescriptor,
|
|
327
|
+
accountId: string,
|
|
328
|
+
accountAddress: string,
|
|
329
|
+
txSeqNumber: number,
|
|
330
|
+
): Operation | undefined {
|
|
331
|
+
if (!tx.info.blockTime || !tx.parsed.meta) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const { message } = tx.parsed.transaction;
|
|
336
|
+
|
|
337
|
+
const accountIndex = message.accountKeys.findIndex(
|
|
338
|
+
pma => pma.pubkey.toBase58() === accountAddress,
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
if (accountIndex < 0) {
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const { preBalances, postBalances } = tx.parsed.meta;
|
|
346
|
+
|
|
347
|
+
const balanceDelta = new BigNumber(postBalances[accountIndex]).minus(
|
|
348
|
+
new BigNumber(preBalances[accountIndex]),
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
const isFeePayer = accountIndex === 0;
|
|
352
|
+
const txFee = new BigNumber(tx.parsed.meta.fee);
|
|
353
|
+
|
|
354
|
+
const opType = getMainAccOperationType({
|
|
355
|
+
tx: tx.parsed.transaction,
|
|
356
|
+
fee: txFee,
|
|
357
|
+
isFeePayer,
|
|
358
|
+
balanceDelta,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
const accum = {
|
|
362
|
+
senders: [] as string[],
|
|
363
|
+
recipients: [] as string[],
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const { senders, recipients } =
|
|
367
|
+
opType === "IN" || opType === "OUT"
|
|
368
|
+
? message.accountKeys.reduce((acc, account, i) => {
|
|
369
|
+
const delta = new BigNumber(postBalances[i]).minus(new BigNumber(preBalances[i]));
|
|
370
|
+
if (delta.lt(0)) {
|
|
371
|
+
const shouldConsiderAsSender = i > 0 || !delta.negated().eq(txFee);
|
|
372
|
+
if (shouldConsiderAsSender) {
|
|
373
|
+
acc.senders.push(account.pubkey.toBase58());
|
|
374
|
+
}
|
|
375
|
+
} else if (delta.gt(0)) {
|
|
376
|
+
acc.recipients.push(account.pubkey.toBase58());
|
|
377
|
+
}
|
|
378
|
+
return acc;
|
|
379
|
+
}, accum)
|
|
380
|
+
: accum;
|
|
381
|
+
|
|
382
|
+
const txHash = tx.info.signature;
|
|
383
|
+
const txDate = new Date(tx.info.blockTime * 1000);
|
|
384
|
+
|
|
385
|
+
const opFee = isFeePayer ? txFee : new BigNumber(0);
|
|
386
|
+
const opValue = getOpValue(balanceDelta, opFee, opType);
|
|
387
|
+
|
|
388
|
+
return {
|
|
389
|
+
id: encodeOperationId(accountId, txHash, opType),
|
|
390
|
+
hash: txHash,
|
|
391
|
+
accountId: accountId,
|
|
392
|
+
hasFailed: !!tx.info.err,
|
|
393
|
+
blockHeight: tx.info.slot,
|
|
394
|
+
blockHash: message.recentBlockhash,
|
|
395
|
+
extra: getOpExtra(tx, balanceDelta, opType),
|
|
396
|
+
type: opType,
|
|
397
|
+
senders,
|
|
398
|
+
recipients,
|
|
399
|
+
date: txDate,
|
|
400
|
+
value: opValue,
|
|
401
|
+
fee: opFee,
|
|
402
|
+
transactionSequenceNumber: txSeqNumber,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function getOpValue(balanceDelta: BigNumber, opFee: BigNumber, opType: OperationType): BigNumber {
|
|
407
|
+
const value = balanceDelta.abs();
|
|
408
|
+
switch (opType) {
|
|
409
|
+
case "DELEGATE":
|
|
410
|
+
case "WITHDRAW_UNBONDED":
|
|
411
|
+
return opFee;
|
|
412
|
+
case "OPT_OUT":
|
|
413
|
+
return value.negated();
|
|
414
|
+
default:
|
|
415
|
+
return value;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function getOpExtra(
|
|
420
|
+
tx: TransactionDescriptor,
|
|
421
|
+
balanceDelta: BigNumber,
|
|
422
|
+
opType: OperationType,
|
|
423
|
+
): SolanaOperationExtra {
|
|
424
|
+
const extra: SolanaOperationExtra = {};
|
|
425
|
+
const { instructions } = tx.parsed.transaction.message;
|
|
426
|
+
const parsedIxs = instructions
|
|
427
|
+
.map(ix => parseQuiet(ix))
|
|
428
|
+
.filter(({ program }) => program !== "spl-memo");
|
|
429
|
+
|
|
430
|
+
if (tx.info.memo !== null) {
|
|
431
|
+
extra.memo = dropMemoLengthPrefixIfAny(tx.info.memo);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (opType === "DELEGATE") {
|
|
435
|
+
const delegateInfo = parsedIxs.find(
|
|
436
|
+
ix => ix.program === "stake" && ix.instruction?.type === "delegate",
|
|
437
|
+
)?.instruction?.info as DelegateInfo;
|
|
438
|
+
if (!delegateInfo) return extra;
|
|
439
|
+
|
|
440
|
+
extra.stake = {
|
|
441
|
+
address: delegateInfo.voteAccount.toBase58(),
|
|
442
|
+
amount: balanceDelta.abs(),
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (opType === "WITHDRAW_UNBONDED") {
|
|
447
|
+
const withdrawInfo = parsedIxs.find(
|
|
448
|
+
ix => ix.program === "stake" && ix.instruction?.type === "withdraw",
|
|
449
|
+
)?.instruction?.info as WithdrawInfo;
|
|
450
|
+
if (!withdrawInfo) return extra;
|
|
451
|
+
|
|
452
|
+
extra.stake = {
|
|
453
|
+
address: withdrawInfo.stakeAccount.toBase58(),
|
|
454
|
+
amount: new BigNumber(withdrawInfo.lamports),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return extra;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function txToTokenAccOperation(
|
|
462
|
+
tx: TransactionDescriptor,
|
|
463
|
+
assocTokenAcc: OnChainTokenAccount,
|
|
464
|
+
accountId: string,
|
|
465
|
+
): Operation | undefined {
|
|
466
|
+
if (!tx.info.blockTime || !tx.parsed.meta) {
|
|
467
|
+
return undefined;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const assocTokenAccIndex = tx.parsed.transaction.message.accountKeys.findIndex(v =>
|
|
471
|
+
v.pubkey.equals(assocTokenAcc.onChainAcc.pubkey),
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
if (assocTokenAccIndex < 0) {
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const { preTokenBalances, postTokenBalances } = tx.parsed.meta;
|
|
479
|
+
|
|
480
|
+
const preTokenBalance = preTokenBalances?.find(b => b.accountIndex === assocTokenAccIndex);
|
|
481
|
+
|
|
482
|
+
const postTokenBalance = postTokenBalances?.find(b => b.accountIndex === assocTokenAccIndex);
|
|
483
|
+
|
|
484
|
+
const delta = new BigNumber(postTokenBalance?.uiTokenAmount.amount ?? 0).minus(
|
|
485
|
+
new BigNumber(preTokenBalance?.uiTokenAmount.amount ?? 0),
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
const opType = getTokenAccOperationType({ tx: tx.parsed.transaction, delta });
|
|
489
|
+
|
|
490
|
+
const txHash = tx.info.signature;
|
|
491
|
+
|
|
492
|
+
const { senders, recipients } = getTokenSendersRecipients({
|
|
493
|
+
meta: tx.parsed.meta,
|
|
494
|
+
accounts: tx.parsed.transaction.message.accountKeys,
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
return {
|
|
498
|
+
id: encodeOperationId(accountId, txHash, opType),
|
|
499
|
+
accountId,
|
|
500
|
+
type: opType,
|
|
501
|
+
hash: txHash,
|
|
502
|
+
date: new Date(tx.info.blockTime * 1000),
|
|
503
|
+
blockHeight: tx.info.slot,
|
|
504
|
+
fee: new BigNumber(0),
|
|
505
|
+
recipients,
|
|
506
|
+
senders,
|
|
507
|
+
value: delta.abs(),
|
|
508
|
+
hasFailed: !!tx.info.err,
|
|
509
|
+
extra: getOpExtra(tx, delta, opType),
|
|
510
|
+
blockHash: tx.parsed.transaction.message.recentBlockhash,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function getMainAccOperationType({
|
|
515
|
+
tx,
|
|
516
|
+
fee,
|
|
517
|
+
isFeePayer,
|
|
518
|
+
balanceDelta,
|
|
519
|
+
}: {
|
|
520
|
+
tx: ParsedTransaction;
|
|
521
|
+
fee: BigNumber;
|
|
522
|
+
isFeePayer: boolean;
|
|
523
|
+
balanceDelta: BigNumber;
|
|
524
|
+
}): OperationType {
|
|
525
|
+
const type = getMainAccOperationTypeFromTx(tx);
|
|
526
|
+
|
|
527
|
+
if (type !== undefined) {
|
|
528
|
+
return type;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return isFeePayer && balanceDelta.negated().eq(fee)
|
|
532
|
+
? "FEES"
|
|
533
|
+
: balanceDelta.lt(0)
|
|
534
|
+
? "OUT"
|
|
535
|
+
: balanceDelta.gt(0)
|
|
536
|
+
? "IN"
|
|
537
|
+
: "NONE";
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function getMainAccOperationTypeFromTx(tx: ParsedTransaction): OperationType | undefined {
|
|
541
|
+
const { instructions } = tx.message;
|
|
542
|
+
|
|
543
|
+
const parsedIxs = instructions
|
|
544
|
+
.map(ix => parseQuiet(ix))
|
|
545
|
+
.filter(({ program }) => program !== "spl-memo");
|
|
546
|
+
|
|
547
|
+
if (parsedIxs.length === 3) {
|
|
548
|
+
const [first, second, third] = parsedIxs;
|
|
549
|
+
if (
|
|
550
|
+
first.program === "system" &&
|
|
551
|
+
(first.instruction.type === "createAccountWithSeed" ||
|
|
552
|
+
first.instruction.type === "createAccount") &&
|
|
553
|
+
second.program === "stake" &&
|
|
554
|
+
second.instruction.type === "initialize" &&
|
|
555
|
+
third.program === "stake" &&
|
|
556
|
+
third.instruction.type === "delegate"
|
|
557
|
+
) {
|
|
558
|
+
return "DELEGATE";
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (parsedIxs.length === 1) {
|
|
563
|
+
const first = parsedIxs[0];
|
|
564
|
+
|
|
565
|
+
switch (first.program) {
|
|
566
|
+
case "spl-associated-token-account":
|
|
567
|
+
switch (first.instruction.type) {
|
|
568
|
+
case "associate":
|
|
569
|
+
return "OPT_IN";
|
|
570
|
+
}
|
|
571
|
+
// needed for lint
|
|
572
|
+
break;
|
|
573
|
+
case "spl-token":
|
|
574
|
+
switch (first.instruction.type) {
|
|
575
|
+
case "closeAccount":
|
|
576
|
+
return "OPT_OUT";
|
|
577
|
+
}
|
|
578
|
+
break;
|
|
579
|
+
case "stake":
|
|
580
|
+
switch (first.instruction.type) {
|
|
581
|
+
case "delegate":
|
|
582
|
+
return "DELEGATE";
|
|
583
|
+
case "deactivate":
|
|
584
|
+
return "UNDELEGATE";
|
|
585
|
+
case "withdraw":
|
|
586
|
+
return "WITHDRAW_UNBONDED";
|
|
587
|
+
}
|
|
588
|
+
break;
|
|
589
|
+
default:
|
|
590
|
+
return undefined;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return undefined;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function getTokenSendersRecipients({
|
|
598
|
+
meta,
|
|
599
|
+
accounts,
|
|
600
|
+
}: {
|
|
601
|
+
meta: ParsedTransactionMeta;
|
|
602
|
+
accounts: ParsedMessageAccount[];
|
|
603
|
+
}) {
|
|
604
|
+
const { preTokenBalances, postTokenBalances } = meta;
|
|
605
|
+
return accounts.reduce(
|
|
606
|
+
(accum, account, i) => {
|
|
607
|
+
const preTokenBalance = preTokenBalances?.find(b => b.accountIndex === i);
|
|
608
|
+
const postTokenBalance = postTokenBalances?.find(b => b.accountIndex === i);
|
|
609
|
+
if (preTokenBalance && postTokenBalance) {
|
|
610
|
+
const tokenDelta = new BigNumber(postTokenBalance.uiTokenAmount.amount).minus(
|
|
611
|
+
new BigNumber(preTokenBalance.uiTokenAmount.amount),
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
if (tokenDelta.lt(0)) {
|
|
615
|
+
accum.senders.push(account.pubkey.toBase58());
|
|
616
|
+
} else if (tokenDelta.gt(0)) {
|
|
617
|
+
accum.recipients.push(account.pubkey.toBase58());
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return accum;
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
senders: [] as string[],
|
|
624
|
+
recipients: [] as string[],
|
|
625
|
+
},
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function getTokenAccOperationType({
|
|
630
|
+
tx,
|
|
631
|
+
delta,
|
|
632
|
+
}: {
|
|
633
|
+
tx: ParsedTransaction;
|
|
634
|
+
delta: BigNumber;
|
|
635
|
+
}): OperationType {
|
|
636
|
+
const { instructions } = tx.message;
|
|
637
|
+
const [mainIx, ...otherIxs] = instructions
|
|
638
|
+
.map(ix => parseQuiet(ix))
|
|
639
|
+
.filter(({ program }) => program !== "spl-memo");
|
|
640
|
+
|
|
641
|
+
if (mainIx !== undefined && otherIxs.length === 0) {
|
|
642
|
+
switch (mainIx.program) {
|
|
643
|
+
case "spl-associated-token-account":
|
|
644
|
+
switch (mainIx.instruction.type) {
|
|
645
|
+
case "associate":
|
|
646
|
+
return "OPT_IN";
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const fallbackType = delta.eq(0) ? "NONE" : delta.gt(0) ? "IN" : "OUT";
|
|
652
|
+
return fallbackType;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function dropMemoLengthPrefixIfAny(memo: string) {
|
|
656
|
+
const lengthPrefixMatch = memo.match(/^\[(\d+)\]\s/);
|
|
657
|
+
if (lengthPrefixMatch) {
|
|
658
|
+
const prefixLength = Number(lengthPrefixMatch[1]);
|
|
659
|
+
if (Number.isInteger(prefixLength) && prefixLength < memo.length) {
|
|
660
|
+
return memo.slice(-prefixLength);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return memo;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
async function getAccount(
|
|
667
|
+
address: string,
|
|
668
|
+
api: ChainAPI,
|
|
669
|
+
): Promise<{
|
|
670
|
+
balance: BigNumber;
|
|
671
|
+
blockHeight: number;
|
|
672
|
+
tokenAccounts: ParsedOnChainTokenAccountWithInfo[];
|
|
673
|
+
stakes: {
|
|
674
|
+
account: ParsedOnChainStakeAccountWithInfo;
|
|
675
|
+
activation: StakeActivationData;
|
|
676
|
+
reward: InflationReward | null;
|
|
677
|
+
}[];
|
|
678
|
+
}> {
|
|
679
|
+
const balanceLamportsWithContext = await api.getBalanceAndContext(address);
|
|
680
|
+
|
|
681
|
+
const tokenAccounts: ParsedOnChainTokenAccountWithInfo[] = [];
|
|
682
|
+
|
|
683
|
+
// no tokens for the first release
|
|
684
|
+
/*await api
|
|
685
|
+
.getParsedTokenAccountsByOwner(address)
|
|
686
|
+
.then((res) => res.value)
|
|
687
|
+
.then(map(toTokenAccountWithInfo));
|
|
688
|
+
*/
|
|
689
|
+
|
|
690
|
+
const stakeAccountsRaw = [
|
|
691
|
+
// ...(await api.getStakeAccountsByStakeAuth(address)),
|
|
692
|
+
...(await api.getStakeAccountsByWithdrawAuth(address)),
|
|
693
|
+
];
|
|
694
|
+
|
|
695
|
+
const stakeAccounts = flow(
|
|
696
|
+
() => stakeAccountsRaw,
|
|
697
|
+
uniqBy(acc => acc.pubkey.toBase58()),
|
|
698
|
+
map(toStakeAccountWithInfo),
|
|
699
|
+
compact,
|
|
700
|
+
)();
|
|
701
|
+
|
|
702
|
+
/*
|
|
703
|
+
Ledger team still decides if we should show rewards
|
|
704
|
+
const stakeRewards = await api.getInflationReward(
|
|
705
|
+
stakeAccounts.map(({ onChainAcc }) => onChainAcc.pubkey.toBase58())
|
|
706
|
+
);
|
|
707
|
+
*/
|
|
708
|
+
|
|
709
|
+
const stakes = await drainSeq(
|
|
710
|
+
stakeAccounts.map(account => async () => {
|
|
711
|
+
return {
|
|
712
|
+
account,
|
|
713
|
+
activation: await api.getStakeActivation(account.onChainAcc.pubkey.toBase58()),
|
|
714
|
+
//reward: stakeRewards[idx],
|
|
715
|
+
reward: null,
|
|
716
|
+
};
|
|
717
|
+
}),
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
const balance = new BigNumber(balanceLamportsWithContext.value);
|
|
721
|
+
const blockHeight = balanceLamportsWithContext.context.slot;
|
|
722
|
+
|
|
723
|
+
return {
|
|
724
|
+
balance,
|
|
725
|
+
blockHeight,
|
|
726
|
+
tokenAccounts,
|
|
727
|
+
stakes,
|
|
728
|
+
};
|
|
729
|
+
}
|