@bosonprotocol/core-sdk 1.6.0-alpha.13 → 1.6.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/cjs/accounts/subgraph.d.ts +9 -9
  2. package/dist/cjs/accounts/subgraph.d.ts.map +1 -1
  3. package/dist/cjs/accounts/subgraph.js +50 -26
  4. package/dist/cjs/accounts/subgraph.js.map +1 -1
  5. package/dist/cjs/accounts/types.d.ts +8 -0
  6. package/dist/cjs/accounts/types.d.ts.map +1 -1
  7. package/dist/cjs/core-sdk.d.ts +10 -15
  8. package/dist/cjs/core-sdk.d.ts.map +1 -1
  9. package/dist/cjs/core-sdk.js +15 -67
  10. package/dist/cjs/core-sdk.js.map +1 -1
  11. package/dist/cjs/exchanges/handler.d.ts +0 -18
  12. package/dist/cjs/exchanges/handler.d.ts.map +1 -1
  13. package/dist/cjs/exchanges/handler.js +6 -82
  14. package/dist/cjs/exchanges/handler.js.map +1 -1
  15. package/dist/cjs/exchanges/index.d.ts +0 -1
  16. package/dist/cjs/exchanges/index.d.ts.map +1 -1
  17. package/dist/cjs/exchanges/index.js +1 -2
  18. package/dist/cjs/exchanges/index.js.map +1 -1
  19. package/dist/cjs/exchanges/interface.d.ts +0 -5
  20. package/dist/cjs/exchanges/interface.d.ts.map +1 -1
  21. package/dist/cjs/exchanges/interface.js +1 -31
  22. package/dist/cjs/exchanges/interface.js.map +1 -1
  23. package/dist/cjs/funds/index.d.ts +1 -0
  24. package/dist/cjs/funds/index.d.ts.map +1 -1
  25. package/dist/cjs/funds/index.js +4 -0
  26. package/dist/cjs/funds/index.js.map +1 -1
  27. package/dist/cjs/funds/subgraph.d.ts +4 -4
  28. package/dist/cjs/funds/subgraph.d.ts.map +1 -1
  29. package/dist/cjs/funds/subgraph.js +28 -14
  30. package/dist/cjs/funds/subgraph.js.map +1 -1
  31. package/dist/cjs/funds/types.d.ts +12 -0
  32. package/dist/cjs/funds/types.d.ts.map +1 -0
  33. package/dist/cjs/funds/types.js +3 -0
  34. package/dist/cjs/funds/types.js.map +1 -0
  35. package/dist/cjs/index.d.ts +0 -1
  36. package/dist/cjs/index.d.ts.map +1 -1
  37. package/dist/cjs/index.js +1 -2
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/offers/index.d.ts +0 -1
  40. package/dist/cjs/offers/index.d.ts.map +1 -1
  41. package/dist/cjs/offers/index.js +0 -1
  42. package/dist/cjs/offers/index.js.map +1 -1
  43. package/dist/cjs/offers/interface.d.ts.map +1 -1
  44. package/dist/cjs/offers/interface.js +4 -11
  45. package/dist/cjs/offers/interface.js.map +1 -1
  46. package/dist/cjs/offers/subgraph.d.ts +8 -4
  47. package/dist/cjs/offers/subgraph.d.ts.map +1 -1
  48. package/dist/cjs/offers/subgraph.js +100 -10
  49. package/dist/cjs/offers/subgraph.js.map +1 -1
  50. package/dist/cjs/offers/types.d.ts +50 -0
  51. package/dist/cjs/offers/types.d.ts.map +1 -1
  52. package/dist/cjs/utils/errors.d.ts +10 -0
  53. package/dist/cjs/utils/errors.d.ts.map +1 -0
  54. package/dist/cjs/utils/errors.js +12 -0
  55. package/dist/cjs/utils/errors.js.map +1 -0
  56. package/dist/cjs/utils/subgraph.d.ts +8 -0
  57. package/dist/cjs/utils/subgraph.d.ts.map +1 -0
  58. package/dist/cjs/utils/subgraph.js +46 -0
  59. package/dist/cjs/utils/subgraph.js.map +1 -0
  60. package/dist/esm/accounts/subgraph.d.ts +9 -9
  61. package/dist/esm/accounts/subgraph.d.ts.map +1 -1
  62. package/dist/esm/accounts/subgraph.js +51 -42
  63. package/dist/esm/accounts/subgraph.js.map +1 -1
  64. package/dist/esm/accounts/types.d.ts +8 -0
  65. package/dist/esm/accounts/types.d.ts.map +1 -1
  66. package/dist/esm/core-sdk.d.ts +10 -15
  67. package/dist/esm/core-sdk.d.ts.map +1 -1
  68. package/dist/esm/core-sdk.js +15 -51
  69. package/dist/esm/core-sdk.js.map +1 -1
  70. package/dist/esm/exchanges/handler.d.ts +0 -18
  71. package/dist/esm/exchanges/handler.d.ts.map +1 -1
  72. package/dist/esm/exchanges/handler.js +6 -73
  73. package/dist/esm/exchanges/handler.js.map +1 -1
  74. package/dist/esm/exchanges/index.d.ts +0 -1
  75. package/dist/esm/exchanges/index.d.ts.map +1 -1
  76. package/dist/esm/exchanges/index.js +0 -1
  77. package/dist/esm/exchanges/index.js.map +1 -1
  78. package/dist/esm/exchanges/interface.d.ts +0 -5
  79. package/dist/esm/exchanges/interface.d.ts.map +1 -1
  80. package/dist/esm/exchanges/interface.js +0 -25
  81. package/dist/esm/exchanges/interface.js.map +1 -1
  82. package/dist/esm/funds/index.d.ts +1 -0
  83. package/dist/esm/funds/index.d.ts.map +1 -1
  84. package/dist/esm/funds/index.js +1 -0
  85. package/dist/esm/funds/index.js.map +1 -1
  86. package/dist/esm/funds/subgraph.d.ts +4 -4
  87. package/dist/esm/funds/subgraph.d.ts.map +1 -1
  88. package/dist/esm/funds/subgraph.js +26 -12
  89. package/dist/esm/funds/subgraph.js.map +1 -1
  90. package/dist/esm/funds/types.d.ts +12 -0
  91. package/dist/esm/funds/types.d.ts.map +1 -0
  92. package/dist/esm/funds/types.js +2 -0
  93. package/dist/esm/funds/types.js.map +1 -0
  94. package/dist/esm/index.d.ts +0 -1
  95. package/dist/esm/index.d.ts.map +1 -1
  96. package/dist/esm/index.js +0 -1
  97. package/dist/esm/index.js.map +1 -1
  98. package/dist/esm/offers/index.d.ts +0 -1
  99. package/dist/esm/offers/index.d.ts.map +1 -1
  100. package/dist/esm/offers/index.js +0 -1
  101. package/dist/esm/offers/index.js.map +1 -1
  102. package/dist/esm/offers/interface.d.ts.map +1 -1
  103. package/dist/esm/offers/interface.js +4 -11
  104. package/dist/esm/offers/interface.js.map +1 -1
  105. package/dist/esm/offers/subgraph.d.ts +8 -4
  106. package/dist/esm/offers/subgraph.d.ts.map +1 -1
  107. package/dist/esm/offers/subgraph.js +104 -12
  108. package/dist/esm/offers/subgraph.js.map +1 -1
  109. package/dist/esm/offers/types.d.ts +50 -0
  110. package/dist/esm/offers/types.d.ts.map +1 -1
  111. package/dist/esm/utils/errors.d.ts +10 -0
  112. package/dist/esm/utils/errors.d.ts.map +1 -0
  113. package/dist/esm/utils/errors.js +10 -0
  114. package/dist/esm/utils/errors.js.map +1 -0
  115. package/dist/esm/utils/subgraph.d.ts +8 -0
  116. package/dist/esm/utils/subgraph.d.ts.map +1 -0
  117. package/dist/esm/utils/subgraph.js +28 -0
  118. package/dist/esm/utils/subgraph.js.map +1 -0
  119. package/package.json +4 -7
  120. package/src/accounts/subgraph.ts +65 -66
  121. package/src/accounts/types.ts +9 -0
  122. package/src/core-sdk.ts +32 -112
  123. package/src/exchanges/handler.ts +6 -123
  124. package/src/exchanges/index.ts +0 -1
  125. package/src/exchanges/interface.ts +0 -28
  126. package/src/funds/index.ts +1 -0
  127. package/src/funds/subgraph.ts +31 -27
  128. package/src/funds/types.ts +11 -0
  129. package/src/index.ts +0 -1
  130. package/src/offers/index.ts +0 -1
  131. package/src/offers/interface.ts +6 -16
  132. package/src/offers/subgraph.ts +120 -26
  133. package/src/offers/types.ts +51 -0
  134. package/src/utils/errors.ts +14 -0
  135. package/src/utils/subgraph.ts +43 -0
  136. package/dist/cjs/exchanges/subgraph.d.ts +0 -6
  137. package/dist/cjs/exchanges/subgraph.d.ts.map +0 -1
  138. package/dist/cjs/exchanges/subgraph.js +0 -30
  139. package/dist/cjs/exchanges/subgraph.js.map +0 -1
  140. package/dist/cjs/offers/getOfferStatus.d.ts +0 -9
  141. package/dist/cjs/offers/getOfferStatus.d.ts.map +0 -1
  142. package/dist/cjs/offers/getOfferStatus.js +0 -26
  143. package/dist/cjs/offers/getOfferStatus.js.map +0 -1
  144. package/dist/cjs/subgraph.d.ts +0 -3148
  145. package/dist/cjs/subgraph.d.ts.map +0 -1
  146. package/dist/cjs/subgraph.js +0 -539
  147. package/dist/cjs/subgraph.js.map +0 -1
  148. package/dist/cjs/utils/graphql.d.ts +0 -91
  149. package/dist/cjs/utils/graphql.d.ts.map +0 -1
  150. package/dist/cjs/utils/graphql.js +0 -11
  151. package/dist/cjs/utils/graphql.js.map +0 -1
  152. package/dist/esm/exchanges/subgraph.d.ts +0 -6
  153. package/dist/esm/exchanges/subgraph.d.ts.map +0 -1
  154. package/dist/esm/exchanges/subgraph.js +0 -15
  155. package/dist/esm/exchanges/subgraph.js.map +0 -1
  156. package/dist/esm/offers/getOfferStatus.d.ts +0 -9
  157. package/dist/esm/offers/getOfferStatus.d.ts.map +0 -1
  158. package/dist/esm/offers/getOfferStatus.js +0 -22
  159. package/dist/esm/offers/getOfferStatus.js.map +0 -1
  160. package/dist/esm/subgraph.d.ts +0 -3148
  161. package/dist/esm/subgraph.d.ts.map +0 -1
  162. package/dist/esm/subgraph.js +0 -541
  163. package/dist/esm/subgraph.js.map +0 -1
  164. package/dist/esm/utils/graphql.d.ts +0 -91
  165. package/dist/esm/utils/graphql.d.ts.map +0 -1
  166. package/dist/esm/utils/graphql.js +0 -7
  167. package/dist/esm/utils/graphql.js.map +0 -1
  168. package/src/accounts/queries.graphql +0 -107
  169. package/src/exchanges/queries.graphql +0 -49
  170. package/src/exchanges/subgraph.ts +0 -35
  171. package/src/funds/queries.graphql +0 -35
  172. package/src/offers/getOfferStatus.ts +0 -27
  173. package/src/offers/queries.graphql +0 -88
  174. package/src/subgraph.ts +0 -3731
  175. package/src/utils/graphql.ts +0 -7
@@ -7,7 +7,6 @@ import {
7
7
  } from "@bosonprotocol/common";
8
8
  import { Interface } from "@ethersproject/abi";
9
9
  import { getAddress } from "@ethersproject/address";
10
- import { BigNumber } from "@ethersproject/bignumber";
11
10
  import { CreateOfferArgs } from "./types";
12
11
 
13
12
  export const bosonOfferHandlerIface = new Interface(abis.IBosonOfferHandlerABI);
@@ -50,7 +49,8 @@ export function argsToOfferDatesStruct(
50
49
  const {
51
50
  validFromDateInMS,
52
51
  validUntilDateInMS,
53
- voucherRedeemableFromDateInMS
52
+ voucherRedeemableFromDateInMS,
53
+ voucherRedeemableUntilDateInMS
54
54
  } = args;
55
55
 
56
56
  return {
@@ -59,10 +59,9 @@ export function argsToOfferDatesStruct(
59
59
  voucherRedeemableFrom: utils.timestamp.msToSec(
60
60
  voucherRedeemableFromDateInMS
61
61
  ),
62
- voucherRedeemableUntil:
63
- // NOTE: Field `voucherRedeemableUntil` not yet fully supported in protocol.
64
- // Therefore converting to `voucherValid` field.
65
- "0"
62
+ voucherRedeemableUntil: utils.timestamp.msToSec(
63
+ voucherRedeemableUntilDateInMS
64
+ )
66
65
  };
67
66
  }
68
67
 
@@ -71,22 +70,13 @@ export function argsToOfferDurationsStruct(
71
70
  ): Partial<OfferDurationsStruct> {
72
71
  const {
73
72
  fulfillmentPeriodDurationInMS,
74
- voucherRedeemableUntilDateInMS,
75
- voucherRedeemableFromDateInMS,
76
73
  voucherValidDurationInMS = 0,
77
74
  resolutionPeriodDurationInMS
78
75
  } = args;
79
76
 
80
77
  return {
81
78
  fulfillmentPeriod: utils.timestamp.msToSec(fulfillmentPeriodDurationInMS),
82
- voucherValid: utils.timestamp.msToSec(
83
- voucherValidDurationInMS ||
84
- // NOTE: Field `voucherRedeemableUntil` not yet fully supported in protocol.
85
- // Therefore converting to `voucherValid` field.
86
- BigNumber.from(voucherRedeemableUntilDateInMS).sub(
87
- BigNumber.from(voucherRedeemableFromDateInMS)
88
- )
89
- ),
79
+ voucherValid: utils.timestamp.msToSec(voucherValidDurationInMS),
90
80
  resolutionPeriod: utils.timestamp.msToSec(resolutionPeriodDurationInMS)
91
81
  };
92
82
  }
@@ -1,38 +1,132 @@
1
1
  import { BigNumberish } from "@ethersproject/bignumber";
2
- import { getSubgraphSdk } from "../utils/graphql";
3
- import {
4
- OfferFieldsFragment,
5
- GetOfferByIdQueryQueryVariables,
6
- GetOffersQueryQueryVariables
7
- } from "../subgraph";
8
-
9
- export type SingleOfferQueryVariables = Omit<
10
- GetOfferByIdQueryQueryVariables,
11
- "offerId"
12
- >;
2
+ import { fetchSubgraph, MultiQueryOpts } from "../utils/subgraph";
3
+ import { RawOfferFromSubgraph } from "./types";
4
+
5
+ export const exchangeFieldsFragment = `
6
+ fragment exchangeFields on Exchange {
7
+ id
8
+ committedDate
9
+ redeemedDate
10
+ finalizedDate
11
+ expired
12
+ disputed
13
+ }
14
+ `;
15
+
16
+ export const offerFieldsFragment = `
17
+ fragment offerFields on Offer {
18
+ id
19
+ createdAt
20
+ price
21
+ sellerDeposit
22
+ protocolFee
23
+ buyerCancelPenalty
24
+ quantityAvailable
25
+ quantityInitial
26
+ validFromDate
27
+ validUntilDate
28
+ voucherRedeemableFromDate
29
+ voucherRedeemableUntilDate
30
+ fulfillmentPeriodDuration
31
+ voucherValidDuration
32
+ resolutionPeriodDuration
33
+ metadataUri
34
+ offerChecksum
35
+ voidedAt
36
+ disputeResolverId
37
+ seller {
38
+ id
39
+ operator
40
+ admin
41
+ clerk
42
+ treasury
43
+ active
44
+ }
45
+ exchangeToken {
46
+ address
47
+ decimals
48
+ name
49
+ symbol
50
+ }
51
+ metadata {
52
+ name
53
+ description
54
+ externalUrl
55
+ schemaUrl
56
+ type
57
+ }
58
+ exchanges {
59
+ ...exchangeFields
60
+ }
61
+ }
62
+ ${exchangeFieldsFragment}
63
+ `;
64
+
65
+ export const getOfferByIdQuery = `
66
+ query GetOfferById($offerId: ID!) {
67
+ offer(id: $offerId) {
68
+ ...offerFields
69
+ }
70
+ }
71
+ ${offerFieldsFragment}
72
+ `;
13
73
 
14
74
  export async function getOfferById(
15
75
  subgraphUrl: string,
16
- offerId: BigNumberish,
17
- queryVars: SingleOfferQueryVariables = {}
18
- ): Promise<OfferFieldsFragment> {
19
- const subgraphSdk = getSubgraphSdk(subgraphUrl);
20
- const { offer } = await subgraphSdk.getOfferByIdQuery({
21
- offerId: offerId.toString(),
22
- ...queryVars
23
- });
76
+ offerId: BigNumberish
77
+ ): Promise<RawOfferFromSubgraph> {
78
+ const { offer } = await fetchSubgraph<{ offer: RawOfferFromSubgraph }>(
79
+ subgraphUrl,
80
+ getOfferByIdQuery,
81
+ { offerId: offerId.toString() }
82
+ );
24
83
 
25
84
  return offer;
26
85
  }
27
86
 
28
- export async function getOffers(
87
+ export const getAllOffersOfOperatorQuery = `
88
+ query GetAllOffersOfOperatorQuery(
89
+ $operator: String!,
90
+ $first: Int,
91
+ $skip: Int,
92
+ $orderBy: String,
93
+ $orderDirection: String
94
+ ) {
95
+ sellers(where: {
96
+ operator: $operator
97
+ }) {
98
+ offers(
99
+ first: $first
100
+ skip: $skip
101
+ orderBy: $orderBy
102
+ orderDirection: $orderDirection
103
+ ) {
104
+ ...offerFields
105
+ }
106
+ }
107
+ }
108
+ ${offerFieldsFragment}
109
+ `;
110
+
111
+ export async function getAllOffersOfOperator(
29
112
  subgraphUrl: string,
30
- queryVars: GetOffersQueryQueryVariables = {}
31
- ): Promise<OfferFieldsFragment[]> {
32
- const subgraphSdk = getSubgraphSdk(subgraphUrl);
33
- const { offers = [] } = await subgraphSdk.getOffersQuery({
34
- ...queryVars
113
+ operatorAddress: string,
114
+ opts: MultiQueryOpts = {}
115
+ ): Promise<RawOfferFromSubgraph[]> {
116
+ const { sellers } = await fetchSubgraph<{
117
+ sellers: { offers: RawOfferFromSubgraph[] };
118
+ }>(subgraphUrl, getAllOffersOfOperatorQuery, {
119
+ operator: operatorAddress.toLowerCase(),
120
+ first: 100,
121
+ skip: 0,
122
+ orderBy: "createdAt",
123
+ orderDirection: "desc",
124
+ ...opts
35
125
  });
36
126
 
37
- return offers;
127
+ if (!sellers) {
128
+ return [];
129
+ }
130
+
131
+ return sellers[0].offers;
38
132
  }
@@ -1 +1,52 @@
1
1
  export { CreateOfferArgs } from "@bosonprotocol/common";
2
+
3
+ export type RawOfferFromSubgraph = {
4
+ id: string;
5
+ createdAt: string;
6
+ price: string;
7
+ sellerDeposit: string;
8
+ protocolFee: string;
9
+ buyerCancelPenalty: string;
10
+ quantityAvailable: string;
11
+ quantityInitial: string;
12
+ validFromDate: string;
13
+ validUntilDate: string;
14
+ voucherRedeemableFromDate: string;
15
+ voucherRedeemableUntilDate: string;
16
+ fulfillmentPeriodDuration: string;
17
+ voucherValidDuration: string;
18
+ resolutionPeriodDuration: string;
19
+ metadataUri: string;
20
+ offerChecksum: string;
21
+ voidedAt: null | string;
22
+ disputeResolverId: string;
23
+ seller: {
24
+ id: string;
25
+ operator: string;
26
+ admin: string;
27
+ clerk: string;
28
+ treasury: string;
29
+ active: boolean;
30
+ };
31
+ exchangeToken: {
32
+ address: string;
33
+ decimals: string;
34
+ name: string;
35
+ symbol: string;
36
+ };
37
+ metadata: null | {
38
+ name: string;
39
+ description: string;
40
+ externalUrl: string;
41
+ schemaUrl: string;
42
+ type: string;
43
+ };
44
+ exchanges: {
45
+ id: string;
46
+ committedDate: string;
47
+ disputed: boolean;
48
+ expired: boolean;
49
+ finalizedDate: string;
50
+ redeemedDate: string;
51
+ }[];
52
+ };
@@ -0,0 +1,14 @@
1
+ export class FetchError extends Error {
2
+ statusCode?: number;
3
+ statusText?: string;
4
+
5
+ constructor(args: {
6
+ message?: string;
7
+ statusCode?: number;
8
+ statusText?: string;
9
+ }) {
10
+ super(args.message);
11
+ this.statusCode = args.statusCode;
12
+ this.statusText = args.statusText;
13
+ }
14
+ }
@@ -0,0 +1,43 @@
1
+ import fetch from "cross-fetch";
2
+ import { FetchError } from "./errors";
3
+
4
+ export type MultiQueryOpts = Partial<{
5
+ first: number;
6
+ skip: number;
7
+ orderBy: string;
8
+ orderDirection: "asc" | "desc";
9
+ }>;
10
+
11
+ export async function fetchSubgraph<T>(
12
+ subgraphUrl: string,
13
+ query: string,
14
+ variables?: Record<string, unknown>
15
+ ): Promise<T> {
16
+ const response = await fetch(subgraphUrl, {
17
+ method: "POST",
18
+ headers: {
19
+ "Content-Type": "application/json"
20
+ },
21
+ body: JSON.stringify({
22
+ query,
23
+ variables
24
+ })
25
+ });
26
+
27
+ if (!response.ok) {
28
+ throw new FetchError({
29
+ message: `Failed to fetch: ${response.status} ${response.statusText}`,
30
+ statusCode: response.status,
31
+ statusText: response.statusText
32
+ });
33
+ }
34
+
35
+ const body = await response.json();
36
+ const { data = {}, errors = [] } = body || {};
37
+
38
+ if (errors.length > 0) {
39
+ throw new Error(`GraphQL errors: ${JSON.stringify(errors)}`);
40
+ }
41
+
42
+ return data as T;
43
+ }
@@ -1,6 +0,0 @@
1
- import { ExchangeFieldsFragment, GetExchangesQueryQueryVariables, GetExchangeByIdQueryQueryVariables } from "../subgraph";
2
- import { BigNumberish } from "@ethersproject/bignumber";
3
- export declare type SingleExchangeQueryVariables = Omit<GetExchangeByIdQueryQueryVariables, "exchangeId">;
4
- export declare function getExchanges(subgraphUrl: string, queryVars?: GetExchangesQueryQueryVariables): Promise<ExchangeFieldsFragment[]>;
5
- export declare function getExchangeById(subgraphUrl: string, exchangeId: BigNumberish, queryVars?: SingleExchangeQueryVariables): Promise<ExchangeFieldsFragment>;
6
- //# sourceMappingURL=subgraph.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subgraph.d.ts","sourceRoot":"","sources":["../../../src/exchanges/subgraph.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,kCAAkC,EACnC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,oBAAY,4BAA4B,GAAG,IAAI,CAC7C,kCAAkC,EAClC,YAAY,CACb,CAAC;AAEF,wBAAsB,YAAY,CAChC,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,+BAAoC,GAC9C,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAInC;AAED,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,YAAY,EACxB,SAAS,GAAE,4BAAiC,GAC3C,OAAO,CAAC,sBAAsB,CAAC,CAQjC"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getExchangeById = exports.getExchanges = void 0;
13
- const graphql_1 = require("../utils/graphql");
14
- function getExchanges(subgraphUrl, queryVars = {}) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
17
- const { exchanges = [] } = yield sdk.getExchangesQuery(queryVars);
18
- return exchanges;
19
- });
20
- }
21
- exports.getExchanges = getExchanges;
22
- function getExchangeById(subgraphUrl, exchangeId, queryVars = {}) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
25
- const { exchange } = yield sdk.getExchangeByIdQuery(Object.assign({ exchangeId: exchangeId.toString() }, queryVars));
26
- return exchange;
27
- });
28
- }
29
- exports.getExchangeById = getExchangeById;
30
- //# sourceMappingURL=subgraph.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subgraph.js","sourceRoot":"","sources":["../../../src/exchanges/subgraph.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAkD;AAalD,SAAsB,YAAY,CAChC,WAAmB,EACnB,YAA6C,EAAE;;QAE/C,MAAM,GAAG,GAAG,IAAA,wBAAc,EAAC,WAAW,CAAC,CAAC;QACxC,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,MAAM,GAAG,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAClE,OAAO,SAAS,CAAC;IACnB,CAAC;CAAA;AAPD,oCAOC;AAED,SAAsB,eAAe,CACnC,WAAmB,EACnB,UAAwB,EACxB,YAA0C,EAAE;;QAE5C,MAAM,GAAG,GAAG,IAAA,wBAAc,EAAC,WAAW,CAAC,CAAC;QACxC,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,GAAG,CAAC,oBAAoB,iBACjD,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE,IAC9B,SAAS,EACZ,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA;AAZD,0CAYC"}
@@ -1,9 +0,0 @@
1
- import { subgraph } from "..";
2
- export declare enum OfferState {
3
- VOIDED = "VOIDED",
4
- NOT_YET_VALID = "NOT YET VALID",
5
- EXPIRED = "EXPIRED",
6
- VALID = "VALID"
7
- }
8
- export declare function getOfferStatus(offer: subgraph.OfferFieldsFragment): OfferState;
9
- //# sourceMappingURL=getOfferStatus.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getOfferStatus.d.ts","sourceRoot":"","sources":["../../../src/offers/getOfferStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAE9B,oBAAY,UAAU;IACpB,MAAM,WAAW;IACjB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,mBAAmB,cAiBjE"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOfferStatus = exports.OfferState = void 0;
4
- var OfferState;
5
- (function (OfferState) {
6
- OfferState["VOIDED"] = "VOIDED";
7
- OfferState["NOT_YET_VALID"] = "NOT YET VALID";
8
- OfferState["EXPIRED"] = "EXPIRED";
9
- OfferState["VALID"] = "VALID";
10
- })(OfferState = exports.OfferState || (exports.OfferState = {}));
11
- function getOfferStatus(offer) {
12
- const toTimeStamp = (numberString) => Number(numberString) * 1000;
13
- const timeNow = Date.now();
14
- if (offer.voidedAt) {
15
- return OfferState.VOIDED;
16
- }
17
- if (toTimeStamp(offer.validFromDate) > timeNow) {
18
- return OfferState.NOT_YET_VALID;
19
- }
20
- if (toTimeStamp(offer.validUntilDate) < timeNow) {
21
- return OfferState.EXPIRED;
22
- }
23
- return OfferState.VALID;
24
- }
25
- exports.getOfferStatus = getOfferStatus;
26
- //# sourceMappingURL=getOfferStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getOfferStatus.js","sourceRoot":"","sources":["../../../src/offers/getOfferStatus.ts"],"names":[],"mappings":";;;AAEA,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,6CAA+B,CAAA;IAC/B,iCAAmB,CAAA;IACnB,6BAAe,CAAA;AACjB,CAAC,EALW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAKrB;AAED,SAAgB,cAAc,CAAC,KAAmC;IAChE,MAAM,WAAW,GAAG,CAAC,YAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE3B,IAAI,KAAK,CAAC,QAAQ,EAAE;QAClB,OAAO,UAAU,CAAC,MAAM,CAAC;KAC1B;IAED,IAAI,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,OAAO,EAAE;QAC9C,OAAO,UAAU,CAAC,aAAa,CAAC;KACjC;IAED,IAAI,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,OAAO,EAAE;QAC/C,OAAO,UAAU,CAAC,OAAO,CAAC;KAC3B;IAED,OAAO,UAAU,CAAC,KAAK,CAAC;AAC1B,CAAC;AAjBD,wCAiBC"}