@thesingularitynetwork/darkswap-sdk 0.1.30 → 0.1.31
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/dist/darkswap-sdk.cjs.development.js +81 -47
- package/dist/darkswap-sdk.cjs.development.js.map +1 -1
- package/dist/darkswap-sdk.cjs.production.min.js +1 -1
- package/dist/darkswap-sdk.cjs.production.min.js.map +1 -1
- package/dist/darkswap-sdk.esm.js +81 -47
- package/dist/darkswap-sdk.esm.js.map +1 -1
- package/dist/services/retail/depositAndCreateOrder.d.ts +1 -0
- package/package.json +1 -1
|
@@ -9328,9 +9328,9 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
|
|
|
9328
9328
|
}
|
|
9329
9329
|
_inheritsLoose(RetailCreateOrderService, _BaseContractService);
|
|
9330
9330
|
var _proto = RetailCreateOrderService.prototype;
|
|
9331
|
-
_proto.
|
|
9332
|
-
var
|
|
9333
|
-
var _yield$generateKeyPai, pubKey,
|
|
9331
|
+
_proto.rebuildContextFromSwapMessage = /*#__PURE__*/function () {
|
|
9332
|
+
var _rebuildContextFromSwapMessage = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(swapMessage, signature) {
|
|
9333
|
+
var _yield$generateKeyPai, pubKey, context;
|
|
9334
9334
|
return _regenerator().w(function (_context) {
|
|
9335
9335
|
while (1) switch (_context.n) {
|
|
9336
9336
|
case 0:
|
|
@@ -9339,12 +9339,46 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
|
|
|
9339
9339
|
case 1:
|
|
9340
9340
|
_yield$generateKeyPai = _context.v;
|
|
9341
9341
|
pubKey = _yield$generateKeyPai[0];
|
|
9342
|
-
|
|
9342
|
+
if (validateOrderNoteWithPubKey(swapMessage.orderNote, pubKey)) {
|
|
9343
|
+
_context.n = 2;
|
|
9344
|
+
break;
|
|
9345
|
+
}
|
|
9346
|
+
throw new DarkSwapError('SwapMessage does not belong to this wallet');
|
|
9347
|
+
case 2:
|
|
9348
|
+
context = new RetailCreateOrderContext(signature);
|
|
9349
|
+
context.orderNote = swapMessage.orderNote;
|
|
9350
|
+
context.swapInNote = swapMessage.inNote;
|
|
9351
|
+
context.feeAmount = swapMessage.feeAmount;
|
|
9352
|
+
context.address = swapMessage.address;
|
|
9353
|
+
_context.n = 3;
|
|
9354
|
+
return this.generateProof(context);
|
|
9355
|
+
case 3:
|
|
9356
|
+
return _context.a(2, context);
|
|
9357
|
+
}
|
|
9358
|
+
}, _callee, this);
|
|
9359
|
+
}));
|
|
9360
|
+
function rebuildContextFromSwapMessage(_x, _x2) {
|
|
9361
|
+
return _rebuildContextFromSwapMessage.apply(this, arguments);
|
|
9362
|
+
}
|
|
9363
|
+
return rebuildContextFromSwapMessage;
|
|
9364
|
+
}();
|
|
9365
|
+
_proto.prepare = /*#__PURE__*/function () {
|
|
9366
|
+
var _prepare = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(address, depositAsset, depositAmount, swapInAsset, swapInAmount, signature) {
|
|
9367
|
+
var _yield$generateKeyPai2, pubKey, privKey, feeRatio, orderNote, feeAmount, realSwapInAmount, swapInNote, context, swapMessage, _t, _t2;
|
|
9368
|
+
return _regenerator().w(function (_context2) {
|
|
9369
|
+
while (1) switch (_context2.n) {
|
|
9370
|
+
case 0:
|
|
9371
|
+
_context2.n = 1;
|
|
9372
|
+
return generateKeyPair(signature);
|
|
9373
|
+
case 1:
|
|
9374
|
+
_yield$generateKeyPai2 = _context2.v;
|
|
9375
|
+
pubKey = _yield$generateKeyPai2[0];
|
|
9376
|
+
privKey = _yield$generateKeyPai2[1];
|
|
9343
9377
|
_t = BigInt;
|
|
9344
|
-
|
|
9378
|
+
_context2.n = 2;
|
|
9345
9379
|
return getFeeRatio(address, this._darkSwap);
|
|
9346
9380
|
case 2:
|
|
9347
|
-
_t2 =
|
|
9381
|
+
_t2 = _context2.v;
|
|
9348
9382
|
feeRatio = _t(_t2);
|
|
9349
9383
|
orderNote = createOrderNoteExt(address, depositAsset, depositAmount, feeRatio, pubKey);
|
|
9350
9384
|
feeAmount = calcFeeAmount(swapInAmount, feeRatio);
|
|
@@ -9355,36 +9389,36 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
|
|
|
9355
9389
|
context.swapInNote = swapInNote;
|
|
9356
9390
|
context.feeAmount = feeAmount;
|
|
9357
9391
|
context.address = address;
|
|
9358
|
-
|
|
9392
|
+
_context2.n = 3;
|
|
9359
9393
|
return generateRetailSwapMessage(address, orderNote, swapInNote, feeAmount, pubKey, privKey);
|
|
9360
9394
|
case 3:
|
|
9361
|
-
swapMessage =
|
|
9395
|
+
swapMessage = _context2.v;
|
|
9362
9396
|
context.swapMessage = swapMessage;
|
|
9363
|
-
return
|
|
9397
|
+
return _context2.a(2, {
|
|
9364
9398
|
context: context,
|
|
9365
9399
|
swapMessage: swapMessage
|
|
9366
9400
|
});
|
|
9367
9401
|
}
|
|
9368
|
-
},
|
|
9402
|
+
}, _callee2, this);
|
|
9369
9403
|
}));
|
|
9370
|
-
function prepare(
|
|
9404
|
+
function prepare(_x3, _x4, _x5, _x6, _x7, _x8) {
|
|
9371
9405
|
return _prepare.apply(this, arguments);
|
|
9372
9406
|
}
|
|
9373
9407
|
return prepare;
|
|
9374
9408
|
}();
|
|
9375
9409
|
_proto.generateProof = /*#__PURE__*/function () {
|
|
9376
|
-
var _generateProof = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
9410
|
+
var _generateProof = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(context) {
|
|
9377
9411
|
var proof;
|
|
9378
|
-
return _regenerator().w(function (
|
|
9379
|
-
while (1) switch (
|
|
9412
|
+
return _regenerator().w(function (_context3) {
|
|
9413
|
+
while (1) switch (_context3.n) {
|
|
9380
9414
|
case 0:
|
|
9381
9415
|
if (!(!context || !context.orderNote || !context.swapInNote || !context.address || !context.feeAmount || !context.signature)) {
|
|
9382
|
-
|
|
9416
|
+
_context3.n = 1;
|
|
9383
9417
|
break;
|
|
9384
9418
|
}
|
|
9385
9419
|
throw new DarkSwapError('Invalid context');
|
|
9386
9420
|
case 1:
|
|
9387
|
-
|
|
9421
|
+
_context3.n = 2;
|
|
9388
9422
|
return generateRetailCreateOrderProof({
|
|
9389
9423
|
depositNote: context.orderNote,
|
|
9390
9424
|
swapInNote: context.swapInNote,
|
|
@@ -9393,26 +9427,26 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
|
|
|
9393
9427
|
feeAmount: context.feeAmount
|
|
9394
9428
|
});
|
|
9395
9429
|
case 2:
|
|
9396
|
-
proof =
|
|
9430
|
+
proof = _context3.v;
|
|
9397
9431
|
context.proof = proof;
|
|
9398
9432
|
case 3:
|
|
9399
|
-
return
|
|
9433
|
+
return _context3.a(2);
|
|
9400
9434
|
}
|
|
9401
|
-
},
|
|
9435
|
+
}, _callee3);
|
|
9402
9436
|
}));
|
|
9403
|
-
function generateProof(
|
|
9437
|
+
function generateProof(_x9) {
|
|
9404
9438
|
return _generateProof.apply(this, arguments);
|
|
9405
9439
|
}
|
|
9406
9440
|
return generateProof;
|
|
9407
9441
|
}();
|
|
9408
9442
|
_proto.allowance = /*#__PURE__*/function () {
|
|
9409
|
-
var _allowance = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
9443
|
+
var _allowance = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(context) {
|
|
9410
9444
|
var signer, asset, amount, allowanceContract, allowance, isLegacy, contract, tx;
|
|
9411
|
-
return _regenerator().w(function (
|
|
9412
|
-
while (1) switch (
|
|
9445
|
+
return _regenerator().w(function (_context4) {
|
|
9446
|
+
while (1) switch (_context4.n) {
|
|
9413
9447
|
case 0:
|
|
9414
9448
|
if (!(!context || !context.orderNote || !context.address || !context.signature || !context.proof)) {
|
|
9415
|
-
|
|
9449
|
+
_context4.n = 1;
|
|
9416
9450
|
break;
|
|
9417
9451
|
}
|
|
9418
9452
|
throw new DarkSwapError('Invalid context');
|
|
@@ -9421,43 +9455,43 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
|
|
|
9421
9455
|
asset = context.orderNote.asset;
|
|
9422
9456
|
amount = context.orderNote.amount;
|
|
9423
9457
|
allowanceContract = new ethers.ethers.Contract(asset, ERC20Abi.abi, this._darkSwap);
|
|
9424
|
-
|
|
9458
|
+
_context4.n = 2;
|
|
9425
9459
|
return allowanceContract.allowance(signer.getAddress(), this._darkSwap.contracts.darkSwapAssetManager);
|
|
9426
9460
|
case 2:
|
|
9427
|
-
allowance =
|
|
9461
|
+
allowance = _context4.v;
|
|
9428
9462
|
if (!(BigInt(allowance) < amount)) {
|
|
9429
|
-
|
|
9463
|
+
_context4.n = 4;
|
|
9430
9464
|
break;
|
|
9431
9465
|
}
|
|
9432
9466
|
isLegacy = legacyTokenConfig.hasOwnProperty(this._darkSwap.chainId) && legacyTokenConfig[this._darkSwap.chainId].includes(asset.toLowerCase());
|
|
9433
9467
|
contract = new ethers.ethers.Contract(asset, isLegacy ? ERC20_USDT.abi : ERC20Abi.abi, signer);
|
|
9434
|
-
|
|
9468
|
+
_context4.n = 3;
|
|
9435
9469
|
return contract.approve(this._darkSwap.contracts.darkSwapAssetManager, hexlify32(MAX_ALLOWANCE));
|
|
9436
9470
|
case 3:
|
|
9437
|
-
tx =
|
|
9438
|
-
|
|
9471
|
+
tx = _context4.v;
|
|
9472
|
+
_context4.n = 4;
|
|
9439
9473
|
return tx.wait();
|
|
9440
9474
|
case 4:
|
|
9441
|
-
return
|
|
9475
|
+
return _context4.a(2);
|
|
9442
9476
|
}
|
|
9443
|
-
},
|
|
9477
|
+
}, _callee4, this);
|
|
9444
9478
|
}));
|
|
9445
|
-
function allowance(
|
|
9479
|
+
function allowance(_x0) {
|
|
9446
9480
|
return _allowance.apply(this, arguments);
|
|
9447
9481
|
}
|
|
9448
9482
|
return allowance;
|
|
9449
9483
|
}();
|
|
9450
9484
|
_proto.execute = /*#__PURE__*/function () {
|
|
9451
|
-
var _execute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
9485
|
+
var _execute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(context) {
|
|
9452
9486
|
var contract, ethAmount, tx;
|
|
9453
|
-
return _regenerator().w(function (
|
|
9454
|
-
while (1) switch (
|
|
9487
|
+
return _regenerator().w(function (_context5) {
|
|
9488
|
+
while (1) switch (_context5.n) {
|
|
9455
9489
|
case 0:
|
|
9456
|
-
|
|
9490
|
+
_context5.n = 1;
|
|
9457
9491
|
return this.generateProof(context);
|
|
9458
9492
|
case 1:
|
|
9459
9493
|
if (!(!context || !context.orderNote || !context.swapInNote || !context.proof)) {
|
|
9460
|
-
|
|
9494
|
+
_context5.n = 2;
|
|
9461
9495
|
break;
|
|
9462
9496
|
}
|
|
9463
9497
|
throw new DarkSwapError('Invalid context');
|
|
@@ -9465,30 +9499,30 @@ var RetailCreateOrderService = /*#__PURE__*/function (_BaseContractService) {
|
|
|
9465
9499
|
contract = new ethers.ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, this._darkSwap.signer);
|
|
9466
9500
|
ethAmount = 0n;
|
|
9467
9501
|
if (!isNativeAsset(context.orderNote.asset)) {
|
|
9468
|
-
|
|
9502
|
+
_context5.n = 3;
|
|
9469
9503
|
break;
|
|
9470
9504
|
}
|
|
9471
9505
|
ethAmount = context.orderNote.amount;
|
|
9472
|
-
|
|
9506
|
+
_context5.n = 4;
|
|
9473
9507
|
break;
|
|
9474
9508
|
case 3:
|
|
9475
|
-
|
|
9509
|
+
_context5.n = 4;
|
|
9476
9510
|
return this.allowance(context);
|
|
9477
9511
|
case 4:
|
|
9478
|
-
|
|
9512
|
+
_context5.n = 5;
|
|
9479
9513
|
return contract.retailDepositCreateOrder([hexlify32(context.orderNote.note), context.proof.depositFooter, context.orderNote.asset, bn_to_0xhex(context.orderNote.amount), hexlify32(context.swapInNote.note), context.proof.swapInNoteFooter], context.proof.proof, {
|
|
9480
9514
|
value: bn_to_0xhex(ethAmount)
|
|
9481
9515
|
});
|
|
9482
9516
|
case 5:
|
|
9483
|
-
tx =
|
|
9484
|
-
|
|
9517
|
+
tx = _context5.v;
|
|
9518
|
+
_context5.n = 6;
|
|
9485
9519
|
return tx.wait();
|
|
9486
9520
|
case 6:
|
|
9487
|
-
return
|
|
9521
|
+
return _context5.a(2, tx.hash);
|
|
9488
9522
|
}
|
|
9489
|
-
},
|
|
9523
|
+
}, _callee5, this);
|
|
9490
9524
|
}));
|
|
9491
|
-
function execute(
|
|
9525
|
+
function execute(_x1) {
|
|
9492
9526
|
return _execute.apply(this, arguments);
|
|
9493
9527
|
}
|
|
9494
9528
|
return execute;
|