mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Get all processors to compile again
Requires splitting `serai-cosign` into `serai-cosign` and `serai-cosign-types` so the processor don't require `serai-client/serai` (not correct yet).
This commit is contained in:
@@ -41,7 +41,6 @@ ethereum-primitives = { package = "serai-processor-ethereum-primitives", path =
|
||||
ethereum-deployer = { package = "serai-processor-ethereum-deployer", path = "../deployer", default-features = false }
|
||||
erc20 = { package = "serai-processor-ethereum-erc20", path = "../erc20", default-features = false }
|
||||
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std"] }
|
||||
serai-client = { path = "../../../substrate/client", default-features = false, features = ["ethereum"] }
|
||||
|
||||
futures-util = { version = "0.3", default-features = false, features = ["std"] }
|
||||
|
||||
@@ -19,7 +19,7 @@ interface IRouterWithoutCollisions {
|
||||
/// @param from The address which called `inInstruction` and caused this event to be emitted
|
||||
/// @param coin The coin transferred in
|
||||
/// @param amount The amount of the coin transferred in
|
||||
/// @param instruction The Shorthand-encoded InInstruction for Serai to decode and handle
|
||||
/// @param instruction The encoded `RefundableInInstruction` for Serai to decode and handle
|
||||
event InInstruction(
|
||||
address indexed from, address indexed coin, uint256 amount, bytes instruction
|
||||
);
|
||||
@@ -81,8 +81,8 @@ interface IRouterWithoutCollisions {
|
||||
/// @param coin The coin to transfer in (address(0) if Ether)
|
||||
/// @param amount The amount to transfer in (msg.value if Ether)
|
||||
/**
|
||||
* @param instruction The Shorthand-encoded InInstruction for Serai to associate with this
|
||||
* transfer in
|
||||
* @param instruction The encoded `RefundableInInstruction` for Serai to associate with this
|
||||
* transfer in
|
||||
*/
|
||||
// Re-entrancy doesn't bork this function
|
||||
// slither-disable-next-line reentrancy-events
|
||||
|
||||
@@ -293,7 +293,7 @@ contract Router is IRouterWithoutCollisions {
|
||||
/// @param coin The coin to transfer in (address(0) if Ether)
|
||||
/// @param amount The amount to transfer in (msg.value if Ether)
|
||||
/**
|
||||
* @param instruction The Shorthand-encoded InInstruction for Serai to associate with this
|
||||
* @param instruction The encoded `RefundableInInstruction` for Serai to associate with this
|
||||
* transfer in
|
||||
*/
|
||||
// This function doesn't require nonReentrant as re-entrancy isn't an issue with this function
|
||||
|
||||
@@ -21,9 +21,8 @@ use alloy_rpc_types_eth::{BlockId, Log, Filter, TransactionInput, TransactionReq
|
||||
use alloy_transport::{TransportErrorKind, RpcError};
|
||||
use alloy_provider::{Provider, RootProvider};
|
||||
|
||||
use scale::Encode;
|
||||
use serai_client::{
|
||||
in_instructions::primitives::Shorthand, networks::ethereum::Address as SeraiAddress,
|
||||
primitives::instructions::RefundableInInstruction, networks::ethereum::Address as SeraiAddress,
|
||||
};
|
||||
|
||||
use ethereum_primitives::LogIndex;
|
||||
@@ -351,20 +350,29 @@ impl Router {
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a transaction to send coins with an InInstruction to Serai.
|
||||
/// Construct a transaction to send coins with an `InInstruction` to Serai.
|
||||
///
|
||||
/// If coin is an ERC20, this will not create a transaction calling the Router but will create a
|
||||
/// top-level transfer of the ERC20 to the Router. This avoids needing to call `approve` before
|
||||
/// publishing the transaction calling the Router.
|
||||
///
|
||||
/// The gas limit and gas price are not set and are left to the caller.
|
||||
pub fn in_instruction(&self, coin: Coin, amount: U256, in_instruction: &Shorthand) -> TxLegacy {
|
||||
pub fn in_instruction(
|
||||
&self,
|
||||
coin: Coin,
|
||||
amount: U256,
|
||||
in_instruction: &RefundableInInstruction,
|
||||
) -> TxLegacy {
|
||||
match coin {
|
||||
Coin::Ether => TxLegacy {
|
||||
to: self.address.into(),
|
||||
input: abi::inInstructionCall::new((coin.into(), amount, in_instruction.encode().into()))
|
||||
.abi_encode()
|
||||
.into(),
|
||||
input: abi::inInstructionCall::new((
|
||||
coin.into(),
|
||||
amount,
|
||||
borsh::to_vec(&in_instruction).unwrap().into(),
|
||||
))
|
||||
.abi_encode()
|
||||
.into(),
|
||||
value: amount,
|
||||
..Default::default()
|
||||
},
|
||||
@@ -373,7 +381,7 @@ impl Router {
|
||||
input: erc20::transferWithInInstructionCall::new((
|
||||
self.address,
|
||||
amount,
|
||||
in_instruction.encode().into(),
|
||||
borsh::to_vec(&in_instruction).unwrap().into(),
|
||||
))
|
||||
.abi_encode()
|
||||
.into(),
|
||||
|
||||
@@ -5,12 +5,9 @@ use alloy_sol_types::SolCall;
|
||||
|
||||
use alloy_consensus::{TxLegacy, Signed};
|
||||
|
||||
use scale::Encode;
|
||||
use serai_client::{
|
||||
primitives::SeraiAddress,
|
||||
in_instructions::primitives::{
|
||||
InInstruction as SeraiInInstruction, RefundableInInstruction, Shorthand,
|
||||
},
|
||||
primitives::instructions::{InInstruction as SeraiInInstruction, RefundableInInstruction},
|
||||
};
|
||||
|
||||
use ethereum_primitives::LogIndex;
|
||||
@@ -18,14 +15,14 @@ use ethereum_primitives::LogIndex;
|
||||
use crate::{InInstruction, tests::*};
|
||||
|
||||
impl Test {
|
||||
pub(crate) fn in_instruction() -> Shorthand {
|
||||
Shorthand::Raw(RefundableInInstruction {
|
||||
pub(crate) fn in_instruction() -> RefundableInInstruction {
|
||||
RefundableInInstruction {
|
||||
origin: None,
|
||||
instruction: SeraiInInstruction::Transfer(SeraiAddress([0xff; 32])),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn eth_in_instruction_tx(&self) -> (Coin, U256, Shorthand, TxLegacy) {
|
||||
pub(crate) fn eth_in_instruction_tx(&self) -> (Coin, U256, RefundableInInstruction, TxLegacy) {
|
||||
let coin = Coin::Ether;
|
||||
let amount = U256::from(1);
|
||||
let shorthand = Self::in_instruction();
|
||||
@@ -42,7 +39,7 @@ impl Test {
|
||||
tx: Signed<TxLegacy>,
|
||||
coin: Coin,
|
||||
amount: U256,
|
||||
shorthand: &Shorthand,
|
||||
shorthand: &RefundableInInstruction,
|
||||
) {
|
||||
let receipt = ethereum_test_primitives::publish_tx(&self.provider, tx.clone()).await;
|
||||
assert!(receipt.status());
|
||||
@@ -81,7 +78,7 @@ impl Test {
|
||||
from: tx.recover_signer().unwrap(),
|
||||
coin,
|
||||
amount,
|
||||
data: shorthand.encode(),
|
||||
data: borsh::to_vec(&shorthand).unwrap(),
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -140,9 +137,13 @@ async fn test_erc20_router_in_instruction() {
|
||||
gas_limit: 1_000_000,
|
||||
to: test.router.address().into(),
|
||||
value: U256::ZERO,
|
||||
input: crate::abi::inInstructionCall::new((coin.into(), amount, shorthand.encode().into()))
|
||||
.abi_encode()
|
||||
.into(),
|
||||
input: crate::abi::inInstructionCall::new((
|
||||
coin.into(),
|
||||
amount,
|
||||
borsh::to_vec(shorthand).unwrap().into(),
|
||||
))
|
||||
.abi_encode()
|
||||
.into(),
|
||||
};
|
||||
|
||||
// If no `approve` was granted, this should fail
|
||||
|
||||
Reference in New Issue
Block a user