diff --git a/src/keeper/ContractHandler.ts b/src/keeper/ContractHandler.ts index 0c03aca..8bd1d4e 100644 --- a/src/keeper/ContractHandler.ts +++ b/src/keeper/ContractHandler.ts @@ -35,7 +35,7 @@ export default class ContractHandler extends Instantiable { this.setInstanceConfig(config) } - public async get(what: string): Promise { + public async get(what: string, optional: boolean = false): Promise { const where = (await this.ocean.keeper.getNetworkName()).toLowerCase() const networkId = await this.ocean.keeper.getNetworkId() try { @@ -44,7 +44,9 @@ export default class ContractHandler extends Instantiable { (await this.load(what, where, networkId)) ) } catch (err) { - this.logger.error('Failed to load', what, 'from', where, err) + if (!optional) { + this.logger.error('Failed to load', what, 'from', where, err) + } throw err } } diff --git a/src/keeper/contracts/ContractBase.ts b/src/keeper/contracts/ContractBase.ts index 6725ff2..dd2ee64 100644 --- a/src/keeper/contracts/ContractBase.ts +++ b/src/keeper/contracts/ContractBase.ts @@ -14,7 +14,7 @@ export abstract class ContractBase extends Instantiable { return this.contract.options.address } - constructor(contractName) { + constructor(contractName, private optional: boolean = false) { super() this.contractName = contractName } @@ -53,7 +53,7 @@ export abstract class ContractBase extends Instantiable { protected async init(config: InstantiableConfig) { this.setInstanceConfig(config) const contractHandler = new ContractHandler(config) - this.contract = await contractHandler.get(this.contractName) + this.contract = await contractHandler.get(this.contractName, this.optional) } protected async getFromAddress(from?: string): Promise { diff --git a/src/keeper/contracts/Dispenser.ts b/src/keeper/contracts/Dispenser.ts index b44bd27..e14363f 100644 --- a/src/keeper/contracts/Dispenser.ts +++ b/src/keeper/contracts/Dispenser.ts @@ -5,7 +5,7 @@ export default class Dispenser extends ContractBase { public static async getInstance( config: InstantiableConfig ): Promise { - const dispenser: Dispenser = new Dispenser('Dispenser') + const dispenser: Dispenser = new Dispenser('Dispenser', true) await dispenser.init(config) return dispenser }