@multiversx/sdk-dapp-liquidity 1.1.7 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +7 -0
- package/index.mjs +8 -1
- package/package.json +19 -16
- package/reactjs/adapters/SuiAdapter.d.ts +60 -0
- package/reactjs/adapters/SuiAdapter.js +350 -0
- package/reactjs/adapters/SuiAdapter.mjs +349 -0
- package/reactjs/components/AmountInput/AmountInput.js +1 -1
- package/reactjs/components/AmountInput/AmountInput.mjs +1 -1
- package/reactjs/components/BridgeForm/Deposit.js +57 -18
- package/reactjs/components/BridgeForm/Deposit.mjs +57 -18
- package/reactjs/components/BridgeForm/Transfer.js +17 -10
- package/reactjs/components/BridgeForm/Transfer.mjs +17 -10
- package/reactjs/components/BridgeForm/hooks/useBridgeTokenSelection.js +31 -9
- package/reactjs/components/BridgeForm/hooks/useBridgeTokenSelection.mjs +31 -9
- package/reactjs/components/BridgeForm/utils/bridgeFormHelpers.d.ts +6 -0
- package/reactjs/components/BridgeForm/utils/bridgeFormHelpers.js +18 -0
- package/reactjs/components/BridgeForm/utils/bridgeFormHelpers.mjs +18 -0
- package/reactjs/components/BridgeHistory/BridgeHistory.js +2 -2
- package/reactjs/components/BridgeHistory/BridgeHistory.mjs +2 -2
- package/reactjs/components/Connect/BridgeAccountDisplay.js +77 -25
- package/reactjs/components/Connect/BridgeAccountDisplay.mjs +77 -25
- package/reactjs/components/Connect/BridgeConnectButton.js +1 -1
- package/reactjs/components/Connect/BridgeConnectButton.mjs +1 -1
- package/reactjs/components/Connect/ChainSelectConnect.d.ts +7 -0
- package/reactjs/components/Connect/ChainSelectConnect.js +144 -0
- package/reactjs/components/Connect/ChainSelectConnect.mjs +143 -0
- package/reactjs/components/Connect/MvxAccountDisplay.js +17 -3
- package/reactjs/components/Connect/MvxAccountDisplay.mjs +17 -3
- package/reactjs/components/Connect/MvxConnectButton.js +2 -2
- package/reactjs/components/Connect/MvxConnectButton.mjs +2 -2
- package/reactjs/components/Connect/index.d.ts +1 -0
- package/reactjs/components/Connect/index.js +2 -0
- package/reactjs/components/Connect/index.mjs +2 -0
- package/reactjs/components/TokenSelector/components/TokenItem.js +11 -1
- package/reactjs/components/TokenSelector/components/TokenItem.mjs +11 -1
- package/reactjs/components/TrimAddress/TrimAddress.js +1 -1
- package/reactjs/components/TrimAddress/TrimAddress.mjs +1 -1
- package/reactjs/components/index.js +2 -0
- package/reactjs/components/index.mjs +2 -0
- package/reactjs/constants/chains.d.ts +7 -1
- package/reactjs/constants/chains.js +6 -0
- package/reactjs/constants/chains.mjs +6 -0
- package/reactjs/helpers/index.d.ts +1 -0
- package/reactjs/helpers/index.js +7 -0
- package/reactjs/helpers/index.mjs +6 -0
- package/reactjs/helpers/resolveBridgeApiChainId.d.ts +18 -0
- package/reactjs/helpers/resolveBridgeApiChainId.js +41 -0
- package/reactjs/helpers/resolveBridgeApiChainId.mjs +40 -0
- package/reactjs/hooks/index.d.ts +2 -0
- package/reactjs/hooks/index.js +4 -0
- package/reactjs/hooks/index.mjs +4 -0
- package/reactjs/hooks/useBridgeApiChainId.d.ts +2 -0
- package/reactjs/hooks/useBridgeApiChainId.js +14 -0
- package/reactjs/hooks/useBridgeApiChainId.mjs +13 -0
- package/reactjs/hooks/useFetchTokens.js +17 -17
- package/reactjs/hooks/useFetchTokens.mjs +17 -17
- package/reactjs/hooks/useGenericSignMessage.d.ts +1 -1
- package/reactjs/hooks/useGenericSignMessage.js +14 -0
- package/reactjs/hooks/useGenericSignMessage.mjs +14 -0
- package/reactjs/hooks/useSignTransaction.d.ts +418 -3
- package/reactjs/hooks/useSignTransaction.js +28 -0
- package/reactjs/hooks/useSignTransaction.mjs +28 -0
- package/reactjs/hooks/useSuiConnect.d.ts +8 -0
- package/reactjs/hooks/useSuiConnect.js +87 -0
- package/reactjs/hooks/useSuiConnect.mjs +86 -0
- package/reactjs/index.js +7 -0
- package/reactjs/index.mjs +8 -1
- package/reactjs/init/index.js +1 -0
- package/reactjs/init/index.mjs +2 -1
- package/reactjs/init/init.d.ts +9 -30
- package/reactjs/init/init.js +90 -9
- package/reactjs/init/init.mjs +91 -10
- package/reactjs/queries/useCheckAccount.query.js +4 -14
- package/reactjs/queries/useCheckAccount.query.mjs +4 -14
- package/reactjs/queries/useGetNonMvxTokensBalances.query.js +1 -0
- package/reactjs/queries/useGetNonMvxTokensBalances.query.mjs +1 -0
- package/style.css +51 -0
- package/types/chainType.d.ts +2 -1
- package/types/chainType.js +1 -0
- package/types/chainType.mjs +1 -0
- package/types/transaction.d.ts +5 -0
package/index.js
CHANGED
|
@@ -37,6 +37,7 @@ const reactjs_components_Connect_MvxConnectButton = require("./reactjs/component
|
|
|
37
37
|
const reactjs_components_Connect_SwitchChainButton = require("./reactjs/components/Connect/SwitchChainButton.js");
|
|
38
38
|
const reactjs_components_Connect_BridgeAccountDisplay = require("./reactjs/components/Connect/BridgeAccountDisplay.js");
|
|
39
39
|
const reactjs_components_Connect_MvxAccountDisplay = require("./reactjs/components/Connect/MvxAccountDisplay.js");
|
|
40
|
+
const reactjs_components_Connect_ChainSelectConnect = require("./reactjs/components/Connect/ChainSelectConnect.js");
|
|
40
41
|
const reactjs_components_CopyButton_CopyButton = require("./reactjs/components/CopyButton/CopyButton.js");
|
|
41
42
|
const reactjs_components_DisplayAmount_DisplayAmount = require("./reactjs/components/DisplayAmount/DisplayAmount.js");
|
|
42
43
|
const reactjs_components_SmallLoader_SmallLoader = require("./reactjs/components/SmallLoader/SmallLoader.js");
|
|
@@ -60,9 +61,11 @@ const reactjs_hooks_useDebounce = require("./reactjs/hooks/useDebounce.js");
|
|
|
60
61
|
const reactjs_hooks_useFetchBridgeData = require("./reactjs/hooks/useFetchBridgeData.js");
|
|
61
62
|
const reactjs_hooks_useFetchTokens = require("./reactjs/hooks/useFetchTokens.js");
|
|
62
63
|
const reactjs_hooks_useGetChainId = require("./reactjs/hooks/useGetChainId.js");
|
|
64
|
+
const reactjs_hooks_useBridgeApiChainId = require("./reactjs/hooks/useBridgeApiChainId.js");
|
|
63
65
|
const reactjs_hooks_useResolveTokenChain = require("./reactjs/hooks/useResolveTokenChain.js");
|
|
64
66
|
const reactjs_hooks_useSendTransactions = require("./reactjs/hooks/useSendTransactions.js");
|
|
65
67
|
const reactjs_hooks_useSignTransaction = require("./reactjs/hooks/useSignTransaction.js");
|
|
68
|
+
const reactjs_hooks_useSuiConnect = require("./reactjs/hooks/useSuiConnect.js");
|
|
66
69
|
const reactjs_init_init = require("./reactjs/init/init.js");
|
|
67
70
|
const reactjs_queries_useGetAllTokens_query = require("./reactjs/queries/useGetAllTokens.query.js");
|
|
68
71
|
const reactjs_queries_useGetChains_query = require("./reactjs/queries/useGetChains.query.js");
|
|
@@ -122,6 +125,7 @@ exports.MvxConnectButton = reactjs_components_Connect_MvxConnectButton.MvxConnec
|
|
|
122
125
|
exports.SwitchChainButton = reactjs_components_Connect_SwitchChainButton.SwitchChainButton;
|
|
123
126
|
exports.BridgeAccountDisplay = reactjs_components_Connect_BridgeAccountDisplay.BridgeAccountDisplay;
|
|
124
127
|
exports.MvxAccountDisplay = reactjs_components_Connect_MvxAccountDisplay.MvxAccountDisplay;
|
|
128
|
+
exports.ChainSelectConnect = reactjs_components_Connect_ChainSelectConnect.ChainSelectConnect;
|
|
125
129
|
exports.CopyButton = reactjs_components_CopyButton_CopyButton.CopyButton;
|
|
126
130
|
exports.DisplayAmount = reactjs_components_DisplayAmount_DisplayAmount.DisplayAmount;
|
|
127
131
|
exports.SmallLoader = reactjs_components_SmallLoader_SmallLoader.SmallLoader;
|
|
@@ -148,9 +152,12 @@ exports.useDebounce = reactjs_hooks_useDebounce.useDebounce;
|
|
|
148
152
|
exports.useFetchBridgeData = reactjs_hooks_useFetchBridgeData.useFetchBridgeData;
|
|
149
153
|
exports.useFetchTokens = reactjs_hooks_useFetchTokens.useFetchTokens;
|
|
150
154
|
exports.useGetChainId = reactjs_hooks_useGetChainId.useGetChainId;
|
|
155
|
+
exports.useBridgeApiChainId = reactjs_hooks_useBridgeApiChainId.useBridgeApiChainId;
|
|
151
156
|
exports.useResolveTokenChain = reactjs_hooks_useResolveTokenChain.useResolveTokenChain;
|
|
152
157
|
exports.useSendTransactions = reactjs_hooks_useSendTransactions.useSendTransactions;
|
|
153
158
|
exports.useSignTransaction = reactjs_hooks_useSignTransaction.useSignTransaction;
|
|
159
|
+
exports.useSuiConnect = reactjs_hooks_useSuiConnect.useSuiConnect;
|
|
160
|
+
exports.SuiMethods = reactjs_init_init.SuiMethods;
|
|
154
161
|
exports.init = reactjs_init_init.init;
|
|
155
162
|
exports.useGetAllTokensQuery = reactjs_queries_useGetAllTokens_query.useGetAllTokensQuery;
|
|
156
163
|
exports.useGetChainsQuery = reactjs_queries_useGetChains_query.useGetChainsQuery;
|
package/index.mjs
CHANGED
|
@@ -34,6 +34,7 @@ import { MvxConnectButton } from "./reactjs/components/Connect/MvxConnectButton.
|
|
|
34
34
|
import { SwitchChainButton } from "./reactjs/components/Connect/SwitchChainButton.mjs";
|
|
35
35
|
import { BridgeAccountDisplay } from "./reactjs/components/Connect/BridgeAccountDisplay.mjs";
|
|
36
36
|
import { MvxAccountDisplay } from "./reactjs/components/Connect/MvxAccountDisplay.mjs";
|
|
37
|
+
import { ChainSelectConnect } from "./reactjs/components/Connect/ChainSelectConnect.mjs";
|
|
37
38
|
import { CopyButton } from "./reactjs/components/CopyButton/CopyButton.mjs";
|
|
38
39
|
import { DisplayAmount } from "./reactjs/components/DisplayAmount/DisplayAmount.mjs";
|
|
39
40
|
import { SmallLoader } from "./reactjs/components/SmallLoader/SmallLoader.mjs";
|
|
@@ -57,10 +58,12 @@ import { useDebounce } from "./reactjs/hooks/useDebounce.mjs";
|
|
|
57
58
|
import { useFetchBridgeData } from "./reactjs/hooks/useFetchBridgeData.mjs";
|
|
58
59
|
import { useFetchTokens } from "./reactjs/hooks/useFetchTokens.mjs";
|
|
59
60
|
import { useGetChainId } from "./reactjs/hooks/useGetChainId.mjs";
|
|
61
|
+
import { useBridgeApiChainId } from "./reactjs/hooks/useBridgeApiChainId.mjs";
|
|
60
62
|
import { useResolveTokenChain } from "./reactjs/hooks/useResolveTokenChain.mjs";
|
|
61
63
|
import { useSendTransactions } from "./reactjs/hooks/useSendTransactions.mjs";
|
|
62
64
|
import { useSignTransaction } from "./reactjs/hooks/useSignTransaction.mjs";
|
|
63
|
-
import {
|
|
65
|
+
import { useSuiConnect } from "./reactjs/hooks/useSuiConnect.mjs";
|
|
66
|
+
import { SuiMethods, init } from "./reactjs/init/init.mjs";
|
|
64
67
|
import { useGetAllTokensQuery } from "./reactjs/queries/useGetAllTokens.query.mjs";
|
|
65
68
|
import { useGetChainsQuery } from "./reactjs/queries/useGetChains.query.mjs";
|
|
66
69
|
import { invalidateEvmTokensBalances, useGetNonMvxTokensBalancesQuery } from "./reactjs/queries/useGetNonMvxTokensBalances.query.mjs";
|
|
@@ -93,6 +96,7 @@ export {
|
|
|
93
96
|
BridgeFormikValuesEnum,
|
|
94
97
|
BridgeHistory,
|
|
95
98
|
ChainName,
|
|
99
|
+
ChainSelectConnect,
|
|
96
100
|
CopyButton,
|
|
97
101
|
CustomConnectButton,
|
|
98
102
|
DisplayAmount,
|
|
@@ -107,6 +111,7 @@ export {
|
|
|
107
111
|
MxSlideover,
|
|
108
112
|
MxTooltip,
|
|
109
113
|
SmallLoader,
|
|
114
|
+
SuiMethods,
|
|
110
115
|
SwitchChainButton,
|
|
111
116
|
TokenSelector,
|
|
112
117
|
TransactionToast,
|
|
@@ -164,6 +169,7 @@ export {
|
|
|
164
169
|
useAppKitState,
|
|
165
170
|
useAppKitTheme,
|
|
166
171
|
useBalances,
|
|
172
|
+
useBridgeApiChainId,
|
|
167
173
|
useBridgeFormik,
|
|
168
174
|
useDebounce,
|
|
169
175
|
useDisconnect,
|
|
@@ -180,6 +186,7 @@ export {
|
|
|
180
186
|
useSecondAmountSchema,
|
|
181
187
|
useSendTransactions,
|
|
182
188
|
useSignTransaction,
|
|
189
|
+
useSuiConnect,
|
|
183
190
|
useTestHasEnoughFunds,
|
|
184
191
|
useTestIsConnected,
|
|
185
192
|
useWaitForTransactionReceipt,
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/multiversx/mx-sdk-dapp-liquidity#readme",
|
|
30
30
|
"license": "MIT",
|
|
31
|
-
"version": "
|
|
31
|
+
"version": "2.0.0-alpha.0",
|
|
32
32
|
"main": "index.js",
|
|
33
33
|
"module": "index.mjs",
|
|
34
34
|
"types": "index.d.ts",
|
|
@@ -53,13 +53,16 @@
|
|
|
53
53
|
"@headlessui/react": "2.2.0",
|
|
54
54
|
"@multiversx/sdk-dapp-utils": "3.0.2",
|
|
55
55
|
"@popperjs/core": "2.11.8",
|
|
56
|
-
"@reown/appkit": "1.8.
|
|
57
|
-
"@reown/appkit-
|
|
58
|
-
"@reown/appkit-adapter-
|
|
59
|
-
"@reown/appkit-adapter-
|
|
60
|
-
"@reown/appkit-
|
|
56
|
+
"@reown/appkit": "1.8.19",
|
|
57
|
+
"@reown/appkit-adapter-bitcoin": "1.8.19",
|
|
58
|
+
"@reown/appkit-adapter-solana": "1.8.19",
|
|
59
|
+
"@reown/appkit-adapter-wagmi": "1.8.19",
|
|
60
|
+
"@reown/appkit-common": "1.8.19",
|
|
61
|
+
"@reown/appkit-controllers": "1.8.19",
|
|
61
62
|
"@solana/web3.js": "1.98.4",
|
|
62
63
|
"@tanstack/react-query": "5.71.3",
|
|
64
|
+
"@walletconnect/modal": "^2.7.0",
|
|
65
|
+
"@walletconnect/universal-provider": "2.23.9",
|
|
63
66
|
"animated-number-react": "0.1.2",
|
|
64
67
|
"axios": "1.7.4",
|
|
65
68
|
"formik": "2.4.6",
|
|
@@ -71,24 +74,21 @@
|
|
|
71
74
|
"react-select": "5.10.0",
|
|
72
75
|
"react-toastify": "11.0.3",
|
|
73
76
|
"tailwind-merge": "2.6.0",
|
|
74
|
-
"viem": "2.
|
|
75
|
-
"wagmi": "
|
|
77
|
+
"viem": "2.47.10",
|
|
78
|
+
"wagmi": "3.6.1",
|
|
76
79
|
"yup": "1.4.0"
|
|
77
80
|
},
|
|
78
81
|
"peerDependencies": {
|
|
79
82
|
"@multiversx/sdk-core": ">= 15.x",
|
|
80
|
-
"
|
|
81
|
-
"react-dom": ">= 18",
|
|
82
|
-
"tailwindcss": ">= 3",
|
|
83
|
+
"@wagmi/core": ">= 3.x",
|
|
83
84
|
"bignumber.js": ">= 9.x",
|
|
84
85
|
"clsx": ">= 2.x",
|
|
85
|
-
"
|
|
86
|
+
"react": ">= 18",
|
|
87
|
+
"react-dom": ">= 18",
|
|
88
|
+
"tailwindcss": ">= 3"
|
|
86
89
|
},
|
|
87
90
|
"devDependencies": {
|
|
88
|
-
"@
|
|
89
|
-
"clsx": "2.0.0",
|
|
90
|
-
"bignumber.js": "9.0.1",
|
|
91
|
-
"@multiversx/sdk-core": "15.3.0",
|
|
91
|
+
"@multiversx/sdk-core": "15.4.0",
|
|
92
92
|
"@rollup/plugin-node-resolve": "15.2.3",
|
|
93
93
|
"@swc-node/jest": "1.6.6",
|
|
94
94
|
"@swc/core": "1.5.24",
|
|
@@ -105,8 +105,11 @@
|
|
|
105
105
|
"@types/react-dom": "18.3.1",
|
|
106
106
|
"@typescript-eslint/eslint-plugin": "7.13.0",
|
|
107
107
|
"@typescript-eslint/parser": "7.13.0",
|
|
108
|
+
"@wagmi/core": "3.4.2",
|
|
108
109
|
"autoprefixer": "10.4.20",
|
|
109
110
|
"axios-mock-adapter": "1.22.0",
|
|
111
|
+
"bignumber.js": "9.0.1",
|
|
112
|
+
"clsx": "2.0.0",
|
|
110
113
|
"dotenv": "16.4.5",
|
|
111
114
|
"eslint": "8.50.0",
|
|
112
115
|
"eslint-config-prettier": "9.0.0",
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { default as UniversalProvider } from '@walletconnect/universal-provider';
|
|
2
|
+
import { AdapterBlueprint } from '@reown/appkit-controllers';
|
|
3
|
+
|
|
4
|
+
export type SuiAdapterOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* CAIP-2 chain ids from `init()` (e.g. `['sui:mainnet']`).
|
|
7
|
+
* AppKit sometimes passes an empty `networks` array into `construct`; this keeps WC valid.
|
|
8
|
+
*/
|
|
9
|
+
explicitCaipChains?: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare class SuiAdapter extends AdapterBlueprint {
|
|
12
|
+
/**
|
|
13
|
+
* AppKit’s single WalletConnect UniversalProvider (same instance as Wagmi/EVM).
|
|
14
|
+
* @see @reown/appkit-adapter-solana — adapters must NOT call UniversalProvider.init() again
|
|
15
|
+
* (duplicate Core breaks pairing / QR). `listenWalletConnect` attaches `display_uri` here only.
|
|
16
|
+
*/
|
|
17
|
+
private sharedWcProvider?;
|
|
18
|
+
private readonly explicitCaipChainsFromInit;
|
|
19
|
+
constructor(opts?: SuiAdapterOptions);
|
|
20
|
+
/**
|
|
21
|
+
* AppKit passes `networks` here from `createAppKit({ networks })` filtered by namespace.
|
|
22
|
+
* `ChainController.getRequestedCaipNetworks('sui')` is often still empty → we must keep this.
|
|
23
|
+
*/
|
|
24
|
+
private suiNetworksFromConfig;
|
|
25
|
+
construct(params: AdapterBlueprint.Params): void;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves CAIP-2 chain ids for the WC session. Never return [] (breaks pairing + QR UI).
|
|
28
|
+
*/
|
|
29
|
+
private pickChainsFromExplicit;
|
|
30
|
+
private resolveSuiChainsForConnect;
|
|
31
|
+
/**
|
|
32
|
+
* `WalletConnectConnector` typings require `caipNetworks` (ChainController may still be empty
|
|
33
|
+
* when this runs). Prefer networks from `construct`, else explicit/init CAIP ids.
|
|
34
|
+
*/
|
|
35
|
+
private getCaipNetworksForWalletConnectConnector;
|
|
36
|
+
syncConnectors(): void;
|
|
37
|
+
setUniversalProvider(sharedProvider: UniversalProvider): Promise<void>;
|
|
38
|
+
private getWcProvider;
|
|
39
|
+
connectWalletConnect(chainId?: string | number): Promise<{
|
|
40
|
+
clientId: string;
|
|
41
|
+
} | undefined>;
|
|
42
|
+
connect(params: AdapterBlueprint.ConnectParams): Promise<AdapterBlueprint.ConnectResult>;
|
|
43
|
+
disconnect(params: AdapterBlueprint.DisconnectParams): Promise<AdapterBlueprint.DisconnectResult>;
|
|
44
|
+
getAccounts(params: AdapterBlueprint.GetAccountsParams): Promise<AdapterBlueprint.GetAccountsResult>;
|
|
45
|
+
getBalance(params: AdapterBlueprint.GetBalanceParams): Promise<AdapterBlueprint.GetBalanceResult>;
|
|
46
|
+
switchNetwork(params: AdapterBlueprint.SwitchNetworkParams): Promise<void>;
|
|
47
|
+
syncConnection(params: AdapterBlueprint.SyncConnectionParams): Promise<AdapterBlueprint.ConnectResult>;
|
|
48
|
+
syncConnections({ connectToFirstConnector, caipNetwork }: AdapterBlueprint.SyncConnectionsParams): Promise<void>;
|
|
49
|
+
getWalletConnectProvider(params: AdapterBlueprint.GetWalletConnectProviderParams): AdapterBlueprint.GetWalletConnectProviderResult;
|
|
50
|
+
signMessage(params: AdapterBlueprint.SignMessageParams): Promise<AdapterBlueprint.SignMessageResult>;
|
|
51
|
+
sendTransaction(params: AdapterBlueprint.SendTransactionParams): Promise<AdapterBlueprint.SendTransactionResult>;
|
|
52
|
+
estimateGas(): Promise<AdapterBlueprint.EstimateGasTransactionResult>;
|
|
53
|
+
writeContract(): Promise<AdapterBlueprint.WriteContractResult>;
|
|
54
|
+
parseUnits(): AdapterBlueprint.ParseUnitsResult;
|
|
55
|
+
formatUnits(): AdapterBlueprint.FormatUnitsResult;
|
|
56
|
+
getCapabilities(): Promise<unknown>;
|
|
57
|
+
grantPermissions(): Promise<unknown>;
|
|
58
|
+
revokePermissions(): Promise<`0x${string}`>;
|
|
59
|
+
walletGetAssets(): Promise<AdapterBlueprint.WalletGetAssetsResponse>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
const appkitControllers = require("@reown/appkit-controllers");
|
|
8
|
+
const WC_ID = "walletConnect";
|
|
9
|
+
const DEFAULT_SUI_CAIP_CHAINS = ["sui:mainnet", "sui:testnet", "sui:devnet"];
|
|
10
|
+
class SuiAdapter extends appkitControllers.AdapterBlueprint {
|
|
11
|
+
constructor(opts) {
|
|
12
|
+
super({
|
|
13
|
+
namespace: "sui",
|
|
14
|
+
adapterType: "sui"
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* AppKit’s single WalletConnect UniversalProvider (same instance as Wagmi/EVM).
|
|
18
|
+
* @see @reown/appkit-adapter-solana — adapters must NOT call UniversalProvider.init() again
|
|
19
|
+
* (duplicate Core breaks pairing / QR). `listenWalletConnect` attaches `display_uri` here only.
|
|
20
|
+
*/
|
|
21
|
+
__publicField(this, "sharedWcProvider");
|
|
22
|
+
__publicField(this, "explicitCaipChainsFromInit");
|
|
23
|
+
/**
|
|
24
|
+
* AppKit passes `networks` here from `createAppKit({ networks })` filtered by namespace.
|
|
25
|
+
* `ChainController.getRequestedCaipNetworks('sui')` is often still empty → we must keep this.
|
|
26
|
+
*/
|
|
27
|
+
__publicField(this, "suiNetworksFromConfig", []);
|
|
28
|
+
this.explicitCaipChainsFromInit = (opts == null ? void 0 : opts.explicitCaipChains) ?? [];
|
|
29
|
+
}
|
|
30
|
+
construct(params) {
|
|
31
|
+
super.construct(params);
|
|
32
|
+
this.suiNetworksFromConfig = params.networks ?? [];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolves CAIP-2 chain ids for the WC session. Never return [] (breaks pairing + QR UI).
|
|
36
|
+
*/
|
|
37
|
+
pickChainsFromExplicit(explicit, chainId) {
|
|
38
|
+
if (explicit.length === 0) {
|
|
39
|
+
return DEFAULT_SUI_CAIP_CHAINS;
|
|
40
|
+
}
|
|
41
|
+
if (chainId !== void 0 && chainId !== null) {
|
|
42
|
+
const cid = chainId.toString();
|
|
43
|
+
const match = explicit.find(
|
|
44
|
+
(c) => c === `sui:${cid}` || c.endsWith(`:${cid}`)
|
|
45
|
+
);
|
|
46
|
+
if (match) {
|
|
47
|
+
return [match];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return explicit;
|
|
51
|
+
}
|
|
52
|
+
resolveSuiChainsForConnect(chainId) {
|
|
53
|
+
const fromController = this.getCaipNetworks("sui");
|
|
54
|
+
const source = fromController.length > 0 ? fromController : this.suiNetworksFromConfig;
|
|
55
|
+
if (source.length === 0) {
|
|
56
|
+
return this.pickChainsFromExplicit(
|
|
57
|
+
this.explicitCaipChainsFromInit,
|
|
58
|
+
chainId
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const toCaip = (n) => n.caipNetworkId || `sui:${n.id}`;
|
|
62
|
+
if (chainId !== void 0 && chainId !== null) {
|
|
63
|
+
const match = source.find((n) => {
|
|
64
|
+
var _a;
|
|
65
|
+
return ((_a = n.id) == null ? void 0 : _a.toString()) === chainId.toString();
|
|
66
|
+
});
|
|
67
|
+
if (match) {
|
|
68
|
+
return [toCaip(match)];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return source.map(toCaip);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* `WalletConnectConnector` typings require `caipNetworks` (ChainController may still be empty
|
|
75
|
+
* when this runs). Prefer networks from `construct`, else explicit/init CAIP ids.
|
|
76
|
+
*/
|
|
77
|
+
getCaipNetworksForWalletConnectConnector() {
|
|
78
|
+
if (this.suiNetworksFromConfig.length > 0) {
|
|
79
|
+
return this.suiNetworksFromConfig;
|
|
80
|
+
}
|
|
81
|
+
const caipIds = this.explicitCaipChainsFromInit.length > 0 ? this.explicitCaipChainsFromInit : DEFAULT_SUI_CAIP_CHAINS;
|
|
82
|
+
return caipIds.map((caip) => {
|
|
83
|
+
const id = caip.startsWith("sui:") ? caip.slice(4) : caip;
|
|
84
|
+
return {
|
|
85
|
+
id,
|
|
86
|
+
chainNamespace: "sui",
|
|
87
|
+
caipNetworkId: caip,
|
|
88
|
+
name: "Sui",
|
|
89
|
+
nativeCurrency: { name: "SUI", symbol: "SUI", decimals: 9 },
|
|
90
|
+
rpcUrls: {
|
|
91
|
+
default: { http: [`https://fullnode.${id}.sui.io:443`] }
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
syncConnectors() {
|
|
97
|
+
}
|
|
98
|
+
async setUniversalProvider(sharedProvider) {
|
|
99
|
+
this.sharedWcProvider = sharedProvider;
|
|
100
|
+
const wcConnector = new appkitControllers.WalletConnectConnector({
|
|
101
|
+
provider: sharedProvider,
|
|
102
|
+
namespace: "sui",
|
|
103
|
+
caipNetworks: this.getCaipNetworksForWalletConnectConnector()
|
|
104
|
+
});
|
|
105
|
+
this.addConnector(wcConnector);
|
|
106
|
+
appkitControllers.WcHelpersUtil.listenWcProvider({
|
|
107
|
+
universalProvider: sharedProvider,
|
|
108
|
+
namespace: "sui",
|
|
109
|
+
onConnect: (accounts) => this.onConnect(accounts, WC_ID),
|
|
110
|
+
onDisconnect: () => this.onDisconnect(WC_ID),
|
|
111
|
+
onAccountsChanged: (accounts) => this.onAccountsChanged(accounts, WC_ID, false)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
getWcProvider() {
|
|
115
|
+
if (!this.sharedWcProvider) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
"SuiAdapter: UniversalProvider not ready — setUniversalProvider must run before connect"
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return this.sharedWcProvider;
|
|
121
|
+
}
|
|
122
|
+
async connectWalletConnect(chainId) {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
const wc = this.getWcProvider();
|
|
125
|
+
if ((_b = (_a = wc.session) == null ? void 0 : _a.namespaces) == null ? void 0 : _b["sui"]) {
|
|
126
|
+
const clientId2 = await wc.client.core.crypto.getClientId();
|
|
127
|
+
return { clientId: clientId2 };
|
|
128
|
+
}
|
|
129
|
+
const chains = this.resolveSuiChainsForConnect(chainId);
|
|
130
|
+
const safeChains = chains.length > 0 ? chains : DEFAULT_SUI_CAIP_CHAINS;
|
|
131
|
+
await wc.connect({
|
|
132
|
+
optionalNamespaces: {
|
|
133
|
+
sui: {
|
|
134
|
+
methods: [
|
|
135
|
+
"sui_signPersonalMessage",
|
|
136
|
+
"sui_signTransaction",
|
|
137
|
+
"sui_signAndExecuteTransaction"
|
|
138
|
+
],
|
|
139
|
+
chains: safeChains,
|
|
140
|
+
events: []
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const clientId = await wc.client.core.crypto.getClientId();
|
|
145
|
+
return { clientId };
|
|
146
|
+
}
|
|
147
|
+
async connect(params) {
|
|
148
|
+
var _a, _b, _c;
|
|
149
|
+
const connector = this.connectors.find((c) => c.id === params.id);
|
|
150
|
+
if (!connector) {
|
|
151
|
+
throw new Error("Sui connector not found");
|
|
152
|
+
}
|
|
153
|
+
const existingConnection = this.getConnection({
|
|
154
|
+
address: params.address,
|
|
155
|
+
connectorId: connector.id,
|
|
156
|
+
connections: this.connections,
|
|
157
|
+
connectors: this.connectors
|
|
158
|
+
});
|
|
159
|
+
if (existingConnection == null ? void 0 : existingConnection.account) {
|
|
160
|
+
const chainId2 = ((_a = existingConnection.caipNetwork) == null ? void 0 : _a.id) ?? params.chainId ?? "mainnet";
|
|
161
|
+
this.emit("accountChanged", {
|
|
162
|
+
address: existingConnection.account.address,
|
|
163
|
+
chainId: chainId2,
|
|
164
|
+
connector
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
id: connector.id,
|
|
168
|
+
address: existingConnection.account.address,
|
|
169
|
+
chainId: chainId2,
|
|
170
|
+
provider: connector.provider,
|
|
171
|
+
type: connector.type
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const wc = this.getWcProvider();
|
|
175
|
+
const accounts = appkitControllers.WcHelpersUtil.getWalletConnectAccounts(
|
|
176
|
+
wc,
|
|
177
|
+
"sui"
|
|
178
|
+
);
|
|
179
|
+
const address = (_b = accounts[0]) == null ? void 0 : _b.address;
|
|
180
|
+
if (!address) {
|
|
181
|
+
throw new Error("No Sui account found after WalletConnect session");
|
|
182
|
+
}
|
|
183
|
+
const caipNetwork = (_c = this.getCaipNetworks()) == null ? void 0 : _c.find(
|
|
184
|
+
(n) => n.id === params.chainId
|
|
185
|
+
);
|
|
186
|
+
this.addConnection({
|
|
187
|
+
connectorId: connector.id,
|
|
188
|
+
accounts: [{ address }],
|
|
189
|
+
caipNetwork
|
|
190
|
+
});
|
|
191
|
+
const chainId = params.chainId ?? (caipNetwork == null ? void 0 : caipNetwork.id) ?? "mainnet";
|
|
192
|
+
this.emit("accountChanged", {
|
|
193
|
+
address,
|
|
194
|
+
chainId,
|
|
195
|
+
connector
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
id: connector.id,
|
|
199
|
+
address,
|
|
200
|
+
chainId,
|
|
201
|
+
provider: connector.provider,
|
|
202
|
+
type: connector.type
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async disconnect(params) {
|
|
206
|
+
if (params == null ? void 0 : params.id) {
|
|
207
|
+
if (this.sharedWcProvider) {
|
|
208
|
+
try {
|
|
209
|
+
await this.sharedWcProvider.disconnect();
|
|
210
|
+
} catch {
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
this.deleteConnection(params.id);
|
|
214
|
+
}
|
|
215
|
+
if (this.connections.length === 0) {
|
|
216
|
+
this.emit("disconnect");
|
|
217
|
+
} else {
|
|
218
|
+
this.emitFirstAvailableConnection();
|
|
219
|
+
}
|
|
220
|
+
return { connections: this.connections };
|
|
221
|
+
}
|
|
222
|
+
async getAccounts(params) {
|
|
223
|
+
if (!this.sharedWcProvider) {
|
|
224
|
+
return { accounts: [] };
|
|
225
|
+
}
|
|
226
|
+
const accounts = appkitControllers.WcHelpersUtil.getWalletConnectAccounts(
|
|
227
|
+
this.sharedWcProvider,
|
|
228
|
+
"sui"
|
|
229
|
+
);
|
|
230
|
+
return {
|
|
231
|
+
accounts: accounts.map((a) => ({
|
|
232
|
+
namespace: "sui",
|
|
233
|
+
address: a.address,
|
|
234
|
+
type: "eoa"
|
|
235
|
+
}))
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
async getBalance(params) {
|
|
239
|
+
var _a, _b, _c;
|
|
240
|
+
if (!params.address) {
|
|
241
|
+
return { balance: "0", symbol: "SUI" };
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const caipNetwork = (_a = this.getCaipNetworks()) == null ? void 0 : _a.find(
|
|
245
|
+
(n) => n.id === params.chainId
|
|
246
|
+
);
|
|
247
|
+
const rpcUrl = `https://fullnode.${caipNetwork == null ? void 0 : caipNetwork.id}.sui.io:443`;
|
|
248
|
+
if (!rpcUrl) {
|
|
249
|
+
return { balance: "0", symbol: "SUI" };
|
|
250
|
+
}
|
|
251
|
+
const res = await fetch(rpcUrl, {
|
|
252
|
+
method: "POST",
|
|
253
|
+
headers: { "Content-Type": "application/json" },
|
|
254
|
+
body: JSON.stringify({
|
|
255
|
+
jsonrpc: "2.0",
|
|
256
|
+
id: 1,
|
|
257
|
+
method: "suix_getBalance",
|
|
258
|
+
params: [params.address, "0x2::sui::SUI"]
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
const data = await res.json();
|
|
262
|
+
const totalBalance = ((_b = data == null ? void 0 : data.result) == null ? void 0 : _b.totalBalance) ?? "0";
|
|
263
|
+
const formatted = (parseInt(totalBalance, 10) / 1e9).toString();
|
|
264
|
+
return {
|
|
265
|
+
balance: formatted,
|
|
266
|
+
symbol: ((_c = caipNetwork == null ? void 0 : caipNetwork.nativeCurrency) == null ? void 0 : _c.symbol) || "SUI"
|
|
267
|
+
};
|
|
268
|
+
} catch {
|
|
269
|
+
return { balance: "0", symbol: "SUI" };
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async switchNetwork(params) {
|
|
273
|
+
await super.switchNetwork(params);
|
|
274
|
+
}
|
|
275
|
+
async syncConnection(params) {
|
|
276
|
+
return this.connect({ ...params, type: "" });
|
|
277
|
+
}
|
|
278
|
+
async syncConnections({
|
|
279
|
+
connectToFirstConnector,
|
|
280
|
+
caipNetwork
|
|
281
|
+
}) {
|
|
282
|
+
if (!this.sharedWcProvider) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const accounts = appkitControllers.WcHelpersUtil.getWalletConnectAccounts(
|
|
286
|
+
this.sharedWcProvider,
|
|
287
|
+
"sui"
|
|
288
|
+
);
|
|
289
|
+
if (accounts.length > 0) {
|
|
290
|
+
this.addConnection({
|
|
291
|
+
connectorId: WC_ID,
|
|
292
|
+
accounts: accounts.map((a) => ({ address: a.address })),
|
|
293
|
+
caipNetwork
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
if (connectToFirstConnector) {
|
|
297
|
+
this.emitFirstAvailableConnection();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
getWalletConnectProvider(params) {
|
|
301
|
+
return params.provider;
|
|
302
|
+
}
|
|
303
|
+
async signMessage(params) {
|
|
304
|
+
const wc = this.getWcProvider();
|
|
305
|
+
const result = await wc.request(
|
|
306
|
+
{
|
|
307
|
+
method: "sui_signPersonalMessage",
|
|
308
|
+
params: { message: params.message, address: params.address }
|
|
309
|
+
},
|
|
310
|
+
"sui:mainnet"
|
|
311
|
+
);
|
|
312
|
+
return { signature: result.signature };
|
|
313
|
+
}
|
|
314
|
+
async sendTransaction(params) {
|
|
315
|
+
const wc = this.getWcProvider();
|
|
316
|
+
const result = await wc.request(
|
|
317
|
+
{
|
|
318
|
+
method: "sui_signAndExecuteTransaction",
|
|
319
|
+
params: { transaction: params.data, address: params.to }
|
|
320
|
+
},
|
|
321
|
+
"sui:mainnet"
|
|
322
|
+
);
|
|
323
|
+
return { hash: result.digest };
|
|
324
|
+
}
|
|
325
|
+
async estimateGas() {
|
|
326
|
+
return { gas: 0n };
|
|
327
|
+
}
|
|
328
|
+
async writeContract() {
|
|
329
|
+
return { hash: "" };
|
|
330
|
+
}
|
|
331
|
+
parseUnits() {
|
|
332
|
+
return 0n;
|
|
333
|
+
}
|
|
334
|
+
formatUnits() {
|
|
335
|
+
return "";
|
|
336
|
+
}
|
|
337
|
+
async getCapabilities() {
|
|
338
|
+
return {};
|
|
339
|
+
}
|
|
340
|
+
async grantPermissions() {
|
|
341
|
+
return {};
|
|
342
|
+
}
|
|
343
|
+
async revokePermissions() {
|
|
344
|
+
return "0x";
|
|
345
|
+
}
|
|
346
|
+
async walletGetAssets() {
|
|
347
|
+
return {};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
exports.SuiAdapter = SuiAdapter;
|