¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.8.11+commit.d7f03943
Idioma
Solidity
Código Fuente del Contrato
Archivo 1 de 8: Address.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @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
* ====
*/functionisContract(address account) internalviewreturns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in// construction, since the code is only stored at the end of the// constructor execution.uint256 size;
assembly {
size :=extcodesize(account)
}
return size >0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/functionsendValue(addresspayable 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._
*/functionfunctionCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalreturns (bytesmemory) {
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._
*/functionfunctionCallWithValue(address target,
bytesmemory data,
uint256 value
) internalreturns (bytesmemory) {
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._
*/functionfunctionCallWithValue(address target,
bytesmemory data,
uint256 value,
stringmemory errorMessage
) internalreturns (bytesmemory) {
require(address(this).balance>= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytesmemory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target, bytesmemory data) internalviewreturns (bytesmemory) {
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._
*/functionfunctionStaticCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalviewreturns (bytesmemory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytesmemory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target, bytesmemory data) internalreturns (bytesmemory) {
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._
*/functionfunctionDelegateCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalreturns (bytesmemory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytesmemory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/functionverifyCallResult(bool success,
bytesmemory returndata,
stringmemory errorMessage
) internalpurereturns (bytesmemory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if presentif (returndata.length>0) {
// The easiest way to bubble the revert reason is using memory via assemblyassembly {
let returndata_size :=mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Código Fuente del Contrato
Archivo 2 de 8: Context.sol
// SPDX-License-Identifier: MITpragmasolidity ^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.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Código Fuente del Contrato
Archivo 3 de 8: IERC20.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (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.
*/functionallowance(address owner, address spender) externalviewreturns (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.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed 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.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
Código Fuente del Contrato
Archivo 4 de 8: IGovernanceToken.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.11;/**
* @title Governance token interface.
*/interfaceIGovernanceToken{
/// @notice A checkpoint for marking number of votes as of a given block.structCheckpoint {
// The 32-bit unsigned integer is valid until these estimated dates for these given chains:// - BSC: Sat Dec 23 2428 18:23:11 UTC// - ETH: Tue Apr 18 3826 09:27:12 UTC// This assumes that block mining rates don't speed up.uint32 blockNumber;
// This type is set to `uint224` for optimizations purposes (i.e., specifically to fit in a 32-byte block). It// assumes that the number of votes for the implementing governance token never exceeds the maximum value for a// 224-bit number.uint224 votes;
}
/**
* @notice Determine the number of votes for an account as of a block number.
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check.
* @param blockNumber The block number to get the vote balance at.
* @return The number of votes the account had as of the given block.
*/functiongetVotesAtBlock(address account, uint32 blockNumber) externalviewreturns (uint224);
/// @notice Emitted whenever a new delegate is set for an account.eventDelegateChanged(addressindexed delegator, address currentDelegate, address newDelegate);
/// @notice Emitted when a delegate's vote count changes.eventDelegateVotesChanged(addressindexed delegatee, uint224 oldVotes, uint224 newVotes);
}
Código Fuente del Contrato
Archivo 5 de 8: ITaxHandler.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.11;/**
* @title Tax handler interface
* @dev Any class that implements this interface can be used for protocol-specific tax calculations.
*/interfaceITaxHandler{
/**
* @notice Get number of tokens to pay as tax.
* @param benefactor Address of the benefactor.
* @param beneficiary Address of the beneficiary.
* @param amount Number of tokens in the transfer.
* @return Number of tokens to pay as tax.
*/functiongetTax(address benefactor,
address beneficiary,
uint256 amount
) externalviewreturns (uint256);
}
Código Fuente del Contrato
Archivo 6 de 8: ITreasuryHandler.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.11;/**
* @title Treasury handler interface
* @dev Any class that implements this interface can be used for protocol-specific operations pertaining to the treasury.
*/interfaceITreasuryHandler{
/**
* @notice Perform operations before a transfer is executed.
* @param benefactor Address of the benefactor.
* @param beneficiary Address of the beneficiary.
* @param amount Number of tokens in the transfer.
*/functionbeforeTransferHandler(address benefactor,
address beneficiary,
uint256 amount
) external;
/**
* @notice Perform operations after a transfer is executed.
* @param benefactor Address of the benefactor.
* @param beneficiary Address of the beneficiary.
* @param amount Number of tokens in the transfer.
*/functionafterTransferHandler(address benefactor,
address beneficiary,
uint256 amount
) external;
}
Código Fuente del Contrato
Archivo 7 de 8: Ownable.sol
// SPDX-License-Identifier: MITpragmasolidity ^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.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
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.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_setOwner(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function_setOwner(address newOwner) private{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Código Fuente del Contrato
Archivo 8 de 8: T1.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.11;import"@openzeppelin/contracts/access/Ownable.sol";
import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import"@openzeppelin/contracts/utils/Address.sol";
import"./governance/IGovernanceToken.sol";
import"./tax/ITaxHandler.sol";
import"./treasury/ITreasuryHandler.sol";
/**
* @title Tokenfi token contract
* @dev The Tokenfi token has modular systems for tax and treasury handler as well as governance capabilities.
*/contractT1isIERC20, IGovernanceToken, Ownable{
usingAddressforaddresspayable;
/// @dev Registry of user token balances.mapping(address=>uint256) private _balances;
/// @dev Registry of addresses users have given allowances to.mapping(address=>mapping(address=>uint256)) private _allowances;
/// @notice Registry of user delegates for governance.mapping(address=>address) public delegates;
/// @notice Registry of nonces for vote delegation.mapping(address=>uint256) public nonces;
/// @notice Registry of the number of balance checkpoints an account has.mapping(address=>uint32) public numCheckpoints;
/// @notice Registry of balance checkpoints per account.mapping(address=>mapping(uint32=> Checkpoint)) public checkpoints;
/// @notice The EIP-712 typehash for the contract's domain.bytes32publicconstant DOMAIN_TYPEHASH =keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract.bytes32publicconstant DELEGATION_TYPEHASH =keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice The contract implementing tax calculations.
ITaxHandler public taxHandler;
/// @notice The contract that performs treasury-related operations.
ITreasuryHandler public treasuryHandler;
/// @notice Emitted when the tax handler contract is changed.eventTaxHandlerChanged(address oldAddress, address newAddress);
/// @notice Emitted when the treasury handler contract is changed.eventTreasuryHandlerChanged(address oldAddress, address newAddress);
/// @dev Name of the token.stringprivate _name;
/// @dev Symbol of the token.stringprivate _symbol;
/**
* @param name_ Name of the token.
* @param symbol_ Symbol of the token.
* @param taxHandlerAddress Initial tax handler contract.
* @param treasuryHandlerAddress Initial treasury handler contract.
*/constructor(stringmemory name_,
stringmemory symbol_,
address taxHandlerAddress,
address treasuryHandlerAddress
) {
_name = name_;
_symbol = symbol_;
taxHandler = ITaxHandler(taxHandlerAddress);
treasuryHandler = ITreasuryHandler(treasuryHandlerAddress);
_balances[_msgSender()] = totalSupply();
emit Transfer(address(0), _msgSender(), totalSupply());
}
/**
* @notice Get token name.
* @return Name of the token.
*/functionname() publicviewreturns (stringmemory) {
return _name;
}
/**
* @notice Get token symbol.
* @return Symbol of the token.
*/functionsymbol() externalviewreturns (stringmemory) {
return _symbol;
}
/**
* @notice Get number of decimals used by the token.
* @return Number of decimals used by the token.
*/functiondecimals() externalpurereturns (uint8) {
return9;
}
/**
* @notice Get the maximum number of tokens.
* @return The maximum number of tokens that will ever be in existence.
*/functiontotalSupply() publicpureoverridereturns (uint256) {
// Five billion, i.e., 5,000,000,000 tokens.return5e9*1e9;
}
/**
* @notice Get token balance of given account.
* @param account Address to retrieve balance for.
* @return The number of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewoverridereturns (uint256) {
return _balances[account];
}
/**
* @notice Transfer tokens from caller's address to another.
* @param recipient Address to send the caller's tokens to.
* @param amount The number of tokens to transfer to recipient.
* @return True if transfer succeeds, else an error is raised.
*/functiontransfer(address recipient, uint256 amount) externaloverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @notice Get the allowance `owner` has given `spender`.
* @param owner The address on behalf of whom tokens can be spent by `spender`.
* @param spender The address authorized to spend tokens on behalf of `owner`.
* @return The allowance `owner` has given `spender`.
*/functionallowance(address owner, address spender) externalviewoverridereturns (uint256) {
return _allowances[owner][spender];
}
/**
* @notice Approve address to spend caller's tokens.
* @dev This method can be exploited by malicious spenders if their allowance is already non-zero. See the following
* document for details: https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/edit.
* Ensure the spender can be trusted before calling this method if they've already been approved before. Otherwise
* use either the `increaseAllowance`/`decreaseAllowance` functions, or first set their allowance to zero, before
* setting a new allowance.
* @param spender Address to authorize for token expenditure.
* @param amount The number of tokens `spender` is allowed to spend.
* @return True if the approval succeeds, else an error is raised.
*/functionapprove(address spender, uint256 amount) externaloverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @notice Transfer tokens from one address to another.
* @param sender Address to move tokens from.
* @param recipient Address to send the caller's tokens to.
* @param amount The number of tokens to transfer to recipient.
* @return True if the transfer succeeds, else an error is raised.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) externaloverridereturns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(
currentAllowance >= amount,
"FLOKI:transferFrom:ALLOWANCE_EXCEEDED: Transfer amount exceeds allowance."
);
unchecked {
_approve(sender, _msgSender(), currentAllowance - amount);
}
returntrue;
}
/**
* @notice Increase spender's allowance.
* @param spender Address of user authorized to spend caller's tokens.
* @param addedValue The number of tokens to add to `spender`'s allowance.
* @return True if the allowance is successfully increased, else an error is raised.
*/functionincreaseAllowance(address spender, uint256 addedValue) externalreturns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
returntrue;
}
/**
* @notice Decrease spender's allowance.
* @param spender Address of user authorized to spend caller's tokens.
* @param subtractedValue The number of tokens to remove from `spender`'s allowance.
* @return True if the allowance is successfully decreased, else an error is raised.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) externalreturns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(
currentAllowance >= subtractedValue,
"FLOKI:decreaseAllowance:ALLOWANCE_UNDERFLOW: Subtraction results in sub-zero allowance."
);
unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
}
returntrue;
}
/**
* @notice Delegate votes to given address.
* @dev It should be noted that users that want to vote themselves, also need to call this method, albeit with their
* own address.
* @param delegatee Address to delegate votes to.
*/functiondelegate(address delegatee) external{
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegate votes from signatory to `delegatee`.
* @param delegatee The address to delegate votes to.
* @param nonce The contract state required to match the signature.
* @param expiry The time at which to expire the signature.
* @param v The recovery byte of the signature.
* @param r Half of the ECDSA signature pair.
* @param s Half of the ECDSA signature pair.
*/functiondelegateBySig(address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external{
bytes32 domainSeparator =keccak256(
abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), block.chainid, address(this))
);
bytes32 structHash =keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));
bytes32 digest =keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
address signatory =ecrecover(digest, v, r, s);
require(signatory !=address(0), "FLOKI:delegateBySig:INVALID_SIGNATURE: Received signature was invalid.");
require(block.timestamp<= expiry, "FLOKI:delegateBySig:EXPIRED_SIGNATURE: Received signature has expired.");
require(nonce == nonces[signatory]++, "FLOKI:delegateBySig:INVALID_NONCE: Received nonce was invalid.");
return _delegate(signatory, delegatee);
}
/**
* @notice Determine the number of votes for an account as of a block number.
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check.
* @param blockNumber The block number to get the vote balance at.
* @return The number of votes the account had as of the given block.
*/functiongetVotesAtBlock(address account, uint32 blockNumber) publicviewreturns (uint224) {
require(
blockNumber <block.number,
"FLOKI:getVotesAtBlock:FUTURE_BLOCK: Cannot get votes at a block in the future."
);
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints ==0) {
return0;
}
// First check most recent balance.if (checkpoints[account][nCheckpoints -1].blockNumber <= blockNumber) {
return checkpoints[account][nCheckpoints -1].votes;
}
// Next check implicit zero balance.if (checkpoints[account][0].blockNumber > blockNumber) {
return0;
}
// Perform binary search.uint32 lowerBound =0;
uint32 upperBound = nCheckpoints -1;
while (upperBound > lowerBound) {
uint32 center = upperBound - (upperBound - lowerBound) /2;
Checkpoint memory checkpoint = checkpoints[account][center];
if (checkpoint.blockNumber == blockNumber) {
return checkpoint.votes;
} elseif (checkpoint.blockNumber < blockNumber) {
lowerBound = center;
} else {
upperBound = center -1;
}
}
// No exact block found. Use last known balance before that block number.return checkpoints[account][lowerBound].votes;
}
/**
* @notice Set new tax handler contract.
* @param taxHandlerAddress Address of new tax handler contract.
*/functionsetTaxHandler(address taxHandlerAddress) externalonlyOwner{
address oldTaxHandlerAddress =address(taxHandler);
taxHandler = ITaxHandler(taxHandlerAddress);
emit TaxHandlerChanged(oldTaxHandlerAddress, taxHandlerAddress);
}
/**
* @notice Set new treasury handler contract.
* @param treasuryHandlerAddress Address of new treasury handler contract.
*/functionsetTreasuryHandler(address treasuryHandlerAddress) externalonlyOwner{
address oldTreasuryHandlerAddress =address(treasuryHandler);
treasuryHandler = ITreasuryHandler(treasuryHandlerAddress);
emit TreasuryHandlerChanged(oldTreasuryHandlerAddress, treasuryHandlerAddress);
}
/**
* @notice Send any tokens or ETH stuck in the token contract to the treasury handler.
* @param tokenAddress Address of the token to withdraw. If set to the zero address, ETH will be withdrawn.
* @param amount The number of tokens to withdraw.
* @dev The treasury handler has a method to send any tokens to the treasury (except for what it uses to swap).
*/functionwithdraw(address tokenAddress, uint256 amount) externalonlyOwner{
if (tokenAddress ==address(0)) {
payable(address(treasuryHandler)).sendValue(amount);
} else {
IERC20(tokenAddress).transferFrom(address(this), address(treasuryHandler), amount);
}
}
/**
* @notice Delegate votes from one address to another.
* @param delegator Address from which to delegate votes for.
* @param delegatee Address to delegate votes to.
*/function_delegate(address delegator, address delegatee) private{
address currentDelegate = delegates[delegator];
uint256 delegatorBalance = _balances[delegator];
delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, uint224(delegatorBalance));
}
/**
* @notice Move delegates from one address to another.
* @param from Representative to move delegates from.
* @param to Representative to move delegates to.
* @param amount Number of delegates to move.
*/function_moveDelegates(addressfrom,
address to,
uint224 amount
) private{
// No need to update checkpoints if the votes don't actually move between different delegates. This can be the// case where tokens are transferred between two parties that have delegated their votes to the same address.if (from== to) {
return;
}
// Some users preemptively delegate their votes (i.e. before they have any tokens). No need to perform an update// to the checkpoints in that case.if (amount ==0) {
return;
}
if (from!=address(0)) {
uint32 fromRepNum = numCheckpoints[from];
uint224 fromRepOld = fromRepNum >0 ? checkpoints[from][fromRepNum -1].votes : 0;
uint224 fromRepNew = fromRepOld - amount;
_writeCheckpoint(from, fromRepNum, fromRepOld, fromRepNew);
}
if (to !=address(0)) {
uint32 toRepNum = numCheckpoints[to];
uint224 toRepOld = toRepNum >0 ? checkpoints[to][toRepNum -1].votes : 0;
uint224 toRepNew = toRepOld + amount;
_writeCheckpoint(to, toRepNum, toRepOld, toRepNew);
}
}
/**
* @notice Write balance checkpoint to chain.
* @param delegatee The address to write the checkpoint for.
* @param nCheckpoints The number of checkpoints `delegatee` already has.
* @param oldVotes Number of votes prior to this checkpoint.
* @param newVotes Number of votes `delegatee` now has.
*/function_writeCheckpoint(address delegatee,
uint32 nCheckpoints,
uint224 oldVotes,
uint224 newVotes
) private{
uint32 blockNumber =uint32(block.number);
if (nCheckpoints >0&& checkpoints[delegatee][nCheckpoints -1].blockNumber == blockNumber) {
checkpoints[delegatee][nCheckpoints -1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints +1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
/**
* @notice Approve spender on behalf of owner.
* @param owner Address on behalf of whom tokens can be spent by `spender`.
* @param spender Address to authorize for token expenditure.
* @param amount The number of tokens `spender` is allowed to spend.
*/function_approve(address owner,
address spender,
uint256 amount
) private{
require(owner !=address(0), "FLOKI:_approve:OWNER_ZERO: Cannot approve for the zero address.");
require(spender !=address(0), "FLOKI:_approve:SPENDER_ZERO: Cannot approve to the zero address.");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @notice Transfer `amount` tokens from account `from` to account `to`.
* @param from Address the tokens are moved out of.
* @param to Address the tokens are moved to.
* @param amount The number of tokens to transfer.
*/function_transfer(addressfrom,
address to,
uint256 amount
) private{
require(from!=address(0), "FLOKI:_transfer:FROM_ZERO: Cannot transfer from the zero address.");
require(to !=address(0), "FLOKI:_transfer:TO_ZERO: Cannot transfer to the zero address.");
require(amount >0, "FLOKI:_transfer:ZERO_AMOUNT: Transfer amount must be greater than zero.");
require(amount <= _balances[from], "FLOKI:_transfer:INSUFFICIENT_BALANCE: Transfer amount exceeds balance.");
treasuryHandler.beforeTransferHandler(from, to, amount);
uint256 tax = taxHandler.getTax(from, to, amount);
uint256 taxedAmount = amount - tax;
_balances[from] -= amount;
_balances[to] += taxedAmount;
_moveDelegates(delegates[from], delegates[to], uint224(taxedAmount));
if (tax >0) {
_balances[address(treasuryHandler)] += tax;
_moveDelegates(delegates[from], delegates[address(treasuryHandler)], uint224(tax));
emit Transfer(from, address(treasuryHandler), tax);
}
treasuryHandler.afterTransferHandler(from, to, amount);
emit Transfer(from, to, taxedAmount);
}
}