Address Contract Verified
Address
0xcccCCCcCCC33D538DBC2EE4fEab0a7A1FF4e8A94
Balance
0 ETH
Nonce
1
Code Size
8108 bytes
Creator
0x28E6eED8...adFb at tx 0x10de68e4...fdb141
Indexed Transactions
4 (24,432,729 → 24,432,802)
Gas Used (indexed)
164,800
Contract Bytecode
8108 bytes
0x608060405234801561000f575f5ffd5b50600436106101bb575f3560e01c80637ecebe00116100f3578063b1a840f211610093578063d505accf1161006e578063d505accf14610431578063dd62ed3e14610444578063e7a324dc1461046e578063f9a5c63914610495575f5ffd5b8063b1a840f2146103d8578063bf353dbb146103eb578063cd0d00961461040a575f5ffd5b80639c52a7f1116100ce5780639c52a7f11461038c5780639dc29fac1461039f5780639fd5a6cf146103b2578063a9059cbb146103c5575f5ffd5b80637ecebe001461034657806394b7175c1461036557806395d89b4114610384575f5ffd5b80633644e5151161015e57806342966c681161013957806342966c68146102fa5780635c19a95c1461030d57806365fae35e1461032057806370a0823114610333575f5ffd5b80633644e5151461029f57806337231224146102a757806340c10f19146102e7575f5ffd5b806318160ddd1161019957806318160ddd1461021557806323b872dd1461022c57806330adf81f1461023f578063313ce56714610266575f5ffd5b806306fdde03146101bf578063095ea7b3146101dd578063097ac46e14610200575b5f5ffd5b6101c76104b4565b6040516101d4919061199a565b60405180910390f35b6101f06101eb3660046119c7565b610540565b60405190151581526020016101d4565b61021361020e366004611ab1565b6105ac565b005b61021e60035481565b6040519081526020016101d4565b6101f061023a366004611b08565b6106ce565b61021e7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b61028d7f000000000000000000000000000000000000000000000000000000000000001281565b60405160ff90911681526020016101d4565b61021e610715565b6102cf6102b5366004611b42565b60076020525f90815260409020546001600160a01b031681565b6040516001600160a01b0390911681526020016101d4565b6102136102f53660046119c7565b610806565b610213610308366004611b5b565b610838565b61021361031b366004611b42565b6108f7565b61021361032e366004611b42565b610902565b61021e610341366004611b42565b61098e565b61021e610354366004611b42565b60066020525f908152604090205481565b61021e610373366004611b42565b60096020525f908152604090205481565b6101c76109ab565b61021361039a366004611b42565b6109b8565b6102136103ad3660046119c7565b610a43565b6102136103c0366004611b72565b610a72565b6101f06103d33660046119c7565b610c46565b6102136103e6366004611c08565b610c85565b61021e6103f9366004611b42565b5f6020819052908152604090205481565b61021e7f000000000000000000000000000000000000000000000000000000000000000181565b61021361043f366004611c4b565b610ec0565b61021e610452366004611cb1565b600560209081525f928352604080842090915290825290205481565b61021e7fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf81565b61021e6104a3366004611b42565b60086020525f908152604090205481565b600180546104c190611cd9565b80601f01602080910402602001604051908101604052809291908181526020018280546104ed90611cd9565b80156105385780601f1061050f57610100808354040283529160200191610538565b820191905f5260205f20905b81548152906001019060200180831161051b57829003601f168201915b505050505081565b335f8181526005602090815260408083206001600160a01b038716808552925280832085905551919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259061059a9086815260200190565b60405180910390a35060015b92915050565b335f908152602081905260409020546001146105f4576040517fea8e4eb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b817f6e616d65000000000000000000000000000000000000000000000000000000000361062d5760016106278282611d6f565b50610692565b817f73796d626f6c0000000000000000000000000000000000000000000000000000036106605760026106278282611d6f565b6040517fba81a94200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b817fe42e0b9a029dc87ccb1029c632e6359090acd0eb032b2b59c811e3ec70160dc6826040516106c2919061199a565b60405180910390a25050565b5f6106da848484610f2f565b6001600160a01b038086165f9081526007602052604080822054878416835291205492935061070e92908216911684610f44565b9392505050565b5f7f000000000000000000000000000000000000000000000000000000000000000146146107e15750604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527fe416b338a274162320c79445ae6604141d1cb08275eb27011b69f002dc094d05828401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b507fe50e09d42247e1d1c31707653d025eb2548d4fca303d404f3595d1716adc76e490565b610810828261108b565b6001600160a01b038083165f90815260076020526040812054610834921683610f44565b5050565b5f6108423361098e565b90508181101561087e576040517ff4d678b800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b335f908152600460209081526040808320858503905560038054869003905560079091528120546108bb916001600160a01b039091169084610f44565b6040518281525f9033907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906020015b60405180910390a35050565b3361083481836111b7565b335f9081526020819052604090205460011461094a576040517fea8e4eb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0381165f8181526020819052604080822060019055517fdd0e34038ac38b2a1ce960229778ac48a8719bc900b6c4f8d0475c6e8b385a609190a250565b6001600160a01b0381165f908152600460205260408120546105a6565b600280546104c190611cd9565b335f90815260208190526040902054600114610a00576040517fea8e4eb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0381165f81815260208190526040808220829055517f184450df2e323acec0ed3b5c7531b81f9b4cdef7914dfd4c0a4317416bb5251b9190a250565b610a4d8282611240565b6001600160a01b038083165f9081526007602052604081205461083492169083610f44565b81421115610aac576040517f1a15a3cc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0385165f90815260066020526040812080546001810190915590610ad5610715565b604080517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c960208201526001600160a01b03808b169282019290925290881660608201526080810187905260a0810184905260c0810186905260e00160405160208183030381529060405280519060200120604051602001610b899291907f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b604051602081830303815290604052805190602001209050610bac8782856113fa565b610be2576040517fddafbaef00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038781165f818152600560209081526040808320948b168084529482529182902089905590518881527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050505050565b5f610c51838361163f565b335f90815260076020526040808220546001600160a01b03878116845291909220549293506105a692918116911684610f44565b8160400135421115610cc3576040517f7318a02400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610ccc610715565b7fe48329057bfd03d55e49b547132e39cffd9c1820ad7b9d4c5307691425d15adf84604051602001610cff929190611e48565b60405160208183030381529060405280519060200120604051602001610d579291907f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b6040516020818303038152906040528051906020012090505f600182845f016020810190610d859190611e85565b604080515f815260208181018084529490945260ff9092168282015291860135606082015290850135608082015260a0016020604051602081039080840390855afa158015610dd6573d5f5f3e3d5ffd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001519150506001600160a01b038116610e41576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0381165f908152600960205260408120805491610e6483611ecb565b91905055846020013514610ea4576040517fa3feab1500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610eba81610eb56020870187611b42565b6111b7565b50505050565b610f2687878787868689604051602001610f1293929190928352602083019190915260f81b7fff0000000000000000000000000000000000000000000000000000000000000016604082015260410190565b604051602081830303815290604052610a72565b50505050505050565b5f610f3c33858585611765565b949350505050565b816001600160a01b0316836001600160a01b031614158015610f6557505f81115b15611086576001600160a01b03831615610ff8576001600160a01b0383165f9081526008602052604081205490610f9c8383611ee3565b6001600160a01b0386165f81815260086020908152604091829020849055815186815290810184905292935090917f1297f65000762bf6b4d22e0529570e8f6c1124585ed2c9e52f468292274c5b20910160405180910390a250505b6001600160a01b03821615611086576001600160a01b0382165f908152600860205260408120549061102a8383611ef6565b6001600160a01b0385165f81815260086020908152604091829020849055815186815290810184905292935090917f1297f65000762bf6b4d22e0529570e8f6c1124585ed2c9e52f468292274c5b20910160405180910390a250505b505050565b335f908152602081905260409020546001146110d3576040517fea8e4eb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038216158015906110f457506001600160a01b0382163014155b61112a576040517fe6c4247b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611169828261114d856001600160a01b03165f9081526004602052604090205490565b016001600160a01b039091165f90815260046020526040902055565b806003546111779190611ef6565b6003556040518181526001600160a01b038316905f907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906020016108eb565b6001600160a01b038083165f8181526007602052604080822080548686167fffffffffffffffffffffffff0000000000000000000000000000000000000000821681179092559151919094169392849290917f5884d7e3ec123de8e772bcf576c18dcdad75b056c4314f999ed966693419c6929190a4611086818361123b8661098e565b610f44565b335f90815260208190526040902054600114611288576040517fea8e4eb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6112928361098e565b9050818110156112ce576040517ff4d678b800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038316331461136d576001600160a01b0383165f9081526005602090815260408083203384529091529020545f19811461136b5782811015611343576040517f13be252b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0384165f908152600560209081526040808320338452909152902083820390555b505b6113ac8383611390866001600160a01b03165f9081526004602052604090205490565b036001600160a01b039091165f90815260046020526040902055565b6003805483900390556040518281525f906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b5f6001600160a01b03841661143b576040517f815e1d6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81516041036114d35760208281015160408085015160608087015183515f8082529681018086528a9052951a928501839052840183905260808401819052919260019060a0016020604051602081039080840390855afa1580156114a1573d5f5f3e3d5ffd5b505050602060405103516001600160a01b0316876001600160a01b0316036114cf576001935050505061070e565b5050505b6001600160a01b0384163b1561070e575f5f856001600160a01b03168585604051602401611502929190611f09565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f1626ba7e00000000000000000000000000000000000000000000000000000000179052516115839190611f21565b5f60405180830381855afa9150503d805f81146115bb576040519150601f19603f3d011682016040523d82523d5f602084013e6115c0565b606091505b50915091508180156115d3575080516020145b8015611635575080517f1626ba7e00000000000000000000000000000000000000000000000000000000906116119083016020908101908401611f37565b7fffffffff0000000000000000000000000000000000000000000000000000000016145b9695505050505050565b5f6001600160a01b0383161580159061166157506001600160a01b0383163014155b611697576040517fe6c4247b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6116a13361098e565b9050828110156116dd576040517ff4d678b800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b335f818152600460205260409020546116f891908590611390565b61171b848461114d876001600160a01b03165f9081526004602052604090205490565b6040518381526001600160a01b0385169033907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35060019392505050565b5f6001600160a01b0383161580159061178757506001600160a01b0383163014155b6117bd576040517fe6c4247b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6117c78561098e565b905082811015611803576040517ff4d678b800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b856001600160a01b0316856001600160a01b0316146118af576001600160a01b038086165f908152600560209081526040808320938a16835292905220545f1981146118ad5783811015611883576040517f13be252b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038087165f908152600560209081526040808320938b1683529290522084820390555b505b6118d28584611390886001600160a01b03165f9081526004602052604090205490565b6118f5848461114d876001600160a01b03165f9081526004602052604090205490565b836001600160a01b0316856001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161193a91815260200190565b60405180910390a350600195945050505050565b5f81518084528060208401602086015e5f6020828601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011685010191505092915050565b602081525f61070e602083018461194e565b80356001600160a01b03811681146119c2575f5ffd5b919050565b5f5f604083850312156119d8575f5ffd5b6119e1836119ac565b946020939093013593505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f5f67ffffffffffffffff841115611a3657611a366119ef565b506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f85018116603f0116810181811067ffffffffffffffff82111715611a8357611a836119ef565b604052838152905080828401851015611a9a575f5ffd5b838360208301375f60208583010152509392505050565b5f5f60408385031215611ac2575f5ffd5b82359150602083013567ffffffffffffffff811115611adf575f5ffd5b8301601f81018513611aef575f5ffd5b611afe85823560208401611a1c565b9150509250929050565b5f5f5f60608486031215611b1a575f5ffd5b611b23846119ac565b9250611b31602085016119ac565b929592945050506040919091013590565b5f60208284031215611b52575f5ffd5b61070e826119ac565b5f60208284031215611b6b575f5ffd5b5035919050565b5f5f5f5f5f60a08688031215611b86575f5ffd5b611b8f866119ac565b9450611b9d602087016119ac565b93506040860135925060608601359150608086013567ffffffffffffffff811115611bc6575f5ffd5b8601601f81018813611bd6575f5ffd5b611be588823560208401611a1c565b9150509295509295909350565b5f60608284031215611c02575f5ffd5b50919050565b5f5f60c08385031215611c19575f5ffd5b611c238484611bf2565b9150611c328460608501611bf2565b90509250929050565b803560ff811681146119c2575f5ffd5b5f5f5f5f5f5f5f60e0888a031215611c61575f5ffd5b611c6a886119ac565b9650611c78602089016119ac565b95506040880135945060608801359350611c9460808901611c3b565b9699959850939692959460a0840135945060c09093013592915050565b5f5f60408385031215611cc2575f5ffd5b611ccb836119ac565b9150611c32602084016119ac565b600181811c90821680611ced57607f821691505b602082108103611c02577f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b601f82111561108657805f5260205f20601f840160051c81016020851015611d495750805b601f840160051c820191505b81811015611d68575f8155600101611d55565b5050505050565b815167ffffffffffffffff811115611d8957611d896119ef565b611d9d81611d978454611cd9565b84611d24565b6020601f821160018114611dcf575f8315611db85750848201515b5f19600385901b1c1916600184901b178455611d68565b5f848152602081207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08516915b82811015611e1c5787850151825560209485019460019092019101611dfc565b5084821015611e3957868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b828152608081016001600160a01b03611e60846119ac565b1660208381019190915283013560408084019190915290920135606090910152919050565b5f60208284031215611e95575f5ffd5b61070e82611c3b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f5f198203611edc57611edc611e9e565b5060010190565b818103818111156105a6576105a6611e9e565b808201808211156105a6576105a6611e9e565b828152604060208201525f610f3c604083018461194e565b5f82518060208501845e5f920191825250919050565b5f60208284031215611f47575f5ffd5b81517fffffffff000000000000000000000000000000000000000000000000000000008116811461070e575f5ffdfea2646970667358221220c1d5d75a16499739585a159b76f405ccf800d7dde4ffc2d9db985a1515b1af9c64736f6c634300081c0033
Verified Source Code Full Match
Compiler: v0.8.28+commit.7893614a
EVM: cancun
Optimization: Yes (10000 runs)
CFG.sol 29 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.28;
import {DelegationToken} from "src/DelegationToken.sol";
import {ICFG} from "src/interfaces/ICFG.sol";
/// @title Centrifuge Token
contract CFG is DelegationToken, ICFG {
constructor(address ward) DelegationToken(18) {
file("name", "Centrifuge");
file("symbol", "CFG");
rely(ward);
}
/// @notice Burns sender's tokens.
function burn(uint256 value) external {
uint256 balance = balanceOf(msg.sender);
require(balance >= value, InsufficientBalance());
unchecked {
// We don't need overflow checks b/c require(balance >= value) and balance <= totalSupply
_setBalance(msg.sender, balance - value);
totalSupply -= value;
}
_moveDelegateVotes(delegatee[msg.sender], address(0), value);
emit Transfer(msg.sender, address(0), value);
}
}
DelegationToken.sol 106 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.28;
import {ERC20} from "protocol-v3/misc/ERC20.sol";
import {IERC20} from "protocol-v3/misc/interfaces/IERC20.sol";
import {IDelegationToken, Delegation, Signature} from "src/interfaces/IDelegationToken.sol";
/// @title Delegation Token
/// @notice Extension of ERC20 to support token delegation
/// This extension keeps track of the current voting power delegated to each account. Voting power can be
/// delegated either by calling the `delegate` function directly, or by providing a signature to be
/// used with `delegateBySig`.
///
/// This enables onchain votes on external voting smart contracts leveraging storage proofs.
///
/// By default, token balance does not account for voting power. This makes transfers cheaper. Whether
/// an account has to self-delegate to vote depends on the voting contract implementation.
/// @author Modified from https://github.com/morpho-org/morpho-token
contract DelegationToken is ERC20, IDelegationToken {
bytes32 public constant DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @inheritdoc IDelegationToken
mapping(address => address) public delegatee;
/// @inheritdoc IDelegationToken
mapping(address => uint256) public delegatedVotingPower;
/// @inheritdoc IDelegationToken
mapping(address => uint256) public delegationNonce;
constructor(uint8 decimals_) ERC20(decimals_) {}
/// @inheritdoc IDelegationToken
function delegate(address newDelegatee) external {
address delegator = msg.sender;
_delegate(delegator, newDelegatee);
}
/// @inheritdoc IDelegationToken
function delegateWithSig(Delegation calldata delegation, Signature calldata signature) external {
require(block.timestamp <= delegation.expiry, DelegatesExpiredSignature());
bytes32 digest = keccak256(
abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), keccak256(abi.encode(DELEGATION_TYPEHASH, delegation)))
);
address delegator = ecrecover(digest, signature.v, signature.r, signature.s);
require(delegator != address(0), InvalidSignature());
require(delegation.nonce == delegationNonce[delegator]++, InvalidDelegationNonce());
_delegate(delegator, delegation.delegatee);
}
/// @dev Delegates the balance of the `delegator` to `newDelegatee`.
function _delegate(address delegator, address newDelegatee) internal {
address oldDelegatee = delegatee[delegator];
delegatee[delegator] = newDelegatee;
emit DelegateeChanged(delegator, oldDelegatee, newDelegatee);
_moveDelegateVotes(oldDelegatee, newDelegatee, balanceOf(delegator));
}
/// @dev Moves voting power when tokens are transferred.
function transfer(address to, uint256 value) public override(ERC20, IERC20) returns (bool success) {
success = super.transfer(to, value);
_moveDelegateVotes(delegatee[msg.sender], delegatee[to], value);
}
/// @dev Moves voting power when tokens are transferred.
function transferFrom(address from, address to, uint256 value)
public
override(ERC20, IERC20)
returns (bool success)
{
success = super.transferFrom(from, to, value);
_moveDelegateVotes(delegatee[from], delegatee[to], value);
}
/// @dev Adds voting power when tokens are minted.
function mint(address to, uint256 value) public override(ERC20) {
super.mint(to, value);
_moveDelegateVotes(address(0), delegatee[to], value);
}
/// @dev Removes voting power when tokens are burned.
function burn(address from, uint256 value) public override(ERC20) {
super.burn(from, value);
_moveDelegateVotes(delegatee[from], address(0), value);
}
/// @dev Moves delegated votes from one delegate to another.
function _moveDelegateVotes(address from, address to, uint256 amount) internal {
if (from != to && amount > 0) {
if (from != address(0)) {
uint256 oldValue = delegatedVotingPower[from];
uint256 newValue = oldValue - amount;
delegatedVotingPower[from] = newValue;
emit DelegatedVotingPowerChanged(from, oldValue, newValue);
}
if (to != address(0)) {
uint256 oldValue = delegatedVotingPower[to];
uint256 newValue = oldValue + amount;
delegatedVotingPower[to] = newValue;
emit DelegatedVotingPowerChanged(to, oldValue, newValue);
}
}
}
}
ICFG.sol 9 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.28;
import {IDelegationToken} from "src/interfaces/IDelegationToken.sol";
interface ICFG is IDelegationToken {
/// @notice Burns sender's tokens.
function burn(uint256 value) external;
}
ERC20.sol 204 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {Auth} from "src/misc/Auth.sol";
import {EIP712Lib} from "src/misc/libraries/EIP712Lib.sol";
import {SignatureLib} from "src/misc/libraries/SignatureLib.sol";
import {IERC20, IERC20Metadata, IERC20Permit} from "src/misc/interfaces/IERC20.sol";
/// @title ERC20
/// @notice Standard ERC-20 implementation, with mint/burn functionality and permit logic.
/// @author Modified from https://github.com/makerdao/xdomain-dss/blob/master/src/Dai.sol
contract ERC20 is Auth, IERC20Metadata, IERC20Permit {
error FileUnrecognizedWhat();
/// @inheritdoc IERC20Metadata
string public name;
/// @inheritdoc IERC20Metadata
string public symbol;
/// @inheritdoc IERC20Metadata
uint8 public immutable decimals;
/// @inheritdoc IERC20
uint256 public totalSupply;
mapping(address => uint256) private balances;
/// @inheritdoc IERC20
mapping(address => mapping(address => uint256)) public allowance;
/// @inheritdoc IERC20Permit
mapping(address => uint256) public nonces;
// --- EIP712 ---
bytes32 private immutable nameHash;
bytes32 private immutable versionHash;
uint256 public immutable deploymentChainId;
bytes32 private immutable _DOMAIN_SEPARATOR;
bytes32 public constant PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
// --- Events ---
event File(bytes32 indexed what, string data);
constructor(uint8 decimals_) Auth(msg.sender) {
decimals = decimals_;
nameHash = keccak256(bytes("Centrifuge"));
versionHash = keccak256(bytes("1"));
deploymentChainId = block.chainid;
_DOMAIN_SEPARATOR = EIP712Lib.calculateDomainSeparator(nameHash, versionHash);
}
function _balanceOf(address user) internal view virtual returns (uint256) {
return balances[user];
}
/// @inheritdoc IERC20
function balanceOf(address user) public view virtual returns (uint256) {
return _balanceOf(user);
}
function _setBalance(address user, uint256 value) internal virtual {
balances[user] = value;
}
/// @inheritdoc IERC20Permit
function DOMAIN_SEPARATOR() public view returns (bytes32) {
return block.chainid == deploymentChainId
? _DOMAIN_SEPARATOR
: EIP712Lib.calculateDomainSeparator(nameHash, versionHash);
}
// --- Administration ---
function file(bytes32 what, string memory data) public virtual auth {
if (what == "name") name = data;
else if (what == "symbol") symbol = data;
else revert FileUnrecognizedWhat();
emit File(what, data);
}
// --- ERC20 Mutations ---
/// @inheritdoc IERC20
function transfer(address to, uint256 value) public virtual returns (bool) {
require(to != address(0) && to != address(this), InvalidAddress());
uint256 balance = balanceOf(msg.sender);
require(balance >= value, InsufficientBalance());
unchecked {
_setBalance(msg.sender, _balanceOf(msg.sender) - value);
// note: we don't need an overflow check here b/c sum of all balances == totalSupply
_setBalance(to, _balanceOf(to) + value);
}
emit Transfer(msg.sender, to, value);
return true;
}
/// @inheritdoc IERC20
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
return _transferFrom(msg.sender, from, to, value);
}
function _transferFrom(address sender, address from, address to, uint256 value) internal virtual returns (bool) {
require(to != address(0) && to != address(this), InvalidAddress());
uint256 balance = balanceOf(from);
require(balance >= value, InsufficientBalance());
if (from != sender) {
uint256 allowed = allowance[from][sender];
if (allowed != type(uint256).max) {
require(allowed >= value, InsufficientAllowance());
unchecked {
allowance[from][sender] = allowed - value;
}
}
}
unchecked {
_setBalance(from, _balanceOf(from) - value);
// note: we don't need an overflow check here b/c sum of all balances == totalSupply
_setBalance(to, _balanceOf(to) + value);
}
emit Transfer(from, to, value);
return true;
}
/// @inheritdoc IERC20
function approve(address spender, uint256 value) external returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// --- Mint/Burn ---
function mint(address to, uint256 value) public virtual auth {
require(to != address(0) && to != address(this), InvalidAddress());
unchecked {
// We don't need an overflow check here b/c balances[to] <= totalSupply
// and there is an overflow check below
_setBalance(to, _balanceOf(to) + value);
}
totalSupply = totalSupply + value;
emit Transfer(address(0), to, value);
}
function burn(address from, uint256 value) public virtual auth {
uint256 balance = balanceOf(from);
require(balance >= value, InsufficientBalance());
if (from != msg.sender) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
require(allowed >= value, InsufficientAllowance());
unchecked {
allowance[from][msg.sender] = allowed - value;
}
}
}
unchecked {
// We don't need overflow checks b/c require(balance >= value) and balance <= totalSupply
_setBalance(from, _balanceOf(from) - value);
totalSupply = totalSupply - value;
}
emit Transfer(from, address(0), value);
}
// --- Approve by signature ---
function permit(address owner, address spender, uint256 value, uint256 deadline, bytes memory signature) public {
require(block.timestamp <= deadline, PermitExpired());
uint256 nonce;
unchecked {
nonce = nonces[owner]++;
}
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonce, deadline))
)
);
require(SignatureLib.isValidSignature(owner, digest, signature), InvalidPermit());
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
/// @inheritdoc IERC20Permit
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
{
permit(owner, spender, value, deadline, abi.encodePacked(r, s, v));
}
}
IERC20.sol 200 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/// @title IERC20
/// @dev Interface of the ERC20 standard as defined in the EIP.
/// @author Modified from OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
interface IERC20 {
error InvalidAddress();
error InsufficientBalance();
error InsufficientAllowance();
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
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);
}
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
error PermitExpired();
error InvalidPermit();
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
interface IERC20Wrapper {
/**
* @dev Returns the address of the underlying ERC-20 token that is being wrapped.
*/
function underlying() external view returns (address);
/**
* @dev Allow a user to deposit underlying tokens and mint the corresponding number of wrapped tokens.
*/
function depositFor(address account, uint256 value) external returns (bool);
/**
* @dev Allow a user to burn a number of wrapped tokens and withdraw the corresponding number of underlying tokens.
*/
function withdrawTo(address account, uint256 value) external returns (bool);
}
IDelegationToken.sol 52 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.28;
import {IERC20Metadata, IERC20Permit} from "protocol-v3/misc/interfaces/IERC20.sol";
struct Delegation {
address delegatee;
uint256 nonce;
uint256 expiry;
}
struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
}
interface IDelegationToken is IERC20Metadata, IERC20Permit {
/// @notice Emitted when an delegator changes their delegatee.
event DelegateeChanged(address indexed delegator, address indexed oldDelegatee, address indexed newDelegatee);
/// @notice Emitted when a delegatee's delegated voting power changes.
event DelegatedVotingPowerChanged(address indexed delegatee, uint256 oldVotes, uint256 newVotes);
/// @notice The signature used has expired.
error DelegatesExpiredSignature();
/// @notice The delegation nonce used by the signer is not its current delegation nonce.
error InvalidDelegationNonce();
/// @notice The signature was invalid.
error InvalidSignature();
/// @notice Returns the delegatee that `account` has chosen.
function delegatee(address account) external view returns (address);
/// @notice Returns the current voting power delegated to `account`.
function delegatedVotingPower(address account) external view returns (uint256);
/// @notice Returns the current delegation nonce of `account`.
function delegationNonce(address account) external view returns (uint256);
/// @notice Delegates the balance of the sender to `newDelegatee`.
/// @dev Delegating to the zero address effectively removes the delegation, incidentally making transfers cheaper.
/// @dev Delegating to the previous delegatee does not revert.
function delegate(address newDelegatee) external;
/// @notice Delegates the balance of the signer to `newDelegatee`.
/// @dev Delegating to the zero address effectively removes the delegation, incidentally making transfers cheaper.
/// @dev Delegating to the previous delegatee effectively revokes past signatures with the same nonce.
function delegateWithSig(Delegation calldata delegation, Signature calldata signature) external;
}
Auth.sol 35 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {IAuth} from "src/misc/interfaces/IAuth.sol";
/// @title Auth
/// @notice Simple authentication pattern
/// @author Based on code from https://github.com/makerdao/dss
abstract contract Auth is IAuth {
/// @inheritdoc IAuth
mapping(address => uint256) public wards;
constructor(address initialWard) {
wards[initialWard] = 1;
emit Rely(initialWard);
}
/// @dev Check if the msg.sender has permissions
modifier auth() {
require(wards[msg.sender] == 1, NotAuthorized());
_;
}
/// @inheritdoc IAuth
function rely(address user) public auth {
wards[user] = 1;
emit Rely(user);
}
/// @inheritdoc IAuth
function deny(address user) public auth {
wards[user] = 0;
emit Deny(user);
}
}
EIP712Lib.sol 12 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/// @title EIP712 Lib
library EIP712Lib {
// keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
bytes32 public constant EIP712_DOMAIN_TYPEHASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;
function calculateDomainSeparator(bytes32 nameHash, bytes32 versionHash) internal view returns (bytes32) {
return keccak256(abi.encode(EIP712_DOMAIN_TYPEHASH, nameHash, versionHash, block.chainid, address(this)));
}
}
SignatureLib.sol 40 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
interface IERC1271 {
function isValidSignature(bytes32, bytes memory) external view returns (bytes4);
}
/// @title Signature Lib
library SignatureLib {
error InvalidSigner();
function isValidSignature(address signer, bytes32 digest, bytes memory signature)
internal
view
returns (bool valid)
{
require(signer != address(0), InvalidSigner());
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
if (signer == ecrecover(digest, v, r, s)) {
return true;
}
}
if (signer.code.length > 0) {
(bool success, bytes memory result) =
signer.staticcall(abi.encodeCall(IERC1271.isValidSignature, (digest, signature)));
valid =
(success && result.length == 32 && abi.decode(result, (bytes4)) == IERC1271.isValidSignature.selector);
}
}
}
IAuth.sol 18 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
interface IAuth {
event Rely(address indexed user);
event Deny(address indexed user);
error NotAuthorized();
/// @notice Returns whether the target is a ward (has admin access)
function wards(address target) external view returns (uint256);
/// @notice Make user a ward (give them admin access)
function rely(address user) external;
/// @notice Remove user as a ward (remove admin access)
function deny(address user) external;
}
Read Contract
DELEGATION_TYPEHASH 0xe7a324dc → bytes32
DOMAIN_SEPARATOR 0x3644e515 → bytes32
PERMIT_TYPEHASH 0x30adf81f → bytes32
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
decimals 0x313ce567 → uint8
delegatedVotingPower 0xf9a5c639 → uint256
delegatee 0x37231224 → address
delegationNonce 0x94b7175c → uint256
deploymentChainId 0xcd0d0096 → uint256
name 0x06fdde03 → string
nonces 0x7ecebe00 → uint256
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256
wards 0xbf353dbb → uint256
Write Contract 13 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address spender
uint256 value
returns: bool
burn 0x42966c68
uint256 value
burn 0x9dc29fac
address from
uint256 value
delegate 0x5c19a95c
address newDelegatee
delegateWithSig 0x34661381
tuple delegation
tuple signature
deny 0x9c52a7f1
address user
file 0x097ac46e
bytes32 what
string data
mint 0x40c10f19
address to
uint256 value
permit 0x9fd5a6cf
address owner
address spender
uint256 value
uint256 deadline
bytes signature
permit 0xd505accf
address owner
address spender
uint256 value
uint256 deadline
uint8 v
bytes32 r
bytes32 s
rely 0x65fae35e
address user
transfer 0xa9059cbb
address to
uint256 value
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 value
returns: bool
Top Interactions
| Address | Txns | Sent | Received |
|---|---|---|---|
| 0xf1Ec3a9C...0593 | 1 | 1 | |
| 0xB5D4fC91...a69E | 1 | 1 | |
| 0x0D070796...92Fe | 1 | 1 | |
| 0x073F5644...3AD7 | 1 | 1 |
Recent Transactions
|
| Hash | Block | Age | From/To | Value | |
|---|---|---|---|---|---|
| 0x090865f3...83fcbe | 24,432,802 | IN | 0x0D070796...92Fe | 0 ETH | |
| 0x8ac4d717...5566d4 | 24,432,788 | IN | 0xf1Ec3a9C...0593 | 0 ETH | |
| 0x8bbc470b...237d99 | 24,432,788 | IN | 0xB5D4fC91...a69E | 0 ETH | |
| 0x9c8ead68...f4d8bb | 24,432,729 | IN | 0x073F5644...3AD7 | 0 ETH |