-
Notifications
You must be signed in to change notification settings - Fork 9
feat: request-withdraw, complete-withdraw #464
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
04659e2
feat: request-withdraw, complete-withdraw
awisniew207 89eb532
chore: version plan
awisniew207 ca1270d
fix: perfectionist imports
awisniew207 319c10a
fix(registry-backend): rebase onto main post-api changes
awisniew207 20c0f62
fix(registry-backend): perfectionist imports
awisniew207 339add2
chore(registry-backend): use zerodev sdk polling methods
awisniew207 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 hidden or 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,22 @@ | ||
| --- | ||
| registry-sdk: minor | ||
| registry-backend: minor | ||
| --- | ||
|
|
||
| Add withdrawal endpoints for users to withdraw tokens from their agent smart accounts | ||
|
|
||
| **registry-backend:** | ||
|
|
||
| - Add `POST /user/:appId/request-withdraw` endpoint to prepare unsigned UserOperations for withdrawing tokens | ||
| - Add `POST /user/:appId/complete-withdraw` endpoint to submit signed UserOperations and execute withdrawals | ||
| - Add `SPONSOR_WITHDRAW_GAS` env var to optionally sponsor gas fees via ZeroDev paymaster | ||
| - Add Alchemy utility for fetching token balances with metadata | ||
| - Refactor chainConfig into utils with network-specific bundler URL support | ||
| - Add integration tests for withdrawal flow | ||
|
|
||
| **registry-sdk:** | ||
|
|
||
| - Add `POST /user/:appId/request-withdraw` endpoint schema | ||
| - Add `POST /user/:appId/complete-withdraw` endpoint schema | ||
| - Add withdraw types: `Asset`, `RequestWithdrawRequest`, `RequestWithdrawResponse`, `SignedWithdrawal`, `CompleteWithdrawRequest`, `CompleteWithdrawResponse` | ||
| - Regenerate RTK clients |
This file contains hidden or 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 hidden or 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,226 @@ | ||
| --- | ||
| title: 'Complete Withdraw' | ||
| api: 'POST /user/{appId}/complete-withdraw' | ||
| --- | ||
|
|
||
| Complete the withdrawal by submitting signed UserOperations to the blockchain. This endpoint broadcasts the signed transactions to the ZeroDev bundler and waits for confirmation. | ||
|
|
||
| <Note> | ||
| The transaction will be rejected if the Agent account does not have enough native tokens to pay for gas fees. | ||
| </Note> | ||
|
|
||
| ## Request | ||
|
|
||
| <ParamField path="appId" type="integer" required> | ||
| The unique identifier of the app | ||
| </ParamField> | ||
|
|
||
| <ParamField body="withdrawals" type="array" required> | ||
| List of signed withdrawals to execute | ||
|
|
||
| <Expandable title="Signed withdrawal object properties"> | ||
| <ParamField body="network" type="string" required> | ||
| Network identifier (must match the network from request-withdraw response) | ||
| </ParamField> | ||
| <ParamField body="userOp" type="object" required> | ||
| The UserOperation object returned from request-withdraw (unchanged) | ||
| </ParamField> | ||
| <ParamField body="signature" type="string" required> | ||
| The user's signature over the UserOperation hash | ||
| </ParamField> | ||
| </Expandable> | ||
| </ParamField> | ||
|
|
||
| ## Response | ||
|
|
||
| <ResponseField name="transactions" type="array"> | ||
| List of completed transactions | ||
|
|
||
| <Expandable title="Transaction object properties"> | ||
| <ResponseField name="network" type="string"> | ||
| Network where the transaction was executed | ||
| </ResponseField> | ||
| <ResponseField name="transactionHash" type="string"> | ||
| The on-chain transaction hash | ||
| </ResponseField> | ||
| <ResponseField name="userOpHash" type="string"> | ||
| The ERC-4337 UserOperation hash | ||
| </ResponseField> | ||
| </Expandable> | ||
| </ResponseField> | ||
|
|
||
| <ResponseField name="errors" type="array"> | ||
| List of errors for networks that failed to complete (only present if some networks failed) | ||
|
|
||
| <Expandable title="Error object properties"> | ||
| <ResponseField name="network" type="string"> | ||
| Network identifier where the error occurred | ||
| </ResponseField> | ||
| <ResponseField name="error" type="string"> | ||
| Error message describing what went wrong | ||
| </ResponseField> | ||
| </Expandable> | ||
| </ResponseField> | ||
|
|
||
| <RequestExample> | ||
| ```bash cURL | ||
| curl -X POST https://api.heyvincent.ai/user/123/complete-withdraw \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "withdrawals": [ | ||
| { | ||
| "network": "base-mainnet", | ||
| "userOp": { | ||
| "sender": "0xAgentSmartAccountAddress...", | ||
| "nonce": "0x1", | ||
| "callData": "0xa9059cbb...", | ||
| "callGasLimit": "0x5208", | ||
| "verificationGasLimit": "0x10000", | ||
| "preVerificationGas": "0x5208", | ||
| "maxFeePerGas": "0x3b9aca00", | ||
| "maxPriorityFeePerGas": "0x3b9aca00", | ||
| "paymaster": "0xPaymasterAddress...", | ||
| "paymasterData": "0x..." | ||
| }, | ||
| "signature": "0xUserSignature..." | ||
| } | ||
| ] | ||
| }' | ||
| ``` | ||
|
|
||
| ```typescript viem | ||
| import { createWalletClient, custom } from 'viem'; | ||
|
|
||
| // Step 1: Request withdrawal (from request-withdraw endpoint) | ||
| const requestResponse = await fetch(`https://api.heyvincent.ai/user/${appId}/request-withdraw`, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ | ||
| userControllerAddress: walletClient.account.address, | ||
| assets: [ | ||
| { | ||
| network: 'base-mainnet', | ||
| tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base | ||
| amount: 100 | ||
| } | ||
| ] | ||
| }) | ||
| }); | ||
|
|
||
| const { withdrawals } = await requestResponse.json(); | ||
|
|
||
| // Step 2: Sign each UserOperation | ||
| const signedWithdrawals = await Promise.all( | ||
| withdrawals.map(async (withdrawal) => { | ||
| const signature = await walletClient.signMessage({ | ||
| message: { raw: withdrawal.userOpHash as `0x${string}` } | ||
| }); | ||
| return { | ||
| network: withdrawal.network, | ||
| userOp: withdrawal.userOp, | ||
| signature | ||
| }; | ||
| }) | ||
| ); | ||
|
|
||
| // Step 3: Complete withdrawal | ||
| const completeResponse = await fetch(`https://api.heyvincent.ai/user/${appId}/complete-withdraw`, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ withdrawals: signedWithdrawals }) | ||
| }); | ||
|
|
||
| const { transactions } = await completeResponse.json(); | ||
|
|
||
| transactions.forEach(tx => { | ||
| console.log(`Withdrawal on ${tx.network}: ${tx.transactionHash}`); | ||
| }); | ||
| ``` | ||
|
|
||
| ```typescript ethers.js (v6) | ||
| import { getBytes } from 'ethers'; | ||
|
|
||
| // Step 1: Request withdrawal (from request-withdraw endpoint) | ||
| const requestResponse = await fetch(`https://api.heyvincent.ai/user/${appId}/request-withdraw`, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ | ||
| userControllerAddress: await signer.getAddress(), | ||
| assets: [ | ||
| { | ||
| network: 'base-mainnet', | ||
| tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base | ||
| amount: 100 | ||
| } | ||
| ] | ||
| }) | ||
| }); | ||
|
|
||
| const { withdrawals } = await requestResponse.json(); | ||
|
|
||
| // Step 2: Sign each UserOperation | ||
| const signedWithdrawals = await Promise.all( | ||
| withdrawals.map(async (withdrawal) => { | ||
| const signature = await signer.signMessage( | ||
| getBytes(withdrawal.userOpHash) | ||
| ); | ||
| return { | ||
| network: withdrawal.network, | ||
| userOp: withdrawal.userOp, | ||
| signature | ||
| }; | ||
| }) | ||
| ); | ||
|
|
||
| // Step 3: Complete withdrawal | ||
| const completeResponse = await fetch(`https://api.heyvincent.ai/user/${appId}/complete-withdraw`, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ withdrawals: signedWithdrawals }) | ||
| }); | ||
|
|
||
| const { transactions } = await completeResponse.json(); | ||
|
|
||
| transactions.forEach(tx => { | ||
| console.log(`Withdrawal on ${tx.network}: ${tx.transactionHash}`); | ||
| }); | ||
| ``` | ||
| </RequestExample> | ||
|
|
||
| <ResponseExample> | ||
| ```json Response | ||
| { | ||
| "transactions": [ | ||
| { | ||
| "network": "base-mainnet", | ||
| "transactionHash": "0xabc123...", | ||
| "userOpHash": "0xdef456..." | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ```json Partial Failure | ||
| { | ||
| "transactions": [ | ||
| { | ||
| "network": "base-mainnet", | ||
| "transactionHash": "0xabc123...", | ||
| "userOpHash": "0xdef456..." | ||
| } | ||
| ], | ||
| "errors": [ | ||
| { | ||
| "network": "ethereum", | ||
| "error": "UserOp 0x123... not confirmed after 15 seconds" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ```json All Failed | ||
| { | ||
| "error": "All withdrawals failed: base-mainnet: UserOp not confirmed after 15 seconds" | ||
| } | ||
| ``` | ||
| </ResponseExample> | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.