@ledgerhq/live-common 21.20.0 → 21.21.0-rc.2
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/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js +4 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js +12 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js.map +1 -1
- package/lib/__tests__/test-helpers/setup.js +1 -0
- package/lib/__tests__/test-helpers/setup.js.map +1 -1
- package/lib/account/pending.d.ts +1 -1
- package/lib/api/Ledger.d.ts.map +1 -1
- package/lib/api/Ledger.js +12 -2
- package/lib/api/Ledger.js.map +1 -1
- package/lib/api/explorerConfig/index.d.ts.map +1 -1
- package/lib/api/explorerConfig/index.js +5 -1
- package/lib/api/explorerConfig/index.js.map +1 -1
- package/lib/data/icons/react/cro.d.ts +8 -0
- package/lib/data/icons/react/cro.d.ts.map +1 -0
- package/lib/data/icons/react/cro.js +33 -0
- package/lib/data/icons/react/cro.js.map +1 -0
- package/lib/data/icons/react/index.d.ts +2 -0
- package/lib/data/icons/react/index.d.ts.map +1 -1
- package/lib/data/icons/react/index.js +12 -8
- package/lib/data/icons/react/index.js.map +1 -1
- package/lib/data/icons/react/sol.d.ts +8 -0
- package/lib/data/icons/react/sol.d.ts.map +1 -0
- package/lib/data/icons/react/sol.js +30 -0
- package/lib/data/icons/react/sol.js.map +1 -0
- package/lib/data/icons/reactNative/cro.d.ts +8 -0
- package/lib/data/icons/reactNative/cro.d.ts.map +1 -0
- package/lib/data/icons/reactNative/cro.js +34 -0
- package/lib/data/icons/reactNative/cro.js.map +1 -0
- package/lib/data/icons/reactNative/index.d.ts +2 -0
- package/lib/data/icons/reactNative/index.d.ts.map +1 -1
- package/lib/data/icons/reactNative/index.js +12 -8
- package/lib/data/icons/reactNative/index.js.map +1 -1
- package/lib/data/icons/reactNative/sol.d.ts +8 -0
- package/lib/data/icons/reactNative/sol.d.ts.map +1 -0
- package/lib/data/icons/reactNative/sol.js +31 -0
- package/lib/data/icons/reactNative/sol.js.map +1 -0
- package/lib/derivation.d.ts +7 -0
- package/lib/derivation.d.ts.map +1 -1
- package/lib/derivation.js +16 -1
- package/lib/derivation.js.map +1 -1
- package/lib/errors.d.ts +1 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -0
- package/lib/errors.js.map +1 -1
- package/lib/families/bitcoin/exchange.d.ts +1 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +1 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.js +3 -2
- package/lib/families/bitcoin/getAccountNetworkInfo.js.map +1 -1
- package/lib/families/bitcoin/js-signOperation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-signOperation.js +7 -2
- package/lib/families/bitcoin/js-signOperation.js.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts +2 -2
- package/lib/families/bitcoin/specs.d.ts +1 -0
- package/lib/families/bitcoin/specs.d.ts.map +1 -1
- package/lib/families/bitcoin/specs.js +14 -1
- package/lib/families/bitcoin/specs.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +8 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts +16 -0
- package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts.map +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/decred.js +248 -0
- package/lib/families/bitcoin/wallet-btc/crypto/decred.js.map +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/factory.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/factory.js +5 -0
- package/lib/families/bitcoin/wallet-btc/crypto/factory.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/index.d.ts +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/index.js +3 -1
- package/lib/families/bitcoin/wallet-btc/crypto/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +13 -3
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js +8 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js +8 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.js +6 -1
- package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts +2 -0
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.js +15 -7
- package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
- package/lib/families/crypto_org/js-synchronisation.d.ts +2 -2
- package/lib/families/elrond/js-synchronisation.d.ts +2 -2
- package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
- package/lib/families/ethereum/synchronisation.js +2 -2
- package/lib/families/ethereum/synchronisation.js.map +1 -1
- package/lib/families/polkadot/api/sidecar.js +4 -2
- package/lib/families/polkadot/api/sidecar.js.map +1 -1
- package/lib/families/polkadot/js-synchronisation.d.ts +2 -2
- package/lib/families/solana/api/cached.d.ts +5 -0
- package/lib/families/solana/api/cached.d.ts.map +1 -0
- package/lib/families/solana/api/cached.js +80 -0
- package/lib/families/solana/api/cached.js.map +1 -0
- package/lib/families/solana/api/chain/account/index.d.ts +2 -0
- package/lib/families/solana/api/chain/account/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/account/index.js +14 -0
- package/lib/families/solana/api/chain/account/index.js.map +1 -0
- package/lib/families/solana/api/chain/account/parser.d.ts +5 -0
- package/lib/families/solana/api/chain/account/parser.d.ts.map +1 -0
- package/lib/families/solana/api/chain/account/parser.js +33 -0
- package/lib/families/solana/api/chain/account/parser.js.map +1 -0
- package/lib/families/solana/api/chain/account/stake.d.ts +237 -0
- package/lib/families/solana/api/chain/account/stake.d.ts.map +1 -0
- package/lib/families/solana/api/chain/account/stake.js +43 -0
- package/lib/families/solana/api/chain/account/stake.js.map +1 -0
- package/lib/families/solana/api/chain/account/token.d.ts +116 -0
- package/lib/families/solana/api/chain/account/token.d.ts.map +1 -0
- package/lib/families/solana/api/chain/account/token.js +42 -0
- package/lib/families/solana/api/chain/account/token.js.map +1 -0
- package/lib/families/solana/api/chain/index.d.ts +22 -0
- package/lib/families/solana/api/chain/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/index.js +54 -0
- package/lib/families/solana/api/chain/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/index.d.ts +15 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/index.js +21 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/types.d.ts +30 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/types.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/types.js +19 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/types.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/memo/index.d.ts +15 -0
- package/lib/families/solana/api/chain/instruction/memo/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/memo/index.js +14 -0
- package/lib/families/solana/api/chain/instruction/memo/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/memo/types.d.ts +21 -0
- package/lib/families/solana/api/chain/instruction/memo/types.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/memo/types.js +16 -0
- package/lib/families/solana/api/chain/instruction/memo/types.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/stake/index.d.ts +15 -0
- package/lib/families/solana/api/chain/instruction/stake/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/stake/index.js +20 -0
- package/lib/families/solana/api/chain/instruction/stake/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/stake/types.d.ts +215 -0
- package/lib/families/solana/api/chain/instruction/stake/types.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/stake/types.js +80 -0
- package/lib/families/solana/api/chain/instruction/stake/types.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/index.d.ts +15 -0
- package/lib/families/solana/api/chain/instruction/token/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/index.js +20 -0
- package/lib/families/solana/api/chain/instruction/token/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/types.d.ts +497 -0
- package/lib/families/solana/api/chain/instruction/token/types.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/types.js +205 -0
- package/lib/families/solana/api/chain/instruction/token/types.js.map +1 -0
- package/lib/families/solana/api/chain/program/constants.d.ts +11 -0
- package/lib/families/solana/api/chain/program/constants.d.ts.map +1 -0
- package/lib/families/solana/api/chain/program/constants.js +14 -0
- package/lib/families/solana/api/chain/program/constants.js.map +1 -0
- package/lib/families/solana/api/chain/program/index.d.ts +2 -0
- package/lib/families/solana/api/chain/program/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/program/index.js +14 -0
- package/lib/families/solana/api/chain/program/index.js.map +1 -0
- package/lib/families/solana/api/chain/program/parser.d.ts +30 -0
- package/lib/families/solana/api/chain/program/parser.d.ts.map +1 -0
- package/lib/families/solana/api/chain/program/parser.js +70 -0
- package/lib/families/solana/api/chain/program/parser.js.map +1 -0
- package/lib/families/solana/api/chain/validators/bignum.d.ts +3 -0
- package/lib/families/solana/api/chain/validators/bignum.d.ts.map +1 -0
- package/lib/families/solana/api/chain/validators/bignum.js +11 -0
- package/lib/families/solana/api/chain/validators/bignum.js.map +1 -0
- package/lib/families/solana/api/chain/validators/index.d.ts +10 -0
- package/lib/families/solana/api/chain/validators/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/validators/index.js +10 -0
- package/lib/families/solana/api/chain/validators/index.js.map +1 -0
- package/lib/families/solana/api/chain/validators/pubkey.d.ts +3 -0
- package/lib/families/solana/api/chain/validators/pubkey.d.ts.map +1 -0
- package/lib/families/solana/api/chain/validators/pubkey.js +7 -0
- package/lib/families/solana/api/chain/validators/pubkey.js.map +1 -0
- package/lib/families/solana/api/chain/web3.d.ts +29 -0
- package/lib/families/solana/api/chain/web3.d.ts.map +1 -0
- package/lib/families/solana/api/chain/web3.js +287 -0
- package/lib/families/solana/api/chain/web3.js.map +1 -0
- package/lib/families/solana/api/index.d.ts +5 -0
- package/lib/families/solana/api/index.d.ts.map +1 -0
- package/lib/families/solana/api/index.js +21 -0
- package/lib/families/solana/api/index.js.map +1 -0
- package/lib/families/solana/api/logged.d.ts +3 -0
- package/lib/families/solana/api/logged.d.ts.map +1 -0
- package/lib/families/solana/api/logged.js +53 -0
- package/lib/families/solana/api/logged.js.map +1 -0
- package/lib/families/solana/api/queued.d.ts +3 -0
- package/lib/families/solana/api/queued.d.ts.map +1 -0
- package/lib/families/solana/api/queued.js +31 -0
- package/lib/families/solana/api/queued.js.map +1 -0
- package/lib/families/solana/bridge/bridge.d.ts +12 -0
- package/lib/families/solana/bridge/bridge.d.ts.map +1 -0
- package/lib/families/solana/bridge/bridge.js +218 -0
- package/lib/families/solana/bridge/bridge.js.map +1 -0
- package/lib/families/solana/bridge/js.d.ts +6 -0
- package/lib/families/solana/bridge/js.d.ts.map +1 -0
- package/lib/families/solana/bridge/js.js +15 -0
- package/lib/families/solana/bridge/js.js.map +1 -0
- package/lib/families/solana/bridge/mock-data.d.ts +186 -0
- package/lib/families/solana/bridge/mock-data.d.ts.map +1 -0
- package/lib/families/solana/bridge/mock-data.js +23 -0
- package/lib/families/solana/bridge/mock-data.js.map +1 -0
- package/lib/families/solana/bridge/mock.d.ts +6 -0
- package/lib/families/solana/bridge/mock.d.ts.map +1 -0
- package/lib/families/solana/bridge/mock.js +75 -0
- package/lib/families/solana/bridge/mock.js.map +1 -0
- package/lib/families/solana/cli-transaction.d.ts +14 -0
- package/lib/families/solana/cli-transaction.d.ts.map +1 -0
- package/lib/families/solana/cli-transaction.js +137 -0
- package/lib/families/solana/cli-transaction.js.map +1 -0
- package/lib/families/solana/datasets/solana.scanAccounts.1.d.ts +6 -0
- package/lib/families/solana/datasets/solana.scanAccounts.1.d.ts.map +1 -0
- package/lib/families/solana/datasets/solana.scanAccounts.1.js +7 -0
- package/lib/families/solana/datasets/solana.scanAccounts.1.js.map +1 -0
- package/lib/families/solana/deviceTransactionConfig.d.ts +10 -0
- package/lib/families/solana/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/families/solana/deviceTransactionConfig.js +121 -0
- package/lib/families/solana/deviceTransactionConfig.js.map +1 -0
- package/lib/families/solana/errors.d.ts +25 -0
- package/lib/families/solana/errors.d.ts.map +1 -0
- package/lib/families/solana/errors.js +13 -0
- package/lib/families/solana/errors.js.map +1 -0
- package/lib/families/solana/hw-getAddress.d.ts +4 -0
- package/lib/families/solana/hw-getAddress.d.ts.map +1 -0
- package/lib/families/solana/hw-getAddress.js +66 -0
- package/lib/families/solana/hw-getAddress.js.map +1 -0
- package/lib/families/solana/js-broadcast.d.ts +7 -0
- package/lib/families/solana/js-broadcast.d.ts.map +1 -0
- package/lib/families/solana/js-broadcast.js +59 -0
- package/lib/families/solana/js-broadcast.js.map +1 -0
- package/lib/families/solana/js-buildTransaction.d.ts +6 -0
- package/lib/families/solana/js-buildTransaction.d.ts.map +1 -0
- package/lib/families/solana/js-buildTransaction.js +123 -0
- package/lib/families/solana/js-buildTransaction.js.map +1 -0
- package/lib/families/solana/js-createTransaction.d.ts +6 -0
- package/lib/families/solana/js-createTransaction.d.ts.map +1 -0
- package/lib/families/solana/js-createTransaction.js +35 -0
- package/lib/families/solana/js-createTransaction.js.map +1 -0
- package/lib/families/solana/js-estimateMaxSpendable.d.ts +7 -0
- package/lib/families/solana/js-estimateMaxSpendable.d.ts.map +1 -0
- package/lib/families/solana/js-estimateMaxSpendable.js +72 -0
- package/lib/families/solana/js-estimateMaxSpendable.js.map +1 -0
- package/lib/families/solana/js-getTransactionStatus.d.ts +5 -0
- package/lib/families/solana/js-getTransactionStatus.d.ts.map +1 -0
- package/lib/families/solana/js-getTransactionStatus.js +106 -0
- package/lib/families/solana/js-getTransactionStatus.js.map +1 -0
- package/lib/families/solana/js-prepareTransaction.d.ts +6 -0
- package/lib/families/solana/js-prepareTransaction.d.ts.map +1 -0
- package/lib/families/solana/js-prepareTransaction.js +380 -0
- package/lib/families/solana/js-prepareTransaction.js.map +1 -0
- package/lib/families/solana/js-signOperation.d.ts +10 -0
- package/lib/families/solana/js-signOperation.d.ts.map +1 -0
- package/lib/families/solana/js-signOperation.js +193 -0
- package/lib/families/solana/js-signOperation.js.map +1 -0
- package/lib/families/solana/js-synchronization.d.ts +5 -0
- package/lib/families/solana/js-synchronization.d.ts.map +1 -0
- package/lib/families/solana/js-synchronization.js +464 -0
- package/lib/families/solana/js-synchronization.js.map +1 -0
- package/lib/families/solana/logic.d.ts +15 -0
- package/lib/families/solana/logic.d.ts.map +1 -0
- package/lib/families/solana/logic.js +49 -0
- package/lib/families/solana/logic.js.map +1 -0
- package/lib/families/solana/specs.d.ts +7 -0
- package/lib/families/solana/specs.d.ts.map +1 -0
- package/lib/families/solana/specs.js +100 -0
- package/lib/families/solana/specs.js.map +1 -0
- package/lib/families/solana/speculos-deviceActions.d.ts +8 -0
- package/lib/families/solana/speculos-deviceActions.d.ts.map +1 -0
- package/lib/families/solana/speculos-deviceActions.js +60 -0
- package/lib/families/solana/speculos-deviceActions.js.map +1 -0
- package/lib/families/solana/test-dataset.d.ts +5 -0
- package/lib/families/solana/test-dataset.d.ts.map +1 -0
- package/lib/families/solana/test-dataset.js +396 -0
- package/lib/families/solana/test-dataset.js.map +1 -0
- package/lib/families/solana/transaction.d.ts +12 -0
- package/lib/families/solana/transaction.d.ts.map +1 -0
- package/lib/families/solana/transaction.js +109 -0
- package/lib/families/solana/transaction.js.map +1 -0
- package/lib/families/solana/types.d.ts +84 -0
- package/lib/families/solana/types.d.ts.map +1 -0
- package/lib/families/solana/types.js +6 -0
- package/lib/families/solana/types.js.map +1 -0
- package/lib/families/solana/utils.d.ts +10 -0
- package/lib/families/solana/utils.d.ts.map +1 -0
- package/lib/families/solana/utils.js +194 -0
- package/lib/families/solana/utils.js.map +1 -0
- package/lib/families/stellar/js-synchronization.d.ts +2 -2
- package/lib/generated/bridge/js.d.ts +4 -0
- package/lib/generated/bridge/js.d.ts.map +1 -1
- package/lib/generated/bridge/js.js +8 -6
- package/lib/generated/bridge/js.js.map +1 -1
- package/lib/generated/bridge/mock.d.ts +4 -0
- package/lib/generated/bridge/mock.d.ts.map +1 -1
- package/lib/generated/bridge/mock.js +6 -4
- package/lib/generated/bridge/mock.js.map +1 -1
- package/lib/generated/cli-transaction.d.ts +9 -0
- package/lib/generated/cli-transaction.d.ts.map +1 -1
- package/lib/generated/cli-transaction.js +8 -6
- package/lib/generated/cli-transaction.js.map +1 -1
- package/lib/generated/deviceTransactionConfig.d.ts +2 -0
- package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/generated/deviceTransactionConfig.js +8 -6
- package/lib/generated/deviceTransactionConfig.js.map +1 -1
- package/lib/generated/exchange.d.ts +1 -1
- package/lib/generated/hw-getAddress.d.ts +1 -0
- package/lib/generated/hw-getAddress.d.ts.map +1 -1
- package/lib/generated/hw-getAddress.js +8 -6
- package/lib/generated/hw-getAddress.js.map +1 -1
- package/lib/generated/specs.d.ts +4 -0
- package/lib/generated/specs.d.ts.map +1 -1
- package/lib/generated/specs.js +8 -6
- package/lib/generated/specs.js.map +1 -1
- package/lib/generated/speculos-deviceActions.d.ts +3 -0
- package/lib/generated/speculos-deviceActions.d.ts.map +1 -1
- package/lib/generated/speculos-deviceActions.js +8 -6
- package/lib/generated/speculos-deviceActions.js.map +1 -1
- package/lib/generated/test-dataset.d.ts +1 -0
- package/lib/generated/test-dataset.d.ts.map +1 -1
- package/lib/generated/test-dataset.js +8 -6
- package/lib/generated/test-dataset.js.map +1 -1
- package/lib/generated/transaction.d.ts +5 -0
- package/lib/generated/transaction.d.ts.map +1 -1
- package/lib/generated/transaction.js +8 -6
- package/lib/generated/transaction.js.map +1 -1
- package/lib/generated/types.d.ts +12 -6
- package/lib/generated/types.d.ts.map +1 -1
- package/lib/generated/types.js +5 -3
- package/lib/generated/types.js.map +1 -1
- package/lib/nft/helpers.js +1 -1
- package/lib/nft/helpers.js.map +1 -1
- package/package.json +8 -4
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +113 -0
- package/src/__tests__/families/bitcoin/wallet-btc/utils.test.ts +4 -0
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.ts +12 -0
- package/src/__tests__/test-helpers/setup.ts +1 -0
- package/src/api/Ledger.ts +11 -1
- package/src/api/explorerConfig/index.ts +1 -3
- package/src/data/icons/react/cro.tsx +12 -0
- package/src/data/icons/react/index.tsx +2 -0
- package/src/data/icons/react/sol.tsx +12 -0
- package/src/data/icons/reactNative/cro.tsx +13 -0
- package/src/data/icons/reactNative/index.tsx +2 -0
- package/src/data/icons/reactNative/sol.tsx +13 -0
- package/src/data/icons/svg/CRO.svg +6 -0
- package/src/data/icons/svg/SOL.svg +3 -0
- package/src/derivation.ts +13 -0
- package/src/errors.ts +1 -0
- package/src/families/bitcoin/getAccountNetworkInfo.ts +5 -2
- package/src/families/bitcoin/js-signOperation.ts +4 -7
- package/src/families/bitcoin/specs.ts +16 -0
- package/src/families/bitcoin/wallet-btc/crypto/base.ts +1 -1
- package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +8 -1
- package/src/families/bitcoin/wallet-btc/crypto/decred.ts +251 -0
- package/src/families/bitcoin/wallet-btc/crypto/factory.ts +5 -0
- package/src/families/bitcoin/wallet-btc/crypto/index.ts +1 -0
- package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +13 -3
- package/src/families/bitcoin/wallet-btc/crypto/types.ts +1 -0
- package/src/families/bitcoin/wallet-btc/crypto/zec.ts +8 -1
- package/src/families/bitcoin/wallet-btc/crypto/zen.ts +8 -1
- package/src/families/bitcoin/wallet-btc/utils.ts +6 -1
- package/src/families/bitcoin/wallet-btc/wallet.ts +18 -5
- package/src/families/ethereum/synchronisation.ts +5 -2
- package/src/families/polkadot/api/sidecar.ts +2 -2
- package/src/families/solana/api/cached.ts +89 -0
- package/src/families/solana/api/chain/account/index.ts +1 -0
- package/src/families/solana/api/chain/account/parser.ts +35 -0
- package/src/families/solana/api/chain/account/stake.ts +50 -0
- package/src/families/solana/api/chain/account/token.ts +63 -0
- package/src/families/solana/api/chain/index.ts +115 -0
- package/src/families/solana/api/chain/instruction/associated-token-account/index.ts +37 -0
- package/src/families/solana/api/chain/instruction/associated-token-account/types.ts +23 -0
- package/src/families/solana/api/chain/instruction/memo/index.ts +24 -0
- package/src/families/solana/api/chain/instruction/memo/types.ts +18 -0
- package/src/families/solana/api/chain/instruction/stake/index.ts +29 -0
- package/src/families/solana/api/chain/instruction/stake/types.ts +95 -0
- package/src/families/solana/api/chain/instruction/token/index.ts +30 -0
- package/src/families/solana/api/chain/instruction/token/types.ts +237 -0
- package/src/families/solana/api/chain/program/constants.ts +10 -0
- package/src/families/solana/api/chain/program/index.ts +1 -0
- package/src/families/solana/api/chain/program/parser.ts +122 -0
- package/src/families/solana/api/chain/validators/bignum.ts +11 -0
- package/src/families/solana/api/chain/validators/index.ts +9 -0
- package/src/families/solana/api/chain/validators/pubkey.ts +8 -0
- package/src/families/solana/api/chain/web3.ts +258 -0
- package/src/families/solana/api/index.ts +4 -0
- package/src/families/solana/api/logged.ts +50 -0
- package/src/families/solana/api/queued.ts +23 -0
- package/src/families/solana/bridge/bridge.ts +169 -0
- package/src/families/solana/bridge/js.ts +28 -0
- package/src/families/solana/bridge/mock-data.ts +22 -0
- package/src/families/solana/bridge/mock.ts +80 -0
- package/src/families/solana/cli-transaction.ts +175 -0
- package/src/families/solana/datasets/solana.scanAccounts.1.ts +9 -0
- package/src/families/solana/deviceTransactionConfig.ts +160 -0
- package/src/families/solana/errors.ts +32 -0
- package/src/families/solana/hw-getAddress.ts +20 -0
- package/src/families/solana/js-broadcast.ts +20 -0
- package/src/families/solana/js-buildTransaction.ts +75 -0
- package/src/families/solana/js-createTransaction.ts +27 -0
- package/src/families/solana/js-estimateMaxSpendable.ts +29 -0
- package/src/families/solana/js-getTransactionStatus.ts +78 -0
- package/src/families/solana/js-prepareTransaction.ts +423 -0
- package/src/families/solana/js-signOperation.ts +230 -0
- package/src/families/solana/js-synchronization.ts +544 -0
- package/src/families/solana/logic.ts +52 -0
- package/src/families/solana/specs.ts +100 -0
- package/src/families/solana/speculos-deviceActions.ts +59 -0
- package/src/families/solana/test-dataset.ts +572 -0
- package/src/families/solana/transaction.ts +146 -0
- package/src/families/solana/types.ts +110 -0
- package/src/families/solana/utils.ts +80 -0
- package/src/generated/bridge/js.ts +3 -0
- package/src/generated/bridge/mock.ts +3 -0
- package/src/generated/cli-transaction.ts +3 -0
- package/src/generated/deviceTransactionConfig.ts +3 -0
- package/src/generated/hw-getAddress.ts +3 -0
- package/src/generated/specs.ts +3 -0
- package/src/generated/speculos-deviceActions.ts +3 -0
- package/src/generated/test-dataset.ts +3 -0
- package/src/generated/transaction.ts +3 -0
- package/src/generated/types.ts +14 -0
- package/src/nft/helpers.ts +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
|
|
4
|
+
export const getMockedMethods = () => [
|
|
5
|
+
|
|
6
|
+
// generated
|
|
7
|
+
{"method":"getBalanceAndContext","params":["AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh"],"answer":{"context":{"slot":109865128},"value":83389840}},
|
|
8
|
+
{"method":"getSignaturesForAddress","params":["AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh",{"limit":100}],"answer":[{"blockTime":1637781134,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"A29zPnK1jPr2tGziTnaAvSnadYR2kLCv9sPywj9FJsaEFjtpwmUonspN3WJgz4u6XWmjtVpoFsDrygEnvW51cgk","slot":108521109},{"blockTime":1637780906,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"25KWBvKtVgKR3yoRmozTY6wmiW8atwrnzAnTXdsms8jqg5aR8GnCDxdJzWXtzMZPvbsE6SUuBkGFXudy2mrcTYna","slot":108520722}]},
|
|
9
|
+
{"method":"getParsedConfirmedTransactions","params":[["A29zPnK1jPr2tGziTnaAvSnadYR2kLCv9sPywj9FJsaEFjtpwmUonspN3WJgz4u6XWmjtVpoFsDrygEnvW51cgk","25KWBvKtVgKR3yoRmozTY6wmiW8atwrnzAnTXdsms8jqg5aR8GnCDxdJzWXtzMZPvbsE6SUuBkGFXudy2mrcTYna"]],"answer":[{"blockTime":1637781134,"meta":{"err":null,"fee":5000,"innerInstructions":[{"index":1,"instructions":[{"parsed":{"info":{"account":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","space":165},"type":"allocate"},"program":"system","programId":new PublicKey(Buffer.from("00", 'hex'))},{"parsed":{"info":{"account":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},"type":"assign"},"program":"system","programId":new PublicKey(Buffer.from("00", 'hex'))},{"parsed":{"info":{"account":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","mint":"So11111111111111111111111111111111111111112","owner":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh","rentSysvar":"SysvarRent111111111111111111111111111111111"},"type":"initializeAccount"},"program":"spl-token","programId":new PublicKey(Buffer.from("06ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9", 'hex'))}]}],"logMessages":["Program 11111111111111111111111111111111 invoke [1]","Program 11111111111111111111111111111111 success","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]","Program log: Allocate space for the associated token account","Program 11111111111111111111111111111111 invoke [2]","Program 11111111111111111111111111111111 success","Program log: Assign the associated token account to the SPL Token program","Program 11111111111111111111111111111111 invoke [2]","Program 11111111111111111111111111111111 success","Program log: Initialize the associated token account","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: InitializeAccount","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3683 of 183452 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 20880 of 200000 compute units","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success"],"postBalances":[83389840,10000000,151314748907,1,1089991680,1009200,898174080],"postTokenBalances":[{"accountIndex":1,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"amount":"7960720","decimals":9,"uiAmount":0.00796072,"uiAmountString":"0.00796072"}}],"preBalances":[93394840,0,151314748907,1,1089991680,1009200,898174080],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"slot":108521109,"transaction":{"message":{"accountKeys":[{"pubkey":new PublicKey(Buffer.from("8bc4d3e507c0550e3d02ffb5f6daf0772240af8a09e32d236615b4a227243702", 'hex')),"signer":true,"writable":true},{"pubkey":new PublicKey(Buffer.from("6e6279fa638560ce9c178033f5b88eacfb5fba6d46ec5902769f1b09eaabc017", 'hex')),"signer":false,"writable":true},{"pubkey":new PublicKey(Buffer.from("069b8857feab8184fb687f634618c035dac439dc1aeb3b5598a0f00000000001", 'hex')),"signer":false,"writable":false},{"pubkey":new PublicKey(Buffer.from("00", 'hex')),"signer":false,"writable":false},{"pubkey":new PublicKey(Buffer.from("06ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9", 'hex')),"signer":false,"writable":false},{"pubkey":new PublicKey(Buffer.from("06a7d517192c5c51218cc94c3d4af17f58daee089ba1fd44e3dbd98a00000000", 'hex')),"signer":false,"writable":false},{"pubkey":new PublicKey(Buffer.from("8c97258f4e2489f1bb3d1029148e0d830b5a1399daff1084048e7bd8dbe9f859", 'hex')),"signer":false,"writable":false}],"instructions":[{"parsed":{"info":{"destination":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","lamports":10000000,"source":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh"},"type":"transfer"},"program":"system","programId":new PublicKey(Buffer.from("00", 'hex'))},{"parsed":{"info":{"account":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","mint":"So11111111111111111111111111111111111111112","rentSysvar":"SysvarRent111111111111111111111111111111111","source":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh","systemProgram":"11111111111111111111111111111111","tokenProgram":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","wallet":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh"},"type":"create"},"program":"spl-associated-token-account","programId":new PublicKey(Buffer.from("8c97258f4e2489f1bb3d1029148e0d830b5a1399daff1084048e7bd8dbe9f859", 'hex'))}],"recentBlockhash":"9tPbgLaETEenufCt5SzXMuWijgFJj549W9j5cJLbaogn"},"signatures":["A29zPnK1jPr2tGziTnaAvSnadYR2kLCv9sPywj9FJsaEFjtpwmUonspN3WJgz4u6XWmjtVpoFsDrygEnvW51cgk"]}},{"blockTime":1637780906,"meta":{"err":null,"fee":5000,"innerInstructions":[],"logMessages":["Program 11111111111111111111111111111111 invoke [1]","Program 11111111111111111111111111111111 success"],"postBalances":[0,93394840,1],"postTokenBalances":[],"preBalances":[93399840,0,1],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"slot":108520722,"transaction":{"message":{"accountKeys":[{"pubkey":new PublicKey(Buffer.from("5c1c77c3d1e8edad4cfb2b2f7e4497d0d83f19e176713876a1d01eeb30a9bf3f", 'hex')),"signer":true,"writable":true},{"pubkey":new PublicKey(Buffer.from("8bc4d3e507c0550e3d02ffb5f6daf0772240af8a09e32d236615b4a227243702", 'hex')),"signer":false,"writable":true},{"pubkey":new PublicKey(Buffer.from("00", 'hex')),"signer":false,"writable":false}],"instructions":[{"parsed":{"info":{"destination":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh","lamports":93394840,"source":"7CZgkK494jMdoY8xpXY3ViLjpDGMbNikCzMtAT5cAjKk"},"type":"transfer"},"program":"system","programId":new PublicKey(Buffer.from("00", 'hex'))}],"recentBlockhash":"4NSL4VrfWd2eUccMD95dLQsdy5UGz8yhokpfH1et1R2c"},"signatures":["25KWBvKtVgKR3yoRmozTY6wmiW8atwrnzAnTXdsms8jqg5aR8GnCDxdJzWXtzMZPvbsE6SUuBkGFXudy2mrcTYna"]}}]},
|
|
10
|
+
{"method":"getBalanceAndContext","params":["6rEgdtB3sgjKJnRE172YEr9z6qUyr4nFW28vJokuD36A"],"answer":{"context":{"slot":109865129},"value":0}},
|
|
11
|
+
{"method":"getSignaturesForAddress","params":["6rEgdtB3sgjKJnRE172YEr9z6qUyr4nFW28vJokuD36A",{"limit":100}],"answer":[]},
|
|
12
|
+
{"method":"getSignaturesForAddress","params":["AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh",{"until":"25KWBvKtVgKR3yoRmozTY6wmiW8atwrnzAnTXdsms8jqg5aR8GnCDxdJzWXtzMZPvbsE6SUuBkGFXudy2mrcTYna","limit":100}],"answer":[{"blockTime":1637781134,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"A29zPnK1jPr2tGziTnaAvSnadYR2kLCv9sPywj9FJsaEFjtpwmUonspN3WJgz4u6XWmjtVpoFsDrygEnvW51cgk","slot":108521109}]},
|
|
13
|
+
{"method":"getParsedConfirmedTransactions","params":[["A29zPnK1jPr2tGziTnaAvSnadYR2kLCv9sPywj9FJsaEFjtpwmUonspN3WJgz4u6XWmjtVpoFsDrygEnvW51cgk"]],"answer":[{"blockTime":1637781134,"meta":{"err":null,"fee":5000,"innerInstructions":[{"index":1,"instructions":[{"parsed":{"info":{"account":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","space":165},"type":"allocate"},"program":"system","programId":new PublicKey(Buffer.from("00", 'hex'))},{"parsed":{"info":{"account":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},"type":"assign"},"program":"system","programId":new PublicKey(Buffer.from("00", 'hex'))},{"parsed":{"info":{"account":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","mint":"So11111111111111111111111111111111111111112","owner":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh","rentSysvar":"SysvarRent111111111111111111111111111111111"},"type":"initializeAccount"},"program":"spl-token","programId":new PublicKey(Buffer.from("06ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9", 'hex'))}]}],"logMessages":["Program 11111111111111111111111111111111 invoke [1]","Program 11111111111111111111111111111111 success","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]","Program log: Allocate space for the associated token account","Program 11111111111111111111111111111111 invoke [2]","Program 11111111111111111111111111111111 success","Program log: Assign the associated token account to the SPL Token program","Program 11111111111111111111111111111111 invoke [2]","Program 11111111111111111111111111111111 success","Program log: Initialize the associated token account","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: InitializeAccount","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3683 of 183452 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 20880 of 200000 compute units","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success"],"postBalances":[83389840,10000000,151314748907,1,1089991680,1009200,898174080],"postTokenBalances":[{"accountIndex":1,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"amount":"7960720","decimals":9,"uiAmount":0.00796072,"uiAmountString":"0.00796072"}}],"preBalances":[93394840,0,151314748907,1,1089991680,1009200,898174080],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"slot":108521109,"transaction":{"message":{"accountKeys":[{"pubkey":new PublicKey(Buffer.from("8bc4d3e507c0550e3d02ffb5f6daf0772240af8a09e32d236615b4a227243702", 'hex')),"signer":true,"writable":true},{"pubkey":new PublicKey(Buffer.from("6e6279fa638560ce9c178033f5b88eacfb5fba6d46ec5902769f1b09eaabc017", 'hex')),"signer":false,"writable":true},{"pubkey":new PublicKey(Buffer.from("069b8857feab8184fb687f634618c035dac439dc1aeb3b5598a0f00000000001", 'hex')),"signer":false,"writable":false},{"pubkey":new PublicKey(Buffer.from("00", 'hex')),"signer":false,"writable":false},{"pubkey":new PublicKey(Buffer.from("06ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9", 'hex')),"signer":false,"writable":false},{"pubkey":new PublicKey(Buffer.from("06a7d517192c5c51218cc94c3d4af17f58daee089ba1fd44e3dbd98a00000000", 'hex')),"signer":false,"writable":false},{"pubkey":new PublicKey(Buffer.from("8c97258f4e2489f1bb3d1029148e0d830b5a1399daff1084048e7bd8dbe9f859", 'hex')),"signer":false,"writable":false}],"instructions":[{"parsed":{"info":{"destination":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","lamports":10000000,"source":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh"},"type":"transfer"},"program":"system","programId":new PublicKey(Buffer.from("00", 'hex'))},{"parsed":{"info":{"account":"8RtwWeqdFz4EFuZU3MAadfYMWSdRMamjFrfq6BXkHuNN","mint":"So11111111111111111111111111111111111111112","rentSysvar":"SysvarRent111111111111111111111111111111111","source":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh","systemProgram":"11111111111111111111111111111111","tokenProgram":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","wallet":"AQbkEagmPgmsdAfS4X8V8UyJnXXjVPMvjeD15etqQ3Jh"},"type":"create"},"program":"spl-associated-token-account","programId":new PublicKey(Buffer.from("8c97258f4e2489f1bb3d1029148e0d830b5a1399daff1084048e7bd8dbe9f859", 'hex'))}],"recentBlockhash":"9tPbgLaETEenufCt5SzXMuWijgFJj549W9j5cJLbaogn"},"signatures":["A29zPnK1jPr2tGziTnaAvSnadYR2kLCv9sPywj9FJsaEFjtpwmUonspN3WJgz4u6XWmjtVpoFsDrygEnvW51cgk"]}}]},
|
|
14
|
+
{"method":"getRecentBlockhash","params":[],"answer":{"blockhash":"CfCUxX9U6hibcKxHV9Sy1CyG3Z2uTTitxAbina1ZXygF","feeCalculator":{"lamportsPerSignature":5000}}},
|
|
15
|
+
{"method":"getBalance","params":["ARRKL4FT4LMwpkhUw4xNbfiHqR7UdePtzGLvkszgydqZ"],"answer":1000000},
|
|
16
|
+
{"method":"getBalance","params":["7b6Q3ap8qRzfyvDw1Qce3fUV8C7WgFNzJQwYNTJm3KQo"],"answer":0},
|
|
17
|
+
{"method":"getBalance","params":["6D8GtWkKJgToM5UoiByHqjQCCC9Dq1Hh7iNmU4jKSs14"],"answer":0},
|
|
18
|
+
|
|
19
|
+
// manual
|
|
20
|
+
{"method":"getTxFeeCalculator","params":[],"answer":{"lamportsPerSignature": 5000}},
|
|
21
|
+
|
|
22
|
+
];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { flow, isArray, isEqual, isObject } from "lodash/fp";
|
|
2
|
+
import { isUndefined, mapValues, omitBy } from "lodash/fp";
|
|
3
|
+
import { cached, ChainAPI, Config, getChainAPI, logged, queued } from "../api";
|
|
4
|
+
import { makeBridges } from "./bridge";
|
|
5
|
+
import { makeLRUCache } from "../../../cache";
|
|
6
|
+
import { getMockedMethods } from "./mock-data";
|
|
7
|
+
import { minutes } from "../api/cached";
|
|
8
|
+
|
|
9
|
+
function mockChainAPI(config: Config): ChainAPI {
|
|
10
|
+
const mockedMethods = getMockedMethods();
|
|
11
|
+
const api = new Proxy(
|
|
12
|
+
{ config },
|
|
13
|
+
{
|
|
14
|
+
get(_, propKey) {
|
|
15
|
+
if (propKey in api) {
|
|
16
|
+
return api[propKey];
|
|
17
|
+
}
|
|
18
|
+
if (propKey === "then") {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const method = propKey.toString();
|
|
22
|
+
const mocks = mockedMethods.filter((mock) => mock.method === method);
|
|
23
|
+
if (mocks.length === 0) {
|
|
24
|
+
throw new Error(`no mock found for api method: ${method}`);
|
|
25
|
+
}
|
|
26
|
+
return function (...args: any[]) {
|
|
27
|
+
const definedArgs = removeUndefineds(args);
|
|
28
|
+
const mock = mocks.find(({ params }) => isEqual(definedArgs)(params));
|
|
29
|
+
if (mock === undefined) {
|
|
30
|
+
const argsJson = JSON.stringify(args);
|
|
31
|
+
throw new Error(
|
|
32
|
+
`no mock found for api method ${method} with args ${argsJson}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return Promise.resolve(mock.answer);
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
return api as ChainAPI;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function removeUndefineds(input: any) {
|
|
44
|
+
return isObject(input)
|
|
45
|
+
? isArray(input)
|
|
46
|
+
? input.map(removeUndefineds)
|
|
47
|
+
: flow(omitBy(isUndefined), mapValues(removeUndefineds))(input)
|
|
48
|
+
: input;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Bridge with this api will log all api calls to a file.
|
|
52
|
+
// The calls data can be copied to mock-data.ts from the file.
|
|
53
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
54
|
+
function createMockDataForAPI() {
|
|
55
|
+
const apiGetter = makeLRUCache(
|
|
56
|
+
(config: Config) =>
|
|
57
|
+
Promise.resolve(
|
|
58
|
+
cached(queued(logged(getChainAPI(config), "/tmp/log"), 100))
|
|
59
|
+
),
|
|
60
|
+
(config) => config.cluster,
|
|
61
|
+
minutes(1000)
|
|
62
|
+
);
|
|
63
|
+
return {
|
|
64
|
+
getAPI: apiGetter,
|
|
65
|
+
getQueuedAPI: apiGetter,
|
|
66
|
+
getQueuedAndCachedAPI: apiGetter,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getMockedAPIs() {
|
|
71
|
+
const mockedAPI = mockChainAPI({ cluster: "mock" } as any);
|
|
72
|
+
return {
|
|
73
|
+
getAPI: (_: Config) => Promise.resolve(mockedAPI),
|
|
74
|
+
getQueuedAPI: (_: Config) => Promise.resolve(mockedAPI),
|
|
75
|
+
getQueuedAndCachedAPI: (_: Config) => Promise.resolve(mockedAPI),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//export default makeBridges(createMockDataForAPI());
|
|
80
|
+
export default makeBridges(getMockedAPIs());
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { findTokenById, findTokenByTicker } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import invariant from "invariant";
|
|
3
|
+
import { getAccountCurrency } from "../../account";
|
|
4
|
+
import type {
|
|
5
|
+
Transaction,
|
|
6
|
+
AccountLike,
|
|
7
|
+
Account,
|
|
8
|
+
AccountLikeArray,
|
|
9
|
+
} from "../../types";
|
|
10
|
+
import { Transaction as SolanaTransaction } from "./types";
|
|
11
|
+
import { assertUnreachable } from "./utils";
|
|
12
|
+
|
|
13
|
+
const modes = ["send", "optIn"] as const;
|
|
14
|
+
type Mode = typeof modes[number];
|
|
15
|
+
|
|
16
|
+
// options already specified in other blockchains like ethereum.
|
|
17
|
+
// trying to reuse existing ones like <token>, <mode>, etc.
|
|
18
|
+
const options = [];
|
|
19
|
+
|
|
20
|
+
function inferTransactions(
|
|
21
|
+
transactions: Array<{
|
|
22
|
+
account: AccountLike;
|
|
23
|
+
mainAccount: Account;
|
|
24
|
+
transaction: Transaction;
|
|
25
|
+
}>,
|
|
26
|
+
opts: Partial<Record<string, string>>
|
|
27
|
+
): Transaction[] {
|
|
28
|
+
const mode = inferMode(opts.mode);
|
|
29
|
+
|
|
30
|
+
// reusing ethereum token option, comes as array
|
|
31
|
+
const tokens: string[] | undefined = opts.token as any;
|
|
32
|
+
|
|
33
|
+
if (tokens !== undefined && tokens.length !== 1) {
|
|
34
|
+
throw new Error("only 1 token at a time supported for solana transactions");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const token = tokens?.[0];
|
|
38
|
+
|
|
39
|
+
return transactions.map(({ account, transaction }) => {
|
|
40
|
+
if (transaction.family !== "solana") {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Solana family transaction expected, got <${transaction.family}>`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
switch (mode) {
|
|
46
|
+
case "send":
|
|
47
|
+
if (account.type === "Account") {
|
|
48
|
+
const solanaTx: SolanaTransaction = {
|
|
49
|
+
...transaction,
|
|
50
|
+
model: {
|
|
51
|
+
kind: "transfer",
|
|
52
|
+
uiState: {
|
|
53
|
+
memo: opts.memo,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
return solanaTx;
|
|
58
|
+
} else {
|
|
59
|
+
if (account.type !== "TokenAccount") {
|
|
60
|
+
throw new Error("expected token account");
|
|
61
|
+
}
|
|
62
|
+
const subAccountId = account.id;
|
|
63
|
+
const solanaTx: SolanaTransaction = {
|
|
64
|
+
...transaction,
|
|
65
|
+
subAccountId,
|
|
66
|
+
model: {
|
|
67
|
+
kind: "token.transfer",
|
|
68
|
+
uiState: {
|
|
69
|
+
memo: opts.memo,
|
|
70
|
+
subAccountId,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
return solanaTx;
|
|
75
|
+
}
|
|
76
|
+
case "optIn": {
|
|
77
|
+
if (token === undefined) {
|
|
78
|
+
throw new Error("token required");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (account.type !== "Account") {
|
|
82
|
+
throw new Error("expected main account");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const tokenCurrency = findTokenByTicker(token) ?? findTokenById(token);
|
|
86
|
+
|
|
87
|
+
if (!tokenCurrency) {
|
|
88
|
+
throw new Error(`token <${token}> not found`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const solanaTx: SolanaTransaction = {
|
|
92
|
+
...transaction,
|
|
93
|
+
model: {
|
|
94
|
+
kind: "token.createATA",
|
|
95
|
+
uiState: {
|
|
96
|
+
tokenId: tokenCurrency.id,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
return solanaTx;
|
|
101
|
+
}
|
|
102
|
+
default:
|
|
103
|
+
return assertUnreachable(mode);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function inferAccounts(
|
|
109
|
+
mainAccount: Account,
|
|
110
|
+
opts: Record<string, string>
|
|
111
|
+
): AccountLikeArray {
|
|
112
|
+
invariant(mainAccount.currency.family === "solana", "solana family currency");
|
|
113
|
+
|
|
114
|
+
const mode = inferMode(opts.mode);
|
|
115
|
+
|
|
116
|
+
switch (mode) {
|
|
117
|
+
case "send": {
|
|
118
|
+
if (!opts.token) {
|
|
119
|
+
return [mainAccount];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// reusing ethereum token option, comes as array
|
|
123
|
+
const tokens: string[] = opts.token as any;
|
|
124
|
+
|
|
125
|
+
if (tokens.length !== 1) {
|
|
126
|
+
throw new Error("only 1 token at a time supported for solana");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const token = tokens[0];
|
|
130
|
+
|
|
131
|
+
const subAccount = mainAccount.subAccounts?.find((subAcc) => {
|
|
132
|
+
const currency = getAccountCurrency(subAcc);
|
|
133
|
+
return token === currency.ticker || token === currency.id;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (subAccount === undefined) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
"token account '" +
|
|
139
|
+
opts.token +
|
|
140
|
+
"' not found. Available: " +
|
|
141
|
+
mainAccount.subAccounts
|
|
142
|
+
?.map((subAcc) => getAccountCurrency(subAcc).ticker)
|
|
143
|
+
.join(", ")
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return [subAccount];
|
|
147
|
+
}
|
|
148
|
+
case "optIn":
|
|
149
|
+
return [mainAccount];
|
|
150
|
+
default:
|
|
151
|
+
return assertUnreachable(mode);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function inferMode(input?: string): Mode {
|
|
156
|
+
const mode: Mode | undefined = input
|
|
157
|
+
? modes.some((m) => m === input)
|
|
158
|
+
? (input as Mode)
|
|
159
|
+
: undefined
|
|
160
|
+
: "send";
|
|
161
|
+
|
|
162
|
+
if (mode === undefined) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Unexpected mode <${mode}>. Supported modes: ${modes.join(", ")}`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return mode;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export default {
|
|
172
|
+
options,
|
|
173
|
+
inferAccounts,
|
|
174
|
+
inferTransactions,
|
|
175
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
name: "solana seed 1",
|
|
3
|
+
apdus: `
|
|
4
|
+
=> e005000009028000002c800001f5
|
|
5
|
+
<= 8bc4d3e507c0550e3d02ffb5f6daf0772240af8a09e32d236615b4a2272437029000
|
|
6
|
+
=> e00500000d038000002c800001f580000000
|
|
7
|
+
<= 56e75dba184e4a77652a1c79a329ffbc562c6bafc33036220c08c0d02ff047739000
|
|
8
|
+
`,
|
|
9
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { AccountLike, Account } from "../../types";
|
|
2
|
+
import type {
|
|
3
|
+
TokenCreateATACommand,
|
|
4
|
+
TokenTransferCommand,
|
|
5
|
+
Transaction,
|
|
6
|
+
TransferCommand,
|
|
7
|
+
ValidCommandDescriptor,
|
|
8
|
+
} from "./types";
|
|
9
|
+
import type { DeviceTransactionField } from "../../transaction";
|
|
10
|
+
import { assertUnreachable } from "./utils";
|
|
11
|
+
|
|
12
|
+
// do not show fields like 'To', 'Recipient', etc., as per Ledger policy
|
|
13
|
+
|
|
14
|
+
function getDeviceTransactionConfig({
|
|
15
|
+
transaction,
|
|
16
|
+
}: {
|
|
17
|
+
account: AccountLike;
|
|
18
|
+
parentAccount: Account | null | undefined;
|
|
19
|
+
transaction: Transaction;
|
|
20
|
+
}): Array<DeviceTransactionField> {
|
|
21
|
+
const { commandDescriptor } = transaction.model;
|
|
22
|
+
if (commandDescriptor === undefined) {
|
|
23
|
+
throw new Error("missing command descriptor");
|
|
24
|
+
}
|
|
25
|
+
switch (commandDescriptor.status) {
|
|
26
|
+
case "valid":
|
|
27
|
+
return fieldsForCommand(commandDescriptor);
|
|
28
|
+
case "invalid":
|
|
29
|
+
throw new Error("unexpected invalid command");
|
|
30
|
+
default:
|
|
31
|
+
return assertUnreachable(commandDescriptor);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default getDeviceTransactionConfig;
|
|
36
|
+
function fieldsForCommand(
|
|
37
|
+
commandDescriptor: ValidCommandDescriptor
|
|
38
|
+
): DeviceTransactionField[] {
|
|
39
|
+
const { command } = commandDescriptor;
|
|
40
|
+
switch (command.kind) {
|
|
41
|
+
case "transfer":
|
|
42
|
+
return fieldsForTransfer(command);
|
|
43
|
+
case "token.transfer":
|
|
44
|
+
return fieldsForTokenTransfer(command);
|
|
45
|
+
case "token.createATA":
|
|
46
|
+
return fieldsForCreateATA(command);
|
|
47
|
+
default:
|
|
48
|
+
return assertUnreachable(command);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function fieldsForTransfer(command: TransferCommand): DeviceTransactionField[] {
|
|
53
|
+
const fields: Array<DeviceTransactionField> = [];
|
|
54
|
+
|
|
55
|
+
fields.push({
|
|
56
|
+
type: "amount",
|
|
57
|
+
label: "Transfer",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
fields.push({
|
|
61
|
+
type: "address",
|
|
62
|
+
address: command.sender,
|
|
63
|
+
label: "Sender",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
fields.push({
|
|
67
|
+
type: "text",
|
|
68
|
+
label: "Fee payer",
|
|
69
|
+
value: "Sender",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return fields;
|
|
73
|
+
}
|
|
74
|
+
function fieldsForTokenTransfer(
|
|
75
|
+
command: TokenTransferCommand
|
|
76
|
+
): DeviceTransactionField[] {
|
|
77
|
+
const fields: Array<DeviceTransactionField> = [];
|
|
78
|
+
|
|
79
|
+
if (command.recipientDescriptor.shouldCreateAsAssociatedTokenAccount) {
|
|
80
|
+
fields.push({
|
|
81
|
+
type: "address",
|
|
82
|
+
label: "Create token acct",
|
|
83
|
+
address: command.recipientDescriptor.tokenAccAddress,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
fields.push({
|
|
87
|
+
type: "address",
|
|
88
|
+
label: "From mint",
|
|
89
|
+
address: command.mintAddress,
|
|
90
|
+
});
|
|
91
|
+
fields.push({
|
|
92
|
+
type: "address",
|
|
93
|
+
label: "Funded by",
|
|
94
|
+
address: command.ownerAddress,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
fields.push({
|
|
99
|
+
type: "amount",
|
|
100
|
+
label: "Transfer tokens",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
fields.push({
|
|
104
|
+
type: "address",
|
|
105
|
+
address: command.ownerAssociatedTokenAccountAddress,
|
|
106
|
+
label: "From",
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
fields.push({
|
|
110
|
+
type: "address",
|
|
111
|
+
address: command.ownerAddress,
|
|
112
|
+
label: "Owner",
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
fields.push({
|
|
116
|
+
type: "address",
|
|
117
|
+
address: command.ownerAddress,
|
|
118
|
+
label: "Fee payer",
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return fields;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function fieldsForCreateATA(
|
|
125
|
+
command: TokenCreateATACommand
|
|
126
|
+
): DeviceTransactionField[] {
|
|
127
|
+
const fields: Array<DeviceTransactionField> = [];
|
|
128
|
+
|
|
129
|
+
fields.push({
|
|
130
|
+
type: "address",
|
|
131
|
+
label: "Create token acct",
|
|
132
|
+
address: command.associatedTokenAccountAddress,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
fields.push({
|
|
136
|
+
type: "address",
|
|
137
|
+
label: "From mint",
|
|
138
|
+
address: command.mint,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
fields.push({
|
|
142
|
+
type: "address",
|
|
143
|
+
label: "Owned by",
|
|
144
|
+
address: command.owner,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
fields.push({
|
|
148
|
+
type: "address",
|
|
149
|
+
label: "Funded by",
|
|
150
|
+
address: command.owner,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
fields.push({
|
|
154
|
+
type: "address",
|
|
155
|
+
label: "Fee payer",
|
|
156
|
+
address: command.owner,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return fields;
|
|
160
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createCustomErrorClass } from "@ledgerhq/errors";
|
|
2
|
+
|
|
3
|
+
export const SolanaAccountNotFunded = createCustomErrorClass(
|
|
4
|
+
"SolanaAccountNotFunded"
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
export const SolanaNotEnoughBalanceToPayFees = createCustomErrorClass(
|
|
8
|
+
"SolanaNotEnoughBalanceToPayFees"
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const SolanaRecipientAssociatedTokenAccountWillBeFunded =
|
|
12
|
+
createCustomErrorClass("SolanaAssociatedTokenAccountWillBeFunded");
|
|
13
|
+
|
|
14
|
+
export const SolanaMemoIsTooLong = createCustomErrorClass(
|
|
15
|
+
"SolanaMemoIsTooLong"
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const SolanaTokenAccountHoldsAnotherToken = createCustomErrorClass(
|
|
19
|
+
"SolanaTokenAccountHoldsAnotherToken"
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const SolanaTokenAccounNotInitialized = createCustomErrorClass(
|
|
23
|
+
"SolanaTokenAccounNotInitialized"
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const SolanaAddressOffEd25519 = createCustomErrorClass(
|
|
27
|
+
"SolanaAddressOfEd25519"
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const SolanaTokenRecipientIsSenderATA = createCustomErrorClass(
|
|
31
|
+
"SolanaTokenRecipientIsSenderATA"
|
|
32
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Resolver } from "../../hw/getAddress/types";
|
|
2
|
+
import Solana from "@ledgerhq/hw-app-solana";
|
|
3
|
+
|
|
4
|
+
import bs58 from "bs58";
|
|
5
|
+
|
|
6
|
+
const resolver: Resolver = async (transport, { path, verify }) => {
|
|
7
|
+
const solana = new Solana(transport);
|
|
8
|
+
|
|
9
|
+
const { address } = await solana.getAddress(path, verify);
|
|
10
|
+
|
|
11
|
+
const publicKey = bs58.encode(address);
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
address: publicKey,
|
|
15
|
+
publicKey,
|
|
16
|
+
path,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default resolver;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { patchOperationWithHash } from "../../operation";
|
|
2
|
+
import type { Account, Operation, SignedOperation } from "../../types";
|
|
3
|
+
import { ChainAPI } from "./api";
|
|
4
|
+
|
|
5
|
+
export const broadcastWithAPI = async (
|
|
6
|
+
{
|
|
7
|
+
signedOperation,
|
|
8
|
+
}: {
|
|
9
|
+
account: Account;
|
|
10
|
+
signedOperation: SignedOperation;
|
|
11
|
+
},
|
|
12
|
+
api: ChainAPI
|
|
13
|
+
): Promise<Operation> => {
|
|
14
|
+
const { signature, operation } = signedOperation;
|
|
15
|
+
const txSignature = await api.sendRawTransaction(
|
|
16
|
+
Buffer.from(signature, "hex")
|
|
17
|
+
);
|
|
18
|
+
const txHash = txSignature;
|
|
19
|
+
return patchOperationWithHash(operation, txHash);
|
|
20
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Account } from "../../types";
|
|
2
|
+
import type { Command, Transaction } from "./types";
|
|
3
|
+
import {
|
|
4
|
+
addSignatureToTransaction,
|
|
5
|
+
buildTransferInstructions,
|
|
6
|
+
buildTokenTransferInstructions,
|
|
7
|
+
buildCreateAssociatedTokenAccountInstruction,
|
|
8
|
+
} from "./api/chain/web3";
|
|
9
|
+
import { assertUnreachable } from "./utils";
|
|
10
|
+
import {
|
|
11
|
+
PublicKey,
|
|
12
|
+
Transaction as OnChainTransaction,
|
|
13
|
+
TransactionInstruction,
|
|
14
|
+
} from "@solana/web3.js";
|
|
15
|
+
import { ChainAPI } from "./api";
|
|
16
|
+
|
|
17
|
+
export const buildTransactionWithAPI = async (
|
|
18
|
+
account: Account,
|
|
19
|
+
transaction: Transaction,
|
|
20
|
+
api: ChainAPI
|
|
21
|
+
): Promise<readonly [Buffer, (signature: Buffer) => Buffer]> => {
|
|
22
|
+
const instructions = buildInstructions(transaction);
|
|
23
|
+
|
|
24
|
+
const recentBlockhash = await api.getRecentBlockhash();
|
|
25
|
+
|
|
26
|
+
const feePayer = new PublicKey(account.freshAddress);
|
|
27
|
+
|
|
28
|
+
const tx = new OnChainTransaction({
|
|
29
|
+
feePayer,
|
|
30
|
+
recentBlockhash,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
tx.add(...instructions);
|
|
34
|
+
|
|
35
|
+
return [
|
|
36
|
+
tx.compileMessage().serialize(),
|
|
37
|
+
(signature: Buffer) => {
|
|
38
|
+
return addSignatureToTransaction({
|
|
39
|
+
tx,
|
|
40
|
+
address: account.freshAddress,
|
|
41
|
+
signature,
|
|
42
|
+
}).serialize();
|
|
43
|
+
},
|
|
44
|
+
] as const;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function buildInstructions(tx: Transaction) {
|
|
48
|
+
const { commandDescriptor } = tx.model;
|
|
49
|
+
if (commandDescriptor === undefined) {
|
|
50
|
+
throw new Error("missing command descriptor");
|
|
51
|
+
}
|
|
52
|
+
switch (commandDescriptor.status) {
|
|
53
|
+
case "valid":
|
|
54
|
+
return buildInstructionsForCommand(commandDescriptor.command);
|
|
55
|
+
case "invalid":
|
|
56
|
+
throw new Error("can not build invalid command");
|
|
57
|
+
default:
|
|
58
|
+
return assertUnreachable(commandDescriptor);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function buildInstructionsForCommand(
|
|
63
|
+
command: Command
|
|
64
|
+
): TransactionInstruction[] {
|
|
65
|
+
switch (command.kind) {
|
|
66
|
+
case "transfer":
|
|
67
|
+
return buildTransferInstructions(command);
|
|
68
|
+
case "token.transfer":
|
|
69
|
+
return buildTokenTransferInstructions(command);
|
|
70
|
+
case "token.createATA":
|
|
71
|
+
return buildCreateAssociatedTokenAccountInstruction(command);
|
|
72
|
+
default:
|
|
73
|
+
return assertUnreachable(command);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { Transaction /* TransactionMode */ } from "./types";
|
|
3
|
+
import { Account } from "../../types";
|
|
4
|
+
|
|
5
|
+
const createTransaction = (_: Account): Transaction => {
|
|
6
|
+
return {
|
|
7
|
+
family: "solana",
|
|
8
|
+
amount: new BigNumber(0),
|
|
9
|
+
useAllAmount: false,
|
|
10
|
+
recipient: "",
|
|
11
|
+
model: {
|
|
12
|
+
kind: "transfer",
|
|
13
|
+
uiState: {
|
|
14
|
+
memo: undefined,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const updateTransaction = (
|
|
21
|
+
t: Transaction,
|
|
22
|
+
patch: Partial<Transaction>
|
|
23
|
+
): Transaction => {
|
|
24
|
+
return { ...t, ...patch };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default createTransaction;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AccountBridge } from "../../types";
|
|
2
|
+
import type { Transaction } from "./types";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { ChainAPI } from "./api";
|
|
5
|
+
|
|
6
|
+
const estimateMaxSpendableWithAPI = async (
|
|
7
|
+
{
|
|
8
|
+
account,
|
|
9
|
+
transaction,
|
|
10
|
+
}: Parameters<AccountBridge<Transaction>["estimateMaxSpendable"]>[0],
|
|
11
|
+
api: ChainAPI
|
|
12
|
+
): Promise<BigNumber> => {
|
|
13
|
+
const feeCalculator =
|
|
14
|
+
transaction?.feeCalculator ?? (await api.getTxFeeCalculator());
|
|
15
|
+
|
|
16
|
+
switch (account.type) {
|
|
17
|
+
case "Account":
|
|
18
|
+
return BigNumber.max(
|
|
19
|
+
account.balance.minus(feeCalculator.lamportsPerSignature),
|
|
20
|
+
0
|
|
21
|
+
);
|
|
22
|
+
case "TokenAccount":
|
|
23
|
+
return account.balance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
throw new Error("not supported account type");
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default estimateMaxSpendableWithAPI;
|