@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.
- 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 +177 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +174 -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 +115 -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 +3 -3
- 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 +192 -0
- package/src/vortex-api.types.ts +138 -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,117 @@ 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
|
+
}, args.apiKey);
|
|
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, apiKey) {
|
|
39768
|
+
const response = await fetch(`${__classPrivateFieldGet(this, _VortexAPI_apiUrl, "f")}${path}`, {
|
|
39769
|
+
method: 'POST',
|
|
39770
|
+
headers: {
|
|
39771
|
+
'Content-Type': 'application/json',
|
|
39772
|
+
'x-api-key': apiKey ?? '',
|
|
39773
|
+
},
|
|
39774
|
+
body: JSON.stringify(body),
|
|
39775
|
+
});
|
|
39776
|
+
return response.json();
|
|
39777
|
+
}, _VortexAPI_assertSuccess = function _VortexAPI_assertSuccess(response) {
|
|
39778
|
+
invariant(response.success === true, `VortexAPI request failed: ${response.error}`);
|
|
39779
|
+
};
|
|
39780
|
+
const vortexAPI = new VortexAPI();
|
|
39781
|
+
|
|
39644
39782
|
// packages/vortex/src/entities/merkle-tree.ts
|
|
39645
39783
|
const merkleTreeHashFunction = (left, right) => poseidon2(BigInt(left), BigInt(right)).toString();
|
|
39646
39784
|
const buildMerkleTree = (elements = []) => new MerkleTree(MERKLE_TREE_HEIGHT, elements, {
|
|
@@ -39649,7 +39787,7 @@ const buildMerkleTree = (elements = []) => new MerkleTree(MERKLE_TREE_HEIGHT, el
|
|
|
39649
39787
|
});
|
|
39650
39788
|
const deserializeMerkleTree = (data) => MerkleTree.deserialize(data, merkleTreeHashFunction);
|
|
39651
39789
|
|
|
39652
|
-
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool,
|
|
39790
|
+
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer, relayerFee, }) => {
|
|
39653
39791
|
const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
|
|
39654
39792
|
// Deposits we do not need a recipient, so we use a random one.
|
|
39655
39793
|
const randomVortexKeypair = VortexKeypair.generate();
|
|
@@ -39696,13 +39834,14 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39696
39834
|
const encryptedUtxo0 = VortexKeypair.encryptUtxoFor(outputUtxo0.payload(), vortexKeypair.encryptionKey);
|
|
39697
39835
|
// UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
|
|
39698
39836
|
const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
|
|
39837
|
+
const root = BigInt(merklePath0.root);
|
|
39699
39838
|
// Prepare circuit input
|
|
39700
39839
|
const input = toProveInput({
|
|
39701
39840
|
vortexObjectId,
|
|
39702
39841
|
accountSecret,
|
|
39703
39842
|
root,
|
|
39704
|
-
merklePath0,
|
|
39705
|
-
merklePath1,
|
|
39843
|
+
merklePath0: merklePath0.path,
|
|
39844
|
+
merklePath1: merklePath1.path,
|
|
39706
39845
|
publicAmount: amount - relayerFee,
|
|
39707
39846
|
nullifier0,
|
|
39708
39847
|
nullifier1,
|
|
@@ -39749,7 +39888,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39749
39888
|
};
|
|
39750
39889
|
};
|
|
39751
39890
|
|
|
39752
|
-
const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool,
|
|
39891
|
+
const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
|
|
39753
39892
|
invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
|
|
39754
39893
|
invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
|
|
39755
39894
|
const accountSecret = 0n;
|
|
@@ -39761,7 +39900,6 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39761
39900
|
vortexSdk,
|
|
39762
39901
|
vortexKeypair,
|
|
39763
39902
|
vortexPool,
|
|
39764
|
-
root,
|
|
39765
39903
|
getMerklePathFn,
|
|
39766
39904
|
relayer,
|
|
39767
39905
|
relayerFee,
|
|
@@ -39776,7 +39914,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39776
39914
|
});
|
|
39777
39915
|
};
|
|
39778
39916
|
|
|
39779
|
-
const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair,
|
|
39917
|
+
const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }) => {
|
|
39780
39918
|
invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
|
|
39781
39919
|
unspentUtxos.sort((a, b) => new BN(b.amount).cmp(new BN(a.amount)));
|
|
39782
39920
|
const totalUnspentUtxosAmount = unspentUtxos
|
|
@@ -39823,13 +39961,14 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39823
39961
|
: vortexKeypair.encryptionKey);
|
|
39824
39962
|
// UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
|
|
39825
39963
|
const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
|
|
39964
|
+
const root = BigInt(merklePath0.root);
|
|
39826
39965
|
// Prepare circuit input
|
|
39827
39966
|
const input = toProveInput({
|
|
39828
39967
|
vortexObjectId,
|
|
39829
39968
|
accountSecret,
|
|
39830
39969
|
root,
|
|
39831
|
-
merklePath0,
|
|
39832
|
-
merklePath1,
|
|
39970
|
+
merklePath0: merklePath0.path,
|
|
39971
|
+
merklePath1: merklePath1.path,
|
|
39833
39972
|
publicAmount: BN254_FIELD_MODULUS - amount,
|
|
39834
39973
|
nullifier0,
|
|
39835
39974
|
nullifier1,
|
|
@@ -39873,31 +40012,34 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39873
40012
|
};
|
|
39874
40013
|
};
|
|
39875
40014
|
|
|
39876
|
-
const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair,
|
|
39877
|
-
const { tx:
|
|
40015
|
+
const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, }) => {
|
|
40016
|
+
const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39878
40017
|
tx,
|
|
39879
40018
|
amount,
|
|
39880
40019
|
unspentUtxos,
|
|
39881
40020
|
vortexPool,
|
|
39882
40021
|
vortexKeypair,
|
|
39883
|
-
root,
|
|
39884
40022
|
getMerklePathFn,
|
|
39885
40023
|
relayer,
|
|
39886
40024
|
relayerFee,
|
|
39887
40025
|
vortexSdk,
|
|
39888
40026
|
accountSecret: 0n,
|
|
39889
40027
|
});
|
|
39890
|
-
const
|
|
40028
|
+
const vortexPoolObject = await vortexSdk.resolveVortexPool(pool);
|
|
40029
|
+
const zeroCoin = tx2.moveCall({
|
|
40030
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::coin::zero`,
|
|
40031
|
+
typeArguments: [vortexPoolObject.coinType],
|
|
40032
|
+
});
|
|
39891
40033
|
return vortexSdk.transact({
|
|
39892
40034
|
vortexPool: pool,
|
|
39893
|
-
tx:
|
|
40035
|
+
tx: tx2,
|
|
39894
40036
|
proof: moveProof,
|
|
39895
40037
|
extData: extData,
|
|
39896
|
-
deposit:
|
|
40038
|
+
deposit: zeroCoin,
|
|
39897
40039
|
});
|
|
39898
40040
|
};
|
|
39899
40041
|
|
|
39900
|
-
const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool,
|
|
40042
|
+
const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
|
|
39901
40043
|
const coins = coinStructs.map((coin) => ({
|
|
39902
40044
|
objectId: coin.coinObjectId,
|
|
39903
40045
|
version: coin.version,
|
|
@@ -39914,7 +40056,6 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39914
40056
|
vortexSdk,
|
|
39915
40057
|
vortexKeypair,
|
|
39916
40058
|
vortexPool,
|
|
39917
|
-
root,
|
|
39918
40059
|
getMerklePathFn,
|
|
39919
40060
|
relayer,
|
|
39920
40061
|
relayerFee,
|
|
@@ -39929,14 +40070,13 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39929
40070
|
});
|
|
39930
40071
|
};
|
|
39931
40072
|
|
|
39932
|
-
const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair,
|
|
40073
|
+
const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
|
|
39933
40074
|
const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39934
40075
|
tx,
|
|
39935
40076
|
amount,
|
|
39936
40077
|
unspentUtxos,
|
|
39937
40078
|
vortexPool,
|
|
39938
40079
|
vortexKeypair,
|
|
39939
|
-
root,
|
|
39940
40080
|
getMerklePathFn,
|
|
39941
40081
|
relayer,
|
|
39942
40082
|
relayerFee,
|
|
@@ -39953,14 +40093,13 @@ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [],
|
|
|
39953
40093
|
});
|
|
39954
40094
|
};
|
|
39955
40095
|
|
|
39956
|
-
const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair,
|
|
40096
|
+
const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }) => {
|
|
39957
40097
|
const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39958
40098
|
tx,
|
|
39959
40099
|
amount,
|
|
39960
40100
|
vortexPool,
|
|
39961
40101
|
unspentUtxos,
|
|
39962
40102
|
vortexKeypair,
|
|
39963
|
-
root,
|
|
39964
40103
|
getMerklePathFn,
|
|
39965
40104
|
relayer,
|
|
39966
40105
|
relayerFee: 0n,
|
|
@@ -39977,7 +40116,7 @@ const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUt
|
|
|
39977
40116
|
coinOutType,
|
|
39978
40117
|
});
|
|
39979
40118
|
};
|
|
39980
|
-
const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair,
|
|
40119
|
+
const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }) => {
|
|
39981
40120
|
const accountSecret = 0n;
|
|
39982
40121
|
const { extData, tx: tx3, moveProof, } = await prepareDepositProof({
|
|
39983
40122
|
tx,
|
|
@@ -39987,7 +40126,6 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
|
|
|
39987
40126
|
vortexSdk,
|
|
39988
40127
|
vortexKeypair,
|
|
39989
40128
|
vortexPool,
|
|
39990
|
-
root,
|
|
39991
40129
|
getMerklePathFn,
|
|
39992
40130
|
relayer: normalizeSuiAddress('0x0'),
|
|
39993
40131
|
relayerFee: 0n,
|
|
@@ -40003,5 +40141,5 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
|
|
|
40003
40141
|
});
|
|
40004
40142
|
};
|
|
40005
40143
|
|
|
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 };
|
|
40144
|
+
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
40145
|
//# sourceMappingURL=index.mjs.map
|