Address Contract Verified
Address
0x1AA1721906D500fae4Ed78A3534a40A69D29dfDe
Balance
0 ETH
Nonce
1
Code Size
13252 bytes
Creator
0x07cb37ED...B877 at tx 0x64736cd9...f9358c
Indexed Transactions
0
Contract Bytecode
13252 bytes
0x6080604052600436106102ae5760003560e01c80637b19f9c511610175578063cbdf0480116100dc578063eb91d37e11610095578063f2fde38b1161006f578063f2fde38b14610855578063f5d9cd6214610875578063f9f3bc451461088a578063fdc705ef146108aa57600080fd5b8063eb91d37e146107d6578063ec74cce2146107eb578063ee0dd08d1461080057600080fd5b8063cbdf04801461073f578063d0dbd89b14610755578063e2a6913514610775578063e2b2fbb01461078b578063e7546ac4146107a0578063e7f27457146107b657600080fd5b80638da5cb5b1161012e5780638da5cb5b1461067d57806391afa1741461069b57806394f3ed31146106b1578063acda2983146106d1578063ba8ae561146106eb578063c6f4d2481461071f57600080fd5b80637b19f9c5146105c65780637bc356da146105e6578063828cedb7146106065780638456cb591461062657806385d2a22d1461063b5780638c3c9a551461066857600080fd5b806337218752116102195780636a7c6c81116101d25780636a7c6c811461051b5780636b79c97f1461053b578063715018a61461055b578063741bef1a1461057057806378a21ad21461059057806379c4b393146105b057600080fd5b8063372187521461047b5780633f48be2d146104915780633f4ba83a146104b15780635b9bdcdf146104c65780635c975abb146104dc5780635dc92647146104fb57600080fd5b806329ae0dcb1161026b57806329ae0dcb146103c55780632ebba655146103db5780632ffdda52146103fb578063323a86811461041b578063349efe4314610445578063350b103a1461046557600080fd5b80630649c135146102b357806309bd6f52146102e95780630fc75a49146102fc578063194e0cd0146103375780631c31f710146103835780632924d4e8146103a5575b600080fd5b3480156102bf57600080fd5b506102d36102ce366004612cc4565b6108ca565b6040516102e09190612d18565b60405180910390f35b6102d36102f7366004612cc4565b610efa565b34801561030857600080fd5b50610329610317366004612d42565b600f6020526000908152604090205481565b6040519081526020016102e0565b34801561034357600080fd5b5061036b7f00000000000000000000000055700cd2e91f39bc56f589b346dac12a7907ea0881565b6040516001600160a01b0390911681526020016102e0565b34801561038f57600080fd5b506103a361039e366004612d42565b611491565b005b3480156103b157600080fd5b506103a36103c0366004612d6b565b611578565b3480156103d157600080fd5b50610329600b5481565b3480156103e757600080fd5b506103a36103f6366004612e5e565b6115e3565b34801561040757600080fd5b506103a3610416366004612f1e565b611751565b34801561042757600080fd5b506009546104359060ff1681565b60405190151581526020016102e0565b34801561045157600080fd5b506103a3610460366004612f6f565b6117b9565b34801561047157600080fd5b50610329600a5481565b34801561048757600080fd5b50610329600d5481565b34801561049d57600080fd5b506103a36104ac366004612d42565b6118b5565b3480156104bd57600080fd5b506103a3611986565b3480156104d257600080fd5b5061032960115481565b3480156104e857600080fd5b50600154600160a01b900460ff16610435565b34801561050757600080fd5b50610435610516366004612f6f565b6119ba565b34801561052757600080fd5b506103a3610536366004612cc4565b611c1c565b34801561054757600080fd5b506103a3610556366004612d42565b611ce5565b34801561056757600080fd5b506103a3611d5d565b34801561057c57600080fd5b5060005461036b906001600160a01b031681565b34801561059c57600080fd5b506103a36105ab366004612d6b565b611dc1565b3480156105bc57600080fd5b5061032960085481565b3480156105d257600080fd5b506103a36105e1366004612cc4565b611e2c565b3480156105f257600080fd5b506103a3610601366004612cc4565b611eaa565b34801561061257600080fd5b5060045461036b906001600160a01b031681565b34801561063257600080fd5b506103a3611f68565b34801561064757600080fd5b50610329610656366004612d42565b60126020526000908152604090205481565b34801561067457600080fd5b50610329611f9a565b34801561068957600080fd5b506001546001600160a01b031661036b565b3480156106a757600080fd5b5061032960065481565b3480156106bd57600080fd5b506103a36106cc366004612d42565b6120c2565b3480156106dd57600080fd5b506010546104359060ff1681565b3480156106f757600080fd5b5061036b7f000000000000000000000000442b153f6f61c0c99a33aa4170dcb31e1abda1d081565b34801561072b57600080fd5b506103a361073a366004612cc4565b612196565b34801561074b57600080fd5b5061032960055481565b34801561076157600080fd5b506103a3610770366004612cc4565b612262565b34801561078157600080fd5b5061032960075481565b34801561079757600080fd5b50610329612322565b3480156107ac57600080fd5b50610329600e5481565b3480156107c257600080fd5b506102d36107d1366004612f6f565b612341565b3480156107e257600080fd5b506103296126b1565b3480156107f757600080fd5b506103296126cf565b34801561080c57600080fd5b50600754600854600b54600e54600d54600c5460408051968752602087019590955293850192909252606084015260808301526001600160a01b031660a082015260c0016102e0565b34801561086157600080fd5b506103a3610870366004612d42565b612706565b34801561088157600080fd5b506103296127d1565b34801561089657600080fd5b506103a36108a5366004612cc4565b6127f7565b3480156108b657600080fd5b50600c5461036b906001600160a01b031681565b600154606090600160a01b900460ff16156109005760405162461bcd60e51b81526004016108f790612f99565b60405180910390fd5b600260035414156109235760405162461bcd60e51b81526004016108f790612fc3565b600260035560095460ff1661097a5760405162461bcd60e51b815260206004820181905260248201527f436172644d616e616765723a2062757920696e204156412064697361626c656460448201526064016108f7565b6000821161099a5760405162461bcd60e51b81526004016108f790612ffa565b6000600e54116109f85760405162461bcd60e51b8152602060048201526024808201527f436172644d616e616765723a2041564120746f6b656e207072696365206e6f74604482015263081cd95d60e21b60648201526084016108f7565b600060075411610a4a5760405162461bcd60e51b815260206004820152601f60248201527f436172644d616e616765723a20696e76616c696420636172642070726963650060448201526064016108f7565b6000610a546127d1565b90506000610a628483613045565b600d5490915015610a94576064600d5482610a7d9190613045565b610a87919061307a565b610a91908261308e565b90505b6001600160a01b037f000000000000000000000000442b153f6f61c0c99a33aa4170dcb31e1abda1d0166370a08231336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160206040518083038186803b158015610b0357600080fd5b505afa158015610b17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3b91906130a5565b811115610bb05760405162461bcd60e51b815260206004820152603960248201527f436172644d616e616765723a20757365722062616c616e636520646f6573206e60448201527f6f74206861766520656e6f7567682041564120746f6b656e730000000000000060648201526084016108f7565b610bbb335b856119ba565b5060006064600b5483610bce9190613045565b610bd8919061307a565b9050610c26336004546001600160a01b0316610bf4848661308e565b6001600160a01b037f000000000000000000000000442b153f6f61c0c99a33aa4170dcb31e1abda1d0169291906128c1565b600081118015610c405750600c546001600160a01b031615155b15610c8057610c8033600c546001600160a01b037f000000000000000000000000442b153f6f61c0c99a33aa4170dcb31e1abda1d08116929116846128c1565b8160056000828254610c9291906130be565b90915550503360009081526012602052604081208054879290610cb69084906130be565b9250508190555084600a6000828254610ccf91906130be565b90915550600090508567ffffffffffffffff811115610cf057610cf0612d88565b604051908082528060200260200182016040528015610d19578160200160208202803683370190505b5090506001861115610de0576001600160a01b037f00000000000000000000000055700cd2e91f39bc56f589b346dac12a7907ea081663470095e8336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101899052604401600060405180830381600087803b158015610d9d57600080fd5b505af1158015610db1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610dd991908101906130d6565b9050610eaf565b60006001600160a01b037f00000000000000000000000055700cd2e91f39bc56f589b346dac12a7907ea081663d578100d336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381600087803b158015610e5357600080fd5b505af1158015610e67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e8b91906130a5565b90508082600081518110610ea157610ea161315c565b602002602001018181525050505b7f16f0a3450df34137a6fe34b49aeca09d15cf0b4b500bea487f930c23029381b933828886604051610ee49493929190613172565b60405180910390a1600160035595945050505050565b600154606090600160a01b900460ff1615610f275760405162461bcd60e51b81526004016108f790612f99565b60026003541415610f4a5760405162461bcd60e51b81526004016108f790612fc3565b600260035581610f6c5760405162461bcd60e51b81526004016108f790612ffa565b600060075411610fbe5760405162461bcd60e51b815260206004820152601f60248201527f436172644d616e616765723a20696e76616c696420636172642070726963650060448201526064016108f7565b6000610fc86126cf565b90506000610fd68483613045565b9050803410156110405760405162461bcd60e51b815260206004820152602f60248201527f436172644d616e616765723a20757365722d7472616e7366657272656420616d60448201526e0deeadce840dcdee840cadcdeeaced608b1b60648201526084016108f7565b61104933610bb5565b5060006064600b543461105c9190613045565b611066919061307a565b6004549091506000906001600160a01b0316611082833461308e565b604051600081818185875af1925050503d80600081146110be576040519150601f19603f3d011682016040523d82523d6000602084013e6110c3565b606091505b505090508061112c5760405162461bcd60e51b815260206004820152602f60248201527f436172644d616e616765723a20455448207472616e7366657220746f2062656e60448201526e19599a58da585c9e4819985a5b1959608a1b60648201526084016108f7565b6000821180156111465750600c546001600160a01b031615155b1561121657600c546040516000916001600160a01b03169084908381818185875af1925050503d8060008114611198576040519150601f19603f3d011682016040523d82523d6000602084013e61119d565b606091505b50509050806112145760405162461bcd60e51b815260206004820152603760248201527f436172644d616e616765723a20455448207472616e7366657220746f20636f6d60448201527f6d756e697479506f6f6c57616c6c6574206661696c656400000000000000000060648201526084016108f7565b505b346006600082825461122891906130be565b9091555050336000908152601260205260408120805488929061124c9084906130be565b9250508190555085600a600082825461126591906130be565b90915550600090508667ffffffffffffffff81111561128657611286612d88565b6040519080825280602002602001820160405280156112af578160200160208202803683370190505b5090506001871115611376576001600160a01b037f00000000000000000000000055700cd2e91f39bc56f589b346dac12a7907ea081663470095e8336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018a9052604401600060405180830381600087803b15801561133357600080fd5b505af1158015611347573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261136f91908101906130d6565b9050611445565b60006001600160a01b037f00000000000000000000000055700cd2e91f39bc56f589b346dac12a7907ea081663d578100d336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381600087803b1580156113e957600080fd5b505af11580156113fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061142191906130a5565b905080826000815181106114375761143761315c565b602002602001018181525050505b7f599e8e456396e530d5a56b7f5cb524182e0633bf96a0b23c91963ce434adbfa23382893460405161147a9493929190613172565b60405180910390a160016003559695505050505050565b6001546001600160a01b031633146114bb5760405162461bcd60e51b81526004016108f7906131a9565b6001600160a01b0381166115235760405162461bcd60e51b815260206004820152602960248201527f436172644d616e616765723a20496e76616c69642062656e65666963696172796044820152685f206164647265737360b81b60648201526084016108f7565b600480546001600160a01b0319166001600160a01b0383169081179091556040519081527f2e916f6a88fdb77c3d7adf752dc95d5dc4822c095d8677493e205bdb882c554d906020015b60405180910390a150565b6001546001600160a01b031633146115a25760405162461bcd60e51b81526004016108f7906131a9565b6009805460ff19168215159081179091556040519081527f9ef5df2421c97dcef584aa823d020e254afb2d437c07352c52732ca409b2515c9060200161156d565b6001546001600160a01b031633148061161057503360009081526002602052604090205460ff1615156001145b61162c5760405162461bcd60e51b81526004016108f7906131d6565b80518251146116ae5760405162461bcd60e51b815260206004820152604260248201527f436172644d616e616765723a2077616c6c65744c6973745f20616e64206d617860448201527f43617264734c6973745f20646f206e6f7420686176652073616d65206c656e676064820152610e8d60f31b608482015260a4016108f7565b60005b8251811015611708576116f68382815181106116cf576116cf61315c565b60200260200101518383815181106116e9576116e961315c565b60200260200101516117b9565b8061170081613206565b9150506116b1565b507f8bc09a68d99b409bf16de42298a2b1e2dd57e3d8b85d5d59c2f7a82a9d758d6982518251604051611745929190918252602082015260400190565b60405180910390a15050565b6001546001600160a01b0316331461177b5760405162461bcd60e51b81526004016108f7906131a9565b61178486611eaa565b61178d85612262565b61179684611c1c565b61179f83611e2c565b6117a8826127f7565b6117b181611ce5565b505050505050565b6001546001600160a01b03163314806117e657503360009081526002602052604090205460ff1615156001145b6118025760405162461bcd60e51b81526004016108f7906131d6565b6001600160a01b0382166118645760405162461bcd60e51b8152602060048201526024808201527f436172644d616e616765723a20496e76616c69642077616c6c65745f206164646044820152637265737360e01b60648201526084016108f7565b6001600160a01b0382166000818152600f6020908152604091829020849055815192835282018390527fddaf708f05ab5210ccf7c67f44cc80306fe2001aed8f578c2b0ae5b612e20feb9101611745565b6001546001600160a01b031633146118df5760405162461bcd60e51b81526004016108f7906131a9565b6001600160a01b0381166119355760405162461bcd60e51b815260206004820181905260248201527f43617264426173653a20696e76616c696420617574685f20616464726573732060448201526064016108f7565b6001600160a01b038116600081815260026020908152604091829020805460ff1916905590519182527f48d42037a339be3ce4c67b781af7467d90953ebe212844cf74b105c9d02ecc33910161156d565b6001546001600160a01b031633146119b05760405162461bcd60e51b81526004016108f7906131a9565b6119b8612921565b565b600060085482600a546119cd91906130be565b1115611a2b5760405162461bcd60e51b815260206004820152602760248201527f436172644d616e616765723a204d617820737570706c7920666f722073616c6560448201526608195e18d9595960ca1b60648201526084016108f7565b60105460ff1615611b6d576001600160a01b0383166000908152600f6020526040902054611ab85760405162461bcd60e51b815260206004820152603460248201527f436172644d616e616765723a204e6f742077686974656c69737465642077616c6044820152736c657420666f7220707269766174652073616c6560601b60648201526084016108f7565b6001600160a01b0383166000908152600f6020908152604080832054601290925290912054611ae89084906130be565b1115611b685760405162461bcd60e51b815260206004820152604360248201527f436172644d616e616765723a206d617820616c6c6f7761626c6520636172647360448201527f207065722077616c6c657420666f7220707269766174652073616c652065786360648201526219595960ea1b608482015260a4016108f7565b611c13565b6011546001600160a01b038416600090815260126020526040902054611b949084906130be565b1115611c135760405162461bcd60e51b815260206004820152604260248201527f436172644d616e616765723a206d617820616c6c6f7761626c6520636172647360448201527f207065722077616c6c657420666f72207075626c69632073616c652065786365606482015261195960f21b608482015260a4016108f7565b50600192915050565b6001546001600160a01b03163314611c465760405162461bcd60e51b81526004016108f7906131a9565b6064811115611cb05760405162461bcd60e51b815260206004820152603060248201527f436172644d616e616765723a20496e76616c696420676976654261636b546f4360448201526f6f6d6d756e69747950657263656e745f60801b60648201526084016108f7565b600b8190556040518181527ff0b8fc2333178e26ee0841a8c4ee0f46af2f3d6db434bb1229333d68e4f86f2f9060200161156d565b6001546001600160a01b03163314611d0f5760405162461bcd60e51b81526004016108f7906131a9565b600c80546001600160a01b0319166001600160a01b0383169081179091556040519081527f6e821eed5017e7561c4609288c436b9cd8218b9bafc42296b294e300afbe2b7c9060200161156d565b6001546001600160a01b03163314611db75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108f7565b6119b860006129be565b6001546001600160a01b03163314611deb5760405162461bcd60e51b81526004016108f7906131a9565b6010805460ff19168215159081179091556040519081527fdf1345894dae79c99ebf7da59ee38d47714412a013697a69a45f00be232cad6d9060200161156d565b6001546001600160a01b0316331480611e5957503360009081526002602052604090205460ff1615156001145b611e755760405162461bcd60e51b81526004016108f7906131d6565b600e8190556040518181527f1720d6b8f2429dd82f49fe9253fedad326020029cbbd704a8306990a970310c89060200161156d565b6001546001600160a01b03163314611ed45760405162461bcd60e51b81526004016108f7906131a9565b60008111611f335760405162461bcd60e51b815260206004820152602660248201527f436172644d616e616765723a20496e76616c69642063617264507269636555736044820152656443656e745f60d01b60648201526084016108f7565b60078190556040518181527ff66c15d7c95671e9e3505a5493f2889aa43ccad1200ee91ac68074cb3229222c9060200161156d565b6001546001600160a01b03163314611f925760405162461bcd60e51b81526004016108f7906131a9565b6119b8612a10565b60004660011480611fab5750466004145b80611fb65750466038145b80611fc15750466061145b156120b85760008060009054906101000a90046001600160a01b03166001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a06040518083038186803b15801561201557600080fd5b505afa158015612029573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061204d919061323b565b505050915050600081136120b35760405162461bcd60e51b815260206004820152602760248201527f5072696365436f6e73756d657256333a20696e76616c69642070726963652072604482015266195d1d5c9b995960ca1b60648201526084016108f7565b919050565b50642e90edd00090565b6001546001600160a01b031633146120ec5760405162461bcd60e51b81526004016108f7906131a9565b6001600160a01b0381166121425760405162461bcd60e51b815260206004820181905260248201527f43617264426173653a20696e76616c696420617574685f20616464726573732060448201526064016108f7565b6001600160a01b038116600081815260026020908152604091829020805460ff1916600117905590519182527fa8de8f411f18b21588820f82c1c480c9010afa6ef212a9585ade363f56542816910161156d565b6001546001600160a01b031633146121c05760405162461bcd60e51b81526004016108f7906131a9565b6000811161222d5760405162461bcd60e51b815260206004820152603460248201527f436172644d616e616765723a20496e76616c6964206d6178416c6c6f7761626c604482015273654361726473466f725075626c696353616c655f60601b60648201526084016108f7565b60118190556040518181527f10236f2d38de809d02769f5b45312e430c56d84c9b19669a4428326b63abf39f9060200161156d565b6001546001600160a01b0316331461228c5760405162461bcd60e51b81526004016108f7906131a9565b600a548110156122ed5760405162461bcd60e51b815260206004820152602660248201527f436172644d616e616765723a20496e76616c6964206d6178537570706c79466f6044820152657253616c655f60d01b60648201526084016108f7565b60088190556040518181527fc1bd5246d95b820f23a470cdfe2099f32ec418d9cab400ae9f254bbc1438dba19060200161156d565b600080620f4240612331611f9a565b61233b919061328b565b92915050565b600154606090600160a01b900460ff161561236e5760405162461bcd60e51b81526004016108f790612f99565b600260035414156123915760405162461bcd60e51b81526004016108f790612fc3565b60026003556001546001600160a01b03163314806123c357503360009081526002602052604090205460ff1615156001145b6123df5760405162461bcd60e51b81526004016108f7906131d6565b600082116123ff5760405162461bcd60e51b81526004016108f790612ffa565b6001600160a01b0383166124555760405162461bcd60e51b815260206004820152601b60248201527f436172644d616e616765723a20696e76616c69642062757965725f000000000060448201526064016108f7565b61245f83836119ba565b506001600160a01b038316600090815260126020526040812080548492906124889084906130be565b9250508190555081600a60008282546124a191906130be565b90915550600090508267ffffffffffffffff8111156124c2576124c2612d88565b6040519080825280602002602001820160405280156124eb578160200160208202803683370190505b50905060018311156125a4576040516308e012bd60e31b81526001600160a01b038581166004830152602482018590527f00000000000000000000000055700cd2e91f39bc56f589b346dac12a7907ea08169063470095e890604401600060405180830381600087803b15801561256157600080fd5b505af1158015612575573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261259d91908101906130d6565b9050612668565b60405163d578100d60e01b81526001600160a01b0385811660048301526000917f00000000000000000000000055700cd2e91f39bc56f589b346dac12a7907ea089091169063d578100d90602401602060405180830381600087803b15801561260c57600080fd5b505af1158015612620573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061264491906130a5565b9050808260008151811061265a5761265a61315c565b602002602001018181525050505b7f2d403abc71cb0cfcdd62ce628611546f145861435ff46d803bdd7763ef92ae2b8433838660405161269d94939291906132b9565b60405180910390a160016003559392505050565b60006305f5e1006126c0611f9a565b6126ca919061328b565b905090565b6000806126da612322565b9050600081670de0b6b3a76400006007546126f59190613045565b6126ff919061307a565b9392505050565b6001546001600160a01b031633146127605760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108f7565b6001600160a01b0381166127c55760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016108f7565b6127ce816129be565b50565b600080600e54670de0b6b3a76400006007546127ed9190613045565b61233b919061307a565b6001546001600160a01b031633146128215760405162461bcd60e51b81526004016108f7906131a9565b606481111561288c5760405162461bcd60e51b815260206004820152603160248201527f436172644d616e616765723a20496e76616c696420646973636f756e745768656044820152706e427579496e41766150657263656e745f60781b60648201526084016108f7565b600d8190556040518181527f3b56ae8e236b6fdf38028af2f1d0f27d0aeaeac671df68af97e2e0a84bad26939060200161156d565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b17905261291b908590612a75565b50505050565b600154600160a01b900460ff166129715760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016108f7565b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600154600160a01b900460ff1615612a3a5760405162461bcd60e51b81526004016108f790612f99565b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586129a13390565b6000612aca826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612b4c9092919063ffffffff16565b805190915015612b475780806020019051810190612ae891906132f6565b612b475760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016108f7565b505050565b6060612b5b8484600085612b63565b949350505050565b606082471015612bc45760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016108f7565b843b612c125760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108f7565b600080866001600160a01b03168587604051612c2e919061333f565b60006040518083038185875af1925050503d8060008114612c6b576040519150601f19603f3d011682016040523d82523d6000602084013e612c70565b606091505b5091509150612c80828286612c8b565b979650505050505050565b60608315612c9a5750816126ff565b825115612caa5782518084602001fd5b8160405162461bcd60e51b81526004016108f7919061335b565b600060208284031215612cd657600080fd5b5035919050565b600081518084526020808501945080840160005b83811015612d0d57815187529582019590820190600101612cf1565b509495945050505050565b6020815260006126ff6020830184612cdd565b80356001600160a01b03811681146120b357600080fd5b600060208284031215612d5457600080fd5b6126ff82612d2b565b80151581146127ce57600080fd5b600060208284031215612d7d57600080fd5b81356126ff81612d5d565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612dc757612dc7612d88565b604052919050565b600067ffffffffffffffff821115612de957612de9612d88565b5060051b60200190565b600082601f830112612e0457600080fd5b81356020612e19612e1483612dcf565b612d9e565b82815260059290921b84018101918181019086841115612e3857600080fd5b8286015b84811015612e535780358352918301918301612e3c565b509695505050505050565b60008060408385031215612e7157600080fd5b823567ffffffffffffffff80821115612e8957600080fd5b818501915085601f830112612e9d57600080fd5b81356020612ead612e1483612dcf565b82815260059290921b84018101918181019089841115612ecc57600080fd5b948201945b83861015612ef157612ee286612d2b565b82529482019490820190612ed1565b96505086013592505080821115612f0757600080fd5b50612f1485828601612df3565b9150509250929050565b60008060008060008060c08789031215612f3757600080fd5b8635955060208701359450604087013593506060870135925060808701359150612f6360a08801612d2b565b90509295509295509295565b60008060408385031215612f8257600080fd5b612f8b83612d2b565b946020939093013593505050565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6020808252818101527f436172644d616e616765723a20696e76616c69642063617264416d6f756e745f604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561305f5761305f61302f565b500290565b634e487b7160e01b600052601260045260246000fd5b60008261308957613089613064565b500490565b6000828210156130a0576130a061302f565b500390565b6000602082840312156130b757600080fd5b5051919050565b600082198211156130d1576130d161302f565b500190565b600060208083850312156130e957600080fd5b825167ffffffffffffffff81111561310057600080fd5b8301601f8101851361311157600080fd5b805161311f612e1482612dcf565b81815260059190911b8201830190838101908783111561313e57600080fd5b928401925b82841015612c8057835182529284019290840190613143565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b038516815260806020820181905260009061319690830186612cdd565b6040830194909452506060015292915050565b60208082526013908201527221b0b9322130b9b29d103737ba1037bbb732b960691b604082015260600190565b60208082526016908201527510d85c9910985cd94e881d5b985d5d1a1bdc9a5e995960521b604082015260600190565b600060001982141561321a5761321a61302f565b5060010190565b805169ffffffffffffffffffff811681146120b357600080fd5b600080600080600060a0868803121561325357600080fd5b61325c86613221565b945060208601519350604086015192506060860151915061327f60808701613221565b90509295509295909350565b60008261329a5761329a613064565b600160ff1b8214600019841416156132b4576132b461302f565b500590565b6001600160a01b038581168252841660208201526080604082018190526000906132e590830185612cdd565b905082606083015295945050505050565b60006020828403121561330857600080fd5b81516126ff81612d5d565b60005b8381101561332e578181015183820152602001613316565b8381111561291b5750506000910152565b60008251613351818460208701613313565b9190910192915050565b602081526000825180602084015261337a816040850160208701613313565b601f01601f1916919091016040019291505056fea2646970667358221220afb6ccebd89ff4a1c87d917ef0b684979bd75b2078dd92bbe9a90b5f436da04164736f6c63430008090033
Verified Source Code Full Match
Compiler: v0.8.9+commit.e5eed63a
EVM: london
Optimization: Yes (200 runs)
Address.sol 217 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Strings.sol 67 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
Ownable.sol 76 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../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.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Pausable.sol 91 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @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);
}
ERC721.sol 424 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits a {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
IERC721.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
ReentrancyGuard.sol 63 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IERC721Receiver.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
CardNft.sol 172 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./CardBase.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract CardNft is ERC721Enumerable, CardBase {
// First tokenId begins from 1
// Also indicate the total number of minted tokens
uint256 public _tokenId;
uint256 public _burnCount; // count the number of burnt tokens
string public _baseTokenURI;
bool public _tokenTransferPaused;
event EventMintCard(
uint256 _tokenId,
address _tokenOwner,
uint256 _timestamp
);
event EventMintCardMany(
uint256[] _tokenIdList,
address _tokenOwner,
uint256 _timestamp
);
event EventAirdrop(uint256 receiverListLength_);
event EventBurnCard(address _tokenOwner, uint256 tokenId_);
event EventAdminBurnCard(address _adminAddress, uint256 tokenId_);
event EventSetTokenTransferPaused(bool tokenTransferPaused_);
event EventSetBaseURI(string baseURI);
event EventAdminTransferToken(uint256 tokenId_, address receiver_);
constructor(
string memory _name,
string memory _symbol,
string memory _baseTokenLink
) ERC721(_name, _symbol) {
_baseTokenURI = _baseTokenLink;
_tokenTransferPaused = false;
}
// Apply pausable for token transfer
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
require(_tokenTransferPaused == false, "CardNft: token transfer paused");
}
function setTokenTransferPaused(bool tokenTransferPaused_) external isOwner {
_tokenTransferPaused = tokenTransferPaused_;
emit EventSetTokenTransferPaused(tokenTransferPaused_);
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function setBaseURI(string memory baseURI) external isOwner {
_baseTokenURI = baseURI;
emit EventSetBaseURI(baseURI);
}
function tokenExists(uint256 tokenId_) external view returns (bool) {
return _exists(tokenId_);
}
// Return the tokenIds owned by a given user wallet address
function getTokenIdsOfUserAddress(address _userAddr)
external
view
returns (uint256[] memory)
{
uint256 tokenCount = balanceOf(_userAddr);
uint256[] memory tokenIds = new uint256[](tokenCount);
for (uint256 i = 0; i < tokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_userAddr, i);
}
return tokenIds;
}
function burnCard(uint256 tokenId_) external whenNotPaused {
require(ownerOf(tokenId_) == _msgSender(), "CardNft: Not token owner");
_burn(tokenId_);
_burnCount += 1;
emit EventBurnCard(_msgSender(), tokenId_);
}
function adminBurnCard(uint256 tokenId_) external whenNotPaused isOwner {
_burn(tokenId_);
_burnCount += 1;
emit EventAdminBurnCard(_msgSender(), tokenId_);
}
function mintCard(address owner_)
external
whenNotPaused
isAuthorized
returns (uint256)
{
_tokenId = _tokenId + 1;
_safeMint(owner_, _tokenId, "");
emit EventMintCard(_tokenId, owner_, block.timestamp);
return _tokenId;
}
function mintCardMany(address owner_, uint256 cardAmount_)
external
whenNotPaused
isAuthorized
returns (uint256[] memory)
{
uint256[] memory tokenIds = new uint256[](cardAmount_);
for (uint256 i = 0; i < cardAmount_; i++) {
_tokenId = _tokenId + 1;
_safeMint(owner_, _tokenId, "");
tokenIds[i] = _tokenId;
}
emit EventMintCardMany(tokenIds, owner_, block.timestamp);
return tokenIds;
}
function airdrop(address[] calldata receiverList_)
external
whenNotPaused
isAuthorized
{
for (uint256 i = 0; i < receiverList_.length; i++) {
_tokenId = _tokenId + 1;
_safeMint(receiverList_[i], _tokenId, "");
}
emit EventAirdrop(receiverList_.length);
}
function adminTransferToken(uint256 tokenId_, address receiver_)
external
isOwner
{
require(_exists(tokenId_), "CardNft: Token not exist");
address tokenOwner = ownerOf(tokenId_);
_safeTransfer(tokenOwner, receiver_, tokenId_, "");
emit EventAdminTransferToken(tokenId_, receiver_);
}
function transfer(uint256 tokenId_, address receiver_) external {
require(ownerOf(tokenId_) == _msgSender(), "CardNft: Not token owner");
_safeTransfer(_msgSender(), receiver_, tokenId_, "");
}
}
CardBase.sol 50 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
abstract contract CardBase is Ownable, Pausable {
// List of _authorizedAddressList addresses
mapping(address => bool) internal _authorizedAddressList;
event EventGrantAuthorized(address auth_);
event EventRevokeAuthorized(address auth_);
modifier isOwner() {
require(_msgSender() == owner(), "CardBase: not owner");
_;
}
modifier isAuthorized() {
require(
_msgSender() == owner() || _authorizedAddressList[_msgSender()] == true,
"CardBase: unauthorized"
);
_;
}
function grantAuthorized(address auth_) external isOwner {
require(auth_ != address(0), "CardBase: invalid auth_ address ");
_authorizedAddressList[auth_] = true;
emit EventGrantAuthorized(auth_);
}
function revokeAuthorized(address auth_) external isOwner {
require(auth_ != address(0), "CardBase: invalid auth_ address ");
_authorizedAddressList[auth_] = false;
emit EventRevokeAuthorized(auth_);
}
function pause() external isOwner {
_pause();
}
function unpause() external isOwner {
_unpause();
}
}
CardManager.sol 531 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./CardBase.sol";
import "./CardNft.sol";
import "./PriceConsumerV3.sol";
contract CardManager is PriceConsumerV3, CardBase, ReentrancyGuard {
using SafeERC20 for IERC20;
// Receive the fund collected
address payable public _beneficiary;
uint256 public _totalAvaTokensCollected;
uint256 public _totalNativeTokensCollected;
// AVA token
IERC20 public immutable _avaToken;
// CardNft contract
CardNft public immutable _cardNft;
// "decimals" is 18 for AVA tokens
uint256 constant E18 = 10**18;
uint256 public _cardPriceUsdCent;
uint256 public _maxSupplyForSale = 900;
bool public _purchaseInAvaEnabled = false;
// Keep current number of minted cards
uint256 public _cardNumForSaleMinted;
uint256 public _giveBackToCommunityPercent = 0;
address payable public _communityPoolWallet;
uint256 public _discountWhenBuyInAvaPercent = 5;
// Update frequently by external background service
uint256 public _avaTokenPriceInUsdCent; // 300 == 3 USD (i.e. 1 AVA costs 3 USD)
// Max allowable cards per wallet address for private sale depending on smart level
mapping(address => uint256) public _maxAllowableCardsForPrivateSale;
bool public _privateSaleEnabled = true;
// Max allowable cards per wallet address for public sale
uint256 public _maxAllowableCardsForPublicSale = 1;
// Keep track of the number of minted cards per wallet address
mapping(address => uint256) public _cardNumPerWalletMinted;
event EventBuyInAva(
address buyer_,
uint256[] mintedTokenIdList_,
uint256 cardAmount_,
uint256 totalAvaTokensToPay_
);
event EventBuyInNative(
address buyer_,
uint256[] mintedTokenIdList_,
uint256 cardAmount_,
uint256 totalToPay_
);
event EventMintAfterPayment(
address buyer_,
address minter_,
uint256[] mintedTokenIdList_,
uint256 cardAmount_
);
event EventSetCardPriceUsdCent(uint256 cardPriceUsdCent_);
event EventSetPurchaseInAvaEnabled(bool purchaseInAvaEnabled_);
event EventSetMaxSupplyForSale(uint256 maxSupplyForSale_);
event EventSetGiveBackToCommunityPercent(uint256 giveBackToCommunityPercent_);
event EventSetCommunityPoolWallet(address communityPoolWallet_);
event EventSetDiscountWhenBuyInAvaPercent(
uint256 discountWhenBuyInAvaPercent_
);
event EventSetAvaTokenPriceInUsdCent(uint256 avaTokenPriceInUsdCent_);
event EventSetBeneficiary(address beneficiary_);
event EventSetPrivateSaleEnabled(bool privateSaleEnabled_);
event EventSetMaxAllowableCardsForPrivateSale(
address wallet_,
uint256 maxCards_
);
event EventBatchSetMaxAllowableCardsForPrivateSale(
uint256 walletListLength,
uint256 maxCardsListLength
);
event EventSetMaxAllowableCardsForPublicSale(
uint256 maxAllowableCardsForPublicSale_
);
constructor(
address avaTokenAddress_,
address cardNftAddress_,
address beneficiary_
) {
require(
avaTokenAddress_ != address(0),
"CardManager: Invalid avaTokenAddress_ address"
);
require(
cardNftAddress_ != address(0),
"CardManager: Invalid cardNftAddress_ address"
);
require(
beneficiary_ != address(0),
"CardManager: Invalid beneficiary_ address"
);
_avaToken = IERC20(avaTokenAddress_);
_cardNft = CardNft(cardNftAddress_);
_beneficiary = payable(beneficiary_);
}
// Check if a wallet address can still buy depending on its number of minted cards
function checkIfCanBuy(address wallet_, uint256 cardAmount_)
public
view
returns (bool)
{
require(
(_cardNumForSaleMinted + cardAmount_) <= _maxSupplyForSale,
"CardManager: Max supply for sale exceed"
);
if (_privateSaleEnabled) {
require(
_maxAllowableCardsForPrivateSale[wallet_] > 0,
"CardManager: Not whitelisted wallet for private sale"
);
require(
(_cardNumPerWalletMinted[wallet_] + cardAmount_) <=
_maxAllowableCardsForPrivateSale[wallet_],
"CardManager: max allowable cards per wallet for private sale exceed"
);
} else {
require(
(_cardNumPerWalletMinted[wallet_] + cardAmount_) <=
_maxAllowableCardsForPublicSale,
"CardManager: max allowable cards per wallet for public sale exceed"
);
}
return true;
}
////////// Start setter /////////
// Set basic info to start the card sale
function setCardSaleInfo(
uint256 cardPriceUsdCent_,
uint256 maxSupplyForSale_,
uint256 giveBackToCommunityPercent_,
uint256 avaTokenPriceInUsdCent_,
uint256 discountWhenBuyInAvaPercent_,
address communityPoolWallet_
) external isOwner {
setCardPriceUsdCent(cardPriceUsdCent_);
setMaxSupplyForSale(maxSupplyForSale_);
setGiveBackToCommunityPercent(giveBackToCommunityPercent_);
setAvaTokenPriceInUsdCent(avaTokenPriceInUsdCent_);
setDiscountWhenBuyInAvaPercent(discountWhenBuyInAvaPercent_);
setCommunityPoolWallet(communityPoolWallet_);
}
function setCardPriceUsdCent(uint256 cardPriceUsdCent_) public isOwner {
require(cardPriceUsdCent_ > 0, "CardManager: Invalid cardPriceUsdCent_");
_cardPriceUsdCent = cardPriceUsdCent_;
emit EventSetCardPriceUsdCent(cardPriceUsdCent_);
}
function setPurchaseInAvaEnabled(bool purchaseInAvaEnabled_)
external
isOwner
{
_purchaseInAvaEnabled = purchaseInAvaEnabled_;
emit EventSetPurchaseInAvaEnabled(purchaseInAvaEnabled_);
}
function setMaxSupplyForSale(uint256 maxSupplyForSale_) public isOwner {
require(
maxSupplyForSale_ >= _cardNumForSaleMinted,
"CardManager: Invalid maxSupplyForSale_"
);
_maxSupplyForSale = maxSupplyForSale_;
emit EventSetMaxSupplyForSale(maxSupplyForSale_);
}
function setGiveBackToCommunityPercent(uint256 giveBackToCommunityPercent_)
public
isOwner
{
// giveBackToCommunityPercent_ can be zero
require(
giveBackToCommunityPercent_ <= 100,
"CardManager: Invalid giveBackToCommunityPercent_"
);
_giveBackToCommunityPercent = giveBackToCommunityPercent_;
emit EventSetGiveBackToCommunityPercent(giveBackToCommunityPercent_);
}
function setCommunityPoolWallet(address communityPoolWallet_) public isOwner {
// communityPoolWallet_ can be address(0)
_communityPoolWallet = payable(communityPoolWallet_);
emit EventSetCommunityPoolWallet(communityPoolWallet_);
}
function setDiscountWhenBuyInAvaPercent(uint256 discountWhenBuyInAvaPercent_)
public
isOwner
{
// discountWhenBuyInAvaPercent_ can be zero
require(
discountWhenBuyInAvaPercent_ <= 100,
"CardManager: Invalid discountWhenBuyInAvaPercent_"
);
_discountWhenBuyInAvaPercent = discountWhenBuyInAvaPercent_;
emit EventSetDiscountWhenBuyInAvaPercent(discountWhenBuyInAvaPercent_);
}
function setAvaTokenPriceInUsdCent(uint256 avaTokenPriceInUsdCent_)
public
isAuthorized
{
// avaTokenPriceInUsdCent_ can be zero
_avaTokenPriceInUsdCent = avaTokenPriceInUsdCent_;
emit EventSetAvaTokenPriceInUsdCent(avaTokenPriceInUsdCent_);
}
function setBeneficiary(address beneficiary_) external isOwner {
require(
beneficiary_ != address(0),
"CardManager: Invalid beneficiary_ address"
);
_beneficiary = payable(beneficiary_);
emit EventSetBeneficiary(beneficiary_);
}
function setPrivateSaleEnabled(bool privateSaleEnabled_) external isOwner {
_privateSaleEnabled = privateSaleEnabled_;
emit EventSetPrivateSaleEnabled(privateSaleEnabled_);
}
function setMaxAllowableCardsForPrivateSale(
address wallet_,
uint256 maxCards_
) public isAuthorized {
require(wallet_ != address(0), "CardManager: Invalid wallet_ address");
_maxAllowableCardsForPrivateSale[wallet_] = maxCards_;
emit EventSetMaxAllowableCardsForPrivateSale(wallet_, maxCards_);
}
function batchSetMaxAllowableCardsForPrivateSale(
address[] memory walletList_,
uint256[] memory maxCardsList_
) external isAuthorized {
require(
walletList_.length == maxCardsList_.length,
"CardManager: walletList_ and maxCardsList_ do not have same length"
);
for (uint256 i = 0; i < walletList_.length; i++) {
setMaxAllowableCardsForPrivateSale(walletList_[i], maxCardsList_[i]);
}
emit EventBatchSetMaxAllowableCardsForPrivateSale(
walletList_.length,
maxCardsList_.length
);
}
function setMaxAllowableCardsForPublicSale(
uint256 maxAllowableCardsForPublicSale_
) external isOwner {
require(
maxAllowableCardsForPublicSale_ > 0,
"CardManager: Invalid maxAllowableCardsForPublicSale_"
);
_maxAllowableCardsForPublicSale = maxAllowableCardsForPublicSale_;
emit EventSetMaxAllowableCardsForPublicSale(
maxAllowableCardsForPublicSale_
);
}
////////// End setter /////////
function getCardSaleInfo()
external
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256,
address
)
{
return (
_cardPriceUsdCent,
_maxSupplyForSale,
_giveBackToCommunityPercent,
_avaTokenPriceInUsdCent,
_discountWhenBuyInAvaPercent,
_communityPoolWallet
);
}
// Get price of ETH or BNB
function getNativeCoinPriceInUsdCent() public view returns (uint256) {
uint256 nativeCoinPriceInUsdCent = uint256(getThePrice() / 10**6);
return nativeCoinPriceInUsdCent;
}
// Get card price in AVA tokens depending on the current price of AVA
function getCardPriceInAvaTokens() public view returns (uint256) {
uint256 cardPriceInAvaTokens = (_cardPriceUsdCent * E18) /
_avaTokenPriceInUsdCent;
return cardPriceInAvaTokens;
}
// Buy card in AVA tokens
function buyInAva(uint256 cardAmount_)
external
whenNotPaused
nonReentrant
returns (uint256[] memory)
{
require(_purchaseInAvaEnabled, "CardManager: buy in AVA disabled");
require(cardAmount_ > 0, "CardManager: invalid cardAmount_");
require(
_avaTokenPriceInUsdCent > 0,
"CardManager: AVA token price not set"
);
require(_cardPriceUsdCent > 0, "CardManager: invalid card price");
uint256 cardPriceInAvaTokens = getCardPriceInAvaTokens();
uint256 totalAvaTokensToPay = cardPriceInAvaTokens * cardAmount_;
if (_discountWhenBuyInAvaPercent > 0) {
totalAvaTokensToPay =
totalAvaTokensToPay -
((totalAvaTokensToPay * _discountWhenBuyInAvaPercent) / 100);
}
// Check if user balance has enough tokens
require(
totalAvaTokensToPay <= _avaToken.balanceOf(_msgSender()),
"CardManager: user balance does not have enough AVA tokens"
);
// Check if can buy
checkIfCanBuy(_msgSender(), cardAmount_);
// Transfer tokens from user wallet to beneficiary or communityPool
uint256 giveBack = (totalAvaTokensToPay * _giveBackToCommunityPercent) /
100;
_avaToken.safeTransferFrom(
_msgSender(),
_beneficiary,
totalAvaTokensToPay - giveBack
);
if (giveBack > 0 && _communityPoolWallet != address(0)) {
_avaToken.safeTransferFrom(_msgSender(), _communityPoolWallet, giveBack);
}
_totalAvaTokensCollected += totalAvaTokensToPay;
_cardNumPerWalletMinted[_msgSender()] += cardAmount_;
_cardNumForSaleMinted += cardAmount_;
// Mint card
uint256[] memory mintedTokenIdList = new uint256[](cardAmount_);
if (cardAmount_ > 1) {
mintedTokenIdList = _cardNft.mintCardMany(_msgSender(), cardAmount_);
} else {
uint256 mintedTokenId = _cardNft.mintCard(_msgSender());
mintedTokenIdList[0] = mintedTokenId;
}
emit EventBuyInAva(
_msgSender(),
mintedTokenIdList,
cardAmount_,
totalAvaTokensToPay
);
return mintedTokenIdList;
}
function getCardPriceInNative() public view returns (uint256) {
uint256 nativeCoinPriceInUsdCent = getNativeCoinPriceInUsdCent();
uint256 cardPriceInNative = (_cardPriceUsdCent * E18) /
nativeCoinPriceInUsdCent;
return cardPriceInNative;
}
// Buy card in native coins (ETH or BNB)
function buyInNative(uint256 cardAmount_)
external
payable
whenNotPaused
nonReentrant
returns (uint256[] memory)
{
require(cardAmount_ > 0, "CardManager: invalid cardAmount_");
require(_cardPriceUsdCent > 0, "CardManager: invalid card price");
uint256 cardPriceInNative = getCardPriceInNative();
uint256 totalToPay = cardPriceInNative * cardAmount_;
// Check if user-transferred amount is enough
require(
msg.value >= totalToPay,
"CardManager: user-transferred amount not enough"
);
// Check if can buy
checkIfCanBuy(_msgSender(), cardAmount_);
// Transfer msg.value from user wallet to beneficiary
uint256 giveBack = (msg.value * _giveBackToCommunityPercent) / 100;
(bool success, ) = _beneficiary.call{ value: (msg.value - giveBack) }("");
require(success, "CardManager: ETH transfer to beneficiary failed");
if (giveBack > 0 && _communityPoolWallet != address(0)) {
(bool success2, ) = _communityPoolWallet.call{ value: giveBack }("");
require(
success2,
"CardManager: ETH transfer to communityPoolWallet failed"
);
}
_totalNativeTokensCollected += msg.value;
_cardNumPerWalletMinted[_msgSender()] += cardAmount_;
_cardNumForSaleMinted += cardAmount_;
// Mint card
uint256[] memory mintedTokenIdList = new uint256[](cardAmount_);
if (cardAmount_ > 1) {
mintedTokenIdList = _cardNft.mintCardMany(_msgSender(), cardAmount_);
} else {
uint256 mintedTokenId = _cardNft.mintCard(_msgSender());
mintedTokenIdList[0] = mintedTokenId;
}
emit EventBuyInNative(
_msgSender(),
mintedTokenIdList,
cardAmount_,
msg.value
);
return mintedTokenIdList;
}
// Mint card(s) after having verified user's payment (e.g. via internal wallet)
// Can only be called by authorized wallet managed by BE
function mintAfterPayment(address buyer_, uint256 cardAmount_)
external
whenNotPaused
nonReentrant
isAuthorized
returns (uint256[] memory)
{
require(cardAmount_ > 0, "CardManager: invalid cardAmount_");
require(buyer_ != address(0), "CardManager: invalid buyer_");
// Check if can buy
checkIfCanBuy(buyer_, cardAmount_);
_cardNumPerWalletMinted[buyer_] += cardAmount_;
_cardNumForSaleMinted += cardAmount_;
// Mint card
uint256[] memory mintedTokenIdList = new uint256[](cardAmount_);
if (cardAmount_ > 1) {
mintedTokenIdList = _cardNft.mintCardMany(buyer_, cardAmount_);
} else {
uint256 mintedTokenId = _cardNft.mintCard(buyer_);
mintedTokenIdList[0] = mintedTokenId;
}
emit EventMintAfterPayment(
buyer_,
_msgSender(),
mintedTokenIdList,
cardAmount_
);
return mintedTokenIdList;
}
// BNB price when running on BSC or ETH price when running on Ethereum
function getCurrentPrice() public view returns (int256) {
return getThePrice() / 10**8;
}
}
AggregatorV3Interface.sol 35 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
IERC721Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
ERC721Enumerable.sol 163 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
PriceConsumerV3.sol 54 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
abstract contract PriceConsumerV3 {
AggregatorV3Interface public priceFeed;
int256 private constant fakePrice = 2000 * 10**8; // remember to multiply by 10 ** 8
// Price feed for ETH/USD on Ethereum and Matic
// Price feed for BNB/USD on BSC
constructor() {
if (block.chainid == 1) {
// Ethereum mainnet
priceFeed = AggregatorV3Interface(
0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419
);
} else if (block.chainid == 4) {
// Rinkeby
priceFeed = AggregatorV3Interface(
0x8A753747A1Fa494EC906cE90E9f37563A8AF630e
);
} else if (block.chainid == 56) {
// BSC mainnet
priceFeed = AggregatorV3Interface(
0x0567F2323251f0Aab15c8dFb1967E4e8A7D42aeE
);
} else if (block.chainid == 97) {
// BSC testnet
priceFeed = AggregatorV3Interface(
0x2514895c72f50D8bd4B4F9b1110F0D6bD2c97526
);
} else {
// Unit-test
}
}
// The returned price must be divided by 10**8
function getThePrice() public view returns (int256) {
if (
block.chainid == 1 ||
block.chainid == 4 ||
block.chainid == 56 ||
block.chainid == 97
) {
(, int256 price, , , ) = priceFeed.latestRoundData();
require(price > 0, "PriceConsumerV3: invalid price returned");
return price;
} else {
return fakePrice;
}
}
}
IERC721Enumerable.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
Read Contract
_avaToken 0xba8ae561 → address
_avaTokenPriceInUsdCent 0xe7546ac4 → uint256
_beneficiary 0x828cedb7 → address
_cardNft 0x194e0cd0 → address
_cardNumForSaleMinted 0x350b103a → uint256
_cardNumPerWalletMinted 0x85d2a22d → uint256
_cardPriceUsdCent 0xe2a69135 → uint256
_communityPoolWallet 0xfdc705ef → address
_discountWhenBuyInAvaPercent 0x37218752 → uint256
_giveBackToCommunityPercent 0x29ae0dcb → uint256
_maxAllowableCardsForPrivateSale 0x0fc75a49 → uint256
_maxAllowableCardsForPublicSale 0x5b9bdcdf → uint256
_maxSupplyForSale 0x79c4b393 → uint256
_privateSaleEnabled 0xacda2983 → bool
_purchaseInAvaEnabled 0x323a8681 → bool
_totalAvaTokensCollected 0xcbdf0480 → uint256
_totalNativeTokensCollected 0x91afa174 → uint256
checkIfCanBuy 0x5dc92647 → bool
getCardPriceInAvaTokens 0xf5d9cd62 → uint256
getCardPriceInNative 0xec74cce2 → uint256
getCardSaleInfo 0xee0dd08d → uint256, uint256, uint256, uint256, uint256, address
getCurrentPrice 0xeb91d37e → int256
getNativeCoinPriceInUsdCent 0xe2b2fbb0 → uint256
getThePrice 0x8c3c9a55 → int256
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
priceFeed 0x741bef1a → address
Write Contract 22 functions
These functions modify contract state and require a wallet transaction to execute.
batchSetMaxAllowableCardsForPrivateSale 0x2ebba655
address[] walletList_
uint256[] maxCardsList_
buyInAva 0x0649c135
uint256 cardAmount_
returns: uint256[]
buyInNative 0x09bd6f52
uint256 cardAmount_
returns: uint256[]
grantAuthorized 0x94f3ed31
address auth_
mintAfterPayment 0xe7f27457
address buyer_
uint256 cardAmount_
returns: uint256[]
pause 0x8456cb59
No parameters
renounceOwnership 0x715018a6
No parameters
revokeAuthorized 0x3f48be2d
address auth_
setAvaTokenPriceInUsdCent 0x7b19f9c5
uint256 avaTokenPriceInUsdCent_
setBeneficiary 0x1c31f710
address beneficiary_
setCardPriceUsdCent 0x7bc356da
uint256 cardPriceUsdCent_
setCardSaleInfo 0x2ffdda52
uint256 cardPriceUsdCent_
uint256 maxSupplyForSale_
uint256 giveBackToCommunityPercent_
uint256 avaTokenPriceInUsdCent_
uint256 discountWhenBuyInAvaPercent_
address communityPoolWallet_
setCommunityPoolWallet 0x6b79c97f
address communityPoolWallet_
setDiscountWhenBuyInAvaPercent 0xf9f3bc45
uint256 discountWhenBuyInAvaPercent_
setGiveBackToCommunityPercent 0x6a7c6c81
uint256 giveBackToCommunityPercent_
setMaxAllowableCardsForPrivateSale 0x349efe43
address wallet_
uint256 maxCards_
setMaxAllowableCardsForPublicSale 0xc6f4d248
uint256 maxAllowableCardsForPublicSale_
setMaxSupplyForSale 0xd0dbd89b
uint256 maxSupplyForSale_
setPrivateSaleEnabled 0x78a21ad2
bool privateSaleEnabled_
setPurchaseInAvaEnabled 0x2924d4e8
bool purchaseInAvaEnabled_
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
Recent Transactions
No transactions found for this address