Skip to content

Commit 54635cc

Browse files
freeze, thaw and revoke ixs + execute in policy engine (#85)
* add freeze, thaw and revoke * clippy * update testts * fix tests * fix tests * execute in policy engine (#86) * move execute to policy engine * fix tests * fix tests * fix ts build * fix lint * fix tests
1 parent 2533eb8 commit 54635cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2650
-1592
lines changed

clients/rwa-token-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bridgesplit/rwa-token-sdk",
3-
"version": "0.0.20",
3+
"version": "0.0.27",
44
"description": "RWA Token SDK for the development of permissioned tokens on SVM blockchains.",
55
"homepage": "https://github.com/bridgesplit/rwa-token#readme",
66
"main": "dist/index",
Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { type AnchorProvider } from "@coral-xyz/anchor";
2-
import { type AssetControllerAccount, type TrackerAccount } from "./types";
2+
import { type AssetControllerAccount } from "./types";
33
import {
44
getAssetControllerPda,
55
getAssetControllerProgram,
6-
getTrackerAccountPda,
76
} from "./utils";
87
import { GetProgramAccountsFilter, PublicKey } from "@solana/web3.js";
9-
import { getPolicyAccount, getPolicyEngineAccount, PolicyAccount, PolicyEngineAccount } from "../policy-engine";
10-
import { DataAccount, DataRegistryAccount, getDataAccountsWithFilter, getDataRegistryAccount } from "../data-registry";
11-
import { getIdentityAccount, getIdentityRegistryAccount, IdentityAccount, IdentityRegistryAccount } from "../identity-registry";
128

139
/**
1410
* Retrieves a asset controller account associated with a specific asset mint.
@@ -65,112 +61,4 @@ export async function getAssetControllerAccountsWithFilter(
6561
return assetAccounts.map((account) =>
6662
assetProgram.coder.accounts.decode("AssetControllerAccount", account.account.data)
6763
);
68-
}
69-
70-
/**
71-
* Retrieves a tracker account pda associated with a specific asset mint and owner.
72-
* @param assetMint - The string representation of the asset mint.
73-
* @param owner - The string representation of the owner's public key.
74-
* @returns A promise resolving to the fetched tracker account, or `undefined` if it doesn't exist.
75-
*/
76-
export async function getTrackerAccount(
77-
assetMint: string,
78-
owner: string,
79-
provider: AnchorProvider
80-
): Promise<TrackerAccount | undefined> {
81-
const assetProgram = getAssetControllerProgram(provider);
82-
const trackerPda = getTrackerAccountPda(assetMint, owner);
83-
return assetProgram.account.trackerAccount
84-
.fetch(trackerPda)
85-
.then((account) => account)
86-
.catch(() => undefined);
87-
}
88-
89-
export const TRACKER_ACCOUNT_ASSET_MINT_OFFSET = 9;
90-
export const TRACKER_ACCOUNT_OWNER_OFFSET = 41;
91-
92-
/**
93-
* Retrieves all tracker accounts associated with a specific asset mint.
94-
* @param assetMint - The string representation of the asset mint.
95-
* @returns A promise resolving to the fetched tracker accounts, or `undefined` if it doesn't exist.
96-
*/
97-
export async function getTrackerAccountsWithFilter(
98-
filter: Omit<AssetControllerDataFilter, "authority" | "delegate">,
99-
provider: AnchorProvider
100-
): Promise<TrackerAccount[] | undefined> {
101-
const { assetMint, owner } = filter;
102-
const assetProgram = getAssetControllerProgram(provider);
103-
const filters: GetProgramAccountsFilter[] = [];
104-
if (assetMint) {
105-
filters.push({ memcmp: { offset: TRACKER_ACCOUNT_ASSET_MINT_OFFSET, bytes: new PublicKey(assetMint).toBase58() } });
106-
}
107-
if (owner) {
108-
filters.push({ memcmp: { offset: TRACKER_ACCOUNT_OWNER_OFFSET, bytes: new PublicKey(owner).toBase58() } });
109-
}
110-
const trackerAccounts = await provider.connection.getProgramAccounts(assetProgram.programId, {
111-
filters,
112-
});
113-
return trackerAccounts.map((account) =>
114-
assetProgram.coder.accounts.decode("TrackerAccount", account.account.data)
115-
);
116-
}
117-
118-
export interface RwaAccounts {
119-
assetMint: string;
120-
assetController?: AssetControllerAccount;
121-
tracker?: TrackerAccount;
122-
policyEngine?: PolicyEngineAccount;
123-
policyAccount?: PolicyAccount;
124-
dataRegistry?: DataRegistryAccount;
125-
dataAccounts?: DataAccount[];
126-
identityRegistry?: IdentityRegistryAccount;
127-
identity?: IdentityAccount;
128-
}
129-
130-
131-
/**
132-
* Retrieves all RWA accounts associated with a specific asset mint.
133-
* @param assetMints - The string representation of the asset mint.
134-
* @returns A promise resolving to the fetched RWA accounts, or `undefined` if it doesn't exist.
135-
*/
136-
export async function getRwaAccountsWithMints(
137-
assetMints: string[],
138-
provider: AnchorProvider,
139-
owner?: string,
140-
): Promise<RwaAccounts[]> {
141-
const accounts: RwaAccounts[] = [];
142-
for (const assetMint of assetMints) {
143-
const assetController = getAssetControllerAccount(assetMint, provider);
144-
const tracker = owner ? getTrackerAccount(assetMint, owner, provider) : undefined;
145-
const policyEngine = getPolicyEngineAccount(assetMint, provider);
146-
const policyAccount = getPolicyAccount(assetMint, provider);
147-
const dataRegistry = getDataRegistryAccount(assetMint, provider);
148-
const dataAccounts = getDataAccountsWithFilter({ assetMint }, provider);
149-
const identityRegistry = getIdentityRegistryAccount(assetMint, provider);
150-
const identity = owner ? getIdentityAccount(assetMint, owner, provider) : undefined;
151-
152-
const [resolvedAssetController, resolvedTracker, resolvedPolicyEngine, resolvedPolicyAccount, resolvedDataRegistry, resolvedDataAccounts, resolvedIdentityRegistry, resolvedIdentity] = await Promise.all([
153-
assetController,
154-
tracker,
155-
policyEngine,
156-
policyAccount,
157-
dataRegistry,
158-
dataAccounts,
159-
identityRegistry,
160-
identity
161-
]);
162-
163-
accounts.push({
164-
assetMint,
165-
assetController: resolvedAssetController,
166-
tracker: resolvedTracker,
167-
policyEngine: resolvedPolicyEngine,
168-
policyAccount: resolvedPolicyAccount,
169-
dataRegistry: resolvedDataRegistry,
170-
dataAccounts: resolvedDataAccounts,
171-
identityRegistry: resolvedIdentityRegistry,
172-
identity: resolvedIdentity,
173-
});
174-
}
175-
return accounts;
17664
}

0 commit comments

Comments
 (0)