https://github.com/kybernetwork/elastic-go-sdk
Go SDK for Elastic pool
https://github.com/kybernetwork/elastic-go-sdk
Last synced: 3 months ago
JSON representation
Go SDK for Elastic pool
- Host: GitHub
- URL: https://github.com/kybernetwork/elastic-go-sdk
- Owner: KyberNetwork
- License: mit
- Created: 2023-05-11T02:28:58.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-19T08:59:38.000Z (about 1 year ago)
- Last Synced: 2025-03-30T06:01:52.654Z (3 months ago)
- Language: Go
- Size: 229 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elastic Go SDK
[](https://pkg.go.dev/github.com/KyberNetwork/elastic-go-sdk)
[](https://github.com/KyberNetwork/elastic-go-sdk/actions/workflows/test.yml)
[](https://goreportcard.com/report/github.com/KyberNetwork/elastic-go-sdk)🛠A Go SDK for building applications on top of Elastic
## Installation
```sh
go get github.com/KyberNetwork/elastic-go-sdk
```## Usage
The following example shows how to create a pool, and get the inputAmount
```go
package mainimport (
"fmt"
"math/big"core "github.com/KyberNetwork/uniswap-sdk-core/entities"
"github.com/KyberNetwork/elastic-go-sdk/constants"
"github.com/KyberNetwork/elastic-go-sdk/entities"
"github.com/KyberNetwork/elastic-go-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.TickSpacings[constants.FeeLow]),
LiquidityNet: OneEther,
LiquidityGross: OneEther,
},
{
Index: entities.NearestUsableTick(utils.MaxTick, constants.TickSpacings[constants.FeeLow]),
LiquidityNet: new(big.Int).Mul(OneEther, constants.NegativeOne),
LiquidityGross: OneEther,
},
}// create tick data provider
p, err := entities.NewTickListDataProvider(ticks, constants.TickSpacings[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](./examples/README.md)