diff --git a/Cargo.lock b/Cargo.lock index 16dfc80..75b5626 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -418,6 +418,9 @@ name = "bytemuck" version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9134a6ef01ce4b366b50689c94f82c14bc72bc5d0386829828a2e2752ef7958c" +dependencies = [ + "bytemuck_derive", +] [[package]] name = "bytemuck_derive" @@ -432,9 +435,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.21" +version = "1.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8691782945451c1c383942c4874dbe63814f61cb57ef773cda2972682b7bb3c0" +checksum = "32db95edf998450acc7881c932f94cd9b05c87b4b2599e8bab064753da4acfd1" dependencies = [ "shlex", ] @@ -734,6 +737,8 @@ version = "0.4.0" dependencies = [ "anchor-gen", "anchor-lang", + "borsh 0.10.4", + "bytemuck", ] [[package]] diff --git a/crates/anchor-idl/src/state.rs b/crates/anchor-idl/src/state.rs index 532e249..64c4308 100644 --- a/crates/anchor-idl/src/state.rs +++ b/crates/anchor-idl/src/state.rs @@ -43,7 +43,7 @@ pub fn generate_account( } }; quote! { - #[account(zero_copy)] + #[account(zero_copy(unsafe))] #repr } } else { diff --git a/crates/anchor-idl/src/typedef.rs b/crates/anchor-idl/src/typedef.rs index aea7e75..53e89b6 100644 --- a/crates/anchor-idl/src/typedef.rs +++ b/crates/anchor-idl/src/typedef.rs @@ -165,7 +165,8 @@ pub fn generate_struct( } }; quote! { - #[zero_copy] + #[derive(::borsh::BorshSerialize, ::borsh::BorshDeserialize)] + #[zero_copy(unsafe)] #repr } } else { diff --git a/examples/kamino-lend/Cargo.toml b/examples/kamino-lend/Cargo.toml index 45a9672..7ff7574 100644 --- a/examples/kamino-lend/Cargo.toml +++ b/examples/kamino-lend/Cargo.toml @@ -19,3 +19,7 @@ cpi = ["no-entrypoint"] [dependencies] anchor-gen = { version = "0.4.0", path = "../../crates/anchor-gen" } anchor-lang = ">=0.20" +# Override anchor to use borsh with the const-generics feature +# Allows to borsh serialize arrays of any length +borsh = { version = "0.10.3", features = ["const-generics"] } +bytemuck = { version = "1.23", features = ["derive", "min_const_generics"] } diff --git a/examples/kamino-lend/src/lib.rs b/examples/kamino-lend/src/lib.rs index e7cc97f..72a09f5 100644 --- a/examples/kamino-lend/src/lib.rs +++ b/examples/kamino-lend/src/lib.rs @@ -9,4 +9,44 @@ #![allow(clippy::too_many_arguments)] -anchor_gen::generate_cpi_interface!(idl_path = "idl.json"); +use anchor_lang::zero_copy; + +anchor_gen::generate_cpi_interface!( + idl_path = "idl.json", + zero_copy( + UpdateConfigMode, + UpdateLendingMarketConfigValue, + UpdateLendingMarketMode, + LastUpdate, + ElevationGroup, + InitObligationArgs, + ObligationCollateral, + ObligationLiquidity, + AssetTier, + BigFractionBytes, + FeeCalculation, + ReserveCollateral, + ReserveConfig, + ReserveFarmKind, + ReserveFees, + ReserveLiquidity, + ReserveStatus, + WithdrawalCaps, + PriceHeuristic, + PythConfiguration, + ScopeConfiguration, + SwitchboardConfiguration, + TokenInfo, + BorrowRateCurve, + CurvePoint, + UserState, + LendingMarket, + Obligation, + ReferrerState, + ReferrerTokenState, + UserMetadata, + Reserve, + Referrer, + ReferrerToken, + ) +);