From cd091ee975a8eea4a2b5f37f1c01caf5fdbbac8c Mon Sep 17 00:00:00 2001 From: Anil Gangapersaud Date: Tue, 9 Sep 2025 16:03:55 +0000 Subject: [PATCH 1/2] update cps apis --- layouts/default.vue | 4 + lib/cpsTradesApi.ts | 69 ++++++++++++++-- pages/debug/cps/details.vue | 14 +++- pages/debug/cps/fetch.vue | 85 +++++++++++++++++--- pages/debug/cps/funding-presign.vue | 120 ++++++++++++++++++++++++++++ pages/debug/cps/index.vue | 8 ++ pages/debug/cps/presign.vue | 100 +++++++++++++++++++++++ pages/debug/cps/signature.vue | 43 ++++++---- 8 files changed, 410 insertions(+), 33 deletions(-) create mode 100644 pages/debug/cps/funding-presign.vue create mode 100644 pages/debug/cps/presign.vue diff --git a/layouts/default.vue b/layouts/default.vue index eb725a3e..4b18c6fa 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -455,6 +455,10 @@ const cpsTradesLinks = [ title: 'GET /cps/trades/{id}', to: '/debug/cps/details', }, + { + title: 'GET /cps/signatures/presign', + to: '/debug/cps/presign', + }, { title: 'POST /cps/signatures', to: '/debug/cps/signature', diff --git a/lib/cpsTradesApi.ts b/lib/cpsTradesApi.ts index 0a49f9e1..1c4ea5b0 100644 --- a/lib/cpsTradesApi.ts +++ b/lib/cpsTradesApi.ts @@ -29,9 +29,10 @@ export interface Consideration { } export interface PiFXTraderDetails { - recipient: string + recipient?: string deadline: number nonce: number + fee: number consideration: Consideration } @@ -43,6 +44,12 @@ export interface CreatePiFXSignaturePayload { signature: string } +export interface FundingPresignPayload { + contractTradeIds: string[] + fundingMode: 'gross' | 'net' + traderType: 'maker' | 'taker' +} + const instance = axios.create({ baseURL: getAPIHostname(), }) @@ -72,6 +79,13 @@ instance.interceptors.response.use( }, ) +const nullIfEmpty = (prop: string | undefined) => { + if (prop === '') { + return undefined + } + return prop +} + /** Returns the axios instance */ function getInstance() { return instance @@ -101,17 +115,38 @@ function createTrade(payload: CreateCpsTradePayload) { /** * Get CPS Trades */ -function getTrades() { - return instance.get(CPS_TRADES_PATH) +function getTrades( + startCreateDateInclusive?: string, + endCreateDateInclusive?: string, + statuses?: string, + type?: string, + pageAfter?: string, + pageBefore?: string, + pageSize?: string, +) { + const queryParams = { + startCreateDateInclusive: nullIfEmpty(startCreateDateInclusive), + endCreateDateInclusive: nullIfEmpty(endCreateDateInclusive), + status: nullIfEmpty(statuses), + type: nullIfEmpty(type), + pageAfter: nullIfEmpty(pageAfter), + pageBefore: nullIfEmpty(pageBefore), + pageSize: nullIfEmpty(pageSize), + } + + return instance.get(CPS_TRADES_PATH, { params: queryParams }) } /** * Get CPS Trade */ -function getTrade(tradeId: string) { +function getTrade(tradeId: string, type?: string) { const url = `${CPS_TRADES_PATH}/${tradeId}` + const queryParams = { + type: nullIfEmpty(type), + } - return instance.get(url) + return instance.get(url, { params: queryParams }) } /** @@ -121,6 +156,28 @@ function registerSignature(payload: CreatePiFXSignaturePayload) { return instance.post(CPS_SIGNATURES_PATH, payload) } +/** + * Get presign data for signing + */ +function getPresignData( + type: string, + tradeId: string, + recipientAddress?: string, +) { + const url = `/v1/exchange/cps/signatures/presign/${type}/${tradeId}` + const queryParams = recipientAddress ? { recipientAddress } : {} + + return instance.get(url, { params: queryParams }) +} + +/** + * Get funding presign data + */ +function getFundingPresignData(payload: FundingPresignPayload) { + const url = '/v1/exchange/cps/signatures/funding/presign' + return instance.post(url, payload) +} + export default { getInstance, createQuote, @@ -128,4 +185,6 @@ export default { getTrades, getTrade, registerSignature, + getPresignData, + getFundingPresignData, } diff --git a/pages/debug/cps/details.vue b/pages/debug/cps/details.vue index f15e3c7c..bd2f27e7 100644 --- a/pages/debug/cps/details.vue +++ b/pages/debug/cps/details.vue @@ -8,6 +8,12 @@ :rules="[required]" label="CPS Trade ID" /> + ({}) const loading = ref(false) const showError = ref(false) @@ -63,7 +75,7 @@ const makeApiCall = async () => { loading.value = true try { - await $cpsTradesApi.getTrade(formData.tradeId) + await $cpsTradesApi.getTrade(formData.tradeId, formData.type || undefined) } catch (err) { error.value = err showError.value = true diff --git a/pages/debug/cps/fetch.vue b/pages/debug/cps/fetch.vue index 688cd73c..e8f9aa27 100644 --- a/pages/debug/cps/fetch.vue +++ b/pages/debug/cps/fetch.vue @@ -1,17 +1,43 @@ diff --git a/pages/debug/cps/index.vue b/pages/debug/cps/index.vue index 23714610..1949c6e6 100644 --- a/pages/debug/cps/index.vue +++ b/pages/debug/cps/index.vue @@ -42,6 +42,14 @@ POST Register CPS signature

+

+ GET + Get presign data for trade +

+

+ POST + Get presign data for funding +

diff --git a/pages/debug/cps/presign.vue b/pages/debug/cps/presign.vue new file mode 100644 index 00000000..b4391bb3 --- /dev/null +++ b/pages/debug/cps/presign.vue @@ -0,0 +1,100 @@ + + + diff --git a/pages/debug/cps/signature.vue b/pages/debug/cps/signature.vue index 19fa33b9..5853d831 100644 --- a/pages/debug/cps/signature.vue +++ b/pages/debug/cps/signature.vue @@ -20,8 +20,9 @@ label="Address" /> +

Consideration Details

{ loading.value = true try { + const details: any = { + deadline: parseInt(formData.details.deadline), + nonce: parseInt(formData.details.nonce), + fee: parseInt(formData.fee), + consideration: { + quoteId: formData.details.consideration.quoteId, + base: formData.details.consideration.base, + quote: formData.details.consideration.quote, + quoteAmount: parseInt(formData.details.consideration.quoteAmount), + baseAmount: parseInt(formData.details.consideration.baseAmount), + maturity: parseInt(formData.details.consideration.maturity), + }, + } + + // Only include recipient if type is taker + if (formData.type === 'taker') { + details.recipient = formData.details.recipient + } + const payloadData: CreatePiFXSignaturePayload = { tradeId: formData.tradeId, type: formData.type, address: formData.address, - details: { - recipient: formData.details.recipient, - deadline: parseInt(formData.details.deadline), - nonce: parseInt(formData.details.nonce), - consideration: { - quoteId: formData.details.consideration.quoteId, - base: formData.details.consideration.base, - quote: formData.details.consideration.quote, - quoteAmount: parseInt(formData.details.consideration.quoteAmount), - baseAmount: parseInt(formData.details.consideration.baseAmount), - maturity: parseInt(formData.details.consideration.maturity), - }, - }, + details, signature: formData.signature, } From 78013055d5c24fc4bd0b0f289bf9d7438fb3b548 Mon Sep 17 00:00:00 2001 From: Anil Gangapersaud Date: Tue, 9 Sep 2025 16:12:35 +0000 Subject: [PATCH 2/2] add nav for presign funding --- layouts/default.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/layouts/default.vue b/layouts/default.vue index 4b18c6fa..ae6d7be7 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -463,6 +463,10 @@ const cpsTradesLinks = [ title: 'POST /cps/signatures', to: '/debug/cps/signature', }, + { + title: 'POST /cps/signatures/funding/presign', + to: '/debug/cps/funding-presign', + }, ] const miniVariant = ref(false)