-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
809 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.14; | ||
|
||
import "../lib/forge-std/src/console.sol"; | ||
import "../lib/forge-std/src/Script.sol"; | ||
import "../src/UniswapV3Pool.sol"; | ||
import "../src/UniswapV3Manager.sol"; | ||
import "../test/ERC20Mintable.sol"; | ||
|
||
contract DeployDevelopment is Script { | ||
function run() public { | ||
uint256 wethBalance = 1 ether; | ||
uint256 usdcBalance = 5042 ether; | ||
int24 currentTick = 85176; | ||
uint160 currentSqrtP = 5602277097478614198912276234240; | ||
vm.startBroadcast(); | ||
ERC20Mintable token0 = new ERC20Mintable("Wrapped Ether", "WETH" ,18); | ||
ERC20Mintable token1 = new ERC20Mintable("USD coin", "USDC", 18); | ||
UniswapV3Pool pool = new UniswapV3Pool( | ||
address(token0), | ||
address(token1), | ||
currentSqrtP, | ||
currentTick | ||
); | ||
UniswapV3Manager manager = new UniswapV3Manager(); | ||
token0.mint(msg.sender,wethBalance); | ||
token1.mint(msg.sender,usdcBalance); | ||
vm.stopBroadcast(); | ||
console.log("WETH address", address(token0)); | ||
console.log("USDC address", address(token1)); | ||
console.log("Pool address", address(pool)); | ||
console.log("Manager address", address(manager)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.14; | ||
import "../src/UniswapV3Pool.sol"; | ||
import "../src/interfaces/IERC20.sol"; | ||
|
||
contract UniswapV3Manager{ | ||
function mint( | ||
address poolAddress_, | ||
int24 lowerTick, | ||
int24 upperTick, | ||
uint128 liquidity, | ||
bytes calldata data | ||
)public returns(uint256, uint256){ | ||
return UniswapV3Pool(poolAddress_).mint(msg.sender, lowerTick, upperTick, liquidity, data); | ||
} | ||
|
||
function swap(address poolAddress_, bytes calldata data) public returns(int256, int256){ | ||
return UniswapV3Pool(poolAddress_).swap(msg.sender, data); | ||
} | ||
function uniswapV3MintCallback( | ||
uint256 amount0, | ||
uint256 amount1, | ||
bytes calldata data | ||
) public { | ||
UniswapV3Pool.CallbackData memory extra = abi.decode( | ||
data, | ||
(UniswapV3Pool.CallbackData) | ||
); | ||
|
||
IERC20(extra.token0).transferFrom(extra.payer, msg.sender, amount0); | ||
IERC20(extra.token1).transferFrom(extra.payer, msg.sender, amount1); | ||
} | ||
|
||
function uniswapV3SwapCallback( | ||
int256 amount0, | ||
int256 amount1, | ||
bytes calldata data | ||
) public { | ||
UniswapV3Pool.CallbackData memory extra = abi.decode( | ||
data, | ||
(UniswapV3Pool.CallbackData) | ||
); | ||
|
||
if (amount0 > 0) { | ||
IERC20(extra.token0).transferFrom( | ||
extra.payer, | ||
msg.sender, | ||
uint256(amount0) | ||
); | ||
} | ||
|
||
if (amount1 > 0) { | ||
IERC20(extra.token1).transferFrom( | ||
extra.payer, | ||
msg.sender, | ||
uint256(amount1) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.14; | ||
|
||
import "../src/UniswapV3Pool.sol"; | ||
|
||
abstract contract TestUtils { | ||
function encodeError(string memory error) | ||
internal | ||
pure | ||
returns (bytes memory encoded) | ||
{ | ||
encoded = abi.encodeWithSignature(error); | ||
} | ||
|
||
function encodeExtra( | ||
address token0_, | ||
address token1_, | ||
address payer | ||
) internal pure returns (bytes memory) { | ||
return | ||
abi.encode( | ||
UniswapV3Pool.CallbackData({ | ||
token0: token0_, | ||
token1: token1_, | ||
payer: payer | ||
}) | ||
); | ||
} | ||
} |
Oops, something went wrong.