Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish to prod #1378

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# backend

## 1.26.24

### Patch Changes

- 380173f: fetch staking apr from api

## 1.26.23

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion config/sonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default <NetworkData>{
},
sts: {
address: '0xe5da20f15420ad15de0fa650600afc998bbe3955',
baseApr: 0.18,
baseAprUrl: 'https://apr.soniclabs.com/current',
validatorFee: 0.15,
},
balancer: {
Expand Down
17 changes: 15 additions & 2 deletions modules/actions/sts/sync-staking-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@ import { StsSubgraphService } from '../../sources/subgraphs/sts-subgraph/sts.ser
import { Address, formatEther } from 'viem';
import { ViemClient } from '../../sources/viem-client';

interface ApiResponse {
success: boolean;
data: {
apr: number;
};
}

export async function syncStakingData(
stakingContractAddress: Address,
viemClient: ViemClient,
subgraphService: StsSubgraphService,
baseApr: number,
baseAprUrl: string,
validatorFee: number,
) {
const stakingDataOnchain = await fetchSonicStakingData(stakingContractAddress, viemClient);
const validators = await subgraphService.getAllValidators();

const response = await fetch(baseAprUrl);
const data = (await response.json()) as ApiResponse;
if (!data.success) {
throw new Error('Failed to fetch sonic staking APR');
}

const stakingApr =
(parseFloat(stakingDataOnchain.totalDelegated) / parseFloat(stakingDataOnchain.totalAssets)) *
(baseApr * (1 - validatorFee)) *
(data.data.apr * (1 - validatorFee)) *
(1 - parseFloat(stakingDataOnchain.protocolFee));

await prisma.prismaStakedSonicData.upsert({
Expand Down
6 changes: 3 additions & 3 deletions modules/controllers/sts-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export function StakedSonicController(tracer?: any) {
async syncSonicStakingData() {
const stakingContractAddress = config['SONIC'].sts!.address;
const stsSubgraphUrl = config['SONIC'].subgraphs.sts!;
const baseApr = config['SONIC'].sts!.baseApr!;
const baseAprUrl = config['SONIC'].sts!.baseAprUrl!;
const validatorFee = config['SONIC'].sts!.validatorFee;

// Guard against unconfigured chains
if (!stakingContractAddress || !stsSubgraphUrl || !baseApr || !validatorFee) {
if (!stakingContractAddress || !stsSubgraphUrl || !baseAprUrl || !validatorFee) {
throw new Error(`Chain not configured for job sonic staking data`);
}

Expand All @@ -43,7 +43,7 @@ export function StakedSonicController(tracer?: any) {
stakingContractAddress as Address,
viemClient,
stsSubgraphClient,
baseApr,
baseAprUrl,
validatorFee,
);
},
Expand Down
2 changes: 1 addition & 1 deletion modules/network/network-config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface NetworkData {
};
sts?: {
address: string;
baseApr: number;
baseAprUrl: string;
validatorFee: number;
};
bal?: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backend",
"version": "1.26.23",
"version": "1.26.24",
"description": "Backend service for Beethoven X and Balancer",
"repository": "https://github.com/balancer/backend",
"author": "Beethoven X",
Expand Down
Loading