@thesingularitynetwork/darkswap-sdk 0.2.0 → 0.2.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.
- package/dist/darkswap-sdk.cjs.development.js +259 -68
- 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 +259 -69
- package/dist/darkswap-sdk.esm.js.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/synara/bridgeAndCreateOrder.d.ts +52 -0
- package/dist/services/synara/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -10056,74 +10056,6 @@ var RetailSwapService = /*#__PURE__*/function (_BaseContractService) {
|
|
|
10056
10056
|
return RetailSwapService;
|
|
10057
10057
|
}(BaseContractService);
|
|
10058
10058
|
|
|
10059
|
-
var DarkSwap = function DarkSwap(signer, chainId, contracts) {
|
|
10060
|
-
// @ts-ignore
|
|
10061
|
-
this.signer = signer;
|
|
10062
|
-
// @ts-ignore
|
|
10063
|
-
this.provider = signer.provider;
|
|
10064
|
-
this.chainId = chainId;
|
|
10065
|
-
if (contracts) {
|
|
10066
|
-
this.contracts = contracts;
|
|
10067
|
-
} else {
|
|
10068
|
-
if (contractConfig[chainId]) {
|
|
10069
|
-
this.contracts = contractConfig[chainId];
|
|
10070
|
-
} else {
|
|
10071
|
-
throw new DarkSwapError('There is no default contract configuration for the provided chainId');
|
|
10072
|
-
}
|
|
10073
|
-
}
|
|
10074
|
-
};
|
|
10075
|
-
|
|
10076
|
-
function serializeDarkSwapMessage(swapMessage) {
|
|
10077
|
-
return JSON.stringify({
|
|
10078
|
-
address: swapMessage.address,
|
|
10079
|
-
orderNote: {
|
|
10080
|
-
rho: swapMessage.orderNote.rho.toString(),
|
|
10081
|
-
amount: swapMessage.orderNote.amount.toString(),
|
|
10082
|
-
asset: swapMessage.orderNote.asset,
|
|
10083
|
-
note: swapMessage.orderNote.note.toString(),
|
|
10084
|
-
feeRatio: swapMessage.orderNote.feeRatio.toString()
|
|
10085
|
-
},
|
|
10086
|
-
orderNullifier: swapMessage.orderNullifier,
|
|
10087
|
-
inNote: {
|
|
10088
|
-
rho: swapMessage.inNote.rho.toString(),
|
|
10089
|
-
amount: swapMessage.inNote.amount.toString(),
|
|
10090
|
-
asset: swapMessage.inNote.asset,
|
|
10091
|
-
note: swapMessage.inNote.note.toString()
|
|
10092
|
-
},
|
|
10093
|
-
feeAmount: swapMessage.feeAmount.toString(),
|
|
10094
|
-
pubKey: [swapMessage.publicKey[0].toString(), swapMessage.publicKey[1].toString()],
|
|
10095
|
-
signature: swapMessage.signature
|
|
10096
|
-
});
|
|
10097
|
-
}
|
|
10098
|
-
function deserializePublicKey(publicKeyString) {
|
|
10099
|
-
return [Fr.fromHexString(publicKeyString[0]), Fr.fromHexString(publicKeyString[1])];
|
|
10100
|
-
}
|
|
10101
|
-
function deserializeDarkSwapMessage(serializedMessage) {
|
|
10102
|
-
var message = JSON.parse(serializedMessage);
|
|
10103
|
-
return {
|
|
10104
|
-
address: message.address,
|
|
10105
|
-
orderNote: {
|
|
10106
|
-
address: message.orderNote.address,
|
|
10107
|
-
rho: BigInt(message.orderNote.rho),
|
|
10108
|
-
amount: BigInt(message.orderNote.amount),
|
|
10109
|
-
asset: message.orderNote.asset,
|
|
10110
|
-
note: BigInt(message.orderNote.note),
|
|
10111
|
-
feeRatio: BigInt(message.orderNote.feeRatio)
|
|
10112
|
-
},
|
|
10113
|
-
feeAmount: BigInt(message.feeAmount),
|
|
10114
|
-
inNote: {
|
|
10115
|
-
address: message.inNote.address,
|
|
10116
|
-
rho: BigInt(message.inNote.rho),
|
|
10117
|
-
amount: BigInt(message.inNote.amount),
|
|
10118
|
-
asset: message.inNote.asset,
|
|
10119
|
-
note: BigInt(message.inNote.note)
|
|
10120
|
-
},
|
|
10121
|
-
signature: message.signature,
|
|
10122
|
-
publicKey: deserializePublicKey(message.pubKey),
|
|
10123
|
-
orderNullifier: message.orderNullifier
|
|
10124
|
-
};
|
|
10125
|
-
}
|
|
10126
|
-
|
|
10127
10059
|
var noir_version$a = "1.0.0-beta.6+e796dfd67726cbc28eb9991782533b211025928d";
|
|
10128
10060
|
var hash$a = "16793290200553875043";
|
|
10129
10061
|
var abi$f = {
|
|
@@ -10422,6 +10354,265 @@ function _generateRetailBridgeOrderProof() {
|
|
|
10422
10354
|
return _generateRetailBridgeOrderProof.apply(this, arguments);
|
|
10423
10355
|
}
|
|
10424
10356
|
|
|
10357
|
+
var BridgeCreateOrderContext = /*#__PURE__*/function (_BaseContext) {
|
|
10358
|
+
function BridgeCreateOrderContext(signature) {
|
|
10359
|
+
return _BaseContext.call(this, signature) || this;
|
|
10360
|
+
}
|
|
10361
|
+
_inheritsLoose(BridgeCreateOrderContext, _BaseContext);
|
|
10362
|
+
return _createClass(BridgeCreateOrderContext, [{
|
|
10363
|
+
key: "orderNote",
|
|
10364
|
+
get: function get() {
|
|
10365
|
+
return this._orderNote;
|
|
10366
|
+
},
|
|
10367
|
+
set: function set(orderNote) {
|
|
10368
|
+
this._orderNote = orderNote;
|
|
10369
|
+
}
|
|
10370
|
+
}, {
|
|
10371
|
+
key: "swapInNote",
|
|
10372
|
+
get: function get() {
|
|
10373
|
+
return this._swapInNote;
|
|
10374
|
+
},
|
|
10375
|
+
set: function set(swapInNote) {
|
|
10376
|
+
this._swapInNote = swapInNote;
|
|
10377
|
+
}
|
|
10378
|
+
}, {
|
|
10379
|
+
key: "feeAmount",
|
|
10380
|
+
get: function get() {
|
|
10381
|
+
return this._feeAmount;
|
|
10382
|
+
},
|
|
10383
|
+
set: function set(feeAmount) {
|
|
10384
|
+
this._feeAmount = feeAmount;
|
|
10385
|
+
}
|
|
10386
|
+
}, {
|
|
10387
|
+
key: "proof",
|
|
10388
|
+
get: function get() {
|
|
10389
|
+
return this._proof;
|
|
10390
|
+
},
|
|
10391
|
+
set: function set(proof) {
|
|
10392
|
+
this._proof = proof;
|
|
10393
|
+
}
|
|
10394
|
+
}, {
|
|
10395
|
+
key: "swapMessage",
|
|
10396
|
+
get: function get() {
|
|
10397
|
+
return this._swapMessage;
|
|
10398
|
+
},
|
|
10399
|
+
set: function set(swapMessage) {
|
|
10400
|
+
this._swapMessage = swapMessage;
|
|
10401
|
+
}
|
|
10402
|
+
}, {
|
|
10403
|
+
key: "sourceChainId",
|
|
10404
|
+
get: function get() {
|
|
10405
|
+
return this._sourceChainId;
|
|
10406
|
+
},
|
|
10407
|
+
set: function set(sourceChainId) {
|
|
10408
|
+
this._sourceChainId = sourceChainId;
|
|
10409
|
+
}
|
|
10410
|
+
}, {
|
|
10411
|
+
key: "destChainId",
|
|
10412
|
+
get: function get() {
|
|
10413
|
+
return this._destChainId;
|
|
10414
|
+
},
|
|
10415
|
+
set: function set(destChainId) {
|
|
10416
|
+
this._destChainId = destChainId;
|
|
10417
|
+
}
|
|
10418
|
+
}, {
|
|
10419
|
+
key: "sourceAsset",
|
|
10420
|
+
get: function get() {
|
|
10421
|
+
return this._sourceAsset;
|
|
10422
|
+
},
|
|
10423
|
+
set: function set(sourceAsset) {
|
|
10424
|
+
this._sourceAsset = sourceAsset;
|
|
10425
|
+
}
|
|
10426
|
+
}, {
|
|
10427
|
+
key: "sourceAmount",
|
|
10428
|
+
get: function get() {
|
|
10429
|
+
return this._sourceAmount;
|
|
10430
|
+
},
|
|
10431
|
+
set: function set(sourceAmount) {
|
|
10432
|
+
this._sourceAmount = sourceAmount;
|
|
10433
|
+
}
|
|
10434
|
+
}, {
|
|
10435
|
+
key: "bridgeFeeAmount",
|
|
10436
|
+
get: function get() {
|
|
10437
|
+
return this._bridgeFeeAmount;
|
|
10438
|
+
},
|
|
10439
|
+
set: function set(bridgeFeeAmount) {
|
|
10440
|
+
this._bridgeFeeAmount = bridgeFeeAmount;
|
|
10441
|
+
}
|
|
10442
|
+
}, {
|
|
10443
|
+
key: "depositId",
|
|
10444
|
+
get: function get() {
|
|
10445
|
+
return this._depositId;
|
|
10446
|
+
},
|
|
10447
|
+
set: function set(depositId) {
|
|
10448
|
+
this._depositId = depositId;
|
|
10449
|
+
}
|
|
10450
|
+
}]);
|
|
10451
|
+
}(BaseContext);
|
|
10452
|
+
var BridgeCreateOrderService = /*#__PURE__*/function () {
|
|
10453
|
+
function BridgeCreateOrderService(_darkSwapOfSourceChain, _darkSwapOfDestChain) {
|
|
10454
|
+
this._darkSwapOfSourceChain = _darkSwapOfSourceChain;
|
|
10455
|
+
this._darkSwapOfDestChain = _darkSwapOfDestChain;
|
|
10456
|
+
}
|
|
10457
|
+
var _proto = BridgeCreateOrderService.prototype;
|
|
10458
|
+
_proto.prepare = /*#__PURE__*/function () {
|
|
10459
|
+
var _prepare = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(address, sourceChainId, sourceAsset, sourceAmount, depositId, bridgeFee, destChainId, depositAsset, depositAmount, swapInAsset, swapInAmount, signature) {
|
|
10460
|
+
var _yield$generateKeyPai, pubKey, privKey, feeRatio, orderNote, feeAmount, realSwapInAmount, swapInNote, context, swapMessage, _t, _t2;
|
|
10461
|
+
return _regenerator().w(function (_context) {
|
|
10462
|
+
while (1) switch (_context.n) {
|
|
10463
|
+
case 0:
|
|
10464
|
+
_context.n = 1;
|
|
10465
|
+
return generateKeyPair(signature);
|
|
10466
|
+
case 1:
|
|
10467
|
+
_yield$generateKeyPai = _context.v;
|
|
10468
|
+
pubKey = _yield$generateKeyPai[0];
|
|
10469
|
+
privKey = _yield$generateKeyPai[1];
|
|
10470
|
+
_t = BigInt;
|
|
10471
|
+
_context.n = 2;
|
|
10472
|
+
return getFeeRatio(address, this._darkSwapOfDestChain);
|
|
10473
|
+
case 2:
|
|
10474
|
+
_t2 = _context.v;
|
|
10475
|
+
feeRatio = _t(_t2);
|
|
10476
|
+
orderNote = createOrderNoteExt(address, depositAsset, depositAmount, feeRatio, pubKey);
|
|
10477
|
+
feeAmount = calcFeeAmount(swapInAmount, feeRatio);
|
|
10478
|
+
realSwapInAmount = swapInAmount - feeAmount;
|
|
10479
|
+
swapInNote = createNote(address, swapInAsset, realSwapInAmount, pubKey);
|
|
10480
|
+
context = new BridgeCreateOrderContext(signature);
|
|
10481
|
+
context.orderNote = orderNote;
|
|
10482
|
+
context.swapInNote = swapInNote;
|
|
10483
|
+
context.feeAmount = feeAmount;
|
|
10484
|
+
context.address = address;
|
|
10485
|
+
context.sourceChainId = sourceChainId;
|
|
10486
|
+
context.destChainId = destChainId;
|
|
10487
|
+
context.sourceAsset = sourceAsset;
|
|
10488
|
+
context.sourceAmount = sourceAmount;
|
|
10489
|
+
context.bridgeFeeAmount = bridgeFee;
|
|
10490
|
+
context.depositId = depositId;
|
|
10491
|
+
_context.n = 3;
|
|
10492
|
+
return generateRetailSwapMessage(address, orderNote, swapInNote, feeAmount, pubKey, privKey);
|
|
10493
|
+
case 3:
|
|
10494
|
+
swapMessage = _context.v;
|
|
10495
|
+
context.swapMessage = swapMessage;
|
|
10496
|
+
return _context.a(2, {
|
|
10497
|
+
context: context,
|
|
10498
|
+
swapMessage: swapMessage
|
|
10499
|
+
});
|
|
10500
|
+
}
|
|
10501
|
+
}, _callee, this);
|
|
10502
|
+
}));
|
|
10503
|
+
function prepare(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8, _x9, _x0, _x1, _x10) {
|
|
10504
|
+
return _prepare.apply(this, arguments);
|
|
10505
|
+
}
|
|
10506
|
+
return prepare;
|
|
10507
|
+
}();
|
|
10508
|
+
_proto.generateProof = /*#__PURE__*/function () {
|
|
10509
|
+
var _generateProof = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(context) {
|
|
10510
|
+
var proof;
|
|
10511
|
+
return _regenerator().w(function (_context2) {
|
|
10512
|
+
while (1) switch (_context2.n) {
|
|
10513
|
+
case 0:
|
|
10514
|
+
if (!(!context || !context.orderNote || !context.swapInNote || !context.address || !context.feeAmount || !context.signature || !context.sourceChainId || !context.destChainId || !context.sourceAsset || !context.sourceAmount || !context.bridgeFeeAmount || !context.depositId)) {
|
|
10515
|
+
_context2.n = 1;
|
|
10516
|
+
break;
|
|
10517
|
+
}
|
|
10518
|
+
throw new DarkSwapError('Invalid context');
|
|
10519
|
+
case 1:
|
|
10520
|
+
_context2.n = 2;
|
|
10521
|
+
return generateRetailBridgeOrderProof({
|
|
10522
|
+
depositSourceAsset: context.sourceAsset,
|
|
10523
|
+
depositNote: context.orderNote,
|
|
10524
|
+
swapInNote: context.swapInNote,
|
|
10525
|
+
feeRatio: context.orderNote.feeRatio,
|
|
10526
|
+
feeAmount: context.feeAmount,
|
|
10527
|
+
destChain: context.destChainId,
|
|
10528
|
+
depositId: context.depositId,
|
|
10529
|
+
bridgeFeeAmount: context.bridgeFeeAmount,
|
|
10530
|
+
address: context.address,
|
|
10531
|
+
signedMessage: context.signature
|
|
10532
|
+
});
|
|
10533
|
+
case 2:
|
|
10534
|
+
proof = _context2.v;
|
|
10535
|
+
return _context2.a(2, proof);
|
|
10536
|
+
}
|
|
10537
|
+
}, _callee2);
|
|
10538
|
+
}));
|
|
10539
|
+
function generateProof(_x11) {
|
|
10540
|
+
return _generateProof.apply(this, arguments);
|
|
10541
|
+
}
|
|
10542
|
+
return generateProof;
|
|
10543
|
+
}();
|
|
10544
|
+
return BridgeCreateOrderService;
|
|
10545
|
+
}();
|
|
10546
|
+
|
|
10547
|
+
var DarkSwap = function DarkSwap(signer, chainId, contracts) {
|
|
10548
|
+
// @ts-ignore
|
|
10549
|
+
this.signer = signer;
|
|
10550
|
+
// @ts-ignore
|
|
10551
|
+
this.provider = signer.provider;
|
|
10552
|
+
this.chainId = chainId;
|
|
10553
|
+
if (contracts) {
|
|
10554
|
+
this.contracts = contracts;
|
|
10555
|
+
} else {
|
|
10556
|
+
if (contractConfig[chainId]) {
|
|
10557
|
+
this.contracts = contractConfig[chainId];
|
|
10558
|
+
} else {
|
|
10559
|
+
throw new DarkSwapError('There is no default contract configuration for the provided chainId');
|
|
10560
|
+
}
|
|
10561
|
+
}
|
|
10562
|
+
};
|
|
10563
|
+
|
|
10564
|
+
function serializeDarkSwapMessage(swapMessage) {
|
|
10565
|
+
return JSON.stringify({
|
|
10566
|
+
address: swapMessage.address,
|
|
10567
|
+
orderNote: {
|
|
10568
|
+
rho: swapMessage.orderNote.rho.toString(),
|
|
10569
|
+
amount: swapMessage.orderNote.amount.toString(),
|
|
10570
|
+
asset: swapMessage.orderNote.asset,
|
|
10571
|
+
note: swapMessage.orderNote.note.toString(),
|
|
10572
|
+
feeRatio: swapMessage.orderNote.feeRatio.toString()
|
|
10573
|
+
},
|
|
10574
|
+
orderNullifier: swapMessage.orderNullifier,
|
|
10575
|
+
inNote: {
|
|
10576
|
+
rho: swapMessage.inNote.rho.toString(),
|
|
10577
|
+
amount: swapMessage.inNote.amount.toString(),
|
|
10578
|
+
asset: swapMessage.inNote.asset,
|
|
10579
|
+
note: swapMessage.inNote.note.toString()
|
|
10580
|
+
},
|
|
10581
|
+
feeAmount: swapMessage.feeAmount.toString(),
|
|
10582
|
+
pubKey: [swapMessage.publicKey[0].toString(), swapMessage.publicKey[1].toString()],
|
|
10583
|
+
signature: swapMessage.signature
|
|
10584
|
+
});
|
|
10585
|
+
}
|
|
10586
|
+
function deserializePublicKey(publicKeyString) {
|
|
10587
|
+
return [Fr.fromHexString(publicKeyString[0]), Fr.fromHexString(publicKeyString[1])];
|
|
10588
|
+
}
|
|
10589
|
+
function deserializeDarkSwapMessage(serializedMessage) {
|
|
10590
|
+
var message = JSON.parse(serializedMessage);
|
|
10591
|
+
return {
|
|
10592
|
+
address: message.address,
|
|
10593
|
+
orderNote: {
|
|
10594
|
+
address: message.orderNote.address,
|
|
10595
|
+
rho: BigInt(message.orderNote.rho),
|
|
10596
|
+
amount: BigInt(message.orderNote.amount),
|
|
10597
|
+
asset: message.orderNote.asset,
|
|
10598
|
+
note: BigInt(message.orderNote.note),
|
|
10599
|
+
feeRatio: BigInt(message.orderNote.feeRatio)
|
|
10600
|
+
},
|
|
10601
|
+
feeAmount: BigInt(message.feeAmount),
|
|
10602
|
+
inNote: {
|
|
10603
|
+
address: message.inNote.address,
|
|
10604
|
+
rho: BigInt(message.inNote.rho),
|
|
10605
|
+
amount: BigInt(message.inNote.amount),
|
|
10606
|
+
asset: message.inNote.asset,
|
|
10607
|
+
note: BigInt(message.inNote.note)
|
|
10608
|
+
},
|
|
10609
|
+
signature: message.signature,
|
|
10610
|
+
publicKey: deserializePublicKey(message.pubKey),
|
|
10611
|
+
orderNullifier: message.orderNullifier
|
|
10612
|
+
};
|
|
10613
|
+
}
|
|
10614
|
+
|
|
10615
|
+
exports.BridgeCreateOrderService = BridgeCreateOrderService;
|
|
10425
10616
|
exports.DEFAULT_FEE_RATIO = DEFAULT_FEE_RATIO;
|
|
10426
10617
|
exports.DOMAIN_NOTE = DOMAIN_NOTE;
|
|
10427
10618
|
exports.DOMAIN_ORDER_NOTE = DOMAIN_ORDER_NOTE;
|