Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lufaque committed Nov 14, 2024
2 parents 9aa03b4 + 027d0ec commit 6abc056
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 623 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"clf-sub-fund": "yarn workspace @se-2/hardhat clf-sub-fund",
"clf-sub-consumer-add": "yarn workspace @se-2/hardhat clf-sub-consumer-add",
"clf-sub-consumer-rm": "yarn workspace @se-2/hardhat clf-sub-consumer-rm",
"clf-sub-timeout-requests": "yarn workspace @se-2/hardhat clf-sub-timeout-requests"
"clf-sub-timeout-requests": "yarn workspace @se-2/hardhat clf-sub-timeout-requests",
"prepare": "husky"
},
"devDependencies": {
"husky": "^8.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/foundry/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# - `make run_fork` : Run an anvil fork on the BASE_LOCAL_FORK_PORT using the base RPC URL.
# - `make run_arb_fork` : Run an anvil fork on the ARB_LOCAL_FORK_PORT using the ARB RPC URL.
# - `make test` : Run all tests using forge with any optional arguments specified in --args.
# For example: `make test --args="--match-test Deposit"`
# For example: `make test args="--match-test Deposit"`

include .env.foundry
include ../../.env
Expand Down
1 change: 1 addition & 0 deletions packages/hardhat/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
13 changes: 4 additions & 9 deletions packages/hardhat/contracts/Interfaces/IParentPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import {ICCIP} from "./ICCIP.sol";
interface IParentPool is IPool {
/* TYPE DECLARATIONS */

enum FunctionsRequestType {
getTotalPoolsBalance,
liquidityRedistribution,
withdrawalLiquidityCollection
}

enum RedistributeLiquidityType {
addPool,
removePool
Expand All @@ -28,9 +22,10 @@ interface IParentPool is IPool {

///@notice Struct to track Functions Requests Type
enum CLFRequestType {
startDeposit_getChildPoolsLiquidity, //Deposits
startWithdrawal_getChildPoolsLiquidity, //Start Withdrawals
performUpkeep_requestLiquidityTransfer
startDeposit_getChildPoolsLiquidity,
startWithdrawal_getChildPoolsLiquidity,
withdrawal_requestLiquidityCollection,
liquidityRedistribution
}

struct WithdrawRequest {
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/contracts/Libraries/ParentPoolStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract ParentPoolStorage {
///@notice variable to store the Chainlink Function DON Secret Version
uint64 internal s_donHostedSecretsVersion;
///@notice variable to store the Chainlink Function Source Hashsum
bytes32 internal s_getBalanceJsCodeHashSum;
bytes32 internal s_getChildPoolsLiquidityJsCodeHashSum;
///@notice variable to store Ethers Hashsum
bytes32 internal s_ethersHashSum;
///@notice variable to store not processed amounts deposited by LPs
Expand Down
12 changes: 6 additions & 6 deletions packages/hardhat/contracts/ParentPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ contract ParentPool is IParentPool, CCIPReceiver, ParentPoolCommon, ParentPoolSt
}

bytes[] memory args = new bytes[](3);
args[0] = abi.encodePacked(s_getBalanceJsCodeHashSum);
args[0] = abi.encodePacked(s_getChildPoolsLiquidityJsCodeHashSum);
args[1] = abi.encodePacked(s_ethersHashSum);
args[2] = abi.encodePacked(FunctionsRequestType.getTotalPoolsBalance);
args[2] = abi.encodePacked(CLFRequestType.startDeposit_getChildPoolsLiquidity);

bytes memory delegateCallArgs = abi.encodeWithSelector(
IParentPoolCLFCLA.sendCLFRequest.selector,
Expand Down Expand Up @@ -350,7 +350,7 @@ contract ParentPool is IParentPool, CCIPReceiver, ParentPoolCommon, ParentPoolSt
}

bytes[] memory args = new bytes[](2);
args[0] = abi.encodePacked(s_getBalanceJsCodeHashSum);
args[0] = abi.encodePacked(s_getChildPoolsLiquidityJsCodeHashSum);
args[1] = abi.encodePacked(s_ethersHashSum);

bytes32 withdrawalId = keccak256(
Expand Down Expand Up @@ -536,7 +536,7 @@ contract ParentPool is IParentPool, CCIPReceiver, ParentPoolCommon, ParentPoolSt
function setGetBalanceJsCodeHashSum(
bytes32 _hashSum
) external payable onlyProxyContext onlyOwner {
s_getBalanceJsCodeHashSum = _hashSum;
s_getChildPoolsLiquidityJsCodeHashSum = _hashSum;
}

/**
Expand Down Expand Up @@ -574,7 +574,7 @@ contract ParentPool is IParentPool, CCIPReceiver, ParentPoolCommon, ParentPoolSt
bytes[] memory args = new bytes[](6);
args[0] = abi.encodePacked(s_distributeLiquidityJsCodeHashSum);
args[1] = abi.encodePacked(s_ethersHashSum);
args[2] = abi.encodePacked(FunctionsRequestType.liquidityRedistribution);
args[2] = abi.encodePacked(CLFRequestType.liquidityRedistribution);
args[3] = abi.encodePacked(_chainSelector);
args[4] = abi.encodePacked(distributeLiquidityRequestId);
args[5] = abi.encodePacked(RedistributeLiquidityType.addPool);
Expand Down Expand Up @@ -619,7 +619,7 @@ contract ParentPool is IParentPool, CCIPReceiver, ParentPoolCommon, ParentPoolSt
bytes[] memory args = new bytes[](6);
args[0] = abi.encodePacked(s_distributeLiquidityJsCodeHashSum);
args[1] = abi.encodePacked(s_ethersHashSum);
args[2] = abi.encodePacked(FunctionsRequestType.liquidityRedistribution);
args[2] = abi.encodePacked(CLFRequestType.liquidityRedistribution);
args[3] = abi.encodePacked(_chainSelector);
args[4] = abi.encodePacked(distributeLiquidityRequestId);
args[5] = abi.encodePacked(RedistributeLiquidityType.removePool);
Expand Down
10 changes: 5 additions & 5 deletions packages/hardhat/contracts/ParentPoolCLFCLA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ contract ParentPoolCLFCLA is
_handleStartWithdrawalCLFFulfill(requestId, response);
delete s_withdrawalIdByCLFRequestId[requestId];
} else if (
requestType == IParentPool.CLFRequestType.performUpkeep_requestLiquidityTransfer
requestType == IParentPool.CLFRequestType.withdrawal_requestLiquidityCollection
) {
_handleAutomationCLFFulfill(requestId);
}
Expand Down Expand Up @@ -189,9 +189,7 @@ contract ParentPoolCLFCLA is
liquidityRequestedFromEachPool
);

s_clfRequestTypes[reqId] = IParentPool
.CLFRequestType
.performUpkeep_requestLiquidityTransfer;
s_clfRequestTypes[reqId] = IParentPool.CLFRequestType.withdrawal_requestLiquidityCollection;

_addWithdrawalOnTheWayAmountById(withdrawalId);
emit WithdrawUpkeepPerformed(reqId);
Expand Down Expand Up @@ -426,7 +424,9 @@ contract ParentPoolCLFCLA is
bytes[] memory args = new bytes[](5);
args[0] = abi.encodePacked(s_collectLiquidityJsCodeHashSum);
args[1] = abi.encodePacked(s_ethersHashSum);
args[2] = abi.encodePacked(IParentPool.FunctionsRequestType.withdrawalLiquidityCollection);
args[2] = abi.encodePacked(
IParentPool.CLFRequestType.withdrawal_requestLiquidityCollection
);
args[3] = abi.encodePacked(liquidityRequestedFromEachPool);
args[4] = abi.encodePacked(withdrawalId);

Expand Down
4 changes: 3 additions & 1 deletion packages/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"clf-sub-fund": "hardhat clf-sub-fund",
"clf-sub-consumer-add": "hardhat clf-sub-consumer-add",
"clf-sub-consumer-rm": "hardhat clf-sub-consumer-rm",
"clf-sub-timeout-requests": "hardhat clf-sub-timeout-requests"
"clf-sub-timeout-requests": "hardhat clf-sub-timeout-requests",
"prepare": "husky"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
Expand Down Expand Up @@ -90,6 +91,7 @@
"envfile": "^7.1.0",
"ethers": "6.12.1",
"hardhat-docgen": "^1.3.0",
"husky": "^9.1.6",
"qrcode": "^1.5.1",
"readline": "^1.3.0",
"regenerator-runtime": "^0.14.1",
Expand Down
50 changes: 50 additions & 0 deletions packages/hardhat/tasks/CLFScripts/decodeCLFResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {AbiParameter, decodeAbiParameters} from 'viem';

const responseDecoders: {[key: string]: AbiParameter[]} = {
infra_src: [
{type: 'uint256', name: 'dstGasPrice'},
{type: 'uint256', name: 'srcGasPrice'},
{type: 'uint64', name: 'dstChainSelector'},
{type: 'uint256', name: 'linkUsdcRate'},
{type: 'uint256', name: 'nativeUsdcRate'},
{type: 'uint256', name: 'linkNativeRate'},
],
infra_dst: [{type: 'uint256', name: 'messageId'}],
pool_get_total_balance: [
{type: 'uint256', name: 'childPoolsLiquidity'},
{type: 'bytes1[]', name: 'depositsOnTheWayIdsToDelete'},
],
pool_distribute_liq: [
{type: 'uint256', name: 'childPoolsLiquidity'},
{type: 'bytes1[]', name: 'depositsOnTheWayIdsToDelete'},
],
};
/**
* Decodes the response hex string based on the script name.
* @param scriptName - The name of the script.
* @param responseHex - The hex string response to decode.
* @returns An object containing the decoded values.
*/
export function decodeCLFResponse(scriptName: string, responseHex: string): any {
const decoder = responseDecoders[scriptName];
if (!decoder) {
console.error(`No decoder defined for script: ${scriptName}`);
return null;
}

const responseData = responseHex.startsWith('0x') ? responseHex : '0x' + responseHex;

try {
const decodedValues = decodeAbiParameters(decoder, responseData);
const result: Record<string, any> = {};

decoder.forEach((param, index) => {
result[param.name || `param${index}`] = decodedValues[index];
});

return result;
} catch (error) {
console.error('Failed to decode response:', error);
return null;
}
}
83 changes: 42 additions & 41 deletions packages/hardhat/tasks/CLFScripts/dist/infra/SRC.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
function hexString(data) {
if (typeof data === 'string' || data instanceof String) {
if ((data = data.match(/^[\s\uFEFF\xA0]*(0[Xx])?([0-9A-Fa-f]*)[\s\uFEFF\xA0]*$/))) {
if (data[2].length % 2) {
throw new Error('Hex string length must be a multiple of 2.');
(async () => {
function hexString(data) {
if (typeof data === 'string' || data instanceof String) {
if ((data = data.match(/^[\s\uFEFF\xA0]*(0[Xx])?([0-9A-Fa-f]*)[\s\uFEFF\xA0]*$/))) {
if (data[2].length % 2) {
throw new Error('Hex string length must be a multiple of 2.');
}
return data[2];
}
return data[2];
}
throw new Error('Data must be a hex string.');
}
throw new Error('Data must be a hex string.');
}
function byteToString(b) {
return (b | 0x100).toString(16).slice(1);
}
function parseByte(data, i) {
return parseInt(data.substr(i, 2), 16);
}
function cdCompress(data) {
data = hexString(data);
var o = '0x',
z = 0,
y = 0,
i = 0,
c;
function pushByte(b) {
o += byteToString(((o.length < 4 * 2 + 2) * 0xff) ^ b);
function byteToString(b) {
return (b | 0x100).toString(16).slice(1);
}
function rle(v, d) {
pushByte(0x00);
pushByte(d - 1 + v * 0x80);
function parseByte(data, i) {
return parseInt(data.substr(i, 2), 16);
}
for (; i < data.length; i += 2) {
c = parseByte(data, i);
if (!c) {
if (y) rle(1, y), (y = 0);
if (++z === 0x80) rle(0, 0x80), (z = 0);
continue;
function cdCompress(data) {
data = hexString(data);
var o = '0x',
z = 0,
y = 0,
i = 0,
c;
function pushByte(b) {
o += byteToString(((o.length < 4 * 2 + 2) * 0xff) ^ b);
}
function rle(v, d) {
pushByte(0x00);
pushByte(d - 1 + v * 0x80);
}
if (c === 0xff) {
for (; i < data.length; i += 2) {
c = parseByte(data, i);
if (!c) {
if (y) rle(1, y), (y = 0);
if (++z === 0x80) rle(0, 0x80), (z = 0);
continue;
}
if (c === 0xff) {
if (z) rle(0, z), (z = 0);
if (++y === 0x20) rle(1, 0x20), (y = 0);
continue;
}
if (y) rle(1, y), (y = 0);
if (z) rle(0, z), (z = 0);
if (++y === 0x20) rle(1, 0x20), (y = 0);
continue;
pushByte(c);
}
if (y) rle(1, y), (y = 0);
if (z) rle(0, z), (z = 0);
pushByte(c);
return o;
}
if (y) rle(1, y), (y = 0);
if (z) rle(0, z), (z = 0);
return o;
}
(async () => {
console.log('SRC');
const [
_,
__,
Expand Down
Loading

0 comments on commit 6abc056

Please sign in to comment.