@aurigami/sdk 1.11.0 → 1.11.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.
@@ -8,6 +8,7 @@ export declare function formatObject(object: Object): string;
8
8
  export declare function decimalFactor(decimal: number): string;
9
9
  export declare const isSameAddress: (address1: Address, address2: Address) => boolean;
10
10
  export declare const getCurrentTimestamp: () => number;
11
+ export declare function sleep(duration: number): Promise<void>;
11
12
  export declare function validateAndParseAddress(address: Address): Address;
12
13
  export declare function getDecimal(address: Address): number;
13
14
  export declare function getSymbol(address: Address): string;
@@ -1212,6 +1212,30 @@ var isSameAddress = function isSameAddress(address1, address2) {
1212
1212
  var getCurrentTimestamp = function getCurrentTimestamp() {
1213
1213
  return Math.trunc(Date.now() / 1000);
1214
1214
  };
1215
+ function sleep(_x) {
1216
+ return _sleep.apply(this, arguments);
1217
+ }
1218
+
1219
+ function _sleep() {
1220
+ _sleep = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(duration) {
1221
+ return runtime_1.wrap(function _callee$(_context) {
1222
+ while (1) {
1223
+ switch (_context.prev = _context.next) {
1224
+ case 0:
1225
+ return _context.abrupt("return", new Promise(function (resolve) {
1226
+ setTimeout(resolve, duration);
1227
+ }));
1228
+
1229
+ case 1:
1230
+ case "end":
1231
+ return _context.stop();
1232
+ }
1233
+ }
1234
+ }, _callee);
1235
+ }));
1236
+ return _sleep.apply(this, arguments);
1237
+ }
1238
+
1215
1239
  function validateAndParseAddress(address) {
1216
1240
  try {
1217
1241
  return ethers.utils.getAddress(address);
@@ -1253,35 +1277,35 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1253
1277
 
1254
1278
  return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
1255
1279
  }
1256
- function getBlockTimestamp(_x, _x2) {
1280
+ function getBlockTimestamp(_x2, _x3) {
1257
1281
  return _getBlockTimestamp.apply(this, arguments);
1258
1282
  }
1259
1283
 
1260
1284
  function _getBlockTimestamp() {
1261
- _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(provider, blockNumber) {
1285
+ _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, blockNumber) {
1262
1286
  var block;
1263
- return runtime_1.wrap(function _callee$(_context) {
1287
+ return runtime_1.wrap(function _callee2$(_context2) {
1264
1288
  while (1) {
1265
- switch (_context.prev = _context.next) {
1289
+ switch (_context2.prev = _context2.next) {
1266
1290
  case 0:
1267
- _context.next = 2;
1291
+ _context2.next = 2;
1268
1292
  return provider.getBlock(blockNumber);
1269
1293
 
1270
1294
  case 2:
1271
- block = _context.sent;
1272
- return _context.abrupt("return", block.timestamp);
1295
+ block = _context2.sent;
1296
+ return _context2.abrupt("return", block.timestamp);
1273
1297
 
1274
1298
  case 4:
1275
1299
  case "end":
1276
- return _context.stop();
1300
+ return _context2.stop();
1277
1301
  }
1278
1302
  }
1279
- }, _callee);
1303
+ }, _callee2);
1280
1304
  }));
1281
1305
  return _getBlockTimestamp.apply(this, arguments);
1282
1306
  }
1283
1307
 
1284
- function getBlocksTimestampViaRPC(_x3, _x4) {
1308
+ function getBlocksTimestampViaRPC(_x4, _x5) {
1285
1309
  return _getBlocksTimestampViaRPC.apply(this, arguments);
1286
1310
  }
1287
1311
  /**
@@ -1291,11 +1315,11 @@ function getBlocksTimestampViaRPC(_x3, _x4) {
1291
1315
  */
1292
1316
 
1293
1317
  function _getBlocksTimestampViaRPC() {
1294
- _getBlocksTimestampViaRPC = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(provider, blocksNumber) {
1318
+ _getBlocksTimestampViaRPC = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(provider, blocksNumber) {
1295
1319
  var CHUNK_SIZE, results, i, slice, promises;
1296
- return runtime_1.wrap(function _callee3$(_context3) {
1320
+ return runtime_1.wrap(function _callee4$(_context4) {
1297
1321
  while (1) {
1298
- switch (_context3.prev = _context3.next) {
1322
+ switch (_context4.prev = _context4.next) {
1299
1323
  case 0:
1300
1324
  // Promise all 200 blocks at a time, using too many blocks at once will cause the RPC call timeout.
1301
1325
  CHUNK_SIZE = 200;
@@ -1304,58 +1328,58 @@ function _getBlocksTimestampViaRPC() {
1304
1328
 
1305
1329
  case 3:
1306
1330
  if (!(i < blocksNumber.length)) {
1307
- _context3.next = 14;
1331
+ _context4.next = 14;
1308
1332
  break;
1309
1333
  }
1310
1334
 
1311
1335
  slice = blocksNumber.slice(i, i + CHUNK_SIZE);
1312
1336
  promises = slice.map( /*#__PURE__*/function () {
1313
- var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(blockNumber) {
1314
- return runtime_1.wrap(function _callee2$(_context2) {
1337
+ var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(blockNumber) {
1338
+ return runtime_1.wrap(function _callee3$(_context3) {
1315
1339
  while (1) {
1316
- switch (_context2.prev = _context2.next) {
1340
+ switch (_context3.prev = _context3.next) {
1317
1341
  case 0:
1318
- return _context2.abrupt("return", getBlockTimestamp(provider, blockNumber));
1342
+ return _context3.abrupt("return", getBlockTimestamp(provider, blockNumber));
1319
1343
 
1320
1344
  case 1:
1321
1345
  case "end":
1322
- return _context2.stop();
1346
+ return _context3.stop();
1323
1347
  }
1324
1348
  }
1325
- }, _callee2);
1349
+ }, _callee3);
1326
1350
  }));
1327
1351
 
1328
- return function (_x9) {
1352
+ return function (_x10) {
1329
1353
  return _ref.apply(this, arguments);
1330
1354
  };
1331
1355
  }());
1332
- _context3.t0 = results;
1333
- _context3.next = 9;
1356
+ _context4.t0 = results;
1357
+ _context4.next = 9;
1334
1358
  return Promise.all(promises);
1335
1359
 
1336
1360
  case 9:
1337
- _context3.t1 = _context3.sent;
1338
- results = _context3.t0.concat.call(_context3.t0, _context3.t1);
1361
+ _context4.t1 = _context4.sent;
1362
+ results = _context4.t0.concat.call(_context4.t0, _context4.t1);
1339
1363
 
1340
1364
  case 11:
1341
1365
  i += CHUNK_SIZE;
1342
- _context3.next = 3;
1366
+ _context4.next = 3;
1343
1367
  break;
1344
1368
 
1345
1369
  case 14:
1346
- return _context3.abrupt("return", results);
1370
+ return _context4.abrupt("return", results);
1347
1371
 
1348
1372
  case 15:
1349
1373
  case "end":
1350
- return _context3.stop();
1374
+ return _context4.stop();
1351
1375
  }
1352
1376
  }
1353
- }, _callee3);
1377
+ }, _callee4);
1354
1378
  }));
1355
1379
  return _getBlocksTimestampViaRPC.apply(this, arguments);
1356
1380
  }
1357
1381
 
1358
- function getBlocksTimestamp(_x5, _x6) {
1382
+ function getBlocksTimestamp(_x6, _x7) {
1359
1383
  return _getBlocksTimestamp.apply(this, arguments);
1360
1384
  }
1361
1385
  /**
@@ -1368,18 +1392,18 @@ function getBlocksTimestamp(_x5, _x6) {
1368
1392
  */
1369
1393
 
1370
1394
  function _getBlocksTimestamp() {
1371
- _getBlocksTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(provider, blockNumbers) {
1395
+ _getBlocksTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(provider, blockNumbers) {
1372
1396
  var CHUNK_SIZE, promises, lines, i, query, results, missingBlocks, missingBlocksTimestamps;
1373
- return runtime_1.wrap(function _callee4$(_context4) {
1397
+ return runtime_1.wrap(function _callee5$(_context5) {
1374
1398
  while (1) {
1375
- switch (_context4.prev = _context4.next) {
1399
+ switch (_context5.prev = _context5.next) {
1376
1400
  case 0:
1377
1401
  if (!(blockNumbers.length == 0)) {
1378
- _context4.next = 2;
1402
+ _context5.next = 2;
1379
1403
  break;
1380
1404
  }
1381
1405
 
1382
- return _context4.abrupt("return", []);
1406
+ return _context5.abrupt("return", []);
1383
1407
 
1384
1408
  case 2:
1385
1409
  CHUNK_SIZE = 100; // graphql query limit
@@ -1395,11 +1419,11 @@ function _getBlocksTimestamp() {
1395
1419
  } // merge all the json objects
1396
1420
 
1397
1421
 
1398
- _context4.next = 8;
1422
+ _context5.next = 8;
1399
1423
  return Promise.all(promises);
1400
1424
 
1401
1425
  case 8:
1402
- results = _context4.sent.reduce(function (acc, cur) {
1426
+ results = _context5.sent.reduce(function (acc, cur) {
1403
1427
  return _extends({}, acc, cur);
1404
1428
  });
1405
1429
  missingBlocks = blockNumbers.filter(function (blockNumber) {
@@ -1410,71 +1434,71 @@ function _getBlocksTimestamp() {
1410
1434
  devLog("These blocks are missing from Aurora GraphQL endpoint: " + missingBlocks.join(', '));
1411
1435
  }
1412
1436
 
1413
- _context4.next = 13;
1437
+ _context5.next = 13;
1414
1438
  return getBlocksTimestampViaRPC(provider, missingBlocks);
1415
1439
 
1416
1440
  case 13:
1417
- missingBlocksTimestamps = _context4.sent;
1441
+ missingBlocksTimestamps = _context5.sent;
1418
1442
  missingBlocksTimestamps.forEach(function (timestamp, index) {
1419
1443
  results["b" + missingBlocks[index]] = {
1420
1444
  timestamp: new Date(timestamp * 1000).toISOString()
1421
1445
  };
1422
1446
  });
1423
- return _context4.abrupt("return", blockNumbers.map(function (blockNumber) {
1447
+ return _context5.abrupt("return", blockNumbers.map(function (blockNumber) {
1424
1448
  return Math.trunc(new Date(results["b" + blockNumber].timestamp).getTime() / 1000);
1425
1449
  }));
1426
1450
 
1427
1451
  case 16:
1428
1452
  case "end":
1429
- return _context4.stop();
1453
+ return _context5.stop();
1430
1454
  }
1431
1455
  }
1432
- }, _callee4);
1456
+ }, _callee5);
1433
1457
  }));
1434
1458
  return _getBlocksTimestamp.apply(this, arguments);
1435
1459
  }
1436
1460
 
1437
- function getBlockBeforeTimestamp(_x7, _x8) {
1461
+ function getBlockBeforeTimestamp(_x8, _x9) {
1438
1462
  return _getBlockBeforeTimestamp.apply(this, arguments);
1439
1463
  }
1440
1464
 
1441
1465
  function _getBlockBeforeTimestamp() {
1442
- _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(provider, timestamp) {
1466
+ _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(provider, timestamp) {
1443
1467
  var result;
1444
- return runtime_1.wrap(function _callee5$(_context5) {
1468
+ return runtime_1.wrap(function _callee6$(_context6) {
1445
1469
  while (1) {
1446
- switch (_context5.prev = _context5.next) {
1470
+ switch (_context6.prev = _context6.next) {
1447
1471
  case 0:
1448
- _context5.next = 2;
1472
+ _context6.next = 2;
1449
1473
  return getQuery('block', 'getblocknobytime', {
1450
1474
  timestamp: timestamp,
1451
1475
  closest: 'before'
1452
1476
  });
1453
1477
 
1454
1478
  case 2:
1455
- result = _context5.sent;
1456
- _context5.t0 = parseInt(result);
1479
+ result = _context6.sent;
1480
+ _context6.t0 = parseInt(result);
1457
1481
 
1458
- if (_context5.t0) {
1459
- _context5.next = 8;
1482
+ if (_context6.t0) {
1483
+ _context6.next = 8;
1460
1484
  break;
1461
1485
  }
1462
1486
 
1463
- _context5.next = 7;
1487
+ _context6.next = 7;
1464
1488
  return provider.getBlockNumber();
1465
1489
 
1466
1490
  case 7:
1467
- _context5.t0 = _context5.sent;
1491
+ _context6.t0 = _context6.sent;
1468
1492
 
1469
1493
  case 8:
1470
- return _context5.abrupt("return", _context5.t0);
1494
+ return _context6.abrupt("return", _context6.t0);
1471
1495
 
1472
1496
  case 9:
1473
1497
  case "end":
1474
- return _context5.stop();
1498
+ return _context6.stop();
1475
1499
  }
1476
1500
  }
1477
- }, _callee5);
1501
+ }, _callee6);
1478
1502
  }));
1479
1503
  return _getBlockBeforeTimestamp.apply(this, arguments);
1480
1504
  }
@@ -2602,6 +2626,7 @@ var helpers = {
2602
2626
  decimalFactor: decimalFactor,
2603
2627
  isSameAddress: isSameAddress,
2604
2628
  getCurrentTimestamp: getCurrentTimestamp,
2629
+ sleep: sleep,
2605
2630
  validateAndParseAddress: validateAndParseAddress,
2606
2631
  getDecimal: getDecimal,
2607
2632
  getSymbol: getSymbol,
@@ -4839,16 +4864,48 @@ var PlyGameRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4839
4864
  var _getPlyGameResultsInTransaction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(txHash) {
4840
4865
  var _this3 = this;
4841
4866
 
4842
- var tx, filter, betMadeEvents;
4867
+ var tx, i, filter, betMadeEvents;
4843
4868
  return runtime_1.wrap(function _callee5$(_context5) {
4844
4869
  while (1) {
4845
4870
  switch (_context5.prev = _context5.next) {
4846
4871
  case 0:
4847
4872
  _context5.next = 2;
4848
- return this._networkConnection.provider.waitForTransaction(txHash, 1);
4873
+ return this._networkConnection.provider.getTransactionReceipt(txHash);
4849
4874
 
4850
4875
  case 2:
4851
4876
  tx = _context5.sent;
4877
+ i = 0;
4878
+
4879
+ case 4:
4880
+ if (!(i < 100 && !tx)) {
4881
+ _context5.next = 13;
4882
+ break;
4883
+ }
4884
+
4885
+ _context5.next = 7;
4886
+ return sleep(1000);
4887
+
4888
+ case 7:
4889
+ _context5.next = 9;
4890
+ return this._networkConnection.provider.getTransactionReceipt(txHash);
4891
+
4892
+ case 9:
4893
+ tx = _context5.sent;
4894
+
4895
+ case 10:
4896
+ i++;
4897
+ _context5.next = 4;
4898
+ break;
4899
+
4900
+ case 13:
4901
+ if (tx) {
4902
+ _context5.next = 15;
4903
+ break;
4904
+ }
4905
+
4906
+ throw new Error("Transaction " + txHash + " takes too long to be mined");
4907
+
4908
+ case 15:
4852
4909
  filter = this.env.plygame.filters.BetMade();
4853
4910
  betMadeEvents = tx.logs.filter(function (log) {
4854
4911
  return isSameAddress(log.topics[0], filter.topics[0]);
@@ -4862,7 +4919,7 @@ var PlyGameRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4862
4919
  return _this3.parseBetMakeEvent(e);
4863
4920
  })));
4864
4921
 
4865
- case 6:
4922
+ case 18:
4866
4923
  case "end":
4867
4924
  return _context5.stop();
4868
4925
  }
@@ -5911,6 +5968,7 @@ exports.networkAddresses = networkAddresses;
5911
5968
  exports.queryGraphQL = queryGraphQL;
5912
5969
  exports.referralRewardDummy1 = referralRewardDummy1;
5913
5970
  exports.referralRewardDummy2 = referralRewardDummy2;
5971
+ exports.sleep = sleep;
5914
5972
  exports.sortEvents = sortEvents;
5915
5973
  exports.symbolRecords = symbolRecords;
5916
5974
  exports.validateAndParseAddress = validateAndParseAddress;