UNPKG

@marinade.finance/kamino-sdk

Version:
147 lines 5.53 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.AmmConfig = 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"); /** Holds the current owner of the factory */ class AmmConfig { /** Bump to identify PDA */ bump; index; /** Address of the protocol owner */ owner; /** The protocol fee */ protocolFeeRate; /** The trade fee, denominated in hundredths of a bip (10^-6) */ tradeFeeRate; /** The tick spacing */ tickSpacing; /** The fund fee, denominated in hundredths of a bip (10^-6) */ fundFeeRate; paddingU32; fundOwner; padding; static discriminator = Buffer.from([218, 244, 33, 104, 203, 203, 43, 111]); static layout = borsh.struct([ borsh.u8('bump'), borsh.u16('index'), borsh.publicKey('owner'), borsh.u32('protocolFeeRate'), borsh.u32('tradeFeeRate'), borsh.u16('tickSpacing'), borsh.u32('fundFeeRate'), borsh.u32('paddingU32'), borsh.publicKey('fundOwner'), borsh.array(borsh.u64(), 3, 'padding'), ]); constructor(fields) { this.bump = fields.bump; this.index = fields.index; this.owner = fields.owner; this.protocolFeeRate = fields.protocolFeeRate; this.tradeFeeRate = fields.tradeFeeRate; this.tickSpacing = fields.tickSpacing; this.fundFeeRate = fields.fundFeeRate; this.paddingU32 = fields.paddingU32; this.fundOwner = fields.fundOwner; 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(AmmConfig.discriminator)) { throw new Error('invalid account discriminator'); } const dec = AmmConfig.layout.decode(data.slice(8)); return new AmmConfig({ bump: dec.bump, index: dec.index, owner: dec.owner, protocolFeeRate: dec.protocolFeeRate, tradeFeeRate: dec.tradeFeeRate, tickSpacing: dec.tickSpacing, fundFeeRate: dec.fundFeeRate, paddingU32: dec.paddingU32, fundOwner: dec.fundOwner, padding: dec.padding, }); } toJSON() { return { bump: this.bump, index: this.index, owner: this.owner.toString(), protocolFeeRate: this.protocolFeeRate, tradeFeeRate: this.tradeFeeRate, tickSpacing: this.tickSpacing, fundFeeRate: this.fundFeeRate, paddingU32: this.paddingU32, fundOwner: this.fundOwner.toString(), padding: this.padding.map((item) => item.toString()), }; } static fromJSON(obj) { return new AmmConfig({ bump: obj.bump, index: obj.index, owner: new web3_js_1.PublicKey(obj.owner), protocolFeeRate: obj.protocolFeeRate, tradeFeeRate: obj.tradeFeeRate, tickSpacing: obj.tickSpacing, fundFeeRate: obj.fundFeeRate, paddingU32: obj.paddingU32, fundOwner: new web3_js_1.PublicKey(obj.fundOwner), padding: obj.padding.map((item) => new bn_js_1.default(item)), }); } } exports.AmmConfig = AmmConfig; //# sourceMappingURL=AmmConfig.js.map