Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed a few variable names to make amm_sample.cairo clearer #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/starkware/starknet/apps/amm_sample/amm_sample.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ from starkware.cairo.common.hash import hash2
from starkware.cairo.common.math import assert_le, assert_nn_le, unsigned_div_rem
from starkware.starknet.common.syscalls import storage_read, storage_write

# The maximum amount of each token that belongs to the AMM.
const BALANCE_UPPER_BOUND = 2 ** 64

const TOKEN_TYPE_A = 1
const TOKEN_TYPE_B = 2

# Ensure the user's balances are much smaller than the pool's balance.
const POOL_UPPER_BOUND = 2 ** 30
const ACCOUNT_BALANCE_BOUND = 1073741 # 2**30 // 1000.
# Maximum amount of each token in a given pool or account.
const BALANCE_UPPER_BOUND = 2 ** 64

# Ensure the users' initial balances are much smaller than the pool's initial balance,
# so that they are able to swap against the pool.
const POOL_INIT_BALANCE_BOUND = 2 ** 30
const ACCOUNT_INIT_BALANCE_BOUND = 1073741 # 2**30 // 1000.

# A map from account and token type to the corresponding balance of that account.
@storage_var
Expand Down Expand Up @@ -126,9 +127,9 @@ end
func add_demo_token{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
account_id : felt, token_a_amount : felt, token_b_amount : felt
):
# Make sure the account's balance is much smaller then pool init balance.
assert_nn_le(token_a_amount, ACCOUNT_BALANCE_BOUND - 1)
assert_nn_le(token_b_amount, ACCOUNT_BALANCE_BOUND - 1)
# Make sure the account's balance is much smaller than pool init balance.
assert_nn_le(token_a_amount, ACCOUNT_INIT_BALANCE_BOUND - 1)
assert_nn_le(token_b_amount, ACCOUNT_INIT_BALANCE_BOUND - 1)

modify_account_balance(account_id=account_id, token_type=TOKEN_TYPE_A, amount=token_a_amount)
modify_account_balance(account_id=account_id, token_type=TOKEN_TYPE_B, amount=token_b_amount)
Expand All @@ -140,8 +141,8 @@ end
func init_pool{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
token_a : felt, token_b : felt
):
assert_nn_le(token_a, POOL_UPPER_BOUND - 1)
assert_nn_le(token_b, POOL_UPPER_BOUND - 1)
assert_nn_le(token_a, POOL_INIT_BALANCE_BOUND - 1)
assert_nn_le(token_b, POOL_INIT_BALANCE_BOUND - 1)

set_pool_token_balance(token_type=TOKEN_TYPE_A, balance=token_a)
set_pool_token_balance(token_type=TOKEN_TYPE_B, balance=token_b)
Expand Down