@scallop-io/sui-scallop-sdk 2.1.3-merge-split-ve-sca-alpha.1 → 2.1.3-merge-split-ve-sca-alpha.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "2.1.3-merge-split-ve-sca-alpha.1",
3
+ "version": "2.1.3-merge-split-ve-sca-alpha.3",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -1,5 +1,9 @@
1
1
  import { Transaction } from '@mysten/sui/transactions';
2
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
2
+ import {
3
+ normalizeSuiAddress,
4
+ MOVE_STDLIB_ADDRESS,
5
+ SuiTxBlock as SuiKitTxBlock,
6
+ } from '@scallop-io/sui-kit';
3
7
  import { ScallopBuilder } from 'src/models';
4
8
  import {
5
9
  GenerateLoyaltyProgramNormalMethod,
@@ -18,6 +22,7 @@ const generateLoyaltyProgramNormalMethod: GenerateLoyaltyProgramNormalMethod =
18
22
  };
19
23
 
20
24
  const veScaProgramIds = {
25
+ object: builder.address.get('vesca.object'),
21
26
  protocolConfig: builder.address.get('vesca.config'),
22
27
  veScaTable: builder.address.get('vesca.table'),
23
28
  subsTable: builder.address.get('vesca.subsTable'),
@@ -39,7 +44,7 @@ const generateLoyaltyProgramNormalMethod: GenerateLoyaltyProgramNormalMethod =
39
44
  );
40
45
  },
41
46
  claimVeScaLoyaltyReward: (veScaKey) => {
42
- return builder.moveCall(
47
+ const optionVeScaKey = builder.moveCall(
43
48
  txBlock,
44
49
  `${veScaLoyaltyProgramIds.pkgId}::ve_sca_reward::redeem_reward`,
45
50
  [
@@ -50,6 +55,17 @@ const generateLoyaltyProgramNormalMethod: GenerateLoyaltyProgramNormalMethod =
50
55
  veScaProgramIds.subsTable,
51
56
  ]
52
57
  );
58
+
59
+ // Extract from option
60
+ const veScaKeyType = `${veScaProgramIds.object}::ve_sca::VeScaKey`;
61
+ const rewardVeScaKey = builder.moveCall(
62
+ txBlock,
63
+ `${normalizeSuiAddress(MOVE_STDLIB_ADDRESS)}::option::destroy_some`,
64
+ [optionVeScaKey],
65
+ [veScaKeyType]
66
+ );
67
+
68
+ return rewardVeScaKey;
53
69
  },
54
70
  };
55
71
  };
@@ -248,9 +248,14 @@ const generateQuickVeScaMethod: GenerateVeScaQuickMethod = ({
248
248
  txBlock,
249
249
  }) => {
250
250
  return {
251
- lockScaQuick: async (amountOrCoin, lockPeriodInDays, autoCheck = true) => {
251
+ lockScaQuick: async (
252
+ amountOrCoin,
253
+ lockPeriodInDays,
254
+ veScaKey,
255
+ autoCheck = true
256
+ ) => {
252
257
  const sender = requireSender(txBlock);
253
- const veSca = await requireVeSca(builder, txBlock);
258
+ const veSca = await requireVeSca(builder, txBlock, veScaKey);
254
259
 
255
260
  let scaCoin: TransactionObjectArgument | SuiObjectArg | undefined =
256
261
  undefined;
@@ -308,15 +308,15 @@ export const TEST_ADDRESSES: AddressesInterface = {
308
308
  '0x574a11f8a0fbaa05b8f559cb65634e8eb20f26b1ec29e7d58de9167f3cedd0f7',
309
309
  },
310
310
  veScaLoyaltyProgram: {
311
- id: '0x7e95dc10fb96ffb2341f664926417b0fb261c9f3dc417344d2a3b11a2f5bb812',
311
+ id: '0xbee5585c16275e582ad595f0bb0c0895ea97fb3f06e7a47779c98effcf756df7',
312
312
  object:
313
- '0x7e95dc10fb96ffb2341f664926417b0fb261c9f3dc417344d2a3b11a2f5bb812',
313
+ '0xbee5585c16275e582ad595f0bb0c0895ea97fb3f06e7a47779c98effcf756df7',
314
314
  adminCap:
315
- '0x4fc52ce8aab57eaa154d9ee42e9d8ecb7add6176d19ff65ebac59bf196b12de8',
315
+ '0xcf17d2d40926226695cbf18ae11d792c74c0dc5419e8259bfa415c3c629a28a9',
316
316
  veScaRewardPool:
317
- '0x59025ec74adfcde1e0d793ff432fa0281f47fe4239aa8811430f10307292eca4',
317
+ '0x8fbcc04c1dc1e0f71c6bbec61761beb2aba07e070751b3e43eeee05ccaca97d5',
318
318
  veScaRewardTableId:
319
- '0xbfa64d2dcd45c9dee92b8c0e052954c05bd687b4e3b132ace9c1f6d6cf619eba',
319
+ '0x51a7c365d58435562a2d72de2c8b78679bc81c345222ef1d9e0fbeca1e365f14',
320
320
  },
321
321
  scoin: {
322
322
  id: '0x826a4934bee9487e558eed603cf42f30cdc4321d6f31083930791b95f903b9f9',
@@ -1,5 +1,6 @@
1
1
  import { SuiObjectData } from '@mysten/sui/client';
2
2
  import BigNumber from 'bignumber.js';
3
+ import { MAX_LOCK_DURATION } from 'src/constants';
3
4
  import { ScallopQuery } from 'src/models';
4
5
  import { LoyaltyProgramInfo, VeScaLoyaltyProgramInfo } from 'src/types';
5
6
  import { z as zod } from 'zod';
@@ -121,13 +122,15 @@ export const getVeScaLoyaltyProgramInformations = async (
121
122
 
122
123
  const result: VeScaLoyaltyProgramInfo = {
123
124
  pendingVeScaReward: 0,
125
+ pendingScaReward: 0,
124
126
  totalPoolReward: 0,
125
127
  isClaimEnabled,
126
128
  };
127
129
 
130
+ let reserveVeSca;
128
131
  // calculate totalPoolreward from reserveVeScaKey
129
132
  if (reserveVeScaKey) {
130
- const reserveVeSca = await query.getVeSca(reserveVeScaKey);
133
+ reserveVeSca = await query.getVeSca(reserveVeScaKey);
131
134
  result.totalPoolReward = reserveVeSca?.currentVeScaBalance ?? 0;
132
135
  }
133
136
 
@@ -151,8 +154,18 @@ export const getVeScaLoyaltyProgramInformations = async (
151
154
 
152
155
  if (userRewardObject?.data?.content?.dataType !== 'moveObject') return result;
153
156
  const userRewardFields = userRewardObject.data.content.fields;
154
- result.pendingVeScaReward = userVeScaRewardFieldsZod.parse(
157
+ result.pendingScaReward = userVeScaRewardFieldsZod.parse(
155
158
  userRewardFields
156
159
  ) as UserVeScaRewardFields;
160
+
161
+ const remainingLockPeriodInMilliseconds = Math.max(
162
+ (reserveVeSca?.unlockAt ?? 0) - Date.now(),
163
+ 0
164
+ );
165
+
166
+ result.pendingVeScaReward =
167
+ result.pendingScaReward *
168
+ (Math.floor(remainingLockPeriodInMilliseconds / 1000) / MAX_LOCK_DURATION);
169
+
157
170
  return result;
158
171
  };
@@ -53,6 +53,7 @@ export type VeScaQuickMethods = {
53
53
  lockScaQuick(
54
54
  amountOrCoin?: SuiObjectArg | number,
55
55
  lockPeriodInDays?: number,
56
+ veScaKey?: SuiObjectArg,
56
57
  autoCheck?: boolean
57
58
  ): Promise<void>;
58
59
  extendLockPeriodQuick: (
@@ -6,6 +6,7 @@ export type LoyaltyProgramInfo = {
6
6
 
7
7
  export type VeScaLoyaltyProgramInfo = {
8
8
  pendingVeScaReward: number;
9
+ pendingScaReward: number;
9
10
  totalPoolReward: number;
10
11
  isClaimEnabled: boolean;
11
12
  };