@interest-protocol/vortex-sdk 4.3.0 → 6.0.0
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/__tests__/test-utils.d.ts +1 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -1
- package/dist/constants.d.ts +6 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -18
- package/dist/index.mjs.map +1 -1
- package/dist/swap.d.ts +17 -0
- package/dist/swap.d.ts.map +1 -0
- package/dist/utils/deposit.d.ts.map +1 -1
- package/dist/utils/withdraw.d.ts +4 -5
- package/dist/utils/withdraw.d.ts.map +1 -1
- package/dist/vortex.d.ts +18 -3
- package/dist/vortex.d.ts.map +1 -1
- package/dist/vortex.types.d.ts +45 -3
- package/dist/vortex.types.d.ts.map +1 -1
- package/dist/withdraw-with-account.d.ts +1 -1
- package/dist/withdraw-with-account.d.ts.map +1 -1
- package/dist/withdraw.d.ts +1 -1
- package/dist/withdraw.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/test-utils.ts +4 -0
- package/src/constants.ts +12 -6
- package/src/index.ts +1 -0
- package/src/swap.ts +93 -0
- package/src/utils/deposit.ts +1 -4
- package/src/utils/withdraw.ts +2 -5
- package/src/vortex.ts +60 -3
- package/src/vortex.types.ts +50 -3
- package/src/withdraw-with-account.ts +0 -2
- package/src/withdraw.ts +0 -2
package/dist/swap.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { StartSwapHelperArgs, FinishSwapHelperArgs } from './vortex.types';
|
|
3
|
+
export declare const startSwap: ({ tx, amount, vortexPool, unspentUtxos, vortexKeypair, root, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }: StartSwapHelperArgs) => Promise<{
|
|
4
|
+
tx: Transaction;
|
|
5
|
+
receipt: {
|
|
6
|
+
$kind: "NestedResult";
|
|
7
|
+
NestedResult: [number, number];
|
|
8
|
+
};
|
|
9
|
+
coinIn: {
|
|
10
|
+
$kind: "NestedResult";
|
|
11
|
+
NestedResult: [number, number];
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
export declare const finishSwap: ({ tx, amount, vortexSdk, vortexPool, vortexKeypair, root, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }: FinishSwapHelperArgs) => Promise<{
|
|
15
|
+
tx: Transaction;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=swap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../src/swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAK3E,eAAO,MAAM,SAAS,GAAU,gIAY7B,mBAAmB;;;;;;;;;;EA6BrB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,0HAY9B,oBAAoB;;EA8BtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../../src/utils/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,OAAO,EAAiB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,UAAU,uBAAuB;IAC/B,EAAE,EAAE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;EA4HzB,CAAC"}
|
package/dist/utils/withdraw.d.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { Transaction } from '@mysten/sui/transactions';
|
|
2
2
|
import { Utxo } from '../entities/utxo';
|
|
3
3
|
import { VortexKeypair } from '../entities/keypair';
|
|
4
|
-
import { GetMerklePathFn } from '../vortex.types';
|
|
4
|
+
import { GetMerklePathFn, VortexPool } from '../vortex.types';
|
|
5
5
|
import { Vortex } from '../vortex';
|
|
6
6
|
interface PrepareWithdrawArgs {
|
|
7
7
|
tx?: Transaction;
|
|
8
8
|
amount: bigint;
|
|
9
9
|
unspentUtxos: Utxo[];
|
|
10
|
-
vortexPool: string |
|
|
10
|
+
vortexPool: string | VortexPool;
|
|
11
11
|
vortexKeypair: VortexKeypair;
|
|
12
12
|
root: bigint;
|
|
13
13
|
getMerklePathFn: GetMerklePathFn;
|
|
14
|
-
recipient: string;
|
|
15
14
|
relayer: string;
|
|
16
15
|
relayerFee: bigint;
|
|
17
16
|
vortexSdk: Vortex;
|
|
18
17
|
accountSecret: bigint;
|
|
19
18
|
}
|
|
20
|
-
export declare const prepareWithdraw: ({ tx, amount, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn,
|
|
19
|
+
export declare const prepareWithdraw: ({ tx, amount, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }: PrepareWithdrawArgs) => Promise<{
|
|
21
20
|
tx: Transaction;
|
|
22
21
|
moveProof: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
23
22
|
extData: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
24
|
-
vortexPool:
|
|
23
|
+
vortexPool: string | VortexPool;
|
|
25
24
|
}>;
|
|
26
25
|
export {};
|
|
27
26
|
//# sourceMappingURL=withdraw.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw.d.ts","sourceRoot":"","sources":["../../src/utils/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASpD,OAAO,EAAiB,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"withdraw.d.ts","sourceRoot":"","sources":["../../src/utils/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASpD,OAAO,EAAiB,eAAe,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,UAAU,mBAAmB;IAC3B,EAAE,CAAC,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,IAAI,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;IAChC,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,eAAe,GAAU,gIAYnC,mBAAmB;;;;;EAgIrB,CAAC"}
|
package/dist/vortex.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
-
import { ConstructorArgs, RegisterArgs, SharedObjectData, NewExtDataArgs, NewProofArgs, VortexPool, TransactArgs, IsNullifierSpentArgs, AreNullifiersSpentArgs, NewArgs, NewAccountArgs, MergeCoinsArgs, TransactWithAccountArgs } from './vortex.types';
|
|
2
|
+
import { ConstructorArgs, RegisterArgs, SharedObjectData, NewExtDataArgs, NewProofArgs, VortexPool, TransactArgs, IsNullifierSpentArgs, AreNullifiersSpentArgs, NewArgs, NewAccountArgs, MergeCoinsArgs, TransactWithAccountArgs, StartSwapArgs, FinishSwapArgs } from './vortex.types';
|
|
3
3
|
export declare class Vortex {
|
|
4
4
|
#private;
|
|
5
5
|
packageId: string;
|
|
6
|
+
swapPackageId: string;
|
|
6
7
|
registry: SharedObjectData;
|
|
7
|
-
constructor({ registry, packageId, fullNodeUrl, }: ConstructorArgs);
|
|
8
|
+
constructor({ registry, packageId, swapPackageId, fullNodeUrl, }: ConstructorArgs);
|
|
8
9
|
newAccount({ tx, hashedSecret }: NewAccountArgs): {
|
|
9
10
|
tx: Transaction;
|
|
10
11
|
account: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
@@ -22,7 +23,7 @@ export declare class Vortex {
|
|
|
22
23
|
};
|
|
23
24
|
vortexAddress(coinType: string): Promise<string | null>;
|
|
24
25
|
encryptionKey(user: string): Promise<string>;
|
|
25
|
-
newExtData({ tx,
|
|
26
|
+
newExtData({ tx, value, action, relayer, relayerFee, encryptedOutput1, encryptedOutput0, }: NewExtDataArgs): {
|
|
26
27
|
tx: Transaction;
|
|
27
28
|
extData: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
28
29
|
};
|
|
@@ -43,6 +44,20 @@ export declare class Vortex {
|
|
|
43
44
|
nextIndex(vortexPool: string | VortexPool): Promise<bigint>;
|
|
44
45
|
isNullifierSpent({ nullifier, vortexPool }: IsNullifierSpentArgs): Promise<boolean>;
|
|
45
46
|
areNullifiersSpent({ nullifiers, vortexPool }: AreNullifiersSpentArgs): Promise<boolean[]>;
|
|
47
|
+
startSwap({ tx, vortex, proof, extData, relayer, minAmountOut, coinOutType, }: StartSwapArgs): Promise<{
|
|
48
|
+
tx: Transaction;
|
|
49
|
+
receipt: {
|
|
50
|
+
$kind: "NestedResult";
|
|
51
|
+
NestedResult: [number, number];
|
|
52
|
+
};
|
|
53
|
+
coinIn: {
|
|
54
|
+
$kind: "NestedResult";
|
|
55
|
+
NestedResult: [number, number];
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
58
|
+
finishSwap({ tx, vortex, coinOut, proof, extData, receipt, coinInType, }: FinishSwapArgs): Promise<{
|
|
59
|
+
tx: Transaction;
|
|
60
|
+
}>;
|
|
46
61
|
getVortexPool(objectId: string): Promise<VortexPool>;
|
|
47
62
|
getNewPoolEvent(coinType: string): string;
|
|
48
63
|
getNewAccountEvent(): string;
|
package/dist/vortex.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vortex.d.ts","sourceRoot":"","sources":["../src/vortex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,cAAc,EAEd,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,sBAAsB,EACtB,OAAO,EACP,cAAc,EACd,cAAc,EACd,uBAAuB,
|
|
1
|
+
{"version":3,"file":"vortex.d.ts","sourceRoot":"","sources":["../src/vortex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,cAAc,EAEd,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,sBAAsB,EACtB,OAAO,EACP,cAAc,EACd,cAAc,EACd,uBAAuB,EACvB,aAAa,EACb,cAAc,EACf,MAAM,gBAAgB,CAAC;AAexB,qBAAa,MAAM;;IAGjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,gBAAgB,CAAC;gBAQf,EACV,QAAQ,EAC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IA6BrE,SAAS,CAAC,EACd,EAAsB,EACtB,MAAM,EACN,KAAK,EACL,OAAO,EACP,OAAO,EACP,YAAY,EACZ,WAAW,GACZ,EAAE,aAAa;;;;;;;;;;;IAkBV,UAAU,CAAC,EACf,EAAsB,EACtB,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,UAAU,GACX,EAAE,cAAc;;;IAkBX,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAa1D,eAAe,CAAC,QAAQ,EAAE,MAAM;IAIhC,kBAAkB;IAIlB,qBAAqB,CAAC,QAAQ,EAAE,MAAM;IAItC,sBAAsB,CAAC,QAAQ,EAAE,MAAM;IAIvC,wBAAwB;IAIxB,oBAAoB,CAAC,EAAE,EAAE,WAAW;;;;;IAQpC,kBAAkB,CAAC,EAAE,EAAE,WAAW;;;;;CAWnC;AAED,eAAO,MAAM,SAAS,QAQpB,CAAC"}
|
package/dist/vortex.types.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export declare enum Action {
|
|
|
9
9
|
Deposit = 0,
|
|
10
10
|
Withdraw = 1
|
|
11
11
|
}
|
|
12
|
+
interface NestedResult {
|
|
13
|
+
$kind: 'NestedResult';
|
|
14
|
+
NestedResult: [number, number];
|
|
15
|
+
}
|
|
12
16
|
export type GetMerklePathFn = (utxo: Utxo | null) => Promise<MerklePath>;
|
|
13
17
|
export interface RegisterArgs extends MaybeTx {
|
|
14
18
|
encryptionKey: string;
|
|
@@ -21,6 +25,7 @@ export interface ConstructorArgs {
|
|
|
21
25
|
registry: SharedObjectData;
|
|
22
26
|
fullNodeUrl?: string;
|
|
23
27
|
packageId: string;
|
|
28
|
+
swapPackageId: string;
|
|
24
29
|
}
|
|
25
30
|
export interface Proof {
|
|
26
31
|
proofA: number[];
|
|
@@ -31,7 +36,6 @@ export interface Proof {
|
|
|
31
36
|
publicInputsHex: string;
|
|
32
37
|
}
|
|
33
38
|
export interface NewExtDataArgs extends MaybeTx {
|
|
34
|
-
recipient: string;
|
|
35
39
|
value: bigint;
|
|
36
40
|
relayer: string;
|
|
37
41
|
relayerFee: bigint;
|
|
@@ -110,7 +114,6 @@ export interface WithdrawArgs extends MaybeTx {
|
|
|
110
114
|
vortexKeypair: VortexKeypair;
|
|
111
115
|
root: bigint;
|
|
112
116
|
getMerklePathFn: GetMerklePathFn;
|
|
113
|
-
recipient: string;
|
|
114
117
|
relayer: string;
|
|
115
118
|
relayerFee: bigint;
|
|
116
119
|
}
|
|
@@ -123,7 +126,6 @@ export interface WithdrawWithAccountArgs extends MaybeTx {
|
|
|
123
126
|
unspentUtxos?: Utxo[];
|
|
124
127
|
account: string;
|
|
125
128
|
accountSecret: bigint;
|
|
126
|
-
recipient: string;
|
|
127
129
|
relayer: string;
|
|
128
130
|
relayerFee: bigint;
|
|
129
131
|
amount: bigint;
|
|
@@ -155,5 +157,45 @@ export interface MergeCoinsArgs extends MaybeTx {
|
|
|
155
157
|
coinType: string;
|
|
156
158
|
coins: Object[];
|
|
157
159
|
}
|
|
160
|
+
export interface StartSwapArgs extends MaybeTx {
|
|
161
|
+
vortex: string | VortexPool;
|
|
162
|
+
proof: TransactionResult;
|
|
163
|
+
extData: TransactionResult;
|
|
164
|
+
relayer: string;
|
|
165
|
+
minAmountOut: bigint;
|
|
166
|
+
coinOutType: string;
|
|
167
|
+
}
|
|
168
|
+
export interface FinishSwapArgs extends MaybeTx {
|
|
169
|
+
vortex: string | VortexPool;
|
|
170
|
+
coinOut: TransactionResult;
|
|
171
|
+
proof: TransactionResult;
|
|
172
|
+
extData: TransactionResult;
|
|
173
|
+
receipt: TransactionResult | NestedResult;
|
|
174
|
+
coinInType: string;
|
|
175
|
+
}
|
|
176
|
+
export interface StartSwapHelperArgs extends MaybeTx {
|
|
177
|
+
amount: bigint;
|
|
178
|
+
vortexPool: string | VortexPool;
|
|
179
|
+
unspentUtxos: Utxo[];
|
|
180
|
+
vortexSdk: Vortex;
|
|
181
|
+
vortexKeypair: VortexKeypair;
|
|
182
|
+
root: bigint;
|
|
183
|
+
getMerklePathFn: GetMerklePathFn;
|
|
184
|
+
relayer: string;
|
|
185
|
+
minAmountOut: bigint;
|
|
186
|
+
coinOutType: string;
|
|
187
|
+
}
|
|
188
|
+
export interface FinishSwapHelperArgs extends MaybeTx {
|
|
189
|
+
amount: bigint;
|
|
190
|
+
vortexSdk: Vortex;
|
|
191
|
+
vortexPool: string | VortexPool;
|
|
192
|
+
vortexKeypair: VortexKeypair;
|
|
193
|
+
root: bigint;
|
|
194
|
+
getMerklePathFn: GetMerklePathFn;
|
|
195
|
+
unspentUtxos?: Utxo[];
|
|
196
|
+
coinOut: TransactionResult;
|
|
197
|
+
receipt: TransactionResult | NestedResult;
|
|
198
|
+
coinInType: string;
|
|
199
|
+
}
|
|
158
200
|
export {};
|
|
159
201
|
//# sourceMappingURL=vortex.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vortex.types.d.ts","sourceRoot":"","sources":["../src/vortex.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,oBAAY,MAAM;IAChB,OAAO,IAAA;IACP,QAAQ,IAAA;CACT;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzE,MAAM,WAAW,YAAa,SAAQ,OAAO;IAC3C,aAAa,EAAE,M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ChC,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC;IACtB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,OAAO,EAAE,iBAAiB,GAAG,YAAY,CAAC;IAC1C,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction } from '@mysten/sui/transactions';
|
|
2
2
|
import { WithdrawWithAccountArgs } from './vortex.types';
|
|
3
|
-
export declare const withdrawWithAccount: ({ tx, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn,
|
|
3
|
+
export declare const withdrawWithAccount: ({ tx, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }: WithdrawWithAccountArgs) => Promise<{
|
|
4
4
|
tx: Transaction;
|
|
5
5
|
coin: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
6
6
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw-with-account.d.ts","sourceRoot":"","sources":["../src/withdraw-with-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,eAAO,MAAM,mBAAmB,GAAU,
|
|
1
|
+
{"version":3,"file":"withdraw-with-account.d.ts","sourceRoot":"","sources":["../src/withdraw-with-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,eAAO,MAAM,mBAAmB,GAAU,yIAavC,uBAAuB;;;EA4BzB,CAAC"}
|
package/dist/withdraw.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction } from '@mysten/sui/transactions';
|
|
2
2
|
import { WithdrawArgs } from './vortex.types';
|
|
3
|
-
export declare const withdraw: ({ tx, amount, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn,
|
|
3
|
+
export declare const withdraw: ({ tx, amount, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, }: WithdrawArgs) => Promise<{
|
|
4
4
|
tx: Transaction;
|
|
5
5
|
coin: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
6
6
|
}>;
|
package/dist/withdraw.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw.d.ts","sourceRoot":"","sources":["../src/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,eAAO,MAAM,QAAQ,GAAU,
|
|
1
|
+
{"version":3,"file":"withdraw.d.ts","sourceRoot":"","sources":["../src/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,eAAO,MAAM,QAAQ,GAAU,iHAW5B,YAAY;;;EA6Bd,CAAC"}
|
package/package.json
CHANGED
|
@@ -19,6 +19,9 @@ export const TEST_REGISTRY_SHARED_OBJECT_ID =
|
|
|
19
19
|
export const TEST_UPGRADE_CAP_ID =
|
|
20
20
|
'0xb76878578f39017a04a892e7250a146c13663282de80876fae7d62fb5b073f4b';
|
|
21
21
|
|
|
22
|
+
export const TEST_VORTEX_SWAP_PACKAGE_ID =
|
|
23
|
+
'0x7efc1d6d42b8c6d6846172a3925f2f28cd5d71cff617ad81f8c3d45a842eabbb';
|
|
24
|
+
|
|
22
25
|
export const TEST_REGISTRY_INITIAL_SHARED_VERSION = '8';
|
|
23
26
|
|
|
24
27
|
export const TEST_VORTEX_INITIAL_SHARED_VERSION = '8';
|
|
@@ -51,6 +54,7 @@ export const testVortex = new Vortex({
|
|
|
51
54
|
initialSharedVersion: TEST_REGISTRY_INITIAL_SHARED_VERSION,
|
|
52
55
|
},
|
|
53
56
|
packageId: TEST_VORTEX_PACKAGE_ID,
|
|
57
|
+
swapPackageId: TEST_VORTEX_SWAP_PACKAGE_ID,
|
|
54
58
|
});
|
|
55
59
|
|
|
56
60
|
interface AssertValueArgs {
|
package/src/constants.ts
CHANGED
|
@@ -73,15 +73,21 @@ export const ERROR_CODES = {
|
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
export const VORTEX_PACKAGE_ID =
|
|
76
|
-
'
|
|
76
|
+
'0xcf81b96e392f82b776ee980108357426b726c4043c838822545a307e12c5ded6';
|
|
77
77
|
|
|
78
|
-
export const
|
|
79
|
-
'
|
|
78
|
+
export const VORTEX_UPGRADE_CAP =
|
|
79
|
+
'0xc2d1925fd45559e09c51f5491ec96d61f9e9108c967d34fe22a053c1b307ddfc';
|
|
80
80
|
|
|
81
81
|
export const REGISTRY_OBJECT_ID =
|
|
82
|
-
'
|
|
82
|
+
'0xf2c11c297e0581e0279714f6ba47e26d03d9a70756036fab5882ebc0f1d2b3b1';
|
|
83
83
|
|
|
84
|
-
export const
|
|
84
|
+
export const VORTEX_SWAP_PACKAGE_ID =
|
|
85
|
+
'0x2ddd33debbac3e0461b3551bb00bd40d3055ea5cd441b4fad8624dcbb095e8fb';
|
|
86
|
+
|
|
87
|
+
export const VORTEX_SWAP_UPGRADE_CAP =
|
|
88
|
+
'0xec0beaf1453b0e09d92f8addf25abcfb4bc6ce43ead828914836cadc8df249a0';
|
|
89
|
+
|
|
90
|
+
export const INITIAL_SHARED_VERSION = '692442863';
|
|
85
91
|
|
|
86
92
|
export const LSK_FETCH_OFFSET = 'fetch_offset';
|
|
87
93
|
|
|
@@ -99,5 +105,5 @@ export const BASIS_POINTS = 10_000n;
|
|
|
99
105
|
|
|
100
106
|
export const VORTEX_POOL_IDS = {
|
|
101
107
|
[SUI_TYPE_ARG]:
|
|
102
|
-
'
|
|
108
|
+
'0x1e3672f35853fccded923505434b5138543829231f025120d57fda95b86b504c',
|
|
103
109
|
};
|
package/src/index.ts
CHANGED
package/src/swap.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
3
|
+
import { StartSwapHelperArgs, FinishSwapHelperArgs } from './vortex.types';
|
|
4
|
+
|
|
5
|
+
import { prepareWithdraw } from './utils/withdraw';
|
|
6
|
+
import { prepareDepositProof } from './utils/deposit';
|
|
7
|
+
|
|
8
|
+
export const startSwap = async ({
|
|
9
|
+
tx = new Transaction(),
|
|
10
|
+
amount,
|
|
11
|
+
vortexPool,
|
|
12
|
+
unspentUtxos,
|
|
13
|
+
vortexKeypair,
|
|
14
|
+
root,
|
|
15
|
+
getMerklePathFn,
|
|
16
|
+
relayer,
|
|
17
|
+
minAmountOut,
|
|
18
|
+
vortexSdk,
|
|
19
|
+
coinOutType,
|
|
20
|
+
}: StartSwapHelperArgs) => {
|
|
21
|
+
const {
|
|
22
|
+
tx: tx2,
|
|
23
|
+
moveProof,
|
|
24
|
+
extData,
|
|
25
|
+
vortexPool: pool,
|
|
26
|
+
} = await prepareWithdraw({
|
|
27
|
+
tx,
|
|
28
|
+
amount,
|
|
29
|
+
vortexPool,
|
|
30
|
+
unspentUtxos,
|
|
31
|
+
vortexKeypair,
|
|
32
|
+
root,
|
|
33
|
+
getMerklePathFn,
|
|
34
|
+
relayer,
|
|
35
|
+
relayerFee: 0n,
|
|
36
|
+
vortexSdk,
|
|
37
|
+
accountSecret: 0n,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return vortexSdk.startSwap({
|
|
41
|
+
tx: tx2,
|
|
42
|
+
vortex: pool,
|
|
43
|
+
proof: moveProof,
|
|
44
|
+
extData,
|
|
45
|
+
relayer,
|
|
46
|
+
minAmountOut,
|
|
47
|
+
coinOutType,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const finishSwap = async ({
|
|
52
|
+
tx = new Transaction(),
|
|
53
|
+
amount,
|
|
54
|
+
vortexSdk,
|
|
55
|
+
vortexPool,
|
|
56
|
+
vortexKeypair,
|
|
57
|
+
root,
|
|
58
|
+
getMerklePathFn,
|
|
59
|
+
unspentUtxos,
|
|
60
|
+
coinOut,
|
|
61
|
+
receipt,
|
|
62
|
+
coinInType,
|
|
63
|
+
}: FinishSwapHelperArgs) => {
|
|
64
|
+
const accountSecret = 0n;
|
|
65
|
+
|
|
66
|
+
const {
|
|
67
|
+
extData,
|
|
68
|
+
tx: tx3,
|
|
69
|
+
moveProof,
|
|
70
|
+
} = await prepareDepositProof({
|
|
71
|
+
tx,
|
|
72
|
+
amount,
|
|
73
|
+
accountSecret,
|
|
74
|
+
unspentUtxos: unspentUtxos ?? [],
|
|
75
|
+
vortexSdk,
|
|
76
|
+
vortexKeypair,
|
|
77
|
+
vortexPool,
|
|
78
|
+
root,
|
|
79
|
+
getMerklePathFn,
|
|
80
|
+
relayer: normalizeSuiAddress('0x0'),
|
|
81
|
+
relayerFee: 0n,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return vortexSdk.finishSwap({
|
|
85
|
+
tx: tx3,
|
|
86
|
+
vortex: vortexPool,
|
|
87
|
+
coinOut: coinOut,
|
|
88
|
+
proof: moveProof,
|
|
89
|
+
extData,
|
|
90
|
+
receipt,
|
|
91
|
+
coinInType,
|
|
92
|
+
});
|
|
93
|
+
};
|
package/src/utils/deposit.ts
CHANGED
|
@@ -43,9 +43,7 @@ export const prepareDepositProof = async ({
|
|
|
43
43
|
typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
|
|
44
44
|
|
|
45
45
|
// Deposits we do not need a recipient, so we use a random one.
|
|
46
|
-
|
|
47
|
-
Ed25519Keypair.generate().toSuiAddress()
|
|
48
|
-
);
|
|
46
|
+
|
|
49
47
|
const randomVortexKeypair = VortexKeypair.generate();
|
|
50
48
|
|
|
51
49
|
// Determine input UTXOs
|
|
@@ -134,7 +132,6 @@ export const prepareDepositProof = async ({
|
|
|
134
132
|
|
|
135
133
|
const { extData, tx: tx2 } = vortexSdk.newExtData({
|
|
136
134
|
tx,
|
|
137
|
-
recipient: randomRecipient,
|
|
138
135
|
value: amount,
|
|
139
136
|
action: Action.Deposit,
|
|
140
137
|
relayer,
|
package/src/utils/withdraw.ts
CHANGED
|
@@ -9,18 +9,17 @@ import { fromHex } from '@mysten/sui/utils';
|
|
|
9
9
|
import { toProveInput } from '../utils';
|
|
10
10
|
import { BN254_FIELD_MODULUS } from '../constants';
|
|
11
11
|
import { prove, verify } from '../utils';
|
|
12
|
-
import { Proof, Action, GetMerklePathFn } from '../vortex.types';
|
|
12
|
+
import { Proof, Action, GetMerklePathFn, VortexPool } from '../vortex.types';
|
|
13
13
|
import { Vortex } from '../vortex';
|
|
14
14
|
|
|
15
15
|
interface PrepareWithdrawArgs {
|
|
16
16
|
tx?: Transaction;
|
|
17
17
|
amount: bigint;
|
|
18
18
|
unspentUtxos: Utxo[];
|
|
19
|
-
vortexPool: string |
|
|
19
|
+
vortexPool: string | VortexPool;
|
|
20
20
|
vortexKeypair: VortexKeypair;
|
|
21
21
|
root: bigint;
|
|
22
22
|
getMerklePathFn: GetMerklePathFn;
|
|
23
|
-
recipient: string;
|
|
24
23
|
relayer: string;
|
|
25
24
|
relayerFee: bigint;
|
|
26
25
|
vortexSdk: Vortex;
|
|
@@ -35,7 +34,6 @@ export const prepareWithdraw = async ({
|
|
|
35
34
|
vortexKeypair,
|
|
36
35
|
root,
|
|
37
36
|
getMerklePathFn,
|
|
38
|
-
recipient,
|
|
39
37
|
relayer,
|
|
40
38
|
relayerFee,
|
|
41
39
|
vortexSdk,
|
|
@@ -141,7 +139,6 @@ export const prepareWithdraw = async ({
|
|
|
141
139
|
|
|
142
140
|
const { extData, tx: tx2 } = vortexSdk.newExtData({
|
|
143
141
|
tx,
|
|
144
|
-
recipient,
|
|
145
142
|
value: amount,
|
|
146
143
|
action: Action.Withdraw,
|
|
147
144
|
relayer: normalizeSuiAddress(relayer),
|
package/src/vortex.ts
CHANGED
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
NewAccountArgs,
|
|
16
16
|
MergeCoinsArgs,
|
|
17
17
|
TransactWithAccountArgs,
|
|
18
|
+
StartSwapArgs,
|
|
19
|
+
FinishSwapArgs,
|
|
18
20
|
} from './vortex.types';
|
|
19
21
|
import { devInspectAndGetReturnValues } from '@polymedia/suitcase-core';
|
|
20
22
|
import { bcs } from '@mysten/sui/bcs';
|
|
@@ -26,6 +28,7 @@ import {
|
|
|
26
28
|
VORTEX_PACKAGE_ID,
|
|
27
29
|
REGISTRY_OBJECT_ID,
|
|
28
30
|
INITIAL_SHARED_VERSION,
|
|
31
|
+
VORTEX_SWAP_PACKAGE_ID,
|
|
29
32
|
} from './constants';
|
|
30
33
|
import { parseVortexPool } from './utils';
|
|
31
34
|
|
|
@@ -33,6 +36,7 @@ export class Vortex {
|
|
|
33
36
|
#suiClient: SuiClient;
|
|
34
37
|
|
|
35
38
|
packageId: string;
|
|
39
|
+
swapPackageId: string;
|
|
36
40
|
registry: SharedObjectData;
|
|
37
41
|
|
|
38
42
|
#newPoolEventType: string;
|
|
@@ -44,6 +48,7 @@ export class Vortex {
|
|
|
44
48
|
constructor({
|
|
45
49
|
registry,
|
|
46
50
|
packageId,
|
|
51
|
+
swapPackageId,
|
|
47
52
|
fullNodeUrl = getFullnodeUrl('devnet'),
|
|
48
53
|
}: ConstructorArgs) {
|
|
49
54
|
this.#suiClient = new SuiClient({
|
|
@@ -56,6 +61,7 @@ export class Vortex {
|
|
|
56
61
|
this.#nullifierSpentEventType = `${packageId}::vortex_events::NullifierSpent`;
|
|
57
62
|
this.#newEncryptionKeyEventType = `${packageId}::vortex_events::NewEncryptionKey`;
|
|
58
63
|
|
|
64
|
+
this.swapPackageId = swapPackageId;
|
|
59
65
|
this.packageId = packageId;
|
|
60
66
|
this.registry = registry;
|
|
61
67
|
}
|
|
@@ -168,7 +174,6 @@ export class Vortex {
|
|
|
168
174
|
|
|
169
175
|
newExtData({
|
|
170
176
|
tx = new Transaction(),
|
|
171
|
-
recipient,
|
|
172
177
|
value,
|
|
173
178
|
action,
|
|
174
179
|
relayer,
|
|
@@ -179,7 +184,6 @@ export class Vortex {
|
|
|
179
184
|
const extData = tx.moveCall({
|
|
180
185
|
target: `${this.packageId}::vortex_ext_data::new`,
|
|
181
186
|
arguments: [
|
|
182
|
-
tx.pure.address(recipient),
|
|
183
187
|
tx.pure.u64(value),
|
|
184
188
|
tx.pure.bool(action === Action.Deposit), // true for deposit, false for withdraw
|
|
185
189
|
tx.pure.address(relayer),
|
|
@@ -385,6 +389,58 @@ export class Vortex {
|
|
|
385
389
|
return result.flat() as boolean[];
|
|
386
390
|
}
|
|
387
391
|
|
|
392
|
+
async startSwap({
|
|
393
|
+
tx = new Transaction(),
|
|
394
|
+
vortex,
|
|
395
|
+
proof,
|
|
396
|
+
extData,
|
|
397
|
+
relayer,
|
|
398
|
+
minAmountOut,
|
|
399
|
+
coinOutType,
|
|
400
|
+
}: StartSwapArgs) {
|
|
401
|
+
const vortexPool = await this.#getVortexPool(vortex);
|
|
402
|
+
|
|
403
|
+
const [receipt, coinIn] = tx.moveCall({
|
|
404
|
+
target: `${this.swapPackageId}::vortex_swap::start_swap`,
|
|
405
|
+
arguments: [
|
|
406
|
+
tx.object(vortexPool.objectId),
|
|
407
|
+
proof,
|
|
408
|
+
extData,
|
|
409
|
+
tx.pure.address(relayer),
|
|
410
|
+
tx.pure.u64(minAmountOut),
|
|
411
|
+
],
|
|
412
|
+
typeArguments: [vortexPool.coinType, coinOutType],
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
return { tx, receipt, coinIn };
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async finishSwap({
|
|
419
|
+
tx = new Transaction(),
|
|
420
|
+
vortex,
|
|
421
|
+
coinOut,
|
|
422
|
+
proof,
|
|
423
|
+
extData,
|
|
424
|
+
receipt,
|
|
425
|
+
coinInType,
|
|
426
|
+
}: FinishSwapArgs) {
|
|
427
|
+
const vortexPool = await this.#getVortexPool(vortex);
|
|
428
|
+
|
|
429
|
+
tx.moveCall({
|
|
430
|
+
target: `${this.swapPackageId}::vortex_swap::finish_swap`,
|
|
431
|
+
arguments: [
|
|
432
|
+
tx.object(vortexPool.objectId),
|
|
433
|
+
coinOut,
|
|
434
|
+
receipt,
|
|
435
|
+
proof,
|
|
436
|
+
extData,
|
|
437
|
+
],
|
|
438
|
+
typeArguments: [coinInType, vortexPool.coinType],
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
return { tx };
|
|
442
|
+
}
|
|
443
|
+
|
|
388
444
|
async getVortexPool(objectId: string): Promise<VortexPool> {
|
|
389
445
|
const objectResponse = await this.#suiClient.getObject({
|
|
390
446
|
id: objectId,
|
|
@@ -445,5 +501,6 @@ export const vortexSDK = new Vortex({
|
|
|
445
501
|
objectId: REGISTRY_OBJECT_ID,
|
|
446
502
|
initialSharedVersion: INITIAL_SHARED_VERSION,
|
|
447
503
|
},
|
|
448
|
-
|
|
504
|
+
swapPackageId: VORTEX_SWAP_PACKAGE_ID,
|
|
505
|
+
fullNodeUrl: getFullnodeUrl('testnet'),
|
|
449
506
|
});
|