|
|
@@ -0,0 +1,55 @@
|
|
|
+import { NextRequest, NextResponse } from 'next/server'
|
|
|
+import { TickMath } from '@/lib/byreal-clmm-sdk/src/instructions/utils/tickMath'
|
|
|
+
|
|
|
+export async function GET(request: NextRequest) {
|
|
|
+ try {
|
|
|
+ const searchParams = request.nextUrl.searchParams
|
|
|
+ const tickParam = searchParams.get('tick')
|
|
|
+ const decimalsAParam = searchParams.get('decimalsA')
|
|
|
+ const decimalsBParam = searchParams.get('decimalsB')
|
|
|
+ const baseInParam = searchParams.get('baseIn')
|
|
|
+
|
|
|
+ if (
|
|
|
+ tickParam === null ||
|
|
|
+ decimalsAParam === null ||
|
|
|
+ decimalsBParam === null
|
|
|
+ ) {
|
|
|
+ return NextResponse.json(
|
|
|
+ { error: 'Missing required parameters: tick, decimalsA, decimalsB' },
|
|
|
+ { status: 400 }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ const tick = parseInt(tickParam, 10)
|
|
|
+ const decimalsA = parseInt(decimalsAParam, 10)
|
|
|
+ const decimalsB = parseInt(decimalsBParam, 10)
|
|
|
+ const baseIn = baseInParam === 'false' ? false : true
|
|
|
+
|
|
|
+ if (isNaN(tick) || isNaN(decimalsA) || isNaN(decimalsB)) {
|
|
|
+ return NextResponse.json(
|
|
|
+ {
|
|
|
+ error:
|
|
|
+ 'Invalid parameter types. tick, decimalsA, and decimalsB must be numbers.',
|
|
|
+ },
|
|
|
+ { status: 400 }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ const price = TickMath.getPriceFromTick({
|
|
|
+ tick,
|
|
|
+ decimalsA,
|
|
|
+ decimalsB,
|
|
|
+ baseIn,
|
|
|
+ })
|
|
|
+
|
|
|
+ return NextResponse.json({
|
|
|
+ price: price.toString(),
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Tick to Price API Error:', error)
|
|
|
+ return NextResponse.json(
|
|
|
+ { error: 'Internal Server Error' },
|
|
|
+ { status: 500 }
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|