Skip to content

Commit

Permalink
Fix bug double adding dc onboarding fees and add an endpoint to corre…
Browse files Browse the repository at this point in the history
…ct the fees (#686)
  • Loading branch information
ChewingGlass authored Aug 2, 2024
1 parent 3f5a4be commit 6eb3edc
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 58 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.

87 changes: 87 additions & 0 deletions packages/helium-admin-cli/src/set-dc-onboarding-fees-paid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as anchor from "@coral-xyz/anchor";
import { init as initHsd, subDaoKey } from "@helium/helium-sub-daos-sdk";
import { MOBILE_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",
},
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,
},
minimumPeriods: {
type: "number",
describe: "The new minimum number of periods",
},
dcOnboardingFeesPaid: {
type: "string",
required: true,
describe: "The new dc onboarding fees paid",
},
dntMint: {
type: "string",
describe: "DNT mint of the boost config",
default: MOBILE_MINT.toBase58(),
},
});
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 hsdProgram = await initHsd(provider);

const instructions: TransactionInstruction[] = [];

const dntMint = new PublicKey(argv.dntMint);
const subDaoK = subDaoKey(dntMint)[0];

instructions.push(
await hsdProgram.methods
.adminSetDcOnboardingFeesPaid({
dcOnboardingFeesPaid: new anchor.BN(argv.dcOnboardingFeesPaid),
})
.accounts({
subDao: subDaoK,
})
.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: [],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,6 @@ pub fn handler<'info>(
dc_onboarding_fee_paid: dc_fee,
});

track_dc_onboarding_fees_v0(
CpiContext::new_with_signer(
ctx.accounts.helium_sub_daos_program.to_account_info(),
TrackDcOnboardingFeesV0 {
hem_auth: ctx.accounts.rewardable_entity_config.to_account_info(),
sub_dao: ctx.accounts.sub_dao.to_account_info(),
},
&[rewardable_entity_config_seeds!(
ctx.accounts.rewardable_entity_config
)],
),
TrackDcOnboardingFeesArgsV0 {
amount: dc_fee,
add: true,
symbol: ctx.accounts.rewardable_entity_config.symbol.clone(),
},
)?;

if let (
Some(location),
ConfigSettingsV0::IotConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,6 @@ pub fn handler<'info>(
is_active: false,
dc_onboarding_fee_paid: dc_fee,
});
track_dc_onboarding_fees_v0(
CpiContext::new_with_signer(
ctx.accounts.helium_sub_daos_program.to_account_info(),
TrackDcOnboardingFeesV0 {
hem_auth: ctx.accounts.rewardable_entity_config.to_account_info(),
sub_dao: ctx.accounts.sub_dao.to_account_info(),
},
&[rewardable_entity_config_seeds!(
ctx.accounts.rewardable_entity_config
)],
),
TrackDcOnboardingFeesArgsV0 {
amount: dc_fee,
add: true,
symbol: ctx.accounts.rewardable_entity_config.symbol.clone(),
},
)?;

if let (
Some(location),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,6 @@ pub fn handler<'info>(
.unwrap();
}

track_dc_onboarding_fees_v0(
CpiContext::new_with_signer(
ctx.accounts.helium_sub_daos_program.to_account_info(),
TrackDcOnboardingFeesV0 {
hem_auth: ctx.accounts.rewardable_entity_config.to_account_info(),
sub_dao: ctx.accounts.sub_dao.to_account_info(),
},
&[&[
"rewardable_entity_config".as_bytes(),
ctx.accounts.sub_dao.key().as_ref(),
ctx.accounts.rewardable_entity_config.symbol.as_bytes(),
&[ctx.accounts.rewardable_entity_config.bump_seed],
]],
),
TrackDcOnboardingFeesArgsV0 {
amount: fees.dc_onboarding_fee,
add: true,
symbol: ctx.accounts.rewardable_entity_config.symbol.clone(),
},
)?;

// burn the dc tokens
burn_without_tracking_v0(
ctx.accounts.burn_ctx(),
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.6"
version = "0.1.7"
description = "Created with Anchor"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use anchor_lang::prelude::*;

use crate::{DaoV0, SubDaoV0};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct AdminSetDcOnboardingFeesPaidArgs {
pub dc_onboarding_fees_paid: u64,
}

#[derive(Accounts)]
pub struct AdminSetDcOnboardingFeesPaid<'info> {
#[account(
has_one = authority,
)]
pub dao: Account<'info, DaoV0>,
#[account(
mut,
has_one = dao,
)]
pub sub_dao: Account<'info, SubDaoV0>,
pub authority: Signer<'info>,
}

pub fn handler(
ctx: Context<AdminSetDcOnboardingFeesPaid>,
args: AdminSetDcOnboardingFeesPaidArgs,
) -> Result<()> {
ctx.accounts.sub_dao.dc_onboarding_fees_paid = args.dc_onboarding_fees_paid;
Ok(())
}
2 changes: 2 additions & 0 deletions programs/helium-sub-daos/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod admin_set_dc_onboarding_fees_paid;
pub mod calculate_utility_score_v0;
pub mod delegation;
pub mod initialize_dao_v0;
Expand All @@ -11,6 +12,7 @@ pub mod update_dao_v0;
pub mod update_sub_dao_v0;
pub mod update_sub_dao_vehnt_v0;

pub use admin_set_dc_onboarding_fees_paid::*;
pub use calculate_utility_score_v0::*;
pub use delegation::*;
pub use initialize_dao_v0::*;
Expand Down
7 changes: 7 additions & 0 deletions programs/helium-sub-daos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,11 @@ pub mod helium_sub_daos {
) -> Result<()> {
track_dc_onboarding_fees_v0::handler(ctx, args)
}

pub fn admin_set_dc_onboarding_fees_paid(
ctx: Context<AdminSetDcOnboardingFeesPaid>,
args: AdminSetDcOnboardingFeesPaidArgs,
) -> Result<()> {
admin_set_dc_onboarding_fees_paid::handler(ctx, args)
}
}

0 comments on commit 6eb3edc

Please sign in to comment.