Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity clarification #35

Merged
merged 13 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
49 changes: 13 additions & 36 deletions auction-server/src/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,14 @@ pub fn get_simulation_call(
provider: Provider<Http>,
chain_config: EthereumConfig,
permission_key: Bytes,
target_contracts: Vec<Address>,
target_calldata: Vec<Bytes>,
bid_amounts: Vec<BidAmount>,
multicall_data: Vec<MulticallData>,
) -> FunctionCall<Arc<Provider<Http>>, Provider<Http>, Vec<MulticallStatus>> {
let client = Arc::new(provider);
let express_relay_contract =
ExpressRelayContract::new(chain_config.express_relay_contract, client);

express_relay_contract
.multicall(
permission_key,
target_contracts,
target_calldata,
bid_amounts,
)
.multicall(permission_key, multicall_data)
.from(relayer)
}

Expand All @@ -135,19 +128,9 @@ pub async fn simulate_bids(
provider: Provider<Http>,
chain_config: EthereumConfig,
permission: Bytes,
target_contracts: Vec<Address>,
target_calldata: Vec<Bytes>,
bid_amounts: Vec<BidAmount>,
multicall_data: Vec<MulticallData>,
) -> Result<(), SimulationError> {
let call = get_simulation_call(
relayer,
provider,
chain_config,
permission,
target_contracts,
target_calldata,
bid_amounts,
);
let call = get_simulation_call(relayer, provider, chain_config, permission, multicall_data);
match call.await {
Ok(results) => {
evaluate_simulation_results(results)?;
Expand Down Expand Up @@ -189,9 +172,7 @@ pub async fn submit_bids(
chain_config: EthereumConfig,
network_id: u64,
permission: Bytes,
target_contracts: Vec<Address>,
target_calldata: Vec<Bytes>,
bid_amounts: Vec<BidAmount>,
multicall_data: Vec<MulticallData>,
) -> Result<Option<TransactionReceipt>, SubmissionError> {
let transformer = LegacyTxTransformer {
use_legacy_tx: chain_config.legacy_tx,
Expand All @@ -203,12 +184,8 @@ pub async fn submit_bids(

let express_relay_contract =
SignableExpressRelayContract::new(chain_config.express_relay_contract, client);
let call = express_relay_contract.multicall(
permission,
target_contracts,
target_calldata,
bid_amounts,
);

let call = express_relay_contract.multicall(permission, multicall_data);
let mut gas_estimate = call
.estimate_gas()
.await
Expand Down Expand Up @@ -255,9 +232,7 @@ pub async fn run_submission_loop(store: Arc<Store>) -> Result<()> {
chain_store.config.clone(),
chain_store.network_id,
permission_key.clone(),
winner_bids.iter().map(|b| b.target_contract).collect(),
winner_bids.iter().map(|b| b.target_calldata.clone()).collect(),
winner_bids.iter().map(|b| b.bid_amount).collect(),
winner_bids.iter().map(|b| MulticallData{target_contract: b.target_contract, target_calldata: b.target_calldata.clone(), bid_amount: b.bid_amount }).collect()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can implement the From trait for MulticallData so that the conversion logic is just implemented once.

)
.await;
match submission {
Expand Down Expand Up @@ -323,9 +298,11 @@ pub async fn handle_bid(store: Arc<Store>, bid: Bid) -> result::Result<Uuid, Res
chain_store.provider.clone(),
chain_store.config.clone(),
bid.permission_key.clone(),
vec![bid.target_contract],
vec![bid.target_calldata.clone()],
vec![bid.amount],
vec![MulticallData {
target_contract: bid.target_contract,
target_calldata: bid.target_calldata.clone(),
bid_amount: bid.amount,
}],
);

if let Err(e) = call.await {
Expand Down
9 changes: 6 additions & 3 deletions auction-server/src/opportunity_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
get_simulation_call,
handle_bid,
Bid,
MulticallData,
MulticallReturn,
},
server::{
Expand Down Expand Up @@ -140,9 +141,11 @@ pub async fn verify_opportunity(
chain_store.provider.clone(),
chain_store.config.clone(),
opportunity.permission_key,
vec![chain_store.config.opportunity_adapter_contract],
vec![adapter_calldata],
vec![fake_bid.amount],
vec![MulticallData {
target_contract: chain_store.config.opportunity_adapter_contract,
target_calldata: adapter_calldata.clone(),
bid_amount: fake_bid.amount,
}],
)
.tx;
let mut state = spoof::State::default();
Expand Down
29 changes: 19 additions & 10 deletions per_multicall/script/Vault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,23 @@ contract VaultScript is Script {

function deployExpressRelay() public returns (address) {
(, uint256 skDeployer) = getDeployer();
(address operatorAddress, uint256 operatorSk) = makeAddrAndKey(
"perOperator"
);
console.log("pk per operator", operatorAddress);
console.log("sk per operator", operatorSk);
(address relayer, uint256 relayerSk) = makeAddrAndKey("relayer");
// TODO: set admin to different address than relayer
address admin = relayer;
console.log("pk relayer", relayer);
console.log("sk relayer", relayerSk);
// since feeSplitPrecision is set to 10 ** 18, this represents ~50% of the fees
uint256 feeSplitProtocolDefault = 50 * (10 ** 16);
m30m marked this conversation as resolved.
Show resolved Hide resolved
// ~5% (10% of the remaining 50%) of the fees go to the relayer
uint256 feeSplitRelayer = 10 * (10 ** 16);
vm.startBroadcast(skDeployer);
payable(operatorAddress).transfer(0.01 ether);
ExpressRelay multicall = new ExpressRelay(operatorAddress, 0);
payable(relayer).transfer(0.01 ether);
ExpressRelay multicall = new ExpressRelay(
admin,
relayer,
feeSplitProtocolDefault,
feeSplitRelayer
);
vm.stopBroadcast();
console.log("deployed ExpressRelay contract at", address(multicall));
return address(multicall);
Expand Down Expand Up @@ -247,8 +256,8 @@ contract VaultScript is Script {
(addressesScript[2], sksScript[2]) = makeAddrAndKey("depositor");
console.log("sk depositor", sksScript[2]);

// make perOperator wallet
(addressesScript[3], sksScript[3]) = makeAddrAndKey("perOperator");
// make relayer wallet
(addressesScript[3], sksScript[3]) = makeAddrAndKey("relayer");

// make tokenVaultDeployer wallet
(addressesScript[4], sksScript[4]) = makeAddrAndKey(
Expand Down Expand Up @@ -309,7 +318,7 @@ contract VaultScript is Script {

// instantiate ERC-20 tokens
vm.startBroadcast(sksScript[3]);
console.log("balance of pk perOperator", addressesScript[3].balance);
console.log("balance of pk relayer", addressesScript[3].balance);

// create token price feed IDs--see https://pyth.network/developers/price-feed-ids
// TODO: automate converting bytes32 to string
Expand Down
3 changes: 3 additions & 0 deletions per_multicall/src/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ error InvalidSignatureLength();
// The new contract does not have the same magic value as the old one.
// Signature: 0x4ed848c1
error InvalidMagicValue();

// Signature: 0x0601f697
error InvalidFeeSplit();
Loading
Loading