stable-layer-sdk 1.0.4 → 1.0.6

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.
@@ -0,0 +1,873 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ StableLayerClient: () => StableLayerClient
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_transactions2 = require("@mysten/sui/transactions");
27
+
28
+ // src/libs/constants.ts
29
+ var STABLE_VAULT = "0x65f38160110cd6859d05f338ff54b4f462883bb6f87c667a65c0fb0e537410a7";
30
+ var USDC_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
31
+ var STABLE_LP_TYPE = "0xb75744fadcbfc174627567ca29645d0af8f6e6fd01b6f57c75a08cd3fb97c567::lake_usdc::LakeUSDC";
32
+ var YUSDB_TYPE = "0xac718b4b672d7f461fe7e86847166ff9c23cadba217397f0848a95bdea1f1051::yesusdb::YesUSDB";
33
+ var STABLE_LAYER_PACKAGE_ID = "0x41e25d09e20cf3bc43fe321e51ef178fac419ae47b783a7161982158fc9f17d6";
34
+ var STABLE_VAULT_FARM_PACKAGE_ID = "0xd5b9fb5a964fa9c274e07a788d7b6d36d8df1c73e2e6f795f8db852621470b70";
35
+ var SAVING_TYPE = "0x38f61c75fa8407140294c84167dd57684580b55c3066883b48dedc344b1cde1e::susdb::SUSDB";
36
+ var YIELD_VAULT = "0x0a7f6325253157cd437812fea0ceee9a6b96f2ec5eac410da6df39558ff3a4d1";
37
+ var STABLE_REGISTRY = "0x213f4d584c0770f455bb98c94a4ee5ea9ddbc3d4ebb98a0ad6d093eb6da41642";
38
+ var STABLE_VAULT_FARM_ENTITY_TYPE = `0xc1025fe014b03d33b207b5afb0ba04293be87fab438c1418a26a75c2fe05c223::stable_vault_farm::StableVaultFarmEntity<${STABLE_LP_TYPE}, ${USDC_TYPE}>`;
39
+ var STABLE_VAULT_FARM = "0xe958b7d102b33bf3c09addb0e2cdff102ff2c93afe407ec5c2a541e8959a650c";
40
+ var YIELD_USDB_PACKAGE_ID = "0x203eebc39442014a1b8180f3b8ed70143dac2c5d28ba5703fe34c21052728705";
41
+ var BTC_USD_TYPE = "0x6d9fc33611f4881a3f5c0cd4899d95a862236ce52b3a38fef039077b0c5b5834::btc_usdc::BtcUSDC";
42
+ var STABLE_COIN_TYPES = {
43
+ btcUSDC: BTC_USD_TYPE
44
+ };
45
+
46
+ // src/index.ts
47
+ var import_client = require("@mysten/sui/client");
48
+
49
+ // src/generated/utils/index.ts
50
+ var import_bcs = require("@mysten/sui/bcs");
51
+ var import_utils = require("@mysten/sui/utils");
52
+ var import_transactions = require("@mysten/sui/transactions");
53
+ var MOVE_STDLIB_ADDRESS = (0, import_utils.normalizeSuiAddress)("0x1");
54
+ var SUI_FRAMEWORK_ADDRESS = (0, import_utils.normalizeSuiAddress)("0x2");
55
+ var SUI_SYSTEM_ADDRESS = (0, import_utils.normalizeSuiAddress)("0x3");
56
+ function getPureBcsSchema(typeTag) {
57
+ const parsedTag = typeof typeTag === "string" ? import_bcs.TypeTagSerializer.parseFromStr(typeTag) : typeTag;
58
+ if ("u8" in parsedTag) {
59
+ return import_bcs.bcs.U8;
60
+ } else if ("u16" in parsedTag) {
61
+ return import_bcs.bcs.U16;
62
+ } else if ("u32" in parsedTag) {
63
+ return import_bcs.bcs.U32;
64
+ } else if ("u64" in parsedTag) {
65
+ return import_bcs.bcs.U64;
66
+ } else if ("u128" in parsedTag) {
67
+ return import_bcs.bcs.U128;
68
+ } else if ("u256" in parsedTag) {
69
+ return import_bcs.bcs.U256;
70
+ } else if ("address" in parsedTag) {
71
+ return import_bcs.bcs.Address;
72
+ } else if ("bool" in parsedTag) {
73
+ return import_bcs.bcs.Bool;
74
+ } else if ("vector" in parsedTag) {
75
+ const type = getPureBcsSchema(parsedTag.vector);
76
+ return type ? import_bcs.bcs.vector(type) : null;
77
+ } else if ("struct" in parsedTag) {
78
+ const structTag = parsedTag.struct;
79
+ const pkg = (0, import_utils.normalizeSuiAddress)(parsedTag.struct.address);
80
+ if (pkg === MOVE_STDLIB_ADDRESS) {
81
+ if ((structTag.module === "ascii" || structTag.module === "string") && structTag.name === "String") {
82
+ return import_bcs.bcs.String;
83
+ }
84
+ if (structTag.module === "option" && structTag.name === "Option") {
85
+ const type = getPureBcsSchema(structTag.typeParams[0]);
86
+ return type ? import_bcs.bcs.option(type) : null;
87
+ }
88
+ }
89
+ if (pkg === SUI_FRAMEWORK_ADDRESS && structTag.module === "Object" && structTag.name === "ID") {
90
+ return import_bcs.bcs.Address;
91
+ }
92
+ }
93
+ return null;
94
+ }
95
+ function normalizeMoveArguments(args, argTypes, parameterNames) {
96
+ const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
97
+ if (parameterNames && argLen !== parameterNames.length) {
98
+ throw new Error(
99
+ `Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`
100
+ );
101
+ }
102
+ const normalizedArgs = [];
103
+ let index = 0;
104
+ for (const [i, argType] of argTypes.entries()) {
105
+ if (argType === `${SUI_FRAMEWORK_ADDRESS}::deny_list::DenyList`) {
106
+ normalizedArgs.push((tx) => tx.object.denyList());
107
+ continue;
108
+ }
109
+ if (argType === `${SUI_FRAMEWORK_ADDRESS}::random::Random`) {
110
+ normalizedArgs.push((tx) => tx.object.random());
111
+ continue;
112
+ }
113
+ if (argType === `${SUI_FRAMEWORK_ADDRESS}::clock::Clock`) {
114
+ normalizedArgs.push((tx) => tx.object.clock());
115
+ continue;
116
+ }
117
+ if (argType === `${SUI_SYSTEM_ADDRESS}::sui_system::SuiSystemState`) {
118
+ normalizedArgs.push((tx) => tx.object.system());
119
+ continue;
120
+ }
121
+ let arg;
122
+ if (Array.isArray(args)) {
123
+ if (index >= args.length) {
124
+ throw new Error(`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`);
125
+ }
126
+ arg = args[index];
127
+ } else {
128
+ if (!parameterNames) {
129
+ throw new Error(`Expected arguments to be passed as an array`);
130
+ }
131
+ const name = parameterNames[index];
132
+ arg = args[name];
133
+ if (arg == null) {
134
+ throw new Error(`Parameter ${name} is required`);
135
+ }
136
+ }
137
+ index += 1;
138
+ if (typeof arg === "function" || (0, import_transactions.isArgument)(arg)) {
139
+ normalizedArgs.push(arg);
140
+ continue;
141
+ }
142
+ const type = argTypes[i];
143
+ const bcsType = getPureBcsSchema(type);
144
+ if (bcsType) {
145
+ const bytes = bcsType.serialize(arg);
146
+ normalizedArgs.push((tx) => tx.pure(bytes));
147
+ continue;
148
+ } else if (typeof arg === "string") {
149
+ normalizedArgs.push((tx) => tx.object(arg));
150
+ continue;
151
+ }
152
+ throw new Error(`Invalid argument ${stringify(arg)} for type ${type}`);
153
+ }
154
+ return normalizedArgs;
155
+ }
156
+ var MoveStruct = class extends import_bcs.BcsStruct {
157
+ };
158
+ var MoveTuple = class extends import_bcs.BcsTuple {
159
+ };
160
+ function stringify(val) {
161
+ if (typeof val === "object") {
162
+ return JSON.stringify(val, (val2) => val2);
163
+ }
164
+ if (typeof val === "bigint") {
165
+ return val.toString();
166
+ }
167
+ return val;
168
+ }
169
+
170
+ // src/generated/yield_usdb/yield_usdb.ts
171
+ var import_bcs8 = require("@mysten/sui/bcs");
172
+
173
+ // src/generated/yield_usdb/deps/sui/object.ts
174
+ var import_bcs2 = require("@mysten/sui/bcs");
175
+ var $moduleName = "0x2::object";
176
+ var UID = new MoveStruct({ name: `${$moduleName}::UID`, fields: {
177
+ id: import_bcs2.bcs.Address
178
+ } });
179
+
180
+ // src/generated/yield_usdb/deps/sui/balance.ts
181
+ var import_bcs3 = require("@mysten/sui/bcs");
182
+ var $moduleName2 = "0x2::balance";
183
+ var Balance = new MoveStruct({ name: `${$moduleName2}::Balance`, fields: {
184
+ value: import_bcs3.bcs.u64()
185
+ } });
186
+ var Supply = new MoveStruct({ name: `${$moduleName2}::Supply`, fields: {
187
+ value: import_bcs3.bcs.u64()
188
+ } });
189
+
190
+ // src/generated/yield_usdb/deps/sui/coin.ts
191
+ var $moduleName3 = "0x2::coin";
192
+ var TreasuryCap = new MoveStruct({ name: `${$moduleName3}::TreasuryCap`, fields: {
193
+ id: UID,
194
+ total_supply: Supply
195
+ } });
196
+
197
+ // src/generated/yield_usdb/deps/bucket_v2_framework/account.ts
198
+ var import_bcs4 = require("@mysten/sui/bcs");
199
+ var $moduleName4 = "bucket_v2_framework::account";
200
+ var Account = new MoveStruct({ name: `${$moduleName4}::Account`, fields: {
201
+ id: UID,
202
+ alias: import_bcs4.bcs.option(import_bcs4.bcs.string())
203
+ } });
204
+
205
+ // src/generated/yield_usdb/buffer.ts
206
+ var import_bcs6 = require("@mysten/sui/bcs");
207
+
208
+ // src/generated/yield_usdb/deps/bucket_v2_framework/double.ts
209
+ var import_bcs5 = require("@mysten/sui/bcs");
210
+ var $moduleName5 = "bucket_v2_framework::double";
211
+ var Double = new MoveStruct({ name: `${$moduleName5}::Double`, fields: {
212
+ value: import_bcs5.bcs.u256()
213
+ } });
214
+
215
+ // src/generated/yield_usdb/buffer.ts
216
+ var $moduleName6 = "@local-pkg/yield_usdb.move::buffer";
217
+ var Buffer2 = new MoveStruct({ name: `${$moduleName6}::Buffer`, fields: {
218
+ balance: Balance,
219
+ flow_rate: Double,
220
+ timestamp: import_bcs6.bcs.u64()
221
+ } });
222
+
223
+ // src/generated/yield_usdb/deps/sui/vec_set.ts
224
+ var import_bcs7 = require("@mysten/sui/bcs");
225
+ var $moduleName7 = "0x2::vec_set";
226
+ function VecSet(...typeParameters) {
227
+ return new MoveStruct({ name: `${$moduleName7}::VecSet<${typeParameters[0].name}>`, fields: {
228
+ contents: import_bcs7.bcs.vector(typeParameters[0])
229
+ } });
230
+ }
231
+
232
+ // src/generated/yield_usdb/yield_usdb.ts
233
+ var $moduleName8 = "@local-pkg/yield_usdb.move::yield_usdb";
234
+ var Created = new MoveStruct({ name: `${$moduleName8}::Created`, fields: {
235
+ vault_id: import_bcs8.bcs.Address,
236
+ max_lp_supply: import_bcs8.bcs.u64(),
237
+ abstract_address: import_bcs8.bcs.Address
238
+ } });
239
+ var MaxSupplyUpdated = new MoveStruct({ name: `${$moduleName8}::MaxSupplyUpdated`, fields: {
240
+ vault_id: import_bcs8.bcs.Address,
241
+ previous_max_lp_supply: import_bcs8.bcs.u64(),
242
+ current_max_lp_supply: import_bcs8.bcs.u64()
243
+ } });
244
+ var Minted = new MoveStruct({ name: `${$moduleName8}::Minted`, fields: {
245
+ vault_id: import_bcs8.bcs.Address,
246
+ usdb_amount: import_bcs8.bcs.u64(),
247
+ lp_amount: import_bcs8.bcs.u64()
248
+ } });
249
+ var Burned = new MoveStruct({ name: `${$moduleName8}::Burned`, fields: {
250
+ vault_id: import_bcs8.bcs.Address,
251
+ lp_amount: import_bcs8.bcs.u64(),
252
+ usdb_amount: import_bcs8.bcs.u64()
253
+ } });
254
+ var Claimed = new MoveStruct({ name: `${$moduleName8}::Claimed`, fields: {
255
+ vault_id: import_bcs8.bcs.Address,
256
+ reward_type: import_bcs8.bcs.string(),
257
+ reward_amount: import_bcs8.bcs.u64()
258
+ } });
259
+ var Collected = new MoveStruct({ name: `${$moduleName8}::Collected`, fields: {
260
+ vault_id: import_bcs8.bcs.Address,
261
+ usdb_amount: import_bcs8.bcs.u64()
262
+ } });
263
+ var YieldVault = new MoveStruct({ name: `${$moduleName8}::YieldVault`, fields: {
264
+ id: UID,
265
+ max_lp_supply: import_bcs8.bcs.u64(),
266
+ lp_treasury_cap: TreasuryCap,
267
+ abstract_account: Account,
268
+ buffer: Buffer2,
269
+ managers: VecSet(import_bcs8.bcs.Address),
270
+ versions: VecSet(import_bcs8.bcs.u16())
271
+ } });
272
+ function release(options) {
273
+ const packageAddress = options.package ?? "@local-pkg/yield_usdb.move";
274
+ const argumentsTypes = [
275
+ `${packageAddress}::yield_usdb::YieldVault<${options.typeArguments[0]}, ${options.typeArguments[1]}>`,
276
+ `${packageAddress}::usdb::Treasury`,
277
+ `${packageAddress}::saving::SavingPool<${options.typeArguments[1]}>`,
278
+ "0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock"
279
+ ];
280
+ const parameterNames = ["vault", "treasury", "savingPool"];
281
+ return (tx) => tx.moveCall({
282
+ package: packageAddress,
283
+ module: "yield_usdb",
284
+ function: "release",
285
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
286
+ typeArguments: options.typeArguments
287
+ });
288
+ }
289
+
290
+ // src/generated/stable_layer/stable_layer.ts
291
+ var import_bcs15 = require("@mysten/sui/bcs");
292
+
293
+ // src/generated/stable_layer/deps/std/type_name.ts
294
+ var import_bcs9 = require("@mysten/sui/bcs");
295
+ var $moduleName9 = "std::type_name";
296
+ var TypeName = new MoveStruct({ name: `${$moduleName9}::TypeName`, fields: {
297
+ /**
298
+ * String representation of the type. All types are represented using their source
299
+ * syntax: "u8", "u64", "bool", "address", "vector", and so on for primitive types.
300
+ * Struct types are represented as fully qualified type names; e.g.
301
+ * `00000000000000000000000000000001::string::String` or
302
+ * `0000000000000000000000000000000a::module_name1::type_name1<0000000000000000000000000000000a::module_name2::type_name2<u64>>`
303
+ * Addresses are hex-encoded lowercase values of length ADDRESS_LENGTH (16, 20, or
304
+ * 32 depending on the Move platform)
305
+ */
306
+ name: import_bcs9.bcs.string()
307
+ } });
308
+
309
+ // src/generated/stable_layer/deps/sui/vec_map.ts
310
+ var import_bcs10 = require("@mysten/sui/bcs");
311
+ var $moduleName10 = "0x2::vec_map";
312
+ function Entry(...typeParameters) {
313
+ return new MoveStruct({ name: `${$moduleName10}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`, fields: {
314
+ key: typeParameters[0],
315
+ value: typeParameters[1]
316
+ } });
317
+ }
318
+ function VecMap(...typeParameters) {
319
+ return new MoveStruct({ name: `${$moduleName10}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`, fields: {
320
+ contents: import_bcs10.bcs.vector(Entry(typeParameters[0], typeParameters[1]))
321
+ } });
322
+ }
323
+
324
+ // src/generated/stable_layer/deps/bucket_v2_framework/liability.ts
325
+ var import_bcs11 = require("@mysten/sui/bcs");
326
+ var $moduleName11 = "bucket_v2_framework::liability";
327
+ var Credit = new MoveStruct({ name: `${$moduleName11}::Credit`, fields: {
328
+ value: import_bcs11.bcs.u64()
329
+ } });
330
+ var Debt = new MoveStruct({ name: `${$moduleName11}::Debt`, fields: {
331
+ value: import_bcs11.bcs.u64()
332
+ } });
333
+
334
+ // src/generated/stable_layer/deps/sui/vec_set.ts
335
+ var import_bcs12 = require("@mysten/sui/bcs");
336
+ var $moduleName12 = "0x2::vec_set";
337
+ function VecSet2(...typeParameters) {
338
+ return new MoveStruct({ name: `${$moduleName12}::VecSet<${typeParameters[0].name}>`, fields: {
339
+ contents: import_bcs12.bcs.vector(typeParameters[0])
340
+ } });
341
+ }
342
+
343
+ // src/generated/stable_layer/deps/bucket_v2_framework/sheet.ts
344
+ var $moduleName13 = "bucket_v2_framework::sheet";
345
+ var Entity = new MoveTuple({ name: `${$moduleName13}::Entity`, fields: [TypeName] });
346
+ var Sheet = new MoveStruct({ name: `${$moduleName13}::Sheet`, fields: {
347
+ credits: VecMap(Entity, Credit),
348
+ debts: VecMap(Entity, Debt),
349
+ blacklist: VecSet2(Entity)
350
+ } });
351
+
352
+ // src/generated/stable_layer/deps/sui/object.ts
353
+ var import_bcs13 = require("@mysten/sui/bcs");
354
+ var $moduleName14 = "0x2::object";
355
+ var UID2 = new MoveStruct({ name: `${$moduleName14}::UID`, fields: {
356
+ id: import_bcs13.bcs.Address
357
+ } });
358
+
359
+ // src/generated/stable_layer/deps/sui/balance.ts
360
+ var import_bcs14 = require("@mysten/sui/bcs");
361
+ var $moduleName15 = "0x2::balance";
362
+ var Supply2 = new MoveStruct({ name: `${$moduleName15}::Supply`, fields: {
363
+ value: import_bcs14.bcs.u64()
364
+ } });
365
+
366
+ // src/generated/stable_layer/deps/sui/coin.ts
367
+ var $moduleName16 = "0x2::coin";
368
+ var TreasuryCap2 = new MoveStruct({ name: `${$moduleName16}::TreasuryCap`, fields: {
369
+ id: UID2,
370
+ total_supply: Supply2
371
+ } });
372
+
373
+ // src/generated/stable_layer/stable_layer.ts
374
+ var $moduleName17 = "@local-pkg/stable_factory.move::stable_layer";
375
+ var NewStable = new MoveStruct({ name: `${$moduleName17}::NewStable`, fields: {
376
+ u_type: import_bcs15.bcs.string(),
377
+ stable_type: import_bcs15.bcs.string(),
378
+ factory_id: import_bcs15.bcs.Address,
379
+ factory_cap_id: import_bcs15.bcs.Address
380
+ } });
381
+ var Mint = new MoveStruct({ name: `${$moduleName17}::Mint`, fields: {
382
+ u_type: import_bcs15.bcs.string(),
383
+ stable_type: import_bcs15.bcs.string(),
384
+ mint_amount: import_bcs15.bcs.u64(),
385
+ farm_type: import_bcs15.bcs.string()
386
+ } });
387
+ var Burn = new MoveStruct({ name: `${$moduleName17}::Burn`, fields: {
388
+ u_type: import_bcs15.bcs.string(),
389
+ stable_type: import_bcs15.bcs.string(),
390
+ burn_amount: import_bcs15.bcs.u64(),
391
+ farm_types: import_bcs15.bcs.vector(Entity),
392
+ repayment_amounts: import_bcs15.bcs.vector(import_bcs15.bcs.u64())
393
+ } });
394
+ var StableFactoryEntity = new MoveStruct({ name: `${$moduleName17}::StableFactoryEntity`, fields: {
395
+ dummy_field: import_bcs15.bcs.bool()
396
+ } });
397
+ var StableRegistry = new MoveStruct({ name: `${$moduleName17}::StableRegistry`, fields: {
398
+ id: UID2,
399
+ versions: VecSet2(import_bcs15.bcs.u16()),
400
+ total_supply: import_bcs15.bcs.u64()
401
+ } });
402
+ var AdminCap = new MoveStruct({ name: `${$moduleName17}::AdminCap`, fields: {
403
+ id: UID2
404
+ } });
405
+ var StableFactory = new MoveStruct({ name: `${$moduleName17}::StableFactory`, fields: {
406
+ id: UID2,
407
+ treasury_cap: TreasuryCap2,
408
+ max_supply: import_bcs15.bcs.u64(),
409
+ sheet: Sheet,
410
+ managers: VecSet2(import_bcs15.bcs.Address)
411
+ } });
412
+ var FactoryCap = new MoveStruct({ name: `${$moduleName17}::FactoryCap`, fields: {
413
+ id: UID2,
414
+ factory_id: import_bcs15.bcs.Address
415
+ } });
416
+ function mint(options) {
417
+ const packageAddress = options.package ?? "@local-pkg/stable_factory.move";
418
+ const argumentsTypes = [
419
+ `${packageAddress}::stable_layer::StableRegistry`,
420
+ `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${options.typeArguments[1]}>`
421
+ ];
422
+ const parameterNames = ["registry", "uCoin"];
423
+ return (tx) => tx.moveCall({
424
+ package: packageAddress,
425
+ module: "stable_layer",
426
+ function: "mint",
427
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
428
+ typeArguments: options.typeArguments
429
+ });
430
+ }
431
+ function requestBurn(options) {
432
+ const packageAddress = options.package ?? "@local-pkg/stable_factory.move";
433
+ const argumentsTypes = [
434
+ `${packageAddress}::stable_layer::StableRegistry`,
435
+ `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${options.typeArguments[0]}>`
436
+ ];
437
+ const parameterNames = ["registry", "stableCoin"];
438
+ return (tx) => tx.moveCall({
439
+ package: packageAddress,
440
+ module: "stable_layer",
441
+ function: "request_burn",
442
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
443
+ typeArguments: options.typeArguments
444
+ });
445
+ }
446
+ function fulfillBurn(options) {
447
+ const packageAddress = options.package ?? "@local-pkg/stable_factory.move";
448
+ const argumentsTypes = [
449
+ `${packageAddress}::stable_layer::StableRegistry`,
450
+ `${packageAddress}::sheet::Request<${options.typeArguments[1]}, ${packageAddress}::stable_layer::StableFactoryEntity<${options.typeArguments[0]}, ${options.typeArguments[1]}>>`
451
+ ];
452
+ const parameterNames = ["registry", "burnRequest"];
453
+ return (tx) => tx.moveCall({
454
+ package: packageAddress,
455
+ module: "stable_layer",
456
+ function: "fulfill_burn",
457
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
458
+ typeArguments: options.typeArguments
459
+ });
460
+ }
461
+
462
+ // src/generated/stable_vault_farm/stable_vault_farm.ts
463
+ var import_bcs23 = require("@mysten/sui/bcs");
464
+
465
+ // src/generated/stable_vault_farm/deps/sui/object.ts
466
+ var import_bcs16 = require("@mysten/sui/bcs");
467
+ var $moduleName18 = "0x2::object";
468
+ var UID3 = new MoveStruct({ name: `${$moduleName18}::UID`, fields: {
469
+ id: import_bcs16.bcs.Address
470
+ } });
471
+
472
+ // src/generated/stable_vault_farm/deps/std/type_name.ts
473
+ var import_bcs17 = require("@mysten/sui/bcs");
474
+ var $moduleName19 = "std::type_name";
475
+ var TypeName2 = new MoveStruct({ name: `${$moduleName19}::TypeName`, fields: {
476
+ /**
477
+ * String representation of the type. All types are represented using their source
478
+ * syntax: "u8", "u64", "bool", "address", "vector", and so on for primitive types.
479
+ * Struct types are represented as fully qualified type names; e.g.
480
+ * `00000000000000000000000000000001::string::String` or
481
+ * `0000000000000000000000000000000a::module_name1::type_name1<0000000000000000000000000000000a::module_name2::type_name2<u64>>`
482
+ * Addresses are hex-encoded lowercase values of length ADDRESS_LENGTH (16, 20, or
483
+ * 32 depending on the Move platform)
484
+ */
485
+ name: import_bcs17.bcs.string()
486
+ } });
487
+
488
+ // src/generated/stable_vault_farm/deps/sui/vec_map.ts
489
+ var import_bcs18 = require("@mysten/sui/bcs");
490
+ var $moduleName20 = "0x2::vec_map";
491
+ function Entry2(...typeParameters) {
492
+ return new MoveStruct({ name: `${$moduleName20}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`, fields: {
493
+ key: typeParameters[0],
494
+ value: typeParameters[1]
495
+ } });
496
+ }
497
+ function VecMap2(...typeParameters) {
498
+ return new MoveStruct({ name: `${$moduleName20}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`, fields: {
499
+ contents: import_bcs18.bcs.vector(Entry2(typeParameters[0], typeParameters[1]))
500
+ } });
501
+ }
502
+
503
+ // src/generated/stable_vault_farm/deps/bucket_v2_framework/liability.ts
504
+ var import_bcs19 = require("@mysten/sui/bcs");
505
+ var $moduleName21 = "bucket_v2_framework::liability";
506
+ var Credit2 = new MoveStruct({ name: `${$moduleName21}::Credit`, fields: {
507
+ value: import_bcs19.bcs.u64()
508
+ } });
509
+ var Debt2 = new MoveStruct({ name: `${$moduleName21}::Debt`, fields: {
510
+ value: import_bcs19.bcs.u64()
511
+ } });
512
+
513
+ // src/generated/stable_vault_farm/deps/sui/vec_set.ts
514
+ var import_bcs20 = require("@mysten/sui/bcs");
515
+ var $moduleName22 = "0x2::vec_set";
516
+ function VecSet3(...typeParameters) {
517
+ return new MoveStruct({ name: `${$moduleName22}::VecSet<${typeParameters[0].name}>`, fields: {
518
+ contents: import_bcs20.bcs.vector(typeParameters[0])
519
+ } });
520
+ }
521
+
522
+ // src/generated/stable_vault_farm/deps/bucket_v2_framework/sheet.ts
523
+ var $moduleName23 = "bucket_v2_framework::sheet";
524
+ var Entity2 = new MoveTuple({ name: `${$moduleName23}::Entity`, fields: [TypeName2] });
525
+ var Sheet2 = new MoveStruct({ name: `${$moduleName23}::Sheet`, fields: {
526
+ credits: VecMap2(Entity2, Credit2),
527
+ debts: VecMap2(Entity2, Debt2),
528
+ blacklist: VecSet3(Entity2)
529
+ } });
530
+
531
+ // src/generated/stable_vault_farm/deps/sui/table.ts
532
+ var import_bcs21 = require("@mysten/sui/bcs");
533
+ var $moduleName24 = "0x2::table";
534
+ var Table = new MoveStruct({ name: `${$moduleName24}::Table`, fields: {
535
+ /** the ID of this table */
536
+ id: UID3,
537
+ /** the number of key-value pairs in the table */
538
+ size: import_bcs21.bcs.u64()
539
+ } });
540
+
541
+ // src/generated/stable_vault_farm/deps/sui/balance.ts
542
+ var import_bcs22 = require("@mysten/sui/bcs");
543
+ var $moduleName25 = "0x2::balance";
544
+ var Balance2 = new MoveStruct({ name: `${$moduleName25}::Balance`, fields: {
545
+ value: import_bcs22.bcs.u64()
546
+ } });
547
+
548
+ // src/generated/stable_vault_farm/stable_vault_farm.ts
549
+ var $moduleName26 = "@local-pkg/stable_vault_farm.move::stable_vault_farm";
550
+ var Claim = new MoveStruct({ name: `${$moduleName26}::Claim`, fields: {
551
+ reward_type: import_bcs23.bcs.string(),
552
+ amount: import_bcs23.bcs.u64(),
553
+ claimer: import_bcs23.bcs.Address
554
+ } });
555
+ var StableVaultFarmEntity = new MoveStruct({ name: `${$moduleName26}::StableVaultFarmEntity`, fields: {
556
+ dummy_field: import_bcs23.bcs.bool()
557
+ } });
558
+ var StableVaultFarmWitness = new MoveStruct({ name: `${$moduleName26}::StableVaultFarmWitness`, fields: {
559
+ dummy_field: import_bcs23.bcs.bool()
560
+ } });
561
+ var StableVaultFarm = new MoveStruct({ name: `${$moduleName26}::StableVaultFarm`, fields: {
562
+ id: UID3,
563
+ sheet: Sheet2,
564
+ yield_table: Table,
565
+ u_surplus: Balance2
566
+ } });
567
+ var AdminCap2 = new MoveStruct({ name: `${$moduleName26}::AdminCap`, fields: {
568
+ id: UID3
569
+ } });
570
+ function receive(options) {
571
+ const packageAddress = options.package ?? "@local-pkg/stable_vault_farm.move";
572
+ const argumentsTypes = [
573
+ `${packageAddress}::stable_vault_farm::StableVaultFarm<${options.typeArguments[0]}, ${options.typeArguments[1]}>`,
574
+ `${packageAddress}::sheet::Loan<${options.typeArguments[1]}, ${packageAddress}::stable_layer::StableFactoryEntity<${options.typeArguments[2]}, ${options.typeArguments[1]}>, ${packageAddress}::stable_vault_farm::StableVaultFarmEntity<${options.typeArguments[0]}, ${options.typeArguments[1]}>>`,
575
+ `${packageAddress}::stable_vault::StableVault<${options.typeArguments[0]}, ${options.typeArguments[1]}, ${options.typeArguments[3]}>`,
576
+ `${packageAddress}::usdb::Treasury`,
577
+ `${packageAddress}::pool::Pool<${options.typeArguments[1]}>`,
578
+ `${packageAddress}::saving::SavingPool<${options.typeArguments[4]}>`,
579
+ `${packageAddress}::yield_usdb::YieldVault<${options.typeArguments[3]}, ${options.typeArguments[4]}>`,
580
+ `${packageAddress}::result::PriceResult<${options.typeArguments[1]}>`,
581
+ "0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock"
582
+ ];
583
+ const parameterNames = ["farm", "loan", "stableVault", "usdbTreasury", "psmPool", "savingPool", "yieldVault", "uPrice"];
584
+ return (tx) => tx.moveCall({
585
+ package: packageAddress,
586
+ module: "stable_vault_farm",
587
+ function: "receive",
588
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
589
+ typeArguments: options.typeArguments
590
+ });
591
+ }
592
+ function pay(options) {
593
+ const packageAddress = options.package ?? "@local-pkg/stable_vault_farm.move";
594
+ const argumentsTypes = [
595
+ `${packageAddress}::stable_vault_farm::StableVaultFarm<${options.typeArguments[0]}, ${options.typeArguments[1]}>`,
596
+ `${packageAddress}::sheet::Request<${options.typeArguments[1]}, ${packageAddress}::stable_layer::StableFactoryEntity<${options.typeArguments[2]}, ${options.typeArguments[1]}>>`,
597
+ `${packageAddress}::stable_vault::StableVault<${options.typeArguments[0]}, ${options.typeArguments[1]}, ${options.typeArguments[3]}>`,
598
+ `${packageAddress}::usdb::Treasury`,
599
+ `${packageAddress}::pool::Pool<${options.typeArguments[1]}>`,
600
+ `${packageAddress}::saving::SavingPool<${options.typeArguments[4]}>`,
601
+ `${packageAddress}::yield_usdb::YieldVault<${options.typeArguments[3]}, ${options.typeArguments[4]}>`,
602
+ `${packageAddress}::result::PriceResult<${options.typeArguments[1]}>`,
603
+ "0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock"
604
+ ];
605
+ const parameterNames = ["farm", "request", "stableVault", "usdbTreasury", "psmPool", "savingPool", "yieldVault", "uPrice"];
606
+ return (tx) => tx.moveCall({
607
+ package: packageAddress,
608
+ module: "stable_vault_farm",
609
+ function: "pay",
610
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
611
+ typeArguments: options.typeArguments
612
+ });
613
+ }
614
+ function claim(options) {
615
+ const packageAddress = options.package ?? "@local-pkg/stable_vault_farm.move";
616
+ const argumentsTypes = [
617
+ `${packageAddress}::stable_vault_farm::StableVaultFarm<${options.typeArguments[0]}, ${options.typeArguments[1]}>`,
618
+ `${packageAddress}::stable_layer::StableRegistry`,
619
+ `${packageAddress}::stable_vault::StableVault<${options.typeArguments[0]}, ${options.typeArguments[1]}, ${options.typeArguments[3]}>`,
620
+ `${packageAddress}::usdb::Treasury`,
621
+ `${packageAddress}::saving::SavingPool<${options.typeArguments[4]}>`,
622
+ `${packageAddress}::yield_usdb::YieldVault<${options.typeArguments[3]}, ${options.typeArguments[4]}>`,
623
+ "0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock"
624
+ ];
625
+ const parameterNames = ["farm", "stableRegistry", "stableVault", "usdbTreasury", "savingPool", "yieldVault"];
626
+ return (tx) => tx.moveCall({
627
+ package: packageAddress,
628
+ module: "stable_vault_farm",
629
+ function: "claim",
630
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
631
+ typeArguments: options.typeArguments
632
+ });
633
+ }
634
+
635
+ // src/index.ts
636
+ var import_sdk = require("@bucket-protocol/sdk");
637
+ var StableLayerClient = class {
638
+ constructor(config) {
639
+ this.bucketClient = new import_sdk.BucketClient({ network: config.network });
640
+ this.suiClient = new import_client.SuiClient({ url: (0, import_client.getFullnodeUrl)(config.network) });
641
+ this.sender = config.sender;
642
+ }
643
+ async buildMintTx({
644
+ tx,
645
+ lpToken,
646
+ usdcCoin,
647
+ sender,
648
+ autoTransfer = true
649
+ }) {
650
+ tx.setSender(sender ?? this.sender);
651
+ const [stableCoin, loan] = mint({
652
+ package: STABLE_LAYER_PACKAGE_ID,
653
+ arguments: {
654
+ registry: STABLE_REGISTRY,
655
+ uCoin: usdcCoin
656
+ },
657
+ typeArguments: [
658
+ STABLE_COIN_TYPES[lpToken],
659
+ USDC_TYPE,
660
+ STABLE_VAULT_FARM_ENTITY_TYPE
661
+ ]
662
+ })(tx);
663
+ const [uPrice] = await this.bucketClient.aggregatePrices(tx, {
664
+ coinTypes: [USDC_TYPE]
665
+ });
666
+ const depositResponse = receive({
667
+ package: STABLE_VAULT_FARM_PACKAGE_ID,
668
+ typeArguments: [
669
+ STABLE_LP_TYPE,
670
+ USDC_TYPE,
671
+ STABLE_COIN_TYPES[lpToken],
672
+ YUSDB_TYPE,
673
+ SAVING_TYPE
674
+ ],
675
+ arguments: {
676
+ farm: STABLE_VAULT_FARM,
677
+ loan,
678
+ stableVault: STABLE_VAULT,
679
+ usdbTreasury: this.bucketClient.treasury(tx),
680
+ psmPool: this.getBucketPSMPool(tx),
681
+ savingPool: this.getBucketSavingPool(tx),
682
+ yieldVault: YIELD_VAULT,
683
+ uPrice
684
+ }
685
+ })(tx);
686
+ this.checkResponse({ tx, response: depositResponse, type: "deposit" });
687
+ if (autoTransfer) {
688
+ tx.transferObjects([stableCoin], sender ?? this.sender);
689
+ return;
690
+ } else {
691
+ return stableCoin;
692
+ }
693
+ }
694
+ async buildBurnTx({
695
+ tx,
696
+ lpToken,
697
+ amount,
698
+ all,
699
+ sender,
700
+ autoTransfer = true
701
+ }) {
702
+ tx.setSender(sender ?? this.sender);
703
+ if (!all && !amount) {
704
+ throw new Error("Amount or all must be provided");
705
+ }
706
+ const btcUsdCoin = (0, import_transactions2.coinWithBalance)({
707
+ balance: all ? BigInt(
708
+ (await this.suiClient.getBalance({
709
+ owner: sender ?? this.sender,
710
+ coinType: STABLE_COIN_TYPES[lpToken]
711
+ })).totalBalance
712
+ ) : amount,
713
+ type: STABLE_COIN_TYPES[lpToken]
714
+ });
715
+ this.releaseRewards(tx);
716
+ const burnRequest = requestBurn({
717
+ package: STABLE_LAYER_PACKAGE_ID,
718
+ arguments: {
719
+ registry: STABLE_REGISTRY,
720
+ stableCoin: btcUsdCoin
721
+ },
722
+ typeArguments: [
723
+ STABLE_COIN_TYPES[lpToken],
724
+ USDC_TYPE
725
+ ]
726
+ })(tx);
727
+ const [uPrice] = await this.bucketClient.aggregatePrices(tx, {
728
+ coinTypes: [USDC_TYPE]
729
+ });
730
+ const withdrawResponse = pay({
731
+ package: STABLE_VAULT_FARM_PACKAGE_ID,
732
+ arguments: {
733
+ farm: STABLE_VAULT_FARM,
734
+ request: burnRequest,
735
+ stableVault: STABLE_VAULT,
736
+ usdbTreasury: this.bucketClient.treasury(tx),
737
+ psmPool: this.getBucketPSMPool(tx),
738
+ savingPool: this.getBucketSavingPool(tx),
739
+ yieldVault: YIELD_VAULT,
740
+ uPrice
741
+ },
742
+ typeArguments: [
743
+ STABLE_LP_TYPE,
744
+ USDC_TYPE,
745
+ STABLE_COIN_TYPES[lpToken],
746
+ YUSDB_TYPE,
747
+ SAVING_TYPE
748
+ ]
749
+ })(tx);
750
+ this.checkResponse({ tx, response: withdrawResponse, type: "withdraw" });
751
+ const usdcCoin = fulfillBurn({
752
+ package: STABLE_LAYER_PACKAGE_ID,
753
+ arguments: {
754
+ registry: STABLE_REGISTRY,
755
+ burnRequest
756
+ },
757
+ typeArguments: [
758
+ STABLE_COIN_TYPES[lpToken],
759
+ USDC_TYPE
760
+ ]
761
+ })(tx);
762
+ if (autoTransfer) {
763
+ tx.transferObjects([usdcCoin], sender ?? this.sender);
764
+ return;
765
+ } else {
766
+ return usdcCoin;
767
+ }
768
+ }
769
+ async buildClaimTx({
770
+ tx,
771
+ lpToken,
772
+ sender,
773
+ autoTransfer = true
774
+ }) {
775
+ tx.setSender(sender ?? this.sender);
776
+ this.releaseRewards(tx);
777
+ const [rewardCoin, withdrawResponse] = claim({
778
+ package: STABLE_VAULT_FARM_PACKAGE_ID,
779
+ arguments: {
780
+ stableRegistry: STABLE_REGISTRY,
781
+ farm: STABLE_VAULT_FARM,
782
+ stableVault: STABLE_VAULT,
783
+ usdbTreasury: this.bucketClient.treasury(tx),
784
+ savingPool: this.getBucketSavingPool(tx),
785
+ yieldVault: YIELD_VAULT
786
+ },
787
+ typeArguments: [
788
+ STABLE_LP_TYPE,
789
+ USDC_TYPE,
790
+ STABLE_COIN_TYPES[lpToken],
791
+ YUSDB_TYPE,
792
+ SAVING_TYPE
793
+ ]
794
+ })(tx);
795
+ this.checkResponse({ tx, response: withdrawResponse, type: "withdraw" });
796
+ if (autoTransfer) {
797
+ tx.transferObjects([rewardCoin], sender ?? this.sender);
798
+ return;
799
+ } else {
800
+ return rewardCoin;
801
+ }
802
+ }
803
+ async getTotalSupply() {
804
+ const result = await this.suiClient.getObject({
805
+ id: STABLE_REGISTRY,
806
+ options: {
807
+ showContent: true
808
+ }
809
+ });
810
+ const content = result.data?.content;
811
+ return content?.fields?.total_supply;
812
+ }
813
+ async getTotalSupplyByCoinName(coinName) {
814
+ const result = await this.suiClient.getDynamicFieldObject({
815
+ parentId: STABLE_REGISTRY,
816
+ name: {
817
+ type: "0x1::type_name::TypeName",
818
+ value: STABLE_COIN_TYPES[coinName]
819
+ }
820
+ });
821
+ const content = result.data?.content;
822
+ return content?.fields?.treasury_cap?.fields?.total_supply?.fields?.value;
823
+ }
824
+ getBucketSavingPool(tx) {
825
+ return this.bucketClient.savingPoolObj(tx, {
826
+ lpType: SAVING_TYPE
827
+ });
828
+ }
829
+ getBucketPSMPool(tx) {
830
+ return this.bucketClient.psmPoolObj(tx, {
831
+ coinType: USDC_TYPE
832
+ });
833
+ }
834
+ checkResponse({
835
+ tx,
836
+ response,
837
+ type
838
+ }) {
839
+ if (type === "deposit") {
840
+ return this.bucketClient.checkDepositResponse(tx, {
841
+ lpType: SAVING_TYPE,
842
+ depositResponse: response
843
+ });
844
+ } else {
845
+ return this.bucketClient.checkWithdrawResponse(tx, {
846
+ lpType: SAVING_TYPE,
847
+ withdrawResponse: response
848
+ });
849
+ }
850
+ }
851
+ releaseRewards(tx) {
852
+ const depositResponse = release({
853
+ package: YIELD_USDB_PACKAGE_ID,
854
+ arguments: {
855
+ vault: YIELD_VAULT,
856
+ treasury: this.bucketClient.treasury(tx),
857
+ savingPool: this.bucketClient.savingPoolObj(tx, {
858
+ lpType: SAVING_TYPE
859
+ })
860
+ },
861
+ typeArguments: [YUSDB_TYPE, SAVING_TYPE]
862
+ })(tx);
863
+ this.bucketClient.checkDepositResponse(tx, {
864
+ depositResponse,
865
+ lpType: SAVING_TYPE
866
+ });
867
+ }
868
+ };
869
+ // Annotate the CommonJS export names for ESM import in node:
870
+ 0 && (module.exports = {
871
+ StableLayerClient
872
+ });
873
+ //# sourceMappingURL=index.cjs.map