@sodax/sdk 1.2.6-beta → 1.3.0-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 +413 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -15
- package/dist/index.d.ts +117 -15
- package/dist/index.mjs +407 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -13,6 +13,7 @@ var bcs = require('@mysten/sui/bcs');
|
|
|
13
13
|
var client = require('@mysten/sui/client');
|
|
14
14
|
var transactions = require('@mysten/sui/transactions');
|
|
15
15
|
var stellarSdk = require('@stellar/stellar-sdk');
|
|
16
|
+
var nearApiJs = require('near-api-js');
|
|
16
17
|
var BigNumber4 = require('bignumber.js');
|
|
17
18
|
var coreProtoTs = require('@injectivelabs/core-proto-ts');
|
|
18
19
|
var rlp = require('rlp');
|
|
@@ -8627,6 +8628,186 @@ var StellarSpokeProvider = class extends StellarBaseSpokeProvider {
|
|
|
8627
8628
|
return viem.toHex(Buffer.from(stellaraddress, "hex"));
|
|
8628
8629
|
}
|
|
8629
8630
|
};
|
|
8631
|
+
var NearBaseSpokeProvider = class {
|
|
8632
|
+
chainConfig;
|
|
8633
|
+
rpcProvider;
|
|
8634
|
+
constructor(chainConfig) {
|
|
8635
|
+
this.chainConfig = chainConfig;
|
|
8636
|
+
this.rpcProvider = new nearApiJs.JsonRpcProvider({ url: chainConfig.rpcUrl });
|
|
8637
|
+
}
|
|
8638
|
+
/**
|
|
8639
|
+
* Waits for a NEAR transaction to reach finality.
|
|
8640
|
+
*
|
|
8641
|
+
* Uses the RPC `waitUntil: 'FINAL'` long-polling mode, which blocks server-side
|
|
8642
|
+
* until the transaction is finalized. Retries are only for transient network errors
|
|
8643
|
+
* (e.g. connection resets, DNS failures, timeouts). A successful RPC response —
|
|
8644
|
+
* whether success or failure — returns immediately without further retries.
|
|
8645
|
+
*/
|
|
8646
|
+
static async waitForTransaction(txHash, accountId, rpcProvider, maxRetries = 3, retryDelay = 1e3) {
|
|
8647
|
+
for (let retry2 = 0; retry2 <= maxRetries; retry2++) {
|
|
8648
|
+
try {
|
|
8649
|
+
const outcome = await rpcProvider.viewTransactionStatus({ txHash, accountId, waitUntil: "FINAL" });
|
|
8650
|
+
const status = outcome?.status;
|
|
8651
|
+
if (status && ("SuccessValue" in status || "SuccessReceiptId" in status)) {
|
|
8652
|
+
return { status: "success" };
|
|
8653
|
+
}
|
|
8654
|
+
if (status && "Failure" in status) {
|
|
8655
|
+
return { status: "failure", failure: status.Failure };
|
|
8656
|
+
}
|
|
8657
|
+
if (retry2 < maxRetries) {
|
|
8658
|
+
await sleep(retryDelay);
|
|
8659
|
+
}
|
|
8660
|
+
} catch {
|
|
8661
|
+
if (retry2 < maxRetries) {
|
|
8662
|
+
await sleep(retryDelay);
|
|
8663
|
+
}
|
|
8664
|
+
}
|
|
8665
|
+
}
|
|
8666
|
+
throw new Error(`NEAR transaction ${txHash} was not confirmed after ${maxRetries} retries`);
|
|
8667
|
+
}
|
|
8668
|
+
queryContract(contractId, method, args) {
|
|
8669
|
+
return this.rpcProvider.callFunction({ contractId, method, args });
|
|
8670
|
+
}
|
|
8671
|
+
async getRawTransaction(params) {
|
|
8672
|
+
throw new Error("Not implemented");
|
|
8673
|
+
}
|
|
8674
|
+
transfer(params, deposit = BigInt("1"), gas = BigInt("300000000000000")) {
|
|
8675
|
+
if (this.isNative(params.token)) {
|
|
8676
|
+
deposit = BigInt(params.amount);
|
|
8677
|
+
return this.depositNear(params, deposit, gas);
|
|
8678
|
+
}
|
|
8679
|
+
return this.depositToken(params, deposit, gas);
|
|
8680
|
+
}
|
|
8681
|
+
depositNear(params, deposit, gas) {
|
|
8682
|
+
return this.getRawTransaction({
|
|
8683
|
+
contractId: this.chainConfig.addresses.assetManager,
|
|
8684
|
+
method: "transfer",
|
|
8685
|
+
args: { to: params.to, amount: params.amount, data: params.data },
|
|
8686
|
+
deposit,
|
|
8687
|
+
gas
|
|
8688
|
+
});
|
|
8689
|
+
}
|
|
8690
|
+
depositToken(params, deposit, gas) {
|
|
8691
|
+
return this.getRawTransaction({
|
|
8692
|
+
contractId: params.token,
|
|
8693
|
+
method: "ft_transfer_call",
|
|
8694
|
+
args: {
|
|
8695
|
+
receiver_id: this.chainConfig.addresses.assetManager,
|
|
8696
|
+
amount: params.amount.toString(),
|
|
8697
|
+
memo: "",
|
|
8698
|
+
msg: JSON.stringify({
|
|
8699
|
+
to: params.to,
|
|
8700
|
+
data: params.data
|
|
8701
|
+
})
|
|
8702
|
+
},
|
|
8703
|
+
deposit,
|
|
8704
|
+
gas
|
|
8705
|
+
});
|
|
8706
|
+
}
|
|
8707
|
+
sendMessage(params, deposit = BigInt("0"), gas = BigInt("300000000000000")) {
|
|
8708
|
+
return this.getRawTransaction({
|
|
8709
|
+
contractId: this.chainConfig.addresses.connection,
|
|
8710
|
+
method: "send_message",
|
|
8711
|
+
args: params,
|
|
8712
|
+
deposit,
|
|
8713
|
+
gas
|
|
8714
|
+
});
|
|
8715
|
+
}
|
|
8716
|
+
isNative(token) {
|
|
8717
|
+
return token === "NEAR";
|
|
8718
|
+
}
|
|
8719
|
+
async getBalance(token) {
|
|
8720
|
+
if (this.isNative(token)) {
|
|
8721
|
+
return this.queryContract(this.chainConfig.addresses.assetManager, "get_balance", {});
|
|
8722
|
+
}
|
|
8723
|
+
return this.queryContract(token, "ft_balance_of", {
|
|
8724
|
+
account_id: this.chainConfig.addresses.assetManager
|
|
8725
|
+
});
|
|
8726
|
+
}
|
|
8727
|
+
async getRateLimit(token) {
|
|
8728
|
+
const res = await this.queryContract(this.chainConfig.addresses.rateLimit, "get_rate_limit", {
|
|
8729
|
+
token
|
|
8730
|
+
});
|
|
8731
|
+
if (res == null || res === void 0) {
|
|
8732
|
+
return {
|
|
8733
|
+
maxAvailable: 0,
|
|
8734
|
+
available: 0,
|
|
8735
|
+
ratePerSecond: 0
|
|
8736
|
+
};
|
|
8737
|
+
}
|
|
8738
|
+
return {
|
|
8739
|
+
maxAvailable: res.max_available,
|
|
8740
|
+
available: res.available,
|
|
8741
|
+
ratePerSecond: res.rate_per_second
|
|
8742
|
+
};
|
|
8743
|
+
}
|
|
8744
|
+
toFillIntent(fillData) {
|
|
8745
|
+
return {
|
|
8746
|
+
amount: fillData.amount.toString(),
|
|
8747
|
+
fill_id: fillData.fill_id.toString(),
|
|
8748
|
+
intent_hash: Array.from(viem.fromHex(fillData.intent_hash, "bytes")),
|
|
8749
|
+
receiver: Array.from(Buffer.from(fillData.receiver, "utf-8")),
|
|
8750
|
+
solver: Array.from(viem.fromHex(fillData.solver, "bytes")),
|
|
8751
|
+
token: Array.from(Buffer.from(fillData.token, "utf-8"))
|
|
8752
|
+
};
|
|
8753
|
+
}
|
|
8754
|
+
async fillIntent(fillData, deposit = BigInt("1"), gas = BigInt("300000000000000")) {
|
|
8755
|
+
if (this.isNative(fillData.token)) {
|
|
8756
|
+
deposit = BigInt(fillData.amount);
|
|
8757
|
+
return this.getRawTransaction({
|
|
8758
|
+
contractId: this.chainConfig.addresses.intentFiller,
|
|
8759
|
+
method: "fill_intent",
|
|
8760
|
+
args: { fill: this.toFillIntent(fillData) },
|
|
8761
|
+
deposit,
|
|
8762
|
+
gas
|
|
8763
|
+
});
|
|
8764
|
+
}
|
|
8765
|
+
return this.getRawTransaction({
|
|
8766
|
+
contractId: fillData.token,
|
|
8767
|
+
method: "ft_transfer_call",
|
|
8768
|
+
args: {
|
|
8769
|
+
receiver_id: this.chainConfig.addresses.intentFiller,
|
|
8770
|
+
amount: fillData.amount.toString(),
|
|
8771
|
+
memo: "",
|
|
8772
|
+
msg: JSON.stringify(this.toFillIntent(fillData))
|
|
8773
|
+
},
|
|
8774
|
+
deposit,
|
|
8775
|
+
gas
|
|
8776
|
+
});
|
|
8777
|
+
}
|
|
8778
|
+
};
|
|
8779
|
+
var NearSpokeProvider = class extends NearBaseSpokeProvider {
|
|
8780
|
+
walletProvider;
|
|
8781
|
+
constructor(walletProvider, chainConfig) {
|
|
8782
|
+
super(chainConfig);
|
|
8783
|
+
this.walletProvider = walletProvider;
|
|
8784
|
+
}
|
|
8785
|
+
async submit(transaction) {
|
|
8786
|
+
return await this.walletProvider.signAndSubmitTxn(transaction);
|
|
8787
|
+
}
|
|
8788
|
+
async getRawTransaction(params) {
|
|
8789
|
+
return {
|
|
8790
|
+
signerId: await this.walletProvider.getWalletAddress(),
|
|
8791
|
+
params
|
|
8792
|
+
};
|
|
8793
|
+
}
|
|
8794
|
+
};
|
|
8795
|
+
var NearRawSpokeProvider = class extends NearBaseSpokeProvider {
|
|
8796
|
+
walletProvider;
|
|
8797
|
+
raw = true;
|
|
8798
|
+
constructor(chainConfig, walletAddress) {
|
|
8799
|
+
super(chainConfig);
|
|
8800
|
+
this.walletProvider = {
|
|
8801
|
+
getWalletAddress: async () => walletAddress
|
|
8802
|
+
};
|
|
8803
|
+
}
|
|
8804
|
+
async getRawTransaction(params) {
|
|
8805
|
+
return {
|
|
8806
|
+
signerId: await this.walletProvider.getWalletAddress(),
|
|
8807
|
+
params
|
|
8808
|
+
};
|
|
8809
|
+
}
|
|
8810
|
+
};
|
|
8630
8811
|
var BigNumberZeroDecimal = BigNumber4.BigNumber.clone({
|
|
8631
8812
|
DECIMAL_PLACES: 0,
|
|
8632
8813
|
ROUNDING_MODE: BigNumber4.BigNumber.ROUND_DOWN
|
|
@@ -12157,6 +12338,159 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
12157
12338
|
}
|
|
12158
12339
|
}
|
|
12159
12340
|
};
|
|
12341
|
+
var NearSpokeService = class _NearSpokeService {
|
|
12342
|
+
constructor() {
|
|
12343
|
+
}
|
|
12344
|
+
/**
|
|
12345
|
+
* Deposit tokens to the spoke chain.
|
|
12346
|
+
* @param {CWSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
12347
|
+
* @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
12348
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
12349
|
+
* @param {boolean} raw - The return type raw or just transaction hash
|
|
12350
|
+
* @returns {PromiseNearTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
12351
|
+
*/
|
|
12352
|
+
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
12353
|
+
const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
12354
|
+
spokeProvider.chainConfig.chain.id,
|
|
12355
|
+
viem.toHex(Buffer.from(params.from, "utf-8")),
|
|
12356
|
+
hubProvider
|
|
12357
|
+
);
|
|
12358
|
+
const txn = await spokeProvider.transfer({
|
|
12359
|
+
token: params.token,
|
|
12360
|
+
to: Array.from(viem.fromHex(userWallet, "bytes")),
|
|
12361
|
+
amount: params.amount.toString(),
|
|
12362
|
+
data: Array.from(viem.fromHex(params.data, "bytes"))
|
|
12363
|
+
});
|
|
12364
|
+
if (raw || isNearRawSpokeProvider(spokeProvider)) {
|
|
12365
|
+
return txn;
|
|
12366
|
+
}
|
|
12367
|
+
const hash = await spokeProvider.submit(txn);
|
|
12368
|
+
return hash;
|
|
12369
|
+
}
|
|
12370
|
+
/**
|
|
12371
|
+
* Get the balance of the token in the spoke chain.
|
|
12372
|
+
* @param {Address} token - The address of the token to get the balance of.
|
|
12373
|
+
* @param {CWSpokeProvider} spokeProvider - The spoke provider.
|
|
12374
|
+
* @returns {Promise<bigint>} The balance of the token.
|
|
12375
|
+
*/
|
|
12376
|
+
static async getDeposit(token, spokeProvider) {
|
|
12377
|
+
const bal = await spokeProvider.getBalance(token);
|
|
12378
|
+
return BigInt(bal);
|
|
12379
|
+
}
|
|
12380
|
+
/**
|
|
12381
|
+
* Generate simulation parameters for deposit from NearSpokeDepositParams.
|
|
12382
|
+
* @param {NearSpokeDepositParams} params - The deposit parameters.
|
|
12383
|
+
* @param {NearSpokeProviderType} spokeProvider - The provider for the spoke chain.
|
|
12384
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
12385
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
12386
|
+
*/
|
|
12387
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
12388
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
12389
|
+
spokeProvider.chainConfig.chain.id,
|
|
12390
|
+
encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
12391
|
+
hubProvider
|
|
12392
|
+
);
|
|
12393
|
+
return {
|
|
12394
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
12395
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
12396
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
12397
|
+
to,
|
|
12398
|
+
amount: params.amount,
|
|
12399
|
+
data: params.data,
|
|
12400
|
+
srcAddress: encodeAddress(spokeProvider.chainConfig.chain.id, spokeProvider.chainConfig.addresses.assetManager)
|
|
12401
|
+
};
|
|
12402
|
+
}
|
|
12403
|
+
/**
|
|
12404
|
+
* Calls a contract on the spoke chain using the user's wallet.
|
|
12405
|
+
* @param {HubAddress} from - The address of the user on the hub chain.
|
|
12406
|
+
* @param {Hex} payload - The payload to send to the contract.
|
|
12407
|
+
* @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
12408
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
12409
|
+
* @returns {Promise<TxReturnType<S, R>>} A promise that resolves to the transaction hash.
|
|
12410
|
+
*/
|
|
12411
|
+
static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
|
|
12412
|
+
const relayId = types.getIntentRelayChainId(hubProvider.chainConfig.chain.id);
|
|
12413
|
+
return _NearSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
|
|
12414
|
+
}
|
|
12415
|
+
/**
|
|
12416
|
+
* Sends a message to the hub chain.
|
|
12417
|
+
* @param {bigint} dstChainId - The chain ID of the hub chain.
|
|
12418
|
+
* @param {Address} dstAddress - The address on the hub chain.
|
|
12419
|
+
* @param {Hex} payload - The payload to send.
|
|
12420
|
+
* @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
12421
|
+
* @returns {Promise<TxReturnType<S, R>>} A promise that resolves to the transaction hash.
|
|
12422
|
+
*/
|
|
12423
|
+
static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
|
|
12424
|
+
const txn = await spokeProvider.sendMessage({
|
|
12425
|
+
dst_address: Array.from(viem.fromHex(dstAddress, "bytes")),
|
|
12426
|
+
dst_chain_id: Number.parseInt(dstChainId.toString()),
|
|
12427
|
+
payload: Array.from(viem.fromHex(payload, "bytes"))
|
|
12428
|
+
});
|
|
12429
|
+
if (raw || isNearRawSpokeProvider(spokeProvider)) {
|
|
12430
|
+
return txn;
|
|
12431
|
+
}
|
|
12432
|
+
const hash = await spokeProvider.submit(txn);
|
|
12433
|
+
return hash;
|
|
12434
|
+
}
|
|
12435
|
+
/**
|
|
12436
|
+
* Get Max Withdrawable Balance for the token.
|
|
12437
|
+
* @param {Address} token - The address of the token to get the balance of.
|
|
12438
|
+
* @param {NearSpokeProvider} spokeProvider - The spoke provider.
|
|
12439
|
+
* @returns {Promise<bigint>} The max limit of the token.
|
|
12440
|
+
*/
|
|
12441
|
+
static async getLimit(token, spokeProvider) {
|
|
12442
|
+
const rate_limit = await spokeProvider.getRateLimit(token);
|
|
12443
|
+
return BigInt(rate_limit.maxAvailable);
|
|
12444
|
+
}
|
|
12445
|
+
/**
|
|
12446
|
+
* Get available withdrawable amount for the token.
|
|
12447
|
+
* @param {Address} token - The address of the token to get the balance of.
|
|
12448
|
+
* @param {NearSpokeProvider} spokeProvider - The spoke provider.
|
|
12449
|
+
* @returns {Promise<bigint>} The available withdrawable amount of the token.
|
|
12450
|
+
*/
|
|
12451
|
+
static async getAvailable(token, spokeProvider) {
|
|
12452
|
+
const rate_limit = await spokeProvider.getRateLimit(token);
|
|
12453
|
+
return BigInt(rate_limit.available);
|
|
12454
|
+
}
|
|
12455
|
+
static async waitForTransaction(spokeProvider, txHash, maxRetries, retryDelay) {
|
|
12456
|
+
try {
|
|
12457
|
+
const accountId = await spokeProvider.walletProvider.getWalletAddress();
|
|
12458
|
+
const receipt = await NearSpokeProvider.waitForTransaction(
|
|
12459
|
+
txHash,
|
|
12460
|
+
accountId,
|
|
12461
|
+
spokeProvider.rpcProvider,
|
|
12462
|
+
maxRetries,
|
|
12463
|
+
retryDelay
|
|
12464
|
+
);
|
|
12465
|
+
if (receipt.status === "success") {
|
|
12466
|
+
return { ok: true, value: true };
|
|
12467
|
+
}
|
|
12468
|
+
return { ok: false, error: new Error(`NEAR transaction failed: ${txHash}`) };
|
|
12469
|
+
} catch (err) {
|
|
12470
|
+
return { ok: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
12471
|
+
}
|
|
12472
|
+
}
|
|
12473
|
+
static async waitForTransactionRaw(params) {
|
|
12474
|
+
try {
|
|
12475
|
+
const { rpcUrl, txHash, accountId, maxRetries, retryDelay } = params;
|
|
12476
|
+
const receipt = await NearSpokeProvider.waitForTransaction(
|
|
12477
|
+
txHash,
|
|
12478
|
+
accountId,
|
|
12479
|
+
new nearApiJs.JsonRpcProvider({ url: rpcUrl }),
|
|
12480
|
+
maxRetries,
|
|
12481
|
+
retryDelay
|
|
12482
|
+
);
|
|
12483
|
+
if (receipt.status === "success") {
|
|
12484
|
+
return { ok: true, value: true };
|
|
12485
|
+
}
|
|
12486
|
+
return { ok: false, error: new Error(`NEAR transaction failed: ${txHash}`) };
|
|
12487
|
+
} catch (err) {
|
|
12488
|
+
return { ok: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
12489
|
+
}
|
|
12490
|
+
}
|
|
12491
|
+
};
|
|
12492
|
+
|
|
12493
|
+
// src/shared/services/spoke/SpokeService.ts
|
|
12160
12494
|
var SpokeService = class _SpokeService {
|
|
12161
12495
|
constructor() {
|
|
12162
12496
|
}
|
|
@@ -12362,6 +12696,15 @@ var SpokeService = class _SpokeService {
|
|
|
12362
12696
|
raw
|
|
12363
12697
|
);
|
|
12364
12698
|
}
|
|
12699
|
+
if (isNearSpokeProviderType(spokeProvider)) {
|
|
12700
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
12701
|
+
return NearSpokeService.deposit(
|
|
12702
|
+
params,
|
|
12703
|
+
spokeProvider,
|
|
12704
|
+
hubProvider,
|
|
12705
|
+
raw
|
|
12706
|
+
);
|
|
12707
|
+
}
|
|
12365
12708
|
throw new Error("Invalid spoke provider");
|
|
12366
12709
|
}
|
|
12367
12710
|
static getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
@@ -12407,6 +12750,13 @@ var SpokeService = class _SpokeService {
|
|
|
12407
12750
|
hubProvider
|
|
12408
12751
|
);
|
|
12409
12752
|
}
|
|
12753
|
+
if (isNearSpokeProviderType(spokeProvider)) {
|
|
12754
|
+
return NearSpokeService.getSimulateDepositParams(
|
|
12755
|
+
params,
|
|
12756
|
+
spokeProvider,
|
|
12757
|
+
hubProvider
|
|
12758
|
+
);
|
|
12759
|
+
}
|
|
12410
12760
|
throw new Error("[getSimulateDepositParams] Invalid spoke provider");
|
|
12411
12761
|
}
|
|
12412
12762
|
static async verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation) {
|
|
@@ -12446,6 +12796,9 @@ var SpokeService = class _SpokeService {
|
|
|
12446
12796
|
if (isSonicSpokeProviderType(spokeProvider)) {
|
|
12447
12797
|
return SonicSpokeService.getDeposit(token, spokeProvider);
|
|
12448
12798
|
}
|
|
12799
|
+
if (isNearSpokeProviderType(spokeProvider)) {
|
|
12800
|
+
return NearSpokeService.getDeposit(token, spokeProvider);
|
|
12801
|
+
}
|
|
12449
12802
|
throw new Error("Invalid spoke provider");
|
|
12450
12803
|
}
|
|
12451
12804
|
/**
|
|
@@ -12519,6 +12872,10 @@ var SpokeService = class _SpokeService {
|
|
|
12519
12872
|
raw
|
|
12520
12873
|
);
|
|
12521
12874
|
}
|
|
12875
|
+
if (isNearSpokeProviderType(spokeProvider)) {
|
|
12876
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
12877
|
+
return await NearSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
|
|
12878
|
+
}
|
|
12522
12879
|
throw new Error("[callWallet] Invalid spoke provider");
|
|
12523
12880
|
}
|
|
12524
12881
|
static async verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation) {
|
|
@@ -12540,6 +12897,30 @@ var SpokeService = class _SpokeService {
|
|
|
12540
12897
|
}
|
|
12541
12898
|
}
|
|
12542
12899
|
}
|
|
12900
|
+
/**
|
|
12901
|
+
* Get max withdrawable balance for token.
|
|
12902
|
+
* @param {string| Address} token - The address of the token to get the balance of.
|
|
12903
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider.
|
|
12904
|
+
* @returns {Promise<bigint>} The max limit allowed for token.
|
|
12905
|
+
*/
|
|
12906
|
+
static getLimit(token, spokeProvider) {
|
|
12907
|
+
if (spokeProvider instanceof NearSpokeProvider) {
|
|
12908
|
+
return NearSpokeService.getLimit(token, spokeProvider);
|
|
12909
|
+
}
|
|
12910
|
+
throw new Error("Invalid spoke provider");
|
|
12911
|
+
}
|
|
12912
|
+
/**
|
|
12913
|
+
* Get available withdrawable amount.
|
|
12914
|
+
* @param {string| Address} token - The address of the token to get the balance of.
|
|
12915
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider.
|
|
12916
|
+
* @returns {Promise<bigint>} The available withdrawable amount for token.
|
|
12917
|
+
*/
|
|
12918
|
+
static getAvailable(token, spokeProvider) {
|
|
12919
|
+
if (spokeProvider instanceof NearSpokeProvider) {
|
|
12920
|
+
return NearSpokeService.getAvailable(token, spokeProvider);
|
|
12921
|
+
}
|
|
12922
|
+
throw new Error("Invalid spoke provider");
|
|
12923
|
+
}
|
|
12543
12924
|
/**
|
|
12544
12925
|
* Verifies the transaction hash for the spoke chain to exist on chain.
|
|
12545
12926
|
* Only stellar and solana need to be verified. For other chains, we assume the transaction exists on chain.
|
|
@@ -12560,6 +12941,9 @@ var SpokeService = class _SpokeService {
|
|
|
12560
12941
|
}
|
|
12561
12942
|
return result;
|
|
12562
12943
|
}
|
|
12944
|
+
if (isNearSpokeProvider(spokeProvider)) {
|
|
12945
|
+
return NearSpokeService.waitForTransaction(spokeProvider, txHash);
|
|
12946
|
+
}
|
|
12563
12947
|
if (isStellarSpokeProvider(spokeProvider)) {
|
|
12564
12948
|
return StellarSpokeService.waitForTransaction(spokeProvider, txHash);
|
|
12565
12949
|
}
|
|
@@ -12579,12 +12963,14 @@ var SpokeService = class _SpokeService {
|
|
|
12579
12963
|
return SolanaSpokeService.waitForConfirmationRaw(params);
|
|
12580
12964
|
case "STELLAR":
|
|
12581
12965
|
return StellarSpokeService.waitForTransactionRaw(params);
|
|
12966
|
+
case "NEAR":
|
|
12967
|
+
return NearSpokeService.waitForTransactionRaw(params);
|
|
12582
12968
|
case "EVM": {
|
|
12583
12969
|
const result = await EvmSpokeService.waitForTransactionReceipt(params);
|
|
12584
12970
|
if (!result.ok) {
|
|
12585
12971
|
return result;
|
|
12586
12972
|
}
|
|
12587
|
-
if (result.value.status && result.value.status !== "0x1") {
|
|
12973
|
+
if (result.value.status && result.value.status !== "0x1" && result.value.status !== "success") {
|
|
12588
12974
|
return { ok: false, error: new Error("Transaction reverted") };
|
|
12589
12975
|
}
|
|
12590
12976
|
return { ok: true, value: true };
|
|
@@ -16354,12 +16740,18 @@ function isSolanaSpokeProviderType(value) {
|
|
|
16354
16740
|
function isSolanaSpokeProvider(value) {
|
|
16355
16741
|
return typeof value === "object" && value !== null && value instanceof SolanaSpokeProvider && !("raw" in value) && value.chainConfig.chain.type === "SOLANA";
|
|
16356
16742
|
}
|
|
16743
|
+
function isNearSpokeProvider(value) {
|
|
16744
|
+
return typeof value === "object" && value !== null && value instanceof NearSpokeProvider && !("raw" in value) && value.chainConfig.chain.type === "NEAR";
|
|
16745
|
+
}
|
|
16357
16746
|
function isStellarSpokeProviderType(value) {
|
|
16358
16747
|
return typeof value === "object" && value !== null && (isStellarSpokeProvider(value) || isStellarRawSpokeProvider(value));
|
|
16359
16748
|
}
|
|
16360
16749
|
function isStellarSpokeProvider(value) {
|
|
16361
16750
|
return typeof value === "object" && value !== null && value instanceof StellarSpokeProvider && !("raw" in value) && value.chainConfig.chain.type === "STELLAR";
|
|
16362
16751
|
}
|
|
16752
|
+
function isNearSpokeProviderType(value) {
|
|
16753
|
+
return typeof value === "object" && value !== null && (isNearSpokeProvider(value) || isNearRawSpokeProvider(value));
|
|
16754
|
+
}
|
|
16363
16755
|
function isInjectiveSpokeProviderType(value) {
|
|
16364
16756
|
return typeof value === "object" && value !== null && (isInjectiveSpokeProvider(value) || isInjectiveRawSpokeProvider(value));
|
|
16365
16757
|
}
|
|
@@ -16465,6 +16857,9 @@ function isInjectiveRawSpokeProvider(value) {
|
|
|
16465
16857
|
function isSonicRawSpokeProvider(value) {
|
|
16466
16858
|
return isRawSpokeProvider(value) && value.chainConfig.chain.type === "EVM" && value.chainConfig.chain.id === types.SONIC_MAINNET_CHAIN_ID;
|
|
16467
16859
|
}
|
|
16860
|
+
function isNearRawSpokeProvider(value) {
|
|
16861
|
+
return isRawSpokeProvider(value) && value.chainConfig.chain.type === "NEAR";
|
|
16862
|
+
}
|
|
16468
16863
|
function isAddressString(value) {
|
|
16469
16864
|
return typeof value === "string";
|
|
16470
16865
|
}
|
|
@@ -16480,6 +16875,9 @@ function isStellarRawSpokeProviderConfig(value) {
|
|
|
16480
16875
|
function isSolanaRawSpokeProviderConfig(value) {
|
|
16481
16876
|
return typeof value === "object" && value !== null && "walletAddress" in value && "chainConfig" in value && "connection" in value && value.chainConfig.chain.type === "SOLANA";
|
|
16482
16877
|
}
|
|
16878
|
+
function isNearRawSpokeProviderConfig(value) {
|
|
16879
|
+
return typeof value === "object" && value !== null && "walletAddress" in value && "chainConfig" in value && value.chainConfig.chain.type === "NEAR";
|
|
16880
|
+
}
|
|
16483
16881
|
async function retry(action, retryCount = DEFAULT_MAX_RETRY, delayMs = DEFAULT_RETRY_DELAY_MS) {
|
|
16484
16882
|
do {
|
|
16485
16883
|
try {
|
|
@@ -16565,6 +16963,8 @@ function encodeAddress(spokeChainId, address) {
|
|
|
16565
16963
|
return viem.toHex(Buffer.from(new web3_js.PublicKey(address).toBytes()));
|
|
16566
16964
|
case "stellar":
|
|
16567
16965
|
return `0x${stellarSdk.Address.fromString(address).toScVal().toXDR("hex")}`;
|
|
16966
|
+
case "near":
|
|
16967
|
+
return viem.toHex(Buffer.from(address, "utf-8"));
|
|
16568
16968
|
default:
|
|
16569
16969
|
return address;
|
|
16570
16970
|
}
|
|
@@ -16631,6 +17031,10 @@ function constructRawSpokeProvider(config) {
|
|
|
16631
17031
|
config.walletAddress
|
|
16632
17032
|
);
|
|
16633
17033
|
}
|
|
17034
|
+
case "NEAR": {
|
|
17035
|
+
invariant6__default.default(isNearRawSpokeProviderConfig(config), "Invalid Near raw spoke provider config");
|
|
17036
|
+
return new NearRawSpokeProvider(config.chainConfig, config.walletAddress);
|
|
17037
|
+
}
|
|
16634
17038
|
default: {
|
|
16635
17039
|
throw new Error(`Unsupported chain type: ${chainType}`);
|
|
16636
17040
|
}
|
|
@@ -18197,7 +18601,7 @@ var StakingService = class {
|
|
|
18197
18601
|
} else {
|
|
18198
18602
|
hubTxHash = txResult.value;
|
|
18199
18603
|
}
|
|
18200
|
-
return { ok: true, value: [txResult.value, hubTxHash] };
|
|
18604
|
+
return { ok: true, value: [txResult.value, hubTxHash ?? ""] };
|
|
18201
18605
|
} catch (error) {
|
|
18202
18606
|
return {
|
|
18203
18607
|
ok: false,
|
|
@@ -20824,6 +21228,9 @@ exports.MAX_UINT256 = MAX_UINT256;
|
|
|
20824
21228
|
exports.MigrationService = MigrationService;
|
|
20825
21229
|
exports.MoneyMarketDataService = MoneyMarketDataService;
|
|
20826
21230
|
exports.MoneyMarketService = MoneyMarketService;
|
|
21231
|
+
exports.NearBaseSpokeProvider = NearBaseSpokeProvider;
|
|
21232
|
+
exports.NearRawSpokeProvider = NearRawSpokeProvider;
|
|
21233
|
+
exports.NearSpokeProvider = NearSpokeProvider;
|
|
20827
21234
|
exports.PartnerFeeClaimService = PartnerFeeClaimService;
|
|
20828
21235
|
exports.PartnerService = PartnerService;
|
|
20829
21236
|
exports.ProtocolIntentsAbi = ProtocolIntentsAbi;
|
|
@@ -20958,6 +21365,10 @@ exports.isMoneyMarketRepayUnknownError = isMoneyMarketRepayUnknownError;
|
|
|
20958
21365
|
exports.isMoneyMarketSubmitTxFailedError = isMoneyMarketSubmitTxFailedError;
|
|
20959
21366
|
exports.isMoneyMarketSupplyUnknownError = isMoneyMarketSupplyUnknownError;
|
|
20960
21367
|
exports.isMoneyMarketWithdrawUnknownError = isMoneyMarketWithdrawUnknownError;
|
|
21368
|
+
exports.isNearRawSpokeProvider = isNearRawSpokeProvider;
|
|
21369
|
+
exports.isNearRawSpokeProviderConfig = isNearRawSpokeProviderConfig;
|
|
21370
|
+
exports.isNearSpokeProvider = isNearSpokeProvider;
|
|
21371
|
+
exports.isNearSpokeProviderType = isNearSpokeProviderType;
|
|
20961
21372
|
exports.isNewbnUSDChainId = isNewbnUSDChainId;
|
|
20962
21373
|
exports.isNewbnUSDToken = isNewbnUSDToken;
|
|
20963
21374
|
exports.isPartnerFeeAmount = isPartnerFeeAmount;
|