mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
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:
parent
cdb8bf01eb
commit
becd0135aa
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.sol linguist-language=Solidity
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -58,5 +58,8 @@ Thumbs.db
|
|||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# truffle
|
||||
|
||||
build/contracts
|
||||
|
||||
# buidler
|
||||
artifacts
|
||||
cache
|
||||
|
|
11
buidler.config.js
Normal file
11
buidler.config.js
Normal 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",
|
||||
},
|
||||
};
|
|
@ -36,14 +36,14 @@ contract Stores {
|
|||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
EventInterface(getEventAddr()).emitEvent(model, id, eventCode, eventData);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
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 { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol";
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
pragma solidity ^0.6.0;
|
||||
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 {
|
||||
function deposit(address, uint) external payable;
|
||||
|
|
|
@ -13,16 +13,22 @@ interface IStakingRewards {
|
|||
}
|
||||
|
||||
contract SynthetixStakingHelper is DSMath, Stores {
|
||||
IStakingRewards stakingContract;
|
||||
|
||||
constructor(address _synthetixStakingAddr) public {
|
||||
stakingContract = IStakingRewards(_synthetixStakingAddr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)){
|
||||
// SBTC
|
||||
return 0x13C1542A468319688B89E323fe9A3Be3A90EBb27;
|
||||
stakingContract = IStakingRewards(0x13C1542A468319688B89E323fe9A3Be3A90EBb27);
|
||||
} else if (token == address(0xC25a3A3b969415c80451098fa907EC722572917F)){
|
||||
// SUSD
|
||||
return 0xDCB6A51eA3CA5d3Fd898Fd6564757c7aAeC3ca92;
|
||||
stakingContract = IStakingRewards(0xDCB6A51eA3CA5d3Fd898Fd6564757c7aAeC3ca92);
|
||||
} else {
|
||||
revert("token-not-found");
|
||||
}
|
||||
|
@ -31,13 +37,15 @@ contract SynthetixStakingHelper is DSMath, Stores {
|
|||
/**
|
||||
* @dev Return Synthetix Token address.
|
||||
*/
|
||||
function getSnxAddr() internal pure returns (address) {
|
||||
function getSnxAddr() virtual internal view returns (address) {
|
||||
return 0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F;
|
||||
}
|
||||
}
|
||||
|
||||
contract SynthetixStaking is SynthetixStakingHelper {
|
||||
|
||||
constructor(address _synthetixStakingAddr) SynthetixStakingHelper(_synthetixStakingAddr) public {}
|
||||
|
||||
// Events
|
||||
event LogDeposit(
|
||||
address token,
|
||||
|
@ -71,7 +79,7 @@ contract SynthetixStaking is SynthetixStakingHelper {
|
|||
uint setId
|
||||
) external payable {
|
||||
uint _amt = getUint(getId, amt);
|
||||
IStakingRewards stakingContract = IStakingRewards(getSynthetixStakingAddr(token));
|
||||
getSynthetixStakingAddr(token);
|
||||
TokenInterface _stakeToken = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? _stakeToken.balanceOf(address(this)) : _amt;
|
||||
|
||||
|
@ -101,7 +109,7 @@ contract SynthetixStaking is SynthetixStakingHelper {
|
|||
uint setIdReward
|
||||
) external payable {
|
||||
uint _amt = getUint(getId, amt);
|
||||
IStakingRewards stakingContract = IStakingRewards(getSynthetixStakingAddr(token));
|
||||
getSynthetixStakingAddr(token);
|
||||
TokenInterface snxToken = TokenInterface(getSnxAddr());
|
||||
|
||||
uint intialBal = snxToken.balanceOf(address(this));
|
||||
|
@ -138,7 +146,7 @@ contract SynthetixStaking is SynthetixStakingHelper {
|
|||
address token,
|
||||
uint setId
|
||||
) external payable {
|
||||
IStakingRewards stakingContract = IStakingRewards(getSynthetixStakingAddr(token));
|
||||
getSynthetixStakingAddr(token);
|
||||
TokenInterface snxToken = TokenInterface(getSnxAddr());
|
||||
|
||||
uint intialBal = snxToken.balanceOf(address(this));
|
||||
|
@ -157,4 +165,7 @@ contract SynthetixStaking is SynthetixStakingHelper {
|
|||
|
||||
contract ConnectSynthetixStaking is SynthetixStaking {
|
||||
string public name = "synthetix-staking-v1";
|
||||
|
||||
constructor(address _synthetixStakingAddr) SynthetixStaking(_synthetixStakingAddr) public {}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,17 +3,19 @@ pragma solidity ^0.6.0;
|
|||
import { ConnectSynthetixStaking } from "../connectors/synthetix.sol";
|
||||
|
||||
contract MockSynthetixStaking is ConnectSynthetixStaking{
|
||||
// uint public _model;
|
||||
// uint public _id;
|
||||
address public synthetixStakingAddr;
|
||||
|
||||
constructor(address _synthetixStakingAddr) public {
|
||||
// _model = model;
|
||||
// _id = id;
|
||||
constructor(address _synthetixStakingAddr) ConnectSynthetixStaking(_synthetixStakingAddr) public {
|
||||
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;
|
||||
}
|
||||
|
||||
function setUint(uint setId, uint val) override internal {}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// const ConnectSBTCCurve = artifacts.require("ConnectSBTCCurve");
|
||||
const MockContract = artifacts.require("MockContract");
|
||||
const MockSynthetixStaking = artifacts.require("MockSynthetixStaking");
|
||||
// const ConnectSynthetixStaking = artifacts.require("ConnectSynthetixStaking");
|
||||
|
||||
// const connectorsABI = require("../test/abi/connectors.json");
|
||||
// let connectorsAddr = "0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c";
|
||||
|
@ -12,6 +13,7 @@ module.exports = async function(deployer) {
|
|||
// let connectorLength = await connectorInstance.methods.connectorLength().call();
|
||||
deployer.deploy(MockContract).then(function () {
|
||||
// return deployer.deploy(MockSynthetixStaking, MockContract.address, 1, +connectorLength + 1);
|
||||
// return deployer.deploy(ConnectSynthetixStaking, MockContract.address);
|
||||
return deployer.deploy(MockSynthetixStaking, MockContract.address);
|
||||
});
|
||||
|
||||
|
|
3584
package-lock.json
generated
3584
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -36,11 +36,15 @@
|
|||
"truffle-verify": "^1.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nomiclabs/buidler": "^1.3.8",
|
||||
"@nomiclabs/buidler-truffle5": "^1.3.4",
|
||||
"@nomiclabs/buidler-web3": "^1.3.4",
|
||||
"@openzeppelin/test-helpers": "^0.5.6",
|
||||
"@studydefi/money-legos": "^2.3.5",
|
||||
"ganache-cli": "^6.10.0-beta.2",
|
||||
"sol-merger": "^2.0.1",
|
||||
"solidity-coverage": "0.5.11",
|
||||
"solium": "1.2.3"
|
||||
"solium": "1.2.3",
|
||||
"web3": "^1.2.9"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,8 +78,6 @@ contract('ConnectSBTCCurve', async accounts => {
|
|||
// Send ETH to master
|
||||
await web3.eth.sendTransaction({from: sender, to: masterAddress, value: ether("5")});
|
||||
|
||||
let connectorID = await connectSBTCCurve.connectorID();
|
||||
|
||||
// Enable the the given connector address
|
||||
await connectorInstance.methods.enable(connectSBTCCurve.address).send({from: masterAddress});
|
||||
// check if the give connector address is enabled.
|
||||
|
|
|
@ -8,24 +8,72 @@ const {
|
|||
|
||||
const MockContract = artifacts.require("MockContract");
|
||||
const MockSynthetixStaking = artifacts.require('MockSynthetixStaking');
|
||||
// const ConnectSynthetixStaking = artifacts.require('ConnectSynthetixStaking');
|
||||
const erc20ABI = require("./abi/erc20.js");
|
||||
const synthetixStaking = require("./abi/synthetixStaking.json");
|
||||
|
||||
contract('ConnectSynthetixStaking', async accounts => {
|
||||
const [sender, receiver] = accounts;
|
||||
const mock = await MockContract.deployed();
|
||||
const mockSynthetixStaking = await MockSynthetixStaking.deployed();
|
||||
const crvRenWSBTCContract = new web3.eth.Contract(erc20ABI, mock.address);
|
||||
let mock, mockSynthetixStaking, stakingContract, token;
|
||||
|
||||
before(async function () {
|
||||
let methodId = await crvRenWSBTCContract.methods.balanceOf(sender).encodeABI();
|
||||
await mock.givenMethodReturnUint(methodId, 10000000);
|
||||
// const connectSynthetixStaking = await ConnectSynthetixStaking.deployed();
|
||||
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() {
|
||||
// expect(wbtcAfter - wbtcBefore).to.be.at.least(10000000);
|
||||
it('can deposit', async function() {
|
||||
// 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");
|
||||
});
|
||||
})
|
||||
|
|
1
test/abi/synthetixStaking.json
Normal file
1
test/abi/synthetixStaking.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user