Skip to content

Commit 86b165e

Browse files
authored
Add migration notification for users with Sai (#7450)
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.
1 parent b339550 commit 86b165e

File tree

12 files changed

+589
-12
lines changed

12 files changed

+589
-12
lines changed

app/_locales/en/messages.json

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2+
"migrateSai": {
3+
"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."
4+
},
5+
"migrate": {
6+
"message": "Migrate"
7+
},
28
"showIncomingTransactions": {
39
"message": "Show Incoming Transactions"
410
},

app/scripts/migrations/039.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const version = 39
2+
const clone = require('clone')
3+
const ethUtil = require('ethereumjs-util')
4+
5+
const DAI_V1_CONTRACT_ADDRESS = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359'
6+
const DAI_V1_TOKEN_SYMBOL = 'DAI'
7+
const SAI_TOKEN_SYMBOL = 'SAI'
8+
9+
function isOldDai (token = {}) {
10+
return token && typeof token === 'object' &&
11+
token.symbol === DAI_V1_TOKEN_SYMBOL &&
12+
ethUtil.toChecksumAddress(token.address) === DAI_V1_CONTRACT_ADDRESS
13+
}
14+
15+
/**
16+
* This migration renames the Dai token to Sai.
17+
*
18+
* As of 2019-11-18 Dai is now called Sai (refs https://git.io/JeooP) to facilitate
19+
* Maker's upgrade to Multi-Collateral Dai and this migration renames the token
20+
* at the old address.
21+
*/
22+
module.exports = {
23+
version,
24+
migrate: async function (originalVersionedData) {
25+
const versionedData = clone(originalVersionedData)
26+
versionedData.meta.version = version
27+
const state = versionedData.data
28+
versionedData.data = transformState(state)
29+
return versionedData
30+
},
31+
}
32+
33+
function transformState (state) {
34+
const { PreferencesController } = state
35+
36+
if (PreferencesController) {
37+
const tokens = PreferencesController.tokens || []
38+
if (Array.isArray(tokens)) {
39+
for (const token of tokens) {
40+
if (isOldDai(token)) {
41+
token.symbol = SAI_TOKEN_SYMBOL
42+
}
43+
}
44+
}
45+
46+
const accountTokens = PreferencesController.accountTokens || {}
47+
if (accountTokens && typeof accountTokens === 'object') {
48+
for (const address of Object.keys(accountTokens)) {
49+
const networkTokens = accountTokens[address]
50+
if (networkTokens && typeof networkTokens === 'object') {
51+
for (const network of Object.keys(networkTokens)) {
52+
const tokensOnNetwork = networkTokens[network]
53+
if (Array.isArray(tokensOnNetwork)) {
54+
for (const token of tokensOnNetwork) {
55+
if (isOldDai(token)) {
56+
token.symbol = SAI_TOKEN_SYMBOL
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
66+
return state
67+
}

app/scripts/migrations/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ module.exports = [
4949
require('./036'),
5050
require('./037'),
5151
require('./038'),
52+
require('./039'),
5253
]

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"dnode": "^1.2.2",
8888
"end-of-stream": "^1.1.0",
8989
"eth-block-tracker": "^4.4.2",
90-
"eth-contract-metadata": "1.9.3",
90+
"eth-contract-metadata": "^1.11.0",
9191
"eth-ens-namehash": "^2.0.8",
9292
"eth-json-rpc-errors": "^1.1.0",
9393
"eth-json-rpc-filters": "^4.1.1",
@@ -114,7 +114,7 @@
114114
"extensionizer": "^1.0.1",
115115
"fast-json-patch": "^2.0.4",
116116
"fuse.js": "^3.2.0",
117-
"gaba": "^1.8.0",
117+
"gaba": "^1.9.0",
118118
"human-standard-token-abi": "^2.0.0",
119119
"jazzicon": "^1.2.0",
120120
"json-rpc-engine": "^5.1.5",

0 commit comments

Comments
 (0)