@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.cjs +17 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +17 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -599,6 +599,11 @@ function collateralToLiquiditySf(r, ctokens) {
|
|
|
599
599
|
if (r.collateralSupply === 0n || r.totalLiquiditySf === 0n) return ctokens * SF;
|
|
600
600
|
return ctokens * r.totalLiquiditySf / r.collateralSupply;
|
|
601
601
|
}
|
|
602
|
+
function oneCtokenLiquidityUp(r) {
|
|
603
|
+
const sf = r.collateralSupply === 0n || r.totalLiquiditySf === 0n ? SF : (r.totalLiquiditySf + r.collateralSupply - 1n) / r.collateralSupply;
|
|
604
|
+
const units = (sf + SF - 1n) / SF;
|
|
605
|
+
return units > 0n ? units : 1n;
|
|
606
|
+
}
|
|
602
607
|
function decodeObligation(address, acc) {
|
|
603
608
|
const d = bytesOf("Obligation", address, acc);
|
|
604
609
|
const deposits = [], borrows = [];
|
|
@@ -1165,11 +1170,21 @@ var KaminoMarketProtocolSolana = class extends KaminoBase {
|
|
|
1165
1170
|
const base64 = await this.build("deposit", me, p);
|
|
1166
1171
|
return this.sendBuilt(base64, this.spendExpectation(o.token, p.amount, this.firstDepositExtra(p)), p.rules, "supply");
|
|
1167
1172
|
}
|
|
1173
|
+
/**
|
|
1174
|
+
* A withdrawal pays out about what was asked: at least the amount less the slippage tolerance, at
|
|
1175
|
+
* most the amount plus that tolerance (interest accrued before the block, on a 'max'), one cToken's
|
|
1176
|
+
* worth at the reserve's on-chain rate (klend redeems whole cTokens) and a unit of rounding. A bigger
|
|
1177
|
+
* payout is collateral the user did not choose to take out of the obligation.
|
|
1178
|
+
*/
|
|
1179
|
+
withdrawExpectation(mint, p) {
|
|
1180
|
+
const max = p.amount + (p.amount - lessBps(p.amount, this.slippageBps)) + oneCtokenLiquidityUp(p.chain.reserve) + 1n;
|
|
1181
|
+
return this.receiveExpectation(mint, p.amount, 0n, max);
|
|
1182
|
+
}
|
|
1168
1183
|
async quoteWithdraw(o) {
|
|
1169
1184
|
const me = await this.me();
|
|
1170
1185
|
const p = await this.prepare("withdraw", me, o.token, o.amount);
|
|
1171
1186
|
const base64 = await this.build("withdraw", me, p);
|
|
1172
|
-
const expect = this.
|
|
1187
|
+
const expect = this.withdrawExpectation(o.token, p);
|
|
1173
1188
|
const { fee } = await this.quoteBuilt(base64, expect, p.rules);
|
|
1174
1189
|
return { fee, reserve: p.reserve.reserve, minReceived: expect.tokenIn.minAmount };
|
|
1175
1190
|
}
|
|
@@ -1178,7 +1193,7 @@ var KaminoMarketProtocolSolana = class extends KaminoBase {
|
|
|
1178
1193
|
const me = await this.me();
|
|
1179
1194
|
const p = await this.prepare("withdraw", me, o.token, o.amount);
|
|
1180
1195
|
const base64 = await this.build("withdraw", me, p);
|
|
1181
|
-
return this.sendBuilt(base64, this.
|
|
1196
|
+
return this.sendBuilt(base64, this.withdrawExpectation(o.token, p), p.rules, "withdraw");
|
|
1182
1197
|
}
|
|
1183
1198
|
/** A borrow pays out at most what was asked: a bigger one is debt the user did not choose. */
|
|
1184
1199
|
borrowExpectation(mint, amount) {
|