UNPKG

@hubbleprotocol/farms-sdk

Version:
102 lines 4.58 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 __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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.OraclePrices = void 0; const web3_js_1 = require("@solana/web3.js"); 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 OraclePrices { constructor(fields) { this.oracleMappings = fields.oracleMappings; this.prices = fields.prices.map((item) => new types.DatedPrice(Object.assign({}, item))); } 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(OraclePrices.discriminator)) { throw new Error("invalid account discriminator"); } const dec = OraclePrices.layout.decode(data.slice(8)); return new OraclePrices({ oracleMappings: dec.oracleMappings, prices: dec.prices.map((item /* eslint-disable-line @typescript-eslint/no-explicit-any */) => types.DatedPrice.fromDecoded(item)), }); } toJSON() { return { oracleMappings: this.oracleMappings.toString(), prices: this.prices.map((item) => item.toJSON()), }; } static fromJSON(obj) { return new OraclePrices({ oracleMappings: new web3_js_1.PublicKey(obj.oracleMappings), prices: obj.prices.map((item) => types.DatedPrice.fromJSON(item)), }); } } exports.OraclePrices = OraclePrices; OraclePrices.discriminator = Buffer.from([ 89, 128, 118, 221, 6, 72, 180, 146, ]); OraclePrices.layout = borsh.struct([ borsh.publicKey("oracleMappings"), borsh.array(types.DatedPrice.layout(), 512, "prices"), ]); //# sourceMappingURL=OraclePrices.js.map