Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/wrappers/set_protocol/MedianizerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,23 @@ export class MedianizerWrapper {
* @return Hex representation of the current price on the medianizer
*/
public async read(medianizerAddress: Address): Promise<Bytes> {
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();
}
}