UNPKG

tokamak-staking-lib

Version:
40 lines (39 loc) 1.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const web3_connector_1 = __importDefault(require("../common/web3-connector")); const Layer2ABI = require("./abi/Layer2.json"); const bn_js_1 = __importDefault(require("bn.js")); const { toBN } = require("web3-utils"); class Layer2 { constructor(address) { const web3 = web3_connector_1.default.instance().web3; this._contract = new web3.eth.Contract(Layer2ABI, address); } async commitDummy(from) { const costNRB = await this._contract.methods.COST_NRB().call(); const NRELength = await this._contract.methods.NRELength().call(); const currentForkNumber = await this._contract.methods.currentFork().call(); const fork = await this._contract.methods.forks(currentForkNumber).call(); const epochNumber = toBN(fork.lastEpoch).add(new bn_js_1.default("1")); const startBlockNumber = toBN(fork.lastBlock).add(new bn_js_1.default("1")); const endBlockNumber = startBlockNumber.add(toBN(NRELength)).sub(new bn_js_1.default("1")); const pos1 = this.makePos(toBN(currentForkNumber), epochNumber); const pos2 = this.makePos(startBlockNumber, endBlockNumber); const dummy = "0xdb431b544b2f5468e3f771d7843d9c5df3b4edcf8bc1c599f18f0b4ea8709bc3"; return this._contract.methods.submitNRE(pos1, pos2, dummy, dummy, dummy).send({ from: from, value: costNRB }); } makePos(x, y) { const temp = x.mul(new bn_js_1.default("2").pow(new bn_js_1.default("128"))); return temp.add(y).toString(); } operator() { return this._contract.methods.operator().call(); } isSubmitter(account) { return this._contract.methods.isSubmitter(account).call(); } } exports.default = Layer2;