-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/PP-278/PP-329/tasks-over-scripts (#75)
* feat: implement hardhat tasks * chore: lint * chore: no .vscode folder * fix: typo on function, relocate map creation * chore: lint Co-authored-by: Christos Otarola <christos@Christoss-MacBook-Pro.local>
- Loading branch information
Showing
10 changed files
with
250 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ artifacts | |
/build | ||
/dist | ||
/contracts-exposed | ||
|
||
.vscode |
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 @@ | ||
{"hardhat.31337":{"Penalizer":"0x5FbDB2315678afecb367f032d93F642f64180aa3","RelayHub":"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512","SmartWallet":"0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0","SmartWalletFactory":"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9","DeployVerifier":"0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9","RelayVerifier":"0x5FC8d32690cc91D4c39d9d3abcBD16989F875707","CustomSmartWallet":"0x0165878A594ca255338adfa4d48449f69242Eb8F","CustomSmartWalletFactory":"0xa513E6E4b8f2a923D98304ec87F64353C4D5C853","CustomSmartWalletDeployVerifier":"0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6","UtilToken":"0x610178dA211FEF7D417bC0e6FeD39F05609AD788","VersionRegistry":"0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"},"regtest.33":{"Penalizer":"0x77A151FE2Ac2300Ccc89FD00330Add038e6e6B45","RelayHub":"0x05840bf34268900b255eFdeAb4E8b18A74Ec822E","SmartWallet":"0xE66d6095193f9Bec61F46d47EB2AC3C4315b01F1","SmartWalletFactory":"0x55898Faccf2D03C6B4d0564b33cC6D397Ca32A17","DeployVerifier":"0xe3d09A82a6f07Ca1B4C6964866075473531E426E","RelayVerifier":"0x9F54ffdB097e4c87C539bcA6DBaeE4BA5F74700C","CustomSmartWallet":"0x4F64cCeC8e2692Bf674f5EAa4E0170B14db8e709","CustomSmartWalletFactory":"0x151A4b94c288a6be9eE48d63949b1d44Dc4e2999","CustomSmartWalletDeployVerifier":"0x091E9C08dA594c831002309E139389d8eCa2A99e","UtilToken":"0xB3647664cD22BcC7B1defEbD3767Df9a0B3E4009","VersionRegistry":"0xBa755AEF160f11185Fc2726DAdd9D3B029aEE50f"}} |
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
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,83 @@ | ||
import { ContractTransaction } from 'ethers'; | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
import { getExistingConfig } from './deploy'; | ||
|
||
export const allowTokens = async ( | ||
taskArgs: { tokenlist: string }, | ||
hre: HardhatRuntimeEnvironment | ||
) => { | ||
const tokenAddresses = taskArgs.tokenlist.split(','); | ||
|
||
const { ethers, network } = hre; | ||
|
||
if (!network) { | ||
throw new Error('Unknown Network'); | ||
} | ||
|
||
const { chainId } = network.config; | ||
|
||
if (!chainId) { | ||
throw new Error('Unknown Chain Id'); | ||
} | ||
|
||
const contractAddresses = getExistingConfig(); | ||
|
||
if (!contractAddresses) { | ||
throw new Error('No contracts deployed'); | ||
} | ||
|
||
const networkChainKey = `${network.name}.${chainId}`; | ||
|
||
const deployVerifierAddress = | ||
contractAddresses[networkChainKey].DeployVerifier; | ||
const relayVerifierAddress = contractAddresses[networkChainKey].RelayVerifier; | ||
const customDeployVerifierAddress = | ||
contractAddresses[networkChainKey].CustomSmartWalletDeployVerifier; | ||
|
||
if (!deployVerifierAddress) { | ||
throw new Error('Could not obtain deploy verifier address'); | ||
} | ||
|
||
if (!relayVerifierAddress) { | ||
throw new Error('Could not obtain relay verifier address'); | ||
} | ||
|
||
if (!customDeployVerifierAddress) { | ||
throw new Error('Could not obtain custom deploy verifier address'); | ||
} | ||
|
||
const deployVerifier = await ethers.getContractAt( | ||
'DeployVerifier', | ||
deployVerifierAddress | ||
); | ||
const relayVerifier = await ethers.getContractAt( | ||
'RelayVerifier', | ||
relayVerifierAddress | ||
); | ||
const customDeployVerifier = await ethers.getContractAt( | ||
'CustomSmartWalletDeployVerifier', | ||
customDeployVerifierAddress | ||
); | ||
|
||
const verifierMap: Map< | ||
string, | ||
{ acceptToken: (tokenAddress: string) => Promise<ContractTransaction> } | ||
> = new Map(); | ||
verifierMap.set('deployVerifier', deployVerifier); | ||
verifierMap.set('relayVerifier', relayVerifier); | ||
verifierMap.set('customDeployVerifier', customDeployVerifier); | ||
|
||
for (const tokenAddress of tokenAddresses) { | ||
for (const [key, verifier] of verifierMap) { | ||
try { | ||
await verifier.acceptToken(tokenAddress); | ||
} catch (error) { | ||
console.error( | ||
`Error adding token with address ${tokenAddress} to allowed tokens on ${key}` | ||
); | ||
throw error; | ||
} | ||
} | ||
} | ||
console.log('Tokens allowed successfully!'); | ||
}; |
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,65 @@ | ||
import { expect, use } from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { Contract } from 'ethers'; | ||
import fs from 'fs'; | ||
import * as hre from 'hardhat'; | ||
import { ethers } from 'hardhat'; | ||
import sinon from 'sinon'; | ||
import { | ||
allowTokens | ||
} from '../../scripts/allowTokens'; | ||
|
||
use(chaiAsPromised); | ||
|
||
describe('Allow Tokens Script', function () { | ||
describe('allowTokens', function () { | ||
const taskArgs = { tokenlist: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7' }; | ||
|
||
const contractAddresses = { | ||
Penalizer: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
RelayHub: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
SmartWallet: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
SmartWalletFactory: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
DeployVerifier: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
RelayVerifier: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
CustomSmartWallet: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
CustomSmartWalletFactory: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
CustomSmartWalletDeployVerifier: | ||
'0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
VersionRegistry: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
UtilToken: '0x145845fd06c85B7EA1AA2d030E1a747B3d8d15D7', | ||
}; | ||
|
||
const chainContractAddresses = { | ||
'hardhat.33': contractAddresses, | ||
}; | ||
|
||
beforeEach(function () { | ||
sinon.stub(fs, 'existsSync').returns(true); | ||
sinon | ||
.stub(fs, 'readFileSync') | ||
.returns(JSON.stringify(chainContractAddresses)); | ||
hre.network.config.chainId = 33; | ||
}); | ||
|
||
afterEach(function () { | ||
sinon.restore(); | ||
}); | ||
|
||
it('should allow a list of tokens', async function () { | ||
const stubContract = sinon.createStubInstance(Contract); | ||
stubContract.acceptToken = () => undefined; | ||
sinon.stub(ethers, 'getContractAt').resolves(stubContract); | ||
await expect(allowTokens(taskArgs, hre)).to.not.be.rejected; | ||
}); | ||
|
||
it('should throw error and print it if token cannot be allowed', async function () { | ||
const stubContract = sinon.createStubInstance(Contract); | ||
stubContract.acceptToken = () => { | ||
throw new Error(); | ||
}; | ||
sinon.stub(ethers, 'getContractAt').resolves(stubContract); | ||
await expect(allowTokens(taskArgs, hre)).to.be.rejected; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.