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

Testing merge into refactored #7

Open
wants to merge 123 commits into
base: refactored
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
8149f08
Create solhint.yml
gul-hameed Oct 13, 2023
22cf237
Create .solhint.json
gul-hameed Oct 13, 2023
1d1aa5a
Update solhint.yml
gul-hameed Oct 13, 2023
668dbe8
Update solhint.yml
gul-hameed Oct 13, 2023
90135a8
Create slither.yml
gul-hameed Oct 13, 2023
1fdd5ca
Create test.t.sol
gul-hameed Oct 13, 2023
d05f849
Create foundry-test.yml
gul-hameed Oct 13, 2023
817de06
Update slither.yml
gul-hameed Oct 17, 2023
f9974c0
Update slither.yml
gul-hameed Oct 17, 2023
c5b1471
Update slither.yml
0xabdullah0 Oct 18, 2023
dcd1eb5
Update slither.yml
0xabdullah0 Oct 18, 2023
b55ccbe
Update slither.yml
0xabdullah0 Oct 18, 2023
07cde01
Update slither.yml
gul-hameed Oct 18, 2023
d717453
Update solhint.yml
gul-hameed Oct 18, 2023
93336cc
Update foundry-test.yml
gul-hameed Oct 18, 2023
56c276b
Update slither.yml
gul-hameed Oct 19, 2023
3699288
Update slither.yml
gul-hameed Oct 19, 2023
019b319
Update slither.yml
gul-hameed Oct 19, 2023
da3e81a
Update slither.yml
gul-hameed Oct 19, 2023
8ddb6cb
Update slither.yml
gul-hameed Oct 19, 2023
8528bf7
Update slither.yml
gul-hameed Oct 19, 2023
9544af4
Update slither.yml
gul-hameed Oct 23, 2023
20a82a0
Update slither.yml
gul-hameed Oct 23, 2023
0199209
Create slither-output.txt
gul-hameed Oct 25, 2023
3ee2f0c
Update slither.yml
gul-hameed Oct 26, 2023
a1d0e5a
Update Slither analysis output
actions-user Oct 26, 2023
968bac4
tests + Index out of bounds fix
HareemSaad Nov 24, 2023
b95ced4
predicate address and fee collector tests
HareemSaad Nov 24, 2023
26bd259
fill order happypath
HareemSaad Nov 24, 2023
3a3af8b
manual pull
HareemSaad Nov 24, 2023
591120a
interfaces
HareemSaad Nov 24, 2023
a7d6204
setup + input fix
HareemSaad Nov 24, 2023
c80dda3
order engine
HareemSaad Nov 24, 2023
0e09306
fee collector fix
HareemSaad Nov 24, 2023
d932765
state check
HareemSaad Nov 24, 2023
07b89e2
script
HareemSaad Nov 24, 2023
d6924e9
live contract test
HareemSaad Nov 25, 2023
ca31acf
transaction script
HareemSaad Nov 25, 2023
a9ada68
input tests
HareemSaad Nov 26, 2023
b20b703
input cleanup
HareemSaad Nov 27, 2023
e53f4d5
test validateOrder
HareemSaad Nov 27, 2023
cb4760a
new deploy and verify
HareemSaad Nov 27, 2023
dec9e37
clean up
HareemSaad Nov 27, 2023
c84c2df
cleanup
HareemSaad Nov 27, 2023
64f0d8f
partially fillable order test
HareemSaad Nov 27, 2023
13f0041
test fill or kill
HareemSaad Nov 27, 2023
66d5d7c
partially fill exceed order amount
HareemSaad Nov 27, 2023
d8a8bc7
predicate tests
HareemSaad Nov 27, 2023
beba2ac
fix
HareemSaad Nov 27, 2023
65ae0c6
drain test
HareemSaad Nov 27, 2023
09f1801
cleanup
HareemSaad Nov 28, 2023
e3deda1
Asymetric order (invariant-contract holds balance)
HareemSaad Nov 28, 2023
4705f5a
cancel order tests
HareemSaad Nov 28, 2023
6355ae8
due to leftover tokens, drain is possible with interactions
HareemSaad Nov 28, 2023
4c0e0bb
pre interacttion
HareemSaad Nov 28, 2023
88585a6
drain test fix
HareemSaad Nov 29, 2023
ec2db93
Test Facilatator Interaction Borrowed Amounts
HareemSaad Nov 29, 2023
7ec6109
import fix
HareemSaad Nov 29, 2023
e2ea369
asymetric order with 1 SO fill or kill & 1 partial
HareemSaad Nov 29, 2023
ef32619
fill partial order in chunks
HareemSaad Nov 29, 2023
fb3c1b6
OR & AND Predicate Tests
HareemSaad Nov 29, 2023
c5fd4f7
cleanup
HareemSaad Nov 29, 2023
8923a08
settle single order using facilitator interaction
HareemSaad Nov 30, 2023
d36f811
ring order
HareemSaad Nov 30, 2023
c0bcaee
ensures sellToken != buyToken
HareemSaad Nov 30, 2023
336d011
withdraw functionality
HareemSaad Nov 30, 2023
b007c27
facilitator swap logic contract upgrade
HareemSaad Nov 30, 2023
34b1f89
test summary
HareemSaad Dec 4, 2023
8d3914f
fix
HareemSaad Dec 4, 2023
a9847a9
fix
HareemSaad Dec 4, 2023
e34d22f
Create slither.yml
gul-hameed Dec 4, 2023
ceafb6a
Create slither-output.txt
gul-hameed Dec 4, 2023
15e294e
Update slither.yml
gul-hameed Dec 4, 2023
4272c7d
Delete slither-output.txt
gul-hameed Dec 4, 2023
6bdf4a9
Create slither-output.txt
gul-hameed Dec 4, 2023
23bdc67
Update slither.yml
gul-hameed Dec 4, 2023
def8194
Update slither.yml
gul-hameed Dec 4, 2023
660b1e3
Update slither.yml
gul-hameed Dec 4, 2023
a6fc0be
Delete slither-output.txt
gul-hameed Dec 4, 2023
ad94521
Update slither.yml
gul-hameed Dec 4, 2023
9f99b78
Update Slither analysis output
actions-user Dec 4, 2023
2c1ee2f
Update slither.yml
gul-hameed Dec 4, 2023
aa564d6
Update slither.yml
gul-hameed Dec 4, 2023
156144f
Update slither.yml
gul-hameed Dec 4, 2023
f111a08
Delete .github directory
gul-hameed Dec 4, 2023
8c89c1d
Create slither-analysis.yml
gul-hameed Dec 4, 2023
4e39178
Update slither-analysis.yml
gul-hameed Dec 4, 2023
e931569
Update slither-analysis.yml
gul-hameed Dec 4, 2023
3628918
Update slither-analysis.yml
gul-hameed Dec 4, 2023
04941c6
Update slither-analysis.yml
gul-hameed Dec 4, 2023
a421d8e
Update slither-analysis.yml
gul-hameed Dec 4, 2023
8fcf93f
Update slither-analysis.yml
gul-hameed Dec 4, 2023
aa2f627
Update slither-analysis.yml
gul-hameed Dec 4, 2023
cc0e994
Update slither-analysis.yml
gul-hameed Dec 4, 2023
e63767a
Added Invariants
0xabdullah0 Dec 5, 2023
e68149c
stress test
HareemSaad Dec 7, 2023
cf0e82d
comment fix
HareemSaad Dec 7, 2023
de5df3f
removed status check in updateTokenWhitelist
HareemSaad Dec 7, 2023
f02f8a1
qouter interface
HareemSaad Dec 8, 2023
4938480
facilitator swap usingexact input
HareemSaad Dec 8, 2023
5ceee3f
fix
HareemSaad Dec 9, 2023
75e88b7
fee fix
HareemSaad Dec 20, 2023
dca82ce
new pegasus deploy
HareemSaad Dec 20, 2023
6686cdc
deploy on sepolia
HareemSaad Dec 20, 2023
951d56e
OrderFill event update
HareemSaad Dec 21, 2023
440a4a9
new deploy
HareemSaad Dec 21, 2023
efa8b6a
select fork
HareemSaad Feb 2, 2024
2290b4d
Breaking Change - Precicison Loss: executedAmounts to be sent in (upt…
HareemSaad Feb 2, 2024
ca4fec6
new deploy
HareemSaad Feb 2, 2024
3d1dbf6
fix
HareemSaad Feb 2, 2024
c222e9e
rem file
HareemSaad Feb 2, 2024
804c9ff
rem file
HareemSaad Feb 2, 2024
6f5f83b
Update slither.yml
gul-hameed Feb 7, 2024
46b9f23
helper functions
HareemSaad Feb 7, 2024
666942b
update test command
HareemSaad Feb 8, 2024
30027d6
Merge branch 'development' into testing
HareemSaad Feb 9, 2024
ffb7ef2
shift token type from IERC20 to address for type hashing compatibilit…
HareemSaad Mar 13, 2024
fbc8dfb
update deploy script
HareemSaad Mar 13, 2024
96d70ed
new deploy
HareemSaad Mar 13, 2024
8700faf
pheonix deploy
HareemSaad Apr 3, 2024
dd7991d
Minimum fee threshhold
HareemSaad Apr 3, 2024
9a9f020
Max fee cap
HareemSaad Apr 3, 2024
969c917
facilatator mainnet deploy
HareemSaad Apr 5, 2024
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
Prev Previous commit
Next Next commit
predicate tests
  • Loading branch information
HareemSaad committed Nov 27, 2023
commit d8a8bc7c0205ee9c15a3db8995a61dd4c60311d8
138 changes: 138 additions & 0 deletions test/AdvancedOrderEngine.t.sol
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import "./../src/libraries/OrderEngine.sol";
import "./../src/Helper/GenerateCalldata.sol";
import "./interfaces/swaprouter.sol";
import "./interfaces/weth9.sol";
import "./interfaces/pricefeed.sol";
import "openzeppelin/token/ERC20/IERC20.sol";
import "openzeppelin/utils/cryptography/ECDSA.sol";

@@ -21,6 +22,7 @@ contract AdvancedOrderEngineTest is Test {
IERC20 usdc = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
IERC20 weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
ISwapRouter02 swapRouter02 = ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45);
IPriceFeed usdc_eth = IPriceFeed(0x986b5E1e1755e3C2440e960477f25201B0a8bbD4);
address zeroAddress = address(0);
address feeCollector = address(147578);
address admin = address(3);
@@ -776,6 +778,138 @@ contract AdvancedOrderEngineTest is Test {
vm.stopPrank();
}

function testPredicateFail() public {


// English: Only allow order execution if the return value from an arbitrary call is greater than some contraint.
// Predicate: gt(constraint(99999 * 10 ** 18), arbitraryStaticCall(targetAddress, callDataToSendToTargetAddress))

// Step 1: Generate calldata to send to our target contract
bytes memory targetContractCalldata = abi.encodeWithSelector(
usdc_eth.latestAnswer.selector
); // 'callDataToSendToTargetAddress'

// Step 2: Generate predicates contract "arbitrary static call" function calldata
bytes memory arbitraryStaticCalldata = abi.encodeWithSignature(
"arbitraryStaticCall(address,bytes)",
address(usdc_eth),
targetContractCalldata
); // arbitraryStaticCall(targetAddress, callDataToSendToTargetAddress)

// Step 3: Generate predicates contract "lt" function calldata
bytes memory ltFnCalldata = abi.encodeWithSignature(
"gt(uint256,bytes)",
_oraclePrice(),
arbitraryStaticCalldata
); // lt(15, arbitraryS
// generateCalldata1

vm.startPrank(operator);

(
OrderEngine.Order[] memory orders,
uint256[] memory sell,
uint256[] memory buy,
bytes[] memory signatures,
bytes memory facilitatorInteraction,
IERC20[] memory borrowedTokens,
uint256[] memory borrowedAmounts,
OrderEngine.Order memory buyOrder,
OrderEngine.Order memory sellOrder
) = getStandardInput();

orders[0].predicateCalldata = ltFnCalldata;
orders[1].predicateCalldata = ltFnCalldata;

(uint8 v, bytes32 r, bytes32 s) = vm.sign(maker2PrivateKey, _hashTypedDataV4(OrderEngine.hash(sellOrder)));
bytes memory sellOrderSignature = abi.encodePacked(r, s, v);

(v, r, s) = vm.sign(maker1PrivateKey, _hashTypedDataV4(OrderEngine.hash(buyOrder)));
bytes memory buyOrderSignature = abi.encodePacked(r, s, v);

signatures[0] = sellOrderSignature;
signatures[1] = buyOrderSignature;

vm.expectRevert(PredicateIsNotTrue.selector);
advancedOrderEngine.fillOrders(
orders,
sell,
buy,
signatures,
facilitatorInteraction,
borrowedTokens,
borrowedAmounts
);

vm.stopPrank();
}

function testPredicate() public {


// English: Only allow order execution if the return value from an arbitrary call is greater than some contraint.
// Predicate: gt(constraint(99999 * 10 ** 18), arbitraryStaticCall(targetAddress, callDataToSendToTargetAddress))

// Step 1: Generate calldata to send to our target contract
bytes memory targetContractCalldata = abi.encodeWithSelector(
usdc_eth.latestAnswer.selector
); // 'callDataToSendToTargetAddress'

// Step 2: Generate predicates contract "arbitrary static call" function calldata
bytes memory arbitraryStaticCalldata = abi.encodeWithSignature(
"arbitraryStaticCall(address,bytes)",
address(usdc_eth),
targetContractCalldata
); // arbitraryStaticCall(targetAddress, callDataToSendToTargetAddress)

// Step 3: Generate predicates contract "lt" function calldata
bytes memory ltFnCalldata = abi.encodeWithSignature(
"lt(uint256,bytes)",
_oraclePrice(),
arbitraryStaticCalldata
); // lt(15, arbitraryS
// generateCalldata1

vm.startPrank(operator);

(
OrderEngine.Order[] memory orders,
uint256[] memory sell,
uint256[] memory buy,
bytes[] memory signatures,
bytes memory facilitatorInteraction,
IERC20[] memory borrowedTokens,
uint256[] memory borrowedAmounts,
OrderEngine.Order memory buyOrder,
OrderEngine.Order memory sellOrder
) = getStandardInput();

orders[0].predicateCalldata = ltFnCalldata;
orders[1].predicateCalldata = ltFnCalldata;

(uint8 v, bytes32 r, bytes32 s) = vm.sign(maker2PrivateKey, _hashTypedDataV4(OrderEngine.hash(sellOrder)));
bytes memory sellOrderSignature = abi.encodePacked(r, s, v);

(v, r, s) = vm.sign(maker1PrivateKey, _hashTypedDataV4(OrderEngine.hash(buyOrder)));
bytes memory buyOrderSignature = abi.encodePacked(r, s, v);

signatures[0] = sellOrderSignature;
signatures[1] = buyOrderSignature;

vm.expectRevert(PredicateIsNotTrue.selector);
advancedOrderEngine.fillOrders(
orders,
sell,
buy,
signatures,
facilitatorInteraction,
borrowedTokens,
borrowedAmounts
);

vm.stopPrank();
}

function getDummyBuyOrder() private view returns(OrderEngine.Order memory) {
return OrderEngine.Order(
123, // nonce value
@@ -866,6 +1000,10 @@ contract AdvancedOrderEngineTest is Test {
return ECDSA.toTypedDataHash(advancedOrderEngine.DOMAIN_SEPARATOR(), structHash);
}

function _oraclePrice() internal view virtual returns (uint256) {
return 99999 ether;
}

}

/** Predicates selectors
7 changes: 7 additions & 0 deletions test/interfaces/pricefeed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

interface IPriceFeed {
function latestAnswer() external payable returns(uint256);
}