From 95d480bce77fa576ef26c95a5d08f2d9a76b0b2e Mon Sep 17 00:00:00 2001 From: Jaxcoder Date: Fri, 9 Feb 2024 09:21:33 -0500 Subject: [PATCH] updates --- src/create-dummy-recipients.ts | 217 ++++++++++++++++++++------------- src/create-pool.ts | 4 +- src/create-profile.ts | 2 +- 3 files changed, 135 insertions(+), 88 deletions(-) diff --git a/src/create-dummy-recipients.ts b/src/create-dummy-recipients.ts index 9a0e97b..d1b4688 100644 --- a/src/create-dummy-recipients.ts +++ b/src/create-dummy-recipients.ts @@ -2,44 +2,66 @@ import * as dotenv from "dotenv"; import { ethers } from "ethers"; import registry from "../abi/Registry.json"; import readline from "readline"; -import { Registry, SQFSuperFluidStrategy } from "@allo-team/allo-v2-sdk"; +import { + DonationVotingMerkleDistributionStrategy, + Registry, + RegistryAbi, +} from "@allo-team/allo-v2-sdk"; import { privateKeyToAccount } from "viem/accounts"; +import { + createPublicClient, + http, + createWalletClient, + defineChain, + Abi, +} from "viem"; +import { decodeEventFromReceipt } from "./utils"; dotenv.config(); const randomNonce = Math.floor(Math.random() * 100000000 - 100000) + 100000; +const chainId = Number(process.env.CHAIN_ID); +const rpc = process.env.RPC_URL as string; +const chain = defineChain({ + id: chainId, + name: "Development 1", + network: "dev1", + nativeCurrency: { + decimals: 18, + name: "Ether", + symbol: "ETH", + }, + rpcUrls: { + default: { http: [rpc] }, + public: { http: [rpc] }, + }, + blockExplorers: { + default: { + name: "dev1", + url: "", + }, + }, +}); // ================== Config ================== -const poolId = 13; +const poolId = 7; const profiles = [ { nonce: randomNonce + 10000000021, name: "Test Profile 1", - metadata: [0, "Test Metadata"], // 0 = NO PROTOCOL, 1 = IPFS + metadata: { + protocol: BigInt(1), + pointer: "bafkreif3wuuv4wqp4i5tfwlrnyogtujmhnn6jmoihr5yekaydhsaw2x6oy", + }, // 0 = NO PROTOCOL, 1 = IPFS members: [], }, - { - nonce: randomNonce + 10000000022, - name: "Test Profile 2", - metadata: [0, "Test Metadata"], // 0 = NO PROTOCOL, 1 = IPFS - members: [], - }, - // { - // nonce: randomNonce + 10000000023, - // name: "Test Profile 3", - // metadata: [0, "Test Metadata"], // 0 = NO PROTOCOL, 1 = IPFS - // members: [], - // }, // { - // nonce: randomNonce + 10000000024, - // name: "Test Profile 4", - // metadata: [0, "Test Metadata"], // 0 = NO PROTOCOL, 1 = IPFS - // members: [], - // }, - // { - // nonce: randomNonce + 10000000025, - // name: "Test Profile 5", - // metadata: [0, "Test Metadata"], // 0 = NO PROTOCOL, 1 = IPFS + // nonce: randomNonce + 10000000022, + // name: "Test Profile 2", + // metadata: { + // protocol: BigInt(1), + // pointer: "bafkreiakgpfq3psade5hmcnk3nrls7eame5yma4n6yfh6d3bvqwqke4rry", + // }, // 0 = NO PROTOCOL, 1 = IPFS // members: [], // }, ]; @@ -48,107 +70,132 @@ const profiles = [ const recipients: { recipientId: `0x${string}` | string; accepted: boolean }[] = []; -const chainId = Number(process.env.CHAIN_ID); -const rpc = process.env.RPC_URL as string; - const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); +const strategy = new DonationVotingMerkleDistributionStrategy({ + chain: chainId, + rpc, + poolId, +}); + async function main() { // Wait 10 blocks for re-org protection - const provider = new ethers.providers.JsonRpcProvider( - process.env.RPC_URL as string - ); + const client = createPublicClient({ + chain, + transport: http(rpc), + }); - const signer = new ethers.Wallet( - process.env.SIGNER_PRIVATE_KEY as string, - provider - ); + const walletClient = createWalletClient({ + chain, + transport: http(rpc), + }); const account = privateKeyToAccount( process.env.SIGNER_PRIVATE_KEY as `0x${string}` ); - const registryContract = new ethers.Contract( - process.env.ALLO_REGISTRY_ADDRESS as string, - registry.abi, - signer - ); - - const owner = signer.address; + // const registryContract = new ethers.Contract( + // process.env.ALLO_REGISTRY_ADDRESS as string, + // registry.abi, + // signer + // ); const registryInstance = new Registry({ chain: chainId, }); - const sqfStrategy = new SQFSuperFluidStrategy({ - chain: chainId, - poolId: poolId, - }); - rl.question( - `Do you want to proceed with address ${signer.address}? (y/n): `, + `Do you want to proceed with address ${account.address}? (y/n): `, async (answer) => { if (answer.toLowerCase() === "y") { for (let i = 0; i < profiles.length; i++) { const { nonce, name, metadata, members } = profiles[i]; - const staticCallResult = - await registryContract.callStatic.createProfile( - nonce, - name, - metadata, - owner, - members - ); - - console.log("Create Profile:", staticCallResult.toString()); - - const createTx = await registryContract.createProfile( + + console.log("Creating profile with:", { nonce, name, metadata, - owner, - members - ); + members, + }); - console.log("Waiting for confirmation..."); + const registerData = await registryInstance.createProfile({ + nonce, + name, + metadata, + owner: account.address, + members, + }); - await createTx.wait(); + const txHash = await walletClient.sendTransaction({ + account, + to: registerData.to, + data: registerData.data, + value: BigInt(registerData.value), + }); - console.log( - `\x1b[32mProfile successfully created: ${staticCallResult.toString()}\x1b[0m` - ); + const txReceipt = await client.waitForTransactionReceipt({ + hash: txHash, + }); - console.log("Creating dummy recipients..."); + const profileCreatedEvent: any = decodeEventFromReceipt({ + abi: RegistryAbi as Abi, + receipt: txReceipt, + event: "ProfileCreated", + }); - const pr = await registryInstance.getProfileById( - staticCallResult.toString() + const profileId = profileCreatedEvent["profileId"]; + const anchor = profileCreatedEvent["anchor"]; + + console.log("Profile ID 1", profileId); + console.log("Anchor 1", anchor); + + // register the recipient + const registerRecipientData = strategy.getRegisterRecipientData( + { + registryAnchor: anchor as `0x${string}`, + recipientAddress: account.address, + metadata: { + protocol: BigInt(1), + pointer: "bafkreiakgpfq3psade5hmcnk3nrls7eame5yma4n6yfh6d3bvqwqke4rry", + }, + } ); - const registerArgs = await sqfStrategy.getRegisterRecipientData({ - registryAnchor: pr.anchor as `0x${string}`, - recipientAddress: owner as `0x${string}`, - metadata: { - protocol: BigInt(0), - pointer: "dummy data", - }, + const registerRecipientTxHash = await walletClient.sendTransaction({ + account, + to: registerRecipientData.to, + data: registerRecipientData.data, + value: BigInt(registerRecipientData.value), }); - const registerTx = await signer.sendTransaction({ - to: registerArgs.to, - data: registerArgs.data, - }); + console.log("Waiting for confirmation...", registerRecipientTxHash); - console.log("Waiting for confirmation..."); + const registerRecipientTxReceipt = + await client.waitForTransactionReceipt({ + hash: registerRecipientTxHash, + }); + + console.log( + "Register recipient receipt: ", + registerRecipientTxReceipt + ); + + const recipientRegisteredEvent: any = decodeEventFromReceipt({ + abi: RegistryAbi as Abi, + receipt: registerRecipientTxReceipt, + event: "Registered", + }); - await registerTx.wait(); + console.log("Register recipient event: ", recipientRegisteredEvent); - console.log("Dummy recipient created: ", pr.anchor); + console.log("Profile ID 2", profileId); + console.log("Anchor 2", anchor); recipients.push({ - recipientId: pr.anchor, + recipientId: anchor, accepted: true, }); } diff --git a/src/create-pool.ts b/src/create-pool.ts index 08df352..79e38f8 100644 --- a/src/create-pool.ts +++ b/src/create-pool.ts @@ -31,12 +31,12 @@ const strategy = new DonationVotingMerkleDistributionStrategy({ // ================= Config ================== -const profileId = "0x3df47d6ad73f128b2f02e38602d2aabe9189f27780c176406e3009955ef3c2a3"; +const profileId = "0x61d4db78579550c2fb9688b4f472b0fcd0a398175713275ddd46c5c15c463a2f"; const strategyAddress = "0xD13ec67938B5E9Cb05A05D8e160daF02Ed5ea9C9"; const amount = BigInt(0) as bigint; const poolMetadata = { protocol: BigInt(1), // 0 = NONE, 1 = IPFS - pointer: "bafkreia45cpoutbvd6vdoffz724bpydyjgc3ercz674i7ivixelgzf4vpy", // IPFS CID + pointer: "QmTMmP2sUFjVAcgE4J8bc5NYygSgdqhvsDupivnSregCkT", // IPFS CID }; const poolToken = NATIVE; const managers = ["0x8C180840fcBb90CE8464B4eCd12ab0f840c6647C"] diff --git a/src/create-profile.ts b/src/create-profile.ts index a0d0723..bfe51f9 100644 --- a/src/create-profile.ts +++ b/src/create-profile.ts @@ -7,7 +7,7 @@ dotenv.config(); // ================== Config ================== const profile = { - nonce: 1000000002, + nonce: 1000040002, name: "Test Profile", metadata: [1, "bafkreia45cpoutbvd6vdoffz724bpydyjgc3ercz674i7ivixelgzf4vpy"], // 0 = NO PROTOCOL, 1 = IPFS members: [],