@suilend/sdk 11.3.0 → 11.4.0-next.gf578f26
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/package.json +1 -1
- package/utils/simulate.d.ts +8 -0
- package/utils/simulate.js +29 -9
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"11.
|
|
1
|
+
{"name":"@suilend/sdk","version":"11.4.0-next.gf578f26","private":false,"description":"A TypeScript SDK for interacting with the Suilend program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./client":"./client.js","./mmt":"./mmt.js","./strategies":"./strategies.js","./api/events":"./api/events.js","./api":"./api/index.js","./lib/constants":"./lib/constants.js","./lib":"./lib/index.js","./lib/initialize":"./lib/initialize.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/proCompatible":"./lib/proCompatible.js","./lib/pyth":"./lib/pyth.js","./lib/strategyOwnerCap":"./lib/strategyOwnerCap.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./margin":"./margin/index.js","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/obligation":"./parsers/obligation.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./swap":"./swap/index.js","./swap/quote":"./swap/quote.js","./swap/transaction":"./swap/transaction.js","./utils/events":"./utils/events.js","./utils/feedId":"./utils/feedId.js","./utils":"./utils/index.js","./utils/obligation":"./utils/obligation.js","./utils/simulate":"./utils/simulate.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend":"./_generated/suilend/index.js","./margin/margin/admin_cap":"./margin/margin/admin_cap.js","./margin/margin/market":"./margin/margin/market.js","./margin/margin/permissions":"./margin/margin/permissions.js","./margin/margin/position":"./margin/margin/position.js","./margin/margin/router":"./margin/margin/router.js","./margin/margin/version":"./margin/margin/version.js","./margin/utils":"./margin/utils/index.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/structs.js","./_generated/suilend/decimal/structs":"./_generated/suilend/decimal/structs.js","./_generated/suilend/lending-market/functions":"./_generated/suilend/lending-market/functions.js","./_generated/suilend/lending-market/structs":"./_generated/suilend/lending-market/structs.js","./_generated/suilend/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/structs.js","./_generated/suilend/rate-limiter/functions":"./_generated/suilend/rate-limiter/functions.js","./_generated/suilend/rate-limiter/structs":"./_generated/suilend/rate-limiter/structs.js","./_generated/suilend/reserve/structs":"./_generated/suilend/reserve/structs.js","./_generated/suilend/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/_dependencies/source/0x1":"./_generated/_dependencies/source/0x1/index.js","./_generated/_dependencies/source/0x2":"./_generated/_dependencies/source/0x2/index.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js","./margin/margin/deps/std/type_name":"./margin/margin/deps/std/type_name.js","./margin/margin/deps/sui/vec_set":"./margin/margin/deps/sui/vec_set.js","./margin/margin/deps/suilend/lending_market":"./margin/margin/deps/suilend/lending_market.js","./_generated/_dependencies/source/0x1/ascii/structs":"./_generated/_dependencies/source/0x1/ascii/structs.js","./_generated/_dependencies/source/0x1/option/structs":"./_generated/_dependencies/source/0x1/option/structs.js","./_generated/_dependencies/source/0x1/type-name/structs":"./_generated/_dependencies/source/0x1/type-name/structs.js","./_generated/_dependencies/source/0x2/bag/structs":"./_generated/_dependencies/source/0x2/bag/structs.js","./_generated/_dependencies/source/0x2/balance/structs":"./_generated/_dependencies/source/0x2/balance/structs.js","./_generated/_dependencies/source/0x2/object/structs":"./_generated/_dependencies/source/0x2/object/structs.js","./_generated/_dependencies/source/0x2/object-table/structs":"./_generated/_dependencies/source/0x2/object-table/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js"},"types":"./index.d.ts","scripts":{"build":"rm -rf ./dist && tsc && node ./fix-esm-imports.js","typecheck":"tsc --noEmit && tsc --noEmit -p tsconfig.test.json","test":"vitest run","lint:ci":"yarn run typecheck","prettier":"prettier --write src/ tests/","release":"yarn run build && node ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/fireflyprotocol/lending-mono.git","directory":"ts/sdks/sdk"},"dependencies":{"@bluefin-exchange/bluefin7k-aggregator-sdk":"7.6.3","@cetusprotocol/aggregator-sdk":"1.7.2","@flowx-finance/sdk":"2.1.0","@pythnetwork/hermes-client":"3.1.0","@pythnetwork/pyth-sui-js":"4.0.0","@suilend/springsui-sdk":"4.1.0","bignumber.js":"11.1.5","bn.js":"5.2.5","crypto-js":"4.2.0","lodash":"4.18.1","p-limit":"7.3.1","uuid":"14.0.2"},"devDependencies":{"@mysten/bcs":"2.1.1","@mysten/sui":"2.26.2","@suilend/sui-core":"1.3.0","@tsconfig/recommended":"1.0.13","@types/bn.js":"5.2.0","@types/lodash":"4.17.25","@types/node":"26.4.0","fast-check":"4.9.0","prettier":"3.9.6","ts-node":"10.9.2","typescript":"6.0.3","vitest":"4.1.11"},"peerDependencies":{"@mysten/bcs":"^2.1.1","@mysten/sui":">=2.22.1 <3","@suilend/sui-core":"^1.3.0"},"type":"module"}
|
package/utils/simulate.d.ts
CHANGED
|
@@ -147,6 +147,14 @@ export declare const getCTokenMarketValueLowerBound: (reserve: Reserve<string>,
|
|
|
147
147
|
export declare const cTokenRatio: (reserve: Reserve<string>) => BigNumber;
|
|
148
148
|
export declare const totalSupply: (reserve: Reserve<string>) => BigNumber;
|
|
149
149
|
export declare const compoundBorrowedAmount: (snapshotAmount: BigNumber, currentCumulativeBorrowRate: BigNumber, snapshotCumulativeBorrowRate: BigNumber) => BigNumber;
|
|
150
|
+
/**
|
|
151
|
+
* @deprecated Rounds the compounded amount through `stringToDecimal`
|
|
152
|
+
* (BigNumber -> JS `number` -> `Math.round(value * WAD)`), which is lossy at
|
|
153
|
+
* WAD scale (LEN-745) — don't feed this into further aggregate/liquidation
|
|
154
|
+
* math. Kept only because `@suilend/sdk/utils/simulate` is externally
|
|
155
|
+
* reachable and deleting it would be a breaking change. For an exact
|
|
156
|
+
* compounded amount, call `compoundBorrowedAmount` directly instead.
|
|
157
|
+
*/
|
|
150
158
|
export declare const compoundDebt: (borrow: Borrow, reserve: Reserve<string>) => Borrow;
|
|
151
159
|
export type ObligationHealthDepositInput = {
|
|
152
160
|
/** Matches `reserve.coinType.name` (unprefixed struct tag) — same field `refreshObligation` compares deposits against. */
|
package/utils/simulate.js
CHANGED
|
@@ -355,22 +355,34 @@ export function computeObligationRefresh(obligation, refreshedReserves, nowMs) {
|
|
|
355
355
|
const borrows = obligation.borrows.map((unrefreshedBorrow) => {
|
|
356
356
|
const reserve = findReserveOrThrow(refreshedReserves, unrefreshedBorrow.coinType.name);
|
|
357
357
|
const config = reserve.config.element;
|
|
358
|
+
// Exact BigNumber-compounded amount, computed once and reused below for
|
|
359
|
+
// `borrow.borrowedAmount` and both market values. `compoundDebt` would
|
|
360
|
+
// compute this same value internally only to round it away via a lossy
|
|
361
|
+
// `stringToDecimal` round-trip (BigNumber -> JS `number` ->
|
|
362
|
+
// `Math.round(value * WAD)`) before this code could read it back
|
|
363
|
+
// (LEN-745), so it's called here directly instead — `compoundDebt`
|
|
364
|
+
// itself stays untouched and exported for other callers.
|
|
365
|
+
const newCumulativeBorrowRate = decimalToBigNumber(reserve.cumulativeBorrowRate);
|
|
366
|
+
const exactBorrowedAmount = compoundBorrowedAmount(decimalToBigNumber(unrefreshedBorrow.borrowedAmount), newCumulativeBorrowRate, decimalToBigNumber(unrefreshedBorrow.cumulativeBorrowRate));
|
|
358
367
|
const borrow = {
|
|
359
|
-
...
|
|
368
|
+
...unrefreshedBorrow,
|
|
369
|
+
borrowedAmount: stringToDecimal(exactBorrowedAmount.toString()),
|
|
370
|
+
cumulativeBorrowRate: stringToDecimal(newCumulativeBorrowRate.toString()),
|
|
360
371
|
};
|
|
361
372
|
userRewardManagers[Number(borrow.userRewardManagerIndex)] =
|
|
362
373
|
updateUserRewardManager(reserve.borrowsPoolRewardManager, userRewardManagers[Number(borrow.userRewardManagerIndex)], nowMs);
|
|
363
|
-
const marketValue =
|
|
374
|
+
const marketValue = exactBorrowedAmount
|
|
364
375
|
.multipliedBy(decimalToBigNumber(reserve.price))
|
|
365
376
|
.dividedBy(new BigNumber(10 ** reserve.mintDecimals));
|
|
366
377
|
const upperBoundPrice = BigNumber.max(decimalToBigNumber(reserve.price), decimalToBigNumber(reserve.smoothedPrice));
|
|
367
|
-
// `
|
|
368
|
-
//
|
|
369
|
-
//
|
|
370
|
-
// `
|
|
371
|
-
// `market_value_upper_bound`, and this is what
|
|
372
|
-
// obligation owing $100 of a reserve with $22M
|
|
373
|
-
|
|
378
|
+
// `exactBorrowedAmount` (this borrow's own amount), not
|
|
379
|
+
// `reserve.borrowedAmount`: the reserve field is the whole reserve's
|
|
380
|
+
// debt, so using it would scale every borrower's upper bound by total
|
|
381
|
+
// reserve borrows. `obligation.move` passes `borrow.borrowed_amount` to
|
|
382
|
+
// both `market_value` and `market_value_upper_bound`, and this is what
|
|
383
|
+
// `is_healthy` tests — an obligation owing $100 of a reserve with $22M
|
|
384
|
+
// borrowed read as $22M.
|
|
385
|
+
const marketValueUpperBound = exactBorrowedAmount
|
|
374
386
|
.multipliedBy(upperBoundPrice)
|
|
375
387
|
.dividedBy(new BigNumber(10 ** reserve.mintDecimals));
|
|
376
388
|
borrow.marketValue = stringToDecimal(marketValue.toString());
|
|
@@ -453,6 +465,14 @@ export const compoundBorrowedAmount = (snapshotAmount, currentCumulativeBorrowRa
|
|
|
453
465
|
}
|
|
454
466
|
return snapshotAmount.multipliedBy(currentCumulativeBorrowRate.dividedBy(snapshotCumulativeBorrowRate));
|
|
455
467
|
};
|
|
468
|
+
/**
|
|
469
|
+
* @deprecated Rounds the compounded amount through `stringToDecimal`
|
|
470
|
+
* (BigNumber -> JS `number` -> `Math.round(value * WAD)`), which is lossy at
|
|
471
|
+
* WAD scale (LEN-745) — don't feed this into further aggregate/liquidation
|
|
472
|
+
* math. Kept only because `@suilend/sdk/utils/simulate` is externally
|
|
473
|
+
* reachable and deleting it would be a breaking change. For an exact
|
|
474
|
+
* compounded amount, call `compoundBorrowedAmount` directly instead.
|
|
475
|
+
*/
|
|
456
476
|
export const compoundDebt = (borrow, reserve) => {
|
|
457
477
|
const borrowCopy = { ...borrow };
|
|
458
478
|
const newCumulativeBorrowRate = decimalToBigNumber(reserve.cumulativeBorrowRate);
|