From f2107b10bbe7d3fa7fc3636234c93dfdfbc1060b Mon Sep 17 00:00:00 2001 From: keyvan Date: Thu, 26 Sep 2024 10:21:19 -0700 Subject: [PATCH 1/2] fix(staking): use Pyth units in locked accounts api --- apps/staking/src/app/api/v1/locked_accounts/route.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/staking/src/app/api/v1/locked_accounts/route.ts b/apps/staking/src/app/api/v1/locked_accounts/route.ts index 5a4a0b4728..284e708932 100644 --- a/apps/staking/src/app/api/v1/locked_accounts/route.ts +++ b/apps/staking/src/app/api/v1/locked_accounts/route.ts @@ -1,4 +1,5 @@ import { PythStakingClient } from "@pythnetwork/staking-sdk"; +import { FRACTION_PRECISION } from "@pythnetwork/staking-sdk/src/constants"; import { WalletAdapterNetwork } from "@solana/wallet-adapter-base"; import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js"; import type { NextRequest } from "next/server"; @@ -76,12 +77,12 @@ export async function GET(req: NextRequest) { const lock = await stakingClient.getUnlockSchedule(position, true); return { custodyAccount: custodyAccount.address.toBase58(), - actualAmount: Number(custodyAccount.amount), + actualAmount: Number(custodyAccount.amount) / FRACTION_PRECISION, lock: { type: lock.type, schedule: lock.schedule.map((unlock) => ({ date: unlock.date, - amount: Number(unlock.amount), + amount: Number(unlock.amount) / FRACTION_PRECISION, })), }, }; From a4b20b07b77b6a66e1643efbbe0e01c4ac3cb0f2 Mon Sep 17 00:00:00 2001 From: keyvan Date: Thu, 26 Sep 2024 10:32:23 -0700 Subject: [PATCH 2/2] fix --- apps/staking/src/app/api/v1/locked_accounts/route.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/staking/src/app/api/v1/locked_accounts/route.ts b/apps/staking/src/app/api/v1/locked_accounts/route.ts index 284e708932..47f2ad9949 100644 --- a/apps/staking/src/app/api/v1/locked_accounts/route.ts +++ b/apps/staking/src/app/api/v1/locked_accounts/route.ts @@ -1,15 +1,15 @@ import { PythStakingClient } from "@pythnetwork/staking-sdk"; -import { FRACTION_PRECISION } from "@pythnetwork/staking-sdk/src/constants"; import { WalletAdapterNetwork } from "@solana/wallet-adapter-base"; import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js"; import type { NextRequest } from "next/server"; import { z } from "zod"; import { IS_MAINNET, RPC } from "../../../../config/server"; +import { tokensToString } from "../../../../tokens"; const UnlockScheduleSchema = z.object({ date: z.date(), - amount: z.number(), + amount: z.string(), }); const LockSchema = z.object({ @@ -20,7 +20,7 @@ const LockSchema = z.object({ const ResponseSchema = z.array( z.object({ custodyAccount: z.string(), - actualAmount: z.number(), + actualAmount: z.string(), lock: LockSchema, }), ); @@ -77,12 +77,12 @@ export async function GET(req: NextRequest) { const lock = await stakingClient.getUnlockSchedule(position, true); return { custodyAccount: custodyAccount.address.toBase58(), - actualAmount: Number(custodyAccount.amount) / FRACTION_PRECISION, + actualAmount: tokensToString(custodyAccount.amount), lock: { type: lock.type, schedule: lock.schedule.map((unlock) => ({ date: unlock.date, - amount: Number(unlock.amount) / FRACTION_PRECISION, + amount: tokensToString(unlock.amount), })), }, };