Verified contractPartialAGPL-3.0-or-later
UsddPsm7
Address0xce355440c00014a229bbec030a2b8f8eb45a2897
- Balance
0 ETH
- Transactions
58,357
- Compiler
solc 0.6.12
- Same code
Only this contract
Details
- Compiler
- solc 0.6.12+commit.27d51765
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- istanbul
- License
- AGPL-3.0-or-later
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 23,274,634
- Creation transaction
- 0xff89eb4cac…d28c0bde06
lib/psm/src/psm7.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity ^0.6.12;
import {UsddJoinAbstract} from "./interfaces/dss/UsddJoinAbstract.sol";
import {UsddAbstract} from "./interfaces/dss/UsddAbstract.sol";
import {VatAbstract} from "./interfaces/dss/VatAbstract.sol";
interface AuthGemJoinAbstract {
function dec() external view returns (uint256);
function vat() external view returns (address);
function ilk() external view returns (bytes32);
function join(address, uint256, address) external returns (uint256);
function exit(address, uint256) external;
}
// USDD Peg Stability Module
contract UsddPsm7 {
// --- Auth ---
mapping(address => uint256) public wards;
function rely(address usr) external auth {wards[usr] = 1;
emit Rely(usr);}
function deny(address usr) external auth {wards[usr] = 0;
emit Deny(usr);}
modifier auth {require(wards[msg.sender] == 1, "UsddPsm/not-authorized");
_;}
VatAbstract immutable public vat;
AuthGemJoinAbstract immutable public gemJoin; // Stablecoin Join adapter
UsddAbstract immutable public usdd; // USDD token
UsddJoinAbstract immutable public usddJoin; // USDD Join adapter
bytes32 immutable public ilk; // Collateral type
address immutable public vow; // System treasury
uint256 immutable internal to18ConversionFactor;
// --- State Variables ---
uint256 public tin; // Fee in [wad]
uint256 public tout; // Fee out [wad]
uint256 public sellEnabled; // Stablecoin -> USDD enabled
uint256 public buyEnabled; // USDD -> Stablecoin enabled
// --- Events ---
event Rely(address indexed usr);
event Deny(address indexed usr);
event File(bytes32 indexed what, uint256 data);
event SellGem(address indexed owner, uint256 value, uint256 fee);
event BuyGem(address indexed owner, uint256 value, uint256 fee);
// --- Init ---
constructor(
address gemJoin_, // Stablecoin Join adapter
address usddJoin_, // USDD Join adapter
address vow_ // System treasury
) public {
wards[msg.sender] = 1;
emit Rely(msg.sender);
AuthGemJoinAbstract gemJoin__ = gemJoin = AuthGemJoinAbstract(gemJoin_);
UsddJoinAbstract usddJoin__ = usddJoin = UsddJoinAbstract(usddJoin_);
VatAbstract vat__ = vat = VatAbstract(address(gemJoin__.vat()));
UsddAbstract usdd__ = usdd = UsddAbstract(address(usddJoin__.usdd()));
ilk = gemJoin__.ilk();
vow = vow_;
// Handle decimals conversion
to18ConversionFactor = 10 ** (18 - gemJoin__.dec());
// Set initial state
sellEnabled = 1; // Enable by default
buyEnabled = 1; // Enable by default
// Approve max amount for USDD transfers
usdd__.approve(usddJoin_, uint256(-1));
vat__.hope(usddJoin_);
}
// --- Math ---
uint256 constant WAD = 10 ** 18;
uint256 constant RAY = 10 ** 27;
function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x + y) >= x, "UsddPsm/add-overflow");
}
function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x - y) <= x, "UsddPsm/sub-underflow");
}
function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
require(y == 0 || (z = x * y) / y == x, "UsddPsm/mul-overflow");
}
// --- Administration ---
function file(bytes32 what, uint256 data) external auth {
if (what == "tin") tin = data;
else if (what == "tout") tout = data;
else if (what == "sellEnabled") {
sellEnabled = data;
}
else if (what == "buyEnabled") {
buyEnabled = data;
}
else revert("UsddPsm/file-unrecognized-param");
emit File(what, data);
}
// --- Upgrade Path ---
function hope(address usr) external auth {
vat.hope(usr);
}
function nope(address usr) external auth {
vat.nope(usr);
}
// --- Primary Functions ---
// Sell gem for USDD
function sellGem(address usr, uint256 gemAmt) external {
require(sellEnabled == 1, "UsddPsm/sell-not-enabled");
// Transfer gem in and mint USDD
uint256 wad = gemJoin.join(address(this), gemAmt, msg.sender);
vat.frob(ilk, address(this), address(this), address(this), int256(wad), int256(wad));
uint256 fee = mul(wad, tin) / WAD;
uint256 usddAmt = sub(wad, fee);
// Send fee to system treasury
vat.move(address(this), vow, mul(fee, RAY));
// Send USDD to user
usddJoin.exit(usr, usddAmt);
emit SellGem(usr, gemAmt, fee);
}
// Buy gem with USDD
function buyGem(address usr, uint256 gemAmt) external {
require(buyEnabled == 1, "UsddPsm/buy-not-enabled");
uint256 gemAmt18 = mul(gemAmt, to18ConversionFactor);
uint256 fee = mul(gemAmt18, tout) / WAD;
uint256 usddAmt = add(gemAmt18, fee);
// Transfer USDD in
require(usdd.transferFrom(msg.sender, address(this), usddAmt), "UsddPsm/failed-transfer");
usddJoin.join(address(this), usddAmt);
// Burn USDD and release gem
vat.frob(ilk, address(this), address(this), address(this), - int256(gemAmt18), - int256(gemAmt18));
gemJoin.exit(usr, gemAmt);
// Send fee to system treasury
vat.move(address(this), vow, mul(fee, RAY));
emit BuyGem(usr, gemAmt, fee);
}
}lib/psm/src/interfaces/dss/UsddAbstract.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.5.12;
// https://github.com/usdd-network/usddv2-contracts/blob/main/src/dss/usdd.sol
interface UsddAbstract {
function wards(address) external view returns (uint256);
function rely(address) external;
function deny(address) external;
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function version() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
function allowance(address, address) external view returns (uint256);
function nonces(address) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external view returns (bytes32);
function transfer(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function mint(address, uint256) external;
function burn(address, uint256) external;
function approve(address, uint256) external returns (bool);
function push(address, uint256) external;
function pull(address, uint256) external;
function move(address, address, uint256) external;
function permit(address, address, uint256, uint256, bool, uint8, bytes32, bytes32) external;
}
lib/psm/src/interfaces/dss/UsddJoinAbstract.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.5.12;
// https://github.com/usdd-network/usddv2-contracts/blob/main/src/dss/join.sol
interface UsddJoinAbstract {
function wards(address) external view returns (uint256);
function rely(address usr) external;
function deny(address usr) external;
function vat() external view returns (address);
function usdd() external view returns (address);
function live() external view returns (uint256);
function cage() external;
function join(address, uint256) external;
function exit(address, uint256) external;
}
lib/psm/src/interfaces/dss/VatAbstract.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.5.12;
// https://github.com/usdd-network/usddv2-contracts/blob/main/src/dss/vat.sol
interface VatAbstract {
function wards(address) external view returns (uint256);
function rely(address) external;
function deny(address) external;
function can(address, address) external view returns (uint256);
function hope(address) external;
function nope(address) external;
function ilks(bytes32) external view returns (uint256, uint256, uint256, uint256, uint256);
function urns(bytes32, address) external view returns (uint256, uint256);
function gem(bytes32, address) external view returns (uint256);
function usdd(address) external view returns (uint256);
function sin(address) external view returns (uint256);
function debt() external view returns (uint256);
function vice() external view returns (uint256);
function Line() external view returns (uint256);
function live() external view returns (uint256);
function init(bytes32) external;
function file(bytes32, uint256) external;
function file(bytes32, bytes32, uint256) external;
function cage() external;
function slip(bytes32, address, int256) external;
function flux(bytes32, address, address, uint256) external;
function move(address, address, uint256) external;
function frob(bytes32, address, address, address, int256, int256) external;
function fork(bytes32, address, address, int256, int256) external;
function grab(bytes32, address, address, address, int256, int256) external;
function heal(uint256) external;
function suck(address, address, uint256) external;
function fold(bytes32, address, int256) external;
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "istanbul",
"remappings": [
"ds-test/=lib/ds-auth/lib/ds-test/src/",
"ds-thing/=lib/ds-value/lib/ds-thing/src/",
"ds-value/=lib/ds-value/src/",
"forge-std/=lib/forge-std/src/",
"psm/=lib/psm/src/",
"ds-token/=lib/ds-token/src/",
"ds-auth/=lib/ds-auth/src/",
"erc4626-tests/=lib/erc4626-tests/",
"ds-math/=lib/ds-token/lib/ds-math/src/",
"ds-note/=lib/ds-value/lib/ds-thing/lib/ds-note/src/",
"usddv2/=lib/psm/lib/usddv2/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.