Skip to content

Commit

Permalink
[REG-1397] Return ERC20Mock to simple version, update USDCMock to per…
Browse files Browse the repository at this point in the history
…mit Upgradable (#364)

* [REG-1397] Return ERC20Mock to simple version, update USDCMock to permit Upgradable

* [REG-1397] versioning

* [REG-1397] versioning fix
  • Loading branch information
Armen-Arakelian authored Sep 13, 2024
1 parent b541ef2 commit 46f2d92
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ yarn lint:fix

npx hardhat clean
yarn compile
git add .
git add -u .
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.9.32

- Added permit functionality to usdcMock and make it upgradable

## v0.9.31

- Add `.smobler` Base TLD
Expand Down
99 changes: 97 additions & 2 deletions artifacts/USDC.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion artifacts/abi/USDC.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
9 changes: 2 additions & 7 deletions contracts/mocks/ERC20Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

pragma solidity ^0.8.0;

import '@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol';

contract ERC20Mock is ERC20PermitUpgradeable {
function initialize() external initializer {
__ERC20Permit_init('');
__ERC20_init_unchained('', '');
}
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract ERC20Mock is ERC20('', '') {
function mint(address account, uint256 amount) external {
_mint(account, amount);
}
Expand Down
9 changes: 7 additions & 2 deletions contracts/mocks/USDC.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// @author Unstoppable Domains, Inc.
// @date June 6th, 2024

import '@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol';

pragma solidity ^0.8.0;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
contract USDC is ERC20PermitUpgradeable {
function initialize() external initializer {
__ERC20Permit_init('USDC Mock');
__ERC20_init_unchained('USDC Mock', 'USDC');
}

contract USDC is ERC20('USDC Mock', 'USDC') {
function decimals() public view virtual override returns (uint8) {
return 6;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uns",
"version": "0.9.31",
"version": "0.9.32",
"description": "UNS contracts and tools",
"repository": "https://github.com/unstoppabledomains/uns.git",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion sandbox/state.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions test/mock/ERC20Mock.test.ts → test/mock/USDCMock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ import { ethers } from 'hardhat';
import { Signature } from 'ethers';
import { expect } from 'chai';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import { ERC20Mock } from '../../types/contracts/mocks/ERC20Mock';
import { USDC } from '../../types/contracts/mocks/USDC';
import { deployProxy } from '../../src/helpers';

describe('ERC20Mock', async () => {
describe('USDC', async () => {
let signers: SignerWithAddress[], owner: SignerWithAddress, user: SignerWithAddress, delegate: SignerWithAddress;

let erc20Mock: ERC20Mock;
let usdcMock: USDC;

before('', async () => {
signers = await ethers.getSigners();
[owner, user, delegate] = signers;

erc20Mock = (await deployProxy<ERC20Mock>(await ethers.getContractFactory('ERC20Mock'), [], {
usdcMock = (await deployProxy<USDC>(await ethers.getContractFactory('USDC'), [], {
initializer: false,
})) as ERC20Mock;
await erc20Mock.initialize();
})) as USDC;
await usdcMock.initialize();
});

describe('ERC20Permit', async () => {
it('should allow user to approve via permit and transfer tokens', async () => {
const value = 50;

await erc20Mock.mint(owner, value);
await usdcMock.mint(owner, value);

const nonce = await erc20Mock.nonces(owner.address);
const nonce = await usdcMock.nonces(owner.address);
const deadline = ethers.MaxUint256;

const domain = {
name: await erc20Mock.name(),
name: await usdcMock.name(),
version: '1',
chainId: (await ethers.provider.getNetwork()).chainId,
verifyingContract: await erc20Mock.getAddress(),
verifyingContract: await usdcMock.getAddress(),
};

const types = {
Expand All @@ -57,15 +57,15 @@ describe('ERC20Mock', async () => {
const signature = await owner.signTypedData(domain, types, permitData);
const { v, r, s } = Signature.from(signature);

await erc20Mock.permit(owner.address, user.address, value, deadline, v, r, s);
await usdcMock.permit(owner.address, user.address, value, deadline, v, r, s);

const allowance = await erc20Mock.allowance(owner.address, user.address);
const allowance = await usdcMock.allowance(owner.address, user.address);
expect(allowance).to.equal(value);

await erc20Mock.connect(user).transferFrom(owner.address, delegate.address, value);
await usdcMock.connect(user).transferFrom(owner.address, delegate.address, value);

const ownerBalance = await erc20Mock.balanceOf(owner.address);
const delegateBalance = await erc20Mock.balanceOf(delegate.address);
const ownerBalance = await usdcMock.balanceOf(owner.address);
const delegateBalance = await usdcMock.balanceOf(delegate.address);

expect(ownerBalance).to.equal(0);
expect(delegateBalance).to.equal(value);
Expand Down

0 comments on commit 46f2d92

Please sign in to comment.