Skip to content

Instantly share code, notes, and snippets.

@kliu128
Last active September 21, 2018 18:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kliu128/28f3f758dcac78daffaf6fe364197456 to your computer and use it in GitHub Desktop.
Save kliu128/28f3f758dcac78daffaf6fe364197456 to your computer and use it in GitHub Desktop.
Deploys Maker contracts to a Truffle development network
OasisDEXInterface oasisDex;
WETHInterface weth;
ERC20 dai;
function createStudyWithDaiExchange(
string _name,
string _desc,
string _citation,
uint64 _expiresOn,
string _publicKey,
DataDefinition _dataDefinition,
string _consentHash,
uint _minBuyAmt) public payable
{
// Convert the ETH to Wrapped ETH (WETH) for trading
weth.deposit.value(msg.value)();
// Give max allowance to oasisdex to spend weth
if (weth.allowance(this, oasisDex) < msg.value) {
weth.approve(oasisDex, uint(-1));
}
// Sell the WETH for a minBuyAmt of DAI
uint daiAmt = oasisDex.sellAllAmount(weth, msg.value, dai, _minBuyAmt);
// Now our contract owns daiAmount of Dai.
// <create the study with that amount of Dai as payment>
}
// SPDX-License-Identifier: AGPL-3.0+
const OasisDEX = artifacts.require("./maker/MatchingMarket.sol");
const FakeDAI = artifacts.require("./maker/FakeDAI.sol");
const WETH = artifacts.require("./maker/WETH9_.sol");
const Web3 = require("web3");
const web3 = new Web3();
// never close
const OASIS_DEX_CLOSE_TIME = 1000000000000000;
const WETH_DEPOSIT_AMOUNT = web3.utils.toWei("5", "ether");
const DAI_PER_WETH = 400;
const DAI_DEPOSIT_AMOUNT = 1000 * 10 ** 18;
module.exports = async (deployer, network) => {
if (network !== "develop") {
return; // Contracts already deployed
}
// Deploy all contracts
await Promise.all([
deployer.deploy(OasisDEX, OASIS_DEX_CLOSE_TIME),
deployer.deploy(WETH),
deployer.deploy(FakeDAI)
]);
const [oasisDex, weth, fdai] = await Promise.all([
OasisDEX.deployed(),
WETH.deployed(),
FakeDAI.deployed()
]);
await oasisDex.addTokenPairWhitelist(WETH.address, FakeDAI.address);
console.log("Setting up WETH -> DAI trading site...");
await weth.deposit({ value: WETH_DEPOSIT_AMOUNT });
await weth.approve(OasisDEX.address, WETH_DEPOSIT_AMOUNT);
await oasisDex.offer(
WETH_DEPOSIT_AMOUNT,
WETH.address,
WETH_DEPOSIT_AMOUNT * DAI_PER_WETH,
FakeDAI.address,
0
);
console.log("Setting up DAI -> WETH trading side...");
// Set up DAI -> WETH trade side
await fdai.mint(await fdai.owner(), DAI_DEPOSIT_AMOUNT);
await fdai.approve(OasisDEX.address, DAI_DEPOSIT_AMOUNT);
await oasisDex.offer(
DAI_DEPOSIT_AMOUNT,
FakeDAI.address,
// TODO For some reason this throws an Internal JSON-RPC error when you
// make this < 0.005
DAI_DEPOSIT_AMOUNT * 0.005,
WETH.address,
0
);
};
const OasisDEX = artifacts.require("./maker/MatchingMarket.sol");
const FakeDAI = artifacts.require("./maker/FakeDAI.sol");
const WETH = artifacts.require("./maker/WETH9_.sol");
const Web3 = require("web3");
const web3 = new Web3();
// never close
const OASIS_DEX_CLOSE_TIME = 1000000000000000;
const WETH_DEPOSIT_AMOUNT = web3.utils.toWei("5", "ether");
const DAI_PER_WETH = 400;
const DAI_DEPOSIT_AMOUNT = 1000 * 10 ** 18;
module.exports = async (deployer, network) => {
if (network !== "develop") {
return; // Contracts already deployed
}
// Deploy all contracts
await Promise.all([
deployer.deploy(OasisDEX, OASIS_DEX_CLOSE_TIME),
deployer.deploy(WETH),
deployer.deploy(FakeDAI)
]);
const [oasisDex, weth, fdai] = await Promise.all([
OasisDEX.deployed(),
WETH.deployed(),
FakeDAI.deployed()
]);
await oasisDex.addTokenPairWhitelist(WETH.address, FakeDAI.address);
console.log("Setting up WETH -> DAI trading site...");
await weth.deposit({ value: WETH_DEPOSIT_AMOUNT });
await weth.approve(OasisDEX.address, WETH_DEPOSIT_AMOUNT);
await oasisDex.offer(
WETH_DEPOSIT_AMOUNT,
WETH.address,
WETH_DEPOSIT_AMOUNT * DAI_PER_WETH,
FakeDAI.address,
0
);
console.log("Setting up DAI -> WETH trading side...");
// Set up DAI -> WETH trade side
await fdai.mint(await fdai.owner(), DAI_DEPOSIT_AMOUNT);
await fdai.approve(OasisDEX.address, DAI_DEPOSIT_AMOUNT);
await oasisDex.offer(
DAI_DEPOSIT_AMOUNT,
FakeDAI.address,
// TODO For some reason this throws an Internal JSON-RPC error when you
// make this < 0.005
DAI_DEPOSIT_AMOUNT * 0.005,
WETH.address,
0
);
Study[] studies; ERC20 dai;
constructor(address _dai) {
dai = ERC20(_dai);
}
function createStudy(
string _name,
string _desc,
string _citation,
uint64 _expiresOn,
string _publicKey,
DataDefinition _dataDefinition,
string _consentHash,
uint256 _paymentPool) public
{
require(_paymentPool != 0);
require(dai.transferFrom(msg.sender, this, _paymentPool));
Study memory newStudy;
newStudy.paymentPool = msg.value;
studies.push(newStudy);
}
await oasisDexMarket.functions.getBuyAmount(
await getDeployedAddress(Contract.DAI, getState().web3.network),
await getDeployedAddress(Contract.WETH, getState().web3.network),
paymentPool // In Ether
);
Study[] studies;
function createStudy(
string _name,
string _desc,
string _citation,
uint64 _expiresOn,
string _publicKey,
DataDefinition _dataDefinition,
string _consentHash) public payable
{
require(msg.value >= 0.1 ether);
Study memory newStudy;
newStudy.paymentPool = msg.value;
studies.push(newStudy);
}
@themandalore
Copy link

Awesome stuff here, just curious, do you have a FakeDai.sol contract anywhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment