Puzzle #4
PairAssetManager
Author
First Blood
Solve Time
Total Solves
Time Left
Phase 0
Phase 1
Phase 2
Solutions revealed
Phase 3
Submissions closed
12345678910111213141516171819202122232425262728293031323334353637383940
1pragma solidity ^0.8.20;2
3import "../lib/curta/src/interfaces/IPuzzle.sol";4
5contract Puzzle is IPuzzle{6 mapping(uint256 => Challenge) public factories;7
8 function name() external pure returns (string memory) {9 return "PairAssetManager";10 }11
12 function generate(address solver) public pure returns (uint256) {13 return uint256(keccak256(abi.encode(solver)));14 }15
16 function verify(uint256 seed, uint256) external view returns (bool) {17 return factories[seed].isSolved();18 }19
20 function deploy() external {21 factories[generate(msg.sender)] = new Challenge();22 factories[generate(msg.sender)].init(generate(msg.sender));23 }24}25
26contract Deployer {27 function create(address owner, address factory) external returns (PairAssetManager) {28 return new PairAssetManager(owner, factory);29 }30}31
32contract Challenge {33 UniswapV2Factory public factory;34 PairAssetManager public assetManager;35 Keeper public keeper;36
37 CurtaToken public curtaUSD;38 CurtaToken public curtaStUSD;39
40 uint256 public seed;41 bool public initialized;42
43 function init(uint256 _seed) external {44 require(!initialized);45 initialized = true;46 seed = _seed;47
48 factory = new UniswapV2Factory(address(0));49 assetManager = Deployer(address(0x1D1f5f03feDD0358e7eB8A980870ef6695834bB9)).create(address(this), address(factory));50 keeper = new Keeper(address(assetManager));51 assetManager.setKeeper(address(keeper));52 curtaUSD = new CurtaToken("curtaUSD", "USD");53 curtaStUSD = new CurtaToken("curtaStUSD", "stUSD");54
55 curtaUSD.mint(address(this), 1 ether);56 curtaStUSD.mint(address(this), 1 ether);57
58 curtaUSD.approve(address(assetManager), 1 ether);59 curtaStUSD.approve(address(assetManager), 1 ether);60
61 factory.createPair(address(curtaUSD), address(curtaStUSD));62 assetManager.setStrategyPair(address(curtaUSD), address(curtaStUSD));63 assetManager.deposit(address(curtaUSD), address(curtaStUSD), 1 ether, 1 ether, 0);64
65 curtaUSD.mint(address(keeper), 10000 ether + 1);66 curtaStUSD.mint(address(keeper), 10000 ether + 1);67
68 keeper.rebalancing(address(curtaUSD), address(curtaStUSD), 1, 0, type(uint256).max, type(uint256).max);69 }70
71 function isSolved() external view returns (bool) {72 require(73 curtaUSD.balanceOf(address(uint160(seed))) == 10000 ether74 && curtaStUSD.balanceOf(address(uint160(seed))) == 10000 ether75 );76 return true;77 }78}
git clone https://github.com/waterfall-mkt/curta-puzzles.git && cd curta-puzzles && forge install
RPC_URL_MAINNET
in .env
RPC_URL_MAINNET=""
forge script <PATH_TO_PUZZLE> -f mainnet -vvv