Skip to content

Commit

Permalink
Merge branch 'develop' into feat/675-on-chain-ouis-devaddrs
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzettler authored Dec 5, 2024
2 parents 0560375 + 2ac6142 commit 09696c4
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions packages/helium-admin-cli/src/switch-mobile-ops-fund.ts
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,
});
}
13 changes: 9 additions & 4 deletions packages/migration-service/src/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export async function getMigrateTransactions(
): Promise<VersionedTransaction[]> {
const assetApiUrl =
process.env.ASSET_API_URL || provider.connection.rpcEndpoint;
const assets = await getAssetsByOwner(assetApiUrl, from.toBase58());
// Filter out all subscriber NFTs
const assets = (await getAssetsByOwner(assetApiUrl, from.toBase58())).filter(
(asset) => asset?.content?.metadata?.symbol !== "SUBSCRIBER"
);

const uniqueAssets = new Set(assets.map((asset) => asset.id.toBase58()));
const vsrProgram = await initVsr(provider);
Expand Down Expand Up @@ -72,8 +75,10 @@ export async function getMigrateTransactions(
proofPath.length - (canopyHeight || 0)
);
if (anchorRemainingAccounts.length > 10) {
console.log(`Asset ${asset.id} skipped due to having insufficient canopy`)
continue
console.log(
`Asset ${asset.id} skipped due to having insufficient canopy`
);
continue;
}

const ixn = createTransferInstruction(
Expand Down Expand Up @@ -229,7 +234,7 @@ export async function getMigrateTransactions(
return provider.wallet.signTransaction(tx);
}

return tx
return tx;
})
);
}
Expand Down
2 changes: 1 addition & 1 deletion programs/helium-sub-daos/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helium-sub-daos"
version = "0.1.10"
version = "0.1.11"
description = "Created with Anchor"
edition = "2021"

Expand Down
29 changes: 22 additions & 7 deletions programs/helium-sub-daos/src/instructions/issue_rewards_v0.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use anchor_lang::prelude::*;
use anchor_spl::token::{Mint, Token, TokenAccount};
use circuit_breaker::{
Expand All @@ -6,7 +8,9 @@ use circuit_breaker::{
};
use shared_utils::precise_number::{InnerUint, PreciseNumber};

use crate::{current_epoch, error::ErrorCode, state::*, OrArithError, EPOCH_LENGTH, TESTING};
use crate::{
current_epoch, dao_seeds, error::ErrorCode, state::*, OrArithError, EPOCH_LENGTH, TESTING,
};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct IssueRewardsArgsV0 {
Expand Down Expand Up @@ -153,7 +157,7 @@ pub fn handler(ctx: Context<IssueRewardsV0>, args: IssueRewardsArgsV0) -> Result
.unwrap();
let total_rewards = PreciseNumber::new(emissions.into()).or_arith_error()?;
let rewards_prec = percent_share.checked_mul(&total_rewards).or_arith_error()?;
let rewards_amount: u64 = rewards_prec
let mut rewards_amount: u64 = rewards_prec
.floor() // Ensure we never overspend the defined rewards
.or_arith_error()?
.to_imprecise()
Expand Down Expand Up @@ -220,13 +224,24 @@ pub fn handler(ctx: Context<IssueRewardsV0>, args: IssueRewardsArgsV0) -> Result
)?;
}

// Until August 1st, 2025, emit the 2.9M HNT to the treasury.
// This contract will be deployed between December 6 and December 7 at UTC midnight.
// That means this will emit payment from December 7 to August 1st, 2025 (because epochs are paid in arrears).
// This is a total of 237 days. 2.9M HNT / 237 days = 12236.28691983 HNT per day.
#[allow(clippy::inconsistent_digit_grouping)]
if epoch_curr_ts < 1754006400
&& ctx.accounts.dnt_mint.key()
== Pubkey::from_str("mb1eu7TzEc71KxDpsmsKoucSSuuoGLv1drys1oP2jh6").unwrap()
{
rewards_amount += 12_236_28691983;
}

msg!("Minting {} to treasury", rewards_amount);
mint_v0(
ctx.accounts.mint_treasury_emissions_ctx().with_signer(&[&[
b"dao",
ctx.accounts.hnt_mint.key().as_ref(),
&[ctx.accounts.dao.bump_seed],
]]),
ctx
.accounts
.mint_treasury_emissions_ctx()
.with_signer(&[dao_seeds!(ctx.accounts.dao)]),
MintArgsV0 {
amount: rewards_amount,
},
Expand Down
2 changes: 2 additions & 0 deletions programs/helium-sub-daos/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod initialize_sub_dao_v0;
pub mod issue_hst_pool_v0;
pub mod issue_rewards_v0;
pub mod issue_voting_rewards_v0;
pub mod switch_mobile_ops_fund;
pub mod temp_update_sub_dao_epoch_info;
pub mod track_dc_burn_v0;
pub mod track_dc_onboarding_fees_v0;
Expand All @@ -23,6 +24,7 @@ pub use initialize_sub_dao_v0::*;
pub use issue_hst_pool_v0::*;
pub use issue_rewards_v0::*;
pub use issue_voting_rewards_v0::*;
pub use switch_mobile_ops_fund::*;
pub use temp_update_sub_dao_epoch_info::*;
pub use track_dc_burn_v0::*;
pub use track_dc_onboarding_fees_v0::*;
Expand Down
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(())
}
4 changes: 4 additions & 0 deletions programs/helium-sub-daos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ pub mod helium_sub_daos {
) -> Result<()> {
issue_voting_rewards_v0::handler(ctx, args)
}

pub fn switch_mobile_ops_fund(ctx: Context<SwitchMobileOpsFund>) -> Result<()> {
switch_mobile_ops_fund::handler(ctx)
}
}
7 changes: 7 additions & 0 deletions programs/helium-sub-daos/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ pub struct DaoV0 {
pub bump_seed: u8,
}

#[macro_export]
macro_rules! dao_seeds {
( $s:expr ) => {
&[b"dao".as_ref(), $s.hnt_mint.as_ref(), &[$s.bump_seed]]
};
}

#[account]
#[derive(Default)]
pub struct DaoEpochInfoV0 {
Expand Down
1 change: 1 addition & 0 deletions tests/helium-sub-daos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ describe("helium-sub-daos", () => {
expect((postMobileBalance - preMobileBalance).toString()).to.eq(
((SUB_DAO_EPOCH_REWARDS / 100) * 92).toString()
);

expect(vsrEpochInfoAcc.rewardsAmount.toString()).to.eq("0");

const acc = await program.account.subDaoEpochInfoV0.fetch(
Expand Down
6 changes: 3 additions & 3 deletions utils/shared-utils/src/precise_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl PreciseNumber {
Some((frac, -bits))
}
} else {
let bits = 128_i64.checked_sub(i64::from(self.to_imprecise()?.leading_zeros()))?;
let bits = (128_i64).checked_sub(i64::from(self.to_imprecise()?.leading_zeros()))?;
let frac = PreciseNumber {
value: self.value >> bits,
};
Expand Down Expand Up @@ -443,7 +443,7 @@ impl PreciseNumber {

let f = f1.signed().checked_sub(&PreciseNumber::one().signed())?;

let s_divisor = PreciseNumber { value: two() }.signed().checked_add(&f)?;
let s_divisor = (PreciseNumber { value: two() }).signed().checked_add(&f)?;
let s = &f.checked_div(&s_divisor)?;
let s2 = s.checked_mul(s)?.value;
let s4 = s2.checked_mul(&s2)?;
Expand All @@ -459,7 +459,7 @@ impl PreciseNumber {
let r = t1.checked_add(&t2)?;
let hfsq = f
.checked_mul(&f)?
.checked_div(&PreciseNumber { value: two() }.signed())?;
.checked_div(&(PreciseNumber { value: two() }).signed())?;
let k = SignedPreciseNumber {
value: PreciseNumber::new(u128::try_from(ki.abs()).ok()?)?,
is_negative: ki < 0,
Expand Down

0 comments on commit 09696c4

Please sign in to comment.