From 35425301085e82035a8c7d3e44c763f2b66c04c1 Mon Sep 17 00:00:00 2001 From: Jay Yu <103467857+jayy04@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:49:56 -0400 Subject: [PATCH] switch to use the helper method to create positions --- .../client/sub_task_runner_test.go | 78 +- .../clob/client/cli/liquidations_cli_test.go | 28 +- protocol/x/clob/e2e/app_test.go | 39 +- .../x/clob/e2e/conditional_orders_test.go | 111 +- .../e2e/isolated_subaccount_orders_test.go | 64 +- .../clob/e2e/liquidation_deleveraging_test.go | 414 ++-- protocol/x/clob/e2e/long_term_orders_test.go | 361 ++-- .../x/clob/e2e/reduce_only_orders_test.go | 147 +- protocol/x/clob/e2e/short_term_orders_test.go | 110 +- protocol/x/clob/e2e/withdrawal_gating_test.go | 28 +- protocol/x/clob/keeper/deleveraging_test.go | 119 +- protocol/x/clob/keeper/liquidations_test.go | 434 +++-- .../keeper/msg_server_place_order_test.go | 10 +- .../process_operations_liquidations_test.go | 106 +- .../process_operations_long_term_test.go | 63 +- .../x/clob/keeper/process_operations_test.go | 324 ++-- protocol/x/sending/app_test.go | 19 +- .../keeper/isolated_subaccount_test.go | 58 +- .../x/subaccounts/keeper/subaccount_test.go | 1723 ++++++++--------- protocol/x/subaccounts/lib/oimf_test.go | 56 +- protocol/x/subaccounts/lib/updates_test.go | 37 +- protocol/x/subaccounts/types/genesis_test.go | 54 +- .../x/subaccounts/types/subaccount_test.go | 78 +- .../x/vault/keeper/grpc_query_vault_test.go | 35 +- .../msg_server_deposit_to_vault_test.go | 9 +- protocol/x/vault/keeper/orders_test.go | 26 +- protocol/x/vault/keeper/shares_test.go | 10 +- protocol/x/vault/keeper/vault_test.go | 10 +- 28 files changed, 2288 insertions(+), 2263 deletions(-) diff --git a/protocol/daemons/liquidation/client/sub_task_runner_test.go b/protocol/daemons/liquidation/client/sub_task_runner_test.go index b695da8d5e..77faaf7d1d 100644 --- a/protocol/daemons/liquidation/client/sub_task_runner_test.go +++ b/protocol/daemons/liquidation/client/sub_task_runner_test.go @@ -2,16 +2,18 @@ package client_test import ( "context" - "cosmossdk.io/log" + "math/big" "testing" + "cosmossdk.io/log" + "github.com/dydxprotocol/v4-chain/protocol/daemons/flags" "github.com/dydxprotocol/v4-chain/protocol/daemons/liquidation/api" "github.com/dydxprotocol/v4-chain/protocol/daemons/liquidation/client" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/mocks" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" "github.com/dydxprotocol/v4-chain/protocol/testutil/grpc" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" @@ -283,17 +285,17 @@ func TestRunLiquidationDaemonTaskLoop(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(55_000_000_000), // $55,000 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(55_000_000_000), // $55,000 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(10_000), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(10_000), + ), }, }, }, @@ -363,17 +365,17 @@ func TestRunLiquidationDaemonTaskLoop(t *testing.T) { { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(-45_000_000_000), // -$45,000 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(-45_000_000_000), // -$45,000 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(-10_000), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100_000_000), // 1 BTC + big.NewInt(-10_000), + ), }, }, }, @@ -443,17 +445,17 @@ func TestRunLiquidationDaemonTaskLoop(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(54_999_000_000), // $54,999 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(54_999_000_000), // $54,999 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(-10_000), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(-10_000), + ), }, }, }, @@ -521,17 +523,17 @@ func TestRunLiquidationDaemonTaskLoop(t *testing.T) { { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(-44_999_000_000), // -$44,999 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(-44_999_000_000), // -$44,999 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(10_000), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100_000_000), // 1 BTC + big.NewInt(10_000), + ), }, }, }, diff --git a/protocol/x/clob/client/cli/liquidations_cli_test.go b/protocol/x/clob/client/cli/liquidations_cli_test.go index 4f85898114..a7a0252359 100644 --- a/protocol/x/clob/client/cli/liquidations_cli_test.go +++ b/protocol/x/clob/client/cli/liquidations_cli_test.go @@ -6,18 +6,19 @@ import ( "fmt" "math" - appflags "github.com/dydxprotocol/v4-chain/protocol/app/flags" "math/big" "testing" + appflags "github.com/dydxprotocol/v4-chain/protocol/app/flags" + networktestutil "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/lib" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" - "github.com/dydxprotocol/v4-chain/protocol/x/clob/client/testutil" + clob_testutil "github.com/dydxprotocol/v4-chain/protocol/x/clob/client/testutil" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" epochstypes "github.com/dydxprotocol/v4-chain/protocol/x/epochs/types" feetierstypes "github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types" @@ -128,7 +129,7 @@ func (s *LiquidationsIntegrationTestSuite) SetupSuite() { s.cfg.GenesisState[types.ModuleName] = buf // Set the balances in the genesis state. - s.cfg.GenesisState[banktypes.ModuleName] = testutil.CreateBankGenesisState( + s.cfg.GenesisState[banktypes.ModuleName] = clob_testutil.CreateBankGenesisState( s.T(), s.cfg, liqTestInitialSubaccountModuleAccBalance, @@ -147,16 +148,17 @@ func (s *LiquidationsIntegrationTestSuite) SetupSuite() { satypes.Subaccount{ Id: &satypes.SubaccountId{Owner: s.validatorAddress.String(), Number: liqTestSubaccountNumberOne}, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(-45_001_000_000), // -$45,001 - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(-45_001_000_000), // -$45,001 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, }, ) @@ -211,7 +213,7 @@ func (s *LiquidationsIntegrationTestSuite) TestCLILiquidations() { subticks := types.Subticks(50_000_000_000) // Place the maker order that should be filled by the liquidation order. - _, err = testutil.MsgPlaceOrderExec( + _, err = clob_testutil.MsgPlaceOrderExec( ctx, s.validatorAddress, liqTestSubaccountNumberZero, diff --git a/protocol/x/clob/e2e/app_test.go b/protocol/x/clob/e2e/app_test.go index 4235964f54..6c318a6c4d 100644 --- a/protocol/x/clob/e2e/app_test.go +++ b/protocol/x/clob/e2e/app_test.go @@ -2,6 +2,7 @@ package clob_test import ( "fmt" + "math/big" "sync" "testing" "time" @@ -15,7 +16,6 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" auth "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/dydxprotocol/v4-chain/protocol/app/config" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/testutil/rand" "gopkg.in/typ.v4/slices" @@ -25,6 +25,7 @@ import ( clobtestutils "github.com/dydxprotocol/v4-chain/protocol/testutil/clob" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" testtx "github.com/dydxprotocol/v4-chain/protocol/testutil/tx" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" epochtypes "github.com/dydxprotocol/v4-chain/protocol/x/epochs/types" feetierstypes "github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types" @@ -525,17 +526,17 @@ func TestHydrationWithMatchPreBlocker(t *testing.T) { require.Equal(t, satypes.Subaccount{ Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000 - 50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000-50_000_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100_000_000), + big.NewInt(0), + ), }, }, carl) @@ -543,17 +544,17 @@ func TestHydrationWithMatchPreBlocker(t *testing.T) { require.Equal(t, satypes.Subaccount{ Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(500_000_000_000 + 50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(500_000_000_000+50_000_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), + big.NewInt(0), + ), }, }, dave) diff --git a/protocol/x/clob/e2e/conditional_orders_test.go b/protocol/x/clob/e2e/conditional_orders_test.go index 7ebb3dc8bb..a4afb5a02b 100644 --- a/protocol/x/clob/e2e/conditional_orders_test.go +++ b/protocol/x/clob/e2e/conditional_orders_test.go @@ -1,17 +1,18 @@ package clob_test import ( + "math/big" "testing" "time" "github.com/cometbft/cometbft/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/lib" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" "github.com/dydxprotocol/v4-chain/protocol/testutil/daemons/pricefeed/exchange_config" "github.com/dydxprotocol/v4-chain/protocol/testutil/encoding" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" feetiertypes "github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" @@ -558,17 +559,17 @@ func TestConditionalOrder(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(10_000_000_000 - 12_500_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(10_000_000_000-12_500_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(25_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(25_000_000), + big.NewInt(0), + ), }, }, }, @@ -600,17 +601,17 @@ func TestConditionalOrder(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(10_000_000_000 - 25_000_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(10_000_000_000-25_000_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), + big.NewInt(0), + ), }, }, }, @@ -680,17 +681,17 @@ func TestConditionalOrder(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(10_000_000_000 - 12_500_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(10_000_000_000-12_500_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(25_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(25_000_000), + big.NewInt(0), + ), }, }, }, @@ -1713,17 +1714,17 @@ func TestConditionalOrder_TriggeringUsingMatchedPrice(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(10_000_000_000 - 12_500_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(10_000_000_000-12_500_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(25_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(25_000_000), + big.NewInt(0), + ), }, }, }, @@ -1755,17 +1756,17 @@ func TestConditionalOrder_TriggeringUsingMatchedPrice(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(10_000_000_000 - 25_000_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(10_000_000_000-25_000_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), + big.NewInt(0), + ), }, }, }, @@ -1835,17 +1836,17 @@ func TestConditionalOrder_TriggeringUsingMatchedPrice(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(10_000_000_000 - 12_500_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(10_000_000_000-12_500_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(25_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(25_000_000), + big.NewInt(0), + ), }, }, }, diff --git a/protocol/x/clob/e2e/isolated_subaccount_orders_test.go b/protocol/x/clob/e2e/isolated_subaccount_orders_test.go index 7c7000eb36..037da337bc 100644 --- a/protocol/x/clob/e2e/isolated_subaccount_orders_test.go +++ b/protocol/x/clob/e2e/isolated_subaccount_orders_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/cometbft/cometbft/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/stretchr/testify/require" "golang.org/x/exp/slices" @@ -17,6 +16,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/lib" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" @@ -70,20 +70,20 @@ func TestIsolatedSubaccountOrders(t *testing.T) { Id: &constants.Alice_Num0, AssetPositions: []*satypes.AssetPosition{ // USDC asset position. - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // Match = 10e9 * 10e-8 * 10 = 100 quantums. Fees = 0. // Alice is buying, subtract match quantums from asset position. - Quantums: dtypes.NewInt(10_000_000_000 - 100), - }, + big.NewInt(10_000_000_000-100), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ // Isolated perpetual position. - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(int64(orderQuantums)), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(int64(orderQuantums)), + big.NewInt(0), + ), }, } @@ -92,20 +92,20 @@ func TestIsolatedSubaccountOrders(t *testing.T) { Id: &constants.Bob_Num0, AssetPositions: []*satypes.AssetPosition{ // USDC asset position. - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // Match = 10e9 * 10e-8 * 10 = 100 quantums. Fees = 1 quantum. // Bob is selling, add match quantums from asset position. - Quantums: dtypes.NewInt(10_000_000_000 + 99), - }, + big.NewInt(10_000_000_000+99), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ // Isolated perpetual position. - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(-1 * int64(orderQuantums)), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(-1*int64(orderQuantums)), + big.NewInt(0), + ), }, } @@ -114,21 +114,21 @@ func TestIsolatedSubaccountOrders(t *testing.T) { Id: &constants.Alice_Num0, AssetPositions: []*satypes.AssetPosition{ // USDC asset position. - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // Match = 10e9 * 10e-8 * 10 = 100 quantums. Fees = 0. // Alice is buying, subtract match quantums from asset position. - Quantums: dtypes.NewInt(10_000_000_000 - 100), - }, + big.NewInt(10_000_000_000-100), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ // Isolated perpetual position. - { - PerpetualId: uint32(3), + testutil.CreateSinglePerpetualPosition( + uint32(3), // Alice buys 1 more ISO, - Quantums: dtypes.NewInt(2 * int64(orderQuantums)), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(2*int64(orderQuantums)), + big.NewInt(0), + ), }, } @@ -137,12 +137,12 @@ func TestIsolatedSubaccountOrders(t *testing.T) { Id: &constants.Bob_Num0, AssetPositions: []*satypes.AssetPosition{ // USDC asset position. - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // Match = 10e9 * 10e-8 * 10 = 100 quantums. Fees = 1. // Bob is selling, add match quantums from asset position. - Quantums: dtypes.NewInt(10_000_000_000 + 99), - }, + big.NewInt(10_000_000_000+99), + ), }, } diff --git a/protocol/x/clob/e2e/liquidation_deleveraging_test.go b/protocol/x/clob/e2e/liquidation_deleveraging_test.go index 0e4103c111..896652d202 100644 --- a/protocol/x/clob/e2e/liquidation_deleveraging_test.go +++ b/protocol/x/clob/e2e/liquidation_deleveraging_test.go @@ -2,6 +2,7 @@ package clob_test import ( "math" + "math/big" "testing" "github.com/dydxprotocol/v4-chain/protocol/daemons/liquidation/api" @@ -12,6 +13,7 @@ import ( testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" clobtest "github.com/dydxprotocol/v4-chain/protocol/testutil/clob" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" feetiertypes "github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types" @@ -73,19 +75,19 @@ func TestLiquidationConfig(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - 50_000_000_000 - 250_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-50_000_000_000-250_000_000), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000), // $100,000 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000), // $100,000 + ), }, }, }, @@ -123,19 +125,19 @@ func TestLiquidationConfig(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000 - 50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000-50_000_000_000), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(-49_501_000_000 + 50_000_000_000 - 250_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(-49_501_000_000+50_000_000_000-250_000_000), + ), }, }, }, @@ -171,33 +173,33 @@ func TestLiquidationConfig(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - 5_000_000_000 - 25_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-5_000_000_000-25_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-90_000_000), // -0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-90_000_000), // -0.9 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(55_000_000_000), // $55,000 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(55_000_000_000), // $55,000 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(90_000_000), // 0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(90_000_000), // 0.9 BTC + big.NewInt(0), + ), }, }, }, @@ -233,33 +235,33 @@ func TestLiquidationConfig(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000 - 5_000_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000-5_000_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-90_000_000), // -0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-90_000_000), // -0.9 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(-49_501_000_000 + 5_000_000_000 - 25_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(-49_501_000_000+5_000_000_000-25_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(90_000_000), // 0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(90_000_000), // 0.9 BTC + big.NewInt(0), + ), }, }, }, @@ -295,33 +297,33 @@ func TestLiquidationConfig(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - 4_950_000_000 - 24_750_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-4_950_000_000-24_750_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-90_000_000), // -0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-90_000_000), // -0.9 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(54_950_000_000), // $54,950 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(54_950_000_000), // $54,950 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(90_000_000), // 0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(90_000_000), // 0.9 BTC + big.NewInt(0), + ), }, }, }, @@ -361,33 +363,33 @@ func TestLiquidationConfig(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000 - 5_050_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000-5_050_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-90_000_000), // -0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-90_000_000), // -0.9 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(-49_501_000_000 + 5_050_000_000 - 25_250_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(-49_501_000_000+5_050_000_000-25_250_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(90_000_000), // 0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(90_000_000), // 0.9 BTC + big.NewInt(0), + ), }, }, }, @@ -433,34 +435,34 @@ func TestLiquidationConfig(t *testing.T) { { Id: &constants.Carl_Num1, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, + testutil.CreateSingleAssetPosition( + 0, // $0.1 from insurance fund - Quantums: dtypes.NewInt(50_499_000_000 - 5_050_000_000 + 100_000), - }, + big.NewInt(50_499_000_000-5_050_000_000+100_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-90_000_000), // -0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-90_000_000), // -0.9 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 49_500_000_000 + 5_050_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+49_500_000_000+5_050_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-10_000_000), // -0.1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-10_000_000), // -0.1 BTC + big.NewInt(0), + ), }, }, }, @@ -506,33 +508,33 @@ func TestLiquidationConfig(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000 - 50_500_000_000 - 4_950_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000-50_500_000_000-4_950_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(10_000_000), // 0.1 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(-49_501_000_000 + 4_950_000_000 + 100_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(-49_501_000_000+4_950_000_000+100_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(90_000_000), // 0.9 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(90_000_000), // 0.9 BTC + big.NewInt(0), + ), }, }, }, @@ -678,19 +680,19 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - 50_000_000_000 - 250_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-50_000_000_000-250_000_000), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000), // $100,000 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000), // $100,000 + ), }, }, }, @@ -720,33 +722,33 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - 12_500_000_000 - 62_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-12_500_000_000-62_500_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 12_500_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+12_500_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(75_000_000), // 0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(75_000_000), // 0.75 BTC + big.NewInt(0), + ), }, }, }, @@ -782,10 +784,10 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 50_499_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+50_499_000_000), + ), }, }, }, @@ -820,33 +822,33 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - (50_498_000_000 / 4) - 250_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-(50_498_000_000/4)-250_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + (50_498_000_000 / 4)), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+(50_498_000_000/4)), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(75_000_000), // 0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(75_000_000), // 0.75 BTC + big.NewInt(0), + ), }, }, }, @@ -910,17 +912,17 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(49_999_000_000 - 12_499_750_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(49_999_000_000-12_499_750_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, // Dave's bankruptcy price to close 1 BTC long is $50,000, and deleveraging can not be @@ -965,18 +967,18 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(49_999_000_000 - 24_999_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(49_999_000_000-24_999_500_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, + testutil.CreateSinglePerpetualPosition( + 0, // Deleveraging fails for remaining amount. - Quantums: dtypes.NewInt(-50_000_000), // -0.5 BTC - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(-50_000_000), // -0.5 BTC + big.NewInt(0), + ), }, }, // Dave_Num0 does not change since deleveraging against this subaccount failed. @@ -1033,10 +1035,10 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 50_499_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+50_499_000_000), + ), }, }, }, @@ -1067,10 +1069,10 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 50_499_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+50_499_000_000), + ), }, }, }, @@ -1093,19 +1095,19 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000 - 50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000-50_000_000_000), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+50_000_000_000), + ), }, }, }, diff --git a/protocol/x/clob/e2e/long_term_orders_test.go b/protocol/x/clob/e2e/long_term_orders_test.go index 0afac82a6c..074a6b3c8c 100644 --- a/protocol/x/clob/e2e/long_term_orders_test.go +++ b/protocol/x/clob/e2e/long_term_orders_test.go @@ -23,6 +23,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" testmsgs "github.com/dydxprotocol/v4-chain/protocol/testutil/msgs" testtx "github.com/dydxprotocol/v4-chain/protocol/testutil/tx" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" "github.com/stretchr/testify/require" @@ -618,50 +619,46 @@ func TestPlaceLongTermOrder(t *testing.T) { { Id: &constants.Alice_Num0, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy1_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Sub( - aliceSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+25_000_000, // taker fee of .5% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Sub( + aliceSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+25_000_000, // taker fee of .5% ), ), - }, + ), }, MarginEnabled: true, }, { Id: &constants.Bob_Num0, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy1_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - bobSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+5_500_000, // maker rebate of .110% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Add( + bobSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+5_500_000, // maker rebate of .110% ), ), - }, + ), }, MarginEnabled: true, }, @@ -747,25 +744,23 @@ func TestPlaceLongTermOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Alice_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy1_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Sub( - aliceSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+25_000_000, // taker fee of .5% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Sub( + aliceSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+25_000_000, // taker fee of .5% ), ), - }, + ), }, nil, // no funding payments ), @@ -781,12 +776,12 @@ func TestPlaceLongTermOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Bob_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy1_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, []*satypes.AssetPosition{ { @@ -951,54 +946,50 @@ func TestPlaceLongTermOrder(t *testing.T) { { Id: &constants.Alice_Num0, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy2_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Sub( - aliceSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+25_000_000+ // taker fee of .5% - 50_000_000_000-5_500_000, // maker rebate of .110% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Sub( + aliceSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+25_000_000+ // taker fee of .5% + 50_000_000_000-5_500_000, // maker rebate of .110% ), ), - }, + ), }, MarginEnabled: true, }, { Id: &constants.Bob_Num0, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( - PlaceOrder_Bob_Num0_Id0_Clob0_Sell1_Price50000_GTB20.Order.GetQuantums() + + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( + PlaceOrder_Bob_Num0_Id0_Clob0_Sell1_Price50000_GTB20.Order.GetQuantums()+ PlaceOrder_Bob_Num0_Id1_Clob0_Sell1_Price50000_GTB20.Order.GetQuantums(), )), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - bobSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+5_500_000+ // maker rebate of .110% from first order - 50_000_000_000-25_000_000, // taker fee of .5% from second order - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Add( + bobSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+5_500_000+ // maker rebate of .110% from first order + 50_000_000_000-25_000_000, // taker fee of .5% from second order ), ), - }, + ), }, MarginEnabled: true, }, @@ -1094,25 +1085,23 @@ func TestPlaceLongTermOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Alice_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( PlaceOrder_Bob_Num0_Id0_Clob0_Sell1_Price50000_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Sub( - aliceSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+25_000_000, // taker fee of .5% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Sub( + aliceSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+25_000_000, // taker fee of .5% ), ), - }, + ), }, nil, // no funding payments ), @@ -1128,25 +1117,23 @@ func TestPlaceLongTermOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Bob_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( PlaceOrder_Bob_Num0_Id0_Clob0_Sell1_Price50000_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - bobSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+5_500_000, // maker rebate of .110% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Add( + bobSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+5_500_000, // maker rebate of .110% ), ), - }, + ), }, nil, // no funding payments ), @@ -1259,30 +1246,28 @@ func TestPlaceLongTermOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Bob_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), // perpetual position size should equal sum of base quantums of Bob's orders // because they are both fully filled - Quantums: dtypes.NewInt(-int64( - PlaceOrder_Bob_Num0_Id0_Clob0_Sell1_Price50000_GTB20.Order.GetQuantums() + + big.NewInt(-int64( + PlaceOrder_Bob_Num0_Id0_Clob0_Sell1_Price50000_GTB20.Order.GetQuantums()+ PlaceOrder_Bob_Num0_Id1_Clob0_Sell1_Price50000_GTB20.Order.GetQuantums(), )), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - bobSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+5_500_000+ // maker rebate of .110% from first order - 50_000_000_000-25_000_000, // taker fee of .5% from second order - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Add( + bobSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+5_500_000+ // maker rebate of .110% from first order + 50_000_000_000-25_000_000, // taker fee of .5% from second order ), ), - }, + ), }, nil, // no funding payments ), @@ -1298,27 +1283,25 @@ func TestPlaceLongTermOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Alice_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), // Order was fully filled - Quantums: dtypes.NewInt(int64( + big.NewInt(int64( LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy2_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Sub( - aliceSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+25_000_000+ // taker fee of .5% from first match - 50_000_000_000-5_500_000, // maker rebate of .110% from second match - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Sub( + aliceSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+25_000_000+ // taker fee of .5% from first match + 50_000_000_000-5_500_000, // maker rebate of .110% from second match ), ), - }, + ), }, nil, // no funding payments ), @@ -1556,50 +1539,46 @@ func TestRegression_InvalidTimeInForce(t *testing.T) { { Id: &constants.Alice_Num0, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( Invalid_TIF_LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy1_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Sub( - aliceSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+25_000_000, // taker fee of .5% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Sub( + aliceSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+25_000_000, // taker fee of .5% ), ), - }, + ), }, MarginEnabled: true, }, { Id: &constants.Bob_Num0, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( Invalid_TIF_LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy1_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - bobSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+5_500_000, // maker rebate of .110% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Add( + bobSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+5_500_000, // maker rebate of .110% ), ), - }, + ), }, MarginEnabled: true, }, @@ -1668,25 +1647,23 @@ func TestRegression_InvalidTimeInForce(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Alice_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( Invalid_TIF_LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy1_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Sub( - aliceSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+25_000_000, // taker fee of .5% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Sub( + aliceSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+25_000_000, // taker fee of .5% ), ), - }, + ), }, nil, // no funding payments ), @@ -1702,25 +1679,23 @@ func TestRegression_InvalidTimeInForce(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Bob_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( Invalid_TIF_LongTermPlaceOrder_Alice_Num0_Id0_Clob0_Buy1_Price50000_GTBT5.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - bobSubaccount.GetUsdcPosition(), - new(big.Int).SetInt64( - 50_000_000_000+5_500_000, // maker rebate of .110% - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Add( + bobSubaccount.GetUsdcPosition(), + new(big.Int).SetInt64( + 50_000_000_000+5_500_000, // maker rebate of .110% ), ), - }, + ), }, nil, // no funding payments ), diff --git a/protocol/x/clob/e2e/reduce_only_orders_test.go b/protocol/x/clob/e2e/reduce_only_orders_test.go index 2dec334210..5536f45788 100644 --- a/protocol/x/clob/e2e/reduce_only_orders_test.go +++ b/protocol/x/clob/e2e/reduce_only_orders_test.go @@ -1,13 +1,14 @@ package clob_test import ( + "math/big" "testing" "github.com/cometbft/cometbft/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" "github.com/dydxprotocol/v4-chain/protocol/testutil/encoding" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" prices "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" @@ -61,33 +62,33 @@ func TestReduceOnlyOrders(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(95_000_550_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(95_000_550_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100), + big.NewInt(0), + ), }, }, { Id: &constants.Alice_Num1, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(504_997_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(504_997_500_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(99_999_900), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(99_999_900), + big.NewInt(0), + ), }, }, }, @@ -122,33 +123,33 @@ func TestReduceOnlyOrders(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(95_000_550_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(95_000_550_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100), + big.NewInt(0), + ), }, }, { Id: &constants.Alice_Num1, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(504_997_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(504_997_500_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(99_999_900), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(99_999_900), + big.NewInt(0), + ), }, }, }, @@ -183,33 +184,33 @@ func TestReduceOnlyOrders(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(9_250_0825_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(9_250_0825_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(150), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(150), + big.NewInt(0), + ), }, }, { Id: &constants.Alice_Num1, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(507_496_250_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(507_496_250_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(99_999_850), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(99_999_850), + big.NewInt(0), + ), }, }, }, @@ -253,33 +254,33 @@ func TestReduceOnlyOrders(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(375_013_750_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(375_013_750_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(25_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(25_000_000), + big.NewInt(0), + ), }, }, { Id: &constants.Alice_Num1, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(624_937_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(624_937_500_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(75_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(75_000_000), + big.NewInt(0), + ), }, }, }, diff --git a/protocol/x/clob/e2e/short_term_orders_test.go b/protocol/x/clob/e2e/short_term_orders_test.go index bf5abb0e0b..d389a5d6f0 100644 --- a/protocol/x/clob/e2e/short_term_orders_test.go +++ b/protocol/x/clob/e2e/short_term_orders_test.go @@ -1,6 +1,7 @@ package clob_test import ( + "math/big" "testing" "github.com/cometbft/cometbft/crypto/tmhash" @@ -19,6 +20,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" testmsgs "github.com/dydxprotocol/v4-chain/protocol/testutil/msgs" testtx "github.com/dydxprotocol/v4-chain/protocol/testutil/tx" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" @@ -152,19 +154,19 @@ func TestPlaceOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Bob_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, // Maker fees calculate to 0 so asset position doesn't change. []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(bobSubaccount.GetUsdcPosition()), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + bobSubaccount.GetUsdcPosition(), + ), }, nil, // no funding payments ), @@ -179,19 +181,19 @@ func TestPlaceOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Alice_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, // Taker fees calculate to 0 so asset position doesn't change. []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(aliceSubaccount.GetUsdcPosition()), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + aliceSubaccount.GetUsdcPosition(), + ), }, nil, // no funding payments ), @@ -329,19 +331,19 @@ func TestPlaceOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Bob_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, // Maker fees calculate to 0 so asset position doesn't change. []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(bobSubaccount.GetUsdcPosition()), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + bobSubaccount.GetUsdcPosition(), + ), }, nil, // no funding payments ), @@ -356,19 +358,19 @@ func TestPlaceOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Alice_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, // Taker fees calculate to 0 so asset position doesn't change. []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(aliceSubaccount.GetUsdcPosition()), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + aliceSubaccount.GetUsdcPosition(), + ), }, nil, // no funding payments ), @@ -506,19 +508,19 @@ func TestPlaceOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Alice_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(int64( PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, // Taker fees calculate to 0 so asset position doesn't change. []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(aliceSubaccount.GetUsdcPosition()), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + aliceSubaccount.GetUsdcPosition(), + ), }, nil, // no funding payments ), @@ -533,19 +535,19 @@ func TestPlaceOrder(t *testing.T) { indexerevents.NewSubaccountUpdateEvent( &constants.Bob_Num0, []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( + testutil.CreateSinglePerpetualPosition( + Clob_0.MustGetPerpetualId(), + big.NewInt(-int64( PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, // Maker fees calculate to 0 so asset position doesn't change. []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(bobSubaccount.GetUsdcPosition()), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + bobSubaccount.GetUsdcPosition(), + ), }, nil, // no funding payments ), diff --git a/protocol/x/clob/e2e/withdrawal_gating_test.go b/protocol/x/clob/e2e/withdrawal_gating_test.go index f66608d3b4..3500441410 100644 --- a/protocol/x/clob/e2e/withdrawal_gating_test.go +++ b/protocol/x/clob/e2e/withdrawal_gating_test.go @@ -1,6 +1,7 @@ package clob_test import ( + "math/big" "testing" sdkmath "cosmossdk.io/math" @@ -17,6 +18,7 @@ import ( testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" clobtest "github.com/dydxprotocol/v4-chain/protocol/testutil/clob" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" feetiertypes "github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types" @@ -31,10 +33,10 @@ func TestWithdrawalGating_NegativeTncSubaccount_BlocksThenUnblocks(t *testing.T) Alice_Num0_AfterWithdrawal := satypes.Subaccount{ Id: &constants.Alice_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(9_999_999_999), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(9_999_999_999), + ), }, PerpetualPositions: nil, } @@ -259,17 +261,17 @@ func TestWithdrawalGating_NegativeTncSubaccount_BlocksThenUnblocks(t *testing.T) { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(49_999_000_000 - 12_499_750_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(49_999_000_000-12_499_750_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, // Dave's bankruptcy price to close 1 BTC long is $50,000, and deleveraging can not be diff --git a/protocol/x/clob/keeper/deleveraging_test.go b/protocol/x/clob/keeper/deleveraging_test.go index b2dcffa329..3702918fd4 100644 --- a/protocol/x/clob/keeper/deleveraging_test.go +++ b/protocol/x/clob/keeper/deleveraging_test.go @@ -13,7 +13,6 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/mocks" clobtest "github.com/dydxprotocol/v4-chain/protocol/testutil/clob" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" @@ -539,10 +538,11 @@ func TestOffsetSubaccountPerpetualPosition(t *testing.T) { &constants.Usdc_Asset_50_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), // 0.5 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), // 0.5 BTC + big.NewInt(0), + ), }, }, { @@ -551,10 +551,11 @@ func TestOffsetSubaccountPerpetualPosition(t *testing.T) { &constants.Usdc_Asset_50_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), // 0.5 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), // 0.5 BTC + big.NewInt(0), + ), }, }, }, @@ -718,11 +719,11 @@ func TestOffsetSubaccountPerpetualPosition(t *testing.T) { { Id: &constants.Carl_Num0, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 1, - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), }, AssetPositions: testutil.CreateUsdcAssetPositions( big.NewInt(-3_000_000_000), @@ -1115,11 +1116,11 @@ func TestProcessDeleveraging(t *testing.T) { big.NewInt(54_999_000_000 - 5_499_900_000), ), PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-90_000_000), // -0.9 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-90_000_000), // -0.9 BTC + big.NewInt(0), + ), }, }, expectedOffsettingSubaccount: satypes.Subaccount{ @@ -1130,11 +1131,11 @@ func TestProcessDeleveraging(t *testing.T) { big.NewInt(50_000_000_000 + 5_499_900_000), ), PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(90_000_000), // 0.9 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(90_000_000), // 0.9 BTC + big.NewInt(0), + ), }, }, }, @@ -1158,20 +1159,22 @@ func TestProcessDeleveraging(t *testing.T) { liquidatedSubaccount: satypes.Subaccount{ Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(80_800_000_000), // $80,800 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(80_800_000_000), // $80,800 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - }, - { - PerpetualId: 1, - Quantums: dtypes.NewInt(-10_000_000_000), // -10 ETH - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(-10_000_000_000), // -10 ETH + big.NewInt(0), + ), }, }, offsettingSubaccount: constants.Dave_Num0_1BTC_Long_50000USD, @@ -1186,11 +1189,11 @@ func TestProcessDeleveraging(t *testing.T) { big.NewInt(80_800_000_000 - 50_500_000_000), ), PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 1, - Quantums: dtypes.NewInt(-10_000_000_000), // -10 ETH - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(-10_000_000_000), // -10 ETH + big.NewInt(0), + ), }, }, expectedOffsettingSubaccount: satypes.Subaccount{ @@ -1574,16 +1577,17 @@ func TestProcessDeleveraging_Rounding(t *testing.T) { liquidatedSubaccount: satypes.Subaccount{ Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(45_001_000_000), // $45,001, TNC = -$4,999 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(45_001_000_000), // $45,001, TNC = -$4,999 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), }, }, offsettingSubaccount: constants.Dave_Num0_1BTC_Long_50000USD, @@ -1593,16 +1597,17 @@ func TestProcessDeleveraging_Rounding(t *testing.T) { liquidatedSubaccount: satypes.Subaccount{ Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(-50_000_000_000 - 4_999_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(-50_000_000_000-4_999_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100_000_000), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100_000_000), + big.NewInt(0), + ), }, }, offsettingSubaccount: constants.Carl_Num0_1BTC_Short_100000USD, diff --git a/protocol/x/clob/keeper/liquidations_test.go b/protocol/x/clob/keeper/liquidations_test.go index e0a6a8c00f..7b0dc1bd65 100644 --- a/protocol/x/clob/keeper/liquidations_test.go +++ b/protocol/x/clob/keeper/liquidations_test.go @@ -11,7 +11,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" "github.com/dydxprotocol/v4-chain/protocol/lib" @@ -486,20 +485,22 @@ func TestPlacePerpetualLiquidation_PreexistingLiquidation(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(54_999_000_000), // $54,999 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(54_999_000_000), // $54,999 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - }, - { - PerpetualId: 1, - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(0), + ), }, }, constants.Dave_Num0_1BTC_Long_50000USD, @@ -569,20 +570,22 @@ func TestPlacePerpetualLiquidation_PreexistingLiquidation(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(54_999_000_000), // $54,999 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(54_999_000_000), // $54,999 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - }, - { - PerpetualId: 1, - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(0), + ), }, }, constants.Dave_Num0_1BTC_Long_50000USD, @@ -697,20 +700,22 @@ func TestPlacePerpetualLiquidation_PreexistingLiquidation(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(53_000_000_000), // $53,000 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(53_000_000_000), // $53,000 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - }, - { - PerpetualId: 1, - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(0), + ), }, }, constants.Dave_Num0_1BTC_Long_50000USD, @@ -1095,20 +1100,22 @@ func TestPlacePerpetualLiquidation_PreexistingLiquidation(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(54_999_000_000), // $54,999 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(54_999_000_000), // $54,999 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - }, - { - PerpetualId: 1, - Quantums: dtypes.NewInt(-2_000_000_000), // -2 ETH - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(-2_000_000_000), // -2 ETH + big.NewInt(0), + ), }, }, constants.Dave_Num0_1BTC_Long_50000USD, @@ -1374,19 +1381,19 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - 50_000_000_000 - 250_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-50_000_000_000-250_000_000), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(100_000_000_000), // $100,000 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(100_000_000_000), // $100,000 + ), }, }, }, @@ -1432,33 +1439,33 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - 12_500_000_000 - 62_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-12_500_000_000-62_500_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 12_500_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+12_500_000_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(75_000_000), // 0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(75_000_000), // 0.75 BTC + big.NewInt(0), + ), }, }, }, @@ -1512,10 +1519,10 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 50_499_000_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+50_499_000_000), + ), }, }, }, @@ -1568,33 +1575,33 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - (50_498_000_000 / 4) - 250_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-(50_498_000_000/4)-250_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + (50_498_000_000 / 4)), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+(50_498_000_000/4)), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(75_000_000), // 0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(75_000_000), // 0.75 BTC + big.NewInt(0), + ), }, }, }, @@ -1681,17 +1688,17 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(49_999_000_000 - 12_499_750_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(49_999_000_000-12_499_750_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, // Dave's bankruptcy price to close 1 BTC long is $50,000, and deleveraging can not be @@ -1701,10 +1708,10 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Dave_Num1, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 12_499_750_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+12_499_750_000), + ), }, }, }, @@ -1754,18 +1761,18 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(49_999_000_000 - 24_999_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(49_999_000_000-24_999_500_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, + testutil.CreateSinglePerpetualPosition( + 0, // Deleveraging fails for remaining amount. - Quantums: dtypes.NewInt(-50_000_000), // -0.5 BTC - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(-50_000_000), // -0.5 BTC + big.NewInt(0), + ), }, }, // Dave_Num0 does not change since deleveraging against this subaccount failed. @@ -1773,10 +1780,10 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Dave_Num1, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 24_999_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+24_999_500_000), + ), }, }, }, @@ -1830,33 +1837,33 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_499_000_000 - (50_498_000_000 / 4) - 250_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_499_000_000-(50_498_000_000/4)-250_000), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + (50_498_000_000 / 4)), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+(50_498_000_000/4)), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(75_000_000), // 0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(75_000_000), // 0.75 BTC + big.NewInt(0), + ), }, }, }, @@ -1912,10 +1919,10 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 50_499_500_000), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+50_499_500_000), + ), }, }, }, @@ -1980,39 +1987,39 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt( - 54_999_000_000 - 50_000_000_000/4 - + testutil.CreateSingleAssetPosition( + 0, + big.NewInt( + 54_999_000_000-50_000_000_000/4- lib.BigIntMulPpm( big.NewInt(50_000_000_000/4), constants.LiquidationsConfig_No_Limit.MaxLiquidationFeePpm, ).Int64(), ), - }, + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-75_000_000), // -0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-75_000_000), // -0.75 BTC + big.NewInt(0), + ), }, }, { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(50_000_000_000 + 50_000_000_000/4), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(50_000_000_000+50_000_000_000/4), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(75_000_000), // 0.75 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(75_000_000), // 0.75 BTC + big.NewInt(0), + ), }, }, }, @@ -2324,10 +2331,11 @@ func TestIsLiquidatable(t *testing.T) { }, perpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC, $5,000 notional. - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000_000), // 0.1 BTC, $5,000 notional. + big.NewInt(0), + ), }, assetPositions: testutil.CreateUsdcAssetPositions( big.NewInt(constants.QuoteBalance_OneDollar * -4_000), @@ -2340,10 +2348,11 @@ func TestIsLiquidatable(t *testing.T) { }, perpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC, $5,000 notional. - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000_000), // 0.1 BTC, $5,000 notional. + big.NewInt(0), + ), }, assetPositions: testutil.CreateUsdcAssetPositions( big.NewInt(constants.QuoteBalance_OneDollar * -4_500), @@ -2356,10 +2365,11 @@ func TestIsLiquidatable(t *testing.T) { }, perpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC, $5,000 notional. - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000_000), // 0.1 BTC, $5,000 notional. + big.NewInt(0), + ), }, assetPositions: testutil.CreateUsdcAssetPositions( big.NewInt(constants.QuoteBalance_OneDollar * -4_501), @@ -4079,10 +4089,11 @@ func TestGetPerpetualPositionToLiquidate(t *testing.T) { }, `full position is returned when position size is smaller than StepBaseQuantums`: { perpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(5), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(5), + big.NewInt(0), + ), }, perpetuals: []perptypes.Perpetual{ constants.BtcUsd_20PercentInitial_10PercentMaintenance, @@ -4107,10 +4118,11 @@ func TestGetPerpetualPositionToLiquidate(t *testing.T) { }, `returned position size is rounded down to the nearest clob.stepBaseQuantums`: { perpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(140), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(140), + big.NewInt(0), + ), }, perpetuals: []perptypes.Perpetual{ constants.BtcUsd_20PercentInitial_10PercentMaintenance, @@ -4136,10 +4148,11 @@ func TestGetPerpetualPositionToLiquidate(t *testing.T) { }, `returned position size is at least clob.stepBaseQuantums`: { perpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(20), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(20), + big.NewInt(0), + ), }, perpetuals: []perptypes.Perpetual{ constants.BtcUsd_20PercentInitial_10PercentMaintenance, @@ -4270,10 +4283,11 @@ func TestGetPerpetualPositionToLiquidate(t *testing.T) { }, `Result is rounded to nearest step size`: { perpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(21), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(21), + big.NewInt(0), + ), }, perpetuals: []perptypes.Perpetual{ constants.BtcUsd_20PercentInitial_10PercentMaintenance, @@ -5015,10 +5029,11 @@ func TestGetMaxAndMinPositionNotionalLiquidatable(t *testing.T) { }, SubaccountBlockLimits: constants.SubaccountBlockLimits_No_Limit, }, - positionToLiquidate: &satypes.PerpetualPosition{ - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, + positionToLiquidate: testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), expectedMinPosNotionalLiquidatable: big.NewInt(100), expectedMaxPosNotionalLiquidatable: big.NewInt(50_000_000_000), // $50,000 }, @@ -5032,10 +5047,11 @@ func TestGetMaxAndMinPositionNotionalLiquidatable(t *testing.T) { }, SubaccountBlockLimits: constants.SubaccountBlockLimits_No_Limit, }, - positionToLiquidate: &satypes.PerpetualPosition{ - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, + positionToLiquidate: testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), expectedMinPosNotionalLiquidatable: big.NewInt(100), expectedMaxPosNotionalLiquidatable: big.NewInt(25_000_000_000), // $25,000 }, @@ -5049,19 +5065,21 @@ func TestGetMaxAndMinPositionNotionalLiquidatable(t *testing.T) { }, SubaccountBlockLimits: constants.SubaccountBlockLimits_No_Limit, }, - positionToLiquidate: &satypes.PerpetualPosition{ - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000), // $5 notional - }, + positionToLiquidate: testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000), // $5 notional + big.NewInt(0), + ), expectedMinPosNotionalLiquidatable: big.NewInt(5_000_000), // $5 expectedMaxPosNotionalLiquidatable: big.NewInt(5_000_000), // $5 }, "errors are propagated": { liquidationConfig: constants.LiquidationsConfig_No_Limit, - positionToLiquidate: &satypes.PerpetualPosition{ - PerpetualId: uint32(999), // non-existent - Quantums: dtypes.NewInt(1), - }, + positionToLiquidate: testutil.CreateSinglePerpetualPosition( + uint32(999), // non-existent + big.NewInt(1), + big.NewInt(0), + ), expectedErr: perptypes.ErrPerpetualDoesNotExist, }, } diff --git a/protocol/x/clob/keeper/msg_server_place_order_test.go b/protocol/x/clob/keeper/msg_server_place_order_test.go index 0ddcb99da2..8d2760bf65 100644 --- a/protocol/x/clob/keeper/msg_server_place_order_test.go +++ b/protocol/x/clob/keeper/msg_server_place_order_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "context" "errors" + "math/big" "testing" "time" @@ -16,6 +17,7 @@ import ( clobtest "github.com/dydxprotocol/v4-chain/protocol/testutil/clob" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" "github.com/dydxprotocol/v4-chain/protocol/x/clob/keeper" @@ -504,10 +506,10 @@ func TestHandleMsgPlaceOrder(t *testing.T) { { Id: &testOrder.OrderId.SubaccountId, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(tc.assetQuantums), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(tc.assetQuantums), + ), }, }, } diff --git a/protocol/x/clob/keeper/process_operations_liquidations_test.go b/protocol/x/clob/keeper/process_operations_liquidations_test.go index e4e873458b..73a11eba89 100644 --- a/protocol/x/clob/keeper/process_operations_liquidations_test.go +++ b/protocol/x/clob/keeper/process_operations_liquidations_test.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "math" + "math/big" "testing" storetypes "cosmossdk.io/store/types" @@ -12,12 +13,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/mocks" testutil_bank "github.com/dydxprotocol/v4-chain/protocol/testutil/bank" clobtest "github.com/dydxprotocol/v4-chain/protocol/testutil/clob" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" @@ -40,20 +41,22 @@ func TestProcessProposerMatches_Liquidation_Undercollateralized_Determinism(t *t { Id: &constants.Dave_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(-45_001_000_000), // -$45,001 - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(-45_001_000_000), // -$45,001 + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, - { - PerpetualId: 1, - Quantums: dtypes.NewInt(1000), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(1000), + big.NewInt(0), + ), }, }, }, @@ -411,18 +414,18 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Carl_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-50_000_000), // .5 BTC + big.NewInt(0), + ), }, constants.Dave_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), // .5 BTC + big.NewInt(0), + ), }, }, expectedProcessProposerMatchesEvents: types.ProcessProposerMatchesEvents{ @@ -516,18 +519,18 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Carl_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-50_000_000), // .5 BTC + big.NewInt(0), + ), }, constants.Dave_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), // .5 BTC + big.NewInt(0), + ), }, }, expectedProcessProposerMatchesEvents: types.ProcessProposerMatchesEvents{ @@ -833,18 +836,18 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Carl_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-50_000_000), // .5 BTC + big.NewInt(0), + ), }, constants.Dave_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), // .5 BTC + big.NewInt(0), + ), }, }, expectedProcessProposerMatchesEvents: types.ProcessProposerMatchesEvents{ @@ -874,16 +877,17 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) { { Id: &constants.Carl_Num0, AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(5_499), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(5_499), + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-10), // Liquidatable position is smaller than StepBaseQuantums - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-10), // Liquidatable position is smaller than StepBaseQuantums + big.NewInt(0), + ), }, }, constants.Dave_Num0_1BTC_Long_50000USD, diff --git a/protocol/x/clob/keeper/process_operations_long_term_test.go b/protocol/x/clob/keeper/process_operations_long_term_test.go index ff164275ce..129b60c4f7 100644 --- a/protocol/x/clob/keeper/process_operations_long_term_test.go +++ b/protocol/x/clob/keeper/process_operations_long_term_test.go @@ -2,17 +2,18 @@ package keeper_test import ( "math" + "math/big" "testing" "time" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/mocks" testutil_bank "github.com/dydxprotocol/v4-chain/protocol/testutil/bank" clobtest "github.com/dydxprotocol/v4-chain/protocol/testutil/clob" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" @@ -452,18 +453,18 @@ func TestProcessProposerMatches_LongTerm_Success(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Carl_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-50_000_000), // .5 BTC + big.NewInt(0), + ), }, constants.Dave_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), // .5 BTC + big.NewInt(0), + ), }, }, }, @@ -806,18 +807,18 @@ func TestProcessProposerMatches_LongTerm_Success(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Carl_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-50_000_000), // .5 BTC + big.NewInt(0), + ), }, constants.Dave_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), // .5 BTC + big.NewInt(0), + ), }, }, }, @@ -898,18 +899,18 @@ func TestProcessProposerMatches_LongTerm_Success(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Carl_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-50_000_000), // .5 BTC + big.NewInt(0), + ), }, constants.Dave_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(50_000_000), // .5 BTC - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(50_000_000), // .5 BTC + big.NewInt(0), + ), }, }, }, diff --git a/protocol/x/clob/keeper/process_operations_test.go b/protocol/x/clob/keeper/process_operations_test.go index d4998bbe62..60fa75f094 100644 --- a/protocol/x/clob/keeper/process_operations_test.go +++ b/protocol/x/clob/keeper/process_operations_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "math/big" "testing" "time" @@ -11,7 +12,6 @@ import ( "cosmossdk.io/store/prefix" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" "github.com/dydxprotocol/v4-chain/protocol/indexer/shared" @@ -21,6 +21,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" perptest "github.com/dydxprotocol/v4-chain/protocol/testutil/perpetuals" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" "github.com/dydxprotocol/v4-chain/protocol/x/clob/memclob" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" @@ -121,10 +122,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -133,10 +135,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, @@ -215,18 +218,18 @@ func TestProcessProposerOperations(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Bob_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 - 100_000_000), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000-100_000_000), + big.NewInt(0), + ), }, constants.Alice_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 + 100_000_000), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000+100_000_000), + big.NewInt(0), + ), }, }, }, @@ -245,10 +248,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -257,10 +261,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, @@ -339,18 +344,18 @@ func TestProcessProposerOperations(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Bob_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 - 100_000_000), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000-100_000_000), + big.NewInt(0), + ), }, constants.Alice_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 + 100_000_000), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000+100_000_000), + big.NewInt(0), + ), }, }, }, @@ -369,10 +374,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -381,10 +387,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, @@ -450,18 +457,18 @@ func TestProcessProposerOperations(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Bob_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 - 5), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000-5), + big.NewInt(0), + ), }, constants.Alice_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 + 5), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000+5), + big.NewInt(0), + ), }, }, }, @@ -480,10 +487,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -492,10 +500,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, @@ -542,18 +551,18 @@ func TestProcessProposerOperations(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Bob_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 - 5), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000-5), + big.NewInt(0), + ), }, constants.Alice_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 + 5), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000+5), + big.NewInt(0), + ), }, }, }, @@ -572,10 +581,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -584,10 +594,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -596,10 +607,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, @@ -705,25 +717,25 @@ func TestProcessProposerOperations(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Bob_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 - 10), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000-10), + big.NewInt(0), + ), }, constants.Alice_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 + 10 + 15), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000+10+15), + big.NewInt(0), + ), }, constants.Carl_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 - 15), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000-15), + big.NewInt(0), + ), }, }, }, @@ -1095,18 +1107,18 @@ func TestProcessProposerOperations(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Carl_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(-100_000_000 + 50_000_000), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(-100_000_000+50_000_000), + big.NewInt(0), + ), }, constants.Dave_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100_000_000 - 50_000_000), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100_000_000-50_000_000), + big.NewInt(0), + ), }, }, expectedNegativeTncSubaccountSeen: map[uint32]bool{ @@ -1305,10 +1317,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -1317,10 +1330,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, @@ -1457,10 +1471,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -1469,10 +1484,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, @@ -1521,18 +1537,18 @@ func TestProcessProposerOperations(t *testing.T) { }, expectedPerpetualPositions: map[satypes.SubaccountId][]*satypes.PerpetualPosition{ constants.Bob_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 - 5), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000-5), + big.NewInt(0), + ), }, constants.Alice_Num0: { - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000 + 5), - FundingIndex: dtypes.ZeroInt(), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000+5), + big.NewInt(0), + ), }, }, }, @@ -1551,10 +1567,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -1563,10 +1580,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, @@ -1605,10 +1623,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, { @@ -1617,10 +1636,11 @@ func TestProcessProposerOperations(t *testing.T) { &constants.Usdc_Asset_100_000, }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(1_000_000_000), // 10 BTC - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(1_000_000_000), // 10 BTC + big.NewInt(0), + ), }, }, }, diff --git a/protocol/x/sending/app_test.go b/protocol/x/sending/app_test.go index 7de5f45333..0803a9f368 100644 --- a/protocol/x/sending/app_test.go +++ b/protocol/x/sending/app_test.go @@ -25,6 +25,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/indexer/msgsender" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" sample_testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/sample" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assetstypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" prices "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" @@ -139,13 +140,12 @@ func TestMsgCreateTransfer(t *testing.T) { { Id: &(tc.senderSubaccountId), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: constants.Usdc.Id, - Index: 0, - Quantums: dtypes.NewIntFromUint64( + testutil.CreateSingleAssetPosition( + constants.Usdc.Id, + big.NewInt(0).SetUint64( tc.senderInitialBalance, ), - }, + ), }, }, } @@ -155,13 +155,12 @@ func TestMsgCreateTransfer(t *testing.T) { satypes.Subaccount{ Id: &(tc.recipientSubaccountId), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: constants.Usdc.Id, - Index: 0, - Quantums: dtypes.NewIntFromUint64( + testutil.CreateSingleAssetPosition( + constants.Usdc.Id, + big.NewInt(0).SetUint64( rand.NewRand().Uint64(), ), - }, + ), }, }, ) diff --git a/protocol/x/subaccounts/keeper/isolated_subaccount_test.go b/protocol/x/subaccounts/keeper/isolated_subaccount_test.go index 265efb8177..33100e29f4 100644 --- a/protocol/x/subaccounts/keeper/isolated_subaccount_test.go +++ b/protocol/x/subaccounts/keeper/isolated_subaccount_test.go @@ -4,8 +4,8 @@ import ( "math/big" "testing" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/keeper" @@ -146,10 +146,10 @@ func TestGetIsolatedPerpetualStateTransition(t *testing.T) { &constants.PerpetualPosition_OneISOLong, }, AssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(-40_000_000), // -$40 - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(-40_000_000), // -$40 + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -184,10 +184,10 @@ func TestGetIsolatedPerpetualStateTransition(t *testing.T) { &constants.PerpetualPosition_OneISOLong, }, AssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(-40_000_000), // -$65 - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(-40_000_000), // -$65 + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -216,10 +216,10 @@ func TestGetIsolatedPerpetualStateTransition(t *testing.T) { &constants.PerpetualPosition_OneISOLong, }, AssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(50_000_000), // $50 - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(50_000_000), // $50 + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -244,14 +244,14 @@ func TestGetIsolatedPerpetualStateTransition(t *testing.T) { &constants.PerpetualPosition_OneISOLong, }, AssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(-40_000_000), // -$40 - }, - { - AssetId: constants.BtcUsd.Id, - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(-40_000_000), // -$40 + ), + testutil.CreateSingleAssetPosition( + constants.BtcUsd.Id, + big.NewInt(100_000_000), // 1 BTC + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -285,14 +285,14 @@ func TestGetIsolatedPerpetualStateTransition(t *testing.T) { &constants.PerpetualPosition_OneISOLong, }, AssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(50_000_000), // $50 - }, - { - AssetId: constants.BtcUsd.Id, - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(50_000_000), // $50 + ), + testutil.CreateSingleAssetPosition( + constants.BtcUsd.Id, + big.NewInt(100_000_000), // 1 BTC + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ diff --git a/protocol/x/subaccounts/keeper/subaccount_test.go b/protocol/x/subaccounts/keeper/subaccount_test.go index 6fee0958e7..6c84119781 100644 --- a/protocol/x/subaccounts/keeper/subaccount_test.go +++ b/protocol/x/subaccounts/keeper/subaccount_test.go @@ -137,10 +137,11 @@ func TestGetCollateralPool(t *testing.T) { constants.IsoUsd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: constants.IsoUsd_IsolatedMarket.GetId(), - Quantums: dtypes.NewInt(100_000_000), - }, + testutil.CreateSinglePerpetualPosition( + constants.IsoUsd_IsolatedMarket.GetId(), + big.NewInt(100_000_000), + big.NewInt(0), + ), }, expectedAddress: authtypes.NewModuleAddress( types.ModuleName + ":" + lib.UintToString(constants.IsoUsd_IsolatedMarket.GetId()), @@ -407,32 +408,32 @@ func TestUpdateSubaccounts(t *testing.T) { }, newFundingIndices: []*big.Int{big.NewInt(-10)}, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(-30), // indexDelta=20, settlement=-20*100 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(-30), // indexDelta=20, settlement=-20*100 + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(-10), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(-10), + ), }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(-2100), // 2100 USDC - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(-2100), // 2100 USDC + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), - FundingIndex: dtypes.NewInt(-10), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), + big.NewInt(-10), + ), }, }, expectedSubaccountIdToFundingPayments: map[types.SubaccountId]map[uint32]dtypes.SerializableInt{ @@ -464,33 +465,33 @@ func TestUpdateSubaccounts(t *testing.T) { }, newFundingIndices: []*big.Int{big.NewInt(-17)}, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(500_000), // 0.005 BTC + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(500_000), // 0.005 BTC // indexDelta=-17, settlement=17*500_000/1_000_000=8 - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(500_000), // 1 BTC - FundingIndex: dtypes.NewInt(-17), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(500_000), // 1 BTC + big.NewInt(-17), + ), }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(-92), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(-92), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(500_000), - FundingIndex: dtypes.NewInt(-17), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(500_000), + big.NewInt(-17), + ), }, }, expectedSubaccountIdToFundingPayments: map[types.SubaccountId]map[uint32]dtypes.SerializableInt{ @@ -524,19 +525,19 @@ func TestUpdateSubaccounts(t *testing.T) { &constants.PerpetualPosition_OneBTCLong, }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(300_000_000), // 3 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(300_000_000), // 3 BTC + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - &types.PerpetualPosition{ - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(300_000_000), // 3 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(300_000_000), // 3 BTC + big.NewInt(0), + ), }, }, updates: []types.Update{ @@ -592,10 +593,10 @@ func TestUpdateSubaccounts(t *testing.T) { expectedAssetPositions: []*types.AssetPosition{}, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(0), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(0), + ), }, }, updates: []types.Update{ @@ -623,26 +624,26 @@ func TestUpdateSubaccounts(t *testing.T) { &constants.PerpetualPosition_OneBTCLong, }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(50_000_000), // .50 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(50_000_000), // .50 BTC + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(50_000_000), // .50 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(50_000_000), // .50 BTC + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(50_000_000_000), + ), }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { @@ -680,11 +681,11 @@ func TestUpdateSubaccounts(t *testing.T) { expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { // Position closed update. - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(0), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(0), + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ @@ -723,35 +724,35 @@ func TestUpdateSubaccounts(t *testing.T) { constants.BtcUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{}, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { // Position closed update. - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(0), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(0), + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(50_000_000_000), + ), }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(50_000_000_000), + ), }, }, updates: []types.Update{ @@ -776,44 +777,44 @@ func TestUpdateSubaccounts(t *testing.T) { constants.EthUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-1_000_000_000_000_000_000), // -1 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-1_000_000_000_000_000_000), // -1 ETH + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-200_000_000), // -2 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-200_000_000), // -2 BTC + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-200_000_000), // -2 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-200_000_000), // -2 BTC + big.NewInt(0), + ), // Position closed update. - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(0), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(0), + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000_000), + ), }, updates: []types.Update{ { @@ -890,44 +891,44 @@ func TestUpdateSubaccounts(t *testing.T) { constants.EthUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-2_000_000_000), // -2 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-2_000_000_000), // -2 ETH + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { // Position closed update. - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(0), - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-2_000_000_000), // -2 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(0), + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-2_000_000_000), // -2 ETH + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(50_000_000_000), + ), }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { @@ -965,33 +966,33 @@ func TestUpdateSubaccounts(t *testing.T) { newFundingIndices: []*big.Int{big.NewInt(-15)}, perpetualPositions: []*types.PerpetualPosition{}, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(-15), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(-15), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(-15), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(-15), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(50_000_000_000), + ), }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(50_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(50_000_000_000), + ), }, }, updates: []types.Update{ @@ -1017,33 +1018,33 @@ func TestUpdateSubaccounts(t *testing.T) { }, perpetualPositions: []*types.PerpetualPosition{}, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // 1 BTC + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // 1 BTC + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(150_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(150_000_000_000), + ), }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(150_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(150_000_000_000), + ), }, }, updates: []types.Update{ @@ -1073,26 +1074,26 @@ func TestUpdateSubaccounts(t *testing.T) { }, expectedPerpetualPositions: []*types.PerpetualPosition{ &constants.PerpetualPosition_OneBTCLong, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000_000), + ), }, updates: []types.Update{ { @@ -1118,34 +1119,34 @@ func TestUpdateSubaccounts(t *testing.T) { }, perpetualPositions: []*types.PerpetualPosition{ &constants.PerpetualPosition_OneBTCLong, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(500_000_000), // 5 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(500_000_000), // 5 ETH + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ &constants.PerpetualPosition_OneBTCLong, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-500_000_000), // -5 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-500_000_000), // -5 ETH + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-500_000_000), // -5 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-500_000_000), // -5 ETH + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000_000), + ), }, updates: []types.Update{ { @@ -1171,39 +1172,39 @@ func TestUpdateSubaccounts(t *testing.T) { }, perpetualPositions: []*types.PerpetualPosition{ &constants.PerpetualPosition_OneBTCLong, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(1_000_000_000), // 1 SOL - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(1_000_000_000), // 1 SOL + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ &constants.PerpetualPosition_OneBTCLong, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(1_000_000_000), // 1 SOL - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(1_000_000_000), // 1 SOL + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000_000), + ), }, updates: []types.Update{ { @@ -1228,44 +1229,44 @@ func TestUpdateSubaccounts(t *testing.T) { constants.SolUsd_20PercentInitial_10PercentMaintenance, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(1_000_000_000), // 1 SOL - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(1_000_000_000), // 1 SOL + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ &constants.PerpetualPosition_OneBTCLong, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(1_000_000_000), // 1 SOL - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(1_000_000_000), // 1 SOL + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000_000), + ), }, updates: []types.Update{ { @@ -1295,36 +1296,36 @@ func TestUpdateSubaccounts(t *testing.T) { big.NewInt(2000), // sol }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(1_000_000_000), // 1 SOL - FundingIndex: dtypes.NewInt(1700), - }, + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(1_000_000_000), // 1 SOL + big.NewInt(1700), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(-5000), - }, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(1_000_000_000), // 1 SOL - FundingIndex: dtypes.NewInt(2000), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(-5000), + ), + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(1_000_000_000), // 1 SOL + big.NewInt(2000), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(-5000), - }, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(1_000_000_000), // 1 SOL - FundingIndex: dtypes.NewInt(2000), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(-5000), + ), + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(1_000_000_000), // 1 SOL + big.NewInt(2000), + ), }, }, expectedSubaccountIdToFundingPayments: map[types.SubaccountId]map[uint32]dtypes.SerializableInt{ @@ -1333,10 +1334,10 @@ func TestUpdateSubaccounts(t *testing.T) { }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(99_999_700_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(99_999_700_000), + ), }, updates: []types.Update{ { @@ -1362,58 +1363,58 @@ func TestUpdateSubaccounts(t *testing.T) { }, perpetualPositions: []*types.PerpetualPosition{ &constants.PerpetualPosition_OneBTCLong, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(1_000_000_000), // 1 SOL - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(1_000_000_000), // 1 SOL + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(200_000_000), // 2 BTC - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(2_000_000_000), // 2 ETH - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(2_000_000_000), // 2 SOL - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(200_000_000), // 2 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(2_000_000_000), // 2 ETH + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(2_000_000_000), // 2 SOL + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(200_000_000), // 2 BTC - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(2_000_000_000), // 2 ETH - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(2), - Quantums: dtypes.NewInt(2_000_000_000), // 2 SOL - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(200_000_000), // 2 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(2_000_000_000), // 2 ETH + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(2), + big.NewInt(2_000_000_000), // 2 SOL + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000_000), + ), }, updates: []types.Update{ { @@ -1444,54 +1445,54 @@ func TestUpdateSubaccounts(t *testing.T) { constants.EthUsd_20PercentInitial_10PercentMaintenance, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(1_000_000_000), // 1 ETH + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{}, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { // Position closed update. - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(0), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(0), + big.NewInt(0), + ), }, { Owner: "non-existent account", Number: uint32(12), }: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000), + ), }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000), + ), }, { Owner: "non-existent account", Number: uint32(12), }: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(500_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(500_000_000), + ), }, }, updates: []types.Update{ @@ -1595,11 +1596,11 @@ func TestUpdateSubaccounts(t *testing.T) { }, newFundingIndices: []*big.Int{big.NewInt(-10)}, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC - FundingIndex: dtypes.NewInt(-7), // indexDelta=-3, settlement=3 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC + big.NewInt(-7), // indexDelta=-3, settlement=3 + ), }, updates: []types.Update{ { @@ -1607,28 +1608,28 @@ func TestUpdateSubaccounts(t *testing.T) { }, }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC - FundingIndex: dtypes.NewInt(-10), // indexDelta=-3, settlement=3 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC + big.NewInt(-10), // indexDelta=-3, settlement=3 + ), }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewIntFromBigInt(new(big.Int).Add( + testutil.CreateSingleAssetPosition( + uint32(0), + new(big.Int).Add( new(big.Int).SetUint64(math.MaxUint64), new(big.Int).SetInt64(1), - )), - }, + ), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), - FundingIndex: dtypes.NewInt(-10), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), + big.NewInt(-10), + ), }, }, expectedSubaccountIdToFundingPayments: map[types.SubaccountId]map[uint32]dtypes.SerializableInt{ @@ -1638,13 +1639,13 @@ func TestUpdateSubaccounts(t *testing.T) { }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewIntFromBigInt(new(big.Int).Add( + testutil.CreateSingleAssetPosition( + uint32(0), + new(big.Int).Add( new(big.Int).SetUint64(math.MaxUint64), new(big.Int).SetInt64(1), - )), - }, + ), + ), }, }, msgSenderEnabled: true, @@ -1667,23 +1668,19 @@ func TestUpdateSubaccounts(t *testing.T) { }, }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewIntFromBigInt( - big_testutil.MustFirst(new(big.Int).SetString("18446744073709551616", 10)), // 1 BTC - ), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big_testutil.MustFirst(new(big.Int).SetString("18446744073709551616", 10)), // 1 BTC + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewIntFromBigInt( - big_testutil.MustFirst(new(big.Int).SetString("18446744073709551616", 10)), // 1 BTC - ), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big_testutil.MustFirst(new(big.Int).SetString("18446744073709551616", 10)), // 1 BTC + big.NewInt(0), + ), }, }, msgSenderEnabled: true, @@ -1696,29 +1693,27 @@ func TestUpdateSubaccounts(t *testing.T) { constants.BtcUsd_SmallMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewIntFromUint64(math.MaxUint64), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(0).SetUint64(math.MaxUint64), + big.NewInt(0), + ), }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(1), - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(1), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - new(big.Int).SetUint64(math.MaxUint64), - new(big.Int).SetUint64(1), - ), + testutil.CreateSinglePerpetualPosition( + uint32(0), + new(big.Int).Add( + new(big.Int).SetUint64(math.MaxUint64), + new(big.Int).SetUint64(1), ), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, updates: []types.Update{ { @@ -1733,24 +1728,22 @@ func TestUpdateSubaccounts(t *testing.T) { }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - new(big.Int).SetUint64(math.MaxUint64), - new(big.Int).SetUint64(1), - ), + testutil.CreateSinglePerpetualPosition( + uint32(0), + new(big.Int).Add( + new(big.Int).SetUint64(math.MaxUint64), + new(big.Int).SetUint64(1), ), - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1), + ), }, }, msgSenderEnabled: false, @@ -1780,43 +1773,43 @@ func TestUpdateSubaccounts(t *testing.T) { }, newFundingIndices: []*big.Int{big.NewInt(-10), big.NewInt(-8)}, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC // indexDelta=-5 - FundingIndex: dtypes.NewInt(-5), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-2_000_000_000), // -2 ETH + big.NewInt(-5), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-2_000_000_000), // -2 ETH // indexDelta=-2 - FundingIndex: dtypes.NewInt(-6), - }, + big.NewInt(-6), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(-10), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH - FundingIndex: dtypes.NewInt(-8), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(-10), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(-8), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(-10), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH - FundingIndex: dtypes.NewInt(-8), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(-10), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(-8), + ), }, }, expectedSubaccountIdToFundingPayments: map[types.SubaccountId]map[uint32]dtypes.SerializableInt{ @@ -1828,13 +1821,13 @@ func TestUpdateSubaccounts(t *testing.T) { }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // Original Asset Position - Funding Payments // = 100_000_000_000 - 4_000 - 500 // = 99_999_995_500 - Quantums: dtypes.NewInt(99_999_995_500), - }, + big.NewInt(99_999_995_500), + ), }, updates: []types.Update{ { @@ -1858,39 +1851,39 @@ func TestUpdateSubaccounts(t *testing.T) { }, newFundingIndices: []*big.Int{big.NewInt(0), big.NewInt(-8)}, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC // indexDelta=0 - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-2_000_000_000), // -2 ETH + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-2_000_000_000), // -2 ETH // indexDelta=-2 - FundingIndex: dtypes.NewInt(-6), - }, + big.NewInt(-6), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH - FundingIndex: dtypes.NewInt(-8), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(-8), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { // Only ETH position is emitted here. - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH - FundingIndex: dtypes.NewInt(-8), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(-8), + ), }, }, expectedSubaccountIdToFundingPayments: map[types.SubaccountId]map[uint32]dtypes.SerializableInt{ @@ -1899,14 +1892,14 @@ func TestUpdateSubaccounts(t *testing.T) { uint32(1): dtypes.NewInt(4_000), }, }, - expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), + expectedAssetPositions: []*types.AssetPosition{ + testutil.CreateSingleAssetPosition( + uint32(0), // Original Asset Position - Funding Payments // = 100_000_000_000 - 4_000 // = 99_999_996_000 - Quantums: dtypes.NewInt(99_999_996_000), - }, + big.NewInt(99_999_996_000), + ), }, updates: []types.Update{ { @@ -1930,39 +1923,39 @@ func TestUpdateSubaccounts(t *testing.T) { }, newFundingIndices: []*big.Int{big.NewInt(-10), big.NewInt(-8)}, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC // indexDelta=-5 - FundingIndex: dtypes.NewInt(-5), - }, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH + big.NewInt(-5), + ), + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-1_000_000_000), // -1 ETH // indexDelta=-2 - FundingIndex: dtypes.NewInt(-6), - }, + big.NewInt(-6), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(-10), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(-10), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // -1 BTC - FundingIndex: dtypes.NewInt(-10), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // -1 BTC + big.NewInt(-10), + ), // Position closed update. - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(0), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(0), + big.NewInt(0), + ), }, }, expectedSubaccountIdToFundingPayments: map[types.SubaccountId]map[uint32]dtypes.SerializableInt{ @@ -1974,13 +1967,13 @@ func TestUpdateSubaccounts(t *testing.T) { }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // Original Asset Position - Funding Payments // = 100_000_000_000 - 2_000 - 500 // = 99_999_997_500 - Quantums: dtypes.NewInt(99_999_997_500), - }, + big.NewInt(99_999_997_500), + ), }, updates: []types.Update{ { @@ -2004,29 +1997,29 @@ func TestUpdateSubaccounts(t *testing.T) { }, newFundingIndices: []*big.Int{big.NewInt(0)}, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(-1_000_000_000), // -1 ETH + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(-1_000_000_000), // -1 ETH // indexDelta=0 - FundingIndex: dtypes.NewInt(0), - }, + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{}, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { // Position closed update. - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(0), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(0), + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(100_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(100_000_000_000), + ), }, updates: []types.Update{ { @@ -2062,35 +2055,35 @@ func TestUpdateSubaccounts(t *testing.T) { ), }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(100), - Quantums: dtypes.NewInt(1_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(101), - Quantums: dtypes.NewInt(1_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(100), + big.NewInt(1_000_000_000), + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(101), + big.NewInt(1_000_000_000), + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(100), - Quantums: dtypes.NewInt(1_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(101), - Quantums: dtypes.NewInt(1_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(100), + big.NewInt(1_000_000_000), + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(101), + big.NewInt(1_000_000_000), + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{}, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1_000_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1_000_000_000_000), + ), }, updates: []types.Update{ { @@ -2177,24 +2170,24 @@ func TestUpdateSubaccounts(t *testing.T) { constants.IsoUsd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), + big.NewInt(0), + ), }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1_000_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1_000_000_000_000), + ), }, updates: []types.Update{ { @@ -2217,24 +2210,24 @@ func TestUpdateSubaccounts(t *testing.T) { constants.Iso2Usd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), + big.NewInt(0), + ), }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1_000_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1_000_000_000_000), + ), }, updates: []types.Update{ { @@ -2257,24 +2250,24 @@ func TestUpdateSubaccounts(t *testing.T) { constants.IsoUsd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), + big.NewInt(0), + ), }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1_000_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1_000_000_000_000), + ), }, updates: []types.Update{ { @@ -2308,33 +2301,33 @@ func TestUpdateSubaccounts(t *testing.T) { }, perpetualPositions: []*types.PerpetualPosition{}, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(999_900_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(999_900_000_000), + ), }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(999_900_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(999_900_000_000), + ), }, }, updates: []types.Update{ @@ -2372,34 +2365,34 @@ func TestUpdateSubaccounts(t *testing.T) { constants.IsoUsd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{}, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(0), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(0), + big.NewInt(0), + ), }, }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1_000_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1_000_000_000_000), + ), }, expectedUpdatedAssetPositions: map[types.SubaccountId][]*types.AssetPosition{ defaultSubaccountId: { - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1_000_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1_000_000_000_000), + ), }, }, updates: []types.Update{ @@ -2427,10 +2420,10 @@ func TestUpdateSubaccounts(t *testing.T) { perpetualPositions: []*types.PerpetualPosition{}, expectedPerpetualPositions: []*types.PerpetualPosition{}, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1_000_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1_000_000_000_000), + ), }, updates: []types.Update{ { @@ -2456,24 +2449,24 @@ func TestUpdateSubaccounts(t *testing.T) { constants.IsoUsd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), - Quantums: dtypes.NewInt(1_000_000_000_000), - }, + testutil.CreateSingleAssetPosition( + uint32(0), + big.NewInt(1_000_000_000_000), + ), }, updates: []types.Update{ { @@ -2555,26 +2548,26 @@ func TestUpdateSubaccounts(t *testing.T) { }, }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-9_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-9_000_000_000), + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-9_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-9_000_000_000), + big.NewInt(0), + ), }, constants.Bob_Num0: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(9_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(9_000_000_000), + big.NewInt(0), + ), }, }, expectedSuccess: true, @@ -2589,10 +2582,11 @@ func TestUpdateSubaccounts(t *testing.T) { constants.BtcUsd_20PercentInitial_10PercentMaintenance_OpenInterest2, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, assetPositions: testutil.CreateUsdcAssetPositions(big.NewInt(-40_000_000_000)), // -40_000 USDC updates: []types.Update{ @@ -2633,10 +2627,11 @@ func TestUpdateSubaccounts(t *testing.T) { 120_000_000_000, )), // 120_000 USDC PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-200_000_000), // -2 BTC - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-200_000_000), // -2 BTC + big.NewInt(0), + ), }, }, }, @@ -2662,26 +2657,26 @@ func TestUpdateSubaccounts(t *testing.T) { }, }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000_000), // 0.1 BTC + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000_000), // 0.1 BTC + big.NewInt(0), + ), }, constants.Bob_Num0: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-110_000_000), // -1.1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-110_000_000), // -1.1 BTC + big.NewInt(0), + ), }, }, expectedSuccess: true, @@ -2696,10 +2691,11 @@ func TestUpdateSubaccounts(t *testing.T) { constants.BtcUsd_20PercentInitial_10PercentMaintenance_OpenInterest1, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, assetPositions: testutil.CreateUsdcAssetPositions(big.NewInt(-40_000_000_000)), // -40_000 USDC updates: []types.Update{ @@ -2738,10 +2734,11 @@ func TestUpdateSubaccounts(t *testing.T) { Id: &constants.Bob_Num0, AssetPositions: testutil.CreateUsdcAssetPositions(big.NewInt(5_000_000_000)), // 5000 USDC PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000_000), // 0.1 BTC + big.NewInt(0), + ), }, }, }, @@ -2767,26 +2764,26 @@ func TestUpdateSubaccounts(t *testing.T) { }, }, expectedPerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000_000), // 0.1 BTC + big.NewInt(0), + ), }, expectedUpdatedPerpetualPositions: map[types.SubaccountId][]*types.PerpetualPosition{ defaultSubaccountId: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(10_000_000), // 0.1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(10_000_000), // 0.1 BTC + big.NewInt(0), + ), }, constants.Bob_Num0: { - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, }, expectedSuccess: true, @@ -4427,11 +4424,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { { Id: &constants.Bob_Num0, AssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // 900_000 USDC (just enough to collateralize 90 BTC at $50_000 and 20% IMF) - Quantums: dtypes.NewInt(900_000_000_000), - }, + big.NewInt(900_000_000_000), + ), }, }, }, @@ -4488,11 +4485,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { { Id: &constants.Bob_Num0, AssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // 900_000 USDC (just enough to collateralize 90 BTC at $50_000 and 20% IMF) - Quantums: dtypes.NewInt(900_000_000_000), - }, + big.NewInt(900_000_000_000), + ), }, }, }, @@ -4556,11 +4553,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { { Id: &constants.Bob_Num0, AssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // 900_000 USDC (just enough to collateralize 90 BTC at $50_000 and 20% IMF) - Quantums: dtypes.NewInt(900_000_000_000), - }, + big.NewInt(900_000_000_000), + ), }, }, }, @@ -4626,11 +4623,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { { Id: &constants.Bob_Num0, AssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // 900_000 USDC (just enough to collateralize 90 BTC at $50_000 and 20% IMF) - Quantums: dtypes.NewInt(900_000_000_000), - }, + big.NewInt(900_000_000_000), + ), }, }, }, @@ -4695,11 +4692,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { { Id: &constants.Bob_Num0, AssetPositions: []*types.AssetPosition{ - { - AssetId: uint32(0), + testutil.CreateSingleAssetPosition( + uint32(0), // 4_500_000 USDC (just enough to collateralize 90 BTC at $50_000 and 100% IMF) - Quantums: dtypes.NewInt(4_500_000_000_000), - }, + big.NewInt(4_500_000_000_000), + ), }, }, }, @@ -4774,11 +4771,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { "perpetual does not exist (should never happen)": { expectedErr: perptypes.ErrPerpetualDoesNotExist, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(999999), - Quantums: dtypes.NewIntFromUint64(math.MaxUint64), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(999999), + big.NewInt(0).SetUint64(math.MaxUint64), + big.NewInt(0), + ), }, updates: []types.Update{ {}, @@ -4789,11 +4786,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_SmallMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewIntFromUint64(math.MaxUint64), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(0).SetUint64(math.MaxUint64), + big.NewInt(0), + ), }, updates: []types.Update{ { @@ -5014,11 +5011,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC, - FundingIndex: dtypes.NewInt(-99), // indexDelta=99, net settlement=-99 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC, + big.NewInt(-99), // indexDelta=99, net settlement=-99 + ), }, updates: []types.Update{ { @@ -5036,11 +5033,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC, - FundingIndex: dtypes.NewInt(-100), // indexDelta=100, net settlement=-100 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC, + big.NewInt(-100), // indexDelta=100, net settlement=-100 + ), }, updates: []types.Update{ { @@ -5058,11 +5055,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC, - FundingIndex: dtypes.NewInt(-200), // indexDelta=200, net settlement=-200 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC, + big.NewInt(-200), // indexDelta=200, net settlement=-200 + ), }, updates: []types.Update{ { @@ -5081,11 +5078,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC, - FundingIndex: dtypes.NewInt(-200), // indexDelta=200, net settlement=-200 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC, + big.NewInt(-200), // indexDelta=200, net settlement=-200 + ), }, updates: []types.Update{ { @@ -5103,11 +5100,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC, - FundingIndex: dtypes.NewInt(100), // indexDelta=-100, net settlement=100 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC, + big.NewInt(100), // indexDelta=-100, net settlement=100 + ), }, updates: []types.Update{ {}, @@ -5123,11 +5120,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC, - FundingIndex: dtypes.NewInt(100), // indexDelta=-100, net settlement=100 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC, + big.NewInt(100), // indexDelta=-100, net settlement=100 + ), }, updates: []types.Update{ {}, @@ -5144,11 +5141,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC, - FundingIndex: dtypes.NewInt(-100), // indexDelta=100, net settlement=-100 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC, + big.NewInt(-100), // indexDelta=100, net settlement=-100 + ), }, updates: []types.Update{ {}, @@ -5165,11 +5162,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(1_000_000), // 0.01 BTC, - FundingIndex: dtypes.NewInt(3), // indexDelta=-3, net settlement=3 - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(1_000_000), // 0.01 BTC, + big.NewInt(3), // indexDelta=-3, net settlement=3 + ), }, updates: []types.Update{ { @@ -5202,16 +5199,16 @@ func TestCanUpdateSubaccounts(t *testing.T) { ), }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(100), - Quantums: dtypes.NewInt(1_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, - { - PerpetualId: uint32(101), - Quantums: dtypes.NewInt(1_000_000_000), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(100), + big.NewInt(1_000_000_000), + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + uint32(101), + big.NewInt(1_000_000_000), + big.NewInt(0), + ), }, updates: []types.Update{ { @@ -5283,11 +5280,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.IsoUsd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, updates: []types.Update{ { @@ -5309,11 +5306,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.Iso2Usd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(3), - Quantums: dtypes.NewInt(1_000_000_000), // 1 ISO - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(3), + big.NewInt(1_000_000_000), // 1 ISO + big.NewInt(0), + ), }, updates: []types.Update{ { @@ -5335,11 +5332,11 @@ func TestCanUpdateSubaccounts(t *testing.T) { constants.IsoUsd_IsolatedMarket, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, updates: []types.Update{ { @@ -5508,11 +5505,11 @@ func TestGetNetCollateralAndMarginRequirements(t *testing.T) { constants.BtcUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(62500), // 0.0125% rate at BTC=50,000 USDC - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(62500), // 0.0125% rate at BTC=50,000 USDC + ), }, }, "single perpetual, USDC asset position and unsettled funding (short)": { @@ -5522,11 +5519,11 @@ func TestGetNetCollateralAndMarginRequirements(t *testing.T) { constants.BtcUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(-100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(62500), // 0.0125% rate at BTC=50,000 USDC - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(-100_000_000), // 1 BTC + big.NewInt(62500), // 0.0125% rate at BTC=50,000 USDC + ), }, }, "non-existing perpetual heled by subaccount (should never happen)": { @@ -5538,11 +5535,11 @@ func TestGetNetCollateralAndMarginRequirements(t *testing.T) { constants.BtcUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(999999999), - Quantums: dtypes.NewInt(-100_000_000), // 1 BTC - FundingIndex: dtypes.NewInt(62500), // 0.0125% rate at BTC=50,000 USDC - }, + testutil.CreateSinglePerpetualPosition( + uint32(999999999), + big.NewInt(-100_000_000), // 1 BTC + big.NewInt(62500), // 0.0125% rate at BTC=50,000 USDC + ), }, expectedErr: perptypes.ErrPerpetualDoesNotExist, }, @@ -5601,11 +5598,11 @@ func TestGetNetCollateralAndMarginRequirements(t *testing.T) { constants.BtcUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewIntFromUint64(math.MaxUint64), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(0).SetUint64(math.MaxUint64), + big.NewInt(0), + ), }, perpetualUpdates: []types.PerpetualUpdate{ { @@ -5619,14 +5616,13 @@ func TestGetNetCollateralAndMarginRequirements(t *testing.T) { constants.BtcUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Neg( - new(big.Int).SetUint64(math.MaxUint64), - )), - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + new(big.Int).Neg( + new(big.Int).SetUint64(math.MaxUint64), + ), + big.NewInt(0), + ), }, perpetualUpdates: []types.PerpetualUpdate{ { @@ -5736,11 +5732,11 @@ func TestGetNetCollateralAndMarginRequirements(t *testing.T) { }, perpetualPositions: []*types.PerpetualPosition{ &constants.PerpetualPosition_OneBTCLong, - { - PerpetualId: uint32(1), - Quantums: dtypes.NewInt(500_000_000), // .5 ETH - FundingIndex: dtypes.NewInt(0), - }, + testutil.CreateSinglePerpetualPosition( + uint32(1), + big.NewInt(500_000_000), // .5 ETH + big.NewInt(0), + ), }, perpetualUpdates: []types.PerpetualUpdate{ { @@ -5759,10 +5755,11 @@ func TestGetNetCollateralAndMarginRequirements(t *testing.T) { constants.BtcUsd_NoMarginRequirement, }, perpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: uint32(0), - Quantums: dtypes.NewInt(100_000_000), // 1 BTC - }, + testutil.CreateSinglePerpetualPosition( + uint32(0), + big.NewInt(100_000_000), // 1 BTC + big.NewInt(0), + ), }, }, "asset with no balance and update": { diff --git a/protocol/x/subaccounts/lib/oimf_test.go b/protocol/x/subaccounts/lib/oimf_test.go index 13d9c7acc7..feb6a683a1 100644 --- a/protocol/x/subaccounts/lib/oimf_test.go +++ b/protocol/x/subaccounts/lib/oimf_test.go @@ -5,7 +5,7 @@ import ( "math/big" "testing" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" salib "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/lib" "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" @@ -199,10 +199,11 @@ func TestGetDeltaOpenInterestFromUpdates(t *testing.T) { SettledSubaccount: types.Subaccount{ Id: bobSubaccountId, PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: 1000, - Quantums: dtypes.NewInt(500), - }, + testutil.CreateSinglePerpetualPosition( + 1000, + big.NewInt(500), + big.NewInt(0), + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -240,10 +241,11 @@ func TestGetDeltaOpenInterestFromUpdates(t *testing.T) { SettledSubaccount: types.Subaccount{ Id: aliceSubaccountId, PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: 1000, - Quantums: dtypes.NewInt(500), - }, + testutil.CreateSinglePerpetualPosition( + 1000, + big.NewInt(500), + big.NewInt(0), + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -275,10 +277,11 @@ func TestGetDeltaOpenInterestFromUpdates(t *testing.T) { SettledSubaccount: types.Subaccount{ Id: aliceSubaccountId, PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: 1000, - Quantums: dtypes.NewInt(-100), - }, + testutil.CreateSinglePerpetualPosition( + 1000, + big.NewInt(-100), + big.NewInt(0), + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -292,10 +295,11 @@ func TestGetDeltaOpenInterestFromUpdates(t *testing.T) { SettledSubaccount: types.Subaccount{ Id: bobSubaccountId, PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: 1000, - Quantums: dtypes.NewInt(250), - }, + testutil.CreateSinglePerpetualPosition( + 1000, + big.NewInt(250), + big.NewInt(0), + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -318,10 +322,11 @@ func TestGetDeltaOpenInterestFromUpdates(t *testing.T) { SettledSubaccount: types.Subaccount{ Id: aliceSubaccountId, PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: 1000, - Quantums: dtypes.NewInt(-3100), - }, + testutil.CreateSinglePerpetualPosition( + 1000, + big.NewInt(-3100), + big.NewInt(0), + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ @@ -335,10 +340,11 @@ func TestGetDeltaOpenInterestFromUpdates(t *testing.T) { SettledSubaccount: types.Subaccount{ Id: bobSubaccountId, PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: 1000, - Quantums: dtypes.NewInt(1000), - }, + testutil.CreateSinglePerpetualPosition( + 1000, + big.NewInt(1000), + big.NewInt(0), + ), }, }, PerpetualUpdates: []types.PerpetualUpdate{ diff --git a/protocol/x/subaccounts/lib/updates_test.go b/protocol/x/subaccounts/lib/updates_test.go index db0e3072a8..3087a28dab 100644 --- a/protocol/x/subaccounts/lib/updates_test.go +++ b/protocol/x/subaccounts/lib/updates_test.go @@ -6,7 +6,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/lib/margin" - assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" pricetypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/lib" @@ -124,9 +124,9 @@ func TestGetRiskForSubaccount(t *testing.T) { subaccount: types.Subaccount{ Id: &subaccountId, PerpetualPositions: []*types.PerpetualPosition{ - createPerpPosition(1, big.NewInt(100), big.NewInt(0)), + testutil.CreateSinglePerpetualPosition(1, big.NewInt(100), big.NewInt(0)), }, - AssetPositions: createUsdcAmount(big.NewInt(100)), + AssetPositions: testutil.CreateUsdcAssetPositions(big.NewInt(100)), }, perpInfos: perptypes.PerpInfos{ 1: createPerpInfo(1, -6, 100, 0), @@ -142,10 +142,10 @@ func TestGetRiskForSubaccount(t *testing.T) { subaccount: types.Subaccount{ Id: &subaccountId, PerpetualPositions: []*types.PerpetualPosition{ - createPerpPosition(1, big.NewInt(100), big.NewInt(0)), - createPerpPosition(2, big.NewInt(-25), big.NewInt(0)), + testutil.CreateSinglePerpetualPosition(1, big.NewInt(100), big.NewInt(0)), + testutil.CreateSinglePerpetualPosition(2, big.NewInt(-25), big.NewInt(0)), }, - AssetPositions: createUsdcAmount(big.NewInt(110)), + AssetPositions: testutil.CreateUsdcAssetPositions(big.NewInt(110)), }, perpInfos: perptypes.PerpInfos{ 1: createPerpInfo(1, -6, 100, 0), @@ -176,9 +176,9 @@ func TestGetRiskForSubaccount_Panic(t *testing.T) { subaccount := types.Subaccount{ Id: &types.SubaccountId{Owner: "test", Number: 1}, PerpetualPositions: []*types.PerpetualPosition{ - createPerpPosition(1, big.NewInt(100), big.NewInt(0)), + testutil.CreateSinglePerpetualPosition(1, big.NewInt(100), big.NewInt(0)), }, - AssetPositions: createUsdcAmount(big.NewInt(100)), + AssetPositions: testutil.CreateUsdcAssetPositions(big.NewInt(100)), } emptyPerpInfos := perptypes.PerpInfos{} @@ -188,27 +188,6 @@ func TestGetRiskForSubaccount_Panic(t *testing.T) { }) } -func createPerpPosition( - id uint32, - quantums *big.Int, - fundingIndex *big.Int, -) *types.PerpetualPosition { - return &types.PerpetualPosition{ - PerpetualId: id, - Quantums: dtypes.NewIntFromBigInt(quantums), - FundingIndex: dtypes.NewIntFromBigInt(fundingIndex), - } -} - -func createUsdcAmount(amount *big.Int) []*types.AssetPosition { - return []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(amount), - }, - } -} - func createPerpInfo( id uint32, atomicResolution int32, diff --git a/protocol/x/subaccounts/types/genesis_test.go b/protocol/x/subaccounts/types/genesis_test.go index 5361b8ed4d..c356f955cc 100644 --- a/protocol/x/subaccounts/types/genesis_test.go +++ b/protocol/x/subaccounts/types/genesis_test.go @@ -1,12 +1,13 @@ package types_test import ( + "math/big" "testing" errorsmod "cosmossdk.io/errors" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/testutil/sample" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" "github.com/stretchr/testify/require" ) @@ -127,12 +128,8 @@ func TestGenesisState_Validate(t *testing.T) { Number: uint32(127), }, AssetPositions: []*types.AssetPosition{ // multiple asset positions. - { - AssetId: 0, - }, - { - AssetId: 1, - }, + testutil.CreateSingleAssetPosition(0, new(big.Int)), + testutil.CreateSingleAssetPosition(1, new(big.Int)), }, }, }, @@ -149,10 +146,10 @@ func TestGenesisState_Validate(t *testing.T) { Number: uint32(127), }, AssetPositions: []*types.AssetPosition{ - { - AssetId: 1, // asset id must be zero (0 = USDC). - Quantums: dtypes.NewInt(1_000), - }, + testutil.CreateSingleAssetPosition( + 1, // asset id must be zero (0 = USDC). + big.NewInt(1_000), + ), }, }, }, @@ -168,10 +165,10 @@ func TestGenesisState_Validate(t *testing.T) { Number: uint32(127), }, AssetPositions: []*types.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewInt(0), // quantum cannot be zero. - }, + testutil.CreateSingleAssetPosition( + 0, + big.NewInt(0), // quantum cannot be zero. + ), }, }, }, @@ -191,14 +188,16 @@ func TestGenesisState_Validate(t *testing.T) { Number: uint32(127), }, PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: 2, // out of order. - Quantums: dtypes.NewInt(1_000), - }, - { - PerpetualId: 1, - Quantums: dtypes.NewInt(1_000), - }, + testutil.CreateSinglePerpetualPosition( + 2, // out of order. + big.NewInt(1_000), + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(1_000), + big.NewInt(0), + ), }, }, }, @@ -214,10 +213,11 @@ func TestGenesisState_Validate(t *testing.T) { Number: uint32(127), }, PerpetualPositions: []*types.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.ZeroInt(), // quantum cannot be zero. - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(0), // quantum cannot be zero. + big.NewInt(0), + ), }, }, }, diff --git a/protocol/x/subaccounts/types/subaccount_test.go b/protocol/x/subaccounts/types/subaccount_test.go index 7de4addf7a..dca03cbf25 100644 --- a/protocol/x/subaccounts/types/subaccount_test.go +++ b/protocol/x/subaccounts/types/subaccount_test.go @@ -5,9 +5,9 @@ import ( "math/big" "testing" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" "github.com/dydxprotocol/v4-chain/protocol/testutil/sample" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" "github.com/stretchr/testify/require" @@ -125,14 +125,16 @@ func TestSubaccount_DeepCopy(t *testing.T) { func TestSubaccount_GetPerpetualPositionForId(t *testing.T) { expectedPerpetualPositions := []*types.PerpetualPosition{ - { - PerpetualId: 0, - Quantums: dtypes.NewInt(100), - }, - { - PerpetualId: 1, - Quantums: dtypes.NewInt(100), - }, + testutil.CreateSinglePerpetualPosition( + 0, + big.NewInt(100), + big.NewInt(0), + ), + testutil.CreateSinglePerpetualPosition( + 1, + big.NewInt(100), + big.NewInt(0), + ), } subaccount := types.Subaccount{ PerpetualPositions: expectedPerpetualPositions, @@ -165,10 +167,10 @@ func TestSubaccount_GetUsdcPosition(t *testing.T) { subaccount: &types.Subaccount{ Id: &constants.Carl_Num0, AssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(-599_000_000), // $599 - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(-599_000_000), // $599 + ), }, }, expectedQuoteBalance: big.NewInt(-599_000_000), @@ -229,30 +231,30 @@ func TestSubaccount_SetUsdcAssetPosition(t *testing.T) { subaccount: &constants.Carl_Num0_599USD, newQuoteBalance: big.NewInt(-10_000_000_000), expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(-10_000_000_000), // $10,000 - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(-10_000_000_000), // $10,000 + ), }, }, "can set max quote balance": { subaccount: &constants.Carl_Num0_599USD, newQuoteBalance: new(big.Int).SetUint64(math.MaxUint64), expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromUint64(math.MaxUint64), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(0).SetUint64(math.MaxUint64), + ), }, }, "can set min quote balance": { subaccount: &constants.Carl_Num0_599USD, newQuoteBalance: constants.BigNegMaxUint64(), expectedAssetPositions: []*types.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(constants.BigNegMaxUint64()), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + constants.BigNegMaxUint64(), + ), }, }, "can set zero quote balance and removes existing position from slice": { @@ -283,14 +285,13 @@ func TestSubaccount_SetUsdcAssetPosition(t *testing.T) { big.NewInt(1), ), expectedAssetPositions: []*types.AssetPosition{ - { - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - new(big.Int).SetUint64(math.MaxUint64), - big.NewInt(1), - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Add( + new(big.Int).SetUint64(math.MaxUint64), + big.NewInt(1), ), - }, + ), }, }, "returns error if abs new quote balance overflows uint64": { @@ -303,14 +304,13 @@ func TestSubaccount_SetUsdcAssetPosition(t *testing.T) { big.NewInt(-1), ), expectedAssetPositions: []*types.AssetPosition{ - { - Quantums: dtypes.NewIntFromBigInt( - new(big.Int).Add( - constants.BigNegMaxUint64(), - big.NewInt(-1), - ), + testutil.CreateSingleAssetPosition( + 0, + new(big.Int).Add( + constants.BigNegMaxUint64(), + big.NewInt(-1), ), - }, + ), }, }, } diff --git a/protocol/x/vault/keeper/grpc_query_vault_test.go b/protocol/x/vault/keeper/grpc_query_vault_test.go index be9a96cdac..7441552459 100644 --- a/protocol/x/vault/keeper/grpc_query_vault_test.go +++ b/protocol/x/vault/keeper/grpc_query_vault_test.go @@ -8,6 +8,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/dtypes" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" @@ -92,16 +93,17 @@ func TestVault(t *testing.T) { { Id: tc.vaultId.ToSubaccountId(), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(tc.asset), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + tc.asset, + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: tc.perpId, - Quantums: dtypes.NewIntFromBigInt(tc.inventory), - }, + testutil.CreateSinglePerpetualPosition( + tc.perpId, + tc.inventory, + big.NewInt(0), + ), }, }, } @@ -209,16 +211,17 @@ func TestAllVaults(t *testing.T) { subaccounts = append(subaccounts, satypes.Subaccount{ Id: vaultId.ToSubaccountId(), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(tc.assets[i]), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + tc.assets[i], + ), }, PerpetualPositions: []*satypes.PerpetualPosition{ - { - PerpetualId: tc.perpIds[i], - Quantums: dtypes.NewIntFromBigInt(tc.inventories[i]), - }, + testutil.CreateSinglePerpetualPosition( + tc.perpIds[i], + tc.inventories[i], + big.NewInt(0), + ), }, }) } diff --git a/protocol/x/vault/keeper/msg_server_deposit_to_vault_test.go b/protocol/x/vault/keeper/msg_server_deposit_to_vault_test.go index af5c72f70f..d36ec1c68d 100644 --- a/protocol/x/vault/keeper/msg_server_deposit_to_vault_test.go +++ b/protocol/x/vault/keeper/msg_server_deposit_to_vault_test.go @@ -12,6 +12,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/dtypes" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" "github.com/stretchr/testify/require" @@ -267,10 +268,10 @@ func TestMsgDepositToVault(t *testing.T) { subaccounts[i] = satypes.Subaccount{ Id: &(setup.depositor), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt(setup.depositorBalance), - }, + testutil.CreateSingleAssetPosition( + 0, + setup.depositorBalance, + ), }, } } diff --git a/protocol/x/vault/keeper/orders_test.go b/protocol/x/vault/keeper/orders_test.go index d8b8f01431..f070f54d7b 100644 --- a/protocol/x/vault/keeper/orders_test.go +++ b/protocol/x/vault/keeper/orders_test.go @@ -13,6 +13,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/indexer/msgsender" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" @@ -129,10 +130,10 @@ func TestRefreshAllVaultOrders(t *testing.T) { subaccounts[i] = satypes.Subaccount{ Id: vaultId.ToSubaccountId(), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(tc.assetQuantums[i]), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + tc.assetQuantums[i], + ), }, } } @@ -275,10 +276,10 @@ func TestRefreshVaultClobOrders(t *testing.T) { { Id: tc.vaultId.ToSubaccountId(), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewInt(1_000_000_000), // 1,000 USDC - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + big.NewInt(1_000_000_000), // 1,000 USDC + ), }, }, } @@ -649,10 +650,11 @@ func TestGetVaultClobOrders(t *testing.T) { if tc.vaultInventoryBaseQuantums != nil && tc.vaultInventoryBaseQuantums.Sign() != 0 { perpPositions = append( perpPositions, - &satypes.PerpetualPosition{ - PerpetualId: tc.perpetual.Params.Id, - Quantums: dtypes.NewIntFromBigInt(tc.vaultInventoryBaseQuantums), - }, + testutil.CreateSinglePerpetualPosition( + tc.perpetual.Params.Id, + tc.vaultInventoryBaseQuantums, + big.NewInt(0), + ), ) } genesisState.Subaccounts = []satypes.Subaccount{ diff --git a/protocol/x/vault/keeper/shares_test.go b/protocol/x/vault/keeper/shares_test.go index 33f077e316..a46ceea64f 100644 --- a/protocol/x/vault/keeper/shares_test.go +++ b/protocol/x/vault/keeper/shares_test.go @@ -5,9 +5,9 @@ import ( "testing" "github.com/cometbft/cometbft/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" "github.com/stretchr/testify/require" @@ -321,10 +321,10 @@ func TestMintShares(t *testing.T) { { Id: tc.vaultId.ToSubaccountId(), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: 0, - Quantums: dtypes.NewIntFromBigInt(tc.equity), - }, + testutil.CreateSingleAssetPosition( + 0, + tc.equity, + ), }, }, } diff --git a/protocol/x/vault/keeper/vault_test.go b/protocol/x/vault/keeper/vault_test.go index 319fc0f4a4..54fcd2d1eb 100644 --- a/protocol/x/vault/keeper/vault_test.go +++ b/protocol/x/vault/keeper/vault_test.go @@ -5,9 +5,9 @@ import ( "testing" "github.com/cometbft/cometbft/types" - "github.com/dydxprotocol/v4-chain/protocol/dtypes" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" @@ -99,10 +99,10 @@ func TestDecommissionNonPositiveEquityVaults(t *testing.T) { satypes.Subaccount{ Id: vaultId.ToSubaccountId(), AssetPositions: []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(tc.equities[i]), - }, + testutil.CreateSingleAssetPosition( + assettypes.AssetUsdc.Id, + tc.equities[i], + ), }, }, )