Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5d44e69
Optimism L2 integration
krebernisak Apr 6, 2021
557b4f2
Add more LinkTokenChild tests
krebernisak Apr 28, 2021
9b30fba
Update with latest upstream changes
krebernisak May 4, 2021
242a046
Introduce contract versioning
krebernisak May 5, 2021
94f2aa3
Change v0.6 contracts code style
krebernisak May 7, 2021
a712092
Remove export of JS helper functions
krebernisak May 7, 2021
9a0e59c
Include vendor contract source
krebernisak May 7, 2021
27ecfda
Add CI network teardown step
krebernisak May 9, 2021
8731d53
Replace OZ AccessControl with CL SimpleWriteAccessController
krebernisak May 10, 2021
4413c43
Polish tests
krebernisak May 11, 2021
bf2e2f7
Rename IERC20Child deposit/withdraw as mint/burn
krebernisak May 11, 2021
0c557cc
Use submodules for vendor contracts
krebernisak May 11, 2021
3b0ca75
Rename interfaces and flatten contracts
krebernisak May 12, 2021
7c41212
Fix the L2 gasPrice to 1 gwei
krebernisak May 12, 2021
e317c66
Fix tests error handling (avoid TX_OVERRIDES_BUG)
krebernisak May 13, 2021
6c37ec6
Revert token name change
krebernisak Jun 2, 2021
9e0dcd8
Update to latest deps + compiler config bug fix
krebernisak Jul 12, 2021
70fca4f
Add README docs (NOTICE) for LinkTokenChild contract
krebernisak Jun 28, 2021
07371f6
Remove Optimism 1 gwei fixed price
krebernisak Jul 15, 2021
426f174
Update to latest upstream changes
krebernisak Jul 15, 2021
f8a0f44
Merge branch 'master' into feature/oe-token
krebernisak Jul 15, 2021
b641420
Revert to before merge updated deps
krebernisak Jul 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# This action checks PRs to see if any CHANGELOG* files were updated.
# If none were, it will add a message to the PR asking if it would make sense to do so.
#
name: Changelog

on: pull_request

jobs:
changelog:
name: Changelog checker
runs-on: ubuntu-latest
steps:
- name: Check for changed files
id: changedfiles
uses: futuratrepadeira/changed-files@186b5b30b1f5e44ed655a59652746c3ce00d53ef # Version v3.1.1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
pattern: '^CHANGELOG.*$'
- name: Make a comment
uses: unsplash/comment-on-pr@d1a1d5dd1eb1bb657a01f4d92dd5e4d5bb7857d3 # Version v1.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: contains(steps.changedfiles.outputs.files_updated, 'CHANGELOG') != true && contains(steps.changedfiles.outputs.files_created, 'CHANGELOG') != true
with:
msg: "I see that you haven't updated any CHANGELOG files. Would it make sense to do so?"
check_for_duplicate_msg: false
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Main

on:
push:
branches:
- master
pull_request: ~

jobs:
run-basic-checks:
name: Run linters and unit tests
runs-on: [self-hosted]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14.x'
- run: npm install -g yarn
- run: yarn install
- run: yarn setup
- run: yarn lint
- run: yarn test
run-integration:
name: Setup and run integration tests
needs: [run-basic-checks]
runs-on: [self-hosted]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14.x'
- run: npm install -g yarn
- run: yarn install
- run: yarn setup
- name: Setup Optimism L2 network
run: yarn script:oe:up
- run: yarn test --network optimism
- name: Tear down Optimism L2 network
run: yarn script:oe:clean
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ coverage.json

# Misc
.DS_STORE

# Optimism monorepo used for integration tests
/optimism
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node 14.16.0
yarn 1.22.4
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Changelog LinkToken

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - Apr 2021

### Added

- Access controlled mintable & burnable LinkToken, for use on sidechains and L2 networks.
- Added versioning to v0.6 & v0.7 contracts

### Changed

- Migrated to Hardhat and Waffle
- Changed LinkToken v0.6 name from 'ChainLink Token' to 'Chainlink Token'

### Fixed

### Removed

- Truffle framework and tests dependencies

## [1.1.0] - Mar 2021

Initial @chainlink/token release!

### Added

- Solidity 0.6 support
- Simple token swapping contract

## [1.0.6] - Sep 2018

Initial link_token release!
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,73 @@
# LINK Token Contracts [![Build Status](https://travis-ci.org/smartcontractkit/LinkToken.svg?branch=master)](https://travis-ci.org/smartcontractkit/LinkToken)
# LINK Token Contracts

The LINK token is an [EIP20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md) token with additional [ERC677](https://github.com/ethereum/EIPs/issues/677) functionality.

The total supply of the token is 1,000,000,000, and each token is divisible up to 18 decimal places.

To prevent accidental burns, the token does not allow transfers to the contract itself and to 0x0.

Security audit for [v0.4 version of the contracts](./contracts/v0.4/) is available [here](https://gist.github.com/Arachnid/4aa88041bd6e34835b8c0fd051245e79).
Security audit for [0.4 version of the contracts](./contracts/v0.4/) is available [here](https://gist.github.com/Arachnid/4aa88041bd6e34835b8c0fd051245e79).

## Details

- Deployments:
- Ethereum Mainnet [LinkToken v0.4](./flat/v0.4/LinkToken.sol): [0x514910771AF9Ca656af840dff83E8264EcF986CA](https://etherscan.io/address/0x514910771af9ca656af840dff83e8264ecf986ca)
- Ethereum Mainnet [LinkToken 0.4](./flat/v0.4/LinkToken.sol): [0x514910771AF9Ca656af840dff83E8264EcF986CA](https://etherscan.io/address/0x514910771af9ca656af840dff83e8264ecf986ca)
- Decimals: 18
- Name: ChainLink Token
- Symbol: LINK

## Installation
## Setup

The project contains [v0.4 contracts](./contracts/v0.4/) that were used for LINK Ethereum Mainnet deployment in 2017. For deployments moving forward, we use the updated [v0.6 contracts](./contracts/v0.6/) which use a more recent version of solc and the OpenZeppelin token standards. These updates include a minor ABI change around approval/allowance naming.
The project contains [0.4 contracts](./contracts/v0.4/) that were used for LINK Ethereum Mainnet deployment in 2017. For deployments moving forward, we use the updated [0.6 contracts](./contracts/v0.6/) which use a more recent version of solc and the OpenZeppelin token standards. These updates include a minor ABI change around approval/allowance naming.

```bash
yarn install
```

## Testing

Setup contracts:

```bash
yarn setup
```

This will compile all versions of the contracts.

## Testing

Run tests:

```bash
yarn test
```

This will test both v0.4 and v0.6 versions of the contracts.
This will run unit tests for all versions of the contracts.

## Integration testing

Integration tests are currently setup for Optimism contracts, and to run them make sure you have a local network running first.

The network can be started using a helpful script, which will clone the [Optimism monorepo](https://github.com/ethereum-optimism/optimism), build the :

```bash
yarn script:oe:up
```

Run tests:

```bash
yarn test --network optimism
```

This will run unit tests for all versions of the contracts, plus supported integration tests against the local L1 & L2 networks.

The network can be stopped using another script:

```bash
yarn script:oe:down
```

Or use the clean script, which will also delete all the images:

```bash
yarn script:oe:clean
```
38 changes: 24 additions & 14 deletions contracts/v0.6/ERC677Token.sol
Original file line number Diff line number Diff line change
@@ -1,48 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.6.0 <0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../vendor/@openzeppelin/contracts/3.4.1/contracts/token/ERC20/ERC20.sol";
import "./token/ERC677.sol";
import "./token/ERC677Receiver.sol";

abstract contract ERC677Token is ERC20, ERC677 {
/**
* @dev transfer token to a contract address with additional data if the recipient is a contact.
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
* @param _data The extra data to be passed to the receiving contract.
* @param to The address to transfer to.
* @param value The amount to be transferred.
* @param data The extra data to be passed to the receiving contract.
*/
function transferAndCall(address _to, uint _value, bytes memory _data)
function transferAndCall(
address to,
uint value,
bytes memory data
)
public
override
virtual
returns (bool success)
{
super.transfer(_to, _value);
emit Transfer(msg.sender, _to, _value, _data);
if (isContract(_to)) {
contractFallback(_to, _value, _data);
super.transfer(to, value);
emit Transfer(msg.sender, to, value, data);
if (isContract(to)) {
contractFallback(to, value, data);
}
return true;
}


// PRIVATE

function contractFallback(address _to, uint _value, bytes memory _data)
function contractFallback(
address to,
uint value,
bytes memory data
)
private
{
ERC677Receiver receiver = ERC677Receiver(_to);
receiver.onTokenTransfer(msg.sender, _value, _data);
ERC677Receiver receiver = ERC677Receiver(to);
receiver.onTokenTransfer(msg.sender, value, data);
}

function isContract(address _addr)
function isContract(
address addr
)
private
view
returns (bool hasCode)
{
uint length;
assembly { length := extcodesize(_addr) }
assembly { length := extcodesize(addr) }
return length > 0;
}
}
53 changes: 43 additions & 10 deletions contracts/v0.6/LinkToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,40 @@ pragma solidity >0.6.0 <0.8.0;

import "./token/LinkERC20.sol";
import "./ERC677Token.sol";
import "./TypeAndVersionInterface.sol";

contract LinkToken is LinkERC20, ERC677Token {
/// @dev LinkToken, an ERC20/ERC677 Chainlink token with 1 billion supply
contract LinkToken is TypeAndVersionInterface, LinkERC20, ERC677Token {
uint private constant TOTAL_SUPPLY = 10**27;
string private constant NAME = 'ChainLink Token';
string private constant NAME = 'Chainlink Token';
string private constant SYMBOL = 'LINK';

constructor() ERC20(NAME, SYMBOL)
constructor()
ERC20(NAME, SYMBOL)
public
{
_onCreate();
}

/**
* @notice versions:
*
* - LinkToken 0.0.3: added versioning, update name
* - LinkToken 0.0.2: upgraded to solc 0.6
* - LinkToken 0.0.1: initial release solc 0.4
*
* @inheritdoc TypeAndVersionInterface
*/
function typeAndVersion()
external
pure
override
virtual
returns (string memory)
{
return "LinkToken 0.0.3";
}

/**
* @dev Hook that is called when this contract is created.
* Useful to override constructor behaviour in child contracts (e.g., LINK bridge tokens).
Expand All @@ -31,7 +53,11 @@ contract LinkToken is LinkERC20, ERC677Token {
* @dev Check if recepient is a valid address before transfer
* @inheritdoc ERC20
*/
function _transfer(address sender, address recipient, uint256 amount)
function _transfer(
address sender,
address recipient,
uint256 amount
)
internal
override
virtual
Expand All @@ -44,7 +70,11 @@ contract LinkToken is LinkERC20, ERC677Token {
* @dev Check if spender is a valid address before approval
* @inheritdoc ERC20
*/
function _approve(address owner, address spender, uint256 amount)
function _approve(
address owner,
address spender,
uint256 amount
)
internal
override
virtual
Expand All @@ -53,13 +83,16 @@ contract LinkToken is LinkERC20, ERC677Token {
super._approve(owner, spender, amount);
}


// MODIFIERS

modifier validAddress(address _recipient)
/**
* @dev Check if recipient is valid (not this contract address)
* @param recipient the account we transfer/approve to
*/
modifier validAddress(
address recipient
)
virtual
{
require(_recipient != address(this), "LinkToken: transfer/approve to this contract address");
require(recipient != address(this), "LinkToken: transfer/approve to this contract address");
_;
}
}
Loading