Skip to content

Commit

Permalink
Adds linting for typescript and solidity (#24)
Browse files Browse the repository at this point in the history
* Add solidity linting

* Add linting to typescript, remove unnecesary files

* Add lint workflow

* Update yarn actions version

* Use yarn action master version
  • Loading branch information
MickdeGraaf authored May 21, 2020
1 parent 0d6c2c6 commit f8ae70f
Show file tree
Hide file tree
Showing 73 changed files with 3,916 additions and 3,935 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint

on:
pull_request:
branches: [ '*' ]

jobs:
lint:
name: with tslint and solhint
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x]

steps:
- uses: actions/checkout@v2
- uses: borales/actions-yarn@master
with:
cmd: install # will run `yarn install` command
- uses: borales/actions-yarn@master
with:
cmd: lint # will run `yarn lint` command
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}
6 changes: 6 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "solhint:default",
"rules": {
"max-line-length": ["error", 100]
}
}
134 changes: 66 additions & 68 deletions contracts/factory/PProxiedFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,74 @@ import "../interfaces/IERC20.sol";
import "../Ownable.sol";
import "../smart-pools/PCappedSmartPool.sol";


contract PProxiedFactory is Ownable {
IBFactory public balancerFactory;
address public smartPoolImplementation;
mapping(address => bool) public isPool;
address[] public pools;

IBFactory public balancerFactory;
address public smartPoolImplementation;
mapping(address => bool) public isPool;
address[] public pools;

event SmartPoolCreated(address indexed poolAddress, string name, string symbol);

function init(address _balancerFactory) public {
require(smartPoolImplementation == address(0), "Already initialised");
_setOwner(msg.sender);
balancerFactory = IBFactory(_balancerFactory);

PCappedSmartPool implementation = new PCappedSmartPool();
// function init(address _bPool, string calldata _name, string calldata _symbol, uint256 _initialSupply) external {
implementation.init(address(1), "IMPL", "IMPL", 1 ether);
smartPoolImplementation = address(implementation);
}
event SmartPoolCreated(address indexed poolAddress, string name, string symbol);

function init(address _balancerFactory) public {
require(smartPoolImplementation == address(0), "Already initialised");
_setOwner(msg.sender);
balancerFactory = IBFactory(_balancerFactory);

PCappedSmartPool implementation = new PCappedSmartPool();
implementation.init(address(1), "IMPL", "IMPL", 1 ether);
smartPoolImplementation = address(implementation);
}

function newProxiedSmartPool(
string memory _name,
string memory _symbol,
uint256 _initialSupply,
address[] memory _tokens,
uint256[] memory _amounts,
uint256[] memory _weights,
uint256 _cap
) public onlyOwner returns (address) {
// Deploy proxy contract
PProxyPausable proxy = new PProxyPausable();

// Setup proxy
proxy.setImplementation(smartPoolImplementation);
proxy.setPauzer(msg.sender);
proxy.setProxyOwner(msg.sender);

function newProxiedSmartPool(
string memory _name,
string memory _symbol,
uint256 _initialSupply,
address[] memory _tokens,
uint256[] memory _amounts,
uint256[] memory _weights,
uint256 _cap
) public onlyOwner returns(address) {
// Deploy proxy contract
PProxyPausable proxy = new PProxyPausable();

// Setup proxy
proxy.setImplementation(smartPoolImplementation);
proxy.setPauzer(msg.sender);
proxy.setProxyOwner(msg.sender);

// Setup balancer pool
address balancerPoolAddress = balancerFactory.newBPool();
IBPool bPool = IBPool(balancerPoolAddress);

for(uint256 i = 0; i < _tokens.length; i ++) {
IERC20 token = IERC20(_tokens[i]);
// Transfer tokens to this contract
token.transferFrom(msg.sender, address(this), _amounts[i]);
// Approve the balancer pool
token.approve(balancerPoolAddress, uint256(-1));
// Bind tokens
bPool.bind(_tokens[i], _amounts[i], _weights[i]);
}
bPool.setController(address(proxy));

// Setup smart pool
PCappedSmartPool smartPool = PCappedSmartPool(address(proxy));

smartPool.init(balancerPoolAddress, _name, _symbol, _initialSupply);
smartPool.setCap(_cap);
smartPool.setPublicSwapSetter(msg.sender);
smartPool.setTokenBinder(msg.sender);
smartPool.setController(msg.sender);
smartPool.approveTokens();

isPool[address(smartPool)] = true;
pools.push(address(smartPool));

emit SmartPoolCreated(address(smartPool), _name, _symbol);

smartPool.transfer(msg.sender, _initialSupply);

return address(smartPool);
// Setup balancer pool
address balancerPoolAddress = balancerFactory.newBPool();
IBPool bPool = IBPool(balancerPoolAddress);

for (uint256 i = 0; i < _tokens.length; i++) {
IERC20 token = IERC20(_tokens[i]);
// Transfer tokens to this contract
token.transferFrom(msg.sender, address(this), _amounts[i]);
// Approve the balancer pool
token.approve(balancerPoolAddress, uint256(-1));
// Bind tokens
bPool.bind(_tokens[i], _amounts[i], _weights[i]);
}
bPool.setController(address(proxy));

// Setup smart pool
PCappedSmartPool smartPool = PCappedSmartPool(address(proxy));

smartPool.init(balancerPoolAddress, _name, _symbol, _initialSupply);
smartPool.setCap(_cap);
smartPool.setPublicSwapSetter(msg.sender);
smartPool.setTokenBinder(msg.sender);
smartPool.setController(msg.sender);
smartPool.approveTokens();

isPool[address(smartPool)] = true;
pools.push(address(smartPool));

emit SmartPoolCreated(address(smartPool), _name, _symbol);

smartPool.transfer(msg.sender, _initialSupply);

}
return address(smartPool);
}
}
5 changes: 3 additions & 2 deletions contracts/interfaces/IBFactory.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity ^0.6.4;


interface IBFactory {
function newBPool() external returns (address);
}
function newBPool() external returns (address);
}
132 changes: 73 additions & 59 deletions contracts/interfaces/IBPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,77 @@

pragma solidity 0.6.4;


interface IBPool {
function isBound(address token) external view returns(bool);
function getBalance(address token) external view returns (uint);
function rebind(address token, uint balance, uint denorm) external;
function setSwapFee(uint swapFee) external;
function setPublicSwap(bool _public) external;
function bind(address token, uint balance, uint denorm) external;
function unbind(address token) external;
function getDenormalizedWeight(address token) external view returns (uint);
function getTotalDenormalizedWeight() external view returns (uint);
function getCurrentTokens() external view returns(address[] memory);
function setController(address manager) external;
function isPublicSwap() external view returns(bool);
function getSwapFee() external view returns (uint256);
function gulp(address token) external;

function calcPoolOutGivenSingleIn(
uint tokenBalanceIn,
uint tokenWeightIn,
uint poolSupply,
uint totalWeight,
uint tokenAmountIn,
uint swapFee
)
external pure
returns (uint poolAmountOut);

function calcSingleInGivenPoolOut(
uint tokenBalanceIn,
uint tokenWeightIn,
uint poolSupply,
uint totalWeight,
uint poolAmountOut,
uint swapFee
)
external pure
returns (uint tokenAmountIn);

function calcSingleOutGivenPoolIn(
uint tokenBalanceOut,
uint tokenWeightOut,
uint poolSupply,
uint totalWeight,
uint poolAmountIn,
uint swapFee
)
external pure
returns (uint tokenAmountOut);

function calcPoolInGivenSingleOut(
uint tokenBalanceOut,
uint tokenWeightOut,
uint poolSupply,
uint totalWeight,
uint tokenAmountOut,
uint swapFee
)
external pure
returns (uint poolAmountIn);
}
function isBound(address token) external view returns (bool);

function getBalance(address token) external view returns (uint256);

function rebind(
address token,
uint256 balance,
uint256 denorm
) external;

function setSwapFee(uint256 swapFee) external;

function setPublicSwap(bool _public) external;

function bind(
address token,
uint256 balance,
uint256 denorm
) external;

function unbind(address token) external;

function getDenormalizedWeight(address token) external view returns (uint256);

function getTotalDenormalizedWeight() external view returns (uint256);

function getCurrentTokens() external view returns (address[] memory);

function setController(address manager) external;

function isPublicSwap() external view returns (bool);

function getSwapFee() external view returns (uint256);

function gulp(address token) external;

function calcPoolOutGivenSingleIn(
uint256 tokenBalanceIn,
uint256 tokenWeightIn,
uint256 poolSupply,
uint256 totalWeight,
uint256 tokenAmountIn,
uint256 swapFee
) external pure returns (uint256 poolAmountOut);

function calcSingleInGivenPoolOut(
uint256 tokenBalanceIn,
uint256 tokenWeightIn,
uint256 poolSupply,
uint256 totalWeight,
uint256 poolAmountOut,
uint256 swapFee
) external pure returns (uint256 tokenAmountIn);

function calcSingleOutGivenPoolIn(
uint256 tokenBalanceOut,
uint256 tokenWeightOut,
uint256 poolSupply,
uint256 totalWeight,
uint256 poolAmountIn,
uint256 swapFee
) external pure returns (uint256 tokenAmountOut);

function calcPoolInGivenSingleOut(
uint256 tokenBalanceOut,
uint256 tokenWeightOut,
uint256 poolSupply,
uint256 totalWeight,
uint256 tokenAmountOut,
uint256 swapFee
) external pure returns (uint256 poolAmountIn);
}
33 changes: 20 additions & 13 deletions contracts/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
pragma solidity ^0.6.4;


interface IERC20 {
event Approval(address indexed _src, address indexed _dst, uint _amount);
event Transfer(address indexed _src, address indexed _dst, uint _amount);

function totalSupply() external view returns (uint);
function balanceOf(address _whom) external view returns (uint);
function allowance(address _src, address _dst) external view returns (uint);

function approve(address _dst, uint _amount) external returns (bool);
function transfer(address _dst, uint _amount) external returns (bool);
function transferFrom(
address _src, address _dst, uint _amount
) external returns (bool);
}
event Approval(address indexed _src, address indexed _dst, uint256 _amount);
event Transfer(address indexed _src, address indexed _dst, uint256 _amount);

function totalSupply() external view returns (uint256);

function balanceOf(address _whom) external view returns (uint256);

function allowance(address _src, address _dst) external view returns (uint256);

function approve(address _dst, uint256 _amount) external returns (bool);

function transfer(address _dst, uint256 _amount) external returns (bool);

function transferFrom(
address _src,
address _dst,
uint256 _amount
) external returns (bool);
}
22 changes: 11 additions & 11 deletions contracts/interfaces/IKyberNetwork.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pragma solidity ^0.6.4;

interface IKyberNetwork {

function trade(
address src,
uint srcAmount,
address dest,
address payable destAddress,
uint maxDestAmount,
uint minConversionRate,
address walletId
) external payable returns(uint256);
}
interface IKyberNetwork {
function trade(
address src,
uint256 srcAmount,
address dest,
address payable destAddress,
uint256 maxDestAmount,
uint256 minConversionRate,
address walletId
) external payable returns (uint256);
}
Loading

0 comments on commit f8ae70f

Please sign in to comment.