@bridgesplit/rwa-token-sdk
Version:
RWA Token SDK for the development of permissioned tokens on SVM blockchains.
87 lines • 4.95 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.getDataAccountsWithFilter = exports.DATA_ACCOUNT_TYPE_OFFSET = exports.DATA_ACCOUNT_REGISTRY_OFFSET = exports.getDataRegistryAccountsWithFilter = exports.DATA_REGISTRY_DELEGATE_OFFSET = exports.DATA_REGISTRY_AUTHORITY_OFFSET = exports.DATA_REGISTRY_ASSET_MINT_OFFSET = exports.getDataRegistryAccount = void 0;
const utils_1 = require("./utils");
const web3_js_1 = require("@solana/web3.js");
/**
* Retrieves data registry account associated with a specific asset mint.
* @param assetMint - The string representation of the asset mint.
* @returns A promise resolving to the fetched data registry account, or `undefined` if it doesn't exist.
*/
function getDataRegistryAccount(assetMint, provider) {
return __awaiter(this, void 0, void 0, function* () {
const dataRegistryProgram = (0, utils_1.getDataRegistryProgram)(provider);
const dataRegistryPda = (0, utils_1.getDataRegistryPda)(assetMint);
return dataRegistryProgram.account.dataRegistryAccount.fetch(dataRegistryPda)
.then(account => account)
.catch(() => undefined);
});
}
exports.getDataRegistryAccount = getDataRegistryAccount;
exports.DATA_REGISTRY_ASSET_MINT_OFFSET = 9;
exports.DATA_REGISTRY_AUTHORITY_OFFSET = 41;
exports.DATA_REGISTRY_DELEGATE_OFFSET = 73;
/**
* Retrieves data registry account associated with a specific asset mint.
* @param assetMint - The string representation of the asset mint.
* @returns A promise resolving to the fetched data registry account, or `undefined` if it doesn't exist.
*/
function getDataRegistryAccountsWithFilter(filter, provider) {
return __awaiter(this, void 0, void 0, function* () {
const { assetMint, authority, delegate } = filter;
const dataRegistryProgram = (0, utils_1.getDataRegistryProgram)(provider);
const filters = [];
if (assetMint) {
filters.push({ memcmp: { offset: exports.DATA_REGISTRY_ASSET_MINT_OFFSET, bytes: new web3_js_1.PublicKey(assetMint).toBase58() } });
}
if (authority) {
filters.push({ memcmp: { offset: exports.DATA_REGISTRY_AUTHORITY_OFFSET, bytes: new web3_js_1.PublicKey(authority).toBase58() } });
}
if (delegate) {
filters.push({ memcmp: { offset: exports.DATA_REGISTRY_DELEGATE_OFFSET, bytes: new web3_js_1.PublicKey(delegate).toBase58() } });
}
const dataAccounts = yield provider.connection.getProgramAccounts(dataRegistryProgram.programId, {
filters,
});
return dataAccounts.map(account => dataRegistryProgram.coder.accounts.decode("DataRegistryAccount", account.account.data));
});
}
exports.getDataRegistryAccountsWithFilter = getDataRegistryAccountsWithFilter;
exports.DATA_ACCOUNT_REGISTRY_OFFSET = 9;
exports.DATA_ACCOUNT_TYPE_OFFSET = 41;
/**
* Retrieves all data accounts associated with a specific asset mint and owner.
* @param assetMint - The string representation of the asset mint.
*/
function getDataAccountsWithFilter(filter, provider) {
return __awaiter(this, void 0, void 0, function* () {
const { assetMint, registry, type } = filter;
const dataRegistryProgram = (0, utils_1.getDataRegistryProgram)(provider);
const filters = [];
if (assetMint) {
const dataRegistryPda = (0, utils_1.getDataRegistryPda)(assetMint);
filters.push({ memcmp: { offset: exports.DATA_ACCOUNT_REGISTRY_OFFSET, bytes: dataRegistryPda.toBase58() } });
}
if (registry) {
filters.push({ memcmp: { offset: exports.DATA_ACCOUNT_REGISTRY_OFFSET, bytes: new web3_js_1.PublicKey(registry).toBase58() } });
}
if (type) {
filters.push({ memcmp: { offset: exports.DATA_ACCOUNT_TYPE_OFFSET, bytes: new web3_js_1.PublicKey(type).toBase58() } });
}
const dataAccounts = yield provider.connection.getProgramAccounts(dataRegistryProgram.programId, {
filters,
});
return dataAccounts.map(account => dataRegistryProgram.coder.accounts.decode("DataAccount", account.account.data));
});
}
exports.getDataAccountsWithFilter = getDataAccountsWithFilter;
//# sourceMappingURL=data.js.map