formating stores.sol;

fixing import for SafeERC20 and IERC20;
set up constructor for synthetix connector to set address for staking contract;
created MockSynthetix.sol for test;
added nomiclabs/buidler;
fixed test for SynthetixProtocol.js;
adding .gitatributes to highlight solidity on GitHub;
adding buidler artefacts and cache to git ignore;
adding buidler.config.js;
This commit is contained in:
Lecky Lao 2020-07-12 02:04:48 +10:00
parent cdb8bf01eb
commit becd0135aa
14 changed files with 3727 additions and 86 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.sol linguist-language=Solidity

5
.gitignore vendored
View File

@ -58,5 +58,8 @@ Thumbs.db
.com.apple.timemachine.donotpresent .com.apple.timemachine.donotpresent
# truffle # truffle
build/contracts build/contracts
# buidler
artifacts
cache

11
buidler.config.js Normal file
View File

@ -0,0 +1,11 @@
usePlugin("@nomiclabs/buidler-truffle5");
// You have to export an object to set up your config
// This object can have the following optional entries:
// defaultNetwork, networks, solc, and paths.
// Go to https://buidler.dev/config/ to learn more
module.exports = {
// This is a sample solc configuration that specifies which version of solc to use
solc: {
version: "0.6.2",
},
};

View File

@ -5,54 +5,54 @@ import { MemoryInterface, EventInterface} from "./interfaces.sol";
contract Stores { contract Stores {
/** /**
* @dev Return ethereum address * @dev Return ethereum address
*/ */
function getEthAddr() internal pure returns (address) { function getEthAddr() internal pure returns (address) {
return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address
} }
/** /**
* @dev Return memory variable address * @dev Return memory variable address
*/ */
function getMemoryAddr() internal pure returns (address) { function getMemoryAddr() internal pure returns (address) {
return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address
} }
/** /**
* @dev Return InstaEvent Address. * @dev Return InstaEvent Address.
*/ */
function getEventAddr() internal pure returns (address) { function getEventAddr() internal pure returns (address) {
return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; // InstaEvent Address return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; // InstaEvent Address
} }
/** /**
* @dev Get Uint value from InstaMemory Contract. * @dev Get Uint value from InstaMemory Contract.
*/ */
function getUint(uint getId, uint val) internal returns (uint returnVal) { function getUint(uint getId, uint val) internal returns (uint returnVal) {
returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId); returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId);
} }
/** /**
* @dev Set Uint value in InstaMemory Contract. * @dev Set Uint value in InstaMemory Contract.
*/ */
function setUint(uint setId, uint val) internal { function setUint(uint setId, uint val) virtual internal {
if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val); if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val);
} }
/** /**
* @dev emit event on event contract * @dev emit event on event contract
*/ */
function emitEvent(bytes32 eventCode, bytes memory eventData) internal { function emitEvent(bytes32 eventCode, bytes memory eventData) virtual internal {
(uint model, uint id) = connectorID(); (uint model, uint id) = connectorID();
EventInterface(getEventAddr()).emitEvent(model, id, eventCode, eventData); EventInterface(getEventAddr()).emitEvent(model, id, eventCode, eventData);
} }
/** /**
* @dev Connector Details - needs to be changed before deployment * @dev Connector Details - needs to be changed before deployment
*/ */
function connectorID() public view returns(uint model, uint id) { function connectorID() public view returns(uint model, uint id) {
(model, id) = (0, 0); (model, id) = (0, 0);
} }
} }

View File

@ -1,6 +1,7 @@
pragma solidity ^0.6.0; pragma solidity ^0.6.0;
import "../../node_modules/@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
// import files from common directory // import files from common directory
import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol";
@ -85,4 +86,4 @@ contract BasicResolver is Stores {
contract ConnectBasic is BasicResolver { contract ConnectBasic is BasicResolver {
string public constant name = "Basic-v1.1"; string public constant name = "Basic-v1.1";
} }

View File

@ -1,7 +1,8 @@
pragma solidity ^0.6.0; pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../node_modules/@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface LiqudityInterface { interface LiqudityInterface {
function deposit(address, uint) external payable; function deposit(address, uint) external payable;
@ -308,4 +309,4 @@ contract LiquidityAccess is LiquidityManage {
contract ConnectInstaPool is LiquidityAccess { contract ConnectInstaPool is LiquidityAccess {
string public name = "InstaPool-v2"; string public name = "InstaPool-v2";
} }

View File

@ -13,16 +13,22 @@ interface IStakingRewards {
} }
contract SynthetixStakingHelper is DSMath, Stores { contract SynthetixStakingHelper is DSMath, Stores {
IStakingRewards stakingContract;
constructor(address _synthetixStakingAddr) public {
stakingContract = IStakingRewards(_synthetixStakingAddr);
}
/** /**
* @dev Return Synthetix staking pool address. * @dev Return Synthetix staking pool address.
*/ */
function getSynthetixStakingAddr(address token) virtual internal view returns (address){ function getSynthetixStakingAddr(address token) virtual internal {
if (token == address(0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3)){ if (token == address(0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3)){
// SBTC // SBTC
return 0x13C1542A468319688B89E323fe9A3Be3A90EBb27; stakingContract = IStakingRewards(0x13C1542A468319688B89E323fe9A3Be3A90EBb27);
} else if (token == address(0xC25a3A3b969415c80451098fa907EC722572917F)){ } else if (token == address(0xC25a3A3b969415c80451098fa907EC722572917F)){
// SUSD // SUSD
return 0xDCB6A51eA3CA5d3Fd898Fd6564757c7aAeC3ca92; stakingContract = IStakingRewards(0xDCB6A51eA3CA5d3Fd898Fd6564757c7aAeC3ca92);
} else { } else {
revert("token-not-found"); revert("token-not-found");
} }
@ -31,13 +37,15 @@ contract SynthetixStakingHelper is DSMath, Stores {
/** /**
* @dev Return Synthetix Token address. * @dev Return Synthetix Token address.
*/ */
function getSnxAddr() internal pure returns (address) { function getSnxAddr() virtual internal view returns (address) {
return 0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F; return 0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F;
} }
} }
contract SynthetixStaking is SynthetixStakingHelper { contract SynthetixStaking is SynthetixStakingHelper {
constructor(address _synthetixStakingAddr) SynthetixStakingHelper(_synthetixStakingAddr) public {}
// Events // Events
event LogDeposit( event LogDeposit(
address token, address token,
@ -71,7 +79,7 @@ contract SynthetixStaking is SynthetixStakingHelper {
uint setId uint setId
) external payable { ) external payable {
uint _amt = getUint(getId, amt); uint _amt = getUint(getId, amt);
IStakingRewards stakingContract = IStakingRewards(getSynthetixStakingAddr(token)); getSynthetixStakingAddr(token);
TokenInterface _stakeToken = TokenInterface(token); TokenInterface _stakeToken = TokenInterface(token);
_amt = _amt == uint(-1) ? _stakeToken.balanceOf(address(this)) : _amt; _amt = _amt == uint(-1) ? _stakeToken.balanceOf(address(this)) : _amt;
@ -101,7 +109,7 @@ contract SynthetixStaking is SynthetixStakingHelper {
uint setIdReward uint setIdReward
) external payable { ) external payable {
uint _amt = getUint(getId, amt); uint _amt = getUint(getId, amt);
IStakingRewards stakingContract = IStakingRewards(getSynthetixStakingAddr(token)); getSynthetixStakingAddr(token);
TokenInterface snxToken = TokenInterface(getSnxAddr()); TokenInterface snxToken = TokenInterface(getSnxAddr());
uint intialBal = snxToken.balanceOf(address(this)); uint intialBal = snxToken.balanceOf(address(this));
@ -138,7 +146,7 @@ contract SynthetixStaking is SynthetixStakingHelper {
address token, address token,
uint setId uint setId
) external payable { ) external payable {
IStakingRewards stakingContract = IStakingRewards(getSynthetixStakingAddr(token)); getSynthetixStakingAddr(token);
TokenInterface snxToken = TokenInterface(getSnxAddr()); TokenInterface snxToken = TokenInterface(getSnxAddr());
uint intialBal = snxToken.balanceOf(address(this)); uint intialBal = snxToken.balanceOf(address(this));
@ -157,4 +165,7 @@ contract SynthetixStaking is SynthetixStakingHelper {
contract ConnectSynthetixStaking is SynthetixStaking { contract ConnectSynthetixStaking is SynthetixStaking {
string public name = "synthetix-staking-v1"; string public name = "synthetix-staking-v1";
constructor(address _synthetixStakingAddr) SynthetixStaking(_synthetixStakingAddr) public {}
} }

View File

@ -3,17 +3,19 @@ pragma solidity ^0.6.0;
import { ConnectSynthetixStaking } from "../connectors/synthetix.sol"; import { ConnectSynthetixStaking } from "../connectors/synthetix.sol";
contract MockSynthetixStaking is ConnectSynthetixStaking{ contract MockSynthetixStaking is ConnectSynthetixStaking{
// uint public _model;
// uint public _id;
address public synthetixStakingAddr; address public synthetixStakingAddr;
constructor(address _synthetixStakingAddr) public { constructor(address _synthetixStakingAddr) ConnectSynthetixStaking(_synthetixStakingAddr) public {
// _model = model;
// _id = id;
synthetixStakingAddr = _synthetixStakingAddr; synthetixStakingAddr = _synthetixStakingAddr;
} }
function getSynthetixStakingAddr(address token) override internal view returns (address){ function getSynthetixStakingAddr(address token) override internal{}
function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {}
function getSnxAddr() override internal view returns (address) {
return synthetixStakingAddr; return synthetixStakingAddr;
} }
function setUint(uint setId, uint val) override internal {}
} }

View File

@ -2,6 +2,7 @@
// const ConnectSBTCCurve = artifacts.require("ConnectSBTCCurve"); // const ConnectSBTCCurve = artifacts.require("ConnectSBTCCurve");
const MockContract = artifacts.require("MockContract"); const MockContract = artifacts.require("MockContract");
const MockSynthetixStaking = artifacts.require("MockSynthetixStaking"); const MockSynthetixStaking = artifacts.require("MockSynthetixStaking");
// const ConnectSynthetixStaking = artifacts.require("ConnectSynthetixStaking");
// const connectorsABI = require("../test/abi/connectors.json"); // const connectorsABI = require("../test/abi/connectors.json");
// let connectorsAddr = "0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c"; // let connectorsAddr = "0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c";
@ -12,6 +13,7 @@ module.exports = async function(deployer) {
// let connectorLength = await connectorInstance.methods.connectorLength().call(); // let connectorLength = await connectorInstance.methods.connectorLength().call();
deployer.deploy(MockContract).then(function () { deployer.deploy(MockContract).then(function () {
// return deployer.deploy(MockSynthetixStaking, MockContract.address, 1, +connectorLength + 1); // return deployer.deploy(MockSynthetixStaking, MockContract.address, 1, +connectorLength + 1);
// return deployer.deploy(ConnectSynthetixStaking, MockContract.address);
return deployer.deploy(MockSynthetixStaking, MockContract.address); return deployer.deploy(MockSynthetixStaking, MockContract.address);
}); });

3584
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -36,11 +36,15 @@
"truffle-verify": "^1.0.8" "truffle-verify": "^1.0.8"
}, },
"devDependencies": { "devDependencies": {
"@nomiclabs/buidler": "^1.3.8",
"@nomiclabs/buidler-truffle5": "^1.3.4",
"@nomiclabs/buidler-web3": "^1.3.4",
"@openzeppelin/test-helpers": "^0.5.6", "@openzeppelin/test-helpers": "^0.5.6",
"@studydefi/money-legos": "^2.3.5", "@studydefi/money-legos": "^2.3.5",
"ganache-cli": "^6.10.0-beta.2", "ganache-cli": "^6.10.0-beta.2",
"sol-merger": "^2.0.1", "sol-merger": "^2.0.1",
"solidity-coverage": "0.5.11", "solidity-coverage": "0.5.11",
"solium": "1.2.3" "solium": "1.2.3",
"web3": "^1.2.9"
} }
} }

View File

@ -78,8 +78,6 @@ contract('ConnectSBTCCurve', async accounts => {
// Send ETH to master // Send ETH to master
await web3.eth.sendTransaction({from: sender, to: masterAddress, value: ether("5")}); await web3.eth.sendTransaction({from: sender, to: masterAddress, value: ether("5")});
let connectorID = await connectSBTCCurve.connectorID();
// Enable the the given connector address // Enable the the given connector address
await connectorInstance.methods.enable(connectSBTCCurve.address).send({from: masterAddress}); await connectorInstance.methods.enable(connectSBTCCurve.address).send({from: masterAddress});
// check if the give connector address is enabled. // check if the give connector address is enabled.

View File

@ -8,24 +8,72 @@ const {
const MockContract = artifacts.require("MockContract"); const MockContract = artifacts.require("MockContract");
const MockSynthetixStaking = artifacts.require('MockSynthetixStaking'); const MockSynthetixStaking = artifacts.require('MockSynthetixStaking');
// const ConnectSynthetixStaking = artifacts.require('ConnectSynthetixStaking');
const erc20ABI = require("./abi/erc20.js"); const erc20ABI = require("./abi/erc20.js");
const synthetixStaking = require("./abi/synthetixStaking.json");
contract('ConnectSynthetixStaking', async accounts => { contract('ConnectSynthetixStaking', async accounts => {
const [sender, receiver] = accounts; const [sender, receiver] = accounts;
const mock = await MockContract.deployed(); let mock, mockSynthetixStaking, stakingContract, token;
const mockSynthetixStaking = await MockSynthetixStaking.deployed();
const crvRenWSBTCContract = new web3.eth.Contract(erc20ABI, mock.address);
before(async function () { before(async function () {
let methodId = await crvRenWSBTCContract.methods.balanceOf(sender).encodeABI(); // const connectSynthetixStaking = await ConnectSynthetixStaking.deployed();
await mock.givenMethodReturnUint(methodId, 10000000); mock = await MockContract.new();
mockSynthetixStaking = await MockSynthetixStaking.new(mock.address);
stakingContract = new web3.eth.Contract(synthetixStaking, mock.address);
token = new web3.eth.Contract(erc20ABI, mock.address);
let crvRenWSBTC = await crvRenWSBTCContract.methods.balanceOf(sender).call(); // mocking balanceOf
let balanceOf = await token.methods.balanceOf(mockSynthetixStaking.address).encodeABI();
await mock.givenMethodReturnUint(balanceOf, 10000000);
// mocking approve
let approve = await token.methods.approve(mockSynthetixStaking.address, 10000000).encodeABI();
await mock.givenMethodReturnBool(approve, "true");
expect(crvRenWSBTC).to.equal("10000000");
}) })
it('can mock token', async function() { it('can deposit', async function() {
// expect(wbtcAfter - wbtcBefore).to.be.at.least(10000000); // mocking stake
let stake = await stakingContract.methods.stake(10000000).encodeABI();
await mock.givenMethodReturnBool(stake, "true");
const tx = await mockSynthetixStaking.deposit(
mock.address,
10000000,
0,
0
)
expectEvent(tx, "LogDeposit");
});
it('can withdraw', async function() {
// mocking withdraw
let withdraw = await stakingContract.methods.withdraw(10000000).encodeABI();
await mock.givenMethodReturnBool(withdraw, "true");
// mocking getReward
let reward = await stakingContract.methods.getReward().encodeABI();
await mock.givenMethodReturnBool(reward, "true");
const tx = await mockSynthetixStaking.withdraw(
mock.address,
10000000,
0,
111,
112
)
expectEvent(tx, "LogWithdraw");
expectEvent(tx, "LogClaimedReward");
});
it('can claim reward', async function() {
// mocking getReward
let reward = await stakingContract.methods.getReward().encodeABI();
await mock.givenMethodReturnBool(reward, "true");
const tx = await mockSynthetixStaking.claimReward(
mock.address,
112
)
expectEvent(tx, "LogClaimedReward");
}); });
}) })

File diff suppressed because one or more lines are too long