@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/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { baseChainInfo, LIGHTLINK_MAINNET_CHAIN_ID, HYPEREVM_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, ETHEREUM_MAINNET_CHAIN_ID } from '@sodax/types';
|
|
1
|
+
import { baseChainInfo, KAIA_MAINNET_CHAIN_ID, LIGHTLINK_MAINNET_CHAIN_ID, HYPEREVM_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, ETHEREUM_MAINNET_CHAIN_ID } from '@sodax/types';
|
|
2
2
|
import { erc20Abi, defineChain } from 'viem';
|
|
3
3
|
import { getPublicClient } from 'wagmi/actions';
|
|
4
4
|
import { useConnections, useAccount, useConnect, useConnectors, useDisconnect, useSwitchChain, usePublicClient, useWalletClient, useSignMessage, WagmiProvider, createConfig, http, useConfig } from 'wagmi';
|
|
5
|
-
import { mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, lightlinkPhoenix } from 'wagmi/chains';
|
|
5
|
+
import { mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, lightlinkPhoenix, kaia } from 'wagmi/chains';
|
|
6
6
|
import * as IconSdkRaw from 'icon-sdk-js';
|
|
7
7
|
import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
|
|
8
8
|
import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi, getInjectiveAddress, getEthereumAddress } from '@injectivelabs/sdk-ts';
|
|
@@ -172,7 +172,7 @@ var hyper = /* @__PURE__ */ defineChain({
|
|
|
172
172
|
});
|
|
173
173
|
var createWagmiConfig = (config) => {
|
|
174
174
|
return createConfig({
|
|
175
|
-
chains: [mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, hyper, lightlinkPhoenix],
|
|
175
|
+
chains: [mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, hyper, lightlinkPhoenix, kaia],
|
|
176
176
|
ssr: true,
|
|
177
177
|
transports: {
|
|
178
178
|
[mainnet.id]: http(config[ETHEREUM_MAINNET_CHAIN_ID]),
|
|
@@ -184,7 +184,8 @@ var createWagmiConfig = (config) => {
|
|
|
184
184
|
[optimism.id]: http(config[OPTIMISM_MAINNET_CHAIN_ID]),
|
|
185
185
|
[polygon.id]: http(config[POLYGON_MAINNET_CHAIN_ID]),
|
|
186
186
|
[hyper.id]: http(config[HYPEREVM_MAINNET_CHAIN_ID]),
|
|
187
|
-
[lightlinkPhoenix.id]: http(config[LIGHTLINK_MAINNET_CHAIN_ID])
|
|
187
|
+
[lightlinkPhoenix.id]: http(config[LIGHTLINK_MAINNET_CHAIN_ID]),
|
|
188
|
+
[kaia.id]: http(config[KAIA_MAINNET_CHAIN_ID])
|
|
188
189
|
}
|
|
189
190
|
});
|
|
190
191
|
};
|
|
@@ -209,6 +210,7 @@ var EvmXService = class _EvmXService extends XService {
|
|
|
209
210
|
const balance = await getPublicClient(this.wagmiConfig, { chainId })?.getBalance({
|
|
210
211
|
address
|
|
211
212
|
});
|
|
213
|
+
console.log("balance", balance);
|
|
212
214
|
return balance || 0n;
|
|
213
215
|
}
|
|
214
216
|
throw new Error(`Unsupported token: ${xToken.symbol}`);
|
|
@@ -236,6 +238,7 @@ var EvmXService = class _EvmXService extends XService {
|
|
|
236
238
|
chainId: getWagmiChainId(xChainId)
|
|
237
239
|
}))
|
|
238
240
|
});
|
|
241
|
+
console.log("result", result);
|
|
239
242
|
return nonNativeXTokens.map((token, index) => ({
|
|
240
243
|
symbol: token.symbol,
|
|
241
244
|
address: token.address,
|
|
@@ -623,6 +626,13 @@ var getTokenBalance = async (address, tokenId, txBuilder, server) => {
|
|
|
623
626
|
};
|
|
624
627
|
|
|
625
628
|
// src/xchains/stellar/StellarXService.ts
|
|
629
|
+
var STELLAR_BASE_RESERVE_STROOPS = 5e6;
|
|
630
|
+
function parseXlmBalanceToStroops(balanceStr) {
|
|
631
|
+
const parts = balanceStr.split(".");
|
|
632
|
+
const whole = parts[0] ?? "0";
|
|
633
|
+
const frac = (parts[1] ?? "").padEnd(7, "0").slice(0, 7);
|
|
634
|
+
return BigInt(whole + frac);
|
|
635
|
+
}
|
|
626
636
|
var StellarXService = class _StellarXService extends XService {
|
|
627
637
|
constructor() {
|
|
628
638
|
super("STELLAR");
|
|
@@ -645,7 +655,16 @@ var StellarXService = class _StellarXService extends XService {
|
|
|
645
655
|
if (xToken.symbol === "XLM") {
|
|
646
656
|
const xlmBalance = stellarAccount.balances.find((balance) => balance.asset_type === "native");
|
|
647
657
|
if (xlmBalance) {
|
|
648
|
-
|
|
658
|
+
const rawBalanceStroops = parseXlmBalanceToStroops(xlmBalance.balance);
|
|
659
|
+
const sellingLiabilitiesStroops = xlmBalance.selling_liabilities ? parseXlmBalanceToStroops(xlmBalance.selling_liabilities) : BigInt(0);
|
|
660
|
+
const reserveFields = stellarAccount;
|
|
661
|
+
const subentryCount = reserveFields.subentry_count ?? 0;
|
|
662
|
+
const numSponsoring = reserveFields.num_sponsoring ?? 0;
|
|
663
|
+
const numSponsored = reserveFields.num_sponsored ?? 0;
|
|
664
|
+
const reserveCount = Math.max(0, 2 + subentryCount + numSponsoring - numSponsored);
|
|
665
|
+
const minBalanceStroops = BigInt(reserveCount) * BigInt(STELLAR_BASE_RESERVE_STROOPS) + sellingLiabilitiesStroops;
|
|
666
|
+
const availableStroops = rawBalanceStroops > minBalanceStroops ? rawBalanceStroops - minBalanceStroops : BigInt(0);
|
|
667
|
+
return availableStroops;
|
|
649
668
|
}
|
|
650
669
|
} else {
|
|
651
670
|
try {
|