Skip to content

Commit

Permalink
Adding Events API Routes to Documentation (#299)
Browse files Browse the repository at this point in the history
* Add the new routes

* Add event routes to base

* Add the response file

* Add avs-event route file

* Add the global-event files

* Add the operator-event file

* Add the staker-event files

* Add the applyAllRefinements function

* Modify the event schemas

* Update the openapi file

* Modify response descriptions and examples

* Change id to getAvsRewardsEvents

* Add all to summary

* Add registration schemas and other fixes

* Add the registration routes

* Add WithTokenDataQuerySchema and WithEthValueQuerySchema

* Add Registration Event schemas and default dates

* Change first letter to lower case

* Add latest openapi.json

* Remove the hardcoded default date/time value
  • Loading branch information
surbhit14 authored Dec 17, 2024
1 parent ae8a2e1 commit 486b088
Show file tree
Hide file tree
Showing 22 changed files with 5,551 additions and 2,129 deletions.
106 changes: 55 additions & 51 deletions packages/api/src/schema/zod/schemas/eventSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
const yyyymmddRegex = /^\d{4}-\d{2}-\d{2}$/

// Reusable refinement functions
const refineWithEthValueRequiresTokenData = (schema: z.ZodTypeAny) =>
export const refineWithEthValueRequiresTokenData = (schema: z.ZodTypeAny) =>
schema.refine(
(data) => {
if (data.withEthValue && !data.withTokenData) {
Expand All @@ -24,7 +24,7 @@ const refineWithEthValueRequiresTokenData = (schema: z.ZodTypeAny) =>
}
)

const refineStartEndDates = (schema: z.ZodTypeAny) =>
export const refineStartEndDates = (schema: z.ZodTypeAny) =>
schema
.refine(
(data) => {
Expand Down Expand Up @@ -55,7 +55,7 @@ const refineStartEndDates = (schema: z.ZodTypeAny) =>
}
)

const refineDelegationTypeRestrictions = (schema: z.ZodTypeAny) =>
export const refineDelegationTypeRestrictions = (schema: z.ZodTypeAny) =>
schema.refine(
(data) => {
if (data.type === 'DELEGATION' || data.type === 'UNDELEGATION') {
Expand All @@ -72,7 +72,7 @@ const refineDelegationTypeRestrictions = (schema: z.ZodTypeAny) =>
}
)

const refineWithdrawalTypeRestrictions = (schema: z.ZodTypeAny) =>
export const refineWithdrawalTypeRestrictions = (schema: z.ZodTypeAny) =>
schema.refine(
(data) => {
if (data.type === 'WITHDRAWAL_COMPLETED') {
Expand All @@ -90,7 +90,7 @@ const refineWithdrawalTypeRestrictions = (schema: z.ZodTypeAny) =>
)

// Base schema for shared fields
const BaseEventQuerySchema = z.object({
export const BaseEventQuerySchema = z.object({
txHash: z
.string()
.regex(/^0x([A-Fa-f0-9]{64})$/, 'Invalid transaction hash')
Expand All @@ -107,7 +107,6 @@ const BaseEventQuerySchema = z.object({
message: 'Invalid date format for startAt. Use YYYY-MM-DD or ISO 8601 format.'
}
)
.default('')
.describe('Start date in ISO string format'),
endAt: z
.string()
Expand All @@ -120,11 +119,10 @@ const BaseEventQuerySchema = z.object({
message: 'Invalid date format for endAt. Use YYYY-MM-DD or ISO 8601 format.'
}
)
.default('')
.describe('End date in ISO string format')
})

const WithdrawalEventQuerySchemaBase = BaseEventQuerySchema.extend({
export const WithdrawalEventQuerySchemaBase = BaseEventQuerySchema.extend({
type: z
.enum(['WITHDRAWAL_QUEUED', 'WITHDRAWAL_COMPLETED'])
.optional()
Expand Down Expand Up @@ -152,7 +150,7 @@ export const WithdrawalEventQuerySchema = refineWithdrawalTypeRestrictions(
refineWithEthValueRequiresTokenData(refineStartEndDates(WithdrawalEventQuerySchemaBase))
)

const DepositEventQuerySchemaBase = BaseEventQuerySchema.extend({
export const DepositEventQuerySchemaBase = BaseEventQuerySchema.extend({
tokenAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid token address')
Expand All @@ -171,9 +169,9 @@ export const DepositEventQuerySchema = refineWithEthValueRequiresTokenData(
refineStartEndDates(DepositEventQuerySchemaBase)
)

const DelegationEventQuerySchemaBase = BaseEventQuerySchema.extend({
export const DelegationEventQuerySchemaBase = BaseEventQuerySchema.extend({
type: z
.enum(['SHARES_INCREASED', 'SHARES_DECREASED', 'DELEGATION', 'UNDELEGATION'])
.enum(['DELEGATION', 'UNDELEGATION', 'SHARES_INCREASED', 'SHARES_DECREASED'])
.optional()
.describe('The type of the delegation event'),
strategyAddress: z
Expand All @@ -182,42 +180,44 @@ const DelegationEventQuerySchemaBase = BaseEventQuerySchema.extend({
.optional()
.describe('The contract address of the restaking strategy')
})
.merge(WithTokenDataQuerySchema)
.merge(WithEthValueQuerySchema)

export const DelegationEventQuerySchema = refineDelegationTypeRestrictions(
refineWithEthValueRequiresTokenData(refineStartEndDates(DelegationEventQuerySchemaBase))
)

export const OperatorDelegationEventQuerySchema = refineDelegationTypeRestrictions(
refineWithEthValueRequiresTokenData(
refineStartEndDates(
DelegationEventQuerySchemaBase.extend({
stakerAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.optional()
.describe('The address of the staker')
})
DelegationEventQuerySchemaBase.merge(WithTokenDataQuerySchema).merge(WithEthValueQuerySchema)
)
)
)

export const OperatorDelegationEventQuerySchemaBase = DelegationEventQuerySchemaBase.extend({
stakerAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.optional()
.describe('The address of the staker')
})
.merge(WithTokenDataQuerySchema)
.merge(WithEthValueQuerySchema)

export const OperatorDelegationEventQuerySchema = refineDelegationTypeRestrictions(
refineWithEthValueRequiresTokenData(refineStartEndDates(OperatorDelegationEventQuerySchemaBase))
)

export const StakerDelegationEventQuerySchemaBase = DelegationEventQuerySchemaBase.extend({
operatorAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.optional()
.describe('The address of the operator')
})
.merge(WithTokenDataQuerySchema)
.merge(WithEthValueQuerySchema)

export const StakerDelegationEventQuerySchema = refineDelegationTypeRestrictions(
refineWithEthValueRequiresTokenData(
refineStartEndDates(
DelegationEventQuerySchemaBase.extend({
operatorAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.optional()
.describe('The address of the operator')
})
)
)
refineWithEthValueRequiresTokenData(refineStartEndDates(StakerDelegationEventQuerySchemaBase))
)

const RewardsEventQuerySchemaBase = BaseEventQuerySchema.extend({
export const RewardsEventQuerySchemaBase = BaseEventQuerySchema.extend({
rewardsSubmissionHash: z
.string()
.regex(/^0x([A-Fa-f0-9]{64})$/, 'Invalid reward submission hash')
Expand All @@ -234,28 +234,32 @@ const RewardsEventQuerySchemaBase = BaseEventQuerySchema.extend({

export const RewardsEventQuerySchema = refineStartEndDates(RewardsEventQuerySchemaBase)

const RegistrationEventQuerySchemaBase = BaseEventQuerySchema.extend({
export const RegistrationEventQuerySchemaBase = BaseEventQuerySchema.extend({
status: z.enum(['REGISTERED', 'DEREGISTERED']).optional().describe('The status of Registration')
})

export const RegistrationEventQuerySchema = refineStartEndDates(RegistrationEventQuerySchemaBase)

export const OperatorRegistrationEventQuerySchemaBase = RegistrationEventQuerySchemaBase.extend({
avsAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.optional()
.describe('The address of the avs')
})

export const OperatorRegistrationEventQuerySchema = refineStartEndDates(
RegistrationEventQuerySchemaBase.extend({
avsAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.optional()
.describe('The address of the avs')
})
OperatorRegistrationEventQuerySchemaBase
)

export const AvsRegistrationEventQuerySchemaBase = RegistrationEventQuerySchemaBase.extend({
operatorAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.optional()
.describe('The address of the operator')
})

export const AvsRegistrationEventQuerySchema = refineStartEndDates(
RegistrationEventQuerySchemaBase.extend({
operatorAddress: z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.optional()
.describe('The address of the operator')
})
AvsRegistrationEventQuerySchemaBase
)
Loading

0 comments on commit 486b088

Please sign in to comment.