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 cab7fd1..4ead701 100644 --- a/src/api/dataStoreApi/client.ts +++ b/src/api/dataStoreApi/client.ts @@ -1,7 +1,11 @@ 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"); @@ -32,6 +36,12 @@ export interface DataStoreApiClient { limit: number, skip: number ) => Promise; + getDomainResourceAssociations: ( + domainId: string + ) => Promise; + getResourceRegistry: ( + resourceType: string + ) => Promise>; } export const createDataStoreApiClient = ( @@ -115,6 +125,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 377f37a..fc08d15 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: ResourceAssociations; } 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 ResourceAssociations { + [resourceType: string]: ResourceAssociation; +} + type Show = 1; type Hide = 0; type OptionsValue = Show | Hide; diff --git a/src/index.ts b/src/index.ts index 60b0e04..e6880f0 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 }; @@ -189,6 +193,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, diff --git a/src/types.ts b/src/types.ts index 795223b..f6346c1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,6 +4,9 @@ import { Bid, BuyNowListing } from "./zAuction"; import { BuyNowPriceListing, DomainSortOptions, + ResourceAssociation, + ResourceAssociations, + ResourceRegistry, } from "./api/dataStoreApi/types"; export type DexSubgraphUris = Map; @@ -244,6 +247,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 @@ -800,6 +817,7 @@ export interface Domain { created?: Created; isRoot?: boolean; buyNow?: BuyNowPriceListing; + resources?: ResourceAssociations; } export interface DomainMetadata { 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`;