Skip to content
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

feat(api-kit): 4337 API functions #777

Merged
merged 25 commits into from May 21, 2024
Merged

Conversation

tmjssz
Copy link
Contributor

@tmjssz tmjssz commented Apr 19, 2024

What it solves

Resolves #775

Adding support for the following 4337 API endpoints:

  • GET /v1/safe-operations/{safe_operation_hash}/
  • GET /v1/safes/{address}/safe-operations/
  • POST /v1/safes/{address}/safe-operations/

@coveralls
Copy link

coveralls commented Apr 19, 2024

Pull Request Test Coverage Report for Build 9082904763

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 22 of 32 (68.75%) changed or added relevant lines in 4 files are covered.
  • 48 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-1.1%) to 77.75%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/api-kit/src/SafeApiKit.ts 18 28 64.29%
Files with Coverage Reduction New Missed Lines %
packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts 8 90.22%
packages/api-kit/src/SafeApiKit.ts 40 62.75%
Totals Coverage Status
Change from base Build 8739921359: -1.1%
Covered Lines: 731
Relevant Lines: 875

💛 - Coveralls

@tmjssz tmjssz linked an issue Apr 19, 2024 that may be closed by this pull request
* @throws "Invalid Ethereum address {safeAddress}"
* @returns The SafeOperations sent from the given Safe's address
*/
async getSafeOperationsByAddress(safeAddress: string): Promise<GetSafeOperationListResponse> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to be ignoring the paging parameters (offset, limit etc) while the response does have the full result (count, next). Is this deliberate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not on purpose 😅 added the missing params now

@@ -0,0 +1,3 @@
import { EMPTY_DATA } from './constants'

export const isEmptyHexData = (input: string) => !input || input === EMPTY_DATA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the !input outside of the function or rename it since empty hex implies a hex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the function

packages/api-kit/tests/endpoint/index.test.ts Outdated Show resolved Hide resolved
callGasLimit?: bigint
}

export interface SafeOperation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to avoid name colision even if this is scoped. People often use ctrl+shift+f to look for definitions.

async addSafeOperation({
moduleAddress: moduleAddressProp,
safeAddress: safeAddressProp,
safeOperation,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... I dont understand the use case for this particular function but here is some food for thought. Right now, there is no internal coupling between this and the Safe4337 module which is better then if we were importing the type from there. There is, however, an implicit one. For someone to use this endpoint, they would have to either: use Safe4337Pack#createTransaction or implementing an interface themselves that accomplishes the same thing (which is a bit awkward). Are there situation where all these things could be supplied by an external library or people should ALWAYS use both modules together? Should we really use such complex object just for an api proxy and should the api-kit itself sign in this case? Perhaps the interface here is just really an UserOperation (which is clearly defined by the ERC) and the fields associated with packing signature (validUntil, validAfter and the authorizer's signature). That data field also almost look like something to represent the internal state of the object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the function in 56315ef to not expect a SafeOperation anymore, but a UserOperation object.

}

const signerAddress = await signer.getAddress()
const signature = safeOperation.getSignature(signerAddress)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at the server-side code and this field seems to be validated like this:

safe_owners = self._get_owners(safe_address)
parsed_signatures = SafeSignature.parse_signature(
    signature, safe_operation_hash, safe_operation_hash_preimage
)
owners_processed = set()
safe_signatures = []
for safe_signature in parsed_signatures:
    # do stuff

Please just check if those are not every owner's concatenated signature. I think the SafeOperation#encodedSignatures() or something.

packages/api-kit/tests/endpoint/index.test.ts Outdated Show resolved Hide resolved
packages/safe-core-sdk-types/src/types.ts Show resolved Hide resolved
…ng with Safe4337 module

The function expects a `UserOperation` object now, instead of a `SafeOperation` object.
tmjssz and others added 2 commits May 14, 2024 18:31
Remove unused PIMLICO_API_KEY

Co-authored-by: Daniel <25051234+dasanra@users.noreply.github.com>
@tmjssz tmjssz force-pushed the feat/4337-api-integration branch from 691cca2 to cd124d8 Compare May 15, 2024 12:28
…e-sdk into feat/4337-api-integration

# Conflicts:
#	packages/api-kit/tests/endpoint/index.test.ts
#	packages/relay-kit/src/packs/safe-4337/types.ts
@dasanra dasanra merged commit 71f978e into development May 21, 2024
20 checks passed
@dasanra dasanra deleted the feat/4337-api-integration branch May 21, 2024 15:58
@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[4337] API Compatibility
5 participants