From e6f010daa14ecb2f98c29b84f6439dac186281a0 Mon Sep 17 00:00:00 2001 From: deep-quality-dev Date: Wed, 16 Nov 2022 08:36:52 -0500 Subject: [PATCH 1/3] Rebase from main --- .../actions/getDomainResourceAssociations.ts | 20 +++++++++++ .../actions/getResourceRegistry.ts | 20 +++++++++++ src/api/dataStoreApi/actions/index.ts | 2 ++ src/api/dataStoreApi/client.ts | 34 +++++++++++++++++-- .../helpers/datastoreDomainToDomain.ts | 1 + src/api/dataStoreApi/types.ts | 14 ++++++++ src/index.ts | 18 ++++++++-- src/types.ts | 18 ++++++++++ 8 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 src/api/dataStoreApi/actions/getDomainResourceAssociations.ts create mode 100644 src/api/dataStoreApi/actions/getResourceRegistry.ts diff --git a/src/api/dataStoreApi/actions/getDomainResourceAssociations.ts b/src/api/dataStoreApi/actions/getDomainResourceAssociations.ts new file mode 100644 index 0000000..c10ab92 --- /dev/null +++ b/src/api/dataStoreApi/actions/getDomainResourceAssociations.ts @@ -0,0 +1,20 @@ +import { Maybe } from "../../../types"; +import { ResourceAssociation } from "../types"; +import { makeApiCall } from "../../helpers"; + +export const getDomainResourceAssociations = async ( + apiUri: string, + domainId: string +): Promise => { + let response: Maybe; + try { + response = await makeApiCall( + `${apiUri}v1/domains/resource/${domainId}`, + "GET" + ); + } catch (e) { + throw Error(`Failed to get domain resource associations: ${domainId}`); + } + + return response; +}; diff --git a/src/api/dataStoreApi/actions/getResourceRegistry.ts b/src/api/dataStoreApi/actions/getResourceRegistry.ts new file mode 100644 index 0000000..93e0ef9 --- /dev/null +++ b/src/api/dataStoreApi/actions/getResourceRegistry.ts @@ -0,0 +1,20 @@ +import { Maybe } from "../../../types"; +import { ResourceRegistry } from "../types"; +import { makeApiCall } from "../../helpers"; + +export const getResourceRegistry = async ( + apiUri: string, + resourceType: string +): Promise> => { + let response: Maybe; + try { + response = await makeApiCall( + `${apiUri}v1/resource-registry/get/${resourceType}`, + "GET" + ); + } catch (e) { + throw Error(`Failed to get resource registry: ${resourceType}`); + } + + return response; +}; diff --git a/src/api/dataStoreApi/actions/index.ts b/src/api/dataStoreApi/actions/index.ts index e70f3e8..9bb722b 100644 --- a/src/api/dataStoreApi/actions/index.ts +++ b/src/api/dataStoreApi/actions/index.ts @@ -3,3 +3,5 @@ export * from "./getMostRecentSubdomainsById"; export * from "./getDomainsByOwner"; export * from "./getDomainById"; export * from "./getSubdomainsByIdDeep"; +export * from "./getDomainResourceAssociations"; +export * from "./getResourceRegistry"; diff --git a/src/api/dataStoreApi/client.ts b/src/api/dataStoreApi/client.ts index 3fc89c6..2e985f6 100644 --- a/src/api/dataStoreApi/client.ts +++ b/src/api/dataStoreApi/client.ts @@ -1,7 +1,11 @@ -import { Domain } from "../../types"; +import { Domain, Maybe } from "../../types"; import * as actions from "./actions"; import { getLogger } from "../../utilities"; -import { DomainSortOptions } from "./types"; +import { + DomainSortOptions, + ResourceAssociation, + ResourceRegistry +} from "./types"; const logger = getLogger("api:client"); @@ -30,6 +34,12 @@ export interface DataStoreApiClient { limit: number, skip: number ) => Promise; + getDomainResourceAssociations: ( + domainId: string + ) => Promise; + getResourceRegistry: ( + resourceType: string + ) => Promise>; } export const createDataStoreApiClient = ( @@ -109,6 +119,26 @@ export const createDataStoreApiClient = ( return domains; }, + + getDomainResourceAssociations: async ( + domainId: string + ): Promise => { + logger.debug("Calling to getDomainResourceAssociations"); + const resourceAssociations: ResourceAssociation[] = + await actions.getDomainResourceAssociations(apiUri, domainId); + + return resourceAssociations; + }, + + getResourceRegistry: async ( + resourceType: string + ): Promise> => { + logger.debug("Calling to getResourceRegistry"); + const resourceRegistry: Maybe = + await actions.getResourceRegistry(apiUri, resourceType); + + return resourceRegistry; + }, }; return apiClient; diff --git a/src/api/dataStoreApi/helpers/datastoreDomainToDomain.ts b/src/api/dataStoreApi/helpers/datastoreDomainToDomain.ts index c893620..264c8b5 100644 --- a/src/api/dataStoreApi/helpers/datastoreDomainToDomain.ts +++ b/src/api/dataStoreApi/helpers/datastoreDomainToDomain.ts @@ -22,6 +22,7 @@ export function datastoreDomainToDomain(d: DataStoreDomain): Domain { contract: d.registrar.toLowerCase(), isRoot: d.isRoot, buyNow: buyNow, + resources: d.resources, }; return domain; } diff --git a/src/api/dataStoreApi/types.ts b/src/api/dataStoreApi/types.ts index eb35919..9ee96b5 100644 --- a/src/api/dataStoreApi/types.ts +++ b/src/api/dataStoreApi/types.ts @@ -37,6 +37,7 @@ export interface DataStoreDomain { buyNow: BuyNow; locked: boolean; // Older domains may not have these properties lockedBy: string; + resources: MappingResourceAssociations; } export interface BuyNowPriceListing { @@ -50,6 +51,19 @@ export interface BuyNow { isActive: boolean; } +export interface ResourceRegistry { + resourceType: string; + resourceRegistry: string; +} + +export interface ResourceAssociation extends ResourceRegistry { + resourceId: string; +} + +export interface MappingResourceAssociations { + [resourceType: string]: ResourceAssociation; +} + type Show = 1; type Hide = 0; type OptionsValue = Show | Hide; diff --git a/src/index.ts b/src/index.ts index 03f626c..a911371 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,7 +46,11 @@ import { DomainPurchaserConfig, NetworkDomainMintableConfig, } from "./actions/minting/types"; -import { DomainSortOptions } from "./api/dataStoreApi/types"; +import { + DomainSortOptions, + ResourceAssociation, + ResourceRegistry, +} from "./api/dataStoreApi/types"; export * from "./types"; export { configuration }; @@ -182,6 +186,16 @@ export const createInstance = (config: Config): Instance => { getAllDomains: subgraphClient.getAllDomains, getDomainMetrics: async (domainIds: string[]) => getDomainMetrics(config.metricsUri, domainIds), + getDomainResourceAssociations: async ( + domainId: string + ): Promise => { + return await dataStoreApiClient.getDomainResourceAssociations(domainId); + }, + getResourceRegistry: async ( + resourceType: string + ): Promise> => { + return await dataStoreApiClient.getResourceRegistry(resourceType); + }, mintSubdomain: async ( params: SubdomainParams, signer: ethers.Signer, @@ -672,7 +686,7 @@ export const createInstance = (config: Config): Instance => { tokenAddress ); - let approvalAmount = amount ?? ethers.constants.MaxUint256; + const approvalAmount = amount ?? ethers.constants.MaxUint256; const tx = await paymentToken .connect(signer) diff --git a/src/types.ts b/src/types.ts index ab8a201..3f8dcfc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,6 +4,9 @@ import { Bid, BuyNowListing } from "./zAuction"; import { BuyNowPriceListing, DomainSortOptions, + MappingResourceAssociations, + ResourceAssociation, + ResourceRegistry, } from "./api/dataStoreApi/types"; export type DexSubgraphUris = Map; @@ -239,6 +242,20 @@ export interface Instance { */ getDomainMetrics(domainIds: string[]): Promise; + /** + * Gets all the resource associations for a domain + * @param domainId Domain id to get resource associations for + */ + getDomainResourceAssociations( + domainId: string + ): Promise; + + /** + * Get resource registry information for a resource type + * @param resourceType Resource type to get resource registry for + */ + getResourceRegistry(resourceType: string): Promise>; + /** * Mints a new subdomain * @param params The subdomain parameters @@ -795,6 +812,7 @@ export interface Domain { created?: Created; isRoot?: boolean; buyNow?: BuyNowPriceListing; + resources?: MappingResourceAssociations; } export interface DomainMetadata { From 36c083abae23959ba46b5f440269bf88f088f941 Mon Sep 17 00:00:00 2001 From: deep-quality-dev Date: Thu, 17 Nov 2022 12:28:18 -0500 Subject: [PATCH 2/3] Rename ResourceAssociations type --- src/api/dataStoreApi/types.ts | 4 ++-- src/types.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/dataStoreApi/types.ts b/src/api/dataStoreApi/types.ts index 9ee96b5..b7c0685 100644 --- a/src/api/dataStoreApi/types.ts +++ b/src/api/dataStoreApi/types.ts @@ -37,7 +37,7 @@ export interface DataStoreDomain { buyNow: BuyNow; locked: boolean; // Older domains may not have these properties lockedBy: string; - resources: MappingResourceAssociations; + resources: ResourceAssociations; } export interface BuyNowPriceListing { @@ -60,7 +60,7 @@ export interface ResourceAssociation extends ResourceRegistry { resourceId: string; } -export interface MappingResourceAssociations { +export interface ResourceAssociations { [resourceType: string]: ResourceAssociation; } diff --git a/src/types.ts b/src/types.ts index 3f8dcfc..b44c8bc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,8 +4,8 @@ import { Bid, BuyNowListing } from "./zAuction"; import { BuyNowPriceListing, DomainSortOptions, - MappingResourceAssociations, ResourceAssociation, + ResourceAssociations, ResourceRegistry, } from "./api/dataStoreApi/types"; @@ -812,7 +812,7 @@ export interface Domain { created?: Created; isRoot?: boolean; buyNow?: BuyNowPriceListing; - resources?: MappingResourceAssociations; + resources?: ResourceAssociations; } export interface DomainMetadata { From 078694541e89f254864644c50fba9b79a367b192 Mon Sep 17 00:00:00 2001 From: Ryan Cross Date: Wed, 5 Apr 2023 12:03:11 -0500 Subject: [PATCH 3/3] disable tests failing due to subgraph deprecation --- test/e2e.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/e2e.test.ts b/test/e2e.test.ts index 4438881..2804bee 100644 --- a/test/e2e.test.ts +++ b/test/e2e.test.ts @@ -62,11 +62,14 @@ describe("SDK test", () => { const info = await sdk.zauction.getPaymentTokenInfo(tokenOnUniNotCG); expect(info.symbol).to.eq("SHKOOBYSHNAX"); }); - it("Reaches out to Sushiswap for a coin that's not on Uniswap", async () => { + + // Sushiswap subgraph no longer exists, so these tests are disabled until a new backup for token info is found. + // See https://wilderworld.atlassian.net/browse/MUD-210 + xit("Reaches out to Sushiswap for a coin that's not on Uniswap", async () => { const info = await sdk.zauction.getPaymentTokenInfo(tokenOnSushiNotUni); expect(info.symbol).to.eq("KING"); }); - it("Fails when token is not found", async () => { + xit("Fails when token is not found", async () => { return await sdk.zauction.getPaymentTokenInfo(randomToken) .catch(error => { const expectedMessage = `Token info with address ${randomToken} could not be found`;