Aggregator init
This commit is contained in:
parent
884c48899d
commit
98f4d06e14
|
@ -1,4 +1,4 @@
|
|||
# Peppersec solidity template [![Build Status](https://github.com/peppersec/solidity-template/workflows/build/badge.svg)](https://github.com/peppersec/solidity-template/actions)
|
||||
# Tornado smart contract data aggregator [![Build Status](https://github.com/peppersec/solidity-template/workflows/build/badge.svg)](https://github.com/peppersec/solidity-template/actions)
|
||||
|
||||
## Dependencies
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.6.12;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./GovernanceAggregator.sol";
|
||||
import "./PriceAggregator.sol";
|
||||
import "./SwapAggregator.sol";
|
||||
|
||||
contract Aggregator is GovernanceAggregator, PriceAggregator, SwapAggregator {}
|
|
@ -0,0 +1,19 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.6.12;
|
||||
|
||||
interface ENS {
|
||||
function resolver(bytes32 node) external view returns (Resolver);
|
||||
}
|
||||
|
||||
interface Resolver {
|
||||
function addr(bytes32 node) external view returns (address);
|
||||
}
|
||||
|
||||
contract EnsResolve {
|
||||
ENS public constant Registry = ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);
|
||||
|
||||
function resolve(bytes32 node) public view returns (address) {
|
||||
return Registry.resolver(node).addr(node);
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.6.12;
|
||||
|
||||
contract Echoer {
|
||||
event Echo(address indexed who, bytes data);
|
||||
|
||||
function echo(bytes calldata data) external {
|
||||
emit Echo(msg.sender, data);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.6.12;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "tornado-governance/contracts/Governance.sol";
|
||||
|
||||
contract GovernanceAggregator {
|
||||
struct Proposal {
|
||||
uint256 id;
|
||||
address proposer;
|
||||
address target;
|
||||
uint256 startTime;
|
||||
uint256 endTime;
|
||||
uint256 forVotes;
|
||||
uint256 againstVotes;
|
||||
bool executed;
|
||||
bool extended;
|
||||
Governance.ProposalState state;
|
||||
}
|
||||
|
||||
function getAllProposals(
|
||||
Governance governance,
|
||||
uint256 from,
|
||||
uint256 to
|
||||
) external view returns (Proposal[] memory proposals) {
|
||||
uint256 proposalCount = governance.proposalCount();
|
||||
to = to == 0 ? proposalCount : to;
|
||||
proposals = new Proposal[](proposalCount);
|
||||
|
||||
for (from; from < to; from++) {
|
||||
(
|
||||
uint256 id,
|
||||
address proposer,
|
||||
address target,
|
||||
uint256 startTime,
|
||||
uint256 endTime,
|
||||
uint256 forVotes,
|
||||
uint256 againstVotes,
|
||||
bool executed,
|
||||
bool extended
|
||||
) = governance.proposals(from + 1);
|
||||
|
||||
proposals[from] = Proposal({
|
||||
id: id,
|
||||
proposer: proposer,
|
||||
target: target,
|
||||
startTime: startTime,
|
||||
endTime: endTime,
|
||||
forVotes: forVotes,
|
||||
againstVotes: againstVotes,
|
||||
executed: executed,
|
||||
extended: extended,
|
||||
state: governance.state(id)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getGovernanceBalances(Governance governance, address[] calldata accs)
|
||||
external
|
||||
view
|
||||
returns (uint256[] memory amounts)
|
||||
{
|
||||
amounts = new uint256[](accs.length);
|
||||
for (uint256 i = 0; i < accs.length; i++) {
|
||||
amounts[i] = governance.balances(accs[i]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.12;
|
||||
|
||||
import "./ENS.sol";
|
||||
|
||||
interface OneSplit {
|
||||
function getExpectedReturn(
|
||||
address fromToken,
|
||||
address destToken,
|
||||
uint256 amount,
|
||||
uint256 parts,
|
||||
uint256 flags // See contants in IOneSplit.sol
|
||||
) external view returns (uint256 returnAmount, uint256[] memory distribution);
|
||||
}
|
||||
|
||||
contract PriceAggregator is EnsResolve {
|
||||
bytes32 nameHash = 0xabbae16ab822a7a0970b116c997c681cea9944854b55e1c441a9a788a2c6fc20; // 1split.eth - https://etherscan.io/enslookup?q=1split.eth
|
||||
|
||||
function getPricesInETH(address[] memory fromTokens, uint256[] memory oneUnitAmounts)
|
||||
public
|
||||
view
|
||||
returns (uint256[] memory prices)
|
||||
{
|
||||
OneSplit split = OneSplit(resolve(nameHash));
|
||||
|
||||
prices = new uint256[](fromTokens.length);
|
||||
for (uint256 i = 0; i < fromTokens.length; i++) {
|
||||
(uint256 price, ) = split.getExpectedReturn(
|
||||
fromTokens[i],
|
||||
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,
|
||||
oneUnitAmounts[i],
|
||||
1,
|
||||
0
|
||||
);
|
||||
prices[i] = price;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.6.12;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "tornado-anonymity-mining/contracts/RewardSwap.sol";
|
||||
|
||||
contract SwapAggregator {
|
||||
function swapState(RewardSwap swap) external view returns (uint256 balance, uint256 poolWeight) {
|
||||
balance = swap.tornVirtualBalance();
|
||||
poolWeight = swap.poolWeight();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
/* global artifacts */
|
||||
const Aggregator = artifacts.require('Aggregator')
|
||||
|
||||
module.exports = function (deployer) {
|
||||
return deployer.then(async () => {
|
||||
const aggregator = await deployer.deploy(Aggregator)
|
||||
|
||||
console.log('Aggregator :', aggregator.address)
|
||||
})
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
/* global artifacts */
|
||||
const Echoer = artifacts.require('Echoer')
|
||||
|
||||
module.exports = function (deployer) {
|
||||
return deployer.then(async () => {
|
||||
const echoer = await deployer.deploy(Echoer)
|
||||
|
||||
console.log('Echoer :', echoer.address)
|
||||
})
|
||||
}
|
|
@ -43,5 +43,10 @@
|
|||
"truffle-hdwallet-provider": "^1.0.17",
|
||||
"truffle-plugin-verify": "^0.3.11",
|
||||
"web3": "^1.2.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"tornado-anonymity-mining": "git+https://github.com/tornadocash/tornado-anonymity-mining.git#1e1a85192be4881b51f77ae1bf3a8194a09a0605",
|
||||
"torn-token": "git+https://github.com/tornadocash/torn-token.git#da424e05749ed06dc61a6a37587e7b35e42bc438",
|
||||
"tornado-governance": "git+https://github.com/tornadocash/governance.git#f27663c39f5e5bf23455ffd44accf3ea42186372"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
/* global artifacts, web3, contract */
|
||||
require('chai').use(require('bn-chai')(web3.utils.BN)).use(require('chai-as-promised')).should()
|
||||
// require('chai').use(require('bn-chai')(web3.utils.BN)).use(require('chai-as-promised')).should()
|
||||
|
||||
const { takeSnapshot, revertSnapshot } = require('../scripts/ganacheHelper')
|
||||
const Echoer = artifacts.require('./Echoer.sol')
|
||||
// const { takeSnapshot, revertSnapshot } = require('../scripts/ganacheHelper')
|
||||
// const Echoer = artifacts.require('./Echoer.sol')
|
||||
|
||||
contract('Echoer', (accounts) => {
|
||||
let echoer
|
||||
let snapshotId
|
||||
// contract('Echoer', (accounts) => {
|
||||
// let echoer
|
||||
// let snapshotId
|
||||
|
||||
before(async () => {
|
||||
echoer = await Echoer.deployed()
|
||||
snapshotId = await takeSnapshot()
|
||||
})
|
||||
// before(async () => {
|
||||
// echoer = await Echoer.deployed()
|
||||
// snapshotId = await takeSnapshot()
|
||||
// })
|
||||
|
||||
describe('#echo', () => {
|
||||
it('should work', async () => {
|
||||
const data = '0xbeef'
|
||||
const { logs } = await echoer.echo(data)
|
||||
// describe('#echo', () => {
|
||||
// it('should work', async () => {
|
||||
// const data = '0xbeef'
|
||||
// const { logs } = await echoer.echo(data)
|
||||
|
||||
logs[0].event.should.be.equal('Echo')
|
||||
logs[0].args.who.should.be.equal(accounts[0])
|
||||
logs[0].args.data.should.be.equal(data)
|
||||
})
|
||||
})
|
||||
// logs[0].event.should.be.equal('Echo')
|
||||
// logs[0].args.who.should.be.equal(accounts[0])
|
||||
// logs[0].args.data.should.be.equal(data)
|
||||
// })
|
||||
// })
|
||||
|
||||
afterEach(async () => {
|
||||
await revertSnapshot(snapshotId.result)
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
snapshotId = await takeSnapshot()
|
||||
})
|
||||
})
|
||||
// afterEach(async () => {
|
||||
// await revertSnapshot(snapshotId.result)
|
||||
// // eslint-disable-next-line require-atomic-updates
|
||||
// snapshotId = await takeSnapshot()
|
||||
// })
|
||||
// })
|
||||
|
|
Loading…
Reference in New Issue