@suilend/springsui-cli 1.0.0 → 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 +7 -0
- package/cli/src/index.js +57 -17
- package/package.json +1 -1
- package/sdk/src/_generated/_dependencies/source/0x1/ascii/structs.d.ts +3 -3
- package/sdk/src/_generated/_dependencies/source/0x1/ascii/structs.js +4 -4
- package/sdk/src/_generated/_dependencies/source/0x1/index.d.ts +1 -1
- package/sdk/src/_generated/_dependencies/source/0x1/index.js +2 -2
- package/sdk/src/_generated/_dependencies/source/0x1/option/structs.d.ts +2 -2
- package/sdk/src/_generated/_dependencies/source/0x1/option/structs.js +2 -2
- package/sdk/src/_generated/_dependencies/source/0x1/string/structs.d.ts +2 -2
- package/sdk/src/_generated/_dependencies/source/0x1/string/structs.js +2 -2
- package/sdk/src/_generated/_dependencies/source/0x1/type-name/structs.d.ts +2 -2
- package/sdk/src/_generated/_dependencies/source/0x1/type-name/structs.js +2 -2
- package/sdk/src/_generated/_dependencies/source/0x3/index.d.ts +1 -1
- package/sdk/src/_generated/_dependencies/source/0x3/index.js +2 -2
- package/sdk/src/_generated/_dependencies/source/0x3/staking-pool/structs.d.ts +7 -7
- package/sdk/src/_generated/_dependencies/source/0x3/staking-pool/structs.js +12 -12
- package/sdk/src/_generated/liquid_staking/cell/structs.d.ts +2 -2
- package/sdk/src/_generated/liquid_staking/fees/structs.d.ts +6 -6
- package/sdk/src/_generated/liquid_staking/index.d.ts +2 -2
- package/sdk/src/_generated/liquid_staking/index.js +3 -3
- package/sdk/src/_generated/liquid_staking/liquid-staking/functions.d.ts +1 -1
- package/sdk/src/_generated/liquid_staking/liquid-staking/functions.js +1 -1
- package/sdk/src/_generated/liquid_staking/liquid-staking/structs.d.ts +28 -28
- package/sdk/src/_generated/liquid_staking/storage/structs.d.ts +6 -6
- package/sdk/src/_generated/liquid_staking/version/structs.d.ts +3 -3
- package/sdk/src/_generated/liquid_staking/weight/functions.d.ts +20 -0
- package/sdk/src/_generated/liquid_staking/weight/functions.js +41 -0
- package/sdk/src/_generated/liquid_staking/weight/structs.d.ts +46 -4
- package/sdk/src/_generated/liquid_staking/weight/structs.js +127 -1
- package/sdk/src/index.d.ts +12 -8
- package/sdk/src/index.js +71 -22
package/sdk/src/index.d.ts
CHANGED
|
@@ -4,41 +4,45 @@ import { LiquidStakingInfo } from "./_generated/liquid_staking/liquid-staking/st
|
|
|
4
4
|
export interface LiquidStakingObjectInfo {
|
|
5
5
|
id: string;
|
|
6
6
|
type: string;
|
|
7
|
+
weightHookId: string;
|
|
7
8
|
}
|
|
8
9
|
export declare class LstClient {
|
|
9
10
|
liquidStakingObject: LiquidStakingObjectInfo;
|
|
10
11
|
client: SuiClient;
|
|
11
12
|
static initialize(client: SuiClient, liquidStakingObjectInfo: LiquidStakingObjectInfo): Promise<LstClient>;
|
|
13
|
+
static createNewLst(tx: Transaction, treasuryCap: string, coinType: string): TransactionObjectInput;
|
|
14
|
+
static getWeightHookAdminCapId(client: SuiClient, address: string, weightHookAdminCapId: string): Promise<string | null | undefined>;
|
|
12
15
|
constructor(liquidStakingObject: LiquidStakingObjectInfo, client: SuiClient);
|
|
13
16
|
getAdminCapId(address: string): Promise<string | null | undefined>;
|
|
14
|
-
getWeightHookAdminCapId(address: string): Promise<string | null | undefined>;
|
|
15
17
|
mint(tx: Transaction, suiCoinId: TransactionObjectInput): {
|
|
16
18
|
$kind: "NestedResult";
|
|
17
19
|
NestedResult: [number, number];
|
|
18
20
|
};
|
|
21
|
+
mintAndRebalanceAndSendToUser: (tx: Transaction, address: string, amount: string) => void;
|
|
19
22
|
redeemLst(tx: Transaction, lstId: TransactionObjectInput): {
|
|
20
23
|
$kind: "NestedResult";
|
|
21
24
|
NestedResult: [number, number];
|
|
22
25
|
};
|
|
26
|
+
redeemAndSendToUser(tx: Transaction, address: string, amount: string): Promise<void>;
|
|
23
27
|
increaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, suiAmount: number): void;
|
|
24
|
-
decreaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string,
|
|
25
|
-
collectFees(tx: Transaction,
|
|
28
|
+
decreaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, targetUnstakeSuiAmount: bigint): void;
|
|
29
|
+
collectFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput): {
|
|
26
30
|
$kind: "NestedResult";
|
|
27
31
|
NestedResult: [number, number];
|
|
28
32
|
};
|
|
29
|
-
|
|
33
|
+
collectFeesAndSendToUser(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, address: string): void;
|
|
34
|
+
updateFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, feeConfigArgs: FeeConfigArgs): void;
|
|
30
35
|
initializeWeightHook(tx: Transaction, adminCapId: TransactionObjectInput): {
|
|
31
36
|
$kind: "NestedResult";
|
|
32
37
|
NestedResult: [number, number];
|
|
33
38
|
};
|
|
34
|
-
setValidatorAddressesAndWeights(tx: Transaction, weightHookId: TransactionObjectInput, weightHookAdminCap: TransactionObjectInput, validatorAddressesAndWeights:
|
|
39
|
+
setValidatorAddressesAndWeights(tx: Transaction, weightHookId: TransactionObjectInput, weightHookAdminCap: TransactionObjectInput, validatorAddressesAndWeights: Record<string, number>): void;
|
|
35
40
|
rebalance(tx: Transaction, weightHookId: TransactionObjectInput): void;
|
|
36
41
|
}
|
|
37
42
|
export declare function fetchLiquidStakingInfo(info: LiquidStakingObjectInfo, client: SuiClient): Promise<LiquidStakingInfo<any>>;
|
|
38
|
-
interface FeeConfigArgs {
|
|
43
|
+
export interface FeeConfigArgs {
|
|
39
44
|
mintFeeBps?: number;
|
|
40
45
|
redeemFeeBps?: number;
|
|
41
|
-
|
|
46
|
+
spreadFeeBps?: number;
|
|
42
47
|
}
|
|
43
48
|
export declare function getSpringSuiApy(client: SuiClient): Promise<number | undefined>;
|
|
44
|
-
export {};
|
package/sdk/src/index.js
CHANGED
|
@@ -44,7 +44,7 @@ const weightHookGenerated = __importStar(require("./_generated/liquid_staking/we
|
|
|
44
44
|
const structs_2 = require("./_generated/liquid_staking/weight/structs");
|
|
45
45
|
const SUI_SYSTEM_STATE_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
46
46
|
const SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
|
|
47
|
-
const SPRING_SUI_UPGRADE_CAP_ID = "
|
|
47
|
+
const SPRING_SUI_UPGRADE_CAP_ID = "0x4dc657b6c0fe896f4b94fee1ceac96312dde0a36b94e799caaec30deb53dcd67";
|
|
48
48
|
function getLatestPackageId(client, upgradeCapId) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
50
|
var _a;
|
|
@@ -66,17 +66,33 @@ class LstClient {
|
|
|
66
66
|
return new LstClient(liquidStakingObjectInfo, client);
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
static createNewLst(tx, treasuryCap, coinType) {
|
|
70
|
+
const [feeConfigBuilder] = (0, functions_1.newBuilder)(tx);
|
|
71
|
+
const [feeConfig] = (0, functions_1.toFeeConfig)(tx, feeConfigBuilder);
|
|
72
|
+
const [adminCap, liquidStakingInfo] = generated.createLst(tx, coinType, {
|
|
73
|
+
feeConfig,
|
|
74
|
+
lstTreasuryCap: treasuryCap,
|
|
75
|
+
});
|
|
76
|
+
tx.moveCall({
|
|
77
|
+
target: `0x2::transfer::public_share_object`,
|
|
78
|
+
typeArguments: [`${structs_1.LiquidStakingInfo.$typeName}<${coinType}>`],
|
|
79
|
+
arguments: [liquidStakingInfo],
|
|
80
|
+
});
|
|
81
|
+
const [weightHook, weightHookAdminCap] = weightHookGenerated.new_(tx, coinType, adminCap);
|
|
82
|
+
tx.moveCall({
|
|
83
|
+
target: `0x2::transfer::public_share_object`,
|
|
84
|
+
typeArguments: [`${structs_2.WeightHook.$typeName}<${coinType}>`],
|
|
85
|
+
arguments: [weightHook],
|
|
86
|
+
});
|
|
87
|
+
return weightHookAdminCap;
|
|
72
88
|
}
|
|
73
|
-
|
|
89
|
+
static getWeightHookAdminCapId(client, address, weightHookAdminCapId) {
|
|
74
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
91
|
var _a;
|
|
76
|
-
const res = (yield
|
|
92
|
+
const res = (yield client.getOwnedObjects({
|
|
77
93
|
owner: address,
|
|
78
94
|
filter: {
|
|
79
|
-
StructType: `${liquid_staking_1.PACKAGE_ID}::
|
|
95
|
+
StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${weightHookAdminCapId}>`,
|
|
80
96
|
},
|
|
81
97
|
})).data;
|
|
82
98
|
if (res.length == 0) {
|
|
@@ -85,13 +101,23 @@ class LstClient {
|
|
|
85
101
|
return (_a = res[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
|
|
86
102
|
});
|
|
87
103
|
}
|
|
88
|
-
|
|
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) {
|
|
89
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
116
|
var _a;
|
|
91
117
|
const res = (yield this.client.getOwnedObjects({
|
|
92
118
|
owner: address,
|
|
93
119
|
filter: {
|
|
94
|
-
StructType: `${liquid_staking_1.PACKAGE_ID}::
|
|
120
|
+
StructType: `${liquid_staking_1.PACKAGE_ID}::liquid_staking::AdminCap<${this.liquidStakingObject.type}>`,
|
|
95
121
|
},
|
|
96
122
|
})).data;
|
|
97
123
|
if (res.length == 0) {
|
|
@@ -118,6 +144,22 @@ class LstClient {
|
|
|
118
144
|
});
|
|
119
145
|
return sui;
|
|
120
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
|
+
}
|
|
121
163
|
// admin functions
|
|
122
164
|
increaseValidatorStake(tx, adminCapId, validatorAddress, suiAmount) {
|
|
123
165
|
generated.increaseValidatorStake(tx, this.liquidStakingObject.type, {
|
|
@@ -128,24 +170,29 @@ class LstClient {
|
|
|
128
170
|
suiAmount: BigInt(suiAmount),
|
|
129
171
|
});
|
|
130
172
|
}
|
|
131
|
-
decreaseValidatorStake(tx, adminCapId, validatorAddress,
|
|
173
|
+
decreaseValidatorStake(tx, adminCapId, validatorAddress, targetUnstakeSuiAmount) {
|
|
132
174
|
generated.decreaseValidatorStake(tx, this.liquidStakingObject.type, {
|
|
133
175
|
self: this.liquidStakingObject.id,
|
|
134
176
|
adminCap: adminCapId,
|
|
135
177
|
systemState: SUI_SYSTEM_STATE_ID,
|
|
136
178
|
validatorAddress,
|
|
137
|
-
|
|
179
|
+
targetUnstakeSuiAmount,
|
|
138
180
|
});
|
|
139
181
|
}
|
|
140
|
-
collectFees(tx,
|
|
141
|
-
const [sui] =
|
|
142
|
-
self: this.liquidStakingObject.
|
|
182
|
+
collectFees(tx, weightHookAdminCapId) {
|
|
183
|
+
const [sui] = weightHookGenerated.collectFees(tx, this.liquidStakingObject.type, {
|
|
184
|
+
self: this.liquidStakingObject.weightHookId,
|
|
185
|
+
liquidStakingInfo: this.liquidStakingObject.id,
|
|
143
186
|
systemState: SUI_SYSTEM_STATE_ID,
|
|
144
|
-
|
|
187
|
+
weightHookAdminCap: weightHookAdminCapId,
|
|
145
188
|
});
|
|
146
189
|
return sui;
|
|
147
190
|
}
|
|
148
|
-
|
|
191
|
+
collectFeesAndSendToUser(tx, weightHookAdminCapId, address) {
|
|
192
|
+
const sui = this.collectFees(tx, weightHookAdminCapId);
|
|
193
|
+
tx.transferObjects([sui], address);
|
|
194
|
+
}
|
|
195
|
+
updateFees(tx, weightHookAdminCapId, feeConfigArgs) {
|
|
149
196
|
let [builder] = (0, functions_1.newBuilder)(tx);
|
|
150
197
|
if (feeConfigArgs.mintFeeBps != null) {
|
|
151
198
|
console.log(`Setting mint fee bps to ${feeConfigArgs.mintFeeBps}`);
|
|
@@ -161,16 +208,18 @@ class LstClient {
|
|
|
161
208
|
fee: BigInt(feeConfigArgs.redeemFeeBps),
|
|
162
209
|
})[0];
|
|
163
210
|
}
|
|
164
|
-
if (feeConfigArgs.
|
|
211
|
+
if (feeConfigArgs.spreadFeeBps != null) {
|
|
212
|
+
console.log(`Setting spread fee bps to ${feeConfigArgs.spreadFeeBps}`);
|
|
165
213
|
builder = (0, functions_1.setSpreadFeeBps)(tx, {
|
|
166
214
|
self: builder,
|
|
167
|
-
fee: BigInt(feeConfigArgs.
|
|
215
|
+
fee: BigInt(feeConfigArgs.spreadFeeBps),
|
|
168
216
|
})[0];
|
|
169
217
|
}
|
|
170
218
|
const [feeConfig] = (0, functions_1.toFeeConfig)(tx, builder);
|
|
171
|
-
|
|
172
|
-
self: this.liquidStakingObject.
|
|
173
|
-
|
|
219
|
+
weightHookGenerated.updateFees(tx, this.liquidStakingObject.type, {
|
|
220
|
+
self: this.liquidStakingObject.weightHookId,
|
|
221
|
+
liquidStakingInfo: this.liquidStakingObject.id,
|
|
222
|
+
weightHookAdminCap: weightHookAdminCapId,
|
|
174
223
|
feeConfig,
|
|
175
224
|
});
|
|
176
225
|
}
|
|
@@ -192,7 +241,7 @@ class LstClient {
|
|
|
192
241
|
typeArguments: ["address", "u64"],
|
|
193
242
|
arguments: [],
|
|
194
243
|
});
|
|
195
|
-
for (const [validatorAddress, weight
|
|
244
|
+
for (const [validatorAddress, weight] of Object.entries(validatorAddressesAndWeights)) {
|
|
196
245
|
tx.moveCall({
|
|
197
246
|
target: `0x2::vec_map::insert`,
|
|
198
247
|
typeArguments: ["address", "u64"],
|