diff --git a/src/balancer/OceanPool.ts b/src/balancer/OceanPool.ts index c587ec95..398e5a55 100644 --- a/src/balancer/OceanPool.ts +++ b/src/balancer/OceanPool.ts @@ -54,6 +54,7 @@ export enum PoolCreateProgressStep { export class OceanPool extends Pool { public oceanAddress: string = null public dtAddress: string = null + public startBlock: number constructor( web3: Web3, @@ -62,12 +63,14 @@ export class OceanPool extends Pool { poolABI: AbiItem | AbiItem[] = null, factoryAddress: string = null, oceanAddress: string = null, - gaslimit?: number + startBlock?: number ) { - super(web3, logger, factoryABI, poolABI, factoryAddress, gaslimit) + super(web3, logger, factoryABI, poolABI, factoryAddress) if (oceanAddress) { this.oceanAddress = oceanAddress } + if (startBlock) this.startBlock = startBlock + else this.startBlock = 0 } /** @@ -855,7 +858,7 @@ export class OceanPool extends Pool { const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress) const events = await factory.getPastEvents('BPoolRegistered', { filter: {}, - fromBlock: BPFACTORY_DEPLOY_BLOCK, + fromBlock: this.startBlock, toBlock: 'latest' }) events.sort((a, b) => (a.blockNumber > b.blockNumber ? 1 : -1)) @@ -920,7 +923,7 @@ export class OceanPool extends Pool { const events = await factory.getPastEvents('BPoolRegistered', { filter: account ? { registeredBy: account } : {}, - fromBlock: BPFACTORY_DEPLOY_BLOCK, + fromBlock: this.startBlock, toBlock: 'latest' }) for (let i = 0; i < events.length; i++) { @@ -941,7 +944,7 @@ export class OceanPool extends Pool { const events = await factory.getPastEvents('BPoolRegistered', { filter: {}, - fromBlock: BPFACTORY_DEPLOY_BLOCK, + fromBlock: this.startBlock, toBlock: 'latest' }) for (let i = 0; i < events.length; i++) { @@ -988,7 +991,7 @@ export class OceanPool extends Pool { const dtAddress = await this.getDTAddress(poolAddress) const filter: Filter = account ? { caller: account } : {} let events: EventData[] - + if (startBlock === 0) startBlock = this.startBlock events = await pool.getPastEvents('LOG_SWAP', { filter, fromBlock: startBlock, @@ -1034,7 +1037,7 @@ export class OceanPool extends Pool { const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress) const events = await factory.getPastEvents('BPoolRegistered', { filter: {}, - fromBlock: BPFACTORY_DEPLOY_BLOCK, + fromBlock: this.startBlock, toBlock: 'latest' }) for (let i = 0; i < events.length; i++) { diff --git a/src/balancer/Pool.ts b/src/balancer/Pool.ts index 26ef8256..e27dc5ed 100644 --- a/src/balancer/Pool.ts +++ b/src/balancer/Pool.ts @@ -26,10 +26,9 @@ export class Pool extends PoolFactory { logger: Logger, factoryABI: AbiItem | AbiItem[] = null, poolABI: AbiItem | AbiItem[] = null, - factoryAddress: string = null, - gaslimit?: number + factoryAddress: string = null ) { - super(web3, logger, factoryABI, factoryAddress, gaslimit) + super(web3, logger, factoryABI, factoryAddress) if (poolABI) this.poolABI = poolABI else this.poolABI = jsonpoolABI.abi as AbiItem[] } diff --git a/src/balancer/PoolFactory.ts b/src/balancer/PoolFactory.ts index c6811e69..953176e4 100644 --- a/src/balancer/PoolFactory.ts +++ b/src/balancer/PoolFactory.ts @@ -15,8 +15,7 @@ export class PoolFactory { web3: Web3, logger: Logger, factoryABI: AbiItem | AbiItem[] = null, - factoryAddress: string = null, - gaslimit?: number + factoryAddress: string = null ) { this.web3 = web3 @@ -25,7 +24,6 @@ export class PoolFactory { if (factoryAddress) { this.factoryAddress = factoryAddress } - if (gaslimit) this.GASLIMIT_DEFAULT = gaslimit this.logger = logger } diff --git a/src/exchange/FixedRateExchange.ts b/src/exchange/FixedRateExchange.ts index af7c614f..1e748a1b 100644 --- a/src/exchange/FixedRateExchange.ts +++ b/src/exchange/FixedRateExchange.ts @@ -39,6 +39,7 @@ export class OceanFixedRateExchange { public contract: Contract = null private logger: Logger public datatokens: DataTokens + public startBlock: number /** * Instantiate FixedRateExchange @@ -53,10 +54,13 @@ export class OceanFixedRateExchange { fixedRateExchangeAddress: string = null, fixedRateExchangeABI: AbiItem | AbiItem[] = null, oceanAddress: string = null, - datatokens: DataTokens + datatokens: DataTokens, + startBlock?: number ) { this.web3 = web3 this.fixedRateExchangeAddress = fixedRateExchangeAddress + if (startBlock) this.startBlock = startBlock + else this.startBlock = 0 this.fixedRateExchangeABI = fixedRateExchangeABI || (defaultFixedRateExchangeABI.abi as AbiItem[]) this.oceanAddress = oceanAddress diff --git a/src/models/Config.ts b/src/models/Config.ts index d1cf7d57..e7a3e924 100644 --- a/src/models/Config.ts +++ b/src/models/Config.ts @@ -96,6 +96,11 @@ export class Config { * @type {any} */ public metadataContractABI?: AbiItem | AbiItem[] + /** + * block number of the deployment + * @type {number} + */ + public startBlock?: number /** * Log level. * @type {boolean | LogLevel} diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 4318e0db..9c933ac9 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -59,7 +59,8 @@ export class Ocean extends Instantiable { instanceConfig.config.poolFactoryABI, instanceConfig.config.poolABI, instanceConfig.config.poolFactoryAddress, - instanceConfig.config.oceanTokenAddress + instanceConfig.config.oceanTokenAddress, + instanceConfig.config.startBlock ) instance.fixedRateExchange = new OceanFixedRateExchange( instanceConfig.config.web3Provider, @@ -67,7 +68,8 @@ export class Ocean extends Instantiable { instanceConfig.config.fixedRateExchangeAddress, instanceConfig.config.fixedRateExchangeAddressABI, instanceConfig.config.oceanTokenAddress, - instance.datatokens + instance.datatokens, + instanceConfig.config.startBlock ) instance.OnChainMetadataCache = new OnChainMetadataCache( instanceConfig.config.web3Provider, diff --git a/src/utils/ConfigHelper.ts b/src/utils/ConfigHelper.ts index 2da3651e..cde9930c 100644 --- a/src/utils/ConfigHelper.ts +++ b/src/utils/ConfigHelper.ts @@ -27,7 +27,8 @@ const configs: ConfigHelperConfig[] = [ factoryAddress: '0x1234', poolFactoryAddress: null, fixedRateExchangeAddress: null, - metadataContractAddress: null + metadataContractAddress: null, + startBlock: 0 }, { // barge @@ -40,7 +41,8 @@ const configs: ConfigHelperConfig[] = [ factoryAddress: null, poolFactoryAddress: null, fixedRateExchangeAddress: null, - metadataContractAddress: null + metadataContractAddress: null, + startBlock: 0 }, { networkId: 4, @@ -52,7 +54,8 @@ const configs: ConfigHelperConfig[] = [ factoryAddress: null, poolFactoryAddress: null, fixedRateExchangeAddress: null, - metadataContractAddress: null + metadataContractAddress: null, + startBlock: 7294090 }, { networkId: 1, @@ -64,7 +67,8 @@ const configs: ConfigHelperConfig[] = [ factoryAddress: null, poolFactoryAddress: null, fixedRateExchangeAddress: null, - metadataContractAddress: null + metadataContractAddress: null, + startBlock: 11105522 } ] diff --git a/test/unit/balancer/Balancer.test.ts b/test/unit/balancer/Balancer.test.ts index cf92e5ba..d990048f 100644 --- a/test/unit/balancer/Balancer.test.ts +++ b/test/unit/balancer/Balancer.test.ts @@ -109,7 +109,8 @@ describe('Balancer flow', () => { OceanPoolFactory.abi as AbiItem[], OceanSPool.abi as AbiItem[], OceanPoolFactoryAddress, - oceanTokenAddress + oceanTokenAddress, + 0 ) assert(Pool !== null) })