@frakters/nft-lending-v2
Version:
Client library for interacting with nft lenging solana program
50 lines (49 loc) • 2.33 kB
JavaScript
;
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getArweaveMetadataByMint = void 0;
const lib_1 = require("./lib");
const borsh_1 = require("borsh");
const web3_js_1 = require("@solana/web3.js");
const bs58_1 = __importDefault(require("bs58"));
(() => {
// https://www.npmjs.com/package/borsh
// Extend Borsh function for read/write pubkey
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);
};
borsh_1.BinaryWriter.prototype.writePubkeyAsString = function (value) {
const writer = this;
writer.writeFixedArray(bs58_1.default.decode(value));
};
})();
exports.getArweaveMetadataByMint = (tokenMints, endpoint) => __awaiter(void 0, void 0, void 0, function* () {
const rawMeta = yield lib_1.getMeta(tokenMints, endpoint);
const metadataByMint = (rawMeta === null || rawMeta === void 0 ? void 0 : rawMeta.reduce((acc, { mint, metadata }) => {
acc[mint] = metadata;
return acc;
}, {})) || {};
return metadataByMint;
});