Skip to content

Commit

Permalink
WIP: Add whitelisted ERC20 tokens to the genesis file
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Jul 14, 2023
1 parent df6efa8 commit d3bbb45
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions ethereum_bridge/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,41 @@ use std::num::NonZeroU64;

use borsh::{BorshDeserialize, BorshSerialize};
use eyre::{eyre, Result};
use namada_core::ledger::eth_bridge::storage::whitelist;
use namada_core::ledger::storage;
use namada_core::ledger::storage::types::encode;
use namada_core::ledger::storage::WlStorage;
use namada_core::ledger::storage_api::{StorageRead, StorageWrite};
use namada_core::types::ethereum_events::EthAddress;
use namada_core::types::ethereum_structs;
use namada_core::types::storage::Key;
use namada_core::types::token::{Amount, Denomination};
use serde::{Deserialize, Serialize};

use crate::storage::eth_bridge_queries::{EthBridgeEnabled, EthBridgeStatus};
use crate::{bridge_pool_vp, storage as bridge_storage, vp};

/// An ERC20 token whitelist entry.
#[derive(
Clone,
Copy,
Eq,
PartialEq,
Debug,
Deserialize,
Serialize,
BorshSerialize,
BorshDeserialize,
)]
pub struct Erc20WhitelistEntry {
/// The address of the whitelisted ERC20 token.
pub token_address: EthAddress,
/// The denomination of the whitelisted ERC20 token.
pub denomination: Denomination,
/// The token cap of the whitelisted ERC20 token.
pub token_cap: Amount,
}

/// Represents a configuration value for the minimum number of
/// confirmations an Ethereum event must reach before it can be acted on.
#[derive(
Expand Down Expand Up @@ -138,6 +161,8 @@ pub struct EthereumBridgeConfig {
/// The addresses of the Ethereum contracts that need to be directly known
/// by validators.
pub contracts: Contracts,
/// List of ERC20 token types whitelisted at genesis time.
pub erc20_whitelist: Vec<Erc20WhitelistEntry>,
}

impl EthereumBridgeConfig {
Expand All @@ -151,6 +176,7 @@ impl EthereumBridgeConfig {
H: 'static + storage::traits::StorageHasher,
{
let Self {
erc20_whitelist,
eth_start_height,
min_confirmations,
contracts:
Expand Down Expand Up @@ -187,6 +213,33 @@ impl EthereumBridgeConfig {
wl_storage
.write_bytes(&eth_start_height_key, encode(eth_start_height))
.unwrap();
for Erc20WhitelistEntry {
token_address: addr,
token_cap: cap,
denomination: denom,
} in erc20_whitelist
{
let key = whitelist::Key {
asset: *addr,
suffix: whitelist::KeyType::Whitelisted,
}
.into();
wl_storage.write_bytes(&key, encode(&true)).unwrap();

let key = whitelist::Key {
asset: *addr,
suffix: whitelist::KeyType::Cap,
}
.into();
wl_storage.write_bytes(&key, encode(cap)).unwrap();

let key = whitelist::Key {
asset: *addr,
suffix: whitelist::KeyType::Denomination,
}
.into();
wl_storage.write_bytes(&key, encode(denom)).unwrap();
}
// Initialize the storage for the Ethereum Bridge VP.
vp::init_storage(wl_storage);
// Initialize the storage for the Bridge Pool VP.
Expand Down Expand Up @@ -228,6 +281,8 @@ impl EthereumBridgeConfig {
let eth_start_height = must_read_key(wl_storage, &eth_start_height_key);

Some(Self {
// TODO: read this from storage? iterate storage prefix
erc20_whitelist: vec![],
eth_start_height,
min_confirmations,
contracts: Contracts {
Expand Down

0 comments on commit d3bbb45

Please sign in to comment.