@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.
Files changed (147) hide show
  1. package/dist/chunk-7y3ffnf3.js +4 -0
  2. package/dist/chunk-7y3ffnf3.js.map +10 -0
  3. package/dist/chunk-fazw0jvt.js +4 -0
  4. package/dist/chunk-fazw0jvt.js.map +9 -0
  5. package/dist/chunk-kx2thqhk.js +5 -0
  6. package/dist/chunk-kx2thqhk.js.map +9 -0
  7. package/dist/chunk-swh9jwp7.js +4 -0
  8. package/dist/chunk-swh9jwp7.js.map +10 -0
  9. package/dist/src/bitget/index.cjs +4 -0
  10. package/dist/src/bitget/index.cjs.map +11 -0
  11. package/dist/src/bitget/index.js +4 -0
  12. package/dist/src/bitget/index.js.map +11 -0
  13. package/dist/src/cosmostation/index.cjs +4 -0
  14. package/dist/src/cosmostation/index.cjs.map +10 -0
  15. package/dist/src/cosmostation/index.js +4 -0
  16. package/dist/src/cosmostation/index.js.map +10 -0
  17. package/dist/src/ctrl/index.cjs +4 -0
  18. package/dist/src/ctrl/index.cjs.map +11 -0
  19. package/dist/src/ctrl/index.js +4 -0
  20. package/dist/src/ctrl/index.js.map +11 -0
  21. package/dist/src/evm-extensions/index.cjs +4 -0
  22. package/dist/src/evm-extensions/index.cjs.map +10 -0
  23. package/dist/src/evm-extensions/index.js +4 -0
  24. package/dist/src/evm-extensions/index.js.map +10 -0
  25. package/dist/src/index.cjs +4 -0
  26. package/dist/src/index.cjs.map +9 -0
  27. package/dist/src/index.js +3 -0
  28. package/dist/src/index.js.map +9 -0
  29. package/dist/src/keepkey-bex/index.cjs +4 -0
  30. package/dist/src/keepkey-bex/index.cjs.map +11 -0
  31. package/dist/src/keepkey-bex/index.js +4 -0
  32. package/dist/src/keepkey-bex/index.js.map +11 -0
  33. package/dist/src/keplr/index.cjs +4 -0
  34. package/dist/src/keplr/index.cjs.map +11 -0
  35. package/dist/src/keplr/index.js +4 -0
  36. package/dist/src/keplr/index.js.map +11 -0
  37. package/dist/src/okx/index.cjs +4 -0
  38. package/dist/src/okx/index.cjs.map +11 -0
  39. package/dist/src/okx/index.js +4 -0
  40. package/dist/src/okx/index.js.map +11 -0
  41. package/dist/src/onekey/index.cjs +4 -0
  42. package/dist/src/onekey/index.cjs.map +10 -0
  43. package/dist/src/onekey/index.js +4 -0
  44. package/dist/src/onekey/index.js.map +10 -0
  45. package/dist/src/phantom/index.cjs +4 -0
  46. package/dist/src/phantom/index.cjs.map +10 -0
  47. package/dist/src/phantom/index.js +4 -0
  48. package/dist/src/phantom/index.js.map +10 -0
  49. package/dist/src/polkadotjs/index.cjs +4 -0
  50. package/dist/src/polkadotjs/index.cjs.map +10 -0
  51. package/dist/src/polkadotjs/index.js +4 -0
  52. package/dist/src/polkadotjs/index.js.map +10 -0
  53. package/dist/src/talisman/index.cjs +4 -0
  54. package/dist/src/talisman/index.cjs.map +10 -0
  55. package/dist/src/talisman/index.js +4 -0
  56. package/dist/src/talisman/index.js.map +10 -0
  57. package/dist/src/tronlink/index.cjs +4 -0
  58. package/dist/src/tronlink/index.cjs.map +12 -0
  59. package/dist/src/tronlink/index.js +4 -0
  60. package/dist/src/tronlink/index.js.map +12 -0
  61. package/dist/src/vultisig/index.cjs +4 -0
  62. package/dist/src/vultisig/index.cjs.map +11 -0
  63. package/dist/src/vultisig/index.js +4 -0
  64. package/dist/src/vultisig/index.js.map +11 -0
  65. package/dist/types/bitget/helpers.d.ts +1607 -0
  66. package/dist/types/bitget/helpers.d.ts.map +1 -0
  67. package/dist/types/bitget/index.d.ts +11 -0
  68. package/dist/types/bitget/index.d.ts.map +1 -0
  69. package/dist/types/cosmostation/index.d.ts +24 -0
  70. package/dist/types/cosmostation/index.d.ts.map +1 -0
  71. package/dist/types/ctrl/index.d.ts +14 -0
  72. package/dist/types/ctrl/index.d.ts.map +1 -0
  73. package/dist/types/ctrl/walletHelpers.d.ts +23 -0
  74. package/dist/types/ctrl/walletHelpers.d.ts.map +1 -0
  75. package/dist/types/evm-extensions/index.d.ts +747 -0
  76. package/dist/types/evm-extensions/index.d.ts.map +1 -0
  77. package/dist/types/evm-extensions/types.d.ts +18 -0
  78. package/dist/types/evm-extensions/types.d.ts.map +1 -0
  79. package/dist/types/helpers/near.d.ts +60 -0
  80. package/dist/types/helpers/near.d.ts.map +1 -0
  81. package/dist/types/index.d.ts +2 -0
  82. package/dist/types/index.d.ts.map +1 -0
  83. package/dist/types/keepkey-bex/index.d.ts +14 -0
  84. package/dist/types/keepkey-bex/index.d.ts.map +1 -0
  85. package/dist/types/keepkey-bex/walletHelpers.d.ts +48 -0
  86. package/dist/types/keepkey-bex/walletHelpers.d.ts.map +1 -0
  87. package/dist/types/keplr/chainRegistry.d.ts +4 -0
  88. package/dist/types/keplr/chainRegistry.d.ts.map +1 -0
  89. package/dist/types/keplr/index.d.ts +14 -0
  90. package/dist/types/keplr/index.d.ts.map +1 -0
  91. package/dist/types/okx/helpers.d.ts +855 -0
  92. package/dist/types/okx/helpers.d.ts.map +1 -0
  93. package/dist/types/okx/index.d.ts +11 -0
  94. package/dist/types/okx/index.d.ts.map +1 -0
  95. package/dist/types/okx/types.d.ts +104 -0
  96. package/dist/types/okx/types.d.ts.map +1 -0
  97. package/dist/types/onekey/evmSigner.d.ts +32 -0
  98. package/dist/types/onekey/evmSigner.d.ts.map +1 -0
  99. package/dist/types/onekey/index.d.ts +14 -0
  100. package/dist/types/onekey/index.d.ts.map +1 -0
  101. package/dist/types/phantom/index.d.ts +15 -0
  102. package/dist/types/phantom/index.d.ts.map +1 -0
  103. package/dist/types/polkadotjs/index.d.ts +14 -0
  104. package/dist/types/polkadotjs/index.d.ts.map +1 -0
  105. package/dist/types/talisman/index.d.ts +14 -0
  106. package/dist/types/talisman/index.d.ts.map +1 -0
  107. package/dist/types/tronlink/helpers.d.ts +29 -0
  108. package/dist/types/tronlink/helpers.d.ts.map +1 -0
  109. package/dist/types/tronlink/index.d.ts +13 -0
  110. package/dist/types/tronlink/index.d.ts.map +1 -0
  111. package/dist/types/tronlink/types.d.ts +55 -0
  112. package/dist/types/tronlink/types.d.ts.map +1 -0
  113. package/dist/types/types.d.ts +166 -0
  114. package/dist/types/types.d.ts.map +1 -0
  115. package/dist/types/vultisig/index.d.ts +14 -0
  116. package/dist/types/vultisig/index.d.ts.map +1 -0
  117. package/dist/types/vultisig/walletHelpers.d.ts +37 -0
  118. package/dist/types/vultisig/walletHelpers.d.ts.map +1 -0
  119. package/package.json +133 -0
  120. package/src/bitget/helpers.ts +181 -0
  121. package/src/bitget/index.ts +26 -0
  122. package/src/cosmostation/index.ts +122 -0
  123. package/src/ctrl/index.ts +194 -0
  124. package/src/ctrl/walletHelpers.ts +186 -0
  125. package/src/evm-extensions/index.ts +122 -0
  126. package/src/evm-extensions/types.ts +15 -0
  127. package/src/helpers/near-browser-provider.d.ts +270 -0
  128. package/src/helpers/near.ts +174 -0
  129. package/src/index.ts +1 -0
  130. package/src/keepkey-bex/index.ts +151 -0
  131. package/src/keepkey-bex/walletHelpers.ts +241 -0
  132. package/src/keplr/chainRegistry.ts +240 -0
  133. package/src/keplr/index.ts +54 -0
  134. package/src/okx/helpers.ts +192 -0
  135. package/src/okx/index.ts +43 -0
  136. package/src/okx/types.ts +117 -0
  137. package/src/onekey/evmSigner.ts +116 -0
  138. package/src/onekey/index.ts +182 -0
  139. package/src/phantom/index.ts +136 -0
  140. package/src/polkadotjs/index.ts +61 -0
  141. package/src/talisman/index.ts +132 -0
  142. package/src/tronlink/helpers.ts +153 -0
  143. package/src/tronlink/index.ts +49 -0
  144. package/src/tronlink/types.ts +44 -0
  145. package/src/types.ts +157 -0
  146. package/src/vultisig/index.ts +179 -0
  147. package/src/vultisig/walletHelpers.ts +295 -0
@@ -0,0 +1,240 @@
1
+ import type { ChainInfo } from "@keplr-wallet/types";
2
+ import { ChainId } from "@tcswap/helpers";
3
+
4
+ export const chainRegistry = new Map<ChainId, ChainInfo>([
5
+ [
6
+ ChainId.Kujira,
7
+ {
8
+ bech32Config: {
9
+ bech32PrefixAccAddr: "kujira",
10
+ bech32PrefixAccPub: "kujirapub",
11
+ bech32PrefixConsAddr: "kujiravalcons",
12
+ bech32PrefixConsPub: "kujiravalconspub",
13
+ bech32PrefixValAddr: "kujiravaloper",
14
+ bech32PrefixValPub: "kujiravaloperpub",
15
+ },
16
+ bip44: { coinType: 118 },
17
+ chainId: "kaiyo-1",
18
+ chainName: "Kujira",
19
+ chainSymbolImageUrl:
20
+ "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/chain.png",
21
+ currencies: [
22
+ {
23
+ coinDecimals: 6,
24
+ coinDenom: "KUJI",
25
+ coinGeckoId: "kujira",
26
+ coinImageUrl: "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/ukuji.png",
27
+ coinMinimalDenom: "ukuji",
28
+ },
29
+ {
30
+ coinDecimals: 6,
31
+ coinDenom: "USK",
32
+ coinGeckoId: "usk",
33
+ coinMinimalDenom: "factory/kujira1qk00h5atutpsv900x202pxx42npjr9thg58dnqpa72f2p7m2luase444a7/uusk",
34
+ },
35
+ {
36
+ coinDecimals: 6,
37
+ coinDenom: "MNTA",
38
+ coinGeckoId: "mantadao",
39
+ coinMinimalDenom: "factory/kujira1643jxg8wasy5cfcn7xm8rd742yeazcksqlg4d7/umnta",
40
+ },
41
+ {
42
+ coinDecimals: 6,
43
+ coinDenom: "bKUJI",
44
+ coinImageUrl:
45
+ "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/factory/kujira15e8q5wzlk5k38gjxlhse3vu6vqnafysncx2ltexd6y9gx50vuj2qpt7dgv/bKUJI.png",
46
+ coinMinimalDenom: "factory/kujira15e8q5wzlk5k38gjxlhse3vu6vqnafysncx2ltexd6y9gx50vuj2qpt7dgv/boneKuji",
47
+ },
48
+ {
49
+ coinDecimals: 6,
50
+ coinDenom: "AQLA",
51
+ coinGeckoId: "aqualibre",
52
+ coinImageUrl:
53
+ "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/factory/kujira1xe0awk5planmtsmjel5xtx2hzhqdw5p8z66yqd/AQLA.png",
54
+ coinMinimalDenom: "factory/kujira1xe0awk5planmtsmjel5xtx2hzhqdw5p8z66yqd/uaqla",
55
+ },
56
+ ],
57
+ features: ["cosmwasm"],
58
+ feeCurrencies: [
59
+ {
60
+ coinDecimals: 6,
61
+ coinDenom: "KUJI",
62
+ coinGeckoId: "kujira",
63
+ coinImageUrl: "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/ukuji.png",
64
+ coinMinimalDenom: "ukuji",
65
+ },
66
+ {
67
+ coinDecimals: 6,
68
+ coinDenom: "USK",
69
+ coinGeckoId: "usk",
70
+ coinMinimalDenom: "factory/kujira1qk00h5atutpsv900x202pxx42npjr9thg58dnqpa72f2p7m2luase444a7/uusk",
71
+ },
72
+ {
73
+ coinDecimals: 6,
74
+ coinDenom: "axlUSDC",
75
+ coinGeckoId: "usd-coin",
76
+ coinMinimalDenom: "ibc/295548A78785A1007F232DE286149A6FF512F180AF5657780FC89C009E2C348F",
77
+ },
78
+ {
79
+ coinDecimals: 6,
80
+ coinDenom: "ATOM",
81
+ coinGeckoId: "cosmos",
82
+ coinMinimalDenom: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
83
+ },
84
+ {
85
+ coinDecimals: 6,
86
+ coinDenom: "OSMO",
87
+ coinGeckoId: "osmosis",
88
+ coinMinimalDenom: "ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23",
89
+ },
90
+ {
91
+ coinDecimals: 6,
92
+ coinDenom: "CMDX",
93
+ coinGeckoId: "comdex",
94
+ coinMinimalDenom: "ibc/3607EB5B5E64DD1C0E12E07F077FF470D5BC4706AFCBC98FE1BA960E5AE4CE07",
95
+ },
96
+ {
97
+ coinDecimals: 6,
98
+ coinDenom: "EVMOS",
99
+ coinGeckoId: "evmos",
100
+ coinMinimalDenom: "ibc/F3AA7EF362EC5E791FE78A0F4CCC69FEE1F9A7485EB1A8CAB3F6601C00522F10",
101
+ },
102
+ {
103
+ coinDecimals: 6,
104
+ coinDenom: "JUNO",
105
+ coinGeckoId: "juno-network",
106
+ coinMinimalDenom: "ibc/EFF323CC632EC4F747C61BCE238A758EFDB7699C3226565F7C20DA06509D59A5",
107
+ },
108
+ {
109
+ coinDecimals: 6,
110
+ coinDenom: "MNTA",
111
+ coinGeckoId: "mantadao",
112
+ coinMinimalDenom: "factory/kujira1643jxg8wasy5cfcn7xm8rd742yeazcksqlg4d7/umnta",
113
+ },
114
+ {
115
+ coinDecimals: 6,
116
+ coinDenom: "SCRT",
117
+ coinGeckoId: "secret",
118
+ coinMinimalDenom: "ibc/A358D7F19237777AF6D8AD0E0F53268F8B18AE8A53ED318095C14D6D7F3B2DB5",
119
+ },
120
+ {
121
+ coinDecimals: 6,
122
+ coinDenom: "STARS",
123
+ coinGeckoId: "stargaze",
124
+ coinMinimalDenom: "ibc/4F393C3FCA4190C0A6756CE7F6D897D5D1BE57D6CCB80D0BC87393566A7B6602",
125
+ },
126
+ {
127
+ coinDecimals: 18,
128
+ coinDenom: "wAVAX",
129
+ coinGeckoId: "avalanche-2",
130
+ coinMinimalDenom: "ibc/004EBF085BBED1029326D56BE8A2E67C08CECE670A94AC1947DF413EF5130EB2",
131
+ },
132
+ {
133
+ coinDecimals: 18,
134
+ coinDenom: "wETH",
135
+ coinGeckoId: "ethereum",
136
+ coinMinimalDenom: "ibc/1B38805B1C75352B28169284F96DF56BDEBD9E8FAC005BDCC8CF0378C82AA8E7",
137
+ },
138
+ ],
139
+ nodeProvider: { email: "pfc-validator@protonmail.com", name: "PFC", website: "https://pfc.zone/" },
140
+ rest: "https://rest.cosmos.directory/kujira/",
141
+ rpc: "https://kujira-rpc.nodes.defiantlabs.net",
142
+ stakeCurrency: {
143
+ coinDecimals: 6,
144
+ coinDenom: "KUJI",
145
+ coinGeckoId: "kujira",
146
+ coinImageUrl: "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/ukuji.png",
147
+ coinMinimalDenom: "ukuji",
148
+ },
149
+ },
150
+ ],
151
+ [
152
+ ChainId.Noble,
153
+ {
154
+ bech32Config: {
155
+ bech32PrefixAccAddr: "noble",
156
+ bech32PrefixAccPub: "noblepub",
157
+ bech32PrefixConsAddr: "noblevalcons",
158
+ bech32PrefixConsPub: "noblevalconspub",
159
+ bech32PrefixValAddr: "noblevaloper",
160
+ bech32PrefixValPub: "noblevaloperpub",
161
+ },
162
+ bip44: { coinType: 118 },
163
+ chainId: "noble-1",
164
+ chainName: "Noble",
165
+ chainSymbolImageUrl:
166
+ "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/noble/chain.png",
167
+ currencies: [
168
+ {
169
+ coinDecimals: 6,
170
+ coinDenom: "USDC",
171
+ coinGeckoId: "usd-coin",
172
+ coinImageUrl: "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/noble/uusdc.png",
173
+ coinMinimalDenom: "uusdc",
174
+ },
175
+ { coinDecimals: 6, coinDenom: "USDN", coinGeckoId: "usd-coin", coinMinimalDenom: "uusdn" },
176
+ ],
177
+ features: ["cosmwasm"],
178
+ feeCurrencies: [
179
+ {
180
+ coinDecimals: 6,
181
+ coinDenom: "USDC",
182
+ coinGeckoId: "usd-coin",
183
+ coinImageUrl: "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/noble/uusdc.png",
184
+ coinMinimalDenom: "uusdc",
185
+ },
186
+ {
187
+ coinDecimals: 6,
188
+ coinDenom: "USDN",
189
+ coinGeckoId: "usd-coin",
190
+ coinMinimalDenom:
191
+ "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/noble/uusdn.png",
192
+ },
193
+ ],
194
+ rest: "https://lcd-noble.keplr.app",
195
+ rpc: "https://rpc-noble.keplr.app",
196
+ },
197
+ ],
198
+ [
199
+ ChainId.THORChain,
200
+ {
201
+ bech32Config: {
202
+ bech32PrefixAccAddr: "thor",
203
+ bech32PrefixAccPub: "thorpub",
204
+ bech32PrefixConsAddr: "thorvalcons",
205
+ bech32PrefixConsPub: "thorvalconspub",
206
+ bech32PrefixValAddr: "thorvaloper",
207
+ bech32PrefixValPub: "thorvaloperpub",
208
+ },
209
+ bip44: { coinType: 931 },
210
+ chainId: "thorchain-1",
211
+ chainName: "THORChain",
212
+ chainSymbolImageUrl:
213
+ "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/thorchain/chain.png",
214
+ currencies: [
215
+ {
216
+ coinDecimals: 8,
217
+ coinDenom: "RUNE",
218
+ coinGeckoId: "thorchain",
219
+ coinImageUrl:
220
+ "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/thorchain/rune.png",
221
+ coinMinimalDenom: "rune",
222
+ },
223
+ ],
224
+ features: [],
225
+ feeCurrencies: [
226
+ {
227
+ coinDecimals: 8,
228
+ coinDenom: "RUNE",
229
+ coinGeckoId: "thorchain",
230
+ coinImageUrl:
231
+ "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/thorchain/rune.png",
232
+ coinMinimalDenom: "rune",
233
+ gasPriceStep: { average: 0.02, high: 0.03, low: 0.02 },
234
+ },
235
+ ],
236
+ rest: "https://lcd-thorchain.keplr.app",
237
+ rpc: "https://rpc-thorchain.keplr.app",
238
+ },
239
+ ],
240
+ ]);
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Modifications © 2025 Horizontal Systems.
3
+ */
4
+
5
+ import { Chain, ChainId, ChainToChainId, filterSupportedChains, USwapError, WalletOption } from "@tcswap/helpers";
6
+ import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
7
+ import { chainRegistry } from "./chainRegistry";
8
+
9
+ const keplrSupportedChainIds = [ChainId.Cosmos, ChainId.Kujira, ChainId.Noble, ChainId.THORChain] as const;
10
+
11
+ export const keplrWallet = createWallet({
12
+ connect: ({ addChain, supportedChains }) =>
13
+ async function connectKeplr(
14
+ chains: Chain[],
15
+ walletType: WalletOption.KEPLR | WalletOption.LEAP = WalletOption.KEPLR,
16
+ ) {
17
+ const extensionKey = walletType === WalletOption.LEAP ? "leap" : "keplr";
18
+ const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
19
+ const keplrClient = window[extensionKey];
20
+
21
+ await Promise.all(
22
+ filteredChains.map(async (chain) => {
23
+ const chainId = ChainToChainId[chain] as (typeof keplrSupportedChainIds)[number];
24
+
25
+ if (!keplrSupportedChainIds.includes(chainId)) {
26
+ const chainConfig = chainRegistry.get(chainId);
27
+ if (!chainConfig) throw new USwapError("wallet_keplr_chain_not_supported", { chain });
28
+
29
+ await keplrClient.experimentalSuggestChain(chainConfig);
30
+ }
31
+
32
+ keplrClient?.enable(chainId);
33
+ const signer = keplrClient?.getOfflineSignerOnlyAmino(chainId);
34
+ if (!signer) throw new USwapError("wallet_keplr_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_keplr_no_accounts");
40
+
41
+ const [{ address }] = accounts;
42
+ const toolbox = await getCosmosToolbox(chain, { signer });
43
+
44
+ addChain({ ...toolbox, address, chain, walletType });
45
+ }),
46
+ );
47
+
48
+ return true;
49
+ },
50
+ name: "connectKeplr",
51
+ supportedChains: [Chain.Cosmos, Chain.Kujira, Chain.Noble, Chain.THORChain],
52
+ });
53
+
54
+ export const KEPLR_SUPPORTED_CHAINS = getWalletSupportedChains(keplrWallet);
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Modifications © 2025 Horizontal Systems.
3
+ */
4
+
5
+ import {
6
+ Chain,
7
+ type EVMChain,
8
+ type GenericTransferParams,
9
+ getChainConfig,
10
+ getRPCUrl,
11
+ prepareNetworkSwitch,
12
+ switchEVMWalletNetwork,
13
+ USwapError,
14
+ } from "@tcswap/helpers";
15
+ import type { TronSigner, TronTransaction } from "@tcswap/toolboxes/tron";
16
+ import { Psbt } from "bitcoinjs-lib";
17
+ import type { Eip1193Provider } from "ethers";
18
+
19
+ const cosmosTransfer =
20
+ (sender: string) =>
21
+ async ({ recipient, assetValue, memo }: GenericTransferParams) => {
22
+ if (!(window.okxwallet && "keplr" in window.okxwallet)) {
23
+ throw new USwapError("wallet_okx_not_found", { chain: Chain.Cosmos });
24
+ }
25
+ const { createSigningStargateClient } = await import("@tcswap/toolboxes/cosmos");
26
+
27
+ const { keplr: wallet } = window.okxwallet;
28
+ const offlineSigner = wallet?.getOfflineSignerOnlyAmino(getChainConfig(Chain.Cosmos).chainId);
29
+
30
+ const rpcUrl = await getRPCUrl(Chain.Cosmos);
31
+ const cosmJS = await createSigningStargateClient(rpcUrl, offlineSigner);
32
+
33
+ const denom = assetValue?.symbol === "MUON" ? "umuon" : "uatom";
34
+ const coins = [{ amount: assetValue.getBaseValue("string"), denom }];
35
+
36
+ const { transactionHash } = await cosmJS.sendTokens(sender, recipient, coins, 1.6, memo);
37
+ return transactionHash;
38
+ };
39
+
40
+ async function getWeb3WalletMethods({
41
+ walletProvider,
42
+ chain,
43
+ }: {
44
+ walletProvider: Eip1193Provider | undefined;
45
+ chain: EVMChain;
46
+ }) {
47
+ const { getEvmToolbox } = await import("@tcswap/toolboxes/evm");
48
+ const { BrowserProvider } = await import("ethers");
49
+ if (!walletProvider) throw new USwapError("wallet_okx_not_found");
50
+
51
+ const provider = new BrowserProvider(walletProvider, "any");
52
+ const signer = await provider.getSigner();
53
+ const toolbox = await getEvmToolbox(chain, { provider, signer });
54
+
55
+ try {
56
+ if (chain !== Chain.Ethereum && "getNetworkParams" in toolbox) {
57
+ await switchEVMWalletNetwork(provider, chain, toolbox.getNetworkParams());
58
+ }
59
+ } catch {
60
+ throw new USwapError("wallet_okx_failed_to_switch_network", { chain });
61
+ }
62
+
63
+ return prepareNetworkSwitch({ chain, provider, toolbox });
64
+ }
65
+
66
+ export async function getWalletMethods(chain: Chain) {
67
+ const { match, P } = await import("ts-pattern");
68
+
69
+ return (
70
+ match(chain)
71
+ .with(
72
+ P.union(
73
+ Chain.Arbitrum,
74
+ Chain.Aurora,
75
+ Chain.Avalanche,
76
+ Chain.Base,
77
+ Chain.Berachain,
78
+ Chain.BinanceSmartChain,
79
+ Chain.Ethereum,
80
+ Chain.Gnosis,
81
+ Chain.Monad,
82
+ Chain.Optimism,
83
+ Chain.Polygon,
84
+ Chain.XLayer,
85
+ ),
86
+ async () => {
87
+ if (!(window.okxwallet && "send" in window.okxwallet)) {
88
+ throw new USwapError("wallet_okx_not_found", { chain });
89
+ }
90
+
91
+ const evmWallet = await getWeb3WalletMethods({ chain: chain as EVMChain, walletProvider: window.okxwallet });
92
+ const address: string = (await window.okxwallet.send("eth_requestAccounts", [])).result[0];
93
+
94
+ return { ...evmWallet, address };
95
+ },
96
+ )
97
+ .with(Chain.Bitcoin, async () => {
98
+ if (!(window.okxwallet && "bitcoin" in window.okxwallet)) {
99
+ throw new USwapError("wallet_okx_not_found", { chain: Chain.Bitcoin });
100
+ }
101
+
102
+ const { getUtxoToolbox } = await import("@tcswap/toolboxes/utxo");
103
+
104
+ const { bitcoin: wallet } = window.okxwallet;
105
+ const address = (await wallet.connect()).address;
106
+
107
+ const signer = {
108
+ getAddress: async () => Promise.resolve(address),
109
+ signTransaction: async (psbt: InstanceType<typeof Psbt>) => {
110
+ const signedPsbt = await wallet.signPsbt(psbt.toHex(), { from: address, type: "list" });
111
+
112
+ return Psbt.fromHex(signedPsbt);
113
+ },
114
+ };
115
+
116
+ const toolbox = await getUtxoToolbox(Chain.Bitcoin, { signer });
117
+
118
+ return { ...toolbox, address };
119
+ })
120
+ .with(Chain.Cosmos, async () => {
121
+ if (!(window.okxwallet && "keplr" in window.okxwallet)) {
122
+ throw new USwapError("wallet_okx_not_found", { chain: Chain.Cosmos });
123
+ }
124
+ const { keplr: wallet } = window.okxwallet;
125
+
126
+ await wallet.enable(getChainConfig(chain).chainId);
127
+ const offlineSigner = wallet.getOfflineSignerOnlyAmino(getChainConfig(chain).chainId);
128
+ const accounts = await offlineSigner.getAccounts();
129
+
130
+ // Add defensive check for accounts array
131
+ if (!(accounts && Array.isArray(accounts)) || accounts.length === 0) {
132
+ throw new USwapError("wallet_okx_no_accounts", {
133
+ chain: Chain.Cosmos,
134
+ message: "No Cosmos accounts returned from OKX Wallet",
135
+ });
136
+ }
137
+
138
+ const { getCosmosToolbox } = await import("@tcswap/toolboxes/cosmos");
139
+ const [{ address }] = accounts;
140
+ const toolbox = await getCosmosToolbox(Chain.Cosmos);
141
+
142
+ return { ...toolbox, address, transfer: cosmosTransfer(address) };
143
+ })
144
+ // INFO: OK wallet near is broken
145
+ // .with(Chain.Near, async () => {
146
+ // if (!(window.okxwallet && "near" in window.okxwallet)) {
147
+ // throw new USwapError("wallet_okx_not_found", { chain: Chain.Near });
148
+ // }
149
+
150
+ // const { createNearSignerFromProvider } = await import("../helpers/near");
151
+ // const { getNearToolbox } = await import("@tcswap/toolboxes/near");
152
+
153
+ // const provider = window.okxwallet.near;
154
+ // const signer = await createNearSignerFromProvider(provider, "OKX");
155
+ // const accountId = await signer.getAddress();
156
+ // const toolbox = await getNearToolbox({ signer });
157
+
158
+ // return { ...toolbox, address: accountId } as NearToolbox & { address: string };
159
+ // })
160
+ .with(Chain.Tron, async () => {
161
+ if (!(window.okxwallet && "tronLink" in window.okxwallet)) {
162
+ throw new USwapError("wallet_okx_not_found", { chain: Chain.Tron });
163
+ }
164
+
165
+ const { createTronToolbox } = await import("@tcswap/toolboxes/tron");
166
+
167
+ const tronLink = window.okxwallet.tronLink;
168
+
169
+ // Request account access
170
+ const accounts = await tronLink.request({ method: "tron_requestAccounts" });
171
+ if (!accounts || accounts.length === 0) {
172
+ throw new USwapError("wallet_okx_no_accounts", { chain: Chain.Tron });
173
+ }
174
+
175
+ const address = tronLink.tronWeb.defaultAddress.base58;
176
+
177
+ const signer: TronSigner = {
178
+ getAddress: async () => address,
179
+ signTransaction: async (transaction: TronTransaction) => {
180
+ return await tronLink.tronWeb.trx.sign(transaction);
181
+ },
182
+ };
183
+
184
+ const toolbox = await createTronToolbox({ signer });
185
+
186
+ return { ...toolbox, address };
187
+ })
188
+ .otherwise(() => {
189
+ throw new USwapError("wallet_okx_chain_not_supported", { chain });
190
+ })
191
+ );
192
+ }
@@ -0,0 +1,43 @@
1
+ import { Chain, filterSupportedChains, WalletOption } from "@tcswap/helpers";
2
+
3
+ import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
4
+ import { getWalletMethods } from "./helpers";
5
+
6
+ export const okxWallet = createWallet({
7
+ connect: ({ addChain, supportedChains, walletType }) =>
8
+ async function connectOkx(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
+ addChain({ ...walletMethods, chain, walletType });
15
+ }),
16
+ );
17
+
18
+ return true;
19
+ },
20
+ name: "connectOkx",
21
+ supportedChains: [
22
+ Chain.Arbitrum,
23
+ Chain.Aurora,
24
+ Chain.Avalanche,
25
+ Chain.Base,
26
+ Chain.Berachain,
27
+ Chain.BinanceSmartChain,
28
+ Chain.Bitcoin,
29
+ Chain.Cosmos,
30
+ Chain.Ethereum,
31
+ Chain.Gnosis,
32
+ Chain.Monad,
33
+ // NEAR transfer is not yet supported in OKX Wallet
34
+ // Chain.Near,
35
+ Chain.Optimism,
36
+ Chain.Polygon,
37
+ Chain.XLayer,
38
+ Chain.Tron,
39
+ ],
40
+ walletType: WalletOption.OKX,
41
+ });
42
+
43
+ export const OKX_SUPPORTED_CHAINS = getWalletSupportedChains(okxWallet);
@@ -0,0 +1,117 @@
1
+ import type { StdSignDoc } from "@cosmjs/amino";
2
+
3
+ export enum BroadcastMode {
4
+ /** Return after tx commit */
5
+ Block = "block",
6
+ /** Return after CheckTx */
7
+ Sync = "sync",
8
+ /** Return right away */
9
+ Async = "async",
10
+ }
11
+
12
+ export interface Coin {
13
+ readonly denom: string;
14
+ readonly amount: string;
15
+ }
16
+
17
+ export interface StdFee {
18
+ readonly amount: readonly Coin[];
19
+ readonly gas: string;
20
+ readonly payer?: string;
21
+ readonly granter?: string;
22
+ readonly feePayer?: string;
23
+ }
24
+
25
+ export interface Msg {
26
+ readonly type: string;
27
+ readonly value: any;
28
+ }
29
+
30
+ export interface PubKey {
31
+ readonly type: string;
32
+ readonly value: string;
33
+ }
34
+
35
+ export interface StdSignature {
36
+ readonly pub_key: PubKey;
37
+ readonly signature: string;
38
+ }
39
+
40
+ export interface StdTx {
41
+ readonly msg: readonly Msg[];
42
+ readonly fee: StdFee;
43
+ readonly signatures: readonly StdSignature[];
44
+ readonly memo: string | undefined;
45
+ }
46
+
47
+ export interface AminoSignResponse {
48
+ readonly signed: StdSignDoc;
49
+ readonly signature: StdSignature;
50
+ }
51
+
52
+ export interface SignDoc {
53
+ /**
54
+ * body_bytes is protobuf serialization of a TxBody that matches the
55
+ * representation in TxRaw.
56
+ */
57
+ bodyBytes: Uint8Array;
58
+ /**
59
+ * auth_info_bytes is a protobuf serialization of an AuthInfo that matches the
60
+ * representation in TxRaw.
61
+ */
62
+ authInfoBytes: Uint8Array;
63
+ /**
64
+ * chain_id is the unique identifier of the chain this transaction targets.
65
+ * It prevents signed transactions from being used on another chain by an
66
+ * attacker
67
+ */
68
+ chainId: string;
69
+ /** account_number is the account number of the account in state */
70
+ accountNumber: any;
71
+ }
72
+
73
+ /**
74
+ * This is the same as Algo from @cosmjs/launchpad but those might diverge in the future.
75
+ */
76
+ export type Algo = "secp256k1" | "ed25519" | "sr25519";
77
+
78
+ /**
79
+ * This is the same as AccountData from @cosmjs/launchpad but those might diverge in the future.
80
+ */
81
+ export interface AccountData {
82
+ /** A printable address (typically bech32 encoded) */
83
+ readonly address: string;
84
+ readonly algo: Algo;
85
+ readonly pubkey: Uint8Array;
86
+ }
87
+
88
+ export interface DirectSignResponse {
89
+ /**
90
+ * The sign doc that was signed.
91
+ * This may be different from the input signDoc when the signer modifies it as part of the signing process.
92
+ */
93
+ readonly signed: SignDoc;
94
+ readonly signature: StdSignature;
95
+ }
96
+
97
+ export interface OfflineDirectSigner {
98
+ readonly getAccounts: () => Promise<readonly AccountData[]>;
99
+ readonly signDirect: (signerAddress: string, signDoc: SignDoc) => Promise<DirectSignResponse>;
100
+ }
101
+
102
+ export interface OfflineAminoSigner {
103
+ /**
104
+ * Get AccountData array from wallet. Rejects if not enabled.
105
+ */
106
+ readonly getAccounts: () => Promise<readonly AccountData[]>;
107
+ /**
108
+ * Request signature from whichever key corresponds to provided bech32-encoded address. Rejects if not enabled.
109
+ *
110
+ * The signer implementation may offer the user the ability to override parts of the signDoc. It must
111
+ * return the doc that was signed in the response.
112
+ *
113
+ * @param signerAddress The address of the account that should sign the transaction
114
+ * @param signDoc The content that should be signed
115
+ */
116
+ readonly signAmino: (signerAddress: string, signDoc: StdSignDoc) => Promise<AminoSignResponse>;
117
+ }