Skip to content

Commit

Permalink
Merge branch 'master' into feat/add-dex-adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed May 11, 2023
2 parents 1950c18 + 3f1492e commit e6d8527
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 57 deletions.
45 changes: 3 additions & 42 deletions contracts/token/BiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import "../utils/Exec.sol";
import {TokenPaymasterErrors} from "../common/Errors.sol";
import "@openzeppelin/contracts/utils/Address.sol";

// todo add revert codes in errors. structure Errors.sol
// todo add try and catch for certain flows (call/static call and if else based on success and fallback)
// todo add more revert codes in errors. structure Errors.sol
// todo formal verification
// todo add and review natspecs

Expand Down Expand Up @@ -62,10 +61,6 @@ contract BiconomyTokenPaymaster is BasePaymaster, ReentrancyGuard, TokenPaymaste

uint256 private constant SIGNATURE_OFFSET = 181;

// review
// notice: Since it's always verified by the signing service, below gated mapping state could be avoided.
mapping(address => bool) private supportedTokens;

// Owned contract that manages chainlink price feeds (token / eth formaat) and helper to give exchange rate (inverse price)
IOracleAggregator public oracleAggregator;

Expand Down Expand Up @@ -108,16 +103,6 @@ contract BiconomyTokenPaymaster is BasePaymaster, ReentrancyGuard, TokenPaymaste
address indexed _newfeeReceiver,
address indexed _actor
);

/**
* Designed to enable the community to track change in supported ERC20 tokens. Note that a token supported earlier
* can be denied*/
event TokenSupportedOrRevoked(
address indexed _token,
bool indexed _allowed,
address indexed _actor
);


/**
* Designed to enable tracking how much fees were charged from the sender and in which ERC20 token
Expand Down Expand Up @@ -202,20 +187,6 @@ contract BiconomyTokenPaymaster is BasePaymaster, ReentrancyGuard, TokenPaymaste

}

/**
* @dev Allow a new token or revoke previously enabled ERC20 token.
* Can only be called by the owner of the contract.
* @param _token ERC20 address
* @param _allowed if new token is being allowed it will be true, for revoking already supported token it will be false
* @notice If _token is set to zero address, it will revert with an error.
* After allow/deny of the token, it will emit an event TokenSupportedOrRevoked.
*/
function setTokenAllowed(address _token, bool _allowed) external payable onlyOwner {
require(_token != address(0), "Token address cannot be zero");
supportedTokens[_token] = _allowed;
emit TokenSupportedOrRevoked(_token, _allowed, msg.sender);
}

/**
* @dev Set a new overhead for unaccounted cost
* Can only be called by the owner of the contract.
Expand Down Expand Up @@ -251,16 +222,6 @@ contract BiconomyTokenPaymaster is BasePaymaster, ReentrancyGuard, TokenPaymaste
entryPoint.withdrawTo(withdrawAddress, amount);
}

/**
* @dev Returns true if this contract supports the given fee token address.
* @param _token ERC20 token address
*/
function isSupportedToken(
address _token
) public view virtual returns (bool) {
return supportedTokens[_token];
}

/**
* @dev Returns the exchange price of the token in wei.
*/
Expand Down Expand Up @@ -389,8 +350,6 @@ contract BiconomyTokenPaymaster is BasePaymaster, ReentrancyGuard, TokenPaymaste

address account = userOp.getSender();

require(isSupportedToken(feeToken), "TokenPaymaster: token is not supported as fee token") ;

uint256 costOfPost = userOp.maxFeePerGas * UNACCOUNTED_COST; // unaccountedEPGasOverhead

// This model assumes irrespective of priceSource exchangeRate is always sent from outside
Expand Down Expand Up @@ -451,12 +410,14 @@ contract BiconomyTokenPaymaster is BasePaymaster, ReentrancyGuard, TokenPaymaste
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
// instead of require could emit an event TokenPaymentDue()
// sender could be banned indefinitely or for certain period
}
emit TokenPaymasterOperation(account, address(feeToken), actualTokenCost + fee, fee, userOpHash, effectiveExchangeRate, priceSource);
}
// there could be else bit acting as deposit paymaster
else {
//in case above transferFrom failed, pay with deposit / notify at least
//sender could be banned indefinitely or for certain period
}
}

Expand Down
3 changes: 2 additions & 1 deletion contracts/token/oracles/OracleAggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
pragma solidity 0.8.17;

import "@openzeppelin/contracts/access/Ownable.sol";
import "./IOracleAggregator.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

contract OracleAggregator is Ownable{
contract OracleAggregator is Ownable, IOracleAggregator{

struct TokenInfo {
/* Number of decimals represents the precision of the price returned by the feed. For example,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@mean-finance/uniswap-v3-oracle": "^1.0.3",
"@openzeppelin/contracts": "4.8.1",
"@openzeppelin/contracts-upgradeable": "4.8.1",
"@pimlico/erc20-paymaster": "^0.0.1",
"@types/mocha": "^9.0.0",
"@uniswap/sdk-core": "^3.2.2",
"@uniswap/universal-router": "^1.4.1",
Expand Down
4 changes: 0 additions & 4 deletions scripts/deploy-token-paymaster-mumbai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ async function main() {
receipt = await tx.wait();
console.log("Oracle set for USDC");

tx = await tokenPaymaster.setTokenAllowed(usdcAddress, true);
receipt = await tx.wait();
console.log("Token is marked allowed");

tx = await tokenPaymaster.transferOwnership(owner);
receipt = await tx.wait();
console.log("ownership transferred: Token Paymaster");
Expand Down
4 changes: 0 additions & 4 deletions scripts/deploy-token-paymaster-polygon-mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ async function main() {
receipt = await tx.wait();
console.log("Oracle set for USDC");

tx = await tokenPaymaster.setTokenAllowed(usdcAddress, true);
receipt = await tx.wait();
console.log("Token is marked allowed");

await delay(5000)

tx = await tokenPaymaster.transferOwnership(owner);
Expand Down
63 changes: 63 additions & 0 deletions test/foundry/TokenPaymaster.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0;

import {DSTest} from "ds-test/test.sol";
import {OracleAggregator} from "../../contracts/token/oracles/OracleAggregator.sol";
import {IOracleAggregator} from "../../contracts/token/oracles/IOracleAggregator.sol";
import {BiconomyTokenPaymaster} from "../../contracts/token/BiconomyTokenPaymaster.sol";
import "@account-abstraction/contracts/core/EntryPoint.sol";
import {Utilities} from "./utils/Utilities.sol";
import {console} from "./utils/Console.sol";
import {Vm} from "forge-std/Vm.sol";

contract ContractTest is DSTest {
Vm internal immutable vm = Vm(HEVM_ADDRESS);

Utilities internal utils;
address payable[] internal users;

OracleAggregator _oa;
BiconomyTokenPaymaster _btpm;
EntryPoint _ep;

function setUp() public {
utils = new Utilities();
users = utils.createUsers(5);
}

function testCreateOA() public {

address payable alice = users[0];
// labels alice's address in call traces as "Alice [<address>]"
vm.label(alice, "Alice");

address payable bob = users[1];
vm.label(bob, "Bob");

_oa = new OracleAggregator(alice);

assertEq(_oa.owner(),alice);

vm.prank(alice);
}

function testCreateTokenPaymaster() public {

address payable alice = users[0];
// labels alice's address in call traces as "Alice [<address>]"
vm.label(alice, "Alice");

address payable bob = users[1];
vm.label(bob, "Bob");

_oa = new OracleAggregator(alice);
_ep = new EntryPoint();
_btpm = new BiconomyTokenPaymaster(alice, _ep, bob, _oa);

assertEq(_oa.owner(),alice);
assertEq(_btpm.owner(),alice);
assertEq(_btpm.verifyingSigner(),bob);

vm.prank(alice);
}
}
2 changes: 0 additions & 2 deletions test/token-paymaster/biconomy-token-paymaster-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ describe("Biconomy Token Paymaster", function () {
ZERO_ADDRESS_ROUTER
);

await sampleTokenPaymaster.setTokenAllowed(token.address, true);

smartWalletImp = await new BiconomyAccountImplementation__factory(deployer).deploy(
entryPoint.address
);
Expand Down
2 changes: 0 additions & 2 deletions test/token-paymaster/btpm-undeployed-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ describe("Biconomy Token Paymaster", function () {
ZERO_ADDRESS_ROUTER
);

await sampleTokenPaymaster.setTokenAllowed(token.address, true);

smartWalletImp = await new BiconomyAccountImplementation__factory(deployer).deploy(
entryPoint.address
);
Expand Down
9 changes: 7 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.1.tgz#709cfc4bbb3ca9f4460d60101f15dac6b7a2d5e4"
integrity sha512-xQ6eUZl+RDyb/FiZe1h+U7qr/f4p/SrTSQcTPH2bjur3C5DbuW/zFgCU/b1P/xcIaEqJep+9ju4xDRi3rmChdQ==

"@openzeppelin/contracts@^4.7.3":
"@openzeppelin/contracts@^4.7.3", "@openzeppelin/contracts@^4.8.2":
version "4.8.3"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.3.tgz#cbef3146bfc570849405f59cba18235da95a252a"
integrity sha512-bQHV8R9Me8IaJoJ2vPG4rXcL7seB7YVuskr4f+f5RyOStSZetwzkWtoqDMl5erkBJy0lDRUnIR2WIkPiC0GJlg==
Expand Down Expand Up @@ -3373,7 +3373,7 @@ ethers@^4.0.40:
uuid "2.0.1"
xmlhttprequest "1.8.0"

ethers@^5.6.8, ethers@^5.7.0, ethers@^5.7.1:
ethers@^5.6.8, ethers@^5.7.0, ethers@^5.7.1, ethers@^5.7.2:
version "5.7.2"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.7.2.tgz#3a7deeabbb8c030d4126b24f84e525466145872e"
integrity sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==
Expand Down Expand Up @@ -6537,6 +6537,11 @@ slice-ansi@^4.0.0:
astral-regex "^2.0.0"
is-fullwidth-code-point "^3.0.0"

solady@^0.0.90:
version "0.0.90"
resolved "https://registry.yarnpkg.com/solady/-/solady-0.0.90.tgz#2075349dfa6909b05ed04031f3b609ddbcd73598"
integrity sha512-NSc0mkfJo2CeKfFfyED1qbBQ8ofvDFxpBb0BLJ/wx2ZN7vCAYl8sp/j6TIIMdPb0BDvOKl2Rie9dVum+KIKeVA==

[email protected]:
version "0.7.3"
resolved "https://registry.yarnpkg.com/solc/-/solc-0.7.3.tgz#04646961bd867a744f63d2b4e3c0701ffdc7d78a"
Expand Down

0 comments on commit e6d8527

Please sign in to comment.