Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freeze, thaw and revoke ixs #85

Merged
merged 10 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/rwa-token-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bridgesplit/rwa-token-sdk",
"version": "0.0.20",
"version": "0.0.27",
"description": "RWA Token SDK for the development of permissioned tokens on SVM blockchains.",
"homepage": "https://github.com/bridgesplit/rwa-token#readme",
"main": "dist/index",
Expand Down
114 changes: 1 addition & 113 deletions clients/rwa-token-sdk/src/asset-controller/data.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { type AnchorProvider } from "@coral-xyz/anchor";
import { type AssetControllerAccount, type TrackerAccount } from "./types";
import { type AssetControllerAccount } from "./types";
import {
getAssetControllerPda,
getAssetControllerProgram,
getTrackerAccountPda,
} from "./utils";
import { GetProgramAccountsFilter, PublicKey } from "@solana/web3.js";
import { getPolicyAccount, getPolicyEngineAccount, PolicyAccount, PolicyEngineAccount } from "../policy-engine";
import { DataAccount, DataRegistryAccount, getDataAccountsWithFilter, getDataRegistryAccount } from "../data-registry";
import { getIdentityAccount, getIdentityRegistryAccount, IdentityAccount, IdentityRegistryAccount } from "../identity-registry";

/**
* Retrieves a asset controller account associated with a specific asset mint.
Expand Down Expand Up @@ -65,112 +61,4 @@ export async function getAssetControllerAccountsWithFilter(
return assetAccounts.map((account) =>
assetProgram.coder.accounts.decode("AssetControllerAccount", account.account.data)
);
}

/**
* 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.
*/
export async function getTrackerAccount(
assetMint: string,
owner: string,
provider: AnchorProvider
): Promise<TrackerAccount | undefined> {
const assetProgram = getAssetControllerProgram(provider);
const trackerPda = getTrackerAccountPda(assetMint, owner);
return assetProgram.account.trackerAccount
.fetch(trackerPda)
.then((account) => account)
.catch(() => undefined);
}

export const TRACKER_ACCOUNT_ASSET_MINT_OFFSET = 9;
export const TRACKER_ACCOUNT_OWNER_OFFSET = 41;

/**
* Retrieves all tracker accounts associated with a specific asset mint.
* @param assetMint - The string representation of the asset mint.
* @returns A promise resolving to the fetched tracker accounts, or `undefined` if it doesn't exist.
*/
export async function getTrackerAccountsWithFilter(
filter: Omit<AssetControllerDataFilter, "authority" | "delegate">,
provider: AnchorProvider
): Promise<TrackerAccount[] | undefined> {
const { assetMint, owner } = filter;
const assetProgram = getAssetControllerProgram(provider);
const filters: GetProgramAccountsFilter[] = [];
if (assetMint) {
filters.push({ memcmp: { offset: TRACKER_ACCOUNT_ASSET_MINT_OFFSET, bytes: new PublicKey(assetMint).toBase58() } });
}
if (owner) {
filters.push({ memcmp: { offset: TRACKER_ACCOUNT_OWNER_OFFSET, bytes: new PublicKey(owner).toBase58() } });
}
const trackerAccounts = await provider.connection.getProgramAccounts(assetProgram.programId, {
filters,
});
return trackerAccounts.map((account) =>
assetProgram.coder.accounts.decode("TrackerAccount", account.account.data)
);
}

export interface RwaAccounts {
assetMint: string;
assetController?: AssetControllerAccount;
tracker?: TrackerAccount;
policyEngine?: PolicyEngineAccount;
policyAccount?: PolicyAccount;
dataRegistry?: DataRegistryAccount;
dataAccounts?: DataAccount[];
identityRegistry?: IdentityRegistryAccount;
identity?: IdentityAccount;
}


/**
* Retrieves all RWA accounts associated with a specific asset mint.
* @param assetMints - The string representation of the asset mint.
* @returns A promise resolving to the fetched RWA accounts, or `undefined` if it doesn't exist.
*/
export async function getRwaAccountsWithMints(
assetMints: string[],
provider: AnchorProvider,
owner?: string,
): Promise<RwaAccounts[]> {
const accounts: RwaAccounts[] = [];
for (const assetMint of assetMints) {
const assetController = getAssetControllerAccount(assetMint, provider);
const tracker = owner ? getTrackerAccount(assetMint, owner, provider) : undefined;
const policyEngine = getPolicyEngineAccount(assetMint, provider);
const policyAccount = getPolicyAccount(assetMint, provider);
const dataRegistry = getDataRegistryAccount(assetMint, provider);
const dataAccounts = getDataAccountsWithFilter({ assetMint }, provider);
const identityRegistry = getIdentityRegistryAccount(assetMint, provider);
const identity = owner ? getIdentityAccount(assetMint, owner, provider) : undefined;

const [resolvedAssetController, resolvedTracker, resolvedPolicyEngine, resolvedPolicyAccount, resolvedDataRegistry, resolvedDataAccounts, resolvedIdentityRegistry, resolvedIdentity] = await Promise.all([
assetController,
tracker,
policyEngine,
policyAccount,
dataRegistry,
dataAccounts,
identityRegistry,
identity
]);

accounts.push({
assetMint,
assetController: resolvedAssetController,
tracker: resolvedTracker,
policyEngine: resolvedPolicyEngine,
policyAccount: resolvedPolicyAccount,
dataRegistry: resolvedDataRegistry,
dataAccounts: resolvedDataAccounts,
identityRegistry: resolvedIdentityRegistry,
identity: resolvedIdentity,
});
}
return accounts;
}
Loading
Loading