polkamarkets-js 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ /** @type import('hardhat/config').HardhatUserConfig */
2
+ module.exports = {
3
+ solidity: "0.8.27",
4
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polkamarkets-js",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -168,7 +168,26 @@ class PredictionMarketV3Contract extends PredictionMarketV2Contract {
168
168
  // should be non-blocking
169
169
  }
170
170
 
171
- const userMarketsData = await this.querier.getUserAllMarketsData({ user });
171
+ const chunkSize = 250;
172
+ let userMarketsData;
173
+
174
+ // chunking data to avoid out of gas errors
175
+ const marketIndex = await this.getMarketIndex();
176
+
177
+ if (marketIndex > chunkSize) {
178
+ const chunks = Math.ceil(marketIndex / chunkSize);
179
+ const promises = Array.from({ length: chunks }, async (_, i) => {
180
+ const marketIds = Array.from({ length: chunkSize }, (_, j) => i * chunkSize + j).filter(id => id < marketIndex);
181
+ const chunkMarketData = await this.querier.getUserMarketsData({ user, marketIds });
182
+ return chunkMarketData;
183
+ });
184
+ const chunksData = await Promise.all(promises);
185
+ // concatenating all arrays into a single one
186
+ userMarketsData = chunksData.reduce((obj, chunk) => [...obj, ...chunk], []);
187
+ } else {
188
+ userMarketsData = await this.querier.getUserAllMarketsData({ user });
189
+ }
190
+
172
191
  const marketIds = Object.keys(userMarketsData).map(Number);
173
192
  // fetching all markets decimals asynchrounously
174
193
  const marketDecimals = await Promise.all(marketIds.map(marketId => this.getMarketDecimals({ marketId })));
@@ -228,6 +247,10 @@ class PredictionMarketV3Contract extends PredictionMarketV2Contract {
228
247
  false,
229
248
  );
230
249
  }
250
+
251
+ async getMarketIndex() {
252
+ return parseInt(await this.getContract().methods.marketIndex().call());
253
+ }
231
254
  }
232
255
 
233
256
  module.exports = PredictionMarketV3Contract;
@@ -8,12 +8,12 @@ class PredictionMarketV3QuerierContract extends IContract {
8
8
  this.contractName = 'PredictionMarketV3Querier';
9
9
  }
10
10
 
11
- async getUserMarketsData({ user, marketId }) {
12
- return await this.params.contract.getContract().methods.getUserMarketData(user, marketId).call();
11
+ async getUserMarketData({ user, marketId }) {
12
+ return await this.params.contract.getContract().methods.getUserMarketData(marketId, user).call();
13
13
  }
14
14
 
15
15
  async getUserMarketsData({ user, marketIds }) {
16
- return await this.params.contract.getContract().methods.getUserMarketsData(user, marketIds).call();
16
+ return await this.params.contract.getContract().methods.getUserMarketsData(marketIds, user).call();
17
17
  }
18
18
 
19
19
  async getUserAllMarketsData({ user }) {