|
| 1 | +import * as anchor from "@coral-xyz/anchor"; |
| 2 | +import { |
| 3 | + FUTARCHY_PROGRAM_ID, |
| 4 | + CONDITIONAL_VAULT_PROGRAM_ID, |
| 5 | + LAUNCHPAD_PROGRAM_ID, |
| 6 | + FutarchyClient, |
| 7 | + getLaunchAddr, |
| 8 | + getLaunchSignerAddr, |
| 9 | +} from "@metadaoproject/futarchy/v0.7"; |
| 10 | +import { LAUNCHPAD_PROGRAM_ID as V06_LAUNCHPAD_PROGRAM_ID } from "@metadaoproject/futarchy/v0.6"; |
| 11 | +import { PublicKey } from "@solana/web3.js"; |
| 12 | +import bs58 from "bs58"; |
| 13 | + |
| 14 | +const provider = anchor.AnchorProvider.env(); |
| 15 | + |
| 16 | +const futarchy: FutarchyClient = new FutarchyClient( |
| 17 | + provider, |
| 18 | + FUTARCHY_PROGRAM_ID, |
| 19 | + CONDITIONAL_VAULT_PROGRAM_ID, |
| 20 | + [], |
| 21 | +); |
| 22 | + |
| 23 | +function getDiscriminator(accountName: string): Buffer { |
| 24 | + return Buffer.from( |
| 25 | + anchor.BorshAccountsCoder.accountDiscriminator(accountName), |
| 26 | + ); |
| 27 | +} |
| 28 | + |
| 29 | +async function main() { |
| 30 | + // 1. Fetch all DAO accounts |
| 31 | + console.log("Fetching all DAO accounts..."); |
| 32 | + const daoDiscriminator = getDiscriminator("Dao"); |
| 33 | + const daoAccounts = await provider.connection.getProgramAccounts( |
| 34 | + futarchy.autocrat.programId, |
| 35 | + { |
| 36 | + filters: [ |
| 37 | + { |
| 38 | + memcmp: { |
| 39 | + offset: 0, |
| 40 | + bytes: bs58.encode(daoDiscriminator), |
| 41 | + }, |
| 42 | + }, |
| 43 | + ], |
| 44 | + }, |
| 45 | + ); |
| 46 | + console.log(`Found ${daoAccounts.length} DAOs`); |
| 47 | + |
| 48 | + // Build map: DAO pubkey -> { squadsMultisigVault, v07LaunchSigner, v06LaunchSigner } |
| 49 | + const daoMap = new Map< |
| 50 | + string, |
| 51 | + { |
| 52 | + squadsMultisigVault: PublicKey; |
| 53 | + v07LaunchSigner: PublicKey; |
| 54 | + v06LaunchSigner: PublicKey; |
| 55 | + } |
| 56 | + >(); |
| 57 | + |
| 58 | + for (const { pubkey, account } of daoAccounts) { |
| 59 | + const dao = futarchy.autocrat.coder.accounts.decode("dao", account.data); |
| 60 | + const [v07Launch] = getLaunchAddr(LAUNCHPAD_PROGRAM_ID, dao.baseMint); |
| 61 | + const [v07LaunchSigner] = getLaunchSignerAddr( |
| 62 | + LAUNCHPAD_PROGRAM_ID, |
| 63 | + v07Launch, |
| 64 | + ); |
| 65 | + const [v06Launch] = getLaunchAddr(V06_LAUNCHPAD_PROGRAM_ID, dao.baseMint); |
| 66 | + const [v06LaunchSigner] = getLaunchSignerAddr( |
| 67 | + V06_LAUNCHPAD_PROGRAM_ID, |
| 68 | + v06Launch, |
| 69 | + ); |
| 70 | + daoMap.set(pubkey.toBase58(), { |
| 71 | + squadsMultisigVault: dao.squadsMultisigVault, |
| 72 | + v07LaunchSigner, |
| 73 | + v06LaunchSigner, |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + // 2. Fetch all AmmPosition accounts |
| 78 | + console.log("Fetching all AmmPosition accounts..."); |
| 79 | + const positionDiscriminator = getDiscriminator("AmmPosition"); |
| 80 | + const positionAccounts = await provider.connection.getProgramAccounts( |
| 81 | + futarchy.autocrat.programId, |
| 82 | + { |
| 83 | + filters: [ |
| 84 | + { |
| 85 | + memcmp: { |
| 86 | + offset: 0, |
| 87 | + bytes: bs58.encode(positionDiscriminator), |
| 88 | + }, |
| 89 | + }, |
| 90 | + ], |
| 91 | + }, |
| 92 | + ); |
| 93 | + console.log(`Found ${positionAccounts.length} AmmPositions\n`); |
| 94 | + |
| 95 | + // 3. Compare each position's authority against its DAO's squadsMultisigVault |
| 96 | + // AND verify whether the position's PDA was derived from squadsMultisigVault |
| 97 | + let matchCount = 0; |
| 98 | + let v07LaunchSignerCount = 0; |
| 99 | + let v06LaunchSignerCount = 0; |
| 100 | + let unknownCount = 0; |
| 101 | + let derivedFromVaultCount = 0; |
| 102 | + let notDerivedFromVaultCount = 0; |
| 103 | + |
| 104 | + for (const { pubkey, account } of positionAccounts) { |
| 105 | + const position = futarchy.autocrat.coder.accounts.decode( |
| 106 | + "ammPosition", |
| 107 | + account.data, |
| 108 | + ); |
| 109 | + |
| 110 | + const daoPubkey = (position.dao as PublicKey).toBase58(); |
| 111 | + const daoInfo = daoMap.get(daoPubkey); |
| 112 | + |
| 113 | + const positionAuthority = ( |
| 114 | + position.positionAuthority as PublicKey |
| 115 | + ).toBase58(); |
| 116 | + const expectedAuthority = daoInfo |
| 117 | + ? daoInfo.squadsMultisigVault.toBase58() |
| 118 | + : "DAO NOT FOUND"; |
| 119 | + const v07LaunchSigner = daoInfo |
| 120 | + ? daoInfo.v07LaunchSigner.toBase58() |
| 121 | + : "DAO NOT FOUND"; |
| 122 | + const v06LaunchSigner = daoInfo |
| 123 | + ? daoInfo.v06LaunchSigner.toBase58() |
| 124 | + : "DAO NOT FOUND"; |
| 125 | + |
| 126 | + // Derive the expected PDA using dao.squadsMultisigVault as position authority |
| 127 | + let derivedFromVault = false; |
| 128 | + let expectedPda = "DAO NOT FOUND"; |
| 129 | + if (daoInfo) { |
| 130 | + const [pda] = PublicKey.findProgramAddressSync( |
| 131 | + [ |
| 132 | + Buffer.from("amm_position"), |
| 133 | + new PublicKey(daoPubkey).toBuffer(), |
| 134 | + daoInfo.squadsMultisigVault.toBuffer(), |
| 135 | + ], |
| 136 | + FUTARCHY_PROGRAM_ID, |
| 137 | + ); |
| 138 | + expectedPda = pda.toBase58(); |
| 139 | + derivedFromVault = pubkey.toBase58() === expectedPda; |
| 140 | + if (derivedFromVault) { |
| 141 | + derivedFromVaultCount++; |
| 142 | + } else { |
| 143 | + notDerivedFromVaultCount++; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + let status: string; |
| 148 | + if (positionAuthority === expectedAuthority) { |
| 149 | + status = "OK (squads multisig vault)"; |
| 150 | + matchCount++; |
| 151 | + } else if (positionAuthority === v07LaunchSigner) { |
| 152 | + status = |
| 153 | + "V0.7 LAUNCH SIGNER (current authority is the v0.7 launch signer)"; |
| 154 | + v07LaunchSignerCount++; |
| 155 | + } else if (positionAuthority === v06LaunchSigner) { |
| 156 | + status = |
| 157 | + "V0.6 LAUNCH SIGNER (current authority is the v0.6 launch signer)"; |
| 158 | + v06LaunchSignerCount++; |
| 159 | + } else { |
| 160 | + status = "UNKNOWN *** MISMATCH ***"; |
| 161 | + unknownCount++; |
| 162 | + } |
| 163 | + |
| 164 | + console.log(`Position: ${pubkey.toBase58()}`); |
| 165 | + console.log(` DAO: ${daoPubkey}`); |
| 166 | + console.log(` Position Authority: ${positionAuthority}`); |
| 167 | + console.log(` Expected Authority: ${expectedAuthority}`); |
| 168 | + console.log(` v0.7 Launch Signer: ${v07LaunchSigner}`); |
| 169 | + console.log(` v0.6 Launch Signer: ${v06LaunchSigner}`); |
| 170 | + console.log( |
| 171 | + ` Derived from vault: ${derivedFromVault ? "YES" : "NO"} (expected PDA: ${expectedPda})`, |
| 172 | + ); |
| 173 | + console.log(` Belongs to: ${status}`); |
| 174 | + console.log(); |
| 175 | + } |
| 176 | + |
| 177 | + // 4. Summary |
| 178 | + console.log("=== Summary ==="); |
| 179 | + console.log(`Total positions: ${positionAccounts.length}`); |
| 180 | + console.log(`Squads vault (OK): ${matchCount}`); |
| 181 | + console.log(`v0.7 launch signer: ${v07LaunchSignerCount}`); |
| 182 | + console.log(`v0.6 launch signer: ${v06LaunchSignerCount}`); |
| 183 | + console.log(`Unknown mismatch: ${unknownCount}`); |
| 184 | + console.log(); |
| 185 | + console.log("=== PDA Derivation Check ==="); |
| 186 | + console.log(`Derived from vault: ${derivedFromVaultCount}`); |
| 187 | + console.log(`NOT derived from vault: ${notDerivedFromVaultCount}`); |
| 188 | +} |
| 189 | + |
| 190 | +main().catch((error) => { |
| 191 | + console.error("Fatal error:", error); |
| 192 | + process.exit(1); |
| 193 | +}); |
0 commit comments