pragma solidity >=0.5.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
pragma solidity =0.6.6;
import "./libraries/chainlink/AggregatorV3Interface.sol";
import './libraries/IERC20.sol';
import './libraries/SafeMath.sol';
import './libraries/TransferHelper.sol';
contract DFBTCV1Factory {
using SafeMath for uint256;
//*************************POOL Begin************************
struct Pools {
address _coinAddress;
uint _minAmounts;
uint _decimalAmount;
}
address[] public poolAddressList;
mapping(address => Pools) public poolmap;
mapping(address => address) public priceFeedmap;
//*************************POOL End**************************
//*************************User Begin************************
struct User {
address _eth;
uint _startTime;
uint _pledgeCycle;
uint _curBTC;
//uint _btcVal;
string _btc;
bool _bReceive;
//bool _Receive;
bool _bExist;
}
address[] public guarantorList;
mapping(address => User) public guarantUserMap;
mapping(address => mapping(address => uint)) public userAssets;//用户资产
event e_userTransfer_records(address indexed _eth, address indexed _coin, uint _amount, uint _addtime);
//*************************User End**************************
//************************Order Begin************************
struct dfbtcOrderClass {
address _from;
address _to;
string _toBTC;
uint _btcAmount;
uint _dfbtcAmount;
uint _createTime;
uint _type;
bool _bExist;
}
mapping(address => dfbtcOrderClass) public dfbtcOrder;
event e_dfbtc_order(address indexed _from, address indexed _to, uint indexed _type, string _toBTC, uint _btcAmount, uint _dfbtcAmount, uint _createTime, uint _status);
//************************Order End**************************
mapping(uint=>bool) public cycle;
uint public btcToDfbtc = 10000;
address public btcPriceFeed = 0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c;
address public aomAddress = 0x060924FB947e37EEE230d0B1A71D9618aEc269fC;
address public ethAddress = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address public dfbtcAddress = 0x67C8d54F38369571AAe70183b8568494032b5D7C;
address public onwer;
address public coo;
address public feeAddress = address(0);
uint public fee = 0;
uint public ETHAPY = 16;
uint public TokenAPY = 9;
uint public btcVal = 0;
modifier onlyOnwer {
require(onwer == msg.sender, "dfbtc: The caller must be onwer!!!");
_;
}
function setAPY(uint ethA, uint tokenA) public onlyOnwer returns (bool) {
ETHAPY = ethA;
TokenAPY = tokenA;
return true;
}
constructor() public {
onwer = msg.sender;
coo = msg.sender;
cycle[30] = true;//30);
cycle[90] = true;
cycle[180] = true;
cycle[360] = true;
addPoolSet(aomAddress, 10000e18, 1);
addPoolSet(ethAddress, 0, 1);
addPoolSet(0xdAC17F958D2ee523a2206206994597C13D831ec7, 0, 1e12);//usdt
addPoolSet(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, 0, 1e12);//usdc
addPoolSet(0x6B175474E89094C44Da98b954EedeAC495271d0F, 0, 1);//dai
initPriceFeedmap(ethAddress, 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
initPriceFeedmap(0xdAC17F958D2ee523a2206206994597C13D831ec7, 0x3E7d1eAB13ad0104d2750B8863b489D65364e32D);
initPriceFeedmap(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, 0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6);
initPriceFeedmap(0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xAed0c38402a5d19df6E4c03F4E2DceD6e29c1ee9);
}
//*************************POOL Begin************************
function getPoolsLength() public view returns (uint) {
return poolAddressList.length;
}
function getPoollist() public view returns (address[] memory){
return poolAddressList;
}
function addPoolSet(address _cAddress, uint _minVal, uint _deimalVal) public onlyOnwer returns (bool) {
Pools memory _tp = Pools({
_coinAddress : _cAddress,
_minAmounts : _minVal,
_decimalAmount : _deimalVal
});
poolAddressList.push(_cAddress);
poolmap[_cAddress] = _tp;
return true;
}
function editPoolset(address _cAddress, uint _minVal, uint _decimalVal) public onlyOnwer returns (bool) {
poolmap[_cAddress]._minAmounts = _minVal;
poolmap[_cAddress]._decimalAmount = _decimalVal;
return true;
}
function initPriceFeedmap(address tokenAddress, address priceAddress) public onlyOnwer returns (bool){
priceFeedmap[tokenAddress] = priceAddress;
return true;
}
//*************************POOL End************************
//*************************USER Begin************************
function getGuarantUserCount() public view returns (uint) {
return guarantorList.length;
}
function getUserCanGetBTCAmount(address user) public view returns (uint) {
uint totalprice = 0;
for(uint i=0; i<poolAddressList.length; i++){
uint uerAssets = userAssets[poolAddressList[i]][user];
if(poolAddressList[i]!=aomAddress && uerAssets > 0){
totalprice = uerAssets.mul(getThePrice(poolAddressList[i])).mul(poolmap[poolAddressList[i]]._decimalAmount).add(totalprice);
}
}
return totalprice.mul(10).div(getThePrice(btcPriceFeed)).div(15);
}
function liquidationAssets(address user) public onlyOnwer {
require(getUserCanGetBTCAmount(user)<guarantUserMap[user]._curBTC, "dfbtc: The node assets are abundant!!!");
for(uint i=0; i<poolAddressList.length; i++){
uint uerAssets = userAssets[poolAddressList[i]][user];
if(uerAssets > 0){
if(isETH(poolAddressList[i])){
msg.sender.transfer(uerAssets);
}else{
TransferHelper.safeTransfer(poolAddressList[i], coo, uerAssets);
}
userAssets[poolAddressList[i]][user] = 0;
}
}
}
function addTokenToPools(address[] memory _tokenList, uint[] memory _valueList, uint ethvalue) private returns (uint) {
uint totalprice = 0;
for(uint i=0; i<_tokenList.length; i++){
require(IERC20(_tokenList[i]).balanceOf(msg.sender)>=_valueList[i], "dfbtc: Insufficient quantity!!!");
require(IERC20(_tokenList[i]).allowance(msg.sender, address(this))>=_valueList[i], "dfbtc: There are not enough authorizations!!!");
require(_valueList[i]>=poolmap[_tokenList[i]]._minAmounts, "dfbtc: Must be greater than the minimum value!!!");
if(_valueList[i]>0){
TransferHelper.safeTransferFrom(_tokenList[i], msg.sender, address(this), _valueList[i]);
userAssets[_tokenList[i]][msg.sender] = _valueList[i].add(userAssets[_tokenList[i]][msg.sender]);
emit e_userTransfer_records(msg.sender, _tokenList[i], _valueList[i], now);
if(_tokenList[i]!=aomAddress){
totalprice = _valueList[i].mul(getThePrice(_tokenList[i])).mul(poolmap[_tokenList[i]]._decimalAmount).add(totalprice);
}
}
}
if(ethvalue>0){
userAssets[ethAddress][msg.sender] = ethvalue.add(userAssets[ethAddress][msg.sender]);
emit e_userTransfer_records(msg.sender, ethAddress, ethvalue, now);
totalprice = ethvalue.mul(getThePrice(ethAddress)).mul(poolmap[ethAddress]._decimalAmount).add(totalprice);
}
return totalprice.div(getThePrice(btcPriceFeed));
}
function addGuarantorNode(address[] memory _tokenList, uint[] memory _valueList, uint _pledgeCycle, string memory _btcAddress) public payable returns (bool){
require(_tokenList.length>0, "dfbtc: Array length must be greater than 0!!!");
require(_tokenList.length==_valueList.length, "dfbtc: Array length must be equal!!!");
require(cycle[_pledgeCycle], "dfbtc: The period value is not within the set range!");
require(!guarantUserMap[msg.sender]._bExist, "dfbtc: Guarantor already exists!");
uint btcVal_ = addTokenToPools(_tokenList, _valueList, msg.value);
User memory _user = User({
_eth : msg.sender,
_startTime : now,
_pledgeCycle : _pledgeCycle*1 days,
_curBTC : 0,
_btc : _btcAddress,
_bReceive : true,
_bExist : true
});
guarantorList.push(msg.sender);
guarantUserMap[msg.sender] = _user;
IERC20(dfbtcAddress).mint(address(this), uint(btcVal_).mul(btcToDfbtc));
return true;
}
function addGuarantorNodeAssets(address[] memory _tokenList, uint[] memory _valueList) public payable returns (bool) {
require(guarantUserMap[msg.sender]._bExist, "dfbtc: Guarantor not exists!!!");
require(_tokenList.length>0, "dfbtc: Array length must be greater than 0!!!");
require(_tokenList.length==_valueList.length, "dfbtc: Array length must be equal!!!");
uint btcVal_ = addTokenToPools(_tokenList, _valueList, msg.value);
//guarantUserMap[msg.sender]._btcVal = btcVal_;
IERC20(dfbtcAddress).mint(address(this), uint(btcVal_).mul(btcToDfbtc));
return true;
}
function redeemAssets(address tokenAddress) public returns(bool){
require(guarantUserMap[msg.sender]._bExist, "dfbtc: Guarantor not exists!!!");
require(!dfbtcOrder[msg.sender]._bExist, "dfbtc: Order exists!!!");
require(guarantUserMap[msg.sender]._curBTC==0, "dfbtc: There is currently btc in custody!!!");
require(now >= (guarantUserMap[msg.sender]._startTime.sub(guarantUserMap[msg.sender]._pledgeCycle)), "dfbtc: There is currently btc in custody!!!");
require(userAssets[tokenAddress][msg.sender] > 0, "dfbtc: Your assets is zero!!!");
if(isETH(tokenAddress)){
msg.sender.transfer(userAssets[tokenAddress][msg.sender].add(userAssets[tokenAddress][msg.sender].mul(ETHAPY).div(100)));
}else{
TransferHelper.safeTransfer(tokenAddress, msg.sender, userAssets[tokenAddress][msg.sender].add(userAssets[tokenAddress][msg.sender].mul(TokenAPY).div(100)));
}
uint totalprice = getThePrice(tokenAddress).mul(userAssets[tokenAddress][msg.sender]);
IERC20(dfbtcAddress).burn(totalprice.div(getThePrice(btcPriceFeed)).mul(btcToDfbtc));
return true;
}
//*************************USER End************************
function safeTransferToOtherPools(address tokenAddress, address toAdddress, uint transferValue) public {
require((onwer == msg.sender || coo == msg.sender), "dfbtc: You are not owner!!!");
if(isETH(tokenAddress)){
address(uint160(toAdddress)).transfer(transferValue);
}else{
TransferHelper.safeTransfer(tokenAddress, toAdddress, transferValue);
}
}
//***********************Order Start***********************
function getGuarantorUserForOrder(address _usera, uint btcAmount, bool bBurn) public view returns (address, string memory){
address retVal = address(0);
string memory btcA = "";
for(uint i=0; i<guarantorList.length; i++){
if(_usera!= guarantorList[i]){
if((!dfbtcOrder[guarantorList[i]]._bExist) || (now >= (dfbtcOrder[msg.sender]._createTime + 1 days))){
if(bBurn){
if(guarantUserMap[guarantorList[i]]._curBTC>=btcAmount){
retVal = guarantorList[i];
btcA = guarantUserMap[guarantorList[i]]._btc;
break;
}
}else{
if((getUserCanGetBTCAmount(guarantorList[i]).sub(guarantUserMap[guarantorList[i]]._curBTC))>=btcAmount){
retVal = guarantorList[i];
btcA = guarantUserMap[guarantorList[i]]._btc;
break;
}
}
}
}
}
return (retVal, btcA);
}
function createTransferBTCOrder(address _gua) public {
require(guarantUserMap[_gua]._bExist, "dfbtc: Guarantor not exist!!!");
require(msg.sender!=_gua, "dfbtc: Can't be the same person!!!");
if(dfbtcOrder[msg.sender]._bExist){
require(now >= (dfbtcOrder[msg.sender]._createTime + 1 days), "dfbtc: Time more than 1 days!!!");
}
if(dfbtcOrder[_gua]._bExist){
require(now >= (dfbtcOrder[_gua]._createTime + 1 days), "dfbtc: Time more than 1 days!!!");
}
require(guarantUserMap[msg.sender]._bExist, "dfbtc: You are not guarantor!!!");
require(guarantUserMap[msg.sender]._curBTC>0, "dfbtc: You has not BTC!!!");
require((getUserCanGetBTCAmount(_gua).sub(guarantUserMap[_gua]._curBTC))>=guarantUserMap[msg.sender]._curBTC, "dfbtc: Guarantor has not enough assets!!!");
dfbtcOrderClass memory _order = dfbtcOrderClass({
_from : msg.sender,
_to : _gua,
_toBTC : guarantUserMap[_gua]._btc,
_btcAmount : guarantUserMap[msg.sender]._curBTC,
_dfbtcAmount : 0,
_createTime : now,
_type : 3,
_bExist : true
});
dfbtcOrder[_gua] = _order;
dfbtcOrder[msg.sender] = _order;
emit e_dfbtc_order(msg.sender, _gua, 3, _order._toBTC, _order._btcAmount, _order._dfbtcAmount, _order._createTime, 1);
}
function confirmTransferOrderSuccess(address guarant) public {
require((onwer == msg.sender || coo == msg.sender), "dfbtc: You are not owner!!!");
require(guarantUserMap[guarant]._bExist, "dfbtc: Guarantor not exists!");
require(dfbtcOrder[guarant]._bExist, "dfbtc: Order not exists!");
require(dfbtcOrder[guarant]._to==guarant, "dfbtc: The user are not guarantor of this order!");
require(dfbtcOrder[guarant]._type==3, "dfbtc: The type of order is not 1!");
dfbtcOrder[guarant]._bExist = false;
dfbtcOrder[dfbtcOrder[guarant]._from]._bExist = false;
guarantUserMap[guarant]._curBTC = guarantUserMap[guarant]._curBTC.add(dfbtcOrder[guarant]._btcAmount);
guarantUserMap[dfbtcOrder[guarant]._from]._curBTC = 0;
emit e_dfbtc_order(dfbtcOrder[msg.sender]._from, guarant, 3, dfbtcOrder[guarant]._toBTC, dfbtcOrder[guarant]._btcAmount, dfbtcOrder[guarant]._dfbtcAmount, now, 2);
}
function createOrder(uint _btcAmount, address _gua) public {
require(guarantUserMap[_gua]._bExist, "dfbtc: Guarantor not exist!!!");
require(msg.sender!=_gua, "dfbtc: Can't be the same person!!!");
if(dfbtcOrder[_gua]._bExist){
require(now >= (dfbtcOrder[_gua]._createTime + 1 days), "dfbtc: Time more than 1 days!!!");
}
require((getUserCanGetBTCAmount(_gua).sub(guarantUserMap[_gua]._curBTC))>=_btcAmount, "dfbtc: Guarantor has not enough assets!!!");
uint dfbtcVal = _btcAmount.mul(btcToDfbtc);
if(fee>0){
uint feeVal = dfbtcVal.mul(fee).div(100);
dfbtcVal = dfbtcVal.sub(feeVal);
}
dfbtcOrderClass memory _order = dfbtcOrderClass({
_from : msg.sender,
_to : _gua,
_toBTC : guarantUserMap[_gua]._btc,
_btcAmount : _btcAmount,
_dfbtcAmount : dfbtcVal,
_createTime : now,
_type : 1,
_bExist : true
});
dfbtcOrder[_gua] = _order;
dfbtcOrder[msg.sender] = _order;
emit e_dfbtc_order(msg.sender, _gua, 1, _order._toBTC, _btcAmount, _order._dfbtcAmount, _order._createTime, 1);
}
function confirmOrderSuccess(address guarant) public {
require((onwer == msg.sender || coo == msg.sender), "dfbtc: You are not owner!!!");
require(guarantUserMap[guarant]._bExist, "dfbtc: Guarantor not exists!");
require(dfbtcOrder[guarant]._bExist, "dfbtc: Order not exists!");
require(dfbtcOrder[guarant]._to==guarant, "dfbtc: The user are not guarantor of this order!");
require(dfbtcOrder[guarant]._type==1, "dfbtc: The type of order is not 1!");
dfbtcOrder[guarant]._bExist = false;
dfbtcOrder[dfbtcOrder[guarant]._from]._bExist = false;
btcVal = btcVal.add(dfbtcOrder[guarant]._btcAmount);
guarantUserMap[guarant]._curBTC = guarantUserMap[guarant]._curBTC.add(dfbtcOrder[guarant]._btcAmount);
uint dfbtcVal = dfbtcOrder[guarant]._btcAmount.mul(btcToDfbtc);
if(fee>0){
uint feeVal = dfbtcVal.mul(fee).div(100);
TransferHelper.safeTransfer(dfbtcAddress, feeAddress, feeVal);
dfbtcVal = dfbtcVal.sub(feeVal);
}
TransferHelper.safeTransfer(dfbtcAddress, dfbtcOrder[guarant]._from, dfbtcVal);
emit e_dfbtc_order(dfbtcOrder[msg.sender]._from, guarant, 1, dfbtcOrder[guarant]._toBTC, dfbtcOrder[guarant]._btcAmount, dfbtcOrder[guarant]._dfbtcAmount, now, 2);
}
function createBurnOrder(address _gauarant, string memory _btc, uint _btcAmount) public {
require(guarantUserMap[_gauarant]._bExist, "dfbtc: Guarantor not exist!!!");
if(dfbtcOrder[_gauarant]._bExist){
require(now >= (dfbtcOrder[_gauarant]._createTime + 1 days), "dfbtc: Time more than 1 days!!!");
}
require(msg.sender!=_gauarant, "dfbtc: Can't be the same person!!!");
require(guarantUserMap[_gauarant]._curBTC>=_btcAmount, "dfbtc: Guarantor has not enough amount!!!");
require(IERC20(dfbtcAddress).balanceOf(msg.sender)>=_btcAmount.mul(btcToDfbtc), "dfbtc: Insufficient quantity!!!");
uint dfbtcVal = _btcAmount.mul(btcToDfbtc);
if(fee>0){
uint feeVal = dfbtcVal.mul(fee).div(100);
dfbtcVal = dfbtcVal.sub(feeVal);
TransferHelper.safeTransfer(dfbtcAddress, feeAddress, feeVal);
}
dfbtcOrderClass memory _order = dfbtcOrderClass({
_from : _gauarant,
_to : msg.sender,
_toBTC : _btc,
_btcAmount : dfbtcVal.div(btcToDfbtc),
_dfbtcAmount : dfbtcVal,
_createTime : now,
_type : 2,
_bExist : true
});
dfbtcOrder[_gauarant] = _order;
dfbtcOrder[msg.sender] = _order;
TransferHelper.safeTransferFrom(dfbtcAddress, msg.sender, address(this), _btcAmount.mul(btcToDfbtc));
emit e_dfbtc_order(_gauarant, msg.sender, 2, _btc, _order._btcAmount, _order._dfbtcAmount, _order._createTime, 1);
}
function confirmBurnOrderSuccess(address user) public {
require((onwer == msg.sender || coo == msg.sender), "dfbtc: You are not owner!!!");
require(dfbtcOrder[user]._bExist, "dfbtc: Order not exists!");
require(dfbtcOrder[user]._to==user, "dfbtc: You are not user of this order!");
require(dfbtcOrder[user]._type==2, "dfbtc: The type of order is not 2!");
dfbtcOrder[user]._bExist = false;
dfbtcOrder[dfbtcOrder[user]._from]._bExist = false;
btcVal = btcVal.sub(dfbtcOrder[user]._btcAmount);
guarantUserMap[dfbtcOrder[user]._from]._curBTC = guarantUserMap[dfbtcOrder[user]._from]._curBTC.sub(dfbtcOrder[user]._btcAmount);
emit e_dfbtc_order(dfbtcOrder[user]._from, user, 2, dfbtcOrder[user]._toBTC, dfbtcOrder[user]._btcAmount, dfbtcOrder[user]._dfbtcAmount, now, 2);
}
function dowithBurnOrderFailerMoreDays(address user) public {
require(msg.sender==onwer||msg.sender==coo, "dfbtc: only manager can run this function!!!");
require(dfbtcOrder[user]._bExist, "dfbtc: Order not exists!");
require(dfbtcOrder[user]._to==user, "dfbtc: You are not a guarantor!");
require(dfbtcOrder[user]._type==2, "dfbtc: The type of order is not 2!");
require(now >= (dfbtcOrder[user]._createTime + 1 days), "dfbtc: Time more than 1 days!!!");
uint tot = getThePrice(btcPriceFeed).mul(dfbtcOrder[user]._btcAmount);
dfbtcOrder[user]._bExist = false;
dfbtcOrder[dfbtcOrder[user]._from]._bExist = false;
btcVal = btcVal.sub(dfbtcOrder[user]._btcAmount);
guarantUserMap[dfbtcOrder[user]._from]._curBTC = guarantUserMap[dfbtcOrder[user]._from]._curBTC.sub(dfbtcOrder[user]._btcAmount);
dowithGuarantAssets(dfbtcOrder[user]._from, user, tot);
emit e_dfbtc_order(dfbtcOrder[user]._from, user, 2, dfbtcOrder[user]._toBTC, dfbtcOrder[user]._btcAmount, dfbtcOrder[user]._dfbtcAmount, now, 4);
}
function dowithGuarantAssets(address fromUser, address user, uint tot) private {
require(tot>0, "dfbtc: Assets must more than 0!!!");
for(uint i=0; i<poolAddressList.length; i++){
if(tot == 0){
break;
}
uint uerAssets = userAssets[poolAddressList[i]][fromUser];
if(poolAddressList[i]!=aomAddress && uerAssets>0){
uint tokenPrice = getThePrice(poolAddressList[i]);
uint tokenAmount = tot.div(tokenPrice);
uint userTot = uerAssets.mul(tokenPrice);
uint needTransfer = 0;
if(userTot>=tot){
needTransfer = tokenAmount;
tot = 0;
}else{
needTransfer = uerAssets;
tot = tot.sub(userTot);
}
if(isETH(poolAddressList[i])){
address(uint160(user)).transfer(needTransfer);
}else{
TransferHelper.safeTransfer(poolAddressList[i], user, needTransfer);
}
userAssets[poolAddressList[i]][fromUser] = userAssets[poolAddressList[i]][fromUser].sub(needTransfer);
}
}
}
//*************************Order End************************
function getThePrice(address _wjhy) public view returns (uint){//(uint80, int, uint, uint, uint80) {
//0x9326BFA02ADD2366b30bacB125260Af641031331
AggregatorV3Interface priceFeed;
if(_wjhy == btcPriceFeed){
priceFeed = AggregatorV3Interface(btcPriceFeed);
}else{
priceFeed = AggregatorV3Interface(priceFeedmap[_wjhy]);
}
//priceFeed = AggregatorV3Interface(_wjhy);
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return uint(price);//(roundID, price, startedAt, timeStamp, answeredInRound);
}
function isETH(address _coinaddress) public view returns (bool) {
if(ethAddress == _coinaddress){
return true;
}else{
return false;
}
}
function setBtcPriceFeed(address pf) public onlyOnwer returns (bool) {
btcPriceFeed = pf;
return true;
}
function setCycle(uint _value) public onlyOnwer returns (bool) {
cycle[_value] = true;
return true;
}
function setAOMAddress(address _newAddress) public onlyOnwer returns (bool){
aomAddress = _newAddress;
return true;
}
function setDfbtcAddress(address _newAddress) public onlyOnwer returns (bool){
dfbtcAddress = _newAddress;
return true;
}
function setOnwer(address _onwer) public {
require(msg.sender == onwer, 'dfbtc: FORBIDDEN');
onwer = _onwer;
}
function setCoo(address _Coo) public {
require(msg.sender == onwer, 'dfbtc: FORBIDDEN');
coo = _Coo;
}
function isContract(address addr) public view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
function getBalanceByAddress(address _coinAddress, address _userAddress) public view returns (uint) {
if(isETH(_coinAddress)){
return _userAddress.balance;
}
require(isContract(_coinAddress), "dfbtc: Not a contract address!");
return IERC20(_coinAddress).balanceOf(_userAddress);
}
function getDFBTCTotal() public view returns (uint) {
return IERC20(dfbtcAddress).totalSupply();
}
function setFee(address _feeAddress, uint _fee) public onlyOnwer returns (bool) {
feeAddress = _feeAddress;
fee = _fee;
return true;
}
}
pragma solidity >=0.5.0;
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function mint(address _to, uint256 _amount) external returns (bool);
function burn(uint value) external;
}
pragma solidity =0.6.6;
// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
library SafeMath {
function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
if (_a == 0) {
return 0;
}
c = _a * _b;
assert(c / _a == _b);
return c;
}
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
return _a / _b;
}
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
assert(_b <= _a);
return _a - _b;
}
function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
c = _a + _b;
assert(c >= _a);
return c;
}
}
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.5.16;
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
}
{
"compilationTarget": {
"DFBTCV1Factory.sol": "DFBTCV1Factory"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"uint256","name":"_type","type":"uint256"},{"indexed":false,"internalType":"string","name":"_toBTC","type":"string"},{"indexed":false,"internalType":"uint256","name":"_btcAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_dfbtcAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_createTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_status","type":"uint256"}],"name":"e_dfbtc_order","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_eth","type":"address"},{"indexed":true,"internalType":"address","name":"_coin","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_addtime","type":"uint256"}],"name":"e_userTransfer_records","type":"event"},{"inputs":[],"name":"ETHAPY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TokenAPY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokenList","type":"address[]"},{"internalType":"uint256[]","name":"_valueList","type":"uint256[]"},{"internalType":"uint256","name":"_pledgeCycle","type":"uint256"},{"internalType":"string","name":"_btcAddress","type":"string"}],"name":"addGuarantorNode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokenList","type":"address[]"},{"internalType":"uint256[]","name":"_valueList","type":"uint256[]"}],"name":"addGuarantorNodeAssets","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_cAddress","type":"address"},{"internalType":"uint256","name":"_minVal","type":"uint256"},{"internalType":"uint256","name":"_deimalVal","type":"uint256"}],"name":"addPoolSet","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"aomAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"btcPriceFeed","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"btcToDfbtc","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"btcVal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"confirmBurnOrderSuccess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"guarant","type":"address"}],"name":"confirmOrderSuccess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"guarant","type":"address"}],"name":"confirmTransferOrderSuccess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"coo","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_gauarant","type":"address"},{"internalType":"string","name":"_btc","type":"string"},{"internalType":"uint256","name":"_btcAmount","type":"uint256"}],"name":"createBurnOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_btcAmount","type":"uint256"},{"internalType":"address","name":"_gua","type":"address"}],"name":"createOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gua","type":"address"}],"name":"createTransferBTCOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"cycle","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dfbtcAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"dfbtcOrder","outputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"string","name":"_toBTC","type":"string"},{"internalType":"uint256","name":"_btcAmount","type":"uint256"},{"internalType":"uint256","name":"_dfbtcAmount","type":"uint256"},{"internalType":"uint256","name":"_createTime","type":"uint256"},{"internalType":"uint256","name":"_type","type":"uint256"},{"internalType":"bool","name":"_bExist","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"dowithBurnOrderFailerMoreDays","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_cAddress","type":"address"},{"internalType":"uint256","name":"_minVal","type":"uint256"},{"internalType":"uint256","name":"_decimalVal","type":"uint256"}],"name":"editPoolset","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"ethAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_coinAddress","type":"address"},{"internalType":"address","name":"_userAddress","type":"address"}],"name":"getBalanceByAddress","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDFBTCTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGuarantUserCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_usera","type":"address"},{"internalType":"uint256","name":"btcAmount","type":"uint256"},{"internalType":"bool","name":"bBurn","type":"bool"}],"name":"getGuarantorUserForOrder","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoollist","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_wjhy","type":"address"}],"name":"getThePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserCanGetBTCAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"guarantUserMap","outputs":[{"internalType":"address","name":"_eth","type":"address"},{"internalType":"uint256","name":"_startTime","type":"uint256"},{"internalType":"uint256","name":"_pledgeCycle","type":"uint256"},{"internalType":"uint256","name":"_curBTC","type":"uint256"},{"internalType":"string","name":"_btc","type":"string"},{"internalType":"bool","name":"_bReceive","type":"bool"},{"internalType":"bool","name":"_bExist","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"guarantorList","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"priceAddress","type":"address"}],"name":"initPriceFeedmap","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"isContract","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_coinaddress","type":"address"}],"name":"isETH","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"liquidationAssets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"onwer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"poolAddressList","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"poolmap","outputs":[{"internalType":"address","name":"_coinAddress","type":"address"},{"internalType":"uint256","name":"_minAmounts","type":"uint256"},{"internalType":"uint256","name":"_decimalAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"priceFeedmap","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"redeemAssets","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"toAdddress","type":"address"},{"internalType":"uint256","name":"transferValue","type":"uint256"}],"name":"safeTransferToOtherPools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newAddress","type":"address"}],"name":"setAOMAddress","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"ethA","type":"uint256"},{"internalType":"uint256","name":"tokenA","type":"uint256"}],"name":"setAPY","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pf","type":"address"}],"name":"setBtcPriceFeed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_Coo","type":"address"}],"name":"setCoo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"setCycle","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newAddress","type":"address"}],"name":"setDfbtcAddress","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeAddress","type":"address"},{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setFee","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_onwer","type":"address"}],"name":"setOnwer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"userAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]