@suilend/sdk 3.0.8 → 4.0.0
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/_generated/_dependencies/source/0x1/ascii/structs.d.ts +4 -4
- package/_generated/_dependencies/source/0x1/ascii/structs.js +42 -41
- package/_generated/_dependencies/source/0x1/option/structs.js +22 -26
- package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +3 -3
- package/_generated/_dependencies/source/0x1/type-name/structs.js +21 -25
- package/_generated/_dependencies/source/0x2/bag/structs.d.ts +5 -5
- package/_generated/_dependencies/source/0x2/bag/structs.js +22 -25
- package/_generated/_dependencies/source/0x2/balance/structs.d.ts +4 -4
- package/_generated/_dependencies/source/0x2/balance/structs.js +42 -41
- package/_generated/_dependencies/source/0x2/object/structs.d.ts +5 -5
- package/_generated/_dependencies/source/0x2/object/structs.js +42 -41
- package/_generated/_dependencies/source/0x2/object-table/structs.d.ts +5 -5
- package/_generated/_dependencies/source/0x2/object-table/structs.js +22 -25
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.d.ts +3 -3
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +22 -25
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.d.ts +9 -9
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +24 -25
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.d.ts +21 -21
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +23 -25
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +2 -2
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +21 -25
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.d.ts +52 -52
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +45 -41
- package/_generated/_framework/vector.js +9 -6
- package/_generated/suilend/cell/structs.d.ts +1 -1
- package/_generated/suilend/cell/structs.js +21 -25
- package/_generated/suilend/decimal/structs.d.ts +2 -2
- package/_generated/suilend/decimal/structs.js +21 -25
- package/_generated/suilend/lending-market/structs.d.ts +129 -129
- package/_generated/suilend/lending-market/structs.js +391 -265
- package/_generated/suilend/liquidity-mining/structs.d.ts +44 -44
- package/_generated/suilend/liquidity-mining/structs.js +122 -89
- package/_generated/suilend/obligation/structs.d.ts +98 -98
- package/_generated/suilend/obligation/structs.js +194 -121
- package/_generated/suilend/rate-limiter/structs.d.ts +12 -12
- package/_generated/suilend/rate-limiter/structs.js +46 -41
- package/_generated/suilend/reserve/structs.d.ts +128 -128
- package/_generated/suilend/reserve/structs.js +243 -153
- package/_generated/suilend/reserve-config/structs.d.ts +30 -30
- package/_generated/suilend/reserve-config/structs.js +60 -41
- package/api/events.js +5 -14
- package/client.js +267 -319
- package/lib/initialize.d.ts +2 -2
- package/lib/initialize.js +26 -31
- package/lib/liquidityMining.js +15 -19
- package/lib/pyth.js +6 -15
- package/lib/pythAdapter.js +96 -112
- package/lib/strategyOwnerCap.js +8 -17
- package/margin/margin/admin_cap.d.ts +2 -2
- package/margin/margin/deps/std/type_name.d.ts +1 -1
- package/margin/margin/deps/suilend/lending_market.d.ts +2 -2
- package/margin/margin/market.d.ts +11 -11
- package/margin/margin/market.js +22 -22
- package/margin/margin/permissions.js +14 -14
- package/margin/margin/position.d.ts +47 -47
- package/margin/margin/position.js +10 -10
- package/margin/margin/router.d.ts +5 -5
- package/margin/margin/router.js +16 -16
- package/margin/margin/version.d.ts +1 -1
- package/margin/utils/index.js +22 -36
- package/package.json +1 -1
- package/parsers/apiReserveAssetDataEvent.js +4 -1
- package/parsers/lendingMarket.js +3 -4
- package/parsers/reserve.js +4 -1
- package/strategies.js +188 -204
- package/swap/quote.d.ts +1 -1
- package/swap/quote.js +28 -39
- package/swap/transaction.js +17 -26
- package/utils/events.js +20 -32
- package/utils/obligation.js +111 -135
- package/utils/simulate.js +16 -24
package/lib/initialize.d.ts
CHANGED
|
@@ -257,10 +257,10 @@ export declare const initializeSuilend: (suiGrpcClient: SuiGrpcClient, suilendCl
|
|
|
257
257
|
totalDeposits: BigNumber;
|
|
258
258
|
}>;
|
|
259
259
|
reserveCoinTypes: string[];
|
|
260
|
-
reserveCoinMetadataMap: Record<string, import("@suilend/sui-
|
|
260
|
+
reserveCoinMetadataMap: Record<string, import("@suilend/sui-core").Token>;
|
|
261
261
|
rewardCoinTypes: string[];
|
|
262
262
|
activeRewardCoinTypes: string[];
|
|
263
|
-
rewardCoinMetadataMap: Record<string, import("@suilend/sui-
|
|
263
|
+
rewardCoinMetadataMap: Record<string, import("@suilend/sui-core").Token>;
|
|
264
264
|
}>;
|
|
265
265
|
export declare const initializeSuilendRewards: (reserveMap: Record<string, ParsedReserve>, activeRewardCoinTypes: string[]) => Promise<{
|
|
266
266
|
rewardPriceMap: Record<string, BigNumber | undefined>;
|
package/lib/initialize.js
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
11
2
|
import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
12
3
|
import BigNumber from "bignumber.js";
|
|
13
|
-
import { NORMALIZED_ALKIMI_COINTYPE, NORMALIZED_AUSD_COINTYPE, NORMALIZED_BLUE_COINTYPE, NORMALIZED_BUCK_COINTYPE, NORMALIZED_DEEP_COINTYPE, NORMALIZED_DMC_COINTYPE, NORMALIZED_FUD_COINTYPE, NORMALIZED_HAEDAL_COINTYPE, NORMALIZED_HIPPO_COINTYPE, NORMALIZED_IKA_COINTYPE, NORMALIZED_KOBAN_COINTYPE, NORMALIZED_LBTC_COINTYPE, NORMALIZED_NS_COINTYPE, NORMALIZED_SEND_COINTYPE, NORMALIZED_SEND_POINTS_S1_COINTYPE, NORMALIZED_SEND_POINTS_S2_COINTYPE, NORMALIZED_SOL_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_UP_COINTYPE, NORMALIZED_USDB_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_USDsui_COINTYPE, NORMALIZED_WAL_COINTYPE, NORMALIZED_WBTC_COINTYPE, NORMALIZED_WETH_COINTYPE, NORMALIZED_XAUm_COINTYPE, NORMALIZED_eEARN_COINTYPE, NORMALIZED_eTHIRD_COINTYPE, NORMALIZED_flSUI_COINTYPE, NORMALIZED_fpSUI_COINTYPE, NORMALIZED_fudSUI_COINTYPE, NORMALIZED_iSUI_COINTYPE, NORMALIZED_jugSUI_COINTYPE, NORMALIZED_kSUI_COINTYPE, NORMALIZED_mSUI_COINTYPE, NORMALIZED_mUSD_COINTYPE, NORMALIZED_oshiSUI_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_sdeUSD_COINTYPE, NORMALIZED_stratSUI_COINTYPE, NORMALIZED_suiETH_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiUSDe_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_trevinSUI_COINTYPE, NORMALIZED_upSUI_COINTYPE, NORMALIZED_wUSDC_COINTYPE, NORMALIZED_wUSDT_COINTYPE, NORMALIZED_xBTC_COINTYPE, NORMALIZED_yapSUI_COINTYPE, TEMPORARY_PYTH_PRICE_FEED_COINTYPES, getAllOwnedObjects, getCoinMetadataMap, getPrice, isSendPoints, isSteammPoints, } from "@suilend/sui-
|
|
4
|
+
import { NORMALIZED_ALKIMI_COINTYPE, NORMALIZED_AUSD_COINTYPE, NORMALIZED_BLUE_COINTYPE, NORMALIZED_BUCK_COINTYPE, NORMALIZED_DEEP_COINTYPE, NORMALIZED_DMC_COINTYPE, NORMALIZED_FUD_COINTYPE, NORMALIZED_HAEDAL_COINTYPE, NORMALIZED_HIPPO_COINTYPE, NORMALIZED_IKA_COINTYPE, NORMALIZED_KOBAN_COINTYPE, NORMALIZED_LBTC_COINTYPE, NORMALIZED_NS_COINTYPE, NORMALIZED_SEND_COINTYPE, NORMALIZED_SEND_POINTS_S1_COINTYPE, NORMALIZED_SEND_POINTS_S2_COINTYPE, NORMALIZED_SOL_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_UP_COINTYPE, NORMALIZED_USDB_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_USDsui_COINTYPE, NORMALIZED_WAL_COINTYPE, NORMALIZED_WBTC_COINTYPE, NORMALIZED_WETH_COINTYPE, NORMALIZED_XAUm_COINTYPE, NORMALIZED_eEARN_COINTYPE, NORMALIZED_eTHIRD_COINTYPE, NORMALIZED_flSUI_COINTYPE, NORMALIZED_fpSUI_COINTYPE, NORMALIZED_fudSUI_COINTYPE, NORMALIZED_iSUI_COINTYPE, NORMALIZED_jugSUI_COINTYPE, NORMALIZED_kSUI_COINTYPE, NORMALIZED_mSUI_COINTYPE, NORMALIZED_mUSD_COINTYPE, NORMALIZED_oshiSUI_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_sdeUSD_COINTYPE, NORMALIZED_stratSUI_COINTYPE, NORMALIZED_suiETH_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiUSDe_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_trevinSUI_COINTYPE, NORMALIZED_upSUI_COINTYPE, NORMALIZED_wUSDC_COINTYPE, NORMALIZED_wUSDT_COINTYPE, NORMALIZED_xBTC_COINTYPE, NORMALIZED_yapSUI_COINTYPE, TEMPORARY_PYTH_PRICE_FEED_COINTYPES, getAllOwnedObjects, getCoinMetadataMap, getPrice, isSendPoints, isSteammPoints, } from "@suilend/sui-core";
|
|
14
5
|
import { LENDING_MARKET_ID, SuilendClient } from "../client.js";
|
|
15
6
|
import { parseLendingMarket, parseObligation } from "../parsers/index.js";
|
|
16
7
|
import * as simulate from "../utils/simulate.js";
|
|
@@ -94,7 +85,7 @@ const TREATS_COINTYPE = "0x0dadb7fa2771c2952f96161fc1f0c105d1f22d53926b9ff2498a8
|
|
|
94
85
|
export const NORMALIZED_MAYA_COINTYPE = normalizeStructTag(MAYA_COINTYPE);
|
|
95
86
|
export const NORMALIZED_mPOINTS_COINTYPE = normalizeStructTag(mPOINTS_COINTYPE);
|
|
96
87
|
export const NORMALIZED_TREATS_COINTYPE = normalizeStructTag(TREATS_COINTYPE);
|
|
97
|
-
export const initializeSuilend = (suiGrpcClient, suilendClient, lendingMarketMetadata, fallbackPythEndpoint) =>
|
|
88
|
+
export const initializeSuilend = async (suiGrpcClient, suilendClient, lendingMarketMetadata, fallbackPythEndpoint) => {
|
|
98
89
|
const nowMs = Date.now();
|
|
99
90
|
const nowS = Math.floor(nowMs / 1000);
|
|
100
91
|
const interestCompoundedRawReserves = suilendClient.lendingMarket.reserves.map((r) => simulate.compoundReserveInterest(r, nowS));
|
|
@@ -110,16 +101,16 @@ export const initializeSuilend = (suiGrpcClient, suilendClient, lendingMarketMet
|
|
|
110
101
|
}
|
|
111
102
|
}
|
|
112
103
|
// Get a working Pyth endpoint (try primary, fallback to fallbackPythEndpoint if provided)
|
|
113
|
-
const pythEndpoint =
|
|
104
|
+
const pythEndpoint = await getWorkingPythEndpoint(fallbackPythEndpoint);
|
|
114
105
|
const pythConnection = new SuiPriceServiceConnection(pythEndpoint, {
|
|
115
106
|
timeout: 30 * 1000,
|
|
116
107
|
});
|
|
117
|
-
const [refreshedReservesWithoutTemporaryPythPriceFeeds] =
|
|
108
|
+
const [refreshedReservesWithoutTemporaryPythPriceFeeds] = await Promise.all([
|
|
118
109
|
simulate.refreshReservePrice(reservesWithoutTemporaryPythPriceFeeds, pythConnection),
|
|
119
|
-
Promise.all(reservesWithTemporaryPythPriceFeeds.map((reserve) => (() =>
|
|
110
|
+
Promise.all(reservesWithTemporaryPythPriceFeeds.map((reserve) => (async () => {
|
|
120
111
|
let cachedUsdPrice;
|
|
121
112
|
try {
|
|
122
|
-
cachedUsdPrice =
|
|
113
|
+
cachedUsdPrice = await getPrice(normalizeStructTag(reserve.coinType.name));
|
|
123
114
|
}
|
|
124
115
|
catch (err) {
|
|
125
116
|
console.error(err);
|
|
@@ -131,7 +122,7 @@ export const initializeSuilend = (suiGrpcClient, suilendClient, lendingMarketMet
|
|
|
131
122
|
.integerValue(BigNumber.ROUND_DOWN));
|
|
132
123
|
reserve.price.value = parsedCachedUsdPrice;
|
|
133
124
|
reserve.smoothedPrice.value = parsedCachedUsdPrice;
|
|
134
|
-
})
|
|
125
|
+
})())),
|
|
135
126
|
]);
|
|
136
127
|
// Recombine reserves back into a single array
|
|
137
128
|
const refreshedRawReserves = [
|
|
@@ -164,12 +155,16 @@ export const initializeSuilend = (suiGrpcClient, suilendClient, lendingMarketMet
|
|
|
164
155
|
const uniqueReserveCoinTypes = Array.from(new Set(reserveCoinTypes));
|
|
165
156
|
const uniqueRewardCoinTypes = Array.from(new Set(rewardCoinTypes));
|
|
166
157
|
const uniqueActiveRewardsCoinTypes = Array.from(new Set(activeRewardCoinTypes));
|
|
167
|
-
const [miscCoinMetadataMap, reserveCoinMetadataMap, rewardCoinMetadataMap] =
|
|
158
|
+
const [miscCoinMetadataMap, reserveCoinMetadataMap, rewardCoinMetadataMap] = await Promise.all([
|
|
168
159
|
getCoinMetadataMap(uniqueMiscCoinTypes),
|
|
169
160
|
getCoinMetadataMap(uniqueReserveCoinTypes),
|
|
170
161
|
getCoinMetadataMap(uniqueRewardCoinTypes),
|
|
171
162
|
]);
|
|
172
|
-
const coinMetadataMap =
|
|
163
|
+
const coinMetadataMap = {
|
|
164
|
+
...miscCoinMetadataMap,
|
|
165
|
+
...reserveCoinMetadataMap,
|
|
166
|
+
...rewardCoinMetadataMap,
|
|
167
|
+
};
|
|
173
168
|
// const walReserve = refreshedRawReserves.find(
|
|
174
169
|
// (r) => normalizeStructTag(r.coinType.name) === NORMALIZED_WAL_COINTYPE,
|
|
175
170
|
// );
|
|
@@ -193,7 +188,7 @@ export const initializeSuilend = (suiGrpcClient, suilendClient, lendingMarketMet
|
|
|
193
188
|
return aCustomOrderIndex > -1 ? -1 : 1;
|
|
194
189
|
});
|
|
195
190
|
}
|
|
196
|
-
const reserveMap = lendingMarket.reserves.reduce((acc, reserve) => (
|
|
191
|
+
const reserveMap = lendingMarket.reserves.reduce((acc, reserve) => ({ ...acc, [reserve.coinType]: reserve }), {});
|
|
197
192
|
return {
|
|
198
193
|
lendingMarket,
|
|
199
194
|
coinMetadataMap,
|
|
@@ -205,15 +200,15 @@ export const initializeSuilend = (suiGrpcClient, suilendClient, lendingMarketMet
|
|
|
205
200
|
activeRewardCoinTypes: uniqueActiveRewardsCoinTypes,
|
|
206
201
|
rewardCoinMetadataMap,
|
|
207
202
|
};
|
|
208
|
-
}
|
|
209
|
-
export const initializeSuilendRewards = (reserveMap, activeRewardCoinTypes) =>
|
|
210
|
-
const rewardPriceMap = Object.entries(reserveMap).reduce((acc, [coinType, reserve]) => (
|
|
203
|
+
};
|
|
204
|
+
export const initializeSuilendRewards = async (reserveMap, activeRewardCoinTypes) => {
|
|
205
|
+
const rewardPriceMap = Object.entries(reserveMap).reduce((acc, [coinType, reserve]) => ({ ...acc, [coinType]: reserve.price }), {});
|
|
211
206
|
rewardPriceMap[NORMALIZED_TREATS_COINTYPE] = new BigNumber(0.1);
|
|
212
207
|
const reservelessActiveRewardCoinTypes = activeRewardCoinTypes.filter((coinType) => !(isSendPoints(coinType) ||
|
|
213
208
|
isSteammPoints(coinType) ||
|
|
214
209
|
coinType === NORMALIZED_MAYA_COINTYPE ||
|
|
215
210
|
coinType === NORMALIZED_mPOINTS_COINTYPE) && !rewardPriceMap[coinType]);
|
|
216
|
-
const reservelessActiveRewardCachedUsdPrices =
|
|
211
|
+
const reservelessActiveRewardCachedUsdPrices = await Promise.all(reservelessActiveRewardCoinTypes.map((coinType) => getPrice(coinType)));
|
|
217
212
|
for (let i = 0; i < reservelessActiveRewardCoinTypes.length; i++) {
|
|
218
213
|
const cachedUsdPrice = reservelessActiveRewardCachedUsdPrices[i];
|
|
219
214
|
if (cachedUsdPrice === undefined)
|
|
@@ -221,8 +216,8 @@ export const initializeSuilendRewards = (reserveMap, activeRewardCoinTypes) => _
|
|
|
221
216
|
rewardPriceMap[reservelessActiveRewardCoinTypes[i]] = new BigNumber(cachedUsdPrice);
|
|
222
217
|
}
|
|
223
218
|
return { rewardPriceMap };
|
|
224
|
-
}
|
|
225
|
-
export const initializeObligations = (suiGrpcClient, suilendClient, refreshedRawReserves, reserveMap, address) =>
|
|
219
|
+
};
|
|
220
|
+
export const initializeObligations = async (suiGrpcClient, suilendClient, refreshedRawReserves, reserveMap, address) => {
|
|
226
221
|
if (!address)
|
|
227
222
|
return {
|
|
228
223
|
strategyOwnerCaps: [],
|
|
@@ -230,12 +225,12 @@ export const initializeObligations = (suiGrpcClient, suilendClient, refreshedRaw
|
|
|
230
225
|
obligationOwnerCaps: [],
|
|
231
226
|
obligations: [],
|
|
232
227
|
};
|
|
233
|
-
const [strategyOwnerCaps, obligationOwnerCaps] =
|
|
234
|
-
(() =>
|
|
228
|
+
const [strategyOwnerCaps, obligationOwnerCaps] = await Promise.all([
|
|
229
|
+
(async () => {
|
|
235
230
|
const hasStrategies = Object.values(STRATEGY_TYPE_INFO_MAP).some((info) => info.lendingMarketId === suilendClient.lendingMarket.id);
|
|
236
231
|
if (!hasStrategies)
|
|
237
232
|
return [];
|
|
238
|
-
const objects =
|
|
233
|
+
const objects = await getAllOwnedObjects(suiGrpcClient, address, `${STRATEGY_WRAPPER_PACKAGE_ID_V1}::strategy_wrapper::StrategyOwnerCap<${suilendClient.lendingMarket.$typeArgs[0]}>`);
|
|
239
234
|
return objects.map((obj) => {
|
|
240
235
|
const json = obj.json;
|
|
241
236
|
const id = json.id;
|
|
@@ -250,10 +245,10 @@ export const initializeObligations = (suiGrpcClient, suilendClient, refreshedRaw
|
|
|
250
245
|
};
|
|
251
246
|
return result;
|
|
252
247
|
});
|
|
253
|
-
})
|
|
248
|
+
})(),
|
|
254
249
|
SuilendClient.getObligationOwnerCaps(address, suilendClient.lendingMarket.$typeArgs, suiGrpcClient),
|
|
255
250
|
]);
|
|
256
|
-
const obligations = (
|
|
251
|
+
const obligations = (await Promise.all([
|
|
257
252
|
...strategyOwnerCaps.map((soc) => soc.obligationId),
|
|
258
253
|
...obligationOwnerCaps.map((ownerCap) => ownerCap.obligationId),
|
|
259
254
|
].map((obligationId) => SuilendClient.getObligation(obligationId, suilendClient.lendingMarket.$typeArgs, suiGrpcClient))))
|
|
@@ -269,4 +264,4 @@ export const initializeObligations = (suiGrpcClient, suilendClient, refreshedRaw
|
|
|
269
264
|
obligationOwnerCaps,
|
|
270
265
|
obligations: nonStrategyObligations,
|
|
271
266
|
};
|
|
272
|
-
}
|
|
267
|
+
};
|
package/lib/liquidityMining.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
3
|
-
import { MS_PER_YEAR, NORMALIZED_eEARN_COINTYPE, NORMALIZED_eTHIRD_COINTYPE, NORMALIZED_sdeUSD_COINTYPE, isSendPoints, } from "@suilend/sui-
|
|
3
|
+
import { MS_PER_YEAR, NORMALIZED_eEARN_COINTYPE, NORMALIZED_eTHIRD_COINTYPE, NORMALIZED_sdeUSD_COINTYPE, isSendPoints, } from "@suilend/sui-core";
|
|
4
4
|
import { WAD } from "./constants.js";
|
|
5
5
|
import { Side } from "./types.js";
|
|
6
6
|
export const getDepositShare = (reserve, share) => share.div(10 ** reserve.mintDecimals).times(reserve.cTokenExchangeRate);
|
|
@@ -12,7 +12,7 @@ export const formatRewards = (parsedReserveMap, coinMetadataMap, priceMap, oblig
|
|
|
12
12
|
const rewardMap = {};
|
|
13
13
|
const getRewardSummary = (reserve, poolReward, side) => {
|
|
14
14
|
const rewardCoinMetadata = coinMetadataMap[poolReward.coinType];
|
|
15
|
-
const rewardPrice = priceMap
|
|
15
|
+
const rewardPrice = priceMap?.[poolReward.coinType];
|
|
16
16
|
const isActive = nowMs >= poolReward.startTimeMs && nowMs < poolReward.endTimeMs;
|
|
17
17
|
const aprPercent = rewardPrice
|
|
18
18
|
? new BigNumber(reserve.depositsPoolRewardManager.totalShares.toString()).eq(0)
|
|
@@ -48,7 +48,7 @@ export const formatRewards = (parsedReserveMap, coinMetadataMap, priceMap, oblig
|
|
|
48
48
|
perDay,
|
|
49
49
|
side,
|
|
50
50
|
},
|
|
51
|
-
obligationClaims: Object.fromEntries((obligations
|
|
51
|
+
obligationClaims: Object.fromEntries((obligations ?? [])
|
|
52
52
|
.map((obligation) => {
|
|
53
53
|
const claim = getObligationClaim(obligation, poolReward, side === Side.DEPOSIT
|
|
54
54
|
? reserve.depositsPoolRewardManager.id
|
|
@@ -96,7 +96,7 @@ const getObligationClaim = (obligation, poolReward, reservePoolManagerId, reserv
|
|
|
96
96
|
if (!userReward)
|
|
97
97
|
return;
|
|
98
98
|
return {
|
|
99
|
-
claimableAmount:
|
|
99
|
+
claimableAmount: userReward?.earnedRewards
|
|
100
100
|
? new BigNumber(userReward.earnedRewards.value.toString())
|
|
101
101
|
.div(WAD)
|
|
102
102
|
.div(10 ** poolReward.mintDecimals)
|
|
@@ -132,26 +132,22 @@ export const getDedupedPerDayRewards = (filteredRewards) => {
|
|
|
132
132
|
return result;
|
|
133
133
|
};
|
|
134
134
|
export const getRewardsAprPercent = (side, filteredRewards) => getDedupedAprRewards(filteredRewards).reduce((acc, reward) => acc.plus(reward.stats.aprPercent.times(side === Side.DEPOSIT ? 1 : -1)), new BigNumber(0));
|
|
135
|
-
export const getStakingYieldAprPercent = (side, coinType, lstStatsMap, sdeUsdAprPercent, eThirdAprPercent, eEarnAprPercent) =>
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
?
|
|
140
|
-
: coinType ===
|
|
141
|
-
?
|
|
142
|
-
: coinType
|
|
143
|
-
|
|
144
|
-
: (_a = lstStatsMap[coinType]) === null || _a === void 0 ? void 0 : _a.aprPercent
|
|
145
|
-
: undefined;
|
|
146
|
-
};
|
|
135
|
+
export const getStakingYieldAprPercent = (side, coinType, lstStatsMap, sdeUsdAprPercent, eThirdAprPercent, eEarnAprPercent) => side === Side.DEPOSIT
|
|
136
|
+
? coinType === NORMALIZED_sdeUSD_COINTYPE
|
|
137
|
+
? sdeUsdAprPercent
|
|
138
|
+
: coinType === NORMALIZED_eTHIRD_COINTYPE
|
|
139
|
+
? eThirdAprPercent
|
|
140
|
+
: coinType === NORMALIZED_eEARN_COINTYPE
|
|
141
|
+
? eEarnAprPercent
|
|
142
|
+
: lstStatsMap[coinType]?.aprPercent
|
|
143
|
+
: undefined;
|
|
147
144
|
export const getTotalAprPercent = (side, aprPercent, filteredRewards, stakingYieldAprPercent) => aprPercent
|
|
148
145
|
.plus(getRewardsAprPercent(side, filteredRewards))
|
|
149
|
-
.plus(stakingYieldAprPercent
|
|
146
|
+
.plus(stakingYieldAprPercent ?? 0);
|
|
150
147
|
export const getNetAprPercent = (obligation, rewardMap, lstStatsMap, sdeUsdAprPercent, eThirdAprPercent, eEarnAprPercent, noShares) => {
|
|
151
148
|
const weightedDepositedAmountUsd_aprPercent = obligation.deposits.reduce((acc, deposit) => {
|
|
152
|
-
var _a;
|
|
153
149
|
const weightedDepositedAmountUsd_baseAprPercent = deposit.reserve.depositAprPercent.times(deposit.depositedAmountUsd);
|
|
154
|
-
const weightedDepositedAmountUsd_stakingYieldAprPercent = new BigNumber(
|
|
150
|
+
const weightedDepositedAmountUsd_stakingYieldAprPercent = new BigNumber(getStakingYieldAprPercent(Side.DEPOSIT, deposit.reserve.coinType, lstStatsMap, sdeUsdAprPercent, eThirdAprPercent, eEarnAprPercent) ?? 0).times(deposit.depositedAmountUsd);
|
|
155
151
|
const weightedDepositedAmountUsd_rewardsAprPercent = getRewardsAprPercent(Side.DEPOSIT, getFilteredRewards(rewardMap[deposit.reserve.coinType].deposit)).times(!noShares
|
|
156
152
|
? getDepositShareUsd(deposit.reserve, new BigNumber(deposit.userRewardManager.share.toString()))
|
|
157
153
|
: deposit.depositedAmountUsd);
|
package/lib/pyth.js
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
export const PRIMARY_PYTH_ENDPOINT = "https://hermes.pyth.network";
|
|
11
2
|
/**
|
|
12
3
|
* Tests if the primary Pyth connection endpoint is working by checking the /live endpoint
|
|
13
4
|
* @returns true if the connection is working, false otherwise
|
|
14
5
|
*/
|
|
15
|
-
export const testPrimaryPythConnection = () =>
|
|
6
|
+
export const testPrimaryPythConnection = async () => {
|
|
16
7
|
try {
|
|
17
|
-
const res =
|
|
8
|
+
const res = await fetch(`${PRIMARY_PYTH_ENDPOINT}/live`, {
|
|
18
9
|
signal: AbortSignal.timeout(5 * 1000), // 5 second timeout
|
|
19
10
|
});
|
|
20
11
|
return res.ok;
|
|
@@ -23,15 +14,15 @@ export const testPrimaryPythConnection = () => __awaiter(void 0, void 0, void 0,
|
|
|
23
14
|
console.warn(`[testPrimaryPythConnection] Pyth connection test failed for ${PRIMARY_PYTH_ENDPOINT}:`, err);
|
|
24
15
|
return false;
|
|
25
16
|
}
|
|
26
|
-
}
|
|
17
|
+
};
|
|
27
18
|
/**
|
|
28
19
|
* Gets a working Pyth connection endpoint, trying primary first, then fallback if provided
|
|
29
20
|
* @param fallbackPythEndpoint Optional fallback endpoint
|
|
30
21
|
* @returns The endpoint URL that is working, or the primary endpoint if fallback fails
|
|
31
22
|
*/
|
|
32
|
-
export const getWorkingPythEndpoint = (fallbackPythEndpoint) =>
|
|
23
|
+
export const getWorkingPythEndpoint = async (fallbackPythEndpoint) => {
|
|
33
24
|
// Test primary endpoint first
|
|
34
|
-
const primaryWorking =
|
|
25
|
+
const primaryWorking = await testPrimaryPythConnection();
|
|
35
26
|
if (primaryWorking) {
|
|
36
27
|
console.log(`[getWorkingPythEndpoint] Using primary Pyth endpoint: ${PRIMARY_PYTH_ENDPOINT}`);
|
|
37
28
|
return PRIMARY_PYTH_ENDPOINT;
|
|
@@ -45,4 +36,4 @@ export const getWorkingPythEndpoint = (fallbackPythEndpoint) => __awaiter(void 0
|
|
|
45
36
|
console.error(`[getWorkingPythEndpoint] Primary Pyth endpoint failed, no fallback provided, using primary anyway`);
|
|
46
37
|
return PRIMARY_PYTH_ENDPOINT;
|
|
47
38
|
}
|
|
48
|
-
}
|
|
39
|
+
};
|
package/lib/pythAdapter.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { bcs } from "@mysten/sui/bcs";
|
|
11
2
|
const PYTH_STATE_ID = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
12
3
|
const PYTH_PRICE_TABLE_ID = "0x234c9ffca44613ab87a2711325b6e17bad9ece0449b917c8bd9c0ad7a0506cc2";
|
|
@@ -19,132 +10,125 @@ const PYTH_PACKAGE = "0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a
|
|
|
19
10
|
*/
|
|
20
11
|
export function createJsonRpcAdapter(suiGrpcClient) {
|
|
21
12
|
return {
|
|
22
|
-
getObject(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
async getObject({ id }) {
|
|
14
|
+
const { object } = await suiGrpcClient.getObject({
|
|
15
|
+
objectId: id,
|
|
16
|
+
include: { json: true },
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
data: {
|
|
20
|
+
objectId: object.objectId,
|
|
21
|
+
type: object.type,
|
|
22
|
+
content: {
|
|
23
|
+
dataType: "moveObject",
|
|
24
|
+
fields: wrapNestedObjects(object.json),
|
|
25
|
+
type: object.type,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
async getCoins({ owner, coinType, cursor, }) {
|
|
31
|
+
const result = await suiGrpcClient.listCoins({
|
|
32
|
+
owner,
|
|
33
|
+
coinType,
|
|
34
|
+
cursor,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
data: result.objects.map((coin) => ({
|
|
38
|
+
coinObjectId: coin.objectId,
|
|
39
|
+
version: coin.version,
|
|
40
|
+
digest: coin.digest,
|
|
41
|
+
balance: coin.balance,
|
|
42
|
+
coinType: coin.type,
|
|
43
|
+
})),
|
|
44
|
+
nextCursor: result.cursor,
|
|
45
|
+
hasNextPage: result.hasNextPage,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
async getDynamicFieldObject({ parentId, name, }) {
|
|
49
|
+
// The gRPC node may not have dynamic field wrapper objects indexed.
|
|
50
|
+
// For known lookups (Pyth price table), use hardcoded values.
|
|
51
|
+
if (parentId === PYTH_STATE_ID &&
|
|
52
|
+
name.type === "vector<u8>" &&
|
|
53
|
+
name.value === "price_info") {
|
|
28
54
|
return {
|
|
29
55
|
data: {
|
|
30
|
-
objectId:
|
|
31
|
-
type: object
|
|
56
|
+
objectId: PYTH_PRICE_TABLE_ID,
|
|
57
|
+
type: `0x2::table::Table<${PYTH_PACKAGE}::price_identifier::PriceIdentifier, 0x2::object::ID>`,
|
|
32
58
|
content: {
|
|
33
59
|
dataType: "moveObject",
|
|
34
|
-
fields:
|
|
35
|
-
type: object
|
|
60
|
+
fields: null,
|
|
61
|
+
type: `0x2::table::Table<${PYTH_PACKAGE}::price_identifier::PriceIdentifier, 0x2::object::ID>`,
|
|
36
62
|
},
|
|
37
63
|
},
|
|
38
64
|
};
|
|
65
|
+
}
|
|
66
|
+
const { dynamicField } = await suiGrpcClient.getDynamicField({
|
|
67
|
+
parentId,
|
|
68
|
+
name: {
|
|
69
|
+
type: name.type,
|
|
70
|
+
bcs: dynamicField_encodeName(name),
|
|
71
|
+
},
|
|
39
72
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
data: result.objects.map((coin) => ({
|
|
50
|
-
coinObjectId: coin.objectId,
|
|
51
|
-
version: coin.version,
|
|
52
|
-
digest: coin.digest,
|
|
53
|
-
balance: coin.balance,
|
|
54
|
-
coinType: coin.type,
|
|
55
|
-
})),
|
|
56
|
-
nextCursor: result.cursor,
|
|
57
|
-
hasNextPage: result.hasNextPage,
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
getDynamicFieldObject(_a) {
|
|
62
|
-
return __awaiter(this, arguments, void 0, function* ({ parentId, name, }) {
|
|
63
|
-
var _b, _c;
|
|
64
|
-
// The gRPC node may not have dynamic field wrapper objects indexed.
|
|
65
|
-
// For known lookups (Pyth price table), use hardcoded values.
|
|
66
|
-
if (parentId === PYTH_STATE_ID &&
|
|
67
|
-
name.type === "vector<u8>" &&
|
|
68
|
-
name.value === "price_info") {
|
|
73
|
+
if (dynamicField.$kind === "DynamicObject" && dynamicField.childId) {
|
|
74
|
+
try {
|
|
75
|
+
const childObject = await suiGrpcClient
|
|
76
|
+
.getObject({
|
|
77
|
+
objectId: dynamicField.childId,
|
|
78
|
+
include: { json: true },
|
|
79
|
+
})
|
|
80
|
+
.then((r) => r.object);
|
|
69
81
|
return {
|
|
70
82
|
data: {
|
|
71
|
-
objectId:
|
|
72
|
-
type:
|
|
83
|
+
objectId: childObject.objectId,
|
|
84
|
+
type: childObject.type,
|
|
73
85
|
content: {
|
|
74
86
|
dataType: "moveObject",
|
|
75
|
-
fields:
|
|
76
|
-
type:
|
|
87
|
+
fields: childObject.json,
|
|
88
|
+
type: childObject.type,
|
|
77
89
|
},
|
|
78
90
|
},
|
|
79
91
|
};
|
|
80
92
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
type: name.type,
|
|
85
|
-
bcs: dynamicField_encodeName(name),
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
if (dynamicField.$kind === "DynamicObject" && dynamicField.childId) {
|
|
89
|
-
try {
|
|
90
|
-
const childObject = yield suiGrpcClient
|
|
91
|
-
.getObject({
|
|
93
|
+
catch {
|
|
94
|
+
return {
|
|
95
|
+
data: {
|
|
92
96
|
objectId: dynamicField.childId,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
data: {
|
|
98
|
-
objectId: childObject.objectId,
|
|
99
|
-
type: childObject.type,
|
|
100
|
-
content: {
|
|
101
|
-
dataType: "moveObject",
|
|
102
|
-
fields: childObject.json,
|
|
103
|
-
type: childObject.type,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
catch (_d) {
|
|
109
|
-
return {
|
|
110
|
-
data: {
|
|
111
|
-
objectId: dynamicField.childId,
|
|
97
|
+
type: dynamicField.valueType,
|
|
98
|
+
content: {
|
|
99
|
+
dataType: "moveObject",
|
|
100
|
+
fields: null,
|
|
112
101
|
type: dynamicField.valueType,
|
|
113
|
-
content: {
|
|
114
|
-
dataType: "moveObject",
|
|
115
|
-
fields: null,
|
|
116
|
-
type: dynamicField.valueType,
|
|
117
|
-
},
|
|
118
102
|
},
|
|
119
|
-
}
|
|
120
|
-
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
121
105
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
106
|
+
}
|
|
107
|
+
const valueBcs = dynamicField.value?.bcs;
|
|
108
|
+
const type = dynamicField.valueType ?? dynamicField.type;
|
|
109
|
+
let fields = null;
|
|
110
|
+
if (valueBcs && valueBcs.length > 0) {
|
|
111
|
+
if (type === "0x2::object::ID" ||
|
|
112
|
+
type.endsWith("::object::ID") ||
|
|
113
|
+
valueBcs.length === 32) {
|
|
114
|
+
const id = "0x" +
|
|
115
|
+
Array.from(valueBcs)
|
|
116
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
117
|
+
.join("");
|
|
118
|
+
fields = { value: id };
|
|
135
119
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
data: {
|
|
123
|
+
objectId: dynamicField.fieldId,
|
|
124
|
+
type,
|
|
125
|
+
content: {
|
|
126
|
+
dataType: "moveObject",
|
|
127
|
+
fields,
|
|
139
128
|
type,
|
|
140
|
-
content: {
|
|
141
|
-
dataType: "moveObject",
|
|
142
|
-
fields,
|
|
143
|
-
type,
|
|
144
|
-
},
|
|
145
129
|
},
|
|
146
|
-
}
|
|
147
|
-
}
|
|
130
|
+
},
|
|
131
|
+
};
|
|
148
132
|
},
|
|
149
133
|
};
|
|
150
134
|
}
|
package/lib/strategyOwnerCap.js
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID, } from "@mysten/sui/utils";
|
|
11
2
|
import BigNumber from "bignumber.js";
|
|
12
3
|
import BN from "bn.js";
|
|
13
|
-
import { MAX_U64, NORMALIZED_AUSD_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_USDsui_COINTYPE, NORMALIZED_eEARN_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_stratSUI_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_xBTC_COINTYPE, isSui, } from "@suilend/sui-
|
|
4
|
+
import { MAX_U64, NORMALIZED_AUSD_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_USDsui_COINTYPE, NORMALIZED_eEARN_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_stratSUI_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_xBTC_COINTYPE, isSui, } from "@suilend/sui-core";
|
|
14
5
|
import { LENDING_MARKET_ID, LENDING_MARKET_TYPE, } from "../client.js";
|
|
15
6
|
import { Side } from "./types.js";
|
|
16
7
|
export const STRATEGY_WRAPPER_PACKAGE_ID_V1 = "0xba97dc73a07638d03d77ad2161484eb21db577edc9cadcd7035fef4b4f2f6fa1";
|
|
@@ -345,9 +336,9 @@ export const strategyClaimRewardsAndMergeCoins = (strategyType, rewardsMap, stra
|
|
|
345
336
|
}
|
|
346
337
|
return mergedCoinsMap;
|
|
347
338
|
};
|
|
348
|
-
export const strategySwapSomeDepositsForCoinType = (strategyType, cetusSdk, cetusPartnerId, obligation, noSwapCoinTypes, // coinTypes to not swap for depositReserve.coinType
|
|
339
|
+
export const strategySwapSomeDepositsForCoinType = async (strategyType, cetusSdk, cetusPartnerId, obligation, noSwapCoinTypes, // coinTypes to not swap for depositReserve.coinType
|
|
349
340
|
swapPercent, // percent of deposit to swap for depositReserve.coinType (0-100)
|
|
350
|
-
depositReserve, strategyOwnerCap, transaction) =>
|
|
341
|
+
depositReserve, strategyOwnerCap, transaction) => {
|
|
351
342
|
// 1) MAX withdraw non-swapCoinTypes deposits
|
|
352
343
|
const swapCoinTypeDeposits = obligation.deposits.filter((deposit) => !noSwapCoinTypes.includes(deposit.coinType));
|
|
353
344
|
if (swapCoinTypeDeposits.length === 0)
|
|
@@ -371,14 +362,14 @@ depositReserve, strategyOwnerCap, transaction) => __awaiter(void 0, void 0, void
|
|
|
371
362
|
// 2) Swap
|
|
372
363
|
let resultCoin = undefined;
|
|
373
364
|
// 2.1) Get routers
|
|
374
|
-
const amountsAndSortedQuotesMap = Object.fromEntries(
|
|
365
|
+
const amountsAndSortedQuotesMap = Object.fromEntries(await Promise.all(Object.entries(withdrawnCoinsMap).map(([coinType, { deposit, coin }]) => (async () => {
|
|
375
366
|
try {
|
|
376
367
|
// Get amount
|
|
377
368
|
const amount = new BigNumber(deposit.depositedAmount.times(swapPercent.div(100)))
|
|
378
369
|
.times(10 ** deposit.reserve.token.decimals)
|
|
379
370
|
.integerValue(BigNumber.ROUND_DOWN); // Use underestimate (deposits keep accruing if deposit APR >0)
|
|
380
371
|
// Get routes
|
|
381
|
-
const routers =
|
|
372
|
+
const routers = await cetusSdk.findRouters({
|
|
382
373
|
from: deposit.coinType,
|
|
383
374
|
target: depositReserve.coinType,
|
|
384
375
|
amount: new BN(amount.toString()), // Underestimate (deposits keep accruing if deposit APR >0)
|
|
@@ -396,7 +387,7 @@ depositReserve, strategyOwnerCap, transaction) => __awaiter(void 0, void 0, void
|
|
|
396
387
|
console.error(err);
|
|
397
388
|
return [coinType, { coin, routers: undefined }];
|
|
398
389
|
}
|
|
399
|
-
})
|
|
390
|
+
})())));
|
|
400
391
|
console.log("[strategySwapSomeDepositsForCoinType] amountsAndSortedQuotesMap", { amountsAndSortedQuotesMap });
|
|
401
392
|
// 2.2) Swap
|
|
402
393
|
for (const [coinType, { coin: coinIn, routers }] of Object.entries(amountsAndSortedQuotesMap)) {
|
|
@@ -406,7 +397,7 @@ depositReserve, strategyOwnerCap, transaction) => __awaiter(void 0, void 0, void
|
|
|
406
397
|
try {
|
|
407
398
|
let coinOut;
|
|
408
399
|
try {
|
|
409
|
-
coinOut = (
|
|
400
|
+
coinOut = (await cetusSdk.fixableRouterSwapV3({
|
|
410
401
|
router: routers,
|
|
411
402
|
inputCoin: coinIn,
|
|
412
403
|
slippage: 3 / 100,
|
|
@@ -432,7 +423,7 @@ depositReserve, strategyOwnerCap, transaction) => __awaiter(void 0, void 0, void
|
|
|
432
423
|
throw new Error("No coin to deposit or transfer");
|
|
433
424
|
console.log("[strategySwapSomeDepositsForCoinType] depositing resultCoin");
|
|
434
425
|
strategyDeposit(strategyType, resultCoin, depositReserve.coinType, strategyOwnerCap, depositReserve.arrayIndex, transaction);
|
|
435
|
-
}
|
|
426
|
+
};
|
|
436
427
|
export const createStrategyOwnerCapIfNoneExists = (strategyType, strategyOwnerCap, transaction) => {
|
|
437
428
|
const { lendingMarketId, lendingMarketType } = getStrategyLendingMarket(strategyType);
|
|
438
429
|
let strategyOwnerCapId;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MoveStruct } from "../utils/index.js";
|
|
2
2
|
export declare const AdminCap: MoveStruct<{
|
|
3
|
-
id: import("@mysten/
|
|
3
|
+
id: import("@mysten/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
4
4
|
}, "0xd5f3054404ec9275b50985851a5b515728f131a3bdd9c9a5f738a9326b738d53::admin_cap::AdminCap">;
|
|
5
5
|
export declare const InitEvent: MoveStruct<{
|
|
6
|
-
admin_cap_id: import("@mysten/
|
|
6
|
+
admin_cap_id: import("@mysten/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
7
7
|
}, "0xd5f3054404ec9275b50985851a5b515728f131a3bdd9c9a5f738a9326b738d53::admin_cap::InitEvent">;
|
|
@@ -12,5 +12,5 @@ export declare const TypeName: MoveStruct<{
|
|
|
12
12
|
* Addresses are hex-encoded lowercase values of length ADDRESS_LENGTH (16, 20, or
|
|
13
13
|
* 32 depending on the Move platform)
|
|
14
14
|
*/
|
|
15
|
-
name: import("@mysten/
|
|
15
|
+
name: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
16
16
|
}, "std::type_name::TypeName">;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MoveStruct } from "../../../utils/index.js";
|
|
2
2
|
export declare const ObligationOwnerCap: MoveStruct<{
|
|
3
|
-
id: import("@mysten/
|
|
4
|
-
obligation_id: import("@mysten/
|
|
3
|
+
id: import("@mysten/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
4
|
+
obligation_id: import("@mysten/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
5
5
|
}, "suilend::lending_market::ObligationOwnerCap<phantom P>">;
|