Skip to content

Commit

Permalink
feat : Expand Curve(two-crypto) on sonic (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunspirit99 authored Jan 10, 2025
1 parent 9b9c869 commit 8803f88
Show file tree
Hide file tree
Showing 11 changed files with 7,560 additions and 402 deletions.
1,293 changes: 1,224 additions & 69 deletions pkg/liquidity-source/curve/plain/abi/CurvePlain.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion pkg/liquidity-source/curve/shared/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ const (
// might not available for all chains, but we only need for some chains so it's ok
CurveAddressProvider = "0x0000000022d53366457f9d5e68ec105046fc4383"

// https://sonicscan.org/address/0x87fe17697d0f14a222e8bef386a0860ecffdd617#code
CurveAddressProvider_Sonic = "0x87fe17697d0f14a222e8bef386a0860ecffdd617"

poolMethodGamma = "gamma"
poolMethodUnderlyingCoins = "underlying_coins"

addressProviderMethodGetAddress = "get_address"

getPoolsEndpoint = "/api/getPools/%s/%s" // <chain>/<registry>
getPoolsEndpoint = "/v1/getPools/%s/%s" // <chain>/<registry>
)
8 changes: 7 additions & 1 deletion pkg/liquidity-source/curve/shared/data_source_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/big"

"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject"
"github.com/KyberNetwork/logger"
"github.com/ethereum/go-ethereum/common"
)
Expand All @@ -25,9 +26,14 @@ func InitDataSourceAddresses(lg logger.Logger, config *Config, ethrpcClient *eth

calls := ethrpcClient.NewRequest()

curveAddressProvider := CurveAddressProvider
if config.ChainID == valueobject.ChainIDSonic {
curveAddressProvider = CurveAddressProvider_Sonic
}

calls.AddCall(&ethrpc.Call{
ABI: addressProviderABI,
Target: CurveAddressProvider,
Target: curveAddressProvider,
Method: addressProviderMethodGetAddress,
Params: []interface{}{big.NewInt(0)},
}, []interface{}{&mainRegistryAddress})
Expand Down
1 change: 1 addition & 0 deletions pkg/liquidity-source/curve/shared/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (u *PoolsListUpdater) GetNewPoolsFromDataSource(ctx context.Context, dataSo
req := u.client.R().SetContext(ctx)

var result GetPoolsResult

resp, err := req.SetResult(&result).Get(fmt.Sprintf(getPoolsEndpoint, u.config.ChainCode, dataSource))
if err != nil {
return nil, err
Expand Down
1,698 changes: 1,616 additions & 82 deletions pkg/liquidity-source/curve/stable-meta-ng/abi/CurveStableMetaNG.json

Large diffs are not rendered by default.

1,526 changes: 1,451 additions & 75 deletions pkg/liquidity-source/curve/stable-ng/abi/CurveStableNG.json

Large diffs are not rendered by default.

1,888 changes: 1,796 additions & 92 deletions pkg/liquidity-source/curve/tricrypto-ng/abi/CurveTricryptoNG.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/liquidity-source/curve/tricrypto-ng/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var (
NumTokensU256 = uint256.NewInt(NumTokens)

// only support CurveTricryptoOptimizedWETH.vy for now
SupportedImplementation = mapset.NewSet("tricrypto-1")
SupportedImplementation = mapset.NewSet("tricrypto-1", "tricrypto-optimized")

Precision = U_1e18
)
Expand Down
8 changes: 5 additions & 3 deletions pkg/liquidity-source/curve/tricrypto-ng/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ func (u *PoolsListUpdater) initPools(_ context.Context, curvePools []shared.Curv
continue
}

if !SupportedImplementation.Contains(curvePool.Implementation) {
lg.Debugf("ignore pool with implementation=%s", curvePool.Implementation)
continue
if curvePool.Implementation != "" {
if !SupportedImplementation.Contains(curvePool.Implementation) {
lg.Debugf("ignore pool with implementation=%s", curvePool.Implementation)
continue
}
}

poolTokens := make([]*entity.PoolToken, 0, len(curvePool.Coins))
Expand Down
1,525 changes: 1,450 additions & 75 deletions pkg/liquidity-source/curve/twocrypto-ng/abi/CurveTwocryptoNG.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pkg/liquidity-source/curve/twocrypto-ng/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ func (u *PoolsListUpdater) initPools(_ context.Context, curvePools []shared.Curv
continue
}

if !SupportedImplementation.Contains(curvePool.Implementation) {
lg.Debugf("ignore pool with implementation=%s", curvePool.Implementation)
continue
if curvePool.Implementation != "" {
if !SupportedImplementation.Contains(curvePool.Implementation) {
lg.Debugf("ignore pool with implementation=%s", curvePool.Implementation)
continue
}
}

poolTokens := make([]*entity.PoolToken, 0, len(curvePool.Coins))
Expand Down

0 comments on commit 8803f88

Please sign in to comment.