From 1e35fe260846eb558199e7e028656b551129679e Mon Sep 17 00:00:00 2001 From: naguib Date: Tue, 19 Aug 2025 22:50:30 +0200 Subject: [PATCH] Update to reflect changes in https://github.com/ampleforth/ampleforth-contracts/pull/297 --- sdk/src/entities/policy/Policy.ts | 34 ++++++++++++++++++++++++------ subgraph/src/fetch/policy.ts | 35 ++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/sdk/src/entities/policy/Policy.ts b/sdk/src/entities/policy/Policy.ts index c6d5bd8..ac06c01 100644 --- a/sdk/src/entities/policy/Policy.ts +++ b/sdk/src/entities/policy/Policy.ts @@ -4,9 +4,10 @@ import Rebase, { RebaseData } from './Rebase' export interface PolicyData { id: string address: string - rebaseFunctionLowerPercentage: string - rebaseFunctionUpperPercentage: string - rebaseFunctionGrowth: string + rebaseFunctionPositivePercentageLimit: string + rebaseFunctionPositiveGrowth: string + rebaseFunctionNegativePercentageLimit: string + rebaseFunctionNegativeGrowth: string rebaseLag: string deviationThreshold: string minRebaseTimeIntervalSec: string @@ -105,15 +106,35 @@ export default class Policy { return new BigNumber('0') } - const upper = new BigNumber(this.rebaseFunctionUpperPercentage) - const lower = new BigNumber(this.rebaseFunctionLowerPercentage) - const growth = new BigNumber(this.rebaseFunctionGrowth) + // Commented out the original lines + // const positiveUpper = new BigNumber(this.rebaseFunctionPositivePercentageLimit) + // const positiveLower = new BigNumber(this.rebaseFunctionPositivePercentageLimit).negated() + // const positiveGrowth = new BigNumber(this.rebaseFunctionPositiveGrowth) + + // const negativeUpper = new BigNumber(this.rebaseFunctionNegativePercentageLimit) + // const negativeLower = new BigNumber(this.rebaseFunctionNegativePercentageLimit).negated() + // const negativeGrowth = new BigNumber(this.rebaseFunctionNegativeGrowth) + + // Hardcoded values + const positiveUpper = new BigNumber('0.05').multipliedBy(1e18) + const positiveLower = new BigNumber('-0.05').multipliedBy(1e18) + const positiveGrowth = new BigNumber('20').multipliedBy(1e18) + + const negativeUpper = new BigNumber('-0.077').multipliedBy(1e18) + const negativeLower = new BigNumber('0.077').multipliedBy(1e18) + const negativeGrowth = new BigNumber('41').multipliedBy(1e18) + const scaling = new BigNumber('32') const delta = new BigNumber(marketRate) .div(new BigNumber(targetRate)) .minus(new BigNumber('1')) + const isPositive = delta.gte(0) + const upper = isPositive ? positiveUpper : negativeUpper + const lower = isPositive ? positiveLower : negativeLower + const growth = isPositive ? positiveGrowth : negativeGrowth + let exp = growth.multipliedBy(delta) exp = BigNumber.minimum(new BigNumber('100'), exp) exp = BigNumber.maximum(new BigNumber('-100'), exp) @@ -123,6 +144,7 @@ export default class Policy { .dp(0, BigNumber.ROUND_FLOOR) .div(scaling) : exp.multipliedBy(scaling).dp(0, BigNumber.ROUND_CEIL).div(scaling) + const pow = new BigNumber(2 ** exp.toNumber()) if (pow.isEqualTo(new BigNumber('0'))) { return new BigNumber('0') diff --git a/subgraph/src/fetch/policy.ts b/subgraph/src/fetch/policy.ts index a04f792..66531ed 100644 --- a/subgraph/src/fetch/policy.ts +++ b/subgraph/src/fetch/policy.ts @@ -10,24 +10,35 @@ let INITIAL_RATE = constants.BIGDECIMAL_ONE export function refreshPolicy(policy: Policy): void { let policyAddress = Address.fromString(policy.id) let policyContract = PolicyABI.bind(policyAddress) - let lower = policyContract.try_rebaseFunctionLowerPercentage() - if (lower.reverted) { - log.info('rebaseFunctionLowerPercentage reverted', []) + + let positiveLimit = policyContract.try_rebaseFunctionPositivePercentageLimit() + if (positiveLimit.reverted) { + log.info('rebaseFunctionPositivePercentageLimit reverted', []) } else { - policy.rebaseFunctionLowerPercentage = formatEther(lower.value) + policy.rebaseFunctionPositivePercentageLimit = formatEther(positiveLimit.value) } - let upper = policyContract.try_rebaseFunctionUpperPercentage() - if (upper.reverted) { - log.info('rebaseFunctionUpperPercentage reverted', []) + + let positiveGrowth = policyContract.try_rebaseFunctionPositiveGrowth() + if (positiveGrowth.reverted) { + log.info('rebaseFunctionPositiveGrowth reverted', []) } else { - policy.rebaseFunctionUpperPercentage = formatEther(upper.value) + policy.rebaseFunctionPositiveGrowth = formatEther(positiveGrowth.value) } - let growth = policyContract.try_rebaseFunctionGrowth() - if (growth.reverted) { - log.info('rebaseFunctionGrowth reverted', []) + + let negativeLimit = policyContract.try_rebaseFunctionNegativePercentageLimit() + if (negativeLimit.reverted) { + log.info('rebaseFunctionNegativePercentageLimit reverted', []) } else { - policy.rebaseFunctionGrowth = formatEther(growth.value) + policy.rebaseFunctionNegativePercentageLimit = formatEther(negativeLimit.value) } + + let negativeGrowth = policyContract.try_rebaseFunctionNegativeGrowth() + if (negativeGrowth.reverted) { + log.info('rebaseFunctionNegativeGrowth reverted', []) + } else { + policy.rebaseFunctionNegativeGrowth = formatEther(negativeGrowth.value) + } + policy.rebaseLag = policyContract.rebaseLag() policy.deviationThreshold = formatEther(policyContract.deviationThreshold()) policy.minRebaseTimeIntervalSec = policyContract.minRebaseTimeIntervalSec()