@sodax/wallet-sdk-react 2.0.0-rc.3 → 2.0.0-rc.5
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 +12 -5
- package/dist/{XConnector-B9YQTVJ4.d.ts → XConnector-12q0OVe5.d.ts} +1 -1
- package/dist/{chunk-NY7U7OJW.mjs → chunk-7V7O3Q7Y.mjs} +0 -2
- package/dist/{chunk-BXJLBR4G.mjs → chunk-C6M34IVL.mjs} +2 -4
- package/dist/{chunk-XZ7CHO2S.mjs → chunk-FSOGMSJH.mjs} +2 -4
- package/dist/{chunk-X2MHIWXO.mjs → chunk-IFXZQW4C.mjs} +0 -2
- package/dist/{chunk-7ULB6DW4.mjs → chunk-JQ4H4GJ5.mjs} +3 -5
- package/dist/{chunk-N5A2TMF6.mjs → chunk-LKSSME2J.mjs} +2 -4
- package/dist/{chunk-BKJB527E.mjs → chunk-MWWVB7TD.mjs} +2 -4
- package/dist/{chunk-MXZVF5HR.mjs → chunk-NAKCAL2M.mjs} +0 -2
- package/dist/{chunk-PJLEJVAU.mjs → chunk-OPYSVPRW.mjs} +10 -6
- package/dist/chunk-QMXBY3UI.mjs +1 -0
- package/dist/{chunk-MAQ47Q52.mjs → chunk-TACW7Z4D.mjs} +0 -2
- package/dist/{chunk-PLCA4ZDJ.mjs → chunk-VCESC6QT.mjs} +54 -30
- package/dist/{chunk-2BOUGCJ7.mjs → chunk-WPZOLGVB.mjs} +4 -6
- package/dist/{chunk-66BAUK56.mjs → chunk-X7BHR7WS.mjs} +4 -6
- package/dist/{chunk-E5IAZ7E6.mjs → chunk-Z5GXDHGL.mjs} +11 -7
- package/dist/{config-OlnzyEUE.d.ts → config-DEsqgrG1.d.ts} +10 -5
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +20 -31
- package/dist/xchains/bitcoin/index.d.ts +1 -1
- package/dist/xchains/bitcoin/index.mjs +14 -16
- package/dist/xchains/evm/index.d.ts +3 -3
- package/dist/xchains/evm/index.mjs +3 -5
- package/dist/xchains/icon/index.d.ts +1 -1
- package/dist/xchains/icon/index.mjs +5 -7
- package/dist/xchains/injective/index.d.ts +2 -2
- package/dist/xchains/injective/index.mjs +3 -5
- package/dist/xchains/near/index.d.ts +1 -1
- package/dist/xchains/near/index.mjs +4 -6
- package/dist/xchains/solana/index.d.ts +1 -1
- package/dist/xchains/solana/index.mjs +5 -7
- package/dist/xchains/stacks/index.d.ts +10 -4
- package/dist/xchains/stacks/index.mjs +3 -5
- package/dist/xchains/stellar/index.d.ts +1 -1
- package/dist/xchains/stellar/index.mjs +4 -6
- package/dist/xchains/sui/index.d.ts +1 -1
- package/dist/xchains/sui/index.mjs +5 -7
- package/docs/ADDING_A_NEW_CHAIN.md +1 -1
- package/docs/SUB_PATH_EXPORTS.md +14 -42
- package/package.json +35 -28
- package/ai-exported/AGENTS.md +0 -122
- package/ai-exported/integration/README.md +0 -102
- package/ai-exported/integration/ai-rules.md +0 -136
- package/ai-exported/integration/architecture.md +0 -181
- package/ai-exported/integration/examples/01-minimal-evm.tsx +0 -75
- package/ai-exported/integration/examples/02-multi-chain-modal.tsx +0 -169
- package/ai-exported/integration/examples/03-nextjs-app-router.tsx +0 -99
- package/ai-exported/integration/examples/04-walletconnect-setup.tsx +0 -89
- package/ai-exported/integration/examples/README.md +0 -29
- package/ai-exported/integration/recipes/batch-operations.md +0 -223
- package/ai-exported/integration/recipes/bridge-to-sdk.md +0 -164
- package/ai-exported/integration/recipes/chain-detection.md +0 -254
- package/ai-exported/integration/recipes/connect-button.md +0 -156
- package/ai-exported/integration/recipes/multi-chain-modal.md +0 -199
- package/ai-exported/integration/recipes/setup.md +0 -160
- package/ai-exported/integration/recipes/sign-message.md +0 -137
- package/ai-exported/integration/recipes/sub-path-imports.md +0 -95
- package/ai-exported/integration/recipes/switch-chain.md +0 -141
- package/ai-exported/integration/recipes/walletconnect-setup.md +0 -139
- package/ai-exported/integration/reference/api-surface.md +0 -175
- package/ai-exported/integration/reference/chain-support.md +0 -78
- package/ai-exported/integration/reference/connectors.md +0 -74
- package/ai-exported/integration/reference/hooks.md +0 -204
- package/ai-exported/integration/reference/wallet-brands.md +0 -106
- package/ai-exported/migration/README.md +0 -49
- package/ai-exported/migration/ai-rules.md +0 -144
- package/ai-exported/migration/breaking-changes.md +0 -305
- package/ai-exported/migration/checklist.md +0 -159
- package/ai-exported/migration/recipes/connect-button.md +0 -166
- package/ai-exported/migration/recipes/multi-chain-modal.md +0 -244
- package/ai-exported/migration/recipes/ssr-setup.md +0 -164
- package/ai-exported/migration/recipes/walletconnect-migration.md +0 -168
- package/ai-exported/migration/reference/components.md +0 -73
- package/ai-exported/migration/reference/config.md +0 -325
- package/ai-exported/migration/reference/hooks.md +0 -323
- package/ai-exported/migration/reference/imports.md +0 -157
- package/dist/chunk-2BOUGCJ7.mjs.map +0 -1
- package/dist/chunk-66BAUK56.mjs.map +0 -1
- package/dist/chunk-7ULB6DW4.mjs.map +0 -1
- package/dist/chunk-BKJB527E.mjs.map +0 -1
- package/dist/chunk-BXJLBR4G.mjs.map +0 -1
- package/dist/chunk-E5IAZ7E6.mjs.map +0 -1
- package/dist/chunk-MAQ47Q52.mjs.map +0 -1
- package/dist/chunk-MXZVF5HR.mjs.map +0 -1
- package/dist/chunk-N5A2TMF6.mjs.map +0 -1
- package/dist/chunk-NY7U7OJW.mjs.map +0 -1
- package/dist/chunk-PJLEJVAU.mjs.map +0 -1
- package/dist/chunk-PLCA4ZDJ.mjs.map +0 -1
- package/dist/chunk-TZMKDXFA.mjs +0 -3
- package/dist/chunk-TZMKDXFA.mjs.map +0 -1
- package/dist/chunk-X2MHIWXO.mjs.map +0 -1
- package/dist/chunk-XZ7CHO2S.mjs.map +0 -1
- package/dist/index.cjs +0 -3337
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/xchains/bitcoin/index.cjs +0 -1927
- package/dist/xchains/bitcoin/index.cjs.map +0 -1
- package/dist/xchains/bitcoin/index.mjs.map +0 -1
- package/dist/xchains/evm/index.cjs +0 -316
- package/dist/xchains/evm/index.cjs.map +0 -1
- package/dist/xchains/evm/index.mjs.map +0 -1
- package/dist/xchains/icon/index.cjs +0 -311
- package/dist/xchains/icon/index.cjs.map +0 -1
- package/dist/xchains/icon/index.mjs.map +0 -1
- package/dist/xchains/injective/index.cjs +0 -223
- package/dist/xchains/injective/index.cjs.map +0 -1
- package/dist/xchains/injective/index.mjs.map +0 -1
- package/dist/xchains/near/index.cjs +0 -190
- package/dist/xchains/near/index.cjs.map +0 -1
- package/dist/xchains/near/index.mjs.map +0 -1
- package/dist/xchains/solana/index.cjs +0 -186
- package/dist/xchains/solana/index.cjs.map +0 -1
- package/dist/xchains/solana/index.mjs.map +0 -1
- package/dist/xchains/stacks/index.cjs +0 -240
- package/dist/xchains/stacks/index.cjs.map +0 -1
- package/dist/xchains/stacks/index.mjs.map +0 -1
- package/dist/xchains/stellar/index.cjs +0 -322
- package/dist/xchains/stellar/index.cjs.map +0 -1
- package/dist/xchains/stellar/index.mjs.map +0 -1
- package/dist/xchains/sui/index.cjs +0 -248
- package/dist/xchains/sui/index.cjs.map +0 -1
- package/dist/xchains/sui/index.mjs.map +0 -1
- package/skills/SKILLS.md +0 -84
- package/skills/bridge-to-sdk.md +0 -148
- package/skills/connect-button.md +0 -116
- package/skills/evm-only-walletconnect.md +0 -111
- package/skills/multi-chain-modal.md +0 -178
- package/skills/setup.md +0 -107
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var stellarWalletsKit = require('@creit.tech/stellar-wallets-kit');
|
|
4
|
-
var StellarSdk = require('@stellar/stellar-sdk');
|
|
5
|
-
|
|
6
|
-
function _interopNamespace(e) {
|
|
7
|
-
if (e && e.__esModule) return e;
|
|
8
|
-
var n = Object.create(null);
|
|
9
|
-
if (e) {
|
|
10
|
-
Object.keys(e).forEach(function (k) {
|
|
11
|
-
if (k !== 'default') {
|
|
12
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return e[k]; }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
n.default = e;
|
|
21
|
-
return Object.freeze(n);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var StellarSdk__namespace = /*#__PURE__*/_interopNamespace(StellarSdk);
|
|
25
|
-
|
|
26
|
-
// src/core/XService.ts
|
|
27
|
-
var XService = class {
|
|
28
|
-
/** The blockchain type this service handles */
|
|
29
|
-
xChainType;
|
|
30
|
-
/** Available wallet connectors for this chain */
|
|
31
|
-
xConnectors = [];
|
|
32
|
-
constructor(xChainType) {
|
|
33
|
-
this.xChainType = xChainType;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Gets the balance of a specific token for an address
|
|
37
|
-
* @param address The wallet address to check
|
|
38
|
-
* @param xToken The token to get the balance for
|
|
39
|
-
* @returns Promise resolving to the token balance as a bigint
|
|
40
|
-
*/
|
|
41
|
-
async getBalance(address, xToken) {
|
|
42
|
-
return 0n;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Gets balances for multiple tokens for an address
|
|
46
|
-
* @param address The wallet address to check
|
|
47
|
-
* @param xTokens Array of tokens to get balances for
|
|
48
|
-
* @returns Promise resolving to object mapping token addresses to balances
|
|
49
|
-
*/
|
|
50
|
-
async getBalances(address, xTokens) {
|
|
51
|
-
if (!address) return {};
|
|
52
|
-
const balancePromises = xTokens.map(async (xToken) => {
|
|
53
|
-
const balance = await this.getBalance(address, xToken);
|
|
54
|
-
return { address: xToken.address, balance };
|
|
55
|
-
});
|
|
56
|
-
const balances = await Promise.all(balancePromises);
|
|
57
|
-
return balances.reduce((acc, { address: address2, balance }) => {
|
|
58
|
-
acc[address2] = balance;
|
|
59
|
-
return acc;
|
|
60
|
-
}, {});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Gets all available connectors for this chain
|
|
64
|
-
*/
|
|
65
|
-
getXConnectors() {
|
|
66
|
-
return this.xConnectors;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Sets the available connectors for this chain
|
|
70
|
-
*/
|
|
71
|
-
setXConnectors(xConnectors) {
|
|
72
|
-
this.xConnectors = xConnectors;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Gets a specific connector by its ID
|
|
76
|
-
* @param xConnectorId The connector ID to look up
|
|
77
|
-
* @returns The matching connector or undefined if not found
|
|
78
|
-
*/
|
|
79
|
-
getXConnectorById(xConnectorId) {
|
|
80
|
-
return this.getXConnectors().find((xConnector) => xConnector.id === xConnectorId);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var CustomSorobanServer = class extends StellarSdk.rpc.Server {
|
|
84
|
-
customHeaders;
|
|
85
|
-
constructor(serverUrl, customHeaders) {
|
|
86
|
-
super(serverUrl, {
|
|
87
|
-
allowHttp: true
|
|
88
|
-
});
|
|
89
|
-
this.customHeaders = customHeaders;
|
|
90
|
-
}
|
|
91
|
-
async simulateTransaction(tx) {
|
|
92
|
-
const requestOptions = {
|
|
93
|
-
method: "POST",
|
|
94
|
-
headers: {
|
|
95
|
-
"Content-Type": "application/json",
|
|
96
|
-
...this.customHeaders
|
|
97
|
-
},
|
|
98
|
-
body: JSON.stringify({
|
|
99
|
-
id: 1,
|
|
100
|
-
jsonrpc: "2.0",
|
|
101
|
-
method: "simulateTransaction",
|
|
102
|
-
params: {
|
|
103
|
-
transaction: tx.toXDR()
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
};
|
|
107
|
-
const response = await fetch(`${this.serverURL}`, requestOptions);
|
|
108
|
-
if (!response.ok) {
|
|
109
|
-
throw new Error(`HTTP error simulating TX! status: ${response.status}`);
|
|
110
|
-
}
|
|
111
|
-
return response.json().then((json) => StellarSdk.rpc.parseRawSimulation(json.result));
|
|
112
|
-
}
|
|
113
|
-
async sendTransaction(tx) {
|
|
114
|
-
const requestOptions = {
|
|
115
|
-
method: "POST",
|
|
116
|
-
headers: {
|
|
117
|
-
"Content-Type": "application/json",
|
|
118
|
-
...this.customHeaders
|
|
119
|
-
},
|
|
120
|
-
body: JSON.stringify({
|
|
121
|
-
id: 1,
|
|
122
|
-
jsonrpc: "2.0",
|
|
123
|
-
method: "sendTransaction",
|
|
124
|
-
params: {
|
|
125
|
-
transaction: tx.toXDR()
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
};
|
|
129
|
-
const response = await fetch(`${this.serverURL}`, requestOptions);
|
|
130
|
-
if (!response.ok) {
|
|
131
|
-
throw new Error(`HTTP error submitting TX! status: ${response.status}`);
|
|
132
|
-
}
|
|
133
|
-
return response.json().then((json) => json.result);
|
|
134
|
-
}
|
|
135
|
-
async getTransaction(hash) {
|
|
136
|
-
const requestOptions = {
|
|
137
|
-
method: "POST",
|
|
138
|
-
headers: {
|
|
139
|
-
"Content-Type": "application/json",
|
|
140
|
-
...this.customHeaders
|
|
141
|
-
},
|
|
142
|
-
body: JSON.stringify({
|
|
143
|
-
id: 1,
|
|
144
|
-
jsonrpc: "2.0",
|
|
145
|
-
method: "getTransaction",
|
|
146
|
-
params: { hash }
|
|
147
|
-
})
|
|
148
|
-
};
|
|
149
|
-
const response = await fetch(`${this.serverURL}`, requestOptions);
|
|
150
|
-
if (!response.ok) {
|
|
151
|
-
throw new Error(`HTTP error getting TX! status: ${response.status}`);
|
|
152
|
-
}
|
|
153
|
-
return response.json().then((json) => json.result);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
var CustomSorobanServer_default = CustomSorobanServer;
|
|
157
|
-
var accountToScVal = (account) => new StellarSdk.Address(account).toScVal();
|
|
158
|
-
var simulateTx = (tx, server) => server.simulateTransaction(tx);
|
|
159
|
-
var getTokenBalance = async (address, tokenId, txBuilder, server) => {
|
|
160
|
-
const params = [accountToScVal(address)];
|
|
161
|
-
const contract = new StellarSdk.Contract(tokenId);
|
|
162
|
-
const tx = txBuilder.addOperation(contract.call("balance", ...params)).setTimeout(StellarSdk.TimeoutInfinite).build();
|
|
163
|
-
const result = await simulateTx(tx, server);
|
|
164
|
-
if (!StellarSdk.rpc.Api.isSimulationSuccess(result)) {
|
|
165
|
-
throw new Error(`Simulation failed: ${JSON.stringify(result)}`);
|
|
166
|
-
}
|
|
167
|
-
return result.result ? StellarSdk.scValToBigInt(result.result.retval) : 0n;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
// src/constants.ts
|
|
171
|
-
var STELLAR_DEFAULT_HORIZON_RPC_URL = "https://horizon.stellar.org";
|
|
172
|
-
var STELLAR_DEFAULT_SOROBAN_RPC_URL = "https://rpc.ankr.com/stellar_soroban";
|
|
173
|
-
|
|
174
|
-
// src/xchains/stellar/StellarXService.ts
|
|
175
|
-
var STELLAR_BASE_RESERVE_STROOPS = 5e6;
|
|
176
|
-
function parseXlmBalanceToStroops(balanceStr) {
|
|
177
|
-
const parts = balanceStr.split(".");
|
|
178
|
-
const whole = parts[0] ?? "0";
|
|
179
|
-
const frac = (parts[1] ?? "").padEnd(7, "0").slice(0, 7);
|
|
180
|
-
return BigInt(whole + frac);
|
|
181
|
-
}
|
|
182
|
-
var StellarXService = class _StellarXService extends XService {
|
|
183
|
-
static instance;
|
|
184
|
-
walletsKit;
|
|
185
|
-
server;
|
|
186
|
-
sorobanServer;
|
|
187
|
-
constructor(horizonRpcUrl, sorobanRpcUrl) {
|
|
188
|
-
super("STELLAR");
|
|
189
|
-
this.walletsKit = new stellarWalletsKit.StellarWalletsKit({
|
|
190
|
-
network: stellarWalletsKit.WalletNetwork.PUBLIC,
|
|
191
|
-
modules: stellarWalletsKit.allowAllModules()
|
|
192
|
-
});
|
|
193
|
-
this.server = new StellarSdk__namespace.Horizon.Server(horizonRpcUrl ?? STELLAR_DEFAULT_HORIZON_RPC_URL, { allowHttp: true });
|
|
194
|
-
this.sorobanServer = new CustomSorobanServer_default(sorobanRpcUrl ?? STELLAR_DEFAULT_SOROBAN_RPC_URL, {});
|
|
195
|
-
}
|
|
196
|
-
static getInstance(horizonRpcUrl, sorobanRpcUrl) {
|
|
197
|
-
if (!_StellarXService.instance) {
|
|
198
|
-
_StellarXService.instance = new _StellarXService(horizonRpcUrl, sorobanRpcUrl);
|
|
199
|
-
} else {
|
|
200
|
-
if (horizonRpcUrl) {
|
|
201
|
-
_StellarXService.instance.server = new StellarSdk__namespace.Horizon.Server(horizonRpcUrl, { allowHttp: true });
|
|
202
|
-
}
|
|
203
|
-
if (sorobanRpcUrl) {
|
|
204
|
-
_StellarXService.instance.sorobanServer = new CustomSorobanServer_default(sorobanRpcUrl, {});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return _StellarXService.instance;
|
|
208
|
-
}
|
|
209
|
-
async getBalance(address, xToken) {
|
|
210
|
-
if (!address) return BigInt(0);
|
|
211
|
-
const stellarAccount = await this.server.loadAccount(address);
|
|
212
|
-
if (xToken.symbol === "XLM") {
|
|
213
|
-
const xlmBalance = stellarAccount.balances.find((balance) => balance.asset_type === "native");
|
|
214
|
-
if (xlmBalance) {
|
|
215
|
-
const rawBalanceStroops = parseXlmBalanceToStroops(xlmBalance.balance);
|
|
216
|
-
const sellingLiabilitiesStroops = xlmBalance.selling_liabilities ? parseXlmBalanceToStroops(xlmBalance.selling_liabilities) : BigInt(0);
|
|
217
|
-
const reserveFields = stellarAccount;
|
|
218
|
-
const subentryCount = reserveFields.subentry_count ?? 0;
|
|
219
|
-
const numSponsoring = reserveFields.num_sponsoring ?? 0;
|
|
220
|
-
const numSponsored = reserveFields.num_sponsored ?? 0;
|
|
221
|
-
const reserveCount = Math.max(0, 2 + subentryCount + numSponsoring - numSponsored);
|
|
222
|
-
const minBalanceStroops = BigInt(reserveCount) * BigInt(STELLAR_BASE_RESERVE_STROOPS) + sellingLiabilitiesStroops;
|
|
223
|
-
const availableStroops = rawBalanceStroops > minBalanceStroops ? rawBalanceStroops - minBalanceStroops : BigInt(0);
|
|
224
|
-
return availableStroops;
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
227
|
-
try {
|
|
228
|
-
const txBuilder = new StellarSdk__namespace.TransactionBuilder(stellarAccount, {
|
|
229
|
-
fee: StellarSdk__namespace.BASE_FEE,
|
|
230
|
-
networkPassphrase: StellarSdk__namespace.Networks.PUBLIC
|
|
231
|
-
});
|
|
232
|
-
const balance = await getTokenBalance(address, xToken.address, txBuilder, this.sorobanServer);
|
|
233
|
-
return balance;
|
|
234
|
-
} catch (e) {
|
|
235
|
-
console.error(`Error while fetching token on Stellar: ${xToken.symbol}, Error: ${e}`);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return BigInt(0);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
// src/core/XConnector.ts
|
|
243
|
-
var XConnector = class {
|
|
244
|
-
/** The blockchain type this connector supports */
|
|
245
|
-
xChainType;
|
|
246
|
-
/** Display name of the wallet provider */
|
|
247
|
-
name;
|
|
248
|
-
/** Unique identifier for the connector */
|
|
249
|
-
_id;
|
|
250
|
-
/** Optional icon URL for the wallet provider */
|
|
251
|
-
_icon;
|
|
252
|
-
constructor(xChainType, name, id) {
|
|
253
|
-
this.xChainType = xChainType;
|
|
254
|
-
this.name = name;
|
|
255
|
-
this._id = id;
|
|
256
|
-
}
|
|
257
|
-
/** Get the unique identifier for this connector */
|
|
258
|
-
get id() {
|
|
259
|
-
return this._id;
|
|
260
|
-
}
|
|
261
|
-
/** Get the optional icon URL for this wallet provider */
|
|
262
|
-
get icon() {
|
|
263
|
-
return this._icon;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* True when the wallet extension backing this connector is installed.
|
|
267
|
-
* Default: true (for provider-managed chains where connector presence already
|
|
268
|
-
* implies install — EVM via EIP-6963, Solana/Sui via adapter discovery).
|
|
269
|
-
* Subclasses backed by extension injection (Bitcoin, ICON, Stacks) override
|
|
270
|
-
* this with a window probe.
|
|
271
|
-
*/
|
|
272
|
-
get isInstalled() {
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
|
-
/** URL to install the wallet extension when missing. Subclasses override. */
|
|
276
|
-
get installUrl() {
|
|
277
|
-
return void 0;
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
// src/xchains/stellar/StellarWalletsKitXConnector.ts
|
|
282
|
-
var StellarWalletsKitXConnector = class extends XConnector {
|
|
283
|
-
_wallet;
|
|
284
|
-
constructor(wallet) {
|
|
285
|
-
super("STELLAR", wallet.name, wallet.id);
|
|
286
|
-
this._wallet = wallet;
|
|
287
|
-
}
|
|
288
|
-
getXService() {
|
|
289
|
-
return StellarXService.getInstance();
|
|
290
|
-
}
|
|
291
|
-
async connect() {
|
|
292
|
-
const kit = this.getXService().walletsKit;
|
|
293
|
-
if (!this._wallet) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
if (!this._wallet.isAvailable) {
|
|
297
|
-
throw new Error(`${this._wallet.name} is not installed. Install the wallet and reload the page.`);
|
|
298
|
-
}
|
|
299
|
-
kit.setWallet(this._wallet.id);
|
|
300
|
-
const { address } = await kit.getAddress();
|
|
301
|
-
return {
|
|
302
|
-
address,
|
|
303
|
-
xChainType: this.xChainType
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
async disconnect() {
|
|
307
|
-
}
|
|
308
|
-
get icon() {
|
|
309
|
-
return this._wallet.icon;
|
|
310
|
-
}
|
|
311
|
-
get isInstalled() {
|
|
312
|
-
return this._wallet.isAvailable;
|
|
313
|
-
}
|
|
314
|
-
get installUrl() {
|
|
315
|
-
return this._wallet.url;
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
exports.StellarWalletsKitXConnector = StellarWalletsKitXConnector;
|
|
320
|
-
exports.StellarXService = StellarXService;
|
|
321
|
-
//# sourceMappingURL=index.cjs.map
|
|
322
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/XService.ts","../../../src/xchains/stellar/CustomSorobanServer.ts","../../../src/xchains/stellar/utils.ts","../../../src/constants.ts","../../../src/xchains/stellar/StellarXService.ts","../../../src/core/XConnector.ts","../../../src/xchains/stellar/StellarWalletsKitXConnector.ts"],"names":["address","rpc","Address","Contract","TimeoutInfinite","scValToBigInt","StellarWalletsKit","WalletNetwork","allowAllModules","StellarSdk"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoBO,IAAe,WAAf,MAAiD;AAAA;AAAA,EAEtC,UAAA;AAAA;AAAA,EAGR,cAA6B,EAAC;AAAA,EAEtC,YAAY,UAAA,EAAuB;AACjC,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAa,UAAA,CAAW,OAAA,EAA6B,MAAA,EAAiC;AACpF,IAAA,OAAO,EAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAa,WAAA,CAAY,OAAA,EAA6B,OAAA,EAA6D;AACjH,IAAA,IAAI,CAAC,OAAA,EAAS,OAAO,EAAC;AAEtB,IAAA,MAAM,eAAA,GAAkB,OAAA,CAAQ,GAAA,CAAI,OAAM,MAAA,KAAU;AAClD,MAAA,MAAM,OAAA,GAAU,MAAM,IAAA,CAAK,UAAA,CAAW,SAAS,MAAM,CAAA;AACrD,MAAA,OAAO,EAAE,OAAA,EAAS,MAAA,CAAO,OAAA,EAAS,OAAA,EAAQ;AAAA,IAC5C,CAAC,CAAA;AAED,IAAA,MAAM,QAAA,GAAW,MAAM,OAAA,CAAQ,GAAA,CAAI,eAAe,CAAA;AAClD,IAAA,OAAO,QAAA,CAAS,OAA+B,CAAC,GAAA,EAAK,EAAE,OAAA,EAAAA,QAAAA,EAAS,SAAQ,KAAM;AAC5E,MAAA,GAAA,CAAIA,QAAO,CAAA,GAAI,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,CAAI,SAAA,CAAU,IAAA,CAAK,OAAA,CAAQ,EAAE,CAAA;AAC7B,IAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAM,IAAI,UAAA,EAAW;AAEzC,IAAA,OAAO;AAAA,MACL,OAAA;AAAA,MACA,YAAY,IAAA,CAAK;AAAA,KACnB;AAAA,EACF;AAAA,EAEA,MAAM,UAAA,GAA4B;AAAA,EAAC;AAAA,EAEnC,IAAoB,IAAA,GAAe;AACjC,IAAA,OAAO,KAAK,OAAA,CAAQ,IAAA;AAAA,EACtB;AAAA,EAEA,IAAoB,WAAA,GAAuB;AACzC,IAAA,OAAO,KAAK,OAAA,CAAQ,WAAA;AAAA,EACtB;AAAA,EAEA,IAAoB,UAAA,GAAiC;AACnD,IAAA,OAAO,KAAK,OAAA,CAAQ,GAAA;AAAA,EACtB;AACF","file":"index.cjs","sourcesContent":["import type { ChainType, IXServiceBase, XToken } from '@sodax/types';\nimport type { IXConnector } from '@/types/interfaces.js';\n\n/**\n * Abstract base class for blockchain service implementations.\n *\n * The XService class serves as a foundation for implementing blockchain-specific services\n * in a multi-chain environment. It provides a standardized interface for:\n * 1. Managing wallet connectors for different blockchain types\n * 2. Querying token balances across different chains\n *\n * Each blockchain implementation (e.g., Solana, EVM chains) extends this class\n * to provide chain-specific functionality while maintaining a consistent interface.\n *\n * @abstract\n * @class XService\n * @property {ChainType} xChainType - The blockchain type this service handles (e.g., 'SOLANA', 'EVM')\n * @property {XConnector[]} xConnectors - Available wallet connectors for this chain\n *\n */\nexport abstract class XService implements IXServiceBase {\n /** The blockchain type this service handles */\n public readonly xChainType: ChainType;\n\n /** Available wallet connectors for this chain */\n private xConnectors: IXConnector[] = [];\n\n constructor(xChainType: ChainType) {\n this.xChainType = xChainType;\n }\n\n /**\n * Gets the balance of a specific token for an address\n * @param address The wallet address to check\n * @param xToken The token to get the balance for\n * @returns Promise resolving to the token balance as a bigint\n */\n public async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {\n return 0n;\n }\n\n /**\n * Gets balances for multiple tokens for an address\n * @param address The wallet address to check\n * @param xTokens Array of tokens to get balances for\n * @returns Promise resolving to object mapping token addresses to balances\n */\n public async getBalances(address: string | undefined, xTokens: readonly XToken[]): Promise<Record<string, bigint>> {\n if (!address) return {};\n\n const balancePromises = xTokens.map(async xToken => {\n const balance = await this.getBalance(address, xToken);\n return { address: xToken.address, balance };\n });\n\n const balances = await Promise.all(balancePromises);\n return balances.reduce<Record<string, bigint>>((acc, { address, balance }) => {\n acc[address] = balance;\n return acc;\n }, {});\n }\n\n /**\n * Gets all available connectors for this chain\n */\n public getXConnectors(): IXConnector[] {\n return this.xConnectors;\n }\n\n /**\n * Sets the available connectors for this chain\n */\n public setXConnectors(xConnectors: IXConnector[]): void {\n this.xConnectors = xConnectors;\n }\n\n /**\n * Gets a specific connector by its ID\n * @param xConnectorId The connector ID to look up\n * @returns The matching connector or undefined if not found\n */\n public getXConnectorById(xConnectorId: string): IXConnector | undefined {\n return this.getXConnectors().find(xConnector => xConnector.id === xConnectorId);\n }\n}\n","import {\n type FeeBumpTransaction,\n type Memo,\n type MemoType,\n type Operation,\n rpc,\n type Transaction,\n} from '@stellar/stellar-sdk';\n\nclass CustomSorobanServer extends rpc.Server {\n private readonly customHeaders: Record<string, string>;\n\n constructor(serverUrl: string, customHeaders: Record<string, string>) {\n super(serverUrl, {\n allowHttp: true,\n });\n this.customHeaders = customHeaders;\n }\n\n override async simulateTransaction(\n tx: Transaction<Memo<MemoType>, Operation[]>,\n ): Promise<rpc.Api.SimulateTransactionResponse> {\n const requestOptions = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.customHeaders,\n },\n body: JSON.stringify({\n id: 1,\n jsonrpc: '2.0',\n method: 'simulateTransaction',\n params: {\n transaction: tx.toXDR(),\n },\n }),\n };\n\n const response = await fetch(`${this.serverURL}`, requestOptions);\n if (!response.ok) {\n throw new Error(`HTTP error simulating TX! status: ${response.status}`);\n }\n // Parse raw JSON-RPC payload into the discriminated union expected by callers\n return response.json().then(json => rpc.parseRawSimulation(json.result));\n }\n\n override async sendTransaction(tx: Transaction | FeeBumpTransaction): Promise<rpc.Api.SendTransactionResponse> {\n const requestOptions = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.customHeaders,\n },\n body: JSON.stringify({\n id: 1,\n jsonrpc: '2.0',\n method: 'sendTransaction',\n params: {\n transaction: tx.toXDR(),\n },\n }),\n };\n\n const response = await fetch(`${this.serverURL}`, requestOptions);\n if (!response.ok) {\n throw new Error(`HTTP error submitting TX! status: ${response.status}`);\n }\n return response.json().then(json => json.result);\n }\n\n override async getTransaction(hash: string): Promise<rpc.Api.GetTransactionResponse> {\n const requestOptions = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.customHeaders,\n },\n body: JSON.stringify({\n id: 1,\n jsonrpc: '2.0',\n method: 'getTransaction',\n params: { hash },\n }),\n };\n\n const response = await fetch(`${this.serverURL}`, requestOptions);\n if (!response.ok) {\n throw new Error(`HTTP error getting TX! status: ${response.status}`);\n }\n return response.json().then(json => json.result);\n }\n}\n\nexport default CustomSorobanServer;\n","import {\n Address,\n Contract,\n type Memo,\n type MemoType,\n type Operation,\n rpc,\n TimeoutInfinite,\n type Transaction,\n type TransactionBuilder,\n scValToBigInt,\n} from '@stellar/stellar-sdk';\nimport type CustomSorobanServer from './CustomSorobanServer.js';\n\nexport const STELLAR_RLP_MSG_TYPE = { type: 'symbol' };\n\n// Can be used whenever you need an Address argument for a contract method\nexport const accountToScVal = (account: string) => new Address(account).toScVal();\n\nexport const simulateTx = (\n tx: Transaction<Memo<MemoType>, Operation[]>,\n server: CustomSorobanServer,\n): Promise<rpc.Api.SimulateTransactionResponse> => server.simulateTransaction(tx);\n\nexport const getTokenBalance = async (\n address: string,\n tokenId: string,\n txBuilder: TransactionBuilder,\n server: CustomSorobanServer,\n) => {\n const params = [accountToScVal(address)];\n const contract = new Contract(tokenId);\n const tx = txBuilder\n .addOperation(contract.call('balance', ...params))\n .setTimeout(TimeoutInfinite)\n .build();\n\n const result = await simulateTx(tx, server);\n\n // Also throws on restore responses — invalid for read-only balance simulation\n if (!rpc.Api.isSimulationSuccess(result)) {\n throw new Error(`Simulation failed: ${JSON.stringify(result)}`);\n }\n\n return result.result ? scValToBigInt(result.result.retval) : 0n;\n};\n","/**\n * Default values used across providers and hydrators.\n * Centralized so consumers and tests have a single source of truth.\n */\n\n// ─── Stacks ─────────────────────────────────────────────────────────────────\nexport const STACKS_DEFAULT_RPC_URL = 'https://api.mainnet.hiro.so';\nexport const STACKS_DEFAULT_NETWORK = 'mainnet' as const;\n\n// ─── Sui ────────────────────────────────────────────────────────────────────\nexport const SUI_DEFAULT_NETWORK = 'mainnet' as const;\nexport const SUI_DEFAULT_AUTO_CONNECT = true;\n\n// ─── EVM ────────────────────────────────────────────────────────────────────\nexport const EVM_DEFAULT_RECONNECT_ON_MOUNT = false;\nexport const EVM_DEFAULT_SSR = true;\n\n// ─── Solana ─────────────────────────────────────────────────────────────────\nexport const SOLANA_DEFAULT_AUTO_CONNECT = true;\nexport const SOLANA_DEFAULT_RPC_URL = 'https://api.mainnet-beta.solana.com';\n/** Timeout for MetaMask Solana wallet connect — MetaMask's Solana adapter is slow to fire `connect`. */\nexport const SOLANA_METAMASK_CONNECT_TIMEOUT_MS = 30_000;\n\n// ─── Bitcoin ────────────────────────────────────────────────────────────────\nexport const BITCOIN_DEFAULT_RPC_URL = 'https://mempool.space/api';\n\n// ─── Stellar ────────────────────────────────────────────────────────────────\nexport const STELLAR_DEFAULT_HORIZON_RPC_URL = 'https://horizon.stellar.org';\nexport const STELLAR_DEFAULT_SOROBAN_RPC_URL = 'https://rpc.ankr.com/stellar_soroban';\n\n// ─── NEAR ───────────────────────────────────────────────────────────────────\nexport const NEAR_DEFAULT_RPC_URL = 'https://1rpc.io/near';\n\n// ─── Wallet metadata (install URLs + icons for extension-based wallets) ────\n// Keys are wallet-level, not per-connector: one OKX extension serves both\n// Bitcoin and EVM connectors, so metadata is shared.\n\nexport const WALLET_METADATA = {\n unisat: {\n installUrl: 'https://chromewebstore.google.com/detail/unisat-wallet/ppbibelpcjmhbdihakflkdcoccbgbkpo',\n icon: 'https://avatars.githubusercontent.com/u/125119198?s=200&v=4',\n },\n xverse: {\n installUrl: 'https://chromewebstore.google.com/detail/xverse-bitcoin-crypto-wal/idnnbdplmphpflfnlkomgpfbpcgelopg',\n icon:\n 'https://cdn.brandfetch.io/iddzGN5Rcv/w/400/h/400/theme/dark/icon.jpeg?c=1bxid64Mup7aczewSAYMX&t=1771902357797',\n },\n okx: {\n installUrl: 'https://chromewebstore.google.com/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge',\n icon: 'https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png',\n },\n hana: {\n installUrl: 'https://chromewebstore.google.com/detail/hana-wallet/jfdlamikmbghhapbgfoogdffldioobgl',\n icon: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/hana.svg',\n },\n} as const satisfies Record<string, { installUrl: string; icon: string }>;\n","import { XService } from '@/core/XService.js';\nimport { StellarWalletsKit, WalletNetwork, allowAllModules } from '@creit.tech/stellar-wallets-kit';\nimport * as StellarSdk from '@stellar/stellar-sdk';\nimport CustomSorobanServer from './CustomSorobanServer.js';\nimport { getTokenBalance } from './utils.js';\nimport type { XToken } from '@sodax/types';\nimport { STELLAR_DEFAULT_HORIZON_RPC_URL, STELLAR_DEFAULT_SOROBAN_RPC_URL } from '@/constants.js';\n\n/** Base reserve in stroops (0.5 XLM). Each subentry (trustline, signer, data entry, offer) adds one base reserve. */\nconst STELLAR_BASE_RESERVE_STROOPS = 5_000_000;\n\n/** Horizon account fields used for minimum balance. Minimum = (2 + subentry_count + num_sponsoring - num_sponsored) * base_reserve + selling_liabilities. */\ninterface StellarAccountReserveFields {\n subentry_count?: number;\n num_sponsoring?: number;\n num_sponsored?: number;\n}\n\n/** Parse XLM balance string (e.g. \"198.8944970\") to stroops (1 XLM = 10^7 stroops). */\nfunction parseXlmBalanceToStroops(balanceStr: string): bigint {\n const parts = balanceStr.split('.');\n const whole = parts[0] ?? '0';\n const frac = (parts[1] ?? '').padEnd(7, '0').slice(0, 7);\n return BigInt(whole + frac);\n}\n\nexport class StellarXService extends XService {\n private static instance: StellarXService;\n\n public walletsKit: StellarWalletsKit;\n public server: StellarSdk.Horizon.Server;\n public sorobanServer: CustomSorobanServer;\n\n private constructor(horizonRpcUrl?: string, sorobanRpcUrl?: string) {\n super('STELLAR');\n\n this.walletsKit = new StellarWalletsKit({\n network: WalletNetwork.PUBLIC,\n modules: allowAllModules(),\n });\n\n this.server = new StellarSdk.Horizon.Server(horizonRpcUrl ?? STELLAR_DEFAULT_HORIZON_RPC_URL, { allowHttp: true });\n this.sorobanServer = new CustomSorobanServer(sorobanRpcUrl ?? STELLAR_DEFAULT_SOROBAN_RPC_URL, {});\n }\n\n public static getInstance(horizonRpcUrl?: string, sorobanRpcUrl?: string): StellarXService {\n if (!StellarXService.instance) {\n StellarXService.instance = new StellarXService(horizonRpcUrl, sorobanRpcUrl);\n } else {\n if (horizonRpcUrl) {\n StellarXService.instance.server = new StellarSdk.Horizon.Server(horizonRpcUrl, { allowHttp: true });\n }\n if (sorobanRpcUrl) {\n StellarXService.instance.sorobanServer = new CustomSorobanServer(sorobanRpcUrl, {});\n }\n }\n return StellarXService.instance;\n }\n\n override async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {\n if (!address) return BigInt(0);\n\n const stellarAccount = await this.server.loadAccount(address);\n\n if (xToken.symbol === 'XLM') {\n const xlmBalance = stellarAccount.balances.find(balance => balance.asset_type === 'native');\n if (xlmBalance) {\n const rawBalanceStroops = parseXlmBalanceToStroops(xlmBalance.balance);\n const sellingLiabilitiesStroops = (xlmBalance as { selling_liabilities?: string }).selling_liabilities\n ? parseXlmBalanceToStroops((xlmBalance as { selling_liabilities: string }).selling_liabilities)\n : BigInt(0);\n const reserveFields = stellarAccount as unknown as StellarAccountReserveFields;\n const subentryCount = reserveFields.subentry_count ?? 0;\n const numSponsoring = reserveFields.num_sponsoring ?? 0;\n const numSponsored = reserveFields.num_sponsored ?? 0;\n // Minimum balance = (2 + subentry_count + num_sponsoring - num_sponsored) * base_reserve + selling_liabilities.\n // When account has sponsored reserves (num_sponsored > 0), those reserves are paid by the sponsor, so we don't subtract them.\n const reserveCount = Math.max(0, 2 + subentryCount + numSponsoring - numSponsored);\n const minBalanceStroops =\n BigInt(reserveCount) * BigInt(STELLAR_BASE_RESERVE_STROOPS) + sellingLiabilitiesStroops;\n const availableStroops =\n rawBalanceStroops > minBalanceStroops ? rawBalanceStroops - minBalanceStroops : BigInt(0);\n return availableStroops;\n }\n } else {\n try {\n const txBuilder = new StellarSdk.TransactionBuilder(stellarAccount, {\n fee: StellarSdk.BASE_FEE,\n networkPassphrase: StellarSdk.Networks.PUBLIC,\n });\n\n const balance = await getTokenBalance(address, xToken.address, txBuilder, this.sorobanServer);\n return balance;\n } catch (e) {\n console.error(`Error while fetching token on Stellar: ${xToken.symbol}, Error: ${e}`);\n }\n }\n\n return BigInt(0);\n }\n}\n","import type { ChainType } from '@sodax/types';\nimport type { XAccount } from '@/types/index.js';\nimport type { IXConnector } from '@/types/interfaces.js';\n\n/**\n * Base class for wallet provider connectors that handles connection management and wallet interactions\n *\n * @abstract\n * @class XConnector\n * @property {ChainType} xChainType - The blockchain type this connector supports\n * @property {string} name - Display name of the wallet provider\n * @property {string} _id - Unique identifier for the connector\n * @property {string | undefined} _icon - Optional icon URL for the wallet provider\n */\n\nexport abstract class XConnector implements IXConnector {\n /** The blockchain type this connector supports */\n public readonly xChainType: ChainType;\n\n /** Display name of the wallet provider */\n public readonly name: string;\n\n /** Unique identifier for the connector */\n public readonly _id: string;\n\n /** Optional icon URL for the wallet provider */\n public readonly _icon?: string;\n\n constructor(xChainType: ChainType, name: string, id: string) {\n this.xChainType = xChainType;\n this.name = name;\n this._id = id;\n }\n\n /**\n * Connects to the wallet provider\n * @returns Promise resolving to the connected account, or undefined if connection fails\n */\n abstract connect(): Promise<XAccount | undefined>;\n\n /**\n * Disconnects from the wallet provider\n */\n abstract disconnect(): Promise<void>;\n\n /** Get the unique identifier for this connector */\n public get id(): string {\n return this._id;\n }\n\n /** Get the optional icon URL for this wallet provider */\n public get icon(): string | undefined {\n return this._icon;\n }\n\n /**\n * True when the wallet extension backing this connector is installed.\n * Default: true (for provider-managed chains where connector presence already\n * implies install — EVM via EIP-6963, Solana/Sui via adapter discovery).\n * Subclasses backed by extension injection (Bitcoin, ICON, Stacks) override\n * this with a window probe.\n */\n public get isInstalled(): boolean {\n return true;\n }\n\n /** URL to install the wallet extension when missing. Subclasses override. */\n public get installUrl(): string | undefined {\n return undefined;\n }\n}\n","import type { XAccount } from '@/types/index.js';\n\nimport { XConnector } from '@/core/index.js';\nimport { StellarXService } from './StellarXService.js';\n\nexport type StellarWalletType = {\n icon: string;\n id: string;\n isAvailable: boolean;\n name: string;\n type: string;\n url: string;\n};\n\nexport class StellarWalletsKitXConnector extends XConnector {\n _wallet: StellarWalletType;\n\n constructor(wallet: StellarWalletType) {\n super('STELLAR', wallet.name, wallet.id);\n this._wallet = wallet;\n }\n\n getXService(): StellarXService {\n return StellarXService.getInstance();\n }\n\n async connect(): Promise<XAccount | undefined> {\n const kit = this.getXService().walletsKit;\n\n if (!this._wallet) {\n return;\n }\n\n if (!this._wallet.isAvailable) {\n // Throw instead of silently navigating to the install URL — callers\n // that bypass `useWalletModal.selectWallet`'s pre-check otherwise\n // see a tab open with no surfaced error. Consumers read\n // `connector.installUrl` to render the install CTA on the caught\n // error.\n throw new Error(`${this._wallet.name} is not installed. Install the wallet and reload the page.`);\n }\n\n kit.setWallet(this._wallet.id);\n const { address } = await kit.getAddress();\n\n return {\n address: address,\n xChainType: this.xChainType,\n };\n }\n\n async disconnect(): Promise<void> {}\n\n public override get icon(): string {\n return this._wallet.icon;\n }\n\n public override get isInstalled(): boolean {\n return this._wallet.isAvailable;\n }\n\n public override get installUrl(): string | undefined {\n return this._wallet.url;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs"}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var walletSdkCore = require('@sodax/wallet-sdk-core');
|
|
4
|
-
require('@sodax/types');
|
|
5
|
-
|
|
6
|
-
// src/core/XService.ts
|
|
7
|
-
var XService = class {
|
|
8
|
-
/** The blockchain type this service handles */
|
|
9
|
-
xChainType;
|
|
10
|
-
/** Available wallet connectors for this chain */
|
|
11
|
-
xConnectors = [];
|
|
12
|
-
constructor(xChainType) {
|
|
13
|
-
this.xChainType = xChainType;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Gets the balance of a specific token for an address
|
|
17
|
-
* @param address The wallet address to check
|
|
18
|
-
* @param xToken The token to get the balance for
|
|
19
|
-
* @returns Promise resolving to the token balance as a bigint
|
|
20
|
-
*/
|
|
21
|
-
async getBalance(address, xToken) {
|
|
22
|
-
return 0n;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Gets balances for multiple tokens for an address
|
|
26
|
-
* @param address The wallet address to check
|
|
27
|
-
* @param xTokens Array of tokens to get balances for
|
|
28
|
-
* @returns Promise resolving to object mapping token addresses to balances
|
|
29
|
-
*/
|
|
30
|
-
async getBalances(address, xTokens) {
|
|
31
|
-
if (!address) return {};
|
|
32
|
-
const balancePromises = xTokens.map(async (xToken) => {
|
|
33
|
-
const balance = await this.getBalance(address, xToken);
|
|
34
|
-
return { address: xToken.address, balance };
|
|
35
|
-
});
|
|
36
|
-
const balances = await Promise.all(balancePromises);
|
|
37
|
-
return balances.reduce((acc, { address: address2, balance }) => {
|
|
38
|
-
acc[address2] = balance;
|
|
39
|
-
return acc;
|
|
40
|
-
}, {});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Gets all available connectors for this chain
|
|
44
|
-
*/
|
|
45
|
-
getXConnectors() {
|
|
46
|
-
return this.xConnectors;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Sets the available connectors for this chain
|
|
50
|
-
*/
|
|
51
|
-
setXConnectors(xConnectors) {
|
|
52
|
-
this.xConnectors = xConnectors;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Gets a specific connector by its ID
|
|
56
|
-
* @param xConnectorId The connector ID to look up
|
|
57
|
-
* @returns The matching connector or undefined if not found
|
|
58
|
-
*/
|
|
59
|
-
getXConnectorById(xConnectorId) {
|
|
60
|
-
return this.getXConnectors().find((xConnector) => xConnector.id === xConnectorId);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// src/utils/index.ts
|
|
65
|
-
var isNativeToken = (xToken) => {
|
|
66
|
-
const nativeAddresses = [
|
|
67
|
-
"cx0000000000000000000000000000000000000000",
|
|
68
|
-
"0x0000000000000000000000000000000000000000",
|
|
69
|
-
"inj",
|
|
70
|
-
"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
71
|
-
"hx0000000000000000000000000000000000000000",
|
|
72
|
-
"11111111111111111111111111111111",
|
|
73
|
-
// solana
|
|
74
|
-
"CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA",
|
|
75
|
-
// stellar
|
|
76
|
-
"ST000000000000000000002AMW42H.nativetoken",
|
|
77
|
-
// stacks
|
|
78
|
-
"0:0"
|
|
79
|
-
// bitcoin
|
|
80
|
-
];
|
|
81
|
-
return nativeAddresses.includes(xToken.address);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// src/shared/guards.ts
|
|
85
|
-
function isRecord(value) {
|
|
86
|
-
return typeof value === "object" && value !== null;
|
|
87
|
-
}
|
|
88
|
-
function hasStringProperty(value, key) {
|
|
89
|
-
return isRecord(value) && typeof value[key] === "string";
|
|
90
|
-
}
|
|
91
|
-
function hasOptionalStringProperty(value, key) {
|
|
92
|
-
return isRecord(value) && (value[key] === void 0 || typeof value[key] === "string");
|
|
93
|
-
}
|
|
94
|
-
function hasFunctionProperty(value, key) {
|
|
95
|
-
return isRecord(value) && typeof value[key] === "function";
|
|
96
|
-
}
|
|
97
|
-
function assert(condition, message) {
|
|
98
|
-
if (!condition) {
|
|
99
|
-
throw new Error(message);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function assertSuiProviderShape(caller, client, wallet, account) {
|
|
103
|
-
const clientOk = isRecord(client) && hasFunctionProperty(client, "executeTransactionBlock") && hasFunctionProperty(client, "devInspectTransactionBlock") && hasFunctionProperty(client, "getCoins");
|
|
104
|
-
assert(clientOk, `[${caller}] invalid Sui client shape`);
|
|
105
|
-
const walletOk = isRecord(wallet) && hasStringProperty(wallet, "name");
|
|
106
|
-
assert(walletOk, `[${caller}] invalid Sui wallet shape`);
|
|
107
|
-
const accountOk = isRecord(account) && hasStringProperty(account, "address");
|
|
108
|
-
assert(accountOk, `[${caller}] invalid Sui account shape`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// src/xchains/sui/SuiXService.ts
|
|
112
|
-
var SuiXService = class _SuiXService extends XService {
|
|
113
|
-
static instance;
|
|
114
|
-
// Hydrated by SuiHydrator. Start undefined because wallet may not be connected yet.
|
|
115
|
-
// suiClient is typed structurally for the methods we call directly.
|
|
116
|
-
// suiWallet/suiAccount are opaque — stored and passed through to SuiWalletProvider.
|
|
117
|
-
suiClient;
|
|
118
|
-
suiWallet;
|
|
119
|
-
suiAccount;
|
|
120
|
-
constructor() {
|
|
121
|
-
super("SUI");
|
|
122
|
-
}
|
|
123
|
-
static getInstance() {
|
|
124
|
-
if (!_SuiXService.instance) {
|
|
125
|
-
_SuiXService.instance = new _SuiXService();
|
|
126
|
-
}
|
|
127
|
-
return _SuiXService.instance;
|
|
128
|
-
}
|
|
129
|
-
createWalletProvider() {
|
|
130
|
-
if (!this.suiClient || !this.suiWallet || !this.suiAccount) {
|
|
131
|
-
console.warn(
|
|
132
|
-
"[SuiXService] createWalletProvider: missing dependencies \u2014 wallet not connected yet",
|
|
133
|
-
{ hasClient: !!this.suiClient, hasWallet: !!this.suiWallet, hasAccount: !!this.suiAccount }
|
|
134
|
-
);
|
|
135
|
-
return void 0;
|
|
136
|
-
}
|
|
137
|
-
assertSuiProviderShape("SuiXService", this.suiClient, this.suiWallet, this.suiAccount);
|
|
138
|
-
return new walletSdkCore.SuiWalletProvider({
|
|
139
|
-
client: this.suiClient,
|
|
140
|
-
wallet: this.suiWallet,
|
|
141
|
-
account: this.suiAccount
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
// getBalance is not used because getBalances uses getAllBalances which returns all balances
|
|
145
|
-
async getBalances(address, xTokens) {
|
|
146
|
-
if (!address || !this.suiClient) return {};
|
|
147
|
-
const client = this.suiClient;
|
|
148
|
-
try {
|
|
149
|
-
const balancePromises = xTokens.map(async (xToken) => {
|
|
150
|
-
let coinType = isNativeToken(xToken) ? "0x2::sui::SUI" : xToken.address;
|
|
151
|
-
if (coinType === "0x03917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR") {
|
|
152
|
-
coinType = "0x3917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR";
|
|
153
|
-
}
|
|
154
|
-
const balance = await client.getBalance({
|
|
155
|
-
owner: address,
|
|
156
|
-
coinType
|
|
157
|
-
});
|
|
158
|
-
return {
|
|
159
|
-
address: xToken.address,
|
|
160
|
-
balance: balance ? BigInt(balance.totalBalance) : void 0
|
|
161
|
-
};
|
|
162
|
-
});
|
|
163
|
-
const results = await Promise.all(balancePromises);
|
|
164
|
-
const tokenMap = {};
|
|
165
|
-
results.forEach((result) => {
|
|
166
|
-
if (result.balance !== void 0) {
|
|
167
|
-
tokenMap[result.address] = result.balance;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
return tokenMap;
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error("[wallet-sdk-react] SUI getBalances failed:", error);
|
|
173
|
-
return {};
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// src/core/XConnector.ts
|
|
179
|
-
var XConnector = class {
|
|
180
|
-
/** The blockchain type this connector supports */
|
|
181
|
-
xChainType;
|
|
182
|
-
/** Display name of the wallet provider */
|
|
183
|
-
name;
|
|
184
|
-
/** Unique identifier for the connector */
|
|
185
|
-
_id;
|
|
186
|
-
/** Optional icon URL for the wallet provider */
|
|
187
|
-
_icon;
|
|
188
|
-
constructor(xChainType, name, id) {
|
|
189
|
-
this.xChainType = xChainType;
|
|
190
|
-
this.name = name;
|
|
191
|
-
this._id = id;
|
|
192
|
-
}
|
|
193
|
-
/** Get the unique identifier for this connector */
|
|
194
|
-
get id() {
|
|
195
|
-
return this._id;
|
|
196
|
-
}
|
|
197
|
-
/** Get the optional icon URL for this wallet provider */
|
|
198
|
-
get icon() {
|
|
199
|
-
return this._icon;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* True when the wallet extension backing this connector is installed.
|
|
203
|
-
* Default: true (for provider-managed chains where connector presence already
|
|
204
|
-
* implies install — EVM via EIP-6963, Solana/Sui via adapter discovery).
|
|
205
|
-
* Subclasses backed by extension injection (Bitcoin, ICON, Stacks) override
|
|
206
|
-
* this with a window probe.
|
|
207
|
-
*/
|
|
208
|
-
get isInstalled() {
|
|
209
|
-
return true;
|
|
210
|
-
}
|
|
211
|
-
/** URL to install the wallet extension when missing. Subclasses override. */
|
|
212
|
-
get installUrl() {
|
|
213
|
-
return void 0;
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
// src/xchains/sui/SuiXConnector.ts
|
|
218
|
-
var isSuiWalletInfo = (value) => {
|
|
219
|
-
return isRecord(value) && hasStringProperty(value, "name") && // Some wallets may not expose `id` — in that case we fall back to `name` for stability.
|
|
220
|
-
// We still validate if it exists.
|
|
221
|
-
hasOptionalStringProperty(value, "id") && hasOptionalStringProperty(value, "icon");
|
|
222
|
-
};
|
|
223
|
-
var SuiXConnector = class extends XConnector {
|
|
224
|
-
wallet;
|
|
225
|
-
constructor(wallet) {
|
|
226
|
-
assert(isSuiWalletInfo(wallet), "[SuiXConnector] invalid wallet object");
|
|
227
|
-
const id = wallet.id ?? wallet.name;
|
|
228
|
-
assert(typeof id === "string" && id.length > 0, "[SuiXConnector] invalid wallet id");
|
|
229
|
-
super("SUI", wallet.name, id);
|
|
230
|
-
this.wallet = { id, name: wallet.name, icon: wallet.icon };
|
|
231
|
-
}
|
|
232
|
-
getXService() {
|
|
233
|
-
return SuiXService.getInstance();
|
|
234
|
-
}
|
|
235
|
-
async connect() {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
async disconnect() {
|
|
239
|
-
}
|
|
240
|
-
get icon() {
|
|
241
|
-
return this.wallet.icon;
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
exports.SuiXConnector = SuiXConnector;
|
|
246
|
-
exports.SuiXService = SuiXService;
|
|
247
|
-
//# sourceMappingURL=index.cjs.map
|
|
248
|
-
//# sourceMappingURL=index.cjs.map
|