Skip to content

Commit

Permalink
API-189: Add accountIds in Models in big.Int format
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovov committed Sep 21, 2023
1 parent 8d2fdfd commit 400e105
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 36 deletions.
9 changes: 2 additions & 7 deletions models/liquidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// - BlockTimestamp: Timestamp of the block where the order was committed.
type Liquidation struct {
MarketID uint64
AccountID uint64
AccountID *big.Int
AmountLiquidated *big.Int
CurrentPositionSize *big.Int
BlockNumber uint64
Expand All @@ -35,14 +35,9 @@ func GetLiquidationFromEvent(event *perpsMarketGoerli.PerpsMarketGoerliPositionL
marketID = event.MarketId.Uint64()
}

accountID := uint64(0)
if event.AccountId != nil {
accountID = event.AccountId.Uint64()
}

return &Liquidation{
MarketID: marketID,
AccountID: accountID,
AccountID: event.AccountId,
AmountLiquidated: event.AmountLiquidated,
CurrentPositionSize: event.CurrentPositionSize,
BlockNumber: event.Raw.BlockNumber,
Expand Down
4 changes: 2 additions & 2 deletions models/liquidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetLiquidationFromEvent(t *testing.T) {
AccountId: big.NewInt(1),
},
want: &Liquidation{
AccountID: uint64(1),
AccountID: big.NewInt(1),
},
},
{
Expand All @@ -54,7 +54,7 @@ func TestGetLiquidationFromEvent(t *testing.T) {
time: uint64(timeNow.Unix()),
want: &Liquidation{
MarketID: uint64(1),
AccountID: uint64(2),
AccountID: big.NewInt(2),
AmountLiquidated: big.NewInt(3),
CurrentPositionSize: big.NewInt(4),
BlockNumber: 5,
Expand Down
9 changes: 2 additions & 7 deletions models/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// - BlockTimestamp: Timestamp of the block where the order was committed.
type Order struct {
MarketID uint64
AccountID uint64
AccountID *big.Int
OrderType uint8
SizeDelta *big.Int
AcceptablePrice *big.Int
Expand All @@ -47,11 +47,6 @@ func GetOrderFromEvent(event *perpsMarketGoerli.PerpsMarketGoerliOrderCommitted,
marketID = event.MarketId.Uint64()
}

accountID := uint64(0)
if event.AccountId != nil {
accountID = event.AccountId.Uint64()
}

settlementTime := uint64(0)
if event.SettlementTime != nil {
settlementTime = event.SettlementTime.Uint64()
Expand All @@ -64,7 +59,7 @@ func GetOrderFromEvent(event *perpsMarketGoerli.PerpsMarketGoerliOrderCommitted,

return &Order{
MarketID: marketID,
AccountID: accountID,
AccountID: event.AccountId,
OrderType: event.OrderType,
SizeDelta: event.SizeDelta,
AcceptablePrice: event.AcceptablePrice,
Expand Down
4 changes: 2 additions & 2 deletions models/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGetOrderFromEvent(t *testing.T) {
AccountId: big.NewInt(1),
},
want: &Order{
AccountID: uint64(1),
AccountID: big.NewInt(1),
},
},
{
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestGetOrderFromEvent(t *testing.T) {
time: uint64(timeNow.Unix()),
want: &Order{
MarketID: uint64(1),
AccountID: uint64(2),
AccountID: big.NewInt(2),
OrderType: uint8(3),
SizeDelta: big.NewInt(5),
AcceptablePrice: big.NewInt(6),
Expand Down
9 changes: 2 additions & 7 deletions models/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// - TransactionHash - Hash of the transaction where the trade was settled.
type Trade struct {
MarketID uint64
AccountID uint64
AccountID *big.Int
FillPrice *big.Int
PnL *big.Int
AccruedFunding *big.Int
Expand Down Expand Up @@ -57,14 +57,9 @@ func GetTradeFromEvent(event *perpsMarketGoerli.PerpsMarketGoerliOrderSettled, t
marketID = event.MarketId.Uint64()
}

accountID := uint64(0)
if event.AccountId != nil {
accountID = event.AccountId.Uint64()
}

return &Trade{
MarketID: marketID,
AccountID: accountID,
AccountID: event.AccountId,
FillPrice: event.FillPrice,
PnL: event.Pnl,
AccruedFunding: event.AccruedFunding,
Expand Down
4 changes: 2 additions & 2 deletions models/trade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestGetTradeFromEvent(t *testing.T) {
AccountId: big.NewInt(1),
},
want: &Trade{
AccountID: uint64(1),
AccountID: big.NewInt(1),
TransactionHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
},
},
Expand All @@ -68,7 +68,7 @@ func TestGetTradeFromEvent(t *testing.T) {
time: uint64(timeNow.Unix()),
want: &Trade{
MarketID: 1,
AccountID: 2,
AccountID: big.NewInt(2),
FillPrice: big.NewInt(3),
AccruedFunding: big.NewInt(4),
SizeDelta: big.NewInt(5),
Expand Down
12 changes: 6 additions & 6 deletions perpsv3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestPerpsv3_RetrieveTrades(t *testing.T) {

trade := &models.Trade{
MarketID: 200,
AccountID: 1692895537802,
AccountID: big.NewInt(1692895537802),
FillPrice: fillPrice,
PnL: pnl,
AccruedFunding: accruedF,
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestPerpsv3_RetrieveTradesLimit(t *testing.T) {

trade := &models.Trade{
MarketID: 200,
AccountID: 1692895537802,
AccountID: big.NewInt(1692895537802),
FillPrice: fillPrice,
PnL: pnl,
AccruedFunding: accruedF,
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestPerpsv3_RetrieveOrders(t *testing.T) {

liquidation := &models.Order{
MarketID: 100,
AccountID: 8714,
AccountID: big.NewInt(8714),
OrderType: 0,
SizeDelta: sizeDelta,
AcceptablePrice: acceptablePrice,
Expand Down Expand Up @@ -413,7 +413,7 @@ func TestPerpsv3_RetrieveOrdersLimit(t *testing.T) {

liquidation := &models.Order{
MarketID: 100,
AccountID: 8714,
AccountID: big.NewInt(8714),
OrderType: 0,
SizeDelta: sizeDelta,
AcceptablePrice: acceptablePrice,
Expand Down Expand Up @@ -486,7 +486,7 @@ func TestPerpsv3_RetrieveLiquidations(t *testing.T) {

liquidation := &models.Liquidation{
MarketID: 100,
AccountID: 25,
AccountID: big.NewInt(25),
AmountLiquidated: big.NewInt(200000000000000000),
CurrentPositionSize: big.NewInt(0),
BlockNumber: 14125002,
Expand Down Expand Up @@ -557,7 +557,7 @@ func TestPerpsv3_RetrieveLiquidations(t *testing.T) {
func TestPerpsv3_RetrieveLiquidationsLimit(t *testing.T) {
liquidation := &models.Liquidation{
MarketID: 100,
AccountID: 25,
AccountID: big.NewInt(25),
AmountLiquidated: big.NewInt(200000000000000000),
CurrentPositionSize: big.NewInt(0),
BlockNumber: 14125002,
Expand Down
5 changes: 4 additions & 1 deletion services/luquidations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ func TestService_RetrieveLiquidations_OnChain(t *testing.T) {
spot, _ := spotMarketGoerli.NewSpotMarketGoerli(common.HexToAddress("0x5FF4b3aacdeC86782d8c757FAa638d8790799E83"), rpcClient)
perps, _ := perpsMarketGoerli.NewPerpsMarketGoerli(common.HexToAddress("0xf272382cB3BE898A8CdB1A23BE056fA2Fcf4513b"), rpcClient)

id := new(big.Int)
id.SetString("170141183460469231731687303715884105753", 10)

want := &models.Liquidation{
MarketID: 100,
AccountID: 25,
AccountID: id,
AmountLiquidated: big.NewInt(200000000000000000),
CurrentPositionSize: big.NewInt(0),
BlockNumber: 14125002,
Expand Down
2 changes: 1 addition & 1 deletion services/orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestService_RetrieveOrders_OnChain(t *testing.T) {

want := &models.Order{
MarketID: 100,
AccountID: 8714,
AccountID: big.NewInt(8714),
OrderType: 0,
SizeDelta: sizeDelta,
AcceptablePrice: acceptablePrice,
Expand Down
2 changes: 1 addition & 1 deletion services/trades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestService_RetrieveTrades_OnChain(t *testing.T) {

want := &models.Trade{
MarketID: 200,
AccountID: 1692895537802,
AccountID: big.NewInt(1692895537802),
FillPrice: fillPrice,
PnL: pnl,
AccruedFunding: accruedF,
Expand Down

0 comments on commit 400e105

Please sign in to comment.