UNPKG

hadeswap-sdk

Version:

HadeSwap SDK for interacting with protocol

37 lines (36 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.enumToAnchorEnum = exports.anchorRawBNsAndPubkeysToNumsAndStrings = exports.returnAnchorProgram = void 0; const anchor_1 = require("@project-serum/anchor"); const frakt_market_registry_1 = require("./idl/frakt_market_registry"); const common_1 = require("../common"); const returnAnchorProgram = (programId, connection) => new anchor_1.Program(frakt_market_registry_1.IDL, programId, 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;