-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/675-on-chain-ouis-devaddrs
- Loading branch information
Showing
11 changed files
with
219 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import { daoKey, init as initHsd } from "@helium/helium-sub-daos-sdk"; | ||
import { HNT_MINT, MOBILE_MINT } from "@helium/spl-utils"; | ||
import { getAssociatedTokenAddressSync } from "@solana/spl-token"; | ||
import { PublicKey } 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", | ||
}, | ||
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, | ||
}, | ||
}); | ||
|
||
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 squads = Squads.endpoint(process.env.ANCHOR_PROVIDER_URL, wallet, { | ||
commitmentOrConfig: "finalized", | ||
}); | ||
let multisig = argv.multisig ? new PublicKey(argv.multisig) : undefined; | ||
|
||
const hsdProgram = await initHsd(provider); | ||
|
||
const dao = daoKey(HNT_MINT)[0] | ||
const daoAuth = (await hsdProgram.account.subDaoV0.fetch(dao)) | ||
.authority; | ||
const instructions = [ | ||
await hsdProgram.methods | ||
.switchMobileOpsFund() | ||
.accounts({ | ||
authority: daoAuth, | ||
payer: daoAuth, | ||
opsFundHnt: getAssociatedTokenAddressSync( | ||
daoAuth, | ||
HNT_MINT | ||
), | ||
opsFundMobile: getAssociatedTokenAddressSync( | ||
daoAuth, | ||
MOBILE_MINT | ||
), | ||
dao, | ||
}) | ||
.instruction(), | ||
]; | ||
|
||
await sendInstructionsOrSquads({ | ||
provider, | ||
instructions, | ||
signers: [], | ||
executeTransaction: false, | ||
squads, | ||
multisig, | ||
authorityIndex: argv.authorityIndex, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
programs/helium-sub-daos/src/instructions/switch_mobile_ops_fund.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::str::FromStr; | ||
|
||
use anchor_lang::prelude::*; | ||
use anchor_spl::{ | ||
associated_token::AssociatedToken, | ||
token::{burn, Burn, Mint, Token, TokenAccount}, | ||
}; | ||
use circuit_breaker::{ | ||
cpi::{accounts::MintV0, mint_v0}, | ||
CircuitBreaker, MintArgsV0, MintWindowedCircuitBreakerV0, | ||
}; | ||
|
||
use crate::{dao_seeds, DaoV0}; | ||
|
||
#[derive(Accounts)] | ||
pub struct SwitchMobileOpsFund<'info> { | ||
#[account(mut)] | ||
pub payer: Signer<'info>, | ||
pub authority: Signer<'info>, | ||
#[account( | ||
init_if_needed, | ||
payer = payer, | ||
associated_token::mint = mobile_mint, | ||
associated_token::authority = payer | ||
)] | ||
pub ops_fund_mobile: Account<'info, TokenAccount>, | ||
#[account( | ||
mut, | ||
address = Pubkey::from_str("mb1eu7TzEc71KxDpsmsKoucSSuuoGLv1drys1oP2jh6").unwrap() | ||
)] | ||
pub mobile_mint: Account<'info, Mint>, | ||
#[account( | ||
init_if_needed, | ||
payer = payer, | ||
associated_token::mint = hnt_mint, | ||
associated_token::authority = payer | ||
)] | ||
pub ops_fund_hnt: Account<'info, TokenAccount>, | ||
#[account( | ||
has_one = hnt_mint, | ||
has_one = authority | ||
)] | ||
pub dao: Account<'info, DaoV0>, | ||
#[account(mut)] | ||
pub hnt_mint: Account<'info, Mint>, | ||
#[account( | ||
mut, | ||
seeds = ["mint_windowed_breaker".as_bytes(), hnt_mint.key().as_ref()], | ||
seeds::program = circuit_breaker_program.key(), | ||
bump = hnt_circuit_breaker.bump_seed | ||
)] | ||
pub hnt_circuit_breaker: Box<Account<'info, MintWindowedCircuitBreakerV0>>, | ||
pub circuit_breaker_program: Program<'info, CircuitBreaker>, | ||
pub system_program: Program<'info, System>, | ||
pub token_program: Program<'info, Token>, | ||
pub associated_token_program: Program<'info, AssociatedToken>, | ||
} | ||
|
||
#[allow(clippy::inconsistent_digit_grouping)] | ||
pub fn handler(ctx: Context<SwitchMobileOpsFund>) -> Result<()> { | ||
burn( | ||
CpiContext::new( | ||
ctx.accounts.token_program.to_account_info(), | ||
Burn { | ||
mint: ctx.accounts.mobile_mint.to_account_info(), | ||
from: ctx.accounts.ops_fund_mobile.to_account_info(), | ||
authority: ctx.accounts.authority.to_account_info(), | ||
}, | ||
), | ||
18_197_425_725_000000, | ||
)?; | ||
mint_v0( | ||
CpiContext::new_with_signer( | ||
ctx.accounts.circuit_breaker_program.to_account_info(), | ||
MintV0 { | ||
mint: ctx.accounts.hnt_mint.to_account_info(), | ||
to: ctx.accounts.ops_fund_hnt.to_account_info(), | ||
circuit_breaker: ctx.accounts.hnt_circuit_breaker.to_account_info(), | ||
token_program: ctx.accounts.token_program.to_account_info(), | ||
mint_authority: ctx.accounts.dao.to_account_info(), | ||
}, | ||
&[dao_seeds!(ctx.accounts.dao)], | ||
), | ||
MintArgsV0 { | ||
amount: 1_300_000_00000000, | ||
}, | ||
)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters