From 3ddccdf84cf929eca0012fa2faa651557f991439 Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:19:47 -0800 Subject: [PATCH 1/9] feat(codama): migrate IDL transforms to codama-rs attributes - Replace appendPdaDerivers with #[codama(seed)] on account structs - Replace appendAccountDiscriminator with #[codama(discriminator)] attributes - Replace setInstructionAccountDefaultValues with ata() shorthand - Replace updateInstructionBumps with account_bump() defaults - Replace removeEmitInstruction with #[codama(skip)] on EmitEvent - Add EventAuthority standalone CodamaPda struct - Bump codama dep to git branch feat/instruction-attributes --- Cargo.lock | 33 +- Cargo.toml | 2 +- idl/escrow_program.json | 965 ++++++++++++++++++++++++- program/src/instructions/definition.rs | 276 +++++-- program/src/state/allowed_mint.rs | 5 + program/src/state/escrow.rs | 4 + program/src/state/escrow_extensions.rs | 5 + program/src/state/event_authority.rs | 7 + program/src/state/mod.rs | 2 + program/src/state/receipt.rs | 7 + scripts/generate-clients.ts | 8 +- 11 files changed, 1200 insertions(+), 114 deletions(-) create mode 100644 program/src/state/event_authority.rs diff --git a/Cargo.lock b/Cargo.lock index 877a9a5..d1a0fac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -791,8 +791,7 @@ dependencies = [ [[package]] name = "codama" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bf2f908673e3177aa1c6546b61fac36874efba6754ffa2b6082f676bd8fa3e0" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "codama-errors", "codama-korok-plugins", @@ -807,8 +806,7 @@ dependencies = [ [[package]] name = "codama-attributes" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce088c3f23ad6a6f9b69da81751c87212da2c2195f1b3e391619c3b626473c25" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "codama-errors", "codama-nodes", @@ -822,8 +820,7 @@ dependencies = [ [[package]] name = "codama-errors" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6485d98de3a1cfd25975cc5afca9c8e03da3ae85c0e4ef1ad818579f7fdc640a" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "cargo_toml", "proc-macro2", @@ -835,8 +832,7 @@ dependencies = [ [[package]] name = "codama-korok-plugins" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07c0899cf03caae88577f4423bebb84659778fca4db1caf4f9dd777ac16f8406" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "codama-errors", "codama-korok-visitors", @@ -846,8 +842,7 @@ dependencies = [ [[package]] name = "codama-korok-visitors" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b3b1d119c0b247a4746f963bb05e7470d7a3729da8f4040144eea4745e73ac1" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "cargo_toml", "codama-attributes", @@ -862,8 +857,7 @@ dependencies = [ [[package]] name = "codama-koroks" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb43f91eef59c2e4ca8b7c9f54026a5f43f6f3b3c0505ed77be1abd900525ce" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "codama-attributes", "codama-errors", @@ -878,8 +872,7 @@ dependencies = [ [[package]] name = "codama-macros" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f20101421d0bc92133bdfb99be7585196e6313c8665bbdb5830701ab7ca85ee" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "codama-attributes", "codama-errors", @@ -893,8 +886,7 @@ dependencies = [ [[package]] name = "codama-nodes" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b4a10746031fb835ee90b0f1d67844de91e938d93df6167129325bb886a5da" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "codama-errors", "codama-nodes-derive", @@ -906,8 +898,7 @@ dependencies = [ [[package]] name = "codama-nodes-derive" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e195f4c7b6a93180a3eb59ba53016d4ea4bbef212f78fa6a04835fe244cb3da1" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "codama-errors", "codama-syn-helpers", @@ -920,8 +911,7 @@ dependencies = [ [[package]] name = "codama-stores" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56bd0a298e94a566dbd3451d1613ba1f7290bfbaa38e66b8ebd0d3688824bd59" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "cargo_toml", "codama-errors", @@ -932,8 +922,7 @@ dependencies = [ [[package]] name = "codama-syn-helpers" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dd908283642bba89c720b5f58d43746e7a3506a960b90357ce64e160381374" +source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" dependencies = [ "codama-errors", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index 4c040f9..252ceb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [ ] } [workspace.dependencies] -codama = "^0.7.2" +codama = { git = "https://github.com/amilz/codama-rs", branch = "feat/instruction-attributes" } serde_json = "^1.0.145" const-crypto = "^0.3.0" pinocchio = "^0.10.1" diff --git a/idl/escrow_program.json b/idl/escrow_program.json index 6a8a79e..c78017d 100644 --- a/idl/escrow_program.json +++ b/idl/escrow_program.json @@ -6,6 +6,19 @@ { "data": { "fields": [ + { + "defaultValue": { + "kind": "numberValueNode", + "number": 3 + }, + "kind": "structFieldTypeNode", + "name": "discriminator", + "type": { + "endian": "le", + "format": "u8", + "kind": "numberTypeNode" + } + }, { "kind": "structFieldTypeNode", "name": "bump", @@ -18,12 +31,36 @@ ], "kind": "structTypeNode" }, + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], "kind": "accountNode", - "name": "allowedMint" + "name": "allowedMint", + "pda": { + "kind": "pdaLinkNode", + "name": "allowedMint" + } }, { "data": { "fields": [ + { + "defaultValue": { + "kind": "numberValueNode", + "number": 0 + }, + "kind": "structFieldTypeNode", + "name": "discriminator", + "type": { + "endian": "le", + "format": "u8", + "kind": "numberTypeNode" + } + }, { "kind": "structFieldTypeNode", "name": "bump", @@ -50,12 +87,36 @@ ], "kind": "structTypeNode" }, + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], "kind": "accountNode", - "name": "escrow" + "name": "escrow", + "pda": { + "kind": "pdaLinkNode", + "name": "escrow" + } }, { "data": { "fields": [ + { + "defaultValue": { + "kind": "numberValueNode", + "number": 1 + }, + "kind": "structFieldTypeNode", + "name": "discriminator", + "type": { + "endian": "le", + "format": "u8", + "kind": "numberTypeNode" + } + }, { "kind": "structFieldTypeNode", "name": "bump", @@ -77,12 +138,36 @@ ], "kind": "structTypeNode" }, + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], "kind": "accountNode", - "name": "escrowExtensionsHeader" + "name": "escrowExtensionsHeader", + "pda": { + "kind": "pdaLinkNode", + "name": "extensions" + } }, { "data": { "fields": [ + { + "defaultValue": { + "kind": "numberValueNode", + "number": 2 + }, + "kind": "structFieldTypeNode", + "name": "discriminator", + "type": { + "endian": "le", + "format": "u8", + "kind": "numberTypeNode" + } + }, { "kind": "structFieldTypeNode", "name": "bump", @@ -157,8 +242,19 @@ ], "kind": "structTypeNode" }, + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], "kind": "accountNode", - "name": "receipt" + "name": "receipt", + "pda": { + "kind": "pdaLinkNode", + "name": "receipt" + } } ], "definedTypes": [ @@ -573,6 +669,23 @@ "name": "escrowSeed" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "escrow" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrowSeed", + "value": { + "kind": "accountValueNode", + "name": "escrowSeed" + } + } + ] + }, "docs": [ "Escrow PDA account to be created" ], @@ -582,6 +695,10 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "11111111111111111111111111111111" + }, "docs": [ "System program" ], @@ -591,6 +708,10 @@ "name": "systemProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -600,6 +721,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -625,6 +750,10 @@ } }, { + "defaultValue": { + "kind": "accountBumpValueNode", + "name": "escrow" + }, "kind": "instructionArgumentNode", "name": "bump", "type": { @@ -674,6 +803,23 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "extensions" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + } + ] + }, "docs": [ "Extensions PDA account to store timelock config" ], @@ -683,6 +829,10 @@ "name": "extensions" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "11111111111111111111111111111111" + }, "docs": [ "System program" ], @@ -692,6 +842,10 @@ "name": "systemProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -701,6 +855,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -726,6 +884,10 @@ } }, { + "defaultValue": { + "kind": "accountBumpValueNode", + "name": "extensions" + }, "kind": "instructionArgumentNode", "name": "extensionsBump", "type": { @@ -784,6 +946,23 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "extensions" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + } + ] + }, "docs": [ "Extensions PDA account to store hook config" ], @@ -793,6 +972,10 @@ "name": "extensions" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "11111111111111111111111111111111" + }, "docs": [ "System program" ], @@ -802,6 +985,10 @@ "name": "systemProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -811,6 +998,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -836,6 +1027,10 @@ } }, { + "defaultValue": { + "kind": "accountBumpValueNode", + "name": "extensions" + }, "kind": "instructionArgumentNode", "name": "extensionsBump", "type": { @@ -892,6 +1087,31 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "allowedMint" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + } + ] + }, "docs": [ "Allowed mint PDA proving this mint is permitted" ], @@ -910,6 +1130,47 @@ "name": "receiptSeed" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "receipt" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "depositor", + "value": { + "kind": "accountValueNode", + "name": "depositor" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "receiptSeed", + "value": { + "kind": "accountValueNode", + "name": "receiptSeed" + } + } + ] + }, "docs": [ "Deposit receipt PDA to be created" ], @@ -919,6 +1180,63 @@ "name": "receipt" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaNode", + "name": "associatedTokenAccount", + "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + "seeds": [ + { + "kind": "variablePdaSeedNode", + "name": "owner", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "tokenProgram", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "mint", + "type": { + "kind": "publicKeyTypeNode" + } + } + ] + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "owner", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "tokenProgram", + "value": { + "kind": "accountValueNode", + "name": "tokenProgram" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + } + ] + }, "docs": [ "Escrow vault token account to receive tokens" ], @@ -928,6 +1246,63 @@ "name": "vault" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaNode", + "name": "associatedTokenAccount", + "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + "seeds": [ + { + "kind": "variablePdaSeedNode", + "name": "owner", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "tokenProgram", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "mint", + "type": { + "kind": "publicKeyTypeNode" + } + } + ] + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "owner", + "value": { + "kind": "accountValueNode", + "name": "depositor" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "tokenProgram", + "value": { + "kind": "accountValueNode", + "name": "tokenProgram" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + } + ] + }, "docs": [ "Depositor's token account to transfer from" ], @@ -946,6 +1321,10 @@ "name": "mint" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, "docs": [ "SPL Token program" ], @@ -955,6 +1334,10 @@ "name": "tokenProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "11111111111111111111111111111111" + }, "docs": [ "System program" ], @@ -964,6 +1347,10 @@ "name": "systemProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -973,6 +1360,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -982,6 +1373,23 @@ "name": "escrowProgram" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "extensions" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + } + ] + }, "docs": [ "Extensions PDA for escrow configuration" ], @@ -1007,6 +1415,10 @@ } }, { + "defaultValue": { + "kind": "accountBumpValueNode", + "name": "receipt" + }, "kind": "instructionArgumentNode", "name": "bump", "type": { @@ -1065,6 +1477,10 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -1074,6 +1490,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -1139,6 +1559,23 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "extensions" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + } + ] + }, "docs": [ "Extensions PDA for escrow configuration" ], @@ -1157,6 +1594,63 @@ "name": "receipt" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaNode", + "name": "associatedTokenAccount", + "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + "seeds": [ + { + "kind": "variablePdaSeedNode", + "name": "owner", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "tokenProgram", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "mint", + "type": { + "kind": "publicKeyTypeNode" + } + } + ] + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "owner", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "tokenProgram", + "value": { + "kind": "accountValueNode", + "name": "tokenProgram" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + } + ] + }, "docs": [ "Escrow vault token account to transfer from" ], @@ -1166,6 +1660,63 @@ "name": "vault" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaNode", + "name": "associatedTokenAccount", + "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + "seeds": [ + { + "kind": "variablePdaSeedNode", + "name": "owner", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "tokenProgram", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "mint", + "type": { + "kind": "publicKeyTypeNode" + } + } + ] + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "owner", + "value": { + "kind": "accountValueNode", + "name": "withdrawer" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "tokenProgram", + "value": { + "kind": "accountValueNode", + "name": "tokenProgram" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + } + ] + }, "docs": [ "Withdrawer's token account to receive tokens" ], @@ -1184,6 +1735,10 @@ "name": "mint" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, "docs": [ "SPL Token program" ], @@ -1193,6 +1748,10 @@ "name": "tokenProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "11111111111111111111111111111111" + }, "docs": [ "System program" ], @@ -1202,6 +1761,10 @@ "name": "systemProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -1211,6 +1774,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -1276,6 +1843,23 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "extensions" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + } + ] + }, "docs": [ "Extensions PDA for escrow configuration" ], @@ -1294,6 +1878,31 @@ "name": "mint" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "allowedMint" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + } + ] + }, "docs": [ "Allowed mint PDA to be created" ], @@ -1303,6 +1912,63 @@ "name": "allowedMint" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaNode", + "name": "associatedTokenAccount", + "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + "seeds": [ + { + "kind": "variablePdaSeedNode", + "name": "owner", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "tokenProgram", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "mint", + "type": { + "kind": "publicKeyTypeNode" + } + } + ] + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "owner", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "tokenProgram", + "value": { + "kind": "accountValueNode", + "name": "tokenProgram" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + } + ] + }, "docs": [ "Escrow vault ATA to be created for this mint" ], @@ -1312,6 +1978,10 @@ "name": "vault" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, "docs": [ "SPL Token program" ], @@ -1321,6 +1991,10 @@ "name": "tokenProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" + }, "docs": [ "Associated Token program for vault creation" ], @@ -1330,6 +2004,10 @@ "name": "associatedTokenProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "11111111111111111111111111111111" + }, "docs": [ "System program" ], @@ -1339,6 +2017,10 @@ "name": "systemProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -1348,6 +2030,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -1373,6 +2059,10 @@ } }, { + "defaultValue": { + "kind": "accountBumpValueNode", + "name": "allowedMint" + }, "kind": "instructionArgumentNode", "name": "bump", "type": { @@ -1431,6 +2121,31 @@ "name": "mint" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "allowedMint" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + }, + { + "kind": "pdaSeedValueNode", + "name": "mint", + "value": { + "kind": "accountValueNode", + "name": "mint" + } + } + ] + }, "docs": [ "Allowed mint PDA to be closed" ], @@ -1440,6 +2155,10 @@ "name": "allowedMint" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, "docs": [ "SPL Token program" ], @@ -1449,6 +2168,10 @@ "name": "tokenProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -1458,6 +2181,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -1523,6 +2250,23 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "extensions" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + } + ] + }, "docs": [ "Extensions PDA account to store blocked extensions" ], @@ -1532,6 +2276,10 @@ "name": "extensions" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "11111111111111111111111111111111" + }, "docs": [ "System program" ], @@ -1541,6 +2289,10 @@ "name": "systemProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "docs": [ "Event authority PDA for CPI event emission" ], @@ -1550,6 +2302,10 @@ "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "docs": [ "Escrow program for CPI event emission" ], @@ -1575,6 +2331,10 @@ } }, { + "defaultValue": { + "kind": "accountBumpValueNode", + "name": "extensions" + }, "kind": "instructionArgumentNode", "name": "extensionsBump", "type": { @@ -1630,24 +2390,53 @@ "name": "escrow" }, { + "defaultValue": { + "kind": "pdaValueNode", + "pda": { + "kind": "pdaLinkNode", + "name": "extensions" + }, + "seeds": [ + { + "kind": "pdaSeedValueNode", + "name": "escrow", + "value": { + "kind": "accountValueNode", + "name": "escrow" + } + } + ] + }, "isSigner": false, "isWritable": true, "kind": "instructionAccountNode", "name": "extensions" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "11111111111111111111111111111111" + }, "isSigner": false, "isWritable": false, "kind": "instructionAccountNode", "name": "systemProgram" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M" + }, "isSigner": false, "isWritable": false, "kind": "instructionAccountNode", "name": "eventAuthority" }, { + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg" + }, "isSigner": false, "isWritable": false, "kind": "instructionAccountNode", @@ -1670,6 +2459,10 @@ } }, { + "defaultValue": { + "kind": "accountBumpValueNode", + "name": "extensions" + }, "kind": "instructionArgumentNode", "name": "extensionsBump", "type": { @@ -1688,49 +2481,153 @@ ], "kind": "instructionNode", "name": "setArbiter" + } + ], + "kind": "programNode", + "name": "escrowProgram", + "pdas": [ + { + "kind": "pdaNode", + "name": "allowedMint", + "seeds": [ + { + "kind": "constantPdaSeedNode", + "type": { + "encoding": "utf8", + "kind": "stringTypeNode" + }, + "value": { + "kind": "stringValueNode", + "string": "allowed_mint" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "escrow", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "mint", + "type": { + "kind": "publicKeyTypeNode" + } + } + ] }, { - "accounts": [ + "kind": "pdaNode", + "name": "escrow", + "seeds": [ { - "docs": [ - "Event authority PDA that must sign via CPI" - ], - "isSigner": true, - "isWritable": false, - "kind": "instructionAccountNode", - "name": "eventAuthority" + "kind": "constantPdaSeedNode", + "type": { + "encoding": "utf8", + "kind": "stringTypeNode" + }, + "value": { + "kind": "stringValueNode", + "string": "escrow" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "escrowSeed", + "type": { + "kind": "publicKeyTypeNode" + } } - ], - "arguments": [ + ] + }, + { + "kind": "pdaNode", + "name": "extensions", + "seeds": [ { - "defaultValue": { - "kind": "numberValueNode", - "number": 228 + "kind": "constantPdaSeedNode", + "type": { + "encoding": "utf8", + "kind": "stringTypeNode" }, - "defaultValueStrategy": "omitted", - "kind": "instructionArgumentNode", - "name": "discriminator", + "value": { + "kind": "stringValueNode", + "string": "extensions" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "escrow", "type": { - "endian": "le", - "format": "u8", - "kind": "numberTypeNode" + "kind": "publicKeyTypeNode" } } - ], - "discriminators": [ + ] + }, + { + "kind": "pdaNode", + "name": "eventAuthority", + "seeds": [ { - "kind": "fieldDiscriminatorNode", - "name": "discriminator", - "offset": 0 + "kind": "constantPdaSeedNode", + "type": { + "encoding": "utf8", + "kind": "stringTypeNode" + }, + "value": { + "kind": "stringValueNode", + "string": "event_authority" + } } - ], - "kind": "instructionNode", - "name": "emitEvent" + ] + }, + { + "kind": "pdaNode", + "name": "receipt", + "seeds": [ + { + "kind": "constantPdaSeedNode", + "type": { + "encoding": "utf8", + "kind": "stringTypeNode" + }, + "value": { + "kind": "stringValueNode", + "string": "receipt" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "escrow", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "depositor", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "mint", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "receiptSeed", + "type": { + "kind": "publicKeyTypeNode" + } + } + ] } ], - "kind": "programNode", - "name": "escrowProgram", - "pdas": [], "publicKey": "Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg", "version": "0.0.1" }, diff --git a/program/src/instructions/definition.rs b/program/src/instructions/definition.rs index 7b2433b..06c6aa8 100644 --- a/program/src/instructions/definition.rs +++ b/program/src/instructions/definition.rs @@ -10,25 +10,53 @@ pub enum EscrowProgramInstruction { #[codama(account(name = "payer", docs = "Pays for escrow account creation", signer, writable))] #[codama(account(name = "admin", docs = "Admin authority for the escrow", signer))] #[codama(account(name = "escrow_seed", docs = "Random keypair seed for escrow PDA derivation", signer))] - #[codama(account(name = "escrow", docs = "Escrow PDA account to be created", writable))] - #[codama(account(name = "system_program", docs = "System program"))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] + #[codama(account( + name = "escrow", + docs = "Escrow PDA account to be created", + writable, + default_value = pda("escrow", [seed("escrowSeed", account("escrowSeed"))]) + ))] + #[codama(account(name = "system_program", docs = "System program", default_value = program("system")))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] CreatesEscrow { /// Bump for the escrow PDA + #[codama(default_value = account_bump("escrow"))] bump: u8, } = 0, /// Add timelock extension to an escrow. #[codama(account(name = "payer", docs = "Pays for extensions account creation", signer, writable))] #[codama(account(name = "admin", docs = "Admin authority for the escrow", signer))] - #[codama(account(name = "escrow", docs = "Escrow account to add timelock to"))] - #[codama(account(name = "extensions", docs = "Extensions PDA account to store timelock config", writable))] - #[codama(account(name = "system_program", docs = "System program"))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] + #[codama(account(name = "escrow", docs = "Escrow account to add timelock to",))] + #[codama(account( + name = "extensions", + docs = "Extensions PDA account to store timelock config", + writable, + default_value = pda("extensions", [seed("escrow", account("escrow"))]) + ))] + #[codama(account(name = "system_program", docs = "System program", default_value = program("system")))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] AddTimelock { /// Bump for extensions PDA + #[codama(default_value = account_bump("extensions"))] extensions_bump: u8, /// Lock duration in seconds from deposit lock_duration: u64, @@ -38,12 +66,26 @@ pub enum EscrowProgramInstruction { #[codama(account(name = "payer", docs = "Pays for extensions account creation", signer, writable))] #[codama(account(name = "admin", docs = "Admin authority for the escrow", signer))] #[codama(account(name = "escrow", docs = "Escrow account to set hook on"))] - #[codama(account(name = "extensions", docs = "Extensions PDA account to store hook config", writable))] - #[codama(account(name = "system_program", docs = "System program"))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] + #[codama(account( + name = "extensions", + docs = "Extensions PDA account to store hook config", + writable, + default_value = pda("extensions", [seed("escrow", account("escrow"))]) + ))] + #[codama(account(name = "system_program", docs = "System program", default_value = program("system")))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] SetHook { /// Bump for extensions PDA + #[codama(default_value = account_bump("extensions"))] extensions_bump: u8, /// Hook program address hook_program: Address, @@ -53,23 +95,56 @@ pub enum EscrowProgramInstruction { #[codama(account(name = "payer", docs = "Pays for receipt account creation", signer, writable))] #[codama(account(name = "depositor", docs = "Authority depositing tokens", signer))] #[codama(account(name = "escrow", docs = "Escrow account to deposit into"))] - #[codama(account(name = "allowed_mint", docs = "Allowed mint PDA proving this mint is permitted"))] + #[codama(account( + name = "allowed_mint", + docs = "Allowed mint PDA proving this mint is permitted", + default_value = pda("allowedMint", [seed("escrow", account("escrow")), seed("mint", account("mint"))]) + ))] #[codama(account(name = "receipt_seed", docs = "Random keypair seed for receipt PDA derivation", signer))] - #[codama(account(name = "receipt", docs = "Deposit receipt PDA to be created", writable))] - #[codama(account(name = "vault", docs = "Escrow vault token account to receive tokens", writable))] + #[codama(account( + name = "receipt", + docs = "Deposit receipt PDA to be created", + writable, + default_value = pda("receipt", [ + seed("escrow", account("escrow")), + seed("depositor", account("depositor")), + seed("mint", account("mint")), + seed("receiptSeed", account("receiptSeed")) + ]) + ))] + #[codama(account( + name = "vault", + docs = "Escrow vault token account to receive tokens", + writable, + default_value = ata("escrow", "mint", "tokenProgram") + ))] #[codama(account( name = "depositor_token_account", docs = "Depositor's token account to transfer from", - writable + writable, + default_value = ata("depositor", "mint", "tokenProgram") ))] #[codama(account(name = "mint", docs = "Token mint of the deposited tokens"))] - #[codama(account(name = "token_program", docs = "SPL Token program"))] - #[codama(account(name = "system_program", docs = "System program"))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] - #[codama(account(name = "extensions", docs = "Extensions PDA for escrow configuration"))] + #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] + #[codama(account(name = "system_program", docs = "System program", default_value = program("system")))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] + #[codama(account( + name = "extensions", + docs = "Extensions PDA for escrow configuration", + default_value = pda("extensions", [seed("escrow", account("escrow"))]) + ))] Deposit { /// Bump for the deposit receipt PDA + #[codama(default_value = account_bump("receipt"))] bump: u8, /// Amount of tokens to deposit amount: u64, @@ -79,27 +154,53 @@ pub enum EscrowProgramInstruction { #[codama(account(name = "admin", docs = "Current admin authority for the escrow", signer))] #[codama(account(name = "new_admin", docs = "New admin authority to transfer ownership to", signer))] #[codama(account(name = "escrow", docs = "Escrow account to update admin on", writable))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] UpdateAdmin {} = 4, /// Withdraw tokens from an escrow vault back to the original depositor. #[codama(account(name = "rent_recipient", docs = "Receives rent from closed receipt account", writable))] #[codama(account(name = "withdrawer", docs = "Authority withdrawing tokens", signer))] #[codama(account(name = "escrow", docs = "Escrow account to withdraw from"))] - #[codama(account(name = "extensions", docs = "Extensions PDA for escrow configuration"))] + #[codama(account( + name = "extensions", + docs = "Extensions PDA for escrow configuration", + default_value = pda("extensions", [seed("escrow", account("escrow"))]) + ))] #[codama(account(name = "receipt", docs = "Deposit receipt to close upon withdrawal", writable))] - #[codama(account(name = "vault", docs = "Escrow vault token account to transfer from", writable))] + #[codama(account( + name = "vault", + docs = "Escrow vault token account to transfer from", + writable, + default_value = ata("escrow", "mint", "tokenProgram") + ))] #[codama(account( name = "withdrawer_token_account", docs = "Withdrawer's token account to receive tokens", - writable + writable, + default_value = ata("withdrawer", "mint", "tokenProgram") ))] #[codama(account(name = "mint", docs = "Token mint of the withdrawn tokens"))] - #[codama(account(name = "token_program", docs = "SPL Token program"))] - #[codama(account(name = "system_program", docs = "System program"))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] + #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] + #[codama(account(name = "system_program", docs = "System program", default_value = program("system")))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] Withdraw {} = 5, /// Allow a token mint for deposits into an escrow. @@ -107,17 +208,44 @@ pub enum EscrowProgramInstruction { #[codama(account(name = "payer", docs = "Pays for allowed mint and vault account creation", signer, writable))] #[codama(account(name = "admin", docs = "Admin authority for the escrow", signer))] #[codama(account(name = "escrow", docs = "Escrow account to allow mint on"))] - #[codama(account(name = "escrow_extensions", docs = "Extensions PDA for escrow configuration"))] + #[codama(account( + name = "escrow_extensions", + docs = "Extensions PDA for escrow configuration", + default_value = pda("extensions", [seed("escrow", account("escrow"))]) + ))] #[codama(account(name = "mint", docs = "Token mint to allow for deposits"))] - #[codama(account(name = "allowed_mint", docs = "Allowed mint PDA to be created", writable))] - #[codama(account(name = "vault", docs = "Escrow vault ATA to be created for this mint", writable))] - #[codama(account(name = "token_program", docs = "SPL Token program"))] - #[codama(account(name = "associated_token_program", docs = "Associated Token program for vault creation"))] - #[codama(account(name = "system_program", docs = "System program"))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] + #[codama(account( + name = "allowed_mint", + docs = "Allowed mint PDA to be created", + writable, + default_value = pda("allowedMint", [seed("escrow", account("escrow")), seed("mint", account("mint"))]) + ))] + #[codama(account( + name = "vault", + docs = "Escrow vault ATA to be created for this mint", + writable, + default_value = ata("escrow", "mint", "tokenProgram") + ))] + #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] + #[codama(account( + name = "associated_token_program", + docs = "Associated Token program for vault creation", + default_value = program("associated-token") + ))] + #[codama(account(name = "system_program", docs = "System program", default_value = program("system")))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] AllowMint { /// Bump for the allowed_mint PDA + #[codama(default_value = account_bump("allowedMint"))] bump: u8, } = 6, @@ -126,22 +254,49 @@ pub enum EscrowProgramInstruction { #[codama(account(name = "rent_recipient", docs = "Receives rent from closed allowed mint account", writable))] #[codama(account(name = "escrow", docs = "Escrow account to block mint on"))] #[codama(account(name = "mint", docs = "Token mint to block from deposits"))] - #[codama(account(name = "allowed_mint", docs = "Allowed mint PDA to be closed", writable))] - #[codama(account(name = "token_program", docs = "SPL Token program"))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] + #[codama(account( + name = "allowed_mint", + docs = "Allowed mint PDA to be closed", + writable, + default_value = pda("allowedMint", [seed("escrow", account("escrow")), seed("mint", account("mint"))]) + ))] + #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] BlockMint {} = 7, /// Block a token extension for an escrow. #[codama(account(name = "payer", docs = "Pays for extensions account creation", signer, writable))] #[codama(account(name = "admin", docs = "Admin authority for the escrow", signer))] #[codama(account(name = "escrow", docs = "Escrow account to block extension on"))] - #[codama(account(name = "extensions", docs = "Extensions PDA account to store blocked extensions", writable))] - #[codama(account(name = "system_program", docs = "System program"))] - #[codama(account(name = "event_authority", docs = "Event authority PDA for CPI event emission"))] - #[codama(account(name = "escrow_program", docs = "Escrow program for CPI event emission"))] + #[codama(account( + name = "extensions", + docs = "Extensions PDA account to store blocked extensions", + writable, + default_value = pda("extensions", [seed("escrow", account("escrow"))]) + ))] + #[codama(account(name = "system_program", docs = "System program", default_value = program("system")))] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA for CPI event emission", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + docs = "Escrow program for CPI event emission", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] BlockTokenExtension { /// Bump for extensions PDA + #[codama(default_value = account_bump("extensions"))] extensions_bump: u8, /// Token-2022 ExtensionType value to block blocked_extension: u16, @@ -153,16 +308,33 @@ pub enum EscrowProgramInstruction { #[codama(account(name = "admin", signer))] #[codama(account(name = "arbiter", signer))] #[codama(account(name = "escrow"))] - #[codama(account(name = "extensions", writable))] - #[codama(account(name = "system_program"))] - #[codama(account(name = "event_authority"))] - #[codama(account(name = "escrow_program"))] + #[codama(account( + name = "extensions", + writable, + default_value = pda("extensions", [seed("escrow", account("escrow"))]) + ))] + #[codama(account(name = "system_program", default_value = program("system")))] + #[codama(account( + name = "event_authority", + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] + #[codama(account( + name = "escrow_program", + default_value = public_key("Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg") + ))] SetArbiter { /// Bump for extensions PDA + #[codama(default_value = account_bump("extensions"))] extensions_bump: u8, } = 9, /// Invoked via CPI to emit event data in instruction args (prevents log truncation). - #[codama(account(name = "event_authority", docs = "Event authority PDA that must sign via CPI", signer))] + #[codama(skip)] + #[codama(account( + name = "event_authority", + docs = "Event authority PDA that must sign via CPI", + signer, + default_value = public_key("Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M") + ))] EmitEvent {} = 228, } diff --git a/program/src/state/allowed_mint.rs b/program/src/state/allowed_mint.rs index cff9f1f..e938b31 100644 --- a/program/src/state/allowed_mint.rs +++ b/program/src/state/allowed_mint.rs @@ -17,6 +17,11 @@ use crate::traits::{ /// # PDA Seeds /// `[b"allowed_mint", escrow.as_ref(), mint.as_ref()]` #[derive(Clone, Debug, PartialEq, CodamaAccount)] +#[codama(field("discriminator", number(u8), default_value = 3))] +#[codama(discriminator(field = "discriminator"))] +#[codama(seed(type = string(utf8), value = "allowed_mint"))] +#[codama(seed(name = "escrow", type = public_key))] +#[codama(seed(name = "mint", type = public_key))] #[repr(C)] pub struct AllowedMint { pub bump: u8, diff --git a/program/src/state/escrow.rs b/program/src/state/escrow.rs index f1e16ed..1fe5605 100644 --- a/program/src/state/escrow.rs +++ b/program/src/state/escrow.rs @@ -20,6 +20,10 @@ use crate::traits::{ /// # PDA Seeds /// `[b"escrow", escrow_seed.as_ref()]` #[derive(Clone, Debug, PartialEq, CodamaAccount)] +#[codama(field("discriminator", number(u8), default_value = 0))] +#[codama(discriminator(field = "discriminator"))] +#[codama(seed(type = string(utf8), value = "escrow"))] +#[codama(seed(name = "escrowSeed", type = public_key))] #[repr(C)] pub struct Escrow { pub bump: u8, diff --git a/program/src/state/escrow_extensions.rs b/program/src/state/escrow_extensions.rs index 3741df5..49479f8 100644 --- a/program/src/state/escrow_extensions.rs +++ b/program/src/state/escrow_extensions.rs @@ -46,6 +46,11 @@ pub const TLV_HEADER_SIZE: usize = 4; /// [discriminator: 1][version: 1][header: 2][TLV extensions: variable] /// ``` #[derive(Clone, Debug, PartialEq, CodamaAccount)] +#[codama(field("discriminator", number(u8), default_value = 1))] +#[codama(discriminator(field = "discriminator"))] +#[codama(pda = "extensions")] +#[codama(seed(type = string(utf8), value = "extensions"))] +#[codama(seed(name = "escrow", type = public_key))] #[repr(C)] pub struct EscrowExtensionsHeader { pub bump: u8, diff --git a/program/src/state/event_authority.rs b/program/src/state/event_authority.rs new file mode 100644 index 0000000..2f3f914 --- /dev/null +++ b/program/src/state/event_authority.rs @@ -0,0 +1,7 @@ +use codama::CodamaPda; + +/// PDA definition for the event authority. +/// This has no account data — it's only used for CPI event emission signing. +#[derive(CodamaPda)] +#[codama(seed(type = string(utf8), value = "event_authority"))] +pub struct EventAuthority; diff --git a/program/src/state/mod.rs b/program/src/state/mod.rs index 21fcd52..766acfb 100644 --- a/program/src/state/mod.rs +++ b/program/src/state/mod.rs @@ -1,11 +1,13 @@ pub mod allowed_mint; pub mod escrow; pub mod escrow_extensions; +pub mod event_authority; pub mod extensions; pub mod receipt; pub use allowed_mint::*; pub use escrow::*; pub use escrow_extensions::*; +pub use event_authority::*; pub use extensions::*; pub use receipt::*; diff --git a/program/src/state/receipt.rs b/program/src/state/receipt.rs index 4bbf6cc..945bffd 100644 --- a/program/src/state/receipt.rs +++ b/program/src/state/receipt.rs @@ -15,6 +15,13 @@ use crate::{assert_no_padding, require_account_len, validate_discriminator}; /// # PDA Seeds /// `[b"receipt", escrow.as_ref(), depositor.as_ref(), mint.as_ref(), receipt_seed.as_ref()]` #[derive(Clone, Debug, PartialEq, CodamaAccount)] +#[codama(field("discriminator", number(u8), default_value = 2))] +#[codama(discriminator(field = "discriminator"))] +#[codama(seed(type = string(utf8), value = "receipt"))] +#[codama(seed(name = "escrow", type = public_key))] +#[codama(seed(name = "depositor", type = public_key))] +#[codama(seed(name = "mint", type = public_key))] +#[codama(seed(name = "receiptSeed", type = public_key))] #[repr(C)] pub struct Receipt { pub bump: u8, diff --git a/scripts/generate-clients.ts b/scripts/generate-clients.ts index cf18d60..ac59ae2 100644 --- a/scripts/generate-clients.ts +++ b/scripts/generate-clients.ts @@ -18,12 +18,10 @@ const rustClientsDir = path.join(__dirname, '..', 'clients', 'rust'); const typescriptClientsDir = path.join(__dirname, '..', 'clients', 'typescript'); const escrowCodama = createEscrowCodamaBuilder(escrowIdl) - .appendAccountDiscriminator() .appendAccountVersion() - .appendPdaDerivers() - .setInstructionAccountDefaultValues() - .updateInstructionBumps() - .removeEmitInstruction() + // .setInstructionAccountDefaultValues() // Now handled by codama-rs: ata() and pda() defaults + // .updateInstructionBumps() // Now handled by codama-rs: account_bump() defaults + // .removeEmitInstruction() // Now handled by codama-rs: #[codama(skip)] .build(); // Preserve configuration files during generation From 7eaf08910de4eec8bfed140cf52faa700cb48c11 Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Thu, 12 Mar 2026 17:45:45 -0700 Subject: [PATCH 2/9] feat: ata --- idl/escrow_program.json | 212 +++++++++---------------- program/src/instructions/definition.rs | 10 +- program/src/state/associated_token.rs | 11 ++ program/src/state/mod.rs | 2 + 4 files changed, 94 insertions(+), 141 deletions(-) create mode 100644 program/src/state/associated_token.rs diff --git a/idl/escrow_program.json b/idl/escrow_program.json index c78017d..ab2c677 100644 --- a/idl/escrow_program.json +++ b/idl/escrow_program.json @@ -1,5 +1,45 @@ { - "additionalPrograms": [], + "additionalPrograms": [ + { + "accounts": [], + "definedTypes": [], + "errors": [], + "instructions": [], + "kind": "programNode", + "name": "associatedToken", + "pdas": [ + { + "kind": "pdaNode", + "name": "associatedToken", + "seeds": [ + { + "kind": "variablePdaSeedNode", + "name": "owner", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "tokenProgram", + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "variablePdaSeedNode", + "name": "mint", + "type": { + "kind": "publicKeyTypeNode" + } + } + ] + } + ], + "publicKey": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + "version": "" + } + ], "kind": "rootNode", "program": { "accounts": [ @@ -1183,37 +1223,17 @@ "defaultValue": { "kind": "pdaValueNode", "pda": { - "kind": "pdaNode", - "name": "associatedTokenAccount", - "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", - "seeds": [ - { - "kind": "variablePdaSeedNode", - "name": "owner", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "tokenProgram", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "mint", - "type": { - "kind": "publicKeyTypeNode" - } - } - ] + "kind": "pdaLinkNode", + "name": "associatedToken", + "program": { + "kind": "programLinkNode", + "name": "associatedToken" + } }, "seeds": [ { "kind": "pdaSeedValueNode", - "name": "owner", + "name": "escrow", "value": { "kind": "accountValueNode", "name": "escrow" @@ -1249,37 +1269,17 @@ "defaultValue": { "kind": "pdaValueNode", "pda": { - "kind": "pdaNode", - "name": "associatedTokenAccount", - "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", - "seeds": [ - { - "kind": "variablePdaSeedNode", - "name": "owner", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "tokenProgram", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "mint", - "type": { - "kind": "publicKeyTypeNode" - } - } - ] + "kind": "pdaLinkNode", + "name": "associatedToken", + "program": { + "kind": "programLinkNode", + "name": "associatedToken" + } }, "seeds": [ { "kind": "pdaSeedValueNode", - "name": "owner", + "name": "depositor", "value": { "kind": "accountValueNode", "name": "depositor" @@ -1597,37 +1597,17 @@ "defaultValue": { "kind": "pdaValueNode", "pda": { - "kind": "pdaNode", - "name": "associatedTokenAccount", - "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", - "seeds": [ - { - "kind": "variablePdaSeedNode", - "name": "owner", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "tokenProgram", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "mint", - "type": { - "kind": "publicKeyTypeNode" - } - } - ] + "kind": "pdaLinkNode", + "name": "associatedToken", + "program": { + "kind": "programLinkNode", + "name": "associatedToken" + } }, "seeds": [ { "kind": "pdaSeedValueNode", - "name": "owner", + "name": "escrow", "value": { "kind": "accountValueNode", "name": "escrow" @@ -1663,37 +1643,17 @@ "defaultValue": { "kind": "pdaValueNode", "pda": { - "kind": "pdaNode", - "name": "associatedTokenAccount", - "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", - "seeds": [ - { - "kind": "variablePdaSeedNode", - "name": "owner", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "tokenProgram", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "mint", - "type": { - "kind": "publicKeyTypeNode" - } - } - ] + "kind": "pdaLinkNode", + "name": "associatedToken", + "program": { + "kind": "programLinkNode", + "name": "associatedToken" + } }, "seeds": [ { "kind": "pdaSeedValueNode", - "name": "owner", + "name": "withdrawer", "value": { "kind": "accountValueNode", "name": "withdrawer" @@ -1915,37 +1875,17 @@ "defaultValue": { "kind": "pdaValueNode", "pda": { - "kind": "pdaNode", - "name": "associatedTokenAccount", - "programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", - "seeds": [ - { - "kind": "variablePdaSeedNode", - "name": "owner", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "tokenProgram", - "type": { - "kind": "publicKeyTypeNode" - } - }, - { - "kind": "variablePdaSeedNode", - "name": "mint", - "type": { - "kind": "publicKeyTypeNode" - } - } - ] + "kind": "pdaLinkNode", + "name": "associatedToken", + "program": { + "kind": "programLinkNode", + "name": "associatedToken" + } }, "seeds": [ { "kind": "pdaSeedValueNode", - "name": "owner", + "name": "escrow", "value": { "kind": "accountValueNode", "name": "escrow" diff --git a/program/src/instructions/definition.rs b/program/src/instructions/definition.rs index 06c6aa8..f9ba65f 100644 --- a/program/src/instructions/definition.rs +++ b/program/src/instructions/definition.rs @@ -116,13 +116,13 @@ pub enum EscrowProgramInstruction { name = "vault", docs = "Escrow vault token account to receive tokens", writable, - default_value = ata("escrow", "mint", "tokenProgram") + default_value = pda("associatedToken", program = "associatedToken", [account("escrow"), account("tokenProgram"), account("mint")]) ))] #[codama(account( name = "depositor_token_account", docs = "Depositor's token account to transfer from", writable, - default_value = ata("depositor", "mint", "tokenProgram") + default_value = pda("associatedToken", program = "associatedToken", [account("depositor"), account("tokenProgram"), account("mint")]) ))] #[codama(account(name = "mint", docs = "Token mint of the deposited tokens"))] #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] @@ -180,13 +180,13 @@ pub enum EscrowProgramInstruction { name = "vault", docs = "Escrow vault token account to transfer from", writable, - default_value = ata("escrow", "mint", "tokenProgram") + default_value = pda("associatedToken", program = "associatedToken", [account("escrow"), account("tokenProgram"), account("mint")]) ))] #[codama(account( name = "withdrawer_token_account", docs = "Withdrawer's token account to receive tokens", writable, - default_value = ata("withdrawer", "mint", "tokenProgram") + default_value = pda("associatedToken", program = "associatedToken", [account("withdrawer"), account("tokenProgram"), account("mint")]) ))] #[codama(account(name = "mint", docs = "Token mint of the withdrawn tokens"))] #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] @@ -224,7 +224,7 @@ pub enum EscrowProgramInstruction { name = "vault", docs = "Escrow vault ATA to be created for this mint", writable, - default_value = ata("escrow", "mint", "tokenProgram") + default_value = pda("associatedToken", program = "associatedToken", [account("escrow"), account("tokenProgram"), account("mint")]) ))] #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] #[codama(account( diff --git a/program/src/state/associated_token.rs b/program/src/state/associated_token.rs new file mode 100644 index 0000000..a55f834 --- /dev/null +++ b/program/src/state/associated_token.rs @@ -0,0 +1,11 @@ +use codama::CodamaPda; + +/// Associated Token Account PDA definition for external program reference. +/// This generates an `additionalPrograms` entry in the IDL with the ATA program's +/// PDA seeds, allowing instruction accounts to reference it via `pda("associatedToken", ...)`. +#[derive(CodamaPda)] +#[codama(program(name = "associatedToken", address = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))] +#[codama(seed(name = "owner", type = public_key))] +#[codama(seed(name = "tokenProgram", type = public_key))] +#[codama(seed(name = "mint", type = public_key))] +pub struct AssociatedToken; diff --git a/program/src/state/mod.rs b/program/src/state/mod.rs index 766acfb..201bd78 100644 --- a/program/src/state/mod.rs +++ b/program/src/state/mod.rs @@ -1,4 +1,5 @@ pub mod allowed_mint; +pub mod associated_token; pub mod escrow; pub mod escrow_extensions; pub mod event_authority; @@ -6,6 +7,7 @@ pub mod extensions; pub mod receipt; pub use allowed_mint::*; +pub use associated_token::*; pub use escrow::*; pub use escrow_extensions::*; pub use event_authority::*; From 0610bbcda04892dd94fe233cd7c1446f4809d90c Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Thu, 12 Mar 2026 18:04:53 -0700 Subject: [PATCH 3/9] chore: switch codama from fork to official crate v0.7.4 codama-rs now natively supports skip, account_bump, and program directives. Replace amilz/codama-rs fork with codama = "0.7.4" from crates.io, remove 5 redundant TS transformers handled by codama-rs attributes, and use generated PDA helpers in integration tests. --- Cargo.lock | 55 ++++---- Cargo.toml | 2 +- scripts/generate-clients.ts | 7 +- scripts/lib/escrow-codama-builder.ts | 34 +---- .../updates/append-account-discriminator.ts | 45 ------- scripts/lib/updates/append-pda-derivers.ts | 58 --------- scripts/lib/updates/index.ts | 4 - .../lib/updates/remove-emit-instruction.ts | 15 --- .../set-instruction-account-default-values.ts | 120 ------------------ .../lib/updates/update-instruction-bumps.ts | 47 ------- .../integration-tests/src/utils/pda_utils.rs | 20 +-- 11 files changed, 42 insertions(+), 365 deletions(-) delete mode 100644 scripts/lib/updates/append-account-discriminator.ts delete mode 100644 scripts/lib/updates/append-pda-derivers.ts delete mode 100644 scripts/lib/updates/remove-emit-instruction.ts delete mode 100644 scripts/lib/updates/set-instruction-account-default-values.ts delete mode 100644 scripts/lib/updates/update-instruction-bumps.ts diff --git a/Cargo.lock b/Cargo.lock index d1a0fac..a55e62f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -790,8 +790,9 @@ dependencies = [ [[package]] name = "codama" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b12c0b52a61261c057e4a786f30d535d49f545b32fb9757cdc4945b05dc907" dependencies = [ "codama-errors", "codama-korok-plugins", @@ -805,8 +806,9 @@ dependencies = [ [[package]] name = "codama-attributes" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0530aae728a7c8993839930c7c923f51a32fd432ddc2fbaf127e7e85fd96c734" dependencies = [ "codama-errors", "codama-nodes", @@ -819,8 +821,9 @@ dependencies = [ [[package]] name = "codama-errors" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1ccf69a1f4e56f08250dd09d285990abe0e94467d14ab791d291511f6a0aee" dependencies = [ "cargo_toml", "proc-macro2", @@ -831,8 +834,9 @@ dependencies = [ [[package]] name = "codama-korok-plugins" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bb70eaf4a37dea5ddf75ca14afcd5f62543acf9d0f8e98f9a95cd40d546d3a6" dependencies = [ "codama-errors", "codama-korok-visitors", @@ -841,8 +845,9 @@ dependencies = [ [[package]] name = "codama-korok-visitors" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81c5f5ba09d746e44d5a1d7381d62bf984b1e9a5dd6cfd931c667d33673fd26b" dependencies = [ "cargo_toml", "codama-attributes", @@ -856,8 +861,9 @@ dependencies = [ [[package]] name = "codama-koroks" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de65e986ed08d93abf355ef62b31de9a6e4c78157590c375c6d39bd98640e548" dependencies = [ "codama-attributes", "codama-errors", @@ -871,8 +877,9 @@ dependencies = [ [[package]] name = "codama-macros" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afdf314b062a4a0c73132d8ba18d98904335a102093417ea28c38fced5e864c0" dependencies = [ "codama-attributes", "codama-errors", @@ -885,8 +892,9 @@ dependencies = [ [[package]] name = "codama-nodes" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7d682e171abf115c184ddc39a096bb743cdbcdd7f9940f6104a642a0f5afab1" dependencies = [ "codama-errors", "codama-nodes-derive", @@ -897,8 +905,9 @@ dependencies = [ [[package]] name = "codama-nodes-derive" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d21379376d3e6ac5c04af64bfd817c8d48246e8040633370d633cdae047bea7e" dependencies = [ "codama-errors", "codama-syn-helpers", @@ -910,8 +919,9 @@ dependencies = [ [[package]] name = "codama-stores" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2b259fad9bbd557d05f7aea51c26cc5ab8e51b4c367976121c8de5db246c849" dependencies = [ "cargo_toml", "codama-errors", @@ -921,8 +931,9 @@ dependencies = [ [[package]] name = "codama-syn-helpers" -version = "0.7.3" -source = "git+https://github.com/amilz/codama-rs?branch=feat%2Finstruction-attributes#221041ffefbc1049a43e65537417a97b9835d5dc" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f33123a6977e8eed56c9bc83439a62e556bdffff9c211e71e42e0a4e20fe5232" dependencies = [ "codama-errors", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index 252ceb0..2f5caa8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [ ] } [workspace.dependencies] -codama = { git = "https://github.com/amilz/codama-rs", branch = "feat/instruction-attributes" } +codama = "0.7.4" serde_json = "^1.0.145" const-crypto = "^0.3.0" pinocchio = "^0.10.1" diff --git a/scripts/generate-clients.ts b/scripts/generate-clients.ts index ac59ae2..7ac8bce 100644 --- a/scripts/generate-clients.ts +++ b/scripts/generate-clients.ts @@ -17,12 +17,7 @@ const escrowIdl = JSON.parse(fs.readFileSync(path.join(idlDir, 'escrow_program.j const rustClientsDir = path.join(__dirname, '..', 'clients', 'rust'); const typescriptClientsDir = path.join(__dirname, '..', 'clients', 'typescript'); -const escrowCodama = createEscrowCodamaBuilder(escrowIdl) - .appendAccountVersion() - // .setInstructionAccountDefaultValues() // Now handled by codama-rs: ata() and pda() defaults - // .updateInstructionBumps() // Now handled by codama-rs: account_bump() defaults - // .removeEmitInstruction() // Now handled by codama-rs: #[codama(skip)] - .build(); +const escrowCodama = createEscrowCodamaBuilder(escrowIdl).appendAccountVersion().build(); // Preserve configuration files during generation const configPreserver = preserveConfigFiles(typescriptClientsDir, rustClientsDir); diff --git a/scripts/lib/escrow-codama-builder.ts b/scripts/lib/escrow-codama-builder.ts index c0107bf..0c2ab2d 100644 --- a/scripts/lib/escrow-codama-builder.ts +++ b/scripts/lib/escrow-codama-builder.ts @@ -1,12 +1,5 @@ import { Codama, createFromJson } from 'codama'; -import { - appendAccountDiscriminator, - appendAccountVersion, - appendPdaDerivers, - setInstructionAccountDefaultValues, - updateInstructionBumps, -} from './updates/'; -import { removeEmitInstruction } from './updates/remove-emit-instruction'; +import { appendAccountVersion } from './updates/'; /** * Builder for applying Codama IDL transformations before client generation. @@ -19,36 +12,11 @@ export class EscrowCodamaBuilder { this.codama = createFromJson(idlJson); } - appendAccountDiscriminator(): this { - this.codama = appendAccountDiscriminator(this.codama); - return this; - } - appendAccountVersion(): this { this.codama = appendAccountVersion(this.codama); return this; } - appendPdaDerivers(): this { - this.codama = appendPdaDerivers(this.codama); - return this; - } - - setInstructionAccountDefaultValues(): this { - this.codama = setInstructionAccountDefaultValues(this.codama); - return this; - } - - updateInstructionBumps(): this { - this.codama = updateInstructionBumps(this.codama); - return this; - } - - removeEmitInstruction(): this { - this.codama = removeEmitInstruction(this.codama); - return this; - } - build(): Codama { return this.codama; } diff --git a/scripts/lib/updates/append-account-discriminator.ts b/scripts/lib/updates/append-account-discriminator.ts deleted file mode 100644 index cbede09..0000000 --- a/scripts/lib/updates/append-account-discriminator.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Codama, bottomUpTransformerVisitor, structFieldTypeNode, numberTypeNode, assertIsNode, isNode } from 'codama'; - -/** - * Adds discriminator fields to account structs for type-safe deserialization. - */ -export function appendAccountDiscriminator(escrowCodama: Codama): Codama { - escrowCodama.update( - bottomUpTransformerVisitor([ - { - select: '[accountNode]', - transform: node => { - assertIsNode(node, 'accountNode'); - - if (isNode(node.data, 'structTypeNode')) { - const updatedNode = { - ...node, - data: { - ...node.data, - fields: [ - structFieldTypeNode({ - name: 'discriminator', - type: numberTypeNode('u8'), - }), - ...node.data.fields, - ], - }, - }; - - if (node.size !== undefined) { - return { - ...updatedNode, - size: (node.size ?? 0) + 1, - }; - } - - return updatedNode; - } - - return node; - }, - }, - ]), - ); - return escrowCodama; -} diff --git a/scripts/lib/updates/append-pda-derivers.ts b/scripts/lib/updates/append-pda-derivers.ts deleted file mode 100644 index b578fc5..0000000 --- a/scripts/lib/updates/append-pda-derivers.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { - Codama, - constantPdaSeedNode, - stringTypeNode, - stringValueNode, - variablePdaSeedNode, - publicKeyTypeNode, - addPdasVisitor, -} from 'codama'; - -/** - * Adds PDA derivation functions for escrow accounts. - */ -export function appendPdaDerivers(escrowCodama: Codama): Codama { - escrowCodama.update( - addPdasVisitor({ - escrowProgram: [ - { - name: 'escrow', - seeds: [ - constantPdaSeedNode(stringTypeNode('utf8'), stringValueNode('escrow')), - variablePdaSeedNode('escrowSeed', publicKeyTypeNode()), - ], - }, - { - name: 'receipt', - seeds: [ - constantPdaSeedNode(stringTypeNode('utf8'), stringValueNode('receipt')), - variablePdaSeedNode('escrow', publicKeyTypeNode()), - variablePdaSeedNode('depositor', publicKeyTypeNode()), - variablePdaSeedNode('mint', publicKeyTypeNode()), - variablePdaSeedNode('receiptSeed', publicKeyTypeNode()), - ], - }, - { - name: 'allowedMint', - seeds: [ - constantPdaSeedNode(stringTypeNode('utf8'), stringValueNode('allowed_mint')), - variablePdaSeedNode('escrow', publicKeyTypeNode()), - variablePdaSeedNode('mint', publicKeyTypeNode()), - ], - }, - { - name: 'extensions', - seeds: [ - constantPdaSeedNode(stringTypeNode('utf8'), stringValueNode('extensions')), - variablePdaSeedNode('escrow', publicKeyTypeNode()), - ], - }, - { - name: 'eventAuthority', - seeds: [constantPdaSeedNode(stringTypeNode('utf8'), stringValueNode('event_authority'))], - }, - ], - }), - ); - return escrowCodama; -} diff --git a/scripts/lib/updates/index.ts b/scripts/lib/updates/index.ts index 3e3ad12..60c7782 100644 --- a/scripts/lib/updates/index.ts +++ b/scripts/lib/updates/index.ts @@ -1,5 +1 @@ -export { appendAccountDiscriminator } from './append-account-discriminator.js'; export { appendAccountVersion } from './append-account-version.js'; -export { appendPdaDerivers } from './append-pda-derivers.js'; -export { setInstructionAccountDefaultValues } from './set-instruction-account-default-values.js'; -export { updateInstructionBumps } from './update-instruction-bumps.js'; diff --git a/scripts/lib/updates/remove-emit-instruction.ts b/scripts/lib/updates/remove-emit-instruction.ts deleted file mode 100644 index 4a4894e..0000000 --- a/scripts/lib/updates/remove-emit-instruction.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Codama, updateInstructionsVisitor } from 'codama'; - -/** - * Removes the internal emitEvent instruction from client APIs. - */ -export function removeEmitInstruction(escrowCodama: Codama): Codama { - escrowCodama.update( - updateInstructionsVisitor({ - emitEvent: { - delete: true, - }, - }), - ); - return escrowCodama; -} diff --git a/scripts/lib/updates/set-instruction-account-default-values.ts b/scripts/lib/updates/set-instruction-account-default-values.ts deleted file mode 100644 index 26a7ded..0000000 --- a/scripts/lib/updates/set-instruction-account-default-values.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { - Codama, - pdaNode, - pdaValueNode, - pdaSeedValueNode, - publicKeyTypeNode, - accountValueNode, - variablePdaSeedNode, - publicKeyValueNode, - pdaLinkNode, - setInstructionAccountDefaultValuesVisitor, -} from 'codama'; - -const ESCROW_PROGRAM_ID = 'Escrowae7RaUfNn4oEZHywMXE5zWzYCXenwrCDaEoifg'; - -const ATA_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'; -const SYSTEM_PROGRAM_ID = '11111111111111111111111111111111'; -const EVENT_AUTHORITY_PDA = 'Eq63FWYo9DXgwoTnpK9gjp7BH4PyhSPo11zEF9FK7f4M'; -const TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; - -function createAtaPdaValueNode(ownerAccount: string, mintAccount: string, tokenProgram: string) { - return pdaValueNode( - pdaNode({ - name: 'associatedTokenAccount', - seeds: [ - variablePdaSeedNode('owner', publicKeyTypeNode()), - variablePdaSeedNode('tokenProgram', publicKeyTypeNode()), - variablePdaSeedNode('mint', publicKeyTypeNode()), - ], - programId: ATA_PROGRAM_ID, - }), - [ - pdaSeedValueNode('owner', accountValueNode(ownerAccount)), - pdaSeedValueNode('tokenProgram', accountValueNode(tokenProgram)), - pdaSeedValueNode('mint', accountValueNode(mintAccount)), - ], - ); -} - -/** - * Sets default values for common instruction accounts (program IDs, PDAs, ATAs). - */ -export function setInstructionAccountDefaultValues(escrowCodama: Codama): Codama { - escrowCodama.update( - setInstructionAccountDefaultValuesVisitor([ - // Global Constants - { - account: 'escrowProgram', - defaultValue: publicKeyValueNode(ESCROW_PROGRAM_ID), - }, - { - account: 'tokenProgram', - defaultValue: publicKeyValueNode(TOKEN_PROGRAM_ID), - }, - { - account: 'associatedTokenProgram', - defaultValue: publicKeyValueNode(ATA_PROGRAM_ID), - }, - { - account: 'systemProgram', - defaultValue: publicKeyValueNode(SYSTEM_PROGRAM_ID), - }, - { - account: 'eventAuthority', - defaultValue: publicKeyValueNode(EVENT_AUTHORITY_PDA), - }, - - // PDA Derivations - { - account: 'escrow', - defaultValue: pdaValueNode(pdaLinkNode('escrow'), [ - pdaSeedValueNode('escrowSeed', accountValueNode('escrowSeed')), - ]), - }, - { - account: 'receipt', - defaultValue: pdaValueNode(pdaLinkNode('receipt'), [ - pdaSeedValueNode('escrow', accountValueNode('escrow')), - pdaSeedValueNode('depositor', accountValueNode('depositor')), - pdaSeedValueNode('mint', accountValueNode('mint')), - pdaSeedValueNode('receiptSeed', accountValueNode('receiptSeed')), - ]), - }, - { - account: 'allowedMint', - defaultValue: pdaValueNode(pdaLinkNode('allowedMint'), [ - pdaSeedValueNode('escrow', accountValueNode('escrow')), - pdaSeedValueNode('mint', accountValueNode('mint')), - ]), - }, - { - account: 'extensions', - defaultValue: pdaValueNode(pdaLinkNode('extensions'), [ - pdaSeedValueNode('escrow', accountValueNode('escrow')), - ]), - }, - { - account: 'escrowExtensions', - defaultValue: pdaValueNode(pdaLinkNode('extensions'), [ - pdaSeedValueNode('escrow', accountValueNode('escrow')), - ]), - }, - - // ATAs - { - account: 'vault', - defaultValue: createAtaPdaValueNode('escrow', 'mint', 'tokenProgram'), - }, - { - account: 'depositorTokenAccount', - defaultValue: createAtaPdaValueNode('depositor', 'mint', 'tokenProgram'), - }, - { - account: 'withdrawerTokenAccount', - defaultValue: createAtaPdaValueNode('withdrawer', 'mint', 'tokenProgram'), - }, - ]), - ); - return escrowCodama; -} diff --git a/scripts/lib/updates/update-instruction-bumps.ts b/scripts/lib/updates/update-instruction-bumps.ts deleted file mode 100644 index 883608a..0000000 --- a/scripts/lib/updates/update-instruction-bumps.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Codama, updateInstructionsVisitor, accountBumpValueNode } from 'codama'; - -/** - * Sets default bump values for createEscrow and allowMint instructions. - */ -export function updateInstructionBumps(escrowCodama: Codama): Codama { - escrowCodama.update( - updateInstructionsVisitor({ - createsEscrow: { - arguments: { - bump: { - defaultValue: accountBumpValueNode('escrow'), - }, - }, - }, - allowMint: { - arguments: { - bump: { - defaultValue: accountBumpValueNode('allowedMint'), - }, - }, - }, - addTimelock: { - arguments: { - extensionsBump: { - defaultValue: accountBumpValueNode('extensions'), - }, - }, - }, - setHook: { - arguments: { - extensionsBump: { - defaultValue: accountBumpValueNode('extensions'), - }, - }, - }, - deposit: { - arguments: { - bump: { - defaultValue: accountBumpValueNode('receipt'), - }, - }, - }, - }), - ); - return escrowCodama; -} diff --git a/tests/integration-tests/src/utils/pda_utils.rs b/tests/integration-tests/src/utils/pda_utils.rs index d509f78..c20c5b5 100644 --- a/tests/integration-tests/src/utils/pda_utils.rs +++ b/tests/integration-tests/src/utils/pda_utils.rs @@ -1,31 +1,23 @@ +use escrow_program_client::accounts::{AllowedMint, Escrow, EscrowExtensionsHeader, Receipt}; use escrow_program_client::ESCROW_PROGRAM_ID; use solana_sdk::pubkey::Pubkey; -const ESCROW_SEED: &[u8] = b"escrow"; -const EXTENSIONS_SEED: &[u8] = b"extensions"; -const EVENT_AUTHORITY_SEED: &[u8] = b"event_authority"; -const RECEIPT_SEED: &[u8] = b"receipt"; -const ALLOWED_MINT_SEED: &[u8] = b"allowed_mint"; - pub fn find_escrow_pda(escrow_seed: &Pubkey) -> (Pubkey, u8) { - Pubkey::find_program_address(&[ESCROW_SEED, escrow_seed.as_ref()], &ESCROW_PROGRAM_ID) + Escrow::find_pda(escrow_seed) } pub fn find_extensions_pda(escrow: &Pubkey) -> (Pubkey, u8) { - Pubkey::find_program_address(&[EXTENSIONS_SEED, escrow.as_ref()], &ESCROW_PROGRAM_ID) + EscrowExtensionsHeader::find_pda(escrow) } pub fn find_event_authority_pda() -> (Pubkey, u8) { - Pubkey::find_program_address(&[EVENT_AUTHORITY_SEED], &ESCROW_PROGRAM_ID) + Pubkey::find_program_address(&[b"event_authority"], &ESCROW_PROGRAM_ID) } pub fn find_receipt_pda(escrow: &Pubkey, depositor: &Pubkey, mint: &Pubkey, receipt_seed: &Pubkey) -> (Pubkey, u8) { - Pubkey::find_program_address( - &[RECEIPT_SEED, escrow.as_ref(), depositor.as_ref(), mint.as_ref(), receipt_seed.as_ref()], - &ESCROW_PROGRAM_ID, - ) + Receipt::find_pda(escrow, depositor, mint, receipt_seed) } pub fn find_allowed_mint_pda(escrow: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) { - Pubkey::find_program_address(&[ALLOWED_MINT_SEED, escrow.as_ref(), mint.as_ref()], &ESCROW_PROGRAM_ID) + AllowedMint::find_pda(escrow, mint) } From b01f7472471b0bdd5be0e7f42149013f39b077cc Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Thu, 12 Mar 2026 18:07:48 -0700 Subject: [PATCH 4/9] style: add caret to codama version for consistency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2f5caa8..ffe9685 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [ ] } [workspace.dependencies] -codama = "0.7.4" +codama = "^0.7.4" serde_json = "^1.0.145" const-crypto = "^0.3.0" pinocchio = "^0.10.1" From 194ddfb69841edc10368b4dc70e5fbd28373b948 Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Fri, 13 Mar 2026 08:53:34 -0700 Subject: [PATCH 5/9] feat(codama): add CodamaAccount to EventAuthority for PDA helper generation --- idl/escrow_program.json | 12 ++++++++++++ program/src/state/event_authority.rs | 7 +++---- tests/integration-tests/src/utils/pda_utils.rs | 5 ++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/idl/escrow_program.json b/idl/escrow_program.json index ab2c677..d2797d7 100644 --- a/idl/escrow_program.json +++ b/idl/escrow_program.json @@ -192,6 +192,18 @@ "name": "extensions" } }, + { + "data": { + "fields": [], + "kind": "structTypeNode" + }, + "kind": "accountNode", + "name": "eventAuthority", + "pda": { + "kind": "pdaLinkNode", + "name": "eventAuthority" + } + }, { "data": { "fields": [ diff --git a/program/src/state/event_authority.rs b/program/src/state/event_authority.rs index 2f3f914..da6cd59 100644 --- a/program/src/state/event_authority.rs +++ b/program/src/state/event_authority.rs @@ -1,7 +1,6 @@ -use codama::CodamaPda; +use codama::CodamaAccount; -/// PDA definition for the event authority. -/// This has no account data — it's only used for CPI event emission signing. -#[derive(CodamaPda)] +/// Event authority PDA — no account data, only used for CPI event emission signing. +#[derive(CodamaAccount)] #[codama(seed(type = string(utf8), value = "event_authority"))] pub struct EventAuthority; diff --git a/tests/integration-tests/src/utils/pda_utils.rs b/tests/integration-tests/src/utils/pda_utils.rs index c20c5b5..4882fbe 100644 --- a/tests/integration-tests/src/utils/pda_utils.rs +++ b/tests/integration-tests/src/utils/pda_utils.rs @@ -1,5 +1,4 @@ -use escrow_program_client::accounts::{AllowedMint, Escrow, EscrowExtensionsHeader, Receipt}; -use escrow_program_client::ESCROW_PROGRAM_ID; +use escrow_program_client::accounts::{AllowedMint, Escrow, EscrowExtensionsHeader, EventAuthority, Receipt}; use solana_sdk::pubkey::Pubkey; pub fn find_escrow_pda(escrow_seed: &Pubkey) -> (Pubkey, u8) { @@ -11,7 +10,7 @@ pub fn find_extensions_pda(escrow: &Pubkey) -> (Pubkey, u8) { } pub fn find_event_authority_pda() -> (Pubkey, u8) { - Pubkey::find_program_address(&[b"event_authority"], &ESCROW_PROGRAM_ID) + EventAuthority::find_pda() } pub fn find_receipt_pda(escrow: &Pubkey, depositor: &Pubkey, mint: &Pubkey, receipt_seed: &Pubkey) -> (Pubkey, u8) { From 4aeee020155704c86e864e942074fd6cb3fbee68 Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Fri, 13 Mar 2026 08:56:27 -0700 Subject: [PATCH 6/9] fix(codama): use named seeds for ATA PDA refs, add TS typecheck to CI Positional account args in ATA pda() defaults produced seed names matching the account name (e.g. "escrow") instead of the PDA seed name ("owner"), causing TS type errors. Switch to named seeds. Add pnpm typecheck (tsc --noEmit) to just check to catch these. --- idl/escrow_program.json | 10 +++++----- justfile | 1 + package.json | 3 ++- program/src/instructions/definition.rs | 10 +++++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/idl/escrow_program.json b/idl/escrow_program.json index d2797d7..aa4ee7f 100644 --- a/idl/escrow_program.json +++ b/idl/escrow_program.json @@ -1245,7 +1245,7 @@ "seeds": [ { "kind": "pdaSeedValueNode", - "name": "escrow", + "name": "owner", "value": { "kind": "accountValueNode", "name": "escrow" @@ -1291,7 +1291,7 @@ "seeds": [ { "kind": "pdaSeedValueNode", - "name": "depositor", + "name": "owner", "value": { "kind": "accountValueNode", "name": "depositor" @@ -1619,7 +1619,7 @@ "seeds": [ { "kind": "pdaSeedValueNode", - "name": "escrow", + "name": "owner", "value": { "kind": "accountValueNode", "name": "escrow" @@ -1665,7 +1665,7 @@ "seeds": [ { "kind": "pdaSeedValueNode", - "name": "withdrawer", + "name": "owner", "value": { "kind": "accountValueNode", "name": "withdrawer" @@ -1897,7 +1897,7 @@ "seeds": [ { "kind": "pdaSeedValueNode", - "name": "escrow", + "name": "owner", "value": { "kind": "accountValueNode", "name": "escrow" diff --git a/justfile b/justfile index 32840ec..beaf7a3 100644 --- a/justfile +++ b/justfile @@ -35,6 +35,7 @@ check: cd program && cargo check --features idl pnpm run format:check pnpm lint + pnpm run typecheck # Run unit tests unit-test: diff --git a/package.json b/package.json index 6095f56..685a201 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "format": "prettier --write .", "format:check": "prettier --check .", "lint": "eslint .", - "lint:fix": "eslint . --fix" + "lint:fix": "eslint . --fix", + "typecheck": "cd clients/typescript && tsc --noEmit" }, "devDependencies": { "@codama/nodes-from-anchor": "^1.3.8", diff --git a/program/src/instructions/definition.rs b/program/src/instructions/definition.rs index f9ba65f..d3bd480 100644 --- a/program/src/instructions/definition.rs +++ b/program/src/instructions/definition.rs @@ -116,13 +116,13 @@ pub enum EscrowProgramInstruction { name = "vault", docs = "Escrow vault token account to receive tokens", writable, - default_value = pda("associatedToken", program = "associatedToken", [account("escrow"), account("tokenProgram"), account("mint")]) + default_value = pda("associatedToken", program = "associatedToken", [seed("owner", account("escrow")), seed("tokenProgram", account("tokenProgram")), seed("mint", account("mint"))]) ))] #[codama(account( name = "depositor_token_account", docs = "Depositor's token account to transfer from", writable, - default_value = pda("associatedToken", program = "associatedToken", [account("depositor"), account("tokenProgram"), account("mint")]) + default_value = pda("associatedToken", program = "associatedToken", [seed("owner", account("depositor")), seed("tokenProgram", account("tokenProgram")), seed("mint", account("mint"))]) ))] #[codama(account(name = "mint", docs = "Token mint of the deposited tokens"))] #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] @@ -180,13 +180,13 @@ pub enum EscrowProgramInstruction { name = "vault", docs = "Escrow vault token account to transfer from", writable, - default_value = pda("associatedToken", program = "associatedToken", [account("escrow"), account("tokenProgram"), account("mint")]) + default_value = pda("associatedToken", program = "associatedToken", [seed("owner", account("escrow")), seed("tokenProgram", account("tokenProgram")), seed("mint", account("mint"))]) ))] #[codama(account( name = "withdrawer_token_account", docs = "Withdrawer's token account to receive tokens", writable, - default_value = pda("associatedToken", program = "associatedToken", [account("withdrawer"), account("tokenProgram"), account("mint")]) + default_value = pda("associatedToken", program = "associatedToken", [seed("owner", account("withdrawer")), seed("tokenProgram", account("tokenProgram")), seed("mint", account("mint"))]) ))] #[codama(account(name = "mint", docs = "Token mint of the withdrawn tokens"))] #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] @@ -224,7 +224,7 @@ pub enum EscrowProgramInstruction { name = "vault", docs = "Escrow vault ATA to be created for this mint", writable, - default_value = pda("associatedToken", program = "associatedToken", [account("escrow"), account("tokenProgram"), account("mint")]) + default_value = pda("associatedToken", program = "associatedToken", [seed("owner", account("escrow")), seed("tokenProgram", account("tokenProgram")), seed("mint", account("mint"))]) ))] #[codama(account(name = "token_program", docs = "SPL Token program", default_value = program("token")))] #[codama(account( From d44a1645a9e6ca8c819d107e02a72e3f0465bdee Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Fri, 13 Mar 2026 09:07:22 -0700 Subject: [PATCH 7/9] refactor: move PDA-only structs from state/ to utils/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AssociatedToken and EventAuthority have no account data — they are codama PDA definitions only. utils/ is a better home for them. --- program/src/state/mod.rs | 4 ---- program/src/{state => utils}/associated_token.rs | 0 program/src/{state => utils}/event_authority.rs | 0 program/src/utils/mod.rs | 2 ++ 4 files changed, 2 insertions(+), 4 deletions(-) rename program/src/{state => utils}/associated_token.rs (100%) rename program/src/{state => utils}/event_authority.rs (100%) diff --git a/program/src/state/mod.rs b/program/src/state/mod.rs index 201bd78..21fcd52 100644 --- a/program/src/state/mod.rs +++ b/program/src/state/mod.rs @@ -1,15 +1,11 @@ pub mod allowed_mint; -pub mod associated_token; pub mod escrow; pub mod escrow_extensions; -pub mod event_authority; pub mod extensions; pub mod receipt; pub use allowed_mint::*; -pub use associated_token::*; pub use escrow::*; pub use escrow_extensions::*; -pub use event_authority::*; pub use extensions::*; pub use receipt::*; diff --git a/program/src/state/associated_token.rs b/program/src/utils/associated_token.rs similarity index 100% rename from program/src/state/associated_token.rs rename to program/src/utils/associated_token.rs diff --git a/program/src/state/event_authority.rs b/program/src/utils/event_authority.rs similarity index 100% rename from program/src/state/event_authority.rs rename to program/src/utils/event_authority.rs diff --git a/program/src/utils/mod.rs b/program/src/utils/mod.rs index 9caf963..a199ee8 100644 --- a/program/src/utils/mod.rs +++ b/program/src/utils/mod.rs @@ -1,4 +1,6 @@ pub mod account_utils; +pub mod associated_token; +pub mod event_authority; pub mod event_utils; pub mod macros; pub mod pda_utils; From 5c83657da431261835f1b71672b8e4f8c612e849 Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Fri, 13 Mar 2026 09:09:05 -0700 Subject: [PATCH 8/9] refactor: inline EventAuthority PDA into event_utils.rs Co-locate the codama PDA definition with its only consumers (verify_event_authority, emit_event) instead of a standalone file. --- program/src/utils/event_authority.rs | 6 ------ program/src/utils/event_utils.rs | 7 +++++++ program/src/utils/mod.rs | 1 - 3 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 program/src/utils/event_authority.rs diff --git a/program/src/utils/event_authority.rs b/program/src/utils/event_authority.rs deleted file mode 100644 index da6cd59..0000000 --- a/program/src/utils/event_authority.rs +++ /dev/null @@ -1,6 +0,0 @@ -use codama::CodamaAccount; - -/// Event authority PDA — no account data, only used for CPI event emission signing. -#[derive(CodamaAccount)] -#[codama(seed(type = string(utf8), value = "event_authority"))] -pub struct EventAuthority; diff --git a/program/src/utils/event_utils.rs b/program/src/utils/event_utils.rs index a7a3dab..e7af15c 100644 --- a/program/src/utils/event_utils.rs +++ b/program/src/utils/event_utils.rs @@ -1,3 +1,5 @@ +use codama::CodamaAccount; + use crate::errors::EscrowProgramError::InvalidEventAuthority; use pinocchio::{ account::AccountView, @@ -9,6 +11,11 @@ use pinocchio::{ use crate::events::{event_authority_pda, EVENT_AUTHORITY_SEED}; +/// Event authority PDA — no account data, only used for CPI event emission signing. +#[derive(CodamaAccount)] +#[codama(seed(type = string(utf8), value = "event_authority"))] +pub struct EventAuthority; + /// Verify the account is the event authority PDA, returning an error if it is not. /// /// # Arguments diff --git a/program/src/utils/mod.rs b/program/src/utils/mod.rs index a199ee8..85edd5d 100644 --- a/program/src/utils/mod.rs +++ b/program/src/utils/mod.rs @@ -1,6 +1,5 @@ pub mod account_utils; pub mod associated_token; -pub mod event_authority; pub mod event_utils; pub mod macros; pub mod pda_utils; From e40b041615f97edb4c7e286b1747495d7fff0c78 Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Fri, 13 Mar 2026 09:09:52 -0700 Subject: [PATCH 9/9] chore: update IDL after event_authority move --- idl/escrow_program.json | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/idl/escrow_program.json b/idl/escrow_program.json index aa4ee7f..32f7a65 100644 --- a/idl/escrow_program.json +++ b/idl/escrow_program.json @@ -43,6 +43,18 @@ "kind": "rootNode", "program": { "accounts": [ + { + "data": { + "fields": [], + "kind": "structTypeNode" + }, + "kind": "accountNode", + "name": "eventAuthority", + "pda": { + "kind": "pdaLinkNode", + "name": "eventAuthority" + } + }, { "data": { "fields": [ @@ -192,18 +204,6 @@ "name": "extensions" } }, - { - "data": { - "fields": [], - "kind": "structTypeNode" - }, - "kind": "accountNode", - "name": "eventAuthority", - "pda": { - "kind": "pdaLinkNode", - "name": "eventAuthority" - } - }, { "data": { "fields": [ @@ -2438,6 +2438,23 @@ "kind": "programNode", "name": "escrowProgram", "pdas": [ + { + "kind": "pdaNode", + "name": "eventAuthority", + "seeds": [ + { + "kind": "constantPdaSeedNode", + "type": { + "encoding": "utf8", + "kind": "stringTypeNode" + }, + "value": { + "kind": "stringValueNode", + "string": "event_authority" + } + } + ] + }, { "kind": "pdaNode", "name": "allowedMint", @@ -2517,23 +2534,6 @@ } ] }, - { - "kind": "pdaNode", - "name": "eventAuthority", - "seeds": [ - { - "kind": "constantPdaSeedNode", - "type": { - "encoding": "utf8", - "kind": "stringTypeNode" - }, - "value": { - "kind": "stringValueNode", - "string": "event_authority" - } - } - ] - }, { "kind": "pdaNode", "name": "receipt",