Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 7, 2024
1 parent 0188584 commit a7f547c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion noir-projects/noir-contracts/contracts/dex_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,23 @@ contract DEX {
let amount_out = get_amount_out(amount_in, reserve_in, reserve_out);
assert(amount_out >= amount_out_min, "INSUFFICIENT_OUTPUT_AMOUNT");

// TODO: Implement UniswapV2Pair._swap(amounts, path, to) here. The code above is from router.
// Below is a snippet from UniswapV2Pair._swap(amounts, path, to) here. The code above is from router.
let token_out = Token::at(token_address_out);
token_out.finalize_transfer_to_private(amount1, transfer_preparer_storage_slot_commitment).call(&mut context);

// Do we want to bother wieht the 'UniswapV2: K' check here or is this fine for PoC?
// https://github.com/Uniswap/v2-core/blob/ee547b17853e71ed4e0101ccfd52e70d5acded58/contracts/UniswapV2Pair.sol#L182

// Update the reserves
let updated_state = State {
token0: state.token0,
token1: state.token1,
liquidity_token: state.liquidity_token,
reserve0: token0.balance_of_public(context.this_address()).view(&mut context) as u64,
reserve1: token1.balance_of_public(context.this_address()).view(&mut context) as u64
};
storage.state.write(updated_state);

_unlock(&mut context);
}

Expand Down

0 comments on commit a7f547c

Please sign in to comment.