@terminusbet/stake-vote-sdk
Version:
A simple SDK for interacting with terminusbet governance
93 lines • 4.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserVoteState = exports.UserStakeVoteState = void 0;
const borsh_1 = require("@coral-xyz/borsh");
const web3_js_1 = require("@solana/web3.js");
const u128 = (property) => (0, borsh_1.struct)([(0, borsh_1.u64)("low"), (0, borsh_1.u64)("high")], property);
const toBigInt = ({ low, high }) => (BigInt(high.toString()) << 64n) + BigInt(low.toString());
class UserStakeVoteState {
discriminator;
stakePoolState;
owner;
timeStartAt;
timeEndAt;
timeStakeRelease;
periodUsed;
periodTotal;
stakeAllTotal; // u128
stakeTotal;
stakeReleaseNotRecived; // u128
stakeReleaseRecived; // u128
stakeReleasePerTime; // u128
votePerTime; // u128
voteUsed;
voteTotal;
decimal;
constructor(discriminator, stakePoolState, owner, timeStartAt, timeEndAt, timeStakeRelease, periodUsed, periodTotal, stakeAllTotal, stakeTotal, stakeReleaseNotRecived, stakeReleaseRecived, stakeReleasePerTime, votePerTime, voteUsed, voteTotal, decimal) {
this.discriminator = discriminator;
this.stakePoolState = stakePoolState;
this.owner = owner;
this.timeStartAt = timeStartAt;
this.timeEndAt = timeEndAt;
this.timeStakeRelease = timeStakeRelease;
this.periodUsed = periodUsed;
this.periodTotal = periodTotal;
this.stakeAllTotal = stakeAllTotal;
this.stakeTotal = stakeTotal;
this.stakeReleaseNotRecived = stakeReleaseNotRecived;
this.stakeReleaseRecived = stakeReleaseRecived;
this.stakeReleasePerTime = stakeReleasePerTime;
this.votePerTime = votePerTime;
this.voteUsed = voteUsed;
this.voteTotal = voteTotal;
this.decimal = decimal;
}
static fromBuffer(buffer) {
const structure = (0, borsh_1.struct)([
(0, borsh_1.u64)("discriminator"),
(0, borsh_1.publicKey)("stakePoolState"),
(0, borsh_1.publicKey)("owner"),
(0, borsh_1.u64)("timeStartAt"),
(0, borsh_1.u64)("timeEndAt"),
(0, borsh_1.u64)("timeStakeRelease"),
(0, borsh_1.u64)("periodUsed"),
(0, borsh_1.u64)("periodTotal"),
u128("stakeAllTotal"),
(0, borsh_1.u64)("stakeTotal"),
u128("stakeReleaseNotRecived"),
u128("stakeReleaseRecived"),
u128("stakeReleasePerTime"),
u128("votePerTime"),
(0, borsh_1.u64)("voteUsed"),
(0, borsh_1.u64)("voteTotal"),
(0, borsh_1.u8)("decimal")
]);
let value = structure.decode(buffer);
return new UserStakeVoteState(BigInt(value.discriminator), new web3_js_1.PublicKey(value.stakePoolState), new web3_js_1.PublicKey(value.owner), BigInt(value.timeStartAt), BigInt(value.timeEndAt), BigInt(value.timeStakeRelease), BigInt(value.periodUsed), BigInt(value.periodTotal), toBigInt(value.stakeAllTotal), BigInt(value.stakeTotal), toBigInt(value.stakeReleaseNotRecived), toBigInt(value.stakeReleaseRecived), toBigInt(value.stakeReleasePerTime), toBigInt(value.votePerTime), BigInt(value.voteUsed), BigInt(value.voteTotal), BigInt(value.decimal));
}
}
exports.UserStakeVoteState = UserStakeVoteState;
class UserVoteState {
discriminator;
ballotBot;
owner;
voteCount;
constructor(discriminator, ballotBot, owner, voteCount) {
this.discriminator = discriminator;
this.ballotBot = ballotBot;
this.owner = owner;
this.voteCount = voteCount;
}
static fromBuffer(buffer) {
const structure = (0, borsh_1.struct)([
(0, borsh_1.u64)("discriminator"),
(0, borsh_1.publicKey)("ballotBot"),
(0, borsh_1.publicKey)("owner"),
(0, borsh_1.u64)("voteCount")
]);
let value = structure.decode(buffer);
return new UserVoteState(BigInt(value.discriminator), new web3_js_1.PublicKey(value.ballotBot), new web3_js_1.PublicKey(value.owner), BigInt(value.voteCount));
}
}
exports.UserVoteState = UserVoteState;
//# sourceMappingURL=userStakeVoteState.js.map