Skip to content

Commit

Permalink
set signedOrderBook addy from precompile call
Browse files Browse the repository at this point in the history
  • Loading branch information
atvanguard committed Feb 27, 2024
1 parent 4685599 commit a9f2268
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 60 deletions.
3 changes: 3 additions & 0 deletions genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"blockTimestamp": 0,
"adminAddresses": ["0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC","0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]
},
"jurorConfig": {
"blockTimestamp": 0
},
"jurorV2Config": {
"blockTimestamp": 0
},
Expand Down
59 changes: 0 additions & 59 deletions plugin/evm/orderbook/hubbleutils/signed_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,62 +116,3 @@ func (o *SignedOrder) Hash() (hash common.Hash, err error) {
}
return EncodeForSigning(typedData)
}

// Trading API methods

// func (o *SignedOrder) UnmarshalJSON(data []byte) error {
// // Redefine the structs with simple types for JSON unmarshalling
// aux := &struct {
// AmmIndex uint64 `json:"ammIndex"`
// Trader common.Address `json:"trader"`
// BaseAssetQuantity string `json:"baseAssetQuantity"`
// Price string `json:"price"`
// Salt string `json:"salt"`
// ReduceOnly bool `json:"reduceOnly"`
// PostOnly bool `json:"postOnly"`
// OrderType uint8 `json:"orderType"`
// ExpireAt uint64 `json:"expireAt"`
// Sig string `json:"sig"`
// }{}

// // Perform the unmarshalling
// if err := json.Unmarshal(data, aux); err != nil {
// return err
// }

// // Convert and assign the values to the original struct
// o.AmmIndex = new(big.Int).SetUint64(aux.AmmIndex)

// o.Trader = aux.Trader

// o.BaseAssetQuantity = new(big.Int)
// o.BaseAssetQuantity.SetString(aux.BaseAssetQuantity, 10)

// o.Price = new(big.Int)
// o.Price.SetString(aux.Price, 10)

// o.Salt = new(big.Int)
// o.Salt.SetBytes(common.FromHex(aux.Salt))

// o.ReduceOnly = aux.ReduceOnly
// o.PostOnly = aux.PostOnly
// o.OrderType = aux.OrderType

// o.ExpireAt = new(big.Int).SetUint64(aux.ExpireAt)
// o.Sig = common.FromHex(aux.Sig)
// return nil
// }

// func (order *SignedOrder) DecodeAPIOrder(rawOrder interface{}) error {
// order_, ok := rawOrder.(string)
// if !ok {
// fmt.Println("invalid data format")
// }

// orderJson := []byte(order_)
// err := json.Unmarshal(orderJson, &order)
// if err != nil {
// return err
// }
// return nil
// }
6 changes: 6 additions & 0 deletions precompile/contracts/bibliophile/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type BibliophileClient interface {
GetNotionalPositionAndMargin(trader common.Address, includeFundingPayments bool, mode uint8, upgradeVersion hu.UpgradeVersion) (*big.Int, *big.Int)
HasReferrer(trader common.Address) bool
GetActiveMarketsCount() int64

GetAccessibleState() contract.AccessibleState
}

// Define a structure that will implement the Bibliophile interface
Expand All @@ -69,6 +71,10 @@ func NewBibliophileClient(accessibleState contract.AccessibleState) BibliophileC
}
}

func (b *bibliophileClient) GetAccessibleState() contract.AccessibleState {
return b.accessibleState
}

func (b *bibliophileClient) GetSignedOrderFilledAmount(orderHash [32]byte) *big.Int {
return GetSignedOrderFilledAmount(b.accessibleState.GetStateDB(), orderHash)
}
Expand Down
15 changes: 15 additions & 0 deletions precompile/contracts/bibliophile/client_mock.go

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

11 changes: 10 additions & 1 deletion precompile/contracts/jurorv2/matching_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jurorv2
import (
"errors"
"math/big"
"strings"

ob "github.com/ava-labs/subnet-evm/plugin/evm/orderbook"
hu "github.com/ava-labs/subnet-evm/plugin/evm/orderbook/hubbleutils"
Expand Down Expand Up @@ -379,11 +380,19 @@ func validateExecuteIOCOrder(bibliophile b.BibliophileClient, order *ob.IOCOrder
}

func validateExecuteSignedOrder(bibliophile b.BibliophileClient, order *hu.SignedOrder, side Side, fillAmount *big.Int) (metadata *Metadata, err error) {
// these fields are only set in plugin/evm/limit_order.go.NewLimitOrderProcesser
// however, the above is not invoked after the bootstrap, so we need to set these fields here to serve the precompile validation during the bootstrap
if hu.VerifyingContract == "" || hu.ChainId == 0 {
chainId := bibliophile.GetAccessibleState().GetSnowContext().ChainID
if strings.EqualFold(chainId.String(), "2jfjkB7NkK4v8zoaoWmh5eaABNW6ynjQvemPFZpgPQ7ugrmUXv") { // mainnet
hu.SetChainIdAndVerifyingSignedOrdersContract(1992, "0x211682829664a5e289885DE21897B094eF289d18")
}
}

orderHash, err := order.Hash()
if err != nil {
return &Metadata{OrderHash: common.Hash{}}, err
}

trader, signer, err := hu.ValidateSignedOrder(
order,
hu.SignedOrderValidationFields{
Expand Down

0 comments on commit a9f2268

Please sign in to comment.