Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x846744fE57BF28A8D32818C2Df67Ce5a83b2aB9f
Balance 0 ETH
Nonce 1
Code Size 15184 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

15184 bytes
0x608060405234801561001057600080fd5b50600436106102775760003560e01c806374ec29a011610160578063a7e7344a116100d8578063da528f3e1161008c578063f2fde38b11610071578063f2fde38b1461079c578063f3bd53bf146107af578063fc5e231e146107d057600080fd5b8063da528f3e1461075d578063dcf6de811461077c57600080fd5b8063be5013dc116100bd578063be5013dc14610678578063c81eec661461068b578063caf3791e1461075457600080fd5b8063a7e7344a14610650578063a8a9bbfd1461066557600080fd5b8063864683d41161012f5780638da5cb5b116101145780638da5cb5b1461060c5780639cfc7e831461062c5780639d01a27d1461063d57600080fd5b8063864683d4146105e65780638a1e6bba146105f957600080fd5b806374ec29a01461056c57806382bc4aaf1461057f57806382bfefc8146105925780638456cb59146105de57600080fd5b80632f37a774116101f357806357593651116101c25780635c975abb116101a75780635c975abb146105235780636d218e481461054657806370feb52a1461055957600080fd5b806357593651146104e057806359974e381461051057600080fd5b80632f37a774146104aa57806335c1dd99146104b25780633f4ba83a146104c55780634617c06a146104cd57600080fd5b80630f2d940b1161024a5780631563461b1161022f5780631563461b1461035b578063163db71b146103705780632274c5cd1461037857600080fd5b80630f2d940b146103025780630fc1bf681461033b57600080fd5b806302aa63181461027c57806304585ac71461029a578063059527bf146102ba57806306fdde03146102ed575b600080fd5b6102846107d8565b6040516102919190612f6d565b60405180910390f35b6102ad6102a8366004613003565b6108ae565b604051610291919061301c565b6102dd6102c836600461308f565b600e6020526000908152604090205460ff1681565b6040519015158152602001610291565b6102f56109b8565b6040516102919190613118565b61032d61031036600461312b565b600b60209081526000928352604080842090915290825290205481565b604051908152602001610291565b600f546102dd906f01000000000000000000000000000000900460ff1681565b61036e610369366004613166565b610a46565b005b600d5461032d565b6104416040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810191909152506040805160e0810182526007548152600854602082015260095464ffffffffff80821693830193909352650100000000008104831660608301526a01000000000000000000008104831660808301526f010000000000000000000000000000008104831660a083015274010000000000000000000000000000000000000000900490911660c082015290565b6040516102919190600060e0820190508251825260208301516020830152604083015164ffffffffff80821660408501528060608601511660608501528060808601511660808501528060a08601511660a08501528060c08601511660c0850152505092915050565b6102dd610baa565b61036e6104c03660046131b2565b610bd6565b61036e610ec9565b61036e6104db3660046131b2565b610f54565b600f546104fa9065010000000000900464ffffffffff1681565b60405164ffffffffff9091168152602001610291565b61036e61051e366004613003565b6111c5565b60005474010000000000000000000000000000000000000000900460ff166102dd565b6102dd61055436600461308f565b611892565b61036e61056736600461308f565b6118e6565b6102dd61057a36600461308f565b611a45565b61036e61058d3660046133c9565b611a96565b6105b97f0000000000000000000000006f40d4a6237c257fff2db00fa0510deeecd303eb81565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610291565b61036e611b77565b61036e6105f4366004613489565b611c00565b61036e6106073660046134f0565b611d46565b6000546105b99073ffffffffffffffffffffffffffffffffffffffff1681565b600f546104fa9064ffffffffff1681565b61036e61064b366004613166565b611ee3565b610658612039565b6040516102919190613532565b61036e6106733660046135b0565b6120e7565b61036e610686366004613606565b61229d565b6104416040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810191909152506040805160e0810182526004548152600554602082015260065464ffffffffff80821693830193909352650100000000008104831660608301526a01000000000000000000008104831660808301526f010000000000000000000000000000008104831660a083015274010000000000000000000000000000000000000000900490911660c082015290565b61032d600a5481565b600f546104fa906a0100000000000000000000900464ffffffffff1681565b61078f61078a366004613003565b6125a1565b60405161029191906136ad565b61036e6107aa36600461308f565b6126d1565b6107c26107bd366004613703565b6127c2565b60405161029192919061377d565b600c5461032d565b6060600d805480602002602001604051908101604052809291908181526020016000905b828210156108a55760008481526020908190206040805160c081018252600286029092018054835260019081015464ffffffffff808216858701526501000000000082048116938501939093526a01000000000000000000008104831660608501526f0100000000000000000000000000000081048316608085015274010000000000000000000000000000000000000000900490911660a083015290835290920191016107fc565b50505050905090565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152600c548211806108e7575081155b1561091e576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600c61092b6001846137ce565b8154811061093b5761093b6137e1565b60009182526020918290206040805160a0810182526002909302909101805483526001015464ffffffffff808216948401949094526501000000000081048416918301919091526a01000000000000000000008104831660608301526f010000000000000000000000000000009004909116608082015292915050565b600180546109c590613810565b80601f01602080910402602001604051908101604052809291908181526020018280546109f190613810565b8015610a3e5780601f10610a1357610100808354040283529160200191610a3e565b820191906000526020600020905b815481529060010190602001808311610a2157829003601f168201915b505050505081565b60005473ffffffffffffffffffffffffffffffffffffffff163314610acc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a4544000000000000000000000000000000000000000060448201526064015b60405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff8116610b1a576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff831660008181526003602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168615159081179091558251938452908301527feeeb06b5605b72367788db09c5284b141487cdc2ab0925fcf8880d30ea58437691015b60405180910390a1505050565b600654600090610bc29064ffffffffff166001613863565b60095464ffffffffff908116911614919050565b610bdf33611892565b610c15576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160e081018252600754808252600854602083015260095464ffffffffff80821694840194909452650100000000008104841660608401526a01000000000000000000008104841660808401526f010000000000000000000000000000008104841660a084015274010000000000000000000000000000000000000000900490921660c08201529086141580610cb2575080602001518514155b80610ccf5750806040015164ffffffffff168464ffffffffff1614155b80610cec57508060a0015164ffffffffff168364ffffffffff1614155b80610d0957508060c0015164ffffffffff168264ffffffffff1614155b15610d40576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60048054600a554264ffffffffff818116606085810182905243808416608080890182905288519097556020808901516005556040808a01516006805460a0808e015160c08f0151948c167fffffffffffffffffffffffffffffffffffffffffffff000000000000000000009093169290921765010000000000909a02999099177fffffffffffffffffffffffff00000000000000000000ffffffffffffffffffff166a01000000000000000000009096027fffffffffffffffffffffffff0000000000ffffffffffffffffffffffffffffff16959095176f01000000000000000000000000000000958a1695909502949094177fffffffffffffff0000000000ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000091891691909102179092558151958c16865285018d905284018b905290830193909352928101919091527fcc3c3071340d91a4fd687f9ad48d1ee5689f8083136feb3594807d0f7481f7cf910160405180910390a1505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610f4a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152606401610ac3565b610f52612844565b565b610f5c6128c1565b610f6533611a45565b610f9b576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600654610fb09064ffffffffff166001613863565b64ffffffffff168364ffffffffff16141580610fd957508064ffffffffff168264ffffffffff16115b15611010576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160e0810182528681526020810186905264ffffffffff8086168284018190524280831660608501819052438085166080870181905289861660a0880181905295891660c090970187905260078d905560088c905560098054740100000000000000000000000000000000000000009098027fffffffffffffff0000000000ffffffffffffffffffffffffffffffffffffffff6f010000000000000000000000000000009098027fffffffffffffffffffffffff0000000000ffffffffffffffffffffffffffffff6a0100000000000000000000909402939093167fffffffffffffffffffffffff00000000000000000000ffffffffffffffffffff650100000000009096027fffffffffffffffffffffffffffffffffffffffffffff00000000000000000000909a1690971798909817939093169490941793909317939093169390931790915591517fb38026cc978f6c2642a5108ee558571a1b01a939b056abcc065b7eabacaf2d9d926111b69287928a928a929164ffffffffff959095168552602085019390935260408401919091526060830152608082015260a00190565b60405180910390a15050505050565b336000908152600e602052604090205460ff161580156111fd575060005473ffffffffffffffffffffffffffffffffffffffff163314155b15611234576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8060000361126e576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f546000906112859064ffffffffff16836138b7565b600f549091506000906112ab9064ffffffffff80821691650100000000009004166138cb565b600c5464ffffffffff9190911691506000811561136b576000600c6112d16001856137ce565b815481106112e1576112e16137e1565b9060005260206000209060020201600101600a9054906101000a900464ffffffffff1660016113109190613863565b600f5464ffffffffff91821692506a010000000000000000000090041681101561135357600f546a0100000000000000000000900464ffffffffff169150611365565b4381116113605743611362565b805b91505b506113a9565b600f546a0100000000000000000000900464ffffffffff1661138d57436113a6565b600f546a0100000000000000000000900464ffffffffff165b90505b806000036113e3576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600d546000906113f49060016138ef565b9050600d6040518060c001604052808881526020018364ffffffffff16815260200185600161142391906138ef565b64ffffffffff9081168252600f546020909201916114429116876138ef565b64ffffffffff9081168252438116602080840191909152428216604093840152845460018181018755600096875282872086516002909302019182559185015191018054938501516060860151608087015160a090970151851674010000000000000000000000000000000000000000027fffffffffffffff0000000000ffffffffffffffffffffffffffffffffffffffff9786166f01000000000000000000000000000000027fffffffffffffffffffffffff0000000000ffffffffffffffffffffffffffffff9287166a010000000000000000000002929092167fffffffffffffffffffffffff00000000000000000000ffffffffffffffffffff93871665010000000000027fffffffffffffffffffffffffffffffffffffffffffff00000000000000000000909816959096169490941795909517169290921792909217929092161790555b600f5464ffffffffff168110156117d257600060016115aa87866138ef565b6115b491906137ce565b90506000826115c48760016138ef565b6115ce91906138ef565b600f5490915088906115e99060019064ffffffffff16613902565b64ffffffffff16840361160d57611600848a613920565b61160a908b6137ce565b90505b6040805160a08101825282815264ffffffffff80851660208301908152898216838501908152878316606085019081528a841660808601908152600c8054600181018255600091909152955160029096027fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c781019690965592517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c8909501805492519151935185166f01000000000000000000000000000000027fffffffffffffffffffffffff0000000000ffffffffffffffffffffffffffffff9486166a010000000000000000000002949094167fffffffffffffffffffffffff00000000000000000000ffffffffffffffffffff92861665010000000000027fffffffffffffffffffffffffffffffffffffffffffff00000000000000000000909416969095169590951791909117169190911717905551859083907f9d1578529527d7ca977e6e95da5e7302299dfa7894fea3a1992ce68741ff5a0a906117a79085908b9089909283526020830191909152604082015260600190565b60405180910390a36117ba8360016138ef565b955050505080806117ca90613937565b91505061158b565b50600f546f01000000000000000000000000000000900460ff161561181d5761181d7f0000000000000000000000006f40d4a6237c257fff2db00fa0510deeecd303eb333089612946565b33817fd3aec04e72c75d4a42792ce6fe015d1ec10b07a8a621c9df2a89bd3644cf7ca88861184c8760016138ef565b600f546118609064ffffffffff16896138ef565b6040805193845260208401929092529082015243606082015242608082015260a00160405180910390a3505050505050565b73ffffffffffffffffffffffffffffffffffffffff811660009081526003602052604081205460ff16806118e0575060005473ffffffffffffffffffffffffffffffffffffffff8381169116145b92915050565b60005473ffffffffffffffffffffffffffffffffffffffff163314611967576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152606401610ac3565b73ffffffffffffffffffffffffffffffffffffffff81166119b4576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff81166000818152600e6020908152604091829020805460ff8116157fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0090911681179091558251938452908301527f7070b1fa79059dab7359a2e5b3be557471a19c213ba384d17144bc86d149672391015b60405180910390a150565b73ffffffffffffffffffffffffffffffffffffffff811660009081526002602052604081205460ff16806118e057505060005473ffffffffffffffffffffffffffffffffffffffff91821691161490565b60005473ffffffffffffffffffffffffffffffffffffffff163314611b17576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152606401610ac3565b60005b8251811015611b7257611b5f838281518110611b3857611b386137e1565b6020026020010151838381518110611b5257611b526137e1565b6020026020010151612a28565b5080611b6a81613937565b915050611b1a565b505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314611bf8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152606401610ac3565b610f52612a74565b60005473ffffffffffffffffffffffffffffffffffffffff163314611c81576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152606401610ac3565b438164ffffffffff161080611c9b575064ffffffffff8116155b15611cd2576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f80547fffffffffffffffffffffffffffffffffff0000000000ffffffffffffffffffff166a010000000000000000000064ffffffffff8416908102919091179091556040519081527f9d04c34d16567c8a1806a7cbaff030caed3589501bd3e0e3f282193a9b3afe6190602001611a3a565b60005b81811015611b7257611ed1838383818110611d6657611d666137e1565b9050602002810190611d78919061396f565b611d8690602081019061308f565b848484818110611d9857611d986137e1565b9050602002810190611daa919061396f565b60200135858585818110611dc057611dc06137e1565b9050602002810190611dd2919061396f565b611de39060608101906040016139ad565b868686818110611df557611df56137e1565b9050602002810190611e07919061396f565b60600135878787818110611e1d57611e1d6137e1565b9050602002810190611e2f919061396f565b60800135888888818110611e4557611e456137e1565b9050602002810190611e57919061396f565b611e659060a08101906139c8565b8a8a8a818110611e7757611e776137e1565b9050602002810190611e89919061396f565b611e979060c0810190613a30565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061229d92505050565b80611edb81613937565b915050611d49565b60005473ffffffffffffffffffffffffffffffffffffffff163314611f64576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152606401610ac3565b8173ffffffffffffffffffffffffffffffffffffffff8116611fb2576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff831660008181526002602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168615159081179091558251938452908301527f780d738f356a91be5dfe8ffb87990c655a36b3430a233c71a209eb1e9a1a1a759101610b9d565b6060600c805480602002602001604051908101604052809291908181526020016000905b828210156108a55760008481526020908190206040805160a081018252600286029092018054835260019081015464ffffffffff808216858701526501000000000082048116938501939093526a01000000000000000000008104831660608501526f0100000000000000000000000000000090049091166080830152908352909201910161205d565b60005473ffffffffffffffffffffffffffffffffffffffff163314612168576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152606401610ac3565b64ffffffffff82161580612181575064ffffffffff8116155b156121b8576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f80547fffffffffffffffffffffffffffffffff00ffffffffff0000000000ffffffffff166f010000000000000000000000000000008515159081027fffffffffffffffffffffffffffffffffffffffffffff0000000000ffffffffff16919091176501000000000064ffffffffff868116918202929092177fffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000016918516918217909355604080519283526020830193909352918101919091527f7ec0e33f381405196f961b48c778f62e8184d357d894aa02af2444db07a09fd890606001610b9d565b6122a56128c1565b3373ffffffffffffffffffffffffffffffffffffffff8916146122f4576040517fbd79de5800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60065464ffffffffff16848114806123205750600081118015612320575061231d6001826137ce565b85145b612356576040517f9b8febfe00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600087878b888c8760405160200161237396959493929190613a95565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152828252805160209182012090830152016040516020818303038152906040528051906020012090506124168585808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505050888514905061240c57600a54612410565b6004545b83612ae3565b61244c576040517f09bde33900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8a166000908152600b602090815260408083208a8452909152812054612487908b6137ce565b9050806000036124c3576040517f969bf72800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8b166000908152600b602090815260408083208b845290915290208a90556125217f0000000000000000000000006f40d4a6237c257fff2db00fa0510deeecd303eb8c83612af9565b6040805173ffffffffffffffffffffffffffffffffffffffff8d1681526020810183905290810188905260ff8a166060820152608081018990524260a08201524360c08201527f309cb1c0dc6ce0f02c0c35cc1f46bbe61ec9deb311d101b87e7d25bd0b647fd79060e00160405180910390a15050505050505050505050565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a0810191909152600d548211806125e1575081155b15612618576040517fa86b651200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600d6126256001846137ce565b81548110612635576126356137e1565b60009182526020918290206040805160c0810182526002909302909101805483526001015464ffffffffff808216948401949094526501000000000081048416918301919091526a01000000000000000000008104831660608301526f0100000000000000000000000000000081048316608083015274010000000000000000000000000000000000000000900490911660a082015292915050565b60005473ffffffffffffffffffffffffffffffffffffffff163314612752576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152606401610ac3565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b60606000858589868a876040516020016127e196959493929190613a95565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152828252805160208083019190912090840152935001604051602081830303815290604052805190602001209050965096945050505050565b61284c612b4f565b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390a1565b60005474010000000000000000000000000000000000000000900460ff1615610f52576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610ac3565b60405173ffffffffffffffffffffffffffffffffffffffff80851660248301528316604482015260648101829052612a229085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152612bd3565b50505050565b6060600080835160208501865af43d6040519250601f19601f6020830101168301604052808352806000602085013e811560018103612a6b57816000803e816000fd5b50505092915050565b612a7c6128c1565b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff16740100000000000000000000000000000000000000001790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586128973390565b600082612af08584612cdf565b14949350505050565b60405173ffffffffffffffffffffffffffffffffffffffff8316602482015260448101829052611b729084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064016129a0565b60005474010000000000000000000000000000000000000000900460ff16610f52576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610ac3565b6000612c35826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16612d2c9092919063ffffffff16565b805190915015611b725780806020019051810190612c539190613aeb565b611b72576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610ac3565b600081815b8451811015612d2457612d1082868381518110612d0357612d036137e1565b6020026020010151612d43565b915080612d1c81613937565b915050612ce4565b509392505050565b6060612d3b8484600085612d75565b949350505050565b6000818310612d5f576000828152602084905260409020612d6e565b60008381526020839052604090205b9392505050565b606082471015612e07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610ac3565b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051612e309190613b08565b60006040518083038185875af1925050503d8060008114612e6d576040519150601f19603f3d011682016040523d82523d6000602084013e612e72565b606091505b5091509150612e8387838387612e8e565b979650505050505050565b60608315612f24578251600003612f1d5773ffffffffffffffffffffffffffffffffffffffff85163b612f1d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610ac3565b5081612d3b565b612d3b8383815115612f395781518083602001fd5b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac39190613118565b6020808252825182820181905260009190848201906040850190845b81811015612ff757612fe483855180518252602081015164ffffffffff80821660208501528060408401511660408501528060608401511660608501528060808401511660808501528060a08401511660a085015250505050565b9284019260c09290920191600101612f89565b50909695505050505050565b60006020828403121561301557600080fd5b5035919050565b60a081016118e0828480518252602081015164ffffffffff808216602085015280604084015116604085015280606084015116606085015280608084015116608085015250505050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461308a57600080fd5b919050565b6000602082840312156130a157600080fd5b612d6e82613066565b60005b838110156130c55781810151838201526020016130ad565b50506000910152565b600081518084526130e68160208601602086016130aa565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b602081526000612d6e60208301846130ce565b6000806040838503121561313e57600080fd5b61314783613066565b946020939093013593505050565b801515811461316357600080fd5b50565b6000806040838503121561317957600080fd5b61318283613066565b9150602083013561319281613155565b809150509250929050565b803564ffffffffff8116811461308a57600080fd5b600080600080600060a086880312156131ca57600080fd5b85359450602086013593506131e16040870161319d565b92506131ef6060870161319d565b91506131fd6080870161319d565b90509295509295909350565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff8111828210171561327f5761327f613209565b604052919050565b600067ffffffffffffffff8211156132a1576132a1613209565b5060051b60200190565b600082601f8301126132bc57600080fd5b813567ffffffffffffffff8111156132d6576132d6613209565b61330760207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601613238565b81815284602083860101111561331c57600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261334a57600080fd5b8135602061335f61335a83613287565b613238565b82815260059290921b8401810191818101908684111561337e57600080fd5b8286015b848110156133be57803567ffffffffffffffff8111156133a25760008081fd5b6133b08986838b01016132ab565b845250918301918301613382565b509695505050505050565b600080604083850312156133dc57600080fd5b823567ffffffffffffffff808211156133f457600080fd5b818501915085601f83011261340857600080fd5b8135602061341861335a83613287565b82815260059290921b8401810191818101908984111561343757600080fd5b948201945b8386101561345c5761344d86613066565b8252948201949082019061343c565b9650508601359250508082111561347257600080fd5b5061347f85828601613339565b9150509250929050565b60006020828403121561349b57600080fd5b612d6e8261319d565b60008083601f8401126134b657600080fd5b50813567ffffffffffffffff8111156134ce57600080fd5b6020830191508360208260051b85010111156134e957600080fd5b9250929050565b6000806020838503121561350357600080fd5b823567ffffffffffffffff81111561351a57600080fd5b613526858286016134a4565b90969095509350505050565b6020808252825182820181905260009190848201906040850190845b81811015612ff75761359d83855180518252602081015164ffffffffff808216602085015280604084015116604085015280606084015116606085015280608084015116608085015250505050565b9284019260a0929092019160010161354e565b6000806000606084860312156135c557600080fd5b83356135d081613155565b92506135de6020850161319d565b91506135ec6040850161319d565b90509250925092565b803560ff8116811461308a57600080fd5b60008060008060008060008060e0898b03121561362257600080fd5b61362b89613066565b97506020890135965061364060408a016135f5565b9550606089013594506080890135935060a089013567ffffffffffffffff8082111561366b57600080fd5b6136778c838d016134a4565b909550935060c08b013591508082111561369057600080fd5b5061369d8b828c016132ab565b9150509295985092959890939650565b60c081016118e0828480518252602081015164ffffffffff80821660208501528060408401511660408501528060608401511660608501528060808401511660808501528060a08401511660a085015250505050565b60008060008060008060c0878903121561371c57600080fd5b61372587613066565b95506020870135945061373a604088016135f5565b9350606087013592506080870135915060a087013567ffffffffffffffff81111561376457600080fd5b61377089828a016132ab565b9150509295509295509295565b60408152600061379060408301856130ce565b90508260208301529392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b818103818111156118e0576118e061379f565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600181811c9082168061382457607f821691505b60208210810361385d577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b64ffffffffff8181168382160190808211156138815761388161379f565b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000826138c6576138c6613888565b500490565b600064ffffffffff808416806138e3576138e3613888565b92169190910492915050565b808201808211156118e0576118e061379f565b64ffffffffff8281168282160390808211156138815761388161379f565b80820281158282048414176118e0576118e061379f565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036139685761396861379f565b5060010190565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff218336030181126139a357600080fd5b9190910192915050565b6000602082840312156139bf57600080fd5b612d6e826135f5565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181126139fd57600080fd5b83018035915067ffffffffffffffff821115613a1857600080fd5b6020019150600581901b36038213156134e957600080fd5b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112613a6557600080fd5b83018035915067ffffffffffffffff821115613a8057600080fd5b6020019150368190038213156134e957600080fd5b60ff8716815285602082015273ffffffffffffffffffffffffffffffffffffffff8516604082015283606082015282608082015260c060a08201526000613adf60c08301846130ce565b98975050505050505050565b600060208284031215613afd57600080fd5b8151612d6e81613155565b600082516139a38184602087016130aa56fea26469706673582212207609cbca8b50d2f1c7cef306a92b5918509b2d83165cbbd062d38e1577d46e2364736f6c63430008150033

Verified Source Code Full Match

Compiler: v0.8.21+commit.d9974bed EVM: paris Optimization: Yes (10000000 runs)
Pausable.sol 105 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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);
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-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);
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/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;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    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));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    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");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    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");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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
     * ====
     *
     * [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://diligence.consensys.net/posts/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.5.11/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;
    }
}
MerkleProof.sol 223 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/MerkleProof.sol)

pragma solidity ^0.8.0;

/**
 * @dev These functions deal with verification of Merkle Tree proofs.
 *
 * The tree and the proofs can be generated using our
 * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
 * You will find a quickstart guide in the readme.
 *
 * WARNING: You should avoid using leaf values that are 64 bytes long prior to
 * hashing, or use a hash function other than keccak256 for hashing leaves.
 * This is because the concatenation of a sorted pair of internal nodes in
 * the merkle tree could be reinterpreted as a leaf value.
 * OpenZeppelin's JavaScript library generates merkle trees that are safe
 * against this attack out of the box.
 */
library MerkleProof {
    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     */
    function verify(
        bytes32[] memory proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }

    /**
     * @dev Calldata version of {verify}
     *
     * _Available since v4.7._
     */
    function verifyCalldata(
        bytes32[] calldata proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProofCalldata(proof, leaf) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leafs & pre-images are assumed to be sorted.
     *
     * _Available since v4.4._
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Calldata version of {processProof}
     *
     * _Available since v4.7._
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Calldata version of {multiProofVerify}
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     *
     * _Available since v4.7._
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Calldata version of {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
        return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
    }

    function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}
errorTypes.sol 34 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

library LibsErrorTypes {
    /***********************************|
    |         LiquidityCalcs            | 
    |__________________________________*/

    /// @notice thrown when supply or borrow exchange price is zero at calc token data (token not configured yet)
    uint256 internal constant LiquidityCalcs__ExchangePriceZero = 70001;

    /// @notice thrown when rate data is set to a version that is not implemented
    uint256 internal constant LiquidityCalcs__UnsupportedRateVersion = 70002;

    /// @notice thrown when the calculated borrow rate turns negative. This should never happen.
    uint256 internal constant LiquidityCalcs__BorrowRateNegative = 70003;

    /***********************************|
    |           SafeTransfer            | 
    |__________________________________*/

    /// @notice thrown when safe transfer from for an ERC20 fails
    uint256 internal constant SafeTransfer__TransferFromFailed = 71001;

    /// @notice thrown when safe transfer for an ERC20 fails
    uint256 internal constant SafeTransfer__TransferFailed = 71002;

    /***********************************|
    |           SafeApprove             | 
    |__________________________________*/

    /// @notice thrown when safe approve from for an ERC20 fails
    uint256 internal constant SafeApprove__ApproveFailed = 81001;
}
safeTransfer.sol 97 lines
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.21;

import { LibsErrorTypes as ErrorTypes } from "./errorTypes.sol";

/// @notice provides minimalistic methods for safe transfers, e.g. ERC20 safeTransferFrom
library SafeTransfer {
    uint256 internal constant MAX_NATIVE_TRANSFER_GAS = 20000; // pass max. 20k gas for native transfers

    error FluidSafeTransferError(uint256 errorId_);

    /// @dev Transfer `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.
    /// Minimally modified from Solmate SafeTransferLib (address as input param for token, Custom Error):
    /// https://github.com/transmissions11/solmate/blob/50e15bb566f98b7174da9b0066126a4c3e75e0fd/src/utils/SafeTransferLib.sol#L31-L63
    function safeTransferFrom(address token_, address from_, address to_, uint256 amount_) internal {
        bool success_;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), and(from_, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from_" argument.
            mstore(add(freeMemoryPointer, 36), and(to_, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to_" argument.
            mstore(add(freeMemoryPointer, 68), amount_) // Append the "amount_" argument. Masking not required as it's a full 32 byte type.

            success_ := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token_, 0, freeMemoryPointer, 100, 0, 32)
            )
        }

        if (!success_) {
            revert FluidSafeTransferError(ErrorTypes.SafeTransfer__TransferFromFailed);
        }
    }

    /// @dev Transfer `amount_` of `token_` to `to_`.
    /// If `token_` returns no value, non-reverting calls are assumed to be successful.
    /// Minimally modified from Solmate SafeTransferLib (address as input param for token, Custom Error):
    /// https://github.com/transmissions11/solmate/blob/50e15bb566f98b7174da9b0066126a4c3e75e0fd/src/utils/SafeTransferLib.sol#L65-L95
    function safeTransfer(address token_, address to_, uint256 amount_) internal {
        bool success_;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), and(to_, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to_" argument.
            mstore(add(freeMemoryPointer, 36), amount_) // Append the "amount_" argument. Masking not required as it's a full 32 byte type.

            success_ := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token_, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        if (!success_) {
            revert FluidSafeTransferError(ErrorTypes.SafeTransfer__TransferFailed);
        }
    }

    /// @dev Transfer `amount_` of ` native token to `to_`.
    /// Minimally modified from Solmate SafeTransferLib (Custom Error):
    /// https://github.com/transmissions11/solmate/blob/50e15bb566f98b7174da9b0066126a4c3e75e0fd/src/utils/SafeTransferLib.sol#L15-L25
    function safeTransferNative(address to_, uint256 amount_) internal {
        bool success_;

        /// @solidity memory-safe-assembly
        assembly {
            // Transfer the ETH and store if it succeeded or not. Pass limited gas
            success_ := call(MAX_NATIVE_TRANSFER_GAS, to_, amount_, 0, 0, 0, 0)
        }

        if (!success_) {
            revert FluidSafeTransferError(ErrorTypes.SafeTransfer__TransferFailed);
        }
    }
}
errors.sol 13 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

abstract contract Errors {
    error Unauthorized();
    error InvalidParams();

    // claim related errors:
    error InvalidCycle();
    error InvalidProof();
    error NothingToClaim();
    error MsgSenderNotRecipient();
}
events.sol 60 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

abstract contract Events {
    /// @notice Emitted when an address is added or removed from the allowed proposers
    event LogUpdateProposer(address proposer, bool isProposer);

    /// @notice Emitted when an address is added or removed from the allowed approvers
    event LogUpdateApprover(address approver, bool isApprover);

    /// @notice Emitted when a new cycle root hash is proposed
    event LogRootProposed(uint256 cycle, bytes32 root, bytes32 contentHash, uint256 timestamp, uint256 blockNumber);

    /// @notice Emitted when a new cycle root hash is approved by the owner and becomes the new active root
    event LogRootUpdated(uint256 cycle, bytes32 root, bytes32 contentHash, uint256 timestamp, uint256 blockNumber);

    /// @notice Emitted when a `user` claims `amount` via a valid merkle proof
    event LogClaimed(
        address user,
        uint256 amount,
        uint256 cycle,
        uint8 positionType,
        bytes32 positionId,
        uint256 timestamp,
        uint256 blockNumber
    );

    /// @notice Emitted when a new reward cycle is created
    event LogRewardCycle(
        uint256 indexed cycle,
        uint256 indexed epoch,
        uint256 amount,
        uint256 startBlock,
        uint256 endBlock
    );

    /// @notice Emitted when a new distribution is created
    event LogDistribution(
        uint256 indexed epoch,
        address indexed initiator,
        uint256 amount,
        uint256 startCycle,
        uint256 endCycle,
        uint256 registrationBlock,
        uint256 registrationTimestamp
    );

    /// @notice Emitted when the distribution configuration is updated
    event LogDistributionConfigUpdated(
        bool pullFromSender,
        uint256 blocksPerDistribution,
        uint256 cyclesPerDistribution
    );

    /// @notice Emitted when a rewards distributor is toggled
    event LogRewardsDistributorToggled(address distributor, bool isDistributor);

    /// @notice Emitted when the start block of the next cycle is updated
    event LogStartBlockOfNextCycleUpdated(uint256 startBlockOfNextCycle);
}
main.sol 484 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { MerkleProof } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

import { Events } from "./events.sol";
import { Errors } from "./errors.sol";
import { Structs } from "./structs.sol";
import { Variables } from "./variables.sol";
import { SafeTransfer } from "../../../libraries/safeTransfer.sol";

// ---------------------------------------------------------------------------------------------
//
// @dev WARNING: DO NOT USE `multiProof` related methods of `MerkleProof`.
// This repo uses OpenZeppelin 4.8.2 which has a vulnerability for multi proofs. See:
// https://github.com/OpenZeppelin/openzeppelin-contracts/security/advisories/GHSA-wprv-93r4-jj2p
//
// ---------------------------------------------------------------------------------------------

abstract contract FluidMerkleDistributorCore is Structs, Variables, Events, Errors {
    /// @dev validates that an address is not the zero address
    modifier validAddress(address value_) {
        if (value_ == address(0)) {
            revert InvalidParams();
        }
        _;
    }
}

abstract contract FluidMerkleDistributorAdmin is FluidMerkleDistributorCore {
    /// @notice                  Updates an address status as a root proposer
    /// @param proposer_         The address to update
    /// @param isProposer_       Whether or not the address should be an allowed proposer
    function updateProposer(address proposer_, bool isProposer_) public onlyOwner validAddress(proposer_) {
        _proposers[proposer_] = isProposer_;
        emit LogUpdateProposer(proposer_, isProposer_);
    }

    /// @notice                  Updates an address status as a root approver
    /// @param approver_         The address to update
    /// @param isApprover_       Whether or not the address should be an allowed approver
    function updateApprover(address approver_, bool isApprover_) public onlyOwner validAddress(approver_) {
        _approvers[approver_] = isApprover_;
        emit LogUpdateApprover(approver_, isApprover_);
    }

    /// @notice                         Spell allows owner aka governance to do any arbitrary call on factory
    /// @param target_                  Address to which the call needs to be delegated
    /// @param data_                    Data to execute at the delegated address
    function _spell(address target_, bytes memory data_) internal returns (bytes memory response_) {
        assembly {
            let succeeded := delegatecall(gas(), target_, add(data_, 0x20), mload(data_), 0, 0)
            let size := returndatasize()

            response_ := mload(0x40)
            mstore(0x40, add(response_, and(add(add(size, 0x20), 0x1f), not(0x1f))))
            mstore(response_, size)
            returndatacopy(add(response_, 0x20), 0, size)

            switch iszero(succeeded)
            case 1 {
                // throw if delegatecall failed
                returndatacopy(0x00, 0x00, size)
                revert(0x00, size)
            }
        }
    }

    /// @dev open payload method for admin to resolve emergency cases
    function spell(address[] memory targets_, bytes[] memory calldatas_) public onlyOwner {
        for (uint256 i = 0; i < targets_.length; i++) _spell(targets_[i], calldatas_[i]);
    }

    /// @notice Pause contract functionality of new roots and claiming
    function pause() external onlyOwner {
        _pause();
    }

    /// @notice Unpause contract functionality of new roots and claiming
    function unpause() external onlyOwner {
        _unpause();
    }
}

abstract contract FluidMerkleDistributorApprover is FluidMerkleDistributorCore {
    /// @dev Checks that the sender is an approver
    modifier onlyApprover() {
        if (!isApprover(msg.sender)) {
            revert Unauthorized();
        }
        _;
    }

    /// @notice checks if the `approver_` is an allowed root approver
    function isApprover(address approver_) public view returns (bool) {
        return (_approvers[approver_] || owner == approver_);
    }

    /// @notice Approve the current pending root and content hash
    function approveRoot(
        bytes32 root_,
        bytes32 contentHash_,
        uint40 cycle_,
        uint40 startBlock_,
        uint40 endBlock_
    ) external onlyApprover {
        MerkleCycle memory merkleCycle_ = _pendingMerkleCycle;

        if (
            root_ != merkleCycle_.merkleRoot ||
            contentHash_ != merkleCycle_.merkleContentHash ||
            cycle_ != merkleCycle_.cycle ||
            startBlock_ != merkleCycle_.startBlock ||
            endBlock_ != merkleCycle_.endBlock
        ) {
            revert InvalidParams();
        }

        previousMerkleRoot = _currentMerkleCycle.merkleRoot;

        merkleCycle_.timestamp = uint40(block.timestamp);
        merkleCycle_.publishBlock = uint40(block.number);

        _currentMerkleCycle = merkleCycle_;

        emit LogRootUpdated(cycle_, root_, contentHash_, block.timestamp, block.number);
    }
}

abstract contract FluidMerkleDistributorProposer is FluidMerkleDistributorCore {
    /// @dev Checks that the sender is a proposer
    modifier onlyProposer() {
        if (!isProposer(msg.sender)) {
            revert Unauthorized();
        }
        _;
    }

    /// @notice checks if the `proposer_` is an allowed root proposer
    function isProposer(address proposer_) public view returns (bool) {
        return (_proposers[proposer_] || owner == proposer_);
    }

    /// @notice Propose a new root and content hash, which will be stored as pending until approved
    function proposeRoot(
        bytes32 root_,
        bytes32 contentHash_,
        uint40 cycle_,
        uint40 startBlock_,
        uint40 endBlock_
    ) external whenNotPaused onlyProposer {
        if (cycle_ != _currentMerkleCycle.cycle + 1 || startBlock_ > endBlock_) {
            revert InvalidParams();
        }

        _pendingMerkleCycle = MerkleCycle({
            merkleRoot: root_,
            merkleContentHash: contentHash_,
            cycle: cycle_,
            startBlock: startBlock_,
            endBlock: endBlock_,
            timestamp: uint40(block.timestamp),
            publishBlock: uint40(block.number)
        });

        emit LogRootProposed(cycle_, root_, contentHash_, block.timestamp, block.number);
    }
}

abstract contract FluidMerkleDistributorRewards is FluidMerkleDistributorCore {
    /// @dev Modifier to check if the sender is a rewards distributor
    modifier onlyRewardsDistributor() {
        if (!rewardsDistributor[msg.sender] && owner != msg.sender) revert Unauthorized();
        _;
    }

    /// @notice Updates the distribution configuration
    /// @param pullFromDistributor_ - whether to pull rewards from distributor or not
    /// @param blocksPerDistribution_ - duration of distribution in blocks
    /// @param cyclesPerDistribution_ - number of cycles to distribute rewards, if 0 then means paused
    function updateDistributionConfig(
        bool pullFromDistributor_,
        uint40 blocksPerDistribution_,
        uint40 cyclesPerDistribution_
    ) external onlyOwner {
        if (blocksPerDistribution_ == 0 || cyclesPerDistribution_ == 0) revert InvalidParams();
        emit LogDistributionConfigUpdated(
            pullFromDistributor = pullFromDistributor_,
            blocksPerDistribution = blocksPerDistribution_,
            cyclesPerDistribution = cyclesPerDistribution_
        );
    }

    /// @notice Toggles a rewards distributor
    /// @param distributor_ - address of the rewards distributor
    function toggleRewardsDistributor(address distributor_) external onlyOwner {
        if (distributor_ == address(0)) revert InvalidParams();
        emit LogRewardsDistributorToggled(
            distributor_,
            rewardsDistributor[distributor_] = !rewardsDistributor[distributor_]
        );
    }

    /// @notice Sets the start block of the next cycle
    /// @param startBlockOfNextCycle_ The start block of the next cycle
    function setStartBlockOfNextCycle(uint40 startBlockOfNextCycle_) external onlyOwner {
        if (startBlockOfNextCycle_ < block.number || startBlockOfNextCycle_ == 0) revert InvalidParams();
        emit LogStartBlockOfNextCycleUpdated(startBlockOfNextCycle = uint40(startBlockOfNextCycle_));
    }

    /////// Public Functions ///////

    /// @notice Returns the cycle rewards
    /// @return rewards_ - rewards
    function getCycleRewards() external view returns (Reward[] memory) {
        return rewards;
    }

    /// @notice Returns the cycle reward for a given cycle
    /// @param cycle_ - cycle of the reward
    /// @return reward_ - reward
    function getCycleReward(uint256 cycle_) external view returns (Reward memory) {
        if (cycle_ > rewards.length || cycle_ == 0) revert InvalidParams();
        return rewards[cycle_ - 1];
    }

    /// @notice Returns the total number of cycles
    /// @return totalCycles_ - total number of cycles
    function totalCycleRewards() external view returns (uint256) {
        return rewards.length;
    }

    /// @notice Returns the total number of distributions
    /// @return totalDistributions_ - total number of distributions
    function totalDistributions() external view returns (uint256) {
        return distributions.length;
    }

    /// @notice Returns the distribution for a given epoch
    /// @param epoch_ - epoch of the distribution
    /// @return distribution_ - distribution
    function getDistributionForEpoch(uint256 epoch_) external view returns (Distribution memory) {
        if (epoch_ > distributions.length || epoch_ == 0) revert InvalidParams();
        return distributions[epoch_ - 1];
    }

    /// @notice Returns all distributions
    /// @return distributions_ - all distributions
    function getDistributions() external view returns (Distribution[] memory) {
        return distributions;
    }

    ////////// Distribution Function //////////

    /// @notice Distributes rewards for a given token
    /// @param amount_ - amount of tokens to distribute rewards for
    function distributeRewards(uint256 amount_) public onlyRewardsDistributor {
        if (amount_ == 0) revert InvalidParams();

        uint256 amountPerCycle_ = amount_ / cyclesPerDistribution;
        uint256 blocksPerCycle_ = blocksPerDistribution / cyclesPerDistribution;

        uint256 cyclesLength_ = rewards.length;
        uint256 startBlock_ = 0;
        if (cyclesLength_ > 0) {
            uint256 lastCycleEndBlock_ = rewards[cyclesLength_ - 1].endBlock + 1;
            // if there are already some cycles, then we need to check if startBlockOfNextCycle was set in order to start from that block, then assign it to startBlock_
            if (lastCycleEndBlock_ < startBlockOfNextCycle) {
                startBlock_ = startBlockOfNextCycle;
            } else {
                // if lastCycleEndBlock_ of last cycle is still syncing, then we need to start last cycle's end block + 1, else start from current block
                startBlock_ = lastCycleEndBlock_ > block.number ? lastCycleEndBlock_ : block.number;
            }
        } else {
            // if there are no cycles, that means this is the first distribution, then we need to start from startBlockOfNextCycle, if it was set, else start from current block
            startBlock_ = startBlockOfNextCycle > 0 ? startBlockOfNextCycle : block.number;
        }

        if (startBlock_ == 0) revert InvalidParams();

        uint256 distributionEpoch_ = distributions.length + 1;

        distributions.push(
            Distribution({
                amount: amount_,
                epoch: uint40(distributionEpoch_),
                startCycle: uint40(cyclesLength_ + 1),
                endCycle: uint40(cyclesLength_ + cyclesPerDistribution),
                registrationBlock: uint40(block.number),
                registrationTimestamp: uint40(block.timestamp)
            })
        );

        for (uint256 i = 0; i < cyclesPerDistribution; i++) {
            uint256 endBlock_ = startBlock_ + blocksPerCycle_ - 1;
            uint256 cycle_ = cyclesLength_ + 1 + i;
            uint256 cycleAmount_ = amountPerCycle_;
            if (i == cyclesPerDistribution - 1) {
                cycleAmount_ = amount_ - (amountPerCycle_ * i);
            }
            rewards.push(
                Reward({
                    cycle: uint40(cycle_),
                    amount: cycleAmount_,
                    startBlock: uint40(startBlock_),
                    endBlock: uint40(endBlock_),
                    epoch: uint40(distributionEpoch_)
                })
            );
            emit LogRewardCycle(cycle_, distributionEpoch_, cycleAmount_, startBlock_, endBlock_);
            startBlock_ = endBlock_ + 1;
        }

        if (pullFromDistributor) SafeERC20.safeTransferFrom(TOKEN, msg.sender, address(this), amount_);

        emit LogDistribution(
            distributionEpoch_,
            msg.sender,
            amount_,
            cyclesLength_ + 1,
            cyclesLength_ + cyclesPerDistribution,
            block.number,
            block.timestamp
        );
    }
}

contract FluidMerkleDistributor is
    FluidMerkleDistributorCore,
    FluidMerkleDistributorAdmin,
    FluidMerkleDistributorApprover,
    FluidMerkleDistributorProposer,
    FluidMerkleDistributorRewards
{
    constructor(
        string memory name_,
        address owner_,
        address proposer_,
        address approver_,
        address rewardToken_,
        uint256 distributionInHours_,
        uint256 cycleInHours_,
        uint256 startBlock_,
        bool pullFromDistributor_
    )
        validAddress(owner_)
        validAddress(proposer_)
        validAddress(approver_)
        validAddress(rewardToken_)
        Variables(owner_, rewardToken_)
    {
        if (distributionInHours_ == 0 || cycleInHours_ == 0) revert InvalidParams();

        name = name_;

        _proposers[proposer_] = true;
        emit LogUpdateProposer(proposer_, true);

        _approvers[approver_] = true;
        emit LogUpdateApprover(approver_, true);

        uint40 _blocksPerDistribution = uint40(distributionInHours_ * 1 hours);
        uint40 _cyclesPerDistribution = uint40(distributionInHours_ / cycleInHours_);

        if (block.chainid == 1) _blocksPerDistribution = _blocksPerDistribution / 12 seconds;
        else if (block.chainid == 42161)
            _blocksPerDistribution = _blocksPerDistribution * 4; // 0.25 seconds blocktime, means 4 blocks per second
        else if (block.chainid == 8453 || block.chainid == 137)
            _blocksPerDistribution = _blocksPerDistribution / 2 seconds;
        else revert("Unsupported chain");

        emit LogDistributionConfigUpdated(
            pullFromDistributor = pullFromDistributor_,
            blocksPerDistribution = _blocksPerDistribution,
            cyclesPerDistribution = _cyclesPerDistribution
        );

        if (startBlock_ > 0) emit LogStartBlockOfNextCycleUpdated(startBlockOfNextCycle = uint40(startBlock_));
    }

    /// @notice checks if there is a proposed root waiting to be approved
    function hasPendingRoot() external view returns (bool) {
        return _pendingMerkleCycle.cycle == _currentMerkleCycle.cycle + 1;
    }

    /// @notice merkle root data related to current cycle (proposed and approved).
    function currentMerkleCycle() public view returns (MerkleCycle memory) {
        return _currentMerkleCycle;
    }

    /// @notice merkle root data related to pending cycle (proposed but not yet approved).
    function pendingMerkleCycle() public view returns (MerkleCycle memory) {
        return _pendingMerkleCycle;
    }

    function encodeClaim(
        address recipient_,
        uint256 cumulativeAmount_,
        uint8 positionType_,
        bytes32 positionId_,
        uint256 cycle_,
        bytes memory metadata_
    ) public pure returns (bytes memory encoded_, bytes32 hash_) {
        encoded_ = abi.encode(positionType_, positionId_, recipient_, cycle_, cumulativeAmount_, metadata_);
        hash_ = keccak256(bytes.concat(keccak256(encoded_)));
    }

    /// @notice Claims rewards for a given recipient
    /// @param recipient_ - address of the recipient
    /// @param cumulativeAmount_ - cumulative amount of rewards to claim
    /// @param positionType_ - type of position, 1 for lending, 2 for vaults, 3 for smart lending, etc
    /// @param positionId_ - id of the position, fToken address for lending and vaultId for vaults
    /// @param cycle_ - cycle of the rewards
    /// @param merkleProof_ - merkle proof of the rewards
    function claim(
        address recipient_,
        uint256 cumulativeAmount_,
        uint8 positionType_,
        bytes32 positionId_,
        uint256 cycle_,
        bytes32[] calldata merkleProof_,
        bytes memory metadata_
    ) public whenNotPaused {
        if (msg.sender != recipient_) revert MsgSenderNotRecipient();
        uint256 currentCycle_ = uint256(_currentMerkleCycle.cycle);

        if (!(cycle_ == currentCycle_ || (currentCycle_ > 0 && cycle_ == currentCycle_ - 1))) {
            revert InvalidCycle();
        }

        // Verify the merkle proof.
        bytes32 node_ = keccak256(
            bytes.concat(
                keccak256(abi.encode(positionType_, positionId_, recipient_, cycle_, cumulativeAmount_, metadata_))
            )
        );
        if (
            !MerkleProof.verify(
                merkleProof_,
                cycle_ == currentCycle_ ? _currentMerkleCycle.merkleRoot : previousMerkleRoot,
                node_
            )
        ) {
            revert InvalidProof();
        }

        uint256 claimable_ = cumulativeAmount_ - claimed[recipient_][positionId_];
        if (claimable_ == 0) {
            revert NothingToClaim();
        }

        claimed[recipient_][positionId_] = cumulativeAmount_;

        SafeERC20.safeTransfer(TOKEN, recipient_, claimable_);

        emit LogClaimed(recipient_, claimable_, cycle_, positionType_, positionId_, block.timestamp, block.number);
    }

    struct Claim {
        address recipient;
        uint256 cumulativeAmount;
        uint8 positionType;
        bytes32 positionId;
        uint256 cycle;
        bytes32[] merkleProof;
        bytes metadata;
    }

    function bulkClaim(Claim[] calldata claims_) external {
        for (uint i = 0; i < claims_.length; i++) {
            claim(
                claims_[i].recipient,
                claims_[i].cumulativeAmount,
                claims_[i].positionType,
                claims_[i].positionId,
                claims_[i].cycle,
                claims_[i].merkleProof,
                claims_[i].metadata
            );
        }
    }
}
structs.sol 38 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

abstract contract Structs {
    struct MerkleCycle {
        // slot 1
        bytes32 merkleRoot;
        // slot 2
        bytes32 merkleContentHash;
        // slot 3
        uint40 cycle;
        uint40 timestamp;
        uint40 publishBlock;
        uint40 startBlock;
        uint40 endBlock;
    }

    struct Reward {
        // slot 1
        uint256 amount;
        // slot 2
        uint40 cycle;
        uint40 startBlock;
        uint40 endBlock;
        uint40 epoch;
    }

    struct Distribution {
        // slot 1
        uint256 amount;
        // slot 2
        uint40 epoch;
        uint40 startCycle;
        uint40 endCycle;
        uint40 registrationBlock;
        uint40 registrationTimestamp;
    }
}
variables.sol 97 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Owned } from "solmate/src/auth/Owned.sol";
import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol";

import { Structs } from "./structs.sol";

abstract contract Constants {
    IERC20 public immutable TOKEN;

    constructor(address rewardToken_) {
        TOKEN = IERC20(rewardToken_);
    }
}

abstract contract Variables is Owned, Pausable, Constants, Structs {
    // ------------ storage variables from inherited contracts (Owned, Pausable) come before vars here --------

    // ----------------------- slot 0 ---------------------------
    // address public owner; -> from Owned

    // bool private _paused; -> from Pausable

    // 11 bytes empty

    // ----------------------- slot 1 ---------------------------

    /// @dev Name of the Merkle Distributor
    string public name;

    // ----------------------- slot 2 ---------------------------

    /// @dev allow list for allowed root proposer addresses
    mapping(address => bool) internal _proposers;

    // ----------------------- slot 3 ---------------------------

    /// @dev allow list for allowed root proposer addresses
    mapping(address => bool) internal _approvers;

    // ----------------------- slot 4-6 ---------------------------

    /// @dev merkle root data related to current cycle (proposed and approved).
    /// @dev timestamp & publishBlock = data from last publish.
    // with custom getter to return whole struct at once instead of default solidity getter splitting it into tuple
    MerkleCycle internal _currentMerkleCycle;

    // ----------------------- slot 7-9 ---------------------------

    /// @dev merkle root data related to pending cycle (proposed but not yet approved).
    /// @dev timestamp & publishBlock = data from last propose.
    // with custom getter to return whole struct at once instead of default solidity getter splitting it into tuple
    MerkleCycle internal _pendingMerkleCycle;

    // ----------------------- slot 10 ---------------------------

    /// @notice merkle root of the previous cycle
    bytes32 public previousMerkleRoot;

    // ----------------------- slot 11 ---------------------------

    /// @notice total claimed amount per user address and fToken. user => positionId => claimed amount
    mapping(address => mapping(bytes32 => uint256)) public claimed;

    // ----------------------- slot 12 ---------------------------

    /// @notice Data of cycle rewards
    Reward[] internal rewards;

    // ----------------------- slot 13 ---------------------------

    /// @notice data of distributions
    Distribution[] internal distributions;

    // ----------------------- slot 14 ---------------------------

    /// @notice allow list for rewards distributors
    mapping(address => bool) public rewardsDistributor;

    // ----------------------- slot 15 ---------------------------

    /// @notice Number of cycles to distribute rewards
    uint40 public cyclesPerDistribution;

    /// @notice Duration of each distribution in blocks
    uint40 public blocksPerDistribution;

    /// @notice Start block of the next cycle
    uint40 public startBlockOfNextCycle;

    /// @notice Whether to pull tokens from distributor or not
    bool public pullFromDistributor;

    constructor(address owner_, address rewardToken_) Constants(rewardToken_) Owned(owner_) {}
}
Owned.sol 44 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

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

    /*//////////////////////////////////////////////////////////////
                            OWNERSHIP STORAGE
    //////////////////////////////////////////////////////////////*/

    address public owner;

    modifier onlyOwner() virtual {
        require(msg.sender == owner, "UNAUTHORIZED");

        _;
    }

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(address _owner) {
        owner = _owner;

        emit OwnershipTransferred(address(0), _owner);
    }

    /*//////////////////////////////////////////////////////////////
                             OWNERSHIP LOGIC
    //////////////////////////////////////////////////////////////*/

    function transferOwnership(address newOwner) public virtual onlyOwner {
        owner = newOwner;

        emit OwnershipTransferred(msg.sender, newOwner);
    }
}

Read Contract

TOKEN 0x82bfefc8 → address
blocksPerDistribution 0x57593651 → uint40
claimed 0x0f2d940b → uint256
currentMerkleCycle 0xc81eec66 → tuple
cyclesPerDistribution 0x9cfc7e83 → uint40
encodeClaim 0xf3bd53bf → bytes, bytes32
getCycleReward 0x04585ac7 → tuple
getCycleRewards 0xa7e7344a → tuple[]
getDistributionForEpoch 0xdcf6de81 → tuple
getDistributions 0x02aa6318 → tuple[]
hasPendingRoot 0x2f37a774 → bool
isApprover 0x6d218e48 → bool
isProposer 0x74ec29a0 → bool
name 0x06fdde03 → string
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
pendingMerkleCycle 0x2274c5cd → tuple
previousMerkleRoot 0xcaf3791e → bytes32
pullFromDistributor 0x0fc1bf68 → bool
rewardsDistributor 0x059527bf → bool
startBlockOfNextCycle 0xda528f3e → uint40
totalCycleRewards 0xfc5e231e → uint256
totalDistributions 0x163db71b → uint256

Write Contract 14 functions

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

approveRoot 0x35c1dd99
bytes32 root_
bytes32 contentHash_
uint40 cycle_
uint40 startBlock_
uint40 endBlock_
bulkClaim 0xcb8e0fbb
tuple[] claims_
claim 0xbe5013dc
address recipient_
uint256 cumulativeAmount_
uint8 positionType_
bytes32 positionId_
uint256 cycle_
bytes32[] merkleProof_
bytes metadata_
distributeRewards 0x59974e38
uint256 amount_
pause 0x8456cb59
No parameters
proposeRoot 0x4617c06a
bytes32 root_
bytes32 contentHash_
uint40 cycle_
uint40 startBlock_
uint40 endBlock_
setStartBlockOfNextCycle 0x864683d4
uint40 startBlockOfNextCycle_
spell 0x82bc4aaf
address[] targets_
bytes[] calldatas_
toggleRewardsDistributor 0x70feb52a
address distributor_
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
updateApprover 0x1563461b
address approver_
bool isApprover_
updateDistributionConfig 0xa8a9bbfd
bool pullFromDistributor_
uint40 blocksPerDistribution_
uint40 cyclesPerDistribution_
updateProposer 0x9d01a27d
address proposer_
bool isProposer_

Recent Transactions

No transactions found for this address