-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from bancorprotocol/initial_version
Initial Version
- Loading branch information
Showing
18 changed files
with
10,888 additions
and
0 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,46 @@ | ||
{ | ||
"extends": ["standard", "prettier", "plugin:@typescript-eslint/recommended"], | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"env": { | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"max-len": ["error", 150, 2], | ||
"camelcase": [ | ||
"error", | ||
{ | ||
"ignoreImports": true | ||
} | ||
], | ||
"indent": [ | ||
"error", | ||
4, | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"semi": ["error", "always"], | ||
"no-plusplus": "off", | ||
"no-await-in-loop": "off", | ||
"no-restricted-syntax": "off", | ||
"no-continue": "off", | ||
"arrow-body-style": "off", | ||
"no-loop-func": "off", | ||
"no-unused-expressions": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/no-explicit-any": "off" | ||
}, | ||
"globals": { | ||
"assert": true, | ||
"expect": true, | ||
"artifacts": true, | ||
"contract": true, | ||
"web3": true | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "999.999.999" | ||
} | ||
} | ||
} |
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,28 @@ | ||
name: Build, Test | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
build-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
### Setup action's dependencies | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16' | ||
|
||
### Build | ||
- name: Install Dependencies | ||
run: yarn install | ||
- name: Build | ||
run: yarn build | ||
|
||
### Testing | ||
- name: Test | ||
run: yarn test |
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,23 @@ | ||
.DS_Store | ||
.vscode/ | ||
*/**/.DS_Store | ||
|
||
# node | ||
/node_modules | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
/cache | ||
/artifacts | ||
/typechain | ||
/data | ||
|
||
.coverage_artifacts | ||
.coverage_contracts | ||
coverage | ||
coverageEnv | ||
coverage.json | ||
allFiredEvents | ||
scTopics | ||
|
||
contracts/hardhat-dependency-compiler |
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,11 @@ | ||
.vscode/ | ||
/node_modules | ||
|
||
artifacts | ||
.coverage_artifacts | ||
.coverage_contracts | ||
coverage | ||
coverageEnv | ||
coverage.json | ||
allFiredEvents | ||
scTopics |
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,19 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"singleQuote": false, | ||
"explicitTypes": "always" | ||
} | ||
} | ||
], | ||
"printWidth": 120, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"arrowParens": "always", | ||
"bracketSpacing": true | ||
} |
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,17 @@ | ||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. | ||
version: v1.14.0 | ||
ignore: {} | ||
# patches apply the minimum changes required to fix a vulnerability | ||
patch: | ||
SNYK-JS-TREEKILL-536781: | ||
- solidity-coverage > tree-kill: | ||
patched: '2019-12-12T13:55:11.672Z' | ||
SNYK-JS-LODASH-450202: | ||
- snyk > @snyk/dep-graph > lodash: | ||
patched: '2019-12-12T13:56:19.599Z' | ||
- snyk > @snyk/snyk-cocoapods-plugin > @snyk/dep-graph > lodash: | ||
patched: '2019-12-12T13:56:19.599Z' | ||
- snyk > snyk-nuget-plugin > dotnet-deps-parser > lodash: | ||
patched: '2019-12-12T13:56:19.599Z' | ||
- snyk > @snyk/snyk-cocoapods-plugin > @snyk/cocoapods-lockfile-parser > @snyk/dep-graph > lodash: | ||
patched: '2019-12-12T13:56:19.599Z' |
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,3 @@ | ||
module.exports = { | ||
skipFiles: ['contracts/helpers'] | ||
}; |
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,13 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"rules": { | ||
"avoid-throw": "off", | ||
"avoid-suicide": "error", | ||
"avoid-sha3": "warn", | ||
"not-rely-on-time": "off", | ||
"no-empty-blocks": "off", | ||
"mark-callable-contracts": "off", | ||
"func-visibility": ["error", { "ignoreConstructors": true }], | ||
"compiler-version": ["error", "0.8.9"] | ||
} | ||
} |
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 @@ | ||
# dad-bridge-wrapper | ||
|
||
[![Build Status](https://github.com/bancorprotocol/dad-bridge-wrapper/actions/workflows/workflow.yml/badge.svg)](https://github.com/bancorprotocol/dad-bridge-wrapper/actions/workflows/workflow.yml) | ||
|
||
## Testing | ||
|
||
### Installation | ||
|
||
- `yarn install` | ||
|
||
### Verification | ||
|
||
- Verifying all the contracts: | ||
- `yarn test` (quick testing) | ||
- `yarn coverage` (full coverage) |
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,61 @@ | ||
/* eslint-enable camelcase */ | ||
import { Signer, ContractFactory } from 'ethers'; | ||
import { ethers } from 'hardhat'; | ||
|
||
export type AsyncReturnType<T extends (...args: any) => any> = T extends (...args: any) => Promise<infer U> | ||
? U | ||
: T extends (...args: any) => infer U | ||
? U | ||
: any; | ||
|
||
export type Contract<F extends ContractFactory> = AsyncReturnType<F['deploy']>; | ||
|
||
export interface ContractBuilder<F extends ContractFactory> { | ||
metadata: { | ||
contractName: string; | ||
abi: unknown; | ||
bytecode: string; | ||
}; | ||
deploy(...args: Parameters<F['deploy']>): Promise<Contract<F>>; | ||
attach(address: string, signer?: Signer): Promise<Contract<F>>; | ||
} | ||
|
||
export type FactoryConstructor<F extends ContractFactory> = { | ||
new (signer?: Signer): F; | ||
abi: unknown; | ||
bytecode: string; | ||
}; | ||
|
||
export const deployOrAttach = <F extends ContractFactory>( | ||
contractName: string, | ||
// @TODO: needs to replace with correctly typed params but it doesn't | ||
// work properly for some reason https://github.com/microsoft/TypeScript/issues/31278 | ||
FactoryConstructor: FactoryConstructor<F>, | ||
initialSigner?: Signer | ||
): ContractBuilder<F> => { | ||
return { | ||
metadata: { | ||
contractName, | ||
abi: FactoryConstructor.abi, | ||
bytecode: FactoryConstructor.bytecode | ||
}, | ||
deploy: async (...args: Parameters<F['deploy']>): Promise<Contract<F>> => { | ||
const defaultSigner = initialSigner || (await ethers.getSigners())[0]; | ||
|
||
return new FactoryConstructor(defaultSigner).deploy(...(args || [])) as Contract<F>; | ||
}, | ||
attach: attachOnly<F>(FactoryConstructor, initialSigner).attach | ||
}; | ||
}; | ||
|
||
export const attachOnly = <F extends ContractFactory>( | ||
FactoryConstructor: FactoryConstructor<F>, | ||
initialSigner?: Signer | ||
) => { | ||
return { | ||
attach: async (address: string, signer?: Signer): Promise<Contract<F>> => { | ||
const defaultSigner = initialSigner || (await ethers.getSigners())[0]; | ||
return new FactoryConstructor(signer || defaultSigner).attach(address) as Contract<F>; | ||
} | ||
}; | ||
}; |
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,20 @@ | ||
/* eslint-disable camelcase */ | ||
import { | ||
DADBridgeWrapper__factory, | ||
TestERC20Token__factory | ||
} from '../typechain'; | ||
import { deployOrAttach } from './ContractBuilder'; | ||
|
||
/* eslint-enable camelcase */ | ||
import { Signer } from 'ethers'; | ||
|
||
const getContracts = (signer?: Signer) => ({ | ||
connect: (signer: Signer) => getContracts(signer), | ||
|
||
DADBridgeWrapper: deployOrAttach('DADBridgeWrapper', DADBridgeWrapper__factory, signer), | ||
TestERC20Token: deployOrAttach('TestERC20Token', TestERC20Token__factory, signer) | ||
}); | ||
|
||
export type ContractsType = ReturnType<typeof getContracts>; | ||
|
||
export default getContracts(); |
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,95 @@ | ||
// SPDX-License-Identifier: SEE LICENSE IN LICENSE | ||
pragma solidity 0.8.9; | ||
|
||
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol"; | ||
import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol"; | ||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
error InvalidToken(); | ||
error InvalidRecipient(); | ||
error InvalidAmount(); | ||
error UnsupportedOperation(); | ||
|
||
contract DADBridgeWrapper is AccessControl, Pausable { | ||
using SafeERC20 for IERC20; | ||
|
||
bytes32 public constant ROLE_ADMIN = keccak256("ROLE_ADMIN"); | ||
|
||
IERC20 private immutable _token; | ||
|
||
uint256 private _totalSupply; | ||
|
||
/** | ||
* @dev initializes the contract | ||
*/ | ||
constructor(IERC20 initToken) { | ||
if (address(initToken) == address(0)) { | ||
revert InvalidToken(); | ||
} | ||
_token = initToken; | ||
_setRoleAdmin(ROLE_ADMIN, ROLE_ADMIN); | ||
_setupRole(ROLE_ADMIN, msg.sender); | ||
} | ||
|
||
/** | ||
* @dev returns the token contract address | ||
*/ | ||
function token() public view returns (IERC20) { | ||
return _token; | ||
} | ||
|
||
/** | ||
* @dev returns the total amount of tokens minted | ||
*/ | ||
function totalSupply() public view returns (uint256) { | ||
return _totalSupply; | ||
} | ||
|
||
/** | ||
* @dev pauses minting | ||
* | ||
* requirements: | ||
* | ||
* - the caller must have the ROLE_ADMIN privileges | ||
*/ | ||
function pause() external onlyRole(ROLE_ADMIN) { | ||
_pause(); | ||
} | ||
|
||
/** | ||
* @dev unpauses minting | ||
* | ||
* requirements: | ||
* | ||
* - the caller must have the ROLE_ADMIN privileges | ||
*/ | ||
function unpause() external onlyRole(ROLE_ADMIN) { | ||
_unpause(); | ||
} | ||
|
||
/** | ||
* @dev mints a given amount of tokens for a given recipient | ||
* | ||
* requirements: | ||
* | ||
* - the caller must have the ROLE_ADMIN privileges, and the contract must not be paused | ||
*/ | ||
function mint(address recipient, uint256 amount) external onlyRole(ROLE_ADMIN) whenNotPaused { | ||
if (recipient == address(0)) { | ||
revert InvalidRecipient(); | ||
} | ||
if (amount == 0) { | ||
revert InvalidAmount(); | ||
} | ||
_token.safeTransfer(recipient, amount); | ||
_totalSupply += amount; | ||
} | ||
|
||
function burn( | ||
address, /* recipient */ | ||
uint256 /* amount */ | ||
) external virtual { | ||
revert UnsupportedOperation(); | ||
} | ||
} |
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 @@ | ||
// SPDX-License-Identifier: SEE LICENSE IN LICENSE | ||
pragma solidity 0.8.9; | ||
|
||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import { ERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol"; | ||
|
||
contract TestERC20Token is ERC20Permit { | ||
constructor( | ||
string memory name, | ||
string memory symbol, | ||
uint256 totalSupply | ||
) ERC20(name, symbol) ERC20Permit(name) { | ||
_mint(msg.sender, totalSupply); | ||
} | ||
} |
Oops, something went wrong.