@sodax/sdk 2.1.0 → 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 +1067 -175
- package/dist/index.d.cts +529 -27
- package/dist/index.d.ts +529 -27
- package/dist/index.mjs +1061 -178
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -10,11 +10,11 @@ import * as ecc from '@bitcoinerlab/secp256k1';
|
|
|
10
10
|
import { CLPositionManagerAbi, encodeCLPositionManagerMintCalldata, encodeCLPositionManagerIncreaseLiquidityCalldata, encodeCLPositionManagerDecreaseLiquidityCalldata, getPoolId, CLPoolManagerAbi, decodePoolKey } from '@pancakeswap/infinity-sdk';
|
|
11
11
|
import { Transaction as Transaction$1 } from '@mysten/sui/transactions';
|
|
12
12
|
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
13
|
-
import { TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddress } from '@solana/spl-token';
|
|
13
|
+
import { TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, unpackAccount, getAssociatedTokenAddress } from '@solana/spl-token';
|
|
14
14
|
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
15
15
|
import BN from 'bn.js';
|
|
16
16
|
import * as IconSdkRaw from 'icon-sdk-js';
|
|
17
|
-
import { ChainGrpcWasmApi, TxGrpcApi, toBase64, fromBase64, MsgExecuteContract, ChainRestAuthApi, BaseAccount, createTransaction } from '@injectivelabs/sdk-ts';
|
|
17
|
+
import { ChainGrpcWasmApi, IndexerGrpcAccountPortfolioApi, TxGrpcApi, toBase64, fromBase64, MsgExecuteContract, ChainRestAuthApi, BaseAccount, createTransaction } from '@injectivelabs/sdk-ts';
|
|
18
18
|
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
|
|
19
19
|
import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
|
|
20
20
|
import * as v from 'valibot';
|
|
@@ -3528,7 +3528,9 @@ var spokeChainConfig = {
|
|
|
3528
3528
|
},
|
|
3529
3529
|
chain: baseChainInfo[ChainKeys.BITCOIN_MAINNET],
|
|
3530
3530
|
bnUSD: "no",
|
|
3531
|
-
|
|
3531
|
+
// Must equal bitcoinSupportedTokens.BTC.address: isNativeToken compares a token's `address`
|
|
3532
|
+
// against this value, so a symbol here classifies native BTC as a contract token.
|
|
3533
|
+
nativeToken: "0:0",
|
|
3532
3534
|
supportedTokens: bitcoinSupportedTokens,
|
|
3533
3535
|
radfi: {
|
|
3534
3536
|
walletMode: "TRADING",
|
|
@@ -3696,7 +3698,7 @@ var spokeChainConfig = {
|
|
|
3696
3698
|
}
|
|
3697
3699
|
},
|
|
3698
3700
|
[ChainKeys.NEAR_MAINNET]: {
|
|
3699
|
-
rpcUrl: "https://
|
|
3701
|
+
rpcUrl: "https://free.rpc.fastnear.com",
|
|
3700
3702
|
chain: baseChainInfo[ChainKeys.NEAR_MAINNET],
|
|
3701
3703
|
nativeToken: "NEAR",
|
|
3702
3704
|
addresses: {
|
|
@@ -4078,8 +4080,12 @@ var moneyMarketSupportedTokens = {
|
|
|
4078
4080
|
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.USDS,
|
|
4079
4081
|
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.XLM
|
|
4080
4082
|
],
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
+
[ChainKeys.ROBINHOOD_MAINNET]: [
|
|
4084
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.ETH,
|
|
4085
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.bnUSD,
|
|
4086
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.SODA,
|
|
4087
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.USDG
|
|
4088
|
+
]
|
|
4083
4089
|
};
|
|
4084
4090
|
var moneyMarketReserveAssets = [
|
|
4085
4091
|
...Object.values(SodaTokens).map((vault) => vault.address),
|
|
@@ -4858,7 +4864,7 @@ function isValidWalletProviderForChainKey(chainKey, walletProvider) {
|
|
|
4858
4864
|
}
|
|
4859
4865
|
|
|
4860
4866
|
// ../types/dist/index.js
|
|
4861
|
-
var CONFIG_VERSION =
|
|
4867
|
+
var CONFIG_VERSION = 232;
|
|
4862
4868
|
|
|
4863
4869
|
// src/shared/utils/resolveTimeoutMs.ts
|
|
4864
4870
|
function resolveTimeoutMs(timeout, fallbackMs) {
|
|
@@ -5407,6 +5413,12 @@ function isFeatureError(feature) {
|
|
|
5407
5413
|
function isCodeMember(codes) {
|
|
5408
5414
|
return (e) => isSodaxError(e) && codes.has(e.code);
|
|
5409
5415
|
}
|
|
5416
|
+
function isAuthStatus(status) {
|
|
5417
|
+
return status === 401 || status === 403;
|
|
5418
|
+
}
|
|
5419
|
+
function isAuthFailure(error) {
|
|
5420
|
+
return isSodaxError(error) && isAuthStatus(error.context?.status);
|
|
5421
|
+
}
|
|
5410
5422
|
|
|
5411
5423
|
// src/errors/wrappers.ts
|
|
5412
5424
|
function messageOf(error, fallback2) {
|
|
@@ -14464,6 +14476,13 @@ var ConfigService = class {
|
|
|
14464
14476
|
* a client-side option set via `new Sodax({ fee })`. Per-feature overrides live on the feature config.
|
|
14465
14477
|
*/
|
|
14466
14478
|
fee;
|
|
14479
|
+
/**
|
|
14480
|
+
* Global backend API key. Resolved once at construction and kept independent of {@link sodax} so
|
|
14481
|
+
* that {@link initialize}'s dynamic-config swap never clobbers it. The backend never supplies it —
|
|
14482
|
+
* it is a client-side option set via `new Sodax({ apiKey })`. Never logged; read here by the swap,
|
|
14483
|
+
* leverage-yield, and partner solver flows, whose transport does not go through `BackendApiService`.
|
|
14484
|
+
*/
|
|
14485
|
+
apiKey;
|
|
14467
14486
|
/**
|
|
14468
14487
|
* RadFi/Bound request signer. Resolved once at construction and kept independent of {@link sodax}
|
|
14469
14488
|
* so that {@link initialize}'s dynamic-config swap never clobbers it. Read by `BitcoinSpokeService`
|
|
@@ -14484,11 +14503,21 @@ var ConfigService = class {
|
|
|
14484
14503
|
hubAssetToXTokenMap;
|
|
14485
14504
|
// `api` / `userConfig` are accepted but unused while initialize()'s dynamic fetch is disabled
|
|
14486
14505
|
// (see TODO(config-v2) below); restore their assignments when re-enabling.
|
|
14487
|
-
constructor({
|
|
14506
|
+
constructor({
|
|
14507
|
+
api,
|
|
14508
|
+
config,
|
|
14509
|
+
userConfig,
|
|
14510
|
+
logger,
|
|
14511
|
+
analytics,
|
|
14512
|
+
fee,
|
|
14513
|
+
apiKey,
|
|
14514
|
+
radfiSigner
|
|
14515
|
+
}) {
|
|
14488
14516
|
this.sodax = config;
|
|
14489
14517
|
this.logger = logger ?? resolveLogger(void 0);
|
|
14490
14518
|
this.analytics = analytics ?? noopAnalytics;
|
|
14491
14519
|
this.fee = fee;
|
|
14520
|
+
this.apiKey = apiKey;
|
|
14492
14521
|
this.radfiSigner = radfiSigner;
|
|
14493
14522
|
this.loadSodaxConfigDataStructures(config);
|
|
14494
14523
|
}
|
|
@@ -14682,7 +14711,9 @@ var ConfigService = class {
|
|
|
14682
14711
|
])
|
|
14683
14712
|
);
|
|
14684
14713
|
this.loadSpokeChainConfigDataStructures(sodaxConfig2);
|
|
14685
|
-
this.moneyMarketReserveAssetsSet = new Set(
|
|
14714
|
+
this.moneyMarketReserveAssetsSet = new Set(
|
|
14715
|
+
sodaxConfig2.moneyMarket.supportedReserveAssets.map((address) => address.toLowerCase())
|
|
14716
|
+
);
|
|
14686
14717
|
this.stakedATokenAddressesSet = new Set(
|
|
14687
14718
|
Object.keys(sodaxConfig2.dex.statATokenAddresses).map((address) => address.toLowerCase())
|
|
14688
14719
|
);
|
|
@@ -15397,10 +15428,54 @@ var EvmAssetManagerService = class _EvmAssetManagerService {
|
|
|
15397
15428
|
});
|
|
15398
15429
|
}
|
|
15399
15430
|
};
|
|
15431
|
+
|
|
15432
|
+
// src/shared/services/spoke/balance-utils.ts
|
|
15433
|
+
function createBalanceCollector({ logger, chainKey }) {
|
|
15434
|
+
const balances = {};
|
|
15435
|
+
let attempted = 0;
|
|
15436
|
+
let failed = 0;
|
|
15437
|
+
return {
|
|
15438
|
+
ok(tokenAddress, value) {
|
|
15439
|
+
attempted++;
|
|
15440
|
+
balances[tokenAddress] = value;
|
|
15441
|
+
},
|
|
15442
|
+
fail(tokenAddress, reason) {
|
|
15443
|
+
attempted++;
|
|
15444
|
+
failed++;
|
|
15445
|
+
logger.warn("[getWalletBalances] balance read failed, reporting 0n", {
|
|
15446
|
+
chainKey,
|
|
15447
|
+
token: tokenAddress,
|
|
15448
|
+
error: reason instanceof Error ? reason.message : String(reason)
|
|
15449
|
+
});
|
|
15450
|
+
balances[tokenAddress] = 0n;
|
|
15451
|
+
},
|
|
15452
|
+
finish() {
|
|
15453
|
+
if (attempted > 0 && failed === attempted) {
|
|
15454
|
+
throw new Error(`[getWalletBalances] every balance read failed on ${chainKey} (${failed}/${attempted})`);
|
|
15455
|
+
}
|
|
15456
|
+
return balances;
|
|
15457
|
+
}
|
|
15458
|
+
};
|
|
15459
|
+
}
|
|
15460
|
+
async function settleWalletBalances(collector, tokens, read) {
|
|
15461
|
+
const settled = await Promise.allSettled(tokens.map((token) => read(token)));
|
|
15462
|
+
tokens.forEach((token, index) => {
|
|
15463
|
+
const outcome = settled[index];
|
|
15464
|
+
if (!outcome) return;
|
|
15465
|
+
if (outcome.status === "fulfilled") {
|
|
15466
|
+
collector.ok(token.address, outcome.value);
|
|
15467
|
+
} else {
|
|
15468
|
+
collector.fail(token.address, outcome.reason);
|
|
15469
|
+
}
|
|
15470
|
+
});
|
|
15471
|
+
}
|
|
15400
15472
|
var HEDERA_NATIVE_VALUE_SCALE = 10n ** 10n;
|
|
15401
15473
|
function scaleNativeMsgValue(chainKey, amount) {
|
|
15402
15474
|
return chainKey === ChainKeys.HEDERA_MAINNET ? amount * HEDERA_NATIVE_VALUE_SCALE : amount;
|
|
15403
15475
|
}
|
|
15476
|
+
function scaleNativeBalance(chainKey, amount) {
|
|
15477
|
+
return chainKey === ChainKeys.HEDERA_MAINNET ? amount / HEDERA_NATIVE_VALUE_SCALE : amount;
|
|
15478
|
+
}
|
|
15404
15479
|
var EvmSpokeService = class {
|
|
15405
15480
|
config;
|
|
15406
15481
|
// map containing the public clients for each evm spoke chain, lazy loaded on demand
|
|
@@ -15517,6 +15592,79 @@ var EvmSpokeService = class {
|
|
|
15517
15592
|
args: [this.config.getChainConfig(params.srcChainKey).addresses.assetManager]
|
|
15518
15593
|
});
|
|
15519
15594
|
}
|
|
15595
|
+
/**
|
|
15596
|
+
* Get the user's own wallet balance of a token on an EVM spoke chain, in smallest units.
|
|
15597
|
+
* Native coin via `eth_getBalance` (Hedera scaled to canonical decimals); erc20 via `balanceOf`.
|
|
15598
|
+
* @param {GetBalanceParams<EvmSpokeOnlyChainKey>} params - The chain key, user address, and token.
|
|
15599
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
15600
|
+
*/
|
|
15601
|
+
async getWalletBalance(params) {
|
|
15602
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
15603
|
+
const publicClient = this.getPublicClient(srcChainKey);
|
|
15604
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
15605
|
+
const balance2 = await publicClient.getBalance({ address: srcAddress });
|
|
15606
|
+
return scaleNativeBalance(srcChainKey, balance2);
|
|
15607
|
+
}
|
|
15608
|
+
const balance = await publicClient.readContract({
|
|
15609
|
+
address: token.address,
|
|
15610
|
+
abi: erc20Abi,
|
|
15611
|
+
functionName: "balanceOf",
|
|
15612
|
+
args: [srcAddress]
|
|
15613
|
+
});
|
|
15614
|
+
return balance ?? 0n;
|
|
15615
|
+
}
|
|
15616
|
+
/**
|
|
15617
|
+
* Get the user's own wallet balances of multiple tokens on an EVM spoke chain, in smallest
|
|
15618
|
+
* units. Non-native tokens are batched via multicall3 when the chain supports it, otherwise
|
|
15619
|
+
* read in parallel.
|
|
15620
|
+
* @param {GetBalancesParams<EvmSpokeOnlyChainKey>} params - The chain key, user address, and tokens.
|
|
15621
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
15622
|
+
*/
|
|
15623
|
+
async getWalletBalances(params) {
|
|
15624
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
15625
|
+
const nativeTokens = tokens.filter((token) => isNativeToken(srcChainKey, token));
|
|
15626
|
+
const nonNativeTokens = tokens.filter((token) => !isNativeToken(srcChainKey, token));
|
|
15627
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
15628
|
+
await settleWalletBalances(
|
|
15629
|
+
collector,
|
|
15630
|
+
nativeTokens,
|
|
15631
|
+
(token) => this.getWalletBalance({ srcChainKey, srcAddress, token })
|
|
15632
|
+
);
|
|
15633
|
+
if (nonNativeTokens.length === 0) {
|
|
15634
|
+
return collector.finish();
|
|
15635
|
+
}
|
|
15636
|
+
const publicClient = this.getPublicClient(srcChainKey);
|
|
15637
|
+
if (getEvmViemChain(srcChainKey).contracts?.multicall3) {
|
|
15638
|
+
const results = await publicClient.multicall({
|
|
15639
|
+
contracts: nonNativeTokens.map((token) => ({
|
|
15640
|
+
abi: erc20Abi,
|
|
15641
|
+
address: token.address,
|
|
15642
|
+
functionName: "balanceOf",
|
|
15643
|
+
args: [srcAddress]
|
|
15644
|
+
}))
|
|
15645
|
+
});
|
|
15646
|
+
nonNativeTokens.forEach((token, index) => {
|
|
15647
|
+
const result = results[index];
|
|
15648
|
+
if (result?.status === "success") {
|
|
15649
|
+
collector.ok(token.address, BigInt(result.result));
|
|
15650
|
+
} else {
|
|
15651
|
+
collector.fail(token.address, result?.error ?? new Error(`missing multicall result for ${token.address}`));
|
|
15652
|
+
}
|
|
15653
|
+
});
|
|
15654
|
+
return collector.finish();
|
|
15655
|
+
}
|
|
15656
|
+
await settleWalletBalances(
|
|
15657
|
+
collector,
|
|
15658
|
+
nonNativeTokens,
|
|
15659
|
+
(token) => publicClient.readContract({
|
|
15660
|
+
address: token.address,
|
|
15661
|
+
abi: erc20Abi,
|
|
15662
|
+
functionName: "balanceOf",
|
|
15663
|
+
args: [srcAddress]
|
|
15664
|
+
})
|
|
15665
|
+
);
|
|
15666
|
+
return collector.finish();
|
|
15667
|
+
}
|
|
15520
15668
|
/**
|
|
15521
15669
|
* Sends a message to the hub chain.
|
|
15522
15670
|
* @param {SendMessageParams} params - Includes dstChainKey, the chain key of the hub chain.
|
|
@@ -15711,6 +15859,31 @@ var StacksSpokeService = class {
|
|
|
15711
15859
|
}
|
|
15712
15860
|
return this.readTokenBalance(params.token, assetManager);
|
|
15713
15861
|
}
|
|
15862
|
+
/**
|
|
15863
|
+
* Get the user's own wallet balance of a token on Stacks, in smallest units. Native STX via the
|
|
15864
|
+
* Hiro REST `/extended/v1/address/{addr}/balances` endpoint; SIP-010 fungible tokens via the
|
|
15865
|
+
* read-only `get-balance` contract call. Unlike {@link getDeposit}, this reads the holding of
|
|
15866
|
+
* `srcAddress` (the user), not the protocol asset manager.
|
|
15867
|
+
* @param {GetBalanceParams<StacksChainKey>} params - The chain key, user address, and token.
|
|
15868
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
15869
|
+
*/
|
|
15870
|
+
async getWalletBalance(params) {
|
|
15871
|
+
if (isNativeToken(params.srcChainKey, params.token)) {
|
|
15872
|
+
return this.getSTXBalance(params.srcAddress);
|
|
15873
|
+
}
|
|
15874
|
+
return this.readTokenBalance(params.token.address, params.srcAddress);
|
|
15875
|
+
}
|
|
15876
|
+
/**
|
|
15877
|
+
* Get the user's own wallet balances of multiple tokens on Stacks, in smallest units.
|
|
15878
|
+
* @param {GetBalancesParams<StacksChainKey>} params - The chain key, user address, and tokens.
|
|
15879
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
15880
|
+
*/
|
|
15881
|
+
async getWalletBalances(params) {
|
|
15882
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
15883
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
15884
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
15885
|
+
return collector.finish();
|
|
15886
|
+
}
|
|
15714
15887
|
/**
|
|
15715
15888
|
* Sends a message to the hub chain.
|
|
15716
15889
|
*/
|
|
@@ -16271,6 +16444,32 @@ var BitcoinSpokeService = class {
|
|
|
16271
16444
|
}
|
|
16272
16445
|
throw new Error("Token balance queries not yet implemented for non-BTC assets");
|
|
16273
16446
|
}
|
|
16447
|
+
/**
|
|
16448
|
+
* Get the user's own wallet balance of a token on Bitcoin, in satoshis. Only native BTC is
|
|
16449
|
+
* readable (summed from confirmed/unconfirmed UTXOs). Non-native spoke tokens are Rune ids
|
|
16450
|
+
* (`block:tx`), whose amounts the Esplora UTXO endpoint does not carry, so they resolve to 0n.
|
|
16451
|
+
* @param {GetBalanceParams<BitcoinChainKey>} params - The chain key, user address, and token.
|
|
16452
|
+
* @returns {Promise<bigint>} The balance in satoshis.
|
|
16453
|
+
*/
|
|
16454
|
+
async getWalletBalance(params) {
|
|
16455
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
16456
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
16457
|
+
const utxos = await this.fetchUTXOs(srcAddress);
|
|
16458
|
+
return BigInt(utxos.reduce((sum, utxo) => sum + utxo.value, 0));
|
|
16459
|
+
}
|
|
16460
|
+
return 0n;
|
|
16461
|
+
}
|
|
16462
|
+
/**
|
|
16463
|
+
* Get the user's own wallet balances of multiple tokens on Bitcoin, in satoshis.
|
|
16464
|
+
* @param {GetBalancesParams<BitcoinChainKey>} params - The chain key, user address, and tokens.
|
|
16465
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
16466
|
+
*/
|
|
16467
|
+
async getWalletBalances(params) {
|
|
16468
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
16469
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
16470
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
16471
|
+
return collector.finish();
|
|
16472
|
+
}
|
|
16274
16473
|
async fetchScriptPubKey(utxo) {
|
|
16275
16474
|
const txHex = await this.fetchRawTransaction(utxo.txid);
|
|
16276
16475
|
const tx = Transaction.fromHex(txHex);
|
|
@@ -22817,6 +23016,39 @@ var NearSpokeService = class {
|
|
|
22817
23016
|
}
|
|
22818
23017
|
return BigInt(bal);
|
|
22819
23018
|
}
|
|
23019
|
+
/**
|
|
23020
|
+
* Get the user's own wallet balance of a token on NEAR, in smallest units (yoctoNEAR for the
|
|
23021
|
+
* native coin). Native NEAR via the account's `viewAccount().amount`; NEP-141 tokens via the
|
|
23022
|
+
* token contract's `ft_balance_of` view. Reads the balance held by `srcAddress` (the user
|
|
23023
|
+
* wallet), not the protocol asset manager. Uses this service's own configured RPC provider.
|
|
23024
|
+
* @param {GetBalanceParams<NearChainKey>} params - The chain key, user address, and token.
|
|
23025
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
23026
|
+
*/
|
|
23027
|
+
async getWalletBalance(params) {
|
|
23028
|
+
if (isNativeToken(params.srcChainKey, params.token)) {
|
|
23029
|
+
const account = await this.rpcProvider.viewAccount({ accountId: params.srcAddress });
|
|
23030
|
+
return BigInt(account.amount);
|
|
23031
|
+
}
|
|
23032
|
+
const bal = await this.queryContract(params.token.address, "ft_balance_of", {
|
|
23033
|
+
account_id: params.srcAddress
|
|
23034
|
+
});
|
|
23035
|
+
if (typeof bal !== "string") {
|
|
23036
|
+
throw new Error("[NearSpokeService.getWalletBalance] Failed to get balance. Unexpected response type.");
|
|
23037
|
+
}
|
|
23038
|
+
return BigInt(bal);
|
|
23039
|
+
}
|
|
23040
|
+
/**
|
|
23041
|
+
* Get the user's own wallet balances of multiple tokens on NEAR, in smallest units. Fans out
|
|
23042
|
+
* over {@link getWalletBalance}, keyed by `token.address`.
|
|
23043
|
+
* @param {GetBalancesParams<NearChainKey>} params - The chain key, user address, and tokens.
|
|
23044
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
23045
|
+
*/
|
|
23046
|
+
async getWalletBalances(params) {
|
|
23047
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
23048
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
23049
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
23050
|
+
return collector.finish();
|
|
23051
|
+
}
|
|
22820
23052
|
/**
|
|
22821
23053
|
* Whether `accountId` is storage-registered on a NEP-141 `token` contract. NEP-141 requires an
|
|
22822
23054
|
* account to pay a one-time storage bond before it can receive (hold a balance of) the token, so
|
|
@@ -23676,6 +23908,76 @@ var SonicSpokeService = class {
|
|
|
23676
23908
|
args: [params.token]
|
|
23677
23909
|
});
|
|
23678
23910
|
}
|
|
23911
|
+
/**
|
|
23912
|
+
* Get the user's own wallet balance of a token on the hub (Sonic) chain, in smallest units.
|
|
23913
|
+
* Native coin via `eth_getBalance`; erc20 via `balanceOf`.
|
|
23914
|
+
* @param {GetBalanceParams<SonicChainKey>} params - The chain key, user address, and token.
|
|
23915
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
23916
|
+
*/
|
|
23917
|
+
async getWalletBalance(params) {
|
|
23918
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
23919
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
23920
|
+
return this.publicClient.getBalance({ address: srcAddress });
|
|
23921
|
+
}
|
|
23922
|
+
const balance = await this.publicClient.readContract({
|
|
23923
|
+
address: token.address,
|
|
23924
|
+
abi: erc20Abi$1,
|
|
23925
|
+
functionName: "balanceOf",
|
|
23926
|
+
args: [srcAddress]
|
|
23927
|
+
});
|
|
23928
|
+
return balance ?? 0n;
|
|
23929
|
+
}
|
|
23930
|
+
/**
|
|
23931
|
+
* Get the user's own wallet balances of multiple tokens on the hub (Sonic) chain, in smallest
|
|
23932
|
+
* units. Non-native tokens are batched via multicall3 when the chain supports it, otherwise
|
|
23933
|
+
* read in parallel.
|
|
23934
|
+
* @param {GetBalancesParams<SonicChainKey>} params - The chain key, user address, and tokens.
|
|
23935
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
23936
|
+
*/
|
|
23937
|
+
async getWalletBalances(params) {
|
|
23938
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
23939
|
+
const nativeTokens = tokens.filter((token) => isNativeToken(srcChainKey, token));
|
|
23940
|
+
const nonNativeTokens = tokens.filter((token) => !isNativeToken(srcChainKey, token));
|
|
23941
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
23942
|
+
await settleWalletBalances(
|
|
23943
|
+
collector,
|
|
23944
|
+
nativeTokens,
|
|
23945
|
+
(token) => this.getWalletBalance({ srcChainKey, srcAddress, token })
|
|
23946
|
+
);
|
|
23947
|
+
if (nonNativeTokens.length === 0) {
|
|
23948
|
+
return collector.finish();
|
|
23949
|
+
}
|
|
23950
|
+
if (getEvmViemChain(srcChainKey).contracts?.multicall3) {
|
|
23951
|
+
const results = await this.publicClient.multicall({
|
|
23952
|
+
contracts: nonNativeTokens.map((token) => ({
|
|
23953
|
+
abi: erc20Abi$1,
|
|
23954
|
+
address: token.address,
|
|
23955
|
+
functionName: "balanceOf",
|
|
23956
|
+
args: [srcAddress]
|
|
23957
|
+
}))
|
|
23958
|
+
});
|
|
23959
|
+
nonNativeTokens.forEach((token, index) => {
|
|
23960
|
+
const result = results[index];
|
|
23961
|
+
if (result?.status === "success") {
|
|
23962
|
+
collector.ok(token.address, BigInt(result.result));
|
|
23963
|
+
} else {
|
|
23964
|
+
collector.fail(token.address, result?.error ?? new Error(`missing multicall result for ${token.address}`));
|
|
23965
|
+
}
|
|
23966
|
+
});
|
|
23967
|
+
return collector.finish();
|
|
23968
|
+
}
|
|
23969
|
+
await settleWalletBalances(
|
|
23970
|
+
collector,
|
|
23971
|
+
nonNativeTokens,
|
|
23972
|
+
(token) => this.publicClient.readContract({
|
|
23973
|
+
address: token.address,
|
|
23974
|
+
abi: erc20Abi$1,
|
|
23975
|
+
functionName: "balanceOf",
|
|
23976
|
+
args: [srcAddress]
|
|
23977
|
+
})
|
|
23978
|
+
);
|
|
23979
|
+
return collector.finish();
|
|
23980
|
+
}
|
|
23679
23981
|
/**
|
|
23680
23982
|
* Execute a batch of contract calls through the Sonic wallet contract.
|
|
23681
23983
|
* @param {Hex} payload - The encoded payload containing the calls array
|
|
@@ -23774,8 +24076,8 @@ var SuiGrpcTransport = class {
|
|
|
23774
24076
|
this.endpoint = endpoint;
|
|
23775
24077
|
this.client = new SuiGrpcClient({ network: "mainnet", baseUrl: endpoint });
|
|
23776
24078
|
}
|
|
23777
|
-
async getCoins(owner, coinType, limit = DEFAULT_GET_COINS_LIMIT) {
|
|
23778
|
-
const response = await this.client.core.listCoins({ owner, coinType, limit });
|
|
24079
|
+
async getCoins(owner, coinType, limit = DEFAULT_GET_COINS_LIMIT, cursor) {
|
|
24080
|
+
const response = await this.client.core.listCoins({ owner, coinType, limit, cursor: cursor ?? void 0 });
|
|
23779
24081
|
return toSuiPaginatedCoins(response, coinType);
|
|
23780
24082
|
}
|
|
23781
24083
|
async simulate(tx, sender) {
|
|
@@ -24015,6 +24317,42 @@ var SuiSpokeService = class {
|
|
|
24015
24317
|
const str_u64 = bcs.U64.parse(Uint8Array.from(val));
|
|
24016
24318
|
return BigInt(str_u64);
|
|
24017
24319
|
}
|
|
24320
|
+
/**
|
|
24321
|
+
* Get the user's own wallet balance of a token on Sui, in smallest units. Unlike {@link getDeposit}
|
|
24322
|
+
* (which reads the protocol asset manager holding), this reads the balance held by `params.srcAddress`
|
|
24323
|
+
* itself. Native SUI is read via its canonical `0x2::sui::SUI` coin type; other coins use the token's
|
|
24324
|
+
* Sui coinType (`token.address`).
|
|
24325
|
+
* @param {GetBalanceParams<SuiChainKey>} params - The chain key, user address, and token.
|
|
24326
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
24327
|
+
*/
|
|
24328
|
+
async getWalletBalance(params) {
|
|
24329
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
24330
|
+
let coinType = isNativeToken(srcChainKey, token) ? "0x2::sui::SUI" : token.address;
|
|
24331
|
+
if (coinType === "0x03917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR") {
|
|
24332
|
+
coinType = "0x3917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR";
|
|
24333
|
+
}
|
|
24334
|
+
let total = 0n;
|
|
24335
|
+
let cursor;
|
|
24336
|
+
do {
|
|
24337
|
+
const page = await this.transport.getCoins(srcAddress, coinType, void 0, cursor);
|
|
24338
|
+
for (const coin of page.data) {
|
|
24339
|
+
total += BigInt(coin.balance);
|
|
24340
|
+
}
|
|
24341
|
+
cursor = page.hasNextPage ? page.nextCursor : void 0;
|
|
24342
|
+
} while (cursor);
|
|
24343
|
+
return total;
|
|
24344
|
+
}
|
|
24345
|
+
/**
|
|
24346
|
+
* Get the user's own wallet balances of multiple tokens on Sui, in smallest units.
|
|
24347
|
+
* @param {GetBalancesParams<SuiChainKey>} params - The chain key, user address, and tokens.
|
|
24348
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
24349
|
+
*/
|
|
24350
|
+
async getWalletBalances(params) {
|
|
24351
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
24352
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
24353
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
24354
|
+
return collector.finish();
|
|
24355
|
+
}
|
|
24018
24356
|
/**
|
|
24019
24357
|
* Fetch the asset manager config from the spoke chain.
|
|
24020
24358
|
* @param {SuiChainKey} chainId - The Sui chain key.
|
|
@@ -24161,6 +24499,11 @@ var CustomSorobanServer = class extends rpc.Server {
|
|
|
24161
24499
|
return response.json().then((json) => json.result);
|
|
24162
24500
|
}
|
|
24163
24501
|
};
|
|
24502
|
+
var STELLAR_BASE_RESERVE_STROOPS = 5000000n;
|
|
24503
|
+
function parseXlmBalanceToStroops(balanceStr) {
|
|
24504
|
+
const [whole = "0", frac = ""] = balanceStr.split(".");
|
|
24505
|
+
return BigInt(whole + frac.padEnd(7, "0").slice(0, 7));
|
|
24506
|
+
}
|
|
24164
24507
|
var CustomStellarAccount = class {
|
|
24165
24508
|
accountId;
|
|
24166
24509
|
sequenceNumber;
|
|
@@ -24199,7 +24542,7 @@ var CustomStellarAccount = class {
|
|
|
24199
24542
|
}
|
|
24200
24543
|
};
|
|
24201
24544
|
var TRUSTLINE_TX_TIMEOUT_SECONDS = 300;
|
|
24202
|
-
var StellarSpokeService = class {
|
|
24545
|
+
var StellarSpokeService = class _StellarSpokeService {
|
|
24203
24546
|
config;
|
|
24204
24547
|
chainConfig;
|
|
24205
24548
|
server;
|
|
@@ -24240,6 +24583,109 @@ var StellarSpokeService = class {
|
|
|
24240
24583
|
}
|
|
24241
24584
|
throw new Error("result undefined");
|
|
24242
24585
|
}
|
|
24586
|
+
/**
|
|
24587
|
+
* Get the user's own wallet balance of a token on Stellar, in smallest units. Native XLM returns
|
|
24588
|
+
* the spendable amount (total minus the minimum reserve and selling liabilities) via Horizon;
|
|
24589
|
+
* other assets return the Soroban token contract's `balance` for the user.
|
|
24590
|
+
* @param {GetBalanceParams<StellarChainKey>} params - The chain key, user address, and token.
|
|
24591
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
24592
|
+
*/
|
|
24593
|
+
async getWalletBalance(params) {
|
|
24594
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
24595
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
24596
|
+
return _StellarSpokeService.spendableXlmStroops(await this.server.loadAccount(srcAddress));
|
|
24597
|
+
}
|
|
24598
|
+
const [network, sourceAccount] = await Promise.all([
|
|
24599
|
+
this.sorobanServer.getNetwork(),
|
|
24600
|
+
this.sorobanServer.getAccount(srcAddress)
|
|
24601
|
+
]);
|
|
24602
|
+
return this.simulateTokenBalance(
|
|
24603
|
+
token.address,
|
|
24604
|
+
srcAddress,
|
|
24605
|
+
new CustomStellarAccount({ account_id: sourceAccount.accountId(), sequence: sourceAccount.sequenceNumber() }),
|
|
24606
|
+
network.passphrase
|
|
24607
|
+
);
|
|
24608
|
+
}
|
|
24609
|
+
/**
|
|
24610
|
+
* Spendable XLM in stroops: the account's native balance minus its minimum reserve and selling
|
|
24611
|
+
* liabilities. Reporting the raw balance would let a user try to spend reserves the network
|
|
24612
|
+
* refuses to release.
|
|
24613
|
+
*/
|
|
24614
|
+
static spendableXlmStroops(account) {
|
|
24615
|
+
const nativeBalance = account.balances.find(
|
|
24616
|
+
(balance) => balance.asset_type === "native"
|
|
24617
|
+
);
|
|
24618
|
+
if (!nativeBalance) {
|
|
24619
|
+
return 0n;
|
|
24620
|
+
}
|
|
24621
|
+
const rawStroops = parseXlmBalanceToStroops(nativeBalance.balance);
|
|
24622
|
+
const sellingLiabilitiesStroops = nativeBalance.selling_liabilities ? parseXlmBalanceToStroops(nativeBalance.selling_liabilities) : 0n;
|
|
24623
|
+
const reserveCount = Math.max(0, 2 + account.subentry_count + account.num_sponsoring - account.num_sponsored);
|
|
24624
|
+
const minStroops = BigInt(reserveCount) * STELLAR_BASE_RESERVE_STROOPS + sellingLiabilitiesStroops;
|
|
24625
|
+
return rawStroops > minStroops ? rawStroops - minStroops : 0n;
|
|
24626
|
+
}
|
|
24627
|
+
/**
|
|
24628
|
+
* Simulate a Soroban token `balance` call. Takes the network passphrase and source account so a
|
|
24629
|
+
* batch can fetch them once; `getAccountClone()` hands each builder its own `Account`, because
|
|
24630
|
+
* `TransactionBuilder.build()` increments the source's sequence number and concurrent builders
|
|
24631
|
+
* would otherwise interleave on a shared one.
|
|
24632
|
+
*/
|
|
24633
|
+
async simulateTokenBalance(tokenAddress, srcAddress, account, networkPassphrase) {
|
|
24634
|
+
const contract = new Contract(tokenAddress);
|
|
24635
|
+
const tx = new TransactionBuilder(account.getAccountClone(), { fee: this.baseFee, networkPassphrase }).addOperation(contract.call("balance", nativeToScVal(srcAddress, { type: "address" }))).setTimeout(TimeoutInfinite).build();
|
|
24636
|
+
const result = await this.sorobanServer.simulateTransaction(tx);
|
|
24637
|
+
if (!rpc.Api.isSimulationSuccess(result)) {
|
|
24638
|
+
throw new Error("Failed to simulate transaction");
|
|
24639
|
+
}
|
|
24640
|
+
if (!result.result) {
|
|
24641
|
+
throw new Error("Failed to read token balance: simulation returned no result");
|
|
24642
|
+
}
|
|
24643
|
+
return scValToBigInt(result.result.retval);
|
|
24644
|
+
}
|
|
24645
|
+
/**
|
|
24646
|
+
* Get the user's own wallet balances of multiple tokens on Stellar, in smallest units.
|
|
24647
|
+
*
|
|
24648
|
+
* The network passphrase and the source account are the same for every token, so they are
|
|
24649
|
+
* fetched once per batch instead of once per token — and only when a partition actually needs
|
|
24650
|
+
* them, so an all-native request issues no Soroban calls at all.
|
|
24651
|
+
* @param {GetBalancesParams<StellarChainKey>} params - The chain key, user address, and tokens.
|
|
24652
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
24653
|
+
*/
|
|
24654
|
+
async getWalletBalances(params) {
|
|
24655
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
24656
|
+
const nativeTokens = tokens.filter((token) => isNativeToken(srcChainKey, token));
|
|
24657
|
+
const sorobanTokens = tokens.filter((token) => !isNativeToken(srcChainKey, token));
|
|
24658
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
24659
|
+
if (nativeTokens.length > 0) {
|
|
24660
|
+
try {
|
|
24661
|
+
const spendable = _StellarSpokeService.spendableXlmStroops(await this.server.loadAccount(srcAddress));
|
|
24662
|
+
for (const token of nativeTokens) {
|
|
24663
|
+
collector.ok(token.address, spendable);
|
|
24664
|
+
}
|
|
24665
|
+
} catch (error) {
|
|
24666
|
+
for (const token of nativeTokens) {
|
|
24667
|
+
collector.fail(token.address, error);
|
|
24668
|
+
}
|
|
24669
|
+
}
|
|
24670
|
+
}
|
|
24671
|
+
if (sorobanTokens.length === 0) {
|
|
24672
|
+
return collector.finish();
|
|
24673
|
+
}
|
|
24674
|
+
const [network, sourceAccount] = await Promise.all([
|
|
24675
|
+
this.sorobanServer.getNetwork(),
|
|
24676
|
+
this.sorobanServer.getAccount(srcAddress)
|
|
24677
|
+
]);
|
|
24678
|
+
const account = new CustomStellarAccount({
|
|
24679
|
+
account_id: sourceAccount.accountId(),
|
|
24680
|
+
sequence: sourceAccount.sequenceNumber()
|
|
24681
|
+
});
|
|
24682
|
+
await settleWalletBalances(
|
|
24683
|
+
collector,
|
|
24684
|
+
sorobanTokens,
|
|
24685
|
+
(token) => this.simulateTokenBalance(token.address, srcAddress, account, network.passphrase)
|
|
24686
|
+
);
|
|
24687
|
+
return collector.finish();
|
|
24688
|
+
}
|
|
24243
24689
|
async buildPriorityStellarTransaction(account, network, operation) {
|
|
24244
24690
|
const simulationForFee = await this.sorobanServer.simulateTransaction(
|
|
24245
24691
|
new TransactionBuilder(account.getAccountClone(), {
|
|
@@ -24813,6 +25259,48 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
24813
25259
|
const tokenAccount = await _SolanaSpokeService.getTokenAccountBalance(this.connection, vaultToken.pda.toBase58());
|
|
24814
25260
|
return BigInt(tokenAccount.value.amount);
|
|
24815
25261
|
}
|
|
25262
|
+
/**
|
|
25263
|
+
* Get the user's own wallet balance of a token on Solana, in smallest units. Native SOL via
|
|
25264
|
+
* `getBalance`; SPL via the associated token account. The mint may belong to the legacy SPL
|
|
25265
|
+
* Token program or Token-2022 (e.g. xStock tokens), which derive different ATAs, so both
|
|
25266
|
+
* candidate ATAs are read in one call and the existing one is used.
|
|
25267
|
+
* @param {GetBalanceParams<SolanaChainKey>} params - The chain key, user address, and token.
|
|
25268
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
25269
|
+
*/
|
|
25270
|
+
async getWalletBalance(params) {
|
|
25271
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
25272
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
25273
|
+
return BigInt(await _SolanaSpokeService.getBalance(this.connection, srcAddress));
|
|
25274
|
+
}
|
|
25275
|
+
const owner = new PublicKey(srcAddress);
|
|
25276
|
+
const mint = new PublicKey(token.address);
|
|
25277
|
+
const candidates = [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID].map((programId) => ({
|
|
25278
|
+
programId,
|
|
25279
|
+
ata: getAssociatedTokenAddressSync(mint, owner, true, programId)
|
|
25280
|
+
}));
|
|
25281
|
+
const accounts = await this.connection.getMultipleAccountsInfo(candidates.map((c) => c.ata));
|
|
25282
|
+
let balance = 0n;
|
|
25283
|
+
for (const [i, candidate] of candidates.entries()) {
|
|
25284
|
+
const info = accounts[i];
|
|
25285
|
+
if (!info) continue;
|
|
25286
|
+
try {
|
|
25287
|
+
balance += unpackAccount(candidate.ata, info, candidate.programId).amount;
|
|
25288
|
+
} catch {
|
|
25289
|
+
}
|
|
25290
|
+
}
|
|
25291
|
+
return balance;
|
|
25292
|
+
}
|
|
25293
|
+
/**
|
|
25294
|
+
* Get the user's own wallet balances of multiple tokens on Solana, in smallest units.
|
|
25295
|
+
* @param {GetBalancesParams<SolanaChainKey>} params - The chain key, user address, and tokens.
|
|
25296
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
25297
|
+
*/
|
|
25298
|
+
async getWalletBalances(params) {
|
|
25299
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
25300
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
25301
|
+
await settleWalletBalances(collector, tokens, (token) => this.getWalletBalance({ srcChainKey, srcAddress, token }));
|
|
25302
|
+
return collector.finish();
|
|
25303
|
+
}
|
|
24816
25304
|
/**
|
|
24817
25305
|
* Sends a message to the hub chain.
|
|
24818
25306
|
* @param dstChainKey - The chain key of the hub chain.
|
|
@@ -25034,8 +25522,84 @@ var IconSpokeService = class {
|
|
|
25034
25522
|
async getDeposit(params) {
|
|
25035
25523
|
const { token, srcChainKey } = params;
|
|
25036
25524
|
const transaction = new CallBuilder().to(token).method("balanceOf").params({ _owner: this.config.getChainConfig(srcChainKey).addresses.assetManager }).build();
|
|
25525
|
+
return this.readIrc2Balance(transaction);
|
|
25526
|
+
}
|
|
25527
|
+
/**
|
|
25528
|
+
* Read an int-returning SCORE call. `iconService.call(...)` registers no result converter, so
|
|
25529
|
+
* `execute()` resolves the raw JSON-RPC `result` — a bare hex string for an int, not `{ value }`.
|
|
25530
|
+
*/
|
|
25531
|
+
async readIrc2Balance(transaction) {
|
|
25037
25532
|
const result = await this.iconService.call(transaction).execute();
|
|
25038
|
-
|
|
25533
|
+
if (typeof result !== "string") {
|
|
25534
|
+
throw new Error(`[IconSpokeService] Unexpected balanceOf response: ${JSON.stringify(result)}`);
|
|
25535
|
+
}
|
|
25536
|
+
return hexToBigInt(result);
|
|
25537
|
+
}
|
|
25538
|
+
/**
|
|
25539
|
+
* Get the user's own wallet balance of a token on ICON, in smallest units. Native ICX is read
|
|
25540
|
+
* via `iconService.getBalance`; IRC-2 tokens via a `balanceOf(_owner)` call on the token contract.
|
|
25541
|
+
* @param {GetBalanceParams<IconChainKey>} params - The chain key, user address, and token.
|
|
25542
|
+
* @returns {Promise<bigint>} The token balance in smallest units.
|
|
25543
|
+
*/
|
|
25544
|
+
async getWalletBalance(params) {
|
|
25545
|
+
const { srcChainKey, srcAddress, token } = params;
|
|
25546
|
+
if (isNativeToken(srcChainKey, token)) {
|
|
25547
|
+
const balance = await this.iconService.getBalance(srcAddress).execute();
|
|
25548
|
+
return BigInt(balance.toFixed());
|
|
25549
|
+
}
|
|
25550
|
+
const transaction = new CallBuilder().to(token.address).method("balanceOf").params({ _owner: srcAddress }).build();
|
|
25551
|
+
return this.readIrc2Balance(transaction);
|
|
25552
|
+
}
|
|
25553
|
+
/**
|
|
25554
|
+
* Get the user's own wallet balances of multiple tokens on ICON, in smallest units. Native ICX
|
|
25555
|
+
* is read via `iconService.getBalance`; IRC-2 balances are batched into a single `tryAggregate`
|
|
25556
|
+
* multicall so every `balanceOf(_owner)` read shares one round-trip.
|
|
25557
|
+
* @param {GetBalancesParams<IconChainKey>} params - The chain key, user address, and tokens.
|
|
25558
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
25559
|
+
*/
|
|
25560
|
+
async getWalletBalances(params) {
|
|
25561
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
25562
|
+
const nativeTokens = tokens.filter((token) => isNativeToken(srcChainKey, token));
|
|
25563
|
+
const nonNativeTokens = tokens.filter((token) => !isNativeToken(srcChainKey, token));
|
|
25564
|
+
const collector = createBalanceCollector({ logger: this.config.logger, chainKey: srcChainKey });
|
|
25565
|
+
if (nativeTokens.length > 0) {
|
|
25566
|
+
try {
|
|
25567
|
+
const balance = await this.iconService.getBalance(srcAddress).execute();
|
|
25568
|
+
for (const token of nativeTokens) {
|
|
25569
|
+
collector.ok(token.address, BigInt(balance.toFixed()));
|
|
25570
|
+
}
|
|
25571
|
+
} catch (error) {
|
|
25572
|
+
for (const token of nativeTokens) {
|
|
25573
|
+
collector.fail(token.address, error);
|
|
25574
|
+
}
|
|
25575
|
+
}
|
|
25576
|
+
}
|
|
25577
|
+
if (nonNativeTokens.length === 0) {
|
|
25578
|
+
return collector.finish();
|
|
25579
|
+
}
|
|
25580
|
+
const multicallAddress = "cxa4aa9185e23558cff990f494c1fd2845f6cbf741";
|
|
25581
|
+
const calls = nonNativeTokens.map((token) => ({
|
|
25582
|
+
target: token.address,
|
|
25583
|
+
method: "balanceOf",
|
|
25584
|
+
params: [srcAddress]
|
|
25585
|
+
}));
|
|
25586
|
+
const transaction = new CallBuilder().to(multicallAddress).method("tryAggregate").params({ requireSuccess: Converter.toHex(0), calls }).build();
|
|
25587
|
+
const result = await this.iconService.call(transaction).execute();
|
|
25588
|
+
const aggregated = result.returnData;
|
|
25589
|
+
if (!Array.isArray(aggregated) || aggregated.length !== nonNativeTokens.length) {
|
|
25590
|
+
throw new Error(
|
|
25591
|
+
`[IconSpokeService] tryAggregate returned ${Array.isArray(aggregated) ? aggregated.length : "no"} entries for ${nonNativeTokens.length} tokens`
|
|
25592
|
+
);
|
|
25593
|
+
}
|
|
25594
|
+
nonNativeTokens.forEach((token, index) => {
|
|
25595
|
+
const agg = aggregated[index];
|
|
25596
|
+
if (agg && agg.success !== "0x0" && typeof agg.returnData === "string") {
|
|
25597
|
+
collector.ok(token.address, hexToBigInt(agg.returnData));
|
|
25598
|
+
} else {
|
|
25599
|
+
collector.fail(token.address, new Error(`balanceOf failed for ${token.address}: ${agg?.returnData}`));
|
|
25600
|
+
}
|
|
25601
|
+
});
|
|
25602
|
+
return collector.finish();
|
|
25039
25603
|
}
|
|
25040
25604
|
/**
|
|
25041
25605
|
* Sends a message to the hub chain.
|
|
@@ -25101,6 +25665,7 @@ var GAS_PRICE_REGEX = /^(\d+)(.*)$/;
|
|
|
25101
25665
|
var InjectiveSpokeService = class {
|
|
25102
25666
|
config;
|
|
25103
25667
|
chainGrpcWasmApi;
|
|
25668
|
+
indexerGrpcAccountPortfolioApi;
|
|
25104
25669
|
txClient;
|
|
25105
25670
|
endpoints;
|
|
25106
25671
|
pollingIntervalMs;
|
|
@@ -25110,6 +25675,7 @@ var InjectiveSpokeService = class {
|
|
|
25110
25675
|
this.config = config;
|
|
25111
25676
|
this.endpoints = getNetworkEndpoints(Network.Mainnet);
|
|
25112
25677
|
this.chainGrpcWasmApi = new ChainGrpcWasmApi(this.endpoints.grpc);
|
|
25678
|
+
this.indexerGrpcAccountPortfolioApi = new IndexerGrpcAccountPortfolioApi(this.endpoints.indexer);
|
|
25113
25679
|
this.txClient = new TxGrpcApi(this.endpoints.grpc);
|
|
25114
25680
|
this.pollingIntervalMs = this.config.sodaxConfig.chains[ChainKeys.INJECTIVE_MAINNET].pollingConfig.pollingIntervalMs;
|
|
25115
25681
|
this.maxTimeoutMs = this.config.sodaxConfig.chains[ChainKeys.INJECTIVE_MAINNET].pollingConfig.maxTimeoutMs;
|
|
@@ -25193,6 +25759,37 @@ var InjectiveSpokeService = class {
|
|
|
25193
25759
|
);
|
|
25194
25760
|
return BigInt(fromBase64(response.data));
|
|
25195
25761
|
}
|
|
25762
|
+
/**
|
|
25763
|
+
* Get the user's own wallet balance of a token on Injective, in smallest units. On Injective every
|
|
25764
|
+
* asset is a bank coin, so the native coin (`inj`) and factory/peggy/IBC tokens are all read from the
|
|
25765
|
+
* account's portfolio bank balances and matched by denom. The denom is the chain's native denom for
|
|
25766
|
+
* the native coin and `params.token.address` for standard tokens.
|
|
25767
|
+
* @param {GetBalanceParams<InjectiveChainKey>} params - The chain key, user address, and token.
|
|
25768
|
+
* @returns {Promise<bigint>} The token balance in smallest units, or 0n when the account holds none.
|
|
25769
|
+
*/
|
|
25770
|
+
async getWalletBalance(params) {
|
|
25771
|
+
const denom = isNativeToken(params.srcChainKey, params.token) ? this.config.getChainConfig(params.srcChainKey).nativeToken : params.token.address;
|
|
25772
|
+
const portfolio = await this.indexerGrpcAccountPortfolioApi.fetchAccountPortfolioBalances(params.srcAddress);
|
|
25773
|
+
const balance = portfolio.bankBalancesList.find((_balance) => _balance.denom === denom);
|
|
25774
|
+
return balance ? BigInt(balance.amount) : 0n;
|
|
25775
|
+
}
|
|
25776
|
+
/**
|
|
25777
|
+
* Get the user's own wallet balances of multiple tokens on Injective, in smallest units.
|
|
25778
|
+
* @param {GetBalancesParams<InjectiveChainKey>} params - The chain key, user address, and tokens.
|
|
25779
|
+
* @returns {Promise<WalletBalanceMap>} A map of token address to balance in smallest units.
|
|
25780
|
+
*/
|
|
25781
|
+
async getWalletBalances(params) {
|
|
25782
|
+
const { srcChainKey, srcAddress, tokens } = params;
|
|
25783
|
+
const portfolio = await this.indexerGrpcAccountPortfolioApi.fetchAccountPortfolioBalances(srcAddress);
|
|
25784
|
+
const amountByDenom = new Map(portfolio.bankBalancesList.map((balance) => [balance.denom, BigInt(balance.amount)]));
|
|
25785
|
+
const nativeDenom = this.config.getChainConfig(srcChainKey).nativeToken;
|
|
25786
|
+
const balances = {};
|
|
25787
|
+
for (const token of tokens) {
|
|
25788
|
+
const denom = isNativeToken(srcChainKey, token) ? nativeDenom : token.address;
|
|
25789
|
+
balances[token.address] = amountByDenom.get(denom) ?? 0n;
|
|
25790
|
+
}
|
|
25791
|
+
return balances;
|
|
25792
|
+
}
|
|
25196
25793
|
async getRawTransaction(chainId, senderAddress, contractAddress, msg, memo, funds = []) {
|
|
25197
25794
|
const msgExec = MsgExecuteContract.fromJSON({
|
|
25198
25795
|
contractAddress,
|
|
@@ -26000,6 +26597,138 @@ var SpokeService = class _SpokeService {
|
|
|
26000
26597
|
return { ok: false, error };
|
|
26001
26598
|
}
|
|
26002
26599
|
}
|
|
26600
|
+
/**
|
|
26601
|
+
* Get a user's own wallet balance of a single token on a spoke chain, in smallest units.
|
|
26602
|
+
* Chain-agnostic: dispatches to the per-chain service, which reads the native coin or the
|
|
26603
|
+
* chain's token standard (EVM erc20, Solana SPL, …). Unlike {@link getDeposit}, this reads
|
|
26604
|
+
* `srcAddress` itself, not the protocol asset manager.
|
|
26605
|
+
* @param {GetBalanceParams<C>} params - The chain key, user address, and token.
|
|
26606
|
+
* @returns {Promise<Result<bigint>>} The token balance in smallest units.
|
|
26607
|
+
*/
|
|
26608
|
+
async getWalletBalance(params) {
|
|
26609
|
+
try {
|
|
26610
|
+
if (isHubChainKeyType(params.srcChainKey)) {
|
|
26611
|
+
const value = await this.sonic.getWalletBalance(params);
|
|
26612
|
+
return { ok: true, value };
|
|
26613
|
+
}
|
|
26614
|
+
const chainType = getChainType(params.srcChainKey);
|
|
26615
|
+
switch (chainType) {
|
|
26616
|
+
case "EVM": {
|
|
26617
|
+
const value = await this.evm.getWalletBalance(params);
|
|
26618
|
+
return { ok: true, value };
|
|
26619
|
+
}
|
|
26620
|
+
case "INJECTIVE": {
|
|
26621
|
+
const value = await this.injective.getWalletBalance(params);
|
|
26622
|
+
return { ok: true, value };
|
|
26623
|
+
}
|
|
26624
|
+
case "STELLAR": {
|
|
26625
|
+
const value = await this.stellar.getWalletBalance(params);
|
|
26626
|
+
return { ok: true, value };
|
|
26627
|
+
}
|
|
26628
|
+
case "SUI": {
|
|
26629
|
+
const value = await this.sui.getWalletBalance(params);
|
|
26630
|
+
return { ok: true, value };
|
|
26631
|
+
}
|
|
26632
|
+
case "ICON": {
|
|
26633
|
+
const value = await this.icon.getWalletBalance(params);
|
|
26634
|
+
return { ok: true, value };
|
|
26635
|
+
}
|
|
26636
|
+
case "SOLANA": {
|
|
26637
|
+
const value = await this.solana.getWalletBalance(params);
|
|
26638
|
+
return { ok: true, value };
|
|
26639
|
+
}
|
|
26640
|
+
case "STACKS": {
|
|
26641
|
+
const value = await this.stacks.getWalletBalance(params);
|
|
26642
|
+
return { ok: true, value };
|
|
26643
|
+
}
|
|
26644
|
+
case "BITCOIN": {
|
|
26645
|
+
const value = await this.bitcoin.getWalletBalance(params);
|
|
26646
|
+
return { ok: true, value };
|
|
26647
|
+
}
|
|
26648
|
+
case "NEAR": {
|
|
26649
|
+
const value = await this.near.getWalletBalance(params);
|
|
26650
|
+
return { ok: true, value };
|
|
26651
|
+
}
|
|
26652
|
+
default: {
|
|
26653
|
+
const exhaustiveCheck = chainType;
|
|
26654
|
+
this.config.logger.debug("Unhandled exhaustive case", { value: exhaustiveCheck });
|
|
26655
|
+
return {
|
|
26656
|
+
ok: false,
|
|
26657
|
+
error: new Error(`[getWalletBalance] Invalid chain type. Valid chain types: ${ChainTypeArr.join(", ")}`)
|
|
26658
|
+
};
|
|
26659
|
+
}
|
|
26660
|
+
}
|
|
26661
|
+
} catch (error) {
|
|
26662
|
+
return { ok: false, error };
|
|
26663
|
+
}
|
|
26664
|
+
}
|
|
26665
|
+
/**
|
|
26666
|
+
* Get a user's own wallet balances of multiple tokens on a spoke chain, in smallest units.
|
|
26667
|
+
* Chain-agnostic sibling of {@link getWalletBalance}; per-chain services batch the reads where the
|
|
26668
|
+
* chain supports it (e.g. EVM multicall3, ICON aggregated call data).
|
|
26669
|
+
* @param {GetBalancesParams<C>} params - The chain key, user address, and tokens.
|
|
26670
|
+
* @returns {Promise<Result<WalletBalanceMap>>} A map of token address to balance in smallest
|
|
26671
|
+
* units. A token that could not be read is logged and reported as `0n`; the `Result` fails when
|
|
26672
|
+
* the whole batch is unusable — invalid chain, a shared round-trip every token depends on, or a
|
|
26673
|
+
* batch in which no token could be read at all.
|
|
26674
|
+
*/
|
|
26675
|
+
async getWalletBalances(params) {
|
|
26676
|
+
try {
|
|
26677
|
+
if (isHubChainKeyType(params.srcChainKey)) {
|
|
26678
|
+
const value = await this.sonic.getWalletBalances(params);
|
|
26679
|
+
return { ok: true, value };
|
|
26680
|
+
}
|
|
26681
|
+
const chainType = getChainType(params.srcChainKey);
|
|
26682
|
+
switch (chainType) {
|
|
26683
|
+
case "EVM": {
|
|
26684
|
+
const value = await this.evm.getWalletBalances(params);
|
|
26685
|
+
return { ok: true, value };
|
|
26686
|
+
}
|
|
26687
|
+
case "INJECTIVE": {
|
|
26688
|
+
const value = await this.injective.getWalletBalances(params);
|
|
26689
|
+
return { ok: true, value };
|
|
26690
|
+
}
|
|
26691
|
+
case "STELLAR": {
|
|
26692
|
+
const value = await this.stellar.getWalletBalances(params);
|
|
26693
|
+
return { ok: true, value };
|
|
26694
|
+
}
|
|
26695
|
+
case "SUI": {
|
|
26696
|
+
const value = await this.sui.getWalletBalances(params);
|
|
26697
|
+
return { ok: true, value };
|
|
26698
|
+
}
|
|
26699
|
+
case "ICON": {
|
|
26700
|
+
const value = await this.icon.getWalletBalances(params);
|
|
26701
|
+
return { ok: true, value };
|
|
26702
|
+
}
|
|
26703
|
+
case "SOLANA": {
|
|
26704
|
+
const value = await this.solana.getWalletBalances(params);
|
|
26705
|
+
return { ok: true, value };
|
|
26706
|
+
}
|
|
26707
|
+
case "STACKS": {
|
|
26708
|
+
const value = await this.stacks.getWalletBalances(params);
|
|
26709
|
+
return { ok: true, value };
|
|
26710
|
+
}
|
|
26711
|
+
case "BITCOIN": {
|
|
26712
|
+
const value = await this.bitcoin.getWalletBalances(params);
|
|
26713
|
+
return { ok: true, value };
|
|
26714
|
+
}
|
|
26715
|
+
case "NEAR": {
|
|
26716
|
+
const value = await this.near.getWalletBalances(params);
|
|
26717
|
+
return { ok: true, value };
|
|
26718
|
+
}
|
|
26719
|
+
default: {
|
|
26720
|
+
const exhaustiveCheck = chainType;
|
|
26721
|
+
this.config.logger.debug("Unhandled exhaustive case", { value: exhaustiveCheck });
|
|
26722
|
+
return {
|
|
26723
|
+
ok: false,
|
|
26724
|
+
error: new Error(`[getWalletBalances] Invalid chain type. Valid chain types: ${ChainTypeArr.join(", ")}`)
|
|
26725
|
+
};
|
|
26726
|
+
}
|
|
26727
|
+
}
|
|
26728
|
+
} catch (error) {
|
|
26729
|
+
return { ok: false, error };
|
|
26730
|
+
}
|
|
26731
|
+
}
|
|
26003
26732
|
/**
|
|
26004
26733
|
* Calls the connection contract on the spoke chain to send a message to the hub wallet, which then executes the message's payload.
|
|
26005
26734
|
* @param {HubAddress} from - The address of the user on the hub chain.
|
|
@@ -27296,6 +28025,119 @@ var EvmHubProvider = class {
|
|
|
27296
28025
|
}
|
|
27297
28026
|
};
|
|
27298
28027
|
|
|
28028
|
+
// src/backendApi/api-utils.ts
|
|
28029
|
+
var API_KEY_HEADER = "x-api-key";
|
|
28030
|
+
function apiKeyHeader(apiKey) {
|
|
28031
|
+
return apiKey ? { [API_KEY_HEADER]: apiKey } : {};
|
|
28032
|
+
}
|
|
28033
|
+
function mergeHeaders(...sources) {
|
|
28034
|
+
const byName = /* @__PURE__ */ new Map();
|
|
28035
|
+
for (const source of sources) {
|
|
28036
|
+
for (const entry of Object.entries(source ?? {})) byName.set(entry[0].toLowerCase(), entry);
|
|
28037
|
+
}
|
|
28038
|
+
return Object.fromEntries(byName.values());
|
|
28039
|
+
}
|
|
28040
|
+
function withApiKey(config, apiKey) {
|
|
28041
|
+
return { ...config, headers: mergeHeaders(apiKeyHeader(apiKey), config.headers) };
|
|
28042
|
+
}
|
|
28043
|
+
function assignHeaders(target, source) {
|
|
28044
|
+
const merged = mergeHeaders(target, source);
|
|
28045
|
+
for (const name of Object.keys(target)) delete target[name];
|
|
28046
|
+
Object.assign(target, merged);
|
|
28047
|
+
}
|
|
28048
|
+
var BackendHttpError = class extends Error {
|
|
28049
|
+
status;
|
|
28050
|
+
bodyText;
|
|
28051
|
+
/** Parsed JSON, or `undefined` for empty or malformed bodies. */
|
|
28052
|
+
body;
|
|
28053
|
+
constructor(status, bodyText) {
|
|
28054
|
+
super("HTTP_REQUEST_FAILED", { cause: new Error(`HTTP ${status}: ${bodyText}`) });
|
|
28055
|
+
this.name = "BackendHttpError";
|
|
28056
|
+
this.status = status;
|
|
28057
|
+
this.bodyText = bodyText;
|
|
28058
|
+
this.body = safeJsonParse(bodyText);
|
|
28059
|
+
}
|
|
28060
|
+
};
|
|
28061
|
+
function isBackendHttpError(error) {
|
|
28062
|
+
if (error instanceof BackendHttpError) return true;
|
|
28063
|
+
return error instanceof Error && error.name === "BackendHttpError" && typeof error.status === "number";
|
|
28064
|
+
}
|
|
28065
|
+
function safeJsonParse(text) {
|
|
28066
|
+
if (text.length === 0) return void 0;
|
|
28067
|
+
try {
|
|
28068
|
+
return JSON.parse(text);
|
|
28069
|
+
} catch {
|
|
28070
|
+
return void 0;
|
|
28071
|
+
}
|
|
28072
|
+
}
|
|
28073
|
+
function trimTrailingSlashes(baseURL) {
|
|
28074
|
+
let end = baseURL.length;
|
|
28075
|
+
while (end > 0 && baseURL[end - 1] === "/") end -= 1;
|
|
28076
|
+
return baseURL.slice(0, end);
|
|
28077
|
+
}
|
|
28078
|
+
var toJsonBody = (value) => JSON.stringify(value, (_key, val) => typeof val === "bigint" ? val.toString() : val);
|
|
28079
|
+
async function makeRequest(params) {
|
|
28080
|
+
const { endpoint, config, overrideConfig = {}, logger, serviceLabel } = params;
|
|
28081
|
+
const baseURL = overrideConfig.baseURL || config.baseURL || "";
|
|
28082
|
+
const url = `${trimTrailingSlashes(baseURL)}${endpoint}`;
|
|
28083
|
+
const headers = mergeHeaders(config.headers, apiKeyHeader(overrideConfig.apiKey), overrideConfig.headers);
|
|
28084
|
+
const controller = new AbortController();
|
|
28085
|
+
const timeout = overrideConfig.timeout ?? config.timeout ?? DEFAULT_BACKEND_API_TIMEOUT;
|
|
28086
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
28087
|
+
try {
|
|
28088
|
+
const response = await fetch(url, {
|
|
28089
|
+
method: config.method,
|
|
28090
|
+
headers,
|
|
28091
|
+
body: config.body,
|
|
28092
|
+
signal: controller.signal
|
|
28093
|
+
});
|
|
28094
|
+
if (!response.ok) {
|
|
28095
|
+
const errorText = await response.text();
|
|
28096
|
+
throw new BackendHttpError(response.status, errorText);
|
|
28097
|
+
}
|
|
28098
|
+
const data = await response.json();
|
|
28099
|
+
return data;
|
|
28100
|
+
} catch (error) {
|
|
28101
|
+
if (error instanceof Error) {
|
|
28102
|
+
if (error.name === "AbortError") {
|
|
28103
|
+
throw new Error("REQUEST_TIMEOUT", { cause: new Error(`Request timeout after ${timeout}ms`) });
|
|
28104
|
+
}
|
|
28105
|
+
logger.error(`[${serviceLabel}] Request error`, error);
|
|
28106
|
+
throw error;
|
|
28107
|
+
}
|
|
28108
|
+
logger.error(`[${serviceLabel}] Unknown error`, error);
|
|
28109
|
+
throw new Error("UNKNOWN_REQUEST_ERROR", { cause: error });
|
|
28110
|
+
} finally {
|
|
28111
|
+
clearTimeout(timeoutId);
|
|
28112
|
+
}
|
|
28113
|
+
}
|
|
28114
|
+
function resolveRequestConfig(config, defaults) {
|
|
28115
|
+
const { baseURL, timeout, headers, apiKey, ...rest } = config;
|
|
28116
|
+
return {
|
|
28117
|
+
...rest,
|
|
28118
|
+
baseURL: baseURL || defaults.baseURL,
|
|
28119
|
+
timeout: timeout ?? defaults.timeout,
|
|
28120
|
+
headers: mergeHeaders(defaults.headers, apiKeyHeader(apiKey), headers)
|
|
28121
|
+
};
|
|
28122
|
+
}
|
|
28123
|
+
function toExternalApiError(params) {
|
|
28124
|
+
const { api, feature, endpoint, error } = params;
|
|
28125
|
+
const context = { api, endpoint };
|
|
28126
|
+
if (isBackendHttpError(error)) context.status = error.status;
|
|
28127
|
+
return new SodaxError(
|
|
28128
|
+
"EXTERNAL_API_ERROR",
|
|
28129
|
+
error instanceof Error ? error.message : `Request to ${endpoint} failed`,
|
|
28130
|
+
{ feature, cause: error, context }
|
|
28131
|
+
);
|
|
28132
|
+
}
|
|
28133
|
+
function toInvalidResponseShapeError(params) {
|
|
28134
|
+
const { api, feature, endpoint, issues } = params;
|
|
28135
|
+
return new SodaxError("EXTERNAL_API_ERROR", `Invalid response shape from ${api} API for ${endpoint}`, {
|
|
28136
|
+
feature,
|
|
28137
|
+
context: { api, endpoint, reason: "invalid_response_shape", issues }
|
|
28138
|
+
});
|
|
28139
|
+
}
|
|
28140
|
+
|
|
27299
28141
|
// src/swap/SolverApiService.ts
|
|
27300
28142
|
var bigintReplacer = (_key, value) => typeof value === "bigint" ? value.toString() : value;
|
|
27301
28143
|
var SolverApiService = class {
|
|
@@ -27342,9 +28184,7 @@ var SolverApiService = class {
|
|
|
27342
28184
|
try {
|
|
27343
28185
|
const response = await fetch(`${config.solverApiEndpoint}/quote`, {
|
|
27344
28186
|
method: "POST",
|
|
27345
|
-
headers: {
|
|
27346
|
-
"Content-Type": "application/json"
|
|
27347
|
-
},
|
|
28187
|
+
headers: mergeHeaders({ "Content-Type": "application/json" }, apiKeyHeader(configService.apiKey)),
|
|
27348
28188
|
body: JSON.stringify({
|
|
27349
28189
|
token_src: tokenSrc,
|
|
27350
28190
|
token_dst: tokenDst,
|
|
@@ -27390,16 +28230,16 @@ var SolverApiService = class {
|
|
|
27390
28230
|
*
|
|
27391
28231
|
* @param request - Object containing `intent_tx_hash` (the hub-chain tx hash of the created intent).
|
|
27392
28232
|
* @param config - Solver endpoint configuration.
|
|
28233
|
+
* @param logger - Diagnostics sink; defaults to the silent logger.
|
|
28234
|
+
* @param apiKey - Configured backend API key (`config.apiKey`), sent as the `x-api-key` header.
|
|
27393
28235
|
* @returns A `Result` containing `{ answer: 'OK', intent_hash: Hex }` on success.
|
|
27394
28236
|
*/
|
|
27395
|
-
static async postExecution(request, config, logger = silentLogger) {
|
|
28237
|
+
static async postExecution(request, config, logger = silentLogger, apiKey) {
|
|
27396
28238
|
try {
|
|
27397
28239
|
const response = await retry(
|
|
27398
28240
|
() => fetch(`${config.solverApiEndpoint}/execute`, {
|
|
27399
28241
|
method: "POST",
|
|
27400
|
-
headers: {
|
|
27401
|
-
"Content-Type": "application/json"
|
|
27402
|
-
},
|
|
28242
|
+
headers: mergeHeaders({ "Content-Type": "application/json" }, apiKeyHeader(apiKey)),
|
|
27403
28243
|
body: JSON.stringify(request)
|
|
27404
28244
|
})
|
|
27405
28245
|
);
|
|
@@ -27443,11 +28283,12 @@ var SolverApiService = class {
|
|
|
27443
28283
|
* request instantly. A non-positive one is a real budget of zero: the request aborts at once.
|
|
27444
28284
|
* The relay's `getTransactionPackets` takes the same parameter but degrades a non-finite value
|
|
27445
28285
|
* to its own per-request budget instead; the divergence is deliberate, and explained inline.
|
|
28286
|
+
* @param apiKey - Configured backend API key (`config.apiKey`), sent as the `x-api-key` header.
|
|
27446
28287
|
* @returns A `Result` containing `{ status: SolverIntentStatusCode, fill_tx_hash?: string }`.
|
|
27447
28288
|
* `fill_tx_hash` is set only when `status === SolverIntentStatusCode.SOLVED (3)`.
|
|
27448
28289
|
* @throws Invariant error if `intent_tx_hash` is empty (thrown before the async request).
|
|
27449
28290
|
*/
|
|
27450
|
-
static async getStatus(request, config, logger = silentLogger, timeoutMs) {
|
|
28291
|
+
static async getStatus(request, config, logger = silentLogger, timeoutMs, apiKey) {
|
|
27451
28292
|
invariant(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
|
|
27452
28293
|
const budgetMs = timeoutMs !== void 0 && Number.isFinite(timeoutMs) ? Math.max(0, timeoutMs) : void 0;
|
|
27453
28294
|
const controller = budgetMs === void 0 ? void 0 : new AbortController();
|
|
@@ -27455,9 +28296,7 @@ var SolverApiService = class {
|
|
|
27455
28296
|
try {
|
|
27456
28297
|
const response = await fetch(`${config.solverApiEndpoint}/status`, {
|
|
27457
28298
|
method: "POST",
|
|
27458
|
-
headers: {
|
|
27459
|
-
"Content-Type": "application/json"
|
|
27460
|
-
},
|
|
28299
|
+
headers: mergeHeaders({ "Content-Type": "application/json" }, apiKeyHeader(apiKey)),
|
|
27461
28300
|
body: JSON.stringify(request),
|
|
27462
28301
|
signal: controller?.signal
|
|
27463
28302
|
});
|
|
@@ -27518,6 +28357,12 @@ async function pollBackendSubmitTx({
|
|
|
27518
28357
|
}
|
|
27519
28358
|
} else {
|
|
27520
28359
|
lastStatusError = statusResult.error;
|
|
28360
|
+
if (isAuthFailure(statusResult.error)) {
|
|
28361
|
+
return {
|
|
28362
|
+
ok: false,
|
|
28363
|
+
cause: new Error("backend submit-tx status rejected the API key", { cause: statusResult.error })
|
|
28364
|
+
};
|
|
28365
|
+
}
|
|
27521
28366
|
}
|
|
27522
28367
|
if (attempt.remaining() <= intervalMs) break;
|
|
27523
28368
|
await sleep(intervalMs);
|
|
@@ -27559,12 +28404,13 @@ async function runBackendSubmitTx({
|
|
|
27559
28404
|
body,
|
|
27560
28405
|
statusQuery,
|
|
27561
28406
|
terminalStatus,
|
|
27562
|
-
onExecuted
|
|
28407
|
+
onExecuted,
|
|
28408
|
+
overrideConfig
|
|
27563
28409
|
}) {
|
|
27564
28410
|
const serviceTimeoutMs = api.getTimeout();
|
|
27565
28411
|
const requestTimeout = attempt.requestTimeout(serviceTimeoutMs);
|
|
27566
28412
|
if (requestTimeout === null) return { ok: false, cause: noRequestBudgetCause(serviceTimeoutMs) };
|
|
27567
|
-
const submitted = await api.submitTx(body, { timeout: requestTimeout });
|
|
28413
|
+
const submitted = await api.submitTx(body, { ...overrideConfig, timeout: requestTimeout });
|
|
27568
28414
|
if (!submitted.ok) return { ok: false, cause: submitted.error };
|
|
27569
28415
|
if (!submitted.value.success) {
|
|
27570
28416
|
return { ok: false, cause: new Error(`backend submit-tx not accepted: ${submitted.value.data.message}`) };
|
|
@@ -27572,7 +28418,8 @@ async function runBackendSubmitTx({
|
|
|
27572
28418
|
const polled = await pollBackendSubmitTx({
|
|
27573
28419
|
attempt,
|
|
27574
28420
|
terminalStatus,
|
|
27575
|
-
|
|
28421
|
+
// The poll's own override (its per-request timeout) wins over the per-action fields.
|
|
28422
|
+
getStatus: (override) => api.getSubmitTxStatus(statusQuery, { ...overrideConfig, ...override }),
|
|
27576
28423
|
onExecuted,
|
|
27577
28424
|
// While this ceiling is the smaller bound the poll retries within the attempt; once the attempt's
|
|
27578
28425
|
// remainder falls below it, one stalled request can spend the rest.
|
|
@@ -27723,9 +28570,38 @@ var TokensByChainMapSchema = v.custom(
|
|
|
27723
28570
|
);
|
|
27724
28571
|
var TokensListSchema = v.array(XTokenSchema);
|
|
27725
28572
|
var ReserveAssetsSchema = v.array(AddressSchema);
|
|
28573
|
+
var ORACLE_CANDLE_INTERVALS = ["1m", "5m", "1h", "1d"];
|
|
28574
|
+
var OracleCandleIntervalSchema = v.picklist(ORACLE_CANDLE_INTERVALS);
|
|
28575
|
+
var OracleMarketsResponseSchema = v.object({
|
|
28576
|
+
quote: v.string(),
|
|
28577
|
+
intervals: v.array(
|
|
28578
|
+
v.object({
|
|
28579
|
+
key: v.string(),
|
|
28580
|
+
label: v.string(),
|
|
28581
|
+
seconds: v.number()
|
|
28582
|
+
})
|
|
28583
|
+
),
|
|
28584
|
+
symbols: v.array(v.string())
|
|
28585
|
+
});
|
|
28586
|
+
var OracleCandlesResponseSchema = v.object({
|
|
28587
|
+
symbol: v.string(),
|
|
28588
|
+
quote: v.string(),
|
|
28589
|
+
interval: OracleCandleIntervalSchema,
|
|
28590
|
+
candles: v.array(
|
|
28591
|
+
v.object({
|
|
28592
|
+
timestamp: v.number(),
|
|
28593
|
+
open: v.string(),
|
|
28594
|
+
high: v.string(),
|
|
28595
|
+
low: v.string(),
|
|
28596
|
+
close: v.string(),
|
|
28597
|
+
final: v.optional(v.boolean())
|
|
28598
|
+
})
|
|
28599
|
+
)
|
|
28600
|
+
});
|
|
27726
28601
|
|
|
27727
28602
|
// src/backendApi/guards.ts
|
|
27728
28603
|
var isFillEvent = (value) => v.is(FillEventSchema, value);
|
|
28604
|
+
var isOracleCandleInterval = (value) => v.is(OracleCandleIntervalSchema, value);
|
|
27729
28605
|
function decodePacketIntentTarget(payload) {
|
|
27730
28606
|
try {
|
|
27731
28607
|
const hex = payload.startsWith("0x") ? payload.slice(2) : payload;
|
|
@@ -27745,6 +28621,34 @@ function selectSolvedIntentPacket(packets, intentsContract) {
|
|
|
27745
28621
|
return packets.reduce((highest, packet) => packet.conn_sn > highest.conn_sn ? packet : highest);
|
|
27746
28622
|
}
|
|
27747
28623
|
|
|
28624
|
+
// src/swap/speed-tier.ts
|
|
28625
|
+
var SPEED_TIER_SECONDS = {
|
|
28626
|
+
/** Either token maps to a money-market-reserve (sodaAsset) hub asset. */
|
|
28627
|
+
sodaAsset: 15,
|
|
28628
|
+
/** Anything else / default. */
|
|
28629
|
+
default: 35,
|
|
28630
|
+
/** Added once when either src or dst is an Ethereum asset. */
|
|
28631
|
+
ethereumPenalty: 10
|
|
28632
|
+
};
|
|
28633
|
+
var SPEED_TIER_THRESHOLDS = {
|
|
28634
|
+
fast: 20,
|
|
28635
|
+
normal: 30
|
|
28636
|
+
};
|
|
28637
|
+
var isEthereumToken = (token) => token.chainKey === ChainKeys.ETHEREUM_MAINNET;
|
|
28638
|
+
var secondsToTier = (seconds) => {
|
|
28639
|
+
if (seconds <= SPEED_TIER_THRESHOLDS.fast) return "fast";
|
|
28640
|
+
if (seconds <= SPEED_TIER_THRESHOLDS.normal) return "normal";
|
|
28641
|
+
return "slow";
|
|
28642
|
+
};
|
|
28643
|
+
function estimateSwapSpeedTier({ srcToken, dstToken }, isSodaAssetRelated) {
|
|
28644
|
+
const eitherSodaAsset = isSodaAssetRelated(srcToken.hubAsset) || isSodaAssetRelated(dstToken.hubAsset);
|
|
28645
|
+
let estimatedSeconds = eitherSodaAsset ? SPEED_TIER_SECONDS.sodaAsset : SPEED_TIER_SECONDS.default;
|
|
28646
|
+
if (isEthereumToken(srcToken) || isEthereumToken(dstToken)) {
|
|
28647
|
+
estimatedSeconds += SPEED_TIER_SECONDS.ethereumPenalty;
|
|
28648
|
+
}
|
|
28649
|
+
return { tier: secondsToTier(estimatedSeconds), estimatedSeconds };
|
|
28650
|
+
}
|
|
28651
|
+
|
|
27748
28652
|
// src/swap/detailedStatus.ts
|
|
27749
28653
|
var DETAILED_STATUS_NOT_DELIVERED = "relay_not_delivered";
|
|
27750
28654
|
function isBackendSubmitTxAbandoned(data) {
|
|
@@ -27901,7 +28805,13 @@ var SwapService = class {
|
|
|
27901
28805
|
* falls through to carries its own {@link RECONCILE_TIMEOUT_MS}, so a bounded call can cost both.
|
|
27902
28806
|
*/
|
|
27903
28807
|
async resolveSolverStatus(request, timeoutMs) {
|
|
27904
|
-
const solverResult = await SolverApiService.getStatus(
|
|
28808
|
+
const solverResult = await SolverApiService.getStatus(
|
|
28809
|
+
request,
|
|
28810
|
+
this.solver,
|
|
28811
|
+
this.config.logger,
|
|
28812
|
+
timeoutMs,
|
|
28813
|
+
this.config.apiKey
|
|
28814
|
+
);
|
|
27905
28815
|
const forgotten = !solverResult.ok || solverResult.value.status === SolverIntentStatusCode.NOT_FOUND;
|
|
27906
28816
|
if (!forgotten) return solverResult;
|
|
27907
28817
|
const timeout = Math.min(RECONCILE_TIMEOUT_MS, this.backendApi.requestTimeoutMs);
|
|
@@ -28050,7 +28960,7 @@ var SwapService = class {
|
|
|
28050
28960
|
*/
|
|
28051
28961
|
async postExecution(request) {
|
|
28052
28962
|
try {
|
|
28053
|
-
const result = await SolverApiService.postExecution(request, this.solver, this.config.logger);
|
|
28963
|
+
const result = await SolverApiService.postExecution(request, this.solver, this.config.logger, this.config.apiKey);
|
|
28054
28964
|
if (result.ok) return result;
|
|
28055
28965
|
const detail = result.error?.detail ?? {
|
|
28056
28966
|
code: -999,
|
|
@@ -28281,6 +29191,9 @@ var SwapService = class {
|
|
|
28281
29191
|
const outcome = await runBackendSubmitTx({
|
|
28282
29192
|
attempt,
|
|
28283
29193
|
api: this.backendApi.swaps,
|
|
29194
|
+
// The configured key is already baked into the SwapsApiService headers, so only this
|
|
29195
|
+
// per-action override (mirroring `extras.partnerFee`) travels per call.
|
|
29196
|
+
overrideConfig: { apiKey: _params.extras?.apiKey },
|
|
28284
29197
|
body: {
|
|
28285
29198
|
txHash: spokeTxHash,
|
|
28286
29199
|
srcChainKey,
|
|
@@ -29029,6 +29942,19 @@ var SwapService = class {
|
|
|
29029
29942
|
getSupportedSwapTokens() {
|
|
29030
29943
|
return this.config.getSupportedSwapTokens();
|
|
29031
29944
|
}
|
|
29945
|
+
/**
|
|
29946
|
+
* Offline, rule-based estimate of how fast a `srcToken`→`dstToken` swap will settle.
|
|
29947
|
+
*
|
|
29948
|
+
* Derived purely from SDK config (no network / on-chain / backend call): tokens tied to a
|
|
29949
|
+
* money-market-reserve sodaAsset settle faster, and an Ethereum leg adds a fixed penalty. See
|
|
29950
|
+
* {@link estimateSwapSpeedTier} for the rules.
|
|
29951
|
+
*
|
|
29952
|
+
* @param params `{ srcToken, dstToken }` spoke token pair to estimate
|
|
29953
|
+
* @returns the estimated `tier` bucket and `estimatedSeconds`
|
|
29954
|
+
*/
|
|
29955
|
+
getSwapSpeedTier(params) {
|
|
29956
|
+
return estimateSwapSpeedTier(params, (hubAsset) => this.config.isMoneyMarketReserveHubAsset(hubAsset));
|
|
29957
|
+
}
|
|
29032
29958
|
};
|
|
29033
29959
|
|
|
29034
29960
|
// src/migration/errors.ts
|
|
@@ -31107,100 +32033,6 @@ var MigrationService = class {
|
|
|
31107
32033
|
}
|
|
31108
32034
|
};
|
|
31109
32035
|
|
|
31110
|
-
// src/backendApi/api-utils.ts
|
|
31111
|
-
var BackendHttpError = class extends Error {
|
|
31112
|
-
status;
|
|
31113
|
-
bodyText;
|
|
31114
|
-
/** Parsed JSON, or `undefined` for empty or malformed bodies. */
|
|
31115
|
-
body;
|
|
31116
|
-
constructor(status, bodyText) {
|
|
31117
|
-
super("HTTP_REQUEST_FAILED", { cause: new Error(`HTTP ${status}: ${bodyText}`) });
|
|
31118
|
-
this.name = "BackendHttpError";
|
|
31119
|
-
this.status = status;
|
|
31120
|
-
this.bodyText = bodyText;
|
|
31121
|
-
this.body = safeJsonParse(bodyText);
|
|
31122
|
-
}
|
|
31123
|
-
};
|
|
31124
|
-
function isBackendHttpError(error) {
|
|
31125
|
-
if (error instanceof BackendHttpError) return true;
|
|
31126
|
-
return error instanceof Error && error.name === "BackendHttpError" && typeof error.status === "number";
|
|
31127
|
-
}
|
|
31128
|
-
function safeJsonParse(text) {
|
|
31129
|
-
if (text.length === 0) return void 0;
|
|
31130
|
-
try {
|
|
31131
|
-
return JSON.parse(text);
|
|
31132
|
-
} catch {
|
|
31133
|
-
return void 0;
|
|
31134
|
-
}
|
|
31135
|
-
}
|
|
31136
|
-
function trimTrailingSlashes(baseURL) {
|
|
31137
|
-
let end = baseURL.length;
|
|
31138
|
-
while (end > 0 && baseURL[end - 1] === "/") end -= 1;
|
|
31139
|
-
return baseURL.slice(0, end);
|
|
31140
|
-
}
|
|
31141
|
-
var toJsonBody = (value) => JSON.stringify(value, (_key, val) => typeof val === "bigint" ? val.toString() : val);
|
|
31142
|
-
async function makeRequest(params) {
|
|
31143
|
-
const { endpoint, config, overrideConfig = {}, logger, serviceLabel } = params;
|
|
31144
|
-
const baseURL = overrideConfig.baseURL || config.baseURL || "";
|
|
31145
|
-
const url = `${trimTrailingSlashes(baseURL)}${endpoint}`;
|
|
31146
|
-
const headers = { ...config.headers, ...overrideConfig.headers };
|
|
31147
|
-
const controller = new AbortController();
|
|
31148
|
-
const timeout = overrideConfig.timeout ?? config.timeout ?? DEFAULT_BACKEND_API_TIMEOUT;
|
|
31149
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
31150
|
-
try {
|
|
31151
|
-
const response = await fetch(url, {
|
|
31152
|
-
method: config.method,
|
|
31153
|
-
headers,
|
|
31154
|
-
body: config.body,
|
|
31155
|
-
signal: controller.signal
|
|
31156
|
-
});
|
|
31157
|
-
if (!response.ok) {
|
|
31158
|
-
const errorText = await response.text();
|
|
31159
|
-
throw new BackendHttpError(response.status, errorText);
|
|
31160
|
-
}
|
|
31161
|
-
const data = await response.json();
|
|
31162
|
-
return data;
|
|
31163
|
-
} catch (error) {
|
|
31164
|
-
if (error instanceof Error) {
|
|
31165
|
-
if (error.name === "AbortError") {
|
|
31166
|
-
throw new Error("REQUEST_TIMEOUT", { cause: new Error(`Request timeout after ${timeout}ms`) });
|
|
31167
|
-
}
|
|
31168
|
-
logger.error(`[${serviceLabel}] Request error`, error);
|
|
31169
|
-
throw error;
|
|
31170
|
-
}
|
|
31171
|
-
logger.error(`[${serviceLabel}] Unknown error`, error);
|
|
31172
|
-
throw new Error("UNKNOWN_REQUEST_ERROR", { cause: error });
|
|
31173
|
-
} finally {
|
|
31174
|
-
clearTimeout(timeoutId);
|
|
31175
|
-
}
|
|
31176
|
-
}
|
|
31177
|
-
function resolveRequestConfig(config, defaults) {
|
|
31178
|
-
const { baseURL, timeout, headers, ...rest } = config;
|
|
31179
|
-
return {
|
|
31180
|
-
...rest,
|
|
31181
|
-
baseURL: baseURL || defaults.baseURL,
|
|
31182
|
-
timeout: timeout ?? defaults.timeout,
|
|
31183
|
-
headers: { ...defaults.headers, ...headers }
|
|
31184
|
-
};
|
|
31185
|
-
}
|
|
31186
|
-
function toExternalApiError(params) {
|
|
31187
|
-
const { api, feature, endpoint, error } = params;
|
|
31188
|
-
const context = { api, endpoint };
|
|
31189
|
-
if (isBackendHttpError(error)) context.status = error.status;
|
|
31190
|
-
return new SodaxError(
|
|
31191
|
-
"EXTERNAL_API_ERROR",
|
|
31192
|
-
error instanceof Error ? error.message : `Request to ${endpoint} failed`,
|
|
31193
|
-
{ feature, cause: error, context }
|
|
31194
|
-
);
|
|
31195
|
-
}
|
|
31196
|
-
function toInvalidResponseShapeError(params) {
|
|
31197
|
-
const { api, feature, endpoint, issues } = params;
|
|
31198
|
-
return new SodaxError("EXTERNAL_API_ERROR", `Invalid response shape from ${api} API for ${endpoint}`, {
|
|
31199
|
-
feature,
|
|
31200
|
-
context: { api, endpoint, reason: "invalid_response_shape", issues }
|
|
31201
|
-
});
|
|
31202
|
-
}
|
|
31203
|
-
|
|
31204
32036
|
// src/backendApi/apiConfig.ts
|
|
31205
32037
|
function flatLayer({ baseURL, timeout, headers }) {
|
|
31206
32038
|
return { baseURL, timeout, headers };
|
|
@@ -31303,7 +32135,7 @@ var SwapsApiService = class _SwapsApiService {
|
|
|
31303
32135
|
trimsLegacyOverrides;
|
|
31304
32136
|
constructor(config, logger = consoleLogger, options = {}) {
|
|
31305
32137
|
this.config = config;
|
|
31306
|
-
this.headers =
|
|
32138
|
+
this.headers = mergeHeaders(config.headers);
|
|
31307
32139
|
this.logger = logger;
|
|
31308
32140
|
this.trimsLegacyOverrides = options.trimLegacyOverrides ?? true;
|
|
31309
32141
|
}
|
|
@@ -31319,7 +32151,7 @@ var SwapsApiService = class _SwapsApiService {
|
|
|
31319
32151
|
const override = overrideConfig?.baseURL;
|
|
31320
32152
|
const baseUrl = override ? this.trimsLegacyOverrides ? stripLegacyBackendMount(override) : override : this.config.baseURL;
|
|
31321
32153
|
const timeout = overrideConfig?.timeout ?? this.config.timeout ?? DEFAULT_BACKEND_API_TIMEOUT;
|
|
31322
|
-
const headers =
|
|
32154
|
+
const headers = mergeHeaders(this.headers, apiKeyHeader(overrideConfig?.apiKey), overrideConfig?.headers);
|
|
31323
32155
|
return new SwapsApi({ baseUrl, headers, timeout });
|
|
31324
32156
|
}
|
|
31325
32157
|
/**
|
|
@@ -31345,6 +32177,11 @@ var SwapsApiService = class _SwapsApiService {
|
|
|
31345
32177
|
context.issues = issues instanceof v.ValiError ? v.flatten(issues.issues) : issues;
|
|
31346
32178
|
}
|
|
31347
32179
|
if (error.context.status !== void 0) context.status = error.context.status;
|
|
32180
|
+
if (isAuthStatus(error.context.status)) {
|
|
32181
|
+
this.logger.warn(
|
|
32182
|
+
`[SwapsApiService] ${endpoint} was rejected by the swaps API key guard (${error.context.status}). Configure a valid partner API key \u2014 new Sodax({ apiKey }) \u2014 see docs/CONFIGURE_SDK.md.`
|
|
32183
|
+
);
|
|
32184
|
+
}
|
|
31348
32185
|
}
|
|
31349
32186
|
this.logger.error(`[SwapsApiService] Request to ${endpoint} failed`, error);
|
|
31350
32187
|
return {
|
|
@@ -31496,9 +32333,7 @@ var SwapsApiService = class _SwapsApiService {
|
|
|
31496
32333
|
* every subsequent call (the delegated client is rebuilt per call).
|
|
31497
32334
|
*/
|
|
31498
32335
|
setHeaders(headers) {
|
|
31499
|
-
|
|
31500
|
-
this.headers[key] = value;
|
|
31501
|
-
});
|
|
32336
|
+
assignHeaders(this.headers, headers);
|
|
31502
32337
|
}
|
|
31503
32338
|
/** Return the base URL the service is currently pointing at. */
|
|
31504
32339
|
getBaseURL() {
|
|
@@ -31539,13 +32374,22 @@ var SponsoringApiService = class {
|
|
|
31539
32374
|
config;
|
|
31540
32375
|
headers;
|
|
31541
32376
|
logger;
|
|
31542
|
-
|
|
32377
|
+
inheritedApiKey;
|
|
32378
|
+
inheritedApiKeyBaseURLs;
|
|
32379
|
+
constructor(config, logger = consoleLogger, options = {}) {
|
|
31543
32380
|
this.config = config;
|
|
31544
|
-
this.headers =
|
|
31545
|
-
...config.apiKey !== void 0 ? { "x-api-key": config.apiKey } : {},
|
|
31546
|
-
...config.headers
|
|
31547
|
-
};
|
|
32381
|
+
this.headers = mergeHeaders(apiKeyHeader(config.apiKey), config.headers);
|
|
31548
32382
|
this.logger = logger;
|
|
32383
|
+
this.inheritedApiKey = options.inheritedApiKey;
|
|
32384
|
+
this.inheritedApiKeyBaseURLs = (options.inheritedApiKeyBaseURLs ?? []).map(trimTrailingSlashes);
|
|
32385
|
+
}
|
|
32386
|
+
/**
|
|
32387
|
+
* The inherited instance key, but only for a request whose effective target is an allowed root.
|
|
32388
|
+
* Evaluated per call because a `RequestOverrideConfig.baseURL` retargets the request.
|
|
32389
|
+
*/
|
|
32390
|
+
inheritedKeyFor(baseURL) {
|
|
32391
|
+
if (!this.inheritedApiKey) return void 0;
|
|
32392
|
+
return this.inheritedApiKeyBaseURLs.includes(trimTrailingSlashes(baseURL)) ? this.inheritedApiKey : void 0;
|
|
31549
32393
|
}
|
|
31550
32394
|
/**
|
|
31551
32395
|
* Validate a response while preserving HTTP failures on `error.cause` for
|
|
@@ -31553,9 +32397,10 @@ var SponsoringApiService = class {
|
|
|
31553
32397
|
*/
|
|
31554
32398
|
async request(endpoint, config, schema) {
|
|
31555
32399
|
try {
|
|
32400
|
+
const inherited = apiKeyHeader(this.inheritedKeyFor(config.baseURL || this.config.baseURL));
|
|
31556
32401
|
const raw = await makeRequest({
|
|
31557
32402
|
endpoint,
|
|
31558
|
-
config: resolveRequestConfig(config, { ...this.config, headers: this.headers }),
|
|
32403
|
+
config: resolveRequestConfig(config, { ...this.config, headers: mergeHeaders(inherited, this.headers) }),
|
|
31559
32404
|
logger: this.logger,
|
|
31560
32405
|
serviceLabel: "SponsoringApiService"
|
|
31561
32406
|
});
|
|
@@ -31597,9 +32442,7 @@ var SponsoringApiService = class {
|
|
|
31597
32442
|
);
|
|
31598
32443
|
}
|
|
31599
32444
|
setHeaders(headers) {
|
|
31600
|
-
|
|
31601
|
-
this.headers[key] = value;
|
|
31602
|
-
});
|
|
32445
|
+
assignHeaders(this.headers, headers);
|
|
31603
32446
|
}
|
|
31604
32447
|
getBaseURL() {
|
|
31605
32448
|
return this.config.baseURL;
|
|
@@ -31830,18 +32673,7 @@ var BridgeApiService = class {
|
|
|
31830
32673
|
}
|
|
31831
32674
|
return { ok: true, value: parsed.output };
|
|
31832
32675
|
} catch (error) {
|
|
31833
|
-
return {
|
|
31834
|
-
ok: false,
|
|
31835
|
-
error: new SodaxError(
|
|
31836
|
-
"EXTERNAL_API_ERROR",
|
|
31837
|
-
error instanceof Error ? error.message : `Request to ${endpoint} failed`,
|
|
31838
|
-
{
|
|
31839
|
-
feature: "backend",
|
|
31840
|
-
cause: error,
|
|
31841
|
-
context: { api: "bridge", endpoint }
|
|
31842
|
-
}
|
|
31843
|
-
)
|
|
31844
|
-
};
|
|
32676
|
+
return { ok: false, error: toExternalApiError({ api: "bridge", feature: "backend", endpoint, error }) };
|
|
31845
32677
|
}
|
|
31846
32678
|
}
|
|
31847
32679
|
// ──────────────────────────────────────────────────────────────────────
|
|
@@ -32000,9 +32832,7 @@ var BridgeApiService = class {
|
|
|
32000
32832
|
* keys are overwritten; keys absent from `headers` are preserved.
|
|
32001
32833
|
*/
|
|
32002
32834
|
setHeaders(headers) {
|
|
32003
|
-
|
|
32004
|
-
this.headers[key] = value;
|
|
32005
|
-
});
|
|
32835
|
+
assignHeaders(this.headers, headers);
|
|
32006
32836
|
}
|
|
32007
32837
|
/** Return the base URL the service is currently pointing at. */
|
|
32008
32838
|
getBaseURL() {
|
|
@@ -32047,8 +32877,8 @@ var BackendApiService = class {
|
|
|
32047
32877
|
* left exactly as given rather than having a real path segment eaten.
|
|
32048
32878
|
*/
|
|
32049
32879
|
trimsLegacyOverrides;
|
|
32050
|
-
constructor(config, logger = consoleLogger) {
|
|
32051
|
-
this.config = resolveBaseApiConfig(config);
|
|
32880
|
+
constructor(config, logger = consoleLogger, options = {}) {
|
|
32881
|
+
this.config = withApiKey(resolveBaseApiConfig(config), options.apiKey);
|
|
32052
32882
|
this.headers = { ...this.config.headers };
|
|
32053
32883
|
this.logger = logger;
|
|
32054
32884
|
this.trimsLegacyOverrides = !hasExplicitBasePath(config);
|
|
@@ -32073,9 +32903,12 @@ var BackendApiService = class {
|
|
|
32073
32903
|
);
|
|
32074
32904
|
}
|
|
32075
32905
|
const overrideOptions = { trimLegacyOverrides: this.trimsLegacyOverrides };
|
|
32076
|
-
this.swaps = new SwapsApiService(swapsConfig2, this.logger, overrideOptions);
|
|
32077
|
-
this.sponsoring = new SponsoringApiService(sponsoringConfig, this.logger
|
|
32078
|
-
|
|
32906
|
+
this.swaps = new SwapsApiService(withApiKey(swapsConfig2, options.apiKey), this.logger, overrideOptions);
|
|
32907
|
+
this.sponsoring = new SponsoringApiService(sponsoringConfig, this.logger, {
|
|
32908
|
+
inheritedApiKey: options.apiKey,
|
|
32909
|
+
inheritedApiKeyBaseURLs: [DEFAULT_SPONSORING_API_ENDPOINT, this.config.baseURL]
|
|
32910
|
+
});
|
|
32911
|
+
this.bridge = new BridgeApiService(withApiKey(bridgeConfig2, options.apiKey), this.logger, overrideOptions);
|
|
32079
32912
|
}
|
|
32080
32913
|
/**
|
|
32081
32914
|
* Issue the HTTP call for a route.
|
|
@@ -32301,6 +33134,46 @@ var BackendApiService = class {
|
|
|
32301
33134
|
const endpoint = `/moneymarket/borrowers?${queryString}`;
|
|
32302
33135
|
return this.request(endpoint, { ...config, method: "GET" }, MoneyMarketBorrowersSchema);
|
|
32303
33136
|
}
|
|
33137
|
+
// Oracle endpoints
|
|
33138
|
+
/**
|
|
33139
|
+
* Fetch the oracle candle store's discovery payload: the quote currency (currently always
|
|
33140
|
+
* `"USD"`), the selectable candle intervals, and the canonical symbols that have candle data.
|
|
33141
|
+
*
|
|
33142
|
+
* Use this to populate a symbol picker and interval switcher before calling
|
|
33143
|
+
* {@link getOracleCandles}.
|
|
33144
|
+
*
|
|
33145
|
+
* @returns `Result<OracleMarketsResponse>` — on success, `{ quote, intervals, symbols }`.
|
|
33146
|
+
*/
|
|
33147
|
+
async getOracleMarkets(config) {
|
|
33148
|
+
return this.request("/oracle/markets", { ...config, method: "GET" }, OracleMarketsResponseSchema);
|
|
33149
|
+
}
|
|
33150
|
+
/**
|
|
33151
|
+
* Fetch USD OHLC candles for a symbol over the half-open time range `[from, to)`.
|
|
33152
|
+
*
|
|
33153
|
+
* `from` and `to` are UNIX **seconds** (integers); `to` is exclusive and must exceed `from`,
|
|
33154
|
+
* and the range may cover at most 5000 buckets of the requested interval (invalid or wider
|
|
33155
|
+
* ranges fail with HTTP 400). A valid range with no stored candles resolves `ok` with
|
|
33156
|
+
* `candles: []`; an unknown symbol currently does the same rather than returning 404. The last
|
|
33157
|
+
* candle may still be forming; re-poll while its `final === false`.
|
|
33158
|
+
* Responses are cached server-side for roughly 10 seconds per distinct URL.
|
|
33159
|
+
*
|
|
33160
|
+
* @param params.symbol - Canonical symbol, exact case, from {@link getOracleMarkets} (e.g. `"ETH"`).
|
|
33161
|
+
* @param params.interval - Candle bucket size: `'1m' | '5m' | '1h' | '1d'`.
|
|
33162
|
+
* @param params.from - Range start, UNIX seconds, inclusive.
|
|
33163
|
+
* @param params.to - Range end, UNIX seconds, exclusive.
|
|
33164
|
+
* @returns `Result<OracleCandlesResponse>` — on success, the echoed query dimensions and
|
|
33165
|
+
* oldest-first candles with USD decimal-string prices (no volume field).
|
|
33166
|
+
*/
|
|
33167
|
+
async getOracleCandles(params, config) {
|
|
33168
|
+
const queryParams = new URLSearchParams();
|
|
33169
|
+
queryParams.append("symbol", params.symbol);
|
|
33170
|
+
queryParams.append("interval", params.interval);
|
|
33171
|
+
queryParams.append("from", String(params.from));
|
|
33172
|
+
queryParams.append("to", String(params.to));
|
|
33173
|
+
const queryString = queryParams.toString();
|
|
33174
|
+
const endpoint = `/oracle/candles?${queryString}`;
|
|
33175
|
+
return this.request(endpoint, { ...config, method: "GET" }, OracleCandlesResponseSchema);
|
|
33176
|
+
}
|
|
32304
33177
|
/**
|
|
32305
33178
|
* Fetch the complete SODAX runtime configuration in a single request.
|
|
32306
33179
|
*
|
|
@@ -32446,9 +33319,7 @@ var BackendApiService = class {
|
|
|
32446
33319
|
* @param headers - Key-value pairs to add or overwrite in the default headers.
|
|
32447
33320
|
*/
|
|
32448
33321
|
setHeaders(headers) {
|
|
32449
|
-
|
|
32450
|
-
this.headers[key] = value;
|
|
32451
|
-
});
|
|
33322
|
+
assignHeaders(this.headers, headers);
|
|
32452
33323
|
this.swaps.setHeaders(headers);
|
|
32453
33324
|
this.bridge.setHeaders(headers);
|
|
32454
33325
|
}
|
|
@@ -32917,6 +33788,9 @@ var BridgeService = class {
|
|
|
32917
33788
|
const outcome = await runBackendSubmitTx({
|
|
32918
33789
|
attempt,
|
|
32919
33790
|
api: this.backendApi.bridge,
|
|
33791
|
+
// The configured key is already baked into the BridgeApiService headers, so only this
|
|
33792
|
+
// per-action override (mirroring `extras.partnerFee`) travels per call.
|
|
33793
|
+
overrideConfig: { apiKey: _params.extras?.apiKey },
|
|
32920
33794
|
body: {
|
|
32921
33795
|
txHash: spokeTxHash,
|
|
32922
33796
|
srcChainKey,
|
|
@@ -40929,7 +41803,8 @@ var PartnerFeeClaimService = class {
|
|
|
40929
41803
|
const solverExecutionResponse = await SolverApiService.postExecution(
|
|
40930
41804
|
{ intent_tx_hash: intentTxHash },
|
|
40931
41805
|
this.config.solver,
|
|
40932
|
-
this.config.logger
|
|
41806
|
+
this.config.logger,
|
|
41807
|
+
this.config.apiKey
|
|
40933
41808
|
);
|
|
40934
41809
|
if (!solverExecutionResponse.ok) {
|
|
40935
41810
|
return solverExecutionResponse;
|
|
@@ -41933,7 +42808,12 @@ var LeverageYieldService = class {
|
|
|
41933
42808
|
*/
|
|
41934
42809
|
async notifySolver(request) {
|
|
41935
42810
|
try {
|
|
41936
|
-
const result = await SolverApiService.postExecution(
|
|
42811
|
+
const result = await SolverApiService.postExecution(
|
|
42812
|
+
request,
|
|
42813
|
+
this.config.solver,
|
|
42814
|
+
this.config.logger,
|
|
42815
|
+
this.config.apiKey
|
|
42816
|
+
);
|
|
41937
42817
|
if (result.ok) return result;
|
|
41938
42818
|
const detail = result.error?.detail ?? {
|
|
41939
42819
|
code: -999,
|
|
@@ -42484,7 +43364,7 @@ function xlmDecimalToStroops(amount) {
|
|
|
42484
43364
|
const scaled = `${whole}${fraction.padEnd(XLM_DECIMALS, "0").slice(0, XLM_DECIMALS)}`;
|
|
42485
43365
|
return BigInt(scaled);
|
|
42486
43366
|
}
|
|
42487
|
-
var
|
|
43367
|
+
var STELLAR_BASE_RESERVE_STROOPS2 = 5000000n;
|
|
42488
43368
|
var BASE_RESERVE_UNITS = 2;
|
|
42489
43369
|
function parseBaseReserveStroops(ledger) {
|
|
42490
43370
|
const value = ledger?.base_reserve_in_stroops;
|
|
@@ -42511,7 +43391,7 @@ var SPONSOR_CONFIG_TTL_MS = 6e4;
|
|
|
42511
43391
|
var STELLAR_BASE_RESERVE_TTL_MS = 36e5;
|
|
42512
43392
|
var DEFAULT_MAX_HORIZON_RETRIES = 2;
|
|
42513
43393
|
var STELLAR_FEE_HEADROOM_STROOPS = 100000n;
|
|
42514
|
-
var STELLAR_TRUSTLINE_MIN_XLM_STROOPS =
|
|
43394
|
+
var STELLAR_TRUSTLINE_MIN_XLM_STROOPS = STELLAR_BASE_RESERVE_STROOPS2 + STELLAR_FEE_HEADROOM_STROOPS;
|
|
42515
43395
|
var SponsoringService = class {
|
|
42516
43396
|
config;
|
|
42517
43397
|
spoke;
|
|
@@ -42614,7 +43494,7 @@ var SponsoringService = class {
|
|
|
42614
43494
|
reason: messageOf(error, String(error))
|
|
42615
43495
|
});
|
|
42616
43496
|
}
|
|
42617
|
-
return
|
|
43497
|
+
return STELLAR_BASE_RESERVE_STROOPS2;
|
|
42618
43498
|
};
|
|
42619
43499
|
const request = read().then((value) => {
|
|
42620
43500
|
this.baseReserveCache = { value, expiresAt: Date.now() + STELLAR_BASE_RESERVE_TTL_MS };
|
|
@@ -42626,18 +43506,18 @@ var SponsoringService = class {
|
|
|
42626
43506
|
return request;
|
|
42627
43507
|
}
|
|
42628
43508
|
/**
|
|
42629
|
-
* Cache key for a config request: the resolved base URL plus
|
|
42630
|
-
*
|
|
42631
|
-
* key scoped to another deployment, or a test harness's scenario header — so
|
|
42632
|
-
*
|
|
42633
|
-
*
|
|
43509
|
+
* Cache key for a config request: the resolved base URL plus the per-call headers the request will
|
|
43510
|
+
* actually carry, `apiKey` included. Headers can select a different response from the same URL — an
|
|
43511
|
+
* API key scoped to another deployment, or a test harness's scenario header — so folding them in
|
|
43512
|
+
* stops one caller's override from being served to, or overwriting, the default path. Names are
|
|
43513
|
+
* lower-cased before sorting and serialized as JSON so casing and delimiters cannot collide two
|
|
43514
|
+
* distinct header sets onto one key. Kept in memory as a Map key only.
|
|
42634
43515
|
*/
|
|
42635
43516
|
configCacheKey(requestConfig) {
|
|
42636
43517
|
const baseURL = requestConfig?.baseURL || this.api.sponsoring.getBaseURL();
|
|
42637
|
-
const headers = requestConfig?.headers;
|
|
42638
|
-
|
|
42639
|
-
|
|
42640
|
-
return normalized.length === 0 ? baseURL : `${baseURL}|${normalized}`;
|
|
43518
|
+
const headers = mergeHeaders(apiKeyHeader(requestConfig?.apiKey), requestConfig?.headers);
|
|
43519
|
+
const entries = Object.entries(headers).map(([name, value]) => [name.toLowerCase(), value]).sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
43520
|
+
return entries.length === 0 ? baseURL : `${baseURL}|${JSON.stringify(entries)}`;
|
|
42641
43521
|
}
|
|
42642
43522
|
/**
|
|
42643
43523
|
* Fetch sponsor config with per-endpoint caching and in-flight deduplication.
|
|
@@ -42863,17 +43743,20 @@ var Sodax = class {
|
|
|
42863
43743
|
const logger = resolveLogger(options?.logger);
|
|
42864
43744
|
const analytics = resolveAnalytics(options?.analytics);
|
|
42865
43745
|
const fee = options?.fee;
|
|
43746
|
+
const apiKey = options?.apiKey || void 0;
|
|
42866
43747
|
const radfiSigner = options?.radfi?.signRequest;
|
|
42867
|
-
|
|
42868
|
-
this.
|
|
43748
|
+
const mergeOptions = options ? { ...options, apiKey: void 0 } : void 0;
|
|
43749
|
+
this.instanceConfig = mergeOptions ? mergeSodaxConfig(sodaxConfig, mergeOptions) : sodaxConfig;
|
|
43750
|
+
this.backendApi = new BackendApiService(this.instanceConfig.api, logger, { apiKey });
|
|
42869
43751
|
this.api = this.backendApi;
|
|
42870
43752
|
this.config = new ConfigService({
|
|
42871
43753
|
api: this.backendApi,
|
|
42872
43754
|
config: this.instanceConfig,
|
|
42873
|
-
userConfig:
|
|
43755
|
+
userConfig: mergeOptions,
|
|
42874
43756
|
logger,
|
|
42875
43757
|
analytics,
|
|
42876
43758
|
fee,
|
|
43759
|
+
apiKey,
|
|
42877
43760
|
radfiSigner
|
|
42878
43761
|
});
|
|
42879
43762
|
this.hubProvider = new EvmHubProvider({ config: this.config });
|
|
@@ -42967,4 +43850,4 @@ var isPartnerError = isCodeMember(PARTNER_CODES);
|
|
|
42967
43850
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
42968
43851
|
*/
|
|
42969
43852
|
|
|
42970
|
-
export { ALLOWANCE_CHECK_CODES, APPROVE_CODES, AssetService, BACKEND_API_BASE_PATH, BITCOIN_CHAIN_KEYS, BITCOIN_CHAIN_KEYS_SET, BITCOIN_DUST_SATS, BTC_WALLET_ADDRESS_TYPES, BackendApiService, BackendHttpError, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BitcoinSpokeService, BnUSDMigrationService, BridgeApiService, BridgeService, CHAIN_KEYS, CHAIN_LOGO_BASE_URL, CONFIG_VERSION, CREATE_INTENT_CODES, ChainKeys, ChainTypeArr, ClService, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_API_BASE_URL, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, DEFAULT_SPONSORING_API_ENDPOINT, DETAILED_STATUS_NOT_DELIVERED, DexService, EVM_CHAIN_ID_TO_KEY, EVM_CHAIN_KEYS, EVM_CHAIN_KEYS_SET, EVM_SPOKE_ONLY_CHAIN_KEYS, EVM_SPOKE_ONLY_CHAIN_KEYS_SET, Erc20Service, Erc4626Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeService, EvmVaultTokenService, FEE_PERCENTAGE_SCALE, GAS_ESTIMATION_CODES, HALF_RAY, HALF_WAD, HUB_CHAIN_KEY, HookKind, HookService, HttpRelayError, HubVaultSymbols, ICON_CHAIN_KEYS, ICON_CHAIN_KEYS_SET, ICON_TX_RESULT_WAIT_MAX_RETRY, INJECTIVE_CHAIN_KEYS, INJECTIVE_CHAIN_KEYS_SET, INTENT_CHAIN_IDS, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataService, IntentDataType, IntentFilledEventAbi, IntentRelayChainIdToChainKey, IntentsAbi, LOOKUP_CODES, LTV_PRECISION, LendingPoolService, LeverageYieldService, LockupMultiplier, LockupPeriod, LsodaSymbols, LsodaTokens, MAX_UINT256, MigrationService, MintPositionEventAbi, MoneyMarketDataService, MoneyMarketService, NEAR_CHAIN_KEYS, NEAR_CHAIN_KEYS_SET, NEAR_DEFAULT_GAS, NEAR_STORAGE_DEPOSIT, NearSpokeService, PartnerFeeClaimService, PartnerService, Permit2Service, ProtocolIntentsAbi, RAY, RAY_DECIMALS, RELAY_ERROR_CODES, RELAY_FALLBACK_FLOOR_MS, RELAY_REQUEST_TIMEOUT_MS, RadfiApiError, RadfiProvider, RecoveryService, RelayChainIdMap, SECONDS_PER_YEAR, SODAX_ERROR_CODES, SODAX_FEATURES, SOLANA_CHAIN_KEYS, SOLANA_CHAIN_KEYS_SET, SONIC_CHAIN_KEYS, SONIC_CHAIN_KEYS_SET, SPONSORING_API_ERROR_CODES, SPONSORING_API_STELLAR_BASE_PATH, SPONSOR_CONFIG_TTL_MS, STACKS_CHAIN_KEYS, STACKS_CHAIN_KEYS_SET, STELLAR_BASE_RESERVE_TTL_MS, STELLAR_CHAIN_KEYS, STELLAR_CHAIN_KEYS_SET, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, SUI_CHAIN_KEYS, SUI_CHAIN_KEYS_SET, SodaTokens, Sodax, SodaxError, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicSpokeService, SpokeService, SponsoringApiService, SponsoringService, StacksSpokeService, StakingLogic, StakingService, StatATokenAddresses, StellarSpokeService, SuiGrpcTransport, SuiSpokeService, SupportedMigrationTokens, SwapService, SwapsApiService, TOKEN_LOGO_BASE_URL, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, adjustAmountByFee, allowanceCheckFailed, apiConfig, approveFailed, arbitrumSupportedTokens, assetManagerAbi, avalancheSupportedTokens, balnSwapAbi, baseChainInfo, baseSupportedTokens, binomialApproximatedRayPow, bitcoinSupportedTokens, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bridgeConfig, bridgeInvariant, bscSupportedTokens, calcOpReturnOutputVbytes, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, clPoolAbi, clPoolManagerAbi, clPositionManagerAbi, clQuoterAbi, clRouterAbi, clTickLensAbi, classifySponsorError, concentratedLiquidityConfig, connectionAbi, consoleLogger, convertTransactionInstructionToRaw, createInvariant, deepMerge, defaultHookAbi, detectBitcoinAddressType, dexConfig, dexInvariant, dexPools, encodeAddress, encodeBtcPayloadToBytes, encodeContractCalls, erc20Abi, erc4626Abi, estimateBitcoinTxSize, ethereumSupportedTokens, executionFailed, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, gasEstimationFailed, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getAssetManagerIdl, getAssetManagerProgram, getChainKeyFromRelayChainId, getChainType, getCompoundedBalance, getConcentratedLiquidityConfig, getConnectionIdl, getConnectionProgram, getEvmChainKeyByChainId, getEvmViemChain, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getProvider, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeHook, getSpokeHooks, getStagingSolverTokens, getSupportedSolverTokens, getTransactionPackets, getbnUSDToken, hederaSupportedTokens, hexToBigInt, hexToSolanaAddress, hubConfig, hyper, hyperevmSupportedTokens, iconSupportedTokens, injectiveSupportedTokens, intentCreationFailed, isApprovalSupportedChainKeyType, isBackendHttpError, isBalnMigrateParams, isBitcoinChainKey, isBitcoinChainKeyType, isBitcoinWalletProviderType, isBridgeAllowanceCheckError, isBridgeApproveError, isBridgeCreateIntentError, isBridgeError, isBridgeLookupError, isBridgeOrchestrationError, isCodeMember, isDexApproveError, isDexCreateIntentError, isDexError, isEvmChainKey, isEvmChainKeyType, isEvmSpokeChainConfig, isEvmSpokeOnlyChainKey, isEvmSpokeOnlyChainKeyType, isEvmWalletProviderType, isFeatureError, isFillEvent, isHookSupportedToken, isHubChainKey, isHubChainKeyType, isIconAddress, isIconChainKey, isIconChainKeyType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveChainKey, isInjectiveChainKeyType, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isLeverageYieldAllowanceCheckError, isLeverageYieldApproveError, isLeverageYieldCreateIntentError, isLeverageYieldError, isLeverageYieldLookupError, isLeverageYieldPostExecutionError, isLeverageYieldSwapError, isMigrateOrchestrationError, isMigrationAllowanceCheckError, isMigrationApproveError, isMigrationCreateIntentError, isMigrationError, isMigrationLookupError, isMoneyMarketAllowanceCheckError, isMoneyMarketApproveError, isMoneyMarketCreateIntentError, isMoneyMarketError, isMoneyMarketGasEstimationError, isMoneyMarketOrchestrationError, isNativeBitcoinToken, isNativeBitcoinTransfer, isNativeToken, isNearChainKey, isNearChainKeyType, isNewbnUSDChainId, isNewbnUSDToken, isOptionalBitcoinWalletProviderType, isOptionalEvmWalletProviderType, isOptionalStellarWalletProviderType, isPartnerError, isPartnerFeeAmount, isPartnerFeePercentage, isPostExecutionError, isRawDestinationParams, isRecoveryError, isResponseAddressType, isResponseSigningType, isRevertMigrationOrchestrationError, isSodaxError, isSolanaChainKey, isSolanaChainKeyType, isSolanaNativeToken, isSonicChainKey, isSonicChainKeyType, isSpokeApproveParamsEvmSpoke, isSpokeApproveParamsHub, isSpokeApproveParamsStellar, isSpokeChainKey, isSpokeIsAllowanceValidParamsEvmSpoke, isSpokeIsAllowanceValidParamsHub, isSpokeIsAllowanceValidParamsStellar, isSponsoringConfigError, isSponsoringLookupError, isSponsoringOrchestrationError, isStacksChainKey, isStacksChainKeyType, isStakeOrchestrationError, isStakingAllowanceCheckError, isStakingApproveError, isStakingCreateIntentError, isStakingError, isStakingInfoFetchError, isStakingOrchestrationError, isStellarChainKey, isStellarChainKeyType, isStellarWalletProviderType, isSuiChainKey, isSuiChainKeyType, isSupportedBitcoinAddressType, isSwapCreateIntentError, isSwapError, isSwapSupportedToken, isUndefinedOrValidWalletProviderForChainKey, isUnifiedBnUSDMigrateParams, isValidWalletProviderForChainKey, kaiaSupportedTokens, leverageYieldConfig, leverageYieldInvariant, leverageYieldVaults, lightlinkSupportedTokens, lookupFailed, mapRelayFailure, mergeSodaxConfig, messageOf, migrationInvariant, mintPositionParamsAbi, mmInvariant, modifyLiquidityParamsAbi, moneyMarketConfig, moneyMarketReserveAssets, moneyMarketSupportedTokens, nativeToUSD, nearSupportedTokens, newbnUSDSpokeChainIds, noopAnalytics, normalize, normalizeBN, normalizePsbtToBase64, normalizeSignatureToBase64, normalizedToUsd, optimismSupportedTokens, pancakeSwapInfinityDefaultHookAbi, pancakeSwapInfinityPoolManagerAbi, pancakeSwapInfinityPositionManagerAbi, parseToStroops, parseTokenArrayFromJson, partnerInvariant, permit2Abi, polygonSupportedTokens, poolAbi, poolKeyAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, recoveryInvariant, redbellySupportedTokens, relayConfig, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, resolveAnalytics, resolveLogger, retry, reverseEncodeAddress, robinhoodChain, robinhoodSupportedTokens, serializeAddressData, silentLogger, sleep, sodaxConfig, sodaxInvariant, solanaSupportedTokens, solverConfig, sonicSupportedTokens, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainKeysSet, spokeHooks, sponsoringInvariant, stacksSupportedTokens, stagingSwapSupportedTokens, stakedSodaAbi, stakingInvariant, stakingRouterAbi, stataTokenFactoryAbi, stellarSupportedTokens, submitTransaction, suiSupportedTokens, supportedSpokeChains, supportedTokensByChain, swapExactInSingleParamsAbi, swapInvariant, swapSupportedTokens, swapsConfig, toCreateBridgeIntentParamsV2, toSuiExecutionResult, toSuiExecutionStatus, toSuiPaginatedCoins, tokenLogo, tokenLogoSlug, uiPoolDataAbi, universalRouterAbi, unknownFailed, usesBip322MessageSigning, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, verifyFailed, wadToRay, waitForStacksTransaction, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
43853
|
+
export { ALLOWANCE_CHECK_CODES, APPROVE_CODES, AssetService, BACKEND_API_BASE_PATH, BITCOIN_CHAIN_KEYS, BITCOIN_CHAIN_KEYS_SET, BITCOIN_DUST_SATS, BTC_WALLET_ADDRESS_TYPES, BackendApiService, BackendHttpError, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BitcoinSpokeService, BnUSDMigrationService, BridgeApiService, BridgeService, CHAIN_KEYS, CHAIN_LOGO_BASE_URL, CONFIG_VERSION, CREATE_INTENT_CODES, ChainKeys, ChainTypeArr, ClService, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_API_BASE_URL, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, DEFAULT_SPONSORING_API_ENDPOINT, DETAILED_STATUS_NOT_DELIVERED, DexService, EVM_CHAIN_ID_TO_KEY, EVM_CHAIN_KEYS, EVM_CHAIN_KEYS_SET, EVM_SPOKE_ONLY_CHAIN_KEYS, EVM_SPOKE_ONLY_CHAIN_KEYS_SET, Erc20Service, Erc4626Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeService, EvmVaultTokenService, FEE_PERCENTAGE_SCALE, GAS_ESTIMATION_CODES, HALF_RAY, HALF_WAD, HUB_CHAIN_KEY, HookKind, HookService, HttpRelayError, HubVaultSymbols, ICON_CHAIN_KEYS, ICON_CHAIN_KEYS_SET, ICON_TX_RESULT_WAIT_MAX_RETRY, INJECTIVE_CHAIN_KEYS, INJECTIVE_CHAIN_KEYS_SET, INTENT_CHAIN_IDS, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataService, IntentDataType, IntentFilledEventAbi, IntentRelayChainIdToChainKey, IntentsAbi, LOOKUP_CODES, LTV_PRECISION, LendingPoolService, LeverageYieldService, LockupMultiplier, LockupPeriod, LsodaSymbols, LsodaTokens, MAX_UINT256, MigrationService, MintPositionEventAbi, MoneyMarketDataService, MoneyMarketService, NEAR_CHAIN_KEYS, NEAR_CHAIN_KEYS_SET, NEAR_DEFAULT_GAS, NEAR_STORAGE_DEPOSIT, NearSpokeService, ORACLE_CANDLE_INTERVALS, PartnerFeeClaimService, PartnerService, Permit2Service, ProtocolIntentsAbi, RAY, RAY_DECIMALS, RELAY_ERROR_CODES, RELAY_FALLBACK_FLOOR_MS, RELAY_REQUEST_TIMEOUT_MS, RadfiApiError, RadfiProvider, RecoveryService, RelayChainIdMap, SECONDS_PER_YEAR, SODAX_ERROR_CODES, SODAX_FEATURES, SOLANA_CHAIN_KEYS, SOLANA_CHAIN_KEYS_SET, SONIC_CHAIN_KEYS, SONIC_CHAIN_KEYS_SET, SPEED_TIER_SECONDS, SPEED_TIER_THRESHOLDS, SPONSORING_API_ERROR_CODES, SPONSORING_API_STELLAR_BASE_PATH, SPONSOR_CONFIG_TTL_MS, STACKS_CHAIN_KEYS, STACKS_CHAIN_KEYS_SET, STELLAR_BASE_RESERVE_TTL_MS, STELLAR_CHAIN_KEYS, STELLAR_CHAIN_KEYS_SET, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, SUI_CHAIN_KEYS, SUI_CHAIN_KEYS_SET, SodaTokens, Sodax, SodaxError, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicSpokeService, SpokeService, SponsoringApiService, SponsoringService, StacksSpokeService, StakingLogic, StakingService, StatATokenAddresses, StellarSpokeService, SuiGrpcTransport, SuiSpokeService, SupportedMigrationTokens, SwapService, SwapsApiService, TOKEN_LOGO_BASE_URL, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, adjustAmountByFee, allowanceCheckFailed, apiConfig, approveFailed, arbitrumSupportedTokens, assetManagerAbi, avalancheSupportedTokens, balnSwapAbi, baseChainInfo, baseSupportedTokens, binomialApproximatedRayPow, bitcoinSupportedTokens, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bridgeConfig, bridgeInvariant, bscSupportedTokens, calcOpReturnOutputVbytes, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, clPoolAbi, clPoolManagerAbi, clPositionManagerAbi, clQuoterAbi, clRouterAbi, clTickLensAbi, classifySponsorError, concentratedLiquidityConfig, connectionAbi, consoleLogger, convertTransactionInstructionToRaw, createBalanceCollector, createInvariant, deepMerge, defaultHookAbi, detectBitcoinAddressType, dexConfig, dexInvariant, dexPools, encodeAddress, encodeBtcPayloadToBytes, encodeContractCalls, erc20Abi, erc4626Abi, estimateBitcoinTxSize, estimateSwapSpeedTier, ethereumSupportedTokens, executionFailed, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, gasEstimationFailed, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getAssetManagerIdl, getAssetManagerProgram, getChainKeyFromRelayChainId, getChainType, getCompoundedBalance, getConcentratedLiquidityConfig, getConnectionIdl, getConnectionProgram, getEvmChainKeyByChainId, getEvmViemChain, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getProvider, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeHook, getSpokeHooks, getStagingSolverTokens, getSupportedSolverTokens, getTransactionPackets, getbnUSDToken, hederaSupportedTokens, hexToBigInt, hexToSolanaAddress, hubConfig, hyper, hyperevmSupportedTokens, iconSupportedTokens, injectiveSupportedTokens, intentCreationFailed, isApprovalSupportedChainKeyType, isAuthFailure, isAuthStatus, isBackendHttpError, isBalnMigrateParams, isBitcoinChainKey, isBitcoinChainKeyType, isBitcoinWalletProviderType, isBridgeAllowanceCheckError, isBridgeApproveError, isBridgeCreateIntentError, isBridgeError, isBridgeLookupError, isBridgeOrchestrationError, isCodeMember, isDexApproveError, isDexCreateIntentError, isDexError, isEvmChainKey, isEvmChainKeyType, isEvmSpokeChainConfig, isEvmSpokeOnlyChainKey, isEvmSpokeOnlyChainKeyType, isEvmWalletProviderType, isFeatureError, isFillEvent, isHookSupportedToken, isHubChainKey, isHubChainKeyType, isIconAddress, isIconChainKey, isIconChainKeyType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveChainKey, isInjectiveChainKeyType, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isLeverageYieldAllowanceCheckError, isLeverageYieldApproveError, isLeverageYieldCreateIntentError, isLeverageYieldError, isLeverageYieldLookupError, isLeverageYieldPostExecutionError, isLeverageYieldSwapError, isMigrateOrchestrationError, isMigrationAllowanceCheckError, isMigrationApproveError, isMigrationCreateIntentError, isMigrationError, isMigrationLookupError, isMoneyMarketAllowanceCheckError, isMoneyMarketApproveError, isMoneyMarketCreateIntentError, isMoneyMarketError, isMoneyMarketGasEstimationError, isMoneyMarketOrchestrationError, isNativeBitcoinToken, isNativeBitcoinTransfer, isNativeToken, isNearChainKey, isNearChainKeyType, isNewbnUSDChainId, isNewbnUSDToken, isOptionalBitcoinWalletProviderType, isOptionalEvmWalletProviderType, isOptionalStellarWalletProviderType, isOracleCandleInterval, isPartnerError, isPartnerFeeAmount, isPartnerFeePercentage, isPostExecutionError, isRawDestinationParams, isRecoveryError, isResponseAddressType, isResponseSigningType, isRevertMigrationOrchestrationError, isSodaxError, isSolanaChainKey, isSolanaChainKeyType, isSolanaNativeToken, isSonicChainKey, isSonicChainKeyType, isSpokeApproveParamsEvmSpoke, isSpokeApproveParamsHub, isSpokeApproveParamsStellar, isSpokeChainKey, isSpokeIsAllowanceValidParamsEvmSpoke, isSpokeIsAllowanceValidParamsHub, isSpokeIsAllowanceValidParamsStellar, isSponsoringConfigError, isSponsoringLookupError, isSponsoringOrchestrationError, isStacksChainKey, isStacksChainKeyType, isStakeOrchestrationError, isStakingAllowanceCheckError, isStakingApproveError, isStakingCreateIntentError, isStakingError, isStakingInfoFetchError, isStakingOrchestrationError, isStellarChainKey, isStellarChainKeyType, isStellarWalletProviderType, isSuiChainKey, isSuiChainKeyType, isSupportedBitcoinAddressType, isSwapCreateIntentError, isSwapError, isSwapSupportedToken, isUndefinedOrValidWalletProviderForChainKey, isUnifiedBnUSDMigrateParams, isValidWalletProviderForChainKey, kaiaSupportedTokens, leverageYieldConfig, leverageYieldInvariant, leverageYieldVaults, lightlinkSupportedTokens, lookupFailed, mapRelayFailure, mergeSodaxConfig, messageOf, migrationInvariant, mintPositionParamsAbi, mmInvariant, modifyLiquidityParamsAbi, moneyMarketConfig, moneyMarketReserveAssets, moneyMarketSupportedTokens, nativeToUSD, nearSupportedTokens, newbnUSDSpokeChainIds, noopAnalytics, normalize, normalizeBN, normalizePsbtToBase64, normalizeSignatureToBase64, normalizedToUsd, optimismSupportedTokens, pancakeSwapInfinityDefaultHookAbi, pancakeSwapInfinityPoolManagerAbi, pancakeSwapInfinityPositionManagerAbi, parseToStroops, parseTokenArrayFromJson, partnerInvariant, permit2Abi, polygonSupportedTokens, poolAbi, poolKeyAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, recoveryInvariant, redbellySupportedTokens, relayConfig, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, resolveAnalytics, resolveLogger, retry, reverseEncodeAddress, robinhoodChain, robinhoodSupportedTokens, serializeAddressData, settleWalletBalances, silentLogger, sleep, sodaxConfig, sodaxInvariant, solanaSupportedTokens, solverConfig, sonicSupportedTokens, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainKeysSet, spokeHooks, sponsoringInvariant, stacksSupportedTokens, stagingSwapSupportedTokens, stakedSodaAbi, stakingInvariant, stakingRouterAbi, stataTokenFactoryAbi, stellarSupportedTokens, submitTransaction, suiSupportedTokens, supportedSpokeChains, supportedTokensByChain, swapExactInSingleParamsAbi, swapInvariant, swapSupportedTokens, swapsConfig, toCreateBridgeIntentParamsV2, toSuiExecutionResult, toSuiExecutionStatus, toSuiPaginatedCoins, tokenLogo, tokenLogoSlug, uiPoolDataAbi, universalRouterAbi, unknownFailed, usesBip322MessageSigning, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, verifyFailed, wadToRay, waitForStacksTransaction, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|