@trustvc/trustvc 1.6.0-alpha.1 → 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/core/endorsement-chain/useEndorsementChain.js +5 -6
- package/dist/cjs/token-registry-functions/index.js +28 -0
- package/dist/cjs/token-registry-functions/mint.js +86 -0
- package/dist/cjs/token-registry-functions/ownerOf.js +45 -0
- package/dist/cjs/token-registry-functions/rejectTransfers.js +123 -0
- package/dist/cjs/token-registry-functions/returnToken.js +204 -0
- package/dist/cjs/token-registry-functions/transfer.js +16 -58
- package/dist/cjs/token-registry-functions/types.js +2 -0
- package/dist/cjs/token-registry-functions/utils.js +37 -0
- package/dist/esm/core/endorsement-chain/useEndorsementChain.js +5 -7
- package/dist/esm/token-registry-functions/index.js +4 -0
- package/dist/esm/token-registry-functions/mint.js +84 -0
- package/dist/esm/token-registry-functions/ownerOf.js +43 -0
- package/dist/esm/token-registry-functions/rejectTransfers.js +119 -0
- package/dist/esm/token-registry-functions/returnToken.js +200 -0
- package/dist/esm/token-registry-functions/transfer.js +16 -58
- package/dist/esm/token-registry-functions/types.js +1 -0
- package/dist/esm/token-registry-functions/utils.js +33 -0
- package/dist/types/core/endorsement-chain/index.d.ts +1 -1
- package/dist/types/core/endorsement-chain/useEndorsementChain.d.ts +2 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/index.d.ts +6 -1
- package/dist/types/token-registry-functions/index.d.ts +6 -1
- package/dist/types/token-registry-functions/mint.d.ts +20 -0
- package/dist/types/token-registry-functions/ownerOf.d.ts +19 -0
- package/dist/types/token-registry-functions/rejectTransfers.d.ts +43 -0
- package/dist/types/token-registry-functions/returnToken.d.ts +44 -0
- package/dist/types/token-registry-functions/transfer.d.ts +79 -40
- package/dist/types/token-registry-functions/types.d.ts +80 -0
- package/dist/types/token-registry-functions/utils.d.ts +13 -0
- package/package.json +1 -1
|
@@ -92,14 +92,12 @@ const getDocumentOwner = /* @__PURE__ */ __name(async (tokenRegistryAddress, tok
|
|
|
92
92
|
const tokenRegistry = new Contract(tokenRegistryAddress, tokenRegistryAbi, provider);
|
|
93
93
|
return await tokenRegistry.ownerOf(tokenId);
|
|
94
94
|
}, "getDocumentOwner");
|
|
95
|
-
const checkSupportsInterface = /* @__PURE__ */ __name(async (
|
|
95
|
+
const checkSupportsInterface = /* @__PURE__ */ __name(async (contractAddress, interfaceId, provider) => {
|
|
96
96
|
try {
|
|
97
97
|
const Contract = ethers.getEthersContractFromProvider(provider);
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const titleEscrowContract = new Contract(titleEscrowAddress, titleEscrowAbi, provider);
|
|
102
|
-
return await titleEscrowContract.supportsInterface(interfaceId);
|
|
98
|
+
const abi = ["function supportsInterface(bytes4 interfaceId) external view returns (bool)"];
|
|
99
|
+
const contract = new Contract(contractAddress, abi, provider);
|
|
100
|
+
return await contract.supportsInterface(interfaceId);
|
|
103
101
|
} catch {
|
|
104
102
|
return false;
|
|
105
103
|
}
|
|
@@ -165,6 +163,7 @@ const fetchEndorsementChain = /* @__PURE__ */ __name(async (tokenRegistryAddress
|
|
|
165
163
|
}, "fetchEndorsementChain");
|
|
166
164
|
|
|
167
165
|
exports.TitleEscrowInterface = TitleEscrowInterface;
|
|
166
|
+
exports.checkSupportsInterface = checkSupportsInterface;
|
|
168
167
|
exports.fetchEndorsementChain = fetchEndorsementChain;
|
|
169
168
|
exports.getDocumentOwner = getDocumentOwner;
|
|
170
169
|
exports.getTitleEscrowAddress = getTitleEscrowAddress;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var transfer = require('./transfer');
|
|
4
|
+
var rejectTransfers = require('./rejectTransfers');
|
|
5
|
+
var returnToken = require('./returnToken');
|
|
6
|
+
var mint = require('./mint');
|
|
7
|
+
var ownerOf = require('./ownerOf');
|
|
4
8
|
|
|
5
9
|
|
|
6
10
|
|
|
@@ -10,3 +14,27 @@ Object.keys(transfer).forEach(function (k) {
|
|
|
10
14
|
get: function () { return transfer[k]; }
|
|
11
15
|
});
|
|
12
16
|
});
|
|
17
|
+
Object.keys(rejectTransfers).forEach(function (k) {
|
|
18
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return rejectTransfers[k]; }
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
Object.keys(returnToken).forEach(function (k) {
|
|
24
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return returnToken[k]; }
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
Object.keys(mint).forEach(function (k) {
|
|
30
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return mint[k]; }
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
Object.keys(ownerOf).forEach(function (k) {
|
|
36
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return ownerOf[k]; }
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var tokenRegistryV5 = require('../token-registry-v5');
|
|
5
|
+
var tokenRegistryV4 = require('../token-registry-v4');
|
|
6
|
+
var utils = require('./utils');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
const mint = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
11
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
12
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
13
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
14
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
15
|
+
const { beneficiaryAddress, holderAddress, tokenId, remarks } = params;
|
|
16
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
17
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
18
|
+
if (titleEscrowVersion === void 0) {
|
|
19
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
20
|
+
core.checkSupportsInterface(
|
|
21
|
+
tokenRegistryAddress,
|
|
22
|
+
tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenMintable,
|
|
23
|
+
signer.provider
|
|
24
|
+
),
|
|
25
|
+
core.checkSupportsInterface(
|
|
26
|
+
tokenRegistryAddress,
|
|
27
|
+
tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenMintable,
|
|
28
|
+
signer.provider
|
|
29
|
+
)
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
if (!isV4TT && !isV5TT) {
|
|
33
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
34
|
+
}
|
|
35
|
+
let tradeTrustTokenContract;
|
|
36
|
+
if (isV5TT) {
|
|
37
|
+
tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
|
|
38
|
+
tokenRegistryAddress,
|
|
39
|
+
signer
|
|
40
|
+
);
|
|
41
|
+
} else if (isV4TT) {
|
|
42
|
+
tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
|
|
43
|
+
tokenRegistryAddress,
|
|
44
|
+
signer
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
48
|
+
try {
|
|
49
|
+
if (isV5TT) {
|
|
50
|
+
await tradeTrustTokenContract.callStatic.mint(
|
|
51
|
+
beneficiaryAddress,
|
|
52
|
+
holderAddress,
|
|
53
|
+
tokenId,
|
|
54
|
+
encryptedRemarks
|
|
55
|
+
);
|
|
56
|
+
} else if (isV4TT) {
|
|
57
|
+
await tradeTrustTokenContract.callStatic.mint(
|
|
58
|
+
beneficiaryAddress,
|
|
59
|
+
holderAddress,
|
|
60
|
+
tokenId
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error("callStatic failed:", e);
|
|
65
|
+
throw new Error("Pre-check (callStatic) for mint failed");
|
|
66
|
+
}
|
|
67
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
68
|
+
if (isV5TT) {
|
|
69
|
+
return await tradeTrustTokenContract.mint(
|
|
70
|
+
beneficiaryAddress,
|
|
71
|
+
holderAddress,
|
|
72
|
+
tokenId,
|
|
73
|
+
encryptedRemarks,
|
|
74
|
+
txOptions
|
|
75
|
+
);
|
|
76
|
+
} else if (isV4TT) {
|
|
77
|
+
return await tradeTrustTokenContract.mint(
|
|
78
|
+
beneficiaryAddress,
|
|
79
|
+
holderAddress,
|
|
80
|
+
tokenId,
|
|
81
|
+
txOptions
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}, "mint");
|
|
85
|
+
|
|
86
|
+
exports.mint = mint;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var tokenRegistryV5 = require('../token-registry-v5');
|
|
5
|
+
var tokenRegistryV4 = require('../token-registry-v4');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
const ownerOf = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
10
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
11
|
+
const { titleEscrowVersion } = options;
|
|
12
|
+
const { tokenId } = params;
|
|
13
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
14
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
15
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
16
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
17
|
+
if (titleEscrowVersion === void 0) {
|
|
18
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
19
|
+
core.checkSupportsInterface(tokenRegistryAddress, tokenRegistryV4.v4SupportInterfaceIds.SBT, signer.provider),
|
|
20
|
+
core.checkSupportsInterface(tokenRegistryAddress, tokenRegistryV5.v5SupportInterfaceIds.SBT, signer.provider)
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
if (!isV4TT && !isV5TT) {
|
|
24
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
25
|
+
}
|
|
26
|
+
let tradeTrustTokenContract;
|
|
27
|
+
if (isV5TT) {
|
|
28
|
+
tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
|
|
29
|
+
tokenRegistryAddress,
|
|
30
|
+
signer
|
|
31
|
+
);
|
|
32
|
+
} else if (isV4TT) {
|
|
33
|
+
tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
|
|
34
|
+
tokenRegistryAddress,
|
|
35
|
+
signer
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (isV5TT) {
|
|
39
|
+
return await tradeTrustTokenContract.ownerOf(tokenId);
|
|
40
|
+
} else if (isV4TT) {
|
|
41
|
+
return await tradeTrustTokenContract.ownerOf(tokenId);
|
|
42
|
+
}
|
|
43
|
+
}, "ownerOf");
|
|
44
|
+
|
|
45
|
+
exports.ownerOf = ownerOf;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var tokenRegistryV5 = require('../token-registry-v5');
|
|
5
|
+
var utils = require('./utils');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
const rejectTransferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
10
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
11
|
+
let { titleEscrowAddress } = contractOptions;
|
|
12
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
13
|
+
if (!titleEscrowAddress) {
|
|
14
|
+
titleEscrowAddress = await core.getTitleEscrowAddress(
|
|
15
|
+
tokenRegistryAddress,
|
|
16
|
+
tokenId,
|
|
17
|
+
signer.provider,
|
|
18
|
+
{}
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
22
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
23
|
+
const { remarks } = params;
|
|
24
|
+
const titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
25
|
+
const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
26
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
27
|
+
if (titleEscrowVersion === void 0) {
|
|
28
|
+
isV5TT = await core.isTitleEscrowVersion({
|
|
29
|
+
titleEscrowAddress,
|
|
30
|
+
versionInterface: core.TitleEscrowInterface.V5,
|
|
31
|
+
provider: signer.provider
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (!isV5TT) {
|
|
35
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
await titleEscrowContract.callStatic.rejectTransferHolder(encryptedRemarks);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error("callStatic failed:", e);
|
|
41
|
+
throw new Error("Pre-check (callStatic) for rejectTransferHolder failed");
|
|
42
|
+
}
|
|
43
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
44
|
+
return await titleEscrowContract.rejectTransferHolder(encryptedRemarks, txOptions);
|
|
45
|
+
}, "rejectTransferHolder");
|
|
46
|
+
const rejectTransferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
47
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
48
|
+
let { titleEscrowAddress } = contractOptions;
|
|
49
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
50
|
+
if (!titleEscrowAddress) {
|
|
51
|
+
titleEscrowAddress = await core.getTitleEscrowAddress(
|
|
52
|
+
tokenRegistryAddress,
|
|
53
|
+
tokenId,
|
|
54
|
+
signer.provider,
|
|
55
|
+
{}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
59
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
60
|
+
const { remarks } = params;
|
|
61
|
+
const titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
62
|
+
const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
63
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
64
|
+
if (titleEscrowVersion === void 0) {
|
|
65
|
+
isV5TT = await core.isTitleEscrowVersion({
|
|
66
|
+
titleEscrowAddress,
|
|
67
|
+
versionInterface: core.TitleEscrowInterface.V5,
|
|
68
|
+
provider: signer.provider
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (!isV5TT) {
|
|
72
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
await titleEscrowContract.callStatic.rejectTransferBeneficiary(encryptedRemarks);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.error("callStatic failed:", e);
|
|
78
|
+
throw new Error("Pre-check (callStatic) for rejectTransferBeneficiary failed");
|
|
79
|
+
}
|
|
80
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
81
|
+
return await titleEscrowContract.rejectTransferBeneficiary(encryptedRemarks, txOptions);
|
|
82
|
+
}, "rejectTransferBeneficiary");
|
|
83
|
+
const rejectTransferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
84
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
85
|
+
let { titleEscrowAddress } = contractOptions;
|
|
86
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
87
|
+
if (!titleEscrowAddress) {
|
|
88
|
+
titleEscrowAddress = await core.getTitleEscrowAddress(
|
|
89
|
+
tokenRegistryAddress,
|
|
90
|
+
tokenId,
|
|
91
|
+
signer.provider,
|
|
92
|
+
{}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
96
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
97
|
+
const { remarks } = params;
|
|
98
|
+
const titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
99
|
+
const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
100
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
101
|
+
if (titleEscrowVersion === void 0) {
|
|
102
|
+
isV5TT = await core.isTitleEscrowVersion({
|
|
103
|
+
titleEscrowAddress,
|
|
104
|
+
versionInterface: core.TitleEscrowInterface.V5,
|
|
105
|
+
provider: signer.provider
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (!isV5TT) {
|
|
109
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
await titleEscrowContract.callStatic.rejectTransferOwners(encryptedRemarks);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.error("callStatic failed:", e);
|
|
115
|
+
throw new Error("Pre-check (callStatic) for rejectTransferOwners failed");
|
|
116
|
+
}
|
|
117
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
118
|
+
return await titleEscrowContract.rejectTransferOwners(encryptedRemarks, txOptions);
|
|
119
|
+
}, "rejectTransferOwners");
|
|
120
|
+
|
|
121
|
+
exports.rejectTransferBeneficiary = rejectTransferBeneficiary;
|
|
122
|
+
exports.rejectTransferHolder = rejectTransferHolder;
|
|
123
|
+
exports.rejectTransferOwners = rejectTransferOwners;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var tokenRegistryV5 = require('../token-registry-v5');
|
|
5
|
+
var tokenRegistryV4 = require('../token-registry-v4');
|
|
6
|
+
var utils = require('./utils');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
const returnToIssuer = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
11
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
12
|
+
let { titleEscrowAddress } = contractOptions;
|
|
13
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
14
|
+
if (!titleEscrowAddress) {
|
|
15
|
+
titleEscrowAddress = await core.getTitleEscrowAddress(
|
|
16
|
+
tokenRegistryAddress,
|
|
17
|
+
tokenId,
|
|
18
|
+
signer.provider,
|
|
19
|
+
{}
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (!titleEscrowAddress) throw new Error("Title Escrow address is required");
|
|
23
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
24
|
+
const { remarks } = params;
|
|
25
|
+
let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
26
|
+
const encryptedRemarks = remarks && options.id ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
27
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
28
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
29
|
+
if (titleEscrowVersion === void 0) {
|
|
30
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
31
|
+
await core.isTitleEscrowVersion({
|
|
32
|
+
titleEscrowAddress,
|
|
33
|
+
versionInterface: core.TitleEscrowInterface.V4,
|
|
34
|
+
provider: signer.provider
|
|
35
|
+
}),
|
|
36
|
+
await core.isTitleEscrowVersion({
|
|
37
|
+
titleEscrowAddress,
|
|
38
|
+
versionInterface: core.TitleEscrowInterface.V5,
|
|
39
|
+
provider: signer.provider
|
|
40
|
+
})
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
if (!isV5TT && !isV4TT) {
|
|
44
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
45
|
+
}
|
|
46
|
+
if (isV4TT) {
|
|
47
|
+
titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
|
|
48
|
+
titleEscrowAddress,
|
|
49
|
+
signer
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
if (isV5TT) {
|
|
54
|
+
await titleEscrowContract.callStatic.returnToIssuer(
|
|
55
|
+
encryptedRemarks
|
|
56
|
+
);
|
|
57
|
+
} else if (isV4TT) {
|
|
58
|
+
await titleEscrowContract.callStatic.surrender();
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.error("callStatic failed:", e);
|
|
62
|
+
throw new Error("Pre-check (callStatic) for returnToIssuer failed");
|
|
63
|
+
}
|
|
64
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
65
|
+
if (isV5TT) {
|
|
66
|
+
return await titleEscrowContract.returnToIssuer(
|
|
67
|
+
encryptedRemarks,
|
|
68
|
+
txOptions
|
|
69
|
+
);
|
|
70
|
+
} else if (isV4TT) {
|
|
71
|
+
return await titleEscrowContract.surrender(txOptions);
|
|
72
|
+
}
|
|
73
|
+
}, "returnToIssuer");
|
|
74
|
+
const rejectReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
75
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
76
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
77
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
78
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
79
|
+
const { tokenId, remarks } = params;
|
|
80
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
81
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
82
|
+
if (titleEscrowVersion === void 0) {
|
|
83
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
84
|
+
core.checkSupportsInterface(
|
|
85
|
+
tokenRegistryAddress,
|
|
86
|
+
tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenRestorable,
|
|
87
|
+
signer.provider
|
|
88
|
+
),
|
|
89
|
+
core.checkSupportsInterface(
|
|
90
|
+
tokenRegistryAddress,
|
|
91
|
+
tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenRestorable,
|
|
92
|
+
signer.provider
|
|
93
|
+
)
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
if (!isV4TT && !isV5TT) {
|
|
97
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
98
|
+
}
|
|
99
|
+
let tradeTrustTokenContract;
|
|
100
|
+
if (isV5TT) {
|
|
101
|
+
tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
|
|
102
|
+
tokenRegistryAddress,
|
|
103
|
+
signer
|
|
104
|
+
);
|
|
105
|
+
} else if (isV4TT) {
|
|
106
|
+
tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
|
|
107
|
+
tokenRegistryAddress,
|
|
108
|
+
signer
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
112
|
+
try {
|
|
113
|
+
if (isV5TT) {
|
|
114
|
+
await tradeTrustTokenContract.callStatic.restore(
|
|
115
|
+
tokenId,
|
|
116
|
+
encryptedRemarks
|
|
117
|
+
);
|
|
118
|
+
} else if (isV4TT) {
|
|
119
|
+
await tradeTrustTokenContract.callStatic.restore(tokenId);
|
|
120
|
+
}
|
|
121
|
+
} catch (e) {
|
|
122
|
+
console.error("callStatic failed:", e);
|
|
123
|
+
throw new Error("Pre-check (callStatic) for rejectReturned failed");
|
|
124
|
+
}
|
|
125
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
126
|
+
if (isV5TT) {
|
|
127
|
+
return await tradeTrustTokenContract.restore(
|
|
128
|
+
tokenId,
|
|
129
|
+
encryptedRemarks,
|
|
130
|
+
txOptions
|
|
131
|
+
);
|
|
132
|
+
} else if (isV4TT) {
|
|
133
|
+
return await tradeTrustTokenContract.restore(
|
|
134
|
+
tokenId,
|
|
135
|
+
txOptions
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}, "rejectReturned");
|
|
139
|
+
const acceptReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
140
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
141
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
142
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
143
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
144
|
+
const { tokenId, remarks } = params;
|
|
145
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
146
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
147
|
+
if (titleEscrowVersion === void 0) {
|
|
148
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
149
|
+
core.checkSupportsInterface(
|
|
150
|
+
tokenRegistryAddress,
|
|
151
|
+
tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenBurnable,
|
|
152
|
+
signer.provider
|
|
153
|
+
),
|
|
154
|
+
core.checkSupportsInterface(
|
|
155
|
+
tokenRegistryAddress,
|
|
156
|
+
tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenBurnable,
|
|
157
|
+
signer.provider
|
|
158
|
+
)
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
if (!isV4TT && !isV5TT) {
|
|
162
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
163
|
+
}
|
|
164
|
+
let tradeTrustTokenContract;
|
|
165
|
+
if (isV5TT) {
|
|
166
|
+
tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
|
|
167
|
+
tokenRegistryAddress,
|
|
168
|
+
signer
|
|
169
|
+
);
|
|
170
|
+
} else if (isV4TT) {
|
|
171
|
+
tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
|
|
172
|
+
tokenRegistryAddress,
|
|
173
|
+
signer
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
177
|
+
try {
|
|
178
|
+
if (isV5TT) {
|
|
179
|
+
await tradeTrustTokenContract.callStatic.burn(
|
|
180
|
+
tokenId,
|
|
181
|
+
encryptedRemarks
|
|
182
|
+
);
|
|
183
|
+
} else if (isV4TT) {
|
|
184
|
+
await tradeTrustTokenContract.callStatic.burn(tokenId);
|
|
185
|
+
}
|
|
186
|
+
} catch (e) {
|
|
187
|
+
console.error("callStatic failed:", e);
|
|
188
|
+
throw new Error("Pre-check (callStatic) for acceptReturned failed");
|
|
189
|
+
}
|
|
190
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
191
|
+
if (isV5TT) {
|
|
192
|
+
return await tradeTrustTokenContract.burn(
|
|
193
|
+
tokenId,
|
|
194
|
+
encryptedRemarks,
|
|
195
|
+
txOptions
|
|
196
|
+
);
|
|
197
|
+
} else if (isV4TT) {
|
|
198
|
+
return await tradeTrustTokenContract.burn(tokenId, txOptions);
|
|
199
|
+
}
|
|
200
|
+
}, "acceptReturned");
|
|
201
|
+
|
|
202
|
+
exports.acceptReturned = acceptReturned;
|
|
203
|
+
exports.rejectReturned = rejectReturned;
|
|
204
|
+
exports.returnToIssuer = returnToIssuer;
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var ethers = require('src/utils/ethers');
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var tokenRegistryV4 = require('../token-registry-v4');
|
|
5
|
+
var tokenRegistryV5 = require('../token-registry-v5');
|
|
6
|
+
var utils = require('./utils');
|
|
8
7
|
|
|
9
8
|
var __defProp = Object.defineProperty;
|
|
10
9
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
-
const getChainIdSafe = /* @__PURE__ */ __name(async (signer) => {
|
|
12
|
-
if (ethers.isV6EthersProvider(signer.provider)) {
|
|
13
|
-
const network = await signer.provider?.getNetwork();
|
|
14
|
-
if (!network?.chainId) throw new Error("Cannot determine chainId: provider is missing");
|
|
15
|
-
return network.chainId;
|
|
16
|
-
}
|
|
17
|
-
return await signer.getChainId();
|
|
18
|
-
}, "getChainIdSafe");
|
|
19
10
|
const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
20
11
|
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
21
12
|
const { titleEscrowVersion } = options;
|
|
22
13
|
let { titleEscrowAddress } = contractOptions;
|
|
23
|
-
|
|
14
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
24
15
|
let isV5TT = titleEscrowVersion === "v5";
|
|
25
16
|
let isV4TT = titleEscrowVersion === "v4";
|
|
26
17
|
if (!titleEscrowAddress) {
|
|
@@ -74,16 +65,7 @@ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, pa
|
|
|
74
65
|
console.error("callStatic failed:", e);
|
|
75
66
|
throw new Error("Pre-check (callStatic) for transferHolder failed");
|
|
76
67
|
}
|
|
77
|
-
|
|
78
|
-
chainId = chainId ?? await getChainIdSafe(signer);
|
|
79
|
-
const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
80
|
-
if (gasStation) {
|
|
81
|
-
const gasFees = await gasStation();
|
|
82
|
-
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
83
|
-
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
68
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
87
69
|
if (isV5TT) {
|
|
88
70
|
return await titleEscrowContract.transferHolder(
|
|
89
71
|
holderAddress,
|
|
@@ -91,14 +73,17 @@ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, pa
|
|
|
91
73
|
txOptions
|
|
92
74
|
);
|
|
93
75
|
} else if (isV4TT) {
|
|
94
|
-
return await titleEscrowContract.transferHolder(
|
|
76
|
+
return await titleEscrowContract.transferHolder(
|
|
77
|
+
holderAddress,
|
|
78
|
+
txOptions
|
|
79
|
+
);
|
|
95
80
|
}
|
|
96
81
|
}, "transferHolder");
|
|
97
82
|
const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
98
83
|
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
99
84
|
const { titleEscrowVersion } = options;
|
|
100
85
|
let { titleEscrowAddress } = contractOptions;
|
|
101
|
-
|
|
86
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
102
87
|
let isV5TT = titleEscrowVersion === "v5";
|
|
103
88
|
let isV4TT = titleEscrowVersion === "v4";
|
|
104
89
|
if (!titleEscrowAddress) {
|
|
@@ -152,16 +137,7 @@ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signe
|
|
|
152
137
|
console.error("callStatic failed:", e);
|
|
153
138
|
throw new Error("Pre-check (callStatic) for transferBeneficiary failed");
|
|
154
139
|
}
|
|
155
|
-
|
|
156
|
-
chainId = chainId ?? await getChainIdSafe(signer);
|
|
157
|
-
const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
158
|
-
if (gasStation) {
|
|
159
|
-
const gasFees = await gasStation();
|
|
160
|
-
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
161
|
-
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
140
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
165
141
|
if (isV5TT) {
|
|
166
142
|
const tx = await titleEscrowContract.transferBeneficiary(
|
|
167
143
|
newBeneficiaryAddress,
|
|
@@ -181,7 +157,7 @@ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, pa
|
|
|
181
157
|
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
182
158
|
const { titleEscrowVersion } = options;
|
|
183
159
|
let { titleEscrowAddress } = contractOptions;
|
|
184
|
-
|
|
160
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
185
161
|
let isV5TT = titleEscrowVersion === "v5";
|
|
186
162
|
let isV4TT = titleEscrowVersion === "v4";
|
|
187
163
|
if (!titleEscrowAddress) {
|
|
@@ -237,16 +213,7 @@ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, pa
|
|
|
237
213
|
console.error("callStatic failed:", e);
|
|
238
214
|
throw new Error("Pre-check (callStatic) for transferOwners failed");
|
|
239
215
|
}
|
|
240
|
-
|
|
241
|
-
chainId = chainId ?? await getChainIdSafe(signer);
|
|
242
|
-
const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
243
|
-
if (gasStation) {
|
|
244
|
-
const gasFees = await gasStation();
|
|
245
|
-
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
246
|
-
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
216
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
250
217
|
if (isV5TT) {
|
|
251
218
|
return await titleEscrowContract.transferOwners(
|
|
252
219
|
newBeneficiaryAddress,
|
|
@@ -266,7 +233,7 @@ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params,
|
|
|
266
233
|
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
267
234
|
const { titleEscrowVersion } = options;
|
|
268
235
|
let { titleEscrowAddress } = contractOptions;
|
|
269
|
-
|
|
236
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
270
237
|
let isV5TT = titleEscrowVersion === "v5";
|
|
271
238
|
let isV4TT = titleEscrowVersion === "v4";
|
|
272
239
|
if (!titleEscrowAddress) {
|
|
@@ -317,16 +284,7 @@ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params,
|
|
|
317
284
|
console.error("callStatic failed:", e);
|
|
318
285
|
throw new Error("Pre-check (callStatic) for nominate failed");
|
|
319
286
|
}
|
|
320
|
-
|
|
321
|
-
chainId = chainId ?? await getChainIdSafe(signer);
|
|
322
|
-
const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
323
|
-
if (gasStation) {
|
|
324
|
-
const gasFees = await gasStation();
|
|
325
|
-
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
326
|
-
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
287
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
330
288
|
if (isV5TT) {
|
|
331
289
|
return await titleEscrowContract.nominate(
|
|
332
290
|
newBeneficiaryAddress,
|