Address Contract Verified
Address
0x6dc3464F0450a1a2bb9b434BA826A6bd3035DCec
Balance
0 ETH
Nonce
1
Code Size
8478 bytes
Creator
0x4ad5d7bf...F31F at tx 0xd5e2c12d...92d0ab
Indexed Transactions
0
Contract Bytecode
8478 bytes
0x608060405234801561001057600080fd5b50600436106101e55760003560e01c8063720536d71161010f5780639d8e2177116100a2578063e30c397811610071578063e30c397814610490578063efdcd974146104a3578063f2fde38b146104b6578063fd967f47146104c957600080fd5b80639d8e2177146104485780639e8c708e14610457578063b3f006741461046a578063cf6d625e1461047d57600080fd5b80638739cedf116100de5780638739cedf146104035780638da5cb5b14610416578063965fa21e1461042c578063969494201461043557600080fd5b8063720536d7146103b757806379ba5097146103ca5780637d01ac41146103d25780638456cb59146103fb57600080fd5b80634f62b7ec116101875780635c975abb116101565780635c975abb146103725780636573220e1461038957806365d9e8441461039c578063715018a6146103af57600080fd5b80634f62b7ec146102e65780634f64b2be1461032c57806359cbe5801461033f5780635aec5f551461035257600080fd5b806332bfe469116101c357806332bfe469146102935780633da5ffc0146102a85780633f4ba83a146102c9578063492e47d2146102d357600080fd5b806304bc3b1c146101ea578063099bf4561461022b5780632c8e7a211461026a575b600080fd5b6102116101f8366004611d6f565b600a602052600090815260409020805460019091015482565b604080519283526020830191909152015b60405180910390f35b6102527f000000000000000000000000a8258dee2a677874a48f5320670a869d74f0cbc181565b6040516001600160a01b039091168152602001610222565b610252610278366004611d6f565b6007602052600090815260409020546001600160a01b031681565b61029b6104d2565b6040516102229190611d93565b6102bb6102b6366004611d6f565b6105fa565b604051908152602001610222565b6102d1610655565b005b6102d16102e1366004611deb565b610667565b6102f96102f4366004611e71565b610708565b604080519586526020860194909452928401919091526001600160a01b031660608301521515608082015260a001610222565b61025261033a366004611e9d565b610763565b600454610252906001600160a01b031681565b610365610360366004611d6f565b61078d565b6040516102229190611eb6565b60015460ff165b6040519015158152602001610222565b6102d1610397366004611d6f565b61083f565b6102d16103aa366004611f22565b6108d0565b6102d1610aa0565b6102d16103c5366004611e71565b610ab2565b6102d1610b3d565b6102526103e0366004611d6f565b6008602052600090815260409020546001600160a01b031681565b6102d1610bc6565b610365610411366004611d6f565b610bd6565b60015461010090046001600160a01b0316610252565b6102bb60095481565b6102d1610443366004611e9d565b610dd0565b6102bb670de0b6b3a764000081565b610379610465366004611d6f565b61113a565b600554610252906001600160a01b031681565b600354610252906001600160a01b031681565b600254610252906001600160a01b031681565b6102d16104b1366004611d6f565b611228565b6102d16104c4366004611d6f565b6112b1565b6102bb61271081565b60065460609060008167ffffffffffffffff8111156104f3576104f3611f5b565b60405190808252806020026020018201604052801561053857816020015b60408051808201909152600080825260208201528152602001906001900390816105115790505b50905060005b828110156105f35760405180604001604052806006838154811061056457610564611f71565b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b031681526020016105c0600684815481106105a6576105a6611f71565b6000918252602090912001546001600160a01b0316611374565b8152508282815181106105d5576105d5611f71565b602002602001018190525080806105eb90611f9d565b91505061053e565b5092915050565b6001600160a01b0381166000908152600a60205260408120600181015490541161062657506000919050565b6001600160a01b0382166000908152600a602052604090206001810154905461064f9190611fb6565b92915050565b61065d611543565b6106656115a3565b565b61066f6115f5565b61067761164e565b6001600160a01b03811661069e5760405163d92e233d60e01b815260040160405180910390fd5b8160008190036106c15760405163521299a960e01b815260040160405180910390fd5b60005b818110156106f7576106ef33848787858181106106e3576106e3611f71565b90506020020135611694565b6001016106c4565b50506107036001600055565b505050565b600b602052816000526040600020818154811061072457600080fd5b6000918252602090912060049091020180546001820154600283015460039093015491945092506001600160a01b03811690600160a01b900460ff1685565b6006818154811061077357600080fd5b6000918252602090912001546001600160a01b0316905081565b6001600160a01b0381166000908152600b60209081526040808320805482518185028101850190935280835260609492939192909184015b828210156108345760008481526020908190206040805160a081018252600486029092018054835260018082015484860152600282015492840192909252600301546001600160a01b0381166060840152600160a01b900460ff161515608083015290835290920191016107c5565b505050509050919050565b610847611543565b6001600160a01b03811661086e5760405163d92e233d60e01b815260040160405180910390fd5b600380546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527ff1d18a244454d9674ffc13001eb749a127c8360590cd3ac3aa39746e9a5316c291015b60405180910390a15050565b6108d8611543565b6001600160a01b03821615806108f557506001600160a01b038116155b156109135760405163d92e233d60e01b815260040160405180910390fd5b6000816001600160a01b031663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610953573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109779190611fc9565b9050826001600160a01b0316816001600160a01b0316146109c357604051639b6a394360e01b81526001600160a01b038083166004830152841660248201526044015b60405180910390fd5b6001600160a01b0383811660009081526007602052604090205416610a2e57600680546001810182556000919091527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f0180546001600160a01b0319166001600160a01b0385161790555b6001600160a01b03808416600081815260076020908152604080832080549588166001600160a01b0319968716811790915580845260089092528083208054909516841790945592517f30990b9ade42619bd352d880a40ddd2712ec867b0c4190bbf6c821287a21e60e9190a3505050565b610aa8611543565b6106656000611862565b610aba61164e565b336000908152600860205260409020546001600160a01b0316158015610aeb57506004546001600160a01b03163314155b15610b09576040516317c5c16560e01b815260040160405180910390fd5b6001600160a01b0382166000908152600a602052604081206001018054839290610b34908490611fe6565b90915550505050565b6002546001600160a01b03163314610b68576040516305e05b4b60e31b815260040160405180910390fd5b6002546001600160a01b0316610b7d81611862565b600280546001600160a01b03191690556040516000906001600160a01b038316907fb3d55174552271a4f1aaf36b72f50381e892171636b3fb5447fe00e995e7a37b908390a350565b610bce611543565b6106656118bc565b6001600160a01b0381166000908152600b60209081526040808320805482518185028101850190935280835260609493849084015b82821015610c7a5760008481526020908190206040805160a081018252600486029092018054835260018082015484860152600282015492840192909252600301546001600160a01b0381166060840152600160a01b900460ff16151560808301529083529092019101610c0b565b5050505090506000815190506000805b82811015610cc357838181518110610ca457610ca4611f71565b602002602001015160800151610cbb578160010191505b600101610c8a565b5060008167ffffffffffffffff811115610cdf57610cdf611f5b565b604051908082528060200260200182016040528015610d4d57816020015b610d3a6040518060a0016040528060008152602001600081526020016000815260200160006001600160a01b031681526020016000151581525090565b815260200190600190039081610cfd5790505b5090506000805b84811015610dc457858181518110610d6e57610d6e611f71565b602002602001015160800151610dbc57858181518110610d9057610d90611f71565b6020026020010151838381518110610daa57610daa611f71565b60200260200101819052508160010191505b600101610d54565b50909695505050505050565b610dd86115f5565b610de061164e565b60006006805480602002602001604051908101604052809291908181526020018280548015610e3857602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610e1a575b5050505050905060008151905082600003610e6657604051637c946ed760e01b815260040160405180910390fd5b610e9b6001600160a01b037f000000000000000000000000a8258dee2a677874a48f5320670a869d74f0cbc1163330866118f7565b600061271060095485610eae9190611ff9565b610eb89190612018565b90506000610ec68286611fb6565b600554909150610f03906001600160a01b037f000000000000000000000000a8258dee2a677874a48f5320670a869d74f0cbc18116911684611968565b60005b838110156110a85760006001600160a01b031660076000878481518110610f2f57610f2f611f71565b6020908102919091018101516001600160a01b03908116835290820192909252604001600020541603610f75576040516317c5c16560e01b815260040160405180910390fd5b6000610f99868381518110610f8c57610f8c611f71565b6020026020010151611374565b90506000670de0b6b3a7640000610fb08386611ff9565b610fba9190612018565b60035488519192506000916001600160a01b039091169063b7c4a6bf908a9087908110610fe957610fe9611f71565b6020026020010151846040518363ffffffff1660e01b81526004016110239291906001600160a01b03929092168252602082015260400190565b602060405180830381865afa158015611040573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611064919061203a565b90508060000361107657505050610f06565b61109a88858151811061108b5761108b611f71565b60200260200101513383611998565b836001019350505050610f06565b50604051632770a7eb60e21b8152306004820152602481018290527f000000000000000000000000a8258dee2a677874a48f5320670a869d74f0cbc16001600160a01b031690639dc29fac90604401600060405180830381600087803b15801561111157600080fd5b505af1158015611125573d6000803e3d6000fd5b50505050505050506111376001600055565b50565b6000611144611543565b6001600160a01b03821661116b5760405163d92e233d60e01b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156111b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111d6919061203a565b9050806000036111f957604051637c946ed760e01b815260040160405180910390fd5b60015461121f9061010090046001600160a01b03166001600160a01b0385169083611968565b50600192915050565b611230611543565b6001600160a01b0381166112575760405163d92e233d60e01b815260040160405180910390fd5b600580546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527fa92ff4390fe6943f0b30e8fe715dde86f85ab79b2b2c640a10fc094cc4036cc891016108c4565b6112b9611543565b6001600160a01b0381166112e057604051639c41f49560e01b815260040160405180910390fd5b60015461010090046001600160a01b03166001600160a01b0316816001600160a01b0316036113225760405163d5e889bf60e01b815260040160405180910390fd5b600280546001600160a01b038381166001600160a01b0319831681179093556040519116919082907fb3d55174552271a4f1aaf36b72f50381e892171636b3fb5447fe00e995e7a37b90600090a35050565b6000807f000000000000000000000000a8258dee2a677874a48f5320670a869d74f0cbc16001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113f9919061203a565b90508060000361140c5750600092915050565b6001600160a01b03808416600090815260076020908152604080832054815163898d846f60e01b815291519394169263898d846f926004808401939192918290030181865afa158015611463573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611487919061203a565b90506000611494856105fa565b90508082116114a45760006114ae565b6114ae8183611fb6565b60035460405163225d6a0160e11b81526001600160a01b038881166004830152929450600092909116906344bad40290602401602060405180830381865afa1580156114fe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611522919061203a565b90508361152f8285611ff9565b6115399190612018565b9695505050505050565b6001546001600160a01b036101009091041633146106655760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016109ba565b6115ab611aaf565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6002600054036116475760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016109ba565b6002600055565b60015460ff16156106655760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016109ba565b6001600160a01b0383166000908152600b602052604090205481106116cc576040516363df817160e01b815260040160405180910390fd5b6001600160a01b0383166000908152600b602052604081208054839081106116f6576116f6611f71565b6000918252602080832060049283020160038101546001600160a01b0390811680865260079093526040808620548151631580f0e760e21b8152915193975093959390911693635603c39c9382820193909290919082900301818387803b15801561176057600080fd5b505af1158015611774573d6000803e3d6000fd5b505050506001600160a01b0381166000908152600a6020526040902060010154600283015411156117b857604051632527a85160e01b815260040160405180910390fd5b6003820154600160a01b900460ff16156117e5576040516306d3830f60e21b815260040160405180910390fd5b60038201805460ff60a01b1916600160a01b1790556001820154611815906001600160a01b038316908690611968565b6040516001600160a01b0385811682528491818816918416907fcf350c2578444143f43895197408f662a20ebd341edd9c7f8a8c732bb58a3de59060200160405180910390a45050505050565b600180546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6118c461164e565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258336115d8565b6040516001600160a01b03808516602483015283166044820152606481018290526119629085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611af8565b50505050565b6040516001600160a01b03831660248201526044810182905261070390849063a9059cbb60e01b9060640161192b565b6001600160a01b0383166000908152600a6020526040812080549091906119c0908490611fe6565b8083556001600160a01b038581166000818152600b602090815260408083208054825160a0810184528181528085018c81528185018a81528f8a166060808501828152608086018b815260018089018a55988c529a8a90209551600488029096019586559351968501969096559051600284015590516003909201805497511515600160a01b026001600160a81b031990981692909916919091179590951790965581518681529283018a90529082018690529495509293919290917faddb540b941dd2740bce0c4489e3a350c85eec025688e4d6d48ad3827fb1c1db910160405180910390a3505050505050565b60015460ff166106655760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016109ba565b6000611b4d826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611bca9092919063ffffffff16565b8051909150156107035780806020019051810190611b6b9190612053565b6107035760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016109ba565b6060611bd98484600085611be1565b949350505050565b606082471015611c425760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016109ba565b600080866001600160a01b03168587604051611c5e9190612099565b60006040518083038185875af1925050503d8060008114611c9b576040519150601f19603f3d011682016040523d82523d6000602084013e611ca0565b606091505b5091509150611cb187838387611cbc565b979650505050505050565b60608315611d2b578251600003611d24576001600160a01b0385163b611d245760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016109ba565b5081611bd9565b611bd98383815115611d405781518083602001fd5b8060405162461bcd60e51b81526004016109ba91906120b5565b6001600160a01b038116811461113757600080fd5b600060208284031215611d8157600080fd5b8135611d8c81611d5a565b9392505050565b602080825282518282018190526000919060409081850190868401855b82811015611dde57815180516001600160a01b03168552860151868501529284019290850190600101611db0565b5091979650505050505050565b600080600060408486031215611e0057600080fd5b833567ffffffffffffffff80821115611e1857600080fd5b818601915086601f830112611e2c57600080fd5b813581811115611e3b57600080fd5b8760208260051b8501011115611e5057600080fd5b60209283019550935050840135611e6681611d5a565b809150509250925092565b60008060408385031215611e8457600080fd5b8235611e8f81611d5a565b946020939093013593505050565b600060208284031215611eaf57600080fd5b5035919050565b602080825282518282018190526000919060409081850190868401855b82811015611dde57815180518552868101518786015285810151868601526060808201516001600160a01b03169086015260809081015115159085015260a09093019290850190600101611ed3565b60008060408385031215611f3557600080fd5b8235611f4081611d5a565b91506020830135611f5081611d5a565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201611faf57611faf611f87565b5060010190565b8181038181111561064f5761064f611f87565b600060208284031215611fdb57600080fd5b8151611d8c81611d5a565b8082018082111561064f5761064f611f87565b600081600019048311821515161561201357612013611f87565b500290565b60008261203557634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561204c57600080fd5b5051919050565b60006020828403121561206557600080fd5b81518015158114611d8c57600080fd5b60005b83811015612090578181015183820152602001612078565b50506000910152565b600082516120ab818460208701612075565b9190910192915050565b60208152600082518060208401526120d4816040850160208701612075565b601f01601f1916919091016040019291505056fea264697066735822122036eff3d854393245858a430a6b378a05be0a0c865f491b79dff96a70f37b0f9564736f6c63430008100033
Verified Source Code Full Match
Compiler: v0.8.16+commit.07a7930e
EVM: london
Optimization: Yes (200 runs)
ShutdownRedeemer.sol 476 lines
//██████╗ █████╗ ██╗ █████╗ ██████╗ ██╗███╗ ██╗
//██╔══██╗██╔══██╗██║ ██╔══██╗██╔══██╗██║████╗ ██║
//██████╔╝███████║██║ ███████║██║ ██║██║██╔██╗ ██║
//██╔═══╝ ██╔══██║██║ ██╔══██║██║ ██║██║██║╚██╗██║
//██║ ██║ ██║███████╗██║ ██║██████╔╝██║██║ ╚████║
//╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═╝╚═╝ ╚═══╝
pragma solidity 0.8.16;
//SPDX-License-Identifier: BUSL-1.1
import {Owner} from "utils/Owner.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {SafeERC20} from "openzeppelin/token/ERC20/utils/SafeERC20.sol";
import {Pausable} from "openzeppelin/security/Pausable.sol";
import {ReentrancyGuard} from "openzeppelin/security/ReentrancyGuard.sol";
import {Errors} from "utils/Errors.sol";
import {WarToken} from "../Token.sol";
import {IRatios} from "interfaces/IRatios.sol";
import {IWarRedeemModule} from "interfaces/IWarRedeemModule.sol";
import {IWarLocker} from "interfaces/IWarLocker.sol";
/**
* @title Warlord contract to redeem vlTokens by burning WAR
* @author Paladin
* @notice Redeem vlTokens against WAR & burn WAR
*/
contract ShutdownRedeemer is IWarRedeemModule, ReentrancyGuard, Pausable, Owner {
using SafeERC20 for IERC20;
// Constants
/**
* @notice 1e18 scale
*/
uint256 public constant UNIT = 1e18;
/**
* @notice Max BPS value (100%)
*/
uint256 public constant MAX_BPS = 10_000;
// Struct
/**
* @notice TokenIndex struct
* queueIndex: current index for the queue
* redeemIndex: current index for redeems
*/
struct TokenIndex {
uint256 queueIndex;
uint256 redeemIndex;
}
/**
* @notice RedeemTicket struct
* amount: amount of tokens to redeem
* redeemIndex: index at which the redeem is possible
* token: address of the token to redeem
* redeemed: true if redeemed
*/
struct RedeemTicket {
uint256 id;
uint256 amount;
uint256 redeemIndex;
address token;
bool redeemed;
}
/**
* @notice TokenWeight struct
* token: token which backs the war token
* weight: the percentage of the backing in BPS
*/
struct TokenWeight {
address token;
uint256 weight;
}
// Storage
/**
* @notice Address of the WAR token
*/
address public immutable war;
/**
* @notice Address of the contract calculating the burn amounts
*/
IRatios public ratios;
address public shutdownMigrator;
/**
* @notice Address of receive the redeem fees
*/
address public feeReceiver;
/**
* @notice Addresses of the tokens in the lockers
*/
address[] public tokens;
/**
* @notice Address of the Locker set for each token
*/
// token => Locker
mapping(address => address) public lockers;
/**
* @notice Address of the token for each Locker
*/
// Locker => token
mapping(address => address) public lockerTokens;
/**
* @notice Ratio of fees in BPS taken when redeeming
*/
uint256 public redeemFee;
/**
* @notice Indexes struct for each token
*/
mapping(address => TokenIndex) public tokenIndexes;
/**
* @notice List of Redeem tickets for each token for each user
*/
// user => token => UserIndexes
mapping(address => RedeemTicket[]) public userRedeems;
// Events
/**
* @notice Event emitted when a Redeem ticket is created
*/
event NewRedeemTicket(address indexed token, address indexed user, uint256 id, uint256 amount, uint256 redeemIndex);
/**
* @notice Event emitted when a Redeem ticket is redeemed
*/
event Redeemed(address indexed token, address indexed user, address receiver, uint256 indexed ticketNumber);
/**
* @notice Event emitted when setting a Locker for a token
*/
event SetWarLocker(address indexed token, address indexed locker);
/**
* @notice Event emitted when the redeem fee is updated
*/
event RedeemFeeUpdated(uint256 oldRedeemFee, uint256 newRedeemFee);
/**
* @notice Event emitted when the Ratio contract is updated
*/
event MintRatioUpdated(address oldMintRatio, address newMintRatio);
/**
* @notice Event emitted when the fee receiver is updated
*/
event FeeReceiverUpdated(address oldFeeReceiver, address newFeeReceiver);
// Constructor
constructor(address _war, address _ratios, address _feeReceiver, address _shutdownMigrator) {
if (_war == address(0) || _ratios == address(0) || _feeReceiver == address(0)) revert Errors.ZeroAddress();
war = _war;
ratios = IRatios(_ratios);
feeReceiver = _feeReceiver;
redeemFee = 0;
shutdownMigrator = _shutdownMigrator;
}
// View Functions
/**
* @notice Returns the amount queued for withdrawal for a given token
* @param token Address of the token
* @return uint256 : amount queued
*/
function queuedForWithdrawal(address token) public view returns (uint256) {
if (tokenIndexes[token].queueIndex <= tokenIndexes[token].redeemIndex) return 0;
return tokenIndexes[token].queueIndex - tokenIndexes[token].redeemIndex;
}
/**
* @notice Returns an user Redeem tickets
* @param user Address of the user
* @return RedeemTicket[] : user Redeem tickets
*/
function getUserRedeemTickets(address user) external view returns (RedeemTicket[] memory) {
return userRedeems[user];
}
/**
* @notice Returns an user active Redeem tickets
* @param user Address of the user
* @return RedeemTicket[] : user active Redeem tickets
*/
function getUserActiveRedeemTickets(address user) external view returns (RedeemTicket[] memory) {
RedeemTicket[] memory _userTickets = userRedeems[user];
uint256 length = _userTickets.length;
uint256 activeTickets;
// Get the amount of non-redeemed tickets
for (uint256 i; i < length;) {
if (!_userTickets[i].redeemed) {
unchecked {
++activeTickets;
}
}
unchecked {
++i;
}
}
// Create the array of non-redeemed tickets & list them
RedeemTicket[] memory activeRedeemTickets = new RedeemTicket[](activeTickets);
uint256 j;
for (uint256 i; i < length;) {
if (!_userTickets[i].redeemed) {
activeRedeemTickets[j] = _userTickets[i];
unchecked {
++j;
}
}
unchecked {
++i;
}
}
return activeRedeemTickets;
}
/**
* @notice Returns the current weights of all listed tokens for redeeming
* @return TokenWeight[] : weights and address for each token
*/
function getTokenWeights() external view returns (TokenWeight[] memory) {
uint256 length = tokens.length;
TokenWeight[] memory _tokens = new TokenWeight[](length);
for (uint256 i; i < length; i++) {
_tokens[i] = TokenWeight(tokens[i], _getTokenWeight(tokens[i]));
}
return _tokens;
}
// State Changing Functions
/**
* @notice Notifies when a Locker unlocks token and send them to this contract
* @param token Address of the token
* @param amount Amount of token unlocked
*/
function notifyUnlock(address token, uint256 amount) external whenNotPaused {
if (lockerTokens[msg.sender] == address(0) && msg.sender != shutdownMigrator) revert Errors.NotListedLocker();
// Update the redeem index for the token based on the amount unlocked & sent by the Locker
tokenIndexes[token].redeemIndex += amount;
}
/**
* @notice Joins the redeem queue for each token & burns the given amount of WAR token
* @param amount Amount of WAR to burn
*/
function joinQueue(uint256 amount) external nonReentrant whenNotPaused {
address[] memory _tokens = tokens;
uint256 tokensLength = _tokens.length;
if (amount == 0) revert Errors.ZeroValue();
// Pull the WAR token to burn
IERC20(war).safeTransferFrom(msg.sender, address(this), amount);
// Calculate the fee & burn amount
uint256 feeAmount = (amount * redeemFee) / MAX_BPS;
uint256 burnAmount = amount - feeAmount;
// Transfer out the fees & burn the rest of the WAR tokens
IERC20(war).safeTransfer(feeReceiver, feeAmount);
for (uint256 i; i < tokensLength;) {
if (lockers[_tokens[i]] == address(0)) revert Errors.NotListedLocker();
uint256 weight = _getTokenWeight(_tokens[i]);
// Calculate the amount of WAR burned for each token in the list
// based on the given weights
uint256 warAmount = (burnAmount * weight) / UNIT;
// Get the amount of token to redeem based on the WAR amount
uint256 redeemAmount = ratios.getBurnAmount(_tokens[i], warAmount);
// Not need for a ticket if the weight gives a value of 0
if (redeemAmount == 0) continue;
// Join the redeem queue for the token
_joinQueue(_tokens[i], msg.sender, redeemAmount);
unchecked {
++i;
}
}
// We burn the WAR at the end to avoid invalid
// calculations during weight calculations
WarToken(war).burn(address(this), burnAmount);
}
/**
* @notice Redeems tickets to receive the tokens
* @param tickets List of tickets to redeem
* @param receiver Address to receive the tokens
*/
function redeem(uint256[] calldata tickets, address receiver) external nonReentrant whenNotPaused {
if (receiver == address(0)) revert Errors.ZeroAddress();
uint256 ticketsLength = tickets.length;
if (ticketsLength == 0) revert Errors.EmptyArray();
for (uint256 i; i < ticketsLength;) {
// Redeem for each ticket
_redeem(msg.sender, receiver, tickets[i]);
unchecked {
++i;
}
}
}
// Internal Functions
/**
* @dev Calculates the redeem ratio for the given token
* @param token Address of the token
* @return (uint256) : weight of the token
*/
function _getTokenWeight(address token) internal view returns (uint256) {
uint256 totalWarSupply = WarToken(war).totalSupply();
if (totalWarSupply == 0) return 0;
uint256 tokenBalance = IWarLocker(lockers[token]).getCurrentLockedTokens();
uint256 queuedAmount = queuedForWithdrawal(token);
tokenBalance = tokenBalance > queuedAmount ? tokenBalance - queuedAmount : 0;
uint256 tokenRatio = ratios.getTokenRatio(token);
return ((tokenBalance * tokenRatio)) / totalWarSupply;
}
/**
* @dev Creates a new Redeem ticket for the given token, based on the calculated redeem amount
* @param token Address of the token
* @param user Address of the user owning the ticket
* @param amount Amount to be redeemed
*/
function _joinQueue(address token, address user, uint256 amount) internal {
TokenIndex storage tokenIndex = tokenIndexes[token];
// Update the queue index based on the amount to redeem
uint256 newQueueIndex = tokenIndex.queueIndex + amount;
tokenIndex.queueIndex = newQueueIndex;
uint256 userNextTicketId = userRedeems[user].length;
// Add a new ticket to the user list,
// using the new queue index as the redeem index for this ticket
userRedeems[user].push(
RedeemTicket({id: userNextTicketId, token: token, amount: amount, redeemIndex: newQueueIndex, redeemed: false})
);
emit NewRedeemTicket(token, user, userNextTicketId, amount, newQueueIndex);
}
/**
* @dev Executes the redeem for the given ticket & transfer out the tokens
* @param user Address of the user
* @param receiver Address to receive the tokens
* @param ticketNumber Index of the ticket in the user's list
*/
function _redeem(address user, address receiver, uint256 ticketNumber) internal {
if (ticketNumber >= userRedeems[user].length) revert Errors.InvalidIndex();
// Load the ticket & the token
RedeemTicket storage redeemTicket = userRedeems[user][ticketNumber];
address token = redeemTicket.token;
// Process any potential unlock for the Locker to update the redeem index
IWarLocker(lockers[token]).processUnlock();
// Check if the token's redeem index is high enough for this redeem
if (redeemTicket.redeemIndex > tokenIndexes[token].redeemIndex) revert Errors.CannotRedeemYet();
if (redeemTicket.redeemed) revert Errors.AlreadyRedeemed();
redeemTicket.redeemed = true;
// Send the tokens to the receiver
IERC20(token).safeTransfer(receiver, redeemTicket.amount);
emit Redeemed(token, user, receiver, ticketNumber);
}
// Admin Functions
/**
* @notice Sets a Locker contract for a given token
* @param token Address of the token
* @param warLocker Address of the Locker contract
*/
function setLocker(address token, address warLocker) external onlyOwner {
if (token == address(0) || warLocker == address(0)) revert Errors.ZeroAddress();
address expectedToken = IWarLocker(warLocker).token();
if (expectedToken != token) revert Errors.MismatchingLocker(expectedToken, token);
if (lockers[token] == address(0)) {
// New token listed
tokens.push(token);
}
lockers[token] = warLocker;
lockerTokens[warLocker] = token;
emit SetWarLocker(token, warLocker);
}
/**
* @notice Sets the Ratio contract address
* @param newRatios Address of the new Ratio contract
*/
function setRatios(address newRatios) external onlyOwner {
if (newRatios == address(0)) revert Errors.ZeroAddress();
address oldRatios = address(ratios);
ratios = IRatios(newRatios);
emit MintRatioUpdated(oldRatios, newRatios);
}
/**
* @notice Sets the Fee Receiver address
* @param newFeeReceiver Address to receive the fees
*/
function setFeeReceiver(address newFeeReceiver) external onlyOwner {
if (newFeeReceiver == address(0)) revert Errors.ZeroAddress();
address oldFeeReceiver = feeReceiver;
feeReceiver = newFeeReceiver;
emit FeeReceiverUpdated(oldFeeReceiver, newFeeReceiver);
}
/**
* @notice Pause the contract
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice Unpause the contract
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice Recover ERC2O tokens in the contract
* @dev Recover ERC2O tokens in the contract
* @param token Address of the ERC2O token
* @return bool: success
*/
function recoverERC20(address token) external onlyOwner returns (bool) {
if (token == address(0)) revert Errors.ZeroAddress();
uint256 amount = IERC20(token).balanceOf(address(this));
if (amount == 0) revert Errors.ZeroValue();
IERC20(token).safeTransfer(owner(), amount);
return true;
}
}
Owner.sol 38 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
import "openzeppelin/access/Ownable.sol";
/**
* @title Extend OZ Ownable contract
*/
/// @author Paladin
contract Owner is Ownable {
address public pendingOwner;
event NewPendingOwner(address indexed previousPendingOwner, address indexed newPendingOwner);
error CannotBeOwner();
error CallerNotPendingOwner();
error OwnerAddressZero();
function transferOwnership(address newOwner) public virtual override onlyOwner {
if (newOwner == address(0)) revert OwnerAddressZero();
if (newOwner == owner()) revert CannotBeOwner();
address oldPendingOwner = pendingOwner;
pendingOwner = newOwner;
emit NewPendingOwner(oldPendingOwner, newOwner);
}
function acceptOwnership() public virtual {
if (msg.sender != pendingOwner) revert CallerNotPendingOwner();
address newOwner = pendingOwner;
_transferOwnership(pendingOwner);
pendingOwner = address(0);
emit NewPendingOwner(newOwner, address(0));
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
Pausable.sol 105 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
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());
}
}
ReentrancyGuard.sol 69 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
Errors.sol 71 lines
pragma solidity 0.8.16;
//SPDX-License-Identifier: Unlicensed
library Errors {
// Argument validation
error ZeroAddress();
error ZeroValue();
error DifferentSizeArrays(uint256 size1, uint256 size2);
error EmptyArray();
error AlreadySet();
error SameAddress();
error InvalidParameter();
// Ownership
error CannotBeOwner();
error CallerNotPendingOwner();
error CallerNotAllowed();
// Token
error AllowanceUnderflow();
// Controller
error ListedLocker();
error ListedFarmer();
error InvalidFeeRatio();
error HarvestNotAllowed();
// Locker
error NoWarLocker(); // _locker[token] == 0x0
error LockerShutdown();
error MismatchingLocker(address expected, address actual);
// Minter
error MintAmountBiggerThanSupply();
// Redeemer
error NotListedLocker();
error InvalidIndex();
error CannotRedeemYet();
error AlreadyRedeemed();
error InvalidWeightSum();
// Staker
error AlreadyListedDepositor();
error NotListedDepositor();
error MismatchingFarmer();
// MintRatio
error ZeroMintAmount();
error SupplyAlreadySet();
error RatioAlreadySet();
// Harvestable
error NotRewardToken();
// IFarmer
error IncorrectToken();
error UnstakingMoreThanBalance();
// Maths
error NumberExceed128Bits();
// AuraBalFarmer
error SlippageTooHigh();
// Admin
error RecoverForbidden();
// AuraLocker
error DelegationRequiresLock();
}
Token.sol 134 lines
//██████╗ █████╗ ██╗ █████╗ ██████╗ ██╗███╗ ██╗
//██╔══██╗██╔══██╗██║ ██╔══██╗██╔══██╗██║████╗ ██║
//██████╔╝███████║██║ ███████║██║ ██║██║██╔██╗ ██║
//██╔═══╝ ██╔══██║██║ ██╔══██║██║ ██║██║██║╚██╗██║
//██║ ██║ ██║███████╗██║ ██║██████╔╝██║██║ ╚████║
//╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═╝╚═╝ ╚═══╝
pragma solidity 0.8.16;
//SPDX-License-Identifier: BUSL-1.1
import {ERC20} from "solmate/tokens/ERC20.sol";
import {AccessControl} from "openzeppelin/access/AccessControl.sol";
import {Errors} from "utils/Errors.sol";
/**
* @title Warlord Token contract
* @author Paladin
* @notice ERC20 token minted by deposit in Warlord
*/
contract WarToken is ERC20, AccessControl {
/**
* @notice Event emitted when a new pending owner is set
*/
event NewPendingOwner(address indexed previousPendingOwner, address indexed newPendingOwner);
/**
* @notice Address of the current pending owner
*/
address public pendingOwner;
/**
* @notice Address of the current owner
*/
address public owner;
/**
* @notice Minter role
*/
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
/**
* @notice Burner role
*/
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
// Constructor
constructor() ERC20("Warlord token", "WAR", 18) {
owner = msg.sender;
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setRoleAdmin(DEFAULT_ADMIN_ROLE, keccak256("NO_ROLE"));
}
/**
* @notice Set the given address as the new pending owner
* @param newOwner Address to set as pending owner
*/
function transferOwnership(address newOwner) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (newOwner == address(0)) revert Errors.ZeroAddress();
if (newOwner == owner) revert Errors.CannotBeOwner();
address oldPendingOwner = pendingOwner;
pendingOwner = newOwner;
emit NewPendingOwner(oldPendingOwner, newOwner);
}
/**
* @notice Accept the ownership transfer (only callable by the current pending owner)
*/
function acceptOwnership() external {
if (msg.sender != pendingOwner) revert Errors.CallerNotPendingOwner();
address newOwner = pendingOwner;
// Revoke the previous owner ADMIN role and set it for the new owner
_revokeRole(DEFAULT_ADMIN_ROLE, owner);
_grantRole(DEFAULT_ADMIN_ROLE, newOwner);
owner = newOwner;
// Reset the pending owner
pendingOwner = address(0);
emit NewPendingOwner(newOwner, address(0));
}
/**
* @notice Mints the given amount of tokens to the given address
* @param to Address to mint token to
* @param amount Amount of token to mint
*/
function mint(address to, uint256 amount) external onlyRole(MINTER_ROLE) {
_mint(to, amount);
}
/**
* @notice Burns the given amount of tokens from the given address
* @param from Address to burn token from
* @param amount Amount of token to burn
*/
function burn(address from, uint256 amount) external onlyRole(BURNER_ROLE) {
_burn(from, amount);
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
* @param spender The address of the spender
* @param addedValue Amount of token to increase the allowance
*/
function increaseAllowance(address spender, uint256 addedValue) external returns (bool) {
uint256 newAllowance = allowance[msg.sender][spender] + addedValue;
allowance[msg.sender][spender] = newAllowance;
emit Approval(msg.sender, spender, newAllowance);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
* @param spender The address of the spender
* @param subtractedValue Amount of token to increase the allowance
*/
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
uint256 currentAllowance = allowance[msg.sender][spender];
if (subtractedValue > currentAllowance) revert Errors.AllowanceUnderflow();
uint256 newAllowance = currentAllowance - subtractedValue;
allowance[msg.sender][spender] = newAllowance;
emit Approval(msg.sender, spender, newAllowance);
return true;
}
}
IRatios.sol 9 lines
// SPDX-License-Identifier: Unlicensed
pragma solidity 0.8.16;
interface IRatios {
function getTokenRatio(address token) external view returns (uint256);
function addToken(address token, uint256 maxSupply) external;
function getMintAmount(address token, uint256 amount) external view returns (uint256 mintAmount);
function getBurnAmount(address token, uint256 amount) external view returns (uint256 burnAmount);
}
IWarRedeemModule.sol 7 lines
// SPDX-License-Identifier: Unlicensed
pragma solidity 0.8.16;
interface IWarRedeemModule {
function queuedForWithdrawal(address token) external returns (uint256);
function notifyUnlock(address token, uint256 amount) external;
}
IWarLocker.sol 11 lines
// SPDX-License-Identifier: Unlicensed
pragma solidity 0.8.16;
import {IHarvestable} from "./IHarvestable.sol";
interface IWarLocker is IHarvestable {
function lock(uint256 amount) external;
function token() external view returns (address);
function getCurrentLockedTokens() external view returns (uint256);
function processUnlock() external;
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "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");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
ERC20.sol 206 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
AccessControl.sol 247 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
IHarvestable.sol 7 lines
// SPDX-License-Identifier: Unlicensed
pragma solidity 0.8.16;
interface IHarvestable {
function harvest() external;
function rewardTokens() external view returns (address[] memory);
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
Strings.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @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] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Read Contract
MAX_BPS 0xfd967f47 → uint256
UNIT 0x9d8e2177 → uint256
feeReceiver 0xb3f00674 → address
getTokenWeights 0x32bfe469 → tuple[]
getUserActiveRedeemTickets 0x8739cedf → tuple[]
getUserRedeemTickets 0x5aec5f55 → tuple[]
lockerTokens 0x7d01ac41 → address
lockers 0x2c8e7a21 → address
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
pendingOwner 0xe30c3978 → address
queuedForWithdrawal 0x3da5ffc0 → uint256
ratios 0xcf6d625e → address
redeemFee 0x965fa21e → uint256
shutdownMigrator 0x59cbe580 → address
tokenIndexes 0x04bc3b1c → uint256, uint256
tokens 0x4f64b2be → address
userRedeems 0x4f62b7ec → uint256, uint256, uint256, address, bool
war 0x099bf456 → address
Write Contract 12 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
joinQueue 0x96949420
uint256 amount
notifyUnlock 0x720536d7
address token
uint256 amount
pause 0x8456cb59
No parameters
recoverERC20 0x9e8c708e
address token
returns: bool
redeem 0x492e47d2
uint256[] tickets
address receiver
renounceOwnership 0x715018a6
No parameters
setFeeReceiver 0xefdcd974
address newFeeReceiver
setLocker 0x65d9e844
address token
address warLocker
setRatios 0x6573220e
address newRatios
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
Recent Transactions
No transactions found for this address