UNPKG

@bridgesplit/rwa-token-sdk

Version:

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

142 lines 6.55 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.getCreateTrackerAccountIx = exports.getCreatePolicyAccountIx = exports.getDetachFromPolicyAccountIx = exports.getAttachToPolicyAccountIx = exports.getCreatePolicyEngineIx = void 0; const web3_js_1 = require("@solana/web3.js"); const utils_1 = require("./utils"); /** * Generate instructions to create a new policy account. * @param args {@link CreatePolicyEngineArgs}. * @returns Create policy engine transaction instruction. */ function getCreatePolicyEngineIx(args, provider) { return __awaiter(this, void 0, void 0, function* () { const policyProgram = (0, utils_1.getPolicyEngineProgram)(provider); const ix = yield policyProgram.methods .createPolicyEngine(new web3_js_1.PublicKey(args.authority), args.delegate ? new web3_js_1.PublicKey(args.delegate) : null) .accountsStrict({ payer: args.payer, signer: args.signer, assetMint: args.assetMint, policyEngineAccount: (0, utils_1.getPolicyEnginePda)(args.assetMint), extraMetasAccount: (0, utils_1.getExtraMetasListPda)(args.assetMint), systemProgram: web3_js_1.SystemProgram.programId, }) .instruction(); return ix; }); } exports.getCreatePolicyEngineIx = getCreatePolicyEngineIx; /** * Generate instructions to connect am policy to an asset. * * This function constructs an instruction to attach a policy account to an asset * using the provided arguments. It calls the policy engine program to attach the policy account, * and returns the generated instruction along with the required signers. * * @param args {@link AttachPolicyArgs} * @returns - {@link IxReturn}, a list of transaction instructions and a new key pair responsible to sign it. */ function getAttachToPolicyAccountIx(args, provider) { return __awaiter(this, void 0, void 0, function* () { const policyProgram = (0, utils_1.getPolicyEngineProgram)(provider); const policyAccount = (0, utils_1.getPolicyAccountPda)(args.assetMint); const ix = yield policyProgram.methods .attachToPolicyAccount(args.identityFilter, args.policyType) .accountsStrict({ policyAccount, signer: new web3_js_1.PublicKey(args.authority), payer: args.payer, policyEngine: (0, utils_1.getPolicyEnginePda)(args.assetMint), systemProgram: web3_js_1.SystemProgram.programId, }) .instruction(); return { ixs: [ix], signers: [], }; }); } exports.getAttachToPolicyAccountIx = getAttachToPolicyAccountIx; /** * Generate instructions to detach an identity policy account to an asset. * * This function constructs an instruction to attach a policy account to an asset * using the provided arguments. It creates a new policy account, calls the policy * engine program to attach the policy account, and returns the generated instruction * along with the required signers. * * @param args {@link AttachPolicyArgs} * @returns - {@link IxReturn}, a list of transaction instructions and a new key pair responsible to sign it. */ function getDetachFromPolicyAccountIx(args, provider) { return __awaiter(this, void 0, void 0, function* () { const policyProgram = (0, utils_1.getPolicyEngineProgram)(provider); const policyAccount = (0, utils_1.getPolicyAccountPda)(args.assetMint); const ix = yield policyProgram.methods .detachFromPolicyAccount(args.hash) .accountsStrict({ policyAccount, signer: new web3_js_1.PublicKey(args.authority), payer: args.payer, policyEngine: (0, utils_1.getPolicyEnginePda)(args.assetMint), systemProgram: web3_js_1.SystemProgram.programId, }) .instruction(); return { ixs: [ix], signers: [], }; }); } exports.getDetachFromPolicyAccountIx = getDetachFromPolicyAccountIx; function getCreatePolicyAccountIx(args, provider) { return __awaiter(this, void 0, void 0, function* () { const policyProgram = (0, utils_1.getPolicyEngineProgram)(provider); const policyAccount = (0, utils_1.getPolicyAccountPda)(args.assetMint); const ix = yield policyProgram.methods .createPolicyAccount(args.identityFilter, args.policyType) .accountsStrict({ policyAccount, signer: new web3_js_1.PublicKey(args.authority), payer: args.payer, policyEngine: (0, utils_1.getPolicyEnginePda)(args.assetMint), systemProgram: web3_js_1.SystemProgram.programId, }) .instruction(); return { ixs: [ix], signers: [], }; }); } exports.getCreatePolicyAccountIx = getCreatePolicyAccountIx; function getCreateTrackerAccountIx(args, provider) { return __awaiter(this, void 0, void 0, function* () { const policyProgram = (0, utils_1.getPolicyEngineProgram)(provider); const trackerAccount = (0, utils_1.getTrackerAccountPda)(args.assetMint, args.owner); const ix = yield policyProgram.methods .createTrackerAccount() .accountsStrict({ payer: args.payer, trackerAccount, owner: new web3_js_1.PublicKey(args.owner), systemProgram: web3_js_1.SystemProgram.programId, program: policyProgram.programId, assetMint: new web3_js_1.PublicKey(args.assetMint), eventAuthority: (0, utils_1.getPolicyEnginerEventAuthority)(), }) .instruction(); return ix; }); } exports.getCreateTrackerAccountIx = getCreateTrackerAccountIx; //# sourceMappingURL=instructions.js.map