Skip to content

🛠 A Go SDK for building applications on top of Uniswap V2

License

Notifications You must be signed in to change notification settings

Vaulverin/uniswapv2-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uniswap V2 SDK

API Reference Test Go Report Card

🛠 A Go SDK for building applications on top of Uniswap V2

Installation

go get github.com/vaulverin/uniswapv2-sdk

Usage

package main

import (
	core "github.com/daoleno/uniswap-sdk-core/entities"
	"github.com/ethereum/go-ethereum/common"
	"github.com/vaulverin/uniswapv2-sdk/entities"
	"github.com/vaulverin/uniswapv2-sdk/router"
	"log"
	"math/big"
)

func main() {
	ether = core.EtherOnChain(1)
	token0 = core.NewToken(1, common.HexToAddress("0x0000000000000000000000000000000000000001"), 18, "t0", "t0")
	token1 = core.NewToken(1, common.HexToAddress("0x0000000000000000000000000000000000000002"), 18, "t1", "t1")

	pair_0_1, _ = entities.NewPair(
		core.FromRawAmount(token0, big.NewInt(1000)),
		core.FromRawAmount(token1, big.NewInt(1000)),
		nil,
	)
	pair_weth_0, _ = entities.NewPair(
		core.FromRawAmount(core.WETH9[1], big.NewInt(1000)),
		core.FromRawAmount(token0, big.NewInt(1000)),
		nil,
	)

	route, _ := entities.NewRoute([]*entities.Pair{pair_weth_0, pair_0_1}, ether, token1)
	trade, _ := entities.ExactIn(route, core.FromRawAmount(ether, big.NewInt(100)))
	swapParams, _ := router.SwapCallParameters(trade, router.TradeOptions{
		AllowedSlippage: core.NewPercent(big.NewInt(1), big.NewInt(100)),
		Recipient:       common.HexToAddress("0x0000000000000000000000000000000000000004"),
		Deadline:        big.NewInt(time.Now().Add(30 * time.Second).Unix()),
	})

	log.Println(swapParams.MethodName)
	log.Println(swapParams.Args)
	log.Println(swapParams.Value)
}

Look for more examples in tests.

About

🛠 A Go SDK for building applications on top of Uniswap V2

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages