@suilend/sdk 2.0.5 → 2.0.6
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 +1 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +1 -1
- package/strategies.js +1 -2
- package/swap/transaction.js +1 -1
- package/lib/coin.d.ts +0 -3
- package/lib/coin.js +0 -67
package/client.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID, fromBase64, normalizeStructTag, toHex, } from "@mysten/sui/utils";
|
|
11
11
|
import { SuiPriceServiceConnection, SuiPythClient, } from "@pythnetwork/pyth-sui-js";
|
|
12
|
-
import { extractCTokenCoinType, getAllCoins } from "@suilend/sui-fe";
|
|
12
|
+
import { extractCTokenCoinType, getAllCoins, getSpendableCoin, } from "@suilend/sui-fe";
|
|
13
13
|
import { PriceInfoObject } from "./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs";
|
|
14
14
|
import { phantom } from "./_generated/_framework/reified";
|
|
15
15
|
import { PKG_V10, setPublishedAt } from "./_generated/suilend";
|
|
@@ -20,7 +20,6 @@ import { createLendingMarket } from "./_generated/suilend/lending-market-registr
|
|
|
20
20
|
import { Obligation } from "./_generated/suilend/obligation/structs";
|
|
21
21
|
import { newConfig as createRateLimiterConfig, } from "./_generated/suilend/rate-limiter/functions";
|
|
22
22
|
import { createReserveConfig, } from "./_generated/suilend/reserve-config/functions";
|
|
23
|
-
import { getSpendableCoin } from "./lib/coin";
|
|
24
23
|
import { PRIMARY_PYTH_ENDPOINT } from "./lib/pyth";
|
|
25
24
|
import { Side } from "./lib/types";
|
|
26
25
|
const SUI_COINTYPE = "0x2::sui::SUI";
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"2.0.
|
|
1
|
+
{"name":"@suilend/sdk","version":"2.0.6","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","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers/obligation":"./parsers/obligation.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./swap/transaction":"./swap/transaction.js","./swap/quote":"./swap/quote.js","./swap":"./swap/index.js","./utils/simulate":"./utils/simulate.js","./utils/events":"./utils/events.js","./utils/obligation":"./utils/obligation.js","./utils":"./utils/index.js","./lib/constants":"./lib/constants.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./lib/initialize":"./lib/initialize.js","./lib":"./lib/index.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/strategyOwnerCap":"./lib/strategyOwnerCap.js","./lib/pyth":"./lib/pyth.js","./api/events":"./api/events.js","./api":"./api/index.js","./margin":"./margin/index.js","./margin/utils":"./margin/utils/index.js","./margin/margin/market":"./margin/margin/market.js","./margin/margin/version":"./margin/margin/version.js","./margin/margin/router":"./margin/margin/router.js","./margin/margin/admin_cap":"./margin/margin/admin_cap.js","./margin/margin/permissions":"./margin/margin/permissions.js","./margin/margin/position":"./margin/margin/position.js","./_generated/suilend":"./_generated/suilend/index.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/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/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/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/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./margin/margin/deps/sui/vec_set":"./margin/margin/deps/sui/vec_set.js","./margin/margin/deps/std/type_name":"./margin/margin/deps/std/type_name.js","./margin/margin/deps/suilend/lending_market":"./margin/margin/deps/suilend/lending_market.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":"./_generated/_dependencies/source/0x1/index.js","./_generated/_dependencies/source/0x2/object-table/structs":"./_generated/_dependencies/source/0x2/object-table/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/bag/structs":"./_generated/_dependencies/source/0x2/bag/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.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"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix src/","prettier":"prettier --write src/","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ./release.js && 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":{"@bluefin-exchange/bluefin7k-aggregator-sdk":"^5.4.1","@cetusprotocol/aggregator-sdk":"^1.4.5","@flowx-finance/sdk":"^1.15.0","@suilend/springsui-sdk":"^2.0.2","aftermath-ts-sdk":"^1.3.28","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":"2.0.1","@mysten/sui":"2.3.1","@suilend/sui-fe":"^2.0.11","@pythnetwork/pyth-sui-js":"2.2.0"},"overrides":{"chalk":"5.3.0","strip-ansi":"7.1.0","color-convert":"2.0.1","color-name":"1.1.4","is-core-module":"2.13.1","error-ex":"1.3.2","has-ansi":"5.0.1","axios":"<=1.11.0"}}
|
package/strategies.js
CHANGED
|
@@ -14,9 +14,8 @@ import BigNumber from "bignumber.js";
|
|
|
14
14
|
import { BN } from "bn.js";
|
|
15
15
|
import { cloneDeep } from "lodash";
|
|
16
16
|
import { LstClient, SPRING_SUI_UPGRADE_CAP_ID, getLatestPackageId as getLatestSpringSuiPackageId, } from "@suilend/springsui-sdk";
|
|
17
|
-
import { API_URL, MAX_U64, MS_PER_YEAR, NORMALIZED_AUSD_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_xBTC_COINTYPE, isSui, } from "@suilend/sui-fe";
|
|
17
|
+
import { API_URL, MAX_U64, MS_PER_YEAR, NORMALIZED_AUSD_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_xBTC_COINTYPE, getSpendableCoin, isSui, } from "@suilend/sui-fe";
|
|
18
18
|
import { getNetAprPercent } from "./lib";
|
|
19
|
-
import { getSpendableCoin } from "./lib/coin";
|
|
20
19
|
import { getRewardsMap } from "./lib/liquidityMining";
|
|
21
20
|
import { STRATEGY_TYPE_INFO_MAP, StrategyType, strategyBorrow, strategyClaimRewardsAndMergeCoins, strategyDeposit, strategyWithdraw, } from "./lib/strategyOwnerCap";
|
|
22
21
|
import { MMT_CONTRACT_PACKAGE_ID, MMT_VERSION_OBJECT_ID } from "./mmt";
|
package/swap/transaction.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { BluefinXTx, buildTx as buildBluefin7kTransaction, } from "@bluefin-exchange/bluefin7k-aggregator-sdk/cjs";
|
|
11
11
|
import { Coin as FlowXCoin, Commission as FlowXCommission, CommissionType as FlowXCommissionType, TradeBuilder as FlowXTradeBuilder, } from "@flowx-finance/sdk";
|
|
12
|
-
import { getSpendableCoin } from "
|
|
12
|
+
import { getSpendableCoin } from "@suilend/sui-fe";
|
|
13
13
|
import { QuoteProvider } from "./quote";
|
|
14
14
|
const getSwapTransactionWrapper = (provider, getSwapTransaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
15
|
console.log(`[getSwapTransactionWrapper] fetching transaction for ${provider} quote`);
|
package/lib/coin.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
2
|
-
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
3
|
-
export declare const getSpendableCoin: (suiClient: SuiJsonRpcClient, address: string, coinType: string, value: string, transaction: Transaction) => Promise<TransactionObjectArgument>;
|
package/lib/coin.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
import { getAllCoins, isSui, mergeAllCoins } from "@suilend/sui-fe";
|
|
11
|
-
// Build a spendable coin using owned coin objects, address balance, or both.
|
|
12
|
-
export const getSpendableCoin = (suiClient, address, coinType, value, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
var _a;
|
|
14
|
-
const spendValue = BigInt(value);
|
|
15
|
-
if (spendValue <= BigInt(0)) {
|
|
16
|
-
throw new Error("Spend amount must be positive");
|
|
17
|
-
}
|
|
18
|
-
// Address-balance withdrawals resolve against the transaction sender.
|
|
19
|
-
transaction.setSenderIfNotSet(address);
|
|
20
|
-
const [coins, balance] = yield Promise.all([
|
|
21
|
-
getAllCoins(suiClient, address, coinType),
|
|
22
|
-
suiClient.getBalance({ owner: address, coinType }),
|
|
23
|
-
]);
|
|
24
|
-
const nonZeroCoins = coins.filter((c) => BigInt(c.balance) > BigInt(0));
|
|
25
|
-
const objectCoinBalance = nonZeroCoins.reduce((sum, c) => sum + BigInt(c.balance), BigInt(0));
|
|
26
|
-
const addressBalanceAvailable = BigInt((_a = balance.fundsInAddressBalance) !== null && _a !== void 0 ? _a : "0");
|
|
27
|
-
const totalAvailable = BigInt(balance.totalBalance);
|
|
28
|
-
if (totalAvailable < spendValue) {
|
|
29
|
-
throw new Error(`Insufficient ${coinType} balance: need ${value}, have ${balance.totalBalance} (${objectCoinBalance.toString()} in coins, ${addressBalanceAvailable.toString()} in address)`);
|
|
30
|
-
}
|
|
31
|
-
const objectCoinSpend = objectCoinBalance >= spendValue ? spendValue : objectCoinBalance;
|
|
32
|
-
const addressBalanceSpend = spendValue - objectCoinSpend;
|
|
33
|
-
console.log(`[getSpendableCoin] ${coinType} requested=${value} coinObjects=${objectCoinSpend.toString()} addressBalance=${addressBalanceSpend.toString()}`);
|
|
34
|
-
// Address balance only.
|
|
35
|
-
if (objectCoinSpend === BigInt(0)) {
|
|
36
|
-
return transaction.moveCall({
|
|
37
|
-
target: "0x2::coin::redeem_funds",
|
|
38
|
-
typeArguments: [coinType],
|
|
39
|
-
arguments: [transaction.withdrawal({ amount: value, type: coinType })],
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const mergedCoin = mergeAllCoins(coinType, transaction, nonZeroCoins);
|
|
43
|
-
const coinSource = isSui(coinType)
|
|
44
|
-
? transaction.gas
|
|
45
|
-
: transaction.object(mergedCoin.coinObjectId);
|
|
46
|
-
// Coin objects only.
|
|
47
|
-
if (addressBalanceSpend === BigInt(0)) {
|
|
48
|
-
const [sendCoin] = transaction.splitCoins(coinSource, [value]);
|
|
49
|
-
return sendCoin;
|
|
50
|
-
}
|
|
51
|
-
// Mixed: split from coin objects, redeem the rest from address balance, merge.
|
|
52
|
-
const [objectCoin] = transaction.splitCoins(coinSource, [
|
|
53
|
-
objectCoinSpend.toString(),
|
|
54
|
-
]);
|
|
55
|
-
const addressCoin = transaction.moveCall({
|
|
56
|
-
target: "0x2::coin::redeem_funds",
|
|
57
|
-
typeArguments: [coinType],
|
|
58
|
-
arguments: [
|
|
59
|
-
transaction.withdrawal({
|
|
60
|
-
amount: addressBalanceSpend.toString(),
|
|
61
|
-
type: coinType,
|
|
62
|
-
}),
|
|
63
|
-
],
|
|
64
|
-
});
|
|
65
|
-
transaction.mergeCoins(objectCoin, [addressCoin]);
|
|
66
|
-
return objectCoin;
|
|
67
|
-
});
|