@hubbleprotocol/farms-sdk
Version:
272 lines • 14.2 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FarmState = void 0;
const web3_js_1 = require("@solana/web3.js");
const bn_js_1 = __importDefault(require("bn.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
const types = __importStar(require("../types")); // eslint-disable-line @typescript-eslint/no-unused-vars
const programId_1 = require("../programId");
class FarmState {
constructor(fields) {
this.farmAdmin = fields.farmAdmin;
this.globalConfig = fields.globalConfig;
this.token = new types.TokenInfo(Object.assign({}, fields.token));
this.rewardInfos = fields.rewardInfos.map((item) => new types.RewardInfo(Object.assign({}, item)));
this.numRewardTokens = fields.numRewardTokens;
this.numUsers = fields.numUsers;
this.totalStakedAmount = fields.totalStakedAmount;
this.farmVault = fields.farmVault;
this.farmVaultsAuthority = fields.farmVaultsAuthority;
this.farmVaultsAuthorityBump = fields.farmVaultsAuthorityBump;
this.delegateAuthority = fields.delegateAuthority;
this.timeUnit = fields.timeUnit;
this.isFarmFrozen = fields.isFarmFrozen;
this.isFarmDelegated = fields.isFarmDelegated;
this.padding0 = fields.padding0;
this.withdrawAuthority = fields.withdrawAuthority;
this.depositWarmupPeriod = fields.depositWarmupPeriod;
this.withdrawalCooldownPeriod = fields.withdrawalCooldownPeriod;
this.totalActiveStakeScaled = fields.totalActiveStakeScaled;
this.totalPendingStakeScaled = fields.totalPendingStakeScaled;
this.totalPendingAmount = fields.totalPendingAmount;
this.slashedAmountCurrent = fields.slashedAmountCurrent;
this.slashedAmountCumulative = fields.slashedAmountCumulative;
this.slashedAmountSpillAddress = fields.slashedAmountSpillAddress;
this.lockingMode = fields.lockingMode;
this.lockingStartTimestamp = fields.lockingStartTimestamp;
this.lockingDuration = fields.lockingDuration;
this.lockingEarlyWithdrawalPenaltyBps =
fields.lockingEarlyWithdrawalPenaltyBps;
this.depositCapAmount = fields.depositCapAmount;
this.scopePrices = fields.scopePrices;
this.scopeOraclePriceId = fields.scopeOraclePriceId;
this.scopeOracleMaxAge = fields.scopeOracleMaxAge;
this.pendingFarmAdmin = fields.pendingFarmAdmin;
this.strategyId = fields.strategyId;
this.padding = fields.padding;
}
static fetch(c_1, address_1) {
return __awaiter(this, arguments, void 0, function* (c, address, programId = programId_1.PROGRAM_ID) {
const info = yield c.getAccountInfo(address);
if (info === null) {
return null;
}
if (!info.owner.equals(programId)) {
throw new Error("account doesn't belong to this program");
}
return this.decode(info.data);
});
}
static fetchMultiple(c_1, addresses_1) {
return __awaiter(this, arguments, void 0, function* (c, addresses, programId = programId_1.PROGRAM_ID) {
const infos = yield c.getMultipleAccountsInfo(addresses);
return infos.map((info) => {
if (info === null) {
return null;
}
if (!info.owner.equals(programId)) {
throw new Error("account doesn't belong to this program");
}
return this.decode(info.data);
});
});
}
static decode(data) {
if (!data.slice(0, 8).equals(FarmState.discriminator)) {
throw new Error("invalid account discriminator");
}
const dec = FarmState.layout.decode(data.slice(8));
return new FarmState({
farmAdmin: dec.farmAdmin,
globalConfig: dec.globalConfig,
token: types.TokenInfo.fromDecoded(dec.token),
rewardInfos: dec.rewardInfos.map((item /* eslint-disable-line @typescript-eslint/no-explicit-any */) => types.RewardInfo.fromDecoded(item)),
numRewardTokens: dec.numRewardTokens,
numUsers: dec.numUsers,
totalStakedAmount: dec.totalStakedAmount,
farmVault: dec.farmVault,
farmVaultsAuthority: dec.farmVaultsAuthority,
farmVaultsAuthorityBump: dec.farmVaultsAuthorityBump,
delegateAuthority: dec.delegateAuthority,
timeUnit: dec.timeUnit,
isFarmFrozen: dec.isFarmFrozen,
isFarmDelegated: dec.isFarmDelegated,
padding0: dec.padding0,
withdrawAuthority: dec.withdrawAuthority,
depositWarmupPeriod: dec.depositWarmupPeriod,
withdrawalCooldownPeriod: dec.withdrawalCooldownPeriod,
totalActiveStakeScaled: dec.totalActiveStakeScaled,
totalPendingStakeScaled: dec.totalPendingStakeScaled,
totalPendingAmount: dec.totalPendingAmount,
slashedAmountCurrent: dec.slashedAmountCurrent,
slashedAmountCumulative: dec.slashedAmountCumulative,
slashedAmountSpillAddress: dec.slashedAmountSpillAddress,
lockingMode: dec.lockingMode,
lockingStartTimestamp: dec.lockingStartTimestamp,
lockingDuration: dec.lockingDuration,
lockingEarlyWithdrawalPenaltyBps: dec.lockingEarlyWithdrawalPenaltyBps,
depositCapAmount: dec.depositCapAmount,
scopePrices: dec.scopePrices,
scopeOraclePriceId: dec.scopeOraclePriceId,
scopeOracleMaxAge: dec.scopeOracleMaxAge,
pendingFarmAdmin: dec.pendingFarmAdmin,
strategyId: dec.strategyId,
padding: dec.padding,
});
}
toJSON() {
return {
farmAdmin: this.farmAdmin.toString(),
globalConfig: this.globalConfig.toString(),
token: this.token.toJSON(),
rewardInfos: this.rewardInfos.map((item) => item.toJSON()),
numRewardTokens: this.numRewardTokens.toString(),
numUsers: this.numUsers.toString(),
totalStakedAmount: this.totalStakedAmount.toString(),
farmVault: this.farmVault.toString(),
farmVaultsAuthority: this.farmVaultsAuthority.toString(),
farmVaultsAuthorityBump: this.farmVaultsAuthorityBump.toString(),
delegateAuthority: this.delegateAuthority.toString(),
timeUnit: this.timeUnit,
isFarmFrozen: this.isFarmFrozen,
isFarmDelegated: this.isFarmDelegated,
padding0: this.padding0,
withdrawAuthority: this.withdrawAuthority.toString(),
depositWarmupPeriod: this.depositWarmupPeriod,
withdrawalCooldownPeriod: this.withdrawalCooldownPeriod,
totalActiveStakeScaled: this.totalActiveStakeScaled.toString(),
totalPendingStakeScaled: this.totalPendingStakeScaled.toString(),
totalPendingAmount: this.totalPendingAmount.toString(),
slashedAmountCurrent: this.slashedAmountCurrent.toString(),
slashedAmountCumulative: this.slashedAmountCumulative.toString(),
slashedAmountSpillAddress: this.slashedAmountSpillAddress.toString(),
lockingMode: this.lockingMode.toString(),
lockingStartTimestamp: this.lockingStartTimestamp.toString(),
lockingDuration: this.lockingDuration.toString(),
lockingEarlyWithdrawalPenaltyBps: this.lockingEarlyWithdrawalPenaltyBps.toString(),
depositCapAmount: this.depositCapAmount.toString(),
scopePrices: this.scopePrices.toString(),
scopeOraclePriceId: this.scopeOraclePriceId.toString(),
scopeOracleMaxAge: this.scopeOracleMaxAge.toString(),
pendingFarmAdmin: this.pendingFarmAdmin.toString(),
strategyId: this.strategyId.toString(),
padding: this.padding.map((item) => item.toString()),
};
}
static fromJSON(obj) {
return new FarmState({
farmAdmin: new web3_js_1.PublicKey(obj.farmAdmin),
globalConfig: new web3_js_1.PublicKey(obj.globalConfig),
token: types.TokenInfo.fromJSON(obj.token),
rewardInfos: obj.rewardInfos.map((item) => types.RewardInfo.fromJSON(item)),
numRewardTokens: new bn_js_1.default(obj.numRewardTokens),
numUsers: new bn_js_1.default(obj.numUsers),
totalStakedAmount: new bn_js_1.default(obj.totalStakedAmount),
farmVault: new web3_js_1.PublicKey(obj.farmVault),
farmVaultsAuthority: new web3_js_1.PublicKey(obj.farmVaultsAuthority),
farmVaultsAuthorityBump: new bn_js_1.default(obj.farmVaultsAuthorityBump),
delegateAuthority: new web3_js_1.PublicKey(obj.delegateAuthority),
timeUnit: obj.timeUnit,
isFarmFrozen: obj.isFarmFrozen,
isFarmDelegated: obj.isFarmDelegated,
padding0: obj.padding0,
withdrawAuthority: new web3_js_1.PublicKey(obj.withdrawAuthority),
depositWarmupPeriod: obj.depositWarmupPeriod,
withdrawalCooldownPeriod: obj.withdrawalCooldownPeriod,
totalActiveStakeScaled: new bn_js_1.default(obj.totalActiveStakeScaled),
totalPendingStakeScaled: new bn_js_1.default(obj.totalPendingStakeScaled),
totalPendingAmount: new bn_js_1.default(obj.totalPendingAmount),
slashedAmountCurrent: new bn_js_1.default(obj.slashedAmountCurrent),
slashedAmountCumulative: new bn_js_1.default(obj.slashedAmountCumulative),
slashedAmountSpillAddress: new web3_js_1.PublicKey(obj.slashedAmountSpillAddress),
lockingMode: new bn_js_1.default(obj.lockingMode),
lockingStartTimestamp: new bn_js_1.default(obj.lockingStartTimestamp),
lockingDuration: new bn_js_1.default(obj.lockingDuration),
lockingEarlyWithdrawalPenaltyBps: new bn_js_1.default(obj.lockingEarlyWithdrawalPenaltyBps),
depositCapAmount: new bn_js_1.default(obj.depositCapAmount),
scopePrices: new web3_js_1.PublicKey(obj.scopePrices),
scopeOraclePriceId: new bn_js_1.default(obj.scopeOraclePriceId),
scopeOracleMaxAge: new bn_js_1.default(obj.scopeOracleMaxAge),
pendingFarmAdmin: new web3_js_1.PublicKey(obj.pendingFarmAdmin),
strategyId: new web3_js_1.PublicKey(obj.strategyId),
padding: obj.padding.map((item) => new bn_js_1.default(item)),
});
}
}
exports.FarmState = FarmState;
FarmState.discriminator = Buffer.from([
198, 102, 216, 74, 63, 66, 163, 190,
]);
FarmState.layout = borsh.struct([
borsh.publicKey("farmAdmin"),
borsh.publicKey("globalConfig"),
types.TokenInfo.layout("token"),
borsh.array(types.RewardInfo.layout(), 10, "rewardInfos"),
borsh.u64("numRewardTokens"),
borsh.u64("numUsers"),
borsh.u64("totalStakedAmount"),
borsh.publicKey("farmVault"),
borsh.publicKey("farmVaultsAuthority"),
borsh.u64("farmVaultsAuthorityBump"),
borsh.publicKey("delegateAuthority"),
borsh.u8("timeUnit"),
borsh.u8("isFarmFrozen"),
borsh.u8("isFarmDelegated"),
borsh.array(borsh.u8(), 5, "padding0"),
borsh.publicKey("withdrawAuthority"),
borsh.u32("depositWarmupPeriod"),
borsh.u32("withdrawalCooldownPeriod"),
borsh.u128("totalActiveStakeScaled"),
borsh.u128("totalPendingStakeScaled"),
borsh.u64("totalPendingAmount"),
borsh.u64("slashedAmountCurrent"),
borsh.u64("slashedAmountCumulative"),
borsh.publicKey("slashedAmountSpillAddress"),
borsh.u64("lockingMode"),
borsh.u64("lockingStartTimestamp"),
borsh.u64("lockingDuration"),
borsh.u64("lockingEarlyWithdrawalPenaltyBps"),
borsh.u64("depositCapAmount"),
borsh.publicKey("scopePrices"),
borsh.u64("scopeOraclePriceId"),
borsh.u64("scopeOracleMaxAge"),
borsh.publicKey("pendingFarmAdmin"),
borsh.publicKey("strategyId"),
borsh.array(borsh.u64(), 86, "padding"),
]);
//# sourceMappingURL=FarmState.js.map