@graphprotocol/toolshed
Version:
A collection of tools and utilities for the Graph Protocol Typescript components
68 lines • 3.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAccounts = getAccounts;
exports.getDeployer = getDeployer;
exports.getGovernor = getGovernor;
exports.getArbitrator = getArbitrator;
exports.getPauseGuardian = getPauseGuardian;
exports.getSubgraphAvailabilityOracle = getSubgraphAvailabilityOracle;
exports.getGateway = getGateway;
exports.getTestAccounts = getTestAccounts;
// The Graph convention for account derivation is:
// 0: Deployer
// 1: Governor
// 2: Arbitrator
// 3: Pause guardian
// 4: Subgraph Availability Oracle
// 5: Gateway/payer
// 6+: Test accounts
var GraphAccountIndex;
(function (GraphAccountIndex) {
GraphAccountIndex[GraphAccountIndex["Deployer"] = 0] = "Deployer";
GraphAccountIndex[GraphAccountIndex["Governor"] = 1] = "Governor";
GraphAccountIndex[GraphAccountIndex["Arbitrator"] = 2] = "Arbitrator";
GraphAccountIndex[GraphAccountIndex["PauseGuardian"] = 3] = "PauseGuardian";
GraphAccountIndex[GraphAccountIndex["SubgraphAvailabilityOracle"] = 4] = "SubgraphAvailabilityOracle";
GraphAccountIndex[GraphAccountIndex["Gateway"] = 5] = "Gateway";
})(GraphAccountIndex || (GraphAccountIndex = {}));
async function getAccounts(provider) {
return {
deployer: await getDeployer(provider, GraphAccountIndex.Deployer),
governor: await getGovernor(provider, GraphAccountIndex.Governor),
arbitrator: await getArbitrator(provider, GraphAccountIndex.Arbitrator),
pauseGuardian: await getPauseGuardian(provider, GraphAccountIndex.PauseGuardian),
subgraphAvailabilityOracle: await getSubgraphAvailabilityOracle(provider, GraphAccountIndex.SubgraphAvailabilityOracle),
gateway: await getGateway(provider, GraphAccountIndex.Gateway),
test: await getTestAccounts(provider),
};
}
async function getDeployer(provider, accountIndex = GraphAccountIndex.Deployer) {
return _getAccount(provider, accountIndex);
}
async function getGovernor(provider, accountIndex = GraphAccountIndex.Governor) {
return _getAccount(provider, accountIndex);
}
async function getArbitrator(provider, accountIndex = GraphAccountIndex.Arbitrator) {
return _getAccount(provider, accountIndex);
}
async function getPauseGuardian(provider, accountIndex = GraphAccountIndex.PauseGuardian) {
return _getAccount(provider, accountIndex);
}
async function getSubgraphAvailabilityOracle(provider, accountIndex = GraphAccountIndex.SubgraphAvailabilityOracle) {
return _getAccount(provider, accountIndex);
}
async function getGateway(provider, accountIndex = GraphAccountIndex.Gateway) {
return _getAccount(provider, accountIndex);
}
async function getTestAccounts(provider) {
const accounts = (await provider.send('eth_accounts', []));
const numReservedAccounts = Object.values(GraphAccountIndex).filter((v) => typeof v === 'number').length;
if (accounts.length < numReservedAccounts) {
return [];
}
return await Promise.all(accounts.slice(numReservedAccounts).map(async (account) => await _getAccount(provider, account)));
}
async function _getAccount(provider, accountIndex) {
return await provider.getSigner(accountIndex);
}
//# sourceMappingURL=accounts.js.map