Skip to content

Commit

Permalink
pool explorer skeleton and updated externalContracts
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed Mar 14, 2024
1 parent c63193f commit 3ca761f
Show file tree
Hide file tree
Showing 14 changed files with 4,277 additions and 1,337 deletions.
72 changes: 72 additions & 0 deletions packages/hardhat/contracts/DynamicPricePool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "./interfaces/IVault.sol";
import "./interfaces/IBasePool.sol";
import "./vault/BalancerPoolToken.sol";

/**
* @title Example DynamicPricePool
* @author BUIDL GUIDL
* @notice CURRENTLY A WIP. This is an example custom pool implementation used.
*/
contract DynamicPricePool is IBasePool, BalancerPoolToken {
constructor(
IVault vault,
string memory name,
string memory symbol
) BalancerPoolToken(vault, name, symbol) {}

/**
* @notice Execute a swap in the pool.
* @param params Swap parameters
* @return amountCalculatedScaled18 Calculated amount for the swap
*/
function onSwap(
SwapParams calldata params
) external pure returns (uint256 amountCalculatedScaled18) {
amountCalculatedScaled18 = params.amountGivenScaled18;
}

/**
* @notice Computes and returns the pool's invariant.
* @dev This function computes the invariant based on current balances
* @param balancesLiveScaled18 Array of current pool balances for each token in the pool, scaled to 18 decimals
* @return invariant The calculated invariant of the pool, represented as a uint256
*/
function computeInvariant(
uint256[] memory balancesLiveScaled18
) public pure returns (uint256 invariant) {
invariant = balancesLiveScaled18[0] + balancesLiveScaled18[1];
}

/**
* @dev Computes the new balance of a token after an operation, given the invariant growth ratio and all other
* balances.
* @param balancesLiveScaled18 Current live balances (adjusted for decimals, rates, etc.)
* @param tokenInIndex The index of the token we're computing the balance for, in token registration order
* @param invariantRatio The ratio of the new invariant (after an operation) to the old
* @return newBalance The new balance of the selected token, after the operation
*/
function computeBalance(
uint256[] memory balancesLiveScaled18,
uint256 tokenInIndex,
uint256 invariantRatio
) external pure returns (uint256 newBalance) {
uint256 invariant = computeInvariant(balancesLiveScaled18);

newBalance =
(balancesLiveScaled18[tokenInIndex] +
invariant *
(invariantRatio)) -
invariant;
}

/**
* @notice Gets the tokens registered to a pool.
* @dev Delegated to the Vault; added here as a convenience, mainly for off-chain processes.
* @dev TODO - left blank for now, but for finished example w/ scaffoldBalancer we need to implement this correctly.
* @return tokens List of tokens in the pool
*/
function getPoolTokens() external view returns (IERC20[] memory tokens) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,32 @@ const deployConstantPricePool: DeployFunction = async function (hre: HardhatRunt
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

const vaultAddress = "0xDaa273AeEc06e9CCb7428a77E2abb1E4659B16D2";
const tokenName = "Balancer Constant Price Pool";
const tokenSymbol = "B-50DAI-50USDe";
const args = [vaultAddress, tokenName, tokenSymbol];
// Vault address is the same for all pools
const VAULT_ADDRESS = "0x1FC7F1F84CFE61a04224AC8D3F87f56214FeC08c";

// Deploy ConstantPricePool
const constantPoolName = "Balancer Constant Price Pool";
const constantPoolSymbol = "B-50DAI-50USDe";
const constantPoolArgs = [VAULT_ADDRESS, constantPoolName, constantPoolSymbol];

await deploy("ConstantPricePool", {
from: deployer,
args, // contract constructor arguments
args: constantPoolArgs, // contract constructor arguments
log: true,
});

// Deploy DynamicPricePool
const dynamicPoolName = "Balancer Dynamic Price Pool";
const dynamicPoolSymbol = "weETH/ezETH/rswETH";
const dynamicPoolArgs = [VAULT_ADDRESS, dynamicPoolName, dynamicPoolSymbol];

await deploy("DynamicPricePool", {
from: deployer,
args: dynamicPoolArgs, // contract constructor arguments
log: true,
});

// Get the deployed contract to interact with it after deploying.
// Get a deployed contract to interact with it after deploying.
// const yourContract = await hre.ethers.getContract<Contract>("ConstantPricePool", deployer);
// const poolTokens = await ConstantPricePool.getPoolTokens());
};
Expand All @@ -42,4 +56,4 @@ export default deployConstantPricePool;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags YourContract
deployConstantPricePool.tags = ["constant", "all"];
deployConstantPricePool.tags = ["all"];
24 changes: 12 additions & 12 deletions packages/hardhat/deployments/sepolia/ConstantPricePool.json

Large diffs are not rendered by default.

Loading

0 comments on commit 3ca761f

Please sign in to comment.