diff --git a/Cargo.lock b/Cargo.lock index ab2be6c1c..1cf9bd6c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2002,7 +2002,7 @@ dependencies = [ [[package]] name = "hexboosting" -version = "0.1.0" +version = "0.0.6" dependencies = [ "anchor-lang", "anchor-spl", diff --git a/packages/helium-admin-cli/src/update-boost-config.ts b/packages/helium-admin-cli/src/update-boost-config.ts index 3ce2b623a..2749cbb80 100644 --- a/packages/helium-admin-cli/src/update-boost-config.ts +++ b/packages/helium-admin-cli/src/update-boost-config.ts @@ -6,10 +6,7 @@ import Squads from "@sqds/sdk"; import os from "os"; import yargs from "yargs/yargs"; import { loadKeypair, sendInstructionsOrSquads } from "./utils"; -import { - init as initHsd, - subDaoKey, -} from "@helium/helium-sub-daos-sdk"; +import { init as initHsd, subDaoKey } from "@helium/helium-sub-daos-sdk"; export async function run(args: any = process.argv) { const yarg = yargs(args).options({ @@ -74,8 +71,8 @@ export async function run(args: any = process.argv) { const instructions: TransactionInstruction[] = []; const dntMint = new PublicKey(argv.dntMint); - const subDaoK = subDaoKey(dntMint)[0] - const subDao = await hsdProgram.account.subDaoV0.fetch(subDaoK) + const subDaoK = subDaoKey(dntMint)[0]; + const subDao = await hsdProgram.account.subDaoV0.fetch(subDaoK); instructions.push( await program.methods diff --git a/packages/hexboosting-sdk/src/pdas.ts b/packages/hexboosting-sdk/src/pdas.ts index 19b336b81..639157a38 100644 --- a/packages/hexboosting-sdk/src/pdas.ts +++ b/packages/hexboosting-sdk/src/pdas.ts @@ -2,30 +2,15 @@ import { PublicKey } from "@solana/web3.js"; import { PROGRAM_ID } from "./constants"; import BN from "bn.js"; -enum DeviceType { - cbrsIndoor, - cbrsOutdoor, - wifiIndoor, - wifiOutdoor, -} - export function boostedHexKey( boostConfig: PublicKey, - deviceType: any, location: BN, programId: PublicKey = PROGRAM_ID ) { const locBuffer = Buffer.alloc(8); locBuffer.writeBigUint64LE(BigInt(location.toString())); - const deviceTypeName = Object.keys(deviceType)[0]; - let deviceTypeValue = DeviceType[deviceTypeName]; return PublicKey.findProgramAddressSync( - [ - Buffer.from("boosted_hex", "utf-8"), - boostConfig.toBuffer(), - Buffer.from([deviceTypeValue]), - locBuffer, - ], + [Buffer.from("boosted_hex", "utf-8"), boostConfig.toBuffer(), locBuffer], programId ); } diff --git a/packages/hexboosting-sdk/src/resolvers.ts b/packages/hexboosting-sdk/src/resolvers.ts index 67bd4cc61..d0eb7e978 100644 --- a/packages/hexboosting-sdk/src/resolvers.ts +++ b/packages/hexboosting-sdk/src/resolvers.ts @@ -6,21 +6,13 @@ import { } from "@helium/anchor-resolvers"; import { subDaoKey } from "@helium/helium-sub-daos-sdk"; import { PublicKey } from "@solana/web3.js"; -import { boostedHexKey } from "./pdas"; export const hexboostingResolvers = combineResolvers( heliumCommonResolver, - resolveIndividual(async ({ path, accounts, args }) => { + resolveIndividual(async ({ path, accounts }) => { if (path[path.length - 1] === "subDao" && accounts.dntMint) { return subDaoKey(accounts.dntMint as PublicKey)[0]; } - if (path[path.length - 1] === "boostedHex" && accounts.boostConfig && args[0].deviceType && args[0].location) { - return boostedHexKey( - accounts.boostConfig as PublicKey, - args[0].deviceType, - args[0].location - )[0] - } }), ataResolver({ instruction: "boostV0", diff --git a/programs/hexboosting/Cargo.toml b/programs/hexboosting/Cargo.toml index 8bf68abd3..e07c7e6dc 100644 --- a/programs/hexboosting/Cargo.toml +++ b/programs/hexboosting/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hexboosting" -version = "0.1.0" +version = "0.0.6" description = "Created with Anchor" edition = "2021" diff --git a/programs/hexboosting/src/instructions/boost_v0.rs b/programs/hexboosting/src/instructions/boost_v0.rs index 22552fbbe..cc4205b60 100644 --- a/programs/hexboosting/src/instructions/boost_v0.rs +++ b/programs/hexboosting/src/instructions/boost_v0.rs @@ -1,4 +1,4 @@ -use crate::{error::ErrorCode, DeviceTypeV0}; +use crate::error::ErrorCode; use anchor_lang::prelude::*; use anchor_spl::{ associated_token::AssociatedToken, @@ -8,7 +8,7 @@ use mobile_entity_manager::CarrierV0; use pyth_solana_receiver_sdk::price_update::PriceUpdateV2; use shared_utils::resize_to_fit; -use crate::{BoostConfigV0, BoostedHexV1}; +use crate::{BoostConfigV0, BoostedHexV0}; pub const TESTING: bool = std::option_env!("TESTING").is_some(); @@ -20,7 +20,6 @@ pub struct BoostArgsV0 { // invalid pub version: u32, pub amounts: Vec, - pub device_type: DeviceTypeV0, } #[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)] @@ -31,7 +30,7 @@ pub struct BoostAmountV0 { fn get_space(boosted_hex: &AccountInfo) -> usize { if boosted_hex.data_len() == 0 { - 8 + 60 + std::mem::size_of::() + 8 + 60 + std::mem::size_of::() } else { boosted_hex.data_len() } @@ -69,11 +68,11 @@ pub struct BoostV0<'info> { init_if_needed, payer = payer, space = get_space(boosted_hex), - seeds = [b"boosted_hex", boost_config.key().as_ref(), &[(args.device_type as u8)], &args.location.to_le_bytes()], + seeds = [b"boosted_hex", boost_config.key().as_ref(), &args.location.to_le_bytes()], bump, constraint = boosted_hex.version == args.version @ ErrorCode::InvalidVersion, )] - pub boosted_hex: Box>, + pub boosted_hex: Box>, pub system_program: Program<'info, System>, pub token_program: Program<'info, Token>, pub associated_token_program: Program<'info, AssociatedToken>, @@ -87,7 +86,6 @@ pub fn handler(ctx: Context, args: BoostArgsV0) -> Result<()> { ctx.accounts.boosted_hex.location = args.location; ctx.accounts.boosted_hex.bump_seed = ctx.bumps["boosted_hex"]; ctx.accounts.boosted_hex.version += 1; - ctx.accounts.boosted_hex.device_type = args.device_type; // Insert the new periods let max_period = args @@ -103,7 +101,6 @@ pub fn handler(ctx: Context, args: BoostArgsV0) -> Result<()> { .boosts_by_period .resize(max_period + 1, 0); } - let now = Clock::get()?.unix_timestamp; for amount in args.amounts.clone() { diff --git a/programs/hexboosting/src/instructions/close_boost_v0.rs b/programs/hexboosting/src/instructions/close_boost_v0.rs index 26da47cff..09998e26d 100644 --- a/programs/hexboosting/src/instructions/close_boost_v0.rs +++ b/programs/hexboosting/src/instructions/close_boost_v0.rs @@ -1,6 +1,6 @@ use anchor_lang::prelude::*; -use crate::{BoostConfigV0, BoostedHexV1}; +use crate::{BoostConfigV0, BoostedHexV0}; #[derive(Accounts)] pub struct CloseBoostV0<'info> { @@ -15,7 +15,7 @@ pub struct CloseBoostV0<'info> { constraint = boosted_hex.is_expired(&boost_config), has_one = boost_config )] - pub boosted_hex: Box>, + pub boosted_hex: Box>, } pub fn handler(_ctx: Context) -> Result<()> { diff --git a/programs/hexboosting/src/instructions/start_boost_v0.rs b/programs/hexboosting/src/instructions/start_boost_v0.rs index 98288359a..81e6e6689 100644 --- a/programs/hexboosting/src/instructions/start_boost_v0.rs +++ b/programs/hexboosting/src/instructions/start_boost_v0.rs @@ -1,6 +1,6 @@ use anchor_lang::prelude::*; -use crate::{BoostConfigV0, BoostedHexV1}; +use crate::{BoostConfigV0, BoostedHexV0}; #[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)] pub struct StartBoostArgsV0 { @@ -18,7 +18,7 @@ pub struct StartBoostV0<'info> { mut, has_one = boost_config, )] - pub boosted_hex: Box>, + pub boosted_hex: Box>, } pub fn handler(ctx: Context, args: StartBoostArgsV0) -> Result<()> { diff --git a/programs/hexboosting/src/state.rs b/programs/hexboosting/src/state.rs index 27d03629c..f34425e65 100644 --- a/programs/hexboosting/src/state.rs +++ b/programs/hexboosting/src/state.rs @@ -20,15 +20,6 @@ pub struct BoostConfigV0 { pub start_authority: Pubkey, } -#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Default, PartialEq)] -pub enum DeviceTypeV0 { - #[default] - CbrsIndoor = 0, - CbrsOutdoor = 1, - WifiIndoor = 2, - WifiOutdoor = 3, -} - #[account] pub struct BoostedHexV0 { pub boost_config: Pubkey, @@ -45,22 +36,7 @@ pub struct BoostedHexV0 { pub version: u32, } -#[account] -pub struct BoostedHexV1 { - pub device_type: DeviceTypeV0, - pub boost_config: Pubkey, - // Track changes to the boosted hex so client can pass what version it made a change to - pub version: u32, - pub location: u64, - // 0 if the boosting has not yet started. Avoding using an option here to keep serialization length - // consistent - pub start_ts: i64, - pub bump_seed: u8, - /// Each entry represents the boost multiplier for a given period - pub boosts_by_period: Vec, -} - -impl BoostedHexV1 { +impl BoostedHexV0 { pub fn is_expired(&self, boost_config: &BoostConfigV0) -> bool { if self.start_ts == 0 { false diff --git a/tests/hexboosting.ts b/tests/hexboosting.ts index c0f548a6c..7ea8726d4 100644 --- a/tests/hexboosting.ts +++ b/tests/hexboosting.ts @@ -207,9 +207,11 @@ describe("hexboosting", () => { const price = await pythProgram.account.priceUpdateV2.fetch( new PublicKey("DQ4C1tzvu28cwo1roN1Wm6TW35sfJEjLh517k3ZeWevx") ); - pythPrice = price.priceMessage.emaPrice.sub( - price.priceMessage.emaConf.mul(new BN(2)) - ).toNumber() * 10 ** price.priceMessage.exponent; + pythPrice = + price.priceMessage.emaPrice + .sub(price.priceMessage.emaConf.mul(new BN(2))) + .toNumber() * + 10 ** price.priceMessage.exponent; console.log(pythPrice); }); @@ -254,7 +256,6 @@ describe("hexboosting", () => { .boostV0({ location: new BN(1), version: 0, - deviceType: { wifiIndoor: {} }, amounts: [ { period: 0, @@ -303,9 +304,8 @@ describe("hexboosting", () => { expected ); - const hex = await program.account.boostedHexV1.fetch(boostedHex!); + const hex = await program.account.boostedHexV0.fetch(boostedHex!); - expect(Object.keys(hex.deviceType)[0]).to.eq("wifiIndoor"); expect(hex.location.toNumber()).to.eq(1); expect(hex.startTs.toNumber()).to.eq(0); expect(hex.boostsByPeriod.toJSON().data).to.deep.eq([1, 1, 1, 1, 1, 1]); @@ -317,7 +317,6 @@ describe("hexboosting", () => { .boostV0({ location: new BN(1), version: 0, - deviceType: { wifiIndoor: {} }, amounts: [ { period: 0, @@ -365,7 +364,6 @@ describe("hexboosting", () => { .boostV0({ location: new BN(1), version: 1, - deviceType: { wifiIndoor: {} }, amounts: [ { period: 2, @@ -397,7 +395,7 @@ describe("hexboosting", () => { Number(expected) ); - const hex = await program.account.boostedHexV1.fetch(boostedHex!); + const hex = await program.account.boostedHexV0.fetch(boostedHex!); expect(hex.boostsByPeriod.toJSON().data).to.deep.eq([ 1, 1, 2, 1, 1, 1, 2, @@ -405,11 +403,7 @@ describe("hexboosting", () => { }); it("allows starting a boost", async () => { - const boostedHex = boostedHexKey( - boostConfigKey(mint)[0], - { wifiIndoor: {} }, - new BN(1) - )[0]; + const boostedHex = boostedHexKey(boostConfigKey(mint)[0], new BN(1))[0]; await program.methods .startBoostV0({ startTs: new BN(1), @@ -418,7 +412,7 @@ describe("hexboosting", () => { boostedHex, }) .rpc({ skipPreflight: true }); - const acc = await program.account.boostedHexV1.fetch(boostedHex!); + const acc = await program.account.boostedHexV0.fetch(boostedHex!); expect(acc.startTs.toNumber()).to.not.eq(0); }); @@ -431,7 +425,6 @@ describe("hexboosting", () => { beforeEach(async () => { const boostedHex = boostedHexKey( boostConfigKey(mint)[0], - { wifiIndoor: {} }, new BN(1) )[0]; await program.methods @@ -447,7 +440,6 @@ describe("hexboosting", () => { it("allows closing the boost when it's done", async () => { const boostedHex = boostedHexKey( boostConfigKey(mint)[0], - { wifiIndoor: {} }, new BN(1) )[0]; // Wait 7 seconds so it is fully expired diff --git a/utils/bulk-claim-rewards/Cargo.lock b/utils/bulk-claim-rewards/Cargo.lock index e244a0d08..cd6505543 100644 --- a/utils/bulk-claim-rewards/Cargo.lock +++ b/utils/bulk-claim-rewards/Cargo.lock @@ -2285,7 +2285,7 @@ dependencies = [ [[package]] name = "helium-sub-daos" -version = "0.1.6" +version = "0.1.5" dependencies = [ "anchor-lang", "anchor-spl", diff --git a/utils/bulk-claim-rewards/src/claim_rewards.rs b/utils/bulk-claim-rewards/src/claim_rewards.rs index 00cee4517..32ccda7a1 100644 --- a/utils/bulk-claim-rewards/src/claim_rewards.rs +++ b/utils/bulk-claim-rewards/src/claim_rewards.rs @@ -33,7 +33,6 @@ use solana_sdk::signature::Keypair; use solana_sdk::{signer::Signer, transaction::Transaction}; use spl_associated_token_account::get_associated_token_address; use std::ops::Deref; -use std::rc::Rc; use std::str::FromStr; use tokio::runtime::Runtime;