Skip to content

Commit

Permalink
Merge pull request #132 from gnosis/contract-names
Browse files Browse the repository at this point in the history
Fix contract names
  • Loading branch information
cag committed Jan 18, 2019
2 parents a4cb9be + 4abcae0 commit 3fe2796
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const contractArtifacts = [
'CategoricalEvent',
'ScalarEvent',
'EventFactory',
'Token',
'ERC20',
'HumanFriendlyToken',
'EtherToken',
'WETH9',
'CentralizedOracle',
'CentralizedOracleFactory',
'UltimateOracle',
Expand Down Expand Up @@ -103,9 +103,7 @@ class Gnosis {
* - `CategoricalEvent <https://gnosis-pm-contracts.readthedocs.io/en/latest/CategoricalEvent.html>`_
* - `ScalarEvent <https://gnosis-pm-contracts.readthedocs.io/en/latest/ScalarEvent.html>`_
* - `EventFactory <https://gnosis-pm-contracts.readthedocs.io/en/latest/EventFactory.html>`_
* - `Token <https://gnosis-pm-contracts.readthedocs.io/en/latest/Token.html>`_
* - `HumanFriendlyToken <https://gnosis-pm-contracts.readthedocs.io/en/latest/HumanFriendlyToken.html>`_
* - `Ether Token <https://gnosis-pm-contracts.readthedocs.io/en/latest/EtherToken.html>`_
* - `CentralizedOracle <https://gnosis-pm-contracts.readthedocs.io/en/latest/CentralizedOracle.html>`_
* - `CentralizedOracleFactory <https://gnosis-pm-contracts.readthedocs.io/en/latest/CentralizedOracleFactory.html>`_
* - `UltimateOracle <https://gnosis-pm-contracts.readthedocs.io/en/latest/UltimateOracle.html>`_
Expand All @@ -114,6 +112,8 @@ class Gnosis {
* - `Market <https://gnosis-pm-contracts.readthedocs.io/en/latest/Market.html>`_
* - `StandardMarket <https://gnosis-pm-contracts.readthedocs.io/en/latest/StandardMarket.html>`_
* - `Standard Market Factory <https://gnosis-pm-contracts.readthedocs.io/en/latest/StandardMarketFactory.html>`_
* - `ERC20 <https://theethereum.wiki/w/index.php/ERC20_Token_Standard>`_
* - `WETH9 <https://weth.io/>`_
*
* These are configured to use the web3 provider specified in Gnosis.create or subsequently modified with Gnosis.setWeb3Provider. The default gas costs for these abstractions are set to the maximum cost of their respective entries found in the `gas-stats.json` file built from the `core contracts <https://github.com/gnosis/pm-contracts#readme>`_. Additionally, the default message sender (i.e. `from` address) is set via the optional `defaultAccount` param in Gnosis.setWeb3Provider.
*
Expand All @@ -131,6 +131,9 @@ class Gnosis {
return [name, c]
}))

this.contracts.Token = this.contracts.ERC20
this.contracts.EtherToken = this.contracts.WETH9

_.forOwn(this.contracts, (c, name, cs) => {
const maxGasCost = Math.max(
...Object.values(c.gasStats || {}).map(
Expand Down Expand Up @@ -212,10 +215,7 @@ class Gnosis {

await Promise.all([
/**
* @TODO review comment below:
* If on mainnet, this will be an EtherToken contract abstraction pointing to the `MakerDAO WETH contract <https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#code>`_.
*
* Otherwise, if `EtherToken <https://gnosis-pm-contracts.readthedocs.io/en/latest/EtherToken.html>`_ is deployed to the current network, this will be set to an EtherToken contract abstraction pointing at the deployment address.
* This will be a WETH9 contract abstraction pointing to the canonical `wETH <https://weth.io/>`_ on the current network.
*
* @member {Contract} Gnosis#etherToken
*/
Expand Down
8 changes: 4 additions & 4 deletions src/markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function buyOutcomeTokens() {
buyTxOpts = Object.assign({}, opts, buyTxOpts)

const market = await this.contracts.Market.at(marketAddress)
const collateralToken = await this.contracts.WETH9.at(
const collateralToken = await this.contracts.ERC20.at(
await this.contracts.Event.at(
await market.eventContract(opts)
).collateralToken()
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function buyOutcomeTokens() {

buyOutcomeTokens.estimateGas = async function({ using }) {
if(using === 'stats') {
return this.contracts.WETH9.gasStats.approve.averageGasUsed +
return this.contracts.ERC20.gasStats.approve.averageGasUsed +
this.contracts.Market.gasStats.buy.averageGasUsed
}
throw new Error(`unsupported gas estimation source ${using}`)
Expand Down Expand Up @@ -202,7 +202,7 @@ export async function sellOutcomeTokens() {
sellTxOpts = Object.assign({}, opts, sellTxOpts)

const market = await this.contracts.Market.at(marketAddress)
const outcomeToken = await this.contracts.WETH9.at(
const outcomeToken = await this.contracts.ERC20.at(
await this.contracts.Event.at(
await market.eventContract(opts)
).outcomeTokens(outcomeTokenIndex)
Expand Down Expand Up @@ -260,7 +260,7 @@ export async function sellOutcomeTokens() {

sellOutcomeTokens.estimateGas = async function({ using }) {
if(using === 'stats') {
return this.contracts.WETH9.gasStats.approve.averageGasUsed +
return this.contracts.ERC20.gasStats.approve.averageGasUsed +
this.contracts.Market.gasStats.sell.averageGasUsed
}
throw new Error(`unsupported gas estimation source ${using}`)
Expand Down
6 changes: 6 additions & 0 deletions test/test_gnosis.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ describe('Gnosis', function () {
assert(gnosis.standardMarketFactory.gasStats)
})

it('initializes with contract aliases for ERC20 and WETH9', async () => {
let gnosis = await Gnosis.create()
assert.strictEqual(gnosis.contracts.ERC20, gnosis.contracts.Token)
assert.strictEqual(gnosis.contracts.WETH9, gnosis.contracts.EtherToken)
})

it('initializes on the mainnet with an etherToken instance that points to the maker WETH', async () => {
let gnosis = await Gnosis.create({
ethereum: ganache.provider({ network_id: 1 }),
Expand Down
6 changes: 3 additions & 3 deletions test/test_markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('Gnosis market mechanics', () => {
assertIsClose(localCalculatedProfit.valueOf(), chainCalculatedProfit.valueOf())
assert(localCalculatedProfit.lte(chainCalculatedProfit.valueOf()))

let outcomeToken = await gnosis.contracts.WETH9.at(await gnosis.contracts.Event.at(await market.eventContract()).outcomeTokens(outcomeTokenIndex))
let outcomeToken = await gnosis.contracts.ERC20.at(await gnosis.contracts.Event.at(await market.eventContract()).outcomeTokens(outcomeTokenIndex))
requireEventFromTXResult(await outcomeToken.approve(market.address, numOutcomeTokensToSell), 'Approval')
let saleEvent = requireEventFromTXResult(
await market.sell(outcomeTokenIndex, numOutcomeTokensToSell, localCalculatedProfit.valueOf()),
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('Gnosis market mechanics', () => {
const outcomeTokenIndex = 0
const outcomeTokenCount = 1e18

const outcomeToken = await gnosis.contracts.WETH9.at(
const outcomeToken = await gnosis.contracts.ERC20.at(
await gnosis.contracts.Event.at(
await market.eventContract()
).outcomeTokens(outcomeTokenIndex)
Expand Down Expand Up @@ -309,7 +309,7 @@ describe('Gnosis market mechanics', () => {
const outcomeTokenIndex = 0
const outcomeTokenCount = 1e17

const outcomeToken = await gnosis.contracts.WETH9.at(
const outcomeToken = await gnosis.contracts.ERC20.at(
await gnosis.contracts.Event.at(
await market.eventContract()
).outcomeTokens(outcomeTokenIndex)
Expand Down

0 comments on commit 3fe2796

Please sign in to comment.