[swap] Parse zippo headers
This commit is contained in:
parent
fbec8d2281
commit
d5f304fc69
@ -361,11 +361,24 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | '
|
||||
// HACK typescript typing does not allow this valid json-schema
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: fix me!
|
||||
schemaUtils.validateSchema(req.query, schemas.swapQuoteRequestSchema as any);
|
||||
const apiKey: string | undefined = req.header('0x-api-key');
|
||||
const origin: string | undefined = req.header('origin');
|
||||
|
||||
// With zippo and the developer dashboard, we'll get:
|
||||
// - 0x-App-Id (instead of an integrator id)
|
||||
// - 0x-Affiliate-Address
|
||||
// For now, we'll use the app id in place of the integrator id, as long as the
|
||||
// app ID exists.
|
||||
// Also, we'll prefer the zippo affiliate address over any passed in the header.
|
||||
let integratorId: string | undefined;
|
||||
if (apiKey) {
|
||||
integratorId = getIntegratorIdForApiKey(apiKey);
|
||||
const zippoAppId = req.header('0x-App-Id');
|
||||
const zippoAffiliateAddress = req.header('0x-Affiliate-Address');
|
||||
if (zippoAppId) {
|
||||
integratorId = zippoAppId;
|
||||
} else {
|
||||
const apiKey: string | undefined = req.header('0x-api-key');
|
||||
if (apiKey) {
|
||||
integratorId = getIntegratorIdForApiKey(apiKey);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse string params
|
||||
@ -475,7 +488,6 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | '
|
||||
includedSources: req.query.includedSources as string | undefined,
|
||||
intentOnFilling: req.query.intentOnFilling as string | undefined,
|
||||
takerAddress: takerAddress as string,
|
||||
apiKey,
|
||||
},
|
||||
endpoint,
|
||||
);
|
||||
@ -492,7 +504,7 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | '
|
||||
}
|
||||
|
||||
const rfqt: Pick<RfqRequestOpts, 'intentOnFilling' | 'isIndicative' | 'nativeExclusivelyRFQ'> | undefined = (() => {
|
||||
if (apiKey) {
|
||||
if (integratorId !== undefined) {
|
||||
if (endpoint === 'quote' && takerAddress) {
|
||||
return {
|
||||
intentOnFilling: req.query.intentOnFilling === 'true',
|
||||
@ -528,7 +540,6 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | '
|
||||
apiKey: integratorId || 'N/A',
|
||||
integratorId: integratorId || 'N/A',
|
||||
integratorLabel: integrator?.label || 'N/A',
|
||||
rawApiKey: apiKey || 'N/A',
|
||||
enableSlippageProtection,
|
||||
priceImpactProtectionPercentage,
|
||||
});
|
||||
@ -536,7 +547,6 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | '
|
||||
return {
|
||||
affiliateAddress: affiliateAddress as string,
|
||||
affiliateFee,
|
||||
apiKey,
|
||||
buyAmount,
|
||||
buyToken,
|
||||
endpoint,
|
||||
|
@ -10,7 +10,6 @@ interface ParseRequestForExcludedSourcesParams {
|
||||
excludedSources?: string;
|
||||
includedSources?: string;
|
||||
intentOnFilling?: string;
|
||||
apiKey?: string;
|
||||
}
|
||||
|
||||
interface ParseRequestForExcludedSourcesResult {
|
||||
@ -68,17 +67,6 @@ export const parseUtils = {
|
||||
]);
|
||||
}
|
||||
|
||||
// We enforce a valid API key - we don't want to fail silently.
|
||||
if (request.apiKey === undefined) {
|
||||
throw new ValidationError([
|
||||
{
|
||||
field: '0x-api-key',
|
||||
code: ValidationErrorCodes.RequiredField,
|
||||
reason: ValidationErrorReasons.InvalidApiKey,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
// If the user is requesting a firm quote, we want to make sure that `intentOnFilling` is set to "true".
|
||||
if (endpoint === 'quote' && request.intentOnFilling !== 'true') {
|
||||
throw new ValidationError([
|
||||
|
@ -46,7 +46,6 @@ describe(SUITE_NAME, () => {
|
||||
{
|
||||
includedSources: 'RFQT',
|
||||
takerAddress: NULL_ADDRESS,
|
||||
apiKey: 'ipsum',
|
||||
},
|
||||
'price',
|
||||
);
|
||||
@ -60,7 +59,6 @@ describe(SUITE_NAME, () => {
|
||||
{
|
||||
includedSources: 'RFQT,Native',
|
||||
takerAddress: NULL_ADDRESS,
|
||||
apiKey: 'ipsum',
|
||||
},
|
||||
'price',
|
||||
);
|
||||
@ -87,7 +85,6 @@ describe(SUITE_NAME, () => {
|
||||
{
|
||||
includedSources: 'RFQT',
|
||||
takerAddress: NULL_ADDRESS,
|
||||
apiKey: 'ipsum',
|
||||
},
|
||||
'quote',
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user