UNPKG

@kamino-finance/klend-sdk

Version:

Typescript SDK for interacting with the Kamino Lending (klend) protocol

114 lines 4.71 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.PriceUpdateV2 = exports.PYTH_RECEIVER_PROGRAM_ID = 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")); exports.PYTH_RECEIVER_PROGRAM_ID = new web3_js_1.PublicKey('rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ'); class PriceUpdateV2 { writeAuthority; verificationLevel; priceMessage; postedSlot; // static readonly discriminator = Buffer.from([ // 43, 242, 204, 202, 26, 247, 59, 127, // ]) static layout = borsh.struct([ borsh.publicKey('writeAuthority'), borsh.u8('verificationLevel'), types.PriceFeedMessage.layout('priceMessage'), borsh.u64('postedSlot'), ]); constructor(fields) { this.writeAuthority = fields.writeAuthority; this.verificationLevel = fields.verificationLevel; this.priceMessage = new types.PriceFeedMessage({ ...fields.priceMessage }); this.postedSlot = fields.postedSlot; } static async fetch(c, address, programId = exports.PYTH_RECEIVER_PROGRAM_ID) { const info = await 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 async fetchMultiple(c, addresses, programId = exports.PYTH_RECEIVER_PROGRAM_ID) { const infos = await 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) { const dec = PriceUpdateV2.layout.decode(data.slice(8)); return new PriceUpdateV2({ writeAuthority: dec.writeAuthority, verificationLevel: dec.verificationLevel, priceMessage: types.PriceFeedMessage.fromDecoded(dec.priceMessage), postedSlot: dec.postedSlot, }); } toJSON() { return { writeAuthority: this.writeAuthority.toString(), verificationLevel: this.verificationLevel.toJSON(), priceMessage: this.priceMessage.toJSON(), postedSlot: this.postedSlot.toString(), }; } static fromJSON(obj) { return new PriceUpdateV2({ writeAuthority: new web3_js_1.PublicKey(obj.writeAuthority), verificationLevel: types.VerificationLevel.fromJSON(obj.verificationLevel), priceMessage: types.PriceFeedMessage.fromJSON(obj.priceMessage), postedSlot: new bn_js_1.default(obj.postedSlot), }); } } exports.PriceUpdateV2 = PriceUpdateV2; //# sourceMappingURL=PriceUpdateV2.js.map