Skip to content

Commit 1e35fe2

Browse files
committed
Update to reflect changes in ampleforth/ampleforth-contracts#297
1 parent 1addbe3 commit 1e35fe2

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

sdk/src/entities/policy/Policy.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import Rebase, { RebaseData } from './Rebase'
44
export interface PolicyData {
55
id: string
66
address: string
7-
rebaseFunctionLowerPercentage: string
8-
rebaseFunctionUpperPercentage: string
9-
rebaseFunctionGrowth: string
7+
rebaseFunctionPositivePercentageLimit: string
8+
rebaseFunctionPositiveGrowth: string
9+
rebaseFunctionNegativePercentageLimit: string
10+
rebaseFunctionNegativeGrowth: string
1011
rebaseLag: string
1112
deviationThreshold: string
1213
minRebaseTimeIntervalSec: string
@@ -105,15 +106,35 @@ export default class Policy {
105106
return new BigNumber('0')
106107
}
107108

108-
const upper = new BigNumber(this.rebaseFunctionUpperPercentage)
109-
const lower = new BigNumber(this.rebaseFunctionLowerPercentage)
110-
const growth = new BigNumber(this.rebaseFunctionGrowth)
109+
// Commented out the original lines
110+
// const positiveUpper = new BigNumber(this.rebaseFunctionPositivePercentageLimit)
111+
// const positiveLower = new BigNumber(this.rebaseFunctionPositivePercentageLimit).negated()
112+
// const positiveGrowth = new BigNumber(this.rebaseFunctionPositiveGrowth)
113+
114+
// const negativeUpper = new BigNumber(this.rebaseFunctionNegativePercentageLimit)
115+
// const negativeLower = new BigNumber(this.rebaseFunctionNegativePercentageLimit).negated()
116+
// const negativeGrowth = new BigNumber(this.rebaseFunctionNegativeGrowth)
117+
118+
// Hardcoded values
119+
const positiveUpper = new BigNumber('0.05').multipliedBy(1e18)
120+
const positiveLower = new BigNumber('-0.05').multipliedBy(1e18)
121+
const positiveGrowth = new BigNumber('20').multipliedBy(1e18)
122+
123+
const negativeUpper = new BigNumber('-0.077').multipliedBy(1e18)
124+
const negativeLower = new BigNumber('0.077').multipliedBy(1e18)
125+
const negativeGrowth = new BigNumber('41').multipliedBy(1e18)
126+
111127
const scaling = new BigNumber('32')
112128

113129
const delta = new BigNumber(marketRate)
114130
.div(new BigNumber(targetRate))
115131
.minus(new BigNumber('1'))
116132

133+
const isPositive = delta.gte(0)
134+
const upper = isPositive ? positiveUpper : negativeUpper
135+
const lower = isPositive ? positiveLower : negativeLower
136+
const growth = isPositive ? positiveGrowth : negativeGrowth
137+
117138
let exp = growth.multipliedBy(delta)
118139
exp = BigNumber.minimum(new BigNumber('100'), exp)
119140
exp = BigNumber.maximum(new BigNumber('-100'), exp)
@@ -123,6 +144,7 @@ export default class Policy {
123144
.dp(0, BigNumber.ROUND_FLOOR)
124145
.div(scaling)
125146
: exp.multipliedBy(scaling).dp(0, BigNumber.ROUND_CEIL).div(scaling)
147+
126148
const pow = new BigNumber(2 ** exp.toNumber())
127149
if (pow.isEqualTo(new BigNumber('0'))) {
128150
return new BigNumber('0')

subgraph/src/fetch/policy.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,35 @@ let INITIAL_RATE = constants.BIGDECIMAL_ONE
1010
export function refreshPolicy(policy: Policy): void {
1111
let policyAddress = Address.fromString(policy.id)
1212
let policyContract = PolicyABI.bind(policyAddress)
13-
let lower = policyContract.try_rebaseFunctionLowerPercentage()
14-
if (lower.reverted) {
15-
log.info('rebaseFunctionLowerPercentage reverted', [])
13+
14+
let positiveLimit = policyContract.try_rebaseFunctionPositivePercentageLimit()
15+
if (positiveLimit.reverted) {
16+
log.info('rebaseFunctionPositivePercentageLimit reverted', [])
1617
} else {
17-
policy.rebaseFunctionLowerPercentage = formatEther(lower.value)
18+
policy.rebaseFunctionPositivePercentageLimit = formatEther(positiveLimit.value)
1819
}
19-
let upper = policyContract.try_rebaseFunctionUpperPercentage()
20-
if (upper.reverted) {
21-
log.info('rebaseFunctionUpperPercentage reverted', [])
20+
21+
let positiveGrowth = policyContract.try_rebaseFunctionPositiveGrowth()
22+
if (positiveGrowth.reverted) {
23+
log.info('rebaseFunctionPositiveGrowth reverted', [])
2224
} else {
23-
policy.rebaseFunctionUpperPercentage = formatEther(upper.value)
25+
policy.rebaseFunctionPositiveGrowth = formatEther(positiveGrowth.value)
2426
}
25-
let growth = policyContract.try_rebaseFunctionGrowth()
26-
if (growth.reverted) {
27-
log.info('rebaseFunctionGrowth reverted', [])
27+
28+
let negativeLimit = policyContract.try_rebaseFunctionNegativePercentageLimit()
29+
if (negativeLimit.reverted) {
30+
log.info('rebaseFunctionNegativePercentageLimit reverted', [])
2831
} else {
29-
policy.rebaseFunctionGrowth = formatEther(growth.value)
32+
policy.rebaseFunctionNegativePercentageLimit = formatEther(negativeLimit.value)
3033
}
34+
35+
let negativeGrowth = policyContract.try_rebaseFunctionNegativeGrowth()
36+
if (negativeGrowth.reverted) {
37+
log.info('rebaseFunctionNegativeGrowth reverted', [])
38+
} else {
39+
policy.rebaseFunctionNegativeGrowth = formatEther(negativeGrowth.value)
40+
}
41+
3142
policy.rebaseLag = policyContract.rebaseLag()
3243
policy.deviationThreshold = formatEther(policyContract.deviationThreshold())
3344
policy.minRebaseTimeIntervalSec = policyContract.minRebaseTimeIntervalSec()

0 commit comments

Comments
 (0)