Skip to content
Merged
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
4 changes: 4 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 48 additions & 0 deletions lib/cpsTradesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,47 @@ 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(),
})

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:
Expand Down Expand Up @@ -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,
Expand All @@ -187,4 +234,5 @@ export default {
registerSignature,
getPresignData,
getFundingPresignData,
fund,
}
Loading
Loading