@interest-protocol/vortex-sdk 4.1.0 → 4.3.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.
@@ -1,8 +1,8 @@
1
1
  import { Transaction } from '@mysten/sui/transactions';
2
2
  import { Utxo } from '../entities/utxo';
3
+ import { GetMerklePathFn } from '../vortex.types';
3
4
  import { Vortex } from '../vortex';
4
5
  import { VortexKeypair as VortexKeypairType } from '../entities/keypair';
5
- import { MerkleTree } from 'fixed-merkle-tree';
6
6
  import { VortexPool } from '../vortex.types';
7
7
  interface PrepareDepositProofArgs {
8
8
  tx: Transaction;
@@ -12,11 +12,12 @@ interface PrepareDepositProofArgs {
12
12
  vortexSdk: Vortex;
13
13
  vortexKeypair: VortexKeypairType;
14
14
  vortexPool: string | VortexPool;
15
- merkleTree: MerkleTree;
15
+ root: bigint;
16
+ getMerklePathFn: GetMerklePathFn;
16
17
  relayer: string;
17
18
  relayerFee: bigint;
18
19
  }
19
- export declare const prepareDepositProof: ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, merkleTree, relayer, relayerFee, }: PrepareDepositProofArgs) => Promise<{
20
+ export declare const prepareDepositProof: ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer, relayerFee, }: PrepareDepositProofArgs) => Promise<{
20
21
  extData: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
21
22
  tx: Transaction;
22
23
  moveProof: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
@@ -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;AAKxC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,aAAa,IA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AM,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,mBAAmB,GAAU,gIAYvC,uBAAuB;;;;;;;;EA+HzB,CAAC"}
@@ -2,10 +2,13 @@ import { MerkleTree } from 'fixed-merkle-tree';
2
2
  import { Utxo } from '../entities/utxo';
3
3
  import { VortexKeypair } from '../entities/keypair';
4
4
  import { SuiObjectData } from '@mysten/sui/client';
5
- export declare function getMerklePath(merkleTree: MerkleTree, utxo: Utxo | null): [string, string][];
5
+ export type MerklePath = [string, string][];
6
+ export declare function getMerklePath(merkleTree: MerkleTree, utxo: Utxo | null): MerklePath;
6
7
  interface ToProveInputArgs {
7
8
  vortexObjectId: string;
8
- merkleTree: MerkleTree;
9
+ root: bigint;
10
+ merklePath0: MerklePath;
11
+ merklePath1: MerklePath;
9
12
  publicAmount: bigint;
10
13
  nullifier0: bigint;
11
14
  nullifier1: bigint;
@@ -18,7 +21,7 @@ interface ToProveInputArgs {
18
21
  outputUtxo1: Utxo;
19
22
  accountSecret: bigint;
20
23
  }
21
- export declare const toProveInput: ({ merkleTree, publicAmount, nullifier0, nullifier1, commitment0, commitment1, vortexKeypair, inputUtxo0, inputUtxo1, outputUtxo0, outputUtxo1, vortexObjectId, accountSecret, }: ToProveInputArgs) => {
24
+ export declare const toProveInput: ({ root, merklePath0, merklePath1, publicAmount, nullifier0, nullifier1, commitment0, commitment1, vortexKeypair, inputUtxo0, inputUtxo1, outputUtxo0, outputUtxo1, vortexObjectId, accountSecret, }: ToProveInputArgs) => {
22
25
  vortex: bigint;
23
26
  root: bigint;
24
27
  publicAmount: bigint;
@@ -36,8 +39,8 @@ export declare const toProveInput: ({ merkleTree, publicAmount, nullifier0, null
36
39
  inBlinding1: bigint;
37
40
  inPathIndex0: bigint;
38
41
  inPathIndex1: bigint;
39
- merklePath0: [string, string][];
40
- merklePath1: [string, string][];
42
+ merklePath0: MerklePath;
43
+ merklePath1: MerklePath;
41
44
  outPublicKey0: string;
42
45
  outPublicKey1: string;
43
46
  outAmount0: bigint;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,GAAG,IAAI,GAChB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAkEpB;AAED,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,WAAW,EAAE,IAAI,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,YAAY,GAAI,iLAc1B,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;CAiClB,CAAC;AAQF,eAAO,MAAM,eAAe,GAAI,MAAM,aAAa;;;;;;;CAelD,CAAC;AAEF,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;AAE5C,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,GAAG,IAAI,GAChB,UAAU,CAkEZ;AAED,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,UAAU,CAAC;IACxB,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,WAAW,EAAE,IAAI,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,YAAY,GAAI,qMAgB1B,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;CAiClB,CAAC;AAQF,eAAO,MAAM,eAAe,GAAI,MAAM,aAAa;;;;;;;CAelD,CAAC;AAEF,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
@@ -1,22 +1,23 @@
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
5
  import { Vortex } from '../vortex';
5
- import { MerkleTree } from 'fixed-merkle-tree';
6
6
  interface PrepareWithdrawArgs {
7
7
  tx?: Transaction;
8
8
  amount: bigint;
9
9
  unspentUtxos: Utxo[];
10
10
  vortexPool: string | any;
11
11
  vortexKeypair: VortexKeypair;
12
- merkleTree: MerkleTree;
12
+ root: bigint;
13
+ getMerklePathFn: GetMerklePathFn;
13
14
  recipient: string;
14
15
  relayer: string;
15
16
  relayerFee: bigint;
16
17
  vortexSdk: Vortex;
17
18
  accountSecret: bigint;
18
19
  }
19
- export declare const prepareWithdraw: ({ tx, amount, unspentUtxos, vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, accountSecret, }: PrepareWithdrawArgs) => Promise<{
20
+ export declare const prepareWithdraw: ({ tx, amount, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, accountSecret, }: PrepareWithdrawArgs) => Promise<{
20
21
  tx: Transaction;
21
22
  moveProof: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
22
23
  extData: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
@@ -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;AAUpD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,UAAU,mBAAmB;IAC3B,EAAE,CAAC,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,IAAI,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC;IACzB,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,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;;;;;EA2HrB,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,MAAM,iBAAiB,CAAC;AACjE,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,GAAG,CAAC;IACzB,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,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,2IAanC,mBAAmB;;;;;EAiIrB,CAAC"}
@@ -2,13 +2,14 @@ import { MaybeTx } from '@interest-protocol/sui-core-sdk';
2
2
  import { TransactionResult } from '@mysten/sui/transactions';
3
3
  import { Vortex } from './vortex';
4
4
  import { VortexKeypair } from './entities/keypair';
5
- import { MerkleTree } from 'fixed-merkle-tree';
6
5
  import { Utxo } from './entities/utxo';
7
- import { CoinStruct } from '@mysten/sui/dist/cjs/client';
6
+ import { CoinStruct } from '@mysten/sui/client';
7
+ import { MerklePath } from './utils';
8
8
  export declare enum Action {
9
9
  Deposit = 0,
10
10
  Withdraw = 1
11
11
  }
12
+ export type GetMerklePathFn = (utxo: Utxo | null) => Promise<MerklePath>;
12
13
  export interface RegisterArgs extends MaybeTx {
13
14
  encryptionKey: string;
14
15
  }
@@ -82,7 +83,8 @@ export interface DepositArgs extends MaybeTx {
82
83
  vortexSdk: Vortex;
83
84
  vortexPool: string | VortexPool;
84
85
  vortexKeypair: VortexKeypair;
85
- merkleTree: MerkleTree;
86
+ root: bigint;
87
+ getMerklePathFn: GetMerklePathFn;
86
88
  unspentUtxos?: Utxo[];
87
89
  relayer?: string;
88
90
  relayerFee?: bigint;
@@ -91,7 +93,8 @@ export interface DepositWithAccountArgs extends MaybeTx {
91
93
  vortexSdk: Vortex;
92
94
  vortexPool: string | VortexPool;
93
95
  vortexKeypair: VortexKeypair;
94
- merkleTree: MerkleTree;
96
+ root: bigint;
97
+ getMerklePathFn: GetMerklePathFn;
95
98
  unspentUtxos?: Utxo[];
96
99
  account: string;
97
100
  accountSecret: bigint;
@@ -105,7 +108,8 @@ export interface WithdrawArgs extends MaybeTx {
105
108
  unspentUtxos: Utxo[];
106
109
  vortexSdk: Vortex;
107
110
  vortexKeypair: VortexKeypair;
108
- merkleTree: MerkleTree;
111
+ root: bigint;
112
+ getMerklePathFn: GetMerklePathFn;
109
113
  recipient: string;
110
114
  relayer: string;
111
115
  relayerFee: bigint;
@@ -114,7 +118,8 @@ export interface WithdrawWithAccountArgs extends MaybeTx {
114
118
  vortexSdk: Vortex;
115
119
  vortexPool: string | VortexPool;
116
120
  vortexKeypair: VortexKeypair;
117
- merkleTree: MerkleTree;
121
+ root: bigint;
122
+ getMerklePathFn: GetMerklePathFn;
118
123
  unspentUtxos?: Utxo[];
119
124
  account: string;
120
125
  accountSecret: bigint;
@@ -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CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;CACjC;AAED,MAAM,WAAW,cAAe,SAAQ,OAAO;IAC7C,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAe,SAAQ,OAAO;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB"}
@@ -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, merkleTree, recipient, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }: WithdrawWithAccountArgs) => Promise<{
3
+ export declare const withdrawWithAccount: ({ tx, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn, recipient, 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,yIAavC,uBAAuB;;;EA4BzB,CAAC"}
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,oJAcvC,uBAAuB;;;EA6BzB,CAAC"}
@@ -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, merkleTree, recipient, relayer, relayerFee, vortexSdk, }: WithdrawArgs) => Promise<{
3
+ export declare const withdraw: ({ tx, amount, unspentUtxos, vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, }: WithdrawArgs) => Promise<{
4
4
  tx: Transaction;
5
5
  coin: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
6
6
  }>;
@@ -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,iHAW5B,YAAY;;;EA6Bd,CAAC"}
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,4HAY5B,YAAY;;;EA8Bd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interest-protocol/vortex-sdk",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "./dist/index.mjs",
package/src/constants.ts CHANGED
@@ -73,15 +73,15 @@ export const ERROR_CODES = {
73
73
  };
74
74
 
75
75
  export const VORTEX_PACKAGE_ID =
76
- '0x866c91d28ee641d6a419e1431e9df918c701730fb45993883c75b107e7424bed';
76
+ '0x4d505443700db57e664f024b4cdfe315a6b80ddc4d6b9f1013c7b68682edd4ab';
77
77
 
78
78
  export const UPGRADE_CAP =
79
- '0xea089918d682128c395e5ef469bfa091fb4c753ef9f24a4ce6dbaa1cbb4c16e6';
79
+ '0x6c4464ca68d4bcd0c0626dcbb7c2b7ec37cb65a6cc74ffb2c16cd8cff3184004';
80
80
 
81
81
  export const REGISTRY_OBJECT_ID =
82
- '0x81b00cf5d31df30a5e01c9bfb179608746b29c856d1a5e4d50e83a0f6fa5ff45';
82
+ '0x58bde5ffed343073d012d28c6955a8ee50caaefd085196e837150bc810e996c0';
83
83
 
84
- export const INITIAL_SHARED_VERSION = '50';
84
+ export const INITIAL_SHARED_VERSION = '4';
85
85
 
86
86
  export const LSK_FETCH_OFFSET = 'fetch_offset';
87
87
 
@@ -99,5 +99,5 @@ export const BASIS_POINTS = 10_000n;
99
99
 
100
100
  export const VORTEX_POOL_IDS = {
101
101
  [SUI_TYPE_ARG]:
102
- '0x45a517f826fa18e2d9d189771feb5c5ba99d54448df35c926fbadc27f824f81b',
102
+ '0x1d8ddda4727146fd39f8181578ae71cd0f828039c68b4bfdba8a7499dda1d84d',
103
103
  };
@@ -11,7 +11,8 @@ export const depositWithAccount = async ({
11
11
  vortexSdk,
12
12
  vortexKeypair,
13
13
  vortexPool,
14
- merkleTree,
14
+ root,
15
+ getMerklePathFn,
15
16
  accountSecret,
16
17
  account,
17
18
  coinStructs,
@@ -31,7 +32,7 @@ export const depositWithAccount = async ({
31
32
 
32
33
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
33
34
  invariant(
34
- BN254_FIELD_MODULUS > amount,
35
+ BN254_FIELD_MODULUS >= amount,
35
36
  'Amount must be less than field modulus'
36
37
  );
37
38
 
@@ -47,7 +48,8 @@ export const depositWithAccount = async ({
47
48
  vortexSdk,
48
49
  vortexKeypair,
49
50
  vortexPool,
50
- merkleTree,
51
+ root,
52
+ getMerklePathFn,
51
53
  relayer,
52
54
  relayerFee,
53
55
  });
package/src/deposit.ts CHANGED
@@ -12,7 +12,8 @@ export const deposit = async ({
12
12
  vortexSdk,
13
13
  vortexKeypair,
14
14
  vortexPool,
15
- merkleTree,
15
+ root,
16
+ getMerklePathFn,
16
17
  relayer = normalizeSuiAddress('0x0'),
17
18
  relayerFee = 0n,
18
19
  }: DepositArgs) => {
@@ -36,7 +37,8 @@ export const deposit = async ({
36
37
  vortexSdk,
37
38
  vortexKeypair,
38
39
  vortexPool,
39
- merkleTree,
40
+ root,
41
+ getMerklePathFn,
40
42
  relayer,
41
43
  relayerFee,
42
44
  });
@@ -197,6 +197,23 @@ export class VortexKeypair {
197
197
  };
198
198
  }
199
199
 
200
+ static encryptBigIntFor(
201
+ value: bigint,
202
+ recipientEncryptionKey: string
203
+ ): string {
204
+ // Convert BigInt to hex string, then to bytes
205
+ const hex = value.toString(16);
206
+ const hexPadded = hex.length % 2 === 0 ? hex : '0' + hex;
207
+ const bytes = Buffer.from(hexPadded, 'hex');
208
+ return VortexKeypair.encryptFor(bytes, recipientEncryptionKey);
209
+ }
210
+
211
+ decryptBigInt(encryptedData: string): bigint {
212
+ const decrypted = this.#decrypt(encryptedData);
213
+ const hex = decrypted.toString('hex');
214
+ return BigInt('0x' + hex);
215
+ }
216
+
200
217
  sign(commitment: bigint, merklePath: bigint): bigint {
201
218
  invariant(this.privateKey !== null, 'Cannot sign without private key');
202
219
  return poseidon3(this.privateKey, commitment, merklePath);
@@ -5,11 +5,11 @@ import { VortexKeypair } from '../entities/keypair';
5
5
  import { Utxo } from '../entities/utxo';
6
6
  import { fromHex, normalizeSuiAddress } from '@mysten/sui/utils';
7
7
  import { toProveInput } from '.';
8
- import { Proof, Action } from '../vortex.types';
8
+ import { Proof, Action, GetMerklePathFn } from '../vortex.types';
9
9
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
10
10
  import { Vortex } from '../vortex';
11
11
  import { VortexKeypair as VortexKeypairType } from '../entities/keypair';
12
- import { MerkleTree } from 'fixed-merkle-tree';
12
+
13
13
  import { VortexPool } from '../vortex.types';
14
14
 
15
15
  interface PrepareDepositProofArgs {
@@ -20,7 +20,8 @@ interface PrepareDepositProofArgs {
20
20
  vortexSdk: Vortex;
21
21
  vortexKeypair: VortexKeypairType;
22
22
  vortexPool: string | VortexPool;
23
- merkleTree: MerkleTree;
23
+ root: bigint;
24
+ getMerklePathFn: GetMerklePathFn;
24
25
  relayer: string;
25
26
  relayerFee: bigint;
26
27
  }
@@ -33,7 +34,8 @@ export const prepareDepositProof = async ({
33
34
  vortexSdk,
34
35
  vortexKeypair,
35
36
  vortexPool,
36
- merkleTree,
37
+ root,
38
+ getMerklePathFn,
37
39
  relayer,
38
40
  relayerFee,
39
41
  }: PrepareDepositProofArgs) => {
@@ -65,7 +67,11 @@ export const prepareDepositProof = async ({
65
67
  vortexPool: vortexObjectId,
66
68
  });
67
69
 
68
- const nextIndex = await vortexSdk.nextIndex(vortexPool);
70
+ const [nextIndex, merklePath0, merklePath1] = await Promise.all([
71
+ vortexSdk.nextIndex(vortexPool),
72
+ getMerklePathFn(inputUtxo0),
73
+ getMerklePathFn(inputUtxo1),
74
+ ]);
69
75
 
70
76
  // Calculate output UTXO0 amount: if using unspent UTXOs, include their amounts
71
77
  const outputUtxo0 = new Utxo({
@@ -105,7 +111,9 @@ export const prepareDepositProof = async ({
105
111
  const input = toProveInput({
106
112
  vortexObjectId,
107
113
  accountSecret,
108
- merkleTree,
114
+ root,
115
+ merklePath0,
116
+ merklePath1,
109
117
  publicAmount: amount - relayerFee,
110
118
  nullifier0,
111
119
  nullifier1,
@@ -139,7 +147,7 @@ export const prepareDepositProof = async ({
139
147
  tx: tx2,
140
148
  vortexPool,
141
149
  proofPoints: fromHex('0x' + proof.proofSerializedHex),
142
- root: BigInt(merkleTree.root),
150
+ root,
143
151
  publicValue: amount - relayerFee,
144
152
  action: Action.Deposit,
145
153
  inputNullifier0: nullifier0,
@@ -1,8 +1,4 @@
1
- import {
2
- normalizeSuiAddress,
3
- toHex,
4
- normalizeStructTag,
5
- } from '@mysten/sui/utils';
1
+ import { normalizeSuiAddress, normalizeStructTag } from '@mysten/sui/utils';
6
2
  import invariant from 'tiny-invariant';
7
3
  import { MerkleTree } from 'fixed-merkle-tree';
8
4
  import { Utxo } from '../entities/utxo';
@@ -14,10 +10,12 @@ import { pathOr } from 'ramda';
14
10
  import { poseidon1 } from '../crypto';
15
11
  import { BN254_FIELD_MODULUS } from '../constants';
16
12
 
13
+ export type MerklePath = [string, string][];
14
+
17
15
  export function getMerklePath(
18
16
  merkleTree: MerkleTree,
19
17
  utxo: Utxo | null
20
- ): [string, string][] {
18
+ ): MerklePath {
21
19
  // Handle zero-amount UTXOs
22
20
  if (!utxo || utxo.amount === 0n) {
23
21
  return Array(MERKLE_TREE_HEIGHT)
@@ -87,7 +85,9 @@ export function getMerklePath(
87
85
 
88
86
  interface ToProveInputArgs {
89
87
  vortexObjectId: string;
90
- merkleTree: MerkleTree;
88
+ root: bigint;
89
+ merklePath0: MerklePath;
90
+ merklePath1: MerklePath;
91
91
  publicAmount: bigint;
92
92
  nullifier0: bigint;
93
93
  nullifier1: bigint;
@@ -102,7 +102,9 @@ interface ToProveInputArgs {
102
102
  }
103
103
 
104
104
  export const toProveInput = ({
105
- merkleTree,
105
+ root,
106
+ merklePath0,
107
+ merklePath1,
106
108
  publicAmount,
107
109
  nullifier0,
108
110
  nullifier1,
@@ -121,7 +123,7 @@ export const toProveInput = ({
121
123
  BigInt(
122
124
  normalizeSuiAddress(vortexObjectId, !vortexObjectId.startsWith('0x'))
123
125
  ) % BN254_FIELD_MODULUS,
124
- root: BigInt(merkleTree.root),
126
+ root,
125
127
  publicAmount,
126
128
  inputNullifier0: nullifier0,
127
129
  inputNullifier1: nullifier1,
@@ -138,8 +140,8 @@ export const toProveInput = ({
138
140
  inBlinding1: inputUtxo1.blinding,
139
141
  inPathIndex0: inputUtxo0.index,
140
142
  inPathIndex1: inputUtxo1.index,
141
- merklePath0: getMerklePath(merkleTree, inputUtxo0),
142
- merklePath1: getMerklePath(merkleTree, inputUtxo1),
143
+ merklePath0,
144
+ merklePath1,
143
145
 
144
146
  outPublicKey0: vortexKeypair.publicKey,
145
147
  outPublicKey1: vortexKeypair.publicKey,
@@ -9,9 +9,8 @@ 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 } from '../vortex.types';
12
+ import { Proof, Action, GetMerklePathFn } from '../vortex.types';
13
13
  import { Vortex } from '../vortex';
14
- import { MerkleTree } from 'fixed-merkle-tree';
15
14
 
16
15
  interface PrepareWithdrawArgs {
17
16
  tx?: Transaction;
@@ -19,7 +18,8 @@ interface PrepareWithdrawArgs {
19
18
  unspentUtxos: Utxo[];
20
19
  vortexPool: string | any;
21
20
  vortexKeypair: VortexKeypair;
22
- merkleTree: MerkleTree;
21
+ root: bigint;
22
+ getMerklePathFn: GetMerklePathFn;
23
23
  recipient: string;
24
24
  relayer: string;
25
25
  relayerFee: bigint;
@@ -33,7 +33,8 @@ export const prepareWithdraw = async ({
33
33
  unspentUtxos = [],
34
34
  vortexPool,
35
35
  vortexKeypair,
36
- merkleTree,
36
+ root,
37
+ getMerklePathFn,
37
38
  recipient,
38
39
  relayer,
39
40
  relayerFee,
@@ -73,7 +74,11 @@ export const prepareWithdraw = async ({
73
74
 
74
75
  const changeAmount = totalWithdrawAmount - amount;
75
76
 
76
- const nextIndex = await vortexSdk.nextIndex(vortexPool);
77
+ const [nextIndex, merklePath0, merklePath1] = await Promise.all([
78
+ vortexSdk.nextIndex(vortexPool),
79
+ getMerklePathFn(inputUtxo0),
80
+ getMerklePathFn(inputUtxo1),
81
+ ]);
77
82
 
78
83
  const outputUtxo0 = new Utxo({
79
84
  amount: changeAmount,
@@ -113,7 +118,9 @@ export const prepareWithdraw = async ({
113
118
  const input = toProveInput({
114
119
  vortexObjectId,
115
120
  accountSecret,
116
- merkleTree,
121
+ root,
122
+ merklePath0,
123
+ merklePath1,
117
124
  publicAmount: BN254_FIELD_MODULUS - amount,
118
125
  nullifier0,
119
126
  nullifier1,
@@ -147,7 +154,7 @@ export const prepareWithdraw = async ({
147
154
  vortexPool,
148
155
  tx: tx2,
149
156
  proofPoints: fromHex('0x' + proof.proofSerializedHex),
150
- root: BigInt(merkleTree.root),
157
+ root,
151
158
  publicValue: amount,
152
159
  action: Action.Withdraw,
153
160
  inputNullifier0: nullifier0,
@@ -2,14 +2,17 @@ import { MaybeTx } from '@interest-protocol/sui-core-sdk';
2
2
  import { TransactionResult } from '@mysten/sui/transactions';
3
3
  import { Vortex } from './vortex';
4
4
  import { VortexKeypair } from './entities/keypair';
5
- import { MerkleTree } from 'fixed-merkle-tree';
6
5
  import { Utxo } from './entities/utxo';
7
- import { CoinStruct } from '@mysten/sui/dist/cjs/client';
6
+ import { CoinStruct } from '@mysten/sui/client';
7
+ import { MerklePath } from './utils';
8
+
8
9
  export enum Action {
9
10
  Deposit,
10
11
  Withdraw,
11
12
  }
12
13
 
14
+ export type GetMerklePathFn = (utxo: Utxo | null) => Promise<MerklePath>;
15
+
13
16
  export interface RegisterArgs extends MaybeTx {
14
17
  encryptionKey: string;
15
18
  }
@@ -94,7 +97,8 @@ export interface DepositArgs extends MaybeTx {
94
97
  vortexSdk: Vortex;
95
98
  vortexPool: string | VortexPool;
96
99
  vortexKeypair: VortexKeypair;
97
- merkleTree: MerkleTree;
100
+ root: bigint;
101
+ getMerklePathFn: GetMerklePathFn;
98
102
  unspentUtxos?: Utxo[];
99
103
  relayer?: string;
100
104
  relayerFee?: bigint;
@@ -104,7 +108,8 @@ export interface DepositWithAccountArgs extends MaybeTx {
104
108
  vortexSdk: Vortex;
105
109
  vortexPool: string | VortexPool;
106
110
  vortexKeypair: VortexKeypair;
107
- merkleTree: MerkleTree;
111
+ root: bigint;
112
+ getMerklePathFn: GetMerklePathFn;
108
113
  unspentUtxos?: Utxo[];
109
114
  account: string;
110
115
  accountSecret: bigint;
@@ -119,7 +124,8 @@ export interface WithdrawArgs extends MaybeTx {
119
124
  unspentUtxos: Utxo[];
120
125
  vortexSdk: Vortex;
121
126
  vortexKeypair: VortexKeypair;
122
- merkleTree: MerkleTree;
127
+ root: bigint;
128
+ getMerklePathFn: GetMerklePathFn;
123
129
  recipient: string;
124
130
  relayer: string;
125
131
  relayerFee: bigint;
@@ -129,7 +135,8 @@ export interface WithdrawWithAccountArgs extends MaybeTx {
129
135
  vortexSdk: Vortex;
130
136
  vortexPool: string | VortexPool;
131
137
  vortexKeypair: VortexKeypair;
132
- merkleTree: MerkleTree;
138
+ root: bigint;
139
+ getMerklePathFn: GetMerklePathFn;
133
140
  unspentUtxos?: Utxo[];
134
141
  account: string;
135
142
  accountSecret: bigint;
@@ -7,7 +7,8 @@ export const withdrawWithAccount = async ({
7
7
  unspentUtxos = [],
8
8
  vortexPool,
9
9
  vortexKeypair,
10
- merkleTree,
10
+ root,
11
+ getMerklePathFn,
11
12
  recipient,
12
13
  relayer,
13
14
  relayerFee,
@@ -27,7 +28,8 @@ export const withdrawWithAccount = async ({
27
28
  unspentUtxos,
28
29
  vortexPool,
29
30
  vortexKeypair,
30
- merkleTree,
31
+ root,
32
+ getMerklePathFn,
31
33
  recipient,
32
34
  relayer,
33
35
  relayerFee,
package/src/withdraw.ts CHANGED
@@ -8,7 +8,8 @@ export const withdraw = async ({
8
8
  unspentUtxos = [],
9
9
  vortexPool,
10
10
  vortexKeypair,
11
- merkleTree,
11
+ root,
12
+ getMerklePathFn,
12
13
  recipient,
13
14
  relayer,
14
15
  relayerFee,
@@ -25,7 +26,8 @@ export const withdraw = async ({
25
26
  unspentUtxos,
26
27
  vortexPool,
27
28
  vortexKeypair,
28
- merkleTree,
29
+ root,
30
+ getMerklePathFn,
29
31
  recipient,
30
32
  relayer,
31
33
  relayerFee,