@interest-protocol/vortex-sdk 4.1.0 → 4.2.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());
@@ -39642,7 +39654,9 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39642
39654
  const input = toProveInput({
39643
39655
  vortexObjectId,
39644
39656
  accountSecret,
39645
- merkleTree,
39657
+ root,
39658
+ merklePath0: await getMerklePathFn(inputUtxo0),
39659
+ merklePath1: await getMerklePathFn(inputUtxo1),
39646
39660
  publicAmount: amount - relayerFee,
39647
39661
  nullifier0,
39648
39662
  nullifier1,
@@ -39671,7 +39685,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39671
39685
  tx: tx2,
39672
39686
  vortexPool,
39673
39687
  proofPoints: fromHex('0x' + proof.proofSerializedHex),
39674
- root: BigInt(merkleTree.root),
39688
+ root,
39675
39689
  publicValue: amount - relayerFee,
39676
39690
  action: Action.Deposit,
39677
39691
  inputNullifier0: nullifier0,
@@ -39690,7 +39704,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39690
39704
  };
39691
39705
  };
39692
39706
 
39693
- const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, merkleTree, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39707
+ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39694
39708
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
39695
39709
  invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
39696
39710
  const accountSecret = 0n;
@@ -39702,7 +39716,8 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39702
39716
  vortexSdk,
39703
39717
  vortexKeypair,
39704
39718
  vortexPool,
39705
- merkleTree,
39719
+ root,
39720
+ getMerklePathFn,
39706
39721
  relayer,
39707
39722
  relayerFee,
39708
39723
  });
@@ -39716,7 +39731,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39716
39731
  });
39717
39732
  };
39718
39733
 
39719
- const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39734
+ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39720
39735
  invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
39721
39736
  unspentUtxos.sort((a, b) => new BN(b.amount).cmp(new BN(a.amount)));
39722
39737
  const totalUnspentUtxosAmount = unspentUtxos
@@ -39763,7 +39778,9 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39763
39778
  const input = toProveInput({
39764
39779
  vortexObjectId,
39765
39780
  accountSecret,
39766
- merkleTree,
39781
+ root,
39782
+ merklePath0: await getMerklePathFn(inputUtxo0),
39783
+ merklePath1: await getMerklePathFn(inputUtxo1),
39767
39784
  publicAmount: BN254_FIELD_MODULUS - amount,
39768
39785
  nullifier0,
39769
39786
  nullifier1,
@@ -39792,7 +39809,7 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39792
39809
  vortexPool,
39793
39810
  tx: tx2,
39794
39811
  proofPoints: fromHex('0x' + proof.proofSerializedHex),
39795
- root: BigInt(merkleTree.root),
39812
+ root,
39796
39813
  publicValue: amount,
39797
39814
  action: Action.Withdraw,
39798
39815
  inputNullifier0: nullifier0,
@@ -39808,14 +39825,15 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39808
39825
  };
39809
39826
  };
39810
39827
 
39811
- const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, }) => {
39828
+ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, }) => {
39812
39829
  const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39813
39830
  tx,
39814
39831
  amount,
39815
39832
  unspentUtxos,
39816
39833
  vortexPool,
39817
39834
  vortexKeypair,
39818
- merkleTree,
39835
+ root,
39836
+ getMerklePathFn,
39819
39837
  recipient,
39820
39838
  relayer,
39821
39839
  relayerFee,
@@ -39832,7 +39850,7 @@ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vor
39832
39850
  });
39833
39851
  };
39834
39852
 
39835
- const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, merkleTree, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39853
+ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39836
39854
  const coins = coinStructs.map((coin) => ({
39837
39855
  objectId: coin.coinObjectId,
39838
39856
  version: coin.version,
@@ -39840,7 +39858,7 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39840
39858
  }));
39841
39859
  let amount = coinStructs.reduce((acc, coin) => acc + BigInt(coin.balance), 0n);
39842
39860
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
39843
- invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
39861
+ invariant(BN254_FIELD_MODULUS >= amount, 'Amount must be less than field modulus');
39844
39862
  const { extData, moveProof, tx: tx3, } = await prepareDepositProof({
39845
39863
  tx,
39846
39864
  amount,
@@ -39849,7 +39867,8 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39849
39867
  vortexSdk,
39850
39868
  vortexKeypair,
39851
39869
  vortexPool,
39852
- merkleTree,
39870
+ root,
39871
+ getMerklePathFn,
39853
39872
  relayer,
39854
39873
  relayerFee,
39855
39874
  });
@@ -39863,14 +39882,15 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39863
39882
  });
39864
39883
  };
39865
39884
 
39866
- const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, merkleTree, recipient, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
39885
+ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, recipient, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
39867
39886
  const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39868
39887
  tx,
39869
39888
  amount,
39870
39889
  unspentUtxos,
39871
39890
  vortexPool,
39872
39891
  vortexKeypair,
39873
- merkleTree,
39892
+ root,
39893
+ getMerklePathFn,
39874
39894
  recipient,
39875
39895
  relayer,
39876
39896
  relayerFee,