@interest-protocol/vortex-sdk 6.2.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/entities/utxo.d.ts +7 -0
- package/dist/entities/utxo.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +185 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +182 -37
- 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 +3 -3
- package/src/deposit-with-account.ts +0 -2
- package/src/deposit.ts +0 -2
- package/src/entities/utxo.ts +28 -8
- 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
|
@@ -39184,11 +39184,19 @@ class Utxo {
|
|
|
39184
39184
|
this.index = index ?? 0n;
|
|
39185
39185
|
this.vortexPool = vortexPool;
|
|
39186
39186
|
}
|
|
39187
|
+
static makeCommitment({ amount, publicKey, blinding, vortexPool, }) {
|
|
39188
|
+
return poseidon4(amount, BigInt(publicKey), blinding, BigInt(normalizeSuiAddress(vortexPool, !vortexPool.startsWith('0x'))));
|
|
39189
|
+
}
|
|
39187
39190
|
static blinding() {
|
|
39188
39191
|
return BigInt(Math.floor(Math.random() * 1000000000));
|
|
39189
39192
|
}
|
|
39190
39193
|
commitment() {
|
|
39191
|
-
return
|
|
39194
|
+
return Utxo.makeCommitment({
|
|
39195
|
+
amount: this.amount,
|
|
39196
|
+
publicKey: this.keypair.publicKey,
|
|
39197
|
+
blinding: this.blinding,
|
|
39198
|
+
vortexPool: this.vortexPool,
|
|
39199
|
+
});
|
|
39192
39200
|
}
|
|
39193
39201
|
nullifier() {
|
|
39194
39202
|
const commitment = this.commitment();
|
|
@@ -39226,6 +39234,33 @@ const getUnspentUtxos = async ({ commitmentEvents, vortexKeypair, vortexSdk, vor
|
|
|
39226
39234
|
const unspentUtxos = utxos.filter((_, index) => !isNullifierSpentArray[index]);
|
|
39227
39235
|
return unspentUtxos;
|
|
39228
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
|
+
};
|
|
39229
39264
|
|
|
39230
39265
|
function getMerklePath(merkleTree, utxo) {
|
|
39231
39266
|
// Handle zero-amount UTXOs
|
|
@@ -39317,10 +39352,9 @@ const parseVortexPool = (data) => {
|
|
|
39317
39352
|
};
|
|
39318
39353
|
};
|
|
39319
39354
|
|
|
39320
|
-
var
|
|
39355
|
+
var _Vortex_suiClient, _Vortex_newPoolEventType, _Vortex_newAccountEventType, _Vortex_newCommitmentEventType, _Vortex_nullifierSpentEventType, _Vortex_newEncryptionKeyEventType;
|
|
39321
39356
|
class Vortex {
|
|
39322
39357
|
constructor({ registry, packageId, swapPackageId, fullNodeUrl = getFullnodeUrl('devnet'), }) {
|
|
39323
|
-
_Vortex_instances.add(this);
|
|
39324
39358
|
_Vortex_suiClient.set(this, void 0);
|
|
39325
39359
|
_Vortex_newPoolEventType.set(this, void 0);
|
|
39326
39360
|
_Vortex_newAccountEventType.set(this, void 0);
|
|
@@ -39435,7 +39469,7 @@ class Vortex {
|
|
|
39435
39469
|
const value = action === Action.Deposit
|
|
39436
39470
|
? publicValue
|
|
39437
39471
|
: BN254_FIELD_MODULUS - publicValue;
|
|
39438
|
-
const vortex = await
|
|
39472
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39439
39473
|
const proof = tx.moveCall({
|
|
39440
39474
|
target: `${this.packageId}::vortex_proof::new`,
|
|
39441
39475
|
arguments: [
|
|
@@ -39453,7 +39487,7 @@ class Vortex {
|
|
|
39453
39487
|
return { tx, proof };
|
|
39454
39488
|
}
|
|
39455
39489
|
async transact({ tx = new Transaction(), vortexPool, proof, extData, deposit, }) {
|
|
39456
|
-
const vortex = await
|
|
39490
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39457
39491
|
const coin = tx.moveCall({
|
|
39458
39492
|
target: `${this.packageId}::vortex::transact`,
|
|
39459
39493
|
arguments: [tx.object(vortex.objectId), deposit, proof, extData],
|
|
@@ -39462,7 +39496,7 @@ class Vortex {
|
|
|
39462
39496
|
return { tx, coin };
|
|
39463
39497
|
}
|
|
39464
39498
|
async transactWithAccount({ tx = new Transaction(), vortexPool, account, coins, proof, extData, }) {
|
|
39465
|
-
const vortex = await
|
|
39499
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39466
39500
|
const coin = tx.moveCall({
|
|
39467
39501
|
target: `${this.packageId}::vortex::transact_with_account`,
|
|
39468
39502
|
arguments: [
|
|
@@ -39508,7 +39542,7 @@ class Vortex {
|
|
|
39508
39542
|
}
|
|
39509
39543
|
async nextIndex(vortexPool) {
|
|
39510
39544
|
const tx = new Transaction();
|
|
39511
|
-
const vortex = await
|
|
39545
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39512
39546
|
tx.moveCall({
|
|
39513
39547
|
target: `${this.packageId}::vortex::next_index`,
|
|
39514
39548
|
arguments: [tx.object(vortex.objectId)],
|
|
@@ -39521,7 +39555,7 @@ class Vortex {
|
|
|
39521
39555
|
return BigInt(result[0][0]);
|
|
39522
39556
|
}
|
|
39523
39557
|
async isNullifierSpent({ nullifier, vortexPool }) {
|
|
39524
|
-
const vortex = await
|
|
39558
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39525
39559
|
const tx = new Transaction();
|
|
39526
39560
|
tx.moveCall({
|
|
39527
39561
|
target: `${this.packageId}::vortex::is_nullifier_spent`,
|
|
@@ -39535,7 +39569,7 @@ class Vortex {
|
|
|
39535
39569
|
return result[0][0];
|
|
39536
39570
|
}
|
|
39537
39571
|
async areNullifiersSpent({ nullifiers, vortexPool }) {
|
|
39538
|
-
const vortex = await
|
|
39572
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39539
39573
|
if (nullifiers.length === 0)
|
|
39540
39574
|
return [];
|
|
39541
39575
|
const tx = new Transaction();
|
|
@@ -39551,7 +39585,7 @@ class Vortex {
|
|
|
39551
39585
|
return result.flat();
|
|
39552
39586
|
}
|
|
39553
39587
|
async startSwap({ tx = new Transaction(), vortex, proof, extData, relayer, minAmountOut, coinOutType, }) {
|
|
39554
|
-
const vortexPool = await
|
|
39588
|
+
const vortexPool = await this.resolveVortexPool(vortex);
|
|
39555
39589
|
const [receipt, coinIn] = tx.moveCall({
|
|
39556
39590
|
target: `${this.swapPackageId}::vortex_swap::start_swap`,
|
|
39557
39591
|
arguments: [
|
|
@@ -39566,7 +39600,7 @@ class Vortex {
|
|
|
39566
39600
|
return { tx, receipt, coinIn };
|
|
39567
39601
|
}
|
|
39568
39602
|
async finishSwap({ tx = new Transaction(), vortex, coinOut, proof, extData, receipt, coinInType, }) {
|
|
39569
|
-
const vortexPool = await
|
|
39603
|
+
const vortexPool = await this.resolveVortexPool(vortex);
|
|
39570
39604
|
tx.moveCall({
|
|
39571
39605
|
target: `${this.swapPackageId}::vortex_swap::finish_swap`,
|
|
39572
39606
|
arguments: [
|
|
@@ -39619,10 +39653,11 @@ class Vortex {
|
|
|
39619
39653
|
mutable: true,
|
|
39620
39654
|
});
|
|
39621
39655
|
}
|
|
39656
|
+
async resolveVortexPool(vortex) {
|
|
39657
|
+
return typeof vortex === 'string' ? this.getVortexPool(vortex) : vortex;
|
|
39658
|
+
}
|
|
39622
39659
|
}
|
|
39623
|
-
_Vortex_suiClient = new WeakMap(), _Vortex_newPoolEventType = new WeakMap(), _Vortex_newAccountEventType = new WeakMap(), _Vortex_newCommitmentEventType = new WeakMap(), _Vortex_nullifierSpentEventType = new WeakMap(), _Vortex_newEncryptionKeyEventType = new WeakMap()
|
|
39624
|
-
return typeof vortex === 'string' ? this.getVortexPool(vortex) : vortex;
|
|
39625
|
-
};
|
|
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();
|
|
39626
39661
|
const vortexSDK = new Vortex({
|
|
39627
39662
|
packageId: VORTEX_PACKAGE_ID,
|
|
39628
39663
|
registry: {
|
|
@@ -39633,6 +39668,116 @@ const vortexSDK = new Vortex({
|
|
|
39633
39668
|
fullNodeUrl: getFullnodeUrl('testnet'),
|
|
39634
39669
|
});
|
|
39635
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
|
+
|
|
39636
39781
|
// packages/vortex/src/entities/merkle-tree.ts
|
|
39637
39782
|
const merkleTreeHashFunction = (left, right) => poseidon2(BigInt(left), BigInt(right)).toString();
|
|
39638
39783
|
const buildMerkleTree = (elements = []) => new MerkleTree(MERKLE_TREE_HEIGHT, elements, {
|
|
@@ -39641,7 +39786,7 @@ const buildMerkleTree = (elements = []) => new MerkleTree(MERKLE_TREE_HEIGHT, el
|
|
|
39641
39786
|
});
|
|
39642
39787
|
const deserializeMerkleTree = (data) => MerkleTree.deserialize(data, merkleTreeHashFunction);
|
|
39643
39788
|
|
|
39644
|
-
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool,
|
|
39789
|
+
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer, relayerFee, }) => {
|
|
39645
39790
|
const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
|
|
39646
39791
|
// Deposits we do not need a recipient, so we use a random one.
|
|
39647
39792
|
const randomVortexKeypair = VortexKeypair.generate();
|
|
@@ -39688,13 +39833,14 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39688
39833
|
const encryptedUtxo0 = VortexKeypair.encryptUtxoFor(outputUtxo0.payload(), vortexKeypair.encryptionKey);
|
|
39689
39834
|
// UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
|
|
39690
39835
|
const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
|
|
39836
|
+
const root = BigInt(merklePath0.root);
|
|
39691
39837
|
// Prepare circuit input
|
|
39692
39838
|
const input = toProveInput({
|
|
39693
39839
|
vortexObjectId,
|
|
39694
39840
|
accountSecret,
|
|
39695
39841
|
root,
|
|
39696
|
-
merklePath0,
|
|
39697
|
-
merklePath1,
|
|
39842
|
+
merklePath0: merklePath0.path,
|
|
39843
|
+
merklePath1: merklePath1.path,
|
|
39698
39844
|
publicAmount: amount - relayerFee,
|
|
39699
39845
|
nullifier0,
|
|
39700
39846
|
nullifier1,
|
|
@@ -39741,7 +39887,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39741
39887
|
};
|
|
39742
39888
|
};
|
|
39743
39889
|
|
|
39744
|
-
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, }) => {
|
|
39745
39891
|
invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
|
|
39746
39892
|
invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
|
|
39747
39893
|
const accountSecret = 0n;
|
|
@@ -39753,7 +39899,6 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39753
39899
|
vortexSdk,
|
|
39754
39900
|
vortexKeypair,
|
|
39755
39901
|
vortexPool,
|
|
39756
|
-
root,
|
|
39757
39902
|
getMerklePathFn,
|
|
39758
39903
|
relayer,
|
|
39759
39904
|
relayerFee,
|
|
@@ -39768,7 +39913,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39768
39913
|
});
|
|
39769
39914
|
};
|
|
39770
39915
|
|
|
39771
|
-
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, }) => {
|
|
39772
39917
|
invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
|
|
39773
39918
|
unspentUtxos.sort((a, b) => new BN(b.amount).cmp(new BN(a.amount)));
|
|
39774
39919
|
const totalUnspentUtxosAmount = unspentUtxos
|
|
@@ -39815,13 +39960,14 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39815
39960
|
: vortexKeypair.encryptionKey);
|
|
39816
39961
|
// UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
|
|
39817
39962
|
const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
|
|
39963
|
+
const root = BigInt(merklePath0.root);
|
|
39818
39964
|
// Prepare circuit input
|
|
39819
39965
|
const input = toProveInput({
|
|
39820
39966
|
vortexObjectId,
|
|
39821
39967
|
accountSecret,
|
|
39822
39968
|
root,
|
|
39823
|
-
merklePath0,
|
|
39824
|
-
merklePath1,
|
|
39969
|
+
merklePath0: merklePath0.path,
|
|
39970
|
+
merklePath1: merklePath1.path,
|
|
39825
39971
|
publicAmount: BN254_FIELD_MODULUS - amount,
|
|
39826
39972
|
nullifier0,
|
|
39827
39973
|
nullifier1,
|
|
@@ -39865,31 +40011,34 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39865
40011
|
};
|
|
39866
40012
|
};
|
|
39867
40013
|
|
|
39868
|
-
const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair,
|
|
39869
|
-
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({
|
|
39870
40016
|
tx,
|
|
39871
40017
|
amount,
|
|
39872
40018
|
unspentUtxos,
|
|
39873
40019
|
vortexPool,
|
|
39874
40020
|
vortexKeypair,
|
|
39875
|
-
root,
|
|
39876
40021
|
getMerklePathFn,
|
|
39877
40022
|
relayer,
|
|
39878
40023
|
relayerFee,
|
|
39879
40024
|
vortexSdk,
|
|
39880
40025
|
accountSecret: 0n,
|
|
39881
40026
|
});
|
|
39882
|
-
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
|
+
});
|
|
39883
40032
|
return vortexSdk.transact({
|
|
39884
40033
|
vortexPool: pool,
|
|
39885
|
-
tx:
|
|
40034
|
+
tx: tx2,
|
|
39886
40035
|
proof: moveProof,
|
|
39887
40036
|
extData: extData,
|
|
39888
|
-
deposit:
|
|
40037
|
+
deposit: zeroCoin,
|
|
39889
40038
|
});
|
|
39890
40039
|
};
|
|
39891
40040
|
|
|
39892
|
-
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, }) => {
|
|
39893
40042
|
const coins = coinStructs.map((coin) => ({
|
|
39894
40043
|
objectId: coin.coinObjectId,
|
|
39895
40044
|
version: coin.version,
|
|
@@ -39906,7 +40055,6 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39906
40055
|
vortexSdk,
|
|
39907
40056
|
vortexKeypair,
|
|
39908
40057
|
vortexPool,
|
|
39909
|
-
root,
|
|
39910
40058
|
getMerklePathFn,
|
|
39911
40059
|
relayer,
|
|
39912
40060
|
relayerFee,
|
|
@@ -39921,14 +40069,13 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39921
40069
|
});
|
|
39922
40070
|
};
|
|
39923
40071
|
|
|
39924
|
-
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, }) => {
|
|
39925
40073
|
const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39926
40074
|
tx,
|
|
39927
40075
|
amount,
|
|
39928
40076
|
unspentUtxos,
|
|
39929
40077
|
vortexPool,
|
|
39930
40078
|
vortexKeypair,
|
|
39931
|
-
root,
|
|
39932
40079
|
getMerklePathFn,
|
|
39933
40080
|
relayer,
|
|
39934
40081
|
relayerFee,
|
|
@@ -39945,14 +40092,13 @@ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [],
|
|
|
39945
40092
|
});
|
|
39946
40093
|
};
|
|
39947
40094
|
|
|
39948
|
-
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, }) => {
|
|
39949
40096
|
const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39950
40097
|
tx,
|
|
39951
40098
|
amount,
|
|
39952
40099
|
vortexPool,
|
|
39953
40100
|
unspentUtxos,
|
|
39954
40101
|
vortexKeypair,
|
|
39955
|
-
root,
|
|
39956
40102
|
getMerklePathFn,
|
|
39957
40103
|
relayer,
|
|
39958
40104
|
relayerFee: 0n,
|
|
@@ -39969,7 +40115,7 @@ const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUt
|
|
|
39969
40115
|
coinOutType,
|
|
39970
40116
|
});
|
|
39971
40117
|
};
|
|
39972
|
-
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, }) => {
|
|
39973
40119
|
const accountSecret = 0n;
|
|
39974
40120
|
const { extData, tx: tx3, moveProof, } = await prepareDepositProof({
|
|
39975
40121
|
tx,
|
|
@@ -39979,7 +40125,6 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
|
|
|
39979
40125
|
vortexSdk,
|
|
39980
40126
|
vortexKeypair,
|
|
39981
40127
|
vortexPool,
|
|
39982
|
-
root,
|
|
39983
40128
|
getMerklePathFn,
|
|
39984
40129
|
relayer: normalizeSuiAddress('0x0'),
|
|
39985
40130
|
relayerFee: 0n,
|
|
@@ -39995,5 +40140,5 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
|
|
|
39995
40140
|
});
|
|
39996
40141
|
};
|
|
39997
40142
|
|
|
39998
|
-
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 };
|
|
39999
40144
|
//# sourceMappingURL=index.mjs.map
|