From 4205b6c824fe4b0121ef5a991eed5a4419a23455 Mon Sep 17 00:00:00 2001 From: felix2feng Date: Thu, 21 May 2020 11:49:34 -0700 Subject: [PATCH] Test --- .../set_protocol/MedianizerWrapper.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wrappers/set_protocol/MedianizerWrapper.ts b/src/wrappers/set_protocol/MedianizerWrapper.ts index 7a4b433f0..f9b52b3e6 100644 --- a/src/wrappers/set_protocol/MedianizerWrapper.ts +++ b/src/wrappers/set_protocol/MedianizerWrapper.ts @@ -44,8 +44,23 @@ export class MedianizerWrapper { * @return Hex representation of the current price on the medianizer */ public async read(medianizerAddress: Address): Promise { - const medianizerContract = await this.contracts.loadMedianizerContract(medianizerAddress); + // If it is authorizable, pick an authorized address and read. Otherwise, just call read + try { + const medianizerContract = await this.contracts.loadAuthorizableAsync(medianizerAddress); + const authorizedList = await medianizerContract.getAuthorizedAddresses.callAsync(); + + if (authorizedList.length > 0) { + return await new web3.eth.Contract(medianizerContract.abi, medianizerAddress).methods + .read() + .call({ from: authorizedList[0] }); + + } else { + throw new Error('Requires authorized but is not'); + } + } catch { + const medianizerContract = await this.contracts.loadMedianizerContract(medianizerAddress); + return await medianizerContract.read.callAsync(); + } - return await medianizerContract.read.callAsync(); } }