Skip to content

Commit

Permalink
update subnet config required for makerbook + jurorv2 tests (#157)
Browse files Browse the repository at this point in the history
* Update avalanchego version in local scripts

* Update subnet config to allow gossiping to non-validators

* Add more tests for jurorv2 precompile

* Change versions for mainnet

* jurorv2 activation time

* rename deprecated apis

---------

Co-authored-by: atvanguard <[email protected]>
  • Loading branch information
lumos42 and atvanguard authored Feb 22, 2024
1 parent fd5456d commit 5c45ca4
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 14 deletions.
2 changes: 1 addition & 1 deletion network-configs/aylin/chain_api_node.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"priority-regossip-txs-per-address": 20,
"priority-regossip-addresses": ["0x06CCAD927e6B1d36E219Cb582Af3185D0705f78F"],
"coreth-admin-api-enabled": true,
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-public-eth","internal-public-blockchain","internal-public-transaction-pool","internal-public-debug","internal-private-debug","internal-public-tx-pool","internal-public-account","debug-tracer"],
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-eth","internal-blockchain","internal-transaction","internal-debug","internal-tx-pool","internal-account","debug-tracer"],
"trading-api-enabled": true,
"testing-api-enabled": true
}
2 changes: 1 addition & 1 deletion network-configs/aylin/chain_archival_node.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"priority-regossip-txs-per-address": 20,
"priority-regossip-addresses": ["0x06CCAD927e6B1d36E219Cb582Af3185D0705f78F"],
"coreth-admin-api-enabled": true,
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-public-eth","internal-public-blockchain","internal-public-transaction-pool","internal-public-debug","internal-private-debug","internal-public-tx-pool","internal-public-account","debug-tracer"],
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-public-eth","internal-blockchain","internal-transaction","internal-debug","internal-tx-pool","internal-account","debug-tracer"],
"trading-api-enabled": true,
"testing-api-enabled": true
}
3 changes: 0 additions & 3 deletions network-configs/aylin/subnet-id.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"proposerMinBlockDelay": 0,
"appGossipValidatorSize": 10,
"appGossipNonValidatorSize": 5,
"appGossipPeerSize": 15
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"proposerMinBlockDelay": 0
"proposerMinBlockDelay": 0,
"appGossipValidatorSize": 10,
"appGossipNonValidatorSize": 5,
"appGossipPeerSize": 15
}
2 changes: 1 addition & 1 deletion network-configs/hubblenet/chain_api_node.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"continuous-profiler-max-files": 200,
"continuous-profiler-frequency": "10m",
"admin-api-enabled": true,
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-public-eth","internal-public-blockchain","internal-public-transaction-pool","internal-public-debug","internal-private-debug","internal-public-tx-pool","internal-public-account","debug-tracer"],
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-public-eth","internal-blockchain","internal-transaction","internal-debug","internal-tx-pool","internal-account","debug-tracer"],
"trading-api-enabled": true,
"testing-api-enabled": true
}
2 changes: 1 addition & 1 deletion network-configs/hubblenet/chain_archival_node.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"continuous-profiler-max-files": 200,
"continuous-profiler-frequency": "10m",
"admin-api-enabled": true,
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-public-eth","internal-public-blockchain","internal-public-transaction-pool","internal-public-debug","internal-private-debug","internal-public-tx-pool","internal-public-account","debug-tracer"],
"eth-apis": ["public-eth","public-eth-filter","net","web3","internal-public-eth","internal-blockchain","internal-transaction","internal-debug","internal-tx-pool","internal-account","debug-tracer"],
"trading-api-enabled": true,
"testing-api-enabled": true
}
5 changes: 5 additions & 0 deletions network-configs/hubblenet/upgrade.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"ticksConfig": {
"blockTimestamp": 1699950600
}
},
{
"jurorV2Config": {
"blockTimestamp": 1708686000
}
}
]
}
182 changes: 178 additions & 4 deletions precompile/contracts/jurorv2/matching_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func testValidateExecuteSignedOrder(t *testing.T, mockBibliophile *b.MockBibliop
assert.Nil(t, err)
assert.Equal(t, orderHash, strings.TrimPrefix(h.Hex(), "0x"))

encodedOrder, err := order.EncodeToABIWithoutType()
assert.Nil(t, err)

marketAddress := common.HexToAddress("0xa72b463C21dA61cCc86069cFab82e9e8491152a0")
mockBibliophile.EXPECT().GetTimeStamp().Return(order.ExpireAt.Uint64()).Times(1)
mockBibliophile.EXPECT().GetActiveMarketsCount().Return(int64(1)).Times(1)
Expand All @@ -290,7 +293,7 @@ func testValidateExecuteSignedOrder(t *testing.T, mockBibliophile *b.MockBibliop
mockBibliophile.EXPECT().GetSignedOrderFilledAmount(h).Return(filledAmount).Times(1)
mockBibliophile.EXPECT().HasReferrer(order.Trader).Return(true).Times(1)

m, err := validateExecuteSignedOrder(mockBibliophile, order, side, fillAmount)
m, err := validateOrder(mockBibliophile, ob.Signed, encodedOrder, side, fillAmount)
assert.Nil(t, err)
assertMetadataEquality(t, &Metadata{
AmmIndex: new(big.Int).Set(order.AmmIndex),
Expand Down Expand Up @@ -329,14 +332,16 @@ func TestValidateExecuteLimitOrder(t *testing.T) {
t.Run("validateExecuteLimitOrder", func(t *testing.T) {
orderHash, err := order.Hash()
assert.Nil(t, err)
encodedOrder, err := order.EncodeToABIWithoutType()
assert.Nil(t, err)

blockPlaced := big.NewInt(42)
mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(filledAmount).Times(1)
mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(1)).Times(1) // placed
mockBibliophile.EXPECT().GetBlockPlaced(orderHash).Return(blockPlaced).Times(1) // placed
mockBibliophile.EXPECT().GetMarketAddressFromMarketID(order.AmmIndex.Int64()).Return(marketAddress).Times(1) // placed

m, err := validateExecuteLimitOrder(mockBibliophile, order, Long, fillAmount)
m, err := validateOrder(mockBibliophile, ob.Limit, encodedOrder, Long, fillAmount)
assert.Nil(t, err)
assertMetadataEquality(t, &Metadata{
AmmIndex: new(big.Int).Set(order.AmmIndex),
Expand All @@ -351,16 +356,95 @@ func TestValidateExecuteLimitOrder(t *testing.T) {
t.Run("validateExecuteLimitOrder returns orderHash even when validation fails", func(t *testing.T) {
orderHash, err := order.Hash()
assert.Nil(t, err)
encodedOrder, err := order.EncodeToABIWithoutType()
assert.Nil(t, err)

mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(filledAmount).Times(1)
mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(2)).Times(1) // Filled

m, err := validateExecuteLimitOrder(mockBibliophile, order, Long, fillAmount)
m, err := validateOrder(mockBibliophile, ob.Limit, encodedOrder, Long, fillAmount)
assert.EqualError(t, err, ErrInvalidOrder.Error())
assert.Equal(t, orderHash, m.OrderHash)
})
}

func TestValidateExecuteIOCOrder(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockBibliophile := b.NewMockBibliophileClient(ctrl)
marketAddress := common.HexToAddress("0xa72b463C21dA61cCc86069cFab82e9e8491152a0")
trader := common.HexToAddress("0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC")

order := &hu.IOCOrder{
BaseOrder: hu.BaseOrder{
AmmIndex: big.NewInt(534),
Trader: trader,
BaseAssetQuantity: big.NewInt(10),
Price: big.NewInt(20),
Salt: big.NewInt(1),
ReduceOnly: false,
},
OrderType: uint8(ob.IOC),
ExpireAt: big.NewInt(65),
}
filledAmount := big.NewInt(5)
fillAmount := big.NewInt(5)

t.Run("validateExecuteIOCOrder success", func(t *testing.T) {
orderHash, err := order.Hash()
assert.Nil(t, err)
encodedOrder, err := order.EncodeToABIWithoutType()
assert.Nil(t, err)

blockPlaced := big.NewInt(42)
mockBibliophile.EXPECT().IOC_GetOrderFilledAmount(orderHash).Return(filledAmount).Times(1)
mockBibliophile.EXPECT().IOC_GetOrderStatus(orderHash).Return(int64(1)).Times(1) // placed
mockBibliophile.EXPECT().IOC_GetBlockPlaced(orderHash).Return(blockPlaced).Times(1) // placed
mockBibliophile.EXPECT().GetMarketAddressFromMarketID(order.AmmIndex.Int64()).Return(marketAddress).Times(1) // placed
mockBibliophile.EXPECT().GetTimeStamp().Return(uint64(60)).Times(1) // placed

m, err := validateOrder(mockBibliophile, ob.IOC, encodedOrder, Long, fillAmount)
assert.Nil(t, err)
assertMetadataEquality(t, &Metadata{
AmmIndex: new(big.Int).Set(order.AmmIndex),
Trader: trader,
BaseAssetQuantity: new(big.Int).Set(order.BaseAssetQuantity),
BlockPlaced: blockPlaced,
Price: new(big.Int).Set(order.Price),
OrderHash: orderHash,
}, m)
})

t.Run("validateExecuteIOCOrder not ioc order", func(t *testing.T) {
order.OrderType = uint8(ob.Limit)
orderHash, err := order.Hash()
assert.Nil(t, err)
encodedOrder, err := order.EncodeToABIWithoutType()
assert.Nil(t, err)

m, err := validateOrder(mockBibliophile, ob.IOC, encodedOrder, Long, fillAmount)
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "not ioc order")
assert.Equal(t, m.OrderHash, orderHash)
})

t.Run("validateExecuteIOCOrder order expires", func(t *testing.T) {
order.OrderType = uint8(ob.IOC)
orderHash, err := order.Hash()
assert.Nil(t, err)
encodedOrder, err := order.EncodeToABIWithoutType()
assert.Nil(t, err)

mockBibliophile.EXPECT().GetTimeStamp().Return(uint64(66)).Times(1)

m, err := validateOrder(mockBibliophile, ob.IOC, encodedOrder, Long, fillAmount)
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "ioc expired")
assert.Equal(t, m.OrderHash, orderHash)
})
}

func assertMetadataEquality(t *testing.T, expected, actual *Metadata) {
assert.Equal(t, expected.AmmIndex.Int64(), actual.AmmIndex.Int64())
assert.Equal(t, expected.Trader, actual.Trader)
Expand All @@ -376,7 +460,7 @@ func TestDetermineFillPrice(t *testing.T) {

mockBibliophile := b.NewMockBibliophileClient(ctrl)

oraclePrice := hu.Mul1e6(big.NewInt(20)) // $10
oraclePrice := hu.Mul1e6(big.NewInt(20)) // $20
spreadLimit := new(big.Int).Mul(big.NewInt(50), big.NewInt(1e4)) // 50%
upperbound := hu.Div1e6(new(big.Int).Mul(oraclePrice, new(big.Int).Add(big.NewInt(1e6), spreadLimit))) // $10
lowerbound := hu.Div1e6(new(big.Int).Mul(oraclePrice, new(big.Int).Sub(big.NewInt(1e6), spreadLimit))) // $30
Expand Down Expand Up @@ -661,6 +745,96 @@ func TestDetermineFillPrice(t *testing.T) {
})
})
})

t.Run("short order came first", func(t *testing.T) {
blockPlaced0 := big.NewInt(70)
blockPlaced1 := big.NewInt(69)
t.Run("short price < long price", func(t *testing.T) {
m0 := &Metadata{
Price: hu.Mul1e6(big.NewInt(20)),
AmmIndex: big.NewInt(market),
BlockPlaced: blockPlaced0,
}
m1 := &Metadata{
Price: hu.Mul1e6(big.NewInt(19)),
BlockPlaced: blockPlaced1,
}
mockBibliophile.EXPECT().GetUpperAndLowerBoundForMarket(market).Return(upperbound, lowerbound).Times(1)
output, err, _ := determineFillPrice(mockBibliophile, m0, m1)
assert.Nil(t, err)
assert.Equal(t, FillPriceAndModes{m1.Price, Taker, Maker}, *output)
})
t.Run("short order is IOC", func(t *testing.T) {
m0 := &Metadata{
Price: hu.Mul1e6(big.NewInt(20)),
AmmIndex: big.NewInt(market),
BlockPlaced: blockPlaced0,
}
m1 := &Metadata{
Price: hu.Mul1e6(big.NewInt(19)),
BlockPlaced: blockPlaced1,
OrderType: ob.IOC,
}
mockBibliophile.EXPECT().GetUpperAndLowerBoundForMarket(market).Return(upperbound, lowerbound).Times(1)
output, err, errorOrder := determineFillPrice(mockBibliophile, m0, m1)
assert.Nil(t, output)
assert.Equal(t, ErrIOCOrderExpired, err)
assert.Equal(t, Order1, errorOrder)
})
t.Run("long order is post only", func(t *testing.T) {
m0 := &Metadata{
Price: hu.Mul1e6(big.NewInt(20)),
AmmIndex: big.NewInt(market),
BlockPlaced: blockPlaced0,
OrderType: ob.Limit,
PostOnly: true,
}
m1 := &Metadata{
Price: hu.Mul1e6(big.NewInt(19)),
BlockPlaced: blockPlaced1,
}
mockBibliophile.EXPECT().GetUpperAndLowerBoundForMarket(market).Return(upperbound, lowerbound).Times(1)
output, err, errorOrder := determineFillPrice(mockBibliophile, m0, m1)
assert.Nil(t, output)
assert.Equal(t, ErrCrossingMarket, err)
assert.Equal(t, Order0, errorOrder)
})
})
t.Run("both orders in the same block", func(t *testing.T) {
blockPlaced0 := big.NewInt(69)
blockPlaced1 := big.NewInt(69)
t.Run("short order = IOC", func(t *testing.T) {
m0 := &Metadata{
Price: hu.Mul1e6(big.NewInt(19)),
AmmIndex: big.NewInt(market),
BlockPlaced: blockPlaced0,
}
m1 := &Metadata{
Price: hu.Mul1e6(big.NewInt(19)),
BlockPlaced: blockPlaced1,
OrderType: ob.IOC,
}
mockBibliophile.EXPECT().GetUpperAndLowerBoundForMarket(market).Return(upperbound, lowerbound).Times(1)
output, err, _ := determineFillPrice(mockBibliophile, m0, m1)
assert.Nil(t, err)
assert.Equal(t, FillPriceAndModes{m0.Price, Maker, Taker}, *output)
})
t.Run("short order != IOC", func(t *testing.T) {
m0 := &Metadata{
Price: hu.Mul1e6(big.NewInt(19)),
AmmIndex: big.NewInt(market),
BlockPlaced: blockPlaced0,
}
m1 := &Metadata{
Price: hu.Mul1e6(big.NewInt(19)),
BlockPlaced: blockPlaced1,
}
mockBibliophile.EXPECT().GetUpperAndLowerBoundForMarket(market).Return(upperbound, lowerbound).Times(1)
output, err, _ := determineFillPrice(mockBibliophile, m0, m1)
assert.Nil(t, err)
assert.Equal(t, FillPriceAndModes{m1.Price, Taker, Maker}, *output)
})
})
}

func TestDetermineLiquidationFillPrice(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ avalanche subnet configure localnet --subnet-config subnet.json --config .avalan

# use the same avalanchego version as the one used in subnet-evm
# use tee to keep showing outut while storing in a var
OUTPUT=$(avalanche subnet deploy localnet -l --avalanchego-version v1.10.17 --config .avalanche-cli.json | tee /dev/fd/2)
OUTPUT=$(avalanche subnet deploy localnet -l --avalanchego-version v1.10.19 --config .avalanche-cli.json | tee /dev/fd/2)

setStatus
2 changes: 1 addition & 1 deletion scripts/upgrade_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ avalanche network stop --snapshot-name snap1
avalanche subnet upgrade vm localnet --binary custom_evm.bin --local

# utse tee to keep showing outut while storing in a var
OUTPUT=$(avalanche network start --avalanchego-version v1.10.17 --snapshot-name snap1 --config .avalanche-cli.json | tee /dev/fd/2)
OUTPUT=$(avalanche network start --avalanchego-version v1.10.19 --snapshot-name snap1 --config .avalanche-cli.json | tee /dev/fd/2)

setStatus

0 comments on commit 5c45ca4

Please sign in to comment.