Skip to content

Commit

Permalink
Updating deployment process for better external use of the project (#489
Browse files Browse the repository at this point in the history
)

This PR modifies the way artifacts are handled in the migration process. This enables the batch exchange deployment from external projects, without publishing the contracts in the npm package.

closes: #449

An example of how this repo can be used for an external project can be found here:
https://github.com/gnosis/dex-contracts-integration-example
  • Loading branch information
josojo committed Jan 22, 2020
1 parent c6e4ec4 commit 647875d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 31 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ And the output should look like this:
remainingAmount: 1e+21 } ]
```
# Building on top of BatchExchange
The integration of the dFusion contracts into your own truffle project are demonstrated here:
https://github.com/gnosis/dex-contracts-integration-example. This repository contains a minimal
truffle project allowing to build on top of contracts.
Please consult its readme for further information.
# Contributions
The continuous integration is running several linters which must pass in order to make a contribution to this repo. For your convenience there is a `pre-commit` hook file contained in the project's root directory. You can make your life easier by executing the following command after cloning this project (it will ensure your changes pass linting before allowing commits).
Expand Down
3 changes: 2 additions & 1 deletion migrations/2_dev_dependencies.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const migrateDependencies = require("../src/migration/dependencies")

module.exports = function(deployer, network) {
module.exports = function(deployer, network, accounts) {
return migrateDependencies({
artifacts,
deployer,
network,
account: accounts[0],
})
}
3 changes: 2 additions & 1 deletion migrations/3_batch_auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ const argv = require("yargs")
.help(false)
.version(false).argv

module.exports = async function(deployer, network) {
module.exports = async function(deployer, network, accounts) {
if (!argv.onlyMigrateStableX) {
return migrateSnappAuction({
artifacts,
network,
deployer,
account: accounts[0],
})
} else {
return
Expand Down
2 changes: 1 addition & 1 deletion migrations/4_batch_exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = async function(deployer, network, accounts, web3) {
artifacts,
deployer,
network,
accounts,
account: accounts[0],
web3,
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/dex-contracts",
"version": "0.1.3",
"version": "0.1.5-dev",
"description": "Contracts for dFusion multi-token batch auction exchange",
"main": "src/index.js",
"directories": {
Expand Down
29 changes: 20 additions & 9 deletions src/migration/PoC_dfusion.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
const { isDevelopmentNetwork, getDependency } = require("./utilities.js")
const deployOwl = require("@gnosis.pm/owl-token/src/migrations-truffle-5/3_deploy_OWL")

async function migrate({ artifacts, deployer, network, accounts, web3, maxTokens = 2 ** 16 - 1 }) {
let fee_token
async function migrate({ artifacts, deployer, network, account, web3, maxTokens = 2 ** 16 - 1 }) {
if (isDevelopmentNetwork(network)) {
await deployOwl({
artifacts,
deployer,
network,
accounts,
account,
web3,
})
const TokenOWLProxy = artifacts.require("TokenOWLProxy")
fee_token = await TokenOWLProxy.deployed()
} else {
const TokenOWLProxy = getDependency(artifacts, network, deployer, "@gnosis.pm/owl-token/build/contracts/TokenOWLProxy")
fee_token = await TokenOWLProxy.deployed()
}
const BatchExchange = artifacts.require("BatchExchange")
const TokenOWLProxy = getDependency(
artifacts,
network,
deployer,
account,
"@gnosis.pm/owl-token/build/contracts/TokenOWLProxy"
)
const fee_token = await TokenOWLProxy.deployed()

const BatchExchange = getDependency(
artifacts,
network,
deployer,
account,
"@gnosis.pm/dex-contracts/build/contracts/BatchExchange"
)
const BiMap = getDependency(
artifacts,
network,
deployer,
account,
"@gnosis.pm/solidity-data-structures/build/contracts/IdToAddressBiMap"
)
const IterableAppendOnlySet = getDependency(
artifacts,
network,
deployer,
account,
"@gnosis.pm/solidity-data-structures/build/contracts/IterableAppendOnlySet"
)

Expand Down
24 changes: 16 additions & 8 deletions src/migration/dependencies.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
const { isDevelopmentNetwork } = require("./utilities.js")
const { isDevelopmentNetwork, getDependency } = require("./utilities.js")

async function migrate({ artifacts, deployer, network }) {
async function migrate({ artifacts, deployer, network, account }) {
if (isDevelopmentNetwork(network)) {
// deploy DevDependencies
const Dependencies = artifacts.require("./DevDependencies")
await deployer.deploy(Dependencies)

// deploy libraries
const BiMap = artifacts.require("@gnosis.pm/solidity-data-structures/build/contracts/IdToAddressBiMap")
const BiMap = getDependency(
artifacts,
network,
deployer,
account,
"@gnosis.pm/solidity-data-structures/build/contracts/IdToAddressBiMap"
)
await deployer.deploy(BiMap)

const IterableAppendOnlySet = artifacts.require("@gnosis.pm/solidity-data-structures/build/contracts/IterableAppendOnlySet")
const IterableAppendOnlySet = getDependency(
artifacts,
network,
deployer,
account,
"@gnosis.pm/solidity-data-structures/build/contracts/IterableAppendOnlySet"
)
await deployer.deploy(IterableAppendOnlySet)
} else {
// eslint-disable-next-line no-console
Expand Down
3 changes: 2 additions & 1 deletion src/migration/snapp_auction.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { getDependency } = require("./utilities")

async function migrate({ artifacts, network, deployer }) {
async function migrate({ artifacts, network, deployer, account }) {
const BiMap = getDependency(
artifacts,
network,
deployer,
account,
"@gnosis.pm/solidity-data-structures/build/contracts/IdToAddressBiMap"
)

Expand Down
36 changes: 27 additions & 9 deletions src/migration/utilities.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
function getDependency(artifacts, network, deployer, path) {
let Contract
function initializeContract(path, deployer, accounts) {
const Contract = require("truffle-contract")

const contract = Contract(require(path))
contract.setProvider(deployer.provider)
contract.setNetwork(deployer.network_id)
// For some reason the automatic value calculation is not working, hence we do:
contract.defaults({
from: accounts[0],
gas: 6.5e6,
})
return contract
}

function getDependency(artifacts, network, deployer, account, path) {
let contract

if (isDevelopmentNetwork(network)) {
Contract = artifacts.require(path)
// If this migration script is used from the repository dex-contracts, the contract
// data is received via the artificats.require.
// If this migration script is used from an external project, the first try statement
// will fail and it will get the contracts from the function initializeContract.
try {
contract = artifacts.require(path.split("/").pop())
} catch (error) {
contract = initializeContract(path, deployer, account)
}
} else {
const contract = require("truffle-contract")

Contract = contract(require(path))
Contract.setProvider(deployer.provider)
Contract.setNetwork(deployer.network_id)
contract = initializeContract(path, deployer, account)
}
return Contract
return contract
}

function isDevelopmentNetwork(network) {
Expand Down

0 comments on commit 647875d

Please sign in to comment.