@sodax/wallet-sdk-react 1.5.7-beta → 2.0.0-rc.1
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/README.md +103 -145
- package/ai-exported/AGENTS.md +122 -0
- package/ai-exported/integration/README.md +102 -0
- package/ai-exported/integration/ai-rules.md +136 -0
- package/ai-exported/integration/architecture.md +181 -0
- package/ai-exported/integration/examples/01-minimal-evm.tsx +75 -0
- package/ai-exported/integration/examples/02-multi-chain-modal.tsx +169 -0
- package/ai-exported/integration/examples/03-nextjs-app-router.tsx +99 -0
- package/ai-exported/integration/examples/04-walletconnect-setup.tsx +89 -0
- package/ai-exported/integration/examples/README.md +29 -0
- package/ai-exported/integration/recipes/batch-operations.md +223 -0
- package/ai-exported/integration/recipes/bridge-to-sdk.md +164 -0
- package/ai-exported/integration/recipes/chain-detection.md +254 -0
- package/ai-exported/integration/recipes/connect-button.md +156 -0
- package/ai-exported/integration/recipes/multi-chain-modal.md +199 -0
- package/ai-exported/integration/recipes/setup.md +158 -0
- package/ai-exported/integration/recipes/sign-message.md +137 -0
- package/ai-exported/integration/recipes/sub-path-imports.md +95 -0
- package/ai-exported/integration/recipes/switch-chain.md +141 -0
- package/ai-exported/integration/recipes/walletconnect-setup.md +139 -0
- package/ai-exported/integration/reference/api-surface.md +175 -0
- package/ai-exported/integration/reference/chain-support.md +78 -0
- package/ai-exported/integration/reference/connectors.md +74 -0
- package/ai-exported/integration/reference/hooks.md +204 -0
- package/ai-exported/integration/reference/wallet-brands.md +106 -0
- package/ai-exported/migration/README.md +49 -0
- package/ai-exported/migration/ai-rules.md +144 -0
- package/ai-exported/migration/breaking-changes.md +305 -0
- package/ai-exported/migration/checklist.md +159 -0
- package/ai-exported/migration/recipes/connect-button.md +166 -0
- package/ai-exported/migration/recipes/multi-chain-modal.md +244 -0
- package/ai-exported/migration/recipes/ssr-setup.md +162 -0
- package/ai-exported/migration/recipes/walletconnect-migration.md +168 -0
- package/ai-exported/migration/reference/components.md +73 -0
- package/ai-exported/migration/reference/config.md +307 -0
- package/ai-exported/migration/reference/hooks.md +278 -0
- package/ai-exported/migration/reference/imports.md +157 -0
- package/dist/XConnector-B9YQTVJ4.d.ts +146 -0
- package/dist/chunk-2BOUGCJ7.mjs +150 -0
- package/dist/chunk-2BOUGCJ7.mjs.map +1 -0
- package/dist/chunk-66BAUK56.mjs +202 -0
- package/dist/chunk-66BAUK56.mjs.map +1 -0
- package/dist/chunk-7ULB6DW4.mjs +102 -0
- package/dist/chunk-7ULB6DW4.mjs.map +1 -0
- package/dist/chunk-BKJB527E.mjs +125 -0
- package/dist/chunk-BKJB527E.mjs.map +1 -0
- package/dist/chunk-BXJLBR4G.mjs +88 -0
- package/dist/chunk-BXJLBR4G.mjs.map +1 -0
- package/dist/chunk-E5IAZ7E6.mjs +186 -0
- package/dist/chunk-E5IAZ7E6.mjs.map +1 -0
- package/dist/chunk-MAQ47Q52.mjs +33 -0
- package/dist/chunk-MAQ47Q52.mjs.map +1 -0
- package/dist/chunk-MXZVF5HR.mjs +34 -0
- package/dist/chunk-MXZVF5HR.mjs.map +1 -0
- package/dist/chunk-N5A2TMF6.mjs +33 -0
- package/dist/chunk-N5A2TMF6.mjs.map +1 -0
- package/dist/chunk-NY7U7OJW.mjs +64 -0
- package/dist/chunk-NY7U7OJW.mjs.map +1 -0
- package/dist/chunk-PJLEJVAU.mjs +140 -0
- package/dist/chunk-PJLEJVAU.mjs.map +1 -0
- package/dist/chunk-PLCA4ZDJ.mjs +1585 -0
- package/dist/chunk-PLCA4ZDJ.mjs.map +1 -0
- package/dist/chunk-TZMKDXFA.mjs +3 -0
- package/dist/chunk-TZMKDXFA.mjs.map +1 -0
- package/dist/chunk-X2MHIWXO.mjs +100 -0
- package/dist/chunk-X2MHIWXO.mjs.map +1 -0
- package/dist/chunk-XZ7CHO2S.mjs +41 -0
- package/dist/chunk-XZ7CHO2S.mjs.map +1 -0
- package/dist/config-OlnzyEUE.d.ts +146 -0
- package/dist/index.cjs +2784 -1594
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +768 -1498
- package/dist/index.mjs +463 -2004
- package/dist/index.mjs.map +1 -1
- package/dist/xchains/bitcoin/index.cjs +1927 -0
- package/dist/xchains/bitcoin/index.cjs.map +1 -0
- package/dist/xchains/bitcoin/index.d.ts +125 -0
- package/dist/xchains/bitcoin/index.mjs +16 -0
- package/dist/xchains/bitcoin/index.mjs.map +1 -0
- package/dist/xchains/evm/index.cjs +316 -0
- package/dist/xchains/evm/index.cjs.map +1 -0
- package/dist/xchains/evm/index.d.ts +39 -0
- package/dist/xchains/evm/index.mjs +5 -0
- package/dist/xchains/evm/index.mjs.map +1 -0
- package/dist/xchains/icon/index.cjs +311 -0
- package/dist/xchains/icon/index.cjs.map +1 -0
- package/dist/xchains/icon/index.d.ts +37 -0
- package/dist/xchains/icon/index.mjs +7 -0
- package/dist/xchains/icon/index.mjs.map +1 -0
- package/dist/xchains/injective/index.cjs +223 -0
- package/dist/xchains/injective/index.cjs.map +1 -0
- package/dist/xchains/injective/index.d.ts +35 -0
- package/dist/xchains/injective/index.mjs +5 -0
- package/dist/xchains/injective/index.mjs.map +1 -0
- package/dist/xchains/near/index.cjs +190 -0
- package/dist/xchains/near/index.cjs.map +1 -0
- package/dist/xchains/near/index.d.ts +34 -0
- package/dist/xchains/near/index.mjs +6 -0
- package/dist/xchains/near/index.mjs.map +1 -0
- package/dist/xchains/solana/index.cjs +186 -0
- package/dist/xchains/solana/index.cjs.map +1 -0
- package/dist/xchains/solana/index.d.ts +26 -0
- package/dist/xchains/solana/index.mjs +7 -0
- package/dist/xchains/solana/index.mjs.map +1 -0
- package/dist/xchains/stacks/index.cjs +240 -0
- package/dist/xchains/stacks/index.cjs.map +1 -0
- package/dist/xchains/stacks/index.d.ts +36 -0
- package/dist/xchains/stacks/index.mjs +5 -0
- package/dist/xchains/stacks/index.mjs.map +1 -0
- package/dist/xchains/stellar/index.cjs +322 -0
- package/dist/xchains/stellar/index.cjs.map +1 -0
- package/dist/xchains/stellar/index.d.ts +44 -0
- package/dist/xchains/stellar/index.mjs +6 -0
- package/dist/xchains/stellar/index.mjs.map +1 -0
- package/dist/xchains/sui/index.cjs +248 -0
- package/dist/xchains/sui/index.cjs.map +1 -0
- package/dist/xchains/sui/index.d.ts +37 -0
- package/dist/xchains/sui/index.mjs +7 -0
- package/dist/xchains/sui/index.mjs.map +1 -0
- package/docs/ADDING_A_NEW_CHAIN.md +440 -0
- package/docs/ARCHITECTURE.md +291 -0
- package/docs/BATCH_OPERATIONS.md +267 -0
- package/docs/CHAIN_DETECTION.md +216 -0
- package/docs/CONFIGURE_PROVIDER.md +360 -0
- package/docs/CONNECTORS.md +247 -0
- package/docs/CONNECT_FLOW.md +276 -0
- package/docs/EVM_SWITCH_CHAIN.md +161 -0
- package/docs/SIGN_MESSAGE.md +213 -0
- package/docs/SUB_PATH_EXPORTS.md +246 -0
- package/docs/WALLETCONNECT.md +154 -0
- package/docs/WALLET_MODAL.md +331 -0
- package/docs/WALLET_PROVIDER_BRIDGE.md +226 -0
- package/package.json +34 -9
- package/skills/SKILLS.md +84 -0
- package/skills/bridge-to-sdk.md +148 -0
- package/skills/connect-button.md +116 -0
- package/skills/evm-only-walletconnect.md +111 -0
- package/skills/multi-chain-modal.md +178 -0
- package/skills/setup.md +107 -0
- package/dist/index.d.cts +0 -1579
- package/src/Hydrate.ts +0 -65
- package/src/SodaxWalletProvider.tsx +0 -97
- package/src/actions/getXChainType.ts +0 -8
- package/src/actions/getXService.ts +0 -33
- package/src/actions/index.ts +0 -2
- package/src/assets/wallets/hana.svg +0 -6
- package/src/assets/wallets/havah.svg +0 -76
- package/src/assets/wallets/keplr.svg +0 -30
- package/src/assets/wallets/metamask.svg +0 -60
- package/src/assets/wallets/phantom.svg +0 -4
- package/src/assets/wallets/sui.svg +0 -20
- package/src/core/XConnector.ts +0 -54
- package/src/core/XService.ts +0 -85
- package/src/core/index.ts +0 -2
- package/src/hooks/index.ts +0 -11
- package/src/hooks/useEthereumChainId.ts +0 -44
- package/src/hooks/useEvmSwitchChain.ts +0 -91
- package/src/hooks/useWalletProvider.ts +0 -206
- package/src/hooks/useXAccount.ts +0 -51
- package/src/hooks/useXAccounts.ts +0 -56
- package/src/hooks/useXBalances.ts +0 -65
- package/src/hooks/useXConnect.ts +0 -118
- package/src/hooks/useXConnection.ts +0 -72
- package/src/hooks/useXConnectors.ts +0 -72
- package/src/hooks/useXDisconnect.ts +0 -73
- package/src/hooks/useXService.ts +0 -8
- package/src/hooks/useXSignMessage.ts +0 -82
- package/src/index.ts +0 -19
- package/src/types/index.ts +0 -22
- package/src/useXWagmiStore.ts +0 -116
- package/src/utils/index.ts +0 -21
- package/src/xchains/bitcoin/BitcoinXConnector.ts +0 -34
- package/src/xchains/bitcoin/BitcoinXService.ts +0 -40
- package/src/xchains/bitcoin/OKXXConnector.ts +0 -117
- package/src/xchains/bitcoin/UnisatXConnector.ts +0 -117
- package/src/xchains/bitcoin/XverseXConnector.ts +0 -232
- package/src/xchains/bitcoin/index.ts +0 -7
- package/src/xchains/bitcoin/useBitcoinXConnectors.ts +0 -14
- package/src/xchains/evm/EvmXConnector.ts +0 -27
- package/src/xchains/evm/EvmXService.ts +0 -211
- package/src/xchains/evm/index.ts +0 -3
- package/src/xchains/icon/IconHanaXConnector.ts +0 -39
- package/src/xchains/icon/IconXService.ts +0 -117
- package/src/xchains/icon/actions.ts +0 -28
- package/src/xchains/icon/iconex/index.tsx +0 -46
- package/src/xchains/icon/index.ts +0 -2
- package/src/xchains/injective/InjectiveXConnector.ts +0 -60
- package/src/xchains/injective/InjectiveXService.ts +0 -62
- package/src/xchains/injective/actions.ts +0 -32
- package/src/xchains/injective/index.ts +0 -2
- package/src/xchains/near/NearXConnector.ts +0 -42
- package/src/xchains/near/NearXService.ts +0 -46
- package/src/xchains/near/useNearXConnectors.ts +0 -23
- package/src/xchains/solana/SolanaXConnector.ts +0 -26
- package/src/xchains/solana/SolanaXService.ts +0 -46
- package/src/xchains/solana/index.ts +0 -2
- package/src/xchains/stacks/StacksXConnector.ts +0 -63
- package/src/xchains/stacks/StacksXService.ts +0 -59
- package/src/xchains/stacks/constants.ts +0 -42
- package/src/xchains/stacks/index.ts +0 -4
- package/src/xchains/stacks/useStacksXConnectors.ts +0 -7
- package/src/xchains/stellar/CustomSorobanServer.ts +0 -93
- package/src/xchains/stellar/StellarWalletsKitXConnector.ts +0 -53
- package/src/xchains/stellar/StellarXService.ts +0 -93
- package/src/xchains/stellar/actions.ts +0 -24
- package/src/xchains/stellar/index.tsx +0 -2
- package/src/xchains/stellar/useStellarXConnectors.ts +0 -21
- package/src/xchains/stellar/utils.ts +0 -49
- package/src/xchains/sui/SuiXConnector.ts +0 -28
- package/src/xchains/sui/SuiXService.ts +0 -66
- package/src/xchains/sui/index.ts +0 -2
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { XService } from '@/core/XService';
|
|
2
|
-
import {
|
|
3
|
-
ARBITRUM_MAINNET_CHAIN_ID,
|
|
4
|
-
AVALANCHE_MAINNET_CHAIN_ID,
|
|
5
|
-
BASE_MAINNET_CHAIN_ID,
|
|
6
|
-
BSC_MAINNET_CHAIN_ID,
|
|
7
|
-
ETHEREUM_MAINNET_CHAIN_ID,
|
|
8
|
-
HYPEREVM_MAINNET_CHAIN_ID,
|
|
9
|
-
KAIA_MAINNET_CHAIN_ID,
|
|
10
|
-
LIGHTLINK_MAINNET_CHAIN_ID,
|
|
11
|
-
OPTIMISM_MAINNET_CHAIN_ID,
|
|
12
|
-
POLYGON_MAINNET_CHAIN_ID,
|
|
13
|
-
REDBELLY_MAINNET_CHAIN_ID,
|
|
14
|
-
SONIC_MAINNET_CHAIN_ID,
|
|
15
|
-
type RpcConfig,
|
|
16
|
-
type XToken,
|
|
17
|
-
} from '@sodax/types';
|
|
18
|
-
import { getWagmiChainId, isNativeToken } from '@/utils';
|
|
19
|
-
|
|
20
|
-
import { type Address, type Chain, defineChain, erc20Abi } from 'viem';
|
|
21
|
-
import { getPublicClient } from 'wagmi/actions';
|
|
22
|
-
import { type Config, createConfig, http, createStorage, cookieStorage } from 'wagmi';
|
|
23
|
-
import {
|
|
24
|
-
mainnet,
|
|
25
|
-
avalanche,
|
|
26
|
-
base,
|
|
27
|
-
optimism,
|
|
28
|
-
polygon,
|
|
29
|
-
arbitrum,
|
|
30
|
-
bsc,
|
|
31
|
-
sonic,
|
|
32
|
-
lightlinkPhoenix,
|
|
33
|
-
redbellyMainnet,
|
|
34
|
-
kaia,
|
|
35
|
-
} from 'wagmi/chains';
|
|
36
|
-
import type { WagmiOptions } from '@/SodaxWalletProvider';
|
|
37
|
-
|
|
38
|
-
// HyperEVM chain is not supported by viem, so we need to define it manually
|
|
39
|
-
export const hyper = /*#__PURE__*/ defineChain({
|
|
40
|
-
id: 999,
|
|
41
|
-
name: 'HyperEVM',
|
|
42
|
-
nativeCurrency: {
|
|
43
|
-
decimals: 18,
|
|
44
|
-
name: 'HYPE',
|
|
45
|
-
symbol: 'HYPE',
|
|
46
|
-
},
|
|
47
|
-
rpcUrls: {
|
|
48
|
-
default: { http: ['https://rpc.hyperliquid.xyz/evm'] },
|
|
49
|
-
},
|
|
50
|
-
blockExplorers: {
|
|
51
|
-
default: {
|
|
52
|
-
name: 'HyperEVMScan',
|
|
53
|
-
url: 'https://hyperevmscan.io/',
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
contracts: {
|
|
57
|
-
multicall3: {
|
|
58
|
-
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
59
|
-
blockCreated: 13051,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
export const createWagmiConfig = (config: RpcConfig, options?: WagmiOptions) => {
|
|
65
|
-
return createConfig({
|
|
66
|
-
chains: [
|
|
67
|
-
mainnet,
|
|
68
|
-
avalanche,
|
|
69
|
-
arbitrum,
|
|
70
|
-
base,
|
|
71
|
-
bsc,
|
|
72
|
-
sonic,
|
|
73
|
-
optimism,
|
|
74
|
-
polygon,
|
|
75
|
-
hyper,
|
|
76
|
-
lightlinkPhoenix,
|
|
77
|
-
kaia,
|
|
78
|
-
redbellyMainnet,
|
|
79
|
-
],
|
|
80
|
-
ssr: options?.ssr,
|
|
81
|
-
transports: {
|
|
82
|
-
[mainnet.id]: http(config[ETHEREUM_MAINNET_CHAIN_ID]),
|
|
83
|
-
[avalanche.id]: http(config[AVALANCHE_MAINNET_CHAIN_ID]),
|
|
84
|
-
[arbitrum.id]: http(config[ARBITRUM_MAINNET_CHAIN_ID]),
|
|
85
|
-
[base.id]: http(config[BASE_MAINNET_CHAIN_ID]),
|
|
86
|
-
[bsc.id]: http(config[BSC_MAINNET_CHAIN_ID]),
|
|
87
|
-
[sonic.id]: http(config[SONIC_MAINNET_CHAIN_ID]),
|
|
88
|
-
[optimism.id]: http(config[OPTIMISM_MAINNET_CHAIN_ID]),
|
|
89
|
-
[polygon.id]: http(config[POLYGON_MAINNET_CHAIN_ID]),
|
|
90
|
-
[hyper.id]: http(config[HYPEREVM_MAINNET_CHAIN_ID]),
|
|
91
|
-
[lightlinkPhoenix.id]: http(config[LIGHTLINK_MAINNET_CHAIN_ID]),
|
|
92
|
-
[redbellyMainnet.id]: http(config[REDBELLY_MAINNET_CHAIN_ID]),
|
|
93
|
-
[kaia.id]: http(config[KAIA_MAINNET_CHAIN_ID]),
|
|
94
|
-
},
|
|
95
|
-
storage: createStorage({
|
|
96
|
-
storage: cookieStorage,
|
|
97
|
-
key: 'sodax',
|
|
98
|
-
}),
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Service class for handling EVM chain interactions.
|
|
104
|
-
* Implements singleton pattern and provides methods for wallet/chain operations.
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
export class EvmXService extends XService {
|
|
108
|
-
private static instance: EvmXService;
|
|
109
|
-
public wagmiConfig: Config | undefined;
|
|
110
|
-
|
|
111
|
-
private constructor() {
|
|
112
|
-
super('EVM');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
getXConnectors() {
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public static getInstance(): EvmXService {
|
|
120
|
-
if (!EvmXService.instance) {
|
|
121
|
-
EvmXService.instance = new EvmXService();
|
|
122
|
-
}
|
|
123
|
-
return EvmXService.instance;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// get erc20 token balance in a chain (evm chain only)
|
|
127
|
-
async _getTokenBalance(address: string | undefined, chainId: number, tokenAddress: string): Promise<bigint> {
|
|
128
|
-
const publicClient = getPublicClient(this.wagmiConfig as Config, { chainId: chainId });
|
|
129
|
-
if (!publicClient) throw new Error('Public client not found');
|
|
130
|
-
const balance = await publicClient.readContract({
|
|
131
|
-
abi: erc20Abi,
|
|
132
|
-
address: tokenAddress as `0x${string}`,
|
|
133
|
-
functionName: 'balanceOf',
|
|
134
|
-
args: [address as `0x${string}`],
|
|
135
|
-
});
|
|
136
|
-
return balance || 0n;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//get native balance of the chain (evm chain only)
|
|
140
|
-
async _getChainBalance(address: string | undefined, chainId: number) {
|
|
141
|
-
const balance = await getPublicClient(this.wagmiConfig as Config, { chainId: chainId })?.getBalance({
|
|
142
|
-
address: address as Address,
|
|
143
|
-
});
|
|
144
|
-
return balance || 0n;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {
|
|
148
|
-
if (!address) return 0n;
|
|
149
|
-
if (!this.wagmiConfig) return 0n;
|
|
150
|
-
|
|
151
|
-
const chainId = getWagmiChainId(xToken.xChainId);
|
|
152
|
-
|
|
153
|
-
if (isNativeToken(xToken)) {
|
|
154
|
-
return this._getChainBalance(address, chainId);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
throw new Error(`Unsupported token: ${xToken.symbol}`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async getBalances(address: string | undefined, xTokens: XToken[]) {
|
|
161
|
-
if (!address) return {};
|
|
162
|
-
if (!this.wagmiConfig) return {};
|
|
163
|
-
|
|
164
|
-
const nativeTokenBalancePromises = xTokens
|
|
165
|
-
.filter(xToken => isNativeToken(xToken))
|
|
166
|
-
.map(async xToken => {
|
|
167
|
-
const balance = await this.getBalance(address, xToken);
|
|
168
|
-
return { symbol: xToken.symbol, address: xToken.address, balance };
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const nativeTokenBalances = await Promise.all(nativeTokenBalancePromises);
|
|
172
|
-
const tokenMap = nativeTokenBalances.reduce((map, { address, balance }) => {
|
|
173
|
-
if (balance) map[address] = balance;
|
|
174
|
-
return map;
|
|
175
|
-
}, {});
|
|
176
|
-
|
|
177
|
-
const nonNativeXTokens = xTokens.filter(xToken => !isNativeToken(xToken));
|
|
178
|
-
const xChainId = xTokens[0].xChainId;
|
|
179
|
-
const viemChain: Chain = this.wagmiConfig.chains.find(chain => chain.id === getWagmiChainId(xChainId)) as Chain;
|
|
180
|
-
const chainId = getWagmiChainId(xChainId);
|
|
181
|
-
|
|
182
|
-
const publicClient = getPublicClient(this.wagmiConfig, { chainId: chainId });
|
|
183
|
-
if (!publicClient) throw new Error('Public client not found');
|
|
184
|
-
|
|
185
|
-
if (viemChain?.contracts?.multicall3) {
|
|
186
|
-
//multicall supports
|
|
187
|
-
const result = await publicClient.multicall({
|
|
188
|
-
contracts: nonNativeXTokens.map(token => ({
|
|
189
|
-
abi: erc20Abi,
|
|
190
|
-
address: token.address as `0x${string}`,
|
|
191
|
-
functionName: 'balanceOf',
|
|
192
|
-
args: [address],
|
|
193
|
-
})),
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
return nonNativeXTokens.reduce((acc, token, index) => {
|
|
197
|
-
acc[token.address] = result?.[index]?.result?.toString() || '0';
|
|
198
|
-
return acc;
|
|
199
|
-
}, tokenMap);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const nonNativeTokenBalances: bigint[] = await Promise.all(
|
|
203
|
-
nonNativeXTokens.map(token => this._getTokenBalance(address, chainId, token.address)),
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
return nonNativeXTokens.reduce((acc, token, idx) => {
|
|
207
|
-
acc[token.address] = nonNativeTokenBalances[idx] || '0';
|
|
208
|
-
return acc;
|
|
209
|
-
}, tokenMap);
|
|
210
|
-
}
|
|
211
|
-
}
|
package/src/xchains/evm/index.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
import { ICONexRequestEventType, ICONexResponseEventType, request } from './iconex';
|
|
3
|
-
|
|
4
|
-
import { XConnector } from '@/core/XConnector';
|
|
5
|
-
|
|
6
|
-
export class IconHanaXConnector extends XConnector {
|
|
7
|
-
constructor() {
|
|
8
|
-
super('ICON', 'Hana Wallet', 'hana');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async connect(): Promise<XAccount | undefined> {
|
|
12
|
-
const { hanaWallet } = window as any;
|
|
13
|
-
if (window && !hanaWallet && !hanaWallet?.isAvailable) {
|
|
14
|
-
window.open('https://chromewebstore.google.com/detail/hana-wallet/jfdlamikmbghhapbgfoogdffldioobgl', '_blank');
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const detail = await request({
|
|
19
|
-
type: ICONexRequestEventType.REQUEST_ADDRESS,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
if (detail?.type === ICONexResponseEventType.RESPONSE_ADDRESS) {
|
|
23
|
-
return {
|
|
24
|
-
address: detail?.payload,
|
|
25
|
-
xChainType: this.xChainType,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async disconnect(): Promise<void> {
|
|
33
|
-
console.log('HanaIconXConnector disconnected');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public get icon() {
|
|
37
|
-
return 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/hana.svg';
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { XService } from '@/core/XService';
|
|
2
|
-
import type { IconService } from 'icon-sdk-js';
|
|
3
|
-
import * as IconSdkRaw from 'icon-sdk-js';
|
|
4
|
-
import type { XToken } from '@sodax/types';
|
|
5
|
-
import { isNativeToken } from '@/utils';
|
|
6
|
-
|
|
7
|
-
const IconSdk = ('default' in IconSdkRaw.default ? IconSdkRaw.default : IconSdkRaw) as typeof IconSdkRaw;
|
|
8
|
-
const { IconService: IconServiceConstructor, Builder: IconBuilder, Converter: IconConverter } = IconSdk;
|
|
9
|
-
export interface CallData {
|
|
10
|
-
target: string;
|
|
11
|
-
method: string;
|
|
12
|
-
params: string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export enum SupportedChainId {
|
|
16
|
-
MAINNET = 1,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ChainInfo {
|
|
20
|
-
readonly name: string;
|
|
21
|
-
readonly node: string;
|
|
22
|
-
readonly APIEndpoint: string;
|
|
23
|
-
readonly debugAPIEndpoint: string;
|
|
24
|
-
readonly chainId: number;
|
|
25
|
-
readonly tracker: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const CHAIN_INFO: { readonly [chainId: number]: ChainInfo } = {
|
|
29
|
-
[SupportedChainId.MAINNET]: {
|
|
30
|
-
name: 'ICON Mainnet',
|
|
31
|
-
node: 'https://ctz.solidwallet.io',
|
|
32
|
-
APIEndpoint: 'https://ctz.solidwallet.io/api/v3',
|
|
33
|
-
debugAPIEndpoint: 'https://api.icon.community/api/v3d',
|
|
34
|
-
chainId: 1,
|
|
35
|
-
tracker: 'https://tracker.icon.community',
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export class IconXService extends XService {
|
|
40
|
-
private static instance: IconXService;
|
|
41
|
-
|
|
42
|
-
public iconService: IconService;
|
|
43
|
-
|
|
44
|
-
private constructor() {
|
|
45
|
-
super('ICON');
|
|
46
|
-
this.iconService = new IconServiceConstructor(
|
|
47
|
-
new IconServiceConstructor.HttpProvider(CHAIN_INFO[SupportedChainId.MAINNET].APIEndpoint),
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public static getInstance(): IconXService {
|
|
52
|
-
if (!IconXService.instance) {
|
|
53
|
-
IconXService.instance = new IconXService();
|
|
54
|
-
}
|
|
55
|
-
return IconXService.instance;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private async getAggregateData(requireSuccess: boolean, calls: CallData[]) {
|
|
59
|
-
const rawTx = new IconBuilder.CallBuilder()
|
|
60
|
-
// muticall address on mainnet
|
|
61
|
-
.to('cxa4aa9185e23558cff990f494c1fd2845f6cbf741')
|
|
62
|
-
.method('tryAggregate')
|
|
63
|
-
.params({ requireSuccess: IconConverter.toHex(requireSuccess ? 1 : 0), calls })
|
|
64
|
-
.build();
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const result = await this.iconService.call(rawTx).execute();
|
|
68
|
-
const aggs = result['returnData'];
|
|
69
|
-
|
|
70
|
-
const data = aggs.map(agg => {
|
|
71
|
-
if (agg['success'] === '0x0') {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
return agg['returnData'];
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return data;
|
|
78
|
-
} catch (err) {
|
|
79
|
-
console.error(err);
|
|
80
|
-
return Array(calls.length).fill(null);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async getBalances(address: string | undefined, xTokens: XToken[]) {
|
|
85
|
-
if (!address) return {};
|
|
86
|
-
|
|
87
|
-
const balances = {};
|
|
88
|
-
|
|
89
|
-
const nativeXToken = xTokens.find(xToken => isNativeToken(xToken));
|
|
90
|
-
const nonNativeXTokens = xTokens.filter(xToken => !isNativeToken(xToken));
|
|
91
|
-
|
|
92
|
-
if (nativeXToken) {
|
|
93
|
-
const balance = await this.iconService.getBalance(address).execute();
|
|
94
|
-
balances[nativeXToken.address] = BigInt(balance.toFixed());
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const cds: CallData[] = nonNativeXTokens.map(token => {
|
|
98
|
-
return {
|
|
99
|
-
target: token.address,
|
|
100
|
-
method: 'balanceOf',
|
|
101
|
-
params: [address],
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const data: string[] = await this.getAggregateData(
|
|
106
|
-
false,
|
|
107
|
-
cds.filter(cd => cd.target.startsWith('cx')),
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
return nonNativeXTokens.reduce((agg, token, idx) => {
|
|
111
|
-
const balance = data[idx];
|
|
112
|
-
balances[token.address] = BigInt(balance);
|
|
113
|
-
|
|
114
|
-
return agg;
|
|
115
|
-
}, balances);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { useXWagmiStore } from '@/useXWagmiStore';
|
|
2
|
-
import { ICONexRequestEventType, ICONexResponseEventType, request } from './iconex';
|
|
3
|
-
|
|
4
|
-
export const reconnectIcon = async () => {
|
|
5
|
-
const iconConnection = useXWagmiStore.getState().xConnections.ICON;
|
|
6
|
-
if (!iconConnection) return;
|
|
7
|
-
|
|
8
|
-
const recentXConnectorId = iconConnection.xConnectorId;
|
|
9
|
-
|
|
10
|
-
const detail = await request({
|
|
11
|
-
type: ICONexRequestEventType.REQUEST_ADDRESS,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
if (detail?.type === ICONexResponseEventType.RESPONSE_ADDRESS) {
|
|
15
|
-
useXWagmiStore.setState({
|
|
16
|
-
xConnections: {
|
|
17
|
-
...useXWagmiStore.getState().xConnections,
|
|
18
|
-
ICON: {
|
|
19
|
-
xAccount: {
|
|
20
|
-
address: detail?.payload,
|
|
21
|
-
xChainType: 'ICON',
|
|
22
|
-
},
|
|
23
|
-
xConnectorId: recentXConnectorId,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const ICONEX_RELAY_RESPONSE = 'ICONEX_RELAY_RESPONSE';
|
|
2
|
-
const ICONEX_RELAY_REQUEST = 'ICONEX_RELAY_REQUEST';
|
|
3
|
-
|
|
4
|
-
export enum ICONexRequestEventType {
|
|
5
|
-
REQUEST_HAS_ACCOUNT = 'REQUEST_HAS_ACCOUNT',
|
|
6
|
-
REQUEST_HAS_ADDRESS = 'REQUEST_HAS_ADDRESS',
|
|
7
|
-
REQUEST_ADDRESS = 'REQUEST_ADDRESS',
|
|
8
|
-
REQUEST_JSON = 'REQUEST_JSON',
|
|
9
|
-
REQUEST_SIGNING = 'REQUEST_SIGNING',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export enum ICONexResponseEventType {
|
|
13
|
-
RESPONSE_HAS_ACCOUNT = 'RESPONSE_HAS_ACCOUNT',
|
|
14
|
-
RESPONSE_HAS_ADDRESS = 'RESPONSE_HAS_ADDRESS',
|
|
15
|
-
RESPONSE_ADDRESS = 'RESPONSE_ADDRESS',
|
|
16
|
-
RESPONSE_JSON = 'RESPONSE_JSON',
|
|
17
|
-
RESPONSE_SIGNING = 'RESPONSE_SIGNING',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ICONexRequestEvent {
|
|
21
|
-
type: ICONexRequestEventType;
|
|
22
|
-
payload?: any;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface ICONexResponseEvent {
|
|
26
|
-
type: ICONexResponseEventType;
|
|
27
|
-
payload?: any;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type ICONexEvent = ICONexRequestEvent | ICONexResponseEvent;
|
|
31
|
-
|
|
32
|
-
export const request = (event: ICONexRequestEvent): Promise<ICONexResponseEvent> => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
const handler = evt => {
|
|
35
|
-
window.removeEventListener(ICONEX_RELAY_RESPONSE, handler);
|
|
36
|
-
resolve(evt.detail);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
window.addEventListener(ICONEX_RELAY_RESPONSE, handler);
|
|
40
|
-
window.dispatchEvent(
|
|
41
|
-
new CustomEvent(ICONEX_RELAY_REQUEST, {
|
|
42
|
-
detail: event,
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
import { XConnector } from '@/core';
|
|
3
|
-
import { getInjectiveAddress } from '@injectivelabs/sdk-ts';
|
|
4
|
-
import { type Wallet, isEvmBrowserWallet, isCosmosBrowserWallet } from '@injectivelabs/wallet-base';
|
|
5
|
-
import { isCosmosWalletInstalled } from '@injectivelabs/wallet-cosmos';
|
|
6
|
-
import { InjectiveXService } from './InjectiveXService';
|
|
7
|
-
|
|
8
|
-
const WALLET_ICONS: Partial<Record<Wallet, string>> = {
|
|
9
|
-
metamask: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/metamask.svg',
|
|
10
|
-
keplr: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg',
|
|
11
|
-
leap: 'https://assets.leapwallet.io/logos/leap-cosmos-logo.svg',
|
|
12
|
-
rabby: 'https://raw.githubusercontent.com/RabbyHub/logo/master/symbol.svg',
|
|
13
|
-
phantom: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/phantom.svg',
|
|
14
|
-
'okx-wallet': 'https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png',
|
|
15
|
-
'trust-wallet': 'https://trustwallet.com/assets/images/media/assets/twLogo.svg',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export class InjectiveXConnector extends XConnector {
|
|
19
|
-
private wallet: Wallet;
|
|
20
|
-
|
|
21
|
-
constructor(name: string, wallet: Wallet) {
|
|
22
|
-
super('INJECTIVE', name, wallet);
|
|
23
|
-
this.wallet = wallet;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getXService(): InjectiveXService {
|
|
27
|
-
return InjectiveXService.getInstance();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async connect(): Promise<XAccount | undefined> {
|
|
31
|
-
if (isCosmosBrowserWallet(this.wallet) && !isCosmosWalletInstalled(this.wallet)) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const walletStrategy = this.getXService().walletStrategy;
|
|
36
|
-
await walletStrategy.setWallet(this.wallet);
|
|
37
|
-
const addresses = await walletStrategy.getAddresses();
|
|
38
|
-
|
|
39
|
-
if (!addresses?.length) return undefined;
|
|
40
|
-
|
|
41
|
-
const address = isEvmBrowserWallet(this.wallet) ? getInjectiveAddress(addresses[0]) : addresses[0];
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
address,
|
|
45
|
-
xChainType: this.xChainType,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async disconnect(): Promise<void> {
|
|
50
|
-
if (isEvmBrowserWallet(this.wallet)) {
|
|
51
|
-
const walletStrategy = this.getXService().walletStrategy;
|
|
52
|
-
await walletStrategy.setWallet(this.wallet);
|
|
53
|
-
await walletStrategy.disconnect();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public get icon(): string | undefined {
|
|
58
|
-
return WALLET_ICONS[this.wallet];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { XService } from '@/core/XService';
|
|
2
|
-
import { Network, getNetworkEndpoints } from '@injectivelabs/networks';
|
|
3
|
-
import { ChainGrpcWasmApi, IndexerGrpcAccountPortfolioApi } from '@injectivelabs/sdk-ts';
|
|
4
|
-
import { ChainId as InjectiveChainId } from '@injectivelabs/ts-types';
|
|
5
|
-
import { MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
6
|
-
import type { XToken } from '@sodax/types';
|
|
7
|
-
import { mainnet } from 'wagmi/chains';
|
|
8
|
-
import { WalletStrategy } from '@injectivelabs/wallet-strategy';
|
|
9
|
-
|
|
10
|
-
export class InjectiveXService extends XService {
|
|
11
|
-
private static instance: InjectiveXService;
|
|
12
|
-
|
|
13
|
-
public walletStrategy: WalletStrategy;
|
|
14
|
-
public indexerGrpcAccountPortfolioApi: IndexerGrpcAccountPortfolioApi;
|
|
15
|
-
public chainGrpcWasmApi: ChainGrpcWasmApi;
|
|
16
|
-
public msgBroadcaster: MsgBroadcaster;
|
|
17
|
-
|
|
18
|
-
private constructor() {
|
|
19
|
-
super('INJECTIVE');
|
|
20
|
-
|
|
21
|
-
const endpoints = getNetworkEndpoints(Network.Mainnet);
|
|
22
|
-
|
|
23
|
-
this.walletStrategy = new WalletStrategy({
|
|
24
|
-
chainId: InjectiveChainId.Mainnet,
|
|
25
|
-
strategies: {},
|
|
26
|
-
evmOptions: {
|
|
27
|
-
evmChainId: mainnet.id,
|
|
28
|
-
rpcUrl: mainnet.rpcUrls.default.http[0],
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
this.indexerGrpcAccountPortfolioApi = new IndexerGrpcAccountPortfolioApi(endpoints.indexer);
|
|
33
|
-
this.chainGrpcWasmApi = new ChainGrpcWasmApi(endpoints.grpc);
|
|
34
|
-
this.msgBroadcaster = new MsgBroadcaster({
|
|
35
|
-
walletStrategy: this.walletStrategy,
|
|
36
|
-
network: Network.Mainnet,
|
|
37
|
-
endpoints,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public static getInstance(): InjectiveXService {
|
|
42
|
-
if (!InjectiveXService.instance) {
|
|
43
|
-
InjectiveXService.instance = new InjectiveXService();
|
|
44
|
-
}
|
|
45
|
-
return InjectiveXService.instance;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async getBalance(address: string | undefined, xToken: XToken) {
|
|
49
|
-
if (!address) return 0n;
|
|
50
|
-
|
|
51
|
-
const portfolio = await this.indexerGrpcAccountPortfolioApi.fetchAccountPortfolioBalances(address);
|
|
52
|
-
|
|
53
|
-
const xTokenAddress = xToken.address;
|
|
54
|
-
|
|
55
|
-
const balance = portfolio.bankBalancesList.find(_balance => _balance.denom === xTokenAddress);
|
|
56
|
-
if (balance) {
|
|
57
|
-
return BigInt(balance.amount);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return 0n;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { useXWagmiStore } from '@/useXWagmiStore';
|
|
2
|
-
import { InjectiveXService } from './InjectiveXService';
|
|
3
|
-
import { isEvmBrowserWallet } from '@injectivelabs/wallet-base';
|
|
4
|
-
import { getInjectiveAddress } from '@injectivelabs/sdk-ts';
|
|
5
|
-
import type { Wallet } from '@injectivelabs/wallet-base';
|
|
6
|
-
|
|
7
|
-
export const reconnectInjective = async () => {
|
|
8
|
-
const injectiveConnection = useXWagmiStore.getState().xConnections.INJECTIVE;
|
|
9
|
-
if (!injectiveConnection) return;
|
|
10
|
-
|
|
11
|
-
const recentXConnectorId = injectiveConnection.xConnectorId;
|
|
12
|
-
const walletStrategy = InjectiveXService.getInstance().walletStrategy;
|
|
13
|
-
await walletStrategy.setWallet(recentXConnectorId as Wallet);
|
|
14
|
-
const addresses = await walletStrategy.getAddresses();
|
|
15
|
-
|
|
16
|
-
const address = isEvmBrowserWallet(recentXConnectorId as Wallet)
|
|
17
|
-
? getInjectiveAddress(addresses?.[0])
|
|
18
|
-
: addresses?.[0];
|
|
19
|
-
|
|
20
|
-
useXWagmiStore.setState({
|
|
21
|
-
xConnections: {
|
|
22
|
-
...useXWagmiStore.getState().xConnections,
|
|
23
|
-
INJECTIVE: {
|
|
24
|
-
xAccount: {
|
|
25
|
-
address,
|
|
26
|
-
xChainType: 'INJECTIVE',
|
|
27
|
-
},
|
|
28
|
-
xConnectorId: recentXConnectorId,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
|
|
3
|
-
import { XConnector } from '@/core';
|
|
4
|
-
import type { NearWalletBase } from '@hot-labs/near-connect';
|
|
5
|
-
import { NearXService } from './NearXService';
|
|
6
|
-
|
|
7
|
-
export class NearXConnector extends XConnector {
|
|
8
|
-
_wallet: NearWalletBase;
|
|
9
|
-
|
|
10
|
-
constructor(wallet: NearWalletBase) {
|
|
11
|
-
super('NEAR', wallet.manifest.name, wallet.manifest.id);
|
|
12
|
-
this._wallet = wallet;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getXService(): NearXService {
|
|
16
|
-
return NearXService.getInstance();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async connect(): Promise<XAccount | undefined> {
|
|
20
|
-
const walletSelector = this.getXService().walletSelector;
|
|
21
|
-
const wallet = await walletSelector.connect({ walletId: this._wallet.manifest.id });
|
|
22
|
-
const accounts = await wallet.getAccounts();
|
|
23
|
-
|
|
24
|
-
if (accounts.length === 0 || accounts[0] === undefined) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
address: accounts[0].accountId,
|
|
30
|
-
xChainType: this.xChainType,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async disconnect(): Promise<void> {
|
|
35
|
-
const walletSelector = this.getXService().walletSelector;
|
|
36
|
-
await walletSelector.disconnect(this._wallet);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public get icon() {
|
|
40
|
-
return this._wallet.manifest.icon;
|
|
41
|
-
}
|
|
42
|
-
}
|