@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.
@@ -26,10 +26,10 @@ export declare const ERROR_CODES: {
26
26
  13: string;
27
27
  14: string;
28
28
  };
29
- export declare const VORTEX_PACKAGE_ID = "0x866c91d28ee641d6a419e1431e9df918c701730fb45993883c75b107e7424bed";
30
- export declare const UPGRADE_CAP = "0xea089918d682128c395e5ef469bfa091fb4c753ef9f24a4ce6dbaa1cbb4c16e6";
31
- export declare const REGISTRY_OBJECT_ID = "0x81b00cf5d31df30a5e01c9bfb179608746b29c856d1a5e4d50e83a0f6fa5ff45";
32
- export declare const INITIAL_SHARED_VERSION = "50";
29
+ export declare const VORTEX_PACKAGE_ID = "0x4d505443700db57e664f024b4cdfe315a6b80ddc4d6b9f1013c7b68682edd4ab";
30
+ export declare const UPGRADE_CAP = "0x6c4464ca68d4bcd0c0626dcbb7c2b7ec37cb65a6cc74ffb2c16cd8cff3184004";
31
+ export declare const REGISTRY_OBJECT_ID = "0x58bde5ffed343073d012d28c6955a8ee50caaefd085196e837150bc810e996c0";
32
+ export declare const INITIAL_SHARED_VERSION = "4";
33
33
  export declare const LSK_FETCH_OFFSET = "fetch_offset";
34
34
  export declare const LSK_ENCRYPTED_OUTPUTS = "encrypted_outputs";
35
35
  export declare const VORTEX_SIGNATURE_DOMAIN = "VORTEXFI.XYZ";
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,iFACgD,CAAC;AAGjF,eAAO,MAAM,UAAU,iFACyD,CAAC;AAEjF,eAAO,MAAM,gBAAgB,iFAAa,CAAC;AAE3C,eAAO,MAAM,oBAAoB,UAiChC,CAAC;AAEF,oBAAY,OAAO;IACjB,OAAO,oBAAoB;IAC3B,KAAK,iBAAiB;IACtB,MAAM,WAAW;CAClB;AAED,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O,MAAM,qBAAqB,sBAAsB,CAAC;AAEzD,eAAO,MAAM,uBAAuB,iBAAiB,CAAC;AAEtD,eAAO,MAAM,gBAAgB,uEACyC,CAAC;AAGvE,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C,eAAO,MAAM,YAAY,SAAU,CAAC;AAEpC,eAAO,MAAM,eAAe;;CAG3B,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Transaction } from '@mysten/sui/transactions';
2
2
  import { DepositWithAccountArgs } from './vortex.types';
3
- export declare const depositWithAccount: ({ tx, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, merkleTree, accountSecret, account, coinStructs, relayer, relayerFee, }: DepositWithAccountArgs) => Promise<{
3
+ export declare const depositWithAccount: ({ tx, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, accountSecret, account, coinStructs, relayer, relayerFee, }: DepositWithAccountArgs) => Promise<{
4
4
  tx: Transaction;
5
5
  coin: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
6
6
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"deposit-with-account.d.ts","sourceRoot":"","sources":["../src/deposit-with-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAIxD,eAAO,MAAM,kBAAkB,GAAU,mIAYtC,sBAAsB;;;EA2CxB,CAAC"}
1
+ {"version":3,"file":"deposit-with-account.d.ts","sourceRoot":"","sources":["../src/deposit-with-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAIxD,eAAO,MAAM,kBAAkB,GAAU,8IAatC,sBAAsB;;;EA4CxB,CAAC"}
package/dist/deposit.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Transaction } from '@mysten/sui/transactions';
2
2
  import { DepositArgs } from './vortex.types';
3
- export declare const deposit: ({ tx, amount, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, merkleTree, relayer, relayerFee, }: DepositArgs) => Promise<{
3
+ export declare const deposit: ({ tx, amount, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer, relayerFee, }: DepositArgs) => Promise<{
4
4
  tx: Transaction;
5
5
  coin: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
6
6
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../src/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,eAAO,MAAM,OAAO,GAAU,sGAU3B,WAAW;;;EAmCb,CAAC"}
1
+ {"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../src/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,eAAO,MAAM,OAAO,GAAU,iHAW3B,WAAW;;;EAoCb,CAAC"}
@@ -22,6 +22,8 @@ export declare class VortexKeypair {
22
22
  static encryptFor(bytes: Buffer, recipientEncryptionKey: string): string;
23
23
  static encryptUtxoFor(utxo: UtxoPayload, recipientEncryptionKey: string): string;
24
24
  decryptUtxo(encryptedData: string): UtxoPayload;
25
+ static encryptBigIntFor(value: bigint, recipientEncryptionKey: string): string;
26
+ decryptBigInt(encryptedData: string): bigint;
25
27
  sign(commitment: bigint, merklePath: bigint): bigint;
26
28
  toString(): string;
27
29
  address(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"keypair.d.ts","sourceRoot":"","sources":["../../src/entities/keypair.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAA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PACKAGE_ID = '0x866c91d28ee641d6a419e1431e9df918c701730fb45993883c75b107e7424bed';
3376
- const UPGRADE_CAP = '0xea089918d682128c395e5ef469bfa091fb4c753ef9f24a4ce6dbaa1cbb4c16e6';
3377
- const REGISTRY_OBJECT_ID = '0x81b00cf5d31df30a5e01c9bfb179608746b29c856d1a5e4d50e83a0f6fa5ff45';
3378
- const INITIAL_SHARED_VERSION = '50';
3375
+ const VORTEX_PACKAGE_ID = '0x4d505443700db57e664f024b4cdfe315a6b80ddc4d6b9f1013c7b68682edd4ab';
3376
+ const UPGRADE_CAP = '0x6c4464ca68d4bcd0c0626dcbb7c2b7ec37cb65a6cc74ffb2c16cd8cff3184004';
3377
+ const REGISTRY_OBJECT_ID = '0x58bde5ffed343073d012d28c6955a8ee50caaefd085196e837150bc810e996c0';
3378
+ const INITIAL_SHARED_VERSION = '4';
3379
3379
  const LSK_FETCH_OFFSET = 'fetch_offset';
3380
3380
  const LSK_ENCRYPTED_OUTPUTS = 'encrypted_outputs';
3381
3381
  const VORTEX_SIGNATURE_DOMAIN = 'VORTEXFI.XYZ';
@@ -3384,7 +3384,7 @@ const TREASURY_ADDRESS = '0x894261575b948c035d002adc3ca4d73c683c01a1bfafac183870
3384
3384
  const DEPOSIT_FEE_IN_BASIS_POINTS = 50n;
3385
3385
  const BASIS_POINTS = 10000n;
3386
3386
  const VORTEX_POOL_IDS = {
3387
- [SUI_TYPE_ARG]: '0x45a517f826fa18e2d9d189771feb5c5ba99d54448df35c926fbadc27f824f81b',
3387
+ [SUI_TYPE_ARG]: '0x1d8ddda4727146fd39f8181578ae71cd0f828039c68b4bfdba8a7499dda1d84d',
3388
3388
  };
3389
3389
 
3390
3390
  /******************************************************************************
@@ -39122,6 +39122,18 @@ class VortexKeypair {
39122
39122
  vortexPool: normalizeSuiAddress(parts[3]),
39123
39123
  };
39124
39124
  }
39125
+ static encryptBigIntFor(value, recipientEncryptionKey) {
39126
+ // Convert BigInt to hex string, then to bytes
39127
+ const hex = value.toString(16);
39128
+ const hexPadded = hex.length % 2 === 0 ? hex : '0' + hex;
39129
+ const bytes = Buffer.from(hexPadded, 'hex');
39130
+ return VortexKeypair.encryptFor(bytes, recipientEncryptionKey);
39131
+ }
39132
+ decryptBigInt(encryptedData) {
39133
+ const decrypted = __classPrivateFieldGet(this, _VortexKeypair_instances, "m", _VortexKeypair_decrypt).call(this, encryptedData);
39134
+ const hex = decrypted.toString('hex');
39135
+ return BigInt('0x' + hex);
39136
+ }
39125
39137
  sign(commitment, merklePath) {
39126
39138
  invariant(this.privateKey !== null, 'Cannot sign without private key');
39127
39139
  return poseidon3(this.privateKey, commitment, merklePath);
@@ -39258,10 +39270,10 @@ function getMerklePath(merkleTree, utxo) {
39258
39270
  invariant(calculatedRoot === expectedRoot, `Root mismatch: calculated ${calculatedRoot}, expected ${expectedRoot}`);
39259
39271
  return wasmPath;
39260
39272
  }
39261
- const toProveInput = ({ merkleTree, publicAmount, nullifier0, nullifier1, commitment0, commitment1, vortexKeypair, inputUtxo0, inputUtxo1, outputUtxo0, outputUtxo1, vortexObjectId, accountSecret, }) => {
39273
+ const toProveInput = ({ root, merklePath0, merklePath1, publicAmount, nullifier0, nullifier1, commitment0, commitment1, vortexKeypair, inputUtxo0, inputUtxo1, outputUtxo0, outputUtxo1, vortexObjectId, accountSecret, }) => {
39262
39274
  return {
39263
39275
  vortex: BigInt(normalizeSuiAddress(vortexObjectId, !vortexObjectId.startsWith('0x'))) % BN254_FIELD_MODULUS,
39264
- root: BigInt(merkleTree.root),
39276
+ root,
39265
39277
  publicAmount,
39266
39278
  inputNullifier0: nullifier0,
39267
39279
  inputNullifier1: nullifier1,
@@ -39277,8 +39289,8 @@ const toProveInput = ({ merkleTree, publicAmount, nullifier0, nullifier1, commit
39277
39289
  inBlinding1: inputUtxo1.blinding,
39278
39290
  inPathIndex0: inputUtxo0.index,
39279
39291
  inPathIndex1: inputUtxo1.index,
39280
- merklePath0: getMerklePath(merkleTree, inputUtxo0),
39281
- merklePath1: getMerklePath(merkleTree, inputUtxo1),
39292
+ merklePath0,
39293
+ merklePath1,
39282
39294
  outPublicKey0: vortexKeypair.publicKey,
39283
39295
  outPublicKey1: vortexKeypair.publicKey,
39284
39296
  outAmount0: outputUtxo0.amount,
@@ -39596,7 +39608,7 @@ const buildMerkleTree = () => new fixedMerkleTree.MerkleTree(MERKLE_TREE_HEIGHT,
39596
39608
  zeroElement: ZERO_VALUE.toString(),
39597
39609
  });
39598
39610
 
39599
- const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, merkleTree, relayer, relayerFee, }) => {
39611
+ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer, relayerFee, }) => {
39600
39612
  const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
39601
39613
  // Deposits we do not need a recipient, so we use a random one.
39602
39614
  const randomRecipient = normalizeSuiAddress(Ed25519Keypair.generate().toSuiAddress());
@@ -39616,7 +39628,11 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39616
39628
  keypair: vortexKeypair,
39617
39629
  vortexPool: vortexObjectId,
39618
39630
  });
39619
- const nextIndex = await vortexSdk.nextIndex(vortexPool);
39631
+ const [nextIndex, merklePath0, merklePath1] = await Promise.all([
39632
+ vortexSdk.nextIndex(vortexPool),
39633
+ getMerklePathFn(inputUtxo0),
39634
+ getMerklePathFn(inputUtxo1),
39635
+ ]);
39620
39636
  // Calculate output UTXO0 amount: if using unspent UTXOs, include their amounts
39621
39637
  const outputUtxo0 = new Utxo({
39622
39638
  amount: amount + inputUtxo0.amount + inputUtxo1.amount - relayerFee,
@@ -39644,7 +39660,9 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39644
39660
  const input = toProveInput({
39645
39661
  vortexObjectId,
39646
39662
  accountSecret,
39647
- merkleTree,
39663
+ root,
39664
+ merklePath0,
39665
+ merklePath1,
39648
39666
  publicAmount: amount - relayerFee,
39649
39667
  nullifier0,
39650
39668
  nullifier1,
@@ -39673,7 +39691,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39673
39691
  tx: tx2,
39674
39692
  vortexPool,
39675
39693
  proofPoints: fromHex('0x' + proof.proofSerializedHex),
39676
- root: BigInt(merkleTree.root),
39694
+ root,
39677
39695
  publicValue: amount - relayerFee,
39678
39696
  action: exports.Action.Deposit,
39679
39697
  inputNullifier0: nullifier0,
@@ -39692,7 +39710,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39692
39710
  };
39693
39711
  };
39694
39712
 
39695
- const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, merkleTree, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39713
+ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39696
39714
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
39697
39715
  invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
39698
39716
  const accountSecret = 0n;
@@ -39704,7 +39722,8 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39704
39722
  vortexSdk,
39705
39723
  vortexKeypair,
39706
39724
  vortexPool,
39707
- merkleTree,
39725
+ root,
39726
+ getMerklePathFn,
39708
39727
  relayer,
39709
39728
  relayerFee,
39710
39729
  });
@@ -39718,7 +39737,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39718
39737
  });
39719
39738
  };
39720
39739
 
39721
- const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39740
+ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39722
39741
  invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
39723
39742
  unspentUtxos.sort((a, b) => new bn_js.BN(b.amount).cmp(new bn_js.BN(a.amount)));
39724
39743
  const totalUnspentUtxosAmount = unspentUtxos
@@ -39737,7 +39756,11 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39737
39756
  });
39738
39757
  const totalWithdrawAmount = inputUtxo0.amount + inputUtxo1.amount;
39739
39758
  const changeAmount = totalWithdrawAmount - amount;
39740
- const nextIndex = await vortexSdk.nextIndex(vortexPool);
39759
+ const [nextIndex, merklePath0, merklePath1] = await Promise.all([
39760
+ vortexSdk.nextIndex(vortexPool),
39761
+ getMerklePathFn(inputUtxo0),
39762
+ getMerklePathFn(inputUtxo1),
39763
+ ]);
39741
39764
  const outputUtxo0 = new Utxo({
39742
39765
  amount: changeAmount,
39743
39766
  index: nextIndex,
@@ -39765,7 +39788,9 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39765
39788
  const input = toProveInput({
39766
39789
  vortexObjectId,
39767
39790
  accountSecret,
39768
- merkleTree,
39791
+ root,
39792
+ merklePath0,
39793
+ merklePath1,
39769
39794
  publicAmount: BN254_FIELD_MODULUS - amount,
39770
39795
  nullifier0,
39771
39796
  nullifier1,
@@ -39794,7 +39819,7 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39794
39819
  vortexPool,
39795
39820
  tx: tx2,
39796
39821
  proofPoints: fromHex('0x' + proof.proofSerializedHex),
39797
- root: BigInt(merkleTree.root),
39822
+ root,
39798
39823
  publicValue: amount,
39799
39824
  action: exports.Action.Withdraw,
39800
39825
  inputNullifier0: nullifier0,
@@ -39810,14 +39835,15 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39810
39835
  };
39811
39836
  };
39812
39837
 
39813
- const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, }) => {
39838
+ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, }) => {
39814
39839
  const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39815
39840
  tx,
39816
39841
  amount,
39817
39842
  unspentUtxos,
39818
39843
  vortexPool,
39819
39844
  vortexKeypair,
39820
- merkleTree,
39845
+ root,
39846
+ getMerklePathFn,
39821
39847
  recipient,
39822
39848
  relayer,
39823
39849
  relayerFee,
@@ -39834,7 +39860,7 @@ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vor
39834
39860
  });
39835
39861
  };
39836
39862
 
39837
- const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, merkleTree, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39863
+ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39838
39864
  const coins = coinStructs.map((coin) => ({
39839
39865
  objectId: coin.coinObjectId,
39840
39866
  version: coin.version,
@@ -39842,7 +39868,7 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39842
39868
  }));
39843
39869
  let amount = coinStructs.reduce((acc, coin) => acc + BigInt(coin.balance), 0n);
39844
39870
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
39845
- invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
39871
+ invariant(BN254_FIELD_MODULUS >= amount, 'Amount must be less than field modulus');
39846
39872
  const { extData, moveProof, tx: tx3, } = await prepareDepositProof({
39847
39873
  tx,
39848
39874
  amount,
@@ -39851,7 +39877,8 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39851
39877
  vortexSdk,
39852
39878
  vortexKeypair,
39853
39879
  vortexPool,
39854
- merkleTree,
39880
+ root,
39881
+ getMerklePathFn,
39855
39882
  relayer,
39856
39883
  relayerFee,
39857
39884
  });
@@ -39865,14 +39892,15 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39865
39892
  });
39866
39893
  };
39867
39894
 
39868
- const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
39895
+ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
39869
39896
  const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39870
39897
  tx,
39871
39898
  amount,
39872
39899
  unspentUtxos,
39873
39900
  vortexPool,
39874
39901
  vortexKeypair,
39875
- merkleTree,
39902
+ root,
39903
+ getMerklePathFn,
39876
39904
  recipient,
39877
39905
  relayer,
39878
39906
  relayerFee,