Address Contract Verified
Address
0x6590DFF6abEd7C077839E8227A4f12Ec90E6D85F
Balance
0 ETH
Nonce
1
Code Size
10350 bytes
Creator
0x12369488...4cAf at tx 0x4c3f998e...d19231
Indexed Transactions
0
Contract Bytecode
10350 bytes
0x608060405234801561001057600080fd5b50600436106101a95760003560e01c80638da5cb5b116100f9578063b766bd8a11610097578063ea1a4e6811610071578063ea1a4e6814610428578063f257a1a014610446578063f2fde38b14610462578063fe7294a81461047e576101a9565b8063b766bd8a146103d0578063bb81268c14610400578063c2b4aa751461040a576101a9565b8063a0712d68116100d3578063a0712d681461035c578063ad3b1b4714610378578063b0b5489514610394578063b29b95ce146103b2576101a9565b80638da5cb5b146103045780638f4ffcb11461032257806395de5a411461033e576101a9565b80632d42067d116101665780635bf32f52116101405780635bf32f52146102a65780636386d0b1146102c257806364e779b1146102de578063715018a6146102fa576101a9565b80632d42067d1461024e5780633678252f1461026a57806351b83ebc14610288576101a9565b806305e448fc146101ae5780630bb037df146101cc5780630c05ab39146101ea5780630c505b7a1461020857806320ad25dc14610226578063240b57e814610230575b600080fd5b6101b661049c565b6040516101c3919061223d565b60405180910390f35b6101d46104a2565b6040516101e1919061223d565b60405180910390f35b6101f26104b8565b6040516101ff9190611fca565b60405180910390f35b6102106104de565b60405161021d919061223d565b60405180910390f35b61022e6104e4565b005b6102386105c5565b604051610245919061223d565b60405180910390f35b61026860048036038101906102639190611be6565b6105cb565b005b610272610711565b60405161027f9190612045565b60405180910390f35b610290610735565b60405161029d919061223d565b60405180910390f35b6102c060048036038101906102bb9190611cf4565b610741565b005b6102dc60048036038101906102d79190611be6565b61081d565b005b6102f860048036038101906102f39190611cf4565b6109a3565b005b610302610c1f565b005b61030c610ca7565b6040516103199190611fca565b60405180910390f35b61033c60048036038101906103379190611c4b565b610cd0565b005b610346610dfd565b6040516103539190612060565b60405180910390f35b61037660048036038101906103719190611cf4565b610e21565b005b610392600480360381019061038d9190611c0f565b610e2e565b005b61039c610ef9565b6040516103a9919061223d565b60405180910390f35b6103ba610f00565b6040516103c7919061223d565b60405180910390f35b6103ea60048036038101906103e59190611cf4565b610f06565b6040516103f7919061223d565b60405180910390f35b610408610f30565b005b610412611224565b60405161041f919061223d565b60405180910390f35b61043061123a565b60405161043d9190611fca565b60405180910390f35b610460600480360381019061045b9190611be6565b611260565b005b61047c60048036038101906104779190611be6565b6113a6565b005b61048661149e565b6040516104939190611fca565b60405180910390f35b60065481565b60006104b360065462093a806114c4565b905090565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60015481565b6104ec61153f565b73ffffffffffffffffffffffffffffffffffffffff1661050a610ca7565b73ffffffffffffffffffffffffffffffffffffffff1614610560576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105579061213d565b60405180910390fd5b6003546105708162093a80611547565b7f3fd2a429fdc4324c186eb6c71dc1bf3accae43e10f21367f6d143635dd5ed33c6002546040516105a1919061223d565b60405180910390a16002546001819055506000600281905550600060038190555050565b60025481565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461065c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106539061215d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156106cc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106c3906121bd565b60405180910390fd5b81600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b7f0000000000000000000000008daebade922df735c38c80c7ebd708af50815faa81565b670de0b6b3a764000081565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146107d2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c99061215d565b60405180910390fd5b7f0ddb39c814329b5da82b52fcacf65e4db6a1f64a0db4755282bee877cb97991a8242604051610803929190612258565b60405180910390a181600281905550426003819055505050565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108ae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108a59061215d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561091e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109159061217d565b60405180910390fd5b7f424e3c8894757dd6fd019d0d8065b19c7e49af137aeb89a275ed3d2435025a96824260405161094f92919061201c565b60405180910390a181600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550426006819055505050565b60006109ae82610f06565b90503373ffffffffffffffffffffffffffffffffffffffff167fe8a2f49c528033a686bb566d35ac82ca6fd93449bdd9f5d5b36c2f1aa68214b383836040516109f8929190612258565b60405180910390a28082610a0c91906122b3565b7f00000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a8873ffffffffffffffffffffffffffffffffffffffff166370a08231336040518263ffffffff1660e01b8152600401610a659190611fca565b60206040518083038186803b158015610a7d57600080fd5b505afa158015610a91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ab59190611d1d565b1015610af6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610aed9061209d565b60405180910390fd5b610b433330837f00000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a8873ffffffffffffffffffffffffffffffffffffffff166115dc909392919063ffffffff16565b7f00000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a8873ffffffffffffffffffffffffffffffffffffffff166379cc679033846040518363ffffffff1660e01b8152600401610b9e92919061201c565b600060405180830381600087803b158015610bb857600080fd5b505af1158015610bcc573d6000803e3d6000fd5b50505050610c1b33837f0000000000000000000000008daebade922df735c38c80c7ebd708af50815faa73ffffffffffffffffffffffffffffffffffffffff166116659092919063ffffffff16565b5050565b610c2761153f565b73ffffffffffffffffffffffffffffffffffffffff16610c45610ca7565b73ffffffffffffffffffffffffffffffffffffffff1614610c9b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c929061213d565b60405180910390fd5b610ca560006116eb565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b7f0000000000000000000000008daebade922df735c38c80c7ebd708af50815faa73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614610d5e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d55906121fd565b60405180910390fd5b7f0000000000000000000000008daebade922df735c38c80c7ebd708af50815faa73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610dec576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610de39061221d565b60405180910390fd5b610df685856117af565b5050505050565b7f00000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a8881565b610e2b33826117af565b50565b610e3661153f565b73ffffffffffffffffffffffffffffffffffffffff16610e54610ca7565b73ffffffffffffffffffffffffffffffffffffffff1614610eaa576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ea19061213d565b60405180910390fd5b610ef582827f00000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a8873ffffffffffffffffffffffffffffffffffffffff166116659092919063ffffffff16565b5050565b62093a8081565b60035481565b6000670de0b6b3a764000060015483610f1f919061233a565b610f299190612309565b9050919050565b610f3861153f565b73ffffffffffffffffffffffffffffffffffffffff16610f56610ca7565b73ffffffffffffffffffffffffffffffffffffffff1614610fac576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fa39061213d565b60405180910390fd5b600654610fbc8162093a80611547565b7f99610bc40a14194a7a819ffeded94200b49e68ba00bc3a3ab89625c0972217ff600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660405161100d9190611fca565b60405180910390a17f00000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a8873ffffffffffffffffffffffffffffffffffffffff1663f2fde38b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff1660e01b81526004016110909190611fca565b600060405180830381600087803b1580156110aa57600080fd5b505af11580156110be573d6000803e3d6000fd5b505050506111d7600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167f0000000000000000000000008daebade922df735c38c80c7ebd708af50815faa73ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016111419190611fca565b60206040518083038186803b15801561115957600080fd5b505afa15801561116d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111919190611d1d565b7f0000000000000000000000008daebade922df735c38c80c7ebd708af50815faa73ffffffffffffffffffffffffffffffffffffffff166116659092919063ffffffff16565b6000600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600060068190555050565b600061123560035462093a806114c4565b905090565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146112f1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112e89061215d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611361576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611358906121bd565b60405180910390fd5b81600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b6113ae61153f565b73ffffffffffffffffffffffffffffffffffffffff166113cc610ca7565b73ffffffffffffffffffffffffffffffffffffffff1614611422576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114199061213d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611492576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611489906120bd565b60405180910390fd5b61149b816116eb565b50565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000808311611508576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114ff906120fd565b60405180910390fd5b600083426115169190612394565b9050828110611529576000915050611539565b80836115359190612394565b9150505b92915050565b600033905090565b6000821161158a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611581906120fd565b60405180910390fd5b8082426115979190612394565b10156115d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115cf9061211d565b60405180910390fd5b5050565b61165f846323b872dd60e01b8585856040516024016115fd93929190611fe5565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506118db565b50505050565b6116e68363a9059cbb60e01b848460405160240161168492919061201c565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506118db565b505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b8173ffffffffffffffffffffffffffffffffffffffff167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe826040516117f5919061223d565b60405180910390a261184a8230837f0000000000000000000000008daebade922df735c38c80c7ebd708af50815faa73ffffffffffffffffffffffffffffffffffffffff166115dc909392919063ffffffff16565b7f00000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a8873ffffffffffffffffffffffffffffffffffffffff166340c10f1983836040518363ffffffff1660e01b81526004016118a592919061201c565b600060405180830381600087803b1580156118bf57600080fd5b505af11580156118d3573d6000803e3d6000fd5b505050505050565b600061193d826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166119a29092919063ffffffff16565b905060008151111561199d578080602001905181019061195d9190611ccb565b61199c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611993906121dd565b60405180910390fd5b5b505050565b60606119b184846000856119ba565b90509392505050565b6060824710156119ff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119f6906120dd565b60405180910390fd5b611a0885611ace565b611a47576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a3e9061219d565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051611a709190611fb3565b60006040518083038185875af1925050503d8060008114611aad576040519150601f19603f3d011682016040523d82523d6000602084013e611ab2565b606091505b5091509150611ac2828286611ae1565b92505050949350505050565b600080823b905060008111915050919050565b60608315611af157829050611b41565b600083511115611b045782518084602001fd5b816040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b38919061207b565b60405180910390fd5b9392505050565b600081359050611b57816127f3565b92915050565b600081519050611b6c8161280a565b92915050565b60008083601f840112611b8457600080fd5b8235905067ffffffffffffffff811115611b9d57600080fd5b602083019150836001820283011115611bb557600080fd5b9250929050565b600081359050611bcb81612821565b92915050565b600081519050611be081612821565b92915050565b600060208284031215611bf857600080fd5b6000611c0684828501611b48565b91505092915050565b60008060408385031215611c2257600080fd5b6000611c3085828601611b48565b9250506020611c4185828601611bbc565b9150509250929050565b600080600080600060808688031215611c6357600080fd5b6000611c7188828901611b48565b9550506020611c8288828901611bbc565b9450506040611c9388828901611b48565b935050606086013567ffffffffffffffff811115611cb057600080fd5b611cbc88828901611b72565b92509250509295509295909350565b600060208284031215611cdd57600080fd5b6000611ceb84828501611b5d565b91505092915050565b600060208284031215611d0657600080fd5b6000611d1484828501611bbc565b91505092915050565b600060208284031215611d2f57600080fd5b6000611d3d84828501611bd1565b91505092915050565b611d4f816123c8565b82525050565b6000611d6082612281565b611d6a8185612297565b9350611d7a818560208601612458565b80840191505092915050565b611d8f81612410565b82525050565b611d9e81612434565b82525050565b6000611daf8261228c565b611db981856122a2565b9350611dc9818560208601612458565b611dd2816124e9565b840191505092915050565b6000611dea6024836122a2565b9150611df5826124fa565b604082019050919050565b6000611e0d6026836122a2565b9150611e1882612549565b604082019050919050565b6000611e306026836122a2565b9150611e3b82612598565b604082019050919050565b6000611e536014836122a2565b9150611e5e826125e7565b602082019050919050565b6000611e766020836122a2565b9150611e8182612610565b602082019050919050565b6000611e996020836122a2565b9150611ea482612639565b602082019050919050565b6000611ebc6018836122a2565b9150611ec782612662565b602082019050919050565b6000611edf6029836122a2565b9150611eea8261268b565b604082019050919050565b6000611f02601d836122a2565b9150611f0d826126da565b602082019050919050565b6000611f256026836122a2565b9150611f3082612703565b604082019050919050565b6000611f48602a836122a2565b9150611f5382612752565b604082019050919050565b6000611f6b6014836122a2565b9150611f76826127a1565b602082019050919050565b6000611f8e601b836122a2565b9150611f99826127ca565b602082019050919050565b611fad81612406565b82525050565b6000611fbf8284611d55565b915081905092915050565b6000602082019050611fdf6000830184611d46565b92915050565b6000606082019050611ffa6000830186611d46565b6120076020830185611d46565b6120146040830184611fa4565b949350505050565b60006040820190506120316000830185611d46565b61203e6020830184611fa4565b9392505050565b600060208201905061205a6000830184611d86565b92915050565b60006020820190506120756000830184611d95565b92915050565b600060208201905081810360008301526120958184611da4565b905092915050565b600060208201905081810360008301526120b681611ddd565b9050919050565b600060208201905081810360008301526120d681611e00565b9050919050565b600060208201905081810360008301526120f681611e23565b9050919050565b6000602082019050818103600083015261211681611e46565b9050919050565b6000602082019050818103600083015261213681611e69565b9050919050565b6000602082019050818103600083015261215681611e8c565b9050919050565b6000602082019050818103600083015261217681611eaf565b9050919050565b6000602082019050818103600083015261219681611ed2565b9050919050565b600060208201905081810360008301526121b681611ef5565b9050919050565b600060208201905081810360008301526121d681611f18565b9050919050565b600060208201905081810360008301526121f681611f3b565b9050919050565b6000602082019050818103600083015261221681611f5e565b9050919050565b6000602082019050818103600083015261223681611f81565b9050919050565b60006020820190506122526000830184611fa4565b92915050565b600060408201905061226d6000830185611fa4565b61227a6020830184611fa4565b9392505050565b600081519050919050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b60006122be82612406565b91506122c983612406565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156122fe576122fd61248b565b5b828201905092915050565b600061231482612406565b915061231f83612406565b92508261232f5761232e6124ba565b5b828204905092915050565b600061234582612406565b915061235083612406565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156123895761238861248b565b5b828202905092915050565b600061239f82612406565b91506123aa83612406565b9250828210156123bd576123bc61248b565b5b828203905092915050565b60006123d3826123e6565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600061241b82612422565b9050919050565b600061242d826123e6565b9050919050565b600061243f82612446565b9050919050565b6000612451826123e6565b9050919050565b60005b8381101561247657808201518184015260208101905061245b565b83811115612485576000848401525b50505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000601f19601f8301169050919050565b7f416d6f756e74202b20666565206578636565647320544254432076322062616c60008201527f616e636500000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b7f4368616e6765206e6f7420696e69746961746564000000000000000000000000600082015250565b7f476f7665726e616e63652064656c617920686173206e6f7420656c6170736564600082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f43616c6c6572206973206e6f7420617574686f72697a65640000000000000000600082015250565b7f4e65772056656e64696e674d616368696e652063616e6e6f74206265207a657260008201527f6f20616464726573730000000000000000000000000000000000000000000000602082015250565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b7f4e657720696e69746961746f72206d757374206e6f74206265207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b7f546f6b656e206973206e6f742054425443207631000000000000000000000000600082015250565b7f4f6e6c7920544254432076312063616c6c657220616c6c6f7765640000000000600082015250565b6127fc816123c8565b811461280757600080fd5b50565b612813816123da565b811461281e57600080fd5b50565b61282a81612406565b811461283557600080fd5b5056fea264697066735822122004db01c528b9b87ac36e1eb71ee034a1378362503cb3b35617819e9003a4c09064736f6c63430008040033
Verified Source Code Full Match
Compiler: v0.8.4+commit.c7e474f2
EVM: istanbul
Optimization: No
VendingMachine.sol 313 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@thesis/solidity-contracts/contracts/token/IReceiveApproval.sol";
import "../token/TBTC.sol";
import "../GovernanceUtils.sol";
/// @title TBTC v2 Vending Machine
/// @notice The Vending Machine is the owner of TBTC v2 token and can mint
/// TBTC v2 tokens in 1:1 ratio from TBTC v1 tokens with TBTC v1
/// deposited in the contract as collateral. TBTC v2 can be
/// unminted back to TBTC v1 with or without a fee - fee parameter is
/// controlled by the Governance. This implementation acts as a bridge
/// between TBTC v1 and TBTC v2 token, allowing to mint TBTC v2 before
/// the system is ready and fully operational without sacrificing any
/// security guarantees and decentralization of the project.
/// Vending Machine can be upgraded in a two-step, governance-controlled
/// process. The new version of the Vending Machine will receive the
/// ownership of TBTC v2 token and entire TBTC v1 balance stored as
/// collateral. It is expected that this process will be executed before
/// the v2 system launch. There is an optional unmint fee with a value
/// that can be updated in a two-step, governance-controlled process.
/// All governable parameters are controlled by two roles: update
/// initiator and finalizer. There is a separate initiator role for
/// unmint fee update and vending machine upgrade. The initiator
/// proposes the change by initiating the update and the finalizer
/// (contract owner) may approve it by finalizing the change after the
/// governance delay passes.
contract VendingMachine is Ownable, IReceiveApproval {
using SafeERC20 for IERC20;
using SafeERC20 for TBTC;
/// @notice The time delay that needs to pass between initializing and
/// finalizing update of any governable parameter in this contract.
uint256 public constant GOVERNANCE_DELAY = 7 days;
/// @notice Divisor for precision purposes. Used to represent fractions
/// in parameter values.
uint256 public constant FLOATING_POINT_DIVISOR = 1e18;
IERC20 public immutable tbtcV1;
TBTC public immutable tbtcV2;
/// @notice The fee for unminting TBTC v2 back into TBTC v1 represented as
/// 1e18 precision fraction. The fee is proportional to the amount
/// being unminted and added on the top of the amount being unminted.
/// To calculate the fee value, the amount being unminted needs
/// to be multiplied by `unmintFee` and divided by 1e18.
/// For example, `unmintFee` set to 1000000000000000
/// means that 0.001 of the amount being unminted needs to be paid
/// to the `VendingMachine` as an unminting fee on the top of the
/// amount being unminted.
uint256 public unmintFee;
uint256 public newUnmintFee;
uint256 public unmintFeeUpdateInitiatedTimestamp;
address public unmintFeeUpdateInitiator;
/// @notice The address of a new vending machine. Set only when the upgrade
/// process is pending. Once the upgrade gets finalized, the new
/// vending machine will become an owner of TBTC v2 token.
address public newVendingMachine;
uint256 public vendingMachineUpgradeInitiatedTimestamp;
address public vendingMachineUpgradeInitiator;
event UnmintFeeUpdateInitiated(uint256 newUnmintFee, uint256 timestamp);
event UnmintFeeUpdated(uint256 newUnmintFee);
event VendingMachineUpgradeInitiated(
address newVendingMachine,
uint256 timestamp
);
event VendingMachineUpgraded(address newVendingMachine);
event Minted(address indexed recipient, uint256 amount);
event Unminted(address indexed recipient, uint256 amount, uint256 fee);
modifier only(address authorizedCaller) {
require(msg.sender == authorizedCaller, "Caller is not authorized");
_;
}
modifier onlyAfterGovernanceDelay(uint256 changeInitiatedTimestamp) {
GovernanceUtils.onlyAfterGovernanceDelay(
changeInitiatedTimestamp,
GOVERNANCE_DELAY
);
_;
}
constructor(
IERC20 _tbtcV1,
TBTC _tbtcV2,
uint256 _unmintFee
) {
tbtcV1 = _tbtcV1;
tbtcV2 = _tbtcV2;
unmintFee = _unmintFee;
unmintFeeUpdateInitiator = msg.sender;
vendingMachineUpgradeInitiator = msg.sender;
}
/// @notice Mints TBTC v2 to the caller from TBTC v1 with 1:1 ratio.
/// The caller needs to have at least `amount` of TBTC v1 balance
/// approved for transfer to the `VendingMachine` before calling
/// this function.
/// @param amount The amount of TBTC v2 to mint from TBTC v1
function mint(uint256 amount) external {
_mint(msg.sender, amount);
}
/// @notice Mints TBTC v2 to `from` address from TBTC v1 with 1:1 ratio.
/// `from` address needs to have at least `amount` of TBTC v1
/// balance approved for transfer to the `VendingMachine` before
/// calling this function.
/// @dev This function is a shortcut for approve + mint. Only TBTC v1
/// caller is allowed and only TBTC v1 is allowed as a token to
/// transfer.
/// @param from TBTC v1 token holder minting TBTC v2 tokens
/// @param amount The amount of TBTC v2 to mint from TBTC v1
/// @param token TBTC v1 token address
function receiveApproval(
address from,
uint256 amount,
address token,
bytes calldata
) external override {
require(token == address(tbtcV1), "Token is not TBTC v1");
require(msg.sender == address(tbtcV1), "Only TBTC v1 caller allowed");
_mint(from, amount);
}
/// @notice Unmints TBTC v2 from the caller into TBTC v1. Depending on
/// `unmintFee` value, may require paying an additional unmint fee
/// in TBTC v2 in addition to the amount being unminted. To see
/// what is the value of the fee, please call `unmintFeeFor(amount)`
/// function. The caller needs to have at least
/// `amount + unmintFeeFor(amount)` of TBTC v2 balance approved for
/// transfer to the `VendingMachine` before calling this function.
/// @param amount The amount of TBTC v2 to unmint to TBTC v1
function unmint(uint256 amount) external {
uint256 fee = unmintFeeFor(amount);
emit Unminted(msg.sender, amount, fee);
require(
tbtcV2.balanceOf(msg.sender) >= amount + fee,
"Amount + fee exceeds TBTC v2 balance"
);
tbtcV2.safeTransferFrom(msg.sender, address(this), fee);
tbtcV2.burnFrom(msg.sender, amount);
tbtcV1.safeTransfer(msg.sender, amount);
}
/// @notice Allows the Governance to withdraw unmint fees accumulated by
/// `VendingMachine`.
/// @param recipient The address receiving the fees
/// @param amount The amount of fees in TBTC v2 to withdraw
function withdrawFees(address recipient, uint256 amount)
external
onlyOwner
{
tbtcV2.safeTransfer(recipient, amount);
}
/// @notice Initiates unmint fee update process. The update process needs to
/// be finalized with a call to `finalizeUnmintFeeUpdate` function
/// after the `GOVERNANCE_DELAY` passes. Only unmint fee update
/// initiator role can initiate the update.
/// @param _newUnmintFee The new unmint fee
function initiateUnmintFeeUpdate(uint256 _newUnmintFee)
external
only(unmintFeeUpdateInitiator)
{
/* solhint-disable-next-line not-rely-on-time */
emit UnmintFeeUpdateInitiated(_newUnmintFee, block.timestamp);
newUnmintFee = _newUnmintFee;
/* solhint-disable-next-line not-rely-on-time */
unmintFeeUpdateInitiatedTimestamp = block.timestamp;
}
/// @notice Allows the contract owner to finalize unmint fee update process.
/// The update process needs to be first initiated with a call to
/// `initiateUnmintFeeUpdate` and the `GOVERNANCE_DELAY` needs to
/// pass.
function finalizeUnmintFeeUpdate()
external
onlyOwner
onlyAfterGovernanceDelay(unmintFeeUpdateInitiatedTimestamp)
{
emit UnmintFeeUpdated(newUnmintFee);
unmintFee = newUnmintFee;
newUnmintFee = 0;
unmintFeeUpdateInitiatedTimestamp = 0;
}
/// @notice Initiates vending machine upgrade process. The upgrade process
/// needs to be finalized with a call to
/// `finalizeVendingMachineUpgrade` function after the
/// `GOVERNANCE_DELAY` passes. Only vending machine upgrade
/// initiator role can initiate the upgrade.
/// @param _newVendingMachine The new vending machine address
function initiateVendingMachineUpgrade(address _newVendingMachine)
external
only(vendingMachineUpgradeInitiator)
{
require(
_newVendingMachine != address(0),
"New VendingMachine cannot be zero address"
);
emit VendingMachineUpgradeInitiated(
_newVendingMachine,
/* solhint-disable-next-line not-rely-on-time */
block.timestamp
);
newVendingMachine = _newVendingMachine;
/* solhint-disable-next-line not-rely-on-time */
vendingMachineUpgradeInitiatedTimestamp = block.timestamp;
}
/// @notice Allows the contract owner to finalize vending machine upgrade
/// process. The upgrade process needs to be first initiated with a
/// call to `initiateVendingMachineUpgrade` and the `GOVERNANCE_DELAY`
/// needs to pass. Once the upgrade is finalized, the new vending
/// machine will become an owner of TBTC v2 token and all TBTC v1
/// held by this contract will be transferred to the new vending
/// machine.
function finalizeVendingMachineUpgrade()
external
onlyOwner
onlyAfterGovernanceDelay(vendingMachineUpgradeInitiatedTimestamp)
{
emit VendingMachineUpgraded(newVendingMachine);
//slither-disable-next-line reentrancy-no-eth
tbtcV2.transferOwnership(newVendingMachine);
tbtcV1.safeTransfer(newVendingMachine, tbtcV1.balanceOf(address(this)));
newVendingMachine = address(0);
vendingMachineUpgradeInitiatedTimestamp = 0;
}
/// @notice Transfers unmint fee update initiator role to another address.
/// Can be called only by the current unmint fee update initiator.
/// @param newInitiator The new unmint fee update initiator
function transferUnmintFeeUpdateInitiatorRole(address newInitiator)
external
only(unmintFeeUpdateInitiator)
{
require(
newInitiator != address(0),
"New initiator must not be zero address"
);
unmintFeeUpdateInitiator = newInitiator;
}
/// @notice Transfers vending machine upgrade initiator role to another
/// address. Can be called only by the current vending machine
/// upgrade initiator.
/// @param newInitiator The new vending machine upgrade initator
function transferVendingMachineUpgradeInitiatorRole(address newInitiator)
external
only(vendingMachineUpgradeInitiator)
{
require(
newInitiator != address(0),
"New initiator must not be zero address"
);
vendingMachineUpgradeInitiator = newInitiator;
}
/// @notice Get the remaining time that needs to pass until unmint fee
/// update can be finalized by the Governance. If the update has
/// not been initiated, the function reverts.
function getRemainingUnmintFeeUpdateTime() external view returns (uint256) {
return
GovernanceUtils.getRemainingGovernanceDelay(
unmintFeeUpdateInitiatedTimestamp,
GOVERNANCE_DELAY
);
}
/// @notice Get the remaining time that needs to pass until vending machine
/// upgrade can be finalized by the Governance. If the upgrade has
/// not been initiated, the function reverts.
function getRemainingVendingMachineUpgradeTime()
external
view
returns (uint256)
{
return
GovernanceUtils.getRemainingGovernanceDelay(
vendingMachineUpgradeInitiatedTimestamp,
GOVERNANCE_DELAY
);
}
/// @notice Calculates the fee that needs to be paid to the `VendingMachine`
/// to unmint the given amount of TBTC v2 back into TBTC v1.
function unmintFeeFor(uint256 amount) public view returns (uint256) {
return (amount * unmintFee) / FLOATING_POINT_DIVISOR;
}
function _mint(address tokenOwner, uint256 amount) internal {
emit Minted(tokenOwner, amount);
tbtcV1.safeTransferFrom(tokenOwner, address(this), amount);
tbtcV2.mint(tokenOwner, amount);
}
}
Ownable.sol 71 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
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);
}
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");
}
}
}
IReceiveApproval.sol 16 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice An interface that should be implemented by contracts supporting
/// `approveAndCall`/`receiveApproval` pattern.
interface IReceiveApproval {
/// @notice Receives approval to spend tokens. Called as a result of
/// `approveAndCall` call on the token.
function receiveApproval(
address from,
uint256 amount,
address token,
bytes calldata extraData
) external;
}
TBTC.sol 10 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
import "@thesis/solidity-contracts/contracts/token/ERC20WithPermit.sol";
import "@thesis/solidity-contracts/contracts/token/MisfundRecovery.sol";
contract TBTC is ERC20WithPermit, MisfundRecovery {
constructor() ERC20WithPermit("tBTC v2", "tBTC") {}
}
GovernanceUtils.sol 43 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
library GovernanceUtils {
/// @notice Reverts if the governance delay has not passed since
/// the change initiated time or if the change has not been
/// initiated.
/// @param changeInitiatedTimestamp The timestamp at which the change has
/// been initiated.
/// @param delay Governance delay.
function onlyAfterGovernanceDelay(
uint256 changeInitiatedTimestamp,
uint256 delay
) internal view {
require(changeInitiatedTimestamp > 0, "Change not initiated");
require(
/* solhint-disable-next-line not-rely-on-time */
block.timestamp - changeInitiatedTimestamp >= delay,
"Governance delay has not elapsed"
);
}
/// @notice Gets the time remaining until the governable parameter update
/// can be committed.
/// @param changeInitiatedTimestamp Timestamp indicating the beginning of
/// the change
/// @param delay Governance delay
/// @return Remaining time in seconds
function getRemainingGovernanceDelay(
uint256 changeInitiatedTimestamp,
uint256 delay
) internal view returns (uint256) {
require(changeInitiatedTimestamp > 0, "Change not initiated");
/* solhint-disable-next-line not-rely-on-time */
uint256 elapsed = block.timestamp - changeInitiatedTimestamp;
if (elapsed >= delay) {
return 0;
} else {
return delay - elapsed;
}
}
}
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;
}
}
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);
}
}
}
}
ERC20WithPermit.sol 334 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./IERC20WithPermit.sol";
import "./IReceiveApproval.sol";
/// @title ERC20WithPermit
/// @notice Burnable ERC20 token with EIP2612 permit functionality. User can
/// authorize a transfer of their token with a signature conforming
/// EIP712 standard instead of an on-chain transaction from their
/// address. Anyone can submit this signature on the user's behalf by
/// calling the permit function, as specified in EIP2612 standard,
/// paying gas fees, and possibly performing other actions in the same
/// transaction.
contract ERC20WithPermit is IERC20WithPermit, Ownable {
/// @notice The amount of tokens owned by the given account.
mapping(address => uint256) public override balanceOf;
/// @notice The remaining number of tokens that spender will be
/// allowed to spend on behalf of owner through `transferFrom` and
/// `burnFrom`. This is zero by default.
mapping(address => mapping(address => uint256)) public override allowance;
/// @notice Returns the current nonce for EIP2612 permission for the
/// provided token owner for a replay protection. Used to construct
/// EIP2612 signature provided to `permit` function.
mapping(address => uint256) public override nonces;
uint256 public immutable cachedChainId;
bytes32 public immutable cachedDomainSeparator;
/// @notice Returns EIP2612 Permit message hash. Used to construct EIP2612
/// signature provided to `permit` function.
bytes32 public constant override PERMIT_TYPEHASH =
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);
/// @notice The amount of tokens in existence.
uint256 public override totalSupply;
/// @notice The name of the token.
string public override name;
/// @notice The symbol of the token.
string public override symbol;
/// @notice The decimals places of the token.
uint8 public constant override decimals = 18;
constructor(string memory _name, string memory _symbol) {
name = _name;
symbol = _symbol;
cachedChainId = block.chainid;
cachedDomainSeparator = buildDomainSeparator();
}
/// @notice Moves `amount` tokens from the caller's account to `recipient`.
/// @return True if the operation succeeded, reverts otherwise.
/// @dev Requirements:
/// - `recipient` cannot be the zero address,
/// - the caller must have a balance of at least `amount`.
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
_transfer(msg.sender, recipient, amount);
return true;
}
/// @notice Moves `amount` tokens from `sender` to `recipient` using the
/// allowance mechanism. `amount` is then deducted from the caller's
/// allowance unless the allowance was made for `type(uint256).max`.
/// @return True if the operation succeeded, reverts otherwise.
/// @dev Requirements:
/// - `sender` and `recipient` cannot be the zero address,
/// - `sender` must have a balance of at least `amount`,
/// - the caller must have allowance for `sender`'s tokens of at least
/// `amount`.
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
uint256 currentAllowance = allowance[sender][msg.sender];
if (currentAllowance != type(uint256).max) {
require(
currentAllowance >= amount,
"Transfer amount exceeds allowance"
);
_approve(sender, msg.sender, currentAllowance - amount);
}
_transfer(sender, recipient, amount);
return true;
}
/// @notice EIP2612 approval made with secp256k1 signature.
/// Users can authorize a transfer of their tokens with a signature
/// conforming EIP712 standard, rather than an on-chain transaction
/// from their address. Anyone can submit this signature on the
/// user's behalf by calling the permit function, paying gas fees,
/// and possibly performing other actions in the same transaction.
/// @dev The deadline argument can be set to `type(uint256).max to create
/// permits that effectively never expire. If the `amount` is set
/// to `type(uint256).max` then `transferFrom` and `burnFrom` will
/// not reduce an allowance.
function permit(
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external override {
/* solhint-disable-next-line not-rely-on-time */
require(deadline >= block.timestamp, "Permission expired");
// Validate `s` and `v` values for a malleability concern described in EIP2.
// Only signatures with `s` value in the lower half of the secp256k1
// curve's order and `v` value of 27 or 28 are considered valid.
require(
uint256(s) <=
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
"Invalid signature 's' value"
);
require(v == 27 || v == 28, "Invalid signature 'v' value");
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
PERMIT_TYPEHASH,
owner,
spender,
amount,
nonces[owner]++,
deadline
)
)
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(
recoveredAddress != address(0) && recoveredAddress == owner,
"Invalid signature"
);
_approve(owner, spender, amount);
}
/// @notice Creates `amount` tokens and assigns them to `account`,
/// increasing the total supply.
/// @dev Requirements:
/// - `recipient` cannot be the zero address.
function mint(address recipient, uint256 amount) external onlyOwner {
require(recipient != address(0), "Mint to the zero address");
beforeTokenTransfer(address(0), recipient, amount);
totalSupply += amount;
balanceOf[recipient] += amount;
emit Transfer(address(0), recipient, amount);
}
/// @notice Destroys `amount` tokens from the caller.
/// @dev Requirements:
/// - the caller must have a balance of at least `amount`.
function burn(uint256 amount) external override {
_burn(msg.sender, amount);
}
/// @notice Destroys `amount` of tokens from `account` using the allowance
/// mechanism. `amount` is then deducted from the caller's allowance
/// unless the allowance was made for `type(uint256).max`.
/// @dev Requirements:
/// - `account` must have a balance of at least `amount`,
/// - the caller must have allowance for `account`'s tokens of at least
/// `amount`.
function burnFrom(address account, uint256 amount) external override {
uint256 currentAllowance = allowance[account][msg.sender];
if (currentAllowance != type(uint256).max) {
require(
currentAllowance >= amount,
"Burn amount exceeds allowance"
);
_approve(account, msg.sender, currentAllowance - amount);
}
_burn(account, amount);
}
/// @notice Calls `receiveApproval` function on spender previously approving
/// the spender to withdraw from the caller multiple times, up to
/// the `amount` amount. If this function is called again, it
/// overwrites the current allowance with `amount`. Reverts if the
/// approval reverted or if `receiveApproval` call on the spender
/// reverted.
/// @return True if both approval and `receiveApproval` calls succeeded.
/// @dev If the `amount` is set to `type(uint256).max` then
/// `transferFrom` and `burnFrom` will not reduce an allowance.
function approveAndCall(
address spender,
uint256 amount,
bytes memory extraData
) external override returns (bool) {
if (approve(spender, amount)) {
IReceiveApproval(spender).receiveApproval(
msg.sender,
amount,
address(this),
extraData
);
return true;
}
return false;
}
/// @notice Sets `amount` as the allowance of `spender` over the caller's
/// tokens.
/// @return True if the operation succeeded.
/// @dev If the `amount` is set to `type(uint256).max` then
/// `transferFrom` and `burnFrom` will not reduce an allowance.
/// 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
function approve(address spender, uint256 amount)
public
override
returns (bool)
{
_approve(msg.sender, spender, amount);
return true;
}
/// @notice Returns hash of EIP712 Domain struct with the token name as
/// a signing domain and token contract as a verifying contract.
/// Used to construct EIP2612 signature provided to `permit`
/// function.
/* solhint-disable-next-line func-name-mixedcase */
function DOMAIN_SEPARATOR() public view override returns (bytes32) {
// As explained in EIP-2612, if the DOMAIN_SEPARATOR contains the
// chainId and is defined at contract deployment instead of
// reconstructed for every signature, there is a risk of possible replay
// attacks between chains in the event of a future chain split.
// To address this issue, we check the cached chain ID against the
// current one and in case they are different, we build domain separator
// from scratch.
if (block.chainid == cachedChainId) {
return cachedDomainSeparator;
} else {
return buildDomainSeparator();
}
}
/// @dev Hook that is called before any transfer of tokens. This includes
/// minting and burning.
///
/// Calling conditions:
/// - when `from` and `to` are both non-zero, `amount` of `from`'s tokens
/// will be to transferred to `to`.
/// - when `from` is zero, `amount` tokens will be minted for `to`.
/// - when `to` is zero, `amount` of ``from``'s tokens will be burned.
/// - `from` and `to` are never both zero.
// slither-disable-next-line dead-code
function beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _burn(address account, uint256 amount) internal {
uint256 currentBalance = balanceOf[account];
require(currentBalance >= amount, "Burn amount exceeds balance");
beforeTokenTransfer(account, address(0), amount);
balanceOf[account] = currentBalance - amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _transfer(
address sender,
address recipient,
uint256 amount
) private {
require(sender != address(0), "Transfer from the zero address");
require(recipient != address(0), "Transfer to the zero address");
require(recipient != address(this), "Transfer to the token address");
beforeTokenTransfer(sender, recipient, amount);
uint256 senderBalance = balanceOf[sender];
require(senderBalance >= amount, "Transfer amount exceeds balance");
balanceOf[sender] = senderBalance - amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) private {
require(owner != address(0), "Approve from the zero address");
require(spender != address(0), "Approve to the zero address");
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function buildDomainSeparator() private view returns (bytes32) {
return
keccak256(
abi.encode(
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
),
keccak256(bytes(name)),
keccak256(bytes("1")),
block.chainid,
address(this)
)
);
}
}
MisfundRecovery.sol 33 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
/// @title MisfundRecovery
/// @notice Allows the owner of the token contract extending MisfundRecovery
/// to recover any ERC20 and ERC721 sent mistakenly to the token
/// contract address.
contract MisfundRecovery is Ownable {
using SafeERC20 for IERC20;
function recoverERC20(
IERC20 token,
address recipient,
uint256 amount
) external onlyOwner {
token.safeTransfer(recipient, amount);
}
function recoverERC721(
IERC721 token,
address recipient,
uint256 tokenId,
bytes calldata data
) external onlyOwner {
token.safeTransferFrom(address(this), recipient, tokenId, data);
}
}
IERC20WithPermit.sol 60 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./IApproveAndCall.sol";
/// @title IERC20WithPermit
/// @notice Burnable ERC20 token with EIP2612 permit functionality. User can
/// authorize a transfer of their token with a signature conforming
/// EIP712 standard instead of an on-chain transaction from their
/// address. Anyone can submit this signature on the user's behalf by
/// calling the permit function, as specified in EIP2612 standard,
/// paying gas fees, and possibly performing other actions in the same
/// transaction.
interface IERC20WithPermit is IERC20, IERC20Metadata, IApproveAndCall {
/// @notice EIP2612 approval made with secp256k1 signature.
/// Users can authorize a transfer of their tokens with a signature
/// conforming EIP712 standard, rather than an on-chain transaction
/// from their address. Anyone can submit this signature on the
/// user's behalf by calling the permit function, paying gas fees,
/// and possibly performing other actions in the same transaction.
/// @dev The deadline argument can be set to `type(uint256).max to create
/// permits that effectively never expire.
function permit(
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/// @notice Destroys `amount` tokens from the caller.
function burn(uint256 amount) external;
/// @notice Destroys `amount` of tokens from `account`, deducting the amount
/// from caller's allowance.
function burnFrom(address account, uint256 amount) external;
/// @notice Returns hash of EIP712 Domain struct with the token name as
/// a signing domain and token contract as a verifying contract.
/// Used to construct EIP2612 signature provided to `permit`
/// function.
/* solhint-disable-next-line func-name-mixedcase */
function DOMAIN_SEPARATOR() external view returns (bytes32);
/// @notice Returns the current nonce for EIP2612 permission for the
/// provided token owner for a replay protection. Used to construct
/// EIP2612 signature provided to `permit` function.
function nonces(address owner) external view returns (uint256);
/// @notice Returns EIP2612 Permit message hash. Used to construct EIP2612
/// signature provided to `permit` function.
/* solhint-disable-next-line func-name-mixedcase */
function PERMIT_TYPEHASH() external pure returns (bytes32);
}
IERC20Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
IApproveAndCall.sol 19 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice An interface that should be implemented by tokens supporting
/// `approveAndCall`/`receiveApproval` pattern.
interface IApproveAndCall {
/// @notice Executes `receiveApproval` function on spender as specified in
/// `IReceiveApproval` interface. Approves spender to withdraw from
/// the caller multiple times, up to the `amount`. If this
/// function is called again, it overwrites the current allowance
/// with `amount`. Reverts if the approval reverted or if
/// `receiveApproval` call on the spender reverted.
function approveAndCall(
address spender,
uint256 amount,
bytes memory extraData
) external returns (bool);
}
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;
}
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);
}
Read Contract
FLOATING_POINT_DIVISOR 0x51b83ebc → uint256
GOVERNANCE_DELAY 0xb0b54895 → uint256
getRemainingUnmintFeeUpdateTime 0xc2b4aa75 → uint256
getRemainingVendingMachineUpgradeTime 0x0bb037df → uint256
newUnmintFee 0x240b57e8 → uint256
newVendingMachine 0xfe7294a8 → address
owner 0x8da5cb5b → address
tbtcV1 0x3678252f → address
tbtcV2 0x95de5a41 → address
unmintFee 0x0c505b7a → uint256
unmintFeeFor 0xb766bd8a → uint256
unmintFeeUpdateInitiatedTimestamp 0xb29b95ce → uint256
unmintFeeUpdateInitiator 0xea1a4e68 → address
vendingMachineUpgradeInitiatedTimestamp 0x05e448fc → uint256
vendingMachineUpgradeInitiator 0x0c05ab39 → address
Write Contract 12 functions
These functions modify contract state and require a wallet transaction to execute.
finalizeUnmintFeeUpdate 0x20ad25dc
No parameters
finalizeVendingMachineUpgrade 0xbb81268c
No parameters
initiateUnmintFeeUpdate 0x5bf32f52
uint256 _newUnmintFee
initiateVendingMachineUpgrade 0x6386d0b1
address _newVendingMachine
mint 0xa0712d68
uint256 amount
receiveApproval 0x8f4ffcb1
address from
uint256 amount
address token
bytes
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
transferUnmintFeeUpdateInitiatorRole 0x2d42067d
address newInitiator
transferVendingMachineUpgradeInitiatorRole 0xf257a1a0
address newInitiator
unmint 0x64e779b1
uint256 amount
withdrawFees 0xad3b1b47
address recipient
uint256 amount
Recent Transactions
No transactions found for this address