Skip to content

Commit

Permalink
wip: integrate mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovov committed Dec 19, 2023
1 parent 0724373 commit 8d1877e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ generate-perps_market-andromeda:

# generate go file for PerpsMarket contract on andromeda net from cannon abi
generate-perps_market-andromeda-c:
go run ./utils/getAbis/get-abis.go --get-mkdir ./cannon-synthetix/andromeda/perpsFactory/PerpsMarketProxy.json ./contracts/perpsMarket
go run ./utils/getAbis/get-abis.go --get-mkdir ./cannon-synthetix/base/perpsFactory/PerpsMarketProxy.json ./contracts/perpsMarket
abigen --abi=./contracts/PerpsMarketProxy.json --pkg=perpsMarket --out=./contracts/perpsMarket/contract.go

# generate go file for snxUSDT contract on andromeda net
Expand All @@ -42,6 +42,11 @@ update-subtree:
fetch-cannon-andromeda:
cannon inspect synthetix-omnibus:latest@andromeda --chain-id 84531 -w ./cannon-synthetix/andromeda --sources

# fetch ABIs from cannon
fetch-cannon-base:
cannon inspect synthetix-omnibus:latest@andromeda --chain-id 8453 -w ./cannon-synthetix/base --sources


# generate mock for service interface for testing
mock-service:
mockgen -source=services/service.go -destination=mocks/service/mockService.go
Expand Down
3 changes: 3 additions & 0 deletions config/chainIDs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ type ChainID int

const (
Unknown ChainID = iota
BaseMainnet
OptimismGoerli
BaseAndromeda
)

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

var chainIDNums = [...]int{
Unknown: 0,
BaseMainnet: 8453,
OptimismGoerli: 420,
BaseAndromeda: 84513,
}
Expand Down
26 changes: 24 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ func GetBaseAndromedaDefaultConfig(rpcURL string) *PerpsvConfig {
rpcURL = "https://base.fastnode.cc/FNGfsgKFzvLlFKHWrNUYOWIgFRTdiAcVrtAxSMbMfZGdKDUDFgagkwnDgxPqgBit/"
}

//https://rpc.goerli.base.gateway.fm

return &PerpsvConfig{
ChainID: BaseAndromeda,
RPC: rpcURL,
Expand All @@ -75,3 +73,27 @@ func GetBaseAndromedaDefaultConfig(rpcURL string) *PerpsvConfig {
ReadTimeout: time.Second * 15,
}
}

// GetBaseMainnetDefaultConfig is used to get default lib config for base main net
func GetBaseMainnetDefaultConfig(rpcURL string) *PerpsvConfig {
if rpcURL == "" {
rpcURL = "https://rpc.ankr.com/base"
}

return &PerpsvConfig{
ChainID: BaseMainnet,
RPC: rpcURL,
ContractAddresses: &ContractAddresses{
Core: "0x32C222A9A159782aFD7529c87FA34b96CA72C696",
PerpsMarket: "0x0A2AF931eFFd34b81ebcc57E3d3c9B1E1dE1C9Ce",
Forwarder: "",
ERC7412: "",
},
FirstContractBlocks: &FirstContractBlocks{
Core: 7889212,
PerpsMarket: 7889389,
},
ConnectionTimeout: time.Second * 30,
ReadTimeout: time.Second * 15,
}
}
9 changes: 8 additions & 1 deletion examples/new_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
perpsv3_Go "github.com/gateway-fm/perpsv3-Go"
"log"
"math/big"
)

func main() {
Expand All @@ -11,13 +12,19 @@ func main() {

//conf := perpsv3_Go.GetOptimismGoerliDefaultConfig(rpcURL)
// OR you can use base andromeda chain
conf := perpsv3_Go.GetBaseAndromedaDefaultConfig(rpcURL)
conf := perpsv3_Go.GetBaseMainnetDefaultConfig(rpcURL)

lib, err := perpsv3_Go.Create(conf)
if err != nil {
log.Fatal(err)
}

res, err := lib.GetMarketSummary(big.NewInt(200))
if err != nil {
log.Fatal(err)
}
log.Println(res)

//...
// call needed methods
// ...
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 GetBaseMainnetDefaultConfig(rpcURL string) *config.PerpsvConfig {
return config.GetBaseMainnetDefaultConfig(rpcURL)
}

func (p *Perpsv3) RetrieveTrades(fromBlock uint64, toBLock *uint64) ([]*models.Trade, error) {
return p.service.RetrieveTrades(fromBlock, toBLock)
}
Expand Down

0 comments on commit 8d1877e

Please sign in to comment.