From 5c759a0bd290f3106c71e2fffee8ee67cc4e5f82 Mon Sep 17 00:00:00 2001 From: metaproph3t Date: Thu, 28 Dec 2023 00:00:00 +0000 Subject: [PATCH] Add instructions for raising proposals --- Anchor.toml | 1 + README.md | 10 ++++++ scripts/initializeProposal.ts | 35 +++++++++++++++++++ scripts/main.ts | 63 ++++------------------------------- 4 files changed, 53 insertions(+), 56 deletions(-) create mode 100644 scripts/initializeProposal.ts diff --git a/Anchor.toml b/Anchor.toml index 6c603551..6c2bb344 100644 --- a/Anchor.toml +++ b/Anchor.toml @@ -22,6 +22,7 @@ autocrat_v0 = "yarn run ts-node scripts/autocratV0.ts" clob = "yarn run tsc scripts/clob.ts --esModuleInterop --resolveJsonModule && node scripts/clob.js && rm scripts/clob.js" crank = "yarn run ts-node scripts/crank.ts" main = "yarn run ts-node scripts/main.ts" +propose = "yarn run ts-node scripts/initializeProposal.ts" initialize_vault = "yarn run tsc scripts/initializeVault.ts --esModuleInterop --resolveJsonModule && node scripts/initializeVault.js" place_order = "yarn run ts-node scripts/placeOrder.ts" test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/*.ts" diff --git a/README.md b/README.md index 5b40f924..78630924 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,16 @@ Monorepo that houses the Meta-DAO's programs. A description of these programs and what they do can be found at [themetadao.org](https://themetadao.org). +## Scripts + +The scripts folder contains a few scripts that you can use to interact with the Meta-DAO. +Today, the only way to create proposals is via script. You can do this by modifying the +`initializeProposal.ts` script and replacing its `pubkey`, `accounts`, and `data` with the +SVM instruction that you want to use in your proposal. + +Then, run `anchor run propose --provider.cluster CLUSTER`, where `CLUSTER` is replaced with +either devnet, mainnet, or (recommended) an RPC URL. + ## Deployments | program | tag | program ID | diff --git a/scripts/initializeProposal.ts b/scripts/initializeProposal.ts new file mode 100644 index 00000000..06727a51 --- /dev/null +++ b/scripts/initializeProposal.ts @@ -0,0 +1,35 @@ +import { initializeProposal } from "./main"; +import * as anchor from "@coral-xyz/anchor"; +import { MEMO_PROGRAM_ID } from "@solana/spl-memo"; + +const { PublicKey, Keypair, SystemProgram } = anchor.web3; +const { BN, Program } = anchor; + +async function main() { + const memoText = + "I, glorious autocrat of the divine Meta-DAO, " + + "sanction the creation of this Saber vote market platform.\n\n" + + "That I shall bestow lavish rewards upon those who contribute to its creation is guaranteed. " + + "Remember that my word is not the word of a man but the word of a market.\n\n" + + "Godspeed, futards!"; + + const memoInstruction = { + programId: new PublicKey(MEMO_PROGRAM_ID), + data: Buffer.from(memoText), + accounts: [], + }; + + // accounts should be an array of objects that look like + // { + // pubkey: new PublicKey(MEMO_PROGRAM_ID), + // isWritable: false, + // isSigner: false, + // } + + await initializeProposal( + memoInstruction, + "https://hackmd.io/@jlPYU3_dTOuQkU5duRNUlg/rkhWWXjLp" + ); +} + +main(); diff --git a/scripts/main.ts b/scripts/main.ts index 953ce293..c69ffb88 100644 --- a/scripts/main.ts +++ b/scripts/main.ts @@ -29,9 +29,6 @@ const AutocratMigratorIDL: AutocratMigrator = require("../target/idl/autocrat_mi const AUTOCRAT_PROGRAM_ID = new PublicKey( "metaX99LHn3A7Gr7VAcCfXhpfocvpMpqQ3eyp3PGUUq" ); -// const AUTOCRAT_PROGRAM_ID = new PublicKey( -// "meta3cxKzFBmWYgCVozmvCQAS3y9b3fGxrG9HkHL7Wi" -// ); const CONDITIONAL_VAULT_PROGRAM_ID = new PublicKey( "vaU1tVLj8RFk7mNj1BxqgAsMKKaL8UvEUHvU3tdbZPe" ); @@ -88,12 +85,12 @@ export const migrator = new anchor.Program( provider ); -const [dao] = PublicKey.findProgramAddressSync( +export const [dao] = PublicKey.findProgramAddressSync( [anchor.utils.bytes.utf8.encode("WWCACOTMICMIBMHAFTTWYGHMB")], autocratProgram.programId ); -const [daoTreasury] = PublicKey.findProgramAddressSync( +export const [daoTreasury] = PublicKey.findProgramAddressSync( [dao.toBuffer()], autocratProgram.programId ); @@ -262,7 +259,10 @@ async function initializeDAO(META: any, USDC: any) { // console.log("Proposal finalized", tx); // } -async function initializeProposal(instruction: any, proposalURL: string) { +export async function initializeProposal( + instruction: any, + proposalURL: string +) { const proposalKeypair = Keypair.generate(); const storedDAO = await autocratProgram.account.dao.fetch(dao); @@ -277,7 +277,7 @@ async function initializeProposal(instruction: any, proposalURL: string) { const quoteVault = await initializeVault( daoTreasury, - USDC, + DEVNET_USDC, baseNonce.or(new BN(1).shln(63)) ); @@ -296,7 +296,6 @@ async function initializeProposal(instruction: any, proposalURL: string) { ).conditionalOnRevertTokenMint; let openbookPassMarketKP = Keypair.generate(); - console.log(openbookPassMarketKP); let [openbookTwapPassMarket] = PublicKey.findProgramAddressSync( [ @@ -335,7 +334,6 @@ async function initializeProposal(instruction: any, proposalURL: string) { .rpc(); let openbookFailMarketKP = Keypair.generate(); - console.log(openbookFailMarketKP); let [openbookTwapFailMarket] = PublicKey.findProgramAddressSync( [ @@ -624,50 +622,3 @@ async function getOrCreateAccount(mint: anchor.web3.PublicKey) { ) ).address; } - -async function main() { - // await initializeProposal(); - // let proposal = (await autocratProgram.account.proposal.all())[0]; - - // console.log(proposal.publicKey) - // console.log(newDaoTreasury) - // console.log(await newAutocratProgram.account.dao.fetch(newDao)); - - const memoText = - "I, glorious autocrat of the divine Meta-DAO, " + - "sanction the creation of this Saber vote market platform.\n\n" + - "That I shall bestow lavish rewards upon those who contribute to its creation is guaranteed. " + - "Remember that my word is not the word of a man but the word of a market.\n\n" + - "Godspeed, futards!"; - - const memoInstruction = { - programId: new PublicKey(MEMO_PROGRAM_ID), - data: Buffer.from(memoText), - accounts: [], - }; - - await initializeProposal( - memoInstruction, - "https://hackmd.io/@jlPYU3_dTOuQkU5duRNUlg/rkhWWXjLp" - ); - - // Create a transaction and add the memo instruction - // const transaction = new anchor.web3.Transaction(); - // transaction.add(memoInstruction); - - // Send the transaction - // const signature = await anchor.web3.sendAndConfirmTransaction( - // provider.connection, - // transaction, - // [payer] // The account that will sign the transaction - // ); - - // console.log(`Transaction sent with signature: ${signature}`); - - // await finalizeProposal(proposal.publicKey) - - // console.log(await openbookTwap.account.twapMarket.fetch(proposal.openbookTwapPassMarket)); - // console.log(await openbookTwap.account.twapMarket.fetch(proposal.openbookTwapPassMarket)); -} - -main();