@interest-protocol/vortex-sdk 6.3.0 → 7.0.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 +176 -35
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +173 -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 +114 -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 +1 -1
  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 +189 -0
  40. package/src/vortex-api.types.ts +137 -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,116 @@ 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
+ });
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) {
39770
+ const response = await fetch(`${__classPrivateFieldGet(this, _VortexAPI_apiUrl, "f")}${path}`, {
39771
+ method: 'POST',
39772
+ headers: {
39773
+ 'Content-Type': 'application/json',
39774
+ },
39775
+ body: JSON.stringify(body),
39776
+ });
39777
+ return response.json();
39778
+ }, _VortexAPI_assertSuccess = function _VortexAPI_assertSuccess(response) {
39779
+ invariant(response.success === true, `VortexAPI request failed: ${response.error}`);
39780
+ };
39781
+ const vortexAPI = new VortexAPI();
39782
+
39646
39783
  // packages/vortex/src/entities/merkle-tree.ts
39647
39784
  const merkleTreeHashFunction = (left, right) => poseidon2(BigInt(left), BigInt(right)).toString();
39648
39785
  const buildMerkleTree = (elements = []) => new fixedMerkleTree.MerkleTree(MERKLE_TREE_HEIGHT, elements, {
@@ -39651,7 +39788,7 @@ const buildMerkleTree = (elements = []) => new fixedMerkleTree.MerkleTree(MERKLE
39651
39788
  });
39652
39789
  const deserializeMerkleTree = (data) => fixedMerkleTree.MerkleTree.deserialize(data, merkleTreeHashFunction);
39653
39790
 
39654
- const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer, relayerFee, }) => {
39791
+ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer, relayerFee, }) => {
39655
39792
  const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
39656
39793
  // Deposits we do not need a recipient, so we use a random one.
39657
39794
  const randomVortexKeypair = VortexKeypair.generate();
@@ -39698,13 +39835,14 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39698
39835
  const encryptedUtxo0 = VortexKeypair.encryptUtxoFor(outputUtxo0.payload(), vortexKeypair.encryptionKey);
39699
39836
  // UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
39700
39837
  const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
39838
+ const root = BigInt(merklePath0.root);
39701
39839
  // Prepare circuit input
39702
39840
  const input = toProveInput({
39703
39841
  vortexObjectId,
39704
39842
  accountSecret,
39705
39843
  root,
39706
- merklePath0,
39707
- merklePath1,
39844
+ merklePath0: merklePath0.path,
39845
+ merklePath1: merklePath1.path,
39708
39846
  publicAmount: amount - relayerFee,
39709
39847
  nullifier0,
39710
39848
  nullifier1,
@@ -39751,7 +39889,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
39751
39889
  };
39752
39890
  };
39753
39891
 
39754
- const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39892
+ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39755
39893
  invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
39756
39894
  invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
39757
39895
  const accountSecret = 0n;
@@ -39763,7 +39901,6 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39763
39901
  vortexSdk,
39764
39902
  vortexKeypair,
39765
39903
  vortexPool,
39766
- root,
39767
39904
  getMerklePathFn,
39768
39905
  relayer,
39769
39906
  relayerFee,
@@ -39778,7 +39915,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
39778
39915
  });
39779
39916
  };
39780
39917
 
39781
- const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39918
+ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }) => {
39782
39919
  invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
39783
39920
  unspentUtxos.sort((a, b) => new bn_js.BN(b.amount).cmp(new bn_js.BN(a.amount)));
39784
39921
  const totalUnspentUtxosAmount = unspentUtxos
@@ -39825,13 +39962,14 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39825
39962
  : vortexKeypair.encryptionKey);
39826
39963
  // UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
39827
39964
  const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
39965
+ const root = BigInt(merklePath0.root);
39828
39966
  // Prepare circuit input
39829
39967
  const input = toProveInput({
39830
39968
  vortexObjectId,
39831
39969
  accountSecret,
39832
39970
  root,
39833
- merklePath0,
39834
- merklePath1,
39971
+ merklePath0: merklePath0.path,
39972
+ merklePath1: merklePath1.path,
39835
39973
  publicAmount: BN254_FIELD_MODULUS - amount,
39836
39974
  nullifier0,
39837
39975
  nullifier1,
@@ -39875,31 +40013,34 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
39875
40013
  };
39876
40014
  };
39877
40015
 
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({
40016
+ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, }) => {
40017
+ const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39880
40018
  tx,
39881
40019
  amount,
39882
40020
  unspentUtxos,
39883
40021
  vortexPool,
39884
40022
  vortexKeypair,
39885
- root,
39886
40023
  getMerklePathFn,
39887
40024
  relayer,
39888
40025
  relayerFee,
39889
40026
  vortexSdk,
39890
40027
  accountSecret: 0n,
39891
40028
  });
39892
- const zeroSuiCoin = tx3.splitCoins(tx3.gas, [tx3.pure.u64(0n)]);
40029
+ const vortexPoolObject = await vortexSdk.resolveVortexPool(pool);
40030
+ const zeroCoin = tx2.moveCall({
40031
+ target: `${SUI_FRAMEWORK_ADDRESS}::coin::zero`,
40032
+ typeArguments: [vortexPoolObject.coinType],
40033
+ });
39893
40034
  return vortexSdk.transact({
39894
40035
  vortexPool: pool,
39895
- tx: tx3,
40036
+ tx: tx2,
39896
40037
  proof: moveProof,
39897
40038
  extData: extData,
39898
- deposit: zeroSuiCoin,
40039
+ deposit: zeroCoin,
39899
40040
  });
39900
40041
  };
39901
40042
 
39902
- const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
40043
+ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
39903
40044
  const coins = coinStructs.map((coin) => ({
39904
40045
  objectId: coin.coinObjectId,
39905
40046
  version: coin.version,
@@ -39916,7 +40057,6 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39916
40057
  vortexSdk,
39917
40058
  vortexKeypair,
39918
40059
  vortexPool,
39919
- root,
39920
40060
  getMerklePathFn,
39921
40061
  relayer,
39922
40062
  relayerFee,
@@ -39931,14 +40071,13 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
39931
40071
  });
39932
40072
  };
39933
40073
 
39934
- const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
40074
+ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
39935
40075
  const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39936
40076
  tx,
39937
40077
  amount,
39938
40078
  unspentUtxos,
39939
40079
  vortexPool,
39940
40080
  vortexKeypair,
39941
- root,
39942
40081
  getMerklePathFn,
39943
40082
  relayer,
39944
40083
  relayerFee,
@@ -39955,14 +40094,13 @@ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [],
39955
40094
  });
39956
40095
  };
39957
40096
 
39958
- const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair, root, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }) => {
40097
+ const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }) => {
39959
40098
  const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
39960
40099
  tx,
39961
40100
  amount,
39962
40101
  vortexPool,
39963
40102
  unspentUtxos,
39964
40103
  vortexKeypair,
39965
- root,
39966
40104
  getMerklePathFn,
39967
40105
  relayer,
39968
40106
  relayerFee: 0n,
@@ -39979,7 +40117,7 @@ const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUt
39979
40117
  coinOutType,
39980
40118
  });
39981
40119
  };
39982
- const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair, root, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }) => {
40120
+ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }) => {
39983
40121
  const accountSecret = 0n;
39984
40122
  const { extData, tx: tx3, moveProof, } = await prepareDepositProof({
39985
40123
  tx,
@@ -39989,7 +40127,6 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
39989
40127
  vortexSdk,
39990
40128
  vortexKeypair,
39991
40129
  vortexPool,
39992
- root,
39993
40130
  getMerklePathFn,
39994
40131
  relayer: normalizeSuiAddress('0x0'),
39995
40132
  relayerFee: 0n,
@@ -40020,6 +40157,7 @@ exports.REGISTRY_OBJECT_ID = REGISTRY_OBJECT_ID;
40020
40157
  exports.ROOT_HISTORY_SIZE = ROOT_HISTORY_SIZE;
40021
40158
  exports.TREASURY_ADDRESS = TREASURY_ADDRESS;
40022
40159
  exports.Utxo = Utxo;
40160
+ exports.VORTEX_API_URL = VORTEX_API_URL;
40023
40161
  exports.VORTEX_PACKAGE_ID = VORTEX_PACKAGE_ID;
40024
40162
  exports.VORTEX_POOL_IDS = VORTEX_POOL_IDS;
40025
40163
  exports.VORTEX_SIGNATURE_DOMAIN = VORTEX_SIGNATURE_DOMAIN;
@@ -40027,6 +40165,7 @@ exports.VORTEX_SWAP_PACKAGE_ID = VORTEX_SWAP_PACKAGE_ID;
40027
40165
  exports.VORTEX_SWAP_UPGRADE_CAP = VORTEX_SWAP_UPGRADE_CAP;
40028
40166
  exports.VORTEX_UPGRADE_CAP = VORTEX_UPGRADE_CAP;
40029
40167
  exports.Vortex = Vortex;
40168
+ exports.VortexAPI = VortexAPI;
40030
40169
  exports.VortexKeypair = VortexKeypair;
40031
40170
  exports.ZERO_VALUE = ZERO_VALUE;
40032
40171
  exports.buildMerkleTree = buildMerkleTree;
@@ -40036,6 +40175,7 @@ exports.deserializeMerkleTree = deserializeMerkleTree;
40036
40175
  exports.finishSwap = finishSwap;
40037
40176
  exports.getMerklePath = getMerklePath;
40038
40177
  exports.getUnspentUtxos = getUnspentUtxos;
40178
+ exports.getUnspentUtxosWithApi = getUnspentUtxosWithApi;
40039
40179
  exports.merkleTreeHashFunction = merkleTreeHashFunction;
40040
40180
  exports.parseNewCommitmentEvent = parseNewCommitmentEvent;
40041
40181
  exports.parseVortexPool = parseVortexPool;
@@ -40047,6 +40187,7 @@ exports.prove = prove;
40047
40187
  exports.startSwap = startSwap;
40048
40188
  exports.toProveInput = toProveInput;
40049
40189
  exports.verify = verify;
40190
+ exports.vortexAPI = vortexAPI;
40050
40191
  exports.vortexSDK = vortexSDK;
40051
40192
  exports.withdraw = withdraw;
40052
40193
  exports.withdrawWithAccount = withdrawWithAccount;