Skip to content

Commit

Permalink
[OTE-777][OTE-690][OTE-688] Update clob code to add revshare logic (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 committed Sep 16, 2024
1 parent b7879b1 commit 16b65ab
Show file tree
Hide file tree
Showing 39 changed files with 1,144 additions and 403 deletions.
1 change: 1 addition & 0 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ func New(
clobFlags,
rate_limit.NewPanicRateLimiter[sdk.Msg](),
daemonLiquidationInfo,
app.RevShareKeeper,
)
clobModule := clobmodule.NewAppModule(
appCodec,
Expand Down
7 changes: 7 additions & 0 deletions protocol/indexer/events/order_fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package events

import (
"fmt"
"math/big"

v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
Expand All @@ -19,6 +20,7 @@ func NewOrderFillEvent(
takerFee int64,
totalFilledMaker satypes.BaseQuantums,
totalFilledTaker satypes.BaseQuantums,
affiliateRevShareQuoteQuantums *big.Int,
) *OrderFillEventV1 {
indexerTakerOrder := v1.OrderToIndexerOrder(takerOrder)
return &OrderFillEventV1{
Expand All @@ -31,6 +33,8 @@ func NewOrderFillEvent(
TakerFee: takerFee,
TotalFilledMaker: totalFilledMaker.ToUint64(),
TotalFilledTaker: totalFilledTaker.ToUint64(),
// Since revshare is always less than taker fee, this will not overflow.
AffiliateRevShare: affiliateRevShareQuoteQuantums.Uint64(),
}
}

Expand All @@ -44,6 +48,7 @@ func NewLiquidationOrderFillEvent(
makerFee int64,
takerFee int64,
totalFilledMaker satypes.BaseQuantums,
affiliateRevShareQuoteQuantums *big.Int,
) *OrderFillEventV1 {
if !liquidationTakerOrder.IsLiquidation() {
panic(fmt.Sprintf("liquidationTakerOrder is not a liquidation order: %v", liquidationTakerOrder))
Expand All @@ -64,5 +69,7 @@ func NewLiquidationOrderFillEvent(
TakerFee: takerFee,
TotalFilledMaker: totalFilledMaker.ToUint64(),
TotalFilledTaker: fillAmount.ToUint64(),
// Since revshare is always less than taker fee, this will not overflow.
AffiliateRevShare: affiliateRevShareQuoteQuantums.Uint64(),
}
}
26 changes: 16 additions & 10 deletions protocol/indexer/events/order_fill_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package events_test

import (
"math/big"
"testing"

"github.com/dydxprotocol/v4-chain/protocol/indexer/events"
Expand All @@ -20,6 +21,7 @@ var (
fillAmount = satypes.BaseQuantums(5)
makerFee = int64(-2)
takerFee = int64(5)
affiliateRevShare = big.NewInt(0)
)

func TestNewOrderFillEvent_Success(t *testing.T) {
Expand All @@ -31,18 +33,20 @@ func TestNewOrderFillEvent_Success(t *testing.T) {
takerFee,
fillAmount,
fillAmount,
affiliateRevShare,
)

expectedOrderFillEventProto := &events.OrderFillEventV1{
MakerOrder: indexerMakerOrder,
TakerOrder: &events.OrderFillEventV1_Order{
Order: &indexerTakerOrder,
},
FillAmount: fillAmount.ToUint64(),
MakerFee: makerFee,
TakerFee: takerFee,
TotalFilledMaker: fillAmount.ToUint64(),
TotalFilledTaker: fillAmount.ToUint64(),
FillAmount: fillAmount.ToUint64(),
MakerFee: makerFee,
TakerFee: takerFee,
TotalFilledMaker: fillAmount.ToUint64(),
TotalFilledTaker: fillAmount.ToUint64(),
AffiliateRevShare: affiliateRevShare.Uint64(),
}
require.Equal(t, expectedOrderFillEventProto, orderFillEvent)
}
Expand All @@ -56,6 +60,7 @@ func TestNewLiquidationOrderFillEvent_Success(t *testing.T) {
makerFee,
takerFee,
fillAmount,
affiliateRevShare,
)

expectedLiquidationOrder := events.LiquidationOrderV1{
Expand All @@ -71,11 +76,12 @@ func TestNewLiquidationOrderFillEvent_Success(t *testing.T) {
TakerOrder: &events.OrderFillEventV1_LiquidationOrder{
LiquidationOrder: &expectedLiquidationOrder,
},
FillAmount: fillAmount.ToUint64(),
MakerFee: makerFee,
TakerFee: takerFee,
TotalFilledMaker: fillAmount.ToUint64(),
TotalFilledTaker: fillAmount.ToUint64(),
FillAmount: fillAmount.ToUint64(),
MakerFee: makerFee,
TakerFee: takerFee,
TotalFilledMaker: fillAmount.ToUint64(),
TotalFilledTaker: fillAmount.ToUint64(),
AffiliateRevShare: affiliateRevShare.Uint64(),
}
require.Equal(t, expectedOrderFillEventProto, liquidationOrderFillEvent)
}
21 changes: 15 additions & 6 deletions protocol/mocks/ClobKeeper.go

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

21 changes: 15 additions & 6 deletions protocol/mocks/MemClobKeeper.go

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

55 changes: 49 additions & 6 deletions protocol/mocks/mocks/CacheMultiStore.go

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

Loading

0 comments on commit 16b65ab

Please sign in to comment.