Skip to content

Commit

Permalink
Add migration notification for users with Sai (#7450)
Browse files Browse the repository at this point in the history
Maker has upgraded its Dai token to "Multi-Collateral Dai" (MCD) and requires
all users interacting with Dai migrate their tokens to the new version. Dai
now exclusively refers to Multi-Collateral Dai and what was previouly called
Dai is now Sai (Single Collateral Dai).

In this description, Sai refers to what was (prior to the 2019-11-18) known as Dai.
Dai is the _new_ token.

This changeset:

1. Only affects users who had non-zero Sai at the old contract address
2. Displays a persistent notification for users with Sai
3. Updates the token symbol for users already tracking the Sai token
4. Bumps our direct and indirect eth-contract-metadata dependencies

The notification copy:

> A message from Maker: The new Multi-Collateral Dai token has been released. Your old tokens are now called Sai. Please upgrade your Sai tokens to the new Dai.

The copy is from the Maker team.
  • Loading branch information
whymarrh authored Nov 18, 2019
1 parent b339550 commit 86b165e
Show file tree
Hide file tree
Showing 12 changed files with 589 additions and 12 deletions.
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"migrateSai": {
"message": "A message from Maker: The new Multi-Collateral Dai token has been released. Your old tokens are now called Sai. Please upgrade your Sai tokens to the new Dai."
},
"migrate": {
"message": "Migrate"
},
"showIncomingTransactions": {
"message": "Show Incoming Transactions"
},
Expand Down
67 changes: 67 additions & 0 deletions app/scripts/migrations/039.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const version = 39
const clone = require('clone')
const ethUtil = require('ethereumjs-util')

const DAI_V1_CONTRACT_ADDRESS = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359'
const DAI_V1_TOKEN_SYMBOL = 'DAI'
const SAI_TOKEN_SYMBOL = 'SAI'

function isOldDai (token = {}) {
return token && typeof token === 'object' &&
token.symbol === DAI_V1_TOKEN_SYMBOL &&
ethUtil.toChecksumAddress(token.address) === DAI_V1_CONTRACT_ADDRESS
}

/**
* This migration renames the Dai token to Sai.
*
* As of 2019-11-18 Dai is now called Sai (refs https://git.io/JeooP) to facilitate
* Maker's upgrade to Multi-Collateral Dai and this migration renames the token
* at the old address.
*/
module.exports = {
version,
migrate: async function (originalVersionedData) {
const versionedData = clone(originalVersionedData)
versionedData.meta.version = version
const state = versionedData.data
versionedData.data = transformState(state)
return versionedData
},
}

function transformState (state) {
const { PreferencesController } = state

if (PreferencesController) {
const tokens = PreferencesController.tokens || []
if (Array.isArray(tokens)) {
for (const token of tokens) {
if (isOldDai(token)) {
token.symbol = SAI_TOKEN_SYMBOL
}
}
}

const accountTokens = PreferencesController.accountTokens || {}
if (accountTokens && typeof accountTokens === 'object') {
for (const address of Object.keys(accountTokens)) {
const networkTokens = accountTokens[address]
if (networkTokens && typeof networkTokens === 'object') {
for (const network of Object.keys(networkTokens)) {
const tokensOnNetwork = networkTokens[network]
if (Array.isArray(tokensOnNetwork)) {
for (const token of tokensOnNetwork) {
if (isOldDai(token)) {
token.symbol = SAI_TOKEN_SYMBOL
}
}
}
}
}
}
}
}

return state
}
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ module.exports = [
require('./036'),
require('./037'),
require('./038'),
require('./039'),
]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"dnode": "^1.2.2",
"end-of-stream": "^1.1.0",
"eth-block-tracker": "^4.4.2",
"eth-contract-metadata": "1.9.3",
"eth-contract-metadata": "^1.11.0",
"eth-ens-namehash": "^2.0.8",
"eth-json-rpc-errors": "^1.1.0",
"eth-json-rpc-filters": "^4.1.1",
Expand All @@ -114,7 +114,7 @@
"extensionizer": "^1.0.1",
"fast-json-patch": "^2.0.4",
"fuse.js": "^3.2.0",
"gaba": "^1.8.0",
"gaba": "^1.9.0",
"human-standard-token-abi": "^2.0.0",
"jazzicon": "^1.2.0",
"json-rpc-engine": "^5.1.5",
Expand Down
Loading

0 comments on commit 86b165e

Please sign in to comment.