@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.
package/dist/index.mjs CHANGED
@@ -3370,10 +3370,10 @@ const ERROR_CODES = {
3370
3370
  13: 'Invalid relayer',
3371
3371
  14: 'Invalid output flag',
3372
3372
  };
3373
- const VORTEX_PACKAGE_ID = '0x866c91d28ee641d6a419e1431e9df918c701730fb45993883c75b107e7424bed';
3374
- const UPGRADE_CAP = '0xea089918d682128c395e5ef469bfa091fb4c753ef9f24a4ce6dbaa1cbb4c16e6';
3375
- const REGISTRY_OBJECT_ID = '0x81b00cf5d31df30a5e01c9bfb179608746b29c856d1a5e4d50e83a0f6fa5ff45';
3376
- const INITIAL_SHARED_VERSION = '50';
3373
+ const VORTEX_PACKAGE_ID = '0x4d505443700db57e664f024b4cdfe315a6b80ddc4d6b9f1013c7b68682edd4ab';
3374
+ const UPGRADE_CAP = '0x6c4464ca68d4bcd0c0626dcbb7c2b7ec37cb65a6cc74ffb2c16cd8cff3184004';
3375
+ const REGISTRY_OBJECT_ID = '0x58bde5ffed343073d012d28c6955a8ee50caaefd085196e837150bc810e996c0';
3376
+ const INITIAL_SHARED_VERSION = '4';
3377
3377
  const LSK_FETCH_OFFSET = 'fetch_offset';
3378
3378
  const LSK_ENCRYPTED_OUTPUTS = 'encrypted_outputs';
3379
3379
  const VORTEX_SIGNATURE_DOMAIN = 'VORTEXFI.XYZ';
@@ -3382,7 +3382,7 @@ const TREASURY_ADDRESS = '0x894261575b948c035d002adc3ca4d73c683c01a1bfafac183870
3382
3382
  const DEPOSIT_FEE_IN_BASIS_POINTS = 50n;
3383
3383
  const BASIS_POINTS = 10000n;
3384
3384
  const VORTEX_POOL_IDS = {
3385
- [SUI_TYPE_ARG]: '0x45a517f826fa18e2d9d189771feb5c5ba99d54448df35c926fbadc27f824f81b',
3385
+ [SUI_TYPE_ARG]: '0x1d8ddda4727146fd39f8181578ae71cd0f828039c68b4bfdba8a7499dda1d84d',
3386
3386
  };
3387
3387
 
3388
3388
  /******************************************************************************
@@ -39120,6 +39120,18 @@ class VortexKeypair {
39120
39120
  vortexPool: normalizeSuiAddress(parts[3]),
39121
39121
  };
39122
39122
  }
39123
+ static encryptBigIntFor(value, recipientEncryptionKey) {
39124
+ // Convert BigInt to hex string, then to bytes
39125
+ const hex = value.toString(16);
39126
+ const hexPadded = hex.length % 2 === 0 ? hex : '0' + hex;
39127
+ const bytes = Buffer.from(hexPadded, 'hex');
39128
+ return VortexKeypair.encryptFor(bytes, recipientEncryptionKey);
39129
+ }
39130
+ decryptBigInt(encryptedData) {
39131
+ const decrypted = __classPrivateFieldGet(this, _VortexKeypair_instances, "m", _VortexKeypair_decrypt).call(this, encryptedData);
39132
+ const hex = decrypted.toString('hex');
39133
+ return BigInt('0x' + hex);
39134
+ }
39123
39135
  sign(commitment, merklePath) {
39124
39136
  invariant(this.privateKey !== null, 'Cannot sign without private key');
39125
39137
  return poseidon3(this.privateKey, commitment, merklePath);
@@ -39256,10 +39268,10 @@ function getMerklePath(merkleTree, utxo) {
39256
39268
  invariant(calculatedRoot === expectedRoot, `Root mismatch: calculated ${calculatedRoot}, expected ${expectedRoot}`);
39257
39269
  return wasmPath;
39258
39270
  }
39259
- const toProveInput = ({ merkleTree, publicAmount, nullifier0, nullifier1, commitment0, commitment1, vortexKeypair, inputUtxo0, inputUtxo1, outputUtxo0, outputUtxo1, vortexObjectId, accountSecret, }) => {
39271
+ const toProveInput = ({ root, merklePath0, merklePath1, publicAmount, nullifier0, nullifier1, commitment0, commitment1, vortexKeypair, inputUtxo0, inputUtxo1, outputUtxo0, outputUtxo1, vortexObjectId, accountSecret, }) => {
39260
39272
  return {
39261
39273
  vortex: BigInt(normalizeSuiAddress(vortexObjectId, !vortexObjectId.startsWith('0x'))) % BN254_FIELD_MODULUS,
39262
- root: BigInt(merkleTree.root),
39274
+ root,
39263
39275
  publicAmount,
39264
39276
  inputNullifier0: nullifier0,
39265
39277
  inputNullifier1: nullifier1,
@@ -39275,8 +39287,8 @@ const toProveInput = ({ merkleTree, publicAmount, nullifier0, nullifier1, commit
39275
39287
  inBlinding1: inputUtxo1.blinding,
39276
39288
  inPathIndex0: inputUtxo0.index,
39277
39289
  inPathIndex1: inputUtxo1.index,
39278
- merklePath0: getMerklePath(merkleTree, inputUtxo0),
39279
- merklePath1: getMerklePath(merkleTree, inputUtxo1),
39290
+ merklePath0,
39291
+ merklePath1,
39280
39292
  outPublicKey0: vortexKeypair.publicKey,
39281
39293
  outPublicKey1: vortexKeypair.publicKey,
39282
39294
  outAmount0: outputUtxo0.amount,
@@ -39594,7 +39606,7 @@ const buildMerkleTree = () => new MerkleTree(MERKLE_TREE_HEIGHT, [], {
39594
39606
  zeroElement: ZERO_VALUE.toString(),
39595
39607
  });
39596
39608
 
39597
- const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, merkleTree, relayer, relayerFee, }) => {
39609
+ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer, relayerFee, }) => {
39598
39610
  const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
39599
39611
  // Deposits we do not need a recipient, so we use a random one.
39600
39612
  const randomRecipient = normalizeSuiAddress(Ed25519Keypair.generate().toSuiAddress());
@@ -39614,7 +39626,11 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39614
39626
  keypair: vortexKeypair,
39615
39627
  vortexPool: vortexObjectId,
39616
39628
  });
39617
- const nextIndex = await vortexSdk.nextIndex(vortexPool);
39629
+ const [nextIndex, merklePath0, merklePath1] = await Promise.all([
39630
+ vortexSdk.nextIndex(vortexPool),
39631
+ getMerklePathFn(inputUtxo0),
39632
+ getMerklePathFn(inputUtxo1),
39633
+ ]);
39618
39634
  // Calculate output UTXO0 amount: if using unspent UTXOs, include their amounts
39619
39635
  const outputUtxo0 = new Utxo({
39620
39636
  amount: amount + inputUtxo0.amount + inputUtxo1.amount - relayerFee,
@@ -39642,7 +39658,9 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39642
39658
  const input = toProveInput({
39643
39659
  vortexObjectId,
39644
39660
  accountSecret,
39645
- merkleTree,
39661
+ root,
39662
+ merklePath0,
39663
+ merklePath1,
39646
39664
  publicAmount: amount - relayerFee,
39647
39665
  nullifier0,
39648
39666
  nullifier1,
@@ -39671,7 +39689,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39671
39689
  tx: tx2,
39672
39690
  vortexPool,
39673
39691
  proofPoints: fromHex('0x' + proof.proofSerializedHex),
39674
- root: BigInt(merkleTree.root),
39692
+ root,
39675
39693
  publicValue: amount - relayerFee,
39676
39694
  action: Action.Deposit,
39677
39695
  inputNullifier0: nullifier0,
@@ -39690,7 +39708,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39690
39708
  };
39691
39709
  };
39692
39710
 
39693
- const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, merkleTree, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39711
+ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39694
39712
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
39695
39713
  invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
39696
39714
  const accountSecret = 0n;
@@ -39702,7 +39720,8 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39702
39720
  vortexSdk,
39703
39721
  vortexKeypair,
39704
39722
  vortexPool,
39705
- merkleTree,
39723
+ root,
39724
+ getMerklePathFn,
39706
39725
  relayer,
39707
39726
  relayerFee,
39708
39727
  });
@@ -39716,7 +39735,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39716
39735
  });
39717
39736
  };
39718
39737
 
39719
- const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39738
+ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39720
39739
  invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
39721
39740
  unspentUtxos.sort((a, b) => new BN(b.amount).cmp(new BN(a.amount)));
39722
39741
  const totalUnspentUtxosAmount = unspentUtxos
@@ -39735,7 +39754,11 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39735
39754
  });
39736
39755
  const totalWithdrawAmount = inputUtxo0.amount + inputUtxo1.amount;
39737
39756
  const changeAmount = totalWithdrawAmount - amount;
39738
- const nextIndex = await vortexSdk.nextIndex(vortexPool);
39757
+ const [nextIndex, merklePath0, merklePath1] = await Promise.all([
39758
+ vortexSdk.nextIndex(vortexPool),
39759
+ getMerklePathFn(inputUtxo0),
39760
+ getMerklePathFn(inputUtxo1),
39761
+ ]);
39739
39762
  const outputUtxo0 = new Utxo({
39740
39763
  amount: changeAmount,
39741
39764
  index: nextIndex,
@@ -39763,7 +39786,9 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39763
39786
  const input = toProveInput({
39764
39787
  vortexObjectId,
39765
39788
  accountSecret,
39766
- merkleTree,
39789
+ root,
39790
+ merklePath0,
39791
+ merklePath1,
39767
39792
  publicAmount: BN254_FIELD_MODULUS - amount,
39768
39793
  nullifier0,
39769
39794
  nullifier1,
@@ -39792,7 +39817,7 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39792
39817
  vortexPool,
39793
39818
  tx: tx2,
39794
39819
  proofPoints: fromHex('0x' + proof.proofSerializedHex),
39795
- root: BigInt(merkleTree.root),
39820
+ root,
39796
39821
  publicValue: amount,
39797
39822
  action: Action.Withdraw,
39798
39823
  inputNullifier0: nullifier0,
@@ -39808,14 +39833,15 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39808
39833
  };
39809
39834
  };
39810
39835
 
39811
- const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, }) => {
39836
+ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, }) => {
39812
39837
  const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39813
39838
  tx,
39814
39839
  amount,
39815
39840
  unspentUtxos,
39816
39841
  vortexPool,
39817
39842
  vortexKeypair,
39818
- merkleTree,
39843
+ root,
39844
+ getMerklePathFn,
39819
39845
  recipient,
39820
39846
  relayer,
39821
39847
  relayerFee,
@@ -39832,7 +39858,7 @@ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vor
39832
39858
  });
39833
39859
  };
39834
39860
 
39835
- const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, merkleTree, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39861
+ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39836
39862
  const coins = coinStructs.map((coin) => ({
39837
39863
  objectId: coin.coinObjectId,
39838
39864
  version: coin.version,
@@ -39840,7 +39866,7 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39840
39866
  }));
39841
39867
  let amount = coinStructs.reduce((acc, coin) => acc + BigInt(coin.balance), 0n);
39842
39868
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
39843
- invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
39869
+ invariant(BN254_FIELD_MODULUS >= amount, 'Amount must be less than field modulus');
39844
39870
  const { extData, moveProof, tx: tx3, } = await prepareDepositProof({
39845
39871
  tx,
39846
39872
  amount,
@@ -39849,7 +39875,8 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39849
39875
  vortexSdk,
39850
39876
  vortexKeypair,
39851
39877
  vortexPool,
39852
- merkleTree,
39878
+ root,
39879
+ getMerklePathFn,
39853
39880
  relayer,
39854
39881
  relayerFee,
39855
39882
  });
@@ -39863,14 +39890,15 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39863
39890
  });
39864
39891
  };
39865
39892
 
39866
- const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
39893
+ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
39867
39894
  const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39868
39895
  tx,
39869
39896
  amount,
39870
39897
  unspentUtxos,
39871
39898
  vortexPool,
39872
39899
  vortexKeypair,
39873
- merkleTree,
39900
+ root,
39901
+ getMerklePathFn,
39874
39902
  recipient,
39875
39903
  relayer,
39876
39904
  relayerFee,