Skip to content

Commit

Permalink
feat: use github.com/goccy/go-json (#557)
Browse files Browse the repository at this point in the history
* feat: custom clone funcs for pool. implement for uniswap-v3

to avoid reflection when implemented

* feat: custom clone funcs for swap limits. refactor to common types

* feat: apply uniswapv3 uint256 for pancake-v3

* feat: use github.com/goccy/go-json
  • Loading branch information
NgoKimPhu authored Nov 6, 2024
1 parent cbdea03 commit 789da21
Show file tree
Hide file tree
Showing 333 changed files with 639 additions and 538 deletions.
2 changes: 1 addition & 1 deletion pkg/entity/bestpath.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package entity

import "encoding/json"
import "github.com/goccy/go-json"

const BestPathKey = "bestpaths"

Expand Down
3 changes: 2 additions & 1 deletion pkg/entity/pool.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package entity

import (
"encoding/json"
"math/big"
"strings"

"github.com/goccy/go-json"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/ambient/pool_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package ambient

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/KyberNetwork/logger"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
Expand Down
7 changes: 4 additions & 3 deletions pkg/liquidity-source/ambient/pool_list_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package ambient_test

import (
"context"
"encoding/json"
"fmt"
"math/big"
"os"
"testing"
"time"

"github.com/KyberNetwork/blockchain-toolkit/time/durationjson"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ambient"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/stretchr/testify/require"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ambient"
)

type mockPoolDataStore struct {
Expand Down
7 changes: 4 additions & 3 deletions pkg/liquidity-source/ambient/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package ambient

import (
"context"
"encoding/json"
"fmt"
"math/big"
"time"

"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/KyberNetwork/logger"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
)

type PoolTracker struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/ambient/pool_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package ambient_test

import (
"context"
"encoding/json"
"math/big"
"os"
"testing"

"github.com/KyberNetwork/ethrpc"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/stretchr/testify/require"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
Expand Down
5 changes: 3 additions & 2 deletions pkg/liquidity-source/ambient/types_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package ambient

import (
"encoding/json"
"testing"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/stretchr/testify/require"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
)

func TestNTokenPool_CanSwapTo(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package shared

import (
"context"
"encoding/json"
"math/big"
"net/http"
"time"

"github.com/goccy/go-json"
"github.com/machinebox/graphql"

graphqlpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql"
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/bancor-v21/common_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package bancorv21

import (
"context"
"encoding/json"
"math/big"
"strings"
"time"

"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/logger"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/bancor-v21/pool_simulator.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package bancorv21

import (
"encoding/json"
"errors"
"fmt"
"math/big"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/samber/lo"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/bancor-v21/pool_simulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package bancorv21

import (
"embed"
"encoding/json"
"fmt"
"math/big"
"strings"
"testing"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/bancor-v21/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package bancorv21

import (
"context"
"encoding/json"
"math/big"
"strings"
"time"

"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/logger"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/bancor-v21/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package bancorv21

import (
"context"
"encoding/json"
"time"

"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/bancor-v3/pool_simulator.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package bancorv3

import (
"encoding/json"
"math/big"
"strings"

"github.com/KyberNetwork/blockchain-toolkit/number"
"github.com/goccy/go-json"
"github.com/holiman/uint256"
"github.com/pkg/errors"

Expand Down
5 changes: 3 additions & 2 deletions pkg/liquidity-source/bebop/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package client

import (
"context"
"encoding/json"
"errors"

bebop "github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bebop"
"github.com/KyberNetwork/logger"
"github.com/ethereum/go-ethereum/common"
"github.com/go-resty/resty/v2"
"github.com/goccy/go-json"

bebop "github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bebop"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/bebop/pool_simulator.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package bebop

import (
"encoding/json"
"errors"
"math"
"math/big"
"strings"

"github.com/goccy/go-json"
"github.com/samber/lo"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
Expand Down
5 changes: 3 additions & 2 deletions pkg/liquidity-source/clipper/pool_simulator.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package clipper

import (
"encoding/json"
"errors"
"math"
"math/big"
"strings"

"github.com/goccy/go-json"
"github.com/samber/lo"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber"
"github.com/samber/lo"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions pkg/liquidity-source/clipper/pool_simulator_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package clipper

import (
"encoding/json"
"math/big"
"testing"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/stretchr/testify/assert"
)

var poolEntityStr = "{\"address\":\"0x655edce464cc797526600a462a8154650eee4b77\",\"reserveUsd\":3099576.562241563,\"amplifiedTvl\":3099576.562241563,\"exchange\":\"clipper\",\"type\":\"clipper\",\"timestamp\":1729014768,\"reserves\":[\"491115278550168767440992\",\"597835189535037939399\",\"650931997785\",\"410635515666\"],\"tokens\":[{\"address\":\"0x6b175474e89094c44da98b954eedeac495271d0f\",\"name\":\"Dai Stablecoin\",\"symbol\":\"DAI\",\"decimals\":18},{\"address\":\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\"name\":\"Wrapped Ether\",\"symbol\":\"WETH\",\"decimals\":18},{\"address\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"name\":\"USD Coin\",\"symbol\":\"USDC\",\"decimals\":6},{\"address\":\"0xdac17f958d2ee523a2206206994597c13d831ec7\",\"name\":\"Tether USD\",\"symbol\":\"USDT\",\"decimals\":6}],\"extra\":\"{\\\"SwapsEnabled\\\":true,\\\"K\\\":0.02,\\\"TimeInSeconds\\\":60,\\\"Assets\\\":[{\\\"Address\\\":\\\"0x6b175474e89094c44da98b954eedeac495271d0f\\\",\\\"Symbol\\\":\\\"DAI\\\",\\\"Decimals\\\":18,\\\"PriceInUSD\\\":1,\\\"Quantity\\\":491115278550168767440992,\\\"ListingWeight\\\":250},{\\\"Address\\\":\\\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\\\",\\\"Symbol\\\":\\\"ETH\\\",\\\"Decimals\\\":18,\\\"PriceInUSD\\\":2587.488,\\\"Quantity\\\":597835189535037939399,\\\"ListingWeight\\\":79},{\\\"Address\\\":\\\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\\\",\\\"Symbol\\\":\\\"USDC\\\",\\\"Decimals\\\":6,\\\"PriceInUSD\\\":1,\\\"Quantity\\\":650931997785,\\\"ListingWeight\\\":188},{\\\"Address\\\":\\\"0xdac17f958d2ee523a2206206994597c13d831ec7\\\",\\\"Symbol\\\":\\\"USDT\\\",\\\"Decimals\\\":6,\\\"PriceInUSD\\\":1,\\\"Quantity\\\":410635515666,\\\"ListingWeight\\\":305}],\\\"Pairs\\\":[{\\\"Assets\\\":[\\\"ETH\\\",\\\"USDC\\\"],\\\"FeeInBasisPoints\\\":4},{\\\"Assets\\\":[\\\"ETH\\\",\\\"USDT\\\"],\\\"FeeInBasisPoints\\\":4},{\\\"Assets\\\":[\\\"ETH\\\",\\\"DAI\\\"],\\\"FeeInBasisPoints\\\":4},{\\\"Assets\\\":[\\\"USDC\\\",\\\"USDT\\\"],\\\"FeeInBasisPoints\\\":1},{\\\"Assets\\\":[\\\"USDC\\\",\\\"DAI\\\"],\\\"FeeInBasisPoints\\\":1},{\\\"Assets\\\":[\\\"USDT\\\",\\\"DAI\\\"],\\\"FeeInBasisPoints\\\":0}]}\"}"
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/curve/plain/pool_simulator.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package plain

import (
"encoding/json"
"fmt"
"math/big"
"strings"

"github.com/KyberNetwork/blockchain-toolkit/number"
"github.com/goccy/go-json"
"github.com/holiman/uint256"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package plain

import (
"encoding/json"
"fmt"
"testing"

"github.com/goccy/go-json"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion pkg/liquidity-source/curve/plain/pool_simulator_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package plain

import (
"encoding/json"
"fmt"
"math/big"
"testing"
"time"

"github.com/goccy/go-json"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
11 changes: 6 additions & 5 deletions pkg/liquidity-source/curve/plain/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package plain

import (
"context"
"encoding/json"
"math/big"
"time"

"github.com/KyberNetwork/blockchain-toolkit/number"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/shared"
poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber"
"github.com/KyberNetwork/logger"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
"github.com/goccy/go-json"
"github.com/holiman/uint256"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/shared"
poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber"
)

type PoolTracker struct {
Expand Down
9 changes: 5 additions & 4 deletions pkg/liquidity-source/curve/plain/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package plain

import (
"context"
"encoding/json"
"math/big"
"strings"
"time"

"github.com/KyberNetwork/blockchain-toolkit/number"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/shared"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject"
"github.com/KyberNetwork/logger"
mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/holiman/uint256"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/shared"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject"
)

type PoolsListUpdater struct {
Expand Down
5 changes: 3 additions & 2 deletions pkg/liquidity-source/curve/shared/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package shared

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/KyberNetwork/blockchain-toolkit/time/durationjson"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject"
"github.com/KyberNetwork/logger"
mapset "github.com/deckarep/golang-set/v2"
"github.com/go-resty/resty/v2"
"github.com/goccy/go-json"
"github.com/pkg/errors"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject"
)

type (
Expand Down
Loading

0 comments on commit 789da21

Please sign in to comment.