@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.
- package/dist/deposit-with-account.d.ts +1 -1
- package/dist/deposit-with-account.d.ts.map +1 -1
- package/dist/deposit.d.ts +1 -1
- package/dist/deposit.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +176 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +173 -36
- package/dist/index.mjs.map +1 -1
- package/dist/swap.d.ts +2 -2
- package/dist/swap.d.ts.map +1 -1
- package/dist/utils/decrypt.d.ts +8 -0
- package/dist/utils/decrypt.d.ts.map +1 -1
- package/dist/utils/deposit.d.ts +1 -2
- package/dist/utils/deposit.d.ts.map +1 -1
- package/dist/utils/withdraw.d.ts +1 -2
- package/dist/utils/withdraw.d.ts.map +1 -1
- package/dist/vortex-api.d.ts +15 -0
- package/dist/vortex-api.d.ts.map +1 -0
- package/dist/vortex-api.types.d.ts +114 -0
- package/dist/vortex-api.types.d.ts.map +1 -0
- package/dist/vortex.d.ts +1 -0
- package/dist/vortex.d.ts.map +1 -1
- package/dist/vortex.types.d.ts +4 -7
- package/dist/vortex.types.d.ts.map +1 -1
- package/dist/withdraw-with-account.d.ts +1 -1
- package/dist/withdraw-with-account.d.ts.map +1 -1
- package/dist/withdraw.d.ts +1 -1
- package/dist/withdraw.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/deposit-with-account.ts +0 -2
- package/src/deposit.ts +0 -2
- package/src/index.ts +2 -0
- package/src/swap.ts +0 -4
- package/src/utils/decrypt.ts +57 -1
- package/src/utils/deposit.ts +5 -6
- package/src/utils/withdraw.ts +4 -4
- package/src/vortex-api.ts +189 -0
- package/src/vortex-api.types.ts +137 -0
- package/src/vortex.ts +9 -9
- package/src/vortex.types.ts +3 -7
- package/src/withdraw-with-account.ts +0 -2
- package/src/withdraw.ts +10 -6
package/dist/index.mjs
CHANGED
|
@@ -39234,6 +39234,33 @@ const getUnspentUtxos = async ({ commitmentEvents, vortexKeypair, vortexSdk, vor
|
|
|
39234
39234
|
const unspentUtxos = utxos.filter((_, index) => !isNullifierSpentArray[index]);
|
|
39235
39235
|
return unspentUtxos;
|
|
39236
39236
|
};
|
|
39237
|
+
const getUnspentUtxosWithApi = async ({ commitments, vortexKeypair, vortexSdk, vortexPool, }) => {
|
|
39238
|
+
const allUtxos = [];
|
|
39239
|
+
const vortexObject = await vortexSdk.resolveVortexPool(vortexPool);
|
|
39240
|
+
commitments.forEach((commitment) => {
|
|
39241
|
+
invariant(normalizeStructTag(commitment.coinType) ===
|
|
39242
|
+
normalizeStructTag(vortexObject.coinType), 'Commitment coin type does not match vortex pool coin type');
|
|
39243
|
+
try {
|
|
39244
|
+
const utxo = vortexKeypair.decryptUtxo(commitment.encryptedOutput);
|
|
39245
|
+
allUtxos.push(utxo);
|
|
39246
|
+
}
|
|
39247
|
+
catch {
|
|
39248
|
+
// Do nothing
|
|
39249
|
+
}
|
|
39250
|
+
});
|
|
39251
|
+
const utxos = allUtxos.map((utxo) => new Utxo({
|
|
39252
|
+
...utxo,
|
|
39253
|
+
keypair: vortexKeypair,
|
|
39254
|
+
vortexPool: vortexObject.objectId,
|
|
39255
|
+
}));
|
|
39256
|
+
const nullifiers = utxos.map((utxo) => utxo.nullifier());
|
|
39257
|
+
const isNullifierSpentArray = await vortexSdk.areNullifiersSpent({
|
|
39258
|
+
nullifiers,
|
|
39259
|
+
vortexPool,
|
|
39260
|
+
});
|
|
39261
|
+
const unspentUtxos = utxos.filter((_, index) => !isNullifierSpentArray[index]);
|
|
39262
|
+
return unspentUtxos;
|
|
39263
|
+
};
|
|
39237
39264
|
|
|
39238
39265
|
function getMerklePath(merkleTree, utxo) {
|
|
39239
39266
|
// Handle zero-amount UTXOs
|
|
@@ -39325,10 +39352,9 @@ const parseVortexPool = (data) => {
|
|
|
39325
39352
|
};
|
|
39326
39353
|
};
|
|
39327
39354
|
|
|
39328
|
-
var
|
|
39355
|
+
var _Vortex_suiClient, _Vortex_newPoolEventType, _Vortex_newAccountEventType, _Vortex_newCommitmentEventType, _Vortex_nullifierSpentEventType, _Vortex_newEncryptionKeyEventType;
|
|
39329
39356
|
class Vortex {
|
|
39330
39357
|
constructor({ registry, packageId, swapPackageId, fullNodeUrl = getFullnodeUrl('devnet'), }) {
|
|
39331
|
-
_Vortex_instances.add(this);
|
|
39332
39358
|
_Vortex_suiClient.set(this, void 0);
|
|
39333
39359
|
_Vortex_newPoolEventType.set(this, void 0);
|
|
39334
39360
|
_Vortex_newAccountEventType.set(this, void 0);
|
|
@@ -39443,7 +39469,7 @@ class Vortex {
|
|
|
39443
39469
|
const value = action === Action.Deposit
|
|
39444
39470
|
? publicValue
|
|
39445
39471
|
: BN254_FIELD_MODULUS - publicValue;
|
|
39446
|
-
const vortex = await
|
|
39472
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39447
39473
|
const proof = tx.moveCall({
|
|
39448
39474
|
target: `${this.packageId}::vortex_proof::new`,
|
|
39449
39475
|
arguments: [
|
|
@@ -39461,7 +39487,7 @@ class Vortex {
|
|
|
39461
39487
|
return { tx, proof };
|
|
39462
39488
|
}
|
|
39463
39489
|
async transact({ tx = new Transaction(), vortexPool, proof, extData, deposit, }) {
|
|
39464
|
-
const vortex = await
|
|
39490
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39465
39491
|
const coin = tx.moveCall({
|
|
39466
39492
|
target: `${this.packageId}::vortex::transact`,
|
|
39467
39493
|
arguments: [tx.object(vortex.objectId), deposit, proof, extData],
|
|
@@ -39470,7 +39496,7 @@ class Vortex {
|
|
|
39470
39496
|
return { tx, coin };
|
|
39471
39497
|
}
|
|
39472
39498
|
async transactWithAccount({ tx = new Transaction(), vortexPool, account, coins, proof, extData, }) {
|
|
39473
|
-
const vortex = await
|
|
39499
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39474
39500
|
const coin = tx.moveCall({
|
|
39475
39501
|
target: `${this.packageId}::vortex::transact_with_account`,
|
|
39476
39502
|
arguments: [
|
|
@@ -39516,7 +39542,7 @@ class Vortex {
|
|
|
39516
39542
|
}
|
|
39517
39543
|
async nextIndex(vortexPool) {
|
|
39518
39544
|
const tx = new Transaction();
|
|
39519
|
-
const vortex = await
|
|
39545
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39520
39546
|
tx.moveCall({
|
|
39521
39547
|
target: `${this.packageId}::vortex::next_index`,
|
|
39522
39548
|
arguments: [tx.object(vortex.objectId)],
|
|
@@ -39529,7 +39555,7 @@ class Vortex {
|
|
|
39529
39555
|
return BigInt(result[0][0]);
|
|
39530
39556
|
}
|
|
39531
39557
|
async isNullifierSpent({ nullifier, vortexPool }) {
|
|
39532
|
-
const vortex = await
|
|
39558
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39533
39559
|
const tx = new Transaction();
|
|
39534
39560
|
tx.moveCall({
|
|
39535
39561
|
target: `${this.packageId}::vortex::is_nullifier_spent`,
|
|
@@ -39543,7 +39569,7 @@ class Vortex {
|
|
|
39543
39569
|
return result[0][0];
|
|
39544
39570
|
}
|
|
39545
39571
|
async areNullifiersSpent({ nullifiers, vortexPool }) {
|
|
39546
|
-
const vortex = await
|
|
39572
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39547
39573
|
if (nullifiers.length === 0)
|
|
39548
39574
|
return [];
|
|
39549
39575
|
const tx = new Transaction();
|
|
@@ -39559,7 +39585,7 @@ class Vortex {
|
|
|
39559
39585
|
return result.flat();
|
|
39560
39586
|
}
|
|
39561
39587
|
async startSwap({ tx = new Transaction(), vortex, proof, extData, relayer, minAmountOut, coinOutType, }) {
|
|
39562
|
-
const vortexPool = await
|
|
39588
|
+
const vortexPool = await this.resolveVortexPool(vortex);
|
|
39563
39589
|
const [receipt, coinIn] = tx.moveCall({
|
|
39564
39590
|
target: `${this.swapPackageId}::vortex_swap::start_swap`,
|
|
39565
39591
|
arguments: [
|
|
@@ -39574,7 +39600,7 @@ class Vortex {
|
|
|
39574
39600
|
return { tx, receipt, coinIn };
|
|
39575
39601
|
}
|
|
39576
39602
|
async finishSwap({ tx = new Transaction(), vortex, coinOut, proof, extData, receipt, coinInType, }) {
|
|
39577
|
-
const vortexPool = await
|
|
39603
|
+
const vortexPool = await this.resolveVortexPool(vortex);
|
|
39578
39604
|
tx.moveCall({
|
|
39579
39605
|
target: `${this.swapPackageId}::vortex_swap::finish_swap`,
|
|
39580
39606
|
arguments: [
|
|
@@ -39627,10 +39653,11 @@ class Vortex {
|
|
|
39627
39653
|
mutable: true,
|
|
39628
39654
|
});
|
|
39629
39655
|
}
|
|
39656
|
+
async resolveVortexPool(vortex) {
|
|
39657
|
+
return typeof vortex === 'string' ? this.getVortexPool(vortex) : vortex;
|
|
39658
|
+
}
|
|
39630
39659
|
}
|
|
39631
|
-
_Vortex_suiClient = new WeakMap(), _Vortex_newPoolEventType = new WeakMap(), _Vortex_newAccountEventType = new WeakMap(), _Vortex_newCommitmentEventType = new WeakMap(), _Vortex_nullifierSpentEventType = new WeakMap(), _Vortex_newEncryptionKeyEventType = new WeakMap()
|
|
39632
|
-
return typeof vortex === 'string' ? this.getVortexPool(vortex) : vortex;
|
|
39633
|
-
};
|
|
39660
|
+
_Vortex_suiClient = new WeakMap(), _Vortex_newPoolEventType = new WeakMap(), _Vortex_newAccountEventType = new WeakMap(), _Vortex_newCommitmentEventType = new WeakMap(), _Vortex_nullifierSpentEventType = new WeakMap(), _Vortex_newEncryptionKeyEventType = new WeakMap();
|
|
39634
39661
|
const vortexSDK = new Vortex({
|
|
39635
39662
|
packageId: VORTEX_PACKAGE_ID,
|
|
39636
39663
|
registry: {
|
|
@@ -39641,6 +39668,116 @@ const vortexSDK = new Vortex({
|
|
|
39641
39668
|
fullNodeUrl: getFullnodeUrl('testnet'),
|
|
39642
39669
|
});
|
|
39643
39670
|
|
|
39671
|
+
const VORTEX_API_URL = 'https://api.vortexfi.xyz';
|
|
39672
|
+
|
|
39673
|
+
var _VortexAPI_instances, _VortexAPI_apiUrl, _VortexAPI_get, _VortexAPI_post, _VortexAPI_assertSuccess;
|
|
39674
|
+
class VortexAPI {
|
|
39675
|
+
constructor({ apiUrl = VORTEX_API_URL } = {}) {
|
|
39676
|
+
_VortexAPI_instances.add(this);
|
|
39677
|
+
_VortexAPI_apiUrl.set(this, void 0);
|
|
39678
|
+
__classPrivateFieldSet(this, _VortexAPI_apiUrl, apiUrl.replace(/\/$/, ''), "f");
|
|
39679
|
+
}
|
|
39680
|
+
async health() {
|
|
39681
|
+
const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, '/api/health');
|
|
39682
|
+
__classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
|
|
39683
|
+
return response;
|
|
39684
|
+
}
|
|
39685
|
+
async getAccounts(hashedSecret) {
|
|
39686
|
+
const params = new URLSearchParams({ hashed_secret: hashedSecret });
|
|
39687
|
+
const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, `/api/v1/accounts?${params.toString()}`);
|
|
39688
|
+
__classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
|
|
39689
|
+
return response;
|
|
39690
|
+
}
|
|
39691
|
+
async createAccount(args) {
|
|
39692
|
+
const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_post).call(this, '/api/v1/accounts', {
|
|
39693
|
+
owner: args.owner,
|
|
39694
|
+
hashedSecret: args.hashedSecret,
|
|
39695
|
+
});
|
|
39696
|
+
__classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
|
|
39697
|
+
return response;
|
|
39698
|
+
}
|
|
39699
|
+
async getPools(args = {}) {
|
|
39700
|
+
const params = new URLSearchParams();
|
|
39701
|
+
if (args.page !== undefined) {
|
|
39702
|
+
params.set('page', args.page.toString());
|
|
39703
|
+
}
|
|
39704
|
+
if (args.limit !== undefined) {
|
|
39705
|
+
params.set('limit', args.limit.toString());
|
|
39706
|
+
}
|
|
39707
|
+
if (args.coinType !== undefined) {
|
|
39708
|
+
params.set('coin_type', args.coinType);
|
|
39709
|
+
}
|
|
39710
|
+
const query = params.toString();
|
|
39711
|
+
const path = query ? `/api/v1/pools?${query}` : '/api/v1/pools';
|
|
39712
|
+
const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, path);
|
|
39713
|
+
__classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
|
|
39714
|
+
return response;
|
|
39715
|
+
}
|
|
39716
|
+
async getCommitments(args) {
|
|
39717
|
+
const params = new URLSearchParams({
|
|
39718
|
+
coin_type: args.coinType,
|
|
39719
|
+
index: args.index.toString(),
|
|
39720
|
+
});
|
|
39721
|
+
if (args.op !== undefined) {
|
|
39722
|
+
params.set('op', args.op);
|
|
39723
|
+
}
|
|
39724
|
+
if (args.page !== undefined) {
|
|
39725
|
+
params.set('page', args.page.toString());
|
|
39726
|
+
}
|
|
39727
|
+
if (args.limit !== undefined) {
|
|
39728
|
+
params.set('limit', args.limit.toString());
|
|
39729
|
+
}
|
|
39730
|
+
const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, `/api/v1/commitments?${params.toString()}`);
|
|
39731
|
+
__classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
|
|
39732
|
+
return response;
|
|
39733
|
+
}
|
|
39734
|
+
async getMerklePath(args) {
|
|
39735
|
+
const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_post).call(this, '/api/v1/merkle/path', {
|
|
39736
|
+
coin_type: args.coinType,
|
|
39737
|
+
index: args.index,
|
|
39738
|
+
amount: args.amount,
|
|
39739
|
+
public_key: args.publicKey,
|
|
39740
|
+
blinding: args.blinding,
|
|
39741
|
+
vortex_pool: args.vortexPool,
|
|
39742
|
+
});
|
|
39743
|
+
__classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
|
|
39744
|
+
return response;
|
|
39745
|
+
}
|
|
39746
|
+
async executeTransaction(args) {
|
|
39747
|
+
const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_post).call(this, '/api/v1/transactions', {
|
|
39748
|
+
txBytes: args.txBytes,
|
|
39749
|
+
});
|
|
39750
|
+
__classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
|
|
39751
|
+
return response;
|
|
39752
|
+
}
|
|
39753
|
+
async getRelayer() {
|
|
39754
|
+
const response = await __classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_get).call(this, '/api/v1/relayer');
|
|
39755
|
+
__classPrivateFieldGet(this, _VortexAPI_instances, "m", _VortexAPI_assertSuccess).call(this, response);
|
|
39756
|
+
return response;
|
|
39757
|
+
}
|
|
39758
|
+
}
|
|
39759
|
+
_VortexAPI_apiUrl = new WeakMap(), _VortexAPI_instances = new WeakSet(), _VortexAPI_get = async function _VortexAPI_get(path) {
|
|
39760
|
+
const response = await fetch(`${__classPrivateFieldGet(this, _VortexAPI_apiUrl, "f")}${path}`, {
|
|
39761
|
+
method: 'GET',
|
|
39762
|
+
headers: {
|
|
39763
|
+
'Content-Type': 'application/json',
|
|
39764
|
+
},
|
|
39765
|
+
});
|
|
39766
|
+
return response.json();
|
|
39767
|
+
}, _VortexAPI_post = async function _VortexAPI_post(path, body) {
|
|
39768
|
+
const response = await fetch(`${__classPrivateFieldGet(this, _VortexAPI_apiUrl, "f")}${path}`, {
|
|
39769
|
+
method: 'POST',
|
|
39770
|
+
headers: {
|
|
39771
|
+
'Content-Type': 'application/json',
|
|
39772
|
+
},
|
|
39773
|
+
body: JSON.stringify(body),
|
|
39774
|
+
});
|
|
39775
|
+
return response.json();
|
|
39776
|
+
}, _VortexAPI_assertSuccess = function _VortexAPI_assertSuccess(response) {
|
|
39777
|
+
invariant(response.success === true, `VortexAPI request failed: ${response.error}`);
|
|
39778
|
+
};
|
|
39779
|
+
const vortexAPI = new VortexAPI();
|
|
39780
|
+
|
|
39644
39781
|
// packages/vortex/src/entities/merkle-tree.ts
|
|
39645
39782
|
const merkleTreeHashFunction = (left, right) => poseidon2(BigInt(left), BigInt(right)).toString();
|
|
39646
39783
|
const buildMerkleTree = (elements = []) => new MerkleTree(MERKLE_TREE_HEIGHT, elements, {
|
|
@@ -39649,7 +39786,7 @@ const buildMerkleTree = (elements = []) => new MerkleTree(MERKLE_TREE_HEIGHT, el
|
|
|
39649
39786
|
});
|
|
39650
39787
|
const deserializeMerkleTree = (data) => MerkleTree.deserialize(data, merkleTreeHashFunction);
|
|
39651
39788
|
|
|
39652
|
-
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool,
|
|
39789
|
+
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer, relayerFee, }) => {
|
|
39653
39790
|
const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
|
|
39654
39791
|
// Deposits we do not need a recipient, so we use a random one.
|
|
39655
39792
|
const randomVortexKeypair = VortexKeypair.generate();
|
|
@@ -39696,13 +39833,14 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39696
39833
|
const encryptedUtxo0 = VortexKeypair.encryptUtxoFor(outputUtxo0.payload(), vortexKeypair.encryptionKey);
|
|
39697
39834
|
// UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
|
|
39698
39835
|
const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
|
|
39836
|
+
const root = BigInt(merklePath0.root);
|
|
39699
39837
|
// Prepare circuit input
|
|
39700
39838
|
const input = toProveInput({
|
|
39701
39839
|
vortexObjectId,
|
|
39702
39840
|
accountSecret,
|
|
39703
39841
|
root,
|
|
39704
|
-
merklePath0,
|
|
39705
|
-
merklePath1,
|
|
39842
|
+
merklePath0: merklePath0.path,
|
|
39843
|
+
merklePath1: merklePath1.path,
|
|
39706
39844
|
publicAmount: amount - relayerFee,
|
|
39707
39845
|
nullifier0,
|
|
39708
39846
|
nullifier1,
|
|
@@ -39749,7 +39887,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39749
39887
|
};
|
|
39750
39888
|
};
|
|
39751
39889
|
|
|
39752
|
-
const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool,
|
|
39890
|
+
const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
|
|
39753
39891
|
invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
|
|
39754
39892
|
invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
|
|
39755
39893
|
const accountSecret = 0n;
|
|
@@ -39761,7 +39899,6 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39761
39899
|
vortexSdk,
|
|
39762
39900
|
vortexKeypair,
|
|
39763
39901
|
vortexPool,
|
|
39764
|
-
root,
|
|
39765
39902
|
getMerklePathFn,
|
|
39766
39903
|
relayer,
|
|
39767
39904
|
relayerFee,
|
|
@@ -39776,7 +39913,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39776
39913
|
});
|
|
39777
39914
|
};
|
|
39778
39915
|
|
|
39779
|
-
const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair,
|
|
39916
|
+
const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }) => {
|
|
39780
39917
|
invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
|
|
39781
39918
|
unspentUtxos.sort((a, b) => new BN(b.amount).cmp(new BN(a.amount)));
|
|
39782
39919
|
const totalUnspentUtxosAmount = unspentUtxos
|
|
@@ -39823,13 +39960,14 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39823
39960
|
: vortexKeypair.encryptionKey);
|
|
39824
39961
|
// UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
|
|
39825
39962
|
const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
|
|
39963
|
+
const root = BigInt(merklePath0.root);
|
|
39826
39964
|
// Prepare circuit input
|
|
39827
39965
|
const input = toProveInput({
|
|
39828
39966
|
vortexObjectId,
|
|
39829
39967
|
accountSecret,
|
|
39830
39968
|
root,
|
|
39831
|
-
merklePath0,
|
|
39832
|
-
merklePath1,
|
|
39969
|
+
merklePath0: merklePath0.path,
|
|
39970
|
+
merklePath1: merklePath1.path,
|
|
39833
39971
|
publicAmount: BN254_FIELD_MODULUS - amount,
|
|
39834
39972
|
nullifier0,
|
|
39835
39973
|
nullifier1,
|
|
@@ -39873,31 +40011,34 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39873
40011
|
};
|
|
39874
40012
|
};
|
|
39875
40013
|
|
|
39876
|
-
const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair,
|
|
39877
|
-
const { tx:
|
|
40014
|
+
const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, }) => {
|
|
40015
|
+
const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39878
40016
|
tx,
|
|
39879
40017
|
amount,
|
|
39880
40018
|
unspentUtxos,
|
|
39881
40019
|
vortexPool,
|
|
39882
40020
|
vortexKeypair,
|
|
39883
|
-
root,
|
|
39884
40021
|
getMerklePathFn,
|
|
39885
40022
|
relayer,
|
|
39886
40023
|
relayerFee,
|
|
39887
40024
|
vortexSdk,
|
|
39888
40025
|
accountSecret: 0n,
|
|
39889
40026
|
});
|
|
39890
|
-
const
|
|
40027
|
+
const vortexPoolObject = await vortexSdk.resolveVortexPool(pool);
|
|
40028
|
+
const zeroCoin = tx2.moveCall({
|
|
40029
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::coin::zero`,
|
|
40030
|
+
typeArguments: [vortexPoolObject.coinType],
|
|
40031
|
+
});
|
|
39891
40032
|
return vortexSdk.transact({
|
|
39892
40033
|
vortexPool: pool,
|
|
39893
|
-
tx:
|
|
40034
|
+
tx: tx2,
|
|
39894
40035
|
proof: moveProof,
|
|
39895
40036
|
extData: extData,
|
|
39896
|
-
deposit:
|
|
40037
|
+
deposit: zeroCoin,
|
|
39897
40038
|
});
|
|
39898
40039
|
};
|
|
39899
40040
|
|
|
39900
|
-
const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool,
|
|
40041
|
+
const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
|
|
39901
40042
|
const coins = coinStructs.map((coin) => ({
|
|
39902
40043
|
objectId: coin.coinObjectId,
|
|
39903
40044
|
version: coin.version,
|
|
@@ -39914,7 +40055,6 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39914
40055
|
vortexSdk,
|
|
39915
40056
|
vortexKeypair,
|
|
39916
40057
|
vortexPool,
|
|
39917
|
-
root,
|
|
39918
40058
|
getMerklePathFn,
|
|
39919
40059
|
relayer,
|
|
39920
40060
|
relayerFee,
|
|
@@ -39929,14 +40069,13 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39929
40069
|
});
|
|
39930
40070
|
};
|
|
39931
40071
|
|
|
39932
|
-
const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair,
|
|
40072
|
+
const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
|
|
39933
40073
|
const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39934
40074
|
tx,
|
|
39935
40075
|
amount,
|
|
39936
40076
|
unspentUtxos,
|
|
39937
40077
|
vortexPool,
|
|
39938
40078
|
vortexKeypair,
|
|
39939
|
-
root,
|
|
39940
40079
|
getMerklePathFn,
|
|
39941
40080
|
relayer,
|
|
39942
40081
|
relayerFee,
|
|
@@ -39953,14 +40092,13 @@ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [],
|
|
|
39953
40092
|
});
|
|
39954
40093
|
};
|
|
39955
40094
|
|
|
39956
|
-
const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair,
|
|
40095
|
+
const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }) => {
|
|
39957
40096
|
const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39958
40097
|
tx,
|
|
39959
40098
|
amount,
|
|
39960
40099
|
vortexPool,
|
|
39961
40100
|
unspentUtxos,
|
|
39962
40101
|
vortexKeypair,
|
|
39963
|
-
root,
|
|
39964
40102
|
getMerklePathFn,
|
|
39965
40103
|
relayer,
|
|
39966
40104
|
relayerFee: 0n,
|
|
@@ -39977,7 +40115,7 @@ const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUt
|
|
|
39977
40115
|
coinOutType,
|
|
39978
40116
|
});
|
|
39979
40117
|
};
|
|
39980
|
-
const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair,
|
|
40118
|
+
const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }) => {
|
|
39981
40119
|
const accountSecret = 0n;
|
|
39982
40120
|
const { extData, tx: tx3, moveProof, } = await prepareDepositProof({
|
|
39983
40121
|
tx,
|
|
@@ -39987,7 +40125,6 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
|
|
|
39987
40125
|
vortexSdk,
|
|
39988
40126
|
vortexKeypair,
|
|
39989
40127
|
vortexPool,
|
|
39990
|
-
root,
|
|
39991
40128
|
getMerklePathFn,
|
|
39992
40129
|
relayer: normalizeSuiAddress('0x0'),
|
|
39993
40130
|
relayerFee: 0n,
|
|
@@ -40003,5 +40140,5 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
|
|
|
40003
40140
|
});
|
|
40004
40141
|
};
|
|
40005
40142
|
|
|
40006
|
-
export { Action, BASIS_POINTS, BN254_FIELD_MODULUS, DEPOSIT_FEE_IN_BASIS_POINTS, EMPTY_COMMITMENT, EMPTY_SUBTREE_HASHES, ERROR_CODES, INITIAL_SHARED_VERSION, LSK_ENCRYPTED_OUTPUTS, LSK_FETCH_OFFSET, MERKLE_TREE_HEIGHT, Modules, OPT, REGISTRY_OBJECT_ID, ROOT_HISTORY_SIZE, TREASURY_ADDRESS, Utxo, VORTEX_PACKAGE_ID, VORTEX_POOL_IDS, VORTEX_SIGNATURE_DOMAIN, VORTEX_SWAP_PACKAGE_ID, VORTEX_SWAP_UPGRADE_CAP, VORTEX_UPGRADE_CAP, Vortex, VortexKeypair, ZERO_VALUE, buildMerkleTree, deposit, depositWithAccount, deserializeMerkleTree, finishSwap, getMerklePath, getUnspentUtxos, merkleTreeHashFunction, parseNewCommitmentEvent, parseVortexPool, poseidon1, poseidon2, poseidon3, poseidon4, prove, startSwap, toProveInput, verify, vortexSDK, withdraw, withdrawWithAccount };
|
|
40143
|
+
export { Action, BASIS_POINTS, BN254_FIELD_MODULUS, DEPOSIT_FEE_IN_BASIS_POINTS, EMPTY_COMMITMENT, EMPTY_SUBTREE_HASHES, ERROR_CODES, INITIAL_SHARED_VERSION, LSK_ENCRYPTED_OUTPUTS, LSK_FETCH_OFFSET, MERKLE_TREE_HEIGHT, Modules, OPT, REGISTRY_OBJECT_ID, ROOT_HISTORY_SIZE, TREASURY_ADDRESS, Utxo, VORTEX_API_URL, VORTEX_PACKAGE_ID, VORTEX_POOL_IDS, VORTEX_SIGNATURE_DOMAIN, VORTEX_SWAP_PACKAGE_ID, VORTEX_SWAP_UPGRADE_CAP, VORTEX_UPGRADE_CAP, Vortex, VortexAPI, VortexKeypair, ZERO_VALUE, buildMerkleTree, deposit, depositWithAccount, deserializeMerkleTree, finishSwap, getMerklePath, getUnspentUtxos, getUnspentUtxosWithApi, merkleTreeHashFunction, parseNewCommitmentEvent, parseVortexPool, poseidon1, poseidon2, poseidon3, poseidon4, prove, startSwap, toProveInput, verify, vortexAPI, vortexSDK, withdraw, withdrawWithAccount };
|
|
40007
40144
|
//# sourceMappingURL=index.mjs.map
|