Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- CommissionTree
- Optimization enabled
- false
- Compiler version
- v0.8.20+commit.a1b79de6
- EVM Version
- Verified at
- 2026-11-21T17:11:33.121082Z
Constructor Arguments
000000000000000000000000e84a941fe9da6eb049aed191e3d780f5e7b8f3ab000000000000000000000000726f6d4ed3b7842ba27e54ed7f198269bc0b2558000000000000000000000000038db84e18f7e1821fe090d8c3113b67f8b803f1000000000000000000000000038db84e18f7e1821fe090d8c3113b67f8b803f1
Arg [0] (address) : 0xe84a941fe9da6eb049aed191e3d780f5e7b8f3ab
Arg [1] (address) : 0x726f6d4ed3b7842ba27e54ed7f198269bc0b2558
Arg [2] (address) : 0x038db84e18f7e1821fe090d8c3113b67f8b803f1
Arg [3] (address) : 0x038db84e18f7e1821fe090d8c3113b67f8b803f1
contracts/core/CommissionTree.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IBBACoin} from "../interfaces/IBBACoin.sol";
/// @title CommissionTree
/// @notice The affiliate engine for the Blockbids ecosystem. Holds the upline
/// graph and pays sponsors three levels deep on two separate streams:
///
/// Stream A - auctions: the web2 engine hands over the 8.5% slice of
/// gross auction revenue in BID, and it is split 10/5/2 (in 17ths) up
/// the winner's chain.
///
/// Stream B - staking: YieldVault reports each stake and freshly
/// minted BBA goes up the chain at 10% / 5% / 2% of the staked amount.
///
/// Any level with no sponsor falls through to the company rotator,
/// so no commission is ever stranded.
/// @dev Needs MINTER_ROLE on BBACoin for Stream B, and the engine must approve
/// this contract for the BID budget before calling Stream A.
contract CommissionTree is AccessControl, ReentrancyGuard {
using SafeERC20 for IERC20;
// --- Roles ---
bytes32 public constant VAULT_ROLE = keccak256("VAULT_ROLE"); // YieldVault
bytes32 public constant ENGINE_ROLE = keccak256("ENGINE_ROLE"); // web2 relayer
// --- Tokens ---
IERC20 public bidToken; // paid out on auctions, pulled from the engine
IBBACoin public bbaToken; // minted on stakes
// --- Rotator ---
// Two company wallets taking turns as the sponsor for orphan signups, and
// as the catch-all for any commission level with no upline.
address[2] public companyWallets;
uint8 public rotatorIndex;
// --- Affiliate tree ---
// Permanent once set. A sponsor must already be registered before anyone
// can name them, and nobody can be registered twice, so the graph is
// append-only and cycles are impossible by construction.
mapping(address => address) public sponsor;
mapping(address => bool) public isRegistered;
// --- Payout constants ---
// Hardcoded depth. Bounded traversal is the whole point: an MLM tree can be
// thousands deep, and an unbounded walk would eventually run out of gas and
// brick every auction settlement.
uint8 private constant MAX_LEVELS = 3;
// Auction split in 17ths (10 + 5 + 2), which is exactly the 58.82 / 29.41 /
// 11.77 spread with no denominator games.
uint256 private constant AUCTION_L1_PARTS = 10;
uint256 private constant AUCTION_L2_PARTS = 5;
uint256 private constant AUCTION_TOTAL_PARTS = 17;
// Staking mint rates, straight percentages of the staked amount.
uint256 private constant STAKING_L1_PCT = 10;
uint256 private constant STAKING_L2_PCT = 5;
uint256 private constant STAKING_L3_PCT = 2;
uint256 private constant PCT_DENOMINATOR = 100;
// --- Events ---
event UserRegistered(address indexed user, address indexed sponsor, bool viaRotator);
event RotatorAdvanced(uint8 newIndex);
event AuctionCommissionPaid(
address indexed winner,
address indexed recipient,
uint8 level,
uint256 amount,
bool viaRotator
);
event StakingCommissionMinted(
address indexed staker,
address indexed recipient,
uint8 level,
uint256 amount,
bool viaRotator
);
event CompanyWalletUpdated(uint8 indexed index, address indexed previous, address indexed current);
event BidTokenUpdated(address indexed previous, address indexed current);
event BbaTokenUpdated(address indexed previous, address indexed current);
event ERC20Rescued(address indexed token, address indexed to, uint256 amount);
constructor(
address _bidToken,
address _bbaToken,
address _companyWalletA,
address _companyWalletB
) {
require(_bidToken != address(0), "Tree: bid is zero");
require(_bbaToken != address(0), "Tree: bba is zero");
require(_companyWalletA != address(0), "Tree: wallet A is zero");
require(_companyWalletB != address(0), "Tree: wallet B is zero");
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
bidToken = IERC20(_bidToken);
bbaToken = IBBACoin(_bbaToken);
companyWallets[0] = _companyWalletA;
companyWallets[1] = _companyWalletB;
// The company wallets seed the tree. Without this nobody could name one
// as their upline, since registerUser only accepts registered sponsors.
isRegistered[_companyWalletA] = true;
isRegistered[_companyWalletB] = true;
}
// ============================================================
// REGISTRATION & ROTATOR
// ============================================================
/// @notice Bind `user` to `upline`, or to the next company wallet if the
/// upline is unusable.
/// @dev ENGINE_ROLE only. The signature takes `user` rather than using
/// msg.sender, so leaving it open would let anyone front-run a signup
/// with registerUser(victim, attacker) and permanently own that
/// wallet's commissions - the binding can never be undone.
function registerUser(address user, address upline) external onlyRole(ENGINE_ROLE) {
require(user != address(0), "Tree: user is zero");
require(!isRegistered[user], "Tree: already registered");
// A referrer only counts if they are in the tree and are not the user
// themselves; anything else (zero, unknown, self) is an orphan.
bool validUpline = upline != address(0) && upline != user && isRegistered[upline];
address assigned;
if (validUpline) {
assigned = upline;
} else {
assigned = companyWallets[rotatorIndex];
rotatorIndex = (rotatorIndex + 1) % 2;
emit RotatorAdvanced(rotatorIndex);
}
sponsor[user] = assigned;
isRegistered[user] = true;
emit UserRegistered(user, assigned, !validUpline);
}
// ============================================================
// STREAM A - AUCTION COMMISSIONS (BID)
// ============================================================
/// @notice Pay the winner's upline out of `totalCommissionBudget` BID.
/// @param winner the bidder whose chain gets paid
/// @param totalCommissionBudget the exact 8.5% slice of gross auction
/// revenue, already computed off-chain
/// @dev The caller must approve this contract for the budget first. Pulling
/// before paying means we can only ever hand out BID we actually hold.
function distributeAuctionCommissions(address winner, uint256 totalCommissionBudget)
external
onlyRole(ENGINE_ROLE)
nonReentrant
{
require(winner != address(0), "Tree: winner is zero");
require(totalCommissionBudget > 0, "Tree: budget is zero");
bidToken.safeTransferFrom(msg.sender, address(this), totalCommissionBudget);
uint256[MAX_LEVELS] memory shares;
shares[0] = (totalCommissionBudget * AUCTION_L1_PARTS) / AUCTION_TOTAL_PARTS;
shares[1] = (totalCommissionBudget * AUCTION_L2_PARTS) / AUCTION_TOTAL_PARTS;
// Remainder rather than *2/17, so the three shares always re-add to the
// budget exactly and integer truncation can never leave dust stuck here.
shares[2] = totalCommissionBudget - shares[0] - shares[1];
address fallbackWallet = companyWallets[rotatorIndex];
address current = sponsor[winner];
for (uint8 i = 0; i < MAX_LEVELS; i++) {
bool viaRotator = current == address(0);
address recipient = viaRotator ? fallbackWallet : current;
if (shares[i] > 0) {
bidToken.safeTransfer(recipient, shares[i]);
emit AuctionCommissionPaid(winner, recipient, i + 1, shares[i], viaRotator);
}
// Once the chain runs out every remaining level is an orphan too.
if (!viaRotator) {
current = sponsor[current];
}
}
}
// ============================================================
// STREAM B - STAKING COMMISSIONS (BBA)
// ============================================================
/// @notice Mint sponsor commissions on a fresh stake.
/// @dev VAULT_ROLE only. Nothing is pulled in - this is new BBA supply
/// minted on top of the stake, 17% of it in total, clamped to what's
/// left under BBA's cap so staking keeps working once emissions end.
function distributeStakingCommissions(address staker, uint256 stakedAmount)
external
onlyRole(VAULT_ROLE)
nonReentrant
{
require(staker != address(0), "Tree: staker is zero");
require(stakedAmount > 0, "Tree: amount is zero");
uint256[MAX_LEVELS] memory shares;
shares[0] = (stakedAmount * STAKING_L1_PCT) / PCT_DENOMINATOR;
shares[1] = (stakedAmount * STAKING_L2_PCT) / PCT_DENOMINATOR;
shares[2] = (stakedAmount * STAKING_L3_PCT) / PCT_DENOMINATOR;
address fallbackWallet = companyWallets[rotatorIndex];
address current = sponsor[staker];
uint256 remaining = bbaToken.mintableRemaining();
for (uint8 i = 0; i < MAX_LEVELS; i++) {
bool viaRotator = current == address(0);
address recipient = viaRotator ? fallbackWallet : current;
if (shares[i] > remaining) {
shares[i] = remaining;
}
if (shares[i] > 0) {
remaining -= shares[i];
bbaToken.mint(recipient, shares[i]);
emit StakingCommissionMinted(staker, recipient, i + 1, shares[i], viaRotator);
}
if (!viaRotator) {
current = sponsor[current];
}
}
}
// ============================================================
// ADMIN
// ============================================================
/// @notice Swap one of the two rotator wallets.
function setCompanyWallet(uint8 index, address wallet)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
require(index < 2, "Tree: bad index");
require(wallet != address(0), "Tree: wallet is zero");
emit CompanyWalletUpdated(index, companyWallets[index], wallet);
companyWallets[index] = wallet;
// Keep it namable as an upline, same as the ones set at construction.
isRegistered[wallet] = true;
}
function setBidToken(address _bidToken) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(_bidToken != address(0), "Tree: bid is zero");
emit BidTokenUpdated(address(bidToken), _bidToken);
bidToken = IERC20(_bidToken);
}
function setBbaToken(address _bbaToken) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(_bbaToken != address(0), "Tree: bba is zero");
emit BbaTokenUpdated(address(bbaToken), _bbaToken);
bbaToken = IBBACoin(_bbaToken);
}
/// @notice Recover tokens sent here by mistake.
/// @dev No surplus guard needed the way YieldVault has one - this contract
/// never holds a balance between transactions, since every BID it
/// pulls is paid straight back out in the same call.
function rescueERC20(address token, address to, uint256 amount)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
require(to != address(0), "Tree: to is zero");
IERC20(token).safeTransfer(to, amount);
emit ERC20Rescued(token, to, amount);
}
}
@openzeppelin/contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";
@openzeppelin/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 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);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
@openzeppelin/contracts/interfaces/draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (interfaces/draft-IERC6093.sol)
pragma solidity >=0.8.4;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-721.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 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);
}
@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
if (!_safeTransfer(token, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
if (!_safeTransferFrom(token, from, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _safeTransfer(token, to, value, false);
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _safeTransferFrom(token, from, to, value, false);
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
if (!_safeApprove(token, spender, value, false)) {
if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity `token.transfer(to, value)` call, 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 to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.transfer.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(to, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
/**
* @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, 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 from The sender of the tokens
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value,
bool bubble
) private returns (bool success) {
bytes4 selector = IERC20.transferFrom.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(from, shr(96, not(0))))
mstore(0x24, and(to, shr(96, not(0))))
mstore(0x44, value)
success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
mstore(0x60, 0)
}
}
/**
* @dev Imitates a Solidity `token.approve(spender, value)` call, 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 spender The spender of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.approve.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(spender, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
}
@openzeppelin/contracts/utils/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
/**
* @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 EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* 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].
*
* IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced
* by the {ReentrancyGuardTransient} variant in v6.0.
*
* @custom:stateless
*/
abstract contract ReentrancyGuard {
using StorageSlot for bytes32;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
// 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;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_reentrancyGuardStorageSlot().getUint256Slot().value = 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();
}
/**
* @dev A `view` only version of {nonReentrant}. Use to block view functions
* from being called, preventing reading from inconsistent contract state.
*
* CAUTION: This is a "view" modifier and does not change the reentrancy
* status. Use it only on view functions. For payable or non-payable functions,
* use the standard {nonReentrant} modifier instead.
*/
modifier nonReentrantView() {
_nonReentrantBeforeView();
_;
}
function _nonReentrantBeforeView() private view {
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
_nonReentrantBeforeView();
// Any calls to nonReentrant after this point will fail
_reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;
}
function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
return REENTRANCY_GUARD_STORAGE;
}
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* 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[ERC 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);
}
@openzeppelin/contracts/utils/StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}
contracts/core/QuarterlyBurner.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {IBBACoin} from "../interfaces/IBBACoin.sol";
/// @title QuarterlyBurner
/// @notice Lightweight autonomous timelock: once every 90 days, anyone can
/// call `executeBurn` to burn exactly 3.69% of BBA's current
/// circulating supply out of the treasury. The contract enforces its
/// own cadence on-chain, so no off-chain scheduler or admin trigger
/// is required.
/// @dev Needs `BURNER_ROLE` on BBACoin, and the treasury must keep BBACoin
/// approved for at least the next burn amount - see BBACoin.burnSupply's
/// two-key (role + allowance) gating. If the treasury is under-approved
/// or under-funded when a quarter rolls over, `executeBurn` simply
/// reverts and can be retried once the treasury is topped up; the 90-day
/// clock does not advance on a revert.
contract QuarterlyBurner is AccessControl {
// --- State ---
IBBACoin public bbaToken;
uint256 public constant BURN_INTERVAL = 90 days;
uint256 public constant BURN_RATE_BPS = 369; // 3.69%
uint256 private constant BPS_DENOMINATOR = 10000;
// 0 at deployment, so the first burn is available immediately; every
// burn after that is locked out until BURN_INTERVAL has elapsed.
uint256 public lastBurnTimestamp;
// --- Events ---
event BbaTokenUpdated(address indexed previous, address indexed current);
event QuarterlyBurnExecuted(
uint256 indexed timestamp,
uint256 circulatingSupply,
uint256 amountBurned
);
constructor(address _bbaToken) {
require(_bbaToken != address(0), "Burner: token is zero");
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
bbaToken = IBBACoin(_bbaToken);
}
// --- Execution ---
/// @notice Burn 3.69% of BBA's current circulating supply. Permissionless,
/// but only once every 90 days.
function executeBurn() external {
require(
block.timestamp >= lastBurnTimestamp + BURN_INTERVAL,
"Burner: too soon"
);
// Effects before the external call, so the window can't be re-entered.
lastBurnTimestamp = block.timestamp;
uint256 circulatingSupply = bbaToken.totalSupply();
uint256 burnAmount = (circulatingSupply * BURN_RATE_BPS) / BPS_DENOMINATOR;
require(burnAmount > 0, "Burner: nothing to burn");
bbaToken.burnSupply(burnAmount);
emit QuarterlyBurnExecuted(block.timestamp, circulatingSupply, burnAmount);
}
// --- Views ---
/// @notice Timestamp at which the next `executeBurn` call will succeed.
function nextBurnAvailableAt() external view returns (uint256) {
return lastBurnTimestamp + BURN_INTERVAL;
}
// --- Admin ---
function setBbaToken(address _bbaToken) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(_bbaToken != address(0), "Burner: token is zero");
emit BbaTokenUpdated(address(bbaToken), _bbaToken);
bbaToken = IBBACoin(_bbaToken);
}
}
contracts/mocks/MockERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MockERC20 is ERC20 {
uint8 private dec;
// stands in for BBACoin's lifetime cap in tests that need one
uint256 public mintCap = type(uint256).max;
constructor(
string memory name,
string memory symbol,
uint8 _decimals
) ERC20(name, symbol) {
dec = _decimals;
}
function mint(address to, uint256 amount) external {
require(totalSupply() + amount <= mintCap, "Mock: cap exceeded");
_mint(to, amount);
}
function setMintCap(uint256 cap) external {
mintCap = cap;
}
function mintableRemaining() external view returns (uint256) {
return mintCap - totalSupply();
}
function decimals() public view override returns (uint8) {
return dec;
}
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 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);
}
@openzeppelin/contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";
@openzeppelin/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* Both values are immutable: they can only be set once during construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/// @inheritdoc IERC20
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/// @inheritdoc IERC20
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/// @inheritdoc IERC20
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation sets the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the `transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner`'s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
@openzeppelin/contracts/access/AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.6.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../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:
*
* ```solidity
* 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}:
*
* ```solidity
* 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. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/// @inheritdoc ERC165
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 returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @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 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 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 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 `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @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 Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
contracts/interfaces/IBBACoin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title IBBACoin
/// @notice Minimal interface the rest of the ecosystem needs against BBACoin:
/// BidToken mints BBA rewards, QuarterlyBurner reads supply and burns
/// it out of the treasury.
interface IBBACoin is IERC20 {
function mint(address to, uint256 amount) external;
function mintableRemaining() external view returns (uint256);
function burnSupply(uint256 amount) external;
}
@openzeppelin/contracts/access/IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/IAccessControl.sol)
pragma solidity >=0.8.4;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @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 to signal this.
*/
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. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
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 `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
@openzeppelin/contracts/interfaces/IERC1363.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
contracts/core/BidToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {IBBACoin} from "../interfaces/IBBACoin.sol";
/// @title BidToken
/// @notice Blockbids' $1-pegged auction token (BID). Spending BID routes the
/// revenue to the treasury, mints BBA to the bidder, and flips the
/// wallet's staking flag on — the "Value Loop".
contract BidToken is ERC20, AccessControl, ReentrancyGuard {
// --- Roles ---
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); // fiat/web2 bridge
// --- State ---
address public bbaTokenAddress; // the BBACoin contract we mint rewards on
address public auctionTreasury; // where spent BID lands (recycled revenue)
uint256 public bbaMintRate; // BBA minted per 1 BID spent, scaled by 1e18
uint256 public minActivationAmount = 1e18; // smallest single deposit that unlocks staking
// "your bids activate staking and farming" — set once a wallet deposits bids
mapping(address => bool) private _isStakingActivated;
// --- Events ---
event BidDeposited(address indexed user, uint256 amount, uint256 bbaRewarded);
event BbaTokenAddressUpdated(address indexed previous, address indexed current);
event AuctionTreasuryUpdated(address indexed previous, address indexed current);
event BbaMintRateUpdated(uint256 newRate);
event MinActivationAmountUpdated(uint256 newAmount);
constructor(
address _bbaTokenAddress,
address _auctionTreasury,
uint256 _bbaMintRate
) ERC20("Blockbids", "BID") {
require(_bbaTokenAddress != address(0), "BID: bba is zero");
require(_auctionTreasury != address(0), "BID: treasury is zero");
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
bbaTokenAddress = _bbaTokenAddress;
auctionTreasury = _auctionTreasury;
bbaMintRate = _bbaMintRate;
}
// --- Value Loop ---
/// @notice Spend BID: route it to the treasury, mint BBA back, and unlock
/// staking if the deposit is at least minActivationAmount.
/// @dev User must hold `bidAmount` BID. No approval needed — these are the
/// caller's own tokens, so we move them with the internal _transfer
/// instead of the spec's transferFrom (which would require a pointless
/// self-approval and, called internally, reverts on a zero self-allowance).
function depositBids(uint256 bidAmount) external nonReentrant {
require(bidAmount > 0, "BID: amount is zero");
// revenue routing (recycling): user -> treasury
_transfer(msg.sender, auctionTreasury, bidAmount);
uint256 bbaReward = (bidAmount * bbaMintRate) / (10 ** decimals());
// past BBA's cap the reward shrinks to what's left, so bids still settle
uint256 remaining = IBBACoin(bbaTokenAddress).mintableRemaining();
if (bbaReward > remaining) {
bbaReward = remaining;
}
// effects before the external call (CEI); nonReentrant guards it too
if (bidAmount >= minActivationAmount) {
_isStakingActivated[msg.sender] = true;
}
if (bbaReward > 0) {
IBBACoin(bbaTokenAddress).mint(msg.sender, bbaReward);
}
emit BidDeposited(msg.sender, bidAmount, bbaReward);
}
// --- Fiat gateway ---
/// @notice Mint BID to a buyer once their fiat/USDC payment clears off-chain.
function mintBid(address to, uint256 amount) external onlyRole(MINTER_ROLE) {
_mint(to, amount);
}
// --- Reads ---
/// @notice Master key for YieldVault: has this wallet ever deposited bids?
function checkStakingStatus(address user) external view returns (bool) {
return _isStakingActivated[user];
}
// --- Admin ---
function setBbaMintRate(uint256 _newRate)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
bbaMintRate = _newRate;
emit BbaMintRateUpdated(_newRate);
}
function setMinActivationAmount(uint256 _amount)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
require(_amount > 0, "BID: amount is zero");
minActivationAmount = _amount;
emit MinActivationAmountUpdated(_amount);
}
function setAuctionTreasury(address _newTreasury)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
require(_newTreasury != address(0), "BID: treasury is zero");
emit AuctionTreasuryUpdated(auctionTreasury, _newTreasury);
auctionTreasury = _newTreasury;
}
function setBbaTokenAddress(address _bbaAddress)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
require(_bbaAddress != address(0), "BID: bba is zero");
emit BbaTokenAddressUpdated(bbaTokenAddress, _bbaAddress);
bbaTokenAddress = _bbaAddress;
}
}
Compiler Settings
{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata"],"":["ast"]}},"optimizer":{"runs":200,"enabled":true},"evmVersion":"paris"}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_bidToken","internalType":"address"},{"type":"address","name":"_bbaToken","internalType":"address"},{"type":"address","name":"_companyWalletA","internalType":"address"},{"type":"address","name":"_companyWalletB","internalType":"address"}]},{"type":"error","name":"AccessControlBadConfirmation","inputs":[]},{"type":"error","name":"AccessControlUnauthorizedAccount","inputs":[{"type":"address","name":"account","internalType":"address"},{"type":"bytes32","name":"neededRole","internalType":"bytes32"}]},{"type":"error","name":"ReentrancyGuardReentrantCall","inputs":[]},{"type":"error","name":"SafeERC20FailedOperation","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"event","name":"AuctionCommissionPaid","inputs":[{"type":"address","name":"winner","internalType":"address","indexed":true},{"type":"address","name":"recipient","internalType":"address","indexed":true},{"type":"uint8","name":"level","internalType":"uint8","indexed":false},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"bool","name":"viaRotator","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"BbaTokenUpdated","inputs":[{"type":"address","name":"previous","internalType":"address","indexed":true},{"type":"address","name":"current","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"BidTokenUpdated","inputs":[{"type":"address","name":"previous","internalType":"address","indexed":true},{"type":"address","name":"current","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"CompanyWalletUpdated","inputs":[{"type":"uint8","name":"index","internalType":"uint8","indexed":true},{"type":"address","name":"previous","internalType":"address","indexed":true},{"type":"address","name":"current","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"ERC20Rescued","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RotatorAdvanced","inputs":[{"type":"uint8","name":"newIndex","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"StakingCommissionMinted","inputs":[{"type":"address","name":"staker","internalType":"address","indexed":true},{"type":"address","name":"recipient","internalType":"address","indexed":true},{"type":"uint8","name":"level","internalType":"uint8","indexed":false},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"bool","name":"viaRotator","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"UserRegistered","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"address","name":"sponsor","internalType":"address","indexed":true},{"type":"bool","name":"viaRotator","internalType":"bool","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"ENGINE_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"VAULT_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IBBACoin"}],"name":"bbaToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC20"}],"name":"bidToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"companyWallets","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"distributeAuctionCommissions","inputs":[{"type":"address","name":"winner","internalType":"address"},{"type":"uint256","name":"totalCommissionBudget","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"distributeStakingCommissions","inputs":[{"type":"address","name":"staker","internalType":"address"},{"type":"uint256","name":"stakedAmount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isRegistered","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"registerUser","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"address","name":"upline","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"callerConfirmation","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"rescueERC20","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"rotatorIndex","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setBbaToken","inputs":[{"type":"address","name":"_bbaToken","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setBidToken","inputs":[{"type":"address","name":"_bidToken","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCompanyWallet","inputs":[{"type":"uint8","name":"index","internalType":"uint8"},{"type":"address","name":"wallet","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"sponsor","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]}]
Contract Creation Code
0x60806040523480156200001157600080fd5b50604051620019e7380380620019e78339810160408190526200003491620002fa565b60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00556001600160a01b038416620000a85760405162461bcd60e51b8152602060048201526011602482015270547265653a20626964206973207a65726f60781b60448201526064015b60405180910390fd5b6001600160a01b038316620000f45760405162461bcd60e51b8152602060048201526011602482015270547265653a20626261206973207a65726f60781b60448201526064016200009f565b6001600160a01b0382166200014c5760405162461bcd60e51b815260206004820152601660248201527f547265653a2077616c6c65742041206973207a65726f0000000000000000000060448201526064016200009f565b6001600160a01b038116620001a45760405162461bcd60e51b815260206004820152601660248201527f547265653a2077616c6c65742042206973207a65726f0000000000000000000060448201526064016200009f565b620001b16000336200022e565b50600180546001600160a01b03199081166001600160a01b039687161782556002805482169587169590951790945560038054938616938516841790556004805492909516919093168117909355600090815260076020526040808220805460ff1990811685179091559382529020805490921617905562000357565b6000828152602081815260408083206001600160a01b038516845290915281205460ff16620002d3576000838152602081815260408083206001600160a01b03861684529091529020805460ff191660011790556200028a3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4506001620002d7565b5060005b92915050565b80516001600160a01b0381168114620002f557600080fd5b919050565b600080600080608085870312156200031157600080fd5b6200031c85620002dd565b93506200032c60208601620002dd565b92506200033c60408601620002dd565b91506200034c60608601620002dd565b905092959194509250565b61168080620003676000396000f3fe608060405234801561001057600080fd5b50600436106101425760003560e01c806398c4f1ac116100b8578063c3c5a5471161007c578063c3c5a54714610303578063d547741f14610326578063dfafd4fd14610339578063e1d353781461034c578063ebc8a2621461035f578063fbe93b781461037257600080fd5b806398c4f1ac1461029b578063a217fddf146102c2578063a22a5bc2146102ca578063a6683c65146102dd578063b2118a8d146102f057600080fd5b806336568abe1161010a57806336568abe146101ef578063501ee12614610202578063766c4f37146102155780637f06572214610256578063885fc6561461027557806391d148541461028857600080fd5b806301ffc9a7146101475780630354adb21461016f5780631084b34314610184578063248a9ca3146101b95780632f2ff15d146101dc575b600080fd5b61015a6101553660046113d6565b610385565b60405190151581526020015b60405180910390f35b61018261017d366004611423565b6103bc565b005b6101ab7f5d0c23b505d97686a7eb149c2db3c9cdda71d0f1778515d411985ce042bf17a181565b604051908152602001610166565b6101ab6101c7366004611456565b60009081526020819052604090206001015490565b6101826101ea36600461146f565b610608565b6101826101fd36600461146f565b610633565b610182610210366004611492565b61066b565b61023e610223366004611492565b6006602052600090815260409020546001600160a01b031681565b6040516001600160a01b039091168152602001610166565b6005546102639060ff1681565b60405160ff9091168152602001610166565b61023e610283366004611456565b61071d565b61015a61029636600461146f565b61073d565b6101ab7f31e0210044b4f6757ce6aa31f9c6e8d4896d24a755014887391a926c5224d95981565b6101ab600081565b6101826102d83660046114ad565b610766565b6101826102eb366004611492565b610a29565b6101826102fe3660046114d7565b610adb565b61015a610311366004611492565b60076020526000908152604090205460ff1681565b61018261033436600461146f565b610b96565b60015461023e906001600160a01b031681565b61018261035a366004611513565b610bbb565b61018261036d3660046114ad565b610d07565b60025461023e906001600160a01b031681565b60006001600160e01b03198216637965db0b60e01b14806103b657506301ffc9a760e01b6001600160e01b03198316145b92915050565b7f5d0c23b505d97686a7eb149c2db3c9cdda71d0f1778515d411985ce042bf17a16103e6816110e0565b6001600160a01b0383166104365760405162461bcd60e51b8152602060048201526012602482015271547265653a2075736572206973207a65726f60701b60448201526064015b60405180910390fd5b6001600160a01b03831660009081526007602052604090205460ff161561049f5760405162461bcd60e51b815260206004820152601860248201527f547265653a20616c726561647920726567697374657265640000000000000000604482015260640161042d565b60006001600160a01b038316158015906104cb5750836001600160a01b0316836001600160a01b031614155b80156104ef57506001600160a01b03831660009081526007602052604090205460ff165b90506000811561050057508261058d565b60055460039060ff166002811061051957610519611537565b01546005546001600160a01b03909116915060029061053c9060ff166001611563565b6105469190611592565b6005805460ff191660ff9290921691821790556040519081527f259c73084332d8083b66457d31983714d2636d8b52fe38baea84ae9d9d1dc1c29060200160405180910390a15b6001600160a01b03858116600081815260066020908152604080832080546001600160a01b03191695871695861790556007825291829020805460ff191660011790559051851581527f859d113797d39f050d937c356ae6c65cef56740d5748fdbe2766c43aab2f5438910160405180910390a35050505050565b600082815260208190526040902060010154610623816110e0565b61062d83836110ed565b50505050565b6001600160a01b038116331461065c5760405163334bd91960e11b815260040160405180910390fd5b610666828261117f565b505050565b6000610676816110e0565b6001600160a01b0382166106c05760405162461bcd60e51b8152602060048201526011602482015270547265653a20626964206973207a65726f60781b604482015260640161042d565b6001546040516001600160a01b038085169216907f3d95ddbd62e70d2b2604c43cb7a4f582291d1d790e813f0ea997adc4a13d3ca990600090a350600180546001600160a01b0319166001600160a01b0392909216919091179055565b6003816002811061072d57600080fd5b01546001600160a01b0316905081565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b7f5d0c23b505d97686a7eb149c2db3c9cdda71d0f1778515d411985ce042bf17a1610790816110e0565b6107986111ea565b6001600160a01b0383166107e55760405162461bcd60e51b8152602060048201526014602482015273547265653a2077696e6e6572206973207a65726f60601b604482015260640161042d565b6000821161082c5760405162461bcd60e51b8152602060048201526014602482015273547265653a20627564676574206973207a65726f60601b604482015260640161042d565b600154610844906001600160a01b0316333085611206565b61084c6113b8565b6011610859600a856115b4565b61086391906115cb565b815260116108726005856115b4565b61087c91906115cb565b60208201819052815161088f90856115df565b61089991906115df565b604082015260055460009060039060ff16600281106108ba576108ba611537565b01546001600160a01b0386811660009081526006602052604081205492821693509116905b600360ff82161015610a0e576001600160a01b038216156000816109035783610905565b845b90506000868460ff166003811061091e5761091e611537565b602002015111156109d55761095a81878560ff166003811061094257610942611537565b60200201516001546001600160a01b0316919061123c565b6001600160a01b03808216908a167f688f1806314286caaa3336d48b31420f00e968df993d2ba83204f3feea127e56610994866001611563565b898760ff16600381106109a9576109a9611537565b602090810291909101516040805160ff9094168452918301528615159082015260600160405180910390a35b816109f9576001600160a01b03938416600090815260066020526040902054909316925b50508080610a06906115f2565b9150506108df565b50505050610666600160008051602061162b83398151915255565b6000610a34816110e0565b6001600160a01b038216610a7e5760405162461bcd60e51b8152602060048201526011602482015270547265653a20626261206973207a65726f60781b604482015260640161042d565b6002546040516001600160a01b038085169216907fbf98f1ee7301f79fde742c95d928a6cee1cb5b1145b8b630ae0013c7fe508ac490600090a350600280546001600160a01b0319166001600160a01b0392909216919091179055565b6000610ae6816110e0565b6001600160a01b038316610b2f5760405162461bcd60e51b815260206004820152601060248201526f547265653a20746f206973207a65726f60801b604482015260640161042d565b610b436001600160a01b038516848461123c565b826001600160a01b0316846001600160a01b03167f8bbfbb5d7fcacf6fc74005cdede0635561638507f576c95f7f294c22141be2e584604051610b8891815260200190565b60405180910390a350505050565b600082815260208190526040902060010154610bb1816110e0565b61062d838361117f565b6000610bc6816110e0565b60028360ff1610610c0b5760405162461bcd60e51b815260206004820152600f60248201526e0a8e4caca7440c4c2c840d2dcc8caf608b1b604482015260640161042d565b6001600160a01b038216610c585760405162461bcd60e51b8152602060048201526014602482015273547265653a2077616c6c6574206973207a65726f60601b604482015260640161042d565b816001600160a01b031660038460ff1660028110610c7857610c78611537565b01546040516001600160a01b039091169060ff8616907ffd33f1bd1c87d1ad4558680942fc16aa42979dc0f5d21f18eef2c1f6a72ab05e90600090a48160038460ff1660028110610ccb57610ccb611537565b0180546001600160a01b0319166001600160a01b03928316179055919091166000908152600760205260409020805460ff191660011790555050565b7f31e0210044b4f6757ce6aa31f9c6e8d4896d24a755014887391a926c5224d959610d31816110e0565b610d396111ea565b6001600160a01b038316610d865760405162461bcd60e51b8152602060048201526014602482015273547265653a207374616b6572206973207a65726f60601b604482015260640161042d565b60008211610dcd5760405162461bcd60e51b8152602060048201526014602482015273547265653a20616d6f756e74206973207a65726f60601b604482015260640161042d565b610dd56113b8565b6064610de2600a856115b4565b610dec91906115cb565b81526064610dfb6005856115b4565b610e0591906115cb565b60208201526064610e176002856115b4565b610e2191906115cb565b604082015260055460009060039060ff1660028110610e4257610e42611537565b01546001600160a01b0386811660009081526006602090815260408083205460025482516337cb2cf960e21b815292519686169750908516959394169263df2cb3e4926004808401939192918290030181865afa158015610ea7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ecb9190611611565b905060005b600360ff821610156110c4576001600160a01b03831615600081610ef45784610ef6565b855b905083878460ff1660038110610f0e57610f0e611537565b60200201511115610f355783878460ff1660038110610f2f57610f2f611537565b60200201525b6000878460ff1660038110610f4c57610f4c611537565b6020020151111561108b57868360ff1660038110610f6c57610f6c611537565b6020020151610f7b90856115df565b6002549094506001600160a01b03166340c10f19828960ff871660038110610fa557610fa5611537565b60200201516040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015610ff057600080fd5b505af1158015611004573d6000803e3d6000fd5b50505050806001600160a01b03168a6001600160a01b03167f7e715ac9816d76d2dc049a75f68a60f3a537fad818151d5b1d94c9812eed9a5a85600161104a9190611563565b8a8760ff166003811061105f5761105f611537565b602090810291909101516040805160ff9094168452918301528615159082015260600160405180910390a35b816110af576001600160a01b03948516600090815260066020526040902054909416935b505080806110bc906115f2565b915050610ed0565b5050505050610666600160008051602061162b83398151915255565b6110ea8133611271565b50565b60006110f9838361073d565b611177576000838152602081815260408083206001600160a01b03861684529091529020805460ff1916600117905561112f3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016103b6565b5060006103b6565b600061118b838361073d565b15611177576000838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45060016103b6565b6111f26112ae565b600260008051602061162b83398151915255565b6112148484848460016112e0565b61062d57604051635274afe760e01b81526001600160a01b038516600482015260240161042d565b6112498383836001611352565b61066657604051635274afe760e01b81526001600160a01b038416600482015260240161042d565b61127b828261073d565b6112aa5760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161042d565b5050565b60008051602061162b833981519152546002036112de57604051633ee5aeb560e01b815260040160405180910390fd5b565b6040516323b872dd60e01b60008181526001600160a01b038781166004528616602452604485905291602083606481808c5af192506001600051148316611340578383151615611333573d6000823e3d81fd5b6000883b113d1516831692505b60405250600060605295945050505050565b60405163a9059cbb60e01b60008181526001600160a01b038616600452602485905291602083604481808b5af1925060016000511483166113ac57838315161561139f573d6000823e3d81fd5b6000873b113d1516831692505b60405250949350505050565b60405180606001604052806003906020820280368337509192915050565b6000602082840312156113e857600080fd5b81356001600160e01b03198116811461140057600080fd5b9392505050565b80356001600160a01b038116811461141e57600080fd5b919050565b6000806040838503121561143657600080fd5b61143f83611407565b915061144d60208401611407565b90509250929050565b60006020828403121561146857600080fd5b5035919050565b6000806040838503121561148257600080fd5b8235915061144d60208401611407565b6000602082840312156114a457600080fd5b61140082611407565b600080604083850312156114c057600080fd5b6114c983611407565b946020939093013593505050565b6000806000606084860312156114ec57600080fd5b6114f584611407565b925061150360208501611407565b9150604084013590509250925092565b6000806040838503121561152657600080fd5b823560ff8116811461143f57600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60ff81811683821601908111156103b6576103b661154d565b634e487b7160e01b600052601260045260246000fd5b600060ff8316806115a5576115a561157c565b8060ff84160691505092915050565b80820281158282048414176103b6576103b661154d565b6000826115da576115da61157c565b500490565b818103818111156103b6576103b661154d565b600060ff821660ff81036116085761160861154d565b60010192915050565b60006020828403121561162357600080fd5b505191905056fe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a264697066735822122022d27befce3d071b9748d8bf721927681b75624151332c211ca401d48e67069864736f6c63430008140033000000000000000000000000e84a941fe9da6eb049aed191e3d780f5e7b8f3ab000000000000000000000000726f6d4ed3b7842ba27e54ed7f198269bc0b2558000000000000000000000000038db84e18f7e1821fe090d8c3113b67f8b803f1000000000000000000000000038db84e18f7e1821fe090d8c3113b67f8b803f1
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106101425760003560e01c806398c4f1ac116100b8578063c3c5a5471161007c578063c3c5a54714610303578063d547741f14610326578063dfafd4fd14610339578063e1d353781461034c578063ebc8a2621461035f578063fbe93b781461037257600080fd5b806398c4f1ac1461029b578063a217fddf146102c2578063a22a5bc2146102ca578063a6683c65146102dd578063b2118a8d146102f057600080fd5b806336568abe1161010a57806336568abe146101ef578063501ee12614610202578063766c4f37146102155780637f06572214610256578063885fc6561461027557806391d148541461028857600080fd5b806301ffc9a7146101475780630354adb21461016f5780631084b34314610184578063248a9ca3146101b95780632f2ff15d146101dc575b600080fd5b61015a6101553660046113d6565b610385565b60405190151581526020015b60405180910390f35b61018261017d366004611423565b6103bc565b005b6101ab7f5d0c23b505d97686a7eb149c2db3c9cdda71d0f1778515d411985ce042bf17a181565b604051908152602001610166565b6101ab6101c7366004611456565b60009081526020819052604090206001015490565b6101826101ea36600461146f565b610608565b6101826101fd36600461146f565b610633565b610182610210366004611492565b61066b565b61023e610223366004611492565b6006602052600090815260409020546001600160a01b031681565b6040516001600160a01b039091168152602001610166565b6005546102639060ff1681565b60405160ff9091168152602001610166565b61023e610283366004611456565b61071d565b61015a61029636600461146f565b61073d565b6101ab7f31e0210044b4f6757ce6aa31f9c6e8d4896d24a755014887391a926c5224d95981565b6101ab600081565b6101826102d83660046114ad565b610766565b6101826102eb366004611492565b610a29565b6101826102fe3660046114d7565b610adb565b61015a610311366004611492565b60076020526000908152604090205460ff1681565b61018261033436600461146f565b610b96565b60015461023e906001600160a01b031681565b61018261035a366004611513565b610bbb565b61018261036d3660046114ad565b610d07565b60025461023e906001600160a01b031681565b60006001600160e01b03198216637965db0b60e01b14806103b657506301ffc9a760e01b6001600160e01b03198316145b92915050565b7f5d0c23b505d97686a7eb149c2db3c9cdda71d0f1778515d411985ce042bf17a16103e6816110e0565b6001600160a01b0383166104365760405162461bcd60e51b8152602060048201526012602482015271547265653a2075736572206973207a65726f60701b60448201526064015b60405180910390fd5b6001600160a01b03831660009081526007602052604090205460ff161561049f5760405162461bcd60e51b815260206004820152601860248201527f547265653a20616c726561647920726567697374657265640000000000000000604482015260640161042d565b60006001600160a01b038316158015906104cb5750836001600160a01b0316836001600160a01b031614155b80156104ef57506001600160a01b03831660009081526007602052604090205460ff165b90506000811561050057508261058d565b60055460039060ff166002811061051957610519611537565b01546005546001600160a01b03909116915060029061053c9060ff166001611563565b6105469190611592565b6005805460ff191660ff9290921691821790556040519081527f259c73084332d8083b66457d31983714d2636d8b52fe38baea84ae9d9d1dc1c29060200160405180910390a15b6001600160a01b03858116600081815260066020908152604080832080546001600160a01b03191695871695861790556007825291829020805460ff191660011790559051851581527f859d113797d39f050d937c356ae6c65cef56740d5748fdbe2766c43aab2f5438910160405180910390a35050505050565b600082815260208190526040902060010154610623816110e0565b61062d83836110ed565b50505050565b6001600160a01b038116331461065c5760405163334bd91960e11b815260040160405180910390fd5b610666828261117f565b505050565b6000610676816110e0565b6001600160a01b0382166106c05760405162461bcd60e51b8152602060048201526011602482015270547265653a20626964206973207a65726f60781b604482015260640161042d565b6001546040516001600160a01b038085169216907f3d95ddbd62e70d2b2604c43cb7a4f582291d1d790e813f0ea997adc4a13d3ca990600090a350600180546001600160a01b0319166001600160a01b0392909216919091179055565b6003816002811061072d57600080fd5b01546001600160a01b0316905081565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b7f5d0c23b505d97686a7eb149c2db3c9cdda71d0f1778515d411985ce042bf17a1610790816110e0565b6107986111ea565b6001600160a01b0383166107e55760405162461bcd60e51b8152602060048201526014602482015273547265653a2077696e6e6572206973207a65726f60601b604482015260640161042d565b6000821161082c5760405162461bcd60e51b8152602060048201526014602482015273547265653a20627564676574206973207a65726f60601b604482015260640161042d565b600154610844906001600160a01b0316333085611206565b61084c6113b8565b6011610859600a856115b4565b61086391906115cb565b815260116108726005856115b4565b61087c91906115cb565b60208201819052815161088f90856115df565b61089991906115df565b604082015260055460009060039060ff16600281106108ba576108ba611537565b01546001600160a01b0386811660009081526006602052604081205492821693509116905b600360ff82161015610a0e576001600160a01b038216156000816109035783610905565b845b90506000868460ff166003811061091e5761091e611537565b602002015111156109d55761095a81878560ff166003811061094257610942611537565b60200201516001546001600160a01b0316919061123c565b6001600160a01b03808216908a167f688f1806314286caaa3336d48b31420f00e968df993d2ba83204f3feea127e56610994866001611563565b898760ff16600381106109a9576109a9611537565b602090810291909101516040805160ff9094168452918301528615159082015260600160405180910390a35b816109f9576001600160a01b03938416600090815260066020526040902054909316925b50508080610a06906115f2565b9150506108df565b50505050610666600160008051602061162b83398151915255565b6000610a34816110e0565b6001600160a01b038216610a7e5760405162461bcd60e51b8152602060048201526011602482015270547265653a20626261206973207a65726f60781b604482015260640161042d565b6002546040516001600160a01b038085169216907fbf98f1ee7301f79fde742c95d928a6cee1cb5b1145b8b630ae0013c7fe508ac490600090a350600280546001600160a01b0319166001600160a01b0392909216919091179055565b6000610ae6816110e0565b6001600160a01b038316610b2f5760405162461bcd60e51b815260206004820152601060248201526f547265653a20746f206973207a65726f60801b604482015260640161042d565b610b436001600160a01b038516848461123c565b826001600160a01b0316846001600160a01b03167f8bbfbb5d7fcacf6fc74005cdede0635561638507f576c95f7f294c22141be2e584604051610b8891815260200190565b60405180910390a350505050565b600082815260208190526040902060010154610bb1816110e0565b61062d838361117f565b6000610bc6816110e0565b60028360ff1610610c0b5760405162461bcd60e51b815260206004820152600f60248201526e0a8e4caca7440c4c2c840d2dcc8caf608b1b604482015260640161042d565b6001600160a01b038216610c585760405162461bcd60e51b8152602060048201526014602482015273547265653a2077616c6c6574206973207a65726f60601b604482015260640161042d565b816001600160a01b031660038460ff1660028110610c7857610c78611537565b01546040516001600160a01b039091169060ff8616907ffd33f1bd1c87d1ad4558680942fc16aa42979dc0f5d21f18eef2c1f6a72ab05e90600090a48160038460ff1660028110610ccb57610ccb611537565b0180546001600160a01b0319166001600160a01b03928316179055919091166000908152600760205260409020805460ff191660011790555050565b7f31e0210044b4f6757ce6aa31f9c6e8d4896d24a755014887391a926c5224d959610d31816110e0565b610d396111ea565b6001600160a01b038316610d865760405162461bcd60e51b8152602060048201526014602482015273547265653a207374616b6572206973207a65726f60601b604482015260640161042d565b60008211610dcd5760405162461bcd60e51b8152602060048201526014602482015273547265653a20616d6f756e74206973207a65726f60601b604482015260640161042d565b610dd56113b8565b6064610de2600a856115b4565b610dec91906115cb565b81526064610dfb6005856115b4565b610e0591906115cb565b60208201526064610e176002856115b4565b610e2191906115cb565b604082015260055460009060039060ff1660028110610e4257610e42611537565b01546001600160a01b0386811660009081526006602090815260408083205460025482516337cb2cf960e21b815292519686169750908516959394169263df2cb3e4926004808401939192918290030181865afa158015610ea7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ecb9190611611565b905060005b600360ff821610156110c4576001600160a01b03831615600081610ef45784610ef6565b855b905083878460ff1660038110610f0e57610f0e611537565b60200201511115610f355783878460ff1660038110610f2f57610f2f611537565b60200201525b6000878460ff1660038110610f4c57610f4c611537565b6020020151111561108b57868360ff1660038110610f6c57610f6c611537565b6020020151610f7b90856115df565b6002549094506001600160a01b03166340c10f19828960ff871660038110610fa557610fa5611537565b60200201516040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015610ff057600080fd5b505af1158015611004573d6000803e3d6000fd5b50505050806001600160a01b03168a6001600160a01b03167f7e715ac9816d76d2dc049a75f68a60f3a537fad818151d5b1d94c9812eed9a5a85600161104a9190611563565b8a8760ff166003811061105f5761105f611537565b602090810291909101516040805160ff9094168452918301528615159082015260600160405180910390a35b816110af576001600160a01b03948516600090815260066020526040902054909416935b505080806110bc906115f2565b915050610ed0565b5050505050610666600160008051602061162b83398151915255565b6110ea8133611271565b50565b60006110f9838361073d565b611177576000838152602081815260408083206001600160a01b03861684529091529020805460ff1916600117905561112f3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016103b6565b5060006103b6565b600061118b838361073d565b15611177576000838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45060016103b6565b6111f26112ae565b600260008051602061162b83398151915255565b6112148484848460016112e0565b61062d57604051635274afe760e01b81526001600160a01b038516600482015260240161042d565b6112498383836001611352565b61066657604051635274afe760e01b81526001600160a01b038416600482015260240161042d565b61127b828261073d565b6112aa5760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161042d565b5050565b60008051602061162b833981519152546002036112de57604051633ee5aeb560e01b815260040160405180910390fd5b565b6040516323b872dd60e01b60008181526001600160a01b038781166004528616602452604485905291602083606481808c5af192506001600051148316611340578383151615611333573d6000823e3d81fd5b6000883b113d1516831692505b60405250600060605295945050505050565b60405163a9059cbb60e01b60008181526001600160a01b038616600452602485905291602083604481808b5af1925060016000511483166113ac57838315161561139f573d6000823e3d81fd5b6000873b113d1516831692505b60405250949350505050565b60405180606001604052806003906020820280368337509192915050565b6000602082840312156113e857600080fd5b81356001600160e01b03198116811461140057600080fd5b9392505050565b80356001600160a01b038116811461141e57600080fd5b919050565b6000806040838503121561143657600080fd5b61143f83611407565b915061144d60208401611407565b90509250929050565b60006020828403121561146857600080fd5b5035919050565b6000806040838503121561148257600080fd5b8235915061144d60208401611407565b6000602082840312156114a457600080fd5b61140082611407565b600080604083850312156114c057600080fd5b6114c983611407565b946020939093013593505050565b6000806000606084860312156114ec57600080fd5b6114f584611407565b925061150360208501611407565b9150604084013590509250925092565b6000806040838503121561152657600080fd5b823560ff8116811461143f57600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60ff81811683821601908111156103b6576103b661154d565b634e487b7160e01b600052601260045260246000fd5b600060ff8316806115a5576115a561157c565b8060ff84160691505092915050565b80820281158282048414176103b6576103b661154d565b6000826115da576115da61157c565b500490565b818103818111156103b6576103b661154d565b600060ff821660ff81036116085761160861154d565b60010192915050565b60006020828403121561162357600080fd5b505191905056fe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a264697066735822122022d27befce3d071b9748d8bf721927681b75624151332c211ca401d48e67069864736f6c63430008140033