@broxus/js-core
Version:
MobX-based JavaScript Core library
1,157 lines (1,156 loc) • 47.5 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VoteEscrow = void 0;
const js_utils_1 = require("@broxus/js-utils");
const mobx_1 = require("mobx");
const console_1 = require("../../console");
const core_1 = require("../../core");
const tvm_token_wallet_1 = require("../../models/tvm-token-wallet");
const vote_escrow_account_1 = require("../../models/vote-escrow-account");
const abi_1 = require("../../models/vote-escrow/abi");
const VoteEscrowUtils_1 = require("../../models/vote-escrow/VoteEscrowUtils");
const utils_1 = require("../../utils");
class VoteEscrow extends core_1.SmartContractModel {
_connection;
options;
_provider;
static Utils = VoteEscrowUtils_1.VoteEscrowUtils;
/**
* @param {ProviderRpcClient} _connection
* Standalone RPC client that doesn't require connection to the TVM wallet provider
* @param {Address | string} address
* VoteEscrow root address
* @param {Readonly<VoteEscrowCtorOptions>} [options]
* (optional) VoteEscrow Smart Contract Model options
* @param {ProviderRpcClient} [_provider]
* (optional) RPC provider that require connection to the TVM wallet
*/
constructor(_connection, address, options, _provider) {
super(_connection, address);
this._connection = _connection;
this.options = options;
this._provider = _provider;
this.setData(() => ({
currentVotingVotes: [],
distribution: [],
distributionSchedule: [],
distributionScheme: [],
gaugeDaoApproved: [],
gaugeWhitelist: [],
normalizedVotes: [],
votes: [],
}));
(0, mobx_1.makeObservable)(this);
}
/**
* @param {ProviderRpcClient} connection
* Standalone RPC client that doesn't require connection to the TVM wallet provider
* @param {Address | string} address
* VoteEscrow root address
* @param {Readonly<VoteEscrowCreateOptions>} [options]
* (optional) VoteEscrow Smart Contract Model options
* @param {ProviderRpcClient} [provider]
* (optional) RPC provider that require connection to the TVM wallet
*/
static async create(connection, address, options, provider) {
const { sync = true, watch, watchCallback, ...restOptions } = { ...options };
const voteEscrow = new VoteEscrow(connection, address, restOptions, provider);
if (sync) {
await voteEscrow.sync({ force: false });
}
if (watch) {
await voteEscrow.watch(watchCallback);
}
return voteEscrow;
}
async sync(options) {
if (!options?.force && this.isSyncing) {
return;
}
try {
this.setState('isSyncing', !options?.silent);
const state = await this.syncContractState({ force: options?.force || !this.contractState });
if (!this.isDeployed) {
(0, js_utils_1.throwException)('VoteEscrow is not deployed');
}
const [details, calculateAverage, currentEpochDetails, currentVotingVotes, normalizedVoting, votingDetails, distributionSchedule, distributionScheme, gaugeDaoApproved, gaugeWhitelist,] = await Promise.all([
VoteEscrow.Utils.getDetails(this._connection, this.address, state),
VoteEscrow.Utils.calculateAverage(this._connection, this.address, state),
VoteEscrow.Utils.getCurrentEpochDetails(this._connection, this.address, state),
VoteEscrow.Utils.currentVotingVotes(this._connection, this.address, state),
VoteEscrow.Utils.getNormalizedVoting(this._connection, this.address, state),
VoteEscrow.Utils.getVotingDetails(this._connection, this.address, state),
VoteEscrow.Utils.distributionSchedule(this._connection, this.address, state),
VoteEscrow.Utils.distributionScheme(this._connection, this.address, state),
VoteEscrow.Utils.gaugeDaoApproved(this._connection, this.address, state),
VoteEscrow.Utils.gaugeWhitelist(this._connection, this.address, state),
]);
this.setData({
...details,
...calculateAverage,
...currentEpochDetails,
...currentVotingVotes,
...normalizedVoting,
...votingDetails,
distributionSchedule,
distributionScheme,
gaugeDaoApproved,
gaugeWhitelist,
});
}
catch (e) {
if (process.env.NODE_ENV !== 'production') {
const state = await this._connection.getProviderState();
(0, utils_1.syncErrorMessage)(this.constructor.name, this.address, e, state.networkId.toString());
}
}
finally {
this.setState('isSyncing', false);
}
}
async watch(callback) {
try {
this.contractSubscriber = new this._connection.Subscriber();
await this.contractSubscriber.states(this.address).delayed(stream => {
if (process.env.NODE_ENV !== 'production') {
(0, utils_1.subscribeDebugMessage)(this.constructor.name, this.address);
}
return stream.on((0, js_utils_1.debounce)(async (event) => {
if (process.env.NODE_ENV !== 'production') {
const state = await this._connection.getProviderState();
(0, utils_1.contractStateChangeDebugMessage)(this.constructor.name, this.address, event, state.networkId.toString());
}
if ((0, utils_1.areAddressesEqual)(event.address, this.address)) {
await this.sync({ force: !this.isSyncing, silent: true });
callback?.(...this.toJSON(true));
return;
}
await this.unwatch();
}, this.options?.watchDebounceDelay ?? 3000));
});
return this.contractSubscriber;
}
catch (e) {
await this.unwatch();
throw e;
}
}
async unwatch() {
if (this.contractSubscriber === undefined) {
return;
}
try {
await this.contractSubscriber?.unsubscribe();
this.contractSubscriber = undefined;
if (process.env.NODE_ENV !== 'production') {
(0, utils_1.unsubscribeDebugMessage)(this.constructor.name, this.address);
}
}
catch (e) {
if (process.env.NODE_ENV !== 'production') {
const state = await this._connection.getProviderState();
(0, utils_1.unsubscribeErrorMessage)(this.constructor.name, this.address, e, state.networkId.toString());
}
}
}
async deposit(params, args) {
if (!this._provider) {
throw new utils_1.ProviderNotDefinedError(this.constructor.name);
}
const callId = params.callId ?? (0, utils_1.getRandomInt)();
const subscriber = new this._connection.Subscriber();
let transaction;
try {
const tokenWallet = new tvm_token_wallet_1.TvmTokenWallet(this._connection, params.tokenWalletAddress, undefined, this._provider);
const message = await tokenWallet.transfer({
amount: params.amount,
deployWalletValue: params.deployWalletValue,
notify: params.notify,
payload: params.payload,
recipient: params.recipient ?? this.address,
remainingGasTo: params.remainingGasTo ?? params.depositOwner,
}, args);
await params.onSend?.(message, { callId });
transaction = await message.transaction;
await params.onTransactionSent?.({ callId, transaction });
const stream = await subscriber
.trace(transaction)
.filterMap(async (tx) => {
if (!(0, utils_1.areAddressesEqual)(tx.account, this.address)) {
return undefined;
}
const events = await this.decodeTransactionEvents(tx);
if (events.length === 0) {
return undefined;
}
const revertEvent = events.find(e => e.event === 'DepositRevert');
if (revertEvent) {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cDepositRevert%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, revertEvent);
}
await params.onTransactionFailure?.({
callId,
error: new Error(revertEvent.event.toString()),
transaction: tx,
});
return revertEvent;
}
const event = events.find(e => e.event === 'Deposit');
if (!event) {
return undefined;
}
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cDeposit%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, event);
}
await params.onTransactionSuccess?.({
callId,
input: {
amount: event.data.amount,
key: event.data.key,
lockTime: parseInt(event.data.lock_time, 10),
user: event.data.user,
veAmount: event.data.ve_amount,
},
transaction: tx,
});
return event;
})
.delayed(s => s.first());
await stream();
return transaction;
}
catch (e) {
params.onTransactionFailure?.({
callId,
error: e,
transaction,
});
throw e;
}
finally {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c Unsubscribed from the Deposit tokens stream`, console_1.warningLabelStyle, console_1.inheritTextStyle);
}
await subscriber?.unsubscribe();
}
}
async withdraw(params, args) {
if (!this._provider) {
throw new utils_1.ProviderNotDefinedError(this.constructor.name);
}
const callId = params.callId ?? (0, utils_1.getRandomInt)();
const subscriber = new this._connection.Subscriber();
let transaction;
try {
const message = await VoteEscrow.Utils.withdraw(this._provider, this.address, {
meta: params.meta,
}, args);
await params.onSend?.(message, { callId });
transaction = await message.transaction;
await params.onTransactionSent?.({ callId, transaction });
const stream = await subscriber
.trace(transaction)
.filterMap(async (tx) => {
if (!(0, utils_1.areAddressesEqual)(tx.account, this.address)) {
return undefined;
}
const events = await this.decodeTransactionEvents(tx);
if (events.length === 0) {
return undefined;
}
const revertEvent = events.find(e => e.event === 'WithdrawRevert');
if (revertEvent) {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cWithdrawRevert%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, revertEvent);
}
await params.onTransactionFailure?.({
callId,
error: new Error(revertEvent.event.toString()),
transaction: tx,
});
return revertEvent;
}
const event = events.find(e => e.event === 'Withdraw');
if (!event) {
return undefined;
}
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cWithdraw%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, event);
}
await params.onTransactionSuccess?.({
callId,
input: {
amount: event.data.amount,
user: event.data.user,
},
transaction: tx,
});
return event;
})
.delayed(s => s.first());
await stream();
return transaction;
}
catch (e) {
params.onTransactionFailure?.({
callId,
error: e,
transaction,
});
throw e;
}
finally {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c Unsubscribed from the Withdraw tokens stream`, console_1.warningLabelStyle, console_1.inheritTextStyle);
}
await subscriber?.unsubscribe();
}
}
async voteEpoch(params, args) {
if (!this._provider) {
throw new utils_1.ProviderNotDefinedError(this.constructor.name);
}
const callId = params.callId ?? (0, utils_1.getRandomInt)();
const subscriber = new this._connection.Subscriber();
let transaction;
try {
const message = await VoteEscrow.Utils.voteEpoch(this._provider, this.address, {
meta: params.meta,
votes: params.votes,
}, args);
await params.onSend?.(message, { callId });
transaction = await message.transaction;
await params.onTransactionSent?.({ callId, transaction });
const stream = await subscriber
.trace(transaction)
.filterMap(async (tx) => {
if (!(0, utils_1.areAddressesEqual)(tx.account, this.address)) {
return undefined;
}
const events = await this.decodeTransactionEvents(tx);
if (events.length === 0) {
return undefined;
}
const reverEvent = events.find(e => e.event === 'VoteRevert');
if (reverEvent) {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cVoteRevert%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, reverEvent);
}
await params.onTransactionFailure?.({
callId,
error: new Error(reverEvent.event.toString()),
transaction: tx,
});
return reverEvent;
}
const event = events.find(e => e.event === 'Vote');
if (!event) {
return undefined;
}
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cVote%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, event);
}
await params.onTransactionSuccess?.({
callId,
input: {
user: event.data.user,
votes: event.data.votes,
},
transaction: tx,
});
return event;
})
.delayed(s => s.first());
await stream();
return transaction;
}
catch (e) {
params.onTransactionFailure?.({
callId,
error: e,
transaction,
});
throw e;
}
finally {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c Unsubscribed from the Vote Epoch stream`, console_1.warningLabelStyle, console_1.inheritTextStyle);
}
await subscriber?.unsubscribe();
}
}
async endVoting(params, args) {
if (!this._provider) {
throw new utils_1.ProviderNotDefinedError(this.constructor.name);
}
const callId = params.callId ?? (0, utils_1.getRandomInt)();
const subscriber = new this._connection.Subscriber();
let transaction;
try {
const message = await VoteEscrow.Utils.endVoting(this._provider, this.address, { meta: params.meta }, args);
await params.onSend?.(message, { callId });
transaction = await message.transaction;
await params.onTransactionSent?.({ callId, transaction });
const stream = await subscriber
.trace(transaction)
.filterMap(async (tx) => {
if (!(0, utils_1.areAddressesEqual)(tx.account, this.address)) {
return undefined;
}
const events = await this.decodeTransactionEvents(tx);
if (events.length === 0) {
return undefined;
}
const revertEvent = events.find(e => e.event === 'VotingEndRevert');
if (revertEvent) {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cVotingEndRevert%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, revertEvent);
}
await params.onTransactionFailure?.({
callId,
error: new Error(revertEvent.event.toString()),
transaction: tx,
});
return revertEvent;
}
const event = events.find(e => e.event === 'VotingEnd');
if (!event) {
return undefined;
}
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cVotingEnd%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, event);
}
await params.onTransactionSuccess?.({
callId,
input: {
newEpoch: parseInt(event.data.new_epoch, 10),
newEpochEnd: parseInt(event.data.new_epoch_end, 10),
newEpochStart: parseInt(event.data.new_epoch_start, 10),
totalVotes: event.data.total_votes,
treasuryVotes: event.data.treasury_votes,
votes: event.data.votes,
},
transaction: tx,
});
return event;
})
.delayed(s => s.first());
await stream();
return transaction;
}
catch (e) {
params.onTransactionFailure?.({
callId,
error: e,
transaction,
});
throw e;
}
finally {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c Unsubscribed from the End Voting stream`, console_1.warningLabelStyle, console_1.inheritTextStyle);
}
await subscriber?.unsubscribe();
}
}
async tryUnlockCastedVotes(params, args) {
if (!this._provider) {
throw new utils_1.ProviderNotDefinedError(this.constructor.name);
}
const callId = params.callId ?? (0, utils_1.getRandomInt)();
const subscriber = new this._connection.Subscriber();
let transaction;
try {
let { voteEscrowAccount } = params;
if (!voteEscrowAccount) {
if (!params.ownerAddress) {
(0, js_utils_1.throwException)('Either voteEscrowAccount or ownerAddress must be defined');
}
voteEscrowAccount = await this.getVoteEscrowAccountAddress(params.ownerAddress);
}
const message = await VoteEscrow.Utils.tryUnlockCastedVotes(this._provider, this.address, { proposalIds: params.proposalIds }, args);
await params.onSend?.(message, { callId });
transaction = await message.transaction;
await params.onTransactionSent?.({ callId, transaction });
const stream = await subscriber
.trace(transaction)
.filterMap(async (tx) => {
if (!(0, utils_1.areAddressesEqual)(tx.account, voteEscrowAccount)) {
return undefined;
}
const events = await vote_escrow_account_1.VoteEscrowAccount.Utils.decodeTransactionEvents(this._connection, voteEscrowAccount, tx);
if (events.length === 0) {
return undefined;
}
const event = events.find(e => e.event === 'UnlockCastedVotes');
if (!event) {
return undefined;
}
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cUnlockCastedVotes%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, event);
}
await params.onTransactionSuccess?.({
callId,
input: event.data,
transaction: tx,
});
return event;
})
.delayed(s => s.first());
await stream();
return transaction;
}
catch (e) {
params.onTransactionFailure?.({
callId,
error: e,
transaction,
});
throw e;
}
finally {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c Unsubscribe from VoteEscrow unlock casted votes stream`, console_1.warningLabelStyle, console_1.inheritTextStyle);
}
await subscriber?.unsubscribe();
}
}
async tryUnlockVoteTokens(params, args) {
if (!this._provider) {
throw new utils_1.ProviderNotDefinedError(this.constructor.name);
}
const callId = params.callId ?? (0, utils_1.getRandomInt)();
const subscriber = new this._connection.Subscriber();
let transaction;
try {
let { voteEscrowAccount } = params;
if (!voteEscrowAccount) {
if (!params.ownerAddress) {
(0, js_utils_1.throwException)('Either voteEscrowAccount or ownerAddress must be defined');
}
voteEscrowAccount = await this.getVoteEscrowAccountAddress(params.ownerAddress);
}
const message = await VoteEscrow.Utils.tryUnlockVoteTokens(this._provider, this.address, { proposalId: params.proposalId }, args);
await params.onSend?.(message, { callId });
transaction = await message.transaction;
await params.onTransactionSent?.({ callId, transaction });
const stream = await subscriber
.trace(transaction)
.filterMap(async (tx) => {
if (!(0, utils_1.areAddressesEqual)(tx.account, voteEscrowAccount)) {
return undefined;
}
const events = await vote_escrow_account_1.VoteEscrowAccount.Utils.decodeTransactionEvents(this._connection, voteEscrowAccount, tx);
if (events.length === 0) {
return undefined;
}
const event = events.find(e => e.event === 'UnlockVotes');
if (!event) {
return undefined;
}
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cUnlockVotes%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, event);
}
await params.onTransactionSuccess?.({
callId,
input: event.data,
transaction: tx,
});
return event;
})
.delayed(s => s.first());
await stream();
return transaction;
}
catch (e) {
params.onTransactionFailure?.({
callId,
error: e,
transaction,
});
throw e;
}
finally {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c Unsubscribe from VoteEscrow unlock vote tokens stream`, console_1.warningLabelStyle, console_1.inheritTextStyle);
}
await subscriber?.unsubscribe();
}
}
async castVote(params, args) {
if (!this._provider) {
throw new utils_1.ProviderNotDefinedError(this.constructor.name);
}
const callId = params.callId ?? (0, utils_1.getRandomInt)();
const subscriber = new this._connection.Subscriber();
let transaction;
try {
let { voteEscrowAccount } = params;
if (!voteEscrowAccount) {
if (!params.ownerAddress) {
(0, js_utils_1.throwException)('Either voteEscrowAccount or ownerAddress must be defined');
}
voteEscrowAccount = await this.getVoteEscrowAccountAddress(params.ownerAddress);
}
const message = await VoteEscrow.Utils.castVote(this._provider, this.address, { proposalId: params.proposalId, support: params.support }, { from: (0, utils_1.resolveTvmAddress)(voteEscrowAccount), ...args });
await params.onSend?.(message, { callId });
transaction = await message.transaction;
await params.onTransactionSent?.({ callId, transaction });
const stream = await subscriber
.trace(transaction)
.filterMap(async (tx) => {
if (!(0, utils_1.areAddressesEqual)(tx.account, voteEscrowAccount)) {
return undefined;
}
const events = await vote_escrow_account_1.VoteEscrowAccount.Utils.decodeTransactionEvents(this._connection, voteEscrowAccount, tx);
if (events.length === 0) {
return undefined;
}
const event = events.find(e => e.event === 'VoteCast');
if (!event) {
return undefined;
}
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cVoteCast%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, event);
}
await params.onTransactionSuccess?.({
callId,
input: event.data,
transaction: tx,
});
return event;
})
.delayed(s => s.first());
await stream();
return transaction;
}
catch (e) {
params.onTransactionFailure?.({
callId,
error: e,
transaction,
});
throw e;
}
finally {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c Unsubscribe from VoteEscrow cast vote stream`, console_1.warningLabelStyle, console_1.inheritTextStyle);
}
await subscriber?.unsubscribe();
}
}
async castVoteWithReason(params, args) {
if (!this._provider) {
throw new utils_1.ProviderNotDefinedError(this.constructor.name);
}
const callId = params.callId ?? (0, utils_1.getRandomInt)();
const subscriber = new this._connection.Subscriber();
let transaction;
try {
let { voteEscrowAccount } = params;
if (!voteEscrowAccount) {
if (!params.ownerAddress) {
(0, js_utils_1.throwException)('Either voteEscrowAccount or ownerAddress must be defined');
}
voteEscrowAccount = await this.getVoteEscrowAccountAddress(params.ownerAddress);
}
const message = await VoteEscrow.Utils.castVoteWithReason(this._provider, this.address, {
proposalId: params.proposalId,
reason: params.reason,
support: params.support,
}, { from: (0, utils_1.resolveTvmAddress)(voteEscrowAccount), ...args });
await params.onSend?.(message, { callId });
transaction = await message.transaction;
await params.onTransactionSent?.({ callId, transaction });
const stream = await subscriber
.trace(transaction)
.filterMap(async (tx) => {
if (!(0, utils_1.areAddressesEqual)(tx.account, voteEscrowAccount)) {
return undefined;
}
const events = await vote_escrow_account_1.VoteEscrowAccount.Utils.decodeTransactionEvents(this._connection, voteEscrowAccount, tx);
if (events.length === 0) {
return undefined;
}
const event = events.find(e => e.event === 'VoteCast');
if (!event) {
return undefined;
}
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c %cVoteCast%c event was captured`, console_1.successLabelStyle, console_1.inheritTextStyle, console_1.successTextStyle, console_1.inheritTextStyle, event);
}
await params.onTransactionSuccess?.({
callId,
input: event.data,
transaction: tx,
});
return event;
})
.delayed(s => s.first());
await stream();
return transaction;
}
catch (e) {
params.onTransactionFailure?.({
callId,
error: e,
transaction,
});
throw e;
}
finally {
if (process.env.NODE_ENV !== 'production') {
(0, js_utils_1.debug)(`%c${this.constructor.name}%c Unsubscribe from VoteEscrow cast vote stream`, console_1.warningLabelStyle, console_1.inheritTextStyle);
}
await subscriber?.unsubscribe();
}
}
getVoteEscrowAccountAddress(ownerAddress) {
return VoteEscrow.Utils.getVoteEscrowAccountAddress(this._connection, this.address, ownerAddress, this.contractState);
}
calculateVeMint(params) {
return VoteEscrow.Utils.calculateVeMint(this._connection, this.address, params, this.contractState);
}
calculateGasForEndVoting() {
return VoteEscrow.Utils.calculateGasForEndVoting(this._connection, this.address, this.contractState);
}
get currentEpoch() {
return this._data.currentEpoch;
}
get currentEpochEndTime() {
return this._data.currentEpochEndTime;
}
get currentEpochStartTime() {
return this._data.currentEpochStartTime;
}
get currentVotingEndTime() {
return this._data.currentVotingEndTime;
}
get currentVotingStartTime() {
return this._data.currentVotingStartTime;
}
get currentVotingVotes() {
return this._data.currentVotingVotes;
}
get dao() {
return this._data.dao;
}
get distribution() {
return this._data.distribution;
}
get distributionSchedule() {
return this._data.distributionSchedule;
}
get distributionScheme() {
return this._data.distributionScheme;
}
get distributionSupply() {
return this._data.distributionSupply;
}
get emergency() {
return this._data.emergency;
}
get emissionDebt() {
return this._data.emissionDebt;
}
get epochTime() {
return this._data.epochTime;
}
get gaugeMaxVotesRatio() {
return this._data.gaugeMaxVotesRatio;
}
get gaugeMinVotesRatio() {
return this._data.gaugeMinVotesRatio;
}
get gaugeDaoApproved() {
return this._data.gaugeDaoApproved;
}
get gaugeWhitelist() {
return this._data.gaugeWhitelist;
}
get gaugeWhitelistPrice() {
return this._data.gaugeWhitelistPrice;
}
get maxGaugesPerVote() {
return this._data.maxGaugesPerVote;
}
get initialized() {
return this._data.initialized;
}
get lastUpdateTime() {
return this._data.lastUpdateTime;
}
get manager() {
return this._data.manager;
}
get normalizedVotes() {
return this._data.normalizedVotes;
}
get owner() {
return this._data.owner;
}
get paused() {
return this._data.paused;
}
get qube() {
return this._data.qube;
}
get qubeBalance() {
return this._data.qubeBalance;
}
get qubeMaxLockTime() {
return this._data.qubeMaxLockTime;
}
get qubeMinLockTime() {
return this._data.qubeMinLockTime;
}
get qubeWallet() {
return this._data.qubeWallet;
}
get teamTokens() {
return this._data.teamTokens;
}
get timeBeforeVoting() {
return this._data.timeBeforeVoting;
}
get treasuryTokens() {
return this._data.treasuryTokens;
}
get veQubeAverage() {
return this._data.veQubeAverage;
}
get veQubeAveragePeriod() {
return this._data.veQubeAveragePeriod;
}
get veQubeBalance() {
return this._data.veQubeBalance;
}
get whitelistPayments() {
return this._data.whitelistPayments;
}
decodeMethodInput(payload, method) {
return this._connection.rawApi.decodeInput({
abi: JSON.stringify(abi_1.VoteEscrowAbi),
body: payload,
internal: true,
method,
});
}
decodeTransactionEvents(transaction) {
return VoteEscrow.Utils.decodeTransactionEvents(this._connection, this.address, transaction);
}
encodeDepositPayload(params) {
return VoteEscrow.Utils.encodeDepositPayload(this._connection, this.address, params);
}
encodeWhitelistPayload(params) {
return VoteEscrow.Utils.encodeWhitelistPayload(this._connection, this.address, params);
}
}
exports.VoteEscrow = VoteEscrow;
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "sync", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Function]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "watch", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "unwatch", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "deposit", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "withdraw", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "voteEpoch", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "endVoting", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "tryUnlockCastedVotes", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "tryUnlockVoteTokens", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "castVote", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "castVoteWithReason", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "getVoteEscrowAccountAddress", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "calculateVeMint", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "calculateGasForEndVoting", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "currentEpoch", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "currentEpochEndTime", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "currentEpochStartTime", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "currentVotingEndTime", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "currentVotingStartTime", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "currentVotingVotes", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "dao", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "distribution", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "distributionSchedule", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "distributionScheme", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "distributionSupply", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "emergency", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "emissionDebt", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "epochTime", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "gaugeMaxVotesRatio", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "gaugeMinVotesRatio", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "gaugeDaoApproved", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "gaugeWhitelist", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "gaugeWhitelistPrice", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "maxGaugesPerVote", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "initialized", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "lastUpdateTime", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "manager", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "normalizedVotes", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "owner", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "paused", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "qube", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "qubeBalance", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "qubeMaxLockTime", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "qubeMinLockTime", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "qubeWallet", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "teamTokens", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "timeBeforeVoting", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "treasuryTokens", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "veQubeAverage", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "veQubeAveragePeriod", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "veQubeBalance", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], VoteEscrow.prototype, "whitelistPayments", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "decodeMethodInput", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "decodeTransactionEvents", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "encodeDepositPayload", null);
__decorate([
mobx_1.action.bound,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], VoteEscrow.prototype, "encodeWhitelistPayload", null);