@bridgesplit/rwa-token-sdk
Version:
RWA Token SDK for the development of permissioned tokens on SVM blockchains.
86 lines • 4.85 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.getTrackerAccount = exports.getPolicyAccount = exports.getPolicyEngineAccountsWithFilter = exports.POLICY_ENGINE_DELEGATE_OFFSET = exports.POLICY_ENGINE_AUTHORITY_OFFSET = exports.POLICY_ENGINE_ASSET_MINT_OFFSET = exports.getPolicyEngineAccount = void 0;
const utils_1 = require("./utils");
const web3_js_1 = require("@solana/web3.js");
/**
* Retrieves policy engine account associated with a specific asset mint.
* @param assetMint - The string representation of the asset mint.
* @returns A promise resolving to {@link PolicyEngineAccount}, or `undefined` if it doesn't exist.
*/
function getPolicyEngineAccount(assetMint, provider) {
return __awaiter(this, void 0, void 0, function* () {
const policyEngineProgram = (0, utils_1.getPolicyEngineProgram)(provider);
const policyEnginePda = (0, utils_1.getPolicyEnginePda)(assetMint);
return policyEngineProgram.account.policyEngineAccount.fetch(policyEnginePda)
.then(account => account)
.catch(() => undefined);
});
}
exports.getPolicyEngineAccount = getPolicyEngineAccount;
exports.POLICY_ENGINE_ASSET_MINT_OFFSET = 9;
exports.POLICY_ENGINE_AUTHORITY_OFFSET = 41;
exports.POLICY_ENGINE_DELEGATE_OFFSET = 73;
/**
* Retrieves policy engine accounts with a filter.
* @param filter - The filter to apply to the policy engine accounts.
* @returns A promise resolving to an array of {@link PolicyEngineAccount}, or `undefined` if it doesn't exist.
*/
function getPolicyEngineAccountsWithFilter(filter, provider) {
return __awaiter(this, void 0, void 0, function* () {
const { assetMint, authority, delegate } = filter;
const policyEngineProgram = (0, utils_1.getPolicyEngineProgram)(provider);
const filters = [];
if (assetMint) {
filters.push({ memcmp: { offset: exports.POLICY_ENGINE_ASSET_MINT_OFFSET, bytes: new web3_js_1.PublicKey(assetMint).toBase58() } });
}
if (authority) {
filters.push({ memcmp: { offset: exports.POLICY_ENGINE_AUTHORITY_OFFSET, bytes: new web3_js_1.PublicKey(authority).toBase58() } });
}
if (delegate) {
filters.push({ memcmp: { offset: exports.POLICY_ENGINE_DELEGATE_OFFSET, bytes: new web3_js_1.PublicKey(delegate).toBase58() } });
}
const policyAccounts = yield provider.connection.getProgramAccounts(policyEngineProgram.programId, {
filters,
});
return policyAccounts.map(account => policyEngineProgram.coder.accounts.decode("PolicyEngineAccount", account.account.data));
});
}
exports.getPolicyEngineAccountsWithFilter = getPolicyEngineAccountsWithFilter;
/**
* Retrieves a policy account associated with a specific asset mint.
* @param assetMint - The string representation of the asset mint.
* @returns A promise resolving to the fetched policy account, or `undefined` if it doesn't exist.
*/
function getPolicyAccount(assetMint, provider) {
return __awaiter(this, void 0, void 0, function* () {
const policyEngineProgram = (0, utils_1.getPolicyEngineProgram)(provider);
const policyAccountPda = (0, utils_1.getPolicyAccountPda)(assetMint);
return policyEngineProgram.account.policyAccount.fetch(policyAccountPda);
});
}
exports.getPolicyAccount = getPolicyAccount;
/**
* Retrieves a tracker account pda associated with a specific asset mint and owner.
* @param assetMint - The string representation of the asset mint.
* @param owner - The string representation of the owner's public key.
* @returns A promise resolving to the fetched tracker account, or `undefined` if it doesn't exist.
*/
function getTrackerAccount(assetMint, owner, provider) {
return __awaiter(this, void 0, void 0, function* () {
const policyEngineProgram = (0, utils_1.getPolicyEngineProgram)(provider);
const trackerPda = (0, utils_1.getTrackerAccountPda)(assetMint, owner);
return yield policyEngineProgram.account.trackerAccount.fetch(trackerPda);
});
}
exports.getTrackerAccount = getTrackerAccount;
//# sourceMappingURL=data.js.map