Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pool fee bridge fix #399

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions contracts/PushComm/PushCommV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -689,21 +689,33 @@ contract PushCommV3 is Initializable, PushCommStorageV2, IPushCommV3, PausableUp
*/
// Should be only admin
// Should only bridge NTT TOKENS FROM COMM TO CORE on ethereum
function transferFeePoolToCore(uint256 _amount) external payable onlyPushChannelAdmin {
function transferFeePoolToCore(CrossChainRequestTypes.CrossChainFunction functionType, uint256 _amount, uint256 gasLimit) external payable onlyPushChannelAdmin {
0xNilesh marked this conversation as resolved.
Show resolved Hide resolved
0xNilesh marked this conversation as resolved.
Show resolved Hide resolved
if (PROTOCOL_POOL_FEE < _amount) {
revert Errors.InsufficientFunds();
}

bytes32 recipient = bytes32(uint256(uint160(EPNSCoreAddress)));

uint256 messageBridgeCost = quoteMsgRelayCost(WORMHOLE_RECIPIENT_CHAIN, gasLimit);
uint256 tokenBridgeCost = quoteTokenBridgingCost();
if (msg.value < tokenBridgeCost) {

if (msg.value < (messageBridgeCost + tokenBridgeCost)) {
revert Errors.InsufficientFunds();
}

PROTOCOL_POOL_FEE = PROTOCOL_POOL_FEE - _amount;
0xNilesh marked this conversation as resolved.
Show resolved Hide resolved

PUSH_NTT.approve(address(NTT_MANAGER), _amount);
zaryab2000 marked this conversation as resolved.
Show resolved Hide resolved
NTT_MANAGER.transfer{ value: tokenBridgeCost }(_amount, WORMHOLE_RECIPIENT_CHAIN, recipient);
NTT_MANAGER.transfer{ value: tokenBridgeCost }(_amount, WORMHOLE_RECIPIENT_CHAIN, BaseHelper.addressToBytes32(EPNSCoreAddress), BaseHelper.addressToBytes32(msg.sender), false, new bytes(1));
0xNilesh marked this conversation as resolved.
Show resolved Hide resolved

bytes memory requestPayload = abi.encode(functionType, bytes(""), _amount, msg.sender);

// Relay the RequestData Payload
WORMHOLE_RELAYER.sendPayloadToEvm{ value: messageBridgeCost }(
WORMHOLE_RECIPIENT_CHAIN,
0xNilesh marked this conversation as resolved.
Show resolved Hide resolved
EPNSCoreAddress,
requestPayload,
0, // no receiver value needed since we're just passing a message
gasLimit,
WORMHOLE_RECIPIENT_CHAIN,
msg.sender // Refund address is of the sender
);
}
}
4 changes: 4 additions & 0 deletions contracts/PushCore/PushCoreV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ contract PushCoreV3 is
arbitraryReqFees[amountRecipient] += amount - feeAmount;

emit ArbitraryRequest(sender, amountRecipient, amount, feePercentage, feeId);
} else if( functionType == CrossChainRequestTypes.CrossChainFunction.AdminRequest_AddPoolFee ){
// Admin Request
PROTOCOL_POOL_FEES += amount;

} else {
revert("Invalid Function Type");
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/libraries/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ library CrossChainRequestTypes {
enum CrossChainFunction {
AddChannel,
IncentivizedChat,
ArbitraryRequest
ArbitraryRequest,
AdminRequest_AddPoolFee
}
}