@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
|
@@ -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,
|
|
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,
|
|
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,
|
|
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
|
}>;
|
package/dist/deposit.d.ts.map
CHANGED
|
@@ -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,
|
|
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/entities/utxo.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ interface UtxoConstructorArgs {
|
|
|
6
6
|
index?: bigint;
|
|
7
7
|
vortexPool: string;
|
|
8
8
|
}
|
|
9
|
+
interface MakeCommitmentArgs {
|
|
10
|
+
amount: bigint;
|
|
11
|
+
publicKey: string;
|
|
12
|
+
blinding: bigint;
|
|
13
|
+
vortexPool: string;
|
|
14
|
+
}
|
|
9
15
|
export declare class Utxo {
|
|
10
16
|
amount: bigint;
|
|
11
17
|
blinding: bigint;
|
|
@@ -13,6 +19,7 @@ export declare class Utxo {
|
|
|
13
19
|
index: bigint;
|
|
14
20
|
vortexPool: string;
|
|
15
21
|
constructor({ amount, blinding, keypair, index, vortexPool, }: UtxoConstructorArgs);
|
|
22
|
+
static makeCommitment({ amount, publicKey, blinding, vortexPool, }: MakeCommitmentArgs): bigint;
|
|
16
23
|
static blinding(): bigint;
|
|
17
24
|
commitment(): bigint;
|
|
18
25
|
nullifier(): bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/entities/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/entities/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAI1C,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,IAAI;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;gBAEP,EACV,MAAM,EACN,QAAQ,EACR,OAAO,EACP,KAAK,EACL,UAAU,GACX,EAAE,mBAAmB;IAQtB,MAAM,CAAC,cAAc,CAAC,EACpB,MAAM,EACN,SAAS,EACT,QAAQ,EACR,UAAU,GACX,EAAE,kBAAkB;IASrB,MAAM,CAAC,QAAQ;IAIf,UAAU;IASV,SAAS;IAST,OAAO;;;;;;CAQR"}
|
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';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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
|
@@ -39186,11 +39186,19 @@ class Utxo {
|
|
|
39186
39186
|
this.index = index ?? 0n;
|
|
39187
39187
|
this.vortexPool = vortexPool;
|
|
39188
39188
|
}
|
|
39189
|
+
static makeCommitment({ amount, publicKey, blinding, vortexPool, }) {
|
|
39190
|
+
return poseidon4(amount, BigInt(publicKey), blinding, BigInt(normalizeSuiAddress(vortexPool, !vortexPool.startsWith('0x'))));
|
|
39191
|
+
}
|
|
39189
39192
|
static blinding() {
|
|
39190
39193
|
return BigInt(Math.floor(Math.random() * 1000000000));
|
|
39191
39194
|
}
|
|
39192
39195
|
commitment() {
|
|
39193
|
-
return
|
|
39196
|
+
return Utxo.makeCommitment({
|
|
39197
|
+
amount: this.amount,
|
|
39198
|
+
publicKey: this.keypair.publicKey,
|
|
39199
|
+
blinding: this.blinding,
|
|
39200
|
+
vortexPool: this.vortexPool,
|
|
39201
|
+
});
|
|
39194
39202
|
}
|
|
39195
39203
|
nullifier() {
|
|
39196
39204
|
const commitment = this.commitment();
|
|
@@ -39228,6 +39236,33 @@ const getUnspentUtxos = async ({ commitmentEvents, vortexKeypair, vortexSdk, vor
|
|
|
39228
39236
|
const unspentUtxos = utxos.filter((_, index) => !isNullifierSpentArray[index]);
|
|
39229
39237
|
return unspentUtxos;
|
|
39230
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
|
+
};
|
|
39231
39266
|
|
|
39232
39267
|
function getMerklePath(merkleTree, utxo) {
|
|
39233
39268
|
// Handle zero-amount UTXOs
|
|
@@ -39319,10 +39354,9 @@ const parseVortexPool = (data) => {
|
|
|
39319
39354
|
};
|
|
39320
39355
|
};
|
|
39321
39356
|
|
|
39322
|
-
var
|
|
39357
|
+
var _Vortex_suiClient, _Vortex_newPoolEventType, _Vortex_newAccountEventType, _Vortex_newCommitmentEventType, _Vortex_nullifierSpentEventType, _Vortex_newEncryptionKeyEventType;
|
|
39323
39358
|
class Vortex {
|
|
39324
39359
|
constructor({ registry, packageId, swapPackageId, fullNodeUrl = getFullnodeUrl('devnet'), }) {
|
|
39325
|
-
_Vortex_instances.add(this);
|
|
39326
39360
|
_Vortex_suiClient.set(this, void 0);
|
|
39327
39361
|
_Vortex_newPoolEventType.set(this, void 0);
|
|
39328
39362
|
_Vortex_newAccountEventType.set(this, void 0);
|
|
@@ -39437,7 +39471,7 @@ class Vortex {
|
|
|
39437
39471
|
const value = action === exports.Action.Deposit
|
|
39438
39472
|
? publicValue
|
|
39439
39473
|
: BN254_FIELD_MODULUS - publicValue;
|
|
39440
|
-
const vortex = await
|
|
39474
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39441
39475
|
const proof = tx.moveCall({
|
|
39442
39476
|
target: `${this.packageId}::vortex_proof::new`,
|
|
39443
39477
|
arguments: [
|
|
@@ -39455,7 +39489,7 @@ class Vortex {
|
|
|
39455
39489
|
return { tx, proof };
|
|
39456
39490
|
}
|
|
39457
39491
|
async transact({ tx = new Transaction(), vortexPool, proof, extData, deposit, }) {
|
|
39458
|
-
const vortex = await
|
|
39492
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39459
39493
|
const coin = tx.moveCall({
|
|
39460
39494
|
target: `${this.packageId}::vortex::transact`,
|
|
39461
39495
|
arguments: [tx.object(vortex.objectId), deposit, proof, extData],
|
|
@@ -39464,7 +39498,7 @@ class Vortex {
|
|
|
39464
39498
|
return { tx, coin };
|
|
39465
39499
|
}
|
|
39466
39500
|
async transactWithAccount({ tx = new Transaction(), vortexPool, account, coins, proof, extData, }) {
|
|
39467
|
-
const vortex = await
|
|
39501
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39468
39502
|
const coin = tx.moveCall({
|
|
39469
39503
|
target: `${this.packageId}::vortex::transact_with_account`,
|
|
39470
39504
|
arguments: [
|
|
@@ -39510,7 +39544,7 @@ class Vortex {
|
|
|
39510
39544
|
}
|
|
39511
39545
|
async nextIndex(vortexPool) {
|
|
39512
39546
|
const tx = new Transaction();
|
|
39513
|
-
const vortex = await
|
|
39547
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39514
39548
|
tx.moveCall({
|
|
39515
39549
|
target: `${this.packageId}::vortex::next_index`,
|
|
39516
39550
|
arguments: [tx.object(vortex.objectId)],
|
|
@@ -39523,7 +39557,7 @@ class Vortex {
|
|
|
39523
39557
|
return BigInt(result[0][0]);
|
|
39524
39558
|
}
|
|
39525
39559
|
async isNullifierSpent({ nullifier, vortexPool }) {
|
|
39526
|
-
const vortex = await
|
|
39560
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39527
39561
|
const tx = new Transaction();
|
|
39528
39562
|
tx.moveCall({
|
|
39529
39563
|
target: `${this.packageId}::vortex::is_nullifier_spent`,
|
|
@@ -39537,7 +39571,7 @@ class Vortex {
|
|
|
39537
39571
|
return result[0][0];
|
|
39538
39572
|
}
|
|
39539
39573
|
async areNullifiersSpent({ nullifiers, vortexPool }) {
|
|
39540
|
-
const vortex = await
|
|
39574
|
+
const vortex = await this.resolveVortexPool(vortexPool);
|
|
39541
39575
|
if (nullifiers.length === 0)
|
|
39542
39576
|
return [];
|
|
39543
39577
|
const tx = new Transaction();
|
|
@@ -39553,7 +39587,7 @@ class Vortex {
|
|
|
39553
39587
|
return result.flat();
|
|
39554
39588
|
}
|
|
39555
39589
|
async startSwap({ tx = new Transaction(), vortex, proof, extData, relayer, minAmountOut, coinOutType, }) {
|
|
39556
|
-
const vortexPool = await
|
|
39590
|
+
const vortexPool = await this.resolveVortexPool(vortex);
|
|
39557
39591
|
const [receipt, coinIn] = tx.moveCall({
|
|
39558
39592
|
target: `${this.swapPackageId}::vortex_swap::start_swap`,
|
|
39559
39593
|
arguments: [
|
|
@@ -39568,7 +39602,7 @@ class Vortex {
|
|
|
39568
39602
|
return { tx, receipt, coinIn };
|
|
39569
39603
|
}
|
|
39570
39604
|
async finishSwap({ tx = new Transaction(), vortex, coinOut, proof, extData, receipt, coinInType, }) {
|
|
39571
|
-
const vortexPool = await
|
|
39605
|
+
const vortexPool = await this.resolveVortexPool(vortex);
|
|
39572
39606
|
tx.moveCall({
|
|
39573
39607
|
target: `${this.swapPackageId}::vortex_swap::finish_swap`,
|
|
39574
39608
|
arguments: [
|
|
@@ -39621,10 +39655,11 @@ class Vortex {
|
|
|
39621
39655
|
mutable: true,
|
|
39622
39656
|
});
|
|
39623
39657
|
}
|
|
39658
|
+
async resolveVortexPool(vortex) {
|
|
39659
|
+
return typeof vortex === 'string' ? this.getVortexPool(vortex) : vortex;
|
|
39660
|
+
}
|
|
39624
39661
|
}
|
|
39625
|
-
_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
|
-
return typeof vortex === 'string' ? this.getVortexPool(vortex) : vortex;
|
|
39627
|
-
};
|
|
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();
|
|
39628
39663
|
const vortexSDK = new Vortex({
|
|
39629
39664
|
packageId: VORTEX_PACKAGE_ID,
|
|
39630
39665
|
registry: {
|
|
@@ -39635,6 +39670,116 @@ const vortexSDK = new Vortex({
|
|
|
39635
39670
|
fullNodeUrl: getFullnodeUrl('testnet'),
|
|
39636
39671
|
});
|
|
39637
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
|
+
|
|
39638
39783
|
// packages/vortex/src/entities/merkle-tree.ts
|
|
39639
39784
|
const merkleTreeHashFunction = (left, right) => poseidon2(BigInt(left), BigInt(right)).toString();
|
|
39640
39785
|
const buildMerkleTree = (elements = []) => new fixedMerkleTree.MerkleTree(MERKLE_TREE_HEIGHT, elements, {
|
|
@@ -39643,7 +39788,7 @@ const buildMerkleTree = (elements = []) => new fixedMerkleTree.MerkleTree(MERKLE
|
|
|
39643
39788
|
});
|
|
39644
39789
|
const deserializeMerkleTree = (data) => fixedMerkleTree.MerkleTree.deserialize(data, merkleTreeHashFunction);
|
|
39645
39790
|
|
|
39646
|
-
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool,
|
|
39791
|
+
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer, relayerFee, }) => {
|
|
39647
39792
|
const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
|
|
39648
39793
|
// Deposits we do not need a recipient, so we use a random one.
|
|
39649
39794
|
const randomVortexKeypair = VortexKeypair.generate();
|
|
@@ -39690,13 +39835,14 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39690
39835
|
const encryptedUtxo0 = VortexKeypair.encryptUtxoFor(outputUtxo0.payload(), vortexKeypair.encryptionKey);
|
|
39691
39836
|
// UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
|
|
39692
39837
|
const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
|
|
39838
|
+
const root = BigInt(merklePath0.root);
|
|
39693
39839
|
// Prepare circuit input
|
|
39694
39840
|
const input = toProveInput({
|
|
39695
39841
|
vortexObjectId,
|
|
39696
39842
|
accountSecret,
|
|
39697
39843
|
root,
|
|
39698
|
-
merklePath0,
|
|
39699
|
-
merklePath1,
|
|
39844
|
+
merklePath0: merklePath0.path,
|
|
39845
|
+
merklePath1: merklePath1.path,
|
|
39700
39846
|
publicAmount: amount - relayerFee,
|
|
39701
39847
|
nullifier0,
|
|
39702
39848
|
nullifier1,
|
|
@@ -39743,7 +39889,7 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39743
39889
|
};
|
|
39744
39890
|
};
|
|
39745
39891
|
|
|
39746
|
-
const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool,
|
|
39892
|
+
const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
|
|
39747
39893
|
invariant(unspentUtxos.length <= 2, 'Unspent UTXOs must be at most 2');
|
|
39748
39894
|
invariant(BN254_FIELD_MODULUS > amount, 'Amount must be less than field modulus');
|
|
39749
39895
|
const accountSecret = 0n;
|
|
@@ -39755,7 +39901,6 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39755
39901
|
vortexSdk,
|
|
39756
39902
|
vortexKeypair,
|
|
39757
39903
|
vortexPool,
|
|
39758
|
-
root,
|
|
39759
39904
|
getMerklePathFn,
|
|
39760
39905
|
relayer,
|
|
39761
39906
|
relayerFee,
|
|
@@ -39770,7 +39915,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39770
39915
|
});
|
|
39771
39916
|
};
|
|
39772
39917
|
|
|
39773
|
-
const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair,
|
|
39918
|
+
const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }) => {
|
|
39774
39919
|
invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
|
|
39775
39920
|
unspentUtxos.sort((a, b) => new bn_js.BN(b.amount).cmp(new bn_js.BN(a.amount)));
|
|
39776
39921
|
const totalUnspentUtxosAmount = unspentUtxos
|
|
@@ -39817,13 +39962,14 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39817
39962
|
: vortexKeypair.encryptionKey);
|
|
39818
39963
|
// UTXO1 is a dummy UTXO for obfuscation, so we use a random Vortex keypair.
|
|
39819
39964
|
const encryptedUtxo1 = VortexKeypair.encryptUtxoFor(outputUtxo1.payload(), randomVortexKeypair.encryptionKey);
|
|
39965
|
+
const root = BigInt(merklePath0.root);
|
|
39820
39966
|
// Prepare circuit input
|
|
39821
39967
|
const input = toProveInput({
|
|
39822
39968
|
vortexObjectId,
|
|
39823
39969
|
accountSecret,
|
|
39824
39970
|
root,
|
|
39825
|
-
merklePath0,
|
|
39826
|
-
merklePath1,
|
|
39971
|
+
merklePath0: merklePath0.path,
|
|
39972
|
+
merklePath1: merklePath1.path,
|
|
39827
39973
|
publicAmount: BN254_FIELD_MODULUS - amount,
|
|
39828
39974
|
nullifier0,
|
|
39829
39975
|
nullifier1,
|
|
@@ -39867,31 +40013,34 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39867
40013
|
};
|
|
39868
40014
|
};
|
|
39869
40015
|
|
|
39870
|
-
const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair,
|
|
39871
|
-
const { tx:
|
|
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({
|
|
39872
40018
|
tx,
|
|
39873
40019
|
amount,
|
|
39874
40020
|
unspentUtxos,
|
|
39875
40021
|
vortexPool,
|
|
39876
40022
|
vortexKeypair,
|
|
39877
|
-
root,
|
|
39878
40023
|
getMerklePathFn,
|
|
39879
40024
|
relayer,
|
|
39880
40025
|
relayerFee,
|
|
39881
40026
|
vortexSdk,
|
|
39882
40027
|
accountSecret: 0n,
|
|
39883
40028
|
});
|
|
39884
|
-
const
|
|
40029
|
+
const vortexPoolObject = await vortexSdk.resolveVortexPool(pool);
|
|
40030
|
+
const zeroCoin = tx2.moveCall({
|
|
40031
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::coin::zero`,
|
|
40032
|
+
typeArguments: [vortexPoolObject.coinType],
|
|
40033
|
+
});
|
|
39885
40034
|
return vortexSdk.transact({
|
|
39886
40035
|
vortexPool: pool,
|
|
39887
|
-
tx:
|
|
40036
|
+
tx: tx2,
|
|
39888
40037
|
proof: moveProof,
|
|
39889
40038
|
extData: extData,
|
|
39890
|
-
deposit:
|
|
40039
|
+
deposit: zeroCoin,
|
|
39891
40040
|
});
|
|
39892
40041
|
};
|
|
39893
40042
|
|
|
39894
|
-
const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool,
|
|
40043
|
+
const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexSdk, vortexKeypair, vortexPool, getMerklePathFn, accountSecret, account, coinStructs, relayer = normalizeSuiAddress('0x0'), relayerFee = 0n, }) => {
|
|
39895
40044
|
const coins = coinStructs.map((coin) => ({
|
|
39896
40045
|
objectId: coin.coinObjectId,
|
|
39897
40046
|
version: coin.version,
|
|
@@ -39908,7 +40057,6 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39908
40057
|
vortexSdk,
|
|
39909
40058
|
vortexKeypair,
|
|
39910
40059
|
vortexPool,
|
|
39911
|
-
root,
|
|
39912
40060
|
getMerklePathFn,
|
|
39913
40061
|
relayer,
|
|
39914
40062
|
relayerFee,
|
|
@@ -39923,14 +40071,13 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39923
40071
|
});
|
|
39924
40072
|
};
|
|
39925
40073
|
|
|
39926
|
-
const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair,
|
|
40074
|
+
const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
|
|
39927
40075
|
const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39928
40076
|
tx,
|
|
39929
40077
|
amount,
|
|
39930
40078
|
unspentUtxos,
|
|
39931
40079
|
vortexPool,
|
|
39932
40080
|
vortexKeypair,
|
|
39933
|
-
root,
|
|
39934
40081
|
getMerklePathFn,
|
|
39935
40082
|
relayer,
|
|
39936
40083
|
relayerFee,
|
|
@@ -39947,14 +40094,13 @@ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [],
|
|
|
39947
40094
|
});
|
|
39948
40095
|
};
|
|
39949
40096
|
|
|
39950
|
-
const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair,
|
|
40097
|
+
const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }) => {
|
|
39951
40098
|
const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39952
40099
|
tx,
|
|
39953
40100
|
amount,
|
|
39954
40101
|
vortexPool,
|
|
39955
40102
|
unspentUtxos,
|
|
39956
40103
|
vortexKeypair,
|
|
39957
|
-
root,
|
|
39958
40104
|
getMerklePathFn,
|
|
39959
40105
|
relayer,
|
|
39960
40106
|
relayerFee: 0n,
|
|
@@ -39971,7 +40117,7 @@ const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUt
|
|
|
39971
40117
|
coinOutType,
|
|
39972
40118
|
});
|
|
39973
40119
|
};
|
|
39974
|
-
const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair,
|
|
40120
|
+
const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }) => {
|
|
39975
40121
|
const accountSecret = 0n;
|
|
39976
40122
|
const { extData, tx: tx3, moveProof, } = await prepareDepositProof({
|
|
39977
40123
|
tx,
|
|
@@ -39981,7 +40127,6 @@ const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPoo
|
|
|
39981
40127
|
vortexSdk,
|
|
39982
40128
|
vortexKeypair,
|
|
39983
40129
|
vortexPool,
|
|
39984
|
-
root,
|
|
39985
40130
|
getMerklePathFn,
|
|
39986
40131
|
relayer: normalizeSuiAddress('0x0'),
|
|
39987
40132
|
relayerFee: 0n,
|
|
@@ -40012,6 +40157,7 @@ exports.REGISTRY_OBJECT_ID = REGISTRY_OBJECT_ID;
|
|
|
40012
40157
|
exports.ROOT_HISTORY_SIZE = ROOT_HISTORY_SIZE;
|
|
40013
40158
|
exports.TREASURY_ADDRESS = TREASURY_ADDRESS;
|
|
40014
40159
|
exports.Utxo = Utxo;
|
|
40160
|
+
exports.VORTEX_API_URL = VORTEX_API_URL;
|
|
40015
40161
|
exports.VORTEX_PACKAGE_ID = VORTEX_PACKAGE_ID;
|
|
40016
40162
|
exports.VORTEX_POOL_IDS = VORTEX_POOL_IDS;
|
|
40017
40163
|
exports.VORTEX_SIGNATURE_DOMAIN = VORTEX_SIGNATURE_DOMAIN;
|
|
@@ -40019,6 +40165,7 @@ exports.VORTEX_SWAP_PACKAGE_ID = VORTEX_SWAP_PACKAGE_ID;
|
|
|
40019
40165
|
exports.VORTEX_SWAP_UPGRADE_CAP = VORTEX_SWAP_UPGRADE_CAP;
|
|
40020
40166
|
exports.VORTEX_UPGRADE_CAP = VORTEX_UPGRADE_CAP;
|
|
40021
40167
|
exports.Vortex = Vortex;
|
|
40168
|
+
exports.VortexAPI = VortexAPI;
|
|
40022
40169
|
exports.VortexKeypair = VortexKeypair;
|
|
40023
40170
|
exports.ZERO_VALUE = ZERO_VALUE;
|
|
40024
40171
|
exports.buildMerkleTree = buildMerkleTree;
|
|
@@ -40028,6 +40175,7 @@ exports.deserializeMerkleTree = deserializeMerkleTree;
|
|
|
40028
40175
|
exports.finishSwap = finishSwap;
|
|
40029
40176
|
exports.getMerklePath = getMerklePath;
|
|
40030
40177
|
exports.getUnspentUtxos = getUnspentUtxos;
|
|
40178
|
+
exports.getUnspentUtxosWithApi = getUnspentUtxosWithApi;
|
|
40031
40179
|
exports.merkleTreeHashFunction = merkleTreeHashFunction;
|
|
40032
40180
|
exports.parseNewCommitmentEvent = parseNewCommitmentEvent;
|
|
40033
40181
|
exports.parseVortexPool = parseVortexPool;
|
|
@@ -40039,6 +40187,7 @@ exports.prove = prove;
|
|
|
40039
40187
|
exports.startSwap = startSwap;
|
|
40040
40188
|
exports.toProveInput = toProveInput;
|
|
40041
40189
|
exports.verify = verify;
|
|
40190
|
+
exports.vortexAPI = vortexAPI;
|
|
40042
40191
|
exports.vortexSDK = vortexSDK;
|
|
40043
40192
|
exports.withdraw = withdraw;
|
|
40044
40193
|
exports.withdrawWithAccount = withdrawWithAccount;
|