Skip to content
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

[pull] master from yearn:master #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ on:
- develop
pull_request:


jobs:
test:
runs-on: ubuntu-latest
name: Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node: ['14.x']
os: ['ubuntu-latest']

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Cache compiler installations
uses: actions/cache@v2
Expand All @@ -23,9 +31,9 @@ jobs:
key: ${{ runner.os }}-compiler-cache

- name: Setup node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: '12.x'
node-version: '14.x'

- name: Install ganache
run: npm install -g ganache-cli@6.12.1
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Yearn Affiliate Wrapper Brownie Mix

## Warning

This repo is for inspiration purposes, this code isn't audited.

## What you'll find here

- Basic Solidity Smart Contract for creating your own Yearn Affiliate Wrapper ([`contracts/AffiliateToken.sol`](contracts/AffiliateToken.sol))
Expand Down
13 changes: 5 additions & 8 deletions brownie-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ autofetch_sources: True

# require OpenZepplin Contracts
dependencies:
- iearn-finance/yearn-vaults@0.4.3
- OpenZeppelin/openzeppelin-contracts@3.1.0
- yearn/yearn-vaults@0.4.5
- OpenZeppelin/openzeppelin-contracts@4.8.0

# path remapping to support imports from GitHub/NPM
compiler:
solc:
version: 0.6.12
version: 0.8.17
remappings:
- "@yearnvaults=iearn-finance/yearn-vaults@0.4.3"
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.1.0"
- "@yearnvaults=yearn/yearn-vaults@0.4.5"
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.8.0"

reports:
exclude_contracts:
- SafeMath
28 changes: 14 additions & 14 deletions contracts/AffiliateToken.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import {VaultAPI, BaseWrapper} from "@yearnvaults/contracts/BaseWrapper.sol";
import {VaultAPI, BaseWrapper} from "./BaseWrapper.sol";

contract AffiliateToken is ERC20, BaseWrapper {
uint8 public immutable DECIMALS;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH =
keccak256(
Expand Down Expand Up @@ -36,7 +36,7 @@ contract AffiliateToken is ERC20, BaseWrapper {
address _registry,
string memory name,
string memory symbol
) public BaseWrapper(_token, _registry) ERC20(name, symbol) {
) BaseWrapper(_token, _registry) ERC20(name, symbol) {
DOMAIN_SEPARATOR = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
Expand All @@ -47,7 +47,7 @@ contract AffiliateToken is ERC20, BaseWrapper {
)
);
affiliate = msg.sender;
_setupDecimals(uint8(ERC20(address(token)).decimals()));
DECIMALS = uint8(ERC20(address(token)).decimals());
}

function _getChainId() internal view returns (uint256) {
Expand All @@ -71,34 +71,30 @@ contract AffiliateToken is ERC20, BaseWrapper {
uint256 totalShares = totalSupply();

if (totalShares > 0) {
return
totalVaultBalance(address(this)).mul(numShares).div(
totalShares
);
return (totalVaultBalance(address(this)) * numShares) / totalShares;
} else {
return numShares;
}
}

function pricePerShare() external view returns (uint256) {
return
totalVaultBalance(address(this)).mul(10**uint256(decimals())).div(
totalSupply()
);
(totalVaultBalance(address(this)) * 10**uint256(decimals())) /
totalSupply();
}

function _sharesForValue(uint256 amount) internal view returns (uint256) {
// total wrapper assets before deposit (assumes deposit already occured)
uint256 totalBalance = totalVaultBalance(address(this));
if (totalBalance > amount) {
return totalSupply().mul(amount).div(totalBalance.sub(amount));
return (totalSupply() * amount) / (totalBalance - amount);
} else {
return amount;
}
}

function deposit() external returns (uint256) {
return deposit(uint256(-1)); // Deposit everything
return deposit(type(uint256).max); // Deposit everything
}

function deposit(uint256 amount) public returns (uint256 deposited) {
Expand Down Expand Up @@ -178,4 +174,8 @@ contract AffiliateToken is ERC20, BaseWrapper {

_approve(owner, spender, amount);
}

function decimals() public view virtual override returns (uint8) {
return DECIMALS;
}
}
Loading