Skip to content

Commit

Permalink
update: add base sepolia configs
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovov committed Jan 16, 2024
1 parent ead3af0 commit f7af14a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
3 changes: 3 additions & 0 deletions config/chainIDs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ const (
BaseMainnet
OptimismGoerli
BaseAndromeda
BaseSepolia
)

var chainIDStrings = [...]string{
Unknown: "Unknown",
BaseMainnet: "BaseMainnet",
OptimismGoerli: "OptimismGoerli",
BaseAndromeda: "BaseAndromeda",
BaseSepolia: "BaseSepolia",
}

var chainIDNums = [...]int{
Unknown: 0,
BaseMainnet: 8453,
OptimismGoerli: 420,
BaseAndromeda: 84531,
BaseSepolia: 84532,
}

func (i ChainID) String() string {
Expand Down
30 changes: 29 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions perpsv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions services/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions services/marketData.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions services/positions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f7af14a

Please sign in to comment.