Skip to content

Commit

Permalink
[TRA-219] emit transfer indexer event on vault deposit (backport #1343)…
Browse files Browse the repository at this point in the history
… (#1799)

Co-authored-by: Tian <[email protected]>
  • Loading branch information
mergify[bot] and tqin7 authored Jun 27, 2024
1 parent d8d0250 commit fa50377
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ func New(
app.ClobKeeper,
app.PerpetualsKeeper,
app.PricesKeeper,
app.SendingKeeper,
app.SubaccountsKeeper,
app.IndexerEventManager,
[]string{
Expand Down
1 change: 1 addition & 0 deletions protocol/testutil/keeper/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func createVaultKeeper(
&mocks.ClobKeeper{},
&mocks.PerpetualsKeeper{},
&mocks.PricesKeeper{},
&mocks.SendingKeeper{},
&mocks.SubaccountsKeeper{},
&mocks.IndexerEventManager{},
[]string{
Expand Down
3 changes: 3 additions & 0 deletions protocol/x/vault/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type (
clobKeeper types.ClobKeeper
perpetualsKeeper types.PerpetualsKeeper
pricesKeeper types.PricesKeeper
sendingKeeper types.SendingKeeper
subaccountsKeeper types.SubaccountsKeeper
indexerEventManager indexer_manager.IndexerEventManager
authorities map[string]struct{}
Expand All @@ -31,6 +32,7 @@ func NewKeeper(
clobKeeper types.ClobKeeper,
perpetualsKeeper types.PerpetualsKeeper,
pricesKeeper types.PricesKeeper,
sendingKeeper types.SendingKeeper,
subaccountsKeeper types.SubaccountsKeeper,
indexerEventManager indexer_manager.IndexerEventManager,
authorities []string,
Expand All @@ -41,6 +43,7 @@ func NewKeeper(
clobKeeper: clobKeeper,
perpetualsKeeper: perpetualsKeeper,
pricesKeeper: pricesKeeper,
sendingKeeper: sendingKeeper,
subaccountsKeeper: subaccountsKeeper,
indexerEventManager: indexerEventManager,
authorities: lib.UniqueSliceToSet(authorities),
Expand Down
13 changes: 8 additions & 5 deletions protocol/x/vault/keeper/msg_server_deposit_to_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/lib/log"
"github.com/dydxprotocol/v4-chain/protocol/lib/metrics"
assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types"
sendingtypes "github.com/dydxprotocol/v4-chain/protocol/x/sending/types"
"github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
)

Expand All @@ -32,12 +33,14 @@ func (k msgServer) DepositToVault(
// Transfer from sender subaccount to vault.
// Note: Transfer should take place after minting shares for
// shares calculation to be correct.
err = k.subaccountsKeeper.TransferFundsFromSubaccountToSubaccount(
err = k.sendingKeeper.ProcessTransfer(
ctx,
*msg.SubaccountId,
*msg.VaultId.ToSubaccountId(),
assettypes.AssetUsdc.Id,
quoteQuantums,
&sendingtypes.Transfer{
Sender: *msg.SubaccountId,
Recipient: *msg.VaultId.ToSubaccountId(),
AssetId: assettypes.AssetUsdc.Id,
Amount: msg.QuoteQuantums.BigInt().Uint64(),
},
)
if err != nil {
return nil, err
Expand Down
15 changes: 8 additions & 7 deletions protocol/x/vault/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types"
pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types"
sendingtypes "github.com/dydxprotocol/v4-chain/protocol/x/sending/types"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
)

Expand Down Expand Up @@ -49,6 +50,13 @@ type PricesKeeper interface {
) (pricestypes.MarketPrice, error)
}

type SendingKeeper interface {
ProcessTransfer(
ctx sdk.Context,
pendingTransfer *sendingtypes.Transfer,
) (err error)
}

type SubaccountsKeeper interface {
GetNetCollateralAndMarginRequirements(
ctx sdk.Context,
Expand All @@ -63,11 +71,4 @@ type SubaccountsKeeper interface {
ctx sdk.Context,
id satypes.SubaccountId,
) satypes.Subaccount
TransferFundsFromSubaccountToSubaccount(
ctx sdk.Context,
senderSubaccountId satypes.SubaccountId,
recipientSubaccountId satypes.SubaccountId,
assetId uint32,
quantums *big.Int,
) (err error)
}

0 comments on commit fa50377

Please sign in to comment.