-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import { init as initHem } from "@helium/helium-entity-manager-sdk"; | ||
import os from "os"; | ||
import yargs from "yargs/yargs"; | ||
import fs from "fs"; | ||
import { batchInstructionsToTxsWithPriorityFee, sendInstructions } from "@helium/spl-utils"; | ||
import { PublicKey, TransactionInstruction } from "@solana/web3.js"; | ||
|
||
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", | ||
}, | ||
badHotspotsFile: { | ||
type: "string", | ||
required: true, | ||
} | ||
}); | ||
|
||
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 hemProgram = await initHem(provider); | ||
|
||
const badHotspots = JSON.parse( | ||
fs.readFileSync(argv.badHotspotsFile, "utf-8") | ||
); | ||
|
||
let instructions: TransactionInstruction[] = []; | ||
for (const hotspot of badHotspots) { | ||
instructions.push( | ||
await hemProgram.methods | ||
.tempRepairMobileHotspotInfo() | ||
.accounts({ | ||
mobileInfo: new PublicKey(hotspot), | ||
}) | ||
.instruction() | ||
); | ||
} | ||
|
||
await batchInstructionsToTxsWithPriorityFee(provider, instructions, { | ||
useFirstEstimateForAll: true, | ||
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/circuit-breaker.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/circuit-breaker.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Development Workflow
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Development Workflow
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/treasury-management.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/treasury-management.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/price-oracle.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/price-oracle.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/mobile-entity-manager.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/mobile-entity-manager.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/helium-sub-daos.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/helium-sub-daos.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/lazy-distributor.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/lazy-distributor.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/data-credits.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/data-credits.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/lazy-transactions.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/lazy-transactions.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/voter-stake-registry.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/voter-stake-registry.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/fanout.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/fanout.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/helium-entity-manager.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/helium-entity-manager.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/hexboosting.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/hexboosting.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/sus.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/sus.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/distributor-oracle.ts)
Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts GitHub Actions / Test Anchor Contracts (tests/distributor-oracle.ts)
|
||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::error::ErrorCode; | ||
use crate::state::*; | ||
use anchor_lang::prelude::*; | ||
use std::str::FromStr; | ||
|
||
use anchor_lang::{AnchorDeserialize, AnchorSerialize}; | ||
|
||
#[account] | ||
pub struct OldMobileHotspotInfo { | ||
pub asset: Pubkey, | ||
pub bump_seed: u8, | ||
|
||
pub location: Option<u64>, | ||
pub is_full_hotspot: bool, | ||
pub num_location_asserts: u16, | ||
pub is_active: bool, | ||
pub dc_onboarding_fee_paid: u64, | ||
pub device_type: MobileDeviceTypeV0, | ||
} | ||
|
||
const FIX_DEPLOYER_KEY: &str = "hprdnjkbziK8NqhThmAn5Gu4XqrBbctX8du4PfJdgvW"; | ||
#[derive(Accounts)] | ||
pub struct TempRepairMobileHotspotInfo<'info> { | ||
/// CHECK: no | ||
#[account(mut)] | ||
pub mobile_info: UncheckedAccount<'info>, | ||
#[account( | ||
constraint = authority.key() == Pubkey::from_str(FIX_DEPLOYER_KEY).unwrap(), | ||
)] | ||
pub authority: Signer<'info>, | ||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
pub fn handler(ctx: Context<TempRepairMobileHotspotInfo>) -> Result<()> { | ||
let mut data = ctx.accounts.mobile_info.try_borrow_mut_data()?; | ||
let old_info: OldMobileHotspotInfo = | ||
OldMobileHotspotInfo::try_deserialize_unchecked(&mut &data[..])?; | ||
let old_info_bytes = old_info.try_to_vec()?; | ||
for byte in &mut data[(8 + old_info_bytes.len())..] { | ||
*byte = 0; | ||
} | ||
|
||
msg!("Repaired, checking..."); | ||
let new_info: MobileHotspotInfoV0 = MobileHotspotInfoV0::try_deserialize(&mut &data[..])?; | ||
|
||
require_eq!(new_info.asset, old_info.asset); | ||
require_eq!(new_info.bump_seed, old_info.bump_seed); | ||
require_eq!(new_info.location.is_some(), old_info.location.is_some()); | ||
if new_info.location.is_some() { | ||
require_eq!(new_info.location.unwrap(), old_info.location.unwrap()); | ||
} | ||
require_eq!(new_info.is_full_hotspot, old_info.is_full_hotspot); | ||
require_eq!(new_info.num_location_asserts, old_info.num_location_asserts); | ||
require_eq!(new_info.is_active, old_info.is_active); | ||
require_eq!( | ||
new_info.dc_onboarding_fee_paid, | ||
old_info.dc_onboarding_fee_paid | ||
); | ||
if new_info.device_type != old_info.device_type { | ||
return Err(ErrorCode::InvalidDeviceType.into()); | ||
} | ||
|
||
Ok(()) | ||
} |