Finish merging in the develop branch

This commit is contained in:
Luke Parker
2025-01-30 03:14:24 -05:00
parent 258c02ff39
commit a275023cfc
62 changed files with 452 additions and 508 deletions

View File

@@ -8,7 +8,7 @@ use scale::{Encode, Decode};
use borsh::{BorshSerialize, BorshDeserialize};
use serai_client::{
primitives::{NetworkId, Coin, Amount, Balance},
primitives::{ExternalNetworkId, ExternalCoin, Amount, ExternalBalance},
networks::ethereum::Address,
};
@@ -17,20 +17,20 @@ use ethereum_router::{Coin as EthereumCoin, InInstruction as EthereumInInstructi
use crate::{DAI, ETHER_DUST};
fn coin_to_serai_coin(coin: &EthereumCoin) -> Option<Coin> {
fn coin_to_serai_coin(coin: &EthereumCoin) -> Option<ExternalCoin> {
match coin {
EthereumCoin::Ether => Some(Coin::Ether),
EthereumCoin::Ether => Some(ExternalCoin::Ether),
EthereumCoin::Erc20(token) => {
if *token == DAI {
return Some(Coin::Dai);
return Some(ExternalCoin::Dai);
}
None
}
}
}
fn amount_to_serai_amount(coin: Coin, amount: U256) -> Amount {
assert_eq!(coin.network(), NetworkId::Ethereum);
fn amount_to_serai_amount(coin: ExternalCoin, amount: U256) -> Amount {
assert_eq!(coin.network(), ExternalNetworkId::Ethereum);
assert_eq!(coin.decimals(), 8);
// Remove 10 decimals so we go from 18 decimals to 8 decimals
let divisor = U256::from(10_000_000_000u64);
@@ -119,7 +119,7 @@ impl ReceivedOutput<<Secp256k1 as Ciphersuite>::G, Address> for Output {
}
}
fn balance(&self) -> Balance {
fn balance(&self) -> ExternalBalance {
match self {
Output::Output { key: _, instruction } => {
let coin = coin_to_serai_coin(&instruction.coin).unwrap_or_else(|| {
@@ -128,9 +128,11 @@ impl ReceivedOutput<<Secp256k1 as Ciphersuite>::G, Address> for Output {
"this never should have been yielded"
)
});
Balance { coin, amount: amount_to_serai_amount(coin, instruction.amount) }
ExternalBalance { coin, amount: amount_to_serai_amount(coin, instruction.amount) }
}
Output::Eventuality { .. } => {
ExternalBalance { coin: ExternalCoin::Ether, amount: ETHER_DUST }
}
Output::Eventuality { .. } => Balance { coin: Coin::Ether, amount: ETHER_DUST },
}
}
fn data(&self) -> &[u8] {

View File

@@ -7,7 +7,7 @@ use alloy_transport::{RpcError, TransportErrorKind};
use alloy_simple_request_transport::SimpleRequest;
use alloy_provider::{Provider, RootProvider};
use serai_client::primitives::{NetworkId, Coin, Amount};
use serai_client::primitives::{ExternalNetworkId, ExternalCoin, Amount};
use tokio::task::JoinSet;
@@ -30,7 +30,7 @@ pub(crate) struct Rpc<D: Db> {
}
impl<D: Db> ScannerFeed for Rpc<D> {
const NETWORK: NetworkId = NetworkId::Ethereum;
const NETWORK: ExternalNetworkId = ExternalNetworkId::Ethereum;
// We only need one confirmation as Ethereum properly finalizes
const CONFIRMATIONS: u64 = 1;
@@ -209,22 +209,22 @@ impl<D: Db> ScannerFeed for Rpc<D> {
}
}
fn dust(coin: Coin) -> Amount {
assert_eq!(coin.network(), NetworkId::Ethereum);
fn dust(coin: ExternalCoin) -> Amount {
assert_eq!(coin.network(), ExternalNetworkId::Ethereum);
match coin {
Coin::Ether => ETHER_DUST,
Coin::Dai => DAI_DUST,
ExternalCoin::Ether => ETHER_DUST,
ExternalCoin::Dai => DAI_DUST,
_ => unreachable!(),
}
}
fn cost_to_aggregate(
&self,
coin: Coin,
coin: ExternalCoin,
_reference_block: &Self::Block,
) -> impl Send + Future<Output = Result<Amount, Self::EphemeralError>> {
async move {
assert_eq!(coin.network(), NetworkId::Ethereum);
assert_eq!(coin.network(), ExternalNetworkId::Ethereum);
// There is no cost to aggregate as we receive to an account
Ok(Amount(0))
}

View File

@@ -3,7 +3,7 @@ use std::collections::HashMap;
use alloy_core::primitives::U256;
use serai_client::{
primitives::{NetworkId, Coin, Balance},
primitives::{ExternalNetworkId, ExternalCoin, ExternalBalance},
networks::ethereum::Address,
};
@@ -17,17 +17,17 @@ use ethereum_router::Coin as EthereumCoin;
use crate::{DAI, transaction::Action, rpc::Rpc};
fn coin_to_ethereum_coin(coin: Coin) -> EthereumCoin {
assert_eq!(coin.network(), NetworkId::Ethereum);
fn coin_to_ethereum_coin(coin: ExternalCoin) -> EthereumCoin {
assert_eq!(coin.network(), ExternalNetworkId::Ethereum);
match coin {
Coin::Ether => EthereumCoin::Ether,
Coin::Dai => EthereumCoin::Erc20(DAI),
ExternalCoin::Ether => EthereumCoin::Ether,
ExternalCoin::Dai => EthereumCoin::Erc20(DAI),
_ => unreachable!(),
}
}
fn balance_to_ethereum_amount(balance: Balance) -> U256 {
assert_eq!(balance.coin.network(), NetworkId::Ethereum);
fn balance_to_ethereum_amount(balance: ExternalBalance) -> U256 {
assert_eq!(balance.coin.network(), ExternalNetworkId::Ethereum);
assert_eq!(balance.coin.decimals(), 8);
// Restore 10 decimals so we go from 8 decimals to 18 decimals
// TODO: Document the expectation all integrated coins have 18 decimals
@@ -73,17 +73,17 @@ impl<D: Db> smart_contract_scheduler::SmartContract<Rpc<D>> for SmartContract {
}
let mut res = vec![];
for coin in [Coin::Ether, Coin::Dai] {
for coin in [ExternalCoin::Ether, ExternalCoin::Dai] {
let Some(outs) = outs.remove(&coin) else { continue };
assert!(!outs.is_empty());
let fee_per_gas = match coin {
// 10 gwei
Coin::Ether => {
ExternalCoin::Ether => {
U256::try_from(10u64).unwrap() * alloy_core::primitives::utils::Unit::GWEI.wei()
}
// 0.0003 DAI
Coin::Dai => {
ExternalCoin::Dai => {
U256::try_from(30u64).unwrap() * alloy_core::primitives::utils::Unit::TWEI.wei()
}
_ => unreachable!(),