@sodax/wallet-sdk-react 1.0.4-beta → 1.1.0-beta-rc2
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 +1 -1
- package/dist/index.cjs +22 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +24 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/xchains/evm/EvmXService.ts +17 -3
- package/src/xchains/stellar/StellarXService.ts +34 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sodax/wallet-sdk-react",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0-beta-rc2",
|
|
5
5
|
"description": "Wallet SDK of Sodax",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"wagmi": "2.16.9",
|
|
47
47
|
"zustand": "4.5.2",
|
|
48
48
|
"bs58": "6.0.0",
|
|
49
|
-
"@sodax/wallet-sdk-core": "1.0
|
|
50
|
-
"@sodax/types": "1.0
|
|
49
|
+
"@sodax/wallet-sdk-core": "1.1.0-beta-rc2",
|
|
50
|
+
"@sodax/types": "1.1.0-beta-rc2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/react": "^19.0.8",
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
BSC_MAINNET_CHAIN_ID,
|
|
7
7
|
ETHEREUM_MAINNET_CHAIN_ID,
|
|
8
8
|
HYPEREVM_MAINNET_CHAIN_ID,
|
|
9
|
+
KAIA_MAINNET_CHAIN_ID,
|
|
9
10
|
LIGHTLINK_MAINNET_CHAIN_ID,
|
|
10
11
|
OPTIMISM_MAINNET_CHAIN_ID,
|
|
11
12
|
POLYGON_MAINNET_CHAIN_ID,
|
|
@@ -18,7 +19,18 @@ import { getWagmiChainId, isNativeToken } from '@/utils';
|
|
|
18
19
|
import { type Address, defineChain, erc20Abi } from 'viem';
|
|
19
20
|
import { getPublicClient } from 'wagmi/actions';
|
|
20
21
|
import { type Config, createConfig, http } from 'wagmi';
|
|
21
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
mainnet,
|
|
24
|
+
avalanche,
|
|
25
|
+
base,
|
|
26
|
+
optimism,
|
|
27
|
+
polygon,
|
|
28
|
+
arbitrum,
|
|
29
|
+
bsc,
|
|
30
|
+
sonic,
|
|
31
|
+
lightlinkPhoenix,
|
|
32
|
+
kaia,
|
|
33
|
+
} from 'wagmi/chains';
|
|
22
34
|
|
|
23
35
|
// HyperEVM chain is not supported by viem, so we need to define it manually
|
|
24
36
|
export const hyper = /*#__PURE__*/ defineChain({
|
|
@@ -48,7 +60,7 @@ export const hyper = /*#__PURE__*/ defineChain({
|
|
|
48
60
|
|
|
49
61
|
export const createWagmiConfig = (config: RpcConfig) => {
|
|
50
62
|
return createConfig({
|
|
51
|
-
chains: [mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, hyper, lightlinkPhoenix],
|
|
63
|
+
chains: [mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, hyper, lightlinkPhoenix, kaia],
|
|
52
64
|
ssr: true,
|
|
53
65
|
transports: {
|
|
54
66
|
[mainnet.id]: http(config[ETHEREUM_MAINNET_CHAIN_ID]),
|
|
@@ -61,6 +73,7 @@ export const createWagmiConfig = (config: RpcConfig) => {
|
|
|
61
73
|
[polygon.id]: http(config[POLYGON_MAINNET_CHAIN_ID]),
|
|
62
74
|
[hyper.id]: http(config[HYPEREVM_MAINNET_CHAIN_ID]),
|
|
63
75
|
[lightlinkPhoenix.id]: http(config[LIGHTLINK_MAINNET_CHAIN_ID]),
|
|
76
|
+
[kaia.id]: http(config[KAIA_MAINNET_CHAIN_ID]),
|
|
64
77
|
},
|
|
65
78
|
});
|
|
66
79
|
};
|
|
@@ -99,6 +112,7 @@ export class EvmXService extends XService {
|
|
|
99
112
|
const balance = await getPublicClient(this.wagmiConfig, { chainId: chainId })?.getBalance({
|
|
100
113
|
address: address as Address,
|
|
101
114
|
});
|
|
115
|
+
console.log('balance', balance);
|
|
102
116
|
return balance || 0n;
|
|
103
117
|
}
|
|
104
118
|
|
|
@@ -133,7 +147,7 @@ export class EvmXService extends XService {
|
|
|
133
147
|
chainId: getWagmiChainId(xChainId),
|
|
134
148
|
})),
|
|
135
149
|
});
|
|
136
|
-
|
|
150
|
+
console.log('result', result);
|
|
137
151
|
return nonNativeXTokens
|
|
138
152
|
.map((token, index) => ({
|
|
139
153
|
symbol: token.symbol,
|
|
@@ -5,6 +5,24 @@ import CustomSorobanServer from './CustomSorobanServer';
|
|
|
5
5
|
import { getTokenBalance } from './utils';
|
|
6
6
|
import type { XToken } from '@sodax/types';
|
|
7
7
|
|
|
8
|
+
/** Base reserve in stroops (0.5 XLM). Each subentry (trustline, signer, data entry, offer) adds one base reserve. */
|
|
9
|
+
const STELLAR_BASE_RESERVE_STROOPS = 5_000_000;
|
|
10
|
+
|
|
11
|
+
/** Horizon account fields used for minimum balance. Minimum = (2 + subentry_count + num_sponsoring - num_sponsored) * base_reserve + selling_liabilities. */
|
|
12
|
+
interface StellarAccountReserveFields {
|
|
13
|
+
subentry_count?: number;
|
|
14
|
+
num_sponsoring?: number;
|
|
15
|
+
num_sponsored?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Parse XLM balance string (e.g. "198.8944970") to stroops (1 XLM = 10^7 stroops). */
|
|
19
|
+
function parseXlmBalanceToStroops(balanceStr: string): bigint {
|
|
20
|
+
const parts = balanceStr.split('.');
|
|
21
|
+
const whole = parts[0] ?? '0';
|
|
22
|
+
const frac = (parts[1] ?? '').padEnd(7, '0').slice(0, 7);
|
|
23
|
+
return BigInt(whole + frac);
|
|
24
|
+
}
|
|
25
|
+
|
|
8
26
|
export class StellarXService extends XService {
|
|
9
27
|
private static instance: StellarXService;
|
|
10
28
|
|
|
@@ -39,7 +57,22 @@ export class StellarXService extends XService {
|
|
|
39
57
|
if (xToken.symbol === 'XLM') {
|
|
40
58
|
const xlmBalance = stellarAccount.balances.find(balance => balance.asset_type === 'native');
|
|
41
59
|
if (xlmBalance) {
|
|
42
|
-
|
|
60
|
+
const rawBalanceStroops = parseXlmBalanceToStroops(xlmBalance.balance);
|
|
61
|
+
const sellingLiabilitiesStroops = (xlmBalance as { selling_liabilities?: string }).selling_liabilities
|
|
62
|
+
? parseXlmBalanceToStroops((xlmBalance as { selling_liabilities: string }).selling_liabilities)
|
|
63
|
+
: BigInt(0);
|
|
64
|
+
const reserveFields = stellarAccount as unknown as StellarAccountReserveFields;
|
|
65
|
+
const subentryCount = reserveFields.subentry_count ?? 0;
|
|
66
|
+
const numSponsoring = reserveFields.num_sponsoring ?? 0;
|
|
67
|
+
const numSponsored = reserveFields.num_sponsored ?? 0;
|
|
68
|
+
// Minimum balance = (2 + subentry_count + num_sponsoring - num_sponsored) * base_reserve + selling_liabilities.
|
|
69
|
+
// When account has sponsored reserves (num_sponsored > 0), those reserves are paid by the sponsor, so we don't subtract them.
|
|
70
|
+
const reserveCount = Math.max(0, 2 + subentryCount + numSponsoring - numSponsored);
|
|
71
|
+
const minBalanceStroops =
|
|
72
|
+
BigInt(reserveCount) * BigInt(STELLAR_BASE_RESERVE_STROOPS) + sellingLiabilitiesStroops;
|
|
73
|
+
const availableStroops =
|
|
74
|
+
rawBalanceStroops > minBalanceStroops ? rawBalanceStroops - minBalanceStroops : BigInt(0);
|
|
75
|
+
return availableStroops;
|
|
43
76
|
}
|
|
44
77
|
} else {
|
|
45
78
|
try {
|