hadeswap-sdk
Version:
HadeSwap SDK for interacting with protocol
31 lines (30 loc) • 2.17 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHadoMarketRegistryByHadoMarket = void 0;
const anchor_1 = require("@project-serum/anchor");
const constants_1 = require("../../../hadeswap-core/constants");
const helpers_1 = require("../../../hadeswap-core/helpers");
const constants_2 = require("../../constants");
const helpers_2 = require("../../helpers");
// import { anchorRawBNsAndPubkeysToNumsAndStrings, returnAnchorProgram } from '../../helpers';
const getHadoMarketRegistryByHadoMarket = (hadoMarket, programId, connection) => __awaiter(void 0, void 0, void 0, function* () {
const program = yield (0, helpers_2.returnAnchorProgram)(programId, connection);
const [hadoRegistry, registrySeed] = yield anchor_1.web3.PublicKey.findProgramAddress([constants_1.ENCODER.encode(constants_2.HADOMARKET_REGISTRY_PREFIX), hadoMarket.toBuffer()], program.programId);
const rawAccount = yield program.account.hadoMarketRegistry.fetchNullable(hadoRegistry);
if (!rawAccount)
return null;
const hadoRegistryAccount = (0, helpers_1.anchorRawBNsAndPubkeysToNumsAndStrings)({ publicKey: hadoRegistry, account: rawAccount });
// const anyAccountsRaw = await program.account[accountId].all();
// const anyAccounts = anyAccountsRaw.map((anyAccountRaw) => anchorRawBNsAndPubkeysToNumsAndStrings(anyAccountRaw));
return hadoRegistryAccount;
});
exports.getHadoMarketRegistryByHadoMarket = getHadoMarketRegistryByHadoMarket;