@sodax/sdk 1.2.7-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.mjs CHANGED
@@ -12,6 +12,7 @@ import { bcs } from '@mysten/sui/bcs';
12
12
  import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
13
13
  import { Transaction } from '@mysten/sui/transactions';
14
14
  import { SorobanRpc, Account, Horizon, Contract, TransactionBuilder, BASE_FEE, nativeToScVal, TimeoutInfinite, rpc, scValToBigInt, Address, Operation, Asset, FeeBumpTransaction } from '@stellar/stellar-sdk';
15
+ import { JsonRpcProvider } from 'near-api-js';
15
16
  import BigNumber4, { BigNumber } from 'bignumber.js';
16
17
  import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
17
18
  import * as rlp from 'rlp';
@@ -8599,6 +8600,186 @@ var StellarSpokeProvider = class extends StellarBaseSpokeProvider {
8599
8600
  return toHex(Buffer.from(stellaraddress, "hex"));
8600
8601
  }
8601
8602
  };
8603
+ var NearBaseSpokeProvider = class {
8604
+ chainConfig;
8605
+ rpcProvider;
8606
+ constructor(chainConfig) {
8607
+ this.chainConfig = chainConfig;
8608
+ this.rpcProvider = new JsonRpcProvider({ url: chainConfig.rpcUrl });
8609
+ }
8610
+ /**
8611
+ * Waits for a NEAR transaction to reach finality.
8612
+ *
8613
+ * Uses the RPC `waitUntil: 'FINAL'` long-polling mode, which blocks server-side
8614
+ * until the transaction is finalized. Retries are only for transient network errors
8615
+ * (e.g. connection resets, DNS failures, timeouts). A successful RPC response —
8616
+ * whether success or failure — returns immediately without further retries.
8617
+ */
8618
+ static async waitForTransaction(txHash, accountId, rpcProvider, maxRetries = 3, retryDelay = 1e3) {
8619
+ for (let retry2 = 0; retry2 <= maxRetries; retry2++) {
8620
+ try {
8621
+ const outcome = await rpcProvider.viewTransactionStatus({ txHash, accountId, waitUntil: "FINAL" });
8622
+ const status = outcome?.status;
8623
+ if (status && ("SuccessValue" in status || "SuccessReceiptId" in status)) {
8624
+ return { status: "success" };
8625
+ }
8626
+ if (status && "Failure" in status) {
8627
+ return { status: "failure", failure: status.Failure };
8628
+ }
8629
+ if (retry2 < maxRetries) {
8630
+ await sleep(retryDelay);
8631
+ }
8632
+ } catch {
8633
+ if (retry2 < maxRetries) {
8634
+ await sleep(retryDelay);
8635
+ }
8636
+ }
8637
+ }
8638
+ throw new Error(`NEAR transaction ${txHash} was not confirmed after ${maxRetries} retries`);
8639
+ }
8640
+ queryContract(contractId, method, args) {
8641
+ return this.rpcProvider.callFunction({ contractId, method, args });
8642
+ }
8643
+ async getRawTransaction(params) {
8644
+ throw new Error("Not implemented");
8645
+ }
8646
+ transfer(params, deposit = BigInt("1"), gas = BigInt("300000000000000")) {
8647
+ if (this.isNative(params.token)) {
8648
+ deposit = BigInt(params.amount);
8649
+ return this.depositNear(params, deposit, gas);
8650
+ }
8651
+ return this.depositToken(params, deposit, gas);
8652
+ }
8653
+ depositNear(params, deposit, gas) {
8654
+ return this.getRawTransaction({
8655
+ contractId: this.chainConfig.addresses.assetManager,
8656
+ method: "transfer",
8657
+ args: { to: params.to, amount: params.amount, data: params.data },
8658
+ deposit,
8659
+ gas
8660
+ });
8661
+ }
8662
+ depositToken(params, deposit, gas) {
8663
+ return this.getRawTransaction({
8664
+ contractId: params.token,
8665
+ method: "ft_transfer_call",
8666
+ args: {
8667
+ receiver_id: this.chainConfig.addresses.assetManager,
8668
+ amount: params.amount.toString(),
8669
+ memo: "",
8670
+ msg: JSON.stringify({
8671
+ to: params.to,
8672
+ data: params.data
8673
+ })
8674
+ },
8675
+ deposit,
8676
+ gas
8677
+ });
8678
+ }
8679
+ sendMessage(params, deposit = BigInt("0"), gas = BigInt("300000000000000")) {
8680
+ return this.getRawTransaction({
8681
+ contractId: this.chainConfig.addresses.connection,
8682
+ method: "send_message",
8683
+ args: params,
8684
+ deposit,
8685
+ gas
8686
+ });
8687
+ }
8688
+ isNative(token) {
8689
+ return token === "NEAR";
8690
+ }
8691
+ async getBalance(token) {
8692
+ if (this.isNative(token)) {
8693
+ return this.queryContract(this.chainConfig.addresses.assetManager, "get_balance", {});
8694
+ }
8695
+ return this.queryContract(token, "ft_balance_of", {
8696
+ account_id: this.chainConfig.addresses.assetManager
8697
+ });
8698
+ }
8699
+ async getRateLimit(token) {
8700
+ const res = await this.queryContract(this.chainConfig.addresses.rateLimit, "get_rate_limit", {
8701
+ token
8702
+ });
8703
+ if (res == null || res === void 0) {
8704
+ return {
8705
+ maxAvailable: 0,
8706
+ available: 0,
8707
+ ratePerSecond: 0
8708
+ };
8709
+ }
8710
+ return {
8711
+ maxAvailable: res.max_available,
8712
+ available: res.available,
8713
+ ratePerSecond: res.rate_per_second
8714
+ };
8715
+ }
8716
+ toFillIntent(fillData) {
8717
+ return {
8718
+ amount: fillData.amount.toString(),
8719
+ fill_id: fillData.fill_id.toString(),
8720
+ intent_hash: Array.from(fromHex(fillData.intent_hash, "bytes")),
8721
+ receiver: Array.from(Buffer.from(fillData.receiver, "utf-8")),
8722
+ solver: Array.from(fromHex(fillData.solver, "bytes")),
8723
+ token: Array.from(Buffer.from(fillData.token, "utf-8"))
8724
+ };
8725
+ }
8726
+ async fillIntent(fillData, deposit = BigInt("1"), gas = BigInt("300000000000000")) {
8727
+ if (this.isNative(fillData.token)) {
8728
+ deposit = BigInt(fillData.amount);
8729
+ return this.getRawTransaction({
8730
+ contractId: this.chainConfig.addresses.intentFiller,
8731
+ method: "fill_intent",
8732
+ args: { fill: this.toFillIntent(fillData) },
8733
+ deposit,
8734
+ gas
8735
+ });
8736
+ }
8737
+ return this.getRawTransaction({
8738
+ contractId: fillData.token,
8739
+ method: "ft_transfer_call",
8740
+ args: {
8741
+ receiver_id: this.chainConfig.addresses.intentFiller,
8742
+ amount: fillData.amount.toString(),
8743
+ memo: "",
8744
+ msg: JSON.stringify(this.toFillIntent(fillData))
8745
+ },
8746
+ deposit,
8747
+ gas
8748
+ });
8749
+ }
8750
+ };
8751
+ var NearSpokeProvider = class extends NearBaseSpokeProvider {
8752
+ walletProvider;
8753
+ constructor(walletProvider, chainConfig) {
8754
+ super(chainConfig);
8755
+ this.walletProvider = walletProvider;
8756
+ }
8757
+ async submit(transaction) {
8758
+ return await this.walletProvider.signAndSubmitTxn(transaction);
8759
+ }
8760
+ async getRawTransaction(params) {
8761
+ return {
8762
+ signerId: await this.walletProvider.getWalletAddress(),
8763
+ params
8764
+ };
8765
+ }
8766
+ };
8767
+ var NearRawSpokeProvider = class extends NearBaseSpokeProvider {
8768
+ walletProvider;
8769
+ raw = true;
8770
+ constructor(chainConfig, walletAddress) {
8771
+ super(chainConfig);
8772
+ this.walletProvider = {
8773
+ getWalletAddress: async () => walletAddress
8774
+ };
8775
+ }
8776
+ async getRawTransaction(params) {
8777
+ return {
8778
+ signerId: await this.walletProvider.getWalletAddress(),
8779
+ params
8780
+ };
8781
+ }
8782
+ };
8602
8783
  var BigNumberZeroDecimal = BigNumber.clone({
8603
8784
  DECIMAL_PLACES: 0,
8604
8785
  ROUNDING_MODE: BigNumber.ROUND_DOWN
@@ -12129,6 +12310,159 @@ var SolanaSpokeService = class _SolanaSpokeService {
12129
12310
  }
12130
12311
  }
12131
12312
  };
12313
+ var NearSpokeService = class _NearSpokeService {
12314
+ constructor() {
12315
+ }
12316
+ /**
12317
+ * Deposit tokens to the spoke chain.
12318
+ * @param {CWSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
12319
+ * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
12320
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
12321
+ * @param {boolean} raw - The return type raw or just transaction hash
12322
+ * @returns {PromiseNearTxReturnType<R>} A promise that resolves to the transaction hash.
12323
+ */
12324
+ static async deposit(params, spokeProvider, hubProvider, raw) {
12325
+ const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
12326
+ spokeProvider.chainConfig.chain.id,
12327
+ toHex(Buffer.from(params.from, "utf-8")),
12328
+ hubProvider
12329
+ );
12330
+ const txn = await spokeProvider.transfer({
12331
+ token: params.token,
12332
+ to: Array.from(fromHex(userWallet, "bytes")),
12333
+ amount: params.amount.toString(),
12334
+ data: Array.from(fromHex(params.data, "bytes"))
12335
+ });
12336
+ if (raw || isNearRawSpokeProvider(spokeProvider)) {
12337
+ return txn;
12338
+ }
12339
+ const hash = await spokeProvider.submit(txn);
12340
+ return hash;
12341
+ }
12342
+ /**
12343
+ * Get the balance of the token in the spoke chain.
12344
+ * @param {Address} token - The address of the token to get the balance of.
12345
+ * @param {CWSpokeProvider} spokeProvider - The spoke provider.
12346
+ * @returns {Promise<bigint>} The balance of the token.
12347
+ */
12348
+ static async getDeposit(token, spokeProvider) {
12349
+ const bal = await spokeProvider.getBalance(token);
12350
+ return BigInt(bal);
12351
+ }
12352
+ /**
12353
+ * Generate simulation parameters for deposit from NearSpokeDepositParams.
12354
+ * @param {NearSpokeDepositParams} params - The deposit parameters.
12355
+ * @param {NearSpokeProviderType} spokeProvider - The provider for the spoke chain.
12356
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
12357
+ * @returns {Promise<DepositSimulationParams>} The simulation parameters.
12358
+ */
12359
+ static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
12360
+ const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
12361
+ spokeProvider.chainConfig.chain.id,
12362
+ encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
12363
+ hubProvider
12364
+ );
12365
+ return {
12366
+ spokeChainID: spokeProvider.chainConfig.chain.id,
12367
+ token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
12368
+ from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
12369
+ to,
12370
+ amount: params.amount,
12371
+ data: params.data,
12372
+ srcAddress: encodeAddress(spokeProvider.chainConfig.chain.id, spokeProvider.chainConfig.addresses.assetManager)
12373
+ };
12374
+ }
12375
+ /**
12376
+ * Calls a contract on the spoke chain using the user's wallet.
12377
+ * @param {HubAddress} from - The address of the user on the hub chain.
12378
+ * @param {Hex} payload - The payload to send to the contract.
12379
+ * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
12380
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
12381
+ * @returns {Promise<TxReturnType<S, R>>} A promise that resolves to the transaction hash.
12382
+ */
12383
+ static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
12384
+ const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
12385
+ return _NearSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
12386
+ }
12387
+ /**
12388
+ * Sends a message to the hub chain.
12389
+ * @param {bigint} dstChainId - The chain ID of the hub chain.
12390
+ * @param {Address} dstAddress - The address on the hub chain.
12391
+ * @param {Hex} payload - The payload to send.
12392
+ * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
12393
+ * @returns {Promise<TxReturnType<S, R>>} A promise that resolves to the transaction hash.
12394
+ */
12395
+ static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
12396
+ const txn = await spokeProvider.sendMessage({
12397
+ dst_address: Array.from(fromHex(dstAddress, "bytes")),
12398
+ dst_chain_id: Number.parseInt(dstChainId.toString()),
12399
+ payload: Array.from(fromHex(payload, "bytes"))
12400
+ });
12401
+ if (raw || isNearRawSpokeProvider(spokeProvider)) {
12402
+ return txn;
12403
+ }
12404
+ const hash = await spokeProvider.submit(txn);
12405
+ return hash;
12406
+ }
12407
+ /**
12408
+ * Get Max Withdrawable Balance for the token.
12409
+ * @param {Address} token - The address of the token to get the balance of.
12410
+ * @param {NearSpokeProvider} spokeProvider - The spoke provider.
12411
+ * @returns {Promise<bigint>} The max limit of the token.
12412
+ */
12413
+ static async getLimit(token, spokeProvider) {
12414
+ const rate_limit = await spokeProvider.getRateLimit(token);
12415
+ return BigInt(rate_limit.maxAvailable);
12416
+ }
12417
+ /**
12418
+ * Get available withdrawable amount for the token.
12419
+ * @param {Address} token - The address of the token to get the balance of.
12420
+ * @param {NearSpokeProvider} spokeProvider - The spoke provider.
12421
+ * @returns {Promise<bigint>} The available withdrawable amount of the token.
12422
+ */
12423
+ static async getAvailable(token, spokeProvider) {
12424
+ const rate_limit = await spokeProvider.getRateLimit(token);
12425
+ return BigInt(rate_limit.available);
12426
+ }
12427
+ static async waitForTransaction(spokeProvider, txHash, maxRetries, retryDelay) {
12428
+ try {
12429
+ const accountId = await spokeProvider.walletProvider.getWalletAddress();
12430
+ const receipt = await NearSpokeProvider.waitForTransaction(
12431
+ txHash,
12432
+ accountId,
12433
+ spokeProvider.rpcProvider,
12434
+ maxRetries,
12435
+ retryDelay
12436
+ );
12437
+ if (receipt.status === "success") {
12438
+ return { ok: true, value: true };
12439
+ }
12440
+ return { ok: false, error: new Error(`NEAR transaction failed: ${txHash}`) };
12441
+ } catch (err) {
12442
+ return { ok: false, error: err instanceof Error ? err : new Error(String(err)) };
12443
+ }
12444
+ }
12445
+ static async waitForTransactionRaw(params) {
12446
+ try {
12447
+ const { rpcUrl, txHash, accountId, maxRetries, retryDelay } = params;
12448
+ const receipt = await NearSpokeProvider.waitForTransaction(
12449
+ txHash,
12450
+ accountId,
12451
+ new JsonRpcProvider({ url: rpcUrl }),
12452
+ maxRetries,
12453
+ retryDelay
12454
+ );
12455
+ if (receipt.status === "success") {
12456
+ return { ok: true, value: true };
12457
+ }
12458
+ return { ok: false, error: new Error(`NEAR transaction failed: ${txHash}`) };
12459
+ } catch (err) {
12460
+ return { ok: false, error: err instanceof Error ? err : new Error(String(err)) };
12461
+ }
12462
+ }
12463
+ };
12464
+
12465
+ // src/shared/services/spoke/SpokeService.ts
12132
12466
  var SpokeService = class _SpokeService {
12133
12467
  constructor() {
12134
12468
  }
@@ -12334,6 +12668,15 @@ var SpokeService = class _SpokeService {
12334
12668
  raw
12335
12669
  );
12336
12670
  }
12671
+ if (isNearSpokeProviderType(spokeProvider)) {
12672
+ await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
12673
+ return NearSpokeService.deposit(
12674
+ params,
12675
+ spokeProvider,
12676
+ hubProvider,
12677
+ raw
12678
+ );
12679
+ }
12337
12680
  throw new Error("Invalid spoke provider");
12338
12681
  }
12339
12682
  static getSimulateDepositParams(params, spokeProvider, hubProvider) {
@@ -12379,6 +12722,13 @@ var SpokeService = class _SpokeService {
12379
12722
  hubProvider
12380
12723
  );
12381
12724
  }
12725
+ if (isNearSpokeProviderType(spokeProvider)) {
12726
+ return NearSpokeService.getSimulateDepositParams(
12727
+ params,
12728
+ spokeProvider,
12729
+ hubProvider
12730
+ );
12731
+ }
12382
12732
  throw new Error("[getSimulateDepositParams] Invalid spoke provider");
12383
12733
  }
12384
12734
  static async verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation) {
@@ -12418,6 +12768,9 @@ var SpokeService = class _SpokeService {
12418
12768
  if (isSonicSpokeProviderType(spokeProvider)) {
12419
12769
  return SonicSpokeService.getDeposit(token, spokeProvider);
12420
12770
  }
12771
+ if (isNearSpokeProviderType(spokeProvider)) {
12772
+ return NearSpokeService.getDeposit(token, spokeProvider);
12773
+ }
12421
12774
  throw new Error("Invalid spoke provider");
12422
12775
  }
12423
12776
  /**
@@ -12491,6 +12844,10 @@ var SpokeService = class _SpokeService {
12491
12844
  raw
12492
12845
  );
12493
12846
  }
12847
+ if (isNearSpokeProviderType(spokeProvider)) {
12848
+ await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
12849
+ return await NearSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
12850
+ }
12494
12851
  throw new Error("[callWallet] Invalid spoke provider");
12495
12852
  }
12496
12853
  static async verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation) {
@@ -12512,6 +12869,30 @@ var SpokeService = class _SpokeService {
12512
12869
  }
12513
12870
  }
12514
12871
  }
12872
+ /**
12873
+ * Get max withdrawable balance for token.
12874
+ * @param {string| Address} token - The address of the token to get the balance of.
12875
+ * @param {SpokeProvider} spokeProvider - The spoke provider.
12876
+ * @returns {Promise<bigint>} The max limit allowed for token.
12877
+ */
12878
+ static getLimit(token, spokeProvider) {
12879
+ if (spokeProvider instanceof NearSpokeProvider) {
12880
+ return NearSpokeService.getLimit(token, spokeProvider);
12881
+ }
12882
+ throw new Error("Invalid spoke provider");
12883
+ }
12884
+ /**
12885
+ * Get available withdrawable amount.
12886
+ * @param {string| Address} token - The address of the token to get the balance of.
12887
+ * @param {SpokeProvider} spokeProvider - The spoke provider.
12888
+ * @returns {Promise<bigint>} The available withdrawable amount for token.
12889
+ */
12890
+ static getAvailable(token, spokeProvider) {
12891
+ if (spokeProvider instanceof NearSpokeProvider) {
12892
+ return NearSpokeService.getAvailable(token, spokeProvider);
12893
+ }
12894
+ throw new Error("Invalid spoke provider");
12895
+ }
12515
12896
  /**
12516
12897
  * Verifies the transaction hash for the spoke chain to exist on chain.
12517
12898
  * Only stellar and solana need to be verified. For other chains, we assume the transaction exists on chain.
@@ -12532,6 +12913,9 @@ var SpokeService = class _SpokeService {
12532
12913
  }
12533
12914
  return result;
12534
12915
  }
12916
+ if (isNearSpokeProvider(spokeProvider)) {
12917
+ return NearSpokeService.waitForTransaction(spokeProvider, txHash);
12918
+ }
12535
12919
  if (isStellarSpokeProvider(spokeProvider)) {
12536
12920
  return StellarSpokeService.waitForTransaction(spokeProvider, txHash);
12537
12921
  }
@@ -12551,12 +12935,14 @@ var SpokeService = class _SpokeService {
12551
12935
  return SolanaSpokeService.waitForConfirmationRaw(params);
12552
12936
  case "STELLAR":
12553
12937
  return StellarSpokeService.waitForTransactionRaw(params);
12938
+ case "NEAR":
12939
+ return NearSpokeService.waitForTransactionRaw(params);
12554
12940
  case "EVM": {
12555
12941
  const result = await EvmSpokeService.waitForTransactionReceipt(params);
12556
12942
  if (!result.ok) {
12557
12943
  return result;
12558
12944
  }
12559
- if (result.value.status && result.value.status !== "0x1") {
12945
+ if (result.value.status && result.value.status !== "0x1" && result.value.status !== "success") {
12560
12946
  return { ok: false, error: new Error("Transaction reverted") };
12561
12947
  }
12562
12948
  return { ok: true, value: true };
@@ -16326,12 +16712,18 @@ function isSolanaSpokeProviderType(value) {
16326
16712
  function isSolanaSpokeProvider(value) {
16327
16713
  return typeof value === "object" && value !== null && value instanceof SolanaSpokeProvider && !("raw" in value) && value.chainConfig.chain.type === "SOLANA";
16328
16714
  }
16715
+ function isNearSpokeProvider(value) {
16716
+ return typeof value === "object" && value !== null && value instanceof NearSpokeProvider && !("raw" in value) && value.chainConfig.chain.type === "NEAR";
16717
+ }
16329
16718
  function isStellarSpokeProviderType(value) {
16330
16719
  return typeof value === "object" && value !== null && (isStellarSpokeProvider(value) || isStellarRawSpokeProvider(value));
16331
16720
  }
16332
16721
  function isStellarSpokeProvider(value) {
16333
16722
  return typeof value === "object" && value !== null && value instanceof StellarSpokeProvider && !("raw" in value) && value.chainConfig.chain.type === "STELLAR";
16334
16723
  }
16724
+ function isNearSpokeProviderType(value) {
16725
+ return typeof value === "object" && value !== null && (isNearSpokeProvider(value) || isNearRawSpokeProvider(value));
16726
+ }
16335
16727
  function isInjectiveSpokeProviderType(value) {
16336
16728
  return typeof value === "object" && value !== null && (isInjectiveSpokeProvider(value) || isInjectiveRawSpokeProvider(value));
16337
16729
  }
@@ -16437,6 +16829,9 @@ function isInjectiveRawSpokeProvider(value) {
16437
16829
  function isSonicRawSpokeProvider(value) {
16438
16830
  return isRawSpokeProvider(value) && value.chainConfig.chain.type === "EVM" && value.chainConfig.chain.id === SONIC_MAINNET_CHAIN_ID;
16439
16831
  }
16832
+ function isNearRawSpokeProvider(value) {
16833
+ return isRawSpokeProvider(value) && value.chainConfig.chain.type === "NEAR";
16834
+ }
16440
16835
  function isAddressString(value) {
16441
16836
  return typeof value === "string";
16442
16837
  }
@@ -16452,6 +16847,9 @@ function isStellarRawSpokeProviderConfig(value) {
16452
16847
  function isSolanaRawSpokeProviderConfig(value) {
16453
16848
  return typeof value === "object" && value !== null && "walletAddress" in value && "chainConfig" in value && "connection" in value && value.chainConfig.chain.type === "SOLANA";
16454
16849
  }
16850
+ function isNearRawSpokeProviderConfig(value) {
16851
+ return typeof value === "object" && value !== null && "walletAddress" in value && "chainConfig" in value && value.chainConfig.chain.type === "NEAR";
16852
+ }
16455
16853
  async function retry(action, retryCount = DEFAULT_MAX_RETRY, delayMs = DEFAULT_RETRY_DELAY_MS) {
16456
16854
  do {
16457
16855
  try {
@@ -16537,6 +16935,8 @@ function encodeAddress(spokeChainId, address) {
16537
16935
  return toHex(Buffer.from(new PublicKey(address).toBytes()));
16538
16936
  case "stellar":
16539
16937
  return `0x${Address.fromString(address).toScVal().toXDR("hex")}`;
16938
+ case "near":
16939
+ return toHex(Buffer.from(address, "utf-8"));
16540
16940
  default:
16541
16941
  return address;
16542
16942
  }
@@ -16603,6 +17003,10 @@ function constructRawSpokeProvider(config) {
16603
17003
  config.walletAddress
16604
17004
  );
16605
17005
  }
17006
+ case "NEAR": {
17007
+ invariant6(isNearRawSpokeProviderConfig(config), "Invalid Near raw spoke provider config");
17008
+ return new NearRawSpokeProvider(config.chainConfig, config.walletAddress);
17009
+ }
16606
17010
  default: {
16607
17011
  throw new Error(`Unsupported chain type: ${chainType}`);
16608
17012
  }
@@ -18169,7 +18573,7 @@ var StakingService = class {
18169
18573
  } else {
18170
18574
  hubTxHash = txResult.value;
18171
18575
  }
18172
- return { ok: true, value: [txResult.value, hubTxHash] };
18576
+ return { ok: true, value: [txResult.value, hubTxHash ?? ""] };
18173
18577
  } catch (error) {
18174
18578
  return {
18175
18579
  ok: false,
@@ -20742,6 +21146,6 @@ var BalnSwapService = class {
20742
21146
  }
20743
21147
  };
20744
21148
 
20745
- export { BackendApiService, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, BridgeService, ConfigService, CustomSorobanServer, CustomStellarAccount, 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, Erc20Service, EvmAssetManagerService, EvmBaseSpokeProvider, EvmHubProvider, EvmRawSpokeProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HubService, ICON_TX_RESULT_WAIT_MAX_RETRY, IconBaseSpokeProvider, IconRawSpokeProvider, IconSpokeProvider, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveBaseSpokeProvider, InjectiveRawSpokeProvider, InjectiveSpokeProvider, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataType, IntentFilledEventAbi, IntentsAbi, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, PartnerFeeClaimService, PartnerService, ProtocolIntentsAbi, RAY, RAY_DECIMALS, SECONDS_PER_YEAR, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaBaseSpokeProvider, SolanaRawSpokeProvider, SolanaSpokeProvider, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicBaseSpokeProvider, SonicRawSpokeProvider, SonicSpokeProvider, SonicSpokeService, SpokeService, StakingLogic, StakingService, StellarBaseSpokeProvider, StellarRawSpokeProvider, StellarSpokeProvider, StellarSpokeService, SuiBaseSpokeProvider, SuiRawSpokeProvider, SuiSpokeProvider, SuiSpokeService, SupportedMigrationTokens, SwapService, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, connectionAbi, constructRawSpokeProvider, convertTransactionInstructionToRaw, deriveUserWalletAddress, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubChainConfig, getIconAddressBytes, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getTransactionPackets, hexToBigInt, hexToSolanaAddress, hyper, isAddressString, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isCreateIntentAutoSwapError, isEvmHubChainConfig, isEvmInitializedConfig, isEvmRawSpokeProvider, isEvmRawSpokeProviderConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmSpokeProviderType, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isHubSpokeProvider, isIconAddress, isIconRawSpokeProvider, isIconSpokeProvider, isIconSpokeProviderType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveRawSpokeProvider, isInjectiveSpokeProvider, isInjectiveSpokeProviderType, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketWithdrawUnknownError, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isRawSpokeProvider, isResponseAddressType, isResponseSigningType, isSetSwapPreferenceError, isSolanaNativeToken, isSolanaRawSpokeProvider, isSolanaRawSpokeProviderConfig, isSolanaSpokeProvider, isSolanaSpokeProviderType, isSolverErrorResponse, isSonicRawSpokeProvider, isSonicRawSpokeProviderConfig, isSonicSpokeProvider, isSonicSpokeProviderType, isStellarRawSpokeProvider, isStellarRawSpokeProviderConfig, isStellarSpokeProvider, isStellarSpokeProviderType, isSuiRawSpokeProvider, isSuiSpokeProvider, isSuiSpokeProviderType, isUnifiedBnUSDMigrateParams, isUnknownIntentAutoSwapError, isWaitIntentAutoSwapError, isWaitUntilIntentExecutedFailed, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, parseToStroops, parseTokenArrayFromJson, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sleep, sonicWalletFactoryAbi, spokeAssetManagerAbi, stakedSodaAbi, stakingRouterAbi, submitTransaction, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
21149
+ export { BackendApiService, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, BridgeService, ConfigService, CustomSorobanServer, CustomStellarAccount, 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, Erc20Service, EvmAssetManagerService, EvmBaseSpokeProvider, EvmHubProvider, EvmRawSpokeProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HubService, ICON_TX_RESULT_WAIT_MAX_RETRY, IconBaseSpokeProvider, IconRawSpokeProvider, IconSpokeProvider, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveBaseSpokeProvider, InjectiveRawSpokeProvider, InjectiveSpokeProvider, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataType, IntentFilledEventAbi, IntentsAbi, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, NearBaseSpokeProvider, NearRawSpokeProvider, NearSpokeProvider, PartnerFeeClaimService, PartnerService, ProtocolIntentsAbi, RAY, RAY_DECIMALS, SECONDS_PER_YEAR, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaBaseSpokeProvider, SolanaRawSpokeProvider, SolanaSpokeProvider, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicBaseSpokeProvider, SonicRawSpokeProvider, SonicSpokeProvider, SonicSpokeService, SpokeService, StakingLogic, StakingService, StellarBaseSpokeProvider, StellarRawSpokeProvider, StellarSpokeProvider, StellarSpokeService, SuiBaseSpokeProvider, SuiRawSpokeProvider, SuiSpokeProvider, SuiSpokeService, SupportedMigrationTokens, SwapService, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, connectionAbi, constructRawSpokeProvider, convertTransactionInstructionToRaw, deriveUserWalletAddress, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubChainConfig, getIconAddressBytes, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getTransactionPackets, hexToBigInt, hexToSolanaAddress, hyper, isAddressString, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isCreateIntentAutoSwapError, isEvmHubChainConfig, isEvmInitializedConfig, isEvmRawSpokeProvider, isEvmRawSpokeProviderConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmSpokeProviderType, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isHubSpokeProvider, isIconAddress, isIconRawSpokeProvider, isIconSpokeProvider, isIconSpokeProviderType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveRawSpokeProvider, isInjectiveSpokeProvider, isInjectiveSpokeProviderType, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketWithdrawUnknownError, isNearRawSpokeProvider, isNearRawSpokeProviderConfig, isNearSpokeProvider, isNearSpokeProviderType, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isRawSpokeProvider, isResponseAddressType, isResponseSigningType, isSetSwapPreferenceError, isSolanaNativeToken, isSolanaRawSpokeProvider, isSolanaRawSpokeProviderConfig, isSolanaSpokeProvider, isSolanaSpokeProviderType, isSolverErrorResponse, isSonicRawSpokeProvider, isSonicRawSpokeProviderConfig, isSonicSpokeProvider, isSonicSpokeProviderType, isStellarRawSpokeProvider, isStellarRawSpokeProviderConfig, isStellarSpokeProvider, isStellarSpokeProviderType, isSuiRawSpokeProvider, isSuiSpokeProvider, isSuiSpokeProviderType, isUnifiedBnUSDMigrateParams, isUnknownIntentAutoSwapError, isWaitIntentAutoSwapError, isWaitUntilIntentExecutedFailed, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, parseToStroops, parseTokenArrayFromJson, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sleep, sonicWalletFactoryAbi, spokeAssetManagerAbi, stakedSodaAbi, stakingRouterAbi, submitTransaction, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
20746
21150
  //# sourceMappingURL=index.mjs.map
20747
21151
  //# sourceMappingURL=index.mjs.map