@suilend/sdk 14.0.0-next.g4630d94 → 14.1.0-next.g80e1a5e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/strategies.d.ts +3 -3
- package/strategies.js +19 -13
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"14.
|
|
1
|
+
{"name":"@suilend/sdk","version":"14.1.0-next.g80e1a5e","private":false,"description":"A TypeScript SDK for interacting with the Suilend program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./client":"./client.js","./mmt":"./mmt.js","./strategies":"./strategies.js","./api/events":"./api/events.js","./api":"./api/index.js","./lib/constants":"./lib/constants.js","./lib":"./lib/index.js","./lib/initialize":"./lib/initialize.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/proCompatible":"./lib/proCompatible.js","./lib/pyth":"./lib/pyth.js","./lib/strategyOwnerCap":"./lib/strategyOwnerCap.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./margin":"./margin/index.js","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/obligation":"./parsers/obligation.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./swap":"./swap/index.js","./swap/quote":"./swap/quote.js","./swap/transaction":"./swap/transaction.js","./utils/events":"./utils/events.js","./utils/feedId":"./utils/feedId.js","./utils":"./utils/index.js","./utils/interpolate":"./utils/interpolate.js","./utils/obligation":"./utils/obligation.js","./utils/priceGuard":"./utils/priceGuard.js","./utils/simulate":"./utils/simulate.js","./_generated/_envs":"./_generated/_envs/index.js","./_generated/_envs/mainnet":"./_generated/_envs/mainnet.js","./_generated/_framework/env":"./_generated/_framework/env.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend":"./_generated/suilend/index.js","./margin/margin/admin_cap":"./margin/margin/admin_cap.js","./margin/margin/market":"./margin/margin/market.js","./margin/margin/permissions":"./margin/margin/permissions.js","./margin/margin/position":"./margin/margin/position.js","./margin/margin/router":"./margin/margin/router.js","./margin/margin/version":"./margin/margin/version.js","./margin/utils":"./margin/utils/index.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/structs.js","./_generated/suilend/decimal/structs":"./_generated/suilend/decimal/structs.js","./_generated/suilend/lending-market/functions":"./_generated/suilend/lending-market/functions.js","./_generated/suilend/lending-market/structs":"./_generated/suilend/lending-market/structs.js","./_generated/suilend/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/structs.js","./_generated/suilend/rate-limiter/functions":"./_generated/suilend/rate-limiter/functions.js","./_generated/suilend/rate-limiter/structs":"./_generated/suilend/rate-limiter/structs.js","./_generated/suilend/reserve/structs":"./_generated/suilend/reserve/structs.js","./_generated/suilend/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/_dependencies/pyth-2/price-identifier/structs":"./_generated/_dependencies/pyth-2/price-identifier/structs.js","./_generated/_dependencies/std/ascii/structs":"./_generated/_dependencies/std/ascii/structs.js","./_generated/_dependencies/std/option/structs":"./_generated/_dependencies/std/option/structs.js","./_generated/_dependencies/std/type-name/structs":"./_generated/_dependencies/std/type-name/structs.js","./_generated/_dependencies/sui/bag/structs":"./_generated/_dependencies/sui/bag/structs.js","./_generated/_dependencies/sui/balance/structs":"./_generated/_dependencies/sui/balance/structs.js","./_generated/_dependencies/sui/object/structs":"./_generated/_dependencies/sui/object/structs.js","./_generated/_dependencies/sui/object-table/structs":"./_generated/_dependencies/sui/object-table/structs.js","./margin/margin/deps/std/type_name":"./margin/margin/deps/std/type_name.js","./margin/margin/deps/sui/vec_set":"./margin/margin/deps/sui/vec_set.js","./margin/margin/deps/suilend/lending_market":"./margin/margin/deps/suilend/lending_market.js"},"types":"./index.d.ts","scripts":{"codegen":"node ./codegen.js","codegen:install":"node ./install-codegen.js","build":"rm -rf ./dist && tsc && node ./fix-esm-imports.js","typecheck":"tsc --noEmit && tsc --noEmit -p tsconfig.test.json","test":"vitest run","lint:ci":"yarn run typecheck","prettier":"prettier --write src/ tests/","release":"yarn run build && node ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/fireflyprotocol/lending-mono.git","directory":"ts/sdks/sdk"},"dependencies":{"@cetusprotocol/aggregator-sdk":"1.7.3","@flowx-finance/sdk":"2.1.0","@pythnetwork/hermes-client":"3.1.0","@pythnetwork/pyth-sui-js":"4.0.0","@suilend/springsui-sdk":"4.1.0","bignumber.js":"11.1.5","bn.js":"5.2.5","crypto-js":"4.2.0","lodash":"4.18.1","p-limit":"7.3.3","uuid":"14.0.2"},"devDependencies":{"@mysten/bcs":"2.1.2","@mysten/sui":"2.35.0","@suilend/sui-core":"2.2.0","@tsconfig/recommended":"1.0.13","@types/bn.js":"5.2.0","@types/lodash":"4.17.26","@types/node":"26.6.5","fast-check":"4.10.2","prettier":"3.9.10","ts-node":"10.9.2","typescript":"6.0.3","vite":"8.3.4","vitest":"5.0.4"},"peerDependencies":{"@mysten/bcs":"^2.1.1","@mysten/sui":">=2.31.3 <3","@suilend/sui-core":"^2.0.1"},"type":"module"}
|
package/strategies.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AggregatorClient as CetusSdk } from "@cetusprotocol/aggregator-sdk";
|
|
2
2
|
import { SuiClientTypes } from "@mysten/sui/client";
|
|
3
3
|
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
4
|
-
import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions";
|
|
4
|
+
import { Transaction, TransactionArgument, TransactionObjectArgument, TransactionObjectInput } from "@mysten/sui/transactions";
|
|
5
5
|
import BigNumber from "bignumber.js";
|
|
6
6
|
import { LstClient } from "@suilend/springsui-sdk";
|
|
7
7
|
import { LiquidStakingInfo } from "@suilend/springsui-sdk/_generated/liquid_staking/liquid-staking/structs";
|
|
@@ -344,14 +344,14 @@ export declare const strategyUnloopToExposureTx: (...args: Parameters<typeof str
|
|
|
344
344
|
}>;
|
|
345
345
|
export declare const strategyDepositTx: (reserveMap: Record<string, ParsedReserve>, lstMap: StrategyLstMap, strategyType: StrategyType, suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, cetusSdk: CetusSdk, cetusPartnerId: string, _address: string, strategyOwnerCapId: TransactionObjectInput, obligationId: string | undefined, _deposits: StrategyDeposit[], _borrowedAmount: BigNumber, deposit: StrategyDeposit, transaction: Transaction, dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<SuiClientTypes.SimulateTransactionResult<{
|
|
346
346
|
commandResults: true;
|
|
347
|
-
}
|
|
347
|
+
}>>, depositCoin?: TransactionObjectArgument) => Promise<{
|
|
348
348
|
deposits: StrategyDeposit[];
|
|
349
349
|
borrowedAmount: BigNumber;
|
|
350
350
|
transaction: Transaction;
|
|
351
351
|
}>;
|
|
352
352
|
export declare const strategyDepositAndLoopToExposureTx: (reserveMap: Record<string, ParsedReserve>, lstMap: StrategyLstMap, strategyType: StrategyType, suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, cetusSdk: CetusSdk, cetusPartnerId: string, _address: string, strategyOwnerCapId: TransactionObjectInput, obligationId: string | undefined, _deposits: StrategyDeposit[], _borrowedAmount: BigNumber, deposit: StrategyDeposit, targetExposure: BigNumber, transaction: Transaction, dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<SuiClientTypes.SimulateTransactionResult<{
|
|
353
353
|
commandResults: true;
|
|
354
|
-
}
|
|
354
|
+
}>>, depositCoin?: TransactionObjectArgument) => Promise<{
|
|
355
355
|
deposits: StrategyDeposit[];
|
|
356
356
|
borrowedAmount: BigNumber;
|
|
357
357
|
transaction: Transaction;
|
package/strategies.js
CHANGED
|
@@ -2062,7 +2062,7 @@ export const strategyDepositTx = async (
|
|
|
2062
2062
|
// AppContext
|
|
2063
2063
|
reserveMap,
|
|
2064
2064
|
// Strategy
|
|
2065
|
-
lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _address, strategyOwnerCapId, obligationId, _deposits, _borrowedAmount, deposit, transaction, dryRunTransaction) => {
|
|
2065
|
+
lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _address, strategyOwnerCapId, obligationId, _deposits, _borrowedAmount, deposit, transaction, dryRunTransaction, depositCoin) => {
|
|
2066
2066
|
const strategyInfo = STRATEGY_TYPE_INFO_MAP[strategyType];
|
|
2067
2067
|
const lst = strategyInfo.depositLstCoinType !== undefined
|
|
2068
2068
|
? lstMap[strategyInfo.depositLstCoinType]
|
|
@@ -2088,6 +2088,13 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2088
2088
|
//
|
|
2089
2089
|
let deposits = cloneDeep(_deposits);
|
|
2090
2090
|
const borrowedAmount = _borrowedAmount;
|
|
2091
|
+
const splitDepositCoin = async (value, fromWallet) => {
|
|
2092
|
+
if (depositCoin === undefined)
|
|
2093
|
+
return fromWallet(value);
|
|
2094
|
+
const coin = transaction.splitCoins(depositCoin, [value]);
|
|
2095
|
+
transaction.transferObjects([depositCoin], _address);
|
|
2096
|
+
return coin;
|
|
2097
|
+
};
|
|
2091
2098
|
// 1) Deposit
|
|
2092
2099
|
// 1.1) SUI
|
|
2093
2100
|
if (isSui(deposit.coinType)) {
|
|
@@ -2098,12 +2105,10 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2098
2105
|
.minus(getStrategyLstMintFee(lstMap, depositReserves.lst.coinType, suiAmount))
|
|
2099
2106
|
.times(lst?.suiToLstExchangeRate ?? 1)).decimalPlaces(LST_DECIMALS, BigNumber.ROUND_DOWN);
|
|
2100
2107
|
// 1.1.1) Split coins
|
|
2101
|
-
const suiCoin =
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
.toString(),
|
|
2106
|
-
]);
|
|
2108
|
+
const suiCoin = await splitDepositCoin(suiAmount
|
|
2109
|
+
.times(10 ** SUI_DECIMALS)
|
|
2110
|
+
.integerValue(BigNumber.ROUND_DOWN)
|
|
2111
|
+
.toString(), (value) => transaction.splitCoins(transaction.gas, [value]));
|
|
2107
2112
|
// 1.1.2) Stake SUI for LST
|
|
2108
2113
|
const lstCoin = lst.client.mint(transaction, suiCoin);
|
|
2109
2114
|
// 1.1.3) Deposit LST (1x exposure)
|
|
@@ -2117,10 +2122,11 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2117
2122
|
// 1.2) LST
|
|
2118
2123
|
else if (deposit.coinType === depositReserves.lst?.coinType) {
|
|
2119
2124
|
// 1.2.1) Split coins
|
|
2120
|
-
const
|
|
2125
|
+
const lstCoinType = depositReserves.lst.coinType;
|
|
2126
|
+
const lstCoin = await splitDepositCoin(deposit.depositedAmount
|
|
2121
2127
|
.times(10 ** LST_DECIMALS)
|
|
2122
2128
|
.integerValue(BigNumber.ROUND_DOWN)
|
|
2123
|
-
.toString(), transaction);
|
|
2129
|
+
.toString(), (value) => getSpendableCoin(suiGrpcClient, _address, lstCoinType, value, transaction));
|
|
2124
2130
|
// 1.2.2) Deposit LST (1x exposure)
|
|
2125
2131
|
strategyDeposit(strategyType, lstCoin, depositReserves.lst.coinType, strategyOwnerCapId, suilendClient.findReserveArrayIndex(depositReserves.lst.coinType), transaction);
|
|
2126
2132
|
// 1.2.3) Update state
|
|
@@ -2130,10 +2136,10 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2130
2136
|
else {
|
|
2131
2137
|
const otherReserve = reserveMap[deposit.coinType];
|
|
2132
2138
|
// 1.3.1) Split coins
|
|
2133
|
-
const otherCoin = await
|
|
2139
|
+
const otherCoin = await splitDepositCoin(deposit.depositedAmount
|
|
2134
2140
|
.times(10 ** otherReserve.token.decimals)
|
|
2135
2141
|
.integerValue(BigNumber.ROUND_DOWN)
|
|
2136
|
-
.toString(), transaction);
|
|
2142
|
+
.toString(), (value) => getSpendableCoin(suiGrpcClient, _address, otherReserve.coinType, value, transaction));
|
|
2137
2143
|
// 1.3.2) If the deposit coin is the same as the borrow coin, swap to base first
|
|
2138
2144
|
if (deposit.coinType === borrowReserve.coinType && depositReserve) {
|
|
2139
2145
|
const routers = await cetusSdk.findRouters({
|
|
@@ -2191,7 +2197,7 @@ export const strategyDepositAndLoopToExposureTx = async (
|
|
|
2191
2197
|
// AppContext
|
|
2192
2198
|
reserveMap,
|
|
2193
2199
|
// Strategy
|
|
2194
|
-
lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _address, strategyOwnerCapId, obligationId, _deposits, _borrowedAmount, deposit, targetExposure, transaction, dryRunTransaction) => {
|
|
2200
|
+
lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _address, strategyOwnerCapId, obligationId, _deposits, _borrowedAmount, deposit, targetExposure, transaction, dryRunTransaction, depositCoin) => {
|
|
2195
2201
|
const strategyInfo = STRATEGY_TYPE_INFO_MAP[strategyType];
|
|
2196
2202
|
const lst = strategyInfo.depositLstCoinType !== undefined
|
|
2197
2203
|
? lstMap[strategyInfo.depositLstCoinType]
|
|
@@ -2230,7 +2236,7 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2230
2236
|
let borrowedAmount = _borrowedAmount;
|
|
2231
2237
|
// 1) Deposit (1x exposure)
|
|
2232
2238
|
// 1.1) Deposit
|
|
2233
|
-
const { deposits: newDeposits, borrowedAmount: newBorrowedAmount, transaction: newTransaction, } = await strategyDepositTx(reserveMap, lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _address, strategyOwnerCapId, obligationId, deposits, borrowedAmount, deposit, transaction, dryRunTransaction);
|
|
2239
|
+
const { deposits: newDeposits, borrowedAmount: newBorrowedAmount, transaction: newTransaction, } = await strategyDepositTx(reserveMap, lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _address, strategyOwnerCapId, obligationId, deposits, borrowedAmount, deposit, transaction, dryRunTransaction, depositCoin);
|
|
2234
2240
|
// 1.2) Update state
|
|
2235
2241
|
deposits = newDeposits;
|
|
2236
2242
|
borrowedAmount = newBorrowedAmount;
|