@suilend/springsui-cli 1.0.11 → 1.0.13

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.
Files changed (27) hide show
  1. package/cli/src/bytecode.js +4 -8
  2. package/package.json +1 -1
  3. package/sdk/src/_generated/_dependencies/source/0x1/ascii/structs.d.ts +7 -11
  4. package/sdk/src/_generated/_dependencies/source/0x1/option/structs.d.ts +4 -6
  5. package/sdk/src/_generated/_dependencies/source/0x1/string/structs.d.ts +4 -6
  6. package/sdk/src/_generated/_dependencies/source/0x1/type-name/structs.d.ts +6 -10
  7. package/sdk/src/_generated/_dependencies/source/0x2/bag/structs.d.ts +8 -15
  8. package/sdk/src/_generated/_dependencies/source/0x2/balance/structs.d.ts +6 -10
  9. package/sdk/src/_generated/_dependencies/source/0x2/coin/structs.d.ts +85 -139
  10. package/sdk/src/_generated/_dependencies/source/0x2/object/structs.d.ts +8 -14
  11. package/sdk/src/_generated/_dependencies/source/0x2/sui/structs.d.ts +3 -5
  12. package/sdk/src/_generated/_dependencies/source/0x2/table/structs.d.ts +8 -15
  13. package/sdk/src/_generated/_dependencies/source/0x2/url/structs.d.ts +6 -10
  14. package/sdk/src/_generated/_dependencies/source/0x2/vec-map/structs.d.ts +13 -18
  15. package/sdk/src/_generated/_dependencies/source/0x3/staking-pool/structs.d.ts +82 -156
  16. package/sdk/src/_generated/_framework/util.d.ts +2 -2
  17. package/sdk/src/_generated/_framework/vector.d.ts +12 -5
  18. package/sdk/src/_generated/liquid_staking/cell/structs.d.ts +6 -10
  19. package/sdk/src/_generated/liquid_staking/fees/structs.d.ts +26 -50
  20. package/sdk/src/_generated/liquid_staking/liquid-staking/structs.d.ts +225 -273
  21. package/sdk/src/_generated/liquid_staking/storage/structs.d.ts +136 -83
  22. package/sdk/src/_generated/liquid_staking/version/structs.d.ts +3 -5
  23. package/sdk/src/_generated/liquid_staking/weight/structs.d.ts +60 -112
  24. package/sdk/src/client.d.ts +10 -7
  25. package/sdk/src/client.js +50 -26
  26. package/sdk/src/lib/transactions.d.ts +3 -3
  27. package/sdk/src/lib/transactions.js +18 -9
package/sdk/src/client.js CHANGED
@@ -45,8 +45,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
45
45
  return (mod && mod.__esModule) ? mod : { "default": mod };
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.fetchRegistryLiquidStakingInfoMap = exports.fetchLiquidStakingInfo = exports.LstClient = exports.SUILEND_VALIDATOR_ADDRESS = void 0;
49
- const transactions_1 = require("@mysten/sui/transactions");
48
+ exports.fetchRegistryLiquidStakingInfoMap = exports.fetchLiquidStakingInfo = exports.LstClient = exports.ADMIN_ADDRESS = exports.SPRING_SUI_UPGRADE_CAP_ID = exports.SUILEND_VALIDATOR_ADDRESS = void 0;
49
+ exports.getLatestPackageId = getLatestPackageId;
50
50
  const utils_1 = require("@mysten/sui/utils");
51
51
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
52
52
  const reified_1 = require("./_generated/_framework/reified");
@@ -58,7 +58,8 @@ const weightHookGenerated = __importStar(require("./_generated/liquid_staking/we
58
58
  const structs_2 = require("./_generated/liquid_staking/weight/structs");
59
59
  const SUI_SYSTEM_STATE_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
60
60
  exports.SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
61
- const SPRING_SUI_UPGRADE_CAP_ID = "0x4dc657b6c0fe896f4b94fee1ceac96312dde0a36b94e799caaec30deb53dcd67";
61
+ exports.SPRING_SUI_UPGRADE_CAP_ID = "0x4dc657b6c0fe896f4b94fee1ceac96312dde0a36b94e799caaec30deb53dcd67";
62
+ exports.ADMIN_ADDRESS = "0xb1ffbc2e1915f44b8f271a703becc1bf8aa79bc22431a58900a102892b783c25";
62
63
  function getLatestPackageId(client, upgradeCapId) {
63
64
  return __awaiter(this, void 0, void 0, function* () {
64
65
  var _a;
@@ -72,11 +73,12 @@ function getLatestPackageId(client, upgradeCapId) {
72
73
  });
73
74
  }
74
75
  class LstClient {
75
- static initialize(client, liquidStakingObjectInfo) {
76
+ static initialize(client, liquidStakingObjectInfo, _publishedAt, logPackageId) {
76
77
  return __awaiter(this, void 0, void 0, function* () {
77
- const publishedAt = yield getLatestPackageId(client, SPRING_SUI_UPGRADE_CAP_ID);
78
+ const publishedAt = _publishedAt !== null && _publishedAt !== void 0 ? _publishedAt : (yield getLatestPackageId(client, exports.SPRING_SUI_UPGRADE_CAP_ID));
79
+ if (logPackageId)
80
+ console.log("@suilend/springsui-sdk | publishedAt:", publishedAt);
78
81
  (0, liquid_staking_1.setPublishedAt)(publishedAt);
79
- console.log(`Initialized LstClient with package ID: ${publishedAt}`);
80
82
  return new LstClient(liquidStakingObjectInfo, client);
81
83
  });
82
84
  }
@@ -105,13 +107,13 @@ class LstClient {
105
107
  });
106
108
  return weightHookAdminCap;
107
109
  }
108
- static getWeightHookAdminCapId(client, address, weightHookAdminCapId) {
110
+ static getWeightHookAdminCapId(client, address, coinType) {
109
111
  return __awaiter(this, void 0, void 0, function* () {
110
112
  var _a;
111
113
  const res = (yield client.getOwnedObjects({
112
114
  owner: address,
113
115
  filter: {
114
- StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${weightHookAdminCapId}>`,
116
+ StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${coinType}>`,
115
117
  },
116
118
  })).data;
117
119
  if (res.length == 0) {
@@ -149,8 +151,8 @@ class LstClient {
149
151
  return lst;
150
152
  }
151
153
  mintAmountAndRebalance(tx, address, amount) {
152
- const [sui] = tx.splitCoins(tx.gas, [BigInt(amount)]);
153
- const lst = this.mint(tx, sui);
154
+ const [suiCoin] = tx.splitCoins(tx.gas, [BigInt(amount)]);
155
+ const lst = this.mint(tx, suiCoin);
154
156
  this.rebalance(tx, this.liquidStakingObject.weightHookId);
155
157
  return lst;
156
158
  }
@@ -160,25 +162,36 @@ class LstClient {
160
162
  }
161
163
  // returns the sui coin
162
164
  redeem(tx, lstId) {
163
- const [sui] = generated.redeem(tx, this.liquidStakingObject.type, {
165
+ const [suiCoin] = generated.redeem(tx, this.liquidStakingObject.type, {
164
166
  self: this.liquidStakingObject.id,
165
167
  systemState: SUI_SYSTEM_STATE_ID,
166
168
  lst: lstId,
167
169
  });
168
- return sui;
170
+ return suiCoin;
169
171
  }
170
- redeemAmount(tx, address, amount) {
171
- const lstCoin = (0, transactions_1.coinWithBalance)({
172
- balance: BigInt(amount),
173
- type: this.liquidStakingObject.type,
174
- useGasCoin: false,
175
- })(tx);
176
- const sui = this.redeem(tx, lstCoin);
177
- return sui;
172
+ redeemAmountAndRebalance(tx, address, amount, client) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const coins = (yield client.getCoins({
175
+ owner: address,
176
+ coinType: this.liquidStakingObject.type,
177
+ })).data;
178
+ const mergeCoin = coins[0];
179
+ if (coins.length > 1) {
180
+ tx.mergeCoins(tx.object(mergeCoin.coinObjectId), coins.map((c) => tx.object(c.coinObjectId)).slice(1));
181
+ }
182
+ const [lstCoin] = tx.splitCoins(tx.object(mergeCoin.coinObjectId), [
183
+ BigInt(amount),
184
+ ]);
185
+ const suiCoin = this.redeem(tx, lstCoin);
186
+ this.rebalance(tx, this.liquidStakingObject.weightHookId);
187
+ return suiCoin;
188
+ });
178
189
  }
179
- redeemAmountAndSendToUser(tx, address, amount) {
180
- const suiCoin = this.redeemAmount(tx, address, amount);
181
- tx.transferObjects([suiCoin], address);
190
+ redeemAmountAndRebalanceAndSendToUser(tx, address, amount, client) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ const suiCoin = yield this.redeemAmountAndRebalance(tx, address, amount, client);
193
+ tx.transferObjects([suiCoin], address);
194
+ });
182
195
  }
183
196
  // admin functions
184
197
  increaseValidatorStake(tx, adminCapId, validatorAddress, suiAmount) {
@@ -285,10 +298,10 @@ class LstClient {
285
298
  liquidStakingInfo: this.liquidStakingObject.id,
286
299
  });
287
300
  }
288
- getSpringSuiApy() {
301
+ getSpringSuiApy(_validatorApys) {
289
302
  return __awaiter(this, void 0, void 0, function* () {
290
303
  var _a, _b;
291
- const validatorApys = (yield this.client.getValidatorsApy()).apys;
304
+ const validatorApys = _validatorApys !== null && _validatorApys !== void 0 ? _validatorApys : (yield this.client.getValidatorsApy()).apys;
292
305
  const liquidStakingInfo = yield (0, exports.fetchLiquidStakingInfo)(this.liquidStakingObject, this.client);
293
306
  const totalSuiSupply = new bignumber_js_1.default(liquidStakingInfo.storage.totalSuiSupply.toString()).div(10 ** utils_1.SUI_DECIMALS);
294
307
  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);
@@ -311,7 +324,18 @@ const fetchLiquidStakingInfo = (info, client) => structs_1.LiquidStakingInfo.fet
311
324
  exports.fetchLiquidStakingInfo = fetchLiquidStakingInfo;
312
325
  const fetchRegistryLiquidStakingInfoMap = (client) => __awaiter(void 0, void 0, void 0, function* () {
313
326
  const REGISTRY_ID = "0x06d6b6881ef14ad1a8cc29d1f97ba3397ecea56af5afa0642093e981b1fda3f4";
314
- const registryObjectIds = (yield client.getDynamicFields({ parentId: REGISTRY_ID })).data.map((d) => d.objectId);
327
+ const registryObjectIds = [];
328
+ let cursor = null;
329
+ let hasNextPage = true;
330
+ while (hasNextPage) {
331
+ const page = yield client.getDynamicFields({
332
+ parentId: REGISTRY_ID,
333
+ cursor,
334
+ });
335
+ registryObjectIds.push(...page.data.map((d) => d.objectId));
336
+ cursor = page.nextCursor;
337
+ hasNextPage = page.hasNextPage;
338
+ }
315
339
  const registryObjects = yield Promise.all(registryObjectIds.map((objectId) => client.getObject({
316
340
  id: objectId,
317
341
  options: {
@@ -1,7 +1,7 @@
1
1
  import { Transaction } from "@mysten/sui/transactions";
2
2
  import { LstClient } from "../client";
3
- export declare const convertLsts: (inLstClient: LstClient, outLstClient: LstClient, transaction: Transaction, address: string, amount: string) => {
3
+ export declare const convertLstsAndRebalance: (inLstClient: LstClient, outLstClient: LstClient, transaction: Transaction, address: string, amount: string) => Promise<{
4
4
  $kind: "NestedResult";
5
5
  NestedResult: [number, number];
6
- };
7
- export declare const convertLstsAndSendToUser: (inLstClient: LstClient, outLstClient: LstClient, transaction: Transaction, address: string, amount: string) => void;
6
+ }>;
7
+ export declare const convertLstsAndRebalanceAndSendToUser: (inLstClient: LstClient, outLstClient: LstClient, transaction: Transaction, address: string, amount: string) => Promise<void>;
@@ -1,15 +1,24 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertLstsAndSendToUser = exports.convertLsts = void 0;
4
- const convertLsts = (inLstClient, outLstClient, transaction, address, amount) => {
5
- const suiCoin = inLstClient.redeemAmount(transaction, address, amount);
12
+ exports.convertLstsAndRebalanceAndSendToUser = exports.convertLstsAndRebalance = void 0;
13
+ const convertLstsAndRebalance = (inLstClient, outLstClient, transaction, address, amount) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const suiCoin = yield inLstClient.redeemAmountAndRebalance(transaction, address, amount, inLstClient.client);
6
15
  const lstCoin = outLstClient.mint(transaction, suiCoin);
7
16
  outLstClient.rebalance(transaction, outLstClient.liquidStakingObject.weightHookId);
8
17
  return lstCoin;
9
- };
10
- exports.convertLsts = convertLsts;
11
- const convertLstsAndSendToUser = (inLstClient, outLstClient, transaction, address, amount) => {
12
- const lstCoin = (0, exports.convertLsts)(inLstClient, outLstClient, transaction, address, amount);
18
+ });
19
+ exports.convertLstsAndRebalance = convertLstsAndRebalance;
20
+ const convertLstsAndRebalanceAndSendToUser = (inLstClient, outLstClient, transaction, address, amount) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const lstCoin = yield (0, exports.convertLstsAndRebalance)(inLstClient, outLstClient, transaction, address, amount);
13
22
  transaction.transferObjects([lstCoin], address);
14
- };
15
- exports.convertLstsAndSendToUser = convertLstsAndSendToUser;
23
+ });
24
+ exports.convertLstsAndRebalanceAndSendToUser = convertLstsAndRebalanceAndSendToUser;