UNPKG

@bridgesplit/rwa-token-sdk

Version:

RWA Token SDK for the development of permissioned tokens on SVM blockchains.

60 lines 3.48 kB
"use strict"; 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.getAssetControllerAccountsWithFilter = exports.ASSET_CONTROLLER_DELEGATE_OFFSET = exports.ASSET_CONTROLLER_AUTHORITY_OFFSET = exports.ASSET_CONTROLLER_ASSET_MINT_OFFSET = exports.getAssetControllerAccount = void 0; const utils_1 = require("./utils"); const web3_js_1 = require("@solana/web3.js"); /** * Retrieves a asset controller account associated with a specific asset mint. * @param assetMint - The string representation of the asset mint. * @returns A promise resolving to the fetched asset controller account, or `undefined` if it doesn't exist. */ function getAssetControllerAccount(assetMint, provider) { return __awaiter(this, void 0, void 0, function* () { const assetProgram = (0, utils_1.getAssetControllerProgram)(provider); const assetControllerPda = (0, utils_1.getAssetControllerPda)(assetMint); return assetProgram.account.assetControllerAccount .fetch(assetControllerPda) .then((account) => account) .catch(() => undefined); }); } exports.getAssetControllerAccount = getAssetControllerAccount; exports.ASSET_CONTROLLER_ASSET_MINT_OFFSET = 9; exports.ASSET_CONTROLLER_AUTHORITY_OFFSET = 41; exports.ASSET_CONTROLLER_DELEGATE_OFFSET = 73; /** * Retrieves a asset controller account associated with a specific asset mint. * @param assetMint - The string representation of the asset mint. * @returns A promise resolving to the fetched asset controller account, or `undefined` if it doesn't exist. */ function getAssetControllerAccountsWithFilter(filter, provider) { return __awaiter(this, void 0, void 0, function* () { const { assetMint, authority, delegate } = filter; const assetProgram = (0, utils_1.getAssetControllerProgram)(provider); const filters = []; if (assetMint) { filters.push({ memcmp: { offset: exports.ASSET_CONTROLLER_ASSET_MINT_OFFSET, bytes: new web3_js_1.PublicKey(assetMint).toBase58() } }); } if (authority) { filters.push({ memcmp: { offset: exports.ASSET_CONTROLLER_AUTHORITY_OFFSET, bytes: new web3_js_1.PublicKey(authority).toBase58() } }); } if (delegate) { filters.push({ memcmp: { offset: exports.ASSET_CONTROLLER_DELEGATE_OFFSET, bytes: new web3_js_1.PublicKey(delegate).toBase58() } }); } const assetAccounts = yield provider.connection.getProgramAccounts(assetProgram.programId, { filters, }); return assetAccounts.map((account) => assetProgram.coder.accounts.decode("AssetControllerAccount", account.account.data)); }); } exports.getAssetControllerAccountsWithFilter = getAssetControllerAccountsWithFilter; //# sourceMappingURL=data.js.map