@interest-protocol/vortex-sdk 4.3.0 → 6.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/__tests__/test-utils.d.ts +1 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -1
- package/dist/constants.d.ts +6 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -18
- package/dist/index.mjs.map +1 -1
- package/dist/swap.d.ts +17 -0
- package/dist/swap.d.ts.map +1 -0
- package/dist/utils/deposit.d.ts.map +1 -1
- package/dist/utils/withdraw.d.ts +4 -5
- package/dist/utils/withdraw.d.ts.map +1 -1
- package/dist/vortex.d.ts +18 -3
- package/dist/vortex.d.ts.map +1 -1
- package/dist/vortex.types.d.ts +45 -3
- 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/__tests__/test-utils.ts +4 -0
- package/src/constants.ts +12 -6
- package/src/index.ts +1 -0
- package/src/swap.ts +93 -0
- package/src/utils/deposit.ts +1 -4
- package/src/utils/withdraw.ts +2 -5
- package/src/vortex.ts +60 -3
- package/src/vortex.types.ts +50 -3
- package/src/withdraw-with-account.ts +0 -2
- package/src/withdraw.ts +0 -2
package/dist/index.mjs
CHANGED
|
@@ -3370,10 +3370,12 @@ const ERROR_CODES = {
|
|
|
3370
3370
|
13: 'Invalid relayer',
|
|
3371
3371
|
14: 'Invalid output flag',
|
|
3372
3372
|
};
|
|
3373
|
-
const VORTEX_PACKAGE_ID = '
|
|
3374
|
-
const
|
|
3375
|
-
const REGISTRY_OBJECT_ID = '
|
|
3376
|
-
const
|
|
3373
|
+
const VORTEX_PACKAGE_ID = '0xcf81b96e392f82b776ee980108357426b726c4043c838822545a307e12c5ded6';
|
|
3374
|
+
const VORTEX_UPGRADE_CAP = '0xc2d1925fd45559e09c51f5491ec96d61f9e9108c967d34fe22a053c1b307ddfc';
|
|
3375
|
+
const REGISTRY_OBJECT_ID = '0xf2c11c297e0581e0279714f6ba47e26d03d9a70756036fab5882ebc0f1d2b3b1';
|
|
3376
|
+
const VORTEX_SWAP_PACKAGE_ID = '0x2ddd33debbac3e0461b3551bb00bd40d3055ea5cd441b4fad8624dcbb095e8fb';
|
|
3377
|
+
const VORTEX_SWAP_UPGRADE_CAP = '0xec0beaf1453b0e09d92f8addf25abcfb4bc6ce43ead828914836cadc8df249a0';
|
|
3378
|
+
const INITIAL_SHARED_VERSION = '692442863';
|
|
3377
3379
|
const LSK_FETCH_OFFSET = 'fetch_offset';
|
|
3378
3380
|
const LSK_ENCRYPTED_OUTPUTS = 'encrypted_outputs';
|
|
3379
3381
|
const VORTEX_SIGNATURE_DOMAIN = 'VORTEXFI.XYZ';
|
|
@@ -3382,7 +3384,7 @@ const TREASURY_ADDRESS = '0x894261575b948c035d002adc3ca4d73c683c01a1bfafac183870
|
|
|
3382
3384
|
const DEPOSIT_FEE_IN_BASIS_POINTS = 50n;
|
|
3383
3385
|
const BASIS_POINTS = 10000n;
|
|
3384
3386
|
const VORTEX_POOL_IDS = {
|
|
3385
|
-
[SUI_TYPE_ARG]: '
|
|
3387
|
+
[SUI_TYPE_ARG]: '0x1e3672f35853fccded923505434b5138543829231f025120d57fda95b86b504c',
|
|
3386
3388
|
};
|
|
3387
3389
|
|
|
3388
3390
|
/******************************************************************************
|
|
@@ -39317,7 +39319,7 @@ const parseVortexPool = (data) => {
|
|
|
39317
39319
|
|
|
39318
39320
|
var _Vortex_instances, _Vortex_suiClient, _Vortex_newPoolEventType, _Vortex_newAccountEventType, _Vortex_newCommitmentEventType, _Vortex_nullifierSpentEventType, _Vortex_newEncryptionKeyEventType, _Vortex_getVortexPool;
|
|
39319
39321
|
class Vortex {
|
|
39320
|
-
constructor({ registry, packageId, fullNodeUrl = getFullnodeUrl('devnet'), }) {
|
|
39322
|
+
constructor({ registry, packageId, swapPackageId, fullNodeUrl = getFullnodeUrl('devnet'), }) {
|
|
39321
39323
|
_Vortex_instances.add(this);
|
|
39322
39324
|
_Vortex_suiClient.set(this, void 0);
|
|
39323
39325
|
_Vortex_newPoolEventType.set(this, void 0);
|
|
@@ -39333,6 +39335,7 @@ class Vortex {
|
|
|
39333
39335
|
__classPrivateFieldSet(this, _Vortex_newCommitmentEventType, `${packageId}::vortex_events::NewCommitment`, "f");
|
|
39334
39336
|
__classPrivateFieldSet(this, _Vortex_nullifierSpentEventType, `${packageId}::vortex_events::NullifierSpent`, "f");
|
|
39335
39337
|
__classPrivateFieldSet(this, _Vortex_newEncryptionKeyEventType, `${packageId}::vortex_events::NewEncryptionKey`, "f");
|
|
39338
|
+
this.swapPackageId = swapPackageId;
|
|
39336
39339
|
this.packageId = packageId;
|
|
39337
39340
|
this.registry = registry;
|
|
39338
39341
|
}
|
|
@@ -39414,11 +39417,10 @@ class Vortex {
|
|
|
39414
39417
|
invariant(result[0], 'Encryption key devInspectAndGetReturnValues failed');
|
|
39415
39418
|
return result[0][0];
|
|
39416
39419
|
}
|
|
39417
|
-
newExtData({ tx = new Transaction(),
|
|
39420
|
+
newExtData({ tx = new Transaction(), value, action, relayer, relayerFee, encryptedOutput1, encryptedOutput0, }) {
|
|
39418
39421
|
const extData = tx.moveCall({
|
|
39419
39422
|
target: `${this.packageId}::vortex_ext_data::new`,
|
|
39420
39423
|
arguments: [
|
|
39421
|
-
tx.pure.address(recipient),
|
|
39422
39424
|
tx.pure.u64(value),
|
|
39423
39425
|
tx.pure.bool(action === Action.Deposit), // true for deposit, false for withdraw
|
|
39424
39426
|
tx.pure.address(relayer),
|
|
@@ -39548,6 +39550,36 @@ class Vortex {
|
|
|
39548
39550
|
invariant(result[0], 'Is nullifier spent devInspectAndGetReturnValues failed');
|
|
39549
39551
|
return result.flat();
|
|
39550
39552
|
}
|
|
39553
|
+
async startSwap({ tx = new Transaction(), vortex, proof, extData, relayer, minAmountOut, coinOutType, }) {
|
|
39554
|
+
const vortexPool = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortex);
|
|
39555
|
+
const [receipt, coinIn] = tx.moveCall({
|
|
39556
|
+
target: `${this.swapPackageId}::vortex_swap::start_swap`,
|
|
39557
|
+
arguments: [
|
|
39558
|
+
tx.object(vortexPool.objectId),
|
|
39559
|
+
proof,
|
|
39560
|
+
extData,
|
|
39561
|
+
tx.pure.address(relayer),
|
|
39562
|
+
tx.pure.u64(minAmountOut),
|
|
39563
|
+
],
|
|
39564
|
+
typeArguments: [vortexPool.coinType, coinOutType],
|
|
39565
|
+
});
|
|
39566
|
+
return { tx, receipt, coinIn };
|
|
39567
|
+
}
|
|
39568
|
+
async finishSwap({ tx = new Transaction(), vortex, coinOut, proof, extData, receipt, coinInType, }) {
|
|
39569
|
+
const vortexPool = await __classPrivateFieldGet(this, _Vortex_instances, "m", _Vortex_getVortexPool).call(this, vortex);
|
|
39570
|
+
tx.moveCall({
|
|
39571
|
+
target: `${this.swapPackageId}::vortex_swap::finish_swap`,
|
|
39572
|
+
arguments: [
|
|
39573
|
+
tx.object(vortexPool.objectId),
|
|
39574
|
+
coinOut,
|
|
39575
|
+
receipt,
|
|
39576
|
+
proof,
|
|
39577
|
+
extData,
|
|
39578
|
+
],
|
|
39579
|
+
typeArguments: [coinInType, vortexPool.coinType],
|
|
39580
|
+
});
|
|
39581
|
+
return { tx };
|
|
39582
|
+
}
|
|
39551
39583
|
async getVortexPool(objectId) {
|
|
39552
39584
|
const objectResponse = await __classPrivateFieldGet(this, _Vortex_suiClient, "f").getObject({
|
|
39553
39585
|
id: objectId,
|
|
@@ -39597,7 +39629,8 @@ const vortexSDK = new Vortex({
|
|
|
39597
39629
|
objectId: REGISTRY_OBJECT_ID,
|
|
39598
39630
|
initialSharedVersion: INITIAL_SHARED_VERSION,
|
|
39599
39631
|
},
|
|
39600
|
-
|
|
39632
|
+
swapPackageId: VORTEX_SWAP_PACKAGE_ID,
|
|
39633
|
+
fullNodeUrl: getFullnodeUrl('testnet'),
|
|
39601
39634
|
});
|
|
39602
39635
|
|
|
39603
39636
|
// packages/vortex/src/entities/merkle-tree.ts
|
|
@@ -39609,7 +39642,6 @@ const buildMerkleTree = () => new MerkleTree(MERKLE_TREE_HEIGHT, [], {
|
|
|
39609
39642
|
const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vortexSdk, vortexKeypair, vortexPool, root, getMerklePathFn, relayer, relayerFee, }) => {
|
|
39610
39643
|
const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
|
|
39611
39644
|
// Deposits we do not need a recipient, so we use a random one.
|
|
39612
|
-
const randomRecipient = normalizeSuiAddress(Ed25519Keypair.generate().toSuiAddress());
|
|
39613
39645
|
const randomVortexKeypair = VortexKeypair.generate();
|
|
39614
39646
|
// Determine input UTXOs
|
|
39615
39647
|
const inputUtxo0 = unspentUtxos.length > 0 && unspentUtxos[0].amount > 0n
|
|
@@ -39677,7 +39709,6 @@ const prepareDepositProof = async ({ tx, amount, accountSecret, unspentUtxos, vo
|
|
|
39677
39709
|
invariant(verify(proofJson), 'Proof verification failed');
|
|
39678
39710
|
const { extData, tx: tx2 } = vortexSdk.newExtData({
|
|
39679
39711
|
tx,
|
|
39680
|
-
recipient: randomRecipient,
|
|
39681
39712
|
value: amount,
|
|
39682
39713
|
action: Action.Deposit,
|
|
39683
39714
|
relayer,
|
|
@@ -39735,7 +39766,7 @@ const deposit = async ({ tx = new Transaction(), amount, unspentUtxos = [], vort
|
|
|
39735
39766
|
});
|
|
39736
39767
|
};
|
|
39737
39768
|
|
|
39738
|
-
const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn,
|
|
39769
|
+
const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, accountSecret, }) => {
|
|
39739
39770
|
invariant(unspentUtxos.length >= 1, 'Must have at least 1 unspent UTXO');
|
|
39740
39771
|
unspentUtxos.sort((a, b) => new BN(b.amount).cmp(new BN(a.amount)));
|
|
39741
39772
|
const totalUnspentUtxosAmount = unspentUtxos
|
|
@@ -39805,7 +39836,6 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39805
39836
|
invariant(verify(proofJson), 'Proof verification failed');
|
|
39806
39837
|
const { extData, tx: tx2 } = vortexSdk.newExtData({
|
|
39807
39838
|
tx,
|
|
39808
|
-
recipient,
|
|
39809
39839
|
value: amount,
|
|
39810
39840
|
action: Action.Withdraw,
|
|
39811
39841
|
relayer: normalizeSuiAddress(relayer),
|
|
@@ -39833,7 +39863,7 @@ const prepareWithdraw = async ({ tx = new Transaction(), amount, unspentUtxos =
|
|
|
39833
39863
|
};
|
|
39834
39864
|
};
|
|
39835
39865
|
|
|
39836
|
-
const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn,
|
|
39866
|
+
const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, }) => {
|
|
39837
39867
|
const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39838
39868
|
tx,
|
|
39839
39869
|
amount,
|
|
@@ -39842,7 +39872,6 @@ const withdraw = async ({ tx = new Transaction(), amount, unspentUtxos = [], vor
|
|
|
39842
39872
|
vortexKeypair,
|
|
39843
39873
|
root,
|
|
39844
39874
|
getMerklePathFn,
|
|
39845
|
-
recipient,
|
|
39846
39875
|
relayer,
|
|
39847
39876
|
relayerFee,
|
|
39848
39877
|
vortexSdk,
|
|
@@ -39890,7 +39919,7 @@ const depositWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], v
|
|
|
39890
39919
|
});
|
|
39891
39920
|
};
|
|
39892
39921
|
|
|
39893
|
-
const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn,
|
|
39922
|
+
const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [], vortexPool, vortexKeypair, root, getMerklePathFn, relayer, relayerFee, vortexSdk, account, accountSecret, amount, }) => {
|
|
39894
39923
|
const { tx: tx3, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39895
39924
|
tx,
|
|
39896
39925
|
amount,
|
|
@@ -39899,7 +39928,6 @@ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [],
|
|
|
39899
39928
|
vortexKeypair,
|
|
39900
39929
|
root,
|
|
39901
39930
|
getMerklePathFn,
|
|
39902
|
-
recipient,
|
|
39903
39931
|
relayer,
|
|
39904
39932
|
relayerFee,
|
|
39905
39933
|
vortexSdk,
|
|
@@ -39915,5 +39943,55 @@ const withdrawWithAccount = async ({ tx = new Transaction(), unspentUtxos = [],
|
|
|
39915
39943
|
});
|
|
39916
39944
|
};
|
|
39917
39945
|
|
|
39918
|
-
|
|
39946
|
+
const startSwap = async ({ tx = new Transaction(), amount, vortexPool, unspentUtxos, vortexKeypair, root, getMerklePathFn, relayer, minAmountOut, vortexSdk, coinOutType, }) => {
|
|
39947
|
+
const { tx: tx2, moveProof, extData, vortexPool: pool, } = await prepareWithdraw({
|
|
39948
|
+
tx,
|
|
39949
|
+
amount,
|
|
39950
|
+
vortexPool,
|
|
39951
|
+
unspentUtxos,
|
|
39952
|
+
vortexKeypair,
|
|
39953
|
+
root,
|
|
39954
|
+
getMerklePathFn,
|
|
39955
|
+
relayer,
|
|
39956
|
+
relayerFee: 0n,
|
|
39957
|
+
vortexSdk,
|
|
39958
|
+
accountSecret: 0n,
|
|
39959
|
+
});
|
|
39960
|
+
return vortexSdk.startSwap({
|
|
39961
|
+
tx: tx2,
|
|
39962
|
+
vortex: pool,
|
|
39963
|
+
proof: moveProof,
|
|
39964
|
+
extData,
|
|
39965
|
+
relayer,
|
|
39966
|
+
minAmountOut,
|
|
39967
|
+
coinOutType,
|
|
39968
|
+
});
|
|
39969
|
+
};
|
|
39970
|
+
const finishSwap = async ({ tx = new Transaction(), amount, vortexSdk, vortexPool, vortexKeypair, root, getMerklePathFn, unspentUtxos, coinOut, receipt, coinInType, }) => {
|
|
39971
|
+
const accountSecret = 0n;
|
|
39972
|
+
const { extData, tx: tx3, moveProof, } = await prepareDepositProof({
|
|
39973
|
+
tx,
|
|
39974
|
+
amount,
|
|
39975
|
+
accountSecret,
|
|
39976
|
+
unspentUtxos: unspentUtxos ?? [],
|
|
39977
|
+
vortexSdk,
|
|
39978
|
+
vortexKeypair,
|
|
39979
|
+
vortexPool,
|
|
39980
|
+
root,
|
|
39981
|
+
getMerklePathFn,
|
|
39982
|
+
relayer: normalizeSuiAddress('0x0'),
|
|
39983
|
+
relayerFee: 0n,
|
|
39984
|
+
});
|
|
39985
|
+
return vortexSdk.finishSwap({
|
|
39986
|
+
tx: tx3,
|
|
39987
|
+
vortex: vortexPool,
|
|
39988
|
+
coinOut: coinOut,
|
|
39989
|
+
proof: moveProof,
|
|
39990
|
+
extData,
|
|
39991
|
+
receipt,
|
|
39992
|
+
coinInType,
|
|
39993
|
+
});
|
|
39994
|
+
};
|
|
39995
|
+
|
|
39996
|
+
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, finishSwap, getMerklePath, getUnspentUtxos, parseNewCommitmentEvent, parseVortexPool, poseidon1, poseidon2, poseidon3, poseidon4, prove, startSwap, toProveInput, verify, vortexSDK, withdraw, withdrawWithAccount };
|
|
39919
39997
|
//# sourceMappingURL=index.mjs.map
|