Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0xBf65FadD5335380A7d5Aa01f1676af22ee60F9Ad
Balance 0 ETH
Nonce 1
Code Size 18671 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

18671 bytes
0x608060405234801561001057600080fd5b50600436106101cf5760003560e01c8063a001ecdd11610104578063d9ceab13116100a2578063e846500911610071578063e846500914610421578063f2fde38b14610430578063f77c479114610443578063fe09d54d1461046a57600080fd5b8063d9ceab13146103ba578063d9e65ced146103dd578063dc01f60d14610406578063e77061831461041957600080fd5b8063ad5c4648116100de578063ad5c464814610366578063ae06c1b714610381578063bf928f8b14610394578063c4d66de8146103a757600080fd5b8063a001ecdd1461033d578063a64e4f8a14610346578063a80ff90a1461035357600080fd5b80636f307dc3116101715780637d59ce011161014b5780637d59ce01146102e35780638da5cb5b146102f6578063945c9142146103075780639c708aab1461032257600080fd5b80636f307dc314610299578063715018a6146102c0578063759cb53b146102c857600080fd5b80635790a0c8116101ad5780635790a0c81461023e5780635e43c47b14610256578063632473da146102695780636dc47e1e1461028457600080fd5b806303950fb5146101d457806349556709146101e9578063558e44d314610221575b600080fd5b6101e76101e23660046141c4565b61047d565b005b61020473838af967537350d2c44abb8c010e49e32673ab9481565b6040516001600160a01b0390911681526020015b60405180910390f35b610230670429d069189e000081565b604051908152602001610218565b61024661059c565b6040519015158152602001610218565b6102466102643660046141fd565b610b93565b610204739ae380f0272e2162340a5bb646c354271c0f5cfc81565b61028c61105e565b604051610218919061425e565b6102047f000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e81565b6101e761106f565b610204734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b81565b600154610204906001600160a01b031681565b6000546001600160a01b0316610204565b61020473d533a949740bb3306d119cc777fa900ba034cd5281565b61020473d9e1ce17f2641f24ae83637ab66a2cca9c378b9f81565b61023060085481565b6007546102469060ff1681565b6101e76103613660046141fd565b611083565b61020473c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6101e761038f366004614271565b611181565b6101e76103a23660046141fd565b611364565b6101e76103b53660046141fd565b611370565b6103c26114b4565b60408051938452602084019290925290820152606001610218565b6102046103eb3660046141fd565b6004602052600090815260409020546001600160a01b031681565b6103c26104143660046141fd565b611a04565b6101e7611c75565b610230670d2f13f7789f000081565b6101e761043e3660046141fd565b611c89565b6102047f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae81565b6101e76104783660046142f5565b611cff565b610485611eae565b6001600160a01b038083166000908152600460205260409020548116908216036104f65760405162461bcd60e51b815260206004820152601c60248201527f6d75737420626520646966666572656e7420746f2063757272656e740000000060448201526064015b60405180910390fd5b6001600160a01b038116156105305761051a6001600160a01b038316826000611d48565b6105306001600160a01b03831682600019611d48565b6001600160a01b0382811660008181526004602090815260409182902080546001600160a01b031916948616948517905581519283528201929092527f8c529c22babad500cea1516422f2bf23f6e1e7fab884b816062d20a9a0f78fef91015b60405180910390a15050565b6000807f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b031663b050ecb86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106219190614394565b905060008060008061063285611f08565b93509350935093508060200151801561065c5750805160009081526006602052604090205460ff16155b1561066c57805161066c90612450565b6231b93b60e91b600090815260056020527faf8cf1498b7428d6c04c3d3fb7125fa218ad2faf2f4f7f7e26309929a16dfcd1546106a990866143c7565b620c6ecf60eb1b6000908152600560205260008051602061487a833981519152549192509085111561070157620c6ecf60eb1b600052600560205260008051602061487a833981519152546106fe90866143c7565b90505b62636e6360e81b6000908152600560205260008051602061489a8339815191525461072c90866143c7565b600754909150600090819060ff16156107975760085461074d908690612473565b91506107646008548561247390919063ffffffff16565b905061077082866143c7565b945061077c81856143c7565b9350610788828a6143c7565b985061079481896143c7565b97505b60007f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166348439e7e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061081b9190614394565b600154604051635598b20960e01b81526001600160a01b039182166004820152911690635598b20990602401602060405180830381865afa158015610864573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061088891906143da565b905080156108c6576108a2620c6ecf60eb1b8a878461249e565b6108b46231b93b60e91b8b888461249e565b6108c662636e6360e81b89868461249e565b60075460ff166108e25760009b50505050505050505050505090565b6001546040516370a0823160e01b81526001600160a01b03909116600482015260009073d533a949740bb3306d119cc777fa900ba034cd52906370a0823190602401602060405180830381865afa158015610941573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061096591906143da565b8411806109f057506001546040516370a0823160e01b81526001600160a01b039091166004820152734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b906370a0823190602401602060405180830381865afa1580156109c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ed91906143da565b83115b15610a01576109fd6124e2565b5060015b600154610a2e9073d533a949740bb3306d119cc777fa900ba034cd52906001600160a01b031630876127ce565b600154610a5b90734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b906001600160a01b031630866127ce565b60007f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b031663469048406040518163ffffffff1660e01b8152600401602060405180830381865afa158015610abb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610adf9190614394565b9050610b0073d533a949740bb3306d119cc777fa900ba034cd52828761280c565b610b1f734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b828661280c565b6040516309e690eb60e31b815260048101869052602481018590526001600160a01b03821690634f34875890604401600060405180830381600087803b158015610b6857600080fd5b505af1158015610b7c573d6000803e3d6000fd5b50505050819d505050505050505050505050505090565b6000610b9d611eae565b6001600160a01b038216610be55760405162461bcd60e51b815260206004820152600f60248201526e696e76616c6964206164647265737360881b60448201526064016104ed565b610bf060028361289b565b15610c2d5760405162461bcd60e51b815260206004820152600d60248201526c185b1c9958591e481859191959609a1b60448201526064016104ed565b6001600160a01b038216734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b14801590610c7757506001600160a01b03821673d533a949740bb3306d119cc777fa900ba034cd5214155b8015610cb557507f000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e6001600160a01b0316826001600160a01b031614155b8015610cde57506001600160a01b038216739ae380f0272e2162340a5bb646c354271c0f5cfc14155b610d1e5760405162461bcd60e51b81526020600482015260116024820152701d1bdad95b881b9bdd08185b1b1bddd959607a1b60448201526064016104ed565b6001546040805163c5c63e6560e01b815290516000926001600160a01b03169163c5c63e6591600480830192869291908290030181865afa158015610d67573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d8f91908101906143f3565b905060005b8151811015610f525760007f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166355eb6b35848481518110610de057610de0614482565b60200260200101516040518263ffffffff1660e01b8152600401610e1391906001600160a01b0391909116815260200190565b602060405180830381865afa158015610e30573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e549190614394565b6001600160a01b03166376a562a4848481518110610e7457610e74614482565b60200260200101516040518263ffffffff1660e01b8152600401610ea791906001600160a01b0391909116815260200190565b602060405180830381865afa158015610ec4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ee89190614394565b9050806001600160a01b0316856001600160a01b031603610f3f5760405162461bcd60e51b81526020600482015260116024820152701d1bdad95b881b9bdd08185b1b1bddd959607a1b60448201526064016104ed565b5080610f4a81614498565b915050610d94565b5060018054604051630e85cb7760e21b81526001600160a01b0386811660048301526024820193909352911690633a172ddc90604401600060405180830381600087803b158015610fa257600080fd5b505af1158015610fb6573d6000803e3d6000fd5b50610fe4925050506001600160a01b03841673d9e1ce17f2641f24ae83637ab66a2cca9c378b9f6000611d48565b61100e6001600160a01b03841673d9e1ce17f2641f24ae83637ab66a2cca9c378b9f600019611d48565b6040516001600160a01b03841681527fd432e6f46dbf91c120fdfa95a1f4bf5c43f04d957fbc3a32e693be0d29bf17b09060200160405180910390a16110556002846128bd565b9150505b919050565b606061106a60026128d2565b905090565b611077611eae565b61108160006128df565b565b61108b611eae565b61109660028261289b565b6110ce5760405162461bcd60e51b81526020600482015260096024820152681b9bdd08185919195960ba1b60448201526064016104ed565b6110d960028261292f565b50600154604051630e85cb7760e21b81526001600160a01b0383811660048301526000602483015290911690633a172ddc90604401600060405180830381600087803b15801561112857600080fd5b505af115801561113c573d6000803e3d6000fd5b50506040516001600160a01b03841681527fe0f3b1406ab4dd940a92a081b1bcef51da212a57978cc8f6dde5c89ab41a5aa7925060200190505b60405180910390a150565b611189611eae565b670429d069189e000081106111f35760405162461bcd60e51b815260206004820152602a60248201527f63616e6e6f7420736574206665652070657263656e7461676520746f206d6f7260448201526965207468616e2033302560b01b60648201526084016104ed565b60085481036112445760405162461bcd60e51b815260206004820152601c60248201527f6d75737420626520646966666572656e7420746f2063757272656e740000000060448201526064016104ed565b60006001600160a01b03167f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b031663469048406040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112d19190614394565b6001600160a01b03160361131f5760405162461bcd60e51b8152602060048201526015602482015274199959481c9958da5c1a595b9d081b9bdd081cd95d605a1b60448201526064016104ed565b60088190556007805460ff19168215151790556040517f3346af6da1932164d501f2ec28f8c5d686db5828a36b77f2da4332d89184fe7b906111769083815260200190565b61136d81612944565b50565b611378611eae565b600054600160a81b900460ff16158080156113a057506000546001600160a01b90910460ff16105b806113c15750303b1580156113c15750600054600160a01b900460ff166001145b6114245760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016104ed565b6000805460ff60a01b1916600160a01b1790558015611451576000805460ff60a81b1916600160a81b1790555b600180546001600160a01b0319166001600160a01b03841617905580156114b0576000805460ff60a81b19169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610590565b5050565b60008060006114c233612944565b3360009081527faf8cf1498b7428d6c04c3d3fb7125fa218ad2faf2f4f7f7e26309929a16dfcd360209081526040808320547f1da685d363c3798567409758b6f6466f17974a073e3ce7ce447c063c18ab49628352818420547f8cda27973994b4c9cef5fc6716a5ee96cc4abe3353228d7fabf6c8bb342178b0909352928190205460015491516370a0823160e01b81526001600160a01b0390921660048301529073d533a949740bb3306d119cc777fa900ba034cd52906370a0823190602401602060405180830381865afa1580156115a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115c491906143da565b83118061164f57506001546040516370a0823160e01b81526001600160a01b039091166004820152734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b906370a0823190602401602060405180830381865afa158015611628573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061164c91906143da565b82115b806116d857506001546040516370a0823160e01b81526001600160a01b039091166004820152739ae380f0272e2162340a5bb646c354271c0f5cfc906370a0823190602401602060405180830381865afa1580156116b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116d591906143da565b81115b15611731576116e56124e2565b60006116f16002612a7b565b11156117315761170033612944565b503360009081527f8cda27973994b4c9cef5fc6716a5ee96cc4abe3353228d7fabf6c8bb342178b060205260409020545b3360008181527f8cda27973994b4c9cef5fc6716a5ee96cc4abe3353228d7fabf6c8bb342178b0602090815260408083208390557f1da685d363c3798567409758b6f6466f17974a073e3ce7ce447c063c18ab496282528083208390557faf8cf1498b7428d6c04c3d3fb7125fa218ad2faf2f4f7f7e26309929a16dfcd39091528120556001546117e29173d533a949740bb3306d119cc777fa900ba034cd52916001600160a01b031690866127ce565b60015461180f90734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b906001600160a01b031633856127ce565b6001546040516370a0823160e01b81526001600160a01b0390911660048201528190739ae380f0272e2162340a5bb646c354271c0f5cfc906370a0823190602401602060405180830381865afa15801561186d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189191906143da565b106118c3576001546118c390739ae380f0272e2162340a5bb646c354271c0f5cfc906001600160a01b031633846127ce565b60008060006119527f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b031663b050ecb86040518163ffffffff1660e01b8152600401602060405180830381865afa158015611929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061194d9190614394565b612a85565b600560209081527faf8cf1498b7428d6c04c3d3fb7125fa218ad2faf2f4f7f7e26309929a16dfcd184905560008051602061487a83398151915283905562636e6360e81b60005260008051602061489a833981519152829055604080518981529182018b90528101899052929550909350915033907f06f39318c760ad4d630f57ba8f8d3c21b8e1deb076e19476d1dece4e3d737e7a9060600160405180910390a25091979396509194509192505050565b6000806000807f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166348439e7e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8c9190614394565b600154604051635598b20960e01b81526001600160a01b039182166004820152911690635598b20990602401602060405180830381865afa158015611ad5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611af991906143da565b90506000806000611b08612aa1565b92509250925060007f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166348439e7e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b929190614394565b600154604051637d2041e560e11b81526001600160a01b0391821660048201528b8216602482015291169063fa4083ca90604401602060405180830381865afa158015611be3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0791906143da565b9050611c1e8962636e6360e81b8484896000612b40565b9750611c43896231b93b60e91b868489600760009054906101000a900460ff16612b40565b9650611c6889620c6ecf60eb1b858489600760009054906101000a900460ff16612b40565b9799969850505050505050565b611c7d61059c565b611081576110816124e2565b611c91611eae565b6001600160a01b038116611cf65760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016104ed565b61136d816128df565b611d07611eae565b60005b81518110156114b057611d35828281518110611d2857611d28614482565b6020026020010151610b93565b5080611d4081614498565b915050611d0a565b801580611dc25750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015611d9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dc091906143da565b155b611e2d5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b60648201526084016104ed565b6040516001600160a01b038316602482015260448101829052611e9090849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612c15565b505050565b6060611ea48484600085612cea565b90505b9392505050565b6000546001600160a01b031633146110815760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016104ed565b6000806000611f2c6040518060400160405280600081526020016000151581525090565b6001546040805163c5c63e6560e01b815290516000926001600160a01b03169163c5c63e6591600480830192869291908290030181865afa158015611f75573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611f9d91908101906143f3565b90506000805b8251811015612125577f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166355eb6b35848381518110611fed57611fed614482565b60200260200101516040518263ffffffff1660e01b815260040161202091906001600160a01b0391909116815260200190565b602060405180830381865afa15801561203d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120619190614394565b60015484516001600160a01b039283169263a775e15e92169086908590811061208c5761208c614482565b60200260200101516040518363ffffffff1660e01b81526004016120c69291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa1580156120e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061210791906143da565b61211190836144b1565b91508061211d81614498565b915050611fa3565b506001546040516370a0823160e01b81526001600160a01b039091166004820152819073d533a949740bb3306d119cc777fa900ba034cd52906370a0823190602401602060405180830381865afa158015612184573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121a891906143da565b6121b291906144b1565b60405163705e1e5560e01b8152600481018390529096506000906001600160a01b0389169063705e1e5590602401606060405180830381865afa1580156121fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061222191906144d4565b6001546040516370a0823160e01b81526001600160a01b0390911660048201529095509091508190734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b906370a0823190602401602060405180830381865afa158015612285573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122a991906143da565b6122b391906144b1565b6001546040516370a0823160e01b81526001600160a01b039091166004820152909650739ae380f0272e2162340a5bb646c354271c0f5cfc906370a0823190602401602060405180830381865afa158015612312573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061233691906143da565b600154909550600160a01b900460ff16612446577f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166348439e7e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156123a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123cc9190614394565b6001546040516334d21ea360e21b81526001600160a01b03918216600482015291169063d3487a8c90602401602060405180830381865afa158015612415573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061243991906143da565b61244390866144b1565b94505b5050509193509193565b6124586124e2565b6000908152600660205260409020805460ff19166001179055565b60006124816012600a61462e565b61248b838561463a565b6124959190614651565b90505b92915050565b6124a88282612dc7565b600085815260056020526040812080549091906124c69084906144b1565b9091555050506000928352506005602052604090912060010155565b6124ea612de0565b6001546040516370a0823160e01b81526001600160a01b039091166004820152600090739ae380f0272e2162340a5bb646c354271c0f5cfc906370a0823190602401602060405180830381865afa158015612549573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061256d91906143da565b9050612577613340565b6001546040516370a0823160e01b81526001600160a01b0390911660048201526000908290739ae380f0272e2162340a5bb646c354271c0f5cfc906370a0823190602401602060405180830381865afa1580156125d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125fc91906143da565b61260691906143c7565b905060007f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166348439e7e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612668573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061268c9190614394565b600154604051635598b20960e01b81526001600160a01b039182166004820152911690635598b20990602401602060405180830381865afa1580156126d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126f991906143da565b905060008111801561270b5750600082115b15611e905761271a8282612dc7565b62636e6360e81b600090815260056020527f8cda27973994b4c9cef5fc6716a5ee96cc4abe3353228d7fabf6c8bb342178ad805490919061275c9084906144b1565b909155505062636e6360e81b6000908152600560205260008051602061489a83398151915280548492906127919084906144b1565b90915550506040518281527ffc8ed0cd46874d9c3cf1425e1b3bbf9c523bc17c4a959c2c2f600e016f4eddef9060200160405180910390a1505050565b6040516001600160a01b03808516602483015283166044820152606481018290526128069085906323b872dd60e01b90608401611e59565b50505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261285d8482613437565b612806576040516001600160a01b03841660248201526000604482015261289190859063095ea7b360e01b90606401611e59565b6128068482612c15565b6001600160a01b03811660009081526001830160205260408120541515612495565b6000612495836001600160a01b0384166134de565b60606000611ea78361352d565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000612495836001600160a01b038416613589565b60007f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166348439e7e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129c89190614394565b600154604051637d2041e560e11b81526001600160a01b039182166004820152848216602482015291169063fa4083ca90604401602060405180830381865afa158015612a19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a3d91906143da565b9050612a4761059c565b50612a5962636e6360e81b838361367c565b612a6a6231b93b60e91b838361367c565b6114b0620c6ecf60eb1b838361367c565b6000612498825490565b6000806000612a9384611f08565b509196909550909350915050565b6000806000807f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b031663b050ecb86040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b299190614394565b9050612b3481613717565b93509350935050909192565b600085815260056020526040812080548415612bb3578315612b9c57612b8b85612b856008546012600a612b74919061462e565b612b7e91906143c7565b8a90612473565b90612dc7565b612b9590826144b1565b9050612bb3565b612ba68786612dc7565b612bb090826144b1565b90505b6001600160a01b0389166000908152600283016020526040902054612be390612bdc90836143c7565b8790612473565b6001600160a01b038a166000908152600384016020526040902054612c0891906144b1565b9998505050505050505050565b6000612c6a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611e959092919063ffffffff16565b9050805160001480612c8b575080806020019051810190612c8b9190614673565b611e905760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016104ed565b606082471015612d4b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016104ed565b600080866001600160a01b03168587604051612d6791906146b2565b60006040518083038185875af1925050503d8060008114612da4576040519150601f19603f3d011682016040523d82523d6000602084013e612da9565b606091505b5091509150612dba878383876137cf565b925050505b949350505050565b600081612dd66012600a61462e565b61248b908561463a565b6001805460ff60a01b1916600160a01b17905560408051632421cf3f60e11b815290516001600160a01b037f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae16916348439e7e9160048083019260209291908290030181865afa158015612e58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7c9190614394565b60015460405163a0190c1760e01b81526001600160a01b03918216600482015291169063a0190c1790602401600060405180830381600087803b158015612ec257600080fd5b505af1158015612ed6573d6000803e3d6000fd5b50506001805460ff60a01b1981169091556040516370a0823160e01b81526001600160a01b03909116600482015260009250734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b91506370a0823190602401602060405180830381865afa158015612f45573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f6991906143da565b6001546040516370a0823160e01b81526001600160a01b03909116600482015290915060009073d533a949740bb3306d119cc777fa900ba034cd52906370a0823190602401602060405180830381865afa158015612fcb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fef91906143da565b90506000600160009054906101000a90046001600160a01b03166001600160a01b031663c5c63e656040518163ffffffff1660e01b8152600401600060405180830381865afa158015613046573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261306e91908101906143f3565b905060005b81518110156131db577f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b03166355eb6b358383815181106130bd576130bd614482565b60200260200101516040518263ffffffff1660e01b81526004016130f091906001600160a01b0391909116815260200190565b602060405180830381865afa15801561310d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131319190614394565b60015483516001600160a01b039283169263970de38192169085908590811061315c5761315c614482565b60200260200101516040518363ffffffff1660e01b81526004016131969291906001600160a01b0392831681529116602082015260400190565b600060405180830381600087803b1580156131b057600080fd5b505af11580156131c4573d6000803e3d6000fd5b5050505080806131d390614498565b915050613073565b506001546040516370a0823160e01b81526001600160a01b0390911660048201526000908490734e3fbd56cd56c3e72c1403e103b45db9da5b9d2b906370a0823190602401602060405180830381865afa15801561323d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061326191906143da565b61326b91906143c7565b6001546040516370a0823160e01b81526001600160a01b039091166004820152909150600090849073d533a949740bb3306d119cc777fa900ba034cd52906370a0823190602401602060405180830381865afa1580156132cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132f391906143da565b6132fd91906143c7565b60408051828152602081018590529192507f141d6e75554381bcc1326596e8010e6c432bb0988e14ca0310d85837a211d292910160405180910390a15050505050565b600061334c6002612a7b565b9050806000036133595750565b60005b8181101561342e57600154613409906001600160a01b031630613380600285613848565b6001546040516370a0823160e01b81526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa1580156133c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133ed91906143da565b6133f8600286613848565b6001600160a01b03169291906127ce565b61341c613417600283613848565b613854565b8061342681614498565b91505061335c565b5061136d613c1a565b6000806000846001600160a01b03168460405161345491906146b2565b6000604051808303816000865af19150503d8060008114613491576040519150601f19603f3d011682016040523d82523d6000602084013e613496565b606091505b50915091508180156134c05750805115806134c05750808060200190518101906134c09190614673565b80156134d557506001600160a01b0385163b15155b95945050505050565b600081815260018301602052604081205461352557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155612498565b506000612498565b60608160000180548060200260200160405190810160405280929190818152602001828054801561357d57602002820191906000526020600020905b815481526020019060010190808311613569575b50505050509050919050565b600081815260018301602052604081205480156136725760006135ad6001836143c7565b85549091506000906135c1906001906143c7565b90508181146136265760008660000182815481106135e1576135e1614482565b906000526020600020015490508087600001848154811061360457613604614482565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613637576136376146ce565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050612498565b6000915050612498565b60008381526005602090815260408083206001600160a01b03861684526002810190925282205481549192916136bc916136b5916143c7565b8490612473565b6001600160a01b03851660009081526003840160205260408120805492935083929091906136eb9084906144b1565b909155505081546001600160a01b03909416600090815260029092016020525060409020919091555050565b60008060008060008061372987612a85565b6231b93b60e91b60005260056020527faf8cf1498b7428d6c04c3d3fb7125fa218ad2faf2f4f7f7e26309929a16dfcd154929550909350915061376c90846143c7565b620c6ecf60eb1b600052600560205260008051602061487a8339815191525490965061379890836143c7565b62636e6360e81b600052600560205260008051602061489a833981519152549095506137c490826143c7565b959794965050505050565b6060831561383e578251600003613837576001600160a01b0385163b6138375760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016104ed565b5081612dbf565b612dbf8383613d7e565b60006124958383613da8565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa15801561389b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138bf91906143da565b9050806000036138cd575050565b6001600160a01b03808316600090815260046020526040902054168015613ada576000807f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b0316639f82b2176040518163ffffffff1660e01b8152600401602060405180830381865afa15801561394f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139739190614394565b604051632feaac8560e11b81526001600160a01b038581166004830152878116602483015273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc260448301529190911690635fd5590a90606401606060405180830381865afa1580156139dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a0191906146f6565b5090925090506fffffffffffffffffffffffffffffffff8083169082166001600160a01b03851663ce7d6503838389613a4f8c73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc283613dd2565b6040516001600160e01b031960e087901b1681526004810194909452602484019290925260448301526064820152600060848201523060a482015260c4016020604051808303816000875af1158015613aac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ad091906143da565b5050505050505050565b6040805160028082526060820183526000926020830190803683370190505090508381600081518110613b0f57613b0f614482565b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110613b5757613b57614482565b6001600160a01b039092166020928302919091019091015273d9e1ce17f2641f24ae83637ab66a2cca9c378b9f6338ed173984613ba98773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc283613dd2565b8430426040518663ffffffff1660e01b8152600401613bcc959493929190614739565b6000604051808303816000875af1158015613beb573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613c139190810190614775565b5050505050565b6040516370a0823160e01b815230600482015260009073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906370a0823190602401602060405180830381865afa158015613c6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c9091906143da565b905080600003613c9d5750565b73838af967537350d2c44abb8c010e49e32673ab9463ce7d65036000600184613cef73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2739ae380f0272e2162340a5bb646c354271c0f5cfc83613dd2565b60015460405160e087901b6001600160e01b03191681526004810195909552602485019390935260448401919091526064830152600060848301526001600160a01b031660a482015260c4016020604051808303816000875af1158015613d5a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114b091906143da565b815115613d8e5781518083602001fd5b8060405162461bcd60e51b81526004016104ed91906147fb565b6000826000018281548110613dbf57613dbf614482565b9060005260206000200154905092915050565b6000807f0000000000000000000000002790ec478f150a98f5d96755601a26403df57eae6001600160a01b0316632630c12f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613e33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e579190614394565b9050836001600160a01b0316856001600160a01b031603613e7b5782915050611ea7565b6040516375151b6360e01b81526001600160a01b0386811660048301528216906375151b6390602401602060405180830381865afa158015613ec1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ee59190614673565b1580613f5857506040516375151b6360e01b81526001600160a01b0385811660048301528216906375151b6390602401602060405180830381865afa158015613f32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f569190614673565b155b15613f67576000915050611ea7565b6134d5670d2f13f7789f0000614126876001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613fb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fd8919061482e565b876001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614016573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061403a919061482e565b604051638b2f0f4f60e01b81526001600160a01b038a8116600483015261411f9190881690638b2f0f4f90602401602060405180830381865afa158015614085573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140a991906143da565b604051638b2f0f4f60e01b81526001600160a01b038d81166004830152612b8591908a1690638b2f0f4f90602401602060405180830381865afa1580156140f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061411891906143da565b8b90612473565b919061412c565b90612473565b60008160ff168360ff1603614142575082611ea7565b8160ff168360ff1611156141625761415b84848461416d565b9050611ea7565b611ea484848461418e565b60006141798284614851565b61418490600a61486a565b611ea49085614651565b600061419a8383614851565b6141a590600a61486a565b611ea4908561463a565b6001600160a01b038116811461136d57600080fd5b600080604083850312156141d757600080fd5b82356141e2816141af565b915060208301356141f2816141af565b809150509250929050565b60006020828403121561420f57600080fd5b8135611ea7816141af565b600081518084526020808501945080840160005b838110156142535781516001600160a01b03168752958201959082019060010161422e565b509495945050505050565b602081526000612495602083018461421a565b60006020828403121561428357600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156142c9576142c961428a565b604052919050565b600067ffffffffffffffff8211156142eb576142eb61428a565b5060051b60200190565b6000602080838503121561430857600080fd5b823567ffffffffffffffff81111561431f57600080fd5b8301601f8101851361433057600080fd5b803561434361433e826142d1565b6142a0565b81815260059190911b8201830190838101908783111561436257600080fd5b928401925b8284101561438957833561437a816141af565b82529284019290840190614367565b979650505050505050565b6000602082840312156143a657600080fd5b8151611ea7816141af565b634e487b7160e01b600052601160045260246000fd5b81810381811115612498576124986143b1565b6000602082840312156143ec57600080fd5b5051919050565b6000602080838503121561440657600080fd5b825167ffffffffffffffff81111561441d57600080fd5b8301601f8101851361442e57600080fd5b805161443c61433e826142d1565b81815260059190911b8201830190838101908783111561445b57600080fd5b928401925b82841015614389578351614473816141af565b82529284019290840190614460565b634e487b7160e01b600052603260045260246000fd5b6000600182016144aa576144aa6143b1565b5060010190565b80820180821115612498576124986143b1565b8051801515811461105957600080fd5b60008082840360608112156144e857600080fd5b835192506040601f19820112156144fe57600080fd5b506040516040810181811067ffffffffffffffff821117156145225761452261428a565b80604052506020840151815261453a604085016144c4565b6020820152809150509250929050565b600181815b8085111561458557816000190482111561456b5761456b6143b1565b8085161561457857918102915b93841c939080029061454f565b509250929050565b60008261459c57506001612498565b816145a957506000612498565b81600181146145bf57600281146145c9576145e5565b6001915050612498565b60ff8411156145da576145da6143b1565b50506001821b612498565b5060208310610133831016604e8410600b8410161715614608575081810a612498565b614612838361454a565b8060001904821115614626576146266143b1565b029392505050565b6000612495838361458d565b8082028115828204841417612498576124986143b1565b60008261466e57634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561468557600080fd5b612495826144c4565b60005b838110156146a9578181015183820152602001614691565b50506000910152565b600082516146c481846020870161468e565b9190910192915050565b634e487b7160e01b600052603160045260246000fd5b8051600f81900b811461105957600080fd5b60008060006060848603121561470b57600080fd5b614714846146e4565b9250614722602085016146e4565b9150614730604085016144c4565b90509250925092565b85815284602082015260a06040820152600061475860a083018661421a565b6001600160a01b0394909416606083015250608001529392505050565b6000602080838503121561478857600080fd5b825167ffffffffffffffff81111561479f57600080fd5b8301601f810185136147b057600080fd5b80516147be61433e826142d1565b81815260059190911b820183019083810190878311156147dd57600080fd5b928401925b82841015614389578351825292840192908401906147e2565b602081526000825180602084015261481a81604085016020870161468e565b601f01601f19169190910160400192915050565b60006020828403121561484057600080fd5b815160ff81168114611ea757600080fd5b60ff8281168282160390811115612498576124986143b1565b600061249560ff84168361458d56fe1da685d363c3798567409758b6f6466f17974a073e3ce7ce447c063c18ab49608cda27973994b4c9cef5fc6716a5ee96cc4abe3353228d7fabf6c8bb342178aea2646970667358221220bed05886cd97652436782d460588624a887d0801d051a032ba7a50295d02173164736f6c63430008110033

Verified Source Code Partial Match

Compiler: v0.8.17+commit.8df45f5f EVM: london Optimization: Yes (200 runs)
Types.sol 14 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

library Types {
    struct Coin {
        address coinAddress;
        uint8 decimals;
    }

    struct CliffInfo {
        uint256 currentCliff;
        bool withinThreshold;
    }
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
IOracle.sol 12 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

interface IOracle {
    event TokenUpdated(address indexed token, address feed, uint256 maxDelay, bool isEthPrice);

    /// @notice returns the price in USD of symbol.
    function getUSDPrice(address token) external view returns (uint256);

    /// @notice returns if the given token is supported for pricing.
    function isTokenSupported(address token) external view returns (bool);
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
IBonding.sol 59 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

interface IBonding {
    event CncStartPriceSet(uint256 startPrice);
    event PriceIncreaseFactorSet(uint256 factor);
    event MinBondingAmountSet(uint256 amount);
    event Bonded(
        address indexed account,
        address indexed recipient,
        uint256 lpTokenAmount,
        uint256 cncReceived,
        uint256 lockTime
    );
    event DebtPoolSet(address indexed pool);
    event DebtPoolFeesClaimed(uint256 crvAmount, uint256 cvxAmount, uint256 cncAmount);
    event StreamClaimed(address indexed account, uint256 amount);
    event BondingStarted(uint256 amount, uint256 epochs);
    event RemainingCNCRecovered(uint256 amount);

    function startBonding() external;

    function setCncStartPrice(uint256 _cncStartPrice) external;

    function setCncPriceIncreaseFactor(uint256 _priceIncreaseFactor) external;

    function setMinBondingAmount(uint256 _minBondingAmount) external;

    function setDebtPool(address _debtPool) external;

    function bondCncCrvUsd(
        uint256 lpTokenAmount,
        uint256 minCncReceived,
        uint64 cncLockTime
    ) external returns (uint256);

    function recoverRemainingCNC() external;

    function claimStream() external;

    function claimFeesForDebtPool() external;

    function streamCheckpoint() external;

    function accountCheckpoint(address account) external;

    function computeCurrentCncBondPrice() external view returns (uint256);

    function cncAvailable() external view returns (uint256);

    function cncBondPrice() external view returns (uint256);

    function bondCncCrvUsdFor(
        uint256 lpTokenAmount,
        uint256 minCncReceived,
        uint64 cncLockTime,
        address recipient
    ) external returns (uint256);
}
IBooster.sol 32 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

interface IBooster {
    function poolInfo(
        uint256 pid
    )
        external
        view
        returns (
            address lpToken,
            address token,
            address gauge,
            address crvRewards,
            address stash,
            bool shutdown
        );

    function poolLength() external view returns (uint256);

    function deposit(uint256 _pid, uint256 _amount, bool _stake) external returns (bool);

    function withdraw(uint256 _pid, uint256 _amount) external returns (bool);

    function withdrawAll(uint256 _pid) external returns (bool);

    function depositAll(uint256 _pid, bool _stake) external returns (bool);

    function earmarkRewards(uint256 _pid) external returns (bool);

    function isShutdown() external view returns (bool);
}
ILpToken.sol 14 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "IERC20Metadata.sol";

interface ILpToken is IERC20Metadata {
    function minter() external view returns (address);

    function mint(address account, uint256 amount, address ubo) external returns (uint256);

    function burn(address _owner, uint256 _amount, address ubo) external returns (uint256);

    function taint(address from, address to, uint256 amount) external;
}
IPausable.sol 23 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "Ownable.sol";

import "IController.sol";

interface IPausable {
    event Paused(uint256 pausedUntil);
    event PauseDurationSet(uint256 pauseDuration);

    function controller() external view returns (IController);

    function pausedUntil() external view returns (uint256);

    function pauseDuration() external view returns (uint256);

    function isPaused() external view returns (bool);

    function setPauseDuration(uint256 _pauseDuration) external;

    function pause() external;
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "IERC20.sol";
import "IERC20Permit.sol";
import "Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}
IConicPool.sol 131 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "ILpToken.sol";
import "IRewardManager.sol";
import "IOracle.sol";
import "IController.sol";
import "IPausable.sol";
import "IConicPoolWeightManagement.sol";

interface IConicPool is IConicPoolWeightManagement, IPausable {
    event Deposit(
        address indexed sender,
        address indexed receiver,
        uint256 depositedAmount,
        uint256 lpReceived
    );
    event Withdraw(address indexed account, uint256 amount);
    event NewWeight(address indexed curvePool, uint256 newWeight);
    event NewMaxIdleCurveLpRatio(uint256 newRatio);
    event ClaimedRewards(uint256 claimedCrv, uint256 claimedCvx);
    event HandledDepeggedCurvePool(address curvePool_);
    event HandledInvalidConvexPid(address curvePool_, uint256 pid_);
    event CurvePoolAdded(address curvePool_);
    event CurvePoolRemoved(address curvePool_);
    event Shutdown();
    event DepegThresholdUpdated(uint256 newThreshold);
    event MaxDeviationUpdated(uint256 newMaxDeviation);
    event RebalancingRewardsEnabledSet(bool enabled);
    event EmergencyRebalancingRewardFactorUpdated(uint256 factor);

    struct PoolWithAmount {
        address poolAddress;
        uint256 amount;
    }

    function underlying() external view returns (IERC20Metadata);

    function lpToken() external view returns (ILpToken);

    function rewardManager() external view returns (IRewardManager);

    function depegThreshold() external view returns (uint256);

    function maxIdleCurveLpRatio() external view returns (uint256);

    function setMaxIdleCurveLpRatio(uint256 value) external;

    function setMaxDeviation(uint256 maxDeviation_) external;

    function updateDepegThreshold(uint256 value) external;

    function depositFor(
        address _account,
        uint256 _amount,
        uint256 _minLpReceived,
        bool stake
    ) external returns (uint256);

    function deposit(uint256 _amount, uint256 _minLpReceived) external returns (uint256);

    function deposit(
        uint256 _amount,
        uint256 _minLpReceived,
        bool stake
    ) external returns (uint256);

    function exchangeRate() external view returns (uint256);

    function usdExchangeRate() external view returns (uint256);

    function unstakeAndWithdraw(uint256 _amount, uint256 _minAmount) external returns (uint256);

    function unstakeAndWithdraw(
        uint256 _amount,
        uint256 _minAmount,
        address _to
    ) external returns (uint256);

    function withdraw(uint256 _amount, uint256 _minAmount) external returns (uint256);

    function withdraw(uint256 _amount, uint256 _minAmount, address _to) external returns (uint256);

    function getAllocatedUnderlying() external view returns (PoolWithAmount[] memory);

    function rebalancingRewardActive() external view returns (bool);

    function totalDeviationAfterWeightUpdate() external view returns (uint256);

    function computeTotalDeviation() external view returns (uint256);

    /// @notice returns the total amount of funds held by this pool in terms of underlying
    function totalUnderlying() external view returns (uint256);

    function getTotalAndPerPoolUnderlying()
        external
        view
        returns (
            uint256 totalUnderlying_,
            uint256 totalAllocated_,
            uint256[] memory perPoolUnderlying_
        );

    /// @notice same as `totalUnderlying` but returns a cached version
    /// that might be slightly outdated if oracle prices have changed
    /// @dev this is useful in cases where we want to reduce gas usage and do
    /// not need a precise value
    function cachedTotalUnderlying() external view returns (uint256);

    function updateRewardSpendingApproval(address token, bool approved) external;

    function shutdownPool() external;

    function isShutdown() external view returns (bool);

    function isBalanced() external view returns (bool);

    function rebalancingRewardsEnabled() external view returns (bool);

    function setRebalancingRewardsEnabled(bool enabled) external;

    function getAllUnderlyingCoins() external view returns (address[] memory result);

    function rebalancingRewardsFactor() external view returns (uint256);

    function rebalancingRewardsActivatedAt() external view returns (uint64);

    function getWeights() external view returns (PoolWeight[] memory);

    function runSanityChecks() external;
}
ScaledMath.sol 131 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

library ScaledMath {
    uint256 internal constant DECIMALS = 18;
    uint256 internal constant ONE = 10 ** DECIMALS;

    function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
        return (a * b) / ONE;
    }

    function mulDown(uint256 a, uint256 b, uint256 decimals) internal pure returns (uint256) {
        return (a * b) / (10 ** decimals);
    }

    function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
        return (a * ONE) / b;
    }

    function divDown(uint256 a, uint256 b, uint256 decimals) internal pure returns (uint256) {
        return (a * 10 ** decimals) / b;
    }

    function divUp(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        return ((a * ONE) - 1) / b + 1;
    }

    function mulDown(int256 a, int256 b) internal pure returns (int256) {
        return (a * b) / int256(ONE);
    }

    function mulDownUint128(uint128 a, uint128 b) internal pure returns (uint128) {
        return (a * b) / uint128(ONE);
    }

    function mulDown(int256 a, int256 b, uint256 decimals) internal pure returns (int256) {
        return (a * b) / int256(10 ** decimals);
    }

    function divDown(int256 a, int256 b) internal pure returns (int256) {
        return (a * int256(ONE)) / b;
    }

    function divDownUint128(uint128 a, uint128 b) internal pure returns (uint128) {
        return (a * uint128(ONE)) / b;
    }

    function divDown(int256 a, int256 b, uint256 decimals) internal pure returns (int256) {
        return (a * int256(10 ** decimals)) / b;
    }

    function convertScale(
        uint256 a,
        uint8 fromDecimals,
        uint8 toDecimals
    ) internal pure returns (uint256) {
        if (fromDecimals == toDecimals) return a;
        if (fromDecimals > toDecimals) return downscale(a, fromDecimals, toDecimals);
        return upscale(a, fromDecimals, toDecimals);
    }

    function convertScale(
        int256 a,
        uint8 fromDecimals,
        uint8 toDecimals
    ) internal pure returns (int256) {
        if (fromDecimals == toDecimals) return a;
        if (fromDecimals > toDecimals) return downscale(a, fromDecimals, toDecimals);
        return upscale(a, fromDecimals, toDecimals);
    }

    function upscale(
        uint256 a,
        uint8 fromDecimals,
        uint8 toDecimals
    ) internal pure returns (uint256) {
        return a * (10 ** (toDecimals - fromDecimals));
    }

    function downscale(
        uint256 a,
        uint8 fromDecimals,
        uint8 toDecimals
    ) internal pure returns (uint256) {
        return a / (10 ** (fromDecimals - toDecimals));
    }

    function upscale(
        int256 a,
        uint8 fromDecimals,
        uint8 toDecimals
    ) internal pure returns (int256) {
        return a * int256(10 ** (toDecimals - fromDecimals));
    }

    function downscale(
        int256 a,
        uint8 fromDecimals,
        uint8 toDecimals
    ) internal pure returns (int256) {
        return a / int256(10 ** (fromDecimals - toDecimals));
    }

    function intPow(uint256 a, uint256 n) internal pure returns (uint256) {
        uint256 result = ONE;
        for (uint256 i; i < n; ) {
            result = mulDown(result, a);
            unchecked {
                ++i;
            }
        }
        return result;
    }

    function absSub(uint256 a, uint256 b) internal pure returns (uint256) {
        unchecked {
            return a >= b ? a - b : b - a;
        }
    }

    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a <= b ? a : b;
    }
}
IController.sol 143 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "IConicPoolWeightManagement.sol";
import "IConicPool.sol";
import "IGenericOracle.sol";
import "IInflationManager.sol";
import "ILpTokenStaker.sol";
import "IBonding.sol";
import "IPoolAdapter.sol";
import "IFeeRecipient.sol";
import "ICurveRegistryCache.sol";

interface IController {
    event PoolAdded(address indexed pool);
    event PoolRemoved(address indexed pool);
    event PoolShutdown(address indexed pool);
    event ConvexBoosterSet(address convexBooster);
    event CurveHandlerSet(address curveHandler);
    event ConvexHandlerSet(address convexHandler);
    event CurveRegistryCacheSet(address curveRegistryCache);
    event InflationManagerSet(address inflationManager);
    event BondingSet(address bonding);
    event FeeRecipientSet(address feeRecipient);
    event PriceOracleSet(address priceOracle);
    event WeightUpdateMinDelaySet(uint256 weightUpdateMinDelay);
    event PauseManagerSet(address indexed manager, bool isManager);
    event MultiDepositsWithdrawsWhitelistSet(address pool, bool allowed);
    event MinimumTaintedTransferAmountSet(address indexed token, uint256 amount);
    event DefaultPoolAdapterSet(address poolAdapter);
    event CustomPoolAdapterSet(address indexed pool, address poolAdapter);

    struct WeightUpdate {
        address conicPoolAddress;
        IConicPoolWeightManagement.PoolWeight[] weights;
    }

    function initialize(address _lpTokenStaker) external;

    // inflation manager

    function inflationManager() external view returns (IInflationManager);

    function setInflationManager(address manager) external;

    // views
    function curveRegistryCache() external view returns (ICurveRegistryCache);

    // pool adapter
    function poolAdapterFor(address pool) external view returns (IPoolAdapter);

    function defaultPoolAdapter() external view returns (IPoolAdapter);

    function setDefaultPoolAdapter(address poolAdapter) external;

    function setCustomPoolAdapter(address pool, address poolAdapter) external;

    /// lp token staker
    function switchLpTokenStaker(address _lpTokenStaker) external;

    function lpTokenStaker() external view returns (ILpTokenStaker);

    // bonding
    function bonding() external view returns (IBonding);

    function setBonding(address _bonding) external;

    // fees
    function feeRecipient() external view returns (IFeeRecipient);

    function setFeeRecipient(address _feeRecipient) external;

    // oracle
    function priceOracle() external view returns (IGenericOracle);

    function setPriceOracle(address oracle) external;

    // pool functions

    function listPools() external view returns (address[] memory);

    function listActivePools() external view returns (address[] memory);

    function isPool(address poolAddress) external view returns (bool);

    function isActivePool(address poolAddress) external view returns (bool);

    function addPool(address poolAddress) external;

    function shutdownPool(address poolAddress) external;

    function removePool(address poolAddress) external;

    function cncToken() external view returns (address);

    function lastWeightUpdate(address poolAddress) external view returns (uint256);

    function updateWeights(WeightUpdate memory update) external;

    function updateAllWeights(WeightUpdate[] memory weights) external;

    // handler functions

    function convexBooster() external view returns (address);

    function curveHandler() external view returns (address);

    function convexHandler() external view returns (address);

    function setConvexBooster(address _convexBooster) external;

    function setCurveHandler(address _curveHandler) external;

    function setConvexHandler(address _convexHandler) external;

    function setCurveRegistryCache(address curveRegistryCache_) external;

    function setWeightUpdateMinDelay(uint256 delay) external;

    function isPauseManager(address account) external view returns (bool);

    function listPauseManagers() external view returns (address[] memory);

    function setPauseManager(address account, bool isManager) external;

    // deposit/withdrawal whitelist
    function isAllowedMultipleDepositsWithdraws(address poolAddress) external view returns (bool);

    function setAllowedMultipleDepositsWithdraws(address account, bool allowed) external;

    function getMultipleDepositsWithdrawsWhitelist() external view returns (address[] memory);

    // tainted transfer amount
    function setMinimumTaintedTransferAmount(address token, uint256 amount) external;

    function getMinimumTaintedTransferAmount(address token) external view returns (uint256);

    // constants

    function MAX_WEIGHT_UPDATE_MIN_DELAY() external view returns (uint256);

    function MIN_WEIGHT_UPDATE_MIN_DELAY() external view returns (uint256);
}
ICurvePoolV1.sol 84 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

interface ICurvePoolV1 {
    function get_virtual_price() external view returns (uint256);

    function add_liquidity(uint256[8] calldata amounts, uint256 min_mint_amount) external;

    function add_liquidity(uint256[7] calldata amounts, uint256 min_mint_amount) external;

    function add_liquidity(uint256[6] calldata amounts, uint256 min_mint_amount) external;

    function add_liquidity(uint256[5] calldata amounts, uint256 min_mint_amount) external;

    function add_liquidity(uint256[4] calldata amounts, uint256 min_mint_amount) external;

    function add_liquidity(uint256[3] calldata amounts, uint256 min_mint_amount) external;

    function add_liquidity(uint256[2] calldata amounts, uint256 min_mint_amount) external;

    function remove_liquidity_imbalance(
        uint256[4] calldata amounts,
        uint256 max_burn_amount
    ) external;

    function remove_liquidity_imbalance(
        uint256[3] calldata amounts,
        uint256 max_burn_amount
    ) external;

    function remove_liquidity_imbalance(
        uint256[2] calldata amounts,
        uint256 max_burn_amount
    ) external;

    function lp_token() external view returns (address);

    function A_PRECISION() external view returns (uint256);

    function A_precise() external view returns (uint256);

    function remove_liquidity(uint256 _amount, uint256[3] calldata min_amounts) external;

    function exchange(
        int128 from,
        int128 to,
        uint256 _from_amount,
        uint256 _min_to_amount
    ) external;

    function coins(uint256 i) external view returns (address);

    function balances(uint256 i) external view returns (uint256);

    function get_dy(int128 i, int128 j, uint256 _dx) external view returns (uint256);

    function calc_token_amount(
        uint256[4] calldata amounts,
        bool deposit
    ) external view returns (uint256);

    function calc_token_amount(
        uint256[3] calldata amounts,
        bool deposit
    ) external view returns (uint256);

    function calc_token_amount(
        uint256[2] calldata amounts,
        bool deposit
    ) external view returns (uint256);

    function calc_withdraw_one_coin(
        uint256 _token_amount,
        int128 i
    ) external view returns (uint256);

    function remove_liquidity_one_coin(
        uint256 _token_amount,
        int128 i,
        uint256 min_amount
    ) external;

    function fee() external view returns (uint256);
}
ICurvePoolV2.sol 88 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

interface ICurvePoolV2 {
    function token() external view returns (address);

    function coins(uint256 i) external view returns (address);

    function factory() external view returns (address);

    function exchange(
        uint256 i,
        uint256 j,
        uint256 dx,
        uint256 min_dy,
        bool use_eth,
        address receiver
    ) external returns (uint256);

    function exchange_underlying(
        uint256 i,
        uint256 j,
        uint256 dx,
        uint256 min_dy,
        address receiver
    ) external returns (uint256);

    function add_liquidity(
        uint256[2] memory amounts,
        uint256 min_mint_amount,
        bool use_eth,
        address receiver
    ) external returns (uint256);

    function add_liquidity(
        uint256[2] memory amounts,
        uint256 min_mint_amount
    ) external returns (uint256);

    function add_liquidity(
        uint256[3] memory amounts,
        uint256 min_mint_amount,
        bool use_eth,
        address receiver
    ) external returns (uint256);

    function add_liquidity(
        uint256[3] memory amounts,
        uint256 min_mint_amount
    ) external returns (uint256);

    function remove_liquidity(
        uint256 _amount,
        uint256[2] memory min_amounts,
        bool use_eth,
        address receiver
    ) external;

    function remove_liquidity(uint256 _amount, uint256[2] memory min_amounts) external;

    function remove_liquidity(
        uint256 _amount,
        uint256[3] memory min_amounts,
        bool use_eth,
        address receiver
    ) external;

    function remove_liquidity(uint256 _amount, uint256[3] memory min_amounts) external;

    function remove_liquidity_one_coin(
        uint256 token_amount,
        uint256 i,
        uint256 min_amount,
        bool use_eth,
        address receiver
    ) external returns (uint256);

    function get_dy(uint256 i, uint256 j, uint256 dx) external view returns (uint256);

    function calc_token_amount(uint256[] memory amounts) external view returns (uint256);

    function calc_withdraw_one_coin(
        uint256 token_amount,
        uint256 i
    ) external view returns (uint256);

    function get_virtual_price() external view returns (uint256);
}
IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IPoolAdapter.sol 78 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

interface IPoolAdapter {
    /// @notice This is to set which LP token price the value computation should use
    /// `Latest` uses a freshly computed price
    /// `Cached` uses the price in cache
    /// `Minimum` uses the minimum of these two
    enum PriceMode {
        Latest,
        Cached,
        Minimum
    }

    /// @notice Deposit `underlyingAmount` of `underlying` into `pool`
    /// @dev This function should be written with the assumption that it will be delegate-called into
    function deposit(address pool, address underlying, uint256 underlyingAmount) external;

    /// @notice Withdraw `underlyingAmount` of `underlying` from `pool`
    /// @dev This function should be written with the assumption that it will be delegate-called into
    function withdraw(address pool, address underlying, uint256 underlyingAmount) external;

    /// @notice Returns the amount of of assets that `conicPool` holds in `pool`, in terms of USD
    function computePoolValueInUSD(
        address conicPool,
        address pool
    ) external view returns (uint256 usdAmount);

    /// @notice Updates the price caches of the given pools
    function updatePriceCache(address pool) external;

    /// @notice Returns the amount of of assets that `conicPool` holds in `pool`, in terms of USD
    /// using the given price mode
    function computePoolValueInUSD(
        address conicPool,
        address pool,
        PriceMode priceMode
    ) external view returns (uint256 usdAmount);

    /// @notice Returns the amount of of assets that `conicPool` holds in `pool`, in terms of underlying
    function computePoolValueInUnderlying(
        address conicPool,
        address pool,
        address underlying,
        uint256 underlyingPrice
    ) external view returns (uint256 underlyingAmount);

    /// @notice Returns the amount of of assets that `conicPool` holds in `pool`, in terms of underlying
    /// using the given price mode
    function computePoolValueInUnderlying(
        address conicPool,
        address pool,
        address underlying,
        uint256 underlyingPrice,
        PriceMode priceMode
    ) external view returns (uint256 underlyingAmount);

    /// @notice Claim earnings of `conicPool` from `pool`
    function claimEarnings(address conicPool, address pool) external;

    /// @notice Returns the LP token of a given `pool`
    function lpToken(address pool) external view returns (address);

    /// @notice Returns true if `pool` supports `asset`
    function supportsAsset(address pool, address asset) external view returns (bool);

    /// @notice Returns the amount of CRV earned by `pool` on Convex
    function getCRVEarnedOnConvex(
        address account,
        address curvePool
    ) external view returns (uint256);

    /// @notice Executes a sanity check, e.g. checking for reentrancy
    function executeSanityCheck(address pool) external;

    /// @notice returns all the underlying coins of the pool
    function getAllUnderlyingCoins(address pool) external view returns (address[] memory);
}
EnumerableSet.sol 378 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}
IFeeRecipient.sol 8 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

interface IFeeRecipient {
    event FeesReceived(address indexed sender, uint256 crvAmount, uint256 cvxAmount);

    function receiveFees(uint256 amountCrv, uint256 amountCvx) external;
}
Initializable.sol 166 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "Address.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}
RewardManager.sol 536 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "Ownable.sol";
import "Initializable.sol";
import "EnumerableSet.sol";
import "SafeERC20.sol";
import "IERC20Metadata.sol";

import "IConicPool.sol";
import "ILpToken.sol";
import "IRewardManager.sol";
import "IConvexHandler.sol";
import "IController.sol";
import "IOracle.sol";
import "IInflationManager.sol";
import "ILpTokenStaker.sol";
import "ICurvePoolV2.sol";
import "UniswapRouter02.sol";

import "ScaledMath.sol";
import "Types.sol";

contract RewardManager is IRewardManager, Ownable, Initializable {
    using ScaledMath for uint256;
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    struct RewardMeta {
        uint256 earnedIntegral;
        uint256 lastHoldings;
        mapping(address => uint256) accountIntegral;
        mapping(address => uint256) accountShare;
    }

    IERC20 public constant CVX = IERC20(0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B);
    IERC20 public constant CRV = IERC20(0xD533a949740bb3306d119CC777fa900bA034cd52);
    IERC20 public constant WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
    IERC20 public constant CNC = IERC20(0x9aE380F0272E2162340a5bB646c354271c0F5cFC);
    UniswapRouter02 public constant SUSHISWAP =
        UniswapRouter02(0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F);
    ICurvePoolV2 public constant CNC_ETH_POOL =
        ICurvePoolV2(0x838af967537350D2C44ABB8c010E49E32673ab94);

    uint256 public constant MAX_FEE_PERCENTAGE = 3e17;
    uint256 public constant SLIPPAGE_THRESHOLD = 0.95e18; // 5% slippage as a multiplier

    bytes32 internal constant _CNC_KEY = "cnc";
    bytes32 internal constant _CRV_KEY = "crv";
    bytes32 internal constant _CVX_KEY = "cvx";

    address public override conicPool;
    IERC20 public immutable underlying;
    IController public immutable controller;
    bool internal _claimingCNC;

    EnumerableSet.AddressSet internal _extraRewards;
    mapping(address => address) public extraRewardsCurvePool;
    mapping(bytes32 => RewardMeta) internal _rewardsMeta;
    mapping(uint256 => bool) internal _claimedForCliff;

    bool public feesEnabled;
    uint256 public feePercentage;

    constructor(address _controller, address _underlying) {
        underlying = IERC20(_underlying);
        controller = IController(_controller);
        WETH.safeApprove(address(CNC_ETH_POOL), type(uint256).max);
    }

    function initialize(address _pool) external onlyOwner initializer {
        conicPool = _pool;
    }

    /// @notice Updates the internal fee accounting state. Returns `true` if rewards were claimed
    function poolCheckpoint() public override returns (bool) {
        IConvexHandler convexHandler = IConvexHandler(controller.convexHandler());

        (
            uint256 crvHoldings,
            uint256 cvxHoldings,
            uint256 cncHoldings,
            Types.CliffInfo memory cliffInfo
        ) = _getHoldingsWithCliffInfo(convexHandler);

        // if we are in the threshold near a cliff for the first time claim rewards
        if (cliffInfo.withinThreshold && !_claimedForCliff[cliffInfo.currentCliff]) {
            _claimPoolEarningsForCliff(cliffInfo.currentCliff);
        }

        uint256 crvEarned = crvHoldings - _rewardsMeta[_CRV_KEY].lastHoldings;
        uint256 cvxEarned;
        if (cvxHoldings > _rewardsMeta[_CVX_KEY].lastHoldings) {
            cvxEarned = cvxHoldings - _rewardsMeta[_CVX_KEY].lastHoldings;
        }
        uint256 cncEarned = cncHoldings - _rewardsMeta[_CNC_KEY].lastHoldings;

        uint256 crvFee;
        uint256 cvxFee;

        if (feesEnabled) {
            crvFee = crvEarned.mulDown(feePercentage);
            cvxFee = cvxEarned.mulDown(feePercentage);
            crvEarned -= crvFee;
            cvxEarned -= cvxFee;
            crvHoldings -= crvFee;
            cvxHoldings -= cvxFee;
        }

        uint256 _totalStaked = controller.lpTokenStaker().getBalanceForPool(conicPool);
        if (_totalStaked > 0) {
            _updateEarned(_CVX_KEY, cvxHoldings, cvxEarned, _totalStaked);
            _updateEarned(_CRV_KEY, crvHoldings, crvEarned, _totalStaked);
            _updateEarned(_CNC_KEY, cncHoldings, cncEarned, _totalStaked);
        }

        if (!feesEnabled) {
            return false;
        }

        bool rewardsClaimed = false;

        if (crvFee > CRV.balanceOf(conicPool) || cvxFee > CVX.balanceOf(conicPool)) {
            _claimPoolEarningsAndSellRewardTokens();
            rewardsClaimed = true;
        }

        CRV.safeTransferFrom(conicPool, address(this), crvFee);
        CVX.safeTransferFrom(conicPool, address(this), cvxFee);

        // Fee transfer to the fee recipient
        IFeeRecipient _feeRecipient = controller.feeRecipient();
        CRV.forceApprove(address(_feeRecipient), crvFee);
        CVX.forceApprove(address(_feeRecipient), cvxFee);
        _feeRecipient.receiveFees(crvFee, cvxFee);

        return rewardsClaimed;
    }

    function _updateEarned(
        bytes32 key,
        uint256 holdings,
        uint256 earned,
        uint256 _totalSupply
    ) internal {
        _rewardsMeta[key].earnedIntegral += earned.divDown(_totalSupply);
        _rewardsMeta[key].lastHoldings = holdings;
    }

    function _getEarnedRewards()
        internal
        view
        returns (uint256 crvEarned, uint256 cvxEarned, uint256 cncEarned)
    {
        IConvexHandler convexHandler = IConvexHandler(controller.convexHandler());
        return _getEarnedRewards(convexHandler);
    }

    function _getHoldingsWithCliffInfo(
        IConvexHandler convexHandler
    )
        internal
        view
        returns (
            uint256 crvHoldings,
            uint256 cvxHoldings,
            uint256 cncHoldings,
            Types.CliffInfo memory cliffInfo
        )
    {
        address[] memory curvePools = IConicPool(conicPool).allPools();

        uint256 claimableCRV;
        for (uint256 i; i < curvePools.length; i++) {
            claimableCRV += controller.poolAdapterFor(curvePools[i]).getCRVEarnedOnConvex(
                conicPool,
                curvePools[i]
            );
        }

        crvHoldings = CRV.balanceOf(conicPool) + claimableCRV;

        uint256 claimableCVX;
        (claimableCVX, cliffInfo) = convexHandler.computeClaimableConvexWithCliffInfo(claimableCRV);
        cvxHoldings = CVX.balanceOf(conicPool) + claimableCVX;
        cncHoldings = CNC.balanceOf(conicPool);
        if (!_claimingCNC) {
            cncHoldings += controller.lpTokenStaker().claimableCnc(conicPool);
        }
    }

    function _getHoldings(
        IConvexHandler convexHandler
    ) internal view returns (uint256 crvHoldings, uint256 cvxHoldings, uint256 cncHoldings) {
        (crvHoldings, cvxHoldings, cncHoldings, ) = _getHoldingsWithCliffInfo(convexHandler);
    }

    function _getEarnedRewards(
        IConvexHandler convexHandler
    ) internal view returns (uint256 crvEarned, uint256 cvxEarned, uint256 cncEarned) {
        (
            uint256 currentHoldingsCRV,
            uint256 currentHoldingsCVX,
            uint256 currentHoldingsCNC
        ) = _getHoldings(convexHandler);

        crvEarned = currentHoldingsCRV - _rewardsMeta[_CRV_KEY].lastHoldings;
        cvxEarned = currentHoldingsCVX - _rewardsMeta[_CVX_KEY].lastHoldings;
        cncEarned = currentHoldingsCNC - _rewardsMeta[_CNC_KEY].lastHoldings;
    }

    function accountCheckpoint(address account) external {
        _accountCheckpoint(account);
    }

    function _accountCheckpoint(address account) internal {
        uint256 accountBalance = controller.lpTokenStaker().getUserBalanceForPool(
            conicPool,
            account
        );
        poolCheckpoint();
        _updateAccountRewardsMeta(_CNC_KEY, account, accountBalance);
        _updateAccountRewardsMeta(_CRV_KEY, account, accountBalance);
        _updateAccountRewardsMeta(_CVX_KEY, account, accountBalance);
    }

    function _updateAccountRewardsMeta(bytes32 key, address account, uint256 balance) internal {
        RewardMeta storage meta = _rewardsMeta[key];
        uint256 share = balance.mulDown(meta.earnedIntegral - meta.accountIntegral[account]);
        meta.accountShare[account] += share;
        meta.accountIntegral[account] = meta.earnedIntegral;
    }

    /// @notice Claims all CRV, CVX and CNC earned by a user. All extra reward
    /// tokens earned will be sold for CNC.
    /// @dev Conic pool LP tokens need to be staked in the `LpTokenStaker` in
    /// order to receive a share of the CRV, CVX and CNC earnings.
    /// after selling all extra reward tokens.
    function claimEarnings() public override returns (uint256, uint256, uint256) {
        _accountCheckpoint(msg.sender);
        uint256 crvAmount = _rewardsMeta[_CRV_KEY].accountShare[msg.sender];
        uint256 cvxAmount = _rewardsMeta[_CVX_KEY].accountShare[msg.sender];
        uint256 cncAmount = _rewardsMeta[_CNC_KEY].accountShare[msg.sender];
        if (
            crvAmount > CRV.balanceOf(conicPool) ||
            cvxAmount > CVX.balanceOf(conicPool) ||
            cncAmount > CNC.balanceOf(conicPool)
        ) {
            _claimPoolEarningsAndSellRewardTokens();
            if (_extraRewards.length() > 0) {
                // if we sold some rewards for CNC, we need to update the account checkpoint
                _accountCheckpoint(msg.sender);
                cncAmount = _rewardsMeta[_CNC_KEY].accountShare[msg.sender];
            }
        }

        _rewardsMeta[_CNC_KEY].accountShare[msg.sender] = 0;
        _rewardsMeta[_CVX_KEY].accountShare[msg.sender] = 0;
        _rewardsMeta[_CRV_KEY].accountShare[msg.sender] = 0;

        CRV.safeTransferFrom(conicPool, msg.sender, crvAmount);
        CVX.safeTransferFrom(conicPool, msg.sender, cvxAmount);
        if (CNC.balanceOf(conicPool) >= cncAmount) {
            CNC.safeTransferFrom(conicPool, msg.sender, cncAmount);
        }

        (
            uint256 currentHoldingsCRV,
            uint256 currentHoldingsCVX,
            uint256 currentHoldingsCNC
        ) = _getHoldings(IConvexHandler(controller.convexHandler()));
        _rewardsMeta[_CRV_KEY].lastHoldings = currentHoldingsCRV;
        _rewardsMeta[_CVX_KEY].lastHoldings = currentHoldingsCVX;
        _rewardsMeta[_CNC_KEY].lastHoldings = currentHoldingsCNC;

        emit EarningsClaimed(msg.sender, cncAmount, crvAmount, cvxAmount);
        return (cncAmount, crvAmount, cvxAmount);
    }

    /// @notice Claims all claimable CVX and CRV from Convex for all staked Curve LP tokens.
    /// Then Swaps all additional rewards tokens for CNC.
    function claimPoolEarningsAndSellRewardTokens() external override {
        if (!poolCheckpoint()) {
            _claimPoolEarningsAndSellRewardTokens();
        }
    }

    function _claimPoolEarningsForCliff(uint256 cliff) internal {
        _claimPoolEarningsAndSellRewardTokens();
        _claimedForCliff[cliff] = true;
    }

    function _claimPoolEarningsAndSellRewardTokens() internal {
        _claimPoolEarnings();

        uint256 cncBalanceBefore_ = CNC.balanceOf(conicPool);

        _sellRewardTokens();

        uint256 receivedCnc_ = CNC.balanceOf(conicPool) - cncBalanceBefore_;
        uint256 _totalStaked = controller.lpTokenStaker().getBalanceForPool(conicPool);
        if (_totalStaked > 0 && receivedCnc_ > 0) {
            _rewardsMeta[_CNC_KEY].earnedIntegral += receivedCnc_.divDown(_totalStaked);
            _rewardsMeta[_CNC_KEY].lastHoldings += receivedCnc_;
            emit SoldRewardTokens(receivedCnc_);
        }
    }

    /// @notice Claims all claimable CVX and CRV from Convex for all staked Curve LP tokens
    function _claimPoolEarnings() internal {
        _claimingCNC = true;
        controller.lpTokenStaker().claimCNCRewardsForPool(conicPool);
        _claimingCNC = false;

        uint256 cvxBalance = CVX.balanceOf(conicPool);
        uint256 crvBalance = CRV.balanceOf(conicPool);

        address[] memory pools = IConicPool(conicPool).allPools();
        for (uint256 i; i < pools.length; i++) {
            controller.poolAdapterFor(pools[i]).claimEarnings(conicPool, pools[i]);
        }

        uint256 claimedCvx = CVX.balanceOf(conicPool) - cvxBalance;
        uint256 claimedCrv = CRV.balanceOf(conicPool) - crvBalance;

        emit ClaimedRewards(claimedCrv, claimedCvx);
    }

    /// @notice Swaps all additional rewards tokens for CNC.
    function _sellRewardTokens() internal {
        uint256 extraRewardsLength_ = _extraRewards.length();
        if (extraRewardsLength_ == 0) return;
        for (uint256 i; i < extraRewardsLength_; i++) {
            IERC20(_extraRewards.at(i)).safeTransferFrom(
                conicPool,
                address(this),
                IERC20(_extraRewards.at(i)).balanceOf(conicPool)
            );
            _swapRewardTokenForWeth(_extraRewards.at(i));
        }
        _swapWethForCNC();
    }

    function listExtraRewards() external view returns (address[] memory) {
        return _extraRewards.values();
    }

    function addExtraReward(address reward) public override onlyOwner returns (bool) {
        require(reward != address(0), "invalid address");
        require(!_extraRewards.contains(reward), "already added");
        require(
            reward != address(CVX) &&
                reward != address(CRV) &&
                reward != address(underlying) &&
                reward != address(CNC),
            "token not allowed"
        );

        // Checking reward token isn't a Curve Pool LP Token
        address[] memory pools = IConicPool(conicPool).allPools();
        for (uint256 i; i < pools.length; i++) {
            address curveLpToken_ = controller.poolAdapterFor(pools[i]).lpToken(pools[i]);
            require(reward != curveLpToken_, "token not allowed");
        }

        IConicPool(conicPool).updateRewardSpendingApproval(reward, true);
        IERC20(reward).safeApprove(address(SUSHISWAP), 0);
        IERC20(reward).safeApprove(address(SUSHISWAP), type(uint256).max);
        emit ExtraRewardAdded(reward);
        return _extraRewards.add(reward);
    }

    function addBatchExtraRewards(address[] memory _rewards) external override onlyOwner {
        for (uint256 i; i < _rewards.length; i++) {
            addExtraReward(_rewards[i]);
        }
    }

    function removeExtraReward(address tokenAddress) external onlyOwner {
        require(_extraRewards.contains(tokenAddress), "not added");
        _extraRewards.remove(tokenAddress);
        IConicPool(conicPool).updateRewardSpendingApproval(tokenAddress, false);
        emit ExtraRewardRemoved(tokenAddress);
    }

    function setExtraRewardsCurvePool(address extraReward_, address curvePool_) external onlyOwner {
        require(curvePool_ != extraRewardsCurvePool[extraReward_], "must be different to current");
        if (curvePool_ != address(0)) {
            IERC20(extraReward_).safeApprove(curvePool_, 0);
            IERC20(extraReward_).safeApprove(curvePool_, type(uint256).max);
        }
        extraRewardsCurvePool[extraReward_] = curvePool_;
        emit ExtraRewardsCurvePoolSet(extraReward_, curvePool_);
    }

    function setFeePercentage(uint256 _feePercentage) external override onlyOwner {
        require(_feePercentage < MAX_FEE_PERCENTAGE, "cannot set fee percentage to more than 30%");
        require(_feePercentage != feePercentage, "must be different to current");
        require(address(controller.feeRecipient()) != address(0), "fee recipient not set");
        feePercentage = _feePercentage;
        feesEnabled = _feePercentage > 0;
        emit FeesSet(feePercentage);
    }

    function claimableRewards(
        address account
    ) external view returns (uint256 cncRewards, uint256 crvRewards, uint256 cvxRewards) {
        uint256 _totalStaked = controller.lpTokenStaker().getBalanceForPool(conicPool);
        (uint256 crvEarned, uint256 cvxEarned, uint256 cncEarned) = _getEarnedRewards();
        uint256 userBalance = controller.lpTokenStaker().getUserBalanceForPool(conicPool, account);

        cncRewards = _getClaimableReward(
            account,
            _CNC_KEY,
            cncEarned,
            userBalance,
            _totalStaked,
            false
        );
        crvRewards = _getClaimableReward(
            account,
            _CRV_KEY,
            crvEarned,
            userBalance,
            _totalStaked,
            feesEnabled
        );
        cvxRewards = _getClaimableReward(
            account,
            _CVX_KEY,
            cvxEarned,
            userBalance,
            _totalStaked,
            feesEnabled
        );
    }

    function _getClaimableReward(
        address account,
        bytes32 key,
        uint256 earned,
        uint256 userBalance,
        uint256 _totalSupply,
        bool deductFee
    ) internal view returns (uint256) {
        RewardMeta storage meta = _rewardsMeta[key];
        uint256 integral = meta.earnedIntegral;
        if (_totalSupply > 0) {
            if (deductFee) {
                integral += earned.mulDown(ScaledMath.ONE - feePercentage).divDown(_totalSupply);
            } else {
                integral += earned.divDown(_totalSupply);
            }
        }
        return
            meta.accountShare[account] +
            userBalance.mulDown(integral - meta.accountIntegral[account]);
    }

    function _swapRewardTokenForWeth(address rewardToken_) internal {
        uint256 tokenBalance_ = IERC20(rewardToken_).balanceOf(address(this));
        if (tokenBalance_ == 0) return;

        ICurvePoolV2 curvePool_ = ICurvePoolV2(extraRewardsCurvePool[rewardToken_]);
        if (address(curvePool_) != address(0)) {
            (int128 i, int128 j, ) = controller.curveRegistryCache().coinIndices(
                address(curvePool_),
                rewardToken_,
                address(WETH)
            );
            (uint256 from_, uint256 to_) = (uint256(uint128(i)), uint256(uint128(j)));
            curvePool_.exchange(
                from_,
                to_,
                tokenBalance_,
                _minAmountOut(address(rewardToken_), address(WETH), tokenBalance_),
                false,
                address(this)
            );
            return;
        }

        address[] memory path_ = new address[](2);
        path_[0] = rewardToken_;
        path_[1] = address(WETH);
        SUSHISWAP.swapExactTokensForTokens(
            tokenBalance_,
            _minAmountOut(address(rewardToken_), address(WETH), tokenBalance_),
            path_,
            address(this),
            block.timestamp
        );
    }

    function _swapWethForCNC() internal {
        uint256 wethBalance_ = WETH.balanceOf(address(this));
        if (wethBalance_ == 0) return;
        CNC_ETH_POOL.exchange(
            0,
            1,
            wethBalance_,
            _minAmountOut(address(WETH), address(CNC), wethBalance_),
            false,
            conicPool
        );
    }

    function _minAmountOut(
        address tokenIn_,
        address tokenOut_,
        uint256 amountIn_
    ) internal view returns (uint256) {
        IOracle oracle_ = controller.priceOracle();

        if (tokenIn_ == tokenOut_) {
            return amountIn_;
        }

        // If we don't have a price for either token, we can't calculate the min amount out
        // This should only ever happen for very minor tokens, so we accept the risk of not having
        // slippage protection in that case
        if (!oracle_.isTokenSupported(tokenIn_) || !oracle_.isTokenSupported(tokenOut_)) {
            return 0;
        }

        return
            amountIn_
                .mulDown(oracle_.getUSDPrice(tokenIn_))
                .divDown(oracle_.getUSDPrice(tokenOut_))
                .convertScale(
                    IERC20Metadata(tokenIn_).decimals(),
                    IERC20Metadata(tokenOut_).decimals()
                )
                .mulDown(SLIPPAGE_THRESHOLD);
    }
}
CurvePoolUtils.sol 93 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "ICurvePoolV2.sol";
import "ICurvePoolV1.sol";
import "ScaledMath.sol";

library CurvePoolUtils {
    using ScaledMath for uint256;

    error NotWithinThreshold(address pool, uint256 assetA, uint256 assetB);

    /// @dev by default, allow for 30 bps deviation regardless of pool fees
    uint256 internal constant _DEFAULT_IMBALANCE_BUFFER = 30e14;

    /// @dev Curve scales the `fee` by 1e10
    uint8 internal constant _CURVE_POOL_FEE_DECIMALS = 10;

    /// @dev allow imbalance to be buffer + 3x the fee, e.g. if fee is 3.6 bps and buffer is 30 bps, allow 40.8 bps
    uint256 internal constant _FEE_IMBALANCE_MULTIPLIER = 3;

    enum AssetType {
        USD,
        ETH,
        BTC,
        OTHER,
        CRYPTO
    }

    struct PoolMeta {
        address pool;
        uint256 numberOfCoins;
        AssetType assetType;
        uint256[] decimals;
        uint256[] prices;
        uint256[] imbalanceBuffers;
    }

    function ensurePoolBalanced(PoolMeta memory poolMeta) internal view {
        uint256 poolFee = ICurvePoolV1(poolMeta.pool).fee().convertScale(
            _CURVE_POOL_FEE_DECIMALS,
            18
        );

        for (uint256 i = 0; i < poolMeta.numberOfCoins - 1; i++) {
            uint256 fromDecimals = poolMeta.decimals[i];
            uint256 fromBalance = 10 ** fromDecimals;
            uint256 fromPrice = poolMeta.prices[i];

            for (uint256 j = i + 1; j < poolMeta.numberOfCoins; j++) {
                uint256 toDecimals = poolMeta.decimals[j];
                uint256 toPrice = poolMeta.prices[j];
                uint256 toExpectedUnscaled = (fromBalance * fromPrice) / toPrice;
                uint256 toExpected = toExpectedUnscaled.convertScale(
                    uint8(fromDecimals),
                    uint8(toDecimals)
                );

                uint256 toActual;

                if (poolMeta.assetType == AssetType.CRYPTO) {
                    // Handling crypto pools
                    toActual = ICurvePoolV2(poolMeta.pool).get_dy(i, j, fromBalance);
                } else {
                    // Handling other pools
                    toActual = ICurvePoolV1(poolMeta.pool).get_dy(
                        int128(uint128(i)),
                        int128(uint128(j)),
                        fromBalance
                    );
                }
                uint256 _maxImbalanceBuffer = poolMeta.imbalanceBuffers[i].max(
                    poolMeta.imbalanceBuffers[j]
                );

                if (!_isWithinThreshold(toExpected, toActual, poolFee, _maxImbalanceBuffer))
                    revert NotWithinThreshold(poolMeta.pool, i, j);
            }
        }
    }

    function _isWithinThreshold(
        uint256 a,
        uint256 b,
        uint256 poolFee,
        uint256 imbalanceBuffer
    ) internal pure returns (bool) {
        if (imbalanceBuffer == 0) imbalanceBuffer = _DEFAULT_IMBALANCE_BUFFER;
        uint256 imbalanceTreshold = imbalanceBuffer + poolFee * _FEE_IMBALANCE_MULTIPLIER;
        if (a > b) return (a - b).divDown(a) <= imbalanceTreshold;
        return (b - a).divDown(b) <= imbalanceTreshold;
    }
}
IConvexHandler.sol 25 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "Types.sol";

interface IConvexHandler {
    function deposit(address _curvePool, uint256 _amount) external;

    function claimEarnings(address _curvePool, address _conicPool) external;

    function getRewardPool(address _curvePool) external view returns (address);

    function getCrvEarned(address _account, address _curvePool) external view returns (uint256);

    function getCrvEarnedBatch(
        address _account,
        address[] memory _curvePools
    ) external view returns (uint256);

    function computeClaimableConvex(uint256 crvAmount) external view returns (uint256);

    function computeClaimableConvexWithCliffInfo(
        uint256 crvAmount
    ) external view returns (uint256, Types.CliffInfo memory);
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
IGenericOracle.sol 31 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "IOracle.sol";

interface IGenericOracle is IOracle {
    /// @notice returns the oracle to be used to price `token`
    function getOracle(address token) external view returns (IOracle);

    /// @notice converts the price of an LP token to the given underlying
    function curveLpToUnderlying(
        address curveLpToken,
        address underlying,
        uint256 curveLpAmount
    ) external view returns (uint256);

    /// @notice same as above but avoids fetching the underlying price again
    function curveLpToUnderlying(
        address curveLpToken,
        address underlying,
        uint256 curveLpAmount,
        uint256 underlyingPrice
    ) external view returns (uint256);

    /// @notice converts the price an underlying asset to a given Curve LP token
    function underlyingToCurveLp(
        address underlying,
        address curveLpToken,
        uint256 underlyingAmount
    ) external view returns (uint256);
}
ILpTokenStaker.sol 40 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

interface ILpTokenStaker {
    event LpTokenStaked(address indexed account, uint256 amount);
    event LpTokenUnstaked(address indexed account, uint256 amount);
    event TokensClaimed(address indexed pool, uint256 cncAmount);
    event Shutdown();

    function stake(uint256 amount, address conicPool) external;

    function unstake(uint256 amount, address conicPool) external;

    function stakeFor(uint256 amount, address conicPool, address account) external;

    function unstakeFor(uint256 amount, address conicPool, address account) external;

    function unstakeFrom(uint256 amount, address account) external;

    function getUserBalanceForPool(
        address conicPool,
        address account
    ) external view returns (uint256);

    function getBalanceForPool(address conicPool) external view returns (uint256);

    function updateBoost(address user) external;

    function claimCNCRewardsForPool(address pool) external;

    function claimableCnc(address pool) external view returns (uint256);

    function checkpoint(address pool) external returns (uint256);

    function shutdown() external;

    function getBoost(address user) external view returns (uint256);

    function isShutdown() external view returns (bool);
}
IRewardManager.sol 42 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

interface IRewardManager {
    event ClaimedRewards(uint256 claimedCrv, uint256 claimedCvx);
    event SoldRewardTokens(uint256 targetTokenReceived);
    event ExtraRewardAdded(address reward);
    event ExtraRewardRemoved(address reward);
    event ExtraRewardsCurvePoolSet(address extraReward, address curvePool);
    event FeesSet(uint256 feePercentage);
    event FeesEnabled(uint256 feePercentage);
    event EarningsClaimed(
        address indexed claimedBy,
        uint256 cncEarned,
        uint256 crvEarned,
        uint256 cvxEarned
    );

    function accountCheckpoint(address account) external;

    function poolCheckpoint() external returns (bool);

    function addExtraReward(address reward) external returns (bool);

    function addBatchExtraRewards(address[] memory rewards) external;

    function conicPool() external view returns (address);

    function setFeePercentage(uint256 _feePercentage) external;

    function claimableRewards(
        address account
    ) external view returns (uint256 cncRewards, uint256 crvRewards, uint256 cvxRewards);

    function claimEarnings() external returns (uint256, uint256, uint256);

    function claimPoolEarningsAndSellRewardTokens() external;

    function feePercentage() external view returns (uint256);

    function feesEnabled() external view returns (bool);
}
UniswapRouter02.sol 76 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

interface UniswapRouter02 {
    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function getAmountIn(
        uint256 amountOut,
        uint256 reserveIn,
        uint256 reserveOut
    ) external returns (uint256 amountIn);

    function getAmountOut(
        uint256 amountIn,
        uint256 reserveIn,
        uint256 reserveOut
    ) external view returns (uint256 amountOut);

    function getAmountsIn(
        uint256 amountOut,
        address[] calldata path
    ) external view returns (uint256[] memory amounts);

    function getAmountsOut(
        uint256 amountIn,
        address[] memory path
    ) external view returns (uint256[] memory amounts);

    function getReserves(
        address factory,
        address tokenA,
        address tokenB
    ) external view returns (uint256 reserveA, uint256 reserveB);

    function WETH() external pure returns (address);
}

interface UniswapV2Pair {
    function getReserves()
        external
        view
        returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast);
}

interface UniswapV2Factory {
    function getPair(address tokenA, address tokenB) external view returns (address pair);
}
IInflationManager.sol 53 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

interface IInflationManager {
    event TokensClaimed(address indexed pool, uint256 cncAmount);
    event RebalancingRewardHandlerAdded(address indexed pool, address indexed handler);
    event RebalancingRewardHandlerRemoved(address indexed pool, address indexed handler);
    event PoolWeightsUpdated();

    function executeInflationRateUpdate() external;

    function updatePoolWeights() external;

    /// @notice returns the weights of the Conic pools to know how much inflation
    /// each of them will receive, as well as the total amount of USD value in all the pools
    function computePoolWeights()
        external
        view
        returns (address[] memory _pools, uint256[] memory poolWeights, uint256 totalUSDValue);

    function computePoolWeight(
        address pool
    ) external view returns (uint256 poolWeight, uint256 totalUSDValue);

    function currentInflationRate() external view returns (uint256);

    function getCurrentPoolInflationRate(address pool) external view returns (uint256);

    function handleRebalancingRewards(
        address account,
        uint256 deviationBefore,
        uint256 deviationAfter
    ) external;

    function addPoolRebalancingRewardHandler(
        address poolAddress,
        address rebalancingRewardHandler
    ) external;

    function removePoolRebalancingRewardHandler(
        address poolAddress,
        address rebalancingRewardHandler
    ) external;

    function rebalancingRewardHandlers(
        address poolAddress
    ) external view returns (address[] memory);

    function hasPoolRebalancingRewardHandler(
        address poolAddress,
        address handler
    ) external view returns (bool);
}
ICurveRegistryCache.sol 57 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "IBooster.sol";
import "CurvePoolUtils.sol";

interface ICurveRegistryCache {
    event PoolInitialized(address indexed pool, uint256 indexed pid);

    function BOOSTER() external view returns (IBooster);

    function initPool(address pool_) external;

    function initPool(address pool_, uint256 pid_) external;

    function lpToken(address pool_) external view returns (address);

    function assetType(address pool_) external view returns (CurvePoolUtils.AssetType);

    function isRegistered(address pool_) external view returns (bool);

    function hasCoinDirectly(address pool_, address coin_) external view returns (bool);

    function hasCoinAnywhere(address pool_, address coin_) external view returns (bool);

    function basePool(address pool_) external view returns (address);

    function coinIndex(address pool_, address coin_) external view returns (int128);

    function nCoins(address pool_) external view returns (uint256);

    function coinIndices(
        address pool_,
        address from_,
        address to_
    ) external view returns (int128, int128, bool);

    function decimals(address pool_) external view returns (uint256[] memory);

    function interfaceVersion(address pool_) external view returns (uint256);

    function poolFromLpToken(address lpToken_) external view returns (address);

    function coins(address pool_) external view returns (address[] memory);

    function getPid(address _pool) external view returns (uint256);

    function getRewardPool(address _pool) external view returns (address);

    function isShutdownPid(uint256 pid_) external view returns (bool);

    /// @notice this returns the underlying coins of a pool, including the underlying of the base pool
    /// if the given pool is a meta pool
    /// This does not return the LP token of the base pool as an underlying
    /// e.g. if the pool is 3CrvFrax, this will return FRAX, DAI, USDC, USDT
    function getAllUnderlyingCoins(address pool) external view returns (address[] memory);
}
IConicPoolWeightManagement.sol 31 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

interface IConicPoolWeightManagement {
    struct PoolWeight {
        address poolAddress;
        uint256 weight;
    }

    function addPool(address pool) external;

    function removePool(address pool) external;

    function updateWeights(PoolWeight[] memory poolWeights) external;

    function handleDepeggedCurvePool(address curvePool_) external;

    function handleInvalidConvexPid(address pool) external returns (uint256);

    function allPools() external view returns (address[] memory);

    function poolsCount() external view returns (uint256);

    function getPoolAtIndex(uint256 _index) external view returns (address);

    function getWeight(address curvePool) external view returns (uint256);

    function getWeights() external view returns (PoolWeight[] memory);

    function isRegisteredPool(address _pool) external view returns (bool);
}

Read Contract

CNC 0x632473da → address
CNC_ETH_POOL 0x49556709 → address
CRV 0x945c9142 → address
CVX 0x759cb53b → address
MAX_FEE_PERCENTAGE 0x558e44d3 → uint256
SLIPPAGE_THRESHOLD 0xe8465009 → uint256
SUSHISWAP 0x9c708aab → address
WETH 0xad5c4648 → address
claimableRewards 0xdc01f60d → uint256, uint256, uint256
conicPool 0x7d59ce01 → address
controller 0xf77c4791 → address
extraRewardsCurvePool 0xd9e65ced → address
feePercentage 0xa001ecdd → uint256
feesEnabled 0xa64e4f8a → bool
listExtraRewards 0x6dc47e1e → address[]
owner 0x8da5cb5b → address
underlying 0x6f307dc3 → address

Write Contract 12 functions

These functions modify contract state and require a wallet transaction to execute.

accountCheckpoint 0xbf928f8b
address account
addBatchExtraRewards 0xfe09d54d
address[] _rewards
addExtraReward 0x5e43c47b
address reward
returns: bool
claimEarnings 0xd9ceab13
No parameters
returns: uint256, uint256, uint256
claimPoolEarningsAndSellRewardTokens 0xe7706183
No parameters
initialize 0xc4d66de8
address _pool
poolCheckpoint 0x5790a0c8
No parameters
returns: bool
removeExtraReward 0xa80ff90a
address tokenAddress
renounceOwnership 0x715018a6
No parameters
setExtraRewardsCurvePool 0x03950fb5
address extraReward_
address curvePool_
setFeePercentage 0xae06c1b7
uint256 _feePercentage
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

No transactions found for this address