-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3fa31a
commit 0a44f7c
Showing
4 changed files
with
202 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
library LibAddress { | ||
function isContract(address _account) internal view returns (bool) { | ||
if (_account == address(0)) { | ||
return false; | ||
} | ||
|
||
uint256 size; | ||
assembly { | ||
size := extcodesize(_account) | ||
} | ||
return size > 0; | ||
} | ||
|
||
function functionExists(address _contract, string memory _func) internal view returns (bool) { | ||
bytes4 selector = bytes4(keccak256(bytes(_func))); | ||
bytes memory bytecode = _contract.code; | ||
|
||
// Check if the bytecode contains the function selector | ||
for (uint i = 0; i < bytecode.length - 3; i++) { | ||
if (bytecode[i] == selector[0] && bytecode[i + 1] == selector[1] && bytecode[i + 2] == selector[2] && bytecode[i + 3] == selector[3]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//@ts-ignore | ||
import { run, ethers } from "hardhat"; | ||
import { | ||
convertFacetAndSelectorsToString, | ||
DeployUpgradeTaskArgs, | ||
FacetsAndAddSelectors, | ||
} from "../../tasks/deployUpgrade"; | ||
import { maticGBMDiamond } from "../constants"; | ||
|
||
export async function deployUpgrade() { | ||
const facets: FacetsAndAddSelectors[] = [ | ||
{ | ||
facetName: "GBMFacet", | ||
addSelectors: [ | ||
"function closeAuction(uint256 _auctionID) external" | ||
], | ||
removeSelectors: [], | ||
}, | ||
]; | ||
|
||
const joined = convertFacetAndSelectorsToString(facets); | ||
|
||
const args: DeployUpgradeTaskArgs = { | ||
diamondUpgrader: "0x585E06CA576D0565a035301819FD2cfD7104c1E8", | ||
diamondAddress: maticGBMDiamond, | ||
facetsAndAddSelectors: joined, | ||
useLedger: true, | ||
useMultisig: false, | ||
initAddress: ethers.constants.AddressZero, | ||
initCalldata: "0x", | ||
}; | ||
|
||
await run("deployUpgrade", args); | ||
} | ||
|
||
// We recommend this pattern to be able to use async/await everywhere | ||
// and properly handle errors. | ||
if (require.main === module) { | ||
deployUpgrade() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {BigNumberish} from "ethers"; | ||
import { ethers, network } from "hardhat"; | ||
import { impersonate } from "../scripts/helperFunctions"; | ||
import { deployUpgrade } from "../scripts/gbmBaazaar/upgrade-closeAuction"; | ||
import {ERC1155Generic, ERC20Generic, GBMFacet} from "../typechain"; | ||
import {ghstAddress, maticGBMDiamond} from "../scripts/constants"; | ||
import { expect } from "chai"; | ||
|
||
// constants for testing | ||
let auctionID = "19516"; | ||
// let auctionID = "19518"; | ||
|
||
let gbmFacet: GBMFacet; | ||
let diamondOwner: string; | ||
|
||
let auctionOwner: string; | ||
let stuckedBidder: string; | ||
let bidAmount: BigNumberish; | ||
let tokenID: BigNumberish; | ||
let tokenContract: string; | ||
let token: ERC1155Generic; | ||
let ghst: ERC20Generic; | ||
|
||
describe("Test Close Auction", async function () { | ||
before(async function () { | ||
this.timeout(300000); | ||
console.log("deploying upgrades "); | ||
await deployUpgrade(); | ||
|
||
diamondOwner = await (await ethers.getContractAt("OwnershipFacet", maticGBMDiamond)).owner() | ||
gbmFacet = (await ethers.getContractAt( | ||
"GBMFacet", | ||
maticGBMDiamond | ||
)) as GBMFacet; | ||
gbmFacet = await impersonate(diamondOwner, gbmFacet, ethers, network); | ||
ghst = await ethers.getContractAt("ERC20Generic", ghstAddress); | ||
}); | ||
|
||
it("Force close stucked auctions", async function () { | ||
auctionOwner = await (await gbmFacet.getAuctionInfo(auctionID)).owner; | ||
const auction = await gbmFacet.getAuctionInfo(auctionID) | ||
tokenID = auction.info.tokenID; | ||
stuckedBidder = auction.highestBidder; | ||
bidAmount = auction.highestBid; | ||
tokenContract = auction.tokenContract; | ||
token = (await ethers.getContractAt( | ||
"ERC1155Generic", | ||
tokenContract | ||
)) as ERC1155Generic; | ||
|
||
const balanceBefore = await token.balanceOf(auctionOwner, tokenID); | ||
const ghstBalanceBefore = await ghst.balanceOf(stuckedBidder); | ||
|
||
await (await gbmFacet.closeAuction(auctionID)).wait(); | ||
|
||
const balanceAfter = await token.balanceOf(auctionOwner, tokenID); | ||
const ghstBalanceAfter = await ghst.balanceOf(stuckedBidder); | ||
|
||
expect(balanceAfter).equal(balanceBefore.add(1)); | ||
expect(ghstBalanceAfter.sub(ghstBalanceBefore)).equal(bidAmount.mul(96).div(100)); | ||
}); | ||
}); |