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/refactor markets tokens initialization #255

Merged
merged 16 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
be869a6
(fix) Added validation in SyncBroadcast code to avoid waiting to see …
aarmoa Oct 3, 2024
94c4b2c
Merge pull request #249 from InjectiveLabs/fix/check_tx_result_in_syn…
PavelInjective Oct 3, 2024
c90276b
(fix) Changed ofac.json file path to make it relative for compiled ap…
aarmoa Oct 9, 2024
a3b4eb0
(fix) Refactored OFAC tests moving them to their own file. Also impro…
aarmoa Oct 9, 2024
e777538
(fix) Fixed pre-commit check issue
aarmoa Oct 9, 2024
4ae8d48
Merge pull request #251 from InjectiveLabs/fix/make_ofac_list_file_pa…
PavelInjective Oct 9, 2024
5aa9a30
(feat) Refactored the tokens markets initialization to get markets fr…
aarmoa Nov 11, 2024
04e9e71
(fix) Fixed ofac.json file URL and updated the local ofac.json copy
aarmoa Nov 13, 2024
89605e1
(fix) Fixed link to official ofac.json file. Refreshed the local copy…
aarmoa Nov 13, 2024
935b4ad
Merge pull request #256 from InjectiveLabs/fix/ofac_list_url
aarmoa Nov 13, 2024
c13db14
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-go into…
aarmoa Nov 13, 2024
d427297
Merge pull request #257 from InjectiveLabs/feat/sync_dev_with_v1_53_1
aarmoa Nov 13, 2024
c8a8167
(fix) Renamed variable as requested in the PR review
aarmoa Nov 13, 2024
102d71e
(feat) Refactored the tokens markets initialization to get markets fr…
aarmoa Nov 11, 2024
edd6608
(fix) Renamed variable as requested in the PR review
aarmoa Nov 13, 2024
4e764e5
Merge branch 'feat/refactor_markets_tokens_initialization' of https:/…
aarmoa Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/cert/embed.go

This file was deleted.

31 changes: 0 additions & 31 deletions client/cert/mainnet.crt

This file was deleted.

31 changes: 0 additions & 31 deletions client/cert/testnet.crt

This file was deleted.

30 changes: 7 additions & 23 deletions client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ type ChainClient interface {
SynchronizeSubaccountNonce(subaccountId ethcommon.Hash) error
ComputeOrderHashes(spotOrders []exchangetypes.SpotOrder, derivativeOrders []exchangetypes.DerivativeOrder, subaccountId ethcommon.Hash) (OrderHashes, error)

SpotOrder(defaultSubaccountID ethcommon.Hash, network common.Network, d *SpotOrderData) *exchangetypes.SpotOrder
CreateSpotOrder(defaultSubaccountID ethcommon.Hash, d *SpotOrderData, marketsAssistant MarketsAssistant) *exchangetypes.SpotOrder
DerivativeOrder(defaultSubaccountID ethcommon.Hash, network common.Network, d *DerivativeOrderData) *exchangetypes.DerivativeOrder
CreateDerivativeOrder(defaultSubaccountID ethcommon.Hash, d *DerivativeOrderData, marketAssistant MarketsAssistant) *exchangetypes.DerivativeOrder
OrderCancel(defaultSubaccountID ethcommon.Hash, d *OrderCancelData) *exchangetypes.OrderData

Expand Down Expand Up @@ -295,9 +293,12 @@ type ChainClient interface {
FetchAddressesByRole(ctx context.Context, denom, role string) (*permissionstypes.QueryAddressesByRoleResponse, error)
FetchVouchersForAddress(ctx context.Context, address string) (*permissionstypes.QueryVouchersForAddressResponse, error)

GetNetwork() common.Network
Close()
}

var _ ChainClient = &chainClient{}

type chainClient struct {
ctx client.Context
network common.Network
Expand Down Expand Up @@ -1072,16 +1073,6 @@ func (c *chainClient) GetSubAccountNonce(ctx context.Context, subaccountId ethco
return res, err
}

// Deprecated: Use CreateSpotOrder instead
func (c *chainClient) SpotOrder(defaultSubaccountID ethcommon.Hash, network common.Network, d *SpotOrderData) *exchangetypes.SpotOrder {
assistant, err := NewMarketsAssistant(network.Name)
if err != nil {
panic(err)
}

return c.CreateSpotOrder(defaultSubaccountID, d, assistant)
}

func (c *chainClient) CreateSpotOrder(defaultSubaccountID ethcommon.Hash, d *SpotOrderData, marketsAssistant MarketsAssistant) *exchangetypes.SpotOrder {

market, isPresent := marketsAssistant.AllSpotMarkets()[d.MarketId]
Expand All @@ -1105,17 +1096,6 @@ func (c *chainClient) CreateSpotOrder(defaultSubaccountID ethcommon.Hash, d *Spo
}
}

// Deprecated: Use CreateDerivativeOrder instead
func (c *chainClient) DerivativeOrder(defaultSubaccountID ethcommon.Hash, network common.Network, d *DerivativeOrderData) *exchangetypes.DerivativeOrder {

assistant, err := NewMarketsAssistant(network.Name)
if err != nil {
panic(err)
}

return c.CreateDerivativeOrder(defaultSubaccountID, d, assistant)
}

func (c *chainClient) CreateDerivativeOrder(defaultSubaccountID ethcommon.Hash, d *DerivativeOrderData, marketAssistant MarketsAssistant) *exchangetypes.DerivativeOrder {
market, isPresent := marketAssistant.AllDerivativeMarkets()[d.MarketId]
if !isPresent {
Expand Down Expand Up @@ -2667,3 +2647,7 @@ func (c *chainClient) FetchVouchersForAddress(ctx context.Context, address strin

return res, err
}

func (c *chainClient) GetNetwork() common.Network {
return c.network
}
77 changes: 55 additions & 22 deletions client/chain/chain_test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@ import (
"errors"
"time"

permissionstypes "github.com/InjectiveLabs/sdk-go/chain/permissions/types"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
"google.golang.org/grpc"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainstreamtypes "github.com/InjectiveLabs/sdk-go/chain/stream/types"
tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
Expand All @@ -31,10 +22,23 @@ import (
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
eth "github.com/ethereum/go-ethereum/common"
"google.golang.org/grpc"

exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
permissionstypes "github.com/InjectiveLabs/sdk-go/chain/permissions/types"
chainstreamtypes "github.com/InjectiveLabs/sdk-go/chain/stream/types"
tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types"
"github.com/InjectiveLabs/sdk-go/client/common"
)

var _ ChainClient = &MockChainClient{}

type MockChainClient struct {
DenomsMetadataResponses []*banktypes.QueryDenomsMetadataResponse
Network common.Network
DenomsMetadataResponses []*banktypes.QueryDenomsMetadataResponse
QuerySpotMarketsResponses []*exchangetypes.QuerySpotMarketsResponse
QueryDerivativeMarketsResponses []*exchangetypes.QueryDerivativeMarketsResponse
QueryBinaryMarketsResponses []*exchangetypes.QueryBinaryMarketsResponse
}

func (c *MockChainClient) CanSignTransactions() bool {
Expand Down Expand Up @@ -191,18 +195,10 @@ func (c *MockChainClient) ComputeOrderHashes(spotOrders []exchangetypes.SpotOrde
return OrderHashes{}, nil
}

func (c *MockChainClient) SpotOrder(defaultSubaccountID eth.Hash, network common.Network, d *SpotOrderData) *exchangetypes.SpotOrder {
return c.CreateSpotOrder(defaultSubaccountID, d, MarketsAssistant{})
}

func (c *MockChainClient) CreateSpotOrder(defaultSubaccountID eth.Hash, d *SpotOrderData, marketsAssistant MarketsAssistant) *exchangetypes.SpotOrder {
return &exchangetypes.SpotOrder{}
}

func (c *MockChainClient) DerivativeOrder(defaultSubaccountID eth.Hash, network common.Network, d *DerivativeOrderData) *exchangetypes.DerivativeOrder {
return c.CreateDerivativeOrder(defaultSubaccountID, d, MarketsAssistant{})
}

func (c *MockChainClient) CreateDerivativeOrder(defaultSubaccountID eth.Hash, d *DerivativeOrderData, marketAssistant MarketsAssistant) *exchangetypes.DerivativeOrder {
return &exchangetypes.DerivativeOrder{}
}
Expand Down Expand Up @@ -371,7 +367,18 @@ func (c *MockChainClient) FetchDenomDecimals(ctx context.Context, denoms []strin
}

func (c *MockChainClient) FetchChainSpotMarkets(ctx context.Context, status string, marketIDs []string) (*exchangetypes.QuerySpotMarketsResponse, error) {
return &exchangetypes.QuerySpotMarketsResponse{}, nil
var response *exchangetypes.QuerySpotMarketsResponse
var localError error
if len(c.QuerySpotMarketsResponses) > 0 {
response = c.QuerySpotMarketsResponses[0]
c.QuerySpotMarketsResponses = c.QuerySpotMarketsResponses[1:]
localError = nil
} else {
response = &exchangetypes.QuerySpotMarketsResponse{}
localError = errors.New("there are no responses configured")
}

return response, localError
}

func (c *MockChainClient) FetchChainSpotMarket(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMarketResponse, error) {
Expand Down Expand Up @@ -439,7 +446,18 @@ func (c *MockChainClient) FetchChainTraderDerivativeTransientOrders(ctx context.
}

func (c *MockChainClient) FetchChainDerivativeMarkets(ctx context.Context, status string, marketIDs []string, withMidPriceAndTob bool) (*exchangetypes.QueryDerivativeMarketsResponse, error) {
return &exchangetypes.QueryDerivativeMarketsResponse{}, nil
var response *exchangetypes.QueryDerivativeMarketsResponse
var localError error
if len(c.QueryDerivativeMarketsResponses) > 0 {
response = c.QueryDerivativeMarketsResponses[0]
c.QueryDerivativeMarketsResponses = c.QueryDerivativeMarketsResponses[1:]
localError = nil
} else {
response = &exchangetypes.QueryDerivativeMarketsResponse{}
localError = errors.New("there are no responses configured")
}

return response, localError
}

func (c *MockChainClient) FetchChainDerivativeMarket(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketResponse, error) {
Expand Down Expand Up @@ -543,7 +561,18 @@ func (c *MockChainClient) FetchMarketVolatility(ctx context.Context, marketId st
}

func (c *MockChainClient) FetchChainBinaryOptionsMarkets(ctx context.Context, status string) (*exchangetypes.QueryBinaryMarketsResponse, error) {
return &exchangetypes.QueryBinaryMarketsResponse{}, nil
var response *exchangetypes.QueryBinaryMarketsResponse
var localError error
if len(c.QueryBinaryMarketsResponses) > 0 {
response = c.QueryBinaryMarketsResponses[0]
c.QueryBinaryMarketsResponses = c.QueryBinaryMarketsResponses[1:]
localError = nil
} else {
response = &exchangetypes.QueryBinaryMarketsResponse{}
localError = errors.New("there are no responses configured")
}

return response, localError
}

func (c *MockChainClient) FetchTraderDerivativeConditionalOrders(ctx context.Context, subaccountId, marketId string) (*exchangetypes.QueryTraderDerivativeConditionalOrdersResponse, error) {
Expand Down Expand Up @@ -741,3 +770,7 @@ func (c *MockChainClient) FetchAddressesByRole(ctx context.Context, denom, role
func (c *MockChainClient) FetchVouchersForAddress(ctx context.Context, address string) (*permissionstypes.QueryVouchersForAddressResponse, error) {
return &permissionstypes.QueryVouchersForAddressResponse{}, nil
}

func (c *MockChainClient) GetNetwork() common.Network {
return c.Network
}
Loading
Loading