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

[VEN-2212]: Fix for MAX_PERCENT in PSR #47

Merged
merged 1 commit into from
Dec 11, 2023
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
14 changes: 7 additions & 7 deletions contracts/ProtocolReserve/ProtocolShareReserve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
struct DistributionConfig {
Schema schema;
/// @dev percenatge is represented without any scale
uint8 percentage;
uint16 percentage;
address destination;
}

Expand All @@ -50,12 +50,12 @@

/// @notice address of vBNB contract
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable vBNB;

Check warning on line 53 in contracts/ProtocolReserve/ProtocolShareReserve.sol

View workflow job for this annotation

GitHub Actions / Lint

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice address of pool registry contract
address public poolRegistry;

uint8 public constant MAX_PERCENT = 100;
uint16 public constant MAX_PERCENT = 1e4;

/// @notice comptroller => asset => schema => balance
mapping(address => mapping(address => mapping(Schema => uint256))) public assetsReserves;
Expand Down Expand Up @@ -99,16 +99,16 @@
/// @notice Event emitted when distribution configuration is updated
event DistributionConfigUpdated(
address indexed destination,
uint8 oldPercentage,
uint8 newPercentage,
uint16 oldPercentage,
uint16 newPercentage,
Schema schema
);

/// @notice Event emitted when distribution configuration is added
event DistributionConfigAdded(address indexed destination, uint8 percentage, Schema schema);
event DistributionConfigAdded(address indexed destination, uint16 percentage, Schema schema);

/// @notice Event emitted when distribution configuration is removed
event DistributionConfigRemoved(address indexed destination, uint8 percentage, Schema schema);
event DistributionConfigRemoved(address indexed destination, uint16 percentage, Schema schema);

/**
* @dev Constructor to initialize the immutable variables
Expand Down Expand Up @@ -424,7 +424,7 @@
*/
function _ensurePercentages() internal view {
uint256 totalSchemas = uint256(type(Schema).max) + 1;
uint8[] memory totalPercentages = new uint8[](totalSchemas);
uint16[] memory totalPercentages = new uint16[](totalSchemas);

uint256 distributionTargetsLength = distributionTargets.length;
for (uint256 i = 0; i < distributionTargetsLength; ) {
Expand Down
32 changes: 16 additions & 16 deletions tests/ProtocolShareReserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,32 @@
await setup.protocolShareReserve.addOrUpdateDistributionConfigs([
{
schema: SCHEMA_PROTOCOL_RESERVE,
percentage: 40,
percentage: 4000,
destination: setup.riskFundSwapper.address,
},
{
schema: SCHEMA_PROTOCOL_RESERVE,
percentage: 20,
percentage: 2000,
destination: setup.xvsVaultSwapper.address,
},
{
schema: SCHEMA_PROTOCOL_RESERVE,
percentage: 40,
percentage: 4000,
destination: setup.dao.address,
},
{
schema: SCHEMA_ADDITIONAL_REVENUE,
percentage: 48,
percentage: 4800,
destination: setup.riskFundSwapper.address,
},
{
schema: SCHEMA_ADDITIONAL_REVENUE,
percentage: 26,
percentage: 2600,
destination: setup.xvsVaultSwapper.address,
},
{
schema: SCHEMA_ADDITIONAL_REVENUE,
percentage: 26,
percentage: 2600,
destination: setup.dao.address,
},
]);
Expand Down Expand Up @@ -152,27 +152,27 @@

expect(config1.schema).to.equal(SCHEMA_PROTOCOL_RESERVE);
expect(config1.destination).to.equal(setup.riskFundSwapper.address);
expect(config1.percentage).to.equal(40);
expect(config1.percentage).to.equal(4000);

expect(config2.schema).to.equal(SCHEMA_PROTOCOL_RESERVE);
expect(config2.destination).to.equal(setup.xvsVaultSwapper.address);
expect(config2.percentage).to.equal(20);
expect(config2.percentage).to.equal(2000);

expect(config3.schema).to.equal(SCHEMA_PROTOCOL_RESERVE);
expect(config3.destination).to.equal(setup.dao.address);
expect(config3.percentage).to.equal(40);
expect(config3.percentage).to.equal(4000);

expect(config4.schema).to.equal(SCHEMA_ADDITIONAL_REVENUE);
expect(config4.destination).to.equal(setup.riskFundSwapper.address);
expect(config4.percentage).to.equal(48);
expect(config4.percentage).to.equal(4800);

expect(config5.schema).to.equal(SCHEMA_ADDITIONAL_REVENUE);
expect(config5.destination).to.equal(setup.xvsVaultSwapper.address);
expect(config5.percentage).to.equal(26);
expect(config5.percentage).to.equal(2600);

expect(config6.schema).to.equal(SCHEMA_ADDITIONAL_REVENUE);
expect(config6.destination).to.equal(setup.dao.address);
expect(config6.percentage).to.equal(26);
expect(config6.percentage).to.equal(2600);
});

it("update configuration of schemas", async () => {
Expand All @@ -181,7 +181,7 @@
protocolShareReserve.addOrUpdateDistributionConfigs([
{
schema: SCHEMA_PROTOCOL_RESERVE,
percentage: 30,
percentage: 3000,
destination: signers[0].address,
},
]),
Expand All @@ -190,12 +190,12 @@
await protocolShareReserve.addOrUpdateDistributionConfigs([
{
schema: SCHEMA_PROTOCOL_RESERVE,
percentage: 30,
percentage: 3000,
destination: setup.riskFundSwapper.address,
},
{
schema: SCHEMA_PROTOCOL_RESERVE,
percentage: 30,
percentage: 3000,
destination: setup.xvsVaultSwapper.address,
},
]);
Expand All @@ -204,7 +204,7 @@

expect(config1.schema).to.equal(SCHEMA_PROTOCOL_RESERVE);
expect(config1.destination).to.equal(setup.riskFundSwapper.address);
expect(config1.percentage).to.equal(30);
expect(config1.percentage).to.equal(3000);
});

it("remove configuration", async () => {
Expand All @@ -231,7 +231,7 @@

await protocolShareReserve.removeDistributionConfig(SCHEMA_PROTOCOL_RESERVE, ONE_ADDRESS);

expect(protocolShareReserve.distributionTargets(6)).to.have.reverted;

Check warning on line 234 in tests/ProtocolShareReserve.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
expect(await protocolShareReserve.totalDistributions()).to.be.equal(6);

await protocolShareReserve.addOrUpdateDistributionConfigs([
Expand Down
Loading