Skip to content

Commit

Permalink
update js code
Browse files Browse the repository at this point in the history
  • Loading branch information
lufaque committed Nov 28, 2024
1 parent 03e6c7e commit 7870210
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 308 deletions.
12 changes: 6 additions & 6 deletions .env.deployments.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ CONCERO_INFRA_PROXY_ADMIN_POLYGON_AMOY=0x125b493Ed7BBD629a15450F171B9aeD64C93361
### BRIDGE CONTRACTS ADDRESSES ###
CONCERO_BRIDGE_SEPOLIA=""
CONCERO_BRIDGE_FUJI=0xa5b6Bb117898dAcD34561a3489e6786f40DE0228
CONCERO_BRIDGE_ARBITRUM_SEPOLIA=0x40725c99d354c76162F6f77099007912e9E24eAE
CONCERO_BRIDGE_BASE_SEPOLIA=0x5D4A401c95F62E009c3cbe6ECCEC60E7A4c071E3
CONCERO_BRIDGE_ARBITRUM_SEPOLIA=0xa8b65f48467Ee223E216f1DDdFa9341417D73AC2
CONCERO_BRIDGE_BASE_SEPOLIA=0x70A117ecf307926713fd2AC7E3cA6e17C537D13d
CONCERO_BRIDGE_OPTIMISM_SEPOLIA=0x1CACCEe6bBB49A1391471192f6e013079191C367
CONCERO_BRIDGE_POLYGON_AMOY=0xF478987348696a33F81A9A2CB2D5b5b1dd48BE63

Expand Down Expand Up @@ -59,15 +59,15 @@ CHILD_POOL_SEPOLIA=""
CHILD_POOL_POLYGON_AMOY=""

# DEX SWAP
CONCERO_DEX_SWAP_BASE_SEPOLIA=0x1cE1e04191308C223aAB0e85E86a2B05D0960708
CONCERO_DEX_SWAP_BASE_SEPOLIA=0x9A5FD0aADB3BE6e43F4Efd50B141eF900265e649
CONCERO_DEX_SWAP_OPTIMISM_SEPOLIA=0xD4437bE364F065Fba62E08899aD3219cbE3fAa4A
CONCERO_DEX_SWAP_ARBITRUM_SEPOLIA=0x0Ab941AAb940DFc69FCB5C5053C5a2F5ea58DDd7
CONCERO_DEX_SWAP_ARBITRUM_SEPOLIA=0x7eba858D27ef5Fd6b14701338FC1607520814E63
CONCERO_DEX_SWAP_POLYGON_AMOY=0x8C23bee630319C0de3e3F5B39Be9b3785c41a034

# ORCHESTRATOR
CONCERO_ORCHESTRATOR_BASE_SEPOLIA=0x495a0D956B279d302e5aF1E42C47951D9C54D602
CONCERO_ORCHESTRATOR_BASE_SEPOLIA=0x48Eb2Fcd767522538f1369Cb0A91BA9F8c2e18A1
CONCERO_ORCHESTRATOR_OPTIMISM_SEPOLIA=0x2B22a64f932739a2CB392dd38A9B2f087072b0D1
CONCERO_ORCHESTRATOR_ARBITRUM_SEPOLIA=0x560992595CDb78c2Ff1Ec5D115500ACD0a3e1729
CONCERO_ORCHESTRATOR_ARBITRUM_SEPOLIA=0x0FD99BC4Ae595F5d3B8D1631CdC94533fA1B33c4
CONCERO_ORCHESTRATOR_POLYGON_AMOY=0x4079dAA49CeeEcb533c4543cb0aA3621c7E7e0d3

# PAUSE CONTRACTS
Expand Down
54 changes: 36 additions & 18 deletions contracts/InfraCLF.sol
Original file line number Diff line number Diff line change
Expand Up @@ -266,28 +266,17 @@ contract InfraCLF is IInfraCLF, FunctionsClient, InfraCommon, InfraStorage {
(address, uint256, bytes)
);

bytes32 recomputedTxDataHash = keccak256(
abi.encode(
conceroMessageId,
amount,
i_chainSelector,
receiver,
keccak256(compressedDstSwapData)
)
_validateBridgeDataHash(
conceroMessageId,
amount,
txDataHash,
receiver,
compressedDstSwapData
);

if (recomputedTxDataHash != txDataHash) {
revert TxDataHashSumMismatch();
}

address bridgeableTokenDst = _getUSDCAddressByChainIndex(CCIPToken.usdc, i_chainIndex);
uint256 amountUsdcAfterFees = amount - getDstTotalFeeInUsdc(amount);

bytes memory decompressedDstSwapData = LibZip.cdDecompress(compressedDstSwapData);
IDexSwap.SwapData[] memory swapData = abi.decode(
decompressedDstSwapData,
(IDexSwap.SwapData[])
);
IDexSwap.SwapData[] memory swapData = _decompressSwapData(compressedDstSwapData);

if (swapData.length == 0) {
IPool(i_poolProxy).takeLoan(bridgeableTokenDst, amountUsdcAfterFees, receiver);
Expand Down Expand Up @@ -318,6 +307,35 @@ contract InfraCLF is IInfraCLF, FunctionsClient, InfraCommon, InfraStorage {
emit TXReleased(conceroMessageId, receiver, bridgeableTokenDst, amountUsdcAfterFees);
}

function _validateBridgeDataHash(
bytes32 conceroMessageId,
uint256 amount,
bytes32 txDataHash,
address receiver,
bytes memory compressedDstSwapData
) internal view {
bytes32 recomputedTxDataHash = keccak256(
abi.encode(
conceroMessageId,
amount,
i_chainSelector,
receiver,
keccak256(compressedDstSwapData)
)
);

if (recomputedTxDataHash != txDataHash) {
revert TxDataHashSumMismatch();
}
}

function _decompressSwapData(
bytes memory compressedDstSwapData
) internal pure returns (IDexSwap.SwapData[] memory swapData) {
bytes memory decompressedDstSwapData = LibZip.cdDecompress(compressedDstSwapData);
return abi.decode(decompressedDstSwapData, (IDexSwap.SwapData[]));
}

/**
* @notice Internal helper function to updated destination storage data
* @param response the CLF response that contains the data
Expand Down
3 changes: 2 additions & 1 deletion tasks/CLFScripts/dist/infra/DST.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
try {
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const constructResult = (receiver, amount, compressedDstSwapData) => {
const encodedReceiver = ethers.zeroPadValue(receiver, 32);
const encodedReceiver = Functions.encodeUint256(BigInt(receiver));
const encodedAmount = Functions.encodeUint256(BigInt(amount));
const encodedCompressedData = ethers.getBytes(compressedDstSwapData);
console.log(encodedReceiver, encodedAmount, encodedCompressedData);
const totalLength = encodedReceiver.length + encodedAmount.length + encodedCompressedData.length;
const result = new Uint8Array(totalLength);
let offset = 0;
Expand Down
2 changes: 1 addition & 1 deletion tasks/CLFScripts/dist/infra/DST.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tasks/CLFScripts/simulationArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const getSimulationArgs: {[functionName: string]: ArgBuilder} = {
'0x0',
'0x' + BigInt(getEnvVar('CONCERO_INFRA_PROXY_ARBITRUM_SEPOLIA')).toString(16),
'0x' + BigInt(getEnvVar('CL_CCIP_CHAIN_SELECTOR_ARBITRUM_SEPOLIA')).toString(16),
'0x1c3361b28a9e61f3b848807c9a816c7ac9d7ac1a8859dc0a0b8b5a5f68aec5b6',
'0xfa726ca69b8b707f6f491e77865af8c8c035d5e16b083ecf11835788df1e12fd',
'0x5dfd8ea23941faa8daa3d2eff5701ed8527a5c7b344c11540498b6c595194873',
'0x38ea807e539efdb47e976510b5b9bc9c3b5dbfc468cdc8cb8070e1ee259751df',
];
},
collect_liq: async () => {
Expand Down
6 changes: 3 additions & 3 deletions tasks/CLFScripts/src/infra/DST.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

const constructResult = (receiver, amount, compressedDstSwapData) => {
const encodedReceiver = ethers.zeroPadValue(receiver, 32);
const encodedReceiver = Functions.encodeUint256(BigInt(receiver));
const encodedAmount = Functions.encodeUint256(BigInt(amount));
const encodedCompressedData = ethers.getBytes(compressedDstSwapData);

console.log(encodedReceiver, encodedAmount, encodedCompressedData);

const totalLength = encodedReceiver.length + encodedAmount.length + encodedCompressedData.length;
const result = new Uint8Array(totalLength);

Expand Down Expand Up @@ -172,11 +174,9 @@
};

const decodedLog = contract.parseLog(logData);

const amount = decodedLog.args[1];
const receiver = decodedLog.args[3];
const compressedDstSwapData = decodedLog.args[4];

const eventHashData = new ethers.AbiCoder().encode(
['bytes32', 'uint256', 'uint64', 'address', 'bytes32'],
[decodedLog.args[0], amount, decodedLog.args[2], receiver, ethers.keccak256(compressedDstSwapData)],
Expand Down
Loading

0 comments on commit 7870210

Please sign in to comment.