Skip to content

Commit 808bd0e

Browse files
committed
whitelist js updates
1 parent 7ed136d commit 808bd0e

File tree

5 files changed

+212
-142
lines changed

5 files changed

+212
-142
lines changed

packages/hyperverse-evm-whitelist/source/environment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {
22
isEvm,
33
Blockchain,
44
BlockchainEvm,
5-
useHyperverse,
65
EvmEnvironment,
6+
NetworkConfig,
77
} from '@decentology/hyperverse';
88
import Whitelist from '../artifacts/contracts/Whitelist.sol/Whitelist.json';
99
import WhitelistFactory from '../artifacts/contracts/WhitelistFactory.sol/WhitelistFactory.json';
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export { useWhitelist } from './useWhitelist';
22
export { Provider } from './Provider';
3+
export const ModuleName = 'Whitelist';
4+
export { WhitelistLibrary } from './library/WhitelistLibrary';
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
import { HyperverseConfig } from '@decentology/hyperverse'
2-
import { BaseLibrary, getProvider } from '@decentology/hyperverse-evm'
3-
import { ethers } from 'ethers'
4-
import { getEnvironment } from '../environment'
5-
import { MetaData } from '../types'
1+
import { HyperverseConfig } from '@decentology/hyperverse';
2+
import { BaseLibrary, getProvider } from '@decentology/hyperverse-evm';
3+
import { ethers } from 'ethers';
4+
import { getEnvironment } from '../environment';
5+
import { MerkleTree } from 'merkletreejs';
6+
import keccak256 from 'keccak256';
67

78
export type WhitelistLibraryType = Awaited<ReturnType<typeof WhitelistLibrary>>;
8-
export async function WhitelistLibrary(
9-
hyperverse: HyperverseConfig,
10-
providerOrSigner?: ethers.providers.Provider | ethers.Signer
11-
){
12-
13-
const {FactoryABI, factoryAddress, ContractABI} = getEnvironment(
14-
hyperverse.blockchain?.name!,
15-
hyperverse.network
16-
);
17-
189

19-
if (!providerOrSigner) {
20-
providerOrSigner = getProvider(hyperverse.network);
21-
}
10+
export async function WhitelistLibrary(
11+
hyperverse: HyperverseConfig,
12+
providerOrSigner?: ethers.providers.Provider | ethers.Signer
13+
) {
14+
const { FactoryABI, factoryAddress, ContractABI } = getEnvironment(
15+
hyperverse.blockchain?.name!,
16+
hyperverse.network
17+
);
2218

23-
const base = await BaseLibrary(hyperverse, factoryAddress!, FactoryABI, ContractABI, providerOrSigner);
19+
if (!providerOrSigner) {
20+
providerOrSigner = getProvider(hyperverse.network);
21+
}
2422

23+
const base = await BaseLibrary(
24+
hyperverse,
25+
factoryAddress!,
26+
FactoryABI,
27+
ContractABI,
28+
providerOrSigner
29+
);
2530

26-
const errors = (err: any) => {
27-
if (!base.factoryContract?.signer) {
31+
const errors = (err: any) => {
32+
if (!base.factoryContract?.signer) {
2833
throw new Error('Please connect your wallet!');
2934
}
3035

@@ -33,11 +38,138 @@ export async function WhitelistLibrary(
3338
}
3439

3540
throw err;
36-
}
41+
};
42+
43+
return {
44+
...base,
45+
getTotalTenants: async () => {
46+
try {
47+
const tenantCount = await base.factoryContract.tenantCounter();
48+
return tenantCount.toNumber();
49+
} catch (err) {
50+
throw err;
51+
}
52+
},
53+
getWhitelistedAddresses: async () => {
54+
try {
55+
const addresses = await base.proxyContract?.whitelistedAddresses();
56+
return addresses;
57+
} catch (error) {
58+
throw error;
59+
}
60+
},
61+
getAddressesClaimed: async () => {
62+
try {
63+
const addresses = await base.proxyContract?.addressesClaimed();
64+
return addresses;
65+
} catch (error) {
66+
throw error;
67+
}
68+
},
69+
isWhitelisted: async (account: string) => {
70+
try {
71+
const check = await base.proxyContract?.whitelistedAddresses(account);
72+
return check;
73+
} catch (error) {
74+
throw error;
75+
}
76+
},
77+
isWhitelistedMerkle: async (account: string) => {
78+
try {
79+
const addresses = await base.proxyContract?.whitelistedAddresses();
80+
const leafNodes = addresses.map((address: string) => keccak256(address));
81+
const tree = new MerkleTree(leafNodes, keccak256, { sortPairs: true });
82+
83+
const check = await base.proxyContract?.checkMerkleWhitelist(
84+
account,
85+
tree.getHexProof(keccak256(account))
86+
);
87+
return check;
88+
} catch (error) {
89+
throw error;
90+
}
91+
},
92+
hasClaimed: async (address: string) => {
93+
try {
94+
const check = await base.proxyContract?.addressesClaimed(address);
95+
return check;
96+
} catch (error) {
97+
throw error;
98+
}
99+
},
100+
active: async () => {
101+
try {
102+
const active = await base.proxyContract?.active();
103+
return active;
104+
} catch (error) {
105+
throw error;
106+
}
107+
},
108+
whitelist: async () => {
109+
try {
110+
const txn = await base.proxyContract?.getWhitelisted();
111+
return txn;
112+
} catch (error) {
113+
throw error;
114+
}
115+
},
116+
claimWhitelist: async (account: string) => {
117+
try {
118+
const addresses = await base.proxyContract?.whitelistedAddresses();
119+
const leafNodes = addresses.map((address: string) => keccak256(address));
120+
const tree = new MerkleTree(leafNodes, keccak256, { sortPairs: true });
37121

122+
const txn = await base.proxyContract?.claimWhitelist(
123+
account,
124+
tree.getHexProof(keccak256(account))
125+
);
126+
return txn;
127+
} catch (error) {
128+
throw error;
129+
}
130+
},
38131

39-
return {
40-
...base,
41-
}
132+
//Admin Functionality
133+
setMerkleRoot: async (root: string) => {
134+
try {
135+
const txn = await base.proxyContract?.updateMerkleRoot(root);
136+
return txn;
137+
} catch (error) {
138+
throw error;
139+
}
140+
},
42141

43-
}
142+
activateClaiming: async () => {
143+
try {
144+
const txn = await base.proxyContract?.activateWhitelistClaiming();
145+
return txn;
146+
} catch (error) {
147+
throw error;
148+
}
149+
},
150+
deactivateClaiming: async () => {
151+
try {
152+
const txn = await base.proxyContract?.deactivateWhitelistClaiming();
153+
return txn;
154+
} catch (error) {
155+
throw error;
156+
}
157+
},
158+
authorizeOperator: async (operator: string) => {
159+
try {
160+
const txn = await base.proxyContract?.authorizeOperator(operator);
161+
return txn;
162+
} catch (error) {
163+
throw error;
164+
}
165+
},
166+
revokeOperator: async (operator: string) => {
167+
try {
168+
const txn = await base.proxyContract?.revokeOperator(operator);
169+
return txn;
170+
} catch (error) {
171+
throw error;
172+
}
173+
},
174+
};
175+
}

0 commit comments

Comments
 (0)