Skip to content

Commit 5819935

Browse files
committed
lower gas costs on mainnet
1 parent 31e492c commit 5819935

File tree

5 files changed

+91
-2
lines changed

5 files changed

+91
-2
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88
"phase5a",
99
"phase5b",
1010
"increase_target_staked_ratio",
11-
"update-tx-claim-rewards",
11+
"update-tx-claim-rewards", "update-gas-costs",
1212
]
1313

1414
default-members = [

Earthfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ source:
1818
COPY --keep-ts Cargo.toml Cargo.lock ./
1919
COPY --keep-ts --chmod 755 docker/run-wasmopt.sh ./run-wasmopt.sh
2020
COPY --keep-ts --chmod 755 docker/download-wasmopt.sh ./download-wasmopt.sh
21-
COPY --keep-ts --dir phase2 phase3 phase4 phase5a phase5b increase_target_staked_ratio update-tx-claim-rewards ./
21+
COPY --keep-ts --dir phase2 phase3 phase4 phase5a phase5b increase_target_staked_ratio update-tx-claim-rewards update-gas-costs ./
2222

2323
# lint runs cargo clippy on the source code
2424
lint:

update-gas-costs/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "update-gas-costs"
3+
description = "WASM transaction to write minimum gas costs for desired tokens."
4+
authors.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
version.workspace = true
8+
9+
[dependencies]
10+
namada_tx_prelude.workspace = true
11+
rlsf.workspace = true
12+
getrandom.workspace = true
13+
14+
[lib]
15+
crate-type = ["cdylib"]
16+

update-gas-costs/src/lib.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use std::collections::BTreeMap;
2+
3+
use namada_tx_prelude::*;
4+
5+
pub type ChannelId = &'static str;
6+
pub type BaseToken = &'static str;
7+
8+
pub type Gas = token::Amount;
9+
pub type MinimumGasPrice = Gas;
10+
11+
const IBC_TOKENS: [(ChannelId, BaseToken, MinimumGasPrice); 6] = [
12+
(
13+
"channel-0",
14+
"stuosmo",
15+
Gas::from_u64(3), // 3 stuosmo / gas unit
16+
),
17+
(
18+
"channel-1",
19+
"uosmo",
20+
Gas::from_u64(3), // 3 uosmo / gas unit
21+
),
22+
(
23+
"channel-4",
24+
"upenumbra",
25+
Gas::from_u64(3), // 3 upenumbra / gas unit;
26+
),
27+
(
28+
"channel-5",
29+
"uusdc",
30+
Gas::from_u64(1), // 1 uusdc / gas unit;
31+
),
32+
(
33+
"channel-6",
34+
"unym",
35+
Gas::from_u64(15), // 15 unym / gas unit;
36+
),
37+
(
38+
"channel-7",
39+
"untrn",
40+
Gas::from_u64(7), // 7 untrn / gas unit;
41+
),
42+
];
43+
44+
#[transaction]
45+
fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult {
46+
// Read the current gas cost map
47+
let gas_cost_key = get_gas_cost_key();
48+
let mut minimum_gas_price: BTreeMap<Address, token::Amount> =
49+
ctx.read(&gas_cost_key)?.unwrap_or_default();
50+
51+
// Enable IBC deposit/withdraws limits
52+
for (channel_id, base_token, can_be_used_as_gas) in IBC_TOKENS {
53+
let ibc_denom = format!("transfer/{channel_id}/{base_token}");
54+
let token_address = ibc::ibc_token(&ibc_denom).clone();
55+
56+
// Check if this ibc token should can also be used to pay for gas
57+
minimum_gas_price.insert(token_address.clone(), gas);
58+
}
59+
60+
// Write the gas cost map back to storage
61+
ctx.write(&gas_cost_key, minimum_gas_price)?;
62+
63+
Ok(())
64+
}

0 commit comments

Comments
 (0)