@thesingularitynetwork/darkswap-sdk 0.1.37 → 0.1.39

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.
@@ -1,6 +1,7 @@
1
1
  export declare const legacyTokenConfig: {
2
2
  [chainId: number]: string[];
3
3
  };
4
+ export declare const getConfirmations: (chainId: number) => number;
4
5
  export declare const DEFAULT_FEE_RATIO = 300n;
5
6
  export declare const GAS_LIMIT_MULTIPLIER = 120n;
6
7
  export declare const GAS_LIMIT_PRECISION = 100n;
@@ -4230,8 +4230,13 @@ var ERC20_USDT = {
4230
4230
  ChainId[ChainId["BASE"] = 8453] = "BASE";
4231
4231
  })(exports.ChainId || (exports.ChainId = {}));
4232
4232
 
4233
- var _legacyTokenConfig;
4233
+ var _legacyTokenConfig, _confirmationsConfig;
4234
4234
  var legacyTokenConfig = (_legacyTokenConfig = {}, _legacyTokenConfig[exports.ChainId.MAINNET] = ['0xdac17f958d2ee523a2206206994597c13d831ec7'], _legacyTokenConfig[exports.ChainId.HARDHAT] = ['0xdac17f958d2ee523a2206206994597c13d831ec7'], _legacyTokenConfig);
4235
+ var confirmationsConfig = (_confirmationsConfig = {}, _confirmationsConfig[exports.ChainId.MAINNET] = 3, _confirmationsConfig[exports.ChainId.ARBITRUM_ONE] = 3, _confirmationsConfig[exports.ChainId.BASE] = 3, _confirmationsConfig[exports.ChainId.SEPOLIA] = 3, _confirmationsConfig[exports.ChainId.HARDHAT] = 3, _confirmationsConfig);
4236
+ var DEFAULT_CONFIRMATIONS = 3;
4237
+ var getConfirmations = function getConfirmations(chainId) {
4238
+ return confirmationsConfig[chainId] || DEFAULT_CONFIRMATIONS;
4239
+ };
4235
4240
  var DEFAULT_FEE_RATIO = 300n;
4236
4241
  var GAS_LIMIT_MULTIPLIER = 120n;
4237
4242
  var GAS_LIMIT_PRECISION = 100n;
@@ -5004,7 +5009,7 @@ var DepositService = /*#__PURE__*/function (_BaseContractService) {
5004
5009
  case 3:
5005
5010
  tx = _context4.v;
5006
5011
  _context4.n = 4;
5007
- return tx.wait();
5012
+ return tx.wait(getConfirmations(this._darkSwap.chainId));
5008
5013
  case 4:
5009
5014
  return _context4.a(2);
5010
5015
  }
@@ -5292,104 +5297,6 @@ function _generateWithdrawProof() {
5292
5297
  return _generateWithdrawProof.apply(this, arguments);
5293
5298
  }
5294
5299
 
5295
- function safeWait(_x, _x2, _x3) {
5296
- return _safeWait.apply(this, arguments);
5297
- }
5298
- function _safeWait() {
5299
- _safeWait = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(tx, provider, conf) {
5300
- var _err$message, err, msg, _t;
5301
- return _regenerator().w(function (_context) {
5302
- while (1) switch (_context.n) {
5303
- case 0:
5304
- if (conf === void 0) {
5305
- conf = 1;
5306
- }
5307
- _context.p = 1;
5308
- _context.n = 2;
5309
- return tx.wait(conf);
5310
- case 2:
5311
- return _context.a(2, _context.v);
5312
- case 3:
5313
- _context.p = 3;
5314
- _t = _context.v;
5315
- console.log("tx.wait error", _t);
5316
- err = _t;
5317
- msg = (_err$message = err == null ? void 0 : err.message) != null ? _err$message : "";
5318
- if (!(msg.includes("value.nonce") || msg.includes("Cannot convert undefined to a BigInt"))) {
5319
- _context.n = 5;
5320
- break;
5321
- }
5322
- console.log("try getTransactionReceipt");
5323
- _context.n = 4;
5324
- return waitForReceipt(provider, tx.hash, conf);
5325
- case 4:
5326
- return _context.a(2, _context.v);
5327
- case 5:
5328
- throw _t;
5329
- case 6:
5330
- return _context.a(2);
5331
- }
5332
- }, _callee, null, [[1, 3]]);
5333
- }));
5334
- return _safeWait.apply(this, arguments);
5335
- }
5336
- function waitForReceipt(_x4, _x5, _x6, _x7, _x8) {
5337
- return _waitForReceipt.apply(this, arguments);
5338
- }
5339
- function _waitForReceipt() {
5340
- _waitForReceipt = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(provider, hash, confirmations, pollMs, timeoutMs) {
5341
- var start, receipt, tip;
5342
- return _regenerator().w(function (_context2) {
5343
- while (1) switch (_context2.n) {
5344
- case 0:
5345
- if (confirmations === void 0) {
5346
- confirmations = 1;
5347
- }
5348
- if (pollMs === void 0) {
5349
- pollMs = 600;
5350
- }
5351
- if (timeoutMs === void 0) {
5352
- timeoutMs = 60000;
5353
- }
5354
- start = Date.now();
5355
- case 1:
5356
- if (!(Date.now() - start < timeoutMs)) {
5357
- _context2.n = 6;
5358
- break;
5359
- }
5360
- _context2.n = 2;
5361
- return provider.getTransactionReceipt(hash);
5362
- case 2:
5363
- receipt = _context2.v;
5364
- if (!(receipt && receipt.blockNumber)) {
5365
- _context2.n = 4;
5366
- break;
5367
- }
5368
- _context2.n = 3;
5369
- return provider.getBlockNumber();
5370
- case 3:
5371
- tip = _context2.v;
5372
- if (!(tip - receipt.blockNumber + 1 >= confirmations)) {
5373
- _context2.n = 4;
5374
- break;
5375
- }
5376
- return _context2.a(2, receipt);
5377
- case 4:
5378
- _context2.n = 5;
5379
- return new Promise(function (r) {
5380
- return setTimeout(r, pollMs);
5381
- });
5382
- case 5:
5383
- _context2.n = 1;
5384
- break;
5385
- case 6:
5386
- return _context2.a(2, null);
5387
- }
5388
- }, _callee2);
5389
- }));
5390
- return _waitForReceipt.apply(this, arguments);
5391
- }
5392
-
5393
5300
  var WithdrawContext = /*#__PURE__*/function (_BaseContext) {
5394
5301
  function WithdrawContext(signature) {
5395
5302
  return _BaseContext.call(this, signature) || this;
@@ -5506,7 +5413,7 @@ var WithdrawService = /*#__PURE__*/function (_BaseContractService) {
5506
5413
  }();
5507
5414
  _proto.execute = /*#__PURE__*/function () {
5508
5415
  var _execute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(context) {
5509
- var contract, tx, reciept;
5416
+ var contract, tx;
5510
5417
  return _regenerator().w(function (_context3) {
5511
5418
  while (1) switch (_context3.n) {
5512
5419
  case 0:
@@ -5525,15 +5432,8 @@ var WithdrawService = /*#__PURE__*/function (_BaseContractService) {
5525
5432
  case 3:
5526
5433
  tx = _context3.v;
5527
5434
  _context3.n = 4;
5528
- return safeWait(tx, this._darkSwap.provider);
5435
+ return tx.wait();
5529
5436
  case 4:
5530
- reciept = _context3.v;
5531
- if (!(!reciept || reciept.status !== 1)) {
5532
- _context3.n = 5;
5533
- break;
5534
- }
5535
- throw new DarkSwapError('Failed to withdraw');
5536
- case 5:
5537
5437
  return _context3.a(2, tx.hash);
5538
5438
  }
5539
5439
  }, _callee3, this);
@@ -9361,7 +9261,7 @@ var RetailCancelOrderService = /*#__PURE__*/function (_BaseContractService) {
9361
9261
  }();
9362
9262
  _proto.execute = /*#__PURE__*/function () {
9363
9263
  var _execute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(context) {
9364
- var contract, tx, reciept;
9264
+ var contract, tx;
9365
9265
  return _regenerator().w(function (_context3) {
9366
9266
  while (1) switch (_context3.n) {
9367
9267
  case 0:
@@ -9380,15 +9280,8 @@ var RetailCancelOrderService = /*#__PURE__*/function (_BaseContractService) {
9380
9280
  case 3:
9381
9281
  tx = _context3.v;
9382
9282
  _context3.n = 4;
9383
- return safeWait(tx, this._darkSwap.provider);
9283
+ return tx.wait();
9384
9284
  case 4:
9385
- reciept = _context3.v;
9386
- if (!(!reciept || reciept.status !== 1)) {
9387
- _context3.n = 5;
9388
- break;
9389
- }
9390
- throw new DarkSwapError('Failed to cancel order');
9391
- case 5:
9392
9285
  return _context3.a(2, tx.hash);
9393
9286
  }
9394
9287
  }, _callee3, this);
@@ -9567,7 +9460,7 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
9567
9460
  }();
9568
9461
  _proto.allowance = /*#__PURE__*/function () {
9569
9462
  var _allowance = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(context) {
9570
- var signer, asset, amount, allowanceContract, allowance, isLegacy, contract, tx, reciept;
9463
+ var signer, asset, amount, allowanceContract, allowance, isLegacy, contract, tx;
9571
9464
  return _regenerator().w(function (_context4) {
9572
9465
  while (1) switch (_context4.n) {
9573
9466
  case 0:
@@ -9577,13 +9470,19 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
9577
9470
  }
9578
9471
  throw new DarkSwapError('Invalid context');
9579
9472
  case 1:
9473
+ if (!isNativeAsset(context.orderNote.asset)) {
9474
+ _context4.n = 2;
9475
+ break;
9476
+ }
9477
+ return _context4.a(2);
9478
+ case 2:
9580
9479
  signer = this._darkSwap.signer;
9581
9480
  asset = context.orderNote.asset;
9582
9481
  amount = context.orderNote.amount;
9583
9482
  allowanceContract = new ethers.ethers.Contract(asset, ERC20Abi.abi, this._darkSwap);
9584
- _context4.n = 2;
9483
+ _context4.n = 3;
9585
9484
  return allowanceContract.allowance(signer.getAddress(), this._darkSwap.contracts.darkSwapAssetManager);
9586
- case 2:
9485
+ case 3:
9587
9486
  allowance = _context4.v;
9588
9487
  if (!(BigInt(allowance) < amount)) {
9589
9488
  _context4.n = 5;
@@ -9591,19 +9490,12 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
9591
9490
  }
9592
9491
  isLegacy = legacyTokenConfig.hasOwnProperty(this._darkSwap.chainId) && legacyTokenConfig[this._darkSwap.chainId].includes(asset.toLowerCase());
9593
9492
  contract = new ethers.ethers.Contract(asset, isLegacy ? ERC20_USDT.abi : ERC20Abi.abi, signer);
9594
- _context4.n = 3;
9595
- return contract.approve(this._darkSwap.contracts.darkSwapAssetManager, hexlify32(MAX_ALLOWANCE));
9596
- case 3:
9597
- tx = _context4.v;
9598
9493
  _context4.n = 4;
9599
- return safeWait(tx, this._darkSwap.provider);
9494
+ return contract.approve(this._darkSwap.contracts.darkSwapAssetManager, hexlify32(MAX_ALLOWANCE));
9600
9495
  case 4:
9601
- reciept = _context4.v;
9602
- if (!(!reciept || reciept.status !== 1)) {
9603
- _context4.n = 5;
9604
- break;
9605
- }
9606
- throw new DarkSwapError('Failed to approve token');
9496
+ tx = _context4.v;
9497
+ _context4.n = 5;
9498
+ return tx.wait();
9607
9499
  case 5:
9608
9500
  return _context4.a(2);
9609
9501
  }
@@ -9616,7 +9508,7 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
9616
9508
  }();
9617
9509
  _proto.execute = /*#__PURE__*/function () {
9618
9510
  var _execute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(context) {
9619
- var contract, ethAmount, tx, reciept, tmpIsNoteCreated;
9511
+ var contract, ethAmount, tx;
9620
9512
  return _regenerator().w(function (_context5) {
9621
9513
  while (1) switch (_context5.n) {
9622
9514
  case 0:
@@ -9648,34 +9540,9 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
9648
9540
  });
9649
9541
  case 5:
9650
9542
  tx = _context5.v;
9651
- console.log("=== before safeWait");
9652
9543
  _context5.n = 6;
9653
- return safeWait(tx, this._darkSwap.provider);
9544
+ return tx.wait();
9654
9545
  case 6:
9655
- reciept = _context5.v;
9656
- if (reciept) {
9657
- _context5.n = 9;
9658
- break;
9659
- }
9660
- _context5.n = 7;
9661
- return isNoteCreated(this._darkSwap, context.orderNote.note);
9662
- case 7:
9663
- tmpIsNoteCreated = _context5.v;
9664
- if (tmpIsNoteCreated) {
9665
- _context5.n = 8;
9666
- break;
9667
- }
9668
- throw new DarkSwapError('Failed to create order');
9669
- case 8:
9670
- _context5.n = 10;
9671
- break;
9672
- case 9:
9673
- if (!(reciept.status !== 1)) {
9674
- _context5.n = 10;
9675
- break;
9676
- }
9677
- throw new DarkSwapError('Failed to create order');
9678
- case 10:
9679
9546
  return _context5.a(2, tx.hash);
9680
9547
  }
9681
9548
  }, _callee5, this);
@@ -10344,6 +10211,7 @@ exports.createNote = createNote;
10344
10211
  exports.createOrderNoteExt = createOrderNoteExt;
10345
10212
  exports.deserializeDarkSwapMessage = deserializeDarkSwapMessage;
10346
10213
  exports.generateKeyPair = generateKeyPair;
10214
+ exports.getConfirmations = getConfirmations;
10347
10215
  exports.getFeeRatio = getFeeRatio;
10348
10216
  exports.getMerklePathAndRoot = getMerklePathAndRoot;
10349
10217
  exports.getNoteFooter = getNoteFooter;