@sodax/sdk 2.1.0-rc.2 → 2.1.0-rc.3

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 CHANGED
@@ -4300,7 +4300,13 @@ var BTC_ADDRESS_TYPES = ["P2PKH", "P2SH", "P2WPKH", "P2TR"];
4300
4300
  // ../types/dist/hooks/hooks.js
4301
4301
  var HookKind = {
4302
4302
  /** Deposits delivered USDC into the recipient's HyperCore perps account (HyperEVM). */
4303
- HYPERCORE_DEPOSIT: "hyperCoreDeposit"
4303
+ HYPERCORE_DEPOSIT: "hyperCoreDeposit",
4304
+ /**
4305
+ * Requests an ERC-7540 deposit of delivered USDC into the Flint RWA vault (Ethereum), with the
4306
+ * recipient as the request's controller. Asynchronous: the request mints no shares — Flint's
4307
+ * curator settles a NAV and then claims the shares on the controller's behalf.
4308
+ */
4309
+ FLINT_DEPOSIT: "flintDeposit"
4304
4310
  };
4305
4311
  var spokeHooks = {
4306
4312
  [ChainKeys.HYPEREVM_MAINNET]: [
@@ -4311,6 +4317,20 @@ var spokeHooks = {
4311
4317
  // USDC on HyperEVM
4312
4318
  }
4313
4319
  ]
4320
+ // HookKind.FLINT_DEPOSIT is not registered yet: FlintDepositHook is not deployed to Ethereum
4321
+ // mainnet (icon-project/sodax-contracts#693). Registering it with a placeholder address would
4322
+ // route real intent output to that address, so the entry lands with the deployment:
4323
+ //
4324
+ // [ChainKeys.ETHEREUM_MAINNET]: [
4325
+ // {
4326
+ // kind: HookKind.FLINT_DEPOSIT,
4327
+ // address: '0x…',
4328
+ // supportedTokens: [spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDC.address],
4329
+ // },
4330
+ // ],
4331
+ //
4332
+ // Until then `getSpokeHook` returns undefined and `resolveDeliveryHook` throws, which is the
4333
+ // correct behaviour for a hook that does not exist on chain.
4314
4334
  };
4315
4335
  var getSpokeHook = (chainKey, kind) => spokeHooks[chainKey]?.find((h) => h.kind === kind);
4316
4336
  var getSpokeHooks = (chainKey) => spokeHooks[chainKey] ?? [];
@@ -4436,7 +4456,7 @@ function isValidWalletProviderForChainKey(chainKey, walletProvider) {
4436
4456
  }
4437
4457
 
4438
4458
  // ../types/dist/index.js
4439
- var CONFIG_VERSION = 222;
4459
+ var CONFIG_VERSION = 223;
4440
4460
  function isEvmSpokeChainConfig(value) {
4441
4461
  return typeof value === "object" && value !== null && value.chain.type === "EVM" && value.chain.key !== HUB_CHAIN_KEY;
4442
4462
  }
@@ -14631,7 +14651,7 @@ var EvmVaultTokenService = class {
14631
14651
  return amount * BigInt(10 ** (decimals - 18));
14632
14652
  }
14633
14653
  };
14634
- var Erc20Service = class {
14654
+ var Erc20Service = class _Erc20Service {
14635
14655
  constructor() {
14636
14656
  }
14637
14657
  static async getErc20Token(token, publicClient) {
@@ -14657,6 +14677,19 @@ var Erc20Service = class {
14657
14677
  });
14658
14678
  return { name, symbol, decimals, address: token };
14659
14679
  }
14680
+ /**
14681
+ * Read the current on-chain allowance of `spender` over `owner`'s balance.
14682
+ * @param params - Token, owner, spender, and publicClient for the chain.
14683
+ * @returns The raw allowance.
14684
+ */
14685
+ static async getAllowance(params) {
14686
+ return params.publicClient.readContract({
14687
+ address: params.token,
14688
+ abi: viem.erc20Abi,
14689
+ functionName: "allowance",
14690
+ args: [params.owner, params.spender]
14691
+ });
14692
+ }
14660
14693
  /**
14661
14694
  * Check if spender has enough ERC20 allowance for given amount.
14662
14695
  * @param params - Token, amount, owner, spender, chainKey, and publicClient for the chain.
@@ -14670,12 +14703,7 @@ var Erc20Service = class {
14670
14703
  value: true
14671
14704
  };
14672
14705
  }
14673
- const allowedAmount = await params.publicClient.readContract({
14674
- address: params.token,
14675
- abi: viem.erc20Abi,
14676
- functionName: "allowance",
14677
- args: [params.owner, params.spender]
14678
- });
14706
+ const allowedAmount = await _Erc20Service.getAllowance(params);
14679
14707
  return {
14680
14708
  ok: true,
14681
14709
  value: allowedAmount >= params.amount
@@ -14687,6 +14715,59 @@ var Erc20Service = class {
14687
14715
  };
14688
14716
  }
14689
14717
  }
14718
+ /**
14719
+ * Decide how many approve transactions this token needs for `amount`.
14720
+ *
14721
+ * Tokens of the 2017 TetherToken lineage reject an allowance change from one non-zero value to
14722
+ * another, so a wallet holding a stale allowance can never approve — every retry reverts the same
14723
+ * way. Such a token needs `approve(0)` first.
14724
+ *
14725
+ * Detection is behavioural: a simulated approve either reverts or it does not. That answers the
14726
+ * question that actually matters ("will this approve revert?") instead of "is this token USDT?",
14727
+ * so a token listed later, or upgraded later behind the same address, is covered without a code
14728
+ * change — and no token list is hardcoded.
14729
+ *
14730
+ * The probes only run once an allowance is already set. The common path (nothing approved yet)
14731
+ * costs a single read.
14732
+ */
14733
+ static async planApproval(params) {
14734
+ const single = (reason) => ({ approveAmount: params.amount, reason });
14735
+ if (params.token.toLowerCase() === params.nativeToken.toLowerCase()) {
14736
+ return single("native-token");
14737
+ }
14738
+ let allowance;
14739
+ try {
14740
+ allowance = await _Erc20Service.getAllowance(params);
14741
+ } catch {
14742
+ return single("allowance-read-failed");
14743
+ }
14744
+ if (allowance === 0n) {
14745
+ return single("zero-allowance");
14746
+ }
14747
+ if (await _Erc20Service.canApprove(params, params.amount)) {
14748
+ return single("probe-passed");
14749
+ }
14750
+ if (!await _Erc20Service.canApprove(params, 0n)) {
14751
+ return single("reset-not-viable");
14752
+ }
14753
+ return { resetAmount: 0n, approveAmount: params.amount, reason: "reset-required" };
14754
+ }
14755
+ /**
14756
+ * Simulate `approve(spender, amount)` as `owner`.
14757
+ *
14758
+ * `call` rather than `simulateContract`, because a TetherToken-lineage `approve` returns no value
14759
+ * and ABI decoding would fail even on a successful call. `account` is required: the guard reads
14760
+ * `allowed[msg.sender][spender]`.
14761
+ */
14762
+ static async canApprove(params, amount) {
14763
+ const { data } = _Erc20Service.encodeApprove(params.token, params.spender, amount);
14764
+ try {
14765
+ await params.publicClient.call({ account: params.owner, to: params.token, data });
14766
+ return true;
14767
+ } catch {
14768
+ return false;
14769
+ }
14770
+ }
14690
14771
  /**
14691
14772
  * Approve ERC20 amount spending
14692
14773
  * @param token - ERC20 token address
@@ -22443,7 +22524,17 @@ var IntentDataType = /* @__PURE__ */ ((IntentDataType2) => {
22443
22524
  })(IntentDataType || {});
22444
22525
  var HOOK_DELIVERY_ABI = {
22445
22526
  // HyperCoreDepositHook expects `abi.encode(address)` — the HyperCore account to credit.
22446
- [HookKind.HYPERCORE_DEPOSIT]: [{ name: "recipient", type: "address" }]
22527
+ [HookKind.HYPERCORE_DEPOSIT]: [{ name: "recipient", type: "address" }],
22528
+ // FlintDepositHook expects `abi.encode(address)` — the ERC-7540 controller the deposit request is
22529
+ // recorded against, i.e. the account that ends up owning the resulting flUSD shares. Same shape as
22530
+ // HyperCore's today; kept as its own entry so the two can diverge without touching each other.
22531
+ [HookKind.FLINT_DEPOSIT]: [{ name: "recipient", type: "address" }]
22532
+ };
22533
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
22534
+ var assertUnsupportedHook = (request) => {
22535
+ throw new Error(
22536
+ `[HookService.encodeDeliveryData] Unsupported delivery hook kind: ${request.kind}`
22537
+ );
22447
22538
  };
22448
22539
  var HookService = class _HookService {
22449
22540
  constructor() {
@@ -22452,17 +22543,28 @@ var HookService = class _HookService {
22452
22543
  * Encodes a hook's `deliveryData` payload. One common entry point for all hooks — the encoding is
22453
22544
  * selected by {@link HookRequest.kind} and uses that hook's schema from {@link HOOK_DELIVERY_ABI}.
22454
22545
  *
22546
+ * Rejects the zero address. Every hook treats its recipient as the account to credit, and a
22547
+ * zero recipient is unrecoverable on arrival: the receiver reverts, which rolls back the whole
22548
+ * cross-chain withdrawal inside `SpokeAssetManager.recvMessage` and leaves the message wedged —
22549
+ * every retry hits the same revert. Failing here keeps that mistake client-side, before an intent
22550
+ * exists. Malformed and non-EVM addresses already throw inside viem's encoder.
22551
+ *
22455
22552
  * @param request - The hook selection (and any hook-specific params).
22456
22553
  * @param recipient - The end recipient the hook should credit (the intent's `dstAddress`).
22457
22554
  */
22458
22555
  static encodeDeliveryData(request, recipient) {
22556
+ invariant(
22557
+ recipient.toLowerCase() !== ZERO_ADDRESS,
22558
+ "[HookService.encodeDeliveryData] recipient (dstAddress) must not be the zero address"
22559
+ );
22459
22560
  switch (request.kind) {
22460
22561
  case HookKind.HYPERCORE_DEPOSIT:
22461
22562
  return viem.encodeAbiParameters(HOOK_DELIVERY_ABI[HookKind.HYPERCORE_DEPOSIT], [recipient]);
22563
+ case HookKind.FLINT_DEPOSIT:
22564
+ return viem.encodeAbiParameters(HOOK_DELIVERY_ABI[HookKind.FLINT_DEPOSIT], [recipient]);
22565
+ default:
22566
+ return assertUnsupportedHook(request);
22462
22567
  }
22463
- throw new Error(
22464
- `[HookService.encodeDeliveryData] Unsupported delivery hook kind: ${request.kind}`
22465
- );
22466
22568
  }
22467
22569
  /**
22468
22570
  * Resolves a high-level {@link HookRequest} to the on-chain delivery pair: the deployed hook address
@@ -24830,6 +24932,12 @@ var SpokeService = class _SpokeService {
24830
24932
  /**
24831
24933
  * Approve ERC-20 spending on hub / EVM spoke or request a Stellar trustline using unified params.
24832
24934
  * Feature services map their action payloads into {@link SpokeApproveParams}.
24935
+ *
24936
+ * A signed ERC-20 approval can take **two** transactions: a token of the TetherToken lineage
24937
+ * rejects an allowance change from one non-zero value to another, so a stale allowance is zeroed
24938
+ * first and the user signs twice. The returned hash is always the last transaction's, so the
24939
+ * contract callers see is unchanged. An unsigned caller still gets exactly one transaction — use
24940
+ * {@link SpokeService.buildApproveTxs} to get the whole plan.
24833
24941
  */
24834
24942
  async approve(params) {
24835
24943
  try {
@@ -24837,53 +24945,168 @@ var SpokeService = class _SpokeService {
24837
24945
  isUndefinedOrValidWalletProviderForChainKey(params.srcChainKey, params.walletProvider),
24838
24946
  `Invalid wallet provider for chain key: ${params.srcChainKey}, walletProvider.chainType: ${params.walletProvider?.chainType}`
24839
24947
  );
24840
- if (isSpokeApproveParamsHub(params)) {
24841
- const result = await Erc20Service.approve({
24842
- ...params,
24843
- token: params.token,
24844
- amount: params.amount,
24845
- from: params.owner,
24846
- spender: params.spender
24847
- });
24948
+ if (isSpokeApproveParamsHub(params) || isSpokeApproveParamsEvmSpoke(params)) {
24949
+ if (params.raw) {
24950
+ const tx = await Erc20Service.approve({
24951
+ ...params,
24952
+ token: params.token,
24953
+ amount: params.amount,
24954
+ from: params.owner,
24955
+ spender: params.spender
24956
+ });
24957
+ return { ok: true, value: tx };
24958
+ }
24959
+ const result = await this.executeErc20ApprovalPlan(params);
24960
+ if (!result.ok) {
24961
+ return result;
24962
+ }
24848
24963
  return {
24849
24964
  ok: true,
24850
- value: result
24965
+ value: result.value
24851
24966
  };
24852
24967
  }
24853
- if (isSpokeApproveParamsEvmSpoke(params)) {
24854
- const result = await Erc20Service.approve({
24855
- ...params,
24856
- token: params.token,
24857
- amount: params.amount,
24858
- from: params.owner,
24859
- spender: params.spender
24860
- });
24968
+ if (isSpokeApproveParamsStellar(params)) {
24969
+ const result = await this.requestTrustlineForApproval(params);
24861
24970
  return {
24862
24971
  ok: true,
24863
24972
  value: result
24864
24973
  };
24865
24974
  }
24866
- if (isSpokeApproveParamsStellar(params)) {
24867
- const result = await this.stellar.requestTrustline({
24868
- ...params,
24869
- srcAddress: params.owner,
24870
- srcChainKey: params.srcChainKey,
24975
+ return {
24976
+ ok: false,
24977
+ error: new Error("[SpokeService.approve] Only hub (Sonic), EVM spokes, and Stellar are supported")
24978
+ };
24979
+ } catch (error) {
24980
+ return { ok: false, error };
24981
+ }
24982
+ }
24983
+ /**
24984
+ * The unsigned approval transactions, named rather than ordered (see {@link ApprovalTxs}).
24985
+ *
24986
+ * `resetTx` is present only when the token needs its stale allowance cleared first (see
24987
+ * {@link Erc20Service.planApproval}); broadcast it and wait for it to be mined before `approveTx`,
24988
+ * which is not valid until the reset has landed. Unsigned callers — the swaps API and the apps
24989
+ * built on it — need this, because {@link SpokeService.approve} can only hand back a single `tx`.
24990
+ *
24991
+ * Deliberately separate from {@link SpokeService.approve} rather than a mode of it: the two return
24992
+ * genuinely different shapes, and folding them together would put a union in the return type of
24993
+ * the method every feature approves through.
24994
+ */
24995
+ async buildApproveTxs(params) {
24996
+ try {
24997
+ if (isSpokeApproveParamsHub(params) || isSpokeApproveParamsEvmSpoke(params)) {
24998
+ const plan = await this.planErc20Approval(params, "buildApproveTxs");
24999
+ const encode3 = (amount) => Erc20Service.approve({
24871
25000
  token: params.token,
24872
- amount: params.amount
25001
+ amount,
25002
+ from: params.owner,
25003
+ spender: params.spender,
25004
+ raw: true
24873
25005
  });
25006
+ const resetTx = plan.resetAmount === void 0 ? void 0 : await encode3(plan.resetAmount);
25007
+ const approveTx = await encode3(plan.approveAmount);
25008
+ return { ok: true, value: resetTx === void 0 ? { approveTx } : { resetTx, approveTx } };
25009
+ }
25010
+ if (isSpokeApproveParamsStellar(params)) {
25011
+ const tx = await this.requestTrustlineForApproval({ ...params, raw: true });
24874
25012
  return {
24875
25013
  ok: true,
24876
- value: result
25014
+ value: { approveTx: tx }
24877
25015
  };
24878
25016
  }
24879
25017
  return {
24880
25018
  ok: false,
24881
- error: new Error("[SpokeService.approve] Only hub (Sonic), EVM spokes, and Stellar are supported")
25019
+ error: new Error("[SpokeService.buildApproveTxs] Only hub (Sonic), EVM spokes, and Stellar are supported")
24882
25020
  };
24883
25021
  } catch (error) {
24884
25022
  return { ok: false, error };
24885
25023
  }
24886
25024
  }
25025
+ /**
25026
+ * Sign and broadcast the approval plan for an ERC-20 on the hub or an EVM spoke.
25027
+ *
25028
+ * A token of the TetherToken lineage rejects an allowance change from one non-zero value to
25029
+ * another, so a wallet holding a stale allowance needs `approve(0)` first. The transactions cannot
25030
+ * be batched: each one is only valid once its predecessor has been mined. The hash of the last is
25031
+ * returned, so the contract callers see is unchanged.
25032
+ */
25033
+ async executeErc20ApprovalPlan(params) {
25034
+ const { walletProvider } = params;
25035
+ invariant(
25036
+ walletProvider !== void 0 && isEvmWalletProviderType(walletProvider),
25037
+ "[SpokeService.approve] Expected an EVM wallet provider for a signed approval"
25038
+ );
25039
+ const plan = await this.planErc20Approval(params, "approve");
25040
+ const sendApprove = (amount) => Erc20Service.approve({
25041
+ token: params.token,
25042
+ amount,
25043
+ from: params.owner,
25044
+ spender: params.spender,
25045
+ raw: false,
25046
+ walletProvider
25047
+ });
25048
+ if (plan.resetAmount !== void 0) {
25049
+ const resetHash = await sendApprove(plan.resetAmount);
25050
+ const receipt = await this.waitForTxReceipt({ txHash: resetHash, chainKey: params.srcChainKey });
25051
+ if (!receipt.ok || receipt.value.status !== "success") {
25052
+ return {
25053
+ ok: false,
25054
+ error: new Error(
25055
+ `[SpokeService.approve] allowance reset transaction ${resetHash} did not confirm. Retry the approval \u2014 once the reset has landed it takes a single transaction.`
25056
+ )
25057
+ };
25058
+ }
25059
+ }
25060
+ const txHash = await sendApprove(plan.approveAmount);
25061
+ return { ok: true, value: txHash };
25062
+ }
25063
+ /**
25064
+ * Stellar approves by adding a trustline — always a single transaction, with no allowance to plan
25065
+ * around. Shared by both entry points so the param mapping and its cast live in one place.
25066
+ */
25067
+ requestTrustlineForApproval(params) {
25068
+ return this.stellar.requestTrustline({
25069
+ ...params,
25070
+ srcAddress: params.owner,
25071
+ srcChainKey: params.srcChainKey,
25072
+ token: params.token,
25073
+ amount: params.amount
25074
+ });
25075
+ }
25076
+ /** Resolve the chain-specific inputs {@link Erc20Service.planApproval} needs, and record the plan. */
25077
+ async planErc20Approval(params, caller) {
25078
+ const plan = await Erc20Service.planApproval({
25079
+ token: params.token,
25080
+ owner: params.owner,
25081
+ spender: params.spender,
25082
+ amount: params.amount,
25083
+ nativeToken: this.config.getChainConfig(params.srcChainKey).nativeToken,
25084
+ publicClient: this.getEvmPublicClient(params.srcChainKey)
25085
+ });
25086
+ this.logApprovalPlan(caller, params.srcChainKey, params.token, plan);
25087
+ return plan;
25088
+ }
25089
+ /** The read client for an EVM chain, whether it is the hub or a spoke. */
25090
+ getEvmPublicClient(chainKey) {
25091
+ return isHubChainKeyType(chainKey) ? this.sonic.publicClient : this.evm.getPublicClient(chainKey);
25092
+ }
25093
+ /**
25094
+ * Log a plan only when it says something: an extra transaction the user will have to sign, or a
25095
+ * probe that could not reach a verdict. The ordinary single approve is the vast majority of calls
25096
+ * and stays silent.
25097
+ */
25098
+ logApprovalPlan(caller, chainKey, token, plan) {
25099
+ const isNoteworthy = plan.resetAmount !== void 0 || plan.reason === "reset-not-viable" || plan.reason === "allowance-read-failed";
25100
+ if (!isNoteworthy) {
25101
+ return;
25102
+ }
25103
+ this.config.logger.debug(`[SpokeService.${caller}] approval plan`, {
25104
+ chainKey,
25105
+ token,
25106
+ needsReset: plan.resetAmount !== void 0,
25107
+ reason: plan.reason
25108
+ });
25109
+ }
24887
25110
  /**
24888
25111
  * Estimate the gas for a raw transaction.
24889
25112
  * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
@@ -27216,9 +27439,13 @@ var SwapService = class {
27216
27439
  * - Stellar: approves the trustline (adds/increases it).
27217
27440
  * - Other chain types: returns an error — approval is not supported.
27218
27441
  *
27219
- * When `raw: true`, returns unsigned transaction data instead of broadcasting.
27442
+ * When `raw: true`, returns unsigned transaction data instead of broadcasting. That is always a
27443
+ * single transaction, which cannot express the two-step approval a TetherToken-lineage token
27444
+ * needs when a stale allowance already exists — use {@link SwapService.buildApproveTxs} for the
27445
+ * whole plan.
27220
27446
  * When `raw: false`, a matching wallet provider for `K` must be supplied and the transaction
27221
- * is signed and broadcast immediately.
27447
+ * is signed and broadcast immediately. Such an approval can take **two** transactions, so the
27448
+ * user may sign twice; the returned hash is the last one's.
27222
27449
  *
27223
27450
  * @param _params - Swap action params including the source chain key, input token, amount, and wallet provider.
27224
27451
  * @returns A `Result` wrapping the chain-specific transaction return type (`TxReturnType<K, Raw>`).
@@ -27288,6 +27515,62 @@ var SwapService = class {
27288
27515
  return { ok: false, error };
27289
27516
  }
27290
27517
  }
27518
+ /**
27519
+ * The unsigned approval transactions for the swap's source token, in the order they must be
27520
+ * broadcast.
27521
+ *
27522
+ * Two transactions when the source token needs its stale allowance cleared first, one otherwise.
27523
+ * {@link SwapService.approve} is unchanged and still returns a single transaction; this is the
27524
+ * entry point for unsigned callers that need to handle the two-step case. When `resetTx` is
27525
+ * present, broadcast it and wait for it to be mined first — `approveTx` is not valid until the
27526
+ * reset has landed.
27527
+ */
27528
+ async buildApproveTxs(_params) {
27529
+ const { params } = _params;
27530
+ const wrapApproveFailure = (cause) => approveFailed("swap", cause);
27531
+ try {
27532
+ if (isHubChainKeyType(params.srcChainKey) || isEvmSpokeOnlyChainKeyType(params.srcChainKey)) {
27533
+ const spender = isHubChainKeyType(params.srcChainKey) ? this.solver.intentsContract : this.config.getChainConfig(params.srcChainKey).addresses.assetManager;
27534
+ const result = await this.spoke.buildApproveTxs({
27535
+ srcChainKey: params.srcChainKey,
27536
+ owner: params.srcAddress,
27537
+ token: params.inputToken,
27538
+ amount: params.inputAmount,
27539
+ spender,
27540
+ raw: true
27541
+ });
27542
+ if (!result.ok) {
27543
+ return { ok: false, error: wrapApproveFailure(result.error) };
27544
+ }
27545
+ return {
27546
+ ok: true,
27547
+ value: result.value
27548
+ };
27549
+ }
27550
+ if (isStellarChainKeyType(params.srcChainKey)) {
27551
+ const result = await this.spoke.buildApproveTxs({
27552
+ srcChainKey: params.srcChainKey,
27553
+ token: params.inputToken,
27554
+ amount: params.inputAmount,
27555
+ owner: params.srcAddress,
27556
+ raw: true
27557
+ });
27558
+ if (!result.ok) {
27559
+ return { ok: false, error: wrapApproveFailure(result.error) };
27560
+ }
27561
+ return {
27562
+ ok: true,
27563
+ value: result.value
27564
+ };
27565
+ }
27566
+ return {
27567
+ ok: false,
27568
+ error: new Error("Approve only supported for hub (Sonic), EVM spokes, and Stellar")
27569
+ };
27570
+ } catch (error) {
27571
+ return { ok: false, error };
27572
+ }
27573
+ }
27291
27574
  /**
27292
27575
  * Creates a swap intent on the user's source spoke chain without submitting it to the solver.
27293
27576
  *
@@ -40603,15 +40886,22 @@ var LeverageYieldService = class {
40603
40886
  spender: params.vault
40604
40887
  };
40605
40888
  if (params.raw) {
40606
- const tx2 = await Erc20Service.approve({ ...baseApprove, raw: true });
40607
- return { ok: true, value: tx2 };
40608
- }
40609
- const tx = await Erc20Service.approve({
40610
- ...baseApprove,
40889
+ const tx = await Erc20Service.approve({ ...baseApprove, raw: true });
40890
+ return { ok: true, value: tx };
40891
+ }
40892
+ const result = await this.spoke.approve({
40893
+ srcChainKey: this.hubProvider.chainConfig.chain.key,
40894
+ token: baseApprove.token,
40895
+ amount: baseApprove.amount,
40896
+ owner: from,
40897
+ spender: baseApprove.spender,
40611
40898
  raw: false,
40612
40899
  walletProvider: params.walletProvider
40613
40900
  });
40614
- return { ok: true, value: tx };
40901
+ if (!result.ok) {
40902
+ return { ok: false, error: approveFailed("leverageYield", result.error, baseCtx) };
40903
+ }
40904
+ return { ok: true, value: result.value };
40615
40905
  } catch (error) {
40616
40906
  if (isLeverageYieldApproveError(error)) return { ok: false, error };
40617
40907
  return { ok: false, error: approveFailed("leverageYield", error, baseCtx) };