-
Notifications
You must be signed in to change notification settings - Fork 0
/
CairoAMM.cairo
55 lines (45 loc) · 2.04 KB
/
CairoAMM.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%builtins output range_check
from starkware.cairo.common.serialize import serialize_word
from starkware.cairo.common.math import unsigned_div_rem
func main{output_ptr: felt*, range_check_ptr}() {
alloc_locals;
local token_a_amount;
local token_a_balance;
local token_b_balance;
local b;
%{
import requests
import json
import configparser
def get_contract_data(tick):
response = requests.post(f"{bison_network_service_endpoint}/contract", json={"tick": tick})
data = response.json()
return data
def check_balance(endpoint, address, amount_required):
response = requests.post(f"{endpoint}/balance", json={"address": address})
balance = response.json().get('balance', 0)
return balance >= float(amount_required) # 将 amount_required 转换为浮点数
config = configparser.ConfigParser()
config.read('config.ini')
tick_values = [config['TICKS']['value1'], config['TICKS']['value2']]
bison_network_service_endpoint = config['API']['BisonNetworkService']
contract_address = config['ContractAddress']['contractAddress']
priv_key = config['ContractAddress']['privKey']
tick1_balance_endpoint = tick1_endpoint + "/balance"
tick2_balance_endpoint = tick2_endpoint + "/balance"
tick1_balance_response = requests.post(tick1_balance_endpoint, json={"address": contract_address})
tick2_balance_response = requests.post(tick2_balance_endpoint, json={"address": contract_address})
tick1_balance = float(tick1_balance_response.json().get('balance', 0))
tick2_balance = float(tick2_balance_response.json().get('balance', 0))
ids.tick1_balance = tick1_balance
ids.tick2_balance = tick2_balance
str = raw_input("tick1 amount"):
ids.token_a_amount = int(str)
%}
tempvar a = token_a_amount;
tempvar x = token_a_balance;
tempvar y = token_b_balance;
let (b, _) = unsigned_div_rem(y * a, x + a);
serialize_word(b);
return();
}