-
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.
Merge pull request #1001 from thesandboxgame/feat/signedMultiGiveaway…
…_package Feat/signed multi giveaway package
- Loading branch information
Showing
22 changed files
with
3,790 additions
and
29 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,15 @@ | ||
module.exports = { | ||
singleQuote: true, | ||
bracketSpacing: false, | ||
plugins: ['prettier-plugin-solidity'], | ||
overrides: [ | ||
{ | ||
files: '*.sol', | ||
options: { | ||
printWidth: 120, | ||
tabWidth: 4, | ||
singleQuote: 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,6 @@ | ||
module.exports = { | ||
mocha: { | ||
grep: '@skip-on-coverage', // Find everything with this tag | ||
invert: true, // Run the grep's inverse set. | ||
}, | ||
}; |
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,21 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"plugins": ["prettier"], | ||
"rules": { | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"endOfLine": "auto" | ||
} | ||
], | ||
"code-complexity": ["error", 7], | ||
"compiler-version": ["error", "^0.8.0"], | ||
"const-name-snakecase": "off", | ||
"func-name-mixedcase": "off", | ||
"constructor-syntax": "error", | ||
"func-visibility": ["error", {"ignoreConstructors": true}], | ||
"not-rely-on-time": "off", | ||
"no-inline-assembly": "off", | ||
"reason-string": ["warn", {"maxLength": 64}] | ||
} | ||
} |
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 @@ | ||
# Signed Giveaways | ||
|
||
This is a hardhat project, see [https://hardhat.org](https://hardhat.org) | ||
|
||
The main contract gives rewards in any ERC20, ERC721 or ERC1155 when the backend authorize it via message signing. | ||
|
||
The message is composed of: | ||
|
||
- A list of signatures. If the contract holt too much value more than one signature is needed. Ideally the systems that | ||
sign must be independent. | ||
- A list of claim ids used by the backend to avoid double spending. | ||
- Expiration the expiration time of the message in unix timestamp. After the expiration the message cannot be used | ||
anymore. | ||
- From: usually the rewards must be transferred to the contract and this value is address(this), if a strategy with | ||
approve and transfer is used this is the address of the source. | ||
- To: the destination address that will get the rewards. | ||
- Claims: A list of union structs (ClaimEntry) that include: token type (ERC20, ERC721, ERC1155, etc), token address and | ||
a data field that depending on the token type may have: amount, tokenId, etc. | ||
|
||
# Usage | ||
|
||
```shell | ||
yarn hardhat help | ||
yarn hardhat test | ||
yarn hardhat coverage | ||
REPORT_GAS=true yarn hardhat test | ||
yarn hardhat markup | ||
``` | ||
|
||
# Deployment | ||
|
||
This package exports the contract source code, for deployments see: [@sandbox-smart-contract/deploy](../deploy) package. | ||
|
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,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
// solhint-disable-next-line compiler-version | ||
pragma solidity 0.8.18; | ||
|
||
/// @dev minimal ERC2771 handler to keep bytecode-size down | ||
/// based on: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.6.0/contracts/metatx/ERC2771Context.sol | ||
/// with an initializer for proxies and a mutable forwarder | ||
|
||
abstract contract ERC2771Handler { | ||
address internal _trustedForwarder; | ||
|
||
function __ERC2771Handler_initialize(address forwarder) internal { | ||
_trustedForwarder = forwarder; | ||
} | ||
|
||
function isTrustedForwarder(address forwarder) public view returns (bool) { | ||
return forwarder == _trustedForwarder; | ||
} | ||
|
||
function getTrustedForwarder() external view returns (address) { | ||
return _trustedForwarder; | ||
} | ||
|
||
function trustedForwarder() external view returns (address) { | ||
return _trustedForwarder; | ||
} | ||
|
||
function _msgSender() internal view virtual returns (address sender) { | ||
if (isTrustedForwarder(msg.sender)) { | ||
// The assembly code is more direct than the Solidity version using `abi.decode`. | ||
// solhint-disable-next-line no-inline-assembly | ||
assembly { | ||
sender := shr(96, calldataload(sub(calldatasize(), 20))) | ||
} | ||
} else { | ||
return msg.sender; | ||
} | ||
} | ||
} |
Oops, something went wrong.
0419d7c
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