Skip to content

feat(sdk-core): add wallet.defi DeFi vault orchestration methods#8912

Draft
hitansh-madan wants to merge 1 commit into
masterfrom
feat/sdk-defi-vault-methods
Draft

feat(sdk-core): add wallet.defi DeFi vault orchestration methods#8912
hitansh-madan wants to merge 1 commit into
masterfrom
feat/sdk-defi-vault-methods

Conversation

@hitansh-madan
Copy link
Copy Markdown
Contributor

@hitansh-madan hitansh-madan commented Jun 2, 2026

Add SDK-side orchestration for Galaxy × Morpho ERC-4626 vault deposits. Introduces wallet.defi.depositToVault() which sequences approve + deposit txRequests with fail-fast auto-cancel, plus resumeDeposit() for recovery, and getOperation()/listOperations() for status tracking.

Ticket: CGD-1533

@hitansh-madan hitansh-madan force-pushed the feat/sdk-defi-vault-methods branch 2 times, most recently from a86ee1d to 065e0e5 Compare June 2, 2026 12:05
Add SDK-side orchestration for Galaxy × Morpho ERC-4626 vault deposits.
Introduces wallet.defi.depositToVault() which sequences approve + deposit
txRequests with fail-fast auto-cancel, plus resumeDeposit() for recovery,
and getOperation()/listOperations() for status tracking.

Ticket: CGD-1533

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hitansh-madan hitansh-madan force-pushed the feat/sdk-defi-vault-methods branch from 065e0e5 to ef017e9 Compare June 2, 2026 12:51
Comment on lines +107 to +112
try {
await this.cancelTxRequest(approveTxRequestId);
} catch {
// Best-effort cancel; the reconciler will clean up if this fails
}
throw err;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thoughts on this?

Suggested change
try {
await this.cancelTxRequest(approveTxRequestId);
} catch {
// Best-effort cancel; the reconciler will clean up if this fails
}
throw err;
await this.cancelTxRequest(approveTxRequestId);

Comment on lines +224 to +225
private operationUrl(operationId: string): string {
return `/api/defi-service/v1/operations/${operationId}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this endpoint should also be be wallet.
without wallet scope, in the resumeDeposit() flow, it can potentially fetch operation from foreign wallet.

Suggested change
private operationUrl(operationId: string): string {
return `/api/defi-service/v1/operations/${operationId}`;
private operationUrl(operationId: string): string {
return `/api/defi-service/v1/wallets/${this.wallet.id()}/operations/${operationId}`;

Comment on lines +87 to +89
if (!operationId) {
throw new Error('operationId not found in approve txRequest response');
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we do cleanup if the operationId is not present in the response?

}

private async cancelTxRequest(txRequestId: string): Promise<void> {
await this.bitgo.del(this.bitgo.url('/wallet/' + this.wallet.id() + '/txrequests/' + txRequestId, 2)).result();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this endpoint exist today in platform?
DELETE /txrequests/{id}

Comment on lines +192 to +205
const query: Record<string, string | number> = {
walletId: this.wallet.id(),
vaultId: params.vaultId,
};
if (params.state) query.state = params.state;
if (params.type) query.type = params.type;
if (params.limit) query.limit = params.limit;
if (params.cursor) query.cursor = params.cursor;

return await this.bitgo
.get(this.bitgo.microservicesUrl(this.vaultOperationsUrl(params.vaultId)))
.query(query)
.result();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

vaultId redundant in the request
It's present in both URL path and query string.

...(params.clientIdempotencyKey ? { clientIdempotencyKey: params.clientIdempotencyKey } : {}),
};

const approveTxRequest = await this.createTxRequest(approveIntent);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

instead of using createTxRequest can we use the sendMany() method?
tomorrow, if we need to extend the depositToVault() for hot wallets, it will be easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants