-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
136 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 1 addition & 15 deletions
16
noir-projects/noir-contracts/contracts/amm_contract/src/config.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
use dep::aztec::protocol_types::{address::AztecAddress, traits::{Deserialize, Packable, Serialize}}; | ||
use std::meta::derive; | ||
|
||
global CONFIG_LENGTH: u32 = 3; | ||
|
||
/// We store the tokens of the pool in a struct such that to load it from SharedImmutable asserts only a single | ||
/// merkle proof. | ||
/// (Once we actually do the optimization. WIP in https://github.com/AztecProtocol/aztec-packages/pull/8022). | ||
#[derive(Serialize, Deserialize)] | ||
#[derive(Deserialize, Packable, Serialize)] | ||
pub struct Config { | ||
pub token0: AztecAddress, | ||
pub token1: AztecAddress, | ||
pub liquidity_token: AztecAddress, | ||
} | ||
|
||
/// We implement the Packable trait for Config because it can be stored in contract's storage (and there | ||
/// the implementation of Packable is required). | ||
impl Packable<CONFIG_LENGTH> for Config { | ||
fn pack(self: Self) -> [Field; CONFIG_LENGTH] { | ||
self.serialize() | ||
} | ||
|
||
fn unpack(fields: [Field; CONFIG_LENGTH]) -> Self { | ||
Self::deserialize(fields) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 3 additions & 32 deletions
35
noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
noir-projects/noir-contracts/contracts/avm_test_contract/src/note.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use dep::aztec::protocol_types::traits::{Deserialize, Packable, Serialize}; | ||
use std::meta::derive; | ||
|
||
#[derive(Deserialize, Packable, Serialize)] | ||
pub struct Note { | ||
a: Field, | ||
b: Field, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 2 additions & 24 deletions
26
noir-projects/noir-contracts/contracts/docs_example_contract/src/types/leader.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,9 @@ | ||
use dep::aztec::protocol_types::{address::AztecAddress, traits::{Deserialize, Packable, Serialize}}; | ||
use std::meta::derive; | ||
|
||
// Shows how to create a custom struct in Public | ||
#[derive(Deserialize, Packable, Serialize)] | ||
pub struct Leader { | ||
account: AztecAddress, | ||
points: u8, | ||
} | ||
|
||
global LEADER_SERIALIZED_LEN: u32 = 2; | ||
|
||
impl Deserialize<LEADER_SERIALIZED_LEN> for Leader { | ||
fn deserialize(fields: [Field; LEADER_SERIALIZED_LEN]) -> Self { | ||
Leader { account: AztecAddress::from_field(fields[0]), points: fields[1] as u8 } | ||
} | ||
} | ||
|
||
impl Serialize<LEADER_SERIALIZED_LEN> for Leader { | ||
fn serialize(self) -> [Field; LEADER_SERIALIZED_LEN] { | ||
[self.account.to_field(), self.points as Field] | ||
} | ||
} | ||
|
||
impl Packable<LEADER_SERIALIZED_LEN> for Leader { | ||
fn pack(self) -> [Field; LEADER_SERIALIZED_LEN] { | ||
self.serialize() | ||
} | ||
|
||
fn unpack(fields: [Field; LEADER_SERIALIZED_LEN]) -> Self { | ||
Self::deserialize(fields) | ||
} | ||
} |
29 changes: 2 additions & 27 deletions
29
noir-projects/noir-contracts/contracts/fpc_contract/src/config.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,8 @@ | ||
use dep::aztec::protocol_types::{address::AztecAddress, traits::{Deserialize, Packable, Serialize}}; | ||
use std::meta::derive; | ||
|
||
global CONFIG_LENGTH: u32 = 2; | ||
|
||
#[derive(Deserialize, Packable, Serialize)] | ||
pub struct Config { | ||
pub accepted_asset: AztecAddress, // Asset the FPC accepts (denoted as AA below) | ||
pub admin: AztecAddress, // Address to which AA is sent during the private fee payment flow | ||
} | ||
|
||
impl Serialize<CONFIG_LENGTH> for Config { | ||
fn serialize(self: Self) -> [Field; CONFIG_LENGTH] { | ||
[self.accepted_asset.to_field(), self.admin.to_field()] | ||
} | ||
} | ||
|
||
impl Deserialize<CONFIG_LENGTH> for Config { | ||
fn deserialize(fields: [Field; CONFIG_LENGTH]) -> Self { | ||
Config { | ||
accepted_asset: AztecAddress::from_field(fields[0]), | ||
admin: AztecAddress::from_field(fields[1]), | ||
} | ||
} | ||
} | ||
|
||
impl Packable<CONFIG_LENGTH> for Config { | ||
fn pack(self) -> [Field; CONFIG_LENGTH] { | ||
self.serialize() | ||
} | ||
|
||
fn unpack(fields: [Field; CONFIG_LENGTH]) -> Self { | ||
Self::deserialize(fields) | ||
} | ||
} |
56 changes: 11 additions & 45 deletions
56
noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,18 @@ | ||
use dep::aztec::prelude::AztecAddress; | ||
use dep::aztec::protocol_types::traits::{Deserialize, Packable, Serialize}; | ||
use dep::aztec::{prelude::AztecAddress, protocol_types::traits::{Deserialize, Packable, Serialize}}; | ||
use std::meta::derive; | ||
|
||
// Struct to be used to represent "totals". Generally, there should be one per Asset. | ||
// It stores the global values that are shared among all users, such as an accumulator | ||
// and last time it was updated. | ||
// In practice, it should also point to an oracle and have more fields related to | ||
// loan to value ratios and other things, but we did not have enough reads/writes for this. | ||
/// Struct to be used to represent "totals". Generally, there should be one per Asset. | ||
/// It stores the global values that are shared among all users, such as an accumulator | ||
/// and last time it was updated. | ||
/// In practice, it should also point to an oracle and have more fields related to | ||
/// loan to value ratios and other things, but we did not have enough reads/writes for this. | ||
/// | ||
/// Note: Right now we are wasting so many writes. If changing last_updated_ts we will end | ||
/// up rewriting all the values. | ||
#[derive(Deserialize, Packable, Serialize)] | ||
pub struct Asset { | ||
interest_accumulator: U128, | ||
last_updated_ts: u64, | ||
loan_to_value: U128, | ||
oracle: AztecAddress, | ||
} | ||
|
||
global SERIALIZED_LEN: u32 = 6; | ||
|
||
impl Serialize<SERIALIZED_LEN> for Asset { | ||
fn serialize(Asset: Asset) -> [Field; SERIALIZED_LEN] { | ||
[ | ||
Asset.interest_accumulator.lo, | ||
Asset.interest_accumulator.hi, | ||
Asset.last_updated_ts as Field, | ||
Asset.loan_to_value.lo, | ||
Asset.loan_to_value.hi, | ||
Asset.oracle.to_field(), | ||
] | ||
} | ||
} | ||
|
||
impl Deserialize<SERIALIZED_LEN> for Asset { | ||
// Right now we are wasting so many writes. If changing last_updated_ts | ||
// we will end up rewriting all of them, wasting writes. | ||
fn deserialize(fields: [Field; SERIALIZED_LEN]) -> Asset { | ||
let interest_accumulator = U128 { lo: fields[0], hi: fields[1] }; | ||
let last_updated_ts = fields[2] as u64; | ||
let loan_to_value = U128 { lo: fields[3], hi: fields[4] }; | ||
let oracle = AztecAddress::from_field(fields[5]); | ||
|
||
Asset { interest_accumulator, last_updated_ts, loan_to_value, oracle } | ||
} | ||
} | ||
|
||
impl Packable<SERIALIZED_LEN> for Asset { | ||
fn pack(self) -> [Field; SERIALIZED_LEN] { | ||
self.serialize() | ||
} | ||
|
||
fn unpack(fields: [Field; SERIALIZED_LEN]) -> Self { | ||
Self::deserialize(fields) | ||
} | ||
} |
Oops, something went wrong.