UNPKG

@marinade.finance/kamino-sdk

Version:
202 lines 9.09 kB
"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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GlobalConfig = 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("@project-serum/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars const programId_1 = require("../programId"); class GlobalConfig { emergencyMode; blockDeposit; blockInvest; blockWithdraw; blockCollectFees; blockCollectRewards; blockSwapRewards; blockSwapUnevenVaults; blockEmergencySwap; feesBps; scopeProgramId; scopePriceId; swapRewardsDiscountBps; actionsAuthority; adminAuthority; treasuryFeeVaults; tokenInfos; blockLocalAdmin; minPerformanceFeeBps; padding; static discriminator = Buffer.from([ 149, 8, 156, 202, 160, 252, 176, 217, ]); static layout = borsh.struct([ borsh.u64("emergencyMode"), borsh.u64("blockDeposit"), borsh.u64("blockInvest"), borsh.u64("blockWithdraw"), borsh.u64("blockCollectFees"), borsh.u64("blockCollectRewards"), borsh.u64("blockSwapRewards"), borsh.u32("blockSwapUnevenVaults"), borsh.u32("blockEmergencySwap"), borsh.u64("feesBps"), borsh.publicKey("scopeProgramId"), borsh.publicKey("scopePriceId"), borsh.array(borsh.u64(), 256, "swapRewardsDiscountBps"), borsh.publicKey("actionsAuthority"), borsh.publicKey("adminAuthority"), borsh.array(borsh.publicKey(), 256, "treasuryFeeVaults"), borsh.publicKey("tokenInfos"), borsh.u64("blockLocalAdmin"), borsh.u64("minPerformanceFeeBps"), borsh.array(borsh.u64(), 2042, "padding"), ]); constructor(fields) { this.emergencyMode = fields.emergencyMode; this.blockDeposit = fields.blockDeposit; this.blockInvest = fields.blockInvest; this.blockWithdraw = fields.blockWithdraw; this.blockCollectFees = fields.blockCollectFees; this.blockCollectRewards = fields.blockCollectRewards; this.blockSwapRewards = fields.blockSwapRewards; this.blockSwapUnevenVaults = fields.blockSwapUnevenVaults; this.blockEmergencySwap = fields.blockEmergencySwap; this.feesBps = fields.feesBps; this.scopeProgramId = fields.scopeProgramId; this.scopePriceId = fields.scopePriceId; this.swapRewardsDiscountBps = fields.swapRewardsDiscountBps; this.actionsAuthority = fields.actionsAuthority; this.adminAuthority = fields.adminAuthority; this.treasuryFeeVaults = fields.treasuryFeeVaults; this.tokenInfos = fields.tokenInfos; this.blockLocalAdmin = fields.blockLocalAdmin; this.minPerformanceFeeBps = fields.minPerformanceFeeBps; this.padding = fields.padding; } static async fetch(c, address) { const info = await c.getAccountInfo(address); if (info === null) { return null; } if (!info.owner.equals(programId_1.PROGRAM_ID)) { throw new Error("account doesn't belong to this program"); } return this.decode(info.data); } static async fetchMultiple(c, addresses) { const infos = await c.getMultipleAccountsInfo(addresses); return infos.map((info) => { if (info === null) { return null; } if (!info.owner.equals(programId_1.PROGRAM_ID)) { throw new Error("account doesn't belong to this program"); } return this.decode(info.data); }); } static decode(data) { if (!data.slice(0, 8).equals(GlobalConfig.discriminator)) { throw new Error("invalid account discriminator"); } const dec = GlobalConfig.layout.decode(data.slice(8)); return new GlobalConfig({ emergencyMode: dec.emergencyMode, blockDeposit: dec.blockDeposit, blockInvest: dec.blockInvest, blockWithdraw: dec.blockWithdraw, blockCollectFees: dec.blockCollectFees, blockCollectRewards: dec.blockCollectRewards, blockSwapRewards: dec.blockSwapRewards, blockSwapUnevenVaults: dec.blockSwapUnevenVaults, blockEmergencySwap: dec.blockEmergencySwap, feesBps: dec.feesBps, scopeProgramId: dec.scopeProgramId, scopePriceId: dec.scopePriceId, swapRewardsDiscountBps: dec.swapRewardsDiscountBps, actionsAuthority: dec.actionsAuthority, adminAuthority: dec.adminAuthority, treasuryFeeVaults: dec.treasuryFeeVaults, tokenInfos: dec.tokenInfos, blockLocalAdmin: dec.blockLocalAdmin, minPerformanceFeeBps: dec.minPerformanceFeeBps, padding: dec.padding, }); } toJSON() { return { emergencyMode: this.emergencyMode.toString(), blockDeposit: this.blockDeposit.toString(), blockInvest: this.blockInvest.toString(), blockWithdraw: this.blockWithdraw.toString(), blockCollectFees: this.blockCollectFees.toString(), blockCollectRewards: this.blockCollectRewards.toString(), blockSwapRewards: this.blockSwapRewards.toString(), blockSwapUnevenVaults: this.blockSwapUnevenVaults, blockEmergencySwap: this.blockEmergencySwap, feesBps: this.feesBps.toString(), scopeProgramId: this.scopeProgramId.toString(), scopePriceId: this.scopePriceId.toString(), swapRewardsDiscountBps: this.swapRewardsDiscountBps.map((item) => item.toString()), actionsAuthority: this.actionsAuthority.toString(), adminAuthority: this.adminAuthority.toString(), treasuryFeeVaults: this.treasuryFeeVaults.map((item) => item.toString()), tokenInfos: this.tokenInfos.toString(), blockLocalAdmin: this.blockLocalAdmin.toString(), minPerformanceFeeBps: this.minPerformanceFeeBps.toString(), padding: this.padding.map((item) => item.toString()), }; } static fromJSON(obj) { return new GlobalConfig({ emergencyMode: new bn_js_1.default(obj.emergencyMode), blockDeposit: new bn_js_1.default(obj.blockDeposit), blockInvest: new bn_js_1.default(obj.blockInvest), blockWithdraw: new bn_js_1.default(obj.blockWithdraw), blockCollectFees: new bn_js_1.default(obj.blockCollectFees), blockCollectRewards: new bn_js_1.default(obj.blockCollectRewards), blockSwapRewards: new bn_js_1.default(obj.blockSwapRewards), blockSwapUnevenVaults: obj.blockSwapUnevenVaults, blockEmergencySwap: obj.blockEmergencySwap, feesBps: new bn_js_1.default(obj.feesBps), scopeProgramId: new web3_js_1.PublicKey(obj.scopeProgramId), scopePriceId: new web3_js_1.PublicKey(obj.scopePriceId), swapRewardsDiscountBps: obj.swapRewardsDiscountBps.map((item) => new bn_js_1.default(item)), actionsAuthority: new web3_js_1.PublicKey(obj.actionsAuthority), adminAuthority: new web3_js_1.PublicKey(obj.adminAuthority), treasuryFeeVaults: obj.treasuryFeeVaults.map((item) => new web3_js_1.PublicKey(item)), tokenInfos: new web3_js_1.PublicKey(obj.tokenInfos), blockLocalAdmin: new bn_js_1.default(obj.blockLocalAdmin), minPerformanceFeeBps: new bn_js_1.default(obj.minPerformanceFeeBps), padding: obj.padding.map((item) => new bn_js_1.default(item)), }); } } exports.GlobalConfig = GlobalConfig; //# sourceMappingURL=GlobalConfig.js.map