hop polygon update

This commit is contained in:
pradyuman-verma 2022-05-07 20:33:57 +05:30
parent 4aeed758fb
commit 7b4d1a4842
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F
4 changed files with 35 additions and 10 deletions

View File

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

View File

@ -18,6 +18,7 @@ contract Helpers is DSMath, Basic {
* @param sourceDeadline The deadline for the source chain transaction (Recommended - Date.now() + 604800 (1 week)) * @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 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 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 { struct BridgeParams {
address token; address token;
@ -30,11 +31,27 @@ contract Helpers is DSMath, Basic {
uint256 sourceDeadline; uint256 sourceDeadline;
uint256 destinationAmountOutMin; uint256 destinationAmountOutMin;
uint256 destinationDeadline; uint256 destinationDeadline;
bool isWrapped;
} }
function _swapAndSend(BridgeParams memory params) internal { function _swapAndSend(BridgeParams memory params, bool isNative) internal {
IHopRouter router = IHopRouter(params.router); 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;
}
TokenInterface tokenContract = TokenInterface(params.token); TokenInterface tokenContract = TokenInterface(params.token);
approve(tokenContract, params.router, params.amount); approve(tokenContract, params.router, params.amount);

View File

@ -13,5 +13,5 @@ interface IHopRouter {
uint256 deadline, uint256 deadline,
uint256 destinationAmountOutMin, uint256 destinationAmountOutMin,
uint256 destinationDeadline uint256 destinationDeadline
) external; ) external payable;
} }

View File

@ -37,28 +37,35 @@ abstract contract Resolver is Helpers {
} }
params.amount = getUint(getId, params.amount); params.amount = getUint(getId, params.amount);
bool isMatic = params.token == maticAddr;
params.token = params.token == maticAddr ? wmaticAddr : params.token;
TokenInterface tokenContract = TokenInterface(params.token); TokenInterface tokenContract = TokenInterface(params.token);
if (isMatic) { if (params.isWrapped) {
convertWmaticToMatic(
params.isWrapped,
tokenContract,
params.amount
);
params.token = maticAddr;
}
bool isNative = params.token == maticAddr;
if (isNative) {
params.amount = params.amount == uint256(-1) params.amount = params.amount == uint256(-1)
? address(this).balance ? address(this).balance
: params.amount; : params.amount;
convertMaticToWmatic(isMatic, tokenContract, params.amount);
} else { } else {
params.amount = params.amount == uint256(-1) params.amount = params.amount == uint256(-1)
? tokenContract.balanceOf(address(this)) ? tokenContract.balanceOf(address(this))
: params.amount; : params.amount;
} }
_swapAndSend(params); _swapAndSend(params, isNative);
_eventName = "LogBridge(address,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)"; _eventName = "LogBridge(address,bool,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode( _eventParam = abi.encode(
params.token, params.token,
params.isWrapped,
params.targetChainId, params.targetChainId,
params.recipient, params.recipient,
params.amount, params.amount,