-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IND-461] handle deleveraging events #730
Merged
Merged
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bbf3d92
proto
dydxwill 607ec57
add deleveraging events
dydxwill de57036
ender skeleton
dydxwill fc3899b
fix mock
dydxwill 8229d67
update
dydxwill 00146ea
proto updates
dydxwill c07f821
lint
dydxwill 46fc914
add deleveraging handler logic
dydxwill 5822965
add on-message unit test
dydxwill f2d0dce
add swagger docs
dydxwill 3275946
update parallelization ids
dydxwill 6fdc2d5
add/fix unit tests
dydxwill ead2682
merge
dydxwill ce2a201
fix
dydxwill 61ccf35
fixes aside from price
dydxwill ca1b6b5
merge
dydxwill cdf90b7
sql
dydxwill c812739
fixes
dydxwill 5148966
fix
dydxwill a8a0596
fixes
dydxwill 2853eca
Merge branch 'main' of https://github.com/dydxprotocol/v4-chain into …
dydxwill 7a79cbb
lint
dydxwill 87279e7
fix
dydxwill 6d856b4
Merge branch 'main' of https://github.com/dydxprotocol/v4-chain into …
dydxwill 25ba7be
address cmts
dydxwill f828f6b
address cmts
dydxwill 82f7a60
address cmt
dydxwill 8467fdb
fix
dydxwill a2a6d12
wip
dydxwill 863c2ee
address cmts
dydxwill 28c981e
fix imports
dydxwill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { logger, ParseMessageError } from '@dydxprotocol-indexer/base'; | ||
import { DeleveragingEventV1, IndexerTendermintBlock, IndexerTendermintEvent } from '@dydxprotocol-indexer/v4-protos'; | ||
import { DydxIndexerSubtypes } from '../../src/lib/types'; | ||
import { DeleveragingValidator } from '../../src/validators/deleveraging-validator'; | ||
import { | ||
defaultDeleveragingEvent, defaultHeight, defaultTime, defaultTxHash, | ||
} from '../helpers/constants'; | ||
import { createIndexerTendermintBlock, createIndexerTendermintEvent } from '../helpers/indexer-proto-helpers'; | ||
import { expectDidntLogError, expectLoggedParseMessageError } from '../helpers/validator-helpers'; | ||
|
||
describe('deleveraging-validator', () => { | ||
beforeEach(() => { | ||
jest.spyOn(logger, 'error'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('validate', () => { | ||
it('does not throw error on valid deleveraging', () => { | ||
const validator: DeleveragingValidator = new DeleveragingValidator( | ||
defaultDeleveragingEvent, | ||
createBlock(defaultDeleveragingEvent), | ||
); | ||
|
||
validator.validate(); | ||
expectDidntLogError(); | ||
}); | ||
|
||
it.each([ | ||
[ | ||
'does not contain liquidated', | ||
{ | ||
...defaultDeleveragingEvent, | ||
liquidated: undefined, | ||
}, | ||
'DeleveragingEvent must have a liquidated subaccount id', | ||
], | ||
[ | ||
'does not contain offsetting', | ||
{ | ||
...defaultDeleveragingEvent, | ||
offsetting: undefined, | ||
}, | ||
'DeleveragingEvent must have an offsetting subaccount id', | ||
], | ||
])('throws error if event %s', (_message: string, event: DeleveragingEventV1, message: string) => { | ||
const validator: DeleveragingValidator = new DeleveragingValidator( | ||
event, | ||
createBlock(event), | ||
); | ||
|
||
expect(() => validator.validate()).toThrow(new ParseMessageError(message)); | ||
expectLoggedParseMessageError( | ||
DeleveragingValidator.name, | ||
message, | ||
{ event }, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
function createBlock( | ||
deleveragingEvent: DeleveragingEventV1, | ||
): IndexerTendermintBlock { | ||
const event: IndexerTendermintEvent = createIndexerTendermintEvent( | ||
DydxIndexerSubtypes.DELEVERAGING, | ||
DeleveragingEventV1.encode(deleveragingEvent).finish(), | ||
0, | ||
0, | ||
); | ||
|
||
return createIndexerTendermintBlock( | ||
defaultHeight, | ||
defaultTime, | ||
[event], | ||
[defaultTxHash], | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
indexer/services/ender/src/handlers/deleveraging-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DeleveragingEventV1 } from '@dydxprotocol-indexer/v4-protos'; | ||
|
||
import { ConsolidatedKafkaEvent } from '../lib/types'; | ||
import { Handler } from './handler'; | ||
|
||
export class DeleveragingHandler extends Handler<DeleveragingEventV1> { | ||
eventType: string = 'DeleveragingEvent'; | ||
|
||
public getParallelizationIds(): string[] { | ||
return []; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
public async internalHandle(): Promise<ConsolidatedKafkaEvent[]> { | ||
// Implement this | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
indexer/services/ender/src/validators/deleveraging-validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { IndexerTendermintEvent, DeleveragingEventV1 } from '@dydxprotocol-indexer/v4-protos'; | ||
|
||
import { DeleveragingHandler } from '../handlers/deleveraging-handler'; | ||
import { Handler } from '../handlers/handler'; | ||
import { Validator } from './validator'; | ||
|
||
export class DeleveragingValidator extends Validator<DeleveragingEventV1> { | ||
public validate(): void { | ||
if (this.event.liquidated === undefined) { | ||
return this.logAndThrowParseMessageError( | ||
'DeleveragingEvent must have a liquidated subaccount id', | ||
{ event: this.event }, | ||
); | ||
} | ||
|
||
if (this.event.offsetting === undefined) { | ||
return this.logAndThrowParseMessageError( | ||
'DeleveragingEvent must have an offsetting subaccount id', | ||
{ event: this.event }, | ||
); | ||
} | ||
|
||
} | ||
|
||
public createHandlers( | ||
indexerTendermintEvent: IndexerTendermintEvent, | ||
txId: number, | ||
): Handler<DeleveragingEventV1>[] { | ||
return [ | ||
new DeleveragingHandler( | ||
this.block, | ||
indexerTendermintEvent, | ||
txId, | ||
this.event, | ||
), | ||
]; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
eventType
property is hardcoded as 'DeleveragingEvent'. This is fine if the class is only intended to handle this specific event type. However, if the class is expected to handle multiple event types, consider makingeventType
a parameter in the constructor.