@steerprotocol/sdk 1.19.14 → 1.19.16
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/README.md +281 -11
- package/dist/cjs/base/VaultClient.js +95 -1
- package/dist/cjs/base/VaultClient.js.map +1 -1
- package/dist/cjs/base/vault/single-asset/calculateLimitPrice.js +231 -0
- package/dist/cjs/base/vault/single-asset/calculateLimitPrice.js.map +1 -0
- package/dist/cjs/base/vault/single-asset/calculateSwapAmount.js +68 -0
- package/dist/cjs/base/vault/single-asset/calculateSwapAmount.js.map +1 -0
- package/dist/cjs/base/vault/single-asset/estimateLpTokens.js +355 -0
- package/dist/cjs/base/vault/single-asset/estimateLpTokens.js.map +1 -0
- package/dist/cjs/base/vault/single-asset/index.js +109 -0
- package/dist/cjs/base/vault/single-asset/index.js.map +1 -0
- package/dist/cjs/base/vault/single-asset/simulateSwap.js +291 -0
- package/dist/cjs/base/vault/single-asset/simulateSwap.js.map +1 -0
- package/dist/cjs/base/vault/single-asset/singleAssetDeposit.js +324 -0
- package/dist/cjs/base/vault/single-asset/singleAssetDeposit.js.map +1 -0
- package/dist/cjs/base/vault/single-asset/types.js +15 -0
- package/dist/cjs/base/vault/single-asset/types.js.map +1 -0
- package/dist/cjs/base/vault/utils.js +229 -18
- package/dist/cjs/base/vault/utils.js.map +1 -1
- package/dist/cjs/const/abis/index.js +3 -0
- package/dist/cjs/const/abis/index.js.map +1 -1
- package/dist/cjs/const/abis/quoter.js +248 -0
- package/dist/cjs/const/abis/quoter.js.map +1 -0
- package/dist/cjs/const/abis/singleTokenDeposit.js +925 -0
- package/dist/cjs/const/abis/singleTokenDeposit.js.map +1 -0
- package/dist/cjs/const/amm/configs/protocols/quickswap-integral.js +3 -0
- package/dist/cjs/const/amm/configs/protocols/quickswap-integral.js.map +1 -1
- package/dist/cjs/const/amm/configs/protocols/uniswap.js +15 -0
- package/dist/cjs/const/amm/configs/protocols/uniswap.js.map +1 -1
- package/dist/cjs/const/deployments/abis.js +277 -0
- package/dist/cjs/const/deployments/abis.js.map +1 -1
- package/dist/cjs/const/deployments/polygon.js +8 -0
- package/dist/cjs/const/deployments/polygon.js.map +1 -1
- package/dist/cjs/const/index.js +6 -5
- package/dist/cjs/const/index.js.map +1 -1
- package/dist/cjs/const/network.js.map +1 -1
- package/dist/cjs/const/quoter.js +38 -0
- package/dist/cjs/const/quoter.js.map +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/base/VaultClient.js +81 -1
- package/dist/esm/base/VaultClient.js.map +1 -1
- package/dist/esm/base/vault/single-asset/calculateLimitPrice.js +224 -0
- package/dist/esm/base/vault/single-asset/calculateLimitPrice.js.map +1 -0
- package/dist/esm/base/vault/single-asset/calculateSwapAmount.js +65 -0
- package/dist/esm/base/vault/single-asset/calculateSwapAmount.js.map +1 -0
- package/dist/esm/base/vault/single-asset/estimateLpTokens.js +350 -0
- package/dist/esm/base/vault/single-asset/estimateLpTokens.js.map +1 -0
- package/dist/esm/base/vault/single-asset/index.js +83 -0
- package/dist/esm/base/vault/single-asset/index.js.map +1 -0
- package/dist/esm/base/vault/single-asset/simulateSwap.js +285 -0
- package/dist/esm/base/vault/single-asset/simulateSwap.js.map +1 -0
- package/dist/esm/base/vault/single-asset/singleAssetDeposit.js +320 -0
- package/dist/esm/base/vault/single-asset/singleAssetDeposit.js.map +1 -0
- package/dist/esm/base/vault/single-asset/types.js +12 -0
- package/dist/esm/base/vault/single-asset/types.js.map +1 -0
- package/dist/esm/base/vault/utils.js +226 -18
- package/dist/esm/base/vault/utils.js.map +1 -1
- package/dist/esm/const/abis/index.js +3 -0
- package/dist/esm/const/abis/index.js.map +1 -1
- package/dist/esm/const/abis/quoter.js +245 -0
- package/dist/esm/const/abis/quoter.js.map +1 -0
- package/dist/esm/const/abis/singleTokenDeposit.js +922 -0
- package/dist/esm/const/abis/singleTokenDeposit.js.map +1 -0
- package/dist/esm/const/amm/configs/protocols/quickswap-integral.js +3 -0
- package/dist/esm/const/amm/configs/protocols/quickswap-integral.js.map +1 -1
- package/dist/esm/const/amm/configs/protocols/uniswap.js +15 -0
- package/dist/esm/const/amm/configs/protocols/uniswap.js.map +1 -1
- package/dist/esm/const/deployments/abis.js +277 -0
- package/dist/esm/const/deployments/abis.js.map +1 -1
- package/dist/esm/const/deployments/polygon.js +8 -0
- package/dist/esm/const/deployments/polygon.js.map +1 -1
- package/dist/esm/const/index.js +6 -5
- package/dist/esm/const/index.js.map +1 -1
- package/dist/esm/const/network.js.map +1 -1
- package/dist/esm/const/quoter.js +34 -0
- package/dist/esm/const/quoter.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/base/VaultClient.d.ts +136 -4
- package/dist/types/base/VaultClient.d.ts.map +1 -1
- package/dist/types/base/vault/single-asset/calculateLimitPrice.d.ts +59 -0
- package/dist/types/base/vault/single-asset/calculateLimitPrice.d.ts.map +1 -0
- package/dist/types/base/vault/single-asset/calculateSwapAmount.d.ts +30 -0
- package/dist/types/base/vault/single-asset/calculateSwapAmount.d.ts.map +1 -0
- package/dist/types/base/vault/single-asset/estimateLpTokens.d.ts +61 -0
- package/dist/types/base/vault/single-asset/estimateLpTokens.d.ts.map +1 -0
- package/dist/types/base/vault/single-asset/index.d.ts +80 -0
- package/dist/types/base/vault/single-asset/index.d.ts.map +1 -0
- package/dist/types/base/vault/single-asset/simulateSwap.d.ts +119 -0
- package/dist/types/base/vault/single-asset/simulateSwap.d.ts.map +1 -0
- package/dist/types/base/vault/single-asset/singleAssetDeposit.d.ts +141 -0
- package/dist/types/base/vault/single-asset/singleAssetDeposit.d.ts.map +1 -0
- package/dist/types/base/vault/single-asset/types.d.ts +167 -0
- package/dist/types/base/vault/single-asset/types.d.ts.map +1 -0
- package/dist/types/base/vault/utils.d.ts +95 -0
- package/dist/types/base/vault/utils.d.ts.map +1 -1
- package/dist/types/const/abis/index.d.ts +3 -0
- package/dist/types/const/abis/index.d.ts.map +1 -1
- package/dist/types/const/abis/quoter.d.ts +206 -0
- package/dist/types/const/abis/quoter.d.ts.map +1 -0
- package/dist/types/const/abis/singleTokenDeposit.d.ts +47 -0
- package/dist/types/const/abis/singleTokenDeposit.d.ts.map +1 -0
- package/dist/types/const/amm/configs/protocols/quickswap-integral.d.ts.map +1 -1
- package/dist/types/const/amm/configs/protocols/uniswap.d.ts.map +1 -1
- package/dist/types/const/deployments/abis.d.ts +215 -0
- package/dist/types/const/deployments/abis.d.ts.map +1 -1
- package/dist/types/const/deployments/polygon.d.ts.map +1 -1
- package/dist/types/const/index.d.ts +6 -5
- package/dist/types/const/index.d.ts.map +1 -1
- package/dist/types/const/network.d.ts +2 -0
- package/dist/types/const/network.d.ts.map +1 -1
- package/dist/types/const/quoter.d.ts +17 -0
- package/dist/types/const/quoter.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ChainId } from './chain';
|
|
2
|
+
import { getAmmConfig } from './amm';
|
|
3
|
+
/**
|
|
4
|
+
* Get the Quoter contract address for a given chain
|
|
5
|
+
* @param chain - The chain to get the Quoter address for
|
|
6
|
+
* @returns The Quoter contract address
|
|
7
|
+
* @throws Error if no Quoter address is available for the chain
|
|
8
|
+
*/
|
|
9
|
+
export function getQuoterAddress(chain) {
|
|
10
|
+
const ammConfig = getAmmConfig('');
|
|
11
|
+
// TO-DO just uniswap right now
|
|
12
|
+
const address = ammConfig.Uniswap?.QuoterV2Address?.[chain];
|
|
13
|
+
if (!address || address === '0x0000000000000000000000000000000000000000') {
|
|
14
|
+
throw new Error(`No Uniswap V3 Quoter contract available for chain: ${chain}`);
|
|
15
|
+
}
|
|
16
|
+
return address;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the Quoter contract address for a given chain ID
|
|
20
|
+
* @param chainId - The chain ID to get the Quoter address for
|
|
21
|
+
* @returns The Quoter contract address
|
|
22
|
+
* @throws Error if no Quoter address is available for the chain ID
|
|
23
|
+
*/
|
|
24
|
+
export function getQuoterAddressByChainId(chainId) {
|
|
25
|
+
// Find the chain enum value that matches the chainId
|
|
26
|
+
const chainEntry = Object.entries(ChainId).find(([, id]) => id === chainId);
|
|
27
|
+
if (!chainEntry) {
|
|
28
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
29
|
+
}
|
|
30
|
+
const [chainName] = chainEntry;
|
|
31
|
+
const chain = chainName;
|
|
32
|
+
return getQuoterAddress(chain);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=quoter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quoter.js","sourceRoot":"","sources":["../../../src/const/quoter.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAIrC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAY;IAE3C,MAAM,SAAS,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;IACnC,+BAA+B;IAC/B,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE,eAAe,EAAE,CAAC,KAAK,CAAC,CAAC;IAG5D,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,4CAA4C,EAAE,CAAC;QACzE,MAAM,IAAI,KAAK,CAAC,sDAAsD,KAAK,EAAE,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,OAAkB,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAe;IACvD,qDAAqD;IACrD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;IAE5E,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC;IAC/B,MAAM,KAAK,GAAG,SAAkB,CAAC;IAEjC,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from './types';
|
|
|
4
4
|
export * from './base/VaultClient';
|
|
5
5
|
export * from './base/SubgraphClient';
|
|
6
6
|
export * from './base/StakingClient';
|
|
7
|
+
export * from './base/vault/single-asset';
|
|
7
8
|
export { PoolClient } from './base/PoolClient';
|
|
8
9
|
export * from './const';
|
|
9
10
|
/**
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,cAAc,SAAS,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type { Address, Hash, PublicClient, WalletClient } from 'viem';
|
|
2
1
|
import { createClient } from '@steerprotocol/api-sdk';
|
|
2
|
+
import { Pool as PoolV3 } from "@uniswap/v3-sdk";
|
|
3
|
+
import type { Address, Hash, PublicClient, WalletClient } from 'viem';
|
|
3
4
|
import { SteerResponse, VaultDetailsResponse } from '../types';
|
|
4
5
|
import { SubgraphClient } from './SubgraphClient';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { PoolInstanceParams, VaultDepositParams } from './vault/deposit/types';
|
|
7
|
+
import { SingleAssetDepositClient } from './vault/single-asset';
|
|
8
|
+
import type { SingleAssetDepositParams, SingleAssetDepositPreview } from './vault/single-asset/types';
|
|
9
|
+
import { TokensFromLpResponse, VaultWithdrawParams } from './vault/withdraw/types';
|
|
10
|
+
export * from "./vault/single-asset";
|
|
8
11
|
export interface VaultApproveParams {
|
|
9
12
|
vaultAddress: Address;
|
|
10
13
|
spender: Address;
|
|
@@ -202,6 +205,7 @@ export declare class VaultClient extends SubgraphClient {
|
|
|
202
205
|
protected readonly walletClient: WalletClient;
|
|
203
206
|
private readonly depositClient;
|
|
204
207
|
private readonly withdrawClient;
|
|
208
|
+
readonly singleAssetDepositClient: SingleAssetDepositClient;
|
|
205
209
|
/**
|
|
206
210
|
* Creates a new instance of VaultClient
|
|
207
211
|
* @param publicClient - The public client for reading from the blockchain
|
|
@@ -441,5 +445,133 @@ export declare class VaultClient extends SubgraphClient {
|
|
|
441
445
|
* @param zeroForOne If true, calculates token1 amount for given token0, if false calculates token0 amount for given token1
|
|
442
446
|
*/
|
|
443
447
|
getCorrespondingTokenAmount(vaultAddress: Address, amount: bigint, zeroForOne: boolean): Promise<SteerResponse<bigint>>;
|
|
448
|
+
/**
|
|
449
|
+
* Previews a single-asset deposit by running all simulation steps
|
|
450
|
+
* This allows users to see the expected outcome before executing the transaction
|
|
451
|
+
*
|
|
452
|
+
* @param params - Single-asset deposit parameters
|
|
453
|
+
* @param poolAddress - Address of the pool (must be provided separately)
|
|
454
|
+
* @returns Promise resolving to the complete deposit preview
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```typescript
|
|
458
|
+
* const preview = await vaultClient.previewSingleAssetDeposit({
|
|
459
|
+
* assets: parseEther('100'),
|
|
460
|
+
* receiver: userAddress,
|
|
461
|
+
* vault: vaultAddress,
|
|
462
|
+
* isToken0: true,
|
|
463
|
+
* depositSlippagePercent: 5n,
|
|
464
|
+
* swapSlippageBP: 500,
|
|
465
|
+
* ammType: AMMType.UniswapV3,
|
|
466
|
+
* singleAssetDepositContract: contractAddress
|
|
467
|
+
* }, poolAddress);
|
|
468
|
+
*
|
|
469
|
+
* if (preview.success) {
|
|
470
|
+
* console.log('Expected LP tokens:', preview.data.lpEstimation.lpTokens);
|
|
471
|
+
* console.log('Swap amount:', preview.data.swapAmount);
|
|
472
|
+
* }
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
previewSingleAssetDeposit(params: SingleAssetDepositParams, poolAddress: Address): Promise<SteerResponse<SingleAssetDepositPreview>>;
|
|
476
|
+
/**
|
|
477
|
+
* Executes a single-asset deposit transaction
|
|
478
|
+
*
|
|
479
|
+
* @param params - Single-asset deposit parameters
|
|
480
|
+
* @returns Promise resolving to the transaction hash
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* const result = await vaultClient.singleAssetDeposit({
|
|
485
|
+
* assets: parseEther('100'),
|
|
486
|
+
* receiver: userAddress,
|
|
487
|
+
* vault: vaultAddress,
|
|
488
|
+
* isToken0: true,
|
|
489
|
+
* depositSlippagePercent: 5n,
|
|
490
|
+
* swapSlippageBP: 500,
|
|
491
|
+
* ammType: AMMType.UniswapV3,
|
|
492
|
+
* singleAssetDepositContract: contractAddress
|
|
493
|
+
* });
|
|
494
|
+
*
|
|
495
|
+
* if (result.success) {
|
|
496
|
+
* console.log('Transaction hash:', result.data);
|
|
497
|
+
* }
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
singleAssetDeposit(params: SingleAssetDepositParams): Promise<SteerResponse<Hash>>;
|
|
501
|
+
/**
|
|
502
|
+
* Prepares a single-asset deposit transaction without executing it
|
|
503
|
+
* Useful for batching transactions or custom execution logic
|
|
504
|
+
*
|
|
505
|
+
* @param params - Single-asset deposit parameters
|
|
506
|
+
* @returns Promise resolving to the prepared transaction data
|
|
507
|
+
*/
|
|
508
|
+
prepareSingleAssetDepositTx(params: SingleAssetDepositParams): Promise<{
|
|
509
|
+
data: {
|
|
510
|
+
address: `0x${string}` | undefined;
|
|
511
|
+
abi: ({
|
|
512
|
+
type: string;
|
|
513
|
+
inputs: never[];
|
|
514
|
+
stateMutability: string;
|
|
515
|
+
name?: undefined;
|
|
516
|
+
outputs?: undefined;
|
|
517
|
+
anonymous?: undefined;
|
|
518
|
+
} | {
|
|
519
|
+
type: string;
|
|
520
|
+
name: string;
|
|
521
|
+
inputs: {
|
|
522
|
+
name: string;
|
|
523
|
+
type: string;
|
|
524
|
+
internalType: string;
|
|
525
|
+
}[];
|
|
526
|
+
outputs: {
|
|
527
|
+
name: string;
|
|
528
|
+
type: string;
|
|
529
|
+
internalType: string;
|
|
530
|
+
}[];
|
|
531
|
+
stateMutability: string;
|
|
532
|
+
anonymous?: undefined;
|
|
533
|
+
} | {
|
|
534
|
+
type: string;
|
|
535
|
+
name: string;
|
|
536
|
+
inputs: {
|
|
537
|
+
name: string;
|
|
538
|
+
type: string;
|
|
539
|
+
indexed: boolean;
|
|
540
|
+
internalType: string;
|
|
541
|
+
}[];
|
|
542
|
+
anonymous: boolean;
|
|
543
|
+
stateMutability?: undefined;
|
|
544
|
+
outputs?: undefined;
|
|
545
|
+
} | {
|
|
546
|
+
type: string;
|
|
547
|
+
name: string;
|
|
548
|
+
inputs: {
|
|
549
|
+
name: string;
|
|
550
|
+
type: string;
|
|
551
|
+
internalType: string;
|
|
552
|
+
}[];
|
|
553
|
+
stateMutability?: undefined;
|
|
554
|
+
outputs?: undefined;
|
|
555
|
+
anonymous?: undefined;
|
|
556
|
+
})[];
|
|
557
|
+
functionName: "deposit";
|
|
558
|
+
args: readonly [bigint, `0x${string}`, `0x${string}`, boolean, bigint, number, import("./vault/single-asset").AMMType];
|
|
559
|
+
};
|
|
560
|
+
status: number;
|
|
561
|
+
success: boolean;
|
|
562
|
+
error?: undefined;
|
|
563
|
+
} | {
|
|
564
|
+
data: null;
|
|
565
|
+
status: number;
|
|
566
|
+
success: boolean;
|
|
567
|
+
error: string;
|
|
568
|
+
}>;
|
|
569
|
+
/**
|
|
570
|
+
* Validates single-asset deposit parameters
|
|
571
|
+
*
|
|
572
|
+
* @param params - Parameters to validate
|
|
573
|
+
* @throws Error if parameters are invalid
|
|
574
|
+
*/
|
|
575
|
+
validateSingleAssetDepositParams(params: SingleAssetDepositParams): void;
|
|
444
576
|
}
|
|
445
577
|
//# sourceMappingURL=VaultClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VaultClient.d.ts","sourceRoot":"","sources":["../../../src/base/VaultClient.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"VaultClient.d.ts","sourceRoot":"","sources":["../../../src/base/VaultClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAGtE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,wB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IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAuBzE;;;OAGG;IACU,eAAe,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAIxF;;;;;OAKG;IACU,2BAA2B,CACtC,YAAY,EAAE,OAAO,EACrB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAMjC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,yBAAyB,CACpC,MAAM,EAAE,wBAAwB,EAChC,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAIpD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAI/F;;;;;;OAMG;IACU,2BAA2B,CAAC,MAAM,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIzE;;;;;OAKG;IACI,gCAAgC,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI;CAIhF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import type { PublicClient } from 'viem';
|
|
3
|
+
import { SteerResponse } from '../../../types';
|
|
4
|
+
import type { CalculateLimitPriceParams, PoolSlot0 } from './types';
|
|
5
|
+
import { AMMType } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Convert BigInt to Decimal for calculations
|
|
8
|
+
*/
|
|
9
|
+
export declare function bigintToDecimal(value: bigint): Decimal;
|
|
10
|
+
/**
|
|
11
|
+
* Convert Decimal back to BigInt for return values
|
|
12
|
+
* Uses toFixed(0) to get full decimal representation without scientific notation
|
|
13
|
+
*/
|
|
14
|
+
export declare function decimalToBigint(value: Decimal): bigint;
|
|
15
|
+
/**
|
|
16
|
+
* Get quote from sqrtRatioX96 using high-precision Decimal arithmetic
|
|
17
|
+
* Equivalent to Solidity's getQuoteFromSqrtRatioX96
|
|
18
|
+
* @param sqrtRatioX96 The sqrt ratio for which to compute the quote
|
|
19
|
+
* @param baseAmount Amount of base token
|
|
20
|
+
* @param baseToken Address of base token
|
|
21
|
+
* @param quoteToken Address of quote token
|
|
22
|
+
* @returns The quote amount as Decimal
|
|
23
|
+
*/
|
|
24
|
+
export declare function getQuoteFromSqrtRatioX96(sqrtRatioX96: Decimal, baseAmount: Decimal, baseToken: `0x${string}`, quoteToken: `0x${string}`): Decimal;
|
|
25
|
+
/**
|
|
26
|
+
* Calculates the sqrt price limit for slippage protection during swaps using high-precision arithmetic
|
|
27
|
+
*
|
|
28
|
+
* @param publicClient - Viem public client for blockchain reads
|
|
29
|
+
* @param params - Parameters for limit price calculation
|
|
30
|
+
* @returns Promise resolving to the calculated sqrt price limit
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const result = await calculateLimitPrice(publicClient, {
|
|
35
|
+
* pool: '0x...',
|
|
36
|
+
* slippageBP: 500, // 5% slippage
|
|
37
|
+
* zeroForOne: true,
|
|
38
|
+
* ammType: AMMType.UniswapV3,
|
|
39
|
+
* token0: '0x...',
|
|
40
|
+
* token1: '0x...'
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* if (result.success) {
|
|
44
|
+
* console.log('Sqrt price limit:', result.data);
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function calculateLimitPrice(publicClient: PublicClient, params: CalculateLimitPriceParams): Promise<SteerResponse<bigint>>;
|
|
49
|
+
/**
|
|
50
|
+
* Gets the current pool state from slot0
|
|
51
|
+
* Currently supports UniswapV3 only
|
|
52
|
+
*
|
|
53
|
+
* @param publicClient - Viem public client for blockchain reads
|
|
54
|
+
* @param poolAddress - Address of the pool
|
|
55
|
+
* @param ammType - Type of AMM
|
|
56
|
+
* @returns Promise resolving to the pool slot0 data
|
|
57
|
+
*/
|
|
58
|
+
export declare function getPoolSlot0(publicClient: PublicClient, poolAddress: `0x${string}`, ammType: AMMType): Promise<SteerResponse<PoolSlot0>>;
|
|
59
|
+
//# sourceMappingURL=calculateLimitPrice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculateLimitPrice.d.ts","sourceRoot":"","sources":["../../../../../src/base/vault/single-asset/calculateLimitPrice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAoClC;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAItD;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,OAAO,EACrB,UAAU,EAAE,OAAO,EACnB,SAAS,EAAE,KAAK,MAAM,EAAE,EACxB,UAAU,EAAE,KAAK,MAAM,EAAE,GACxB,OAAO,CAaT;AAqED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAuDhC;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,KAAK,MAAM,EAAE,EAC1B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CA2BnC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PublicClient } from 'viem';
|
|
2
|
+
import { SteerResponse } from '../../../types';
|
|
3
|
+
import type { CalculateSwapAmountParams, SwapAmountResponse } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the amount that needs to be swapped for a single-asset deposit
|
|
6
|
+
* This function calls the smart contract's calculateSwapAmount function
|
|
7
|
+
*
|
|
8
|
+
* @param publicClient - Viem public client for blockchain reads
|
|
9
|
+
* @param params - Parameters for swap amount calculation
|
|
10
|
+
* @returns Promise resolving to swap amount and current sqrt price
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const result = await calculateSwapAmount(publicClient, {
|
|
15
|
+
* depositAmount: parseEther('100'),
|
|
16
|
+
* isToken0: true,
|
|
17
|
+
* vault: '0x...',
|
|
18
|
+
* pool: '0x...',
|
|
19
|
+
* ammType: AMMType.UniswapV3,
|
|
20
|
+
* singleAssetDepositContract: '0x...'
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* if (result.success) {
|
|
24
|
+
* console.log('Swap amount:', result.data.swapAmount);
|
|
25
|
+
* console.log('Current sqrt price:', result.data.sqrtPrice);
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function calculateSwapAmount(publicClient: PublicClient, params: CalculateSwapAmountParams): Promise<SteerResponse<SwapAmountResponse>>;
|
|
30
|
+
//# sourceMappingURL=calculateSwapAmount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculateSwapAmount.d.ts","sourceRoot":"","sources":["../../../../../src/base/vault/single-asset/calculateSwapAmount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAG7E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAuC5C"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { PublicClient } from 'viem';
|
|
2
|
+
import { SteerResponse } from '../../../types';
|
|
3
|
+
import type { EstimateLpTokensParams, LpTokenEstimationResponse } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Estimates the amount of LP tokens that will be received based on the final token amounts
|
|
6
|
+
* This calculation follows the Solidity getShares implementation from the vault contract
|
|
7
|
+
*
|
|
8
|
+
* @param publicClient - Viem public client for blockchain reads
|
|
9
|
+
* @param params - Parameters for LP token estimation
|
|
10
|
+
* @returns Promise resolving to the estimated LP tokens and final amounts
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const result = await estimateLpTokens(publicClient, {
|
|
15
|
+
* vault: '0x...',
|
|
16
|
+
* originalAssets: parseEther('100'),
|
|
17
|
+
* swapAmount: parseEther('50'),
|
|
18
|
+
* swapResult: { amount0: -parseEther('50'), amount1: parseEther('150') },
|
|
19
|
+
* isToken0: true
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* if (result.success) {
|
|
23
|
+
* console.log('Estimated LP tokens:', result.data.lpTokens);
|
|
24
|
+
* console.log('Final amount0:', result.data.finalAmount0);
|
|
25
|
+
* console.log('Final amount1:', result.data.finalAmount1);
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function estimateLpTokens(publicClient: PublicClient, params: EstimateLpTokensParams): Promise<SteerResponse<LpTokenEstimationResponse>>;
|
|
30
|
+
/**
|
|
31
|
+
* Calculates shares (LP tokens) based on deposit amounts and vault reserves
|
|
32
|
+
* This is a TypeScript implementation of the Solidity getShares function
|
|
33
|
+
*
|
|
34
|
+
* @param totalSupply - Current total supply of LP tokens
|
|
35
|
+
* @param total0 - Current balance of token0 in vault
|
|
36
|
+
* @param total1 - Current balance of token1 in vault
|
|
37
|
+
* @param amount0Desired - Desired amount of token0 to deposit
|
|
38
|
+
* @param amount1Desired - Desired amount of token1 to deposit
|
|
39
|
+
* @param amount0Min - Minimum amount of token0 (set to 0n)
|
|
40
|
+
* @param amount1Min - Minimum amount of token1 (set to 0n)
|
|
41
|
+
* @param minShares - Minimum shares required (set to 0n)
|
|
42
|
+
* @returns Object with shares, amount0Used, and amount1Used
|
|
43
|
+
*/
|
|
44
|
+
export declare function getShares(totalSupply: bigint, total0: bigint, total1: bigint, amount0Desired: bigint, amount1Desired: bigint, amount0Min: bigint, amount1Min: bigint, minShares: bigint): {
|
|
45
|
+
shares: bigint;
|
|
46
|
+
amount0Used: bigint;
|
|
47
|
+
amount1Used: bigint;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Gets the current vault reserves for both tokens
|
|
51
|
+
*
|
|
52
|
+
* @param publicClient - Viem public client for blockchain reads
|
|
53
|
+
* @param vaultAddress - Address of the vault
|
|
54
|
+
* @returns Promise resolving to [token0Balance, token1Balance, totalSupply]
|
|
55
|
+
*/
|
|
56
|
+
export declare function getVaultReserves(publicClient: PublicClient, vaultAddress: `0x${string}`): Promise<SteerResponse<{
|
|
57
|
+
token0Balance: bigint;
|
|
58
|
+
token1Balance: bigint;
|
|
59
|
+
totalSupply: bigint;
|
|
60
|
+
}>>;
|
|
61
|
+
//# sourceMappingURL=estimateLpTokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimateLpTokens.d.ts","sourceRoot":"","sources":["../../../../../src/base/vault/single-asset/estimateLpTokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,YAAY,EAAE,MAAM,MAAM,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAKjF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC,CA+JnD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACvB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAwD9D;AAiCD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,KAAK,MAAM,EAAE,GAC1B,OAAO,CAAC,aAAa,CAAC;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAuE/F"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { calculateSwapAmount } from './calculateSwapAmount';
|
|
3
|
+
export { calculateLimitPrice, getPoolSlot0 } from './calculateLimitPrice';
|
|
4
|
+
export { simulateSwap, determineSwapDirection, validateSwapParams } from './simulateSwap';
|
|
5
|
+
export { estimateLpTokens, getVaultReserves } from './estimateLpTokens';
|
|
6
|
+
export { SingleAssetDepositClient } from './singleAssetDeposit';
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview Single-Asset Deposit Module
|
|
9
|
+
*
|
|
10
|
+
* This module provides comprehensive functionality for single-asset deposits into liquidity vaults.
|
|
11
|
+
* The process allows users to deposit only one token (token0 or token1), while the contract
|
|
12
|
+
* internally performs a swap to balance the token pair before depositing into the vault.
|
|
13
|
+
*
|
|
14
|
+
* ## Architecture
|
|
15
|
+
*
|
|
16
|
+
* The single-asset deposit process is broken down into separate, testable functions:
|
|
17
|
+
*
|
|
18
|
+
* 1. **calculateSwapAmount** - Determines how much of the input token needs to be swapped
|
|
19
|
+
* 2. **calculateLimitPrice** - Calculates slippage protection limits for the internal swap
|
|
20
|
+
* 3. **simulateSwap** - Simulates the swap to preview expected output amounts
|
|
21
|
+
* 4. **estimateLpTokens** - Estimates the final LP tokens that will be received
|
|
22
|
+
* 5. **SingleAssetDepositClient** - Main orchestrator that combines all steps
|
|
23
|
+
*
|
|
24
|
+
* ## Supported AMM Types
|
|
25
|
+
*
|
|
26
|
+
* Currently supports:
|
|
27
|
+
* - UniswapV3 (fully implemented)
|
|
28
|
+
* - Algebra variants (planned for future implementation)
|
|
29
|
+
*
|
|
30
|
+
* ## Example Usage
|
|
31
|
+
*
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { SingleAssetDepositClient, AMMType } from '@steerprotocol/sdk';
|
|
34
|
+
* import { parseEther } from 'viem';
|
|
35
|
+
*
|
|
36
|
+
* // Initialize the client
|
|
37
|
+
* const client = new SingleAssetDepositClient(publicClient, walletClient);
|
|
38
|
+
*
|
|
39
|
+
* // Preview the deposit
|
|
40
|
+
* const preview = await client.previewDeposit({
|
|
41
|
+
* assets: parseEther('100'),
|
|
42
|
+
* receiver: userAddress,
|
|
43
|
+
* vault: vaultAddress,
|
|
44
|
+
* isToken0: true,
|
|
45
|
+
* depositSlippagePercent: 5n,
|
|
46
|
+
* swapSlippageBP: 500,
|
|
47
|
+
* ammType: AMMType.UniswapV3,
|
|
48
|
+
* singleAssetDepositContract: contractAddress
|
|
49
|
+
* }, poolAddress);
|
|
50
|
+
*
|
|
51
|
+
* if (preview.success) {
|
|
52
|
+
* console.log('Expected LP tokens:', preview.data.lpEstimation.lpTokens);
|
|
53
|
+
*
|
|
54
|
+
* // Execute the deposit
|
|
55
|
+
* const result = await client.deposit(params);
|
|
56
|
+
* if (result.success) {
|
|
57
|
+
* console.log('Transaction hash:', result.data);
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* ## Testing Individual Functions
|
|
63
|
+
*
|
|
64
|
+
* Each function can be tested separately:
|
|
65
|
+
*
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { calculateSwapAmount, AMMType } from '@steerprotocol/sdk';
|
|
68
|
+
*
|
|
69
|
+
* // Test swap amount calculation
|
|
70
|
+
* const result = await calculateSwapAmount(publicClient, {
|
|
71
|
+
* depositAmount: parseEther('100'),
|
|
72
|
+
* isToken0: true,
|
|
73
|
+
* vault: vaultAddress,
|
|
74
|
+
* pool: poolAddress,
|
|
75
|
+
* ammType: AMMType.UniswapV3,
|
|
76
|
+
* singleAssetDepositContract: contractAddress
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/base/vault/single-asset/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { PublicClient } from 'viem';
|
|
2
|
+
import { SteerResponse } from '../../../types';
|
|
3
|
+
import type { PoolSlot0, SimulateSwapParams, SwapSimulationResponse } from './types';
|
|
4
|
+
import { AMMType } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Simulates a swap to get the expected output amounts without executing the swap
|
|
7
|
+
* Uses Uniswap V3 Quoter contract for accurate simulation
|
|
8
|
+
*
|
|
9
|
+
* @param publicClient - Viem public client for blockchain reads
|
|
10
|
+
* @param params - Parameters for swap simulation
|
|
11
|
+
* @param chainId - Chain ID to get the appropriate Quoter address
|
|
12
|
+
* @returns Promise resolving to the simulated swap results
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const result = await simulateSwap(publicClient, {
|
|
17
|
+
* pool: '0x...',
|
|
18
|
+
* recipient: '0x...',
|
|
19
|
+
* zeroForOne: true,
|
|
20
|
+
* amountSpecified: parseEther('10'),
|
|
21
|
+
* sqrtPriceLimitX96: limitPrice,
|
|
22
|
+
* ammType: AMMType.UniswapV3,
|
|
23
|
+
* tokenIn: '0x...',
|
|
24
|
+
* tokenOut: '0x...',
|
|
25
|
+
* fee: 3000
|
|
26
|
+
* }, 137); // Polygon chain ID
|
|
27
|
+
*
|
|
28
|
+
* if (result.success) {
|
|
29
|
+
* console.log('Amount out:', result.data.amountOut);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function simulateSwap(publicClient: PublicClient, params: SimulateSwapParams, chainId: number): Promise<SteerResponse<SwapSimulationResponse>>;
|
|
34
|
+
/**
|
|
35
|
+
* Determines the swap direction based on the token being deposited
|
|
36
|
+
*
|
|
37
|
+
* @param isToken0 - true if depositing token0, false if token1
|
|
38
|
+
* @returns true if swapping token0 → token1, false otherwise
|
|
39
|
+
*/
|
|
40
|
+
export declare function determineSwapDirection(isToken0: boolean): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Validates swap simulation parameters
|
|
43
|
+
*
|
|
44
|
+
* @param params - Parameters to validate
|
|
45
|
+
* @throws Error if parameters are invalid
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateSwapParams(params: SimulateSwapParams): void;
|
|
48
|
+
/**
|
|
49
|
+
* Parameters for swap with slippage analysis
|
|
50
|
+
*/
|
|
51
|
+
export interface SwapWithSlippageParams {
|
|
52
|
+
/** Address of the pool */
|
|
53
|
+
poolAddress: string;
|
|
54
|
+
/** Address that will receive the swap output (or address(this) for simulation) */
|
|
55
|
+
recipient: string;
|
|
56
|
+
/** true if swapping token0 → token1, else false */
|
|
57
|
+
zeroForOne: boolean;
|
|
58
|
+
/** Amount to swap */
|
|
59
|
+
amountSpecified: bigint;
|
|
60
|
+
/** Slippage-adjusted limit price */
|
|
61
|
+
sqrtPriceLimitX96: bigint;
|
|
62
|
+
/** AMM type */
|
|
63
|
+
ammType: AMMType;
|
|
64
|
+
/** Input token address (required for Quoter) */
|
|
65
|
+
tokenIn: string;
|
|
66
|
+
/** Output token address (required for Quoter) */
|
|
67
|
+
tokenOut: string;
|
|
68
|
+
/** Pool fee (required for Quoter) */
|
|
69
|
+
fee: number;
|
|
70
|
+
/** Quoter contract address (optional - will use default if not provided) */
|
|
71
|
+
quoterAddress?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Response from swap simulation with slippage analysis
|
|
75
|
+
*/
|
|
76
|
+
export interface SwapWithSlippageResponse {
|
|
77
|
+
/** Current pool slot0 data */
|
|
78
|
+
currentSlot0: PoolSlot0;
|
|
79
|
+
/** Swap simulation results */
|
|
80
|
+
swapSimulation: SwapSimulationResponse;
|
|
81
|
+
/** Price slippage percentage (positive means price moved unfavorably) */
|
|
82
|
+
priceSlippagePercent: string;
|
|
83
|
+
/** Current price (derived from sqrtPriceX96) */
|
|
84
|
+
currentPrice: bigint;
|
|
85
|
+
/** Price after swap (derived from sqrtPriceX96After) */
|
|
86
|
+
priceAfter: bigint;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Simulates a swap with slippage analysis by first getting current pool state,
|
|
90
|
+
* then simulating the swap and calculating price impact
|
|
91
|
+
*
|
|
92
|
+
* @param publicClient - Viem public client for blockchain reads
|
|
93
|
+
* @param params - Parameters for swap simulation with slippage analysis
|
|
94
|
+
* @param chainId - Chain ID to get the appropriate Quoter address
|
|
95
|
+
* @returns Promise resolving to swap results with slippage analysis
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const result = await simulateSwapWithSlippage(publicClient, {
|
|
100
|
+
* poolAddress: '0x...',
|
|
101
|
+
* recipient: '0x...',
|
|
102
|
+
* zeroForOne: true,
|
|
103
|
+
* amountSpecified: parseEther('10'),
|
|
104
|
+
* sqrtPriceLimitX96: limitPrice,
|
|
105
|
+
* ammType: AMMType.UniswapV3,
|
|
106
|
+
* tokenIn: '0x...',
|
|
107
|
+
* tokenOut: '0x...',
|
|
108
|
+
* fee: 3000
|
|
109
|
+
* }, 137); // Polygon chain ID
|
|
110
|
+
*
|
|
111
|
+
* if (result.success) {
|
|
112
|
+
* console.log('Price slippage:', result.data.priceSlippagePercent, '%');
|
|
113
|
+
* console.log('Current price:', result.data.currentPrice);
|
|
114
|
+
* console.log('Price after swap:', result.data.priceAfter);
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function simulateSwapWithSlippage(publicClient: PublicClient, params: SwapWithSlippageParams, chainId: number): Promise<SteerResponse<SwapWithSlippageResponse>>;
|
|
119
|
+
//# sourceMappingURL=simulateSwap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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