Address Contract Verified
Address
0x680AD93DF2a2813167e628427Aa4b46E2C654a0b
Balance
0.000013555 ETH
Nonce
1
Code Size
24370 bytes
Creator
0x55340fDB...6bA4 at tx 0x7a152da7...e7c40a
Indexed Transactions
0
Contract Bytecode
24370 bytes
0x6080604052600436106102e5575f3560e01c8063677342ce11610181578063b17acdcd116100d4578063c4b19b5411610083578063f2fde38b11610060578063f2fde38b14610993578063f60b36e3146109b2578063f77c4791146109d157005b8063c4b19b5414610919578063c53b770214610938578063df2a558b1461096557005b8063bf0e622b116100b1578063bf0e622b14610889578063c31c9c07146108cb578063c45a0155146108f257005b8063b17acdcd14610832578063b3a5794314610851578063bc3291981461087057005b80638da5cb5b116101305780639a7fe3a11161010d5780639a7fe3a1146107d15780639ba69249146107f0578063a9e88b8f1461080457005b80638da5cb5b1461074157806392eefe9b1461075d57806399fbab881461077c57005b8063715018a61161015e578063715018a6146106f157806381720479146107055780638abb98451461072457005b8063677342ce1461067d578063699535011461069c5780636a0f27c2146106bb57005b8063329aa41411610239578063481c6a75116101e85780634a2539c3116101c55780634a2539c3146106135780635a29638d1461063257806363011d1a1461065157005b8063481c6a7514610583578063495915d3146105b657806349c69fd8146105d557005b806339040ed11161021657806339040ed11461052257806342d9843e1461054d578063439370b11461057b57005b8063329aa414146104c557806332c4171d146104e4578063338b5dea1461050357005b8063145a6ae0116102955780631b9a91a4116102725780631b9a91a41461046a5780631fba9eda146104895780633018205f146104a857005b8063145a6ae0146103da578063150b7a02146103f957806319cc33571461045657005b806308092e9a116102c357806308092e9a146103685780630a861f2a1461039c5780630acc8cd1146103bb57005b8062ae3bf8146102ee57806301e336671461030d578063041ae8801461032c57005b366102ec57005b005b3480156102f9575f80fd5b506102ec610308366004615455565b6109f0565b348015610318575f80fd5b506102ec610327366004615470565b610b3c565b348015610337575f80fd5b5060035461034b906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b348015610373575f80fd5b506103876103823660046154be565b610cb0565b6040805192835260208301919091520161035f565b3480156103a7575f80fd5b506102ec6103b6366004615519565b6112ef565b3480156103c6575f80fd5b506102ec6103d5366004615455565b6115d2565b3480156103e5575f80fd5b506102ec6103f4366004615519565b61163a565b348015610404575f80fd5b5061043d610413366004615530565b7f150b7a020000000000000000000000000000000000000000000000000000000095945050505050565b6040516001600160e01b0319909116815260200161035f565b348015610461575f80fd5b506102ec611add565b348015610475575f80fd5b506102ec6104843660046155c9565b611af4565b348015610494575f80fd5b5061034b6104a336600461560a565b611bb1565b3480156104b3575f80fd5b506002546001600160a01b031661034b565b3480156104d0575f80fd5b506102ec6104df366004615519565b611bf5565b3480156104ef575f80fd5b506102ec6104fe366004615645565b611e6e565b34801561050e575f80fd5b506102ec61051d3660046155c9565b61203b565b34801561052d575f80fd5b50600e5461053b9060ff1681565b60405160ff909116815260200161035f565b348015610558575f80fd5b5061053b610567366004615519565b60396020525f908152604090205460ff1681565b6102ec6121ab565b34801561058e575f80fd5b5061034b7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8881565b3480156105c1575f80fd5b506102ec6105d0366004615688565b6121e5565b3480156105e0575f80fd5b506106036105ef366004615455565b603a6020525f908152604090205460ff1681565b604051901515815260200161035f565b34801561061e575f80fd5b506102ec61062d366004615519565b6123fb565b34801561063d575f80fd5b5060045461034b906001600160a01b031681565b34801561065c575f80fd5b5061066561279c565b6040516001600160801b03909116815260200161035f565b348015610688575f80fd5b50610665610697366004615519565b612df8565b3480156106a7575f80fd5b506102ec6106b6366004615455565b612f79565b3480156106c6575f80fd5b506106da6106d53660046156f9565b612fa3565b6040805192835260ff90911660208301520161035f565b3480156106fc575f80fd5b506102ec61347a565b348015610710575f80fd5b5061038761071f366004615645565b61348d565b34801561072f575f80fd5b506003546001600160a01b031661034b565b34801561074c575f80fd5b505f546001600160a01b031661034b565b348015610768575f80fd5b506102ec610777366004615455565b6134ab565b348015610787575f80fd5b5061079b610796366004615519565b61350a565b604080516001600160a01b039687168152602081019590955284019290925283166060830152909116608082015260a00161035f565b3480156107dc575f80fd5b506106656107eb366004615455565b61354d565b3480156107fb575f80fd5b506106656135fe565b34801561080f575f80fd5b5061060361081e366004615455565b60016020525f908152604090205460ff1681565b34801561083d575f80fd5b506102ec61084c366004615519565b6136da565b34801561085c575f80fd5b5061034b61086b36600461576e565b61397c565b34801561087b575f80fd5b5060385461053b9060ff1681565b348015610894575f80fd5b506108b86108a3366004615455565b60056020525f908152604090205461ffff1681565b60405161ffff909116815260200161035f565b3480156108d6575f80fd5b5061034b73e592427a0aece92de3edee1f18e0157c0586156481565b3480156108fd575f80fd5b5061034b731f98431c8ad98523631ae4a59f267346ea31f98481565b348015610924575f80fd5b5061034b610933366004615519565b6139bd565b348015610943575f80fd5b50610957610952366004615455565b6139dc565b60405190815260200161035f565b348015610970575f80fd5b5061053b61097f366004615455565b600f6020525f908152604090205460ff1681565b34801561099e575f80fd5b506102ec6109ad366004615455565b613a77565b3480156109bd575f80fd5b506102ec6109cc366004615455565b613b07565b3480156109dc575f80fd5b5060025461034b906001600160a01b031681565b6109f8613d70565b6001600160a01b0381165f908152600f6020526040902054600e5460ff918216911681101580610a515750816001600160a01b031660068260ff1660088110610a4357610a436157b6565b01546001600160a01b031614155b610aa25760405162461bcd60e51b815260206004820152601860248201527f43616e6e6f74202772657363756527206465706f73697473000000000000000060448201526064015b60405180910390fd5b816001600160a01b031663a9059cbb610ac25f546001600160a01b031690565b610acb856139dc565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303815f875af1158015610b13573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b3791906157d9565b505050565b8015610b37576003546001600160a01b03163314610b8b5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a99565b6040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b0383811660048301526024820183905284169063a9059cbb906044016020604051808303815f875af1158015610bf0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c1491906157d9565b610c605760405162461bcd60e51b815260206004820152600f60248201527f5472616e73666572206661696c656400000000000000000000000000000000006044820152606401610a99565b610c6983613dc9565b604080516001600160a01b0385168152602081018390527f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5910160405180910390a1505050565b6002545f9081906001600160a01b0316331480610ccc57503330145b610d075760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a99565b6001600160a01b038716158015610d4f57507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316866001600160a01b0316145b15610dde57838510610d615783610d63565b845b91507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0836040518263ffffffff1660e01b81526004015f604051808303818588803b158015610dbe575f80fd5b505af1158015610dd0573d5f803e3d5ffd5b508594506112e59350505050565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316876001600160a01b0316148015610e2657506001600160a01b038616155b15610ed457838510610e385783610e3a565b845b6040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018290529092507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d906024015f604051808303815f87803b158015610eb5575f80fd5b505af1158015610ec7573d5f803e3d5ffd5b508493506112e592505050565b600480546040517f64aa79a30000000000000000000000000000000000000000000000000000000081526001600160a01b038a8116938201939093528883166024820152604481018890526064810187905262ffffff861660848201525f92839216906364aa79a39060a401606060405180830381865afa158015610f5b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f7f91906157f2565b90955090925090506001600160a01b038916611006577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0856040518263ffffffff1660e01b81526004015f604051808303818588803b158015610fee575f80fd5b505af1158015611000573d5f803e3d5ffd5b50505050505b5f6040518061010001604052805f6001600160a01b03168c6001600160a01b031614611032578b611054565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25b6001600160a01b031681526020015f6001600160a01b03168b6001600160a01b031614611081578a6110a3565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25b6001600160a01b03168152602001846001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110ed573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111119190615831565b62ffffff168152602001306001600160a01b031681526020014281526020018681526020018381526020015f6001600160a01b0316815250905073e592427a0aece92de3edee1f18e0157c058615646001600160a01b031663414bf389826040518263ffffffff1660e01b815260040161118b919061584c565b6020604051808303815f875af11580156111a7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111cb91906158dd565b93506001600160a01b038a16156111e5576111e58a613dc9565b6001600160a01b038916611286576040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018590527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d906024015f604051808303815f87803b15801561126b575f80fd5b505af115801561127d573d5f803e3d5ffd5b5050505061128f565b61128f89613f9d565b604080516001600160a01b03808d1682528b166020820152908101869052606081018590527f25f1d03755df23c30e25db2dbd3891e31ce084bdfbfc46f9fe5e446ee5f9b2d49060800160405180910390a15050505b9550959350505050565b6003546001600160a01b031633146113385760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a99565b6040517f42842e0e000000000000000000000000000000000000000000000000000000008152306004820152336024820152604481018290527f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b0316906342842e0e906064015f604051808303815f87803b1580156113bc575f80fd5b505af11580156113ce573d5f803e3d5ffd5b5050505f8281526039602052604081205460ff169150601082600881106113f7576113f76157b6565b60385460059190910291909101915060ff90811690831610801561141e5750828160020154145b15610b375760038101546001600160a01b03165f908152600560205260408120805461ffff169161144e83615908565b82546101009290920a61ffff81810219909316918316021790915560048301546001600160a01b03165f9081526005602052604081208054909216925061149483615908565b825461ffff9182166101009390930a9283029190920219909116179055506038805460ff16905f6114c483615924565b82546101009290920a60ff81810219909316918316021790915560385416159050610b375760385460109060ff1660088110611502576115026157b6565b6005020160108360ff166008811061151c5761151c6157b6565b82546005919091029190910180546001600160a01b03199081166001600160a01b03938416178255600180850154908301556002808501549083015560038085015490830180548316918516919091179055600493840154939091018054909116929091169190911790558160395f601060ff8416600881106115a1576115a16157b6565b600502016002015481526020019081526020015f205f6101000a81548160ff021916908360ff160217905550505050565b6115da613d70565b600380546001600160a01b038381166001600160a01b03198316811790935560408051938452911660208301819052917f9fb5233a5c1113ee4f5aafa72ecf995c4c5bc0c057ecbcad707ea04ebc829c6691015b60405180910390a15050565b6002546001600160a01b031633146116835760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a99565b61168c816136da565b5f8181526039602052604081205460ff1690601082600881106116b1576116b16157b6565b6005020190505f805f805f7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab88896040518263ffffffff1660e01b815260040161170a91815260200190565b61018060405180830381865afa158015611726573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061174a9190615968565b50505050975097509750509650965050505f865f015f9054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156117ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117d19190615a63565b50505050505090505f6117e3876139dc565b905061180e6117f1876139dc565b600160c01b6118096001600160a01b03861680615ae6565b6144d2565b6118189082615afd565b90505f6118366118278761457c565b6118308761457c565b846149b8565b6004549091505f9081906001600160a01b031663c72e160b866118588b61457c565b6118618b61457c565b60646118776001600160801b038a166062615ae6565b6118819190615b24565b6040516001600160e01b031960e087901b1681526001600160a01b0394851660048201529284166024840152921660448201526001600160801b0390911660648201526084016040805180830381865afa1580156118e1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119059190615b37565b915091506119158a8a8484611e6e565b5f6040518060c001604052808f81526020016119308d6139dc565b815260200161193e8c6139dc565b81525f602080830182905260408084018390524260609485015280517f219f5d170000000000000000000000000000000000000000000000000000000081528551600482015291850151602483015284015160448201529183015160648301526080830151608483015260a083015160a48301529192506001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88169063219f5d179060c4016060604051808303815f875af1158015611a05573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a299190615b59565b8095508196508293505050507f1172e6c2fa5b068f7396efd2ed20f26bf1ce7899860acd635416a62a99bb975c8f8e6003015f9054906101000a90046001600160a01b03168f6004015f9054906101000a90046001600160a01b03168b85611a919190615b74565b604051611ac494939291909384526001600160a01b03928316602085015291166040830152600f0b606082015260800190565b60405180910390a1505050505050505050505050505050565b611ae5613d70565b603b805460ff19166001179055565b8015611bad576003546001600160a01b03163314611b435760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a99565b6040516001600160a01b0383169082156108fc029083905f818181858888f19350505050158015611b76573d5f803e3d5ffd5b50604080515f8152602081018390527f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5910161162e565b5050565b5f80611bd78369ffffffffffffffffffff16600160c01b86600c0160ff16600a0a6144d2565b9050611be281612df8565b6001600160801b03169150505b92915050565b6040517f99fbab88000000000000000000000000000000000000000000000000000000008152600481018290525f907f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b0316906399fbab889060240161018060405180830381865afa158015611c74573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c989190615968565b5050505f8b815260396020526040812054929a5060ff90921698509096506010955087945050600884109250611cd391505057611cd36157b6565b6005020190506001600160801b03831615611e68576040805160a0810182528581526001600160801b03858116602083019081525f83850181815260608501918252426080860190815295517f0c49ccbe0000000000000000000000000000000000000000000000000000000081528551600482015292519093166024830152915160448201529051606482015291516084830152907f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b031690630c49ccbe9060a40160408051808303815f875af1158015611db8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ddc9190615b37565b5050600382015460048301547f1172e6c2fa5b068f7396efd2ed20f26bf1ce7899860acd635416a62a99bb975c9187916001600160a01b039182169116611e2288615b93565b604051611e5594939291909384526001600160a01b03928316602085015291166040830152600f0b606082015260800190565b60405180910390a1611e66856136da565b505b50505050565b5f611e78856139dc565b90505f611e84856139dc565b9050838210158015611e965750828110155b15611ea2575050611e68565b5f805f848710611eb457848703611eb6565b5f5b9150838610611ec757838603611ec9565b5f5b90508685108015611ed957508584115b15611f1b5785840392505f611efe898b86620f4240620f7cd888025b04613a98610cb0565b91505080831115611f1157808303611f13565b5f5b925050611f62565b8584108015611f2957508685115b15611f625786850392505f611f498a8a86620f4240620f7cd88702611ef5565b91505080821115611f5c57808203611f5e565b5f5b9150505b611f8f89897f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28585614a21565b9092509050611fa189895f8585614a21565b9092509050611fd389897f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb488585614a21565b909250905081158015611fe4575080155b6120305760405162461bcd60e51b815260206004820152600b60248201527f556e64657266756e6465640000000000000000000000000000000000000000006044820152606401610a99565b505050505050505050565b8015611bad576003546001600160a01b0316331461208a5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a99565b6040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018290526001600160a01b038316906323b872dd906064016020604051808303815f875af11580156120f3573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061211791906157d9565b6121635760405162461bcd60e51b815260206004820152600f60248201527f5472616e73666572206661696c656400000000000000000000000000000000006044820152606401610a99565b61216c82613f9d565b604080516001600160a01b0384168152602081018390527f2da466a7b24304f47e87fa2e1e5a81b9831ce54fec19055ce277ca2f39ba42c4910161162e565b604080515f81523460208201527f2da466a7b24304f47e87fa2e1e5a81b9831ce54fec19055ce277ca2f39ba42c4910160405180910390a1565b6121ed613d70565b603b5460ff16156122405760405162461bcd60e51b815260206004820152600660248201527f6c6f636b656400000000000000000000000000000000000000000000000000006044820152606401610a99565b5f6122496135fe565b600802662386f26fc100000190505f5b60ff8116831115611e68575f84848360ff1681811061227a5761227a6157b6565b905060200201602081019061228f9190615455565b6001600160a01b038181165f81815260016020819052604091829020805460ff19169091179055600480549151633d7e854360e11b8152908101929092527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2831660248301526001600160801b0387166044830152929350911690637afd0a86906064016020604051808303815f875af115801561232f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123539190615bcf565b5060048054604051633d7e854360e11b81526001600160a01b03848116938201939093527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48831660248201525f6044820152911690637afd0a86906064016020604051808303815f875af11580156123cd573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123f19190615bcf565b5050600101612259565b6002546001600160a01b031633146124445760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a99565b5f8181526039602052604081205460ff169060108260088110612469576124696157b6565b60050201600381015460048201549192506001600160a01b0390811691165f612491836139dc565b90505f61249d836139dc565b90506124a887611bf5565b6124b1876136da565b6040517f42966c68000000000000000000000000000000000000000000000000000000008152600481018890527f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b0316906342966c68906024015f604051808303815f87803b158015612529575f80fd5b505af115801561253b573d5f803e3d5ffd5b505050505f8261254a866139dc565b6125549190615bea565b90505f82612561866139dc565b61256b9190615bea565b6001600160a01b0387165f908152600560205260408120805492935061ffff909216919061259883615908565b82546101009290920a61ffff8181021990931691831602179091556001600160a01b0387165f908152600560205260408120805490921692506125da83615908565b825461ffff9182166101009390930a9283029190920219909116179055506038805460ff16905f61260a83615924565b82546101009290920a60ff818102199093169183160217909155603854161590506127145760385460109060ff1660088110612648576126486157b6565b6005020160108960ff1660088110612662576126626157b6565b82546005919091029190910180546001600160a01b03199081166001600160a01b03938416178255600180850154908301556002808501549083015560038085015490830180548316918516919091179055600493840154939091018054909116929091169190911790558760395f601060ff8416600881106126e7576126e76157b6565b600502016002015481526020019081526020015f205f6101000a81548160ff021916908360ff1602179055505b6103e88210156127275761272786613dc9565b6103e881101561273a5761273a85613dc9565b604080518a81526001600160a01b038881166020830152871681830152606081018490526080810183905290517f5501b833962ceaf131361ff8d59683c382ab00f523035d0fc4c2ffc19bef3a459181900360a00190a1505050505050505050565b5f6127aa620f424047615b24565b9050620f42406127d97f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26139dc565b6127e39190615b24565b6127ed9082615bfd565b90505f6128197f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486139dc565b905061c3508111156128ef57600480546040516332d2f46960e11b81526001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb488116938201939093527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc283166024820152604481018490529116906365a5e8d290606401602060405180830381865afa1580156128be573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128e29190615c1c565b6128ec9083615bfd565b91505b5f5b600e5460ff9081169082161015612a6d576004546001600160a01b03166365a5e8d2600660ff841660088110612929576129296157b6565b01546001600160a01b03167f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2600660ff86166008811061296b5761296b6157b6565b01546040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156129c9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129ed91906158dd565b6040516001600160e01b031960e086901b1681526001600160a01b0393841660048201529290911660248301526044820152606401602060405180830381865afa158015612a3d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a619190615c1c565b909201916001016128f1565b505f5b60385460ff9081169082161015612df3575f805f805f7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab8860108860ff1660088110612acb57612acb6157b6565b60050201600201546040518263ffffffff1660e01b8152600401612af191815260200190565b61018060405180830381865afa158015612b0d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612b319190615968565b50505050975097509750509650965050505f60108760ff1660088110612b5957612b596157b6565b6005020154604080517f3850c7bd00000000000000000000000000000000000000000000000000000000815290516001600160a01b0390921691633850c7bd9160048082019260e0929091908290030181865afa158015612bbc573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612be09190615a63565b50506004549495505f948594506001600160a01b0316925063c72e160b9150859050612c0b8961457c565b612c148961457c565b60405160e085901b6001600160e01b03191681526001600160a01b039384166004820152918316602483015290911660448201526001600160801b03871660648201526084016040805180830381865afa158015612c74573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c989190615b37565b600480546040516332d2f46960e11b81526001600160a01b038d8116938201939093527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2831660248201526044810185905293955091935016906365a5e8d290606401602060405180830381865afa158015612d16573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d3a9190615c1c565b600480546040516332d2f46960e11b81526001600160a01b038b8116938201939093527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2831660248201526044810185905292909d019c16906365a5e8d290606401602060405180830381865afa158015612db7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ddb9190615c1c565b909a0199505060019096019550612a70945050505050565b505090565b5f815f03612e0757505f919050565b8160017001000000000000000000000000000000008210612e2d5760809190911c9060401b5b680100000000000000008210612e485760409190911c9060201b5b6401000000008210612e5f5760209190911c9060101b5b620100008210612e745760109190911c9060081b5b6101008210612e885760089190911c9060041b5b60108210612e9b5760049190911c9060021b5b60088210612ea75760011b5b6001818581612eb857612eb8615b10565b048201901c90506001818581612ed057612ed0615b10565b048201901c90506001818581612ee857612ee8615b10565b048201901c90506001818581612f0057612f00615b10565b048201901c90506001818581612f1857612f18615b10565b048201901c90506001818581612f3057612f30615b10565b048201901c90506001818581612f4857612f48615b10565b0491909101901c5f612f5a8286615b24565b9050808210612f695780612f6b565b815b95945050505050565b919050565b612f81613d70565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6002545f9081906001600160a01b03163314612ff05760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610a99565b603854600860ff909116106130475760405162461bcd60e51b815260206004820152600d60248201527f4f7574206f66206d656d6f7279000000000000000000000000000000000000006044820152606401610a99565b856001600160a01b0316876001600160a01b0316036130a85760405162461bcd60e51b815260206004820152600a60248201527f53616d6520746f6b656e000000000000000000000000000000000000000000006044820152606401610a99565b5f866001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130e5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131099190615c35565b886001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613145573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131699190615c35565b6131739190615c4e565b90505f613185898961086b858b611bb1565b90505f6131978a8a61086b868b611bb1565b90505f8b6001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156131d6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131fa9190615a63565b5050505050509050816001600160a01b0316836001600160a01b03161115613220579091905b5f61322c84848a6149b8565b90505f61323e8e8e8e86898988614b20565b6001600160a01b038f165f9081526005602052604081208054939b5091935061ffff9092169161326d83615c6e565b82546101009290920a61ffff8181021990931691831602179091556001600160a01b038e165f908152600560205260408120805490921692506132af83615c6e565b91906101000a81548161ffff021916908361ffff160217905550506040518060a001604052808f6001600160a01b031681526020018281526020018981526020018e6001600160a01b031681526020018d6001600160a01b0316815250601060385f9054906101000a900460ff1660ff1660088110613330576133306157b6565b82516005919091029190910180546001600160a01b03199081166001600160a01b0393841617825560208085015160018401556040808601516002850155606086015160038501805485169187169190911790556080909501516004909301805490921692909316919091179055603880545f8c81526039909352928220805460ff94851660ff19909116179055805490921698508891906133d183615c8e565b91906101000a81548160ff021916908360ff160217905550507f29cd472535c058e9f744cc9cead6f8c38cbe5ea230674d825060f275884bdd72888e8e8e8e8e604051613461969594939291909586526001600160a01b03948516602087015292909316604085015269ffffffffffffffffffff908116606085015291909116608083015260a082015260c00190565b60405180910390a1505050505050965096945050505050565b613482613d70565b61348b5f614d56565b565b5f8061349e86868686613a98610cb0565b9150915094509492505050565b6134b3613d70565b600280546001600160a01b038381166001600160a01b03198316811790935560408051938452911660208301819052917e7582b62407f53d49cfc72e7ddab574c06ef3b8aced104b54b7bed4681ee54a910161162e565b60108160088110613519575f80fd5b6005020180546001820154600283015460038401546004909401546001600160a01b03938416955091939092908116911685565b5f80613558836139dc565b600480546040516332d2f46960e11b81526001600160a01b03878116938201939093527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48831660248201526044810184905292935016906365a5e8d290606401602060405180830381865afa1580156135d3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906135f79190615c1c565b9392505050565b600480546040517fea4bc51c0000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28116938201939093525f9264e8d4a5100092169063ea4bc51c90602401602060405180830381865afa158015613689573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906136ad9190615ca3565b69ffffffffffffffffffff166136c161279c565b6136cb9190615cbe565b6136d59190615ce0565b905090565b5f818152603960209081526040808320548151608081018352858152309381019384526001600160801b038184018181526060830182815294517ffc6f78650000000000000000000000000000000000000000000000000000000081528351600482015295516001600160a01b039081166024880152905182166044870152935116606485015260ff909116939092909182917f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe889091169063fc6f78659060840160408051808303815f875af11580156137b6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906137da9190615b37565b915091505f60108560ff16600881106137f5576137f56157b6565b600502018054600482015460038301549293506001600160a01b03918216925f9291821691161061388557816001600160a01b031663461413196040518163ffffffff1660e01b8152600401602060405180830381865afa15801561385c573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061388091906158dd565b6138e5565b816001600160a01b031663f30583996040518163ffffffff1660e01b8152600401602060405180830381865afa1580156138c1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906138e591906158dd565b60018401819055600484015460038501549192506001600160a01b0390811691161115613910579293925b60038301546004840154604080518b81526001600160a01b03938416602082015292909116828201526060820187905260808201869052517ff75febe5036272e29c10c008070a13657798560aaa45a46b302b112d865ff1f29181900360a00190a15050505050505050565b5f826001600160a01b0316846001600160a01b0316101561399e5750806135f7565b6139b56001600160a01b038316600160c01b615b24565b949350505050565b600681600881106139cc575f80fd5b01546001600160a01b0316905081565b5f6001600160a01b03821615613a70576040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015613a47573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613a6b91906158dd565b611bef565b4792915050565b613a7f613d70565b6001600160a01b038116613afb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610a99565b613b0481614d56565b50565b6002546001600160a01b0316331480613b2957505f546001600160a01b031633145b613b755760405162461bcd60e51b815260206004820152600d60248201527f4163636573732064656e696564000000000000000000000000000000000000006044820152606401610a99565b6001600160a01b0381165f9081526001602052604090205460ff16613bdc5760405162461bcd60e51b815260206004820152600d60248201527f496e76616c696420746f6b656e000000000000000000000000000000000000006044820152606401610a99565b60385460ff165b60ff811615613c5f576040517f4a2539c300000000000000000000000000000000000000000000000000000000815260ff5f199290920191821660048201523090634a2539c3906024015f604051808303815f87803b158015613c44575f80fd5b505af1158015613c56573d5f803e3d5ffd5b50505050613be3565b50600e5460ff165b60ff811615613cc2575f1901613cbd600660ff831660088110613c8c57613c8c6157b6565b01546001600160a01b03167f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2614da5565b613c67565b50613ced7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc282614da5565b613d177f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4882614da5565b613d215f82614da5565b600280546001600160a01b03191690556040516001600160a01b03821681527f2cc79b200fc7fdf7af6be005fc77813bfacedb82066816356eed5b7df46194709060200160405180910390a150565b5f546001600160a01b0316331461348b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a99565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316816001600160a01b03161480613e1057506001600160a01b038116155b15613e185750565b6001600160a01b0381165f908152600f6020526040902054600e5460ff918216911681108015613e705750816001600160a01b031660068260ff1660088110613e6357613e636157b6565b01546001600160a01b0316145b8015613e8457506064613e82836139dc565b105b8015613ea957506001600160a01b0382165f9081526005602052604090205461ffff16155b15611bad57600e805460ff16905f613ec083615924565b82546101009290920a60ff818102199093169183160217909155600e54161580159150613ef55750600e5460ff828116911614155b15611bad57600e5460069060ff1660088110613f1357613f136157b6565b01546001600160a01b0316600660ff831660088110613f3457613f346157b6565b0180546001600160a01b0319166001600160a01b039290921691909117905580600f5f600660ff841660088110613f6d57613f6d6157b6565b01546001600160a01b0316815260208101919091526040015f20805460ff191660ff929092169190911790555050565b6001600160a01b03811615801590613fcd57506001600160a01b0381165f908152603a602052604090205460ff16155b1561413b576040517f095ea7b300000000000000000000000000000000000000000000000000000000815273e592427a0aece92de3edee1f18e0157c0586156460048201525f1960248201526001600160a01b0382169063095ea7b3906044016020604051808303815f875af1158015614049573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061406d91906157d9565b506040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88811660048301525f19602483015282169063095ea7b3906044016020604051808303815f875af11580156140f3573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061411791906157d9565b506001600160a01b0381165f908152603a60205260409020805460ff191660011790555b6001600160a01b0381161580159061418557507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316816001600160a01b031614155b15613b04576001600160a01b0381165f818152600f602052604090205460069060ff16600881106141b8576141b86157b6565b01546001600160a01b03161415806141f05750600e546001600160a01b0382165f908152600f602052604090205460ff918216911610155b15613b0457600e54600860ff9091161061424c5760405162461bcd60e51b815260206004820152600d60248201527f4f7574206f66206d656d6f7279000000000000000000000000000000000000006044820152606401610a99565b5f6142556135fe565b90507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316826001600160a01b03161461436b5760048054604051633d7e854360e11b81526001600160a01b03858116938201939093527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48831660248201526001600160801b0384166044820152911690637afd0a86906064016020604051808303815f875af1925050508015614330575060408051601f3d908101601f1916820190925261432d91810190615bcf565b60015b614369573d80801561435d576040519150601f19603f3d011682016040523d82523d5f602084013e614362565b606091505b505061436b565b505b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b03161461444c5760048054604051633d7e854360e11b81526001600160a01b03858116938201939093527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2831660248201526001600160801b0384166044820152911690637afd0a86906064016020604051808303815f875af1158015614426573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061444a9190615bcf565b505b600e54829060069060ff1660088110614467576144676157b6565b0180546001600160a01b039283166001600160a01b0319909116179055600e80549184165f908152600f60205260408120805460ff191660ff9485161790558154909216916144b583615c8e565b91906101000a81548160ff021916908360ff160217905550505050565b5f80805f19858709858702925082811083820303915050805f03614506575f84116144fb575f80fd5b5082900490506135f7565b808411614511575f80fd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f805f8360020b12614591578260020b61459e565b8260020b61459e90615d0d565b90506145ad620d89e719615d27565b62ffffff168111156146015760405162461bcd60e51b815260206004820152600160248201527f54000000000000000000000000000000000000000000000000000000000000006044820152606401610a99565b5f816001165f0361462357700100000000000000000000000000000000614635565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff169050600282161561467457608061466f826ffff97272373d413259a46990580e213a615ae6565b901c90505b600482161561469e576080614699826ffff2e50f5f656932ef12357cf3c7fdcc615ae6565b901c90505b60088216156146c85760806146c3826fffe5caca7e10e4e61c3624eaa0941cd0615ae6565b901c90505b60108216156146f25760806146ed826fffcb9843d60f6159c9db58835c926644615ae6565b901c90505b602082161561471c576080614717826fff973b41fa98c081472e6896dfb254c0615ae6565b901c90505b6040821615614746576080614741826fff2ea16466c96a3843ec78b326b52861615ae6565b901c90505b608082161561477057608061476b826ffe5dee046a99a2a811c461f1969c3053615ae6565b901c90505b61010082161561479b576080614796826ffcbe86c7900a88aedcffc83b479aa3a4615ae6565b901c90505b6102008216156147c65760806147c1826ff987a7253ac413176f2b074cf7815e54615ae6565b901c90505b6104008216156147f15760806147ec826ff3392b0822b70005940c7a398e4b70f3615ae6565b901c90505b61080082161561481c576080614817826fe7159475a2c29b7443b29c7fa6e889d9615ae6565b901c90505b611000821615614847576080614842826fd097f3bdfd2022b8845ad8f792aa5825615ae6565b901c90505b61200082161561487257608061486d826fa9f746462d870fdf8a65dc1f90e061e5615ae6565b901c90505b61400082161561489d576080614898826f70d869a156d2a1b890bb3df62baf32f7615ae6565b901c90505b6180008216156148c85760806148c3826f31be135f97d08fd981231505542fcfa6615ae6565b901c90505b620100008216156148f45760806148ef826f09aa508b5b7a84e1c677de54f3e99bc9615ae6565b901c90505b6202000082161561491f57608061491a826e5d6af8dedb81196699c329225ee604615ae6565b901c90505b62040000821615614949576080614944826d2216e584f5fa1ea926041bedfe98615ae6565b901c90505b6208000082161561497157608061496c826b048a170391f7dc42444e8fa2615ae6565b901c90505b5f8460020b131561498a57614987815f19615b24565b90505b61499964010000000082615d3f565b156149a55760016149a7565b5f5b6139b59060ff16602083901c615afd565b5f826001600160a01b0316846001600160a01b031611156149d7579192915b5f614a02856001600160a01b0316856001600160a01b03166c010000000000000000000000006144d2565b9050612f6b8382614a138888615d52565b6001600160a01b03166144d2565b5f80846001600160a01b0316876001600160a01b031614158015614a575750846001600160a01b0316866001600160a01b031614155b15614b14575f614a66866139dc565b9050620f42408110158015614a7a57505f85115b15614aca575f80614aaa888b85620f4240614a988c620f7cd8615ae6565b614aa29190615b24565b613a98610cb0565b91509150818303925086811015614ac357808703614ac5565b5f5b965050505b620f42408110158015614adc57505f84115b15614b12575f614af9878984620f4240614a988a620f7cd8615ae6565b91505084811015614b0c57808503614b0e565b5f5b9450505b505b50919590945092505050565b5f805f896001600160a01b031663d0c93a7c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614b5f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614b839190615d71565b62ffffff1690506018818260020b614b9a89614e8f565b60020b81614baa57614baa615b10565b050262ffffff1668ffffffffffffffffff16901b811790506030818260020b614bd288614e8f565b60020b81614be257614be2615b10565b050262ffffff1668ffffffffffffffffff16901b81179050614c6789898987858f6001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015614c3e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614c629190615831565b6151ed565b9250876001600160a01b0316896001600160a01b031610614ce757896001600160a01b031663461413196040518163ffffffff1660e01b8152600401602060405180830381865afa158015614cbe573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614ce291906158dd565b614d47565b896001600160a01b031663f30583996040518163ffffffff1660e01b8152600401602060405180830381865afa158015614d23573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614d4791906158dd565b91505097509795505050505050565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f614daf836139dc565b9050816001600160a01b0316836001600160a01b031614610b37576040517f08092e9a0000000000000000000000000000000000000000000000000000000081526001600160a01b03808516600483015283166024820152604481018290525f196064820152620124f8608482015230906308092e9a9060a40160408051808303815f875af1925050508015614e62575060408051601f3d908101601f19168201909252614e5f91810190615b37565b60015b611e66573d808015611e66576040519150601f19603f3d011682016040523d82523d5f602084013e611e66565b5f6401000276a36001600160a01b03831610801590614eca575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038316105b614f165760405162461bcd60e51b815260206004820152600160248201527f52000000000000000000000000000000000000000000000000000000000000006044820152606401610a99565b77ffffffffffffffffffffffffffffffffffffffff00000000602083901b166001600160801b03811160071b81811c67ffffffffffffffff811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c97908811961790941790921717909117171760808110614fbe57614fb4607f82615bea565b83901c9150614fcf565b614fc981607f615bea565b83901b91505b5f6040614fdd608084615d8a565b901b9050828302607f1c92508260801c80603f1b8217915083811c935050828302607f1c92508260801c80603e1b8217915083811c935050828302607f1c92508260801c80603d1b8217915083811c935050828302607f1c92508260801c80603c1b8217915083811c935050828302607f1c92508260801c80603b1b8217915083811c935050828302607f1c92508260801c80603a1b8217915083811c935050828302607f1c92508260801c8060391b8217915083811c935050828302607f1c92508260801c8060381b8217915083811c935050828302607f1c92508260801c8060371b8217915083811c935050828302607f1c92508260801c8060361b8217915083811c935050828302607f1c92508260801c8060351b8217915083811c935050828302607f1c92508260801c8060341b8217915083811c935050828302607f1c92508260801c8060331b8217915083811c935050828302607f1c92508260801c8060321b82179150505f81693627a301d71055774c8561515f9190615da9565b90505f608061517e6f028f6481ab7f045a5af012a19d003aaa84615d8a565b901d90505f608061519f846fdb2df09e81959a81455e260799a0632f615dd8565b901d90508060020b8260020b146151de57886001600160a01b03166151c38261457c565b6001600160a01b031611156151d857816151e0565b806151e0565b815b9998505050505050505050565b5f80866001600160a01b0316886001600160a01b03161161520e5787615210565b865b90505f876001600160a01b0316896001600160a01b0316116152325787615234565b885b6004549091505f9081906001600160a01b031663c72e160b8a61526265ffffffffffff60188c901c1661457c565b61527a60308c68ffffffffffffffffff16901c61457c565b60405160e085901b6001600160e01b03191681526001600160a01b039384166004820152918316602483015290911660448201526001600160801b038b1660648201526084016040805180830381865afa1580156152da573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906152fe9190615b37565b9150915061530e84848484611e6e565b5f604051806101600160405280866001600160a01b03168152602001856001600160a01b031681526020018862ffffff16815260200160188a68ffffffffffffffffff16901c60020b815260200160308a68ffffffffffffffffff16901c60020b81526020018481526020018381526020015f81526020015f8152602001306001600160a01b031681526020014281525090507f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166388316456826040518263ffffffff1660e01b81526004016153ed9190615dff565b6080604051808303815f875af1158015615409573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061542d9190615ec3565b50919e9d5050505050505050505050505050565b6001600160a01b0381168114613b04575f80fd5b5f60208284031215615465575f80fd5b81356135f781615441565b5f805f60608486031215615482575f80fd5b833561548d81615441565b9250602084013561549d81615441565b929592945050506040919091013590565b62ffffff81168114613b04575f80fd5b5f805f805f60a086880312156154d2575f80fd5b85356154dd81615441565b945060208601356154ed81615441565b93506040860135925060608601359150608086013561550b816154ae565b809150509295509295909350565b5f60208284031215615529575f80fd5b5035919050565b5f805f805f60808688031215615544575f80fd5b853561554f81615441565b9450602086013561555f81615441565b935060408601359250606086013567ffffffffffffffff811115615581575f80fd5b8601601f81018813615591575f80fd5b803567ffffffffffffffff8111156155a7575f80fd5b8860208284010111156155b8575f80fd5b959894975092955050506020019190565b5f80604083850312156155da575f80fd5b82356155e581615441565b946020939093013593505050565b69ffffffffffffffffffff81168114613b04575f80fd5b5f806040838503121561561b575f80fd5b8235805f0b811461562a575f80fd5b9150602083013561563a816155f3565b809150509250929050565b5f805f8060808587031215615658575f80fd5b843561566381615441565b9350602085013561567381615441565b93969395505050506040820135916060013590565b5f8060208385031215615699575f80fd5b823567ffffffffffffffff8111156156af575f80fd5b8301601f810185136156bf575f80fd5b803567ffffffffffffffff8111156156d5575f80fd5b8560208260051b84010111156156e9575f80fd5b6020919091019590945092505050565b5f805f805f8060c0878903121561570e575f80fd5b863561571981615441565b9550602087013561572981615441565b9450604087013561573981615441565b93506060870135615749816155f3565b92506080870135615759816155f3565b9598949750929591949360a090920135925050565b5f805f60608486031215615780575f80fd5b833561578b81615441565b9250602084013561579b81615441565b915060408401356157ab81615441565b809150509250925092565b634e487b7160e01b5f52603260045260245ffd5b80518015158114612f74575f80fd5b5f602082840312156157e9575f80fd5b6135f7826157ca565b5f805f60608486031215615804575f80fd5b835161580f81615441565b602085015160409095015190969495509392505050565b8051612f74816154ae565b5f60208284031215615841575f80fd5b81516135f7816154ae565b5f610100820190506001600160a01b0383511682526001600160a01b03602084015116602083015262ffffff6040840151166040830152606083015161589d60608401826001600160a01b03169052565b506080830151608083015260a083015160a083015260c083015160c083015260e08301516158d660e08401826001600160a01b03169052565b5092915050565b5f602082840312156158ed575f80fd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b5f61ffff82168061591b5761591b6158f4565b5f190192915050565b5f60ff82168061591b5761591b6158f4565b8051612f7481615441565b8051600281900b8114612f74575f80fd5b80516001600160801b0381168114612f74575f80fd5b5f805f805f805f805f805f806101808d8f031215615984575f80fd5b8c516bffffffffffffffffffffffff8116811461599f575f80fd5b9b506159ad60208e01615936565b9a506159bb60408e01615936565b99506159c960608e01615936565b98506159d760808e01615826565b97506159e560a08e01615941565b96506159f360c08e01615941565b9550615a0160e08e01615952565b6101008e01516101208f015191965094509250615a216101408e01615952565b9150615a306101608e01615952565b90509295989b509295989b509295989b565b805161ffff81168114612f74575f80fd5b805160ff81168114612f74575f80fd5b5f805f805f805f60e0888a031215615a79575f80fd5b8751615a8481615441565b9650615a9260208901615941565b9550615aa060408901615a42565b9450615aae60608901615a42565b9350615abc60808901615a42565b9250615aca60a08901615a53565b9150615ad860c089016157ca565b905092959891949750929550565b8082028115828204841417611bef57611bef6158f4565b80820180821115611bef57611bef6158f4565b634e487b7160e01b5f52601260045260245ffd5b5f82615b3257615b32615b10565b500490565b5f8060408385031215615b48575f80fd5b505080516020909101519092909150565b5f805f60608486031215615b6b575f80fd5b61580f84615952565b6001600160801b038281168282160390811115611bef57611bef6158f4565b5f81600f0b7fffffffffffffffffffffffffffffffff800000000000000000000000000000008103615bc757615bc76158f4565b5f0392915050565b5f60208284031215615bdf575f80fd5b81516135f781615441565b81810381811115611bef57611bef6158f4565b6001600160801b038181168382160190811115611bef57611bef6158f4565b5f60208284031215615c2c575f80fd5b6135f782615952565b5f60208284031215615c45575f80fd5b6135f782615a53565b5f82810b9082900b03607f198112607f82131715611bef57611bef6158f4565b5f61ffff821661ffff8103615c8557615c856158f4565b60010192915050565b5f60ff821660ff8103615c8557615c856158f4565b5f60208284031215615cb3575f80fd5b81516135f7816155f3565b6001600160801b0381811683821602908116908181146158d6576158d66158f4565b5f6001600160801b03831680615cf857615cf8615b10565b806001600160801b0384160491505092915050565b5f600160ff1b8203615d2157615d216158f4565b505f0390565b5f8160020b627fffff198103615bc757615bc76158f4565b5f82615d4d57615d4d615b10565b500690565b6001600160a01b038281168282160390811115611bef57611bef6158f4565b5f60208284031215615d81575f80fd5b6135f782615941565b8181035f8312801583831316838312821617156158d6576158d66158f4565b8082025f8212600160ff1b84141615615dc457615dc46158f4565b8181058314821517611bef57611bef6158f4565b8082018281125f831280158216821582161715615df757615df76158f4565b505092915050565b81516001600160a01b0316815261016081016020830151615e2b60208401826001600160a01b03169052565b506040830151615e42604084018262ffffff169052565b506060830151615e57606084018260020b9052565b506080830151615e6c608084018260020b9052565b5060a083015160a083015260c083015160c083015260e083015160e0830152610100830151610100830152610120830151615eb36101208401826001600160a01b03169052565b5061014092830151919092015290565b5f805f8060808587031215615ed6575f80fd5b84519350615ee660208601615952565b604086015160609096015194979096509250505056fea2646970667358221220566a8d3e66d99f92e0ac1643681459456d2fee3b57fceab62fca050a93e71a0364736f6c634300081a0033
Verified Source Code Full Match
Compiler: v0.8.26+commit.8a97fa7a
EVM: cancun
Optimization: Yes (1750 runs)
IERC721.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC-721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
IERC721Enumerable.sol 29 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
IERC721Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IUniswapV3Factory.sol 78 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
/// @notice Emitted when the owner of the factory is changed
/// @param oldOwner The owner before the owner was changed
/// @param newOwner The owner after the owner was changed
event OwnerChanged(address indexed oldOwner, address indexed newOwner);
/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(
address indexed token0,
address indexed token1,
uint24 indexed fee,
int24 tickSpacing,
address pool
);
/// @notice Emitted when a new fee amount is enabled for pool creation via the factory
/// @param fee The enabled fee, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);
/// @notice Returns the current owner of the factory
/// @dev Can be changed by the current owner via setOwner
/// @return The address of the factory owner
function owner() external view returns (address);
/// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
/// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
/// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
/// @return The tick spacing
function feeAmountTickSpacing(uint24 fee) external view returns (int24);
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The pool address
function getPool(
address tokenA,
address tokenB,
uint24 fee
) external view returns (address pool);
/// @notice Creates a pool for the given two tokens and fee
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param fee The desired fee for the pool
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
/// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
/// are invalid.
/// @return pool The address of the newly created pool
function createPool(
address tokenA,
address tokenB,
uint24 fee
) external returns (address pool);
/// @notice Updates the owner of the factory
/// @dev Must be called by the current owner
/// @param _owner The new owner of the factory
function setOwner(address _owner) external;
/// @notice Enables a fee amount with the given tickSpacing
/// @dev Fee amounts may never be removed once enabled
/// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
/// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}
IUniswapV3Pool.sol 24 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import './pool/IUniswapV3PoolImmutables.sol';
import './pool/IUniswapV3PoolState.sol';
import './pool/IUniswapV3PoolDerivedState.sol';
import './pool/IUniswapV3PoolActions.sol';
import './pool/IUniswapV3PoolOwnerActions.sol';
import './pool/IUniswapV3PoolEvents.sol';
/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
IUniswapV3PoolImmutables,
IUniswapV3PoolState,
IUniswapV3PoolDerivedState,
IUniswapV3PoolActions,
IUniswapV3PoolOwnerActions,
IUniswapV3PoolEvents
{
}
IUniswapV3SwapCallback.sol 21 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}
IUniswapV3PoolActions.sol 103 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}
IUniswapV3PoolDerivedState.sol 40 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
/// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
/// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
/// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
/// you must call it with secondsAgos = [3600, 0].
/// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
/// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
/// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
/// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
/// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
/// timestamp
function observe(uint32[] calldata secondsAgos)
external
view
returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
/// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
/// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
/// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
/// snapshot is taken and the second snapshot is taken.
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @return tickCumulativeInside The snapshot of the tick accumulator for the range
/// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
/// @return secondsInside The snapshot of seconds per liquidity for the range
function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
external
view
returns (
int56 tickCumulativeInside,
uint160 secondsPerLiquidityInsideX128,
uint32 secondsInside
);
}
IUniswapV3PoolEvents.sol 121 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
/// @notice Emitted exactly once by a pool when #initialize is first called on the pool
/// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
/// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
/// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
event Initialize(uint160 sqrtPriceX96, int24 tick);
/// @notice Emitted when liquidity is minted for a given position
/// @param sender The address that minted the liquidity
/// @param owner The owner of the position and recipient of any minted liquidity
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity minted to the position range
/// @param amount0 How much token0 was required for the minted liquidity
/// @param amount1 How much token1 was required for the minted liquidity
event Mint(
address sender,
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when fees are collected by the owner of a position
/// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
/// @param owner The owner of the position for which fees are collected
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount0 The amount of token0 fees collected
/// @param amount1 The amount of token1 fees collected
event Collect(
address indexed owner,
address recipient,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount0,
uint128 amount1
);
/// @notice Emitted when a position's liquidity is removed
/// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
/// @param owner The owner of the position for which liquidity is removed
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity to remove
/// @param amount0 The amount of token0 withdrawn
/// @param amount1 The amount of token1 withdrawn
event Burn(
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted by the pool for any swaps between token0 and token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the output of the swap
/// @param amount0 The delta of the token0 balance of the pool
/// @param amount1 The delta of the token1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of price of the pool after the swap
event Swap(
address indexed sender,
address indexed recipient,
int256 amount0,
int256 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick
);
/// @notice Emitted by the pool for any flashes of token0/token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the tokens from flash
/// @param amount0 The amount of token0 that was flashed
/// @param amount1 The amount of token1 that was flashed
/// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
/// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
event Flash(
address indexed sender,
address indexed recipient,
uint256 amount0,
uint256 amount1,
uint256 paid0,
uint256 paid1
);
/// @notice Emitted by the pool for increases to the number of observations that can be stored
/// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
/// just before a mint/swap/burn.
/// @param observationCardinalityNextOld The previous value of the next observation cardinality
/// @param observationCardinalityNextNew The updated value of the next observation cardinality
event IncreaseObservationCardinalityNext(
uint16 observationCardinalityNextOld,
uint16 observationCardinalityNextNew
);
/// @notice Emitted when the protocol fee is changed by the pool
/// @param feeProtocol0Old The previous value of the token0 protocol fee
/// @param feeProtocol1Old The previous value of the token1 protocol fee
/// @param feeProtocol0New The updated value of the token0 protocol fee
/// @param feeProtocol1New The updated value of the token1 protocol fee
event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);
/// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
/// @param sender The address that collects the protocol fees
/// @param recipient The address that receives the collected protocol fees
/// @param amount0 The amount of token0 protocol fees that is withdrawn
/// @param amount0 The amount of token1 protocol fees that is withdrawn
event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}
IUniswapV3PoolImmutables.sol 35 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
/// @return The contract address
function factory() external view returns (address);
/// @notice The first of the two tokens of the pool, sorted by address
/// @return The token contract address
function token0() external view returns (address);
/// @notice The second of the two tokens of the pool, sorted by address
/// @return The token contract address
function token1() external view returns (address);
/// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
/// @return The fee
function fee() external view returns (uint24);
/// @notice The pool tick spacing
/// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
/// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
/// This value is an int24 to avoid casting even though it is always positive.
/// @return The tick spacing
function tickSpacing() external view returns (int24);
/// @notice The maximum amount of position liquidity that can use any tick in the range
/// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
/// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
/// @return The max amount of liquidity per tick
function maxLiquidityPerTick() external view returns (uint128);
}
IUniswapV3PoolOwnerActions.sol 23 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
/// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool
function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;
/// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1
function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
}
IUniswapV3PoolState.sol 116 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
/// when accessed externally.
/// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
/// tick The current tick of the pool, i.e. according to the last tick transition that was run.
/// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
/// boundary.
/// observationIndex The index of the last oracle observation that was written,
/// observationCardinality The current maximum number of observations stored in the pool,
/// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
/// feeProtocol The protocol fee for both tokens of the pool.
/// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
/// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
/// unlocked Whether the pool is currently locked to reentrancy
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint8 feeProtocol,
bool unlocked
);
/// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal0X128() external view returns (uint256);
/// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal1X128() external view returns (uint256);
/// @notice The amounts of token0 and token1 that are owed to the protocol
/// @dev Protocol fees will never exceed uint128 max in either token
function protocolFees() external view returns (uint128 token0, uint128 token1);
/// @notice The currently in range liquidity available to the pool
/// @dev This value has no relationship to the total liquidity across all ticks
function liquidity() external view returns (uint128);
/// @notice Look up information about a specific tick in the pool
/// @param tick The tick to look up
/// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
/// tick upper,
/// liquidityNet how much liquidity changes when the pool price crosses the tick,
/// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
/// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
/// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
/// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
/// secondsOutside the seconds spent on the other side of the tick from the current tick,
/// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
/// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
/// In addition, these values are only relative and must be used only in comparison to previous snapshots for
/// a specific position.
function ticks(int24 tick)
external
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
int56 tickCumulativeOutside,
uint160 secondsPerLiquidityOutsideX128,
uint32 secondsOutside,
bool initialized
);
/// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
function tickBitmap(int16 wordPosition) external view returns (uint256);
/// @notice Returns the information about a position by the position's key
/// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
/// @return _liquidity The amount of liquidity in the position,
/// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
/// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
/// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
/// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
function positions(bytes32 key)
external
view
returns (
uint128 _liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Returns data about a specific observation index
/// @param index The element of the observations array to fetch
/// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
/// ago, rather than at a specific index in the array.
/// @return blockTimestamp The timestamp of the observation,
/// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
/// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
/// Returns initialized whether the observation has been initialized and the values are safe to use
function observations(uint256 index)
external
view
returns (
uint32 blockTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
bool initialized
);
}
TickMath.sol 205 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0 <0.9.0;
/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
/// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
int24 internal constant MIN_TICK = -887272;
/// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
int24 internal constant MAX_TICK = -MIN_TICK;
/// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
uint160 internal constant MIN_SQRT_RATIO = 4295128739;
/// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;
/// @notice Calculates sqrt(1.0001^tick) * 2^96
/// @dev Throws if |tick| > max tick
/// @param tick The input tick for the above formula
/// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
/// at the given tick
function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
require(absTick <= uint24(MAX_TICK), 'T');
uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;
if (tick > 0) ratio = type(uint256).max / ratio;
// this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
// we then downcast because we know the result always fits within 160 bits due to our tick input constraint
// we round up in the division so getTickAtSqrtRatio of the output price is always consistent
sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
}
/// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
/// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
/// ever return.
/// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
/// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
// second inequality must be < because the price can never reach the price at the max tick
require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R');
uint256 ratio = uint256(sqrtPriceX96) << 32;
uint256 r = ratio;
uint256 msb = 0;
assembly {
let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(5, gt(r, 0xFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(4, gt(r, 0xFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(3, gt(r, 0xFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(2, gt(r, 0xF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(1, gt(r, 0x3))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := gt(r, 0x1)
msb := or(msb, f)
}
if (msb >= 128) r = ratio >> (msb - 127);
else r = ratio << (127 - msb);
int256 log_2 = (int256(msb) - 128) << 64;
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(63, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(62, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(61, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(60, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(59, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(58, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(57, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(56, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(55, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(54, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(53, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(52, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(51, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(50, f))
}
int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number
int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);
tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
}
}
IERC721Permit.sol 32 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
/// @title ERC721 with permit
/// @notice Extension to ERC721 that includes a permit function for signature based approvals
interface IERC721Permit is IERC721 {
/// @notice The permit typehash used in the permit signature
/// @return The typehash for the permit
function PERMIT_TYPEHASH() external pure returns (bytes32);
/// @notice The domain separator used in the permit signature
/// @return The domain seperator used in encoding of permit signature
function DOMAIN_SEPARATOR() external view returns (bytes32);
/// @notice Approve of a specific token ID for spending by spender via signature
/// @param spender The account that is being approved
/// @param tokenId The ID of the token that is being approved for spending
/// @param deadline The deadline timestamp by which the call must be mined for the approve to work
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
function permit(
address spender,
uint256 tokenId,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external payable;
}
INonfungiblePositionManager.sol 180 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import '@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol';
import './IPoolInitializer.sol';
import './IERC721Permit.sol';
import './IPeripheryPayments.sol';
import './IPeripheryImmutableState.sol';
import '../libraries/PoolAddress.sol';
/// @title Non-fungible token for positions
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager is
IPoolInitializer,
IPeripheryPayments,
IPeripheryImmutableState,
IERC721Metadata,
IERC721Enumerable,
IERC721Permit
{
/// @notice Emitted when liquidity is increased for a position NFT
/// @dev Also emitted when a token is minted
/// @param tokenId The ID of the token for which liquidity was increased
/// @param liquidity The amount by which liquidity for the NFT position was increased
/// @param amount0 The amount of token0 that was paid for the increase in liquidity
/// @param amount1 The amount of token1 that was paid for the increase in liquidity
event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Emitted when liquidity is decreased for a position NFT
/// @param tokenId The ID of the token for which liquidity was decreased
/// @param liquidity The amount by which liquidity for the NFT position was decreased
/// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
/// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Emitted when tokens are collected for a position NFT
/// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
/// @param tokenId The ID of the token for which underlying tokens were collected
/// @param recipient The address of the account that received the collected tokens
/// @param amount0 The amount of token0 owed to the position that was collected
/// @param amount1 The amount of token1 owed to the position that was collected
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);
/// @notice Returns the position information associated with a given token ID.
/// @dev Throws if the token ID is not valid.
/// @param tokenId The ID of the token that represents the position
/// @return nonce The nonce for permits
/// @return operator The address that is approved for spending
/// @return token0 The address of the token0 for a specific pool
/// @return token1 The address of the token1 for a specific pool
/// @return fee The fee associated with the pool
/// @return tickLower The lower end of the tick range for the position
/// @return tickUpper The higher end of the tick range for the position
/// @return liquidity The liquidity of the position
/// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
function positions(uint256 tokenId)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
/// @notice Creates a new position wrapped in a NFT
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
/// a method does not exist, i.e. the pool is assumed to be initialized.
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
/// @return tokenId The ID of the token that represents the minted position
/// @return liquidity The amount of liquidity for this position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mint(MintParams calldata params)
external
payable
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
/// @param params tokenId The ID of the token for which liquidity is being increased,
/// amount0Desired The desired amount of token0 to be spent,
/// amount1Desired The desired amount of token1 to be spent,
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
/// deadline The time by which the transaction must be included to effect the change
/// @return liquidity The new liquidity amount as a result of the increase
/// @return amount0 The amount of token0 to acheive resulting liquidity
/// @return amount1 The amount of token1 to acheive resulting liquidity
function increaseLiquidity(IncreaseLiquidityParams calldata params)
external
payable
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
/// @param params tokenId The ID of the token for which liquidity is being decreased,
/// amount The amount by which liquidity will be decreased,
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
external
payable
returns (uint256 amount0, uint256 amount1);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
/// @param params tokenId The ID of the NFT for which tokens are being collected,
/// recipient The account that should receive the tokens,
/// amount0Max The maximum amount of token0 to collect,
/// amount1Max The maximum amount of token1 to collect
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
/// must be collected first.
/// @param tokenId The ID of the token that is being burned
function burn(uint256 tokenId) external payable;
}
IPeripheryImmutableState.sol 12 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IPeripheryImmutableState {
/// @return Returns the address of the Uniswap V3 factory
function factory() external view returns (address);
/// @return Returns the address of WETH9
function WETH9() external view returns (address);
}
IPeripheryPayments.sol 28 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPayments {
/// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
/// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
/// @param amountMinimum The minimum amount of WETH9 to unwrap
/// @param recipient The address receiving ETH
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;
/// @notice Refunds any ETH balance held by this contract to the `msg.sender`
/// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
/// that use ether for the input amount
function refundETH() external payable;
/// @notice Transfers the full amount of a token held by this contract to recipient
/// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
/// @param token The contract address of the token which will be transferred to `recipient`
/// @param amountMinimum The minimum amount of token required for a transfer
/// @param recipient The destination address of the token
function sweepToken(
address token,
uint256 amountMinimum,
address recipient
) external payable;
}
IPoolInitializer.sol 22 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
/// @title Creates and initializes V3 Pools
/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that
/// require the pool to exist.
interface IPoolInitializer {
/// @notice Creates a new pool if it does not exist, then initializes if not initialized
/// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool
/// @param token0 The contract address of token0 of the pool
/// @param token1 The contract address of token1 of the pool
/// @param fee The fee amount of the v3 pool for the specified token pair
/// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value
/// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary
function createAndInitializePoolIfNecessary(
address token0,
address token1,
uint24 fee,
uint160 sqrtPriceX96
) external payable returns (address pool);
}
ISwapRouter.sol 67 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';
/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another token
/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
/// @return amountOut The amount of the received token
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
/// @return amountOut The amount of the received token
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another token
/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
/// @return amountIn The amount of the input token
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
/// @return amountIn The amount of the input token
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}
PoolAddress.sol 48 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddress {
bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
/// @notice The identifying key of the pool
struct PoolKey {
address token0;
address token1;
uint24 fee;
}
/// @notice Returns PoolKey: the ordered tokens with the matched fee levels
/// @param tokenA The first token of a pool, unsorted
/// @param tokenB The second token of a pool, unsorted
/// @param fee The fee level of the pool
/// @return Poolkey The pool details with ordered token0 and token1 assignments
function getPoolKey(
address tokenA,
address tokenB,
uint24 fee
) internal pure returns (PoolKey memory) {
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
}
/// @notice Deterministically computes the pool address given the factory and PoolKey
/// @param factory The Uniswap V3 factory contract address
/// @param key The PoolKey
/// @return pool The contract address of the V3 pool
function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {
require(key.token0 < key.token1);
pool = address(uint160(
uint256(
keccak256(
abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encode(key.token0, key.token1, key.fee)),
POOL_INIT_CODE_HASH
)
)
)
));
}
}
HoldingContract.sol 1094 lines
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.24;
/*
* TOKEN AND LIQUIDITY HOLDER CONTRACT
*
* Provides an interface for managing the contents of the contract
*
* One account owns the contract for administrative purposes, one account
* is able to deposit and withdraw funds, and another contract is able to
* manage the held assets and liquidity positions.
*
* This contract has three main purposes:
* - Hold and protect funds
* - Abstract complex behavior
* - Provide an API useful to other contracts
*
*/
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function decimals() external view returns (uint8);
function allowance(
address owner,
address spender
) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
abstract contract WETH9 {
function deposit() public virtual payable;
function withdraw(uint wad) public virtual;
}
interface IPermit2 {
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
}
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
abstract contract IHoldingContractUtils {
mapping(address => address) public uniswapV3USDCPoolByToken;
mapping(address => address) public uniswapV3ETHPoolByToken;
// RANDOM LARGE/EXPENSIVE FUNCTIONS
// Computes how much liquidity to add or remove, given a number of wanted tokens. Note that it simply aims to get the total token value
// in this contract to match the total value of newBaseBal and newQuoteBal, but does not attempt to swap to make the balances match the ratio.
function liquidityDiffHelper(uint256 positionId, address base, address quote, uint256 baseBal, uint256 quoteBal, uint256 newBaseBal, uint256 newQuoteBal) external virtual view returns (int128 liquidityDiff, uint256 baseTmp, uint256 quoteTmp);
function v4PositionInfoHelper(uint256 positionId, address base, address quote) public virtual view returns (uint128 liquidity, uint256 quotePos, uint256 basePos);
/// @notice Estimates the amount of input tokens needed and the minimum expected output for a swap.
/// @dev Supports ETH via address(0) aliasing. Accounts for Uniswap V3 pool fees and slippage tolerance.
/// Reverts if no valid pool is found for the given token pair.
/// @param from The address of the input token (use address(0) for ETH).
/// @param to The address of the output token (use address(0) for ETH).
/// @param maxIn The maximum amount of input tokens the caller is willing to provide.
/// @param maxOut The desired amount of output tokens (can be set to max(uint160) to indicate no specific target).
/// @param slippageE6 The slippage tolerance in parts per million (1e6 = 100%, 1e4 = 1%).
/// @return pool The selected Uniswap V3 pool used for the swap.
/// @return amountIn The estimated amount of input tokens required for the desired output, adjusted for fees.
/// @return outMinimum The minimum acceptable output after applying slippage tolerance.
function preSwapHelper(address from, address to, uint256 maxIn, uint256 maxOut, uint24 slippageE6) external virtual view returns (IUniswapV3Pool pool, uint256 amountIn, uint256 outMinimum);
// PRICE DATA
function getTwapPriceP12(int8 decimalDiff, address base, address quote, uint32 duration) public virtual view returns (uint80 price12);
function getTwapPricePX96(address poolAddress, address base, address quote, uint32 duration) public virtual view returns (uint256 priceX96);
function safeGetPriceUSDC12Of(address token) public virtual view returns (uint80 price12);
function safeGetPrice12Of(address base, address quote) public virtual view returns (uint80 price12);
function value12OfTokensAgainst(address token, address quote, uint256 quantity) external virtual view returns (uint128 value12);
// POOLS
function getPreferredPoolFor(address a, address b) public virtual view returns (address pool);
// Primary should either be USDC or address(0), indicating Eth. This will save the contract address
// for the pool this contract can use later.
function findV3PoolFor(address base, address quote, uint128 minValueUSDC12) public virtual returns (address bestPool);
// MATH FUNCTIONS
function getAmountsForLiquidity(uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity) public virtual pure returns (uint256 amount0, uint256 amount1);
}
abstract contract IAssetHolder {
function getTotalValueUsd12() public virtual view returns (uint128 valueUsd12);
function getTotalValueEth12() public virtual view returns (uint128 valueEth12);
function getUsd12ValueIn(address token) public virtual view returns (uint128 valueUsd12);
}
abstract contract IManagedV3AssetHolder is IAssetHolder {
// ADMINISTRATION
function getController() external virtual view returns (address _controller);
function setController(address newController) external virtual;
// Destroys and liquidates the current liquidity position, if it exists. Does not convert tokens.
function destroyPosition(uint256 positionId) external virtual;
// Takes all tokens out of the position without destroying it
function closeLiquidity(uint256 positionId) public virtual;
// Creates a new liquidity position with the given parameters.
function createV3Position(IUniswapV3Pool pool, address base, address quote, uint80 lowPrice12, uint80 highPrice12, uint256 toAdd) external virtual returns (uint256 tokenId, uint8 idx);
// Puts all available base and quote into the given position
function fillLiquidity(uint256 positionId) external virtual;
function collectFees(uint256 tokenId) public virtual;
// Swaps tokens
function swapTokensInto(address tokenFrom, address tokenTo, uint256 maxIn, uint256 maxOut) external virtual returns (uint256 tokensIn, uint256 tokensOut);
// Expected gas usage: 160000 - 550000
function obtainTokens(address token0, address token1, uint256 amount0, uint256 amount1) public virtual;
// Other functions
// Swaps everything into the given token immediately, sets this token as the system token (unless it is USDC or ETH).
// This function also sets the system controller to address 0 to prevent automation from restarting without human input.
// storeOfValueToken must be a reputable token like USDC, USDT, ETH (represented with address 0), WBTC, DAI, LINK, or UNI.
// This function will try to use updated price data to prevent front running if possible, but if the updated data is not
// available, it will complete anyway at whatever price it can get. This function should only be used in emergencies for
// this very reason (emergencies like USDC depegging, a criticl contract vulterability being discovered, etc).
// If possible, updatePriceData() should be called first.
// This function can be executed by the owner or the controller.
// Suggested emergency tokens:
// 0xdAC17F958D2ee523a2206206994597C13D831ec7 -> USDT (WARNING: For some reason this doesn't play nice with our contract, not sure why)
// 0x514910771AF9Ca656af840dff83E8264EcF986CA -> LINK
// 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 -> WBTC
// 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 -> UNI
// 0x6B175474E89094C44Da98b954EedeAC495271d0F -> DAI
function emergencyCircuitBreaker(address storeOfValueToken) external virtual;
// EVENTS
event ControllerSet(address newController, address oldController);
event EmergencyCircuitBreakerFlipped(address storeOfValueToken);
event TokensSwapped(address from, address to, uint256 fromAmt, uint256 toAmt);
event PositionMinted(uint256 poolPosition, address base, address quote, uint80 minPrice, uint80 maxPrice, uint256 toAdd);
event PositionBurned(uint256 poolPosition, address base, address quote, uint256 baseTaken, uint256 quoteTaken);
event LiquidityFeesCollected(uint256 poolPosition, address base, address quote, uint256 baseTaken, uint256 quoteTaken);
event LiquidityModified(uint256 poolPosition, address base, address quote, int128 liquidityChange);
}
abstract contract IDepositable is IAssetHolder {
// ADMINISTRATION
function getFunder() external virtual view returns (address _funder);
function setFunder(address newFunder) external virtual;
// DEPOSITS
function depositToken(address token, uint256 amount) external virtual;
function depositEth() external virtual payable;
// WITHDRAWS
function withdrawEth(address destination, uint256 amount) external virtual;
function withdrawToken(address token, address destination, uint256 amount) external virtual;
// EVENTS
event FunderSet(address newController, address oldController);
event Deposited(address token, uint256 amount);
event Withdrawn(address token, uint256 amount);
}
contract UniswapV3HoldingContract is IDepositable, IManagedV3AssetHolder, Ownable {
address internal immutable USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address internal immutable WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal immutable WETH_USDC_POOL = 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640;
// These are the tokens we can swap to in an emergency
// This prevents a bad actor or some contract error from swapping
// into a honeypot, should they ever gain unauthorized access
mapping(address => bool) public validEmergencyTokens;
// The controller is a changeable smart contract address which
// handles the automation. This allows us to change the logic
// of this system without creating a new WolfAMM contract.
// The owner is an account which can update and manage the system
// to keep things running smoothly, intervene in emergencies, or
// upgrade the system to improve performance.
// The funder is the account (usually a contract) which is allowed
// to add or remove funds.
// The controller or funder may be set to an actual account for
// diagnostic or debugging purposes.
// This separation of permissions should help prevent attacks and
// reduce attack surface somewhat for this rather large web of
// contracts.
address public controller;
address public funder;
// NOTE: This only works for Ethereum Mainnet!!
INonfungiblePositionManager public immutable manager = INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88);
ISwapRouter public constant swapRouter = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
IUniswapV3Factory public constant factory = IUniswapV3Factory(0x1F98431c8aD98523631AE4a59f267346ea31F984);
IHoldingContractUtils public utils;
struct Position {
IUniswapV3Pool pool;
uint256 lastFeeX128;
uint256 tokenId;
address base;
address quote;
}
mapping(address => uint16) public numLiquidityPositionsByToken;
address[8] public tokensHeld;
uint8 public nTokensHeld = 0;
mapping(address => uint8) public indexFromTokenAddress;
Position[8] public positions;
uint8 public nLiquidityPositions = 0;
mapping(uint256 => uint8) public indexFromPositionId;
mapping(address => bool) public isTokenApprovedForSwap;
constructor(address utilsAdr) {
// These are always good options
// Null address represents raw eth
validEmergencyTokens[USDC] = true;
validEmergencyTokens[WETH] = true;
validEmergencyTokens[0x0000000000000000000000000000000000000000] = true;
IERC20(WETH).approve(address(swapRouter), type(uint256).max);
IERC20(WETH).approve(address(manager), type(uint256).max);
IERC20(USDC).approve(address(swapRouter), type(uint256).max);
IERC20(USDC).approve(address(manager), type(uint256).max);
setController(msg.sender);
setFunder(msg.sender);
setUtils(utilsAdr);
}
function getTotalValueEth12() public override view returns (uint128 valueEth12) {
valueEth12 = uint128(address(this).balance / 1e6);
valueEth12 += uint128(contractBalance(WETH) / 1e6);
uint256 usdcBalance = contractBalance(USDC);
if (usdcBalance > 50000)
valueEth12 += utils.value12OfTokensAgainst(USDC, WETH, usdcBalance);
unchecked {
for (uint8 i = 0; i < nTokensHeld; i++)
valueEth12 += utils.value12OfTokensAgainst(tokensHeld[i], WETH, IERC20(tokensHeld[i]).balanceOf(address(this)));
for (uint8 i = 0; i < nLiquidityPositions; i++) {
(,, address token0, address token1,, int24 tickLower, int24 tickUpper, uint128 liquidity,,,,) = manager.positions(positions[i].tokenId);
(uint160 sqrtPriceX96,,,,,,) = positions[i].pool.slot0();
(uint256 amount0, uint256 amount1) = utils.getAmountsForLiquidity(
sqrtPriceX96,
TickMath.getSqrtRatioAtTick(tickLower),
TickMath.getSqrtRatioAtTick(tickUpper),
liquidity
);
valueEth12 += utils.value12OfTokensAgainst(token0, WETH, amount0);
valueEth12 += utils.value12OfTokensAgainst(token1, WETH, amount1);
}
}
}
function getTotalValueUsd12() public override view returns (uint128 valueUsd12) {
return uint128((getTotalValueEth12() * utils.safeGetPriceUSDC12Of(WETH)) / 1e12);
}
function contractBalance(address token) public view returns (uint256 balance) {
return token == address(0) ? address(this).balance : IERC20(token).balanceOf(address(this));
}
function getUsd12ValueIn(address token) public override view returns (uint128 valueUsd12) {
uint256 totalBalance = contractBalance(token);
return utils.value12OfTokensAgainst(token, USDC, totalBalance);
}
// DEPOSITS
function depositToken(address token, uint256 amount) external override {
if (amount > 0) {
require(msg.sender == funder, "Unauthorized");
require(IERC20(token).transferFrom(msg.sender, address(this), amount), "Transfer failed");
// Track what tokens we own
onReceiveToken(token);
emit Deposited(token, amount);
}
}
function depositEth() external override payable {
// Sure we'll take free ethereum, lol
//require(msg.sender == funder, "Unauthorized");
emit Deposited(address(0), msg.value);
}
fallback() external payable {
// This simply allows WETH to send raw ETH to this contract
// Back in my day, there was no receive, and fallback functions were different I think.
// Weird seeing the new syntax, but I think this is an improvement.
}
receive () external payable {
// This simply allows WETH to send raw ETH to this contract
}
// WITHDRAWS
function withdrawEth(address destination, uint256 amount) external override {
if (amount > 0) {
require(msg.sender == funder, "Unauthorized");
payable(destination).transfer(amount);
emit Withdrawn(address(0), amount);
}
}
function withdrawToken(address token, address destination, uint256 amount) external override {
if (amount > 0) {
require(msg.sender == funder, "Unauthorized");
require(IERC20(token).transfer(destination, amount), "Transfer failed");
// Track what tokens we own
onSendToken(token);
emit Withdrawn(token, amount);
}
}
function withdrawLiquidity(uint256 tokenId) external {
require(msg.sender == funder, "Unauthorized");
manager.safeTransferFrom(address(this), msg.sender, tokenId);
uint8 index = indexFromPositionId[tokenId];
Position storage position = positions[index];
if (index < nLiquidityPositions && position.tokenId == tokenId) {
numLiquidityPositionsByToken[position.base]--;
numLiquidityPositionsByToken[position.quote]--;
nLiquidityPositions--;
if (nLiquidityPositions > 0) {
positions[index] = positions[nLiquidityPositions];
indexFromPositionId[positions[index].tokenId] = index;
}
}
}
// For getting out tokens which were sent on accident (ie, not through depositToken)
function rescueTokens(address token) external onlyOwner {
// First make sure the owner isn't stealing something that was deposited
uint8 index = indexFromTokenAddress[token];
require(index >= nTokensHeld || tokensHeld[index] != token, "Cannot 'rescue' deposits");
IERC20(token).transfer(owner(), contractBalance(token));
}
function onReceiveToken(address token) internal {
if (token != address(0) && !isTokenApprovedForSwap[token]) {
IERC20(token).approve(address(swapRouter), type(uint256).max);
IERC20(token).approve(address(manager), type(uint256).max);
isTokenApprovedForSwap[token] = true;
}
if (token != address(0) && token != USDC) {
if (tokensHeld[indexFromTokenAddress[token]] != token || indexFromTokenAddress[token] >= nTokensHeld) {
require(nTokensHeld < tokensHeld.length, "Out of memory");
// Refresh pool data if the token is being received again after not being held
uint128 minValueUSDC12 = getTotalValueUsd12();
if (token != USDC) {
try utils.findV3PoolFor(token, USDC, minValueUSDC12) {}
catch (bytes memory) {}
}
if (token != WETH) utils.findV3PoolFor(token, WETH, minValueUSDC12);
tokensHeld[nTokensHeld] = token;
indexFromTokenAddress[token] = nTokensHeld;
nTokensHeld++;
}
}
}
function onSendToken(address token) internal {
if (token == USDC || token == address(0))
return;
uint8 index = indexFromTokenAddress[token];
if (index < nTokensHeld && tokensHeld[index] == token && contractBalance(token) < 100 && numLiquidityPositionsByToken[token] == 0) {
nTokensHeld--;
if (nTokensHeld > 0 && index != nTokensHeld) {
tokensHeld[index] = tokensHeld[nTokensHeld];
indexFromTokenAddress[tokensHeld[index]] = index;
}
}
}
// Other functions
// Swaps everything into the given token immediately
// This function also sets the system controller to address 0 to prevent automation from restarting without human input.
// storeOfValueToken must be a reputable token like USDC, USDT, ETH (represented with address 0), WBTC, DAI, LINK, or UNI.
// Emergency tokens can be added until the emergency token list is locked.
function emergencyCircuitBreaker(address storeOfValueToken) external override {
require(msg.sender == controller || msg.sender == owner(), "Access denied");
require(validEmergencyTokens[storeOfValueToken], "Invalid token");
unchecked {
for (uint8 i = nLiquidityPositions; i > 0;)
this.destroyPosition(--i);
for (uint8 i = nTokensHeld; i > 0;) {
_circuitBreakerHelper(tokensHeld[--i], WETH);
}
}
_circuitBreakerHelper(WETH, storeOfValueToken);
_circuitBreakerHelper(USDC, storeOfValueToken);
_circuitBreakerHelper(address(0), storeOfValueToken);
controller = address(0);
emit EmergencyCircuitBreakerFlipped(storeOfValueToken);
}
function _circuitBreakerHelper(address from, address to) internal {
uint256 bal = contractBalance(from);
if (from != to) {
// Check what it's worth in dollars; if it's $5 or more then convert it, otherwise ignore
// I do this because sometimes our position in a token will be very small, and the token
// may have few decimal places, causing mathematical errors that result in a revert.
// $5 isn't enough for us to care about really, a revert could cost us thousands in this
// scenario.
// This is also why we have a try block - should anything go wrong, we don't want to have a revert.
//try {
// if (getUsd12ValueIn(from) < 5e12)
// return;
// Here we allow a much higher slippage of 7.5% because this is an emergency case.
// We really, really want this transaction to go through.
// ;
//}
try this.swapTokens(from, to, bal, type(uint256).max, 75_000) {}
catch (bytes memory) {}
}
}
bool emergencyTokensLocked = false;
function addEmergencyTokens(address[] calldata tokens) external onlyOwner {
require(!emergencyTokensLocked, "locked");
uint128 minValueUSDC12;
unchecked {
// Make sure we can safely sell 10k or more of tokens to the given pool
// It is likely that when this function is called, the contract balance
// will be zero, so this corrects for that.
// Is 30k realistic? No idea, but in practice I highly doubt this will
// become a problem.
minValueUSDC12 = getTotalValueUsd12() * 8 + 10000e12;
}
for (uint8 i = 0; i < tokens.length;) {
address token = tokens[i];
validEmergencyTokens[token] = true;
utils.findV3PoolFor(token, WETH, minValueUSDC12);
utils.findV3PoolFor(token, USDC, 0);
unchecked { i++; }
}
}
function lockEmergencyTokens() external onlyOwner {
emergencyTokensLocked = true;
}
function collectFees(uint256 tokenId) public override {
// We don't check because the operation is harmless, save the gas
//require(msg.sender == controller, "You do not have permission");
uint8 index = indexFromPositionId[tokenId];
INonfungiblePositionManager.CollectParams memory params =
INonfungiblePositionManager.CollectParams({
tokenId: tokenId,
recipient: address(this),
amount0Max: type(uint128).max,
amount1Max: type(uint128).max
});
(uint256 baseTaken, uint256 quoteTaken) = manager.collect(params);
Position storage position = positions[index];
IUniswapV3Pool pool = position.pool;
uint256 feeGrowth = position.base < position.quote ? pool.feeGrowthGlobal0X128() : pool.feeGrowthGlobal1X128();
position.lastFeeX128 = feeGrowth;
if (position.base > position.quote)
(baseTaken, quoteTaken) = (quoteTaken, baseTaken);
emit LiquidityFeesCollected(tokenId, position.base, position.quote, baseTaken, quoteTaken);
}
// Takes basically all available tokens of base and quote and puts them into the liquidity position
function fillLiquidity(uint256 positionId) external override {
require(msg.sender == controller, "Unauthorized");
collectFees(positionId);
// Get details about the tokens
uint8 index = indexFromPositionId[positionId];
Position storage position = positions[index];
(,, address token0, address token1,, int24 tickLower, int24 tickUpper, uint128 liquidityPrev,,,,) = manager.positions(positionId);
(uint160 sqrtRatioX96,,,,,,) = position.pool.slot0();
uint256 toAdd = contractBalance(token0);
toAdd += mulDiv(contractBalance(token1), 1 << 192, uint256(sqrtRatioX96) * uint256(sqrtRatioX96));
uint128 liquidity = getLiquidityForAmount0(TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), toAdd);
// Calculate amounts of each token
(uint256 amount0, uint256 amount1) = utils.getAmountsForLiquidity(
sqrtRatioX96,
TickMath.getSqrtRatioAtTick(tickLower),
TickMath.getSqrtRatioAtTick(tickUpper),
uint128((uint256(liquidity) * 98) / 100)
);
obtainTokens(token0, token1, amount0, amount1);
INonfungiblePositionManager.IncreaseLiquidityParams memory params =
INonfungiblePositionManager.IncreaseLiquidityParams({
tokenId: positionId,
amount0Desired: contractBalance(token0),
amount1Desired: contractBalance(token1),
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
});
uint128 liquidityNew;
(liquidityNew, amount0, amount1) = manager.increaseLiquidity(params);
emit LiquidityModified(positionId, position.base, position.quote, int128(liquidityNew - liquidityPrev));
}
function closeLiquidity(uint256 tokenId) public override {
(,,,,,,, uint128 liquidity,,,,) = manager.positions(tokenId);
uint8 index = indexFromPositionId[tokenId];
Position storage position = positions[index];
if (liquidity > 0) {
// amount0Min and amount1Min are price slippage checks
// if the amount received after burning is not greater than these minimums, transaction will fail
INonfungiblePositionManager.DecreaseLiquidityParams memory params =
INonfungiblePositionManager.DecreaseLiquidityParams({
tokenId: tokenId,
liquidity: liquidity,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
});
manager.decreaseLiquidity(params);
emit LiquidityModified(tokenId, position.base, position.quote, -int128(liquidity));
// This is required for us to actually get the tokens out of the position
collectFees(tokenId);
}
}
// Destroys and liquidates the current liquidity position, if it exists. Does not convert tokens.
function destroyPosition(uint256 tokenId) external override {
require(msg.sender == controller, "Unauthorized");
uint8 index = indexFromPositionId[tokenId];
Position storage position = positions[index];
address base = position.base;
address quote = position.quote;
uint256 baseBal = contractBalance(base);
uint256 quoteBal = contractBalance(quote);
closeLiquidity(tokenId);
collectFees(tokenId);
manager.burn(tokenId);
uint256 baseTaken = (contractBalance(base)) - baseBal;
uint256 quoteTaken = (contractBalance(quote))- quoteBal;
numLiquidityPositionsByToken[base]--;
numLiquidityPositionsByToken[quote]--;
nLiquidityPositions--;
if (nLiquidityPositions > 0) {
positions[index] = positions[nLiquidityPositions];
indexFromPositionId[positions[index].tokenId] = index;
}
// We need to call this because of the possible situation where we sent all
// of one token to the liquidity position, but received only the other token
// back.
if (baseTaken < 1000) onSendToken(base);
if (quoteTaken < 1000) onSendToken(quote);
emit PositionBurned(tokenId, base, quote, baseTaken, quoteTaken);
}
// Creates a new liquidity position with the given parameters, and returns the position ID.
// This function will automatically swap tokens to fill the position if needed, first between quote and base,
// then from available WETH, USDC, or ETH reserves. If these are not available, the function will revert.
// Prices are specified in quote per 1e12 base, where base is the other token traded on the pool.
// toAdd is in quote units.
function createV3Position(IUniswapV3Pool pool, address base, address quote, uint80 lowPrice12, uint80 highPrice12, uint256 toAdd) external override returns (uint256 tokenId, uint8 idx) {
require(msg.sender == controller, "Unauthorized");
require(nLiquidityPositions < positions.length, "Out of memory");
require(base != quote, "Same token");
// Get info on the tokens
int8 decimalDiff = int8(IERC20(base).decimals()) - int8(IERC20(quote).decimals());
// Convert prices
// Note that these are in the pool's native ordering, not necessarily ours.
uint160 sqrtRatioAX96 = correctPriceDirection(base, quote, getSqrtPriceX96FromPrice(decimalDiff, lowPrice12));
uint160 sqrtRatioBX96 = correctPriceDirection(base, quote, getSqrtPriceX96FromPrice(decimalDiff, highPrice12));
(uint160 sqrtRatioX96,,,,,,) = pool.slot0();
if (sqrtRatioAX96 > sqrtRatioBX96)
(sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
// Get other random data about the pool
uint128 liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, toAdd);
uint256 feeGrowth;
(tokenId, feeGrowth) = _mintV3Raw(pool, base, quote, sqrtRatioX96, sqrtRatioAX96, sqrtRatioBX96, liquidity);
numLiquidityPositionsByToken[base]++;
numLiquidityPositionsByToken[quote]++;
positions[nLiquidityPositions] = Position(pool, feeGrowth, tokenId, base, quote);
indexFromPositionId[tokenId] = nLiquidityPositions;
idx = nLiquidityPositions;
nLiquidityPositions++;
// Not called because it won't do anything here
// onSendToken(base);
// onSendToken(quote);
emit PositionMinted(tokenId, base, quote, lowPrice12, highPrice12, toAdd);
}
function _mintV3Raw(IUniswapV3Pool pool, address base, address quote, uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity) internal returns (uint256 tokenId, uint256 feeGrowth) {
// Much wow, such solidity!
// Boy do we love stack limitations!!!
uint72 tickVals = uint72(uint24(pool.tickSpacing()));
unchecked {
tickVals |= uint72(uint24((TickMath.getTickAtSqrtRatio(sqrtRatioAX96) / int24(uint24(tickVals))) * int24(uint24(tickVals)))) << 24;
tickVals |= uint72(uint24((TickMath.getTickAtSqrtRatio(sqrtRatioBX96) / int24(uint24(tickVals))) * int24(uint24(tickVals)))) << 48;
}
tokenId = _odeToSolidity(base, quote, sqrtRatioX96, liquidity, tickVals, pool.fee());
feeGrowth = address(base) < quote ? pool.feeGrowthGlobal0X128() : pool.feeGrowthGlobal1X128();
}
function _odeToSolidity(address base, address quote, uint160 sqrtRatioX96, uint128 liquidity, uint72 tickVals, uint24 fee) internal returns (uint256 tokenId) {
address token0 = base > quote ? quote : base;
address token1 = base > quote ? base : quote;
// Calculate amounts of each token
(uint256 amount0, uint256 amount1) = utils.getAmountsForLiquidity(
sqrtRatioX96,
TickMath.getSqrtRatioAtTick(int24(uint24(tickVals >> 24))),
TickMath.getSqrtRatioAtTick(int24(uint24(tickVals >> 48))),
liquidity
);
obtainTokens(token0, token1, amount0, amount1);
INonfungiblePositionManager.MintParams memory params =
INonfungiblePositionManager.MintParams({
token0: token0,
token1: token1,
fee: fee,
tickLower: int24(uint24(tickVals >> 24)),
tickUpper: int24(uint24(tickVals >> 48)),
amount0Desired: amount0,
amount1Desired: amount1,
amount0Min: 0,
amount1Min: 0,
recipient: address(this),
deadline: block.timestamp
});
(tokenId,,,) = manager.mint(params);
}
function onERC721Received(address, address, uint256, bytes calldata) external returns (bytes4) {
return this.onERC721Received.selector;
}
// Swaps tokens
function swapTokensInto(address tokenFrom, address tokenTo, uint256 maxIn, uint256 maxOut) external override returns (uint256 tokensIn, uint256 tokensOut) {
// We don't check permissions because the swap function does that for us
// Maximum 1.5% slippage
return swapTokens(tokenFrom, tokenTo, maxIn, maxOut, 15_000);
}
// Swaps between token0 and token1 if necessery to have amount0 and amount1 available tokens of each.
// If there are not enough of the tokens to do this, the function draws from ETH, WETH, or USDC reserves.
// If this still is not enough, then the function reverts.
// Only the controller may call this function, although this function may also be called internally.
function obtainTokens(address token0, address token1, uint256 amount0, uint256 amount1) public override {
// We don't check permissions because the swap function does that for us
uint256 bal0 = contractBalance(token0);
uint256 bal1 = contractBalance(token1);
// If we already have enough, just return
if (bal0 >= amount0 && bal1 >= amount1) return;
uint256 excess;
uint256 needed0;
uint256 needed1;
unchecked {
needed0 = amount0 < bal0 ? 0 : amount0 - bal0;
needed1 = amount1 < bal1 ? 0 : amount1 - bal1;
}
// Try to swap between token0 and token1 to meet the needs
if (bal0 < amount0 && bal1 > amount1) {unchecked {
excess = bal1 - amount1;
// Will get at most needed0 tokens out, and spend at most excess1 tokens.
(, uint256 tokensOut) = swapTokens(token1, token0, excess, (needed0 * 1015_000) / 1e6, 15_000);
needed0 = needed0 <= tokensOut ? 0 : needed0 - tokensOut;
}} else if (bal1 < amount1 && bal0 > amount0) {unchecked {
excess = bal0 - amount0;
// Will get at most needed1 tokens out, and spend at most excess0 tokens.
(, uint256 tokensOut) = swapTokens(token0, token1, excess, (needed1 * 1015_000) / 1e6, 15_000);
needed1 = needed1 <= tokensOut ? 0 : needed1 - tokensOut;
}}
// Check again: if we still need tokens, draw from reserves
(needed0, needed1) = _obtainTokensHelper(token0, token1, WETH, needed0, needed1);
(needed0, needed1) = _obtainTokensHelper(token0, token1, address(0x0), needed0, needed1);
(needed0, needed1) = _obtainTokensHelper(token0, token1, USDC, needed0, needed1);
require(needed0 == 0 && needed1 == 0, "Underfunded");
}
function _obtainTokensHelper(address token0, address token1, address quote, uint256 needed0, uint256 needed1) internal returns (uint256 newNeeded0, uint256 newNeeded1) {
if (token0 != quote && token1 != quote) {
uint256 balance = contractBalance(quote);
if (balance >= 1e6 && needed0 > 0) {
(uint256 tokensIn, uint256 tokensOut) = swapTokens(quote, token0, balance, (needed0 * 1015_000) / 1e6, 15_000);
unchecked {
balance -= tokensIn;
needed0 = tokensOut >= needed0 ? 0 : needed0 - tokensOut;
}
}
if (balance >= 1e6 && needed1 > 0) {
(,uint256 tokensOut) = swapTokens(quote, token1, balance, (needed1 * 1015_000) / 1e6, 15_000);
unchecked {
needed1 = tokensOut >= needed1 ? 0 : needed1 - tokensOut;
}
}
}
// No change
return (needed0, needed1);
}
// Functions for administration purposes
function getController() external view override returns (address _controller) {
return controller;
}
function setController(address newController) public override onlyOwner {
address oldController = controller;
controller = newController;
emit ControllerSet(newController, oldController);
}
function getFunder() external view override returns (address _funder) {
return funder;
}
function setFunder(address newFunder) public override onlyOwner {
address oldFunder = funder;
funder = newFunder;
emit FunderSet(newFunder, oldFunder);
}
function setUtils(address utilsAdr) public onlyOwner {
utils = IHoldingContractUtils(utilsAdr);
}
// Swap internals
// Make a swap with the given slippage. If slippage is zero, then it is set to 100%, which is dangerous but garuntees
// the swap to occur.
// Will spend at most maxIn tokens, and will receive about at most maxOut tokens.
function swapTokens(address from, address to, uint256 maxIn, uint256 maxOut, uint24 slippageE6) public returns (uint256 amountIn, uint256 amountOut) {
require(msg.sender == controller || msg.sender == address(this), "Unauthorized");
if (from == address(0) && to == WETH) {
amountIn = maxIn < maxOut ? maxIn : maxOut;
WETH9(WETH).deposit{value: amountIn}();
return (amountIn, amountIn);
} else if (from == WETH && to == address(0)) {
amountIn = maxIn < maxOut ? maxIn : maxOut;
WETH9(WETH).withdraw(amountIn);
return (amountIn, amountIn);
}
IUniswapV3Pool pool;
uint256 outMinimum;
(pool, amountIn, outMinimum) = utils.preSwapHelper(from, to, maxIn, maxOut, slippageE6);
if (from == address(0)) {
// Convert to WETH first then change token type
WETH9(WETH).deposit{value: amountIn}();
}
ISwapRouter.ExactInputSingleParams memory params =
ISwapRouter.ExactInputSingleParams({
tokenIn: from == address(0) ? WETH : from,
tokenOut: to == address(0) ? WETH : to,
fee: pool.fee(),
recipient: address(this),
deadline: block.timestamp,
amountIn: amountIn,
amountOutMinimum: outMinimum,
sqrtPriceLimitX96: 0
});
amountOut = swapRouter.exactInputSingle(params);
if (from != address(0)) onSendToken(from);
if (to == address(0)) {
// Convert to ETH
WETH9(WETH).withdraw(amountOut);
} else
onReceiveToken(to);
emit TokensSwapped(from, to, amountIn, amountOut);
}
// Utilities
function correctPriceDirection(address base, address quote, uint160 sqrtPriceX96) public pure returns (uint160 sqrtPriceX96Corrected) {
if (base < quote)
return sqrtPriceX96;
else
return uint160((1 << 192) / uint256(sqrtPriceX96));
}
function getSqrtPriceX96FromPrice(int8 decimalDiff, uint80 price_12Decimals) public pure returns (uint160 sqrtPriceX96) {
unchecked {
uint256 ratioX192 = mulDiv(uint256(price_12Decimals), 1 << 192, 10**uint8(12 + decimalDiff));
return uint160(sqrt(ratioX192));
}
}
/// @notice Computes the amount of liquidity received for a given amount of token0 and price range
/// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount0 being sent in
/// @return liquidity The amount of returned liquidity
function getLiquidityForAmount0(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint256 amount0
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
uint256 intermediate = mulDiv(sqrtRatioAX96, sqrtRatioBX96, 0x1000000000000000000000000 /* FixedPoint96.Q96 */);
return uint128(mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));
}
// https://ethereum-magicians.org/t/eip-7054-gas-efficient-square-root-calculation-with-binary-search-approach/14539
function sqrt(uint x) public pure returns (uint128) {
if (x == 0) return 0;
else {
uint xx = x;
uint r = 1;
if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; }
if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; }
if (xx >= 0x100000000) { xx >>= 32; r <<= 16; }
if (xx >= 0x10000) { xx >>= 16; r <<= 8; }
if (xx >= 0x100) { xx >>= 8; r <<= 4; }
if (xx >= 0x10) { xx >>= 4; r <<= 2; }
if (xx >= 0x8) { r <<= 1; }
unchecked {
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
}
uint r1 = x / r;
return uint128 (r < r1 ? r : r1);
}
}
// From https://arbiscan.io/contractdiffchecker?a2=0x819356bf26d384e7e70cd26c07fc807e6b354f08&a1=0x48e455852669adb747b3d16f2bd8b541d696b697
function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = a * b
// Compute the product mod 2**256 and mod 2**256 - 1
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2**256 + prod0
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(a, b, not(0))
prod0 := mul(a, b)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division
if (prod1 == 0) {
require(denominator > 0);
assembly {
result := div(prod0, denominator)
}
return result;
}
// Make sure the result is less than 2**256.
// Also prevents denominator == 0
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly {
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator
// Compute largest power of two divisor of denominator.
// Always >= 1.
uint256 twos = (0 - denominator) & denominator;
// Divide denominator by power of two
assembly {
denominator := div(denominator, twos)
}
// Divide [prod1 prod0] by the factors of two
assembly {
prod0 := div(prod0, twos)
}
// Shift in bits from prod1 into prod0. For this we need
// to flip `twos` such that it is 2**256 / twos.
// If twos is zero, then it becomes one
assembly {
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
// Invert denominator mod 2**256
// Now that denominator is an odd number, it has an inverse
// modulo 2**256 such that denominator * inv = 1 mod 2**256.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, denominator * inv = 1 mod 2**4
uint256 inv = (3 * denominator) ^ 2;
// Now use Newton-Raphson iteration to improve the precision.
// Thanks to Hensel's lifting lemma, this also works in modular
// arithmetic, doubling the correct bits in each step.
inv *= 2 - denominator * inv; // inverse mod 2**8
inv *= 2 - denominator * inv; // inverse mod 2**16
inv *= 2 - denominator * inv; // inverse mod 2**32
inv *= 2 - denominator * inv; // inverse mod 2**64
inv *= 2 - denominator * inv; // inverse mod 2**128
inv *= 2 - denominator * inv; // inverse mod 2**256
// Because the division is now exact we can divide by multiplying
// with the modular inverse of denominator. This will give us the
// correct result modulo 2**256. Since the precoditions guarantee
// that the outcome is less than 2**256, this is the final result.
// We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inv;
return result;
}
}
}
Read Contract
contractBalance 0xc53b7702 → uint256
controller 0xf77c4791 → address
correctPriceDirection 0xb3a57943 → uint160
factory 0xc45a0155 → address
funder 0x041ae880 → address
getController 0x3018205f → address
getFunder 0x8abb9845 → address
getSqrtPriceX96FromPrice 0x1fba9eda → uint160
getTotalValueEth12 0x63011d1a → uint128
getTotalValueUsd12 0x9ba69249 → uint128
getUsd12ValueIn 0x9a7fe3a1 → uint128
indexFromPositionId 0x42d9843e → uint8
indexFromTokenAddress 0xdf2a558b → uint8
isTokenApprovedForSwap 0x49c69fd8 → bool
manager 0x481c6a75 → address
nLiquidityPositions 0xbc329198 → uint8
nTokensHeld 0x39040ed1 → uint8
numLiquidityPositionsByToken 0xbf0e622b → uint16
owner 0x8da5cb5b → address
positions 0x99fbab88 → address, uint256, uint256, address, address
sqrt 0x677342ce → uint128
swapRouter 0xc31c9c07 → address
tokensHeld 0xc4b19b54 → address
utils 0x5a29638d → address
validEmergencyTokens 0xa9e88b8f → bool
Write Contract 23 functions
These functions modify contract state and require a wallet transaction to execute.
addEmergencyTokens 0x495915d3
address[] tokens
closeLiquidity 0x329aa414
uint256 tokenId
collectFees 0xb17acdcd
uint256 tokenId
createV3Position 0x6a0f27c2
address pool
address base
address quote
uint80 lowPrice12
uint80 highPrice12
uint256 toAdd
returns: uint256, uint8
depositEth 0x439370b1
No parameters
depositToken 0x338b5dea
address token
uint256 amount
destroyPosition 0x4a2539c3
uint256 tokenId
emergencyCircuitBreaker 0xf60b36e3
address storeOfValueToken
fillLiquidity 0x145a6ae0
uint256 positionId
lockEmergencyTokens 0x19cc3357
No parameters
obtainTokens 0x32c4171d
address token0
address token1
uint256 amount0
uint256 amount1
onERC721Received 0x150b7a02
address
address
uint256
bytes
returns: bytes4
renounceOwnership 0x715018a6
No parameters
rescueTokens 0x00ae3bf8
address token
setController 0x92eefe9b
address newController
setFunder 0x0acc8cd1
address newFunder
setUtils 0x69953501
address utilsAdr
swapTokens 0x08092e9a
address from
address to
uint256 maxIn
uint256 maxOut
uint24 slippageE6
returns: uint256, uint256
swapTokensInto 0x81720479
address tokenFrom
address tokenTo
uint256 maxIn
uint256 maxOut
returns: uint256, uint256
transferOwnership 0xf2fde38b
address newOwner
withdrawEth 0x1b9a91a4
address destination
uint256 amount
withdrawLiquidity 0x0a861f2a
uint256 tokenId
withdrawToken 0x01e33667
address token
address destination
uint256 amount
Token Balances (1)
View Transfers →Recent Transactions
No transactions found for this address