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.
Files changed (107) hide show
  1. package/dist/abstract/BaseAPI.cjs.map +1 -1
  2. package/dist/abstract/BaseAPI.d.cts +2 -2
  3. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  4. package/dist/abstract/BaseAPI.d.mts +2 -2
  5. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  6. package/dist/abstract/BaseAPI.mjs.map +1 -1
  7. package/dist/consts/deployments-shared-mainnet.json +50 -0
  8. package/dist/consts/deployments-shared-testnet.json +45 -0
  9. package/dist/consts/index.cjs +13 -0
  10. package/dist/consts/index.cjs.map +1 -1
  11. package/dist/consts/index.d.cts +6 -1
  12. package/dist/consts/index.d.cts.map +1 -1
  13. package/dist/consts/index.d.mts +6 -1
  14. package/dist/consts/index.d.mts.map +1 -1
  15. package/dist/consts/index.mjs +12 -0
  16. package/dist/consts/index.mjs.map +1 -1
  17. package/dist/implementations/SLPAPI.cjs +84 -0
  18. package/dist/implementations/SLPAPI.cjs.map +1 -1
  19. package/dist/implementations/SLPAPI.d.cts +12 -0
  20. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  21. package/dist/implementations/SLPAPI.d.mts +12 -0
  22. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  23. package/dist/implementations/SLPAPI.mjs +84 -0
  24. package/dist/implementations/SLPAPI.mjs.map +1 -1
  25. package/dist/implementations/SLPDataAPI.cjs +79 -2
  26. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  27. package/dist/implementations/SLPDataAPI.d.cts +6 -0
  28. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  29. package/dist/implementations/SLPDataAPI.d.mts +6 -0
  30. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  31. package/dist/implementations/SLPDataAPI.mjs +79 -2
  32. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  33. package/dist/implementations/USDZAPI.cjs +4 -13
  34. package/dist/implementations/USDZAPI.cjs.map +1 -1
  35. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  36. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  37. package/dist/implementations/USDZAPI.mjs +4 -13
  38. package/dist/implementations/USDZAPI.mjs.map +1 -1
  39. package/dist/implementations/USDZDataAPI.cjs +6 -3
  40. package/dist/implementations/USDZDataAPI.cjs.map +1 -1
  41. package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
  42. package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
  43. package/dist/implementations/USDZDataAPI.mjs +6 -3
  44. package/dist/implementations/USDZDataAPI.mjs.map +1 -1
  45. package/dist/implementations/ZBTCVCAPI.cjs +4 -13
  46. package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
  47. package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
  48. package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
  49. package/dist/implementations/ZBTCVCAPI.mjs +4 -13
  50. package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
  51. package/dist/implementations/ZBTCVCDataAPI.cjs +6 -2
  52. package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
  53. package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
  54. package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
  55. package/dist/implementations/ZBTCVCDataAPI.mjs +6 -2
  56. package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
  57. package/dist/implementations/ZLPAPI.cjs +103 -25
  58. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  59. package/dist/implementations/ZLPAPI.d.cts +13 -3
  60. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  61. package/dist/implementations/ZLPAPI.d.mts +13 -3
  62. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  63. package/dist/implementations/ZLPAPI.mjs +103 -25
  64. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  65. package/dist/implementations/ZLPDataAPI.cjs +89 -4
  66. package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
  67. package/dist/implementations/ZLPDataAPI.d.cts +6 -3
  68. package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
  69. package/dist/implementations/ZLPDataAPI.d.mts +6 -3
  70. package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
  71. package/dist/implementations/ZLPDataAPI.mjs +89 -4
  72. package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
  73. package/dist/interfaces/base.d.cts +2 -2
  74. package/dist/interfaces/base.d.cts.map +1 -1
  75. package/dist/interfaces/base.d.mts +2 -2
  76. package/dist/interfaces/base.d.mts.map +1 -1
  77. package/dist/interfaces/slp.d.cts +1 -0
  78. package/dist/interfaces/slp.d.cts.map +1 -1
  79. package/dist/interfaces/slp.d.mts +1 -0
  80. package/dist/interfaces/slp.d.mts.map +1 -1
  81. package/dist/interfaces/zlp.d.cts +1 -0
  82. package/dist/interfaces/zlp.d.cts.map +1 -1
  83. package/dist/interfaces/zlp.d.mts +1 -0
  84. package/dist/interfaces/zlp.d.mts.map +1 -1
  85. package/dist/oracle.cjs +1 -0
  86. package/dist/oracle.cjs.map +1 -1
  87. package/dist/oracle.d.cts +1 -0
  88. package/dist/oracle.d.cts.map +1 -1
  89. package/dist/oracle.d.mts +1 -0
  90. package/dist/oracle.d.mts.map +1 -1
  91. package/dist/oracle.mjs +2 -1
  92. package/dist/oracle.mjs.map +1 -1
  93. package/package.json +9 -9
  94. package/src/consts/deployments-shared-mainnet.json +50 -0
  95. package/src/consts/deployments-shared-testnet.json +45 -0
  96. package/src/consts/index.ts +15 -1
  97. package/src/implementations/SLPAPI.ts +104 -0
  98. package/src/implementations/SLPDataAPI.ts +112 -15
  99. package/src/implementations/USDZAPI.ts +5 -17
  100. package/src/implementations/USDZDataAPI.ts +11 -5
  101. package/src/implementations/ZBTCVCAPI.ts +5 -17
  102. package/src/implementations/ZBTCVCDataAPI.ts +11 -4
  103. package/src/implementations/ZLPAPI.ts +124 -27
  104. package/src/implementations/ZLPDataAPI.ts +117 -4
  105. package/src/interfaces/slp.ts +4 -1
  106. package/src/interfaces/zlp.ts +1 -0
  107. 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.consts.zoLootbox.package}::lootbox::admin_issue_lootbox`,
1398
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::admin_issue_lootbox`,
1302
1399
  typeArguments: [module],
1303
1400
  arguments: [
1304
- tx.object(this.consts.zoLootbox.adminCap),
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.consts.zoLootbox.lootboxSettings}`),
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.consts.zoLootbox.package}::lootbox::deposit`,
1427
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::deposit`,
1331
1428
  typeArguments: [module],
1332
1429
  arguments: [
1333
- tx.object(this.consts.zoLootbox.adminCap),
1334
- tx.object(this.consts.zoLootbox.lootboxTreasury),
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.consts.zoLootbox.package}::lootbox::withdraw`,
1452
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::withdraw`,
1356
1453
  typeArguments: [module],
1357
1454
  arguments: [
1358
- tx.object(this.consts.zoLootbox.adminCap),
1359
- tx.object(this.consts.zoLootbox.lootboxTreasury),
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.consts.zoLootbox.upgradedPackage}::lootbox::open_lootbox`,
1478
+ target: `${this.sharedConfig.zoLootbox.upgradedPackage}::lootbox::open_lootbox`,
1382
1479
  typeArguments: [module],
1383
1480
  arguments: [
1384
- tx.object(`${this.consts.zoLootbox.lootboxTreasury}`),
1481
+ tx.object(`${this.sharedConfig.zoLootbox.lootboxTreasury}`),
1385
1482
  tx.object(lootbox),
1386
1483
  tx.object(metadata),
1387
- tx.object(`${this.consts.zoLootbox.lootboxSettings}`),
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.consts.zoLootboxV2.package}::lootbox::admin_issue_lootbox`,
1508
+ target: `${this.sharedConfig.zoLootboxV2.package}::lootbox::admin_issue_lootbox`,
1412
1509
  typeArguments: [module],
1413
1510
  arguments: [
1414
- tx.object(this.consts.zoLootboxV2.adminCap),
1415
- tx.object(this.consts.zoLootboxV2.lootboxTreasury),
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.consts.zoLootboxV2.lootboxSettings}`),
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.consts.zoLootboxV2.package}::lootbox::open_lootbox`,
1541
+ target: `${this.sharedConfig.zoLootboxV2.package}::lootbox::open_lootbox`,
1445
1542
  typeArguments: [module],
1446
1543
  arguments: [
1447
- tx.object(this.consts.zoLootboxV2.lootboxTreasury),
1544
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
1448
1545
  tx.object(lootbox),
1449
1546
  tx.object(metadata),
1450
- tx.object(this.consts.zoLootboxV2.lootboxSettings),
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(_owner: string): Promise<IBaseStaked> {
46
- throw new Error(`${this.constructor.name}: Method not implemented.`)
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<IBaseStakePool> {
50
- throw new Error(`${this.constructor.name}: Method not implemented.`)
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
  }
@@ -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
 
@@ -60,6 +60,7 @@ export interface IZLPHistory extends IBaseHistory {
60
60
 
61
61
  export interface IZLPStakePool extends IBaseStakePool {
62
62
  // ZLP-specific stake pool fields can be added here
63
+ rewardRate: bigint
63
64
  }
64
65
 
65
66
  export interface IZLPCredential extends IBaseCredential {
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)