@thesingularitynetwork/darkswap-sdk 0.1.5 → 0.1.7
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/index.esm.js +46 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +46 -26
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +46 -26
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/config/contractConfig.d.ts +1 -1
- package/dist/types/src/proof/pro/orders/createOrderProof.d.ts +2 -1
- package/dist/types/src/services/pro/createOrder.d.ts +7 -5
- package/package.json +1 -1
- package/src/abis/DarkSwapAssetManager.json +1 -1
- package/src/config/contractConfig.ts +6 -6
- package/src/proof/pro/orders/createOrderProof.ts +6 -5
- package/src/services/base/deposit.ts +2 -1
- package/src/services/pro/createOrder.ts +34 -17
package/dist/index.esm.js
CHANGED
|
@@ -1846,7 +1846,7 @@ var abi$a = [
|
|
|
1846
1846
|
name: "retailDepositCreateOrder",
|
|
1847
1847
|
outputs: [
|
|
1848
1848
|
],
|
|
1849
|
-
stateMutability: "
|
|
1849
|
+
stateMutability: "payable",
|
|
1850
1850
|
type: "function"
|
|
1851
1851
|
},
|
|
1852
1852
|
{
|
|
@@ -2943,7 +2943,7 @@ class DepositService extends BaseContractService {
|
|
|
2943
2943
|
const contract = new ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, signer);
|
|
2944
2944
|
if (!isNativeAsset(context.newBalance.asset)) {
|
|
2945
2945
|
await this.allowance(context);
|
|
2946
|
-
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
2946
|
+
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof, { value: 0n });
|
|
2947
2947
|
await tx.wait();
|
|
2948
2948
|
return tx.hash;
|
|
2949
2949
|
}
|
|
@@ -4234,14 +4234,14 @@ async function generateProCreateOrderProof(param) {
|
|
|
4234
4234
|
}
|
|
4235
4235
|
if (param.newBalanceNote.amount < 0n
|
|
4236
4236
|
|| param.oldBalanceNote.amount <= 0n
|
|
4237
|
-
|| param.
|
|
4237
|
+
|| param.inAmount <= 0n
|
|
4238
4238
|
|| param.orderNote.amount <= 0n) {
|
|
4239
4239
|
throw new DarkSwapProofError("Invalid note amount");
|
|
4240
4240
|
}
|
|
4241
4241
|
if (param.orderNote.amount != param.oldBalanceNote.amount - param.newBalanceNote.amount) {
|
|
4242
4242
|
throw new DarkSwapProofError("Invalid order amount");
|
|
4243
4243
|
}
|
|
4244
|
-
const feeAmount = param.
|
|
4244
|
+
const feeAmount = param.inAmount * param.orderNote.feeRatio / FEE_RATIO_PRECISION;
|
|
4245
4245
|
const [[fuzkPubKeyX, fuzkPubKeyY], fuzkPriKey] = await generateKeyPair(param.signedMessage);
|
|
4246
4246
|
let newBalanceFooter = EMPTY_FOOTER;
|
|
4247
4247
|
if (param.oldBalanceNote.amount != 0n) {
|
|
@@ -4277,8 +4277,8 @@ async function generateProCreateOrderProof(param) {
|
|
|
4277
4277
|
order_note_footer: bn_to_0xhex(orderNoteFooter),
|
|
4278
4278
|
order_asset: bn_to_0xhex(encodeAddress(param.orderNote.asset)),
|
|
4279
4279
|
order_amount: bn_to_0xhex(param.orderNote.amount),
|
|
4280
|
-
in_asset: bn_to_0xhex(encodeAddress(param.
|
|
4281
|
-
in_amount: bn_to_0xhex(param.
|
|
4280
|
+
in_asset: bn_to_0xhex(encodeAddress(param.inAsset)),
|
|
4281
|
+
in_amount: bn_to_0xhex(param.inAmount),
|
|
4282
4282
|
pub_key: [fuzkPubKeyX.toString(), fuzkPubKeyY.toString()],
|
|
4283
4283
|
signature: uint8ArrayToNumberArray(signature),
|
|
4284
4284
|
};
|
|
@@ -4312,7 +4312,13 @@ class ProCreateOrderContext extends BaseContext {
|
|
|
4312
4312
|
writable: true,
|
|
4313
4313
|
value: void 0
|
|
4314
4314
|
});
|
|
4315
|
-
Object.defineProperty(this, "
|
|
4315
|
+
Object.defineProperty(this, "_swapInAsset", {
|
|
4316
|
+
enumerable: true,
|
|
4317
|
+
configurable: true,
|
|
4318
|
+
writable: true,
|
|
4319
|
+
value: void 0
|
|
4320
|
+
});
|
|
4321
|
+
Object.defineProperty(this, "_swapInAmount", {
|
|
4316
4322
|
enumerable: true,
|
|
4317
4323
|
configurable: true,
|
|
4318
4324
|
writable: true,
|
|
@@ -4343,11 +4349,17 @@ class ProCreateOrderContext extends BaseContext {
|
|
|
4343
4349
|
get orderNote() {
|
|
4344
4350
|
return this._orderNote;
|
|
4345
4351
|
}
|
|
4346
|
-
set
|
|
4347
|
-
this.
|
|
4352
|
+
set swapInAsset(swapInAsset) {
|
|
4353
|
+
this._swapInAsset = swapInAsset;
|
|
4348
4354
|
}
|
|
4349
|
-
get
|
|
4350
|
-
return this.
|
|
4355
|
+
get swapInAsset() {
|
|
4356
|
+
return this._swapInAsset;
|
|
4357
|
+
}
|
|
4358
|
+
set swapInAmount(swapInAmount) {
|
|
4359
|
+
this._swapInAmount = swapInAmount;
|
|
4360
|
+
}
|
|
4361
|
+
get swapInAmount() {
|
|
4362
|
+
return this._swapInAmount;
|
|
4351
4363
|
}
|
|
4352
4364
|
set oldBalance(oldBalance) {
|
|
4353
4365
|
this._oldBalance = oldBalance;
|
|
@@ -4384,23 +4396,24 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4384
4396
|
constructor(_darkSwap) {
|
|
4385
4397
|
super(_darkSwap);
|
|
4386
4398
|
}
|
|
4387
|
-
async prepare(address,
|
|
4388
|
-
const [pubKey
|
|
4389
|
-
const orderNote = createOrderNoteExt(address,
|
|
4390
|
-
const newBalance = createNote(address,
|
|
4391
|
-
const swapInNote = createNote(address, swapInAsset, swapInAmount, pubKey);
|
|
4399
|
+
async prepare(address, orderAsset, orderAmount, swapInAsset, swapInAmount, balanceNote, signature) {
|
|
4400
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
4401
|
+
const orderNote = createOrderNoteExt(address, orderAsset, orderAmount, FEE_RATIO, pubKey);
|
|
4402
|
+
const newBalance = createNote(address, orderAsset, balanceNote.amount - orderAmount, pubKey);
|
|
4392
4403
|
const context = new ProCreateOrderContext(signature);
|
|
4393
4404
|
context.orderNote = orderNote;
|
|
4394
|
-
context.
|
|
4405
|
+
context.swapInAsset = swapInAsset;
|
|
4406
|
+
context.swapInAmount = swapInAmount;
|
|
4395
4407
|
context.oldBalance = balanceNote;
|
|
4396
4408
|
context.newBalance = newBalance;
|
|
4397
4409
|
context.address = address;
|
|
4398
|
-
return { context, orderNote,
|
|
4410
|
+
return { context, orderNote, newBalance };
|
|
4399
4411
|
}
|
|
4400
4412
|
async generateProof(context) {
|
|
4401
4413
|
if (!context
|
|
4402
4414
|
|| !context.orderNote
|
|
4403
|
-
|| !context.
|
|
4415
|
+
|| !context.swapInAsset
|
|
4416
|
+
|| !context.swapInAmount
|
|
4404
4417
|
|| !context.oldBalance
|
|
4405
4418
|
|| !context.newBalance
|
|
4406
4419
|
|| !context.address
|
|
@@ -4415,7 +4428,8 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4415
4428
|
orderNote: context.orderNote,
|
|
4416
4429
|
oldBalanceNote: context.oldBalance,
|
|
4417
4430
|
newBalanceNote: context.newBalance,
|
|
4418
|
-
|
|
4431
|
+
inAsset: context.swapInAsset,
|
|
4432
|
+
inAmount: context.swapInAmount,
|
|
4419
4433
|
address: context.address,
|
|
4420
4434
|
signedMessage: context.signature,
|
|
4421
4435
|
});
|
|
@@ -4424,7 +4438,13 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4424
4438
|
}
|
|
4425
4439
|
async execute(context) {
|
|
4426
4440
|
await this.generateProof(context);
|
|
4427
|
-
if (!context
|
|
4441
|
+
if (!context
|
|
4442
|
+
|| !context.orderNote
|
|
4443
|
+
|| !context.swapInAsset
|
|
4444
|
+
|| !context.swapInAmount
|
|
4445
|
+
|| !context.oldBalance
|
|
4446
|
+
|| !context.newBalance
|
|
4447
|
+
|| !context.proof) {
|
|
4428
4448
|
throw new DarkSwapError('Invalid context');
|
|
4429
4449
|
}
|
|
4430
4450
|
const contract = new ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, this._darkSwap.signer);
|
|
@@ -6115,7 +6135,7 @@ const contractConfig = {
|
|
|
6115
6135
|
merkleTreeOperator: '0x0', //FIXME
|
|
6116
6136
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6117
6137
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6118
|
-
|
|
6138
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-subgraph/version/v0.0.1/api',
|
|
6119
6139
|
},
|
|
6120
6140
|
[ChainId.ARBITRUM_ONE]: {
|
|
6121
6141
|
priceOracle: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
|
@@ -6124,7 +6144,7 @@ const contractConfig = {
|
|
|
6124
6144
|
merkleTreeOperator: '0x0', //FIXME
|
|
6125
6145
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6126
6146
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6127
|
-
|
|
6147
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-arb-subgraph/api'
|
|
6128
6148
|
},
|
|
6129
6149
|
[ChainId.BASE]: {
|
|
6130
6150
|
priceOracle: '0xf224a25453D76A41c4427DD1C05369BC9f498444',
|
|
@@ -6133,7 +6153,7 @@ const contractConfig = {
|
|
|
6133
6153
|
merkleTreeOperator: '0x0', //FIXME
|
|
6134
6154
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6135
6155
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6136
|
-
|
|
6156
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-base-subgraph/api'
|
|
6137
6157
|
},
|
|
6138
6158
|
[ChainId.SEPOLIA]: {
|
|
6139
6159
|
priceOracle: '0x4Fe44a9aC8Ef059Be2dB97f9e3bcA32Ab698C2f2',
|
|
@@ -6142,7 +6162,7 @@ const contractConfig = {
|
|
|
6142
6162
|
merkleTreeOperator: '0x0', //FIXME
|
|
6143
6163
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6144
6164
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6145
|
-
|
|
6165
|
+
drakSwapSubgraphUrl: ''
|
|
6146
6166
|
},
|
|
6147
6167
|
[ChainId.HARDHAT]: {
|
|
6148
6168
|
priceOracle: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
|
@@ -6151,7 +6171,7 @@ const contractConfig = {
|
|
|
6151
6171
|
merkleTreeOperator: '0xEd8D7d3A98CB4ea6C91a80dcd2220719c264531f',
|
|
6152
6172
|
darkSwapAssetManager: '0xeF66010868Ff77119171628B7eFa0F6179779375',
|
|
6153
6173
|
darkSwapFeeAssetManager: '0xe3EF345391654121f385679613Cea79A692C2Dd8',
|
|
6154
|
-
|
|
6174
|
+
drakSwapSubgraphUrl: 'https://34.142.142.240:8080/subgraphs/name/singularity/',
|
|
6155
6175
|
}
|
|
6156
6176
|
};
|
|
6157
6177
|
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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a = [
|
|
|
1846
1846
|
name: "retailDepositCreateOrder",
|
|
1847
1847
|
outputs: [
|
|
1848
1848
|
],
|
|
1849
|
-
stateMutability: "
|
|
1849
|
+
stateMutability: "payable",
|
|
1850
1850
|
type: "function"
|
|
1851
1851
|
},
|
|
1852
1852
|
{
|
|
@@ -2943,7 +2943,7 @@ class DepositService extends BaseContractService {
|
|
|
2943
2943
|
const contract = new ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, signer);
|
|
2944
2944
|
if (!isNativeAsset(context.newBalance.asset)) {
|
|
2945
2945
|
await this.allowance(context);
|
|
2946
|
-
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
2946
|
+
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof, { value: 0n });
|
|
2947
2947
|
await tx.wait();
|
|
2948
2948
|
return tx.hash;
|
|
2949
2949
|
}
|
|
@@ -4234,14 +4234,14 @@ async function generateProCreateOrderProof(param) {
|
|
|
4234
4234
|
}
|
|
4235
4235
|
if (param.newBalanceNote.amount < 0n
|
|
4236
4236
|
|| param.oldBalanceNote.amount <= 0n
|
|
4237
|
-
|| param.
|
|
4237
|
+
|| param.inAmount <= 0n
|
|
4238
4238
|
|| param.orderNote.amount <= 0n) {
|
|
4239
4239
|
throw new DarkSwapProofError("Invalid note amount");
|
|
4240
4240
|
}
|
|
4241
4241
|
if (param.orderNote.amount != param.oldBalanceNote.amount - param.newBalanceNote.amount) {
|
|
4242
4242
|
throw new DarkSwapProofError("Invalid order amount");
|
|
4243
4243
|
}
|
|
4244
|
-
const feeAmount = param.
|
|
4244
|
+
const feeAmount = param.inAmount * param.orderNote.feeRatio / FEE_RATIO_PRECISION;
|
|
4245
4245
|
const [[fuzkPubKeyX, fuzkPubKeyY], fuzkPriKey] = await generateKeyPair(param.signedMessage);
|
|
4246
4246
|
let newBalanceFooter = EMPTY_FOOTER;
|
|
4247
4247
|
if (param.oldBalanceNote.amount != 0n) {
|
|
@@ -4277,8 +4277,8 @@ async function generateProCreateOrderProof(param) {
|
|
|
4277
4277
|
order_note_footer: bn_to_0xhex(orderNoteFooter),
|
|
4278
4278
|
order_asset: bn_to_0xhex(encodeAddress(param.orderNote.asset)),
|
|
4279
4279
|
order_amount: bn_to_0xhex(param.orderNote.amount),
|
|
4280
|
-
in_asset: bn_to_0xhex(encodeAddress(param.
|
|
4281
|
-
in_amount: bn_to_0xhex(param.
|
|
4280
|
+
in_asset: bn_to_0xhex(encodeAddress(param.inAsset)),
|
|
4281
|
+
in_amount: bn_to_0xhex(param.inAmount),
|
|
4282
4282
|
pub_key: [fuzkPubKeyX.toString(), fuzkPubKeyY.toString()],
|
|
4283
4283
|
signature: uint8ArrayToNumberArray(signature),
|
|
4284
4284
|
};
|
|
@@ -4312,7 +4312,13 @@ class ProCreateOrderContext extends BaseContext {
|
|
|
4312
4312
|
writable: true,
|
|
4313
4313
|
value: void 0
|
|
4314
4314
|
});
|
|
4315
|
-
Object.defineProperty(this, "
|
|
4315
|
+
Object.defineProperty(this, "_swapInAsset", {
|
|
4316
|
+
enumerable: true,
|
|
4317
|
+
configurable: true,
|
|
4318
|
+
writable: true,
|
|
4319
|
+
value: void 0
|
|
4320
|
+
});
|
|
4321
|
+
Object.defineProperty(this, "_swapInAmount", {
|
|
4316
4322
|
enumerable: true,
|
|
4317
4323
|
configurable: true,
|
|
4318
4324
|
writable: true,
|
|
@@ -4343,11 +4349,17 @@ class ProCreateOrderContext extends BaseContext {
|
|
|
4343
4349
|
get orderNote() {
|
|
4344
4350
|
return this._orderNote;
|
|
4345
4351
|
}
|
|
4346
|
-
set
|
|
4347
|
-
this.
|
|
4352
|
+
set swapInAsset(swapInAsset) {
|
|
4353
|
+
this._swapInAsset = swapInAsset;
|
|
4348
4354
|
}
|
|
4349
|
-
get
|
|
4350
|
-
return this.
|
|
4355
|
+
get swapInAsset() {
|
|
4356
|
+
return this._swapInAsset;
|
|
4357
|
+
}
|
|
4358
|
+
set swapInAmount(swapInAmount) {
|
|
4359
|
+
this._swapInAmount = swapInAmount;
|
|
4360
|
+
}
|
|
4361
|
+
get swapInAmount() {
|
|
4362
|
+
return this._swapInAmount;
|
|
4351
4363
|
}
|
|
4352
4364
|
set oldBalance(oldBalance) {
|
|
4353
4365
|
this._oldBalance = oldBalance;
|
|
@@ -4384,23 +4396,24 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4384
4396
|
constructor(_darkSwap) {
|
|
4385
4397
|
super(_darkSwap);
|
|
4386
4398
|
}
|
|
4387
|
-
async prepare(address,
|
|
4388
|
-
const [pubKey
|
|
4389
|
-
const orderNote = createOrderNoteExt(address,
|
|
4390
|
-
const newBalance = createNote(address,
|
|
4391
|
-
const swapInNote = createNote(address, swapInAsset, swapInAmount, pubKey);
|
|
4399
|
+
async prepare(address, orderAsset, orderAmount, swapInAsset, swapInAmount, balanceNote, signature) {
|
|
4400
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
4401
|
+
const orderNote = createOrderNoteExt(address, orderAsset, orderAmount, FEE_RATIO, pubKey);
|
|
4402
|
+
const newBalance = createNote(address, orderAsset, balanceNote.amount - orderAmount, pubKey);
|
|
4392
4403
|
const context = new ProCreateOrderContext(signature);
|
|
4393
4404
|
context.orderNote = orderNote;
|
|
4394
|
-
context.
|
|
4405
|
+
context.swapInAsset = swapInAsset;
|
|
4406
|
+
context.swapInAmount = swapInAmount;
|
|
4395
4407
|
context.oldBalance = balanceNote;
|
|
4396
4408
|
context.newBalance = newBalance;
|
|
4397
4409
|
context.address = address;
|
|
4398
|
-
return { context, orderNote,
|
|
4410
|
+
return { context, orderNote, newBalance };
|
|
4399
4411
|
}
|
|
4400
4412
|
async generateProof(context) {
|
|
4401
4413
|
if (!context
|
|
4402
4414
|
|| !context.orderNote
|
|
4403
|
-
|| !context.
|
|
4415
|
+
|| !context.swapInAsset
|
|
4416
|
+
|| !context.swapInAmount
|
|
4404
4417
|
|| !context.oldBalance
|
|
4405
4418
|
|| !context.newBalance
|
|
4406
4419
|
|| !context.address
|
|
@@ -4415,7 +4428,8 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4415
4428
|
orderNote: context.orderNote,
|
|
4416
4429
|
oldBalanceNote: context.oldBalance,
|
|
4417
4430
|
newBalanceNote: context.newBalance,
|
|
4418
|
-
|
|
4431
|
+
inAsset: context.swapInAsset,
|
|
4432
|
+
inAmount: context.swapInAmount,
|
|
4419
4433
|
address: context.address,
|
|
4420
4434
|
signedMessage: context.signature,
|
|
4421
4435
|
});
|
|
@@ -4424,7 +4438,13 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4424
4438
|
}
|
|
4425
4439
|
async execute(context) {
|
|
4426
4440
|
await this.generateProof(context);
|
|
4427
|
-
if (!context
|
|
4441
|
+
if (!context
|
|
4442
|
+
|| !context.orderNote
|
|
4443
|
+
|| !context.swapInAsset
|
|
4444
|
+
|| !context.swapInAmount
|
|
4445
|
+
|| !context.oldBalance
|
|
4446
|
+
|| !context.newBalance
|
|
4447
|
+
|| !context.proof) {
|
|
4428
4448
|
throw new DarkSwapError('Invalid context');
|
|
4429
4449
|
}
|
|
4430
4450
|
const contract = new ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, this._darkSwap.signer);
|
|
@@ -6115,7 +6135,7 @@ const contractConfig = {
|
|
|
6115
6135
|
merkleTreeOperator: '0x0', //FIXME
|
|
6116
6136
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6117
6137
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6118
|
-
|
|
6138
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-subgraph/version/v0.0.1/api',
|
|
6119
6139
|
},
|
|
6120
6140
|
[ChainId.ARBITRUM_ONE]: {
|
|
6121
6141
|
priceOracle: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
|
@@ -6124,7 +6144,7 @@ const contractConfig = {
|
|
|
6124
6144
|
merkleTreeOperator: '0x0', //FIXME
|
|
6125
6145
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6126
6146
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6127
|
-
|
|
6147
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-arb-subgraph/api'
|
|
6128
6148
|
},
|
|
6129
6149
|
[ChainId.BASE]: {
|
|
6130
6150
|
priceOracle: '0xf224a25453D76A41c4427DD1C05369BC9f498444',
|
|
@@ -6133,7 +6153,7 @@ const contractConfig = {
|
|
|
6133
6153
|
merkleTreeOperator: '0x0', //FIXME
|
|
6134
6154
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6135
6155
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6136
|
-
|
|
6156
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-base-subgraph/api'
|
|
6137
6157
|
},
|
|
6138
6158
|
[ChainId.SEPOLIA]: {
|
|
6139
6159
|
priceOracle: '0x4Fe44a9aC8Ef059Be2dB97f9e3bcA32Ab698C2f2',
|
|
@@ -6142,7 +6162,7 @@ const contractConfig = {
|
|
|
6142
6162
|
merkleTreeOperator: '0x0', //FIXME
|
|
6143
6163
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6144
6164
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6145
|
-
|
|
6165
|
+
drakSwapSubgraphUrl: ''
|
|
6146
6166
|
},
|
|
6147
6167
|
[ChainId.HARDHAT]: {
|
|
6148
6168
|
priceOracle: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
|
@@ -6151,7 +6171,7 @@ const contractConfig = {
|
|
|
6151
6171
|
merkleTreeOperator: '0xEd8D7d3A98CB4ea6C91a80dcd2220719c264531f',
|
|
6152
6172
|
darkSwapAssetManager: '0xeF66010868Ff77119171628B7eFa0F6179779375',
|
|
6153
6173
|
darkSwapFeeAssetManager: '0xe3EF345391654121f385679613Cea79A692C2Dd8',
|
|
6154
|
-
|
|
6174
|
+
drakSwapSubgraphUrl: 'https://34.142.142.240:8080/subgraphs/name/singularity/',
|
|
6155
6175
|
}
|
|
6156
6176
|
};
|
|
6157
6177
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1846,7 +1846,7 @@
|
|
|
1846
1846
|
name: "retailDepositCreateOrder",
|
|
1847
1847
|
outputs: [
|
|
1848
1848
|
],
|
|
1849
|
-
stateMutability: "
|
|
1849
|
+
stateMutability: "payable",
|
|
1850
1850
|
type: "function"
|
|
1851
1851
|
},
|
|
1852
1852
|
{
|
|
@@ -2943,7 +2943,7 @@
|
|
|
2943
2943
|
const contract = new ethers.ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, signer);
|
|
2944
2944
|
if (!isNativeAsset(context.newBalance.asset)) {
|
|
2945
2945
|
await this.allowance(context);
|
|
2946
|
-
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
2946
|
+
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof, { value: 0n });
|
|
2947
2947
|
await tx.wait();
|
|
2948
2948
|
return tx.hash;
|
|
2949
2949
|
}
|
|
@@ -4234,14 +4234,14 @@
|
|
|
4234
4234
|
}
|
|
4235
4235
|
if (param.newBalanceNote.amount < 0n
|
|
4236
4236
|
|| param.oldBalanceNote.amount <= 0n
|
|
4237
|
-
|| param.
|
|
4237
|
+
|| param.inAmount <= 0n
|
|
4238
4238
|
|| param.orderNote.amount <= 0n) {
|
|
4239
4239
|
throw new DarkSwapProofError("Invalid note amount");
|
|
4240
4240
|
}
|
|
4241
4241
|
if (param.orderNote.amount != param.oldBalanceNote.amount - param.newBalanceNote.amount) {
|
|
4242
4242
|
throw new DarkSwapProofError("Invalid order amount");
|
|
4243
4243
|
}
|
|
4244
|
-
const feeAmount = param.
|
|
4244
|
+
const feeAmount = param.inAmount * param.orderNote.feeRatio / FEE_RATIO_PRECISION;
|
|
4245
4245
|
const [[fuzkPubKeyX, fuzkPubKeyY], fuzkPriKey] = await generateKeyPair(param.signedMessage);
|
|
4246
4246
|
let newBalanceFooter = EMPTY_FOOTER;
|
|
4247
4247
|
if (param.oldBalanceNote.amount != 0n) {
|
|
@@ -4277,8 +4277,8 @@
|
|
|
4277
4277
|
order_note_footer: bn_to_0xhex(orderNoteFooter),
|
|
4278
4278
|
order_asset: bn_to_0xhex(encodeAddress(param.orderNote.asset)),
|
|
4279
4279
|
order_amount: bn_to_0xhex(param.orderNote.amount),
|
|
4280
|
-
in_asset: bn_to_0xhex(encodeAddress(param.
|
|
4281
|
-
in_amount: bn_to_0xhex(param.
|
|
4280
|
+
in_asset: bn_to_0xhex(encodeAddress(param.inAsset)),
|
|
4281
|
+
in_amount: bn_to_0xhex(param.inAmount),
|
|
4282
4282
|
pub_key: [fuzkPubKeyX.toString(), fuzkPubKeyY.toString()],
|
|
4283
4283
|
signature: uint8ArrayToNumberArray(signature),
|
|
4284
4284
|
};
|
|
@@ -4312,7 +4312,13 @@
|
|
|
4312
4312
|
writable: true,
|
|
4313
4313
|
value: void 0
|
|
4314
4314
|
});
|
|
4315
|
-
Object.defineProperty(this, "
|
|
4315
|
+
Object.defineProperty(this, "_swapInAsset", {
|
|
4316
|
+
enumerable: true,
|
|
4317
|
+
configurable: true,
|
|
4318
|
+
writable: true,
|
|
4319
|
+
value: void 0
|
|
4320
|
+
});
|
|
4321
|
+
Object.defineProperty(this, "_swapInAmount", {
|
|
4316
4322
|
enumerable: true,
|
|
4317
4323
|
configurable: true,
|
|
4318
4324
|
writable: true,
|
|
@@ -4343,11 +4349,17 @@
|
|
|
4343
4349
|
get orderNote() {
|
|
4344
4350
|
return this._orderNote;
|
|
4345
4351
|
}
|
|
4346
|
-
set
|
|
4347
|
-
this.
|
|
4352
|
+
set swapInAsset(swapInAsset) {
|
|
4353
|
+
this._swapInAsset = swapInAsset;
|
|
4348
4354
|
}
|
|
4349
|
-
get
|
|
4350
|
-
return this.
|
|
4355
|
+
get swapInAsset() {
|
|
4356
|
+
return this._swapInAsset;
|
|
4357
|
+
}
|
|
4358
|
+
set swapInAmount(swapInAmount) {
|
|
4359
|
+
this._swapInAmount = swapInAmount;
|
|
4360
|
+
}
|
|
4361
|
+
get swapInAmount() {
|
|
4362
|
+
return this._swapInAmount;
|
|
4351
4363
|
}
|
|
4352
4364
|
set oldBalance(oldBalance) {
|
|
4353
4365
|
this._oldBalance = oldBalance;
|
|
@@ -4384,23 +4396,24 @@
|
|
|
4384
4396
|
constructor(_darkSwap) {
|
|
4385
4397
|
super(_darkSwap);
|
|
4386
4398
|
}
|
|
4387
|
-
async prepare(address,
|
|
4388
|
-
const [pubKey
|
|
4389
|
-
const orderNote = createOrderNoteExt(address,
|
|
4390
|
-
const newBalance = createNote(address,
|
|
4391
|
-
const swapInNote = createNote(address, swapInAsset, swapInAmount, pubKey);
|
|
4399
|
+
async prepare(address, orderAsset, orderAmount, swapInAsset, swapInAmount, balanceNote, signature) {
|
|
4400
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
4401
|
+
const orderNote = createOrderNoteExt(address, orderAsset, orderAmount, FEE_RATIO, pubKey);
|
|
4402
|
+
const newBalance = createNote(address, orderAsset, balanceNote.amount - orderAmount, pubKey);
|
|
4392
4403
|
const context = new ProCreateOrderContext(signature);
|
|
4393
4404
|
context.orderNote = orderNote;
|
|
4394
|
-
context.
|
|
4405
|
+
context.swapInAsset = swapInAsset;
|
|
4406
|
+
context.swapInAmount = swapInAmount;
|
|
4395
4407
|
context.oldBalance = balanceNote;
|
|
4396
4408
|
context.newBalance = newBalance;
|
|
4397
4409
|
context.address = address;
|
|
4398
|
-
return { context, orderNote,
|
|
4410
|
+
return { context, orderNote, newBalance };
|
|
4399
4411
|
}
|
|
4400
4412
|
async generateProof(context) {
|
|
4401
4413
|
if (!context
|
|
4402
4414
|
|| !context.orderNote
|
|
4403
|
-
|| !context.
|
|
4415
|
+
|| !context.swapInAsset
|
|
4416
|
+
|| !context.swapInAmount
|
|
4404
4417
|
|| !context.oldBalance
|
|
4405
4418
|
|| !context.newBalance
|
|
4406
4419
|
|| !context.address
|
|
@@ -4415,7 +4428,8 @@
|
|
|
4415
4428
|
orderNote: context.orderNote,
|
|
4416
4429
|
oldBalanceNote: context.oldBalance,
|
|
4417
4430
|
newBalanceNote: context.newBalance,
|
|
4418
|
-
|
|
4431
|
+
inAsset: context.swapInAsset,
|
|
4432
|
+
inAmount: context.swapInAmount,
|
|
4419
4433
|
address: context.address,
|
|
4420
4434
|
signedMessage: context.signature,
|
|
4421
4435
|
});
|
|
@@ -4424,7 +4438,13 @@
|
|
|
4424
4438
|
}
|
|
4425
4439
|
async execute(context) {
|
|
4426
4440
|
await this.generateProof(context);
|
|
4427
|
-
if (!context
|
|
4441
|
+
if (!context
|
|
4442
|
+
|| !context.orderNote
|
|
4443
|
+
|| !context.swapInAsset
|
|
4444
|
+
|| !context.swapInAmount
|
|
4445
|
+
|| !context.oldBalance
|
|
4446
|
+
|| !context.newBalance
|
|
4447
|
+
|| !context.proof) {
|
|
4428
4448
|
throw new DarkSwapError('Invalid context');
|
|
4429
4449
|
}
|
|
4430
4450
|
const contract = new ethers.ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, this._darkSwap.signer);
|
|
@@ -6115,7 +6135,7 @@
|
|
|
6115
6135
|
merkleTreeOperator: '0x0', //FIXME
|
|
6116
6136
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6117
6137
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6118
|
-
|
|
6138
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-subgraph/version/v0.0.1/api',
|
|
6119
6139
|
},
|
|
6120
6140
|
[exports.ChainId.ARBITRUM_ONE]: {
|
|
6121
6141
|
priceOracle: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
|
@@ -6124,7 +6144,7 @@
|
|
|
6124
6144
|
merkleTreeOperator: '0x0', //FIXME
|
|
6125
6145
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6126
6146
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6127
|
-
|
|
6147
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-arb-subgraph/api'
|
|
6128
6148
|
},
|
|
6129
6149
|
[exports.ChainId.BASE]: {
|
|
6130
6150
|
priceOracle: '0xf224a25453D76A41c4427DD1C05369BC9f498444',
|
|
@@ -6133,7 +6153,7 @@
|
|
|
6133
6153
|
merkleTreeOperator: '0x0', //FIXME
|
|
6134
6154
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6135
6155
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6136
|
-
|
|
6156
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-base-subgraph/api'
|
|
6137
6157
|
},
|
|
6138
6158
|
[exports.ChainId.SEPOLIA]: {
|
|
6139
6159
|
priceOracle: '0x4Fe44a9aC8Ef059Be2dB97f9e3bcA32Ab698C2f2',
|
|
@@ -6142,7 +6162,7 @@
|
|
|
6142
6162
|
merkleTreeOperator: '0x0', //FIXME
|
|
6143
6163
|
darkSwapAssetManager: '0x0', //FIXME
|
|
6144
6164
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
6145
|
-
|
|
6165
|
+
drakSwapSubgraphUrl: ''
|
|
6146
6166
|
},
|
|
6147
6167
|
[exports.ChainId.HARDHAT]: {
|
|
6148
6168
|
priceOracle: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
|
@@ -6151,7 +6171,7 @@
|
|
|
6151
6171
|
merkleTreeOperator: '0xEd8D7d3A98CB4ea6C91a80dcd2220719c264531f',
|
|
6152
6172
|
darkSwapAssetManager: '0xeF66010868Ff77119171628B7eFa0F6179779375',
|
|
6153
6173
|
darkSwapFeeAssetManager: '0xe3EF345391654121f385679613Cea79A692C2Dd8',
|
|
6154
|
-
|
|
6174
|
+
drakSwapSubgraphUrl: 'https://34.142.142.240:8080/subgraphs/name/singularity/',
|
|
6155
6175
|
}
|
|
6156
6176
|
};
|
|
6157
6177
|
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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SwapSubgraphUrl: string;
|
|
9
9
|
};
|
|
10
10
|
export declare const contractConfig: {
|
|
11
11
|
[chainId: number]: ContractConfiguartion;
|
|
@@ -6,7 +6,8 @@ export type ProCreateOrderProofParam = BaseProofParam & {
|
|
|
6
6
|
oldBalanceNote: DarkSwapNote;
|
|
7
7
|
newBalanceNote: DarkSwapNote;
|
|
8
8
|
orderNote: DarkSwapOrderNote;
|
|
9
|
-
|
|
9
|
+
inAsset: string;
|
|
10
|
+
inAmount: bigint;
|
|
10
11
|
};
|
|
11
12
|
export type ProCreateOrderProofResult = BaseProofResult & {
|
|
12
13
|
oldBalanceNullifier: string;
|
|
@@ -6,15 +6,18 @@ declare class ProCreateOrderContext extends BaseContext {
|
|
|
6
6
|
private _orderNote?;
|
|
7
7
|
private _oldBalance?;
|
|
8
8
|
private _newBalance?;
|
|
9
|
-
private
|
|
9
|
+
private _swapInAsset?;
|
|
10
|
+
private _swapInAmount?;
|
|
10
11
|
private _proof?;
|
|
11
12
|
private _feeAmount?;
|
|
12
13
|
private _swapMessage?;
|
|
13
14
|
constructor(signature: string);
|
|
14
15
|
set orderNote(orderNote: DarkSwapOrderNote | undefined);
|
|
15
16
|
get orderNote(): DarkSwapOrderNote | undefined;
|
|
16
|
-
set
|
|
17
|
-
get
|
|
17
|
+
set swapInAsset(swapInAsset: string | undefined);
|
|
18
|
+
get swapInAsset(): string | undefined;
|
|
19
|
+
set swapInAmount(swapInAmount: bigint | undefined);
|
|
20
|
+
get swapInAmount(): bigint | undefined;
|
|
18
21
|
set oldBalance(oldBalance: DarkSwapNote | undefined);
|
|
19
22
|
get oldBalance(): DarkSwapNote | undefined;
|
|
20
23
|
set newBalance(newBalance: DarkSwapNote | undefined);
|
|
@@ -28,10 +31,9 @@ declare class ProCreateOrderContext extends BaseContext {
|
|
|
28
31
|
}
|
|
29
32
|
export declare class ProCreateOrderService extends BaseContractService {
|
|
30
33
|
constructor(_darkSwap: DarkSwap);
|
|
31
|
-
prepare(address: string,
|
|
34
|
+
prepare(address: string, orderAsset: string, orderAmount: bigint, swapInAsset: string, swapInAmount: bigint, balanceNote: DarkSwapNote, signature: string): Promise<{
|
|
32
35
|
context: ProCreateOrderContext;
|
|
33
36
|
orderNote: DarkSwapOrderNote;
|
|
34
|
-
swapInNote: DarkSwapNote;
|
|
35
37
|
newBalance: DarkSwapNote;
|
|
36
38
|
}>;
|
|
37
39
|
private generateProof;
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ export type ContractConfiguartion = {
|
|
|
7
7
|
merkleTreeOperator: string;
|
|
8
8
|
darkSwapAssetManager: string;
|
|
9
9
|
darkSwapFeeAssetManager: string;
|
|
10
|
-
|
|
10
|
+
drakSwapSubgraphUrl: string;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const contractConfig: { [chainId: number]: ContractConfiguartion } = {
|
|
@@ -18,7 +18,7 @@ export const contractConfig: { [chainId: number]: ContractConfiguartion } = {
|
|
|
18
18
|
merkleTreeOperator: '0x0', //FIXME
|
|
19
19
|
darkSwapAssetManager: '0x0', //FIXME
|
|
20
20
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
21
|
-
|
|
21
|
+
drakSwapSubgraphUrl:
|
|
22
22
|
'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-subgraph/version/v0.0.1/api',
|
|
23
23
|
},
|
|
24
24
|
[ChainId.ARBITRUM_ONE]: {
|
|
@@ -28,7 +28,7 @@ export const contractConfig: { [chainId: number]: ContractConfiguartion } = {
|
|
|
28
28
|
merkleTreeOperator: '0x0', //FIXME
|
|
29
29
|
darkSwapAssetManager: '0x0', //FIXME
|
|
30
30
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
31
|
-
|
|
31
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-arb-subgraph/api'
|
|
32
32
|
},
|
|
33
33
|
[ChainId.BASE]: {
|
|
34
34
|
priceOracle: '0xf224a25453D76A41c4427DD1C05369BC9f498444',
|
|
@@ -37,7 +37,7 @@ export const contractConfig: { [chainId: number]: ContractConfiguartion } = {
|
|
|
37
37
|
merkleTreeOperator: '0x0', //FIXME
|
|
38
38
|
darkSwapAssetManager: '0x0', //FIXME
|
|
39
39
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
40
|
-
|
|
40
|
+
drakSwapSubgraphUrl: 'https://subgraph.satsuma-prod.com/1c6a44a9ed6e/pgs-team--611591/singularity-base-subgraph/api'
|
|
41
41
|
},
|
|
42
42
|
[ChainId.SEPOLIA]: {
|
|
43
43
|
priceOracle: '0x4Fe44a9aC8Ef059Be2dB97f9e3bcA32Ab698C2f2',
|
|
@@ -46,7 +46,7 @@ export const contractConfig: { [chainId: number]: ContractConfiguartion } = {
|
|
|
46
46
|
merkleTreeOperator: '0x0', //FIXME
|
|
47
47
|
darkSwapAssetManager: '0x0', //FIXME
|
|
48
48
|
darkSwapFeeAssetManager: '0x0', //FIXME
|
|
49
|
-
|
|
49
|
+
drakSwapSubgraphUrl: ''
|
|
50
50
|
},
|
|
51
51
|
[ChainId.HARDHAT]: {
|
|
52
52
|
priceOracle: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
|
@@ -55,7 +55,7 @@ export const contractConfig: { [chainId: number]: ContractConfiguartion } = {
|
|
|
55
55
|
merkleTreeOperator: '0xEd8D7d3A98CB4ea6C91a80dcd2220719c264531f',
|
|
56
56
|
darkSwapAssetManager: '0xeF66010868Ff77119171628B7eFa0F6179779375',
|
|
57
57
|
darkSwapFeeAssetManager: '0xe3EF345391654121f385679613Cea79A692C2Dd8',
|
|
58
|
-
|
|
58
|
+
drakSwapSubgraphUrl: 'https://34.142.142.240:8080/subgraphs/name/singularity/',
|
|
59
59
|
|
|
60
60
|
}
|
|
61
61
|
};
|
|
@@ -47,7 +47,8 @@ export type ProCreateOrderProofParam = BaseProofParam & {
|
|
|
47
47
|
oldBalanceNote: DarkSwapNote,
|
|
48
48
|
newBalanceNote: DarkSwapNote,
|
|
49
49
|
orderNote: DarkSwapOrderNote,
|
|
50
|
-
|
|
50
|
+
inAsset: string,
|
|
51
|
+
inAmount: bigint,
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
export type ProCreateOrderProofResult = BaseProofResult & {
|
|
@@ -63,7 +64,7 @@ export async function generateProCreateOrderProof(param: ProCreateOrderProofPara
|
|
|
63
64
|
|
|
64
65
|
if (param.newBalanceNote.amount < 0n
|
|
65
66
|
|| param.oldBalanceNote.amount <= 0n
|
|
66
|
-
|| param.
|
|
67
|
+
|| param.inAmount <= 0n
|
|
67
68
|
|| param.orderNote.amount <= 0n) {
|
|
68
69
|
throw new DarkSwapProofError("Invalid note amount");
|
|
69
70
|
}
|
|
@@ -72,7 +73,7 @@ export async function generateProCreateOrderProof(param: ProCreateOrderProofPara
|
|
|
72
73
|
throw new DarkSwapProofError("Invalid order amount");
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
const feeAmount = param.
|
|
76
|
+
const feeAmount = param.inAmount * param.orderNote.feeRatio / FEE_RATIO_PRECISION;
|
|
76
77
|
|
|
77
78
|
const [[fuzkPubKeyX, fuzkPubKeyY], fuzkPriKey] = await generateKeyPair(param.signedMessage);
|
|
78
79
|
|
|
@@ -116,8 +117,8 @@ export async function generateProCreateOrderProof(param: ProCreateOrderProofPara
|
|
|
116
117
|
order_note_footer: bn_to_0xhex(orderNoteFooter),
|
|
117
118
|
order_asset: bn_to_0xhex(encodeAddress(param.orderNote.asset)),
|
|
118
119
|
order_amount: bn_to_0xhex(param.orderNote.amount),
|
|
119
|
-
in_asset: bn_to_0xhex(encodeAddress(param.
|
|
120
|
-
in_amount: bn_to_0xhex(param.
|
|
120
|
+
in_asset: bn_to_0xhex(encodeAddress(param.inAsset)),
|
|
121
|
+
in_amount: bn_to_0xhex(param.inAmount),
|
|
121
122
|
|
|
122
123
|
pub_key: [fuzkPubKeyX.toString(), fuzkPubKeyY.toString()],
|
|
123
124
|
signature: uint8ArrayToNumberArray(signature),
|
|
@@ -131,7 +131,8 @@ export class DepositService extends BaseContractService {
|
|
|
131
131
|
context.proof.oldBalanceNullifier,
|
|
132
132
|
hexlify32(context.newBalance.note),
|
|
133
133
|
context.proof.newBalanceFooter,
|
|
134
|
-
context.proof.proof
|
|
134
|
+
context.proof.proof,
|
|
135
|
+
{ value: 0n }
|
|
135
136
|
);
|
|
136
137
|
await tx.wait();
|
|
137
138
|
return tx.hash;
|
|
@@ -14,7 +14,8 @@ class ProCreateOrderContext extends BaseContext {
|
|
|
14
14
|
private _orderNote?: DarkSwapOrderNote;
|
|
15
15
|
private _oldBalance?: DarkSwapNote;
|
|
16
16
|
private _newBalance?: DarkSwapNote;
|
|
17
|
-
private
|
|
17
|
+
private _swapInAsset?: string;
|
|
18
|
+
private _swapInAmount?: bigint;
|
|
18
19
|
private _proof?: ProCreateOrderProofResult;
|
|
19
20
|
private _feeAmount?: bigint;
|
|
20
21
|
private _swapMessage?: DarkSwapMessage;
|
|
@@ -31,12 +32,20 @@ class ProCreateOrderContext extends BaseContext {
|
|
|
31
32
|
return this._orderNote;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
set
|
|
35
|
-
this.
|
|
35
|
+
set swapInAsset(swapInAsset: string | undefined) {
|
|
36
|
+
this._swapInAsset = swapInAsset;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
get
|
|
39
|
-
return this.
|
|
39
|
+
get swapInAsset(): string | undefined {
|
|
40
|
+
return this._swapInAsset;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set swapInAmount(swapInAmount: bigint | undefined) {
|
|
44
|
+
this._swapInAmount = swapInAmount;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get swapInAmount(): bigint | undefined {
|
|
48
|
+
return this._swapInAmount;
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
set oldBalance(oldBalance: DarkSwapNote | undefined) {
|
|
@@ -87,30 +96,31 @@ export class ProCreateOrderService extends BaseContractService {
|
|
|
87
96
|
|
|
88
97
|
public async prepare(
|
|
89
98
|
address: string,
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
orderAsset: string,
|
|
100
|
+
orderAmount: bigint,
|
|
92
101
|
swapInAsset: string,
|
|
93
102
|
swapInAmount: bigint,
|
|
94
103
|
balanceNote: DarkSwapNote,
|
|
95
104
|
signature: string
|
|
96
|
-
): Promise<{ context: ProCreateOrderContext; orderNote: DarkSwapOrderNote,
|
|
97
|
-
const [pubKey
|
|
98
|
-
const orderNote = createOrderNoteExt(address,
|
|
99
|
-
const newBalance = createNote(address,
|
|
100
|
-
const swapInNote = createNote(address, swapInAsset, swapInAmount, pubKey);
|
|
105
|
+
): Promise<{ context: ProCreateOrderContext; orderNote: DarkSwapOrderNote, newBalance: DarkSwapNote }> {
|
|
106
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
107
|
+
const orderNote = createOrderNoteExt(address, orderAsset, orderAmount, FEE_RATIO, pubKey);
|
|
108
|
+
const newBalance = createNote(address, orderAsset, balanceNote.amount - orderAmount, pubKey);
|
|
101
109
|
const context = new ProCreateOrderContext(signature);
|
|
102
110
|
context.orderNote = orderNote;
|
|
103
|
-
context.
|
|
111
|
+
context.swapInAsset = swapInAsset;
|
|
112
|
+
context.swapInAmount = swapInAmount;
|
|
104
113
|
context.oldBalance = balanceNote;
|
|
105
114
|
context.newBalance = newBalance;
|
|
106
115
|
context.address = address;
|
|
107
|
-
return { context, orderNote,
|
|
116
|
+
return { context, orderNote, newBalance };
|
|
108
117
|
}
|
|
109
118
|
|
|
110
119
|
private async generateProof(context: ProCreateOrderContext): Promise<void> {
|
|
111
120
|
if (!context
|
|
112
121
|
|| !context.orderNote
|
|
113
|
-
|| !context.
|
|
122
|
+
|| !context.swapInAsset
|
|
123
|
+
|| !context.swapInAmount
|
|
114
124
|
|| !context.oldBalance
|
|
115
125
|
|| !context.newBalance
|
|
116
126
|
|| !context.address
|
|
@@ -127,7 +137,8 @@ export class ProCreateOrderService extends BaseContractService {
|
|
|
127
137
|
orderNote: context.orderNote,
|
|
128
138
|
oldBalanceNote: context.oldBalance,
|
|
129
139
|
newBalanceNote: context.newBalance,
|
|
130
|
-
|
|
140
|
+
inAsset: context.swapInAsset,
|
|
141
|
+
inAmount: context.swapInAmount,
|
|
131
142
|
address: context.address,
|
|
132
143
|
signedMessage: context.signature,
|
|
133
144
|
});
|
|
@@ -137,7 +148,13 @@ export class ProCreateOrderService extends BaseContractService {
|
|
|
137
148
|
|
|
138
149
|
public async execute(context: ProCreateOrderContext): Promise<string> {
|
|
139
150
|
await this.generateProof(context);
|
|
140
|
-
if (!context
|
|
151
|
+
if (!context
|
|
152
|
+
|| !context.orderNote
|
|
153
|
+
|| !context.swapInAsset
|
|
154
|
+
|| !context.swapInAmount
|
|
155
|
+
|| !context.oldBalance
|
|
156
|
+
|| !context.newBalance
|
|
157
|
+
|| !context.proof) {
|
|
141
158
|
throw new DarkSwapError('Invalid context');
|
|
142
159
|
}
|
|
143
160
|
|