@tcswap/wallet-extensions 4.1.16
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/dist/chunk-7y3ffnf3.js +4 -0
- package/dist/chunk-7y3ffnf3.js.map +10 -0
- package/dist/chunk-fazw0jvt.js +4 -0
- package/dist/chunk-fazw0jvt.js.map +9 -0
- package/dist/chunk-kx2thqhk.js +5 -0
- package/dist/chunk-kx2thqhk.js.map +9 -0
- package/dist/chunk-swh9jwp7.js +4 -0
- package/dist/chunk-swh9jwp7.js.map +10 -0
- package/dist/src/bitget/index.cjs +4 -0
- package/dist/src/bitget/index.cjs.map +11 -0
- package/dist/src/bitget/index.js +4 -0
- package/dist/src/bitget/index.js.map +11 -0
- package/dist/src/cosmostation/index.cjs +4 -0
- package/dist/src/cosmostation/index.cjs.map +10 -0
- package/dist/src/cosmostation/index.js +4 -0
- package/dist/src/cosmostation/index.js.map +10 -0
- package/dist/src/ctrl/index.cjs +4 -0
- package/dist/src/ctrl/index.cjs.map +11 -0
- package/dist/src/ctrl/index.js +4 -0
- package/dist/src/ctrl/index.js.map +11 -0
- package/dist/src/evm-extensions/index.cjs +4 -0
- package/dist/src/evm-extensions/index.cjs.map +10 -0
- package/dist/src/evm-extensions/index.js +4 -0
- package/dist/src/evm-extensions/index.js.map +10 -0
- package/dist/src/index.cjs +4 -0
- package/dist/src/index.cjs.map +9 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +9 -0
- package/dist/src/keepkey-bex/index.cjs +4 -0
- package/dist/src/keepkey-bex/index.cjs.map +11 -0
- package/dist/src/keepkey-bex/index.js +4 -0
- package/dist/src/keepkey-bex/index.js.map +11 -0
- package/dist/src/keplr/index.cjs +4 -0
- package/dist/src/keplr/index.cjs.map +11 -0
- package/dist/src/keplr/index.js +4 -0
- package/dist/src/keplr/index.js.map +11 -0
- package/dist/src/okx/index.cjs +4 -0
- package/dist/src/okx/index.cjs.map +11 -0
- package/dist/src/okx/index.js +4 -0
- package/dist/src/okx/index.js.map +11 -0
- package/dist/src/onekey/index.cjs +4 -0
- package/dist/src/onekey/index.cjs.map +10 -0
- package/dist/src/onekey/index.js +4 -0
- package/dist/src/onekey/index.js.map +10 -0
- package/dist/src/phantom/index.cjs +4 -0
- package/dist/src/phantom/index.cjs.map +10 -0
- package/dist/src/phantom/index.js +4 -0
- package/dist/src/phantom/index.js.map +10 -0
- package/dist/src/polkadotjs/index.cjs +4 -0
- package/dist/src/polkadotjs/index.cjs.map +10 -0
- package/dist/src/polkadotjs/index.js +4 -0
- package/dist/src/polkadotjs/index.js.map +10 -0
- package/dist/src/talisman/index.cjs +4 -0
- package/dist/src/talisman/index.cjs.map +10 -0
- package/dist/src/talisman/index.js +4 -0
- package/dist/src/talisman/index.js.map +10 -0
- package/dist/src/tronlink/index.cjs +4 -0
- package/dist/src/tronlink/index.cjs.map +12 -0
- package/dist/src/tronlink/index.js +4 -0
- package/dist/src/tronlink/index.js.map +12 -0
- package/dist/src/vultisig/index.cjs +4 -0
- package/dist/src/vultisig/index.cjs.map +11 -0
- package/dist/src/vultisig/index.js +4 -0
- package/dist/src/vultisig/index.js.map +11 -0
- package/dist/types/bitget/helpers.d.ts +1607 -0
- package/dist/types/bitget/helpers.d.ts.map +1 -0
- package/dist/types/bitget/index.d.ts +11 -0
- package/dist/types/bitget/index.d.ts.map +1 -0
- package/dist/types/cosmostation/index.d.ts +24 -0
- package/dist/types/cosmostation/index.d.ts.map +1 -0
- package/dist/types/ctrl/index.d.ts +14 -0
- package/dist/types/ctrl/index.d.ts.map +1 -0
- package/dist/types/ctrl/walletHelpers.d.ts +23 -0
- package/dist/types/ctrl/walletHelpers.d.ts.map +1 -0
- package/dist/types/evm-extensions/index.d.ts +747 -0
- package/dist/types/evm-extensions/index.d.ts.map +1 -0
- package/dist/types/evm-extensions/types.d.ts +18 -0
- package/dist/types/evm-extensions/types.d.ts.map +1 -0
- package/dist/types/helpers/near.d.ts +60 -0
- package/dist/types/helpers/near.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/keepkey-bex/index.d.ts +14 -0
- package/dist/types/keepkey-bex/index.d.ts.map +1 -0
- package/dist/types/keepkey-bex/walletHelpers.d.ts +48 -0
- package/dist/types/keepkey-bex/walletHelpers.d.ts.map +1 -0
- package/dist/types/keplr/chainRegistry.d.ts +4 -0
- package/dist/types/keplr/chainRegistry.d.ts.map +1 -0
- package/dist/types/keplr/index.d.ts +14 -0
- package/dist/types/keplr/index.d.ts.map +1 -0
- package/dist/types/okx/helpers.d.ts +855 -0
- package/dist/types/okx/helpers.d.ts.map +1 -0
- package/dist/types/okx/index.d.ts +11 -0
- package/dist/types/okx/index.d.ts.map +1 -0
- package/dist/types/okx/types.d.ts +104 -0
- package/dist/types/okx/types.d.ts.map +1 -0
- package/dist/types/onekey/evmSigner.d.ts +32 -0
- package/dist/types/onekey/evmSigner.d.ts.map +1 -0
- package/dist/types/onekey/index.d.ts +14 -0
- package/dist/types/onekey/index.d.ts.map +1 -0
- package/dist/types/phantom/index.d.ts +15 -0
- package/dist/types/phantom/index.d.ts.map +1 -0
- package/dist/types/polkadotjs/index.d.ts +14 -0
- package/dist/types/polkadotjs/index.d.ts.map +1 -0
- package/dist/types/talisman/index.d.ts +14 -0
- package/dist/types/talisman/index.d.ts.map +1 -0
- package/dist/types/tronlink/helpers.d.ts +29 -0
- package/dist/types/tronlink/helpers.d.ts.map +1 -0
- package/dist/types/tronlink/index.d.ts +13 -0
- package/dist/types/tronlink/index.d.ts.map +1 -0
- package/dist/types/tronlink/types.d.ts +55 -0
- package/dist/types/tronlink/types.d.ts.map +1 -0
- package/dist/types/types.d.ts +166 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/vultisig/index.d.ts +14 -0
- package/dist/types/vultisig/index.d.ts.map +1 -0
- package/dist/types/vultisig/walletHelpers.d.ts +37 -0
- package/dist/types/vultisig/walletHelpers.d.ts.map +1 -0
- package/package.json +133 -0
- package/src/bitget/helpers.ts +181 -0
- package/src/bitget/index.ts +26 -0
- package/src/cosmostation/index.ts +122 -0
- package/src/ctrl/index.ts +194 -0
- package/src/ctrl/walletHelpers.ts +186 -0
- package/src/evm-extensions/index.ts +122 -0
- package/src/evm-extensions/types.ts +15 -0
- package/src/helpers/near-browser-provider.d.ts +270 -0
- package/src/helpers/near.ts +174 -0
- package/src/index.ts +1 -0
- package/src/keepkey-bex/index.ts +151 -0
- package/src/keepkey-bex/walletHelpers.ts +241 -0
- package/src/keplr/chainRegistry.ts +240 -0
- package/src/keplr/index.ts +54 -0
- package/src/okx/helpers.ts +192 -0
- package/src/okx/index.ts +43 -0
- package/src/okx/types.ts +117 -0
- package/src/onekey/evmSigner.ts +116 -0
- package/src/onekey/index.ts +182 -0
- package/src/phantom/index.ts +136 -0
- package/src/polkadotjs/index.ts +61 -0
- package/src/talisman/index.ts +132 -0
- package/src/tronlink/helpers.ts +153 -0
- package/src/tronlink/index.ts +49 -0
- package/src/tronlink/types.ts +44 -0
- package/src/types.ts +157 -0
- package/src/vultisig/index.ts +179 -0
- package/src/vultisig/walletHelpers.ts +295 -0
package/package.json
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "swapkit-oss",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@keplr-wallet/types": "0.12.285",
|
|
5
|
+
"@near-js/accounts": "~2.5.0",
|
|
6
|
+
"@near-js/crypto": "~2.5.0",
|
|
7
|
+
"@near-js/transactions": "~2.5.0",
|
|
8
|
+
"@solana/web3.js": "~1.98.0",
|
|
9
|
+
"@tcswap/helpers": "4.5.15",
|
|
10
|
+
"@tcswap/toolboxes": "4.3.15",
|
|
11
|
+
"@tcswap/wallet-core": "4.0.59",
|
|
12
|
+
"ethers": "^6.14.0",
|
|
13
|
+
"sats-connect": "~1.0.0",
|
|
14
|
+
"ts-pattern": "~5.9.0"
|
|
15
|
+
},
|
|
16
|
+
"description": "USwap - Wallet Extension",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@keplr-wallet/types": "0.12.285",
|
|
19
|
+
"@near-js/accounts": "2.5.0",
|
|
20
|
+
"@near-js/crypto": "2.5.0",
|
|
21
|
+
"@near-js/transactions": "2.5.0",
|
|
22
|
+
"@solana/web3.js": "1.98.4",
|
|
23
|
+
"ethers": "6.15.0",
|
|
24
|
+
"sats-connect": "1.0.0",
|
|
25
|
+
"ts-pattern": "5.9.0"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"bun": "./src/index.ts",
|
|
30
|
+
"default": "./dist/src/index.js",
|
|
31
|
+
"require": "./dist/src/index.cjs",
|
|
32
|
+
"types": "./dist/types/types.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./bitget": {
|
|
35
|
+
"bun": "./src/bitget/index.ts",
|
|
36
|
+
"default": "./dist/src/bitget/index.js",
|
|
37
|
+
"require": "./dist/src/bitget/index.cjs",
|
|
38
|
+
"types": "./dist/types/bitget/index.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./cosmostation": {
|
|
41
|
+
"bun": "./src/cosmostation/index.ts",
|
|
42
|
+
"default": "./dist/src/cosmostation/index.js",
|
|
43
|
+
"require": "./dist/src/cosmostation/index.cjs",
|
|
44
|
+
"types": "./dist/types/cosmostation/index.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"./ctrl": {
|
|
47
|
+
"bun": "./src/ctrl/index.ts",
|
|
48
|
+
"default": "./dist/src/ctrl/index.js",
|
|
49
|
+
"require": "./dist/src/ctrl/index.cjs",
|
|
50
|
+
"types": "./dist/types/ctrl/index.d.ts"
|
|
51
|
+
},
|
|
52
|
+
"./evm-extensions": {
|
|
53
|
+
"bun": "./src/evm-extensions/index.ts",
|
|
54
|
+
"default": "./dist/src/evm-extensions/index.js",
|
|
55
|
+
"require": "./dist/src/evm-extensions/index.cjs",
|
|
56
|
+
"types": "./dist/types/evm-extensions/index.d.ts"
|
|
57
|
+
},
|
|
58
|
+
"./keepkey-bex": {
|
|
59
|
+
"bun": "./src/keepkey-bex/index.ts",
|
|
60
|
+
"default": "./dist/src/keepkey-bex/index.js",
|
|
61
|
+
"require": "./dist/src/keepkey-bex/index.cjs",
|
|
62
|
+
"types": "./dist/types/keepkey-bex/index.d.ts"
|
|
63
|
+
},
|
|
64
|
+
"./keplr": {
|
|
65
|
+
"bun": "./src/keplr/index.ts",
|
|
66
|
+
"default": "./dist/src/keplr/index.js",
|
|
67
|
+
"require": "./dist/src/keplr/index.cjs",
|
|
68
|
+
"types": "./dist/types/keplr/index.d.ts"
|
|
69
|
+
},
|
|
70
|
+
"./okx": {
|
|
71
|
+
"bun": "./src/okx/index.ts",
|
|
72
|
+
"default": "./dist/src/okx/index.js",
|
|
73
|
+
"require": "./dist/src/okx/index.cjs",
|
|
74
|
+
"types": "./dist/types/okx/index.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./onekey": {
|
|
77
|
+
"bun": "./src/onekey/index.ts",
|
|
78
|
+
"default": "./dist/src/onekey/index.js",
|
|
79
|
+
"require": "./dist/src/onekey/index.cjs",
|
|
80
|
+
"types": "./dist/types/onekey/index.d.ts"
|
|
81
|
+
},
|
|
82
|
+
"./phantom": {
|
|
83
|
+
"bun": "./src/phantom/index.ts",
|
|
84
|
+
"default": "./dist/src/phantom/index.js",
|
|
85
|
+
"require": "./dist/src/phantom/index.cjs",
|
|
86
|
+
"types": "./dist/types/phantom/index.d.ts"
|
|
87
|
+
},
|
|
88
|
+
"./polkadotjs": {
|
|
89
|
+
"bun": "./src/polkadotjs/index.ts",
|
|
90
|
+
"default": "./dist/src/polkadotjs/index.js",
|
|
91
|
+
"require": "./dist/src/polkadotjs/index.cjs",
|
|
92
|
+
"types": "./dist/types/polkadotjs/index.d.ts"
|
|
93
|
+
},
|
|
94
|
+
"./talisman": {
|
|
95
|
+
"bun": "./src/talisman/index.ts",
|
|
96
|
+
"default": "./dist/src/talisman/index.js",
|
|
97
|
+
"require": "./dist/src/talisman/index.cjs",
|
|
98
|
+
"types": "./dist/types/talisman/index.d.ts"
|
|
99
|
+
},
|
|
100
|
+
"./tronlink": {
|
|
101
|
+
"bun": "./src/tronlink/index.ts",
|
|
102
|
+
"default": "./dist/src/tronlink/index.js",
|
|
103
|
+
"require": "./dist/src/tronlink/index.cjs",
|
|
104
|
+
"types": "./dist/types/tronlink/index.d.ts"
|
|
105
|
+
},
|
|
106
|
+
"./vultisig": {
|
|
107
|
+
"bun": "./src/vultisig/index.ts",
|
|
108
|
+
"default": "./dist/src/vultisig/index.js",
|
|
109
|
+
"require": "./dist/src/vultisig/index.cjs",
|
|
110
|
+
"types": "./dist/types/vultisig/index.d.ts"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"files": ["dist/", "src/"],
|
|
114
|
+
"homepage": "https://github.com/thorchain/TCSwap",
|
|
115
|
+
"license": "Apache-2.0",
|
|
116
|
+
"name": "@tcswap/wallet-extensions",
|
|
117
|
+
"repository": {
|
|
118
|
+
"directory": "packages/wallet-extension",
|
|
119
|
+
"type": "git",
|
|
120
|
+
"url": "git+https://github.com/thorchain/TCSwap.git"
|
|
121
|
+
},
|
|
122
|
+
"scripts": {
|
|
123
|
+
"build": "bun run ./build.ts",
|
|
124
|
+
"build:clean": "rm -rf dist && bun run ./build.ts",
|
|
125
|
+
"clean": "rm -rf dist node_modules *.tsbuildinfo",
|
|
126
|
+
"test": "echo 'bun test'",
|
|
127
|
+
"test:ci": "echo 'bun test --coverage'",
|
|
128
|
+
"type-check": "bun tsc --noEmit",
|
|
129
|
+
"type-check:go": "tsgo"
|
|
130
|
+
},
|
|
131
|
+
"type": "module",
|
|
132
|
+
"version": "4.1.16"
|
|
133
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Chain,
|
|
7
|
+
type EVMChain,
|
|
8
|
+
GAIAConfig,
|
|
9
|
+
prepareNetworkSwitch,
|
|
10
|
+
switchEVMWalletNetwork,
|
|
11
|
+
USwapError,
|
|
12
|
+
} from "@tcswap/helpers";
|
|
13
|
+
import type { TronTransaction } from "@tcswap/toolboxes/tron";
|
|
14
|
+
import { Psbt } from "bitcoinjs-lib";
|
|
15
|
+
import type { Eip1193Provider } from "ethers";
|
|
16
|
+
|
|
17
|
+
export async function getWalletMethods(chain: Chain) {
|
|
18
|
+
const { match, P } = await import("ts-pattern");
|
|
19
|
+
const bitget = window.bitkeep;
|
|
20
|
+
|
|
21
|
+
return match(chain)
|
|
22
|
+
.with(
|
|
23
|
+
P.union(
|
|
24
|
+
Chain.Arbitrum,
|
|
25
|
+
Chain.Aurora,
|
|
26
|
+
Chain.Avalanche,
|
|
27
|
+
Chain.Base,
|
|
28
|
+
Chain.Berachain,
|
|
29
|
+
Chain.BinanceSmartChain,
|
|
30
|
+
Chain.Ethereum,
|
|
31
|
+
Chain.Gnosis,
|
|
32
|
+
Chain.Monad,
|
|
33
|
+
Chain.Optimism,
|
|
34
|
+
Chain.Polygon,
|
|
35
|
+
Chain.XLayer,
|
|
36
|
+
),
|
|
37
|
+
async () => {
|
|
38
|
+
if (!(bitget && "ethereum" in bitget)) {
|
|
39
|
+
throw new USwapError("wallet_bitkeep_not_found");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const wallet = bitget.ethereum;
|
|
43
|
+
|
|
44
|
+
const [address]: [string] = await wallet.send("eth_requestAccounts", []);
|
|
45
|
+
const evmWallet = await getWeb3WalletMethods({ chain: chain as EVMChain, walletProvider: wallet });
|
|
46
|
+
|
|
47
|
+
return { ...evmWallet, address };
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
.with(Chain.Bitcoin, async () => {
|
|
51
|
+
if (!(bitget && "unisat" in bitget)) {
|
|
52
|
+
throw new USwapError("wallet_bitkeep_not_found");
|
|
53
|
+
}
|
|
54
|
+
const { unisat: wallet } = bitget;
|
|
55
|
+
|
|
56
|
+
const { getUtxoToolbox } = await import("@tcswap/toolboxes/utxo");
|
|
57
|
+
const [address] = await wallet.requestAccounts();
|
|
58
|
+
|
|
59
|
+
async function signTransaction(psbt: Psbt) {
|
|
60
|
+
const signedPsbt = await wallet.signPsbt(psbt.toHex(), { autoFinalized: false });
|
|
61
|
+
|
|
62
|
+
return Psbt.fromHex(signedPsbt);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const signer = { getAddress: () => Promise.resolve(address), signTransaction };
|
|
66
|
+
|
|
67
|
+
const toolbox = await getUtxoToolbox(Chain.Bitcoin, { signer });
|
|
68
|
+
|
|
69
|
+
return { ...toolbox, address };
|
|
70
|
+
})
|
|
71
|
+
.with(Chain.Cosmos, async () => {
|
|
72
|
+
if (!(bitget && "keplr" in bitget)) {
|
|
73
|
+
throw new USwapError("wallet_bitkeep_not_found");
|
|
74
|
+
}
|
|
75
|
+
const { keplr: wallet } = bitget;
|
|
76
|
+
|
|
77
|
+
await wallet.enable(GAIAConfig.chainId);
|
|
78
|
+
const offlineSigner = wallet.getOfflineSignerOnlyAmino(GAIAConfig.chainId);
|
|
79
|
+
const accounts = await offlineSigner.getAccounts();
|
|
80
|
+
if (!accounts?.[0]) throw new USwapError("wallet_bitkeep_no_accounts", { chain: Chain.Cosmos });
|
|
81
|
+
|
|
82
|
+
const { getCosmosToolbox } = await import("@tcswap/toolboxes/cosmos");
|
|
83
|
+
const [{ address }] = accounts;
|
|
84
|
+
|
|
85
|
+
const signer = {
|
|
86
|
+
...offlineSigner,
|
|
87
|
+
getAddress: () => Promise.resolve(address),
|
|
88
|
+
signTransaction: async () => Promise.resolve({} as any),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const toolbox = await getCosmosToolbox(Chain.Cosmos, { signer });
|
|
92
|
+
|
|
93
|
+
return { ...toolbox, address };
|
|
94
|
+
})
|
|
95
|
+
.with(Chain.Solana, async () => {
|
|
96
|
+
if (!(bitget && "solana" in bitget)) {
|
|
97
|
+
throw new USwapError("wallet_bitkeep_not_found");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { getSolanaToolbox } = await import("@tcswap/toolboxes/solana");
|
|
101
|
+
const provider = bitget?.solana;
|
|
102
|
+
|
|
103
|
+
// Connect to get the public key
|
|
104
|
+
const providerConnection = await provider.connect();
|
|
105
|
+
const address: string = providerConnection.publicKey.toString();
|
|
106
|
+
|
|
107
|
+
// Create a proper signer object that wraps the provider
|
|
108
|
+
const signer = { ...provider, getAddress: async () => address, publicKey: providerConnection.publicKey };
|
|
109
|
+
|
|
110
|
+
const toolbox = await getSolanaToolbox({ signer });
|
|
111
|
+
|
|
112
|
+
return { ...toolbox, address };
|
|
113
|
+
})
|
|
114
|
+
.with(Chain.Tron, async () => {
|
|
115
|
+
if (!(bitget && "tronLink" in bitget && "tronWeb" in bitget)) {
|
|
116
|
+
throw new USwapError("wallet_bitkeep_not_found");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const { createTronToolbox } = await import("@tcswap/toolboxes/tron");
|
|
120
|
+
const { tronLink, tronWeb } = bitget;
|
|
121
|
+
|
|
122
|
+
// Request account access
|
|
123
|
+
const response = await tronLink.request({ method: "tron_requestAccounts" });
|
|
124
|
+
|
|
125
|
+
// Check if the request was successful
|
|
126
|
+
if (response.code !== 200) {
|
|
127
|
+
throw new USwapError("wallet_connection_rejected_by_user", {
|
|
128
|
+
message: response.message || "User rejected connection",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// After successful approval, the address should be available in tronWeb.defaultAddress
|
|
133
|
+
const address = tronWeb.defaultAddress?.base58;
|
|
134
|
+
|
|
135
|
+
if (!address) {
|
|
136
|
+
throw new USwapError("wallet_bitkeep_no_accounts", { chain: Chain.Tron });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Create signer compatible with TronSigner interface
|
|
140
|
+
const signer = {
|
|
141
|
+
getAddress: () => Promise.resolve(address),
|
|
142
|
+
signTransaction: async (transaction: TronTransaction) => {
|
|
143
|
+
const signedTx = await tronWeb.trx.sign(transaction);
|
|
144
|
+
return signedTx;
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const toolbox = await createTronToolbox({ signer });
|
|
149
|
+
|
|
150
|
+
return { ...toolbox, address };
|
|
151
|
+
})
|
|
152
|
+
.otherwise(() => {
|
|
153
|
+
throw new USwapError("wallet_chain_not_supported");
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export const getWeb3WalletMethods = async ({
|
|
158
|
+
chain,
|
|
159
|
+
walletProvider,
|
|
160
|
+
}: {
|
|
161
|
+
walletProvider?: Eip1193Provider;
|
|
162
|
+
chain: EVMChain;
|
|
163
|
+
}) => {
|
|
164
|
+
const { getEvmToolbox } = await import("@tcswap/toolboxes/evm");
|
|
165
|
+
const { BrowserProvider } = await import("ethers");
|
|
166
|
+
if (!walletProvider) throw new USwapError("wallet_provider_not_found");
|
|
167
|
+
|
|
168
|
+
const provider = new BrowserProvider(walletProvider, "any");
|
|
169
|
+
const signer = await provider.getSigner();
|
|
170
|
+
const toolbox = await getEvmToolbox(chain, { provider, signer });
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
if (chain !== Chain.Ethereum && "getNetworkParams" in toolbox) {
|
|
174
|
+
await switchEVMWalletNetwork(provider, chain, toolbox.getNetworkParams());
|
|
175
|
+
}
|
|
176
|
+
} catch {
|
|
177
|
+
throw new USwapError("wallet_bitkeep_failed_to_switch_network", { chain });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return prepareNetworkSwitch({ chain, provider, toolbox });
|
|
181
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Chain, EVMChains, filterSupportedChains, WalletOption } from "@tcswap/helpers";
|
|
2
|
+
import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
|
|
3
|
+
|
|
4
|
+
import { getWalletMethods } from "./helpers";
|
|
5
|
+
|
|
6
|
+
export const bitgetWallet = createWallet({
|
|
7
|
+
connect: ({ addChain, walletType, supportedChains }) =>
|
|
8
|
+
async function connectBitget(chains: Chain[]) {
|
|
9
|
+
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
10
|
+
|
|
11
|
+
await Promise.all(
|
|
12
|
+
filteredChains.map(async (chain) => {
|
|
13
|
+
const walletMethods = await getWalletMethods(chain);
|
|
14
|
+
|
|
15
|
+
addChain({ ...walletMethods, chain, walletType });
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return true;
|
|
20
|
+
},
|
|
21
|
+
name: "connectBitget",
|
|
22
|
+
supportedChains: [...EVMChains, Chain.Cosmos, Chain.Bitcoin, Chain.Solana, Chain.Tron],
|
|
23
|
+
walletType: WalletOption.BITGET,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const BITGET_SUPPORTED_CHAINS = getWalletSupportedChains(bitgetWallet);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Keplr } from "@keplr-wallet/types";
|
|
6
|
+
import { Chain, ChainId, ChainToChainId, filterSupportedChains, USwapError, WalletOption } from "@tcswap/helpers";
|
|
7
|
+
import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
|
|
8
|
+
|
|
9
|
+
const cosmostationSupportedChainIds = [ChainId.Cosmos, ChainId.Kujira, ChainId.Noble, ChainId.THORChain] as const;
|
|
10
|
+
const cosmostationSupportedEVMChains = [
|
|
11
|
+
Chain.Ethereum,
|
|
12
|
+
Chain.BinanceSmartChain,
|
|
13
|
+
Chain.Avalanche,
|
|
14
|
+
Chain.Polygon,
|
|
15
|
+
Chain.Arbitrum,
|
|
16
|
+
Chain.Optimism,
|
|
17
|
+
Chain.Base,
|
|
18
|
+
Chain.XLayer,
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
declare global {
|
|
22
|
+
interface Window {
|
|
23
|
+
cosmostation?: { providers?: { keplr?: Keplr } };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function connectCosmosChains(chains: Chain[], addChain: any, keplrProvider: Keplr) {
|
|
28
|
+
await Promise.all(
|
|
29
|
+
chains.map(async (chain) => {
|
|
30
|
+
const chainId = ChainToChainId[chain] as (typeof cosmostationSupportedChainIds)[number];
|
|
31
|
+
|
|
32
|
+
await keplrProvider.enable(chainId);
|
|
33
|
+
const signer = keplrProvider.getOfflineSignerOnlyAmino(chainId);
|
|
34
|
+
if (!signer) throw new USwapError("wallet_cosmostation_signer_not_found");
|
|
35
|
+
|
|
36
|
+
const { getCosmosToolbox } = await import("@tcswap/toolboxes/cosmos");
|
|
37
|
+
|
|
38
|
+
const accounts = await signer.getAccounts();
|
|
39
|
+
if (!accounts?.[0]?.address) throw new USwapError("wallet_cosmostation_no_accounts");
|
|
40
|
+
|
|
41
|
+
const [{ address }] = accounts;
|
|
42
|
+
const toolbox = await getCosmosToolbox(chain as any, { signer });
|
|
43
|
+
|
|
44
|
+
addChain({ ...toolbox, address, chain, walletType: WalletOption.COSMOSTATION });
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function connectEvmChains(chains: Chain[], addChain: any) {
|
|
50
|
+
const provider = window.ethereum;
|
|
51
|
+
|
|
52
|
+
if (!provider) {
|
|
53
|
+
throw new USwapError("wallet_cosmostation_evm_provider_not_found");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const accounts = (await provider.request({ method: "eth_requestAccounts" })) as string[];
|
|
57
|
+
|
|
58
|
+
if (!accounts || accounts.length === 0) {
|
|
59
|
+
throw new USwapError("wallet_cosmostation_no_evm_accounts");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { getEvmToolbox } = await import("@tcswap/toolboxes/evm");
|
|
63
|
+
|
|
64
|
+
for (const chain of chains) {
|
|
65
|
+
const toolbox = getEvmToolbox(chain as any, { provider });
|
|
66
|
+
const [address] = accounts;
|
|
67
|
+
|
|
68
|
+
if (!address) {
|
|
69
|
+
throw new USwapError("wallet_cosmostation_no_evm_address");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
addChain({ ...toolbox, address, chain, walletType: WalletOption.COSMOSTATION });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const cosmostationWallet = createWallet({
|
|
77
|
+
connect: ({ addChain, supportedChains }) =>
|
|
78
|
+
async function connectCosmostation(chains: Chain[]) {
|
|
79
|
+
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType: WalletOption.COSMOSTATION });
|
|
80
|
+
|
|
81
|
+
if (!window.cosmostation) {
|
|
82
|
+
throw new USwapError("wallet_cosmostation_not_found");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const cosmosChains = filteredChains.filter((chain) =>
|
|
86
|
+
cosmostationSupportedChainIds.includes(ChainToChainId[chain] as any),
|
|
87
|
+
);
|
|
88
|
+
const evmChains = filteredChains.filter((chain) => cosmostationSupportedEVMChains.includes(chain as any));
|
|
89
|
+
|
|
90
|
+
if (cosmosChains.length > 0) {
|
|
91
|
+
const keplrProvider = window.cosmostation.providers?.keplr;
|
|
92
|
+
if (!keplrProvider) {
|
|
93
|
+
throw new USwapError("wallet_cosmostation_keplr_provider_not_found");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await connectCosmosChains(cosmosChains, addChain, keplrProvider);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (evmChains.length > 0) {
|
|
100
|
+
await connectEvmChains(evmChains, addChain);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return true;
|
|
104
|
+
},
|
|
105
|
+
name: "connectCosmostation",
|
|
106
|
+
supportedChains: [
|
|
107
|
+
Chain.Cosmos,
|
|
108
|
+
Chain.Kujira,
|
|
109
|
+
Chain.Noble,
|
|
110
|
+
Chain.THORChain,
|
|
111
|
+
Chain.Ethereum,
|
|
112
|
+
Chain.BinanceSmartChain,
|
|
113
|
+
Chain.Avalanche,
|
|
114
|
+
Chain.Polygon,
|
|
115
|
+
Chain.Arbitrum,
|
|
116
|
+
Chain.Optimism,
|
|
117
|
+
Chain.Base,
|
|
118
|
+
Chain.XLayer,
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const COSMOSTATION_SUPPORTED_CHAINS = getWalletSupportedChains(cosmostationWallet);
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Chain,
|
|
7
|
+
ChainToChainId,
|
|
8
|
+
filterSupportedChains,
|
|
9
|
+
type GenericTransferParams,
|
|
10
|
+
USwapError,
|
|
11
|
+
WalletOption,
|
|
12
|
+
} from "@tcswap/helpers";
|
|
13
|
+
import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
|
|
14
|
+
|
|
15
|
+
import { getCtrlAddress, getCtrlProvider, walletTransfer } from "./walletHelpers";
|
|
16
|
+
|
|
17
|
+
export const ctrlWallet = createWallet({
|
|
18
|
+
connect: ({ addChain, walletType, supportedChains }) =>
|
|
19
|
+
async function connectCtrl(chains: Chain[]) {
|
|
20
|
+
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
21
|
+
|
|
22
|
+
const promises = filteredChains.map(async (chain) => {
|
|
23
|
+
const address = await getCtrlAddress(chain);
|
|
24
|
+
const walletMethods = await getWalletMethods(chain);
|
|
25
|
+
|
|
26
|
+
addChain({ ...walletMethods, address, chain, walletType });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await Promise.all(promises);
|
|
30
|
+
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
name: "connectCtrl",
|
|
34
|
+
supportedChains: [
|
|
35
|
+
Chain.Arbitrum,
|
|
36
|
+
Chain.Aurora,
|
|
37
|
+
Chain.Avalanche,
|
|
38
|
+
Chain.Base,
|
|
39
|
+
Chain.Berachain,
|
|
40
|
+
Chain.BinanceSmartChain,
|
|
41
|
+
Chain.Bitcoin,
|
|
42
|
+
Chain.BitcoinCash,
|
|
43
|
+
Chain.Cosmos,
|
|
44
|
+
Chain.Dogecoin,
|
|
45
|
+
Chain.Ethereum,
|
|
46
|
+
Chain.Gnosis,
|
|
47
|
+
Chain.Kujira,
|
|
48
|
+
Chain.Litecoin,
|
|
49
|
+
Chain.Maya,
|
|
50
|
+
Chain.Monad,
|
|
51
|
+
Chain.Near,
|
|
52
|
+
Chain.Noble,
|
|
53
|
+
Chain.Optimism,
|
|
54
|
+
Chain.Polygon,
|
|
55
|
+
Chain.Solana,
|
|
56
|
+
Chain.THORChain,
|
|
57
|
+
Chain.XLayer,
|
|
58
|
+
],
|
|
59
|
+
walletType: WalletOption.CTRL,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const CTRL_SUPPORTED_CHAINS = getWalletSupportedChains(ctrlWallet);
|
|
63
|
+
|
|
64
|
+
async function getWalletMethods(chain: (typeof CTRL_SUPPORTED_CHAINS)[number]) {
|
|
65
|
+
switch (chain) {
|
|
66
|
+
case Chain.Solana: {
|
|
67
|
+
const { getSolanaToolbox } = await import("@tcswap/toolboxes/solana");
|
|
68
|
+
const provider = getCtrlProvider(chain);
|
|
69
|
+
|
|
70
|
+
if (!provider) {
|
|
71
|
+
throw new USwapError("wallet_ctrl_not_found");
|
|
72
|
+
}
|
|
73
|
+
const toolbox = await getSolanaToolbox({ signer: provider });
|
|
74
|
+
|
|
75
|
+
return toolbox;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
case Chain.Maya:
|
|
79
|
+
case Chain.THORChain: {
|
|
80
|
+
const { getCosmosToolbox, THORCHAIN_GAS_VALUE, MAYA_GAS_VALUE } = await import("@tcswap/toolboxes/cosmos");
|
|
81
|
+
|
|
82
|
+
const gasLimit = chain === Chain.Maya ? MAYA_GAS_VALUE : THORCHAIN_GAS_VALUE;
|
|
83
|
+
const toolbox = await getCosmosToolbox(chain);
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
...toolbox,
|
|
87
|
+
deposit: (tx: GenericTransferParams) => walletTransfer({ ...tx, recipient: "" }, "deposit"),
|
|
88
|
+
transfer: (tx: GenericTransferParams) => walletTransfer({ ...tx, gasLimit }, "transfer"),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
case Chain.Cosmos:
|
|
93
|
+
case Chain.Kujira:
|
|
94
|
+
case Chain.Noble: {
|
|
95
|
+
const { getCosmosToolbox } = await import("@tcswap/toolboxes/cosmos");
|
|
96
|
+
const chainId = ChainToChainId[chain];
|
|
97
|
+
const provider = getCtrlProvider(chain);
|
|
98
|
+
|
|
99
|
+
await provider?.enable(chainId);
|
|
100
|
+
const signer = provider?.getOfflineSignerOnlyAmino(chainId, { preferNoSetFee: true });
|
|
101
|
+
|
|
102
|
+
if (!signer) {
|
|
103
|
+
throw new USwapError("wallet_ctrl_not_found");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const toolbox = await getCosmosToolbox(chain, { signer });
|
|
107
|
+
|
|
108
|
+
return toolbox;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
case Chain.Bitcoin:
|
|
112
|
+
case Chain.BitcoinCash:
|
|
113
|
+
case Chain.Dogecoin:
|
|
114
|
+
case Chain.Litecoin: {
|
|
115
|
+
const { getUtxoToolbox } = await import("@tcswap/toolboxes/utxo");
|
|
116
|
+
const toolbox = await getUtxoToolbox(chain);
|
|
117
|
+
|
|
118
|
+
return { ...toolbox, transfer: walletTransfer };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
case Chain.Arbitrum:
|
|
122
|
+
case Chain.Aurora:
|
|
123
|
+
case Chain.Avalanche:
|
|
124
|
+
case Chain.Base:
|
|
125
|
+
case Chain.Berachain:
|
|
126
|
+
case Chain.BinanceSmartChain:
|
|
127
|
+
case Chain.Ethereum:
|
|
128
|
+
case Chain.Gnosis:
|
|
129
|
+
case Chain.Monad:
|
|
130
|
+
case Chain.Optimism:
|
|
131
|
+
case Chain.Polygon:
|
|
132
|
+
case Chain.XLayer: {
|
|
133
|
+
const { prepareNetworkSwitch, switchEVMWalletNetwork } = await import("@tcswap/helpers");
|
|
134
|
+
const { getEvmToolbox } = await import("@tcswap/toolboxes/evm");
|
|
135
|
+
const { BrowserProvider } = await import("ethers");
|
|
136
|
+
const ethereumWindowProvider = getCtrlProvider(chain);
|
|
137
|
+
|
|
138
|
+
if (!ethereumWindowProvider) {
|
|
139
|
+
throw new USwapError("wallet_ctrl_not_found");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const provider = new BrowserProvider(ethereumWindowProvider, "any");
|
|
143
|
+
const signer = await provider.getSigner();
|
|
144
|
+
const toolbox = await getEvmToolbox(chain, { provider, signer });
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
if (chain !== Chain.Ethereum) {
|
|
148
|
+
const networkParams = toolbox.getNetworkParams();
|
|
149
|
+
await switchEVMWalletNetwork(provider, chain, networkParams);
|
|
150
|
+
}
|
|
151
|
+
} catch {
|
|
152
|
+
throw new USwapError({
|
|
153
|
+
errorKey: "wallet_failed_to_add_or_switch_network",
|
|
154
|
+
info: { chain, wallet: WalletOption.CTRL },
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return prepareNetworkSwitch({ chain, provider, toolbox });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
case Chain.Near: {
|
|
162
|
+
const provider = getCtrlProvider(chain);
|
|
163
|
+
|
|
164
|
+
if (!provider) {
|
|
165
|
+
throw new USwapError("wallet_ctrl_not_found", { chain: Chain.Near });
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const { createNearSignerFromProvider } = await import("../helpers/near");
|
|
169
|
+
const { getNearToolbox } = await import("@tcswap/toolboxes/near");
|
|
170
|
+
|
|
171
|
+
const signer = await createNearSignerFromProvider(provider, "CTRL");
|
|
172
|
+
const accountId = await signer.getAddress();
|
|
173
|
+
const toolbox = await getNearToolbox({ signer });
|
|
174
|
+
|
|
175
|
+
const transfer = async (params: GenericTransferParams) => {
|
|
176
|
+
const { actionCreators } = await import("@near-js/transactions");
|
|
177
|
+
|
|
178
|
+
const amountInYocto = params.assetValue.getBaseValue("string");
|
|
179
|
+
const action = actionCreators.transfer(BigInt(amountInYocto));
|
|
180
|
+
|
|
181
|
+
const transaction = { actions: [action], receiverId: params.recipient, signerId: accountId };
|
|
182
|
+
|
|
183
|
+
const txHash: string = await provider.request({ method: "signAndSendTransaction", params: { transaction } });
|
|
184
|
+
|
|
185
|
+
return txHash;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
return { ...toolbox, transfer };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
default:
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|