编译器
0.8.16+commit.07a7930e
文件 1 的 16:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 16:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
文件 3 的 16:ERC20Burnable.sol
pragma solidity ^0.8.0;
import "../ERC20.sol";
import "../../../utils/Context.sol";
abstract contract ERC20Burnable is Context, ERC20 {
function burn(uint256 amount) public virtual {
_burn(_msgSender(), amount);
}
function burnFrom(address account, uint256 amount) public virtual {
_spendAllowance(account, _msgSender(), amount);
_burn(account, amount);
}
}
文件 4 的 16:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
文件 5 的 16:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 6 的 16:IERC4626.sol
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
function asset() external view returns (address assetTokenAddress);
function totalAssets() external view returns (uint256 totalManagedAssets);
function convertToShares(uint256 assets) external view returns (uint256 shares);
function convertToAssets(uint256 shares) external view returns (uint256 assets);
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
function previewDeposit(uint256 assets) external view returns (uint256 shares);
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
function maxMint(address receiver) external view returns (uint256 maxShares);
function previewMint(uint256 shares) external view returns (uint256 assets);
function mint(uint256 shares, address receiver) external returns (uint256 assets);
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
function maxRedeem(address owner) external view returns (uint256 maxShares);
function previewRedeem(uint256 shares) external view returns (uint256 assets);
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}
文件 7 的 16:IKeyProtocolVariables.sol
pragma solidity 0.8.16;
interface IKeyProtocolVariables {
function xTokenMintFee() external view returns (uint256);
function securityDepositMonths() external view returns (uint8);
function xTokensSecurityWallet() external view returns (address);
function landxOperationalWallet() external view returns (address);
function landxChoiceWallet() external view returns (address);
function landXOperationsPercentage() external view returns (uint256);
function landXChoicePercentage() external view returns (uint256);
function lndxHoldersPercentage() external view returns (uint256);
function hedgeFundAllocation() external view returns (uint256);
function hedgeFundWallet() external view returns (address);
function preLaunch() external view returns (bool);
function sellXTokenSlippage() external view returns (uint256);
function buyXTokenSlippage() external view returns (uint256);
function cTokenSellFee() external view returns (uint256);
function validatorCommission() external view returns (uint256);
function validatorCommisionWallet() external view returns (address);
function payRentFee() external view returns (uint256);
function maxValidatorFee() external view returns (uint256);
}
文件 8 的 16:IOraclePrices.sol
pragma solidity 0.8.16;
interface IOraclePrices {
function prices(string memory grain) external view returns (uint256);
function getXTokenPrice(address xToken) external view returns (uint256);
function usdc() external view returns (address);
}
文件 9 的 16:ISwapRouter.sol
pragma solidity >=0.7.5;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}
文件 10 的 16:ITWAP.sol
pragma solidity >=0.7.4;
interface ITWAP {
function getPrice(address tokenIn, address tokenOut) external view returns (uint);
}
文件 11 的 16:IUniswapV3SwapCallback.sol
pragma solidity >=0.5.0;
interface IUniswapV3SwapCallback {
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}
文件 12 的 16:IxToken.sol
pragma solidity 0.8.16;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IxToken is IERC20 {
function previewNonDistributedYield() external view returns(uint256);
function getNonDistributedYield() external returns(uint256);
function stake(uint256 amount) external;
function unstake(uint256 amount) external;
function xBasketTransfer(address _from, uint256 amount) external;
function Staked(address)
external
view
returns (uint256 amount, uint256 startTime);
function availableToClaim(address account) external view returns (uint256);
function claim() external;
}
文件 13 的 16:IxTokenRouter.sol
pragma solidity 0.8.16;
interface IxTokenRouter {
function getXToken(string memory _name) external view returns (address);
function getCToken(string memory _name) external view returns (address);
}
文件 14 的 16:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 15 的 16:TransferHelper.sol
pragma solidity >=0.6.0;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
library TransferHelper {
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) =
token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
}
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'STE');
}
}
文件 16 的 16:xBasket.sol
pragma solidity 0.8.16;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
import "@openzeppelin/contracts/interfaces/IERC4626.sol";
import "./interfaces/IKeyProtocolVariables.sol";
import "./interfaces/IxTokenRouter.sol";
import "./interfaces/IOraclePrices.sol";
import "./interfaces/IxToken.sol";
import "./interfaces/ITWAP.sol";
contract xBasket is ERC20, IERC4626, Ownable {
IxTokenRouter public xTokenRouter;
IOraclePrices public oraclePrices;
IKeyProtocolVariables public keyProtocolValues;
address public xWheat;
address public xSoy;
address public xCorn;
address public xRice;
address public cWheat;
address public cSoy;
address public cCorn;
address public cRice;
address public usdc;
ISwapRouter public uniswapRouter;
ITWAP public twap;
event AutoCompounded(uint256 xWheat, uint256 xSoy, uint256 xRice, uint256 xCorn);
constructor(
address _xTokenRouter,
address _oraclePrices,
address _keyProtocolValues,
address _uniswapRouter,
address _twap
) ERC20("xBasket LandX Index Fund", "xBASKET") {
require(_xTokenRouter != address(0), "zero address is not allowed");
require(_oraclePrices != address(0), "zero address is not allowed");
require(_keyProtocolValues != address(0), "zero address is not allowed");
require(_uniswapRouter != address(0), "zero address is not allowed");
xTokenRouter = IxTokenRouter(_xTokenRouter);
oraclePrices = IOraclePrices(_oraclePrices);
keyProtocolValues = IKeyProtocolVariables(_keyProtocolValues);
xWheat = xTokenRouter.getXToken("WHEAT");
xSoy = xTokenRouter.getXToken("SOY");
xRice = xTokenRouter.getXToken("RICE");
xCorn = xTokenRouter.getXToken("CORN");
cWheat = xTokenRouter.getCToken("WHEAT");
cSoy = xTokenRouter.getCToken("SOY");
cRice = xTokenRouter.getCToken("RICE");
cCorn = xTokenRouter.getCToken("CORN");
usdc = oraclePrices.usdc();
uniswapRouter = ISwapRouter(_uniswapRouter);
twap = ITWAP(_twap);
}
function asset() public view override returns (address) {
return usdc;
}
function totalAssets() public view override returns (uint256) {
return calculateTVL();
}
function convertToShares(uint256 assets)
public
view
override
returns (uint256)
{
return _convertToShares(assets);
}
function _convertToShares(uint256 assets)
internal
view
returns (uint256 shares)
{
uint256 usdVaultValuation = calculateTVL();
uint256 circulatingSupply = totalSupply();
if (circulatingSupply == 0) {
shares = 4 * assets;
} else {
uint256 xWheatPrice = twap.getPrice(xWheat, usdc);
uint256 xSoyPrice = twap.getPrice(xSoy, usdc);
uint256 xRicePrice = twap.getPrice(xRice, usdc);
uint256 xCornPrice = twap.getPrice(xCorn, usdc);
shares =
(assets *
(xWheatPrice + xSoyPrice + xCornPrice + xRicePrice) *
circulatingSupply) /
usdVaultValuation /
1e6;
}
return shares;
}
function convertToAssets(uint256 shares)
public
view
override
returns (uint256)
{
return _convertToAssets(shares);
}
function _convertToAssets(uint256 shares) internal view returns (uint256) {
uint256 usdVaultValuation = calculateTVL();
uint256 circulatingSupply = totalSupply();
if (circulatingSupply == 0) {
return shares / 4;
}
uint256 xWheatPrice = twap.getPrice(xWheat, usdc);
uint256 xSoyPrice = twap.getPrice(xSoy, usdc);
uint256 xRicePrice = twap.getPrice(xRice, usdc);
uint256 xCornPrice = twap.getPrice(xCorn, usdc);
uint256 redeemAmount = (1e6 * shares * usdVaultValuation) /
circulatingSupply /
(xWheatPrice + xSoyPrice + xRicePrice + xCornPrice);
return redeemAmount;
}
function maxDeposit(address receiver)
public
view
virtual
override
returns (uint256)
{
return _findMinAssetBalanceValue(receiver);
}
function maxMint(address receiver)
public
view
virtual
override
returns (uint256)
{
return _convertToShares(_findMinAssetBalanceValue(receiver));
}
function maxWithdraw(address owner)
public
view
virtual
override
returns (uint256)
{
return _convertToAssets(balanceOf(owner));
}
function maxRedeem(address owner)
public
view
virtual
override
returns (uint256)
{
return balanceOf(owner);
}
function previewDeposit(uint256 assets)
public
view
virtual
override
returns (uint256)
{
return _convertToShares(assets);
}
function previewMint(uint256 shares)
public
view
virtual
override
returns (uint256)
{
return _convertToAssets(shares);
}
function previewWithdraw(uint256 assets)
public
view
virtual
override
returns (uint256)
{
return _convertToShares(assets);
}
function previewRedeem(uint256 shares)
public
view
virtual
override
returns (uint256)
{
return _convertToAssets(shares);
}
function deposit(uint256 assets, address receiver)
public
virtual
override
returns (uint256)
{
require(
assets <= maxDeposit(msg.sender),
"ERC4626: deposit more than max"
);
uint256 shares = previewDeposit(assets);
_deposit(msg.sender, receiver, assets, shares);
return shares;
}
function mint(uint256 shares, address receiver)
public
virtual
override
returns (uint256)
{
require(shares <= maxMint(msg.sender), "ERC4626: mint more than max");
uint256 assets = previewMint(shares);
_deposit(msg.sender, receiver, assets, shares);
return assets;
}
function withdraw(
uint256 assets,
address receiver,
address owner
) public virtual override returns (uint256) {
require(
assets <= maxWithdraw(owner),
"ERC4626: withdraw more than max"
);
uint256 shares = previewWithdraw(assets);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return shares;
}
function redeem(
uint256 shares,
address receiver,
address owner
) public virtual override returns (uint256) {
require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");
uint256 assets = previewRedeem(shares);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return assets;
}
function _findMinAssetBalanceValue(address owner)
internal
view
returns (uint256)
{
uint256 xWheatBalance = IxToken(xWheat).balanceOf(owner);
uint256 xSoyBalance = IxToken(xSoy).balanceOf(owner);
uint256 xRiceBalance = IxToken(xRice).balanceOf(owner);
uint256 xCornBalance = IxToken(xCorn).balanceOf(owner);
uint256[4] memory balances = [
xWheatBalance,
xSoyBalance,
xRiceBalance,
xCornBalance
];
uint256 smallest = xWheatBalance;
uint256 i;
for (i = 0; i < balances.length; i++) {
if (balances[i] < smallest) {
smallest = balances[i];
}
}
return smallest;
}
function _deposit(
address caller,
address receiver,
uint256 assets,
uint256 shares
) internal {
IxToken(xWheat).xBasketTransfer(caller, assets);
IxToken(xSoy).xBasketTransfer(caller, assets);
IxToken(xRice).xBasketTransfer(caller, assets);
IxToken(xCorn).xBasketTransfer(caller, assets);
IxToken(xWheat).stake(assets);
IxToken(xSoy).stake(assets);
IxToken(xRice).stake(assets);
IxToken(xCorn).stake(assets);
_mint(receiver, shares);
emit Deposit(caller, receiver, assets, shares);
}
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256 shares
) internal {
if (caller != owner) {
_spendAllowance(owner, caller, shares);
}
autoCompoundRewards();
_burn(owner, shares);
IxToken(xWheat).unstake(assets);
IxToken(xSoy).unstake(assets);
IxToken(xRice).unstake(assets);
IxToken(xCorn).unstake(assets);
IxToken(xWheat).transfer(receiver, assets);
IxToken(xSoy).transfer(receiver, assets);
IxToken(xRice).transfer(receiver, assets);
IxToken(xCorn).transfer(receiver, assets);
emit Withdraw(caller, receiver, owner, assets, shares);
}
function calculateCollateral() public view returns (uint256) {
uint256 xWheatBalance = IxToken(xWheat).balanceOf(address(this));
uint256 xSoyBalance = IxToken(xSoy).balanceOf(address(this));
uint256 xRiceBalance = IxToken(xRice).balanceOf(address(this));
uint256 xCornBalance = IxToken(xCorn).balanceOf(address(this));
(uint256 xWheatStaked, ) = IxToken(xWheat).Staked(address(this));
(uint256 xSoyStaked, ) = IxToken(xSoy).Staked(address(this));
(uint256 xRiceStaked, ) = IxToken(xRice).Staked(address(this));
(uint256 xCornStaked, ) = IxToken(xCorn).Staked(address(this));
uint256 xWheatPrice = twap.getPrice(xWheat, usdc);
uint256 xSoyPrice = twap.getPrice(xSoy, usdc);
uint256 xRicePrice = twap.getPrice(xRice, usdc);
uint256 xCornPrice = twap.getPrice(xCorn, usdc);
uint256 collateral;
collateral += (xWheatBalance + xWheatStaked) * xWheatPrice;
collateral += (xSoyBalance + xSoyStaked) * xSoyPrice;
collateral += (xRiceBalance + xRiceStaked) * xRicePrice;
collateral += (xCornBalance + xCornStaked) * xCornPrice;
collateral = collateral / 1e6;
return collateral;
}
function calculateYield() public view returns (uint256) {
uint256 cWheatPending = IxToken(xWheat).availableToClaim(address(this));
uint256 cSoyPending = IxToken(xSoy).availableToClaim(address(this));
uint256 cRicePending = IxToken(xRice).availableToClaim(address(this));
uint256 cCornPending = IxToken(xCorn).availableToClaim(address(this));
uint256 usdcBalance = IERC20(usdc).balanceOf(address(this));
uint256 cWheatPrice = oraclePrices.prices("WHEAT");
uint256 cSoyPrice = oraclePrices.prices("SOY");
uint256 cRicePrice = oraclePrices.prices("RICE");
uint256 cCornPrice = oraclePrices.prices("CORN");
uint256 totalYield = usdcBalance;
totalYield +=
((IERC20(cWheat).balanceOf(address(this)) + cWheatPending) *
cWheatPrice) /
1e9;
totalYield +=
((IERC20(cSoy).balanceOf(address(this)) + cSoyPending) *
cSoyPrice) /
1e9;
totalYield +=
((IERC20(cRice).balanceOf(address(this)) + cRicePending) *
cRicePrice) /
1e9;
totalYield +=
((IERC20(cCorn).balanceOf(address(this)) + cCornPending) *
cCornPrice) /
1e9;
return totalYield;
}
function calculateTVL() public view returns (uint256) {
uint256 totalCollateral = calculateCollateral();
uint256 totalYield = calculateYield();
uint256 tvl = totalCollateral + totalYield;
return tvl;
}
function pricePerToken() public view returns (uint256) {
uint256 tvl = calculateTVL();
uint256 circulatingSupply = totalSupply();
if (circulatingSupply == 0) {
return 0;
}
uint256 xBasketPrice = (tvl * 1e6) / circulatingSupply;
return xBasketPrice;
}
function autoCompoundRewards() public {
IxToken(xWheat).claim();
IxToken(xSoy).claim();
IxToken(xRice).claim();
IxToken(xCorn).claim();
uint256 cWheatBalance = IERC20(cWheat).balanceOf(address(this));
uint256 cSoyBalance = IERC20(cSoy).balanceOf(address(this));
uint256 cRiceBalance = IERC20(cRice).balanceOf(address(this));
uint256 cCornBalance = IERC20(cCorn).balanceOf(address(this));
ERC20Burnable(cWheat).burn(cWheatBalance);
_convertToXToken(xWheat);
ERC20Burnable(cSoy).burn(cSoyBalance);
_convertToXToken(xSoy);
ERC20Burnable(cRice).burn(cRiceBalance);
_convertToXToken(xRice);
ERC20Burnable(cCorn).burn(cCornBalance);
_convertToXToken(xCorn);
uint256 xWheatBalance = IxToken(xWheat).balanceOf(address(this));
uint256 xSoyBalance = IxToken(xSoy).balanceOf(address(this));
uint256 xRiceBalance = IxToken(xRice).balanceOf(address(this));
uint256 xCornBalance = IxToken(xCorn).balanceOf(address(this));
IxToken(xWheat).stake(xWheatBalance);
IxToken(xSoy).stake(xSoyBalance);
IxToken(xRice).stake(xRiceBalance);
IxToken(xCorn).stake(xCornBalance);
emit AutoCompounded(xWheatBalance, xSoyBalance, xRiceBalance, xCornBalance);
}
function quoteAmountOut(uint _amount, address xToken) public view returns (uint) {
uint price = twap.getPrice(usdc, xToken);
uint256 amountOut = _amount * price / 1e6;
return amountOut;
}
function _convertToXToken(address xToken) internal returns (uint256) {
uint256 amountIn = IERC20(usdc).balanceOf(address(this));
uint256 slippage = keyProtocolValues.buyXTokenSlippage();
uint256 predictedAmountOut = quoteAmountOut(amountIn, xToken);
uint256 minAmountOut = predictedAmountOut * 10000 / (10000 + slippage);
TransferHelper.safeApprove(usdc, address(uniswapRouter), amountIn);
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter
.ExactInputSingleParams(
usdc,
xToken,
3000,
address(this),
block.timestamp + 15,
amountIn,
minAmountOut,
0
);
return uniswapRouter.exactInputSingle(params);
}
function renounceOwnership() public view override onlyOwner {
revert ("can 't renounceOwnership here");
}
function decimals()
public
view
virtual
override(ERC20, IERC20Metadata)
returns (uint8)
{
return 6;
}
}
{
"compilationTarget": {
"contracts/xBasket.sol": "xBasket"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 2000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_xTokenRouter","type":"address"},{"internalType":"address","name":"_oraclePrices","type":"address"},{"internalType":"address","name":"_keyProtocolValues","type":"address"},{"internalType":"address","name":"_uniswapRouter","type":"address"},{"internalType":"address","name":"_twap","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"xWheat","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"xSoy","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"xRice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"xCorn","type":"uint256"}],"name":"AutoCompounded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"autoCompoundRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cCorn","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cRice","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cSoy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cWheat","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"calculateCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"calculateTVL","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"calculateYield","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"keyProtocolValues","outputs":[{"internalType":"contract IKeyProtocolVariables","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oraclePrices","outputs":[{"internalType":"contract IOraclePrices","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pricePerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"xToken","type":"address"}],"name":"quoteAmountOut","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"twap","outputs":[{"internalType":"contract ITWAP","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapRouter","outputs":[{"internalType":"contract ISwapRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"usdc","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"xCorn","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"xRice","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"xSoy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"xTokenRouter","outputs":[{"internalType":"contract IxTokenRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"xWheat","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]