@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/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +14 -14
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
- package/src/builders/loyaltyProgramBuilder.ts +18 -2
- package/src/builders/vescaBuilder.ts +7 -2
- package/src/constants/testAddress.ts +5 -5
- package/src/queries/loyaltyProgramQuery.ts +15 -2
- package/src/types/builder/vesca.ts +1 -0
- package/src/types/query/loyaltyProgram.ts +1 -0
package/package.json
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
-
import {
|
|
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
|
-
|
|
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 (
|
|
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: '
|
|
311
|
+
id: '0xbee5585c16275e582ad595f0bb0c0895ea97fb3f06e7a47779c98effcf756df7',
|
|
312
312
|
object:
|
|
313
|
-
'
|
|
313
|
+
'0xbee5585c16275e582ad595f0bb0c0895ea97fb3f06e7a47779c98effcf756df7',
|
|
314
314
|
adminCap:
|
|
315
|
-
'
|
|
315
|
+
'0xcf17d2d40926226695cbf18ae11d792c74c0dc5419e8259bfa415c3c629a28a9',
|
|
316
316
|
veScaRewardPool:
|
|
317
|
-
'
|
|
317
|
+
'0x8fbcc04c1dc1e0f71c6bbec61761beb2aba07e070751b3e43eeee05ccaca97d5',
|
|
318
318
|
veScaRewardTableId:
|
|
319
|
-
'
|
|
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
|
-
|
|
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.
|
|
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
|
};
|