UNPKG

fbonds-core

Version:

Banx protocol sdk

40 lines (39 loc) 2.13 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.enumToAnchorEnum = exports.anchorRawBNsAndPubkeysToNumsAndStrings = exports.returnAnchorProgram = void 0; const common_1 = require("../common"); const frakt_market_registry_json_1 = __importDefault(require("../idls/frakt_market_registry.json")); const anchor_1 = require("@coral-xyz/anchor"); const returnAnchorProgram = (programId, connection) => new anchor_1.Program(frakt_market_registry_json_1.default, new anchor_1.AnchorProvider(connection, (0, common_1.createFakeWallet)(), anchor_1.AnchorProvider.defaultOptions())); exports.returnAnchorProgram = returnAnchorProgram; const anchorRawBNsAndPubkeysToNumsAndStrings = (rawAccount) => { const copyRawAccount = Object.assign({}, rawAccount); const newAccount = parseRawAccount(rawAccount.account); return Object.assign(Object.assign({}, newAccount), { publicKey: copyRawAccount.publicKey.toBase58() }); }; exports.anchorRawBNsAndPubkeysToNumsAndStrings = anchorRawBNsAndPubkeysToNumsAndStrings; const parseRawAccount = (rawAccount) => { const copyRawAccount = Object.assign({}, rawAccount); for (let key in copyRawAccount) { if (copyRawAccount[key] === null || copyRawAccount[key] === undefined) continue; if (copyRawAccount[key].toNumber) { copyRawAccount[key] = copyRawAccount[key].toNumber(); } if (copyRawAccount[key].toBase58) { copyRawAccount[key] = copyRawAccount[key].toBase58(); } if (typeof copyRawAccount[key] === 'object' && Object.keys(copyRawAccount[key]).length === 1) { copyRawAccount[key] = Object.keys(copyRawAccount[key])[0]; } else if (typeof copyRawAccount[key] === 'object') { copyRawAccount[key] = parseRawAccount(copyRawAccount[key]); } } return copyRawAccount; }; const enumToAnchorEnum = (anyEnum) => ({ [anyEnum]: {} }); exports.enumToAnchorEnum = enumToAnchorEnum;