@suilend/sdk 1.1.88 → 1.1.90
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/lib/initialize.js +1 -1
- package/package.json +1 -1
- package/parsers/obligation.d.ts +1 -1
- package/parsers/obligation.js +4 -3
- package/strategies.js +26 -6
package/lib/initialize.js
CHANGED
|
@@ -281,7 +281,7 @@ const initializeObligations = (suiClient, suilendClient, refreshedRawReserves, r
|
|
|
281
281
|
...obligationOwnerCaps.map((ownerCap) => ownerCap.obligationId),
|
|
282
282
|
].map((obligationId) => client_1.SuilendClient.getObligation(obligationId, suilendClient.lendingMarket.$typeArgs, suiClient))))
|
|
283
283
|
.map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves))
|
|
284
|
-
.map((refreshedObligation) => (0, parsers_1.parseObligation)(refreshedObligation, reserveMap))
|
|
284
|
+
.map((refreshedObligation) => (0, parsers_1.parseObligation)(refreshedObligation, reserveMap, strategyOwnerCaps.some((soc) => soc.obligationId === refreshedObligation.id)))
|
|
285
285
|
.sort((a, b) => +b.netValueUsd.minus(a.netValueUsd));
|
|
286
286
|
// Divide into strategy and non-strategy
|
|
287
287
|
const strategyObligations = obligations.filter((o) => strategyOwnerCaps.some((soc) => soc.obligationId === o.id));
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"1.1.
|
|
1
|
+
{"name":"@suilend/sdk","version":"1.1.90","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/strategyOwnerCap":"./lib/strategyOwnerCap.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.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":"./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","./_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","./_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/i64/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ts-node ./release.ts && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/suilend-fe-public.git"},"bugs":{"url":"https://github.com/suilend/suilend-fe-public/issues"},"dependencies":{"@7kprotocol/sdk-ts":"^3.4.1","@cetusprotocol/aggregator-sdk":"^1.2.1","@flowx-finance/sdk":"^1.13.5","@pythnetwork/pyth-sui-js":"^2.2.0","@suilend/springsui-sdk":"^1.0.27","aftermath-ts-sdk":"^1.3.22","bignumber.js":"^9.1.2","bn.js":"^5.2.2","crypto-js":"^4.2.0","lodash":"^4.17.21","p-limit":"3.1.0","uuid":"^11.0.3"},"devDependencies":{"@types/bn.js":"^5.2.0","@types/lodash":"^4.17.20","ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"1.8.1","@mysten/sui":"1.42.0","@suilend/sui-fe":"^0.3.40"},"overrides":{"chalk":"5.3.0","strip-ansi":"7.1.0","color-convert":"2.0.1","color-name":"1.1.4","is-core-module":"2.13.1","error-ex":"1.3.2","has-ansi":"5.0.1"}}
|
package/parsers/obligation.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type ParsedObligation = ReturnType<typeof parseObligation>;
|
|
|
5
5
|
export type ParsedPosition = ParsedObligation["deposits"][0] | ParsedObligation["borrows"][0];
|
|
6
6
|
export declare const parseObligation: (obligation: Obligation<string>, parsedReserveMap: {
|
|
7
7
|
[coinType: string]: ParsedReserve;
|
|
8
|
-
}) => {
|
|
8
|
+
}, isStrategy?: boolean) => {
|
|
9
9
|
id: string;
|
|
10
10
|
depositedAmountUsd: BigNumber;
|
|
11
11
|
borrowedAmountUsd: BigNumber;
|
package/parsers/obligation.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.parseObligation = void 0;
|
|
|
7
7
|
const utils_1 = require("@mysten/sui/utils");
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
9
|
const constants_1 = require("../lib/constants");
|
|
10
|
-
const parseObligation = (obligation, parsedReserveMap) => {
|
|
10
|
+
const parseObligation = (obligation, parsedReserveMap, isStrategy) => {
|
|
11
11
|
let totalDepositedAmountUsd = new bignumber_js_1.default(0);
|
|
12
12
|
let totalBorrowedAmountUsd = new bignumber_js_1.default(0);
|
|
13
13
|
let weightedBorrowsUsd = new bignumber_js_1.default(0);
|
|
@@ -82,8 +82,9 @@ const parseObligation = (obligation, parsedReserveMap) => {
|
|
|
82
82
|
};
|
|
83
83
|
});
|
|
84
84
|
const netValueUsd = totalDepositedAmountUsd.minus(totalBorrowedAmountUsd);
|
|
85
|
-
// Cap `minPriceBorrowLimitUsd` at $30m (account borrow limit)
|
|
86
|
-
|
|
85
|
+
// Cap `minPriceBorrowLimitUsd` at $30m (account borrow limit) -- NON-STRATEGY OBLIGATIONS ONLY
|
|
86
|
+
if (!isStrategy)
|
|
87
|
+
minPriceBorrowLimitUsd = bignumber_js_1.default.min(minPriceBorrowLimitUsd, 30 * 10 ** 6);
|
|
87
88
|
const weightedConservativeBorrowUtilizationPercent = minPriceBorrowLimitUsd.eq(0)
|
|
88
89
|
? new bignumber_js_1.default(0)
|
|
89
90
|
: maxPriceWeightedBorrowsUsd.div(minPriceBorrowLimitUsd).times(100);
|
package/strategies.js
CHANGED
|
@@ -307,12 +307,12 @@ lstMap, strategyType, deposits, _borrowedAmount) => {
|
|
|
307
307
|
.minus(borrowedAmount.times(borrowReserve.price)),
|
|
308
308
|
weightedBorrowsUsd: new bignumber_js_1.default(borrowedAmount.times(borrowReserve.price)).times(borrowReserve.config.borrowWeightBps.div(10000)),
|
|
309
309
|
maxPriceWeightedBorrowsUsd: new bignumber_js_1.default(borrowedAmount.times(borrowReserve.maxPrice)).times(borrowReserve.config.borrowWeightBps.div(10000)),
|
|
310
|
-
minPriceBorrowLimitUsd:
|
|
310
|
+
minPriceBorrowLimitUsd: deposits.reduce((acc, deposit) => {
|
|
311
311
|
const depositReserve = reserveMap[deposit.coinType];
|
|
312
312
|
return acc.plus(deposit.depositedAmount
|
|
313
313
|
.times(depositReserve.minPrice)
|
|
314
314
|
.times(depositReserve.config.openLtvPct / 100));
|
|
315
|
-
}, new bignumber_js_1.default(0)),
|
|
315
|
+
}, new bignumber_js_1.default(0)), // Not capped to $30m
|
|
316
316
|
unhealthyBorrowValueUsd: deposits.reduce((acc, deposit) => {
|
|
317
317
|
const depositReserve = reserveMap[deposit.coinType];
|
|
318
318
|
return acc.plus(deposit.depositedAmount
|
|
@@ -1480,8 +1480,18 @@ transaction, dryRunTransaction) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
1480
1480
|
stepRepaidAmount: stepRepaidAmount.toFixed(20),
|
|
1481
1481
|
isMaxRepay,
|
|
1482
1482
|
}, null, 2));
|
|
1483
|
-
|
|
1484
|
-
|
|
1483
|
+
try {
|
|
1484
|
+
const txCopy = transactions_1.Transaction.from(transaction);
|
|
1485
|
+
suilendClient.repay(obligationId, borrowReserve.coinType, stepSuiCoin, txCopy);
|
|
1486
|
+
txCopy.transferObjects([stepSuiCoin], _address);
|
|
1487
|
+
yield dryRunTransaction(txCopy); // Throws error if fails
|
|
1488
|
+
transaction = txCopy;
|
|
1489
|
+
}
|
|
1490
|
+
catch (err) {
|
|
1491
|
+
// Don't block user if fails
|
|
1492
|
+
console.error(err);
|
|
1493
|
+
transaction.transferObjects([stepSuiCoin], _address);
|
|
1494
|
+
}
|
|
1485
1495
|
// 3.2) Update state
|
|
1486
1496
|
borrowedAmount = borrowedAmount.minus(stepRepaidAmount);
|
|
1487
1497
|
console.log(`[unloopStrategyToExposure] ${i} repay_sui.update_state |`, JSON.stringify({
|
|
@@ -1605,8 +1615,18 @@ transaction, dryRunTransaction) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
1605
1615
|
stepRepaidAmount: stepRepaidAmount.toFixed(20),
|
|
1606
1616
|
isMaxRepay,
|
|
1607
1617
|
}, null, 2));
|
|
1608
|
-
|
|
1609
|
-
|
|
1618
|
+
try {
|
|
1619
|
+
const txCopy = transactions_1.Transaction.from(transaction);
|
|
1620
|
+
suilendClient.repay(obligationId, borrowReserve.coinType, stepBorrowCoin, txCopy);
|
|
1621
|
+
txCopy.transferObjects([stepBorrowCoin], _address);
|
|
1622
|
+
yield dryRunTransaction(txCopy); // Throws error if fails
|
|
1623
|
+
transaction = txCopy;
|
|
1624
|
+
}
|
|
1625
|
+
catch (err) {
|
|
1626
|
+
// Don't block user if fails
|
|
1627
|
+
console.error(err);
|
|
1628
|
+
transaction.transferObjects([stepBorrowCoin], _address);
|
|
1629
|
+
}
|
|
1610
1630
|
// 3.2) Update state
|
|
1611
1631
|
borrowedAmount = borrowedAmount.minus(stepRepaidAmount);
|
|
1612
1632
|
console.log(`[unloopStrategyToExposure] ${i} repay_borrows.update_state |`, JSON.stringify({
|