Skip to content

Commit ace44cb

Browse files
authored
chore: unstoppable domain proxy (#404) (#405)
1 parent 303a3ef commit ace44cb

File tree

8 files changed

+159
-39
lines changed

8 files changed

+159
-39
lines changed

src/gql/heart-monitor/heart-monitor.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
defaultInflationDistribution,
4343
GQLFeatureFlags,
4444
defaultFeatureFlags,
45-
defaultProxy,
4645
GQLProxies,
4746
defaultInflationReward,
4847
featureFlagsQueryString,
@@ -54,6 +53,8 @@ import {
5453
GQLQueryGqlUserArgs,
5554
GQLEvm,
5655
defaultEvm,
56+
defaultBybit,
57+
defaultProxy,
5758
} from ".."
5859

5960
const nibiruUrl = "testnet-2"
@@ -360,19 +361,23 @@ test.skip("oraclePricesSubscription", async () => {
360361
)
361362
})
362363

363-
const testProxies = async (fields: GQLProxies) => {
364-
const resp = await heartMonitor.proxies(fields)
364+
const testProxies = async (fields: GQLProxies, domainName?: string) => {
365+
const resp = await heartMonitor.proxies(fields, domainName)
365366
expect(resp).toHaveProperty("proxies")
366367

367368
if (resp.proxies) {
368369
const { proxies } = resp
369370

370-
checkFields([proxies], ["bybit"])
371+
checkFields(
372+
[proxies],
373+
["bybit", ...(domainName ? ["unstoppableDomains"] : [])]
374+
)
371375
}
372376
}
373377

374378
test("proxies", async () => {
375-
await testProxies(defaultProxy)
379+
await testProxies(defaultProxy, "cameron.nibi")
380+
await testProxies({ bybit: defaultBybit })
376381
})
377382

378383
const testEvm = async (fields: GQLEvm) => {

src/gql/heart-monitor/heart-monitor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ export interface IHeartMonitor {
106106
AsyncIterableIterator<ExecutionResult<GqlOutOraclePrices>> | undefined
107107
>
108108

109-
readonly proxies: (fields: DeepPartial<GQLProxies>) => Promise<GqlOutProxies>
109+
readonly proxies: (
110+
fields: DeepPartial<GQLProxies>,
111+
domainName?: string
112+
) => Promise<GqlOutProxies>
110113

111114
readonly evm: (fields: DeepPartial<GQLEvm>) => Promise<GqlOutEvm>
112115

@@ -198,8 +201,8 @@ export class HeartMonitor implements IHeartMonitor {
198201
fields: DeepPartial<GQLOraclePrice>
199202
) => oraclePricesSubscription(args, fields, this.subscriptionClient)
200203

201-
proxies = async (fields: DeepPartial<GQLProxies>) =>
202-
proxies(this.gqlEndpt, fields)
204+
proxies = async (fields: DeepPartial<GQLProxies>, domainName?: string) =>
205+
proxies(this.gqlEndpt, fields, domainName)
203206

204207
evm = async (fields: DeepPartial<GQLEvm>) => evm(this.gqlEndpt, fields)
205208

src/gql/query/proxies.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,38 @@ export interface GqlOutProxies {
1212
}
1313

1414
export const proxiesQueryString = (
15-
excludeParentObject: boolean,
16-
fields: DeepPartial<GQLProxies>
17-
) =>
18-
gqlQuery(
19-
"proxies",
20-
{},
21-
convertObjectToPropertiesString(fields),
22-
excludeParentObject
23-
)
15+
fields: DeepPartial<GQLProxies>,
16+
domainName?: string
17+
) => {
18+
const proxiesQuery: string[] = []
19+
20+
if (fields.bybit) {
21+
proxiesQuery.push(
22+
gqlQuery("bybit", {}, convertObjectToPropertiesString(fields.bybit), true)
23+
)
24+
}
25+
26+
if (fields.unstoppableDomains) {
27+
proxiesQuery.push(
28+
gqlQuery(
29+
"unstoppableDomains",
30+
{ domainName },
31+
convertObjectToPropertiesString(fields.unstoppableDomains),
32+
true
33+
)
34+
)
35+
}
36+
37+
return `{
38+
proxies {
39+
${proxiesQuery.join("\n")}
40+
}
41+
}`
42+
}
2443

2544
export const proxies = async (
2645
endpt: string,
27-
fields: DeepPartial<GQLProxies>
46+
fields: DeepPartial<GQLProxies>,
47+
domainName?: string
2848
): Promise<GqlOutProxies> =>
29-
doGqlQuery(proxiesQueryString(false, fields), endpt)
49+
doGqlQuery(proxiesQueryString(fields, domainName), endpt)

src/gql/query/user.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ export const userQueryString = (
1616
args: GQLQueryGqlUserArgs,
1717
excludeParentObject: boolean,
1818
fields: DeepPartial<GQLUser>
19-
) => {
20-
return gqlQuery(
19+
) =>
20+
gqlQuery(
2121
"user",
2222
args,
2323
convertObjectToPropertiesString(fields),
2424
excludeParentObject
2525
)
26-
}
2726

2827
export const user = async (
2928
args: GQLQueryGqlUserArgs,

src/gql/utils/consts.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { fetch } from "cross-fetch"
2-
import { Client } from "graphql-ws"
32

43
type OptionalArrayOr<T, Otherwise> = T extends T[] ? T[] | undefined : Otherwise
54
type OptionalUndefinedOr<T, Otherwise> = T extends undefined
@@ -163,7 +162,9 @@ export const gqlQuery = <T>(
163162
delete typedQueryArgs.where
164163

165164
Object.keys(typedQueryArgs).forEach((key) =>
166-
queryArgList.push(arg<T>(key, typedQueryArgs[key], true))
165+
// key !== "domainName" normally `true`, however domainName is a special case
166+
// Will need to future proof this if more special cases arise
167+
queryArgList.push(arg<T>(key, typedQueryArgs[key], key !== "domainName"))
167168
)
168169

169170
const hasQueryList = (char: string) => (queryArgList.length > 0 ? char : "")

src/gql/utils/defaultObjects.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
GQLBlock,
3+
GQLBybitResponse,
34
GQLDelegation,
45
GQLDistributionCommission,
56
GQLEvm,
@@ -235,20 +236,45 @@ export const defaultFeatureFlags: GQLFeatureFlags = {
235236
wasm: true,
236237
}
237238

239+
export const defaultBybit: GQLBybitResponse = {
240+
ask1Price: "",
241+
ask1Size: "",
242+
bid1Price: "",
243+
bid1Size: "",
244+
highPrice24h: "",
245+
lastPrice: "",
246+
lowPrice24h: "",
247+
prevPrice24h: "",
248+
price24hPcnt: "",
249+
symbol: "",
250+
turnover24h: "",
251+
volume24h: "",
252+
}
253+
238254
export const defaultProxy: GQLProxies = {
239-
bybit: {
240-
ask1Price: "",
241-
ask1Size: "",
242-
bid1Price: "",
243-
bid1Size: "",
244-
highPrice24h: "",
245-
lastPrice: "",
246-
lowPrice24h: "",
247-
prevPrice24h: "",
248-
price24hPcnt: "",
249-
symbol: "",
250-
turnover24h: "",
251-
volume24h: "",
255+
bybit: defaultBybit,
256+
unstoppableDomains: {
257+
records: {
258+
cryptoEthAddress: "",
259+
cryptoNibiAddress: "",
260+
ipfsHtmlValue: "",
261+
tokenEvmEthEthAddress: "",
262+
tokenEvmMaticMaticAddress: "",
263+
tokenEvmMaticPolAddress: "",
264+
tokenNibiNibiNibiAddress: "",
265+
},
266+
meta: {
267+
blockchain: "",
268+
domain: "",
269+
namehash: "",
270+
owner: "",
271+
networkId: 0,
272+
registry: "",
273+
resolver: "",
274+
tokenId: "",
275+
reverse: false,
276+
type: "",
277+
},
252278
},
253279
}
254280

src/gql/utils/generated.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,13 @@ export enum GQLOraclesOrder {
512512

513513
export type GQLProxies = {
514514
readonly __typename?: 'Proxies';
515-
readonly bybit: GQLBybitResponse;
515+
readonly bybit?: Maybe<GQLBybitResponse>;
516+
readonly unstoppableDomains?: Maybe<GQLUnstoppableDomainsResponse>;
517+
};
518+
519+
520+
export type GQLProxiesGqlUnstoppableDomainsArgs = {
521+
domainName: Scalars['String']['input'];
516522
};
517523

518524
export type GQLQuery = {
@@ -614,6 +620,17 @@ export type GQLQueryGqlValidatorsArgs = {
614620
where?: InputMaybe<GQLValidatorFilter>;
615621
};
616622

623+
export type GQLRecords = {
624+
readonly __typename?: 'Records';
625+
readonly cryptoEthAddress?: Maybe<Scalars['String']['output']>;
626+
readonly cryptoNibiAddress?: Maybe<Scalars['String']['output']>;
627+
readonly ipfsHtmlValue?: Maybe<Scalars['String']['output']>;
628+
readonly tokenEvmEthEthAddress?: Maybe<Scalars['String']['output']>;
629+
readonly tokenEvmMaticMaticAddress?: Maybe<Scalars['String']['output']>;
630+
readonly tokenEvmMaticPolAddress?: Maybe<Scalars['String']['output']>;
631+
readonly tokenNibiNibiNibiAddress?: Maybe<Scalars['String']['output']>;
632+
};
633+
617634
export type GQLRedelegation = {
618635
readonly __typename?: 'Redelegation';
619636
readonly amount: Scalars['Int']['output'];
@@ -824,6 +841,26 @@ export enum GQLUnbondingOrder {
824841
GQLValidatorAddress = 'validator_address'
825842
}
826843

844+
export type GQLUnstoppableDomainsMeta = {
845+
readonly __typename?: 'UnstoppableDomainsMeta';
846+
readonly blockchain: Scalars['String']['output'];
847+
readonly domain: Scalars['String']['output'];
848+
readonly namehash: Scalars['String']['output'];
849+
readonly networkId: Scalars['Int']['output'];
850+
readonly owner: Scalars['String']['output'];
851+
readonly registry: Scalars['String']['output'];
852+
readonly resolver: Scalars['String']['output'];
853+
readonly reverse: Scalars['Boolean']['output'];
854+
readonly tokenId: Scalars['String']['output'];
855+
readonly type: Scalars['String']['output'];
856+
};
857+
858+
export type GQLUnstoppableDomainsResponse = {
859+
readonly __typename?: 'UnstoppableDomainsResponse';
860+
readonly meta: GQLUnstoppableDomainsMeta;
861+
readonly records: GQLRecords;
862+
};
863+
827864
export type GQLUser = {
828865
readonly __typename?: 'User';
829866
readonly address: Scalars['String']['output'];

src/gql/utils/schema.graphql

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ enum OraclesOrder {
393393
}
394394

395395
type Proxies {
396-
bybit: BybitResponse!
396+
bybit: BybitResponse
397+
unstoppableDomains(domainName: String!): UnstoppableDomainsResponse
397398
}
398399

399400
type Query {
@@ -419,6 +420,16 @@ type Query {
419420
wasm: Wasm!
420421
}
421422

423+
type Records {
424+
cryptoEthAddress: String
425+
cryptoNibiAddress: String
426+
ipfsHtmlValue: String
427+
tokenEvmEthEthAddress: String
428+
tokenEvmMaticMaticAddress: String
429+
tokenEvmMaticPolAddress: String
430+
tokenNibiNibiNibiAddress: String
431+
}
432+
422433
type Redelegation {
423434
amount: Int!
424435
completion_time: String!
@@ -565,6 +576,24 @@ enum UnbondingOrder {
565576
validator_address
566577
}
567578

579+
type UnstoppableDomainsMeta {
580+
blockchain: String!
581+
domain: String!
582+
namehash: String!
583+
networkId: Int!
584+
owner: String!
585+
registry: String!
586+
resolver: String!
587+
reverse: Boolean!
588+
tokenId: String!
589+
type: String!
590+
}
591+
592+
type UnstoppableDomainsResponse {
593+
meta: UnstoppableDomainsMeta!
594+
records: Records!
595+
}
596+
568597
type User {
569598
address: String!
570599
all_balances: [Balance!]!

0 commit comments

Comments
 (0)