Skip to content

Instantly share code, notes, and snippets.

@pythonpete32
Created April 24, 2023 10:15
Show Gist options
  • Save pythonpete32/74956133778374d90533e1e506cb4f34 to your computer and use it in GitHub Desktop.
Save pythonpete32/74956133778374d90533e1e506cb4f34 to your computer and use it in GitHub Desktop.
import {CentralizedArbitrator} from './../typechain/contracts/CentralizedArbitrator';
import {ADDRESS_ZERO} from './../test/unit-tests/common';
import deployedContracts from '../deployed_contracts.json';
import hre, {ethers} from 'hardhat';
import config from '../config-dao';
// IPFS IMPORTS
import {BytesLike, ethers} from 'ethers';
import {Web3Storage, File} from 'web3.storage';
import {Buffer} from 'buffer';
import {
addDeployedContract,
getNetwork,
hexToBytes,
} from '../tasks/helpers';
import {
DAOFactory,
DAOFactory__factory,
DAORegistry__factory,
PluginRepo__factory,
activeContractsList,
} from '@aragon/osx-ethers';
import {uploadToIPFS} from '../utils/ipfs-upload';
import {defaultAbiCoder} from '@ethersproject/abi';
import {toUtf8Bytes} from 'ethers/lib/utils';
async function main() {
const [deployer] = await hre.ethers.getSigners();
const network = getNetwork(hre.network);
const daoFactory = DAOFactory__factory.connect(
activeContractsList[network].DAOFactory,
deployer
);
// const installData = encodeTokenVotingPlugin({
// <YOUR TOKEN VOTING INSTALL PARAMS>
// })
const creationTx = await daoFactory.createDao(
{
metadata: toUtf8Bytes(`ipfs://${await uploadToIPFS(metadata)}`),
subdomain: 'optimistic' + Math.floor(Math.random() * 1000000),
trustedForwarder: ADDRESS_ZERO,
daoURI: 'https://daobox.app',
},
[installData]
);
const txHash = creationTx.hash;
console.log('txHash', txHash);
await creationTx.wait();
const iface = DAORegistry__factory.connect(ADDRESS_ZERO, deployer).interface;
const {dao, creator, subdomain} = (
await findEventTopicLog(creationTx, iface, 'DAORegistered')
).args;
console.log({dao, creator, subdomain, txHash, network: hre.network.name});
}
main().catch(error => {
console.error(error);
process.exitCode = 1;
});
export async function findEventTopicLog(
tx: any,
iface: any,
eventName: string
): Promise<any> {
const receipt = await tx.wait();
const topic = iface.getEventTopic(eventName);
const log = receipt.logs.find(x => x.topics.indexOf(topic) >= 0);
if (!log) {
throw new Error(`No logs found for this event ${eventName} topic.`);
}
return iface.parseLog(log);
}
// https://web3.storage/ <-- sign up here and get a token
export async function uploadToIPFS(text: string): Promise<string> {
// Read the access token from the environment variable
const accessToken = process.env.WEB_3_STORAGE_KEY;
if (!accessToken) {
throw new Error('WEB_3_STORAGE_KEY environment variable not set');
}
// Create a Web3Storage client instance
const client = new Web3Storage({token: accessToken});
// Convert the string to a Buffer
const textBuffer = Buffer.from(text);
// Create a File object with the text buffer
const file = new File([textBuffer], '');
// Store the File object on web3.storage without wrapping it in a directory
return await client.put([file], {wrapWithDirectory: false});
}
export function toHex(input: string): BytesLike {
return ethers.utils.hexlify(ethers.utils.toUtf8Bytes(input));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment