-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making examples work out-of-the-box #224
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,68 +33,96 @@ const metadata: DaoMetadata = { | |
}], | ||
}; | ||
|
||
// Through pinning the metadata in IPFS, we can get the IPFS URI. You can read more about it here: https://docs.ipfs.tech/how-to/pin-files/ | ||
const metadataUri = await client.methods.pinMetadata(metadata); | ||
|
||
// You need at least one plugin in order to create a DAO. In this example, we'll use the TokenVoting plugin, but feel free to install whichever one best suites your needs. You can find resources on how to do this in the plugin sections. | ||
// These would be the plugin params if you need to mint a new token for the DAO to enable TokenVoting. | ||
const tokenVotingPluginInstallParams: TokenVotingPluginInstall = { | ||
votingSettings: { | ||
minDuration: 60 * 60 * 24 * 2, // seconds | ||
minParticipation: 0.25, // 25% | ||
supportThreshold: 0.5, // 50% | ||
minProposerVotingPower: BigInt("5000"), // default 0 | ||
votingMode: VotingMode.EARLY_EXECUTION, // default is STANDARD. other options: EARLY_EXECUTION, VOTE_REPLACEMENT | ||
}, | ||
newToken: { | ||
name: "Token", // the name of your token | ||
symbol: "TOK", // the symbol for your token. shouldn't be more than 5 letters | ||
decimals: 18, // the number of decimals your token uses | ||
minter: "0x...", // optional. if you don't define any, we'll use the standard OZ ERC20 contract. Otherwise, you can define your own token minter contract address. | ||
balances: [ | ||
{ // Defines the initial balances of the new token | ||
address: "0x2371238740123847102983471022", // address of the account to receive the newly minted tokens | ||
balance: BigInt(10), // amount of tokens that address should receive | ||
}, | ||
], | ||
}, | ||
}; | ||
const main = async () => { | ||
// Through pinning the metadata in IPFS, we can get the IPFS URI. You can read more about it here: https://docs.ipfs.tech/how-to/pin-files/ | ||
const metadataUri = await client.methods.pinMetadata(metadata); | ||
|
||
// Creates a TokenVoting plugin client with the parameteres defined above (with an existing token). | ||
const tokenVotingInstallItem = TokenVotingClient.encoding | ||
.getPluginInstallItem(tokenVotingPluginInstallParams); | ||
console.log("Creating DAO..."); | ||
|
||
const createDaoParams: CreateDaoParams = { | ||
metadataUri, | ||
ensSubdomain: "my-org", // my-org.dao.eth | ||
plugins: [tokenVotingInstallItem], // plugin array cannot be empty or the transaction will fail. you need at least one governance mechanism to create your DAO. | ||
}; | ||
// Through pinning the metadata in IPFS, we can get the IPFS URI. You can read more about it here: https://docs.ipfs.tech/how-to/pin-files/ | ||
// const metadataUri = await client.methods.pinMetadata(metadata); | ||
|
||
// You need at least one plugin in order to create a DAO. In this example, we'll use the TokenVoting plugin, but feel free to install whichever one best suites your needs. You can find resources on how to do this in the plugin sections. | ||
// These would be the plugin params if you need to mint a new token for the DAO to enable TokenVoting. | ||
const tokenVotingPluginInstallParams: TokenVotingPluginInstall = { | ||
votingSettings: { | ||
minDuration: 60 * 60 * 24 * 2, // seconds | ||
minParticipation: 0.25, // 25% | ||
supportThreshold: 0.5, // 50% | ||
minProposerVotingPower: BigInt("5000"), // default 0 | ||
votingMode: VotingMode.EARLY_EXECUTION, // default is STANDARD. other options: EARLY_EXECUTION, VOTE_REPLACEMENT | ||
}, | ||
newToken: { | ||
name: "My DAO", // the name of your token | ||
symbol: "DAOTOKEN", // the symbol for your token. shouldn't be more than 5 letters | ||
decimals: 18, // the number of decimals your token uses | ||
// minter: "0x...", // optional. if you don't define any, we'll use the standard OZ ERC20 contract. Otherwise, you can define your own token minter contract address. | ||
balances: [ | ||
{ | ||
// Defines the initial balances of the new token | ||
address: await context.signer.getAddress(), // address of the account to receive the newly minted tokens | ||
balance: BigInt(10), // amount of tokens that address should receive | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
// Creates a TokenVoting plugin client with the parameteres defined above (with an existing token). | ||
const tokenVotingInstallItem = | ||
TokenVotingClient.encoding.getPluginInstallItem( | ||
tokenVotingPluginInstallParams, | ||
context.network | ||
); | ||
|
||
// console.log('tokenVotingInstallItem', tokenVotingInstallItem); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove or uncomment |
||
|
||
// Estimate how much gas the transaction will cost. | ||
const estimatedGas: GasFeeEstimation = await client.estimation.createDao( | ||
createDaoParams, | ||
); | ||
console.log({ avg: estimatedGas.average, maximum: estimatedGas.max }); | ||
|
||
// Create the DAO. | ||
const steps = client.methods.createDao(createDaoParams); | ||
|
||
for await (const step of steps) { | ||
try { | ||
switch (step.key) { | ||
case DaoCreationSteps.CREATING: | ||
console.log({ txHash: step.txHash }); | ||
break; | ||
case DaoCreationSteps.DONE: | ||
console.log({ | ||
daoAddress: step.address, | ||
pluginAddresses: step.pluginAddresses, | ||
}); | ||
break; | ||
const createDaoParams: CreateDaoParams = { | ||
metadataUri, // : `https://dao.mydao.com/metadata.json`, // the URI of the metadata file | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the URL is more like |
||
ensSubdomain: "my-org", // my-org.dao.eth | ||
plugins: [tokenVotingInstallItem], // plugin array cannot be empty or the transaction will fail. you need at least one governance mechanism to create your DAO. | ||
}; | ||
|
||
// Estimate how much gas the transaction will cost. | ||
const estimatedGas: GasFeeEstimation = await client.estimation.createDao( | ||
createDaoParams | ||
); | ||
console.log("estimate dao create", { | ||
avg: estimatedGas.average, | ||
maximum: estimatedGas.max, | ||
}); | ||
|
||
// Create the DAO. | ||
const steps = client.methods.createDao(createDaoParams); | ||
|
||
for await (const step of steps) { | ||
try { | ||
switch (step.key) { | ||
case DaoCreationSteps.CREATING: | ||
console.log("dao deploying...", { txHash: step.txHash }); | ||
break; | ||
case DaoCreationSteps.DONE: | ||
console.log("dao created", { | ||
daoAddress: step.address, | ||
pluginAddresses: step.pluginAddresses, | ||
}); | ||
break; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
// if running in shell, execute the main function | ||
if (require.main === module) { | ||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
// console.error(error.message); | ||
// if (process.env.DEBUG) | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
/* MARKDOWN | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the intention with this comment? the code is already on lines 37-38