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

[SC-861] Updated hardhat version to support ethers v6 #22

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('@nomiclabs/hardhat-ethers');
require('@nomiclabs/hardhat-etherscan');
require('@nomicfoundation/hardhat-ethers');
require('@nomicfoundation/hardhat-verify');
require('@nomicfoundation/hardhat-chai-matchers');
require('solidity-coverage');
require('hardhat-dependency-compiler');
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/delegating",
"version": "1.0.0",
"version": "1.0.1",
"description": "Set of contracts for delegating incentives",
"homepage": "https://github.com/1inch/delegating#readme",
"author": "1inch",
Expand All @@ -14,30 +14,30 @@
},
"license": "MIT",
"dependencies": {
"@1inch/token-plugins": "1.1.1",
"@1inch/farming": "3.0.1",
"@1inch/solidity-utils": "2.2.21",
"@openzeppelin/contracts": "4.8.2",
"@1inch/token-plugins": "1.1.2",
"@1inch/farming": "3.0.2",
"@1inch/solidity-utils": "3.0.1",
"@openzeppelin/contracts": "4.9.2",
"hardhat-dependency-compiler": "1.1.3"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "1.0.6",
"@nomiclabs/hardhat-ethers": "2.2.2",
"@nomiclabs/hardhat-etherscan": "3.1.7",
"@nomicfoundation/hardhat-chai-matchers": "2.0.1",
"@nomicfoundation/hardhat-ethers": "3.0.4",
"@nomicfoundation/hardhat-verify": "1.0.4",
"chai": "4.3.7",
"dotenv": "16.0.3",
"eslint": "8.36.0",
"eslint-config-standard": "17.0.0",
"dotenv": "16.3.1",
"eslint": "8.45.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-n": "15.6.1",
"eslint-plugin-n": "16.0.1",
"eslint-plugin-promise": "6.1.1",
"ethers": "5.7.2",
"hardhat": "2.13.0",
"hardhat-deploy": "0.11.25",
"ethers": "6.6.5",
"hardhat": "2.17.0",
"hardhat-deploy": "0.11.34",
"hardhat-gas-reporter": "1.0.9",
"rimraf": "4.4.0",
"rimraf": "5.0.1",
"solhint": "3.4.1",
"solidity-coverage": "0.8.2"
"solidity-coverage": "0.8.4"
},
"scripts": {
"test": "hardhat test --parallel",
Expand Down
100 changes: 50 additions & 50 deletions test/DelegationPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,128 +13,128 @@ describe('DelegationPlugin', function () {
async function initContracts () {
const Erc20PluginsMock = await ethers.getContractFactory('ERC20PluginsMock');
const erc20Plugins = await Erc20PluginsMock.deploy('ERC20PluginsMock', 'EPM', 5, ERC20_PLUGINS_GASLIMIT);
await erc20Plugins.deployed();
await erc20Plugins.waitForDeployment();
const DelegationPlugin = await ethers.getContractFactory('DelegationPlugin');
const delegationPlugin = await DelegationPlugin.deploy('basic1INCH', 'basic1INCH', erc20Plugins.address);
await delegationPlugin.deployed();
const delegationPlugin = await DelegationPlugin.deploy('basic1INCH', 'basic1INCH', erc20Plugins);
await delegationPlugin.waitForDeployment();
const amount = ether('1');
return { erc20Plugins, delegationPlugin, amount };
};

async function initAndMint () {
const { erc20Plugins, delegationPlugin, amount } = await initContracts();
await erc20Plugins.mint(addr1.address, amount);
await erc20Plugins.mint(addr1, amount);
return { erc20Plugins, delegationPlugin, amount };
}

async function initAndMintAndAddPluginWithDelegate () {
const { erc20Plugins, delegationPlugin, amount } = await initAndMint();
await erc20Plugins.addPlugin(delegationPlugin.address);
await delegationPlugin.delegate(delegatee.address);
await erc20Plugins.addPlugin(delegationPlugin);
await delegationPlugin.delegate(delegatee);
return { erc20Plugins, delegationPlugin, amount };
}

describe('delegate', function () {
it('should set delegate and emit Delegated event', async function () {
const { delegationPlugin } = await loadFixture(initContracts);
const tx = await delegationPlugin.delegate(delegatee.address);
const tx = await delegationPlugin.delegate(delegatee);
const receipt = await tx.wait();
expect(await delegationPlugin.delegated(addr1.address)).to.equal(delegatee.address);
expect(receipt.events[0].event).to.equal('Delegated');
expect(await delegationPlugin.delegated(addr1)).to.equal(delegatee.address);
expect(receipt.logs[0].eventName).to.equal('Delegated');
});

it('should does nothing and does not emit Delegated event when the same delegatee', async function () {
const { delegationPlugin } = await loadFixture(initContracts);
await delegationPlugin.delegate(delegatee.address);
const tx = await delegationPlugin.delegate(delegatee.address);
await delegationPlugin.delegate(delegatee);
const tx = await delegationPlugin.delegate(delegatee);
const receipt = await tx.wait();
expect(await delegationPlugin.delegated(addr1.address)).to.equal(delegatee.address);
expect(receipt.events.length).to.equal(0);
expect(await delegationPlugin.delegated(addr1)).to.equal(delegatee.address);
expect(receipt.logs.length).to.equal(0);
});

it('should not change delegatee balance when users pluginBalance is 0', async function () {
const { erc20Plugins, delegationPlugin } = await loadFixture(initAndMint);
expect(await erc20Plugins.pluginBalanceOf(delegationPlugin.address, addr1.address)).to.equal('0');
const delegateeBalanceBefore = await delegationPlugin.balanceOf(delegatee.address);
await delegationPlugin.delegate(delegatee.address);
expect(await delegationPlugin.balanceOf(delegatee.address)).to.equal(delegateeBalanceBefore);
expect(await erc20Plugins.pluginBalanceOf(delegationPlugin, addr1)).to.equal('0');
const delegateeBalanceBefore = await delegationPlugin.balanceOf(delegatee);
await delegationPlugin.delegate(delegatee);
expect(await delegationPlugin.balanceOf(delegatee)).to.equal(delegateeBalanceBefore);
});

it('should increase delegatee balance when users pluginBalance is not 0', async function () {
const { erc20Plugins, delegationPlugin, amount } = await loadFixture(initAndMint);
await erc20Plugins.addPlugin(delegationPlugin.address);
expect(await erc20Plugins.pluginBalanceOf(delegationPlugin.address, addr1.address)).to.equal(amount);
const delegateeBalanceBefore = await delegationPlugin.balanceOf(delegatee.address);
await delegationPlugin.delegate(delegatee.address);
expect(await delegationPlugin.balanceOf(delegatee.address)).to.equal(delegateeBalanceBefore.add(amount));
await erc20Plugins.addPlugin(delegationPlugin);
expect(await erc20Plugins.pluginBalanceOf(delegationPlugin, addr1)).to.equal(amount);
const delegateeBalanceBefore = await delegationPlugin.balanceOf(delegatee);
await delegationPlugin.delegate(delegatee);
expect(await delegationPlugin.balanceOf(delegatee)).to.equal(delegateeBalanceBefore + amount);
});

it('should increase new delegatee balance and decrease prev delegatee balance when user redelegate', async function () {
const { delegationPlugin, amount } = await loadFixture(initAndMintAndAddPluginWithDelegate);
const balanceBeforeDelegatee = await delegationPlugin.balanceOf(delegatee.address);
const balanceBeforeNewDelegatee = await delegationPlugin.balanceOf(newDelegatee.address);
await delegationPlugin.delegate(newDelegatee.address);
expect(await delegationPlugin.balanceOf(delegatee.address)).to.equal(balanceBeforeDelegatee.sub(amount));
expect(await delegationPlugin.balanceOf(newDelegatee.address)).to.equal(balanceBeforeNewDelegatee.add(amount));
const balanceBeforeDelegatee = await delegationPlugin.balanceOf(delegatee);
const balanceBeforeNewDelegatee = await delegationPlugin.balanceOf(newDelegatee);
await delegationPlugin.delegate(newDelegatee);
expect(await delegationPlugin.balanceOf(delegatee)).to.equal(balanceBeforeDelegatee - amount);
expect(await delegationPlugin.balanceOf(newDelegatee)).to.equal(balanceBeforeNewDelegatee + amount);
});
});

describe('updateBalances', function () {
async function initContractsAndDelegateWithWallets () {
const { erc20Plugins, delegationPlugin, amount } = await initContracts();
await erc20Plugins.mint(addr1.address, amount);
await erc20Plugins.mint(addr2.address, amount * 2n);
await erc20Plugins.connect(addr1).addPlugin(delegationPlugin.address);
await erc20Plugins.connect(addr2).addPlugin(delegationPlugin.address);
await delegationPlugin.connect(addr1).delegate(delegatee.address);
await delegationPlugin.connect(addr2).delegate(newDelegatee.address);
await erc20Plugins.mint(addr1, amount);
await erc20Plugins.mint(addr2, amount * 2n);
await erc20Plugins.connect(addr1).addPlugin(delegationPlugin);
await erc20Plugins.connect(addr2).addPlugin(delegationPlugin);
await delegationPlugin.connect(addr1).delegate(delegatee);
await delegationPlugin.connect(addr2).delegate(newDelegatee);
return { erc20Plugins, delegationPlugin, amount };
}

it('`address(0) -> addr1` should increase delegatee balance', async function () {
const { erc20Plugins, delegationPlugin, amount } = await loadFixture(initAndMint);
await delegationPlugin.delegate(delegatee.address);
const balanceBefore = await delegationPlugin.balanceOf(delegatee.address);
await erc20Plugins.addPlugin(delegationPlugin.address);
expect(await delegationPlugin.balanceOf(delegatee.address)).to.equal(balanceBefore.add(amount));
await delegationPlugin.delegate(delegatee);
const balanceBefore = await delegationPlugin.balanceOf(delegatee);
await erc20Plugins.addPlugin(delegationPlugin);
expect(await delegationPlugin.balanceOf(delegatee)).to.equal(balanceBefore + amount);
});

it('`addr1 -> address(0)` should decrease delegatee balance', async function () {
const { erc20Plugins, delegationPlugin, amount } = await loadFixture(initAndMint);
await delegationPlugin.delegate(delegatee.address);
await erc20Plugins.addPlugin(delegationPlugin.address);
const balanceBefore = await delegationPlugin.balanceOf(delegatee.address);
await erc20Plugins.removePlugin(delegationPlugin.address);
expect(await delegationPlugin.balanceOf(delegatee.address)).to.equal(balanceBefore.sub(amount));
await delegationPlugin.delegate(delegatee);
await erc20Plugins.addPlugin(delegationPlugin);
const balanceBefore = await delegationPlugin.balanceOf(delegatee);
await erc20Plugins.removePlugin(delegationPlugin);
expect(await delegationPlugin.balanceOf(delegatee)).to.equal(balanceBefore - amount);
});

it('`addr1 -> addr2` should change delegatee balances', async function () {
const { erc20Plugins, delegationPlugin, amount } = await loadFixture(initContractsAndDelegateWithWallets);
const transferAmount = amount / 2n;
const balanceBeforeDelegatee = await delegationPlugin.balanceOf(delegatee.address);
const balanceBeforeNewDelegatee = await delegationPlugin.balanceOf(newDelegatee.address);
await erc20Plugins.transfer(addr2.address, transferAmount);
expect(await delegationPlugin.balanceOf(delegatee.address)).to.equal(balanceBeforeDelegatee.sub(transferAmount));
expect(await delegationPlugin.balanceOf(newDelegatee.address)).to.equal(balanceBeforeNewDelegatee.add(transferAmount));
const balanceBeforeDelegatee = await delegationPlugin.balanceOf(delegatee);
const balanceBeforeNewDelegatee = await delegationPlugin.balanceOf(newDelegatee);
await erc20Plugins.transfer(addr2, transferAmount);
expect(await delegationPlugin.balanceOf(delegatee)).to.equal(balanceBeforeDelegatee - transferAmount);
expect(await delegationPlugin.balanceOf(newDelegatee)).to.equal(balanceBeforeNewDelegatee + transferAmount);
});
});

describe('ERC20 overrides', function () {
it('should not transfer', async function () {
const { delegationPlugin } = await loadFixture(initContracts);
await expect(delegationPlugin.transfer(addr2.address, ether('1')))
await expect(delegationPlugin.transfer(addr2, ether('1')))
.to.be.revertedWithCustomError(delegationPlugin, 'TransferDisabled');
});

it('should not transferFrom', async function () {
const { delegationPlugin } = await loadFixture(initContracts);
await expect(delegationPlugin.transferFrom(addr2.address, delegatee.address, ether('1')))
await expect(delegationPlugin.transferFrom(addr2, delegatee, ether('1')))
.to.be.revertedWithCustomError(delegationPlugin, 'TransferDisabled');
});

it('should not approve', async function () {
const { delegationPlugin } = await loadFixture(initContracts);
await expect(delegationPlugin.approve(addr2.address, ether('1')))
await expect(delegationPlugin.approve(addr2, ether('1')))
.to.be.revertedWithCustomError(delegationPlugin, 'ApproveDisabled');
});
});
Expand Down
Loading