Skip to content

Commit 1ad8702

Browse files
committed
anchor group/member example placeholder, extensions not live
1 parent b2349a6 commit 1ad8702

File tree

11 files changed

+208
-0
lines changed

11 files changed

+208
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.anchor
2+
.DS_Store
3+
target
4+
**/*.rs.bk
5+
node_modules
6+
test-ledger
7+
.yarn
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.anchor
2+
.DS_Store
3+
target
4+
node_modules
5+
dist
6+
build
7+
test-ledger
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[toolchain]
2+
3+
[features]
4+
resolution = true
5+
skip-lint = false
6+
7+
[programs.localnet]
8+
group = "4XCDGMD8fsdjUzmYj6d9if8twFt1f23Ym52iDmWK8fFs"
9+
10+
[registry]
11+
url = "https://api.apr.dev"
12+
13+
[provider]
14+
cluster = "Devnet"
15+
wallet = "~/.config/solana/id.json"
16+
17+
[scripts]
18+
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[workspace]
2+
members = [
3+
"programs/*"
4+
]
5+
resolver = "2"
6+
7+
[profile.release]
8+
overflow-checks = true
9+
lto = "fat"
10+
codegen-units = 1
11+
[profile.release.build-override]
12+
opt-level = 3
13+
incremental = false
14+
codegen-units = 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Migrations are an early feature. Currently, they're nothing more than this
2+
// single deploy script that's invoked from the CLI, injecting a provider
3+
// configured from the workspace's Anchor.toml.
4+
5+
const anchor = require("@coral-xyz/anchor");
6+
7+
module.exports = async function (provider) {
8+
// Configure client to use the provider.
9+
anchor.setProvider(provider);
10+
11+
// Add your deploy script here.
12+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"scripts": {
3+
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
4+
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
5+
},
6+
"dependencies": {
7+
"@coral-xyz/anchor": "^0.30.0"
8+
},
9+
"devDependencies": {
10+
"chai": "^4.3.4",
11+
"mocha": "^9.0.3",
12+
"ts-mocha": "^10.0.0",
13+
"@types/bn.js": "^5.1.0",
14+
"@types/chai": "^4.3.0",
15+
"@types/mocha": "^9.0.0",
16+
"typescript": "^4.3.5",
17+
"prettier": "^2.6.2"
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "group"
3+
version = "0.1.0"
4+
description = "Created with Anchor"
5+
edition = "2021"
6+
7+
[lib]
8+
crate-type = ["cdylib", "lib"]
9+
name = "group"
10+
11+
[features]
12+
default = []
13+
cpi = ["no-entrypoint"]
14+
no-entrypoint = []
15+
no-idl = []
16+
no-log-ix-name = []
17+
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
18+
19+
[dependencies]
20+
anchor-lang = "0.30.0"
21+
anchor-spl = "0.30.0"
22+
spl-token-group-interface = "=0.2.3"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.bpfel-unknown-unknown.dependencies.std]
2+
features = []
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use anchor_lang::prelude::*;
2+
use anchor_spl::token_2022::spl_token_2022::extension::group_pointer::GroupPointer;
3+
use anchor_spl::token_interface::{
4+
spl_token_2022::{
5+
extension::{BaseStateWithExtensions, StateWithExtensions},
6+
state::Mint as MintState,
7+
},
8+
token_group_initialize, Mint, Token2022, TokenGroupInitialize,
9+
};
10+
11+
declare_id!("4XCDGMD8fsdjUzmYj6d9if8twFt1f23Ym52iDmWK8fFs");
12+
13+
#[program]
14+
pub mod group {
15+
16+
use super::*;
17+
18+
pub fn test_initialize_group(ctx: Context<InitializeGroup>) -> Result<()> {
19+
ctx.accounts.check_mint_data()?;
20+
21+
// // Token Group and Token Member extensions features not enabled yet on the Token2022 program
22+
// // This is temporary placeholder to update one extensions are live
23+
// // Initializing the "pointers" works, but you can't initialize the group/member data yet
24+
25+
// let signer_seeds: &[&[&[u8]]] = &[&[b"group", &[ctx.bumps.mint_account]]];
26+
// token_group_initialize(
27+
// CpiContext::new(
28+
// ctx.accounts.token_program.to_account_info(),
29+
// TokenGroupInitialize {
30+
// token_program_id: ctx.accounts.token_program.to_account_info(),
31+
// group: ctx.accounts.mint_account.to_account_info(),
32+
// mint: ctx.accounts.mint_account.to_account_info(),
33+
// mint_authority: ctx.accounts.mint_account.to_account_info(),
34+
// },
35+
// )
36+
// .with_signer(signer_seeds),
37+
// Some(ctx.accounts.payer.key()), // update_authority
38+
// 10, // max_size
39+
// )?;
40+
Ok(())
41+
}
42+
}
43+
44+
#[derive(Accounts)]
45+
pub struct InitializeGroup<'info> {
46+
#[account(mut)]
47+
pub payer: Signer<'info>,
48+
49+
#[account(
50+
init,
51+
seeds = [b"group"],
52+
bump,
53+
payer = payer,
54+
mint::decimals = 2,
55+
mint::authority = mint_account,
56+
mint::freeze_authority = mint_account,
57+
extensions::group_pointer::authority = mint_account,
58+
extensions::group_pointer::group_address = mint_account,
59+
)]
60+
pub mint_account: InterfaceAccount<'info, Mint>,
61+
pub token_program: Program<'info, Token2022>,
62+
pub system_program: Program<'info, System>,
63+
}
64+
65+
impl<'info> InitializeGroup<'info> {
66+
pub fn check_mint_data(&self) -> Result<()> {
67+
let mint = &self.mint_account.to_account_info();
68+
let mint_data = mint.data.borrow();
69+
let mint_with_extension = StateWithExtensions::<MintState>::unpack(&mint_data)?;
70+
let extension_data = mint_with_extension.get_extension::<GroupPointer>()?;
71+
72+
msg!("{:?}", mint_with_extension);
73+
msg!("{:?}", extension_data);
74+
Ok(())
75+
}
76+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as anchor from "@coral-xyz/anchor";
2+
import { Program } from "@coral-xyz/anchor";
3+
import { Group } from "../target/types/group";
4+
5+
describe("group", () => {
6+
// Configure the client to use the local cluster.
7+
const provider = anchor.AnchorProvider.env();
8+
const connection = provider.connection;
9+
const wallet = provider.wallet as anchor.Wallet;
10+
anchor.setProvider(provider);
11+
12+
const program = anchor.workspace.Group as Program<Group>;
13+
14+
it("Create Mint with Group Pointer", async () => {
15+
const transactionSignature = await program.methods
16+
.testInitializeGroup()
17+
.accounts({})
18+
.rpc({ skipPreflight: true });
19+
console.log("Your transaction signature", transactionSignature);
20+
});
21+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"types": ["mocha", "chai"],
4+
"typeRoots": ["./node_modules/@types"],
5+
"lib": ["es2015"],
6+
"module": "commonjs",
7+
"target": "es6",
8+
"esModuleInterop": true
9+
}
10+
}

0 commit comments

Comments
 (0)