@subwallet/extension-base 1.2.31-0 → 1.2.33-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/background/KoniTypes.d.ts +78 -227
- package/background/KoniTypes.js +3 -40
- package/background/errors/SWError.d.ts +4 -7
- package/background/errors/SWError.js +4 -0
- package/background/errors/TransactionError.d.ts +2 -2
- package/background/errors/TransactionError.js +2 -4
- package/background/handlers/State.d.ts +0 -12
- package/background/types.d.ts +9 -134
- package/background/warnings/TransactionWarning.d.ts +1 -1
- package/background/warnings/TransactionWarning.js +5 -1
- package/cjs/background/KoniTypes.js +4 -44
- package/cjs/background/errors/SWError.js +4 -0
- package/cjs/background/errors/TransactionError.js +13 -15
- package/cjs/background/warnings/TransactionWarning.js +6 -2
- package/cjs/constants/environment.js +13 -0
- package/cjs/constants/index.js +40 -13
- package/cjs/constants/signing.js +23 -0
- package/cjs/constants/storage.js +4 -2
- package/cjs/core/consts.js +20 -0
- package/cjs/core/logic-validation/recipientAddress.js +106 -0
- package/cjs/core/logic-validation/request.js +11 -19
- package/cjs/core/logic-validation/swap.js +5 -5
- package/cjs/core/logic-validation/transfer.js +83 -42
- package/cjs/core/types.js +26 -0
- package/cjs/core/utils.js +113 -0
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +14 -5
- package/cjs/koni/api/staking/bonding/paraChain.js +8 -8
- package/cjs/koni/api/staking/bonding/relayChain.js +9 -9
- package/cjs/koni/api/staking/index.js +4 -1
- package/cjs/koni/background/cron.js +7 -7
- package/cjs/koni/background/handlers/Extension.js +510 -1446
- package/cjs/koni/background/handlers/State.js +61 -238
- package/cjs/koni/background/handlers/Tabs.js +143 -107
- package/cjs/koni/background/subscription.js +5 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/Accounts.js +2 -5
- package/cjs/page/SubWalleEvmProvider.js +1 -1
- package/cjs/page/index.js +2 -1
- package/cjs/services/balance-service/BalanceMapImpl.js +48 -20
- package/cjs/services/balance-service/helpers/subscribe/index.js +27 -15
- package/cjs/services/balance-service/helpers/subscribe/ton/consts.js +40 -0
- package/cjs/services/balance-service/helpers/subscribe/ton/ton.js +120 -0
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +181 -0
- package/cjs/services/balance-service/index.js +25 -13
- package/cjs/services/balance-service/transfer/token.js +41 -24
- package/cjs/services/balance-service/transfer/ton-transfer.js +136 -0
- package/cjs/services/buy-service/index.js +5 -1
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateApi.js +1 -0
- package/cjs/services/chain-service/handler/TonApi.js +213 -0
- package/cjs/services/chain-service/handler/TonChainHandler.js +81 -0
- package/cjs/services/chain-service/index.js +32 -8
- package/cjs/services/chain-service/utils/index.js +78 -22
- package/cjs/services/earning-service/constants/chains.js +3 -1
- package/cjs/services/earning-service/handlers/base.js +2 -1
- package/cjs/services/earning-service/handlers/lending/base.js +8 -9
- package/cjs/services/earning-service/handlers/lending/interlay.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +9 -10
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/astar.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +13 -13
- package/cjs/services/earning-service/handlers/native-staking/base.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +15 -15
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +14 -14
- package/cjs/services/earning-service/handlers/special.js +10 -10
- package/cjs/services/earning-service/service.js +26 -17
- package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +1 -1
- package/cjs/services/history-service/index.js +29 -11
- package/cjs/services/history-service/subscan-history.js +9 -21
- package/cjs/services/keyring-service/context/account-context.js +259 -0
- package/cjs/services/keyring-service/context/handlers/Base.js +20 -0
- package/cjs/services/keyring-service/context/handlers/Derive.js +377 -0
- package/cjs/services/keyring-service/context/handlers/Inject.js +75 -0
- package/cjs/services/keyring-service/context/handlers/Json.js +348 -0
- package/cjs/services/keyring-service/context/handlers/Ledger.js +165 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +218 -0
- package/cjs/services/keyring-service/context/handlers/Modify.js +258 -0
- package/cjs/services/keyring-service/context/handlers/Secret.js +310 -0
- package/cjs/services/keyring-service/context/handlers/index.js +82 -0
- package/cjs/services/keyring-service/context/state.js +649 -0
- package/cjs/services/keyring-service/context/stores/AccountProxy.js +32 -0
- package/cjs/services/keyring-service/context/stores/Base.js +37 -0
- package/cjs/services/keyring-service/context/stores/CurrentAccount.js +28 -0
- package/cjs/services/keyring-service/context/stores/ModifyPair.js +19 -0
- package/cjs/services/keyring-service/context/stores/index.js +38 -0
- package/cjs/services/keyring-service/index.js +20 -164
- package/cjs/services/migration-service/scripts/index.js +6 -4
- package/cjs/services/migration-service/scripts/{MigrateLedgerAccountV2.js → keyring/MigrateLedgerAccountV2.js} +1 -1
- package/cjs/services/migration-service/scripts/keyring/MigratePairData.js +28 -0
- package/cjs/services/migration-service/scripts/{MigrateRemoveGenesisHash.js → keyring/MigrateRemoveGenesisHash.js} +1 -1
- package/cjs/services/request-service/constants.js +5 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +104 -57
- package/cjs/services/request-service/handler/EvmRequestHandler.js +3 -4
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +5 -11
- package/cjs/services/request-service/handler/TonRequestHandler.js +175 -0
- package/cjs/services/request-service/index.js +24 -5
- package/cjs/services/swap-service/handler/asset-hub/handler.js +6 -5
- package/cjs/services/swap-service/handler/base-handler.js +8 -8
- package/cjs/services/swap-service/handler/chainflip-handler.js +5 -4
- package/cjs/services/swap-service/handler/hydradx-handler.js +4 -3
- package/cjs/services/swap-service/index.js +4 -4
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +184 -84
- package/cjs/services/wallet-connect-service/handler/PolkadotRequestHandler.js +2 -10
- package/cjs/stores/AccountProxyStore.js +18 -0
- package/cjs/stores/ModifyPairStore.js +18 -0
- package/cjs/stores/index.js +23 -2
- package/cjs/types/account/action/add/index.js +38 -0
- package/cjs/types/account/action/add/json.js +1 -0
- package/cjs/types/account/action/add/mnemonic.js +1 -0
- package/cjs/types/account/action/add/secret.js +1 -0
- package/cjs/types/account/action/derive.js +1 -0
- package/cjs/types/account/action/edit.js +1 -0
- package/cjs/types/account/action/export.js +1 -0
- package/cjs/types/account/action/index.js +71 -0
- package/cjs/types/account/action/subscribe.js +16 -0
- package/cjs/types/account/action/validate.js +1 -0
- package/cjs/types/account/error/common.js +40 -0
- package/cjs/types/account/error/derive.js +55 -0
- package/cjs/types/account/error/index.js +27 -0
- package/cjs/types/account/index.js +38 -0
- package/cjs/types/account/info/current.js +1 -0
- package/cjs/types/account/info/index.js +38 -0
- package/cjs/types/account/info/keyring.js +90 -0
- package/cjs/types/account/info/proxy.js +49 -0
- package/cjs/types/error.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/transaction/data.js +1 -0
- package/cjs/types/transaction/error.js +53 -0
- package/cjs/types/transaction/index.js +49 -0
- package/cjs/types/transaction/request.js +1 -0
- package/cjs/types/transaction/warning.js +14 -0
- package/cjs/types/yield/actions/join/validate.js +1 -16
- package/cjs/utils/account/analyze.js +166 -0
- package/cjs/utils/account/common.js +121 -0
- package/cjs/utils/account/derive/index.js +27 -0
- package/cjs/utils/account/derive/info/index.js +27 -0
- package/cjs/utils/account/derive/info/solo.js +246 -0
- package/cjs/utils/account/derive/info/unified.js +112 -0
- package/cjs/utils/account/derive/validate.js +177 -0
- package/cjs/utils/account/index.js +49 -0
- package/cjs/utils/account/transform.js +566 -0
- package/cjs/utils/auth.js +46 -0
- package/cjs/utils/getId.js +8 -1
- package/cjs/utils/index.js +48 -62
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +6 -0
- package/constants/index.d.ts +5 -1
- package/constants/index.js +5 -2
- package/constants/signing.d.ts +4 -0
- package/constants/signing.js +15 -0
- package/constants/storage.d.ts +1 -0
- package/constants/storage.js +2 -1
- package/core/consts.d.ts +1 -0
- package/core/consts.js +13 -0
- package/core/logic-validation/recipientAddress.d.ts +2 -0
- package/core/logic-validation/recipientAddress.js +100 -0
- package/core/logic-validation/request.js +10 -18
- package/core/logic-validation/swap.js +1 -1
- package/core/logic-validation/transfer.d.ts +3 -2
- package/core/logic-validation/transfer.js +50 -10
- package/core/types.d.ts +26 -0
- package/core/types.js +19 -0
- package/core/utils.d.ts +10 -0
- package/core/utils.js +105 -0
- package/koni/api/dotsama/crowdloan.js +1 -1
- package/koni/api/nft/index.js +14 -5
- package/koni/api/staking/bonding/paraChain.js +2 -2
- package/koni/api/staking/bonding/relayChain.js +2 -2
- package/koni/api/staking/index.js +4 -1
- package/koni/background/cron.js +7 -7
- package/koni/background/handlers/Extension.d.ts +26 -35
- package/koni/background/handlers/Extension.js +337 -1242
- package/koni/background/handlers/State.d.ts +12 -19
- package/koni/background/handlers/State.js +57 -231
- package/koni/background/handlers/Tabs.d.ts +2 -3
- package/koni/background/handlers/Tabs.js +105 -61
- package/koni/background/subscription.js +5 -5
- package/package.json +352 -53
- package/packageInfo.js +1 -1
- package/page/Accounts.js +2 -5
- package/page/SubWalleEvmProvider.js +1 -1
- package/page/index.js +2 -1
- package/services/balance-service/BalanceMapImpl.d.ts +6 -4
- package/services/balance-service/BalanceMapImpl.js +44 -18
- package/services/balance-service/helpers/subscribe/index.d.ts +3 -4
- package/services/balance-service/helpers/subscribe/index.js +29 -17
- package/services/balance-service/helpers/subscribe/ton/consts.d.ts +18 -0
- package/services/balance-service/helpers/subscribe/ton/consts.js +28 -0
- package/services/balance-service/helpers/subscribe/ton/ton.d.ts +3 -0
- package/services/balance-service/helpers/subscribe/ton/ton.js +111 -0
- package/services/balance-service/helpers/subscribe/ton/types.d.ts +26 -0
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +32 -0
- package/services/balance-service/helpers/subscribe/ton/utils.js +159 -0
- package/services/balance-service/index.js +25 -13
- package/services/balance-service/transfer/token.d.ts +2 -2
- package/services/balance-service/transfer/token.js +18 -1
- package/services/balance-service/transfer/ton-transfer.d.ts +25 -0
- package/services/balance-service/transfer/ton-transfer.js +127 -0
- package/services/buy-service/index.js +5 -1
- package/services/buy-service/types.d.ts +2 -2
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/handler/SubstrateApi.js +1 -0
- package/services/chain-service/handler/TonApi.d.ts +52 -0
- package/services/chain-service/handler/TonApi.js +204 -0
- package/services/chain-service/handler/TonChainHandler.d.ts +17 -0
- package/services/chain-service/handler/TonChainHandler.js +73 -0
- package/services/chain-service/index.d.ts +5 -1
- package/services/chain-service/index.js +32 -8
- package/services/chain-service/types.d.ts +24 -0
- package/services/chain-service/utils/index.d.ts +10 -2
- package/services/chain-service/utils/index.js +59 -18
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +1 -0
- package/services/earning-service/handlers/base.js +3 -2
- package/services/earning-service/handlers/lending/base.js +1 -2
- package/services/earning-service/handlers/lending/interlay.js +2 -2
- package/services/earning-service/handlers/liquid-staking/base.js +1 -2
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
- package/services/earning-service/handlers/native-staking/amplitude.js +2 -2
- package/services/earning-service/handlers/native-staking/astar.js +2 -2
- package/services/earning-service/handlers/native-staking/base-para.js +2 -2
- package/services/earning-service/handlers/native-staking/base.js +2 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +2 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +2 -2
- package/services/earning-service/handlers/nomination-pool/index.js +2 -2
- package/services/earning-service/handlers/special.js +2 -2
- package/services/earning-service/service.js +18 -9
- package/services/event-service/types.d.ts +3 -1
- package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +1 -1
- package/services/history-service/index.d.ts +4 -1
- package/services/history-service/index.js +29 -11
- package/services/history-service/subscan-history.js +8 -20
- package/services/keyring-service/context/account-context.d.ts +87 -0
- package/services/keyring-service/context/account-context.js +250 -0
- package/services/keyring-service/context/handlers/Base.d.ts +11 -0
- package/services/keyring-service/context/handlers/Base.js +13 -0
- package/services/keyring-service/context/handlers/Derive.d.ts +29 -0
- package/services/keyring-service/context/handlers/Derive.js +365 -0
- package/services/keyring-service/context/handlers/Inject.d.ts +11 -0
- package/services/keyring-service/context/handlers/Inject.js +69 -0
- package/services/keyring-service/context/handlers/Json.d.ts +18 -0
- package/services/keyring-service/context/handlers/Json.js +328 -0
- package/services/keyring-service/context/handlers/Ledger.d.ts +11 -0
- package/services/keyring-service/context/handlers/Ledger.js +158 -0
- package/services/keyring-service/context/handlers/Mnemonic.d.ts +15 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +206 -0
- package/services/keyring-service/context/handlers/Modify.d.ts +16 -0
- package/services/keyring-service/context/handlers/Modify.js +250 -0
- package/services/keyring-service/context/handlers/Secret.d.ts +16 -0
- package/services/keyring-service/context/handlers/Secret.js +299 -0
- package/services/keyring-service/context/handlers/index.d.ts +7 -0
- package/services/keyring-service/context/handlers/index.js +10 -0
- package/services/keyring-service/context/state.d.ts +92 -0
- package/services/keyring-service/context/state.js +629 -0
- package/services/keyring-service/context/stores/AccountProxy.d.ts +13 -0
- package/services/keyring-service/context/stores/AccountProxy.js +25 -0
- package/services/keyring-service/context/stores/Base.d.ts +22 -0
- package/services/keyring-service/context/stores/Base.js +30 -0
- package/services/keyring-service/context/stores/CurrentAccount.d.ts +15 -0
- package/services/keyring-service/context/stores/CurrentAccount.js +21 -0
- package/services/keyring-service/context/stores/ModifyPair.d.ts +10 -0
- package/services/keyring-service/context/stores/ModifyPair.js +12 -0
- package/services/keyring-service/context/stores/index.d.ts +3 -0
- package/services/keyring-service/context/stores/index.js +6 -0
- package/services/keyring-service/index.d.ts +10 -22
- package/services/keyring-service/index.js +20 -161
- package/services/migration-service/scripts/index.js +6 -4
- package/services/migration-service/scripts/{MigrateLedgerAccountV2.d.ts → keyring/MigrateLedgerAccountV2.d.ts} +1 -1
- package/services/migration-service/scripts/{MigrateLedgerAccountV2.js → keyring/MigrateLedgerAccountV2.js} +1 -1
- package/services/migration-service/scripts/keyring/MigratePairData.d.ts +4 -0
- package/services/migration-service/scripts/keyring/MigratePairData.js +20 -0
- package/services/migration-service/scripts/{MigrateRemoveGenesisHash.js → keyring/MigrateRemoveGenesisHash.js} +1 -1
- package/services/mkt-campaign-service/types.d.ts +4 -0
- package/services/request-service/constants.d.ts +1 -1
- package/services/request-service/constants.js +2 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
- package/services/request-service/handler/AuthRequestHandler.js +93 -45
- package/services/request-service/handler/EvmRequestHandler.js +3 -4
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +2 -2
- package/services/request-service/handler/SubstrateRequestHandler.js +5 -11
- package/services/request-service/handler/TonRequestHandler.d.ts +17 -0
- package/services/request-service/handler/TonRequestHandler.js +168 -0
- package/services/request-service/index.d.ts +8 -3
- package/services/request-service/index.js +23 -5
- package/services/request-service/types.d.ts +6 -3
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -1
- package/services/swap-service/handler/asset-hub/handler.js +2 -1
- package/services/swap-service/handler/base-handler.js +1 -1
- package/services/swap-service/handler/chainflip-handler.d.ts +1 -1
- package/services/swap-service/handler/chainflip-handler.js +4 -3
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -1
- package/services/swap-service/handler/hydradx-handler.js +2 -1
- package/services/swap-service/index.js +1 -1
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +1 -0
- package/services/transaction-service/index.js +114 -17
- package/services/transaction-service/types.d.ts +4 -2
- package/services/wallet-connect-service/handler/PolkadotRequestHandler.js +2 -10
- package/stores/AccountProxyStore.d.ts +5 -0
- package/stores/AccountProxyStore.js +10 -0
- package/stores/Authorize.d.ts +1 -1
- package/stores/CurrentAccountStore.d.ts +1 -1
- package/stores/ModifyPairStore.d.ts +5 -0
- package/stores/ModifyPairStore.js +10 -0
- package/stores/index.d.ts +4 -1
- package/stores/index.js +5 -2
- package/types/account/action/add/index.d.ts +3 -0
- package/types/account/action/add/index.js +6 -0
- package/types/account/action/add/json.d.ts +29 -0
- package/types/account/action/add/json.js +1 -0
- package/types/account/action/add/mnemonic.d.ts +77 -0
- package/types/account/action/add/mnemonic.js +1 -0
- package/types/account/action/add/secret.d.ts +55 -0
- package/types/account/action/add/secret.js +1 -0
- package/types/account/action/derive.d.ts +77 -0
- package/types/account/action/derive.js +1 -0
- package/types/account/action/edit.d.ts +31 -0
- package/types/account/action/edit.js +1 -0
- package/types/account/action/export.d.ts +15 -0
- package/types/account/action/export.js +1 -0
- package/types/account/action/index.d.ts +6 -0
- package/types/account/action/index.js +9 -0
- package/types/account/action/subscribe.d.ts +22 -0
- package/types/account/action/subscribe.js +10 -0
- package/types/account/action/validate.d.ts +17 -0
- package/types/account/action/validate.js +1 -0
- package/types/account/error/common.d.ts +10 -0
- package/types/account/error/common.js +33 -0
- package/types/account/error/derive.d.ts +13 -0
- package/types/account/error/derive.js +48 -0
- package/types/account/error/index.d.ts +2 -0
- package/types/account/error/index.js +5 -0
- package/types/account/index.d.ts +3 -0
- package/types/account/index.js +6 -0
- package/types/account/info/current.d.ts +10 -0
- package/types/account/info/current.js +1 -0
- package/types/account/info/index.d.ts +3 -0
- package/types/account/info/index.js +6 -0
- package/types/account/info/keyring.d.ts +161 -0
- package/types/account/info/keyring.js +88 -0
- package/types/account/info/proxy.d.ts +73 -0
- package/types/account/info/proxy.js +46 -0
- package/types/balance/index.d.ts +4 -1
- package/types/buy.d.ts +3 -1
- package/types/error.d.ts +8 -0
- package/types/error.js +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +5 -1
- package/types/transaction/data.d.ts +17 -0
- package/types/transaction/data.js +1 -0
- package/types/transaction/error.d.ts +39 -0
- package/types/transaction/error.js +44 -0
- package/types/transaction/index.d.ts +4 -0
- package/types/transaction/index.js +7 -0
- package/types/transaction/request.d.ts +24 -0
- package/types/transaction/request.js +1 -0
- package/types/transaction/warning.d.ts +5 -0
- package/types/transaction/warning.js +8 -0
- package/types/yield/actions/join/submit.d.ts +2 -2
- package/types/yield/actions/join/validate.d.ts +1 -6
- package/types/yield/actions/join/validate.js +1 -10
- package/types/yield/actions/others.d.ts +1 -1
- package/utils/account/analyze.d.ts +4 -0
- package/utils/account/analyze.js +159 -0
- package/utils/account/common.d.ts +16 -0
- package/utils/account/common.js +104 -0
- package/utils/account/derive/index.d.ts +2 -0
- package/utils/account/derive/index.js +5 -0
- package/utils/account/derive/info/index.d.ts +2 -0
- package/utils/account/derive/info/index.js +5 -0
- package/utils/account/derive/info/solo.d.ts +11 -0
- package/utils/account/derive/info/solo.js +230 -0
- package/utils/account/derive/info/unified.d.ts +7 -0
- package/utils/account/derive/info/unified.js +102 -0
- package/utils/account/derive/validate.d.ts +8 -0
- package/utils/account/derive/validate.js +165 -0
- package/utils/account/index.d.ts +4 -0
- package/utils/account/index.js +7 -0
- package/utils/account/transform.d.ts +41 -0
- package/utils/account/transform.js +533 -0
- package/utils/auth.d.ts +2 -0
- package/utils/auth.js +39 -0
- package/utils/canDerive.d.ts +1 -1
- package/utils/eth/mergeTransactionAndSignature.d.ts +1 -1
- package/utils/getId.d.ts +1 -0
- package/utils/getId.js +3 -1
- package/utils/index.d.ts +12 -5
- package/utils/index.js +28 -47
- package/cjs/signers/substrates/KeyringSigner.js +0 -35
- package/cjs/signers/substrates/LedgerSigner.js +0 -44
- package/cjs/signers/substrates/QrSigner.js +0 -63
- package/cjs/signers/types.js +0 -15
- package/cjs/signers/web3/QrSigner.js +0 -67
- package/cjs/utils/account.js +0 -34
- package/signers/substrates/KeyringSigner.d.ts +0 -13
- package/signers/substrates/KeyringSigner.js +0 -27
- package/signers/substrates/LedgerSigner.d.ts +0 -13
- package/signers/substrates/LedgerSigner.js +0 -37
- package/signers/substrates/QrSigner.d.ts +0 -20
- package/signers/substrates/QrSigner.js +0 -55
- package/signers/types.d.ts +0 -34
- package/signers/types.js +0 -9
- package/signers/web3/QrSigner.d.ts +0 -18
- package/signers/web3/QrSigner.js +0 -59
- package/types/transaction.d.ts +0 -3
- package/utils/account.d.ts +0 -5
- package/utils/account.js +0 -24
- /package/cjs/{types/transaction.js → services/balance-service/helpers/subscribe/ton/types.js} +0 -0
- /package/cjs/services/migration-service/scripts/{MigrateLedgerAccount.js → keyring/MigrateLedgerAccount.js} +0 -0
- /package/{types/transaction.js → services/balance-service/helpers/subscribe/ton/types.js} +0 -0
- /package/services/migration-service/scripts/{MigrateLedgerAccount.d.ts → keyring/MigrateLedgerAccount.d.ts} +0 -0
- /package/services/migration-service/scripts/{MigrateLedgerAccount.js → keyring/MigrateLedgerAccount.js} +0 -0
- /package/services/migration-service/scripts/{MigrateRemoveGenesisHash.d.ts → keyring/MigrateRemoveGenesisHash.d.ts} +0 -0
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { AccountProxyType } from '@subwallet/extension-base/types';
|
|
5
6
|
import { isAccountAll } from '@subwallet/extension-base/utils';
|
|
6
7
|
import { BehaviorSubject } from 'rxjs';
|
|
7
8
|
import { groupBalance } from "./helpers/index.js";
|
|
8
9
|
export class BalanceMapImpl {
|
|
9
|
-
constructor(_map = {}) {
|
|
10
|
+
constructor(state, _map = {}) {
|
|
11
|
+
this.state = state;
|
|
10
12
|
this._map = _map;
|
|
11
13
|
this._mapSubject = new BehaviorSubject(_map);
|
|
12
14
|
}
|
|
@@ -24,9 +26,9 @@ export class BalanceMapImpl {
|
|
|
24
26
|
this._map[address] = data;
|
|
25
27
|
this.triggerChange();
|
|
26
28
|
}
|
|
27
|
-
triggerChange(
|
|
28
|
-
if (
|
|
29
|
-
this.
|
|
29
|
+
triggerChange(proxyId) {
|
|
30
|
+
if (proxyId) {
|
|
31
|
+
this.computeBalance(proxyId);
|
|
30
32
|
}
|
|
31
33
|
this._mapSubject.next(this._map);
|
|
32
34
|
}
|
|
@@ -41,11 +43,11 @@ export class BalanceMapImpl {
|
|
|
41
43
|
this._map[address][tokenSlug] = balanceItem;
|
|
42
44
|
trigger && this.triggerChange();
|
|
43
45
|
}
|
|
44
|
-
updateBalanceItems(balanceItems,
|
|
46
|
+
updateBalanceItems(balanceItems, proxyId) {
|
|
45
47
|
balanceItems.forEach(balanceItem => {
|
|
46
48
|
this.updateBalanceItem(balanceItem);
|
|
47
49
|
});
|
|
48
|
-
this.triggerChange(
|
|
50
|
+
this.triggerChange(proxyId);
|
|
49
51
|
}
|
|
50
52
|
removeBalanceItemByFilter(filter) {
|
|
51
53
|
Object.keys(this._map).forEach(address => {
|
|
@@ -57,21 +59,45 @@ export class BalanceMapImpl {
|
|
|
57
59
|
});
|
|
58
60
|
this.triggerChange();
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
computeBalance(_proxyId) {
|
|
63
|
+
const isAll = isAccountAll(_proxyId);
|
|
64
|
+
const compoundMap = {};
|
|
65
|
+
const accountProxies = this.state.keyringService.context.accounts;
|
|
66
|
+
const unifiedAccountsMap = Object.values(accountProxies).filter(value => value.accountType === AccountProxyType.UNIFIED).reduce((rs, value) => {
|
|
67
|
+
rs[value.id] = value.accounts.map(account => account.address);
|
|
68
|
+
return rs;
|
|
69
|
+
}, {});
|
|
70
|
+
const revertUnifiedAccountsMap = Object.entries(unifiedAccountsMap).reduce((rs, [proxyId, accounts]) => {
|
|
71
|
+
if (isAll || proxyId === _proxyId) {
|
|
72
|
+
for (const account of accounts) {
|
|
73
|
+
rs[account] = proxyId;
|
|
67
74
|
}
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
}
|
|
76
|
+
return rs;
|
|
77
|
+
}, {});
|
|
78
|
+
const proxyIds = Object.keys(unifiedAccountsMap);
|
|
79
|
+
Object.keys(this._map).filter(a => !isAccountAll(a) && !proxyIds.includes(a)).forEach(address => {
|
|
80
|
+
const addItemToMap = key => {
|
|
81
|
+
const unifiedAccountBalance = compoundMap[key] || {};
|
|
82
|
+
Object.keys(this._map[address]).forEach(tokenSlug => {
|
|
83
|
+
if (!unifiedAccountBalance[tokenSlug]) {
|
|
84
|
+
unifiedAccountBalance[tokenSlug] = [];
|
|
85
|
+
}
|
|
86
|
+
unifiedAccountBalance[tokenSlug].push(this._map[address][tokenSlug]);
|
|
87
|
+
});
|
|
88
|
+
compoundMap[key] = unifiedAccountBalance;
|
|
89
|
+
};
|
|
90
|
+
const proxyId = revertUnifiedAccountsMap[address];
|
|
91
|
+
isAll && addItemToMap(ALL_ACCOUNT_KEY);
|
|
92
|
+
proxyId && addItemToMap(proxyId);
|
|
70
93
|
});
|
|
71
|
-
Object.entries(
|
|
72
|
-
|
|
94
|
+
Object.entries(compoundMap).forEach(([compoundKey, balanceMap]) => {
|
|
95
|
+
const rs = {};
|
|
96
|
+
Object.entries(balanceMap).forEach(([tokenSlug, balanceItems]) => {
|
|
97
|
+
rs[tokenSlug] = groupBalance(balanceItems, compoundKey, tokenSlug);
|
|
98
|
+
});
|
|
99
|
+
this._map[compoundKey] = rs;
|
|
73
100
|
});
|
|
74
|
-
this._map[ALL_ACCOUNT_KEY] = allAccountBalanceInfo;
|
|
75
101
|
}
|
|
76
102
|
|
|
77
103
|
// Remove balance items buy address or tokenSlug
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { BalanceItem } from '@subwallet/extension-base/types';
|
|
3
|
+
import { _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
+
import { AccountJson, BalanceItem } from '@subwallet/extension-base/types';
|
|
6
5
|
/**
|
|
7
6
|
* @function getAccountJsonByAddress
|
|
8
7
|
* @desc Get account info by address
|
|
@@ -13,4 +12,4 @@ import { BalanceItem } from '@subwallet/extension-base/types';
|
|
|
13
12
|
* @returns {AccountJson|null} - Account info or null if not found
|
|
14
13
|
*/
|
|
15
14
|
export declare const getAccountJsonByAddress: (address: string) => AccountJson | null;
|
|
16
|
-
export declare function subscribeBalance(addresses: string[], chains: string[], tokens: string[], _chainAssetMap: Record<string, _ChainAsset>, _chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem[]) => void, extrinsicType?: ExtrinsicType): () => void;
|
|
15
|
+
export declare function subscribeBalance(addresses: string[], chains: string[], tokens: string[], _chainAssetMap: Record<string, _ChainAsset>, _chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, tonApiMap: Record<string, _TonApi>, callback: (rs: BalanceItem[]) => void, extrinsicType?: ExtrinsicType): () => void;
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
5
|
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import { _getSubstrateGenesisHash, _isChainEvmCompatible, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
-
import { categoryAddresses, filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
|
|
6
|
+
import { _getSubstrateGenesisHash, _isChainBitcoinCompatible, _isChainEvmCompatible, _isChainTonCompatible, _isPureEvmChain, _isPureTonChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { categoryAddresses, filterAssetsByChainAndType, pairToAccount } from '@subwallet/extension-base/utils';
|
|
8
8
|
import keyring from '@subwallet/ui-keyring';
|
|
9
|
+
import { subscribeTonBalance } from "./ton/ton.js";
|
|
9
10
|
import { subscribeEVMBalance } from "./evm.js";
|
|
10
11
|
import { subscribeSubstrateBalance } from "./substrate/index.js";
|
|
11
12
|
|
|
@@ -22,11 +23,7 @@ export const getAccountJsonByAddress = address => {
|
|
|
22
23
|
try {
|
|
23
24
|
const pair = keyring.getPair(address);
|
|
24
25
|
if (pair) {
|
|
25
|
-
return
|
|
26
|
-
address: pair.address,
|
|
27
|
-
type: pair.type,
|
|
28
|
-
...pair.meta
|
|
29
|
-
};
|
|
26
|
+
return pairToAccount(pair);
|
|
30
27
|
} else {
|
|
31
28
|
return null;
|
|
32
29
|
}
|
|
@@ -38,14 +35,22 @@ export const getAccountJsonByAddress = address => {
|
|
|
38
35
|
|
|
39
36
|
/** Filter addresses to subscribe by chain info */
|
|
40
37
|
const filterAddress = (addresses, chainInfo) => {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const {
|
|
39
|
+
bitcoin,
|
|
40
|
+
evm,
|
|
41
|
+
substrate,
|
|
42
|
+
ton
|
|
43
|
+
} = categoryAddresses(addresses);
|
|
44
|
+
if (_isChainEvmCompatible(chainInfo)) {
|
|
45
|
+
return [evm, [...bitcoin, ...substrate, ...ton]];
|
|
46
|
+
} else if (_isChainBitcoinCompatible(chainInfo)) {
|
|
47
|
+
return [bitcoin, [...evm, ...substrate, ...ton]];
|
|
48
|
+
} else if (_isChainTonCompatible(chainInfo)) {
|
|
49
|
+
return [ton, [...bitcoin, ...evm, ...substrate]];
|
|
45
50
|
} else {
|
|
46
51
|
const fetchList = [];
|
|
47
52
|
const unfetchList = [];
|
|
48
|
-
|
|
53
|
+
substrate.forEach(address => {
|
|
49
54
|
const account = getAccountJsonByAddress(address);
|
|
50
55
|
if (account) {
|
|
51
56
|
if (account.isHardware) {
|
|
@@ -67,7 +72,7 @@ const filterAddress = (addresses, chainInfo) => {
|
|
|
67
72
|
fetchList.push(address);
|
|
68
73
|
}
|
|
69
74
|
});
|
|
70
|
-
return [fetchList, [...unfetchList, ...
|
|
75
|
+
return [fetchList, [...unfetchList, ...bitcoin, ...evm, ...ton]];
|
|
71
76
|
}
|
|
72
77
|
};
|
|
73
78
|
const handleUnsupportedOrPendingAddresses = (addresses, chainSlug, chainAssetMap, state, callback) => {
|
|
@@ -87,7 +92,7 @@ const handleUnsupportedOrPendingAddresses = (addresses, chainSlug, chainAssetMap
|
|
|
87
92
|
};
|
|
88
93
|
|
|
89
94
|
// main subscription, use for multiple chains, multiple addresses and multiple tokens
|
|
90
|
-
export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, callback, extrinsicType) {
|
|
95
|
+
export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, callback, extrinsicType) {
|
|
91
96
|
// Filter chain and token
|
|
92
97
|
const chainAssetMap = Object.fromEntries(Object.entries(_chainAssetMap).filter(([token]) => tokens.includes(token)));
|
|
93
98
|
const chainInfoMap = Object.fromEntries(Object.entries(_chainInfoMap).filter(([chain]) => chains.includes(chain)));
|
|
@@ -109,10 +114,17 @@ export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _cha
|
|
|
109
114
|
evmApi
|
|
110
115
|
});
|
|
111
116
|
}
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
114
|
-
|
|
117
|
+
const tonApi = tonApiMap[chainSlug];
|
|
118
|
+
if (_isPureTonChain(chainInfo)) {
|
|
119
|
+
return subscribeTonBalance({
|
|
120
|
+
addresses: useAddresses,
|
|
121
|
+
assetMap: chainAssetMap,
|
|
122
|
+
callback,
|
|
123
|
+
chainInfo,
|
|
124
|
+
tonApi
|
|
125
|
+
});
|
|
115
126
|
}
|
|
127
|
+
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
116
128
|
return subscribeSubstrateBalance(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
|
|
117
129
|
});
|
|
118
130
|
return () => {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const WORKCHAIN = 0;
|
|
2
|
+
export declare const INIT_FEE_JETTON_TRANSFER = "0.1";
|
|
3
|
+
export declare enum TON_OPCODES {
|
|
4
|
+
JETTON_TRANSFER = 260734629,
|
|
5
|
+
NFT_TRANSFER = 1607220500,
|
|
6
|
+
STONFI_SWAP = 630424929
|
|
7
|
+
}
|
|
8
|
+
export declare const SW_QUERYID_HEX = 536937731;
|
|
9
|
+
export declare const EXTRA_TON_ESTIMATE_FEE: bigint;
|
|
10
|
+
export declare const TON_CENTER_API_KEY = "078f715c911784eb4c8d2d545da3ce5db5d07996452bb2246e0a0071c66b87e9";
|
|
11
|
+
export declare enum SendMode {
|
|
12
|
+
CARRY_ALL_REMAINING_BALANCE = 128,
|
|
13
|
+
CARRY_ALL_REMAINING_INCOMING_VALUE = 64,
|
|
14
|
+
DESTROY_ACCOUNT_IF_ZERO = 32,
|
|
15
|
+
PAY_GAS_SEPARATELY = 1,
|
|
16
|
+
IGNORE_ERRORS = 2,
|
|
17
|
+
NONE = 0
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export const WORKCHAIN = 0;
|
|
5
|
+
export const INIT_FEE_JETTON_TRANSFER = '0.1';
|
|
6
|
+
export let TON_OPCODES;
|
|
7
|
+
(function (TON_OPCODES) {
|
|
8
|
+
TON_OPCODES[TON_OPCODES["JETTON_TRANSFER"] = 260734629] = "JETTON_TRANSFER";
|
|
9
|
+
TON_OPCODES[TON_OPCODES["NFT_TRANSFER"] = 1607220500] = "NFT_TRANSFER";
|
|
10
|
+
TON_OPCODES[TON_OPCODES["STONFI_SWAP"] = 630424929] = "STONFI_SWAP";
|
|
11
|
+
})(TON_OPCODES || (TON_OPCODES = {}));
|
|
12
|
+
export const SW_QUERYID_HEX = 0x20010503;
|
|
13
|
+
export const EXTRA_TON_ESTIMATE_FEE = BigInt(500);
|
|
14
|
+
|
|
15
|
+
// todo: This is just free API for dev, remove this and set better RPC later
|
|
16
|
+
// export const TON_CENTER_API_KEY = '98b3eaf42da2981d265bfa6aea2c8d390befb6f677f675fefd3b12201bdf1bc3';
|
|
17
|
+
// export const TON_CENTER_API_KEY = '870ff97c30ad16dc4297bcac8bcf2243a4daffeba6c6d6c31553e342811e673a';
|
|
18
|
+
export const TON_CENTER_API_KEY = '078f715c911784eb4c8d2d545da3ce5db5d07996452bb2246e0a0071c66b87e9'; // alibaba
|
|
19
|
+
|
|
20
|
+
export let SendMode;
|
|
21
|
+
(function (SendMode) {
|
|
22
|
+
SendMode[SendMode["CARRY_ALL_REMAINING_BALANCE"] = 128] = "CARRY_ALL_REMAINING_BALANCE";
|
|
23
|
+
SendMode[SendMode["CARRY_ALL_REMAINING_INCOMING_VALUE"] = 64] = "CARRY_ALL_REMAINING_INCOMING_VALUE";
|
|
24
|
+
SendMode[SendMode["DESTROY_ACCOUNT_IF_ZERO"] = 32] = "DESTROY_ACCOUNT_IF_ZERO";
|
|
25
|
+
SendMode[SendMode["PAY_GAS_SEPARATELY"] = 1] = "PAY_GAS_SEPARATELY";
|
|
26
|
+
SendMode[SendMode["IGNORE_ERRORS"] = 2] = "IGNORE_ERRORS";
|
|
27
|
+
SendMode[SendMode["NONE"] = 0] = "NONE";
|
|
28
|
+
})(SendMode || (SendMode = {}));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SubscribeTonPalletBalance } from '@subwallet/extension-base/types';
|
|
2
|
+
export declare function subscribeJettonBalanceInterval({ addresses, assetMap, callback, chainInfo, tonApi }: SubscribeTonPalletBalance): () => void;
|
|
3
|
+
export declare function subscribeTonBalance(params: SubscribeTonPalletBalance): () => void;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
|
+
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import { ASTAR_REFRESH_BALANCE_INTERVAL, SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
7
|
+
import { getJettonMasterContract, getJettonWalletContract } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
8
|
+
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
|
+
import { filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
|
|
10
|
+
import { Address } from '@ton/core';
|
|
11
|
+
export function subscribeJettonBalanceInterval({
|
|
12
|
+
addresses,
|
|
13
|
+
assetMap,
|
|
14
|
+
callback,
|
|
15
|
+
chainInfo,
|
|
16
|
+
tonApi
|
|
17
|
+
}) {
|
|
18
|
+
const chain = chainInfo.slug;
|
|
19
|
+
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.TEP74]);
|
|
20
|
+
const jettonMasterContractMap = {};
|
|
21
|
+
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
22
|
+
jettonMasterContractMap[slug] = getJettonMasterContract(tonApi, _getContractAddressOfToken(tokenInfo));
|
|
23
|
+
});
|
|
24
|
+
const getJettonBalances = () => {
|
|
25
|
+
Object.values(tokenList).map(async tokenInfo => {
|
|
26
|
+
try {
|
|
27
|
+
const masterContract = jettonMasterContractMap[tokenInfo.slug];
|
|
28
|
+
const balances = await Promise.all(addresses.map(async address => {
|
|
29
|
+
try {
|
|
30
|
+
const jettonWalletContract = await getJettonWalletContract(masterContract, tonApi, address);
|
|
31
|
+
return await jettonWalletContract.getBalance();
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(`Error on get balance of account ${address} for token ${tokenInfo.slug}`, e);
|
|
34
|
+
return BigInt(0);
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
const items = balances.map((balance, index) => {
|
|
38
|
+
return {
|
|
39
|
+
address: addresses[index],
|
|
40
|
+
tokenSlug: tokenInfo.slug,
|
|
41
|
+
free: balance.toString(),
|
|
42
|
+
locked: '0',
|
|
43
|
+
state: APIItemState.READY
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
callback(items);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.log(tokenInfo.slug, err);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
getJettonBalances();
|
|
53
|
+
const interval = setInterval(getJettonBalances, SUB_TOKEN_REFRESH_BALANCE_INTERVAL);
|
|
54
|
+
return () => {
|
|
55
|
+
clearInterval(interval);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async function getTonBalance(addresses, tonApi) {
|
|
59
|
+
return await Promise.all(addresses.map(async address => {
|
|
60
|
+
try {
|
|
61
|
+
const tonAddress = Address.parse(address);
|
|
62
|
+
return await tonApi.getBalance(tonAddress);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return BigInt(0);
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
export function subscribeTonBalance(params) {
|
|
69
|
+
var _Object$values$;
|
|
70
|
+
const {
|
|
71
|
+
addresses,
|
|
72
|
+
assetMap,
|
|
73
|
+
callback,
|
|
74
|
+
chainInfo,
|
|
75
|
+
tonApi
|
|
76
|
+
} = params;
|
|
77
|
+
const chain = chainInfo.slug;
|
|
78
|
+
const nativeTokenInfo = filterAssetsByChainAndType(assetMap, chain, [_AssetType.NATIVE]);
|
|
79
|
+
const nativeTokenSlug = ((_Object$values$ = Object.values(nativeTokenInfo)[0]) === null || _Object$values$ === void 0 ? void 0 : _Object$values$.slug) || '';
|
|
80
|
+
function getBalance() {
|
|
81
|
+
getTonBalance(addresses, tonApi).then(balances => {
|
|
82
|
+
return balances.map((balance, index) => {
|
|
83
|
+
return {
|
|
84
|
+
address: addresses[index],
|
|
85
|
+
tokenSlug: nativeTokenSlug,
|
|
86
|
+
state: APIItemState.READY,
|
|
87
|
+
free: balance.toString(),
|
|
88
|
+
locked: '0'
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}).catch(e => {
|
|
92
|
+
console.error(`Error on get native balance with token ${nativeTokenSlug}`, e);
|
|
93
|
+
return addresses.map(address => {
|
|
94
|
+
return {
|
|
95
|
+
address: address,
|
|
96
|
+
tokenSlug: nativeTokenSlug,
|
|
97
|
+
state: APIItemState.READY,
|
|
98
|
+
free: '0',
|
|
99
|
+
locked: '0'
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
}).then(items => callback(items)).catch(console.error);
|
|
103
|
+
}
|
|
104
|
+
getBalance();
|
|
105
|
+
const interval = setInterval(getBalance, ASTAR_REFRESH_BALANCE_INTERVAL);
|
|
106
|
+
const unsub2 = subscribeJettonBalanceInterval(params);
|
|
107
|
+
return () => {
|
|
108
|
+
clearInterval(interval);
|
|
109
|
+
unsub2 && unsub2();
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Cell } from '@ton/core';
|
|
3
|
+
export declare type Signer = (message: Cell) => Promise<Buffer>;
|
|
4
|
+
export interface TxByMsgResponse {
|
|
5
|
+
transactions: TxDetailInfo[];
|
|
6
|
+
}
|
|
7
|
+
export declare type AccountState = 'uninitialized' | 'active' | 'frozen' | 'unknown';
|
|
8
|
+
interface TxDetailInfo {
|
|
9
|
+
hash: string;
|
|
10
|
+
description: {
|
|
11
|
+
compute_ph: {
|
|
12
|
+
success: boolean;
|
|
13
|
+
};
|
|
14
|
+
action: {
|
|
15
|
+
success: boolean;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
in_msg: Msg;
|
|
19
|
+
out_msgs: Msg[];
|
|
20
|
+
}
|
|
21
|
+
interface Msg {
|
|
22
|
+
hash: string;
|
|
23
|
+
bounced: boolean;
|
|
24
|
+
opcode: string;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TxByMsgResponse } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/types';
|
|
3
|
+
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
4
|
+
import { TonApi } from '@subwallet/extension-base/services/chain-service/handler/TonApi';
|
|
5
|
+
import { _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
|
+
import { TonWalletContract } from '@subwallet/keyring/types';
|
|
7
|
+
import { Address, Cell, MessageRelaxed } from '@ton/core';
|
|
8
|
+
import { JettonMaster, JettonWallet, OpenedContract } from '@ton/ton';
|
|
9
|
+
import { Buffer } from 'buffer';
|
|
10
|
+
export declare function getJettonMasterContract(tonApi: _TonApi, contractAddress: string): OpenedContract<JettonMaster>;
|
|
11
|
+
export declare function getJettonWalletContract(jettonMasterContract: OpenedContract<JettonMaster>, tonApi: _TonApi, ownerAddress: string): Promise<OpenedContract<JettonWallet>>;
|
|
12
|
+
export declare function externalMessage(contract: TonWalletContract, seqno: number, body: Cell): Cell;
|
|
13
|
+
export declare function retry<T>(fn: () => Promise<T>, options: {
|
|
14
|
+
retries: number;
|
|
15
|
+
delay: number;
|
|
16
|
+
}): Promise<T>;
|
|
17
|
+
export declare function getMessageTxStatus(txByMsgInfo: TxByMsgResponse): boolean;
|
|
18
|
+
export declare function getNativeTonTxStatus(tonApi: TonApi, internalMsgHash: string): Promise<boolean>;
|
|
19
|
+
export declare function getJettonTxStatus(tonApi: TonApi, jettonTransferMsgHash: string): Promise<boolean>;
|
|
20
|
+
export declare function estimateTonTxFee(tonApi: _TonApi, messages: MessageRelaxed[], walletContract: TonWalletContract, _seqno?: number): Promise<bigint>;
|
|
21
|
+
export declare function messageRelaxedToCell(message: MessageRelaxed): Cell;
|
|
22
|
+
export declare function cellToBase64Str(cell: Cell): string;
|
|
23
|
+
export declare function getWalletQueryId(): bigint;
|
|
24
|
+
export declare function isBounceableAddress(address: string): boolean;
|
|
25
|
+
export declare function tonAddressInfo(address: string): {
|
|
26
|
+
isBounceable: boolean;
|
|
27
|
+
isTestOnly: boolean;
|
|
28
|
+
address: Address;
|
|
29
|
+
} | undefined;
|
|
30
|
+
export declare function getTonSendMode(isTransferAll: boolean): number;
|
|
31
|
+
export declare function getTransferCellPromise(walletContract: TonWalletContract, signer: (message: Cell) => Promise<Buffer>, payload: TonTransactionConfig, seqno: number, messages: MessageRelaxed[]): Promise<Cell>;
|
|
32
|
+
export declare function getTransferCell(walletContract: TonWalletContract, secretKey: Buffer, seqno: number, messages: MessageRelaxed[]): Cell;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { EXTRA_TON_ESTIMATE_FEE, SendMode, SW_QUERYID_HEX } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/consts';
|
|
5
|
+
import { Address, beginCell, storeMessage, storeMessageRelaxed } from '@ton/core';
|
|
6
|
+
import { external, JettonMaster, JettonWallet, WalletContractV3R1, WalletContractV3R2, WalletContractV4, WalletContractV5R1 } from '@ton/ton';
|
|
7
|
+
import { Buffer } from 'buffer';
|
|
8
|
+
import nacl from 'tweetnacl';
|
|
9
|
+
export function getJettonMasterContract(tonApi, contractAddress) {
|
|
10
|
+
const masterAddress = Address.parse(contractAddress);
|
|
11
|
+
return tonApi.open(JettonMaster.create(masterAddress));
|
|
12
|
+
}
|
|
13
|
+
export async function getJettonWalletContract(jettonMasterContract, tonApi, ownerAddress) {
|
|
14
|
+
const walletAddress = Address.parse(ownerAddress);
|
|
15
|
+
const jettonWalletAddress = await jettonMasterContract.getWalletAddress(walletAddress);
|
|
16
|
+
return tonApi.open(JettonWallet.create(jettonWalletAddress));
|
|
17
|
+
}
|
|
18
|
+
export function externalMessage(contract, seqno, body) {
|
|
19
|
+
return beginCell().storeWritable(storeMessage(external({
|
|
20
|
+
to: contract.address,
|
|
21
|
+
init: seqno === 0 ? contract.init : undefined,
|
|
22
|
+
// contract init for first transaction.
|
|
23
|
+
body: body
|
|
24
|
+
}))).endCell();
|
|
25
|
+
}
|
|
26
|
+
export async function retry(fn, options) {
|
|
27
|
+
let lastError;
|
|
28
|
+
for (let i = 0; i < options.retries; i++) {
|
|
29
|
+
try {
|
|
30
|
+
return await fn();
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e instanceof Error) {
|
|
33
|
+
lastError = e;
|
|
34
|
+
}
|
|
35
|
+
await new Promise(resolve => setTimeout(resolve, options.delay)); // wait for delay period, then recall the fn()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
throw lastError; // throw only last error, in case no successful result from fn()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getMessageTxStatus(txByMsgInfo) {
|
|
43
|
+
var _txDetailInfo$descrip, _txDetailInfo$descrip2, _txDetailInfo$descrip3, _txDetailInfo$descrip4, _txDetailInfo$descrip5, _txDetailInfo$descrip6, _txDetailInfo$out_msg, _txDetailInfo$out_msg2;
|
|
44
|
+
const txDetailInfo = txByMsgInfo.transactions[0];
|
|
45
|
+
const isCompute = (_txDetailInfo$descrip = (_txDetailInfo$descrip2 = txDetailInfo.description) === null || _txDetailInfo$descrip2 === void 0 ? void 0 : (_txDetailInfo$descrip3 = _txDetailInfo$descrip2.compute_ph) === null || _txDetailInfo$descrip3 === void 0 ? void 0 : _txDetailInfo$descrip3.success) !== null && _txDetailInfo$descrip !== void 0 ? _txDetailInfo$descrip : false;
|
|
46
|
+
const isAction = (_txDetailInfo$descrip4 = (_txDetailInfo$descrip5 = txDetailInfo.description) === null || _txDetailInfo$descrip5 === void 0 ? void 0 : (_txDetailInfo$descrip6 = _txDetailInfo$descrip5.action) === null || _txDetailInfo$descrip6 === void 0 ? void 0 : _txDetailInfo$descrip6.success) !== null && _txDetailInfo$descrip4 !== void 0 ? _txDetailInfo$descrip4 : false;
|
|
47
|
+
const isBounced = (_txDetailInfo$out_msg = (_txDetailInfo$out_msg2 = txDetailInfo.out_msgs[0]) === null || _txDetailInfo$out_msg2 === void 0 ? void 0 : _txDetailInfo$out_msg2.bounced) !== null && _txDetailInfo$out_msg !== void 0 ? _txDetailInfo$out_msg : false;
|
|
48
|
+
return isCompute && isAction && !isBounced;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
export async function getNativeTonTxStatus(tonApi, internalMsgHash) {
|
|
53
|
+
const internalTxInfoRaw = await tonApi.getTxByInMsg(internalMsgHash);
|
|
54
|
+
return getMessageTxStatus(internalTxInfoRaw);
|
|
55
|
+
}
|
|
56
|
+
export async function getJettonTxStatus(tonApi, jettonTransferMsgHash) {
|
|
57
|
+
const jettonTransferTxInfoRaw = await tonApi.getTxByInMsg(jettonTransferMsgHash);
|
|
58
|
+
const status = getMessageTxStatus(jettonTransferTxInfoRaw);
|
|
59
|
+
if (status) {
|
|
60
|
+
var _jettonTransferTxInfo;
|
|
61
|
+
// Jetton Transfer success -> Check Jetton Internal Transfer
|
|
62
|
+
const jettonTransferTxInfo = jettonTransferTxInfoRaw.transactions[0];
|
|
63
|
+
const jettonInternalTransferHash = (_jettonTransferTxInfo = jettonTransferTxInfo.out_msgs[0]) === null || _jettonTransferTxInfo === void 0 ? void 0 : _jettonTransferTxInfo.hash;
|
|
64
|
+
const jettonInternalTransferTxInfoRaw = await tonApi.getTxByInMsg(jettonInternalTransferHash);
|
|
65
|
+
return getMessageTxStatus(jettonInternalTransferTxInfoRaw); // Jetton Internal Transfer success -> Receiver successfully receiver fund!
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
export async function estimateTonTxFee(tonApi, messages, walletContract, _seqno) {
|
|
71
|
+
const contract = tonApi.open(walletContract);
|
|
72
|
+
const seqno = _seqno !== null && _seqno !== void 0 ? _seqno : await contract.getSeqno();
|
|
73
|
+
const isInit = seqno !== 0;
|
|
74
|
+
const similatedSecretKey = Buffer.from(new Array(64));
|
|
75
|
+
const simulatedTxCell = getTransferCell(walletContract, similatedSecretKey, seqno, messages);
|
|
76
|
+
const estimateFeeInfo = await tonApi.estimateExternalMessageFee(walletContract, simulatedTxCell, isInit);
|
|
77
|
+
return BigInt(estimateFeeInfo.source_fees.gas_fee + estimateFeeInfo.source_fees.in_fwd_fee + estimateFeeInfo.source_fees.storage_fee + estimateFeeInfo.source_fees.fwd_fee) + EXTRA_TON_ESTIMATE_FEE;
|
|
78
|
+
}
|
|
79
|
+
export function messageRelaxedToCell(message) {
|
|
80
|
+
return beginCell().store(storeMessageRelaxed(message)).endCell();
|
|
81
|
+
}
|
|
82
|
+
export function cellToBase64Str(cell) {
|
|
83
|
+
return cell.toBoc().toString('base64');
|
|
84
|
+
}
|
|
85
|
+
export function getWalletQueryId() {
|
|
86
|
+
const swSignal = SW_QUERYID_HEX.toString(16);
|
|
87
|
+
const swSignalBuffer = Buffer.from(swSignal, 'hex');
|
|
88
|
+
const randomBuffer = nacl.randomBytes(4);
|
|
89
|
+
const buffer = Buffer.concat([swSignalBuffer, randomBuffer]);
|
|
90
|
+
return BigInt('0x' + buffer.toString('hex'));
|
|
91
|
+
}
|
|
92
|
+
export function isBounceableAddress(address) {
|
|
93
|
+
return Address.isFriendly(address) ? Address.parseFriendly(address).isBounceable : true;
|
|
94
|
+
}
|
|
95
|
+
export function tonAddressInfo(address) {
|
|
96
|
+
return Address.isFriendly(address) ? Address.parseFriendly(address) : undefined;
|
|
97
|
+
}
|
|
98
|
+
export function getTonSendMode(isTransferAll) {
|
|
99
|
+
return isTransferAll ? SendMode.CARRY_ALL_REMAINING_BALANCE : SendMode.PAY_GAS_SEPARATELY + SendMode.IGNORE_ERRORS;
|
|
100
|
+
}
|
|
101
|
+
const isVersionv3r1 = walletContract => {
|
|
102
|
+
return walletContract instanceof WalletContractV3R1;
|
|
103
|
+
};
|
|
104
|
+
const isVersionv3r2 = walletContract => {
|
|
105
|
+
return walletContract instanceof WalletContractV3R2;
|
|
106
|
+
};
|
|
107
|
+
const isVersionv4 = walletContract => {
|
|
108
|
+
return walletContract instanceof WalletContractV4;
|
|
109
|
+
};
|
|
110
|
+
const isVersionv5r1 = walletContract => {
|
|
111
|
+
return walletContract instanceof WalletContractV5R1;
|
|
112
|
+
};
|
|
113
|
+
export function getTransferCellPromise(walletContract, signer, payload, seqno, messages) {
|
|
114
|
+
let promise;
|
|
115
|
+
const params = {
|
|
116
|
+
signer,
|
|
117
|
+
sendMode: getTonSendMode(payload.transferAll),
|
|
118
|
+
seqno: seqno,
|
|
119
|
+
messages: messages
|
|
120
|
+
};
|
|
121
|
+
if (isVersionv3r1(walletContract)) {
|
|
122
|
+
promise = walletContract.createTransfer(params);
|
|
123
|
+
} else if (isVersionv3r2(walletContract)) {
|
|
124
|
+
promise = walletContract.createTransfer(params);
|
|
125
|
+
} else if (isVersionv4(walletContract)) {
|
|
126
|
+
promise = walletContract.createTransfer(params);
|
|
127
|
+
} else if (isVersionv5r1(walletContract)) {
|
|
128
|
+
promise = walletContract.createTransfer({
|
|
129
|
+
...params,
|
|
130
|
+
sendMode: params.sendMode
|
|
131
|
+
});
|
|
132
|
+
} else {
|
|
133
|
+
throw new Error('Unknown wallet contract address');
|
|
134
|
+
}
|
|
135
|
+
return promise;
|
|
136
|
+
}
|
|
137
|
+
export function getTransferCell(walletContract, secretKey, seqno, messages) {
|
|
138
|
+
let cell;
|
|
139
|
+
const params = {
|
|
140
|
+
secretKey,
|
|
141
|
+
seqno,
|
|
142
|
+
messages
|
|
143
|
+
};
|
|
144
|
+
if (isVersionv3r1(walletContract)) {
|
|
145
|
+
cell = walletContract.createTransfer(params);
|
|
146
|
+
} else if (isVersionv3r2(walletContract)) {
|
|
147
|
+
cell = walletContract.createTransfer(params);
|
|
148
|
+
} else if (isVersionv4(walletContract)) {
|
|
149
|
+
cell = walletContract.createTransfer(params);
|
|
150
|
+
} else if (isVersionv5r1(walletContract)) {
|
|
151
|
+
cell = walletContract.createTransfer({
|
|
152
|
+
...params,
|
|
153
|
+
sendMode: params.sendMode
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
throw new Error('Unknown wallet contract address');
|
|
157
|
+
}
|
|
158
|
+
return cell;
|
|
159
|
+
}
|