@nomad-xyz/sdk
Version:
86 lines • 3.47 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreContracts = void 0;
const ethers_1 = require("ethers");
const core = __importStar(require("@nomad-xyz/contracts-core"));
const multi_provider_1 = require("@nomad-xyz/multi-provider");
class CoreContracts extends multi_provider_1.Contracts {
constructor(context, domain, conf) {
super(context, domain, conf);
this.conf = conf;
}
/**
* Resolves Replica with given domain
*
* @param nameOrDomain The name or domain ID of the Replica
* @returns An interface for the Replica, undefined if not found
*/
getReplica(nameOrDomain) {
const domain = this.context.resolveDomainName(nameOrDomain);
if (!this.connection)
throw new multi_provider_1.NoProviderError(this.context, domain);
const replica = this.conf.replicas[domain];
if (!replica)
return;
return core.Replica__factory.connect(replica.proxy, this.connection);
}
get deployHeight() {
return this.conf.deployHeight;
}
get home() {
if (!this.connection)
throw new multi_provider_1.NoProviderError(this.context, this.domain);
return core.Home__factory.connect(this.conf.home.proxy, this.connection);
}
get governanceRouter() {
if (!this.connection)
throw new multi_provider_1.NoProviderError(this.context, this.domain);
return core.GovernanceRouter__factory.connect(this.conf.governanceRouter.proxy, this.connection);
}
get xAppConnectionManager() {
if (!this.connection)
throw new multi_provider_1.NoProviderError(this.context, this.domain);
return core.XAppConnectionManager__factory.connect(this.conf.xAppConnectionManager, this.connection);
}
async governor() {
if (this._governor) {
return this._governor;
}
const [domain, identifier] = await Promise.all([
this.governanceRouter.governorDomain(),
this.governanceRouter.governor(),
]);
if (identifier === ethers_1.ethers.constants.AddressZero) {
this._governor = { location: 'remote', domain };
}
else {
this._governor = { location: 'local', identifier };
}
return this._governor;
}
}
exports.CoreContracts = CoreContracts;
//# sourceMappingURL=CoreContracts.js.map