Skip to content

Commit

Permalink
feat: swagger updates. (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz authored Feb 21, 2024
1 parent 02b1c7a commit 69ce6b5
Show file tree
Hide file tree
Showing 31 changed files with 1,251 additions and 79 deletions.
7 changes: 7 additions & 0 deletions .changeset/clean-kids-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/evm-api': patch
'moralis': patch
---

Updated many endpoints to changes in the EVM API swagger.
3 changes: 2 additions & 1 deletion packages/common/evmUtils/generator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"price_token_address",
"contract_address",
"from_wallet",
"to_wallet"
"to_wallet",
"collection_address"
],
"className": "EvmAddress",
"import": "../../dataTypes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';

// $ref: #/components/schemas/marketDataHottestNFTCollectionByTradingVolume/items
// type: marketDataHottestNFTCollectionByTradingVolume_Item
// properties:
Expand All @@ -9,6 +11,7 @@
// - volume_usd ($ref: #/components/schemas/marketDataHottestNFTCollectionByTradingVolume/items/properties/volume_usd)
// - volume_24hr_percent_change ($ref: #/components/schemas/marketDataHottestNFTCollectionByTradingVolume/items/properties/volume_24hr_percent_change)
// - average_price_usd ($ref: #/components/schemas/marketDataHottestNFTCollectionByTradingVolume/items/properties/average_price_usd)
// - collection_address ($ref: #/components/schemas/marketDataHottestNFTCollectionByTradingVolume/items/properties/collection_address)

export interface EvmMarketDataHottestNFTCollectionByTradingVolumeItemJSON {
readonly rank: number;
Expand All @@ -19,6 +22,7 @@ export interface EvmMarketDataHottestNFTCollectionByTradingVolumeItemJSON {
readonly volume_usd: string;
readonly volume_24hr_percent_change: string;
readonly average_price_usd?: string;
readonly collection_address: EvmAddressJSON;
}

export interface EvmMarketDataHottestNFTCollectionByTradingVolumeItemInput {
Expand All @@ -30,6 +34,7 @@ export interface EvmMarketDataHottestNFTCollectionByTradingVolumeItemInput {
readonly volumeUsd: string;
readonly volume24hrPercentChange: string;
readonly averagePriceUsd?: string;
readonly collectionAddress: EvmAddressInput | EvmAddress;
}

export class EvmMarketDataHottestNFTCollectionByTradingVolumeItem {
Expand All @@ -50,6 +55,7 @@ export class EvmMarketDataHottestNFTCollectionByTradingVolumeItem {
volumeUsd: json.volume_usd,
volume24hrPercentChange: json.volume_24hr_percent_change,
averagePriceUsd: json.average_price_usd,
collectionAddress: EvmAddress.fromJSON(json.collection_address),
};
return EvmMarketDataHottestNFTCollectionByTradingVolumeItem.create(input);
}
Expand Down Expand Up @@ -86,6 +92,10 @@ export class EvmMarketDataHottestNFTCollectionByTradingVolumeItem {
* @description The average price in USD
*/
public readonly averagePriceUsd?: string;
/**
* @description The collection address
*/
public readonly collectionAddress: EvmAddress;

private constructor(input: EvmMarketDataHottestNFTCollectionByTradingVolumeItemInput) {
this.rank = input.rank;
Expand All @@ -96,6 +106,7 @@ export class EvmMarketDataHottestNFTCollectionByTradingVolumeItem {
this.volumeUsd = input.volumeUsd;
this.volume24hrPercentChange = input.volume24hrPercentChange;
this.averagePriceUsd = input.averagePriceUsd;
this.collectionAddress = EvmAddress.create(input.collectionAddress);
}

public toJSON(): EvmMarketDataHottestNFTCollectionByTradingVolumeItemJSON {
Expand All @@ -108,6 +119,7 @@ export class EvmMarketDataHottestNFTCollectionByTradingVolumeItem {
volume_usd: this.volumeUsd,
volume_24hr_percent_change: this.volume24hrPercentChange,
average_price_usd: this.averagePriceUsd,
collection_address: this.collectionAddress.toJSON(),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';

// $ref: #/components/schemas/marketDataTopNFTCollectionByMarketCap/items
// type: marketDataTopNFTCollectionByMarketCap_Item
// properties:
Expand All @@ -10,6 +12,7 @@
// - market_cap_24hr_percent_change ($ref: #/components/schemas/marketDataTopNFTCollectionByMarketCap/items/properties/market_cap_24hr_percent_change)
// - volume_usd ($ref: #/components/schemas/marketDataTopNFTCollectionByMarketCap/items/properties/volume_usd)
// - volume_24hr_percent_change ($ref: #/components/schemas/marketDataTopNFTCollectionByMarketCap/items/properties/volume_24hr_percent_change)
// - collection_address ($ref: #/components/schemas/marketDataTopNFTCollectionByMarketCap/items/properties/collection_address)

export interface EvmMarketDataTopNFTCollectionByMarketCapItemJSON {
readonly rank: number;
Expand All @@ -21,6 +24,7 @@ export interface EvmMarketDataTopNFTCollectionByMarketCapItemJSON {
readonly market_cap_24hr_percent_change: string;
readonly volume_usd: string;
readonly volume_24hr_percent_change: string;
readonly collection_address: EvmAddressJSON;
}

export interface EvmMarketDataTopNFTCollectionByMarketCapItemInput {
Expand All @@ -33,6 +37,7 @@ export interface EvmMarketDataTopNFTCollectionByMarketCapItemInput {
readonly marketCap24hrPercentChange: string;
readonly volumeUsd: string;
readonly volume24hrPercentChange: string;
readonly collectionAddress: EvmAddressInput | EvmAddress;
}

export class EvmMarketDataTopNFTCollectionByMarketCapItem {
Expand All @@ -54,6 +59,7 @@ export class EvmMarketDataTopNFTCollectionByMarketCapItem {
marketCap24hrPercentChange: json.market_cap_24hr_percent_change,
volumeUsd: json.volume_usd,
volume24hrPercentChange: json.volume_24hr_percent_change,
collectionAddress: EvmAddress.fromJSON(json.collection_address),
};
return EvmMarketDataTopNFTCollectionByMarketCapItem.create(input);
}
Expand Down Expand Up @@ -94,6 +100,10 @@ export class EvmMarketDataTopNFTCollectionByMarketCapItem {
* @description The volume 24hr percent change
*/
public readonly volume24hrPercentChange: string;
/**
* @description The collection address
*/
public readonly collectionAddress: EvmAddress;

private constructor(input: EvmMarketDataTopNFTCollectionByMarketCapItemInput) {
this.rank = input.rank;
Expand All @@ -105,6 +115,7 @@ export class EvmMarketDataTopNFTCollectionByMarketCapItem {
this.marketCap24hrPercentChange = input.marketCap24hrPercentChange;
this.volumeUsd = input.volumeUsd;
this.volume24hrPercentChange = input.volume24hrPercentChange;
this.collectionAddress = EvmAddress.create(input.collectionAddress);
}

public toJSON(): EvmMarketDataTopNFTCollectionByMarketCapItemJSON {
Expand All @@ -118,6 +129,7 @@ export class EvmMarketDataTopNFTCollectionByMarketCapItem {
market_cap_24hr_percent_change: this.marketCap24hrPercentChange,
volume_usd: this.volumeUsd,
volume_24hr_percent_change: this.volume24hrPercentChange,
collection_address: this.collectionAddress.toJSON(),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('getContractEventsOperation', () => {
offset: 0,
topic: 'topic0',
cursor: '0xCURSOR',
order: 'ASC',
};

const serializedRequest = getContractEventsOperation.serializeRequest(request, core);
Expand All @@ -48,6 +49,7 @@ describe('getContractEventsOperation', () => {
expect(serializedRequest.toDate).toBe(toDate);
expect(serializedRequest.abi).toBe(request.abi);
expect(serializedRequest.cursor).toBe(request.cursor);
expect(serializedRequest.order).toBe(request.order);

const deserializedRequest = getContractEventsOperation.deserializeRequest(serializedRequest, core);

Expand All @@ -61,5 +63,6 @@ describe('getContractEventsOperation', () => {
expect(deserializedRequest.topic).toBe(request.topic);
expect(deserializedRequest.abi).toBe(request.abi);
expect(deserializedRequest.cursor).toBe(request.cursor);
expect(deserializedRequest.order).toBe(request.order);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,18 @@ export const getContractEventsOperation: PaginatedOperation<
groupName: 'events',
urlPathPattern: '/{address}/events',
urlPathParamNames: ['address'],
urlSearchParamNames: ['chain', 'fromBlock', 'toBlock', 'fromDate', 'toDate', 'topic', 'offset', 'limit', 'cursor'],
urlSearchParamNames: [
'chain',
'fromBlock',
'toBlock',
'fromDate',
'toDate',
'topic',
'offset',
'limit',
'cursor',
'order',
],
bodyParamNames: ['abi'],
bodyType: 'raw',
firstPageIndex: 0,
Expand All @@ -78,6 +89,7 @@ function getRequestUrlParams(request: GetContractEventsRequest, core: Core) {
limit: maybe(request.limit, String),
address: EvmAddress.create(request.address).lowercase,
cursor: request.cursor,
order: request.order,
};
}

Expand Down Expand Up @@ -120,6 +132,7 @@ function serializeRequest(request: GetContractEventsRequest, core: Core) {
address: EvmAddress.create(request.address).lowercase,
abi: request.abi,
cursor: request.cursor,
order: request.order,
};
}

Expand All @@ -136,5 +149,6 @@ function deserializeRequest(jsonRequest: GetContractEventsJSONRequest): GetContr
address: EvmAddress.create(jsonRequest.address),
abi: jsonRequest.abi,
cursor: jsonRequest.cursor,
order: jsonRequest.order,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('getContractLogsOperation', () => {
topic0: 'topic0',
blockNumber: '123',
cursor: 'cursor',
order: 'ASC',
};

const serializedRequest = getContractLogsOperation.serializeRequest(request, core);
Expand All @@ -40,6 +41,7 @@ describe('getContractLogsOperation', () => {
expect(serializedRequest.toDate).toBe(toDate);
expect(serializedRequest.cursor).toBe(request.cursor);
expect(serializedRequest.fromBlock).toBe(request.fromBlock);
expect(serializedRequest.order).toBe(request.order);

const deserializedRequest = getContractLogsOperation.deserializeRequest(serializedRequest, core);

Expand All @@ -53,5 +55,6 @@ describe('getContractLogsOperation', () => {
expect(deserializedRequest.topic0).toBe(request.topic0);
expect(deserializedRequest.blockNumber).toBe(request.blockNumber);
expect(deserializedRequest.fromBlock).toBe(request.fromBlock);
expect(deserializedRequest.order).toBe(request.order);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const getContractLogsOperation: PaginatedOperation<
'topic0',
'limit',
'cursor',
'order',
],
firstPageIndex: 0,

Expand All @@ -84,6 +85,7 @@ function getRequestUrlParams(request: GetContractLogsRequest, core: Core) {
limit: maybe(request.limit, String),
cursor: request.cursor,
address: EvmAddress.create(request.address).lowercase,
order: request.order,
};
}

Expand All @@ -99,6 +101,7 @@ function serializeRequest(request: GetContractLogsRequest, core: Core) {
limit: request.limit,
cursor: request.cursor,
address: EvmAddress.create(request.address).lowercase,
order: request.order,
};
}

Expand All @@ -114,6 +117,7 @@ function deserializeRequest(jsonRequest: GetContractLogsJSONRequest): GetContrac
limit: jsonRequest.limit,
cursor: jsonRequest.cursor,
address: EvmAddress.create(jsonRequest.address),
order: jsonRequest.order,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('getNftContractTransfersOperation', () => {
toBlock: 16225608,
toDate: new Date(toDate),
fromDate: new Date(fromDate),
order: 'ASC',
};

const serializedRequest = getNFTContractTransfersOperation.serializeRequest(request, core);
Expand All @@ -37,6 +38,7 @@ describe('getNftContractTransfersOperation', () => {
expect(serializedRequest.toBlock).toBe(request.toBlock);
expect(serializedRequest.fromDate).toBe(fromDate);
expect(serializedRequest.toDate).toBe(toDate);
expect(serializedRequest.order).toBe(request.order);

const deserializedRequest = getNFTContractTransfersOperation.deserializeRequest(serializedRequest, core);

Expand All @@ -47,6 +49,7 @@ describe('getNftContractTransfersOperation', () => {
expect(deserializedRequest.cursor).toBe(request.cursor);
expect(deserializedRequest.fromBlock).toBe(request.fromBlock);
expect(deserializedRequest.toBlock).toBe(request.toBlock);
expect(deserializedRequest.order).toBe(request.order);
expect((deserializedRequest.fromDate as Date | undefined)?.toISOString()).toBe(fromDate);
expect((deserializedRequest.toDate as Date | undefined)?.toISOString()).toBe(toDate);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const getNFTContractTransfersOperation: PaginatedOperation<
groupName: 'nft',
urlPathPattern: '/nft/{address}/transfers',
urlPathParamNames: ['address'],
urlSearchParamNames: ['chain', 'format', 'limit', 'cursor', 'fromBlock', 'fromDate', 'toBlock', 'toDate'],
urlSearchParamNames: ['chain', 'format', 'limit', 'cursor', 'fromBlock', 'fromDate', 'toBlock', 'toDate', 'order'],
firstPageIndex: 0,
getRequestUrlParams,
serializeRequest,
Expand All @@ -72,6 +72,7 @@ function getRequestUrlParams(request: GetNFTContractTransfersRequest, core: Core
to_block: maybe(request.toBlock, String),
to_date: request.toDate ? new Date(request.toDate).toISOString() : undefined,
cursor: request.cursor,
order: request.order,
};
}

Expand Down Expand Up @@ -105,6 +106,7 @@ function serializeRequest(request: GetNFTContractTransfersRequest, core: Core) {
toBlock: request.toBlock,
fromDate: request.fromDate ? new Date(request.fromDate).toISOString() : undefined,
toDate: request.toDate ? new Date(request.toDate).toISOString() : undefined,
order: request.order,
};
}

Expand All @@ -119,5 +121,6 @@ function deserializeRequest(jsonRequest: GetNFTContractTransfersJSONRequest): Ge
toBlock: jsonRequest.toBlock,
fromDate: jsonRequest.fromDate ? new Date(jsonRequest.fromDate) : undefined,
toDate: jsonRequest.toDate ? new Date(jsonRequest.toDate) : undefined,
order: jsonRequest.order,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('getNFTTransfersByBlockOperation', () => {
blockNumberOrHash: '0x123',
limit: 100,
cursor: 'CURSOR1',
order: 'ASC',
};

const serializedRequest = getNFTTransfersByBlockOperation.serializeRequest(request, core);
Expand All @@ -25,12 +26,14 @@ describe('getNFTTransfersByBlockOperation', () => {
expect(serializedRequest.blockNumberOrHash).toBe(request.blockNumberOrHash);
expect(serializedRequest.limit).toBe(request.limit);
expect(serializedRequest.cursor).toBe(request.cursor);
expect(serializedRequest.order).toBe(request.order);

const deserializedRequest = getNFTTransfersByBlockOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.chain as EvmChain).apiHex).toBe(chain);
expect(deserializedRequest.blockNumberOrHash).toBe(request.blockNumberOrHash);
expect(deserializedRequest.limit).toBe(request.limit);
expect(deserializedRequest.cursor).toBe(request.cursor);
expect(deserializedRequest.order).toBe(request.order);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const getNFTTransfersByBlockOperation: PaginatedOperation<
groupName: 'nft',
urlPathPattern: '/block/{blockNumberOrHash}/nft/transfers',
urlPathParamNames: ['blockNumberOrHash'],
urlSearchParamNames: ['chain', 'limit', 'cursor'],
urlSearchParamNames: ['chain', 'limit', 'cursor', 'order'],
firstPageIndex: 0,

getRequestUrlParams,
Expand All @@ -63,6 +63,7 @@ function getRequestUrlParams(request: GetNFTTransfersByBlockRequest, core: Core)
limit: maybe(request.limit, String),
cursor: request.cursor,
blockNumberOrHash: request.blockNumberOrHash,
order: request.order,
};
}

Expand Down Expand Up @@ -91,6 +92,7 @@ function serializeRequest(request: GetNFTTransfersByBlockRequest, core: Core) {
limit: request.limit,
cursor: request.cursor,
blockNumberOrHash: request.blockNumberOrHash,
order: request.order,
};
}

Expand All @@ -100,5 +102,6 @@ function deserializeRequest(jsonRequest: GetNFTTransfersByBlockJSONRequest): Get
limit: jsonRequest.limit,
cursor: jsonRequest.cursor,
blockNumberOrHash: jsonRequest.blockNumberOrHash,
order: jsonRequest.order,
};
}
Loading

1 comment on commit 69ce6b5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 20%
20.6% (61/296) 20.48% (17/83) 19.04% (12/63)
auth Coverage: 89%
92.45% (98/106) 83.33% (20/24) 86.66% (26/30)
evm-api Coverage: 90%
90.9% (90/99) 66.66% (6/9) 86.15% (56/65)
common-aptos-utils Coverage: 4%
4.56% (151/3306) 4.49% (25/556) 5.53% (45/813)
common-evm-utils Coverage: 64%
64.46% (1702/2640) 24.8% (194/782) 43.45% (428/985)
sol-api Coverage: 97%
97.56% (40/41) 66.66% (6/9) 93.75% (15/16)
common-sol-utils Coverage: 64%
65.42% (229/350) 41.86% (18/43) 50.89% (57/112)
common-streams-utils Coverage: 90%
90.73% (1204/1327) 73.63% (363/493) 82.07% (444/541)
streams Coverage: 91%
90.54% (603/666) 72.34% (68/94) 90.97% (131/144)

Please sign in to comment.