-
Notifications
You must be signed in to change notification settings - Fork 1
Initial Structure #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,59 @@ | |
| pragma solidity ^0.8.0; | ||
|
|
||
| import "../libs/openzeppelin/token/ERC20/ERC20.sol"; | ||
| import "../libs/openzeppelin/token/ERC20/IPair.sol"; | ||
| import "../libs/openzeppelin/access/Ownable.sol"; | ||
| import "../libs/openzeppelin/utils/math/SafeMath.sol"; | ||
|
|
||
| contract MiniYak is ERC20 { | ||
| contract MiniYak is ERC20, Ownable { | ||
| using SafeMath for uint; | ||
| IPair private swapPair; | ||
| bool private swapsEnabled; | ||
| event Deposit(address indexed dst, uint amount); | ||
|
|
||
| constructor() ERC20("MiniYak", "MYAK") {} | ||
| uint constant internal mini = 1000000; | ||
|
|
||
| /** | ||
| * @dev Throws if called by any account other than the owner. | ||
| */ | ||
| modifier swapsAllowed() { | ||
| require( swapsEnabled == true, "Ownable: caller is not the owner"); | ||
| require(address(swapPair) != address(0)); | ||
| _; | ||
| } | ||
|
|
||
| receive() external payable { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MiniYak does not need to deal with payable, it'll receive YakToken which is ERC20 and wrap it |
||
| // only accept AVAX via fallback from the owner when rewards are distributed by masterChef | ||
| assert(msg.sender == owner()); | ||
| } | ||
|
|
||
| function wrap() public payable { | ||
| _mint(msg.sender, (msg.value).mul(mini)); | ||
| emit Deposit(msg.sender, msg.value); | ||
| } | ||
|
|
||
| function withdrawOwnerOnly(uint amount) public onlyOwner { | ||
| payable(msg.sender).transfer(amount); | ||
| } | ||
|
|
||
| function unwrap(uint amount) public { | ||
| _burn(msg.sender,amount.div(mini)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should require here that the amount is bigger than |
||
| payable(msg.sender).transfer(amount.div(mini)); | ||
| } | ||
|
|
||
| function assignSwapPair(address pair) public onlyOwner { | ||
| require(address(pair)!= address(0),"Cannot assign to a dead address"); | ||
| require(IPair(pair).token0() == address(this) || IPair(pair).token1() == address(this)); | ||
| swapPair = IPair(pair); | ||
| } | ||
|
|
||
| function swapFromAVAX(uint amount) public swapsAllowed { | ||
| swapPair.swap(0, amount, msg.sender, new bytes(0)); | ||
| } | ||
|
|
||
| function swapToAVAX(uint amount) public swapsAllowed { | ||
| swapPair.swap(amount, 0, msg.sender, new bytes(0)); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,56 @@ | |
| pragma solidity ^0.8.0; | ||
|
|
||
| import "../libs/openzeppelin/token/ERC20/ERC20.sol"; | ||
| import "../libs/openzeppelin/token/ERC20/IPair.sol"; | ||
| import "../libs/openzeppelin/access/Ownable.sol"; | ||
|
|
||
| contract YakAVAX is ERC20 { | ||
| contract YakAVAX is ERC20, Ownable { | ||
| IPair private swapPair; | ||
| bool private swapsEnabled; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need an admin function to disabled it and re-enable |
||
| event Deposit(address indexed dst, uint amount); | ||
| constructor() ERC20("YakAVAX", "YAKX") { | ||
|
|
||
| constructor() ERC20("YakAVAX", "YAKX") {} | ||
| } | ||
| /** | ||
| * @dev Throws if called by any account other than the owner. | ||
| */ | ||
| modifier swapsAllowed() { | ||
| require( swapsEnabled == true, "Ownable: caller is not the owner"); | ||
| require(address(swapPair) != address(0)); | ||
| _; | ||
| } | ||
|
|
||
| receive() external payable { | ||
| // only accept AVAX via fallback from the owner when rewards are distributed by masterChef | ||
| assert(msg.sender == owner()); | ||
| } | ||
|
|
||
| function wrap() public payable { | ||
| _mint(msg.sender, msg.value); | ||
| emit Deposit(msg.sender, msg.value); | ||
| } | ||
|
|
||
| function withdrawOwnerOnly(uint amount) public onlyOwner { | ||
| payable(msg.sender).transfer(amount); | ||
| } | ||
|
|
||
| function unwrap(uint amount) public { | ||
| _burn(msg.sender,amount); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good idea to require that the contract has the underlying AVAX available |
||
| payable(msg.sender).transfer(amount); | ||
| } | ||
|
|
||
| function assignSwapPair(address pair) public onlyOwner { | ||
| require(address(pair)!= address(0),"Cannot assign to a dead address"); | ||
| require(IPair(pair).token0() == address(this) || IPair(pair).token1() == address(this)); | ||
| swapPair = IPair(pair); | ||
| } | ||
|
|
||
| function swapForYakAVAX(uint amount) public swapsAllowed { | ||
| swapPair.swap(0, amount, msg.sender, new bytes(0)); | ||
| } | ||
|
|
||
| function swapForAVAX(uint amount) public swapsAllowed { | ||
| swapPair.swap(amount, 0, msg.sender, new bytes(0)); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "./IERC20.sol"; | ||
|
|
||
| interface IPair is IERC20 { | ||
| function token0() external pure returns (address); | ||
| function token1() external pure returns (address); | ||
| function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; | ||
| function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); | ||
| function mint(address to) external returns (uint liquidity); | ||
| function sync() external; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "./IERC20.sol"; | ||
|
|
||
| interface IYAK is IERC20 { | ||
| function wrap() external payable; | ||
| function withdrawOwnerOnly(uint amount) external; | ||
| function unwrap() external; | ||
| function assignSwapPair(address pair) external; | ||
| function mint(address to) external returns (uint liquidity); | ||
| function sync() external; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { expect } from "chai" | ||
| import { ethers } from "hardhat" | ||
| import {run} from "hardhat" | ||
| import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers" | ||
| import { Contract } from "@ethersproject/contracts" | ||
|
|
||
| describe("YakAVAX", async function() { | ||
|
|
||
| let owner: SignerWithAddress | ||
| let account: SignerWithAddress | ||
| let yakAVAXContract: Contract | ||
|
|
||
| before(async function() { | ||
| //this makes sure the newest changes are compiled and pushed to the fork node | ||
| run("compile") | ||
| }) | ||
|
|
||
| beforeEach(async function() { | ||
| owner = (await ethers.getSigners())[0] | ||
| account = (await ethers.getSigners())[1] | ||
| }) | ||
|
|
||
| it("Can be deployed", async function() { | ||
| const factory = await ethers.getContractFactory("YakAVAX") | ||
| yakAVAXContract = await factory.connect(owner).deploy() | ||
| // await expect(miniYakContract.deployed()).to.be.reverted | ||
| await yakAVAXContract.deployed() | ||
| console.log("Account balance of Owner before deposit:", (await owner.getBalance()).toString()); | ||
| await yakAVAXContract.connect(owner).deposit({from: owner.address, value: "40000000000000000000"}); | ||
| console.log("Account balance after deposit:", (await owner.getBalance()).toString()); | ||
| console.log("YakAVAX balance of Owner after deposit:", (await yakAVAXContract.connect(owner).balanceOf(await owner.getAddress())).toString()); | ||
| await yakAVAXContract.connect(owner).withdraw("40000000000000000000"); | ||
| console.log("Account balance of owner after withdraw:", (await owner.getBalance()).toString()); | ||
| console.log("Account balance:", (await yakAVAXContract.connect(owner).balanceOf(await owner.getAddress())).toString()); | ||
|
|
||
| }) | ||
|
|
||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to limit the transfer function to only transfer values higher than
mini, users with less mYak than the definedminiwould cause problems