@thesingularitynetwork/darkswap-sdk 0.1.11 → 0.1.13
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 +662 -609
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +662 -609
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +668 -609
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/proof/pro/orders/swapProof.d.ts +1 -0
- package/dist/types/src/proof/retail/depositOrderProof.d.ts +1 -1
- package/dist/types/src/proof/retail/swapProof.d.ts +0 -2
- package/dist/types/src/services/agent/index.d.ts +1 -0
- package/dist/types/src/services/agent/retailSwap.d.ts +25 -0
- package/dist/types/src/services/pro/index.d.ts +0 -1
- package/dist/types/src/services/pro/proSwap.d.ts +6 -1
- package/dist/types/src/services/pro/swapMessage.d.ts +2 -2
- package/dist/types/src/types.d.ts +2 -0
- package/dist/types/test/services/pro/proSwap.test.d.ts +1 -0
- package/dist/types/test/utils/helpers.d.ts +3 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/proof/pro/orders/swapProof.ts +8 -11
- package/src/proof/retail/depositOrderProof.ts +6 -3
- package/src/proof/retail/swapProof.ts +5 -10
- package/src/services/agent/index.ts +1 -0
- package/src/services/agent/retailSwap.ts +116 -0
- package/src/services/pro/cancelOrder.ts +1 -1
- package/src/services/pro/createOrder.ts +2 -2
- package/src/services/pro/index.ts +1 -2
- package/src/services/pro/proSwap.ts +53 -16
- package/src/services/retail/depositAndCreateOrder.ts +1 -1
- package/src/types.ts +2 -0
- package/src/utils/swapUtils.ts +20 -5
- package/src/services/pro/swapMessage.ts +0 -13
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":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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -10,5 +10,5 @@ export type RetailCreateOrderProofResult = BaseProofResult & {
|
|
|
10
10
|
depositFooter: string;
|
|
11
11
|
swapInNoteFooter: string;
|
|
12
12
|
};
|
|
13
|
-
export declare function generateRetailSwapMessage(address: string, orderNote: DarkSwapOrderNote, swapInNote: DarkSwapNote, pubKey: [Fr, Fr], privKey: Fr): Promise<DarkSwapMessage>;
|
|
13
|
+
export declare function generateRetailSwapMessage(address: string, orderNote: DarkSwapOrderNote, swapInNote: DarkSwapNote, feeAmount: bigint, pubKey: [Fr, Fr], privKey: Fr): Promise<DarkSwapMessage>;
|
|
14
14
|
export declare function generateRetailCreateOrderProof(param: RetailCreateOrderProofParam): Promise<RetailCreateOrderProofResult>;
|
|
@@ -3,11 +3,9 @@ export type RetailSwapProofParam = {
|
|
|
3
3
|
merkleRoot: string;
|
|
4
4
|
aliceMerkleIndex: number[];
|
|
5
5
|
aliceMerklePath: string[];
|
|
6
|
-
aliceAddress: string;
|
|
7
6
|
aliceMessage: DarkSwapMessage;
|
|
8
7
|
bobMerkleIndex: number[];
|
|
9
8
|
bobMerklePath: string[];
|
|
10
|
-
bobAddress: string;
|
|
11
9
|
bobMessage: DarkSwapMessage;
|
|
12
10
|
};
|
|
13
11
|
export type RetailSwapProofResult = BaseProofResult & {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './retailSwap';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DarkSwap } from '../../darkSwap';
|
|
2
|
+
import { RetailSwapProofResult } from '../../proof/retail/swapProof';
|
|
3
|
+
import { DarkSwapMessage } from '../../types';
|
|
4
|
+
import { BaseContext, BaseContractService } from '../BaseService';
|
|
5
|
+
declare class RetailSwapContext extends BaseContext {
|
|
6
|
+
private _aliceSwapMessage?;
|
|
7
|
+
private _bobSwapMessage?;
|
|
8
|
+
private _proof?;
|
|
9
|
+
constructor(signature: string);
|
|
10
|
+
set aliceSwapMessage(aliceSwapMessage: DarkSwapMessage | undefined);
|
|
11
|
+
get aliceSwapMessage(): DarkSwapMessage | undefined;
|
|
12
|
+
set bobSwapMessage(bobSwapMessage: DarkSwapMessage | undefined);
|
|
13
|
+
get bobSwapMessage(): DarkSwapMessage | undefined;
|
|
14
|
+
set proof(proof: RetailSwapProofResult | undefined);
|
|
15
|
+
get proof(): RetailSwapProofResult | undefined;
|
|
16
|
+
}
|
|
17
|
+
export declare class RetailSwapService extends BaseContractService {
|
|
18
|
+
constructor(_darkSwap: DarkSwap);
|
|
19
|
+
prepare(aliceSwapMessage: DarkSwapMessage, bobSwapMessage: DarkSwapMessage): Promise<{
|
|
20
|
+
context: RetailSwapContext;
|
|
21
|
+
}>;
|
|
22
|
+
private generateProof;
|
|
23
|
+
execute(context: RetailSwapContext): Promise<string>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -9,6 +9,7 @@ declare class ProSwapContext extends BaseContext {
|
|
|
9
9
|
private _proof?;
|
|
10
10
|
private _bobAddress?;
|
|
11
11
|
private _bobSwapMessage?;
|
|
12
|
+
private _aliceFeeAmount?;
|
|
12
13
|
constructor(signature: string);
|
|
13
14
|
set orderNote(orderNote: DarkSwapOrderNote | undefined);
|
|
14
15
|
get orderNote(): DarkSwapOrderNote | undefined;
|
|
@@ -16,6 +17,8 @@ declare class ProSwapContext extends BaseContext {
|
|
|
16
17
|
get changeNote(): DarkSwapNote | undefined;
|
|
17
18
|
set swapInNote(swapInNote: DarkSwapNote | undefined);
|
|
18
19
|
get swapInNote(): DarkSwapNote | undefined;
|
|
20
|
+
set aliceFeeAmount(aliceFeeAmount: bigint | undefined);
|
|
21
|
+
get aliceFeeAmount(): bigint | undefined;
|
|
19
22
|
set proof(proof: ProSwapProofResult | undefined);
|
|
20
23
|
get proof(): ProSwapProofResult | undefined;
|
|
21
24
|
set bobSwapMessage(bobSwapMessage: DarkSwapMessage | undefined);
|
|
@@ -25,10 +28,12 @@ declare class ProSwapContext extends BaseContext {
|
|
|
25
28
|
}
|
|
26
29
|
export declare class ProSwapService extends BaseContractService {
|
|
27
30
|
constructor(_darkSwap: DarkSwap);
|
|
28
|
-
|
|
31
|
+
static prepareProSwapMessageForBob(address: string, orderNote: DarkSwapOrderNote, swapInAmount: bigint, swapInAsset: string, signature: string): Promise<DarkSwapMessage>;
|
|
32
|
+
prepare(address: string, orderNote: DarkSwapOrderNote, bobAddress: string, bobSwapMessage: DarkSwapMessage, signature: string): Promise<{
|
|
29
33
|
context: ProSwapContext;
|
|
30
34
|
swapInNote: DarkSwapNote;
|
|
31
35
|
changeNote: DarkSwapNote;
|
|
36
|
+
feeAmount: bigint;
|
|
32
37
|
}>;
|
|
33
38
|
private generateProof;
|
|
34
39
|
execute(context: ProSwapContext): Promise<string>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DarkSwapMessage,
|
|
2
|
-
export declare function
|
|
1
|
+
import { DarkSwapMessage, DarkSwapOrderNote } from "../..";
|
|
2
|
+
export declare function prepareProSwapMessageForBob(address: string, orderNote: DarkSwapOrderNote, swapInAmount: bigint, swapInAsset: string, signature: string): Promise<DarkSwapMessage>;
|
|
@@ -49,9 +49,11 @@ export type BaseProofInput = {
|
|
|
49
49
|
signature: any;
|
|
50
50
|
};
|
|
51
51
|
export type DarkSwapMessage = {
|
|
52
|
+
address: string;
|
|
52
53
|
orderNote: DarkSwapOrderNote;
|
|
53
54
|
orderNullifier: string;
|
|
54
55
|
inNote: DarkSwapNote;
|
|
56
|
+
feeAmount: bigint;
|
|
55
57
|
publicKey: [Fr, Fr];
|
|
56
58
|
signature: string;
|
|
57
59
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import { DarkSwap } from "../../src";
|
|
3
3
|
export declare function getAliceWallet(): ethers.Wallet;
|
|
4
|
+
export declare function getBobWallet(): ethers.Wallet;
|
|
4
5
|
export declare function getAliceSignature(): Promise<string>;
|
|
6
|
+
export declare function getBobSignature(): Promise<string>;
|
|
5
7
|
export declare function getAliceWalletBalance(asset: string): Promise<any>;
|
|
6
8
|
export declare function getDarkSwapForAlice(): DarkSwap;
|
|
9
|
+
export declare function getDarkSwapForBob(): DarkSwap;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import swapCircuit from "../../../circuits/pro/dark_swap_pro_swap_compiled_circuit.json";
|
|
2
|
-
import { BaseProofResult, DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote, DarkSwapProofError,
|
|
2
|
+
import { BaseProofResult, DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote, DarkSwapProofError, EMPTY_FOOTER, PROOF_DOMAIN } from "../../../types";
|
|
3
3
|
import { encodeAddress } from "../../../utils/encoders";
|
|
4
4
|
import { bn_to_0xhex, bn_to_hex } from "../../../utils/formatters";
|
|
5
5
|
import { mimc_bn254 } from "../../../utils/mimc";
|
|
@@ -72,6 +72,7 @@ export type ProSwapProofParam = {
|
|
|
72
72
|
aliceMerklePath: string[],
|
|
73
73
|
aliceAddress: string,
|
|
74
74
|
aliceOrderNote: DarkSwapOrderNote,
|
|
75
|
+
aliceFeeAmount: bigint,
|
|
75
76
|
aliceInNote: DarkSwapNote,
|
|
76
77
|
aliceChangeNote: DarkSwapNote,
|
|
77
78
|
aliceSignedMessage: string,
|
|
@@ -104,19 +105,16 @@ export async function generateProSwapProof(param: ProSwapProofParam): Promise<Pr
|
|
|
104
105
|
throw new DarkSwapProofError("Invalid note amount");
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
if (param.aliceOrderNote.amount != param.aliceChangeNote.amount
|
|
108
|
-
|| param.bobMessage.orderNote.amount != param.aliceInNote.amount) {
|
|
108
|
+
if (param.aliceOrderNote.amount != param.aliceChangeNote.amount + param.bobMessage.inNote.amount + param.bobMessage.feeAmount
|
|
109
|
+
|| param.bobMessage.orderNote.amount != param.aliceInNote.amount + param.aliceFeeAmount) {
|
|
109
110
|
throw new DarkSwapProofError("Invalid order amount");
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
const aliceFeeAmount = param.aliceInNote.amount * param.aliceOrderNote.feeRatio / FEE_RATIO_PRECISION;
|
|
113
|
-
const bobFeeAmount = param.bobMessage.inNote.amount * param.bobMessage.orderNote.feeRatio / FEE_RATIO_PRECISION;
|
|
114
|
-
|
|
115
113
|
const [[fuzkPubKeyX, fuzkPubKeyY], fuzkPriKey] = await generateKeyPair(param.aliceSignedMessage);
|
|
116
114
|
|
|
117
115
|
const aliceOrderNoteNullifier = calcNullifier(param.aliceOrderNote.rho, [fuzkPubKeyX, fuzkPubKeyY]);
|
|
118
116
|
const aliceInNoteFooter = getNoteFooter(param.aliceInNote.rho, [fuzkPubKeyX, fuzkPubKeyY]);
|
|
119
|
-
const aliceChangeNoteFooter = getNoteFooter(param.aliceChangeNote.rho, [fuzkPubKeyX, fuzkPubKeyY]);
|
|
117
|
+
const aliceChangeNoteFooter = param.aliceChangeNote.amount == 0n ? EMPTY_FOOTER : getNoteFooter(param.aliceChangeNote.rho, [fuzkPubKeyX, fuzkPubKeyY]);
|
|
120
118
|
const bobOrderNoteNullifier = calcNullifier(param.bobMessage.orderNote.rho, param.bobMessage.publicKey);
|
|
121
119
|
const bobInNoteFooter = getNoteFooter(param.bobMessage.inNote.rho, param.bobMessage.publicKey);
|
|
122
120
|
|
|
@@ -136,7 +134,6 @@ export async function generateProSwapProof(param: ProSwapProofParam): Promise<Pr
|
|
|
136
134
|
|
|
137
135
|
const inputs: ProSwapProofInput = {
|
|
138
136
|
merkle_root: param.merkleRoot,
|
|
139
|
-
|
|
140
137
|
alice_merkle_index: param.aliceMerkleIndex,
|
|
141
138
|
alice_merkle_path: param.aliceMerklePath,
|
|
142
139
|
alice_address: bn_to_0xhex(aliceAddressMod),
|
|
@@ -145,7 +142,7 @@ export async function generateProSwapProof(param: ProSwapProofParam): Promise<Pr
|
|
|
145
142
|
alice_out_nullifier: bn_to_0xhex(aliceOrderNoteNullifier),
|
|
146
143
|
alice_out_amount: bn_to_0xhex(param.aliceOrderNote.amount),
|
|
147
144
|
alice_fee_ratio: bn_to_0xhex(param.aliceOrderNote.feeRatio),
|
|
148
|
-
alice_fee_amount: bn_to_0xhex(aliceFeeAmount),
|
|
145
|
+
alice_fee_amount: bn_to_0xhex(param.aliceFeeAmount),
|
|
149
146
|
|
|
150
147
|
alice_in_note: bn_to_0xhex(param.aliceInNote.note),
|
|
151
148
|
alice_in_rho: bn_to_0xhex(param.aliceInNote.rho),
|
|
@@ -161,7 +158,7 @@ export async function generateProSwapProof(param: ProSwapProofParam): Promise<Pr
|
|
|
161
158
|
bob_out_asset: bn_to_0xhex(encodeAddress(param.bobMessage.orderNote.asset)),
|
|
162
159
|
bob_out_amount: bn_to_0xhex(param.bobMessage.orderNote.amount),
|
|
163
160
|
bob_in_asset: bn_to_0xhex(encodeAddress(param.bobMessage.inNote.asset)),
|
|
164
|
-
bob_in_amount: bn_to_0xhex(param.bobMessage.inNote.amount),
|
|
161
|
+
bob_in_amount: bn_to_0xhex(param.bobMessage.inNote.amount + param.bobMessage.feeAmount),
|
|
165
162
|
|
|
166
163
|
bob_merkle_index: param.bobMerkleIndex,
|
|
167
164
|
bob_merkle_path: param.bobMerklePath,
|
|
@@ -171,7 +168,7 @@ export async function generateProSwapProof(param: ProSwapProofParam): Promise<Pr
|
|
|
171
168
|
bob_out_rho: bn_to_0xhex(param.bobMessage.orderNote.rho),
|
|
172
169
|
bob_out_nullifier: bn_to_0xhex(bobOrderNoteNullifier),
|
|
173
170
|
bob_fee_ratio: bn_to_0xhex(param.bobMessage.orderNote.feeRatio),
|
|
174
|
-
bob_fee_amount: bn_to_0xhex(
|
|
171
|
+
bob_fee_amount: bn_to_0xhex(param.bobMessage.feeAmount),
|
|
175
172
|
|
|
176
173
|
bob_in_note: bn_to_0xhex(param.bobMessage.inNote.note),
|
|
177
174
|
bob_in_rho: bn_to_0xhex(param.bobMessage.inNote.rho),
|
|
@@ -49,25 +49,28 @@ export async function generateRetailSwapMessage(
|
|
|
49
49
|
address: string,
|
|
50
50
|
orderNote: DarkSwapOrderNote,
|
|
51
51
|
swapInNote: DarkSwapNote,
|
|
52
|
+
feeAmount: bigint,
|
|
52
53
|
pubKey: [Fr, Fr],
|
|
53
54
|
privKey: Fr
|
|
54
55
|
): Promise<DarkSwapMessage> {
|
|
55
56
|
|
|
56
57
|
const addressMod = encodeAddress(address);
|
|
57
|
-
const orderNoteNullifier =
|
|
58
|
+
const orderNoteNullifier = calcNullifier(orderNote.rho, pubKey);
|
|
58
59
|
const message = bn_to_hex(mimc_bn254([
|
|
59
60
|
BigInt(PROOF_DOMAIN.RETAIL_CREATE_ORDER),
|
|
60
61
|
addressMod,
|
|
61
|
-
|
|
62
|
+
orderNoteNullifier,
|
|
62
63
|
orderNote.feeRatio,
|
|
63
64
|
swapInNote.note,
|
|
64
65
|
]));
|
|
65
66
|
const signature = await signMessage(message, privKey);
|
|
66
67
|
|
|
67
68
|
return {
|
|
69
|
+
address: address,
|
|
68
70
|
orderNote: orderNote,
|
|
69
|
-
orderNullifier: orderNoteNullifier,
|
|
71
|
+
orderNullifier: bn_to_0xhex(orderNoteNullifier),
|
|
70
72
|
inNote: swapInNote,
|
|
73
|
+
feeAmount: feeAmount,
|
|
71
74
|
publicKey: pubKey,
|
|
72
75
|
signature: signatureToHexString(signature),
|
|
73
76
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { Field } from "@noir-lang/types";
|
|
2
1
|
import retailSwapCircuit from "../../circuits/retail/dark_swap_retail_swap_compiled_circuit.json";
|
|
3
|
-
import { BaseProofResult, DarkSwapMessage,
|
|
2
|
+
import { BaseProofResult, DarkSwapMessage, DarkSwapProofError, FEE_RATIO_PRECISION } from "../../types";
|
|
4
3
|
import { encodeAddress } from "../../utils/encoders";
|
|
5
|
-
import { bn_to_0xhex
|
|
6
|
-
import { mimc_bn254 } from "../../utils/mimc";
|
|
4
|
+
import { bn_to_0xhex } from "../../utils/formatters";
|
|
7
5
|
import { hexStringToSignature, uint8ArrayToNumberArray } from "../../utils/proofUtils";
|
|
8
|
-
import { generateProof
|
|
9
|
-
import { generateKeyPair } from "../keyService";
|
|
6
|
+
import { generateProof } from "../baseProofService";
|
|
10
7
|
import { calcNullifier, getNoteFooter } from "../noteService";
|
|
11
8
|
|
|
12
9
|
type RetailSwapProofInput = {
|
|
@@ -65,12 +62,10 @@ export type RetailSwapProofParam = {
|
|
|
65
62
|
merkleRoot: string,
|
|
66
63
|
aliceMerkleIndex: number[],
|
|
67
64
|
aliceMerklePath: string[],
|
|
68
|
-
aliceAddress: string,
|
|
69
65
|
aliceMessage: DarkSwapMessage,
|
|
70
66
|
|
|
71
67
|
bobMerkleIndex: number[],
|
|
72
68
|
bobMerklePath: string[],
|
|
73
|
-
bobAddress: string,
|
|
74
69
|
bobMessage: DarkSwapMessage,
|
|
75
70
|
}
|
|
76
71
|
|
|
@@ -108,8 +103,8 @@ export async function generateRetailSwapProof(param: RetailSwapProofParam): Prom
|
|
|
108
103
|
const bobOrderNoteNullifier = calcNullifier(param.bobMessage.orderNote.rho, param.bobMessage.publicKey);
|
|
109
104
|
const bobInNoteFooter = getNoteFooter(param.bobMessage.inNote.rho, param.bobMessage.publicKey);
|
|
110
105
|
|
|
111
|
-
const aliceAddressMod = encodeAddress(param.
|
|
112
|
-
const bobAddressMod = encodeAddress(param.
|
|
106
|
+
const aliceAddressMod = encodeAddress(param.aliceMessage.address);
|
|
107
|
+
const bobAddressMod = encodeAddress(param.bobMessage.address);
|
|
113
108
|
|
|
114
109
|
const inputs: RetailSwapProofInput = {
|
|
115
110
|
merkle_root: param.merkleRoot,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './retailSwap';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import DarkSwapAssetManagerAbi from '../../abis/DarkSwapAssetManager.json';
|
|
3
|
+
import { DarkSwap } from '../../darkSwap';
|
|
4
|
+
import { DarkSwapError } from '../../entities';
|
|
5
|
+
import { generateRetailSwapProof, RetailSwapProofResult } from '../../proof/retail/swapProof';
|
|
6
|
+
import { DarkSwapMessage } from '../../types';
|
|
7
|
+
import { hexlify32 } from '../../utils/util';
|
|
8
|
+
import { BaseContext, BaseContractService } from '../BaseService';
|
|
9
|
+
import { multiGetMerklePathAndRoot } from '../merkletree';
|
|
10
|
+
|
|
11
|
+
class RetailSwapContext extends BaseContext {
|
|
12
|
+
private _aliceSwapMessage?: DarkSwapMessage;
|
|
13
|
+
private _bobSwapMessage?: DarkSwapMessage;
|
|
14
|
+
private _proof?: RetailSwapProofResult;
|
|
15
|
+
|
|
16
|
+
constructor(signature: string) {
|
|
17
|
+
super(signature);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
set aliceSwapMessage(aliceSwapMessage: DarkSwapMessage | undefined) {
|
|
21
|
+
this._aliceSwapMessage = aliceSwapMessage;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get aliceSwapMessage(): DarkSwapMessage | undefined {
|
|
25
|
+
return this._aliceSwapMessage;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
set bobSwapMessage(bobSwapMessage: DarkSwapMessage | undefined) {
|
|
29
|
+
this._bobSwapMessage = bobSwapMessage;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get bobSwapMessage(): DarkSwapMessage | undefined {
|
|
33
|
+
return this._bobSwapMessage;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
set proof(proof: RetailSwapProofResult | undefined) {
|
|
37
|
+
this._proof = proof;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get proof(): RetailSwapProofResult | undefined {
|
|
41
|
+
return this._proof;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class RetailSwapService extends BaseContractService {
|
|
46
|
+
constructor(_darkSwap: DarkSwap) {
|
|
47
|
+
super(_darkSwap);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async prepare(
|
|
51
|
+
aliceSwapMessage: DarkSwapMessage,
|
|
52
|
+
bobSwapMessage: DarkSwapMessage
|
|
53
|
+
): Promise<{ context: RetailSwapContext }> {
|
|
54
|
+
const context = new RetailSwapContext(aliceSwapMessage.signature);
|
|
55
|
+
context.aliceSwapMessage = aliceSwapMessage;
|
|
56
|
+
context.bobSwapMessage = bobSwapMessage;
|
|
57
|
+
return { context };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private async generateProof(context: RetailSwapContext): Promise<void> {
|
|
61
|
+
if (!context
|
|
62
|
+
|| !context.aliceSwapMessage
|
|
63
|
+
|| !context.bobSwapMessage) {
|
|
64
|
+
throw new DarkSwapError('Invalid context');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const merklePathes = await multiGetMerklePathAndRoot([context.aliceSwapMessage.orderNote.note, context.bobSwapMessage.orderNote.note], this._darkSwap);
|
|
68
|
+
const aliceOrderNotePath = merklePathes[0];
|
|
69
|
+
const bobOrderNotePath = merklePathes[1];
|
|
70
|
+
|
|
71
|
+
const proof = await generateRetailSwapProof({
|
|
72
|
+
merkleRoot: aliceOrderNotePath.root,
|
|
73
|
+
aliceMerkleIndex: aliceOrderNotePath.index,
|
|
74
|
+
aliceMerklePath: aliceOrderNotePath.path,
|
|
75
|
+
aliceMessage: context.aliceSwapMessage,
|
|
76
|
+
bobMerkleIndex: bobOrderNotePath.index,
|
|
77
|
+
bobMerklePath: bobOrderNotePath.path,
|
|
78
|
+
bobMessage: context.bobSwapMessage,
|
|
79
|
+
});
|
|
80
|
+
context.merkleRoot = aliceOrderNotePath.root;
|
|
81
|
+
context.proof = proof;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public async execute(context: RetailSwapContext): Promise<string> {
|
|
85
|
+
await this.generateProof(context);
|
|
86
|
+
if (!context
|
|
87
|
+
|| !context.merkleRoot
|
|
88
|
+
|| !context.aliceSwapMessage
|
|
89
|
+
|| !context.bobSwapMessage
|
|
90
|
+
|| !context.proof) {
|
|
91
|
+
throw new DarkSwapError('Invalid context');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const contract = new ethers.Contract(
|
|
95
|
+
this._darkSwap.contracts.darkSwapAssetManager,
|
|
96
|
+
DarkSwapAssetManagerAbi.abi,
|
|
97
|
+
this._darkSwap.signer
|
|
98
|
+
);
|
|
99
|
+
const tx = await contract.retailSwap(
|
|
100
|
+
[
|
|
101
|
+
context.merkleRoot,
|
|
102
|
+
hexlify32(context.aliceSwapMessage.orderNote.feeRatio),
|
|
103
|
+
context.proof.aliceOrderNullifier,
|
|
104
|
+
hexlify32(context.aliceSwapMessage.inNote.note),
|
|
105
|
+
context.proof.aliceInNoteFooter,
|
|
106
|
+
hexlify32(context.bobSwapMessage.orderNote.feeRatio),
|
|
107
|
+
context.proof.bobOrderNullifier,
|
|
108
|
+
hexlify32(context.bobSwapMessage.inNote.note),
|
|
109
|
+
context.proof.bobInNoteFooter
|
|
110
|
+
],
|
|
111
|
+
context.proof.proof
|
|
112
|
+
);
|
|
113
|
+
await tx.wait();
|
|
114
|
+
return tx.hash;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -128,7 +128,7 @@ export class ProCancelOrderService extends BaseContractService {
|
|
|
128
128
|
DarkSwapAssetManagerAbi.abi,
|
|
129
129
|
this._darkSwap.signer
|
|
130
130
|
);
|
|
131
|
-
const tx = await contract.
|
|
131
|
+
const tx = await contract.cancelOrder(
|
|
132
132
|
context.merkleRoot,
|
|
133
133
|
context.proof.orderNullifier,
|
|
134
134
|
context.proof.oldBalanceNullifier,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import DarkSwapAssetManagerAbi from '../../abis/DarkSwapAssetManager.json';
|
|
3
|
-
import { getFeeRatio } from '../feeRatioService';
|
|
4
3
|
import { DarkSwap } from '../../darkSwap';
|
|
5
4
|
import { DarkSwapError } from '../../entities';
|
|
6
5
|
import { generateKeyPair } from '../../proof/keyService';
|
|
7
6
|
import { calcNullifier, createNote, createOrderNoteExt } from '../../proof/noteService';
|
|
8
7
|
import { generateProCreateOrderProof, ProCreateOrderProofResult } from '../../proof/pro/orders/createOrderProof';
|
|
9
8
|
import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote, DarkSwapOrderNoteExt } from '../../types';
|
|
9
|
+
import { hexlify32 } from '../../utils/util';
|
|
10
10
|
import { BaseContext, BaseContractService } from '../BaseService';
|
|
11
|
+
import { getFeeRatio } from '../feeRatioService';
|
|
11
12
|
import { getMerklePathAndRoot } from '../merkletree';
|
|
12
|
-
import { hexlify32 } from '../../utils/util';
|
|
13
13
|
|
|
14
14
|
class ProCreateOrderContext extends BaseContext {
|
|
15
15
|
private _orderNote?: DarkSwapOrderNote;
|
|
@@ -5,9 +5,11 @@ import { DarkSwapError } from '../../entities';
|
|
|
5
5
|
import { generateKeyPair } from '../../proof/keyService';
|
|
6
6
|
import { createNote } from '../../proof/noteService';
|
|
7
7
|
import { generateProSwapProof, ProSwapProofResult } from '../../proof/pro/orders/swapProof';
|
|
8
|
-
import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote } from '../../types';
|
|
8
|
+
import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote, FEE_RATIO_PRECISION } from '../../types';
|
|
9
9
|
import { BaseContext, BaseContractService } from '../BaseService';
|
|
10
10
|
import { multiGetMerklePathAndRoot } from '../merkletree';
|
|
11
|
+
import { hexlify32 } from '../../utils/util';
|
|
12
|
+
import { generateRetailSwapMessage } from '../../proof/retail/depositOrderProof';
|
|
11
13
|
|
|
12
14
|
class ProSwapContext extends BaseContext {
|
|
13
15
|
private _orderNote?: DarkSwapOrderNote;
|
|
@@ -16,6 +18,7 @@ class ProSwapContext extends BaseContext {
|
|
|
16
18
|
private _proof?: ProSwapProofResult;
|
|
17
19
|
private _bobAddress?: string;
|
|
18
20
|
private _bobSwapMessage?: DarkSwapMessage;
|
|
21
|
+
private _aliceFeeAmount?: bigint;
|
|
19
22
|
|
|
20
23
|
constructor(signature: string) {
|
|
21
24
|
super(signature);
|
|
@@ -45,6 +48,14 @@ class ProSwapContext extends BaseContext {
|
|
|
45
48
|
return this._swapInNote;
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
set aliceFeeAmount(aliceFeeAmount: bigint | undefined) {
|
|
52
|
+
this._aliceFeeAmount = aliceFeeAmount;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get aliceFeeAmount(): bigint | undefined {
|
|
56
|
+
return this._aliceFeeAmount;
|
|
57
|
+
}
|
|
58
|
+
|
|
48
59
|
set proof(proof: ProSwapProofResult | undefined) {
|
|
49
60
|
this._proof = proof;
|
|
50
61
|
}
|
|
@@ -75,27 +86,43 @@ export class ProSwapService extends BaseContractService {
|
|
|
75
86
|
super(_darkSwap);
|
|
76
87
|
}
|
|
77
88
|
|
|
78
|
-
public async
|
|
89
|
+
public static async prepareProSwapMessageForBob(
|
|
79
90
|
address: string,
|
|
80
91
|
orderNote: DarkSwapOrderNote,
|
|
81
|
-
swapOutAmount: bigint,
|
|
82
92
|
swapInAmount: bigint,
|
|
93
|
+
swapInAsset: string,
|
|
94
|
+
signature: string
|
|
95
|
+
): Promise<DarkSwapMessage> {
|
|
96
|
+
const [pubKey, privKey] = await generateKeyPair(signature);
|
|
97
|
+
const feeAmount = swapInAmount * orderNote.feeRatio / FEE_RATIO_PRECISION;
|
|
98
|
+
const swapInNote = createNote(address, swapInAsset, swapInAmount - feeAmount, pubKey);
|
|
99
|
+
const darkSwapMessage = await generateRetailSwapMessage(address, orderNote, swapInNote, feeAmount, pubKey, privKey);
|
|
100
|
+
return darkSwapMessage;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public async prepare(
|
|
104
|
+
address: string,
|
|
105
|
+
orderNote: DarkSwapOrderNote,
|
|
83
106
|
bobAddress: string,
|
|
84
107
|
bobSwapMessage: DarkSwapMessage,
|
|
85
108
|
signature: string
|
|
86
|
-
): Promise<{ context: ProSwapContext; swapInNote: DarkSwapNote, changeNote: DarkSwapNote }> {
|
|
87
|
-
const [pubKey
|
|
109
|
+
): Promise<{ context: ProSwapContext; swapInNote: DarkSwapNote, changeNote: DarkSwapNote, feeAmount: bigint }> {
|
|
110
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
111
|
+
const swapOutAmount = bobSwapMessage.feeAmount + bobSwapMessage.inNote.amount;
|
|
112
|
+
const swapInAmount = bobSwapMessage.orderNote.amount;
|
|
113
|
+
const aliceFeeAmount = swapInAmount * orderNote.feeRatio / FEE_RATIO_PRECISION;
|
|
88
114
|
const changeNote = createNote(address, orderNote.asset, orderNote.amount - swapOutAmount, pubKey);
|
|
89
|
-
const swapInNote = createNote(address, bobSwapMessage.orderNote.asset, swapInAmount, pubKey);
|
|
115
|
+
const swapInNote = createNote(address, bobSwapMessage.orderNote.asset, swapInAmount - aliceFeeAmount, pubKey);
|
|
90
116
|
|
|
91
117
|
const context = new ProSwapContext(signature);
|
|
92
118
|
context.orderNote = orderNote;
|
|
93
119
|
context.swapInNote = swapInNote;
|
|
94
120
|
context.changeNote = changeNote;
|
|
121
|
+
context.aliceFeeAmount = aliceFeeAmount;
|
|
95
122
|
context.address = address;
|
|
96
123
|
context.bobAddress = bobAddress;
|
|
97
124
|
context.bobSwapMessage = bobSwapMessage;
|
|
98
|
-
return { context, swapInNote, changeNote };
|
|
125
|
+
return { context, swapInNote, changeNote, feeAmount: aliceFeeAmount };
|
|
99
126
|
}
|
|
100
127
|
|
|
101
128
|
private async generateProof(context: ProSwapContext): Promise<void> {
|
|
@@ -112,7 +139,7 @@ export class ProSwapService extends BaseContractService {
|
|
|
112
139
|
|
|
113
140
|
const merklePathes = await multiGetMerklePathAndRoot([context.orderNote.note, context.bobSwapMessage.orderNote.note], this._darkSwap);
|
|
114
141
|
const orderNotePath = merklePathes[0];
|
|
115
|
-
const
|
|
142
|
+
const bobOrderNotePath = merklePathes[1];
|
|
116
143
|
|
|
117
144
|
const proof = await generateProSwapProof({
|
|
118
145
|
merkleRoot: orderNotePath.root,
|
|
@@ -122,10 +149,11 @@ export class ProSwapService extends BaseContractService {
|
|
|
122
149
|
aliceOrderNote: context.orderNote,
|
|
123
150
|
aliceChangeNote: context.changeNote,
|
|
124
151
|
aliceInNote: context.swapInNote,
|
|
152
|
+
aliceFeeAmount: context.aliceFeeAmount!,
|
|
125
153
|
aliceSignedMessage: context.signature,
|
|
126
154
|
bobAddress: context.bobAddress,
|
|
127
|
-
bobMerkleIndex:
|
|
128
|
-
bobMerklePath:
|
|
155
|
+
bobMerkleIndex: bobOrderNotePath.index,
|
|
156
|
+
bobMerklePath: bobOrderNotePath.path,
|
|
129
157
|
bobMessage: context.bobSwapMessage,
|
|
130
158
|
});
|
|
131
159
|
context.merkleRoot = orderNotePath.root;
|
|
@@ -134,7 +162,7 @@ export class ProSwapService extends BaseContractService {
|
|
|
134
162
|
|
|
135
163
|
public async execute(context: ProSwapContext): Promise<string> {
|
|
136
164
|
await this.generateProof(context);
|
|
137
|
-
if (!context
|
|
165
|
+
if (!context
|
|
138
166
|
|| !context.orderNote
|
|
139
167
|
|| !context.swapInNote
|
|
140
168
|
|| !context.changeNote
|
|
@@ -150,13 +178,22 @@ export class ProSwapService extends BaseContractService {
|
|
|
150
178
|
this._darkSwap.signer
|
|
151
179
|
);
|
|
152
180
|
const tx = await contract.proSwap(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
181
|
+
[
|
|
182
|
+
context.merkleRoot,
|
|
183
|
+
context.proof.aliceOutNullifier,
|
|
184
|
+
hexlify32(context.orderNote.feeRatio),
|
|
185
|
+
hexlify32(context.swapInNote.note),
|
|
186
|
+
context.proof.aliceInNoteFooter,
|
|
187
|
+
hexlify32(context.changeNote.note),
|
|
188
|
+
context.proof.aliceChangeNoteFooter,
|
|
189
|
+
context.proof.bobOutNullifier,
|
|
190
|
+
hexlify32(context.bobSwapMessage.orderNote.feeRatio),
|
|
191
|
+
hexlify32(context.bobSwapMessage.inNote.note),
|
|
192
|
+
context.proof.bobInNoteFooter
|
|
193
|
+
],
|
|
158
194
|
context.proof.proof
|
|
159
195
|
);
|
|
196
|
+
await tx.wait();
|
|
160
197
|
return tx.hash;
|
|
161
198
|
}
|
|
162
199
|
}
|
|
@@ -90,7 +90,7 @@ export class RetailCreateOrderService extends BaseContractService {
|
|
|
90
90
|
context.feeAmount = feeAmount;
|
|
91
91
|
context.address = address;
|
|
92
92
|
|
|
93
|
-
const swapMessage = await generateRetailSwapMessage(address, orderNote, swapInNote, pubKey, privKey);
|
|
93
|
+
const swapMessage = await generateRetailSwapMessage(address, orderNote, swapInNote, feeAmount, pubKey, privKey);
|
|
94
94
|
context.swapMessage = swapMessage;
|
|
95
95
|
return { context, swapMessage };
|
|
96
96
|
}
|