@sodax/wallet-sdk-react 1.5.7-beta → 2.0.0-rc.10

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 (127) hide show
  1. package/README.md +107 -142
  2. package/dist/XConnector-12q0OVe5.d.ts +146 -0
  3. package/dist/chunk-7V7O3Q7Y.mjs +62 -0
  4. package/dist/chunk-C6M34IVL.mjs +86 -0
  5. package/dist/chunk-DQTYAMKF.mjs +1609 -0
  6. package/dist/chunk-FSOGMSJH.mjs +39 -0
  7. package/dist/chunk-IFXZQW4C.mjs +98 -0
  8. package/dist/chunk-JQ4H4GJ5.mjs +100 -0
  9. package/dist/chunk-LKSSME2J.mjs +31 -0
  10. package/dist/chunk-MWWVB7TD.mjs +123 -0
  11. package/dist/chunk-NAKCAL2M.mjs +32 -0
  12. package/dist/chunk-OPYSVPRW.mjs +144 -0
  13. package/dist/chunk-QMXBY3UI.mjs +1 -0
  14. package/dist/chunk-TACW7Z4D.mjs +31 -0
  15. package/dist/chunk-WPZOLGVB.mjs +148 -0
  16. package/dist/chunk-X7BHR7WS.mjs +200 -0
  17. package/dist/chunk-Z5GXDHGL.mjs +190 -0
  18. package/dist/config-DEsqgrG1.d.ts +151 -0
  19. package/dist/index.d.ts +768 -1498
  20. package/dist/index.mjs +453 -2005
  21. package/dist/xchains/bitcoin/index.d.ts +125 -0
  22. package/dist/xchains/bitcoin/index.mjs +14 -0
  23. package/dist/xchains/evm/index.d.ts +39 -0
  24. package/dist/xchains/evm/index.mjs +3 -0
  25. package/dist/xchains/icon/index.d.ts +37 -0
  26. package/dist/xchains/icon/index.mjs +5 -0
  27. package/dist/xchains/injective/index.d.ts +35 -0
  28. package/dist/xchains/injective/index.mjs +3 -0
  29. package/dist/xchains/near/index.d.ts +34 -0
  30. package/dist/xchains/near/index.mjs +4 -0
  31. package/dist/xchains/solana/index.d.ts +26 -0
  32. package/dist/xchains/solana/index.mjs +5 -0
  33. package/dist/xchains/stacks/index.d.ts +42 -0
  34. package/dist/xchains/stacks/index.mjs +3 -0
  35. package/dist/xchains/stellar/index.d.ts +44 -0
  36. package/dist/xchains/stellar/index.mjs +4 -0
  37. package/dist/xchains/sui/index.d.ts +37 -0
  38. package/dist/xchains/sui/index.mjs +5 -0
  39. package/docs/ADDING_A_NEW_CHAIN.md +440 -0
  40. package/docs/ARCHITECTURE.md +291 -0
  41. package/docs/BATCH_OPERATIONS.md +267 -0
  42. package/docs/CHAIN_DETECTION.md +216 -0
  43. package/docs/CONFIGURE_PROVIDER.md +360 -0
  44. package/docs/CONNECTORS.md +247 -0
  45. package/docs/CONNECT_FLOW.md +276 -0
  46. package/docs/EVM_SWITCH_CHAIN.md +161 -0
  47. package/docs/SIGN_MESSAGE.md +213 -0
  48. package/docs/SUB_PATH_EXPORTS.md +218 -0
  49. package/docs/WALLETCONNECT.md +154 -0
  50. package/docs/WALLET_MODAL.md +331 -0
  51. package/docs/WALLET_PROVIDER_BRIDGE.md +226 -0
  52. package/package.json +56 -22
  53. package/dist/index.cjs +0 -2147
  54. package/dist/index.cjs.map +0 -1
  55. package/dist/index.d.cts +0 -1579
  56. package/dist/index.mjs.map +0 -1
  57. package/src/Hydrate.ts +0 -65
  58. package/src/SodaxWalletProvider.tsx +0 -97
  59. package/src/actions/getXChainType.ts +0 -8
  60. package/src/actions/getXService.ts +0 -33
  61. package/src/actions/index.ts +0 -2
  62. package/src/assets/wallets/hana.svg +0 -6
  63. package/src/assets/wallets/havah.svg +0 -76
  64. package/src/assets/wallets/keplr.svg +0 -30
  65. package/src/assets/wallets/metamask.svg +0 -60
  66. package/src/assets/wallets/phantom.svg +0 -4
  67. package/src/assets/wallets/sui.svg +0 -20
  68. package/src/core/XConnector.ts +0 -54
  69. package/src/core/XService.ts +0 -85
  70. package/src/core/index.ts +0 -2
  71. package/src/hooks/index.ts +0 -11
  72. package/src/hooks/useEthereumChainId.ts +0 -44
  73. package/src/hooks/useEvmSwitchChain.ts +0 -91
  74. package/src/hooks/useWalletProvider.ts +0 -206
  75. package/src/hooks/useXAccount.ts +0 -51
  76. package/src/hooks/useXAccounts.ts +0 -56
  77. package/src/hooks/useXBalances.ts +0 -65
  78. package/src/hooks/useXConnect.ts +0 -118
  79. package/src/hooks/useXConnection.ts +0 -72
  80. package/src/hooks/useXConnectors.ts +0 -72
  81. package/src/hooks/useXDisconnect.ts +0 -73
  82. package/src/hooks/useXService.ts +0 -8
  83. package/src/hooks/useXSignMessage.ts +0 -82
  84. package/src/index.ts +0 -19
  85. package/src/types/index.ts +0 -22
  86. package/src/useXWagmiStore.ts +0 -116
  87. package/src/utils/index.ts +0 -21
  88. package/src/xchains/bitcoin/BitcoinXConnector.ts +0 -34
  89. package/src/xchains/bitcoin/BitcoinXService.ts +0 -40
  90. package/src/xchains/bitcoin/OKXXConnector.ts +0 -117
  91. package/src/xchains/bitcoin/UnisatXConnector.ts +0 -117
  92. package/src/xchains/bitcoin/XverseXConnector.ts +0 -232
  93. package/src/xchains/bitcoin/index.ts +0 -7
  94. package/src/xchains/bitcoin/useBitcoinXConnectors.ts +0 -14
  95. package/src/xchains/evm/EvmXConnector.ts +0 -27
  96. package/src/xchains/evm/EvmXService.ts +0 -211
  97. package/src/xchains/evm/index.ts +0 -3
  98. package/src/xchains/icon/IconHanaXConnector.ts +0 -39
  99. package/src/xchains/icon/IconXService.ts +0 -117
  100. package/src/xchains/icon/actions.ts +0 -28
  101. package/src/xchains/icon/iconex/index.tsx +0 -46
  102. package/src/xchains/icon/index.ts +0 -2
  103. package/src/xchains/injective/InjectiveXConnector.ts +0 -60
  104. package/src/xchains/injective/InjectiveXService.ts +0 -62
  105. package/src/xchains/injective/actions.ts +0 -32
  106. package/src/xchains/injective/index.ts +0 -2
  107. package/src/xchains/near/NearXConnector.ts +0 -42
  108. package/src/xchains/near/NearXService.ts +0 -46
  109. package/src/xchains/near/useNearXConnectors.ts +0 -23
  110. package/src/xchains/solana/SolanaXConnector.ts +0 -26
  111. package/src/xchains/solana/SolanaXService.ts +0 -46
  112. package/src/xchains/solana/index.ts +0 -2
  113. package/src/xchains/stacks/StacksXConnector.ts +0 -63
  114. package/src/xchains/stacks/StacksXService.ts +0 -59
  115. package/src/xchains/stacks/constants.ts +0 -42
  116. package/src/xchains/stacks/index.ts +0 -4
  117. package/src/xchains/stacks/useStacksXConnectors.ts +0 -7
  118. package/src/xchains/stellar/CustomSorobanServer.ts +0 -93
  119. package/src/xchains/stellar/StellarWalletsKitXConnector.ts +0 -53
  120. package/src/xchains/stellar/StellarXService.ts +0 -93
  121. package/src/xchains/stellar/actions.ts +0 -24
  122. package/src/xchains/stellar/index.tsx +0 -2
  123. package/src/xchains/stellar/useStellarXConnectors.ts +0 -21
  124. package/src/xchains/stellar/utils.ts +0 -49
  125. package/src/xchains/sui/SuiXConnector.ts +0 -28
  126. package/src/xchains/sui/SuiXService.ts +0 -66
  127. package/src/xchains/sui/index.ts +0 -2
@@ -0,0 +1,148 @@
1
+ import { assert, isRecord, hasBooleanProperty } from './chunk-TACW7Z4D.mjs';
2
+ import { WALLET_METADATA } from './chunk-NAKCAL2M.mjs';
3
+ import { isNativeToken } from './chunk-7V7O3Q7Y.mjs';
4
+ import { XService, XConnector } from './chunk-IFXZQW4C.mjs';
5
+ import * as IconSdkRaw from 'icon-sdk-js';
6
+
7
+ var IconSdk = "default" in IconSdkRaw.default ? IconSdkRaw.default : IconSdkRaw;
8
+ var { IconService: IconServiceConstructor, Builder: IconBuilder, Converter: IconConverter } = IconSdk;
9
+ var SupportedChainId = /* @__PURE__ */ ((SupportedChainId2) => {
10
+ SupportedChainId2[SupportedChainId2["MAINNET"] = 1] = "MAINNET";
11
+ return SupportedChainId2;
12
+ })(SupportedChainId || {});
13
+ var CHAIN_INFO = {
14
+ [1 /* MAINNET */]: {
15
+ name: "ICON Mainnet",
16
+ node: "https://ctz.solidwallet.io",
17
+ APIEndpoint: "https://ctz.solidwallet.io/api/v3",
18
+ debugAPIEndpoint: "https://api.icon.community/api/v3d",
19
+ chainId: 1,
20
+ tracker: "https://tracker.icon.community"
21
+ }
22
+ };
23
+ var IconXService = class _IconXService extends XService {
24
+ static instance;
25
+ iconService;
26
+ constructor(rpcUrl) {
27
+ super("ICON");
28
+ const mainnetInfo = CHAIN_INFO[1 /* MAINNET */];
29
+ if (!mainnetInfo) throw new Error("ICON mainnet chain info not found");
30
+ this.iconService = new IconServiceConstructor(
31
+ new IconServiceConstructor.HttpProvider(rpcUrl ?? mainnetInfo.APIEndpoint)
32
+ );
33
+ }
34
+ static getInstance(rpcUrl) {
35
+ if (!_IconXService.instance) {
36
+ _IconXService.instance = new _IconXService(rpcUrl);
37
+ }
38
+ return _IconXService.instance;
39
+ }
40
+ async getAggregateData(requireSuccess, calls) {
41
+ const rawTx = new IconBuilder.CallBuilder().to("cxa4aa9185e23558cff990f494c1fd2845f6cbf741").method("tryAggregate").params({ requireSuccess: IconConverter.toHex(requireSuccess ? 1 : 0), calls }).build();
42
+ try {
43
+ const result = await this.iconService.call(rawTx).execute();
44
+ const aggs = result["returnData"];
45
+ const data = aggs.map((agg) => {
46
+ if (agg["success"] === "0x0") {
47
+ return null;
48
+ }
49
+ return agg["returnData"];
50
+ });
51
+ return data;
52
+ } catch (err) {
53
+ console.error(err);
54
+ return Array(calls.length).fill(null);
55
+ }
56
+ }
57
+ async getBalances(address, xTokens) {
58
+ if (!address) return {};
59
+ const balances = {};
60
+ const nativeXToken = xTokens.find((xToken) => isNativeToken(xToken));
61
+ const nonNativeXTokens = xTokens.filter((xToken) => !isNativeToken(xToken));
62
+ if (nativeXToken) {
63
+ const balance = await this.iconService.getBalance(address).execute();
64
+ balances[nativeXToken.address] = BigInt(balance.toFixed());
65
+ }
66
+ const cds = nonNativeXTokens.map((token) => {
67
+ return {
68
+ target: token.address,
69
+ method: "balanceOf",
70
+ params: [address]
71
+ };
72
+ });
73
+ const data = await this.getAggregateData(
74
+ false,
75
+ cds.filter((cd) => cd.target.startsWith("cx"))
76
+ );
77
+ return nonNativeXTokens.reduce((agg, token, idx) => {
78
+ const balance = data[idx];
79
+ if (balance) {
80
+ balances[token.address] = BigInt(balance);
81
+ }
82
+ return agg;
83
+ }, balances);
84
+ }
85
+ };
86
+
87
+ // src/xchains/icon/iconex/index.tsx
88
+ var ICONEX_RELAY_RESPONSE = "ICONEX_RELAY_RESPONSE";
89
+ var ICONEX_RELAY_REQUEST = "ICONEX_RELAY_REQUEST";
90
+ var request = (event) => {
91
+ return new Promise((resolve, reject) => {
92
+ const handler = (evt) => {
93
+ window.removeEventListener(ICONEX_RELAY_RESPONSE, handler);
94
+ resolve(evt.detail);
95
+ };
96
+ window.addEventListener(ICONEX_RELAY_RESPONSE, handler);
97
+ window.dispatchEvent(
98
+ new CustomEvent(ICONEX_RELAY_REQUEST, {
99
+ detail: event
100
+ })
101
+ );
102
+ });
103
+ };
104
+
105
+ // src/xchains/icon/IconHanaXConnector.ts
106
+ var isHanaWallet = (value) => {
107
+ return isRecord(value) && (value.available === void 0 || hasBooleanProperty(value, "available"));
108
+ };
109
+ var IconHanaXConnector = class extends XConnector {
110
+ constructor() {
111
+ super("ICON", "Hana Wallet", "hana");
112
+ }
113
+ get isInstalled() {
114
+ if (typeof window === "undefined") return false;
115
+ const hanaWallet = window.hanaWallet;
116
+ return isHanaWallet(hanaWallet) && hanaWallet.available === true;
117
+ }
118
+ get installUrl() {
119
+ return WALLET_METADATA.hana.installUrl;
120
+ }
121
+ async connect() {
122
+ const hanaWallet = window.hanaWallet;
123
+ assert(isHanaWallet(hanaWallet) || hanaWallet === void 0, "[IconHanaXConnector] invalid window.hanaWallet type");
124
+ if (!hanaWallet || !hanaWallet.available) {
125
+ window.open(WALLET_METADATA.hana.installUrl, "_blank", "noopener,noreferrer");
126
+ return;
127
+ }
128
+ const detail = await request({
129
+ type: "REQUEST_ADDRESS" /* REQUEST_ADDRESS */
130
+ });
131
+ if (detail?.type === "RESPONSE_ADDRESS" /* RESPONSE_ADDRESS */) {
132
+ return {
133
+ address: detail?.payload,
134
+ xChainType: this.xChainType
135
+ };
136
+ }
137
+ console.warn("[IconHanaXConnector] connect: unexpected response from Hana wallet", detail);
138
+ return void 0;
139
+ }
140
+ async disconnect() {
141
+ console.log("HanaIconXConnector disconnected");
142
+ }
143
+ get icon() {
144
+ return WALLET_METADATA.hana.icon;
145
+ }
146
+ };
147
+
148
+ export { CHAIN_INFO, IconHanaXConnector, IconXService, SupportedChainId, request };
@@ -0,0 +1,200 @@
1
+ import { STELLAR_DEFAULT_HORIZON_RPC_URL, STELLAR_DEFAULT_SOROBAN_RPC_URL } from './chunk-NAKCAL2M.mjs';
2
+ import { XService, XConnector } from './chunk-IFXZQW4C.mjs';
3
+ import { StellarWalletsKit, WalletNetwork, allowAllModules } from '@creit.tech/stellar-wallets-kit';
4
+ import * as StellarSdk from '@stellar/stellar-sdk';
5
+ import { rpc, Contract, TimeoutInfinite, scValToBigInt, Address } from '@stellar/stellar-sdk';
6
+
7
+ var CustomSorobanServer = class extends rpc.Server {
8
+ customHeaders;
9
+ constructor(serverUrl, customHeaders) {
10
+ super(serverUrl, {
11
+ allowHttp: true
12
+ });
13
+ this.customHeaders = customHeaders;
14
+ }
15
+ async simulateTransaction(tx) {
16
+ const requestOptions = {
17
+ method: "POST",
18
+ headers: {
19
+ "Content-Type": "application/json",
20
+ ...this.customHeaders
21
+ },
22
+ body: JSON.stringify({
23
+ id: 1,
24
+ jsonrpc: "2.0",
25
+ method: "simulateTransaction",
26
+ params: {
27
+ transaction: tx.toXDR()
28
+ }
29
+ })
30
+ };
31
+ const response = await fetch(`${this.serverURL}`, requestOptions);
32
+ if (!response.ok) {
33
+ throw new Error(`HTTP error simulating TX! status: ${response.status}`);
34
+ }
35
+ return response.json().then((json) => rpc.parseRawSimulation(json.result));
36
+ }
37
+ async sendTransaction(tx) {
38
+ const requestOptions = {
39
+ method: "POST",
40
+ headers: {
41
+ "Content-Type": "application/json",
42
+ ...this.customHeaders
43
+ },
44
+ body: JSON.stringify({
45
+ id: 1,
46
+ jsonrpc: "2.0",
47
+ method: "sendTransaction",
48
+ params: {
49
+ transaction: tx.toXDR()
50
+ }
51
+ })
52
+ };
53
+ const response = await fetch(`${this.serverURL}`, requestOptions);
54
+ if (!response.ok) {
55
+ throw new Error(`HTTP error submitting TX! status: ${response.status}`);
56
+ }
57
+ return response.json().then((json) => json.result);
58
+ }
59
+ async getTransaction(hash) {
60
+ const requestOptions = {
61
+ method: "POST",
62
+ headers: {
63
+ "Content-Type": "application/json",
64
+ ...this.customHeaders
65
+ },
66
+ body: JSON.stringify({
67
+ id: 1,
68
+ jsonrpc: "2.0",
69
+ method: "getTransaction",
70
+ params: { hash }
71
+ })
72
+ };
73
+ const response = await fetch(`${this.serverURL}`, requestOptions);
74
+ if (!response.ok) {
75
+ throw new Error(`HTTP error getting TX! status: ${response.status}`);
76
+ }
77
+ return response.json().then((json) => json.result);
78
+ }
79
+ };
80
+ var CustomSorobanServer_default = CustomSorobanServer;
81
+ var accountToScVal = (account) => new Address(account).toScVal();
82
+ var simulateTx = (tx, server) => server.simulateTransaction(tx);
83
+ var getTokenBalance = async (address, tokenId, txBuilder, server) => {
84
+ const params = [accountToScVal(address)];
85
+ const contract = new Contract(tokenId);
86
+ const tx = txBuilder.addOperation(contract.call("balance", ...params)).setTimeout(TimeoutInfinite).build();
87
+ const result = await simulateTx(tx, server);
88
+ if (!rpc.Api.isSimulationSuccess(result)) {
89
+ throw new Error(`Simulation failed: ${JSON.stringify(result)}`);
90
+ }
91
+ return result.result ? scValToBigInt(result.result.retval) : 0n;
92
+ };
93
+
94
+ // src/xchains/stellar/StellarXService.ts
95
+ var STELLAR_BASE_RESERVE_STROOPS = 5e6;
96
+ function parseXlmBalanceToStroops(balanceStr) {
97
+ const parts = balanceStr.split(".");
98
+ const whole = parts[0] ?? "0";
99
+ const frac = (parts[1] ?? "").padEnd(7, "0").slice(0, 7);
100
+ return BigInt(whole + frac);
101
+ }
102
+ var StellarXService = class _StellarXService extends XService {
103
+ static instance;
104
+ walletsKit;
105
+ server;
106
+ sorobanServer;
107
+ constructor(horizonRpcUrl, sorobanRpcUrl) {
108
+ super("STELLAR");
109
+ this.walletsKit = new StellarWalletsKit({
110
+ network: WalletNetwork.PUBLIC,
111
+ modules: allowAllModules()
112
+ });
113
+ this.server = new StellarSdk.Horizon.Server(horizonRpcUrl ?? STELLAR_DEFAULT_HORIZON_RPC_URL, { allowHttp: true });
114
+ this.sorobanServer = new CustomSorobanServer_default(sorobanRpcUrl ?? STELLAR_DEFAULT_SOROBAN_RPC_URL, {});
115
+ }
116
+ static getInstance(horizonRpcUrl, sorobanRpcUrl) {
117
+ if (!_StellarXService.instance) {
118
+ _StellarXService.instance = new _StellarXService(horizonRpcUrl, sorobanRpcUrl);
119
+ } else {
120
+ if (horizonRpcUrl) {
121
+ _StellarXService.instance.server = new StellarSdk.Horizon.Server(horizonRpcUrl, { allowHttp: true });
122
+ }
123
+ if (sorobanRpcUrl) {
124
+ _StellarXService.instance.sorobanServer = new CustomSorobanServer_default(sorobanRpcUrl, {});
125
+ }
126
+ }
127
+ return _StellarXService.instance;
128
+ }
129
+ async getBalance(address, xToken) {
130
+ if (!address) return BigInt(0);
131
+ const stellarAccount = await this.server.loadAccount(address);
132
+ if (xToken.symbol === "XLM") {
133
+ const xlmBalance = stellarAccount.balances.find((balance) => balance.asset_type === "native");
134
+ if (xlmBalance) {
135
+ const rawBalanceStroops = parseXlmBalanceToStroops(xlmBalance.balance);
136
+ const sellingLiabilitiesStroops = xlmBalance.selling_liabilities ? parseXlmBalanceToStroops(xlmBalance.selling_liabilities) : BigInt(0);
137
+ const reserveFields = stellarAccount;
138
+ const subentryCount = reserveFields.subentry_count ?? 0;
139
+ const numSponsoring = reserveFields.num_sponsoring ?? 0;
140
+ const numSponsored = reserveFields.num_sponsored ?? 0;
141
+ const reserveCount = Math.max(0, 2 + subentryCount + numSponsoring - numSponsored);
142
+ const minBalanceStroops = BigInt(reserveCount) * BigInt(STELLAR_BASE_RESERVE_STROOPS) + sellingLiabilitiesStroops;
143
+ const availableStroops = rawBalanceStroops > minBalanceStroops ? rawBalanceStroops - minBalanceStroops : BigInt(0);
144
+ return availableStroops;
145
+ }
146
+ } else {
147
+ try {
148
+ const txBuilder = new StellarSdk.TransactionBuilder(stellarAccount, {
149
+ fee: StellarSdk.BASE_FEE,
150
+ networkPassphrase: StellarSdk.Networks.PUBLIC
151
+ });
152
+ const balance = await getTokenBalance(address, xToken.address, txBuilder, this.sorobanServer);
153
+ return balance;
154
+ } catch (e) {
155
+ console.error(`Error while fetching token on Stellar: ${xToken.symbol}, Error: ${e}`);
156
+ }
157
+ }
158
+ return BigInt(0);
159
+ }
160
+ };
161
+
162
+ // src/xchains/stellar/StellarWalletsKitXConnector.ts
163
+ var StellarWalletsKitXConnector = class extends XConnector {
164
+ _wallet;
165
+ constructor(wallet) {
166
+ super("STELLAR", wallet.name, wallet.id);
167
+ this._wallet = wallet;
168
+ }
169
+ getXService() {
170
+ return StellarXService.getInstance();
171
+ }
172
+ async connect() {
173
+ const kit = this.getXService().walletsKit;
174
+ if (!this._wallet) {
175
+ return;
176
+ }
177
+ if (!this._wallet.isAvailable) {
178
+ throw new Error(`${this._wallet.name} is not installed. Install the wallet and reload the page.`);
179
+ }
180
+ kit.setWallet(this._wallet.id);
181
+ const { address } = await kit.getAddress();
182
+ return {
183
+ address,
184
+ xChainType: this.xChainType
185
+ };
186
+ }
187
+ async disconnect() {
188
+ }
189
+ get icon() {
190
+ return this._wallet.icon;
191
+ }
192
+ get isInstalled() {
193
+ return this._wallet.isAvailable;
194
+ }
195
+ get installUrl() {
196
+ return this._wallet.url;
197
+ }
198
+ };
199
+
200
+ export { StellarWalletsKitXConnector, StellarXService };
@@ -0,0 +1,190 @@
1
+ import { getRpcUrl, getWagmiChainId, isNativeToken } from './chunk-7V7O3Q7Y.mjs';
2
+ import { XService, XConnector } from './chunk-IFXZQW4C.mjs';
3
+ import { ChainKeys } from '@sodax/types';
4
+ import { erc20Abi, defineChain } from 'viem';
5
+ import { getPublicClient } from 'wagmi/actions';
6
+ import { createConfig, createStorage, cookieStorage, http } from 'wagmi';
7
+ import { mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, lightlinkPhoenix, kaia, redbellyMainnet } from 'wagmi/chains';
8
+
9
+ var hyper = /* @__PURE__ */ defineChain({
10
+ id: 999,
11
+ name: "HyperEVM",
12
+ nativeCurrency: {
13
+ decimals: 18,
14
+ name: "HYPE",
15
+ symbol: "HYPE"
16
+ },
17
+ rpcUrls: {
18
+ default: { http: ["https://rpc.hyperliquid.xyz/evm"] }
19
+ },
20
+ blockExplorers: {
21
+ default: {
22
+ name: "HyperEVMScan",
23
+ url: "https://hyperevmscan.io/"
24
+ }
25
+ },
26
+ contracts: {
27
+ multicall3: {
28
+ address: "0xcA11bde05977b3631167028862bE2a173976CA11",
29
+ blockCreated: 13051
30
+ }
31
+ }
32
+ });
33
+ var createWagmiConfig = (evmChains, options) => {
34
+ return createConfig({
35
+ chains: [
36
+ mainnet,
37
+ avalanche,
38
+ arbitrum,
39
+ base,
40
+ bsc,
41
+ sonic,
42
+ optimism,
43
+ polygon,
44
+ hyper,
45
+ lightlinkPhoenix,
46
+ kaia,
47
+ redbellyMainnet
48
+ ],
49
+ connectors: options?.connectors ?? [],
50
+ // NOTE: wagmi's `ssr` is a hydration-timing flag, not an "is host app SSR"
51
+ // flag. `true` defers `Hydrate.onMount()` into `useEffect` (safe for both
52
+ // CSR and SSR); `false` runs it in render and trips React's "setState
53
+ // during render" warning on subscribers like `EvmHydrator`. Default to
54
+ // `true` so direct callers of `createWagmiConfig` stay safe — only pass
55
+ // `false` if you have a specific reason. See issue #129.
56
+ ssr: options?.ssr ?? true,
57
+ transports: {
58
+ [mainnet.id]: http(getRpcUrl(evmChains?.[ChainKeys.ETHEREUM_MAINNET])),
59
+ [avalanche.id]: http(getRpcUrl(evmChains?.[ChainKeys.AVALANCHE_MAINNET])),
60
+ [arbitrum.id]: http(getRpcUrl(evmChains?.[ChainKeys.ARBITRUM_MAINNET])),
61
+ [base.id]: http(getRpcUrl(evmChains?.[ChainKeys.BASE_MAINNET])),
62
+ [bsc.id]: http(getRpcUrl(evmChains?.[ChainKeys.BSC_MAINNET])),
63
+ [sonic.id]: http(getRpcUrl(evmChains?.[ChainKeys.SONIC_MAINNET])),
64
+ [optimism.id]: http(getRpcUrl(evmChains?.[ChainKeys.OPTIMISM_MAINNET])),
65
+ [polygon.id]: http(getRpcUrl(evmChains?.[ChainKeys.POLYGON_MAINNET])),
66
+ [hyper.id]: http(getRpcUrl(evmChains?.[ChainKeys.HYPEREVM_MAINNET])),
67
+ [lightlinkPhoenix.id]: http(getRpcUrl(evmChains?.[ChainKeys.LIGHTLINK_MAINNET])),
68
+ [redbellyMainnet.id]: http(getRpcUrl(evmChains?.[ChainKeys.REDBELLY_MAINNET])),
69
+ [kaia.id]: http(getRpcUrl(evmChains?.[ChainKeys.KAIA_MAINNET]))
70
+ },
71
+ storage: createStorage({
72
+ storage: cookieStorage,
73
+ key: "sodax"
74
+ })
75
+ });
76
+ };
77
+ var EvmXService = class _EvmXService extends XService {
78
+ static instance;
79
+ wagmiConfig;
80
+ constructor() {
81
+ super("EVM");
82
+ }
83
+ static getInstance() {
84
+ if (!_EvmXService.instance) {
85
+ _EvmXService.instance = new _EvmXService();
86
+ }
87
+ return _EvmXService.instance;
88
+ }
89
+ // get erc20 token balance in a chain (evm chain only)
90
+ async _getTokenBalance(address, chainId, tokenAddress) {
91
+ const publicClient = getPublicClient(this.wagmiConfig, { chainId });
92
+ if (!publicClient) throw new Error("Public client not found");
93
+ const balance = await publicClient.readContract({
94
+ abi: erc20Abi,
95
+ address: tokenAddress,
96
+ functionName: "balanceOf",
97
+ args: [address]
98
+ });
99
+ return balance || 0n;
100
+ }
101
+ //get native balance of the chain (evm chain only)
102
+ async _getChainBalance(address, chainId) {
103
+ const balance = await getPublicClient(this.wagmiConfig, { chainId })?.getBalance({
104
+ address
105
+ });
106
+ return balance || 0n;
107
+ }
108
+ async getBalance(address, xToken) {
109
+ if (!address) return 0n;
110
+ if (!this.wagmiConfig) return 0n;
111
+ const chainId = getWagmiChainId(xToken.chainKey);
112
+ if (isNativeToken(xToken)) {
113
+ return this._getChainBalance(address, chainId);
114
+ }
115
+ throw new Error(`Unsupported token: ${xToken.symbol}`);
116
+ }
117
+ async getBalances(address, xTokens) {
118
+ if (!address) return {};
119
+ if (!this.wagmiConfig) return {};
120
+ const nativeTokenBalancePromises = xTokens.filter((xToken) => isNativeToken(xToken)).map(async (xToken) => {
121
+ const balance = await this.getBalance(address, xToken);
122
+ return { symbol: xToken.symbol, address: xToken.address, balance };
123
+ });
124
+ const nativeTokenBalances = await Promise.all(nativeTokenBalancePromises);
125
+ const tokenMap = nativeTokenBalances.reduce(
126
+ (map, { address: address2, balance }) => {
127
+ if (balance) map[address2] = balance;
128
+ return map;
129
+ },
130
+ {}
131
+ );
132
+ const nonNativeXTokens = xTokens.filter((xToken) => !isNativeToken(xToken));
133
+ const firstToken = xTokens[0];
134
+ if (!firstToken) return tokenMap;
135
+ const chainKey = firstToken.chainKey;
136
+ const viemChain = this.wagmiConfig.chains.find((chain) => chain.id === getWagmiChainId(chainKey));
137
+ const chainId = getWagmiChainId(chainKey);
138
+ const publicClient = getPublicClient(this.wagmiConfig, { chainId });
139
+ if (!publicClient) throw new Error("Public client not found");
140
+ if (viemChain?.contracts?.multicall3) {
141
+ const result = await publicClient.multicall({
142
+ contracts: nonNativeXTokens.map((token) => ({
143
+ abi: erc20Abi,
144
+ address: token.address,
145
+ functionName: "balanceOf",
146
+ args: [address]
147
+ }))
148
+ });
149
+ return nonNativeXTokens.reduce((acc, token, index) => {
150
+ const resultValue = result?.[index]?.result;
151
+ acc[token.address] = resultValue !== void 0 && resultValue !== null ? BigInt(resultValue) : 0n;
152
+ return acc;
153
+ }, tokenMap);
154
+ }
155
+ const nonNativeTokenBalances = await Promise.all(
156
+ nonNativeXTokens.map((token) => this._getTokenBalance(address, chainId, token.address))
157
+ );
158
+ return nonNativeXTokens.reduce((acc, token, idx) => {
159
+ acc[token.address] = nonNativeTokenBalances[idx] ?? 0n;
160
+ return acc;
161
+ }, tokenMap);
162
+ }
163
+ };
164
+
165
+ // src/xchains/evm/EvmXConnector.ts
166
+ var WALLETCONNECT_ICON = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath fill='%233B99FC' d='M9.58 11.58c3.55-3.47 9.29-3.47 12.84 0l.43.42a.44.44 0 0 1 0 .63l-1.46 1.43a.23.23 0 0 1-.32 0l-.59-.57a6.72 6.72 0 0 0-9.36 0l-.63.61a.23.23 0 0 1-.32 0L8.71 12.7a.44.44 0 0 1 0-.63l.87-.5Zm15.87 2.95 1.3 1.28a.44.44 0 0 1 0 .63l-5.87 5.74a.46.46 0 0 1-.64 0l-4.17-4.08a.11.11 0 0 0-.16 0l-4.17 4.08a.46.46 0 0 1-.64 0l-5.87-5.74a.44.44 0 0 1 0-.63l1.3-1.28a.46.46 0 0 1 .64 0l4.17 4.08a.11.11 0 0 0 .16 0l4.17-4.08a.46.46 0 0 1 .64 0l4.17 4.08a.11.11 0 0 0 .16 0l4.17-4.08a.46.46 0 0 1 .64 0Z'/%3E%3C/svg%3E";
167
+ var EvmXConnector = class extends XConnector {
168
+ connector;
169
+ constructor(connector) {
170
+ super("EVM", connector.name, connector.id);
171
+ this.connector = connector;
172
+ }
173
+ async connect() {
174
+ return;
175
+ }
176
+ async disconnect() {
177
+ return;
178
+ }
179
+ get id() {
180
+ return this.connector.id;
181
+ }
182
+ get icon() {
183
+ if (!this.connector.icon && this.connector.type === "walletConnect") {
184
+ return WALLETCONNECT_ICON;
185
+ }
186
+ return this.connector.icon;
187
+ }
188
+ };
189
+
190
+ export { EvmXConnector, EvmXService, createWagmiConfig };
@@ -0,0 +1,151 @@
1
+ import { BitcoinRpcConfig, ChainType, EvmChainKey, SolanaChainKey, SuiChainKey, IconChainKey, NearChainKey, StellarChainKey, StellarRpcConfig, BitcoinChainKey, InjectiveChainKey, InjectiveRpcConfig, StacksChainKey, StacksNetworkName, StacksNetworkLike, ChainKey, baseChainInfo } from '@sodax/types';
2
+ import { BitcoinWalletDefaults, EvmWalletDefaults, SolanaWalletDefaults, SuiWalletDefaults, IconWalletDefaults, NearWalletDefaults, StellarWalletDefaults, InjectiveWalletDefaults, StacksWalletDefaults } from '@sodax/wallet-sdk-core';
3
+ import { State } from 'wagmi';
4
+ import { WalletConnectParameters } from 'wagmi/connectors';
5
+ import { I as IXConnector } from './XConnector-12q0OVe5.js';
6
+
7
+ type SimpleChainEntry<D> = {
8
+ rpcUrl?: string;
9
+ defaults?: D;
10
+ };
11
+ type EvmChainEntry = SimpleChainEntry<EvmWalletDefaults>;
12
+ type SolanaChainEntry = SimpleChainEntry<SolanaWalletDefaults>;
13
+ type SuiChainEntry = SimpleChainEntry<SuiWalletDefaults>;
14
+ type IconChainEntry = SimpleChainEntry<IconWalletDefaults>;
15
+ type NearChainEntry = SimpleChainEntry<NearWalletDefaults>;
16
+ type StellarChainEntry = StellarRpcConfig & {
17
+ defaults?: StellarWalletDefaults;
18
+ };
19
+ type BitcoinChainEntry = BitcoinRpcConfig & {
20
+ defaults?: BitcoinWalletDefaults;
21
+ };
22
+ type InjectiveChainEntry = InjectiveRpcConfig & {
23
+ defaults?: InjectiveWalletDefaults;
24
+ };
25
+ type StacksChainEntry = StacksNetworkName | (StacksNetworkLike & {
26
+ defaults?: StacksWalletDefaults;
27
+ });
28
+ /** Wagmi-config-level settings shared across all configured EVM chains. */
29
+ type EvmAdapterFields = {
30
+ /** Attempt to reconnect previously connected wallets on mount. @default false */
31
+ reconnectOnMount?: boolean;
32
+ /**
33
+ * wagmi hydration-timing flag (not an "app is SSR" flag).
34
+ * `true` defers wagmi reconnect into `useEffect`; `false` runs it in render
35
+ * and triggers React's "setState during render" warning. Keep `true` unless
36
+ * you know you need otherwise. @default true
37
+ */
38
+ ssr?: boolean;
39
+ /** Wagmi SSR hydration state — pass `cookieToInitialState()` to avoid disconnect flash on first load (Next.js only). */
40
+ initialState?: State;
41
+ /** WalletConnect configuration. Adds a WalletConnect connector when provided. */
42
+ walletConnect?: WalletConnectParameters;
43
+ };
44
+ /** `@solana/wallet-adapter-react` provider settings. */
45
+ type SolanaAdapterFields = {
46
+ /** Auto-connect previously connected Solana wallet on mount. @default true */
47
+ autoConnect?: boolean;
48
+ };
49
+ /** `@mysten/dapp-kit` provider settings. */
50
+ type SuiAdapterFields = {
51
+ autoConnect?: boolean;
52
+ /** Default network for the SuiClientProvider. @default 'mainnet' */
53
+ network?: 'mainnet' | 'testnet' | 'devnet';
54
+ };
55
+ /**
56
+ * Per-chain-type metadata — the only place that needs editing when adding a
57
+ * new chain type. Keys must match `ChainType`.
58
+ */
59
+ type ChainMeta = {
60
+ EVM: {
61
+ keys: EvmChainKey;
62
+ entry: EvmChainEntry;
63
+ defaults: EvmWalletDefaults;
64
+ adapter: EvmAdapterFields;
65
+ };
66
+ SOLANA: {
67
+ keys: SolanaChainKey;
68
+ entry: SolanaChainEntry;
69
+ defaults: SolanaWalletDefaults;
70
+ adapter: SolanaAdapterFields;
71
+ };
72
+ SUI: {
73
+ keys: SuiChainKey;
74
+ entry: SuiChainEntry;
75
+ defaults: SuiWalletDefaults;
76
+ adapter: SuiAdapterFields;
77
+ };
78
+ ICON: {
79
+ keys: IconChainKey;
80
+ entry: IconChainEntry;
81
+ defaults: IconWalletDefaults;
82
+ adapter: {};
83
+ };
84
+ NEAR: {
85
+ keys: NearChainKey;
86
+ entry: NearChainEntry;
87
+ defaults: NearWalletDefaults;
88
+ adapter: {};
89
+ };
90
+ STELLAR: {
91
+ keys: StellarChainKey;
92
+ entry: StellarChainEntry;
93
+ defaults: StellarWalletDefaults;
94
+ adapter: {};
95
+ };
96
+ BITCOIN: {
97
+ keys: BitcoinChainKey;
98
+ entry: BitcoinChainEntry;
99
+ defaults: BitcoinWalletDefaults;
100
+ adapter: {};
101
+ };
102
+ INJECTIVE: {
103
+ keys: InjectiveChainKey;
104
+ entry: InjectiveChainEntry;
105
+ defaults: InjectiveWalletDefaults;
106
+ adapter: {};
107
+ };
108
+ STACKS: {
109
+ keys: StacksChainKey;
110
+ entry: StacksChainEntry;
111
+ defaults: StacksWalletDefaults;
112
+ adapter: {};
113
+ };
114
+ };
115
+ /** Resolves a `ChainKey` to its `ChainType` via the runtime `baseChainInfo` map. */
116
+ type ChainTypeOf<K extends ChainKey> = (typeof baseChainInfo)[K]['type'];
117
+ /**
118
+ * Flatten `A & B` into a single object type so TypeScript runs excess-property
119
+ * checks against the merged shape. Intersection types skip EPC, which lets
120
+ * unknown fields like `rpcUrl` slip into the EVM slot silently — flattening
121
+ * forces the check to fire on object literals.
122
+ */
123
+ type Merge<A, B> = {
124
+ [K in keyof (A & B)]: (A & B)[K];
125
+ };
126
+ /** Per-chain-type slot shape — adapter fields + nested chain entries map. */
127
+ type ChainTypeConfig<T extends ChainType> = Merge<ChainMeta[T]['adapter'], {
128
+ /** Optional connector overrides. If omitted, uses defaults from chainRegistry. */
129
+ connectors?: IXConnector[];
130
+ /** Per-chain-key entries — chain-specific RPC + wallet provider defaults. */
131
+ chains?: Partial<Record<ChainMeta[T]['keys'], ChainMeta[T]['entry']>>;
132
+ }>;
133
+ /** Per-chain-key entry shape — narrows by chain key via `baseChainInfo` lookup. */
134
+ type ChainEntry<K extends ChainKey = ChainKey> = ChainMeta[ChainTypeOf<K>]['entry'];
135
+ /** Wallet provider defaults shape for a given chain key. */
136
+ type WalletDefaultsByKey<K extends ChainKey> = ChainMeta[ChainTypeOf<K>]['defaults'];
137
+ type EvmTypeConfig = ChainTypeConfig<'EVM'>;
138
+ type SolanaTypeConfig = ChainTypeConfig<'SOLANA'>;
139
+ type SuiTypeConfig = ChainTypeConfig<'SUI'>;
140
+ type BitcoinTypeConfig = ChainTypeConfig<'BITCOIN'>;
141
+ type StellarTypeConfig = ChainTypeConfig<'STELLAR'>;
142
+ type InjectiveTypeConfig = ChainTypeConfig<'INJECTIVE'>;
143
+ type IconTypeConfig = ChainTypeConfig<'ICON'>;
144
+ type NearTypeConfig = ChainTypeConfig<'NEAR'>;
145
+ type StacksTypeConfig = ChainTypeConfig<'STACKS'>;
146
+ /** Top-level config for `<SodaxWalletProvider>`. Omitted chain-type slots are not mounted. */
147
+ type SodaxWalletConfig = {
148
+ [T in ChainType]?: ChainTypeConfig<T>;
149
+ };
150
+
151
+ export type { BitcoinChainEntry as B, ChainEntry as C, EvmAdapterFields as E, IconChainEntry as I, NearChainEntry as N, SodaxWalletConfig as S, WalletDefaultsByKey as W, BitcoinTypeConfig as a, ChainMeta as b, ChainTypeConfig as c, ChainTypeOf as d, EvmChainEntry as e, EvmTypeConfig as f, IconTypeConfig as g, InjectiveChainEntry as h, InjectiveTypeConfig as i, NearTypeConfig as j, SolanaAdapterFields as k, SolanaChainEntry as l, SolanaTypeConfig as m, StacksChainEntry as n, StacksTypeConfig as o, StellarChainEntry as p, StellarTypeConfig as q, SuiAdapterFields as r, SuiChainEntry as s, SuiTypeConfig as t };