-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate savings-usds/sky-psm (#723)
* add testutil.TestCalcAmountIn * simplify block timestamp * use MulDivOverflow * use common pool type
- Loading branch information
1 parent
7c14bb4
commit 14702ed
Showing
32 changed files
with
1,057 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package savingsdai | ||
|
||
type Config struct { | ||
DexID string `json:"dexID"` | ||
DepositToken string `json:"depositToken"` | ||
SavingsToken string `json:"savingsToken"` | ||
Pot string `json:"pot"` | ||
// ssr (Sky Savings Rate) | dsr (DAI Savings Rate) | ||
SavingsRateSymbol string `json:"savingsRateSymbol"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
pkg/liquidity-source/maker/savingsdai/pool_list_updater.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package savingsdai | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/KyberNetwork/ethrpc" | ||
"github.com/KyberNetwork/logger" | ||
"github.com/goccy/go-json" | ||
|
||
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" | ||
poollist "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool/list" | ||
) | ||
|
||
type PoolListUpdater struct { | ||
config *Config | ||
ethrpcClient *ethrpc.Client | ||
initialized bool | ||
} | ||
|
||
var _ = poollist.RegisterFactoryCE(DexType, NewPoolListUpdater) | ||
|
||
func NewPoolListUpdater(config *Config, ethrpcClient *ethrpc.Client) *PoolListUpdater { | ||
return &PoolListUpdater{ | ||
config: config, | ||
ethrpcClient: ethrpcClient, | ||
} | ||
} | ||
|
||
func (u *PoolListUpdater) GetNewPools(_ context.Context, metadataBytes []byte) ([]entity.Pool, []byte, error) { | ||
logger.WithFields(logger.Fields{ | ||
"dexType": u.config.DexID, | ||
}).Infof("Start updating pools list ...") | ||
defer func() { | ||
logger.WithFields(logger.Fields{ | ||
"dexType": u.config.DexID, | ||
}).Infof("Finish updating pools list.") | ||
}() | ||
|
||
if u.initialized { | ||
logger.WithFields(logger.Fields{ | ||
"dexType": u.config.DexID, | ||
}).Infof("Pools have been initialized.") | ||
return nil, metadataBytes, nil | ||
} | ||
|
||
staticExtra := StaticExtra{ | ||
Pot: u.config.Pot, | ||
SavingsRateSymbol: u.config.SavingsRateSymbol, | ||
} | ||
|
||
staticExtraBytes, err := json.Marshal(staticExtra) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
pool := entity.Pool{ | ||
Address: u.config.SavingsToken, | ||
Exchange: u.config.DexID, | ||
Type: DexType, | ||
Reserves: entity.PoolReserves{"0", "0"}, | ||
Tokens: []*entity.PoolToken{ | ||
{ | ||
Address: strings.ToLower(u.config.DepositToken), | ||
Swappable: true, | ||
}, | ||
{ | ||
Address: strings.ToLower(u.config.SavingsToken), | ||
Swappable: true, | ||
}, | ||
}, | ||
StaticExtra: string(staticExtraBytes), | ||
} | ||
|
||
u.initialized = true | ||
|
||
return []entity.Pool{pool}, metadataBytes, nil | ||
} |
85 changes: 85 additions & 0 deletions
85
pkg/liquidity-source/maker/savingsdai/pool_list_updater_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package savingsdai | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/KyberNetwork/ethrpc" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/goccy/go-json" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
|
||
poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" | ||
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject" | ||
) | ||
|
||
type PoolListUpdaterTestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func (ts *PoolListUpdaterTestSuite) TestGetNewPools() { | ||
rpcClientByChainID := map[valueobject.ChainID]*ethrpc.Client{ | ||
1: ethrpc.New("https://ethereum.kyberengineering.io"). | ||
SetMulticallContract(common.HexToAddress("0x5ba1e12693dc8f9c48aad8770482f4739beed696")), | ||
} | ||
|
||
testCases := []struct { | ||
chainID valueobject.ChainID | ||
config Config | ||
}{ | ||
{ | ||
chainID: valueobject.ChainIDEthereum, | ||
config: Config{ | ||
DepositToken: "0x6b175474e89094c44da98b954eedeac495271d0f", | ||
SavingsToken: "0x83f20f44975d03b1b09e64809b757c47f942beea", | ||
Pot: "0x197e90f9fad81970ba7976f33cbd77088e5d7cf7", | ||
SavingsRateSymbol: "dsr", | ||
}, | ||
}, | ||
{ | ||
chainID: valueobject.ChainIDEthereum, | ||
config: Config{ | ||
DepositToken: "0xdc035d45d973e3ec169d2276ddab16f1e407384f", | ||
SavingsToken: "0xa3931d71877c0e7a3148cb7eb4463524fec27fbd", | ||
Pot: "0xa3931d71877c0e7a3148cb7eb4463524fec27fbd", | ||
SavingsRateSymbol: "ssr", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
ts.T().Run(tc.config.DexID, func(t *testing.T) { | ||
updater := PoolListUpdater{ | ||
config: &tc.config, | ||
ethrpcClient: rpcClientByChainID[tc.chainID], | ||
initialized: false, | ||
} | ||
|
||
tracker := NewPoolTracker( | ||
&tc.config, | ||
rpcClientByChainID[tc.chainID], | ||
) | ||
|
||
pools, _, err := updater.GetNewPools(context.Background(), nil) | ||
require.NoError(t, err) | ||
require.NotNil(t, pools) | ||
|
||
for _, pool := range pools { | ||
entityPool, err := tracker.GetNewPoolState(context.Background(), pool, poolpkg.GetNewPoolStateParams{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, entityPool) | ||
|
||
prettyJSON, err := json.MarshalIndent(entityPool, "", " ") | ||
require.NoError(t, err) | ||
require.NotNil(t, pools) | ||
t.Log(string(prettyJSON)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestPoolListUpdaterTestSuite(t *testing.T) { | ||
// t.Skip("Skipping testing in CI environment") | ||
suite.Run(t, new(PoolListUpdaterTestSuite)) | ||
} |
Oops, something went wrong.