UNPKG

@exromany/lido-csm-sdk

Version:

[![GitHub license](https://img.shields.io/github/license/lidofinance/lido-csm-sdk?color=limegreen)](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [![Version npm](https://img.shields.io/npm/v/@lidofinance/lido-csm-sdk?label=version)](h

180 lines 11.6 kB
"use strict"; var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { var useValue = arguments.length > 2; for (var i = 0; i < initializers.length; i++) { value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); } return useValue ? value : void 0; }; var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); var _, done = false; for (var i = decorators.length - 1; i >= 0; i--) { var context = {}; for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; for (var p in contextIn.access) context.access[p] = contextIn.access[p]; context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); if (kind === "accessor") { if (result === void 0) continue; if (result === null || typeof result !== "object") throw new TypeError("Object expected"); if (_ = accept(result.get)) descriptor.get = _; if (_ = accept(result.set)) descriptor.set = _; if (_ = accept(result.init)) initializers.unshift(_); } else if (_ = accept(result)) { if (kind === "field") initializers.unshift(_); else descriptor[key] = _; } } if (target) Object.defineProperty(target, contextIn.name, descriptor); done = true; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CuratedGateSDK = void 0; const csm_sdk_module_js_1 = require("../common/class-primitives/csm-sdk-module.js"); const index_js_1 = require("../common/decorators/index.js"); const index_js_2 = require("../common/index.js"); const find_address_proof_js_1 = require("../common/utils/find-address-proof.js"); const index_js_3 = require("../common/utils/index.js"); const index_js_4 = require("../tx-sdk/index.js"); const parse_create_operator_props_js_1 = require("./parse-create-operator-props.js"); let CuratedGateSDK = (() => { var _a; let _classSuper = csm_sdk_module_js_1.CsmSDKModule; let _instanceExtraInitializers = []; let _createNodeOperator_decorators; let _getCurveId_decorators; let _getTreeConfig_decorators; let _isConsumed_decorators; let _isPaused_decorators; let _verifyProof_decorators; let _getProofTreeUrls_decorators; let _getProofTree_decorators; let _getProof_decorators; let _getProofAndConsumed_decorators; let _getEligibility_decorators; return _a = class CuratedGateSDK extends _classSuper { constructor(props, gateName, name) { super(props, name); Object.defineProperty(this, "contract", { enumerable: true, configurable: true, writable: true, value: __runInitializers(this, _instanceExtraInitializers) }); this.contract = this.core.getContract(gateName); } async parseOperatorFromReceipt(receipt) { const nodeOperatorId = await (0, index_js_3.parseNodeOperatorAddedEvents)(receipt); return this.bus.operator.getManagementProperties(nodeOperatorId); } async createNodeOperator(props) { const { name, description, managerAddress, rewardAddress, proof, ...rest } = await (0, parse_create_operator_props_js_1.parseCreateOperatorProps)(props); return this.bus.tx.perform({ ...rest, call: () => (0, index_js_4.prepCall)(this.contract, 'createNodeOperator', [ name, description, managerAddress, rewardAddress, proof, ]), decodeResult: (receipt) => this.parseOperatorFromReceipt(receipt), }); } async getCurveId() { return this.contract.read.curveId(); } async getTreeConfig() { const [root, cid] = await Promise.all([ this.contract.read.treeRoot(), this.contract.read.treeCid(), ]).catch(index_js_3.onError); return { root, cid }; } async isConsumed(address) { return this.contract.read.isConsumed([address]); } async isPaused() { return this.contract.read.isPaused(); } async verifyProof(address, proof) { return this.contract.read.verifyProof([address, proof]); } getProofTreeUrls(cid) { return [ ...this.core.getIpfsUrls(cid), this.core.curatedGateTreeLink, ].filter(index_js_3.isDefined); } async getProofTree() { const { root, cid } = await this.getTreeConfig(); if (!root || !cid) return null; const urls = this.getProofTreeUrls(cid); return (0, index_js_3.fetchTree)({ urls, root }); } async getProof(address) { const proofTree = await this.getProofTree(); if (!proofTree) return null; return (0, find_address_proof_js_1.findAddressProof)(proofTree, address); } async getProofAndConsumed(address) { const [proof, isConsumed] = await Promise.all([ this.getProof(address), this.isConsumed(address), ]); return { proof, isConsumed }; } async getEligibility(address) { const [curveId, isPaused, proof, isConsumed] = await Promise.all([ this.getCurveId(), this.isPaused(), this.getProof(address), this.isConsumed(address), ]); const isEligible = !!proof && !isConsumed && !isPaused; return { isPaused, curveId, proof, isConsumed, isEligible, }; } }, (() => { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; _createNodeOperator_decorators = [(0, index_js_1.Logger)('Call:'), (0, index_js_1.ErrorHandler)()]; _getCurveId_decorators = [(0, index_js_1.Logger)('Views:'), (0, index_js_1.ErrorHandler)()]; _getTreeConfig_decorators = [(0, index_js_1.Logger)('Views:'), (0, index_js_1.ErrorHandler)()]; _isConsumed_decorators = [(0, index_js_1.Logger)('Views:'), (0, index_js_1.ErrorHandler)()]; _isPaused_decorators = [(0, index_js_1.Logger)('Views:'), (0, index_js_1.ErrorHandler)()]; _verifyProof_decorators = [(0, index_js_1.Logger)('Views:'), (0, index_js_1.ErrorHandler)()]; _getProofTreeUrls_decorators = [(0, index_js_1.Logger)('Utils:')]; _getProofTree_decorators = [(0, index_js_1.Logger)('API:'), (0, index_js_1.Cache)(index_js_2.CACHE_LONG)]; _getProof_decorators = [(0, index_js_1.Logger)('Utils:')]; _getProofAndConsumed_decorators = [(0, index_js_1.Logger)('Utils:')]; _getEligibility_decorators = [(0, index_js_1.Logger)('Views:')]; __esDecorate(_a, null, _createNodeOperator_decorators, { kind: "method", name: "createNodeOperator", static: false, private: false, access: { has: obj => "createNodeOperator" in obj, get: obj => obj.createNodeOperator }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getCurveId_decorators, { kind: "method", name: "getCurveId", static: false, private: false, access: { has: obj => "getCurveId" in obj, get: obj => obj.getCurveId }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getTreeConfig_decorators, { kind: "method", name: "getTreeConfig", static: false, private: false, access: { has: obj => "getTreeConfig" in obj, get: obj => obj.getTreeConfig }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _isConsumed_decorators, { kind: "method", name: "isConsumed", static: false, private: false, access: { has: obj => "isConsumed" in obj, get: obj => obj.isConsumed }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _isPaused_decorators, { kind: "method", name: "isPaused", static: false, private: false, access: { has: obj => "isPaused" in obj, get: obj => obj.isPaused }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _verifyProof_decorators, { kind: "method", name: "verifyProof", static: false, private: false, access: { has: obj => "verifyProof" in obj, get: obj => obj.verifyProof }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getProofTreeUrls_decorators, { kind: "method", name: "getProofTreeUrls", static: false, private: false, access: { has: obj => "getProofTreeUrls" in obj, get: obj => obj.getProofTreeUrls }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getProofTree_decorators, { kind: "method", name: "getProofTree", static: false, private: false, access: { has: obj => "getProofTree" in obj, get: obj => obj.getProofTree }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getProof_decorators, { kind: "method", name: "getProof", static: false, private: false, access: { has: obj => "getProof" in obj, get: obj => obj.getProof }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getProofAndConsumed_decorators, { kind: "method", name: "getProofAndConsumed", static: false, private: false, access: { has: obj => "getProofAndConsumed" in obj, get: obj => obj.getProofAndConsumed }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getEligibility_decorators, { kind: "method", name: "getEligibility", static: false, private: false, access: { has: obj => "getEligibility" in obj, get: obj => obj.getEligibility }, metadata: _metadata }, null, _instanceExtraInitializers); if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); })(), _a; })(); exports.CuratedGateSDK = CuratedGateSDK; //# sourceMappingURL=curated-gate-sdk.js.map