-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add framework for validating order using custom handler logics (#56)
- Loading branch information
Showing
5 changed files
with
117 additions
and
34 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
SmartOrderValidationResult, | ||
SmartOrderValidator, | ||
ValidateOrderParams, | ||
} from "../model"; | ||
|
||
import { | ||
handlerAddress as handlerTwap, | ||
validateOrder as validateOrderTwap, | ||
} from "./twap"; | ||
|
||
const validatorsForHandler: Record<string, SmartOrderValidator> = { | ||
[handlerTwap.toLowerCase()]: validateOrderTwap, | ||
}; | ||
|
||
/** | ||
* Validate a smart order using the custom handler logic (if known) | ||
* | ||
* @returns The result of the validation if the handler is known, undefined otherwise | ||
*/ | ||
export async function validateOrder( | ||
params: ValidateOrderParams | ||
): Promise<SmartOrderValidationResult<void> | undefined> { | ||
const { handler } = params; | ||
const validateFn = validatorsForHandler[handler.toLowerCase()]; | ||
return validateFn ? validateFn(params) : undefined; | ||
} |
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,14 @@ | ||
import { TWAP_ADDRESS } from "@cowprotocol/cow-sdk"; | ||
|
||
import { SmartOrderValidator, ValidationResult } from "../model"; | ||
|
||
export const handlerAddress = TWAP_ADDRESS; | ||
|
||
export const validateOrder: SmartOrderValidator = async (_params) => { | ||
// TODO: Implement validation logic, ideally delegate to the SDK | ||
|
||
return { | ||
result: ValidationResult.Success, | ||
data: undefined, | ||
}; | ||
}; |
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