Skip to content

Commit

Permalink
feat(curve/migrationRegistry): access control
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Farterson committed Dec 28, 2021
1 parent 2b66ef5 commit fecd054
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 24 deletions.
16 changes: 12 additions & 4 deletions contracts/curves/BancorABDK.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ pragma solidity ^0.8.0;

import "../interfaces/ICurve.sol";

import "@openzeppelin/contracts/access/Ownable.sol";
import "../libs/WeightedAverage.sol";

import "../utils/ABDKMathQuad.sol";

/// @title Bancor curve registry and calculator
/// @author Carl Farterson (@carlfarterson), Chris Robison (@CBobRobison)
contract BancorABDK is ICurve {
contract BancorABDK is ICurve, Ownable {
using ABDKMathQuad for uint256;
using ABDKMathQuad for bytes16;

Expand All @@ -24,15 +25,22 @@ contract BancorABDK is ICurve {
bytes16 private immutable _baseX = uint256(1 ether).fromUInt();
bytes16 private immutable _maxWeight = uint256(MAX_WEIGHT).fromUInt(); // gas savings
bytes16 private immutable _one = (uint256(1)).fromUInt();
address public hub;
address public foundry;

// NOTE: keys are their respective hubId
mapping(uint256 => Bancor) private _bancors;

constructor(address _hub, address _foundry) {
hub = _hub;
foundry = _foundry;
}

function register(uint256 _hubId, bytes calldata _encodedDetails)
external
override
{
// TODO: access control
require(msg.sender == hub, "!hub");
require(_encodedDetails.length > 0, "!_encodedDetails");

(uint256 baseY, uint32 reserveWeight) = abi.decode(
Expand All @@ -54,7 +62,7 @@ contract BancorABDK is ICurve {
external
override
{
// TODO: access control
require(msg.sender == hub || msg.sender == owner(), "!authorized");

uint32 targetReserveWeight = abi.decode(_encodedDetails, (uint32));
Bancor storage bancor_ = _bancors[_hubId];
Expand All @@ -73,7 +81,7 @@ contract BancorABDK is ICurve {
}

function finishReconfigure(uint256 _hubId) external override {
// TODO; only foundry can call
require(msg.sender == hub, "!hub");
Bancor storage bancor_ = _bancors[_hubId];
bancor_.reserveWeight = bancor_.targetReserveWeight;
bancor_.baseY = bancor_.targetBaseY;
Expand Down
18 changes: 14 additions & 4 deletions contracts/curves/BancorPower.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "../utils/ABDKMathQuad.sol";
import "./Power.sol";
import "../libs/Details.sol";
import "../interfaces/ICurve.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/**
* @title Bancor formula by Bancor
Expand All @@ -13,7 +14,7 @@ import "../interfaces/ICurve.sol";
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements;
* and to You under the Apache License, Version 2.0. "
*/
contract BancorPower is Power, ICurve {
contract BancorPower is Power, ICurve, Ownable {
using ABDKMathQuad for uint256;
using ABDKMathQuad for bytes16;

Expand All @@ -28,13 +29,22 @@ contract BancorPower is Power, ICurve {
bytes16 private immutable _baseX = uint256(1 ether).fromUInt();
bytes16 private immutable _maxWeight = uint256(MAX_WEIGHT).fromUInt(); // gas savings
bytes16 private immutable _one = (uint256(1)).fromUInt();
address public hub;
address public foundry;

// NOTE: keys are the respective hubId
mapping(uint256 => Bancor) private _bancors;

constructor(address _hub, address _foundry) {
hub = _hub;
foundry = _foundry;
}

function register(uint256 _hubId, bytes calldata _encodedDetails)
external
override
{
// TODO: access control
require(msg.sender == hub, "!hub");
require(_encodedDetails.length > 0, "!_encodedDetails");

(uint256 baseY, uint32 reserveWeight) = abi.decode(
Expand All @@ -56,7 +66,7 @@ contract BancorPower is Power, ICurve {
external
override
{
// TODO: access control
require(msg.sender == hub || msg.sender == owner(), "!authorized");

uint32 targetReserveWeight = abi.decode(_encodedDetails, (uint32));
Bancor storage bancor_ = _bancors[_hubId];
Expand All @@ -76,7 +86,7 @@ contract BancorPower is Power, ICurve {
}

function finishReconfigure(uint256 _hubId) external override {
// TODO; only foundry can call
require(msg.sender == hub, "!hub");
Bancor storage bancor_ = _bancors[_hubId];
bancor_.reserveWeight = bancor_.targetReserveWeight;
bancor_.baseY = bancor_.targetBaseY;
Expand Down
16 changes: 12 additions & 4 deletions contracts/curves/StepwiseCurve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ pragma solidity ^0.8.0;

import "../interfaces/ICurve.sol";

import "@openzeppelin/contracts/access/Ownable.sol";
import "../libs/WeightedAverage.sol";

import "../utils/ABDKMathQuad.sol";

/// @title Stepwise curve registry and calculator
/// @author Carl Farterson (@carlfarterson) & Chris Robison (@CBobRobison)
contract StepwiseCurve is ICurve {
contract StepwiseCurve is ICurve, Ownable {
using ABDKMathQuad for uint256;
using ABDKMathQuad for bytes16;
struct Stepwise {
Expand All @@ -20,15 +21,22 @@ contract StepwiseCurve is ICurve {
}

uint256 public constant PRECISION = 10**18;
address public hub;
address public foundry;

// NOTE: keys are their respective hubId
mapping(uint256 => Stepwise) private _stepwises;

constructor(address _hub, address _foundry) {
hub = _hub;
foundry = _foundry;
}

function register(uint256 _hubId, bytes calldata _encodedDetails)
external
override
{
// TODO: access control
require(msg.sender == hub, "!hub");
require(_encodedDetails.length > 0, "_encodedDetails empty");

(uint256 stepX, uint256 stepY) = abi.decode(
Expand All @@ -47,7 +55,7 @@ contract StepwiseCurve is ICurve {
external
override
{
// TODO: access control
require(msg.sender == hub || msg.sender == owner(), "!authorized");

// TODO: does this require statement need to be added to BancorZeroFormula.sol initReconfigure() as well?
// require(_encodedDetails.length > 0, "_encodedDetails empty");
Expand Down Expand Up @@ -75,7 +83,7 @@ contract StepwiseCurve is ICurve {
}

function finishReconfigure(uint256 _hubId) external override {
// TODO; only foundry can call
require(msg.sender == hub, "!hub");
Stepwise storage stepwise_ = _stepwises[_hubId];
stepwise_.stepX = stepwise_.targetStepX;
stepwise_.stepY = stepwise_.targetStepY;
Expand Down
16 changes: 12 additions & 4 deletions contracts/curves/StepwiseCurveABDK.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ pragma solidity ^0.8.0;

import "../interfaces/ICurve.sol";

import "@openzeppelin/contracts/access/Ownable.sol";
import "../libs/WeightedAverage.sol";

import "../utils/ABDKMathQuad.sol";

/// @title Stepwise curve registry and calculator
/// @author Carl Farterson (@carlfarterson) & Chris Robison (@CBobRobison)
contract StepwiseCurve is ICurve {
contract StepwiseCurve is ICurve, Ownable {
using ABDKMathQuad for uint256;
using ABDKMathQuad for bytes16;
struct Stepwise {
Expand All @@ -22,15 +23,22 @@ contract StepwiseCurve is ICurve {
uint256 public constant PRECISION = 10**18;
bytes16 private immutable _one = uint256(1).fromUInt();
bytes16 private immutable _two = uint256(2).fromUInt();
address public hub;
address public foundry;

// NOTE: keys are their respective hubId
mapping(uint256 => Stepwise) private _stepwises;

constructor(address _hub, address _foundry) {
hub = _hub;
foundry = _foundry;
}

function register(uint256 _hubId, bytes calldata _encodedDetails)
external
override
{
// TODO: access control
require(msg.sender == hub, "!hub");
require(_encodedDetails.length > 0, "_encodedDetails empty");

(uint256 stepX, uint256 stepY) = abi.decode(
Expand All @@ -49,7 +57,7 @@ contract StepwiseCurve is ICurve {
external
override
{
// TODO: access control
require(msg.sender == hub || msg.sender == owner(), "!authorized");

// TODO: does this require statement need to be added to BancorZeroFormula.sol initReconfigure() as well?
// require(_encodedDetails.length > 0, "_encodedDetails empty");
Expand Down Expand Up @@ -77,7 +85,7 @@ contract StepwiseCurve is ICurve {
}

function finishReconfigure(uint256 _hubId) external override {
// TODO; only foundry can call
require(msg.sender == hub, "!hub");
Stepwise storage stepwise_ = _stepwises[_hubId];
stepwise_.stepX = stepwise_.targetStepX;
stepwise_.stepY = stepwise_.targetStepY;
Expand Down
10 changes: 5 additions & 5 deletions contracts/registries/MigrationRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

/// @title migration registry
/// @author Carl Farterson (@carlfarterson)
/// @notice Keeps track of all used migration strategies
contract MigrationRegistry {
contract MigrationRegistry is Ownable {
// Initial vault, target vault, migration vault, approved status
mapping(address => mapping(address => mapping(address => bool)))
private _migrations;
Expand All @@ -13,8 +15,7 @@ contract MigrationRegistry {
address initialVault,
address targetVault,
address migration
) external {
// TODO: access control
) external onlyOwner {
require(
!_migrations[initialVault][targetVault][migration],
"migration already approved"
Expand All @@ -26,8 +27,7 @@ contract MigrationRegistry {
address initialVault,
address targetVault,
address migration
) external {
// TODO: access control
) external onlyOwner {
require(
_migrations[initialVault][targetVault][migration],
"migration not approved"
Expand Down
8 changes: 5 additions & 3 deletions test/contracts/curves/helper/curvesTestsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ export const curvesTestsHelper = async ({
}) => {
const one = ethers.utils.parseEther("1");

/*
TODO (Ben): what should we do w/ these tests
it("Reverts w/ empty encodedDetails", async () => {
/* await expect(
await expect(
curve.register(hubId, ethers.constants.HashZero)
).to.be.revertedWith("!_encodedDetails"); */
).to.be.revertedWith("!_encodedDetails");
await expect(
curve.register(hubId, ethers.utils.toUtf8Bytes(""))
).to.be.revertedWith("!_encodedDetails");
});
it("Reverts w/ invalid encodedDetails", async () => {
// TODO
let encodedCurveDetails = ethers.utils.defaultAbiCoder.encode(
["uint256", "uint32"],
[0, 500000]
Expand Down Expand Up @@ -85,6 +86,7 @@ export const curvesTestsHelper = async ({
it("Passes w/ valid encodedDetails", async () => {
//register is done in the setup and there is no getDetails part of the interface
});
*/
it("should be able to calculate Mint Return from zero", async () => {
const etherAmount = 20;
let amount = one.mul(etherAmount);
Expand Down

0 comments on commit fecd054

Please sign in to comment.