Skip to content
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

Add script to revoke maker #723

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions packages/helium-admin-cli/src/revoke-maker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import * as anchor from "@coral-xyz/anchor";
import { init as initHem, makerKey, rewardableEntityConfigKey } from "@helium/helium-entity-manager-sdk";
import { daoKey, subDaoKey } from "@helium/helium-sub-daos-sdk";
import { HNT_MINT } from "@helium/spl-utils";
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
import Squads from "@sqds/sdk";
import os from "os";
import yargs from "yargs/yargs";
import { loadKeypair, sendInstructionsOrSquads } from "./utils";

export async function run(args: any = process.argv) {
const yarg = yargs(args).options({
wallet: {
alias: "k",
describe: "Anchor wallet keypair",
default: `${os.homedir()}/.config/solana/id.json`,
},
url: {
alias: "u",
default: "http://127.0.0.1:8899",
describe: "The solana url",
},
name: {
alias: "n",
type: "string",
required: true,
describe: "Name of the maker, case sensitive",
},
executeTransaction: {
type: "boolean",
},
multisig: {
type: "string",
describe:
"Address of the squads multisig to be authority. If not provided, your wallet will be the authority",
},
authorityIndex: {
type: "number",
describe: "Authority index for squads. Defaults to 1",
default: 1,
},
dntMint: {
type: "string",
describe: "The dnt mint to revoke",
required: true,
},
symbol: {
alias: "s",
type: "string",
required: true,
describe: "The symbol of the entity config",
},
});
const argv = await yarg.argv;
process.env.ANCHOR_WALLET = argv.wallet;
process.env.ANCHOR_PROVIDER_URL = argv.url;
anchor.setProvider(anchor.AnchorProvider.local(argv.url));
const provider = anchor.getProvider() as anchor.AnchorProvider;
const wallet = new anchor.Wallet(loadKeypair(argv.wallet));
const program = await initHem(provider);

const instructions: TransactionInstruction[] = [];

const maker = makerKey(daoKey(HNT_MINT)[0], argv.name)[0];
// Ensure the maker exists
await program.account.makerV0.fetch(maker);
const rewardableEntityConfigK = rewardableEntityConfigKey(
subDaoKey(new PublicKey(argv.dntMint))[0],
argv.symbol
)[0];
const rewardableEntityConfig =
await program.account.rewardableEntityConfigV0.fetch(
rewardableEntityConfigK
);

instructions.push(
await program.methods
.revokeMakerV0()
.accounts({
maker,
authority: rewardableEntityConfig.authority,
rewardableEntityConfig: rewardableEntityConfigK,
})
.instruction()
);

const squads = Squads.endpoint(process.env.ANCHOR_PROVIDER_URL, wallet, {
commitmentOrConfig: "finalized",
});

await sendInstructionsOrSquads({
provider,
instructions,
executeTransaction: argv.executeTransaction,
squads,
multisig: argv.multisig ? new PublicKey(argv.multisig) : undefined,
authorityIndex: argv.authorityIndex,
signers: [],
});
}
Loading