@gearbox-protocol/sdk 18.4.1-aave.5 → 18.4.1-aave.6

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.
@@ -112,7 +112,7 @@ function planRepay(intent, view) {
112
112
  *
113
113
  * Aave lends the debt plus the {@link SETTLE_MARGIN} headroom, since the facade
114
114
  * is told to repay everything outstanding by the time the transaction lands;
115
- * what it does not take stays on the account.
115
+ * what it does not take goes to `to`.
116
116
  */
117
117
  function planMoveToAave(intent, view) {
118
118
  const { claimable } = intent;
@@ -139,7 +139,12 @@ function planMoveToAave(intent, view) {
139
139
  },
140
140
  ...view.rwaAsset ? [convert(view.rwaAsset, view.underlying, RAISED)] : [],
141
141
  clearQuotas(),
142
- repay(view.debt)
142
+ repay(view.debt),
143
+ {
144
+ kind: "sweep",
145
+ to: intent.to,
146
+ token: view.underlying
147
+ }
143
148
  ];
144
149
  }
145
150
  /**
@@ -330,8 +330,9 @@ async function realize(steps, props) {
330
330
  break;
331
331
  case "sweep": {
332
332
  withdrawsCollateral = true;
333
+ const swept = (token) => !step.token || require_onchain_accounts_intents_utils_common.eq(token, step.token) || rwaAsset !== void 0 && require_onchain_accounts_intents_utils_common.eq(step.token, underlying) && require_onchain_accounts_intents_utils_common.eq(token, rwaAsset);
333
334
  const wrapped = ledger.balanceOf(underlying);
334
- if (rwaAsset && wrapped > 0n) push(await require_onchain_accounts_intents_operations.buildUnwrapRwaCollateralOperation({
335
+ if (rwaAsset && wrapped > 0n && swept(underlying)) push(await require_onchain_accounts_intents_operations.buildUnwrapRwaCollateralOperation({
335
336
  tokenIn: underlying,
336
337
  all: true,
337
338
  amountIn: wrapped,
@@ -341,6 +342,7 @@ async function realize(steps, props) {
341
342
  sdk
342
343
  }));
343
344
  for (const { token, balance } of ledger.snapshot().assets) {
345
+ if (!swept(token)) continue;
344
346
  const withdrawal = require_onchain_accounts_intents_operations.buildWithdrawCollateralOperation({
345
347
  token,
346
348
  amount: balance,
@@ -398,6 +398,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
398
398
  return this.#startIntent(position, {}, {
399
399
  type: "MOVE_TO_AAVE",
400
400
  token: params.token,
401
+ to: params.to,
401
402
  claimable: params.claimable && toClaimableWithdrawal(params.claimable)
402
403
  });
403
404
  }
@@ -111,7 +111,7 @@ function planRepay(intent, view) {
111
111
  *
112
112
  * Aave lends the debt plus the {@link SETTLE_MARGIN} headroom, since the facade
113
113
  * is told to repay everything outstanding by the time the transaction lands;
114
- * what it does not take stays on the account.
114
+ * what it does not take goes to `to`.
115
115
  */
116
116
  function planMoveToAave(intent, view) {
117
117
  const { claimable } = intent;
@@ -138,7 +138,12 @@ function planMoveToAave(intent, view) {
138
138
  },
139
139
  ...view.rwaAsset ? [convert(view.rwaAsset, view.underlying, RAISED)] : [],
140
140
  clearQuotas(),
141
- repay(view.debt)
141
+ repay(view.debt),
142
+ {
143
+ kind: "sweep",
144
+ to: intent.to,
145
+ token: view.underlying
146
+ }
142
147
  ];
143
148
  }
144
149
  /**
@@ -329,8 +329,9 @@ async function realize(steps, props) {
329
329
  break;
330
330
  case "sweep": {
331
331
  withdrawsCollateral = true;
332
+ const swept = (token) => !step.token || eq(token, step.token) || rwaAsset !== void 0 && eq(step.token, underlying) && eq(token, rwaAsset);
332
333
  const wrapped = ledger.balanceOf(underlying);
333
- if (rwaAsset && wrapped > 0n) push(await buildUnwrapRwaCollateralOperation({
334
+ if (rwaAsset && wrapped > 0n && swept(underlying)) push(await buildUnwrapRwaCollateralOperation({
334
335
  tokenIn: underlying,
335
336
  all: true,
336
337
  amountIn: wrapped,
@@ -340,6 +341,7 @@ async function realize(steps, props) {
340
341
  sdk
341
342
  }));
342
343
  for (const { token, balance } of ledger.snapshot().assets) {
344
+ if (!swept(token)) continue;
343
345
  const withdrawal = buildWithdrawCollateralOperation({
344
346
  token,
345
347
  amount: balance,
@@ -397,6 +397,7 @@ var PrepareApi = class extends MultichainConstruct {
397
397
  return this.#startIntent(position, {}, {
398
398
  type: "MOVE_TO_AAVE",
399
399
  token: params.token,
400
+ to: params.to,
400
401
  claimable: params.claimable && toClaimableWithdrawal(params.claimable)
401
402
  });
402
403
  }
@@ -83,12 +83,15 @@ export type Step = {
83
83
  } |
84
84
  /**
85
85
  * Hands whatever is left on the account to `to`, each balance in the token it
86
- * stands in. Only an exit asks for this: the amounts are whatever the legs
87
- * before it happen to leave, which no planner can name in advance.
86
+ * stands in. Only a plan that leaves no debt asks for this: the amounts are
87
+ * whatever the legs before it happen to leave, which no planner can name in
88
+ * advance. `token` limits it to that balance, the underlying of an RWA
89
+ * market leaving as the asset it wraps.
88
90
  */
89
91
  {
90
92
  kind: "sweep";
91
93
  to: Address;
94
+ token?: Address;
92
95
  } |
93
96
  /**
94
97
  * Drops every quota the account holds, in the same transaction and before
@@ -173,7 +176,7 @@ export declare function planRepay(intent: Omit<RepayStrategyIntent, "type">, vie
173
176
  *
174
177
  * Aave lends the debt plus the {@link SETTLE_MARGIN} headroom, since the facade
175
178
  * is told to repay everything outstanding by the time the transaction lands;
176
- * what it does not take stays on the account.
179
+ * what it does not take goes to `to`.
177
180
  */
178
181
  export declare function planMoveToAave(intent: Omit<MoveToAaveIntent, "type">, view: AccountView): Step[];
179
182
  /**
@@ -450,8 +450,9 @@ export interface RepayStrategyIntent {
450
450
  * borrows the underlying on the owner's behalf into the account, and the loan
451
451
  * is repaid in full with its quotas. The bridge borrows the debt plus a 10bps
452
452
  * margin for the interest of the blocks still to come; whatever the facade
453
- * does not take stays on the account. On an RWA market Aave lends the asset
454
- * the underlying wraps, which is wrapped before the repayment.
453
+ * does not take goes to `to`. On an RWA market Aave lends the asset the
454
+ * underlying wraps, which is wrapped before the repayment and the remainder
455
+ * unwrapped again on its way out.
455
456
  *
456
457
  * The bridge borrows as the owner, so the owner must have delegated credit on
457
458
  * the Aave variable debt token to the bridge beforehand.
@@ -460,6 +461,8 @@ export interface MoveToAaveIntent {
460
461
  type: "MOVE_TO_AAVE";
461
462
  /** RWA collateral on the account, as the Aave pool lists it. */
462
463
  token: Address;
464
+ /** Wallet the margin the repayment leaves goes to. */
465
+ to: Address;
463
466
  /**
464
467
  * Matured mint of `token`, claimed ahead of the supply; what it brings
465
468
  * moves along with the balance already on the account.
@@ -397,6 +397,11 @@ export interface RepayStrategyParams extends PrepareOptions {
397
397
  export interface MoveToAaveParams {
398
398
  /** RWA collateral on the account; its whole balance moves to Aave. */
399
399
  token: Address;
400
+ /**
401
+ * Wallet the margin the repayment leaves goes to, as the asset on an RWA
402
+ * market.
403
+ **/
404
+ to: Address;
400
405
  /**
401
406
  * The matured mint of `token`, from `sdk.positions.getCurrentWithdrawals()`:
402
407
  * claimed in the same transaction ahead of the supply, so what it brings
@@ -830,9 +835,10 @@ export interface IOpportunitiesPrepare {
830
835
  * which borrows the underlying on the owner's behalf into the account, and
831
836
  * the Gearbox loan is repaid in full with its quotas. Aave lends the debt
832
837
  * plus a 10bps margin for the interest still to come; whatever the facade
833
- * does not take stays on the account. On an RWA market Aave lends the
834
- * asset the underlying wraps, and it is wrapped before the repayment. The state answered is the credit
835
- * account's: owing nothing, holding that remainder.
838
+ * does not take goes to `to`. On an RWA market Aave lends the asset the
839
+ * underlying wraps, which is wrapped before the repayment and unwrapped
840
+ * again on its way to `to`. The state answered is the credit account's:
841
+ * owing nothing, and holding none of the underlying.
836
842
  *
837
843
  * The bridge borrows as the owner, so the transaction reverts unless the
838
844
  * owner has delegated credit on Aave's variable debt token to the bridge;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "18.4.1-aave.5",
3
+ "version": "18.4.1-aave.6",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {