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

Simulate with gas coin on Neutron Testnet #24

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/cosmos/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,12 +1527,20 @@ impl TxBuilder {
sequences: &[u64],
) -> Result<FullSimulateResponse, crate::Error> {
let body = self.make_tx_body();
let gas_coin = cosmos.pool.builder.gas_coin();

// First simulate the request with no signature and fake gas
let simulate_tx = Tx {
auth_info: Some(AuthInfo {
fee: Some(Fee {
amount: vec![],
amount: if cosmos.pool.builder.get_simulate_with_gas_coin() {
vec![Coin {
denom: gas_coin.to_owned(),
amount: "1".to_owned(),
}]
} else {
vec![]
},
gas_limit: 0,
payer: "".to_owned(),
granter: "".to_owned(),
Expand Down
19 changes: 18 additions & 1 deletion packages/cosmos/src/cosmos_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct CosmosBuilder {
all_nodes_broadcast: bool,
http2_keep_alive_interval: Option<Duration>,
keep_alive_while_idle: Option<bool>,
simulate_with_gas_coin: bool,
}

impl CosmosBuilder {
Expand All @@ -59,10 +60,12 @@ impl CosmosBuilder {
hrp: AddressHrp,
grpc_url: impl Into<String>,
) -> CosmosBuilder {
let chain_id = chain_id.into();
let simulate_with_gas_coin = chain_id == "pion-1";
Self {
grpc_url: Arc::new(grpc_url.into()),
grpc_fallback_urls: vec![],
chain_id: chain_id.into(),
chain_id,
gas_coin: gas_coin.into(),
hrp,
gas_estimate_multiplier: GasMultiplierConfig::Default,
Expand Down Expand Up @@ -92,6 +95,7 @@ impl CosmosBuilder {
all_nodes_broadcast: true,
http2_keep_alive_interval: None,
keep_alive_while_idle: None,
simulate_with_gas_coin,
}
}

Expand Down Expand Up @@ -500,6 +504,19 @@ impl CosmosBuilder {
pub fn get_keep_alive_while_idle(&self) -> Option<bool> {
self.keep_alive_while_idle
}

/// When simulating transactions, do we include a fee with the gas coin?
///
/// Most networks do not require this. However, Neutron Testnet started requiring
/// this some time around June 2024.
pub fn get_simulate_with_gas_coin(&self) -> bool {
self.simulate_with_gas_coin
}

/// See [Self::get_simulate_with_gas_coin]
pub fn set_simulate_with_gas_coin(&mut self, value: bool) {
self.simulate_with_gas_coin = value;
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
Expand Down
Loading