1413字约5分钟
2024-05-22
TreasuryVault是一个智能合约,用于管理资金的存入、铸造代币、销毁代币以及债务管理。用户可以通过存入ETH来铸造相应的YETH和PT代币,也可以通过销毁这些代币来提取ETH。此外,合约还支持管理借款和还款功能。
sellFee
:出售代币时的手续费比例。buyFee
:购买代币时的手续费比例。feeTo
:手续费收入接收地址。total
:合约内部使用的变量,具体作用未在文档中说明。totalDebt
:累计债务金额。totalRepay
:累计还款金额。PToken
:PT代币的地址。YToken
:YETH代币的地址。BaseRate
:基础兑换比例,ETH与PT/YETH的兑换基数。Deposit
:当用户存入ETH并铸造代币时触发。Withdrawal
:当用户销毁代币并提取ETH时触发。Borrow
:当管理员执行借款操作时触发。Repayment
:当管理员执行还款操作时触发。initialize(address _ptoken, address _ytoken)
:初始化合约,设置PT和YETH代币的地址。deposit(uint8 _type)
:用户存入ETH并根据_type铸造YETH和PT代币。_type为1时,铸造500YETH和500PT;为2时,铸造1000PT。withdraw(uint wad)
:用户销毁YETH和PT代币来提取ETH。borrow(uint256 _amount)
:管理员从合约中借用指定金额的资金。repayment()
:管理员执行还款操作,增加合约的资金。updateSellFee(uint256 _sellFee)
:更新出售代币的手续费比例。updateBuyFee(uint256 _buyFee)
:更新购买代币的手续费比例。updateFeeTo(address _feeTo)
:更新手续费收入接收地址。updatePT(address _pt)
:更新PT代币的地址。updateYT(address _yt)
:更新YETH代币的地址。updateBaseRate(uint256 _base)
:更新基础兑换比例。totalSupply()
:返回合约的总供应量。balance()
:返回合约的ETH余额。ManagerUpgradeable
和PausableUpgradeable
,支持权限管理和升级功能。SafeMath
库来防止整数溢出。pragma solidity >=0.6.12;
interface ISETH {
/**
@dev 用户质押事件
@param from 质押地址
@param value 质押金额
*/
event Deposit(address indexed from, uint value);
/**
@dev 用户取款事件
@param from 取款地址
@param value 取款金额
*/
event Withdrawal(address indexed from, uint value);
/**
@dev 用户支付eth铸造 yeth或者pt
@param _type 铸造类型,1:1eth=1 YETH + 1000 PT 2:1 ETH = 2000 PT
*/
function deposit(uint8 _type) external payable;
/**
@dev 取款,用户将1yt+1000pt销毁,获取1ETH 【whenNotPaused】
@param wad 取款金额
@notice 支持收费,不需要对 yt 和 pt 进行授权, 只校验资产即可
*/
function withdraw(uint wad) external;
/**
@dev 解除/出售 手续费
*/
function sellFee() external view returns (uint256);
/**
@dev 质押/购买 手续费
*/
function buyFee() external view returns (uint256);
/**
@dev 手续费地址
*/
function feeTo() external view returns (address);
/**
@dev 设置 出售/解除质押 手续费百分比,整数百分比,10为10%
*/
function updateSellFee(uint256 _fee) external;
/**
@dev 设置 质押/购买 手续费百分比,整数百分比,10为10%
*/
function updateBuyFee(uint256 _fee) external;
/**
@dev 设置手续费地址
*/
function updateFeeTo(address _to) external;
function updatePT(address _pt) external;
function updateYT(address _yt) external;
function updateBaseRate(uint256 _base) external;
// -------------- 合约操作
/**
@dev 指定地址可以借用
*/
function borrow(uint256 _amount) external;
/**
@dev 指定地址可以还款
*/
function repayment() external payable;
/**
@dev 当前债务总额度
*/
function totalDebt() external view returns (uint256);
/**
@dev 累计还款金额,会出现入账大于出账的情况,属于正常
*/
function totalRepay() external view returns (uint256);
/**
@dev 当前质押eth累计总额度
*/
function totalDeposit() external view returns (uint256);
/**
@dev 当前取款eth累计总额度
*/
function totalWithdraw() external view returns (uint256);
}
{
"_format": "hh-sol-artifact-1",
"contractName": "IVault",
"sourceName": "contracts/interface/ISETHVault.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "src",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "wad",
"type": "uint256"
}
],
"name": "Borrow",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "src",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "wad",
"type": "uint256"
}
],
"name": "Repayment",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Withdrawal",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
}
],
"name": "borrow",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "buyFee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint8",
"name": "_type",
"type": "uint8"
}
],
"name": "deposit",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "feeTo",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_manager",
"type": "address"
}
],
"name": "removeManager",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "repayment",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "sellFee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_manager",
"type": "address"
}
],
"name": "setManager",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "totalDebt",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalDeposit",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalRepay",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalWithdraw",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_base",
"type": "uint256"
}
],
"name": "updateBaseRate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_fee",
"type": "uint256"
}
],
"name": "updateBuyFee",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_to",
"type": "address"
}
],
"name": "updateFeeTo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_pt",
"type": "address"
}
],
"name": "updatePT",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_fee",
"type": "uint256"
}
],
"name": "updateSellFee",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_yt",
"type": "address"
}
],
"name": "updateYT",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "wad",
"type": "uint256"
}
],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}