Skip to content

Commit

Permalink
Add: natspec for contract declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Farterson committed Apr 16, 2021
1 parent 46fee5e commit bf25039
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 78 deletions.
13 changes: 5 additions & 8 deletions contracts/curves/BancorZeroFormula.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ pragma solidity ^0.8.0;

import "../utils/Power.sol";

/**
* @title Bancor formula by Bancor
* @dev Modified from the original by Slava Balasanov
* https://github.com/bancorprotocol/contracts
* Split Power.sol out from BancorFormula.sol and replace SafeMath formulas with zeppelin's SafeMath
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements;
* and to You under the Apache License, Version 2.0. "
*/
/// @title Bancor formula by Bancor
/// @author Carl Farterson (@carlfarterson), originally by Slava Blasanov
/// @notice All private methods used for BancorZeroValueSet.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 BancorZeroFormula is Power {

uint32 public MAX_WEIGHT = 1000000;
Expand Down
4 changes: 4 additions & 0 deletions contracts/curves/BancorZeroValueSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import "./BancorZeroFormula.sol";

// example of a contract `curves.libraryParameterSet` that can be registered in CurveRegistry.sol
// specifically paired with BancorFormulaFromZero.sol

/// @title Bancor curve registry and calculator
/// @author Carl Farterson (@carlfarterson)
/// @notice Uses BancorZeroFormula.sol for private methods
contract BancorZeroFormulaValues is BancorZeroFormula {

// NOTE: each valueSet is for a curve
Expand Down
3 changes: 3 additions & 0 deletions contracts/curves/SigmoidalFormula.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pragma solidity ^0.8.0;

/// @title Sigmoidal curve private methods
/// @author Carl Farterson (@carlfarterson)
/// @notice All private methods used for SigmoidalValueSet.sol
contract SigmoidalFormula {

}
6 changes: 4 additions & 2 deletions contracts/curves/SigmoidalValueSet.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// example of a contract `curves.libraryParameterSet` that can be registered in CurveRegistry.sol
// specifically paired with BancorFormulaFromZero.sol
pragma solidity ^0.8.0;

import "./SigmoidalFormula.sol";

/// @title Sigmoidal curve registry and calculator
/// @author Carl Farterson (@carlfarterson)
/// @notice Uses SigmoidalFormula.sol for private methods
contract SigmoidalValues is SigmoidalFormula {

struct ValueSet{
Expand Down
4 changes: 3 additions & 1 deletion contracts/factories/MeTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ pragma solidity ^0.8.0;
import "../MeToken.sol";
import "../interfaces/I_MeTokenRegistry.sol";


/// @title meToken factory
/// @author Carl Farterson (@carlfarterson)
/// @notice This contract creates and deploys a users' meToken
contract MeTokenFactory {

I_MeTokenRegistry public meTokenRegistry;
Expand Down
17 changes: 7 additions & 10 deletions contracts/factories/VaultFactories/SingleAssetFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ pragma solidity ^0.8.0;
import "../../vaults/SingleAsset.sol";
import "../../interfaces/I_VaultRegistry.sol";


/// @title Factory contract to erc20-collateral vaults
/// @author Carl Farterson (@carlfarterson)
/// @notice Deploys a single collateral vault (non-LP token)
contract SingleAssetFactory {

I_VaultRegistry public vaultRegistry;
Vault public vault;

constructor(address _vaultRegistry) public {
require(_vaultRegistry != address(0), "Cannot be 0 address");
constructor(address _hub, address _vaultRegistry) public {
hub = _hub;
vaultRegistry = _vaultRegistry;
}

Expand All @@ -20,15 +22,10 @@ contract SingleAssetFactory {
address _owner,
uint256 _hub,
address _valueSetAddress,
// address[] _collateralAssets[], // TODO
bytes4 _encodedVaultAdditionalArgs // NOTE: this is _refundRatio and _collateralAsset hashed
address _collateralAsset,
bytes4 _encodedVaultAdditionalArgs // NOTE: this is _refundRatio, base_x, & base_y
) public returns (address) {

require(
_collateralAssets.length > 0 && _collateralAssets.length <= MAX_NUM_COLLATERAL_ASSETS,
"Invalid number of collateral assets"
);

// create our vault
// TODO: create2 shit
Vault memory vault = new Vault_SingleAsset();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
pragma solidity ^0.8.0;

/// @title Vault migrator from erc20 to erc20 (non-lp)
/// @author Carl Farterson (@carlfarterson)
/// @notice This contract moves the pooled/locked balances from
/// one erc20 to another
contract MigrationVault_SingleAsset_to_SingleAsset {

}
3 changes: 3 additions & 0 deletions contracts/registries/CurveRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pragma solidity ^0.8.0;

/// @title Curve registry
/// @author Carl Farterson (@carlfarterson)
/// @notice This contract keeps track of active curve types and their base values
contract CurveRegistry {

event RegisterCurve(string name, address formula, address values);
Expand Down
5 changes: 5 additions & 0 deletions contracts/registries/HubRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import "../interfaces/I_CurveValueSet.sol";
import "../interfaces/I_Vault.sol";


/// @title meToken hub
/// @author Carl Farterson (@carlfarterson)
/// @notice This contract tracks all combinations of vaults and curves,
/// and their respective subscribed meTokens
contract HubRegistry {

event RegisterHub(string name, address indexed vault); // TODO: decide on arguments
Expand Down Expand Up @@ -163,6 +167,7 @@ contract HubRegistry {
);

// TODO: Update balance pooled


I_MeToken(_meToken).transfer(fees.feeRecipient(), fee);
I_MeToken(_meToken).burn(msg.sender, meTokensBurnedAfterFees);
Expand Down
46 changes: 3 additions & 43 deletions contracts/registries/MeTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import "../interfaces/I_MeTokenFactory.sol";
import "../interfaces/I_HubRegistry.sol";


/// @title meToken registry
/// @author Carl Farterson (@carlfarterson)
/// @notice This contract tracks basic information about all meTokens
contract MeTokenRegistry{

event RegisterMeToken(
Expand All @@ -14,8 +17,6 @@ contract MeTokenRegistry{
string symbol,
uint256 hub
);
// event ApproveCollateralAsset(address asset);
// event UnapproveCollateralAsset(address asset);

I_MeTokenFactory public meTokenFactory;
I_HubRegistry public hubRegistry;
Expand Down Expand Up @@ -69,56 +70,15 @@ contract MeTokenRegistry{
return meTokenOwners[_owner];
}

function getMeTokenOwner(address _meToken) external view returns (address) {
// TODO: validate MeTokenDetails struct wwill revert for missing meToken address
MeTokenDetails memory meTokenDetails = meTokens[_meToken];
return meTokenDetails.owner;
}

function getMeTokenHub(address _meToken) external view returns (uint256) {
MeTokenDetails memory meTokenDetails = meTokens[_meToken];
return meTokenDetails.hub;
}

function getMeTokenBalancePooled(address _meToken) external view returns (uint256) {
MeTokenDetails memory meTokenDetails = meTokens[_meToken];
return meTokenDetails.balancePooled;
}

function getMeTokenBalanceLocked(address _meToken) external view returns (uint256) {
MeTokenDetails memory meTokenDetails = meTokens[_meToken];
return meTokenDetails.balanceLocked;
}

function isMeTokenMigrating(address _meToken) external view returns (uint256) {
MeTokenDetails memory MeTokenDetails = meTokens[_meToken];
return meTokenDetails.migrating;
}

function getMeTokenDetails(address _meToken) external view returns (MeTokenDetails calldata) {
MeTokenDetails memory meTokenDetails = meTokens[_meToken];
return meTokenDetails;
}

/*
function approveCollateralAsset(address _asset) external {
// TODO: access control
require(!approvedCollateralAssets[_asset], "Asset already approved");
approvedCollateralAssets[_asset] = true;
emit ApproveCollateralAsset(_asset);
}
function unapproveCollateralAsset(address _asset) external {
require(approvedCollateralAssets[_asset], "Asset not approved");
approvedCollateralAssets[_asset] = false;
emit UnapproveCollateralAsset(_asset);
}
function isApprovedCollateralAsset(address _asset) external view returns (bool) {
return approvedCollateralAssets[_asset];
}
*/

// TODO
// function migrate(uint256 meTokenAddress) external onlyOwner(meTokenAddress) returns(bool) {}
}
4 changes: 4 additions & 0 deletions contracts/registries/MigrationRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
pragma solidity ^0.8.0;


/// @title Migration registry
/// @author Carl Farterson (@carlfarterson)
/// @notice Keeps track of all used migration strategies
contract MigrationRegistry {

mapping (uint256 => MigrationDetails) migrations;
Expand Down
8 changes: 5 additions & 3 deletions contracts/registries/VaultRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
pragma solidity ^0.8.0;


/// @title vault registry
/// @author Carl Farterson (@carlfarterson)
/// @notice Keeps track of all active vaults and available vault factories
contract VaultRegistry {

event RegisterVault(string name, address vault, address factory);
Expand All @@ -13,14 +17,12 @@ contract VaultRegistry {
struct VaultDetails {
string name;
address factory; // NOTE: references factories/VaultFactories/{}.sol
bool active;
bool active; // NOTE: can be inactive after vault migration
}

// TODO: argument check
function registerVault(string calldata _name, address _vault, address _factory) external {
// TODO: access control
require(approvedVaultFactories[_factory], "Factory not approved");

// Add vault details to storage
// TODO: validate memory vs. storage usage
VaultDetails memory vaultDetails = VaultDetails(_name, _factory, true);
Expand Down
12 changes: 3 additions & 9 deletions contracts/utils/Power.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
pragma solidity ^0.8.0;

/**
* @title Power function by Bancor
* @dev https://github.com/bancorprotocol/contracts
*
* Modified from the original by Slava Balasanov & Tarrence van As
*
* Split Power.sol out from BancorFormula.sol
* https://github.com/bancorprotocol/contracts/blob/c9adc95e82fdfb3a0ada102514beb8ae00147f5d/solidity/contracts/converter/BancorFormula.sol
*/
/// @title Power function by Bancor
/// @dev https://github.com/bancorprotocol/contracts
/// @notice Modified from the original by Slava Balasanov & Tarrence van As
contract Power {
string public version = "0.3";

Expand Down
8 changes: 6 additions & 2 deletions contracts/vaults/SingleAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import "../interfaces/I_CurveValueSet.sol";
import "../interfaces/I_ERC20.sol"; // TODO
import "../interfaces/I_MeToken.sol";

contract SingleAsset is Fees, MeTokenRegistry, HubRegistry, CurveRegistry {

/// @title ERC-20 (non-LP) token vault
/// @author Carl Farterson (@carlfarterson)
/// @notice Base single asset vault contract
/// @dev Only callable by the vault factory
contract SingleAsset is Vault {

event SetCurve(address curveValueSet);

bytes4 private encodedInitializeFunc = bytes(keccak256("_initialize(uint256,address)"));

uint256 private PRECISION = 10**18;
uint256 public id;
address public owner;
uint256 public collateralBalance;
Expand Down
11 changes: 11 additions & 0 deletions contracts/vaults/Vault.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
pragma solidity ^0.8.0;


/// @title Vault
/// @author Carl Farterson (@carlfarterson)
/// @notice Base vault contract inherited by all vaults
contract Vault {

uint256 private PRECISION = 10**18;
address private collateralAsset;
bool private initialized;

event SetCollateralAsset(address asset);

function getCollateralAsset() external view returns (address) {
return collateralAsset;
Expand All @@ -11,4 +19,7 @@ contract Vault {
// TODO - figure out governance of updating the collateralAsset in a vault
function setCollateralAsset(address _collateralAsset) public onlyGov {
require(initialized, "!initialized");
require(_collateralAsset != collateralAsset, "Cannot change asset to same asset");
collateralAsset = _collateralAsset;
emit setCollateralAsset(_collateralAsset);
}

0 comments on commit bf25039

Please sign in to comment.