Skip to content

Commit

Permalink
remove broadcast that deploys mock tokens for run of DeployPool script
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed May 16, 2024
1 parent f7d4b64 commit c2131fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
7 changes: 3 additions & 4 deletions packages/foundry/script/DeployFactoryAndPool.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {TokenConfig} from "@balancer-labs/v3-interfaces/contracts/vault/VaultTypes.sol";
import {HelperConfig} from "../utils/HelperConfig.sol";
import {ArrayHelpers} from "@balancer-labs/v3-solidity-utils/contracts/helpers/ArrayHelpers.sol";
import { InputHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpers/InputHelpers.sol";
import {InputHelpers} from "@balancer-labs/v3-solidity-utils/contracts/helpers/InputHelpers.sol";

/**
* @title DeployFactoryAndPool
Expand All @@ -30,7 +30,7 @@ contract DeployFactoryAndPool is ScaffoldETHDeploy, DeployPool {

// Deploy mock tokens. Remove this if using already deployed tokens and instead set the tokens above
vm.startBroadcast(deployerPrivateKey);
(IERC20 token1, IERC20 token2) = deployMockTokens();
(address mockToken1, address mockToken2) = deployMockTokens();
vm.stopBroadcast();

// Look up configuration options from `HelperConfig.sol`
Expand All @@ -40,7 +40,7 @@ contract DeployFactoryAndPool is ScaffoldETHDeploy, DeployPool {
string memory name,
string memory symbol,
TokenConfig[] memory tokenConfig
) = helperConfig.getPoolConfig(token1, token2);
) = helperConfig.getPoolConfig(mockToken1, mockToken2);
(
IERC20[] memory tokens,
uint256[] memory exactAmountsIn,
Expand Down Expand Up @@ -81,5 +81,4 @@ contract DeployFactoryAndPool is ScaffoldETHDeploy, DeployPool {
*/
exportDeployments();
}

}
26 changes: 11 additions & 15 deletions packages/foundry/script/DeployPool.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {TokenConfig} from "@balancer-labs/v3-interfaces/contracts/vault/VaultTypes.sol";
import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
import {Script, console} from "forge-std/Script.sol";
import { InputHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpers/InputHelpers.sol";
import {InputHelpers} from "@balancer-labs/v3-solidity-utils/contracts/helpers/InputHelpers.sol";
import {HelperConfig} from "../utils/HelperConfig.sol";

/**
Expand All @@ -35,25 +35,21 @@ contract DeployPool is HelperFunctions, HelperConfig, Script {
);
}

// Deploy mock tokens to use in the pool
vm.startBroadcast(deployerPrivateKey);
(IERC20 token1, IERC20 token2) = (IERC20(DevOpsTools.get_most_recent_deployment(
"MockToken1", // Must match the pool factory contract name
address mockToken1 = DevOpsTools.get_most_recent_deployment(
"MockToken1", // Must match the mock token contract name
block.chainid
)),IERC20(DevOpsTools.get_most_recent_deployment(
"MockToken2", // Must match the pool factory contract name
);
address mockToken2 = DevOpsTools.get_most_recent_deployment(
"MockToken2", // Must match the mock token contract name
block.chainid
))); // Get the most recently deployed address of the pool factory)

vm.stopBroadcast();
);

// Look up configurations from `HelperConfig.sol`
HelperConfig helperConfig = new HelperConfig();
(
,
,
TokenConfig[] memory tokenConfig
) = helperConfig.getPoolConfig(token1, token2);
(, , TokenConfig[] memory tokenConfig) = helperConfig.getPoolConfig(
mockToken1,
mockToken2
);
(
IERC20[] memory tokens,
uint256[] memory exactAmountsIn,
Expand Down
29 changes: 13 additions & 16 deletions packages/foundry/utils/HelperConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@ contract HelperConfig {
IVault public vault = IVault(0x1FC7F1F84CFE61a04224AC8D3F87f56214FeC08c);
IRouter public router = IRouter(0xA0De078cd5cFa7088821B83e0bD7545ccfb7c883);

/**
* @dev Tokens for pool (also requires configuration of `TokenConfig` in the `getPoolConfig` function)
* @dev If using already deployed tokens, set the addresses here and remove the args for `getPoolConfig` function
* @notice the args for `getPoolConfig` enable the use of mock tokens that are not yet deployed
*/
IERC20 mockToken1; // Make sure to have proper token order (alphanumeric)
IERC20 mockToken2; // Make sure to have proper token order (alphanumeric)

/**
* @notice Creates mock tokens for the pool and mints 1000 of each to the deployer wallet
*/
function deployMockTokens() internal returns (IERC20, IERC20) {
function deployMockTokens() internal returns (address, address) {
MockToken1 scUSD = new MockToken1("Scaffold USD", "scUSD");
MockToken2 scDAI = new MockToken2("Scaffold DAI", "scDAI");

return (scDAI, scUSD);
return (address(scDAI), address(scUSD));
}

/**
Expand All @@ -53,8 +45,8 @@ contract HelperConfig {
* @dev Set the name, symbol, and token configuration for the pool here
*/
function getPoolConfig(
IERC20 token1,
IERC20 token2
address token1,
address token2
)
public
pure
Expand All @@ -69,13 +61,13 @@ contract HelperConfig {

tokenConfig = new TokenConfig[](2); // An array of descriptors for the tokens the pool will manage.
tokenConfig[0] = TokenConfig({ // Make sure to have proper token order (alphanumeric)
token: token1,
token: IERC20(token1),
tokenType: TokenType.STANDARD, // STANDARD, WITH_RATE, or ERC4626
rateProvider: IRateProvider(address(0)), // The rate provider for a token
yieldFeeExempt: false // Flag indicating whether yield fees should be charged on this token
});
tokenConfig[1] = TokenConfig({ // Make sure to have proper token order (alphanumeric)
token: token2,
token: IERC20(token2),
tokenType: TokenType.STANDARD, // STANDARD, WITH_RATE, or ERC4626
rateProvider: IRateProvider(address(0)), // The rate provider for a token
yieldFeeExempt: false // Flag indicating whether yield fees should be charged on this token
Expand Down Expand Up @@ -109,12 +101,17 @@ contract HelperConfig {
userData = bytes(""); // Additional (optional) data required for adding initial liquidity
}

function sortTokenConfig(TokenConfig[] memory tokenConfig) public pure returns (TokenConfig[] memory) {
function sortTokenConfig(
TokenConfig[] memory tokenConfig
) public pure returns (TokenConfig[] memory) {
for (uint256 i = 0; i < tokenConfig.length - 1; i++) {
for (uint256 j = 0; j < tokenConfig.length - i - 1; j++) {
if (tokenConfig[j].token > tokenConfig[j + 1].token) {
// Swap if they're out of order.
(tokenConfig[j], tokenConfig[j + 1]) = (tokenConfig[j + 1], tokenConfig[j]);
(tokenConfig[j], tokenConfig[j + 1]) = (
tokenConfig[j + 1],
tokenConfig[j]
);
}
}
}
Expand Down

0 comments on commit c2131fb

Please sign in to comment.