Skip to content

Commit 9eb0bb1

Browse files
kariyclaude
andcommitted
feat(contracts): add AVNU paymaster contracts and consolidate class definitions
- Add avnu-labs/paymaster as git submodule at v1.0.0 - Update build.rs to build AVNU contracts with scarb via asdf - Add avnu module with AvnuForwarder contract to katana-contracts - Update controller and cartridge crates to use contracts from katana-contracts instead of include_str! with JSON files - Remove classes/ directory from controller (all contract artifacts now come from katana-contracts crate) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4c286c2 commit 9eb0bb1

File tree

13 files changed

+67
-2764
lines changed

13 files changed

+67
-2764
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
[submodule "crates/contracts/contracts/vrf"]
1919
path = crates/contracts/contracts/vrf
2020
url = https://github.com/cartridge-gg/vrf.git
21+
[submodule "crates/contracts/contracts/avnu"]
22+
path = crates/contracts/contracts/avnu
23+
url = https://github.com/avnu-labs/paymaster

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cartridge/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ build = "build.rs"
99
[dependencies]
1010
katana-contracts.workspace = true
1111
katana-genesis.workspace = true
12-
katana-chain-spec.workspace = true
1312
katana-primitives.workspace = true
1413
katana-rpc-types = { path = "../rpc/rpc-types" }
1514

crates/cartridge/src/vrf/bootstrap.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use std::time::{Duration, Instant};
1212

1313
use anyhow::{anyhow, Context, Result};
1414
use ark_ff::PrimeField;
15-
use katana_chain_spec::ChainSpec;
16-
use katana_genesis::allocation::GenesisAccountAlloc;
1715
use katana_genesis::constant::DEFAULT_STRK_FEE_TOKEN_ADDRESS;
1816
use katana_primitives::chain::ChainId;
1917
use katana_primitives::utils::get_contract_address;
@@ -241,20 +239,12 @@ pub async fn bootstrap_vrf(
241239

242240
/// Get the class hash of the VRF account contract.
243241
pub fn vrf_account_class_hash() -> Result<Felt> {
244-
let class = katana_primitives::utils::class::parse_sierra_class(include_str!(concat!(
245-
env!("CARGO_MANIFEST_DIR"),
246-
"/../controller/classes/cartridge_vrf_VrfAccount.contract_class.json"
247-
)))?;
248-
class.class_hash().context("failed to compute vrf account class hash")
242+
Ok(katana_contracts::vrf::CartridgeVrfAccount::HASH)
249243
}
250244

251245
/// Get the class hash of the VRF consumer contract.
252246
pub fn vrf_consumer_class_hash() -> Result<Felt> {
253-
let class = katana_primitives::utils::class::parse_sierra_class(include_str!(concat!(
254-
env!("CARGO_MANIFEST_DIR"),
255-
"/../controller/classes/cartridge_vrf_VrfConsumer.contract_class.json"
256-
)))?;
257-
class.class_hash().context("failed to compute vrf consumer class hash")
247+
Ok(katana_contracts::vrf::CartridgeVrfConsumer::HASH)
258248
}
259249

260250
// ============================================================================

crates/contracts/build.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn main() {
1111
println!("cargo:rerun-if-changed=contracts/messaging");
1212
println!("cargo:rerun-if-changed=contracts/test-contracts");
1313
println!("cargo:rerun-if-changed=contracts/vrf");
14+
println!("cargo:rerun-if-changed=contracts/avnu");
1415
println!("cargo:rerun-if-changed=build.rs");
1516

1617
let contracts_dir = Path::new("contracts");
@@ -65,6 +66,10 @@ fn main() {
6566
let vrf_dir = contracts_dir.join("vrf");
6667
build_vrf_contracts(&vrf_dir);
6768

69+
// Build AVNU contracts (uses different scarb version via asdf)
70+
let avnu_dir = contracts_dir.join("avnu/contracts");
71+
build_avnu_contracts(&avnu_dir);
72+
6873
// Create build directory if it doesn't exist
6974
if let Err(e) = fs::create_dir_all(build_dir) {
7075
panic!("Failed to create build directory: {e}");
@@ -90,6 +95,17 @@ fn main() {
9095
} else {
9196
println!("cargo:warning=No VRF contract artifacts found in vrf/target/dev");
9297
}
98+
99+
// Copy AVNU contract artifacts from avnu/contracts/target/dev to build directory
100+
let avnu_target_dir = avnu_dir.join("target/dev");
101+
if avnu_target_dir.exists() {
102+
if let Err(e) = copy_dir_contents(&avnu_target_dir, build_dir) {
103+
panic!("Failed to copy AVNU contract artifacts: {e}");
104+
}
105+
println!("cargo:warning=AVNU contract artifacts copied to build directory");
106+
} else {
107+
println!("cargo:warning=No AVNU contract artifacts found in avnu/contracts/target/dev");
108+
}
93109
}
94110

95111
fn copy_dir_contents(src: &Path, dst: &Path) -> std::io::Result<()> {
@@ -132,3 +148,31 @@ fn build_vrf_contracts(vrf_dir: &Path) {
132148
);
133149
}
134150
}
151+
152+
fn build_avnu_contracts(avnu_dir: &Path) {
153+
println!("cargo:warning=Building AVNU contracts with scarb...");
154+
155+
let output = Command::new("asdf")
156+
.args(["exec", "scarb", "build"])
157+
.current_dir(avnu_dir)
158+
.output()
159+
.expect("Failed to execute scarb build for AVNU contracts");
160+
161+
if !output.status.success() {
162+
let logs = String::from_utf8_lossy(&output.stdout);
163+
let last_n_lines = logs
164+
.split('\n')
165+
.rev()
166+
.take(50)
167+
.collect::<Vec<&str>>()
168+
.into_iter()
169+
.rev()
170+
.collect::<Vec<&str>>()
171+
.join("\n");
172+
173+
panic!(
174+
"AVNU contracts compilation failed. Below are the last 50 lines of `scarb build` \
175+
output:\n\n{last_n_lines}"
176+
);
177+
}
178+
}

crates/contracts/contracts/avnu

Submodule avnu added at 04c6bb8

crates/contracts/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ pub mod vrf {
2525
"{CARGO_MANIFEST_DIR}/build/cartridge_vrf_VrfAccount.contract_class.json"
2626
);
2727
}
28+
29+
pub mod avnu {
30+
use katana_contracts_macro::contract;
31+
32+
contract!(
33+
AvnuForwarder,
34+
"{CARGO_MANIFEST_DIR}/build/avnu_Forwarder.contract_class.json"
35+
);
36+
}

crates/controller/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ version.workspace = true
88

99
[dependencies]
1010
cartridge.workspace = true
11+
katana-contracts.workspace = true
1112
katana-genesis.workspace = true
1213
katana-primitives.workspace = true

0 commit comments

Comments
 (0)