Skip to content

Commit

Permalink
[protocol] Rename infrastructureFraction to proposerFraction
Browse files Browse the repository at this point in the history
  • Loading branch information
mcortesi committed Oct 1, 2019
1 parent 4416f95 commit 128d032
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 37 deletions.
12 changes: 4 additions & 8 deletions packages/contractkit/src/wrappers/GasPriceMinimum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface GasPriceMinimumConfig {
gasPriceMinimum: BigNumber
targetDensity: BigNumber
adjustmentSpeed: BigNumber
infrastructureFraction: BigNumber
proposerFraction: BigNumber
}

/**
Expand All @@ -33,11 +33,7 @@ export class GasPriceMinimumWrapper extends BaseWrapper<GasPriceMinimum> {
* @returns current fraction of the gas price minimum which is sent to
* the infrastructure fund
*/
infrastructureFraction = proxyCall(
this.contract.methods.infrastructureFraction,
undefined,
toBigNumber
)
proposerFraction = proxyCall(this.contract.methods.proposerFraction, undefined, toBigNumber)
/**
* Returns current configuration parameters.
*/
Expand All @@ -46,13 +42,13 @@ export class GasPriceMinimumWrapper extends BaseWrapper<GasPriceMinimum> {
this.gasPriceMinimum(),
this.targetDensity(),
this.adjustmentSpeed(),
this.infrastructureFraction(),
this.proposerFraction(),
])
return {
gasPriceMinimum: res[0],
targetDensity: res[1],
adjustmentSpeed: res[2],
infrastructureFraction: res[3],
proposerFraction: res[3],
}
}
}
22 changes: 11 additions & 11 deletions packages/protocol/contracts/common/GasPriceMinimum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ contract GasPriceMinimum is Ownable, Initializable, UsingRegistry {
uint256 adjustmentSpeed
);

event InfrastructureFractionSet(
uint256 infrastructureFraction
event ProposerFractionSet(
uint256 proposerFraction
);

uint256 public gasPriceMinimum;
Expand All @@ -35,10 +35,10 @@ contract GasPriceMinimum is Ownable, Initializable, UsingRegistry {
FixidityLib.Fraction public adjustmentSpeed;

// FixidityLib.Fraction of the gas price minimum allocated to the infrastructure fund.
FixidityLib.Fraction public infrastructureFraction;
FixidityLib.Fraction public proposerFraction;

function infrastructureFraction_() external view returns (uint256, uint256) {
return (infrastructureFraction.unwrap(), FixidityLib.fixed1().unwrap());
function proposerFraction_() external view returns (uint256, uint256) {
return (proposerFraction.unwrap(), FixidityLib.fixed1().unwrap());
}

modifier onlyVm() {
Expand All @@ -51,7 +51,7 @@ contract GasPriceMinimum is Ownable, Initializable, UsingRegistry {
uint256 initialGas,
uint256 _targetDensity,
uint256 _adjustmentSpeed,
uint256 _infrastructureFraction
uint256 _proposerFraction
)
external
initializer
Expand All @@ -61,7 +61,7 @@ contract GasPriceMinimum is Ownable, Initializable, UsingRegistry {
gasPriceMinimum = initialGas;
setTargetDensity(_targetDensity);
setAdjustmentSpeed(_adjustmentSpeed);
setInfrastructureFraction(_infrastructureFraction);
setProposerFraction(_proposerFraction);
}

/**
Expand Down Expand Up @@ -89,10 +89,10 @@ contract GasPriceMinimum is Ownable, Initializable, UsingRegistry {
* the infrastructure fund.
* @dev Value is expected to be < 1.
*/
function setInfrastructureFraction(uint256 _infrastructureFraction) public onlyOwner {
infrastructureFraction = FixidityLib.wrap(_infrastructureFraction);
require(infrastructureFraction.lt(FixidityLib.fixed1()));
emit InfrastructureFractionSet(_infrastructureFraction);
function setProposerFraction(uint256 _proposerFraction) public onlyOwner {
proposerFraction = FixidityLib.wrap(_proposerFraction);
require(proposerFraction.lt(FixidityLib.fixed1()));
emit ProposerFractionSet(_proposerFraction);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/migrations/06_gaspriceminimum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const initializeArgs = async (): Promise<any[]> => {
config.gasPriceMinimum.initialMinimum,
toFixed(config.gasPriceMinimum.targetDensity).toString(),
toFixed(config.gasPriceMinimum.adjustmentSpeed).toString(),
toFixed(config.gasPriceMinimum.infrastructureFraction).toString(),
toFixed(config.gasPriceMinimum.proposerFraction).toString(),
]
}

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/migrationsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const DefaultConfig = {
initialMinimum: 10000,
targetDensity: 1 / 2,
adjustmentSpeed: 1 / 2,
infrastructureFraction: 1 / 2,
proposerFraction: 1 / 2,
},
registry: {
predeployedProxyAddress: '0x000000000000000000000000000000000000ce10',
Expand Down
32 changes: 16 additions & 16 deletions packages/protocol/test/common/gaspriceminimum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract('GasPriceMinimum', (accounts: string[]) => {
const initialGasPriceMinimum = new BigNumber(500)
const targetDensity = toFixed(1 / 2)
const adjustmentSpeed = toFixed(1 / 2)
const infrastructureFraction = toFixed(1 / 2)
const proposerFraction = toFixed(1 / 2)

beforeEach(async () => {
registry = await Registry.new()
Expand All @@ -34,7 +34,7 @@ contract('GasPriceMinimum', (accounts: string[]) => {
initialGasPriceMinimum,
targetDensity,
adjustmentSpeed,
infrastructureFraction
proposerFraction
)
})

Expand All @@ -60,8 +60,8 @@ contract('GasPriceMinimum', (accounts: string[]) => {
})

it('should set the infrastructure fraction', async () => {
const actualInfrastructureFraction = await gasPriceMinimum.infrastructureFraction()
assertEqualBN(actualInfrastructureFraction, infrastructureFraction)
const actualProposerFraction = await gasPriceMinimum.proposerFraction()
assertEqualBN(actualProposerFraction, proposerFraction)
})

it('should not be callable again', async () => {
Expand All @@ -71,7 +71,7 @@ contract('GasPriceMinimum', (accounts: string[]) => {
initialGasPriceMinimum,
targetDensity,
adjustmentSpeed,
infrastructureFraction
proposerFraction
)
)
})
Expand Down Expand Up @@ -141,34 +141,34 @@ contract('GasPriceMinimum', (accounts: string[]) => {
})
})

describe('#setInfrastructureFraction', () => {
const newInfrastructureFraction = toFixed(1 / 3)
describe('#setProposerFraction', () => {
const newProposerFraction = toFixed(1 / 3)

it('should set the adjustment speed', async () => {
await gasPriceMinimum.setInfrastructureFraction(newInfrastructureFraction)
const actualInfrastructureFraction = await gasPriceMinimum.infrastructureFraction()
assertEqualBN(actualInfrastructureFraction, newInfrastructureFraction)
await gasPriceMinimum.setProposerFraction(newProposerFraction)
const actualProposerFraction = await gasPriceMinimum.proposerFraction()
assertEqualBN(actualProposerFraction, newProposerFraction)
})

it('should emit the InfrastructureFractionSet event', async () => {
const resp = await gasPriceMinimum.setInfrastructureFraction(newInfrastructureFraction)
it('should emit the ProposerFractionSet event', async () => {
const resp = await gasPriceMinimum.setProposerFraction(newProposerFraction)
assert.equal(resp.logs.length, 1)
const log = resp.logs[0]
assertLogMatches2(log, {
event: 'InfrastructureFractionSet',
event: 'ProposerFractionSet',
args: {
infrastructureFraction: newInfrastructureFraction,
proposerFraction: newProposerFraction,
},
})
})

it('should revert when the provided fraction is greater than one', async () => {
await assertRevert(gasPriceMinimum.setInfrastructureFraction(toFixed(3 / 2)))
await assertRevert(gasPriceMinimum.setProposerFraction(toFixed(3 / 2)))
})

it('should revert when called by anyone other than the owner', async () => {
await assertRevert(
gasPriceMinimum.setInfrastructureFraction(newInfrastructureFraction, { from: nonOwner })
gasPriceMinimum.setProposerFraction(newProposerFraction, { from: nonOwner })
)
})
})
Expand Down

0 comments on commit 128d032

Please sign in to comment.