Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xd731884eFf85E0f34AC9209119024CB2B59Ad751
Balance 0 ETH
Nonce 1
Code Size 14365 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

14365 bytes
0x608060405260043610610161575f3560e01c80637ecebe00116100cd578063a64c5f4e11610087578063c13996fe11610062578063c13996fe14610465578063d64356ab14610479578063f2fde38b14610498578063f8c8765e146104b7575f80fd5b8063a64c5f4e146103f4578063ad3cb1cc14610413578063b14a87f714610450575f80fd5b80637ecebe001461032b5780638764420014610356578063889d7624146103755780638da5cb5b14610394578063a0440e55146103c0578063a4ea2003146103d5575f80fd5b80634f1ef2861161011e5780634f1ef2861461026557806352d1902d14610278578063566887001461028c5780636f7bc9be146102ab578063715018a6146102ec5780637bacc6a514610300575f80fd5b806306d47de9146101655780630bb325c8146101865780632d6fa4b2146101b45780633118b5e2146101e15780633cca242014610200578063416a441a14610246575b5f80fd5b348015610170575f80fd5b5061018461017f36600461319e565b6104d6565b005b348015610191575f80fd5b5061019a610a66565b604080519283526020830191909152015b60405180910390f35b3480156101bf575f80fd5b506101d36101ce3660046131c8565b610b58565b6040519081526020016101ab565b3480156101ec575f80fd5b506101846101fb366004613295565b610bcf565b34801561020b575f80fd5b50603754603854610226916001600160a01b03908116911682565b604080516001600160a01b039384168152929091166020830152016101ab565b348015610251575f80fd5b506101d36102603660046131c8565b6111a2565b610184610273366004613322565b6112d0565b348015610283575f80fd5b506101d36112ef565b348015610297575f80fd5b506101846102a636600461319e565b61130a565b3480156102b6575f80fd5b506102dc6102c53660046131c8565b5f6020819052908152604090206002015460ff1681565b60405190151581526020016101ab565b3480156102f7575f80fd5b506101846115a4565b34801561030b575f80fd5b506101d361031a3660046131c8565b60016020525f908152604090205481565b348015610336575f80fd5b506101d36103453660046131c8565b603c6020525f908152604090205481565b348015610361575f80fd5b506101d36103703660046131c8565b6115b7565b348015610380575f80fd5b5061018461038f36600461336f565b61162d565b34801561039f575f80fd5b506103a861172e565b6040516001600160a01b0390911681526020016101ab565b3480156103cb575f80fd5b506101d360345481565b3480156103e0575f80fd5b506101846103ef3660046133ab565b61175c565b3480156103ff575f80fd5b506036546103a8906001600160a01b031681565b34801561041e575f80fd5b50610443604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516101ab9190613416565b34801561045b575f80fd5b506101d360355481565b348015610470575f80fd5b50610184611969565b348015610484575f80fd5b50610184610493366004613428565b611a62565b3480156104a3575f80fd5b506101846104b23660046131c8565b611d6a565b3480156104c2575f80fd5b506101846104d136600461343f565b611da7565b60365f9054906101000a90046001600160a01b03166001600160a01b03166351fb012d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610526573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061054a9190613498565b15806105bb5750603654604051634d8c928d60e11b81523360048201526001600160a01b0390911690639b19251a90602401602060405180830381865afa158015610597573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105bb9190613498565b6040518060400160405280600f81526020016e139bdd081dda1a5d195b1a5cdd1959608a1b8152509061060a5760405162461bcd60e51b81526004016106019190613416565b60405180910390fd5b50603854604080516060810190915260218082526001600160a01b03858116931692909214916137566020830139906106565760405162461bcd60e51b81526004016106019190613416565b505f811180156106745750335f908152600160205260409020548111155b60405180606001604052806037815260200161371f60379139906106ab5760405162461bcd60e51b81526004016106019190613416565b5060365f9054906101000a90046001600160a01b03166001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106fc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061072091906134b7565b6001600160a01b0316336001600160a01b03161461094a575f606460365f9054906101000a90046001600160a01b03166001600160a01b031663c35eb85f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561078b573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107af91906134d2565b60ff1660015f6107bd61172e565b6001600160a01b03166001600160a01b031681526020019081526020015f205460015f60365f9054906101000a90046001600160a01b03166001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa158015610830573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061085491906134b7565b6001600160a01b03166001600160a01b031681526020019081526020015f20546034546108819190613506565b61088b9190613506565b6108959190613519565b61089f9190613530565b6038546040516370a0823160e01b815230600482015291925082916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156108ea573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061090e919061354f565b10156040518060600160405280602581526020016137c360259139906109475760405162461bcd60e51b81526004016106019190613416565b50505b610952611f57565b5f61095d3383612003565b90508060345f8282546109709190613506565b909155505f9050610980336115b7565b90505f61098d8284613566565b90505f81116040518060400160405280602081526020017f5769746864726177616c73206f6e20686f6c642c20706c656173652077616974815250906109e65760405162461bcd60e51b81526004016106019190613416565b506038546109fe906001600160a01b0316338361228c565b610a066122eb565b604080518281526001600160a01b0387166020820152908101859052606081018490526080810183905233907f096749e8609d2bf7e60c7b936d52e47c5d4ee3ace33ae4bb602c6028051795479060a00160405180910390a25050505050565b5f8060365f9054906101000a90046001600160a01b03166001600160a01b031663ce5f94546040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ab8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610adc919061354f565b915060365f9054906101000a90046001600160a01b03166001600160a01b03166396ce07956040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b2e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b52919061354f565b90509091565b5f80805b6001600160a01b0384165f90815260208190526040902054811015610bc8576001600160a01b0384165f908152602081905260409020805482908110610ba457610ba4613579565b905f5260205f2090600202015f015482610bbe9190613566565b9150600101610b5c565b5092915050565b603654604051637df73e2760e01b81523360048201526001600160a01b0390911690637df73e2790602401602060405180830381865afa158015610c15573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c399190613498565b80610c5c5750610c4761172e565b6001600160a01b0316336001600160a01b0316145b6040518060400160405280602081526020017f4f6e6c79207369676e657220616e64206f776e657220697320616c6c6f77656481525090610cb05760405162461bcd60e51b81526004016106019190613416565b50603c5f876001600160a01b03166001600160a01b031681526020019081526020015f205481146040518060400160405280600d81526020016c496e76616c6964206e6f6e636560981b81525090610d1b5760405162461bcd60e51b81526004016106019190613416565b50603654603754603854604051636fb6c54f60e11b81526001600160a01b039384169363df6d8a9e93610d5d938a938d938d93811692169030906004016135c1565b5f6040518083038186803b158015610d73575f80fd5b505afa158015610d85573d5f803e3d5ffd5b505050505f858588868686604051602001610da596959493929190613608565b60408051601f1981840301815290829052805160209091012060365463f7b2ec0d60e01b83529092505f916001600160a01b039091169063f7b2ec0d90610df29085908d9060040161364a565b602060405180830381865afa158015610e0d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e3191906134b7565b9050876001600160a01b0316816001600160a01b03161460405180604001604052806014815260200173496e76616c69642075736572206164647265737360601b81525090610e935760405162461bcd60e51b81526004016106019190613416565b505f610e9f8689613506565b6036546040516373fd67f360e11b8152600481018390529192505f916001600160a01b039091169063e7facfe690602401602060405180830381865afa158015610eeb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f0f919061354f565b90505f60365f9054906101000a90046001600160a01b03166001600160a01b0316638357b605838b60375f015f9054906101000a90046001600160a01b031660376001015f9054906101000a90046001600160a01b03166040518563ffffffff1660e01b8152600401610f859493929190613662565b602060405180830381865afa158015610fa0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fc4919061354f565b90508060355f828254610fd79190613566565b909155505f9050610fe88385613506565b905061106b8c60365f9054906101000a90046001600160a01b03166001600160a01b0316630e0bfb496040518163ffffffff1660e01b8152600401602060405180830381865afa15801561103e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611062919061354f565b8c848f8d612343565b5f8a600181111561107e5761107e61358d565b036111025760385460365460408051630f91594160e21b815290516110fd936001600160a01b03908116931691633e4565049160048083019260209291908290030181865afa1580156110d3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110f791906134b7565b8b61228c565b61116b565b60018a60018111156111165761111661358d565b0361116b5760375460365460408051630f91594160e21b8152905161116b936001600160a01b03908116931691633e4565049160048083019260209291908290030181865afa1580156110d3573d5f803e3d5ffd5b6001600160a01b038c165f908152603c6020526040812080549161118e83613699565b919050555050505050505050505050505050565b5f80805b6001600160a01b0384165f90815260208190526040902054811015610bc85760365f9054906101000a90046001600160a01b03166001600160a01b031663563cd6396040518163ffffffff1660e01b8152600401602060405180830381865afa158015611215573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611239919061354f565b6001600160a01b0385165f90815260208190526040902080548390811061126257611262613579565b905f5260205f209060020201600101544361127d9190613506565b106112c8576001600160a01b0384165f9081526020819052604090208054829081106112ab576112ab613579565b905f5260205f2090600202015f0154826112c59190613566565b91505b6001016111a6565b6112d8612734565b6112e1826127d8565b6112eb82826127e0565b5050565b5f6112f861289c565b505f805160206136ff83398151915290565b60365f9054906101000a90046001600160a01b03166001600160a01b03166351fb012d6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561135a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061137e9190613498565b15806113ef5750603654604051634d8c928d60e11b81523360048201526001600160a01b0390911690639b19251a90602401602060405180830381865afa1580156113cb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113ef9190613498565b6040518060400160405280600f81526020016e139bdd081dda1a5d195b1a5cdd1959608a1b815250906114355760405162461bcd60e51b81526004016106019190613416565b50603854604080516060810190915260238082526001600160a01b03858116931692909214916136dc6020830139906114815760405162461bcd60e51b81526004016106019190613416565b5061148a611f57565b6114a2336038546001600160a01b03169030846128e5565b335f9081526020819052604081206002015460ff16151590036114d7576114d56114cc6039612924565b6039903361292e565b505b335f8181526020818152604080832081518083018352868152438185019081528254600180820185558488528688209351600292830290940193845591519282019290925595855201805460ff1916851790559290529081208054839290611540908490613566565b925050819055508060345f8282546115589190613566565b9091555050604080518281526001600160a01b038416602082015233917fa21288bdd948f634bcd5a8bfc9825db1b01914f370ef82149e123b7c8dc3b65b910160405180910390a25050565b6115ac61294d565b6115b55f61297f565b565b5f80805b6001600160a01b0384165f90815260208190526040902060010154811015610bc8576001600160a01b0384165f90815260208190526040902060010180548290811061160957611609613579565b905f5260205f2090600202015f0154826116239190613566565b91506001016115bb565b60365f9054906101000a90046001600160a01b03166001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa15801561167d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116a191906134b7565b6001600160a01b0316336001600160a01b031614806116d857506116c361172e565b6001600160a01b0316336001600160a01b0316145b6040518060400160405280600e81526020016d139bdd08185d5d1a1bdc9a5e995960921b8152509061171d5760405162461bcd60e51b81526004016106019190613416565b506117298383836129ef565b505050565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b603654603754603854604051636fb6c54f60e11b81526001600160a01b039384169363df6d8a9e9361179d93889333938b93811692169030906004016135c1565b5f6040518083038186803b1580156117b3575f80fd5b505afa1580156117c5573d5f803e3d5ffd5b50506036546040516373fd67f360e11b8152600481018790525f93506001600160a01b03909116915063e7facfe690602401602060405180830381865afa158015611812573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611836919061354f565b603654603754603854604051638357b60560e01b81529394505f936001600160a01b0393841693638357b6059361187b9388938b939283169290911690600401613662565b602060405180830381865afa158015611896573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118ba919061354f565b90508060355f8282546118cd9190613566565b909155505f90506118de8387613506565b90506119613360365f9054906101000a90046001600160a01b03166001600160a01b0316630e0bfb496040518163ffffffff1660e01b8152600401602060405180830381865afa158015611934573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611958919061354f565b87848a89612343565b505050505050565b60365f9054906101000a90046001600160a01b03166001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119b9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119dd91906134b7565b6001600160a01b0316336001600160a01b03161480611a1457506119ff61172e565b6001600160a01b0316336001600160a01b0316145b6040518060400160405280600e81526020016d139bdd08185d5d1a1bdc9a5e995960921b81525090611a595760405162461bcd60e51b81526004016106019190613416565b506115b5611f57565b60365f9054906101000a90046001600160a01b03166001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ab2573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ad691906134b7565b6001600160a01b0316336001600160a01b03161480611b0d5750611af861172e565b6001600160a01b0316336001600160a01b0316145b6040518060400160405280600e81526020016d139bdd08185d5d1a1bdc9a5e995960921b81525090611b525760405162461bcd60e51b81526004016106019190613416565b505f81116040518060400160405280602081526020017f416d6f756e74206d7573742062652067726561746572207468616e207a65726f81525090611baa5760405162461bcd60e51b81526004016106019190613416565b506038546040516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa158015611bf1573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c15919061354f565b905060345481111560405180606001604052806028815260200161379b6028913990611c545760405162461bcd60e51b81526004016106019190613416565b50603854611c6d906001600160a01b03163330856128e5565b5f81603454611c7c9190613506565b8311611c88575f611ca0565b81603454611c969190613506565b611ca09084613506565b90508015611d2057335f8181526020818152604080832081518083018352868152438185019081528254600181810185559387528587209251600290910290920191825551908201559383529290529081208054839290611d02908490613566565b925050819055508060345f828254611d1a9190613566565b90915550505b603854604080518581526001600160a01b0390921660208301527f60d70dc2462a825f77dd1833245f3dc0a4607360e0545ed862accd28b34f5531910160405180910390a1505050565b611d7261294d565b6001600160a01b038116611d9b57604051631e4fbdf760e01b81525f6004820152602401610601565b611da48161297f565b50565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff165f81158015611dec5750825b90505f8267ffffffffffffffff166001148015611e085750303b155b905081158015611e16575080155b15611e345760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315611e5e57845460ff60401b1916600160401b1785555b5f6001600160a01b0316876001600160a01b031614156040518060600160405280602481526020016137776024913990611eab5760405162461bcd60e51b81526004016106019190613416565b50611eb587612c1a565b604080518082019091526001600160a01b038981168083528b82166020909301839052603780546001600160a01b03199081169092179055603880548216909317909255603680549092169088161790558315611f4c57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050505050565b6034545f5b611f666039612924565b8110156112eb575f611f79603983612c2b565b915050611f868184612c46565b6001600160a01b0381165f81815260016020908152604091829020548251878152918201527f417a9700f367e00643dfe33b90b0b9261163ffe2645239bcac5df430c7886828910160405180910390a26001600160a01b0381165f90815260016020526040902054611ff89084613506565b925050600101611f5c565b5f8181805b6001600160a01b0386165f9081526020819052604090205481101561225d57821561225d5760365f9054906101000a90046001600160a01b03166001600160a01b031663563cd6396040518163ffffffff1660e01b8152600401602060405180830381865afa15801561207d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120a1919061354f565b6001600160a01b0387165f9081526020819052604090208054839081106120ca576120ca613579565b905f5260205f20906002020160010154436120e59190613506565b10612255576001600160a01b0386165f90815260208190526040902080548491908390811061211657612116613579565b905f5260205f2090600202015f0154116121f7576001600160a01b0386165f90815260208190526040902080548290811061215357612153613579565b905f5260205f2090600202015f01548361216d9190613506565b6001600160a01b0387165f9081526020819052604090208054919450908290811061219a5761219a613579565b905f5260205f2090600202015f0154826121b49190613566565b6001600160a01b0387165f90815260208190526040812080549294509091839081106121e2576121e2613579565b5f918252602090912060029091020155612255565b6001600160a01b0386165f90815260208190526040902080548491908390811061222357612223613579565b905f5260205f2090600202015f015f82825461223f9190613506565b9091555061224f90508383613566565b91505f92505b600101612008565b50335f908152600160205260408120805483929061227c908490613506565b9091555090925050505b92915050565b6040516001600160a01b0383811660248301526044820183905261172991859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050612d84565b335f90815260208190526040902060010154156115b557335f908152602081905260409020600101805480612322576123226136b1565b5f8281526020812060025f19909301928302018181556001015590556122eb565b5f8460018111156123565761235661358d565b0361253a576036546037546038546040516373ca8f9d60e01b8152600481018790526001600160a01b03928316602482015290821660448201525f9291909116906373ca8f9d90606401602060405180830381865afa1580156123bb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123df919061354f565b6037546040516370a0823160e01b815230600482015291925082916001600160a01b03909116906370a0823190602401602060405180830381865afa15801561242a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061244e919061354f565b10156040518060400160405280601d81526020017f496e73756666696369656e742062616c616e636520666f722073776170000000815250906124a45760405162461bcd60e51b81526004016106019190613416565b506038546124bd906001600160a01b03168830866128e5565b6037546124d4906001600160a01b0316838361228c565b8460018111156124e6576124e661358d565b600160408051898152602081018590529081018690526001600160a01b038a16907f123d71c451370d8178d36e016eaab5782e622bb56fbad702ba3c683f238599be9060600160405180910390a450611961565b600184600181111561254e5761254e61358d565b0361196157603654603754603854604051632b8dbab360e11b8152600481018790526001600160a01b03928316602482015290821660448201525f92919091169063571b756690606401602060405180830381865afa1580156125b3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125d7919061354f565b6038546040516370a0823160e01b815230600482015291925082916001600160a01b03909116906370a0823190602401602060405180830381865afa158015612622573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612646919061354f565b10156040518060400160405280601d81526020017f496e73756666696369656e742062616c616e636520666f7220737761700000008152509061269c5760405162461bcd60e51b81526004016106019190613416565b506037546126b5906001600160a01b03168830866128e5565b6038546126cc906001600160a01b0316838361228c565b8460018111156126de576126de61358d565b5f60408051898152602081018590529081018690526001600160a01b038a16907f123d71c451370d8178d36e016eaab5782e622bb56fbad702ba3c683f238599be9060600160405180910390a450505050505050565b306001600160a01b037f000000000000000000000000d731884eff85e0f34ac9209119024cb2b59ad7511614806127ba57507f000000000000000000000000d731884eff85e0f34ac9209119024cb2b59ad7516001600160a01b03166127ae5f805160206136ff833981519152546001600160a01b031690565b6001600160a01b031614155b156115b55760405163703e46dd60e11b815260040160405180910390fd5b611da461294d565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561283a575060408051601f3d908101601f191682019092526128379181019061354f565b60015b61286257604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610601565b5f805160206136ff833981519152811461289257604051632a87526960e21b815260048101829052602401610601565b6117298383612de5565b306001600160a01b037f000000000000000000000000d731884eff85e0f34ac9209119024cb2b59ad75116146115b55760405163703e46dd60e11b815260040160405180910390fd5b6040516001600160a01b03848116602483015283811660448301526064820183905261291e9186918216906323b872dd906084016122b9565b50505050565b5f61228682612e3a565b5f61294384846001600160a01b038516612e44565b90505b9392505050565b3361295661172e565b6001600160a01b0316146115b55760405163118cdaa760e01b8152336004820152602401610601565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b5f826001811115612a0257612a0261358d565b03612ad9576037546040516370a0823160e01b815230600482015282916001600160a01b0316906370a0823190602401602060405180830381865afa158015612a4d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a71919061354f565b101560405180604001604052806012815260200171496e73756666696369656e742066756e647360701b81525090612abc5760405162461bcd60e51b81526004016106019190613416565b50603754612ad4906001600160a01b0316848361228c565b612bbf565b6001826001811115612aed57612aed61358d565b03612bbf576038546040516370a0823160e01b815230600482015282916001600160a01b0316906370a0823190602401602060405180830381865afa158015612b38573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612b5c919061354f565b101560405180604001604052806012815260200171496e73756666696369656e742066756e647360701b81525090612ba75760405162461bcd60e51b81526004016106019190613416565b50603854612bbf906001600160a01b0316848361228c565b42826001811115612bd257612bd261358d565b846001600160a01b03167f033aa488f78e1be3ecfd3789fd355616860a111828e4b30f89b16662d31c58b784604051612c0d91815260200190565b60405180910390a4505050565b612c22612e60565b611da481612ea9565b5f808080612c398686612eb1565b9097909650945050505050565b5f612c5083610b58565b90508115611729576036546035546040516307e966c360e21b8152600481018490526024810185905260448101919091525f916001600160a01b031690631fa59b0c90606401602060405180830381865afa158015612cb1573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612cd5919061354f565b90508060355f828254612ce89190613506565b90915550506001600160a01b0384165f81815260208181526040808320815180830183528681524381850181815260019384018054808601825590885295909620915160029095029091019384559351920191909155517f0e2b590499a5d6089db5b8a87d79070c419b294e1006a7e6a4f6530316beb84b91612d7691859190918252602082015260400190565b60405180910390a250505050565b5f612d986001600160a01b03841683612eda565b905080515f14158015612dbc575080806020019051810190612dba9190613498565b155b1561172957604051635274afe760e01b81526001600160a01b0384166004820152602401610601565b612dee82612ee7565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2805115612e32576117298282612f4a565b6112eb612fbc565b5f61228682612fdb565b5f82815260028401602052604081208290556129438484612fe4565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff166115b557604051631afcd79f60e31b815260040160405180910390fd5b611d72612e60565b5f8080612ebe8585612fef565b5f81815260029690960160205260409095205494959350505050565b606061294683835f612ffa565b806001600160a01b03163b5f03612f1c57604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610601565b5f805160206136ff83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f80846001600160a01b031684604051612f6691906136c5565b5f60405180830381855af49150503d805f8114612f9e576040519150601f19603f3d011682016040523d82523d5f602084013e612fa3565b606091505b5091509150612fb3858383613093565b95945050505050565b34156115b55760405163b398979f60e01b815260040160405180910390fd5b5f612286825490565b5f61294683836130ef565b5f612946838361313b565b60608147101561301f5760405163cd78605960e01b8152306004820152602401610601565b5f80856001600160a01b0316848660405161303a91906136c5565b5f6040518083038185875af1925050503d805f8114613074576040519150601f19603f3d011682016040523d82523d5f602084013e613079565b606091505b5091509150613089868383613093565b9695505050505050565b6060826130a8576130a382613161565b612946565b81511580156130bf57506001600160a01b0384163b155b156130e857604051639996b31560e01b81526001600160a01b0385166004820152602401610601565b5080612946565b5f81815260018301602052604081205461313457508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155612286565b505f612286565b5f825f01828154811061315057613150613579565b905f5260205f200154905092915050565b8051156131715780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160a01b0381168114611da4575f80fd5b5f80604083850312156131af575f80fd5b82356131ba8161318a565b946020939093013593505050565b5f602082840312156131d8575f80fd5b81356129468161318a565b634e487b7160e01b5f52604160045260245ffd5b5f82601f830112613206575f80fd5b813567ffffffffffffffff811115613220576132206131e3565b604051601f8201601f19908116603f0116810167ffffffffffffffff8111828210171561324f5761324f6131e3565b604052818152838201602001851015613266575f80fd5b816020850160208301375f918101602001919091529392505050565b803560028110613290575f80fd5b919050565b5f805f805f805f60e0888a0312156132ab575f80fd5b873567ffffffffffffffff8111156132c1575f80fd5b6132cd8a828b016131f7565b97505060208801356132de8161318a565b9550604088013594506132f360608901613282565b93506080880135925060a088013561330a8161318a565b96999598509396929591949193505060c09091013590565b5f8060408385031215613333575f80fd5b823561333e8161318a565b9150602083013567ffffffffffffffff811115613359575f80fd5b613365858286016131f7565b9150509250929050565b5f805f60608486031215613381575f80fd5b833561338c8161318a565b925061339a60208501613282565b929592945050506040919091013590565b5f805f606084860312156133bd575f80fd5b833592506133cd60208501613282565b915060408401356133dd8161318a565b809150509250925092565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f61294660208301846133e8565b5f60208284031215613438575f80fd5b5035919050565b5f805f8060808587031215613452575f80fd5b843561345d8161318a565b9350602085013561346d8161318a565b9250604085013561347d8161318a565b9150606085013561348d8161318a565b939692955090935050565b5f602082840312156134a8575f80fd5b81518015158114612946575f80fd5b5f602082840312156134c7575f80fd5b81516129468161318a565b5f602082840312156134e2575f80fd5b815160ff81168114612946575f80fd5b634e487b7160e01b5f52601160045260245ffd5b81810381811115612286576122866134f2565b8082028115828204841417612286576122866134f2565b5f8261354a57634e487b7160e01b5f52601260045260245ffd5b500490565b5f6020828403121561355f575f80fd5b5051919050565b80820180821115612286576122866134f2565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b600281106135bd57634e487b7160e01b5f52602160045260245ffd5b9052565b60c081016135cf82896135a1565b6001600160a01b03968716602083015260408201959095529285166060840152908416608083015290921660a090920191909152919050565b86815260c0810161361c60208301886135a1565b6001600160a01b039586166040830152606082019490945291909316608082015260a0019190915292915050565b828152604060208201525f61294360408301846133e8565b8481526080810161367660208301866135a1565b6001600160a01b0393841660408301529190921660609092019190915292915050565b5f600182016136aa576136aa6134f2565b5060010190565b634e487b7160e01b5f52603160045260245ffd5b5f82518060208501845e5f92019182525091905056fe4f6e6c79205553445420697320616363657074656420666f72206c6971756964697479360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc43616e6e6f74207769746864726177206d6f7265207468616e207468652062616c616e6365206f7220616d6f756e74206973207a65726f4f6e6c792055534454207769746864726177616c732061726520616c6c6f776564496e697469616c206f776e65722063616e6e6f74206265207a65726f2061646472657373436f6e74726163742062616c616e6365206578636565647320746f74616c206c6971756964697479436f6e7472616374206973206f7574206f662062616c616e63652c20747279206c61746572a26469706673582212208f3cb31ad374791d5fc57a9aff7821e33d335d19cb6c31dc4d972840311221be64736f6c634300081a0033

Verified Source Code Full Match

Compiler: v0.8.26+commit.8a97fa7a EVM: cancun Optimization: Yes (200 runs)
Enum.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

enum ConversionType {
    ntzc,
    usdt
}
Events.sol 43 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./Enum.sol";

contract Events {
    event WithdrawTransaction(
        address indexed to,
        ConversionType indexed conversionType,
        uint amount,
        uint indexed blockTimestamp
    );

    event SwapTransaction(
        address indexed userWalletAddress,
        ConversionType indexed fromToken,
        ConversionType indexed toToken,
        uint ratio,
        uint sentAmount,
        uint receivedAmount
    );

    event LiquidityAdded(address indexed investor, uint256 amount, address token);
    event LiquidityWithdrawn(address indexed investor, uint256 fullAmount, address token, uint256 requestedAmount, uint256 baseInvestment, uint256 fee);
    event PoolRebalanced(uint256 amount, address token);
    event SwapExecuted(address indexed client, address tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut, address indexed receiver, uint256 fee);
    event InvestorProfitsUpdated(address indexed investor, uint256 liquidityCounter, uint256 investorBalance);
    event InvestorProfitUpdated(address indexed investor, uint256 feeShare, uint256 blockNumber);

    event NumeratorFeesUpdate(uint value);
    event DenominatorFeesUpdate(uint value);
    event UpdateRatio(uint value);
    event UpdateNetworkFeeWallet(address indexed networkFeeWallet);
    event SwapFeePercentUpdated(uint256 newSwapFeePercent);
    event WhitelistEnabled(bool enabled);
    event MinimumLiquidityPercentageUpdated(uint8 newPercentage);
    event UpdateSigner(address indexed signer, bool value);
    event UpdateSubAdmin(address indexed subAdmin, bool value);
    event InvestorWhitelisted(address indexed investor);
    event InvestorRemovedFromWhitelist(address indexed investor);
    event AdminUpdated(address indexed admin);
    event UpdateEligibilityPeriod(uint256 indexed blocks);
}
IAccess.sol 122 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./Enum.sol";
import "./IERC20Extended.sol";

interface IAccess {
    // Function to set the numerator
    function setNumerator(uint256 value) external;

    // Function to set the denominator
    function setDenominator(uint256 value) external;

    // Function to set the swap ratio
    function setSwapRatio(uint256 _ratio) external;

    // Function to update the swap fee percent
    function updateSwapFeePercent(uint256 newSwapFeePercent) external;

    // Function to update the eligibility period
    function updateEligibilityPeriod(uint256 blocks) external;

    // Function to update the minimum liquidity percentage
    function updateMinimumLiquidityPercentage(uint8 newPercentage) external;

    // Function to update the network fee wallet
    function updateNetworkFeeWallet(address _networkFeeWallet) external;

    // Function to enable or disable the whitelist
    function enableWhitelist(bool enabled) external;

    // Function to update sub-admin status
    function updateSubAdmin(address _subAdmin, bool _value) external;

    // Function to update sign manager status
    function updateSignManager(address _signManagerAddress, bool _value)
        external;

    // Function to add investor to whitelist
    function addInvestorToWhitelist(address investor) external;

    // Function to remove investor from whitelist
    function removeInvestorFromWhitelist(address investor) external;

    // Function to check if an address is a signer
    function isSigner(address _address) external view returns (bool);

    // Function to calculate fees
    function feesCalculate(uint256 _amount) external view returns (uint256);

    // Function to getSigner
    function getSigner(bytes32 _message, bytes memory signature)
        external
        pure
        returns (address);

    // Public variables (not directly accessible but included for completeness)
    function signManagers(address) external view returns (bool);

    function subAdmin(address) external view returns (bool);

    function whitelist(address) external view returns (bool);

    function numerator() external view returns (uint256);

    function denominator() external view returns (uint256);

    function swapRatio() external view returns (uint256);

    function eligibilityPeriod() external view returns (uint256);

    function swapFeePercent() external view returns (uint256);

    function networkFeeWallet() external view returns (address);

    function minimumLiquidityPercentage() external view returns (uint8);

    function whitelistEnabled() external view returns (bool);

    function admin() external view returns (address);

    function eligibility(address) external view returns (bool);

    function convertFeesToUsdt(
        uint256 _feeAmount,
        ConversionType _conversionType,
        IERC20Extended _ntzcContract,
        IERC20Extended _usdtContract
    ) external view returns (uint256 usdtFeeAmount);

    function getInvestmentAmount(address investor)
        external
        view
        returns (uint256);


    function calculateFeeProfit(
        uint256 eligibleInvestmentAmount,
        uint256 liquidityCounter,
        uint256 totalFeesCollectedUSDT
    ) external pure returns (uint256 result);

    function ntzcAmount(
        uint256 _remainingTokenAmount,
        IERC20Extended _ntzcContract,
        IERC20Extended _usdtContract
    ) external view returns (uint256);

    function usdtAmount(
        uint256 _remainingTokenAmount,
        IERC20Extended _ntzcContract,
        IERC20Extended _usdtContract
    ) external view returns (uint256);

    function validateAllowanceAndBalance(
        ConversionType _conversionType,
        address _walletAddress,
        uint256 _amount,
        IERC20Extended _ntzcContract,
        IERC20Extended _usdtContract,
        address _adddress
    ) external view;
}
SwapTreasury.sol 512 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./InvestorStructs.sol";
import "./IAccess.sol";
import "./ErrorMessages.sol";
import "./Events.sol";
import "./Enum.sol";

contract SwapTreasury is
    Initializable,
    UUPSUpgradeable,
    OwnableUpgradeable,
    InvestorStructures
{
    using SafeERC20 for IERC20Extended;
    using ErrorMessages for *;

    uint256[50] private __gap;
    uint256 public totalLiquidityUSDT;
    uint256 public totalFeesCollectedUSDT;

    IAccess public accessContract;
    struct ContractStruct {
        IERC20Extended ntzcContract;
        IERC20Extended usdtContract;
    }

    ContractStruct public contractData;

    using EnumerableMap for EnumerableMap.UintToAddressMap;
    EnumerableMap.UintToAddressMap private investorsList;

    mapping(address => uint256) public nonces;

    modifier onlySigner() {
        require(
            accessContract.isSigner(msg.sender) || msg.sender == owner(),
            ErrorMessages.E2
        );
        _;
    }

    modifier onlyAdminOrOwner() {
        require(
            msg.sender == accessContract.admin() || msg.sender == owner(),
            ErrorMessages.E3
        );
        _;
    }

    modifier onlyWhitelisted() {
        require(
            !accessContract.whitelistEnabled() ||
                accessContract.whitelist(msg.sender),
            ErrorMessages.E4
        );
        _;
    }

    function initialize(
        address _usdt,
        address _ntzc,
        address _initialOwner,
        address _accessContract
    ) public initializer {
        require(_initialOwner != address(0), ErrorMessages.E1);
        __Ownable_init(_initialOwner);
        contractData = ContractStruct(
            IERC20Extended(_ntzc),
            IERC20Extended(_usdt)
        );
        accessContract = IAccess(_accessContract);
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        override
        onlyOwner
    {}

    function addLiquidity(address token, uint256 amount)
        external
        onlyWhitelisted
    {
        require(token == address(contractData.usdtContract), ErrorMessages.E5);
        updateAllInvestorProfits();
        contractData.usdtContract.safeTransferFrom(
            _msgSender(),
            address(this),
            amount
        );

        if (investors[_msgSender()].isInvestor == false) {
            investorsList.set(investorsList.length(), _msgSender());
        }

        investors[_msgSender()].investments.push(
            Investment(amount, block.number)
        );
        investors[_msgSender()].isInvestor = true;
        investorBalancesUSDT[msg.sender] += amount;
        totalLiquidityUSDT += amount;

        emit Events.LiquidityAdded(msg.sender, amount, token);
    }

    function withdrawLiquidity(address token, uint256 amount)
        external
        onlyWhitelisted
    {
        require(token == address(contractData.usdtContract), ErrorMessages.E6);
        require(
            amount > 0 && amount <= investorBalancesUSDT[msg.sender],
            ErrorMessages.E7
        );

        if (msg.sender != accessContract.admin()) {
            uint256 minRequiredBalance = ((totalLiquidityUSDT -
                investorBalancesUSDT[accessContract.admin()] -
                investorBalancesUSDT[owner()]) *
                accessContract.minimumLiquidityPercentage()) / 100;
            require(
                contractData.usdtContract.balanceOf(address(this)) >=
                    minRequiredBalance,
                ErrorMessages.E8
            );
        }

        updateAllInvestorProfits();
        uint256 eligibleAmount = updateInvestorInvestments(
            _msgSender(),
            amount
        );
        totalLiquidityUSDT -= eligibleAmount;
        uint256 profit = getCurrentInvestorProfits(_msgSender());
        uint256 totalAmountToWithdraw = eligibleAmount + profit;
        require(totalAmountToWithdraw > 0, ErrorMessages.E9);
        contractData.usdtContract.safeTransfer(
            msg.sender,
            totalAmountToWithdraw
        );
        withdrawFees();
        emit Events.LiquidityWithdrawn(
            msg.sender,
            totalAmountToWithdraw,
            token,
            amount,
            eligibleAmount,
            profit
        );
    }

    function getCurrentInvestorProfits(address investor)
        public
        view
        returns (uint256)
    {
        uint256 totalProfit = 0;

        for (uint256 i = 0; i < investors[investor].feeProfits.length; i++) {
            totalProfit += investors[investor].feeProfits[i].amount;
        }
        return totalProfit;
    }

    function updateAllInvestorProfits() private {
        uint256 liquidityCounter = totalLiquidityUSDT;
        for (uint256 i = 0; i < investorsList.length(); i++) {
            (, address investor) = investorsList.at(i);
            updateInvestorProfits(investor, liquidityCounter);
            emit Events.InvestorProfitsUpdated(
                investor,
                liquidityCounter,
                investorBalancesUSDT[investor]
            );
            liquidityCounter -= investorBalancesUSDT[investor];
        }
    }

    function updateAllInvestorProfitsAdmin() public onlyAdminOrOwner {
        updateAllInvestorProfits();
    }

    function updateInvestorProfits(address investor, uint256 liquidityCounter)
        private
    {
        uint256 eligibleInvestmentAmount = getInvestmentAmount(investor);
        if (
            liquidityCounter > 0
        ) {
            uint256 feeShare = accessContract.calculateFeeProfit(
                eligibleInvestmentAmount,
                liquidityCounter,
                totalFeesCollectedUSDT
            );
            totalFeesCollectedUSDT -= feeShare;
            investors[investor].feeProfits.push(
                FeeProfit(feeShare, block.number)
            );
            emit Events.InvestorProfitUpdated(investor, feeShare, block.number);
        }
    }

    function getInvestmentAmount(address investor)
            public
            view
            returns (uint256)
        {
            uint256 amount = 0;
            for (uint256 i = 0; i < investors[investor].investments.length; i++) {
                amount += investors[investor].investments[i].amount;
            }
            return amount;
        }

    function updateInvestorInvestments(address investor, uint256 amount)
        private
        returns (uint256)
    {
        uint256 remainingAmount = amount;
        uint256 eligibleBalance = 0;
        for (uint256 i = 0; i < investors[investor].investments.length; i++) {
            if (remainingAmount == 0) break;
            if (
                block.number - investors[investor].investments[i].blockNumber >=
                accessContract.eligibilityPeriod()
            ) {
                if (
                    investors[investor].investments[i].amount <= remainingAmount
                ) {
                    remainingAmount -= investors[investor]
                        .investments[i]
                        .amount;
                    eligibleBalance += investors[investor]
                        .investments[i]
                        .amount;
                    investors[investor].investments[i].amount = 0;
                } else {
                    investors[investor]
                        .investments[i]
                        .amount -= remainingAmount;
                    eligibleBalance += remainingAmount;
                    remainingAmount = 0;
                }
            }
        }
        investorBalancesUSDT[msg.sender] -= eligibleBalance;
        return eligibleBalance;
    }

    function withdrawFees() internal {
        while (investors[_msgSender()].feeProfits.length > 0) {
            investors[_msgSender()].feeProfits.pop();
        }
    }

    function rebalancePool(uint256 amount) external onlyAdminOrOwner {
        require(amount > 0, ErrorMessages.E10);

        uint256 contractBalance = contractData.usdtContract.balanceOf(
            address(this)
        );
        require(contractBalance <= totalLiquidityUSDT, ErrorMessages.E11);
        contractData.usdtContract.safeTransferFrom(
            msg.sender,
            address(this),
            amount
        );

        uint256 excessLiquidity = amount > totalLiquidityUSDT - contractBalance
            ? amount - (totalLiquidityUSDT - contractBalance)
            : 0;

        if (excessLiquidity > 0) {
            investors[msg.sender].investments.push(
                Investment(excessLiquidity, block.number)
            );
            investorBalancesUSDT[msg.sender] += excessLiquidity;
            totalLiquidityUSDT += excessLiquidity;
        }

        emit Events.PoolRebalanced(amount, address(contractData.usdtContract));
    }

    function swapDirect(
        uint256 _amount,
        ConversionType _conversionType,
        address _tokenReceiveAddress
    ) public {
        accessContract.validateAllowanceAndBalance(_conversionType, msg.sender, _amount,  contractData.ntzcContract, contractData.usdtContract, address(this));
        uint256 fees = accessContract.feesCalculate(_amount);

        uint256 feesInUSDT = accessContract.convertFeesToUsdt(
            fees,
            _conversionType,
            contractData.ntzcContract,
            contractData.usdtContract
        );
        totalFeesCollectedUSDT += feesInUSDT;

        uint256 remainingTokenAmount = _amount - fees;

        _swap(
            msg.sender,
            accessContract.swapRatio(),
            _conversionType,
            remainingTokenAmount,
            _amount,
            _tokenReceiveAddress
        );
    }

    function delegateSwap(
        bytes memory _signature,
        address _walletAddress,
        uint256 _amount,
        ConversionType _conversionType,
        uint256 _networkFee,
        address _tokenReceiveAddress,
        uint256 _nonce
    ) public onlySigner {
        require(_nonce == nonces[_walletAddress], ErrorMessages.E13);

        accessContract.validateAllowanceAndBalance(_conversionType, _walletAddress, _amount,   contractData.ntzcContract, contractData.usdtContract, address(this));

        bytes32 message = keccak256(
            abi.encode(
                _amount,
                _conversionType,
                _walletAddress,
                _networkFee,
                _tokenReceiveAddress,
                _nonce
            )
        );
        address signerAddress = accessContract.getSigner(message, _signature);
        require(signerAddress == _walletAddress, ErrorMessages.E14);
        uint256 remainingToken = _amount - _networkFee;
        uint256 fees = accessContract.feesCalculate(remainingToken);
        uint256 feesInUSDT = accessContract.convertFeesToUsdt(
            fees,
            _conversionType,
            contractData.ntzcContract,
            contractData.usdtContract
        );
        totalFeesCollectedUSDT += feesInUSDT;

        uint256 remainingTokenAmount = remainingToken - fees;

        _swap(
            _walletAddress,
            accessContract.swapRatio(),
            _conversionType,
            remainingTokenAmount,
            _amount,
            _tokenReceiveAddress
        );
        if (_conversionType == ConversionType.ntzc) {
            SafeERC20.safeTransfer(
                contractData.usdtContract,
                accessContract.networkFeeWallet(),
                _networkFee
            );
        } else if (_conversionType == ConversionType.usdt) {
            SafeERC20.safeTransfer(
                contractData.ntzcContract,
                accessContract.networkFeeWallet(),
                _networkFee
            );
        }
        nonces[_walletAddress]++;
    }

    function _swap(
        address _walletAddress,
        uint256 _swapRatio,
        ConversionType _conversionType,
        uint256 _remainingTokenAmount,
        uint256 _amount,
        address _tokenReceiveAddress
    ) internal {
        if (_conversionType == ConversionType.ntzc) {
            uint256 ntzcAmount = accessContract.ntzcAmount(
                _remainingTokenAmount,
                contractData.ntzcContract,
                contractData.usdtContract
            );
            require(
                contractData.ntzcContract.balanceOf(address(this)) >=
                    ntzcAmount,
                ErrorMessages.E15
            );

            SafeERC20.safeTransferFrom(
                contractData.usdtContract,
                _walletAddress,
                address(this),
                _amount
            );
            SafeERC20.safeTransfer(
                contractData.ntzcContract,
                _tokenReceiveAddress,
                ntzcAmount
            );
            emit Events.SwapTransaction(
                _walletAddress,
                ConversionType.usdt,
                _conversionType,
                _swapRatio,
                ntzcAmount,
                _amount
            );
        } else if (_conversionType == ConversionType.usdt) {
            uint256 usdtAmount = accessContract.usdtAmount(
                _remainingTokenAmount,
                contractData.ntzcContract,
                contractData.usdtContract
            );
            require(
                contractData.usdtContract.balanceOf(address(this)) >=
                    usdtAmount,
                ErrorMessages.E15
            );

            SafeERC20.safeTransferFrom(
                contractData.ntzcContract,
                _walletAddress,
                address(this),
                _amount
            );
            SafeERC20.safeTransfer(
                contractData.usdtContract,
                _tokenReceiveAddress,
                usdtAmount
            );
            emit Events.SwapTransaction(
                _walletAddress,
                ConversionType.ntzc,
                _conversionType,
                _swapRatio,
                usdtAmount,
                _amount
            );
        }
    }

    function _withdraw(
        address _to,
        ConversionType _conversionType,
        uint256 _amount
    ) internal {
        if (_conversionType == ConversionType.ntzc) {
            require(
                contractData.ntzcContract.balanceOf(address(this)) >= _amount,
                ErrorMessages.E16
            );
            SafeERC20.safeTransfer(contractData.ntzcContract, _to, _amount);
        } else if (_conversionType == ConversionType.usdt) {
            require(
                contractData.usdtContract.balanceOf(address(this)) >= _amount,
                ErrorMessages.E16
            );
            SafeERC20.safeTransfer(contractData.usdtContract, _to, _amount);
        }

        emit Events.WithdrawTransaction(
            _to,
            _conversionType,
            _amount,
            block.timestamp
        );
    }

    function withdrawAdmin(
        address _to,
        ConversionType _conversionType,
        uint256 _amount
    ) public onlyAdminOrOwner {
        _withdraw(_to, _conversionType, _amount);
    }
  
   function getNumeratorAndDenominator() public view returns (uint256 numerator, uint256 denominator) {
    numerator = accessContract.numerator();
    denominator = accessContract.denominator();
    return (numerator, denominator);
   }

    function getEligibleBalance(address investor)
        public
        view
        returns (uint256)
    {
        uint256 eligibleBalance = 0;
        for (uint256 i = 0; i < investors[investor].investments.length; i++) {
            if (
                block.number - investors[investor].investments[i].blockNumber >=
                accessContract.eligibilityPeriod()
            ) {
                eligibleBalance += investors[investor].investments[i].amount;
            }
        }
        return eligibleBalance;
    }
}
ErrorMessages.sol 30 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

library ErrorMessages {
    string internal constant E1 = "Initial owner cannot be zero address";
    string internal constant E2 = "Only signer and owner is allowed";
    string internal constant E3 = "Not authorized";
    string internal constant E4 = "Not whitelisted";
    string internal constant E5 = "Only USDT is accepted for liquidity";
    string internal constant E6 = "Only USDT withdrawals are allowed";
    string internal constant E7 =
        "Cannot withdraw more than the balance or amount is zero";
    string internal constant E8 =  "Contract is out of balance, try later";
    string internal constant E9 =  "Withdrawals on hold, please wait";
    string internal constant E10 = "Amount must be greater than zero";
    string internal constant E11 = "Contract balance exceeds total liquidity";
    string internal constant E12 = "Invalid address";
    string internal constant E13 = "Invalid nonce";
    string internal constant E14 = "Invalid user address";
    string internal constant E15 = "Insufficient balance for swap";
    string internal constant E16 = "Insufficient funds";
    string internal constant E17 = "Insufficient allowance or balance";
    string internal constant E18 = "Only owner, admin and sub admin can call this function";
    string internal constant E19 = "Admin cannot be zero address";
    string internal constant E20 = "Denominator cannot be zero";
    string internal constant E21 = "Same wallet address";
    string internal constant E22 = "sub admin cannot be zero address";
    string internal constant E23 = "sign manager address cannot be zero address";
    string internal constant E24 = "Investor cannot be zero address";
}
IERC20Extended.sol 8 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IERC20Extended is IERC20 {
    function decimals() external view returns (uint8);
}
InvestorStructs.sol 27 lines
// InvestorStructures.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";

contract InvestorStructures {
    struct Investment {
        uint256 amount;
        uint256 blockNumber;
    }

    struct FeeProfit {
        uint256 amount;
        uint256 blockNumber;
    }

    struct Investor {
        Investment[] investments;
        FeeProfit[] feeProfits;
        bool isInvestor;
    }
   
   
    mapping(address => Investor) public investors;
    mapping(address => uint256) public investorBalancesUSDT;
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

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

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @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 or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * 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.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @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`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

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

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

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

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

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

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

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

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
StorageSlot.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.20;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}
ERC1967Utils.sol 193 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 */
library ERC1967Utils {
    // We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
    // This will be fixed in Solidity 0.8.21. At that point we should remove these events.
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

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

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

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

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

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

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

    /**
     * @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);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

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

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}
EnumerableMap.sol 533 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableMap.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableMap.js.

pragma solidity ^0.8.20;

import {EnumerableSet} from "./EnumerableSet.sol";

/**
 * @dev Library for managing an enumerable variant of Solidity's
 * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
 * type.
 *
 * Maps have the following properties:
 *
 * - Entries are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Entries are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableMap for EnumerableMap.UintToAddressMap;
 *
 *     // Declare a set state variable
 *     EnumerableMap.UintToAddressMap private myMap;
 * }
 * ```
 *
 * The following map types are supported:
 *
 * - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
 * - `address -> uint256` (`AddressToUintMap`) since v4.6.0
 * - `bytes32 -> bytes32` (`Bytes32ToBytes32Map`) since v4.6.0
 * - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0
 * - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableMap.
 * ====
 */
library EnumerableMap {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    // To implement this library for multiple types with as little code repetition as possible, we write it in
    // terms of a generic Map type with bytes32 keys and values. The Map implementation uses private functions,
    // and user-facing implementations such as `UintToAddressMap` are just wrappers around the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit in bytes32.

    /**
     * @dev Query for a nonexistent map key.
     */
    error EnumerableMapNonexistentKey(bytes32 key);

    struct Bytes32ToBytes32Map {
        // Storage of keys
        EnumerableSet.Bytes32Set _keys;
        mapping(bytes32 key => bytes32) _values;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(Bytes32ToBytes32Map storage map, bytes32 key, bytes32 value) internal returns (bool) {
        map._values[key] = value;
        return map._keys.add(key);
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {
        delete map._values[key];
        return map._keys.remove(key);
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {
        return map._keys.contains(key);
    }

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {
        return map._keys.length();
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool, bytes32) {
        bytes32 value = map._values[key];
        if (value == bytes32(0)) {
            return (contains(map, key), bytes32(0));
        } else {
            return (true, value);
        }
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {
        bytes32 value = map._values[key];
        if (value == 0 && !contains(map, key)) {
            revert EnumerableMapNonexistentKey(key);
        }
        return value;
    }

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

    // UintToUintMap

    struct UintToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(UintToUintMap storage map, uint256 key, uint256 value) internal returns (bool) {
        return set(map._inner, bytes32(key), bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(UintToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(key)));
    }

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

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

        return result;
    }

    // UintToAddressMap

    struct UintToAddressMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
        return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(UintToAddressMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
        return (success, address(uint160(uint256(value))));
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
        return address(uint160(uint256(get(map._inner, bytes32(key)))));
    }

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

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

        return result;
    }

    // AddressToUintMap

    struct AddressToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(AddressToUintMap storage map, address key, uint256 value) internal returns (bool) {
        return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(AddressToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(AddressToUintMap storage map, address key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(uint256(uint160(key))));
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(uint256(uint160(key)))));
    }

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

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

        return result;
    }

    // Bytes32ToUintMap

    struct Bytes32ToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(Bytes32ToUintMap storage map, bytes32 key, uint256 value) internal returns (bool) {
        return set(map._inner, key, bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(Bytes32ToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, key);
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Bytes32ToUintMap storage map, bytes32 key) internal view returns (uint256) {
        return uint256(get(map._inner, key));
    }

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

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

        return result;
    }
}
EnumerableSet.sol 378 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

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

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @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.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
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].
     *
     * CAUTION: See Security Considerations above.
     */
    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);
}
ContextUpgradeable.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
OwnableUpgradeable.sol 119 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable
    struct OwnableStorage {
        address _owner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

    function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
        assembly {
            $.slot := OwnableStorageLocation
        }
    }

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

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

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    function __Ownable_init(address initialOwner) internal onlyInitializing {
        __Ownable_init_unchained(initialOwner);
    }

    function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

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

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        OwnableStorage storage $ = _getOwnableStorage();
        address oldOwner = $._owner;
        $._owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
Initializable.sol 228 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

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

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

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

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

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

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}
UUPSUpgradeable.sol 153 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.20;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC1967-compliant implementation pointing to self.
     * See {_onlyProxy}.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}

Read Contract

UPGRADE_INTERFACE_VERSION 0xad3cb1cc → string
accessContract 0xa64c5f4e → address
contractData 0x3cca2420 → address, address
getCurrentInvestorProfits 0x87644200 → uint256
getEligibleBalance 0x416a441a → uint256
getInvestmentAmount 0x2d6fa4b2 → uint256
getNumeratorAndDenominator 0x0bb325c8 → uint256, uint256
investorBalancesUSDT 0x7bacc6a5 → uint256
investors 0x6f7bc9be → bool
nonces 0x7ecebe00 → uint256
owner 0x8da5cb5b → address
proxiableUUID 0x52d1902d → bytes32
totalFeesCollectedUSDT 0xb14a87f7 → uint256
totalLiquidityUSDT 0xa0440e55 → uint256

Write Contract 11 functions

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

addLiquidity 0x56688700
address token
uint256 amount
delegateSwap 0x3118b5e2
bytes _signature
address _walletAddress
uint256 _amount
uint8 _conversionType
uint256 _networkFee
address _tokenReceiveAddress
uint256 _nonce
initialize 0xf8c8765e
address _usdt
address _ntzc
address _initialOwner
address _accessContract
rebalancePool 0xd64356ab
uint256 amount
renounceOwnership 0x715018a6
No parameters
swapDirect 0xa4ea2003
uint256 _amount
uint8 _conversionType
address _tokenReceiveAddress
transferOwnership 0xf2fde38b
address newOwner
updateAllInvestorProfitsAdmin 0xc13996fe
No parameters
upgradeToAndCall 0x4f1ef286
address newImplementation
bytes data
withdrawAdmin 0x889d7624
address _to
uint8 _conversionType
uint256 _amount
withdrawLiquidity 0x06d47de9
address token
uint256 amount

Recent Transactions

No transactions found for this address