-
Notifications
You must be signed in to change notification settings - Fork 0
/
arbitrage.mpc
47 lines (39 loc) · 1.68 KB
/
arbitrage.mpc
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
exec(open("../cfmms.mpc").read())
exec(open("../router.mpc").read())
exec(open("../optimizers.mpc").read())
# Skeleton code. Doesn't compile as of Nov 18
program.use_split(4)
sfix.round_nearest = True
cfix.set_precision(f=32, k=128)
sfix.set_precision(f=32, k=128)
# Enable the below parameter for optimizations
#program.use_edabit(True)
# Create pools
reserves_eq = Matrix(2, 1, sfix)
reserves_eq.assign([1000000, 1000000])
globals_eq = Array.create_from([regint(0), regint(1)])
fee = sfix(1)
equal_pool = ProductTwoCoinCFMM(reserves_eq, fee, globals_eq)
reserves_uneq = Matrix(2, 1, sfix)
reserves_uneq.assign([1000, 2000])
globals_uneq = Array.create_from([regint(0), regint(1)])
unequal_small_pool = ProductTwoCoinCFMM(reserves_uneq, fee, globals_uneq)
reserves_weighted = Matrix(2, 1, sfix)
reserves_weighted.assign([1000, 2000])
globals_weighted = Array.create_from([regint(0), regint(1)])
weights = Matrix(2, 1, sfix)
weights.assign([round(0.4 * (2**32)), round(0.6 * (2**32))])
weighted_pool = GeometricMeanTwoCoinCFMM(reserves_weighted, weights, fee, globals_weighted)
# Get market price vector
# Just get the market price of assets from a player. Will change to MPCaaS setting client later.
price_vector = Matrix(2, 1, sfix)
price_vector.assign(sfix.get_input_from(0, size=2))
lin_obj = LinearNonnegative(price_vector)
l_bfgs_b_opt = L_BFGS_BOptimizer(lin_obj, 2)
router = ArbitrageRouter([equal_pool, unequal_small_pool, weighted_pool], 2, lin_obj)
router.route(l_bfgs_b_opt, price_vector=price_vector)
net_trade = router.netflows()
price_vector_tmp = Matrix(1, 2, sfix)
price_vector_tmp.assign(router.v)
net_trade.print_reveal_nested()
print_ln("Profit: %s", price_vector_tmp.dot(net_trade).reveal())