@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
|
@@ -9,10 +9,14 @@ var _api = require("@gear-js/api");
|
|
|
9
9
|
var _types = require("@subwallet/chain-list/types");
|
|
10
10
|
var _wasm = require("@subwallet/extension-base/koni/api/contract-handler/wasm");
|
|
11
11
|
var _utils = require("@subwallet/extension-base/koni/api/contract-handler/wasm/utils");
|
|
12
|
+
var _utils2 = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils");
|
|
12
13
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
14
|
+
var _utils3 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
15
|
+
var _utils4 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
16
|
+
var _utils5 = require("@subwallet/extension-base/utils");
|
|
17
|
+
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
18
|
+
var _core = require("@ton/core");
|
|
19
|
+
var _ton = require("@ton/ton");
|
|
16
20
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
17
21
|
var _util = require("@polkadot/util");
|
|
18
22
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
@@ -44,15 +48,15 @@ const createTransferExtrinsic = async _ref => {
|
|
|
44
48
|
const isTxAssetsSupported = !!api && !!api.tx && !!api.tx.assets;
|
|
45
49
|
let transferAmount; // for PSP-22 tokens, might be deprecated in the future
|
|
46
50
|
|
|
47
|
-
if ((0,
|
|
48
|
-
const onChainInfo = (0,
|
|
51
|
+
if ((0, _utils3._isBridgedToken)(tokenInfo) && api.tx.foreignAssets) {
|
|
52
|
+
const onChainInfo = (0, _utils3._getTokenOnChainInfo)(tokenInfo) || (0, _utils3._getXcmAssetMultilocation)(tokenInfo);
|
|
49
53
|
if (transferAll) {
|
|
50
54
|
transfer = api.tx.foreignAssets.transfer(onChainInfo, to, value);
|
|
51
55
|
} else {
|
|
52
56
|
transfer = api.tx.foreignAssets.transferKeepAlive(onChainInfo, to, value);
|
|
53
57
|
}
|
|
54
|
-
} else if ((0,
|
|
55
|
-
const contractPromise = (0, _wasm.getPSP22ContractPromise)(api, (0,
|
|
58
|
+
} else if ((0, _utils3._isTokenWasmSmartContract)(tokenInfo) && api.query.contracts) {
|
|
59
|
+
const contractPromise = (0, _wasm.getPSP22ContractPromise)(api, (0, _utils3._getContractAddressOfToken)(tokenInfo));
|
|
56
60
|
// @ts-ignore
|
|
57
61
|
const gasLimit = await (0, _utils.getWasmContractGasLimit)(api, from, 'psp22::transfer', contractPromise, {}, [from, value, {}]);
|
|
58
62
|
|
|
@@ -61,8 +65,8 @@ const createTransferExtrinsic = async _ref => {
|
|
|
61
65
|
gasLimit
|
|
62
66
|
}, to, value, {});
|
|
63
67
|
transferAmount = value;
|
|
64
|
-
} else if ((0,
|
|
65
|
-
const contractPromise = tokenInfo.assetType === _types._AssetType.GRC20 ? (0,
|
|
68
|
+
} else if ((0, _utils3._isTokenGearSmartContract)(tokenInfo) && api instanceof _api.GearApi) {
|
|
69
|
+
const contractPromise = tokenInfo.assetType === _types._AssetType.GRC20 ? (0, _utils5.getGRC20ContractPromise)(api, (0, _utils3._getContractAddressOfToken)(tokenInfo)) : (0, _utils5.getVFTContractPromise)(api, (0, _utils3._getContractAddressOfToken)(tokenInfo));
|
|
66
70
|
const transaction = await contractPromise.service.transfer((0, _util.u8aToHex)((0, _utilCrypto.decodeAddress)(to)), value) // Create transfer transaction
|
|
67
71
|
.withAccount(from) // Set sender account
|
|
68
72
|
.calculateGas(); // Add account arg to extrinsic
|
|
@@ -70,9 +74,9 @@ const createTransferExtrinsic = async _ref => {
|
|
|
70
74
|
transfer = transaction.extrinsic;
|
|
71
75
|
transferAmount = value;
|
|
72
76
|
} else if (_constants._TRANSFER_CHAIN_GROUP.acala.includes(networkKey)) {
|
|
73
|
-
if (!(0,
|
|
77
|
+
if (!(0, _utils3._isNativeToken)(tokenInfo)) {
|
|
74
78
|
if (isTxCurrenciesSupported) {
|
|
75
|
-
transfer = api.tx.currencies.transfer(to, (0,
|
|
79
|
+
transfer = api.tx.currencies.transfer(to, (0, _utils3._getTokenOnChainInfo)(tokenInfo), value);
|
|
76
80
|
}
|
|
77
81
|
} else {
|
|
78
82
|
if (transferAll) {
|
|
@@ -83,23 +87,23 @@ const createTransferExtrinsic = async _ref => {
|
|
|
83
87
|
}
|
|
84
88
|
} else if (_constants._TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) && isTxTokensSupported) {
|
|
85
89
|
if (transferAll) {
|
|
86
|
-
transfer = api.tx.tokens.transferAll(to, (0,
|
|
90
|
+
transfer = api.tx.tokens.transferAll(to, (0, _utils3._getTokenOnChainInfo)(tokenInfo) || (0, _utils3._getTokenOnChainAssetId)(tokenInfo), false);
|
|
87
91
|
} else if (value) {
|
|
88
|
-
transfer = api.tx.tokens.transfer(to, (0,
|
|
92
|
+
transfer = api.tx.tokens.transfer(to, (0, _utils3._getTokenOnChainInfo)(tokenInfo) || (0, _utils3._getTokenOnChainAssetId)(tokenInfo), new _util.BN(value));
|
|
89
93
|
}
|
|
90
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.pendulum.includes(networkKey) && isTxTokensSupported && !(0,
|
|
94
|
+
} else if (_constants._TRANSFER_CHAIN_GROUP.pendulum.includes(networkKey) && isTxTokensSupported && !(0, _utils3._isNativeToken)(tokenInfo)) {
|
|
91
95
|
if (transferAll) {
|
|
92
|
-
transfer = api.tx.tokens.transferAll(to, (0,
|
|
96
|
+
transfer = api.tx.tokens.transferAll(to, (0, _utils3._getTokenOnChainInfo)(tokenInfo) || (0, _utils3._getTokenOnChainAssetId)(tokenInfo), false);
|
|
93
97
|
} else if (value) {
|
|
94
|
-
transfer = api.tx.tokens.transfer(to, (0,
|
|
98
|
+
transfer = api.tx.tokens.transfer(to, (0, _utils3._getTokenOnChainInfo)(tokenInfo) || (0, _utils3._getTokenOnChainAssetId)(tokenInfo), new _util.BN(value));
|
|
95
99
|
}
|
|
96
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.bitcountry.includes(networkKey) && !(0,
|
|
97
|
-
transfer = api.tx.currencies.transfer(to, (0,
|
|
98
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !(0,
|
|
99
|
-
transfer = api.tx.assets.transfer((0,
|
|
100
|
+
} else if (_constants._TRANSFER_CHAIN_GROUP.bitcountry.includes(networkKey) && !(0, _utils3._isNativeToken)(tokenInfo)) {
|
|
101
|
+
transfer = api.tx.currencies.transfer(to, (0, _utils3._getTokenOnChainInfo)(tokenInfo), value);
|
|
102
|
+
} else if (_constants._TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !(0, _utils3._isNativeToken)(tokenInfo)) {
|
|
103
|
+
transfer = api.tx.assets.transfer((0, _utils3._getTokenOnChainAssetId)(tokenInfo), to, value);
|
|
100
104
|
} else if (_constants._TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey) && isTxAssetsSupported) {
|
|
101
|
-
transfer = api.tx.assets.transfer((0,
|
|
102
|
-
} else if (isTxBalancesSupported && (0,
|
|
105
|
+
transfer = api.tx.assets.transfer((0, _utils3._getTokenOnChainAssetId)(tokenInfo), to, value);
|
|
106
|
+
} else if (isTxBalancesSupported && (0, _utils3._isNativeToken)(tokenInfo)) {
|
|
103
107
|
if (_constants._TRANSFER_CHAIN_GROUP.disable_transfer.includes(networkKey)) {
|
|
104
108
|
return [null, transferAmount || value];
|
|
105
109
|
}
|
|
@@ -119,7 +123,7 @@ exports.createTransferExtrinsic = createTransferExtrinsic;
|
|
|
119
123
|
const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) => {
|
|
120
124
|
try {
|
|
121
125
|
let estimatedFee;
|
|
122
|
-
if ((0,
|
|
126
|
+
if ((0, _utils3._isChainEvmCompatible)(chainInfo) && (0, _utils3._isTokenTransferredByEvm)(tokenInfo)) {
|
|
123
127
|
const web3 = api;
|
|
124
128
|
const transaction = {
|
|
125
129
|
value: 0,
|
|
@@ -128,13 +132,26 @@ const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) => {
|
|
|
128
132
|
from: address
|
|
129
133
|
};
|
|
130
134
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
131
|
-
const priority = await (0,
|
|
135
|
+
const priority = await (0, _utils4.calculateGasFeeParams)(web3, chainInfo.slug);
|
|
132
136
|
if (priority.baseGasFee) {
|
|
133
137
|
const maxFee = priority.maxFeePerGas;
|
|
134
138
|
estimatedFee = maxFee.multipliedBy(gasLimit);
|
|
135
139
|
} else {
|
|
136
140
|
estimatedFee = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit);
|
|
137
141
|
}
|
|
142
|
+
} else if ((0, _utils3._isChainTonCompatible)(chainInfo) && (0, _utils3._isTokenTransferredByTon)(tokenInfo)) {
|
|
143
|
+
const mockWalletContract = _uiKeyring.keyring.getPair(address).ton.currentContract;
|
|
144
|
+
const tonApi = api;
|
|
145
|
+
const maxBlance = await tonApi.getBalance(_ton.Address.parse(address));
|
|
146
|
+
const mockMessage = (0, _core.internal)({
|
|
147
|
+
to: address,
|
|
148
|
+
// anyAddress
|
|
149
|
+
value: maxBlance,
|
|
150
|
+
// estimate value
|
|
151
|
+
bounce: false // anyMode
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
estimatedFee = new _bignumber.default((await (0, _utils2.estimateTonTxFee)(tonApi, [mockMessage], mockWalletContract)).toString());
|
|
138
155
|
} else {
|
|
139
156
|
var _paymentInfo$partialF;
|
|
140
157
|
const substrateApi = api;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createTonTransaction = createTonTransaction;
|
|
7
|
+
var _consts = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/consts");
|
|
8
|
+
var _utils = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils");
|
|
9
|
+
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
10
|
+
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
11
|
+
var _core = require("@ton/core");
|
|
12
|
+
var _ton = require("@ton/ton");
|
|
13
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
14
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
15
|
+
|
|
16
|
+
async function createTonTransaction(_ref) {
|
|
17
|
+
let {
|
|
18
|
+
from,
|
|
19
|
+
networkKey,
|
|
20
|
+
to,
|
|
21
|
+
tokenInfo,
|
|
22
|
+
tonApi,
|
|
23
|
+
transferAll,
|
|
24
|
+
value
|
|
25
|
+
} = _ref;
|
|
26
|
+
if ((0, _utils2._isNativeToken)(tokenInfo)) {
|
|
27
|
+
return createTonNativeTransaction({
|
|
28
|
+
from,
|
|
29
|
+
to,
|
|
30
|
+
networkKey,
|
|
31
|
+
tokenInfo,
|
|
32
|
+
value: value || '0',
|
|
33
|
+
transferAll: transferAll,
|
|
34
|
+
tonApi
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if ((0, _utils2._isJettonToken)(tokenInfo)) {
|
|
38
|
+
return createJettonTransaction({
|
|
39
|
+
from,
|
|
40
|
+
to,
|
|
41
|
+
networkKey,
|
|
42
|
+
tokenInfo,
|
|
43
|
+
value: value || '0',
|
|
44
|
+
transferAll: transferAll,
|
|
45
|
+
tonApi
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return [null, value];
|
|
49
|
+
}
|
|
50
|
+
async function createTonNativeTransaction(_ref2) {
|
|
51
|
+
let {
|
|
52
|
+
from,
|
|
53
|
+
networkKey,
|
|
54
|
+
to,
|
|
55
|
+
tonApi,
|
|
56
|
+
transferAll,
|
|
57
|
+
value
|
|
58
|
+
} = _ref2;
|
|
59
|
+
const walletContract = _uiKeyring.keyring.getPair(from).ton.currentContract;
|
|
60
|
+
const contract = tonApi.open(walletContract);
|
|
61
|
+
const seqno = await contract.getSeqno();
|
|
62
|
+
const messages = (0, _core.internal)({
|
|
63
|
+
to: to,
|
|
64
|
+
value: (0, _core.fromNano)(value),
|
|
65
|
+
bounce: false // todo: check and update the send bounced logic
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const messagePayload = (0, _utils.cellToBase64Str)((0, _utils.messageRelaxedToCell)(messages));
|
|
69
|
+
const estimateExternalFee = await (0, _utils.estimateTonTxFee)(tonApi, [messages], walletContract);
|
|
70
|
+
const transactionObject = {
|
|
71
|
+
from,
|
|
72
|
+
to,
|
|
73
|
+
networkKey,
|
|
74
|
+
value: value,
|
|
75
|
+
messagePayload,
|
|
76
|
+
messages: [messages],
|
|
77
|
+
estimateFee: estimateExternalFee.toString(),
|
|
78
|
+
seqno,
|
|
79
|
+
transferAll
|
|
80
|
+
};
|
|
81
|
+
return [transactionObject, transactionObject.value];
|
|
82
|
+
}
|
|
83
|
+
async function createJettonTransaction(_ref3) {
|
|
84
|
+
let {
|
|
85
|
+
from,
|
|
86
|
+
networkKey,
|
|
87
|
+
to,
|
|
88
|
+
tokenInfo,
|
|
89
|
+
tonApi,
|
|
90
|
+
transferAll,
|
|
91
|
+
value
|
|
92
|
+
} = _ref3;
|
|
93
|
+
const walletContract = _uiKeyring.keyring.getPair(from).ton.currentContract;
|
|
94
|
+
const sendertonAddress = _ton.Address.parse(from);
|
|
95
|
+
const destinationAddress = _ton.Address.parse(to);
|
|
96
|
+
const contract = tonApi.open(walletContract);
|
|
97
|
+
const seqno = await contract.getSeqno();
|
|
98
|
+
|
|
99
|
+
// retrieve jetton info
|
|
100
|
+
const jettonContractAddress = _ton.Address.parse((0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
101
|
+
const jettonMasterContract = tonApi.open(_ton.JettonMaster.create(jettonContractAddress));
|
|
102
|
+
const jettonWalletAddress = await jettonMasterContract.getWalletAddress(sendertonAddress);
|
|
103
|
+
const messageBody = (0, _core.beginCell)().storeUint(_consts.TON_OPCODES.JETTON_TRANSFER, 32) // opcode for jetton transfer
|
|
104
|
+
.storeUint((0, _utils.getWalletQueryId)(), 64) // query id
|
|
105
|
+
.storeCoins(BigInt(value)) // jetton bigint amount
|
|
106
|
+
.storeAddress(destinationAddress).storeAddress(sendertonAddress) // response destination, who get remain token
|
|
107
|
+
.storeBit(0) // no custom payload
|
|
108
|
+
.storeCoins(BigInt(1)) // forward amount - if >0, will send notification message
|
|
109
|
+
.storeBit(0) // no forward payload
|
|
110
|
+
// .storeRef(forwardPayload)
|
|
111
|
+
.endCell();
|
|
112
|
+
const messages = (0, _core.internal)({
|
|
113
|
+
to: jettonWalletAddress,
|
|
114
|
+
// JettonWallet of sender
|
|
115
|
+
value: (0, _core.toNano)(_consts.INIT_FEE_JETTON_TRANSFER),
|
|
116
|
+
// set this for fee, excess later
|
|
117
|
+
bounce: true,
|
|
118
|
+
// todo: check and update the send bounced logic
|
|
119
|
+
body: messageBody
|
|
120
|
+
});
|
|
121
|
+
const messagePayload = (0, _utils.cellToBase64Str)((0, _utils.messageRelaxedToCell)(messages));
|
|
122
|
+
const estimateExternalFee = await (0, _utils.estimateTonTxFee)(tonApi, [messages], walletContract);
|
|
123
|
+
const estimateFee = (0, _core.toNano)(_consts.INIT_FEE_JETTON_TRANSFER) > estimateExternalFee ? (0, _core.toNano)(_consts.INIT_FEE_JETTON_TRANSFER) : estimateExternalFee;
|
|
124
|
+
const transactionObject = {
|
|
125
|
+
from,
|
|
126
|
+
to,
|
|
127
|
+
networkKey,
|
|
128
|
+
value,
|
|
129
|
+
messagePayload,
|
|
130
|
+
messages: [messages],
|
|
131
|
+
estimateFee: estimateFee.toString(),
|
|
132
|
+
seqno,
|
|
133
|
+
transferAll
|
|
134
|
+
};
|
|
135
|
+
return [transactionObject, transactionObject.value];
|
|
136
|
+
}
|
|
@@ -4,12 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _types = require("@subwallet/extension-base/types");
|
|
7
8
|
var _fetchStaticData = require("@subwallet/extension-base/utils/fetchStaticData");
|
|
8
9
|
var _rxjs = require("rxjs");
|
|
9
10
|
var _constants = require("./constants");
|
|
10
11
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
11
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
13
|
|
|
14
|
+
const convertSupportType = support => {
|
|
15
|
+
return support === 'ETHEREUM' ? _types.AccountChainType.ETHEREUM : _types.AccountChainType.SUBSTRATE;
|
|
16
|
+
};
|
|
13
17
|
class BuyService {
|
|
14
18
|
#state;
|
|
15
19
|
buyTokensSubject = new _rxjs.BehaviorSubject({});
|
|
@@ -35,7 +39,7 @@ class BuyService {
|
|
|
35
39
|
serviceInfo: {
|
|
36
40
|
..._constants.DEFAULT_SERVICE_INFO
|
|
37
41
|
},
|
|
38
|
-
support: datum.support,
|
|
42
|
+
support: convertSupportType(datum.support),
|
|
39
43
|
services: [],
|
|
40
44
|
slug: datum.slug,
|
|
41
45
|
symbol: datum.symbol,
|
|
@@ -297,7 +297,7 @@ const _XCM_TYPE = {
|
|
|
297
297
|
PR: `${_types._SubstrateChainType.PARACHAIN}-${_types._SubstrateChainType.RELAYCHAIN}` // UMP
|
|
298
298
|
};
|
|
299
299
|
exports._XCM_TYPE = _XCM_TYPE;
|
|
300
|
-
const _DEFAULT_ACTIVE_CHAINS = [..._chainList._DEFAULT_CHAINS, 'vara_network'];
|
|
300
|
+
const _DEFAULT_ACTIVE_CHAINS = [..._chainList._DEFAULT_CHAINS, 'vara_network', 'ton'];
|
|
301
301
|
exports._DEFAULT_ACTIVE_CHAINS = _DEFAULT_ACTIVE_CHAINS;
|
|
302
302
|
const EVM_PASS_CONNECT_STATUS = {
|
|
303
303
|
arbitrum_one: ['*'],
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TonApi = void 0;
|
|
7
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
8
|
+
var _consts = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/consts");
|
|
9
|
+
var _utils = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils");
|
|
10
|
+
var _types = require("@subwallet/extension-base/services/chain-service/types");
|
|
11
|
+
var _utils2 = require("@subwallet/extension-base/utils");
|
|
12
|
+
var _ton = require("@ton/ton");
|
|
13
|
+
var _rxjs = require("rxjs");
|
|
14
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
class TonApi {
|
|
18
|
+
apiRetry = 0;
|
|
19
|
+
isApiConnectedSubject = new _rxjs.BehaviorSubject(false);
|
|
20
|
+
connectionStatusSubject = new _rxjs.BehaviorSubject(_types._ChainConnectionStatus.DISCONNECTED);
|
|
21
|
+
isApiReady = false;
|
|
22
|
+
isApiReadyOnce = false;
|
|
23
|
+
constructor(chainSlug, apiUrl, _ref) {
|
|
24
|
+
let {
|
|
25
|
+
providerName
|
|
26
|
+
} = _ref;
|
|
27
|
+
this.chainSlug = chainSlug;
|
|
28
|
+
this.apiUrl = apiUrl;
|
|
29
|
+
this.providerName = providerName || 'unknown';
|
|
30
|
+
this.api = this.createProvider(apiUrl);
|
|
31
|
+
this.isReadyHandler = (0, _utils2.createPromiseHandler)();
|
|
32
|
+
this.connect();
|
|
33
|
+
}
|
|
34
|
+
get isApiConnected() {
|
|
35
|
+
return this.isApiConnectedSubject.getValue();
|
|
36
|
+
}
|
|
37
|
+
get connectionStatus() {
|
|
38
|
+
return this.connectionStatusSubject.getValue();
|
|
39
|
+
}
|
|
40
|
+
updateConnectionStatus(status) {
|
|
41
|
+
const isConnected = status === _types._ChainConnectionStatus.CONNECTED;
|
|
42
|
+
if (isConnected !== this.isApiConnectedSubject.value) {
|
|
43
|
+
this.isApiConnectedSubject.next(isConnected);
|
|
44
|
+
}
|
|
45
|
+
if (status !== this.connectionStatusSubject.value) {
|
|
46
|
+
this.connectionStatusSubject.next(status);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
get isReady() {
|
|
50
|
+
return this.isReadyHandler.promise;
|
|
51
|
+
}
|
|
52
|
+
async updateApiUrl(apiUrl) {
|
|
53
|
+
if (this.apiUrl === apiUrl) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
await this.disconnect();
|
|
57
|
+
|
|
58
|
+
// Create new provider and api
|
|
59
|
+
this.apiUrl = apiUrl;
|
|
60
|
+
this.api = new _ton.TonClient({
|
|
61
|
+
endpoint: this.getJsonRpc(this.apiUrl),
|
|
62
|
+
apiKey: _consts.TON_CENTER_API_KEY
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async recoverConnect() {
|
|
66
|
+
await this.disconnect();
|
|
67
|
+
this.connect();
|
|
68
|
+
await this.isReadyHandler.promise;
|
|
69
|
+
}
|
|
70
|
+
createProvider(apiUrl) {
|
|
71
|
+
return new _ton.TonClient({
|
|
72
|
+
endpoint: this.getJsonRpc(apiUrl),
|
|
73
|
+
apiKey: _consts.TON_CENTER_API_KEY
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getJsonRpc(url) {
|
|
77
|
+
return `${url}/jsonRPC`;
|
|
78
|
+
}
|
|
79
|
+
connect() {
|
|
80
|
+
this.updateConnectionStatus(_types._ChainConnectionStatus.CONNECTING);
|
|
81
|
+
// There isn't a persistent network connection underlying TonClient. Cant check connection status.
|
|
82
|
+
// this.isApiReadyOnce = true;
|
|
83
|
+
this.onConnect();
|
|
84
|
+
}
|
|
85
|
+
async disconnect() {
|
|
86
|
+
this.onDisconnect();
|
|
87
|
+
this.updateConnectionStatus(_types._ChainConnectionStatus.DISCONNECTED);
|
|
88
|
+
return Promise.resolve();
|
|
89
|
+
}
|
|
90
|
+
destroy() {
|
|
91
|
+
// Todo: implement this in the future
|
|
92
|
+
return this.disconnect();
|
|
93
|
+
}
|
|
94
|
+
onConnect() {
|
|
95
|
+
if (!this.isApiConnected) {
|
|
96
|
+
console.log(`Connected to ${this.chainSlug} at ${this.apiUrl}`);
|
|
97
|
+
this.isApiReady = true;
|
|
98
|
+
if (this.isApiReadyOnce) {
|
|
99
|
+
this.isReadyHandler.resolve(this);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
this.updateConnectionStatus(_types._ChainConnectionStatus.CONNECTED);
|
|
103
|
+
}
|
|
104
|
+
onDisconnect() {
|
|
105
|
+
this.updateConnectionStatus(_types._ChainConnectionStatus.DISCONNECTED);
|
|
106
|
+
if (this.isApiConnected) {
|
|
107
|
+
console.warn(`Disconnected from ${this.chainSlug} of ${this.apiUrl}`);
|
|
108
|
+
this.isApiReady = false;
|
|
109
|
+
this.isReadyHandler = (0, _utils2.createPromiseHandler)();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Util functions
|
|
114
|
+
|
|
115
|
+
async getBalance(address) {
|
|
116
|
+
return await this.api.getBalance(address);
|
|
117
|
+
}
|
|
118
|
+
open(src) {
|
|
119
|
+
return this.api.open(src);
|
|
120
|
+
}
|
|
121
|
+
estimateExternalMessageFee(walletContract, body, isInit) {
|
|
122
|
+
let ignoreSignature = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
123
|
+
const initCode = isInit ? null : walletContract.init.code;
|
|
124
|
+
const initData = isInit ? null : walletContract.init.data;
|
|
125
|
+
return this.api.estimateExternalMessageFee(walletContract.address, {
|
|
126
|
+
body: body,
|
|
127
|
+
ignoreSignature: ignoreSignature,
|
|
128
|
+
initCode: initCode,
|
|
129
|
+
initData: initData
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async sendTonTransaction(boc) {
|
|
133
|
+
try {
|
|
134
|
+
const url = `${this.apiUrl}/api/v2/sendBocReturnHash`;
|
|
135
|
+
const resp = await fetch(url, {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
headers: {
|
|
138
|
+
accept: 'application/json',
|
|
139
|
+
'Content-Type': 'application/json',
|
|
140
|
+
'X-API-KEY': _consts.TON_CENTER_API_KEY
|
|
141
|
+
},
|
|
142
|
+
body: JSON.stringify({
|
|
143
|
+
boc: boc
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
const extMsgInfo = await resp.json();
|
|
147
|
+
return extMsgInfo.result.hash;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error('Failed to send transaction with boc', boc);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async getTxByInMsg(extMsgHash) {
|
|
154
|
+
const url = `${this.apiUrl}/api/v3/transactionsByMessage?msg_hash=${encodeURIComponent(extMsgHash)}&direction=in`;
|
|
155
|
+
const resp = await fetch(url, {
|
|
156
|
+
method: 'GET',
|
|
157
|
+
headers: {
|
|
158
|
+
accept: 'application/json',
|
|
159
|
+
'Content-Type': 'application/json',
|
|
160
|
+
'X-API-KEY': _consts.TON_CENTER_API_KEY
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return await resp.json();
|
|
164
|
+
}
|
|
165
|
+
async getStatusByExtMsgHash(extMsgHash, extrinsicType) {
|
|
166
|
+
return (0, _utils.retry)(async () => {
|
|
167
|
+
var _externalTxInfo$out_m, _externalTxInfo$out_m2;
|
|
168
|
+
// retry many times to get transaction status and transaction hex
|
|
169
|
+
const externalTxInfoRaw = await this.getTxByInMsg(extMsgHash);
|
|
170
|
+
const externalTxInfo = externalTxInfoRaw.transactions[0];
|
|
171
|
+
const isExternalTxCompute = externalTxInfo.description.compute_ph.success;
|
|
172
|
+
const isExternalTxAction = externalTxInfo.description.action.success;
|
|
173
|
+
const base64Hex = externalTxInfo.hash;
|
|
174
|
+
const hex = '0x'.concat(Buffer.from(base64Hex, 'base64').toString('hex'));
|
|
175
|
+
if (!(isExternalTxCompute && isExternalTxAction)) {
|
|
176
|
+
return [false, hex];
|
|
177
|
+
}
|
|
178
|
+
if (extrinsicType === _KoniTypes.ExtrinsicType.TRANSFER_BALANCE) {
|
|
179
|
+
return [true, hex];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// get out msg info from tx
|
|
183
|
+
const internalMsgHash = (_externalTxInfo$out_m = externalTxInfo.out_msgs[0]) === null || _externalTxInfo$out_m === void 0 ? void 0 : _externalTxInfo$out_m.hash;
|
|
184
|
+
const opcode = parseInt(((_externalTxInfo$out_m2 = externalTxInfo.out_msgs[0]) === null || _externalTxInfo$out_m2 === void 0 ? void 0 : _externalTxInfo$out_m2.opcode) || '0');
|
|
185
|
+
if (internalMsgHash) {
|
|
186
|
+
// notice to update opcode check when supporting more transaction type in ton blockchain
|
|
187
|
+
const status = opcode === _consts.TON_OPCODES.JETTON_TRANSFER ? await (0, _utils.getJettonTxStatus)(this, internalMsgHash) : false;
|
|
188
|
+
return [status, hex];
|
|
189
|
+
}
|
|
190
|
+
throw new Error('Transaction not found');
|
|
191
|
+
}, {
|
|
192
|
+
retries: 10,
|
|
193
|
+
delay: 5000
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async getAccountState(address) {
|
|
197
|
+
const url = `${this.apiUrl}/api/v2/getAddressState?address=${address}`;
|
|
198
|
+
const resp = await fetch(url, {
|
|
199
|
+
method: 'GET',
|
|
200
|
+
headers: {
|
|
201
|
+
accept: 'application/json',
|
|
202
|
+
'Content-Type': 'application/json',
|
|
203
|
+
'X-API-KEY': _consts.TON_CENTER_API_KEY
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
const accountStateInfo = await resp.json();
|
|
207
|
+
if (accountStateInfo.ok) {
|
|
208
|
+
return accountStateInfo.result;
|
|
209
|
+
}
|
|
210
|
+
return 'unknown';
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.TonApi = TonApi;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TonChainHandler = void 0;
|
|
7
|
+
var _AbstractChainHandler = require("@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler");
|
|
8
|
+
var _TonApi = require("@subwallet/extension-base/services/chain-service/handler/TonApi");
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class TonChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
13
|
+
tonApiMap = {};
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line no-useless-constructor
|
|
16
|
+
constructor(parent) {
|
|
17
|
+
super(parent);
|
|
18
|
+
}
|
|
19
|
+
getTonApiMap() {
|
|
20
|
+
return this.tonApiMap;
|
|
21
|
+
}
|
|
22
|
+
getTonApiByChain(chain) {
|
|
23
|
+
return this.tonApiMap[chain];
|
|
24
|
+
}
|
|
25
|
+
getApiByChain(chain) {
|
|
26
|
+
return this.getTonApiByChain(chain);
|
|
27
|
+
}
|
|
28
|
+
setTonApi(chain, tonApi) {
|
|
29
|
+
this.tonApiMap[chain] = tonApi;
|
|
30
|
+
}
|
|
31
|
+
async initApi(chainSlug, apiUrl) {
|
|
32
|
+
let {
|
|
33
|
+
onUpdateStatus,
|
|
34
|
+
providerName
|
|
35
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
36
|
+
const existed = this.getTonApiByChain(chainSlug);
|
|
37
|
+
if (existed) {
|
|
38
|
+
existed.connect();
|
|
39
|
+
if (apiUrl !== existed.apiUrl) {
|
|
40
|
+
existed.updateApiUrl(apiUrl).catch(console.error);
|
|
41
|
+
}
|
|
42
|
+
return existed;
|
|
43
|
+
}
|
|
44
|
+
const apiObject = new _TonApi.TonApi(chainSlug, apiUrl, {
|
|
45
|
+
providerName
|
|
46
|
+
});
|
|
47
|
+
apiObject.connectionStatusSubject.subscribe(this.handleConnection.bind(this, chainSlug));
|
|
48
|
+
apiObject.connectionStatusSubject.subscribe(onUpdateStatus);
|
|
49
|
+
return Promise.resolve(apiObject);
|
|
50
|
+
}
|
|
51
|
+
async recoverApi(chain) {
|
|
52
|
+
const existed = this.getTonApiByChain(chain);
|
|
53
|
+
if (existed && !existed.isApiReadyOnce) {
|
|
54
|
+
console.log(`Reconnect ${existed.providerName || existed.chainSlug} at ${existed.apiUrl}`);
|
|
55
|
+
return existed.recoverConnect();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
destroyTonApi(chain) {
|
|
59
|
+
const tonApi = this.getTonApiByChain(chain);
|
|
60
|
+
tonApi === null || tonApi === void 0 ? void 0 : tonApi.destroy().catch(console.error);
|
|
61
|
+
}
|
|
62
|
+
async sleep() {
|
|
63
|
+
this.isSleeping = true;
|
|
64
|
+
this.cancelAllRecover();
|
|
65
|
+
await Promise.all(Object.values(this.getTonApiMap()).map(tonApi => {
|
|
66
|
+
return tonApi.disconnect().catch(console.error);
|
|
67
|
+
}));
|
|
68
|
+
return Promise.resolve();
|
|
69
|
+
}
|
|
70
|
+
wakeUp() {
|
|
71
|
+
var _this$parent;
|
|
72
|
+
this.isSleeping = false;
|
|
73
|
+
const activeChains = ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.getActiveChains()) || [];
|
|
74
|
+
for (const chain of activeChains) {
|
|
75
|
+
const tonApi = this.getTonApiByChain(chain);
|
|
76
|
+
tonApi === null || tonApi === void 0 ? void 0 : tonApi.connect();
|
|
77
|
+
}
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.TonChainHandler = TonChainHandler;
|