From d0bf7f0bef49f42628be9b1eb6c8c84ee7008177 Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Thu, 8 Oct 2020 10:40:42 +0200 Subject: [PATCH] Add xDAI compatibility (#212) * Add xDAI contract in env * Upgrade version of dex-js * Go back to dex-js version 0.3 * Allow to not provide the TCR * Add TOKEN_OVERRIDES for xDAI * Simplify type * Remove unused import --- .env.example | 4 ++++ package.json | 2 +- src/bot.ts | 2 -- src/config.ts | 1 + src/helpers/contracts.ts | 2 +- src/services/DfusionService.ts | 11 ++++++----- yarn.lock | 12 ++++++------ 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.env.example b/.env.example index c269ed4..c85b4fb 100644 --- a/.env.example +++ b/.env.example @@ -70,6 +70,10 @@ NODE_URL=wss://mainnet.infura.io/ws/v3/ # https://github.com/gnosis/dex-contracts/blob/master/networks.json STABLE_COIN_CONTRACT_ADDRESS=0x6F400810b62df8E13fded51bE75fF5393eaa841F +# xDAO Gnosis Protocol +# https://github.com/gnosis/dex-contracts/blob/master/networks.json +STABLE_COIN_CONTRACT_ADDRESS=0x25B06305CC4ec6AfCF3E7c0b673da1EF8ae26313 + # Rinkeby Gnosis Protocol # https://github.com/gnosis/dex-contracts/blob/master/networks.json #STABLE_COIN_CONTRACT_ADDRESS=0xC576eA7bd102F7E476368a5E98FA455d1Ea34dE2 diff --git a/package.json b/package.json index cb2f64e..e9e4834 100644 --- a/package.json +++ b/package.json @@ -69,4 +69,4 @@ "typescript": "^3.7.2", "typescript-transform-paths": "^1.1.13" } -} +} \ No newline at end of file diff --git a/src/bot.ts b/src/bot.ts index c60d32d..9b43e02 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -12,8 +12,6 @@ const WEB_BASE_URL = process.env.WEB_BASE_URL assert(WEB_BASE_URL, 'WEB_BASE_URL is required') const port = parseInt(process.env.API_PORT || '3000') -assert(process.env.TCR_CONTRACT_ADDRESS, 'TCR_CONTRACT_ADDRESS env var is required') - moment.tz.setDefault('Etc/GMT') logUnhandledErrors() diff --git a/src/config.ts b/src/config.ts index 84574a7..77ae7fc 100644 --- a/src/config.ts +++ b/src/config.ts @@ -22,4 +22,5 @@ export const TOKEN_OVERRIDES = { forceAddressDisplay: true, // name and symbol are ignored when `forceAddressDisplay` is set }, }, + 100: {}, } diff --git a/src/helpers/contracts.ts b/src/helpers/contracts.ts index 6e491ba..8cf0165 100644 --- a/src/helpers/contracts.ts +++ b/src/helpers/contracts.ts @@ -4,4 +4,4 @@ import { TCR_CONTRACT_ADDRESS } from 'config' export const batchExchangeContract = createBatchExchangeContract(web3) export const erc20Contract = createErc20Contract(web3) -export const tcrContract = createTcrContract(web3, TCR_CONTRACT_ADDRESS) +export const tcrContract = TCR_CONTRACT_ADDRESS ? createTcrContract(web3, TCR_CONTRACT_ADDRESS) : undefined diff --git a/src/services/DfusionService.ts b/src/services/DfusionService.ts index 72820e1..b30537d 100644 --- a/src/services/DfusionService.ts +++ b/src/services/DfusionService.ts @@ -39,7 +39,7 @@ const log = new Logger('service:dfusion') export interface Params { batchExchangeContract: BatchExchangeContract erc20Contract: Erc20Contract - tcrContract: TcrContract + tcrContract?: TcrContract tokenIdsFilter?: string[] web3: Web3 } @@ -96,7 +96,7 @@ export interface AboutDto { contractsVersion: string dexJsVersion: string batchExchangeAddress: string - tcrContractAddress: string + tcrContractAddress?: string tcrListId: number } @@ -120,7 +120,7 @@ export class DfusionRepoImpl implements DfusionService { private _erc20Contract: Erc20Contract private _tokenIdsFilter?: string[] - private _tcrContract: TcrContract + private _tcrContract?: TcrContract private _networkId: number private _batchTime: BigNumber private _cache: NodeCache @@ -208,6 +208,7 @@ export class DfusionRepoImpl implements DfusionService { public watchOrderPlacement(params: WatchOrderPlacementParams) { const OrderPlacement = this._contract.events.OrderPlacement const subscriptions: Map> = new Map() + if (this._tokenIdsFilter) { const tokenListDescription = this._tokenIdsFilter.join(', ') subscriptions.set( @@ -315,7 +316,7 @@ export class DfusionRepoImpl implements DfusionService { dexJsVersion, version: packageJson.version, batchExchangeAddress: this._contract.options.address, - tcrContractAddress: this._tcrContract.options.address, + tcrContractAddress: this._tcrContract?.options.address, tcrListId: TCR_LIST_ID, } } @@ -403,7 +404,7 @@ export class DfusionRepoImpl implements DfusionService { return cachedAddresses } - const tcrList = await this._tcrContract.methods + const tcrList = await this._tcrContract?.methods .getTokens(TCR_LIST_ID) .call() .catch(() => []) diff --git a/yarn.lock b/yarn.lock index aa647b4..11361e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -402,9 +402,9 @@ "@ethersproject/signing-key" "^5.0.0" "@gnosis.pm/dex-contracts@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@gnosis.pm/dex-contracts/-/dex-contracts-0.2.0.tgz#1649e2efdb818158db79569e9375d6bf9405c63f" - integrity sha512-9zMT7XaveDJ5L52o0RNRcFL0Vf2nOpX1lGsWimIZCZBnCL1HyvKHvX4W4mfcItkScNVNgvJ9EWSNVXQjS+pK5g== + version "0.2.15" + resolved "https://registry.yarnpkg.com/@gnosis.pm/dex-contracts/-/dex-contracts-0.2.15.tgz#254314c6f8dff33a022a3d2b67035b08f0782c94" + integrity sha512-rvGuiHfl12F70qBiJimUv/uGdn5+Dfao2xAbhiQh9/wJBt5A5nVYONnZ13JFfIoOrSJTRT1n61SEhLfLOlG6dw== dependencies: bn.js "^5.1.1" @@ -1298,9 +1298,9 @@ bn.js@^4.11.9: integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw== bn.js@^5.1.1: - version "5.1.1" - resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.1.tgz#48efc4031a9c4041b9c99c6941d903463ab62eb5" - integrity sha512-IUTD/REb78Z2eodka1QZyyEk66pciRcP6Sroka0aI3tG/iwIdYLrBD62RsubR7vqdt3WyX8p4jxeatzmRSphtA== + version "5.1.3" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.3.tgz#beca005408f642ebebea80b042b4d18d2ac0ee6b" + integrity sha512-GkTiFpjFtUzU9CbMeJ5iazkCzGL3jrhzerzZIuqLABjbwRaFt33I9tUdSNryIptM+RxDet6OKm2WnLXzW51KsQ== body-parser@1.19.0, body-parser@^1.16.0: version "1.19.0"