dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
47 lines • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoupeConfigAdapter = void 0;
class LoupeConfigAdapter {
static adapt(config) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
if (!config) {
return {};
}
const loupeConfig = (_c = (_b = (_a = config.contracts) === null || _a === void 0 ? void 0 : _a.diamond) === null || _b === void 0 ? void 0 : _b.standards) === null || _c === void 0 ? void 0 : _c.loupe;
if (!loupeConfig) {
return {};
}
return {
functions: {
facets: this.adaptFunction('facets', (_d = loupeConfig.customFunctions) === null || _d === void 0 ? void 0 : _d.facets),
facetSelectors: this.adaptFunction('facetSelectors', (_e = loupeConfig.customFunctions) === null || _e === void 0 ? void 0 : _e.facetSelectors),
facetAddresses: this.adaptFunction('facetAddresses', (_f = loupeConfig.customFunctions) === null || _f === void 0 ? void 0 : _f.facetAddresses),
facetAddress: this.adaptFunction('facetAddress', (_g = loupeConfig.customFunctions) === null || _g === void 0 ? void 0 : _g.facetAddress),
owner: this.adaptFunction('owner', (_h = loupeConfig.customFunctions) === null || _h === void 0 ? void 0 : _h.owner),
version: this.adaptFunction('version', (_j = loupeConfig.customFunctions) === null || _j === void 0 ? void 0 : _j.version)
},
returnTypes: loupeConfig.returnTypes
};
}
static adaptFunction(functionName, config) {
var _a, _b;
if (!config) {
return functionName;
}
if (typeof config === 'string') {
return config;
}
// Convert CoreFacetFunctionConfig to DiamondLoupeFunctionConfig
return {
name: ((_a = config.abi) === null || _a === void 0 ? void 0 : _a.toString()) || functionName,
abi: config.abi,
additionalParams: (_b = config.additionalParams) === null || _b === void 0 ? void 0 : _b.map(param => ({
name: param.name,
type: param.type,
envKey: param.location === 'env' ? param.key : `CONFIG_${param.key}`
}))
};
}
}
exports.LoupeConfigAdapter = LoupeConfigAdapter;
//# sourceMappingURL=loupeConfigAdapter.js.map