Hi Guys,
I am trying to replicate a full gsn flow in my truffle tests:
So I am using gsn start to get the forwarder and relayhub and have my own custom paymaster set up which has my complete whitelisting logic here is the contract
/**
- SPDX-License-Identifier: MIT
pragma solidity 0.6.11;
pragma experimental ABIEncoderV2;import “@opengsn/gsn/contracts/forwarder/IForwarder.sol”;
import “@opengsn/gsn/contracts/BasePaymaster.sol”;contract FrontPayMaster is BasePaymaster {
// allow the owner to set ourTarget
event TargetSet(address target);
event PreRelayed(uint);
event PostRelayed(uint);// whitelisting details of users and their wallets mapping (address=>bool) public senderWhitelist; mapping (address=>bool) public targetWhitelist; /** @dev whitelisting of sender and target as part of auth mechanism. */
function whitelist(address _target, address _sender) external onlyOwner {
senderWhitelist[_sender]=true;
targetWhitelist[_target]=true;
emit TargetSet(_target);
}function preRelayedCall(
GsnTypes.RelayRequest calldata relayRequest,
bytes calldata signature,
bytes calldata approvalData,
uint256 maxPossibleGas
) external override virtual
returns (bytes memory context, bool) {
require(senderWhitelist[relayRequest.request.from], “sender not whitelisted”);
require(targetWhitelist[relayRequest.request.to], “target not whitelisted”);
_verifyForwarder(relayRequest);
(signature, approvalData, maxPossibleGas);
emit PreRelayed(now);
return (abi.encode(now), false);
}function postRelayedCall( bytes calldata context, bool success, uint256 gasUseWithoutPost, GsnTypes.RelayData calldata relayData ) external virtual override { (context, success, gasUseWithoutPost, relayData); emit PostRelayed(abi.decode(context, (uint256))); } function versionPaymaster() external virtual override view returns (string memory) { return "1.0"; }
}
Now what happens is I am able to set the relay hub and transfer eth to paymaster but when I call my recipient contract which is
/**
- SPDX-License-Identifier: MIT
pragma solidity 0.6.11;
import { Create2 } from “@openzeppelin/contracts/utils/Create2.sol”;
import “@opengsn/gsn/contracts/BaseRelayRecipient.sol”;
import “@opengsn/gsn/contracts/interfaces/IKnowForwarderAddress.sol”;
import “./FrontSmartWallet.sol”;contract FrontProxyFactory is BaseRelayRecipient, IKnowForwarderAddress {
mapping (address => address) public registry;
string public override versionRecipient = “2.0.0”;event FrontProxyCreated(address minimalProxy);
constructor(address _forwarder) public {
trustedForwarder = _forwarder;
}function computeAddress(uint256 salt, address implementation) public view returns (address) { return Create2.computeAddress( keccak256(abi.encodePacked(salt)), keccak256(getContractCreationCode(implementation)), address(this) ); } /** @dev smart wallet deployment using create2 + minimal proxy. */ function deploy( uint256 salt, address implementation, bytes memory _data, address _forwarder ) public { address minimalProxy = Create2.deploy( 0, keccak256(abi.encodePacked(salt)), getContractCreationCode(implementation) ); if(_data.length > 0) { (bool success,) = minimalProxy.call(_data); require(success); } registry[msg.sender] = minimalProxy; address payable wallet = address(uint160(minimalProxy)); FrontSmartWallet(wallet).setForwarder(_forwarder); emit FrontProxyCreated(minimalProxy); } function getContractCreationCode(address logic) internal pure returns (bytes memory) { bytes10 creation = 0x3d602d80600a3d3981f3; bytes10 prefix = 0x363d3d373d3d3d363d73; bytes20 targetBytes = bytes20(logic); bytes15 suffix = 0x5af43d82803e903d91602b57fd5bf3; return abi.encodePacked(creation, prefix, targetBytes, suffix); } function getTrustedForwarder() external override view returns (address) { return trustedForwarder; }
}
but when I check relay hub balance before and after calling my recipient contract I see the same balance which implies the tx is not funded by relay hub also since the paymaster has all my auth related logic as I said so it doesn’t get checked either looks like when I call my recipient contract it gets called straight away and not via relay hub as mentioned in the docs so am I missing something ?