Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sealevel): read / write igp gas oracle config #2705

Merged
merged 11 commits into from
Sep 7, 2023
153 changes: 152 additions & 1 deletion rust/sealevel/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ use account_utils::DiscriminatorEncode;
use hyperlane_core::{Encode, HyperlaneMessage, H160, H256};
use hyperlane_sealevel_connection_client::router::RemoteRouterConfig;
use hyperlane_sealevel_igp::{
accounts::{InterchainGasPaymasterType, OverheadIgpAccount},
accounts::{
GasOracle, IgpAccount, InterchainGasPaymasterType, OverheadIgpAccount, RemoteGasData,
},
igp_gas_payment_pda_seeds, igp_program_data_pda_seeds,
instruction::{GasOracleConfig, GasOverheadConfig},
};
use hyperlane_sealevel_mailbox::{
accounts::{InboxAccount, OutboxAccount},
Expand Down Expand Up @@ -118,6 +121,7 @@ pub(crate) struct WarpRouteCmd {
#[derive(Subcommand)]
pub(crate) enum WarpRouteSubCmd {
Deploy(WarpRouteDeploy),
DestinationGas(DestinationGasArgs),
}

#[derive(Args)]
Expand All @@ -138,6 +142,14 @@ pub(crate) struct WarpRouteDeploy {
ata_payer_funding_amount: Option<u64>,
}

#[derive(Args)]
struct DestinationGasArgs {
#[arg(long)]
program_id: Pubkey,
#[arg(long)]
destination_domain: u32,
}

#[derive(Args)]
struct CoreCmd {
#[command(subcommand)]
Expand Down Expand Up @@ -342,6 +354,8 @@ struct IgpCmd {
#[derive(Subcommand)]
enum IgpSubCmd {
PayForGas(PayForGasArgs),
GasOracleConfig(GasOracleConfigArgs),
DestinationGasOverhead(DestinationGasOverheadArgs),
TransferIgpOwnership(TransferIgpOwnership),
TransferOverheadIgpOwnership(TransferIgpOwnership),
}
Expand All @@ -363,6 +377,42 @@ struct PayForGasArgs {
message_id: String,
}

#[derive(Args)]
struct GasOracleConfigArgs {
#[arg(long)]
environment: String,
#[arg(long)]
environments_dir: PathBuf,
#[arg(long)]
chain_name: String,
#[arg(long)]
remote_domain: u32,
// If the following arguments are not provided, just read the current on-chain config.
// Otherwise, set these values on-chain.
#[arg(long)]
token_exchange_rate: Option<u128>,
#[arg(long)]
gas_price: Option<u128>,
#[arg(long)]
token_decimals: Option<u8>,
}

#[derive(Args)]
struct DestinationGasOverheadArgs {
#[arg(long)]
environment: String,
#[arg(long)]
environments_dir: PathBuf,
#[arg(long)]
chain_name: String,
#[arg(long)]
remote_domain: u32,
// If the following argument is not provided, just read the current on-chain config.
// Otherwise, set this value on-chain.
#[arg(long)]
gas_overhead: Option<u64>,
}

#[derive(Args)]
struct ValidatorAnnounceCmd {
#[command(subcommand)]
Expand Down Expand Up @@ -1256,6 +1306,107 @@ fn process_igp_cmd(ctx: Context, cmd: IgpCmd) {
payment_details.message_id, gas_payment_data_account
);
}
IgpSubCmd::GasOracleConfig(args) => {
let core_program_ids =
read_core_program_ids(&args.environments_dir, &args.environment, &args.chain_name);
match (
args.token_decimals,
args.token_exchange_rate,
args.gas_price,
) {
(None, None, None) => {
// Read the gas oracle config
let igp_account = ctx
.client
.get_account_with_commitment(&core_program_ids.igp_account, ctx.commitment)
.unwrap()
.value
.expect(
"IGP account not found. Make sure you are connected to the right RPC.",
);

let igp_account = IgpAccount::fetch(&mut &igp_account.data[..])
.unwrap()
.into_inner();

println!(
"IGP account gas oracle: {:#?}",
igp_account.gas_oracles.get(&args.remote_domain)
);
}
(Some(token_decimals), Some(token_exchange_rate), Some(gas_price)) => {
// Set the gas oracle config
let remote_gas_data = RemoteGasData {
token_exchange_rate,
gas_price,
token_decimals,
};
let gas_oracle_config = GasOracleConfig {
domain: args.remote_domain,
gas_oracle: Some(GasOracle::RemoteGasData(remote_gas_data)),
};
let instruction =
hyperlane_sealevel_igp::instruction::set_gas_oracle_configs_instruction(
core_program_ids.igp_program_id,
core_program_ids.igp_account,
ctx.payer_pubkey,
vec![gas_oracle_config],
)
.unwrap();
ctx.new_txn().add(instruction).send_with_payer();
println!("Set gas oracle for remote domain {:?}", args.remote_domain);
}
_ => {
println!("Must specify all or none of --token-decimals, --token-exchange-rate, and --gas-price");
}
}
}
IgpSubCmd::DestinationGasOverhead(args) => {
let core_program_ids =
read_core_program_ids(&args.environments_dir, &args.environment, &args.chain_name);
match args.gas_overhead {
None => {
// Read the gas overhead config
let overhead_igp_account = ctx
.client
.get_account_with_commitment(
&core_program_ids.overhead_igp_account,
ctx.commitment,
)
.unwrap()
.value
.expect("Overhead IGP account not found. Make sure you are connected to the right RPC.");
let overhead_igp_account =
OverheadIgpAccount::fetch(&mut &overhead_igp_account.data[..])
.unwrap()
.into_inner();
println!(
"Overhead IGP account gas oracle: {:#?}",
overhead_igp_account.gas_overheads.get(&args.remote_domain)
);
}
Some(gas_overhead) => {
let overhead_config = GasOverheadConfig {
destination_domain: args.remote_domain,
gas_overhead: Some(gas_overhead),
};
// Set the gas overhead config
let instruction =
hyperlane_sealevel_igp::instruction::set_destination_gas_overheads(
core_program_ids.igp_program_id,
core_program_ids.overhead_igp_account,
ctx.payer_pubkey,
vec![overhead_config],
)
.unwrap();
ctx.new_txn().add(instruction).send_with_payer();
println!(
"Set gas overheads for remote domain {:?}",
args.remote_domain
)
}
}
}
IgpSubCmd::TransferIgpOwnership(ref transfer_ownership)
| IgpSubCmd::TransferOverheadIgpOwnership(ref transfer_ownership) => {
let igp_account_type = match cmd.cmd {
Expand Down
7 changes: 7 additions & 0 deletions rust/sealevel/client/src/warp_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ pub(crate) fn process_warp_route_cmd(mut ctx: Context, cmd: WarpRouteCmd) {
.collect::<HashMap<String, H256>>();
write_program_ids(&warp_route_dir, &routers_by_name);
}
WarpRouteSubCmd::DestinationGas(args) => {
let destination_gas = get_destination_gas(&ctx.client, &args.program_id).unwrap();
println!(
"Destination gas: {:?}",
destination_gas[&args.destination_domain]
);
}
}
}

Expand Down
Loading