@interest-protocol/vortex-sdk 6.3.0 → 7.1.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.
Files changed (44) hide show
  1. package/dist/deposit-with-account.d.ts +1 -1
  2. package/dist/deposit-with-account.d.ts.map +1 -1
  3. package/dist/deposit.d.ts +1 -1
  4. package/dist/deposit.d.ts.map +1 -1
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +177 -35
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +174 -36
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/swap.d.ts +2 -2
  12. package/dist/swap.d.ts.map +1 -1
  13. package/dist/utils/decrypt.d.ts +8 -0
  14. package/dist/utils/decrypt.d.ts.map +1 -1
  15. package/dist/utils/deposit.d.ts +1 -2
  16. package/dist/utils/deposit.d.ts.map +1 -1
  17. package/dist/utils/withdraw.d.ts +1 -2
  18. package/dist/utils/withdraw.d.ts.map +1 -1
  19. package/dist/vortex-api.d.ts +15 -0
  20. package/dist/vortex-api.d.ts.map +1 -0
  21. package/dist/vortex-api.types.d.ts +115 -0
  22. package/dist/vortex-api.types.d.ts.map +1 -0
  23. package/dist/vortex.d.ts +1 -0
  24. package/dist/vortex.d.ts.map +1 -1
  25. package/dist/vortex.types.d.ts +4 -7
  26. package/dist/vortex.types.d.ts.map +1 -1
  27. package/dist/withdraw-with-account.d.ts +1 -1
  28. package/dist/withdraw-with-account.d.ts.map +1 -1
  29. package/dist/withdraw.d.ts +1 -1
  30. package/dist/withdraw.d.ts.map +1 -1
  31. package/package.json +3 -3
  32. package/src/deposit-with-account.ts +0 -2
  33. package/src/deposit.ts +0 -2
  34. package/src/index.ts +2 -0
  35. package/src/swap.ts +0 -4
  36. package/src/utils/decrypt.ts +57 -1
  37. package/src/utils/deposit.ts +5 -6
  38. package/src/utils/withdraw.ts +4 -4
  39. package/src/vortex-api.ts +192 -0
  40. package/src/vortex-api.types.ts +138 -0
  41. package/src/vortex.ts +9 -9
  42. package/src/vortex.types.ts +3 -7
  43. package/src/withdraw-with-account.ts +0 -2
  44. package/src/withdraw.ts +10 -6
@@ -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, root, getMerklePathFn, accountSecret, account, coinStructs, relayer, relayerFee, }: DepositWithAccountArgs) => Promise<{
3
+ export declare const depositWithAccount: ({ tx, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, 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,8IAatC,sBAAsB;;;EA4CxB,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,wIAYtC,sBAAsB;;;EA2CxB,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, root, getMerklePathFn, relayer, relayerFee, }: DepositArgs) => Promise<{
3
+ export declare const deposit: ({ tx, amount, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, 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,iHAW3B,WAAW;;;EAoCb,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,2GAU3B,WAAW;;;EAmCb,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from './constants';
2
2
  export * from './vortex';
3
+ export * from './vortex-api';
3
4
  export * from './entities';
4
5
  export * from './vortex.types';
6
+ export * from './vortex-api.types';
5
7
  export * from './crypto';
6
8
  export * from './utils';
7
9
  export * from './deposit';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -39236,6 +39236,33 @@ const getUnspentUtxos = async ({ commitmentEvents, vortexKeypair, vortexSdk, vor
39236
39236
  const unspentUtxos = utxos.filter((_, index) => !isNullifierSpentArray[index]);
39237
39237
  return unspentUtxos;
39238
39238
  };
39239
+ const getUnspentUtxosWithApi = async ({ commitments, vortexKeypair, vortexSdk, vortexPool, }) => {
39240
+ const allUtxos = [];
39241
+ const vortexObject = await vortexSdk.resolveVortexPool(vortexPool);
39242
+ commitments.forEach((commitment) => {
39243
+ invariant(normalizeStructTag(commitment.coinType) ===
39244
+ normalizeStructTag(vortexObject.coinType), 'Commitment coin type does not match vortex pool coin type');
39245
+ try {
39246
+ const utxo = vortexKeypair.decryptUtxo(commitment.encryptedOutput);
39247
+ allUtxos.push(utxo);
39248
+ }
39249
+ catch {
39250
+ // Do nothing
39251
+ }
39252
+ });
39253
+ const utxos = allUtxos.map((utxo) => new Utxo({
39254
+ ...utxo,
39255
+ keypair: vortexKeypair,
39256
+ vortexPool: vortexObject.objectId,
39257
+ }));
39258
+ const nullifiers = utxos.map((utxo) => utxo.nullifier());
39259
+ const isNullifierSpentArray = await vortexSdk.areNullifiersSpent({
39260
+ nullifiers,
39261
+ vortexPool,
39262
+ });
39263
+ const unspentUtxos = utxos.filter((_, index) => !isNullifierSpentArray[index]);
39264
+ return unspentUtxos;
39265
+ };
39239
39266
 
39240
39267
  function getMerklePath(merkleTree, utxo) {
39241
39268
  // Handle zero-amount UTXOs
@@ -39327,10 +39354,9 @@ const parseVortexPool = (data) => {
39327
39354
  };
39328
39355
  };
39329
39356
 
39330
- var _Vortex_instances, _Vortex_suiClient, _Vortex_newPoolEventType, _Vortex_newAccountEventType, _Vortex_newCommitmentEventType, _Vortex_nullifierSpentEventType, _Vortex_newEncryptionKeyEventType, _Vortex_getVortexPool;
39357
+ var _Vortex_suiClient, _Vortex_newPoolEventType, _Vortex_newAccountEventType, _Vortex_newCommitmentEventType, _Vortex_nullifierSpentEventType, _Vortex_newEncryptionKeyEventType;
39331
39358
  class Vortex {
39332
39359
  constructor({ registry, packageId, swapPackageId, fullNodeUrl = getFullnodeUrl('devnet'), }) {
39333
- _Vortex_instances.add(this);
39334
39360
  _Vortex_suiClient.set(this, void 0);
39335
39361
  _Vortex_newPoolEventType.set(this, void 0);
39336
39362
  _Vortex_newAccountEventType.set(this, void 0);
@@ -39445,7 +39471,7 @@ class Vortex {
39445
39471
  const value = action === exports.Action.Deposit
39446
39472
  ? publicValue
39447
39473
  : BN254_FIELD_MODULUS - publicValue;
39448
- const vortex = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortexPool);
39474
+ const vortex = await this.resolveVortexPool(vortexPool);
39449
39475
  const proof = tx.moveCall({
39450
39476
  target: `${this.packageId}::vortex_proof::new`,
39451
39477
  arguments: [
@@ -39463,7 +39489,7 @@ class Vortex {
39463
39489
  return { tx, proof };
39464
39490
  }
39465
39491
  async transact({ tx = new Transaction(), vortexPool, proof, extData, deposit, }) {
39466
- const vortex = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortexPool);
39492
+ const vortex = await this.resolveVortexPool(vortexPool);
39467
39493
  const coin = tx.moveCall({
39468
39494
  target: `${this.packageId}::vortex::transact`,
39469
39495
  arguments: [tx.object(vortex.objectId), deposit, proof, extData],
@@ -39472,7 +39498,7 @@ class Vortex {
39472
39498
  return { tx, coin };
39473
39499
  }
39474
39500
  async transactWithAccount({ tx = new Transaction(), vortexPool, account, coins, proof, extData, }) {
39475
- const vortex = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortexPool);
39501
+ const vortex = await this.resolveVortexPool(vortexPool);
39476
39502
  const coin = tx.moveCall({
39477
39503
  target: `${this.packageId}::vortex::transact_with_account`,
39478
39504
  arguments: [
@@ -39518,7 +39544,7 @@ class Vortex {
39518
39544
  }
39519
39545
  async nextIndex(vortexPool) {
39520
39546
  const tx = new Transaction();
39521
- const vortex = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortexPool);
39547
+ const vortex = await this.resolveVortexPool(vortexPool);
39522
39548
  tx.moveCall({
39523
39549
  target: `${this.packageId}::vortex::next_index`,
39524
39550
  arguments: [tx.object(vortex.objectId)],
@@ -39531,7 +39557,7 @@ class Vortex {
39531
39557
  return BigInt(result[0][0]);
39532
39558
  }
39533
39559
  async isNullifierSpent({ nullifier, vortexPool }) {
39534
- const vortex = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortexPool);
39560
+ const vortex = await this.resolveVortexPool(vortexPool);
39535
39561
  const tx = new Transaction();
39536
39562
  tx.moveCall({
39537
39563
  target: `${this.packageId}::vortex::is_nullifier_spent`,
@@ -39545,7 +39571,7 @@ class Vortex {
39545
39571
  return result[0][0];
39546
39572
  }
39547
39573
  async areNullifiersSpent({ nullifiers, vortexPool }) {
39548
- const vortex = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortexPool);
39574
+ const vortex = await this.resolveVortexPool(vortexPool);
39549
39575
  if (nullifiers.length === 0)
39550
39576
  return [];
39551
39577
  const tx = new Transaction();
@@ -39561,7 +39587,7 @@ class Vortex {
39561
39587
  return result.flat();
39562
39588
  }
39563
39589
  async startSwap({ tx = new Transaction(), vortex, proof, extData, relayer, minAmountOut, coinOutType, }) {
39564
- const vortexPool = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortex);
39590
+ const vortexPool = await this.resolveVortexPool(vortex);
39565
39591
  const [receipt, coinIn] = tx.moveCall({
39566
39592
  target: `${this.swapPackageId}::vortex_swap::start_swap`,
39567
39593
  arguments: [
@@ -39576,7 +39602,7 @@ class Vortex {
39576
39602
  return { tx, receipt, coinIn };
39577
39603
  }
39578
39604
  async finishSwap({ tx = new Transaction(), vortex, coinOut, proof, extData, receipt, coinInType, }) {
39579
- const vortexPool = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortex);
39605
+ const vortexPool = await this.resolveVortexPool(vortex);
39580
39606
  tx.moveCall({
39581
39607
  target: `${this.swapPackageId}::vortex_swap::finish_swap`,
39582
39608
  arguments: [
@@ -39629,10 +39655,11 @@ class Vortex {
39629
39655
  mutable: true,
39630
39656
  });
39631
39657
  }
39658
+ async resolveVortexPool(vortex) {
39659
+ return typeof vortex === 'string' ? this.getVortexPool(vortex) : vortex;
39660
+ }
39632
39661
  }
39633
- _Vortex_suiClient = new WeakMap(), _Vortex_newPoolEventType = new WeakMap(), _Vortex_newAccountEventType = new WeakMap(), _Vortex_newCommitmentEventType = new WeakMap(), _Vortex_nullifierSpentEventType = new WeakMap(), _Vortex_newEncryptionKeyEventType = new WeakMap(), _Vortex_instances = new WeakSet(), _Vortex_getVortexPool = async function _Vortex_getVortexPool(vortex) {
39634
- return typeof vortex === 'string' ? this.getVortexPool(vortex) : vortex;
39635
- };
39662
+ _Vortex_suiClient = new WeakMap(), _Vortex_newPoolEventType = new WeakMap(), _Vortex_newAccountEventType = new WeakMap(), _Vortex_newCommitmentEventType = new WeakMap(), _Vortex_nullifierSpentEventType = new WeakMap(), _Vortex_newEncryptionKeyEventType = new WeakMap();
39636
39663
  const vortexSDK = new Vortex({
39637
39664
  packageId: VORTEX_PACKAGE_ID,
39638
39665
  registry: {
@@ -39643,6 +39670,117 @@ const vortexSDK = new Vortex({
39643
39670
  fullNodeUrl: getFullnodeUrl('testnet'),
39644
39671
  });
39645
39672
 
39673
+ const VORTEX_API_URL = 'https://api.vortexfi.xyz';
39674
+
39675
+ var _VortexAPI_instances, _VortexAPI_apiUrl, _VortexAPI_get, _VortexAPI_post, _VortexAPI_assertSuccess;
39676
+ class VortexAPI {
39677
+ constructor({ apiUrl = VORTEX_API_URL } = {}) {
39678
+ _VortexAPI_instances.add(this);
39679
+ _VortexAPI_apiUrl.set(this, void 0);
39680
+ __classPrivateFieldSet(this, _VortexAPI_apiUrl, apiUrl.replace(/\/$/, ''), "f");
39681
+ }
39682
+ async health() {
39683
+ const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, '/api/health');
39684
+ __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
39685
+ return response;
39686
+ }
39687
+ async getAccounts(hashedSecret) {
39688
+ const params = new URLSearchParams({ hashed_secret: hashedSecret });
39689
+ const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, `/api/v1/accounts?${params.toString()}`);
39690
+ __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
39691
+ return response;
39692
+ }
39693
+ async createAccount(args) {
39694
+ const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_post).call(this, '/api/v1/accounts', {
39695
+ owner: args.owner,
39696
+ hashedSecret: args.hashedSecret,
39697
+ });
39698
+ __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
39699
+ return response;
39700
+ }
39701
+ async getPools(args = {}) {
39702
+ const params = new URLSearchParams();
39703
+ if (args.page !== undefined) {
39704
+ params.set('page', args.page.toString());
39705
+ }
39706
+ if (args.limit !== undefined) {
39707
+ params.set('limit', args.limit.toString());
39708
+ }
39709
+ if (args.coinType !== undefined) {
39710
+ params.set('coin_type', args.coinType);
39711
+ }
39712
+ const query = params.toString();
39713
+ const path = query ? `/api/v1/pools?${query}` : '/api/v1/pools';
39714
+ const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, path);
39715
+ __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
39716
+ return response;
39717
+ }
39718
+ async getCommitments(args) {
39719
+ const params = new URLSearchParams({
39720
+ coin_type: args.coinType,
39721
+ index: args.index.toString(),
39722
+ });
39723
+ if (args.op !== undefined) {
39724
+ params.set('op', args.op);
39725
+ }
39726
+ if (args.page !== undefined) {
39727
+ params.set('page', args.page.toString());
39728
+ }
39729
+ if (args.limit !== undefined) {
39730
+ params.set('limit', args.limit.toString());
39731
+ }
39732
+ const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, `/api/v1/commitments?${params.toString()}`);
39733
+ __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
39734
+ return response;
39735
+ }
39736
+ async getMerklePath(args) {
39737
+ const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_post).call(this, '/api/v1/merkle/path', {
39738
+ coin_type: args.coinType,
39739
+ index: args.index,
39740
+ amount: args.amount,
39741
+ public_key: args.publicKey,
39742
+ blinding: args.blinding,
39743
+ vortex_pool: args.vortexPool,
39744
+ });
39745
+ __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
39746
+ return response;
39747
+ }
39748
+ async executeTransaction(args) {
39749
+ const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_post).call(this, '/api/v1/transactions', {
39750
+ txBytes: args.txBytes,
39751
+ }, args.apiKey);
39752
+ __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
39753
+ return response;
39754
+ }
39755
+ async getRelayer() {
39756
+ const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, '/api/v1/relayer');
39757
+ __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
39758
+ return response;
39759
+ }
39760
+ }
39761
+ _VortexAPI_apiUrl = new WeakMap(), _VortexAPI_instances = new WeakSet(), _VortexAPI_get = async function _VortexAPI_get(path) {
39762
+ const response = await fetch(`${__classPrivateFieldGet(this, _VortexAPI_apiUrl, "f")}${path}`, {
39763
+ method: 'GET',
39764
+ headers: {
39765
+ 'Content-Type': 'application/json',
39766
+ },
39767
+ });
39768
+ return response.json();
39769
+ }, _VortexAPI_post = async function _VortexAPI_post(path, body, apiKey) {
39770
+ const response = await fetch(`${__classPrivateFieldGet(this, _VortexAPI_apiUrl, "f")}${path}`, {
39771
+ method: 'POST',
39772
+ headers: {
39773
+ 'Content-Type': 'application/json',
39774
+ 'x-api-key': apiKey ?? '',
39775
+ },
39776
+ body: JSON.stringify(body),
39777
+ });
39778
+ return response.json();
39779
+ }, _VortexAPI_assertSuccess = function _VortexAPI_assertSuccess(response) {
39780
+ invariant(response.success === true, `VortexAPI request failed: ${response.error}`);
39781
+ };
39782
+ const vortexAPI = new VortexAPI();
39783
+
39646
39784
  // packages/vortex/src/entities/merkle-tree.ts
39647
39785
  const merkleTreeHashFunction = (left, right) => poseidon2(BigInt(left), BigInt(right)).toString();
39648
39786
  const buildMerkleTree = (elements = []) => new fixedMerkleTree.MerkleTree(MERKLE_TREE_HEIGHT, elements, {
@@ -39651,7 +39789,7 @@ const buildMerkleTree = (elements = []) => new fixedMerkleTree.MerkleTree(MERKLE
39651
39789
  });
39652
39790
  const deserializeMerkleTree = (data) => fixedMerkleTree.MerkleTree.deserialize(data, merkleTreeHashFunction);
39653
39791
 
39654
- const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer, relayerFee, }) => {
39792
+ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer, relayerFee, }) => {
39655
39793
  const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
39656
39794
  // Deposits we do not need a recipient, so we use a random one.
39657
39795
  const randomVortexKeypair = VortexKeypair.generate();
@@ -39698,13 +39836,14 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39698
39836
  const encryptedUtxo0 = VortexKeypair.encryptUtxoFor(outputUtxo0.payload(), vortexKeypair.encryptionKey);
39699
39837
  // UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
39700
39838
  const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
39839
+ const root = BigInt(merklePath0.root);
39701
39840
  // Prepare circuit input
39702
39841
  const input = toProveInput({
39703
39842
  vortexObjectId,
39704
39843
  accountSecret,
39705
39844
  root,
39706
- merklePath0,
39707
- merklePath1,
39845
+ merklePath0: merklePath0.path,
39846
+ merklePath1: merklePath1.path,
39708
39847
  publicAmount: amount - relayerFee,
39709
39848
  nullifier0,
39710
39849
  nullifier1,
@@ -39751,7 +39890,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39751
39890
  };
39752
39891
  };
39753
39892
 
39754
- const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39893
+ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39755
39894
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
39756
39895
  invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
39757
39896
  const accountSecret = 0n;
@@ -39763,7 +39902,6 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39763
39902
  vortexSdk,
39764
39903
  vortexKeypair,
39765
39904
  vortexPool,
39766
- root,
39767
39905
  getMerklePathFn,
39768
39906
  relayer,
39769
39907
  relayerFee,
@@ -39778,7 +39916,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39778
39916
  });
39779
39917
  };
39780
39918
 
39781
- const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39919
+ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39782
39920
  invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
39783
39921
  unspentUtxos.sort((a, b) => new bn_js.BN(b.amount).cmp(new bn_js.BN(a.amount)));
39784
39922
  const totalUnspentUtxosAmount = unspentUtxos
@@ -39825,13 +39963,14 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39825
39963
  : vortexKeypair.encryptionKey);
39826
39964
  // UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
39827
39965
  const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
39966
+ const root = BigInt(merklePath0.root);
39828
39967
  // Prepare circuit input
39829
39968
  const input = toProveInput({
39830
39969
  vortexObjectId,
39831
39970
  accountSecret,
39832
39971
  root,
39833
- merklePath0,
39834
- merklePath1,
39972
+ merklePath0: merklePath0.path,
39973
+ merklePath1: merklePath1.path,
39835
39974
  publicAmount: BN254_FIELD_MODULUS - amount,
39836
39975
  nullifier0,
39837
39976
  nullifier1,
@@ -39875,31 +40014,34 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39875
40014
  };
39876
40015
  };
39877
40016
 
39878
- const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, }) => {
39879
- const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
40017
+ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, }) => {
40018
+ const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39880
40019
  tx,
39881
40020
  amount,
39882
40021
  unspentUtxos,
39883
40022
  vortexPool,
39884
40023
  vortexKeypair,
39885
- root,
39886
40024
  getMerklePathFn,
39887
40025
  relayer,
39888
40026
  relayerFee,
39889
40027
  vortexSdk,
39890
40028
  accountSecret: 0n,
39891
40029
  });
39892
- const zeroSuiCoin = tx3.splitCoins(tx3.gas, [tx3.pure.u64(0n)]);
40030
+ const vortexPoolObject = await vortexSdk.resolveVortexPool(pool);
40031
+ const zeroCoin = tx2.moveCall({
40032
+ target: `${SUI_FRAMEWORK_ADDRESS}::coin::zero`,
40033
+ typeArguments: [vortexPoolObject.coinType],
40034
+ });
39893
40035
  return vortexSdk.transact({
39894
40036
  vortexPool: pool,
39895
- tx: tx3,
40037
+ tx: tx2,
39896
40038
  proof: moveProof,
39897
40039
  extData: extData,
39898
- deposit: zeroSuiCoin,
40040
+ deposit: zeroCoin,
39899
40041
  });
39900
40042
  };
39901
40043
 
39902
- const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
40044
+ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39903
40045
  const coins = coinStructs.map((coin) => ({
39904
40046
  objectId: coin.coinObjectId,
39905
40047
  version: coin.version,
@@ -39916,7 +40058,6 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39916
40058
  vortexSdk,
39917
40059
  vortexKeypair,
39918
40060
  vortexPool,
39919
- root,
39920
40061
  getMerklePathFn,
39921
40062
  relayer,
39922
40063
  relayerFee,
@@ -39931,14 +40072,13 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39931
40072
  });
39932
40073
  };
39933
40074
 
39934
- const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
40075
+ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
39935
40076
  const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39936
40077
  tx,
39937
40078
  amount,
39938
40079
  unspentUtxos,
39939
40080
  vortexPool,
39940
40081
  vortexKeypair,
39941
- root,
39942
40082
  getMerklePathFn,
39943
40083
  relayer,
39944
40084
  relayerFee,
@@ -39955,14 +40095,13 @@ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [],
39955
40095
  });
39956
40096
  };
39957
40097
 
39958
- const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair, root, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }) => {
40098
+ const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }) => {
39959
40099
  const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39960
40100
  tx,
39961
40101
  amount,
39962
40102
  vortexPool,
39963
40103
  unspentUtxos,
39964
40104
  vortexKeypair,
39965
- root,
39966
40105
  getMerklePathFn,
39967
40106
  relayer,
39968
40107
  relayerFee: 0n,
@@ -39979,7 +40118,7 @@ const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUt
39979
40118
  coinOutType,
39980
40119
  });
39981
40120
  };
39982
- const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair, root, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }) => {
40121
+ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }) => {
39983
40122
  const accountSecret = 0n;
39984
40123
  const { extData, tx: tx3, moveProof, } = await prepareDepositProof({
39985
40124
  tx,
@@ -39989,7 +40128,6 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
39989
40128
  vortexSdk,
39990
40129
  vortexKeypair,
39991
40130
  vortexPool,
39992
- root,
39993
40131
  getMerklePathFn,
39994
40132
  relayer: normalizeSuiAddress('0x0'),
39995
40133
  relayerFee: 0n,
@@ -40020,6 +40158,7 @@ exports.REGISTRY_OBJECT_ID = REGISTRY_OBJECT_ID;
40020
40158
  exports.ROOT_HISTORY_SIZE = ROOT_HISTORY_SIZE;
40021
40159
  exports.TREASURY_ADDRESS = TREASURY_ADDRESS;
40022
40160
  exports.Utxo = Utxo;
40161
+ exports.VORTEX_API_URL = VORTEX_API_URL;
40023
40162
  exports.VORTEX_PACKAGE_ID = VORTEX_PACKAGE_ID;
40024
40163
  exports.VORTEX_POOL_IDS = VORTEX_POOL_IDS;
40025
40164
  exports.VORTEX_SIGNATURE_DOMAIN = VORTEX_SIGNATURE_DOMAIN;
@@ -40027,6 +40166,7 @@ exports.VORTEX_SWAP_PACKAGE_ID = VORTEX_SWAP_PACKAGE_ID;
40027
40166
  exports.VORTEX_SWAP_UPGRADE_CAP = VORTEX_SWAP_UPGRADE_CAP;
40028
40167
  exports.VORTEX_UPGRADE_CAP = VORTEX_UPGRADE_CAP;
40029
40168
  exports.Vortex = Vortex;
40169
+ exports.VortexAPI = VortexAPI;
40030
40170
  exports.VortexKeypair = VortexKeypair;
40031
40171
  exports.ZERO_VALUE = ZERO_VALUE;
40032
40172
  exports.buildMerkleTree = buildMerkleTree;
@@ -40036,6 +40176,7 @@ exports.deserializeMerkleTree = deserializeMerkleTree;
40036
40176
  exports.finishSwap = finishSwap;
40037
40177
  exports.getMerklePath = getMerklePath;
40038
40178
  exports.getUnspentUtxos = getUnspentUtxos;
40179
+ exports.getUnspentUtxosWithApi = getUnspentUtxosWithApi;
40039
40180
  exports.merkleTreeHashFunction = merkleTreeHashFunction;
40040
40181
  exports.parseNewCommitmentEvent = parseNewCommitmentEvent;
40041
40182
  exports.parseVortexPool = parseVortexPool;
@@ -40047,6 +40188,7 @@ exports.prove = prove;
40047
40188
  exports.startSwap = startSwap;
40048
40189
  exports.toProveInput = toProveInput;
40049
40190
  exports.verify = verify;
40191
+ exports.vortexAPI = vortexAPI;
40050
40192
  exports.vortexSDK = vortexSDK;
40051
40193
  exports.withdraw = withdraw;
40052
40194
  exports.withdrawWithAccount = withdrawWithAccount;