Contract 0x1442bC024a92C2F96c3c1D2E9274bC4d8119d97e 1

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x8543c33f03e69bc40a2f2d06f64f75d60682adbdc8062191054293271b1e5f0f0x60c06040197370072021-10-22 5:44:2947 days 12 hrs ago0x55d56e1bb2fc8280a775ccfe9ececcecf1a01562 IN  Contract Creation0 FTM0.154099851421
[ Download CSV Export 
Latest 1 internal transaction
Parent Txn Hash Block From To Value
0x8543c33f03e69bc40a2f2d06f64f75d60682adbdc8062191054293271b1e5f0f197370072021-10-22 5:44:2947 days 12 hrs ago 0x55d56e1bb2fc8280a775ccfe9ececcecf1a01562  Contract Creation0 FTM
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CDPRegistry

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 3 : CDPRegistry.sol
// SPDX-License-Identifier: bsl-1.1

/*
  Copyright 2020 Unit Protocol: Artem Zakharov ([email protected]).
*/
pragma solidity ^0.7.1;
pragma experimental ABIEncoderV2;

import "./interfaces/IVault.sol";
import "./interfaces/ICollateralRegistry.sol";


contract CDPRegistry {

    struct CDP {
        address asset;
        address owner;
    }

    mapping (address => address[]) cdpList;
    mapping (address => mapping (address => uint)) cdpIndex;

    IVault public immutable vault;
    ICollateralRegistry public immutable cr;

    event Added(address indexed asset, address indexed owner);
    event Removed(address indexed asset, address indexed owner);

    constructor (address _vault, address _collateralRegistry) {
        require(_vault != address(0) && _collateralRegistry != address(0), "Unit Protocol: ZERO_ADDRESS");
        vault = IVault(_vault);
        cr = ICollateralRegistry(_collateralRegistry);
    }

    function checkpoint(address asset, address owner) public {
        require(asset != address(0) && owner != address(0), "Unit Protocol: ZERO_ADDRESS");

        bool listed = isListed(asset, owner);
        bool alive = isAlive(asset, owner);

        if (alive && !listed) {
            _addCdp(asset, owner);
        } else if (listed && !alive) {
            _removeCdp(asset, owner);
        }
    }

    function batchCheckpointForAsset(address asset, address[] calldata owners) external {
        for (uint i = 0; i < owners.length; i++) {
            checkpoint(asset, owners[i]);
        }
    }

    function batchCheckpoint(address[] calldata assets, address[] calldata owners) external {
        require(assets.length == owners.length, "Unit Protocol: ARGUMENTS_LENGTH_MISMATCH");
        for (uint i = 0; i < owners.length; i++) {
            checkpoint(assets[i], owners[i]);
        }
    }

    function isAlive(address asset, address owner) public view returns (bool) {
        return vault.debts(asset, owner) != 0;
    }

    function isListed(address asset, address owner) public view returns (bool) {
        if (cdpList[asset].length == 0) { return false; }
        return cdpIndex[asset][owner] != 0 || cdpList[asset][0] == owner;
    }

    function _removeCdp(address asset, address owner) internal {
        uint id = cdpIndex[asset][owner];

        delete cdpIndex[asset][owner];

        uint lastId = cdpList[asset].length - 1;

        if (id != lastId) {
            address lastOwner = cdpList[asset][lastId];
            cdpList[asset][id] = lastOwner;
            cdpIndex[asset][lastOwner] = id;
        }

        cdpList[asset].pop();

        emit Removed(asset, owner);
    }

    function _addCdp(address asset, address owner) internal {
        cdpIndex[asset][owner] = cdpList[asset].length;
        cdpList[asset].push(owner);

        emit Added(asset, owner);
    }

    function getCdpsByCollateral(address asset) external view returns (CDP[] memory cdps) {
        address[] memory owners = cdpList[asset];
        cdps = new CDP[](owners.length);
        for (uint i = 0; i < owners.length; i++) {
            cdps[i] = CDP(asset, owners[i]);
        }
    }

    function getCdpsByOwner(address owner) external view returns (CDP[] memory r) {
        address[] memory assets = cr.collaterals();
        CDP[] memory cdps = new CDP[](assets.length);
        uint actualCdpsCount;

        for (uint i = 0; i < assets.length; i++) {
            if (isListed(assets[i], owner)) {
                cdps[actualCdpsCount++] = CDP(assets[i], owner);
            }
        }

        r = new CDP[](actualCdpsCount);

        for (uint i = 0; i < actualCdpsCount; i++) {
            r[i] = cdps[i];
        }

    }

    function getAllCdps() external view returns (CDP[] memory r) {
        uint totalCdpCount = getCdpsCount();
        
        uint cdpCount;

        r = new CDP[](totalCdpCount);

        address[] memory assets = cr.collaterals();
        for (uint i = 0; i < assets.length; i++) {
            address[] memory owners = cdpList[assets[i]];
            for (uint j = 0; j < owners.length; j++) {
                r[cdpCount++] = CDP(assets[i], owners[j]);
            }
        }
    }

    function getCdpsCount() public view returns (uint totalCdpCount) {
        address[] memory assets = cr.collaterals();
        for (uint i = 0; i < assets.length; i++) {
            totalCdpCount += cdpList[assets[i]].length;
        }
    }

    function getCdpsCountForCollateral(address asset) public view returns (uint) {
        return cdpList[asset].length;
    }
}

File 2 of 3 : IVault.sol
// SPDX-License-Identifier: bsl-1.1

/*
  Copyright 2020 Unit Protocol: Artem Zakharov ([email protected]).
*/
pragma solidity ^0.7.6;

interface IVault {
    function DENOMINATOR_1E2 (  ) external view returns ( uint256 );
    function DENOMINATOR_1E5 (  ) external view returns ( uint256 );
    function borrow ( address asset, address user, uint256 amount ) external returns ( uint256 );
    function changeOracleType ( address asset, address user, uint256 newOracleType ) external;
    function chargeFee ( address asset, address user, uint256 amount ) external;
    function decreaseFee ( address asset, address user, uint amount ) external;
    function col (  ) external view returns ( address );
    function colToken ( address, address ) external view returns ( uint256 );
    function collaterals ( address, address ) external view returns ( uint256 );
    function debts ( address, address ) external view returns ( uint256 );
    function getFee ( address, address ) external view returns ( uint256 );
    function depositCol ( address asset, address user, uint256 amount ) external;
    function depositEth ( address user ) external payable;
    function depositMain ( address asset, address user, uint256 amount ) external;
    function destroy ( address asset, address user ) external;
    function getTotalDebt ( address asset, address user ) external view returns ( uint256 );
    function lastUpdate ( address, address ) external view returns ( uint256 );
    function liquidate ( address asset, address positionOwner, uint256 mainAssetToLiquidator, uint256 mainAssetToPositionOwner, uint256 repayment, uint256 penalty, address liquidator ) external;
    function liquidationBlock ( address, address ) external view returns ( uint256 );
    function liquidationFee ( address, address ) external view returns ( uint256 );
    function liquidationPrice ( address, address ) external view returns ( uint256 );
    function oracleType ( address, address ) external view returns ( uint256 );
    function repay ( address asset, address user, uint256 amount ) external returns ( uint256 );
    function spawn ( address asset, address user, uint256 _oracleType ) external;
    function stabilityFee ( address, address ) external view returns ( uint256 );
    function tokenDebts ( address ) external view returns ( uint256 );
    function triggerLiquidation ( address asset, address positionOwner, uint256 initialPrice ) external;
    function update ( address asset, address user ) external;
    function usdp (  ) external view returns ( address );
    function vaultParameters (  ) external view returns ( address );
    function weth (  ) external view returns ( address payable );
    function withdrawCol ( address asset, address user, uint256 amount ) external;
    function withdrawEth ( address user, uint256 amount ) external;
    function withdrawMain ( address asset, address user, uint256 amount ) external;
}

File 3 of 3 : ICollateralRegistry.sol
// SPDX-License-Identifier: bsl-1.1

/*
  Copyright 2020 Unit Protocol: Artem Zakharov ([email protected]).
*/
pragma solidity ^0.7.6;

interface ICollateralRegistry {
    function addCollateral ( address asset ) external;
    function collateralId ( address ) external view returns ( uint256 );
    function collaterals (  ) external view returns ( address[] memory );
    function removeCollateral ( address asset ) external;
    function vaultParameters (  ) external view returns ( address );
    function isCollateral ( address asset ) external view returns ( bool );
    function collateralList ( uint id ) external view returns ( address );
    function collateralsCount (  ) external view returns ( uint );
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_collateralRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"Added","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"Removed","type":"event"},{"inputs":[{"internalType":"address[]","name":"assets","type":"address[]"},{"internalType":"address[]","name":"owners","type":"address[]"}],"name":"batchCheckpoint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address[]","name":"owners","type":"address[]"}],"name":"batchCheckpointForAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"checkpoint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cr","outputs":[{"internalType":"contract ICollateralRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllCdps","outputs":[{"components":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"internalType":"struct CDPRegistry.CDP[]","name":"r","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"getCdpsByCollateral","outputs":[{"components":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"internalType":"struct CDPRegistry.CDP[]","name":"cdps","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"getCdpsByOwner","outputs":[{"components":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"internalType":"struct CDPRegistry.CDP[]","name":"r","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCdpsCount","outputs":[{"internalType":"uint256","name":"totalCdpCount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"getCdpsCountForCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"isAlive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"isListed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60c060405234801561001057600080fd5b506040516200120838038062001208833981016040819052610031916100b0565b6001600160a01b0382161580159061005157506001600160a01b03811615155b6100765760405162461bcd60e51b815260040161006d906100e2565b60405180910390fd5b6001600160601b0319606092831b8116608052911b1660a052610119565b80516001600160a01b03811681146100ab57600080fd5b919050565b600080604083850312156100c2578182fd5b6100cb83610094565b91506100d960208401610094565b90509250929050565b6020808252601b908201527f556e69742050726f746f636f6c3a205a45524f5f414444524553530000000000604082015260600190565b60805160601c60a05160601c6110b162000157600039806103ce528061059452806106945280610780525080610a5e5280610af052506110b16000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c8063bb55b7fc11610071578063bb55b7fc14610147578063bce092c41461015a578063e5011ac614610162578063f45a432014610175578063f8aa43f714610195578063fbfa77cf146101a8576100b4565b80633e18638f146100b957806348e3da3c146100e25780635a5fdfe5146100f757806362eb33e3146100ff578063a04a7c6914610114578063b0113e6b14610127575b600080fd5b6100cc6100c7366004610d62565b6101b0565b6040516100d99190610f60565b60405180910390f35b6100f56100f0366004610e10565b6102df565b005b6100cc610366565b610107610592565b6040516100d99190610fc7565b6100f5610122366004610dbd565b6105b6565b61013a610135366004610d62565b6105df565b6040516100d9919061105a565b6100f5610155366004610d85565b6105fe565b61013a61068f565b6100cc610170366004610d62565b61077a565b610188610183366004610d85565b610997565b6040516100d99190610fbc565b6101886101a3366004610d85565b610a44565b610107610aee565b6001600160a01b03811660009081526020818152604080832080548251818502810185019093528083526060949383018282801561021757602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116101f9575b50505050509050805167ffffffffffffffff8111801561023657600080fd5b5060405190808252806020026020018201604052801561027057816020015b61025d610cf7565b8152602001906001900390816102555790505b50915060005b81518110156102d8576040518060400160405280856001600160a01b031681526020018383815181106102a557fe5b60200260200101516001600160a01b03168152508382815181106102c557fe5b6020908102919091010152600101610276565b5050919050565b8281146103075760405162461bcd60e51b81526004016102fe90610fdb565b60405180910390fd5b60005b8181101561035f5761035785858381811061032157fe5b90506020020160208101906103369190610d62565b84848481811061034257fe5b90506020020160208101906101559190610d62565b60010161030a565b5050505050565b6060600061037261068f565b905060008167ffffffffffffffff8111801561038d57600080fd5b506040519080825280602002602001820160405280156103c757816020015b6103b4610cf7565b8152602001906001900390816103ac5790505b50925060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634113e5ca6040518163ffffffff1660e01b815260040160006040518083038186803b15801561042557600080fd5b505afa158015610439573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526104619190810190610e79565b905060005b815181101561058b57600080600084848151811061048057fe5b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156104fc57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116104de575b5050505050905060005b815181101561058157604051806040016040528085858151811061052657fe5b60200260200101516001600160a01b0316815260200183838151811061054857fe5b60200260200101516001600160a01b031681525087868060010197508151811061056e57fe5b6020908102919091010152600101610506565b5050600101610466565b5050505090565b7f000000000000000000000000000000000000000000000000000000000000000081565b60005b818110156105d9576105d18484848481811061034257fe5b6001016105b9565b50505050565b6001600160a01b0381166000908152602081905260409020545b919050565b6001600160a01b0382161580159061061e57506001600160a01b03811615155b61063a5760405162461bcd60e51b81526004016102fe90611023565b60006106468383610997565b905060006106548484610a44565b9050808015610661575081155b15610675576106708484610b12565b6105d9565b818015610680575080155b156105d9576105d98484610b8e565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634113e5ca6040518163ffffffff1660e01b815260040160006040518083038186803b1580156106eb57600080fd5b505afa1580156106ff573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526107279190810190610e79565b905060005b81518110156107755760008083838151811061074457fe5b6020908102919091018101516001600160a01b0316825281019190915260400160002054929092019160010161072c565b505090565b606060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634113e5ca6040518163ffffffff1660e01b815260040160006040518083038186803b1580156107d757600080fd5b505afa1580156107eb573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526108139190810190610e79565b90506000815167ffffffffffffffff8111801561082f57600080fd5b5060405190808252806020026020018201604052801561086957816020015b610856610cf7565b81526020019060019003908161084e5790505b5090506000805b83518110156108fb5761089684828151811061088857fe5b602002602001015187610997565b156108f35760405180604001604052808583815181106108b257fe5b60200260200101516001600160a01b03168152602001876001600160a01b03168152508383806001019450815181106108e757fe5b60200260200101819052505b600101610870565b508067ffffffffffffffff8111801561091357600080fd5b5060405190808252806020026020018201604052801561094d57816020015b61093a610cf7565b8152602001906001900390816109325790505b50935060005b8181101561098e5782818151811061096757fe5b602002602001015185828151811061097b57fe5b6020908102919091010152600101610953565b50505050919050565b6001600160a01b0382166000908152602081905260408120546109bc57506000610a3e565b6001600160a01b03808416600090815260016020908152604080832093861683529290522054151580610a3b5750816001600160a01b0316600080856001600160a01b03166001600160a01b03168152602001908152602001600020600081548110610a2457fe5b6000918252602090912001546001600160a01b0316145b90505b92915050565b604051634ac1c33d60e01b81526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690634ac1c33d90610a959086908690600401610f46565b60206040518083038186803b158015610aad57600080fd5b505afa158015610ac1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae59190610f2e565b15159392505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6001600160a01b03808316600081815260208181526040808320805460018085528386209789168087529785528386208290558585528101825590845291832090910180546001600160a01b03191685179055517f938c63ac3d228b23f6bee7618fefc6790522e338ac202c958a2ea9eb9706c5d19190a35050565b6001600160a01b0380831660008181526001602090815260408083209486168352938152838220805490839055928252819052919091205460001901808214610c74576001600160a01b0384166000908152602081905260408120805483908110610bf557fe5b60009182526020808320909101546001600160a01b038881168452918390526040909220805491909216925082919085908110610c2e57fe5b600091825260208083209190910180546001600160a01b0319166001600160a01b0394851617905587831682526001815260408083209490931682529290925290208290555b6001600160a01b0384166000908152602081905260409020805480610c9557fe5b600082815260208120820160001990810180546001600160a01b03191690559091019091556040516001600160a01b0385811692908716917f40e634d0e26d9ec2e860e4dd9b7b2cfbb569b6058362a1a54d3a94718bc495879190a350505050565b604080518082019091526000808252602082015290565b80516105f981611063565b60008083601f840112610d2a578081fd5b50813567ffffffffffffffff811115610d41578182fd5b6020830191508360208083028501011115610d5b57600080fd5b9250929050565b600060208284031215610d73578081fd5b8135610d7e81611063565b9392505050565b60008060408385031215610d97578081fd5b8235610da281611063565b91506020830135610db281611063565b809150509250929050565b600080600060408486031215610dd1578081fd5b8335610ddc81611063565b9250602084013567ffffffffffffffff811115610df7578182fd5b610e0386828701610d19565b9497909650939450505050565b60008060008060408587031215610e25578081fd5b843567ffffffffffffffff80821115610e3c578283fd5b610e4888838901610d19565b90965094506020870135915080821115610e60578283fd5b50610e6d87828801610d19565b95989497509550505050565b60006020808385031215610e8b578182fd5b825167ffffffffffffffff80821115610ea2578384fd5b818501915085601f830112610eb5578384fd5b815181811115610ec157fe5b83810260405185828201018181108582111715610eda57fe5b604052828152858101935084860182860187018a1015610ef8578788fd5b8795505b83861015610f2157610f0d81610d0e565b855260019590950194938601938601610efc565b5098975050505050505050565b600060208284031215610f3f578081fd5b5051919050565b6001600160a01b0392831681529116602082015260400190565b602080825282518282018190526000919060409081850190868401855b82811015610faf57815180516001600160a01b0390811686529087015116868501529284019290850190600101610f7d565b5091979650505050505050565b901515815260200190565b6001600160a01b0391909116815260200190565b60208082526028908201527f556e69742050726f746f636f6c3a20415247554d454e54535f4c454e4754485f60408201526709a92a69a82a886960c31b606082015260800190565b6020808252601b908201527f556e69742050726f746f636f6c3a205a45524f5f414444524553530000000000604082015260600190565b90815260200190565b6001600160a01b038116811461107857600080fd5b5056fea26469706673582212209b90c05698eb7a9cb76f25e8fdbefe3830c852f66c6364467683dd8886b19f7264736f6c63430007060033000000000000000000000000d7a9b0d75e51bfb91c843b23fb2c19aa3b8d958e0000000000000000000000005bef93a96dcc2caec92e8610bb2f5bf5eb4d89f4

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000d7a9b0d75e51bfb91c843b23fb2c19aa3b8d958e0000000000000000000000005bef93a96dcc2caec92e8610bb2f5bf5eb4d89f4

-----Decoded View---------------
Arg [0] : _vault (address): 0xd7a9b0d75e51bfb91c843b23fb2c19aa3b8d958e
Arg [1] : _collateralRegistry (address): 0x5bef93a96dcc2caec92e8610bb2f5bf5eb4d89f4

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000d7a9b0d75e51bfb91c843b23fb2c19aa3b8d958e
Arg [1] : 0000000000000000000000005bef93a96dcc2caec92e8610bb2f5bf5eb4d89f4


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Validator ID :
0 FTM

Amount Staked
0

Amount Delegated
0

Staking Total
0

Staking Start Epoch
0

Staking Start Time
0

Proof of Importance
0

Origination Score
0

Validation Score
0

Active
0

Online
0

Downtime
0 s
Address Amount claimed Rewards Created On Epoch Created On
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.