@suilend/sdk 1.1.9 → 1.1.11
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/README.md +0 -2
- package/client.d.ts +1 -1
- package/client.js +5 -6
- package/index.d.ts +1 -2
- package/index.js +1 -2
- package/package.json +1 -1
- package/utils/index.d.ts +7 -0
- package/utils/index.js +39 -0
- package/utils.d.ts +0 -7
- package/utils.js +0 -41
package/README.md
CHANGED
|
@@ -4,8 +4,6 @@ A TypeScript SDK for interacting with the Suilend program published on npm as [`
|
|
|
4
4
|
|
|
5
5
|
For examples, please see [suilend-public/frontend](https://github.com/solendprotocol/suilend-public/tree/HEAD/frontend), an open-source Suilend client powered by and developed alongside the Suilend SDK, in the Suilend monorepo.
|
|
6
6
|
|
|
7
|
-
Note: `suilend-public/frontend` imports the SDK directly from the Suilend monorepo via aliased paths (see [suilend-public/frontend/tsconfig.ts](https://github.com/solendprotocol/suilend-public/tree/HEAD/frontend/tsconfig.json)) and does not use the npm package, so the import paths may look slightly different.
|
|
8
|
-
|
|
9
7
|
---
|
|
10
8
|
|
|
11
9
|
Got a suggestion, running into issues, or have a question? Join our [#dev-support](https://discord.com/channels/1202984617087598622/1238023733403193385) channel on Discord.
|
package/client.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare class SuilendClient {
|
|
|
27
27
|
static getLendingMarketOwnerCapId(ownerId: string, lendingMarketTypeArgs: string[], client: SuiClient): Promise<string | null>;
|
|
28
28
|
getLendingMarketOwnerCapId(ownerId: string): Promise<string | null>;
|
|
29
29
|
createReserve(lendingMarketOwnerCapId: string, transaction: Transaction, pythPriceId: string, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
|
30
|
-
addReward(ownerId: string, lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardCoinType: string, rewardValue: string, startTimeMs: bigint, endTimeMs: bigint, transaction: Transaction): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
|
30
|
+
addReward(ownerId: string, lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardCoinType: string, rewardValue: string, startTimeMs: bigint, endTimeMs: bigint, transaction: Transaction, mergeCoins?: boolean): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
|
31
31
|
cancelReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
|
32
32
|
closeReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
|
33
33
|
claimReward(obligationOwnerCapId: string, reserveArrayIndex: bigint, rewardIndex: bigint, rewardType: string, side: Side, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
package/client.js
CHANGED
|
@@ -176,18 +176,17 @@ class SuilendClient {
|
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
-
addReward(
|
|
180
|
-
return __awaiter(this,
|
|
179
|
+
addReward(ownerId_1, lendingMarketOwnerCapId_1, reserveArrayIndex_1, isDepositReward_1, rewardCoinType_1, rewardValue_1, startTimeMs_1, endTimeMs_1, transaction_1) {
|
|
180
|
+
return __awaiter(this, arguments, void 0, function* (ownerId, lendingMarketOwnerCapId, reserveArrayIndex, isDepositReward, rewardCoinType, rewardValue, startTimeMs, endTimeMs, transaction, mergeCoins = true) {
|
|
181
181
|
const isSui = (0, utils_1.normalizeStructTag)(rewardCoinType) === (0, utils_1.normalizeStructTag)(SUI_COINTYPE);
|
|
182
182
|
const coins = (yield this.client.getCoins({
|
|
183
183
|
owner: ownerId,
|
|
184
184
|
coinType: rewardCoinType,
|
|
185
185
|
})).data;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), coins.map((c) => transaction.object(c.coinObjectId)).slice(1));
|
|
186
|
+
if (coins.length > 1 && !isSui && mergeCoins) {
|
|
187
|
+
transaction.mergeCoins(transaction.object(coins[0].coinObjectId), coins.map((c) => transaction.object(c.coinObjectId)).slice(1));
|
|
189
188
|
}
|
|
190
|
-
const [rewardCoin] = transaction.splitCoins(isSui ? transaction.gas : transaction.object(
|
|
189
|
+
const [rewardCoin] = transaction.splitCoins(isSui ? transaction.gas : transaction.object(coins[0].coinObjectId), [rewardValue]);
|
|
191
190
|
return (0, functions_1.addPoolReward)(transaction, [this.lendingMarket.$typeArgs[0], rewardCoinType], {
|
|
192
191
|
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
193
192
|
lendingMarket: transaction.object(this.lendingMarket.id),
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -16,8 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./api"), exports);
|
|
18
18
|
__exportStar(require("./parsers"), exports);
|
|
19
|
-
__exportStar(require("./utils
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
20
|
__exportStar(require("./client"), exports);
|
|
21
21
|
__exportStar(require("./constants"), exports);
|
|
22
22
|
__exportStar(require("./types"), exports);
|
|
23
|
-
__exportStar(require("./utils"), exports);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"1.1.
|
|
1
|
+
{"name":"@suilend/sdk","version":"1.1.11","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","./constants":"./constants.js","./types":"./types.js","./api/events":"./api/events.js","./api":"./api/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","./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/price-identifier/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/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","release":"bun run build && bun ts-node ./prepublish.ts && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/solendprotocol/suilend-public.git"},"bugs":{"url":"https://github.com/solendprotocol/suilend-public/issues"},"homepage":"https://github.com/solendprotocol/suilend-public/tree/HEAD/sdk#readme","dependencies":{"@mysten/bcs":"1.1.0","@mysten/sui":"1.14.1","@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","p-limit":"3.1.0","uuid":"^9.0.1"},"devDependencies":{"@types/node":"^20.12.7","ts-node":"^10.9.2","typescript":"^5.3.3"}}
|
package/utils/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { ParsedReserve } from "../parsers/reserve";
|
|
1
3
|
export * from "./events";
|
|
2
4
|
export * from "./obligation";
|
|
3
5
|
export * from "./simulate";
|
|
6
|
+
export declare const toHexString: (bytes: number[]) => string;
|
|
7
|
+
export declare const reserveSort: (reserves: ParsedReserve[], aCoinType: string, bCoinType: string) => number;
|
|
8
|
+
export declare const linearlyInterpolate: (array: any[], xKey: string, yKey: string, _xValue: number | BigNumber) => BigNumber;
|
|
9
|
+
export declare const isCTokenCoinType: (coinType: string) => boolean;
|
|
10
|
+
export declare const extractCTokenCoinType: (coinType: string) => string;
|
package/utils/index.js
CHANGED
|
@@ -13,7 +13,46 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.extractCTokenCoinType = exports.isCTokenCoinType = exports.linearlyInterpolate = exports.reserveSort = exports.toHexString = void 0;
|
|
21
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
22
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
17
23
|
__exportStar(require("./events"), exports);
|
|
18
24
|
__exportStar(require("./obligation"), exports);
|
|
19
25
|
__exportStar(require("./simulate"), exports);
|
|
26
|
+
const toHexString = (bytes) => Array.from(bytes, function (byte) {
|
|
27
|
+
return ("0" + (byte & 0xff).toString(16)).slice(-2);
|
|
28
|
+
}).join("");
|
|
29
|
+
exports.toHexString = toHexString;
|
|
30
|
+
const reserveSort = (reserves, aCoinType, bCoinType) => reserves.findIndex((r) => r.coinType === aCoinType) -
|
|
31
|
+
reserves.findIndex((r) => r.coinType === bCoinType);
|
|
32
|
+
exports.reserveSort = reserveSort;
|
|
33
|
+
const linearlyInterpolate = (array, xKey, yKey, _xValue) => {
|
|
34
|
+
let i = 1;
|
|
35
|
+
while (i < array.length) {
|
|
36
|
+
const leftXValue = new bignumber_js_1.default(array[i - 1][xKey]);
|
|
37
|
+
const leftYValue = new bignumber_js_1.default(array[i - 1][yKey]);
|
|
38
|
+
const xValue = new bignumber_js_1.default(_xValue);
|
|
39
|
+
const rightXValue = new bignumber_js_1.default(array[i][xKey]);
|
|
40
|
+
const rightYValue = new bignumber_js_1.default(array[i][yKey]);
|
|
41
|
+
if (xValue.gte(leftXValue) && xValue.lte(rightXValue)) {
|
|
42
|
+
const weight = new bignumber_js_1.default(xValue.minus(leftXValue)).div(rightXValue.minus(leftXValue));
|
|
43
|
+
return leftYValue.plus(weight.times(rightYValue.minus(leftYValue)));
|
|
44
|
+
}
|
|
45
|
+
i = i + 1;
|
|
46
|
+
}
|
|
47
|
+
// Should never reach here
|
|
48
|
+
return new bignumber_js_1.default(0);
|
|
49
|
+
};
|
|
50
|
+
exports.linearlyInterpolate = linearlyInterpolate;
|
|
51
|
+
const isCTokenCoinType = (coinType) => coinType.includes("::reserve::CToken<") && coinType.endsWith(">");
|
|
52
|
+
exports.isCTokenCoinType = isCTokenCoinType;
|
|
53
|
+
const extractCTokenCoinType = (coinType) => {
|
|
54
|
+
if (!(0, exports.isCTokenCoinType)(coinType))
|
|
55
|
+
throw new Error("Not a CToken ");
|
|
56
|
+
return (0, utils_1.normalizeStructTag)(coinType.split("::reserve::CToken")[1].split(",")[1].slice(0, -1));
|
|
57
|
+
};
|
|
58
|
+
exports.extractCTokenCoinType = extractCTokenCoinType;
|
package/utils.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
|
-
import { ParsedReserve } from "./parsers/reserve";
|
|
3
|
-
export declare const toHexString: (bytes: number[]) => string;
|
|
4
|
-
export declare const reserveSort: (reserves: ParsedReserve[], aCoinType: string, bCoinType: string) => number;
|
|
5
|
-
export declare const linearlyInterpolate: (array: any[], xKey: string, yKey: string, _xValue: number | BigNumber) => BigNumber;
|
|
6
|
-
export declare const isCTokenCoinType: (coinType: string) => boolean;
|
|
7
|
-
export declare const extractCTokenCoinType: (coinType: string) => string;
|
package/utils.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extractCTokenCoinType = exports.isCTokenCoinType = exports.linearlyInterpolate = exports.reserveSort = exports.toHexString = void 0;
|
|
7
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
8
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
-
const toHexString = (bytes) => Array.from(bytes, function (byte) {
|
|
10
|
-
return ("0" + (byte & 0xff).toString(16)).slice(-2);
|
|
11
|
-
}).join("");
|
|
12
|
-
exports.toHexString = toHexString;
|
|
13
|
-
const reserveSort = (reserves, aCoinType, bCoinType) => reserves.findIndex((r) => r.coinType === aCoinType) -
|
|
14
|
-
reserves.findIndex((r) => r.coinType === bCoinType);
|
|
15
|
-
exports.reserveSort = reserveSort;
|
|
16
|
-
const linearlyInterpolate = (array, xKey, yKey, _xValue) => {
|
|
17
|
-
let i = 1;
|
|
18
|
-
while (i < array.length) {
|
|
19
|
-
const leftXValue = new bignumber_js_1.default(array[i - 1][xKey]);
|
|
20
|
-
const leftYValue = new bignumber_js_1.default(array[i - 1][yKey]);
|
|
21
|
-
const xValue = new bignumber_js_1.default(_xValue);
|
|
22
|
-
const rightXValue = new bignumber_js_1.default(array[i][xKey]);
|
|
23
|
-
const rightYValue = new bignumber_js_1.default(array[i][yKey]);
|
|
24
|
-
if (xValue.gte(leftXValue) && xValue.lte(rightXValue)) {
|
|
25
|
-
const weight = new bignumber_js_1.default(xValue.minus(leftXValue)).div(rightXValue.minus(leftXValue));
|
|
26
|
-
return leftYValue.plus(weight.times(rightYValue.minus(leftYValue)));
|
|
27
|
-
}
|
|
28
|
-
i = i + 1;
|
|
29
|
-
}
|
|
30
|
-
// Should never reach here
|
|
31
|
-
return new bignumber_js_1.default(0);
|
|
32
|
-
};
|
|
33
|
-
exports.linearlyInterpolate = linearlyInterpolate;
|
|
34
|
-
const isCTokenCoinType = (coinType) => coinType.includes("::reserve::CToken<") && coinType.endsWith(">");
|
|
35
|
-
exports.isCTokenCoinType = isCTokenCoinType;
|
|
36
|
-
const extractCTokenCoinType = (coinType) => {
|
|
37
|
-
if (!(0, exports.isCTokenCoinType)(coinType))
|
|
38
|
-
throw new Error("Not a CToken ");
|
|
39
|
-
return (0, utils_1.normalizeStructTag)(coinType.split("::reserve::CToken")[1].split(",")[1].slice(0, -1));
|
|
40
|
-
};
|
|
41
|
-
exports.extractCTokenCoinType = extractCTokenCoinType;
|