@suilend/springsui-cli 1.0.7 → 1.0.8
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/client.d.ts +58 -0
- package/sdk/src/client.js +304 -0
- package/sdk/src/index.d.ts +2 -58
- package/sdk/src/index.js +4 -290
- package/sdk/src/lib/coinType.d.ts +4 -0
- package/sdk/src/lib/coinType.js +11 -0
- package/sdk/src/lib/index.d.ts +3 -0
- package/sdk/src/lib/index.js +19 -0
- package/sdk/src/lib/lsts.d.ts +12 -0
- package/sdk/src/lib/lsts.js +56 -0
- package/sdk/src/lib/transactions.d.ts +7 -0
- package/sdk/src/lib/transactions.js +15 -0
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/springsui-cli","version":"1.0.
|
|
1
|
+
{"name":"@suilend/springsui-cli","version":"1.0.8","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/client":"./sdk/src/client.js","./sdk/src":"./sdk/src/index.js","./sdk/src/lib/coinType":"./sdk/src/lib/coinType.js","./sdk/src/lib":"./sdk/src/lib/index.js","./sdk/src/lib/lsts":"./sdk/src/lib/lsts.js","./sdk/src/lib/transactions":"./sdk/src/lib/transactions.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.2.1","@mysten/sui":"1.20.0","commander":"^12.1.0"},"devDependencies":{"ts-node":"^10.9.2"}}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
2
|
+
import { Transaction, TransactionObjectInput } from "@mysten/sui/transactions";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { LiquidStakingInfo } from "./_generated/liquid_staking/liquid-staking/structs";
|
|
5
|
+
export interface LiquidStakingObjectInfo {
|
|
6
|
+
id: string;
|
|
7
|
+
type: string;
|
|
8
|
+
weightHookId: string;
|
|
9
|
+
}
|
|
10
|
+
export interface FeeConfigArgs {
|
|
11
|
+
mintFeeBps?: number;
|
|
12
|
+
redeemFeeBps?: number;
|
|
13
|
+
spreadFeeBps?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare const SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
|
|
16
|
+
export declare class LstClient {
|
|
17
|
+
liquidStakingObject: LiquidStakingObjectInfo;
|
|
18
|
+
client: SuiClient;
|
|
19
|
+
static initialize(client: SuiClient, liquidStakingObjectInfo: LiquidStakingObjectInfo): Promise<LstClient>;
|
|
20
|
+
static createNewLst(tx: Transaction, treasuryCap: string, coinType: string): TransactionObjectInput;
|
|
21
|
+
static getWeightHookAdminCapId(client: SuiClient, address: string, weightHookAdminCapId: string): Promise<string | null | undefined>;
|
|
22
|
+
constructor(liquidStakingObject: LiquidStakingObjectInfo, client: SuiClient);
|
|
23
|
+
getAdminCapId(address: string): Promise<string | null | undefined>;
|
|
24
|
+
mint(tx: Transaction, suiCoinId: TransactionObjectInput): {
|
|
25
|
+
$kind: "NestedResult";
|
|
26
|
+
NestedResult: [number, number];
|
|
27
|
+
};
|
|
28
|
+
mintAmountAndRebalance(tx: Transaction, address: string, amount: string): {
|
|
29
|
+
$kind: "NestedResult";
|
|
30
|
+
NestedResult: [number, number];
|
|
31
|
+
};
|
|
32
|
+
mintAmountAndRebalanceAndSendToUser(tx: Transaction, address: string, amount: string): void;
|
|
33
|
+
redeem(tx: Transaction, lstId: TransactionObjectInput): {
|
|
34
|
+
$kind: "NestedResult";
|
|
35
|
+
NestedResult: [number, number];
|
|
36
|
+
};
|
|
37
|
+
redeemAmount(tx: Transaction, address: string, amount: string): {
|
|
38
|
+
$kind: "NestedResult";
|
|
39
|
+
NestedResult: [number, number];
|
|
40
|
+
};
|
|
41
|
+
redeemAmountAndSendToUser(tx: Transaction, address: string, amount: string): void;
|
|
42
|
+
increaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, suiAmount: number): void;
|
|
43
|
+
decreaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, targetUnstakeSuiAmount: bigint): void;
|
|
44
|
+
collectFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput): {
|
|
45
|
+
$kind: "NestedResult";
|
|
46
|
+
NestedResult: [number, number];
|
|
47
|
+
};
|
|
48
|
+
collectFeesAndSendToUser(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, address: string): void;
|
|
49
|
+
updateFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, feeConfigArgs: FeeConfigArgs): void;
|
|
50
|
+
initializeWeightHook(tx: Transaction, adminCapId: TransactionObjectInput): {
|
|
51
|
+
$kind: "NestedResult";
|
|
52
|
+
NestedResult: [number, number];
|
|
53
|
+
};
|
|
54
|
+
setValidatorAddressesAndWeights(tx: Transaction, weightHookId: TransactionObjectInput, weightHookAdminCap: TransactionObjectInput, validatorAddressesAndWeights: Record<string, number>): void;
|
|
55
|
+
rebalance(tx: Transaction, weightHookId: TransactionObjectInput): void;
|
|
56
|
+
getSpringSuiApy(): Promise<BigNumber>;
|
|
57
|
+
}
|
|
58
|
+
export declare const fetchLiquidStakingInfo: (info: LiquidStakingObjectInfo, client: SuiClient) => Promise<LiquidStakingInfo<any>>;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.fetchLiquidStakingInfo = exports.LstClient = exports.SUILEND_VALIDATOR_ADDRESS = void 0;
|
|
49
|
+
const transactions_1 = require("@mysten/sui/transactions");
|
|
50
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
51
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
52
|
+
const reified_1 = require("./_generated/_framework/reified");
|
|
53
|
+
const liquid_staking_1 = require("./_generated/liquid_staking");
|
|
54
|
+
const functions_1 = require("./_generated/liquid_staking/fees/functions");
|
|
55
|
+
const generated = __importStar(require("./_generated/liquid_staking/liquid-staking/functions"));
|
|
56
|
+
const structs_1 = require("./_generated/liquid_staking/liquid-staking/structs");
|
|
57
|
+
const weightHookGenerated = __importStar(require("./_generated/liquid_staking/weight/functions"));
|
|
58
|
+
const structs_2 = require("./_generated/liquid_staking/weight/structs");
|
|
59
|
+
const SUI_SYSTEM_STATE_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
60
|
+
exports.SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
|
|
61
|
+
const SPRING_SUI_UPGRADE_CAP_ID = "0x4dc657b6c0fe896f4b94fee1ceac96312dde0a36b94e799caaec30deb53dcd67";
|
|
62
|
+
function getLatestPackageId(client, upgradeCapId) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
var _a;
|
|
65
|
+
const object = yield client.getObject({
|
|
66
|
+
id: upgradeCapId,
|
|
67
|
+
options: {
|
|
68
|
+
showContent: true,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return ((_a = object.data) === null || _a === void 0 ? void 0 : _a.content).fields.package;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
class LstClient {
|
|
75
|
+
static initialize(client, liquidStakingObjectInfo) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const publishedAt = yield getLatestPackageId(client, SPRING_SUI_UPGRADE_CAP_ID);
|
|
78
|
+
(0, liquid_staking_1.setPublishedAt)(publishedAt);
|
|
79
|
+
console.log(`Initialized LstClient with package ID: ${publishedAt}`);
|
|
80
|
+
return new LstClient(liquidStakingObjectInfo, client);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
static createNewLst(tx, treasuryCap, coinType) {
|
|
84
|
+
const [feeConfigBuilder] = (0, functions_1.newBuilder)(tx);
|
|
85
|
+
const [feeConfig] = (0, functions_1.toFeeConfig)(tx, feeConfigBuilder);
|
|
86
|
+
const [adminCap, liquidStakingInfo] = generated.createLst(tx, coinType, {
|
|
87
|
+
feeConfig,
|
|
88
|
+
lstTreasuryCap: treasuryCap,
|
|
89
|
+
});
|
|
90
|
+
tx.moveCall({
|
|
91
|
+
target: `0x2::transfer::public_share_object`,
|
|
92
|
+
typeArguments: [`${structs_1.LiquidStakingInfo.$typeName}<${coinType}>`],
|
|
93
|
+
arguments: [liquidStakingInfo],
|
|
94
|
+
});
|
|
95
|
+
const [weightHook, weightHookAdminCap] = weightHookGenerated.new_(tx, coinType, adminCap);
|
|
96
|
+
tx.moveCall({
|
|
97
|
+
target: `0x2::transfer::public_share_object`,
|
|
98
|
+
typeArguments: [`${structs_2.WeightHook.$typeName}<${coinType}>`],
|
|
99
|
+
arguments: [weightHook],
|
|
100
|
+
});
|
|
101
|
+
return weightHookAdminCap;
|
|
102
|
+
}
|
|
103
|
+
static getWeightHookAdminCapId(client, address, weightHookAdminCapId) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
var _a;
|
|
106
|
+
const res = (yield client.getOwnedObjects({
|
|
107
|
+
owner: address,
|
|
108
|
+
filter: {
|
|
109
|
+
StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${weightHookAdminCapId}>`,
|
|
110
|
+
},
|
|
111
|
+
})).data;
|
|
112
|
+
if (res.length == 0) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return (_a = res[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
constructor(liquidStakingObject, client) {
|
|
119
|
+
this.liquidStakingObject = liquidStakingObject;
|
|
120
|
+
this.client = client;
|
|
121
|
+
}
|
|
122
|
+
getAdminCapId(address) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
var _a;
|
|
125
|
+
const res = (yield this.client.getOwnedObjects({
|
|
126
|
+
owner: address,
|
|
127
|
+
filter: {
|
|
128
|
+
StructType: `${liquid_staking_1.PACKAGE_ID}::liquid_staking::AdminCap<${this.liquidStakingObject.type}>`,
|
|
129
|
+
},
|
|
130
|
+
})).data;
|
|
131
|
+
if (res.length == 0) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return (_a = res[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// returns the lst object
|
|
138
|
+
mint(tx, suiCoinId) {
|
|
139
|
+
const [lst] = generated.mint(tx, this.liquidStakingObject.type, {
|
|
140
|
+
self: this.liquidStakingObject.id,
|
|
141
|
+
sui: suiCoinId,
|
|
142
|
+
systemState: SUI_SYSTEM_STATE_ID,
|
|
143
|
+
});
|
|
144
|
+
return lst;
|
|
145
|
+
}
|
|
146
|
+
mintAmountAndRebalance(tx, address, amount) {
|
|
147
|
+
const [sui] = tx.splitCoins(tx.gas, [BigInt(amount)]);
|
|
148
|
+
const lst = this.mint(tx, sui);
|
|
149
|
+
this.rebalance(tx, this.liquidStakingObject.weightHookId);
|
|
150
|
+
return lst;
|
|
151
|
+
}
|
|
152
|
+
mintAmountAndRebalanceAndSendToUser(tx, address, amount) {
|
|
153
|
+
const lst = this.mintAmountAndRebalance(tx, address, amount);
|
|
154
|
+
tx.transferObjects([lst], address);
|
|
155
|
+
}
|
|
156
|
+
// returns the sui coin
|
|
157
|
+
redeem(tx, lstId) {
|
|
158
|
+
const [sui] = generated.redeem(tx, this.liquidStakingObject.type, {
|
|
159
|
+
self: this.liquidStakingObject.id,
|
|
160
|
+
systemState: SUI_SYSTEM_STATE_ID,
|
|
161
|
+
lst: lstId,
|
|
162
|
+
});
|
|
163
|
+
return sui;
|
|
164
|
+
}
|
|
165
|
+
redeemAmount(tx, address, amount) {
|
|
166
|
+
const lstCoin = (0, transactions_1.coinWithBalance)({
|
|
167
|
+
balance: BigInt(amount),
|
|
168
|
+
type: this.liquidStakingObject.type,
|
|
169
|
+
useGasCoin: false,
|
|
170
|
+
})(tx);
|
|
171
|
+
const sui = this.redeem(tx, lstCoin);
|
|
172
|
+
return sui;
|
|
173
|
+
}
|
|
174
|
+
redeemAmountAndSendToUser(tx, address, amount) {
|
|
175
|
+
const suiCoin = this.redeemAmount(tx, address, amount);
|
|
176
|
+
tx.transferObjects([suiCoin], address);
|
|
177
|
+
}
|
|
178
|
+
// admin functions
|
|
179
|
+
increaseValidatorStake(tx, adminCapId, validatorAddress, suiAmount) {
|
|
180
|
+
generated.increaseValidatorStake(tx, this.liquidStakingObject.type, {
|
|
181
|
+
self: this.liquidStakingObject.id,
|
|
182
|
+
adminCap: adminCapId,
|
|
183
|
+
systemState: SUI_SYSTEM_STATE_ID,
|
|
184
|
+
validatorAddress,
|
|
185
|
+
suiAmount: BigInt(suiAmount),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
decreaseValidatorStake(tx, adminCapId, validatorAddress, targetUnstakeSuiAmount) {
|
|
189
|
+
generated.decreaseValidatorStake(tx, this.liquidStakingObject.type, {
|
|
190
|
+
self: this.liquidStakingObject.id,
|
|
191
|
+
adminCap: adminCapId,
|
|
192
|
+
systemState: SUI_SYSTEM_STATE_ID,
|
|
193
|
+
validatorAddress,
|
|
194
|
+
targetUnstakeSuiAmount,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
collectFees(tx, weightHookAdminCapId) {
|
|
198
|
+
const [sui] = weightHookGenerated.collectFees(tx, this.liquidStakingObject.type, {
|
|
199
|
+
self: this.liquidStakingObject.weightHookId,
|
|
200
|
+
liquidStakingInfo: this.liquidStakingObject.id,
|
|
201
|
+
systemState: SUI_SYSTEM_STATE_ID,
|
|
202
|
+
weightHookAdminCap: weightHookAdminCapId,
|
|
203
|
+
});
|
|
204
|
+
return sui;
|
|
205
|
+
}
|
|
206
|
+
collectFeesAndSendToUser(tx, weightHookAdminCapId, address) {
|
|
207
|
+
const sui = this.collectFees(tx, weightHookAdminCapId);
|
|
208
|
+
tx.transferObjects([sui], address);
|
|
209
|
+
}
|
|
210
|
+
updateFees(tx, weightHookAdminCapId, feeConfigArgs) {
|
|
211
|
+
let [builder] = (0, functions_1.newBuilder)(tx);
|
|
212
|
+
if (feeConfigArgs.mintFeeBps != null) {
|
|
213
|
+
console.log(`Setting mint fee bps to ${feeConfigArgs.mintFeeBps}`);
|
|
214
|
+
builder = (0, functions_1.setSuiMintFeeBps)(tx, {
|
|
215
|
+
self: builder,
|
|
216
|
+
fee: BigInt(feeConfigArgs.mintFeeBps),
|
|
217
|
+
})[0];
|
|
218
|
+
}
|
|
219
|
+
if (feeConfigArgs.redeemFeeBps != null) {
|
|
220
|
+
console.log(`Setting redeem fee bps to ${feeConfigArgs.redeemFeeBps}`);
|
|
221
|
+
builder = (0, functions_1.setRedeemFeeBps)(tx, {
|
|
222
|
+
self: builder,
|
|
223
|
+
fee: BigInt(feeConfigArgs.redeemFeeBps),
|
|
224
|
+
})[0];
|
|
225
|
+
}
|
|
226
|
+
if (feeConfigArgs.spreadFeeBps != null) {
|
|
227
|
+
console.log(`Setting spread fee bps to ${feeConfigArgs.spreadFeeBps}`);
|
|
228
|
+
builder = (0, functions_1.setSpreadFeeBps)(tx, {
|
|
229
|
+
self: builder,
|
|
230
|
+
fee: BigInt(feeConfigArgs.spreadFeeBps),
|
|
231
|
+
})[0];
|
|
232
|
+
}
|
|
233
|
+
const [feeConfig] = (0, functions_1.toFeeConfig)(tx, builder);
|
|
234
|
+
weightHookGenerated.updateFees(tx, this.liquidStakingObject.type, {
|
|
235
|
+
self: this.liquidStakingObject.weightHookId,
|
|
236
|
+
liquidStakingInfo: this.liquidStakingObject.id,
|
|
237
|
+
weightHookAdminCap: weightHookAdminCapId,
|
|
238
|
+
feeConfig,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// weight hook functions
|
|
242
|
+
initializeWeightHook(tx, adminCapId) {
|
|
243
|
+
const [weightHook, weightHookAdminCap] = weightHookGenerated.new_(tx, this.liquidStakingObject.type, adminCapId);
|
|
244
|
+
tx.moveCall({
|
|
245
|
+
target: `0x2::transfer::public_share_object`,
|
|
246
|
+
typeArguments: [
|
|
247
|
+
`${structs_2.WeightHook.$typeName}<${this.liquidStakingObject.type}>`,
|
|
248
|
+
],
|
|
249
|
+
arguments: [weightHook],
|
|
250
|
+
});
|
|
251
|
+
return weightHookAdminCap;
|
|
252
|
+
}
|
|
253
|
+
setValidatorAddressesAndWeights(tx, weightHookId, weightHookAdminCap, validatorAddressesAndWeights) {
|
|
254
|
+
const [vecMap] = tx.moveCall({
|
|
255
|
+
target: `0x2::vec_map::empty`,
|
|
256
|
+
typeArguments: ["address", "u64"],
|
|
257
|
+
arguments: [],
|
|
258
|
+
});
|
|
259
|
+
for (const [validatorAddress, weight] of Object.entries(validatorAddressesAndWeights)) {
|
|
260
|
+
tx.moveCall({
|
|
261
|
+
target: `0x2::vec_map::insert`,
|
|
262
|
+
typeArguments: ["address", "u64"],
|
|
263
|
+
arguments: [
|
|
264
|
+
vecMap,
|
|
265
|
+
tx.pure.address(validatorAddress),
|
|
266
|
+
tx.pure.u64(weight),
|
|
267
|
+
],
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
weightHookGenerated.setValidatorAddressesAndWeights(tx, this.liquidStakingObject.type, {
|
|
271
|
+
self: weightHookId,
|
|
272
|
+
weightHookAdminCap,
|
|
273
|
+
validatorAddressesAndWeights: vecMap,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
rebalance(tx, weightHookId) {
|
|
277
|
+
weightHookGenerated.rebalance(tx, this.liquidStakingObject.type, {
|
|
278
|
+
self: weightHookId,
|
|
279
|
+
systemState: SUI_SYSTEM_STATE_ID,
|
|
280
|
+
liquidStakingInfo: this.liquidStakingObject.id,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
getSpringSuiApy() {
|
|
284
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
+
var _a, _b;
|
|
286
|
+
const validatorApys = (yield this.client.getValidatorsApy()).apys;
|
|
287
|
+
const liquidStakingInfo = yield (0, exports.fetchLiquidStakingInfo)(this.liquidStakingObject, this.client);
|
|
288
|
+
const totalSuiSupply = new bignumber_js_1.default(liquidStakingInfo.storage.totalSuiSupply.toString()).div(10 ** utils_1.SUI_DECIMALS);
|
|
289
|
+
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);
|
|
290
|
+
return new bignumber_js_1.default(liquidStakingInfo.storage.validatorInfos
|
|
291
|
+
.reduce((acc, validatorInfo) => {
|
|
292
|
+
var _a, _b;
|
|
293
|
+
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);
|
|
294
|
+
const validatorTotalSuiAmount = new bignumber_js_1.default(validatorInfo.totalSuiAmount.toString()).div(10 ** utils_1.SUI_DECIMALS);
|
|
295
|
+
return acc.plus(validatorApy.times(validatorTotalSuiAmount));
|
|
296
|
+
}, new bignumber_js_1.default(0))
|
|
297
|
+
.div(totalSuiSupply)).times(new bignumber_js_1.default(1).minus(spreadFeePercent.div(100)));
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.LstClient = LstClient;
|
|
302
|
+
// user functions
|
|
303
|
+
const fetchLiquidStakingInfo = (info, client) => structs_1.LiquidStakingInfo.fetch(client, (0, reified_1.phantom)(info.type), info.id);
|
|
304
|
+
exports.fetchLiquidStakingInfo = fetchLiquidStakingInfo;
|
package/sdk/src/index.d.ts
CHANGED
|
@@ -1,58 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import BigNumber from "bignumber.js";
|
|
4
|
-
import { LiquidStakingInfo } from "./_generated/liquid_staking/liquid-staking/structs";
|
|
5
|
-
export interface LiquidStakingObjectInfo {
|
|
6
|
-
id: string;
|
|
7
|
-
type: string;
|
|
8
|
-
weightHookId: string;
|
|
9
|
-
}
|
|
10
|
-
export declare const SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
|
|
11
|
-
export declare class LstClient {
|
|
12
|
-
liquidStakingObject: LiquidStakingObjectInfo;
|
|
13
|
-
client: SuiClient;
|
|
14
|
-
static initialize(client: SuiClient, liquidStakingObjectInfo: LiquidStakingObjectInfo): Promise<LstClient>;
|
|
15
|
-
static createNewLst(tx: Transaction, treasuryCap: string, coinType: string): TransactionObjectInput;
|
|
16
|
-
static getWeightHookAdminCapId(client: SuiClient, address: string, weightHookAdminCapId: string): Promise<string | null | undefined>;
|
|
17
|
-
constructor(liquidStakingObject: LiquidStakingObjectInfo, client: SuiClient);
|
|
18
|
-
getAdminCapId(address: string): Promise<string | null | undefined>;
|
|
19
|
-
mint(tx: Transaction, suiCoinId: TransactionObjectInput): {
|
|
20
|
-
$kind: "NestedResult";
|
|
21
|
-
NestedResult: [number, number];
|
|
22
|
-
};
|
|
23
|
-
mintAmountAndRebalance(tx: Transaction, address: string, amount: string): {
|
|
24
|
-
$kind: "NestedResult";
|
|
25
|
-
NestedResult: [number, number];
|
|
26
|
-
};
|
|
27
|
-
mintAmountAndRebalanceAndSendToUser(tx: Transaction, address: string, amount: string): void;
|
|
28
|
-
redeem(tx: Transaction, lstId: TransactionObjectInput): {
|
|
29
|
-
$kind: "NestedResult";
|
|
30
|
-
NestedResult: [number, number];
|
|
31
|
-
};
|
|
32
|
-
redeemAmount(tx: Transaction, address: string, amount: string): {
|
|
33
|
-
$kind: "NestedResult";
|
|
34
|
-
NestedResult: [number, number];
|
|
35
|
-
};
|
|
36
|
-
redeemAmountAndSendToUser(tx: Transaction, address: string, amount: string): void;
|
|
37
|
-
increaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, suiAmount: number): void;
|
|
38
|
-
decreaseValidatorStake(tx: Transaction, adminCapId: TransactionObjectInput, validatorAddress: string, targetUnstakeSuiAmount: bigint): void;
|
|
39
|
-
collectFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput): {
|
|
40
|
-
$kind: "NestedResult";
|
|
41
|
-
NestedResult: [number, number];
|
|
42
|
-
};
|
|
43
|
-
collectFeesAndSendToUser(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, address: string): void;
|
|
44
|
-
updateFees(tx: Transaction, weightHookAdminCapId: TransactionObjectInput, feeConfigArgs: FeeConfigArgs): void;
|
|
45
|
-
initializeWeightHook(tx: Transaction, adminCapId: TransactionObjectInput): {
|
|
46
|
-
$kind: "NestedResult";
|
|
47
|
-
NestedResult: [number, number];
|
|
48
|
-
};
|
|
49
|
-
setValidatorAddressesAndWeights(tx: Transaction, weightHookId: TransactionObjectInput, weightHookAdminCap: TransactionObjectInput, validatorAddressesAndWeights: Record<string, number>): void;
|
|
50
|
-
rebalance(tx: Transaction, weightHookId: TransactionObjectInput): void;
|
|
51
|
-
getSpringSuiApy(): Promise<BigNumber>;
|
|
52
|
-
}
|
|
53
|
-
export declare const fetchLiquidStakingInfo: (info: LiquidStakingObjectInfo, client: SuiClient) => Promise<LiquidStakingInfo<any>>;
|
|
54
|
-
export interface FeeConfigArgs {
|
|
55
|
-
mintFeeBps?: number;
|
|
56
|
-
redeemFeeBps?: number;
|
|
57
|
-
spreadFeeBps?: number;
|
|
58
|
-
}
|
|
1
|
+
export * from "./lib";
|
|
2
|
+
export * from "./client";
|
package/sdk/src/index.js
CHANGED
|
@@ -10,295 +10,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
46
15
|
};
|
|
47
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
51
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
52
|
-
const reified_1 = require("./_generated/_framework/reified");
|
|
53
|
-
const liquid_staking_1 = require("./_generated/liquid_staking");
|
|
54
|
-
const functions_1 = require("./_generated/liquid_staking/fees/functions");
|
|
55
|
-
const generated = __importStar(require("./_generated/liquid_staking/liquid-staking/functions"));
|
|
56
|
-
const structs_1 = require("./_generated/liquid_staking/liquid-staking/structs");
|
|
57
|
-
const weightHookGenerated = __importStar(require("./_generated/liquid_staking/weight/functions"));
|
|
58
|
-
const structs_2 = require("./_generated/liquid_staking/weight/structs");
|
|
59
|
-
const SUI_SYSTEM_STATE_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
60
|
-
exports.SUILEND_VALIDATOR_ADDRESS = "0xce8e537664ba5d1d5a6a857b17bd142097138706281882be6805e17065ecde89";
|
|
61
|
-
const SPRING_SUI_UPGRADE_CAP_ID = "0x4dc657b6c0fe896f4b94fee1ceac96312dde0a36b94e799caaec30deb53dcd67";
|
|
62
|
-
function getLatestPackageId(client, upgradeCapId) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
var _a;
|
|
65
|
-
const object = yield client.getObject({
|
|
66
|
-
id: upgradeCapId,
|
|
67
|
-
options: {
|
|
68
|
-
showContent: true,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
return ((_a = object.data) === null || _a === void 0 ? void 0 : _a.content).fields.package;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
class LstClient {
|
|
75
|
-
static initialize(client, liquidStakingObjectInfo) {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const publishedAt = yield getLatestPackageId(client, SPRING_SUI_UPGRADE_CAP_ID);
|
|
78
|
-
(0, liquid_staking_1.setPublishedAt)(publishedAt);
|
|
79
|
-
console.log(`Initialized LstClient with package ID: ${publishedAt}`);
|
|
80
|
-
return new LstClient(liquidStakingObjectInfo, client);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
static createNewLst(tx, treasuryCap, coinType) {
|
|
84
|
-
const [feeConfigBuilder] = (0, functions_1.newBuilder)(tx);
|
|
85
|
-
const [feeConfig] = (0, functions_1.toFeeConfig)(tx, feeConfigBuilder);
|
|
86
|
-
const [adminCap, liquidStakingInfo] = generated.createLst(tx, coinType, {
|
|
87
|
-
feeConfig,
|
|
88
|
-
lstTreasuryCap: treasuryCap,
|
|
89
|
-
});
|
|
90
|
-
tx.moveCall({
|
|
91
|
-
target: `0x2::transfer::public_share_object`,
|
|
92
|
-
typeArguments: [`${structs_1.LiquidStakingInfo.$typeName}<${coinType}>`],
|
|
93
|
-
arguments: [liquidStakingInfo],
|
|
94
|
-
});
|
|
95
|
-
const [weightHook, weightHookAdminCap] = weightHookGenerated.new_(tx, coinType, adminCap);
|
|
96
|
-
tx.moveCall({
|
|
97
|
-
target: `0x2::transfer::public_share_object`,
|
|
98
|
-
typeArguments: [`${structs_2.WeightHook.$typeName}<${coinType}>`],
|
|
99
|
-
arguments: [weightHook],
|
|
100
|
-
});
|
|
101
|
-
return weightHookAdminCap;
|
|
102
|
-
}
|
|
103
|
-
static getWeightHookAdminCapId(client, address, weightHookAdminCapId) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
var _a;
|
|
106
|
-
const res = (yield client.getOwnedObjects({
|
|
107
|
-
owner: address,
|
|
108
|
-
filter: {
|
|
109
|
-
StructType: `${liquid_staking_1.PACKAGE_ID}::weight::WeightHookAdminCap<${weightHookAdminCapId}>`,
|
|
110
|
-
},
|
|
111
|
-
})).data;
|
|
112
|
-
if (res.length == 0) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
return (_a = res[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
constructor(liquidStakingObject, client) {
|
|
119
|
-
this.liquidStakingObject = liquidStakingObject;
|
|
120
|
-
this.client = client;
|
|
121
|
-
}
|
|
122
|
-
getAdminCapId(address) {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
var _a;
|
|
125
|
-
const res = (yield this.client.getOwnedObjects({
|
|
126
|
-
owner: address,
|
|
127
|
-
filter: {
|
|
128
|
-
StructType: `${liquid_staking_1.PACKAGE_ID}::liquid_staking::AdminCap<${this.liquidStakingObject.type}>`,
|
|
129
|
-
},
|
|
130
|
-
})).data;
|
|
131
|
-
if (res.length == 0) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
return (_a = res[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// returns the lst object
|
|
138
|
-
mint(tx, suiCoinId) {
|
|
139
|
-
const [lst] = generated.mint(tx, this.liquidStakingObject.type, {
|
|
140
|
-
self: this.liquidStakingObject.id,
|
|
141
|
-
sui: suiCoinId,
|
|
142
|
-
systemState: SUI_SYSTEM_STATE_ID,
|
|
143
|
-
});
|
|
144
|
-
return lst;
|
|
145
|
-
}
|
|
146
|
-
mintAmountAndRebalance(tx, address, amount) {
|
|
147
|
-
const [sui] = tx.splitCoins(tx.gas, [BigInt(amount)]);
|
|
148
|
-
const lst = this.mint(tx, sui);
|
|
149
|
-
this.rebalance(tx, this.liquidStakingObject.weightHookId);
|
|
150
|
-
return lst;
|
|
151
|
-
}
|
|
152
|
-
mintAmountAndRebalanceAndSendToUser(tx, address, amount) {
|
|
153
|
-
const lst = this.mintAmountAndRebalance(tx, address, amount);
|
|
154
|
-
tx.transferObjects([lst], address);
|
|
155
|
-
}
|
|
156
|
-
// returns the sui coin
|
|
157
|
-
redeem(tx, lstId) {
|
|
158
|
-
const [sui] = generated.redeem(tx, this.liquidStakingObject.type, {
|
|
159
|
-
self: this.liquidStakingObject.id,
|
|
160
|
-
systemState: SUI_SYSTEM_STATE_ID,
|
|
161
|
-
lst: lstId,
|
|
162
|
-
});
|
|
163
|
-
return sui;
|
|
164
|
-
}
|
|
165
|
-
redeemAmount(tx, address, amount) {
|
|
166
|
-
const lstCoin = (0, transactions_1.coinWithBalance)({
|
|
167
|
-
balance: BigInt(amount),
|
|
168
|
-
type: this.liquidStakingObject.type,
|
|
169
|
-
useGasCoin: false,
|
|
170
|
-
})(tx);
|
|
171
|
-
const sui = this.redeem(tx, lstCoin);
|
|
172
|
-
return sui;
|
|
173
|
-
}
|
|
174
|
-
redeemAmountAndSendToUser(tx, address, amount) {
|
|
175
|
-
const suiCoin = this.redeemAmount(tx, address, amount);
|
|
176
|
-
tx.transferObjects([suiCoin], address);
|
|
177
|
-
}
|
|
178
|
-
// admin functions
|
|
179
|
-
increaseValidatorStake(tx, adminCapId, validatorAddress, suiAmount) {
|
|
180
|
-
generated.increaseValidatorStake(tx, this.liquidStakingObject.type, {
|
|
181
|
-
self: this.liquidStakingObject.id,
|
|
182
|
-
adminCap: adminCapId,
|
|
183
|
-
systemState: SUI_SYSTEM_STATE_ID,
|
|
184
|
-
validatorAddress,
|
|
185
|
-
suiAmount: BigInt(suiAmount),
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
decreaseValidatorStake(tx, adminCapId, validatorAddress, targetUnstakeSuiAmount) {
|
|
189
|
-
generated.decreaseValidatorStake(tx, this.liquidStakingObject.type, {
|
|
190
|
-
self: this.liquidStakingObject.id,
|
|
191
|
-
adminCap: adminCapId,
|
|
192
|
-
systemState: SUI_SYSTEM_STATE_ID,
|
|
193
|
-
validatorAddress,
|
|
194
|
-
targetUnstakeSuiAmount,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
collectFees(tx, weightHookAdminCapId) {
|
|
198
|
-
const [sui] = weightHookGenerated.collectFees(tx, this.liquidStakingObject.type, {
|
|
199
|
-
self: this.liquidStakingObject.weightHookId,
|
|
200
|
-
liquidStakingInfo: this.liquidStakingObject.id,
|
|
201
|
-
systemState: SUI_SYSTEM_STATE_ID,
|
|
202
|
-
weightHookAdminCap: weightHookAdminCapId,
|
|
203
|
-
});
|
|
204
|
-
return sui;
|
|
205
|
-
}
|
|
206
|
-
collectFeesAndSendToUser(tx, weightHookAdminCapId, address) {
|
|
207
|
-
const sui = this.collectFees(tx, weightHookAdminCapId);
|
|
208
|
-
tx.transferObjects([sui], address);
|
|
209
|
-
}
|
|
210
|
-
updateFees(tx, weightHookAdminCapId, feeConfigArgs) {
|
|
211
|
-
let [builder] = (0, functions_1.newBuilder)(tx);
|
|
212
|
-
if (feeConfigArgs.mintFeeBps != null) {
|
|
213
|
-
console.log(`Setting mint fee bps to ${feeConfigArgs.mintFeeBps}`);
|
|
214
|
-
builder = (0, functions_1.setSuiMintFeeBps)(tx, {
|
|
215
|
-
self: builder,
|
|
216
|
-
fee: BigInt(feeConfigArgs.mintFeeBps),
|
|
217
|
-
})[0];
|
|
218
|
-
}
|
|
219
|
-
if (feeConfigArgs.redeemFeeBps != null) {
|
|
220
|
-
console.log(`Setting redeem fee bps to ${feeConfigArgs.redeemFeeBps}`);
|
|
221
|
-
builder = (0, functions_1.setRedeemFeeBps)(tx, {
|
|
222
|
-
self: builder,
|
|
223
|
-
fee: BigInt(feeConfigArgs.redeemFeeBps),
|
|
224
|
-
})[0];
|
|
225
|
-
}
|
|
226
|
-
if (feeConfigArgs.spreadFeeBps != null) {
|
|
227
|
-
console.log(`Setting spread fee bps to ${feeConfigArgs.spreadFeeBps}`);
|
|
228
|
-
builder = (0, functions_1.setSpreadFeeBps)(tx, {
|
|
229
|
-
self: builder,
|
|
230
|
-
fee: BigInt(feeConfigArgs.spreadFeeBps),
|
|
231
|
-
})[0];
|
|
232
|
-
}
|
|
233
|
-
const [feeConfig] = (0, functions_1.toFeeConfig)(tx, builder);
|
|
234
|
-
weightHookGenerated.updateFees(tx, this.liquidStakingObject.type, {
|
|
235
|
-
self: this.liquidStakingObject.weightHookId,
|
|
236
|
-
liquidStakingInfo: this.liquidStakingObject.id,
|
|
237
|
-
weightHookAdminCap: weightHookAdminCapId,
|
|
238
|
-
feeConfig,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
// weight hook functions
|
|
242
|
-
initializeWeightHook(tx, adminCapId) {
|
|
243
|
-
const [weightHook, weightHookAdminCap] = weightHookGenerated.new_(tx, this.liquidStakingObject.type, adminCapId);
|
|
244
|
-
tx.moveCall({
|
|
245
|
-
target: `0x2::transfer::public_share_object`,
|
|
246
|
-
typeArguments: [
|
|
247
|
-
`${structs_2.WeightHook.$typeName}<${this.liquidStakingObject.type}>`,
|
|
248
|
-
],
|
|
249
|
-
arguments: [weightHook],
|
|
250
|
-
});
|
|
251
|
-
return weightHookAdminCap;
|
|
252
|
-
}
|
|
253
|
-
setValidatorAddressesAndWeights(tx, weightHookId, weightHookAdminCap, validatorAddressesAndWeights) {
|
|
254
|
-
const [vecMap] = tx.moveCall({
|
|
255
|
-
target: `0x2::vec_map::empty`,
|
|
256
|
-
typeArguments: ["address", "u64"],
|
|
257
|
-
arguments: [],
|
|
258
|
-
});
|
|
259
|
-
for (const [validatorAddress, weight] of Object.entries(validatorAddressesAndWeights)) {
|
|
260
|
-
tx.moveCall({
|
|
261
|
-
target: `0x2::vec_map::insert`,
|
|
262
|
-
typeArguments: ["address", "u64"],
|
|
263
|
-
arguments: [
|
|
264
|
-
vecMap,
|
|
265
|
-
tx.pure.address(validatorAddress),
|
|
266
|
-
tx.pure.u64(weight),
|
|
267
|
-
],
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
weightHookGenerated.setValidatorAddressesAndWeights(tx, this.liquidStakingObject.type, {
|
|
271
|
-
self: weightHookId,
|
|
272
|
-
weightHookAdminCap,
|
|
273
|
-
validatorAddressesAndWeights: vecMap,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
rebalance(tx, weightHookId) {
|
|
277
|
-
weightHookGenerated.rebalance(tx, this.liquidStakingObject.type, {
|
|
278
|
-
self: weightHookId,
|
|
279
|
-
systemState: SUI_SYSTEM_STATE_ID,
|
|
280
|
-
liquidStakingInfo: this.liquidStakingObject.id,
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
getSpringSuiApy() {
|
|
284
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
var _a, _b;
|
|
286
|
-
const validatorApys = (yield this.client.getValidatorsApy()).apys;
|
|
287
|
-
const liquidStakingInfo = yield (0, exports.fetchLiquidStakingInfo)(this.liquidStakingObject, this.client);
|
|
288
|
-
const totalSuiSupply = new bignumber_js_1.default(liquidStakingInfo.storage.totalSuiSupply.toString()).div(10 ** utils_1.SUI_DECIMALS);
|
|
289
|
-
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);
|
|
290
|
-
return new bignumber_js_1.default(liquidStakingInfo.storage.validatorInfos
|
|
291
|
-
.reduce((acc, validatorInfo) => {
|
|
292
|
-
var _a, _b;
|
|
293
|
-
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);
|
|
294
|
-
const validatorTotalSuiAmount = new bignumber_js_1.default(validatorInfo.totalSuiAmount.toString()).div(10 ** utils_1.SUI_DECIMALS);
|
|
295
|
-
return acc.plus(validatorApy.times(validatorTotalSuiAmount));
|
|
296
|
-
}, new bignumber_js_1.default(0))
|
|
297
|
-
.div(totalSuiSupply)).times(new bignumber_js_1.default(1).minus(spreadFeePercent.div(100)));
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
exports.LstClient = LstClient;
|
|
302
|
-
// user functions
|
|
303
|
-
const fetchLiquidStakingInfo = (info, client) => structs_1.LiquidStakingInfo.fetch(client, (0, reified_1.phantom)(info.type), info.id);
|
|
304
|
-
exports.fetchLiquidStakingInfo = fetchLiquidStakingInfo;
|
|
17
|
+
__exportStar(require("./lib"), exports);
|
|
18
|
+
__exportStar(require("./client"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEcosystemLst = exports.isLst = exports.NORMALIZED_ECOSYSTEM_LST_COINTYPES = exports.NORMALIZED_LST_COINTYPES = void 0;
|
|
4
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
5
|
+
const lsts_1 = require("./lsts");
|
|
6
|
+
exports.NORMALIZED_LST_COINTYPES = Object.values(lsts_1.LIQUID_STAKING_INFO_MAP).map((info) => info.type);
|
|
7
|
+
exports.NORMALIZED_ECOSYSTEM_LST_COINTYPES = exports.NORMALIZED_LST_COINTYPES.filter((coinType) => (0, utils_1.normalizeStructTag)(coinType) !== lsts_1.LIQUID_STAKING_INFO_MAP.sSUI.type);
|
|
8
|
+
const isLst = (coinType) => exports.NORMALIZED_LST_COINTYPES.includes((0, utils_1.normalizeStructTag)(coinType));
|
|
9
|
+
exports.isLst = isLst;
|
|
10
|
+
const isEcosystemLst = (coinType) => exports.NORMALIZED_ECOSYSTEM_LST_COINTYPES.includes((0, utils_1.normalizeStructTag)(coinType));
|
|
11
|
+
exports.isEcosystemLst = isEcosystemLst;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./coinType"), exports);
|
|
18
|
+
__exportStar(require("./lsts"), exports);
|
|
19
|
+
__exportStar(require("./transactions"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LiquidStakingObjectInfo } from "../client";
|
|
2
|
+
export declare enum LstId {
|
|
3
|
+
sSUI = "sSUI",
|
|
4
|
+
mSUI = "mSUI",
|
|
5
|
+
fudSUI = "fudSUI",
|
|
6
|
+
kSUI = "kSUI",
|
|
7
|
+
trevinSUI = "trevinSUI",
|
|
8
|
+
upSUI = "upSUI",
|
|
9
|
+
test1SUI = "test1SUI",
|
|
10
|
+
ripleysSUI = "ripleysSUI"
|
|
11
|
+
}
|
|
12
|
+
export declare const LIQUID_STAKING_INFO_MAP: Record<LstId, LiquidStakingObjectInfo>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LIQUID_STAKING_INFO_MAP = exports.LstId = void 0;
|
|
4
|
+
var LstId;
|
|
5
|
+
(function (LstId) {
|
|
6
|
+
LstId["sSUI"] = "sSUI";
|
|
7
|
+
LstId["mSUI"] = "mSUI";
|
|
8
|
+
LstId["fudSUI"] = "fudSUI";
|
|
9
|
+
LstId["kSUI"] = "kSUI";
|
|
10
|
+
LstId["trevinSUI"] = "trevinSUI";
|
|
11
|
+
LstId["upSUI"] = "upSUI";
|
|
12
|
+
LstId["test1SUI"] = "test1SUI";
|
|
13
|
+
LstId["ripleysSUI"] = "ripleysSUI";
|
|
14
|
+
})(LstId || (exports.LstId = LstId = {}));
|
|
15
|
+
exports.LIQUID_STAKING_INFO_MAP = {
|
|
16
|
+
[LstId.sSUI]: {
|
|
17
|
+
id: "0x15eda7330c8f99c30e430b4d82fd7ab2af3ead4ae17046fcb224aa9bad394f6b",
|
|
18
|
+
type: "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI",
|
|
19
|
+
weightHookId: "0xbbafcb2d7399c0846f8185da3f273ad5b26b3b35993050affa44cfa890f1f144",
|
|
20
|
+
},
|
|
21
|
+
[LstId.mSUI]: {
|
|
22
|
+
id: "0x985dd33bc2a8b5390f2c30a18d32e9a63a993a5b52750c6fe2e6ac8baeb69f48",
|
|
23
|
+
type: "0x922d15d7f55c13fd790f6e54397470ec592caa2b508df292a2e8553f3d3b274f::msui::MSUI",
|
|
24
|
+
weightHookId: "0x887d03877df512e7ed72ca96821dc9cc1715ff7abd204d7cfa41b36a7d61d737",
|
|
25
|
+
},
|
|
26
|
+
[LstId.fudSUI]: {
|
|
27
|
+
id: "0x7b4406fd4de96e08711729516f826e36f3268c2fefe6de985abc41192b02b871",
|
|
28
|
+
type: "0x02358129a7d66f943786a10b518fdc79145f1fc8d23420d9948c4aeea190f603::fud_sui::FUD_SUI",
|
|
29
|
+
weightHookId: "0x33af323b12561bf362a2952e2bd5fe5a8e4799314b8bbf7c88033b2a8b6d2ec3",
|
|
30
|
+
},
|
|
31
|
+
[LstId.kSUI]: {
|
|
32
|
+
id: "0x03583e2c4d5a66299369214012564d72c4a141afeefce50c349cd56b5f8a6955",
|
|
33
|
+
type: "0x41ff228bfd566f0c707173ee6413962a77e3929588d010250e4e76f0d1cc0ad4::ksui::KSUI",
|
|
34
|
+
weightHookId: "0x8e6a057e3ded16af8bd11d2a5a5ac984776791d458a22de9437124fb40ee385e",
|
|
35
|
+
},
|
|
36
|
+
[LstId.trevinSUI]: {
|
|
37
|
+
id: "0x1ec3b836fe8095152741ae5425ca4c35606ba5622c76291962d8fd9daba961db",
|
|
38
|
+
type: "0x502867b177303bf1bf226245fcdd3403c177e78d175a55a56c0602c7ff51c7fa::trevin_sui::TREVIN_SUI",
|
|
39
|
+
weightHookId: "0xf6a76b1026ec24af5102ee0df1e7a031208b3e85dea7d5e114ab559eb9569c2a",
|
|
40
|
+
},
|
|
41
|
+
[LstId.upSUI]: {
|
|
42
|
+
id: "0x0ee341383a760c3af14337f134d96a5502073b897f551895e92f74aa07de0905",
|
|
43
|
+
type: "0xe68fad47384e18cd79040cb8d72b7f64d267eebb73a0b8d54711aa860570f404::upsui::UPSUI",
|
|
44
|
+
weightHookId: "0x3302addc63a941747c713b3799a6915aa3232fc9b94c76ae5c5315fbdb1d9286",
|
|
45
|
+
},
|
|
46
|
+
[LstId.test1SUI]: {
|
|
47
|
+
id: "0xa4b536491aa3a8c02c43a1a1f31c6564579171001d835570bb52978b81c8aa4b",
|
|
48
|
+
type: "0xb5825ab8dc9e72e1f8e6b3fa568407474821c2d9513b596e6639f468eb1f469::test1_sui::TEST1_SUI",
|
|
49
|
+
weightHookId: "0xd67b194bcf9c72eefc1be8802a79f44959817eb1952432ac57c7045507e7240b",
|
|
50
|
+
},
|
|
51
|
+
[LstId.ripleysSUI]: {
|
|
52
|
+
id: "0x50f983c5257f578a2340ff45f6c82f3d6fc358a3e7a8bc57dd112d280badbfd6",
|
|
53
|
+
type: "0xdc0c8026236f1be172ba03d7d689bfd663497cc5a730bf367bfb2e2c72ec6df8::ripleys::RIPLEYS",
|
|
54
|
+
weightHookId: "0xfee25aa74038036cb1548a27a6824213c6a263c3aa45dc37b1c3fbe6037be7d2",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
2
|
+
import { LstClient } from "../client";
|
|
3
|
+
export declare const convertLsts: (inLstClient: LstClient, outLstClient: LstClient, transaction: Transaction, address: string, amount: string) => {
|
|
4
|
+
$kind: "NestedResult";
|
|
5
|
+
NestedResult: [number, number];
|
|
6
|
+
};
|
|
7
|
+
export declare const convertLstsAndSendToUser: (inLstClient: LstClient, outLstClient: LstClient, transaction: Transaction, address: string, amount: string) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
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);
|
|
6
|
+
const lstCoin = outLstClient.mint(transaction, suiCoin);
|
|
7
|
+
outLstClient.rebalance(transaction, outLstClient.liquidStakingObject.weightHookId);
|
|
8
|
+
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);
|
|
13
|
+
transaction.transferObjects([lstCoin], address);
|
|
14
|
+
};
|
|
15
|
+
exports.convertLstsAndSendToUser = convertLstsAndSendToUser;
|