reworked to optionally use Hardhat in mock; chain id 31337; refactored TransactionJob management; execute() mostly commented out for minimalism
This commit is contained in:
@@ -29,9 +29,13 @@ contract MockEnv {
|
||||
// the initial price is 1.000000, but since COIN has 18 decimals and USD only has 6, the raw pool price is 1e-12
|
||||
// therefore the sqrt price is 1e-6
|
||||
// 1000e12 liquidity is put into the pool at each tick spacing for 10 tick spacings to either side of $1
|
||||
function init() internal {
|
||||
function init() public {
|
||||
COIN = new MockERC20('Mock Coin', 'MOCK', 18);
|
||||
USD = new MockERC20('Universally Supported Dollars', 'USD', 6);
|
||||
console2.log('COIN');
|
||||
console2.log(address(COIN));
|
||||
USD = new MockERC20('Universally Stable Denomination', 'USD', 6);
|
||||
console2.log('USD');
|
||||
console2.log(address(USD));
|
||||
fee = 500;
|
||||
inverted = address(COIN) > address(USD);
|
||||
token0 = inverted ? address(USD) : address(COIN);
|
||||
@@ -40,7 +44,8 @@ contract MockEnv {
|
||||
console2.log('if this is the last line before a revert then make sure to run forge with --rpc-url');
|
||||
// if this reverts here make sure Anvil is started and you are running forge with --rpc-url
|
||||
pool = IUniswapV3Pool(nfpm.createAndInitializePoolIfNecessary(token0, token1, fee, initialPrice));
|
||||
console2.log('created v3 pool successfully');
|
||||
console2.log('v3 pool');
|
||||
console2.log(address(pool));
|
||||
int24 ts = pool.tickSpacing();
|
||||
(, int24 lower, , , , ,) = pool.slot0();
|
||||
int24 upper = lower;
|
||||
|
||||
@@ -9,6 +9,8 @@ import "../src/Factory.sol";
|
||||
import "../src/OrderLib.sol";
|
||||
|
||||
contract TestOrder is MockEnv, Test {
|
||||
using OrderLib for OrderLib.OrdersInfo;
|
||||
|
||||
Factory public factory;
|
||||
Vault public vault;
|
||||
|
||||
@@ -24,7 +26,7 @@ contract TestOrder is MockEnv, Test {
|
||||
}
|
||||
|
||||
|
||||
function testOrder() public {
|
||||
function testPlaceOrder() public {
|
||||
OrderLib.Tranche[] memory tranches = new OrderLib.Tranche[](3);
|
||||
OrderLib.Constraint[] memory constraints1 = new OrderLib.Constraint[](1);
|
||||
constraints1[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Time, bytes(hex"0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000046500"));
|
||||
@@ -44,4 +46,25 @@ contract TestOrder is MockEnv, Test {
|
||||
vault.placeOrder(order);
|
||||
}
|
||||
|
||||
function testExecuteOrder() public {
|
||||
OrderLib.Tranche[] memory tranches = new OrderLib.Tranche[](1);
|
||||
OrderLib.Constraint[] memory constraints1 = new OrderLib.Constraint[](1);
|
||||
constraints1[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Time, bytes(hex"0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000046500"));
|
||||
tranches[0] = OrderLib.Tranche(type(uint16).max,constraints1);
|
||||
uint256 amount = 3*10**COIN.decimals() / 10; // 0.3 COIN
|
||||
COIN.mint(address(vault), amount); // create COIN to sell
|
||||
OrderLib.SwapOrder memory order = OrderLib.SwapOrder(
|
||||
address(COIN), address(USD), // sell COIN for USD
|
||||
OrderLib.Route(OrderLib.Exchange.UniswapV3, 500), amount, true, false,
|
||||
OrderLib.NO_CHAIN, tranches
|
||||
);
|
||||
uint64 orderIndex = vault.numSwapOrders();
|
||||
vault.placeOrder(order);
|
||||
console2.log('placed order');
|
||||
console2.log(uint(orderIndex));
|
||||
string memory result;
|
||||
vault.execute(orderIndex, 0, OrderLib.PriceProof(0));
|
||||
console2.log('executed');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user