-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/origin/release'
# Conflicts: # .env.clf # .env.deployments # packages/foundry/script/ParentPoolDeploy.s.sol # packages/foundry/test/ParentPool/Deposit.t.sol # packages/foundry/test/ParentPool/unitTests/DepositOnTheWayRequest.t.sol # packages/foundry/test/ParentPool/wrappers/ParentPool_DepositWrapper.sol # packages/foundry/test/ParentPool/wrappers/ParentPool_Wrapper.sol # packages/hardhat/constants/CLFSecrets.ts # packages/hardhat/constants/cNetworks.ts # packages/hardhat/contracts/ConceroAutomation.sol # packages/hardhat/contracts/ConceroParentPool.sol # packages/hardhat/contracts/Interfaces/IConceroAutomation.sol # packages/hardhat/contracts/Interfaces/IParentPool.sol # packages/hardhat/contracts/Libraries/ParentPoolStorage.sol # packages/hardhat/tasks/CLFScripts/dist/infra/DST.min.js # packages/hardhat/tasks/CLFScripts/dist/infra/SRC.js # packages/hardhat/tasks/CLFScripts/dist/infra/SRC.min.js # packages/hardhat/tasks/CLFScripts/dist/pool/getTotalBalance.js # packages/hardhat/tasks/CLFScripts/dist/pool/getTotalBalance.min.js # packages/hardhat/tasks/CLFScripts/src/infra/SRC.js # packages/hardhat/tasks/CLFScripts/src/pool/getTotalBalance.js # packages/hardhat/tasks/concero/deployInfra/deployInfra.ts # packages/hardhat/tasks/concero/liveChains.ts # packages/hardhat/tasks/index.ts # packages/hardhat/test/testnet/ParentPoolStartAndCompleteDeposit.ts
- Loading branch information
Showing
13 changed files
with
429 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
packages/foundry/test/ParentPool/unitTests/CalculateLpTokensToMint.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import {BaseTest} from "../BaseTest.t.sol"; | ||
import {Test, console, Vm} from "forge-std/Test.sol"; | ||
import {ParentPool_Wrapper} from "../wrappers/ParentPool_Wrapper.sol"; | ||
import {ConceroParentPool} from "contracts/ConceroParentPool.sol"; | ||
|
||
interface IERC20 { | ||
function balanceOf(address account) external view returns (uint256); | ||
} | ||
|
||
contract CalculateLpTokensToMintTest is BaseTest { | ||
uint256 internal constant USDC_DECIMALS = 10 ** 6; | ||
uint256 internal constant LP_DECIMALS = 10 ** 18; | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
SETUP | ||
//////////////////////////////////////////////////////////////*/ | ||
function setUp() public virtual override { | ||
vm.selectFork(forkId); | ||
deployParentPoolProxy(); | ||
deployLpToken(); | ||
|
||
parentPoolImplementation = new ParentPool_Wrapper( | ||
address(parentPoolProxy), | ||
vm.envAddress("LINK_BASE"), | ||
vm.envBytes32("CLF_DONID_BASE"), | ||
uint64(vm.envUint("CLF_SUBID_BASE")), | ||
address(vm.envAddress("CLF_ROUTER_BASE")), | ||
address(vm.envAddress("CL_CCIP_ROUTER_BASE")), | ||
address(vm.envAddress("USDC_BASE")), | ||
address(lpToken), | ||
vm.envAddress("CONCERO_AUTOMATION_BASE"), | ||
address(vm.envAddress("CONCERO_ORCHESTRATOR_BASE")), | ||
address(deployer), | ||
[vm.envAddress("POOL_MESSENGER_0_ADDRESS"), address(0), address(0)] | ||
); | ||
|
||
setProxyImplementation(address(parentPoolImplementation)); | ||
setParentPoolVars(); | ||
addFunctionsConsumer(); | ||
} | ||
|
||
/*///////////////////////////////////////////////////////////// | ||
TESTS | ||
/////////////////////////////////////////////////////////////*/ | ||
|
||
function test_CalculateLpTokensToMint_DepositInPurePool() public { | ||
uint256 totalCrossChainBalanceUSDC = 0; | ||
uint256 childPoolBalanceUSDC = 0; | ||
uint256 amountToDepositUSDC = 200_000_000; | ||
uint256 expectedLpAmountToMint = 200 ether; | ||
|
||
uint256 lpAmountToMint = ConceroParentPool(payable(parentPoolProxy)).calculateLpAmount( | ||
childPoolBalanceUSDC, | ||
amountToDepositUSDC | ||
); | ||
|
||
require(lpAmountToMint == expectedLpAmountToMint, "Incorrect LP amount calculated"); | ||
} | ||
|
||
function test_CalculateLpTokensToMint_DepositInPoolWithDepositsOnTheWay() public { | ||
uint256 totalCrossChainBalanceBody = 3000; | ||
uint256 totalCrossChainBalanceUSDC = totalCrossChainBalanceBody * USDC_DECIMALS; | ||
uint256 amountToDepositUSDC = 100 * USDC_DECIMALS; | ||
uint256 childPoolsCount = 3; | ||
uint256 expectedLpAmountToMint = 100 ether; | ||
uint256 prevDepositAmountUSDC = 100 * USDC_DECIMALS; | ||
uint256 lpTokenAmount = totalCrossChainBalanceBody * LP_DECIMALS; | ||
uint256 childPoolsBalanceUSDC = _setupPoolsAndLpToken( | ||
totalCrossChainBalanceUSDC, | ||
lpTokenAmount, | ||
prevDepositAmountUSDC | ||
); | ||
|
||
uint256 lpAmountToMint = ConceroParentPool(payable(parentPoolProxy)).calculateLpAmount( | ||
childPoolsBalanceUSDC, | ||
amountToDepositUSDC | ||
); | ||
|
||
require(lpAmountToMint == expectedLpAmountToMint, "Incorrect LP amount calculated"); | ||
} | ||
|
||
function test_CalculateLpTokensToMint_DepositInPoolWithFees() public { | ||
uint256 totalCrossChainBalanceBody = 94_000; | ||
uint256 feesEarnedBody = 400; | ||
uint256 totalCrossChainBalanceUSDC = (totalCrossChainBalanceBody + feesEarnedBody) * | ||
USDC_DECIMALS; | ||
uint256 amountToDepositUSDC = 100 * USDC_DECIMALS; | ||
uint256 childPoolsCount = 3; | ||
uint256 expectedLpAmountToMint = 99576271186440677966; | ||
uint256 lpTokenAmount = totalCrossChainBalanceBody * LP_DECIMALS; | ||
uint256 childPoolsBalanceUSDC = _setupPoolsAndLpToken( | ||
totalCrossChainBalanceUSDC, | ||
lpTokenAmount, | ||
0 | ||
); | ||
|
||
uint256 lpAmountToMint = ConceroParentPool(payable(parentPoolProxy)).calculateLpAmount( | ||
childPoolsBalanceUSDC, | ||
amountToDepositUSDC | ||
); | ||
|
||
require(lpAmountToMint == expectedLpAmountToMint, "Incorrect LP amount calculated"); | ||
} | ||
|
||
/*/////////////////////////////////////// | ||
HELPERS | ||
///////////////////////////////////////*/ | ||
|
||
function _mintLpToken(uint256 amount, address receiver) private { | ||
vm.prank(address(parentPoolProxy)); | ||
lpToken.mint(receiver, amount); | ||
} | ||
|
||
function _USDCToLpDecimals(uint256 amount) private returns (uint256) { | ||
return (amount * LP_DECIMALS) / USDC_DECIMALS; | ||
} | ||
|
||
function _simulateParentPoolDepositOnTheWay(uint256 amount, uint256 childPoolsCount) internal { | ||
for (uint256 i = 0; i < childPoolsCount; i++) { | ||
ParentPool_Wrapper(payable(parentPoolProxy)).addDepositOnTheWay( | ||
bytes32(uint256(1)), | ||
uint64(i), | ||
amount / (childPoolsCount + 1) | ||
); | ||
} | ||
} | ||
|
||
function _simulatePoolsBalanceUSDC( | ||
uint256 totalCrossChainBalanceUSDC, | ||
uint256 depositOnTheWayAmountUSDC | ||
) internal returns (uint256) { | ||
uint256 depositsOnTheWayAmount = ConceroParentPool(payable(parentPoolProxy)) | ||
.s_depositsOnTheWayAmount(); | ||
uint256 childPoolsBalanceUSDC = ((totalCrossChainBalanceUSDC - depositOnTheWayAmountUSDC) * | ||
3) / 4; | ||
uint256 parentPoolBalanceUSDC = totalCrossChainBalanceUSDC - | ||
childPoolsBalanceUSDC - | ||
depositsOnTheWayAmount; | ||
|
||
deal(usdc, address(parentPoolProxy), parentPoolBalanceUSDC); | ||
|
||
return childPoolsBalanceUSDC; | ||
} | ||
|
||
function _setupPoolsAndLpToken( | ||
uint256 crossChainBalanceUSDC, | ||
uint256 lpTokenAmount, | ||
uint256 depositOnTheWatAmount | ||
) internal returns (uint256) { | ||
_mintLpToken((lpTokenAmount), makeAddr("1")); | ||
return _simulatePoolsBalanceUSDC(crossChainBalanceUSDC, depositOnTheWatAmount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
import { getEnvVar } from "../utils/getEnvVar"; | ||
import { CLFSecrets } from "../types/CLFSecrets"; | ||
type envString = string | undefined; | ||
export type CLFSecrets = { | ||
MESSENGER_0_PRIVATE_KEY: envString; | ||
MESSENGER_1_PRIVATE_KEY: envString; | ||
MESSENGER_2_PRIVATE_KEY: envString; | ||
POOL_MESSENGER_0_PRIVATE_KEY: envString; | ||
INFURA_API_KEY: envString; | ||
ALCHEMY_API_KEY: envString; | ||
PARENT_POOL_INFURA_API_KEY: envString; | ||
PARENT_POOL_ALCHEMY_API_KEY: envString; | ||
}; | ||
|
||
const secrets: CLFSecrets = { | ||
MESSENGER_0_PRIVATE_KEY: getEnvVar("MESSENGER_0_PRIVATE_KEY"), | ||
MESSENGER_1_PRIVATE_KEY: getEnvVar("MESSENGER_1_PRIVATE_KEY"), | ||
MESSENGER_2_PRIVATE_KEY: getEnvVar("MESSENGER_2_PRIVATE_KEY"), | ||
POOL_MESSENGER_0_PRIVATE_KEY: getEnvVar("POOL_MESSENGER_0_PRIVATE_KEY"), | ||
INFURA_API_KEY: getEnvVar("INFURA_API_KEY"), | ||
ALCHEMY_API_KEY: getEnvVar("ALCHEMY_API_KEY"), | ||
MESSENGER_0_PRIVATE_KEY: process.env.MESSENGER_0_PRIVATE_KEY, | ||
MESSENGER_1_PRIVATE_KEY: process.env.MESSENGER_1_PRIVATE_KEY, | ||
MESSENGER_2_PRIVATE_KEY: process.env.MESSENGER_2_PRIVATE_KEY, | ||
POOL_MESSENGER_0_PRIVATE_KEY: process.env.POOL_MESSENGER_0_PRIVATE_KEY, | ||
INFURA_API_KEY: process.env.INFURA_API_KEY, | ||
ALCHEMY_API_KEY: process.env.ALCHEMY_API_KEY, | ||
PARENT_POOL_INFURA_API_KEY: process.env.PARENT_POOL_INFURA_API_KEY, | ||
PARENT_POOL_ALCHEMY_API_KEY: process.env.PARENT_POOL_ALCHEMY_API_KEY, | ||
}; | ||
|
||
export default secrets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.