Skip to content

Commit

Permalink
Merge pull request #24 from fpco/neutron-testnet
Browse files Browse the repository at this point in the history
Simulate with gas coin on Neutron Testnet
  • Loading branch information
snoyberg authored Jun 17, 2024
2 parents b59ea88 + 12ee5a3 commit e950e21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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

0 comments on commit e950e21

Please sign in to comment.