initial Curve connector version

This commit is contained in:
AA 2020-05-05 04:54:10 +03:00
parent e1cfe964f2
commit b20e2728b6
14 changed files with 5485 additions and 6 deletions

View File

@ -1,7 +1,7 @@
pragma solidity ^0.6.0;
interface TokenInterface {
function approve(address, uint) external;
function approve(address, uint256) external;
function transfer(address, uint) external;
function transferFrom(address, address, uint) external;
function deposit() external payable;

View File

@ -8,6 +8,10 @@ contract DSMath {
require((z = x + y) >= x, "math-not-safe");
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, "ds-math-sub-underflow");
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, "math-not-safe");
}

View File

@ -0,0 +1,146 @@
pragma solidity ^0.6.0;
// import files from common directory
import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol";
import { Stores } from "../common/stores.sol";
import { DSMath } from "../common/math.sol";
interface ICurve {
function get_virtual_price() external returns (uint256 out);
function calc_token_amount(uint256[4] calldata amounts, bool deposit) external returns (uint256 amount);
function add_liquidity(uint256[4] calldata amounts, uint256 min_mint_amount) external;
function get_dy(int128 i, int128 j, uint256 dx)
external
returns (uint256 out);
function get_dy_underlying(int128 i, int128 j, uint256 dx)
external
returns (uint256 out);
function exchange(
int128 i,
int128 j,
uint256 dx,
uint256 min_dy
) external;
function exchange_underlying(
int128 i,
int128 j,
uint256 dx,
uint256 min_dy
) external;
function remove_liquidity(
uint256 _amount,
uint256[4] calldata min_amounts
) external;
function remove_liquidity_imbalance(uint256[4] calldata amounts, uint256 max_burn_amount)
external;
}
interface ICurveZap {
function calc_withdraw_one_coin(uint256 _token_amount, int128 i) external returns (uint256 amount);
function remove_liquidity_one_coin(
uint256 _token_amount,
int128 i,
uint256 min_uamount
) external;
}
contract CurveProtocol is Stores, DSMath {
event LogBuy(address sellAddr, address buyAddr, uint256 sellAmount, uint256 buyAmount);
event LogAddLiquidity(uint256[4] amounts, uint256 mintAmount);
event LogRemoveLiquidityImbalance(uint256[4] amounts, uint256 burnAmount);
event LogRemoveLiquidityOneCoin(address receiveCoin, uint256 amount);
address public constant sCurveSwap = address(0xA5407eAE9Ba41422680e2e00537571bcC53efBfD);
address public constant sCurveToken = address(0xC25a3A3b969415c80451098fa907EC722572917F);
address public constant sCurveZap = address(0xFCBa3E75865d2d561BE8D220616520c171F12851);
address public constant DAI = address(0x6B175474E89094C44Da98b954EedeAC495271d0F);
address public constant USDC = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
address public constant USDT = address(0xdAC17F958D2ee523a2206206994597C13D831ec7);
address public constant sUSD = address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51);
mapping (int128 => address) addresses;
constructor() public {
addresses[0] = address(0x6B175474E89094C44Da98b954EedeAC495271d0F);
addresses[1] = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
addresses[2] = address(0xdAC17F958D2ee523a2206206994597C13D831ec7);
addresses[3] = address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51);
}
function get_virtual_price() external returns (uint256) {
ICurve curve = ICurve(sCurveSwap);
return curve.get_virtual_price();
}
function get_dy(int128 i, int128 j, uint256 dx) public returns(uint256) {
ICurve curve = ICurve(sCurveSwap);
return curve.get_dy(i, j, dx);
}
function exchange(int128 i, int128 j, uint256 dx, uint256 slippage) external {
TokenInterface(addresses[i]).approve(sCurveSwap, dx);
uint256 dy = get_dy(i, j, dx);
uint256 min_dy = mul(dy, sub(100, slippage)) / 100;
ICurve(sCurveSwap).exchange(i, j, dx, min_dy);
uint256 bought = TokenInterface(addresses[j]).balanceOf(address(this));
emit LogBuy(addresses[i], addresses[j], dx, bought);
}
function add_liquidity(uint256[4] calldata amounts, uint256 slippage) external {
for(uint256 i = 0; i < 4; i++) {
uint256 amount = amounts[i];
if(amount == 0) continue;
int128 coin_i = int128(i);
TokenInterface(addresses[coin_i]).approve(sCurveSwap, amount);
}
uint256 min_mint_amount = ICurve(sCurveSwap).calc_token_amount(amounts, true);
ICurve(sCurveSwap).add_liquidity(amounts, mul(min_mint_amount, sub(100, slippage)) / 100);
uint256 mintAmount = TokenInterface(sCurveToken).balanceOf(address(this));
emit LogAddLiquidity(amounts, mintAmount);
}
function remove_liquidity_imbalance(uint256[4] calldata amounts) external {
uint256 max_burn_amount = ICurve(sCurveSwap).calc_token_amount(amounts, false);
uint256 balance = TokenInterface(sCurveToken).balanceOf(address(this));
ICurve(sCurveSwap).remove_liquidity_imbalance(amounts, mul(max_burn_amount, 101) / 100);
uint burnAmount = sub(balance, TokenInterface(sCurveToken).balanceOf(address(this)));
emit LogRemoveLiquidityImbalance(amounts, burnAmount);
}
function remove_liquidity_one_coin(uint256 _token_amount, int128 i, uint256 slippage) external {
uint256 min_uamount = ICurveZap(sCurveZap).calc_withdraw_one_coin(_token_amount, i);
min_uamount = mul(min_uamount, sub(100, slippage) / 100);
uint256 balance = TokenInterface(addresses[i]).balanceOf(address(this));
TokenInterface(sCurveToken).approve(sCurveZap, _token_amount);
ICurveZap(sCurveZap).remove_liquidity_one_coin(_token_amount, i, min_uamount);
uint256 newBalance = TokenInterface(addresses[i]).balanceOf(address(this));
uint256 received_amount = sub(newBalance, balance);
emit LogRemoveLiquidityOneCoin(addresses[i], received_amount);
}
}
contract ConnectCurve is CurveProtocol {
string public name = "Curve-susdv2-v1";
}

View File

@ -1,4 +1,4 @@
const Connector = artifacts.require("MockProtocol"); // Change the Connector name while deploying.
const Connector = artifacts.require("CurveProtocol"); // Change the Connector name while deploying.
module.exports = function(deployer) {
deployer.deploy(Connector);

3748
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -22,15 +22,17 @@
"homepage": "https://github.com/InstaDApp/dsa-connectors#readme",
"dependencies": {
"@truffle/artifactor": "^4.0.45",
"chai": "^4.2.0",
"chalk": "^4.0.0",
"dotenv": "^7.0.0",
"ethereumjs-abi": "^0.6.8",
"minimist": "^1.2.5",
"openzeppelin-test-helpers": "^0.5.1",
"solc": "^0.6.0",
"truffle-assertions": "^0.9.2",
"truffle-hdwallet-provider": "^1.0.17",
"truffle-plugin-verify": "^0.3.10",
"truffle-verify": "^1.0.8",
"minimist": "^1.2.5",
"chalk": "^4.0.0"
"truffle-verify": "^1.0.8"
},
"devDependencies": {
"sol-merger": "^2.0.1",

18
tenderly.yaml Normal file
View File

@ -0,0 +1,18 @@
account_id: ""
exports:
ganache:
project_slug: dsa
rpc_address: 127.0.0.1:8545
protocol: ""
forked_network: Mainnet
chain_config:
homestead_block: 0
eip150_block: 0
eip150_hash: "0x0000000000000000000000000000000000000000000000000000000000000000"
eip155_block: 0
eip158_block: 0
byzantium_block: 0
constantinople_block: 0
petersburg_block: 0
istanbul_block: 0
project_slug: ""

92
test/CurveProtocol.js Normal file
View File

@ -0,0 +1,92 @@
const CurveProtocol = artifacts.require('CurveProtocol')
const daiABI = require('./abi/dai');
const erc20 = require('./abi/erc20')
const swap_abi = require('./abi/swap')
const { BN, ether, balance } = require('openzeppelin-test-helpers');
const { asyncForEach } = require('./utils');
// userAddress must be unlocked using --unlock ADDRESS
const userAddress = '0x9eb7f2591ed42dee9315b6e2aaf21ba85ea69f8c';
const daiAddress = '0x6b175474e89094c44da98b954eedeac495271d0f';
const daiContract = new web3.eth.Contract(daiABI, daiAddress);
const usdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
const usdcContract = new web3.eth.Contract(erc20, usdcAddress);
const swap = '0xA5407eAE9Ba41422680e2e00537571bcC53efBfD'
const swapContract = new web3.eth.Contract(swap_abi, swap)
const swapToken = '0xC25a3A3b969415c80451098fa907EC722572917F'
const tokenContract = new web3.eth.Contract(erc20, swapToken)
//console.log(CurveProtocol);
contract('Curve Protocol', async accounts => {
it('should send ether to the DAI address', async () => {
let account = accounts[0]
let contract = await CurveProtocol.deployed()
// Send 0.1 eth to userAddress to have gas to send an ERC20 tx.
await web3.eth.sendTransaction({
from: accounts[0],
to: userAddress,
value: ether('0.1')
});
const ethBalance = await balance.current(userAddress);
//expect(new BN(ethBalance)).to.be.bignumber.least(new BN(ether('0.1')));
});
it('should mint DAI for our first 5 generated accounts', async () => {
let account = accounts[0]
let contract = await CurveProtocol.deployed()
// Get 100 DAI for first 5 accounts
// daiAddress is passed to ganache-cli with flag `--unlock`
// so we can use the `transfer` method
await daiContract.methods
.transfer(contract.address, ether('10').toString())
.send({ from: userAddress, gasLimit: 800000 });
const daiBalance = await daiContract.methods.balanceOf(contract.address).call();
});
it('should approve DAI to CurveProtocol', async() => {
let account = accounts[0]
let contract = await CurveProtocol.deployed()
await daiContract.methods
.approve(contract.address, "1000000000000000000000000000")
.send({ from: account, gasLimit: 800000 });
});
it('should exchange', async () => {
let account = accounts[0]
let contract = await CurveProtocol.deployed()
// Get 100 DAI for first 5 accounts
let receipt = await contract.exchange(0, 1, "1000000000000000000", 1, { from: account });
console.log(receipt.logs[0].args.sellAmount.toString(), receipt.logs[0].args.buyAmount.toString())
});
it('should add liquidity', async () => {
let account = accounts[0]
let contract = await CurveProtocol.deployed()
let receipt = await contract.add_liquidity(["1000000000000000000", 0, 0, 0], 1, { from: account })
console.log(receipt.logs[0].args.amounts.map(amount=>amount.toString()), receipt.logs[0].args.mintAmount.toString())
})
it('should remove liquidity imbalance', async () => {
let account = accounts[0]
let contract = await CurveProtocol.deployed()
let receipt = await contract.remove_liquidity_imbalance(["100000000000", 0, 0, 0], { from: account })
console.log(receipt.logs[0].args.amounts.map(amount=>amount.toString()), receipt.logs[0].args.burnAmount.toString())
})
it('should remove liquidity in one coin', async() => {
let account = accounts[0]
let contract = await CurveProtocol.deployed()
let receipt = await contract.remove_liquidity_one_coin("100000000000", 0, 1, { from: account })
console.log(receipt.logs[0].args.receiveCoin, receipt.logs[0].args.amount.toString())
})
});

325
test/abi/dai.js Normal file
View File

@ -0,0 +1,325 @@
module.exports = [
{
constant: true,
inputs: [],
name: 'name',
outputs: [{ name: '', type: 'bytes32' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [],
name: 'stop',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'guy', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'approve',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'owner_', type: 'address' }],
name: 'setOwner',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'totalSupply',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'src', type: 'address' },
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'transferFrom',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'decimals',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'guy', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'mint',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'wad', type: 'uint256' }],
name: 'burn',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'name_', type: 'bytes32' }],
name: 'setName',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [{ name: 'src', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'stopped',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'authority_', type: 'address' }],
name: 'setAuthority',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'owner',
outputs: [{ name: '', type: 'address' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'symbol',
outputs: [{ name: '', type: 'bytes32' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'guy', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'burn',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'wad', type: 'uint256' }],
name: 'mint',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'transfer',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'push',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'src', type: 'address' },
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'move',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [],
name: 'start',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'authority',
outputs: [{ name: '', type: 'address' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'guy', type: 'address' }],
name: 'approve',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [
{ name: 'src', type: 'address' },
{ name: 'guy', type: 'address' }
],
name: 'allowance',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'src', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'pull',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [{ name: 'symbol_', type: 'bytes32' }],
payable: false,
stateMutability: 'nonpayable',
type: 'constructor'
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'guy', type: 'address' },
{ indexed: false, name: 'wad', type: 'uint256' }
],
name: 'Mint',
type: 'event'
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'guy', type: 'address' },
{ indexed: false, name: 'wad', type: 'uint256' }
],
name: 'Burn',
type: 'event'
},
{
anonymous: false,
inputs: [{ indexed: true, name: 'authority', type: 'address' }],
name: 'LogSetAuthority',
type: 'event'
},
{
anonymous: false,
inputs: [{ indexed: true, name: 'owner', type: 'address' }],
name: 'LogSetOwner',
type: 'event'
},
{
anonymous: true,
inputs: [
{ indexed: true, name: 'sig', type: 'bytes4' },
{ indexed: true, name: 'guy', type: 'address' },
{ indexed: true, name: 'foo', type: 'bytes32' },
{ indexed: true, name: 'bar', type: 'bytes32' },
{ indexed: false, name: 'wad', type: 'uint256' },
{ indexed: false, name: 'fax', type: 'bytes' }
],
name: 'LogNote',
type: 'event'
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'src', type: 'address' },
{ indexed: true, name: 'guy', type: 'address' },
{ indexed: false, name: 'wad', type: 'uint256' }
],
name: 'Approval',
type: 'event'
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'src', type: 'address' },
{ indexed: true, name: 'dst', type: 'address' },
{ indexed: false, name: 'wad', type: 'uint256' }
],
name: 'Transfer',
type: 'event'
}
];

325
test/abi/erc20.js Normal file
View File

@ -0,0 +1,325 @@
module.exports = [
{
constant: true,
inputs: [],
name: 'name',
outputs: [{ name: '', type: 'bytes32' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [],
name: 'stop',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'guy', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'approve',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'owner_', type: 'address' }],
name: 'setOwner',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'totalSupply',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'src', type: 'address' },
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'transferFrom',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'decimals',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'guy', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'mint',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'wad', type: 'uint256' }],
name: 'burn',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'name_', type: 'bytes32' }],
name: 'setName',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [{ name: 'src', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'stopped',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'authority_', type: 'address' }],
name: 'setAuthority',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'owner',
outputs: [{ name: '', type: 'address' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'symbol',
outputs: [{ name: '', type: 'bytes32' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'guy', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'burn',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'wad', type: 'uint256' }],
name: 'mint',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'transfer',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'push',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'src', type: 'address' },
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'move',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: false,
inputs: [],
name: 'start',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'authority',
outputs: [{ name: '', type: 'address' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [{ name: 'guy', type: 'address' }],
name: 'approve',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [
{ name: 'src', type: 'address' },
{ name: 'guy', type: 'address' }
],
name: 'allowance',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: false,
inputs: [
{ name: 'src', type: 'address' },
{ name: 'wad', type: 'uint256' }
],
name: 'pull',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [{ name: 'symbol_', type: 'bytes32' }],
payable: false,
stateMutability: 'nonpayable',
type: 'constructor'
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'guy', type: 'address' },
{ indexed: false, name: 'wad', type: 'uint256' }
],
name: 'Mint',
type: 'event'
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'guy', type: 'address' },
{ indexed: false, name: 'wad', type: 'uint256' }
],
name: 'Burn',
type: 'event'
},
{
anonymous: false,
inputs: [{ indexed: true, name: 'authority', type: 'address' }],
name: 'LogSetAuthority',
type: 'event'
},
{
anonymous: false,
inputs: [{ indexed: true, name: 'owner', type: 'address' }],
name: 'LogSetOwner',
type: 'event'
},
{
anonymous: true,
inputs: [
{ indexed: true, name: 'sig', type: 'bytes4' },
{ indexed: true, name: 'guy', type: 'address' },
{ indexed: true, name: 'foo', type: 'bytes32' },
{ indexed: true, name: 'bar', type: 'bytes32' },
{ indexed: false, name: 'wad', type: 'uint256' },
{ indexed: false, name: 'fax', type: 'bytes' }
],
name: 'LogNote',
type: 'event'
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'src', type: 'address' },
{ indexed: true, name: 'guy', type: 'address' },
{ indexed: false, name: 'wad', type: 'uint256' }
],
name: 'Approval',
type: 'event'
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'src', type: 'address' },
{ indexed: true, name: 'dst', type: 'address' },
{ indexed: false, name: 'wad', type: 'uint256' }
],
name: 'Transfer',
type: 'event'
}
];

760
test/abi/swap.js Normal file
View File

@ -0,0 +1,760 @@
module.exports = [
{
"name": "TokenExchange",
"inputs": [
{
"type": "address",
"name": "buyer",
"indexed": true
},
{
"type": "int128",
"name": "sold_id",
"indexed": false
},
{
"type": "uint256",
"name": "tokens_sold",
"indexed": false
},
{
"type": "int128",
"name": "bought_id",
"indexed": false
},
{
"type": "uint256",
"name": "tokens_bought",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "TokenExchangeUnderlying",
"inputs": [
{
"type": "address",
"name": "buyer",
"indexed": true
},
{
"type": "int128",
"name": "sold_id",
"indexed": false
},
{
"type": "uint256",
"name": "tokens_sold",
"indexed": false
},
{
"type": "int128",
"name": "bought_id",
"indexed": false
},
{
"type": "uint256",
"name": "tokens_bought",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "AddLiquidity",
"inputs": [
{
"type": "address",
"name": "provider",
"indexed": true
},
{
"type": "uint256[4]",
"name": "token_amounts",
"indexed": false
},
{
"type": "uint256[4]",
"name": "fees",
"indexed": false
},
{
"type": "uint256",
"name": "invariant",
"indexed": false
},
{
"type": "uint256",
"name": "token_supply",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "RemoveLiquidity",
"inputs": [
{
"type": "address",
"name": "provider",
"indexed": true
},
{
"type": "uint256[4]",
"name": "token_amounts",
"indexed": false
},
{
"type": "uint256[4]",
"name": "fees",
"indexed": false
},
{
"type": "uint256",
"name": "token_supply",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "RemoveLiquidityImbalance",
"inputs": [
{
"type": "address",
"name": "provider",
"indexed": true
},
{
"type": "uint256[4]",
"name": "token_amounts",
"indexed": false
},
{
"type": "uint256[4]",
"name": "fees",
"indexed": false
},
{
"type": "uint256",
"name": "invariant",
"indexed": false
},
{
"type": "uint256",
"name": "token_supply",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "CommitNewAdmin",
"inputs": [
{
"type": "uint256",
"name": "deadline",
"indexed": true,
"unit": "sec"
},
{
"type": "address",
"name": "admin",
"indexed": true
}
],
"anonymous": false,
"type": "event"
},
{
"name": "NewAdmin",
"inputs": [
{
"type": "address",
"name": "admin",
"indexed": true
}
],
"anonymous": false,
"type": "event"
},
{
"name": "CommitNewParameters",
"inputs": [
{
"type": "uint256",
"name": "deadline",
"indexed": true,
"unit": "sec"
},
{
"type": "uint256",
"name": "A",
"indexed": false
},
{
"type": "uint256",
"name": "fee",
"indexed": false
},
{
"type": "uint256",
"name": "admin_fee",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "NewParameters",
"inputs": [
{
"type": "uint256",
"name": "A",
"indexed": false
},
{
"type": "uint256",
"name": "fee",
"indexed": false
},
{
"type": "uint256",
"name": "admin_fee",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"outputs": [],
"inputs": [
{
"type": "address[4]",
"name": "_coins"
},
{
"type": "address[4]",
"name": "_underlying_coins"
},
{
"type": "address",
"name": "_pool_token"
},
{
"type": "uint256",
"name": "_A"
},
{
"type": "uint256",
"name": "_fee"
}
],
"constant": false,
"payable": false,
"type": "constructor"
},
{
"name": "get_virtual_price",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 1570535
},
{
"name": "calc_token_amount",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "uint256[4]",
"name": "amounts"
},
{
"type": "bool",
"name": "deposit"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 6103471
},
{
"name": "add_liquidity",
"outputs": [],
"inputs": [
{
"type": "uint256[4]",
"name": "amounts"
},
{
"type": "uint256",
"name": "min_mint_amount"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 9331701
},
{
"name": "get_dy",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 3489637
},
{
"name": "get_dy_underlying",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 3489467
},
{
"name": "exchange",
"outputs": [],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
},
{
"type": "uint256",
"name": "min_dy"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 7034253
},
{
"name": "exchange_underlying",
"outputs": [],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
},
{
"type": "uint256",
"name": "min_dy"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 7050488
},
{
"name": "remove_liquidity",
"outputs": [],
"inputs": [
{
"type": "uint256",
"name": "_amount"
},
{
"type": "uint256[4]",
"name": "min_amounts"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 241191
},
{
"name": "remove_liquidity_imbalance",
"outputs": [],
"inputs": [
{
"type": "uint256[4]",
"name": "amounts"
},
{
"type": "uint256",
"name": "max_burn_amount"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 9330864
},
{
"name": "commit_new_parameters",
"outputs": [],
"inputs": [
{
"type": "uint256",
"name": "amplification"
},
{
"type": "uint256",
"name": "new_fee"
},
{
"type": "uint256",
"name": "new_admin_fee"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 146045
},
{
"name": "apply_new_parameters",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 133452
},
{
"name": "revert_new_parameters",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 21775
},
{
"name": "commit_transfer_ownership",
"outputs": [],
"inputs": [
{
"type": "address",
"name": "_owner"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 74452
},
{
"name": "apply_transfer_ownership",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 60508
},
{
"name": "revert_transfer_ownership",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 21865
},
{
"name": "withdraw_admin_fees",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 23448
},
{
"name": "kill_me",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 37818
},
{
"name": "unkill_me",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 21955
},
{
"name": "coins",
"outputs": [
{
"type": "address",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "arg0"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 2130
},
{
"name": "underlying_coins",
"outputs": [
{
"type": "address",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "arg0"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 2160
},
{
"name": "balances",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "arg0"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 2190
},
{
"name": "A",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2021
},
{
"name": "fee",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2051
},
{
"name": "admin_fee",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2081
},
{
"name": "owner",
"outputs": [
{
"type": "address",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2111
},
{
"name": "admin_actions_deadline",
"outputs": [
{
"type": "uint256",
"unit": "sec",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2141
},
{
"name": "transfer_ownership_deadline",
"outputs": [
{
"type": "uint256",
"unit": "sec",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2171
},
{
"name": "future_A",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2201
},
{
"name": "future_fee",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2231
},
{
"name": "future_admin_fee",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2261
},
{
"name": "future_owner",
"outputs": [
{
"type": "address",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2291
}
]

54
test/dai.js Normal file
View File

@ -0,0 +1,54 @@
// const { BN, ether, balance } = require('openzeppelin-test-helpers');
// const { expect } = require('chai');
// const { asyncForEach } = require('./utils');
// // ABI
// const daiABI = require('./abi/dai');
// // userAddress must be unlocked using --unlock ADDRESS
// const userAddress = '0x9eb7f2591ed42dee9315b6e2aaf21ba85ea69f8c';
// const daiAddress = '0x6b175474e89094c44da98b954eedeac495271d0f';
// const daiContract = new web3.eth.Contract(daiABI, daiAddress);
// contract('Truffle Mint DAI', async accounts => {
// it('should send ether to the DAI address', async () => {
// // Send 0.1 eth to userAddress to have gas to send an ERC20 tx.
// await web3.eth.sendTransaction({
// from: accounts[0],
// to: userAddress,
// value: ether('0.1')
// });
// const ethBalance = await balance.current(userAddress);
// expect(new BN(ethBalance)).to.be.bignumber.least(new BN(ether('0.1')));
// });
// it('should mint DAI for our first 5 generated accounts', async () => {
// // Get 100 DAI for first 5 accounts
// await asyncForEach(accounts.slice(0, 5), async account => {
// // daiAddress is passed to ganache-cli with flag `--unlock`
// // so we can use the `transfer` method
// await daiContract.methods
// .transfer(account, ether('100').toString())
// .send({ from: userAddress, gasLimit: 800000 });
// const daiBalance = await daiContract.methods.balanceOf(account).call();
// expect(new BN(daiBalance)).to.be.bignumber.least(ether('100'));
// });
// });
// });
// contract('Truffle Approve DAI', async accounts => {
// it('should mint DAI for our first 5 generated accounts', async () => {
// // Get 100 DAI for first 5 accounts
// await asyncForEach(accounts.slice(0, 5), async account => {
// // daiAddress is passed to ganache-cli with flag `--unlock`
// // so we can use the `transfer` method
// await daiContract.methods
// .approve('0xDCa32D06633e49F4731cF473587691355F24476a', "1000000000000000000000000000")
// .send({ from: account, gasLimit: 800000 });
// console.log(await daiContract.methods.allowance(account, '0xA5407eAE9Ba41422680e2e00537571bcC53efBfD').call())
// });
// });
// });

5
test/utils.js Normal file
View File

@ -0,0 +1,5 @@
module.exports.asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};

View File

@ -51,7 +51,7 @@ module.exports = {
//
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 9545, // Standard Ethereum port (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},