refactored code

This commit is contained in:
pradyuman-verma 2022-05-10 18:23:57 +05:30
parent 7b4d1a4842
commit 44e9968dac
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F
3 changed files with 5 additions and 27 deletions

View File

@ -4,7 +4,6 @@ pragma solidity ^0.7.0;
contract Events {
event LogBridge(
address token,
bool isWrapped,
uint256 chainId,
address recipient,
uint256 amount,

View File

@ -18,7 +18,6 @@ contract Helpers is DSMath, Basic {
* @param sourceDeadline The deadline for the source chain transaction (Recommended - Date.now() + 604800 (1 week))
* @param destinationAmountOutMin minimum amount of token out for bridge on target chain, zero for L1 bridging
* @param destinationDeadline The deadline for the target chain transaction (Recommended - Date.now() + 604800 (1 week)), zero for L1 bridging
* @param isWrapped if the token to transfer if wrapped token of native chain token (ex. WETH)
*/
struct BridgeParams {
address token;
@ -31,31 +30,16 @@ contract Helpers is DSMath, Basic {
uint256 sourceDeadline;
uint256 destinationAmountOutMin;
uint256 destinationDeadline;
bool isWrapped;
}
function _swapAndSend(BridgeParams memory params, bool isNative) internal {
IHopRouter router = IHopRouter(params.router);
if (isNative) {
router.swapAndSend{ value: params.amount }(
params.targetChainId,
params.recipient,
params.amount,
params.bonderFee,
params.sourceAmountOutMin,
params.sourceDeadline,
params.destinationAmountOutMin,
params.destinationDeadline
);
return;
}
uint256 nativeTokenAmt = isNative ? params.amount : 0;
TokenInterface tokenContract = TokenInterface(params.token);
approve(tokenContract, params.router, params.amount);
router.swapAndSend(
router.swapAndSend{ value: nativeTokenAmt }(
params.targetChainId,
params.recipient,
params.amount,

View File

@ -39,12 +39,8 @@ abstract contract Resolver is Helpers {
params.amount = getUint(getId, params.amount);
TokenInterface tokenContract = TokenInterface(params.token);
if (params.isWrapped) {
convertWmaticToMatic(
params.isWrapped,
tokenContract,
params.amount
);
if (params.token == wmaticAddr) {
convertWmaticToMatic(true, tokenContract, params.amount);
params.token = maticAddr;
}
@ -62,10 +58,9 @@ abstract contract Resolver is Helpers {
_swapAndSend(params, isNative);
_eventName = "LogBridge(address,bool,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
_eventName = "LogBridge(address,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(
params.token,
params.isWrapped,
params.targetChainId,
params.recipient,
params.amount,