Skip to content

Commit 21190c6

Browse files
Merge pull request #8991 from BitGo/feat/sdk-defi-disable-preflight
feat(sdk-core): disable active operation pre-flight check in DefiVault
2 parents aebe4a6 + 7ace459 commit 21190c6

2 files changed

Lines changed: 14 additions & 25 deletions

File tree

modules/sdk-core/src/bitgo/defi/defiVault.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export class DefiVault implements IDefiVault {
5252
*
5353
* Internally issues two sendMany calls (approve + deposit) and returns the
5454
* operationId that links them. If the deposit sendMany fails after
55-
* the approve succeeds, the approve is auto-cancelled (fail-fast).
55+
* the approve succeeds, the error propagates — the server-side reconciler
56+
* handles orphaned approvals.
5657
*
5758
* @param params.vaultId - DeFi-service vault identifier
5859
* @param params.amount - amount in base units of the underlying asset
@@ -67,15 +68,16 @@ export class DefiVault implements IDefiVault {
6768
throw new Error('amount is required');
6869
}
6970

70-
// Layer-1 pre-flight: reject if an active deposit already exists for this (wallet, vault)
71-
const activeOps: DefiOperationListResult = await this.bitgo
72-
.get(this.bitgo.microservicesUrl(this.operationsUrl()))
73-
.query({ vaultId: params.vaultId, state: 'active' })
74-
.result();
75-
76-
if (activeOps.items && activeOps.items.length > 0) {
77-
throw new ActiveOperationExistsError(activeOps.items[0].operationId);
78-
}
71+
// TODO(CGD-1709): Re-enable active operation pre-flight check once the
72+
// defi-service operations endpoint is deployed and returning active state.
73+
// const activeOps: DefiOperationListResult = await this.bitgo
74+
// .get(this.bitgo.microservicesUrl(this.operationsUrl()))
75+
// .query({ vaultId: params.vaultId, state: 'active' })
76+
// .result();
77+
//
78+
// if (activeOps.items && activeOps.items.length > 0) {
79+
// throw new ActiveOperationExistsError(activeOps.items[0].operationId);
80+
// }
7981

8082
// Step 1: Approve txRequest via sendMany
8183
const approveResult = await this.wallet.sendMany({

modules/sdk-core/test/unit/bitgo/defi/defiVault.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ describe('DefiVault', function () {
5454
it('should call sendMany for approve and deposit on happy path', async function () {
5555
const operationId = 'op-uuid-123';
5656

57-
// Pre-flight: no active operations
58-
const preflightReq = mockRequest({ items: [] });
59-
mockBitGo.get.onFirstCall().returns(preflightReq);
60-
6157
// Mock sendMany for approve and deposit
6258
const sendManyStub = sinon.stub(wallet, 'sendMany');
6359
sendManyStub.onFirstCall().resolves({
@@ -82,9 +78,6 @@ describe('DefiVault', function () {
8278
result.txRequestIds.approve.should.equal('txreq-approve-1');
8379
result.txRequestIds.deposit.should.equal('txreq-deposit-1');
8480

85-
// Verify pre-flight was called with correct query
86-
preflightReq.query.calledWith({ vaultId: 'vlt-galaxy-usdc', state: 'active' }).should.be.true();
87-
8881
// Verify sendMany was called with correct params for approve
8982
sendManyStub.calledTwice.should.be.true();
9083
const approveArgs: any = sendManyStub.firstCall.args[0];
@@ -98,7 +91,8 @@ describe('DefiVault', function () {
9891
depositArgs.defiParams.operationId.should.equal(operationId);
9992
});
10093

101-
it('should reject when an active operation already exists', async function () {
94+
// TODO(CGD-1709): Re-enable when active operation pre-flight check is restored
95+
xit('should reject when an active operation already exists', async function () {
10296
const preflightReq = mockRequest({
10397
items: [{ operationId: 'existing-op-id', state: 'APPROVE_TX_REQUESTED' }],
10498
});
@@ -117,10 +111,6 @@ describe('DefiVault', function () {
117111
it('should propagate deposit sendMany failure without cleanup', async function () {
118112
const operationId = 'op-uuid-456';
119113

120-
// Pre-flight: no active operations
121-
const preflightReq = mockRequest({ items: [] });
122-
mockBitGo.get.returns(preflightReq);
123-
124114
// Mock sendMany: approve succeeds, deposit fails
125115
const sendManyStub = sinon.stub(wallet, 'sendMany');
126116
sendManyStub.onFirstCall().resolves({
@@ -154,9 +144,6 @@ describe('DefiVault', function () {
154144
it('should pass clientIdempotencyKey and walletPassphrase when provided', async function () {
155145
const operationId = 'op-uuid-789';
156146

157-
const preflightReq = mockRequest({ items: [] });
158-
mockBitGo.get.returns(preflightReq);
159-
160147
const sendManyStub = sinon.stub(wallet, 'sendMany');
161148
sendManyStub.onFirstCall().resolves({
162149
txRequest: {

0 commit comments

Comments
 (0)