UNPKG

fbonds-core

Version:

Banx protocol sdk

56 lines (55 loc) 2.9 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.vote = exports.updateVote = exports.createVote = void 0; const helpers_1 = require("../../helpers"); const helpers_2 = require("./helpers"); const anchor_1 = require("@coral-xyz/anchor"); const createVote = (_a) => __awaiter(void 0, [_a], void 0, function* ({ programId, connection, accounts, sendTxn }) { const previousProposalVariantPubkey = accounts.proposalVariantPubkey; return (0, exports.vote)({ programId, connection, accounts: Object.assign(Object.assign({}, accounts), { previousProposalVariantPubkey }), sendTxn }); }); exports.createVote = createVote; const updateVote = (_a) => __awaiter(void 0, [_a], void 0, function* ({ programId, connection, accounts, sendTxn }) { if (accounts.previousProposalVariantPubkey === accounts.proposalVariantPubkey) throw new Error('No change in variant'); return (0, exports.vote)({ programId, connection, accounts, sendTxn }); }); exports.updateVote = updateVote; const vote = (_a) => __awaiter(void 0, [_a], void 0, function* ({ programId, connection, accounts, sendTxn }) { const program = (0, helpers_1.returnAnchorProgram)(connection); const instructions = []; const previousProposalVariant = accounts.previousProposalVariantPubkey || accounts.proposalVariantPubkey; console.log({ previousProposalVariant }); instructions.push(yield program.methods .vote() .accountsStrict({ adventureSubscriptionSnapshot: accounts.adventureSubscriptionSnapshot, proposal: accounts.proposalPubkey, proposalVariant: accounts.proposalVariantPubkey, user: accounts.userPubkey, previousProposalVariant, vote: yield (0, helpers_2.getVotePubkey)(program, accounts), systemProgram: anchor_1.web3.SystemProgram.programId, rent: anchor_1.web3.SYSVAR_RENT_PUBKEY, }) .instruction()); const transaction = new anchor_1.web3.Transaction(); for (const instruction of instructions) transaction.add(instruction); const signers = []; yield sendTxn(transaction, signers); return { instructions, signers, }; }); exports.vote = vote;