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: use ethers v6 in the instant-giveaway pacakge #1157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 23 additions & 27 deletions packages/giveaway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,40 @@
}
},
"dependencies": {
"@openzeppelin/contracts-upgradeable": "^4.9.0"
"@openzeppelin/contracts-upgradeable": "^4.9.3"
adjisb marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@dlsl/hardhat-markup": "^1.0.0-rc.11",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@nomicfoundation/hardhat-chai-matchers": "1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/contracts-upgradeable": "^4.9.0",
"@dlsl/hardhat-markup": "^1.0.0-rc.14",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.2",
"@nomicfoundation/hardhat-ethers": "^3.0.4",
"@nomicfoundation/hardhat-network-helpers": "^1.0.9",
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@nomicfoundation/hardhat-verify": "^1.1.1",
"@release-it/keep-a-changelog": "^4.0.0",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.1.2",
"@types/chai": "^4.3.5",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.3.6",
"@types/mocha": "^10.0.1",
"@types/node": "^20.2.5",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"chai": "^4.3.7",
"dotenv": "^16.1.3",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"@types/node": "^20.6.3",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"chai": "^4.3.8",
"dotenv": "^16.3.1",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eth-sig-util": "^3.0.1",
"ethers": "^5.0.0",
"hardhat": "^2.14.1",
"ethers": "^6.7.1",
"hardhat": "^2.17.3",
"hardhat-gas-reporter": "^1.0.9",
"prettier": "^2.8.8",
"prettier-plugin-solidity": "^1.1.3",
"release-it": "^16.1.5",
"solhint": "^3.4.1",
"solhint": "^3.6.2",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.8.2",
"solidity-coverage": "^0.8.4",
"ts-node": "^10.9.1",
"typechain": "^8.2.0",
"typescript": "5.0.4"
"typechain": "^8.3.1",
"typescript": "^5.2.2"
}
}
84 changes: 48 additions & 36 deletions packages/giveaway/test/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {BigNumber, BigNumberish, Contract, Signer} from 'ethers';
import {
Claim,
compareClaim,
Expand All @@ -11,14 +10,15 @@ import {
} from './signature';
import {ethers} from 'hardhat';
import {expect} from 'chai';
import {Contract, Signer} from 'ethers';

export async function deploy(
name: string,
users: Signer[] = []
): Promise<Contract[]> {
const Contract = await ethers.getContractFactory(name);
const contract = await Contract.deploy();
await contract.deployed();
await contract.waitForDeployment();
const ret = [];
for (const s of users) {
ret.push(await contract.connect(s));
Expand All @@ -35,14 +35,14 @@ export async function deployWithProxy(

const Proxy = await ethers.getContractFactory('FakeProxy');
// This uses signers[0]
const proxy = await Proxy.deploy(contract[0].address);
await proxy.deployed();
const proxy = await Proxy.deploy(await contract[0].getAddress());
await proxy.waitForDeployment();
const ret = [];
for (let i = 0; i < contract.length; i++) {
ret[i] = await contract[i].attach(proxy.address);
ret[i] = await contract[i].attach(await proxy.getAddress());
}
// add implementation contract
ret.push(contract[0]);
ret.push(contract[contract.length - 1]);
return ret;
}

Expand Down Expand Up @@ -80,12 +80,18 @@ export async function setupSignedMultiGiveaway() {
]);

// Initialize
await contractAsDeployer.initialize(trustedForwarder.address, admin.address);
await contractAsDeployer.initialize(
await trustedForwarder.getAddress(),
await admin.getAddress()
);
// Grant roles.
const signerRole = await contractAsAdmin.SIGNER_ROLE();
await contractAsAdmin.grantRole(signerRole, signer.address);
await contractAsAdmin.grantRole(signerRole, await signer.getAddress());
const backofficeRole = await contractAsAdmin.BACKOFFICE_ROLE();
await contractAsAdmin.grantRole(backofficeRole, backofficeAdmin.address);
await contractAsAdmin.grantRole(
backofficeRole,
await backofficeAdmin.getAddress()
);

interface ERC721Balance {
tokenType: TokenType.ERC721 | TokenType.ERC721_SAFE;
Expand All @@ -111,7 +117,7 @@ export async function setupSignedMultiGiveaway() {
claims: Claim[]
) {
const pos = await balances(source, claims);
const postDest = await balances(dest.address, claims);
const postDest = await balances(await dest.getAddress(), claims);
for (const [idx, c] of claims.entries()) {
switch (c.tokenType) {
case TokenType.ERC20:
Expand All @@ -121,20 +127,16 @@ export async function setupSignedMultiGiveaway() {
const rDest = preDest[idx] as ERC20Claim;
const s = pos[idx] as ERC20Claim;
const sDest = postDest[idx] as ERC20Claim;
expect(s.amount).to.be.equal(
BigNumber.from(r.amount).sub(c.amount)
);
expect(sDest.amount).to.be.equal(
BigNumber.from(rDest.amount).add(c.amount)
);
expect(s.amount).to.be.equal(r.amount - c.amount);
expect(sDest.amount).to.be.equal(rDest.amount + c.amount);
}
break;
case TokenType.ERC721:
{
const r = pre[idx] as ERC721Balance;
const s = pos[idx] as ERC721Balance;
expect(r.owner).to.be.equal(contract.address);
expect(s.owner).to.be.equal(dest.address);
expect(r.owner).to.be.equal(await contract.getAddress());
expect(s.owner).to.be.equal(await dest.getAddress());
}
break;
}
Expand Down Expand Up @@ -203,12 +205,22 @@ export async function setupSignedMultiGiveaway() {
}
break;
case TokenType.ERC1155:
await c.token.mint(address, c.tokenId, c.amount, c.data);
await c.token.mint(
address,
c.tokenId,
c.amount,
ethers.getBytes(c.data)
);
break;
case TokenType.ERC1155_BATCH:
{
for (const [idx, tokenId] of c.tokenIds.entries()) {
await c.token.mint(address, tokenId, c.amounts[idx], c.data);
await c.token.mint(
address,
tokenId,
c.amounts[idx],
ethers.getBytes(c.data)
);
}
}
break;
Expand All @@ -223,42 +235,42 @@ export async function setupSignedMultiGiveaway() {
balances,
checkBalances,
signAndClaim: async (
claimIds: BigNumberish[],
claimIds: bigint[],
claims: Claim[],
signerUser = signer,
expiration = 0
) => {
await mintToContract(contract.address, claims);
const pre = await balances(contract.address, claims);
const preDest = await balances(dest.address, claims);
await mintToContract(await contract.getAddress(), claims);
const pre = await balances(await contract.getAddress(), claims);
const preDest = await balances(await dest.getAddress(), claims);
const {v, r, s} = await signedMultiGiveawaySignature(
contract,
signerUser.address,
signerUser,
claimIds,
expiration,
contract.address,
dest.address,
getClaimEntires(claims)
await contract.getAddress(),
await dest.getAddress(),
await getClaimEntires(claims)
);
await expect(
contract.claim(
[{v, r, s}],
claimIds,
expiration,
contract.address,
dest.address,
getClaimEntires(claims)
await contract.getAddress(),
await dest.getAddress(),
await getClaimEntires(claims)
)
)
.to.emit(contract, 'Claimed')
.withArgs(
claimIds,
contract.address,
dest.address,
compareClaim(claims),
other.address
await contract.getAddress(),
await dest.getAddress(),
compareClaim(await getClaimEntires(claims)),
await other.getAddress()
);
await checkBalances(contract.address, pre, preDest, claims);
await checkBalances(await contract.getAddress(), pre, preDest, claims);
},
signedGiveaway,
contract,
Expand Down
Loading
Loading