diff --git a/network-configs/aylin/chain_api_node.json b/network-configs/aylin/chain_api_node.json index c701f5513a..6a61c830b9 100644 --- a/network-configs/aylin/chain_api_node.json +++ b/network-configs/aylin/chain_api_node.json @@ -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 } diff --git a/network-configs/aylin/chain_archival_node.json b/network-configs/aylin/chain_archival_node.json index 609a602344..cf2c361794 100644 --- a/network-configs/aylin/chain_archival_node.json +++ b/network-configs/aylin/chain_archival_node.json @@ -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 } diff --git a/network-configs/aylin/subnet-id.json b/network-configs/aylin/subnet-id.json deleted file mode 100644 index 1e0ba71454..0000000000 --- a/network-configs/aylin/subnet-id.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "proposerMinBlockDelay": 0 -} diff --git a/network-configs/aylin/t2WSjSsoE3geV9ARu5r7gzTc5UayePy3NxDrSTx7hadLYvqbg.json b/network-configs/aylin/t2WSjSsoE3geV9ARu5r7gzTc5UayePy3NxDrSTx7hadLYvqbg.json new file mode 100644 index 0000000000..b3cf39918f --- /dev/null +++ b/network-configs/aylin/t2WSjSsoE3geV9ARu5r7gzTc5UayePy3NxDrSTx7hadLYvqbg.json @@ -0,0 +1,6 @@ +{ + "proposerMinBlockDelay": 0, + "appGossipValidatorSize": 10, + "appGossipNonValidatorSize": 5, + "appGossipPeerSize": 15 +} diff --git a/network-configs/hubblenet/2mxZY7A2t1tuRMALW4BcBUPVGNR3LH1DXhftdbLAHm1QtDkFp8.json b/network-configs/hubblenet/2mxZY7A2t1tuRMALW4BcBUPVGNR3LH1DXhftdbLAHm1QtDkFp8.json index 1e0ba71454..b3cf39918f 100644 --- a/network-configs/hubblenet/2mxZY7A2t1tuRMALW4BcBUPVGNR3LH1DXhftdbLAHm1QtDkFp8.json +++ b/network-configs/hubblenet/2mxZY7A2t1tuRMALW4BcBUPVGNR3LH1DXhftdbLAHm1QtDkFp8.json @@ -1,3 +1,6 @@ { - "proposerMinBlockDelay": 0 + "proposerMinBlockDelay": 0, + "appGossipValidatorSize": 10, + "appGossipNonValidatorSize": 5, + "appGossipPeerSize": 15 } diff --git a/network-configs/hubblenet/chain_api_node.json b/network-configs/hubblenet/chain_api_node.json index 2e183ead7e..2deb5bf5c5 100644 --- a/network-configs/hubblenet/chain_api_node.json +++ b/network-configs/hubblenet/chain_api_node.json @@ -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 } diff --git a/network-configs/hubblenet/chain_archival_node.json b/network-configs/hubblenet/chain_archival_node.json index ee718e5924..dfcf759fb4 100644 --- a/network-configs/hubblenet/chain_archival_node.json +++ b/network-configs/hubblenet/chain_archival_node.json @@ -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 } diff --git a/network-configs/hubblenet/upgrade.json b/network-configs/hubblenet/upgrade.json index f81b1f6c52..c1a7d7202e 100644 --- a/network-configs/hubblenet/upgrade.json +++ b/network-configs/hubblenet/upgrade.json @@ -9,6 +9,11 @@ "ticksConfig": { "blockTimestamp": 1699950600 } + }, + { + "jurorV2Config": { + "blockTimestamp": 1708686000 + } } ] } diff --git a/precompile/contracts/jurorv2/matching_validation_test.go b/precompile/contracts/jurorv2/matching_validation_test.go index 888c56c84e..41c98844da 100644 --- a/precompile/contracts/jurorv2/matching_validation_test.go +++ b/precompile/contracts/jurorv2/matching_validation_test.go @@ -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) @@ -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), @@ -329,6 +332,8 @@ 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) @@ -336,7 +341,7 @@ func TestValidateExecuteLimitOrder(t *testing.T) { 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), @@ -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) @@ -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 @@ -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) { diff --git a/scripts/run_local.sh b/scripts/run_local.sh index e5c9f58b43..029fc2a7f4 100755 --- a/scripts/run_local.sh +++ b/scripts/run_local.sh @@ -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 diff --git a/scripts/upgrade_local.sh b/scripts/upgrade_local.sh index 1ae83fcad4..f0cec40cfc 100755 --- a/scripts/upgrade_local.sh +++ b/scripts/upgrade_local.sh @@ -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