Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 31, 2024
1 parent 1253628 commit 8faf2af
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod lib;
mod state;
// mod test;
mod test;

use dep::aztec::macros::aztec;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod full_flow;
mod full_flow;
mod utils;
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::{AMM, test::utils::setup};
use dep::token::Token;
use dep::uint_note::uint_note::UintNote;
use aztec::prelude::AztecAddress;

#[test]
unconstrained fn full_flow() {
// Setup
let (env, amm_address, token0_address, token1_address, liquidity_token_address, token_admin, liquidity_provider, lp_balance_0, lp_balance_1, swapper_balance_0) = setup();
let (env, amm_address, token0_address, token1_address, liquidity_token_address, token_admin, liquidity_provider, lp_balance_0, lp_balance_1, swapper_balance_0) =
setup();
let amm = AMM::at(amm_address);

// Now we add liquidity

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dep::uint_note::uint_note::UintNote;
use crate::AMM;
use dep::token::Token;
use dep::uint_note::uint_note::UintNote;
use aztec::{
keys::getters::get_public_keys,
oracle::{
Expand All @@ -11,10 +12,8 @@ use aztec::{
protocol_types::storage::map::derive_storage_slot_in_map,
test::helpers::{cheatcodes, test_environment::TestEnvironment},
};
use crate::AMM;

pub unconstrained fn setup(
) -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress, Field, Field, Field) {
pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress, Field, Field, Field) {
// Setup env, generate keys
let mut env = TestEnvironment::new();

Expand All @@ -26,56 +25,61 @@ pub unconstrained fn setup(
env.impersonate(token_admin);

// Deploy tokens to be swapped and a liquidity token
let token0 =
env.deploy_self("Token").with_public_void_initializer(Token::interface().constructor(
token_admin,
"TestToken0000000000000000000000",
"TT00000000000000000000000000000",
18,
));
let token0_address = token0.to_address();
let token0_address = env
.deploy_self("Token")
.with_public_void_initializer(Token::interface().constructor(
token_admin,
"TestToken0000000000000000000000",
"TT00000000000000000000000000000",
18,
))
.to_address();
let token0 = Token::at(token0_address);

let token1 =
env.deploy_self("Token").with_public_void_initializer(Token::interface().constructor(
token_admin,
"TestToken1000000000000000000000",
"TT10000000000000000000000000000",
18,
));
let token1_address = token1.to_address();
let token1_address = env
.deploy_self("Token")
.with_public_void_initializer(Token::interface().constructor(
token_admin,
"TestToken1000000000000000000000",
"TT10000000000000000000000000000",
18,
))
.to_address();
let token1 = Token::at(token1_address);

let liquidity_token =
env.deploy_self("Token").with_public_void_initializer(Token::interface().constructor(
token_admin,
"TestLiquidityToken0000000000000",
"TLT0000000000000000000000000000",
18,
));
let liquidity_token_address = liquidity_token.to_address();
let liquidity_token_address = env
.deploy_self("Token")
.with_public_void_initializer(Token::interface().constructor(
token_admin,
"TestLiquidityToken0000000000000",
"TLT0000000000000000000000000000",
18,
))
.to_address();
let liquidity_token = Token::at(liquidity_token_address);

let amm = env.deploy_self("AMM").with_public_void_initializer(AMM::interface().constructor(
token0_address,
token1_address,
liquidity_token_address,
));
let amm_address = amm.to_address();
let amm_address = env
.deploy_self("AMM")
.with_public_void_initializer(AMM::interface().constructor(
token0_address,
token1_address,
liquidity_token_address,
))
.to_address();
let amm = AMM::at(amm_address);

// Now we mint both tokens to the liquidity provider and token0 to swapper
let lp_balance_0 = 20000;
let lp_balance_1 = 10000;
let swapper_balance_0 = 5000;

token0.mint_to_private(liquidity_provider, lp_balance_0).call(
&mut env.private(),
);
token1.mint_to_private(liquidity_provider, lp_balance_1).call(
&mut env.private(),
);
token0.mint_private(swapper, swapper_balance_0).call(
&mut env.private(),
);

token0.mint_to_private(liquidity_provider, lp_balance_0).call(&mut env.private());
token1.mint_to_private(liquidity_provider, lp_balance_1).call(&mut env.private());
token0.mint_to_private(swapper, swapper_balance_0).call(&mut env.private());

env.advance_block_by(1);
(&mut env, amm_address, token0_address, token1_address, liquidity_token_address, token_admin, liquidity_provider, lp_balance_0, lp_balance_1, swapper_balance_0)
}
(
&mut env, amm_address, token0_address, token1_address, liquidity_token_address, token_admin,
liquidity_provider, lp_balance_0, lp_balance_1, swapper_balance_0,
)
}

0 comments on commit 8faf2af

Please sign in to comment.