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

Overview

Uniswap V3 SDK

API Reference Test Go Report Card

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

Installation

go get github.com/daoleno/uniswapv3-sdk

Usage

The following example shows how to create a pool, and get the inputAmount

DAI outputAmount := core.FromRawAmount(DAI.Currency, big.NewInt(98)) inputAmount, _, err := pool.GetInputAmount(outputAmount, nil) if err != nil { panic(err) } fmt.Println(inputAmount.ToSignificant(4)) } ">
package main

import (
	"fmt"
	"math/big"

	core "github.com/daoleno/uniswap-sdk-core/entities"
	"github.com/daoleno/uniswapv3-sdk/constants"
	"github.com/daoleno/uniswapv3-sdk/entities"
	"github.com/daoleno/uniswapv3-sdk/utils"
	"github.com/ethereum/go-ethereum/common"
)

var (
	USDC     = core.NewToken(1, common.HexToAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"), 6, "USDC", "USD Coin")
	DAI      = core.NewToken(1, common.HexToAddress("0x6B175474E89094C44Da98b954EedeAC495271d0F"), 18, "DAI", "Dai Stablecoin")
	OneEther = big.NewInt(1e18)
)

func main() {
	// create demo ticks
	ticks := []entities.Tick{
		{
			Index:          entities.NearestUsableTick(utils.MinTick, constants.TickSpaces[constants.FeeLow]),
			LiquidityNet:   OneEther,
			LiquidityGross: OneEther,
		},
		{
			Index:          entities.NearestUsableTick(utils.MaxTick, constants.TickSpaces[constants.FeeLow]),
			LiquidityNet:   new(big.Int).Mul(OneEther, constants.NegativeOne),
			LiquidityGross: OneEther,
		},
	}

	// create tick data provider
	p, err := entities.NewTickListDataProvider(ticks, constants.TickSpaces[constants.FeeLow])
	if err != nil {
		panic(err)
	}

	// new pool
	pool, err := entities.NewPool(USDC, DAI, constants.FeeLow, utils.EncodeSqrtRatioX96(constants.One, constants.One), OneEther, 0, p)
	if err != nil {
		panic(err)
	}

	// USDC -> DAI
	outputAmount := core.FromRawAmount(DAI.Currency, big.NewInt(98))
	inputAmount, _, err := pool.GetInputAmount(outputAmount, nil)
	if err != nil {
		panic(err)
	}
	fmt.Println(inputAmount.ToSignificant(4))
}

More Examples

Issues
  • Implement atomic swaps

    Implement atomic swaps

    opened by alienatorZ 2
  • Token has no field or method Currency

    Token has no field or method Currency

    github.com/daoleno/uniswapv3-sdk v0.3.0

    DAI.Currency undefined (type *"github.com/daoleno/uniswap-sdk-core/entities".Token has no field or method Currency)

    opened by Shuixingchen 1
  • abi can not pack (Standard)PermitArguments

    abi can not pack (Standard)PermitArguments

    abi: cannot use uint as type uint8 as argument when calling abi.Pack("selfPermit", token.Address, options.Amount, options.Deadline, options.V, options.R, options.S) in selfpermit.go

    opened by andrewelkin 1
  • "invalid tick index" incorrect check

    https://github.com/daoleno/uniswapv3-sdk/blob/master/entities/ticklist.go#L60-L62

    func GetTick(ticks []Tick, index int) Tick {
    	tick := ticks[binarySearch(ticks, index)]
    	if tick.Index <= 0 {
    		panic("invalid tick index")
    	}
    	return tick
    }
    

    Hi @daoleno ,

    I think this function should be something like

    func GetTick(ticks []Tick, index int) Tick {
            tickIndex := binarySearch(ticks, index)
            if tickIndex < 0 {
    		panic("invalid tick index")
    	}
    	tick := ticks[tickIndex]
    
    	return tick
    }
    

    Because tick.Index can be negative. Am I right?

    opened by piavgh 1
  • How to use auto permit(allowance) when operating the position?

    How to use auto permit(allowance) when operating the position?

    Hi, guys. Thanks for sharing this SDK.

    I have a question about auto perimting allowance when calling mutilcall. I saw two parameters (Token0Permit, Token1Permit) in CommonAddLiquidityOptions:

    //  Options for producing the calldata to add liquidity
    type CommonAddLiquidityOptions struct {
    	SlippageTolerance *core.Percent  // How much the pool price is allowed to move
    	Deadline          *big.Int       // When the transaction expires, in epoch seconds
    	UseNative         *core.Ether    // Whether to spend ether. If true, one of the pool tokens must be WETH, by default false
    	Token0Permit      *PermitOptions // The optional permit parameters for spending token0
    	Token1Permit      *PermitOptions // The optional permit parameters for spending token1
    }
    

    These two permit parameters defined in https://github.com/daoleno/uniswapv3-sdk/blob/master/periphery/selfpermit.go

    I know it would be wrapped in AddCallParameters automatically. But I don't know how to wrap the VRS(signature data). Can you give me a simple example for calling AddCallParameters with perimited parameters?

    opened by leyafo 2
Releases(v0.3.1)
Owner
daoleno
software engineer
daoleno
A go sdk for baidu netdisk open platform 百度网盘开放平台 Go SDK

Pan Go Sdk 该代码库为百度网盘开放平台Go语言的SDK

Jsyz Chen 71 Jun 15, 2022
Nextengine-sdk-go: the NextEngine SDK for the Go programming language

NextEngine SDK for Go nextengine-sdk-go is the NextEngine SDK for the Go programming language. Getting Started Install go get github.com/takaaki-s/nex

null 0 Dec 7, 2021
Commercetools-go-sdk is fork of original commercetools-go-sdk

commercetools-go-sdk The Commercetools Go SDK is automatically generated based on the official API specifications of Commercetools. It should therefor

Flink 0 Dec 13, 2021
Sdk-go - Go version of the Synapse SDK

synapsesdk-go Synapse Protocol's Go SDK. Currently in super duper alpha, do not

null 0 Jan 7, 2022
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go

Redash Go SDK An SDK for the programmatic management of Redash. The main compone

RecoLabs 24 Mar 3, 2022
Building block for mobile money api clients

base the base code for creating mobile money api clients using golang build request request := NewRequestBuilder("login request", http.MethodPost, "ht

TECHCRAFT TECHNOLOGIES LIMITED 3 Jan 4, 2022
AWS SDK for the Go programming language.

AWS SDK for Go aws-sdk-go is the official AWS SDK for the Go programming language. Checkout our release notes for information about the latest bug fix

Amazon Web Services 7.7k Jul 4, 2022
A Facebook Graph API SDK For Go.

A Facebook Graph API SDK In Golang This is a Go package that fully supports the Facebook Graph API with file upload, batch request and marketing API.

Huan Du 1.1k Jun 27, 2022
A Golang SDK for Medium's OAuth2 API

Medium SDK for Go This repository contains the open source SDK for integrating Medium's OAuth2 API into your Go app. Install go get github.com/Medium/

Medium 131 May 18, 2022
MinIO Client SDK for Go

MinIO Go Client SDK for Amazon S3 Compatible Cloud Storage The MinIO Go Client SDK provides simple APIs to access any Amazon S3 compatible object stor

High Performance, Kubernetes Native Object Storage 1.6k Jun 30, 2022
Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK)

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Rohan Verma 87 Jun 10, 2022
Twilight is an unofficial Golang SDK for Twilio APIs

Twilight is an unofficial Golang SDK for Twilio APIs. Twilight was born as a result of my inability to spell Twilio correctly. I searched for a Twillio Golang client library and couldn’t find any, I decided to build one. Halfway through building this, I realized I had spelled Twilio as Twillio when searching for a client library on Github.

Ghvst Code 18 Jul 2, 2021
Wechat Pay SDK(V3) Write by Go.

WechatPay GO(v3) Introduction Wechat Pay SDK(V3) Write by Go. API V3 of Office document is here. Features Signature/Verify messages Encrypt/Decrypt ce

luoji 23 May 23, 2022
Go Wechaty is a Conversational SDK for Chatbot Makers Written in Go

go-wechaty Connecting Chatbots Wechaty is a RPA SDK for Wechat Individual Account that can help you create a chatbot in 6 lines of Go. Voice of the De

Wechaty 241 Jul 2, 2022
An easy-to-use unofficial SDK for Feishu and Lark Open Platform

go-lark go-lark is an easy-to-use unofficial SDK for Feishu and Lark Open Platform. go-lark implements messaging APIs, with full-fledged supports on b

go-lark-sdk 98 Jun 21, 2022
A go SDK for the data available via data.gov.gr

go-data-gov-gr-sdk A Go based SDK to access the public data provided by the Greek Government and are available at https://www.data.gov.gr/ Quick Start

Papapetrou Patroklos 23 Jan 24, 2022
weixin/wechat/微信公众平台/微信企业号/微信商户平台/微信支付 go/golang sdk

wechat SDK for golang https://github.com/chanxuehong/wechat 招人啦 golang 后端的坑, 趣头条集团下面的创新团队, 现在步入正常轨道了, 前景很好. 要求: golang中高级 自驱、有责任心 沟通没有问题 待遇: open, 看能力

chanxuehong 2.4k Jun 22, 2022
SDK for Yigim Payment Gateway

Yigim gateway SDK The package provides ability to access the Yigim payment's api via the Go language. Usage To install run: go get github.com/paladium

Ilkin Musayev 4 Oct 5, 2021
DipDup Golang SDK

General instruments for DipDup in golang

DipDup 9 Jun 8, 2022