-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (46 loc) · 1.65 KB
/
main.go
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
56
57
58
59
package main
import (
"fmt"
"log"
"math/big"
"hex/amm/v1/exchange"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
client, err := ethclient.Dial("https://mainnet.infura.io/v3/a30f13ea65fe406a86783fa912982906")
if err != nil {
log.Fatal(err)
}
// ammPtr := flag.String("amm", "uniswap", "string")
// fromPtr := flag.String("from", "DAI", "string")
// toPtr := flag.String("to", "USDC", "string")
// var ammMap = make(map[string](*exchange.ExchangeProvider))
// ammMap["uniswap"] = exchange.NewUniswapProvider(client)
// provider, err := exchange.NewUniswapProvider(client)
provider, err := exchange.NewMStableProvider(client)
// provider, err := exchange.NewCurveProvider(client)
if err != nil {
log.Fatal(err)
}
// amountIn := big.NewInt(1e6)
tokenA := "DAI"
tokenB := "USDC"
// amountOut, fee, err := provider.GetAmountOut(tokenA, tokenB, amountIn)
// fmt.Printf("swap %s %s for %s %s with fee: %s \n", tokenA, amountIn.String(), tokenB, amountOut.FloatString(2), fee.FloatString(2))
var i int64
for i = 1; i <= 1e9; i = i * 10 {
amtIn := big.NewInt(i)
amountOut, fee, err := provider.GetAmountOut(tokenA, tokenB, amtIn)
if err != nil {
log.Fatal("cannot do this swap", err)
continue
}
price := new(big.Rat).Mul(new(big.Rat).SetInt64(i), new(big.Rat).Inv(amountOut))
fmt.Printf("swap %s %s for %s %s with price %s and fee: %s \n", tokenA, amtIn.String(), tokenB, amountOut.FloatString(2), price.FloatString(5), fee.FloatString(2))
}
// price, err := provider.GetPriceAfterAmount("DAI", "USDC", million)
// fmt.Printf("new price after swap: %s \n", price.FloatString(8))
if err != nil {
log.Fatal(err)
}
}