@suilend/sdk 1.1.77 → 1.1.79
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/lib/strategyOwnerCap.d.ts +12 -8
- package/lib/strategyOwnerCap.js +74 -60
- package/lib/types.d.ts +1 -0
- package/package.json +1 -1
- package/swap/quote.js +14 -10
package/lib/initialize.js
CHANGED
|
@@ -245,7 +245,7 @@ const initializeObligations = (suiClient, suilendClient, refreshedRawReserves, r
|
|
|
245
245
|
if (suilendClient.lendingMarket.id !== client_1.LENDING_MARKET_ID)
|
|
246
246
|
return []; // Only main lending market has strategy owner caps
|
|
247
247
|
const objects = yield (0, sui_fe_1.getAllOwnedObjects)(suiClient, address, {
|
|
248
|
-
StructType: `${strategyOwnerCap_1.
|
|
248
|
+
StructType: `${strategyOwnerCap_1.STRATEGY_WRAPPER_PACKAGE_ID_V1}::strategy_wrapper::StrategyOwnerCap<${suilendClient.lendingMarket.$typeArgs[0]}>`,
|
|
249
249
|
});
|
|
250
250
|
return objects.map((obj) => {
|
|
251
251
|
var _a;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { AggregatorClient as CetusSdk } from "@cetusprotocol/aggregator-sdk";
|
|
2
2
|
import { Transaction, TransactionObjectInput, TransactionResult } from "@mysten/sui/transactions";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
3
4
|
import { ParsedObligation, ParsedReserve } from "../parsers";
|
|
4
5
|
import { RewardsMap, StrategyOwnerCap } from "./types";
|
|
5
|
-
export declare const
|
|
6
|
+
export declare const STRATEGY_WRAPPER_PACKAGE_ID_V1 = "0xba97dc73a07638d03d77ad2161484eb21db577edc9cadcd7035fef4b4f2f6fa1";
|
|
6
7
|
export declare enum StrategyType {
|
|
7
8
|
sSUI_SUI_LOOPING = "1",
|
|
8
9
|
stratSUI_SUI_LOOPING = "2",
|
|
9
|
-
USDC_sSUI_SUI_LOOPING = "3"
|
|
10
|
+
USDC_sSUI_SUI_LOOPING = "3",
|
|
11
|
+
AUSD_sSUI_SUI_LOOPING = "4"
|
|
10
12
|
}
|
|
11
13
|
export declare const STRATEGY_TYPE_INFO_MAP: Record<StrategyType, {
|
|
12
14
|
queryParam: string;
|
|
@@ -16,17 +18,19 @@ export declare const STRATEGY_TYPE_INFO_MAP: Record<StrategyType, {
|
|
|
16
18
|
tooltip: string;
|
|
17
19
|
type: string;
|
|
18
20
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
depositCoinTypes: string[];
|
|
21
|
+
depositBaseCoinType?: string;
|
|
22
|
+
depositLstCoinType: string;
|
|
22
23
|
borrowCoinType: string;
|
|
23
|
-
|
|
24
|
+
currencyCoinTypes: string[];
|
|
25
|
+
defaultCurrencyCoinType: string;
|
|
24
26
|
}>;
|
|
25
27
|
export declare const strategyDeposit: (coin: TransactionObjectInput, coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, transaction: Transaction) => TransactionResult;
|
|
26
28
|
export declare const strategyBorrow: (coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, value: bigint, transaction: Transaction) => TransactionResult;
|
|
27
29
|
export declare const strategyWithdraw: (coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, value: bigint, transaction: Transaction) => TransactionResult;
|
|
28
|
-
export declare const
|
|
29
|
-
export declare const
|
|
30
|
+
export declare const strategyClaimRewardsAndSwapForCoinType: (address: string, cetusSdk: CetusSdk, cetusPartnerId: string, rewardsMap: RewardsMap, depositReserve: ParsedReserve, strategyOwnerCap: TransactionObjectInput, isDepositing: boolean, transaction: Transaction) => Promise<void>;
|
|
31
|
+
export declare const strategySwapSomeDepositsForCoinType: (strategyType: StrategyType, cetusSdk: CetusSdk, cetusPartnerId: string, obligation: ParsedObligation, noSwapCoinTypes: string[], // coinTypes to not swap for depositReserve.coinType
|
|
32
|
+
swapPercent: BigNumber, // percent of deposit to swap for depositReserve.coinType (0-100)
|
|
33
|
+
depositReserve: ParsedReserve, strategyOwnerCap: TransactionObjectInput, transaction: Transaction) => Promise<void>;
|
|
30
34
|
export declare const createStrategyOwnerCapIfNoneExists: (strategyType: StrategyType, strategyOwnerCap: StrategyOwnerCap | undefined, transaction: Transaction) => {
|
|
31
35
|
strategyOwnerCapId: string | TransactionResult;
|
|
32
36
|
didCreate: boolean;
|
package/lib/strategyOwnerCap.js
CHANGED
|
@@ -12,19 +12,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.sendStrategyOwnerCapToUser = exports.createStrategyOwnerCapIfNoneExists = exports.
|
|
15
|
+
exports.sendStrategyOwnerCapToUser = exports.createStrategyOwnerCapIfNoneExists = exports.strategySwapSomeDepositsForCoinType = exports.strategyClaimRewardsAndSwapForCoinType = exports.strategyWithdraw = exports.strategyBorrow = exports.strategyDeposit = exports.STRATEGY_TYPE_INFO_MAP = exports.StrategyType = exports.STRATEGY_WRAPPER_PACKAGE_ID_V1 = void 0;
|
|
16
16
|
const utils_1 = require("@mysten/sui/utils");
|
|
17
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
17
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
18
18
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
19
19
|
const sui_fe_1 = require("@suilend/sui-fe");
|
|
20
20
|
const client_1 = require("../client");
|
|
21
21
|
const types_1 = require("./types");
|
|
22
|
-
exports.
|
|
22
|
+
exports.STRATEGY_WRAPPER_PACKAGE_ID_V1 = "0xba97dc73a07638d03d77ad2161484eb21db577edc9cadcd7035fef4b4f2f6fa1";
|
|
23
|
+
const STRATEGY_WRAPPER_PACKAGE_ID_V6 = "0xb4e22255bb2ef58c4451eaf5a93135bb9acac58951b1755f1d2aaaad675a0f47";
|
|
23
24
|
var StrategyType;
|
|
24
25
|
(function (StrategyType) {
|
|
25
26
|
StrategyType["sSUI_SUI_LOOPING"] = "1";
|
|
26
27
|
StrategyType["stratSUI_SUI_LOOPING"] = "2";
|
|
27
28
|
StrategyType["USDC_sSUI_SUI_LOOPING"] = "3";
|
|
29
|
+
StrategyType["AUSD_sSUI_SUI_LOOPING"] = "4";
|
|
28
30
|
})(StrategyType || (exports.StrategyType = StrategyType = {}));
|
|
29
31
|
exports.STRATEGY_TYPE_INFO_MAP = {
|
|
30
32
|
[StrategyType.sSUI_SUI_LOOPING]: {
|
|
@@ -35,14 +37,11 @@ exports.STRATEGY_TYPE_INFO_MAP = {
|
|
|
35
37
|
tooltip: "Sets up a sSUI/SUI Looping strategy by depositing sSUI and borrowing SUI to the desired leverage",
|
|
36
38
|
type: "Looping",
|
|
37
39
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
41
|
-
sui_fe_1.NORMALIZED_sSUI_COINTYPE,
|
|
42
|
-
],
|
|
43
|
-
depositCoinTypes: [sui_fe_1.NORMALIZED_sSUI_COINTYPE],
|
|
40
|
+
depositBaseCoinType: undefined,
|
|
41
|
+
depositLstCoinType: sui_fe_1.NORMALIZED_sSUI_COINTYPE,
|
|
44
42
|
borrowCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
45
|
-
|
|
43
|
+
currencyCoinTypes: [sui_fe_1.NORMALIZED_SUI_COINTYPE, sui_fe_1.NORMALIZED_sSUI_COINTYPE],
|
|
44
|
+
defaultCurrencyCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
46
45
|
},
|
|
47
46
|
[StrategyType.stratSUI_SUI_LOOPING]: {
|
|
48
47
|
queryParam: "stratSUI-SUI-looping",
|
|
@@ -52,32 +51,43 @@ exports.STRATEGY_TYPE_INFO_MAP = {
|
|
|
52
51
|
tooltip: "Sets up a stratSUI/SUI Looping strategy by depositing stratSUI and borrowing SUI to the desired leverage",
|
|
53
52
|
type: "Looping",
|
|
54
53
|
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
58
|
-
sui_fe_1.NORMALIZED_stratSUI_COINTYPE,
|
|
59
|
-
],
|
|
60
|
-
depositCoinTypes: [sui_fe_1.NORMALIZED_stratSUI_COINTYPE],
|
|
54
|
+
depositBaseCoinType: undefined,
|
|
55
|
+
depositLstCoinType: sui_fe_1.NORMALIZED_stratSUI_COINTYPE,
|
|
61
56
|
borrowCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
62
|
-
|
|
57
|
+
currencyCoinTypes: [sui_fe_1.NORMALIZED_SUI_COINTYPE, sui_fe_1.NORMALIZED_stratSUI_COINTYPE],
|
|
58
|
+
defaultCurrencyCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
63
59
|
},
|
|
64
60
|
[StrategyType.USDC_sSUI_SUI_LOOPING]: {
|
|
65
61
|
queryParam: "USDC-sSUI-SUI-looping",
|
|
66
62
|
header: {
|
|
67
63
|
coinTypes: [sui_fe_1.NORMALIZED_USDC_COINTYPE],
|
|
68
|
-
title: "USDC",
|
|
64
|
+
title: "USDC sSUI/SUI",
|
|
69
65
|
tooltip: "Sets up a USDC sSUI/SUI Looping strategy by depositing USDC and looping sSUI/SUI to the desired leverage",
|
|
70
66
|
type: "Looping",
|
|
71
67
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
depositCoinTypes: [sui_fe_1.NORMALIZED_USDC_COINTYPE, sui_fe_1.NORMALIZED_sSUI_COINTYPE],
|
|
68
|
+
depositBaseCoinType: sui_fe_1.NORMALIZED_USDC_COINTYPE,
|
|
69
|
+
depositLstCoinType: sui_fe_1.NORMALIZED_sSUI_COINTYPE,
|
|
75
70
|
borrowCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
76
|
-
|
|
71
|
+
currencyCoinTypes: [sui_fe_1.NORMALIZED_USDC_COINTYPE],
|
|
72
|
+
defaultCurrencyCoinType: sui_fe_1.NORMALIZED_USDC_COINTYPE,
|
|
73
|
+
},
|
|
74
|
+
[StrategyType.AUSD_sSUI_SUI_LOOPING]: {
|
|
75
|
+
queryParam: "AUSD-sSUI-SUI-looping",
|
|
76
|
+
header: {
|
|
77
|
+
coinTypes: [sui_fe_1.NORMALIZED_AUSD_COINTYPE],
|
|
78
|
+
title: "AUSD sSUI/SUI",
|
|
79
|
+
tooltip: "Sets up an AUSD sSUI/SUI Looping strategy by depositing AUSD and looping sSUI/SUI to the desired leverage",
|
|
80
|
+
type: "Looping",
|
|
81
|
+
},
|
|
82
|
+
depositBaseCoinType: sui_fe_1.NORMALIZED_AUSD_COINTYPE,
|
|
83
|
+
depositLstCoinType: sui_fe_1.NORMALIZED_sSUI_COINTYPE,
|
|
84
|
+
borrowCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
|
|
85
|
+
currencyCoinTypes: [sui_fe_1.NORMALIZED_AUSD_COINTYPE],
|
|
86
|
+
defaultCurrencyCoinType: sui_fe_1.NORMALIZED_AUSD_COINTYPE,
|
|
77
87
|
},
|
|
78
88
|
};
|
|
79
89
|
const strategyDeposit = (coin, coinType, strategyOwnerCap, reserveArrayIndex, transaction) => transaction.moveCall({
|
|
80
|
-
target: `${
|
|
90
|
+
target: `${STRATEGY_WRAPPER_PACKAGE_ID_V6}::strategy_wrapper::deposit_liquidity_and_deposit_into_obligation`,
|
|
81
91
|
typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
|
|
82
92
|
arguments: [
|
|
83
93
|
transaction.object(strategyOwnerCap),
|
|
@@ -90,7 +100,7 @@ const strategyDeposit = (coin, coinType, strategyOwnerCap, reserveArrayIndex, tr
|
|
|
90
100
|
exports.strategyDeposit = strategyDeposit;
|
|
91
101
|
const strategyBorrow = (coinType, strategyOwnerCap, reserveArrayIndex, value, transaction) => (0, sui_fe_1.isSui)(coinType)
|
|
92
102
|
? transaction.moveCall({
|
|
93
|
-
target: `${
|
|
103
|
+
target: `${STRATEGY_WRAPPER_PACKAGE_ID_V6}::strategy_wrapper::borrow_sui_from_obligation`,
|
|
94
104
|
typeArguments: [client_1.LENDING_MARKET_TYPE],
|
|
95
105
|
arguments: [
|
|
96
106
|
transaction.object(strategyOwnerCap),
|
|
@@ -102,7 +112,7 @@ const strategyBorrow = (coinType, strategyOwnerCap, reserveArrayIndex, value, tr
|
|
|
102
112
|
],
|
|
103
113
|
})
|
|
104
114
|
: transaction.moveCall({
|
|
105
|
-
target: `${
|
|
115
|
+
target: `${STRATEGY_WRAPPER_PACKAGE_ID_V6}::strategy_wrapper::borrow_from_obligation`,
|
|
106
116
|
typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
|
|
107
117
|
arguments: [
|
|
108
118
|
transaction.object(strategyOwnerCap),
|
|
@@ -114,7 +124,7 @@ const strategyBorrow = (coinType, strategyOwnerCap, reserveArrayIndex, value, tr
|
|
|
114
124
|
});
|
|
115
125
|
exports.strategyBorrow = strategyBorrow;
|
|
116
126
|
const strategyWithdraw = (coinType, strategyOwnerCap, reserveArrayIndex, value, transaction) => transaction.moveCall({
|
|
117
|
-
target: `${
|
|
127
|
+
target: `${STRATEGY_WRAPPER_PACKAGE_ID_V6}::strategy_wrapper::withdraw_from_obligation_and_redeem`,
|
|
118
128
|
typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
|
|
119
129
|
arguments: [
|
|
120
130
|
transaction.object(strategyOwnerCap),
|
|
@@ -126,7 +136,7 @@ const strategyWithdraw = (coinType, strategyOwnerCap, reserveArrayIndex, value,
|
|
|
126
136
|
});
|
|
127
137
|
exports.strategyWithdraw = strategyWithdraw;
|
|
128
138
|
const strategyClaimRewards = (coinType, strategyOwnerCap, reserveArrayIndex, rewardIndex, side, transaction) => transaction.moveCall({
|
|
129
|
-
target: `${
|
|
139
|
+
target: `${STRATEGY_WRAPPER_PACKAGE_ID_V6}::strategy_wrapper::claim_rewards`,
|
|
130
140
|
typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
|
|
131
141
|
arguments: [
|
|
132
142
|
transaction.object(strategyOwnerCap),
|
|
@@ -164,12 +174,12 @@ const strategyClaimRewardsAndMergeCoins = (rewardsMap, strategyOwnerCap, transac
|
|
|
164
174
|
}
|
|
165
175
|
return mergedCoinsMap;
|
|
166
176
|
};
|
|
167
|
-
const
|
|
177
|
+
const strategyClaimRewardsAndSwapForCoinType = (address, cetusSdk, cetusPartnerId, rewardsMap, depositReserve, strategyOwnerCap, isDepositing, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
178
|
// 1) Claim rewards and merge coins
|
|
169
179
|
const mergedCoinsMap = strategyClaimRewardsAndMergeCoins(rewardsMap, strategyOwnerCap, transaction);
|
|
170
180
|
// 2) Prepare
|
|
171
|
-
const nonSwappedCoinTypes = Object.keys(mergedCoinsMap).filter((coinType) => coinType ===
|
|
172
|
-
const swappedCoinTypes = Object.keys(mergedCoinsMap).filter((coinType) => coinType !==
|
|
181
|
+
const nonSwappedCoinTypes = Object.keys(mergedCoinsMap).filter((coinType) => coinType === depositReserve.coinType);
|
|
182
|
+
const swappedCoinTypes = Object.keys(mergedCoinsMap).filter((coinType) => coinType !== depositReserve.coinType);
|
|
173
183
|
let resultCoin = undefined;
|
|
174
184
|
// 3.1) Non-swapped coins
|
|
175
185
|
for (const [coinType, coin] of Object.entries(mergedCoinsMap).filter(([coinType]) => nonSwappedCoinTypes.includes(coinType))) {
|
|
@@ -188,31 +198,28 @@ const strategyClaimRewardsAndSwap = (address, cetusSdk, cetusPartnerId, rewardsM
|
|
|
188
198
|
// Get routes
|
|
189
199
|
const routers = yield cetusSdk.findRouters({
|
|
190
200
|
from: coinType,
|
|
191
|
-
target:
|
|
201
|
+
target: depositReserve.coinType,
|
|
192
202
|
amount: new bn_js_1.default(amount.toString()), // Underestimate (rewards keep accruing)
|
|
193
203
|
byAmountIn: true,
|
|
194
204
|
});
|
|
195
205
|
if (!routers)
|
|
196
206
|
throw new Error(`No swap quote found for ${coinType}`);
|
|
197
|
-
console.log("[
|
|
207
|
+
console.log("[strategyClaimRewardsAndSwapForCoinType] routers", {
|
|
198
208
|
coinType,
|
|
199
209
|
routers,
|
|
200
210
|
});
|
|
201
211
|
return [coinType, { coin, routers }];
|
|
202
212
|
}))())));
|
|
203
|
-
console.log("[
|
|
204
|
-
amountsAndSortedQuotesMap,
|
|
205
|
-
});
|
|
213
|
+
console.log("[strategyClaimRewardsAndSwapForCoinType] amountsAndSortedQuotesMap", { amountsAndSortedQuotesMap });
|
|
206
214
|
// 3.2.2) Swap
|
|
207
215
|
for (const [coinType, { coin: coinIn, routers }] of Object.entries(amountsAndSortedQuotesMap)) {
|
|
208
|
-
console.log("[
|
|
209
|
-
const slippagePercent = 3;
|
|
216
|
+
console.log("[strategyClaimRewardsAndSwapForCoinType] swapping coinType", coinType);
|
|
210
217
|
let coinOut;
|
|
211
218
|
try {
|
|
212
219
|
coinOut = yield cetusSdk.fixableRouterSwapV3({
|
|
213
220
|
router: routers,
|
|
214
221
|
inputCoin: coinIn,
|
|
215
|
-
slippage:
|
|
222
|
+
slippage: 3 / 100,
|
|
216
223
|
txb: transaction,
|
|
217
224
|
partner: cetusPartnerId,
|
|
218
225
|
});
|
|
@@ -229,21 +236,31 @@ const strategyClaimRewardsAndSwap = (address, cetusSdk, cetusPartnerId, rewardsM
|
|
|
229
236
|
if (!resultCoin)
|
|
230
237
|
throw new Error("No coin to deposit or transfer");
|
|
231
238
|
if (isDepositing) {
|
|
232
|
-
(0, exports.strategyDeposit)(resultCoin,
|
|
239
|
+
(0, exports.strategyDeposit)(resultCoin, depositReserve.coinType, strategyOwnerCap, depositReserve.arrayIndex, transaction);
|
|
233
240
|
}
|
|
234
241
|
else {
|
|
235
242
|
transaction.transferObjects([resultCoin], transaction.pure.address(address));
|
|
236
243
|
}
|
|
237
244
|
});
|
|
238
|
-
exports.
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
245
|
+
exports.strategyClaimRewardsAndSwapForCoinType = strategyClaimRewardsAndSwapForCoinType;
|
|
246
|
+
const strategySwapSomeDepositsForCoinType = (strategyType, cetusSdk, cetusPartnerId, obligation, noSwapCoinTypes, // coinTypes to not swap for depositReserve.coinType
|
|
247
|
+
swapPercent, // percent of deposit to swap for depositReserve.coinType (0-100)
|
|
248
|
+
depositReserve, strategyOwnerCap, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
249
|
+
// 1) MAX withdraw non-swapCoinTypes deposits
|
|
250
|
+
const swapCoinTypeDeposits = obligation.deposits.filter((deposit) => !noSwapCoinTypes.includes(deposit.coinType));
|
|
251
|
+
if (swapCoinTypeDeposits.length === 0)
|
|
243
252
|
return;
|
|
244
253
|
const withdrawnCoinsMap = {};
|
|
245
|
-
for (const deposit of
|
|
246
|
-
const [withdrawnCoin] = (0, exports.strategyWithdraw)(deposit.coinType, strategyOwnerCap, deposit.reserve.arrayIndex,
|
|
254
|
+
for (const deposit of swapCoinTypeDeposits) {
|
|
255
|
+
const [withdrawnCoin] = (0, exports.strategyWithdraw)(deposit.coinType, strategyOwnerCap, deposit.reserve.arrayIndex, swapPercent.eq(100)
|
|
256
|
+
? BigInt(sui_fe_1.MAX_U64.toString())
|
|
257
|
+
: BigInt(new bignumber_js_1.default(new bignumber_js_1.default(deposit.depositedAmount.times(swapPercent.div(100)))
|
|
258
|
+
.times(10 ** deposit.reserve.token.decimals)
|
|
259
|
+
.integerValue(bignumber_js_1.default.ROUND_DOWN)
|
|
260
|
+
.toString())
|
|
261
|
+
.div(deposit.reserve.cTokenExchangeRate)
|
|
262
|
+
.integerValue(bignumber_js_1.default.ROUND_UP)
|
|
263
|
+
.toString()), transaction);
|
|
247
264
|
withdrawnCoinsMap[deposit.coinType] = {
|
|
248
265
|
deposit,
|
|
249
266
|
coin: withdrawnCoin,
|
|
@@ -254,37 +271,34 @@ const strategySwapNonLstDepositsForLst = (cetusSdk, cetusPartnerId, obligation,
|
|
|
254
271
|
// 2.1) Get routers
|
|
255
272
|
const amountsAndSortedQuotesMap = Object.fromEntries(yield Promise.all(Object.entries(withdrawnCoinsMap).map(([coinType, { deposit, coin }]) => (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
256
273
|
// Get amount
|
|
257
|
-
const amount = deposit.depositedAmount
|
|
274
|
+
const amount = new bignumber_js_1.default(deposit.depositedAmount.times(swapPercent.div(100)))
|
|
258
275
|
.times(10 ** deposit.reserve.token.decimals)
|
|
259
|
-
.integerValue(bignumber_js_1.
|
|
276
|
+
.integerValue(bignumber_js_1.default.ROUND_DOWN); // Use underestimate (deposits keep accruing if deposit APR >0)
|
|
260
277
|
// Get routes
|
|
261
278
|
const routers = yield cetusSdk.findRouters({
|
|
262
279
|
from: deposit.coinType,
|
|
263
|
-
target:
|
|
280
|
+
target: depositReserve.coinType,
|
|
264
281
|
amount: new bn_js_1.default(amount.toString()), // Underestimate (deposits keep accruing if deposit APR >0)
|
|
265
282
|
byAmountIn: true,
|
|
266
283
|
});
|
|
267
284
|
if (!routers)
|
|
268
285
|
throw new Error(`No swap quote found for ${deposit.coinType}`);
|
|
269
|
-
console.log("[
|
|
286
|
+
console.log("[strategySwapSomeDepositsForCoinType] routers", {
|
|
270
287
|
coinType: deposit.coinType,
|
|
271
288
|
routers,
|
|
272
289
|
});
|
|
273
290
|
return [deposit.coinType, { coin, routers }];
|
|
274
291
|
}))())));
|
|
275
|
-
console.log("[
|
|
276
|
-
amountsAndSortedQuotesMap,
|
|
277
|
-
});
|
|
292
|
+
console.log("[strategySwapSomeDepositsForCoinType] amountsAndSortedQuotesMap", { amountsAndSortedQuotesMap });
|
|
278
293
|
// 2.2) Swap
|
|
279
294
|
for (const [coinType, { coin: coinIn, routers }] of Object.entries(amountsAndSortedQuotesMap)) {
|
|
280
|
-
console.log("[
|
|
281
|
-
const slippagePercent = 3;
|
|
295
|
+
console.log("[strategySwapSomeDepositsForCoinType] swapping coinType", coinType);
|
|
282
296
|
let coinOut;
|
|
283
297
|
try {
|
|
284
298
|
coinOut = yield cetusSdk.fixableRouterSwapV3({
|
|
285
299
|
router: routers,
|
|
286
300
|
inputCoin: coinIn,
|
|
287
|
-
slippage:
|
|
301
|
+
slippage: 3 / 100,
|
|
288
302
|
txb: transaction,
|
|
289
303
|
partner: cetusPartnerId,
|
|
290
304
|
});
|
|
@@ -300,10 +314,10 @@ const strategySwapNonLstDepositsForLst = (cetusSdk, cetusPartnerId, obligation,
|
|
|
300
314
|
// 3) Deposit
|
|
301
315
|
if (!resultCoin)
|
|
302
316
|
throw new Error("No coin to deposit or transfer");
|
|
303
|
-
console.log("[
|
|
304
|
-
(0, exports.strategyDeposit)(resultCoin,
|
|
317
|
+
console.log("[strategySwapSomeDepositsForCoinType] depositing resultCoin");
|
|
318
|
+
(0, exports.strategyDeposit)(resultCoin, depositReserve.coinType, strategyOwnerCap, depositReserve.arrayIndex, transaction);
|
|
305
319
|
});
|
|
306
|
-
exports.
|
|
320
|
+
exports.strategySwapSomeDepositsForCoinType = strategySwapSomeDepositsForCoinType;
|
|
307
321
|
const createStrategyOwnerCapIfNoneExists = (strategyType, strategyOwnerCap, transaction) => {
|
|
308
322
|
let strategyOwnerCapId;
|
|
309
323
|
let didCreate = false;
|
|
@@ -311,7 +325,7 @@ const createStrategyOwnerCapIfNoneExists = (strategyType, strategyOwnerCap, tran
|
|
|
311
325
|
strategyOwnerCapId = strategyOwnerCap.id;
|
|
312
326
|
else {
|
|
313
327
|
strategyOwnerCapId = transaction.moveCall({
|
|
314
|
-
target: `${
|
|
328
|
+
target: `${STRATEGY_WRAPPER_PACKAGE_ID_V6}::strategy_wrapper::create_strategy_owner_cap`,
|
|
315
329
|
typeArguments: [client_1.LENDING_MARKET_TYPE],
|
|
316
330
|
arguments: [
|
|
317
331
|
transaction.object(client_1.LENDING_MARKET_ID),
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"1.1.
|
|
1
|
+
{"name":"@suilend/sdk","version":"1.1.79","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/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.0","@cetusprotocol/aggregator-sdk":"^1.1.2","@flowx-finance/sdk":"^1.11.3","@pythnetwork/pyth-sui-js":"^2.2.0","aftermath-ts-sdk":"^1.3.14","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.6.0","@mysten/sui":"1.28.2","@suilend/sui-fe":"^0.3.29"}}
|
package/swap/quote.js
CHANGED
|
@@ -119,11 +119,11 @@ const getAftermathQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0
|
|
|
119
119
|
provider: path.protocolName,
|
|
120
120
|
in: {
|
|
121
121
|
coinType: (0, utils_1.normalizeStructTag)(path.coinIn.type),
|
|
122
|
-
amount: new bignumber_js_1.default(path.coinIn.amount.toString())
|
|
122
|
+
amount: new bignumber_js_1.default(path.coinIn.amount.toString()),
|
|
123
123
|
},
|
|
124
124
|
out: {
|
|
125
125
|
coinType: (0, utils_1.normalizeStructTag)(path.coinOut.type),
|
|
126
|
-
amount: new bignumber_js_1.default(path.coinOut.amount.toString())
|
|
126
|
+
amount: new bignumber_js_1.default(path.coinOut.amount.toString()),
|
|
127
127
|
},
|
|
128
128
|
})),
|
|
129
129
|
})),
|
|
@@ -188,11 +188,11 @@ const getCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
188
188
|
provider: path.provider,
|
|
189
189
|
in: {
|
|
190
190
|
coinType: (0, utils_1.normalizeStructTag)(path.from),
|
|
191
|
-
amount: new bignumber_js_1.default(path.amountIn.toString())
|
|
191
|
+
amount: new bignumber_js_1.default(path.amountIn.toString()),
|
|
192
192
|
},
|
|
193
193
|
out: {
|
|
194
194
|
coinType: (0, utils_1.normalizeStructTag)(path.target),
|
|
195
|
-
amount: new bignumber_js_1.default(path.amountOut.toString())
|
|
195
|
+
amount: new bignumber_js_1.default(path.amountOut.toString()),
|
|
196
196
|
},
|
|
197
197
|
})),
|
|
198
198
|
})),
|
|
@@ -212,11 +212,11 @@ const get7kQuote = (tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, vo
|
|
|
212
212
|
provider: QuoteProvider._7K,
|
|
213
213
|
in: {
|
|
214
214
|
coinType: tokenIn.coinType,
|
|
215
|
-
amount: new bignumber_js_1.default(quote.
|
|
215
|
+
amount: new bignumber_js_1.default(quote.swapAmountWithDecimal).div(10 ** tokenIn.decimals),
|
|
216
216
|
},
|
|
217
217
|
out: {
|
|
218
218
|
coinType: tokenOut.coinType,
|
|
219
|
-
amount: new bignumber_js_1.default(quote.
|
|
219
|
+
amount: new bignumber_js_1.default(quote.returnAmountWithDecimal).div(10 ** tokenOut.decimals),
|
|
220
220
|
},
|
|
221
221
|
routes: ((_a = quote.routes) !== null && _a !== void 0 ? _a : []).map((route, routeIndex) => ({
|
|
222
222
|
percent: new bignumber_js_1.default(route.tokenInAmount)
|
|
@@ -229,11 +229,15 @@ const get7kQuote = (tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, vo
|
|
|
229
229
|
provider: hop.pool.type,
|
|
230
230
|
in: {
|
|
231
231
|
coinType: (0, utils_1.normalizeStructTag)(hop.tokenIn),
|
|
232
|
-
amount: new bignumber_js_1.default(hop.tokenInAmount)
|
|
232
|
+
amount: new bignumber_js_1.default(hop.tokenInAmount).times(10 **
|
|
233
|
+
hop.pool.allTokens.find((t) => (0, utils_1.normalizeStructTag)(t.address) ===
|
|
234
|
+
(0, utils_1.normalizeStructTag)(hop.tokenIn)).decimal),
|
|
233
235
|
},
|
|
234
236
|
out: {
|
|
235
237
|
coinType: (0, utils_1.normalizeStructTag)(hop.tokenOut),
|
|
236
|
-
amount: new bignumber_js_1.default(hop.tokenOutAmount)
|
|
238
|
+
amount: new bignumber_js_1.default(hop.tokenOutAmount).times(10 **
|
|
239
|
+
hop.pool.allTokens.find((t) => (0, utils_1.normalizeStructTag)(t.address) ===
|
|
240
|
+
(0, utils_1.normalizeStructTag)(hop.tokenOut)).decimal),
|
|
237
241
|
},
|
|
238
242
|
})),
|
|
239
243
|
})),
|
|
@@ -270,11 +274,11 @@ const getFlowXQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
270
274
|
provider: hop.protocol(),
|
|
271
275
|
in: {
|
|
272
276
|
coinType: (0, utils_1.normalizeStructTag)(hop.input.coinType),
|
|
273
|
-
amount: new bignumber_js_1.default(hop.amountIn.toString())
|
|
277
|
+
amount: new bignumber_js_1.default(hop.amountIn.toString()),
|
|
274
278
|
},
|
|
275
279
|
out: {
|
|
276
280
|
coinType: (0, utils_1.normalizeStructTag)(hop.output.coinType),
|
|
277
|
-
amount: new bignumber_js_1.default(hop.amountOut.toString())
|
|
281
|
+
amount: new bignumber_js_1.default(hop.amountOut.toString()),
|
|
278
282
|
},
|
|
279
283
|
})),
|
|
280
284
|
})),
|