Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
9 changes: 8 additions & 1 deletion rs/ethereum/cketh/minter/cketh_minter.did
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ type MinterInfo = record {
evm_rpc_id : opt principal;
};


type GasFeeEstimate = record {
// Maximum amount of Wei per gas unit that the transaction is willing to pay in total.
// This covers the base fee determined by the network and the `max_priority_fee_per_gas`.
Expand Down Expand Up @@ -570,6 +569,14 @@ type Event = record {
from_subaccount : opt blob;
created_at: opt nat64;
};
AcceptedSweeperFundingRequest : record {
withdrawal_amount : nat;
destination : text;
ledger_burn_index : nat;
from : principal;
from_subaccount : opt blob;
created_at: nat64;
};
CreatedTransaction : record {
withdrawal_id : nat;
transaction : UnsignedTransaction;
Expand Down
7 changes: 7 additions & 0 deletions rs/ethereum/cketh/minter/src/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ impl DashboardTemplate {
created_at: Some(req.created_at),
}
}
WithdrawalRequest::SweeperFunding(req) => DashboardWithdrawalRequest {
cketh_ledger_burn_index: req.ledger_burn_index,
destination: req.destination,
value: req.withdrawal_amount.into(),
token_symbol: CkTokenSymbol::cketh_symbol_from_state(state),
created_at: Some(req.created_at),
},
})
.collect();
withdrawal_requests.sort_unstable_by_key(|req| Reverse(req.cketh_ledger_burn_index));
Expand Down
6 changes: 5 additions & 1 deletion rs/ethereum/cketh/minter/src/dashboard/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,12 +884,16 @@ fn should_display_reimbursed_requests() {
},
);
}
Comment thread
gregorydemay marked this conversation as resolved.
WithdrawalRequest::SweeperFunding(_) => {
unreachable!("sweeper funding is never reimbursed")
}
}
} else {
apply_state_transition(
&mut state,
&EventType::QuarantinedReimbursement {
index: ReimbursementIndex::from(&req),
index: ReimbursementIndex::try_from(&req)
.expect("BUG: this test's fixtures are all user withdrawals"),
},
)
}
Expand Down
8 changes: 8 additions & 0 deletions rs/ethereum/cketh/minter/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ pub mod events {
from_subaccount: Option<[u8; 32]>,
created_at: Option<u64>,
},
AcceptedSweeperFundingRequest {
withdrawal_amount: Nat,
destination: String,
ledger_burn_index: Nat,
from: Principal,
from_subaccount: Option<[u8; 32]>,
created_at: u64,
},
CreatedTransaction {
withdrawal_id: Nat,
transaction: UnsignedTransaction,
Expand Down
7 changes: 7 additions & 0 deletions rs/ethereum/cketh/minter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ pub const EVM_RPC_ID_PRODUCTION: Principal =
Principal::from_slice(&[0, 0, 0, 0, 2, 48, 0, 204, 1, 1]);
pub const EVM_RPC_ID_STAGING: Principal = Principal::from_slice(&[0, 0, 0, 0, 2, 48, 0, 161, 1, 1]);
pub const CKETH_LEDGER_MEMO_SIZE: u16 = 80;

pub const CKETH_FEE_SUBACCOUNT: [u8; 32] = {
let mut subaccount = [0_u8; 32];
subaccount[30] = 0x0f;
subaccount[31] = 0xee;
subaccount
};
27 changes: 24 additions & 3 deletions rs/ethereum/cketh/minter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use ic_cketh_minter::state::audit::{Event, EventType, process_event};
use ic_cketh_minter::state::eth_logs_scraping::{LogScrapingId, LogScrapingInfo};
use ic_cketh_minter::state::transactions::{
Erc20WithdrawalRequest, EthWithdrawalRequest, Reimbursed, ReimbursementIndex,
ReimbursementRequest,
ReimbursementRequest, SweeperFundingRequest,
};
use ic_cketh_minter::state::{
STATE, State, lazy_call_ecdsa_public_key, mutate_state, read_state, transactions,
Expand Down Expand Up @@ -407,7 +407,9 @@ async fn withdrawal_status(parameter: WithdrawalSearchParameter) -> Vec<Withdraw
withdrawal_id: *request.cketh_ledger_burn_index().as_ref(),
recipient_address: request.payee().to_string(),
token_symbol: match request {
CkEth(_) => CkTokenSymbol::cketh_symbol_from_state(s).to_string(),
CkEth(_) | SweeperFunding(_) => {
CkTokenSymbol::cketh_symbol_from_state(s).to_string()
}
CkErc20(r) => s
.ckerc20_tokens
.get_alt(&r.erc20_contract_address)
Expand All @@ -417,12 +419,16 @@ async fn withdrawal_status(parameter: WithdrawalSearchParameter) -> Vec<Withdraw
withdrawal_amount: match request {
CkEth(r) => r.withdrawal_amount.into(),
CkErc20(r) => r.withdrawal_amount.into(),
SweeperFunding(r) => r.withdrawal_amount.into(),
},
max_transaction_fee: match (request, tx) {
(CkEth(_), None) => None,
(CkEth(_) | SweeperFunding(_), None) => None,
(CkEth(r), Some(tx)) => {
r.withdrawal_amount.checked_sub(tx.amount).map(|x| x.into())
}
(SweeperFunding(r), Some(tx)) => {
r.withdrawal_amount.checked_sub(tx.amount).map(|x| x.into())
}
(CkErc20(r), _) => Some(r.max_transaction_fee.into()),
},
from: request.from(),
Expand Down Expand Up @@ -832,6 +838,21 @@ fn get_events(arg: GetEventsArg) -> GetEventsResult {
from_subaccount: from_subaccount.map(LedgerSubaccount::to_bytes),
created_at,
},
EventType::AcceptedSweeperFundingRequest(SweeperFundingRequest {
withdrawal_amount,
destination,
ledger_burn_index,
from,
from_subaccount,
created_at,
}) => EP::AcceptedSweeperFundingRequest {
withdrawal_amount: withdrawal_amount.into(),
destination: destination.to_string(),
ledger_burn_index: ledger_burn_index.get().into(),
from,
from_subaccount: from_subaccount.map(LedgerSubaccount::to_bytes),
created_at,
},
EventType::CreatedTransaction {
withdrawal_id,
transaction,
Expand Down
4 changes: 4 additions & 0 deletions rs/ethereum/cketh/minter/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ impl State {
.checked_sub(tx.transaction().amount)
.expect("BUG: withdrawal amount MUST always be at least the transaction amount"),
WithdrawalRequest::CkErc20(req) => req.max_transaction_fee,
WithdrawalRequest::SweeperFunding(req) => req
Comment thread
mbjorkqvist marked this conversation as resolved.
Outdated
.withdrawal_amount
.checked_sub(tx.transaction().amount)
.expect("BUG: funded amount MUST always be at least the transaction amount"),
};
let unspent_tx_fee = charged_tx_fee.checked_sub(tx_fee).expect(
"BUG: charged transaction fee MUST always be at least the effective transaction fee",
Expand Down
5 changes: 5 additions & 0 deletions rs/ethereum/cketh/minter/src/state/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ pub fn apply_state_transition(state: &mut State, payload: &EventType) {
.eth_transactions
.record_withdrawal_request(request.clone());
}
EventType::AcceptedSweeperFundingRequest(request) => {
state
.eth_transactions
.record_withdrawal_request(request.clone());
}
EventType::CreatedTransaction {
withdrawal_id,
transaction,
Expand Down
17 changes: 16 additions & 1 deletion rs/ethereum/cketh/minter/src/state/audit/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl GetEventsFile {
use crate::eth_logs::EventSource;
use crate::state::TransactionStatus;
use crate::state::audit::EventType as ET;
use crate::state::transactions::EthWithdrawalRequest;
use crate::state::transactions::{EthWithdrawalRequest, SweeperFundingRequest};

fn map_event_source(
CandidEventSource {
Expand Down Expand Up @@ -315,6 +315,21 @@ impl GetEventsFile {
from_subaccount: from_subaccount.and_then(LedgerSubaccount::from_bytes),
created_at,
}),
EventPayload::AcceptedSweeperFundingRequest {
withdrawal_amount,
destination,
ledger_burn_index,
from,
from_subaccount,
created_at,
} => ET::AcceptedSweeperFundingRequest(SweeperFundingRequest {
withdrawal_amount: withdrawal_amount.try_into().unwrap(),
destination: destination.parse().unwrap(),
ledger_burn_index: map_nat(ledger_burn_index),
from,
from_subaccount: from_subaccount.and_then(LedgerSubaccount::from_bytes),
created_at,
}),
EventPayload::CreatedTransaction {
withdrawal_id,
transaction,
Expand Down
5 changes: 4 additions & 1 deletion rs/ethereum/cketh/minter/src/state/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::lifecycle::{init::InitArg, upgrade::UpgradeArg};
use crate::numeric::{BlockNumber, Erc20Value, LedgerBurnIndex, LedgerMintIndex};
use crate::state::transactions::{
Erc20WithdrawalRequest, EthWithdrawalRequest, Reimbursed, ReimbursementIndex,
ReimbursementRequest,
ReimbursementRequest, SweeperFundingRequest,
};
use crate::timed_sized_map::Timestamp;
use crate::tx::{Eip1559TransactionRequest, SignedEip1559TransactionRequest};
Expand Down Expand Up @@ -182,6 +182,9 @@ pub enum EventType {
/// durable even across an ungraceful trap (unlike the pre-upgrade snapshot).
#[n(26)]
AutomaticDepositReceived(#[n(0)] AutomaticDeposit),
/// The minter burned ckETH from its fee subaccount to top up the sweeper address with gas.
#[n(27)]
AcceptedSweeperFundingRequest(#[n(0)] SweeperFundingRequest),
Comment thread
mbjorkqvist marked this conversation as resolved.
Outdated
}

/// Full snapshot of the ckERC20 deposit address registry. Carries the limits in
Expand Down
Loading
Loading