Skip to content
Verified contractExactAGPL-3.0

OldSifuBalance

Address0xd8960b01ac99966e686101196c0d5aaa4e2d7588
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.20

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
License
AGPL-3.0
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
21,538,780
Creation transaction
0x2e64c9e542…28d8290095

contracts/OldSifuBalance.sol

// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title SifuBalance
 * @dev Calculates the Sifu real balance of a user. The calculation takes into account the user’s holdings of Sifu, as well as their collateral and debts, to determine their effective balance.
 */
contract OldSifuBalance {
    IERC20 public immutable sifu;
    IERC20 public immutable uSIFU;
    IERC20 public immutable variableDebtSIFU;

    /**
     * @dev Internal function to check if an address is a contract.
     * @param account The address to check.
     * @return A boolean indicating if the address is a contract.
     */
    function isContract(address account) internal view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Constructor function to initialize the smart contract with addresses of specific tokens.
     * @param _sifu Address of the Sifu token contract.
     * @param _uSifu Address of the uSifu token contract.
     * @param _variableDebtSifu Address of the variableDebtSifu token contract.
     */
    constructor(address _sifu, address _uSifu, address _variableDebtSifu) {
        require(
            _sifu != address(0) &&
                _uSifu != address(0) &&
                _variableDebtSifu != address(0),
            "Invalid token address"
        );

        require(isContract(_sifu), "sifu is not a contract");
        require(isContract(_uSifu), "uSifu is not a contract");
        require(
            isContract(_variableDebtSifu),
            "variableDebtSifu is not a contract"
        );

        sifu = IERC20(_sifu);
        uSIFU = IERC20(_uSifu);
        variableDebtSIFU = IERC20(_variableDebtSifu);
    }

    /**
     * @dev Internal function to get the balance of a specific token for an account.
     * @param token The ERC20 token contract.
     * @param account The address of the account.
     * @return The balance of the token for the given account.
     */
    function getBalance(
        IERC20 token,
        address account
    ) internal view returns (uint256) {
        return token.balanceOf(account);
    }

    /**
     * @dev External function to calculate the effective balance of an account.
     * It sums the balances of Sifu, uSIFU tokens and subtracts the balance of variableDebtSIFU tokens.
     * If the debt is greater than the sum of Sifu, uSIFU, the function returns 0.
     * @param account The address of the account.
     * @return The calculated effective voting power of the account.
     */
    function balanceOf(address account) external view returns (uint256) {
        uint256 sifuBalance = getBalance(sifu, account);
        uint256 uSifuBalance = getBalance(uSIFU, account);
        uint256 debtSifuBalance = getBalance(variableDebtSIFU, account);

        uint256 totalBalance = sifuBalance + uSifuBalance;

        return
            debtSifuBalance > totalBalance
                ? 0
                : (totalBalance - debtSifuBalance);
    }
}

@openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the 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);
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.