@bosonprotocol/core-sdk 1.5.0 → 1.6.0-alpha.1

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 (108) hide show
  1. package/dist/cjs/accounts/subgraph.d.ts.map +1 -1
  2. package/dist/cjs/accounts/subgraph.js +3 -3
  3. package/dist/cjs/accounts/subgraph.js.map +1 -1
  4. package/dist/cjs/core-sdk.d.ts +3 -0
  5. package/dist/cjs/core-sdk.d.ts.map +1 -1
  6. package/dist/cjs/core-sdk.js +18 -0
  7. package/dist/cjs/core-sdk.js.map +1 -1
  8. package/dist/cjs/exchanges/handler.d.ts.map +1 -1
  9. package/dist/cjs/exchanges/handler.js +2 -1
  10. package/dist/cjs/exchanges/handler.js.map +1 -1
  11. package/dist/cjs/funds/handler.d.ts +10 -0
  12. package/dist/cjs/funds/handler.d.ts.map +1 -0
  13. package/dist/cjs/funds/handler.js +31 -0
  14. package/dist/cjs/funds/handler.js.map +1 -0
  15. package/dist/cjs/funds/index.d.ts +5 -0
  16. package/dist/cjs/funds/index.d.ts.map +1 -0
  17. package/dist/cjs/funds/index.js +34 -0
  18. package/dist/cjs/funds/index.js.map +1 -0
  19. package/dist/cjs/funds/interface.d.ts +5 -0
  20. package/dist/cjs/funds/interface.d.ts.map +1 -0
  21. package/dist/cjs/funds/interface.js +15 -0
  22. package/dist/cjs/funds/interface.js.map +1 -0
  23. package/dist/cjs/funds/subgraph.d.ts +6 -0
  24. package/dist/cjs/funds/subgraph.d.ts.map +1 -0
  25. package/dist/cjs/funds/subgraph.js +44 -0
  26. package/dist/cjs/funds/subgraph.js.map +1 -0
  27. package/dist/cjs/funds/types.d.ts +12 -0
  28. package/dist/cjs/funds/types.d.ts.map +1 -0
  29. package/dist/cjs/funds/types.js +3 -0
  30. package/dist/cjs/funds/types.js.map +1 -0
  31. package/dist/cjs/index.d.ts +1 -0
  32. package/dist/cjs/index.d.ts.map +1 -1
  33. package/dist/cjs/index.js +2 -1
  34. package/dist/cjs/index.js.map +1 -1
  35. package/dist/cjs/offers/index.d.ts +10 -4
  36. package/dist/cjs/offers/index.d.ts.map +1 -1
  37. package/dist/cjs/offers/interface.d.ts +9 -2
  38. package/dist/cjs/offers/interface.d.ts.map +1 -1
  39. package/dist/cjs/offers/interface.js +33 -8
  40. package/dist/cjs/offers/interface.js.map +1 -1
  41. package/dist/cjs/offers/subgraph.d.ts.map +1 -1
  42. package/dist/cjs/offers/subgraph.js +6 -1
  43. package/dist/cjs/offers/subgraph.js.map +1 -1
  44. package/dist/cjs/offers/types.d.ts +6 -1
  45. package/dist/cjs/offers/types.d.ts.map +1 -1
  46. package/dist/cjs/orchestration/interface.js +1 -1
  47. package/dist/cjs/orchestration/interface.js.map +1 -1
  48. package/dist/esm/accounts/subgraph.d.ts.map +1 -1
  49. package/dist/esm/accounts/subgraph.js +3 -3
  50. package/dist/esm/accounts/subgraph.js.map +1 -1
  51. package/dist/esm/core-sdk.d.ts +3 -0
  52. package/dist/esm/core-sdk.d.ts.map +1 -1
  53. package/dist/esm/core-sdk.js +14 -0
  54. package/dist/esm/core-sdk.js.map +1 -1
  55. package/dist/esm/exchanges/handler.d.ts.map +1 -1
  56. package/dist/esm/exchanges/handler.js +2 -1
  57. package/dist/esm/exchanges/handler.js.map +1 -1
  58. package/dist/esm/funds/handler.d.ts +10 -0
  59. package/dist/esm/funds/handler.d.ts.map +1 -0
  60. package/dist/esm/funds/handler.js +16 -0
  61. package/dist/esm/funds/handler.js.map +1 -0
  62. package/dist/esm/funds/index.d.ts +5 -0
  63. package/dist/esm/funds/index.d.ts.map +1 -0
  64. package/dist/esm/funds/index.js +5 -0
  65. package/dist/esm/funds/index.js.map +1 -0
  66. package/dist/esm/funds/interface.d.ts +5 -0
  67. package/dist/esm/funds/interface.d.ts.map +1 -0
  68. package/dist/esm/funds/interface.js +11 -0
  69. package/dist/esm/funds/interface.js.map +1 -0
  70. package/dist/esm/funds/subgraph.d.ts +6 -0
  71. package/dist/esm/funds/subgraph.d.ts.map +1 -0
  72. package/dist/esm/funds/subgraph.js +29 -0
  73. package/dist/esm/funds/subgraph.js.map +1 -0
  74. package/dist/esm/funds/types.d.ts +12 -0
  75. package/dist/esm/funds/types.d.ts.map +1 -0
  76. package/dist/esm/funds/types.js +2 -0
  77. package/dist/esm/funds/types.js.map +1 -0
  78. package/dist/esm/index.d.ts +1 -0
  79. package/dist/esm/index.d.ts.map +1 -1
  80. package/dist/esm/index.js +1 -0
  81. package/dist/esm/index.js.map +1 -1
  82. package/dist/esm/offers/index.d.ts +10 -4
  83. package/dist/esm/offers/index.d.ts.map +1 -1
  84. package/dist/esm/offers/interface.d.ts +9 -2
  85. package/dist/esm/offers/interface.d.ts.map +1 -1
  86. package/dist/esm/offers/interface.js +28 -11
  87. package/dist/esm/offers/interface.js.map +1 -1
  88. package/dist/esm/offers/subgraph.d.ts.map +1 -1
  89. package/dist/esm/offers/subgraph.js +6 -1
  90. package/dist/esm/offers/subgraph.js.map +1 -1
  91. package/dist/esm/offers/types.d.ts +6 -1
  92. package/dist/esm/offers/types.d.ts.map +1 -1
  93. package/dist/esm/orchestration/interface.js +2 -2
  94. package/dist/esm/orchestration/interface.js.map +1 -1
  95. package/package.json +4 -4
  96. package/src/accounts/subgraph.ts +9 -15
  97. package/src/core-sdk.ts +23 -0
  98. package/src/exchanges/handler.ts +2 -1
  99. package/src/funds/handler.ts +31 -0
  100. package/src/funds/index.ts +4 -0
  101. package/src/funds/interface.ts +17 -0
  102. package/src/funds/subgraph.ts +39 -0
  103. package/src/funds/types.ts +11 -0
  104. package/src/index.ts +1 -0
  105. package/src/offers/interface.ts +63 -21
  106. package/src/offers/subgraph.ts +6 -1
  107. package/src/offers/types.ts +6 -1
  108. package/src/orchestration/interface.ts +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/offers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEx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AAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,SAAS,EAAE;QACT,EAAE,EAAE,MAAM,CAAC;QACX,aAAa,EAAE,MAAM,CAAC;QACtB,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;KACtB,EAAE,CAAC;CACL,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import { abis } from "@bosonprotocol/common";
2
2
  import { Interface } from "@ethersproject/abi";
3
3
  import { createSellerArgsToStruct } from "../accounts/interface";
4
- import { createOfferArgsToStruct } from "../offers/interface";
4
+ import { createOfferArgsToStructs } from "../offers/interface";
5
5
  export const bosonOrchestrationHandlerIface = new Interface(abis.IBosonOrchestrationHandlerABI);
6
6
  export function encodeCreateSellerAndOffer(seller, offer) {
7
- return bosonOrchestrationHandlerIface.encodeFunctionData("createSellerAndOffer", [createSellerArgsToStruct(seller), createOfferArgsToStruct(offer)]);
7
+ return bosonOrchestrationHandlerIface.encodeFunctionData("createSellerAndOffer", [createSellerArgsToStruct(seller), ...createOfferArgsToStructs(offer)]);
8
8
  }
9
9
  //# sourceMappingURL=interface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/orchestration/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAK9D,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,SAAS,CACzD,IAAI,CAAC,6BAA6B,CACnC,CAAC;AAEF,MAAM,UAAU,0BAA0B,CACxC,MAAwB,EACxB,KAAsB;IAEtB,OAAO,8BAA8B,CAAC,kBAAkB,CACtD,sBAAsB,EACtB,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,KAAK,CAAC,CAAC,CACnE,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/orchestration/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAK/D,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,SAAS,CACzD,IAAI,CAAC,6BAA6B,CACnC,CAAC;AAEF,MAAM,UAAU,0BAA0B,CACxC,MAAwB,EACxB,KAAsB;IAEtB,OAAO,8BAA8B,CAAC,kBAAkB,CACtD,sBAAsB,EACtB,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC,CACvE,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bosonprotocol/core-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.6.0-alpha.1",
4
4
  "description": "> TODO: description",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
7
7
  "types": "./dist/cjs/index.d.ts",
8
8
  "scripts": {
9
- "dev": "tsc --build tsconfig.cjs.json --watch --preserveWatchOutput ",
9
+ "dev": "tsc --watch --preserveWatchOutput ",
10
10
  "lint": "eslint --ignore-path ../../.gitignore --ext .js,.ts .",
11
11
  "build": "rimraf dist && tsc && tsc --build tsconfig.cjs.json",
12
12
  "test": "jest",
@@ -30,7 +30,7 @@
30
30
  "access": "restricted"
31
31
  },
32
32
  "dependencies": {
33
- "@bosonprotocol/common": "^1.5.1",
33
+ "@bosonprotocol/common": "^1.6.0-alpha.1",
34
34
  "@ethersproject/abi": "^5.5.0",
35
35
  "@ethersproject/address": "^5.5.0",
36
36
  "@ethersproject/bignumber": "^5.5.0",
@@ -46,5 +46,5 @@
46
46
  "ts-jest": "^27.1.3",
47
47
  "typescript": "^4.5.5"
48
48
  },
49
- "gitHead": "61fa5f811a172faf91ae6fa0e66332ebdc45ce20"
49
+ "gitHead": "a6b9522306908975de38960fb7b31f8144eeed60"
50
50
  }
@@ -27,11 +27,9 @@ export async function getSellerByOperator(
27
27
  subgraphUrl: string,
28
28
  operatorAddress: string
29
29
  ): Promise<RawSellerFromSubgraph> {
30
- const { sellers } = await fetchSubgraph<{ sellers: RawSellerFromSubgraph }>(
31
- subgraphUrl,
32
- getSellerByOperatorQuery,
33
- { operator: operatorAddress }
34
- );
30
+ const { sellers = [] } = await fetchSubgraph<{
31
+ sellers: RawSellerFromSubgraph[];
32
+ }>(subgraphUrl, getSellerByOperatorQuery, { operator: operatorAddress });
35
33
 
36
34
  return sellers[0];
37
35
  }
@@ -51,11 +49,9 @@ export async function getSellerByAdmin(
51
49
  subgraphUrl: string,
52
50
  adminAddress: string
53
51
  ): Promise<RawSellerFromSubgraph> {
54
- const { sellers } = await fetchSubgraph<{ sellers: RawSellerFromSubgraph }>(
55
- subgraphUrl,
56
- getSellerByOperatorQuery,
57
- { admin: adminAddress }
58
- );
52
+ const { sellers = [] } = await fetchSubgraph<{
53
+ sellers: RawSellerFromSubgraph[];
54
+ }>(subgraphUrl, getSellerByAdminQuery, { admin: adminAddress });
59
55
 
60
56
  return sellers[0];
61
57
  }
@@ -75,11 +71,9 @@ export async function getSellerByClerk(
75
71
  subgraphUrl: string,
76
72
  clerkAddress: string
77
73
  ): Promise<RawSellerFromSubgraph> {
78
- const { sellers } = await fetchSubgraph<{ sellers: RawSellerFromSubgraph }>(
79
- subgraphUrl,
80
- getSellerByOperatorQuery,
81
- { clerk: clerkAddress }
82
- );
74
+ const { sellers = [] } = await fetchSubgraph<{
75
+ sellers: RawSellerFromSubgraph[];
76
+ }>(subgraphUrl, getSellerByClerkQuery, { clerk: clerkAddress });
83
77
 
84
78
  return sellers[0];
85
79
  }
package/src/core-sdk.ts CHANGED
@@ -7,11 +7,14 @@ import {
7
7
  Log
8
8
  } from "@bosonprotocol/common";
9
9
  import { BigNumberish } from "@ethersproject/bignumber";
10
+ import { AddressZero } from "@ethersproject/constants";
11
+
10
12
  import * as accounts from "./accounts";
11
13
  import * as exchanges from "./exchanges";
12
14
  import * as offers from "./offers";
13
15
  import * as orchestration from "./orchestration";
14
16
  import * as erc20 from "./erc20";
17
+ import * as funds from "./funds";
15
18
  import { getValueFromLogs } from "./utils/logs";
16
19
  import { MultiQueryOpts } from "./utils/subgraph";
17
20
 
@@ -251,4 +254,24 @@ export class CoreSDK {
251
254
  web3Lib: this._web3Lib
252
255
  });
253
256
  }
257
+
258
+ public async depositFunds(
259
+ sellerId: BigNumberish,
260
+ fundsAmount: BigNumberish,
261
+ fundsTokenAddress: string = AddressZero
262
+ ): Promise<TransactionResponse> {
263
+ return funds.handler.depositFunds({
264
+ sellerId,
265
+ fundsAmount,
266
+ fundsTokenAddress,
267
+ contractAddress: this._protocolDiamond,
268
+ web3Lib: this._web3Lib
269
+ });
270
+ }
271
+
272
+ public async getFundsByAccountId(
273
+ accountId: BigNumberish
274
+ ): Promise<funds.RawFundsEntityFromSubgraph[]> {
275
+ return funds.subgraph.getFundsByAccountId(this._subgraphUrl, accountId);
276
+ }
254
277
  }
@@ -34,6 +34,7 @@ export async function commitToOffer(args: {
34
34
 
35
35
  return args.web3Lib.sendTransaction({
36
36
  to: args.contractAddress,
37
- data: encodeCommitToOffer(args.buyer, args.offerId)
37
+ data: encodeCommitToOffer(args.buyer, args.offerId),
38
+ value: offer.price
38
39
  });
39
40
  }
@@ -0,0 +1,31 @@
1
+ import { BigNumberish } from "@ethersproject/bignumber";
2
+ import { isAddress } from "@ethersproject/address";
3
+ import { AddressZero } from "@ethersproject/constants";
4
+ import { Web3LibAdapter, TransactionResponse } from "@bosonprotocol/common";
5
+ import { encodeDepositFunds } from "./interface";
6
+
7
+ export async function depositFunds(args: {
8
+ sellerId: BigNumberish;
9
+ fundsTokenAddress?: string;
10
+ fundsAmount: BigNumberish;
11
+ contractAddress: string;
12
+ web3Lib: Web3LibAdapter;
13
+ }): Promise<TransactionResponse> {
14
+ const { fundsTokenAddress = AddressZero } = args;
15
+
16
+ if (!isAddress(fundsTokenAddress)) {
17
+ throw new Error(`Invalid fundsTokenAddress: ${fundsTokenAddress}`);
18
+ }
19
+
20
+ const isNativeCoin = fundsTokenAddress === AddressZero;
21
+
22
+ return args.web3Lib.sendTransaction({
23
+ to: args.contractAddress,
24
+ data: encodeDepositFunds(
25
+ args.sellerId,
26
+ args.fundsTokenAddress,
27
+ args.fundsAmount
28
+ ),
29
+ value: isNativeCoin ? args.fundsAmount : "0"
30
+ });
31
+ }
@@ -0,0 +1,4 @@
1
+ export * as iface from "./interface";
2
+ export * as subgraph from "./subgraph";
3
+ export * as handler from "./handler";
4
+ export * from "./types";
@@ -0,0 +1,17 @@
1
+ import { abis } from "@bosonprotocol/common";
2
+ import { Interface } from "@ethersproject/abi";
3
+ import { BigNumberish } from "@ethersproject/bignumber";
4
+
5
+ export const bosonFundsHandlerIface = new Interface(abis.IBosonFundsHandlerABI);
6
+
7
+ export function encodeDepositFunds(
8
+ sellerId: BigNumberish,
9
+ tokenAddress: string,
10
+ amount: BigNumberish
11
+ ) {
12
+ return bosonFundsHandlerIface.encodeFunctionData("depositFunds", [
13
+ sellerId,
14
+ tokenAddress,
15
+ amount
16
+ ]);
17
+ }
@@ -0,0 +1,39 @@
1
+ import { BigNumberish } from "@ethersproject/bignumber";
2
+ import { fetchSubgraph } from "../utils/subgraph";
3
+ import { RawFundsEntityFromSubgraph } from "./types";
4
+
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
+ `;
18
+
19
+ export const getFundsByAccountIdQuery = `
20
+ query GetFundsByAccountIdQuery($accountId: String!) {
21
+ fundsEntities(where: {
22
+ accountId: $accountId
23
+ }) {
24
+ ...fundsEntityFields
25
+ }
26
+ }
27
+ ${fundsEntityFieldsFragment}
28
+ `;
29
+
30
+ export async function getFundsByAccountId(
31
+ subgraphUrl: string,
32
+ accountId: BigNumberish
33
+ ): Promise<RawFundsEntityFromSubgraph[]> {
34
+ const { fundsEntities = [] } = await fetchSubgraph<{
35
+ fundsEntities: RawFundsEntityFromSubgraph[];
36
+ }>(subgraphUrl, getFundsByAccountIdQuery, { accountId });
37
+
38
+ return fundsEntities;
39
+ }
@@ -0,0 +1,11 @@
1
+ export type RawFundsEntityFromSubgraph = {
2
+ id: string;
3
+ availableAmount: string;
4
+ token: {
5
+ address: string;
6
+ name: string;
7
+ symbol: string;
8
+ decimals: number;
9
+ };
10
+ accountId: string;
11
+ };
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export * as accounts from "./accounts";
5
5
  export * as exchanges from "./exchanges";
6
6
  export * as orchestration from "./orchestration";
7
7
  export * as erc20 from "./erc20";
8
+ export * as funds from "./funds";
8
9
 
9
10
  export { defaultConfigs, getDefaultConfig } from "@bosonprotocol/common";
10
11
 
@@ -1,4 +1,10 @@
1
- import { OfferStruct, utils, abis } from "@bosonprotocol/common";
1
+ import {
2
+ OfferStruct,
3
+ utils,
4
+ abis,
5
+ OfferDatesStruct,
6
+ OfferDurationsStruct
7
+ } from "@bosonprotocol/common";
2
8
  import { Interface } from "@ethersproject/abi";
3
9
  import { getAddress } from "@ethersproject/address";
4
10
  import { CreateOfferArgs } from "./types";
@@ -6,35 +12,71 @@ import { CreateOfferArgs } from "./types";
6
12
  export const bosonOfferHandlerIface = new Interface(abis.IBosonOfferHandlerABI);
7
13
 
8
14
  export function encodeCreateOffer(args: CreateOfferArgs) {
9
- return bosonOfferHandlerIface.encodeFunctionData("createOffer", [
10
- createOfferArgsToStruct(args)
11
- ]);
15
+ return bosonOfferHandlerIface.encodeFunctionData(
16
+ "createOffer",
17
+ createOfferArgsToStructs(args)
18
+ );
12
19
  }
13
20
 
14
- export function createOfferArgsToStruct(
21
+ export function createOfferArgsToStructs(
15
22
  args: CreateOfferArgs
16
- ): Partial<OfferStruct> {
23
+ ): [
24
+ Partial<OfferStruct>,
25
+ Partial<OfferDatesStruct>,
26
+ Partial<OfferDurationsStruct>
27
+ ] {
28
+ return [
29
+ argsToOfferStruct(args),
30
+ argsToOfferDatesStruct(args),
31
+ argsToOfferDurationsStruct(args)
32
+ ];
33
+ }
34
+
35
+ export function argsToOfferStruct(args: CreateOfferArgs): Partial<OfferStruct> {
36
+ const { exchangeToken, ...restArgs } = args;
37
+
38
+ return {
39
+ id: "0",
40
+ sellerId: "0",
41
+ ...restArgs,
42
+ exchangeToken: getAddress(exchangeToken)
43
+ };
44
+ }
45
+
46
+ export function argsToOfferDatesStruct(
47
+ args: CreateOfferArgs
48
+ ): Partial<OfferDatesStruct> {
17
49
  const {
18
- exchangeToken,
19
50
  validFromDateInMS,
20
51
  validUntilDateInMS,
21
- redeemableFromDateInMS,
22
- fulfillmentPeriodDurationInMS,
23
- voucherValidDurationInMS,
24
- ...restArgs
52
+ voucherRedeemableFromDateInMS,
53
+ voucherRedeemableUntilDateInMS
25
54
  } = args;
26
55
 
27
56
  return {
28
- id: "0",
29
- sellerId: "0",
30
- ...restArgs,
31
- exchangeToken: getAddress(exchangeToken),
32
- validFromDate: utils.timestamp.msToSec(validFromDateInMS),
33
- validUntilDate: utils.timestamp.msToSec(validUntilDateInMS),
34
- redeemableFromDate: utils.timestamp.msToSec(redeemableFromDateInMS),
35
- fulfillmentPeriodDuration: utils.timestamp.msToSec(
36
- fulfillmentPeriodDurationInMS
57
+ validFrom: utils.timestamp.msToSec(validFromDateInMS),
58
+ validUntil: utils.timestamp.msToSec(validUntilDateInMS),
59
+ voucherRedeemableFrom: utils.timestamp.msToSec(
60
+ voucherRedeemableFromDateInMS
37
61
  ),
38
- voucherValidDuration: utils.timestamp.msToSec(voucherValidDurationInMS)
62
+ voucherRedeemableUntil: utils.timestamp.msToSec(
63
+ voucherRedeemableUntilDateInMS
64
+ )
65
+ };
66
+ }
67
+
68
+ export function argsToOfferDurationsStruct(
69
+ args: CreateOfferArgs
70
+ ): Partial<OfferDurationsStruct> {
71
+ const {
72
+ fulfillmentPeriodDurationInMS,
73
+ voucherValidDurationInMS = 0,
74
+ resolutionPeriodDurationInMS
75
+ } = args;
76
+
77
+ return {
78
+ fulfillmentPeriod: utils.timestamp.msToSec(fulfillmentPeriodDurationInMS),
79
+ voucherValid: utils.timestamp.msToSec(voucherValidDurationInMS),
80
+ resolutionPeriod: utils.timestamp.msToSec(resolutionPeriodDurationInMS)
39
81
  };
40
82
  }
@@ -19,16 +19,21 @@ fragment offerFields on Offer {
19
19
  createdAt
20
20
  price
21
21
  sellerDeposit
22
+ protocolFee
22
23
  buyerCancelPenalty
23
24
  quantityAvailable
25
+ quantityInitial
24
26
  validFromDate
25
27
  validUntilDate
26
- redeemableFromDate
28
+ voucherRedeemableFromDate
29
+ voucherRedeemableUntilDate
27
30
  fulfillmentPeriodDuration
28
31
  voucherValidDuration
32
+ resolutionPeriodDuration
29
33
  metadataUri
30
34
  offerChecksum
31
35
  voidedAt
36
+ disputeResolverId
32
37
  seller {
33
38
  id
34
39
  operator
@@ -5,16 +5,21 @@ export type RawOfferFromSubgraph = {
5
5
  createdAt: string;
6
6
  price: string;
7
7
  sellerDeposit: string;
8
+ protocolFee: string;
8
9
  buyerCancelPenalty: string;
9
10
  quantityAvailable: string;
11
+ quantityInitial: string;
10
12
  validFromDate: string;
11
13
  validUntilDate: string;
12
- redeemableFromDate: string;
14
+ voucherRedeemableFromDate: string;
15
+ voucherRedeemableUntilDate: string;
13
16
  fulfillmentPeriodDuration: string;
14
17
  voucherValidDuration: string;
18
+ resolutionPeriodDuration: string;
15
19
  metadataUri: string;
16
20
  offerChecksum: string;
17
21
  voidedAt: null | string;
22
+ disputeResolverId: string;
18
23
  seller: {
19
24
  id: string;
20
25
  operator: string;
@@ -1,7 +1,7 @@
1
1
  import { abis } from "@bosonprotocol/common";
2
2
  import { Interface } from "@ethersproject/abi";
3
3
  import { createSellerArgsToStruct } from "../accounts/interface";
4
- import { createOfferArgsToStruct } from "../offers/interface";
4
+ import { createOfferArgsToStructs } from "../offers/interface";
5
5
 
6
6
  import { CreateSellerArgs } from "../accounts/types";
7
7
  import { CreateOfferArgs } from "../offers/types";
@@ -16,6 +16,6 @@ export function encodeCreateSellerAndOffer(
16
16
  ) {
17
17
  return bosonOrchestrationHandlerIface.encodeFunctionData(
18
18
  "createSellerAndOffer",
19
- [createSellerArgsToStruct(seller), createOfferArgsToStruct(offer)]
19
+ [createSellerArgsToStruct(seller), ...createOfferArgsToStructs(offer)]
20
20
  );
21
21
  }