@sodax/sdk 1.2.3-beta → 1.2.5-beta
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/dist/index.cjs +137 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -7
- package/dist/index.d.ts +52 -7
- package/dist/index.mjs +137 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -10443,13 +10443,12 @@ var MoneyMarketDataService = class {
|
|
|
10443
10443
|
}
|
|
10444
10444
|
/**
|
|
10445
10445
|
* Get the user reserves data
|
|
10446
|
-
* @param
|
|
10446
|
+
* @param spokeChainId - The spoke chain ID
|
|
10447
|
+
* @param userAddress - The user's wallet address on the spoke chain
|
|
10447
10448
|
* @returns {Promise<readonly [readonly UserReserveData[], number]>} - The user reserves data
|
|
10448
10449
|
*/
|
|
10449
|
-
async getUserReservesData(
|
|
10450
|
-
const
|
|
10451
|
-
const spokeChainId = spokeProvider.chainConfig.chain.id;
|
|
10452
|
-
const hubWalletAddress = await HubService.getUserHubWalletAddress(walletAddress, spokeChainId, this.hubProvider);
|
|
10450
|
+
async getUserReservesData(spokeChainId, userAddress) {
|
|
10451
|
+
const hubWalletAddress = await HubService.getUserHubWalletAddress(userAddress, spokeChainId, this.hubProvider);
|
|
10453
10452
|
return this.uiPoolDataProviderService.getUserReservesData(hubWalletAddress);
|
|
10454
10453
|
}
|
|
10455
10454
|
/**
|
|
@@ -10475,13 +10474,12 @@ var MoneyMarketDataService = class {
|
|
|
10475
10474
|
}
|
|
10476
10475
|
/**
|
|
10477
10476
|
* Get the user reserves humanized
|
|
10478
|
-
* @param
|
|
10477
|
+
* @param spokeChainId - The spoke chain ID
|
|
10478
|
+
* @param userAddress - The user's wallet address on the spoke chain
|
|
10479
10479
|
* @returns {Promise<{userReserves: UserReserveDataHumanized[], userEmodeCategoryId: number}>} - The user reserves humanized
|
|
10480
10480
|
*/
|
|
10481
|
-
async getUserReservesHumanized(
|
|
10482
|
-
const
|
|
10483
|
-
const spokeChainId = spokeProvider.chainConfig.chain.id;
|
|
10484
|
-
const hubWalletAddress = await HubService.getUserHubWalletAddress(walletAddress, spokeChainId, this.hubProvider);
|
|
10481
|
+
async getUserReservesHumanized(spokeChainId, userAddress) {
|
|
10482
|
+
const hubWalletAddress = await HubService.getUserHubWalletAddress(userAddress, spokeChainId, this.hubProvider);
|
|
10485
10483
|
return this.uiPoolDataProviderService.getUserReservesHumanized(hubWalletAddress);
|
|
10486
10484
|
}
|
|
10487
10485
|
/**
|
|
@@ -10767,6 +10765,33 @@ var StellarSpokeService = class _StellarSpokeService {
|
|
|
10767
10765
|
raw
|
|
10768
10766
|
);
|
|
10769
10767
|
}
|
|
10768
|
+
static async waitForTransactionRaw(params) {
|
|
10769
|
+
const defaultParams = {
|
|
10770
|
+
pollingTimeout: 750,
|
|
10771
|
+
maxAttempts: 40
|
|
10772
|
+
};
|
|
10773
|
+
const { pollingTimeout, maxAttempts, sorobanRpcConfig, txHash } = { ...defaultParams, ...params };
|
|
10774
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
10775
|
+
try {
|
|
10776
|
+
const sorobanServer = new CustomSorobanServer(sorobanRpcConfig.sorobanRpcUrl, sorobanRpcConfig.customHeaders);
|
|
10777
|
+
const tx = await sorobanServer.getTransaction(txHash);
|
|
10778
|
+
if (tx && tx.status === "SUCCESS") {
|
|
10779
|
+
return { ok: true, value: true };
|
|
10780
|
+
}
|
|
10781
|
+
if (tx && tx.status === "FAILED") {
|
|
10782
|
+
return { ok: false, error: new Error(`Transaction failed: ${JSON.stringify(tx)}`) };
|
|
10783
|
+
}
|
|
10784
|
+
if (tx && tx.status === "NOT_FOUND") {
|
|
10785
|
+
await sleep(pollingTimeout);
|
|
10786
|
+
continue;
|
|
10787
|
+
}
|
|
10788
|
+
await sleep(pollingTimeout);
|
|
10789
|
+
} catch (err) {
|
|
10790
|
+
await sleep(pollingTimeout);
|
|
10791
|
+
}
|
|
10792
|
+
}
|
|
10793
|
+
return { ok: false, error: new Error("Transaction was not confirmed within the max attempts") };
|
|
10794
|
+
}
|
|
10770
10795
|
static async waitForTransaction(spokeProvider, txHash, pollingTimeout = 750, maxAttempts = 40) {
|
|
10771
10796
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
10772
10797
|
try {
|
|
@@ -11576,6 +11601,42 @@ var EvmSpokeService = class _EvmSpokeService {
|
|
|
11576
11601
|
}
|
|
11577
11602
|
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
11578
11603
|
}
|
|
11604
|
+
static async waitForTransactionReceipt(params) {
|
|
11605
|
+
try {
|
|
11606
|
+
const { txHash, chainId, rpcUrl, confirmations, pollingInterval, retryCount, retryDelay, timeout } = params;
|
|
11607
|
+
const evmChain = getEvmViemChain(chainId);
|
|
11608
|
+
const publicClient = viem.createPublicClient({
|
|
11609
|
+
chain: evmChain,
|
|
11610
|
+
transport: viem.http(rpcUrl ?? evmChain.rpcUrls.default.http[0])
|
|
11611
|
+
});
|
|
11612
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
11613
|
+
hash: txHash,
|
|
11614
|
+
confirmations,
|
|
11615
|
+
pollingInterval,
|
|
11616
|
+
retryCount,
|
|
11617
|
+
retryDelay,
|
|
11618
|
+
timeout
|
|
11619
|
+
});
|
|
11620
|
+
const response = {
|
|
11621
|
+
...receipt,
|
|
11622
|
+
transactionIndex: receipt.transactionIndex.toString(),
|
|
11623
|
+
blockNumber: receipt.blockNumber.toString(),
|
|
11624
|
+
cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
|
|
11625
|
+
gasUsed: receipt.gasUsed.toString(),
|
|
11626
|
+
contractAddress: receipt.contractAddress?.toString() ?? null,
|
|
11627
|
+
logs: receipt.logs.map((log) => ({
|
|
11628
|
+
...log,
|
|
11629
|
+
blockNumber: log.blockNumber.toString(),
|
|
11630
|
+
logIndex: log.logIndex.toString(),
|
|
11631
|
+
transactionIndex: log.transactionIndex.toString()
|
|
11632
|
+
})),
|
|
11633
|
+
effectiveGasPrice: receipt.effectiveGasPrice?.toString()
|
|
11634
|
+
};
|
|
11635
|
+
return { ok: true, value: response };
|
|
11636
|
+
} catch (error) {
|
|
11637
|
+
return { ok: false, error: new Error(`Failed to get transaction receipt: ${JSON.stringify(error)}`) };
|
|
11638
|
+
}
|
|
11639
|
+
}
|
|
11579
11640
|
};
|
|
11580
11641
|
|
|
11581
11642
|
// src/shared/utils/icon-utils.ts
|
|
@@ -12037,7 +12098,40 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
12037
12098
|
}
|
|
12038
12099
|
return spokeProvider.walletProvider.sendTransaction(serializedTransaction);
|
|
12039
12100
|
}
|
|
12040
|
-
static async
|
|
12101
|
+
static async waitForConfirmationRaw(params) {
|
|
12102
|
+
try {
|
|
12103
|
+
const defaultParams = {
|
|
12104
|
+
commitment: "finalized",
|
|
12105
|
+
timeoutMs: 6e4,
|
|
12106
|
+
// total time to wait
|
|
12107
|
+
pollingTimeout: 750
|
|
12108
|
+
// 750ms retry interval
|
|
12109
|
+
};
|
|
12110
|
+
const { rpcUrl, signature, commitment, timeoutMs, pollingTimeout } = { ...defaultParams, ...params };
|
|
12111
|
+
const connection = new web3_js.Connection(rpcUrl, commitment);
|
|
12112
|
+
const deadline = Date.now() + timeoutMs;
|
|
12113
|
+
while (Date.now() < deadline) {
|
|
12114
|
+
try {
|
|
12115
|
+
const tx = await connection.getTransaction(signature, { commitment, maxSupportedTransactionVersion: 0 });
|
|
12116
|
+
if (tx) {
|
|
12117
|
+
if (tx.meta?.err) {
|
|
12118
|
+
return { ok: false, error: new Error(JSON.stringify(tx.meta.err)) };
|
|
12119
|
+
}
|
|
12120
|
+
return { ok: true, value: true };
|
|
12121
|
+
}
|
|
12122
|
+
} catch {
|
|
12123
|
+
}
|
|
12124
|
+
await new Promise((r) => setTimeout(r, pollingTimeout));
|
|
12125
|
+
}
|
|
12126
|
+
return {
|
|
12127
|
+
ok: false,
|
|
12128
|
+
error: new Error(`Timed out after ${timeoutMs}ms waiting for ${commitment} confirmation for ${signature}`)
|
|
12129
|
+
};
|
|
12130
|
+
} catch (error) {
|
|
12131
|
+
return { ok: false, error: new Error(`Failed to get transaction confirmation: ${JSON.stringify(error)}`) };
|
|
12132
|
+
}
|
|
12133
|
+
}
|
|
12134
|
+
static async waitForConfirmation(spokeProvider, signature, commitment = "finalized", timeoutMs = 6e4, pollingTimeout = 750) {
|
|
12041
12135
|
try {
|
|
12042
12136
|
const connection = new web3_js.Connection(spokeProvider.chainConfig.rpcUrl, commitment);
|
|
12043
12137
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -12052,7 +12146,7 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
12052
12146
|
}
|
|
12053
12147
|
} catch {
|
|
12054
12148
|
}
|
|
12055
|
-
await new Promise((r) => setTimeout(r,
|
|
12149
|
+
await new Promise((r) => setTimeout(r, pollingTimeout));
|
|
12056
12150
|
}
|
|
12057
12151
|
return {
|
|
12058
12152
|
ok: false,
|
|
@@ -12474,6 +12568,31 @@ var SpokeService = class _SpokeService {
|
|
|
12474
12568
|
value: true
|
|
12475
12569
|
};
|
|
12476
12570
|
}
|
|
12571
|
+
/**
|
|
12572
|
+
* Verifies the transaction hash for the spoke chain to exist on chain.
|
|
12573
|
+
* @param {VerifyTxHashRawConfig} params - The parameters for the verification.
|
|
12574
|
+
* @returns {Promise<Result<boolean>>} A promise that resolves to the result of the verification.
|
|
12575
|
+
*/
|
|
12576
|
+
static async verifyTxHashRaw(params) {
|
|
12577
|
+
switch (params.chainType) {
|
|
12578
|
+
case "SOLANA":
|
|
12579
|
+
return SolanaSpokeService.waitForConfirmationRaw(params);
|
|
12580
|
+
case "STELLAR":
|
|
12581
|
+
return StellarSpokeService.waitForTransactionRaw(params);
|
|
12582
|
+
case "EVM": {
|
|
12583
|
+
const result = await EvmSpokeService.waitForTransactionReceipt(params);
|
|
12584
|
+
if (!result.ok) {
|
|
12585
|
+
return result;
|
|
12586
|
+
}
|
|
12587
|
+
if (result.value.status && result.value.status !== "0x1") {
|
|
12588
|
+
return { ok: false, error: new Error("Transaction reverted") };
|
|
12589
|
+
}
|
|
12590
|
+
return { ok: true, value: true };
|
|
12591
|
+
}
|
|
12592
|
+
default:
|
|
12593
|
+
return { ok: true, value: true };
|
|
12594
|
+
}
|
|
12595
|
+
}
|
|
12477
12596
|
};
|
|
12478
12597
|
var IntentDataType = /* @__PURE__ */ ((IntentDataType2) => {
|
|
12479
12598
|
IntentDataType2[IntentDataType2["FEE"] = 1] = "FEE";
|
|
@@ -15400,6 +15519,11 @@ var PartnerFeeClaimService = class {
|
|
|
15400
15519
|
invariant6__default.default(isSonicSpokeProviderType(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15401
15520
|
invariant6__default.default(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15402
15521
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15522
|
+
const outputToken = params.dstChain !== this.hubProvider.chainConfig.chain.id ? this.hubProvider.configService.getHubAssetInfo(params.dstChain, params.outputToken)?.asset : params.outputToken;
|
|
15523
|
+
invariant6__default.default(
|
|
15524
|
+
outputToken,
|
|
15525
|
+
`hub asset not found for spoke chain token (params.outputToken): ${params.outputToken} with chain id: ${params.dstChain}`
|
|
15526
|
+
);
|
|
15403
15527
|
const rawTx = {
|
|
15404
15528
|
from: walletAddress,
|
|
15405
15529
|
to: this.config.protocolIntentsContract,
|
|
@@ -15408,7 +15532,7 @@ var PartnerFeeClaimService = class {
|
|
|
15408
15532
|
abi: ProtocolIntentsAbi,
|
|
15409
15533
|
functionName: "setAutoSwapPreferences",
|
|
15410
15534
|
args: [
|
|
15411
|
-
|
|
15535
|
+
outputToken,
|
|
15412
15536
|
BigInt(types.getIntentRelayChainId(params.dstChain)),
|
|
15413
15537
|
encodeAddress(params.dstChain, params.dstAddress)
|
|
15414
15538
|
]
|