opensea-js 4.0.21 → 4.0.22
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/lib/abi/CanonicalWETH.d.ts +2 -0
- package/lib/abi/CanonicalWETH.js +157 -0
- package/lib/abi/CanonicalWETH.js.map +1 -0
- package/lib/abi/ERC1155.d.ts +2 -0
- package/lib/abi/ERC1155.js +9 -0
- package/lib/abi/ERC1155.js.map +1 -0
- package/lib/abi/ERC1155Abi.json +2346 -0
- package/lib/abi/ERC20.d.ts +2 -0
- package/lib/abi/ERC20.js +141 -0
- package/lib/abi/ERC20.js.map +1 -0
- package/lib/abi/ERC721v3.d.ts +2 -0
- package/lib/abi/ERC721v3.js +9 -0
- package/lib/abi/ERC721v3.js.map +1 -0
- package/lib/abi/ERC721v3Abi.json +470 -0
- package/lib/abi/Proxy.d.ts +27 -0
- package/lib/abi/Proxy.js +30 -0
- package/lib/abi/Proxy.js.map +1 -0
- package/lib/abi/UniswapExchange.d.ts +2 -0
- package/lib/abi/UniswapExchange.js +9 -0
- package/lib/abi/UniswapExchange.js.map +1 -0
- package/lib/abi/UniswapExchangeAbi.json +451 -0
- package/lib/abi/UniswapFactory.d.ts +2 -0
- package/lib/abi/UniswapFactory.js +9 -0
- package/lib/abi/UniswapFactory.js.map +1 -0
- package/lib/abi/UniswapFactoryAbi.json +67 -0
- package/lib/abi/WrappedNFT.d.ts +2 -0
- package/lib/abi/WrappedNFT.js +9 -0
- package/lib/abi/WrappedNFT.js.map +1 -0
- package/lib/abi/WrappedNFTAbi.json +331 -0
- package/lib/abi/WrappedNFTFactory.d.ts +2 -0
- package/lib/abi/WrappedNFTFactory.js +9 -0
- package/lib/abi/WrappedNFTFactory.js.map +1 -0
- package/lib/abi/WrappedNFTFactoryAbi.json +250 -0
- package/lib/abi/WrappedNFTLiquidationProxy.d.ts +2 -0
- package/lib/abi/WrappedNFTLiquidationProxy.js +139 -0
- package/lib/abi/WrappedNFTLiquidationProxy.js.map +1 -0
- package/lib/api.d.ts +134 -0
- package/lib/api.js +509 -0
- package/lib/api.js.map +1 -0
- package/lib/constants.d.ts +56 -0
- package/lib/constants.js +89 -0
- package/lib/constants.js.map +1 -0
- package/lib/contracts.d.ts +12 -0
- package/lib/contracts.js +32 -0
- package/lib/contracts.js.map +1 -0
- package/lib/debugging.d.ts +22 -0
- package/lib/debugging.js +194 -0
- package/lib/debugging.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +25 -0
- package/lib/index.js.map +1 -0
- package/lib/orders/privateListings.d.ts +4 -0
- package/lib/orders/privateListings.js +129 -0
- package/lib/orders/privateListings.js.map +1 -0
- package/lib/orders/schemas.d.ts +3 -0
- package/lib/orders/schemas.js +78 -0
- package/lib/orders/schemas.js.map +1 -0
- package/lib/orders/types.d.ts +99 -0
- package/lib/orders/types.js +3 -0
- package/lib/orders/types.js.map +1 -0
- package/lib/orders/utils.d.ts +23 -0
- package/lib/orders/utils.js +76 -0
- package/lib/orders/utils.js.map +1 -0
- package/lib/package.json +2 -1
- package/lib/schemas.d.ts +9 -0
- package/lib/schemas.js +50 -0
- package/lib/schemas.js.map +1 -0
- package/lib/sdk.d.ts +704 -0
- package/lib/sdk.js +3336 -0
- package/lib/sdk.js.map +1 -0
- package/lib/src/__integration_tests__/postOrder.d.ts +1 -0
- package/lib/src/__integration_tests__/postOrder.js +78 -0
- package/lib/src/__integration_tests__/postOrder.js.map +1 -0
- package/lib/src/__tests__/constants.d.ts +12 -0
- package/lib/src/__tests__/constants.js +22 -0
- package/lib/src/__tests__/constants.js.map +1 -0
- package/lib/src/api.d.ts +14 -2
- package/lib/src/api.js +74 -8
- package/lib/src/api.js.map +1 -1
- package/lib/src/constants.d.ts +1 -1
- package/lib/src/constants.js +1 -1
- package/lib/src/orders/types.d.ts +29 -1
- package/lib/src/orders/utils.d.ts +21 -1
- package/lib/src/orders/utils.js +34 -1
- package/lib/src/orders/utils.js.map +1 -1
- package/lib/src/sdk.d.ts +17 -3
- package/lib/src/sdk.js +86 -16
- package/lib/src/sdk.js.map +1 -1
- package/lib/src/types.d.ts +1 -1
- package/lib/typechain/contracts/ERC1155Abi.d.ts +436 -0
- package/lib/typechain/contracts/ERC1155Abi.js +6 -0
- package/lib/typechain/contracts/ERC1155Abi.js.map +1 -0
- package/lib/typechain/contracts/ERC721v3Abi.d.ts +76 -0
- package/lib/typechain/contracts/ERC721v3Abi.js +6 -0
- package/lib/typechain/contracts/ERC721v3Abi.js.map +1 -0
- package/lib/typechain/contracts/UniswapExchangeAbi.d.ts +132 -0
- package/lib/typechain/contracts/UniswapExchangeAbi.js +6 -0
- package/lib/typechain/contracts/UniswapExchangeAbi.js.map +1 -0
- package/lib/typechain/contracts/UniswapFactoryAbi.d.ts +37 -0
- package/lib/typechain/contracts/UniswapFactoryAbi.js +6 -0
- package/lib/typechain/contracts/UniswapFactoryAbi.js.map +1 -0
- package/lib/typechain/contracts/WrappedNFTAbi.d.ts +80 -0
- package/lib/typechain/contracts/WrappedNFTAbi.js +6 -0
- package/lib/typechain/contracts/WrappedNFTAbi.js.map +1 -0
- package/lib/typechain/contracts/WrappedNFTFactoryAbi.d.ts +57 -0
- package/lib/typechain/contracts/WrappedNFTFactoryAbi.js +6 -0
- package/lib/typechain/contracts/WrappedNFTFactoryAbi.js.map +1 -0
- package/lib/typechain/contracts/types.d.ts +54 -0
- package/lib/typechain/contracts/types.js +3 -0
- package/lib/typechain/contracts/types.js.map +1 -0
- package/lib/types.d.ts +516 -0
- package/lib/types.js +151 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +15 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/schema.d.ts +49 -0
- package/lib/utils/schema.js +238 -0
- package/lib/utils/schema.js.map +1 -0
- package/lib/utils/utils.d.ts +203 -0
- package/lib/utils/utils.js +1113 -0
- package/lib/utils/utils.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,1113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (_) try {
|
|
48
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
69
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
70
|
+
};
|
|
71
|
+
var _a;
|
|
72
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
73
|
+
exports.feesToBasisPoints = exports.getAddressAfterRemappingSharedStorefrontAddressToLazyMintAdapterAddress = exports.getAssetItemType = exports.hasErrorCode = exports.getMaxOrderExpirationTimestamp = exports.merkleValidatorByNetwork = exports.getNonCompliantApprovalAddress = exports.onDeprecated = exports.validateAndFormatWalletAddress = exports.delay = exports.assignOrdersToSides = exports.getOrderHash = exports.getWyvernBundle = exports.getWyvernAsset = exports.estimateCurrentPrice = exports.getTransferFeeSettings = exports.getCurrentGasPrice = exports.estimateGas = exports.rawCall = exports.sendRawTransaction = exports.makeBigNumber = exports.isContractAddress = exports.signTypedDataAsync = exports.personalSignAsync = exports.orderToJSON = exports.orderFromJSON = exports.tokenFromJSON = exports.collectionFromJSON = exports.assetContractFromJSON = exports.assetBundleFromJSON = exports.userFromJSON = exports.accountFromJSON = exports.transactionFromJSON = exports.assetEventFromJSON = exports.assetFromJSON = exports.confirmTransaction = exports.promisifyCall = exports.annotateERC20TransferABI = exports.annotateERC721TransferABI = exports.WyvernProtocol = void 0;
|
|
74
|
+
var constants_1 = require("@opensea/seaport-js/lib/constants");
|
|
75
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
76
|
+
var ethereum_types_1 = require("ethereum-types");
|
|
77
|
+
var ethUtil = __importStar(require("ethereumjs-util"));
|
|
78
|
+
var _ = __importStar(require("lodash"));
|
|
79
|
+
var wyvern_js_1 = require("wyvern-js");
|
|
80
|
+
Object.defineProperty(exports, "WyvernProtocol", { enumerable: true, get: function () { return wyvern_js_1.WyvernProtocol; } });
|
|
81
|
+
var types_1 = require("wyvern-schemas/dist/types");
|
|
82
|
+
var constants_2 = require("../constants");
|
|
83
|
+
var contracts_1 = require("../contracts");
|
|
84
|
+
var types_2 = require("../types");
|
|
85
|
+
var annotateERC721TransferABI = function (asset) { return ({
|
|
86
|
+
constant: false,
|
|
87
|
+
inputs: [
|
|
88
|
+
{
|
|
89
|
+
name: "_to",
|
|
90
|
+
type: "address",
|
|
91
|
+
kind: types_1.FunctionInputKind.Replaceable,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "_tokenId",
|
|
95
|
+
type: "uint256",
|
|
96
|
+
kind: types_1.FunctionInputKind.Asset,
|
|
97
|
+
value: asset.id,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
target: asset.address,
|
|
101
|
+
name: "transfer",
|
|
102
|
+
outputs: [],
|
|
103
|
+
payable: false,
|
|
104
|
+
stateMutability: types_1.StateMutability.Nonpayable,
|
|
105
|
+
type: ethereum_types_1.AbiType.Function,
|
|
106
|
+
}); };
|
|
107
|
+
exports.annotateERC721TransferABI = annotateERC721TransferABI;
|
|
108
|
+
var annotateERC20TransferABI = function (asset) { return ({
|
|
109
|
+
constant: false,
|
|
110
|
+
inputs: [
|
|
111
|
+
{
|
|
112
|
+
name: "_to",
|
|
113
|
+
type: "address",
|
|
114
|
+
kind: types_1.FunctionInputKind.Replaceable,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "_amount",
|
|
118
|
+
type: "uint256",
|
|
119
|
+
kind: types_1.FunctionInputKind.Count,
|
|
120
|
+
value: asset.quantity,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
target: asset.address,
|
|
124
|
+
name: "transfer",
|
|
125
|
+
outputs: [
|
|
126
|
+
{
|
|
127
|
+
name: "success",
|
|
128
|
+
type: "bool",
|
|
129
|
+
kind: types_1.FunctionOutputKind.Other,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
payable: false,
|
|
133
|
+
stateMutability: types_1.StateMutability.Nonpayable,
|
|
134
|
+
type: ethereum_types_1.AbiType.Function,
|
|
135
|
+
}); };
|
|
136
|
+
exports.annotateERC20TransferABI = annotateERC20TransferABI;
|
|
137
|
+
// OTHER
|
|
138
|
+
var txCallbacks = {};
|
|
139
|
+
/**
|
|
140
|
+
* Promisify a callback-syntax web3 function
|
|
141
|
+
* @param inner callback function that accepts a Web3 callback function and passes
|
|
142
|
+
* it to the Web3 function
|
|
143
|
+
*/
|
|
144
|
+
function promisify(inner) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
148
|
+
return inner(function (err, res) {
|
|
149
|
+
if (err) {
|
|
150
|
+
reject(err);
|
|
151
|
+
}
|
|
152
|
+
resolve(res);
|
|
153
|
+
});
|
|
154
|
+
})];
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Promisify a call a method on a contract,
|
|
160
|
+
* handling Parity errors. Returns '0x' if error.
|
|
161
|
+
* Note that if T is not "string", this may return a falsey
|
|
162
|
+
* value when the contract doesn't support the method (e.g. `isApprovedForAll`).
|
|
163
|
+
* @param callback An anonymous function that takes a web3 callback
|
|
164
|
+
* and returns a Web3 Contract's call result, e.g. `c => erc721.ownerOf(3, c)`
|
|
165
|
+
* @param onError callback when user denies transaction
|
|
166
|
+
*/
|
|
167
|
+
function promisifyCall(callback, onError) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
var result, error_1;
|
|
170
|
+
return __generator(this, function (_a) {
|
|
171
|
+
switch (_a.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
_a.trys.push([0, 2, , 3]);
|
|
174
|
+
return [4 /*yield*/, promisify(callback)];
|
|
175
|
+
case 1:
|
|
176
|
+
result = _a.sent();
|
|
177
|
+
if (typeof result === "string" && result == "0x") {
|
|
178
|
+
// Geth compatibility
|
|
179
|
+
return [2 /*return*/, undefined];
|
|
180
|
+
}
|
|
181
|
+
return [2 /*return*/, result];
|
|
182
|
+
case 2:
|
|
183
|
+
error_1 = _a.sent();
|
|
184
|
+
// Probably method not found, and web3 is a Parity node
|
|
185
|
+
if (onError) {
|
|
186
|
+
onError(error_1);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.error(error_1);
|
|
190
|
+
}
|
|
191
|
+
return [2 /*return*/, undefined];
|
|
192
|
+
case 3: return [2 /*return*/];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
exports.promisifyCall = promisifyCall;
|
|
198
|
+
var track = function (web3, txHash, onFinalized) {
|
|
199
|
+
if (txCallbacks[txHash]) {
|
|
200
|
+
txCallbacks[txHash].push(onFinalized);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
txCallbacks[txHash] = [onFinalized];
|
|
204
|
+
var poll_1 = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
205
|
+
var tx, receipt, status_1;
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0: return [4 /*yield*/, web3.eth.getTransaction(txHash)];
|
|
209
|
+
case 1:
|
|
210
|
+
tx = _a.sent();
|
|
211
|
+
if (!(tx && tx.blockHash && tx.blockHash !== constants_2.NULL_BLOCK_HASH)) return [3 /*break*/, 3];
|
|
212
|
+
return [4 /*yield*/, web3.eth.getTransactionReceipt(txHash)];
|
|
213
|
+
case 2:
|
|
214
|
+
receipt = _a.sent();
|
|
215
|
+
if (!receipt) {
|
|
216
|
+
// Hack: assume success if no receipt
|
|
217
|
+
console.warn("No receipt found for ", txHash);
|
|
218
|
+
}
|
|
219
|
+
status_1 = receipt.status;
|
|
220
|
+
txCallbacks[txHash].map(function (f) { return f(status_1); });
|
|
221
|
+
delete txCallbacks[txHash];
|
|
222
|
+
return [3 /*break*/, 4];
|
|
223
|
+
case 3:
|
|
224
|
+
setTimeout(poll_1, 1000);
|
|
225
|
+
_a.label = 4;
|
|
226
|
+
case 4: return [2 /*return*/];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}); };
|
|
230
|
+
poll_1().catch();
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var confirmTransaction = function (web3, txHash) { return __awaiter(void 0, void 0, void 0, function () {
|
|
234
|
+
return __generator(this, function (_a) {
|
|
235
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
236
|
+
track(web3, txHash, function (didSucceed) {
|
|
237
|
+
if (didSucceed) {
|
|
238
|
+
resolve("Transaction complete!");
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
reject(new Error("Transaction failed :( You might have already completed this action. See more on the mainnet at etherscan.io/tx/".concat(txHash)));
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
})];
|
|
245
|
+
});
|
|
246
|
+
}); };
|
|
247
|
+
exports.confirmTransaction = confirmTransaction;
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
|
+
var assetFromJSON = function (asset) {
|
|
250
|
+
var isAnimated = asset.image_url && asset.image_url.endsWith(".gif");
|
|
251
|
+
var isSvg = asset.image_url && asset.image_url.endsWith(".svg");
|
|
252
|
+
var fromJSON = {
|
|
253
|
+
tokenId: asset.token_id.toString(),
|
|
254
|
+
tokenAddress: asset.asset_contract.address,
|
|
255
|
+
name: asset.name,
|
|
256
|
+
description: asset.description,
|
|
257
|
+
owner: asset.owner,
|
|
258
|
+
assetContract: (0, exports.assetContractFromJSON)(asset.asset_contract),
|
|
259
|
+
collection: (0, exports.collectionFromJSON)(asset.collection),
|
|
260
|
+
orders: asset.orders ? asset.orders.map(exports.orderFromJSON) : null,
|
|
261
|
+
sellOrders: asset.sell_orders ? asset.sell_orders.map(exports.orderFromJSON) : null,
|
|
262
|
+
buyOrders: asset.buy_orders ? asset.buy_orders.map(exports.orderFromJSON) : null,
|
|
263
|
+
isPresale: asset.is_presale,
|
|
264
|
+
// Don't use previews if it's a special image
|
|
265
|
+
imageUrl: isAnimated || isSvg
|
|
266
|
+
? asset.image_url
|
|
267
|
+
: asset.image_preview_url || asset.image_url,
|
|
268
|
+
imagePreviewUrl: asset.image_preview_url,
|
|
269
|
+
imageUrlOriginal: asset.image_original_url,
|
|
270
|
+
imageUrlThumbnail: asset.image_thumbnail_url,
|
|
271
|
+
externalLink: asset.external_link,
|
|
272
|
+
openseaLink: asset.permalink,
|
|
273
|
+
traits: asset.traits,
|
|
274
|
+
numSales: asset.num_sales,
|
|
275
|
+
lastSale: asset.last_sale ? (0, exports.assetEventFromJSON)(asset.last_sale) : null,
|
|
276
|
+
backgroundColor: asset.background_color
|
|
277
|
+
? "#".concat(asset.background_color)
|
|
278
|
+
: null,
|
|
279
|
+
};
|
|
280
|
+
// If orders were included, put them in sell/buy order groups
|
|
281
|
+
if (fromJSON.orders && !fromJSON.sellOrders) {
|
|
282
|
+
fromJSON.sellOrders = fromJSON.orders.filter(function (o) { return o.side == types_2.OrderSide.Sell; });
|
|
283
|
+
}
|
|
284
|
+
if (fromJSON.orders && !fromJSON.buyOrders) {
|
|
285
|
+
fromJSON.buyOrders = fromJSON.orders.filter(function (o) { return o.side == types_2.OrderSide.Buy; });
|
|
286
|
+
}
|
|
287
|
+
return fromJSON;
|
|
288
|
+
};
|
|
289
|
+
exports.assetFromJSON = assetFromJSON;
|
|
290
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
291
|
+
var assetEventFromJSON = function (assetEvent) {
|
|
292
|
+
return {
|
|
293
|
+
eventType: assetEvent.event_type,
|
|
294
|
+
eventTimestamp: assetEvent.event_timestamp,
|
|
295
|
+
auctionType: assetEvent.auction_type,
|
|
296
|
+
totalPrice: assetEvent.total_price,
|
|
297
|
+
transaction: assetEvent.transaction
|
|
298
|
+
? (0, exports.transactionFromJSON)(assetEvent.transaction)
|
|
299
|
+
: null,
|
|
300
|
+
paymentToken: assetEvent.payment_token
|
|
301
|
+
? (0, exports.tokenFromJSON)(assetEvent.payment_token)
|
|
302
|
+
: null,
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
exports.assetEventFromJSON = assetEventFromJSON;
|
|
306
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
307
|
+
var transactionFromJSON = function (transaction) {
|
|
308
|
+
return {
|
|
309
|
+
fromAccount: (0, exports.accountFromJSON)(transaction.from_account),
|
|
310
|
+
toAccount: (0, exports.accountFromJSON)(transaction.to_account),
|
|
311
|
+
createdDate: new Date("".concat(transaction.created_date, "Z")),
|
|
312
|
+
modifiedDate: new Date("".concat(transaction.modified_date, "Z")),
|
|
313
|
+
transactionHash: transaction.transaction_hash,
|
|
314
|
+
transactionIndex: transaction.transaction_index,
|
|
315
|
+
blockNumber: transaction.block_number,
|
|
316
|
+
blockHash: transaction.block_hash,
|
|
317
|
+
timestamp: new Date("".concat(transaction.timestamp, "Z")),
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
exports.transactionFromJSON = transactionFromJSON;
|
|
321
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
322
|
+
var accountFromJSON = function (account) {
|
|
323
|
+
return {
|
|
324
|
+
address: account.address,
|
|
325
|
+
config: account.config,
|
|
326
|
+
profileImgUrl: account.profile_img_url,
|
|
327
|
+
user: account.user ? (0, exports.userFromJSON)(account.user) : null,
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
exports.accountFromJSON = accountFromJSON;
|
|
331
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
332
|
+
var userFromJSON = function (user) {
|
|
333
|
+
return {
|
|
334
|
+
username: user.username,
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
exports.userFromJSON = userFromJSON;
|
|
338
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
339
|
+
var assetBundleFromJSON = function (asset_bundle) {
|
|
340
|
+
var fromJSON = {
|
|
341
|
+
maker: asset_bundle.maker,
|
|
342
|
+
assets: asset_bundle.assets ? asset_bundle.assets.map(exports.assetFromJSON) : [],
|
|
343
|
+
assetContract: asset_bundle.asset_contract
|
|
344
|
+
? (0, exports.assetContractFromJSON)(asset_bundle.asset_contract)
|
|
345
|
+
: undefined,
|
|
346
|
+
name: asset_bundle.name,
|
|
347
|
+
slug: asset_bundle.slug,
|
|
348
|
+
description: asset_bundle.description,
|
|
349
|
+
externalLink: asset_bundle.external_link,
|
|
350
|
+
permalink: asset_bundle.permalink,
|
|
351
|
+
sellOrders: asset_bundle.sell_orders
|
|
352
|
+
? asset_bundle.sell_orders.map(exports.orderFromJSON)
|
|
353
|
+
: null,
|
|
354
|
+
};
|
|
355
|
+
return fromJSON;
|
|
356
|
+
};
|
|
357
|
+
exports.assetBundleFromJSON = assetBundleFromJSON;
|
|
358
|
+
var assetContractFromJSON = function (
|
|
359
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
360
|
+
asset_contract) {
|
|
361
|
+
return {
|
|
362
|
+
name: asset_contract.name,
|
|
363
|
+
description: asset_contract.description,
|
|
364
|
+
type: asset_contract.asset_contract_type,
|
|
365
|
+
schemaName: asset_contract.schema_name,
|
|
366
|
+
address: asset_contract.address,
|
|
367
|
+
tokenSymbol: asset_contract.symbol,
|
|
368
|
+
buyerFeeBasisPoints: +asset_contract.buyer_fee_basis_points,
|
|
369
|
+
sellerFeeBasisPoints: +asset_contract.seller_fee_basis_points,
|
|
370
|
+
openseaBuyerFeeBasisPoints: +asset_contract.opensea_buyer_fee_basis_points,
|
|
371
|
+
openseaSellerFeeBasisPoints: +asset_contract.opensea_seller_fee_basis_points,
|
|
372
|
+
devBuyerFeeBasisPoints: +asset_contract.dev_buyer_fee_basis_points,
|
|
373
|
+
devSellerFeeBasisPoints: +asset_contract.dev_seller_fee_basis_points,
|
|
374
|
+
imageUrl: asset_contract.image_url,
|
|
375
|
+
externalLink: asset_contract.external_link,
|
|
376
|
+
wikiLink: asset_contract.wiki_link,
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
exports.assetContractFromJSON = assetContractFromJSON;
|
|
380
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
381
|
+
var collectionFromJSON = function (collection) {
|
|
382
|
+
var createdDate = new Date("".concat(collection.created_date, "Z"));
|
|
383
|
+
return {
|
|
384
|
+
createdDate: createdDate,
|
|
385
|
+
name: collection.name,
|
|
386
|
+
description: collection.description,
|
|
387
|
+
slug: collection.slug,
|
|
388
|
+
editors: collection.editors,
|
|
389
|
+
hidden: collection.hidden,
|
|
390
|
+
featured: collection.featured,
|
|
391
|
+
featuredImageUrl: collection.featured_image_url,
|
|
392
|
+
displayData: collection.display_data,
|
|
393
|
+
paymentTokens: (collection.payment_tokens || []).map(exports.tokenFromJSON),
|
|
394
|
+
openseaBuyerFeeBasisPoints: +collection.opensea_buyer_fee_basis_points,
|
|
395
|
+
openseaSellerFeeBasisPoints: +collection.opensea_seller_fee_basis_points,
|
|
396
|
+
devBuyerFeeBasisPoints: +collection.dev_buyer_fee_basis_points,
|
|
397
|
+
devSellerFeeBasisPoints: +collection.dev_seller_fee_basis_points,
|
|
398
|
+
payoutAddress: collection.payout_address,
|
|
399
|
+
imageUrl: collection.image_url,
|
|
400
|
+
largeImageUrl: collection.large_image_url,
|
|
401
|
+
stats: collection.stats,
|
|
402
|
+
traitStats: collection.traits,
|
|
403
|
+
externalLink: collection.external_url,
|
|
404
|
+
wikiLink: collection.wiki_url,
|
|
405
|
+
fees: {
|
|
406
|
+
openseaFees: new Map(Object.entries(collection.fees.opensea_fees || {})),
|
|
407
|
+
sellerFees: new Map(Object.entries(collection.fees.seller_fees || {})),
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
exports.collectionFromJSON = collectionFromJSON;
|
|
412
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
413
|
+
var tokenFromJSON = function (token) {
|
|
414
|
+
var fromJSON = {
|
|
415
|
+
name: token.name,
|
|
416
|
+
symbol: token.symbol,
|
|
417
|
+
decimals: token.decimals,
|
|
418
|
+
address: token.address,
|
|
419
|
+
imageUrl: token.image_url,
|
|
420
|
+
ethPrice: token.eth_price,
|
|
421
|
+
usdPrice: token.usd_price,
|
|
422
|
+
};
|
|
423
|
+
return fromJSON;
|
|
424
|
+
};
|
|
425
|
+
exports.tokenFromJSON = tokenFromJSON;
|
|
426
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
427
|
+
var orderFromJSON = function (order) {
|
|
428
|
+
var createdDate = new Date("".concat(order.created_date, "Z"));
|
|
429
|
+
var fromJSON = {
|
|
430
|
+
hash: order.order_hash || order.hash,
|
|
431
|
+
cancelledOrFinalized: order.cancelled || order.finalized,
|
|
432
|
+
markedInvalid: order.marked_invalid,
|
|
433
|
+
metadata: order.metadata,
|
|
434
|
+
quantity: new bignumber_js_1.default(order.quantity || 1),
|
|
435
|
+
exchange: order.exchange,
|
|
436
|
+
makerAccount: order.maker,
|
|
437
|
+
takerAccount: order.taker,
|
|
438
|
+
// Use string address to conform to Wyvern Order schema
|
|
439
|
+
maker: order.maker.address,
|
|
440
|
+
taker: order.taker.address,
|
|
441
|
+
makerRelayerFee: new bignumber_js_1.default(order.maker_relayer_fee),
|
|
442
|
+
takerRelayerFee: new bignumber_js_1.default(order.taker_relayer_fee),
|
|
443
|
+
makerProtocolFee: new bignumber_js_1.default(order.maker_protocol_fee),
|
|
444
|
+
takerProtocolFee: new bignumber_js_1.default(order.taker_protocol_fee),
|
|
445
|
+
makerReferrerFee: new bignumber_js_1.default(order.maker_referrer_fee || 0),
|
|
446
|
+
waitingForBestCounterOrder: order.fee_recipient.address == constants_2.NULL_ADDRESS,
|
|
447
|
+
feeMethod: order.fee_method,
|
|
448
|
+
feeRecipientAccount: order.fee_recipient,
|
|
449
|
+
feeRecipient: order.fee_recipient.address,
|
|
450
|
+
side: order.side,
|
|
451
|
+
saleKind: order.sale_kind,
|
|
452
|
+
target: order.target,
|
|
453
|
+
howToCall: order.how_to_call,
|
|
454
|
+
calldata: order.calldata,
|
|
455
|
+
replacementPattern: order.replacement_pattern,
|
|
456
|
+
staticTarget: order.static_target,
|
|
457
|
+
staticExtradata: order.static_extradata,
|
|
458
|
+
paymentToken: order.payment_token,
|
|
459
|
+
basePrice: new bignumber_js_1.default(order.base_price),
|
|
460
|
+
extra: new bignumber_js_1.default(order.extra),
|
|
461
|
+
currentBounty: new bignumber_js_1.default(order.current_bounty || 0),
|
|
462
|
+
currentPrice: new bignumber_js_1.default(order.current_price || 0),
|
|
463
|
+
createdTime: new bignumber_js_1.default(Math.round(createdDate.getTime() / 1000)),
|
|
464
|
+
listingTime: new bignumber_js_1.default(order.listing_time),
|
|
465
|
+
expirationTime: new bignumber_js_1.default(order.expiration_time),
|
|
466
|
+
salt: new bignumber_js_1.default(order.salt),
|
|
467
|
+
v: parseInt(order.v),
|
|
468
|
+
r: order.r,
|
|
469
|
+
s: order.s,
|
|
470
|
+
paymentTokenContract: order.payment_token_contract
|
|
471
|
+
? (0, exports.tokenFromJSON)(order.payment_token_contract)
|
|
472
|
+
: undefined,
|
|
473
|
+
asset: order.asset ? (0, exports.assetFromJSON)(order.asset) : undefined,
|
|
474
|
+
assetBundle: order.asset_bundle
|
|
475
|
+
? (0, exports.assetBundleFromJSON)(order.asset_bundle)
|
|
476
|
+
: undefined,
|
|
477
|
+
};
|
|
478
|
+
// Use client-side price calc, to account for buyer fee (not added by server) and latency
|
|
479
|
+
fromJSON.currentPrice = estimateCurrentPrice(fromJSON);
|
|
480
|
+
return fromJSON;
|
|
481
|
+
};
|
|
482
|
+
exports.orderFromJSON = orderFromJSON;
|
|
483
|
+
/**
|
|
484
|
+
* Convert an order to JSON, hashing it as well if necessary
|
|
485
|
+
* @param order order (hashed or unhashed)
|
|
486
|
+
*/
|
|
487
|
+
var orderToJSON = function (order) {
|
|
488
|
+
var asJSON = {
|
|
489
|
+
exchange: order.exchange.toLowerCase(),
|
|
490
|
+
maker: order.maker.toLowerCase(),
|
|
491
|
+
taker: order.taker.toLowerCase(),
|
|
492
|
+
makerRelayerFee: order.makerRelayerFee.toString(),
|
|
493
|
+
takerRelayerFee: order.takerRelayerFee.toString(),
|
|
494
|
+
makerProtocolFee: order.makerProtocolFee.toString(),
|
|
495
|
+
takerProtocolFee: order.takerProtocolFee.toString(),
|
|
496
|
+
makerReferrerFee: order.makerReferrerFee.toString(),
|
|
497
|
+
feeMethod: order.feeMethod,
|
|
498
|
+
feeRecipient: order.feeRecipient.toLowerCase(),
|
|
499
|
+
side: order.side,
|
|
500
|
+
saleKind: order.saleKind,
|
|
501
|
+
target: order.target.toLowerCase(),
|
|
502
|
+
howToCall: order.howToCall,
|
|
503
|
+
calldata: order.calldata,
|
|
504
|
+
replacementPattern: order.replacementPattern,
|
|
505
|
+
staticTarget: order.staticTarget.toLowerCase(),
|
|
506
|
+
staticExtradata: order.staticExtradata,
|
|
507
|
+
paymentToken: order.paymentToken.toLowerCase(),
|
|
508
|
+
quantity: order.quantity.toString(),
|
|
509
|
+
basePrice: order.basePrice.toString(),
|
|
510
|
+
englishAuctionReservePrice: order.englishAuctionReservePrice
|
|
511
|
+
? order.englishAuctionReservePrice.toString()
|
|
512
|
+
: undefined,
|
|
513
|
+
extra: order.extra.toString(),
|
|
514
|
+
createdTime: order.createdTime ? order.createdTime.toString() : undefined,
|
|
515
|
+
listingTime: order.listingTime.toString(),
|
|
516
|
+
expirationTime: order.expirationTime.toString(),
|
|
517
|
+
salt: order.salt.toString(),
|
|
518
|
+
metadata: order.metadata,
|
|
519
|
+
v: order.v,
|
|
520
|
+
r: order.r,
|
|
521
|
+
s: order.s,
|
|
522
|
+
nonce: order.nonce,
|
|
523
|
+
};
|
|
524
|
+
return asJSON;
|
|
525
|
+
};
|
|
526
|
+
exports.orderToJSON = orderToJSON;
|
|
527
|
+
/**
|
|
528
|
+
* Sign messages using web3 personal signatures
|
|
529
|
+
* @param web3 Web3 instance
|
|
530
|
+
* @param message message to sign
|
|
531
|
+
* @param signerAddress web3 address signing the message
|
|
532
|
+
* @returns A signature if provider can sign, otherwise null
|
|
533
|
+
*/
|
|
534
|
+
function personalSignAsync(web3, message, signerAddress) {
|
|
535
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
536
|
+
var signature, error;
|
|
537
|
+
return __generator(this, function (_a) {
|
|
538
|
+
switch (_a.label) {
|
|
539
|
+
case 0: return [4 /*yield*/, promisify(function (c) {
|
|
540
|
+
return web3.currentProvider.sendAsync({
|
|
541
|
+
method: "personal_sign",
|
|
542
|
+
params: [message, signerAddress],
|
|
543
|
+
from: signerAddress,
|
|
544
|
+
id: new Date().getTime(),
|
|
545
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
546
|
+
}, c);
|
|
547
|
+
})];
|
|
548
|
+
case 1:
|
|
549
|
+
signature = _a.sent();
|
|
550
|
+
error = signature.error;
|
|
551
|
+
if (error) {
|
|
552
|
+
throw new Error(error);
|
|
553
|
+
}
|
|
554
|
+
return [2 /*return*/, parseSignatureHex(signature === null || signature === void 0 ? void 0 : signature.result)];
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
exports.personalSignAsync = personalSignAsync;
|
|
560
|
+
/**
|
|
561
|
+
* Sign messages using web3 signTypedData signatures
|
|
562
|
+
* @param web3 Web3 instance
|
|
563
|
+
* @param message message to sign
|
|
564
|
+
* @param signerAddress web3 address signing the message
|
|
565
|
+
* @returns A signature if provider can sign, otherwise null
|
|
566
|
+
*/
|
|
567
|
+
function signTypedDataAsync(web3, message, signerAddress) {
|
|
568
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
569
|
+
var signature, _a, error;
|
|
570
|
+
return __generator(this, function (_b) {
|
|
571
|
+
switch (_b.label) {
|
|
572
|
+
case 0:
|
|
573
|
+
_b.trys.push([0, 2, , 4]);
|
|
574
|
+
return [4 /*yield*/, promisify(function (c) {
|
|
575
|
+
return web3.currentProvider.sendAsync({
|
|
576
|
+
method: "eth_signTypedData_v4",
|
|
577
|
+
params: [signerAddress, JSON.stringify(message)],
|
|
578
|
+
from: signerAddress,
|
|
579
|
+
id: new Date().getTime(),
|
|
580
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
581
|
+
}, c);
|
|
582
|
+
})];
|
|
583
|
+
case 1:
|
|
584
|
+
// Using sign typed data V4 works with a stringified message, used by browser providers i.e. Metamask
|
|
585
|
+
signature = _b.sent();
|
|
586
|
+
return [3 /*break*/, 4];
|
|
587
|
+
case 2:
|
|
588
|
+
_a = _b.sent();
|
|
589
|
+
return [4 /*yield*/, promisify(function (c) {
|
|
590
|
+
return web3.currentProvider.sendAsync({
|
|
591
|
+
method: "eth_signTypedData",
|
|
592
|
+
params: [signerAddress, message],
|
|
593
|
+
from: signerAddress,
|
|
594
|
+
id: new Date().getTime(),
|
|
595
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
596
|
+
}, c);
|
|
597
|
+
})];
|
|
598
|
+
case 3:
|
|
599
|
+
// Fallback to normal sign typed data for node providers, without using stringified message
|
|
600
|
+
// https://github.com/coinbase/coinbase-wallet-sdk/issues/60
|
|
601
|
+
signature = _b.sent();
|
|
602
|
+
return [3 /*break*/, 4];
|
|
603
|
+
case 4:
|
|
604
|
+
error = signature.error;
|
|
605
|
+
if (error) {
|
|
606
|
+
throw new Error(error);
|
|
607
|
+
}
|
|
608
|
+
return [2 /*return*/, parseSignatureHex(signature === null || signature === void 0 ? void 0 : signature.result)];
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
exports.signTypedDataAsync = signTypedDataAsync;
|
|
614
|
+
/**
|
|
615
|
+
* Checks whether a given address contains any code
|
|
616
|
+
* @param web3 Web3 instance
|
|
617
|
+
* @param address input address
|
|
618
|
+
*/
|
|
619
|
+
function isContractAddress(web3, address) {
|
|
620
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
621
|
+
var code;
|
|
622
|
+
return __generator(this, function (_a) {
|
|
623
|
+
switch (_a.label) {
|
|
624
|
+
case 0: return [4 /*yield*/, web3.eth.getCode(address)];
|
|
625
|
+
case 1:
|
|
626
|
+
code = _a.sent();
|
|
627
|
+
return [2 /*return*/, code !== "0x"];
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
exports.isContractAddress = isContractAddress;
|
|
633
|
+
/**
|
|
634
|
+
* Special fixes for making BigNumbers using web3 results
|
|
635
|
+
* @param arg An arg or the result of a web3 call to turn into a BigNumber
|
|
636
|
+
*/
|
|
637
|
+
function makeBigNumber(arg) {
|
|
638
|
+
// Zero sometimes returned as 0x from contracts
|
|
639
|
+
if (arg === "0x") {
|
|
640
|
+
arg = 0;
|
|
641
|
+
}
|
|
642
|
+
// fix "new BigNumber() number type has more than 15 significant digits"
|
|
643
|
+
arg = arg.toString();
|
|
644
|
+
return new bignumber_js_1.default(arg);
|
|
645
|
+
}
|
|
646
|
+
exports.makeBigNumber = makeBigNumber;
|
|
647
|
+
/**
|
|
648
|
+
* Send a transaction to the blockchain and optionally confirm it
|
|
649
|
+
* @param web3 Web3 instance
|
|
650
|
+
* @param param0 __namedParameters
|
|
651
|
+
* @param from address sending transaction
|
|
652
|
+
* @param to destination contract address
|
|
653
|
+
* @param data data to send to contract
|
|
654
|
+
* @param gasPrice gas price to use. If unspecified, uses web3 default (mean gas price)
|
|
655
|
+
* @param value value in ETH to send with data. Defaults to 0
|
|
656
|
+
* @param onError callback when user denies transaction
|
|
657
|
+
*/
|
|
658
|
+
function sendRawTransaction(web3, _a, onError) {
|
|
659
|
+
var from = _a.from, to = _a.to, data = _a.data, gasPrice = _a.gasPrice, _b = _a.value, value = _b === void 0 ? 0 : _b, gas = _a.gas;
|
|
660
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
661
|
+
var txHashRes, error_2;
|
|
662
|
+
return __generator(this, function (_c) {
|
|
663
|
+
switch (_c.label) {
|
|
664
|
+
case 0:
|
|
665
|
+
if (!(gas == null)) return [3 /*break*/, 2];
|
|
666
|
+
return [4 /*yield*/, estimateGas(web3, { from: from, to: to, data: data, value: value })];
|
|
667
|
+
case 1:
|
|
668
|
+
// This gas cannot be increased due to an ethjs error
|
|
669
|
+
gas = _c.sent();
|
|
670
|
+
_c.label = 2;
|
|
671
|
+
case 2:
|
|
672
|
+
_c.trys.push([2, 4, , 5]);
|
|
673
|
+
return [4 /*yield*/, promisify(function (c) {
|
|
674
|
+
return web3.eth.sendTransaction({
|
|
675
|
+
from: from,
|
|
676
|
+
to: to,
|
|
677
|
+
value: value.toString(),
|
|
678
|
+
data: data,
|
|
679
|
+
gas: gas === null || gas === void 0 ? void 0 : gas.toString(),
|
|
680
|
+
gasPrice: gasPrice === null || gasPrice === void 0 ? void 0 : gasPrice.toString(),
|
|
681
|
+
}, c);
|
|
682
|
+
})];
|
|
683
|
+
case 3:
|
|
684
|
+
txHashRes = _c.sent();
|
|
685
|
+
return [2 /*return*/, txHashRes];
|
|
686
|
+
case 4:
|
|
687
|
+
error_2 = _c.sent();
|
|
688
|
+
onError(error_2);
|
|
689
|
+
throw error_2;
|
|
690
|
+
case 5: return [2 /*return*/];
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
exports.sendRawTransaction = sendRawTransaction;
|
|
696
|
+
/**
|
|
697
|
+
* Call a method on a contract, sending arbitrary data and
|
|
698
|
+
* handling Parity errors. Returns '0x' if error.
|
|
699
|
+
* @param web3 Web3 instance
|
|
700
|
+
* @param param0 __namedParameters
|
|
701
|
+
* @param from address sending call
|
|
702
|
+
* @param to destination contract address
|
|
703
|
+
* @param data data to send to contract
|
|
704
|
+
* @param onError callback when user denies transaction
|
|
705
|
+
*/
|
|
706
|
+
function rawCall(web3, _a, onError) {
|
|
707
|
+
var from = _a.from, to = _a.to, data = _a.data;
|
|
708
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
709
|
+
var result, error_3;
|
|
710
|
+
return __generator(this, function (_b) {
|
|
711
|
+
switch (_b.label) {
|
|
712
|
+
case 0:
|
|
713
|
+
_b.trys.push([0, 2, , 3]);
|
|
714
|
+
return [4 /*yield*/, web3.eth.call({
|
|
715
|
+
from: from,
|
|
716
|
+
to: to,
|
|
717
|
+
data: data,
|
|
718
|
+
})];
|
|
719
|
+
case 1:
|
|
720
|
+
result = _b.sent();
|
|
721
|
+
return [2 /*return*/, result];
|
|
722
|
+
case 2:
|
|
723
|
+
error_3 = _b.sent();
|
|
724
|
+
// Probably method not found, and web3 is a Parity node
|
|
725
|
+
if (onError) {
|
|
726
|
+
onError(error_3);
|
|
727
|
+
}
|
|
728
|
+
// Backwards compatibility with Geth nodes
|
|
729
|
+
return [2 /*return*/, "0x"];
|
|
730
|
+
case 3: return [2 /*return*/];
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
exports.rawCall = rawCall;
|
|
736
|
+
/**
|
|
737
|
+
* Estimate Gas usage for a transaction
|
|
738
|
+
* @param web3 Web3 instance
|
|
739
|
+
* @param from address sending transaction
|
|
740
|
+
* @param to destination contract address
|
|
741
|
+
* @param data data to send to contract
|
|
742
|
+
* @param value value in ETH to send with data
|
|
743
|
+
*/
|
|
744
|
+
function estimateGas(web3, _a) {
|
|
745
|
+
var from = _a.from, to = _a.to, data = _a.data, _b = _a.value, value = _b === void 0 ? 0 : _b;
|
|
746
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
747
|
+
var amount;
|
|
748
|
+
return __generator(this, function (_c) {
|
|
749
|
+
switch (_c.label) {
|
|
750
|
+
case 0: return [4 /*yield*/, web3.eth.estimateGas({
|
|
751
|
+
from: from,
|
|
752
|
+
to: to,
|
|
753
|
+
value: value.toString(),
|
|
754
|
+
data: data,
|
|
755
|
+
})];
|
|
756
|
+
case 1:
|
|
757
|
+
amount = _c.sent();
|
|
758
|
+
return [2 /*return*/, amount];
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
exports.estimateGas = estimateGas;
|
|
764
|
+
/**
|
|
765
|
+
* Get mean gas price for sending a txn, in wei
|
|
766
|
+
* @param web3 Web3 instance
|
|
767
|
+
*/
|
|
768
|
+
function getCurrentGasPrice(web3) {
|
|
769
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
770
|
+
var gasPrice;
|
|
771
|
+
return __generator(this, function (_a) {
|
|
772
|
+
switch (_a.label) {
|
|
773
|
+
case 0: return [4 /*yield*/, web3.eth.getGasPrice()];
|
|
774
|
+
case 1:
|
|
775
|
+
gasPrice = _a.sent();
|
|
776
|
+
return [2 /*return*/, new bignumber_js_1.default(gasPrice)];
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
exports.getCurrentGasPrice = getCurrentGasPrice;
|
|
782
|
+
/**
|
|
783
|
+
* Get current transfer fees for an asset
|
|
784
|
+
* @param web3 Web3 instance
|
|
785
|
+
* @param asset The asset to check for transfer fees
|
|
786
|
+
*/
|
|
787
|
+
function getTransferFeeSettings(web3, _a) {
|
|
788
|
+
var asset = _a.asset, accountAddress = _a.accountAddress;
|
|
789
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
790
|
+
var transferFee, transferFeeTokenAddress, feeContract, params;
|
|
791
|
+
return __generator(this, function (_b) {
|
|
792
|
+
switch (_b.label) {
|
|
793
|
+
case 0:
|
|
794
|
+
if (!(asset.tokenAddress.toLowerCase() == constants_2.ENJIN_ADDRESS.toLowerCase())) return [3 /*break*/, 2];
|
|
795
|
+
feeContract = new web3.eth.Contract(contracts_1.ERC1155, asset.tokenAddress);
|
|
796
|
+
return [4 /*yield*/, feeContract.methods
|
|
797
|
+
.transferSettings(asset.tokenId)
|
|
798
|
+
.call({ from: accountAddress })];
|
|
799
|
+
case 1:
|
|
800
|
+
params = _b.sent();
|
|
801
|
+
if (params) {
|
|
802
|
+
transferFee = makeBigNumber(params[3]);
|
|
803
|
+
if (params[2] === "0") {
|
|
804
|
+
transferFeeTokenAddress = constants_2.ENJIN_COIN_ADDRESS;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
_b.label = 2;
|
|
808
|
+
case 2: return [2 /*return*/, { transferFee: transferFee, transferFeeTokenAddress: transferFeeTokenAddress }];
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
exports.getTransferFeeSettings = getTransferFeeSettings;
|
|
814
|
+
// sourced from 0x.js:
|
|
815
|
+
// https://github.com/ProjectWyvern/wyvern-js/blob/39999cb93ce5d80ea90b4382182d1bd4339a9c6c/src/utils/signature_utils.ts
|
|
816
|
+
function parseSignatureHex(signature) {
|
|
817
|
+
// HACK: There is no consensus on whether the signatureHex string should be formatted as
|
|
818
|
+
// v + r + s OR r + s + v, and different clients (even different versions of the same client)
|
|
819
|
+
// return the signature params in different orders. In order to support all client implementations,
|
|
820
|
+
// we parse the signature in both ways, and evaluate if either one is a valid signature.
|
|
821
|
+
var validVParamValues = [27, 28];
|
|
822
|
+
var ecSignatureRSV = _parseSignatureHexAsRSV(signature);
|
|
823
|
+
if (_.includes(validVParamValues, ecSignatureRSV.v)) {
|
|
824
|
+
return ecSignatureRSV;
|
|
825
|
+
}
|
|
826
|
+
// For older clients
|
|
827
|
+
var ecSignatureVRS = _parseSignatureHexAsVRS(signature);
|
|
828
|
+
if (_.includes(validVParamValues, ecSignatureVRS.v)) {
|
|
829
|
+
return ecSignatureVRS;
|
|
830
|
+
}
|
|
831
|
+
throw new Error("Invalid signature");
|
|
832
|
+
function _parseSignatureHexAsVRS(signatureHex) {
|
|
833
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
834
|
+
var signatureBuffer = ethUtil.toBuffer(signatureHex);
|
|
835
|
+
var v = signatureBuffer[0];
|
|
836
|
+
if (v < 27) {
|
|
837
|
+
v += 27;
|
|
838
|
+
}
|
|
839
|
+
var r = signatureBuffer.slice(1, 33);
|
|
840
|
+
var s = signatureBuffer.slice(33, 65);
|
|
841
|
+
var ecSignature = {
|
|
842
|
+
v: v,
|
|
843
|
+
r: ethUtil.bufferToHex(r),
|
|
844
|
+
s: ethUtil.bufferToHex(s),
|
|
845
|
+
};
|
|
846
|
+
return ecSignature;
|
|
847
|
+
}
|
|
848
|
+
function _parseSignatureHexAsRSV(signatureHex) {
|
|
849
|
+
var _a = ethUtil.fromRpcSig(signatureHex), v = _a.v, r = _a.r, s = _a.s;
|
|
850
|
+
var ecSignature = {
|
|
851
|
+
v: v,
|
|
852
|
+
r: ethUtil.bufferToHex(r),
|
|
853
|
+
s: ethUtil.bufferToHex(s),
|
|
854
|
+
};
|
|
855
|
+
return ecSignature;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Estimates the price of an order
|
|
860
|
+
* @param order The order to estimate price on
|
|
861
|
+
* @param secondsToBacktrack The number of seconds to subtract on current time,
|
|
862
|
+
* to fix race conditions
|
|
863
|
+
* @param shouldRoundUp Whether to round up fractional wei
|
|
864
|
+
*/
|
|
865
|
+
function estimateCurrentPrice(order, secondsToBacktrack, shouldRoundUp) {
|
|
866
|
+
if (secondsToBacktrack === void 0) { secondsToBacktrack = 30; }
|
|
867
|
+
if (shouldRoundUp === void 0) { shouldRoundUp = true; }
|
|
868
|
+
var basePrice = order.basePrice, listingTime = order.listingTime, expirationTime = order.expirationTime, extra = order.extra;
|
|
869
|
+
var side = order.side, takerRelayerFee = order.takerRelayerFee, saleKind = order.saleKind;
|
|
870
|
+
var now = new bignumber_js_1.default(Math.round(Date.now() / 1000)).minus(secondsToBacktrack);
|
|
871
|
+
basePrice = new bignumber_js_1.default(basePrice);
|
|
872
|
+
listingTime = new bignumber_js_1.default(listingTime);
|
|
873
|
+
expirationTime = new bignumber_js_1.default(expirationTime);
|
|
874
|
+
extra = new bignumber_js_1.default(extra);
|
|
875
|
+
var exactPrice = basePrice;
|
|
876
|
+
if (saleKind === types_2.SaleKind.FixedPrice) {
|
|
877
|
+
// Do nothing, price is correct
|
|
878
|
+
}
|
|
879
|
+
else if (saleKind === types_2.SaleKind.DutchAuction) {
|
|
880
|
+
var diff = extra
|
|
881
|
+
.times(now.minus(listingTime))
|
|
882
|
+
.dividedBy(expirationTime.minus(listingTime));
|
|
883
|
+
exactPrice =
|
|
884
|
+
side == types_2.OrderSide.Sell
|
|
885
|
+
? /* Sell-side - start price: basePrice. End price: basePrice - extra. */
|
|
886
|
+
basePrice.minus(diff)
|
|
887
|
+
: /* Buy-side - start price: basePrice. End price: basePrice + extra. */
|
|
888
|
+
basePrice.plus(diff);
|
|
889
|
+
}
|
|
890
|
+
// Add taker fee only for buyers
|
|
891
|
+
if (side === types_2.OrderSide.Sell && !order.waitingForBestCounterOrder) {
|
|
892
|
+
// Buyer fee increases sale price
|
|
893
|
+
exactPrice = exactPrice.times(+takerRelayerFee / constants_2.INVERSE_BASIS_POINT + 1);
|
|
894
|
+
}
|
|
895
|
+
return shouldRoundUp
|
|
896
|
+
? exactPrice.integerValue(bignumber_js_1.default.ROUND_CEIL)
|
|
897
|
+
: exactPrice;
|
|
898
|
+
}
|
|
899
|
+
exports.estimateCurrentPrice = estimateCurrentPrice;
|
|
900
|
+
/**
|
|
901
|
+
* Get the Wyvern representation of a fungible asset
|
|
902
|
+
* @param schema The WyvernSchema needed to access this asset
|
|
903
|
+
* @param asset The asset to trade
|
|
904
|
+
* @param quantity The number of items to trade
|
|
905
|
+
*/
|
|
906
|
+
function getWyvernAsset(schema, asset, quantity) {
|
|
907
|
+
if (quantity === void 0) { quantity = new bignumber_js_1.default(1); }
|
|
908
|
+
var tokenId = asset.tokenId != null ? asset.tokenId.toString() : undefined;
|
|
909
|
+
return schema.assetFromFields({
|
|
910
|
+
ID: tokenId,
|
|
911
|
+
Quantity: quantity.toString(),
|
|
912
|
+
Address: asset.tokenAddress.toLowerCase(),
|
|
913
|
+
Name: asset.name,
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
exports.getWyvernAsset = getWyvernAsset;
|
|
917
|
+
/**
|
|
918
|
+
* Get the Wyvern representation of a group of assets
|
|
919
|
+
* Sort order is enforced here. Throws if there's a duplicate.
|
|
920
|
+
* @param assets Assets to bundle
|
|
921
|
+
* @param schemas The WyvernSchemas needed to access each asset, respectively
|
|
922
|
+
* @param quantities The quantity of each asset to bundle, respectively
|
|
923
|
+
*/
|
|
924
|
+
function getWyvernBundle(assets, schemas, quantities) {
|
|
925
|
+
if (assets.length != quantities.length) {
|
|
926
|
+
throw new Error("Bundle must have a quantity for every asset");
|
|
927
|
+
}
|
|
928
|
+
if (assets.length != schemas.length) {
|
|
929
|
+
throw new Error("Bundle must have a schema for every asset");
|
|
930
|
+
}
|
|
931
|
+
var wyAssets = assets.map(function (asset, i) {
|
|
932
|
+
return getWyvernAsset(schemas[i], asset, quantities[i]);
|
|
933
|
+
});
|
|
934
|
+
var sorters = [
|
|
935
|
+
function (assetAndSchema) {
|
|
936
|
+
return assetAndSchema.asset.address;
|
|
937
|
+
},
|
|
938
|
+
function (assetAndSchema) {
|
|
939
|
+
return assetAndSchema.asset.id || 0;
|
|
940
|
+
},
|
|
941
|
+
];
|
|
942
|
+
var wyAssetsAndSchemas = wyAssets.map(function (asset, i) { return ({
|
|
943
|
+
asset: asset,
|
|
944
|
+
schema: schemas[i].name,
|
|
945
|
+
}); });
|
|
946
|
+
var uniqueAssets = _.uniqBy(wyAssetsAndSchemas, function (group) { return "".concat(sorters[0](group), "-").concat(sorters[1](group)); });
|
|
947
|
+
if (uniqueAssets.length != wyAssetsAndSchemas.length) {
|
|
948
|
+
throw new Error("Bundle can't contain duplicate assets");
|
|
949
|
+
}
|
|
950
|
+
var sortedWyAssetsAndSchemas = _.sortBy(wyAssetsAndSchemas, sorters);
|
|
951
|
+
return {
|
|
952
|
+
assets: sortedWyAssetsAndSchemas.map(function (group) { return group.asset; }),
|
|
953
|
+
schemas: sortedWyAssetsAndSchemas.map(function (group) { return group.schema; }),
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
exports.getWyvernBundle = getWyvernBundle;
|
|
957
|
+
/**
|
|
958
|
+
* Get the non-prefixed hash for the order
|
|
959
|
+
* (Fixes a Wyvern typescript issue and casing issue)
|
|
960
|
+
* @param order order to hash
|
|
961
|
+
*/
|
|
962
|
+
function getOrderHash(order) {
|
|
963
|
+
var orderWithStringTypes = __assign(__assign({}, order), { maker: order.maker.toLowerCase(), taker: order.taker.toLowerCase(), feeRecipient: order.feeRecipient.toLowerCase(), side: order.side.toString(), saleKind: order.saleKind.toString(), howToCall: order.howToCall.toString(), feeMethod: order.feeMethod.toString() });
|
|
964
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
965
|
+
return wyvern_js_1.WyvernProtocol.getOrderHashHex(orderWithStringTypes);
|
|
966
|
+
}
|
|
967
|
+
exports.getOrderHash = getOrderHash;
|
|
968
|
+
/**
|
|
969
|
+
* Assign an order and a new matching order to their buy/sell sides
|
|
970
|
+
* @param order Original order
|
|
971
|
+
* @param matchingOrder The result of _makeMatchingOrder
|
|
972
|
+
*/
|
|
973
|
+
function assignOrdersToSides(order, matchingOrder) {
|
|
974
|
+
var isSellOrder = order.side == types_2.OrderSide.Sell;
|
|
975
|
+
var buy;
|
|
976
|
+
var sell;
|
|
977
|
+
if (!isSellOrder) {
|
|
978
|
+
buy = order;
|
|
979
|
+
sell = __assign(__assign({}, matchingOrder), { v: buy.v, r: buy.r, s: buy.s });
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
sell = order;
|
|
983
|
+
buy = __assign(__assign({}, matchingOrder), { v: sell.v, r: sell.r, s: sell.s });
|
|
984
|
+
}
|
|
985
|
+
return { buy: buy, sell: sell };
|
|
986
|
+
}
|
|
987
|
+
exports.assignOrdersToSides = assignOrdersToSides;
|
|
988
|
+
/**
|
|
989
|
+
* Delay using setTimeout
|
|
990
|
+
* @param ms milliseconds to wait
|
|
991
|
+
*/
|
|
992
|
+
function delay(ms) {
|
|
993
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
994
|
+
return __generator(this, function (_a) {
|
|
995
|
+
return [2 /*return*/, new Promise(function (res) { return setTimeout(res, ms); })];
|
|
996
|
+
});
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
exports.delay = delay;
|
|
1000
|
+
/**
|
|
1001
|
+
* Validates that an address exists, isn't null, and is properly
|
|
1002
|
+
* formatted for Wyvern and OpenSea
|
|
1003
|
+
* @param address input address
|
|
1004
|
+
*/
|
|
1005
|
+
function validateAndFormatWalletAddress(web3, address) {
|
|
1006
|
+
if (!address) {
|
|
1007
|
+
throw new Error("No wallet address found");
|
|
1008
|
+
}
|
|
1009
|
+
if (!web3.utils.isAddress(address)) {
|
|
1010
|
+
throw new Error("Invalid wallet address");
|
|
1011
|
+
}
|
|
1012
|
+
if (address == constants_2.NULL_ADDRESS) {
|
|
1013
|
+
throw new Error("Wallet cannot be the null address");
|
|
1014
|
+
}
|
|
1015
|
+
return address.toLowerCase();
|
|
1016
|
+
}
|
|
1017
|
+
exports.validateAndFormatWalletAddress = validateAndFormatWalletAddress;
|
|
1018
|
+
/**
|
|
1019
|
+
* Notify developer when a pattern will be deprecated
|
|
1020
|
+
* @param msg message to log to console
|
|
1021
|
+
*/
|
|
1022
|
+
function onDeprecated(msg) {
|
|
1023
|
+
console.warn("DEPRECATION NOTICE: ".concat(msg));
|
|
1024
|
+
}
|
|
1025
|
+
exports.onDeprecated = onDeprecated;
|
|
1026
|
+
/**
|
|
1027
|
+
* Get special-case approval addresses for an erc721 contract
|
|
1028
|
+
* @param erc721Contract contract to check
|
|
1029
|
+
*/
|
|
1030
|
+
function getNonCompliantApprovalAddress(erc721Contract, tokenId, _accountAddress) {
|
|
1031
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1032
|
+
var results;
|
|
1033
|
+
return __generator(this, function (_a) {
|
|
1034
|
+
switch (_a.label) {
|
|
1035
|
+
case 0: return [4 /*yield*/, Promise.allSettled([
|
|
1036
|
+
// CRYPTOKITTIES check
|
|
1037
|
+
erc721Contract.methods.kittyIndexToApproved(tokenId).call(),
|
|
1038
|
+
// Etherbots check
|
|
1039
|
+
erc721Contract.methods.partIndexToApproved(tokenId).call(),
|
|
1040
|
+
])];
|
|
1041
|
+
case 1:
|
|
1042
|
+
results = _a.sent();
|
|
1043
|
+
return [2 /*return*/, _.compact(results)[0].status];
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
exports.getNonCompliantApprovalAddress = getNonCompliantApprovalAddress;
|
|
1049
|
+
exports.merkleValidatorByNetwork = (_a = {},
|
|
1050
|
+
_a[types_1.Network.Main] = constants_2.MERKLE_VALIDATOR_MAINNET,
|
|
1051
|
+
_a[types_1.Network.Rinkeby] = constants_2.MERKLE_VALIDATOR_RINKEBY,
|
|
1052
|
+
_a[types_1.Network.Goerli] = null,
|
|
1053
|
+
_a);
|
|
1054
|
+
/**
|
|
1055
|
+
* The longest time that an order is valid for is six months from the current date
|
|
1056
|
+
* @returns unix timestamp
|
|
1057
|
+
*/
|
|
1058
|
+
var getMaxOrderExpirationTimestamp = function () {
|
|
1059
|
+
var maxExpirationDate = new Date();
|
|
1060
|
+
maxExpirationDate.setMonth(maxExpirationDate.getMonth() + constants_2.MAX_EXPIRATION_MONTHS);
|
|
1061
|
+
maxExpirationDate.setDate(maxExpirationDate.getDate() - 1);
|
|
1062
|
+
return Math.round(maxExpirationDate.getTime() / 1000);
|
|
1063
|
+
};
|
|
1064
|
+
exports.getMaxOrderExpirationTimestamp = getMaxOrderExpirationTimestamp;
|
|
1065
|
+
var hasErrorCode = function (error) {
|
|
1066
|
+
var untypedError = error;
|
|
1067
|
+
return !!untypedError.code;
|
|
1068
|
+
};
|
|
1069
|
+
exports.hasErrorCode = hasErrorCode;
|
|
1070
|
+
var getAssetItemType = function (schemaName) {
|
|
1071
|
+
switch (schemaName) {
|
|
1072
|
+
case "ERC20":
|
|
1073
|
+
return constants_1.ItemType.ERC20;
|
|
1074
|
+
case "ERC721":
|
|
1075
|
+
return constants_1.ItemType.ERC721;
|
|
1076
|
+
case "ERC1155":
|
|
1077
|
+
return constants_1.ItemType.ERC1155;
|
|
1078
|
+
default:
|
|
1079
|
+
throw new Error("Unknown schema name: ".concat(schemaName));
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
exports.getAssetItemType = getAssetItemType;
|
|
1083
|
+
var SHARED_STOREFRONT_ADDRESSES = new Set([
|
|
1084
|
+
constants_2.SHARED_STORE_FRONT_ADDRESS_MAINNET.toLowerCase(),
|
|
1085
|
+
constants_2.SHARED_STORE_FRONT_ADDRESS_RINKEBY.toLowerCase(),
|
|
1086
|
+
]);
|
|
1087
|
+
/**
|
|
1088
|
+
* Checks if the token address is the shared storefront address and if so replaces
|
|
1089
|
+
* that address with the lazy mint adapter addres. Otherwise, returns the input token address
|
|
1090
|
+
* @param tokenAddress token address
|
|
1091
|
+
* @returns input token address or lazy mint adapter address
|
|
1092
|
+
*/
|
|
1093
|
+
var getAddressAfterRemappingSharedStorefrontAddressToLazyMintAdapterAddress = function (tokenAddress) {
|
|
1094
|
+
return SHARED_STOREFRONT_ADDRESSES.has(tokenAddress.toLowerCase())
|
|
1095
|
+
? constants_2.SHARED_STOREFRONT_LAZY_MINT_ADAPTER_ADDRESS
|
|
1096
|
+
: tokenAddress;
|
|
1097
|
+
};
|
|
1098
|
+
exports.getAddressAfterRemappingSharedStorefrontAddressToLazyMintAdapterAddress = getAddressAfterRemappingSharedStorefrontAddressToLazyMintAdapterAddress;
|
|
1099
|
+
/**
|
|
1100
|
+
* Sums up the basis points for an Opensea or seller fee map and returns the
|
|
1101
|
+
* single numeric value if the map is not empty. Otherwise, it returns 0
|
|
1102
|
+
* @param fees a `Fees` submap holding fees (either Fees.openseaFees
|
|
1103
|
+
* or Fees.sellerFees)
|
|
1104
|
+
* @returns sum of basis points in a fee map
|
|
1105
|
+
*/
|
|
1106
|
+
var feesToBasisPoints = function (fees) {
|
|
1107
|
+
if (!fees) {
|
|
1108
|
+
return 0;
|
|
1109
|
+
}
|
|
1110
|
+
return Array.from(fees.values()).reduce(function (sum, basisPoints) { return basisPoints + sum; }, 0);
|
|
1111
|
+
};
|
|
1112
|
+
exports.feesToBasisPoints = feesToBasisPoints;
|
|
1113
|
+
//# sourceMappingURL=utils.js.map
|