Skip to content

Commit

Permalink
deriving Serialize for Position
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 21, 2025
1 parent a5d125d commit 8ea6152
Showing 1 changed file with 2 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
use dep::aztec::protocol_types::traits::{Deserialize, Serialize};
use std::meta::derive;

#[derive(Serialize, Deserialize)]
pub struct Position {
collateral: U128,
static_debt: U128,
debt: U128,
}

global POSITION_SERIALIZED_LEN: u32 = 6;

impl Serialize<POSITION_SERIALIZED_LEN> for Position {
fn serialize(position: Position) -> [Field; POSITION_SERIALIZED_LEN] {
let serialized_collateral = position.collateral.serialize();
let serialized_static_debt = position.static_debt.serialize();
let serialized_debt = position.debt.serialize();
[
serialized_collateral[0],
serialized_collateral[1],
serialized_static_debt[0],
serialized_static_debt[1],
serialized_debt[0],
serialized_debt[1],
]
}
}

impl Deserialize<POSITION_SERIALIZED_LEN> for Position {
fn deserialize(fields: [Field; POSITION_SERIALIZED_LEN]) -> Position {
Position {
collateral: U128::deserialize([fields[0], fields[1]]),
static_debt: U128::deserialize([fields[2], fields[3]]),
debt: U128::deserialize([fields[4], fields[5]]),
}
}
}

0 comments on commit 8ea6152

Please sign in to comment.