UNPKG

@frakters/nft-lending-v2

Version:

Client library for interacting with nft lenging solana program

52 lines (51 loc) 2.15 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.serialize = exports.deserializeUnchecked = exports.deserialize = exports.struct = exports.Data = exports.extendBorsh = void 0; const web3_js_1 = require("@solana/web3.js"); const borsh_1 = require("borsh"); Object.defineProperty(exports, "deserializeUnchecked", { enumerable: true, get: function () { return borsh_1.deserializeUnchecked; } }); Object.defineProperty(exports, "serialize", { enumerable: true, get: function () { return borsh_1.serialize; } }); Object.defineProperty(exports, "deserialize", { enumerable: true, get: function () { return borsh_1.deserialize; } }); const bs58_1 = __importDefault(require("bs58")); exports.extendBorsh = () => { borsh_1.BinaryReader.prototype.readPubkey = function () { const reader = this; const array = reader.readFixedArray(32); return new web3_js_1.PublicKey(array); }; borsh_1.BinaryWriter.prototype.writePubkey = function (value) { const writer = this; writer.writeFixedArray(value.toBuffer()); }; borsh_1.BinaryReader.prototype.readPubkeyAsString = function () { const reader = this; const array = reader.readFixedArray(32); return bs58_1.default.encode(array); // pubkey string }; borsh_1.BinaryWriter.prototype.writePubkeyAsString = function (value) { const writer = this; writer.writeFixedArray(bs58_1.default.decode(value)); }; }; exports.extendBorsh(); class Data { constructor(args = {}) { Object.assign(this, args); } static struct(fields) { return exports.struct(this, fields); } static serialize(args = {}) { return Buffer.from(borsh_1.serialize(this.SCHEMA, new this(args))); } static deserialize(data) { return borsh_1.deserializeUnchecked(this.SCHEMA, this, data); } } exports.Data = Data; exports.struct = (type, fields) => { return new Map([[type, { kind: 'struct', fields }]]); };