@bosonprotocol/core-sdk 1.12.0-alpha.1 → 1.12.0-alpha.10
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/index.d.ts +2 -0
- package/dist/cjs/accounts/index.d.ts.map +1 -1
- package/dist/cjs/accounts/interface.d.ts +5 -2
- package/dist/cjs/accounts/interface.d.ts.map +1 -1
- package/dist/cjs/accounts/interface.js +27 -7
- package/dist/cjs/accounts/interface.js.map +1 -1
- package/dist/cjs/core-sdk.d.ts +35 -5
- package/dist/cjs/core-sdk.d.ts.map +1 -1
- package/dist/cjs/core-sdk.js +151 -11
- package/dist/cjs/core-sdk.js.map +1 -1
- package/dist/cjs/disputes/handler.d.ts +61 -0
- package/dist/cjs/disputes/handler.d.ts.map +1 -0
- package/dist/cjs/disputes/handler.js +104 -0
- package/dist/cjs/disputes/handler.js.map +1 -0
- package/dist/cjs/disputes/index.d.ts +4 -0
- package/dist/cjs/disputes/index.d.ts.map +1 -0
- package/dist/cjs/disputes/index.js +30 -0
- package/dist/cjs/disputes/index.js.map +1 -0
- package/dist/cjs/disputes/interface.d.ts +30 -0
- package/dist/cjs/disputes/interface.d.ts.map +1 -0
- package/dist/cjs/disputes/interface.js +74 -0
- package/dist/cjs/disputes/interface.js.map +1 -0
- package/dist/cjs/disputes/subgraph.d.ts +6 -0
- package/dist/cjs/disputes/subgraph.d.ts.map +1 -0
- package/dist/cjs/disputes/subgraph.js +30 -0
- package/dist/cjs/disputes/subgraph.js.map +1 -0
- package/dist/cjs/offers/index.d.ts +1 -2
- package/dist/cjs/offers/index.d.ts.map +1 -1
- package/dist/cjs/offers/index.js +1 -0
- package/dist/cjs/offers/index.js.map +1 -1
- package/dist/cjs/offers/interface.d.ts +1 -0
- package/dist/cjs/offers/interface.d.ts.map +1 -1
- package/dist/cjs/offers/interface.js +2 -1
- package/dist/cjs/offers/interface.js.map +1 -1
- package/dist/cjs/offers/renderContractualAgreement.d.ts +41 -0
- package/dist/cjs/offers/renderContractualAgreement.d.ts.map +1 -0
- package/dist/cjs/offers/renderContractualAgreement.js +156 -0
- package/dist/cjs/offers/renderContractualAgreement.js.map +1 -0
- package/dist/cjs/offers/subgraph.d.ts.map +1 -1
- package/dist/cjs/offers/subgraph.js.map +1 -1
- package/dist/cjs/orchestration/interface.d.ts.map +1 -1
- package/dist/cjs/orchestration/interface.js +9 -2
- package/dist/cjs/orchestration/interface.js.map +1 -1
- package/dist/cjs/subgraph.d.ts +4426 -50
- package/dist/cjs/subgraph.d.ts.map +1 -1
- package/dist/cjs/subgraph.js +319 -169
- package/dist/cjs/subgraph.js.map +1 -1
- package/dist/cjs/utils/graphql.d.ts +16 -0
- package/dist/cjs/utils/graphql.d.ts.map +1 -1
- package/dist/cjs/utils/tokenInfoManager.d.ts +16 -0
- package/dist/cjs/utils/tokenInfoManager.d.ts.map +1 -0
- package/dist/cjs/utils/tokenInfoManager.js +97 -0
- package/dist/cjs/utils/tokenInfoManager.js.map +1 -0
- package/dist/esm/accounts/index.d.ts +2 -0
- package/dist/esm/accounts/index.d.ts.map +1 -1
- package/dist/esm/accounts/interface.d.ts +5 -2
- package/dist/esm/accounts/interface.d.ts.map +1 -1
- package/dist/esm/accounts/interface.js +17 -8
- package/dist/esm/accounts/interface.js.map +1 -1
- package/dist/esm/core-sdk.d.ts +35 -5
- package/dist/esm/core-sdk.d.ts.map +1 -1
- package/dist/esm/core-sdk.js +127 -11
- package/dist/esm/core-sdk.js.map +1 -1
- package/dist/esm/disputes/handler.d.ts +61 -0
- package/dist/esm/disputes/handler.d.ts.map +1 -0
- package/dist/esm/disputes/handler.js +62 -0
- package/dist/esm/disputes/handler.js.map +1 -0
- package/dist/esm/disputes/index.d.ts +4 -0
- package/dist/esm/disputes/index.d.ts.map +1 -0
- package/dist/esm/disputes/index.js +4 -0
- package/dist/esm/disputes/index.js.map +1 -0
- package/dist/esm/disputes/interface.d.ts +30 -0
- package/dist/esm/disputes/interface.d.ts.map +1 -0
- package/dist/esm/disputes/interface.js +61 -0
- package/dist/esm/disputes/interface.js.map +1 -0
- package/dist/esm/disputes/subgraph.d.ts +6 -0
- package/dist/esm/disputes/subgraph.d.ts.map +1 -0
- package/dist/esm/disputes/subgraph.js +15 -0
- package/dist/esm/disputes/subgraph.js.map +1 -0
- package/dist/esm/offers/index.d.ts +1 -2
- package/dist/esm/offers/index.d.ts.map +1 -1
- package/dist/esm/offers/index.js +1 -0
- package/dist/esm/offers/index.js.map +1 -1
- package/dist/esm/offers/interface.d.ts +1 -0
- package/dist/esm/offers/interface.d.ts.map +1 -1
- package/dist/esm/offers/interface.js +2 -1
- package/dist/esm/offers/interface.js.map +1 -1
- package/dist/esm/offers/renderContractualAgreement.d.ts +41 -0
- package/dist/esm/offers/renderContractualAgreement.d.ts.map +1 -0
- package/dist/esm/offers/renderContractualAgreement.js +132 -0
- package/dist/esm/offers/renderContractualAgreement.js.map +1 -0
- package/dist/esm/offers/subgraph.d.ts.map +1 -1
- package/dist/esm/offers/subgraph.js.map +1 -1
- package/dist/esm/orchestration/interface.d.ts.map +1 -1
- package/dist/esm/orchestration/interface.js +9 -2
- package/dist/esm/orchestration/interface.js.map +1 -1
- package/dist/esm/subgraph.d.ts +4426 -50
- package/dist/esm/subgraph.d.ts.map +1 -1
- package/dist/esm/subgraph.js +317 -167
- package/dist/esm/subgraph.js.map +1 -1
- package/dist/esm/utils/graphql.d.ts +16 -0
- package/dist/esm/utils/graphql.d.ts.map +1 -1
- package/dist/esm/utils/tokenInfoManager.d.ts +16 -0
- package/dist/esm/utils/tokenInfoManager.d.ts.map +1 -0
- package/dist/esm/utils/tokenInfoManager.js +83 -0
- package/dist/esm/utils/tokenInfoManager.js.map +1 -0
- package/package.json +6 -4
- package/src/accounts/interface.ts +22 -11
- package/src/accounts/queries.graphql +3 -0
- package/src/core-sdk.ts +202 -16
- package/src/disputes/handler.ts +132 -0
- package/src/disputes/index.ts +3 -0
- package/src/disputes/interface.ts +90 -0
- package/src/disputes/queries.graphql +56 -0
- package/src/disputes/subgraph.ts +34 -0
- package/src/metadata/product-v1.graphql +3 -0
- package/src/offers/index.ts +1 -0
- package/src/offers/interface.ts +3 -1
- package/src/offers/queries.graphql +31 -0
- package/src/offers/renderContractualAgreement.ts +203 -0
- package/src/offers/subgraph.ts +0 -1
- package/src/orchestration/interface.ts +9 -2
- package/src/subgraph.ts +4738 -272
- package/src/utils/tokenInfoManager.ts +97 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/utils/graphql.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/utils/graphql.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Web3LibAdapter } from "@bosonprotocol/common";
|
|
2
|
+
export interface ITokenInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
decimals: number;
|
|
5
|
+
symbol: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ITokenInfoManager {
|
|
8
|
+
getExchangeTokenInfo: (tokenAddress: string) => Promise<ITokenInfo>;
|
|
9
|
+
}
|
|
10
|
+
export declare class TokenInfoManager implements ITokenInfoManager {
|
|
11
|
+
private _tokenInfos;
|
|
12
|
+
private _web3Lib;
|
|
13
|
+
constructor(chainId: number, web3Lib: Web3LibAdapter);
|
|
14
|
+
getExchangeTokenInfo(tokenAddress: string): Promise<ITokenInfo>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=tokenInfoManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenInfoManager.d.ts","sourceRoot":"","sources":["../../../src/utils/tokenInfoManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,oBAAoB,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CACrE;AAqDD,qBAAa,gBAAiB,YAAW,iBAAiB;IACxD,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,QAAQ,CAAiB;gBAEd,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc;IAQ9C,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAmB7E"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { AddressZero } from "@ethersproject/constants";
|
|
2
|
+
import { erc20 } from "..";
|
|
3
|
+
const NATIVE_TOKENS = {
|
|
4
|
+
1: {
|
|
5
|
+
// Ethereum Mainnet
|
|
6
|
+
name: "Ether",
|
|
7
|
+
decimals: 18,
|
|
8
|
+
symbol: "ETH"
|
|
9
|
+
},
|
|
10
|
+
3: {
|
|
11
|
+
// Ethereum Ropsten
|
|
12
|
+
name: "Ether",
|
|
13
|
+
decimals: 18,
|
|
14
|
+
symbol: "ETH"
|
|
15
|
+
},
|
|
16
|
+
4: {
|
|
17
|
+
// Ethereum Rinkeby
|
|
18
|
+
name: "Ether",
|
|
19
|
+
decimals: 18,
|
|
20
|
+
symbol: "ETH"
|
|
21
|
+
},
|
|
22
|
+
5: {
|
|
23
|
+
// Ethereum Goerli
|
|
24
|
+
name: "Ether",
|
|
25
|
+
decimals: 18,
|
|
26
|
+
symbol: "ETH"
|
|
27
|
+
},
|
|
28
|
+
137: {
|
|
29
|
+
// Polygon Mainnet
|
|
30
|
+
name: "MATIC",
|
|
31
|
+
decimals: 18,
|
|
32
|
+
symbol: "MATIC"
|
|
33
|
+
},
|
|
34
|
+
80001: {
|
|
35
|
+
// Polygon Mumbai
|
|
36
|
+
name: "MATIC",
|
|
37
|
+
decimals: 18,
|
|
38
|
+
symbol: "MATIC"
|
|
39
|
+
},
|
|
40
|
+
1234: {
|
|
41
|
+
// Private Node
|
|
42
|
+
name: "Ether",
|
|
43
|
+
decimals: 18,
|
|
44
|
+
symbol: "ETH"
|
|
45
|
+
},
|
|
46
|
+
31337: {
|
|
47
|
+
// Local Hardhat
|
|
48
|
+
name: "Ether",
|
|
49
|
+
decimals: 18,
|
|
50
|
+
symbol: "ETH"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export class TokenInfoManager {
|
|
54
|
+
_tokenInfos = new Map();
|
|
55
|
+
_web3Lib;
|
|
56
|
+
constructor(chainId, web3Lib) {
|
|
57
|
+
if (!NATIVE_TOKENS[chainId]) {
|
|
58
|
+
throw new Error(`Unexpected chainId value '${chainId}'`);
|
|
59
|
+
}
|
|
60
|
+
this._tokenInfos.set(AddressZero, NATIVE_TOKENS[chainId]);
|
|
61
|
+
this._web3Lib = web3Lib;
|
|
62
|
+
}
|
|
63
|
+
async getExchangeTokenInfo(tokenAddress) {
|
|
64
|
+
if (!this._tokenInfos.has(tokenAddress.toLowerCase())) {
|
|
65
|
+
const args = {
|
|
66
|
+
web3Lib: this._web3Lib,
|
|
67
|
+
contractAddress: tokenAddress
|
|
68
|
+
};
|
|
69
|
+
const [decimals, name, symbol] = await Promise.all([
|
|
70
|
+
erc20.handler.getDecimals(args),
|
|
71
|
+
erc20.handler.getName(args),
|
|
72
|
+
erc20.handler.getSymbol(args)
|
|
73
|
+
]);
|
|
74
|
+
this._tokenInfos.set(tokenAddress.toLowerCase(), {
|
|
75
|
+
decimals,
|
|
76
|
+
name,
|
|
77
|
+
symbol
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return this._tokenInfos.get(tokenAddress.toLowerCase());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=tokenInfoManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenInfoManager.js","sourceRoot":"","sources":["../../../src/utils/tokenInfoManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAY3B,MAAM,aAAa,GAAkC;IACnD,CAAC,EAAE;QACD,mBAAmB;QACnB,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,KAAK;KACd;IACD,CAAC,EAAE;QACD,mBAAmB;QACnB,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,KAAK;KACd;IACD,CAAC,EAAE;QACD,mBAAmB;QACnB,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,KAAK;KACd;IACD,CAAC,EAAE;QACD,kBAAkB;QAClB,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,KAAK;KACd;IACD,GAAG,EAAE;QACH,kBAAkB;QAClB,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,OAAO;KAChB;IACD,KAAK,EAAE;QACL,iBAAiB;QACjB,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,OAAO;KAChB;IACD,IAAI,EAAE;QACJ,eAAe;QACf,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,KAAK;KACd;IACD,KAAK,EAAE;QACL,gBAAgB;QAChB,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,KAAK;KACd;CACF,CAAC;AAEF,MAAM,OAAO,gBAAgB;IACnB,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC5C,QAAQ,CAAiB;IAEjC,YAAmB,OAAe,EAAE,OAAuB;QACzD,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,GAAG,CAAC,CAAC;SAC1D;QACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,YAAoB;QACpD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,EAAE;YACrD,MAAM,IAAI,GAAG;gBACX,OAAO,EAAE,IAAI,CAAC,QAAQ;gBACtB,eAAe,EAAE,YAAY;aAC9B,CAAC;YACF,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACjD,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC;gBAC/B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;gBAC3B,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC;aAC9B,CAAC,CAAC;YACH,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE;gBAC/C,QAAQ;gBACR,IAAI;gBACJ,MAAM;aACP,CAAC,CAAC;SACJ;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bosonprotocol/core-sdk",
|
|
3
|
-
"version": "1.12.0-alpha.
|
|
3
|
+
"version": "1.12.0-alpha.10",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -33,15 +33,17 @@
|
|
|
33
33
|
"access": "restricted"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@bosonprotocol/common": "^1.9.0-alpha.
|
|
36
|
+
"@bosonprotocol/common": "^1.9.0-alpha.10",
|
|
37
37
|
"@ethersproject/abi": "^5.5.0",
|
|
38
38
|
"@ethersproject/address": "^5.5.0",
|
|
39
39
|
"@ethersproject/bignumber": "^5.5.0",
|
|
40
|
+
"@ethersproject/bytes": "^5.6.1",
|
|
40
41
|
"@ethersproject/constants": "^5.5.0",
|
|
41
42
|
"@ethersproject/units": "^5.5.0",
|
|
42
43
|
"cross-fetch": "^3.1.5",
|
|
43
44
|
"graphql": "^16.5.0",
|
|
44
|
-
"graphql-request": "^4.3.0"
|
|
45
|
+
"graphql-request": "^4.3.0",
|
|
46
|
+
"mustache": "^4.2.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"eslint": "^8.10.0",
|
|
@@ -51,5 +53,5 @@
|
|
|
51
53
|
"ts-jest": "^27.1.3",
|
|
52
54
|
"typescript": "^4.5.5"
|
|
53
55
|
},
|
|
54
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "97acb60ebdb531a063787e99cc44cf5a4461aa25"
|
|
55
57
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SellerStruct,
|
|
3
|
+
AuthTokenStruct,
|
|
3
4
|
abis,
|
|
4
5
|
DisputeResolverStruct,
|
|
5
6
|
utils
|
|
@@ -17,9 +18,11 @@ export const bosonAccountHandlerIface = new Interface(
|
|
|
17
18
|
);
|
|
18
19
|
|
|
19
20
|
export function encodeCreateAccount(seller: CreateSellerArgs) {
|
|
21
|
+
const sellerArgs = createSellerArgsToStruct(seller);
|
|
20
22
|
return bosonAccountHandlerIface.encodeFunctionData("createSeller", [
|
|
21
|
-
|
|
22
|
-
seller.contractUri
|
|
23
|
+
sellerArgs.sellerStruct,
|
|
24
|
+
seller.contractUri,
|
|
25
|
+
sellerArgs.authTokenStruct
|
|
23
26
|
]);
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -86,16 +89,24 @@ export function encodeUpdateDisputeResolver(
|
|
|
86
89
|
]);
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
export function createSellerArgsToStruct(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
export function createSellerArgsToStruct(args: CreateSellerArgs): {
|
|
93
|
+
sellerStruct: Partial<SellerStruct>;
|
|
94
|
+
authTokenStruct: AuthTokenStruct;
|
|
95
|
+
} {
|
|
96
|
+
const { authTokenId, authTokenType, ...sellerStructArgs } = args;
|
|
92
97
|
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
sellerStruct: {
|
|
99
|
+
// NOTE: It doesn't matter which values we set for `id` and `active` here
|
|
100
|
+
// as they will be overridden by the contract. But to conform to the struct
|
|
101
|
+
// we need to set some arbitrary values.
|
|
102
|
+
id: "0",
|
|
103
|
+
active: true,
|
|
104
|
+
...sellerStructArgs
|
|
105
|
+
},
|
|
106
|
+
authTokenStruct: {
|
|
107
|
+
tokenId: authTokenId,
|
|
108
|
+
tokenType: authTokenType
|
|
109
|
+
}
|
|
99
110
|
};
|
|
100
111
|
}
|
|
101
112
|
|
package/src/core-sdk.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ITokenInfo, TokenInfoManager } from "./utils/tokenInfoManager";
|
|
1
2
|
import {
|
|
2
3
|
Web3LibAdapter,
|
|
3
4
|
TransactionResponse,
|
|
@@ -8,8 +9,10 @@ import {
|
|
|
8
9
|
} from "@bosonprotocol/common";
|
|
9
10
|
import { BigNumberish } from "@ethersproject/bignumber";
|
|
10
11
|
import { AddressZero } from "@ethersproject/constants";
|
|
12
|
+
import { BytesLike } from "@ethersproject/bytes";
|
|
11
13
|
|
|
12
14
|
import * as accounts from "./accounts";
|
|
15
|
+
import * as disputes from "./disputes";
|
|
13
16
|
import * as exchanges from "./exchanges";
|
|
14
17
|
import * as offers from "./offers";
|
|
15
18
|
import * as orchestration from "./orchestration";
|
|
@@ -28,6 +31,8 @@ export class CoreSDK {
|
|
|
28
31
|
|
|
29
32
|
private _subgraphUrl: string;
|
|
30
33
|
private _protocolDiamond: string;
|
|
34
|
+
private _chainId: number;
|
|
35
|
+
private _tokenInfoManager: TokenInfoManager;
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
38
|
* Creates an instance of `CoreSDK`
|
|
@@ -39,12 +44,14 @@ export class CoreSDK {
|
|
|
39
44
|
protocolDiamond: string;
|
|
40
45
|
metadataStorage?: MetadataStorage;
|
|
41
46
|
theGraphStorage?: MetadataStorage;
|
|
47
|
+
chainId?: number;
|
|
42
48
|
}) {
|
|
43
49
|
this._web3Lib = opts.web3Lib;
|
|
44
50
|
this._subgraphUrl = opts.subgraphUrl;
|
|
45
51
|
this._protocolDiamond = opts.protocolDiamond;
|
|
46
52
|
this._metadataStorage = opts.metadataStorage;
|
|
47
53
|
this._theGraphStorage = opts.theGraphStorage;
|
|
54
|
+
this._chainId = opts.chainId;
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
/**
|
|
@@ -80,7 +87,8 @@ export class CoreSDK {
|
|
|
80
87
|
metadataStorage: args.metadataStorage,
|
|
81
88
|
theGraphStorage: args.theGraphStorage,
|
|
82
89
|
subgraphUrl: defaultConfig.subgraphUrl,
|
|
83
|
-
protocolDiamond: defaultConfig.contracts.protocolDiamond
|
|
90
|
+
protocolDiamond: defaultConfig.contracts.protocolDiamond,
|
|
91
|
+
chainId: args.chainId
|
|
84
92
|
});
|
|
85
93
|
}
|
|
86
94
|
|
|
@@ -641,22 +649,21 @@ export class CoreSDK {
|
|
|
641
649
|
* @param exchangeToken - Address exchange token.
|
|
642
650
|
* @returns Decimals, name and symbol.
|
|
643
651
|
*/
|
|
644
|
-
public async getExchangeTokenInfo(
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
]);
|
|
652
|
+
public async getExchangeTokenInfo(
|
|
653
|
+
exchangeToken: string
|
|
654
|
+
): Promise<ITokenInfo> {
|
|
655
|
+
if (this._chainId === undefined) {
|
|
656
|
+
this._chainId = await this._web3Lib.getChainId();
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
if (this._tokenInfoManager === undefined) {
|
|
660
|
+
this._tokenInfoManager = new TokenInfoManager(
|
|
661
|
+
this._chainId,
|
|
662
|
+
this._web3Lib
|
|
663
|
+
);
|
|
664
|
+
}
|
|
658
665
|
|
|
659
|
-
return
|
|
666
|
+
return this._tokenInfoManager.getExchangeTokenInfo(exchangeToken);
|
|
660
667
|
}
|
|
661
668
|
|
|
662
669
|
/**
|
|
@@ -923,6 +930,167 @@ export class CoreSDK {
|
|
|
923
930
|
/* Dispute related methods */
|
|
924
931
|
/* -------------------------------------------------------------------------- */
|
|
925
932
|
|
|
933
|
+
public async getDisputeById(
|
|
934
|
+
disputeId: BigNumberish,
|
|
935
|
+
queryVars?: disputes.subgraph.SingleDisputeQueryVariables
|
|
936
|
+
) {
|
|
937
|
+
return disputes.subgraph.getDisputeById(
|
|
938
|
+
this._subgraphUrl,
|
|
939
|
+
disputeId,
|
|
940
|
+
queryVars
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
public async getDisputes(
|
|
945
|
+
queryVars?: subgraph.GetDisputesQueryQueryVariables
|
|
946
|
+
) {
|
|
947
|
+
return disputes.subgraph.getDisputes(this._subgraphUrl, queryVars);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
public async raiseDispute(
|
|
951
|
+
exchangeId: BigNumberish,
|
|
952
|
+
complaint: string
|
|
953
|
+
): Promise<TransactionResponse> {
|
|
954
|
+
return disputes.handler.raiseDispute({
|
|
955
|
+
exchangeId,
|
|
956
|
+
complaint,
|
|
957
|
+
contractAddress: this._protocolDiamond,
|
|
958
|
+
web3Lib: this._web3Lib
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
public async retractDispute(
|
|
963
|
+
exchangeId: BigNumberish
|
|
964
|
+
): Promise<TransactionResponse> {
|
|
965
|
+
return disputes.handler.retractDispute({
|
|
966
|
+
exchangeId,
|
|
967
|
+
contractAddress: this._protocolDiamond,
|
|
968
|
+
web3Lib: this._web3Lib
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
public async extendDisputeTimeout(
|
|
973
|
+
exchangeId: BigNumberish,
|
|
974
|
+
newDisputeTimeout: BigNumberish
|
|
975
|
+
): Promise<TransactionResponse> {
|
|
976
|
+
return disputes.handler.extendDisputeTimeout({
|
|
977
|
+
exchangeId,
|
|
978
|
+
newDisputeTimeout,
|
|
979
|
+
contractAddress: this._protocolDiamond,
|
|
980
|
+
web3Lib: this._web3Lib
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
public async expireDispute(
|
|
985
|
+
exchangeId: BigNumberish
|
|
986
|
+
): Promise<TransactionResponse> {
|
|
987
|
+
return disputes.handler.expireDispute({
|
|
988
|
+
exchangeId,
|
|
989
|
+
contractAddress: this._protocolDiamond,
|
|
990
|
+
web3Lib: this._web3Lib
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
public async expireDisputeBatch(
|
|
995
|
+
exchangeIds: BigNumberish[]
|
|
996
|
+
): Promise<TransactionResponse> {
|
|
997
|
+
return disputes.handler.expireDisputeBatch({
|
|
998
|
+
exchangeIds,
|
|
999
|
+
contractAddress: this._protocolDiamond,
|
|
1000
|
+
web3Lib: this._web3Lib
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
public async resolveDispute(args: {
|
|
1005
|
+
exchangeId: BigNumberish;
|
|
1006
|
+
buyerPercent: BigNumberish;
|
|
1007
|
+
sigR: BytesLike;
|
|
1008
|
+
sigS: BytesLike;
|
|
1009
|
+
sigV: BigNumberish;
|
|
1010
|
+
}): Promise<TransactionResponse> {
|
|
1011
|
+
return disputes.handler.resolveDispute({
|
|
1012
|
+
...args,
|
|
1013
|
+
contractAddress: this._protocolDiamond,
|
|
1014
|
+
web3Lib: this._web3Lib
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
public async escalateDispute(
|
|
1019
|
+
exchangeId: BigNumberish
|
|
1020
|
+
): Promise<TransactionResponse> {
|
|
1021
|
+
return disputes.handler.escalateDispute({
|
|
1022
|
+
exchangeId,
|
|
1023
|
+
contractAddress: this._protocolDiamond,
|
|
1024
|
+
web3Lib: this._web3Lib
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
public async decideDispute(
|
|
1029
|
+
exchangeId: BigNumberish,
|
|
1030
|
+
buyerPercent: BigNumberish
|
|
1031
|
+
): Promise<TransactionResponse> {
|
|
1032
|
+
return disputes.handler.decideDispute({
|
|
1033
|
+
exchangeId,
|
|
1034
|
+
buyerPercent,
|
|
1035
|
+
contractAddress: this._protocolDiamond,
|
|
1036
|
+
web3Lib: this._web3Lib
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
public async refuseEscalatedDispute(
|
|
1041
|
+
exchangeId: BigNumberish
|
|
1042
|
+
): Promise<TransactionResponse> {
|
|
1043
|
+
return disputes.handler.refuseEscalatedDispute({
|
|
1044
|
+
exchangeId,
|
|
1045
|
+
contractAddress: this._protocolDiamond,
|
|
1046
|
+
web3Lib: this._web3Lib
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
public async expireEscalatedDispute(
|
|
1051
|
+
exchangeId: BigNumberish
|
|
1052
|
+
): Promise<TransactionResponse> {
|
|
1053
|
+
return disputes.handler.expireEscalatedDispute({
|
|
1054
|
+
exchangeId,
|
|
1055
|
+
contractAddress: this._protocolDiamond,
|
|
1056
|
+
web3Lib: this._web3Lib
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
public async signMutualAgreement(args: {
|
|
1061
|
+
exchangeId: string;
|
|
1062
|
+
buyerPercent: string;
|
|
1063
|
+
}) {
|
|
1064
|
+
// Set the message Type, needed for signature
|
|
1065
|
+
const resolutionType = [
|
|
1066
|
+
{ name: "exchangeId", type: "uint256" },
|
|
1067
|
+
{ name: "buyerPercent", type: "uint256" }
|
|
1068
|
+
];
|
|
1069
|
+
|
|
1070
|
+
const customSignatureType = {
|
|
1071
|
+
Resolution: resolutionType
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
const message = {
|
|
1075
|
+
exchangeId: args.exchangeId,
|
|
1076
|
+
buyerPercent: args.buyerPercent
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
if (this._chainId === undefined) {
|
|
1080
|
+
this._chainId = await this._web3Lib.getChainId();
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
return metaTx.handler.prepareDataSignatureParameters({
|
|
1084
|
+
web3Lib: this._web3Lib,
|
|
1085
|
+
metaTxHandlerAddress: this._protocolDiamond,
|
|
1086
|
+
chainId: this._chainId,
|
|
1087
|
+
customTransactionType: customSignatureType,
|
|
1088
|
+
primaryType: "Resolution",
|
|
1089
|
+
message,
|
|
1090
|
+
nonce: "" // not used in this case
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
|
|
926
1094
|
/* -------------------------------------------------------------------------- */
|
|
927
1095
|
/* Meta Tx related methods */
|
|
928
1096
|
/* -------------------------------------------------------------------------- */
|
|
@@ -983,4 +1151,22 @@ export class CoreSDK {
|
|
|
983
1151
|
...args
|
|
984
1152
|
});
|
|
985
1153
|
}
|
|
1154
|
+
|
|
1155
|
+
public async renderContractualAgreementForOffer(
|
|
1156
|
+
offerId: BigNumberish
|
|
1157
|
+
): Promise<string> {
|
|
1158
|
+
const offerData = await offers.subgraph.getOfferById(
|
|
1159
|
+
this._subgraphUrl,
|
|
1160
|
+
offerId
|
|
1161
|
+
);
|
|
1162
|
+
return offers.renderContractualAgreementForOffer(offerData);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
public async renderContractualAgreement(
|
|
1166
|
+
template: string,
|
|
1167
|
+
offerData: offers.CreateOfferArgs
|
|
1168
|
+
): Promise<string> {
|
|
1169
|
+
const tokenInfo = await this.getExchangeTokenInfo(offerData.exchangeToken);
|
|
1170
|
+
return offers.renderContractualAgreement(template, offerData, tokenInfo);
|
|
1171
|
+
}
|
|
986
1172
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Web3LibAdapter, TransactionResponse } from "@bosonprotocol/common";
|
|
2
|
+
import { BigNumberish } from "@ethersproject/bignumber";
|
|
3
|
+
import { BytesLike } from "@ethersproject/bytes";
|
|
4
|
+
import {
|
|
5
|
+
encodeRaiseDispute,
|
|
6
|
+
encodeDecideDispute,
|
|
7
|
+
encodeEscalateDispute,
|
|
8
|
+
encodeExpireDispute,
|
|
9
|
+
encodeExpireDisputeBatch,
|
|
10
|
+
encodeExpireEscalatedDispute,
|
|
11
|
+
encodeExtendDisputeTimeout,
|
|
12
|
+
encodeRefuseEscalatedDispute,
|
|
13
|
+
encodeResolveDispute,
|
|
14
|
+
encodeRetractDispute
|
|
15
|
+
} from "./interface";
|
|
16
|
+
|
|
17
|
+
export async function raiseDispute(args: {
|
|
18
|
+
exchangeId: BigNumberish;
|
|
19
|
+
complaint: string;
|
|
20
|
+
contractAddress: string;
|
|
21
|
+
web3Lib: Web3LibAdapter;
|
|
22
|
+
}): Promise<TransactionResponse> {
|
|
23
|
+
return args.web3Lib.sendTransaction({
|
|
24
|
+
to: args.contractAddress,
|
|
25
|
+
data: encodeRaiseDispute(args)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function retractDispute(args: {
|
|
30
|
+
exchangeId: BigNumberish;
|
|
31
|
+
contractAddress: string;
|
|
32
|
+
web3Lib: Web3LibAdapter;
|
|
33
|
+
}): Promise<TransactionResponse> {
|
|
34
|
+
return args.web3Lib.sendTransaction({
|
|
35
|
+
to: args.contractAddress,
|
|
36
|
+
data: encodeRetractDispute(args.exchangeId)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function extendDisputeTimeout(args: {
|
|
41
|
+
exchangeId: BigNumberish;
|
|
42
|
+
newDisputeTimeout: BigNumberish;
|
|
43
|
+
contractAddress: string;
|
|
44
|
+
web3Lib: Web3LibAdapter;
|
|
45
|
+
}): Promise<TransactionResponse> {
|
|
46
|
+
return args.web3Lib.sendTransaction({
|
|
47
|
+
to: args.contractAddress,
|
|
48
|
+
data: encodeExtendDisputeTimeout(args)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function expireDispute(args: {
|
|
53
|
+
exchangeId: BigNumberish;
|
|
54
|
+
contractAddress: string;
|
|
55
|
+
web3Lib: Web3LibAdapter;
|
|
56
|
+
}): Promise<TransactionResponse> {
|
|
57
|
+
return args.web3Lib.sendTransaction({
|
|
58
|
+
to: args.contractAddress,
|
|
59
|
+
data: encodeExpireDispute(args.exchangeId)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function expireDisputeBatch(args: {
|
|
64
|
+
exchangeIds: BigNumberish[];
|
|
65
|
+
contractAddress: string;
|
|
66
|
+
web3Lib: Web3LibAdapter;
|
|
67
|
+
}): Promise<TransactionResponse> {
|
|
68
|
+
return args.web3Lib.sendTransaction({
|
|
69
|
+
to: args.contractAddress,
|
|
70
|
+
data: encodeExpireDisputeBatch(args.exchangeIds)
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function resolveDispute(args: {
|
|
75
|
+
exchangeId: BigNumberish;
|
|
76
|
+
buyerPercent: BigNumberish;
|
|
77
|
+
sigR: BytesLike;
|
|
78
|
+
sigS: BytesLike;
|
|
79
|
+
sigV: BigNumberish;
|
|
80
|
+
contractAddress: string;
|
|
81
|
+
web3Lib: Web3LibAdapter;
|
|
82
|
+
}): Promise<TransactionResponse> {
|
|
83
|
+
return args.web3Lib.sendTransaction({
|
|
84
|
+
to: args.contractAddress,
|
|
85
|
+
data: encodeResolveDispute(args)
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function escalateDispute(args: {
|
|
90
|
+
exchangeId: BigNumberish;
|
|
91
|
+
contractAddress: string;
|
|
92
|
+
web3Lib: Web3LibAdapter;
|
|
93
|
+
}): Promise<TransactionResponse> {
|
|
94
|
+
return args.web3Lib.sendTransaction({
|
|
95
|
+
to: args.contractAddress,
|
|
96
|
+
data: encodeEscalateDispute(args.exchangeId)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function decideDispute(args: {
|
|
101
|
+
exchangeId: BigNumberish;
|
|
102
|
+
buyerPercent: BigNumberish;
|
|
103
|
+
contractAddress: string;
|
|
104
|
+
web3Lib: Web3LibAdapter;
|
|
105
|
+
}): Promise<TransactionResponse> {
|
|
106
|
+
return args.web3Lib.sendTransaction({
|
|
107
|
+
to: args.contractAddress,
|
|
108
|
+
data: encodeDecideDispute(args)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function refuseEscalatedDispute(args: {
|
|
113
|
+
exchangeId: BigNumberish;
|
|
114
|
+
contractAddress: string;
|
|
115
|
+
web3Lib: Web3LibAdapter;
|
|
116
|
+
}): Promise<TransactionResponse> {
|
|
117
|
+
return args.web3Lib.sendTransaction({
|
|
118
|
+
to: args.contractAddress,
|
|
119
|
+
data: encodeRefuseEscalatedDispute(args.exchangeId)
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function expireEscalatedDispute(args: {
|
|
124
|
+
exchangeId: BigNumberish;
|
|
125
|
+
contractAddress: string;
|
|
126
|
+
web3Lib: Web3LibAdapter;
|
|
127
|
+
}): Promise<TransactionResponse> {
|
|
128
|
+
return args.web3Lib.sendTransaction({
|
|
129
|
+
to: args.contractAddress,
|
|
130
|
+
data: encodeExpireEscalatedDispute(args.exchangeId)
|
|
131
|
+
});
|
|
132
|
+
}
|