@bosonprotocol/core-sdk 1.23.0-alpha.2 → 1.23.0-alpha.21

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 (203) hide show
  1. package/dist/cjs/accounts/mixin.d.ts +194 -0
  2. package/dist/cjs/accounts/mixin.d.ts.map +1 -0
  3. package/dist/cjs/accounts/mixin.js +426 -0
  4. package/dist/cjs/accounts/mixin.js.map +1 -0
  5. package/dist/cjs/core-sdk.d.ts +16 -818
  6. package/dist/cjs/core-sdk.d.ts.map +1 -1
  7. package/dist/cjs/core-sdk.js +26 -1579
  8. package/dist/cjs/core-sdk.js.map +1 -1
  9. package/dist/cjs/disputes/mixin.d.ts +113 -0
  10. package/dist/cjs/disputes/mixin.d.ts.map +1 -0
  11. package/dist/cjs/disputes/mixin.js +203 -0
  12. package/dist/cjs/disputes/mixin.js.map +1 -0
  13. package/dist/cjs/erc1155/handler.d.ts +9 -0
  14. package/dist/cjs/erc1155/handler.d.ts.map +1 -0
  15. package/dist/cjs/erc1155/handler.js +28 -0
  16. package/dist/cjs/erc1155/handler.js.map +1 -0
  17. package/dist/cjs/erc1155/index.d.ts +3 -0
  18. package/dist/cjs/erc1155/index.d.ts.map +1 -0
  19. package/dist/cjs/erc1155/index.js +29 -0
  20. package/dist/cjs/erc1155/index.js.map +1 -0
  21. package/dist/cjs/erc1155/interface.d.ts +3 -0
  22. package/dist/cjs/erc1155/interface.d.ts.map +1 -0
  23. package/dist/cjs/erc1155/interface.js +7 -0
  24. package/dist/cjs/erc1155/interface.js.map +1 -0
  25. package/dist/cjs/erc20/handler.d.ts +5 -0
  26. package/dist/cjs/erc20/handler.d.ts.map +1 -1
  27. package/dist/cjs/erc20/handler.js +12 -1
  28. package/dist/cjs/erc20/handler.js.map +1 -1
  29. package/dist/cjs/erc721/handler.d.ts +5 -0
  30. package/dist/cjs/erc721/handler.d.ts.map +1 -1
  31. package/dist/cjs/erc721/handler.js +12 -1
  32. package/dist/cjs/erc721/handler.js.map +1 -1
  33. package/dist/cjs/event-logs/mixin.d.ts +11 -0
  34. package/dist/cjs/event-logs/mixin.d.ts.map +1 -0
  35. package/dist/cjs/event-logs/mixin.js +28 -0
  36. package/dist/cjs/event-logs/mixin.js.map +1 -0
  37. package/dist/cjs/exchanges/mixin.d.ts +77 -0
  38. package/dist/cjs/exchanges/mixin.d.ts.map +1 -0
  39. package/dist/cjs/exchanges/mixin.js +172 -0
  40. package/dist/cjs/exchanges/mixin.js.map +1 -0
  41. package/dist/cjs/funds/mixin.d.ts +42 -0
  42. package/dist/cjs/funds/mixin.d.ts.map +1 -0
  43. package/dist/cjs/funds/mixin.js +95 -0
  44. package/dist/cjs/funds/mixin.js.map +1 -0
  45. package/dist/cjs/groups/mixin.d.ts +14 -0
  46. package/dist/cjs/groups/mixin.d.ts.map +1 -0
  47. package/dist/cjs/groups/mixin.js +33 -0
  48. package/dist/cjs/groups/mixin.js.map +1 -0
  49. package/dist/cjs/meta-tx/mixin.d.ts +176 -0
  50. package/dist/cjs/meta-tx/mixin.d.ts.map +1 -0
  51. package/dist/cjs/meta-tx/mixin.js +296 -0
  52. package/dist/cjs/meta-tx/mixin.js.map +1 -0
  53. package/dist/cjs/metadata/mixin.d.ts +42 -0
  54. package/dist/cjs/metadata/mixin.d.ts.map +1 -0
  55. package/dist/cjs/metadata/mixin.js +89 -0
  56. package/dist/cjs/metadata/mixin.js.map +1 -0
  57. package/dist/cjs/metadata/subgraph.d.ts +3 -1
  58. package/dist/cjs/metadata/subgraph.d.ts.map +1 -1
  59. package/dist/cjs/metadata/subgraph.js +17 -1
  60. package/dist/cjs/metadata/subgraph.js.map +1 -1
  61. package/dist/cjs/mixins/base-core-sdk.d.ts +41 -0
  62. package/dist/cjs/mixins/base-core-sdk.d.ts.map +1 -0
  63. package/dist/cjs/mixins/base-core-sdk.js +51 -0
  64. package/dist/cjs/mixins/base-core-sdk.js.map +1 -0
  65. package/dist/cjs/native-meta-tx/mixin.d.ts +35 -0
  66. package/dist/cjs/native-meta-tx/mixin.d.ts.map +1 -0
  67. package/dist/cjs/native-meta-tx/mixin.js +68 -0
  68. package/dist/cjs/native-meta-tx/mixin.js.map +1 -0
  69. package/dist/cjs/offers/mixin.d.ts +133 -0
  70. package/dist/cjs/offers/mixin.d.ts.map +1 -0
  71. package/dist/cjs/offers/mixin.js +338 -0
  72. package/dist/cjs/offers/mixin.js.map +1 -0
  73. package/dist/cjs/orchestration/mixin.d.ts +28 -0
  74. package/dist/cjs/orchestration/mixin.d.ts.map +1 -0
  75. package/dist/cjs/orchestration/mixin.js +59 -0
  76. package/dist/cjs/orchestration/mixin.js.map +1 -0
  77. package/dist/cjs/subgraph.d.ts +3707 -1509
  78. package/dist/cjs/subgraph.d.ts.map +1 -1
  79. package/dist/cjs/subgraph.js +113 -4
  80. package/dist/cjs/subgraph.js.map +1 -1
  81. package/dist/cjs/utils/graphql.d.ts +14 -0
  82. package/dist/cjs/utils/graphql.d.ts.map +1 -1
  83. package/dist/cjs/utils/signature.d.ts.map +1 -1
  84. package/dist/cjs/utils/signature.js +5 -1
  85. package/dist/cjs/utils/signature.js.map +1 -1
  86. package/dist/cjs/utils/tokenInfoManager.d.ts +6 -2
  87. package/dist/cjs/utils/tokenInfoManager.d.ts.map +1 -1
  88. package/dist/cjs/utils/tokenInfoManager.js +39 -6
  89. package/dist/cjs/utils/tokenInfoManager.js.map +1 -1
  90. package/dist/esm/accounts/mixin.d.ts +194 -0
  91. package/dist/esm/accounts/mixin.d.ts.map +1 -0
  92. package/dist/esm/accounts/mixin.js +342 -0
  93. package/dist/esm/accounts/mixin.js.map +1 -0
  94. package/dist/esm/core-sdk.d.ts +16 -818
  95. package/dist/esm/core-sdk.d.ts.map +1 -1
  96. package/dist/esm/core-sdk.js +27 -1483
  97. package/dist/esm/core-sdk.js.map +1 -1
  98. package/dist/esm/disputes/mixin.d.ts +113 -0
  99. package/dist/esm/disputes/mixin.d.ts.map +1 -0
  100. package/dist/esm/disputes/mixin.js +173 -0
  101. package/dist/esm/disputes/mixin.js.map +1 -0
  102. package/dist/esm/erc1155/handler.d.ts +9 -0
  103. package/dist/esm/erc1155/handler.d.ts.map +1 -0
  104. package/dist/esm/erc1155/handler.js +13 -0
  105. package/dist/esm/erc1155/handler.js.map +1 -0
  106. package/dist/esm/erc1155/index.d.ts +3 -0
  107. package/dist/esm/erc1155/index.d.ts.map +1 -0
  108. package/dist/esm/erc1155/index.js +3 -0
  109. package/dist/esm/erc1155/index.js.map +1 -0
  110. package/dist/esm/erc1155/interface.d.ts +3 -0
  111. package/dist/esm/erc1155/interface.d.ts.map +1 -0
  112. package/dist/esm/erc1155/interface.js +4 -0
  113. package/dist/esm/erc1155/interface.js.map +1 -0
  114. package/dist/esm/erc20/handler.d.ts +5 -0
  115. package/dist/esm/erc20/handler.d.ts.map +1 -1
  116. package/dist/esm/erc20/handler.js +8 -0
  117. package/dist/esm/erc20/handler.js.map +1 -1
  118. package/dist/esm/erc721/handler.d.ts +5 -0
  119. package/dist/esm/erc721/handler.d.ts.map +1 -1
  120. package/dist/esm/erc721/handler.js +8 -0
  121. package/dist/esm/erc721/handler.js.map +1 -1
  122. package/dist/esm/event-logs/mixin.d.ts +11 -0
  123. package/dist/esm/event-logs/mixin.d.ts.map +1 -0
  124. package/dist/esm/event-logs/mixin.js +13 -0
  125. package/dist/esm/event-logs/mixin.js.map +1 -0
  126. package/dist/esm/exchanges/mixin.d.ts +77 -0
  127. package/dist/esm/exchanges/mixin.d.ts.map +1 -0
  128. package/dist/esm/exchanges/mixin.js +141 -0
  129. package/dist/esm/exchanges/mixin.js.map +1 -0
  130. package/dist/esm/funds/mixin.d.ts +42 -0
  131. package/dist/esm/funds/mixin.d.ts.map +1 -0
  132. package/dist/esm/funds/mixin.js +72 -0
  133. package/dist/esm/funds/mixin.js.map +1 -0
  134. package/dist/esm/groups/mixin.d.ts +14 -0
  135. package/dist/esm/groups/mixin.d.ts.map +1 -0
  136. package/dist/esm/groups/mixin.js +18 -0
  137. package/dist/esm/groups/mixin.js.map +1 -0
  138. package/dist/esm/meta-tx/mixin.d.ts +176 -0
  139. package/dist/esm/meta-tx/mixin.d.ts.map +1 -0
  140. package/dist/esm/meta-tx/mixin.js +351 -0
  141. package/dist/esm/meta-tx/mixin.js.map +1 -0
  142. package/dist/esm/metadata/mixin.d.ts +42 -0
  143. package/dist/esm/metadata/mixin.d.ts.map +1 -0
  144. package/dist/esm/metadata/mixin.js +60 -0
  145. package/dist/esm/metadata/mixin.js.map +1 -0
  146. package/dist/esm/metadata/subgraph.d.ts +3 -1
  147. package/dist/esm/metadata/subgraph.d.ts.map +1 -1
  148. package/dist/esm/metadata/subgraph.js +14 -0
  149. package/dist/esm/metadata/subgraph.js.map +1 -1
  150. package/dist/esm/mixins/base-core-sdk.d.ts +41 -0
  151. package/dist/esm/mixins/base-core-sdk.d.ts.map +1 -0
  152. package/dist/esm/mixins/base-core-sdk.js +54 -0
  153. package/dist/esm/mixins/base-core-sdk.js.map +1 -0
  154. package/dist/esm/native-meta-tx/mixin.d.ts +35 -0
  155. package/dist/esm/native-meta-tx/mixin.d.ts.map +1 -0
  156. package/dist/esm/native-meta-tx/mixin.js +51 -0
  157. package/dist/esm/native-meta-tx/mixin.js.map +1 -0
  158. package/dist/esm/offers/mixin.d.ts +133 -0
  159. package/dist/esm/offers/mixin.d.ts.map +1 -0
  160. package/dist/esm/offers/mixin.js +276 -0
  161. package/dist/esm/offers/mixin.js.map +1 -0
  162. package/dist/esm/orchestration/mixin.d.ts +28 -0
  163. package/dist/esm/orchestration/mixin.d.ts.map +1 -0
  164. package/dist/esm/orchestration/mixin.js +42 -0
  165. package/dist/esm/orchestration/mixin.js.map +1 -0
  166. package/dist/esm/subgraph.d.ts +3707 -1509
  167. package/dist/esm/subgraph.d.ts.map +1 -1
  168. package/dist/esm/subgraph.js +110 -1
  169. package/dist/esm/subgraph.js.map +1 -1
  170. package/dist/esm/utils/graphql.d.ts +14 -0
  171. package/dist/esm/utils/graphql.d.ts.map +1 -1
  172. package/dist/esm/utils/signature.d.ts.map +1 -1
  173. package/dist/esm/utils/signature.js +5 -1
  174. package/dist/esm/utils/signature.js.map +1 -1
  175. package/dist/esm/utils/tokenInfoManager.d.ts +6 -2
  176. package/dist/esm/utils/tokenInfoManager.d.ts.map +1 -1
  177. package/dist/esm/utils/tokenInfoManager.js +39 -6
  178. package/dist/esm/utils/tokenInfoManager.js.map +1 -1
  179. package/package.json +3 -3
  180. package/src/accounts/mixin.ts +484 -0
  181. package/src/core-sdk.ts +42 -2102
  182. package/src/disputes/mixin.ts +240 -0
  183. package/src/erc1155/handler.ts +21 -0
  184. package/src/erc1155/index.ts +2 -0
  185. package/src/erc1155/interface.ts +4 -0
  186. package/src/erc20/handler.ts +14 -0
  187. package/src/erc721/handler.ts +14 -0
  188. package/src/event-logs/mixin.ts +16 -0
  189. package/src/exchanges/mixin.ts +184 -0
  190. package/src/funds/mixin.ts +99 -0
  191. package/src/groups/mixin.ts +24 -0
  192. package/src/meta-tx/mixin.ts +515 -0
  193. package/src/metadata/mixin.ts +97 -0
  194. package/src/metadata/product-v1.graphql +77 -1
  195. package/src/metadata/subgraph.ts +31 -1
  196. package/src/mixins/base-core-sdk.ts +96 -0
  197. package/src/native-meta-tx/mixin.ts +77 -0
  198. package/src/offers/mixin.ts +376 -0
  199. package/src/offers/queries.graphql +1 -1
  200. package/src/orchestration/mixin.ts +57 -0
  201. package/src/subgraph.ts +3620 -1296
  202. package/src/utils/signature.ts +6 -1
  203. package/src/utils/tokenInfoManager.ts +44 -6
@@ -0,0 +1,240 @@
1
+ import { BaseCoreSDK } from "./../mixins/base-core-sdk";
2
+ import * as subgraph from "../subgraph";
3
+ import { TransactionResponse } from "@bosonprotocol/common";
4
+ import { BigNumberish } from "@ethersproject/bignumber";
5
+ import { BytesLike } from "@ethersproject/bytes";
6
+ import {
7
+ raiseDispute,
8
+ retractDispute,
9
+ extendDisputeTimeout,
10
+ expireDispute,
11
+ expireDisputeBatch,
12
+ resolveDispute,
13
+ escalateDispute,
14
+ decideDispute,
15
+ refuseEscalatedDispute,
16
+ expireEscalatedDispute,
17
+ signResolutionProposal
18
+ } from "./handler";
19
+ import {
20
+ SingleDisputeQueryVariables,
21
+ getDisputeById,
22
+ getDisputes
23
+ } from "./subgraph";
24
+
25
+ export class DisputesMixin extends BaseCoreSDK {
26
+ /* -------------------------------------------------------------------------- */
27
+ /* Dispute related methods */
28
+ /* -------------------------------------------------------------------------- */
29
+
30
+ /**
31
+ * Returns dispute entity from subgraph.
32
+ * @param disputeId - ID of dispute entity.
33
+ * @param queryVars - Optional query variables to skip, order or filter.
34
+ * @returns Dispute entity from subgraph.
35
+ */
36
+ public async getDisputeById(
37
+ disputeId: BigNumberish,
38
+ queryVars?: SingleDisputeQueryVariables
39
+ ) {
40
+ return getDisputeById(this._subgraphUrl, disputeId, queryVars);
41
+ }
42
+
43
+ /**
44
+ * Returns dispute entities from subgraph.
45
+ * @param queryVars - Optional query variables to skip, order or filter.
46
+ * @returns Dispute entities from subgraph.
47
+ */
48
+ public async getDisputes(
49
+ queryVars?: subgraph.GetDisputesQueryQueryVariables
50
+ ) {
51
+ return getDisputes(this._subgraphUrl, queryVars);
52
+ }
53
+
54
+ /**
55
+ * Raises a dispute by calling the `DisputeHandlerContract`.
56
+ * @param exchangeId - ID of exchange to dispute.
57
+ * @returns Transaction response.
58
+ */
59
+ public async raiseDispute(
60
+ exchangeId: BigNumberish
61
+ ): Promise<TransactionResponse> {
62
+ return raiseDispute({
63
+ exchangeId,
64
+ contractAddress: this._protocolDiamond,
65
+ web3Lib: this._web3Lib
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Retracts a dispute by calling the `DisputeHandlerContract`.
71
+ * @param exchangeId - ID of disputed exchange.
72
+ * @returns Transaction response.
73
+ */
74
+ public async retractDispute(
75
+ exchangeId: BigNumberish
76
+ ): Promise<TransactionResponse> {
77
+ return retractDispute({
78
+ exchangeId,
79
+ contractAddress: this._protocolDiamond,
80
+ web3Lib: this._web3Lib
81
+ });
82
+ }
83
+
84
+ /**
85
+ * Extends the dispute timeout by calling the `DisputeHandlerContract`.
86
+ * @param exchangeId - ID of disputed exchange.
87
+ * @param newDisputeTimeout - New dispute timeout in seconds.
88
+ * @returns Transaction response.
89
+ */
90
+ public async extendDisputeTimeout(
91
+ exchangeId: BigNumberish,
92
+ newDisputeTimeout: BigNumberish
93
+ ): Promise<TransactionResponse> {
94
+ return extendDisputeTimeout({
95
+ exchangeId,
96
+ newDisputeTimeout,
97
+ contractAddress: this._protocolDiamond,
98
+ web3Lib: this._web3Lib
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Expires a dispute by calling the `DisputeHandlerContract`.
104
+ * @param exchangeId - ID of disputed exchange.
105
+ * @returns Transaction response.
106
+ */
107
+ public async expireDispute(
108
+ exchangeId: BigNumberish
109
+ ): Promise<TransactionResponse> {
110
+ return expireDispute({
111
+ exchangeId,
112
+ contractAddress: this._protocolDiamond,
113
+ web3Lib: this._web3Lib
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Expires many disputes by calling the `DisputeHandlerContract`.
119
+ * @param exchangeIds - IDs of disputed exchanges.
120
+ * @returns Transaction response.
121
+ */
122
+ public async expireDisputeBatch(
123
+ exchangeIds: BigNumberish[]
124
+ ): Promise<TransactionResponse> {
125
+ return expireDisputeBatch({
126
+ exchangeIds,
127
+ contractAddress: this._protocolDiamond,
128
+ web3Lib: this._web3Lib
129
+ });
130
+ }
131
+
132
+ /**
133
+ * Resolves dispute by calling the `DisputeHandlerContract`. If caller is `buyer` then
134
+ * signature of `seller` is required as an argument. If caller if `seller` then vice-versa.
135
+ * The signature can be retrieved by calling the method
136
+ * `CoreSDK.signDisputeResolutionProposal`.
137
+ * @param args - Dispute resolve arguments:
138
+ * - `args.exchangeId` - ID of disputed exchange.
139
+ * - `args.buyerPercent` - Percentage of deposit the buyer gets.
140
+ * - `args.sigR` - r signature value of counterparty.
141
+ * - `args.sigS` - s signature value of counterparty.
142
+ * - `args.sigV` - v signature value of counterparty.
143
+ * @returns Transaction response.
144
+ */
145
+ public async resolveDispute(args: {
146
+ exchangeId: BigNumberish;
147
+ buyerPercentBasisPoints: BigNumberish;
148
+ sigR: BytesLike;
149
+ sigS: BytesLike;
150
+ sigV: BigNumberish;
151
+ }): Promise<TransactionResponse> {
152
+ return resolveDispute({
153
+ ...args,
154
+ contractAddress: this._protocolDiamond,
155
+ web3Lib: this._web3Lib
156
+ });
157
+ }
158
+
159
+ /**
160
+ * Escalates dispute by calling the `DisputeHandlerContract`.
161
+ * @param exchangeId - ID of disputed exchange.
162
+ * @returns Transaction response.
163
+ */
164
+ public async escalateDispute(
165
+ exchangeId: BigNumberish
166
+ ): Promise<TransactionResponse> {
167
+ return escalateDispute({
168
+ exchangeId,
169
+ contractAddress: this._protocolDiamond,
170
+ web3Lib: this._web3Lib
171
+ });
172
+ }
173
+
174
+ /**
175
+ * Decides dispute by calling the `DisputeHandlerContract`.
176
+ * @param exchangeId - ID of disputed exchange.
177
+ * @param buyerPercent - Percentage of deposit buyer gets.
178
+ * @returns Transaction response.
179
+ */
180
+ public async decideDispute(
181
+ exchangeId: BigNumberish,
182
+ buyerPercent: BigNumberish
183
+ ): Promise<TransactionResponse> {
184
+ return decideDispute({
185
+ exchangeId,
186
+ buyerPercent,
187
+ contractAddress: this._protocolDiamond,
188
+ web3Lib: this._web3Lib
189
+ });
190
+ }
191
+
192
+ /**
193
+ * Refuses escalated dispute by calling the `DisputeHandlerContract`.
194
+ * @param exchangeId - ID of disputed exchange.
195
+ * @returns Transaction response.
196
+ */
197
+ public async refuseEscalatedDispute(
198
+ exchangeId: BigNumberish
199
+ ): Promise<TransactionResponse> {
200
+ return refuseEscalatedDispute({
201
+ exchangeId,
202
+ contractAddress: this._protocolDiamond,
203
+ web3Lib: this._web3Lib
204
+ });
205
+ }
206
+
207
+ /**
208
+ * Expires escalated dispute by calling the `DisputeHandlerContract`.
209
+ * @param exchangeId - ID of disputed exchange.
210
+ * @returns Transaction response.
211
+ */
212
+ public async expireEscalatedDispute(
213
+ exchangeId: BigNumberish
214
+ ): Promise<TransactionResponse> {
215
+ return expireEscalatedDispute({
216
+ exchangeId,
217
+ contractAddress: this._protocolDiamond,
218
+ web3Lib: this._web3Lib
219
+ });
220
+ }
221
+
222
+ /**
223
+ * Signs dispute resolution message.
224
+ * @param args - Dispute resolve arguments:
225
+ * - `args.exchangeId` - ID of disputed exchange.
226
+ * - `args.buyerPercentBasisPoints` - Percentage of deposit the buyer gets.
227
+ * @returns Signature.
228
+ */
229
+ public async signDisputeResolutionProposal(args: {
230
+ exchangeId: BigNumberish;
231
+ buyerPercentBasisPoints: BigNumberish;
232
+ }) {
233
+ return signResolutionProposal({
234
+ ...args,
235
+ web3Lib: this._web3Lib,
236
+ contractAddress: this._protocolDiamond,
237
+ chainId: this._chainId
238
+ });
239
+ }
240
+ }
@@ -0,0 +1,21 @@
1
+ import { Web3LibAdapter } from "@bosonprotocol/common";
2
+ import { BigNumberish } from "@ethersproject/bignumber";
3
+ import { erc1155Iface } from "./interface";
4
+
5
+ export async function balanceOf(args: {
6
+ contractAddress: string;
7
+ tokenId: BigNumberish;
8
+ owner: string;
9
+ web3Lib: Web3LibAdapter;
10
+ }): Promise<string> {
11
+ const result = await args.web3Lib.call({
12
+ to: args.contractAddress,
13
+ data: erc1155Iface.encodeFunctionData("balanceOf", [
14
+ args.owner,
15
+ args.tokenId
16
+ ])
17
+ });
18
+
19
+ const [balance] = erc1155Iface.decodeFunctionResult("balanceOf", result);
20
+ return String(balance);
21
+ }
@@ -0,0 +1,2 @@
1
+ export * as iface from "./interface";
2
+ export * as handler from "./handler";
@@ -0,0 +1,4 @@
1
+ import { abis } from "@bosonprotocol/common";
2
+ import { Interface } from "@ethersproject/abi";
3
+
4
+ export const erc1155Iface = new Interface(abis.ERC1155);
@@ -81,3 +81,17 @@ export async function ensureAllowance(args: {
81
81
  await approveTx.wait();
82
82
  }
83
83
  }
84
+
85
+ export async function balanceOf(args: {
86
+ contractAddress: string;
87
+ owner: string;
88
+ web3Lib: Web3LibAdapter;
89
+ }): Promise<string> {
90
+ const result = await args.web3Lib.call({
91
+ to: args.contractAddress,
92
+ data: erc20Iface.encodeFunctionData("balanceOf", [args.owner])
93
+ });
94
+
95
+ const [balance] = erc20Iface.decodeFunctionResult("balanceOf", result);
96
+ return String(balance);
97
+ }
@@ -16,6 +16,20 @@ export async function balanceOf(args: {
16
16
  return String(balance);
17
17
  }
18
18
 
19
+ export async function ownerOf(args: {
20
+ contractAddress: string;
21
+ tokenId: BigNumberish;
22
+ web3Lib: Web3LibAdapter;
23
+ }): Promise<string> {
24
+ const result = await args.web3Lib.call({
25
+ to: args.contractAddress,
26
+ data: erc721Iface.encodeFunctionData("ownerOf", [args.tokenId])
27
+ });
28
+
29
+ const [owner] = erc721Iface.decodeFunctionResult("ownerOf", result);
30
+ return String(owner);
31
+ }
32
+
19
33
  export async function tokenOfOwnerByIndex(args: {
20
34
  contractAddress: string;
21
35
  owner: string;
@@ -0,0 +1,16 @@
1
+ import { BaseCoreSDK } from "./../mixins/base-core-sdk";
2
+ import * as subgraph from "../subgraph";
3
+ import { getEventLogs } from "./subgraph";
4
+
5
+ export class EventLogsMixin extends BaseCoreSDK {
6
+ /**
7
+ * Returns event logs from subgraph.
8
+ * @param queryVars - Optional query variables to skip, order or filter.
9
+ * @returns Event log entities from subgraph.
10
+ */
11
+ public async getEventLogs(
12
+ queryVars?: subgraph.GetEventLogsQueryQueryVariables
13
+ ) {
14
+ return getEventLogs(this._subgraphUrl, queryVars);
15
+ }
16
+ }
@@ -0,0 +1,184 @@
1
+ import { BaseCoreSDK } from "./../mixins/base-core-sdk";
2
+ import * as subgraph from "../subgraph";
3
+ import { TransactionResponse, Log } from "@bosonprotocol/common";
4
+ import { BigNumberish } from "@ethersproject/bignumber";
5
+ import { getValueFromLogs } from "../utils/logs";
6
+ import {
7
+ commitToOffer,
8
+ revokeVoucher,
9
+ cancelVoucher,
10
+ redeemVoucher,
11
+ completeExchange,
12
+ completeExchangeBatch,
13
+ expireVoucher
14
+ } from "./handler";
15
+ import { getExchangeById, getExchanges } from "./subgraph";
16
+ import { bosonExchangeHandlerIface } from "./interface";
17
+
18
+ export class ExchangesMixin extends BaseCoreSDK {
19
+ /* -------------------------------------------------------------------------- */
20
+ /* Exchange related methods */
21
+ /* -------------------------------------------------------------------------- */
22
+
23
+ /**
24
+ * Returns exchange entity from subgraph.
25
+ * @param exchangeId - ID of exchange entity.
26
+ * @param queryVars - Optional query variables to skip, order or filter.
27
+ * @returns Exchange entity from subgraph.
28
+ */
29
+ public async getExchangeById(
30
+ exchangeId: BigNumberish,
31
+ queryVars?: subgraph.GetExchangeByIdQueryQueryVariables
32
+ ): Promise<subgraph.ExchangeFieldsFragment> {
33
+ return getExchangeById(this._subgraphUrl, exchangeId, queryVars);
34
+ }
35
+
36
+ /**
37
+ * Returns exchange entities from subgraph.
38
+ * @param queryVars - Optional query variables to skip, order or filter.
39
+ * @returns Exchange entities from subgraph.
40
+ */
41
+ public async getExchanges(
42
+ queryVars?: subgraph.GetExchangesQueryQueryVariables
43
+ ): Promise<subgraph.ExchangeFieldsFragment[]> {
44
+ return getExchanges(this._subgraphUrl, queryVars);
45
+ }
46
+
47
+ /**
48
+ * Commits to an offer by calling the `ExchangeHandlerContract`.
49
+ * This transaction only succeeds if the seller has deposited funds.
50
+ * @param offerId - ID of offer to commit to.
51
+ * @param overrides - Optional overrides.
52
+ * @returns Transaction response.
53
+ */
54
+ public async commitToOffer(
55
+ offerId: BigNumberish,
56
+ overrides: Partial<{
57
+ buyer: string;
58
+ }> = {}
59
+ ): Promise<TransactionResponse> {
60
+ const buyer = overrides.buyer || (await this._web3Lib.getSignerAddress());
61
+ return commitToOffer({
62
+ buyer,
63
+ offerId,
64
+ web3Lib: this._web3Lib,
65
+ subgraphUrl: this._subgraphUrl,
66
+ contractAddress: this._protocolDiamond
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Utility method to retrieve the created `exchangeId` from logs after calling `commitToOffer`.
72
+ * @param logs - Logs to search in.
73
+ * @returns Created exchange id.
74
+ */
75
+ public getCommittedExchangeIdFromLogs(logs: Log[]): string | null {
76
+ return getValueFromLogs({
77
+ iface: bosonExchangeHandlerIface,
78
+ logs,
79
+ eventArgsKey: "exchangeId",
80
+ eventName: "BuyerCommitted"
81
+ });
82
+ }
83
+
84
+ /**
85
+ * Revokes an existing voucher by calling the `ExchangeHandlerContract`.
86
+ * Callable by seller `operator`.
87
+ * @param exchangeId - ID of exchange to revoke.
88
+ * @returns Transaction response.
89
+ */
90
+ public async revokeVoucher(
91
+ exchangeId: BigNumberish
92
+ ): Promise<TransactionResponse> {
93
+ return revokeVoucher({
94
+ web3Lib: this._web3Lib,
95
+ contractAddress: this._protocolDiamond,
96
+ exchangeId,
97
+ subgraphUrl: this._subgraphUrl
98
+ });
99
+ }
100
+
101
+ /**
102
+ * Cancels an existing voucher by calling the `ExchangeHandlerContract`.
103
+ * Callable by buyer.
104
+ * @param exchangeId - ID of exchange to cancel.
105
+ * @returns Transaction response.
106
+ */
107
+ public async cancelVoucher(
108
+ exchangeId: BigNumberish
109
+ ): Promise<TransactionResponse> {
110
+ return cancelVoucher({
111
+ web3Lib: this._web3Lib,
112
+ contractAddress: this._protocolDiamond,
113
+ exchangeId,
114
+ subgraphUrl: this._subgraphUrl
115
+ });
116
+ }
117
+
118
+ /**
119
+ * Redeems an existing voucher by calling the `ExchangeHandlerContract`.
120
+ * Callable by buyer.
121
+ * @param exchangeId - ID of exchange to redeem.
122
+ * @returns Transaction response.
123
+ */
124
+ public async redeemVoucher(
125
+ exchangeId: BigNumberish
126
+ ): Promise<TransactionResponse> {
127
+ return redeemVoucher({
128
+ web3Lib: this._web3Lib,
129
+ contractAddress: this._protocolDiamond,
130
+ exchangeId,
131
+ subgraphUrl: this._subgraphUrl
132
+ });
133
+ }
134
+
135
+ /**
136
+ * Completes an existing voucher by calling the `ExchangeHandlerContract`.
137
+ * Callable by buyer or seller operator.
138
+ * @param exchangeId - ID of exchange to complete.
139
+ * @returns Transaction response.
140
+ */
141
+ public async completeExchange(
142
+ exchangeId: BigNumberish
143
+ ): Promise<TransactionResponse> {
144
+ return completeExchange({
145
+ web3Lib: this._web3Lib,
146
+ contractAddress: this._protocolDiamond,
147
+ exchangeId,
148
+ subgraphUrl: this._subgraphUrl
149
+ });
150
+ }
151
+
152
+ /**
153
+ * Completes a batch of existing vouchers by calling the `ExchangeHandlerContract`.
154
+ * Callable by buyer or seller operator.
155
+ * @param exchangeIds - IDs of exchange to complete.
156
+ * @returns Transaction response.
157
+ */
158
+ public async completeExchangeBatch(
159
+ exchangeIds: BigNumberish[]
160
+ ): Promise<TransactionResponse> {
161
+ return completeExchangeBatch({
162
+ web3Lib: this._web3Lib,
163
+ contractAddress: this._protocolDiamond,
164
+ exchangeIds,
165
+ subgraphUrl: this._subgraphUrl
166
+ });
167
+ }
168
+
169
+ /**
170
+ * Expires an existing voucher by calling the `ExchangeHandlerContract`.
171
+ * @param exchangeId - ID of exchange to expire.
172
+ * @returns Transaction response.
173
+ */
174
+ public async expireVoucher(
175
+ exchangeId: BigNumberish
176
+ ): Promise<TransactionResponse> {
177
+ return expireVoucher({
178
+ web3Lib: this._web3Lib,
179
+ contractAddress: this._protocolDiamond,
180
+ exchangeId,
181
+ subgraphUrl: this._subgraphUrl
182
+ });
183
+ }
184
+ }
@@ -0,0 +1,99 @@
1
+ import { BaseCoreSDK } from "./../mixins/base-core-sdk";
2
+ import * as subgraph from "../subgraph";
3
+ import { TransactionResponse } from "@bosonprotocol/common";
4
+ import { BigNumberish } from "@ethersproject/bignumber";
5
+ import { AddressZero } from "@ethersproject/constants";
6
+ import {
7
+ withdrawFunds,
8
+ withdrawAllAvailableFunds,
9
+ depositFunds
10
+ } from "./handler";
11
+ import { getFundsById, getFunds } from "./subgraph";
12
+
13
+ export class FundsMixin extends BaseCoreSDK {
14
+ /* -------------------------------------------------------------------------- */
15
+ /* Funds related methods */
16
+ /* -------------------------------------------------------------------------- */
17
+
18
+ /**
19
+ * Deposit funds by calling the `FundsHandlerFacet` contract.
20
+ * @param sellerId - ID of seller account to deposit funds for.
21
+ * @param fundsAmount - Amount of funds.
22
+ * @param fundsTokenAddress - Address of funds token.
23
+ * @returns Transaction response.
24
+ */
25
+ public async depositFunds(
26
+ sellerId: BigNumberish,
27
+ fundsAmount: BigNumberish,
28
+ fundsTokenAddress: string = AddressZero
29
+ ): Promise<TransactionResponse> {
30
+ return depositFunds({
31
+ sellerId,
32
+ fundsAmount,
33
+ fundsTokenAddress,
34
+ contractAddress: this._protocolDiamond,
35
+ web3Lib: this._web3Lib
36
+ });
37
+ }
38
+
39
+ /**
40
+ * Returns funds entity from subgraph.
41
+ * @param fundsId - ID of funds entity.
42
+ * @param queryVars - Optional query variables to skip, order or filter.
43
+ * @returns Funds entity from subgraph.
44
+ */
45
+ public async getFundsById(
46
+ fundsId: BigNumberish,
47
+ queryVars?: subgraph.GetFundsByIdQueryVariables
48
+ ): Promise<subgraph.FundsEntityFieldsFragment> {
49
+ return getFundsById(this._subgraphUrl, fundsId, queryVars);
50
+ }
51
+
52
+ /**
53
+ * Returns funds entities from subgraph.
54
+ * @param queryVars - Optional query variables to skip, order or filter.
55
+ * @returns Funds entities from subgraph.
56
+ */
57
+ public async getFunds(
58
+ queryVars?: subgraph.GetFundsQueryVariables
59
+ ): Promise<subgraph.FundsEntityFieldsFragment[]> {
60
+ return getFunds(this._subgraphUrl, queryVars);
61
+ }
62
+
63
+ /**
64
+ * Withdraw selected funds by calling the `FundsHandlerFacet` contract.
65
+ * @param sellerId - ID of seller account to withdraw funds for.
66
+ * @param tokensToWithdraw - Addresses of funds tokens to withdraw.
67
+ * @param amountsToWithdraw - Amounts of funds token to withdraw.
68
+ * @returns Transaction response.
69
+ */
70
+ public async withdrawFunds(
71
+ sellerId: BigNumberish,
72
+ tokensToWithdraw: Array<string>,
73
+ amountsToWithdraw: Array<BigNumberish>
74
+ ): Promise<TransactionResponse> {
75
+ return withdrawFunds({
76
+ sellerId,
77
+ tokensToWithdraw,
78
+ amountsToWithdraw,
79
+ contractAddress: this._protocolDiamond,
80
+ web3Lib: this._web3Lib
81
+ });
82
+ }
83
+
84
+ /**
85
+ * Withdraw all available funds by calling the `FundsHandlerFacet` contract.
86
+ * @param sellerId - ID of seller account to withdraw funds for.
87
+ * @returns Transaction response.
88
+ */
89
+ public async withdrawAllAvailableFunds(
90
+ sellerId: BigNumberish
91
+ ): Promise<TransactionResponse> {
92
+ return withdrawAllAvailableFunds({
93
+ sellerId,
94
+ subgraphUrl: this._subgraphUrl,
95
+ contractAddress: this._protocolDiamond,
96
+ web3Lib: this._web3Lib
97
+ });
98
+ }
99
+ }
@@ -0,0 +1,24 @@
1
+ import { CreateGroupArgs, TransactionResponse } from "@bosonprotocol/common";
2
+ import { handler } from ".";
3
+ import { BaseCoreSDK } from "./../mixins/base-core-sdk";
4
+
5
+ export class GroupsMixin extends BaseCoreSDK {
6
+ /**
7
+ * Creates a group of contract addresses
8
+ * @param groupToCreate - group with the contract condition
9
+ * @param overrides - Optional overrides.
10
+ * @returns Transaction response.
11
+ */
12
+ public async createGroup(
13
+ groupToCreate: CreateGroupArgs,
14
+ overrides: Partial<{
15
+ contractAddress: string;
16
+ }> = {}
17
+ ): Promise<TransactionResponse> {
18
+ return handler.createGroup({
19
+ groupToCreate,
20
+ contractAddress: overrides.contractAddress || this._protocolDiamond,
21
+ web3Lib: this._web3Lib
22
+ });
23
+ }
24
+ }