Skip to content

Commit ee3dd66

Browse files
committed
Fix zero copy generation
1 parent 3fb6943 commit ee3dd66

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

Cargo.lock

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/anchor-idl/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn generate_account(
4343
}
4444
};
4545
quote! {
46-
#[account(zero_copy)]
46+
#[account(zero_copy(unsafe))]
4747
#repr
4848
}
4949
} else {

crates/anchor-idl/src/typedef.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ pub fn generate_struct(
165165
}
166166
};
167167
quote! {
168-
#[zero_copy]
168+
#[derive(::borsh::BorshSerialize, ::borsh::BorshDeserialize)]
169+
#[zero_copy(unsafe)]
169170
#repr
170171
}
171172
} else {

examples/kamino-lend/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ cpi = ["no-entrypoint"]
1919
[dependencies]
2020
anchor-gen = { version = "0.4.0", path = "../../crates/anchor-gen" }
2121
anchor-lang = ">=0.20"
22+
# Override anchor to use borsh with the const-generics feature
23+
# Allows to borsh serialize arrays of any length
24+
borsh = { version = "0.10.3", features = ["const-generics"] }
25+
bytemuck = { version = "1.23", features = ["derive", "min_const_generics"] }

examples/kamino-lend/src/lib.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,44 @@
99
1010
#![allow(clippy::too_many_arguments)]
1111

12-
anchor_gen::generate_cpi_interface!(idl_path = "idl.json");
12+
use anchor_lang::zero_copy;
13+
14+
anchor_gen::generate_cpi_interface!(
15+
idl_path = "idl.json",
16+
zero_copy(
17+
UpdateConfigMode,
18+
UpdateLendingMarketConfigValue,
19+
UpdateLendingMarketMode,
20+
LastUpdate,
21+
ElevationGroup,
22+
InitObligationArgs,
23+
ObligationCollateral,
24+
ObligationLiquidity,
25+
AssetTier,
26+
BigFractionBytes,
27+
FeeCalculation,
28+
ReserveCollateral,
29+
ReserveConfig,
30+
ReserveFarmKind,
31+
ReserveFees,
32+
ReserveLiquidity,
33+
ReserveStatus,
34+
WithdrawalCaps,
35+
PriceHeuristic,
36+
PythConfiguration,
37+
ScopeConfiguration,
38+
SwitchboardConfiguration,
39+
TokenInfo,
40+
BorrowRateCurve,
41+
CurvePoint,
42+
UserState,
43+
LendingMarket,
44+
Obligation,
45+
ReferrerState,
46+
ReferrerTokenState,
47+
UserMetadata,
48+
Reserve,
49+
Referrer,
50+
ReferrerToken,
51+
)
52+
);

0 commit comments

Comments
 (0)