Verified contractExactAGPL-3.0-or-later
Sa003PsmOperatorActivationSpellBeta
Address0x7adeeec52d4659c982c98b626a43a112cff4afba
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- istanbul
- License
- AGPL-3.0-or-later
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,390,924
- Creation transaction
- 0xd4e0e8df89…26623e80d2
10 files
- src/spells/Sa003PsmOperatorActivationSpell-Beta.solmain15.46 KB
- operator/contracts/PsmOperator.sol12.24 KB
- operator/contracts/PsmOperatorSpell.sol3.05 KB
- src/interfaces/chainlog/ChainLogAbstract.sol420 B
- src/interfaces/dapp/DSTokenAbstract.sol1.34 KB
- src/interfaces/dss/GemJoinAbstract.sol700 B
- src/interfaces/dss/JugAbstract.sol777 B
- src/interfaces/dss/PsmAbstract.sol971 B
- src/interfaces/dss/SpotAbstract.sol763 B
- src/interfaces/dss/VatAbstract.sol1.75 KB
src/spells/Sa003PsmOperatorActivationSpell-Beta.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.26;
import {VatAbstract} from "../interfaces/dss/VatAbstract.sol";
import {JugAbstract} from "../interfaces/dss/JugAbstract.sol";
import {SpotAbstract} from "../interfaces/dss/SpotAbstract.sol";
import {GemJoinAbstract} from "../interfaces/dss/GemJoinAbstract.sol";
import {DSTokenAbstract} from "../interfaces/dapp/DSTokenAbstract.sol";
import {ChainLogAbstract} from "../interfaces/chainlog/ChainLogAbstract.sol";
import {PsmAbstract} from "../interfaces/dss/PsmAbstract.sol";
import {PsmOperator, OperatorPsmLike} from "../../operator/contracts/PsmOperator.sol";
import {OperatorPermissionLike} from "../../operator/contracts/PsmOperatorSpell.sol";
interface RwaLiquidationLike {
function wards(address) external returns (uint256);
function ilks(bytes32) external returns (string memory,address,uint48,uint48);
function rely(address) external;
function deny(address) external;
function init(bytes32, uint256, string calldata, uint48) external;
}
interface RwaInputConduitLike {
function usdd() external view returns(address);
function psm() external view returns(address);
function gem() external view returns(address);
function to() external view returns(address);
function mate(address usr) external;
function file(bytes32 what, address data) external;
}
interface RwaOutputConduitLike {
function usdd() external view returns(address);
function psm() external view returns(address);
function gem() external view returns(address);
function wards(address) external returns (uint256);
function can(address) external returns (uint256);
function rely(address) external;
function deny(address) external;
function hope(address) external;
function nope(address) external;
function bud(address) external returns (uint256);
function kiss(address) external;
function diss(address) external;
function pick(address) external;
function push() external;
function mate(address) external;
function hate(address) external;
function file(bytes32 what, address data) external;
}
interface RwaUrnLike {
function vat() external view returns(address);
function jug() external view returns(address);
function gemJoin() external view returns(address);
function usddJoin() external view returns(address);
function outputConduit() external view returns(address);
function hope(address) external;
}
interface RwaJarLike {
function vow() external view returns(address);
function usdd() external view returns(address);
function usddJoin() external view returns(address);
}
interface DSValueAbstract {
function peek() external view returns (bytes32, bool);
}
/// @notice Initialize Ethereum beta SA003-A and authorize its USDC PSM Operator.
/// @dev Deploy without arguments. Execute setup() through GovActionsProxy.execSpell.
/// Combines RwaEthSpellSA003 onboarding with PsmOperatorSpell permissions.
/// SA003 funding and locking are separate operations; this Spell never moves tokens.
contract Sa003PsmOperatorActivationSpellBeta {
bytes32 public constant ilk = "SA003-A";
bytes32 public constant PSM_ILK = "PSM-USDC-A";
uint256 internal constant WAD = 1e18;
uint256 internal constant RAY = 1e27;
uint256 internal constant RAD = 1e45;
ChainLogAbstract public constant CHAINLOG = ChainLogAbstract(0xAc266def6e633FA65745A718958469d3B72558B6);
address public constant MCD_PAUSE_PROXY = 0x045a1B4Cc48483F55E2D266a601b683Ed95aAA3C;
address public constant MCD_VAT = 0x62Ee80CB1E96B113B5aea31F1C6fcB9AE64fd453;
address public constant MCD_SPOT = 0xEc9cC5051B105B6131568c26eFa20724C02Ff02A;
address public constant MCD_JUG = 0xeB6f9eb259F86518524C7D9799B0e813368F3A04;
address public constant MCD_USDD = 0x8cF988aE191a6000E7c65079A46b087C7d984463;
address public constant MCD_JOIN_USDD = 0x506D1C1A826f94f74e78529dbbED01Cc55893dB8;
address public constant MCD_VOW = 0x7e3f8Ddd5D7e948BeaF4aA62BF00F46c1E6fAFAf;
address public constant PSM_GEM = 0x9D0cFFBA7116dCE88F35e4BDCB1e22e47048b275;
address public constant MCD_JOIN_PSM_USDC_A = 0x8AA5C3FFb718eF612748783c9f850F261Ad0Bcc9;
address public constant PSM = 0x879ccEF70B4ebE4fe57282533e95E4D0B10102CD;
address public constant PIP_PSM_USDC = 0x2315C629110a0013C9F5018CBE53E9FbAc531b93;
address public constant SA003_GEM = 0xFa2d372Af915119587dCBc682cCeaA7FfE6bfc27;
address public constant MCD_JOIN_SA003_A = 0x8a1a3C1fae7721FFa9CeF3b9031bC735Dd0C2EC7;
address public constant SA003_A_URN = 0x04e0DbbB140BA361bcEbAf600554c36F3BFED0d7;
address public constant SA003_A_JAR = 0xF465EAce1Dd838cC0b4a55217F85F824Bdb3015f;
address public constant SA003_A_INPUT_CONDUIT_URN = 0xF7953816c9E57AAd446adA1BBcbd1928858299d6;
address public constant SA003_A_INPUT_CONDUIT_JAR = 0x55D1C4046B6F787d6B698023ADC643a88f4Fbe2d;
address public constant SA003_A_OUTPUT_CONDUIT = 0x6433eadf313A0515dE75Ae91c32741e0F7e11b69;
address public constant LIQUIDATION_ORACLE = 0x73735E92e96B38355c52070d3613674740871552;
address public constant RWA_TOKEN_FACTORY = 0xD81629b29AADcD4F8309cD79F54dDa2eB45D022e;
address public constant RWA_URN_CLOSE_HELPER = 0x0292cB83A66a58dda813DaD3f8e659b1a3355feA;
address public constant PSM_OPERATOR = 0x50fbc0de8D4ce6D7f779002d8fF10d67AaF742F2;
address public constant SA003_OPERATOR = 0x09B1E13A3eB32F1064990B1Ab130492DA9D1E76E;
uint256 public constant SA003_A_INITIAL_PRICE = 400_000_000 * WAD;
uint256 public constant SA003_A_INITIAL_DC = 400_000_000 * RAD;
uint256 public constant SA003_A_RATE = RAY;
uint256 public constant SA003_A_MAT = RAY;
uint48 public constant SA003_A_REMEDIATION_PERIOD = 0;
string public constant SA003_DOC = "";
address public constant SA003_A_URN_CLOSE_HELPER = RWA_URN_CLOSE_HELPER;
uint256 public constant PSM_USDC_A_DC = 100_000_000 * RAD;
uint256 public constant PSM_USDC_A_FEE = 2 * WAD / 1000;
error WrongExecutionContext(address actual);
error InvalidConfiguration();
event WithdrawalConfigured(address indexed withdrawal, address indexed receiver);
// Immutable so delegatecall still records the Spell's own address in ChainLog.
address public immutable spellSelf = address(this);
function setup() external {
if (address(this) != MCD_PAUSE_PROXY) revert WrongExecutionContext(address(this));
// SA003-A collateral deploy
address SA003_USER = PsmOperator(PSM_OPERATOR).receiver();
// Sanity checks
require(GemJoinAbstract(MCD_JOIN_SA003_A).vat() == MCD_VAT, "join-vat-not-match");
require(GemJoinAbstract(MCD_JOIN_SA003_A).ilk() == ilk, "join-ilk-not-match");
require(GemJoinAbstract(MCD_JOIN_SA003_A).gem() == SA003_GEM, "join-gem-not-match");
require(GemJoinAbstract(MCD_JOIN_SA003_A).dec() == DSTokenAbstract(SA003_GEM).decimals(), "join-dec-not-match");
require(RwaUrnLike(SA003_A_URN).vat() == MCD_VAT, "urn-vat-not-match");
require(RwaUrnLike(SA003_A_URN).jug() == MCD_JUG, "urn-jug-not-match");
require(RwaUrnLike(SA003_A_URN).usddJoin() == MCD_JOIN_USDD, "urn-usddjoin-not-match");
require(RwaUrnLike(SA003_A_URN).gemJoin() == MCD_JOIN_SA003_A, "urn-gemjoin-not-match");
require(RwaUrnLike(SA003_A_URN).outputConduit() == SA003_A_OUTPUT_CONDUIT, "urn-outputconduit-not-match");
require(RwaJarLike(SA003_A_JAR).vow() == MCD_VOW, "jar-vow-not-match");
require(RwaJarLike(SA003_A_JAR).usdd() == MCD_USDD, "jar-usdd-not-match");
require(RwaJarLike(SA003_A_JAR).usddJoin() == MCD_JOIN_USDD, "jar-usddjoin-not-match");
require(RwaOutputConduitLike(SA003_A_OUTPUT_CONDUIT).usdd() == MCD_USDD, "output-conduit-usdd-not-match");
require(RwaOutputConduitLike(SA003_A_OUTPUT_CONDUIT).gem() == PSM_GEM, "output-conduit-gem-not-match");
require(RwaOutputConduitLike(SA003_A_OUTPUT_CONDUIT).psm() == PSM, "output-conduit-psm-not-match");
require(RwaInputConduitLike(SA003_A_INPUT_CONDUIT_URN).psm() == PSM, "input-conduit-urn-psm-not-match");
require(RwaInputConduitLike(SA003_A_INPUT_CONDUIT_URN).to() == SA003_A_URN, "input-conduit-urn-to-not-match");
require(RwaInputConduitLike(SA003_A_INPUT_CONDUIT_URN).usdd() == MCD_USDD, "input-conduit-urn-usdd-not-match");
require(RwaInputConduitLike(SA003_A_INPUT_CONDUIT_URN).gem() == PSM_GEM, "input-conduit-urn-gem-not-match");
require(RwaInputConduitLike(SA003_A_INPUT_CONDUIT_JAR).psm() == PSM, "input-conduit-jar-psm-not-match");
require(RwaInputConduitLike(SA003_A_INPUT_CONDUIT_JAR).to() == SA003_A_JAR, "input-conduit-jar-to-not-match");
require(RwaInputConduitLike(SA003_A_INPUT_CONDUIT_JAR).usdd() == MCD_USDD, "input-conduit-jar-usdd-not-match");
require(RwaInputConduitLike(SA003_A_INPUT_CONDUIT_JAR).gem() == PSM_GEM, "input-conduit-jar-gem-not-match");
// init the RwaLiquidationOracle
RwaLiquidationLike(LIQUIDATION_ORACLE).init(
ilk, SA003_A_INITIAL_PRICE, SA003_DOC, SA003_A_REMEDIATION_PERIOD
);
(,address pip,,) = RwaLiquidationLike(LIQUIDATION_ORACLE).ilks(ilk);
// Set price feed for SA003
SpotAbstract(MCD_SPOT).file(ilk, "pip", pip);
// Init SA-002 in Vat
VatAbstract(MCD_VAT).init(ilk);
// Init SA-002 in Jug
JugAbstract(MCD_JUG).init(ilk);
// Allow SA-002 Join to modify Vat registry
VatAbstract(MCD_VAT).rely(MCD_JOIN_SA003_A);
// The liquidation oracle already has Vat authority on mainnet.
// set the debt ceiling
VatAbstract(MCD_VAT).file(ilk, "line", SA003_A_INITIAL_DC);
VatAbstract(MCD_VAT).file("Line", VatAbstract(MCD_VAT).Line() + SA003_A_INITIAL_DC);
// No dust
// VatAbstract(MCD_VAT).file(ilk, "dust", 0)
// set the stability fee
JugAbstract(MCD_JUG).file(ilk, "duty", SA003_A_RATE);
// set the collateralization ratio
SpotAbstract(MCD_SPOT).file(ilk, "mat", SA003_A_MAT);
// poke the spotter to pull in a price
SpotAbstract(MCD_SPOT).poke(ilk);
// give the urn permissions on the join adapter
GemJoinAbstract(MCD_JOIN_SA003_A).rely(SA003_A_URN);
// set up the urn
RwaUrnLike(SA003_A_URN).hope(SA003_OPERATOR);
RwaUrnLike(SA003_A_URN).hope(SA003_A_URN_CLOSE_HELPER);
// set up output conduit
RwaOutputConduitLike(SA003_A_OUTPUT_CONDUIT).hope(SA003_OPERATOR);
RwaOutputConduitLike(SA003_A_OUTPUT_CONDUIT).mate(SA003_OPERATOR);
RwaOutputConduitLike(SA003_A_OUTPUT_CONDUIT).kiss(SA003_USER); // who can be picked as recipient address
RwaOutputConduitLike(SA003_A_OUTPUT_CONDUIT).file("quitTo", SA003_A_URN);
RwaInputConduitLike(SA003_A_INPUT_CONDUIT_URN).mate(SA003_OPERATOR);
RwaInputConduitLike(SA003_A_INPUT_CONDUIT_URN).file("quitTo", SA003_USER);
RwaInputConduitLike(SA003_A_INPUT_CONDUIT_JAR).mate(SA003_OPERATOR);
RwaInputConduitLike(SA003_A_INPUT_CONDUIT_JAR).file("quitTo", SA003_USER);
// add SA-002 contract to the ChainLog
CHAINLOG.setAddress("SA003", SA003_GEM);
CHAINLOG.setAddress("MCD_JOIN_SA003_A", MCD_JOIN_SA003_A);
CHAINLOG.setAddress("SA003_A_URN", SA003_A_URN);
CHAINLOG.setAddress("SA003_A_JAR", SA003_A_JAR);
CHAINLOG.setAddress("SA003_A_INPUT_CONDUIT_URN", SA003_A_INPUT_CONDUIT_URN);
CHAINLOG.setAddress("SA003_A_INPUT_CONDUIT_JAR", SA003_A_INPUT_CONDUIT_JAR);
CHAINLOG.setAddress("SA003_A_OUTPUT_CONDUIT", SA003_A_OUTPUT_CONDUIT);
CHAINLOG.setAddress("PIP_SA003", pip);
CHAINLOG.setAddress("SA003_A_URN_CLOSE_HELPER", RWA_URN_CLOSE_HELPER);
CHAINLOG.setVersion("1.3.8");
// USDC PSM parameters: keep the $1 price and adjust only the ceiling difference.
require(OperatorPsmLike(PSM).buyEnabled() == 1 && OperatorPsmLike(PSM).sellEnabled() == 1, "Sa003Spell/psm-disabled");
{
(bytes32 price, bool valid) = DSValueAbstract(PIP_PSM_USDC).peek();
require(valid && uint256(price) == WAD, "Sa003Spell/usdc-price-not-one");
(uint256 art, uint256 rate, uint256 spot, uint256 oldPsmLine,) = VatAbstract(MCD_VAT).ilks(PSM_ILK);
require(rate == RAY && spot == RAY, "Sa003Spell/psm-rate-or-spot");
require(art * rate <= PSM_USDC_A_DC, "Sa003Spell/psm-debt-above-line");
require(VatAbstract(MCD_VAT).Line() + PSM_USDC_A_DC >= oldPsmLine, "Sa003Spell/global-line-underflow");
require(
VatAbstract(MCD_VAT).Line() + PSM_USDC_A_DC - oldPsmLine >= VatAbstract(MCD_VAT).debt(),
"Sa003Spell/global-debt-above-line"
);
VatAbstract(MCD_VAT).file(PSM_ILK, "line", PSM_USDC_A_DC);
VatAbstract(MCD_VAT).file("Line", VatAbstract(MCD_VAT).Line() + PSM_USDC_A_DC - oldPsmLine);
}
PsmAbstract(PSM).file("tin", PSM_USDC_A_FEE);
PsmAbstract(PSM).file("tout", PSM_USDC_A_FEE);
// PsmOperatorSpell configuration, appended after SA003 onboarding.
PsmOperator withdrawal = PsmOperator(PSM_OPERATOR);
address psm = address(withdrawal.psm());
address rwaUrn = address(withdrawal.rwaUrn());
address outputConduit = address(withdrawal.outputConduit());
address inputConduit = address(withdrawal.inputConduit());
require(
psm == PSM && rwaUrn == SA003_A_URN && outputConduit == SA003_A_OUTPUT_CONDUIT,
"Sa003Spell/operator-not-match"
);
require(inputConduit == SA003_A_INPUT_CONDUIT_URN, "Sa003Spell/input-conduit-not-match");
if (withdrawal.rwaUrn().vat() != withdrawal.vat()
|| withdrawal.rwaUrn().outputConduit() != outputConduit
|| withdrawal.outputConduit().psm() != psm
|| withdrawal.outputConduit().gem() != address(withdrawal.gem())
|| withdrawal.psm().gemJoin() != withdrawal.gemJoin()
|| withdrawal.inputConduit().psm() != psm
|| withdrawal.inputConduit().gem() != address(withdrawal.gem())
|| withdrawal.inputConduit().usdd() != withdrawal.psm().usdd()
|| withdrawal.inputConduit().to() != rwaUrn) revert InvalidConfiguration();
address account = address(withdrawal);
address receiver = withdrawal.receiver();
OperatorPermissionLike(psm).rely(account);
OperatorPermissionLike(rwaUrn).hope(account);
OperatorPermissionLike(outputConduit).hope(account);
OperatorPermissionLike(outputConduit).mate(account);
// kiss() is ward-only: receiver management grants broad Conduit administration.
OperatorPermissionLike(outputConduit).rely(account);
OperatorPermissionLike(outputConduit).kiss(receiver);
OperatorPermissionLike(inputConduit).mate(account);
emit WithdrawalConfigured(account, receiver);
CHAINLOG.setAddress("PSM_OPERATOR_SA003_A", PSM_OPERATOR);
CHAINLOG.setAddress("PSM_OPERATOR_SPELL_SA003_A", spellSelf);
}
}
operator/contracts/PsmOperator.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface OperatorPsmLike {
function vat() external view returns (address);
function ilk() external view returns (bytes32);
function gemJoin() external view returns (address);
function buyEnabled() external view returns (uint256);
function tout() external view returns (uint256);
function tin() external view returns (uint256);
function sellEnabled() external view returns (uint256);
function usdd() external view returns (address);
function file(bytes32 what, uint256 value) external;
}
interface OperatorVatLike {
function urns(bytes32 ilk, address urn) external view returns (uint256 ink, uint256 art);
}
interface OperatorJoinLike {
function gem() external view returns (address);
function dec() external view returns (uint256);
}
interface OperatorTokenLike {
function balanceOf(address account) external view returns (uint256);
}
interface OperatorRwaUrnLike {
function vat() external view returns (address);
function outputConduit() external view returns (address);
function draw(uint256 wad) external;
function usddJoin() external view returns (address);
function wipe(uint256 wad) external;
}
interface OperatorUsddJoinLike {
function usdd() external view returns (address);
function vat() external view returns (address);
}
interface OperatorOutputConduitLike {
function psm() external view returns (address);
function gem() external view returns (address);
function requiredUsddWad(uint256 amount) external view returns (uint256);
function expectedGemAmt(uint256 wad) external view returns (uint256);
function pick(address receiver) external;
function push(uint256 wad) external;
function kiss(address receiver) external;
function bud(address receiver) external view returns (uint256);
}
interface OperatorInputConduitLike {
function psm() external view returns (address);
function gem() external view returns (address);
function usdd() external view returns (address);
function to() external view returns (address);
function push(uint256 amount) external;
}
/// @notice Withdraw collateral or return it to PSM and repay the bound RWA vault.
/// @dev Receiver management requires OutputConduit ward. Never changes buy/sell switches.
contract PsmOperator {
OperatorPsmLike public immutable psm;
OperatorRwaUrnLike public immutable rwaUrn;
OperatorOutputConduitLike public immutable outputConduit;
OperatorInputConduitLike public immutable inputConduit;
address public immutable vat;
address public immutable gemJoin;
OperatorTokenLike public immutable gem;
uint256 public immutable to18ConversionFactor;
address public receiver;
mapping(address => uint256) public wards;
bool private entered;
error InvalidAddress(address account);
error InvalidConfiguration();
error NotAuthorized(address account);
error ReentrantCall();
error BuyDisabled();
error InvalidAmount();
error UnexpectedWithdrawalAmount();
error FeeNotRestored();
error SellDisabled();
error UnexpectedRepaymentAmount();
error TokenCallFailed();
event Rely(address indexed account);
event Deny(address indexed account);
event ReceiverUpdated(address indexed previousReceiver, address indexed newReceiver);
event Withdrawn(address indexed receiver, uint256 gemAmount, uint256 usddDrawn, uint256 restoredTout);
event Repaid(address indexed rwaUrn, uint256 gemAmount, uint256 usddRepaid, uint256 restoredTin);
event TokenRecovered(address indexed token, address indexed receiver, uint256 amount);
constructor(address psm_, address rwaUrn_, address inputConduit_, address receiver_, address operator_) {
if (psm_.code.length == 0) revert InvalidAddress(psm_);
if (rwaUrn_.code.length == 0) revert InvalidAddress(rwaUrn_);
if (operator_ == address(0)) revert InvalidAddress(operator_);
psm = OperatorPsmLike(psm_);
rwaUrn = OperatorRwaUrnLike(rwaUrn_);
vat = psm.vat();
if (vat.code.length == 0) revert InvalidAddress(vat);
gemJoin = psm.gemJoin();
if (gemJoin.code.length == 0) revert InvalidAddress(gemJoin);
address token = OperatorJoinLike(gemJoin).gem();
if (token.code.length == 0) revert InvalidAddress(token);
gem = OperatorTokenLike(token);
uint256 decimals = OperatorJoinLike(gemJoin).dec();
if (decimals > 18) revert InvalidConfiguration();
to18ConversionFactor = 10 ** (18 - decimals);
address conduit = rwaUrn.outputConduit();
if (conduit.code.length == 0) revert InvalidAddress(conduit);
outputConduit = OperatorOutputConduitLike(conduit);
if (inputConduit_.code.length == 0) revert InvalidAddress(inputConduit_);
inputConduit = OperatorInputConduitLike(inputConduit_);
_checkWithdrawConfiguration();
_checkRepayConfiguration();
_setReceiver(receiver_);
wards[operator_] = 1;
emit Rely(operator_);
}
modifier auth() {
if (wards[msg.sender] != 1) revert NotAuthorized(msg.sender);
_;
}
modifier nonReentrant() {
if (entered) revert ReentrantCall();
entered = true;
_;
entered = false;
}
function rely(address account) external auth {
if (account == address(0)) revert InvalidAddress(account);
wards[account] = 1;
emit Rely(account);
}
function deny(address account) external auth {
wards[account] = 0;
emit Deny(account);
}
function setReceiver(address receiver_) external auth nonReentrant {
_checkWithdrawConfiguration();
_setReceiver(receiver_);
outputConduit.kiss(receiver_);
if (outputConduit.bud(receiver_) != 1) revert InvalidConfiguration();
}
function _setReceiver(address receiver_) private {
if (receiver_ == address(0) || receiver_ == address(this) || receiver_ == gemJoin || receiver_ == address(psm)) revert InvalidAddress(receiver_);
emit ReceiverUpdated(receiver, receiver_);
receiver = receiver_;
}
/// @dev Validate dependencies used by withdrawals and receiver management.
function _checkWithdrawConfiguration() private view {
if (rwaUrn.vat() != vat || psm.gemJoin() != gemJoin) revert InvalidConfiguration();
if (rwaUrn.outputConduit() != address(outputConduit)
|| outputConduit.psm() != address(psm)
|| outputConduit.gem() != address(gem)) revert InvalidConfiguration();
}
/// @dev Validate dependencies used by repayments, independently of OutputConduit.
function _checkRepayConfiguration() private view {
if (rwaUrn.vat() != vat || psm.gemJoin() != gemJoin) revert InvalidConfiguration();
address usdd = psm.usdd();
address usddJoin = rwaUrn.usddJoin();
if (inputConduit.psm() != address(psm) || inputConduit.gem() != address(gem)
|| inputConduit.usdd() != usdd || inputConduit.to() != address(rwaUrn)
|| usdd.code.length == 0 || usddJoin.code.length == 0
|| OperatorUsddJoinLike(usddJoin).usdd() != usdd
|| OperatorUsddJoinLike(usddJoin).vat() != vat) revert InvalidConfiguration();
}
/// @notice Reserve-side withdrawal limit in collateral raw units, not a guarantee of execution.
/// @dev Other constraints, including RWA debt headroom and permissions, still apply.
function maxWithdrawAmount() external view returns (uint256) {
_checkWithdrawConfiguration();
return _withdrawLimit(gem.balanceOf(gemJoin));
}
function _withdrawLimit(uint256 joinBalance) private view returns (uint256) {
(uint256 ink,) = OperatorVatLike(vat).urns(psm.ilk(), address(psm));
uint256 accountedBalance = ink / to18ConversionFactor;
return accountedBalance < joinBalance ? accountedBalance : joinBalance;
}
/// @param amount Collateral raw units: e.g. 100 USDC = 100 * 10**6.
function withdraw(uint256 amount) external auth nonReentrant {
_checkWithdrawConfiguration();
if (psm.buyEnabled() != 1) revert BuyDisabled();
uint256 joinBalance = gem.balanceOf(gemJoin);
if (amount == 0 || amount > _withdrawLimit(joinBalance)) revert InvalidAmount();
address recipient = receiver;
uint256 receiverBalance = gem.balanceOf(recipient);
uint256 previousTout = psm.tout();
if (previousTout != 0) psm.file("tout", 0);
if (psm.tout() != 0) revert InvalidConfiguration();
uint256 wad = amount * to18ConversionFactor;
if (outputConduit.requiredUsddWad(amount) != wad || outputConduit.expectedGemAmt(wad) != amount) {
revert UnexpectedWithdrawalAmount();
}
rwaUrn.draw(wad);
outputConduit.pick(recipient);
outputConduit.push(wad);
if (previousTout != 0) psm.file("tout", previousTout);
if (psm.tout() != previousTout) revert FeeNotRestored();
if (gem.balanceOf(gemJoin) != joinBalance - amount || gem.balanceOf(recipient) != receiverBalance + amount) {
revert UnexpectedWithdrawalAmount();
}
emit Withdrawn(recipient, amount, wad, previousTout);
}
/// @notice Return collateral already funded to InputConduit and repay the corresponding USDD amount.
/// @dev Does not promise to clear accrued interest or all normalized debt. Excess repayment reverts in RwaUrn2.
function repay(uint256 amount) external auth nonReentrant {
_checkRepayConfiguration();
if (psm.sellEnabled() != 1) revert SellDisabled();
uint256 balance = gem.balanceOf(address(inputConduit));
if (amount == 0 || amount > balance) revert InvalidAmount();
address usdd = psm.usdd();
uint256 joinBalance = gem.balanceOf(gemJoin);
uint256 urnBalance = OperatorTokenLike(usdd).balanceOf(address(rwaUrn));
uint256 wad = amount * to18ConversionFactor;
uint256 previousTin = psm.tin();
if (previousTin != 0) psm.file("tin", 0);
if (psm.tin() != 0) revert InvalidConfiguration();
// InputConduit owns the collateral and maintains its own GemJoin allowance.
inputConduit.push(amount);
if (gem.balanceOf(address(inputConduit)) != balance - amount || gem.balanceOf(gemJoin) != joinBalance + amount
|| OperatorTokenLike(usdd).balanceOf(address(rwaUrn)) != urnBalance + wad) revert UnexpectedRepaymentAmount();
rwaUrn.wipe(wad);
if (OperatorTokenLike(usdd).balanceOf(address(rwaUrn)) != urnBalance) revert UnexpectedRepaymentAmount();
if (previousTin != 0) psm.file("tin", previousTin);
if (psm.tin() != previousTin) revert FeeNotRestored();
emit Repaid(address(rwaUrn), amount, wad, previousTin);
}
/// @notice Recover tokens held by this contract to the configured receiver.
/// @dev Does not withdraw PSM reserves or repay RWA debt. No per-depositor accounting.
function recoverToken(address token, uint256 amount) external auth nonReentrant {
if (token.code.length == 0) revert InvalidAddress(token);
if (amount == 0 || amount > OperatorTokenLike(token).balanceOf(address(this))) revert InvalidAmount();
address recipient = receiver;
_callToken(token, abi.encodeWithSignature("transfer(address,uint256)", recipient, amount));
emit TokenRecovered(token, recipient, amount);
}
function _callToken(address token, bytes memory data) private {
(bool ok, bytes memory result) = token.call(data);
if (!ok) {
if (result.length == 0) revert TokenCallFailed();
// Preserve the token's revert string, custom error or panic for callers.
assembly ("memory-safe") {
revert(add(result, 32), mload(result))
}
}
if (result.length != 0) {
if (result.length != 32) revert TokenCallFailed();
// Only the canonical ABI encoding of true is accepted.
if (abi.decode(result, (uint256)) != 1) revert TokenCallFailed();
}
}
}
operator/contracts/PsmOperatorSpell.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {PsmOperator} from "./PsmOperator.sol";
interface OperatorPermissionLike {
function rely(address account) external;
function hope(address account) external;
function mate(address account) external;
function kiss(address account) external;
}
/// @notice Grant withdrawal, repayment and receiver-management permissions.
/// @dev Execute setup() through GovActionsProxy.execSpell / DSPauseProxy delegatecall.
/// PauseProxy must already be a ward on PSM, RwaUrn2, OutputConduit and InputConduit.
/// No storage writes to the delegatecall context, and no Vat ward grant.
contract PsmOperatorSpell {
PsmOperator public immutable withdrawal;
address public immutable pauseProxy;
address public immutable psm;
address public immutable rwaUrn;
address public immutable outputConduit;
address public immutable inputConduit;
error InvalidAddress(address account);
error WrongExecutionContext(address actual);
error InvalidConfiguration();
event WithdrawalConfigured(address indexed withdrawal, address indexed receiver);
constructor(address withdrawal_, address pauseProxy_) {
if (withdrawal_.code.length == 0) revert InvalidAddress(withdrawal_);
if (pauseProxy_.code.length == 0) revert InvalidAddress(pauseProxy_);
withdrawal = PsmOperator(withdrawal_);
pauseProxy = pauseProxy_;
psm = address(withdrawal.psm());
rwaUrn = address(withdrawal.rwaUrn());
outputConduit = address(withdrawal.outputConduit());
inputConduit = address(withdrawal.inputConduit());
}
function setup() external {
if (address(this) != pauseProxy) revert WrongExecutionContext(address(this));
if (withdrawal.rwaUrn().vat() != withdrawal.vat()
|| withdrawal.rwaUrn().outputConduit() != outputConduit
|| withdrawal.outputConduit().psm() != psm
|| withdrawal.outputConduit().gem() != address(withdrawal.gem())
|| withdrawal.psm().gemJoin() != withdrawal.gemJoin()
|| withdrawal.inputConduit().psm() != psm
|| withdrawal.inputConduit().gem() != address(withdrawal.gem())
|| withdrawal.inputConduit().usdd() != withdrawal.psm().usdd()
|| withdrawal.inputConduit().to() != rwaUrn) revert InvalidConfiguration();
address account = address(withdrawal);
address receiver = withdrawal.receiver();
OperatorPermissionLike(psm).rely(account);
OperatorPermissionLike(rwaUrn).hope(account);
OperatorPermissionLike(outputConduit).hope(account);
OperatorPermissionLike(outputConduit).mate(account);
// kiss() is ward-only: receiver management grants broad Conduit administration.
OperatorPermissionLike(outputConduit).rely(account);
OperatorPermissionLike(outputConduit).kiss(receiver);
OperatorPermissionLike(inputConduit).mate(account);
emit WithdrawalConfigured(account, receiver);
}
}
src/interfaces/chainlog/ChainLogAbstract.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.5.12;
interface ChainLogAbstract {
function setVersion(string calldata) external;
function setIPFS(string calldata) external;
function setSha256sum(string calldata) external;
function getAddress(bytes32) external view returns (address);
function setAddress(bytes32, address) external;
function removeAddress(bytes32) external;
}
src/interfaces/dapp/DSTokenAbstract.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.5.12;
// https://github.com/dapphub/ds-token/blob/master/src/token.sol
interface DSTokenAbstract {
function name() external view returns (bytes32);
function symbol() external view returns (bytes32);
function decimals() external view returns (uint256);
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
function transfer(address, uint256) external returns (bool);
function allowance(address, address) external view returns (uint256);
function approve(address, uint256) external returns (bool);
function approve(address) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function push(address, uint256) external;
function pull(address, uint256) external;
function move(address, address, uint256) external;
function mint(uint256) external;
function mint(address,uint) external;
function burn(uint256) external;
function burn(address,uint) external;
function setName(bytes32) external;
function authority() external view returns (address);
function owner() external view returns (address);
function setOwner(address) external;
function setAuthority(address) external;
}
src/interfaces/dss/GemJoinAbstract.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 GemJoinAbstract {
function wards(address) external view returns (uint256);
function rely(address) external;
function deny(address) external;
function vat() external view returns (address);
function ilk() external view returns (bytes32);
function gem() external view returns (address);
function dec() external view returns (uint256);
function live() external view returns (uint256);
function cage() external;
function join(address, uint256) external;
function exit(address, uint256) external;
}
src/interfaces/dss/JugAbstract.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/jug.sol
interface JugAbstract {
function wards(address) external view returns (uint256);
function rely(address) external;
function deny(address) external;
function ilks(bytes32) external view returns (uint256, uint256);
function vat() external view returns (address);
function vow() external view returns (address);
function base() external view returns (uint256);
function init(bytes32) external;
function file(bytes32, bytes32, uint256) external;
function file(bytes32, uint256) external;
function file(bytes32, address) external;
function drip(bytes32) external returns (uint256);
}
src/interfaces/dss/PsmAbstract.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.5.12;
// https://github.com/usdd-network/psm/blob/main/src/psm.sol
interface PsmAbstract {
function wards(address) external view returns (uint256);
function rely(address) external;
function deny(address) external;
function vat() external view returns (address);
function gemJoin() external view returns (address);
function usdd() external view returns (address);
function usddJoin() external view returns (address);
function ilk() external view returns (bytes32);
function vow() external view returns (address);
function tin() external view returns (uint256);
function tout() external view returns (uint256);
function file(bytes32 what, uint256 data) external;
function hope(address) external;
function nope(address) external;
function sellGem(address usr, uint256 gemAmt) external;
function buyGem(address usr, uint256 gemAmt) external;
}
src/interfaces/dss/SpotAbstract.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/spot.sol
interface SpotAbstract {
function wards(address) external view returns (uint256);
function rely(address) external;
function deny(address) external;
function ilks(bytes32) external view returns (address, uint256);
function vat() external view returns (address);
function par() external view returns (uint256);
function live() external view returns (uint256);
function file(bytes32, bytes32, address) external;
function file(bytes32, uint256) external;
function file(bytes32, bytes32, uint256) external;
function poke(bytes32) external;
function cage() external;
}
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
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "istanbul"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.