diff --git a/protocol/x/subaccounts/keeper/subaccount.go b/protocol/x/subaccounts/keeper/subaccount.go index a6fff13edd..9a43ac8cbe 100644 --- a/protocol/x/subaccounts/keeper/subaccount.go +++ b/protocol/x/subaccounts/keeper/subaccount.go @@ -277,7 +277,10 @@ func (k Keeper) UpdateSubaccounts( // Emit an event indicating a funding payment was paid / received for each settled funding // payment. Note that `fundingPaid` is positive if the subaccount paid funding, // and negative if the subaccount received funding. - for perpetualId, fundingPaid := range fundingPayments { + // Note the perpetual IDs are sorted first to ensure event emission determinism. + sortedPerpIds := lib.GetSortedKeys[lib.Sortable[uint32]](fundingPayments) + for _, perpetualId := range sortedPerpIds { + fundingPaid := fundingPayments[perpetualId] ctx.EventManager().EmitEvent( types.NewCreateSettledFundingEvent( *u.SettledSubaccount.Id,