Forkchoice Ethereum Mainnet

Address Contract Verified

Address 0xd32050abDeBCC751D7889BC928BE807812337e8d
Balance 0 ETH
Nonce 1
Code Size 22516 bytes
Indexed Transactions 0 (1 on-chain, 1.1% indexed)
External Etherscan · Sourcify

Contract Bytecode

22516 bytes
0x6080604052600436106103355760003560e01c8063838626a6116101ab578063be3da249116100f7578063e325057a11610095578063f0fa55a91161006f578063f0fa55a914610a25578063f5188c2714610a45578063f825b0a114610a65578063fec6b96414610a7c57600080fd5b8063e325057a146109da578063e941fa78146109fa578063ef1a0a7114610a0f57600080fd5b8063ce0fcd8c116100d1578063ce0fcd8c1461096f578063d547741f14610985578063d6cac145146109a5578063da3691ee146109c557600080fd5b8063be3da24914610923578063c1419def1461093a578063cd4c69021461094f57600080fd5b806393f1a40b11610164578063a217fddf1161013e578063a217fddf1461083d578063ab673c8514610852578063ad5c4648146108db578063aed869b81461090357600080fd5b806393f1a40b14610783578063971d5a64146107d75780639753485b146107f757600080fd5b8063838626a6146106d157806383d9fbfc146106f157806389a30271146107115780638dbdbe6d1461073957806391d148541461074c578063935c327c1461076c57600080fd5b806338c76fcf116102855780635502127c116102235780636147c499116101fd5780636147c49914610657578063694a7ce7146106775780636ed937211461069757806371fc0752146106b157600080fd5b80635502127c1461060c57806359ef0dd01461062c5780635e87dce61461064257600080fd5b8063401e52f91161025f578063401e52f91461054a57806344a982e71461056a5780635117e3381461058a57806354346b66146105cd57600080fd5b806338c76fcf146104fe5780633a1aa88d1461051e5780633e032a3b1461053457600080fd5b80631df4ccfc116102f25780632b2fb8c5116102cc5780632b2fb8c51461047e5780632f2ff15d1461049e57806336568abe146104be57806337a468b2146104de57600080fd5b80631df4ccfc14610422578063248a9ca31461043857806329dcb0cf1461046857600080fd5b806301a4cbbf1461033a57806301ffc9a7146103635780630fe0b211146103935780631694505e146103a8578063195199f6146103e05780631cb44dfc14610402575b600080fd5b34801561034657600080fd5b5061035061019081565b6040519081526020015b60405180910390f35b34801561036f57600080fd5b5061038361037e366004614f46565b610a9c565b604051901515815260200161035a565b34801561039f57600080fd5b5061035060fa81565b3480156103b457600080fd5b506007546103c8906001600160a01b031681565b6040516001600160a01b03909116815260200161035a565b3480156103ec57600080fd5b506104006103fb366004614f70565b610ad3565b005b34801561040e57600080fd5b5061040061041d366004614f9e565b610b07565b34801561042e57600080fd5b50610350600a5481565b34801561044457600080fd5b50610350610453366004614f70565b60009081526020819052604090206001015490565b34801561047457600080fd5b50610350600c5481565b34801561048a57600080fd5b50610400610499366004614fbb565b610b8b565b3480156104aa57600080fd5b506104006104b9366004614fdd565b610f92565b3480156104ca57600080fd5b506104006104d9366004614fdd565b610fbc565b3480156104ea57600080fd5b506104006104f9366004614f70565b61103a565b34801561050a57600080fd5b50610350610519366004614fbb565b611308565b34801561052a57600080fd5b506103506103e881565b34801561054057600080fd5b5061035060095481565b34801561055657600080fd5b50610350610565366004614f70565b6113d3565b34801561057657600080fd5b506103c8610585366004614fbb565b611498565b34801561059657600080fd5b506103506105a5366004614fdd565b60009182526003602090815260408084206001600160a01b0393909316845291905290205490565b3480156105d957600080fd5b506105ed6105e8366004614fbb565b6114d9565b604080516001600160a01b03909316835260208301919091520161035a565b34801561061857600080fd5b506006546103c8906001600160a01b031681565b34801561063857600080fd5b506103506101f481565b34801561064e57600080fd5b50610350601281565b34801561066357600080fd5b50610350610672366004614f70565b61151f565b34801561068357600080fd5b5061040061069236600461500d565b611691565b3480156106a357600080fd5b50600b546103839060ff1681565b3480156106bd57600080fd5b506104006106cc366004614fbb565b61220c565b3480156106dd57600080fd5b506005546103c8906001600160a01b031681565b3480156106fd57600080fd5b5061040061070c36600461505a565b612693565b34801561071d57600080fd5b506103c873a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b610400610747366004615086565b61290c565b34801561075857600080fd5b50610383610767366004614fdd565b6132c1565b34801561077857600080fd5b50610350624f1a0081565b34801561078f57600080fd5b506107c261079e366004614fdd565b60036020908152600092835260408084209091529082529020805460019091015482565b6040805192835260208301919091520161035a565b3480156107e357600080fd5b506104006107f236600461500d565b6132ea565b34801561080357600080fd5b50610350610812366004614fdd565b60009182526003602090815260408084206001600160a01b0393909316845291905290206001015490565b34801561084957600080fd5b50610350600081565b34801561085e57600080fd5b5061087261086d366004614f70565b613306565b604080519c15158d526001600160a01b03909b1660208d0152998b019890985260608a0196909652608089019490945260a088019290925260c087015260e08601521515610100850152151561012084015215156101408301526101608201526101800161035a565b3480156108e757600080fd5b506103c873c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b34801561090f57600080fd5b5061040061091e3660046150bf565b61338c565b34801561092f57600080fd5b5061035062278d0081565b34801561094657600080fd5b50610350600681565b34801561095b57600080fd5b5061040061096a366004614f9e565b61366c565b34801561097b57600080fd5b5061035060085481565b34801561099157600080fd5b506104006109a0366004614fdd565b613731565b3480156109b157600080fd5b506104006109c036600461505a565b613756565b3480156109d157600080fd5b506103506139c9565b3480156109e657600080fd5b506104006109f5366004615110565b6139f1565b348015610a0657600080fd5b50610400614006565b348015610a1b57600080fd5b5061035061271081565b348015610a3157600080fd5b50610400610a40366004614f70565b6141ba565b348015610a5157600080fd5b50610400610a6036600461513c565b61423d565b348015610a7157600080fd5b506103506276a70081565b348015610a8857600080fd5b50610350610a97366004614f70565b6142b2565b60006001600160e01b03198216637965db0b60e01b1480610acd57506301ffc9a760e01b6001600160e01b03198316145b92915050565b604051602001610ae290615159565b60405160208183030381529060405280519060200120610b01816142e0565b50600c55565b604051602001610b1690615159565b60405160208183030381529060405280519060200120610b35816142e0565b600680546001600160a01b0319166001600160a01b0384169081179091556040519081527f3df77beb5db05fcdd70a30fc8adf3f83f9501b68579455adbd100b8180940394906020015b60405180910390a15050565b600260015403610bb65760405162461bcd60e51b8152600401610bad9061517e565b60405180910390fd5b6002600181905550600060048381548110610bd357610bd36151b5565b6000918252602080832060408051610180810182526009909402909101805460ff808216151586526001600160a01b036101009283900481168787015260018401548786015260028401546060880152600380850154608089015260048086015460a08a015260058087015460c08b0152600687015460e08b015260078701548086161515878c0152958604851615156101208b01526201000090950490931615156101408901526008909401546101608801528a885292855283872033808952955295839020905492516370a0823160e01b815294965094879492909116926370a0823192610cd292016001600160a01b0391909116815260200190565b602060405180830381865afa158015610cef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1391906151cb565b1015610d6c5760405162461bcd60e51b815260206004820152602260248201527f4552525f494e53554646494349454e545f4445504f5349544f525f42414c414e604482015261434560f01b6064820152608401610bad565b828160010154610d7c91906151fa565b60018083019182556000868152600360209081526040808320338452909152908190208454815592549290910191909155820151610dbb9084906151fa565b60408301526004805483919086908110610dd757610dd76151b5565b60009182526020918290208351600992909202018054928401516001600160a81b0319909316911515610100600160a81b031916919091176101006001600160a01b0393841681029190911782556040808501516001840155606085015160028401556080850151600384015560a085015160048085019190915560c086015160058086019190915560e08701516006860155838701516007860180546101208a01516101408b015161ffff1990921693151561ff001916939093179215159096029190911762ff00001916620100009515159590950294909417909355610160909501516008909301929092555490516323b872dd60e01b815233938101939093523060248401526044830186905216906323b872dd906064016020604051808303816000875af1158015610f11573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f359190615212565b610f515760405162461bcd60e51b8152600401610bad9061522f565b604051838152849033907f1218bdf10f37b284cb97026689d22fbef478fa738afc47812ebbd129805b28df9060200160405180910390a35050600180555050565b600082815260208190526040902060010154610fad816142e0565b610fb783836142ed565b505050565b6001600160a01b038116331461102c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610bad565b6110368282614371565b5050565b60405160200161104990615159565b60405160208183030381529060405280519060200120611068816142e0565b60006004838154811061107d5761107d6151b5565b600091825260209182902060408051610180810182526009909302909101805460ff808216151585526001600160a01b036101009283900416958501959095526001820154928401929092526002810154606084015260038101546080840152600481015460a0840152600581015460c0840152600681015460e08401526007810154808516151583850152918204841615156101208401526201000090910490921615801561014083015260089092015461016082015291506111795760405162461bcd60e51b815260206004820152601360248201527211549497d193d491d25391d7d4d51054951151606a1b6044820152606401610bad565b600083815260026020526040902054610160820151106111cf5760405162461bcd60e51b81526020600482015260116024820152704552525f4e4f5f4445504f5349544f525360781b6044820152606401610bad565b6001610140820152600061012082015260048054829190859081106111f6576111f66151b5565b600091825260208083208451600993909302018054918501516001600160a81b0319909216921515610100600160a81b031916929092176101006001600160a01b0390921682021782556040808501516001840155606085015160028401556080850151600384015560a0850151600484015560c0850151600584015560e085015160068401558185015160078401805461012088015161014089015161ffff1990921693151561ff001916939093179215159094029190911762ff000019166201000093151593909302929092179091556101609384015160089092019190915591830151915185917fdc9dd0cb0b6b99ae9633a8b330e5a4343834074afe5d49c849ccdfa10582fb1491a3505050565b600042808311801590611326575061132362278d00846151fa565b81105b156113565761271061133a6101f48261525c565b6113449086615273565b61134e9190615292565b915050610acd565b8061136462278d00856151fa565b1115801561137d575061137a624f1a00846151fa565b81105b156113915761271061133a6101908261525c565b8061139f624f1a00856151fa565b111580156113b857506113b56276a700846151fa565b81105b156113cb5761271061133a60fa8261525c565b509192915050565b6000806113df8361151f565b90506000600660009054906101000a90046001600160a01b03166001600160a01b03166398e96f566040518163ffffffff1660e01b8152600401602060405180830381865afa158015611436573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061145a91906151cb565b60066114676012806151fa565b611471919061525c565b61147c90600a615398565b6114869084615273565b6114909190615292565b949350505050565b60008281526002602052604081208054839081106114b8576114b86151b5565b60009182526020909120600290910201546001600160a01b03169392505050565b600260205281600052604060002081815481106114f557600080fd5b6000918252602090912060029091020180546001909101546001600160a01b039091169250905082565b60008060048381548110611535576115356151b5565b600091825260209182902060408051610180810182526009909302909101805460ff808216151585526001600160a01b03610100928390041695850186905260018301549385019390935260028201546060850181905260038301546080860152600483015460a0860152600583015460c0860152600683015460e0860152600783015480851615158387015291820484161515610120860152620100009091049092161515610140840152600801546101608301529092509073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4719810161161357509392505050565b600654604051630c2d365160e31b81526001600160a01b0383811660048301526024820185905290911690636169b28890604401602060405180830381865afa158015611664573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061168891906151cb565b95945050505050565b6002600154036116b35760405162461bcd60e51b8152600401610bad9061517e565b60026001819055506000600485815481106116d0576116d06151b5565b600091825260209182902060408051610180810182526009909302909101805460ff808216151585526001600160a01b036101009283900416958501959095526001820154928401929092526002810154606084015260038101546080840152600481015460a0840152600581015460c0840152600681015460e08401526007810154808516151583850181905292810485161515610120850152620100009004909316151561014083015260089092015461016082015291506117ce5760405162461bcd60e51b815260206004820152601560248201527411549497d5d2551211149055d7d11254d050931151605a1b6044820152606401610bad565b60008581526003602090815260408083203384529091529020600181015485111561183b5760405162461bcd60e51b815260206004820152601d60248201527f4552525f494e53554646494349454e545f555345525f42414c414e43450000006044820152606401610bad565b6005546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015611884573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118a891906151cb565b9050858110156118fa5760405162461bcd60e51b815260206004820152601e60248201527f4552525f464f5247455f42414c414e43455f494e53554646494349454e5400006044820152606401610bad565b60e0830151600061190b8883611308565b9050611917818961525c565b600a5461192491906151fa565b600a55600554604051630dc6eaf760e21b81526004810183905260009182916001600160a01b039091169063371babdc90602401600060405180830381865afa158015611975573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261199d91908101906154de565b9092509050886119ad83826143d6565b6119f95760405162461bcd60e51b815260206004820152601860248201527f4552525f494e56414c49445f52454445454d5f544f4b454e00000000000000006044820152606401610bad565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa158015611a40573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a6491906151cb565b90508b8960400151611a76919061525c565b60408a0152600480548a91908f908110611a9257611a926151b5565b60009182526020918290208351600992909202018054928401516001600160a81b0319909316911515610100600160a81b031916919091176101006001600160a01b0390931683021781556040830151600180830191909155606084015160028301556080840151600383015560a0840151600483015560c0840151600583015560e084015160068301558284015160078301805461012087015161014088015161ffff1990921693151561ff001916939093179215159095029190911762ff0000191662010000941515949094029390931790925561016090920151600890920191909155880154611b86908d9061525c565b600189810191825560008f8152600360209081526040808320338452909152908190208b5481559254929091019190915560055490516323ddc5ab60e01b8152600481018790526001600160a01b03909116906323ddc5ab90602401600060405180830381600087803b158015611bfc57600080fd5b505af1158015611c10573d6000803e3d6000fd5b505050506000805b85518110156120eb576000868281518110611c3557611c356151b5565b602002602001015190506000868381518110611c5357611c536151b5565b60209081029190910101516040516370a0823160e01b815230600482015290915081906001600160a01b038416906370a0823190602401602060405180830381865afa158015611ca7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ccb91906151cb565b1015611d195760405162461bcd60e51b815260206004820152601b60248201527f4552525f494e53554646494349454e545f46554e44535f4d494e5400000000006044820152606401610bad565b856001600160a01b0316826001600160a01b0316146120c957600754611d4c906001600160a01b03848116911683614437565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc260006001600160a01b0384168214801590611d8e5750816001600160a01b0316886001600160a01b031614155b15611d9b57506003611d9f565b5060025b60608167ffffffffffffffff811115611dba57611dba6153a4565b604051908082528060200260200182016040528015611de3578160200160208202803683370190505b5090508481600081518110611dfa57611dfa6151b5565b6001600160a01b03928316602091820292909201015285811690841614801590611e365750826001600160a01b0316896001600160a01b031614155b15611ea8578281600181518110611e4f57611e4f6151b5565b60200260200101906001600160a01b031690816001600160a01b0316815250508881600281518110611e8357611e836151b5565b60200260200101906001600160a01b031690816001600160a01b031681525050611edd565b8881600181518110611ebc57611ebc6151b5565b60200260200101906001600160a01b031690816001600160a01b0316815250505b60075460405163d06ca61f60e01b81526000916001600160a01b03169063d06ca61f90611f109088908690600401615586565b600060405180830381865afa158015611f2d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611f55919081019061559f565b905060006103e86009546103e8611f6c919061525c565b83611f7860018861525c565b81518110611f8857611f886151b5565b6020026020010151611f9a9190615273565b611fa49190615292565b90506000600760009054906101000a90046001600160a01b03166001600160a01b03166338ed173988848733600c5442611fde91906151fa565b6040518663ffffffff1660e01b8152600401611ffe9594939291906155d4565b6000604051808303816000875af115801561201d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612045919081019061559f565b9050835181511461208a5760405162461bcd60e51b815260206004820152600f60248201526e11549497d4d5d05417d19052531151608a1b6044820152606401610bad565b8060018251612099919061525c565b815181106120a9576120a96151b5565b60200260200101518a6120bc91906151fa565b99505050505050506120d6565b6120d381856151fa565b93505b505080806120e390615610565b915050611c18565b508a8110156121355760405162461bcd60e51b815260206004820152601660248201527511549497d352539253555357d05353d5539517d3d55560521b6044820152606401610bad565b6040516370a0823160e01b815230600482015260009083906001600160a01b038616906370a0823190602401602060405180830381865afa15801561217e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121a291906151cb565b6121ac919061525c565b90506121c26001600160a01b038516338361451c565b6040518e815233907f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b93699060200160405180910390a250506001805550505050505050505050505050565b60026001540361222e5760405162461bcd60e51b8152600401610bad9061517e565b600260018190555060006004838154811061224b5761224b6151b5565b6000918252602080832060408051610180810182526009909402909101805460ff808216151586526001600160a01b03610100928390041686860152600183015486850152600283015460608701526003808401546080880152600484015460a0880152600584015460c0880152600684015460e088015260078401548083161515848901529283048216151561012088015262010000909204811615156101408701526008909201546101608601528886528352818520338652909252909220600b5491935091166123585760405162461bcd60e51b815260206004820152601560248201527411549497d5d2551211149055d7d11254d050931151605a1b6044820152606401610bad565b60018101546005546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156123a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123c991906151cb565b10156124215760405162461bcd60e51b815260206004820152602160248201527f4552525f494e53554646494349454e545f434f4e54524143545f42414c414e436044820152604560f81b6064820152608401610bad565b82816001015410156124755760405162461bcd60e51b815260206004820152601d60248201527f4552525f494e53554646494349454e545f555345525f42414c414e43450000006044820152606401610bad565b828160010154612485919061525c565b600180830191825560008681526003602090815260408083203384529091529081902084548155925492909101919091558201516124c490849061525c565b604083015260048054839190869081106124e0576124e06151b5565b60009182526020918290208351600992909202018054928401516001600160a81b0319909316911515610100600160a81b031916919091176101006001600160a01b0393841681029190911782556040808501516001840155606085015160028401556080850151600384015560a085015160048085019190915560c086015160058086019190915560e08701516006860155838701516007860180546101208a01516101408b015161ffff1990921693151561ff001916939093179215159096029190911762ff000019166201000095151595909502949094179093556101609095015160089093019290925554905163a9059cbb60e01b8152339381019390935260248301869052169063a9059cbb906044016020604051808303816000875af1158015612614573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126389190615212565b6126545760405162461bcd60e51b8152600401610bad9061522f565b60405183815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a25050600180555050565b6040516020016126a290615159565b604051602081830303815290604052805190602001206126c1816142e0565b600854821061270a5760405162461bcd60e51b81526020600482015260156024820152744552525f4e4f4e4558495354454e545f464f52474560581b6044820152606401610bad565b60006004838154811061271f5761271f6151b5565b600091825260209182902060408051610180810182526009909302909101805460ff808216151585526001600160a01b03610100928390041695850195909552600182015492840192909252600281015460608401526003810154608084015260048082015460a0850152600582015460c0850152600682015460e0850152600782015483810486161515610120860152620100009004909416151561014084015260080154610160830152861515908201528154909250829190859081106127ea576127ea6151b5565b60009182526020918290208351600992909202018054848401516001600160a81b0319909116921515610100600160a81b031916929092176101006001600160a01b0390931683021781556040808501516001830155606085015160028301556080850151600383015560a0850151600483015560c0850151600583015560e085015160068301558285015160078301805461012088015161014089015161ffff1990921693151561ff001916939093179215159095029190911762ff0000191662010000941515949094029390931790925561016090930151600890930192909255815186151581529081018590527fbc0d94592e0d8071e25abcc983358bc95a2c75b9ea9eed5071ac910effadc31b91015b60405180910390a150505050565b60026001540361292e5760405162461bcd60e51b8152600401610bad9061517e565b60026001556001600160a01b03811661297c5760405162461bcd60e51b815260206004820152601060248201526f4552525f5a45524f5f4144445245535360801b6044820152606401610bad565b600060048481548110612991576129916151b5565b600091825260209182902060408051610180810182526009909302909101805460ff808216151585526001600160a01b036101009283900416958501959095526001820154928401929092526002810154606084015260038101546080840152600481015460a0840152600581015460c0840152600681015460e084015260078101548085161515838501529182048416151561012084018190526201000090920490931615156101408301526008909201546101608201529150612a8f5760405162461bcd60e51b815260206004820152601460248201527311549497d1115413d4d25517d11254d05093115160621b6044820152606401610bad565b60008481526003602090815260408083206001600160a01b03861684529091529020815115612e1457348414612b075760405162461bcd60e51b815260206004820152601860248201527f4552525f494e56414c49445f414d4f554e545f56414c554500000000000000006044820152606401610bad565b8054600090612b179034906151fa565b90508483608001511115612b6d5760405162461bcd60e51b815260206004820181905260248201527f4552525f414d4f554e545f42454c4f575f4d494e434f4e545249425554494f4e6044820152606401610bad565b8260a00151811115612bc15760405162461bcd60e51b815260206004820181905260248201527f4552525f414d4f554e545f41424f56455f4d4158434f4e545249425554494f4e6044820152606401610bad565b8260c00151348460600151612bd691906151fa565b1115612bf45760405162461bcd60e51b8152600401610bad90615629565b8154612c019034906151fa565b82556060830151612c139034906151fa565b60608401526004805484919088908110612c2f57612c2f6151b5565b600091825260208083208451600993909302018054858301516001600160a81b0319909116931515610100600160a81b031916939093176101006001600160a01b03948516810291909117825560408087015160018085019190915560608801516002808601919091556080890151600386015560a089015160048087019190915560c08a0151600587015560e08a01516006870155848a01516007870180546101208d01516101408e015161ffff1990921693151561ff001916939093179215159097029190911762ff00001916620100009615159690960295909517909455610160909801516008909401939093558c8652868452808620815180830183528c871681523481870181815283548088018555938a529689209151929099020180546001600160a01b03191691909616178555925193909101929092558051630d0e30db60e41b8152905173c02aaa39b223fe8d0a0e5c4f27ead9083c756cc29463d0e30db09490938381019391929182900301818588803b158015612db557600080fd5b505af1158015612dc9573d6000803e3d6000fd5b50506040518881526001600160a01b03881693503392507f8752a472e571a816aea92eec8dae9baf628e840f4929fbcc2d155e6233ff68a7915060200160405180910390a3506132b6565b8160c00151848360600151612e2991906151fa565b1115612e475760405162461bcd60e51b8152600401610bad90615629565b60208201516040516370a0823160e01b815233600482015285906001600160a01b038316906370a0823190602401602060405180830381865afa158015612e92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612eb691906151cb565b1015612efc5760405162461bcd60e51b81526020600482015260156024820152744552525f4e4f545f454e4f5547485f544f4b454e5360581b6044820152606401610bad565b604051636eb1769f60e11b815233600482015230602482015285906001600160a01b0383169063dd62ed3e90604401602060405180830381865afa158015612f48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f6c91906151cb565b1015612fba5760405162461bcd60e51b815260206004820152601a60248201527f4552525f494e53554646494349454e545f414c4c4f57414e43450000000000006044820152606401610bad565b8154600090612fca9087906151fa565b905080846080015111156130205760405162461bcd60e51b815260206004820181905260248201527f4552525f414d4f554e545f42454c4f575f4d494e434f4e545249425554494f4e6044820152606401610bad565b8360a001518111156130745760405162461bcd60e51b815260206004820181905260248201527f4552525f414d4f554e545f41424f56455f4d4158434f4e545249425554494f4e6044820152606401610bad565b60c08401516040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa1580156130bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130e191906151cb565b11156130ff5760405162461bcd60e51b8152600401610bad90615629565b80835560608401516131129087906151fa565b6060850152600480548591908990811061312e5761312e6151b5565b600091825260208083208451600993909302018054858301516001600160a81b0319909116931515610100600160a81b031916939093176101006001600160a01b03948516810291909117825560408087015160018085019190915560608801516002808601919091556080890151600386015560a0890151600486015560c0890151600586015560e08901516006860155838901516007860180546101208c01516101408d015161ffff1990921693151561ff001916939093179215159096029190911762ff00001916620100009515159590950294909417909355610160909701516008909301929092558c855280835281852082518084019093528b851683528284018d81528154808901835591875293909520915194020180546001600160a01b03191693831693909317835551919092015561327390831633308961454c565b6040518681526001600160a01b0386169033907f8752a472e571a816aea92eec8dae9baf628e840f4929fbcc2d155e6233ff68a79060200160405180910390a350505b505060018055505050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6132f48484610b8b565b61330084848484611691565b50505050565b6004818154811061331657600080fd5b600091825260209091206009909102018054600182015460028301546003840154600485015460058601546006870154600788015460089098015460ff8089169a506001600160a01b03610100998a9004169997989697959694959394929380821693810482169262010000909104909116908c565b60405160200161339b90615159565b604051602081830303815290604052805190602001206133ba816142e0565b6000841180156133ca5750600083115b80156133d65750600082115b6134105760405162461bcd60e51b815260206004820152600b60248201526a282924a1a2afa2a92927a960a91b6044820152606401610bad565b8515613482576001600160a01b03851673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2146134825760405162461bcd60e51b815260206004820152601c60248201527f494e434f52524543545f434f4e545249425554494f4e5f544f4b454e000000006044820152606401610bad565b60046040518061018001604052808815158152602001876001600160a01b0316815260200160008152602001600081526020018681526020018581526020018481526020014281526020016000151581526020016000151581526020016000151581526020016000815250908060018154018082558091505060019003906000526020600020906009020160009091909190915060008201518160000160006101000a81548160ff02191690831515021790555060208201518160000160016101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160010155606082015181600201556080820151816003015560a0820151816004015560c0820151816005015560e082015181600601556101008201518160070160006101000a81548160ff0219169083151502179055506101208201518160070160016101000a81548160ff0219169083151502179055506101408201518160070160026101000a81548160ff02191690831515021790555061016082015181600801555050600854600161361e91906151fa565b6008556004546001600160a01b0386169061363b9060019061525c565b6040517f301cbd0a789bea7fa3e0daaf79d09daadff7305100772dd9c8e02df19286561690600090a3505050505050565b60405160200161367b90615159565b6040516020818303038152906040528051906020012061369a816142e0565b6001600160a01b0382166136e35760405162461bcd60e51b815260206004820152601060248201526f4552525f414444524553535f5a45524f60801b6044820152606401610bad565b600780546001600160a01b0319166001600160a01b0384169081179091556040519081527f5935abca017ffeaa3066a015c5baa00f64dc3add561ea6fbbbb324c7f7290c5090602001610b7f565b60008281526020819052604090206001015461374c816142e0565b610fb78383614371565b60405160200161376590615159565b60405160208183030381529060405280519060200120613784816142e0565b60085482106137cd5760405162461bcd60e51b81526020600482015260156024820152744552525f4e4f4e4558495354454e545f464f52474560581b6044820152606401610bad565b6000600483815481106137e2576137e26151b5565b600091825260209182902060408051610180810182526009909302909101805460ff808216151585526001600160a01b03610100928390041695850195909552600182015492840192909252600281015460608401526003810154608084015260048082015460a0850152600582015460c0850152600682015460e085015260078201548086161515938501939093526201000090920490931615156101408301526008909201546101608201528515156101208201528154909250829190859081106138b1576138b16151b5565b60009182526020918290208351600992909202018054848401516001600160a81b0319909116921515610100600160a81b031916929092176101006001600160a01b0390931683021781556040808501516001830155606085015160028301556080850151600383015560a0850151600483015560c0850151600583015560e085015160068301558285015160078301805461012088015161014089015161ffff1990921693151561ff001916939093179215159095029190911762ff0000191662010000941515949094029390931790925561016090930151600890930192909255815186151581529081018590527ffefdcc9f03b51b31523cc9504dc9242a6b4091c5a6a1928b48ee6c9742c3526991016128fe565b6040516020016139d890615159565b6040516020818303038152906040528051906020012081565b600260015403613a135760405162461bcd60e51b8152600401610bad9061517e565b6002600155604051613a2790602001615159565b60405160208183030381529060405280519060200120613a46816142e0565b6000849050600060048281548110613a6057613a606151b5565b600091825260209182902060408051610180810182526009909302909101805460ff808216151585526001600160a01b036101009283900416958501959095526001820154928401929092526002810154606084015260038101546080840152600481015460a0840152600581015460c0840152600681015460e084015260078101548085161515838501529182048416151561012084015262010000909104909216151561014082018190526008909201546101608201529150613b675760405162461bcd60e51b815260206004820152601760248201527f4552525f464f5247494e475f4e4f545f535441525445440000000000000000006044820152606401610bad565b80610120015115613bba5760405162461bcd60e51b815260206004820152601960248201527f4552525f4445504f534954535f4e4f545f44495341424c4544000000000000006044820152606401610bad565b60008511613c0a5760405162461bcd60e51b815260206004820152601c60248201527f434f4e5452494255544f52535f544f5f4d494e545f49535f5a45524f000000006044820152606401610bad565b6000613c1760018761525c565b826101600151613c2791906151fa565b600084815260026020526040902054909150613c4460018261525c565b8210610140840152808210613c6157613c5e60018261525c565b91505b61016083015160009081905b848111613cc5576000878152600260205260409020805482908110613c9457613c946151b5565b90600052602060002090600202016001015482613cb191906151fa565b915080613cbd81615610565b915050613c6d565b60008211613d155760405162461bcd60e51b815260206004820152601860248201527f4552525f414d4f554e545f544f5f464f5247455f5a45524f00000000000000006044820152606401610bad565b6000613d25876020015184614584565b905089811015613d705760405162461bcd60e51b815260206004820152601660248201527511549497d352539253555357d05353d5539517d3d55560521b6044820152606401610bad565b86610160015191505b858211158015613d8857508284105b15613ebc576000888152600260205260408120805484908110613dad57613dad6151b5565b60009182526020808320600292830201548c84526003825260408085206001600160a01b039092168086529183528085208e86529390925290832080549194509192919086908110613e0157613e016151b5565b90600052602060002090600202016001015490508087613e2191906151fa565b8254909750613e3190829061525c565b8255600086613e408387615273565b613e4a9190615292565b905080836001016000828254613e6091906151fa565b909155505060405182815281906001600160a01b038616907f3adf92e6f32049ba19076ba71279a2a6c4a61bf23125ec746c2814b4b03ec16e9060200160405180910390a3505050508180613eb490615610565b925050613d79565b613ec78660016151fa565b6101608801526060870151613edd90859061525c565b6060880152604087018051829190613ef69083906151fa565b905250600480548891908a908110613f1057613f106151b5565b60009182526020918290208351600992909202018054928401516001600160a81b0319909316911515610100600160a81b031916919091176101006001600160a01b0390931683021781556040830151600180830191909155606084015160028301556080840151600383015560a0840151600483015560c0840151600583015560e084015160068301558284015160078301805461012087015161014088015161ffff1990921693151561ff001916939093179215159095029190911762ff00001916620100009415159490940293909317909255610160909201516008909201919091558055505050505050505050505050565b6002600154036140285760405162461bcd60e51b8152600401610bad9061517e565b600260015560405161403c90602001615159565b6040516020818303038152906040528051906020012061405b816142e0565b600a546005546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156140a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140ca91906151cb565b10156141185760405162461bcd60e51b815260206004820152601860248201527f4552525f494e53554646494349454e545f42414c414e434500000000000000006044820152606401610bad565b600a8054600090915560055460405163a9059cbb60e01b8152336004820152602481018390526001600160a01b039091169063a9059cbb906044016020604051808303816000875af1158015614172573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141969190615212565b6141b25760405162461bcd60e51b8152600401610bad9061522f565b505060018055565b6040516020016141c990615159565b604051602081830303815290604052805190602001206141e8816142e0565b6141f560026103e8615292565b82106142375760405162461bcd60e51b81526020600482015260116024820152700a69892a0a0828e8abea89e9ebe90928e9607b1b6044820152606401610bad565b50600955565b60405160200161424c90615159565b6040516020818303038152906040528051906020012061426b816142e0565b600b805460ff191683151590811790915560405160ff909116151581527f1b6e07ede0355a4b5ba751d1419e61ea34da85f5680d9bcca27bed4a4228853290602001610b7f565b6000600482815481106142c7576142c76151b5565b9060005260206000209060090201600201549050919050565b6142ea8133614b59565b50565b6142f782826132c1565b611036576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561432d3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b61437b82826132c1565b15611036576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000805b835181101561443057826001600160a01b03168482815181106143ff576143ff6151b5565b60200260200101516001600160a01b03160361441e5760019150614430565b8061442881615610565b9150506143da565b5092915050565b604051636eb1769f60e11b81523060048201526001600160a01b038381166024830152600091839186169063dd62ed3e90604401602060405180830381865afa158015614488573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144ac91906151cb565b6144b691906151fa565b6040516001600160a01b03851660248201526044810182905290915061330090859063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614bbd565b6040516001600160a01b038316602482015260448101829052610fb790849063a9059cbb60e01b906064016144e5565b6040516001600160a01b03808516602483015283166044820152606481018290526133009085906323b872dd60e01b906084016144e5565b600654604051630c2d365160e31b81526001600160a01b038481166004830152602482018490526000928392911690636169b28890604401602060405180830381865afa1580156145d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145fd91906151cb565b90506060806000600660009054906101000a90046001600160a01b03166001600160a01b0316632e4d3a636040518163ffffffff1660e01b8152600401600060405180830381865afa158015614657573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261467f919081019061564a565b9194509250905060005b8351811015614a545760008482815181106146a6576146a66151b5565b602002602001015190506000670de0b6b3a76400008584815181106146cd576146cd6151b5565b60200260200101518a6146e09190615273565b6146ea9190615292565b905060008a6001600160a01b0316836001600160a01b03160361470e575080614a24565b8a60006001600160a01b03821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21480159061475b57506001600160a01b03851673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc214155b905060008161476b57600261476e565b60035b60ff16905060008167ffffffffffffffff81111561478e5761478e6153a4565b6040519080825280602002602001820160405280156147b7578160200160208202803683370190505b50905083816000815181106147ce576147ce6151b5565b60200260200101906001600160a01b031690816001600160a01b031681525050821561483d5773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28160018151811061481c5761481c6151b5565b60200260200101906001600160a01b031690816001600160a01b0316815250505b868161484a60018561525c565b8151811061485a5761485a6151b5565b6001600160a01b03928316602091820292909201015260075460405163d06ca61f60e01b8152600092919091169063d06ca61f9061489e908a908690600401615586565b600060405180830381865afa1580156148bb573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526148e3919081019061559f565b9050806148f160018561525c565b81518110614901576149016151b5565b6020908102919091010151600754909650614929906001600160a01b03878116911689614437565b81516007546009546001600160a01b03909116906338ed1739908a906103e890614953908261525c565b61495d908c615273565b6149679190615292565b8630600c544261497791906151fa565b6040518663ffffffff1660e01b81526004016149979594939291906155d4565b6000604051808303816000875af11580156149b6573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526149de919081019061559f565b5114614a1e5760405162461bcd60e51b815260206004820152600f60248201526e11549497d4d5d05417d19052531151608a1b6044820152606401610bad565b50505050505b600554614a3e906001600160a01b03858116911683614437565b5050508080614a4c90615610565b915050614689565b50600554604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015614a9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ac391906151cb565b9050600082614ad28388615273565b614adc9190615292565b600554604051633fe9067560e01b8152600481018390529192506001600160a01b031690633fe90675906024016020604051808303816000875af1158015614b28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b4c91906151cb565b9998505050505050505050565b614b6382826132c1565b61103657614b7b816001600160a01b03166014614c8f565b614b86836020614c8f565b604051602001614b979291906156e3565b60408051601f198184030181529082905262461bcd60e51b8252610bad91600401615758565b6000614c12826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614e329092919063ffffffff16565b805190915015610fb75780806020019051810190614c309190615212565b610fb75760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610bad565b60606000614c9e836002615273565b614ca99060026151fa565b67ffffffffffffffff811115614cc157614cc16153a4565b6040519080825280601f01601f191660200182016040528015614ceb576020820181803683370190505b509050600360fc1b81600081518110614d0657614d066151b5565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110614d3557614d356151b5565b60200101906001600160f81b031916908160001a9053506000614d59846002615273565b614d649060016151fa565b90505b6001811115614ddc576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110614d9857614d986151b5565b1a60f81b828281518110614dae57614dae6151b5565b60200101906001600160f81b031916908160001a90535060049490941c93614dd58161578b565b9050614d67565b508315614e2b5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610bad565b9392505050565b60606114908484600085856001600160a01b0385163b614e945760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610bad565b600080866001600160a01b03168587604051614eb091906157a2565b60006040518083038185875af1925050503d8060008114614eed576040519150601f19603f3d011682016040523d82523d6000602084013e614ef2565b606091505b5091509150614f02828286614f0d565b979650505050505050565b60608315614f1c575081614e2b565b825115614f2c5782518084602001fd5b8160405162461bcd60e51b8152600401610bad9190615758565b600060208284031215614f5857600080fd5b81356001600160e01b031981168114614e2b57600080fd5b600060208284031215614f8257600080fd5b5035919050565b6001600160a01b03811681146142ea57600080fd5b600060208284031215614fb057600080fd5b8135614e2b81614f89565b60008060408385031215614fce57600080fd5b50508035926020909101359150565b60008060408385031215614ff057600080fd5b82359150602083013561500281614f89565b809150509250929050565b6000806000806080858703121561502357600080fd5b8435935060208501359250604085013561503c81614f89565b9396929550929360600135925050565b80151581146142ea57600080fd5b6000806040838503121561506d57600080fd5b82356150788161504c565b946020939093013593505050565b60008060006060848603121561509b57600080fd5b833592506020840135915060408401356150b481614f89565b809150509250925092565b600080600080600060a086880312156150d757600080fd5b85356150e28161504c565b945060208601356150f281614f89565b94979496505050506040830135926060810135926080909101359150565b60008060006060848603121561512557600080fd5b505081359360208301359350604090920135919050565b60006020828403121561514e57600080fd5b8135614e2b8161504c565b6020808252600b908201526a08498828696bea69a92a8960ab1b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156151dd57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000821982111561520d5761520d6151e4565b500190565b60006020828403121561522457600080fd5b8151614e2b8161504c565b60208082526013908201527211549497d514905394d1915497d19052531151606a1b604082015260600190565b60008282101561526e5761526e6151e4565b500390565b600081600019048311821515161561528d5761528d6151e4565b500290565b6000826152af57634e487b7160e01b600052601260045260246000fd5b500490565b600181815b808511156152ef5781600019048211156152d5576152d56151e4565b808516156152e257918102915b93841c93908002906152b9565b509250929050565b60008261530657506001610acd565b8161531357506000610acd565b816001811461532957600281146153335761534f565b6001915050610acd565b60ff841115615344576153446151e4565b50506001821b610acd565b5060208310610133831016604e8410600b8410161715615372575081810a610acd565b61537c83836152b4565b8060001904821115615390576153906151e4565b029392505050565b6000614e2b83836152f7565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156153e3576153e36153a4565b604052919050565b600067ffffffffffffffff821115615405576154056153a4565b5060051b60200190565b600082601f83011261542057600080fd5b81516020615435615430836153eb565b6153ba565b82815260059290921b8401810191818101908684111561545457600080fd5b8286015b8481101561547857805161546b81614f89565b8352918301918301615458565b509695505050505050565b600082601f83011261549457600080fd5b815160206154a4615430836153eb565b82815260059290921b840181019181810190868411156154c357600080fd5b8286015b8481101561547857805183529183019183016154c7565b600080604083850312156154f157600080fd5b825167ffffffffffffffff8082111561550957600080fd5b6155158683870161540f565b9350602085015191508082111561552b57600080fd5b5061553885828601615483565b9150509250929050565b600081518084526020808501945080840160005b8381101561557b5781516001600160a01b031687529582019590820190600101615556565b509495945050505050565b8281526040602082015260006114906040830184615542565b6000602082840312156155b157600080fd5b815167ffffffffffffffff8111156155c857600080fd5b61149084828501615483565b85815284602082015260a0604082015260006155f360a0830186615542565b6001600160a01b0394909416606083015250608001529392505050565b600060018201615622576156226151e4565b5060010190565b60208082526007908201526604d41585f4341560cc1b604082015260600190565b60008060006060848603121561565f57600080fd5b835167ffffffffffffffff8082111561567757600080fd5b6156838783880161540f565b9450602086015191508082111561569957600080fd5b506156a686828701615483565b925050604084015190509250925092565b60005b838110156156d25781810151838201526020016156ba565b838111156133005750506000910152565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161571b8160178501602088016156b7565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161574c8160288401602088016156b7565b01602801949350505050565b60208152600082518060208401526157778160408501602087016156b7565b601f01601f19169190910160400192915050565b60008161579a5761579a6151e4565b506000190190565b600082516157b48184602087016156b7565b919091019291505056fea264697066735822122084605a599f029f0451835f3d4f4c6b3e59e514d179d5ca3904720470d703982a64736f6c634300080f0033

Verified Source Code Full Match

Compiler: v0.8.15+commit.e14f2714 EVM: london Optimization: Yes (200 runs)
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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");
        }
    }
}
IERC20.sol 25 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;

interface IERC20 {
    event Approval(address indexed _src, address indexed _dst, uint256 _amount);

    function totalSupply() external view returns (uint256);

    function balanceOf(address _whom) external view returns (uint256);

    function allowance(address _src, address _dst)
        external
        view
        returns (uint256);

    function approve(address _dst, uint256 _amount) external returns (bool);

    function transfer(address _dst, uint256 _amount) external returns (bool);

    function transferFrom(
        address _src,
        address _dst,
        uint256 _amount
    ) external returns (bool);
}
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);
}
IUniswapV2Router.sol 53 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;

interface IUniswapV2Router {
    function swapExactTokensForTokens(
        //amount of tokens we are sending in
        uint256 amountIn,
        //the minimum amount of tokens we want out of the trade
        uint256 amountOutMin,
        //list of token addresses we are going to trade in.  this is necessary to calculate amounts
        address[] calldata path,
        //this is the address we are going to send the output tokens to
        address to,
        //the last time that the trade is valid for
        uint256 deadline
    ) external returns (uint256[] memory amounts);

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

    function quote(
        uint256 amountA,
        uint256 reserveA,
        uint256 reserveB
    ) external pure returns (uint256 amountB);

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

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

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

    function getAmountsIn(uint256 amountOut, address[] calldata path)
        external
        view
        returns (uint256[] memory amounts);
}
IWETH.sol 10 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;

import "./IERC20.sol";

interface IWETH is IERC20 {
    function deposit() external payable;

    function withdraw(uint256 wad) external;
}
Strings.sol 75 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IDynaset.sol 22 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;

import "./IERC20.sol";

interface IDynaset is IERC20 {
    function joinDynaset(uint256 _amount) external returns (uint256);

    function exitDynaset(uint256 _amount) external;

    function calcTokensForAmount(uint256 _amount)
        external
        view
        returns (address[] memory tokens, uint256[] memory amounts);
        
    function getTokenAmounts()
        external
        view
        returns (address[] memory tokens, uint256[] memory amounts);

    function getCurrentTokens() external view returns (address[] memory tokens);
}
ReentrancyGuard.sol 63 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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 functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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);
            }
        }
    }
}
IDynasetTvlOracle.sol 13 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;

interface IDynasetTvlOracle {
    function dynasetTvlUsdc() external view returns (uint256 total_usd);

    function tokenUsdcValue(address _tokenIn, uint256 _amount) external view returns (uint256);

    function dynasetUsdcValuePerShare() external view returns (uint256);

    function dynasetTokenUsdcRatios() external view returns (address[] memory, uint256[] memory, uint256);
    
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}
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;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
ForgeV1.sol 614 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;

import "@openzeppelin/contracts/access/AccessControl.sol";
import {IWETH} from "./interfaces/IWETH.sol";
import "./interfaces/IUniswapV2Router.sol";
import {IDynaset} from "./interfaces/IDynaset.sol";
import "./interfaces/IDynasetTvlOracle.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract ForgeV1 is AccessControl , ReentrancyGuard {
    using SafeERC20 for IERC20;
    /* ==========  Structs  ========== */

    struct ForgeInfo {
        bool isEth;
        address contributionToken;
        uint256 dynasetLp;
        uint256 totalContribution;
        uint256 minContribution;
        uint256 maxContribution;
        uint256 maxCap;
        uint256 contributionPeriod;
        bool withdrawEnabled;
        bool depositEnabled;
        bool forging;
        uint256 nextForgeContributorIndex;
    }

    struct UserInfo {
        uint256 depositAmount;
        uint256 dynasetsOwed;
    }

    struct Contributor {
        address contributorAddress;
        uint256 contributedAmount;
    }

    /* ==========  Constants  ========== */
    bytes32 public constant BLACK_SMITH = keccak256(abi.encode("BLACK_SMITH"));

    address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
    address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

    uint256 public constant USDC_DECIMALS = 6;
    uint256 public constant DYNASET_DECIMALS = 18;

    uint256 public constant SLIPPAGE_FACTOR = 1000;
    uint256 public constant WITHDRAW_FEE_FACTOR = 10000;
    uint256 public constant WITHDRAW_FEE_5_PERCENT = 500;
    uint256 public constant WITHDRAW_FEE_4_PERCENT = 400;
    uint256 public constant WITHDRAW_FEE_2_5_PERCENT = 250;

    uint256 public constant WITHDRAW_FEE_5_PERCENT_PERIOD = 30 days;
    uint256 public constant WITHDRAW_FEE_4_PERCENT_PERIOD = 60 days;
    uint256 public constant WITHDRAW_FEE_2_5_PERCENT_PERIOD = 90 days;

    /* ==========  State  ========== */
    
    // forgeID => Contributor
    mapping(uint256 => Contributor[]) public contributors; 
    mapping(uint256 => mapping(address => UserInfo)) public userInfo;

    ForgeInfo[] public forgeInfo;

    IDynaset public dynaset;
    IDynasetTvlOracle public dynasetTvlOracle;
    address public uniswapV2Router = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;

    uint256 public totalForges;
    uint256 public slippage = 50;
    uint256 public totalFee;
    bool    public lpWithdraw;

    uint256 public deadline;

    /* ==========  Events  ========== */

    event LogForgeAddition(uint256 indexed forgeId, address indexed contributionToken);
    event Deposited(address indexed caller, address indexed user, uint256 amount);
    event ForgingStarted(uint256 indexed forgeId, uint256 indexed nextForgeContributorIndex);
    event DepositedLP(address indexed user, uint256 indexed forgeId, uint256 amount);
    event Withdraw(address indexed user, uint256 amount);
    event Redeemed(address indexed user, uint256 amount);
    event Forged(address indexed user, uint256 indexed amount, uint256 price);
    event SetlpWithdraw(bool lpWithdraw);
    event ForgeWithdrawEnabled(bool status, uint256 forgeId);
    event ForgeDepositEnabled(bool status, uint256 forgeId);
    event OracleUpdated(address oracle);
    event RouterUpgraded(address router);

    /* ==========  Constructor  ========== */

    constructor(
        address _blacksmith,
        address _dynaset,
        address _dynasetTvlOracle
    ) {
        require(
            _blacksmith != address(0)
            && _dynaset != address(0)
            && _dynasetTvlOracle != address(0),
            "ERR_ZERO_ADDRESS"
        );
        dynaset = IDynaset(_dynaset);
        dynasetTvlOracle = IDynasetTvlOracle(_dynasetTvlOracle);
        _setupRole(BLACK_SMITH, _blacksmith);
    }

    /* ==========  External Functions  ========== */

    function createForge(
        bool isEth,
        address contributionToken,
        uint256 mincontrib,
        uint256 maxcontrib,
        uint256 maxcapital
    ) external onlyRole(BLACK_SMITH) {
        require(
            mincontrib > 0 && maxcontrib > 0 && maxcapital > 0,
            "PRICE_ERROR"
        );
        if(isEth) {
            require(contributionToken == WETH, "INCORRECT_CONTRIBUTION_TOKEN");
        }
        forgeInfo.push(
            ForgeInfo({
                isEth: isEth,
                dynasetLp: 0,
                contributionToken: contributionToken,
                totalContribution: 0,
                minContribution: mincontrib,
                maxContribution: maxcontrib,
                maxCap: maxcapital,
                contributionPeriod: block.timestamp,
                withdrawEnabled: false,
                depositEnabled: false,
                forging: false,
                nextForgeContributorIndex: 0
            })
        );
        totalForges = totalForges + 1;
        emit LogForgeAddition(forgeInfo.length - 1, contributionToken);
    }

    function startForging(uint256 forgeId) external onlyRole(BLACK_SMITH) {
        ForgeInfo memory forge = forgeInfo[forgeId];
        require(!forge.forging, "ERR_FORGING_STARTED");
        require(
            forge.nextForgeContributorIndex < contributors[forgeId].length,
            "ERR_NO_DEPOSITORS"
        );
        forge.forging = true;
        forge.depositEnabled = false;
        forgeInfo[forgeId] = forge;
        emit ForgingStarted(forgeId, forge.nextForgeContributorIndex);
    }

    //select forge to mint to assign the dynaset tokens to it
    //mint from the contributions set to that forge
    function forgeFunction(
        uint256 forgeId,
        uint256 contributorsToMint,
        uint256 minimumAmountOut
    ) external nonReentrant onlyRole(BLACK_SMITH) {
        uint256 _forgeId = forgeId; // avoid stack too deep
        ForgeInfo memory forge = forgeInfo[_forgeId];
        require(forge.forging, "ERR_FORGING_NOT_STARTED");
        require(!forge.depositEnabled, "ERR_DEPOSITS_NOT_DISABLED");

        require(contributorsToMint > 0, "CONTRIBUTORS_TO_MINT_IS_ZERO");
        uint256 finalIndex = forge.nextForgeContributorIndex + (contributorsToMint - 1);
        uint256 totalContributors = contributors[_forgeId].length;
        forge.forging = (finalIndex < totalContributors - 1);
        if (finalIndex >= totalContributors) {
            finalIndex = totalContributors - 1;
        }

        uint256 forgedAmount;
        uint256 amountToForge;
        uint256 i;

        for (i = forge.nextForgeContributorIndex; i <= finalIndex; i++) {
            amountToForge += contributors[_forgeId][i].contributedAmount;
        }
        require(amountToForge > 0, "ERR_AMOUNT_TO_FORGE_ZERO");
        uint256 tokensMinted = _mintDynaset(forge.contributionToken, amountToForge);
        require(tokensMinted >= minimumAmountOut, "ERR_MINIMUM_AMOUNT_OUT");
        
        for (i = forge.nextForgeContributorIndex; i <= finalIndex && forgedAmount < amountToForge; i++) {
            address contributorAddress = contributors[_forgeId][i].contributorAddress;
            UserInfo storage user = userInfo[_forgeId][contributorAddress];
            uint256 userContributedAmount = contributors[_forgeId][i].contributedAmount;
            
            forgedAmount += userContributedAmount;
            user.depositAmount = user.depositAmount - userContributedAmount;
            uint256 userTokensMinted = tokensMinted * userContributedAmount / amountToForge;
            user.dynasetsOwed += userTokensMinted;
            emit Forged(
                contributorAddress,
                userTokensMinted,
                userContributedAmount
            );
        }
        forge.nextForgeContributorIndex = finalIndex + 1;
        forge.totalContribution = forge.totalContribution - forgedAmount;
        forge.dynasetLp += tokensMinted;
        forgeInfo[_forgeId] = forge;
    }

    // deposits funds to the forge and the contribution is added to the to address.
    // the to address will receive the dynaset LPs.
    function deposit(
        uint256 forgeId,
        uint256 amount,
        address to
    ) external nonReentrant payable {
        require(to != address(0), "ERR_ZERO_ADDRESS");
        ForgeInfo memory forge = forgeInfo[forgeId];
        require(forge.depositEnabled, "ERR_DEPOSIT_DISABLED");

        UserInfo storage user = userInfo[forgeId][to];
        if (forge.isEth) {
            require(amount == msg.value, "ERR_INVALID_AMOUNT_VALUE");

            uint256 totalContribution = user.depositAmount + msg.value;

            require(
                forge.minContribution <= amount,
                "ERR_AMOUNT_BELOW_MINCONTRIBUTION"
            );

            require(
                totalContribution <= forge.maxContribution,
                "ERR_AMOUNT_ABOVE_MAXCONTRIBUTION"
            );

            //3. `forge.maxCap` limit may be exceeded if `forge.isEth` flag is `true`.
            require(
                (forge.totalContribution + msg.value) <= forge.maxCap,
                "MAX_CAP"
            );
            //convert to weth the eth deposited to the contract
            //comment to run tests
            user.depositAmount = (user.depositAmount + msg.value);
            forge.totalContribution = (forge.totalContribution + msg.value);
            forgeInfo[forgeId] = forge;
            contributors[forgeId].push(Contributor(to, msg.value));

            IWETH(WETH).deposit{value: msg.value}();
            emit Deposited(msg.sender, to, amount);
        } else {
            require(
                (forge.totalContribution + amount) <= forge.maxCap,
                "MAX_CAP"
            );
            IERC20 tokenContribution = IERC20(forge.contributionToken);
            require(
                tokenContribution.balanceOf(msg.sender) >= amount,
                "ERR_NOT_ENOUGH_TOKENS"
            );
            require(
                tokenContribution.allowance(msg.sender, address(this)) >=
                    amount,
                "ERR_INSUFFICIENT_ALLOWANCE"
            );

            uint256 contribution = user.depositAmount + amount;

            require(
                forge.minContribution <= contribution,
                "ERR_AMOUNT_BELOW_MINCONTRIBUTION"
            );

            require(
                contribution <= forge.maxContribution,
                "ERR_AMOUNT_ABOVE_MAXCONTRIBUTION"
            );
            require(
                tokenContribution.balanceOf(address(this)) <= forge.maxCap,
                "MAX_CAP"
            );
            user.depositAmount = contribution;
            forge.totalContribution = forge.totalContribution + amount;
            forgeInfo[forgeId] = forge;
            contributors[forgeId].push(Contributor(to, amount));
            tokenContribution.safeTransferFrom(
                msg.sender,
                address(this),
                amount
            );
            emit Deposited(msg.sender, to, amount);
        }
    }

    function redeem(
        uint256 forgeId,
        uint256 amount,
        address redeemToken,
        uint256 minimumAmountOut
    ) public nonReentrant {
        ForgeInfo memory forge = forgeInfo[forgeId];
        require(forge.withdrawEnabled, "ERR_WITHDRAW_DISABLED");

        UserInfo storage user = userInfo[forgeId][msg.sender];
        //require(userbalance on dynaset)
        require(user.dynasetsOwed >= amount, "ERR_INSUFFICIENT_USER_BALANCE");

        uint256 dynasetBalance = dynaset.balanceOf(
            address(this)
        );
        require(dynasetBalance >= amount, "ERR_FORGE_BALANCE_INSUFFICIENT");
        uint256 startTime = forge.contributionPeriod;
        uint256 amountSlashed = capitalSlash(amount, startTime);
        totalFee = totalFee + (amount - amountSlashed);
        (address[] memory tokens, uint256[] memory amounts) = dynaset.calcTokensForAmount(amountSlashed);
        address _redeemToken = redeemToken; // avoid stack too deep
        require(
            _checkValidToken(tokens, _redeemToken),
            "ERR_INVALID_REDEEM_TOKEN"
        );

        uint256 initialRedeemTokenBalance = IERC20(_redeemToken).balanceOf(
            address(this)
        );
        forge.dynasetLp = forge.dynasetLp - amount;
        forgeInfo[forgeId] = forge;
        user.dynasetsOwed = user.dynasetsOwed - amount;
        userInfo[forgeId][msg.sender] = user;
        dynaset.exitDynaset(amountSlashed);
        uint256 amountOut = 0;
        for (uint256 i = 0; i < tokens.length; i++) {
            address tokenOut = tokens[i];
            uint256 amountIn = amounts[i];
            require(
                IERC20(tokenOut).balanceOf(address(this)) >= amountIn,
                "ERR_INSUFFICIENT_FUNDS_MINT"
            );
            // for all tokens execpt the redeem token Swap the tokens and
            // send them to the user address
            // if the tokenOut == redeemToken the funds will be transfered outsede this for loop
            if (tokenOut != _redeemToken) {
                IERC20(tokenOut).safeIncreaseAllowance(
                    uniswapV2Router,
                    amountIn
                );
                address wethAddress = WETH;
                uint256 pathLength;
                if (tokenOut != wethAddress && _redeemToken != wethAddress) {
                    pathLength = 3;
                } else {
                    pathLength = 2;
                }
                address[] memory path;
                path = new address[](pathLength);
                path[0] = tokenOut;
                if (tokenOut != wethAddress && _redeemToken != wethAddress) {
                    path[1] = wethAddress;
                    path[2] = _redeemToken;
                } else {
                    path[1] = _redeemToken;
                }
                uint256[] memory uniAmountsOut = IUniswapV2Router(uniswapV2Router).getAmountsOut(amountIn, path);
                uint256 minimumAmountOut_ = uniAmountsOut[pathLength - 1] 
                                            * (SLIPPAGE_FACTOR - slippage) / SLIPPAGE_FACTOR;
                //then we will call swapExactTokensForTokens
                //for the deadline we will pass in block.timestamp + deadline
                //the deadline is the latest time the trade is valid for
                uint256[] memory amountsOut = IUniswapV2Router(uniswapV2Router)
                    .swapExactTokensForTokens(
                        amountIn,
                        minimumAmountOut_,
                        path,
                        msg.sender,
                        block.timestamp + deadline
                    );
                require(amountsOut.length == path.length, "ERR_SWAP_FAILED");
                amountOut += amountsOut[amountsOut.length - 1];
            } else {
                amountOut += amountIn;
            }
        }
        require(amountOut >= minimumAmountOut, "ERR_MINIMUM_AMOUNT_OUT");
        uint256 amountToTransfer = (IERC20(_redeemToken).balanceOf(address(this)) - initialRedeemTokenBalance);
        IERC20(_redeemToken).safeTransfer(msg.sender, amountToTransfer);
        emit Redeemed(msg.sender, amount);
    }

    function setlpWithdraw(bool status) external onlyRole(BLACK_SMITH) {
        lpWithdraw = status;
        emit SetlpWithdraw(lpWithdraw);
    }

    function withdrawFee() external nonReentrant onlyRole(BLACK_SMITH) {
        require(dynaset.balanceOf(address(this)) >= totalFee, "ERR_INSUFFICIENT_BALANCE");
        uint256 feeToRedeem = totalFee;
        totalFee = 0;
        require(dynaset.transfer(msg.sender, feeToRedeem), "ERR_TRANSFER_FAILED");
    }

    function setWithdraw(bool status, uint256 forgeId) external onlyRole(BLACK_SMITH) {
        require(forgeId < totalForges, "ERR_NONEXISTENT_FORGE");
        ForgeInfo memory forge = forgeInfo[forgeId];
        forge.withdrawEnabled = status;
        forgeInfo[forgeId] = forge;
        emit ForgeWithdrawEnabled(status, forgeId);
    }

    function setDeposit(bool status, uint256 forgeId) external onlyRole(BLACK_SMITH) {
        require(forgeId < totalForges, "ERR_NONEXISTENT_FORGE");
        ForgeInfo memory forge = forgeInfo[forgeId];
        forge.depositEnabled = status;
        forgeInfo[forgeId] = forge;
        emit ForgeDepositEnabled(status, forgeId);
    }

    function setDeadline(uint256 newDeadline) external onlyRole(BLACK_SMITH) {
        deadline = newDeadline;
    }

    function upgradeUniswapV2Router(address newUniswapV2Router) external onlyRole(BLACK_SMITH) {
        require(newUniswapV2Router != address(0), "ERR_ADDRESS_ZERO");
        uniswapV2Router = newUniswapV2Router;
        emit RouterUpgraded(newUniswapV2Router);
    }

    function depositOutput(uint256 forgeId, uint256 amount) public nonReentrant {
        ForgeInfo memory forge = forgeInfo[forgeId];
        UserInfo storage user = userInfo[forgeId][msg.sender];

        require(dynaset.balanceOf(msg.sender) >= amount, "ERR_INSUFFICIENT_DEPOSITOR_BALANCE");

        user.dynasetsOwed = user.dynasetsOwed + amount;
        userInfo[forgeId][msg.sender] = user;

        forge.dynasetLp = forge.dynasetLp + amount;
        forgeInfo[forgeId] = forge;

        require(dynaset.transferFrom(msg.sender, address(this), amount), "ERR_TRANSFER_FAILED");
        emit DepositedLP(msg.sender, forgeId, amount);
    }

    function withdrawOutput(uint256 forgeId, uint256 amount) external nonReentrant {
        ForgeInfo memory forge = forgeInfo[forgeId];
        UserInfo storage user = userInfo[forgeId][msg.sender];

        require(lpWithdraw, "ERR_WITHDRAW_DISABLED");
        require(dynaset.balanceOf(address(this)) >= user.dynasetsOwed, "ERR_INSUFFICIENT_CONTRACT_BALANCE");
        require(user.dynasetsOwed >= amount, "ERR_INSUFFICIENT_USER_BALANCE");
        
        user.dynasetsOwed = user.dynasetsOwed - (amount);
        userInfo[forgeId][msg.sender] = user;

        forge.dynasetLp = forge.dynasetLp - (amount);
        forgeInfo[forgeId] = forge;

        require(dynaset.transfer(msg.sender, amount), "ERR_TRANSFER_FAILED");
        emit Withdraw(msg.sender, amount);
    }

    // the dynaset tokens are transfered from wallet to forgeContract
    // which are then redeemed to desired redeemToken
    // Did not add reEntrency Guard because both depositOutput and
    // redeem are nonReentrant 
    function redeemFromWallet(
        uint256 forgeId,
        uint256 amount,
        address redeemToken,
        uint256 minimumAmountOut
    ) external {
        depositOutput(forgeId, amount);
        redeem(forgeId, amount, redeemToken, minimumAmountOut);
    }

    function setSlippage(uint256 newSlippage) external onlyRole(BLACK_SMITH) {
        require(newSlippage < (SLIPPAGE_FACTOR / 2), "SLIPPAGE_TOO_HIGH");
        slippage = newSlippage;
    }
    
    function updateOracle(address newDynasetTvlOracle) external onlyRole(BLACK_SMITH) {
        dynasetTvlOracle = IDynasetTvlOracle(newDynasetTvlOracle);
        emit OracleUpdated(newDynasetTvlOracle);
    }

    function getUserDynasetsOwned(uint256 forgeId, address user) external view returns (uint256) {
        return userInfo[forgeId][user].dynasetsOwed;
    }

    function getUserContribution(uint256 forgeId, address user) external view returns (uint256) {
        return userInfo[forgeId][user].depositAmount;
    }

    function getForgeBalance(uint256 forgeId) external view returns (uint256) {
        return forgeInfo[forgeId].totalContribution;
    }

    function getContributor(uint256 id, uint256 index) external view returns (address) {
        return contributors[id][index].contributorAddress;
    }

    /* ==========  Public Functions  ========== */

    function calculateContributionUsdc(uint256 forgeId) public view returns (uint256 contrib) {
        ForgeInfo memory forge = forgeInfo[forgeId];
        uint256 contributionAmount = forge.totalContribution;
        address contributionToken = forge.contributionToken;
        if (contributionToken == USDC) {
            return contributionAmount;
        } else {
            return dynasetTvlOracle.tokenUsdcValue(contributionToken, contributionAmount);
        }
    }

    // withdrawal fee calculation based on contribution time
    // 0-30 days 5%
    // 31-60 days 4%
    // 61 - 90 days 2.5%
    // above 91 days 0%
    function capitalSlash(uint256 amount, uint256 contributionTime) public view returns (uint256) {
        uint256 currentTime = block.timestamp;
        if ((contributionTime <= currentTime)
        && (currentTime < contributionTime + WITHDRAW_FEE_5_PERCENT_PERIOD)) {
            return amount * (WITHDRAW_FEE_FACTOR - WITHDRAW_FEE_5_PERCENT) / WITHDRAW_FEE_FACTOR;
        }
        if ((contributionTime + WITHDRAW_FEE_5_PERCENT_PERIOD <= currentTime) 
        && (currentTime < contributionTime + WITHDRAW_FEE_4_PERCENT_PERIOD)) {
            return amount * (WITHDRAW_FEE_FACTOR - WITHDRAW_FEE_4_PERCENT) / WITHDRAW_FEE_FACTOR;
        }
        if ((contributionTime + WITHDRAW_FEE_4_PERCENT_PERIOD <= currentTime) 
        && (currentTime < contributionTime + WITHDRAW_FEE_2_5_PERCENT_PERIOD)) {
            return amount * (WITHDRAW_FEE_FACTOR - WITHDRAW_FEE_2_5_PERCENT) / WITHDRAW_FEE_FACTOR;
        }
        return amount;
    }
  
    // ! Keeping it commented to verify it is not used anywhere.
    // function getDepositors(uint256 forgeId) external view returns (address[] memory depositors) {
    //     uint256 length = contributors[forgeId].length;
    //     depositors = new address[](length);
    //     for (uint256 i = 0; i < length; i++) {
    //         depositors[i] = contributors[forgeId][i].contributorAddress;
    //     }
    // }

    // This method should multiply by 18 decimals before doing division 
    // to be sure that the outputAmount has 18 decimals precision
    function getOutputAmount(uint256 forgeId) public view returns (uint256 amount) {
        uint256 contributionUsdcValue = calculateContributionUsdc(forgeId);
        uint256 output = (contributionUsdcValue * (10**(DYNASET_DECIMALS + DYNASET_DECIMALS - USDC_DECIMALS)))
                         / dynasetTvlOracle.dynasetUsdcValuePerShare();
        return output;
    }

    /* ==========  Internal Functions  ========== */


    function _mintDynaset(address _contributionToken, uint256 contributionAmount) internal returns (uint256) {
        uint256 contributionUsdcValue = dynasetTvlOracle.tokenUsdcValue(_contributionToken, contributionAmount);
        address[] memory tokens;
        uint256[] memory ratios;
        uint256 totalUSDC;
        (tokens, ratios, totalUSDC) = dynasetTvlOracle.dynasetTokenUsdcRatios();
        for (uint256 i = 0; i < tokens.length; i++) {
            address token = tokens[i];
            uint256 amountIn = contributionAmount * ratios[i] / 1e18;
            uint256 amountOut;
            if (token == _contributionToken) {
                amountOut = amountIn;
            } else {
                address contributionToken = _contributionToken;
                bool routeOverWeth = (contributionToken != WETH && token != WETH);
                uint256 pathLength = routeOverWeth ? 3 : 2;
                address[] memory path = new address[](pathLength);
                path[0] = contributionToken;
                if (routeOverWeth) {
                    path[1] = WETH;
                }
                path[pathLength - 1] = token;

                uint256[] memory amountsOut = IUniswapV2Router(uniswapV2Router).getAmountsOut(amountIn, path);
                amountOut = amountsOut[pathLength - 1];

                IERC20(contributionToken).safeIncreaseAllowance(uniswapV2Router, amountIn);
                require(
                    IUniswapV2Router(uniswapV2Router)
                        .swapExactTokensForTokens(
                            amountIn,
                            amountOut * (SLIPPAGE_FACTOR - slippage) / SLIPPAGE_FACTOR,
                            path,
                            address(this),
                            block.timestamp + deadline
                        )
                        .length == path.length,
                    "ERR_SWAP_FAILED"
                );
            }
            IERC20(token).safeIncreaseAllowance(address(dynaset), amountOut);
        }
        uint256 totalSupply = dynaset.totalSupply();
        uint256 sharesToMint = contributionUsdcValue * totalSupply / totalUSDC;
        return dynaset.joinDynaset(sharesToMint);
    }

    function _checkValidToken(address[] memory tokens, address redeemToken) internal pure returns (bool valid) {
        for (uint256 i = 0; i < tokens.length; i++) {
            if (tokens[i] == redeemToken) {
                valid = true;
                break;
            }
        }
    }
}
AccessControl.sol 247 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

Read Contract

BLACK_SMITH 0xda3691ee → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
DYNASET_DECIMALS 0x5e87dce6 → uint256
SLIPPAGE_FACTOR 0x3a1aa88d → uint256
USDC 0x89a30271 → address
USDC_DECIMALS 0xc1419def → uint256
WETH 0xad5c4648 → address
WITHDRAW_FEE_2_5_PERCENT 0x0fe0b211 → uint256
WITHDRAW_FEE_2_5_PERCENT_PERIOD 0xf825b0a1 → uint256
WITHDRAW_FEE_4_PERCENT 0x01a4cbbf → uint256
WITHDRAW_FEE_4_PERCENT_PERIOD 0x935c327c → uint256
WITHDRAW_FEE_5_PERCENT 0x59ef0dd0 → uint256
WITHDRAW_FEE_5_PERCENT_PERIOD 0xbe3da249 → uint256
WITHDRAW_FEE_FACTOR 0xef1a0a71 → uint256
calculateContributionUsdc 0x6147c499 → uint256
capitalSlash 0x38c76fcf → uint256
contributors 0x54346b66 → address, uint256
deadline 0x29dcb0cf → uint256
dynaset 0x838626a6 → address
dynasetTvlOracle 0x5502127c → address
forgeInfo 0xab673c85 → bool, address, uint256, uint256, uint256, uint256, uint256, uint256, bool, bool, bool, uint256
getContributor 0x44a982e7 → address
getForgeBalance 0xfec6b964 → uint256
getOutputAmount 0x401e52f9 → uint256
getRoleAdmin 0x248a9ca3 → bytes32
getUserContribution 0x5117e338 → uint256
getUserDynasetsOwned 0x9753485b → uint256
hasRole 0x91d14854 → bool
lpWithdraw 0x6ed93721 → bool
slippage 0x3e032a3b → uint256
supportsInterface 0x01ffc9a7 → bool
totalFee 0x1df4ccfc → uint256
totalForges 0xce0fcd8c → uint256
uniswapV2Router 0x1694505e → address
userInfo 0x93f1a40b → uint256, uint256

Write Contract 19 functions

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

createForge 0xaed869b8
bool isEth
address contributionToken
uint256 mincontrib
uint256 maxcontrib
uint256 maxcapital
deposit 0x8dbdbe6d
uint256 forgeId
uint256 amount
address to
depositOutput 0x2b2fb8c5
uint256 forgeId
uint256 amount
forgeFunction 0xe325057a
uint256 forgeId
uint256 contributorsToMint
uint256 minimumAmountOut
grantRole 0x2f2ff15d
bytes32 role
address account
redeem 0x694a7ce7
uint256 forgeId
uint256 amount
address redeemToken
uint256 minimumAmountOut
redeemFromWallet 0x971d5a64
uint256 forgeId
uint256 amount
address redeemToken
uint256 minimumAmountOut
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setDeadline 0x195199f6
uint256 newDeadline
setDeposit 0xd6cac145
bool status
uint256 forgeId
setSlippage 0xf0fa55a9
uint256 newSlippage
setWithdraw 0x83d9fbfc
bool status
uint256 forgeId
setlpWithdraw 0xf5188c27
bool status
startForging 0x37a468b2
uint256 forgeId
updateOracle 0x1cb44dfc
address newDynasetTvlOracle
upgradeUniswapV2Router 0xcd4c6902
address newUniswapV2Router
withdrawFee 0xe941fa78
No parameters
withdrawOutput 0x71fc0752
uint256 forgeId
uint256 amount

Recent Transactions

This address has 1 on-chain transactions, but only 1.1% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →