diff --git a/README.md b/README.md index 6a041e04..9568cff6 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ To run a happy path test of the on-chain contracts plus the off-chain services, f. Retrieve the number saved under "searcherAOwnerSk", convert to a hex string, and save as SEARCHER_SK. You can perform this conversion in Python by calling hex on the number. 5. Create a file `auction-server/config.yaml`. Follow the format in the template `auction-server/config.sample.yaml`. Under the chain `development`, set a. `geth_rpc_addr` to the value stored in ANVIL_RPC_URL - b. `per_contract` to the value stored in MULTICALL - c. `adapter_contract` to the value stored in ADAPTER + b. `express_relay_contract` to the value stored in MULTICALL + c. `opportunity_adapter_contract` to the value stored in ADAPTER 6. Run `cargo run -- run --relayer-private-key ${OPERATOR_SK}` from `auction-server/`. This should start up the auction server. 7. Run `python3 -m per_sdk.protocols.token_vault_monitor --chain-id development --rpc-url ${ANVIL_RPC_URL} --vault-contract ${TOKEN_VAULT} --weth-contract ${WETH} --liquidation-server-url http://localhost:9000/v1/liquidation/opportunities --mock-pyth`. This should start up the monitor script that exposes liquidatable vaults to the liquidation monitor server. 8. Run `python3 -m per_sdk.searcher.simple_searcher --private-key ${SEARCHER_SK} --chain-id development --verbose --liquidation-server-url http://localhost:9000`. diff --git a/per_multicall/src/Errors.sol b/per_multicall/src/Errors.sol index e3e7bc83..cfe376d7 100644 --- a/per_multicall/src/Errors.sol +++ b/per_multicall/src/Errors.sol @@ -29,7 +29,7 @@ error InvalidTimestamp(); error NotRegistered(); // Signature: 0xd3c8346c -error FulfillFailed(string reason); +error ExecutionFailed(string reason); // Signature: 0x4af147aa error InsufficientTokenReceived(); diff --git a/per_multicall/src/OpportunityAdapter.sol b/per_multicall/src/OpportunityAdapter.sol index bc259520..c3252fb5 100644 --- a/per_multicall/src/OpportunityAdapter.sol +++ b/per_multicall/src/OpportunityAdapter.sol @@ -83,7 +83,7 @@ contract OpportunityAdapter is SigVerify { revert SignatureAlreadyUsed(); } - uint256[] memory balancesExpectedReceipt = new uint256[]( + uint256[] memory balancesBuyTokens = new uint256[]( params.buyTokens.length ); @@ -117,9 +117,7 @@ contract OpportunityAdapter is SigVerify { IERC20 token = IERC20(params.buyTokens[i].token); uint256 amount = params.buyTokens[i].amount; - balancesExpectedReceipt[i] = - token.balanceOf(address(this)) + - amount; + balancesBuyTokens[i] = token.balanceOf(address(this)) + amount; } if (params.value > 0) { // unwrap weth to eth to use in call @@ -133,7 +131,7 @@ contract OpportunityAdapter is SigVerify { if (!success) { string memory revertData = _getRevertMsg(reason); - revert FulfillFailed(revertData); + revert ExecutionFailed(revertData); } // check balances of buy tokens after call and transfer to opportunity adapter @@ -142,11 +140,11 @@ contract OpportunityAdapter is SigVerify { uint256 amount = params.buyTokens[i].amount; uint256 balanceFinal = token.balanceOf(address(this)); - if (balanceFinal < balancesExpectedReceipt[i]) { + if (balanceFinal < balancesBuyTokens[i]) { revert InsufficientTokenReceived(); } - // transfer buy tokens to the fulfiller + // transfer buy tokens to the executor token.transfer(params.executor, amount); } diff --git a/per_multicall/test/PERIntegration.t.sol b/per_multicall/test/ExpressRelayIntegration.sol similarity index 98% rename from per_multicall/test/PERIntegration.t.sol rename to per_multicall/test/ExpressRelayIntegration.sol index d1198d96..ab9b4f60 100644 --- a/per_multicall/test/PERIntegration.t.sol +++ b/per_multicall/test/ExpressRelayIntegration.sol @@ -37,7 +37,7 @@ import "./helpers/MulticallHelpers.sol"; * * The focus in these tests is ensuring that liquidation succeeds (or fails as expected) through the ExpressRelay contrct routing to the searcher contracts or the OpportunityAdapter contract. */ -contract PERIntegrationTest is +contract ExpressRelayIntegrationTest is Test, TestParsingHelpers, Signatures, @@ -525,16 +525,17 @@ contract PERIntegrationTest is for (uint i = 0; i < bidInfos.length; i++) { // create liquidation call params struct - bytes memory signatureLiquidator = createLiquidationSignature( - sellTokens, - expectedReceiptTokens, - contractAddress, - calldataVault, - value, - bidInfos[i].bid, - bidInfos[i].validUntil, - bidInfos[i].liquidatorSk - ); + bytes + memory signatureLiquidator = createOpportunityExecutionSignature( + sellTokens, + expectedReceiptTokens, + contractAddress, + calldataVault, + value, + bidInfos[i].bid, + bidInfos[i].validUntil, + bidInfos[i].liquidatorSk + ); ExecutionParams memory liquidationCallParams = ExecutionParams( sellTokens, expectedReceiptTokens, @@ -1166,9 +1167,6 @@ contract PERIntegrationTest is assertEqBalances(balancesBPost, balancesBPre); assertEq(multicallStatuses[0].externalSuccess, true); - assertFailedExternal( - multicallStatuses[1], - "LiquidationCallFailed(string)" - ); + assertFailedExternal(multicallStatuses[1], "ExecutionFailed(string)"); } } diff --git a/per_multicall/test/helpers/Signatures.sol b/per_multicall/test/helpers/Signatures.sol index 543b4eba..9f98c40c 100644 --- a/per_multicall/test/helpers/Signatures.sol +++ b/per_multicall/test/helpers/Signatures.sol @@ -17,38 +17,35 @@ contract Signatures is Test, SigVerify { bytes32 calldataHash = keccak256( abi.encode(dataNumber, bid, validUntil) ); - (uint8 vSearcher, bytes32 rSearcher, bytes32 sSearcher) = vm.sign( - searcherSk, - calldataHash - ); - return abi.encodePacked(rSearcher, sSearcher, vSearcher); + (uint8 v, bytes32 r, bytes32 s) = vm.sign(searcherSk, calldataHash); + return abi.encodePacked(r, s, v); } - function createLiquidationSignature( + function createOpportunityExecutionSignature( TokenAmount[] memory sellTokens, TokenAmount[] memory buyTokens, - address contractAddress, + address target, bytes memory data, uint256 value, uint256 bid, uint256 validUntil, - uint256 liquidatorSk + uint256 executorSk ) public pure returns (bytes memory) { bytes32 calldataDigestLiquidator = keccak256( abi.encode( sellTokens, buyTokens, - contractAddress, + target, data, value, bid, validUntil ) ); - (uint8 vLiquidator, bytes32 rLiquidator, bytes32 sLiquidator) = vm.sign( - liquidatorSk, + (uint8 v, bytes32 r, bytes32 s) = vm.sign( + executorSk, calldataDigestLiquidator ); - return abi.encodePacked(rLiquidator, sLiquidator, vLiquidator); + return abi.encodePacked(r, s, v); } }