-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add datasource for Safe Decoder Service #2313
Draft
iamacook
wants to merge
2
commits into
main
Choose a base branch
from
safe-decoder-datasource
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
iamacook
force-pushed
the
safe-decoder-datasource
branch
from
January 29, 2025 16:09
ef803f7
to
4b4cb62
Compare
iamacook
commented
Jan 29, 2025
Comment on lines
+6
to
+26
export const ProjectSchema = z.object({ | ||
description: z.string(), | ||
logo_file: z.string().url(), | ||
}); | ||
|
||
export const AbiSchema = z.object({ | ||
// We could use abitype here, but we don't consume the ABI/it would increase entity complexity | ||
abi_json: z.array(z.record(z.unknown())), | ||
abi_hash: HexSchema, | ||
modified: z.coerce.date(), | ||
}); | ||
|
||
export const ContractSchema = z.object({ | ||
address: AddressSchema, | ||
name: z.string(), | ||
display_name: z.string().nullable(), | ||
chain_id: z.number().transform(String), | ||
project: ProjectSchema.nullable(), | ||
abi: AbiSchema, | ||
modified: z.coerce.date(), | ||
}); |
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.
@Uxio0 has confirmed that this (and decoded data) will be changed to camel case, hence leaving this as a draft.
iamacook
commented
Jan 29, 2025
Comment on lines
+11
to
+53
export const MultisendSchema = z.object({ | ||
operation: z.nativeEnum(Operation), | ||
value: NumericStringSchema, | ||
data_decoded: z.lazy(() => BaseDataDecodedSchema.nullable()), | ||
to: AddressSchema, | ||
data: HexSchema.nullable(), | ||
}); | ||
|
||
export const ValueDecodedSchema = z.union([ | ||
z.array(z.lazy(() => MultisendSchema)), | ||
z.lazy(() => BaseDataDecodedSchema), | ||
]); | ||
|
||
export const ParameterSchema = z.object({ | ||
name: z.string(), | ||
type: z.string(), | ||
value: HexSchema, | ||
value_decoded: ValueDecodedSchema.nullable(), | ||
}); | ||
|
||
export const BaseDataDecodedSchemaShape = { | ||
method: z.string(), | ||
parameters: z.array(z.lazy(() => ParameterSchema)), | ||
}; | ||
|
||
// We need explicitly define ZodType due to recursion | ||
export const BaseDataDecodedSchema: z.ZodType<{ | ||
method: string; | ||
parameters: Array<z.infer<typeof ParameterSchema>>; | ||
}> = z.lazy(() => z.object(BaseDataDecodedSchemaShape)); | ||
|
||
export const Accuracy = [ | ||
'FULL_MATCH', // Matched contract and chain ID | ||
'PARTIAL_MATCH', // Matched contract | ||
'ONLY_FUNCTION_MATCH', // Matched function from another contract | ||
'NO_MATCH', // Selector cannot be decoded | ||
] as const; | ||
|
||
export const DataDecodedSchema = z.lazy(() => | ||
z.object(BaseDataDecodedSchemaShape).extend({ | ||
accuracy: z.enum([...Accuracy, 'UNKNOWN']).catch('UNKNOWN'), | ||
}), | ||
); |
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.
As before re. snake- to camelcase.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The new Safe Decoder Service improves upon the decoder of the Safe Transaction Service. As such, we intend to migrate to it.
This lays the foundation of usage, by creating a datasource (with manager) and base repository for validating the responses.
Changes
safeDataDecoder.baseUri
(test) configurationDataDecoderApiManager
interface, implementation and moduleDataDecoderApi
interface, implementation and moduleDataDecoded
and `Contract, with inferred types and buildersDataDecoderRepository
for accessing/validating datasource responses