Skip to content

Commit

Permalink
update defi development
Browse files Browse the repository at this point in the history
  • Loading branch information
jklepatch committed Oct 10, 2020
1 parent a4d73fa commit 7290d43
Show file tree
Hide file tree
Showing 51 changed files with 928 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pragma solidity ^0.7.2;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/access/Ownable.sol';

contract BonusToken is ERC20, Ownable {
constructor() ERC20('Bonus Token', 'BTK') Ownable() {}

function mint(address to, uint amount) external onlyOwner() {
_mint(to, amount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pragma solidity ^0.7.2;

import './LpToken.sol';
import './BonusToken.sol';

contract LiquidityMining {
struct User {
uint balance;
uint checkpoint;
}
mapping(address => User) public users;
uint public totalBalance;
uint public checkpoint;
uint constant public BONUS_PER_BLOCK = 1000;
LpToken public lpToken;
BonusToken public bonusToken;

constructor(address _lpToken, address _bonusToken) {
lpToken = LpToken(_lpToken);
bonusToken = BonusToken(_bonusToken);
}

function deposit(uint amount) external {
User storage user = users[msg.sender];
_updateBonusTokens(user);
lpToken.transferFrom(msg.sender, address(this), amount);
user.balance += amount;
totalBalance += amount;
}

function withdraw(uint amount) external {
User storage user = users[msg.sender];
_updateBonusTokens(user);
lpToken.transfer(msg.sender, amount);
user.balance -= amount;
totalBalance -= amount;
}

function _updateBonusTokens(User storage user) internal {
uint mintableBonusTokens = (block.number - checkpoint) * BONUS_PER_BLOCK;
if(block.number > checkpoint) {
bonusToken.mint(address(this), mintableBonusTokens);
checkpoint = block.number;
}
if(block.number > user.checkpoint) {
bonusToken.transfer(msg.sender, mintableBonusTokens * user.balance / totalBalance);
user.checkpoint = block.number;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.7.2;

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

contract LpToken is ERC20 {
constructor() ERC20('Lp Token', 'LTK') {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const LpToken = artifacts.require('LpToken.sol');
const BonusToken = artifacts.require('BonusToken.sol');
const LiquidityMining = artifacts.require('LiquidityMining.sol');

module.exports = async function (deployer) {
await deployer.deploy(LpToken);
const lpToken = await LpToken.deployed();

await deployer.deploy(BonusToken);
const bonusToken = await BonusToken.deployed();

await deployer.deploy(LiquidityMining, lpToken.address, bonusToken.address);
const liquidityMining = await LiquidityMining.deployed();
await bonusToken.transferOwnership(liquidityMining.address);
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "yield-farming",
"version": "1.0.0",
"main": "truffle-config.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@openzeppelin/contracts": "^3.2.1-solc-0.7"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Use this file to configure your truffle project. It's seeded with some
* common settings for different networks and features like migrations,
* compilation and testing. Uncomment the ones you need or modify
* them to suit your project as necessary.
*
* More information about configuration can be found at:
*
* trufflesuite.com/docs/advanced/configuration
*
* To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)
* to sign your transactions before they're sent to a remote public node. Infura accounts
* are available for free at: infura.io/register.
*
* You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
* public/private key pairs. If you're publishing your code to GitHub make sure you load this
* phrase from a file you've .gitignored so it doesn't accidentally become public.
*
*/

// const HDWalletProvider = require('@truffle/hdwallet-provider');
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
/**
* Networks define how you connect to your ethereum client and let you set the
* defaults web3 uses to send transactions. If you don't specify one truffle
* will spin up a development blockchain for you on port 9545 when you
* run `develop` or `test`. You can ask a truffle command to use a specific
* network from the command line, e.g
*
* $ truffle test --network <network-name>
*/

networks: {
// Useful for testing. The `development` name is special - truffle uses it by default
// if it's defined here and no other network is specified at the command line.
// You should run a client (like ganache-cli, geth or parity) in a separate terminal
// tab if you use this network and you must also set the `host`, `port` and `network_id`
// options below to some value.
//
// development: {
// host: "127.0.0.1", // Localhost (default: none)
// port: 8545, // Standard Ethereum port (default: none)
// network_id: "*", // Any network (default: none)
// },
// Another network with more advanced options...
// advanced: {
// port: 8777, // Custom port
// network_id: 1342, // Custom network
// gas: 8500000, // Gas sent with each transaction (default: ~6700000)
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
// from: <address>, // Account to send txs from (default: accounts[0])
// websockets: true // Enable EventEmitter interface for web3 (default: false)
// },
// Useful for deploying to a public network.
// NB: It's important to wrap the provider as a function.
// ropsten: {
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
// network_id: 3, // Ropsten's id
// gas: 5500000, // Ropsten has a lower block limit than mainnet
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
// },
// Useful for private networks
// private: {
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
// network_id: 2111, // This network is yours, in the cloud.
// production: true // Treats this network as if it was a public net. (default: false)
// }
},

// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},

// Configure your compilers
compilers: {
solc: {
version: "0.7.2", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: "byzantium"
// }
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.7.2;

contract YieldFarmer {
function rebalance() external {
uint yieldA = pricer.getYieldA();
uint yieldB = pricer.getYieldB();
uint yieldC = pricer.getYieldC();
if(yieldA >= yieldB && yieldA >= yieldC) {

}
if(yieldB >= yieldA && yieldB >= yieldC) {
}
if(yieldC >= yieldA && yieldC >= yieldB) {
}
}

function getYieldA() public view returns(uint) {
}
function getYieldB() public view returns(uint) {
}
function getYieldC() public view returns(uint) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Use this file to configure your truffle project. It's seeded with some
* common settings for different networks and features like migrations,
* compilation and testing. Uncomment the ones you need or modify
* them to suit your project as necessary.
*
* More information about configuration can be found at:
*
* trufflesuite.com/docs/advanced/configuration
*
* To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)
* to sign your transactions before they're sent to a remote public node. Infura accounts
* are available for free at: infura.io/register.
*
* You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
* public/private key pairs. If you're publishing your code to GitHub make sure you load this
* phrase from a file you've .gitignored so it doesn't accidentally become public.
*
*/

// const HDWalletProvider = require('@truffle/hdwallet-provider');
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
/**
* Networks define how you connect to your ethereum client and let you set the
* defaults web3 uses to send transactions. If you don't specify one truffle
* will spin up a development blockchain for you on port 9545 when you
* run `develop` or `test`. You can ask a truffle command to use a specific
* network from the command line, e.g
*
* $ truffle test --network <network-name>
*/

networks: {
// Useful for testing. The `development` name is special - truffle uses it by default
// if it's defined here and no other network is specified at the command line.
// You should run a client (like ganache-cli, geth or parity) in a separate terminal
// tab if you use this network and you must also set the `host`, `port` and `network_id`
// options below to some value.
//
// development: {
// host: "127.0.0.1", // Localhost (default: none)
// port: 8545, // Standard Ethereum port (default: none)
// network_id: "*", // Any network (default: none)
// },
// Another network with more advanced options...
// advanced: {
// port: 8777, // Custom port
// network_id: 1342, // Custom network
// gas: 8500000, // Gas sent with each transaction (default: ~6700000)
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
// from: <address>, // Account to send txs from (default: accounts[0])
// websockets: true // Enable EventEmitter interface for web3 (default: false)
// },
// Useful for deploying to a public network.
// NB: It's important to wrap the provider as a function.
// ropsten: {
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
// network_id: 3, // Ropsten's id
// gas: 5500000, // Ropsten has a lower block limit than mainnet
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
// },
// Useful for private networks
// private: {
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
// network_id: 2111, // This network is yours, in the cloud.
// production: true // Treats this network as if it was a public net. (default: false)
// }
},

// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},

// Configure your compilers
compilers: {
solc: {
version: "0.7.2", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: "byzantium"
// }
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pragma solidity ^0.7.2;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import './Flashloan.sol';
import './IFlashloanCallee.sol';

contract ExampleFlashloanCallee is IFlashloanCallee {
function startFlashloan(
address flashloan,
uint amount,
address token
)
external
{
Flashloan(flashloan).executeFlashloan(
address(this),
amount,
token,
bytes('')
);
}

function flashloanCallback(
uint amount,
address token,
bytes memory data
)
override
external
{
//do some arbitrage, liquidation, etc..
IERC20(token).transfer(msg.sender, amount);
}
}
Loading

0 comments on commit 7290d43

Please sign in to comment.