Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module.exports = {
'CHALO-',
'CECHO-',
'CSHLD-',
'DEFI-',
'#', // Prefix used by GitHub issues
],
},
Expand Down
2 changes: 1 addition & 1 deletion modules/abstract-lightning/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
]
},
"dependencies": {
"@bitgo/public-types": "6.22.0",
"@bitgo/public-types": "6.40.0",
"@bitgo/sdk-core": "^38.0.0",
"@bitgo/statics": "^58.54.0",
"@bitgo/utxo-lib": "^11.24.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"superagent": "^9.0.1"
},
"devDependencies": {
"@bitgo/public-types": "6.22.0",
"@bitgo/public-types": "6.40.0",
"@bitgo/sdk-opensslbytes": "^2.1.0",
"@bitgo/sdk-test": "^9.1.57",
"@openpgp/web-stream-tools": "0.0.14",
Expand Down
2 changes: 1 addition & 1 deletion modules/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"superagent": "^9.0.1"
},
"devDependencies": {
"@bitgo/public-types": "6.22.0",
"@bitgo/public-types": "6.40.0",
"@bitgo/sdk-lib-mpc": "^10.15.0",
"@bitgo/sdk-test": "^9.1.57",
"@types/argparse": "^1.0.36",
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-flrp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"nock": "^13.3.1"
},
"dependencies": {
"@bitgo/public-types": "6.22.0",
"@bitgo/public-types": "6.40.0",
"@bitgo/sdk-core": "^38.0.0",
"@bitgo/secp256k1": "^1.11.0",
"@bitgo/statics": "^58.54.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-sol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"@bitgo/logger": "^1.4.0",
"@bitgo/public-types": "6.22.0",
"@bitgo/public-types": "6.40.0",
"@bitgo/sdk-core": "^38.0.0",
"@bitgo/sdk-lib-mpc": "^10.15.0",
"@bitgo/statics": "^58.54.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
]
},
"dependencies": {
"@bitgo/public-types": "6.22.0",
"@bitgo/public-types": "6.40.0",
"@bitgo/sdk-lib-mpc": "^10.15.0",
"@bitgo/secp256k1": "^1.11.0",
"@bitgo/sjcl": "^1.1.0",
Expand Down
76 changes: 72 additions & 4 deletions modules/sdk-core/src/bitgo/defi/defiVault.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
/**
* @prettier
*/
import { GetVaultResponse, VaultProtocol } from '@bitgo/public-types';
import {
ConcreteDepositResult,
MorphoDepositResult,
DefiOperation,
DefiOperationListResult,
DepositResult,
DepositToVaultOptions,
GetOperationOptions,
GetVaultConfigOptions,
IDefiVault,
ListOperationsOptions,
ResumeDepositOptions,
} from './iDefiVault';
import { IWallet } from '../wallet';
import { BitGoBase } from '../bitgoBase';
import { decodeWithCodec } from '../utils';

/**
* Error thrown when a concurrent active deposit already exists for the (wallet, vault) pair.
Expand Down Expand Up @@ -47,13 +52,26 @@ export class DefiVault implements IDefiVault {
this.bitgo = wallet.bitgo;
}

/**
* Fetch vault config from defi-service. Used internally to determine
* which deposit path to take (Concrete vs Morpho).
*/
async getVaultConfig(params: GetVaultConfigOptions): Promise<GetVaultResponse> {
if (!params.vaultId) {
throw new Error('vaultId is required');
}
const raw = await this.bitgo
.get(this.bitgo.microservicesUrl(`/api/defi-service/v1/vaults/${params.vaultId}`))
.result();
return decodeWithCodec(GetVaultResponse, raw, 'getVaultConfig');
}

/**
* Deposit an amount of underlying asset into a vault.
*
* Internally issues two sendMany calls (approve + deposit) and returns the
* operationId that links them. If the deposit sendMany fails after
* the approve succeeds, the error propagates — the server-side reconciler
* handles orphaned approvals.
* Dispatches to the concrete or morpho path based on vault provider.
* The concrete path returns a pendingApproval (custodial wallet).
* The morpho path issues two sendMany calls (approve + deposit).
*
* @param params.vaultId - DeFi-service vault identifier
* @param params.amount - amount in base units of the underlying asset
Expand All @@ -68,6 +86,41 @@ export class DefiVault implements IDefiVault {
throw new Error('amount is required');
}

const config = await this.getVaultConfig({ vaultId: params.vaultId });

if (config.provider === VaultProtocol.CONCRETE_BTCCX) {
return this.depositToConcreteVault(params);
} else if (config.provider === VaultProtocol.MORPHO) {
return this.depositToMorphoVault(params);
} else {
throw new Error(`Unsupported vault provider: ${config.provider}`);
}
}

/**
* Concrete BTC vault deposit path. The client BTC wallet is custodial, so
* sendMany returns a pendingApproval rather than a signed transfer.
* No recipients are sent — WP resolves the escrow destination server-side.
*/
private async depositToConcreteVault(params: DepositToVaultOptions): Promise<ConcreteDepositResult> {
const sendManyResult = await this.wallet.sendMany({
type: 'defi-deposit',

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.

can we have common intent type case as I can see most of intent type follow camel case but here we are using Kebab Case ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same in BitGoJS sdk too,

case 'defiApprove':
txRequest = await this.tssUtils!.prebuildTxWithIntent(
{
reqId,
intentType: 'defi-approve',
defiParams: params.defiParams as {
vaultId: string;
amount: string;
clientIdempotencyKey?: string;
},
},
apiVersion,
params.preview
);
break;
case 'defiDeposit':
txRequest = await this.tssUtils!.prebuildTxWithIntent(
{
reqId,
intentType: 'defi-deposit',
defiParams: params.defiParams as {
vaultId: string;
amount: string;
operationId?: string;
clientIdempotencyKey?: string;
},
},
apiVersion,
params.preview
);

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.

Since we are building a new service, we should align the intent type naming convention with what we follow in WP. The existing intent types use camelCase, so it would be better to keep the same convention here instead of introducing kebab-case.

@venkateshv1266 venkateshv1266 Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In case of morpho, these changes are already done and its live in prod i guess cc: @kamleshmugdiya @hafeezshaik933

defiParams: {
vaultId: params.vaultId,
amount: params.amount,
actionType: 'defi-deposit',
},
...(params.walletPassphrase ? { walletPassphrase: params.walletPassphrase } : {}),
});

return this.extractConcreteDepositResult(sendManyResult);
}

/**
* Morpho vault deposit path. Issues two sendMany calls (approve + deposit)
* and returns the operationId that links them.
*/
private async depositToMorphoVault(params: DepositToVaultOptions): Promise<MorphoDepositResult> {
// TODO(CGD-1709): Re-enable active operation pre-flight check once the
// defi-service operations endpoint is deployed and returning active state.
// const activeOps: DefiOperationListResult = await this.bitgo
Expand Down Expand Up @@ -256,6 +309,21 @@ export class DefiVault implements IDefiVault {
return intent?.operationId as string | undefined;
}

/**
* Extracts {@link ConcreteDepositResult} from a custodial sendMany response.
* Concrete BTC deposits return a `pendingApproval` instead of a txRequest —
* throws if `pendingApproval.id` is absent, indicating an unexpected shape.
*/
private extractConcreteDepositResult(sendManyResult: Record<string, unknown>): ConcreteDepositResult {
const pendingApproval = sendManyResult.pendingApproval as Record<string, unknown> | undefined;
const id = pendingApproval?.id as string | undefined;
if (!id) {
throw new Error('Unexpected sendMany response for defi-deposit: no pendingApproval.id');
}
const state = (pendingApproval?.state as string | undefined) ?? 'awaitingSignature';
return { pendingApprovalId: id, state };
}

private operationsUrl(): string {
return `/api/defi-service/v1/wallets/${this.wallet.id()}/operations`;
}
Expand Down
21 changes: 16 additions & 5 deletions modules/sdk-core/src/bitgo/defi/iDefiVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @prettier
*/

import { GetVaultResponse } from '@bitgo/public-types';

export interface DepositToVaultOptions {
/** DeFi-service vault identifier */
vaultId: string;
Expand Down Expand Up @@ -32,6 +34,10 @@ export interface ListOperationsOptions {
cursor?: string;
}

export interface GetVaultConfigOptions {
vaultId: string;
}

export interface DefiOperation {
operationId: string;
walletId: string;
Expand All @@ -45,14 +51,18 @@ export interface DefiOperation {
updatedAt: string;
}

export interface DepositResult {
export interface ConcreteDepositResult {
pendingApprovalId: string;
state: string;
}

export interface MorphoDepositResult {
operationId: string;
txRequestIds: {
approve: string;
deposit: string;
};
txRequestIds: { approve: string; deposit: string };
}

export type DepositResult = ConcreteDepositResult | MorphoDepositResult;

export interface DefiOperationListResult {
items: DefiOperation[];
nextCursor?: string;
Expand All @@ -63,4 +73,5 @@ export interface IDefiVault {
resumeDeposit(params: ResumeDepositOptions): Promise<DepositResult>;
getOperation(params: GetOperationOptions): Promise<DefiOperation>;
listOperations(params: ListOperationsOptions): Promise<DefiOperationListResult>;
getVaultConfig(params: GetVaultConfigOptions): Promise<GetVaultResponse>;
}
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/wallet/BuildParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const BuildParams = t.exact(
feeToken: t.unknown,
// Bridging parameters for cross-chain operations (e.g., BTC to sBTC)
bridgingParams: t.unknown,
defiParams: t.unknown,
}),
])
);
Expand Down
7 changes: 7 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/iWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,13 @@ export interface SendManyOptions extends PrebuildAndSignTransactionOptions {
eip1559?: EIP1559;
gasLimit?: number;
custodianTransactionId?: string;
defiParams?: {
vaultId?: string;
amount?: string | number;
actionType?: string;
operationId?: string;
clientIdempotencyKey?: string;
};
}

export interface FetchCrossChainUTXOsOptions {
Expand Down
Loading
Loading