zo-sdk 0.1.25 → 0.1.27
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/dist/abstract/BaseAPI.cjs.map +1 -1
- package/dist/abstract/BaseAPI.d.cts +2 -2
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +2 -2
- package/dist/abstract/BaseAPI.d.mts.map +1 -1
- package/dist/abstract/BaseAPI.mjs.map +1 -1
- package/dist/consts/deployments-shared-mainnet.json +50 -0
- package/dist/consts/deployments-shared-testnet.json +45 -0
- package/dist/consts/index.cjs +13 -0
- package/dist/consts/index.cjs.map +1 -1
- package/dist/consts/index.d.cts +6 -1
- package/dist/consts/index.d.cts.map +1 -1
- package/dist/consts/index.d.mts +6 -1
- package/dist/consts/index.d.mts.map +1 -1
- package/dist/consts/index.mjs +12 -0
- package/dist/consts/index.mjs.map +1 -1
- package/dist/implementations/SLPAPI.cjs +84 -0
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +12 -0
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +12 -0
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +84 -0
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +79 -2
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts +6 -0
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts +6 -0
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +79 -2
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +4 -13
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +4 -13
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.cjs +6 -3
- package/dist/implementations/USDZDataAPI.cjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/USDZDataAPI.mjs +6 -3
- package/dist/implementations/USDZDataAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.cjs +4 -13
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.mjs +4 -13
- package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.cjs +6 -2
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.mjs +6 -2
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +103 -25
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +13 -3
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +13 -3
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +103 -25
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs +89 -4
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +6 -3
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +6 -3
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs +89 -4
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +2 -2
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +2 -2
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/slp.d.cts +1 -0
- package/dist/interfaces/slp.d.cts.map +1 -1
- package/dist/interfaces/slp.d.mts +1 -0
- package/dist/interfaces/slp.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +1 -0
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +1 -0
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/dist/oracle.cjs +1 -0
- package/dist/oracle.cjs.map +1 -1
- package/dist/oracle.d.cts +1 -0
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +1 -0
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +2 -1
- package/dist/oracle.mjs.map +1 -1
- package/package.json +9 -9
- package/src/consts/deployments-shared-mainnet.json +50 -0
- package/src/consts/deployments-shared-testnet.json +45 -0
- package/src/consts/index.ts +15 -1
- package/src/implementations/SLPAPI.ts +104 -0
- package/src/implementations/SLPDataAPI.ts +112 -15
- package/src/implementations/USDZAPI.ts +5 -17
- package/src/implementations/USDZDataAPI.ts +11 -5
- package/src/implementations/ZBTCVCAPI.ts +5 -17
- package/src/implementations/ZBTCVCDataAPI.ts +11 -4
- package/src/implementations/ZLPAPI.ts +124 -27
- package/src/implementations/ZLPDataAPI.ts +117 -4
- package/src/interfaces/slp.ts +4 -1
- package/src/interfaces/zlp.ts +1 -0
- package/src/oracle.ts +3 -1
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
IBaseSymbolInfo,
|
|
29
29
|
IBaseVaultInfo,
|
|
30
30
|
IZLPAPI,
|
|
31
|
+
IZLPCredential,
|
|
31
32
|
} from '../interfaces'
|
|
32
33
|
import { joinSymbol } from '../utils'
|
|
33
34
|
import { ZLPDataAPI } from './ZLPDataAPI'
|
|
@@ -45,14 +46,6 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
45
46
|
this.dataAPI = new ZLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
public stake(_lpCoinObjects: string[], _amount: bigint, _pool: string, _tx?: Transaction): Transaction {
|
|
49
|
-
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public unstake(_credentials: IBaseCredential[], _amount: bigint, _pool: string, _tx?: Transaction): Transaction {
|
|
53
|
-
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
49
|
public claimTokenFromSCard(_token: string, _coinObjects: string[], _kioskClient: KioskClient, _kioskCap: KioskOwnerCap, _scard: string): Transaction {
|
|
57
50
|
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
58
51
|
}
|
|
@@ -275,6 +268,110 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
275
268
|
return tx
|
|
276
269
|
}
|
|
277
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Stakes ZLP tokens in ZO staking pools
|
|
273
|
+
*/
|
|
274
|
+
public stake(
|
|
275
|
+
lpCoinObjects: string[],
|
|
276
|
+
amount: bigint,
|
|
277
|
+
pool: string,
|
|
278
|
+
tx?: Transaction,
|
|
279
|
+
): Transaction {
|
|
280
|
+
if (!tx) {
|
|
281
|
+
tx = new Transaction()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const coinObject = this.processCoins(tx, 'zlp', lpCoinObjects)
|
|
285
|
+
const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
|
|
286
|
+
|
|
287
|
+
tx.moveCall({
|
|
288
|
+
target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
|
|
289
|
+
typeArguments: [
|
|
290
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
291
|
+
`${this.consts.coins.sui.module}`,
|
|
292
|
+
],
|
|
293
|
+
arguments: [
|
|
294
|
+
tx.object(pool),
|
|
295
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
296
|
+
depositObject,
|
|
297
|
+
],
|
|
298
|
+
})
|
|
299
|
+
return tx
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Stakes ZLP tokens using coin object only (PTB)
|
|
304
|
+
*/
|
|
305
|
+
public stakeCoinObject(
|
|
306
|
+
coinObject: any,
|
|
307
|
+
pool: string,
|
|
308
|
+
tx?: Transaction,
|
|
309
|
+
): Transaction {
|
|
310
|
+
if (!tx) {
|
|
311
|
+
tx = new Transaction()
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
tx.moveCall({
|
|
315
|
+
target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
|
|
316
|
+
typeArguments: [
|
|
317
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
318
|
+
`${this.consts.coins.sui.module}`,
|
|
319
|
+
],
|
|
320
|
+
arguments: [
|
|
321
|
+
tx.object(pool),
|
|
322
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
323
|
+
coinObject,
|
|
324
|
+
],
|
|
325
|
+
})
|
|
326
|
+
return tx
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Unstakes ZLP tokens from ZO staking pools
|
|
331
|
+
*/
|
|
332
|
+
public unstake(
|
|
333
|
+
credentials: IZLPCredential[],
|
|
334
|
+
amount: bigint,
|
|
335
|
+
pool: string,
|
|
336
|
+
tx?: Transaction,
|
|
337
|
+
): Transaction {
|
|
338
|
+
let unstakeAmount = amount
|
|
339
|
+
if (!tx) {
|
|
340
|
+
tx = new Transaction()
|
|
341
|
+
}
|
|
342
|
+
for (const credential of credentials) {
|
|
343
|
+
const withdrawAmount = (() => {
|
|
344
|
+
const min = (a: bigint, b: bigint) => a < b ? a : b
|
|
345
|
+
return min(unstakeAmount, credential.amount)
|
|
346
|
+
})()
|
|
347
|
+
unstakeAmount -= withdrawAmount
|
|
348
|
+
tx.moveCall({
|
|
349
|
+
target: `${this.sharedConfig.zoStaking.package}::pool::withdraw`,
|
|
350
|
+
typeArguments: [
|
|
351
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
352
|
+
`${this.consts.coins.sui.module}`,
|
|
353
|
+
],
|
|
354
|
+
arguments: [
|
|
355
|
+
tx.object(pool),
|
|
356
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
357
|
+
tx.object(credential.id),
|
|
358
|
+
tx.pure.u64(withdrawAmount),
|
|
359
|
+
],
|
|
360
|
+
})
|
|
361
|
+
if (credential.amount === BigInt(0)) {
|
|
362
|
+
tx.moveCall({
|
|
363
|
+
target: `${this.sharedConfig.zoStaking.package}::pool::clear_empty_credential`,
|
|
364
|
+
typeArguments: [
|
|
365
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
366
|
+
`${this.consts.coins.sui.module}`,
|
|
367
|
+
],
|
|
368
|
+
arguments: [tx.object(credential.id)],
|
|
369
|
+
})
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return tx
|
|
373
|
+
}
|
|
374
|
+
|
|
278
375
|
public async swap(
|
|
279
376
|
fromToken: string,
|
|
280
377
|
toToken: string,
|
|
@@ -1298,15 +1395,15 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
1298
1395
|
}
|
|
1299
1396
|
for (const [i, beneficiary] of beneficiaries.entries()) {
|
|
1300
1397
|
tx.moveCall({
|
|
1301
|
-
target: `${this.
|
|
1398
|
+
target: `${this.sharedConfig.zoLootbox.package}::lootbox::admin_issue_lootbox`,
|
|
1302
1399
|
typeArguments: [module],
|
|
1303
1400
|
arguments: [
|
|
1304
|
-
tx.object(this.
|
|
1401
|
+
tx.object(this.sharedConfig.zoLootbox.adminCap),
|
|
1305
1402
|
tx.pure.u8(tiers[i]),
|
|
1306
1403
|
tx.pure.address(beneficiary),
|
|
1307
1404
|
tx.pure.u64(amounts[i]),
|
|
1308
1405
|
tx.pure.bool(amounts[i] > 0),
|
|
1309
|
-
tx.object(`${this.
|
|
1406
|
+
tx.object(`${this.sharedConfig.zoLootbox.lootboxSettings}`),
|
|
1310
1407
|
],
|
|
1311
1408
|
})
|
|
1312
1409
|
}
|
|
@@ -1327,11 +1424,11 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
1327
1424
|
}
|
|
1328
1425
|
|
|
1329
1426
|
tx.moveCall({
|
|
1330
|
-
target: `${this.
|
|
1427
|
+
target: `${this.sharedConfig.zoLootbox.package}::lootbox::deposit`,
|
|
1331
1428
|
typeArguments: [module],
|
|
1332
1429
|
arguments: [
|
|
1333
|
-
tx.object(this.
|
|
1334
|
-
tx.object(this.
|
|
1430
|
+
tx.object(this.sharedConfig.zoLootbox.adminCap),
|
|
1431
|
+
tx.object(this.sharedConfig.zoLootbox.lootboxTreasury),
|
|
1335
1432
|
depositObject,
|
|
1336
1433
|
],
|
|
1337
1434
|
})
|
|
@@ -1352,11 +1449,11 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
1352
1449
|
}
|
|
1353
1450
|
|
|
1354
1451
|
tx.moveCall({
|
|
1355
|
-
target: `${this.
|
|
1452
|
+
target: `${this.sharedConfig.zoLootbox.package}::lootbox::withdraw`,
|
|
1356
1453
|
typeArguments: [module],
|
|
1357
1454
|
arguments: [
|
|
1358
|
-
tx.object(this.
|
|
1359
|
-
tx.object(this.
|
|
1455
|
+
tx.object(this.sharedConfig.zoLootbox.adminCap),
|
|
1456
|
+
tx.object(this.sharedConfig.zoLootbox.lootboxTreasury),
|
|
1360
1457
|
tx.object(metadata),
|
|
1361
1458
|
tx.pure.u64(amount),
|
|
1362
1459
|
],
|
|
@@ -1378,13 +1475,13 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
1378
1475
|
}
|
|
1379
1476
|
|
|
1380
1477
|
tx.moveCall({
|
|
1381
|
-
target: `${this.
|
|
1478
|
+
target: `${this.sharedConfig.zoLootbox.upgradedPackage}::lootbox::open_lootbox`,
|
|
1382
1479
|
typeArguments: [module],
|
|
1383
1480
|
arguments: [
|
|
1384
|
-
tx.object(`${this.
|
|
1481
|
+
tx.object(`${this.sharedConfig.zoLootbox.lootboxTreasury}`),
|
|
1385
1482
|
tx.object(lootbox),
|
|
1386
1483
|
tx.object(metadata),
|
|
1387
|
-
tx.object(`${this.
|
|
1484
|
+
tx.object(`${this.sharedConfig.zoLootbox.lootboxSettings}`),
|
|
1388
1485
|
],
|
|
1389
1486
|
})
|
|
1390
1487
|
|
|
@@ -1408,18 +1505,18 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
1408
1505
|
|
|
1409
1506
|
for (const [i, beneficiary] of beneficiaries.entries()) {
|
|
1410
1507
|
const moveCallArgs = {
|
|
1411
|
-
target: `${this.
|
|
1508
|
+
target: `${this.sharedConfig.zoLootboxV2.package}::lootbox::admin_issue_lootbox`,
|
|
1412
1509
|
typeArguments: [module],
|
|
1413
1510
|
arguments: [
|
|
1414
|
-
tx.object(this.
|
|
1415
|
-
tx.object(this.
|
|
1511
|
+
tx.object(this.sharedConfig.zoLootboxV2.adminCap),
|
|
1512
|
+
tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
|
|
1416
1513
|
tx.pure.u8(tiers[i]),
|
|
1417
1514
|
tx.pure.address(beneficiary),
|
|
1418
1515
|
tx.pure.u64(amounts[i]),
|
|
1419
1516
|
tx.pure.bool(amounts[i] > 0),
|
|
1420
1517
|
tx.pure.string(titles[i]),
|
|
1421
1518
|
tx.pure.string(descriptions[i]),
|
|
1422
|
-
tx.object(`${this.
|
|
1519
|
+
tx.object(`${this.sharedConfig.zoLootboxV2.lootboxSettings}`),
|
|
1423
1520
|
],
|
|
1424
1521
|
}
|
|
1425
1522
|
|
|
@@ -1441,13 +1538,13 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
1441
1538
|
}
|
|
1442
1539
|
|
|
1443
1540
|
tx.moveCall({
|
|
1444
|
-
target: `${this.
|
|
1541
|
+
target: `${this.sharedConfig.zoLootboxV2.package}::lootbox::open_lootbox`,
|
|
1445
1542
|
typeArguments: [module],
|
|
1446
1543
|
arguments: [
|
|
1447
|
-
tx.object(this.
|
|
1544
|
+
tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
|
|
1448
1545
|
tx.object(lootbox),
|
|
1449
1546
|
tx.object(metadata),
|
|
1450
|
-
tx.object(this.
|
|
1547
|
+
tx.object(this.sharedConfig.zoLootboxV2.lootboxSettings),
|
|
1451
1548
|
],
|
|
1452
1549
|
})
|
|
1453
1550
|
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
IBaseHistoryResponse,
|
|
16
16
|
IBaseStaked,
|
|
17
17
|
IBaseStakePool,
|
|
18
|
+
IZLPCredential,
|
|
18
19
|
IZLPDataAPI,
|
|
19
20
|
IZLPFundingFeeModel,
|
|
20
21
|
IZLPMarketInfo,
|
|
@@ -26,6 +27,7 @@ import type {
|
|
|
26
27
|
IZLPPositionInfo,
|
|
27
28
|
IZLPRebaseFeeModel,
|
|
28
29
|
IZLPReservingFeeModel,
|
|
30
|
+
IZLPStakePool,
|
|
29
31
|
IZLPSymbolConfig,
|
|
30
32
|
IZLPSymbolInfo,
|
|
31
33
|
IZLPVaultInfo,
|
|
@@ -42,12 +44,70 @@ export class ZLPDataAPI extends BaseDataAPI implements IZLPDataAPI {
|
|
|
42
44
|
super(network, provider, apiEndpoint, connectionURL, LPToken.ZLP)
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
public getStaked(
|
|
46
|
-
|
|
47
|
+
public async getStaked(owner: string): Promise<IBaseStaked> {
|
|
48
|
+
let rawCredentialsData: any[] = []
|
|
49
|
+
let queryNextPage = true
|
|
50
|
+
let queryCursor: string | undefined | null
|
|
51
|
+
|
|
52
|
+
const limit = 50
|
|
53
|
+
|
|
54
|
+
while (queryNextPage) {
|
|
55
|
+
const { data, hasNextPage, nextCursor } = await this.provider.getOwnedObjects({
|
|
56
|
+
owner,
|
|
57
|
+
filter: {
|
|
58
|
+
MoveModule: {
|
|
59
|
+
package: this.consts.zoStaking.package,
|
|
60
|
+
module: 'pool',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
options: {
|
|
64
|
+
showType: true,
|
|
65
|
+
showContent: true,
|
|
66
|
+
},
|
|
67
|
+
cursor: queryCursor,
|
|
68
|
+
limit,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
queryNextPage = hasNextPage
|
|
72
|
+
queryCursor = nextCursor!
|
|
73
|
+
if (!data)
|
|
74
|
+
break
|
|
75
|
+
rawCredentialsData = [...rawCredentialsData, ...data]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const pool = await this.getStakePool()
|
|
79
|
+
|
|
80
|
+
// TODO: Update reward coin type once available
|
|
81
|
+
const credentials = rawCredentialsData
|
|
82
|
+
.filter(
|
|
83
|
+
(item: any) =>
|
|
84
|
+
item.data.type ===
|
|
85
|
+
`${this.sharedConfig.zoStaking.package}::pool::Credential<${this.consts.zoCore.package}::zlp::ZLP, 0x2::sui::SUI>`
|
|
86
|
+
).map((item: any) =>
|
|
87
|
+
ZLPDataAPI.parseCredential(item, pool),
|
|
88
|
+
)
|
|
89
|
+
return {
|
|
90
|
+
credentials,
|
|
91
|
+
amount: credentials.reduce(
|
|
92
|
+
(acc: bigint, cur: IZLPCredential) => acc + cur.amount,
|
|
93
|
+
BigInt(0),
|
|
94
|
+
),
|
|
95
|
+
claimable: credentials.reduce(
|
|
96
|
+
(acc: bigint, cur: IZLPCredential) => acc + cur.claimable,
|
|
97
|
+
BigInt(0),
|
|
98
|
+
),
|
|
99
|
+
}
|
|
47
100
|
}
|
|
48
101
|
|
|
49
|
-
public getStakePool(): Promise<
|
|
50
|
-
|
|
102
|
+
public async getStakePool(): Promise<IZLPStakePool> {
|
|
103
|
+
const poolId = this.consts.zoStaking.pools.ZLP
|
|
104
|
+
const raw = await this.provider.getObject({
|
|
105
|
+
id: poolId,
|
|
106
|
+
options: {
|
|
107
|
+
showContent: true,
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
return ZLPDataAPI.parseStakePool(raw)
|
|
51
111
|
}
|
|
52
112
|
|
|
53
113
|
/**
|
|
@@ -907,4 +967,57 @@ export class ZLPDataAPI extends BaseDataAPI implements IZLPDataAPI {
|
|
|
907
967
|
return vaultInfo.unrealisedReservingFeeAmount
|
|
908
968
|
+ (vaultInfo.reservedAmount * reservingFeeModel.multiplier * periods) / 1e18
|
|
909
969
|
}
|
|
970
|
+
|
|
971
|
+
private static parseCredential(raw: any, pool: IZLPStakePool): IZLPCredential {
|
|
972
|
+
const stakedAmount = BigInt(raw.data.content.fields.stake)
|
|
973
|
+
const accRewardPerShare = BigInt(
|
|
974
|
+
raw.data.content.fields.acc_reward_per_share,
|
|
975
|
+
)
|
|
976
|
+
return {
|
|
977
|
+
id: raw.data.objectId,
|
|
978
|
+
lockUntil: parseValue(raw.data.content.fields.lock_until),
|
|
979
|
+
amount: stakedAmount,
|
|
980
|
+
accRewardPerShare,
|
|
981
|
+
claimable:
|
|
982
|
+
((pool.accRewardPerShare - accRewardPerShare) * stakedAmount)
|
|
983
|
+
/ BigInt(1e18),
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
private static parseStakePool(raw: any): IZLPStakePool {
|
|
988
|
+
const content = raw.data.content.fields
|
|
989
|
+
const pool = {
|
|
990
|
+
id: content.id.id,
|
|
991
|
+
enabled: content.enabled,
|
|
992
|
+
lastUpdatedTime: parseValue(content.last_updated_time),
|
|
993
|
+
stakedAmount: BigInt(content.staked_amount),
|
|
994
|
+
reward: BigInt(content.reward_vault),
|
|
995
|
+
startTime: parseValue(content.start_time),
|
|
996
|
+
endTime: parseValue(content.end_time),
|
|
997
|
+
rewardRate: BigInt(content.reward_rate),
|
|
998
|
+
accRewardPerShare: BigInt(content.acc_reward_per_share),
|
|
999
|
+
lockDuration: parseValue(content.lock_duration),
|
|
1000
|
+
}
|
|
1001
|
+
ZLPDataAPI.refreshPool(pool, Math.floor(Date.now() / 1000))
|
|
1002
|
+
return pool
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
private static refreshPool(pool: IZLPStakePool, timestamp: number): void {
|
|
1006
|
+
if (timestamp <= pool.lastUpdatedTime || timestamp < pool.startTime) {
|
|
1007
|
+
return
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
const applicableEndTime = Math.max(pool.endTime, pool.lastUpdatedTime)
|
|
1011
|
+
|
|
1012
|
+
const calculationEndTime = Math.min(timestamp, applicableEndTime)
|
|
1013
|
+
|
|
1014
|
+
if (calculationEndTime > pool.lastUpdatedTime && pool.stakedAmount > BigInt(0) && pool.rewardRate > BigInt(0)) {
|
|
1015
|
+
const timeDiff = BigInt(calculationEndTime - pool.lastUpdatedTime)
|
|
1016
|
+
const rewardAmount = timeDiff * pool.rewardRate
|
|
1017
|
+
const rewardPerShare = (rewardAmount * BigInt(1e18)) / pool.stakedAmount
|
|
1018
|
+
pool.accRewardPerShare += rewardPerShare
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
pool.lastUpdatedTime = calculationEndTime
|
|
1022
|
+
}
|
|
910
1023
|
}
|
package/src/interfaces/slp.ts
CHANGED
|
@@ -56,7 +56,10 @@ export interface ISLPHistory extends IBaseHistory { }
|
|
|
56
56
|
|
|
57
57
|
export interface ISLPStaked extends IBaseStaked { }
|
|
58
58
|
|
|
59
|
-
export interface ISLPStakePool extends IBaseStakePool {
|
|
59
|
+
export interface ISLPStakePool extends IBaseStakePool {
|
|
60
|
+
// SLP-specific stake pool fields to match new staking implementation
|
|
61
|
+
rewardRate?: bigint // Optional for backward compatibility
|
|
62
|
+
}
|
|
60
63
|
|
|
61
64
|
export interface ISLPCredential extends IBaseCredential { }
|
|
62
65
|
|
package/src/interfaces/zlp.ts
CHANGED
package/src/oracle.ts
CHANGED
|
@@ -4,12 +4,13 @@ import type { PriceFeed } from '@pythnetwork/pyth-sui-js'
|
|
|
4
4
|
import { SuiPriceServiceConnection, SuiPythClient } from '@pythnetwork/pyth-sui-js'
|
|
5
5
|
|
|
6
6
|
import type { IConsts, Network } from './consts'
|
|
7
|
-
import { getConsts, getPriceIdToPythFeeder, getPythFeederToId, getPythFeederToPriceId, LPToken } from './consts'
|
|
7
|
+
import { getConsts, getPriceIdToPythFeeder, getPythFeederToId, getPythFeederToPriceId, getSharedConfig, LPToken } from './consts'
|
|
8
8
|
import { createJsonRpcProvider } from './utils'
|
|
9
9
|
|
|
10
10
|
export class OracleAPI {
|
|
11
11
|
network: Network
|
|
12
12
|
consts: IConsts
|
|
13
|
+
sharedConfig: IConsts
|
|
13
14
|
connectionURL: string
|
|
14
15
|
PythFeederToPriceId: Record<string, string>
|
|
15
16
|
PythFeederToId: Record<string, string>
|
|
@@ -27,6 +28,7 @@ export class OracleAPI {
|
|
|
27
28
|
) {
|
|
28
29
|
this.network = network
|
|
29
30
|
this.consts = getConsts(network, lpToken)
|
|
31
|
+
this.sharedConfig = getSharedConfig(network)
|
|
30
32
|
this.connectionURL = connectionURL
|
|
31
33
|
this.PythFeederToPriceId = getPythFeederToPriceId(network)
|
|
32
34
|
this.PythFeederToId = getPythFeederToId(network)
|