@sodax/sdk 2.2.0-rc.1 → 2.2.0-rc.2
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 +7 -7
- package/dist/index.cjs +788 -11
- package/dist/index.d.cts +361 -13
- package/dist/index.d.ts +361 -13
- package/dist/index.mjs +787 -14
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -3556,7 +3556,9 @@ var spokeChainConfig = {
|
|
|
3556
3556
|
},
|
|
3557
3557
|
chain: baseChainInfo[ChainKeys.BITCOIN_MAINNET],
|
|
3558
3558
|
bnUSD: "no",
|
|
3559
|
-
|
|
3559
|
+
// Must equal bitcoinSupportedTokens.BTC.address: isNativeToken compares a token's `address`
|
|
3560
|
+
// against this value, so a symbol here classifies native BTC as a contract token.
|
|
3561
|
+
nativeToken: "0:0",
|
|
3560
3562
|
supportedTokens: bitcoinSupportedTokens,
|
|
3561
3563
|
radfi: {
|
|
3562
3564
|
walletMode: "TRADING",
|
|
@@ -4106,8 +4108,12 @@ var moneyMarketSupportedTokens = {
|
|
|
4106
4108
|
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.USDS,
|
|
4107
4109
|
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.XLM
|
|
4108
4110
|
],
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
+
[ChainKeys.ROBINHOOD_MAINNET]: [
|
|
4112
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.ETH,
|
|
4113
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.bnUSD,
|
|
4114
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.SODA,
|
|
4115
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.USDG
|
|
4116
|
+
]
|
|
4111
4117
|
};
|
|
4112
4118
|
var moneyMarketReserveAssets = [
|
|
4113
4119
|
...Object.values(SodaTokens).map((vault) => vault.address),
|
|
@@ -4886,7 +4892,7 @@ function isValidWalletProviderForChainKey(chainKey, walletProvider) {
|
|
|
4886
4892
|
}
|
|
4887
4893
|
|
|
4888
4894
|
// ../types/dist/index.js
|
|
4889
|
-
var CONFIG_VERSION =
|
|
4895
|
+
var CONFIG_VERSION = 232;
|
|
4890
4896
|
|
|
4891
4897
|
// src/shared/utils/resolveTimeoutMs.ts
|
|
4892
4898
|
function resolveTimeoutMs(timeout, fallbackMs) {
|
|
@@ -15450,10 +15456,54 @@ var EvmAssetManagerService = class _EvmAssetManagerService {
|
|
|
15450
15456
|
});
|
|
15451
15457
|
}
|
|
15452
15458
|
};
|
|
15459
|
+
|
|
15460
|
+
// src/shared/services/spoke/balance-utils.ts
|
|
15461
|
+
function createBalanceCollector({ logger, chainKey }) {
|
|
15462
|
+
const balances = {};
|
|
15463
|
+
let attempted = 0;
|
|
15464
|
+
let failed = 0;
|
|
15465
|
+
return {
|
|
15466
|
+
ok(tokenAddress, value) {
|
|
15467
|
+
attempted++;
|
|
15468
|
+
balances[tokenAddress] = value;
|
|
15469
|
+
},
|
|
15470
|
+
fail(tokenAddress, reason) {
|
|
15471
|
+
attempted++;
|
|
15472
|
+
failed++;
|
|
15473
|
+
logger.warn("[getWalletBalances] balance read failed, reporting 0n", {
|
|
15474
|
+
chainKey,
|
|
15475
|
+
token: tokenAddress,
|
|
15476
|
+
error: reason instanceof Error ? reason.message : String(reason)
|
|
15477
|
+
});
|
|
15478
|
+
balances[tokenAddress] = 0n;
|
|
15479
|
+
},
|
|
15480
|
+
finish() {
|
|
15481
|
+
if (attempted > 0 && failed === attempted) {
|
|
15482
|
+
throw new Error(`[getWalletBalances] every balance read failed on ${chainKey} (${failed}/${attempted})`);
|
|
15483
|
+
}
|
|
15484
|
+
return balances;
|
|
15485
|
+
}
|
|
15486
|
+
};
|
|
15487
|
+
}
|
|
15488
|
+
async function settleWalletBalances(collector, tokens, read) {
|
|
15489
|
+
const settled = await Promise.allSettled(tokens.map((token) => read(token)));
|
|
15490
|
+
tokens.forEach((token, index) => {
|
|
15491
|
+
const outcome = settled[index];
|
|
15492
|
+
if (!outcome) return;
|
|
15493
|
+
if (outcome.status === "fulfilled") {
|
|
15494
|
+
collector.ok(token.address, outcome.value);
|
|
15495
|
+
} else {
|
|
15496
|
+
collector.fail(token.address, outcome.reason);
|
|
15497
|
+
}
|
|
15498
|
+
});
|
|
15499
|
+
}
|
|
15453
15500
|
var HEDERA_NATIVE_VALUE_SCALE = 10n ** 10n;
|
|
15454
15501
|
function scaleNativeMsgValue(chainKey, amount) {
|
|
15455
15502
|
return chainKey === ChainKeys.HEDERA_MAINNET ? amount * HEDERA_NATIVE_VALUE_SCALE : amount;
|
|
15456
15503
|
}
|
|
15504
|
+
function scaleNativeBalance(chainKey, amount) {
|
|
15505
|
+
return chainKey === ChainKeys.HEDERA_MAINNET ? amount / HEDERA_NATIVE_VALUE_SCALE : amount;
|
|
15506
|
+
}
|
|
15457
15507
|
var EvmSpokeService = class {
|
|
15458
15508
|
config;
|
|
15459
15509
|
// map containing the public clients for each evm spoke chain, lazy loaded on demand
|
|
@@ -15570,6 +15620,79 @@ var EvmSpokeService = class {
|
|
|
15570
15620
|
args: [this.config.getChainConfig(params.srcChainKey).addresses.assetManager]
|
|
15571
15621
|
});
|
|
15572
15622
|
}
|
|
15623
|
+
/**
|
|
15624
|
+
* Get the user's own wallet balance of a token on an EVM spoke chain, in smallest units.
|
|
15625
|
+
* Native coin via `eth_getBalance` (Hedera scaled to canonical decimals); erc20 via `balanceOf`.
|
|
15626
|
+
* @param {GetBalanceParams<EvmSpokeOnlyChainKey>} params - The chain key, user address, and token.
|
|
15627
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
15628
|
+
*/
|
|
15629
|
+
async getWalletBalance(params) {
|
|
15630
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
15631
|
+
const publicClient = this.getPublicClient(srcChainKey);
|
|
15632
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
15633
|
+
const balance2 = await publicClient.getBalance({ address: srcAddress });
|
|
15634
|
+
return scaleNativeBalance(srcChainKey, balance2);
|
|
15635
|
+
}
|
|
15636
|
+
const balance = await publicClient.readContract({
|
|
15637
|
+
address: token.address,
|
|
15638
|
+
abi: erc20Abi,
|
|
15639
|
+
functionName: "balanceOf",
|
|
15640
|
+
args: [srcAddress]
|
|
15641
|
+
});
|
|
15642
|
+
return balance ?? 0n;
|
|
15643
|
+
}
|
|
15644
|
+
/**
|
|
15645
|
+
* Get the user's own wallet balances of multiple tokens on an EVM spoke chain, in smallest
|
|
15646
|
+
* units. Non-native tokens are batched via multicall3 when the chain supports it, otherwise
|
|
15647
|
+
* read in parallel.
|
|
15648
|
+
* @param {GetBalancesParams<EvmSpokeOnlyChainKey>} params - The chain key, user address, and tokens.
|
|
15649
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
15650
|
+
*/
|
|
15651
|
+
async getWalletBalances(params) {
|
|
15652
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
15653
|
+
const nativeTokens = tokens.filter((token) => isNativeToken(srcChainKey, token));
|
|
15654
|
+
const nonNativeTokens = tokens.filter((token) => !isNativeToken(srcChainKey, token));
|
|
15655
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
15656
|
+
await settleWalletBalances(
|
|
15657
|
+
collector,
|
|
15658
|
+
nativeTokens,
|
|
15659
|
+
(token) => this.getWalletBalance({ srcChainKey, srcAddress, token })
|
|
15660
|
+
);
|
|
15661
|
+
if (nonNativeTokens.length === 0) {
|
|
15662
|
+
return collector.finish();
|
|
15663
|
+
}
|
|
15664
|
+
const publicClient = this.getPublicClient(srcChainKey);
|
|
15665
|
+
if (getEvmViemChain(srcChainKey).contracts?.multicall3) {
|
|
15666
|
+
const results = await publicClient.multicall({
|
|
15667
|
+
contracts: nonNativeTokens.map((token) => ({
|
|
15668
|
+
abi: erc20Abi,
|
|
15669
|
+
address: token.address,
|
|
15670
|
+
functionName: "balanceOf",
|
|
15671
|
+
args: [srcAddress]
|
|
15672
|
+
}))
|
|
15673
|
+
});
|
|
15674
|
+
nonNativeTokens.forEach((token, index) => {
|
|
15675
|
+
const result = results[index];
|
|
15676
|
+
if (result?.status === "success") {
|
|
15677
|
+
collector.ok(token.address, BigInt(result.result));
|
|
15678
|
+
} else {
|
|
15679
|
+
collector.fail(token.address, result?.error ?? new Error(`missing multicall result for ${token.address}`));
|
|
15680
|
+
}
|
|
15681
|
+
});
|
|
15682
|
+
return collector.finish();
|
|
15683
|
+
}
|
|
15684
|
+
await settleWalletBalances(
|
|
15685
|
+
collector,
|
|
15686
|
+
nonNativeTokens,
|
|
15687
|
+
(token) => publicClient.readContract({
|
|
15688
|
+
address: token.address,
|
|
15689
|
+
abi: erc20Abi,
|
|
15690
|
+
functionName: "balanceOf",
|
|
15691
|
+
args: [srcAddress]
|
|
15692
|
+
})
|
|
15693
|
+
);
|
|
15694
|
+
return collector.finish();
|
|
15695
|
+
}
|
|
15573
15696
|
/**
|
|
15574
15697
|
* Sends a message to the hub chain.
|
|
15575
15698
|
* @param {SendMessageParams} params - Includes dstChainKey, the chain key of the hub chain.
|
|
@@ -15764,6 +15887,31 @@ var StacksSpokeService = class {
|
|
|
15764
15887
|
}
|
|
15765
15888
|
return this.readTokenBalance(params.token, assetManager);
|
|
15766
15889
|
}
|
|
15890
|
+
/**
|
|
15891
|
+
* Get the user's own wallet balance of a token on Stacks, in smallest units. Native STX via the
|
|
15892
|
+
* Hiro REST `/extended/v1/address/{addr}/balances` endpoint; SIP-010 fungible tokens via the
|
|
15893
|
+
* read-only `get-balance` contract call. Unlike {@link getDeposit}, this reads the holding of
|
|
15894
|
+
* `srcAddress` (the user), not the protocol asset manager.
|
|
15895
|
+
* @param {GetBalanceParams<StacksChainKey>} params - The chain key, user address, and token.
|
|
15896
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
15897
|
+
*/
|
|
15898
|
+
async getWalletBalance(params) {
|
|
15899
|
+
if (isNativeToken(params.srcChainKey, params.token)) {
|
|
15900
|
+
return this.getSTXBalance(params.srcAddress);
|
|
15901
|
+
}
|
|
15902
|
+
return this.readTokenBalance(params.token.address, params.srcAddress);
|
|
15903
|
+
}
|
|
15904
|
+
/**
|
|
15905
|
+
* Get the user's own wallet balances of multiple tokens on Stacks, in smallest units.
|
|
15906
|
+
* @param {GetBalancesParams<StacksChainKey>} params - The chain key, user address, and tokens.
|
|
15907
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
15908
|
+
*/
|
|
15909
|
+
async getWalletBalances(params) {
|
|
15910
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
15911
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
15912
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
15913
|
+
return collector.finish();
|
|
15914
|
+
}
|
|
15767
15915
|
/**
|
|
15768
15916
|
* Sends a message to the hub chain.
|
|
15769
15917
|
*/
|
|
@@ -16324,6 +16472,32 @@ var BitcoinSpokeService = class {
|
|
|
16324
16472
|
}
|
|
16325
16473
|
throw new Error("Token balance queries not yet implemented for non-BTC assets");
|
|
16326
16474
|
}
|
|
16475
|
+
/**
|
|
16476
|
+
* Get the user's own wallet balance of a token on Bitcoin, in satoshis. Only native BTC is
|
|
16477
|
+
* readable (summed from confirmed/unconfirmed UTXOs). Non-native spoke tokens are Rune ids
|
|
16478
|
+
* (`block:tx`), whose amounts the Esplora UTXO endpoint does not carry, so they resolve to 0n.
|
|
16479
|
+
* @param {GetBalanceParams<BitcoinChainKey>} params - The chain key, user address, and token.
|
|
16480
|
+
* @returns {Promise<bigint>} The balance in satoshis.
|
|
16481
|
+
*/
|
|
16482
|
+
async getWalletBalance(params) {
|
|
16483
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
16484
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
16485
|
+
const utxos = await this.fetchUTXOs(srcAddress);
|
|
16486
|
+
return BigInt(utxos.reduce((sum, utxo) => sum + utxo.value, 0));
|
|
16487
|
+
}
|
|
16488
|
+
return 0n;
|
|
16489
|
+
}
|
|
16490
|
+
/**
|
|
16491
|
+
* Get the user's own wallet balances of multiple tokens on Bitcoin, in satoshis.
|
|
16492
|
+
* @param {GetBalancesParams<BitcoinChainKey>} params - The chain key, user address, and tokens.
|
|
16493
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
16494
|
+
*/
|
|
16495
|
+
async getWalletBalances(params) {
|
|
16496
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
16497
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
16498
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
16499
|
+
return collector.finish();
|
|
16500
|
+
}
|
|
16327
16501
|
async fetchScriptPubKey(utxo) {
|
|
16328
16502
|
const txHex = await this.fetchRawTransaction(utxo.txid);
|
|
16329
16503
|
const tx = bitcoinjsLib.Transaction.fromHex(txHex);
|
|
@@ -22870,6 +23044,39 @@ var NearSpokeService = class {
|
|
|
22870
23044
|
}
|
|
22871
23045
|
return BigInt(bal);
|
|
22872
23046
|
}
|
|
23047
|
+
/**
|
|
23048
|
+
* Get the user's own wallet balance of a token on NEAR, in smallest units (yoctoNEAR for the
|
|
23049
|
+
* native coin). Native NEAR via the account's `viewAccount().amount`; NEP-141 tokens via the
|
|
23050
|
+
* token contract's `ft_balance_of` view. Reads the balance held by `srcAddress` (the user
|
|
23051
|
+
* wallet), not the protocol asset manager. Uses this service's own configured RPC provider.
|
|
23052
|
+
* @param {GetBalanceParams<NearChainKey>} params - The chain key, user address, and token.
|
|
23053
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
23054
|
+
*/
|
|
23055
|
+
async getWalletBalance(params) {
|
|
23056
|
+
if (isNativeToken(params.srcChainKey, params.token)) {
|
|
23057
|
+
const account = await this.rpcProvider.viewAccount({ accountId: params.srcAddress });
|
|
23058
|
+
return BigInt(account.amount);
|
|
23059
|
+
}
|
|
23060
|
+
const bal = await this.queryContract(params.token.address, "ft_balance_of", {
|
|
23061
|
+
account_id: params.srcAddress
|
|
23062
|
+
});
|
|
23063
|
+
if (typeof bal !== "string") {
|
|
23064
|
+
throw new Error("[NearSpokeService.getWalletBalance] Failed to get balance. Unexpected response type.");
|
|
23065
|
+
}
|
|
23066
|
+
return BigInt(bal);
|
|
23067
|
+
}
|
|
23068
|
+
/**
|
|
23069
|
+
* Get the user's own wallet balances of multiple tokens on NEAR, in smallest units. Fans out
|
|
23070
|
+
* over {@link getWalletBalance}, keyed by `token.address`.
|
|
23071
|
+
* @param {GetBalancesParams<NearChainKey>} params - The chain key, user address, and tokens.
|
|
23072
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
23073
|
+
*/
|
|
23074
|
+
async getWalletBalances(params) {
|
|
23075
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
23076
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
23077
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
23078
|
+
return collector.finish();
|
|
23079
|
+
}
|
|
22873
23080
|
/**
|
|
22874
23081
|
* Whether `accountId` is storage-registered on a NEP-141 `token` contract. NEP-141 requires an
|
|
22875
23082
|
* account to pay a one-time storage bond before it can receive (hold a balance of) the token, so
|
|
@@ -23729,6 +23936,76 @@ var SonicSpokeService = class {
|
|
|
23729
23936
|
args: [params.token]
|
|
23730
23937
|
});
|
|
23731
23938
|
}
|
|
23939
|
+
/**
|
|
23940
|
+
* Get the user's own wallet balance of a token on the hub (Sonic) chain, in smallest units.
|
|
23941
|
+
* Native coin via `eth_getBalance`; erc20 via `balanceOf`.
|
|
23942
|
+
* @param {GetBalanceParams<SonicChainKey>} params - The chain key, user address, and token.
|
|
23943
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
23944
|
+
*/
|
|
23945
|
+
async getWalletBalance(params) {
|
|
23946
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
23947
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
23948
|
+
return this.publicClient.getBalance({ address: srcAddress });
|
|
23949
|
+
}
|
|
23950
|
+
const balance = await this.publicClient.readContract({
|
|
23951
|
+
address: token.address,
|
|
23952
|
+
abi: viem.erc20Abi,
|
|
23953
|
+
functionName: "balanceOf",
|
|
23954
|
+
args: [srcAddress]
|
|
23955
|
+
});
|
|
23956
|
+
return balance ?? 0n;
|
|
23957
|
+
}
|
|
23958
|
+
/**
|
|
23959
|
+
* Get the user's own wallet balances of multiple tokens on the hub (Sonic) chain, in smallest
|
|
23960
|
+
* units. Non-native tokens are batched via multicall3 when the chain supports it, otherwise
|
|
23961
|
+
* read in parallel.
|
|
23962
|
+
* @param {GetBalancesParams<SonicChainKey>} params - The chain key, user address, and tokens.
|
|
23963
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
23964
|
+
*/
|
|
23965
|
+
async getWalletBalances(params) {
|
|
23966
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
23967
|
+
const nativeTokens = tokens.filter((token) => isNativeToken(srcChainKey, token));
|
|
23968
|
+
const nonNativeTokens = tokens.filter((token) => !isNativeToken(srcChainKey, token));
|
|
23969
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
23970
|
+
await settleWalletBalances(
|
|
23971
|
+
collector,
|
|
23972
|
+
nativeTokens,
|
|
23973
|
+
(token) => this.getWalletBalance({ srcChainKey, srcAddress, token })
|
|
23974
|
+
);
|
|
23975
|
+
if (nonNativeTokens.length === 0) {
|
|
23976
|
+
return collector.finish();
|
|
23977
|
+
}
|
|
23978
|
+
if (getEvmViemChain(srcChainKey).contracts?.multicall3) {
|
|
23979
|
+
const results = await this.publicClient.multicall({
|
|
23980
|
+
contracts: nonNativeTokens.map((token) => ({
|
|
23981
|
+
abi: viem.erc20Abi,
|
|
23982
|
+
address: token.address,
|
|
23983
|
+
functionName: "balanceOf",
|
|
23984
|
+
args: [srcAddress]
|
|
23985
|
+
}))
|
|
23986
|
+
});
|
|
23987
|
+
nonNativeTokens.forEach((token, index) => {
|
|
23988
|
+
const result = results[index];
|
|
23989
|
+
if (result?.status === "success") {
|
|
23990
|
+
collector.ok(token.address, BigInt(result.result));
|
|
23991
|
+
} else {
|
|
23992
|
+
collector.fail(token.address, result?.error ?? new Error(`missing multicall result for ${token.address}`));
|
|
23993
|
+
}
|
|
23994
|
+
});
|
|
23995
|
+
return collector.finish();
|
|
23996
|
+
}
|
|
23997
|
+
await settleWalletBalances(
|
|
23998
|
+
collector,
|
|
23999
|
+
nonNativeTokens,
|
|
24000
|
+
(token) => this.publicClient.readContract({
|
|
24001
|
+
address: token.address,
|
|
24002
|
+
abi: viem.erc20Abi,
|
|
24003
|
+
functionName: "balanceOf",
|
|
24004
|
+
args: [srcAddress]
|
|
24005
|
+
})
|
|
24006
|
+
);
|
|
24007
|
+
return collector.finish();
|
|
24008
|
+
}
|
|
23732
24009
|
/**
|
|
23733
24010
|
* Execute a batch of contract calls through the Sonic wallet contract.
|
|
23734
24011
|
* @param {Hex} payload - The encoded payload containing the calls array
|
|
@@ -23827,8 +24104,8 @@ var SuiGrpcTransport = class {
|
|
|
23827
24104
|
this.endpoint = endpoint;
|
|
23828
24105
|
this.client = new grpc.SuiGrpcClient({ network: "mainnet", baseUrl: endpoint });
|
|
23829
24106
|
}
|
|
23830
|
-
async getCoins(owner, coinType, limit = DEFAULT_GET_COINS_LIMIT) {
|
|
23831
|
-
const response = await this.client.core.listCoins({ owner, coinType, limit });
|
|
24107
|
+
async getCoins(owner, coinType, limit = DEFAULT_GET_COINS_LIMIT, cursor) {
|
|
24108
|
+
const response = await this.client.core.listCoins({ owner, coinType, limit, cursor: cursor ?? void 0 });
|
|
23832
24109
|
return toSuiPaginatedCoins(response, coinType);
|
|
23833
24110
|
}
|
|
23834
24111
|
async simulate(tx, sender) {
|
|
@@ -24068,6 +24345,42 @@ var SuiSpokeService = class {
|
|
|
24068
24345
|
const str_u64 = bcs.bcs.U64.parse(Uint8Array.from(val));
|
|
24069
24346
|
return BigInt(str_u64);
|
|
24070
24347
|
}
|
|
24348
|
+
/**
|
|
24349
|
+
* Get the user's own wallet balance of a token on Sui, in smallest units. Unlike {@link getDeposit}
|
|
24350
|
+
* (which reads the protocol asset manager holding), this reads the balance held by `params.srcAddress`
|
|
24351
|
+
* itself. Native SUI is read via its canonical `0x2::sui::SUI` coin type; other coins use the token's
|
|
24352
|
+
* Sui coinType (`token.address`).
|
|
24353
|
+
* @param {GetBalanceParams<SuiChainKey>} params - The chain key, user address, and token.
|
|
24354
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
24355
|
+
*/
|
|
24356
|
+
async getWalletBalance(params) {
|
|
24357
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
24358
|
+
let coinType = isNativeToken(srcChainKey, token) ? "0x2::sui::SUI" : token.address;
|
|
24359
|
+
if (coinType === "0x03917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR") {
|
|
24360
|
+
coinType = "0x3917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR";
|
|
24361
|
+
}
|
|
24362
|
+
let total = 0n;
|
|
24363
|
+
let cursor;
|
|
24364
|
+
do {
|
|
24365
|
+
const page = await this.transport.getCoins(srcAddress, coinType, void 0, cursor);
|
|
24366
|
+
for (const coin of page.data) {
|
|
24367
|
+
total += BigInt(coin.balance);
|
|
24368
|
+
}
|
|
24369
|
+
cursor = page.hasNextPage ? page.nextCursor : void 0;
|
|
24370
|
+
} while (cursor);
|
|
24371
|
+
return total;
|
|
24372
|
+
}
|
|
24373
|
+
/**
|
|
24374
|
+
* Get the user's own wallet balances of multiple tokens on Sui, in smallest units.
|
|
24375
|
+
* @param {GetBalancesParams<SuiChainKey>} params - The chain key, user address, and tokens.
|
|
24376
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
24377
|
+
*/
|
|
24378
|
+
async getWalletBalances(params) {
|
|
24379
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
24380
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
24381
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
24382
|
+
return collector.finish();
|
|
24383
|
+
}
|
|
24071
24384
|
/**
|
|
24072
24385
|
* Fetch the asset manager config from the spoke chain.
|
|
24073
24386
|
* @param {SuiChainKey} chainId - The Sui chain key.
|
|
@@ -24214,6 +24527,11 @@ var CustomSorobanServer = class extends stellarSdk.rpc.Server {
|
|
|
24214
24527
|
return response.json().then((json) => json.result);
|
|
24215
24528
|
}
|
|
24216
24529
|
};
|
|
24530
|
+
var STELLAR_BASE_RESERVE_STROOPS = 5000000n;
|
|
24531
|
+
function parseXlmBalanceToStroops(balanceStr) {
|
|
24532
|
+
const [whole = "0", frac = ""] = balanceStr.split(".");
|
|
24533
|
+
return BigInt(whole + frac.padEnd(7, "0").slice(0, 7));
|
|
24534
|
+
}
|
|
24217
24535
|
var CustomStellarAccount = class {
|
|
24218
24536
|
accountId;
|
|
24219
24537
|
sequenceNumber;
|
|
@@ -24252,7 +24570,7 @@ var CustomStellarAccount = class {
|
|
|
24252
24570
|
}
|
|
24253
24571
|
};
|
|
24254
24572
|
var TRUSTLINE_TX_TIMEOUT_SECONDS = 300;
|
|
24255
|
-
var StellarSpokeService = class {
|
|
24573
|
+
var StellarSpokeService = class _StellarSpokeService {
|
|
24256
24574
|
config;
|
|
24257
24575
|
chainConfig;
|
|
24258
24576
|
server;
|
|
@@ -24293,6 +24611,109 @@ var StellarSpokeService = class {
|
|
|
24293
24611
|
}
|
|
24294
24612
|
throw new Error("result undefined");
|
|
24295
24613
|
}
|
|
24614
|
+
/**
|
|
24615
|
+
* Get the user's own wallet balance of a token on Stellar, in smallest units. Native XLM returns
|
|
24616
|
+
* the spendable amount (total minus the minimum reserve and selling liabilities) via Horizon;
|
|
24617
|
+
* other assets return the Soroban token contract's `balance` for the user.
|
|
24618
|
+
* @param {GetBalanceParams<StellarChainKey>} params - The chain key, user address, and token.
|
|
24619
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
24620
|
+
*/
|
|
24621
|
+
async getWalletBalance(params) {
|
|
24622
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
24623
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
24624
|
+
return _StellarSpokeService.spendableXlmStroops(await this.server.loadAccount(srcAddress));
|
|
24625
|
+
}
|
|
24626
|
+
const [network, sourceAccount] = await Promise.all([
|
|
24627
|
+
this.sorobanServer.getNetwork(),
|
|
24628
|
+
this.sorobanServer.getAccount(srcAddress)
|
|
24629
|
+
]);
|
|
24630
|
+
return this.simulateTokenBalance(
|
|
24631
|
+
token.address,
|
|
24632
|
+
srcAddress,
|
|
24633
|
+
new CustomStellarAccount({ account_id: sourceAccount.accountId(), sequence: sourceAccount.sequenceNumber() }),
|
|
24634
|
+
network.passphrase
|
|
24635
|
+
);
|
|
24636
|
+
}
|
|
24637
|
+
/**
|
|
24638
|
+
* Spendable XLM in stroops: the account's native balance minus its minimum reserve and selling
|
|
24639
|
+
* liabilities. Reporting the raw balance would let a user try to spend reserves the network
|
|
24640
|
+
* refuses to release.
|
|
24641
|
+
*/
|
|
24642
|
+
static spendableXlmStroops(account) {
|
|
24643
|
+
const nativeBalance = account.balances.find(
|
|
24644
|
+
(balance) => balance.asset_type === "native"
|
|
24645
|
+
);
|
|
24646
|
+
if (!nativeBalance) {
|
|
24647
|
+
return 0n;
|
|
24648
|
+
}
|
|
24649
|
+
const rawStroops = parseXlmBalanceToStroops(nativeBalance.balance);
|
|
24650
|
+
const sellingLiabilitiesStroops = nativeBalance.selling_liabilities ? parseXlmBalanceToStroops(nativeBalance.selling_liabilities) : 0n;
|
|
24651
|
+
const reserveCount = Math.max(0, 2 + account.subentry_count + account.num_sponsoring - account.num_sponsored);
|
|
24652
|
+
const minStroops = BigInt(reserveCount) * STELLAR_BASE_RESERVE_STROOPS + sellingLiabilitiesStroops;
|
|
24653
|
+
return rawStroops > minStroops ? rawStroops - minStroops : 0n;
|
|
24654
|
+
}
|
|
24655
|
+
/**
|
|
24656
|
+
* Simulate a Soroban token `balance` call. Takes the network passphrase and source account so a
|
|
24657
|
+
* batch can fetch them once; `getAccountClone()` hands each builder its own `Account`, because
|
|
24658
|
+
* `TransactionBuilder.build()` increments the source's sequence number and concurrent builders
|
|
24659
|
+
* would otherwise interleave on a shared one.
|
|
24660
|
+
*/
|
|
24661
|
+
async simulateTokenBalance(tokenAddress, srcAddress, account, networkPassphrase) {
|
|
24662
|
+
const contract = new stellarSdk.Contract(tokenAddress);
|
|
24663
|
+
const tx = new stellarSdk.TransactionBuilder(account.getAccountClone(), { fee: this.baseFee, networkPassphrase }).addOperation(contract.call("balance", stellarSdk.nativeToScVal(srcAddress, { type: "address" }))).setTimeout(stellarSdk.TimeoutInfinite).build();
|
|
24664
|
+
const result = await this.sorobanServer.simulateTransaction(tx);
|
|
24665
|
+
if (!stellarSdk.rpc.Api.isSimulationSuccess(result)) {
|
|
24666
|
+
throw new Error("Failed to simulate transaction");
|
|
24667
|
+
}
|
|
24668
|
+
if (!result.result) {
|
|
24669
|
+
throw new Error("Failed to read token balance: simulation returned no result");
|
|
24670
|
+
}
|
|
24671
|
+
return stellarSdk.scValToBigInt(result.result.retval);
|
|
24672
|
+
}
|
|
24673
|
+
/**
|
|
24674
|
+
* Get the user's own wallet balances of multiple tokens on Stellar, in smallest units.
|
|
24675
|
+
*
|
|
24676
|
+
* The network passphrase and the source account are the same for every token, so they are
|
|
24677
|
+
* fetched once per batch instead of once per token — and only when a partition actually needs
|
|
24678
|
+
* them, so an all-native request issues no Soroban calls at all.
|
|
24679
|
+
* @param {GetBalancesParams<StellarChainKey>} params - The chain key, user address, and tokens.
|
|
24680
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
24681
|
+
*/
|
|
24682
|
+
async getWalletBalances(params) {
|
|
24683
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
24684
|
+
const nativeTokens = tokens.filter((token) => isNativeToken(srcChainKey, token));
|
|
24685
|
+
const sorobanTokens = tokens.filter((token) => !isNativeToken(srcChainKey, token));
|
|
24686
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
24687
|
+
if (nativeTokens.length > 0) {
|
|
24688
|
+
try {
|
|
24689
|
+
const spendable = _StellarSpokeService.spendableXlmStroops(await this.server.loadAccount(srcAddress));
|
|
24690
|
+
for (const token of nativeTokens) {
|
|
24691
|
+
collector.ok(token.address, spendable);
|
|
24692
|
+
}
|
|
24693
|
+
} catch (error) {
|
|
24694
|
+
for (const token of nativeTokens) {
|
|
24695
|
+
collector.fail(token.address, error);
|
|
24696
|
+
}
|
|
24697
|
+
}
|
|
24698
|
+
}
|
|
24699
|
+
if (sorobanTokens.length === 0) {
|
|
24700
|
+
return collector.finish();
|
|
24701
|
+
}
|
|
24702
|
+
const [network, sourceAccount] = await Promise.all([
|
|
24703
|
+
this.sorobanServer.getNetwork(),
|
|
24704
|
+
this.sorobanServer.getAccount(srcAddress)
|
|
24705
|
+
]);
|
|
24706
|
+
const account = new CustomStellarAccount({
|
|
24707
|
+
account_id: sourceAccount.accountId(),
|
|
24708
|
+
sequence: sourceAccount.sequenceNumber()
|
|
24709
|
+
});
|
|
24710
|
+
await settleWalletBalances(
|
|
24711
|
+
collector,
|
|
24712
|
+
sorobanTokens,
|
|
24713
|
+
(token) => this.simulateTokenBalance(token.address, srcAddress, account, network.passphrase)
|
|
24714
|
+
);
|
|
24715
|
+
return collector.finish();
|
|
24716
|
+
}
|
|
24296
24717
|
async buildPriorityStellarTransaction(account, network, operation) {
|
|
24297
24718
|
const simulationForFee = await this.sorobanServer.simulateTransaction(
|
|
24298
24719
|
new stellarSdk.TransactionBuilder(account.getAccountClone(), {
|
|
@@ -24866,6 +25287,48 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
24866
25287
|
const tokenAccount = await _SolanaSpokeService.getTokenAccountBalance(this.connection, vaultToken.pda.toBase58());
|
|
24867
25288
|
return BigInt(tokenAccount.value.amount);
|
|
24868
25289
|
}
|
|
25290
|
+
/**
|
|
25291
|
+
* Get the user's own wallet balance of a token on Solana, in smallest units. Native SOL via
|
|
25292
|
+
* `getBalance`; SPL via the associated token account. The mint may belong to the legacy SPL
|
|
25293
|
+
* Token program or Token-2022 (e.g. xStock tokens), which derive different ATAs, so both
|
|
25294
|
+
* candidate ATAs are read in one call and the existing one is used.
|
|
25295
|
+
* @param {GetBalanceParams<SolanaChainKey>} params - The chain key, user address, and token.
|
|
25296
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
25297
|
+
*/
|
|
25298
|
+
async getWalletBalance(params) {
|
|
25299
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
25300
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
25301
|
+
return BigInt(await _SolanaSpokeService.getBalance(this.connection, srcAddress));
|
|
25302
|
+
}
|
|
25303
|
+
const owner = new web3_js.PublicKey(srcAddress);
|
|
25304
|
+
const mint = new web3_js.PublicKey(token.address);
|
|
25305
|
+
const candidates = [splToken.TOKEN_PROGRAM_ID, splToken.TOKEN_2022_PROGRAM_ID].map((programId) => ({
|
|
25306
|
+
programId,
|
|
25307
|
+
ata: splToken.getAssociatedTokenAddressSync(mint, owner, true, programId)
|
|
25308
|
+
}));
|
|
25309
|
+
const accounts = await this.connection.getMultipleAccountsInfo(candidates.map((c) => c.ata));
|
|
25310
|
+
let balance = 0n;
|
|
25311
|
+
for (const [i, candidate] of candidates.entries()) {
|
|
25312
|
+
const info = accounts[i];
|
|
25313
|
+
if (!info) continue;
|
|
25314
|
+
try {
|
|
25315
|
+
balance += splToken.unpackAccount(candidate.ata, info, candidate.programId).amount;
|
|
25316
|
+
} catch {
|
|
25317
|
+
}
|
|
25318
|
+
}
|
|
25319
|
+
return balance;
|
|
25320
|
+
}
|
|
25321
|
+
/**
|
|
25322
|
+
* Get the user's own wallet balances of multiple tokens on Solana, in smallest units.
|
|
25323
|
+
* @param {GetBalancesParams<SolanaChainKey>} params - The chain key, user address, and tokens.
|
|
25324
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
25325
|
+
*/
|
|
25326
|
+
async getWalletBalances(params) {
|
|
25327
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
25328
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
25329
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
25330
|
+
return collector.finish();
|
|
25331
|
+
}
|
|
24869
25332
|
/**
|
|
24870
25333
|
* Sends a message to the hub chain.
|
|
24871
25334
|
* @param dstChainKey - The chain key of the hub chain.
|
|
@@ -25087,8 +25550,84 @@ var IconSpokeService = class {
|
|
|
25087
25550
|
async getDeposit(params) {
|
|
25088
25551
|
const { token, srcChainKey } = params;
|
|
25089
25552
|
const transaction = new CallBuilder().to(token).method("balanceOf").params({ _owner: this.config.getChainConfig(srcChainKey).addresses.assetManager }).build();
|
|
25553
|
+
return this.readIrc2Balance(transaction);
|
|
25554
|
+
}
|
|
25555
|
+
/**
|
|
25556
|
+
* Read an int-returning SCORE call. `iconService.call(...)` registers no result converter, so
|
|
25557
|
+
* `execute()` resolves the raw JSON-RPC `result` — a bare hex string for an int, not `{ value }`.
|
|
25558
|
+
*/
|
|
25559
|
+
async readIrc2Balance(transaction) {
|
|
25560
|
+
const result = await this.iconService.call(transaction).execute();
|
|
25561
|
+
if (typeof result !== "string") {
|
|
25562
|
+
throw new Error(`[IconSpokeService] Unexpected balanceOf response: ${JSON.stringify(result)}`);
|
|
25563
|
+
}
|
|
25564
|
+
return hexToBigInt(result);
|
|
25565
|
+
}
|
|
25566
|
+
/**
|
|
25567
|
+
* Get the user's own wallet balance of a token on ICON, in smallest units. Native ICX is read
|
|
25568
|
+
* via `iconService.getBalance`; IRC-2 tokens via a `balanceOf(_owner)` call on the token contract.
|
|
25569
|
+
* @param {GetBalanceParams<IconChainKey>} params - The chain key, user address, and token.
|
|
25570
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
25571
|
+
*/
|
|
25572
|
+
async getWalletBalance(params) {
|
|
25573
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
25574
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
25575
|
+
const balance = await this.iconService.getBalance(srcAddress).execute();
|
|
25576
|
+
return BigInt(balance.toFixed());
|
|
25577
|
+
}
|
|
25578
|
+
const transaction = new CallBuilder().to(token.address).method("balanceOf").params({ _owner: srcAddress }).build();
|
|
25579
|
+
return this.readIrc2Balance(transaction);
|
|
25580
|
+
}
|
|
25581
|
+
/**
|
|
25582
|
+
* Get the user's own wallet balances of multiple tokens on ICON, in smallest units. Native ICX
|
|
25583
|
+
* is read via `iconService.getBalance`; IRC-2 balances are batched into a single `tryAggregate`
|
|
25584
|
+
* multicall so every `balanceOf(_owner)` read shares one round-trip.
|
|
25585
|
+
* @param {GetBalancesParams<IconChainKey>} params - The chain key, user address, and tokens.
|
|
25586
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
25587
|
+
*/
|
|
25588
|
+
async getWalletBalances(params) {
|
|
25589
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
25590
|
+
const nativeTokens = tokens.filter((token) => isNativeToken(srcChainKey, token));
|
|
25591
|
+
const nonNativeTokens = tokens.filter((token) => !isNativeToken(srcChainKey, token));
|
|
25592
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
25593
|
+
if (nativeTokens.length > 0) {
|
|
25594
|
+
try {
|
|
25595
|
+
const balance = await this.iconService.getBalance(srcAddress).execute();
|
|
25596
|
+
for (const token of nativeTokens) {
|
|
25597
|
+
collector.ok(token.address, BigInt(balance.toFixed()));
|
|
25598
|
+
}
|
|
25599
|
+
} catch (error) {
|
|
25600
|
+
for (const token of nativeTokens) {
|
|
25601
|
+
collector.fail(token.address, error);
|
|
25602
|
+
}
|
|
25603
|
+
}
|
|
25604
|
+
}
|
|
25605
|
+
if (nonNativeTokens.length === 0) {
|
|
25606
|
+
return collector.finish();
|
|
25607
|
+
}
|
|
25608
|
+
const multicallAddress = "cxa4aa9185e23558cff990f494c1fd2845f6cbf741";
|
|
25609
|
+
const calls = nonNativeTokens.map((token) => ({
|
|
25610
|
+
target: token.address,
|
|
25611
|
+
method: "balanceOf",
|
|
25612
|
+
params: [srcAddress]
|
|
25613
|
+
}));
|
|
25614
|
+
const transaction = new CallBuilder().to(multicallAddress).method("tryAggregate").params({ requireSuccess: Converter.toHex(0), calls }).build();
|
|
25090
25615
|
const result = await this.iconService.call(transaction).execute();
|
|
25091
|
-
|
|
25616
|
+
const aggregated = result.returnData;
|
|
25617
|
+
if (!Array.isArray(aggregated) || aggregated.length !== nonNativeTokens.length) {
|
|
25618
|
+
throw new Error(
|
|
25619
|
+
`[IconSpokeService] tryAggregate returned ${Array.isArray(aggregated) ? aggregated.length : "no"} entries for ${nonNativeTokens.length} tokens`
|
|
25620
|
+
);
|
|
25621
|
+
}
|
|
25622
|
+
nonNativeTokens.forEach((token, index) => {
|
|
25623
|
+
const agg = aggregated[index];
|
|
25624
|
+
if (agg && agg.success !== "0x0" && typeof agg.returnData === "string") {
|
|
25625
|
+
collector.ok(token.address, hexToBigInt(agg.returnData));
|
|
25626
|
+
} else {
|
|
25627
|
+
collector.fail(token.address, new Error(`balanceOf failed for ${token.address}: ${agg?.returnData}`));
|
|
25628
|
+
}
|
|
25629
|
+
});
|
|
25630
|
+
return collector.finish();
|
|
25092
25631
|
}
|
|
25093
25632
|
/**
|
|
25094
25633
|
* Sends a message to the hub chain.
|
|
@@ -25154,6 +25693,7 @@ var GAS_PRICE_REGEX = /^(\d+)(.*)$/;
|
|
|
25154
25693
|
var InjectiveSpokeService = class {
|
|
25155
25694
|
config;
|
|
25156
25695
|
chainGrpcWasmApi;
|
|
25696
|
+
indexerGrpcAccountPortfolioApi;
|
|
25157
25697
|
txClient;
|
|
25158
25698
|
endpoints;
|
|
25159
25699
|
pollingIntervalMs;
|
|
@@ -25163,6 +25703,7 @@ var InjectiveSpokeService = class {
|
|
|
25163
25703
|
this.config = config;
|
|
25164
25704
|
this.endpoints = networks.getNetworkEndpoints(networks.Network.Mainnet);
|
|
25165
25705
|
this.chainGrpcWasmApi = new sdkTs.ChainGrpcWasmApi(this.endpoints.grpc);
|
|
25706
|
+
this.indexerGrpcAccountPortfolioApi = new sdkTs.IndexerGrpcAccountPortfolioApi(this.endpoints.indexer);
|
|
25166
25707
|
this.txClient = new sdkTs.TxGrpcApi(this.endpoints.grpc);
|
|
25167
25708
|
this.pollingIntervalMs = this.config.sodaxConfig.chains[ChainKeys.INJECTIVE_MAINNET].pollingConfig.pollingIntervalMs;
|
|
25168
25709
|
this.maxTimeoutMs = this.config.sodaxConfig.chains[ChainKeys.INJECTIVE_MAINNET].pollingConfig.maxTimeoutMs;
|
|
@@ -25246,6 +25787,37 @@ var InjectiveSpokeService = class {
|
|
|
25246
25787
|
);
|
|
25247
25788
|
return BigInt(sdkTs.fromBase64(response.data));
|
|
25248
25789
|
}
|
|
25790
|
+
/**
|
|
25791
|
+
* Get the user's own wallet balance of a token on Injective, in smallest units. On Injective every
|
|
25792
|
+
* asset is a bank coin, so the native coin (`inj`) and factory/peggy/IBC tokens are all read from the
|
|
25793
|
+
* account's portfolio bank balances and matched by denom. The denom is the chain's native denom for
|
|
25794
|
+
* the native coin and `params.token.address` for standard tokens.
|
|
25795
|
+
* @param {GetBalanceParams<InjectiveChainKey>} params - The chain key, user address, and token.
|
|
25796
|
+
* @returns {Promise<bigint>} The token balance in smallest units, or 0n when the account holds none.
|
|
25797
|
+
*/
|
|
25798
|
+
async getWalletBalance(params) {
|
|
25799
|
+
const denom = isNativeToken(params.srcChainKey, params.token) ? this.config.getChainConfig(params.srcChainKey).nativeToken : params.token.address;
|
|
25800
|
+
const portfolio = await this.indexerGrpcAccountPortfolioApi.fetchAccountPortfolioBalances(params.srcAddress);
|
|
25801
|
+
const balance = portfolio.bankBalancesList.find((_balance) => _balance.denom === denom);
|
|
25802
|
+
return balance ? BigInt(balance.amount) : 0n;
|
|
25803
|
+
}
|
|
25804
|
+
/**
|
|
25805
|
+
* Get the user's own wallet balances of multiple tokens on Injective, in smallest units.
|
|
25806
|
+
* @param {GetBalancesParams<InjectiveChainKey>} params - The chain key, user address, and tokens.
|
|
25807
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
25808
|
+
*/
|
|
25809
|
+
async getWalletBalances(params) {
|
|
25810
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
25811
|
+
const portfolio = await this.indexerGrpcAccountPortfolioApi.fetchAccountPortfolioBalances(srcAddress);
|
|
25812
|
+
const amountByDenom = new Map(portfolio.bankBalancesList.map((balance) => [balance.denom, BigInt(balance.amount)]));
|
|
25813
|
+
const nativeDenom = this.config.getChainConfig(srcChainKey).nativeToken;
|
|
25814
|
+
const balances = {};
|
|
25815
|
+
for (const token of tokens) {
|
|
25816
|
+
const denom = isNativeToken(srcChainKey, token) ? nativeDenom : token.address;
|
|
25817
|
+
balances[token.address] = amountByDenom.get(denom) ?? 0n;
|
|
25818
|
+
}
|
|
25819
|
+
return balances;
|
|
25820
|
+
}
|
|
25249
25821
|
async getRawTransaction(chainId, senderAddress, contractAddress, msg, memo, funds = []) {
|
|
25250
25822
|
const msgExec = sdkTs.MsgExecuteContract.fromJSON({
|
|
25251
25823
|
contractAddress,
|
|
@@ -26053,6 +26625,138 @@ var SpokeService = class _SpokeService {
|
|
|
26053
26625
|
return { ok: false, error };
|
|
26054
26626
|
}
|
|
26055
26627
|
}
|
|
26628
|
+
/**
|
|
26629
|
+
* Get a user's own wallet balance of a single token on a spoke chain, in smallest units.
|
|
26630
|
+
* Chain-agnostic: dispatches to the per-chain service, which reads the native coin or the
|
|
26631
|
+
* chain's token standard (EVM erc20, Solana SPL, …). Unlike {@link getDeposit}, this reads
|
|
26632
|
+
* `srcAddress` itself, not the protocol asset manager.
|
|
26633
|
+
* @param {GetBalanceParams<C>} params - The chain key, user address, and token.
|
|
26634
|
+
* @returns {Promise<Result<bigint>>} The token balance in smallest units.
|
|
26635
|
+
*/
|
|
26636
|
+
async getWalletBalance(params) {
|
|
26637
|
+
try {
|
|
26638
|
+
if (isHubChainKeyType(params.srcChainKey)) {
|
|
26639
|
+
const value = await this.sonic.getWalletBalance(params);
|
|
26640
|
+
return { ok: true, value };
|
|
26641
|
+
}
|
|
26642
|
+
const chainType = getChainType(params.srcChainKey);
|
|
26643
|
+
switch (chainType) {
|
|
26644
|
+
case "EVM": {
|
|
26645
|
+
const value = await this.evm.getWalletBalance(params);
|
|
26646
|
+
return { ok: true, value };
|
|
26647
|
+
}
|
|
26648
|
+
case "INJECTIVE": {
|
|
26649
|
+
const value = await this.injective.getWalletBalance(params);
|
|
26650
|
+
return { ok: true, value };
|
|
26651
|
+
}
|
|
26652
|
+
case "STELLAR": {
|
|
26653
|
+
const value = await this.stellar.getWalletBalance(params);
|
|
26654
|
+
return { ok: true, value };
|
|
26655
|
+
}
|
|
26656
|
+
case "SUI": {
|
|
26657
|
+
const value = await this.sui.getWalletBalance(params);
|
|
26658
|
+
return { ok: true, value };
|
|
26659
|
+
}
|
|
26660
|
+
case "ICON": {
|
|
26661
|
+
const value = await this.icon.getWalletBalance(params);
|
|
26662
|
+
return { ok: true, value };
|
|
26663
|
+
}
|
|
26664
|
+
case "SOLANA": {
|
|
26665
|
+
const value = await this.solana.getWalletBalance(params);
|
|
26666
|
+
return { ok: true, value };
|
|
26667
|
+
}
|
|
26668
|
+
case "STACKS": {
|
|
26669
|
+
const value = await this.stacks.getWalletBalance(params);
|
|
26670
|
+
return { ok: true, value };
|
|
26671
|
+
}
|
|
26672
|
+
case "BITCOIN": {
|
|
26673
|
+
const value = await this.bitcoin.getWalletBalance(params);
|
|
26674
|
+
return { ok: true, value };
|
|
26675
|
+
}
|
|
26676
|
+
case "NEAR": {
|
|
26677
|
+
const value = await this.near.getWalletBalance(params);
|
|
26678
|
+
return { ok: true, value };
|
|
26679
|
+
}
|
|
26680
|
+
default: {
|
|
26681
|
+
const exhaustiveCheck = chainType;
|
|
26682
|
+
this.config.logger.debug("Unhandled exhaustive case", { value: exhaustiveCheck });
|
|
26683
|
+
return {
|
|
26684
|
+
ok: false,
|
|
26685
|
+
error: new Error(`[getWalletBalance] Invalid chain type. Valid chain types: ${ChainTypeArr.join(", ")}`)
|
|
26686
|
+
};
|
|
26687
|
+
}
|
|
26688
|
+
}
|
|
26689
|
+
} catch (error) {
|
|
26690
|
+
return { ok: false, error };
|
|
26691
|
+
}
|
|
26692
|
+
}
|
|
26693
|
+
/**
|
|
26694
|
+
* Get a user's own wallet balances of multiple tokens on a spoke chain, in smallest units.
|
|
26695
|
+
* Chain-agnostic sibling of {@link getWalletBalance}; per-chain services batch the reads where the
|
|
26696
|
+
* chain supports it (e.g. EVM multicall3, ICON aggregated call data).
|
|
26697
|
+
* @param {GetBalancesParams<C>} params - The chain key, user address, and tokens.
|
|
26698
|
+
* @returns {Promise<Result<WalletBalanceMap>>} A map of token address to balance in smallest
|
|
26699
|
+
* units. A token that could not be read is logged and reported as `0n`; the `Result` fails when
|
|
26700
|
+
* the whole batch is unusable — invalid chain, a shared round-trip every token depends on, or a
|
|
26701
|
+
* batch in which no token could be read at all.
|
|
26702
|
+
*/
|
|
26703
|
+
async getWalletBalances(params) {
|
|
26704
|
+
try {
|
|
26705
|
+
if (isHubChainKeyType(params.srcChainKey)) {
|
|
26706
|
+
const value = await this.sonic.getWalletBalances(params);
|
|
26707
|
+
return { ok: true, value };
|
|
26708
|
+
}
|
|
26709
|
+
const chainType = getChainType(params.srcChainKey);
|
|
26710
|
+
switch (chainType) {
|
|
26711
|
+
case "EVM": {
|
|
26712
|
+
const value = await this.evm.getWalletBalances(params);
|
|
26713
|
+
return { ok: true, value };
|
|
26714
|
+
}
|
|
26715
|
+
case "INJECTIVE": {
|
|
26716
|
+
const value = await this.injective.getWalletBalances(params);
|
|
26717
|
+
return { ok: true, value };
|
|
26718
|
+
}
|
|
26719
|
+
case "STELLAR": {
|
|
26720
|
+
const value = await this.stellar.getWalletBalances(params);
|
|
26721
|
+
return { ok: true, value };
|
|
26722
|
+
}
|
|
26723
|
+
case "SUI": {
|
|
26724
|
+
const value = await this.sui.getWalletBalances(params);
|
|
26725
|
+
return { ok: true, value };
|
|
26726
|
+
}
|
|
26727
|
+
case "ICON": {
|
|
26728
|
+
const value = await this.icon.getWalletBalances(params);
|
|
26729
|
+
return { ok: true, value };
|
|
26730
|
+
}
|
|
26731
|
+
case "SOLANA": {
|
|
26732
|
+
const value = await this.solana.getWalletBalances(params);
|
|
26733
|
+
return { ok: true, value };
|
|
26734
|
+
}
|
|
26735
|
+
case "STACKS": {
|
|
26736
|
+
const value = await this.stacks.getWalletBalances(params);
|
|
26737
|
+
return { ok: true, value };
|
|
26738
|
+
}
|
|
26739
|
+
case "BITCOIN": {
|
|
26740
|
+
const value = await this.bitcoin.getWalletBalances(params);
|
|
26741
|
+
return { ok: true, value };
|
|
26742
|
+
}
|
|
26743
|
+
case "NEAR": {
|
|
26744
|
+
const value = await this.near.getWalletBalances(params);
|
|
26745
|
+
return { ok: true, value };
|
|
26746
|
+
}
|
|
26747
|
+
default: {
|
|
26748
|
+
const exhaustiveCheck = chainType;
|
|
26749
|
+
this.config.logger.debug("Unhandled exhaustive case", { value: exhaustiveCheck });
|
|
26750
|
+
return {
|
|
26751
|
+
ok: false,
|
|
26752
|
+
error: new Error(`[getWalletBalances] Invalid chain type. Valid chain types: ${ChainTypeArr.join(", ")}`)
|
|
26753
|
+
};
|
|
26754
|
+
}
|
|
26755
|
+
}
|
|
26756
|
+
} catch (error) {
|
|
26757
|
+
return { ok: false, error };
|
|
26758
|
+
}
|
|
26759
|
+
}
|
|
26056
26760
|
/**
|
|
26057
26761
|
* Calls the connection contract on the spoke chain to send a message to the hub wallet, which then executes the message's payload.
|
|
26058
26762
|
* @param {HubAddress} from - The address of the user on the hub chain.
|
|
@@ -27894,9 +28598,38 @@ var TokensByChainMapSchema = v__namespace.custom(
|
|
|
27894
28598
|
);
|
|
27895
28599
|
var TokensListSchema = v__namespace.array(XTokenSchema);
|
|
27896
28600
|
var ReserveAssetsSchema = v__namespace.array(AddressSchema);
|
|
28601
|
+
var ORACLE_CANDLE_INTERVALS = ["1m", "5m", "1h", "1d"];
|
|
28602
|
+
var OracleCandleIntervalSchema = v__namespace.picklist(ORACLE_CANDLE_INTERVALS);
|
|
28603
|
+
var OracleMarketsResponseSchema = v__namespace.object({
|
|
28604
|
+
quote: v__namespace.string(),
|
|
28605
|
+
intervals: v__namespace.array(
|
|
28606
|
+
v__namespace.object({
|
|
28607
|
+
key: v__namespace.string(),
|
|
28608
|
+
label: v__namespace.string(),
|
|
28609
|
+
seconds: v__namespace.number()
|
|
28610
|
+
})
|
|
28611
|
+
),
|
|
28612
|
+
symbols: v__namespace.array(v__namespace.string())
|
|
28613
|
+
});
|
|
28614
|
+
var OracleCandlesResponseSchema = v__namespace.object({
|
|
28615
|
+
symbol: v__namespace.string(),
|
|
28616
|
+
quote: v__namespace.string(),
|
|
28617
|
+
interval: OracleCandleIntervalSchema,
|
|
28618
|
+
candles: v__namespace.array(
|
|
28619
|
+
v__namespace.object({
|
|
28620
|
+
timestamp: v__namespace.number(),
|
|
28621
|
+
open: v__namespace.string(),
|
|
28622
|
+
high: v__namespace.string(),
|
|
28623
|
+
low: v__namespace.string(),
|
|
28624
|
+
close: v__namespace.string(),
|
|
28625
|
+
final: v__namespace.optional(v__namespace.boolean())
|
|
28626
|
+
})
|
|
28627
|
+
)
|
|
28628
|
+
});
|
|
27897
28629
|
|
|
27898
28630
|
// src/backendApi/guards.ts
|
|
27899
28631
|
var isFillEvent = (value) => v__namespace.is(FillEventSchema, value);
|
|
28632
|
+
var isOracleCandleInterval = (value) => v__namespace.is(OracleCandleIntervalSchema, value);
|
|
27900
28633
|
function decodePacketIntentTarget(payload) {
|
|
27901
28634
|
try {
|
|
27902
28635
|
const hex = payload.startsWith("0x") ? payload.slice(2) : payload;
|
|
@@ -32429,6 +33162,46 @@ var BackendApiService = class {
|
|
|
32429
33162
|
const endpoint = `/moneymarket/borrowers?${queryString}`;
|
|
32430
33163
|
return this.request(endpoint, { ...config, method: "GET" }, MoneyMarketBorrowersSchema);
|
|
32431
33164
|
}
|
|
33165
|
+
// Oracle endpoints
|
|
33166
|
+
/**
|
|
33167
|
+
* Fetch the oracle candle store's discovery payload: the quote currency (currently always
|
|
33168
|
+
* `"USD"`), the selectable candle intervals, and the canonical symbols that have candle data.
|
|
33169
|
+
*
|
|
33170
|
+
* Use this to populate a symbol picker and interval switcher before calling
|
|
33171
|
+
* {@link getOracleCandles}.
|
|
33172
|
+
*
|
|
33173
|
+
* @returns `Result<OracleMarketsResponse>` — on success, `{ quote, intervals, symbols }`.
|
|
33174
|
+
*/
|
|
33175
|
+
async getOracleMarkets(config) {
|
|
33176
|
+
return this.request("/oracle/markets", { ...config, method: "GET" }, OracleMarketsResponseSchema);
|
|
33177
|
+
}
|
|
33178
|
+
/**
|
|
33179
|
+
* Fetch USD OHLC candles for a symbol over the half-open time range `[from, to)`.
|
|
33180
|
+
*
|
|
33181
|
+
* `from` and `to` are UNIX **seconds** (integers); `to` is exclusive and must exceed `from`,
|
|
33182
|
+
* and the range may cover at most 5000 buckets of the requested interval (invalid or wider
|
|
33183
|
+
* ranges fail with HTTP 400). A valid range with no stored candles resolves `ok` with
|
|
33184
|
+
* `candles: []`; an unknown symbol currently does the same rather than returning 404. The last
|
|
33185
|
+
* candle may still be forming; re-poll while its `final === false`.
|
|
33186
|
+
* Responses are cached server-side for roughly 10 seconds per distinct URL.
|
|
33187
|
+
*
|
|
33188
|
+
* @param params.symbol - Canonical symbol, exact case, from {@link getOracleMarkets} (e.g. `"ETH"`).
|
|
33189
|
+
* @param params.interval - Candle bucket size: `'1m' | '5m' | '1h' | '1d'`.
|
|
33190
|
+
* @param params.from - Range start, UNIX seconds, inclusive.
|
|
33191
|
+
* @param params.to - Range end, UNIX seconds, exclusive.
|
|
33192
|
+
* @returns `Result<OracleCandlesResponse>` — on success, the echoed query dimensions and
|
|
33193
|
+
* oldest-first candles with USD decimal-string prices (no volume field).
|
|
33194
|
+
*/
|
|
33195
|
+
async getOracleCandles(params, config) {
|
|
33196
|
+
const queryParams = new URLSearchParams();
|
|
33197
|
+
queryParams.append("symbol", params.symbol);
|
|
33198
|
+
queryParams.append("interval", params.interval);
|
|
33199
|
+
queryParams.append("from", String(params.from));
|
|
33200
|
+
queryParams.append("to", String(params.to));
|
|
33201
|
+
const queryString = queryParams.toString();
|
|
33202
|
+
const endpoint = `/oracle/candles?${queryString}`;
|
|
33203
|
+
return this.request(endpoint, { ...config, method: "GET" }, OracleCandlesResponseSchema);
|
|
33204
|
+
}
|
|
32432
33205
|
/**
|
|
32433
33206
|
* Fetch the complete SODAX runtime configuration in a single request.
|
|
32434
33207
|
*
|
|
@@ -42619,7 +43392,7 @@ function xlmDecimalToStroops(amount) {
|
|
|
42619
43392
|
const scaled = `${whole}${fraction.padEnd(XLM_DECIMALS, "0").slice(0, XLM_DECIMALS)}`;
|
|
42620
43393
|
return BigInt(scaled);
|
|
42621
43394
|
}
|
|
42622
|
-
var
|
|
43395
|
+
var STELLAR_BASE_RESERVE_STROOPS2 = 5000000n;
|
|
42623
43396
|
var BASE_RESERVE_UNITS = 2;
|
|
42624
43397
|
function parseBaseReserveStroops(ledger) {
|
|
42625
43398
|
const value = ledger?.base_reserve_in_stroops;
|
|
@@ -42646,7 +43419,7 @@ var SPONSOR_CONFIG_TTL_MS = 6e4;
|
|
|
42646
43419
|
var STELLAR_BASE_RESERVE_TTL_MS = 36e5;
|
|
42647
43420
|
var DEFAULT_MAX_HORIZON_RETRIES = 2;
|
|
42648
43421
|
var STELLAR_FEE_HEADROOM_STROOPS = 100000n;
|
|
42649
|
-
var STELLAR_TRUSTLINE_MIN_XLM_STROOPS =
|
|
43422
|
+
var STELLAR_TRUSTLINE_MIN_XLM_STROOPS = STELLAR_BASE_RESERVE_STROOPS2 + STELLAR_FEE_HEADROOM_STROOPS;
|
|
42650
43423
|
var SponsoringService = class {
|
|
42651
43424
|
config;
|
|
42652
43425
|
spoke;
|
|
@@ -42749,7 +43522,7 @@ var SponsoringService = class {
|
|
|
42749
43522
|
reason: messageOf(error, String(error))
|
|
42750
43523
|
});
|
|
42751
43524
|
}
|
|
42752
|
-
return
|
|
43525
|
+
return STELLAR_BASE_RESERVE_STROOPS2;
|
|
42753
43526
|
};
|
|
42754
43527
|
const request = read().then((value) => {
|
|
42755
43528
|
this.baseReserveCache = { value, expiresAt: Date.now() + STELLAR_BASE_RESERVE_TTL_MS };
|
|
@@ -43203,6 +43976,7 @@ exports.NEAR_CHAIN_KEYS_SET = NEAR_CHAIN_KEYS_SET;
|
|
|
43203
43976
|
exports.NEAR_DEFAULT_GAS = NEAR_DEFAULT_GAS;
|
|
43204
43977
|
exports.NEAR_STORAGE_DEPOSIT = NEAR_STORAGE_DEPOSIT;
|
|
43205
43978
|
exports.NearSpokeService = NearSpokeService;
|
|
43979
|
+
exports.ORACLE_CANDLE_INTERVALS = ORACLE_CANDLE_INTERVALS;
|
|
43206
43980
|
exports.PartnerFeeClaimService = PartnerFeeClaimService;
|
|
43207
43981
|
exports.PartnerService = PartnerService;
|
|
43208
43982
|
exports.Permit2Service = Permit2Service;
|
|
@@ -43301,6 +44075,7 @@ exports.concentratedLiquidityConfig = concentratedLiquidityConfig;
|
|
|
43301
44075
|
exports.connectionAbi = connectionAbi;
|
|
43302
44076
|
exports.consoleLogger = consoleLogger;
|
|
43303
44077
|
exports.convertTransactionInstructionToRaw = convertTransactionInstructionToRaw;
|
|
44078
|
+
exports.createBalanceCollector = createBalanceCollector;
|
|
43304
44079
|
exports.createInvariant = createInvariant;
|
|
43305
44080
|
exports.deepMerge = deepMerge;
|
|
43306
44081
|
exports.defaultHookAbi = defaultHookAbi;
|
|
@@ -43434,6 +44209,7 @@ exports.isNewbnUSDToken = isNewbnUSDToken;
|
|
|
43434
44209
|
exports.isOptionalBitcoinWalletProviderType = isOptionalBitcoinWalletProviderType;
|
|
43435
44210
|
exports.isOptionalEvmWalletProviderType = isOptionalEvmWalletProviderType;
|
|
43436
44211
|
exports.isOptionalStellarWalletProviderType = isOptionalStellarWalletProviderType;
|
|
44212
|
+
exports.isOracleCandleInterval = isOracleCandleInterval;
|
|
43437
44213
|
exports.isPartnerError = isPartnerError;
|
|
43438
44214
|
exports.isPartnerFeeAmount = isPartnerFeeAmount;
|
|
43439
44215
|
exports.isPartnerFeePercentage = isPartnerFeePercentage;
|
|
@@ -43535,6 +44311,7 @@ exports.reverseEncodeAddress = reverseEncodeAddress;
|
|
|
43535
44311
|
exports.robinhoodChain = robinhoodChain;
|
|
43536
44312
|
exports.robinhoodSupportedTokens = robinhoodSupportedTokens;
|
|
43537
44313
|
exports.serializeAddressData = serializeAddressData;
|
|
44314
|
+
exports.settleWalletBalances = settleWalletBalances;
|
|
43538
44315
|
exports.silentLogger = silentLogger;
|
|
43539
44316
|
exports.sleep = sleep;
|
|
43540
44317
|
exports.sodaxConfig = sodaxConfig;
|