@suilend/sdk 1.1.55 → 1.1.57
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/client.js +2 -2
- package/lib/initialize.d.ts +2 -2
- package/lib/initialize.js +49 -49
- package/lib/liquidityMining.js +11 -9
- package/package.json +1 -1
- package/parsers/obligation.js +2 -0
package/client.js
CHANGED
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.SuilendClient = exports.LENDING_MARKET_TYPE = exports.LENDING_MARKET_ID = exports.LENDING_MARKETS = exports.LENDING_MARKET_REGISTRY_ID = exports.ADMIN_ADDRESS = void 0;
|
|
13
13
|
const utils_1 = require("@mysten/sui/utils");
|
|
14
14
|
const pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
|
|
15
|
-
const
|
|
15
|
+
const sui_fe_1 = require("@suilend/sui-fe");
|
|
16
16
|
const structs_1 = require("./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs");
|
|
17
17
|
const reified_1 = require("./_generated/_framework/reified");
|
|
18
18
|
const suilend_1 = require("./_generated/suilend");
|
|
@@ -682,7 +682,7 @@ class SuilendClient {
|
|
|
682
682
|
if (mergeCoins.length > 1) {
|
|
683
683
|
transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), mergeCoins.map((mc) => transaction.object(mc.coinObjectId)).slice(1));
|
|
684
684
|
}
|
|
685
|
-
const coinType = (0,
|
|
685
|
+
const coinType = (0, sui_fe_1.extractCTokenCoinType)(ctokenCoinType);
|
|
686
686
|
const [exemption] = transaction.moveCall({
|
|
687
687
|
target: `0x1::option::none`,
|
|
688
688
|
typeArguments: [
|
package/lib/initialize.d.ts
CHANGED
|
@@ -255,10 +255,10 @@ export declare const initializeSuilend: (suiClient: SuiClient, suilendClient: Su
|
|
|
255
255
|
totalDeposits: BigNumber;
|
|
256
256
|
}>;
|
|
257
257
|
reserveCoinTypes: string[];
|
|
258
|
-
reserveCoinMetadataMap: Record<string, import("@suilend/
|
|
258
|
+
reserveCoinMetadataMap: Record<string, import("@suilend/sui-fe").Token>;
|
|
259
259
|
rewardCoinTypes: string[];
|
|
260
260
|
activeRewardCoinTypes: string[];
|
|
261
|
-
rewardCoinMetadataMap: Record<string, import("@suilend/
|
|
261
|
+
rewardCoinMetadataMap: Record<string, import("@suilend/sui-fe").Token>;
|
|
262
262
|
}>;
|
|
263
263
|
export declare const initializeSuilendRewards: (reserveMap: Record<string, ParsedReserve>, activeRewardCoinTypes: string[]) => Promise<{
|
|
264
264
|
rewardPriceMap: Record<string, BigNumber | undefined>;
|
package/lib/initialize.js
CHANGED
|
@@ -49,49 +49,49 @@ exports.initializeObligations = exports.initializeSuilendRewards = exports.initi
|
|
|
49
49
|
const utils_1 = require("@mysten/sui/utils");
|
|
50
50
|
const pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
|
|
51
51
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
52
|
-
const
|
|
52
|
+
const sui_fe_1 = require("@suilend/sui-fe");
|
|
53
53
|
const client_1 = require("../client");
|
|
54
54
|
const parsers_1 = require("../parsers");
|
|
55
55
|
const simulate = __importStar(require("../utils/simulate"));
|
|
56
56
|
const constants_1 = require("./constants");
|
|
57
57
|
exports.RESERVES_CUSTOM_ORDER = [
|
|
58
58
|
// MAIN ASSETS
|
|
59
|
-
|
|
59
|
+
sui_fe_1.NORMALIZED_sSUI_COINTYPE,
|
|
60
60
|
// MAIN ASSETS - Ecosystem LSTs
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
61
|
+
sui_fe_1.NORMALIZED_kSUI_COINTYPE,
|
|
62
|
+
sui_fe_1.NORMALIZED_iSUI_COINTYPE,
|
|
63
|
+
sui_fe_1.NORMALIZED_mSUI_COINTYPE,
|
|
64
|
+
sui_fe_1.NORMALIZED_fudSUI_COINTYPE,
|
|
65
|
+
sui_fe_1.NORMALIZED_trevinSUI_COINTYPE,
|
|
66
|
+
sui_fe_1.NORMALIZED_upSUI_COINTYPE,
|
|
67
|
+
sui_fe_1.NORMALIZED_yapSUI_COINTYPE,
|
|
68
|
+
sui_fe_1.NORMALIZED_flSUI_COINTYPE,
|
|
69
|
+
sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
70
|
+
sui_fe_1.NORMALIZED_USDC_COINTYPE,
|
|
71
|
+
sui_fe_1.NORMALIZED_wUSDC_COINTYPE,
|
|
72
|
+
sui_fe_1.NORMALIZED_suiUSDT_COINTYPE,
|
|
73
|
+
sui_fe_1.NORMALIZED_wUSDT_COINTYPE,
|
|
74
|
+
sui_fe_1.NORMALIZED_AUSD_COINTYPE,
|
|
75
|
+
sui_fe_1.NORMALIZED_LBTC_COINTYPE,
|
|
76
|
+
sui_fe_1.NORMALIZED_wBTC_COINTYPE,
|
|
77
|
+
sui_fe_1.NORMALIZED_suiETH_COINTYPE,
|
|
78
|
+
sui_fe_1.NORMALIZED_WETH_COINTYPE,
|
|
79
|
+
sui_fe_1.NORMALIZED_SOL_COINTYPE,
|
|
80
80
|
// ISOLATED ASSETS
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
sui_fe_1.NORMALIZED_SEND_COINTYPE,
|
|
82
|
+
sui_fe_1.NORMALIZED_DEEP_COINTYPE,
|
|
83
|
+
sui_fe_1.NORMALIZED_WAL_COINTYPE,
|
|
84
|
+
sui_fe_1.NORMALIZED_HAEDAL_COINTYPE,
|
|
85
|
+
sui_fe_1.NORMALIZED_BLUE_COINTYPE,
|
|
86
|
+
sui_fe_1.NORMALIZED_NS_COINTYPE,
|
|
87
|
+
sui_fe_1.NORMALIZED_UP_COINTYPE,
|
|
88
|
+
sui_fe_1.NORMALIZED_KOBAN_COINTYPE,
|
|
89
|
+
sui_fe_1.NORMALIZED_mUSD_COINTYPE,
|
|
90
|
+
sui_fe_1.NORMALIZED_BUCK_COINTYPE,
|
|
91
91
|
// ISOLATED ASSETS - Memecoins
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
sui_fe_1.NORMALIZED_HIPPO_COINTYPE,
|
|
93
|
+
sui_fe_1.NORMALIZED_LOFI_COINTYPE, // Not listed
|
|
94
|
+
sui_fe_1.NORMALIZED_FUD_COINTYPE,
|
|
95
95
|
];
|
|
96
96
|
const MAYA_COINTYPE = "0x3bf0aeb7b9698b18ec7937290a5701088fcd5d43ad11a2564b074d022a6d71ec::maya::MAYA";
|
|
97
97
|
const mPOINTS_COINTYPE = "0x7bae0b3b7b6c3da899fe3f4af95b7110633499c02b8c6945110d799d99deaa68::mpoints::MPOINTS";
|
|
@@ -124,20 +124,20 @@ const initializeSuilend = (suiClient, suilendClient) => __awaiter(void 0, void 0
|
|
|
124
124
|
const uniqueRewardCoinTypes = Array.from(new Set(rewardCoinTypes));
|
|
125
125
|
const uniqueActiveRewardsCoinTypes = Array.from(new Set(activeRewardCoinTypes));
|
|
126
126
|
const [reserveCoinMetadataMap, rewardCoinMetadataMap] = yield Promise.all([
|
|
127
|
-
(0,
|
|
128
|
-
(0,
|
|
127
|
+
(0, sui_fe_1.getCoinMetadataMap)(uniqueReserveCoinTypes),
|
|
128
|
+
(0, sui_fe_1.getCoinMetadataMap)(uniqueRewardCoinTypes),
|
|
129
129
|
]);
|
|
130
130
|
const coinMetadataMap = Object.assign(Object.assign({}, reserveCoinMetadataMap), rewardCoinMetadataMap);
|
|
131
|
-
const reservesWithTemporaryPythPriceFeeds = refreshedRawReserves.filter((r) =>
|
|
131
|
+
const reservesWithTemporaryPythPriceFeeds = refreshedRawReserves.filter((r) => sui_fe_1.TEMPORARY_PYTH_PRICE_FEED_COINTYPES.includes((0, utils_1.normalizeStructTag)(r.coinType.name)));
|
|
132
132
|
for (const reserve of reservesWithTemporaryPythPriceFeeds) {
|
|
133
|
-
let
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
const
|
|
133
|
+
let cachedUsdPrice = yield (0, sui_fe_1.getPrice)((0, utils_1.normalizeStructTag)(reserve.coinType.name));
|
|
134
|
+
if (cachedUsdPrice === undefined)
|
|
135
|
+
cachedUsdPrice = 0.0001; // Non-zero price override for coinTypes with price feed overrides
|
|
136
|
+
const parsedCachedUsdPrice = BigInt(+new bignumber_js_1.default(cachedUsdPrice)
|
|
137
137
|
.times(constants_1.WAD)
|
|
138
138
|
.integerValue(bignumber_js_1.default.ROUND_DOWN));
|
|
139
|
-
reserve.price.value =
|
|
140
|
-
reserve.smoothedPrice.value =
|
|
139
|
+
reserve.price.value = parsedCachedUsdPrice;
|
|
140
|
+
reserve.smoothedPrice.value = parsedCachedUsdPrice;
|
|
141
141
|
}
|
|
142
142
|
// const walReserve = refreshedRawReserves.find(
|
|
143
143
|
// (r) => normalizeStructTag(r.coinType.name) === NORMALIZED_WAL_COINTYPE,
|
|
@@ -177,16 +177,16 @@ exports.initializeSuilend = initializeSuilend;
|
|
|
177
177
|
const initializeSuilendRewards = (reserveMap, activeRewardCoinTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
178
|
const rewardPriceMap = Object.entries(reserveMap).reduce((acc, [coinType, reserve]) => (Object.assign(Object.assign({}, acc), { [coinType]: reserve.price })), {});
|
|
179
179
|
rewardPriceMap[exports.NORMALIZED_TREATS_COINTYPE] = new bignumber_js_1.default(0.1);
|
|
180
|
-
const reservelessActiveRewardCoinTypes = activeRewardCoinTypes.filter((coinType) => !((0,
|
|
181
|
-
(0,
|
|
180
|
+
const reservelessActiveRewardCoinTypes = activeRewardCoinTypes.filter((coinType) => !((0, sui_fe_1.isSendPoints)(coinType) ||
|
|
181
|
+
(0, sui_fe_1.isSteammPoints)(coinType) ||
|
|
182
182
|
coinType === exports.NORMALIZED_MAYA_COINTYPE ||
|
|
183
183
|
coinType === exports.NORMALIZED_mPOINTS_COINTYPE) && !rewardPriceMap[coinType]);
|
|
184
|
-
const
|
|
184
|
+
const reservelessActiveRewardCachedUsdPrices = yield Promise.all(reservelessActiveRewardCoinTypes.map((coinType) => (0, sui_fe_1.getPrice)(coinType)));
|
|
185
185
|
for (let i = 0; i < reservelessActiveRewardCoinTypes.length; i++) {
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
186
|
+
const cachedUsdPrice = reservelessActiveRewardCachedUsdPrices[i];
|
|
187
|
+
if (cachedUsdPrice === undefined)
|
|
188
188
|
continue;
|
|
189
|
-
rewardPriceMap[reservelessActiveRewardCoinTypes[i]] = new bignumber_js_1.default(
|
|
189
|
+
rewardPriceMap[reservelessActiveRewardCoinTypes[i]] = new bignumber_js_1.default(cachedUsdPrice);
|
|
190
190
|
}
|
|
191
191
|
return { rewardPriceMap };
|
|
192
192
|
});
|
package/lib/liquidityMining.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getNetAprPercent = exports.getTotalAprPercent = exports.getStakingYieldAprPercent = exports.getRewardsAprPercent = exports.getDedupedPerDayRewards = exports.getDedupedAprRewards = exports.getFilteredRewards = exports.formatRewards = exports.getBorrowShare = exports.getDepositShare = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
|
-
const
|
|
9
|
+
const sui_fe_1 = require("@suilend/sui-fe");
|
|
10
10
|
const constants_1 = require("./constants");
|
|
11
11
|
const types_1 = require("./types");
|
|
12
12
|
const getDepositShare = (reserve, share) => share.div(10 ** reserve.mintDecimals).times(reserve.cTokenExchangeRate);
|
|
@@ -23,18 +23,20 @@ const formatRewards = (parsedReserveMap, coinMetadataMap, priceMap, obligations)
|
|
|
23
23
|
const rewardPrice = priceMap === null || priceMap === void 0 ? void 0 : priceMap[poolReward.coinType];
|
|
24
24
|
const isActive = nowMs >= poolReward.startTimeMs && nowMs < poolReward.endTimeMs;
|
|
25
25
|
const aprPercent = rewardPrice
|
|
26
|
-
?
|
|
27
|
-
.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
? new bignumber_js_1.default(reserve.depositsPoolRewardManager.totalShares.toString()).eq(0)
|
|
27
|
+
? new bignumber_js_1.default(0)
|
|
28
|
+
: poolReward.totalRewards
|
|
29
|
+
.times(rewardPrice)
|
|
30
|
+
.times(new bignumber_js_1.default(sui_fe_1.MS_PER_YEAR).div(poolReward.endTimeMs - poolReward.startTimeMs))
|
|
31
|
+
.div(side === types_1.Side.DEPOSIT
|
|
32
|
+
? getDepositShareUsd(reserve, new bignumber_js_1.default(reserve.depositsPoolRewardManager.totalShares.toString()))
|
|
33
|
+
: getBorrowShareUsd(reserve, new bignumber_js_1.default(reserve.borrowsPoolRewardManager.totalShares.toString())))
|
|
34
|
+
.times(100)
|
|
33
35
|
: undefined;
|
|
34
36
|
const perDay = rewardPrice
|
|
35
37
|
? undefined
|
|
36
38
|
: poolReward.totalRewards
|
|
37
|
-
.times(new bignumber_js_1.default(
|
|
39
|
+
.times(new bignumber_js_1.default(sui_fe_1.MS_PER_YEAR).div(poolReward.endTimeMs - poolReward.startTimeMs))
|
|
38
40
|
.div(365)
|
|
39
41
|
.div(side === types_1.Side.DEPOSIT
|
|
40
42
|
? (0, exports.getDepositShare)(reserve, new bignumber_js_1.default(reserve.depositsPoolRewardManager.totalShares.toString()))
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"1.1.
|
|
1
|
+
{"name":"@suilend/sdk","version":"1.1.57","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","./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/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","./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/solendprotocol/suilend-public.git"},"bugs":{"url":"https://github.com/solendprotocol/suilend-public/issues"},"dependencies":{"@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","p-limit":"3.1.0","uuid":"^11.0.3"},"devDependencies":{"ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"1.6.0","@mysten/sui":"1.28.2","@suilend/sui-fe":"^0.2.72"}}
|
package/parsers/obligation.js
CHANGED
|
@@ -82,6 +82,8 @@ const parseObligation = (obligation, parsedReserveMap) => {
|
|
|
82
82
|
};
|
|
83
83
|
});
|
|
84
84
|
const netValueUsd = totalDepositedAmountUsd.minus(totalBorrowedAmountUsd);
|
|
85
|
+
// Cap `minPriceBorrowLimitUsd` at $20m (account borrow limit)
|
|
86
|
+
minPriceBorrowLimitUsd = bignumber_js_1.default.min(minPriceBorrowLimitUsd, 20 * 10 ** 6);
|
|
85
87
|
const weightedConservativeBorrowUtilizationPercent = minPriceBorrowLimitUsd.eq(0)
|
|
86
88
|
? new bignumber_js_1.default(0)
|
|
87
89
|
: maxPriceWeightedBorrowsUsd.div(minPriceBorrowLimitUsd).times(100);
|