@bosonprotocol/core-sdk 1.6.0-alpha.9 → 1.6.0
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.
- package/dist/cjs/accounts/subgraph.d.ts +9 -5
- package/dist/cjs/accounts/subgraph.d.ts.map +1 -1
- package/dist/cjs/accounts/subgraph.js +26 -22
- package/dist/cjs/accounts/subgraph.js.map +1 -1
- package/dist/cjs/core-sdk.d.ts +14 -11
- package/dist/cjs/core-sdk.d.ts.map +1 -1
- package/dist/cjs/core-sdk.js +61 -19
- package/dist/cjs/core-sdk.js.map +1 -1
- package/dist/cjs/exchanges/handler.d.ts +18 -0
- package/dist/cjs/exchanges/handler.d.ts.map +1 -1
- package/dist/cjs/exchanges/handler.js +82 -6
- package/dist/cjs/exchanges/handler.js.map +1 -1
- package/dist/cjs/exchanges/interface.d.ts +5 -0
- package/dist/cjs/exchanges/interface.d.ts.map +1 -1
- package/dist/cjs/exchanges/interface.js +31 -1
- package/dist/cjs/exchanges/interface.js.map +1 -1
- package/dist/cjs/exchanges/subgraph.d.ts +4 -4
- package/dist/cjs/exchanges/subgraph.d.ts.map +1 -1
- package/dist/cjs/exchanges/subgraph.js +9 -11
- package/dist/cjs/exchanges/subgraph.js.map +1 -1
- package/dist/cjs/funds/subgraph.d.ts +4 -2
- package/dist/cjs/funds/subgraph.d.ts.map +1 -1
- package/dist/cjs/funds/subgraph.js +13 -7
- package/dist/cjs/funds/subgraph.js.map +1 -1
- package/dist/cjs/offers/interface.d.ts.map +1 -1
- package/dist/cjs/offers/interface.js +11 -4
- package/dist/cjs/offers/interface.js.map +1 -1
- package/dist/cjs/offers/subgraph.d.ts +4 -4
- package/dist/cjs/offers/subgraph.d.ts.map +1 -1
- package/dist/cjs/offers/subgraph.js +7 -12
- package/dist/cjs/offers/subgraph.js.map +1 -1
- package/dist/cjs/subgraph.d.ts +531 -121
- package/dist/cjs/subgraph.d.ts.map +1 -1
- package/dist/cjs/subgraph.js +229 -101
- package/dist/cjs/subgraph.js.map +1 -1
- package/dist/cjs/utils/graphql.d.ts +82 -29
- package/dist/cjs/utils/graphql.d.ts.map +1 -1
- package/dist/esm/accounts/subgraph.d.ts +9 -5
- package/dist/esm/accounts/subgraph.d.ts.map +1 -1
- package/dist/esm/accounts/subgraph.js +37 -18
- package/dist/esm/accounts/subgraph.js.map +1 -1
- package/dist/esm/core-sdk.d.ts +14 -11
- package/dist/esm/core-sdk.d.ts.map +1 -1
- package/dist/esm/core-sdk.js +49 -19
- package/dist/esm/core-sdk.js.map +1 -1
- package/dist/esm/exchanges/handler.d.ts +18 -0
- package/dist/esm/exchanges/handler.d.ts.map +1 -1
- package/dist/esm/exchanges/handler.js +73 -6
- package/dist/esm/exchanges/handler.js.map +1 -1
- package/dist/esm/exchanges/interface.d.ts +5 -0
- package/dist/esm/exchanges/interface.d.ts.map +1 -1
- package/dist/esm/exchanges/interface.js +25 -0
- package/dist/esm/exchanges/interface.js.map +1 -1
- package/dist/esm/exchanges/subgraph.d.ts +4 -4
- package/dist/esm/exchanges/subgraph.d.ts.map +1 -1
- package/dist/esm/exchanges/subgraph.js +8 -10
- package/dist/esm/exchanges/subgraph.js.map +1 -1
- package/dist/esm/funds/subgraph.d.ts +4 -2
- package/dist/esm/funds/subgraph.d.ts.map +1 -1
- package/dist/esm/funds/subgraph.js +11 -5
- package/dist/esm/funds/subgraph.js.map +1 -1
- package/dist/esm/offers/interface.d.ts.map +1 -1
- package/dist/esm/offers/interface.js +11 -4
- package/dist/esm/offers/interface.js.map +1 -1
- package/dist/esm/offers/subgraph.d.ts +4 -4
- package/dist/esm/offers/subgraph.d.ts.map +1 -1
- package/dist/esm/offers/subgraph.js +7 -10
- package/dist/esm/offers/subgraph.js.map +1 -1
- package/dist/esm/subgraph.d.ts +531 -121
- package/dist/esm/subgraph.d.ts.map +1 -1
- package/dist/esm/subgraph.js +234 -100
- package/dist/esm/subgraph.js.map +1 -1
- package/dist/esm/utils/graphql.d.ts +82 -29
- package/dist/esm/utils/graphql.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/accounts/queries.graphql +89 -17
- package/src/accounts/subgraph.ts +58 -23
- package/src/core-sdk.ts +82 -35
- package/src/exchanges/handler.ts +123 -6
- package/src/exchanges/interface.ts +28 -0
- package/src/exchanges/queries.graphql +23 -23
- package/src/exchanges/subgraph.ts +21 -20
- package/src/funds/queries.graphql +20 -2
- package/src/funds/subgraph.ts +27 -8
- package/src/offers/interface.ts +16 -6
- package/src/offers/queries.graphql +43 -22
- package/src/offers/subgraph.ts +18 -20
- package/src/subgraph.ts +807 -262
|
@@ -1,35 +1,107 @@
|
|
|
1
|
-
query
|
|
2
|
-
|
|
1
|
+
query getSellerByIdQuery(
|
|
2
|
+
$sellerId: ID!
|
|
3
|
+
$fundsSkip: Int
|
|
4
|
+
$fundsFirst: Int
|
|
5
|
+
$fundsOrderBy: FundsEntity_orderBy
|
|
6
|
+
$fundsOrderDirection: OrderDirection
|
|
7
|
+
$fundsFilter: FundsEntity_filter
|
|
8
|
+
$offersSkip: Int
|
|
9
|
+
$offersFirst: Int
|
|
10
|
+
$offersOrderBy: Offer_orderBy
|
|
11
|
+
$offersOrderDirection: OrderDirection
|
|
12
|
+
$offersFilter: Offer_filter
|
|
13
|
+
$exchangesSkip: Int
|
|
14
|
+
$exchangesFirst: Int
|
|
15
|
+
$exchangesOrderBy: Exchange_orderBy
|
|
16
|
+
$exchangesOrderDirection: OrderDirection
|
|
17
|
+
$exchangesFilter: Exchange_filter
|
|
18
|
+
$includeExchanges: Boolean = false
|
|
19
|
+
$includeOffers: Boolean = false
|
|
20
|
+
$includeFunds: Boolean = false
|
|
21
|
+
) {
|
|
22
|
+
seller(id: $sellerId) {
|
|
3
23
|
...SellerFields
|
|
4
24
|
}
|
|
5
25
|
}
|
|
6
26
|
|
|
7
|
-
query
|
|
8
|
-
|
|
27
|
+
query getSellersQuery(
|
|
28
|
+
$sellersSkip: Int
|
|
29
|
+
$sellersFirst: Int
|
|
30
|
+
$sellersOrderBy: Seller_orderBy
|
|
31
|
+
$sellersOrderDirection: OrderDirection
|
|
32
|
+
$sellersFilter: Seller_filter
|
|
33
|
+
$fundsSkip: Int
|
|
34
|
+
$fundsFirst: Int
|
|
35
|
+
$fundsOrderBy: FundsEntity_orderBy
|
|
36
|
+
$fundsOrderDirection: OrderDirection
|
|
37
|
+
$fundsFilter: FundsEntity_filter
|
|
38
|
+
$offersSkip: Int
|
|
39
|
+
$offersFirst: Int
|
|
40
|
+
$offersOrderBy: Offer_orderBy
|
|
41
|
+
$offersOrderDirection: OrderDirection
|
|
42
|
+
$offersFilter: Offer_filter
|
|
43
|
+
$exchangesSkip: Int
|
|
44
|
+
$exchangesFirst: Int
|
|
45
|
+
$exchangesOrderBy: Exchange_orderBy
|
|
46
|
+
$exchangesOrderDirection: OrderDirection
|
|
47
|
+
$exchangesFilter: Exchange_filter
|
|
48
|
+
$includeExchanges: Boolean = false
|
|
49
|
+
$includeOffers: Boolean = false
|
|
50
|
+
$includeFunds: Boolean = false
|
|
51
|
+
) {
|
|
52
|
+
sellers(
|
|
53
|
+
skip: $sellersSkip
|
|
54
|
+
first: $sellersFirst
|
|
55
|
+
orderBy: $sellersOrderBy
|
|
56
|
+
orderDirection: $sellersOrderDirection
|
|
57
|
+
where: $sellersFilter
|
|
58
|
+
) {
|
|
9
59
|
...SellerFields
|
|
10
60
|
}
|
|
11
61
|
}
|
|
12
62
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
63
|
+
fragment SellerFields on Seller {
|
|
64
|
+
...BaseSellerFields
|
|
65
|
+
funds(
|
|
66
|
+
skip: $fundsSkip
|
|
67
|
+
first: $fundsFirst
|
|
68
|
+
orderBy: $fundsOrderBy
|
|
69
|
+
orderDirection: $fundsOrderDirection
|
|
70
|
+
where: $fundsFilter
|
|
71
|
+
) @include(if: $includeFunds) {
|
|
72
|
+
...FundsEntityFields
|
|
73
|
+
}
|
|
74
|
+
offers(
|
|
75
|
+
skip: $offersSkip
|
|
76
|
+
first: $offersFirst
|
|
77
|
+
orderBy: $offersOrderBy
|
|
78
|
+
orderDirection: $offersOrderDirection
|
|
79
|
+
where: $offersFilter
|
|
80
|
+
) @include(if: $includeOffers) {
|
|
81
|
+
...BaseOfferFields
|
|
82
|
+
}
|
|
83
|
+
exchanges(
|
|
84
|
+
skip: $exchangesSkip
|
|
85
|
+
first: $exchangesFirst
|
|
86
|
+
orderBy: $exchangesOrderBy
|
|
87
|
+
orderDirection: $exchangesOrderDirection
|
|
88
|
+
where: $exchangesFilter
|
|
89
|
+
) @include(if: $includeExchanges) {
|
|
90
|
+
...BaseExchangeFields
|
|
16
91
|
}
|
|
17
92
|
}
|
|
18
93
|
|
|
19
|
-
fragment
|
|
94
|
+
fragment BaseSellerFields on Seller {
|
|
20
95
|
id
|
|
21
96
|
operator
|
|
22
97
|
admin
|
|
23
98
|
clerk
|
|
24
99
|
treasury
|
|
25
100
|
active
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
symbol
|
|
33
|
-
}
|
|
34
|
-
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fragment BaseBuyerFields on Buyer {
|
|
104
|
+
id
|
|
105
|
+
wallet
|
|
106
|
+
active
|
|
35
107
|
}
|
package/src/accounts/subgraph.ts
CHANGED
|
@@ -1,57 +1,92 @@
|
|
|
1
1
|
import { getSubgraphSdk } from "../utils/graphql";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
SellerFieldsFragment,
|
|
4
|
+
GetSellersQueryQueryVariables,
|
|
5
|
+
GetSellerByIdQueryQueryVariables
|
|
6
|
+
} from "../subgraph";
|
|
7
|
+
import { BigNumberish } from "@ethersproject/bignumber";
|
|
3
8
|
|
|
4
|
-
export
|
|
9
|
+
export type SingleSellerQueryVariables = Omit<
|
|
10
|
+
GetSellerByIdQueryQueryVariables,
|
|
11
|
+
"sellerId"
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export async function getSellerById(
|
|
5
15
|
subgraphUrl: string,
|
|
6
|
-
|
|
7
|
-
|
|
16
|
+
sellerId: BigNumberish,
|
|
17
|
+
queryVars: SingleSellerQueryVariables = {}
|
|
8
18
|
): Promise<SellerFieldsFragment> {
|
|
9
19
|
const sdk = getSubgraphSdk(subgraphUrl);
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
const { seller } = await sdk.getSellerByIdQuery({
|
|
21
|
+
sellerId: sellerId.toString(),
|
|
22
|
+
...queryVars
|
|
13
23
|
});
|
|
24
|
+
return seller;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function getSellers(
|
|
28
|
+
subgraphUrl: string,
|
|
29
|
+
queryVars: GetSellersQueryQueryVariables = {}
|
|
30
|
+
): Promise<SellerFieldsFragment[]> {
|
|
31
|
+
const sdk = getSubgraphSdk(subgraphUrl);
|
|
32
|
+
const { sellers = [] } = await sdk.getSellersQuery(queryVars);
|
|
33
|
+
return sellers;
|
|
34
|
+
}
|
|
14
35
|
|
|
36
|
+
export async function getSellerByOperator(
|
|
37
|
+
subgraphUrl: string,
|
|
38
|
+
operatorAddress: string,
|
|
39
|
+
queryVars: GetSellersQueryQueryVariables = {}
|
|
40
|
+
): Promise<SellerFieldsFragment | undefined> {
|
|
41
|
+
const sellers = await getSellers(subgraphUrl, {
|
|
42
|
+
sellersFilter: {
|
|
43
|
+
...queryVars.sellersFilter,
|
|
44
|
+
operator: operatorAddress.toLowerCase()
|
|
45
|
+
},
|
|
46
|
+
...queryVars
|
|
47
|
+
});
|
|
15
48
|
return sellers[0];
|
|
16
49
|
}
|
|
17
50
|
|
|
18
51
|
export async function getSellerByAdmin(
|
|
19
52
|
subgraphUrl: string,
|
|
20
53
|
adminAddress: string,
|
|
21
|
-
|
|
54
|
+
queryVars: GetSellersQueryQueryVariables = {}
|
|
22
55
|
): Promise<SellerFieldsFragment> {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
56
|
+
const sellers = await getSellers(subgraphUrl, {
|
|
57
|
+
sellersFilter: {
|
|
58
|
+
...queryVars.sellersFilter,
|
|
59
|
+
admin: adminAddress.toLowerCase()
|
|
60
|
+
},
|
|
61
|
+
...queryVars
|
|
27
62
|
});
|
|
28
|
-
|
|
29
63
|
return sellers[0];
|
|
30
64
|
}
|
|
31
65
|
|
|
32
66
|
export async function getSellerByClerk(
|
|
33
67
|
subgraphUrl: string,
|
|
34
68
|
clerkAddress: string,
|
|
35
|
-
|
|
69
|
+
queryVars: GetSellersQueryQueryVariables = {}
|
|
36
70
|
): Promise<SellerFieldsFragment> {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
const sellers = await getSellers(subgraphUrl, {
|
|
72
|
+
sellersFilter: {
|
|
73
|
+
...queryVars.sellersFilter,
|
|
74
|
+
clerk: clerkAddress.toLowerCase()
|
|
75
|
+
},
|
|
76
|
+
...queryVars
|
|
41
77
|
});
|
|
42
|
-
|
|
43
78
|
return sellers[0];
|
|
44
79
|
}
|
|
45
80
|
|
|
46
81
|
export async function getSellerByAddress(
|
|
47
82
|
subgraphUrl: string,
|
|
48
83
|
address: string,
|
|
49
|
-
|
|
84
|
+
queryVars: GetSellersQueryQueryVariables = {}
|
|
50
85
|
): Promise<SellerFieldsFragment> {
|
|
51
86
|
const [operator, admin, clerk] = await Promise.all([
|
|
52
|
-
getSellerByOperator(subgraphUrl, address,
|
|
53
|
-
getSellerByAdmin(subgraphUrl, address,
|
|
54
|
-
getSellerByClerk(subgraphUrl, address,
|
|
87
|
+
getSellerByOperator(subgraphUrl, address, queryVars),
|
|
88
|
+
getSellerByAdmin(subgraphUrl, address, queryVars),
|
|
89
|
+
getSellerByClerk(subgraphUrl, address, queryVars)
|
|
55
90
|
]);
|
|
56
91
|
|
|
57
92
|
return operator || admin || clerk;
|
package/src/core-sdk.ts
CHANGED
|
@@ -78,39 +78,56 @@ export class CoreSDK {
|
|
|
78
78
|
return this._metadataStorage.getMetadata(metadataHashOrUri);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
public async getSellerById(
|
|
82
|
+
sellerId: BigNumberish,
|
|
83
|
+
queryVars?: accounts.subgraph.SingleSellerQueryVariables
|
|
84
|
+
): Promise<subgraph.SellerFieldsFragment> {
|
|
85
|
+
return accounts.subgraph.getSellerById(
|
|
86
|
+
this._subgraphUrl,
|
|
87
|
+
sellerId,
|
|
88
|
+
queryVars
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
81
92
|
public async getSellerByOperator(
|
|
82
93
|
operator: string,
|
|
83
|
-
|
|
94
|
+
queryVars?: subgraph.GetSellersQueryQueryVariables
|
|
84
95
|
): Promise<subgraph.SellerFieldsFragment> {
|
|
85
96
|
return accounts.subgraph.getSellerByOperator(
|
|
86
97
|
this._subgraphUrl,
|
|
87
98
|
operator,
|
|
88
|
-
|
|
99
|
+
queryVars
|
|
89
100
|
);
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
public async getSellerByClerk(
|
|
93
104
|
clerk: string,
|
|
94
|
-
|
|
105
|
+
queryVars?: subgraph.GetSellersQueryQueryVariables
|
|
95
106
|
): Promise<subgraph.SellerFieldsFragment> {
|
|
96
107
|
return accounts.subgraph.getSellerByClerk(
|
|
97
108
|
this._subgraphUrl,
|
|
98
109
|
clerk,
|
|
99
|
-
|
|
110
|
+
queryVars
|
|
100
111
|
);
|
|
101
112
|
}
|
|
102
113
|
|
|
103
114
|
public async getSellerByAddress(
|
|
104
115
|
address: string,
|
|
105
|
-
|
|
116
|
+
queryVars?: subgraph.GetSellersQueryQueryVariables
|
|
106
117
|
): Promise<subgraph.SellerFieldsFragment> {
|
|
107
118
|
return accounts.subgraph.getSellerByAddress(
|
|
108
119
|
this._subgraphUrl,
|
|
109
120
|
address,
|
|
110
|
-
|
|
121
|
+
queryVars
|
|
111
122
|
);
|
|
112
123
|
}
|
|
113
124
|
|
|
125
|
+
public async getSellers(
|
|
126
|
+
queryVars?: subgraph.GetSellersQueryQueryVariables
|
|
127
|
+
): Promise<subgraph.SellerFieldsFragment[]> {
|
|
128
|
+
return accounts.subgraph.getSellers(this._subgraphUrl, queryVars);
|
|
129
|
+
}
|
|
130
|
+
|
|
114
131
|
public async createSellerAndOffer(
|
|
115
132
|
sellerToCreate: accounts.CreateSellerArgs,
|
|
116
133
|
offerToCreate: offers.CreateOfferArgs,
|
|
@@ -177,26 +194,16 @@ export class CoreSDK {
|
|
|
177
194
|
}
|
|
178
195
|
|
|
179
196
|
public async getOfferById(
|
|
180
|
-
offerId: BigNumberish
|
|
197
|
+
offerId: BigNumberish,
|
|
198
|
+
queryVars?: offers.subgraph.SingleOfferQueryVariables
|
|
181
199
|
): Promise<subgraph.OfferFieldsFragment> {
|
|
182
|
-
return offers.subgraph.getOfferById(this._subgraphUrl, offerId);
|
|
200
|
+
return offers.subgraph.getOfferById(this._subgraphUrl, offerId, queryVars);
|
|
183
201
|
}
|
|
184
202
|
|
|
185
|
-
public async
|
|
186
|
-
|
|
187
|
-
operatorAddress: string;
|
|
188
|
-
// TODO: add support for sellerId, adminAddress, clerkAddress, treasuryAddress
|
|
189
|
-
},
|
|
190
|
-
opts?: offers.subgraph.AllOffersQueryOpts
|
|
203
|
+
public async getOffers(
|
|
204
|
+
queryVars?: subgraph.GetOffersQueryQueryVariables
|
|
191
205
|
): Promise<subgraph.OfferFieldsFragment[]> {
|
|
192
|
-
|
|
193
|
-
return offers.subgraph.getAllOffersOfOperator(
|
|
194
|
-
this._subgraphUrl,
|
|
195
|
-
sellerFilter.operatorAddress,
|
|
196
|
-
opts
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
return [];
|
|
206
|
+
return offers.subgraph.getOffers(this._subgraphUrl, queryVars);
|
|
200
207
|
}
|
|
201
208
|
|
|
202
209
|
public async commitToOffer(
|
|
@@ -285,26 +292,66 @@ export class CoreSDK {
|
|
|
285
292
|
});
|
|
286
293
|
}
|
|
287
294
|
|
|
288
|
-
public async
|
|
289
|
-
|
|
295
|
+
public async getFundsById(
|
|
296
|
+
fundsId: BigNumberish,
|
|
297
|
+
queryVars?: subgraph.GetFundsByIdQueryVariables
|
|
298
|
+
): Promise<subgraph.FundsEntityFieldsFragment> {
|
|
299
|
+
return funds.subgraph.getFundsById(this._subgraphUrl, fundsId, queryVars);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
public async getFunds(
|
|
303
|
+
queryVars?: subgraph.GetFundsQueryVariables
|
|
290
304
|
): Promise<subgraph.FundsEntityFieldsFragment[]> {
|
|
291
|
-
return funds.subgraph.
|
|
305
|
+
return funds.subgraph.getFunds(this._subgraphUrl, queryVars);
|
|
292
306
|
}
|
|
293
307
|
|
|
294
308
|
public async getExchangeById(
|
|
295
|
-
exchangeId: BigNumberish
|
|
309
|
+
exchangeId: BigNumberish,
|
|
310
|
+
queryVars?: subgraph.GetExchangeByIdQueryQueryVariables
|
|
296
311
|
): Promise<subgraph.ExchangeFieldsFragment> {
|
|
297
|
-
return exchanges.subgraph.getExchangeById(
|
|
312
|
+
return exchanges.subgraph.getExchangeById(
|
|
313
|
+
this._subgraphUrl,
|
|
314
|
+
exchangeId,
|
|
315
|
+
queryVars
|
|
316
|
+
);
|
|
298
317
|
}
|
|
299
318
|
|
|
300
|
-
public async
|
|
301
|
-
|
|
302
|
-
opts?: exchanges.subgraph.ExchangesQueryOpts
|
|
319
|
+
public async getExchanges(
|
|
320
|
+
queryVars?: subgraph.GetExchangesQueryQueryVariables
|
|
303
321
|
): Promise<subgraph.ExchangeFieldsFragment[]> {
|
|
304
|
-
return exchanges.subgraph.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
322
|
+
return exchanges.subgraph.getExchanges(this._subgraphUrl, queryVars);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
public async revokeVoucher(
|
|
326
|
+
exchangeId: BigNumberish
|
|
327
|
+
): Promise<TransactionResponse> {
|
|
328
|
+
return exchanges.handler.revokeVoucher({
|
|
329
|
+
web3Lib: this._web3Lib,
|
|
330
|
+
contractAddress: this._protocolDiamond,
|
|
331
|
+
exchangeId,
|
|
332
|
+
subgraphUrl: this._subgraphUrl
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
public async cancelVoucher(
|
|
337
|
+
exchangeId: BigNumberish
|
|
338
|
+
): Promise<TransactionResponse> {
|
|
339
|
+
return exchanges.handler.cancelVoucher({
|
|
340
|
+
web3Lib: this._web3Lib,
|
|
341
|
+
contractAddress: this._protocolDiamond,
|
|
342
|
+
exchangeId,
|
|
343
|
+
subgraphUrl: this._subgraphUrl
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
public async redeemVoucher(
|
|
348
|
+
exchangeId: BigNumberish
|
|
349
|
+
): Promise<TransactionResponse> {
|
|
350
|
+
return exchanges.handler.redeemVoucher({
|
|
351
|
+
web3Lib: this._web3Lib,
|
|
352
|
+
contractAddress: this._protocolDiamond,
|
|
353
|
+
exchangeId,
|
|
354
|
+
subgraphUrl: this._subgraphUrl
|
|
355
|
+
});
|
|
309
356
|
}
|
|
310
357
|
}
|
package/src/exchanges/handler.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { BigNumberish } from "@ethersproject/bignumber";
|
|
2
2
|
import { Web3LibAdapter, TransactionResponse } from "@bosonprotocol/common";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
encodeCancelVoucher,
|
|
5
|
+
encodeCommitToOffer,
|
|
6
|
+
encodeRevokeVoucher,
|
|
7
|
+
encodeRedeemVoucher
|
|
8
|
+
} from "./interface";
|
|
4
9
|
import { getOfferById } from "../offers/subgraph";
|
|
10
|
+
import { getExchangeById } from "../exchanges/subgraph";
|
|
11
|
+
import { ExchangeFieldsFragment, ExchangeState } from "../subgraph";
|
|
5
12
|
|
|
6
13
|
export async function commitToOffer(args: {
|
|
7
14
|
buyer: string;
|
|
@@ -13,23 +20,23 @@ export async function commitToOffer(args: {
|
|
|
13
20
|
const offer = await getOfferById(args.subgraphUrl, args.offerId);
|
|
14
21
|
|
|
15
22
|
if (!offer) {
|
|
16
|
-
throw new Error(`Offer with id
|
|
23
|
+
throw new Error(`Offer with id ${args.offerId} does not exist`);
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
if (offer.voidedAt) {
|
|
20
|
-
throw new Error(`Offer with id
|
|
27
|
+
throw new Error(`Offer with id ${args.offerId} has been voided`);
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
if (Date.now() < Number(offer.validFromDate) * 1000) {
|
|
24
|
-
throw new Error(`Offer with id
|
|
31
|
+
throw new Error(`Offer with id ${args.offerId} is not valid yet`);
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
if (Date.now() >= Number(offer.validUntilDate) * 1000) {
|
|
28
|
-
throw new Error(`Offer with id
|
|
35
|
+
throw new Error(`Offer with id ${args.offerId} is not valid anymore`);
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
if (Number(offer.quantityAvailable) === 0) {
|
|
32
|
-
throw new Error(`Offer with id
|
|
39
|
+
throw new Error(`Offer with id ${args.offerId} is sold out`);
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
return args.web3Lib.sendTransaction({
|
|
@@ -38,3 +45,113 @@ export async function commitToOffer(args: {
|
|
|
38
45
|
value: offer.price
|
|
39
46
|
});
|
|
40
47
|
}
|
|
48
|
+
|
|
49
|
+
export async function revokeVoucher(args: {
|
|
50
|
+
exchangeId: BigNumberish;
|
|
51
|
+
contractAddress: string;
|
|
52
|
+
subgraphUrl: string;
|
|
53
|
+
web3Lib: Web3LibAdapter;
|
|
54
|
+
}): Promise<TransactionResponse> {
|
|
55
|
+
const [exchange, signerAddress] = await Promise.all([
|
|
56
|
+
getExchangeById(args.subgraphUrl, args.exchangeId),
|
|
57
|
+
args.web3Lib.getSignerAddress()
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
assertExchange(args.exchangeId, exchange);
|
|
61
|
+
assertExchangeState(exchange, ExchangeState.Committed);
|
|
62
|
+
assertSignerIsOperator(signerAddress, exchange);
|
|
63
|
+
|
|
64
|
+
return args.web3Lib.sendTransaction({
|
|
65
|
+
to: args.contractAddress,
|
|
66
|
+
data: encodeRevokeVoucher(args.exchangeId)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function cancelVoucher(args: {
|
|
71
|
+
exchangeId: BigNumberish;
|
|
72
|
+
contractAddress: string;
|
|
73
|
+
subgraphUrl: string;
|
|
74
|
+
web3Lib: Web3LibAdapter;
|
|
75
|
+
}): Promise<TransactionResponse> {
|
|
76
|
+
const [exchange, signerAddress] = await Promise.all([
|
|
77
|
+
getExchangeById(args.subgraphUrl, args.exchangeId),
|
|
78
|
+
args.web3Lib.getSignerAddress()
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
assertExchange(args.exchangeId, exchange);
|
|
82
|
+
assertExchangeState(exchange, ExchangeState.Committed);
|
|
83
|
+
assertSignerIsBuyer(signerAddress, exchange);
|
|
84
|
+
|
|
85
|
+
return args.web3Lib.sendTransaction({
|
|
86
|
+
to: args.contractAddress,
|
|
87
|
+
data: encodeCancelVoucher(args.exchangeId)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function redeemVoucher(args: {
|
|
92
|
+
exchangeId: BigNumberish;
|
|
93
|
+
contractAddress: string;
|
|
94
|
+
subgraphUrl: string;
|
|
95
|
+
web3Lib: Web3LibAdapter;
|
|
96
|
+
}): Promise<TransactionResponse> {
|
|
97
|
+
const [exchange, signerAddress] = await Promise.all([
|
|
98
|
+
getExchangeById(args.subgraphUrl, args.exchangeId),
|
|
99
|
+
args.web3Lib.getSignerAddress()
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
assertExchange(args.exchangeId, exchange);
|
|
103
|
+
assertExchangeState(exchange, ExchangeState.Committed);
|
|
104
|
+
assertSignerIsBuyer(signerAddress, exchange);
|
|
105
|
+
|
|
106
|
+
if (Date.now() < Number(exchange.offer.voucherRedeemableFromDate) * 1000) {
|
|
107
|
+
throw new Error(`Voucher not redeemable yet`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (Date.now() > Number(exchange.validUntilDate) * 1000) {
|
|
111
|
+
throw new Error(`Voucher can not be redeemed anymore`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return args.web3Lib.sendTransaction({
|
|
115
|
+
to: args.contractAddress,
|
|
116
|
+
data: encodeRedeemVoucher(args.exchangeId)
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function assertExchange(
|
|
121
|
+
exchangeId: BigNumberish,
|
|
122
|
+
exchange?: ExchangeFieldsFragment
|
|
123
|
+
) {
|
|
124
|
+
if (!exchange) {
|
|
125
|
+
throw new Error(`Exchange with id ${exchangeId} does not exist`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function assertExchangeState(
|
|
130
|
+
exchange: ExchangeFieldsFragment,
|
|
131
|
+
requiredState: ExchangeState
|
|
132
|
+
) {
|
|
133
|
+
if (exchange.state !== requiredState) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`Exchange with id ${exchange.id} not in required state: ${requiredState}, actual state: ${exchange.state}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function assertSignerIsOperator(
|
|
141
|
+
signer: string,
|
|
142
|
+
exchange: ExchangeFieldsFragment
|
|
143
|
+
) {
|
|
144
|
+
if (exchange.seller.operator.toLowerCase() !== signer.toLowerCase()) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
`Signer ${signer} is not the operator ${exchange.seller.operator}`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function assertSignerIsBuyer(signer: string, exchange: ExchangeFieldsFragment) {
|
|
152
|
+
if (exchange.buyer.wallet.toLowerCase() !== signer.toLowerCase()) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
`Signer ${signer} is not the buyer ${exchange.buyer.wallet}`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -12,3 +12,31 @@ export function encodeCommitToOffer(buyer: string, offerId: BigNumberish) {
|
|
|
12
12
|
offerId
|
|
13
13
|
]);
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
export function encodeCompleteExchange(exchangeId: BigNumberish) {
|
|
17
|
+
return bosonExchangeHandlerIface.encodeFunctionData("completeExchange", [
|
|
18
|
+
exchangeId
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function encodeRevokeVoucher(exchangeId: BigNumberish) {
|
|
23
|
+
return bosonExchangeHandlerIface.encodeFunctionData("revokeVoucher", [
|
|
24
|
+
exchangeId
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function encodeCancelVoucher(exchangeId: BigNumberish) {
|
|
29
|
+
return bosonExchangeHandlerIface.encodeFunctionData("cancelVoucher", [
|
|
30
|
+
exchangeId
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
export function encodeExpireVoucher(exchangeId: BigNumberish) {
|
|
34
|
+
return bosonExchangeHandlerIface.encodeFunctionData("expireVoucher", [
|
|
35
|
+
exchangeId
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
export function encodeRedeemVoucher(exchangeId: BigNumberish) {
|
|
39
|
+
return bosonExchangeHandlerIface.encodeFunctionData("redeemVoucher", [
|
|
40
|
+
exchangeId
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
@@ -4,46 +4,46 @@ query getExchangeByIdQuery($exchangeId: ID!) {
|
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
query
|
|
8
|
-
$
|
|
9
|
-
$
|
|
10
|
-
$
|
|
11
|
-
$
|
|
12
|
-
$
|
|
7
|
+
query getExchangesQuery(
|
|
8
|
+
$exchangesSkip: Int
|
|
9
|
+
$exchangesFirst: Int
|
|
10
|
+
$exchangesOrderBy: Exchange_orderBy
|
|
11
|
+
$exchangesOrderDirection: OrderDirection
|
|
12
|
+
$exchangesFilter: Exchange_filter
|
|
13
13
|
) {
|
|
14
14
|
exchanges(
|
|
15
|
-
|
|
16
|
-
first: $
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
skip: $exchangesSkip
|
|
16
|
+
first: $exchangesFirst
|
|
17
|
+
orderBy: $exchangesOrderBy
|
|
18
|
+
orderDirection: $exchangesOrderDirection
|
|
19
|
+
where: $exchangesFilter
|
|
20
20
|
) {
|
|
21
21
|
...ExchangeFields
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
fragment ExchangeFields on Exchange {
|
|
26
|
-
|
|
26
|
+
...BaseExchangeFields
|
|
27
27
|
buyer {
|
|
28
|
-
|
|
29
|
-
wallet
|
|
30
|
-
active
|
|
28
|
+
...BaseBuyerFields
|
|
31
29
|
}
|
|
32
30
|
seller {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
active
|
|
31
|
+
...BaseSellerFields
|
|
32
|
+
}
|
|
33
|
+
offer {
|
|
34
|
+
...BaseOfferFields
|
|
38
35
|
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fragment BaseExchangeFields on Exchange {
|
|
39
|
+
id
|
|
39
40
|
disputed
|
|
40
41
|
state
|
|
41
42
|
committedDate
|
|
42
43
|
finalizedDate
|
|
43
44
|
validUntilDate
|
|
44
45
|
redeemedDate
|
|
46
|
+
revokedDate
|
|
47
|
+
cancelledDate
|
|
45
48
|
expired
|
|
46
|
-
offer {
|
|
47
|
-
...OfferFields
|
|
48
|
-
}
|
|
49
49
|
}
|