11import { useEffect , useState } from 'react' ;
22
3- // Constants - defined inside component for Mintlify compatibility
4- const NAGA_PROD_PRICE_FEED_ADDRESS = '0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C' ;
5- const NAGA_PROD_PKP_ADDRESS = '0xaeEA5fE3654919c8Bb2b356aDCb5dF4eC082C168' ;
6- const RPC_URL = 'https://lit-chain-rpc.litprotocol.com/' ;
7-
8- // Product IDs
9- const ProductId = {
10- PkpSign : 0 ,
11- EncSign : 1 ,
12- LitAction : 2 ,
13- SignSessionKey : 3 ,
14- } ;
15-
16- // Product IDs array used for fetching prices
17- const PRODUCT_IDS = [
18- ProductId . PkpSign ,
19- ProductId . EncSign ,
20- ProductId . LitAction ,
21- ProductId . SignSessionKey ,
22- ] ;
23-
24- // Constants are now in lit-pricing-constants.js and available via window.LitPricingConstants
25-
26- // PriceFeed ABI (minimal - only functions we need)
27- const PRICE_FEED_ABI = [
28- {
29- inputs : [
30- {
31- internalType : 'uint256[]' ,
32- name : 'productIds' ,
33- type : 'uint256[]' ,
34- } ,
35- ] ,
36- name : 'baseNetworkPrices' ,
37- outputs : [
38- {
39- internalType : 'uint256[]' ,
40- name : '' ,
41- type : 'uint256[]' ,
42- } ,
43- ] ,
44- stateMutability : 'view' ,
45- type : 'function' ,
46- } ,
47- {
48- inputs : [
49- {
50- internalType : 'uint256[]' ,
51- name : 'productIds' ,
52- type : 'uint256[]' ,
53- } ,
54- ] ,
55- name : 'maxNetworkPrices' ,
56- outputs : [
57- {
58- internalType : 'uint256[]' ,
59- name : '' ,
60- type : 'uint256[]' ,
61- } ,
62- ] ,
63- stateMutability : 'view' ,
64- type : 'function' ,
65- } ,
66- {
67- inputs : [
68- {
69- internalType : 'uint256' ,
70- name : 'usagePercent' ,
71- type : 'uint256' ,
72- } ,
73- {
74- internalType : 'uint256[]' ,
75- name : 'productIds' ,
76- type : 'uint256[]' ,
77- } ,
78- ] ,
79- name : 'usagePercentToPrices' ,
80- outputs : [
81- {
82- internalType : 'uint256[]' ,
83- name : '' ,
84- type : 'uint256[]' ,
85- } ,
86- ] ,
87- stateMutability : 'view' ,
88- type : 'function' ,
89- } ,
90- {
91- inputs : [ ] ,
92- name : 'getLitActionPriceConfigs' ,
93- outputs : [
94- {
95- components : [
96- {
97- internalType : 'enum LibPriceFeedStorage.LitActionPriceComponent' ,
98- name : 'priceComponent' ,
99- type : 'uint8' ,
100- } ,
101- {
102- internalType : 'enum LibPriceFeedStorage.NodePriceMeasurement' ,
103- name : 'priceMeasurement' ,
104- type : 'uint8' ,
105- } ,
106- {
107- internalType : 'uint256' ,
108- name : 'price' ,
109- type : 'uint256' ,
110- } ,
111- ] ,
112- internalType : 'struct LibPriceFeedStorage.LitActionPriceConfig[]' ,
113- name : '' ,
114- type : 'tuple[]' ,
115- } ,
116- ] ,
117- stateMutability : 'view' ,
118- type : 'function' ,
119- } ,
120- ] ;
121-
122- // PKP Contract ABI (for mintCost)
123- const PKP_ABI = [
124- {
125- inputs : [ ] ,
126- name : 'mintCost' ,
127- outputs : [
128- {
129- internalType : 'uint256' ,
130- name : '' ,
131- type : 'uint256' ,
132- } ,
133- ] ,
134- stateMutability : 'view' ,
135- type : 'function' ,
136- } ,
137- ] ;
138-
139- // Helper functions
140- const getLitKeyPrice = async ( ) => {
141- try {
142- const response = await fetch (
143- 'https://api.coingecko.com/api/v3/simple/price?ids=lit-protocol&vs_currencies=usd'
144- ) ;
145- const data = await response . json ( ) ;
146-
147- if ( data [ 'lit-protocol' ] && data [ 'lit-protocol' ] . usd ) {
148- return data [ 'lit-protocol' ] . usd ;
149- }
150-
151- throw new Error ( 'LIT price not found in CoinGecko response' ) ;
152- } catch ( error ) {
153- console . error ( 'Error fetching LITKEY price from CoinGecko:' , error ) ;
154- return null ;
155- }
156- } ;
157-
1583export const weiToTokens = ( wei , ethers ) => {
1594 if ( ! ethers || ! ethers . utils ) {
1605 return 0 ;
@@ -170,6 +15,158 @@ export const formatPrice = (priceInTokens, priceInUSD) => {
17015} ;
17116
17217export const PriceProvider = ( { children, component : Component } ) => {
18+ // Constants - defined inside component for Mintlify compatibility
19+ const NAGA_PROD_PRICE_FEED_ADDRESS = '0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C' ;
20+ const NAGA_PROD_PKP_ADDRESS = '0xaeEA5fE3654919c8Bb2b356aDCb5dF4eC082C168' ;
21+ const RPC_URL = 'https://lit-chain-rpc.litprotocol.com/' ;
22+
23+ // Product IDs
24+ const ProductId = {
25+ PkpSign : 0 ,
26+ EncSign : 1 ,
27+ LitAction : 2 ,
28+ SignSessionKey : 3 ,
29+ } ;
30+
31+ // Product IDs array used for fetching prices
32+ const PRODUCT_IDS = [
33+ ProductId . PkpSign ,
34+ ProductId . EncSign ,
35+ ProductId . LitAction ,
36+ ProductId . SignSessionKey ,
37+ ] ;
38+
39+ // PriceFeed ABI (minimal - only functions we need)
40+ const PRICE_FEED_ABI = [
41+ {
42+ inputs : [
43+ {
44+ internalType : 'uint256[]' ,
45+ name : 'productIds' ,
46+ type : 'uint256[]' ,
47+ } ,
48+ ] ,
49+ name : 'baseNetworkPrices' ,
50+ outputs : [
51+ {
52+ internalType : 'uint256[]' ,
53+ name : '' ,
54+ type : 'uint256[]' ,
55+ } ,
56+ ] ,
57+ stateMutability : 'view' ,
58+ type : 'function' ,
59+ } ,
60+ {
61+ inputs : [
62+ {
63+ internalType : 'uint256[]' ,
64+ name : 'productIds' ,
65+ type : 'uint256[]' ,
66+ } ,
67+ ] ,
68+ name : 'maxNetworkPrices' ,
69+ outputs : [
70+ {
71+ internalType : 'uint256[]' ,
72+ name : '' ,
73+ type : 'uint256[]' ,
74+ } ,
75+ ] ,
76+ stateMutability : 'view' ,
77+ type : 'function' ,
78+ } ,
79+ {
80+ inputs : [
81+ {
82+ internalType : 'uint256' ,
83+ name : 'usagePercent' ,
84+ type : 'uint256' ,
85+ } ,
86+ {
87+ internalType : 'uint256[]' ,
88+ name : 'productIds' ,
89+ type : 'uint256[]' ,
90+ } ,
91+ ] ,
92+ name : 'usagePercentToPrices' ,
93+ outputs : [
94+ {
95+ internalType : 'uint256[]' ,
96+ name : '' ,
97+ type : 'uint256[]' ,
98+ } ,
99+ ] ,
100+ stateMutability : 'view' ,
101+ type : 'function' ,
102+ } ,
103+ {
104+ inputs : [ ] ,
105+ name : 'getLitActionPriceConfigs' ,
106+ outputs : [
107+ {
108+ components : [
109+ {
110+ internalType : 'enum LibPriceFeedStorage.LitActionPriceComponent' ,
111+ name : 'priceComponent' ,
112+ type : 'uint8' ,
113+ } ,
114+ {
115+ internalType : 'enum LibPriceFeedStorage.NodePriceMeasurement' ,
116+ name : 'priceMeasurement' ,
117+ type : 'uint8' ,
118+ } ,
119+ {
120+ internalType : 'uint256' ,
121+ name : 'price' ,
122+ type : 'uint256' ,
123+ } ,
124+ ] ,
125+ internalType : 'struct LibPriceFeedStorage.LitActionPriceConfig[]' ,
126+ name : '' ,
127+ type : 'tuple[]' ,
128+ } ,
129+ ] ,
130+ stateMutability : 'view' ,
131+ type : 'function' ,
132+ } ,
133+ ] ;
134+
135+ // PKP Contract ABI (for mintCost)
136+ const PKP_ABI = [
137+ {
138+ inputs : [ ] ,
139+ name : 'mintCost' ,
140+ outputs : [
141+ {
142+ internalType : 'uint256' ,
143+ name : '' ,
144+ type : 'uint256' ,
145+ } ,
146+ ] ,
147+ stateMutability : 'view' ,
148+ type : 'function' ,
149+ } ,
150+ ] ;
151+
152+ // Helper function to get LITKEY price
153+ const getLitKeyPrice = async ( ) => {
154+ try {
155+ const response = await fetch (
156+ 'https://api.coingecko.com/api/v3/simple/price?ids=lit-protocol&vs_currencies=usd'
157+ ) ;
158+ const data = await response . json ( ) ;
159+
160+ if ( data [ 'lit-protocol' ] && data [ 'lit-protocol' ] . usd ) {
161+ return data [ 'lit-protocol' ] . usd ;
162+ }
163+
164+ throw new Error ( 'LIT price not found in CoinGecko response' ) ;
165+ } catch ( error ) {
166+ console . error ( 'Error fetching LITKEY price from CoinGecko:' , error ) ;
167+ return null ;
168+ }
169+ } ;
173170 const [ loading , setLoading ] = useState ( true ) ;
174171 const [ error , setError ] = useState ( null ) ;
175172 const [ basePrices , setBasePrices ] = useState ( [ ] ) ;
0 commit comments