@anywalletkit/protocol-lending-kamino-solana 0.3.1 → 0.3.2

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.d.cts CHANGED
@@ -630,6 +630,13 @@ declare class KaminoMarketProtocolSolana extends KaminoBase<KaminoMarketConfig>
630
630
  private reported;
631
631
  quoteSupply(o: SupplyOptions): Promise<MarketQuote>;
632
632
  supply(o: SupplyOptions): Promise<LendingResult>;
633
+ /**
634
+ * A withdrawal pays out about what was asked: at least the amount less the slippage tolerance, at
635
+ * most the amount plus that tolerance (interest accrued before the block, on a 'max'), one cToken's
636
+ * worth at the reserve's on-chain rate (klend redeems whole cTokens) and a unit of rounding. A bigger
637
+ * payout is collateral the user did not choose to take out of the obligation.
638
+ */
639
+ private withdrawExpectation;
633
640
  quoteWithdraw(o: KaminoMarketWithdrawOptions): Promise<MarketQuote>;
634
641
  withdraw(o: KaminoMarketWithdrawOptions): Promise<LendingResult>;
635
642
  /** A borrow pays out at most what was asked: a bigger one is debt the user did not choose. */
package/dist/index.d.ts CHANGED
@@ -630,6 +630,13 @@ declare class KaminoMarketProtocolSolana extends KaminoBase<KaminoMarketConfig>
630
630
  private reported;
631
631
  quoteSupply(o: SupplyOptions): Promise<MarketQuote>;
632
632
  supply(o: SupplyOptions): Promise<LendingResult>;
633
+ /**
634
+ * A withdrawal pays out about what was asked: at least the amount less the slippage tolerance, at
635
+ * most the amount plus that tolerance (interest accrued before the block, on a 'max'), one cToken's
636
+ * worth at the reserve's on-chain rate (klend redeems whole cTokens) and a unit of rounding. A bigger
637
+ * payout is collateral the user did not choose to take out of the obligation.
638
+ */
639
+ private withdrawExpectation;
633
640
  quoteWithdraw(o: KaminoMarketWithdrawOptions): Promise<MarketQuote>;
634
641
  withdraw(o: KaminoMarketWithdrawOptions): Promise<LendingResult>;
635
642
  /** A borrow pays out at most what was asked: a bigger one is debt the user did not choose. */
package/dist/index.js CHANGED
@@ -527,6 +527,11 @@ function collateralToLiquiditySf(r, ctokens) {
527
527
  if (r.collateralSupply === 0n || r.totalLiquiditySf === 0n) return ctokens * SF;
528
528
  return ctokens * r.totalLiquiditySf / r.collateralSupply;
529
529
  }
530
+ function oneCtokenLiquidityUp(r) {
531
+ const sf = r.collateralSupply === 0n || r.totalLiquiditySf === 0n ? SF : (r.totalLiquiditySf + r.collateralSupply - 1n) / r.collateralSupply;
532
+ const units = (sf + SF - 1n) / SF;
533
+ return units > 0n ? units : 1n;
534
+ }
530
535
  function decodeObligation(address, acc) {
531
536
  const d = bytesOf("Obligation", address, acc);
532
537
  const deposits = [], borrows = [];
@@ -1093,11 +1098,21 @@ var KaminoMarketProtocolSolana = class extends KaminoBase {
1093
1098
  const base64 = await this.build("deposit", me, p);
1094
1099
  return this.sendBuilt(base64, this.spendExpectation(o.token, p.amount, this.firstDepositExtra(p)), p.rules, "supply");
1095
1100
  }
1101
+ /**
1102
+ * A withdrawal pays out about what was asked: at least the amount less the slippage tolerance, at
1103
+ * most the amount plus that tolerance (interest accrued before the block, on a 'max'), one cToken's
1104
+ * worth at the reserve's on-chain rate (klend redeems whole cTokens) and a unit of rounding. A bigger
1105
+ * payout is collateral the user did not choose to take out of the obligation.
1106
+ */
1107
+ withdrawExpectation(mint, p) {
1108
+ const max = p.amount + (p.amount - lessBps(p.amount, this.slippageBps)) + oneCtokenLiquidityUp(p.chain.reserve) + 1n;
1109
+ return this.receiveExpectation(mint, p.amount, 0n, max);
1110
+ }
1096
1111
  async quoteWithdraw(o) {
1097
1112
  const me = await this.me();
1098
1113
  const p = await this.prepare("withdraw", me, o.token, o.amount);
1099
1114
  const base64 = await this.build("withdraw", me, p);
1100
- const expect = this.receiveExpectation(o.token, p.amount);
1115
+ const expect = this.withdrawExpectation(o.token, p);
1101
1116
  const { fee } = await this.quoteBuilt(base64, expect, p.rules);
1102
1117
  return { fee, reserve: p.reserve.reserve, minReceived: expect.tokenIn.minAmount };
1103
1118
  }
@@ -1106,7 +1121,7 @@ var KaminoMarketProtocolSolana = class extends KaminoBase {
1106
1121
  const me = await this.me();
1107
1122
  const p = await this.prepare("withdraw", me, o.token, o.amount);
1108
1123
  const base64 = await this.build("withdraw", me, p);
1109
- return this.sendBuilt(base64, this.receiveExpectation(o.token, p.amount), p.rules, "withdraw");
1124
+ return this.sendBuilt(base64, this.withdrawExpectation(o.token, p), p.rules, "withdraw");
1110
1125
  }
1111
1126
  /** A borrow pays out at most what was asked: a bigger one is debt the user did not choose. */
1112
1127
  borrowExpectation(mint, amount) {