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 1 commit
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.24",
"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
127 changes: 124 additions & 3 deletions clients/rwa-token-sdk/src/asset-controller/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export type IssueTokenArgs = {
amount: number;
authority: string;
owner: string;
createTa?: boolean;
} & CommonArgs;

/**
Expand All @@ -142,8 +143,26 @@ export type IssueTokenArgs = {
export async function getIssueTokensIx(
args: IssueTokenArgs,
provider: AnchorProvider
): Promise<TransactionInstruction> {
): Promise<TransactionInstruction[]> {
const assetProgram = getAssetControllerProgram(provider);
const ixs: TransactionInstruction[] = [];
try {
await getAccount(provider.connection, getAssociatedTokenAddressSync(
new PublicKey(args.assetMint),
new PublicKey(args.owner),
true,
TOKEN_2022_PROGRAM_ID
), undefined, TOKEN_2022_PROGRAM_ID);
} catch (error) {
if (args.createTa) {
ixs.push(createAssociatedTokenAccountInstruction(new PublicKey(args.payer), getAssociatedTokenAddressSync(
new PublicKey(args.assetMint),
new PublicKey(args.owner),
true,
TOKEN_2022_PROGRAM_ID
), new PublicKey(args.owner), new PublicKey(args.assetMint), TOKEN_2022_PROGRAM_ID));
}
}
const ix = await assetProgram.methods
.issueTokens({
amount: new BN(args.amount),
Expand All @@ -161,7 +180,8 @@ export async function getIssueTokensIx(
),
})
.instruction();
return ix;
ixs.push(ix);
return ixs;
}

export type VoidTokensArgs = {
Expand All @@ -176,7 +196,7 @@ export async function getVoidTokensIx(
const assetProgram = getAssetControllerProgram(provider);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const ix = await assetProgram.methods
.voidTokens(new BN(args.amount))
.burnTokens(new BN(args.amount))
.accountsStrict({
assetMint: new PublicKey(args.assetMint),
tokenProgram: TOKEN_2022_PROGRAM_ID,
Expand Down Expand Up @@ -529,4 +549,105 @@ export async function getCloseMintIx(
})
.instruction();
return ix;
}

export type FreezeTokenArgs = {
authority: string;
owner: string;
} & CommonArgs;

/**
* Generate Instructions to freeze token account
* @param args - {@link FreezeTokenArgs}
* @returns - {@link TransactionInstruction}
*/
export async function getFreezeTokenIx(
args: FreezeTokenArgs,
provider: AnchorProvider
): Promise<TransactionInstruction> {
const assetProgram = getAssetControllerProgram(provider);
const ix = await assetProgram.methods
.freezeTokenAccount()
.accountsStrict({
authority: new PublicKey(args.authority),
assetMint: new PublicKey(args.assetMint),
tokenProgram: TOKEN_2022_PROGRAM_ID,
assetController: getAssetControllerPda(args.assetMint),
tokenAccount: getAssociatedTokenAddressSync(
new PublicKey(args.assetMint),
new PublicKey(args.owner),
false,
TOKEN_2022_PROGRAM_ID
),
})
.instruction();
return ix;
}

/**
* Generate Instructions to thaw token account
* @param args - {@link FreezeTokenArgs}
* @returns - {@link TransactionInstruction}
* */
export async function getThawTokenIx(
args: FreezeTokenArgs,
provider: AnchorProvider
): Promise<TransactionInstruction> {
const assetProgram = getAssetControllerProgram(provider);
const ix = await assetProgram.methods
.thawTokenAccount()
.accountsStrict({
authority: new PublicKey(args.authority),
assetMint: new PublicKey(args.assetMint),
tokenProgram: TOKEN_2022_PROGRAM_ID,
assetController: getAssetControllerPda(args.assetMint),
tokenAccount: getAssociatedTokenAddressSync(
new PublicKey(args.assetMint),
new PublicKey(args.owner),
false,
TOKEN_2022_PROGRAM_ID
),
})
.instruction();
return ix;
}

export type RevokeTokensArgs = {
amount: number;
owner: string;
authority: string;
} & CommonArgs;

/**
* Revoke tokens from a user
* @param args - {@link RevokeTokensArgs}
* @returns - {@link TransactionInstruction}
* */
export async function getRevokeTokensIx(
args: RevokeTokensArgs,
provider: AnchorProvider
): Promise<TransactionInstruction> {
const assetProgram = getAssetControllerProgram(provider);
const ix = await assetProgram.methods
.revokeTokens(new BN(args.amount))
.accountsStrict({
authority: new PublicKey(args.authority),
assetMint: new PublicKey(args.assetMint),
tokenProgram: TOKEN_2022_PROGRAM_ID,
assetController: getAssetControllerPda(args.assetMint),
revokeTokenAccount: getAssociatedTokenAddressSync(
new PublicKey(args.assetMint),
new PublicKey(args.owner),
false,
TOKEN_2022_PROGRAM_ID
),
authorityTokenAccount: getAssociatedTokenAddressSync(
new PublicKey(args.assetMint),
new PublicKey(args.authority),
false,
TOKEN_2022_PROGRAM_ID
),
})
.instruction();
return ix;
}
6 changes: 3 additions & 3 deletions clients/rwa-token-sdk/src/classes/AssetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export class AssetController {
*/
async issueTokenIxns(
IssueArgs: IssueTokenArgs
): Promise<TransactionInstruction> {
const issueTokensIx = await getIssueTokensIx(
): Promise<TransactionInstruction[]> {
const issueTokensIxs = await getIssueTokensIx(
IssueArgs,
this.rwaClient.provider
);
return issueTokensIx;
return issueTokensIxs;
}

/**
Expand Down
Loading
Loading