-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
41 lines (34 loc) · 1.04 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
package main
import (
"fmt"
"math/big"
"log"
"github.com/KyberNetwork/uniswapv3-sdk-uint256/examples/contract"
"github.com/KyberNetwork/uniswapv3-sdk-uint256/examples/helper"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
log.SetFlags(log.Lshortfile | log.LstdFlags)
client, err := ethclient.Dial(helper.PolygonRPC)
if err != nil {
panic(err)
}
quoterContract, err := contract.NewUniswapv3Quoter(common.HexToAddress(helper.ContractV3Quoter), client)
if err != nil {
panic(err)
}
token0 := common.HexToAddress(helper.WMaticAddr)
token1 := common.HexToAddress(helper.AmpAddr)
fee := big.NewInt(3000)
amountIn := helper.FloatStringToBigInt("1.00", 18)
sqrtPriceLimitX96 := big.NewInt(0)
var out []interface{}
rawCaller := &contract.Uniswapv3QuoterRaw{Contract: quoterContract}
err = rawCaller.Call(nil, &out, "quoteExactInputSingle", token0, token1,
fee, amountIn, sqrtPriceLimitX96)
if err != nil {
log.Fatal(err)
}
fmt.Println("amountOut: ", out[0].(*big.Int).String())
}