From f7af14a6dc0b5a38f8d66c9c04a826e8767dfbac Mon Sep 17 00:00:00 2001 From: asolovov Date: Tue, 16 Jan 2024 20:25:25 +0300 Subject: [PATCH] update: add base sepolia configs --- config/chainIDs.go | 3 +++ config/config.go | 30 +++++++++++++++++++++++++++++- perpsv3.go | 4 ++++ services/accounts.go | 12 ++++++------ services/marketData.go | 6 +++--- services/positions.go | 6 +++--- 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/config/chainIDs.go b/config/chainIDs.go index 3be7f7f..ccdc6aa 100644 --- a/config/chainIDs.go +++ b/config/chainIDs.go @@ -8,6 +8,7 @@ const ( BaseMainnet OptimismGoerli BaseAndromeda + BaseSepolia ) var chainIDStrings = [...]string{ @@ -15,6 +16,7 @@ var chainIDStrings = [...]string{ BaseMainnet: "BaseMainnet", OptimismGoerli: "OptimismGoerli", BaseAndromeda: "BaseAndromeda", + BaseSepolia: "BaseSepolia", } var chainIDNums = [...]int{ @@ -22,6 +24,7 @@ var chainIDNums = [...]int{ BaseMainnet: 8453, OptimismGoerli: 420, BaseAndromeda: 84531, + BaseSepolia: 84532, } func (i ChainID) String() string { diff --git a/config/config.go b/config/config.go index f1134a6..69fc2c0 100644 --- a/config/config.go +++ b/config/config.go @@ -56,7 +56,35 @@ func GetOptimismGoerliDefaultConfig(rpcURL string) *PerpsvConfig { } } -// GetBaseAndromedaDefaultConfig is used to get default lib config for base andromeda test net +// GetBaseSepoliaDefaultConfig is used to get default lib config for base sepolia test net +func GetBaseSepoliaDefaultConfig(rpcURL string) *PerpsvConfig { + if rpcURL == "" { + rpcURL = "https://base-sepolia.blockpi.network/v1/rpc/public" + } + + return &PerpsvConfig{ + ChainID: BaseAndromeda, + RPC: rpcURL, + Multicall: &Multicall{ + Retries: 5, + Wait: time.Millisecond * 200, + }, + ContractAddresses: &ContractAddresses{ + Core: "0xF4Df9Dd327Fd30695d478c3c8a2fffAddcdD0d31", + PerpsMarket: "0xE6C5f05C415126E6b81FCc3619f65Db2fCAd58D0", + Forwarder: "0xE2C5658cC5C448B48141168f3e475dF8f65A1e3e", + ERC7412: "0xBf01fE835b3315968bbc094f50AE3164e6d3D969", + }, + FirstContractBlocks: &FirstContractBlocks{ + Core: 4548696, + PerpsMarket: 4548969, + }, + ConnectionTimeout: time.Second * 30, + ReadTimeout: time.Second * 15, + } +} + +// GetBaseAndromedaDefaultConfig is used to get default lib config for base goerli test net func GetBaseAndromedaDefaultConfig(rpcURL string) *PerpsvConfig { if rpcURL == "" { rpcURL = "https://rpc.ankr.com/base_goerli/6259fa6541ffabb10ca241f7f437c2389ab7dda38c7be817ab0fb76992e73ae5" diff --git a/perpsv3.go b/perpsv3.go index 55315a9..c8ff76b 100644 --- a/perpsv3.go +++ b/perpsv3.go @@ -196,6 +196,10 @@ func GetBaseAndromedaDefaultConfig(rpcURL string) *config.PerpsvConfig { return config.GetBaseAndromedaDefaultConfig(rpcURL) } +func GetBaseSepoliaDefaultConfig(rpcURL string) *config.PerpsvConfig { + return config.GetBaseSepoliaDefaultConfig(rpcURL) +} + func GetBaseMainnetDefaultConfig(rpcURL string) *config.PerpsvConfig { return config.GetBaseMainnetDefaultConfig(rpcURL) } diff --git a/services/accounts.go b/services/accounts.go index 573ce60..0d487c2 100644 --- a/services/accounts.go +++ b/services/accounts.go @@ -127,14 +127,14 @@ func (s *Service) GetAvailableMargin(accountId *big.Int) (*big.Int, error) { } func (s *Service) getAvailableMarginMulticallRetries(accountId *big.Int, fails int) (res *big.Int, err error) { - switch s.chainID { - case config.BaseAndromeda: + switch { + case s.chainID == config.BaseAndromeda || s.chainID == config.BaseSepolia: res, err = s.getAvailableMarginMulticallNoPyth(accountId, true) if err != nil && fails <= s.multicallRetries { time.Sleep(s.multicallWait) return s.getAvailableMarginMulticallRetries(accountId, fails+1) } - case config.BaseMainnet: + case s.chainID == config.BaseMainnet: res, err = s.getAvailableMarginMulticall(accountId, true) if err != nil && fails <= s.multicallRetries { time.Sleep(s.multicallWait) @@ -278,14 +278,14 @@ func (s *Service) GetRequiredMaintenanceMargin(accountId *big.Int) (*big.Int, er } func (s *Service) getRequiredMaintenanceMarginRetries(accountId *big.Int, fails int) (res *big.Int, err error) { - switch s.chainID { - case config.BaseAndromeda: + switch { + case s.chainID == config.BaseAndromeda || s.chainID == config.BaseSepolia: res, err = s.getRequiredMaintenanceMarginMulticallNoPyth(accountId, true) if err != nil && fails <= s.multicallRetries { time.Sleep(s.multicallWait) return s.getRequiredMaintenanceMarginRetries(accountId, fails+1) } - case config.BaseMainnet: + case s.chainID == config.BaseMainnet: res, err = s.getRequiredMaintenanceMarginMulticall(accountId, true) if err != nil && fails <= s.multicallRetries { time.Sleep(s.multicallWait) diff --git a/services/marketData.go b/services/marketData.go index f13e075..f42069f 100644 --- a/services/marketData.go +++ b/services/marketData.go @@ -130,14 +130,14 @@ func (s *Service) GetMarketMetadata(marketID *big.Int) (*models.MarketMetadata, } func (s *Service) getMarketSummaryRetries(marketID *big.Int, fails int) (res perpsMarket.IPerpsMarketModuleMarketSummary, err error) { - switch s.chainID { - case config.BaseAndromeda: + switch { + case s.chainID == config.BaseAndromeda || s.chainID == config.BaseSepolia: res, err = s.getMarketSummaryMultiCallNoPyth(marketID, true) if err != nil && fails <= s.multicallRetries { time.Sleep(s.multicallWait) return s.getMarketSummaryRetries(marketID, fails+1) } - case config.BaseMainnet: + case s.chainID == config.BaseMainnet: res, err = s.getMarketSummaryMultiCall(marketID, true) if err != nil && fails <= s.multicallRetries { time.Sleep(s.multicallWait) diff --git a/services/positions.go b/services/positions.go index ed33d60..5a4c60c 100644 --- a/services/positions.go +++ b/services/positions.go @@ -41,14 +41,14 @@ func (s *Service) GetPosition(accountID *big.Int, marketID *big.Int) (*models.Po } func (s *Service) getPositionMultiCallRetries(opts *bind.CallOpts, accountID *big.Int, marketID *big.Int, block *types.Header, fails int) (res *models.Position, err error) { - switch s.chainID { - case config.BaseAndromeda: + switch { + case s.chainID == config.BaseAndromeda || s.chainID == config.BaseSepolia: res, err = s.getPositionMultiCallNoPyth(accountID, marketID, block, true) if err != nil && fails <= s.multicallRetries { time.Sleep(s.multicallWait) return s.getPositionMultiCallRetries(opts, accountID, marketID, block, fails+1) } - case config.BaseMainnet: + case s.chainID == config.BaseMainnet: res, err = s.getPositionMultiCall(accountID, marketID, block, true) if err != nil && fails <= s.multicallRetries { time.Sleep(s.multicallWait)