Class: PandoBot::Lake::Uniswap

Inherits:
Object
  • Object
show all
Defined in:
lib/pando_bot/lake/uniswap.rb

Overview

Uniswap protocal

Instance Method Summary collapse

Constructor Details

#initializeUniswap

Returns a new instance of Uniswap.



8
# File 'lib/pando_bot/lake/uniswap.rb', line 8

def initialize; end

Instance Method Details

#price_impact(x, y, dx, dy) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pando_bot/lake/uniswap.rb', line 40

def price_impact(x, y, dx, dy)
  x = x.to_f
  y = y.to_f
  dx = dx.to_f
  dy = dy.to_f

  return 0 if x.zero? || y.zero?

  [
    (1 - ((y - dy) / (x + dx) / (y / x))),
    0
  ].max.to_f
end

#swap(x, y, dx, k = nil) ⇒ Object

swap A for B x, y is liquidity of A, B dx is supply amount of A k is liquidity of pair



14
15
16
17
18
19
20
21
22
23
# File 'lib/pando_bot/lake/uniswap.rb', line 14

def swap(x, y, dx, k = nil)
  x = x.to_f
  y = y.to_f
  dx = dx.to_f

  _k = (k || (x * y)).to_f
  _x = x + dx
  _y = _k / _x
  y - _y
end

#swap_reverse(x, y, dy, k = nil) ⇒ Object

swap A for B x, y is liquidity of A, B dx is supply amount of A dy is wanted amount of B



29
30
31
32
33
34
35
36
37
38
# File 'lib/pando_bot/lake/uniswap.rb', line 29

def swap_reverse(x, y, dy, k = nil)
  x = x.to_f
  y = y.to_f
  dy = dy.to_f

  _k = (k || (x * y)).to_f
  _y = y - dy
  _x = _k / _y
  _x - x
end