@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.
- package/dist/cjs/accounts/subgraph.d.ts +9 -9
- package/dist/cjs/accounts/subgraph.d.ts.map +1 -1
- package/dist/cjs/accounts/subgraph.js +50 -26
- package/dist/cjs/accounts/subgraph.js.map +1 -1
- package/dist/cjs/accounts/types.d.ts +8 -0
- package/dist/cjs/accounts/types.d.ts.map +1 -1
- package/dist/cjs/core-sdk.d.ts +10 -15
- package/dist/cjs/core-sdk.d.ts.map +1 -1
- package/dist/cjs/core-sdk.js +15 -67
- package/dist/cjs/core-sdk.js.map +1 -1
- package/dist/cjs/exchanges/handler.d.ts +0 -18
- package/dist/cjs/exchanges/handler.d.ts.map +1 -1
- package/dist/cjs/exchanges/handler.js +6 -82
- package/dist/cjs/exchanges/handler.js.map +1 -1
- package/dist/cjs/exchanges/index.d.ts +0 -1
- package/dist/cjs/exchanges/index.d.ts.map +1 -1
- package/dist/cjs/exchanges/index.js +1 -2
- package/dist/cjs/exchanges/index.js.map +1 -1
- package/dist/cjs/exchanges/interface.d.ts +0 -5
- package/dist/cjs/exchanges/interface.d.ts.map +1 -1
- package/dist/cjs/exchanges/interface.js +1 -31
- package/dist/cjs/exchanges/interface.js.map +1 -1
- package/dist/cjs/funds/index.d.ts +1 -0
- package/dist/cjs/funds/index.d.ts.map +1 -1
- package/dist/cjs/funds/index.js +4 -0
- package/dist/cjs/funds/index.js.map +1 -1
- package/dist/cjs/funds/subgraph.d.ts +4 -4
- package/dist/cjs/funds/subgraph.d.ts.map +1 -1
- package/dist/cjs/funds/subgraph.js +28 -14
- package/dist/cjs/funds/subgraph.js.map +1 -1
- package/dist/cjs/funds/types.d.ts +12 -0
- package/dist/cjs/funds/types.d.ts.map +1 -0
- package/dist/cjs/funds/types.js +3 -0
- package/dist/cjs/funds/types.js.map +1 -0
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/offers/index.d.ts +0 -1
- package/dist/cjs/offers/index.d.ts.map +1 -1
- package/dist/cjs/offers/index.js +0 -1
- package/dist/cjs/offers/index.js.map +1 -1
- package/dist/cjs/offers/interface.d.ts.map +1 -1
- package/dist/cjs/offers/interface.js +4 -11
- package/dist/cjs/offers/interface.js.map +1 -1
- package/dist/cjs/offers/subgraph.d.ts +8 -4
- package/dist/cjs/offers/subgraph.d.ts.map +1 -1
- package/dist/cjs/offers/subgraph.js +100 -10
- package/dist/cjs/offers/subgraph.js.map +1 -1
- package/dist/cjs/offers/types.d.ts +50 -0
- package/dist/cjs/offers/types.d.ts.map +1 -1
- package/dist/cjs/utils/errors.d.ts +10 -0
- package/dist/cjs/utils/errors.d.ts.map +1 -0
- package/dist/cjs/utils/errors.js +12 -0
- package/dist/cjs/utils/errors.js.map +1 -0
- package/dist/cjs/utils/subgraph.d.ts +8 -0
- package/dist/cjs/utils/subgraph.d.ts.map +1 -0
- package/dist/cjs/utils/subgraph.js +46 -0
- package/dist/cjs/utils/subgraph.js.map +1 -0
- package/dist/esm/accounts/subgraph.d.ts +9 -9
- package/dist/esm/accounts/subgraph.d.ts.map +1 -1
- package/dist/esm/accounts/subgraph.js +51 -42
- package/dist/esm/accounts/subgraph.js.map +1 -1
- package/dist/esm/accounts/types.d.ts +8 -0
- package/dist/esm/accounts/types.d.ts.map +1 -1
- package/dist/esm/core-sdk.d.ts +10 -15
- package/dist/esm/core-sdk.d.ts.map +1 -1
- package/dist/esm/core-sdk.js +15 -51
- package/dist/esm/core-sdk.js.map +1 -1
- package/dist/esm/exchanges/handler.d.ts +0 -18
- package/dist/esm/exchanges/handler.d.ts.map +1 -1
- package/dist/esm/exchanges/handler.js +6 -73
- package/dist/esm/exchanges/handler.js.map +1 -1
- package/dist/esm/exchanges/index.d.ts +0 -1
- package/dist/esm/exchanges/index.d.ts.map +1 -1
- package/dist/esm/exchanges/index.js +0 -1
- package/dist/esm/exchanges/index.js.map +1 -1
- package/dist/esm/exchanges/interface.d.ts +0 -5
- package/dist/esm/exchanges/interface.d.ts.map +1 -1
- package/dist/esm/exchanges/interface.js +0 -25
- package/dist/esm/exchanges/interface.js.map +1 -1
- package/dist/esm/funds/index.d.ts +1 -0
- package/dist/esm/funds/index.d.ts.map +1 -1
- package/dist/esm/funds/index.js +1 -0
- package/dist/esm/funds/index.js.map +1 -1
- package/dist/esm/funds/subgraph.d.ts +4 -4
- package/dist/esm/funds/subgraph.d.ts.map +1 -1
- package/dist/esm/funds/subgraph.js +26 -12
- package/dist/esm/funds/subgraph.js.map +1 -1
- package/dist/esm/funds/types.d.ts +12 -0
- package/dist/esm/funds/types.d.ts.map +1 -0
- package/dist/esm/funds/types.js +2 -0
- package/dist/esm/funds/types.js.map +1 -0
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/offers/index.d.ts +0 -1
- package/dist/esm/offers/index.d.ts.map +1 -1
- package/dist/esm/offers/index.js +0 -1
- package/dist/esm/offers/index.js.map +1 -1
- package/dist/esm/offers/interface.d.ts.map +1 -1
- package/dist/esm/offers/interface.js +4 -11
- package/dist/esm/offers/interface.js.map +1 -1
- package/dist/esm/offers/subgraph.d.ts +8 -4
- package/dist/esm/offers/subgraph.d.ts.map +1 -1
- package/dist/esm/offers/subgraph.js +104 -12
- package/dist/esm/offers/subgraph.js.map +1 -1
- package/dist/esm/offers/types.d.ts +50 -0
- package/dist/esm/offers/types.d.ts.map +1 -1
- package/dist/esm/utils/errors.d.ts +10 -0
- package/dist/esm/utils/errors.d.ts.map +1 -0
- package/dist/esm/utils/errors.js +10 -0
- package/dist/esm/utils/errors.js.map +1 -0
- package/dist/esm/utils/subgraph.d.ts +8 -0
- package/dist/esm/utils/subgraph.d.ts.map +1 -0
- package/dist/esm/utils/subgraph.js +28 -0
- package/dist/esm/utils/subgraph.js.map +1 -0
- package/package.json +4 -7
- package/src/accounts/subgraph.ts +65 -66
- package/src/accounts/types.ts +9 -0
- package/src/core-sdk.ts +32 -112
- package/src/exchanges/handler.ts +6 -123
- package/src/exchanges/index.ts +0 -1
- package/src/exchanges/interface.ts +0 -28
- package/src/funds/index.ts +1 -0
- package/src/funds/subgraph.ts +31 -27
- package/src/funds/types.ts +11 -0
- package/src/index.ts +0 -1
- package/src/offers/index.ts +0 -1
- package/src/offers/interface.ts +6 -16
- package/src/offers/subgraph.ts +120 -26
- package/src/offers/types.ts +51 -0
- package/src/utils/errors.ts +14 -0
- package/src/utils/subgraph.ts +43 -0
- package/dist/cjs/exchanges/subgraph.d.ts +0 -6
- package/dist/cjs/exchanges/subgraph.d.ts.map +0 -1
- package/dist/cjs/exchanges/subgraph.js +0 -30
- package/dist/cjs/exchanges/subgraph.js.map +0 -1
- package/dist/cjs/offers/getOfferStatus.d.ts +0 -9
- package/dist/cjs/offers/getOfferStatus.d.ts.map +0 -1
- package/dist/cjs/offers/getOfferStatus.js +0 -26
- package/dist/cjs/offers/getOfferStatus.js.map +0 -1
- package/dist/cjs/subgraph.d.ts +0 -3148
- package/dist/cjs/subgraph.d.ts.map +0 -1
- package/dist/cjs/subgraph.js +0 -539
- package/dist/cjs/subgraph.js.map +0 -1
- package/dist/cjs/utils/graphql.d.ts +0 -91
- package/dist/cjs/utils/graphql.d.ts.map +0 -1
- package/dist/cjs/utils/graphql.js +0 -11
- package/dist/cjs/utils/graphql.js.map +0 -1
- package/dist/esm/exchanges/subgraph.d.ts +0 -6
- package/dist/esm/exchanges/subgraph.d.ts.map +0 -1
- package/dist/esm/exchanges/subgraph.js +0 -15
- package/dist/esm/exchanges/subgraph.js.map +0 -1
- package/dist/esm/offers/getOfferStatus.d.ts +0 -9
- package/dist/esm/offers/getOfferStatus.d.ts.map +0 -1
- package/dist/esm/offers/getOfferStatus.js +0 -22
- package/dist/esm/offers/getOfferStatus.js.map +0 -1
- package/dist/esm/subgraph.d.ts +0 -3148
- package/dist/esm/subgraph.d.ts.map +0 -1
- package/dist/esm/subgraph.js +0 -541
- package/dist/esm/subgraph.js.map +0 -1
- package/dist/esm/utils/graphql.d.ts +0 -91
- package/dist/esm/utils/graphql.d.ts.map +0 -1
- package/dist/esm/utils/graphql.js +0 -7
- package/dist/esm/utils/graphql.js.map +0 -1
- package/src/accounts/queries.graphql +0 -107
- package/src/exchanges/queries.graphql +0 -49
- package/src/exchanges/subgraph.ts +0 -35
- package/src/funds/queries.graphql +0 -35
- package/src/offers/getOfferStatus.ts +0 -27
- package/src/offers/queries.graphql +0 -88
- package/src/subgraph.ts +0 -3731
- package/src/utils/graphql.ts +0 -7
package/src/accounts/subgraph.ts
CHANGED
|
@@ -1,92 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
SellerFieldsFragment,
|
|
4
|
-
GetSellersQueryQueryVariables,
|
|
5
|
-
GetSellerByIdQueryQueryVariables
|
|
6
|
-
} from "../subgraph";
|
|
7
|
-
import { BigNumberish } from "@ethersproject/bignumber";
|
|
1
|
+
import { fetchSubgraph } from "../utils/subgraph";
|
|
2
|
+
import { RawSellerFromSubgraph } from "./types";
|
|
8
3
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
queryVars: SingleSellerQueryVariables = {}
|
|
18
|
-
): Promise<SellerFieldsFragment> {
|
|
19
|
-
const sdk = getSubgraphSdk(subgraphUrl);
|
|
20
|
-
const { seller } = await sdk.getSellerByIdQuery({
|
|
21
|
-
sellerId: sellerId.toString(),
|
|
22
|
-
...queryVars
|
|
23
|
-
});
|
|
24
|
-
return seller;
|
|
4
|
+
export const sellerFieldsFragment = `
|
|
5
|
+
fragment sellerFields on Seller {
|
|
6
|
+
id
|
|
7
|
+
operator
|
|
8
|
+
admin
|
|
9
|
+
clerk
|
|
10
|
+
treasury
|
|
11
|
+
active
|
|
25
12
|
}
|
|
13
|
+
`;
|
|
26
14
|
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
export const getSellerByOperatorQuery = `
|
|
16
|
+
query GetSellersByOperator($operator: String!) {
|
|
17
|
+
sellers(where: {
|
|
18
|
+
operator: $operator
|
|
19
|
+
}) {
|
|
20
|
+
...sellerFields
|
|
21
|
+
}
|
|
34
22
|
}
|
|
23
|
+
${sellerFieldsFragment}
|
|
24
|
+
`;
|
|
35
25
|
|
|
36
26
|
export async function getSellerByOperator(
|
|
37
27
|
subgraphUrl: string,
|
|
38
|
-
operatorAddress: string
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
operator: operatorAddress.toLowerCase()
|
|
45
|
-
},
|
|
46
|
-
...queryVars
|
|
47
|
-
});
|
|
28
|
+
operatorAddress: string
|
|
29
|
+
): Promise<RawSellerFromSubgraph> {
|
|
30
|
+
const { sellers = [] } = await fetchSubgraph<{
|
|
31
|
+
sellers: RawSellerFromSubgraph[];
|
|
32
|
+
}>(subgraphUrl, getSellerByOperatorQuery, { operator: operatorAddress });
|
|
33
|
+
|
|
48
34
|
return sellers[0];
|
|
49
35
|
}
|
|
50
36
|
|
|
37
|
+
export const getSellerByAdminQuery = `
|
|
38
|
+
query GetSellersByAdmin($admin: String!) {
|
|
39
|
+
sellers(where: {
|
|
40
|
+
admin: $admin
|
|
41
|
+
}) {
|
|
42
|
+
...sellerFields
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
${sellerFieldsFragment}
|
|
46
|
+
`;
|
|
47
|
+
|
|
51
48
|
export async function getSellerByAdmin(
|
|
52
49
|
subgraphUrl: string,
|
|
53
|
-
adminAddress: string
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
admin: adminAddress.toLowerCase()
|
|
60
|
-
},
|
|
61
|
-
...queryVars
|
|
62
|
-
});
|
|
50
|
+
adminAddress: string
|
|
51
|
+
): Promise<RawSellerFromSubgraph> {
|
|
52
|
+
const { sellers = [] } = await fetchSubgraph<{
|
|
53
|
+
sellers: RawSellerFromSubgraph[];
|
|
54
|
+
}>(subgraphUrl, getSellerByAdminQuery, { admin: adminAddress });
|
|
55
|
+
|
|
63
56
|
return sellers[0];
|
|
64
57
|
}
|
|
65
58
|
|
|
59
|
+
export const getSellerByClerkQuery = `
|
|
60
|
+
query GetSellersByOperator($clerk: String!) {
|
|
61
|
+
sellers(where: {
|
|
62
|
+
clerk: $clerk
|
|
63
|
+
}) {
|
|
64
|
+
...sellerFields
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
${sellerFieldsFragment}
|
|
68
|
+
`;
|
|
69
|
+
|
|
66
70
|
export async function getSellerByClerk(
|
|
67
71
|
subgraphUrl: string,
|
|
68
|
-
clerkAddress: string
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
clerk: clerkAddress.toLowerCase()
|
|
75
|
-
},
|
|
76
|
-
...queryVars
|
|
77
|
-
});
|
|
72
|
+
clerkAddress: string
|
|
73
|
+
): Promise<RawSellerFromSubgraph> {
|
|
74
|
+
const { sellers = [] } = await fetchSubgraph<{
|
|
75
|
+
sellers: RawSellerFromSubgraph[];
|
|
76
|
+
}>(subgraphUrl, getSellerByClerkQuery, { clerk: clerkAddress });
|
|
77
|
+
|
|
78
78
|
return sellers[0];
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export async function getSellerByAddress(
|
|
82
82
|
subgraphUrl: string,
|
|
83
|
-
address: string
|
|
84
|
-
|
|
85
|
-
): Promise<SellerFieldsFragment> {
|
|
83
|
+
address: string
|
|
84
|
+
): Promise<RawSellerFromSubgraph> {
|
|
86
85
|
const [operator, admin, clerk] = await Promise.all([
|
|
87
|
-
getSellerByOperator(subgraphUrl, address
|
|
88
|
-
getSellerByAdmin(subgraphUrl, address
|
|
89
|
-
getSellerByClerk(subgraphUrl, address
|
|
86
|
+
getSellerByOperator(subgraphUrl, address),
|
|
87
|
+
getSellerByAdmin(subgraphUrl, address),
|
|
88
|
+
getSellerByClerk(subgraphUrl, address)
|
|
90
89
|
]);
|
|
91
90
|
|
|
92
91
|
return operator || admin || clerk;
|
package/src/accounts/types.ts
CHANGED
package/src/core-sdk.ts
CHANGED
|
@@ -15,9 +15,8 @@ import * as offers from "./offers";
|
|
|
15
15
|
import * as orchestration from "./orchestration";
|
|
16
16
|
import * as erc20 from "./erc20";
|
|
17
17
|
import * as funds from "./funds";
|
|
18
|
-
import * as subgraph from "./subgraph";
|
|
19
|
-
|
|
20
18
|
import { getValueFromLogs } from "./utils/logs";
|
|
19
|
+
import { MultiQueryOpts } from "./utils/subgraph";
|
|
21
20
|
|
|
22
21
|
export class CoreSDK {
|
|
23
22
|
private _web3Lib: Web3LibAdapter;
|
|
@@ -78,54 +77,22 @@ export class CoreSDK {
|
|
|
78
77
|
return this._metadataStorage.getMetadata(metadataHashOrUri);
|
|
79
78
|
}
|
|
80
79
|
|
|
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
|
-
|
|
92
80
|
public async getSellerByOperator(
|
|
93
|
-
operator: string
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return accounts.subgraph.getSellerByOperator(
|
|
97
|
-
this._subgraphUrl,
|
|
98
|
-
operator,
|
|
99
|
-
queryVars
|
|
100
|
-
);
|
|
81
|
+
operator: string
|
|
82
|
+
): Promise<accounts.RawSellerFromSubgraph> {
|
|
83
|
+
return accounts.subgraph.getSellerByOperator(this._subgraphUrl, operator);
|
|
101
84
|
}
|
|
102
85
|
|
|
103
86
|
public async getSellerByClerk(
|
|
104
|
-
clerk: string
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return accounts.subgraph.getSellerByClerk(
|
|
108
|
-
this._subgraphUrl,
|
|
109
|
-
clerk,
|
|
110
|
-
queryVars
|
|
111
|
-
);
|
|
87
|
+
clerk: string
|
|
88
|
+
): Promise<accounts.RawSellerFromSubgraph> {
|
|
89
|
+
return accounts.subgraph.getSellerByClerk(this._subgraphUrl, clerk);
|
|
112
90
|
}
|
|
113
91
|
|
|
114
92
|
public async getSellerByAddress(
|
|
115
|
-
address: string
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return accounts.subgraph.getSellerByAddress(
|
|
119
|
-
this._subgraphUrl,
|
|
120
|
-
address,
|
|
121
|
-
queryVars
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public async getSellers(
|
|
126
|
-
queryVars?: subgraph.GetSellersQueryQueryVariables
|
|
127
|
-
): Promise<subgraph.SellerFieldsFragment[]> {
|
|
128
|
-
return accounts.subgraph.getSellers(this._subgraphUrl, queryVars);
|
|
93
|
+
address: string
|
|
94
|
+
): Promise<accounts.RawSellerFromSubgraph> {
|
|
95
|
+
return accounts.subgraph.getSellerByAddress(this._subgraphUrl, address);
|
|
129
96
|
}
|
|
130
97
|
|
|
131
98
|
public async createSellerAndOffer(
|
|
@@ -194,16 +161,26 @@ export class CoreSDK {
|
|
|
194
161
|
}
|
|
195
162
|
|
|
196
163
|
public async getOfferById(
|
|
197
|
-
offerId: BigNumberish
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return offers.subgraph.getOfferById(this._subgraphUrl, offerId, queryVars);
|
|
164
|
+
offerId: BigNumberish
|
|
165
|
+
): Promise<offers.RawOfferFromSubgraph> {
|
|
166
|
+
return offers.subgraph.getOfferById(this._subgraphUrl, offerId);
|
|
201
167
|
}
|
|
202
168
|
|
|
203
|
-
public async
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
169
|
+
public async getAllOffersOfSeller(
|
|
170
|
+
sellerFilter: {
|
|
171
|
+
operatorAddress: string;
|
|
172
|
+
// TODO: add support for sellerId, adminAddress, clerkAddress, treasuryAddress
|
|
173
|
+
},
|
|
174
|
+
opts: MultiQueryOpts = {}
|
|
175
|
+
): Promise<offers.RawOfferFromSubgraph[]> {
|
|
176
|
+
if (sellerFilter.operatorAddress) {
|
|
177
|
+
return offers.subgraph.getAllOffersOfOperator(
|
|
178
|
+
this._subgraphUrl,
|
|
179
|
+
sellerFilter.operatorAddress,
|
|
180
|
+
opts
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return [];
|
|
207
184
|
}
|
|
208
185
|
|
|
209
186
|
public async commitToOffer(
|
|
@@ -292,66 +269,9 @@ export class CoreSDK {
|
|
|
292
269
|
});
|
|
293
270
|
}
|
|
294
271
|
|
|
295
|
-
public async
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return funds.subgraph.getFundsById(this._subgraphUrl, fundsId, queryVars);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
public async getFunds(
|
|
303
|
-
queryVars?: subgraph.GetFundsQueryVariables
|
|
304
|
-
): Promise<subgraph.FundsEntityFieldsFragment[]> {
|
|
305
|
-
return funds.subgraph.getFunds(this._subgraphUrl, queryVars);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
public async getExchangeById(
|
|
309
|
-
exchangeId: BigNumberish,
|
|
310
|
-
queryVars?: subgraph.GetExchangeByIdQueryQueryVariables
|
|
311
|
-
): Promise<subgraph.ExchangeFieldsFragment> {
|
|
312
|
-
return exchanges.subgraph.getExchangeById(
|
|
313
|
-
this._subgraphUrl,
|
|
314
|
-
exchangeId,
|
|
315
|
-
queryVars
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
public async getExchanges(
|
|
320
|
-
queryVars?: subgraph.GetExchangesQueryQueryVariables
|
|
321
|
-
): Promise<subgraph.ExchangeFieldsFragment[]> {
|
|
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
|
-
});
|
|
272
|
+
public async getFundsByAccountId(
|
|
273
|
+
accountId: BigNumberish
|
|
274
|
+
): Promise<funds.RawFundsEntityFromSubgraph[]> {
|
|
275
|
+
return funds.subgraph.getFundsByAccountId(this._subgraphUrl, accountId);
|
|
356
276
|
}
|
|
357
277
|
}
|
package/src/exchanges/handler.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { BigNumberish } from "@ethersproject/bignumber";
|
|
2
2
|
import { Web3LibAdapter, TransactionResponse } from "@bosonprotocol/common";
|
|
3
|
-
import {
|
|
4
|
-
encodeCancelVoucher,
|
|
5
|
-
encodeCommitToOffer,
|
|
6
|
-
encodeRevokeVoucher,
|
|
7
|
-
encodeRedeemVoucher
|
|
8
|
-
} from "./interface";
|
|
3
|
+
import { encodeCommitToOffer } from "./interface";
|
|
9
4
|
import { getOfferById } from "../offers/subgraph";
|
|
10
|
-
import { getExchangeById } from "../exchanges/subgraph";
|
|
11
|
-
import { ExchangeFieldsFragment, ExchangeState } from "../subgraph";
|
|
12
5
|
|
|
13
6
|
export async function commitToOffer(args: {
|
|
14
7
|
buyer: string;
|
|
@@ -20,23 +13,23 @@ export async function commitToOffer(args: {
|
|
|
20
13
|
const offer = await getOfferById(args.subgraphUrl, args.offerId);
|
|
21
14
|
|
|
22
15
|
if (!offer) {
|
|
23
|
-
throw new Error(`Offer with id ${args.offerId} does not exist`);
|
|
16
|
+
throw new Error(`Offer with id "${args.offerId}" does not exist`);
|
|
24
17
|
}
|
|
25
18
|
|
|
26
19
|
if (offer.voidedAt) {
|
|
27
|
-
throw new Error(`Offer with id ${args.offerId} has been voided`);
|
|
20
|
+
throw new Error(`Offer with id "${args.offerId}" has been voided`);
|
|
28
21
|
}
|
|
29
22
|
|
|
30
23
|
if (Date.now() < Number(offer.validFromDate) * 1000) {
|
|
31
|
-
throw new Error(`Offer with id ${args.offerId} is not valid yet`);
|
|
24
|
+
throw new Error(`Offer with id "${args.offerId}" is not valid yet`);
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
if (Date.now() >= Number(offer.validUntilDate) * 1000) {
|
|
35
|
-
throw new Error(`Offer with id ${args.offerId} is not valid anymore`);
|
|
28
|
+
throw new Error(`Offer with id "${args.offerId}" is not valid anymore`);
|
|
36
29
|
}
|
|
37
30
|
|
|
38
31
|
if (Number(offer.quantityAvailable) === 0) {
|
|
39
|
-
throw new Error(`Offer with id ${args.offerId} is sold out`);
|
|
32
|
+
throw new Error(`Offer with id "${args.offerId}" is sold out`);
|
|
40
33
|
}
|
|
41
34
|
|
|
42
35
|
return args.web3Lib.sendTransaction({
|
|
@@ -45,113 +38,3 @@ export async function commitToOffer(args: {
|
|
|
45
38
|
value: offer.price
|
|
46
39
|
});
|
|
47
40
|
}
|
|
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
|
-
}
|
package/src/exchanges/index.ts
CHANGED
|
@@ -12,31 +12,3 @@ 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
|
-
}
|
package/src/funds/index.ts
CHANGED
package/src/funds/subgraph.ts
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import { getSubgraphSdk } from "../utils/graphql";
|
|
2
|
-
import {
|
|
3
|
-
FundsEntityFieldsFragment,
|
|
4
|
-
GetFundsByIdQueryVariables,
|
|
5
|
-
GetFundsQueryVariables
|
|
6
|
-
} from "../subgraph";
|
|
7
1
|
import { BigNumberish } from "@ethersproject/bignumber";
|
|
2
|
+
import { fetchSubgraph } from "../utils/subgraph";
|
|
3
|
+
import { RawFundsEntityFromSubgraph } from "./types";
|
|
8
4
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
export const fundsEntityFieldsFragment = `
|
|
6
|
+
fragment fundsEntityFields on FundsEntity {
|
|
7
|
+
id
|
|
8
|
+
availableAmount
|
|
9
|
+
token {
|
|
10
|
+
address
|
|
11
|
+
name
|
|
12
|
+
symbol
|
|
13
|
+
decimals
|
|
14
|
+
}
|
|
15
|
+
accountId
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
13
18
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
export const getFundsByAccountIdQuery = `
|
|
20
|
+
query GetFundsByAccountIdQuery($accountId: String!) {
|
|
21
|
+
fundsEntities(where: {
|
|
22
|
+
accountId: $accountId
|
|
23
|
+
}) {
|
|
24
|
+
...fundsEntityFields
|
|
25
|
+
}
|
|
21
26
|
}
|
|
27
|
+
${fundsEntityFieldsFragment}
|
|
28
|
+
`;
|
|
22
29
|
|
|
23
|
-
export async function
|
|
30
|
+
export async function getFundsByAccountId(
|
|
24
31
|
subgraphUrl: string,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
fundsId: fundsId.toString(),
|
|
31
|
-
...queryVars
|
|
32
|
-
});
|
|
32
|
+
accountId: BigNumberish
|
|
33
|
+
): Promise<RawFundsEntityFromSubgraph[]> {
|
|
34
|
+
const { fundsEntities = [] } = await fetchSubgraph<{
|
|
35
|
+
fundsEntities: RawFundsEntityFromSubgraph[];
|
|
36
|
+
}>(subgraphUrl, getFundsByAccountIdQuery, { accountId });
|
|
33
37
|
|
|
34
|
-
return
|
|
38
|
+
return fundsEntities;
|
|
35
39
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,6 @@ export * as exchanges from "./exchanges";
|
|
|
6
6
|
export * as orchestration from "./orchestration";
|
|
7
7
|
export * as erc20 from "./erc20";
|
|
8
8
|
export * as funds from "./funds";
|
|
9
|
-
export * as subgraph from "./subgraph";
|
|
10
9
|
|
|
11
10
|
export { defaultConfigs, getDefaultConfig } from "@bosonprotocol/common";
|
|
12
11
|
|
package/src/offers/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * as subgraph from "./subgraph";
|
|
|
5
5
|
export * as iface from "./interface";
|
|
6
6
|
export * as storage from "./storage";
|
|
7
7
|
export * from "./types";
|
|
8
|
-
export * from "./getOfferStatus";
|
|
9
8
|
|
|
10
9
|
export const validation = {
|
|
11
10
|
createOfferArgsSchema: utils.validation.createOfferArgsSchema
|