levr-sdk 0.0.1 → 0.0.2
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 +109 -13
- package/dist/esm/abis/StateView.js +149 -0
- package/dist/esm/abis/V3QuoterV2.js +26 -0
- package/dist/esm/abis/index.js +4 -0
- package/dist/esm/balance.js +30 -4
- package/dist/esm/balance.js.map +1 -1
- package/dist/esm/client/hook/use-balance.js +2 -1
- package/dist/esm/client/hook/use-balance.js.map +1 -1
- package/dist/esm/client/hook/use-fee-receivers.js +0 -1
- package/dist/esm/client/hook/use-fee-receivers.js.map +1 -1
- package/dist/esm/client/hook/use-governance.js +13 -32
- package/dist/esm/client/hook/use-governance.js.map +1 -1
- package/dist/esm/client/hook/use-project.js +7 -10
- package/dist/esm/client/hook/use-project.js.map +1 -1
- package/dist/esm/client/hook/use-proposals.js +2 -4
- package/dist/esm/client/hook/use-proposals.js.map +1 -1
- package/dist/esm/client/hook/use-stake.js +3 -23
- package/dist/esm/client/hook/use-stake.js.map +1 -1
- package/dist/esm/client/hook/use-swap.js +14 -6
- package/dist/esm/client/hook/use-swap.js.map +1 -1
- package/dist/esm/client/levr-provider.js +9 -2
- package/dist/esm/client/levr-provider.js.map +1 -1
- package/dist/esm/client/query-keys.js +1 -1
- package/dist/esm/client/query-keys.js.map +1 -1
- package/dist/esm/constants.js +41 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/fee-receivers.js +5 -2
- package/dist/esm/fee-receivers.js.map +1 -1
- package/dist/esm/governance.js +20 -5
- package/dist/esm/governance.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pool-key.js +152 -0
- package/dist/esm/pool-key.js.map +1 -0
- package/dist/esm/project.js +48 -5
- package/dist/esm/project.js.map +1 -1
- package/dist/esm/projects.js +2 -30
- package/dist/esm/projects.js.map +1 -1
- package/dist/esm/quote/index.js +98 -0
- package/dist/esm/quote/index.js.map +1 -0
- package/dist/esm/quote/v3.js +62 -0
- package/dist/esm/quote/v3.js.map +1 -0
- package/dist/esm/quote/v4.js +228 -0
- package/dist/esm/quote/v4.js.map +1 -0
- package/dist/esm/stake.js +102 -40
- package/dist/esm/stake.js.map +1 -1
- package/dist/esm/usd-price.js +149 -0
- package/dist/esm/usd-price.js.map +1 -0
- package/dist/esm/util.js +45 -1
- package/dist/esm/util.js.map +1 -1
- package/dist/types/abis/StateView.d.ts +278 -0
- package/dist/types/abis/V3QuoterV2.d.ts +39 -0
- package/dist/types/abis/index.d.ts +2 -0
- package/dist/types/balance.d.ts +4 -6
- package/dist/types/balance.d.ts.map +1 -1
- package/dist/types/client/hook/index.d.ts +1 -1
- package/dist/types/client/hook/index.d.ts.map +1 -1
- package/dist/types/client/hook/use-balance.d.ts +3 -1
- package/dist/types/client/hook/use-balance.d.ts.map +1 -1
- package/dist/types/client/hook/use-fee-receivers.d.ts +1 -1
- package/dist/types/client/hook/use-fee-receivers.d.ts.map +1 -1
- package/dist/types/client/hook/use-governance.d.ts +20 -15
- package/dist/types/client/hook/use-governance.d.ts.map +1 -1
- package/dist/types/client/hook/use-project.d.ts +3 -1
- package/dist/types/client/hook/use-project.d.ts.map +1 -1
- package/dist/types/client/hook/use-proposals.d.ts +1 -1
- package/dist/types/client/hook/use-proposals.d.ts.map +1 -1
- package/dist/types/client/hook/use-stake.d.ts +37 -132
- package/dist/types/client/hook/use-stake.d.ts.map +1 -1
- package/dist/types/client/hook/use-swap.d.ts +2 -1
- package/dist/types/client/hook/use-swap.d.ts.map +1 -1
- package/dist/types/client/levr-provider.d.ts +31 -38
- package/dist/types/client/levr-provider.d.ts.map +1 -1
- package/dist/types/client/query-keys.d.ts +1 -1
- package/dist/types/client/query-keys.d.ts.map +1 -1
- package/dist/types/constants.d.ts +18 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/fee-receivers.d.ts +1 -2
- package/dist/types/fee-receivers.d.ts.map +1 -1
- package/dist/types/governance.d.ts +8 -21
- package/dist/types/governance.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/pool-key.d.ts +121 -0
- package/dist/types/pool-key.d.ts.map +1 -0
- package/dist/types/project.d.ts +7 -12
- package/dist/types/project.d.ts.map +1 -1
- package/dist/types/projects.d.ts +1 -1
- package/dist/types/projects.d.ts.map +1 -1
- package/dist/types/quote/index.d.ts +97 -0
- package/dist/types/quote/index.d.ts.map +1 -0
- package/dist/types/quote/v3.d.ts +78 -0
- package/dist/types/quote/v3.d.ts.map +1 -0
- package/dist/types/quote/v4.d.ts +95 -0
- package/dist/types/quote/v4.d.ts.map +1 -0
- package/dist/types/stake.d.ts +38 -59
- package/dist/types/stake.d.ts.map +1 -1
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/usd-price.d.ts +141 -0
- package/dist/types/usd-price.d.ts.map +1 -0
- package/dist/types/util.d.ts +17 -0
- package/dist/types/util.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/esm/quote-v4.js +0 -169
- package/dist/esm/quote-v4.js.map +0 -1
- package/dist/types/quote-v4.d.ts +0 -54
- package/dist/types/quote-v4.d.ts.map +0 -1
package/dist/types/stake.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TransactionReceipt } from 'viem';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BalanceResult, PopPublicClient, PopWalletClient, PricingResult } from './types';
|
|
3
3
|
export type StakeConfig = {
|
|
4
4
|
wallet: PopWalletClient;
|
|
5
5
|
publicClient: PopPublicClient;
|
|
@@ -7,6 +7,7 @@ export type StakeConfig = {
|
|
|
7
7
|
tokenAddress: `0x${string}`;
|
|
8
8
|
tokenDecimals: number;
|
|
9
9
|
trustedForwarder?: `0x${string}`;
|
|
10
|
+
pricing?: PricingResult;
|
|
10
11
|
};
|
|
11
12
|
export type UnstakeParams = {
|
|
12
13
|
amount: number | string | bigint;
|
|
@@ -16,6 +17,31 @@ export type ClaimParams = {
|
|
|
16
17
|
tokens?: `0x${string}`[];
|
|
17
18
|
to?: `0x${string}`;
|
|
18
19
|
};
|
|
20
|
+
export type StakePoolData = {
|
|
21
|
+
totalStaked: BalanceResult;
|
|
22
|
+
escrowBalance: BalanceResult;
|
|
23
|
+
streamParams: {
|
|
24
|
+
windowSeconds: number;
|
|
25
|
+
streamStart: bigint;
|
|
26
|
+
streamEnd: bigint;
|
|
27
|
+
isActive: boolean;
|
|
28
|
+
};
|
|
29
|
+
rewardRatePerSecond: BalanceResult;
|
|
30
|
+
};
|
|
31
|
+
export type StakeUserData = {
|
|
32
|
+
stakedBalance: BalanceResult;
|
|
33
|
+
aprBps: {
|
|
34
|
+
raw: bigint;
|
|
35
|
+
percentage: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type StakeOutstandingRewards = {
|
|
39
|
+
available: BalanceResult;
|
|
40
|
+
pending: BalanceResult;
|
|
41
|
+
};
|
|
42
|
+
export type StakeClaimableRewards = {
|
|
43
|
+
claimable: BalanceResult;
|
|
44
|
+
};
|
|
19
45
|
export declare class Stake {
|
|
20
46
|
private wallet;
|
|
21
47
|
private publicClient;
|
|
@@ -25,6 +51,7 @@ export declare class Stake {
|
|
|
25
51
|
private chainId;
|
|
26
52
|
private userAddress;
|
|
27
53
|
private trustedForwarder?;
|
|
54
|
+
private pricing?;
|
|
28
55
|
constructor(config: StakeConfig);
|
|
29
56
|
/**
|
|
30
57
|
* Approve ERC20 tokens for spending by the staking contract
|
|
@@ -45,75 +72,27 @@ export declare class Stake {
|
|
|
45
72
|
/**
|
|
46
73
|
* Get allowance for a token and spender
|
|
47
74
|
*/
|
|
48
|
-
getAllowance(): Promise<
|
|
49
|
-
raw: bigint;
|
|
50
|
-
formatted: string;
|
|
51
|
-
}>;
|
|
75
|
+
getAllowance(): Promise<BalanceResult>;
|
|
52
76
|
/**
|
|
53
77
|
* Get pool data from staking contract
|
|
54
78
|
*/
|
|
55
|
-
getPoolData(): Promise<
|
|
56
|
-
totalStaked: {
|
|
57
|
-
raw: bigint;
|
|
58
|
-
formatted: string;
|
|
59
|
-
};
|
|
60
|
-
escrowBalance: {
|
|
61
|
-
raw: bigint;
|
|
62
|
-
formatted: string;
|
|
63
|
-
};
|
|
64
|
-
streamParams: {
|
|
65
|
-
windowSeconds: number;
|
|
66
|
-
streamStart: bigint;
|
|
67
|
-
streamEnd: bigint;
|
|
68
|
-
isActive: boolean;
|
|
69
|
-
};
|
|
70
|
-
rewardRatePerSecond: {
|
|
71
|
-
raw: bigint;
|
|
72
|
-
formatted: string;
|
|
73
|
-
};
|
|
74
|
-
}>;
|
|
79
|
+
getPoolData(): Promise<StakePoolData>;
|
|
75
80
|
/**
|
|
76
81
|
* Get user data from staking contract
|
|
77
82
|
*/
|
|
78
|
-
getUserData(): Promise<
|
|
79
|
-
stakedBalance: {
|
|
80
|
-
raw: bigint;
|
|
81
|
-
formatted: string;
|
|
82
|
-
};
|
|
83
|
-
aprBps: {
|
|
84
|
-
raw: bigint;
|
|
85
|
-
percentage: number;
|
|
86
|
-
};
|
|
87
|
-
}>;
|
|
83
|
+
getUserData(): Promise<StakeUserData>;
|
|
88
84
|
/**
|
|
89
85
|
* Get outstanding rewards for the token (for accrual purposes)
|
|
90
86
|
*/
|
|
91
|
-
getOutstandingRewards(tokenAddress?: `0x${string}`): Promise<
|
|
92
|
-
available: {
|
|
93
|
-
raw: bigint;
|
|
94
|
-
formatted: string;
|
|
95
|
-
};
|
|
96
|
-
pending: {
|
|
97
|
-
raw: bigint;
|
|
98
|
-
formatted: string;
|
|
99
|
-
};
|
|
100
|
-
}>;
|
|
87
|
+
getOutstandingRewards(tokenAddress?: `0x${string}`): Promise<StakeOutstandingRewards>;
|
|
101
88
|
/**
|
|
102
89
|
* Get claimable rewards for the current user and token
|
|
103
90
|
*/
|
|
104
|
-
getClaimableRewards(tokenAddress?: `0x${string}`): Promise<
|
|
105
|
-
claimable: {
|
|
106
|
-
raw: bigint;
|
|
107
|
-
formatted: string;
|
|
108
|
-
};
|
|
109
|
-
}>;
|
|
91
|
+
getClaimableRewards(tokenAddress?: `0x${string}`): Promise<StakeClaimableRewards>;
|
|
110
92
|
/**
|
|
111
93
|
* Get reward rate per second for a specific token
|
|
112
94
|
*/
|
|
113
|
-
getRewardRatePerSecond(tokenAddress?: `0x${string}`): Promise<
|
|
114
|
-
raw: bigint;
|
|
115
|
-
formatted: string;
|
|
116
|
-
}>;
|
|
95
|
+
getRewardRatePerSecond(tokenAddress?: `0x${string}`): Promise<BalanceResult>;
|
|
117
96
|
/**
|
|
118
97
|
* Accrue rewards by triggering automatic collection from LP locker and claiming from ClankerFeeLocker
|
|
119
98
|
*/
|
|
@@ -123,13 +102,13 @@ export declare class Stake {
|
|
|
123
102
|
*/
|
|
124
103
|
accrueAllRewards(tokenAddresses: `0x${string}`[]): Promise<TransactionReceipt>;
|
|
125
104
|
/**
|
|
126
|
-
* Calculate WETH APR using
|
|
127
|
-
*
|
|
105
|
+
* Calculate WETH APR using USD pricing data
|
|
106
|
+
* No on-chain quotes needed - uses existing pricing data
|
|
107
|
+
* Formula: (wethRewardRatePerSecond * secondsPerYear * wethPriceInTokens / totalStaked) * 10000
|
|
128
108
|
*
|
|
129
|
-
* @param poolKey - The Uniswap V4 pool key for price discovery
|
|
130
109
|
* @returns WETH APR in basis points and percentage
|
|
131
110
|
*/
|
|
132
|
-
calculateWethApr(
|
|
111
|
+
calculateWethApr(): Promise<{
|
|
133
112
|
raw: bigint;
|
|
134
113
|
percentage: number;
|
|
135
114
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stake.d.ts","sourceRoot":"","sources":["../../src/stake.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"stake.d.ts","sourceRoot":"","sources":["../../src/stake.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA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qBAAqB,CAAC;IAuCvF;;OAEG;IACG,sBAAsB,CAAC,YAAY,CAAC,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAmClF;;OAEG;IACG,aAAa,CAAC,YAAY,CAAC,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAkB9E;;OAEG;IACG,gBAAgB,CAAC,cAAc,EAAE,KAAK,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAkCpF;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC;QAChC,GAAG,EAAE,MAAM,CAAA;QACX,UAAU,EAAE,MAAM,CAAA;KACnB,CAAC;CA6DH"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -17,4 +17,19 @@ export type CallData = {
|
|
|
17
17
|
value: bigint;
|
|
18
18
|
callData: `0x${string}`;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* @description Standard balance/amount result with optional USD value
|
|
22
|
+
*/
|
|
23
|
+
export type BalanceResult = {
|
|
24
|
+
raw: bigint;
|
|
25
|
+
formatted: string;
|
|
26
|
+
usd?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @description USD pricing result
|
|
30
|
+
*/
|
|
31
|
+
export type PricingResult = {
|
|
32
|
+
wethUsd: string;
|
|
33
|
+
tokenUsd: string;
|
|
34
|
+
};
|
|
20
35
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAEjF,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;AACrE,MAAM,MAAM,eAAe,GAAG,Y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AED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { PublicClient } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* @description Parameters for getting WETH/USD price
|
|
4
|
+
*/
|
|
5
|
+
export type GetWethUsdPriceParams = {
|
|
6
|
+
/**
|
|
7
|
+
* Public client for WETH/USDC oracle queries
|
|
8
|
+
* This should connect to a chain with reliable USDC liquidity (e.g., Base mainnet)
|
|
9
|
+
*/
|
|
10
|
+
publicClient: PublicClient;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @description Return type for WETH/USD price function
|
|
14
|
+
*/
|
|
15
|
+
export type GetWethUsdPriceReturnType = {
|
|
16
|
+
/**
|
|
17
|
+
* WETH price in USD as a formatted string (e.g. "2543.21")
|
|
18
|
+
*/
|
|
19
|
+
priceUsd: string;
|
|
20
|
+
/**
|
|
21
|
+
* Raw amount of USDC received for 1 WETH (in USDC's 6 decimals)
|
|
22
|
+
*/
|
|
23
|
+
wethPerUsdc: bigint;
|
|
24
|
+
/**
|
|
25
|
+
* Fee tier of the V3 pool used (500 = 0.05%, 3000 = 0.3%, 10000 = 1%)
|
|
26
|
+
*/
|
|
27
|
+
fee: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @description Get the USD price of WETH from a WETH/USDC pool using Uniswap V3
|
|
31
|
+
*
|
|
32
|
+
* @param params Parameters for WETH/USD price oracle
|
|
33
|
+
* @returns WETH price in USD and raw quote data
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* This function queries Uniswap V3 WETH/USDC pools for accurate pricing.
|
|
37
|
+
* V3 is used instead of V4 because V3 has much deeper liquidity on most chains.
|
|
38
|
+
*
|
|
39
|
+
* The function:
|
|
40
|
+
* 1. Tries common V3 fee tiers (0.3%, 0.05%, 1%) in order of preference
|
|
41
|
+
* 2. Quotes 1 WETH to get USDC output
|
|
42
|
+
* 3. Returns the first successful quote
|
|
43
|
+
*
|
|
44
|
+
* This is commonly used as a price oracle for other token pricing calculations.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Get current WETH price on Base mainnet
|
|
49
|
+
* const { priceUsd, fee } = await getWethUsdPrice({
|
|
50
|
+
* publicClient: baseMainnetClient,
|
|
51
|
+
* })
|
|
52
|
+
* console.log(`WETH price: $${priceUsd} (from ${fee/10000}% pool)`)
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const getWethUsdPrice: ({ publicClient, }: GetWethUsdPriceParams) => Promise<GetWethUsdPriceReturnType>;
|
|
56
|
+
/**
|
|
57
|
+
* @description Parameters for getting USD price of a token
|
|
58
|
+
*/
|
|
59
|
+
export type GetUsdPriceParams = {
|
|
60
|
+
/**
|
|
61
|
+
* Public client for price oracle queries (WETH/USDC)
|
|
62
|
+
* This should connect to a chain with reliable USDC liquidity (e.g., Base mainnet)
|
|
63
|
+
*/
|
|
64
|
+
oraclePublicClient: PublicClient;
|
|
65
|
+
/**
|
|
66
|
+
* Public client for token quote queries (Token/WETH)
|
|
67
|
+
* This should connect to the chain where the token is deployed
|
|
68
|
+
*/
|
|
69
|
+
quotePublicClient: PublicClient;
|
|
70
|
+
/**
|
|
71
|
+
* Token address to get price for
|
|
72
|
+
*/
|
|
73
|
+
tokenAddress: `0x${string}`;
|
|
74
|
+
/**
|
|
75
|
+
* Optional fee tier for the token/WETH pool (in hundredths of a bip, e.g. 3000 = 0.3%)
|
|
76
|
+
* If not provided, uses defaults from pool-key module (3000 = 0.3%)
|
|
77
|
+
* Note: WETH/USDC pool is automatically discovered
|
|
78
|
+
*/
|
|
79
|
+
quoteFee?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Optional tick spacing for the token/WETH pool
|
|
82
|
+
* If not provided, uses defaults from pool-key module (60 for 0.3% fee tier)
|
|
83
|
+
* Note: WETH/USDC pool is automatically discovered
|
|
84
|
+
*/
|
|
85
|
+
quoteTickSpacing?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Optional hooks address for the token/WETH pool
|
|
88
|
+
* If not provided, uses defaults from pool-key module (zero address = no hooks)
|
|
89
|
+
* Note: WETH/USDC pool is automatically discovered
|
|
90
|
+
*/
|
|
91
|
+
quoteHooks?: `0x${string}`;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* @description Return type for USD price function
|
|
95
|
+
*/
|
|
96
|
+
export type GetUsdPriceReturnType = {
|
|
97
|
+
/**
|
|
98
|
+
* USD price of the token as a formatted string (e.g. "1234.56")
|
|
99
|
+
*/
|
|
100
|
+
priceUsd: string;
|
|
101
|
+
/**
|
|
102
|
+
* Raw price ratio of token to WETH
|
|
103
|
+
*/
|
|
104
|
+
tokenPerWeth: bigint;
|
|
105
|
+
/**
|
|
106
|
+
* Raw price ratio of WETH to USDC
|
|
107
|
+
*/
|
|
108
|
+
wethPerUsdc: bigint;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* @description Get the USD price of a token paired with WETH
|
|
112
|
+
*
|
|
113
|
+
* @param params Parameters including token addresses and chain config
|
|
114
|
+
* @returns USD price and intermediate price ratios
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* This function calculates the USD price of a token by:
|
|
118
|
+
* 1. Auto-discovering and querying a liquid WETH/USDC pool (oracle chain)
|
|
119
|
+
* 2. Getting the price of the token in WETH (quote chain)
|
|
120
|
+
* 3. Multiplying them together to get token price in USD
|
|
121
|
+
*
|
|
122
|
+
* The paired token must be WETH, otherwise an error is thrown.
|
|
123
|
+
* USD pricing always uses USDC as the stable reference.
|
|
124
|
+
*
|
|
125
|
+
* This design allows you to:
|
|
126
|
+
* - Use mainnet for accurate WETH/USDC prices (oracle auto-discovers pool)
|
|
127
|
+
* - Quote tokens from any chain (testnet, L2, etc.)
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* // Get testnet token price using mainnet oracle
|
|
132
|
+
* const { priceUsd } = await getUsdPrice({
|
|
133
|
+
* oraclePublicClient: mainnetClient,
|
|
134
|
+
* quotePublicClient: testnetClient,
|
|
135
|
+
* tokenAddress: '0x123...',
|
|
136
|
+
* })
|
|
137
|
+
* console.log(`Token price: $${priceUsd}`)
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare const getUsdPrice: ({ oraclePublicClient, quotePublicClient, tokenAddress, quoteFee, quoteTickSpacing, quoteHooks, }: GetUsdPriceParams) => Promise<GetUsdPriceReturnType>;
|
|
141
|
+
//# sourceMappingURL=usd-price.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usd-price.d.ts","sourceRoot":"","sources":["../../src/usd-price.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAOxC;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,YAAY,EAAE,YAAY,CAAA;CAC3B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,GAAU,mBAEnC,qBAAqB,KAAG,OAAO,CAAC,yBAAyB,CA0D3D,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,kBAAkB,EAAE,YAAY,CAAA;IAChC;;;OAGG;IACH,iBAAiB,EAAE,YAAY,CAAA;IAC/B;;OAEG;IACH,YAAY,EAAE,KAAK,MAAM,EAAE,CAAA;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,KAAK,MAAM,EAAE,CAAA;CAC3B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,WAAW,GAAU,kGAO/B,iBAAiB,KAAG,OAAO,CAAC,qBAAqB,CAqDnD,CAAA"}
|
package/dist/types/util.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import type { PopPublicClient } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Get a configured public client for a given chain
|
|
4
|
+
* @param chainId - The chain ID to connect to
|
|
5
|
+
* @param rpcUrl - Optional custom RPC URL (falls back to public endpoints)
|
|
6
|
+
* @returns Configured public client
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Use default public RPC
|
|
11
|
+
* const client = getPublicClient(8453)
|
|
12
|
+
*
|
|
13
|
+
* // Use custom RPC
|
|
14
|
+
* const client = getPublicClient(8453, 'https://my-rpc.com')
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function getPublicClient(chainId: number, rpcUrl?: string): PopPublicClient;
|
|
1
18
|
/**
|
|
2
19
|
* Check if approval is needed for a given amount
|
|
3
20
|
*/
|
package/dist/types/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAU9C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAsBjF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAC1C,cAAc,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EACxC,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAiBT"}
|
package/package.json
CHANGED
package/dist/esm/quote-v4.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { encodeAbiParameters, keccak256 } from "viem";
|
|
2
|
-
import { IClankerHookDynamicFee, IClankerHookStaticFee, V4Quoter } from "./abis/index.js";
|
|
3
|
-
import { UNISWAP_V4_QUOTER } from "./constants.js";
|
|
4
|
-
/**
|
|
5
|
-
* @description Try to get static fees from a Clanker hook using multicall
|
|
6
|
-
* @param publicClient Public client
|
|
7
|
-
* @param hookAddress Hook address
|
|
8
|
-
* @param poolId Pool ID
|
|
9
|
-
* @returns Static fees or undefined
|
|
10
|
-
*/
|
|
11
|
-
const tryGetStaticFees = async (publicClient, hookAddress, poolId) => {
|
|
12
|
-
try {
|
|
13
|
-
const results = await publicClient.multicall({
|
|
14
|
-
contracts: [
|
|
15
|
-
{
|
|
16
|
-
address: hookAddress,
|
|
17
|
-
abi: IClankerHookStaticFee,
|
|
18
|
-
functionName: "clankerFee",
|
|
19
|
-
args: [poolId],
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
address: hookAddress,
|
|
23
|
-
abi: IClankerHookStaticFee,
|
|
24
|
-
functionName: "pairedFee",
|
|
25
|
-
args: [poolId],
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
});
|
|
29
|
-
if (results[0].status === "success" && results[1].status === "success") {
|
|
30
|
-
return {
|
|
31
|
-
clankerFee: Number(results[0].result),
|
|
32
|
-
pairedFee: Number(results[1].result),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* @description Try to get dynamic fee configuration from a Clanker hook
|
|
43
|
-
* @param publicClient Public client
|
|
44
|
-
* @param hookAddress Hook address
|
|
45
|
-
* @param poolId Pool ID
|
|
46
|
-
* @returns Dynamic fee config or undefined
|
|
47
|
-
*/
|
|
48
|
-
const tryGetDynamicFees = async (publicClient, hookAddress, poolId) => {
|
|
49
|
-
try {
|
|
50
|
-
const config = await publicClient.readContract({
|
|
51
|
-
address: hookAddress,
|
|
52
|
-
abi: IClankerHookDynamicFee,
|
|
53
|
-
functionName: "poolConfigVars",
|
|
54
|
-
args: [poolId],
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
baseFee: Number(config.baseFee),
|
|
58
|
-
maxLpFee: Number(config.maxLpFee),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* @description Get hook fee information from Clanker hooks
|
|
67
|
-
* @param publicClient Public client
|
|
68
|
-
* @param poolKey Pool key containing hook address
|
|
69
|
-
* @returns Hook fee information or undefined
|
|
70
|
-
*/
|
|
71
|
-
const getHookFees = async (publicClient, poolKey) => {
|
|
72
|
-
// Generate pool ID for hook queries (keccak256 of abi.encode(PoolKey))
|
|
73
|
-
const poolId = keccak256(encodeAbiParameters([
|
|
74
|
-
{
|
|
75
|
-
type: "tuple",
|
|
76
|
-
components: [
|
|
77
|
-
{ name: "currency0", type: "address" },
|
|
78
|
-
{ name: "currency1", type: "address" },
|
|
79
|
-
{ name: "fee", type: "uint24" },
|
|
80
|
-
{ name: "tickSpacing", type: "int24" },
|
|
81
|
-
{ name: "hooks", type: "address" },
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
], [poolKey]));
|
|
85
|
-
// Try static fees first
|
|
86
|
-
const staticFees = await tryGetStaticFees(publicClient, poolKey.hooks, poolId);
|
|
87
|
-
if (staticFees) {
|
|
88
|
-
return {
|
|
89
|
-
type: "static",
|
|
90
|
-
clankerFee: staticFees.clankerFee,
|
|
91
|
-
pairedFee: staticFees.pairedFee,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
// Try dynamic fees
|
|
95
|
-
const dynamicFees = await tryGetDynamicFees(publicClient, poolKey.hooks, poolId);
|
|
96
|
-
if (dynamicFees) {
|
|
97
|
-
return {
|
|
98
|
-
type: "dynamic",
|
|
99
|
-
baseFee: dynamicFees.baseFee,
|
|
100
|
-
maxLpFee: dynamicFees.maxLpFee,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
return undefined;
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* @description Get a swap quote from Uniswap V4 Quoter
|
|
107
|
-
* @param params Quote parameters including pool key and amount
|
|
108
|
-
* @returns Quote result with output amount, gas estimate, and hook fees
|
|
109
|
-
*
|
|
110
|
-
* @remarks
|
|
111
|
-
* The V4Quoter uses state-changing calls that are simulated via static call.
|
|
112
|
-
* The quoter returns the expected output amount for the given input.
|
|
113
|
-
*
|
|
114
|
-
* This function works for both native ETH and ERC20 swaps:
|
|
115
|
-
* - Native ETH → Token: Quote uses WETH address, swap router handles wrapping
|
|
116
|
-
* - Token → Native ETH: Quote uses WETH address, swap router handles unwrapping
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```typescript
|
|
120
|
-
* const quote = await quoteV4({
|
|
121
|
-
* publicClient,
|
|
122
|
-
* chainId: base.id,
|
|
123
|
-
* poolKey,
|
|
124
|
-
* zeroForOne: true,
|
|
125
|
-
* amountIn: parseEther('1'),
|
|
126
|
-
* })
|
|
127
|
-
* console.log(`Output: ${formatEther(quote.amountOut)}`)
|
|
128
|
-
* console.log(`Fees:`, quote.hookFees)
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export const quoteV4 = async ({ publicClient, chainId, poolKey, zeroForOne, amountIn, hookData = "0x", }) => {
|
|
132
|
-
const quoterAddress = UNISWAP_V4_QUOTER(chainId);
|
|
133
|
-
if (!quoterAddress)
|
|
134
|
-
throw new Error("V4 Quoter address not found for chain");
|
|
135
|
-
// Always fetch hook fee information (in parallel with quote)
|
|
136
|
-
const hookFeesPromise = getHookFees(publicClient, poolKey);
|
|
137
|
-
// Call the quoter using simulateContract (static call simulation)
|
|
138
|
-
// This is equivalent to ethers.js callStatic
|
|
139
|
-
const [{ result }, hookFees] = await Promise.all([
|
|
140
|
-
publicClient.simulateContract({
|
|
141
|
-
address: quoterAddress,
|
|
142
|
-
abi: V4Quoter,
|
|
143
|
-
functionName: "quoteExactInputSingle",
|
|
144
|
-
args: [
|
|
145
|
-
{
|
|
146
|
-
poolKey: {
|
|
147
|
-
currency0: poolKey.currency0,
|
|
148
|
-
currency1: poolKey.currency1,
|
|
149
|
-
fee: poolKey.fee,
|
|
150
|
-
tickSpacing: poolKey.tickSpacing,
|
|
151
|
-
hooks: poolKey.hooks,
|
|
152
|
-
},
|
|
153
|
-
zeroForOne,
|
|
154
|
-
exactAmount: amountIn,
|
|
155
|
-
hookData,
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
}),
|
|
159
|
-
hookFeesPromise,
|
|
160
|
-
]);
|
|
161
|
-
// The quoter returns [amountOut: bigint, gasEstimate: bigint]
|
|
162
|
-
const [amountOut, gasEstimate] = result;
|
|
163
|
-
return {
|
|
164
|
-
amountOut,
|
|
165
|
-
gasEstimate,
|
|
166
|
-
hookFees,
|
|
167
|
-
};
|
|
168
|
-
};
|
|
169
|
-
//# sourceMappingURL=quote-v4.js.map
|
package/dist/esm/quote-v4.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quote-v4.js","sourceRoot":"","sources":["../../src/quote-v4.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAErD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AA6B/C;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,KAAK,EAC5B,YAA0B,EAC1B,WAA0B,EAC1B,MAAqB,EAC2C,EAAE;IAClE,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC;YAC3C,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,WAAW;oBACpB,GAAG,EAAE,qBAAqB;oBAC1B,YAAY,EAAE,YAAY;oBAC1B,IAAI,EAAE,CAAC,MAAM,CAAC;iBACf;gBACD;oBACE,OAAO,EAAE,WAAW;oBACpB,GAAG,EAAE,qBAAqB;oBAC1B,YAAY,EAAE,WAAW;oBACzB,IAAI,EAAE,CAAC,MAAM,CAAC;iBACf;aACF;SACF,CAAC,CAAA;QAEF,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACvE,OAAO;gBACL,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBACrC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;aACrC,CAAA;QACH,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAAC,MAAM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OAAO,CAAC,SAAS;wBAC5B,GAAG,EAAE,OAAO,CAAC,GAAG;wBAChB,WAAW,EAAE,OAAO,CAAC,WAAW;wBAChC,KAAK,EAAE,OAAO,CAAC,KAAK;qBACrB;oBACD,UAAU;oBACV,WAAW,EAAE,QAAQ;oBACrB,QAAQ;iBACT;aACF;SACF,CAAC;QACF,eAAe;KAChB,CAAC,CAAA;IAEF,8DAA8D;IAC9D,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,MAAM,CAAA;IAEvC,OAAO;QACL,SAAS;QACT,WAAW;QACX,QAAQ;KACT,CAAA;AACH,CAAC,CAAA"}
|
package/dist/types/quote-v4.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { PublicClient } from 'viem';
|
|
2
|
-
import type { PoolKey } from './types';
|
|
3
|
-
export type QuoteV4Params = {
|
|
4
|
-
publicClient: PublicClient;
|
|
5
|
-
chainId: number;
|
|
6
|
-
poolKey: PoolKey;
|
|
7
|
-
zeroForOne: boolean;
|
|
8
|
-
amountIn: bigint;
|
|
9
|
-
hookData?: `0x${string}`;
|
|
10
|
-
};
|
|
11
|
-
export type QuoteV4ReturnType = {
|
|
12
|
-
amountOut: bigint;
|
|
13
|
-
gasEstimate: bigint;
|
|
14
|
-
/**
|
|
15
|
-
* Fee information from Clanker hooks (if available)
|
|
16
|
-
* - Static fees: clankerFee and pairedFee in basis points
|
|
17
|
-
* - Dynamic fees: baseFee and maxLpFee in basis points
|
|
18
|
-
*/
|
|
19
|
-
hookFees?: {
|
|
20
|
-
type: 'static' | 'dynamic';
|
|
21
|
-
clankerFee?: number;
|
|
22
|
-
pairedFee?: number;
|
|
23
|
-
baseFee?: number;
|
|
24
|
-
maxLpFee?: number;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* @description Get a swap quote from Uniswap V4 Quoter
|
|
29
|
-
* @param params Quote parameters including pool key and amount
|
|
30
|
-
* @returns Quote result with output amount, gas estimate, and hook fees
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* The V4Quoter uses state-changing calls that are simulated via static call.
|
|
34
|
-
* The quoter returns the expected output amount for the given input.
|
|
35
|
-
*
|
|
36
|
-
* This function works for both native ETH and ERC20 swaps:
|
|
37
|
-
* - Native ETH → Token: Quote uses WETH address, swap router handles wrapping
|
|
38
|
-
* - Token → Native ETH: Quote uses WETH address, swap router handles unwrapping
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const quote = await quoteV4({
|
|
43
|
-
* publicClient,
|
|
44
|
-
* chainId: base.id,
|
|
45
|
-
* poolKey,
|
|
46
|
-
* zeroForOne: true,
|
|
47
|
-
* amountIn: parseEther('1'),
|
|
48
|
-
* })
|
|
49
|
-
* console.log(`Output: ${formatEther(quote.amountOut)}`)
|
|
50
|
-
* console.log(`Fees:`, quote.hookFees)
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export declare const quoteV4: ({ publicClient, chainId, poolKey, zeroForOne, amountIn, hookData, }: QuoteV4Params) => Promise<QuoteV4ReturnType>;
|
|
54
|
-
//# sourceMappingURL=quote-v4.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quote-v4.d.ts","sourceRoot":"","sources":["../../src/quote-v4.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAKxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,KAAK,MAAM,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE;QACT,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;QAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AA4HD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,OAAO,GAAU,qEAO3B,aAAa,KAAG,OAAO,CAAC,iBAAiB,CAwC3C,CAAA"}
|