Skip to content

Commit

Permalink
fix(KTX): Add configuration for GMX dex-type to select correct contra…
Browse files Browse the repository at this point in the history
…ct function on Mantle (#587)
  • Loading branch information
sunspirit99 authored Nov 14, 2024
1 parent 7cb6ad0 commit 5ee1913
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
9 changes: 6 additions & 3 deletions pkg/source/gmx/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package gmx

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

type Config struct {
DexID string `json:"-"`
VaultAddress string `json:"vaultAddress"`
UseSecondaryPriceFeedV1 bool `json:"useSecondaryPriceFeedV1"`
ChainID valueobject.ChainID `json:"chainID"`
DexID string `json:"dexID"`
VaultAddress string `json:"vaultAddress"`
UseSecondaryPriceFeedV1 bool `json:"useSecondaryPriceFeedV1"`
}
14 changes: 13 additions & 1 deletion pkg/source/gmx/price_feed_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
)

type Param struct {
PriceFeedMethodGetRoundData string
}

type PriceFeedReader struct {
param Param
abi abi.ABI
ethrpcClient *ethrpc.Client
log logger.Logger
}

func NewPriceFeedReader(ethrpcClient *ethrpc.Client) *PriceFeedReader {
return NewPriceFeedReaderWithParam(ethrpcClient, Param{
PriceFeedMethodGetRoundData: priceFeedMethodGetRoundData,
})
}

func NewPriceFeedReaderWithParam(ethrpcClient *ethrpc.Client, param Param) *PriceFeedReader {
return &PriceFeedReader{
param: param,
abi: priceFeedABI,
ethrpcClient: ethrpcClient,
log: logger.WithFields(logger.Fields{
Expand Down Expand Up @@ -50,7 +62,7 @@ func (r *PriceFeedReader) getLatestRoundData(ctx context.Context, address string
rpcRequest.AddCall(&ethrpc.Call{
ABI: r.abi,
Target: address,
Method: priceFeedMethodLatestRoundData,
Method: r.param.PriceFeedMethodGetRoundData,
Params: nil,
}, []interface{}{&latestRoundData})

Expand Down
16 changes: 12 additions & 4 deletions pkg/source/gmx/vault_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"

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

type VaultScanner struct {
Expand All @@ -28,16 +29,23 @@ func NewVaultScanner(
config *Config,
ethrpcClient *ethrpc.Client,
) *VaultScanner {
method := priceFeedMethodLatestRoundData
if config.ChainID == valueobject.ChainIDMantle && config.DexID == string(valueobject.ExchangeKTX) {
method = "latestRound"
}

return &VaultScanner{
config: config,
vaultReader: NewVaultReader(ethrpcClient),
vaultPriceFeedReader: NewVaultPriceFeedReader(ethrpcClient),
fastPriceFeedV1Reader: NewFastPriceFeedV1Reader(ethrpcClient),
fastPriceFeedV2Reader: NewFastPriceFeedV2Reader(ethrpcClient),
priceFeedReader: NewPriceFeedReader(ethrpcClient),
usdgReader: NewUSDGReader(ethrpcClient),
chainlinkFlagsReader: NewChainlinkFlagsReader(ethrpcClient),
pancakePairReader: NewPancakePairReader(ethrpcClient),
priceFeedReader: NewPriceFeedReaderWithParam(ethrpcClient, Param{
PriceFeedMethodGetRoundData: method,
}),
usdgReader: NewUSDGReader(ethrpcClient),
chainlinkFlagsReader: NewChainlinkFlagsReader(ethrpcClient),
pancakePairReader: NewPancakePairReader(ethrpcClient),
log: logger.WithFields(logger.Fields{
"liquiditySource": DexTypeGmx,
"scanner": "VaultScanner",
Expand Down

0 comments on commit 5ee1913

Please sign in to comment.