Skip to content

Commit

Permalink
partially working
Browse files Browse the repository at this point in the history
  • Loading branch information
Code0x2 committed Nov 22, 2023
1 parent b49ecd6 commit f9e9ba7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/contracts/common/ExecutionBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ contract ExecutionBase is Base {

if (source == user) {
if (shiftedPhase & SAFE_USER_TRANSFER == 0) {
address(0).staticcall("");
return false;
}
if (ERC20(token).allowance(user, atlas) < amount) {
Expand Down
52 changes: 26 additions & 26 deletions src/contracts/examples/intents-example/V4SwapIntent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ struct SwapData {
contract V4SwapIntentController is DAppControl {
using SafeTransferLib for ERC20;

address constant V4_POOL = address(0); // TODO: set for test v4 pool
address immutable V4_POOL; // TODO: set for test v4 pool

uint256 startingBalance; // Balance tracked for the v4 pool

constructor(address _escrow)
DAppControl(
_escrow,
msg.sender,
CallConfig({
sequenced: false,
requirePreOps: false,
trackPreOpsReturnData: false,
trackUserReturnData: true,
localUser: false,
delegateUser: true,
preSolver: true,
postSolver: true,
requirePostOps: false,
zeroSolvers: false,
reuseUserOp: true,
userBundler: true,
solverBundler: true,
verifySolverBundlerCallChainHash: true,
unknownBundler: true,
forwardReturnData: false
})
)
{}
constructor(address _escrow, address poolManager) DAppControl(
_escrow,
msg.sender,
CallConfig({
sequenced: false,
requirePreOps: false,
trackPreOpsReturnData: false,
trackUserReturnData: true,
localUser: false,
delegateUser: true,
preSolver: true,
postSolver: true,
requirePostOps: false,
zeroSolvers: false,
reuseUserOp: true,
userBundler: true,
solverBundler: true,
verifySolverBundlerCallChainHash: true,
unknownBundler: true,
forwardReturnData: false
})
) {
V4_POOL = poolManager;
}

//////////////////////////////////
// CONTRACT-SPECIFIC FUNCTIONS //
Expand All @@ -81,7 +81,7 @@ contract V4SwapIntentController is DAppControl {
}

require(
_availableFundsERC20(tokenIn, user, amount, ExecutionPhase.SolverOperations),
_availableFundsERC20(tokenIn, user, amount, ExecutionPhase.PreSolver),
"ERR-PI059 SellFundsUnavailable"
);
_;
Expand Down
18 changes: 9 additions & 9 deletions test/V4SwapIntent.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ contract V4SwapIntentTest is BaseTest {
function setUp() public virtual override {
BaseTest.setUp();

// deploy new pool manager
poolManager = new PoolManager(30000000);

// Creating new gov address (ERR-V49 OwnerActive if already registered with controller)
governancePK = 11112;
governanceEOA = vm.addr(governancePK);

// Deploy new SwapIntent Controller from new gov and initialize in Atlas
vm.startPrank(governanceEOA);
swapIntentController = new V4SwapIntentController(address(escrow));
swapIntentController = new V4SwapIntentController(address(escrow), address(poolManager));
atlas.initializeGovernance(address(swapIntentController));
atlas.integrateDApp(address(swapIntentController));
vm.stopPrank();
Expand All @@ -55,9 +58,7 @@ contract V4SwapIntentTest is BaseTest {
atlasAddress: address(atlas)
});

// Deploy new poolamanger and create a DAI/WETH pool with no hooks
poolManager = new PoolManager(30000000);

// Create a DAI/WETH pool with no hooks
poolKey = PoolKey({
currency0: Currency.wrap(address(DAI)),
currency1: Currency.wrap(address(WETH)),
Expand All @@ -66,10 +67,7 @@ contract V4SwapIntentTest is BaseTest {
hooks: IHooks(address(0))
});

// Original: 1823965582028705631020492031
// SQRT_RATIO_1_1: 79228162514264337593543950336

poolManager.initialize(poolKey, 79228162514264337593543950336, new bytes(0));
poolManager.initialize(poolKey, 1797734745375579914506781200, new bytes(0));

// New stuff
PoolModifyPositionTest modifyPositionRouter = new PoolModifyPositionTest(IPoolManager(address(poolManager)));
Expand All @@ -84,7 +82,7 @@ contract V4SwapIntentTest is BaseTest {
modifyPositionRouter.modifyPosition(poolKey, IPoolManager.ModifyPositionParams({
tickLower: -887220,
tickUpper: 887220,
liquidityDelta: 1000000
liquidityDelta: 100000000000000000
}), new bytes(0));

vm.stopPrank();
Expand Down Expand Up @@ -248,6 +246,7 @@ contract UniswapV4IntentSolver is SolverBase {
require(ERC20(swap.tokenIn).balanceOf(address(this)) >= (swap.requestedAmount > 0 ? uint256(swap.requestedAmount) : swap.limitAmount - bid), "Did not receive enough tokenIn");

// Make swap on the v4 pool
ERC20(swap.tokenIn).approve(address(swapHelper), swap.requestedAmount > 0 ? uint256(swap.requestedAmount) : swap.limitAmount - bid);
swapHelper.swap(poolKey, IPoolManager.SwapParams({
zeroForOne: swap.tokenIn < swap.tokenOut,
amountSpecified: swap.requestedAmount,
Expand All @@ -258,6 +257,7 @@ contract UniswapV4IntentSolver is SolverBase {
}), new bytes(0));

// Send min tokens back to user to fulfill intent, rest are profit for solver
address(0).staticcall(abi.encode(bid));
ERC20(swap.tokenOut).transfer(executionEnvironment, swap.requestedAmount > 0 ? bid : uint256(-swap.requestedAmount));
}

Expand Down

0 comments on commit f9e9ba7

Please sign in to comment.