Skip to content

Commit

Permalink
Merge pull request #159 from Bananapus/feature/accounting-flags
Browse files Browse the repository at this point in the history
Feature/accounting flags
  • Loading branch information
mejango authored Jun 30, 2024
2 parents 7da1b2a + 42d6039 commit 72cd86b
Show file tree
Hide file tree
Showing 63 changed files with 1,095 additions and 406 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ block_number = 14126430
block_timestamp = 1643802347
runs = 4096
libs = ["node_modules", "lib"]
build_info = true
build_info = false
extra_output = ['storageLayout']
fs_permissions = [{ access = "read-write", path = "./"}]

Expand Down
18 changes: 9 additions & 9 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ contract Deploy is Script, Sphinx {

function deploy() public sphinx {
bytes32 _coreDeploymentSalt = keccak256(abi.encode(CORE_DEPLOYMENT_NONCE));
address _safe = safeAddress();

JBPermissions permissions = new JBPermissions{salt: _coreDeploymentSalt}();
JBProjects projects = new JBProjects{salt: _coreDeploymentSalt}(_safe, _safe);
JBDirectory directory = new JBDirectory{salt: _coreDeploymentSalt}(permissions, projects, _safe);
JBProjects projects = new JBProjects{salt: _coreDeploymentSalt}(safeAddress(), safeAddress());
JBDirectory directory = new JBDirectory{salt: _coreDeploymentSalt}(permissions, projects, safeAddress());
JBSplits splits = new JBSplits{salt: _coreDeploymentSalt}(directory);
JBRulesets rulesets = new JBRulesets{salt: _coreDeploymentSalt}(directory);
JBPrices prices = new JBPrices{salt: _coreDeploymentSalt}(permissions, projects, directory, safeAddress());

directory.setIsAllowedToSetFirstController(
address(
new JBController{salt: _coreDeploymentSalt}({
Expand All @@ -74,19 +75,18 @@ contract Deploy is Script, Sphinx {
tokens: new JBTokens{salt: _coreDeploymentSalt}(directory, new JBERC20{salt: _coreDeploymentSalt}()),
splits: splits,
fundAccessLimits: new JBFundAccessLimits{salt: _coreDeploymentSalt}(directory),
prices: prices,
trustedForwarder: TRUSTED_FORWARDER
})
),
true
);

JBFeelessAddresses feeless = new JBFeelessAddresses{salt: _coreDeploymentSalt}(_safe);
JBPrices prices = new JBPrices{salt: _coreDeploymentSalt}(permissions, projects, _safe);
JBFeelessAddresses feeless = new JBFeelessAddresses{salt: _coreDeploymentSalt}(safeAddress());

new JBMultiTerminal{salt: _coreDeploymentSalt}({
permissions: permissions,
projects: projects,
directory: directory,
splits: splits,
store: new JBTerminalStore{salt: _coreDeploymentSalt}({directory: directory, rulesets: rulesets, prices: prices}),
feelessAddresses: feeless,
Expand All @@ -95,16 +95,16 @@ contract Deploy is Script, Sphinx {
});

// If the manager is not the deployer we transfer all ownership to it.
if (MANAGER != _safe && MANAGER != address(0)) {
if (MANAGER != safeAddress() && MANAGER != address(0)) {
directory.transferOwnership(MANAGER);
feeless.transferOwnership(MANAGER);
prices.transferOwnership(MANAGER);
projects.transferOwnership(MANAGER);
}

// Transfer ownership to the fee project owner.
if (FEE_PROJECT_OWNER != _safe && FEE_PROJECT_OWNER != address(0)) {
projects.safeTransferFrom(_safe, FEE_PROJECT_OWNER, 1);
if (FEE_PROJECT_OWNER != safeAddress() && FEE_PROJECT_OWNER != address(0)) {
projects.safeTransferFrom(safeAddress(), FEE_PROJECT_OWNER, 1);
}
}
}
44 changes: 43 additions & 1 deletion src/JBController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {IJBFundAccessLimits} from "./interfaces/IJBFundAccessLimits.sol";
import {IJBMigratable} from "./interfaces/IJBMigratable.sol";
import {IJBPermissioned} from "./interfaces/IJBPermissioned.sol";
import {IJBPermissions} from "./interfaces/IJBPermissions.sol";
import {IJBPriceFeed} from "./interfaces/IJBPriceFeed.sol";
import {IJBPrices} from "./interfaces/IJBPrices.sol";
import {IJBProjects} from "./interfaces/IJBProjects.sol";
import {IJBProjectUriRegistry} from "./interfaces/IJBProjectUriRegistry.sol";
import {IJBRulesets} from "./interfaces/IJBRulesets.sol";
Expand Down Expand Up @@ -52,6 +54,7 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
// --------------------------- custom errors ------------------------- //
//*********************************************************************//

error ADDING_PRICE_FEED_NOT_ALLOWED();
error CREDIT_TRANSFERS_PAUSED();
error RULESETS_ARRAY_EMPTY();
error INVALID_BASE_CURRENCY();
Expand Down Expand Up @@ -87,6 +90,9 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
/// @notice A contract that stores fund access limits for each project.
IJBFundAccessLimits public immutable override FUND_ACCESS_LIMITS;

/// @notice A contract that stores prices for each project.
IJBPrices public immutable override PRICES;

//*********************************************************************//
// --------------------- public stored properties -------------------- //
//*********************************************************************//
Expand Down Expand Up @@ -253,6 +259,7 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
/// @param tokens A contract that manages token minting and burning.
/// @param splits A contract that stores splits for each project.
/// @param fundAccessLimits A contract that stores fund access limits for each project.
/// @param prices A contract that stores prices for each project.
constructor(
IJBPermissions permissions,
IJBProjects projects,
Expand All @@ -261,6 +268,7 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
IJBTokens tokens,
IJBSplits splits,
IJBFundAccessLimits fundAccessLimits,
IJBPrices prices,
address trustedForwarder
)
JBPermissioned(permissions)
Expand All @@ -272,6 +280,7 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
TOKENS = tokens;
SPLITS = splits;
FUND_ACCESS_LIMITS = fundAccessLimits;
PRICES = prices;
}

//*********************************************************************//
Expand Down Expand Up @@ -713,6 +722,36 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
TOKENS.transferCreditsFrom(holder, projectId, recipient, amount);
}

/// @notice Add a price feed for a project.
/// @dev Can only be called by the project's owner or an address with the owner's permission to `ADD_PRICE_FEED`.
/// @param projectId The ID of the project to add the feed for.
/// @param pricingCurrency The currency the feed's output price is in terms of.
/// @param unitCurrency The currency being priced by the feed.
/// @param feed The address of the price feed to add.
function addPriceFeed(
uint256 projectId,
uint256 pricingCurrency,
uint256 unitCurrency,
IJBPriceFeed feed
)
external
override
{
// Enforce permissions.
_requirePermissionFrom({
account: PROJECTS.ownerOf(projectId),
projectId: projectId,
permissionId: JBPermissionIds.ADD_PRICE_FEED
});

JBRuleset memory ruleset = RULESETS.currentOf(projectId);

// Make sure the project's ruleset allows adding price feeds.
if (!ruleset.allowAddPriceFeed()) revert ADDING_PRICE_FEED_NOT_ALLOWED();

PRICES.addPriceFeedFor(projectId, pricingCurrency, unitCurrency, feed);
}

/// @notice When a project receives reserved tokens, if it has a terminal for the token, this is used to pay the
/// terminal.
/// @dev Can only be called by this controller.
Expand Down Expand Up @@ -1008,7 +1047,10 @@ contract JBController is JBPermissioned, ERC2771Context, IJBController, IJBMigra
terminalConfig = terminalConfigs[i];

// Add the accounting contexts for the specified tokens.
terminalConfig.terminal.addAccountingContextsFor(projectId, terminalConfig.tokensToAccept);
terminalConfig.terminal.addAccountingContextsFor({
projectId: projectId,
accountingContexts: terminalConfig.accountingContextsToAccept
});

// Add the terminal.
terminals[i] = terminalConfig.terminal;
Expand Down
Loading

0 comments on commit 72cd86b

Please sign in to comment.