Custom Searcher Contract
Searchers can use their in-house custom contracts to execute the opportunities Express Relay provides. In this case, they must construct the bids based on the opportunity details.
Refer to the following example of a custom contract that executes liquidation transactions:
...
function callLiquidation(Opportunity memory opp){
for (uint i=0; i<opp.sell_tokens.length; i++) {
let token = opp.sell_tokens[i];
IERC20(token.contract).approve(opp.contract, token.amount);
}
uint256[] before = new uint256[](opp.buy_tokens.length);
for (uint j=0; j<opp.buy_tokens.length; j++) {
let token = opp.buy_tokens[j];
before = IERC20(token.contract).balanceOf(address(this));
}
opp.target_contract.call{value: opp.target_call_value}(opp.target_calldata);
uint256[] after = new uint256[](opp.buy_tokens.length);
for (uint j=0; j<opp.buy_tokens.length; j++) {
let token = opp.buy_tokens[j];
after = IERC20(token.target_contract).balanceOf(address(this));
assert(after[j] == before[j] + token.amount);
}
}
...
ℹ️
Make sure to allow the Express Relay contract to call the relevant methods in your custom contract.
Last updated on