@aintivirus-ai/mixer-sdk 1.0.0 → 1.0.1
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/evm/index.d.ts +7 -3
- package/dist/evm/index.js +38 -16
- package/dist/hooks/useAdmin.d.ts +0 -2
- package/dist/hooks/useAdmin.js +11 -51
- package/dist/hooks/useAintiVirus.js +1 -1
- package/dist/hooks/useClaim.js +1 -1
- package/dist/hooks/useDeploy.js +1 -1
- package/dist/hooks/useDeposit.js +1 -1
- package/dist/hooks/useStake.js +1 -1
- package/dist/hooks/useView.js +1 -1
- package/dist/hooks/useWithdraw.js +1 -1
- package/dist/solana/idl/aintivirus_factory.json +2951 -0
- package/dist/solana/idl/aintivirus_mixer.json +615 -0
- package/dist/solana/idl/aintivirus_staking.json +989 -0
- package/dist/solana/index.d.ts +60 -14
- package/dist/solana/index.js +310 -235
- package/dist/solana/types/aintivirus_factory.d.ts +2957 -0
- package/dist/solana/types/aintivirus_factory.js +2 -0
- package/dist/solana/types/aintivirus_mixer.d.ts +621 -0
- package/dist/solana/types/aintivirus_mixer.js +2 -0
- package/dist/solana/types/aintivirus_staking.d.ts +995 -0
- package/dist/solana/types/aintivirus_staking.js +2 -0
- package/dist/types/index.d.ts +43 -5
- package/dist/types/index.js +1 -0
- package/dist/utils/proof.js +35 -10
- package/package.json +9 -5
package/dist/evm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Contract, Signer, Provider } from "ethers";
|
|
2
|
-
import { AssetMode, WithdrawalProof, TransactionResult,
|
|
2
|
+
import { AssetMode, WithdrawalProof, TransactionResult, EVMStakeSeason, EVMStakerRecord } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* EVM SDK for AintiVirus Mixer
|
|
5
5
|
*/
|
|
@@ -84,14 +84,18 @@ export declare class AintiVirusEVM {
|
|
|
84
84
|
* Get staking contract address
|
|
85
85
|
*/
|
|
86
86
|
getStakingAddress(): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Start a new stake season
|
|
89
|
+
*/
|
|
90
|
+
startStakeSeason(): Promise<TransactionResult>;
|
|
87
91
|
/**
|
|
88
92
|
* Get stake season information
|
|
89
93
|
*/
|
|
90
|
-
getStakeSeason(seasonId: bigint): Promise<
|
|
94
|
+
getStakeSeason(seasonId: bigint): Promise<EVMStakeSeason>;
|
|
91
95
|
/**
|
|
92
96
|
* Get staker record
|
|
93
97
|
*/
|
|
94
|
-
getStakerRecord(address: string): Promise<
|
|
98
|
+
getStakerRecord(address: string): Promise<EVMStakerRecord>;
|
|
95
99
|
/**
|
|
96
100
|
* Check if user has claimed rewards for a season
|
|
97
101
|
*/
|
package/dist/evm/index.js
CHANGED
|
@@ -11,7 +11,9 @@ class AintiVirusEVM {
|
|
|
11
11
|
constructor(factoryAddress, tokenAddress, signerOrProvider) {
|
|
12
12
|
// Check if it's a Signer by checking for provider property
|
|
13
13
|
// In ethers v6, Signer has a provider property, Provider doesn't
|
|
14
|
-
const isSigner = signerOrProvider &&
|
|
14
|
+
const isSigner = signerOrProvider &&
|
|
15
|
+
"provider" in signerOrProvider &&
|
|
16
|
+
signerOrProvider.provider !== null;
|
|
15
17
|
this.provider = isSigner
|
|
16
18
|
? signerOrProvider.provider
|
|
17
19
|
: signerOrProvider;
|
|
@@ -235,24 +237,45 @@ class AintiVirusEVM {
|
|
|
235
237
|
return await this.factory.staking();
|
|
236
238
|
}
|
|
237
239
|
/**
|
|
238
|
-
*
|
|
240
|
+
* Start a new stake season
|
|
239
241
|
*/
|
|
240
|
-
async
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
async startStakeSeason() {
|
|
243
|
+
if (!this.signer) {
|
|
244
|
+
throw new Error("Signer required for transactions");
|
|
245
|
+
}
|
|
246
|
+
const tx = await this.factory.startStakeSeason();
|
|
247
|
+
const receipt = await tx.wait();
|
|
244
248
|
return {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
totalStakedEthAmount: season.totalStakedEthAmount,
|
|
249
|
-
totalStakedTokenAmount: season.totalStakedTokenAmount,
|
|
250
|
-
totalRewardEthAmount: season.totalRewardEthAmount,
|
|
251
|
-
totalRewardTokenAmount: season.totalRewardTokenAmount,
|
|
252
|
-
totalEthWeightValue: season.totalEthWeightValue,
|
|
253
|
-
totalTokenWeightValue: season.totalTokenWeightValue,
|
|
249
|
+
txHash: receipt.hash,
|
|
250
|
+
blockNumber: receipt.blockNumber,
|
|
251
|
+
blockTime: (await this.provider.getBlock(receipt.blockNumber))?.timestamp,
|
|
254
252
|
};
|
|
255
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Get stake season information
|
|
256
|
+
*/
|
|
257
|
+
async getStakeSeason(seasonId) {
|
|
258
|
+
try {
|
|
259
|
+
const stakingAddress = await this.getStakingAddress();
|
|
260
|
+
const staking = new ethers_1.Contract(stakingAddress, AintiVirusEVM.STAKING_ABI, this.provider);
|
|
261
|
+
const season = await staking.stakeSeasons(seasonId);
|
|
262
|
+
return {
|
|
263
|
+
seasonId: season.seasonId,
|
|
264
|
+
startTimestamp: season.startTimestamp,
|
|
265
|
+
endTimestamp: season.endTimestamp,
|
|
266
|
+
totalStakedEthAmount: season.totalStakedEthAmount,
|
|
267
|
+
totalStakedTokenAmount: season.totalStakedTokenAmount,
|
|
268
|
+
totalRewardEthAmount: season.totalRewardEthAmount,
|
|
269
|
+
totalRewardTokenAmount: season.totalRewardTokenAmount,
|
|
270
|
+
totalEthWeightValue: season.totalEthWeightValue,
|
|
271
|
+
totalTokenWeightValue: season.totalTokenWeightValue,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
276
|
+
throw new Error(`Stake season ${seasonId} not found. Original error: ${errorMsg}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
256
279
|
/**
|
|
257
280
|
* Get staker record
|
|
258
281
|
*/
|
|
@@ -353,7 +376,6 @@ AintiVirusEVM.FACTORY_ABI = [
|
|
|
353
376
|
"function setStakingSeasonPeriod(uint256 _period)",
|
|
354
377
|
"function startStakeSeason()",
|
|
355
378
|
"function setVerifier(address _verifier)",
|
|
356
|
-
"function setHasher(address _hasher)",
|
|
357
379
|
"event MixerDeployed(address indexed mixer, uint256 indexed mode, uint256 indexed amount)",
|
|
358
380
|
"event Deposit(bytes32 indexed commitment, uint32 leafIndex, uint256 timestamp)",
|
|
359
381
|
"event Withdrawal(address to, bytes32 nullifierHash)",
|
package/dist/hooks/useAdmin.d.ts
CHANGED
|
@@ -23,8 +23,6 @@ export interface UseAdminReturn {
|
|
|
23
23
|
setFeeRate: (chainType: ChainType, feeRate: bigint) => Promise<TransactionResult>;
|
|
24
24
|
setStakingSeasonPeriod: (chainType: ChainType, period: bigint) => Promise<TransactionResult>;
|
|
25
25
|
startStakeSeason: (chainType: ChainType) => Promise<TransactionResult>;
|
|
26
|
-
setVerifier: (chainType: ChainType, verifierAddress: string) => Promise<TransactionResult>;
|
|
27
|
-
setHasher: (chainType: ChainType, hasherAddress: string) => Promise<TransactionResult>;
|
|
28
26
|
isEVMReady: boolean;
|
|
29
27
|
isSolanaReady: boolean;
|
|
30
28
|
}
|
package/dist/hooks/useAdmin.js
CHANGED
|
@@ -57,7 +57,7 @@ function useAdmin(config) {
|
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
59
|
try {
|
|
60
|
-
return new solana_1.AintiVirusSolana(config.
|
|
60
|
+
return new solana_1.AintiVirusSolana(config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
63
|
console.error("Failed to initialize AintiVirusSolana:", error);
|
|
@@ -84,7 +84,8 @@ function useAdmin(config) {
|
|
|
84
84
|
return {
|
|
85
85
|
txHash: receipt.hash,
|
|
86
86
|
blockNumber: receipt.blockNumber,
|
|
87
|
-
blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))
|
|
87
|
+
blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))
|
|
88
|
+
?.timestamp,
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
else if (chainType === types_1.ChainType.SOLANA) {
|
|
@@ -106,7 +107,8 @@ function useAdmin(config) {
|
|
|
106
107
|
return {
|
|
107
108
|
txHash: receipt.hash,
|
|
108
109
|
blockNumber: receipt.blockNumber,
|
|
109
|
-
blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))
|
|
110
|
+
blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))
|
|
111
|
+
?.timestamp,
|
|
110
112
|
};
|
|
111
113
|
}
|
|
112
114
|
else if (chainType === types_1.ChainType.SOLANA) {
|
|
@@ -128,58 +130,18 @@ function useAdmin(config) {
|
|
|
128
130
|
return {
|
|
129
131
|
txHash: receipt.hash,
|
|
130
132
|
blockNumber: receipt.blockNumber,
|
|
131
|
-
blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))
|
|
133
|
+
blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))
|
|
134
|
+
?.timestamp,
|
|
132
135
|
};
|
|
133
136
|
}
|
|
134
137
|
else if (chainType === types_1.ChainType.SOLANA) {
|
|
135
138
|
if (!solanaSDK) {
|
|
136
139
|
throw new Error("Solana SDK not initialized");
|
|
137
140
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const setVerifier = (0, react_1.useCallback)(async (chainType, verifierAddress) => {
|
|
143
|
-
if (chainType === types_1.ChainType.EVM) {
|
|
144
|
-
if (!evmSDK) {
|
|
145
|
-
throw new Error("EVM SDK not initialized");
|
|
146
|
-
}
|
|
147
|
-
const factory = evmSDK.getFactory();
|
|
148
|
-
const tx = await factory.setVerifier(verifierAddress);
|
|
149
|
-
const receipt = await tx.wait();
|
|
150
|
-
return {
|
|
151
|
-
txHash: receipt.hash,
|
|
152
|
-
blockNumber: receipt.blockNumber,
|
|
153
|
-
blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))?.timestamp,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
else if (chainType === types_1.ChainType.SOLANA) {
|
|
157
|
-
if (!solanaSDK) {
|
|
158
|
-
throw new Error("Solana SDK not initialized");
|
|
159
|
-
}
|
|
160
|
-
return solanaSDK.setVerifier(verifierAddress);
|
|
161
|
-
}
|
|
162
|
-
throw new Error(`Unsupported chain type: ${chainType}`);
|
|
163
|
-
}, [evmSDK, solanaSDK]);
|
|
164
|
-
const setHasher = (0, react_1.useCallback)(async (chainType, hasherAddress) => {
|
|
165
|
-
if (chainType === types_1.ChainType.EVM) {
|
|
166
|
-
if (!evmSDK) {
|
|
167
|
-
throw new Error("EVM SDK not initialized");
|
|
168
|
-
}
|
|
169
|
-
const factory = evmSDK.getFactory();
|
|
170
|
-
const tx = await factory.setHasher(hasherAddress);
|
|
171
|
-
const receipt = await tx.wait();
|
|
172
|
-
return {
|
|
173
|
-
txHash: receipt.hash,
|
|
174
|
-
blockNumber: receipt.blockNumber,
|
|
175
|
-
blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))?.timestamp,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
else if (chainType === types_1.ChainType.SOLANA) {
|
|
179
|
-
if (!solanaSDK) {
|
|
180
|
-
throw new Error("Solana SDK not initialized");
|
|
181
|
-
}
|
|
182
|
-
return solanaSDK.setHasher(hasherAddress);
|
|
141
|
+
// Get current season and increment by 1 for next season
|
|
142
|
+
const currentSeason = await solanaSDK.getCurrentStakeSeason();
|
|
143
|
+
const nextSeasonId = currentSeason + 1n;
|
|
144
|
+
return solanaSDK.startStakeSeason(nextSeasonId);
|
|
183
145
|
}
|
|
184
146
|
throw new Error(`Unsupported chain type: ${chainType}`);
|
|
185
147
|
}, [evmSDK, solanaSDK]);
|
|
@@ -187,8 +149,6 @@ function useAdmin(config) {
|
|
|
187
149
|
setFeeRate,
|
|
188
150
|
setStakingSeasonPeriod,
|
|
189
151
|
startStakeSeason,
|
|
190
|
-
setVerifier,
|
|
191
|
-
setHasher,
|
|
192
152
|
isEVMReady,
|
|
193
153
|
isSolanaReady,
|
|
194
154
|
};
|
|
@@ -60,7 +60,7 @@ function useAintiVirus(config) {
|
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
62
62
|
try {
|
|
63
|
-
return new solana_1.AintiVirusSolana(config.
|
|
63
|
+
return new solana_1.AintiVirusSolana(config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
66
66
|
console.error("Failed to initialize AintiVirusSolana:", error);
|
package/dist/hooks/useClaim.js
CHANGED
|
@@ -56,7 +56,7 @@ function useClaim(config) {
|
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
try {
|
|
59
|
-
return new solana_1.AintiVirusSolana(config.
|
|
59
|
+
return new solana_1.AintiVirusSolana(config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
62
62
|
console.error("Failed to initialize AintiVirusSolana:", error);
|
package/dist/hooks/useDeploy.js
CHANGED
|
@@ -56,7 +56,7 @@ function useDeploy(config) {
|
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
try {
|
|
59
|
-
return new solana_1.AintiVirusSolana(config.
|
|
59
|
+
return new solana_1.AintiVirusSolana(config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
62
62
|
console.error("Failed to initialize AintiVirusSolana:", error);
|
package/dist/hooks/useDeposit.js
CHANGED
|
@@ -57,7 +57,7 @@ function useDeposit(config) {
|
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
59
|
try {
|
|
60
|
-
return new solana_1.AintiVirusSolana(config.
|
|
60
|
+
return new solana_1.AintiVirusSolana(config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
63
|
console.error("Failed to initialize AintiVirusSolana:", error);
|
package/dist/hooks/useStake.js
CHANGED
|
@@ -56,7 +56,7 @@ function useStake(config) {
|
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
try {
|
|
59
|
-
return new solana_1.AintiVirusSolana(config.
|
|
59
|
+
return new solana_1.AintiVirusSolana(config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
62
62
|
console.error("Failed to initialize AintiVirusSolana:", error);
|
package/dist/hooks/useView.js
CHANGED
|
@@ -62,7 +62,7 @@ function useView(config) {
|
|
|
62
62
|
if (!config.solanaWallet) {
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
|
-
return new solana_1.AintiVirusSolana(config.
|
|
65
|
+
return new solana_1.AintiVirusSolana(config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
|
|
66
66
|
}
|
|
67
67
|
catch (error) {
|
|
68
68
|
console.error("Failed to initialize AintiVirusSolana:", error);
|
|
@@ -56,7 +56,7 @@ function useWithdraw(config) {
|
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
try {
|
|
59
|
-
return new solana_1.AintiVirusSolana(config.
|
|
59
|
+
return new solana_1.AintiVirusSolana(config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
62
62
|
console.error("Failed to initialize AintiVirusSolana:", error);
|