@suilend/springsui-cli 1.0.2 → 1.0.4
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/sdk/src/index.d.ts +8 -2
- package/sdk/src/index.js +35 -22
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/springsui-cli","version":"1.0.
|
|
1
|
+
{"name":"@suilend/springsui-cli","version":"1.0.4","private":false,"description":"A CLI for interacting with the SpringSui program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./cli/src":"./cli/src/index.js","./sdk/src":"./sdk/src/index.js","./sdk/src/_generated/_framework/reified":"./sdk/src/_generated/_framework/reified.js","./sdk/src/_generated/_framework/util":"./sdk/src/_generated/_framework/util.js","./sdk/src/_generated/_framework/vector":"./sdk/src/_generated/_framework/vector.js","./sdk/src/_generated/liquid_staking":"./sdk/src/_generated/liquid_staking/index.js","./sdk/src/_generated/liquid_staking/cell/structs":"./sdk/src/_generated/liquid_staking/cell/structs.js","./sdk/src/_generated/liquid_staking/fees/functions":"./sdk/src/_generated/liquid_staking/fees/functions.js","./sdk/src/_generated/liquid_staking/fees/structs":"./sdk/src/_generated/liquid_staking/fees/structs.js","./sdk/src/_generated/liquid_staking/liquid-staking/functions":"./sdk/src/_generated/liquid_staking/liquid-staking/functions.js","./sdk/src/_generated/liquid_staking/liquid-staking/structs":"./sdk/src/_generated/liquid_staking/liquid-staking/structs.js","./sdk/src/_generated/liquid_staking/storage/structs":"./sdk/src/_generated/liquid_staking/storage/structs.js","./sdk/src/_generated/liquid_staking/version/structs":"./sdk/src/_generated/liquid_staking/version/structs.js","./sdk/src/_generated/liquid_staking/weight/functions":"./sdk/src/_generated/liquid_staking/weight/functions.js","./sdk/src/_generated/liquid_staking/weight/structs":"./sdk/src/_generated/liquid_staking/weight/structs.js","./sdk/src/_generated/_dependencies/source/0x1":"./sdk/src/_generated/_dependencies/source/0x1/index.js","./sdk/src/_generated/_dependencies/source/0x2":"./sdk/src/_generated/_dependencies/source/0x2/index.js","./sdk/src/_generated/_dependencies/source/0x3":"./sdk/src/_generated/_dependencies/source/0x3/index.js","./sdk/src/_generated/_dependencies/source/0x1/ascii/structs":"./sdk/src/_generated/_dependencies/source/0x1/ascii/structs.js","./sdk/src/_generated/_dependencies/source/0x1/option/structs":"./sdk/src/_generated/_dependencies/source/0x1/option/structs.js","./sdk/src/_generated/_dependencies/source/0x1/string/structs":"./sdk/src/_generated/_dependencies/source/0x1/string/structs.js","./sdk/src/_generated/_dependencies/source/0x1/type-name/structs":"./sdk/src/_generated/_dependencies/source/0x1/type-name/structs.js","./sdk/src/_generated/_dependencies/source/0x2/bag/structs":"./sdk/src/_generated/_dependencies/source/0x2/bag/structs.js","./sdk/src/_generated/_dependencies/source/0x2/balance/structs":"./sdk/src/_generated/_dependencies/source/0x2/balance/structs.js","./sdk/src/_generated/_dependencies/source/0x2/coin/structs":"./sdk/src/_generated/_dependencies/source/0x2/coin/structs.js","./sdk/src/_generated/_dependencies/source/0x2/object/structs":"./sdk/src/_generated/_dependencies/source/0x2/object/structs.js","./sdk/src/_generated/_dependencies/source/0x2/sui/structs":"./sdk/src/_generated/_dependencies/source/0x2/sui/structs.js","./sdk/src/_generated/_dependencies/source/0x2/table/structs":"./sdk/src/_generated/_dependencies/source/0x2/table/structs.js","./sdk/src/_generated/_dependencies/source/0x2/url/structs":"./sdk/src/_generated/_dependencies/source/0x2/url/structs.js","./sdk/src/_generated/_dependencies/source/0x2/vec-map/structs":"./sdk/src/_generated/_dependencies/source/0x2/vec-map/structs.js","./sdk/src/_generated/_dependencies/source/0x3/staking-pool/structs":"./sdk/src/_generated/_dependencies/source/0x3/staking-pool/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/solendprotocol/liquid-staking.git"},"bugs":{"url":"https://github.com/solendprotocol/liquid-staking/issues"},"dependencies":{"@mysten/bcs":"1.1.0","@mysten/sui":"1.14.3","commander":"^12.1.0"},"devDependencies":{"ts-node":"^10.9.2"}}
|
package/sdk/src/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { SuiClient } from "@mysten/sui/client";
|
|
2
2
|
import { Transaction, TransactionObjectInput } from "@mysten/sui/transactions";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
3
4
|
import { LiquidStakingInfo } from "./_generated/liquid_staking/liquid-staking/structs";
|
|
4
5
|
export interface LiquidStakingObjectInfo {
|
|
5
6
|
id: string;
|
|
6
7
|
type: string;
|
|
7
8
|
weightHookId: string;
|
|
8
9
|
}
|
|
10
|
+
export declare const SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
|
|
9
11
|
export declare class LstClient {
|
|
10
12
|
liquidStakingObject: LiquidStakingObjectInfo;
|
|
11
13
|
client: SuiClient;
|
|
@@ -18,6 +20,10 @@ export declare class LstClient {
|
|
|
18
20
|
$kind: "NestedResult";
|
|
19
21
|
NestedResult: [number, number];
|
|
20
22
|
};
|
|
23
|
+
mintAndRebalance: (tx: Transaction, amount: string) => {
|
|
24
|
+
$kind: "NestedResult";
|
|
25
|
+
NestedResult: [number, number];
|
|
26
|
+
};
|
|
21
27
|
mintAndRebalanceAndSendToUser: (tx: Transaction, address: string, amount: string) => void;
|
|
22
28
|
redeemLst(tx: Transaction, lstId: TransactionObjectInput): {
|
|
23
29
|
$kind: "NestedResult";
|
|
@@ -38,11 +44,11 @@ export declare class LstClient {
|
|
|
38
44
|
};
|
|
39
45
|
setValidatorAddressesAndWeights(tx: Transaction, weightHookId: TransactionObjectInput, weightHookAdminCap: TransactionObjectInput, validatorAddressesAndWeights: Record<string, number>): void;
|
|
40
46
|
rebalance(tx: Transaction, weightHookId: TransactionObjectInput): void;
|
|
47
|
+
getSpringSuiApy(): Promise<BigNumber>;
|
|
41
48
|
}
|
|
42
|
-
export declare
|
|
49
|
+
export declare const fetchLiquidStakingInfo: (info: LiquidStakingObjectInfo, client: SuiClient) => Promise<LiquidStakingInfo<any>>;
|
|
43
50
|
export interface FeeConfigArgs {
|
|
44
51
|
mintFeeBps?: number;
|
|
45
52
|
redeemFeeBps?: number;
|
|
46
53
|
spreadFeeBps?: number;
|
|
47
54
|
}
|
|
48
|
-
export declare function getSpringSuiApy(client: SuiClient): Promise<number | undefined>;
|
package/sdk/src/index.js
CHANGED
|
@@ -31,10 +31,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
34
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.LstClient = void 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
exports.fetchLiquidStakingInfo = exports.LstClient = exports.SUILEND_VALIDATOR_ADDRESS = void 0;
|
|
39
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
40
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
38
41
|
const reified_1 = require("./_generated/_framework/reified");
|
|
39
42
|
const liquid_staking_1 = require("./_generated/liquid_staking");
|
|
40
43
|
const functions_1 = require("./_generated/liquid_staking/fees/functions");
|
|
@@ -43,7 +46,7 @@ const structs_1 = require("./_generated/liquid_staking/liquid-staking/structs");
|
|
|
43
46
|
const weightHookGenerated = __importStar(require("./_generated/liquid_staking/weight/functions"));
|
|
44
47
|
const structs_2 = require("./_generated/liquid_staking/weight/structs");
|
|
45
48
|
const SUI_SYSTEM_STATE_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
46
|
-
|
|
49
|
+
exports.SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
|
|
47
50
|
const SPRING_SUI_UPGRADE_CAP_ID = "0x4dc657b6c0fe896f4b94fee1ceac96312dde0a36b94e799caaec30deb53dcd67";
|
|
48
51
|
function getLatestPackageId(client, upgradeCapId) {
|
|
49
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -102,11 +105,15 @@ class LstClient {
|
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
107
|
constructor(liquidStakingObject, client) {
|
|
105
|
-
this.
|
|
108
|
+
this.mintAndRebalance = (tx, amount) => {
|
|
106
109
|
const [sui] = tx.splitCoins(tx.gas, [BigInt(amount)]);
|
|
107
|
-
const
|
|
108
|
-
tx.transferObjects([rSui], address);
|
|
110
|
+
const lst = this.mint(tx, sui);
|
|
109
111
|
this.rebalance(tx, this.liquidStakingObject.weightHookId);
|
|
112
|
+
return lst;
|
|
113
|
+
};
|
|
114
|
+
this.mintAndRebalanceAndSendToUser = (tx, address, amount) => {
|
|
115
|
+
const lst = this.mintAndRebalance(tx, amount);
|
|
116
|
+
tx.transferObjects([lst], address);
|
|
110
117
|
};
|
|
111
118
|
this.liquidStakingObject = liquidStakingObject;
|
|
112
119
|
this.client = client;
|
|
@@ -128,12 +135,12 @@ class LstClient {
|
|
|
128
135
|
}
|
|
129
136
|
// returns the lst object
|
|
130
137
|
mint(tx, suiCoinId) {
|
|
131
|
-
const [
|
|
138
|
+
const [lst] = generated.mint(tx, this.liquidStakingObject.type, {
|
|
132
139
|
self: this.liquidStakingObject.id,
|
|
133
140
|
sui: suiCoinId,
|
|
134
141
|
systemState: SUI_SYSTEM_STATE_ID,
|
|
135
142
|
});
|
|
136
|
-
return
|
|
143
|
+
return lst;
|
|
137
144
|
}
|
|
138
145
|
// returns the sui coin
|
|
139
146
|
redeemLst(tx, lstId) {
|
|
@@ -265,19 +272,25 @@ class LstClient {
|
|
|
265
272
|
liquidStakingInfo: this.liquidStakingObject.id,
|
|
266
273
|
});
|
|
267
274
|
}
|
|
275
|
+
getSpringSuiApy() {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
var _a, _b;
|
|
278
|
+
const validatorApys = (yield this.client.getValidatorsApy()).apys;
|
|
279
|
+
const liquidStakingInfo = yield (0, exports.fetchLiquidStakingInfo)(this.liquidStakingObject, this.client);
|
|
280
|
+
const totalSuiSupply = new bignumber_js_1.default(liquidStakingInfo.storage.totalSuiSupply.toString()).div(10 ** utils_1.SUI_DECIMALS);
|
|
281
|
+
const spreadFeePercent = new bignumber_js_1.default((_b = (_a = liquidStakingInfo.feeConfig.element) === null || _a === void 0 ? void 0 : _a.spreadFeeBps.toString()) !== null && _b !== void 0 ? _b : 0).div(100);
|
|
282
|
+
return new bignumber_js_1.default(liquidStakingInfo.storage.validatorInfos
|
|
283
|
+
.reduce((acc, validatorInfo) => {
|
|
284
|
+
var _a, _b;
|
|
285
|
+
const validatorApy = new bignumber_js_1.default((_b = (_a = validatorApys.find((_apy) => _apy.address === validatorInfo.validatorAddress)) === null || _a === void 0 ? void 0 : _a.apy) !== null && _b !== void 0 ? _b : 0);
|
|
286
|
+
const validatorTotalSuiAmount = new bignumber_js_1.default(validatorInfo.totalSuiAmount.toString()).div(10 ** utils_1.SUI_DECIMALS);
|
|
287
|
+
return acc.plus(validatorApy.times(validatorTotalSuiAmount));
|
|
288
|
+
}, new bignumber_js_1.default(0))
|
|
289
|
+
.div(totalSuiSupply)).times(new bignumber_js_1.default(1).minus(spreadFeePercent.div(100)));
|
|
290
|
+
});
|
|
291
|
+
}
|
|
268
292
|
}
|
|
269
293
|
exports.LstClient = LstClient;
|
|
270
294
|
// user functions
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
return structs_1.LiquidStakingInfo.fetch(client, (0, reified_1.phantom)(info.type), info.id);
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
// only works for sSui
|
|
277
|
-
function getSpringSuiApy(client) {
|
|
278
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
-
const res = yield client.getValidatorsApy();
|
|
280
|
-
const validatorApy = res.apys.find((apy) => apy.address == SUILEND_VALIDATOR_ADDRESS);
|
|
281
|
-
return validatorApy === null || validatorApy === void 0 ? void 0 : validatorApy.apy;
|
|
282
|
-
});
|
|
283
|
-
}
|
|
295
|
+
const fetchLiquidStakingInfo = (info, client) => structs_1.LiquidStakingInfo.fetch(client, (0, reified_1.phantom)(info.type), info.id);
|
|
296
|
+
exports.fetchLiquidStakingInfo = fetchLiquidStakingInfo;
|