Commit ce39a68a authored by XFT-dev's avatar XFT-dev
Browse files

initializing repo

parent 8605a110
# protocol-main
offshift code + docs
\ No newline at end of file
This diff is collapsed.
pragma solidity ^0.6.7;
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
function getLatestPrice(address aggregatorAddress) public view returns (int) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(aggregatorAddress);
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
// If the round is not complete yet, timestamp is 0
require(timeStamp > 0, "Round not complete");
return price;
}
function getPrice(address _Aaddress, address _bAddress) public view returns (uint256) {
uint priceA = uint(getLatestPrice(_Aaddress))
unit priceB = uint(getLatestPrice(_Baddress))
return uint((priceA * 10 ** decimals) / priceB);
}
}
pragma solidity ^0.6.0;
// SPDX-License-Identifier: MIT
interface zkAsset {
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function mint(address to, uint256 amount) external;
function burn(address to, uint256 amount) external;
event Transfer(address indexed from, address indexed to, uint256 value);
}
interface chainLink {
function getPrice() external view returns (uint256);
}
contract burner {
zkAsset tokenA;
zkAsset tokenB;
chainLink priceOracle;
event Shifted(uint256 value);
constructor(address _tokenA, address _tokenB) public{
tokenA = zkAsset(_tokenA);
tokenB = zkAsset(_tokenB);
priceOracle = chainLink(); // deployed chainlink.sol address
}
function shift(uint256 amount) public {
require(amount > 0, "amount can't be zero");
uint256 allowance = tokenA.allowance(msg.sender, address(this));
uint256 Price = priceOracle.getPrice();
require(allowance >= amount, "remember to approve this contract");
tokenA.transferFrom(msg.sender, address(0x5a6b6173736574), amount);// <--- burn here
tokenB.mint(msg.sender ,((amount * Price)/10**18);//mint
emit Shifted(amount);
}
}
pragma solidity ^0.6.0;
// SPDX-License-Identifier: MIT
interface zkAsset {
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function mint(address to, uint256 amount) external;
function burn(address to, uint256 amount) external;
event Transfer(address indexed from, address indexed to, uint256 value);
}
interface xftTest {
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function mint(address to, uint256 amount) external;
function burn(address to, uint256 amount) external;
function balanceOf(address account) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
}
interface chainLink {
function getPrice(address _Aaddress, address _bAddress) external view returns (uint256);
}
contract burner {
xftTest tokenA;
zkAsset tokenB;
chainLink priceOracle;
event Shifted(uint256 value);
constructor(address _tokenA, address _tokenB) public{
tokenA = xftTest(_tokenA);
tokenB = zkAsset(_tokenB);
priceOracle = chainLink(0x51681E73Ec15C3206074d668cE55FAF4305Ea9D7); // deployed chainlink.sol address
}
function shift(uint256 amount, address _Aaddress, address _bAddress) public {
require(amount > 0, "amount can't be zero");
uint256 allowance = tokenA.allowance(msg.sender, address(this));
uint256 Price = priceOracle.getPrice(_Aaddress, _bAddress);
require(allowance >= amount, "remember to approve this contract");
tokenA.transferFrom(msg.sender, address(0x5a6b6173736574), amount); // <--- burn here
tokenB.mint(msg.sender ,((amount * Price)/10**18)); //mint
emit Shifted(amount);
}
function faucet() public payable {
require(tokenA.balanceOf(msg.sender)<(10*10**18), "you already have enough tokens!!");
tokenA.mint(msg.sender, (10*10**18));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment