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

add more policies #88

Merged
merged 8 commits into from
Oct 8, 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
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- run: cd clients/rwa-token-sdk && yarn install
- run: cd clients/rwa-token-sdk && yarn lint
- run: solana-keygen new --no-bip39-passphrase
- run: cd programs && cargo fmt -- --check
- run: cd programs && cargo clippy -- -D warnings
- run: cd programs && anchor build
- run: cd programs && anchor test
- run: cargo fmt -- --check
- run: cargo clippy -- -D warnings
- run: anchor build
- run: anchor test
10 changes: 5 additions & 5 deletions programs/Anchor.toml → Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ wallet = "~/.config/solana/id.json"

[workspace]
members = [
"asset_controller",
"data_registry",
"identity_registry",
"policy_engine",
"programs/asset_controller",
"programs/data_registry",
"programs/identity_registry",
"programs/policy_engine",
]

[programs.localnet]
Expand All @@ -23,7 +23,7 @@ identity_registry = "idtynCMYbdisCTv4FrCWPSQboZb1uM4TV2cPi79yxQf"
policy_engine = "po1cPf1eyUJJPqULw4so3T4JU9pdFn83CDyuLEKFAau"

[scripts]
test = "cd ../clients/rwa-token-sdk && yarn test"
test = "cd clients/rwa-token-sdk && yarn test"

[test.validator]
url = "https://api.mainnet-beta.solana.com"
Expand Down
File renamed without changes.
27 changes: 27 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[workspace]
members = [
"programs/asset_controller",
"programs/data_registry",
"programs/identity_registry",
"programs/policy_engine",
"rwa_utils"
]
resolver = "2"

[profile.dev]
overflow-checks = true

[profile.release]
overflow-checks = true
lto = "fat"
codegen-units = 1

[profile.release.build-override]
opt-level = 3
incremental = false
codegen-units = 1

[workspace.dependencies]
anchor-lang = { git = "https://github.com/bridgesplit/anchor" }
anchor-spl = { git = "https://github.com/bridgesplit/anchor" }
rwa_utils = { path = "./rwa_utils" }
6 changes: 3 additions & 3 deletions 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.27",
"version": "0.0.31",
"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 Expand Up @@ -44,8 +44,8 @@
"author": "Standard Labs, Inc.",
"contributors": [
"Luke Truitt <[email protected]>",
"Bhargava Sai Macha <bhargava@bridgesplit.com>",
"Chris Hagedorn <chris@bridgesplit.com>"
"Bhargava Sai Macha <bhargava@loopscale.com>",
"Chris Hagedorn <chris@loopscale.com>"
],
"license": "MIT"
}
36 changes: 33 additions & 3 deletions clients/rwa-token-sdk/src/asset-controller/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getCreateIdentityAccountIx,
getIdentityAccountPda,
getIdentityRegistryPda,
getAddLevelToIdentityAccount,
} from "../identity-registry";
import {
type CommonArgs,
Expand Down Expand Up @@ -264,6 +265,11 @@ export async function getTransferTokensIxs(
isWritable: false,
isSigner: false,
},
{
pubkey: getIdentityAccountPda(args.assetMint, args.from),
isWritable: false,
isSigner: false,
}
];

const ixs: TransactionInstruction[] = [];
Expand Down Expand Up @@ -368,7 +374,7 @@ export type SetupUserArgs = {
owner: string;
signer: string;
assetMint: string;
level: number;
levels: number[];
};

/**
Expand All @@ -382,16 +388,34 @@ export async function getSetupUserIxs(
args: SetupUserArgs,
provider: AnchorProvider
): Promise<IxReturn> {
const ixs: TransactionInstruction[] = [];
const identityAccountIx = await getCreateIdentityAccountIx(
{
payer: args.payer,
signer: args.signer,
assetMint: args.assetMint,
owner: args.owner,
level: args.level,
level: args.levels[0],
},
provider
);
ixs.push(identityAccountIx);
if (args.levels.length > 1) {
for (let i = 1; i < args.levels.length; i++) {
const addLevelIx = await getAddLevelToIdentityAccount(
{
authority: args.signer,
owner: args.owner,
assetMint: args.assetMint,
level: args.levels[i],
signer: args.signer,
payer: args.payer,
},
provider
);
ixs.push(addLevelIx);
}
}
const trackerAccountIx = await getCreateTrackerAccountIx(
{
payer: args.payer,
Expand All @@ -400,8 +424,9 @@ export async function getSetupUserIxs(
},
provider
);
ixs.push(trackerAccountIx);
return {
ixs: [identityAccountIx, trackerAccountIx],
ixs,
signers: [],
};
}
Expand Down Expand Up @@ -641,6 +666,11 @@ export async function getRevokeTokensIx(
isWritable: false,
isSigner: false,
},
{
pubkey: getIdentityAccountPda(args.assetMint, args.owner),
isWritable: false,
isSigner: false,
}
];
const ixs: TransactionInstruction[] = [];
const ix = await assetProgram.methods
Expand Down
4 changes: 4 additions & 0 deletions clients/rwa-token-sdk/src/identity-registry/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getIdentityAccountPda,
getIdentityRegistryProgram,
getIdentityRegistryPda,
getIdentityMetadataPda,
} from "./utils";
import { type AnchorProvider } from "@coral-xyz/anchor";

Expand Down Expand Up @@ -66,6 +67,7 @@ export async function getCreateIdentityAccountIx(
identityRegistry: getIdentityRegistryPda(args.assetMint),
identityAccount: getIdentityAccountPda(args.assetMint, args.owner),
systemProgram: SystemProgram.programId,
identityMetadataAccount: getIdentityMetadataPda(args.assetMint, args.level),
signer: args.signer
? args.signer
: getIdentityRegistryPda(args.assetMint),
Expand Down Expand Up @@ -97,6 +99,7 @@ export async function getAddLevelToIdentityAccount(
signer: args.signer,
identityRegistry: getIdentityRegistryPda(args.assetMint),
identityAccount: getIdentityAccountPda(args.assetMint, args.owner),
identityMetadataAccount: getIdentityMetadataPda(args.assetMint, args.level),
payer: args.payer,
systemProgram: SystemProgram.programId,
})
Expand Down Expand Up @@ -128,6 +131,7 @@ export async function getRemoveLevelFromIdentityAccount(
: getIdentityRegistryPda(args.assetMint),
identityRegistry: getIdentityRegistryPda(args.assetMint),
identityAccount: getIdentityAccountPda(args.assetMint, args.owner),
identityMetadataAccount: getIdentityMetadataPda(args.assetMint, args.level),
payer: args.signer,
systemProgram: SystemProgram.programId,
})
Expand Down
12 changes: 12 additions & 0 deletions clients/rwa-token-sdk/src/identity-registry/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@ export const getIdentityAccountPda = (assetMint: string, owner: string) => Publi
identityRegistryProgramId,
)[0];


/**
* Retrieves the identity metadata account pda public key for a specific asset mint.
* @param assetMint - The string representation of the asset's mint address.
* @param level - The level of the identity account.
* @returns The identity metadata pda.
*/
export const getIdentityMetadataPda = (assetMint: string, level: number) => PublicKey.findProgramAddressSync(
[Buffer.from([level]), getIdentityRegistryPda(assetMint).toBuffer()],
identityRegistryProgramId,
)[0];

export const POLICY_SKIP_LEVEL = 255;
4 changes: 3 additions & 1 deletion clients/rwa-token-sdk/src/policy-engine/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@solana/web3.js";
import { type CommonArgs, type IxReturn } from "../utils";
import {
getExtraMetasListPda,
getPolicyAccountPda,
getPolicyEnginePda,
getPolicyEngineProgram,
Expand Down Expand Up @@ -39,7 +40,8 @@ export async function getCreatePolicyEngineIx(
payer: args.payer,
signer: args.signer,
assetMint: args.assetMint,
policyEngine: getPolicyEnginePda(args.assetMint),
policyEngineAccount: getPolicyEnginePda(args.assetMint),
extraMetasAccount: getExtraMetasListPda(args.assetMint),
systemProgram: SystemProgram.programId,
})
.instruction();
Expand Down
1 change: 1 addition & 0 deletions clients/rwa-token-sdk/src/programs/idls/DataRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"accounts": [
{
"name": "signer",
"writable": true,
"signer": true
},
{
Expand Down
Loading
Loading