Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
codenamejason committed Feb 9, 2024
1 parent c96446b commit 95d480b
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 88 deletions.
217 changes: 132 additions & 85 deletions src/create-dummy-recipients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
// },
];
Expand All @@ -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,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/create-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/create-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down

0 comments on commit 95d480b

Please sign in to comment.