Skip to content

Commit 3a4721e

Browse files
committed
rate limits mocks
1 parent 856dbd2 commit 3a4721e

File tree

10 files changed

+63
-48
lines changed

10 files changed

+63
-48
lines changed

public/api/ccip/v1/openapi.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
"in": "query",
8888
"schema": {
8989
"type": "string",
90-
"enum": ["chainId", "selector", "internalId"],
91-
"default": "chainId"
90+
"enum": ["chain_id", "selector", "internal_id"],
91+
"default": "chain_id"
9292
},
9393
"description": "Key to use for organizing the response data"
9494
},
@@ -274,8 +274,8 @@
274274
"in": "query",
275275
"schema": {
276276
"type": "string",
277-
"enum": ["chainId", "selector", "internalId"],
278-
"default": "chainId"
277+
"enum": ["chain_id", "selector", "internal_id"],
278+
"default": "chain_id"
279279
},
280280
"description": "Key to use for organizing the response data"
281281
}
@@ -393,8 +393,8 @@
393393
"in": "query",
394394
"schema": {
395395
"type": "string",
396-
"enum": ["chainId", "selector", "internalId"],
397-
"default": "chainId"
396+
"enum": ["chain_id", "selector", "internal_id"],
397+
"default": "chain_id"
398398
},
399399
"description": "Key to use for organizing the response data by chain"
400400
}
@@ -548,8 +548,8 @@
548548
"in": "query",
549549
"schema": {
550550
"type": "string",
551-
"enum": ["chainId", "selector", "internalId"],
552-
"default": "chainId"
551+
"enum": ["chain_id", "selector", "internal_id"],
552+
"default": "chain_id"
553553
},
554554
"description": "Key to use for organizing the response data by chain"
555555
}
@@ -715,8 +715,8 @@
715715
"in": "query",
716716
"schema": {
717717
"type": "string",
718-
"enum": ["chainId", "selector", "internalId"],
719-
"default": "chainId"
718+
"enum": ["chain_id", "selector", "internal_id"],
719+
"default": "chain_id"
720720
},
721721
"description": "Key format to use for organizing the lane keys in the response"
722722
}

src/lib/ccip/services/lane-data.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,26 +252,26 @@ export class LaneDataService {
252252
filters: LaneFilterType
253253
): boolean {
254254
// Check source chain filters
255-
if (filters.sourceChainId && !this.matchesChainFilter(sourceChain, filters.sourceChainId, "chainId")) {
255+
if (filters.sourceChainId && !this.matchesChainFilter(sourceChain, filters.sourceChainId, "chain_id")) {
256256
return false
257257
}
258258
if (filters.sourceSelector && !this.matchesChainFilter(sourceChain, filters.sourceSelector, "selector")) {
259259
return false
260260
}
261-
if (filters.sourceInternalId && !this.matchesChainFilter(sourceChain, filters.sourceInternalId, "internalId")) {
261+
if (filters.sourceInternalId && !this.matchesChainFilter(sourceChain, filters.sourceInternalId, "internal_id")) {
262262
return false
263263
}
264264

265265
// Check destination chain filters
266-
if (filters.destinationChainId && !this.matchesChainFilter(destChain, filters.destinationChainId, "chainId")) {
266+
if (filters.destinationChainId && !this.matchesChainFilter(destChain, filters.destinationChainId, "chain_id")) {
267267
return false
268268
}
269269
if (filters.destinationSelector && !this.matchesChainFilter(destChain, filters.destinationSelector, "selector")) {
270270
return false
271271
}
272272
if (
273273
filters.destinationInternalId &&
274-
!this.matchesChainFilter(destChain, filters.destinationInternalId, "internalId")
274+
!this.matchesChainFilter(destChain, filters.destinationInternalId, "internal_id")
275275
) {
276276
return false
277277
}
@@ -285,14 +285,21 @@ export class LaneDataService {
285285
private matchesChainFilter(
286286
chain: ChainInfoInternal,
287287
filterValue: string,
288-
filterType: "chainId" | "selector" | "internalId"
288+
filterType: "chain_id" | "selector" | "internal_id"
289289
): boolean {
290290
const filterValues = filterValue.split(",").map((v) => v.trim())
291-
const chainValue = chain[filterType].toString()
291+
// Map snake_case filter types to camelCase property names
292+
const propertyMap: Record<string, keyof ChainInfoInternal> = {
293+
chain_id: "chainId",
294+
selector: "selector",
295+
internal_id: "internalId",
296+
}
297+
const propertyName = propertyMap[filterType]
298+
const chainValue = chain[propertyName].toString()
292299

293-
// For chainId, also check generated chain key format
294-
if (filterType === "chainId") {
295-
const generatedKey = generateChainKey(chain.chainId, chain.chainType, "chainId")
300+
// For chain_id, also check generated chain key format
301+
if (filterType === "chain_id") {
302+
const generatedKey = generateChainKey(chain.chainId, chain.chainType, "chain_id")
296303
return filterValues.includes(chainValue) || filterValues.includes(generatedKey)
297304
}
298305

@@ -307,15 +314,23 @@ export class LaneDataService {
307314
destChain: ChainInfoInternal,
308315
outputKey: OutputKeyType
309316
): string {
317+
// Map snake_case output keys to camelCase property names
318+
const propertyMap: Record<string, keyof ChainInfoInternal> = {
319+
chain_id: "chainId",
320+
selector: "selector",
321+
internal_id: "internalId",
322+
}
323+
const propertyName = propertyMap[outputKey]
324+
310325
const sourceKey =
311-
outputKey === "chainId"
326+
outputKey === "chain_id"
312327
? generateChainKey(sourceChain.chainId, sourceChain.chainType, outputKey)
313-
: sourceChain[outputKey].toString()
328+
: sourceChain[propertyName].toString()
314329

315330
const destKey =
316-
outputKey === "chainId"
331+
outputKey === "chain_id"
317332
? generateChainKey(destChain.chainId, destChain.chainType, outputKey)
318-
: destChain[outputKey].toString()
333+
: destChain[propertyName].toString()
319334

320335
return `${sourceKey}_to_${destKey}`
321336
}
@@ -515,14 +530,14 @@ export class LaneDataService {
515530
inputKeyType: LaneInputKeyType,
516531
chainsReferenceData: Record<string, ChainConfig>
517532
): string | null {
518-
// If already an internalId, return it directly
519-
if (inputKeyType === "internalId") {
533+
// If already an internal_id, return it directly
534+
if (inputKeyType === "internal_id") {
520535
return chainsReferenceData[identifier] ? identifier : null
521536
}
522537

523-
// Search through chains to find matching chainId or selector
538+
// Search through chains to find matching chain_id or selector
524539
for (const [internalId, chainConfig] of Object.entries(chainsReferenceData)) {
525-
if (inputKeyType === "chainId") {
540+
if (inputKeyType === "chain_id") {
526541
// Try to match by numeric chain ID
527542
try {
528543
const supportedChain = directoryToSupportedChain(internalId)

src/lib/ccip/services/token-data.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ export class TokenDataService {
149149

150150
if (!destNumericChainId) return destChainId
151151

152-
if (outputKey === "chainId") {
152+
if (outputKey === "chain_id") {
153153
return generateChainKey(destNumericChainId, destChainType, outputKey)
154154
} else if (outputKey === "selector") {
155155
const selectorEntry = getSelectorEntry(destNumericChainId, destChainType)
156156
return selectorEntry?.selector || destChainId
157-
} else if (outputKey === "internalId") {
157+
} else if (outputKey === "internal_id") {
158158
const selectorEntry = getSelectorEntry(destNumericChainId, destChainType)
159159
return selectorEntry?.name || destChainId
160160
}
@@ -164,14 +164,14 @@ export class TokenDataService {
164164

165165
// Get the appropriate key based on outputKey parameter
166166
let chainKey = chainId
167-
if (outputKey === "chainId") {
167+
if (outputKey === "chain_id") {
168168
chainKey = generateChainKey(numericChainId, chainType, outputKey)
169169
} else if (outputKey === "selector") {
170170
const selectorEntry = getSelectorEntry(numericChainId, chainType)
171171
if (selectorEntry) {
172172
chainKey = selectorEntry.selector
173173
}
174-
} else if (outputKey === "internalId") {
174+
} else if (outputKey === "internal_id") {
175175
const selectorEntry = getSelectorEntry(numericChainId, chainType)
176176
if (selectorEntry) {
177177
chainKey = selectorEntry.name
@@ -276,7 +276,7 @@ export class TokenDataService {
276276
public async getFilteredTokens(
277277
environment: Environment,
278278
filters: TokenFilterType,
279-
outputKey: OutputKeyType = "chainId"
279+
outputKey: OutputKeyType = "chain_id"
280280
): Promise<TokenServiceResponse> {
281281
logger.info({
282282
message: "Starting token filtering process",
@@ -388,7 +388,7 @@ export class TokenDataService {
388388
public async getTokenWithFinality(
389389
environment: Environment,
390390
tokenCanonicalSymbol: string,
391-
outputKey: OutputKeyType = "chainId"
391+
outputKey: OutputKeyType = "chain_id"
392392
): Promise<TokenDetailServiceResponse | null> {
393393
logger.info({
394394
message: "Getting token with finality data",
@@ -523,7 +523,7 @@ export class TokenDataService {
523523
public async getTokenFinality(
524524
environment: Environment,
525525
tokenCanonicalSymbol: string,
526-
outputKey: OutputKeyType = "chainId"
526+
outputKey: OutputKeyType = "chain_id"
527527
): Promise<TokenFinalityServiceResponse | null> {
528528
logger.info({
529529
message: "Getting token finality data",

src/lib/ccip/types/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export type ChainApiResponse = {
6464
}[]
6565
}
6666

67-
export type OutputKeyType = "chainId" | "selector" | "internalId"
67+
export type OutputKeyType = "chain_id" | "selector" | "internal_id"
6868

6969
export type ChainApiError = {
7070
error: string
@@ -313,7 +313,7 @@ export interface LaneFilterType {
313313
/**
314314
* Input key type for lane path parameters
315315
*/
316-
export type LaneInputKeyType = "chainId" | "selector" | "internalId"
316+
export type LaneInputKeyType = "chain_id" | "selector" | "internal_id"
317317

318318
/**
319319
* Metadata for single lane detail API responses

src/lib/ccip/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ export const validateFilters = (filters: FilterType): void => {
332332
* @returns Validated output key
333333
* @throws CCIPError if output key is invalid
334334
*/
335-
export const validateOutputKey = (outputKey?: string): "chainId" | "selector" | "internalId" => {
336-
if (!outputKey) return "chainId"
337-
if (!["chainId", "selector", "internalId"].includes(outputKey)) {
338-
throw new CCIPError(400, "output_key must be one of: chainId, selector, or internalId")
335+
export const validateOutputKey = (outputKey?: string): "chain_id" | "selector" | "internal_id" => {
336+
if (!outputKey) return "chain_id"
337+
if (!["chain_id", "selector", "internal_id"].includes(outputKey)) {
338+
throw new CCIPError(400, "output_key must be one of: chain_id, selector, or internal_id")
339339
}
340-
return outputKey as "chainId" | "selector" | "internalId"
340+
return outputKey as "chain_id" | "selector" | "internal_id"
341341
}
342342

343343
/**
@@ -358,7 +358,7 @@ export const validateEnrichFeeTokens = (enrichFeeTokens?: string): boolean => {
358358
export const generateChainKey = (chainId: number | string, chainType: ChainType, outputKey: OutputKeyType): string => {
359359
const chainIdStr = chainId.toString()
360360

361-
if (outputKey === "chainId" && chainType !== "evm" && chainType !== "solana") {
361+
if (outputKey === "chain_id" && chainType !== "evm" && chainType !== "solana") {
362362
return `${chainType}-${chainIdStr}`
363363
}
364364

src/pages/api/ccip/v1/chains.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const GET: APIRoute = async ({ request }) => {
4444

4545
// Validate filters
4646
const filters: FilterType = {
47-
chainId: params.get("chainId") || undefined,
47+
chainId: params.get("chain_id") || undefined,
4848
selector: params.get("selector") || undefined,
4949
internalId: params.get("internalId") || undefined,
5050
}
@@ -104,7 +104,7 @@ export const GET: APIRoute = async ({ request }) => {
104104
acc[family] = chainList.reduce(
105105
(familyAcc, chain) => {
106106
const key =
107-
outputKey === "chainId"
107+
outputKey === "chain_id"
108108
? generateChainKey(chain.chainId, chain.chainType, outputKey)
109109
: outputKey
110110
? chain[outputKey].toString()

src/pages/api/ccip/v1/lanes/by-chain-id/[source]/[destination]/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const GET: APIRoute = async ({ params, request }) => {
4242
})
4343

4444
const laneDataService = new LaneDataService()
45-
const result = await laneDataService.getLaneDetails(environment, source, destination, "chainId")
45+
const result = await laneDataService.getLaneDetails(environment, source, destination, "chain_id")
4646

4747
if (!result.data) {
4848
throw new CCIPError(404, `Lane from chain '${source}' to chain '${destination}' not found`)

src/pages/api/ccip/v1/lanes/by-chain-id/[source]/[destination]/supported-tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const GET: APIRoute = async ({ params, request }) => {
4242
})
4343

4444
const laneDataService = new LaneDataService()
45-
const result = await laneDataService.getSupportedTokensWithRateLimits(environment, source, destination, "chainId")
45+
const result = await laneDataService.getSupportedTokensWithRateLimits(environment, source, destination, "chain_id")
4646

4747
if (!result.data) {
4848
throw new CCIPError(404, `Lane from chain '${source}' to chain '${destination}' not found`)

src/pages/api/ccip/v1/lanes/by-internal-id/[source]/[destination]/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const GET: APIRoute = async ({ params, request }) => {
4242
})
4343

4444
const laneDataService = new LaneDataService()
45-
const result = await laneDataService.getLaneDetails(environment, source, destination, "internalId")
45+
const result = await laneDataService.getLaneDetails(environment, source, destination, "internal_id")
4646

4747
if (!result.data) {
4848
throw new CCIPError(404, `Lane from '${source}' to '${destination}' not found`)

src/pages/api/ccip/v1/lanes/by-internal-id/[source]/[destination]/supported-tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const GET: APIRoute = async ({ params, request }) => {
4646
environment,
4747
source,
4848
destination,
49-
"internalId"
49+
"internal_id"
5050
)
5151

5252
if (!result.data) {

0 commit comments

Comments
 (0)