Skip to content

Commit 1f3cfce

Browse files
Merge pull request #74 from bridgesplit/staging
Staging
2 parents b529d07 + db6aac1 commit 1f3cfce

File tree

25 files changed

+793
-12
lines changed

25 files changed

+793
-12
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ on:
55
pull_request:
66
branches:
77
- 'staging'
8+
89
jobs:
910
setup-tests:
1011
runs-on: ubicloud-standard-16
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
1115
steps:
1216
- id: cache-cli-deps
1317
uses: actions/cache@v2

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.4",
3+
"version": "0.0.15",
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",

clients/rwa-token-sdk/src/asset-controller/instructions.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
getExtraMetasListPda,
3838
getTrackerAccountPda,
3939
assetControllerProgramId,
40+
getAssetControllerEventAuthority,
4041
} from "./utils";
4142
import { type AnchorProvider, BN } from "@coral-xyz/anchor";
4243

@@ -75,11 +76,52 @@ export async function getCreateAssetControllerIx(
7576
systemProgram: SystemProgram.programId,
7677
tokenProgram: TOKEN_2022_PROGRAM_ID,
7778
authority: args.authority,
79+
eventAuthority: getAssetControllerEventAuthority(),
80+
program: assetControllerProgramId,
7881
})
7982
.instruction();
8083
return ix;
8184
}
8285

86+
/** Represents arguments for update an on chain asset metadata. */
87+
export type UpdateAssetMetadataArgs = {
88+
authority: string;
89+
name?: string;
90+
uri?: string;
91+
symbol?: string;
92+
} & CommonArgs;
93+
94+
/**
95+
* Builds the transaction instruction to create an Asset Controller.
96+
* @param args - {@link UpdateAssetMetadataArgs}
97+
* @returns Create asset controller transaction instruction
98+
*/
99+
export async function getUpdateAssetMetadataIx(
100+
args: UpdateAssetMetadataArgs,
101+
provider: AnchorProvider
102+
): Promise<TransactionInstruction> {
103+
const assetProgram = getAssetControllerProgram(provider);
104+
const ix = await assetProgram.methods
105+
.updateMetadata({
106+
name: args.name || null,
107+
uri: args.uri || null,
108+
symbol: args.symbol || null,
109+
})
110+
.accountsStrict({
111+
payer: args.payer,
112+
assetMint: args.assetMint,
113+
assetController: getAssetControllerPda(args.assetMint),
114+
tokenProgram: TOKEN_2022_PROGRAM_ID,
115+
authority: args.authority,
116+
eventAuthority: getAssetControllerEventAuthority(),
117+
systemProgram: SystemProgram.programId,
118+
program: assetControllerProgramId,
119+
})
120+
.instruction();
121+
return ix;
122+
}
123+
124+
83125
/** Represents arguments for issuing an on chain asset/token. */
84126
export type IssueTokenArgs = {
85127
amount: number;
@@ -311,6 +353,7 @@ export async function getSetupAssetControllerIxs(
311353
updatedArgs,
312354
provider
313355
);
356+
314357
return {
315358
ixs: [
316359
assetControllerCreateIx,

clients/rwa-token-sdk/src/asset-controller/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PublicKey } from "@solana/web3.js";
2-
import { type Idl, Program, type Provider } from "@coral-xyz/anchor";
2+
import { type Idl, Program, type Provider, utils } from "@coral-xyz/anchor";
33
import { AssetControllerIdl, AssetControllerIdlTypes } from "../programs";
44
import { utf8 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
55

@@ -48,3 +48,8 @@ export const getTrackerAccountPda = (assetMint: string, owner: string) =>
4848
[new PublicKey(assetMint).toBuffer(), new PublicKey(owner).toBuffer()],
4949
assetControllerProgramId
5050
)[0];
51+
52+
export const getAssetControllerEventAuthority = () => PublicKey.findProgramAddressSync(
53+
[utils.bytes.utf8.encode("__event_authority")],
54+
assetControllerProgramId
55+
)[0];

clients/rwa-token-sdk/src/classes/AssetController.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
getAssetControllerPda,
1212
getTrackerAccountPda,
1313
getExtraMetasListPda,
14+
getUpdateAssetMetadataIx,
15+
UpdateAssetMetadataArgs,
1416
} from "../asset-controller";
1517
import { type IxReturn } from "../utils";
1618
import { type RwaClient } from "./Client";
@@ -41,6 +43,21 @@ export class AssetController {
4143
return setupControllerIx;
4244
}
4345

46+
/**
47+
* Update the asset controller's metadata.
48+
* @param - {@link UpdateAssetMetadataArgs}
49+
* @returns A Promise that resolves to the instructions to update the asset controller's metadata.
50+
* */
51+
async updateAssetMetadata(
52+
updateAssetControllerArgs: UpdateAssetMetadataArgs
53+
): Promise<TransactionInstruction> {
54+
const updateMetadataIx = await getUpdateAssetMetadataIx(
55+
updateAssetControllerArgs,
56+
this.rwaClient.provider
57+
);
58+
return updateMetadataIx;
59+
}
60+
4461
/**
4562
* Asynchronously generates instructions to issue tokens.
4663
* @param - {@link IssueTokenArgs}

clients/rwa-token-sdk/src/classes/DataRegistry.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
getDelegateDataRegistryIx,
99
getUpdateDataAccountIx,
1010
getDataRegistryPda,
11+
DeleteDataAccountArgs,
12+
getDeleteDataAccountIx,
1113
} from "../data-registry";
1214
import { type RwaClient } from "./Client";
1315

@@ -49,6 +51,20 @@ export class DataRegistry {
4951
return updateIx;
5052
}
5153

54+
/**
55+
* Asynchronously generates instructions to delete asset information.
56+
* @returns A Promise that resolves to the instructions to delete asset information.
57+
*/
58+
async deleteAssetsDataAccountInfoIxns(
59+
deleteArgs: DeleteDataAccountArgs
60+
): Promise<TransactionInstruction> {
61+
const deleteIx = await getDeleteDataAccountIx(
62+
deleteArgs,
63+
this.rwaClient.provider
64+
);
65+
return deleteIx;
66+
}
67+
5268
/**
5369
* Asynchronously generates instructions to update asset information.
5470
* @returns A Promise that resolves to the instructions to update asset information.

clients/rwa-token-sdk/src/data-registry/instructions.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,27 @@ export async function getUpdateDataAccountIx(
102102
return ix;
103103
}
104104

105+
export type DeleteDataAccountArgs = {
106+
signer: string;
107+
dataAccount: string;
108+
} & CommonArgs;
109+
110+
export async function getDeleteDataAccountIx(
111+
args: DeleteDataAccountArgs,
112+
provider: AnchorProvider
113+
): Promise<TransactionInstruction> {
114+
const dataProgram = getDataRegistryProgram(provider);
115+
const ix = await dataProgram.methods
116+
.deleteDataAccount()
117+
.accountsStrict({
118+
signer: args.signer,
119+
dataAccount: args.dataAccount,
120+
dataRegistry: getDataRegistryPda(args.assetMint),
121+
})
122+
.instruction();
123+
return ix;
124+
}
125+
105126
export type DelegateDataRegistryArgs = {
106127
delegate: string;
107128
authority: string;

clients/rwa-token-sdk/src/identity-registry/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ export const getIdentityAccountPda = (assetMint: string, owner: string) => Publi
3131
[getIdentityRegistryPda(assetMint).toBuffer(), new PublicKey(owner).toBuffer()],
3232
identityRegistryProgramId,
3333
)[0];
34+
35+
export const POLICY_SKIP_LEVEL = 255;

0 commit comments

Comments
 (0)