Address Contract Partially Verified
Address
0x0259119359Bf053ebF42C9807752de6bbb4925f3
Balance
0 ETH
Nonce
1
Code Size
19037 bytes
Creator
0x7bE52e01...fEfC at tx 0xe3114e81...a46b1d
Indexed Transactions
0
Contract Bytecode
19037 bytes
0x608060405234801561001057600080fd5b50600436106103425760003560e01c8063676a196a116101b85780639f181b5e11610104578063bff86757116100a2578063e985e9c51161007c578063e985e9c514610738578063eadb80b81461074b578063ed81cdda14610773578063fa3e47051461078657600080fd5b8063bff86757146106ff578063c87b56dd14610712578063df7490861461072557600080fd5b8063a7103afa116100de578063a7103afa146106b3578063b88d4fde146106c6578063ba6b5f96146106d9578063bef44f18146106ec57600080fd5b80639f181b5e14610684578063a22cb4651461068d578063a57a63b2146106a057600080fd5b80638456cb59116101715780638da7d0b51161014b5780638da7d0b51461064e57806392fede001461066157806395d89b41146106695780639d6fa6181461067157600080fd5b80638456cb59146106225780638d81f51e1461062a5780638da5cb5b1461063d57600080fd5b8063676a196a146105b25780636c0360eb146105c557806370a08231146105cd5780637b371107146105e05780637eef0896146105e8578063804f3fb2146105fb57600080fd5b80632f745c59116102925780634f6ccce7116102305780635c975abb1161020a5780635c975abb146105725780635d799f87146105845780635f992fdd146105975780636352211e1461059f57600080fd5b80634f6ccce71461051457806355f804b3146105275780635680a3ad1461053a57600080fd5b80633f4ba83a1161026c5780633f4ba83a146104d357806340d097c3146104db57806342842e0e146104ee57806343a61a8e1461050157600080fd5b80632f745c591461049a57806334854fda146104ad57806335b21ceb146104c057600080fd5b80630d5a621b116102ff57806318160ddd116102d957806318160ddd1461045e5780631d98f3c51461046657806322ab2e6f1461047957806323b872dd1461048757600080fd5b80630d5a621b146103fe578063150b7a0214610411578063160b01a11461043d57600080fd5b806301cf69021461034757806301ffc9a71461038b57806306fdde03146103ae578063081812fc146103c357806308937f62146103d6578063095ea7b3146103eb575b600080fd5b61036e7f000000000000000000000000adde73498902f61bfcb702e94c31c13c534879ac81565b6040516001600160a01b0390911681526020015b60405180910390f35b61039e610399366004613b34565b610799565b6040519015158152602001610382565b6103b66107df565b6040516103829190613ba1565b61036e6103d1366004613bb4565b610871565b6103e96103e4366004613cc7565b61090b565b005b6103e96103f9366004613d44565b610953565b61036e61040c366004613d70565b610a68565b61042461041f366004613dd3565b610a87565b6040516001600160e01b03199091168152602001610382565b61045061044b366004613e45565b610b37565b604051908152602001610382565b600854610450565b6103e9610474366004613e7d565b610b6b565b61045063cd740db560e01b81565b6103e9610495366004613ec5565b610c47565b6104506104a8366004613d44565b610c78565b6104506104bb366004614072565b610d0e565b6104506104ce3660046140a6565b610d26565b6103e9610d51565b6104506104e93660046140d6565b610d85565b6103e96104fc366004613ec5565b610dd9565b61045061050f366004613bb4565b610df4565b610450610522366004613bb4565b610e01565b6103e96105353660046140f3565b610e94565b61039e610548366004613d44565b6001600160a01b039190911660009081526010602090815260408083209383529290522054151590565b600c54600160a01b900460ff1661039e565b6103e961059236600461413b565b610eca565b6103e9610fbf565b61036e6105ad366004613bb4565b61102b565b61039e6105c03660046140d6565b6110a2565b6103b661113c565b6104506105db3660046140d6565b6111ca565b6103e9611251565b6103e96105f6366004614169565b6112c0565b61036e7f000000000000000000000000dcb004c4ab4b9c12e6bb4ed7992bb78218e9652081565b6103e96114f6565b6103e9610638366004614228565b611528565b600b546001600160a01b031661036e565b61045061065c366004613bb4565b611629565b6103e9611640565b6103b661166a565b6103e961067f3660046140d6565b611679565b610450600d5481565b6103e961069b36600461429d565b61172a565b6103e96106ae3660046142cb565b6117ee565b6103e96106c13660046142cb565b6117fc565b6103e96106d4366004614311565b611806565b6103e96106e736600461437c565b611838565b6103e96106fa366004613e7d565b61195a565b6103e961070d3660046143b4565b6119cc565b6103b6610720366004613bb4565b6119e0565b6103e96107333660046140a6565b611aba565b61039e61074636600461413b565b611c29565b61075e610759366004613d44565b611c57565b60408051928352602083019190915201610382565b610450610781366004613d44565b611ce9565b6103e9610794366004614420565b611dc9565b60006001600160e01b03198216630a85bd0160e11b14806107ca57506001600160e01b03198216639fa4074560e01b145b806107d957506107d982612074565b92915050565b6060600080546107ee90614462565b80601f016020809104026020016040519081016040528092919081815260200182805461081a90614462565b80156108675780601f1061083c57610100808354040283529160200191610867565b820191906000526020600020905b81548152906001019060200180831161084a57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166108ef5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60405162461bcd60e51b815260206004820152601d60248201527f424f54544f4d5f55505f4348494c445f4e4f545f535550504f5254454400000060448201526064016108e6565b600061095e8261102b565b9050806001600160a01b0316836001600160a01b0316036109cb5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016108e6565b336001600160a01b03821614806109e757506109e78133611c29565b610a595760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016108e6565b610a6383836120cf565b505050565b6000828152600e60205260408120610a80908361213d565b9392505050565b600c54600090600160a01b900460ff1615610ab45760405162461bcd60e51b81526004016108e69061449c565b6002600a5403610ad65760405162461bcd60e51b81526004016108e6906144c6565b6002600a81905550610b2085338686868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061214992505050565b50630a85bd0160e11b6001600a5595945050505050565b6000838152600f602090815260408083206001600160a01b03861684529091528120610b63908361213d565b949350505050565b6002600a5403610b8d5760405162461bcd60e51b81526004016108e6906144c6565b6002600a55610b9e8484848461218f565b604051632142170760e11b81526001600160a01b038316906342842e0e90610bce903090879086906004016144fd565b600060405180830381600087803b158015610be857600080fd5b505af1158015610bfc573d6000803e3d6000fd5b50505050816001600160a01b0316836001600160a01b031685600080516020614a3183398151915284604051610c3491815260200190565b60405180910390a450506001600a555050565b610c5133826121ae565b610c6d5760405162461bcd60e51b81526004016108e690614521565b610a6383838361227d565b6000610c83836111ca565b8210610ce55760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016108e6565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600080610d1a33610d85565b90506107d98184612428565b6000828152600f602090815260408083206001600160a01b03851684529091528120610a809061270d565b600b546001600160a01b03163314610d7b5760405162461bcd60e51b81526004016108e690614572565b610d83612717565b565b600c54600090600160a01b900460ff1615610db25760405162461bcd60e51b81526004016108e69061449c565b6000600d60008154610dc3906145bd565b918290555090506107d983826127b4565b919050565b610a6383838360405180602001604052806000815250611806565b60006107d9600083611ce9565b6000610e0c60085490565b8210610e6f5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016108e6565b60088281548110610e8257610e826145d6565b90600052602060002001549050919050565b600b546001600160a01b03163314610ebe5760405162461bcd60e51b81526004016108e690614572565b610ec7816127ce565b50565b600b546001600160a01b03163314610ef45760405162461bcd60e51b81526004016108e690614572565b6040516370a0823160e01b815230600482015282906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610f3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f6191906145ec565b905060008111610fa55760405162461bcd60e51b815260206004820152600f60248201526e1b9bc81d1bdad95b9cc81bdddb9959608a1b60448201526064016108e6565b610fb96001600160a01b0383168483612824565b50505050565b600c546001600160a01b031633146110195760405162461bcd60e51b815260206004820152601c60248201527f4f776e61626c653a206e6f74206f776e65722063616e6469646174650000000060448201526064016108e6565b600c80546001600160a01b0319169055565b6000818152600260205260408120546001600160a01b0316806107d95760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016108e6565b604051636651f11d60e01b81526001600160a01b0382811660048301526000917f000000000000000000000000adde73498902f61bfcb702e94c31c13c534879ac91839190831690636651f11d90602401602060405180830381865afa158015611110573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061113491906145ec565b119392505050565b6011805461114990614462565b80601f016020809104026020016040519081016040528092919081815260200182805461117590614462565b80156111c25780601f10611197576101008083540402835291602001916111c2565b820191906000526020600020905b8154815290600101906020018083116111a557829003601f168201915b505050505081565b60006001600160a01b0382166112355760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016108e6565b506001600160a01b031660009081526003602052604090205490565b600c546001600160a01b031633146112ab5760405162461bcd60e51b815260206004820152601c60248201527f4f776e61626c653a206e6f74206f776e65722063616e6469646174650000000060448201526064016108e6565b600c54611019906001600160a01b0316612876565b6001600160a01b038a1660009081526010602090815260408083208c8452909152812054906112ee82610df4565b90506001600160a01b03811633146113545760405162461bcd60e51b815260206004820152602360248201527f70756c6c41697264726f70206d73672e73656e646572206e6f7420656c696769604482015262626c6560e81b60648201526084016108e6565b8b6001600160a01b03166342842e0e307f000000000000000000000000dcb004c4ab4b9c12e6bb4ed7992bb78218e965208e6040518463ffffffff1660e01b81526004016113a4939291906144fd565b600060405180830381600087803b1580156113be57600080fd5b505af11580156113d2573d6000803e3d6000fd5b5050604051633f77844b60e11b81526001600160a01b037f000000000000000000000000dcb004c4ab4b9c12e6bb4ed7992bb78218e96520169250637eef08969150611434908f908f908f908f908f908f908f908f908f908f90600401614605565b600060405180830381600087803b15801561144e57600080fd5b505af1158015611462573d6000803e3d6000fd5b505050508b6001600160a01b03166342842e0e7f000000000000000000000000dcb004c4ab4b9c12e6bb4ed7992bb78218e96520308e6040518463ffffffff1660e01b81526004016114b6939291906144fd565b600060405180830381600087803b1580156114d057600080fd5b505af11580156114e4573d6000803e3d6000fd5b50505050505050505050505050505050565b600b546001600160a01b031633146115205760405162461bcd60e51b81526004016108e690614572565b610d836128c8565b6002600a540361154a5760405162461bcd60e51b81526004016108e6906144c6565b6002600a5561155b8585858561218f565b306001600160a01b0385160361157c5761157733848484612149565b61161d565b604051635c46a7ef60e11b81526001600160a01b0384169063b88d4fde906115ae903090889087908790600401614687565b600060405180830381600087803b1580156115c857600080fd5b505af11580156115dc573d6000803e3d6000fd5b50505050826001600160a01b0316846001600160a01b031686600080516020614a318339815191528560405161161491815260200190565b60405180910390a45b50506001600a55505050565b6000818152600e602052604081206107d99061270d565b600b546001600160a01b031633146110195760405162461bcd60e51b81526004016108e690614572565b6060600180546107ee90614462565b600b546001600160a01b031633146116a35760405162461bcd60e51b81526004016108e690614572565b6001600160a01b0381166117085760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016108e6565b600c80546001600160a01b0319166001600160a01b0392909216919091179055565b336001600160a01b038316036117825760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016108e6565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6117f88282612428565b5050565b6117f8828261292d565b61181033836121ae565b61182c5760405162461bcd60e51b81526004016108e690614521565b610fb984848484612b43565b600c54600160a01b900460ff16156118625760405162461bcd60e51b81526004016108e69061449c565b6002600a54036118845760405162461bcd60e51b81526004016108e6906144c6565b6002600a556001600160a01b03841633146118e15760405162461bcd60e51b815260206004820152601a60248201527f5f66726f6d2073686f756c64206265206d73672e73656e64657200000000000060448201526064016108e6565b6118ed84848484612b76565b6040516323b872dd60e01b81526001600160a01b038316906323b872dd9061191d908790309086906004016144fd565b600060405180830381600087803b15801561193757600080fd5b505af115801561194b573d6000803e3d6000fd5b50506001600a55505050505050565b6002600a540361197c5760405162461bcd60e51b81526004016108e6906144c6565b6002600a5561198d8484848461218f565b611998838383612bce565b816001600160a01b0316836001600160a01b031685600080516020614a3183398151915284604051610c3491815260200190565b6119d68383612428565b610a63838261292d565b6000818152600260205260409020546060906001600160a01b0316611a5f5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016108e6565b6000611a69612c8f565b90506000815111611a895760405180602001604052806000815250610a80565b80611a9384611f74565b604051602001611aa49291906146c4565b6040516020818303038152906040529392505050565b611ac381612c9e565b611acc82612cf4565b6000828152600e60205260408120611ae39061270d565b11156117f8576000828152600e60205260408120611b01908261213d565b90505b6000838152600f602090815260408083206001600160a01b03851684529091528120611b2f9061270d565b1115611c2357611b3e83612cf4565b6000838152600f602090815260408083206001600160a01b03851684529091528120611b6a908261213d565b9050611b77848383612d92565b604051632142170760e11b81526001600160a01b038316906342842e0e90611ba7903090879086906004016144fd565b600060405180830381600087803b158015611bc157600080fd5b505af1925050508015611bd2575060015b611be157611be1838383612bce565b816001600160a01b0316836001600160a01b031685600080516020614a3183398151915284604051611c1591815260200190565b60405180910390a450611b04565b50611acc565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6001600160a01b0382166000908152601060209081526040808320848452909152812054808203611cca5760405162461bcd60e51b815260206004820152601a60248201527f6368696c6420746f6b656e20646f6573206e6f7420657869737400000000000060448201526064016108e6565b6000611cd58261102b565b63cd740db560e01b17959194509092505050565b6000806001600160a01b03841615611d0e57611d058484612e1e565b93509050611d1a565b611d178361102b565b90505b6001600160a01b0381163b15611db9576040516376c0e6ed60e11b8152306004820152602481018490526001600160a01b0382169063ed81cdda90604401602060405180830381865afa925050508015611d91575060408051601f3d908101601f19168201909252611d8e918101906145ec565b60015b15611db95763328bf24b60e01b6001600160e01b0319821601611db75791506107d99050565b505b63cd740db560e01b179392505050565b600b546001600160a01b03163314611df35760405162461bcd60e51b81526004016108e690614572565b6001600160a01b0383166000908152601060209081526040808320858452909152902054839015611e5b5760405162461bcd60e51b8152602060048201526012602482015271746f6b656e20697320696e2062756e646c6560701b60448201526064016108e6565b6040516331a9108f60e11b81526004810184905230906001600160a01b03831690636352211e90602401602060405180830381865afa158015611ea2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ec691906146f3565b6001600160a01b031614611f0c5760405162461bcd60e51b815260206004820152600d60248201526c1b999d081b9bdd081bdddb9959609a1b60448201526064016108e6565b604051632142170760e11b81526001600160a01b038216906342842e0e90611f3c903090869088906004016144fd565b600060405180830381600087803b158015611f5657600080fd5b505af1158015611f6a573d6000803e3d6000fd5b5050505050505050565b606081600003611f9b5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611fc55780611faf816145bd565b9150611fbe9050600a83614726565b9150611f9f565b6000816001600160401b03811115611fdf57611fdf613be2565b6040519080825280601f01601f191660200182016040528015612009576020820181803683370190505b5090505b8415610b635761201e60018361473a565b915061202b600a8661474d565b612036906030614761565b60f81b81838151811061204b5761204b6145d6565b60200101906001600160f81b031916908160001a90535061206d600a86614726565b945061200d565b60006001600160e01b0319821663cde244d960e01b14806120a557506001600160e01b031982166328d12bf960e21b145b806120c05750630f7ef9b560e11b6001600160e01b03198316145b806107d957506107d982612ea4565b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906121048261102b565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610a808383612ec9565b7f000000000000000000000000dcb004c4ab4b9c12e6bb4ed7992bb78218e965206001600160a01b0316846001600160a01b03160315610fb957610fb984848484612ef3565b61219883612c9e565b6121a3848383612f8c565b610fb9848383612d92565b6000818152600260205260408120546001600160a01b03166122275760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016108e6565b60006122328361102b565b9050806001600160a01b0316846001600160a01b0316148061226d5750836001600160a01b031661226284610871565b6001600160a01b0316145b80610b635750610b638185611c29565b826001600160a01b03166122908261102b565b6001600160a01b0316146122f85760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016108e6565b6001600160a01b03821661235a5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016108e6565b612365838383613094565b6123706000826120cf565b6001600160a01b038316600090815260036020526040812080546001929061239990849061473a565b90915550506001600160a01b03821660009081526003602052604081208054600192906123c7908490614761565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600081511161246b5760405162461bcd60e51b815260206004820152600f60248201526e62756e646c6520697320656d70747960881b60448201526064016108e6565b805160005b8181146126cf5761249d83828151811061248c5761248c6145d6565b6020026020010151600001516110a2565b6124e05760405162461bcd60e51b8152602060048201526014602482015273195c98cdcc8c481b9bdd081c195c9b5a5d1d195960621b60448201526064016108e6565b8281815181106124f2576124f26145d6565b60200260200101516040015115612620576000838281518110612517576125176145d6565b60200260200101516020015151905060005b81811461261957848381518110612542576125426145d6565b6020026020010151600001516001600160a01b031663b88d4fde3330888781518110612570576125706145d6565b602002602001015160200151858151811061258d5761258d6145d6565b60200260200101518a6040516020016125a891815260200190565b6040516020818303038152906040526040518563ffffffff1660e01b81526004016125d69493929190614687565b600060405180830381600087803b1580156125f057600080fd5b505af1158015612604573d6000803e3d6000fd5b5050505080612612906145bd565b9050612529565b50506126bf565b6000838281518110612634576126346145d6565b60200260200101516020015151905060005b8181146126bc576126ac3387878681518110612664576126646145d6565b602002602001015160000151888781518110612682576126826145d6565b602002602001015160200151858151811061269f5761269f6145d6565b6020026020010151611838565b6126b5816145bd565b9050612646565b50505b6126c8816145bd565b9050612470565b50827faeecfeb34aeb11fe7449e04fbc8fc80d3ddd8eeb67b35e6c1b8e1b7e3d8f0257836040516127009190614774565b60405180910390a2505050565b60006107d9825490565b600c54600160a01b900460ff166127675760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016108e6565b600c805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6117f88282604051806020016040528060008152506130f7565b60008151116127ec5760405180602001604052806000815250612817565b806127f646611f74565b60405160200161280792919061482a565b6040516020818303038152906040525b6011906117f890826148b3565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610a6390849061312a565b600b80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600c54600160a01b900460ff16156128f25760405162461bcd60e51b81526004016108e69061449c565b600c805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586127973390565b60008151116129705760405162461bcd60e51b815260206004820152600f60248201526e62756e646c6520697320656d70747960881b60448201526064016108e6565b805160005b818114612b12576000838281518110612990576129906145d6565b602002602001015160000151905060008483815181106129b2576129b26145d6565b60200260200101516020015151905060005b818114612afe5760008685815181106129df576129df6145d6565b60200260200101516020015182815181106129fc576129fc6145d6565b60200260200101519050612a11888583612f8c565b612a1c888583612d92565b868581518110612a2e57612a2e6145d6565b60200260200101516040015115612aa657604051632142170760e11b81526001600160a01b038516906342842e0e90612a6f903090339086906004016144fd565b600060405180830381600087803b158015612a8957600080fd5b505af1158015612a9d573d6000803e3d6000fd5b50505050612ab1565b612ab1338583612bce565b836001600160a01b0316336001600160a01b031689600080516020614a3183398151915284604051612ae591815260200190565b60405180910390a450612af7816145bd565b90506129c4565b50505080612b0b906145bd565b9050612975565b50827ff60c055f56c20fcc9ca127b02b3958fad33fb25c41c195093e037d94fcc27008836040516127009190614774565b612b4e84848461227d565b612b5a848484846131fc565b610fb95760405162461bcd60e51b81526004016108e690614972565b612b7f826110a2565b612bc25760405162461bcd60e51b8152602060048201526014602482015273195c98cdcc8c481b9bdd081c195c9b5a5d1d195960621b60448201526064016108e6565b610fb9848484846132fd565b60405163095ea7b360e01b8152306004820152602481018290526001600160a01b0383169063095ea7b390604401600060405180830381600087803b158015612c1657600080fd5b505af1925050508015612c27575060015b506040516323b872dd60e01b81526001600160a01b038316906323b872dd90612c58903090879086906004016144fd565b600060405180830381600087803b158015612c7257600080fd5b505af1158015612c86573d6000803e3d6000fd5b50505050505050565b6060601180546107ee90614462565b6001600160a01b038116610ec75760405162461bcd60e51b815260206004820152601e60248201527f6368696c64207472616e7366657220746f207a65726f2061646472657373000060448201526064016108e6565b6000612cff82610df4565b90506001600160a01b038116331480612d28575033612d1d83610871565b6001600160a01b0316145b80612d385750612d388133611c29565b6117f85760405162461bcd60e51b815260206004820152602560248201527f7472616e736665724368696c64206d73672e73656e646572206e6f7420656c696044820152646769626c6560d81b60648201526084016108e6565b6000838152600f602090815260408083206001600160a01b03861684529091529020612dbe9082613444565b506001600160a01b03821660008181526010602090815260408083208584528252808320839055868352600f825280832093835292905220612dff9061270d565b600003610a63576000838152600e60205260409020610fb99083613450565b6001600160a01b0382166000908152601060209081526040808320848452909152812054808203612e915760405162461bcd60e51b815260206004820152601a60248201527f6368696c6420746f6b656e20646f6573206e6f7420657869737400000000000060448201526064016108e6565b612e9a8161102b565b91505b9250929050565b60006001600160e01b0319821663780e9d6360e01b14806107d957506107d982613465565b6000826000018281548110612ee057612ee06145d6565b9060005260206000200154905092915050565b6000815111612f6a5760405162461bcd60e51b815260206004820152603860248201527f64617461206d75737420636f6e7461696e20746f6b656e496420746f2074726160448201527f6e7366657220746865206368696c6420746f6b656e20746f000000000000000060648201526084016108e6565b6000612f77826020015190565b9050612f8585828686612b76565b5050505050565b6001600160a01b03821660009081526010602090815260408083208484529091528120549081900361301e5760405162461bcd60e51b815260206004820152603560248201527f5f7472616e736665724368696c64205f6368696c64436f6e7472616374205f636044820152741a1a5b19151bdad95b9259081b9bdd08199bdd5b99605a1b60648201526084016108e6565b83811461308b5760405162461bcd60e51b815260206004820152603560248201527f436f6d706f7361626c65546f70446f776e3a205f7472616e736665724368696c60448201527419081ddc9bdb99c81d1bdad95b925908199bdd5b99605a1b60648201526084016108e6565b610fb981612cf4565b306001600160a01b038316036130ec5760405162461bcd60e51b815260206004820152601a60248201527f6e65737465642062756e646c6573206e6f7420616c6c6f77656400000000000060448201526064016108e6565b610a638383836134b5565b613101838361356d565b61310e60008484846131fc565b610a635760405162461bcd60e51b81526004016108e690614972565b600061317f826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166136bb9092919063ffffffff16565b805190915015610a63578080602001905181019061319d91906149c4565b610a635760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016108e6565b60006001600160a01b0384163b156132f257604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290613240903390899088908890600401614687565b6020604051808303816000875af192505050801561327b575060408051601f3d908101601f19168201909252613278918101906149e1565b60015b6132d8573d8080156132a9576040519150601f19603f3d011682016040523d82523d6000602084013e6132ae565b606091505b5080516000036132d05760405162461bcd60e51b81526004016108e690614972565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610b63565b506001949350505050565b6000838152600260205260409020546001600160a01b03166133615760405162461bcd60e51b815260206004820152601d60248201527f62756e646c6520746f6b656e496420646f6573206e6f7420657869737400000060448201526064016108e6565b6000838152600f602090815260408083206001600160a01b0386168452909152812061338c9061270d565b9050806000036133b0576000848152600e602052604090206133ae90846136ca565b505b6000848152600f602090815260408083206001600160a01b038716845290915290206133dc90836136df565b506001600160a01b038381166000818152601060209081526040808320878452825291829020889055905185815291928792908916917f0371ddf2288ad1ba92626a7e31c86a9d006e592cfe57d7d946ef08b13457c08b910160405180910390a45050505050565b6000610a8083836136eb565b6000610a80836001600160a01b0384166136eb565b60006001600160e01b031982166380ac58cd60e01b148061349657506001600160e01b03198216635b5e139f60e01b145b806107d957506301ffc9a760e01b6001600160e01b03198316146107d9565b6001600160a01b0383166135105761350b81600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b613533565b816001600160a01b0316836001600160a01b0316146135335761353383826137de565b6001600160a01b03821661354a57610a638161387b565b826001600160a01b0316826001600160a01b031614610a6357610a63828261392a565b6001600160a01b0382166135c35760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016108e6565b6000818152600260205260409020546001600160a01b0316156136285760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016108e6565b61363460008383613094565b6001600160a01b038216600090815260036020526040812080546001929061365d908490614761565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6060610b63848460008561396e565b6000610a80836001600160a01b038416613a96565b6000610a808383613a96565b600081815260018301602052604081205480156137d457600061370f60018361473a565b85549091506000906137239060019061473a565b9050818114613788576000866000018281548110613743576137436145d6565b9060005260206000200154905080876000018481548110613766576137666145d6565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613799576137996149fe565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506107d9565b60009150506107d9565b600060016137eb846111ca565b6137f5919061473a565b600083815260076020526040902054909150808214613848576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b60085460009061388d9060019061473a565b600083815260096020526040812054600880549394509092849081106138b5576138b56145d6565b9060005260206000200154905080600883815481106138d6576138d66145d6565b600091825260208083209091019290925582815260099091526040808220849055858252812055600880548061390e5761390e6149fe565b6001900381819060005260206000200160009055905550505050565b6000613935836111ca565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6060824710156139cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016108e6565b843b613a1d5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108e6565b600080866001600160a01b03168587604051613a399190614a14565b60006040518083038185875af1925050503d8060008114613a76576040519150601f19603f3d011682016040523d82523d6000602084013e613a7b565b606091505b5091509150613a8b828286613ae5565b979650505050505050565b6000818152600183016020526040812054613add575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556107d9565b5060006107d9565b60608315613af4575081610a80565b825115613b045782518084602001fd5b8160405162461bcd60e51b81526004016108e69190613ba1565b6001600160e01b031981168114610ec757600080fd5b600060208284031215613b4657600080fd5b8135610a8081613b1e565b60005b83811015613b6c578181015183820152602001613b54565b50506000910152565b60008151808452613b8d816020860160208601613b51565b601f01601f19169290920160200192915050565b602081526000610a806020830184613b75565b600060208284031215613bc657600080fd5b5035919050565b6001600160a01b0381168114610ec757600080fd5b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b0381118282101715613c1a57613c1a613be2565b60405290565b604051601f8201601f191681016001600160401b0381118282101715613c4857613c48613be2565b604052919050565b60006001600160401b03831115613c6957613c69613be2565b613c7c601f8401601f1916602001613c20565b9050828152838383011115613c9057600080fd5b828260208301376000602084830101529392505050565b600082601f830112613cb857600080fd5b610a8083833560208501613c50565b60008060008060008060c08789031215613ce057600080fd5b863595506020870135613cf281613bcd565b9450604087013593506060870135613d0981613bcd565b92506080870135915060a08701356001600160401b03811115613d2b57600080fd5b613d3789828a01613ca7565b9150509295509295509295565b60008060408385031215613d5757600080fd5b8235613d6281613bcd565b946020939093013593505050565b60008060408385031215613d8357600080fd5b50508035926020909101359150565b60008083601f840112613da457600080fd5b5081356001600160401b03811115613dbb57600080fd5b602083019150836020828501011115612e9d57600080fd5b600080600080600060808688031215613deb57600080fd5b8535613df681613bcd565b94506020860135613e0681613bcd565b93506040860135925060608601356001600160401b03811115613e2857600080fd5b613e3488828901613d92565b969995985093965092949392505050565b600080600060608486031215613e5a57600080fd5b833592506020840135613e6c81613bcd565b929592945050506040919091013590565b60008060008060808587031215613e9357600080fd5b843593506020850135613ea581613bcd565b92506040850135613eb581613bcd565b9396929550929360600135925050565b600080600060608486031215613eda57600080fd5b8335613ee581613bcd565b92506020840135613e6c81613bcd565b60006001600160401b03821115613f0e57613f0e613be2565b5060051b60200190565b8015158114610ec757600080fd5b8035610dd481613f18565b600082601f830112613f4257600080fd5b81356020613f57613f5283613ef5565b613c20565b82815260059290921b84018101918181019086841115613f7657600080fd5b8286015b848110156140675780356001600160401b0380821115613f9a5760008081fd5b908801906060828b03601f1901811315613fb45760008081fd5b613fbc613bf8565b87840135613fc981613bcd565b815260408481013584811115613fdf5760008081fd5b85019350603f84018d13613ff35760008081fd5b88840135614003613f5282613ef5565b81815260059190911b85018201908a8101908f8311156140235760008081fd5b958301955b828710156140415786358252958b0195908b0190614028565b848c0152506140539050858401613f26565b908201528652505050918301918301613f7a565b509695505050505050565b60006020828403121561408457600080fd5b81356001600160401b0381111561409a57600080fd5b610b6384828501613f31565b600080604083850312156140b957600080fd5b8235915060208301356140cb81613bcd565b809150509250929050565b6000602082840312156140e857600080fd5b8135610a8081613bcd565b60006020828403121561410557600080fd5b81356001600160401b0381111561411b57600080fd5b8201601f8101841361412c57600080fd5b610b6384823560208401613c50565b6000806040838503121561414e57600080fd5b823561415981613bcd565b915060208301356140cb81613bcd565b6000806000806000806000806000806101208b8d03121561418957600080fd5b8a3561419481613bcd565b995060208b0135985060408b01356141ab81613bcd565b975060608b01356001600160401b038111156141c657600080fd5b6141d28d828e01613d92565b90985096505060808b01356141e681613bcd565b945060a08b0135935060c08b01356141fd81613f18565b925060e08b013591506101008b013561421581613bcd565b809150509295989b9194979a5092959850565b600080600080600060a0868803121561424057600080fd5b85359450602086013561425281613bcd565b9350604086013561426281613bcd565b92506060860135915060808601356001600160401b0381111561428457600080fd5b61429088828901613ca7565b9150509295509295909350565b600080604083850312156142b057600080fd5b82356142bb81613bcd565b915060208301356140cb81613f18565b600080604083850312156142de57600080fd5b8235915060208301356001600160401b038111156142fb57600080fd5b61430785828601613f31565b9150509250929050565b6000806000806080858703121561432757600080fd5b843561433281613bcd565b9350602085013561434281613bcd565b92506040850135915060608501356001600160401b0381111561436457600080fd5b61437087828801613ca7565b91505092959194509250565b6000806000806080858703121561439257600080fd5b843561439d81613bcd565b9350602085013592506040850135613eb581613bcd565b6000806000606084860312156143c957600080fd5b8335925060208401356001600160401b03808211156143e757600080fd5b6143f387838801613f31565b9350604086013591508082111561440957600080fd5b5061441686828701613f31565b9150509250925092565b60008060006060848603121561443557600080fd5b833561444081613bcd565b925060208401359150604084013561445781613bcd565b809150509250925092565b600181811c9082168061447657607f821691505b60208210810361449657634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052601160045260246000fd5b6000600182016145cf576145cf6145a7565b5060010190565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156145fe57600080fd5b5051919050565b6001600160a01b038b81168252602082018b9052898116604083015261012060608301819052820188905260009061014090898b838601376000848b0183015290971660808301525060a081019490945291151560c084015260e08301526001600160a01b0316610100820152601f909201601f191690910101949350505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906146ba90830184613b75565b9695505050505050565b600083516146d6818460208801613b51565b8351908301906146ea818360208801613b51565b01949350505050565b60006020828403121561470557600080fd5b8151610a8081613bcd565b634e487b7160e01b600052601260045260246000fd5b60008261473557614735614710565b500490565b818103818111156107d9576107d96145a7565b60008261475c5761475c614710565b500690565b808201808211156107d9576107d96145a7565b60006020808301818452808551808352604092508286019150828160051b8701018488016000805b8481101561481b57898403603f19018652825180516001600160a01b031685528881015160608a8701819052815190870181905260808701918b019085905b808210156147fb5782518452928c0192918c0191600191909101906147db565b50505090880151151594880194909452948701949187019160010161479c565b50919998505050505050505050565b6000835161483c818460208801613b51565b835190830190614850818360208801613b51565b602f60f81b9101908152600101949350505050565b601f821115610a6357600081815260208120601f850160051c8101602086101561488c5750805b601f850160051c820191505b818110156148ab57828155600101614898565b505050505050565b81516001600160401b038111156148cc576148cc613be2565b6148e0816148da8454614462565b84614865565b602080601f83116001811461491557600084156148fd5750858301515b600019600386901b1c1916600185901b1785556148ab565b600085815260208120601f198616915b8281101561494457888601518255948401946001909101908401614925565b50858210156149625787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6000602082840312156149d657600080fd5b8151610a8081613f18565b6000602082840312156149f357600080fd5b8151610a8081613b1e565b634e487b7160e01b600052603160045260246000fd5b60008251614a26818460208701613b51565b919091019291505056fe0ef52e516fb5aec15a5d3587e5480481b702b26db93c8430eca78b61990fd3f6a164736f6c6343000811000a
Verified Source Code Partial Match
Compiler: v0.8.17+commit.8df45f5f
EVM: london
Optimization: Yes (200 runs)
NftfiBundler.sol 364 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "./ERC998TopDown.sol";
import "./INftfiBundler.sol";
import "./IBundleBuilder.sol";
import "./IPermittedNFTs.sol";
import "./utils/Ownable.sol";
import "./airdrop/AirdropFlashLoan.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
/**
* @title NftfiBundler
* @author NFTfi
* @dev ERC998 Top-Down Composable Non-Fungible Token that supports ERC721 children.
*/
contract NftfiBundler is ERC998TopDown, IBundleBuilder {
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableSet for EnumerableSet.AddressSet;
using SafeERC20 for IERC20;
using Strings for uint256;
address public immutable permittedNfts;
address public immutable airdropFlashLoan;
string public baseURI;
/**
* @dev Stores name and symbol
*
* @param _admin - Initial admin of this contract.
* @param _name name of the token contract
* @param _symbol symbol of the token contract
*/
constructor(
address _admin,
string memory _name,
string memory _symbol,
string memory _customBaseURI,
address _permittedNfts,
address _airdropFlashLoan
) ERC721(_name, _symbol) ERC998TopDown(_admin) {
permittedNfts = _permittedNfts;
airdropFlashLoan = _airdropFlashLoan;
_setBaseURI(_customBaseURI);
_pause();
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 _interfaceId) public view virtual override returns (bool) {
return
_interfaceId == type(IERC721Receiver).interfaceId ||
_interfaceId == type(INftfiBundler).interfaceId ||
super.supportsInterface(_interfaceId);
}
/**
* @notice Tells if an asset is permitted or not
* @param _asset address of the asset
* @return true if permitted, false otherwise
*/
function permittedAsset(address _asset) public view returns (bool) {
IPermittedNFTs permittedNFTs = IPermittedNFTs(permittedNfts);
return permittedNFTs.getNFTPermit(_asset) > 0;
}
/**
* @dev used to build a bundle from the BundleElements struct,
* returns the id of the created bundle
*
* @param _bundleElements - the lists of erc721 tokens that are to be bundled
*/
function buildBundle(BundleElementERC721[] memory _bundleElements) external override returns (uint256) {
uint256 tokenId = safeMint(msg.sender);
_addBundleElements(tokenId, _bundleElements);
return tokenId;
}
/**
* @dev Adds a set of BundleElementERC721 objects to the specified token ID.
*
* @param _tokenId The ID of the token to add the bundle elements to.
* @param _bundleElements The array of BundleElementERC721 objects to add.
*/
function addBundleElements(uint256 _tokenId, BundleElementERC721[] memory _bundleElements) external {
_addBundleElements(_tokenId, _bundleElements);
}
/**
* @dev Removes a set of BundleElementERC721 objects to the specified token ID.
*
* @param _tokenId The ID of the token to remove the bundle elements from.
* @param _bundleElements The array of BundleElementERC721 objects to remove.
*/
function removeBundleElements(uint256 _tokenId, BundleElementERC721[] memory _bundleElements) external {
_removeBundleElements(_tokenId, _bundleElements);
}
/**
* @dev Adds and removes a set of BundleElementERC721 objects from the specified token ID.
*
* @param _tokenId The ID of the token to add and remove the bundle elements from.
* @param _toAdd The array of BundleElementERC721 objects to add.
* @param _toRemove The array of BundleElementERC721 objects to remove.
*/
function addAndRemoveBundleElements(
uint256 _tokenId,
BundleElementERC721[] memory _toAdd,
BundleElementERC721[] memory _toRemove
) external {
_addBundleElements(_tokenId, _toAdd);
_removeBundleElements(_tokenId, _toRemove);
}
/**
* @notice Remove all the children from the bundle
* @dev This method may run out of gas if the list of children is too big. In that case, children can be removed
* individually.
* @param _tokenId the id of the bundle
* @param _receiver address of the receiver of the children
*/
function decomposeBundle(uint256 _tokenId, address _receiver) external override {
_validateReceiver(_receiver);
_validateTransferSender(_tokenId);
// In each iteration all contracts children are removed, so eventually all contracts are removed
while (childContracts[_tokenId].length() > 0) {
address childContract = childContracts[_tokenId].at(0);
// In each iteration a child is removed, so eventually all contracts children are removed
while (childTokens[_tokenId][childContract].length() > 0) {
// has to re-validate against re-entry attack
_validateTransferSender(_tokenId);
uint256 childId = childTokens[_tokenId][childContract].at(0);
_removeChild(_tokenId, childContract, childId);
try IERC721(childContract).safeTransferFrom(address(this), _receiver, childId) {
// solhint-disable-previous-line no-empty-blocks
} catch {
_oldNFTsTransfer(_receiver, childContract, childId);
}
emit TransferChild(_tokenId, _receiver, childContract, childId);
}
}
}
/**
* @dev Internal function to add a set of BundleElementERC721 objects to the specified token ID.
*
* @param _tokenId The ID of the token to add the bundle elements to.
* @param _bundleElements The array of BundleElementERC721 objects to add.
*/
function _addBundleElements(uint256 _tokenId, BundleElementERC721[] memory _bundleElements) internal {
require(_bundleElements.length > 0, "bundle is empty");
uint256 elementNumber = _bundleElements.length;
for (uint256 i; i != elementNumber; ++i) {
require(permittedAsset(_bundleElements[i].tokenContract), "erc721 not permitted");
if (_bundleElements[i].safeTransferable) {
uint256 nuberOfIds = _bundleElements[i].ids.length;
for (uint256 j; j != nuberOfIds; ++j) {
IERC721(_bundleElements[i].tokenContract).safeTransferFrom(
msg.sender,
address(this),
_bundleElements[i].ids[j],
abi.encodePacked(_tokenId)
);
}
} else {
uint256 nuberOfIds = _bundleElements[i].ids.length;
for (uint256 j; j != nuberOfIds; ++j) {
getChild(msg.sender, _tokenId, _bundleElements[i].tokenContract, _bundleElements[i].ids[j]);
}
}
}
emit AddBundleElements(_tokenId, _bundleElements);
}
/**
* @dev Internal function to remove a set of BundleElementERC721 objects to the specified token ID.
*
* @param _tokenId The ID of the token to remove the bundle elements from.
* @param _bundleElements The array of BundleElementERC721 objects to remove.
*/
function _removeBundleElements(uint256 _tokenId, BundleElementERC721[] memory _bundleElements) internal {
require(_bundleElements.length > 0, "bundle is empty");
uint256 elementNumber = _bundleElements.length;
for (uint256 i; i != elementNumber; ++i) {
address erc721Contract = _bundleElements[i].tokenContract;
uint256 nuberOfIds = _bundleElements[i].ids.length;
for (uint256 j; j != nuberOfIds; ++j) {
uint256 childId = _bundleElements[i].ids[j];
_validateChildTransfer(_tokenId, erc721Contract, childId);
_removeChild(_tokenId, erc721Contract, childId);
if (_bundleElements[i].safeTransferable) {
IERC721(erc721Contract).safeTransferFrom(address(this), msg.sender, childId);
} else {
_oldNFTsTransfer(msg.sender, erc721Contract, childId);
}
emit TransferChild(_tokenId, msg.sender, erc721Contract, childId);
}
}
emit RemoveBundleElements(_tokenId, _bundleElements);
}
/**
* @dev Update the state to receive a ERC721 child
* Overrides the implementation to check if the asset is permitted
* @param _from The owner of the child token
* @param _tokenId The token receiving the child
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The token that is being transferred to the parent
*/
function _receiveChild(
address _from,
uint256 _tokenId,
address _childContract,
uint256 _childTokenId
) internal virtual override {
require(permittedAsset(_childContract), "erc721 not permitted");
super._receiveChild(_from, _tokenId, _childContract, _childTokenId);
}
/**
* @dev Override validation if it is a transfer from the airdropFlashLoan contract giving back the flashloan.
* Validates the data from a child transfer and receives it otherwise
* @param _from The owner of the child token
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The token that is being transferred to the parent
* @param _data Up to the first 32 bytes contains an integer which is the receiving parent tokenId
*/
function _validateAndReceiveChild(
address _from,
address _childContract,
uint256 _childTokenId,
bytes memory _data
) internal virtual override {
if (_from == airdropFlashLoan) {
return;
} else {
super._validateAndReceiveChild(_from, _childContract, _childTokenId, _data);
}
}
/**
* @notice this function initiates a flashloan to pull an airdrop from a tartget contract
*
* @param _nftContract - contract address of the target nft of the drop
* @param _nftId - id of the target nft of the drop
* @param _target - address of the airdropping contract
* @param _data - function selector to be called on the airdropping contract
* @param _nftAirdrop - address of the used claiming nft in the drop
* @param _nftAirdropId - id of the used claiming nft in the drop
* @param _is1155 -
* @param _nftAirdropAmount - amount in case of 1155
*/
function pullAirdrop(
address _nftContract,
uint256 _nftId,
address _target,
bytes calldata _data,
address _nftAirdrop,
uint256 _nftAirdropId,
bool _is1155,
uint256 _nftAirdropAmount,
address _beneficiary
) external {
uint256 tokenId = childTokenOwner[_nftContract][_nftId];
address rootOwner = address(uint160(uint256(rootOwnerOf(tokenId))));
require(rootOwner == msg.sender, "pullAirdrop msg.sender not eligible");
IERC721(_nftContract).safeTransferFrom(address(this), airdropFlashLoan, _nftId);
AirdropFlashLoan(airdropFlashLoan).pullAirdrop(
_nftContract,
_nftId,
_target,
_data,
_nftAirdrop,
_nftAirdropId,
_is1155,
_nftAirdropAmount,
_beneficiary
);
//take back collateral
IERC721(_nftContract).safeTransferFrom(airdropFlashLoan, address(this), _nftId);
}
/**
* @notice used by the owner account to be able to drain ERC721 tokens received as airdrops
* for the locked collateral NFT-s
* @param _tokenAddress - address of the token contract for the token to be sent out
* @param _tokenId - id token to be sent out
* @param _receiver - receiver of the token
*/
function rescueERC721(
address _tokenAddress,
uint256 _tokenId,
address _receiver
) external onlyOwner {
IERC721 tokenContract = IERC721(_tokenAddress);
require(childTokenOwner[_tokenAddress][_tokenId] == 0, "token is in bundle");
require(tokenContract.ownerOf(_tokenId) == address(this), "nft not owned");
tokenContract.safeTransferFrom(address(this), _receiver, _tokenId);
}
/**
* @notice used by the owner account to be able to drain ERC20 tokens received as airdrops
* for the locked collateral NFT-s
* @param _tokenAddress - address of the token contract for the token to be sent out
* @param _receiver - receiver of the token
*/
function rescueERC20(address _tokenAddress, address _receiver) external onlyOwner {
IERC20 tokenContract = IERC20(_tokenAddress);
uint256 amount = tokenContract.balanceOf(address(this));
require(amount > 0, "no tokens owned");
tokenContract.safeTransfer(_receiver, amount);
}
/**
* @dev Sets baseURI.
* @param _customBaseURI - Base URI
*/
function setBaseURI(string memory _customBaseURI) external onlyOwner {
_setBaseURI(_customBaseURI);
}
/**
* @dev Sets baseURI.
*/
function _setBaseURI(string memory _customBaseURI) internal virtual {
baseURI = bytes(_customBaseURI).length > 0
? string(abi.encodePacked(_customBaseURI, _getChainID().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`.
*/
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/**
* @dev This function gets the current chain ID.
*/
function _getChainID() internal view returns (uint256) {
uint256 id;
// solhint-disable-next-line no-inline-assembly
assembly {
id := chainid()
}
return id;
}
}
ERC998TopDown.sol 553 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "./utils/Ownable.sol";
import "./IERC998ERC721TopDown.sol";
import "./IERC998ERC721TopDownEnumerable.sol";
/**
* @title ERC998TopDown
* @author NFTfi
* @dev ERC998ERC721 Top-Down Composable Non-Fungible Token.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-998.md
* This implementation does not support children to be nested bundles, erc20 nor bottom-up
*/
abstract contract ERC998TopDown is
ERC721Enumerable,
IERC998ERC721TopDown,
IERC998ERC721TopDownEnumerable,
ReentrancyGuard,
Ownable,
Pausable
{
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableSet for EnumerableSet.AddressSet;
// return this.rootOwnerOf.selector ^ this.rootOwnerOfChild.selector ^
// this.tokenOwnerOf.selector ^ this.ownerOfChild.selector;
bytes32 public constant ERC998_MAGIC_VALUE = 0xcd740db500000000000000000000000000000000000000000000000000000000;
bytes32 internal constant ERC998_MAGIC_MASK = 0xffffffff00000000000000000000000000000000000000000000000000000000;
uint256 public tokenCount = 0;
// tokenId => child contract
mapping(uint256 => EnumerableSet.AddressSet) internal childContracts;
// tokenId => (child address => array of child tokens)
mapping(uint256 => mapping(address => EnumerableSet.UintSet)) internal childTokens;
// child address => childId => tokenId
// this is used for ERC721 type tokens
mapping(address => mapping(uint256 => uint256)) internal childTokenOwner;
/**
* @dev Stores the admin
*
* @param _admin address capable of pausing
*/
constructor(address _admin) Ownable(_admin) {
// solhint-disable-previous-line no-empty-blocks
}
/**
* @notice Tells whether the ERC721 type child exists or not
* @param _childContract The contract address of the child token
* @param _childTokenId The tokenId of the child
* @return True if the child exists, false otherwise
*/
function childExists(address _childContract, uint256 _childTokenId) external view virtual returns (bool) {
uint256 tokenId = childTokenOwner[_childContract][_childTokenId];
return tokenId != 0;
}
/**
* @notice Get the total number of child contracts with tokens that are owned by _tokenId
* @param _tokenId The parent token of child tokens in child contracts
* @return uint256 The total number of child contracts with tokens owned by _tokenId
*/
function totalChildContracts(uint256 _tokenId) public view virtual override returns (uint256) {
return childContracts[_tokenId].length();
}
/**
* @notice Get child contract by tokenId and index
* @param _tokenId The parent token of child tokens in child contract
* @param _index The index position of the child contract
* @return childContract The contract found at the _tokenId and index
*/
function childContractByIndex(uint256 _tokenId, uint256 _index)
external
view
virtual
override
returns (address childContract)
{
return childContracts[_tokenId].at(_index);
}
/**
* @notice Get the total number of child tokens owned by tokenId that exist in a child contract
* @param _tokenId The parent token of child tokens
* @param _childContract The child contract containing the child tokens
* @return uint256 The total number of child tokens found in child contract that are owned by _tokenId
*/
function totalChildTokens(uint256 _tokenId, address _childContract) external view override returns (uint256) {
return childTokens[_tokenId][_childContract].length();
}
/**
* @notice Get child token owned by _tokenId, in child contract, at index position
* @param _tokenId The parent token of the child token
* @param _childContract The child contract of the child token
* @param _index The index position of the child token
* @return childTokenId The child tokenId for the parent token, child token and index
*/
function childTokenByIndex(
uint256 _tokenId,
address _childContract,
uint256 _index
) external view virtual override returns (uint256 childTokenId) {
return childTokens[_tokenId][_childContract].at(_index);
}
/**
* @notice Get the parent tokenId and its owner of a ERC721 child token
* @param _childContract The contract address of the child token
* @param _childTokenId The tokenId of the child
* @return parentTokenOwner The parent address of the parent token and ERC998 magic value
* @return parentTokenId The parent tokenId of _childTokenId
*/
function ownerOfChild(address _childContract, uint256 _childTokenId)
external
view
virtual
override
returns (bytes32 parentTokenOwner, uint256 parentTokenId)
{
parentTokenId = childTokenOwner[_childContract][_childTokenId];
require(parentTokenId != 0, "child token does not exist");
address parentTokenOwnerAddress = ownerOf(parentTokenId);
// solhint-disable-next-line no-inline-assembly
assembly {
parentTokenOwner := or(ERC998_MAGIC_VALUE, parentTokenOwnerAddress)
}
}
/**
* @notice Get the root owner of tokenId
* @param _tokenId The token to query for a root owner address
* @return rootOwner The root owner at the top of tree of tokens and ERC998 magic value.
*/
function rootOwnerOf(uint256 _tokenId) public view virtual override returns (bytes32 rootOwner) {
return rootOwnerOfChild(address(0), _tokenId);
}
/**
* @notice Get the root owner of a child token
* @dev Returns the owner at the top of the tree of composables
* Use Cases handled:
* - Case 1: Token owner is this contract and token.
* - Case 2: Token owner is other external top-down composable
* - Case 3: Token owner is other contract
* - Case 4: Token owner is user
* @param _childContract The contract address of the child token
* @param _childTokenId The tokenId of the child
* @return rootOwner The root owner at the top of tree of tokens and ERC998 magic value
*/
function rootOwnerOfChild(address _childContract, uint256 _childTokenId)
public
view
virtual
override
returns (bytes32 rootOwner)
{
address rootOwnerAddress;
if (_childContract != address(0)) {
(rootOwnerAddress, _childTokenId) = _ownerOfChild(_childContract, _childTokenId);
} else {
rootOwnerAddress = ownerOf(_childTokenId);
}
if (rootOwnerAddress.isContract()) {
try IERC998ERC721TopDown(rootOwnerAddress).rootOwnerOfChild(address(this), _childTokenId) returns (
bytes32 returnedRootOwner
) {
// Case 2: Token owner is other external top-down composable
if (returnedRootOwner & ERC998_MAGIC_MASK == ERC998_MAGIC_VALUE) {
return returnedRootOwner;
}
} catch {
// solhint-disable-previous-line no-empty-blocks
}
}
// Case 3: Token owner is other contract
// Or
// Case 4: Token owner is user
// solhint-disable-next-line no-inline-assembly
assembly {
rootOwner := or(ERC998_MAGIC_VALUE, rootOwnerAddress)
}
return rootOwner;
}
/**
* @dev See {IERC165-supportsInterface}.
* The interface id 0x1efdf36a is added. The spec claims it to be the interface id of IERC998ERC721TopDown.
* But it is not.
* It is added anyway in case some contract checks it being compliant with the spec.
*/
function supportsInterface(bytes4 _interfaceId) public view virtual override(ERC721Enumerable) returns (bool) {
return
_interfaceId == type(IERC998ERC721TopDown).interfaceId ||
_interfaceId == type(IERC998ERC721TopDownEnumerable).interfaceId ||
_interfaceId == 0x1efdf36a ||
super.supportsInterface(_interfaceId);
}
/**
* @notice Mints a new bundle
* @param _to The address that owns the new bundle
* @return The id of the new bundle
*/
function safeMint(address _to) public virtual whenNotPaused returns (uint256) {
uint256 id = ++tokenCount;
_safeMint(_to, id);
return id;
}
/**
* @notice Transfer child token from top-down composable to address
* @param _fromTokenId The owning token to transfer from
* @param _to The address that receives the child token
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The tokenId of the token that is being transferred
*/
function safeTransferChild(
uint256 _fromTokenId,
address _to,
address _childContract,
uint256 _childTokenId
) external virtual override nonReentrant {
_transferChild(_fromTokenId, _to, _childContract, _childTokenId);
IERC721(_childContract).safeTransferFrom(address(this), _to, _childTokenId);
emit TransferChild(_fromTokenId, _to, _childContract, _childTokenId);
}
/**
* @notice Transfer child token from top-down composable to address or other top-down composable
* @param _fromTokenId The owning token to transfer from
* @param _to The address that receives the child token
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The tokenId of the token that is being transferred
* @param _data Additional data with no specified format
*/
function safeTransferChild(
uint256 _fromTokenId,
address _to,
address _childContract,
uint256 _childTokenId,
bytes memory _data
) external virtual override nonReentrant {
_transferChild(_fromTokenId, _to, _childContract, _childTokenId);
if (_to == address(this)) {
_validateAndReceiveChild(msg.sender, _childContract, _childTokenId, _data);
} else {
IERC721(_childContract).safeTransferFrom(address(this), _to, _childTokenId, _data);
emit TransferChild(_fromTokenId, _to, _childContract, _childTokenId);
}
}
/**
* @dev Transfer child token from top-down composable to address
* @param _fromTokenId The owning token to transfer from
* @param _to The address that receives the child token
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The tokenId of the token that is being transferred
*/
function transferChild(
uint256 _fromTokenId,
address _to,
address _childContract,
uint256 _childTokenId
) external virtual override nonReentrant {
_transferChild(_fromTokenId, _to, _childContract, _childTokenId);
_oldNFTsTransfer(_to, _childContract, _childTokenId);
emit TransferChild(_fromTokenId, _to, _childContract, _childTokenId);
}
/**
* @notice NOT SUPPORTED
* Intended to transfer bottom-up composable child token from top-down composable to other ERC721 token.
*/
function transferChildToParent(
uint256,
address,
uint256,
address,
uint256,
bytes memory
) external virtual override {
revert("BOTTOM_UP_CHILD_NOT_SUPPORTED");
}
/**
* @notice Transfer a child token from an ERC721 contract to a composable. Used for old tokens that does not
* have a safeTransferFrom method like cryptokitties
* @dev This contract has to be approved first in _childContract
* @param _from The address that owns the child token.
* @param _tokenId The token that becomes the parent owner
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The tokenId of the child token
*/
function getChild(
address _from,
uint256 _tokenId,
address _childContract,
uint256 _childTokenId
) public virtual override whenNotPaused nonReentrant {
require(_from == msg.sender, "_from should be msg.sender");
_receiveChild(_from, _tokenId, _childContract, _childTokenId);
IERC721(_childContract).transferFrom(_from, address(this), _childTokenId);
}
/**
* @notice A token receives a child token
* param The address that caused the transfer
* @param _from The owner of the child token
* @param _childTokenId The token that is being transferred to the parent
* @param _data Up to the first 32 bytes contains an integer which is the receiving parent tokenId
* @return the selector of this method
*/
function onERC721Received(
address,
address _from,
uint256 _childTokenId,
bytes calldata _data
) external virtual override whenNotPaused nonReentrant returns (bytes4) {
_validateAndReceiveChild(_from, msg.sender, _childTokenId, _data);
return this.onERC721Received.selector;
}
/**
* @dev ERC721 implementation hook that is called before any token transfer. Prevents nested bundles
* @param _from address of the current owner of the token
* @param _to destination address
* @param _tokenId id of the token to transfer
*/
function _beforeTokenTransfer(
address _from,
address _to,
uint256 _tokenId
) internal virtual override {
require(_to != address(this), "nested bundles not allowed");
super._beforeTokenTransfer(_from, _to, _tokenId);
}
/**
* @dev Validates the child transfer parameters and remove the child from the bundle
* @param _fromTokenId The owning token to transfer from
* @param _to The address that receives the child token
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The tokenId of the token that is being transferred
*/
function _transferChild(
uint256 _fromTokenId,
address _to,
address _childContract,
uint256 _childTokenId
) internal virtual {
_validateReceiver(_to);
_validateChildTransfer(_fromTokenId, _childContract, _childTokenId);
_removeChild(_fromTokenId, _childContract, _childTokenId);
}
/**
* @dev Validates the child transfer parameters
* @param _fromTokenId The owning token to transfer from
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The tokenId of the token that is being transferred
*/
function _validateChildTransfer(
uint256 _fromTokenId,
address _childContract,
uint256 _childTokenId
) internal virtual {
uint256 tokenId = childTokenOwner[_childContract][_childTokenId];
require(tokenId != 0, "_transferChild _childContract _childTokenId not found");
require(tokenId == _fromTokenId, "ComposableTopDown: _transferChild wrong tokenId found");
_validateTransferSender(tokenId);
}
/**
* @dev Validates the receiver of a child transfer
* @param _to The address that receives the child token
*/
function _validateReceiver(address _to) internal virtual {
require(_to != address(0), "child transfer to zero address");
}
/**
* @dev Updates the state to remove a child
* @param _tokenId The owning token to transfer from
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The tokenId of the token that is being transferred
*/
function _removeChild(
uint256 _tokenId,
address _childContract,
uint256 _childTokenId
) internal virtual {
// remove child token
childTokens[_tokenId][_childContract].remove(_childTokenId);
delete childTokenOwner[_childContract][_childTokenId];
// remove contract
if (childTokens[_tokenId][_childContract].length() == 0) {
childContracts[_tokenId].remove(_childContract);
}
}
/**
* @dev Validates the data from a child transfer and receives it
* @param _from The owner of the child token
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The token that is being transferred to the parent
* @param _data Up to the first 32 bytes contains an integer which is the receiving parent tokenId
*/
function _validateAndReceiveChild(
address _from,
address _childContract,
uint256 _childTokenId,
bytes memory _data
) internal virtual {
require(_data.length > 0, "data must contain tokenId to transfer the child token to");
// convert up to 32 bytes of _data to uint256, owner nft tokenId passed as uint in bytes
uint256 tokenId = _parseTokenId(_data);
_receiveChild(_from, tokenId, _childContract, _childTokenId);
}
/**
* @dev Update the state to receive a child
* @param _from The owner of the child token
* @param _tokenId The token receiving the child
* @param _childContract The ERC721 contract of the child token
* @param _childTokenId The token that is being transferred to the parent
*/
function _receiveChild(
address _from,
uint256 _tokenId,
address _childContract,
uint256 _childTokenId
) internal virtual {
require(_exists(_tokenId), "bundle tokenId does not exist");
uint256 childTokensLength = childTokens[_tokenId][_childContract].length();
if (childTokensLength == 0) {
childContracts[_tokenId].add(_childContract);
}
childTokens[_tokenId][_childContract].add(_childTokenId);
childTokenOwner[_childContract][_childTokenId] = _tokenId;
emit ReceivedChild(_from, _tokenId, _childContract, _childTokenId);
}
/**
* @dev Returns the owner of a child
* @param _childContract The contract address of the child token
* @param _childTokenId The tokenId of the child
* @return parentTokenOwner The parent address of the parent token and ERC998 magic value
* @return parentTokenId The parent tokenId of _childTokenId
*/
function _ownerOfChild(address _childContract, uint256 _childTokenId)
internal
view
virtual
returns (address parentTokenOwner, uint256 parentTokenId)
{
parentTokenId = childTokenOwner[_childContract][_childTokenId];
require(parentTokenId != 0, "child token does not exist");
return (ownerOf(parentTokenId), parentTokenId);
}
/**
* @dev Convert up to 32 bytes of_data to uint256, owner nft tokenId passed as uint in bytes
* @param _data Up to the first 32 bytes contains an integer which is the receiving parent tokenId
* @return tokenId the token Id encoded in the data
*/
function _parseTokenId(bytes memory _data) internal pure virtual returns (uint256 tokenId) {
// solhint-disable-next-line no-inline-assembly
assembly {
tokenId := mload(add(_data, 0x20))
}
}
/**
* @dev Transfers the NFT using method compatible with old token contracts
* @param _to address of the receiver of the children
* @param _childContract The contract address of the child token
* @param _childTokenId The tokenId of the child
*/
function _oldNFTsTransfer(
address _to,
address _childContract,
uint256 _childTokenId
) internal {
// This is here to be compatible with cryptokitties and other old contracts that require being owner and
// approved before transferring.
// Does not work with current standard which does not allow approving self, so we must let it fail in that case.
try IERC721(_childContract).approve(address(this), _childTokenId) {
// solhint-disable-previous-line no-empty-blocks
} catch {
// solhint-disable-previous-line no-empty-blocks
}
IERC721(_childContract).transferFrom(address(this), _to, _childTokenId);
}
/**
* @notice Validates that the sender is authorized to perform a child transfer
* @param _fromTokenId The owning token to transfer from
*/
function _validateTransferSender(uint256 _fromTokenId) internal virtual {
address rootOwner = address(uint160(uint256(rootOwnerOf(_fromTokenId))));
require(
rootOwner == msg.sender ||
getApproved(_fromTokenId) == msg.sender ||
isApprovedForAll(rootOwner, msg.sender),
"transferChild msg.sender not eligible"
);
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - Only the owner can call this method.
* - The contract must not be paused.
*/
function pause() external onlyOwner {
_pause();
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - Only the owner can call this method.
* - The contract must be paused.
*/
function unpause() external onlyOwner {
_unpause();
}
}
INftfiBundler.sol 11 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
interface INftfiBundler is IERC721 {
function safeMint(address _to) external returns (uint256);
function decomposeBundle(uint256 _tokenId, address _receiver) external;
}
Ownable.sol 83 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import "@openzeppelin/contracts/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.
*
* Modified version from openzeppelin/contracts/access/Ownable.sol that allows to
* initialize the owner using a parameter in the constructor
*/
abstract contract Ownable is Context {
address private _owner;
address private _ownerCandidate;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor(address _initialOwner) {
_setOwner(_initialOwner);
}
/**
* @dev Requests transferring ownership of the contract to a new account (`_newOwnerCandidate`).
* Can only be called by the current owner.
*/
function requestTransferOwnership(address _newOwnerCandidate) public virtual onlyOwner {
require(_newOwnerCandidate != address(0), "Ownable: new owner is the zero address");
_ownerCandidate = _newOwnerCandidate;
}
function acceptTransferOwnership() public virtual {
require(_ownerCandidate == _msgSender(), "Ownable: not owner candidate");
_setOwner(_ownerCandidate);
delete _ownerCandidate;
}
function cancelTransferOwnership() public virtual onlyOwner {
delete _ownerCandidate;
}
function rejectTransferOwnership() public virtual {
require(_ownerCandidate == _msgSender(), "Ownable: not owner candidate");
delete _ownerCandidate;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Sets the owner.
*/
function _setOwner(address _newOwner) internal {
address oldOwner = _owner;
_owner = _newOwner;
emit OwnershipTransferred(oldOwner, _newOwner);
}
}
IBundleBuilder.sol 38 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
interface IBundleBuilder {
/**
* @notice data of a erc721 bundle element
*
* @param tokenContract - address of the token contract
* @param id - id of the token
* @param safeTransferable - wether the implementing token contract has a safeTransfer function or not
*/
struct BundleElementERC721 {
address tokenContract;
uint256[] ids;
bool safeTransferable;
}
/**
* @notice used to build a bundle from the BundleElements struct,
* returns the id of the created bundle
*
* @param _bundleElements - the lists of erc721 tokens that are to be bundled
*/
function buildBundle(BundleElementERC721[] memory _bundleElements) external returns (uint256);
/**
* @notice Remove all the children from the bundle
* @dev This method may run out of gas if the list of children is too big. In that case, children can be removed
* individually or in smaller batches.
* @param _tokenId the id of the bundle
* @param _receiver address of the receiver of the children
*/
function decomposeBundle(uint256 _tokenId, address _receiver) external;
event AddBundleElements(uint256 indexed _tokenId, BundleElementERC721[] _bundleElements);
event RemoveBundleElements(uint256 indexed _tokenId, BundleElementERC721[] _bundleElements);
}
IPermittedNFTs.sol 7 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
interface IPermittedNFTs {
function getNFTPermit(address _nftContract) external view returns (bytes32);
}
IERC998ERC721TopDown.sol 74 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
interface IERC998ERC721TopDown {
event ReceivedChild(
address indexed _from,
uint256 indexed _tokenId,
address indexed _childContract,
uint256 _childTokenId
);
event TransferChild(
uint256 indexed tokenId,
address indexed _to,
address indexed _childContract,
uint256 _childTokenId
);
function onERC721Received(
address _operator,
address _from,
uint256 _childTokenId,
bytes calldata _data
) external returns (bytes4);
function transferChild(
uint256 _fromTokenId,
address _to,
address _childContract,
uint256 _childTokenId
) external;
function safeTransferChild(
uint256 _fromTokenId,
address _to,
address _childContract,
uint256 _childTokenId
) external;
function safeTransferChild(
uint256 _fromTokenId,
address _to,
address _childContract,
uint256 _childTokenId,
bytes memory _data
) external;
function transferChildToParent(
uint256 _fromTokenId,
address _toContract,
uint256 _toTokenId,
address _childContract,
uint256 _childTokenId,
bytes memory _data
) external;
// getChild function enables older contracts like cryptokitties to be transferred into a composable
// The _childContract must approve this contract. Then getChild can be called.
function getChild(
address _from,
uint256 _tokenId,
address _childContract,
uint256 _childTokenId
) external;
function rootOwnerOf(uint256 _tokenId) external view returns (bytes32 rootOwner);
function rootOwnerOfChild(address _childContract, uint256 _childTokenId) external view returns (bytes32 rootOwner);
function ownerOfChild(address _childContract, uint256 _childTokenId)
external
view
returns (bytes32 parentTokenOwner, uint256 parentTokenId);
}
AirdropFlashLoan.sol 76 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
/**
* @title AirdropFlashLoan
* @author NFTfi
* @dev
*/
contract AirdropFlashLoan is ERC721Holder, ERC1155Holder, ReentrancyGuard {
using Address for address;
using SafeERC20 for IERC20;
/**
* @notice this function initiates a flashloan to pull an airdrop from a tartget contract
*
* @param _nftContract - contract address of the target nft of the drop
* @param _nftId - id of the target nft of the drop
* @param _target - address of the airdropping contract
* @param _data - function selector to be called on the airdropping contract
* @param _nftAirdrop - address of the used claiming nft in the drop
* @param _nftAirdropId - id of the used claiming nft in the drop
* @param _is1155 -
* @param _nftAirdropAmount - amount in case of 1155
* @param _beneficiary - address receiving the drop
*/
function pullAirdrop(
address _nftContract,
uint256 _nftId,
address _target,
bytes calldata _data,
address _nftAirdrop,
uint256 _nftAirdropId,
bool _is1155,
uint256 _nftAirdropAmount,
address _beneficiary
) external nonReentrant {
// assumes that the collateral nft has been transferreded to this contract before calling this function
_target.functionCall(_data);
// return the collateral
IERC721(_nftContract).approve(msg.sender, _nftId);
// in case that arbitray function from _target does not send the airdrop to a specified address
if (_nftAirdrop != address(0) && _beneficiary != address(0)) {
// send the airdrop to the beneficiary
if (_is1155) {
IERC1155(_nftAirdrop).safeTransferFrom(
address(this),
_beneficiary,
_nftAirdropId,
_nftAirdropAmount,
"0x"
);
} else {
IERC721(_nftAirdrop).safeTransferFrom(address(this), _beneficiary, _nftAirdropId);
}
}
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 _interfaceId) public view virtual override(ERC1155Receiver) returns (bool) {
return _interfaceId == type(IERC721Receiver).interfaceId || super.supportsInterface(_interfaceId);
}
}
Address.sol 210 lines
// SPDX-License-Identifier: MIT
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);
}
function _verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) private 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 23 lines
// SPDX-License-Identifier: MIT
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 66 lines
// SPDX-License-Identifier: MIT
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);
}
}
IERC998ERC721TopDownEnumerable.sol 17 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
interface IERC998ERC721TopDownEnumerable {
function totalChildContracts(uint256 _tokenId) external view returns (uint256);
function childContractByIndex(uint256 _tokenId, uint256 _index) external view returns (address childContract);
function totalChildTokens(uint256 _tokenId, address _childContract) external view returns (uint256);
function childTokenByIndex(
uint256 _tokenId,
address _childContract,
uint256 _index
) external view returns (uint256 childTokenId);
}
Pausable.sol 90 lines
// SPDX-License-Identifier: MIT
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 81 lines
// SPDX-License-Identifier: MIT
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 411 lines
// SPDX-License-Identifier: MIT
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 {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_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 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(to).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 142 lines
// SPDX-License-Identifier: MIT
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;
}
IERC1155.sol 124 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
ReentrancyGuard.sol 62 lines
// SPDX-License-Identifier: MIT
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 make 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 28 lines
// SPDX-License-Identifier: MIT
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 98 lines
// SPDX-License-Identifier: MIT
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 24 lines
// SPDX-License-Identifier: MIT
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);
}
EnumerableSet.sol 294 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
IERC721Receiver.sol 26 lines
// SPDX-License-Identifier: MIT
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);
}
IERC1155Receiver.sol 52 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev _Available since v3.1._
*/
interface IERC1155Receiver is IERC165 {
/**
@dev Handles the receipt of a single ERC1155 token type. This function is
called at the end of a `safeTransferFrom` after the balance has been updated.
To accept the transfer, this must return
`bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
(i.e. 0xf23a6e61, or its own function selector).
@param operator The address which initiated the transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param id The ID of the token being transferred
@param value The amount of tokens being transferred
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
@dev Handles the receipt of a multiple ERC1155 token types. This function
is called at the end of a `safeBatchTransferFrom` after the balances have
been updated. To accept the transfer(s), this must return
`bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
(i.e. 0xbc197c81, or its own function selector).
@param operator The address which initiated the batch transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param ids An array containing ids of each token being transferred (order and length must match values array)
@param values An array containing amounts of each token being transferred (order and length must match ids array)
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
ERC721Holder.sol 27 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
*/
contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
}
ERC1155Holder.sol 30 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ERC1155Receiver.sol";
/**
* @dev _Available since v3.1._
*/
contract ERC1155Holder is ERC1155Receiver {
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
ERC1155Receiver.sol 18 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC1155Receiver.sol";
import "../../../utils/introspection/ERC165.sol";
/**
* @dev _Available since v3.1._
*/
abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
}
IERC721Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
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 162 lines
// SPDX-License-Identifier: MIT
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();
}
}
IERC721Enumerable.sol 28 lines
// SPDX-License-Identifier: MIT
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
ERC998_MAGIC_VALUE 0x22ab2e6f → bytes32
airdropFlashLoan 0x804f3fb2 → address
balanceOf 0x70a08231 → uint256
baseURI 0x6c0360eb → string
childContractByIndex 0x0d5a621b → address
childExists 0x5680a3ad → bool
childTokenByIndex 0x160b01a1 → uint256
getApproved 0x081812fc → address
isApprovedForAll 0xe985e9c5 → bool
name 0x06fdde03 → string
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
ownerOfChild 0xeadb80b8 → bytes32, uint256
paused 0x5c975abb → bool
permittedAsset 0x676a196a → bool
permittedNfts 0x01cf6902 → address
rootOwnerOf 0x43a61a8e → bytes32
rootOwnerOfChild 0xed81cdda → bytes32
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenByIndex 0x4f6ccce7 → uint256
tokenCount 0x9f181b5e → uint256
tokenOfOwnerByIndex 0x2f745c59 → uint256
tokenURI 0xc87b56dd → string
totalChildContracts 0x8da7d0b5 → uint256
totalChildTokens 0x35b21ceb → uint256
totalSupply 0x18160ddd → uint256
Write Contract 27 functions
These functions modify contract state and require a wallet transaction to execute.
acceptTransferOwnership 0x7b371107
No parameters
addAndRemoveBundleElements 0x660d0b24
uint256 _tokenId
tuple[] _toAdd
tuple[] _toRemove
addBundleElements 0x5cdca8b3
uint256 _tokenId
tuple[] _bundleElements
approve 0x095ea7b3
address to
uint256 tokenId
buildBundle 0xf8647e89
tuple[] _bundleElements
returns: uint256
cancelTransferOwnership 0x92fede00
No parameters
decomposeBundle 0xdf749086
uint256 _tokenId
address _receiver
getChild 0xba6b5f96
address _from
uint256 _tokenId
address _childContract
uint256 _childTokenId
onERC721Received 0x150b7a02
address
address _from
uint256 _childTokenId
bytes _data
returns: bytes4
pause 0x8456cb59
No parameters
pullAirdrop 0x7eef0896
address _nftContract
uint256 _nftId
address _target
bytes _data
address _nftAirdrop
uint256 _nftAirdropId
bool _is1155
uint256 _nftAirdropAmount
address _beneficiary
rejectTransferOwnership 0x5f992fdd
No parameters
removeBundleElements 0xaa730886
uint256 _tokenId
tuple[] _bundleElements
requestTransferOwnership 0x9d6fa618
address _newOwnerCandidate
rescueERC20 0x5d799f87
address _tokenAddress
address _receiver
rescueERC721 0xfa3e4705
address _tokenAddress
uint256 _tokenId
address _receiver
safeMint 0x40d097c3
address _to
returns: uint256
safeTransferChild 0x1d98f3c5
uint256 _fromTokenId
address _to
address _childContract
uint256 _childTokenId
safeTransferChild 0x8d81f51e
uint256 _fromTokenId
address _to
address _childContract
uint256 _childTokenId
bytes _data
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes _data
setApprovalForAll 0xa22cb465
address operator
bool approved
setBaseURI 0x55f804b3
string _customBaseURI
transferChild 0xbef44f18
uint256 _fromTokenId
address _to
address _childContract
uint256 _childTokenId
transferChildToParent 0x08937f62
uint256
address
uint256
address
uint256
bytes
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
unpause 0x3f4ba83a
No parameters
Recent Transactions
No transactions found for this address