Skip to main content

Method Signature

agent.getAPR(params: GetAPRParams): Promise<WalletAprResponse>

Description

Calculates the Annual Percentage Rate (APR) realized by an agent over a specified time period. Optionally provides sub-period breakdown for detailed analysis.

Parameters

wallet
Address
required
Smart account wallet address.
start_date
string
Start date for APR calculation (ISO datetime format).Example: "2024-01-01T00:00:00Z"
end_date
string
End date for APR calculation (ISO datetime format).Example: "2024-02-01T00:00:00Z"
use_exact_end_date
boolean
default:"false"
If true, uses the exact end_date as the last performance point.

Return Value

apr
number
Annual Percentage Rate (as a percentage, e.g., 5.25 for 5.25%).
sub_periods
WalletAprSubPeriod[]
Optional breakdown of APR by sub-periods, each containing:
  • start_date - Period start
  • end_date - Period end
  • return_ - Return for this period
  • initial_value - Value at start of period

Example

import { GizaAgent, Chain } from '@giza/agent-sdk';

const giza = new GizaAgent({ chainId: Chain.BASE });

// Get overall APR
const aprData = await giza.agent.getAPR({
  wallet: smartAccountAddress,
});

console.log(`Current APR: ${aprData.apr}%`);

// Get APR for a specific date range
const periodApr = await giza.agent.getAPR({
  wallet: smartAccountAddress,
  start_date: '2024-01-01T00:00:00Z',
  end_date: '2024-02-01T00:00:00Z',
});

console.log(`Period APR: ${periodApr.apr}%`);

// Analyze sub-periods if available
if (periodApr.sub_periods) {
  periodApr.sub_periods.forEach((period) => {
    console.log(`${period.start_date} - ${period.end_date}: ${period.return_}%`);
  });
}

Output

{
  apr: 8.25,
  sub_periods: [
    {
      start_date: '2024-01-01T00:00:00Z',
      end_date: '2024-01-15T00:00:00Z',
      return_: 0.35,
      initial_value: 1000
    },
    {
      start_date: '2024-01-15T00:00:00Z',
      end_date: '2024-02-01T00:00:00Z',
      return_: 0.38,
      initial_value: 1003.5
    }
  ]
}

Error Handling

import { ValidationError, GizaAPIError } from '@giza/agent-sdk';

try {
  const aprData = await giza.agent.getAPR({
    wallet: smartAccountAddress,
    start_date: '2024-01-01T00:00:00Z',
  });
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Invalid parameters:', error.message);
  } else if (error instanceof GizaAPIError) {
    console.error('Failed to get APR:', error.message);
  }
}

Notes

APR is calculated based on the actual returns realized by the agent, accounting for deposits and withdrawals during the period.
APR calculation requires at least two performance data points. If the agent was recently activated, the APR may not be available yet.

Next Steps