-
Notifications
You must be signed in to change notification settings - Fork 88
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
Showing
26 changed files
with
2,357 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
||
# generated docs | ||
generated-markups | ||
|
||
# editors | ||
.idea |
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,41 @@ | ||
const path = require('path'); | ||
const tsconfigPath = path.join(__dirname, 'tsconfig.json'); | ||
module.exports = { | ||
root: true, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:mocha/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
}, | ||
plugins: ['mocha'], | ||
env: { | ||
commonjs: true, | ||
node: true, | ||
mocha: true, | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*.ts'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: [tsconfigPath], | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['mocha', '@typescript-eslint'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:mocha/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
rules: { | ||
'@typescript-eslint/no-misused-promises': 'error', | ||
'@typescript-eslint/no-floating-promises': 'error', | ||
}, | ||
}, | ||
], | ||
}; |
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,16 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
||
# generated docs | ||
generated-markups | ||
|
||
# editors | ||
.idea |
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,16 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
||
# generated docs | ||
generated-markups | ||
|
||
# editors | ||
.idea |
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,4 @@ | ||
module.exports = { | ||
singleQuote: true, | ||
bracketSpacing: 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,70 @@ | ||
# TSB contracts deploy | ||
|
||
This package is used to compile, deploy, test and keep track of the contracts we use in our environments. | ||
|
||
## Compilation | ||
|
||
The source code of the contracts is imported via `npm` dependencies (except for some mocks used for testing). For | ||
example the instant giveaway contract `SignedMultiGiveaway.sol` is imported from the | ||
package `@sandbox-smart-contracts/giveaway` that is in this same monorepo by adding the dependency to the `package.json` | ||
file. | ||
|
||
We use `hardhat` to compile the project and to compile code from other packages we have a specific | ||
task `importedPackages` that adapts the compilation workflow to our needs. The task is configured via the | ||
key `importedPackages` in the `hardhat.config.ts` file. `importedPackages` is a javascript object. The keys are the | ||
package name and the value is the paths to the source code inside the package, for example: | ||
|
||
``` solidity | ||
const importedPackages = { | ||
'@sandbox-smart-contracts/giveaway': 'contracts/SignedMultiGiveaway.sol', | ||
}; | ||
``` | ||
|
||
## Deployment | ||
|
||
To deploy the contract we use [hardhat-deploy](https://github.com/wighawag/hardhat-deploy) you can check the manual for | ||
the specifics, the only think you must take into account is to use the Fully Qualified Name of the contract when | ||
deploying it ( | ||
see: [reading-artifacts](https://hardhat.org/hardhat-runner/docs/advanced/artifacts#reading-artifacts)), for | ||
example: `'@sandbox-smart-contracts/giveaway/contracts/SignedMultiGiveaway.sol:SignedMultiGiveaway'` for the | ||
`SignedMultiGiveaway` contract. | ||
|
||
To execute a deployment run: `yarn deploy --network NETWORK --tags SOMETAGS` | ||
where: | ||
|
||
- `NETWORK` is the network name like: `mumbai`, `goerli`, `polygon`, `mainet`, etc | ||
- `SOMETAGS` are the tags used to limit which deployment scripts will be executed ( | ||
see:[hardhat-deploy](https://github.com/wighawag/hardhat-deploy) configuration) | ||
|
||
## Testing | ||
|
||
We assume that the imported contracts are well tested in their own package by having enough unit tests and more that 80% | ||
coverage. This repo contains integrations tests and tests that verify the integrity of the system. For example in the | ||
case of the `SignedMultiGiveaway` contract we check the roles and the users assigned to them are correctly configured. | ||
|
||
The tests can be run in different contexts: | ||
|
||
- on hardhat: | ||
- run all the deployment scripts just to test them: `yarn deploy` | ||
- run the integration tests using `hardhat-deploy` fixtures: `yarn test` | ||
- on a real network `testnet` or `mainnet`, run the integration tests over contracts already deployed and fail if | ||
something is wrong, for example: `yarn test --network mumbai` | ||
- to run on a fork of some network the following environment variables must be set: | ||
- HARDHAT_DEPLOY_FIXTURE=true | ||
- HARDHAT_FORK=mumbai | ||
- HARDHAT_DEPLOY_ACCOUNTS_NETWORK=mumbai | ||
|
||
and then `yarn test` can be executed for integration tests or `yarn deploy` | ||
with or without tags to test just the deployment scripts. | ||
|
||
To simplify the execution of the integration tests over forks the following targets are added to the package.json | ||
file: `fork:mainnet`, `fork:polygon`, `fork:goerli` and `fork:mumbai`. | ||
|
||
# Adding contract from a new package | ||
|
||
- add the dependency to the `package.json` file as usual (`yarn add`). | ||
- add an entry to the `importedPackages` in the `hardhat.config.ts` file so the code is compiled. | ||
- add the deployment scripts to the `deploy` directory. Check | ||
the [hardhat-deploy](https://github.com/wighawag/hardhat-deploy) docs on how to write deployments scripts. | ||
- In the deployment scripts use the Fully Qualified Name of the contract, | ||
see: [reading-artifacts](https://hardhat.org/hardhat-runner/docs/advanced/artifacts#reading-artifacts) |
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,26 @@ | ||
//SPDX-License-Identifier: MIT | ||
// solhint-disable-next-line compiler-version | ||
pragma solidity 0.8.2; | ||
|
||
contract TrustedForwarderMock { | ||
|
||
struct ForwardRequest { | ||
address from; | ||
address to; | ||
uint256 value; | ||
uint256 gas; | ||
uint256 nonce; | ||
bytes data; | ||
} | ||
|
||
function execute(ForwardRequest calldata req, bytes calldata) | ||
public | ||
payable | ||
returns (bool, bytes memory) | ||
{ | ||
(bool success, bytes memory returndata) = | ||
req.to.call{gas : req.gas, value : req.value}(abi.encodePacked(req.data, req.from)); | ||
assert(gasleft() > req.gas / 63); | ||
return (success, returndata); | ||
} | ||
} |
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,30 @@ | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
|
||
const func: DeployFunction = async function ( | ||
hre: HardhatRuntimeEnvironment | ||
): Promise<void> { | ||
const {deployments, getNamedAccounts} = hre; | ||
const {deployer, upgradeAdmin, sandAdmin} = await getNamedAccounts(); | ||
const TRUSTED_FORWARDER = await deployments.get('TRUSTED_FORWARDER_V2'); | ||
await deployments.deploy('MultiGiveawayV1', { | ||
from: deployer, | ||
contract: | ||
'@sandbox-smart-contracts/giveaway/contracts/SignedMultiGiveaway.sol:SignedMultiGiveaway', | ||
log: true, | ||
skipIfAlreadyDeployed: true, | ||
proxy: { | ||
owner: upgradeAdmin, | ||
proxyContract: 'OptimizedTransparentProxy', | ||
execute: { | ||
methodName: 'initialize', | ||
args: [TRUSTED_FORWARDER.address, sandAdmin], | ||
}, | ||
upgradeIndex: 0, | ||
}, | ||
}); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['MultiGiveawayV1', 'MultiGiveawayV1_deploy', 'L2']; | ||
func.dependencies = ['TRUSTED_FORWARDER_V2']; |
33 changes: 33 additions & 0 deletions
33
packages/deploy/deploy/100_claim/60_multi_claim_role_setup.ts
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,33 @@ | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
|
||
const func: DeployFunction = async function ( | ||
hre: HardhatRuntimeEnvironment | ||
): Promise<void> { | ||
const {deployments, getNamedAccounts} = hre; | ||
const {execute, read, catchUnknownSigner} = deployments; | ||
const {sandAdmin, backendCashbackWallet} = await getNamedAccounts(); | ||
const signerRole = await read('MultiGiveawayV1', 'SIGNER_ROLE'); | ||
if ( | ||
!(await read( | ||
'MultiGiveawayV1', | ||
'hasRole', | ||
signerRole, | ||
backendCashbackWallet | ||
)) | ||
) { | ||
await catchUnknownSigner( | ||
execute( | ||
'MultiGiveawayV1', | ||
{from: sandAdmin, log: true}, | ||
'grantRole', | ||
signerRole, | ||
backendCashbackWallet | ||
) | ||
); | ||
} | ||
}; | ||
|
||
export default func; | ||
func.tags = ['MultiGiveawayV1', 'MultiGiveawayV1_role_setup', 'L2']; | ||
func.dependencies = ['MultiGiveawayV1_deploy']; |
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,16 @@ | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
|
||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const {deployments, getNamedAccounts} = hre; | ||
const {deploy} = deployments; | ||
|
||
const {deployer} = await getNamedAccounts(); | ||
await deploy('TRUSTED_FORWARDER_V2', { | ||
from: deployer, | ||
contract: 'TrustedForwarderMock', | ||
log: true, | ||
}); | ||
}; | ||
export default func; | ||
func.tags = ['TRUSTED_FORWARDER', 'TRUSTED_FORWARDER_V2']; |
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 @@ | ||
5 |
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 @@ | ||
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 @@ | ||
80001 |
Oops, something went wrong.
789ef58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage for this commit
Coverage Report