Skip to content

Commit

Permalink
fix: migrate to scarb lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 committed Oct 25, 2023
1 parent d6ef746 commit 6b6f9be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions listings/ch01-applications/constant_product_amm/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "constant_product_amm"
version = "0.1.0"
dependencies = [
"openzeppelin",
]

[[package]]
name = "openzeppelin"
version = "0.7.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.7.0#61a2505fe0c0f19b5de2b3f8dedf421ba2cff657"
2 changes: 1 addition & 1 deletion listings/ch01-applications/constant_product_amm/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "constant_product_amm"
version = "0.1.0"

[dependencies]
starknet = ">=2.3.0-rc0"
starknet = "2.2.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.7.0" }

[[target.starknet-contract]]
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod ConstantProductAmm {

#[constructor]
fn constructor(ref self: ContractState, token0: ContractAddress, token1: ContractAddress, fee: u256) {
assert(fee <= 1000, 'fee > 1000')
assert(fee <= 1000, 'fee > 1000');
self.fee.write(fee);
self.token0.write(IERC20Dispatcher { contract_address: token0 });
self.token1.write(IERC20Dispatcher { contract_address: token1 });
Expand Down Expand Up @@ -102,7 +102,7 @@ mod ConstantProductAmm {
// (yx + ydx - xy) / (x + dx) = dy
// ydx / (x + dx) = dy

let amount_in_with_fee = (amount_in * (1000 - fee)) / 1000;
let amount_in_with_fee = (amount_in * (1000 - self.fee.read())) / 1000;
let amount_out = (reserve_out * amount_in_with_fee) / (reserve_in + amount_in_with_fee);

token_out.transfer(caller, amount_out);
Expand Down

0 comments on commit 6b6f9be

Please sign in to comment.