mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
WIP having InternalCompilerError;
formating synthetic.sol and staking.sol; Adding MockInstaMapping; update test;
This commit is contained in:
parent
819fead058
commit
df61aebc58
|
|
@ -15,59 +15,60 @@ interface IStakingRewards {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SynthetixMapping {
|
interface SynthetixMapping {
|
||||||
struct StakingData {
|
struct StakingData {
|
||||||
address stakingPool;
|
address stakingPool;
|
||||||
address stakingToken;
|
address stakingToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
function stakingMapping(bytes32) external view returns(StakingData memory);
|
function stakingMapping(bytes32) external view returns(StakingData memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract SynthetixStakingHelper is DSMath, Stores {
|
contract SynthetixStakingHelper is DSMath, Stores {
|
||||||
/**
|
/**
|
||||||
* @dev Return InstaDApp Synthetix Mapping Addresses
|
* @dev Return InstaDApp Synthetix Mapping Addresses
|
||||||
*/
|
*/
|
||||||
function getMappingAddr() internal pure returns (address) {
|
function getMappingAddr() internal pure returns (address) {
|
||||||
return 0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88; // InstaMapping Address
|
return 0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88; // InstaMapping Address
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Convert String to bytes32.
|
* @dev Convert String to bytes32.
|
||||||
*/
|
*/
|
||||||
function stringToBytes32(string memory str) internal pure returns (bytes32 result) {
|
function stringToBytes32(string memory str) internal pure returns (bytes32 result) {
|
||||||
require(bytes(str).length != 0, "string-empty");
|
require(bytes(str).length != 0, "string-empty");
|
||||||
// solium-disable-next-line security/no-inline-assembly
|
// solium-disable-next-line security/no-inline-assembly
|
||||||
assembly {
|
assembly {
|
||||||
result := mload(add(str, 32))
|
result := mload(add(str, 32))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Get staking data
|
* @dev Get staking data
|
||||||
*/
|
*/
|
||||||
function getStakingData(string memory stakingName)
|
function getStakingData(string memory stakingName)
|
||||||
internal
|
virtual
|
||||||
view
|
internal
|
||||||
returns (
|
view
|
||||||
IStakingRewards stakingContract,
|
returns (
|
||||||
TokenInterface stakingToken,
|
IStakingRewards stakingContract,
|
||||||
bytes32 stakingType
|
TokenInterface stakingToken,
|
||||||
)
|
bytes32 stakingType
|
||||||
{
|
)
|
||||||
stakingType = stringToBytes32(stakingName);
|
{
|
||||||
SynthetixMapping.StakingData memory stakingData = SynthetixMapping(getMappingAddr()).stakingMapping(stakingType);
|
stakingType = stringToBytes32(stakingName);
|
||||||
require(stakingData.stakingPool != address(0), "Wrong Staking Name");
|
SynthetixMapping.StakingData memory stakingData = SynthetixMapping(getMappingAddr()).stakingMapping(stakingType);
|
||||||
require(stakingData.stakingToken != address(0), "Wrong Staking Name");
|
require(stakingData.stakingPool != address(0), "Wrong Staking Name");
|
||||||
stakingContract = IStakingRewards(stakingData.stakingPool);
|
require(stakingData.stakingToken != address(0), "Wrong Staking Name");
|
||||||
stakingToken = TokenInterface(stakingData.stakingToken);
|
stakingContract = IStakingRewards(stakingData.stakingPool);
|
||||||
}
|
stakingToken = TokenInterface(stakingData.stakingToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract SynthetixStaking is SynthetixStakingHelper {
|
contract SynthetixStaking is SynthetixStakingHelper {
|
||||||
|
|
@ -95,10 +96,10 @@ contract SynthetixStaking is SynthetixStakingHelper {
|
||||||
/**
|
/**
|
||||||
* @dev Deposit Token.
|
* @dev Deposit Token.
|
||||||
* @param stakingPoolName staking token address.
|
* @param stakingPoolName staking token address.
|
||||||
* @param amt staking token amount.
|
* @param amt staking token amount.
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function deposit(
|
function deposit(
|
||||||
string calldata stakingPoolName,
|
string calldata stakingPoolName,
|
||||||
uint amt,
|
uint amt,
|
||||||
|
|
@ -122,11 +123,11 @@ contract SynthetixStaking is SynthetixStakingHelper {
|
||||||
/**
|
/**
|
||||||
* @dev Withdraw Token.
|
* @dev Withdraw Token.
|
||||||
* @param stakingPoolName staking token address.
|
* @param stakingPoolName staking token address.
|
||||||
* @param amt staking token amount.
|
* @param amt staking token amount.
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setIdAmount Set token amount at this ID in `InstaMemory` Contract.
|
* @param setIdAmount Set token amount at this ID in `InstaMemory` Contract.
|
||||||
* @param setIdReward Set reward amount at this ID in `InstaMemory` Contract.
|
* @param setIdReward Set reward amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function withdraw(
|
function withdraw(
|
||||||
string calldata stakingPoolName,
|
string calldata stakingPoolName,
|
||||||
uint amt,
|
uint amt,
|
||||||
|
|
@ -164,8 +165,8 @@ contract SynthetixStaking is SynthetixStakingHelper {
|
||||||
/**
|
/**
|
||||||
* @dev Claim Reward.
|
* @dev Claim Reward.
|
||||||
* @param stakingPoolName staking token address.
|
* @param stakingPoolName staking token address.
|
||||||
* @param setId Set reward amount at this ID in `InstaMemory` Contract.
|
* @param setId Set reward amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function claimReward(
|
function claimReward(
|
||||||
string calldata stakingPoolName,
|
string calldata stakingPoolName,
|
||||||
uint setId
|
uint setId
|
||||||
|
|
|
||||||
|
|
@ -2,93 +2,93 @@ pragma solidity ^0.6.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
interface ConnectorsInterface {
|
interface ConnectorsInterface {
|
||||||
function chief(address) external view returns (bool);
|
function chief(address) external view returns (bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IndexInterface {
|
interface IndexInterface {
|
||||||
function master() external view returns (address);
|
function master() external view returns (address);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract BytesHelper {
|
contract BytesHelper {
|
||||||
/**
|
/**
|
||||||
* @dev Convert String to bytes32.
|
* @dev Convert String to bytes32.
|
||||||
*/
|
*/
|
||||||
function stringToBytes32(string memory str) internal pure returns (bytes32 result) {
|
function stringToBytes32(string memory str) internal pure returns (bytes32 result) {
|
||||||
require(bytes(str).length != 0, "String-Empty");
|
require(bytes(str).length != 0, "String-Empty");
|
||||||
// solium-disable-next-line security/no-inline-assembly
|
// solium-disable-next-line security/no-inline-assembly
|
||||||
assembly {
|
assembly {
|
||||||
result := mload(add(str, 32))
|
result := mload(add(str, 32))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Convert bytes32 to String.
|
* @dev Convert bytes32 to String.
|
||||||
*/
|
*/
|
||||||
function bytes32ToString(bytes32 _bytes32) internal pure returns (string memory) {
|
function bytes32ToString(bytes32 _bytes32) internal pure returns (string memory) {
|
||||||
bytes32 _temp;
|
bytes32 _temp;
|
||||||
uint count;
|
uint count;
|
||||||
for (uint256 i; i < 32; i++) {
|
for (uint256 i; i < 32; i++) {
|
||||||
_temp = _bytes32[i];
|
_temp = _bytes32[i];
|
||||||
if( _temp != bytes32(0)) {
|
if( _temp != bytes32(0)) {
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
bytes memory bytesArray = new bytes(count);
|
|
||||||
for (uint256 i; i < count; i++) {
|
|
||||||
bytesArray[i] = (_bytes32[i]);
|
|
||||||
}
|
|
||||||
return (string(bytesArray));
|
|
||||||
}
|
}
|
||||||
|
bytes memory bytesArray = new bytes(count);
|
||||||
|
for (uint256 i; i < count; i++) {
|
||||||
|
bytesArray[i] = (_bytes32[i]);
|
||||||
|
}
|
||||||
|
return (string(bytesArray));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
contract Helpers is BytesHelper {
|
contract Helpers is BytesHelper {
|
||||||
address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c;
|
address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c;
|
||||||
address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
|
address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
|
||||||
uint public version = 1;
|
uint public version = 1;
|
||||||
|
|
||||||
struct StakingData {
|
struct StakingData {
|
||||||
address stakingPool;
|
address stakingPool;
|
||||||
address stakingToken;
|
address stakingToken;
|
||||||
}
|
}
|
||||||
mapping (bytes32 => StakingData) public stakingMapping;
|
mapping (bytes32 => StakingData) public stakingMapping;
|
||||||
|
|
||||||
event LogAddStakingMapping(string stakingName, bytes32 stakingType, address stakingAddress, address stakingToken);
|
event LogAddStakingMapping(string stakingName, bytes32 stakingType, address stakingAddress, address stakingToken);
|
||||||
event LogRemoveStakingMapping(string stakingName, bytes32 stakingType, address stakingAddress, address stakingToken);
|
event LogRemoveStakingMapping(string stakingName, bytes32 stakingType, address stakingAddress, address stakingToken);
|
||||||
|
|
||||||
modifier isChief {
|
modifier isChief virtual {
|
||||||
require(
|
require(
|
||||||
ConnectorsInterface(connectors).chief(msg.sender) ||
|
ConnectorsInterface(connectors).chief(msg.sender) ||
|
||||||
IndexInterface(instaIndex).master() == msg.sender, "not-Chief");
|
IndexInterface(instaIndex).master() == msg.sender, "not-Chief");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
function addStakingMapping(string memory stakingName, address stakingAddress, address stakingToken) public isChief {
|
function addStakingMapping(string memory stakingName, address stakingAddress, address stakingToken) public isChief {
|
||||||
require(stakingAddress != address(0), "StakingPool-not-vaild");
|
require(stakingAddress != address(0), "StakingPool-not-vaild");
|
||||||
require(stakingToken != address(0), "StakingToken-not-vaild");
|
require(stakingToken != address(0), "StakingToken-not-vaild");
|
||||||
require(bytes(stakingName).length < 32, "Lenght-exceeds"); // TODO - test this.
|
require(bytes(stakingName).length < 32, "Lenght-exceeds"); // TODO - test this.
|
||||||
bytes32 stakeType = stringToBytes32(stakingName);
|
bytes32 stakeType = stringToBytes32(stakingName);
|
||||||
require(stakingMapping[stakeType].stakingPool == address(0), "StakingPool-Already-Added");
|
require(stakingMapping[stakeType].stakingPool == address(0), "StakingPool-Already-Added");
|
||||||
require(stakingMapping[stakeType].stakingToken == address(0), "StakingPool-Already-Added");
|
require(stakingMapping[stakeType].stakingToken == address(0), "StakingPool-Already-Added");
|
||||||
|
|
||||||
stakingMapping[stakeType] = StakingData(
|
stakingMapping[stakeType] = StakingData(
|
||||||
stakingAddress,
|
stakingAddress,
|
||||||
stakingToken
|
stakingToken
|
||||||
);
|
);
|
||||||
emit LogAddStakingMapping(stakingName, stakeType, stakingAddress, stakingToken);
|
emit LogAddStakingMapping(stakingName, stakeType, stakingAddress, stakingToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeStakingMapping(string memory stakingName, address stakingAddress) public isChief {
|
function removeStakingMapping(string memory stakingName, address stakingAddress) public isChief {
|
||||||
require(stakingAddress != address(0), "StakingPool-not-vaild");
|
require(stakingAddress != address(0), "StakingPool-not-vaild");
|
||||||
require(bytes(stakingName).length < 32, "Lenght-exceeds"); // TODO - test this.
|
require(bytes(stakingName).length < 32, "Lenght-exceeds"); // TODO - test this.
|
||||||
bytes32 stakeType = stringToBytes32(stakingName);
|
bytes32 stakeType = stringToBytes32(stakingName);
|
||||||
require(stakingMapping[stakeType].stakingPool != address(0), "StakingPool-Already-Added");
|
require(stakingMapping[stakeType].stakingPool != address(0), "StakingPool-Already-Added");
|
||||||
require(stakingMapping[stakeType].stakingToken != address(0), "StakingPool-Already-Added");
|
require(stakingMapping[stakeType].stakingToken != address(0), "StakingPool-Already-Added");
|
||||||
require(stakingMapping[stakeType].stakingPool == stakingAddress, "Not-same-staking-pool");
|
require(stakingMapping[stakeType].stakingPool == stakingAddress, "Not-same-staking-pool");
|
||||||
|
|
||||||
emit LogRemoveStakingMapping(stakingName, stakeType, stakingAddress, stakingMapping[stakeType].stakingToken);
|
emit LogRemoveStakingMapping(stakingName, stakeType, stakingAddress, stakingMapping[stakeType].stakingToken);
|
||||||
delete stakingMapping[stakeType];
|
delete stakingMapping[stakeType];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract InstaMapping is Helpers {
|
contract InstaMapping is Helpers {
|
||||||
string constant public name = "Synthetix-Mapping-v1";
|
string constant public name = "Synthetix-Mapping-v1";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
contracts/tests/MockInstaMapping.sol
Normal file
7
contracts/tests/MockInstaMapping.sol
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
pragma solidity ^0.6.0;
|
||||||
|
|
||||||
|
import { InstaMapping } from "../mapping/staking.sol";
|
||||||
|
|
||||||
|
contract MockInstaMapping is InstaMapping {
|
||||||
|
modifier isChief override {_;}
|
||||||
|
}
|
||||||
|
|
@ -9,9 +9,9 @@ contract MockSynthetixStaking is ConnectSynthetixStaking{
|
||||||
synthetixStakingAddr = _synthetixStakingAddr;
|
synthetixStakingAddr = _synthetixStakingAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSynthetixStakingAddr(address token) override internal returns (address) {
|
// function getSynthetixStakingAddr(address token) override internal returns (address) {
|
||||||
return synthetixStakingAddr;
|
// return synthetixStakingAddr;
|
||||||
}
|
// }
|
||||||
|
|
||||||
function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {}
|
function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,22 @@ 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 MockInstaMapping = artifacts.require('MockInstaMapping');
|
||||||
const erc20ABI = require("./abi/erc20.js");
|
const erc20ABI = require("./abi/erc20.js");
|
||||||
const synthetixStaking = require("./abi/synthetixStaking.json");
|
const synthetixStaking = require("./abi/synthetixStaking.json");
|
||||||
|
|
||||||
contract('ConnectSynthetixStaking', async accounts => {
|
contract('ConnectSynthetixStaking', async accounts => {
|
||||||
const [sender, receiver] = accounts;
|
const [sender, receiver] = accounts;
|
||||||
let mock, mockSynthetixStaking, stakingContract, token;
|
let mock, mockSynthetixStaking, stakingContract, token;
|
||||||
|
let instaMapping;
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
// const connectSynthetixStaking = await ConnectSynthetixStaking.deployed();
|
|
||||||
mock = await MockContract.new();
|
mock = await MockContract.new();
|
||||||
|
mockInstaMapping = await MockInstaMapping.new();
|
||||||
mockSynthetixStaking = await MockSynthetixStaking.new(mock.address);
|
mockSynthetixStaking = await MockSynthetixStaking.new(mock.address);
|
||||||
stakingContract = new web3.eth.Contract(synthetixStaking, mock.address);
|
stakingContract = new web3.eth.Contract(synthetixStaking, mock.address);
|
||||||
token = new web3.eth.Contract(erc20ABI, mock.address);
|
token = new web3.eth.Contract(erc20ABI, mock.address);
|
||||||
|
mockInstaMapping.addStakingMapping('snx', mock.address, mock.address);
|
||||||
|
|
||||||
// mocking balanceOf
|
// mocking balanceOf
|
||||||
let balanceOf = await token.methods.balanceOf(mockSynthetixStaking.address).encodeABI();
|
let balanceOf = await token.methods.balanceOf(mockSynthetixStaking.address).encodeABI();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user