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

Use self-CPI for logging #84

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@metaplex-foundation/umi": "^0.8.2",
"@metaplex-foundation/umi-bundle-tests": "^0.8.2",
"@metaplex-foundation/umi-web3js-adapters": "^0.8.2",
"@project-serum/anchor": "^0.26.0",
"@coral-xyz/anchor": "^0.29.0",
"@solana/spl-token": "^0.3.5",
"@solana/web3.js": "^1.65.0",
"borsh": "^0.7.0",
Expand Down
108 changes: 78 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/mmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default = []
anchor-test = []

[dependencies]
anchor-lang = { version = "0.29.0", features = ["init-if-needed"] }
anchor-lang = { version = "0.29.0", features = ["init-if-needed", "event-cpi"] }
anchor-spl = "0.29.0"
community-managed-token = { version = "0.3.0", features = ["no-entrypoint"] }
mpl-token-metadata = { version = "4.0.0" }
Expand Down
2 changes: 0 additions & 2 deletions programs/mmm/src/ata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ pub fn init_if_needed_ata<'a>(
associated_token: AccountInfo<'a>,
token_program: AccountInfo<'a>,
system_program: AccountInfo<'a>,
rent: AccountInfo<'a>,
) -> Result<spl_token_2022::state::Account> {
let token_program_id = token_program.key();

Expand All @@ -87,7 +86,6 @@ pub fn init_if_needed_ata<'a>(
mint.to_account_info(),
associated_token,
system_program,
rent,
token_program,
],
)?;
Expand Down
8 changes: 7 additions & 1 deletion programs/mmm/src/instructions/admin/create_pool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::pool_event::PoolEvent;

use super::*;

#[derive(AnchorSerialize, AnchorDeserialize)]
Expand All @@ -20,6 +22,7 @@ pub struct CreatePoolArgs {
pub allowlists: [Allowlist; ALLOWLIST_MAX_LEN],
}

#[event_cpi]
#[derive(Accounts)]
#[instruction(args:CreatePoolArgs)]
pub struct CreatePool<'info> {
Expand Down Expand Up @@ -75,7 +78,10 @@ pub fn handler(ctx: Context<CreatePool>, args: CreatePoolArgs) -> Result<()> {
pool.payment_mint = args.payment_mint;
pool.allowlists = args.allowlists;

log_pool("post_create_pool", pool)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might have some indexing depends on this logging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct. The idea behind this PR is to change the way logging happens to avoid truncated logs causing misses on indexing, but it requires updating the indexing parser to handle the new logging method. So the indexing changes should be implemented before this PR is merged. @madergaser knows what needs to happen on this.

emit_cpi!(PoolEvent {
prefix: "post_create_pool".to_string(),
pool_state: pool.to_account_info().try_borrow_data()?.to_vec(),
});

Ok(())
}
9 changes: 8 additions & 1 deletion programs/mmm/src/instructions/admin/set_shared_escrow.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::pool_event::PoolEvent;

use super::*;

#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct SetSharedEscrowArgs {
pub shared_escrow_count: u64,
}

#[event_cpi]
#[derive(Accounts)]
#[instruction(args:SetSharedEscrowArgs)]
pub struct SetSharedEscrow<'info> {
Expand Down Expand Up @@ -53,7 +56,11 @@ pub fn handler(ctx: Context<SetSharedEscrow>, args: SetSharedEscrowArgs) -> Resu

pool.shared_escrow_account = ctx.accounts.shared_escrow_account.key();
pool.shared_escrow_count = args.shared_escrow_count;
log_pool("post_set_shared_escrow", pool)?;

emit_cpi!(PoolEvent {
prefix: "post_set_shared_escrow".to_string(),
pool_state: pool.to_account_info().try_borrow_data()?.to_vec(),
});

Ok(())
}
Loading
Loading