Skip to content
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
node_modules
.vscode
# .vscode
!.vscode/launch.json

.env

#Hardhat files
cache
artifacts

#hardhat-deploy
/deployments
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch via NPM",
"request": "launch",
"runtimeArgs": [
"run-script",
"deploy:celo"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
},
]
}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ npm run test
npm run compile
```

# Hardhat Tasks
- Deploy InfinityProtocol
```
npx hardhat deploy_infinityProtocol --router [router_address] --network [network_name]
```
- Deploy LiquidVault
```
npx hardhat deploy_liquidVault --network [network_name]
```
- Deploy FeeDistributor
```
npx hardhat deploy_liquidVault --network [network_name]
```

2 changes: 1 addition & 1 deletion contracts/InfinityProtocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract InfinityProtocol is IInfinityProtocol, Context, Ownable {
return _SYMBOL;
}

function decimals() public pure returns (uint8) {
function decimals() public pure override returns (uint8) {
return _DECIMALS;
}

Expand Down
89 changes: 89 additions & 0 deletions contracts/PriceOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.7.4;
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
import '@uniswap/lib/contracts/libraries/FixedPoint.sol';
import '@uniswap/v2-periphery/contracts/libraries/UniswapV2OracleLibrary.sol';
import "./interfaces/IERC20.sol";


contract PriceOracle {
using FixedPoint for *;
IUniswapV2Pair public immutable pair;
uint public multiplier;
uint private priceLast;
uint public priceCumulativeLast;
uint32 public blockTimestampLast;

address public tokenA;
address public tokenB;
address public token0;

constructor(IUniswapV2Pair _pair, address _tokenA, address _tokenB) public {
pair = _pair;
tokenA = _tokenA;
tokenB = _tokenB;
(token0, ) = _tokenA < _tokenB
? (_tokenA, _tokenB)
: (_tokenB, _tokenA);

if(token0 == _tokenA) {
priceCumulativeLast = _pair.price0CumulativeLast();
multiplier = uint(10)**(IERC20(_pair.token0()).decimals());
} else {
priceCumulativeLast = _pair.price1CumulativeLast();
multiplier = uint(10)**(IERC20(_pair.token1()).decimals());
}
}
function update() public returns(uint) {
uint112 reserve0;
uint112 reserve1;
(reserve0, reserve1, blockTimestampLast) = pair.getReserves();
require(reserve0 != 0 && reserve1 != 0, 'PriceOracle: NO_RESERVES');

uint _priceCumulative;
(uint _price0Cumulative, uint _price1Cumulative, uint32 _blockTimestamp) =
UniswapV2OracleLibrary.currentCumulativePrices(address(pair));
if(token0 == tokenA) {
_priceCumulative = _price0Cumulative;
} else {
_priceCumulative = _price1Cumulative;
}
uint _priceCumulativeLast = priceCumulativeLast;
uint _blockTimestampLast = blockTimestampLast;
uint _price;
if (_blockTimestamp != _blockTimestampLast) {
_price = FixedPoint.uq112x112(uint224((_priceCumulative - _priceCumulativeLast) /
(_blockTimestamp - _blockTimestampLast))).mul(multiplier).decode144();
priceLast = _price;
priceCumulativeLast = _priceCumulative;
blockTimestampLast = _blockTimestamp;
} else {
_price = priceLast;
}
return _price;
}
// note this will always return 0 before update has been called successfully for the first time.
function consult() external view returns (uint) {
uint _priceCumulative;

(uint _price0Cumulative, uint _price1Cumulative, uint32 _blockTimestamp) =
UniswapV2OracleLibrary.currentCumulativePrices(address(pair));

if(token0 == tokenA) {
_priceCumulative = _price0Cumulative;
} else {
_priceCumulative = _price1Cumulative;
}
uint _priceCumulativeLast = priceCumulativeLast;
uint _blockTimestampLast = blockTimestampLast;
// most recent price is already calculated.
if (_blockTimestamp == _blockTimestampLast) {
return priceLast;
}
return FixedPoint.uq112x112(uint224((_priceCumulative - _priceCumulativeLast) /
(_blockTimestamp - _blockTimestampLast))).mul(multiplier).decode144();
}
function updateAndConsult() external returns (uint) {
return update();
}
}
2 changes: 2 additions & 0 deletions contracts/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface IERC20 {
*/
function transfer(address recipient, uint256 amount) external returns (bool);

function decimals() external pure returns (uint8);

/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/IPriceOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma solidity 0.7.4;


interface IPriceOracle {
function update() external returns(uint);
}
19 changes: 19 additions & 0 deletions deploy/celo_infinityProtocol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Imports
const hardhat = require("hardhat");
require('dotenv').config();

// Load env var
const { ROUTER, FACTORY, FEE_RECEIVER, ALFAJORES_CELO } = process.env;

async function main() {
await hardhat.run("deploy_infinityProtocol", {router: ROUTER})
await hardhat.run("deploy_liquidVault", {})
await hardhat.run("deploy_feeDistributor", {})
}

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
8 changes: 7 additions & 1 deletion env
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
API_KEY='API_KEY'
FORNO_CELO_MAINNET='https://forno.celo.org'
FORNO_CELO_TESTNET='https://alfajores-forno.celo-testnet.org'
PRIVATE_KEY='KEY'
ROUTER='ROUTER'
UNISWAP_PAIR='PAIR'
FEE_RECEIVER='address'
ETHERSCAN_API_KEY=
ETHERSCAN_API_KEY=
PAIR=''
TOKENA=''
TOKENB=''
PRICE_ORACLE=''
49 changes: 31 additions & 18 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan");
// Hardhat Global Imports
const { task } = require('hardhat/config');
require('hardhat-deploy')
require('hardhat-deploy-ethers')
require('@nomiclabs/hardhat-waffle');
require('@nomiclabs/hardhat-ethers');
require('@nomiclabs/hardhat-etherscan');
require('dotenv').config()

const {API_KEY, PRIVATE_KEY, PRIVATE_KEY_MAINNET, ETHERSCAN_API_KEY} = process.env;
// Hardhat Tasks
require('./tasks/deploy_infinityProtocol')
require('./tasks/deploy_liquidVault')
require('./tasks/deploy_feeDistributor')

const {FORNO_CELO_MAINNET, FORNO_CELO_TESTNET, DEPLOYER_PRIVATE_KEY, OWNER_PRIVATE_KEY, ETHERSCAN_API_KEY, ROUTER} = process.env;

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async () => {
const accounts = await ethers.getSigners();

for (const account of accounts) {
console.log(account.address);
}
});
// task(
// "infinity-deploy",
// "Deploys - Infinity Protocol, Reality LVault, FeeD, seeds FeeD",
// ).addParam(
// "router",
// "Uniswap / Ubeswap Router Address for Infinity Protocol").setAction(async () => {

// });

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
Expand All @@ -22,13 +34,16 @@ task("accounts", "Prints the list of accounts", async () => {
*/
module.exports = {
networks: {
kovan: {
url: `https://kovan.infura.io/v3/${API_KEY}`,
accounts: [PRIVATE_KEY]
alfajores: {
url: FORNO_CELO_TESTNET,
accounts: [DEPLOYER_PRIVATE_KEY, OWNER_PRIVATE_KEY],
live: true,
gasPrice: 0.5 * 10 ** 9,
gas: 8000000,
},
mainnet: {
url: `https://mainnet.infura.io/v3/${API_KEY}`,
accounts: [PRIVATE_KEY_MAINNET]
celo_mainnet: {
url: FORNO_CELO_MAINNET,
accounts: [DEPLOYER_PRIVATE_KEY, OWNER_PRIVATE_KEY]
}
},
solidity: {
Expand All @@ -40,9 +55,7 @@ module.exports = {
}
}
},
gasPrice: "61000000000",
gas: "auto",

namedAccounts: { deployer: 0, tokenOwner: 1},
etherscan: {
apiKey: ETHERSCAN_API_KEY
}
Expand Down
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
"scripts": {
"test": "npx hardhat test",
"compile": "npx hardhat compile",
"deploy:kovan": "npx hardhat run scripts/infinity-deploy.js --network kovan",
"powerDeploy:kovan": "npx hardhat run scripts/power-vault-deploy.js --network kovan"
"deploy:alfajores": "npx hardhat run scripts/infinity-deploy.js --network alfajores",
"deploy:celo": "npx hardhat run --network alfajores scripts/celo-deploy.js",
"deploy:alfajoresOracle": "npx hardhat run scripts/oracle-deploy.js --network alfajores",
"deploy:celoMainnet": "npx hardhat run scripts/infinity-deploy.js --network celo_mainnet",
"deploy:celoMainnetOracle": "npx hardhat run scripts/oracle-deploy.js --network celo_mainnet",
"deploy:celoMainnetSpace": "npx hardhat run scripts/dual-vaults-space-deploy.js --network celo_mainnet",
"deploy:celoPower": "npx hardhat run scripts/power-vault-deploy.js --network celo_mainnet",
"deploy:alfajoresPower": "npx hardhat run scripts/power-vault-deploy.js --network alfajores"
},
"keywords": [],
"author": "",
Expand All @@ -18,13 +24,16 @@
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "^3.2.0",
"@openzeppelin/test-helpers": "^0.5.9",
"@ubeswap/core": "^1.0.2",
"@uniswap/v2-core": "^1.0.1",
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"assert": "2.0.0",
"chai": "^4.3.4",
"dotenv": "8.2.0",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.1.0",
"hardhat": "^2.1.2"
"hardhat": "^2.1.2",
"hardhat-deploy": "^0.8.9",
"hardhat-deploy-ethers": "^0.3.0-beta.10"
}
}
Loading