@totems/evm 1.0.8 → 1.0.9

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": "@totems/evm",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "description": "Totems EVM smart contracts for building modular token systems",
6
6
  "author": "nsjames",
@@ -24,7 +24,8 @@
24
24
  "contracts/**/*.sol",
25
25
  "interfaces/**/*.sol",
26
26
  "mods/**/*.sol",
27
- "test/**/*"
27
+ "test/**/*",
28
+ "artifacts/**/*"
28
29
  ],
29
30
  "exports": {
30
31
  "./test/helpers": {
package/test/helpers.d.ts CHANGED
@@ -37,8 +37,14 @@ export declare const Hook: {
37
37
  export declare const setupTotemsTest: (minBaseFee?: bigint, burnedFee?: bigint) => Promise<{
38
38
  viem: any;
39
39
  publicClient: any;
40
- market: any;
41
- totems: any;
40
+ market: {
41
+ address: any;
42
+ abi: any;
43
+ };
44
+ totems: {
45
+ address: any;
46
+ abi: any;
47
+ };
42
48
  accounts: any;
43
49
  proxyModSeller: any;
44
50
  proxyMod: any;
package/test/helpers.ts CHANGED
@@ -1,5 +1,37 @@
1
1
  import {network} from "hardhat";
2
- import { keccak256, toBytes, decodeErrorResult, Abi } from "viem";
2
+ import { keccak256, toBytes, decodeErrorResult, Abi, getContract } from "viem";
3
+ import { readFileSync, existsSync } from "fs";
4
+ import { dirname, join } from "path";
5
+ import { fileURLToPath } from "url";
6
+
7
+ // Detect if we're running from the package or the main project
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ const packageArtifactsDir = join(__dirname, '..', 'artifacts');
10
+ const isPackage = existsSync(join(packageArtifactsDir, 'ProxyMod.json'));
11
+
12
+ function loadArtifact(name: string) {
13
+ if (isPackage) {
14
+ // Load from package artifacts
15
+ const path = join(packageArtifactsDir, `${name}.json`);
16
+ return JSON.parse(readFileSync(path, 'utf-8'));
17
+ }
18
+ // Load from main project's hardhat artifacts
19
+ const paths: Record<string, string> = {
20
+ 'ProxyMod': 'artifacts/contracts/mods/ProxyMod.sol/ProxyMod.json',
21
+ 'ModMarket': 'artifacts/contracts/market/ModMarket.sol/ModMarket.json',
22
+ 'Totems': 'artifacts/contracts/totems/Totems.sol/Totems.json',
23
+ 'ITotems': 'artifacts/contracts/interfaces/ITotems.sol/ITotems.json',
24
+ 'IMarket': 'artifacts/contracts/interfaces/IMarket.sol/IMarket.json',
25
+ };
26
+ const path = join(__dirname, '..', paths[name]);
27
+ return JSON.parse(readFileSync(path, 'utf-8'));
28
+ }
29
+
30
+ const ProxyModArtifact = loadArtifact('ProxyMod');
31
+ const ModMarketArtifact = loadArtifact('ModMarket');
32
+ const TotemsArtifact = loadArtifact('Totems');
33
+ const ITotemsArtifact = loadArtifact('ITotems');
34
+ const IMarketArtifact = loadArtifact('IMarket');
3
35
 
4
36
  export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
5
37
 
@@ -155,30 +187,56 @@ export const Hook = {
155
187
  export const setupTotemsTest = async (minBaseFee: bigint = MIN_BASE_FEE, burnedFee: bigint = BURNED_FEE) => {
156
188
  const { viem } = await network.connect() as any;
157
189
  const publicClient = await viem.getPublicClient();
158
- // @ts-ignore
159
190
  const walletClient = await viem.getWalletClient();
160
191
 
161
192
  const addresses = await walletClient.getAddresses();
162
193
  const proxyModInitializer = addresses[0];
163
- const proxyMod = await viem.deployContract("ProxyMod", [
164
- proxyModInitializer
165
- ]);
166
-
167
- let market = await viem.deployContract("ModMarket", [minBaseFee, burnedFee]);
168
- let totems:any = await viem.deployContract("Totems", [
169
- market.address,
170
- proxyMod.address,
171
- minBaseFee,
172
- burnedFee,
173
- ]);
174
-
175
-
176
- // using these to validate the interfaces
177
- totems = await viem.getContractAt("ITotems", totems.address);
178
- // @ts-ignore
179
- market = await viem.getContractAt("IMarket", market.address);
180
- // initialize proxy mod
181
- await proxyMod.write.initialize([totems.address, market.address], { account: proxyModInitializer });
194
+
195
+ // Deploy using pre-built artifacts from the package
196
+ const proxyModHash = await walletClient.deployContract({
197
+ abi: ProxyModArtifact.abi,
198
+ bytecode: ProxyModArtifact.bytecode,
199
+ args: [proxyModInitializer],
200
+ account: proxyModInitializer,
201
+ });
202
+ const proxyModReceipt = await publicClient.waitForTransactionReceipt({ hash: proxyModHash });
203
+ const proxyMod = getContract({
204
+ address: proxyModReceipt.contractAddress!,
205
+ abi: ProxyModArtifact.abi,
206
+ client: { public: publicClient, wallet: walletClient },
207
+ }) as any;
208
+
209
+ const marketHash = await walletClient.deployContract({
210
+ abi: ModMarketArtifact.abi,
211
+ bytecode: ModMarketArtifact.bytecode,
212
+ args: [minBaseFee, burnedFee],
213
+ account: proxyModInitializer,
214
+ });
215
+ const marketReceipt = await publicClient.waitForTransactionReceipt({ hash: marketHash });
216
+
217
+ const totemsHash = await walletClient.deployContract({
218
+ abi: TotemsArtifact.abi,
219
+ bytecode: TotemsArtifact.bytecode,
220
+ args: [marketReceipt.contractAddress!, proxyModReceipt.contractAddress!, minBaseFee, burnedFee],
221
+ account: proxyModInitializer,
222
+ });
223
+ const totemsReceipt = await publicClient.waitForTransactionReceipt({ hash: totemsHash });
224
+
225
+ // Use interface ABIs for the contract instances
226
+ const totems = getContract({
227
+ address: totemsReceipt.contractAddress!,
228
+ abi: ITotemsArtifact.abi,
229
+ client: { public: publicClient, wallet: walletClient },
230
+ });
231
+
232
+ const market = getContract({
233
+ address: marketReceipt.contractAddress!,
234
+ abi: IMarketArtifact.abi,
235
+ client: { public: publicClient, wallet: walletClient },
236
+ });
237
+
238
+ // Initialize proxy mod
239
+ await proxyMod.write.initialize([totemsReceipt.contractAddress!, marketReceipt.contractAddress!], { account: proxyModInitializer });
182
240
 
183
241
  return {
184
242
  viem,