Skip to content

Commit

Permalink
feat: resolveENSDomain.
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz committed Apr 4, 2023
1 parent d2edf67 commit 8caf913
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/dry-zebras-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/evm-api': patch
---

Added `resolveENSDomain` method to the EvmApi module.
29 changes: 28 additions & 1 deletion packages/common/evmUtils/src/operations/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ export interface paths {
/** Resolve a specific Unstoppable domain to its address. */
get: operations["resolveDomain"];
};
"/resolve/ens/{domain}": {
/** Resolve a specific ENS domain to its address. */
get: operations["resolveENSDomain"];
};
"/{pair_address}/reserves": {
/** Get the liquidity reserves for a given pair address. Only Uniswap V2 based exchanges supported at the moment. */
get: operations["getPairReserves"];
Expand Down Expand Up @@ -1318,7 +1322,7 @@ export interface components {
};
/**
* @default
* @example internal_transactions
* @example
* @enum {string}
*/
includeList: "internal_transactions";
Expand Down Expand Up @@ -3834,6 +3838,29 @@ export interface operations {
};
};
};
/** Resolve a specific ENS domain to its address. */
resolveENSDomain: {
parameters: {
path: {
/** The domain to be resolved */
domain: string;
};
};
responses: {
/** Returns an address */
200: {
content: {
"application/json": components["schemas"]["resolve"];
};
};
/** Returns an address */
404: {
content: {
"application/json": { [key: string]: unknown };
};
};
};
};
/** Get the liquidity reserves for a given pair address. Only Uniswap V2 based exchanges supported at the moment. */
getPairReserves: {
parameters: {
Expand Down
3 changes: 2 additions & 1 deletion packages/common/evmUtils/src/operations/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
searchNFTsOperation,
syncNFTContractOperation,
} from './nft';
import { resolveAddressOperation, resolveDomainOperation } from './resolve';
import { resolveAddressOperation, resolveDomainOperation, resolveENSDomainOperation } from './resolve';
import {
getTokenAllowanceOperation,
getTokenMetadataBySymbolOperation,
Expand Down Expand Up @@ -89,6 +89,7 @@ export const operations = [
getWalletTransactionsVerboseOperation,
resolveAddressOperation,
resolveDomainOperation,
resolveENSDomainOperation,
reSyncMetadataOperation,
runContractFunctionOperation,
searchNFTsOperation,
Expand Down
1 change: 1 addition & 0 deletions packages/common/evmUtils/src/operations/resolve/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './resolveAddressOperation';
export * from './resolveDomainOperation';
export * from './resolveENSDomainOperation';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import MoralisCore from '@moralisweb3/common-core';
import { resolveENSDomainOperation, ResolveENSDomainJSONRequest } from './resolveENSDomainOperation';

describe('resolveENSDomainOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const request: Required<ResolveENSDomainJSONRequest> = {
domain: 'nick.eth',
};

const serializedRequest = resolveENSDomainOperation.serializeRequest(request, core);

expect(serializedRequest.domain).toBe(request.domain);

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

expect(deserializedRequest.domain).toBe(request.domain);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Core, { Camelize, Operation, ResponseAdapter } from '@moralisweb3/common-core';
import { EvmAddress } from '../../dataTypes';

import { operations } from '../openapi';

type OperationId = 'resolveENSDomain';

type PathParams = operations[OperationId]['parameters']['path'];
type RequestParams = PathParams;

type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json'];

// Exports

export interface ResolveENSDomainRequest extends Camelize<RequestParams> {}

export type ResolveENSDomainJSONRequest = ReturnType<typeof serializeRequest>;

export type ResolveENSDomainJSONResponse = SuccessResponse;

export type ResolveENSDomainResponse = ReturnType<typeof deserializeResponse>;

export interface ResolveENSDomainResponseAdapter
extends ResponseAdapter<ResolveENSDomainResponse, ResolveENSDomainJSONResponse> {}

/** Resolve a specific ENS domain to its address. */
export const resolveENSDomainOperation: Operation<
ResolveENSDomainRequest,
ResolveENSDomainJSONRequest,
ResolveENSDomainResponse,
ResolveENSDomainJSONResponse
> = {
method: 'GET',
name: 'resolveENSDomain',
id: 'resolveENSDomain',
groupName: 'resolve',
isNullable: true,
urlPathPattern: '/resolve/ens/{domain}',
urlPathParamNames: ['domain'],

getRequestUrlParams,
serializeRequest,
deserializeRequest,
deserializeResponse,
};

// Methods

function getRequestUrlParams(request: ResolveENSDomainRequest) {
return {
domain: request.domain,
};
}

function serializeRequest(request: ResolveENSDomainRequest) {
return {
domain: request.domain,
};
}

function deserializeRequest(jsonRequest: ResolveENSDomainJSONRequest): ResolveENSDomainRequest {
return {
domain: jsonRequest.domain,
};
}

function deserializeResponse(jsonResponse: ResolveENSDomainJSONResponse, _: ResolveENSDomainRequest, core: Core) {
return {
address: EvmAddress.create(jsonResponse.address, core),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const mockResolveDomain = MockScenarios.create(
url: '/resolve/:domain',
getParams: ({ req }) => ({
domain: req.params.domain,
currency: req.url.searchParams.get('currency'),
}),
},
[
Expand Down
30 changes: 30 additions & 0 deletions packages/evmApi/integration/mocks/endpoints/resolveENSDomain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MockScenarios } from '@moralisweb3/test-utils';
import { createErrorResponse } from '../response/errorResponse';

export const mockResolveENSDomain = MockScenarios.create(
{
name: 'mockResolveENSDomain',
method: 'get',
url: '/resolve/ens/:domain',
getParams: ({ req }) => ({
domain: req.params.domain,
}),
},
[
{
condition: {
domain: 'nick.eth',
},
response: {
address: '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5',
},
},
{
condition: {
domain: 'unknown.eth',
},
responseStatus: 404,
response: createErrorResponse('null'),
},
],
);
2 changes: 2 additions & 0 deletions packages/evmApi/integration/mocks/mockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { mockGetInternalTransaction } from './endpoints/getInternalTransactions'
import { mockGetTransactionVerbose } from './endpoints/getTransactionVerbose';
import { mockGetErc20Approvals } from './endpoints/getErc20Approvals';
import { mockGetErc20Burns } from './endpoints/getErc20Burns';
import { mockResolveENSDomain } from './endpoints/resolveENSDomain';

const handler = [
mockGetDateToBlock,
Expand All @@ -72,6 +73,7 @@ const handler = [
mockGetWalletTokenTransfers,
mockResolveAddress,
mockResolveDomain,
mockResolveENSDomain,
mockGetPairAddress,
mockGetPairReserves,
mockRunContractFunction,
Expand Down
30 changes: 30 additions & 0 deletions packages/evmApi/integration/test/resolveENSDomain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { EvmApi } from '../../src/EvmApi';
import { cleanEvmApi, setupEvmApi } from '../setup';

describe('resolveENSDomain', () => {
let evmApi: EvmApi;

beforeAll(() => {
evmApi = setupEvmApi();
});

afterAll(() => {
cleanEvmApi();
});

it('returns an address', async () => {
const result = await evmApi.resolve.resolveENSDomain({
domain: 'nick.eth',
});

expect(result?.result.address.checksum).toEqual('0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5');
});

it('returns null when API returns HTTP 404', async () => {
const result = await evmApi.resolve.resolveENSDomain({
domain: 'unknown.eth',
});

expect(result).toBeNull();
});
});
5 changes: 4 additions & 1 deletion packages/evmApi/src/generated/ClientEvmApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// CAUTION: This file is automatically generated. Do not edit it manually!
import { endpointWeightsOperation, EndpointWeightsResponseAdapter, runContractFunctionOperation, RunContractFunctionRequest, RunContractFunctionResponseAdapter, web3ApiVersionOperation, Web3ApiVersionResponseAdapter, getBlockOperation, GetBlockRequest, GetBlockResponseAdapter, getDateToBlockOperation, GetDateToBlockRequest, GetDateToBlockResponseAdapter, getContractEventsOperation, GetContractEventsRequest, GetContractEventsResponseAdapter, getContractLogsOperation, GetContractLogsRequest, GetContractLogsResponseAdapter, getContractNFTsOperation, GetContractNFTsRequest, GetContractNFTsResponseAdapter, getMultipleNFTsOperation, GetMultipleNFTsRequest, GetMultipleNFTsResponseAdapter, getNFTContractMetadataOperation, GetNFTContractMetadataRequest, GetNFTContractMetadataResponseAdapter, getNFTContractTransfersOperation, GetNFTContractTransfersRequest, GetNFTContractTransfersResponseAdapter, getNFTLowestPriceOperation, GetNFTLowestPriceRequest, GetNFTLowestPriceResponseAdapter, getNFTMetadataOperation, GetNFTMetadataRequest, GetNFTMetadataResponseAdapter, getNFTOwnersOperation, GetNFTOwnersRequest, GetNFTOwnersResponseAdapter, getNFTTokenIdOwnersOperation, GetNFTTokenIdOwnersRequest, GetNFTTokenIdOwnersResponseAdapter, getNFTTradesOperation, GetNFTTradesRequest, GetNFTTradesResponseAdapter, getNFTTransfersByBlockOperation, GetNFTTransfersByBlockRequest, GetNFTTransfersByBlockResponseAdapter, getNFTTransfersFromToBlockOperation, GetNFTTransfersFromToBlockRequest, GetNFTTransfersFromToBlockResponseAdapter, getNFTTransfersOperation, GetNFTTransfersRequest, GetNFTTransfersResponseAdapter, getWalletNFTCollectionsOperation, GetWalletNFTCollectionsRequest, GetWalletNFTCollectionsResponseAdapter, getWalletNFTsOperation, GetWalletNFTsRequest, GetWalletNFTsResponseAdapter, getWalletNFTTransfersOperation, GetWalletNFTTransfersRequest, GetWalletNFTTransfersResponseAdapter, reSyncMetadataOperation, ReSyncMetadataRequest, ReSyncMetadataResponseAdapter, searchNFTsOperation, SearchNFTsRequest, SearchNFTsResponseAdapter, syncNFTContractOperation, SyncNFTContractRequest, SyncNFTContractResponseAdapter, getErc20ApprovalsOperation, GetErc20ApprovalsRequest, GetErc20ApprovalsResponseAdapter, getErc20BurnsOperation, GetErc20BurnsRequest, GetErc20BurnsResponseAdapter, getErc20TransfersOperation, GetErc20TransfersRequest, GetErc20TransfersResponseAdapter, getErc20MintsOperation, GetErc20MintsRequest, GetErc20MintsResponseAdapter, getTokenAllowanceOperation, GetTokenAllowanceRequest, GetTokenAllowanceResponseAdapter, getTokenMetadataBySymbolOperation, GetTokenMetadataBySymbolRequest, GetTokenMetadataBySymbolResponseAdapter, getTokenMetadataOperation, GetTokenMetadataRequest, GetTokenMetadataResponseAdapter, getTokenPriceOperation, GetTokenPriceRequest, GetTokenPriceResponseAdapter, getTokenTransfersOperation, GetTokenTransfersRequest, GetTokenTransfersResponseAdapter, getWalletTokenBalancesOperation, GetWalletTokenBalancesRequest, GetWalletTokenBalancesResponseAdapter, getWalletTokenTransfersOperation, GetWalletTokenTransfersRequest, GetWalletTokenTransfersResponseAdapter, getInternalTransactionsOperation, GetInternalTransactionsRequest, GetInternalTransactionsResponseAdapter, getTransactionOperation, GetTransactionRequest, GetTransactionResponseAdapter, getTransactionVerboseOperation, GetTransactionVerboseRequest, GetTransactionVerboseResponseAdapter, getWalletTransactionsOperation, GetWalletTransactionsRequest, GetWalletTransactionsResponseAdapter, getWalletTransactionsVerboseOperation, GetWalletTransactionsVerboseRequest, GetWalletTransactionsVerboseResponseAdapter, getNativeBalanceOperation, GetNativeBalanceRequest, GetNativeBalanceResponseAdapter, getNativeBalancesForAddressesOperation, GetNativeBalancesForAddressesRequest, GetNativeBalancesForAddressesResponseAdapter, getPairAddressOperation, GetPairAddressRequest, GetPairAddressResponseAdapter, getPairReservesOperation, GetPairReservesRequest, GetPairReservesResponseAdapter, resolveAddressOperation, ResolveAddressRequest, ResolveAddressResponseAdapter, resolveDomainOperation, ResolveDomainRequest, ResolveDomainResponseAdapter, uploadFolderOperation, UploadFolderRequest, UploadFolderResponseAdapter } from '@moralisweb3/common-evm-utils';
import { endpointWeightsOperation, EndpointWeightsResponseAdapter, runContractFunctionOperation, RunContractFunctionRequest, RunContractFunctionResponseAdapter, web3ApiVersionOperation, Web3ApiVersionResponseAdapter, getBlockOperation, GetBlockRequest, GetBlockResponseAdapter, getDateToBlockOperation, GetDateToBlockRequest, GetDateToBlockResponseAdapter, getContractEventsOperation, GetContractEventsRequest, GetContractEventsResponseAdapter, getContractLogsOperation, GetContractLogsRequest, GetContractLogsResponseAdapter, getContractNFTsOperation, GetContractNFTsRequest, GetContractNFTsResponseAdapter, getMultipleNFTsOperation, GetMultipleNFTsRequest, GetMultipleNFTsResponseAdapter, getNFTContractMetadataOperation, GetNFTContractMetadataRequest, GetNFTContractMetadataResponseAdapter, getNFTContractTransfersOperation, GetNFTContractTransfersRequest, GetNFTContractTransfersResponseAdapter, getNFTLowestPriceOperation, GetNFTLowestPriceRequest, GetNFTLowestPriceResponseAdapter, getNFTMetadataOperation, GetNFTMetadataRequest, GetNFTMetadataResponseAdapter, getNFTOwnersOperation, GetNFTOwnersRequest, GetNFTOwnersResponseAdapter, getNFTTokenIdOwnersOperation, GetNFTTokenIdOwnersRequest, GetNFTTokenIdOwnersResponseAdapter, getNFTTradesOperation, GetNFTTradesRequest, GetNFTTradesResponseAdapter, getNFTTransfersByBlockOperation, GetNFTTransfersByBlockRequest, GetNFTTransfersByBlockResponseAdapter, getNFTTransfersFromToBlockOperation, GetNFTTransfersFromToBlockRequest, GetNFTTransfersFromToBlockResponseAdapter, getNFTTransfersOperation, GetNFTTransfersRequest, GetNFTTransfersResponseAdapter, getWalletNFTCollectionsOperation, GetWalletNFTCollectionsRequest, GetWalletNFTCollectionsResponseAdapter, getWalletNFTsOperation, GetWalletNFTsRequest, GetWalletNFTsResponseAdapter, getWalletNFTTransfersOperation, GetWalletNFTTransfersRequest, GetWalletNFTTransfersResponseAdapter, reSyncMetadataOperation, ReSyncMetadataRequest, ReSyncMetadataResponseAdapter, searchNFTsOperation, SearchNFTsRequest, SearchNFTsResponseAdapter, syncNFTContractOperation, SyncNFTContractRequest, SyncNFTContractResponseAdapter, getErc20ApprovalsOperation, GetErc20ApprovalsRequest, GetErc20ApprovalsResponseAdapter, getErc20BurnsOperation, GetErc20BurnsRequest, GetErc20BurnsResponseAdapter, getErc20TransfersOperation, GetErc20TransfersRequest, GetErc20TransfersResponseAdapter, getErc20MintsOperation, GetErc20MintsRequest, GetErc20MintsResponseAdapter, getTokenAllowanceOperation, GetTokenAllowanceRequest, GetTokenAllowanceResponseAdapter, getTokenMetadataBySymbolOperation, GetTokenMetadataBySymbolRequest, GetTokenMetadataBySymbolResponseAdapter, getTokenMetadataOperation, GetTokenMetadataRequest, GetTokenMetadataResponseAdapter, getTokenPriceOperation, GetTokenPriceRequest, GetTokenPriceResponseAdapter, getTokenTransfersOperation, GetTokenTransfersRequest, GetTokenTransfersResponseAdapter, getWalletTokenBalancesOperation, GetWalletTokenBalancesRequest, GetWalletTokenBalancesResponseAdapter, getWalletTokenTransfersOperation, GetWalletTokenTransfersRequest, GetWalletTokenTransfersResponseAdapter, getInternalTransactionsOperation, GetInternalTransactionsRequest, GetInternalTransactionsResponseAdapter, getTransactionOperation, GetTransactionRequest, GetTransactionResponseAdapter, getTransactionVerboseOperation, GetTransactionVerboseRequest, GetTransactionVerboseResponseAdapter, getWalletTransactionsOperation, GetWalletTransactionsRequest, GetWalletTransactionsResponseAdapter, getWalletTransactionsVerboseOperation, GetWalletTransactionsVerboseRequest, GetWalletTransactionsVerboseResponseAdapter, getNativeBalanceOperation, GetNativeBalanceRequest, GetNativeBalanceResponseAdapter, getNativeBalancesForAddressesOperation, GetNativeBalancesForAddressesRequest, GetNativeBalancesForAddressesResponseAdapter, getPairAddressOperation, GetPairAddressRequest, GetPairAddressResponseAdapter, getPairReservesOperation, GetPairReservesRequest, GetPairReservesResponseAdapter, resolveAddressOperation, ResolveAddressRequest, ResolveAddressResponseAdapter, resolveDomainOperation, ResolveDomainRequest, ResolveDomainResponseAdapter, resolveENSDomainOperation, ResolveENSDomainRequest, ResolveENSDomainResponseAdapter, uploadFolderOperation, UploadFolderRequest, UploadFolderResponseAdapter } from '@moralisweb3/common-evm-utils';
import { OperationResolver, NullableOperationResolver, PaginatedOperationResolver } from '@moralisweb3/api-utils';
import { ApiModule, } from '@moralisweb3/common-core';
export abstract class ClientEvmApi extends ApiModule {
Expand Down Expand Up @@ -179,6 +179,9 @@ export abstract class ClientEvmApi extends ApiModule {
resolveDomain: (request: ResolveDomainRequest): Promise<ResolveDomainResponseAdapter | null> => {
return new NullableOperationResolver(resolveDomainOperation, this.baseUrl, this.core).fetch(request);
},
resolveENSDomain: (request: ResolveENSDomainRequest): Promise<ResolveENSDomainResponseAdapter | null> => {
return new NullableOperationResolver(resolveENSDomainOperation, this.baseUrl, this.core).fetch(request);
},

};

Expand Down

1 comment on commit 8caf913

@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: 30%
30.34% (61/201) 30.35% (17/56) 30.76% (12/39)
auth Coverage: 89%
92.38% (97/105) 83.33% (20/24) 86.2% (25/29)
evm-api Coverage: 100%
100% (89/89) 66.66% (6/9) 100% (57/57)
common-aptos-utils Coverage: 4%
4.87% (149/3056) 5.47% (25/457) 5.66% (45/794)
common-evm-utils Coverage: 70%
71.15% (1423/2000) 32.04% (314/980) 48.28% (393/814)
sol-api Coverage: 96%
96.66% (29/30) 66.66% (6/9) 91.66% (11/12)
common-sol-utils Coverage: 74%
74.55% (167/224) 66.66% (18/27) 65.38% (51/78)
common-streams-utils Coverage: 91%
91.42% (1184/1295) 77.57% (415/535) 82.08% (426/519)
streams Coverage: 88%
88.19% (575/652) 68.81% (64/93) 87.94% (124/141)

Please sign in to comment.