@hypercerts-org/marketplace-sdk 0.3.35 → 0.3.37

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright 2023 Hypercerts Foundation
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
4
+ License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
9
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
10
+ language governing permissions and limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Hypercerts Foundation
4
+
5
+ Copyright (c) 2022 LooksRare for portions of marketplace: https://github.com/LooksRare/contracts-exchange-v2 commit:
6
+ 7fca565
7
+
8
+ Copyright (c) 2022 Paul Razvan Berg for inital template: https://github.com/paulrberg/foundry-template
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
12
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ persons to whom the Software is furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
16
+ Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,7 +1,4 @@
1
1
  import { Addresses, ChainId } from "../types";
2
- /**
3
- * List of useful contract addresses
4
- */
5
2
  export declare const addressesByNetwork: {
6
3
  [chainId in ChainId]: Addresses;
7
4
  };
package/dist/errors.d.ts CHANGED
@@ -28,3 +28,8 @@ export declare class ErrorItemId extends Error {
28
28
  readonly name = "ErrorItemId";
29
29
  constructor();
30
30
  }
31
+ /** Currency is not supported */
32
+ export declare class ErrorCurrency extends Error {
33
+ readonly name = "ErrorCurrency";
34
+ constructor();
35
+ }
package/dist/index.cjs.js CHANGED
@@ -684,6 +684,8 @@ var strategies = /*#__PURE__*/Object.freeze({
684
684
  strategyInfo: strategyInfo
685
685
  });
686
686
 
687
+ /** All possible supported currencies */
688
+ const SUPPORTED_CURRENCIES = ["ETH", "WETH", "DAI", "CELO", "cUSD", "USDT", "USDC"];
687
689
  /** List of supported chains */
688
690
  exports.ChainId = void 0;
689
691
  (function (ChainId) {
@@ -692,8 +694,8 @@ exports.ChainId = void 0;
692
694
  ChainId[ChainId["HARDHAT"] = 31337] = "HARDHAT";
693
695
  ChainId[ChainId["OPTIMISM"] = 10] = "OPTIMISM";
694
696
  ChainId[ChainId["CELO"] = 42220] = "CELO";
695
- ChainId[ChainId["BASE"] = 8453] = "BASE";
696
697
  ChainId[ChainId["ARBITRUM_SEPOLIA"] = 421614] = "ARBITRUM_SEPOLIA";
698
+ ChainId[ChainId["ARBITRUM"] = 42161] = "ARBITRUM";
697
699
  })(exports.ChainId || (exports.ChainId = {}));
698
700
  /** List of collection types supported by the protocol */
699
701
  exports.CollectionType = void 0;
@@ -1098,48 +1100,46 @@ var asDeployedChain$1 = /*#__PURE__*/Object.freeze({
1098
1100
  asDeployedChain: asDeployedChain
1099
1101
  });
1100
1102
 
1101
- const sepoliaAddresses = {
1102
- EXCHANGE_V2: contracts.deployments[11155111].HypercertExchange,
1103
- TRANSFER_MANAGER_V2: contracts.deployments[11155111].TransferManager,
1104
- ORDER_VALIDATOR_V2: contracts.deployments[11155111].OrderValidatorV2A,
1105
- MINTER: contracts.deployments[11155111].HypercertMinterUUPS,
1106
- };
1107
- const baseSepoliaAddresses = {
1108
- EXCHANGE_V2: contracts.deployments[84532].HypercertExchange,
1109
- TRANSFER_MANAGER_V2: contracts.deployments[84532].TransferManager,
1110
- ORDER_VALIDATOR_V2: contracts.deployments[84532].OrderValidatorV2A,
1111
- MINTER: contracts.deployments[84532].HypercertMinterUUPS,
1112
- };
1113
- const optimismAddresses = {
1114
- EXCHANGE_V2: contracts.deployments[10].HypercertExchange,
1115
- TRANSFER_MANAGER_V2: contracts.deployments[10].TransferManager,
1116
- ORDER_VALIDATOR_V2: contracts.deployments[10].OrderValidatorV2A,
1117
- MINTER: contracts.deployments[10].HypercertMinterUUPS,
1118
- };
1119
- const celoAddresses = {
1120
- EXCHANGE_V2: contracts.deployments[42220].HypercertExchange,
1121
- TRANSFER_MANAGER_V2: contracts.deployments[42220].TransferManager,
1122
- ORDER_VALIDATOR_V2: contracts.deployments[42220].OrderValidatorV2A,
1123
- MINTER: contracts.deployments[42220].HypercertMinterUUPS,
1124
- };
1125
- const baseAddresses = {
1126
- EXCHANGE_V2: contracts.deployments[8453].HypercertExchange,
1127
- TRANSFER_MANAGER_V2: contracts.deployments[8453].TransferManager,
1128
- ORDER_VALIDATOR_V2: contracts.deployments[8453].OrderValidatorV2A,
1129
- MINTER: contracts.deployments[8453].HypercertMinterUUPS,
1103
+ function getRequiredAddress(chainId, contractName) {
1104
+ const chainIdStr = chainId.toString();
1105
+ const deployment = contracts.deployments[chainIdStr];
1106
+ if (!deployment) {
1107
+ throw new Error(`Missing deployment for chain ${chainId}`);
1108
+ }
1109
+ const address = deployment[contractName];
1110
+ if (!address) {
1111
+ throw new Error(`Missing required address for ${contractName} on chain ${chainId}`);
1112
+ }
1113
+ return ethers.getAddress(address);
1114
+ }
1115
+ // Helper function to create addresses for a network
1116
+ const createNetworkAddresses = (chainId) => ({
1117
+ EXCHANGE_V2: getRequiredAddress(chainId, "HypercertExchange"),
1118
+ TRANSFER_MANAGER_V2: getRequiredAddress(chainId, "TransferManager"),
1119
+ ORDER_VALIDATOR_V2: getRequiredAddress(chainId, "OrderValidatorV2A"),
1120
+ MINTER: getRequiredAddress(chainId, "HypercertMinterUUPS"),
1121
+ });
1122
+ // Network chain IDs
1123
+ const CHAIN_IDS = {
1124
+ // Testnets
1125
+ SEPOLIA: 11155111,
1126
+ BASE_SEPOLIA: 84532,
1127
+ ARBITRUM_SEPOLIA: 421614,
1128
+ // Mainnets
1129
+ OPTIMISM: 10,
1130
+ CELO: 42220,
1131
+ ARBITRUM: 42161,
1130
1132
  };
1131
- /**
1132
- * List of useful contract addresses
1133
- */
1134
1133
  const addressesByNetwork = {
1135
1134
  // Testnets
1136
- [exports.ChainId.SEPOLIA]: sepoliaAddresses,
1137
- [exports.ChainId.HARDHAT]: sepoliaAddresses,
1138
- [exports.ChainId.BASE_SEPOLIA]: baseSepoliaAddresses,
1135
+ [exports.ChainId.SEPOLIA]: createNetworkAddresses(CHAIN_IDS.SEPOLIA),
1136
+ [exports.ChainId.HARDHAT]: createNetworkAddresses(CHAIN_IDS.SEPOLIA), // Using Sepolia for Hardhat
1137
+ [exports.ChainId.BASE_SEPOLIA]: createNetworkAddresses(CHAIN_IDS.BASE_SEPOLIA),
1138
+ [exports.ChainId.ARBITRUM_SEPOLIA]: createNetworkAddresses(CHAIN_IDS.ARBITRUM_SEPOLIA),
1139
1139
  // Production nets
1140
- [exports.ChainId.OPTIMISM]: optimismAddresses,
1141
- [exports.ChainId.CELO]: celoAddresses,
1142
- [exports.ChainId.BASE]: baseAddresses,
1140
+ [exports.ChainId.OPTIMISM]: createNetworkAddresses(CHAIN_IDS.OPTIMISM),
1141
+ [exports.ChainId.CELO]: createNetworkAddresses(CHAIN_IDS.CELO),
1142
+ [exports.ChainId.ARBITRUM]: createNetworkAddresses(CHAIN_IDS.ARBITRUM),
1143
1143
  };
1144
1144
 
1145
1145
  const currencyAddressesPerChain = {
@@ -1174,34 +1174,53 @@ const currencyAddressesPerChain = {
1174
1174
  USDC: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
1175
1175
  },
1176
1176
  [exports.ChainId.CELO]: {
1177
- ETH: ethers.ZeroAddress,
1178
- WETH: "0x66803fb87abd4aac3cbb3fad7c3aa01f6f3fb207",
1179
- DAI: "0xE4fE50cdD716522A56204352f00AA110F731932d",
1180
- USDC: "0xef4229c8c3250C675F21BCefa42f58EfbfF6002a",
1177
+ CELO: "0x471EcE3750Da237f93B8E339c536989b8978a438",
1178
+ cUSD: "0x765DE816845861e75A25fCA122bb6898B8B1282a",
1179
+ USDC: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
1180
+ USDT: "0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e",
1181
1181
  },
1182
- [exports.ChainId.BASE]: {
1182
+ [exports.ChainId.ARBITRUM]: {
1183
1183
  ETH: ethers.ZeroAddress,
1184
- WETH: "0x4200000000000000000000000000000000000006",
1185
- DAI: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
1186
- USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
1184
+ WETH: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
1185
+ DAI: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
1186
+ USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
1187
1187
  },
1188
1188
  };
1189
1189
  const getCurrencies = (chainId) => {
1190
1190
  const currenciesForChain = currencyAddressesPerChain[chainId];
1191
+ if ("ETH" in currenciesForChain) {
1192
+ return {
1193
+ ETH: {
1194
+ symbol: "ETH",
1195
+ address: currenciesForChain.ETH,
1196
+ decimals: 18,
1197
+ },
1198
+ WETH: {
1199
+ symbol: "WETH",
1200
+ address: currenciesForChain.WETH,
1201
+ decimals: 18,
1202
+ },
1203
+ DAI: {
1204
+ symbol: "DAI",
1205
+ address: currenciesForChain.DAI,
1206
+ decimals: 18,
1207
+ },
1208
+ USDC: {
1209
+ symbol: "USDC",
1210
+ address: currenciesForChain.USDC,
1211
+ decimals: 6,
1212
+ },
1213
+ };
1214
+ }
1191
1215
  return {
1192
- ETH: {
1193
- symbol: "ETH",
1194
- address: currenciesForChain.ETH,
1195
- decimals: 18,
1196
- },
1197
- WETH: {
1198
- symbol: "WETH",
1199
- address: currenciesForChain.WETH,
1216
+ CELO: {
1217
+ symbol: "CELO",
1218
+ address: currenciesForChain.CELO,
1200
1219
  decimals: 18,
1201
1220
  },
1202
- DAI: {
1203
- symbol: "DAI",
1204
- address: currenciesForChain.DAI,
1221
+ cUSD: {
1222
+ symbol: "cUSD",
1223
+ address: currenciesForChain.cUSD,
1205
1224
  decimals: 18,
1206
1225
  },
1207
1226
  USDC: {
@@ -1209,6 +1228,11 @@ const getCurrencies = (chainId) => {
1209
1228
  address: currenciesForChain.USDC,
1210
1229
  decimals: 6,
1211
1230
  },
1231
+ USDT: {
1232
+ symbol: "USDT",
1233
+ address: currenciesForChain.USDT,
1234
+ decimals: 6,
1235
+ },
1212
1236
  };
1213
1237
  };
1214
1238
  const currenciesByNetwork = {
@@ -1217,8 +1241,8 @@ const currenciesByNetwork = {
1217
1241
  [exports.ChainId.BASE_SEPOLIA]: getCurrencies(exports.ChainId.BASE_SEPOLIA),
1218
1242
  [exports.ChainId.OPTIMISM]: getCurrencies(exports.ChainId.OPTIMISM),
1219
1243
  [exports.ChainId.CELO]: getCurrencies(exports.ChainId.CELO),
1220
- [exports.ChainId.BASE]: getCurrencies(exports.ChainId.BASE),
1221
1244
  [exports.ChainId.ARBITRUM_SEPOLIA]: getCurrencies(exports.ChainId.ARBITRUM_SEPOLIA),
1245
+ [exports.ChainId.ARBITRUM]: getCurrencies(exports.ChainId.ARBITRUM),
1222
1246
  };
1223
1247
 
1224
1248
  const chainInfo = {
@@ -1246,6 +1270,14 @@ const chainInfo = {
1246
1270
  baseApiUrl: "https://staging-api.hypercerts.org",
1247
1271
  osApiUrl: "https://testnets-api.opensea.io"
1248
1272
  },
1273
+ [exports.ChainId.ARBITRUM]: {
1274
+ label: "Arbitrum",
1275
+ appUrl: "https://app.hypercerts.org",
1276
+ explorer: "https://arbitrum.io",
1277
+ rpcUrl: "https://arbitrum.io",
1278
+ baseApiUrl: "https://api.hypercerts.org",
1279
+ osApiUrl: "https://testnets-api.opensea.io"
1280
+ },
1249
1281
  [exports.ChainId.ARBITRUM_SEPOLIA]: {
1250
1282
  label: "Arbitrum Sepolia",
1251
1283
  appUrl: "https://testnet.hypercerts.org",
@@ -1270,14 +1302,6 @@ const chainInfo = {
1270
1302
  baseApiUrl: "https://api.hypercerts.org",
1271
1303
  osApiUrl: "https://testnets-api.opensea.io"
1272
1304
  },
1273
- [exports.ChainId.BASE]: {
1274
- label: "Base",
1275
- appUrl: "https://app.hypercerts.org",
1276
- explorer: "https://basescan.io",
1277
- rpcUrl: "https://mainnet.base.org",
1278
- baseApiUrl: "https://api.hypercerts.org",
1279
- osApiUrl: "https://testnets-api.opensea.io"
1280
- }
1281
1305
  };
1282
1306
 
1283
1307
  /** Maximum amount of orders in a merkle tree
@@ -1332,6 +1356,13 @@ class ErrorItemId extends Error {
1332
1356
  this.name = "ErrorItemId";
1333
1357
  }
1334
1358
  }
1359
+ /** Currency is not supported */
1360
+ class ErrorCurrency extends Error {
1361
+ constructor() {
1362
+ super("Currency is not defined or supported");
1363
+ this.name = "ErrorCurrency";
1364
+ }
1365
+ }
1335
1366
 
1336
1367
  var IERC1155 = [
1337
1368
  {
@@ -7756,11 +7787,14 @@ class HypercertExchangeClient {
7756
7787
  * @param CreateMakerInput
7757
7788
  * @returns the maker object, isCurrencyApproved, and isBalanceSufficient
7758
7789
  */
7759
- async createMakerBid({ collection, strategyId, collectionType, subsetNonce, orderNonce, endTime, price, itemIds, amounts = [1], currency = this.currencies.WETH.address, startTime = Math.floor(Date.now() / 1000), additionalParameters = [], }) {
7790
+ async createMakerBid({ collection, strategyId, collectionType, subsetNonce, orderNonce, endTime, price, itemIds, amounts = [1], currency, startTime = Math.floor(Date.now() / 1000), additionalParameters = [], }) {
7760
7791
  const signer = this.getSigner();
7761
7792
  if (!this.isTimestampValid(startTime) || !this.isTimestampValid(endTime)) {
7762
7793
  throw new ErrorTimestamp();
7763
7794
  }
7795
+ if (!currency) {
7796
+ throw new ErrorCurrency();
7797
+ }
7764
7798
  const signerAddress = await signer.getAddress();
7765
7799
  const spenderAddress = this.addresses.EXCHANGE_V2;
7766
7800
  // Use this.provider (MulticallProvider) in order to batch the calls
@@ -8104,11 +8138,14 @@ class HypercertExchangeClient {
8104
8138
  * @param currency Currency used to buy the fractions (default to WETH)
8105
8139
  * @param additionalParameters Additional parameters used to support complex orders
8106
8140
  */
8107
- async createDirectFractionsSaleMakerAsk({ itemIds, price, startTime, endTime, currency = this.currencies.WETH.address, additionalParameters = [], }) {
8141
+ async createDirectFractionsSaleMakerAsk({ itemIds, price, startTime, endTime, currency, additionalParameters = [], }) {
8108
8142
  const address = await this.signer?.getAddress();
8109
8143
  if (!address) {
8110
8144
  throw new Error("No signer address could be determined");
8111
8145
  }
8146
+ if (!currency) {
8147
+ throw new ErrorCurrency();
8148
+ }
8112
8149
  const chainId = this.chainId;
8113
8150
  const { nonce_counter } = await this.api.fetchOrderNonce({
8114
8151
  address,
@@ -8145,11 +8182,14 @@ class HypercertExchangeClient {
8145
8182
  * @param sellLeftoverFraction Whether or not the seller wants to sell the leftover units
8146
8183
  * @param root Merkle tree root (optional)
8147
8184
  */
8148
- async createFractionalSaleMakerAsk({ itemIds, price, startTime, endTime, currency = this.currencies.WETH.address, maxUnitAmount, minUnitAmount, minUnitsToKeep, sellLeftoverFraction, root, }) {
8185
+ async createFractionalSaleMakerAsk({ itemIds, price, startTime, endTime, currency, maxUnitAmount, minUnitAmount, minUnitsToKeep, sellLeftoverFraction, root, }) {
8149
8186
  const address = await this.signer?.getAddress();
8150
8187
  if (!address) {
8151
8188
  throw new Error("No signer address could be determined");
8152
8189
  }
8190
+ if (!currency) {
8191
+ throw new ErrorCurrency();
8192
+ }
8153
8193
  const chainId = this.chainId;
8154
8194
  const { nonce_counter } = await this.api.fetchOrderNonce({
8155
8195
  address,
@@ -8245,6 +8285,7 @@ const utils = {
8245
8285
  exports.ApiClient = ApiClient;
8246
8286
  exports.Eip712MakerMerkleTree = Eip712MakerMerkleTree;
8247
8287
  exports.Eip712MerkleTree = Eip712MerkleTree;
8288
+ exports.ErrorCurrency = ErrorCurrency;
8248
8289
  exports.ErrorItemId = ErrorItemId;
8249
8290
  exports.ErrorMerkleTreeDepth = ErrorMerkleTreeDepth;
8250
8291
  exports.ErrorQuoteType = ErrorQuoteType;
@@ -8258,6 +8299,7 @@ exports.IERC721Abi = abiIERC721;
8258
8299
  exports.LooksRareProtocolAbi = LooksRareProtocol;
8259
8300
  exports.MAX_ORDERS_PER_TREE = MAX_ORDERS_PER_TREE;
8260
8301
  exports.OrderValidatorV2AAbi = OrderValidatorV2A;
8302
+ exports.SUPPORTED_CURRENCIES = SUPPORTED_CURRENCIES;
8261
8303
  exports.TransferManagerAbi = TransferManager;
8262
8304
  exports.WETHAbi = WETH;
8263
8305
  exports.addressesByNetwork = addressesByNetwork;
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Contract, ZeroAddress, AbiCoder, TypedDataEncoder, keccak256, solidityPackedKeccak256, ethers, ZeroHash, MaxUint256 } from 'ethers';
1
+ import { Contract, ZeroAddress, AbiCoder, TypedDataEncoder, keccak256, solidityPackedKeccak256, ethers, getAddress, ZeroHash, MaxUint256 } from 'ethers';
2
2
  import { HypercertExchangeAbi, TransferManagerAbi, OrderValidatorV2AAbi, deployments, asDeployedChain as asDeployedChain$2 } from '@hypercerts-org/contracts';
3
3
  import { MerkleTree } from 'merkletreejs';
4
4
  import { keccak256 as keccak256$1 } from 'js-sha3';
@@ -682,6 +682,8 @@ var strategies = /*#__PURE__*/Object.freeze({
682
682
  strategyInfo: strategyInfo
683
683
  });
684
684
 
685
+ /** All possible supported currencies */
686
+ const SUPPORTED_CURRENCIES = ["ETH", "WETH", "DAI", "CELO", "cUSD", "USDT", "USDC"];
685
687
  /** List of supported chains */
686
688
  var ChainId;
687
689
  (function (ChainId) {
@@ -690,8 +692,8 @@ var ChainId;
690
692
  ChainId[ChainId["HARDHAT"] = 31337] = "HARDHAT";
691
693
  ChainId[ChainId["OPTIMISM"] = 10] = "OPTIMISM";
692
694
  ChainId[ChainId["CELO"] = 42220] = "CELO";
693
- ChainId[ChainId["BASE"] = 8453] = "BASE";
694
695
  ChainId[ChainId["ARBITRUM_SEPOLIA"] = 421614] = "ARBITRUM_SEPOLIA";
696
+ ChainId[ChainId["ARBITRUM"] = 42161] = "ARBITRUM";
695
697
  })(ChainId || (ChainId = {}));
696
698
  /** List of collection types supported by the protocol */
697
699
  var CollectionType;
@@ -1096,48 +1098,46 @@ var asDeployedChain$1 = /*#__PURE__*/Object.freeze({
1096
1098
  asDeployedChain: asDeployedChain
1097
1099
  });
1098
1100
 
1099
- const sepoliaAddresses = {
1100
- EXCHANGE_V2: deployments[11155111].HypercertExchange,
1101
- TRANSFER_MANAGER_V2: deployments[11155111].TransferManager,
1102
- ORDER_VALIDATOR_V2: deployments[11155111].OrderValidatorV2A,
1103
- MINTER: deployments[11155111].HypercertMinterUUPS,
1104
- };
1105
- const baseSepoliaAddresses = {
1106
- EXCHANGE_V2: deployments[84532].HypercertExchange,
1107
- TRANSFER_MANAGER_V2: deployments[84532].TransferManager,
1108
- ORDER_VALIDATOR_V2: deployments[84532].OrderValidatorV2A,
1109
- MINTER: deployments[84532].HypercertMinterUUPS,
1110
- };
1111
- const optimismAddresses = {
1112
- EXCHANGE_V2: deployments[10].HypercertExchange,
1113
- TRANSFER_MANAGER_V2: deployments[10].TransferManager,
1114
- ORDER_VALIDATOR_V2: deployments[10].OrderValidatorV2A,
1115
- MINTER: deployments[10].HypercertMinterUUPS,
1116
- };
1117
- const celoAddresses = {
1118
- EXCHANGE_V2: deployments[42220].HypercertExchange,
1119
- TRANSFER_MANAGER_V2: deployments[42220].TransferManager,
1120
- ORDER_VALIDATOR_V2: deployments[42220].OrderValidatorV2A,
1121
- MINTER: deployments[42220].HypercertMinterUUPS,
1122
- };
1123
- const baseAddresses = {
1124
- EXCHANGE_V2: deployments[8453].HypercertExchange,
1125
- TRANSFER_MANAGER_V2: deployments[8453].TransferManager,
1126
- ORDER_VALIDATOR_V2: deployments[8453].OrderValidatorV2A,
1127
- MINTER: deployments[8453].HypercertMinterUUPS,
1101
+ function getRequiredAddress(chainId, contractName) {
1102
+ const chainIdStr = chainId.toString();
1103
+ const deployment = deployments[chainIdStr];
1104
+ if (!deployment) {
1105
+ throw new Error(`Missing deployment for chain ${chainId}`);
1106
+ }
1107
+ const address = deployment[contractName];
1108
+ if (!address) {
1109
+ throw new Error(`Missing required address for ${contractName} on chain ${chainId}`);
1110
+ }
1111
+ return getAddress(address);
1112
+ }
1113
+ // Helper function to create addresses for a network
1114
+ const createNetworkAddresses = (chainId) => ({
1115
+ EXCHANGE_V2: getRequiredAddress(chainId, "HypercertExchange"),
1116
+ TRANSFER_MANAGER_V2: getRequiredAddress(chainId, "TransferManager"),
1117
+ ORDER_VALIDATOR_V2: getRequiredAddress(chainId, "OrderValidatorV2A"),
1118
+ MINTER: getRequiredAddress(chainId, "HypercertMinterUUPS"),
1119
+ });
1120
+ // Network chain IDs
1121
+ const CHAIN_IDS = {
1122
+ // Testnets
1123
+ SEPOLIA: 11155111,
1124
+ BASE_SEPOLIA: 84532,
1125
+ ARBITRUM_SEPOLIA: 421614,
1126
+ // Mainnets
1127
+ OPTIMISM: 10,
1128
+ CELO: 42220,
1129
+ ARBITRUM: 42161,
1128
1130
  };
1129
- /**
1130
- * List of useful contract addresses
1131
- */
1132
1131
  const addressesByNetwork = {
1133
1132
  // Testnets
1134
- [ChainId.SEPOLIA]: sepoliaAddresses,
1135
- [ChainId.HARDHAT]: sepoliaAddresses,
1136
- [ChainId.BASE_SEPOLIA]: baseSepoliaAddresses,
1133
+ [ChainId.SEPOLIA]: createNetworkAddresses(CHAIN_IDS.SEPOLIA),
1134
+ [ChainId.HARDHAT]: createNetworkAddresses(CHAIN_IDS.SEPOLIA), // Using Sepolia for Hardhat
1135
+ [ChainId.BASE_SEPOLIA]: createNetworkAddresses(CHAIN_IDS.BASE_SEPOLIA),
1136
+ [ChainId.ARBITRUM_SEPOLIA]: createNetworkAddresses(CHAIN_IDS.ARBITRUM_SEPOLIA),
1137
1137
  // Production nets
1138
- [ChainId.OPTIMISM]: optimismAddresses,
1139
- [ChainId.CELO]: celoAddresses,
1140
- [ChainId.BASE]: baseAddresses,
1138
+ [ChainId.OPTIMISM]: createNetworkAddresses(CHAIN_IDS.OPTIMISM),
1139
+ [ChainId.CELO]: createNetworkAddresses(CHAIN_IDS.CELO),
1140
+ [ChainId.ARBITRUM]: createNetworkAddresses(CHAIN_IDS.ARBITRUM),
1141
1141
  };
1142
1142
 
1143
1143
  const currencyAddressesPerChain = {
@@ -1172,34 +1172,53 @@ const currencyAddressesPerChain = {
1172
1172
  USDC: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
1173
1173
  },
1174
1174
  [ChainId.CELO]: {
1175
- ETH: ZeroAddress,
1176
- WETH: "0x66803fb87abd4aac3cbb3fad7c3aa01f6f3fb207",
1177
- DAI: "0xE4fE50cdD716522A56204352f00AA110F731932d",
1178
- USDC: "0xef4229c8c3250C675F21BCefa42f58EfbfF6002a",
1175
+ CELO: "0x471EcE3750Da237f93B8E339c536989b8978a438",
1176
+ cUSD: "0x765DE816845861e75A25fCA122bb6898B8B1282a",
1177
+ USDC: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
1178
+ USDT: "0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e",
1179
1179
  },
1180
- [ChainId.BASE]: {
1180
+ [ChainId.ARBITRUM]: {
1181
1181
  ETH: ZeroAddress,
1182
- WETH: "0x4200000000000000000000000000000000000006",
1183
- DAI: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
1184
- USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
1182
+ WETH: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
1183
+ DAI: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
1184
+ USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
1185
1185
  },
1186
1186
  };
1187
1187
  const getCurrencies = (chainId) => {
1188
1188
  const currenciesForChain = currencyAddressesPerChain[chainId];
1189
+ if ("ETH" in currenciesForChain) {
1190
+ return {
1191
+ ETH: {
1192
+ symbol: "ETH",
1193
+ address: currenciesForChain.ETH,
1194
+ decimals: 18,
1195
+ },
1196
+ WETH: {
1197
+ symbol: "WETH",
1198
+ address: currenciesForChain.WETH,
1199
+ decimals: 18,
1200
+ },
1201
+ DAI: {
1202
+ symbol: "DAI",
1203
+ address: currenciesForChain.DAI,
1204
+ decimals: 18,
1205
+ },
1206
+ USDC: {
1207
+ symbol: "USDC",
1208
+ address: currenciesForChain.USDC,
1209
+ decimals: 6,
1210
+ },
1211
+ };
1212
+ }
1189
1213
  return {
1190
- ETH: {
1191
- symbol: "ETH",
1192
- address: currenciesForChain.ETH,
1193
- decimals: 18,
1194
- },
1195
- WETH: {
1196
- symbol: "WETH",
1197
- address: currenciesForChain.WETH,
1214
+ CELO: {
1215
+ symbol: "CELO",
1216
+ address: currenciesForChain.CELO,
1198
1217
  decimals: 18,
1199
1218
  },
1200
- DAI: {
1201
- symbol: "DAI",
1202
- address: currenciesForChain.DAI,
1219
+ cUSD: {
1220
+ symbol: "cUSD",
1221
+ address: currenciesForChain.cUSD,
1203
1222
  decimals: 18,
1204
1223
  },
1205
1224
  USDC: {
@@ -1207,6 +1226,11 @@ const getCurrencies = (chainId) => {
1207
1226
  address: currenciesForChain.USDC,
1208
1227
  decimals: 6,
1209
1228
  },
1229
+ USDT: {
1230
+ symbol: "USDT",
1231
+ address: currenciesForChain.USDT,
1232
+ decimals: 6,
1233
+ },
1210
1234
  };
1211
1235
  };
1212
1236
  const currenciesByNetwork = {
@@ -1215,8 +1239,8 @@ const currenciesByNetwork = {
1215
1239
  [ChainId.BASE_SEPOLIA]: getCurrencies(ChainId.BASE_SEPOLIA),
1216
1240
  [ChainId.OPTIMISM]: getCurrencies(ChainId.OPTIMISM),
1217
1241
  [ChainId.CELO]: getCurrencies(ChainId.CELO),
1218
- [ChainId.BASE]: getCurrencies(ChainId.BASE),
1219
1242
  [ChainId.ARBITRUM_SEPOLIA]: getCurrencies(ChainId.ARBITRUM_SEPOLIA),
1243
+ [ChainId.ARBITRUM]: getCurrencies(ChainId.ARBITRUM),
1220
1244
  };
1221
1245
 
1222
1246
  const chainInfo = {
@@ -1244,6 +1268,14 @@ const chainInfo = {
1244
1268
  baseApiUrl: "https://staging-api.hypercerts.org",
1245
1269
  osApiUrl: "https://testnets-api.opensea.io"
1246
1270
  },
1271
+ [ChainId.ARBITRUM]: {
1272
+ label: "Arbitrum",
1273
+ appUrl: "https://app.hypercerts.org",
1274
+ explorer: "https://arbitrum.io",
1275
+ rpcUrl: "https://arbitrum.io",
1276
+ baseApiUrl: "https://api.hypercerts.org",
1277
+ osApiUrl: "https://testnets-api.opensea.io"
1278
+ },
1247
1279
  [ChainId.ARBITRUM_SEPOLIA]: {
1248
1280
  label: "Arbitrum Sepolia",
1249
1281
  appUrl: "https://testnet.hypercerts.org",
@@ -1268,14 +1300,6 @@ const chainInfo = {
1268
1300
  baseApiUrl: "https://api.hypercerts.org",
1269
1301
  osApiUrl: "https://testnets-api.opensea.io"
1270
1302
  },
1271
- [ChainId.BASE]: {
1272
- label: "Base",
1273
- appUrl: "https://app.hypercerts.org",
1274
- explorer: "https://basescan.io",
1275
- rpcUrl: "https://mainnet.base.org",
1276
- baseApiUrl: "https://api.hypercerts.org",
1277
- osApiUrl: "https://testnets-api.opensea.io"
1278
- }
1279
1303
  };
1280
1304
 
1281
1305
  /** Maximum amount of orders in a merkle tree
@@ -1330,6 +1354,13 @@ class ErrorItemId extends Error {
1330
1354
  this.name = "ErrorItemId";
1331
1355
  }
1332
1356
  }
1357
+ /** Currency is not supported */
1358
+ class ErrorCurrency extends Error {
1359
+ constructor() {
1360
+ super("Currency is not defined or supported");
1361
+ this.name = "ErrorCurrency";
1362
+ }
1363
+ }
1333
1364
 
1334
1365
  var IERC1155 = [
1335
1366
  {
@@ -7754,11 +7785,14 @@ class HypercertExchangeClient {
7754
7785
  * @param CreateMakerInput
7755
7786
  * @returns the maker object, isCurrencyApproved, and isBalanceSufficient
7756
7787
  */
7757
- async createMakerBid({ collection, strategyId, collectionType, subsetNonce, orderNonce, endTime, price, itemIds, amounts = [1], currency = this.currencies.WETH.address, startTime = Math.floor(Date.now() / 1000), additionalParameters = [], }) {
7788
+ async createMakerBid({ collection, strategyId, collectionType, subsetNonce, orderNonce, endTime, price, itemIds, amounts = [1], currency, startTime = Math.floor(Date.now() / 1000), additionalParameters = [], }) {
7758
7789
  const signer = this.getSigner();
7759
7790
  if (!this.isTimestampValid(startTime) || !this.isTimestampValid(endTime)) {
7760
7791
  throw new ErrorTimestamp();
7761
7792
  }
7793
+ if (!currency) {
7794
+ throw new ErrorCurrency();
7795
+ }
7762
7796
  const signerAddress = await signer.getAddress();
7763
7797
  const spenderAddress = this.addresses.EXCHANGE_V2;
7764
7798
  // Use this.provider (MulticallProvider) in order to batch the calls
@@ -8102,11 +8136,14 @@ class HypercertExchangeClient {
8102
8136
  * @param currency Currency used to buy the fractions (default to WETH)
8103
8137
  * @param additionalParameters Additional parameters used to support complex orders
8104
8138
  */
8105
- async createDirectFractionsSaleMakerAsk({ itemIds, price, startTime, endTime, currency = this.currencies.WETH.address, additionalParameters = [], }) {
8139
+ async createDirectFractionsSaleMakerAsk({ itemIds, price, startTime, endTime, currency, additionalParameters = [], }) {
8106
8140
  const address = await this.signer?.getAddress();
8107
8141
  if (!address) {
8108
8142
  throw new Error("No signer address could be determined");
8109
8143
  }
8144
+ if (!currency) {
8145
+ throw new ErrorCurrency();
8146
+ }
8110
8147
  const chainId = this.chainId;
8111
8148
  const { nonce_counter } = await this.api.fetchOrderNonce({
8112
8149
  address,
@@ -8143,11 +8180,14 @@ class HypercertExchangeClient {
8143
8180
  * @param sellLeftoverFraction Whether or not the seller wants to sell the leftover units
8144
8181
  * @param root Merkle tree root (optional)
8145
8182
  */
8146
- async createFractionalSaleMakerAsk({ itemIds, price, startTime, endTime, currency = this.currencies.WETH.address, maxUnitAmount, minUnitAmount, minUnitsToKeep, sellLeftoverFraction, root, }) {
8183
+ async createFractionalSaleMakerAsk({ itemIds, price, startTime, endTime, currency, maxUnitAmount, minUnitAmount, minUnitsToKeep, sellLeftoverFraction, root, }) {
8147
8184
  const address = await this.signer?.getAddress();
8148
8185
  if (!address) {
8149
8186
  throw new Error("No signer address could be determined");
8150
8187
  }
8188
+ if (!currency) {
8189
+ throw new ErrorCurrency();
8190
+ }
8151
8191
  const chainId = this.chainId;
8152
8192
  const { nonce_counter } = await this.api.fetchOrderNonce({
8153
8193
  address,
@@ -8240,4 +8280,4 @@ const utils = {
8240
8280
  ...asDeployedChain$1,
8241
8281
  };
8242
8282
 
8243
- export { ApiClient, ChainId, CollectionType, Eip712MakerMerkleTree, Eip712MerkleTree, ErrorItemId, ErrorMerkleTreeDepth, ErrorQuoteType, ErrorSigner, ErrorStrategyType, ErrorTimestamp, HypercertExchangeClient, IERC1155 as IERC1155Abi, abiIERC20 as IERC20Abi, abiIERC721 as IERC721Abi, LooksRareProtocol as LooksRareProtocolAbi, MAX_ORDERS_PER_TREE, MerkleTreeNodePosition, OrderValidatorCode, OrderValidatorV2A as OrderValidatorV2AAbi, QuoteType, StrategyType, TransferManager as TransferManagerAbi, WETH as WETHAbi, addressesByNetwork, chainInfo, currenciesByNetwork, defaultMerkleTree, utils };
8283
+ export { ApiClient, ChainId, CollectionType, Eip712MakerMerkleTree, Eip712MerkleTree, ErrorCurrency, ErrorItemId, ErrorMerkleTreeDepth, ErrorQuoteType, ErrorSigner, ErrorStrategyType, ErrorTimestamp, HypercertExchangeClient, IERC1155 as IERC1155Abi, abiIERC20 as IERC20Abi, abiIERC721 as IERC721Abi, LooksRareProtocol as LooksRareProtocolAbi, MAX_ORDERS_PER_TREE, MerkleTreeNodePosition, OrderValidatorCode, OrderValidatorV2A as OrderValidatorV2AAbi, QuoteType, SUPPORTED_CURRENCIES, StrategyType, TransferManager as TransferManagerAbi, WETH as WETHAbi, addressesByNetwork, chainInfo, currenciesByNetwork, defaultMerkleTree, utils };
package/dist/types.d.ts CHANGED
@@ -7,19 +7,17 @@ export interface Addresses {
7
7
  ORDER_VALIDATOR_V2: `0x${string}`;
8
8
  MINTER: `0x${string}`;
9
9
  }
10
- /** List of supported currencies */
11
- export interface Currencies {
12
- ETH: Currency;
13
- WETH: Currency;
14
- USDC: Currency;
15
- DAI: Currency;
16
- }
17
10
  /** Available information about a currency */
18
11
  export interface Currency {
19
12
  symbol: string;
20
13
  address: `0x${string}`;
21
14
  decimals: number;
22
15
  }
16
+ /** All possible supported currencies */
17
+ export declare const SUPPORTED_CURRENCIES: readonly ["ETH", "WETH", "DAI", "CELO", "cUSD", "USDT", "USDC"];
18
+ export type SupportedCurrencySymbol = (typeof SUPPORTED_CURRENCIES)[number];
19
+ /** Type for currency configuration */
20
+ export type Currencies = Partial<Record<SupportedCurrencySymbol, Currency>>;
23
21
  /** List of supported chains */
24
22
  export declare enum ChainId {
25
23
  SEPOLIA = 11155111,
@@ -27,8 +25,8 @@ export declare enum ChainId {
27
25
  HARDHAT = 31337,
28
26
  OPTIMISM = 10,
29
27
  CELO = 42220,
30
- BASE = 8453,
31
- ARBITRUM_SEPOLIA = 421614
28
+ ARBITRUM_SEPOLIA = 421614,
29
+ ARBITRUM = 42161
32
30
  }
33
31
  /** ChainInfo data used to interact with HypercertExchange ecosystem */
34
32
  export interface ChainInfo {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypercerts-org/marketplace-sdk",
3
- "version": "0.3.35",
3
+ "version": "0.3.37",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -24,6 +24,20 @@
24
24
  "engines": {
25
25
  "node": ">= 16.15.1 <= 20.x"
26
26
  },
27
+ "scripts": {
28
+ "prebuild": "rm -rf ./src/typechain ./src/artifacts cache dist",
29
+ "dev": "rollup -c --bundleConfigAsCjs -w",
30
+ "build:ts": "rollup -c --bundleConfigAsCjs",
31
+ "build:sc": "hardhat compile",
32
+ "build": "yarn build:sc && yarn build:ts",
33
+ "test": "nyc hardhat test",
34
+ "doc": "typedoc --plugin typedoc-plugin-markdown --tsconfig tsconfig.build.json",
35
+ "lint": "eslint --max-warnings 0 'src/**/*.{js,ts}'",
36
+ "format:check": "prettier --check 'src/**/*.{js,ts,json,yaml,yml,md}'",
37
+ "format:write": "prettier --write 'src/**/*.{js,ts,json,yaml,yml,md}'",
38
+ "release": "release-it --only-version --set-upstream",
39
+ "supabase:types:hypercerts": "npx supabase gen types typescript --project-id zgvoyckkistexkfdmjqc --schema public > src/utils/hypercerts-database-types.ts"
40
+ },
27
41
  "lint-staged": {
28
42
  "*.{js,jsx,ts,tsx,json,yaml,yml}": "yarn format:write"
29
43
  },
@@ -34,7 +48,7 @@
34
48
  "@0no-co/graphqlsp": "^1.12.8",
35
49
  "@commitlint/cli": "^17.0.2",
36
50
  "@commitlint/config-conventional": "^17.0.2",
37
- "@hypercerts-org/contracts": "2.0.0-alpha.8",
51
+ "@hypercerts-org/contracts": "2.0.0-alpha.11",
38
52
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
39
53
  "@looksrare/contracts-exchange-v1": "^1.2.0",
40
54
  "@looksrare/contracts-exchange-v2": "^0.1.2",
@@ -79,25 +93,11 @@
79
93
  "typescript": "^5.3.3"
80
94
  },
81
95
  "dependencies": {
82
- "@hypercerts-org/sdk": "2.1.1",
96
+ "@hypercerts-org/sdk": "2.3.0",
83
97
  "@supabase/supabase-js": "^2.39.2",
84
98
  "@urql/core": "^5.0.4",
85
99
  "ethers": "^6.6.2",
86
100
  "gql.tada": "^1.7.6",
87
101
  "merkletreejs": "^0.3.9"
88
- },
89
- "scripts": {
90
- "prebuild": "rm -rf ./src/typechain ./src/artifacts cache dist",
91
- "dev": "rollup -c --bundleConfigAsCjs -w",
92
- "build:ts": "rollup -c --bundleConfigAsCjs",
93
- "build:sc": "hardhat compile",
94
- "build": "yarn build:sc && yarn build:ts",
95
- "test": "nyc hardhat test",
96
- "doc": "typedoc --plugin typedoc-plugin-markdown --tsconfig tsconfig.build.json",
97
- "lint": "eslint --max-warnings 0 'src/**/*.{js,ts}'",
98
- "format:check": "prettier --check 'src/**/*.{js,ts,json,yaml,yml,md}'",
99
- "format:write": "prettier --write 'src/**/*.{js,ts,json,yaml,yml,md}'",
100
- "release": "release-it --only-version --set-upstream",
101
- "supabase:types:hypercerts": "npx supabase gen types typescript --project-id zgvoyckkistexkfdmjqc --schema public > src/utils/hypercerts-database-types.ts"
102
102
  }
103
- }
103
+ }