UNPKG

@kamino-finance/scope-sdk

Version:
228 lines 9.66 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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __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.PositionRequest = void 0; /* eslint-disable @typescript-eslint/no-unused-vars */ const kit_1 = require("@solana/kit"); /* eslint-enable @typescript-eslint/no-unused-vars */ 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 utils_1 = require("../utils"); // 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 PositionRequest { owner; pool; custody; position; mint; openTime; updateTime; sizeUsdDelta; collateralDelta; requestChange; requestType; side; priceSlippage; jupiterMinimumOut; preSwapAmount; triggerPrice; triggerAboveThreshold; entirePosition; executed; counter; bump; referral; static discriminator = Buffer.from([ 12, 38, 250, 199, 46, 154, 32, 216, ]); static layout = borsh.struct([ (0, utils_1.borshAddress)("owner"), (0, utils_1.borshAddress)("pool"), (0, utils_1.borshAddress)("custody"), (0, utils_1.borshAddress)("position"), (0, utils_1.borshAddress)("mint"), borsh.i64("openTime"), borsh.i64("updateTime"), borsh.u64("sizeUsdDelta"), borsh.u64("collateralDelta"), types.RequestChange.layout("requestChange"), types.RequestType.layout("requestType"), types.Side.layout("side"), borsh.option(borsh.u64(), "priceSlippage"), borsh.option(borsh.u64(), "jupiterMinimumOut"), borsh.option(borsh.u64(), "preSwapAmount"), borsh.option(borsh.u64(), "triggerPrice"), borsh.option(borsh.bool(), "triggerAboveThreshold"), borsh.option(borsh.bool(), "entirePosition"), borsh.bool("executed"), borsh.u64("counter"), borsh.u8("bump"), borsh.option((0, utils_1.borshAddress)(), "referral"), ]); constructor(fields) { this.owner = fields.owner; this.pool = fields.pool; this.custody = fields.custody; this.position = fields.position; this.mint = fields.mint; this.openTime = fields.openTime; this.updateTime = fields.updateTime; this.sizeUsdDelta = fields.sizeUsdDelta; this.collateralDelta = fields.collateralDelta; this.requestChange = fields.requestChange; this.requestType = fields.requestType; this.side = fields.side; this.priceSlippage = fields.priceSlippage; this.jupiterMinimumOut = fields.jupiterMinimumOut; this.preSwapAmount = fields.preSwapAmount; this.triggerPrice = fields.triggerPrice; this.triggerAboveThreshold = fields.triggerAboveThreshold; this.entirePosition = fields.entirePosition; this.executed = fields.executed; this.counter = fields.counter; this.bump = fields.bump; this.referral = fields.referral; } static async fetch(rpc, address, programId = programId_1.PROGRAM_ID) { const info = await (0, kit_1.fetchEncodedAccount)(rpc, address); if (!info.exists) { return null; } if (info.programAddress !== programId) { throw new Error("account doesn't belong to this program"); } return this.decode(Buffer.from(info.data)); } static async fetchMultiple(rpc, addresses, programId = programId_1.PROGRAM_ID) { const infos = await (0, kit_1.fetchEncodedAccounts)(rpc, addresses); return infos.map((info) => { if (!info.exists) { return null; } if (info.programAddress !== programId) { throw new Error("account doesn't belong to this program"); } return this.decode(Buffer.from(info.data)); }); } static decode(data) { if (!data.slice(0, 8).equals(PositionRequest.discriminator)) { throw new Error("invalid account discriminator"); } const dec = PositionRequest.layout.decode(data.slice(8)); return new PositionRequest({ owner: dec.owner, pool: dec.pool, custody: dec.custody, position: dec.position, mint: dec.mint, openTime: dec.openTime, updateTime: dec.updateTime, sizeUsdDelta: dec.sizeUsdDelta, collateralDelta: dec.collateralDelta, requestChange: types.RequestChange.fromDecoded(dec.requestChange), requestType: types.RequestType.fromDecoded(dec.requestType), side: types.Side.fromDecoded(dec.side), priceSlippage: dec.priceSlippage, jupiterMinimumOut: dec.jupiterMinimumOut, preSwapAmount: dec.preSwapAmount, triggerPrice: dec.triggerPrice, triggerAboveThreshold: dec.triggerAboveThreshold, entirePosition: dec.entirePosition, executed: dec.executed, counter: dec.counter, bump: dec.bump, referral: dec.referral, }); } toJSON() { return { owner: this.owner, pool: this.pool, custody: this.custody, position: this.position, mint: this.mint, openTime: this.openTime.toString(), updateTime: this.updateTime.toString(), sizeUsdDelta: this.sizeUsdDelta.toString(), collateralDelta: this.collateralDelta.toString(), requestChange: this.requestChange.toJSON(), requestType: this.requestType.toJSON(), side: this.side.toJSON(), priceSlippage: (this.priceSlippage && this.priceSlippage.toString()) || null, jupiterMinimumOut: (this.jupiterMinimumOut && this.jupiterMinimumOut.toString()) || null, preSwapAmount: (this.preSwapAmount && this.preSwapAmount.toString()) || null, triggerPrice: (this.triggerPrice && this.triggerPrice.toString()) || null, triggerAboveThreshold: this.triggerAboveThreshold, entirePosition: this.entirePosition, executed: this.executed, counter: this.counter.toString(), bump: this.bump, referral: this.referral, }; } static fromJSON(obj) { return new PositionRequest({ owner: (0, kit_1.address)(obj.owner), pool: (0, kit_1.address)(obj.pool), custody: (0, kit_1.address)(obj.custody), position: (0, kit_1.address)(obj.position), mint: (0, kit_1.address)(obj.mint), openTime: new bn_js_1.default(obj.openTime), updateTime: new bn_js_1.default(obj.updateTime), sizeUsdDelta: new bn_js_1.default(obj.sizeUsdDelta), collateralDelta: new bn_js_1.default(obj.collateralDelta), requestChange: types.RequestChange.fromJSON(obj.requestChange), requestType: types.RequestType.fromJSON(obj.requestType), side: types.Side.fromJSON(obj.side), priceSlippage: (obj.priceSlippage && new bn_js_1.default(obj.priceSlippage)) || null, jupiterMinimumOut: (obj.jupiterMinimumOut && new bn_js_1.default(obj.jupiterMinimumOut)) || null, preSwapAmount: (obj.preSwapAmount && new bn_js_1.default(obj.preSwapAmount)) || null, triggerPrice: (obj.triggerPrice && new bn_js_1.default(obj.triggerPrice)) || null, triggerAboveThreshold: obj.triggerAboveThreshold, entirePosition: obj.entirePosition, executed: obj.executed, counter: new bn_js_1.default(obj.counter), bump: obj.bump, referral: (obj.referral && (0, kit_1.address)(obj.referral)) || null, }); } } exports.PositionRequest = PositionRequest; //# sourceMappingURL=PositionRequest.js.map