@suilend/springsui-cli 1.0.1 → 1.0.2

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.2","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.2","commander":"^12.1.0","uuid":"^9.0.1"},"devDependencies":{"ts-node":"^10.9.2"}}
@@ -11,23 +11,26 @@ export declare class LstClient {
11
11
  client: SuiClient;
12
12
  static initialize(client: SuiClient, liquidStakingObjectInfo: LiquidStakingObjectInfo): Promise<LstClient>;
13
13
  static createNewLst(tx: Transaction, treasuryCap: string, coinType: string): TransactionObjectInput;
14
+ static getWeightHookAdminCapId(client: SuiClient, address: string, weightHookAdminCapId: string): Promise<string | null | undefined>;
14
15
  constructor(liquidStakingObject: LiquidStakingObjectInfo, client: SuiClient);
15
16
  getAdminCapId(address: string): Promise<string | null | undefined>;
16
- getWeightHookAdminCapId(address: string): Promise<string | null | undefined>;
17
17
  mint(tx: Transaction, suiCoinId: TransactionObjectInput): {
18
18
  $kind: "NestedResult";
19
19
  NestedResult: [number, number];
20
20
  };
21
+ mintAndRebalanceAndSendToUser: (tx: Transaction, address: string, amount: string) => void;
21
22
  redeemLst(tx: Transaction, lstId: TransactionObjectInput): {
22
23
  $kind: "NestedResult";
23
24
  NestedResult: [number, number];
24
25
  };
26
+ redeemAndSendToUser(tx: Transaction, address: string, amount: string): Promise<void>;
25
27
  increaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, suiAmount: number): void;
26
28
  decreaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, targetUnstakeSuiAmount: bigint): void;
27
29
  collectFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput): {
28
30
  $kind: "NestedResult";
29
31
  NestedResult: [number, number];
30
32
  };
33
+ collectFeesAndSendToUser(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, address: string): void;
31
34
  updateFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, feeConfigArgs: FeeConfigArgs): void;
32
35
  initializeWeightHook(tx: Transaction, adminCapId: TransactionObjectInput): {
33
36
  $kind: "NestedResult";
package/sdk/src/index.js CHANGED
@@ -86,17 +86,13 @@ class LstClient {
86
86
  });
87
87
  return weightHookAdminCap;
88
88
  }
89
- constructor(liquidStakingObject, client) {
90
- this.liquidStakingObject = liquidStakingObject;
91
- this.client = client;
92
- }
93
- getAdminCapId(address) {
89
+ static getWeightHookAdminCapId(client, address, weightHookAdminCapId) {
94
90
  return __awaiter(this, void 0, void 0, function* () {
95
91
  var _a;
96
- const res = (yield this.client.getOwnedObjects({
92
+ const res = (yield client.getOwnedObjects({
97
93
  owner: address,
98
94
  filter: {
99
- StructType: `${liquid_staking_1.PACKAGE_ID}::liquid_staking::AdminCap<${this.liquidStakingObject.type}>`,
95
+ StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${weightHookAdminCapId}>`,
100
96
  },
101
97
  })).data;
102
98
  if (res.length == 0) {
@@ -105,13 +101,23 @@ class LstClient {
105
101
  return (_a = res[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
106
102
  });
107
103
  }
108
- getWeightHookAdminCapId(address) {
104
+ constructor(liquidStakingObject, client) {
105
+ this.mintAndRebalanceAndSendToUser = (tx, address, amount) => {
106
+ const [sui] = tx.splitCoins(tx.gas, [BigInt(amount)]);
107
+ const rSui = this.mint(tx, sui);
108
+ tx.transferObjects([rSui], address);
109
+ this.rebalance(tx, this.liquidStakingObject.weightHookId);
110
+ };
111
+ this.liquidStakingObject = liquidStakingObject;
112
+ this.client = client;
113
+ }
114
+ getAdminCapId(address) {
109
115
  return __awaiter(this, void 0, void 0, function* () {
110
116
  var _a;
111
117
  const res = (yield this.client.getOwnedObjects({
112
118
  owner: address,
113
119
  filter: {
114
- StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${this.liquidStakingObject.type}>`,
120
+ StructType: `${liquid_staking_1.PACKAGE_ID}::liquid_staking::AdminCap<${this.liquidStakingObject.type}>`,
115
121
  },
116
122
  })).data;
117
123
  if (res.length == 0) {
@@ -138,6 +144,22 @@ class LstClient {
138
144
  });
139
145
  return sui;
140
146
  }
147
+ redeemAndSendToUser(tx, address, amount) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ const coins = (yield this.client.getCoins({
150
+ owner: address,
151
+ coinType: this.liquidStakingObject.type,
152
+ })).data;
153
+ if (coins.length > 1) {
154
+ tx.mergeCoins(tx.object(coins[0].coinObjectId), coins.map((c) => tx.object(c.coinObjectId)).slice(1));
155
+ }
156
+ const [lst] = tx.splitCoins(tx.object(coins[0].coinObjectId), [
157
+ BigInt(amount),
158
+ ]);
159
+ const sui = this.redeemLst(tx, lst);
160
+ tx.transferObjects([sui], address);
161
+ });
162
+ }
141
163
  // admin functions
142
164
  increaseValidatorStake(tx, adminCapId, validatorAddress, suiAmount) {
143
165
  generated.increaseValidatorStake(tx, this.liquidStakingObject.type, {
@@ -166,6 +188,10 @@ class LstClient {
166
188
  });
167
189
  return sui;
168
190
  }
191
+ collectFeesAndSendToUser(tx, weightHookAdminCapId, address) {
192
+ const sui = this.collectFees(tx, weightHookAdminCapId);
193
+ tx.transferObjects([sui], address);
194
+ }
169
195
  updateFees(tx, weightHookAdminCapId, feeConfigArgs) {
170
196
  let [builder] = (0, functions_1.newBuilder)(tx);
171
197
  if (feeConfigArgs.mintFeeBps != null) {