Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: market stage one #1821

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion blockchain/addresses.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package blockchain

import "fmt"

const (
defaultContractRegistryAddr = "0xd1a6f3d1ae33b4b19565a6b283d7a05c5a0decb0"

sidechainSNMAddressKey = "sidechainSNMAddress"
masterchainSNMAddressKey = "masterchainSNMAddress"
blacklistAddressKey = "blacklistAddress"
marketAddressKey = "marketAddress"
profileRegistryAddressKey = "profileRegistryAddress"
oracleUsdAddressKey = "oracleUsdAddress"
gatekeeperMasterchainAddressKey = "gatekeeperMasterchainAddress"
gatekeeperSidechainAddressKey = "gatekeeperSidechainAddress"
testnetFaucetAddressKey = "testnetFaucetAddress"
oracleMultiSigAddressKey = "oracleMultiSigAddress"
)

func marketAddressKey(version uint) (string, error) {
switch version {
case 1:
return "marketAddress", nil
case 2:
return "marketV2Address", nil
default:
return "", fmt.Errorf("invalid market version %d", version)
}
}
14 changes: 9 additions & 5 deletions blockchain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func NewAPI(ctx context.Context, opts ...Option) (API, error) {
}

func (api *BasicAPI) setupContractRegistry(ctx context.Context) error {
registry, err := NewRegistry(ctx, api.options.contractRegistry, api.options.sidechain)
registry, err := NewRegistry(ctx, api.options.version, api.options.contractRegistry, api.options.sidechain)
if err != nil {
return fmt.Errorf("failed to setup contract registry: %s", err)
}
Expand Down Expand Up @@ -391,7 +391,7 @@ func (api *BasicAPI) ContractRegistry() ContractRegistry {
return api.contractRegistry
}

func NewRegistry(ctx context.Context, address common.Address, opts *chainOpts) (*BasicContractRegistry, error) {
func NewRegistry(ctx context.Context, version uint, address common.Address, opts *chainOpts) (*BasicContractRegistry, error) {
client, err := opts.getClient()
if err != nil {
return nil, err
Expand All @@ -405,7 +405,7 @@ func NewRegistry(ctx context.Context, address common.Address, opts *chainOpts) (
registry := &BasicContractRegistry{
registryContract: contract,
}
if err := registry.setup(ctx); err != nil {
if err := registry.setup(ctx, version); err != nil {
return nil, err
}
return registry, nil
Expand Down Expand Up @@ -444,15 +444,19 @@ func (m *BasicContractRegistry) readContract(ctx context.Context, key string, ta
return nil
}

func (m *BasicContractRegistry) setup(ctx context.Context) error {
func (m *BasicContractRegistry) setup(ctx context.Context, version uint) error {
marketKey, err := marketAddressKey(version)
if err != nil {
return err
}
addresses := []struct {
key string
target *common.Address
}{
{sidechainSNMAddressKey, &m.sidechainSNMAddress},
{masterchainSNMAddressKey, &m.masterchainSNMAddress},
{blacklistAddressKey, &m.blacklistAddress},
{marketAddressKey, &m.marketAddress},
{marketKey, &m.marketAddress},
{profileRegistryAddressKey, &m.profileRegistryAddress},
{oracleUsdAddressKey, &m.oracleUsdAddress},
{gatekeeperMasterchainAddressKey, &m.gatekeeperMasterchainAddress},
Expand Down
8 changes: 8 additions & 0 deletions blockchain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Config struct {
ContractRegistryAddr common.Address
BlocksBatchSize uint64
MasterchainGasPrice *big.Int
Version uint
}

func NewDefaultConfig() (*Config, error) {
Expand All @@ -32,6 +33,7 @@ func NewDefaultConfig() (*Config, error) {
Endpoint: *endpoint,
SidechainEndpoint: *sidechainEndpoint,
ContractRegistryAddr: common.HexToAddress(defaultContractRegistryAddr),
Version: defaultVersion,
}, nil
}

Expand All @@ -42,6 +44,7 @@ func (m *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
ContractRegistryAddr common.Address `yaml:"contract_registry"`
BlocksBatchSize uint64 `yaml:"blocks_batch_size"`
MasterchainGasPrice GasPrice `yaml:"masterchain_gas_price"`
Version uint `yaml:"version"`
}

if err := unmarshal(&cfg); err != nil {
Expand All @@ -56,6 +59,10 @@ func (m *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
cfg.SidechainEndpoint = defaultSidechainEndpoint
}

if cfg.Version == 0 {
cfg.Version = defaultVersion
}

endpoint, err := url.Parse(cfg.MasterchainEndpoint)
if err != nil {
return err
Expand All @@ -75,6 +82,7 @@ func (m *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
m.ContractRegistryAddr = cfg.ContractRegistryAddr
m.BlocksBatchSize = cfg.BlocksBatchSize
m.MasterchainGasPrice = cfg.MasterchainGasPrice.Int
m.Version = cfg.Version

return nil
}
6 changes: 3 additions & 3 deletions blockchain/gasLimits.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const (
approveGasLimit = 70000
placeOrderGasLimit = 650000
cancelOrderGasLimit = 300000
quickBuyGasLimit = 1200000
openDealGasLimit = 600000
quickBuyGasLimit = 1300000
openDealGasLimit = 800000
closeDealGasLimit = 250000
billGasLimit = 300000
createChangeRequestGasLimit = 300000
Expand All @@ -25,5 +25,5 @@ const (
)

func devicesGasLimit(size uint64) uint64 {
return 200000 + size/32*20000
return 400000 + size/32*31000
}
11 changes: 10 additions & 1 deletion blockchain/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const (
defaultLogParsePeriod = time.Second
defaultMasterchainGasLimit = 500000
defaultSidechainGasLimit = 2000000
defaultBlockBatchSize = 50
defaultBlockBatchSize = 500
defaultVersion = 1
)

// chainOpts describes common options
Expand Down Expand Up @@ -60,6 +61,7 @@ type options struct {
contractRegistry common.Address
blocksBatchSize uint64
niceMarket bool
version uint
}

func defaultOptions() *options {
Expand Down Expand Up @@ -125,6 +127,7 @@ func WithConfig(cfg *Config) Option {
}
o.blocksBatchSize = cfg.BlocksBatchSize
o.masterchain.gasPrice = cfg.MasterchainGasPrice
o.version = cfg.Version
}
}
}
Expand Down Expand Up @@ -165,3 +168,9 @@ func WithNiceMarket() Option {
o.niceMarket = true
}
}

func WithVersion(version uint) Option {
return func(o *options) {
o.version = version
}
}
2 changes: 1 addition & 1 deletion blockchain/source/api/Market.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion blockchain/source/api/OracleUSD.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.