@dydxfoundation/governance
Version:
dYdX governance smart contracts
23 lines (22 loc) • 1.09 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findAddressWithRole = void 0;
const lodash_1 = __importDefault(require("lodash"));
const util_1 = require("../../src/lib/util");
async function findAddressWithRole(starkProxy, role) {
const roleHash = (0, util_1.getRole)(role);
const roleGrantedEvents = await starkProxy.queryFilter(starkProxy.filters.RoleGranted(roleHash, null, null));
const owners = lodash_1.default.uniq(lodash_1.default.map(roleGrantedEvents, 'args.account'));
const roleOwners = (await Promise.all(owners.map(async (account) => {
const hasRole = await starkProxy.hasRole(roleHash, account);
return hasRole ? account : '';
}))).filter((account) => !!account);
if (!roleOwners.length) {
throw new Error(`StarkProxy has no accounts that own role ${role.toString()}`);
}
return roleOwners[0];
}
exports.findAddressWithRole = findAddressWithRole;