New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@streamr/data-v2

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@streamr/data-v2

The second iteration of the DATA token

  • 1.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
21
increased by200%
Maintainers
0
Weekly downloads
 
Created
Source

DATAv2 token contract

Continuous Integration Audit by LimeChain Audit by Isentropy

Deployments

ChainAddress
Ethereum Mainnet0x8f693ca8d21b157107184d29d398a8d082b38b76
Binance Smart Chain0x0864c156b3c5f69824564dec60c629ae6401bf2a
Gnosis (formerly xDAI)0x256eb8a51f382650B2A1e946b8811953640ee47D
Polygon0x3a9A81d576d83FF21f26f325066054540720fC34
Polygon Amoy testnet0xf5e28a2E7BbedbE97c3782b17b102410E10d90f1
IoTeX testnet0x5ABD469031d2B5f939808565EAB8562d7Cbaa939

NPM package contents

JS/TypeScript utilities to get a nicely typed DATAv2 instance. Here's a sample code for plain node.js:

const { JsonRpcProvider } = require("@ethersproject/providers")
const { formatEther, parseEther } = require("@ethersproject/units")
const { Wallet } = require("@ethersproject/wallet")
const { deployToken } = require("@streamr/data-v2")

const key = process.env.PRIVATE_KEY
const provider = new JsonRpcProvider(process.env.ETHEREUM_URL)
const wallet = new Wallet(key, provider)

async function main() {
    const token = await deployToken(wallet)
    console.log("Before: %s", formatEther(await token.balanceOf(wallet.address)))
    await (await token.grantRole(await token.MINTER_ROLE(), wallet.address)).wait()
    await (await token.mint(wallet.address, parseEther("10"))).wait()
    console.log("After: %s", formatEther(await token.balanceOf(wallet.address)))
}
main().catch(console.error)

And here's another sample code for TypeScript, run with ts-node:

import { JsonRpcProvider } from "@ethersproject/providers"
import { getTokenAt } from "@streamr/data-v2"
import type { DATAv2 } from "@streamr/data-v2"

const provider: JsonRpcProvider = new JsonRpcProvider(process.env.ETHEREUM_URL)
const token: DATAv2 = await getTokenAt(process.env.TOKEN_ADDRESS, provider)
console.log("Symbol:", await token.symbol())

List of files

FileDescriptionDeployed
contracts/CrowdsaleToken.solThe current (or "old") DATA tokenETH 0x0cf0...23
contracts/DATAv2.solThe new DATA tokenETH 0x8f6...b76 (see above)
contracts/DataTokenMigrator.solMigrator contract that acts as UpgradeAgent for the old tokenETH 0xc7...c16c
contracts/IERC677.solInterface of ERC677 as defined in the LINK token
contracts/IERC677Receiver.solInterface of ERC677Receiver also defined in the LINK token
contracts/MockRecipient.solIERC677Receiver implementation for the purpose of testing
test/DATAv2-test.jsDATAv2.sol tests
test/DataTokenMigrator-test.jsDataTokenMigrator.sol tests
contracts/DATAv2onPolygon.sol *DATAv2 deployed on MATIC/Polygon chain, extended slightly for bridgingMATIC 0x3a9...34

* added after the audit

DATAv2 features

Some of the following features are inherited from OpenZeppelin contracts:

FeatureAssociated functionFile where the function is
ERC-677transferAndCallcontracts/DATAv2.sol
EIP-2612permit@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol
MintinggrantRole, revokeRole@openzeppelin/contracts/access/AccessControl.sol
Mintingmintcontracts/DATAv2.sol
Burningburn, burnFrom@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol

Minting

DATAv2 has an admin role (controlled by Streamr) that can add and remove minters, who can mint tokens tokens at will. The admin and minters will be contracts that are not controlled by a single wallet.

The whole old DATA supply is minted as part of migration, and new tokens may be minted later as decided by the community process in the form of Streamr Improvement Proposals, see e.g. SIP-6.

ERC677 functionality

DATAv2 follows the convention of LINK and other tokens with regard to the callback function onTokenTransfer invoked by transferAndCall: DATAv2 does not check the bool return value of onTokenTransfer. Instead onTokenTransfer should revert if the transfer is to be rejected by the recipient contract. If the recipient is a contract, it must implement onTokenTransfer or else transferAndCall reverts.

Migration process

  1. We deploy the DATAv2 and DataTokenMigrator contracts
  2. We call grantRole(id('MINTER_ROLE'), minter.address) on the DATAv2 contract
  3. Minter calls mint(migrator.address, tokenSupply) on the DATAv2 contract to mint the tokens belonging to old DATA holders into the DataTokenMigrator contract
  4. We call setUpgradeAgent(migrator.address) in the old DATA contract to start the upgrade
  5. DATA token holders call upgrade(amountWei) in the old DATA contract

Result:

  • Old DATA tokens are burned
  • DATAv2 tokens are transferred from the DataTokenMigrator to the holders

At all times, DATAv2 tokens left in the DataTokenMigrator are the unmigrated DATA tokens, and they should be equal in number to the tokenSupply of the old DATA contract

DATAv2 contract anatomy

OpenZeppelin contracts were used where available to implement the features listed in the above table.

Explanations of the origins and intents of all code found in DATAv2.sol:

LinesExplanation
1...12OpenZeppelin and interface imports, DATAv2 token properties
16...46Adapted from @openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol to implement the minting feature. The AccessControl.sol is a bit of a can of worms when it comes to state-space: the "role admin" can set up any constellation of roles and grant those roles and their administration to anyone; its implementation is quite elegant though, so it didn't feel very significantly worse than a "brute" mapping (address => bool) isMinter type of implementation, especially since it's all library code. Added isMinter convenience function.
48...74Adapted from LINK token to implement the ERC-677 token transfer hook. Recipient smart contracts can now react to DATAv2 token transfer which makes approve+transferFrom two-transaction flow avoidable if not entirely redundant. Decided to go for the simply ERC-677 instead of the ERC-777 because of some misfeatures on ERC-777 (defaultOperators, higher plain transfer gas price) as well as uncertain adoption at this stage.
76...103Allow the admin to change token symbol and name just in case, e.g. to support token rebranding, and graceful end-of-life after the possible next migration

Dependencies

FAQs

Package last updated on 25 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc