Skip to content
Verified contractExactMIT

DemoUSD

Address0xff8e088caced659926442575493d50800d98b373
Balance

0 ETH

 

Transactions

3

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
Yes, 2,000 runs
EVM version
prague
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,495,030
Creation transaction
0x99c67c1640…a8ab6bba26

src/demo/DemoContracts.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/// @title DemoUSD
/// @notice Test token for the kpk demo Fund (6 decimals, like USDC). Only the deployer mints. No value.
contract DemoUSD {
    string public constant name = "kpk Demo USD (test token, no value)";
    string public constant symbol = "kdUSD";
    uint8 public constant decimals = 6;
    address public immutable minter;

    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    constructor() {
        minter = msg.sender;
    }

    function mint(address to, uint256 amount) external {
        require(msg.sender == minter, "not minter");
        totalSupply += amount;
        balanceOf[to] += amount;
        emit Transfer(address(0), to, amount);
    }

    function approve(address spender, uint256 amount) external returns (bool) {
        allowance[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);
        return true;
    }

    function transfer(address to, uint256 amount) external returns (bool) {
        _transfer(msg.sender, to, amount);
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        uint256 allowed = allowance[from][msg.sender];
        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
        _transfer(from, to, amount);
        return true;
    }

    function _transfer(address from, address to, uint256 amount) internal {
        balanceOf[from] -= amount;
        balanceOf[to] += amount;
        emit Transfer(from, to, amount);
    }
}

interface IERC20Minimal {
    function balanceOf(address account) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function decimals() external view returns (uint8);
    function symbol() external view returns (string memory);
}

/// @title DemoPortfolio
/// @notice Stands in for a kpk Fund's Portfolio Safe: holds the Fund's assets and lets the share contract pay
///         redemptions from it (kpkShares pays with transferFrom(portfolioSafe, receiver, assets)).
contract DemoPortfolio {
    address public immutable owner;

    constructor() {
        owner = msg.sender;
    }

    /// @notice Lets `spender` (the share contract) pull `token` for redemptions.
    function approve(address token, address spender) external {
        require(msg.sender == owner, "not owner");
        IERC20Minimal(token).approve(spender, type(uint256).max);
    }
}

/// @title DemoNavCalculator
/// @notice Same interface as kpk's NAVCalculator (`getAccountNav(account, quoteAsset)`), with a cheap NAV: the
///         account's balance of the quote asset. kpk's NAVCalculator scans 47 balance adapters and costs about
///         17 million gas per read; this read costs a few thousand.
contract DemoNavCalculator {
    struct Asset {
        address asset;
        string symbol;
        uint8 decimals;
    }

    struct NAV {
        int256 value;
        Asset quoteAsset;
        uint64 timestamp;
        Asset[] stalePriceAssets;
        bool sequencerDown;
        bool quoteAssetStale;
        Asset[] irregularPriceAssets;
        bool quoteAssetIrregular;
        Asset[] monitorsUnhealthyPriceAssets;
    }

    function getAccountNav(address account, address quoteAsset) external view returns (NAV memory nav) {
        IERC20Minimal quote = IERC20Minimal(quoteAsset);
        nav.value = int256(quote.balanceOf(account));
        nav.quoteAsset = Asset(quoteAsset, quote.symbol(), quote.decimals());
        nav.timestamp = uint64(block.timestamp);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 2000,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "credible-std/=/home/user/workspace/repo/lib/credible-std/src/",
    "forge-std/=/home/user/workspace/repo/lib/credible-std/lib/forge-std/src/",
    "kpk-assertions/=/home/user/workspace/repo/assertions/src/",
    "kpk-fixtures/=/home/user/workspace/repo/assertions/test/fixtures/",
    "credible-registry/=src/credible-registry/",
    "@openzeppelin/contracts-upgradeable/=src/kpk/lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/contracts/=src/kpk/lib/openzeppelin-contracts/contracts/",
    "erc4626-tests/=/home/user/workspace/repo/lib/credible-std/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "halmos-cheatcodes/=/home/user/workspace/repo/lib/credible-std/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts/=/home/user/workspace/repo/lib/credible-std/lib/openzeppelin-contracts/",
    "safe-smart-account-1.3.0/=/home/user/workspace/repo/lib/credible-std/lib/safe-smart-account-1.3.0/contracts/",
    "safe-smart-account-1.4.0/=/home/user/workspace/repo/lib/credible-std/lib/safe-smart-account-1.4.0/contracts/",
    "safe-smart-account-1.5.0/=/home/user/workspace/repo/lib/credible-std/lib/safe-smart-account-1.5.0/",
    "safe-smart-account/=/home/user/workspace/repo/lib/credible-std/lib/safe-smart-account/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.