@suilend/springsui-cli 1.0.1 → 1.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ # springsui/cli
2
+
3
+ A CLI for interacting with the SpringSui program published on npm as [`@suilend/springsui-cli`](https://www.npmjs.com/package/@suilend/springsui-cli).
4
+
5
+ ---
6
+
7
+ Got a suggestion, running into issues, or have a question? Join our [#dev-support](https://discord.com/channels/1202984617087598622/1238023733403193385) channel on Discord.
package/cli/src/index.js CHANGED
@@ -37,9 +37,9 @@ const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
37
37
  const transactions_1 = require("@mysten/sui/transactions");
38
38
  const utils_1 = require("@mysten/sui/utils");
39
39
  const commander_1 = require("commander");
40
- const sdk = __importStar(require("../../sdk/src"));
41
- const src_1 = require("../../sdk/src");
42
- const liquid_staking_1 = require("../../sdk/src/_generated/liquid_staking");
40
+ const springsui_sdk_1 = require("@suilend/springsui-sdk");
41
+ const sdk = __importStar(require("@suilend/springsui-sdk"));
42
+ const liquid_staking_1 = require("@suilend/springsui-sdk/_generated/liquid_staking");
43
43
  const LIQUID_STAKING_INFO = {
44
44
  id: "0x15eda7330c8f99c30e430b4d82fd7ab2af3ead4ae17046fcb224aa9bad394f6b",
45
45
  type: "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI",
@@ -53,7 +53,7 @@ const keypair = ed25519_1.Ed25519Keypair.fromSecretKey((0, utils_1.fromBase64)(p
53
53
  function mint(options) {
54
54
  return __awaiter(this, void 0, void 0, function* () {
55
55
  const client = new client_1.SuiClient({ url: RPC_URL });
56
- const lstClient = yield src_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
56
+ const lstClient = yield springsui_sdk_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
57
57
  const tx = new transactions_1.Transaction();
58
58
  const [sui] = tx.splitCoins(tx.gas, [BigInt(options.amount)]);
59
59
  const rSui = lstClient.mint(tx, sui);
@@ -79,7 +79,7 @@ function redeem(options) {
79
79
  limit: 1000,
80
80
  });
81
81
  const tx = new transactions_1.Transaction();
82
- const lstClient = yield src_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
82
+ const lstClient = yield springsui_sdk_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
83
83
  if (lstCoins.data.length > 1) {
84
84
  tx.mergeCoins(lstCoins.data[0].coinObjectId, lstCoins.data.slice(1).map((c) => c.coinObjectId));
85
85
  }
@@ -103,7 +103,7 @@ function redeem(options) {
103
103
  function increaseValidatorStake(options) {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  const client = new client_1.SuiClient({ url: RPC_URL });
106
- const lstClient = yield src_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
106
+ const lstClient = yield springsui_sdk_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
107
107
  const adminCapId = yield lstClient.getAdminCapId(keypair.toSuiAddress());
108
108
  if (!adminCapId)
109
109
  return;
@@ -124,7 +124,7 @@ function increaseValidatorStake(options) {
124
124
  function decreaseValidatorStake(options) {
125
125
  return __awaiter(this, void 0, void 0, function* () {
126
126
  const client = new client_1.SuiClient({ url: RPC_URL });
127
- const lstClient = yield src_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
127
+ const lstClient = yield springsui_sdk_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
128
128
  const adminCapId = yield lstClient.getAdminCapId(keypair.toSuiAddress());
129
129
  if (!adminCapId)
130
130
  return;
@@ -146,7 +146,7 @@ function updateFees(options) {
146
146
  return __awaiter(this, void 0, void 0, function* () {
147
147
  var _a;
148
148
  const client = new client_1.SuiClient({ url: RPC_URL });
149
- const lstClient = yield src_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
149
+ const lstClient = yield springsui_sdk_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
150
150
  const adminCap = (yield client.getOwnedObjects({
151
151
  owner: keypair.toSuiAddress(),
152
152
  filter: {
@@ -173,7 +173,7 @@ function updateFees(options) {
173
173
  function initializeWeightHook(options) {
174
174
  return __awaiter(this, void 0, void 0, function* () {
175
175
  const client = new client_1.SuiClient({ url: RPC_URL });
176
- const lstClient = yield src_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
176
+ const lstClient = yield springsui_sdk_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
177
177
  const adminCapId = yield lstClient.getAdminCapId(keypair.toSuiAddress());
178
178
  if (!adminCapId)
179
179
  return;
@@ -195,7 +195,7 @@ function initializeWeightHook(options) {
195
195
  function setValidatorAddressesAndWeights(options) {
196
196
  return __awaiter(this, void 0, void 0, function* () {
197
197
  const client = new client_1.SuiClient({ url: RPC_URL });
198
- const lstClient = yield src_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
198
+ const lstClient = yield springsui_sdk_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
199
199
  if (options.validators.length != options.weights.length) {
200
200
  throw new Error("Validators and weights arrays must be of the same length");
201
201
  }
@@ -204,7 +204,7 @@ function setValidatorAddressesAndWeights(options) {
204
204
  validatorAddressesAndWeights[options.validators[i]] = options.weights[i];
205
205
  }
206
206
  console.log(validatorAddressesAndWeights);
207
- const weightHookAdminCapId = yield lstClient.getWeightHookAdminCapId(keypair.toSuiAddress());
207
+ const weightHookAdminCapId = yield springsui_sdk_1.LstClient.getWeightHookAdminCapId(client, keypair.toSuiAddress(), LIQUID_STAKING_INFO.type);
208
208
  if (!weightHookAdminCapId)
209
209
  return;
210
210
  const tx = new transactions_1.Transaction();
@@ -224,7 +224,7 @@ function setValidatorAddressesAndWeights(options) {
224
224
  function rebalance(options) {
225
225
  return __awaiter(this, void 0, void 0, function* () {
226
226
  const client = new client_1.SuiClient({ url: RPC_URL });
227
- const lstClient = yield src_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
227
+ const lstClient = yield springsui_sdk_1.LstClient.initialize(client, LIQUID_STAKING_INFO);
228
228
  const tx = new transactions_1.Transaction();
229
229
  lstClient.rebalance(tx, LIQUID_STAKING_INFO.weightHookId);
230
230
  const txResponse = yield client.signAndExecuteTransaction({
@@ -257,7 +257,7 @@ function createNewLst(options) {
257
257
  const coinType = type.substring(type.indexOf("<") + 1, type.lastIndexOf(">"));
258
258
  console.log(coinType);
259
259
  const tx = new transactions_1.Transaction();
260
- const weightHookAdminCap = src_1.LstClient.createNewLst(tx, options.treasuryCap, coinType);
260
+ const weightHookAdminCap = springsui_sdk_1.LstClient.createNewLst(tx, options.treasuryCap, coinType);
261
261
  tx.transferObjects([tx.object(weightHookAdminCap)], keypair.toSuiAddress());
262
262
  const txResponse = yield client.signAndExecuteTransaction({
263
263
  transaction: tx,
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/springsui-cli","version":"1.0.1","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","release":"bun run build && bun ts-node ./prepublish.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.1","commander":"^12.1.0","uuid":"^9.0.1"},"devDependencies":{"@types/node":"^20.12.7","ts-node":"^10.9.2","typescript":"^5.3.3"}}
1
+ {"name":"@suilend/springsui-cli","version":"1.0.3","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"}}
@@ -1,33 +1,42 @@
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;
12
14
  static initialize(client: SuiClient, liquidStakingObjectInfo: LiquidStakingObjectInfo): Promise<LstClient>;
13
15
  static createNewLst(tx: Transaction, treasuryCap: string, coinType: string): TransactionObjectInput;
16
+ static getWeightHookAdminCapId(client: SuiClient, address: string, weightHookAdminCapId: string): Promise<string | null | undefined>;
14
17
  constructor(liquidStakingObject: LiquidStakingObjectInfo, client: SuiClient);
15
18
  getAdminCapId(address: string): Promise<string | null | undefined>;
16
- getWeightHookAdminCapId(address: string): Promise<string | null | undefined>;
17
19
  mint(tx: Transaction, suiCoinId: TransactionObjectInput): {
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
+ };
27
+ mintAndRebalanceAndSendToUser: (tx: Transaction, address: string, amount: string) => void;
21
28
  redeemLst(tx: Transaction, lstId: TransactionObjectInput): {
22
29
  $kind: "NestedResult";
23
30
  NestedResult: [number, number];
24
31
  };
32
+ redeemAndSendToUser(tx: Transaction, address: string, amount: string): Promise<void>;
25
33
  increaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, suiAmount: number): void;
26
34
  decreaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, targetUnstakeSuiAmount: bigint): void;
27
35
  collectFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput): {
28
36
  $kind: "NestedResult";
29
37
  NestedResult: [number, number];
30
38
  };
39
+ collectFeesAndSendToUser(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, address: string): void;
31
40
  updateFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, feeConfigArgs: FeeConfigArgs): void;
32
41
  initializeWeightHook(tx: Transaction, adminCapId: TransactionObjectInput): {
33
42
  $kind: "NestedResult";
@@ -35,11 +44,11 @@ export declare class LstClient {
35
44
  };
36
45
  setValidatorAddressesAndWeights(tx: Transaction, weightHookId: TransactionObjectInput, weightHookAdminCap: TransactionObjectInput, validatorAddressesAndWeights: Record<string, number>): void;
37
46
  rebalance(tx: Transaction, weightHookId: TransactionObjectInput): void;
47
+ getSpringSuiApy(): Promise<BigNumber>;
38
48
  }
39
- export declare function fetchLiquidStakingInfo(info: LiquidStakingObjectInfo, client: SuiClient): Promise<LiquidStakingInfo<any>>;
49
+ export declare const fetchLiquidStakingInfo: (info: LiquidStakingObjectInfo, client: SuiClient) => Promise<LiquidStakingInfo<any>>;
40
50
  export interface FeeConfigArgs {
41
51
  mintFeeBps?: number;
42
52
  redeemFeeBps?: number;
43
53
  spreadFeeBps?: number;
44
54
  }
45
- 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
- exports.fetchLiquidStakingInfo = fetchLiquidStakingInfo;
37
- exports.getSpringSuiApy = getSpringSuiApy;
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
- const SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
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* () {
@@ -86,17 +89,13 @@ class LstClient {
86
89
  });
87
90
  return weightHookAdminCap;
88
91
  }
89
- constructor(liquidStakingObject, client) {
90
- this.liquidStakingObject = liquidStakingObject;
91
- this.client = client;
92
- }
93
- getAdminCapId(address) {
92
+ static getWeightHookAdminCapId(client, address, weightHookAdminCapId) {
94
93
  return __awaiter(this, void 0, void 0, function* () {
95
94
  var _a;
96
- const res = (yield this.client.getOwnedObjects({
95
+ const res = (yield client.getOwnedObjects({
97
96
  owner: address,
98
97
  filter: {
99
- StructType: `${liquid_staking_1.PACKAGE_ID}::liquid_staking::AdminCap<${this.liquidStakingObject.type}>`,
98
+ StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${weightHookAdminCapId}>`,
100
99
  },
101
100
  })).data;
102
101
  if (res.length == 0) {
@@ -105,13 +104,27 @@ class LstClient {
105
104
  return (_a = res[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
106
105
  });
107
106
  }
108
- getWeightHookAdminCapId(address) {
107
+ constructor(liquidStakingObject, client) {
108
+ this.mintAndRebalance = (tx, amount) => {
109
+ const [sui] = tx.splitCoins(tx.gas, [BigInt(amount)]);
110
+ const lst = this.mint(tx, sui);
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);
117
+ };
118
+ this.liquidStakingObject = liquidStakingObject;
119
+ this.client = client;
120
+ }
121
+ getAdminCapId(address) {
109
122
  return __awaiter(this, void 0, void 0, function* () {
110
123
  var _a;
111
124
  const res = (yield this.client.getOwnedObjects({
112
125
  owner: address,
113
126
  filter: {
114
- StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${this.liquidStakingObject.type}>`,
127
+ StructType: `${liquid_staking_1.PACKAGE_ID}::liquid_staking::AdminCap<${this.liquidStakingObject.type}>`,
115
128
  },
116
129
  })).data;
117
130
  if (res.length == 0) {
@@ -122,12 +135,12 @@ class LstClient {
122
135
  }
123
136
  // returns the lst object
124
137
  mint(tx, suiCoinId) {
125
- const [rSui] = generated.mint(tx, this.liquidStakingObject.type, {
138
+ const [lst] = generated.mint(tx, this.liquidStakingObject.type, {
126
139
  self: this.liquidStakingObject.id,
127
140
  sui: suiCoinId,
128
141
  systemState: SUI_SYSTEM_STATE_ID,
129
142
  });
130
- return rSui;
143
+ return lst;
131
144
  }
132
145
  // returns the sui coin
133
146
  redeemLst(tx, lstId) {
@@ -138,6 +151,22 @@ class LstClient {
138
151
  });
139
152
  return sui;
140
153
  }
154
+ redeemAndSendToUser(tx, address, amount) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ const coins = (yield this.client.getCoins({
157
+ owner: address,
158
+ coinType: this.liquidStakingObject.type,
159
+ })).data;
160
+ if (coins.length > 1) {
161
+ tx.mergeCoins(tx.object(coins[0].coinObjectId), coins.map((c) => tx.object(c.coinObjectId)).slice(1));
162
+ }
163
+ const [lst] = tx.splitCoins(tx.object(coins[0].coinObjectId), [
164
+ BigInt(amount),
165
+ ]);
166
+ const sui = this.redeemLst(tx, lst);
167
+ tx.transferObjects([sui], address);
168
+ });
169
+ }
141
170
  // admin functions
142
171
  increaseValidatorStake(tx, adminCapId, validatorAddress, suiAmount) {
143
172
  generated.increaseValidatorStake(tx, this.liquidStakingObject.type, {
@@ -166,6 +195,10 @@ class LstClient {
166
195
  });
167
196
  return sui;
168
197
  }
198
+ collectFeesAndSendToUser(tx, weightHookAdminCapId, address) {
199
+ const sui = this.collectFees(tx, weightHookAdminCapId);
200
+ tx.transferObjects([sui], address);
201
+ }
169
202
  updateFees(tx, weightHookAdminCapId, feeConfigArgs) {
170
203
  let [builder] = (0, functions_1.newBuilder)(tx);
171
204
  if (feeConfigArgs.mintFeeBps != null) {
@@ -239,19 +272,23 @@ class LstClient {
239
272
  liquidStakingInfo: this.liquidStakingObject.id,
240
273
  });
241
274
  }
275
+ getSpringSuiApy() {
276
+ return __awaiter(this, void 0, void 0, function* () {
277
+ const validatorApys = (yield this.client.getValidatorsApy()).apys;
278
+ const liquidStakingInfo = yield (0, exports.fetchLiquidStakingInfo)(this.liquidStakingObject, this.client);
279
+ const totalSuiSupply = new bignumber_js_1.default(liquidStakingInfo.storage.totalSuiSupply.toString()).div(10 ** utils_1.SUI_DECIMALS);
280
+ return liquidStakingInfo.storage.validatorInfos
281
+ .reduce((acc, validatorInfo) => {
282
+ var _a, _b;
283
+ 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);
284
+ const validatorTotalSuiAmount = new bignumber_js_1.default(validatorInfo.totalSuiAmount.toString()).div(10 ** utils_1.SUI_DECIMALS);
285
+ return acc.plus(validatorApy.times(validatorTotalSuiAmount));
286
+ }, new bignumber_js_1.default(0))
287
+ .div(totalSuiSupply);
288
+ });
289
+ }
242
290
  }
243
291
  exports.LstClient = LstClient;
244
292
  // user functions
245
- function fetchLiquidStakingInfo(info, client) {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- return structs_1.LiquidStakingInfo.fetch(client, (0, reified_1.phantom)(info.type), info.id);
248
- });
249
- }
250
- // only works for sSui
251
- function getSpringSuiApy(client) {
252
- return __awaiter(this, void 0, void 0, function* () {
253
- const res = yield client.getValidatorsApy();
254
- const validatorApy = res.apys.find((apy) => apy.address == SUILEND_VALIDATOR_ADDRESS);
255
- return validatorApy === null || validatorApy === void 0 ? void 0 : validatorApy.apy;
256
- });
257
- }
293
+ const fetchLiquidStakingInfo = (info, client) => structs_1.LiquidStakingInfo.fetch(client, (0, reified_1.phantom)(info.type), info.id);
294
+ exports.fetchLiquidStakingInfo = fetchLiquidStakingInfo;