From 9407b3b46bc4c0b839a2de76d8bfbed9fb875e7a Mon Sep 17 00:00:00 2001 From: Anil Gangapersaud Date: Wed, 24 Sep 2025 21:30:38 +0000 Subject: [PATCH 1/2] add cps fund api to sample app --- layouts/default.vue | 4 + lib/cpsTradesApi.ts | 48 +++++ pages/debug/cps/fund.vue | 358 ++++++++++++++++++++++++++++++++++++++ pages/debug/cps/index.vue | 4 + 4 files changed, 414 insertions(+) create mode 100644 pages/debug/cps/fund.vue diff --git a/layouts/default.vue b/layouts/default.vue index ae6d7be7..df4697b1 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -467,6 +467,10 @@ const cpsTradesLinks = [ title: 'POST /cps/signatures/funding/presign', to: '/debug/cps/funding-presign', }, + { + title: 'POST /cps/fund', + to: '/debug/cps/fund', + }, ] const miniVariant = ref(false) diff --git a/lib/cpsTradesApi.ts b/lib/cpsTradesApi.ts index 1c4ea5b0..3d6b85b0 100644 --- a/lib/cpsTradesApi.ts +++ b/lib/cpsTradesApi.ts @@ -50,6 +50,39 @@ export interface FundingPresignPayload { traderType: 'maker' | 'taker' } +export interface SingleTradeWitnessPermit2 { + permitted: { + token: string + amount: number + } + spender: string + nonce: number + deadline: number + witness: { + id: number + } +} + +export interface BatchTradeWitnessPermit2 { + permitted: Array<{ + token: string + amount: number + }> + spender: string + nonce: number + deadline: number + witness: { + ids: number[] + } +} + +export interface CpsFundPayload { + type: 'maker' | 'taker' + signature: string + fundingMode: 'gross' | 'net' + permit2: SingleTradeWitnessPermit2 | BatchTradeWitnessPermit2 +} + const instance = axios.create({ baseURL: getAPIHostname(), }) @@ -57,6 +90,7 @@ const instance = axios.create({ const CPS_TRADES_PATH = '/v1/exchange/cps/trades' const CPS_QUOTES_PATH = '/v1/exchange/cps/quotes' const CPS_SIGNATURES_PATH = '/v1/exchange/cps/signatures' +const CPS_FUND_PATH = '/v1/exchange/cps/fund' /** * Global error handler: @@ -178,6 +212,19 @@ function getFundingPresignData(payload: FundingPresignPayload) { return instance.post(url, payload) } +/** + * Fund CPS Trade + * Note: 'net' funding mode is only available for makers + */ +function fund(payload: CpsFundPayload) { + // Validate that net funding mode is only used with makers + if (payload.fundingMode === 'net' && payload.type !== 'maker') { + throw new Error('Net funding mode is only available for makers') + } + + return instance.post(CPS_FUND_PATH, payload) +} + export default { getInstance, createQuote, @@ -187,4 +234,5 @@ export default { registerSignature, getPresignData, getFundingPresignData, + fund, } diff --git a/pages/debug/cps/fund.vue b/pages/debug/cps/fund.vue new file mode 100644 index 00000000..bfd3b4dc --- /dev/null +++ b/pages/debug/cps/fund.vue @@ -0,0 +1,358 @@ + + + + + diff --git a/pages/debug/cps/index.vue b/pages/debug/cps/index.vue index 1949c6e6..66d0ad49 100644 --- a/pages/debug/cps/index.vue +++ b/pages/debug/cps/index.vue @@ -50,6 +50,10 @@ POST Get presign data for funding

+

+ POST + Fund CPS Trade +

From dc02f1f5d4ca3f6ab7ff528ab4f1fc6f1563e822 Mon Sep 17 00:00:00 2001 From: Anil Gangapersaud Date: Wed, 24 Sep 2025 21:36:48 +0000 Subject: [PATCH 2/2] lint --- pages/debug/cps/fund.vue | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pages/debug/cps/fund.vue b/pages/debug/cps/fund.vue index bfd3b4dc..a13ed18d 100644 --- a/pages/debug/cps/fund.vue +++ b/pages/debug/cps/fund.vue @@ -35,7 +35,7 @@

Single Trade Witness Permit2

- +

Batch Trade Witness Permit2

- +
@@ -101,7 +101,7 @@ Add Token
- +
- + - +