UNPKG

@saberhq/snapshots

Version:

The TypeScript SDK for the Saber Voting Escrow Snapshot system.

100 lines 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SnapshotsWrapper = void 0; const tslib_1 = require("tslib"); const web3_js_1 = require("@solana/web3.js"); const tribeca_sdk_1 = require("@tribecahq/tribeca-sdk"); const _1 = require("."); /** * Handles interacting with the Snapshots program. */ class SnapshotsWrapper { /** * Constructor for a {@link SnapshotsWrapper}. * @param sdk */ constructor(sdk) { this.sdk = sdk; this.program = sdk.programs.Snapshots; } get provider() { return this.sdk.provider; } fetchLockerHistory(key) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield this.program.account.lockerHistory.fetchNullable(key); }); } fetchEscrowHistory(key) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield this.program.account.escrowHistory.fetchNullable(key); }); } /** * Creates a Locker History. * @returns */ createLockerHistory({ locker, era, }) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const [lockerHistory] = yield (0, _1.findLockerHistoryAddress)(locker, era); return { lockerHistory, tx: this.provider.newTX([ this.program.instruction.createLockerHistory(era, { accounts: { locker, lockerHistory, payer: this.provider.wallet.publicKey, systemProgram: web3_js_1.SystemProgram.programId, }, }), ]), }; }); } /** * Creates an Escrow History. * @returns */ createEscrowHistory({ escrow, era, }) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const [escrowHistory] = yield (0, _1.findEscrowHistoryAddress)(escrow, era); return { escrowHistory, tx: this.provider.newTX([ this.program.instruction.createEscrowHistory(era, { accounts: { escrow, escrowHistory, payer: this.provider.wallet.publicKey, systemProgram: web3_js_1.SystemProgram.programId, }, }), ]), }; }); } /** * Synchronizes an EscrowHistory. * @returns */ sync({ locker, owner, era, }) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const [lockerHistory] = yield (0, _1.findLockerHistoryAddress)(locker, era); const [escrow] = yield (0, tribeca_sdk_1.findEscrowAddress)(locker, owner); const [escrowHistory] = yield (0, _1.findEscrowHistoryAddress)(escrow, era); return this.provider.newTX([ this.program.instruction.sync({ accounts: { locker, escrow, lockerHistory, escrowHistory, }, }), ]); }); } } exports.SnapshotsWrapper = SnapshotsWrapper; //# sourceMappingURL=snapshots.js.map