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

fix(naming): use target_ for contract/calldata/value #29

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 13 additions & 13 deletions auction-server/src/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ 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.contract).collect(),
winner_bids.iter().map(|b| b.calldata.clone()).collect(),
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(),
)
.await;
Expand Down Expand Up @@ -297,20 +297,20 @@ pub async fn run_submission_loop(store: Arc<Store>) -> Result<()> {
pub struct Bid {
/// The permission key to bid on.
#[schema(example = "0xdeadbeef", value_type=String)]
pub permission_key: Bytes,
pub permission_key: Bytes,
/// The chain id to bid on.
#[schema(example = "sepolia", value_type=String)]
pub chain_id: String,
pub chain_id: String,
/// The contract address to call.
#[schema(example = "0xcA11bde05977b3631167028862bE2a173976CA11",value_type = String)]
pub contract: abi::Address,
pub target_contract: abi::Address,
/// Calldata for the contract call.
#[schema(example = "0xdeadbeef", value_type=String)]
pub calldata: Bytes,
pub target_calldata: Bytes,
/// Amount of bid in wei.
#[schema(example = "10", value_type=String)]
#[serde(with = "crate::serde::u256")]
pub amount: BidAmount,
pub amount: BidAmount,
}

pub async fn handle_bid(store: Arc<Store>, bid: Bid) -> result::Result<Uuid, RestError> {
Expand All @@ -323,8 +323,8 @@ 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.contract],
vec![bid.calldata.clone()],
vec![bid.target_contract],
vec![bid.target_calldata.clone()],
vec![bid.amount],
);

Expand Down Expand Up @@ -354,10 +354,10 @@ pub async fn handle_bid(store: Arc<Store>, bid: Bid) -> result::Result<Uuid, Res
.entry(bid.permission_key.clone())
.or_default()
.push(SimulatedBid {
contract: bid.contract,
calldata: bid.calldata.clone(),
bid_amount: bid.amount,
id: bid_id,
target_contract: bid.target_contract,
target_calldata: bid.target_calldata.clone(),
bid_amount: bid.amount,
id: bid_id,
});
store
.bid_status_store
Expand Down
30 changes: 15 additions & 15 deletions auction-server/src/opportunity_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn get_params_digest(params: ExecutionParams) -> Result<H256> {
params.buy_tokens.into_token(),
params.target_contract.into_token(),
params.target_calldata.into_token(),
params.value.into_token(),
params.target_call_value.into_token(),
params.bid_amount.into_token(),
params.valid_until.into_token(),
]));
Expand Down Expand Up @@ -260,23 +260,23 @@ pub fn make_opportunity_execution_params(
bid: OpportunityBid,
) -> ExecutionParams {
ExecutionParams {
sell_tokens: opportunity
sell_tokens: opportunity
.sell_tokens
.into_iter()
.map(TokenAmount::from)
.collect(),
buy_tokens: opportunity
buy_tokens: opportunity
.buy_tokens
.into_iter()
.map(TokenAmount::from)
.collect(),
executor: bid.executor,
target_contract: opportunity.target_contract,
target_calldata: opportunity.target_calldata,
value: opportunity.value,
valid_until: bid.valid_until,
bid_amount: bid.amount,
signature: bid.signature.to_vec().into(),
executor: bid.executor,
target_contract: opportunity.target_contract,
target_calldata: opportunity.target_calldata,
target_call_value: opportunity.target_call_value,
valid_until: bid.valid_until,
bid_amount: bid.amount,
signature: bid.signature.to_vec().into(),
}
}

Expand Down Expand Up @@ -447,11 +447,11 @@ pub async fn handle_opportunity_bid(
match handle_bid(
store.clone(),
Bid {
permission_key: params.permission_key.clone(),
chain_id: params.chain_id.clone(),
contract: chain_store.config.opportunity_adapter_contract,
calldata: adapter_calldata,
amount: opportunity_bid.amount,
permission_key: params.permission_key.clone(),
chain_id: params.chain_id.clone(),
target_contract: chain_store.config.opportunity_adapter_contract,
target_calldata: adapter_calldata,
amount: opportunity_bid.amount,
},
)
.await
Expand Down
18 changes: 9 additions & 9 deletions auction-server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ pub type BidAmount = U256;

#[derive(Clone)]
pub struct SimulatedBid {
pub id: BidId,
pub contract: Address,
pub calldata: Bytes,
pub bid_amount: BidAmount,
pub id: BidId,
pub target_contract: Address,
pub target_calldata: Bytes,
pub bid_amount: BidAmount,
// simulation_time:
}

Expand All @@ -75,20 +75,20 @@ pub struct TokenAmount {
pub struct OpportunityParamsV1 {
/// The permission key required for successful execution of the opportunity.
#[schema(example = "0xdeadbeefcafe", value_type=String)]
pub permission_key: Bytes,
pub permission_key: Bytes,
/// The chain id where the opportunity will be executed.
#[schema(example = "sepolia", value_type=String)]
pub chain_id: ChainId,
pub chain_id: ChainId,
/// The contract address to call for execution of the opportunity.
#[schema(example = "0xcA11bde05977b3631167028862bE2a173976CA11", value_type=String)]
pub target_contract: ethers::abi::Address,
pub target_contract: ethers::abi::Address,
/// Calldata for the target contract call.
#[schema(example = "0xdeadbeef", value_type=String)]
pub target_calldata: Bytes,
pub target_calldata: Bytes,
/// The value to send with the contract call.
#[schema(example = "1", value_type=String)]
#[serde(with = "crate::serde::u256")]
pub value: U256,
pub target_call_value: U256,

pub sell_tokens: Vec<TokenAmount>,
pub buy_tokens: Vec<TokenAmount>,
Expand Down
14 changes: 7 additions & 7 deletions per_multicall/src/OpportunityAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract OpportunityAdapter is SigVerify {
params.buyTokens,
params.targetContract,
params.targetCalldata,
params.value,
params.targetCallValue,
params.bidAmount,
params.validUntil
),
Expand Down Expand Up @@ -101,10 +101,10 @@ contract OpportunityAdapter is SigVerify {
// approve contract to spend sell tokens
uint256 approveAmount = params.sellTokens[i].amount;
if (params.sellTokens[i].token == weth) {
if (approveAmount >= params.value) {
// we need `parmas.value` of to be sent to the contract directly
if (approveAmount >= params.targetCallValue) {
// we need `parmas.targetCallValue` of to be sent to the contract directly
// so this amount should be subtracted from the approveAmount
approveAmount = approveAmount - params.value;
approveAmount = approveAmount - params.targetCallValue;
} else {
revert InsufficientWETHForMsgValue();
}
Expand All @@ -119,14 +119,14 @@ contract OpportunityAdapter is SigVerify {

balancesBuyTokens[i] = token.balanceOf(address(this)) + amount;
}
if (params.value > 0) {
if (params.targetCallValue > 0) {
// unwrap weth to eth to use in call
// TODO: Wrap in try catch and throw a revert with a better error since WETH9 reverts do not return a reason
WETH9(payable(weth)).withdraw(params.value);
WETH9(payable(weth)).withdraw(params.targetCallValue);
}

(bool success, bytes memory reason) = params.targetContract.call{
value: params.value
value: params.targetCallValue
}(params.targetCalldata);

if (!success) {
Expand Down
2 changes: 1 addition & 1 deletion per_multicall/src/Structs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct ExecutionParams {
address executor;
address targetContract;
bytes targetCalldata;
uint256 value;
uint256 targetCallValue;
uint256 validUntil;
uint256 bidAmount;
bytes signature;
Expand Down
2 changes: 1 addition & 1 deletion per_sdk/protocols/token_vault_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def create_liquidation_opp(
"target_calldata": calldata,
"permission_key": permission,
"account": str(account["account_number"]),
"value": str(call_value),
"target_call_value": str(call_value),
"sell_tokens": sell_tokens,
"buy_tokens": [
(account["token_address_collateral"], str(account["amount_collateral"]))
Expand Down
2 changes: 1 addition & 1 deletion per_sdk/searcher/simple_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def create_liquidation_transaction(
buy_tokens,
opp["target_contract"],
liq_calldata,
int(opp["value"]),
int(opp["target_call_value"]),
bid_info,
sk_liquidator,
)
Expand Down
2 changes: 1 addition & 1 deletion per_sdk/utils/types_liquidation_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Opportunity(TypedDict):
# The calldata that needs to be passed in with the liquidation method call
target_calldata: str
# The value that needs to be passed in with the liquidation method call
value: str
target_call_value: str
# The permission key necessary to call the liquidation method
permission_key: str
# A list of tokens that can be used to repay this account's debt.
Expand Down
Loading