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

feat: add erc20 paymaster #6

Merged
merged 46 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3a4404f
feat: add erc20 paymaster
aliXsed Jan 25, 2024
e74cd34
chore: remove unused imports
aliXsed Jan 25, 2024
f2f8194
chore: fix whitespacing
aliXsed Jan 25, 2024
666fc35
fix: remove granting role to admin as it's done in base
aliXsed Jan 25, 2024
b74cd7a
Merge branch 'main' into aliX/nodl-paymaster
aliXsed Jan 25, 2024
1716276
fix: format and warnings
aliXsed Jan 25, 2024
597987c
Merge branch 'main' into aliX/nodl-paymaster
aliXsed Jan 26, 2024
bcfb8ba
test: add nonce option to deploy contract and add a Erc20Paymaster test
aliXsed Jan 26, 2024
b01c715
feat: revoke price oracle role for nodl-paymaster plus more tests
aliXsed Jan 30, 2024
cfa1bfa
Merge branch 'main' into aliX/nodl-paymaster
aliXsed Jan 30, 2024
a2c04d2
test(Erc20Paymaster): fix "Non Admin cannot grant or revoke roles"
aliXsed Jan 30, 2024
dc90979
test: random user can mint NFT using nodl paymaster
aliXsed Jan 30, 2024
c003edd
test: ensure transaction published in block + tidy up
aliXsed Jan 31, 2024
eec6dd7
test: use local node for testing, setup eth provider correctly
aliXsed Feb 6, 2024
3ac3c1a
feat: enable reading next token id from ContentSignNfT plus checking …
aliXsed Feb 7, 2024
4e5392f
test: get gas price from provider for calcs to match paymaster
aliXsed Feb 8, 2024
9f3ae8f
test: remove approval for paymaster
aliXsed Feb 8, 2024
7bde422
test: remove tranferring eth to user wallet
aliXsed Feb 8, 2024
3a819e5
feat: Make mint and burn fail if cap is exceeded
aliXsed Feb 9, 2024
b1e915d
test: fix all tests to wait for tx inclusion and explicitly specify g…
aliXsed Feb 9, 2024
ac0a005
test(Erc20Paymaster): fix reading fee price freshly from contract
aliXsed Feb 9, 2024
a2277fa
Update contracts/test/paymasters/Erc20Paymaster.test.ts
aliXsed Feb 11, 2024
d694959
feat(NODL): override decimal function
aliXsed Feb 11, 2024
4bce915
feat(Erc20Paymaster): revert on too high fee explicitly
aliXsed Feb 12, 2024
0936b67
test(Erc20Paymaster): check paymaster failures
aliXsed Feb 12, 2024
f0d89e7
test(Erc20Paymaster): fix fee too high test
aliXsed Feb 12, 2024
c599075
test(Erc20Paymaster): fix "Transaction fails if fee is too high"
aliXsed Feb 12, 2024
ce82446
test(Erc20Paymaster): remove explicit nonce management
aliXsed Feb 12, 2024
30b8dc7
test: remove explicit nonce management
aliXsed Feb 12, 2024
ab29a50
chore: enforce format check
aliXsed Feb 12, 2024
1372ae5
test: separate getRandomWallet from getWallet
aliXsed Feb 13, 2024
1a32efc
Merge branch 'main' into aliX/nodl-paymaster
aliXsed Feb 13, 2024
8dc6599
chore: fix format
aliXsed Feb 13, 2024
339c9a4
chore: start zksync in detached mode
aliXsed Feb 13, 2024
0c56484
chore: add extra delay for service to be fully up
aliXsed Feb 13, 2024
c87ff9c
chore: try checking port to run test
aliXsed Feb 13, 2024
5044924
chore: check port 8545 alongside 3050
aliXsed Feb 13, 2024
50defc6
chore: extra wait
aliXsed Feb 13, 2024
f481207
chore: use different detach mode for docker
aliXsed Feb 13, 2024
e6f1d60
chore: print docker logs while waiting
aliXsed Feb 13, 2024
8bbfe91
ci: fix service in the background
aliXsed Feb 13, 2024
88726b7
ci: alternative approach
aliXsed Feb 13, 2024
57fdaa4
ci: another attempt
aliXsed Feb 13, 2024
445ce34
ci: fix env
aliXsed Feb 13, 2024
15ce634
ci: extra wait
aliXsed Feb 13, 2024
bbf7bde
ci: kill better
aliXsed Feb 13, 2024
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
16 changes: 7 additions & 9 deletions contracts/contracts/NODL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC2
import {ERC20Capped} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";

contract NODL is ERC20, ERC20Burnable, ERC20Capped, AccessControl {
contract NODL is ERC20Burnable, ERC20Capped, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
uint256 public constant MAX_SUPPLY = 21_000_000_000;
ETeissonniere marked this conversation as resolved.
Show resolved Hide resolved
uint8 public constant DECIMALS = 11;
ETeissonniere marked this conversation as resolved.
Show resolved Hide resolved

constructor(address defaultAdmin, address minter) ERC20("Nodle Token", "NODL") ERC20Capped(21000000000 * (10 ** 18)) {

constructor(address defaultAdmin, address minter) ERC20("Nodle Token", "NODL") ERC20Capped(MAX_SUPPLY * (10 ** DECIMALS)) {
_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
_grantRole(MINTER_ROLE, minter);
}
Expand All @@ -19,12 +22,7 @@ contract NODL is ERC20, ERC20Burnable, ERC20Capped, AccessControl {
_mint(to, amount);
}

// The following functions are overrides required by Solidity.

function _update(address from, address to, uint256 value)
internal
override(ERC20, ERC20Capped)
{
super._update(from, to, value);
function _update(address from, address to, uint256 value) internal override(ERC20, ERC20Capped) {
ERC20Capped._update(from, to, value);
}
}
45 changes: 30 additions & 15 deletions contracts/test/NODL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ describe("NODL", function () {
let tokenContract: Contract;
let ownerWallet: Wallet;
let userWallet: Wallet;
const mintAmount = 1000n;

before(async function () {
ownerWallet = getWallet(LOCAL_RICH_WALLETS[0].privateKey);
userWallet = getWallet(LOCAL_RICH_WALLETS[1].privateKey);

tokenContract = await deployContract("NODL", [ownerWallet.address, ownerWallet.address], { wallet: ownerWallet, silent: true, skipChecks: true });
await tokenContract.waitForDeployment();
});

it("Should be deployed with no supply", async function () {
Expand All @@ -22,10 +24,10 @@ describe("NODL", function () {

it("Should be mintable", async () => {
const balanceBefore = await tokenContract.balanceOf(userWallet.address);
const mintAmount = ethers.parseEther("1000");
const initialSupply = await tokenContract.totalSupply();

await tokenContract.mint(userWallet.address, mintAmount);
const minTx = await tokenContract.connect(ownerWallet).mint(userWallet.address, mintAmount);
await minTx.wait();

const balanceAfter = await tokenContract.balanceOf(userWallet.address);
expect(balanceAfter).to.equal(balanceBefore + mintAmount);
Expand All @@ -36,20 +38,32 @@ describe("NODL", function () {

it("Should be burnable", async () => {
const balanceBefore = await tokenContract.balanceOf(userWallet.address);
const burnAmount = ethers.parseEther("1000");
const initialSupply = await tokenContract.totalSupply();
const burnAmount = mintAmount/2n;

await tokenContract.connect(userWallet).burn(burnAmount);
const userBurnTx = await tokenContract.connect(userWallet).burn(burnAmount);
await userBurnTx.wait();

const balanceAfter = await tokenContract.balanceOf(userWallet.address);
expect(balanceAfter).to.equal(balanceBefore - burnAmount);
const balanceAfterUserBurn = await tokenContract.balanceOf(userWallet.address);
expect(balanceAfterUserBurn).to.equal(balanceBefore - burnAmount);
const supplyAfterUserBurn = await tokenContract.totalSupply();
expect(supplyAfterUserBurn).to.equal(initialSupply - burnAmount);

const finalSupply = await tokenContract.totalSupply();
expect(finalSupply).to.equal(initialSupply - burnAmount);
const userApproveTx = await tokenContract.connect(userWallet).approve(ownerWallet.address, burnAmount);
await userApproveTx.wait();

const approvedBurnTx = await tokenContract.connect(ownerWallet).burnFrom(userWallet.address, burnAmount);
await approvedBurnTx.wait();

const balanceAfterApprovedBurn = await tokenContract.balanceOf(userWallet.address);
expect(balanceAfterApprovedBurn).to.equal(balanceBefore - mintAmount);

const supplyAfterApprovedBurn = await tokenContract.totalSupply();
expect(supplyAfterApprovedBurn).to.equal(initialSupply - mintAmount);
});

it("Has a max supply of 21 billion", async () => {
const maxSupply = ethers.parseEther("21000000000");
const maxSupply = ethers.parseUnits("21000000000", 11);
const cap = await tokenContract.cap();
expect(cap).to.equal(maxSupply);
});
Expand All @@ -59,12 +73,13 @@ describe("NODL", function () {
const currentSupply = await tokenContract.totalSupply();

const maxMint = cap - currentSupply;
await tokenContract.mint(userWallet.address, maxMint);
const mintAllTx = await tokenContract.connect(ownerWallet).mint(userWallet.address, maxMint);
await mintAllTx.wait();

expect(await tokenContract.balanceOf(userWallet.address)).to.equal(maxMint);
expect(await tokenContract.totalSupply()).to.equal(cap);

await expect(
tokenContract.mint(userWallet.address, 1)
).to.be
.revertedWithCustomError(tokenContract, "ERC20ExceededCap")
.withArgs(cap + 1n, cap);
const mintAboveCapTx = tokenContract.connect(ownerWallet).mint(userWallet.address, 1);
await expect(mintAboveCapTx).to.be.revertedWithCustomError(tokenContract, "ERC20ExceededCap").withArgs(cap + 1n, cap);
});
});
Loading