diff --git a/packages/dai-plugin-governance/package.json b/packages/dai-plugin-governance/package.json index cda7ad690..c0b2b5606 100644 --- a/packages/dai-plugin-governance/package.json +++ b/packages/dai-plugin-governance/package.json @@ -1,7 +1,7 @@ { "name": "@makerdao/dai-plugin-governance", "description": "A dai.js plugin for adding MKR governance support to dapps.", - "version": "0.12.1", + "version": "0.12.5", "license": "MIT", "repository": { "type": "git", @@ -30,7 +30,7 @@ }, "dependencies": { "@makerdao/currency": ">=0.9.0", - "@makerdao/services-core": ">=0.9.0", + "@makerdao/services-core": "^0.10.0", "assert": "^2.0.0", "debug": "^4.1.1", "ramda": "^0.25.0" diff --git a/packages/dai-plugin-governance/src/GovPollingService.js b/packages/dai-plugin-governance/src/GovPollingService.js index 54728be66..61bb06931 100644 --- a/packages/dai-plugin-governance/src/GovPollingService.js +++ b/packages/dai-plugin-governance/src/GovPollingService.js @@ -167,19 +167,21 @@ export default class GovPollingService extends PrivateService { tally.rounds++; // eliminate the weakest candidate - const [optionToEliminate] = Object.entries(tally.options) - .filter(([, optionDetails]) => !optionDetails.eliminated) - .reduce((prv, cur) => { - const [, prvVotes] = prv; - const [, curVotes] = cur; - if ( - curVotes.firstChoice - .plus(curVotes.transfer) - .lt(prvVotes.firstChoice.plus(prvVotes.transfer)) - ) - return cur; - return prv; - }); + const filteredOptions = Object.entries(tally.options).filter( + ([, optionDetails]) => !optionDetails.eliminated + ); + + const [optionToEliminate] = filteredOptions.reduce((prv, cur) => { + const [, prvVotes] = prv; + const [, curVotes] = cur; + if ( + curVotes.firstChoice + .plus(curVotes.transfer) + .lt(prvVotes.firstChoice.plus(prvVotes.transfer)) + ) + return cur; + return prv; + }); tally.options[optionToEliminate].eliminated = true; tally.options[optionToEliminate].transfer = BigNumber(0); @@ -208,8 +210,12 @@ export default class GovPollingService extends PrivateService { } ); - //if there's no more rounds, the winner is the option with the most votes - if (tally.rounds > MAX_ROUNDS && !tally.winner) { + //if there's no more rounds, or if there's only one option that hasn't been eliminated + // the winner is the option with the most votes + if ( + (tally.rounds > MAX_ROUNDS && !tally.winner) || + (filteredOptions.length === 1 && !tally.winner) + ) { let max = BigNumber(0); let maxOption; Object.entries(tally.options).forEach( diff --git a/packages/dai-plugin-mcd/README.md b/packages/dai-plugin-mcd/README.md index a29ecb2b1..03d173a82 100644 --- a/packages/dai-plugin-mcd/README.md +++ b/packages/dai-plugin-mcd/README.md @@ -6,7 +6,7 @@ multi-collateral dai contracts ### Example usage ```js -import { McdPlugin, ETH, REP, MDAI } from '@makerdao/dai-plugin-mcd'; +import { McdPlugin, ETH, REP, DAI } from '@makerdao/dai-plugin-mcd'; import Maker from '@makerdao/dai'; import { createCurrency } from '@makerdao/currency'; import { tokenAddress, tokenAbi } from 'someOtherTokenData'; @@ -33,9 +33,9 @@ const maker = await Maker.create('http', { await maker.service('proxy').ensureProxy(); const cdpManager = maker.service('mcd:cdpManager'); -const cdp1 = await cdpManager.openLockAndDraw('REP-A', REP(50), MDAI(1000)); -const cdp2 = await cdpManager.openLockAndDraw('ETH-A', ETH(50), MDAI(1000)); -const cdp3 = await cdpManager.openLockAndDraw('TOK-Z', TOK(50), MDAI(1000)); +const cdp1 = await cdpManager.openLockAndDraw('REP-A', REP(50), DAI(1000)); +const cdp2 = await cdpManager.openLockAndDraw('ETH-A', ETH(50), DAI(1000)); +const cdp3 = await cdpManager.openLockAndDraw('TOK-Z', TOK(50), DAI(1000)); ``` Please visit [docs.makerdao.com](https://docs.makerdao.com/building-with-maker/daijs) for more documentation. diff --git a/packages/dai-plugin-mcd/package.json b/packages/dai-plugin-mcd/package.json index e5617e56a..1d4ca0bf3 100644 --- a/packages/dai-plugin-mcd/package.json +++ b/packages/dai-plugin-mcd/package.json @@ -1,7 +1,7 @@ { "name": "@makerdao/dai-plugin-mcd", "description": "Plugin to add Multi-Collateral Dai support to dai.js", - "version": "1.4.3", + "version": "1.5.0", "license": "MIT", "main": "dist/index.js", "browser": "umd/index.js", diff --git a/packages/dai-plugin-mcd/src/Auction.js b/packages/dai-plugin-mcd/src/Auction.js index 950e5166f..c0252de49 100644 --- a/packages/dai-plugin-mcd/src/Auction.js +++ b/packages/dai-plugin-mcd/src/Auction.js @@ -1,11 +1,11 @@ import { WAD } from './constants'; import BigNumber from 'bignumber.js'; -import { MDAI } from './index'; +import { DAI } from './index'; export default class Auction { constructor(ilk, smartContractService) { switch (ilk) { - case MDAI.symbol: + case DAI.symbol: this.contract = smartContractService.getContract('MCD_FLAP'); break; case 'MKR': diff --git a/packages/dai-plugin-mcd/src/CdpManager.js b/packages/dai-plugin-mcd/src/CdpManager.js index 74ff2beb6..e6773449b 100644 --- a/packages/dai-plugin-mcd/src/CdpManager.js +++ b/packages/dai-plugin-mcd/src/CdpManager.js @@ -9,7 +9,7 @@ import ManagedCdp from './ManagedCdp'; import { castAsCurrency, stringToBytes, bytesToString } from './utils'; import has from 'lodash/has'; import padStart from 'lodash/padStart'; -import { MDAI, ETH, GNT } from './index'; +import { DAI, ETH, GNT } from './index'; const { CDP_MANAGER, CDP_TYPE, SYSTEM_DATA } = ServiceRoles; import getEventHistoryImpl from './EventHistory'; @@ -115,13 +115,13 @@ export default class CdpManager extends LocalService { } @tracksTransactionsWithOptions({ numArguments: 5 }) - async lockAndDraw(id, ilk, lockAmount, drawAmount = MDAI(0), { promise }) { + async lockAndDraw(id, ilk, lockAmount, drawAmount = DAI(0), { promise }) { assert(lockAmount && drawAmount, 'both amounts must be specified'); assert( lockAmount instanceof Currency, 'lockAmount must be a Currency value' ); - drawAmount = castAsCurrency(drawAmount, MDAI); + drawAmount = castAsCurrency(drawAmount, DAI); const proxyAddress = await this.get('proxy').ensureProxy({ promise }); const jugAddress = this.get('smartContract').getContractAddress('MCD_JUG'); const isEth = ETH.isInstance(lockAmount); @@ -194,13 +194,13 @@ export default class CdpManager extends LocalService { this.get('smartContract').getContractAddress('MCD_JUG'), this._adapterAddress('DAI'), this.getIdBytes(id), - castAsCurrency(drawAmount, MDAI).toFixed('wei'), + castAsCurrency(drawAmount, DAI).toFixed('wei'), { dsProxy: true, promise, metadata: { id, ilk, drawAmount } } ); } @tracksTransactionsWithOptions({ numArguments: 5 }) - wipeAndFree(id, ilk, wipeAmount = MDAI(0), freeAmount, { promise }) { + wipeAndFree(id, ilk, wipeAmount = DAI(0), freeAmount, { promise }) { const isEth = ETH.isInstance(freeAmount); const method = isEth ? 'wipeAndFreeETH' : 'wipeAndFreeGem'; return this.proxyActions[method]( diff --git a/packages/dai-plugin-mcd/src/CdpType.js b/packages/dai-plugin-mcd/src/CdpType.js index fe9a8065e..6280081d7 100644 --- a/packages/dai-plugin-mcd/src/CdpType.js +++ b/packages/dai-plugin-mcd/src/CdpType.js @@ -1,7 +1,7 @@ import assert from 'assert'; import { ServiceRoles } from './constants'; import { stringToBytes } from './utils'; -import { MDAI, ETH, MWETH } from './index'; +import { DAI, ETH, WETH } from './index'; import * as math from './math'; export default class CdpType { @@ -28,7 +28,7 @@ export default class CdpType { get totalDebt() { const { Art, rate } = this._getCached('vatInfo'); - return MDAI.wei(Art) + return DAI.wei(Art) .times(rate) .shiftedBy(-27); } @@ -72,7 +72,7 @@ export default class CdpType { // separate calls if (!this._prefetchPromise) { const adapterAddress = this._systemData.adapterAddress(this.ilk); - const { symbol } = this.currency === ETH ? MWETH : this.currency; + const { symbol } = this.currency === ETH ? WETH : this.currency; this._prefetchPromise = Promise.all([ this._systemData diff --git a/packages/dai-plugin-mcd/src/ManagedCdp.js b/packages/dai-plugin-mcd/src/ManagedCdp.js index e8cb7a873..422701a0a 100644 --- a/packages/dai-plugin-mcd/src/ManagedCdp.js +++ b/packages/dai-plugin-mcd/src/ManagedCdp.js @@ -4,7 +4,7 @@ import tracksTransactions, { } from './utils/tracksTransactions'; import { ServiceRoles } from './constants'; import assert from 'assert'; -import { MDAI } from './index'; +import { DAI } from './index'; import * as math from './math'; export default class ManagedCdp { @@ -93,14 +93,10 @@ export default class ManagedCdp { } @tracksTransactionsWithOptions({ numArguments: 3 }) - lockAndDraw( - lockAmount = this.currency(0), - drawAmount = MDAI(0), - { promise } - ) { + lockAndDraw(lockAmount = this.currency(0), drawAmount = DAI(0), { promise }) { assert(lockAmount && drawAmount, 'amounts must be defined'); lockAmount = castAsCurrency(lockAmount, this.currency); - drawAmount = castAsCurrency(drawAmount, MDAI); + drawAmount = castAsCurrency(drawAmount, DAI); return this._cdpManager.lockAndDraw( this.id, this.ilk, @@ -111,12 +107,12 @@ export default class ManagedCdp { } wipeDai(amount) { - amount = castAsCurrency(amount, MDAI); + amount = castAsCurrency(amount, DAI); return this._cdpManager.wipe(this.id, amount, null); } unsafeWipe(amount) { - amount = castAsCurrency(amount, MDAI); + amount = castAsCurrency(amount, DAI); return this._cdpManager.unsafeWipe(this.id, amount); } @@ -141,13 +137,9 @@ export default class ManagedCdp { } @tracksTransactionsWithOptions({ numArguments: 3 }) - wipeAndFree( - wipeAmount = MDAI(0), - freeAmount = this.currency(0), - { promise } - ) { + wipeAndFree(wipeAmount = DAI(0), freeAmount = this.currency(0), { promise }) { assert(wipeAmount && freeAmount, 'amounts must be defined'); - wipeAmount = castAsCurrency(wipeAmount, MDAI); + wipeAmount = castAsCurrency(wipeAmount, DAI); freeAmount = castAsCurrency(freeAmount, this.currency); return this._cdpManager.wipeAndFree( this.id, diff --git a/packages/dai-plugin-mcd/src/SavingsService.js b/packages/dai-plugin-mcd/src/SavingsService.js index 05f8abad0..157a21bbe 100644 --- a/packages/dai-plugin-mcd/src/SavingsService.js +++ b/packages/dai-plugin-mcd/src/SavingsService.js @@ -1,6 +1,6 @@ import { PublicService } from '@makerdao/services-core'; import { ServiceRoles } from './constants'; -import { MDAI } from './index'; +import { DAI } from './index'; import BigNumber from 'bignumber.js'; import { RAY, WAD, SECONDS_PER_YEAR } from './constants'; import tracksTransactions from './utils/tracksTransactions'; @@ -55,13 +55,13 @@ export default class SavingsService extends PublicService { async balance() { const proxy = await this.get('proxy').currentProxy(); - return proxy ? this.balanceOf(proxy) : MDAI(0); + return proxy ? this.balanceOf(proxy) : DAI(0); } async balanceOf(guy) { const slice = new BigNumber(await this._pot.pie(guy)); const chi = await this.chi(); - return MDAI( + return DAI( slice .times(chi) .div(WAD) @@ -72,7 +72,7 @@ export default class SavingsService extends PublicService { async getTotalDai() { const totalPie = new BigNumber(await this._pot.Pie()); const chi = await this.chi(); - return MDAI( + return DAI( totalPie .times(chi) .div(WAD) @@ -119,7 +119,7 @@ export default class SavingsService extends PublicService { if (type === 'DSR_WITHDRAW') sum = sum.minus(amount); }); const balance = await this.balanceOf(address); - return balance.gt(sum) ? balance.minus(sum) : MDAI(0); + return balance.gt(sum) ? balance.minus(sum) : DAI(0); } resetEventHistoryCache(address = null) { diff --git a/packages/dai-plugin-mcd/src/SystemDataService.js b/packages/dai-plugin-mcd/src/SystemDataService.js index 1cc1f76a6..3842ec903 100644 --- a/packages/dai-plugin-mcd/src/SystemDataService.js +++ b/packages/dai-plugin-mcd/src/SystemDataService.js @@ -1,6 +1,7 @@ import { PublicService } from '@makerdao/services-core'; import { RAD, RAY, ServiceRoles, SECONDS_PER_YEAR } from './constants'; import BigNumber from 'bignumber.js'; +import { DAI } from './index'; export default class SystemDataService extends PublicService { constructor(name = ServiceRoles.SYSTEM_DATA) { @@ -33,6 +34,15 @@ export default class SystemDataService extends PublicService { return live.eq(0); } + async getSystemSurplus() { + const vowAddr = this.get('smartContract').getContractAddress('MCD_VOW'); + const [dai, sin] = await Promise.all([ + this.vat.dai(vowAddr), + this.vat.sin(vowAddr) + ]); + return DAI.rad(dai).minus(DAI.rad(sin)); + } + // Helpers ---------------------------------------------- get cat() { diff --git a/packages/dai-plugin-mcd/src/index.js b/packages/dai-plugin-mcd/src/index.js index 7e204efec..8bd19e32e 100644 --- a/packages/dai-plugin-mcd/src/index.js +++ b/packages/dai-plugin-mcd/src/index.js @@ -14,6 +14,7 @@ import AuctionService from './AuctionService'; import SystemDataService from './SystemDataService'; import { ServiceRoles as ServiceRoles_ } from './constants'; import BigNumber from 'bignumber.js'; +import wethAbi from '../contracts/abis/WETH9.json'; export const ServiceRoles = ServiceRoles_; const { CDP_MANAGER, CDP_TYPE, SYSTEM_DATA, AUCTION, SAVINGS } = ServiceRoles; @@ -54,11 +55,8 @@ export const MKR = createCurrency('MKR'); export const USD = createCurrency('USD'); export const USD_ETH = createCurrencyRatio(USD, ETH); -// these are prefixed with M so that they don't override their SCD versions-- -// otherwise, adding the MCD plugin would break MCD. maybe there's a better way -// to work around this? -export const MWETH = createCurrency('MWETH'); -export const MDAI = createCurrency('MDAI'); +export const WETH = createCurrency('WETH'); +export const DAI = createCurrency('DAI'); // Casting for savings dai export const DSR_DAI = createCurrency('DSR-DAI'); @@ -88,8 +86,8 @@ export const ALLOWANCE_AMOUNT = BigNumber( export const defaultTokens = [ ...new Set([ ...defaultCdpTypes.map(type => type.currency), - MDAI, - MWETH, + DAI, + WETH, SAI, DSR_DAI ]) @@ -107,7 +105,7 @@ export const McdPlugin = { })); } const tokens = uniqBy(cdpTypes, 'currency').map( - ({ currency, address, abi, decimals }, idx) => { + ({ currency, address, abi, decimals }) => { const data = address && abi ? { address, abi } : addContracts[currency.symbol]; assert(data, `No address and ABI found for "${currency.symbol}"`); @@ -127,8 +125,8 @@ export const McdPlugin = { smartContract: { addContracts }, token: { erc20: [ - { currency: MDAI, address: addContracts.MCD_DAI.address }, - { currency: MWETH, address: addContracts.ETH.address }, + { currency: DAI, address: addContracts.MCD_DAI.address }, + { currency: WETH, address: addContracts.ETH.address, abi: wethAbi }, ...tokens ] }, diff --git a/packages/dai-plugin-mcd/src/math.js b/packages/dai-plugin-mcd/src/math.js index acbbf4681..f3a12d8de 100644 --- a/packages/dai-plugin-mcd/src/math.js +++ b/packages/dai-plugin-mcd/src/math.js @@ -1,7 +1,7 @@ import BigNumber from 'bignumber.js'; import { createCurrencyRatio } from '@makerdao/currency'; import { RAY } from './constants'; -import { MDAI, USD } from './index'; +import { DAI, USD } from './index'; // NOTE: When a function below has an argument with the same name as a function // defined earlier in the file, that means it expects that argument's value to @@ -12,7 +12,7 @@ import { MDAI, USD } from './index'; // ilk math export function debtCeiling(line) { - return MDAI.rad(line); + return DAI.rad(line); } export function liquidationPenalty(chop) { @@ -23,7 +23,7 @@ export function liquidationPenalty(chop) { } export function liquidationRatio(mat) { - const ratio = createCurrencyRatio(USD, MDAI); + const ratio = createCurrencyRatio(USD, DAI); return ratio(new BigNumber(mat.toString()).dividedBy(RAY).toString()); } @@ -57,13 +57,13 @@ export function collateralValue(collateralAmount, price) { } export function debtValue(art, rate) { - art = MDAI.wei(art); + art = DAI.wei(art); return art.times(rate).shiftedBy(-27); } export function collateralizationRatio(collateralValue, debtValue) { if (debtValue.eq(0)) { - const ratio = createCurrencyRatio(USD, MDAI); + const ratio = createCurrencyRatio(USD, DAI); return ratio(Infinity); } return collateralValue.div(debtValue); @@ -88,6 +88,6 @@ export function minSafeCollateralAmount(debtValue, liquidationRatio, price) { export function daiAvailable(collateralValue, debtValue, liquidationRatio) { const maxSafeDebtValue = collateralValue.div(liquidationRatio); return debtValue.lt(maxSafeDebtValue) - ? MDAI(maxSafeDebtValue.minus(debtValue)) - : MDAI(0); + ? DAI(maxSafeDebtValue.minus(debtValue)) + : DAI(0); } diff --git a/packages/dai-plugin-mcd/src/schemas/computed.js b/packages/dai-plugin-mcd/src/schemas/computed.js index 18d7890ac..7efe0bf7d 100644 --- a/packages/dai-plugin-mcd/src/schemas/computed.js +++ b/packages/dai-plugin-mcd/src/schemas/computed.js @@ -6,7 +6,7 @@ import { liquidationPrice as calcLiquidationPrice, minSafeCollateralAmount as calcMinSafeCollateralAmount } from '../math'; -import { USD, MDAI, DSR_DAI, defaultCdpTypes, ALLOWANCE_AMOUNT } from '../'; +import { USD, DAI, DSR_DAI, defaultCdpTypes, ALLOWANCE_AMOUNT } from '../'; import BigNumber from 'bignumber.js'; import { RATIO_DAI_USD, @@ -166,7 +166,7 @@ export const debtValue = { [DEBT_SCALING_FACTOR, [VAULT_TYPE, id]] ], computed: (encumberedDebt, debtScalingFactor) => { - return MDAI(encumberedDebt).times(debtScalingFactor); + return DAI(encumberedDebt).times(debtScalingFactor); } }) }; @@ -528,7 +528,7 @@ export const collateralDebt = { [DEBT_SCALING_FACTOR, collateralTypeName] ], computed: (totalEncumberedDebt, debtScalingFactor) => { - return MDAI(totalEncumberedDebt).times(debtScalingFactor); + return DAI(totalEncumberedDebt).times(debtScalingFactor); } }) }; diff --git a/packages/dai-plugin-mcd/src/schemas/spot.js b/packages/dai-plugin-mcd/src/schemas/spot.js index bee14bb7b..80b3a8e0a 100644 --- a/packages/dai-plugin-mcd/src/schemas/spot.js +++ b/packages/dai-plugin-mcd/src/schemas/spot.js @@ -1,6 +1,6 @@ import { toHex, fromRay } from '../utils'; import { createCurrencyRatio } from '@makerdao/currency'; -import { MDAI, USD } from '../..'; +import { DAI, USD } from '..'; import { PRICE_FEED_ADDRESS, @@ -27,7 +27,7 @@ export const spotIlks = { transforms: { [LIQUIDATION_RATIO]: liqRatio => liqRatio.toString() !== '0' - ? createCurrencyRatio(USD, MDAI)(fromRay(liqRatio)) + ? createCurrencyRatio(USD, DAI)(fromRay(liqRatio)) : null } }), @@ -45,7 +45,7 @@ export const spotPar = { contract: 'MCD_SPOT', call: ['par()(uint256)'] }), - returns: [[RATIO_DAI_USD, v => createCurrencyRatio(MDAI, USD)(fromRay(v))]] + returns: [[RATIO_DAI_USD, v => createCurrencyRatio(DAI, USD)(fromRay(v))]] }; export default { diff --git a/packages/dai-plugin-mcd/src/schemas/token.js b/packages/dai-plugin-mcd/src/schemas/token.js index 3e30d35d4..2b5412665 100644 --- a/packages/dai-plugin-mcd/src/schemas/token.js +++ b/packages/dai-plugin-mcd/src/schemas/token.js @@ -10,12 +10,12 @@ export const ALLOWANCE_AMOUNT = BigNumber( export const tokenBalance = { generate: (address, symbol) => { - if (symbol === 'WETH') symbol = 'MWETH'; - if (symbol === 'DAI') symbol = 'MDAI'; + if (symbol === 'WETH') symbol = 'WETH'; + if (symbol === 'DAI') symbol = 'DAI'; const currencyToken = getMcdToken(symbol); const contract = - symbol === 'MDAI' ? 'MCD_DAI' : symbol === 'MWETH' ? 'ETH' : symbol; + symbol === 'DAI' ? 'MCD_DAI' : symbol === 'WETH' ? 'ETH' : symbol; if (!currencyToken) throw new Error(`${symbol} token is not part of the default tokens list`); if (symbol === 'DSR-DAI') @@ -57,14 +57,12 @@ export const tokenBalances = { export const tokenAllowanceBase = { generate: (address, proxyAddress, symbol) => { - if (symbol === 'WETH') symbol = 'MWETH'; - if (symbol === 'DAI') symbol = 'MDAI'; if (symbol === 'ETH' || symbol === 'DSR-DAI') throw new Error(`${symbol} does not require an allowance to be set`); const currencyToken = getMcdToken(symbol); const contract = - symbol === 'MDAI' ? 'MCD_DAI' : symbol === 'MWETH' ? 'ETH' : symbol; + symbol === 'DAI' ? 'MCD_DAI' : symbol === 'WETH' ? 'ETH' : symbol; if (!currencyToken) throw new Error(`${symbol} token is not part of the default tokens list`); @@ -101,9 +99,9 @@ export const adapterBalance = { generate: collateralTypeName => ({ dependencies: ({ get }) => { collateralTypeName = - collateralTypeName === 'MDAI' ? 'DAI' : collateralTypeName; + collateralTypeName === 'DAI' ? 'DAI' : collateralTypeName; let tokenSymbol = collateralTypeName.split('-')[0]; - tokenSymbol = tokenSymbol === 'ETH' ? 'MWETH' : tokenSymbol; + tokenSymbol = tokenSymbol === 'ETH' ? 'WETH' : tokenSymbol; return [ [ TOKEN_BALANCE, diff --git a/packages/dai-plugin-mcd/src/schemas/vat.js b/packages/dai-plugin-mcd/src/schemas/vat.js index f780a7d0d..8bba31f37 100644 --- a/packages/dai-plugin-mcd/src/schemas/vat.js +++ b/packages/dai-plugin-mcd/src/schemas/vat.js @@ -1,5 +1,5 @@ import { toHex, fromRay, fromRad, fromWei } from '../utils'; -import { MDAI } from '../..'; +import { DAI } from '..'; import { TOTAL_ENCUMBERED_DEBT, @@ -27,7 +27,7 @@ export const vatIlks = { [TOTAL_ENCUMBERED_DEBT, fromWei], [DEBT_SCALING_FACTOR, fromRay], [PRICE_WITH_SAFETY_MARGIN, fromRay], - [DEBT_CEILING, v => MDAI(v, 'rad')], + [DEBT_CEILING, v => DAI(v, 'rad')], [DEBT_FLOOR, fromRad] ] }; @@ -38,7 +38,7 @@ export const vatDebt = { contract: 'MCD_VAT', call: ['debt()(uint256)'] }), - returns: [[TOTAL_DAI_SUPPLY, v => MDAI(v, 'rad')]] + returns: [[TOTAL_DAI_SUPPLY, v => DAI(v, 'rad')]] }; export const vatUrns = { @@ -47,7 +47,10 @@ export const vatUrns = { contract: 'MCD_VAT', call: ['urns(bytes32,address)(uint256,uint256)', toHex(ilkName), urn] }), - returns: [[ENCUMBERED_COLLATERAL, fromWei], [ENCUMBERED_DEBT, fromWei]] + returns: [ + [ENCUMBERED_COLLATERAL, fromWei], + [ENCUMBERED_DEBT, fromWei] + ] }; export const vatGem = { @@ -65,7 +68,7 @@ export const vatLine = { contract: 'MCD_VAT', call: ['Line()(uint256)'] }), - returns: [[GLOBAL_DEBT_CEILING, v => MDAI(v, 'rad')]] + returns: [[GLOBAL_DEBT_CEILING, v => DAI(v, 'rad')]] }; export default { diff --git a/packages/dai-plugin-mcd/test/Auction.spec.js b/packages/dai-plugin-mcd/test/Auction.spec.js index ed83043bb..cdbc5045b 100644 --- a/packages/dai-plugin-mcd/test/Auction.spec.js +++ b/packages/dai-plugin-mcd/test/Auction.spec.js @@ -1,7 +1,7 @@ import { mcdMaker } from './helpers'; import { ServiceRoles } from '../src/constants'; -const scenarios = [['ETH-A'], ['MDAI'], ['MKR']]; +const scenarios = [['ETH-A'], ['DAI'], ['MKR']]; /* The following arrays are expected values for each tested @@ -10,7 +10,7 @@ const scenarios = [['ETH-A'], ['MDAI'], ['MKR']]; */ const systemData = { 'ETH-A': [1, 0.01], - MDAI: [3, 0.05], + DAI: [3, 0.05], MKR: [3, 0.05] }; diff --git a/packages/dai-plugin-mcd/test/CdpManager.spec.js b/packages/dai-plugin-mcd/test/CdpManager.spec.js index 81a104609..7a9ee8b55 100644 --- a/packages/dai-plugin-mcd/test/CdpManager.spec.js +++ b/packages/dai-plugin-mcd/test/CdpManager.spec.js @@ -2,7 +2,7 @@ import findIndex from 'lodash/findIndex'; import { mcdMaker, setupCollateral } from './helpers'; import { setMethod, transferToBag } from '../src/CdpManager'; import { ServiceRoles } from '../src/constants'; -import { ETH, MDAI, GNT, DGD, BAT } from '../src'; +import { ETH, DAI, GNT, DGD, BAT } from '../src'; import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; import TestAccountProvider from '@makerdao/test-helpers/src/TestAccountProvider'; @@ -50,8 +50,8 @@ test('getCdpIds gets all CDP data from the proxy', async () => { test('getCombinedDebtValue', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(3)); - await cdpMgr.openLockAndDraw('ETH-A', ETH(2), MDAI(5)); + await cdpMgr.openLockAndDraw('ETH-A', ETH(1), DAI(3)); + await cdpMgr.openLockAndDraw('ETH-A', ETH(2), DAI(5)); maker.service(ServiceRoles.CDP_TYPE).reset(); const currentProxy = await maker.currentProxy(); const totalDebt = await cdpMgr.getCombinedDebtValue(currentProxy); @@ -86,7 +86,7 @@ test('getCdp can disable prefetch', async () => { test('transaction tracking for openLockAndDraw', async () => { const cdpMgr = maker.service(ServiceRoles.CDP_MANAGER); const txMgr = maker.service('transactionManager'); - const open = cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(0)); + const open = cdpMgr.openLockAndDraw('ETH-A', ETH(1), DAI(0)); expect.assertions(5); const handlers = { pending: jest.fn(({ metadata: { contract, method } }) => { @@ -194,7 +194,7 @@ describe('using a different account', () => { test('get event history via web3', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - const cdp = await cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(3)); + const cdp = await cdpMgr.openLockAndDraw('ETH-A', ETH(1), DAI(3)); await cdp.freeCollateral(ETH(0.5)); await cdpMgr.give(cdp.id, '0x1000000000000000000000000000000000000000'); const events = await cdpMgr.getEventHistory(cdp); diff --git a/packages/dai-plugin-mcd/test/CdpType.spec.js b/packages/dai-plugin-mcd/test/CdpType.spec.js index de782e294..8016cd763 100644 --- a/packages/dai-plugin-mcd/test/CdpType.spec.js +++ b/packages/dai-plugin-mcd/test/CdpType.spec.js @@ -1,7 +1,7 @@ import { createCurrencyRatio } from '@makerdao/currency'; import { mcdMaker, setupCollateral } from './helpers'; import { ServiceRoles } from '../src/constants'; -import { ETH, MDAI, USD, BAT } from '../src'; +import { ETH, DAI, USD, BAT } from '../src'; const { CDP_MANAGER, CDP_TYPE } = ServiceRoles; let maker, service; @@ -14,7 +14,10 @@ beforeAll(async () => { // these CDP types should be available to the Maker instance because // of the configuration passed into it (see test/helpers.js) -const scenarios = [['ETH-A', ETH], ['BAT-A', BAT]]; +const scenarios = [ + ['ETH-A', ETH], + ['BAT-A', BAT] +]; /* The following arrays are expected values for each tested @@ -57,7 +60,7 @@ describe.each(scenarios)('%s', (ilk, GEM) => { }); test('get debt ceiling', () => { - expect(cdpType.debtCeiling).toEqual(MDAI(systemValues[ilk][2])); + expect(cdpType.debtCeiling).toEqual(DAI(systemValues[ilk][2])); }); test('get liquidation ratio', () => { diff --git a/packages/dai-plugin-mcd/test/ManagedCdp.spec.js b/packages/dai-plugin-mcd/test/ManagedCdp.spec.js index ca72deeb5..9007bb750 100644 --- a/packages/dai-plugin-mcd/test/ManagedCdp.spec.js +++ b/packages/dai-plugin-mcd/test/ManagedCdp.spec.js @@ -1,6 +1,6 @@ import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; import { mcdMaker, setupCollateral } from './helpers'; -import { ETH, MDAI, USD, BAT, GNT, DGD, USDC } from '../src'; +import { ETH, DAI, USD, BAT, GNT, DGD, USDC } from '../src'; import { ServiceRoles } from '../src/constants'; import { createCurrencyRatio } from '@makerdao/currency'; const { CDP_MANAGER } = ServiceRoles; @@ -17,7 +17,7 @@ beforeAll(async () => { { currency: USDC, ilk: 'USDC-A', decimals: 6 } ] }); - dai = maker.getToken(MDAI); + dai = maker.getToken(DAI); // the current account has a proxy only because the testchain setup script // creates it -- this is probably not a future-proof assumption proxy = await maker.currentProxy(); @@ -53,7 +53,7 @@ test('liquidationPrice and collateralizationRatio are infinite with 0 collateral const cdp = await maker.service(CDP_MANAGER).open('BAT-A'); await cdp.prefetch(); const ratio = createCurrencyRatio(USD, BAT); - const ratio2 = createCurrencyRatio(USD, MDAI); + const ratio2 = createCurrencyRatio(USD, DAI); expect(cdp.liquidationPrice).toEqual(ratio(Infinity)); expect(cdp.collateralizationRatio).toEqual(ratio2(Infinity)); }); @@ -114,7 +114,7 @@ async function expectValues( expect(cdp.isSafe).toBe(isSafe); } if (daiAvailable !== undefined) { - cdp.daiAvailable.eq(MDAI(daiAvailable)); + cdp.daiAvailable.eq(DAI(daiAvailable)); } } @@ -201,7 +201,7 @@ describe.each([ test('openLockAndDraw, get, draw, wipe, wipeAndFree', async () => { const txStates = ['pending', 'mined', 'confirmed']; const mgr = maker.service(CDP_MANAGER); - const cdp = await mgr.openLockAndDraw(ilk, GEM(1), MDAI(1)); + const cdp = await mgr.openLockAndDraw(ilk, GEM(1), DAI(1)); await expectValues(cdp, { collateral: 1, debt: 1, @@ -249,7 +249,7 @@ describe.each([ myDai: startingDaiBalance.plus(1.5) }); - await cdp.wipeAndFree(MDAI(1), GEM(0.5)); + await cdp.wipeAndFree(DAI(1), GEM(0.5)); await expectValuesAfterReset(cdp, { collateral: 0.5, debt: 0.5, @@ -261,7 +261,7 @@ describe.each([ test('openLockAndDraw, wipeAll, give', async () => { const txStates = ['pending', 'mined', 'confirmed']; const mgr = maker.service(CDP_MANAGER); - const cdp = await mgr.openLockAndDraw(ilk, GEM(1), MDAI(1)); + const cdp = await mgr.openLockAndDraw(ilk, GEM(1), DAI(1)); await expectValuesAfterReset(cdp, { debt: 1, myDai: startingDaiBalance.plus(1) @@ -298,7 +298,7 @@ describe.each([ test('openLockAndDraw, wipeAllAndFree, giveToProxy', async () => { const txStates = ['pending', 'mined', 'confirmed']; const mgr = maker.service(CDP_MANAGER); - const cdp = await mgr.openLockAndDraw(ilk, GEM(1), MDAI(1)); + const cdp = await mgr.openLockAndDraw(ilk, GEM(1), DAI(1)); await expectValuesAfterReset(cdp, { collateral: 1, debt: 1, @@ -342,9 +342,9 @@ describe.each([ test('openLockAndDraw, unsafeWipe', async () => { const txStates = ['pending', 'mined', 'confirmed']; const mgr = maker.service(CDP_MANAGER); - const cdp = await mgr.openLockAndDraw(ilk, GEM(1), MDAI(1)); + const cdp = await mgr.openLockAndDraw(ilk, GEM(1), DAI(1)); - const unsafeWipe = cdp.unsafeWipe(MDAI(1)); + const unsafeWipe = cdp.unsafeWipe(DAI(1)); const unsafeWipeHandler = jest.fn((tx, state) => { expect(tx.metadata.method).toEqual(expect.stringContaining('wipe')); expect(state).toBe(txStates[unsafeWipeHandler.mock.calls.length - 1]); @@ -357,7 +357,7 @@ describe.each([ test('openLockAndDraw, unsafeWipeAll', async () => { const txStates = ['pending', 'mined', 'confirmed']; const mgr = maker.service(CDP_MANAGER); - const cdp = await mgr.openLockAndDraw(ilk, GEM(1), MDAI(1)); + const cdp = await mgr.openLockAndDraw(ilk, GEM(1), DAI(1)); const unsafeWipeAll = cdp.unsafeWipeAll(); const unsafeWipeAllHandler = jest.fn((tx, state) => { diff --git a/packages/dai-plugin-mcd/test/SavingsService.spec.js b/packages/dai-plugin-mcd/test/SavingsService.spec.js index 60fe1e28f..60c89cb45 100644 --- a/packages/dai-plugin-mcd/test/SavingsService.spec.js +++ b/packages/dai-plugin-mcd/test/SavingsService.spec.js @@ -6,7 +6,7 @@ import { } from '@makerdao/test-helpers'; import { mcdMaker, setupCollateral } from './helpers'; import { ServiceRoles } from '../src/constants'; -import { MDAI, ETH } from '../src/index'; +import { DAI, ETH } from '../src/index'; import BigNumber from 'bignumber.js'; import findIndex from 'lodash/findIndex'; @@ -39,19 +39,19 @@ describe('Savings Service', () => { async function makeSomeDai(amount) { const cdpMgr = await maker.service(ServiceRoles.CDP_MANAGER); await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(amount)); + await cdpMgr.openLockAndDraw('ETH-A', ETH(1), DAI(amount)); } beforeAll(async () => { maker = await mcdMaker(); service = maker.service(ServiceRoles.SAVINGS); - dai = maker.getToken(MDAI); + dai = maker.getToken(DAI); proxyAddress = await maker.service('proxy').ensureProxy(); await dai.approveUnlimited(proxyAddress); }); afterAll(async () => { - await maker.service('allowance').removeAllowance('MDAI', proxyAddress); + await maker.service('allowance').removeAllowance('DAI', proxyAddress); }); beforeEach(async () => { @@ -73,7 +73,7 @@ describe('Savings Service', () => { const potTotalBeforeJoin = await service.getTotalDai(); expect(potTotalBeforeJoin.toNumber()).toBe(0); - await service.join(MDAI(2)); + await service.join(DAI(2)); const potTotalAfterJoin = await service.getTotalDai(); expect(potTotalAfterJoin.toNumber()).toBe(2); @@ -85,7 +85,7 @@ describe('Savings Service', () => { expect(potTotalBeforeJoin.toNumber()).toBe(0); const joinAmount = 2; - await service.join(MDAI(joinAmount)); + await service.join(DAI(joinAmount)); const potTotalAfterJoin = await service.getTotalDai(); expect(potTotalAfterJoin.toNumber()).toBe(2); @@ -102,13 +102,13 @@ describe('Savings Service', () => { test('check amount in balance', async () => { const amount = await service.balance(); - expect(MDAI.isInstance(amount)).toBeTruthy(); + expect(DAI.isInstance(amount)).toBeTruthy(); }); test('check amount using balance of', async () => { const proxyAddress = await maker.currentProxy(); const amount = await service.balanceOf(proxyAddress); - expect(MDAI.isInstance(amount)).toBeTruthy(); + expect(DAI.isInstance(amount)).toBeTruthy(); }); test('get balance without proxy', async () => { @@ -127,7 +127,7 @@ describe('Savings Service', () => { await makeSomeDai(3); const joinAmount = 2; - await service.join(MDAI(joinAmount)); + await service.join(DAI(joinAmount)); const balanceBeforeTime = await service.balanceOf(proxyAddress); expect(balanceBeforeTime.toNumber()).toBe(joinAmount); @@ -144,7 +144,7 @@ describe('Savings Service', () => { test('check balance after join with multiple accounts', async () => { await makeSomeDai(3); - await service.join(MDAI(2)); + await service.join(DAI(2)); const { address, key } = TestAccountProvider.nextAccount(); await maker @@ -152,7 +152,7 @@ describe('Savings Service', () => { .addAccount(address, { type: 'privateKey', key }); const otherAccountJoinAmount = 1; - await maker.getToken(MDAI).transfer(address, otherAccountJoinAmount); + await maker.getToken(DAI).transfer(address, otherAccountJoinAmount); await mineBlocks(maker.service('web3'), 3); await maker @@ -163,7 +163,7 @@ describe('Savings Service', () => { maker.service('accounts').useAccount(address); const otherProxyAddress = await maker.service('proxy').ensureProxy(); await dai.approveUnlimited(otherProxyAddress); - await service.join(MDAI(otherAccountJoinAmount)); + await service.join(DAI(otherAccountJoinAmount)); const [chi1, chi2] = await mineBlocksAndReturnChi(3); const accruedInterest = calculateAccruedInterest( @@ -182,11 +182,11 @@ describe('Savings Service', () => { test('cannot exit pot more than joined', async () => { await makeSomeDai(3); - await service.join(MDAI(1)); + await service.join(DAI(1)); const startingBalance = await dai.balance(); - const exit = service.exit(MDAI(2)); + const exit = service.exit(DAI(2)); await expect(exit).rejects.toThrow(); const endingBalance = await dai.balance(); @@ -200,7 +200,7 @@ describe('Savings Service', () => { const amountBeforeJoin = await service.balance(); const joinAmount = 2; - await service.join(MDAI(joinAmount)); + await service.join(DAI(joinAmount)); const amountAfterJoin = await service.balance(); expect(amountAfterJoin.toNumber()).toBeCloseTo( @@ -214,7 +214,7 @@ describe('Savings Service', () => { const [chi1, chi2] = await mineBlocksAndReturnChi(3); const accruedInterest = calculateAccruedInterest(joinAmount, chi1, chi2); - await service.exit(MDAI(joinAmount)); + await service.exit(DAI(joinAmount)); const amountAfterExit = await service.balance(); expect(amountAfterExit.toNumber()).toBeCloseTo(accruedInterest, 8); @@ -222,8 +222,8 @@ describe('Savings Service', () => { const endingBalance = await dai.balance(); // Due to how 'exit' handles rounding sub-wei amounts, the ending balance can be one wei less than expected - const amountLessWei = MDAI(startingBalance) - .minus(MDAI.wei(1)) + const amountLessWei = DAI(startingBalance) + .minus(DAI.wei(1)) .toBigNumber() .toString(); expect( @@ -238,7 +238,7 @@ describe('Savings Service', () => { const startingBalance = (await dai.balance()).toNumber(); const joinAmount = 2; - await service.join(MDAI(joinAmount)); + await service.join(DAI(joinAmount)); const [chi1, chi2] = await mineBlocksAndReturnChi(3); const accruedInterest = calculateAccruedInterest(joinAmount, chi1, chi2); @@ -254,11 +254,11 @@ describe('Savings Service', () => { xtest('get dsr event history via web3', async () => { await makeSomeDai(10); - await service.join(MDAI(3)); + await service.join(DAI(3)); await mineBlocks(maker.service('web3'), 5); const exitAmount = '2'; - await service.exit(MDAI(exitAmount)); + await service.exit(DAI(exitAmount)); const events = await service.getEventHistory(proxyAddress); const depositEventIdx = findIndex(events, { type: 'DSR_DEPOSIT' }); @@ -272,15 +272,15 @@ describe('Savings Service', () => { expect(events[withdrawEventIdx].gem).toEqual('DAI'); // Due to how 'exit' handles rounding sub-wei amounts, the exit amount returned can be one wei less than intended - const amountLessWei = MDAI(exitAmount) - .minus(MDAI.wei(1)) + const amountLessWei = DAI(exitAmount) + .minus(DAI.wei(1)) .toBigNumber() .toString(); expect( [exitAmount, amountLessWei].includes(events[withdrawEventIdx].amount) ).toBe(true); - await service.join(MDAI(1)); + await service.join(DAI(1)); const cachedEvents = await service.getEventHistory(proxyAddress); expect(cachedEvents.length).toEqual(2); @@ -289,7 +289,7 @@ describe('Savings Service', () => { test('earnings to date', async () => { await makeSomeDai(10); const joinAmount = 10; - await service.join(MDAI(joinAmount)); + await service.join(DAI(joinAmount)); const etdA = await service.getEarningsToDate(proxyAddress); const [chi1, chi2] = await mineBlocksAndReturnChi(10); diff --git a/packages/dai-plugin-mcd/test/SystemDataService.spec.js b/packages/dai-plugin-mcd/test/SystemDataService.spec.js index 4d9ac5921..14d51eeed 100644 --- a/packages/dai-plugin-mcd/test/SystemDataService.spec.js +++ b/packages/dai-plugin-mcd/test/SystemDataService.spec.js @@ -1,5 +1,6 @@ import { mcdMaker } from './helpers'; import { ServiceRoles } from '../src/constants'; +import { DAI } from '../src/index'; let service; let maker; @@ -23,3 +24,9 @@ test('get global settlement status', async () => { const cage = await service.isGlobalSettlementInvoked(); expect(cage).toBe(false); }); + +test('get system surplus', async () => { + const surplus = await service.getSystemSurplus(); + console.log('surplus.toNumber', surplus.toNumber()); + expect(surplus).toEqual(DAI(0)); //TODO change to expect non-zero number +}); diff --git a/packages/dai-plugin-mcd/test/integration/mcd.spec.js b/packages/dai-plugin-mcd/test/integration/mcd.spec.js index 2db8338cd..2cad9c47a 100644 --- a/packages/dai-plugin-mcd/test/integration/mcd.spec.js +++ b/packages/dai-plugin-mcd/test/integration/mcd.spec.js @@ -1,6 +1,6 @@ import { mcdMaker } from '../helpers'; import { ServiceRoles } from '../../src/constants'; -import { ETH, MDAI } from '../../src'; +import { ETH, DAI } from '../../src'; import { uniqueId } from '../../src/utils/index'; import debug from 'debug'; import { infuraProjectId } from './index'; @@ -35,7 +35,7 @@ beforeAll(async () => { await maker.authenticate(); - dai = maker.getToken(MDAI); + dai = maker.getToken(DAI); proxy = await maker.currentProxy(); txMgr = maker.service('transactionManager'); @@ -59,7 +59,7 @@ async function expectValues(cdp, { collateral, debt, myGem, myDai }) { expect(await cdp.getCollateralAmount()).toEqual(cdp.currency(collateral)); } if (debt !== undefined) { - expect(await cdp.getDebtValue()).toEqual(MDAI(debt)); + expect(await cdp.getDebtValue()).toEqual(DAI(debt)); } if (myGem !== undefined) { const balance = await maker.getToken(cdp.currency).balance(); @@ -131,7 +131,7 @@ describe.each(scenarios)('%s', (ilk, GEM) => { startingGemBalance = await maker.getToken(GEM).balance(); startingDaiBalance = await dai.balance(); await dai.approveUnlimited(proxy); - const cdp = await mgr.openLockAndDraw(ilk, GEM(0.01), MDAI(0.1)); + const cdp = await mgr.openLockAndDraw(ilk, GEM(0.01), DAI(0.1)); await expectValues(cdp, { collateral: 0.01, debt: 0.1, @@ -172,7 +172,7 @@ describe.each(scenarios)('%s', (ilk, GEM) => { myDai: startingDaiBalance.plus(0.15) }); - await cdp.wipeAndFree(MDAI(0.1), GEM(0.005)); + await cdp.wipeAndFree(DAI(0.1), GEM(0.005)); await expectValues(cdp, { collateral: 0.005, debt: 0.05, diff --git a/packages/dai-plugin-mcd/test/math.spec.js b/packages/dai-plugin-mcd/test/math.spec.js index 4e5f00ad3..a09f2dfb1 100644 --- a/packages/dai-plugin-mcd/test/math.spec.js +++ b/packages/dai-plugin-mcd/test/math.spec.js @@ -1,10 +1,10 @@ import { daiAvailable } from '../src/math'; -import { USD, MDAI } from '../src'; +import { USD, DAI } from '../src'; test('daiAvailable', () => { - expect(daiAvailable(USD(10), USD(5), 1)).toEqual(MDAI(5)); + expect(daiAvailable(USD(10), USD(5), 1)).toEqual(DAI(5)); }); test('daiAvailable handles undercollateralized values', () => { - expect(daiAvailable(USD(10), USD(5), 2.1)).toEqual(MDAI(0)); + expect(daiAvailable(USD(10), USD(5), 2.1)).toEqual(DAI(0)); }); diff --git a/packages/dai-plugin-mcd/test/schemas/cdpManager.spec.js b/packages/dai-plugin-mcd/test/schemas/cdpManager.spec.js index b0f940974..34d11a1bf 100644 --- a/packages/dai-plugin-mcd/test/schemas/cdpManager.spec.js +++ b/packages/dai-plugin-mcd/test/schemas/cdpManager.spec.js @@ -1,6 +1,6 @@ import { mcdMaker, setupCollateral } from '../helpers'; import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; -import { ETH, BAT, MDAI } from '../../src'; +import { ETH, BAT, DAI } from '../../src'; import { ServiceRoles } from '../../src/constants'; import BigNumber from 'bignumber.js'; @@ -8,8 +8,7 @@ import { VAULT_ADDRESS, VAULT_TYPE, VAULTS_CREATED, - VAULT_OWNER, - TOTAL_OWNED_VAULTS + VAULT_OWNER } from '../../src/schemas'; import cdpManagerSchemas from '../../src/schemas/cdpManager'; @@ -17,7 +16,7 @@ import cdpManagerSchemas from '../../src/schemas/cdpManager'; let maker, snapshotData, cdpMgr, proxyAddress, expectedVaultAddress; const ETH_A_COLLATERAL_AMOUNT = ETH(1); -const ETH_A_DEBT_AMOUNT = MDAI(1); +const ETH_A_DEBT_AMOUNT = DAI(1); const ETH_A_PRICE = 180; beforeAll(async () => { @@ -38,7 +37,7 @@ beforeAll(async () => { }); cdpMgr = await maker.service(ServiceRoles.CDP_MANAGER); - const dai = maker.getToken(MDAI); + const dai = maker.getToken(DAI); proxyAddress = await maker.service('proxy').ensureProxy(); await dai.approveUnlimited(proxyAddress); diff --git a/packages/dai-plugin-mcd/test/schemas/computed.spec.js b/packages/dai-plugin-mcd/test/schemas/computed.spec.js index 0566b22d7..ffe438fd9 100644 --- a/packages/dai-plugin-mcd/test/schemas/computed.spec.js +++ b/packages/dai-plugin-mcd/test/schemas/computed.spec.js @@ -1,5 +1,5 @@ import { mcdMaker, setupCollateral } from '../helpers'; -import { ETH, BAT, MDAI, USD } from '../../src'; +import { ETH, BAT, DAI, USD } from '../../src'; import { takeSnapshot, restoreSnapshot, @@ -66,11 +66,11 @@ let maker, expectedEthVaultAddress, expectedBatVaultAddress; const ETH_A_COLLATERAL_AMOUNT = ETH(1); -const ETH_A_DEBT_AMOUNT = MDAI(1); +const ETH_A_DEBT_AMOUNT = DAI(1); const ETH_A_PRICE = 180; const BAT_A_COLLATERAL_AMOUNT = BAT(1); -const BAT_A_DEBT_AMOUNT = MDAI(1); +const BAT_A_DEBT_AMOUNT = DAI(1); const BAT_A_PRICE = 40; beforeAll(async () => { @@ -117,7 +117,7 @@ beforeAll(async () => { const mgr = await maker.service(ServiceRoles.CDP_MANAGER); const sav = await maker.service(ServiceRoles.SAVINGS); - const dai = maker.getToken(MDAI); + const dai = maker.getToken(DAI); proxyAddress = await maker.service('proxy').ensureProxy(); await dai.approveUnlimited(proxyAddress); @@ -135,7 +135,7 @@ beforeAll(async () => { ); expectedBatVaultAddress = await mgr.getUrn(vault.id); - await sav.join(MDAI(1)); + await sav.join(DAI(1)); }); afterAll(async () => { @@ -245,7 +245,7 @@ test(COLLATERAL_VALUE, async () => { test(COLLATERALIZATION_RATIO, async () => { const cdpId = 1; const colRatio = await maker.latest(COLLATERALIZATION_RATIO, cdpId); - const expected = createCurrencyRatio(USD, MDAI)(180); + const expected = createCurrencyRatio(USD, DAI)(180); expect(colRatio.toString()).toEqual(expected.toString()); }); @@ -253,7 +253,7 @@ test(COLLATERALIZATION_RATIO, async () => { test(DEBT_VALUE, async () => { const cdpId = 1; const debtValue = await maker.latest(DEBT_VALUE, cdpId); - const expected = MDAI(1); + const expected = DAI(1); expect(debtValue.toNumber()).toEqual(expected.toNumber()); }); @@ -269,7 +269,7 @@ test(LIQUIDATION_PRICE, async () => { test(DAI_AVAILABLE, async () => { const cdpId = 1; const daiAvailable = await maker.latest(DAI_AVAILABLE, cdpId); - const expected = MDAI(119); + const expected = DAI(119); expect(daiAvailable.toString()).toEqual(expected.toString()); }); @@ -306,16 +306,16 @@ test(VAULT, async () => { const expectedEncumberedCollateral = fromWei(1000000000000000000); const expectedEncumberedDebt = fromWei(995000000000000000); const expectedColTypePrice = createCurrencyRatio(USD, ETH)(180); - const expectedDebtValue = MDAI(1); - const expectedColRatio = createCurrencyRatio(USD, MDAI)(180); + const expectedDebtValue = DAI(1); + const expectedColRatio = createCurrencyRatio(USD, DAI)(180); const expectedCollateralAmount = ETH(1); const expectedCollateralValue = USD(180); const expectedLiquidationPrice = createCurrencyRatio(USD, ETH)(1.5); - const expectedDaiAvailable = MDAI(119); + const expectedDaiAvailable = DAI(119); const expectedCollateralAvailableAmount = ETH(0.99); const expectedCollateralAvailableValue = USD(178.5); const expectedUnlockedCollateral = fromWei(0); - const expectedLiqRatio = createCurrencyRatio(USD, MDAI)(1.5); + const expectedLiqRatio = createCurrencyRatio(USD, DAI)(1.5); const expectedLiqPenalty = BigNumber('0.05'); const expectedAnnStabilityFee = 0.04999999999989363; const expectedDebtFloor = BigNumber('0'); @@ -395,10 +395,10 @@ test(BALANCE, async () => { const daiBalance = await maker.latest(BALANCE, 'DAI', address); const wethBalance = await maker.latest(BALANCE, 'WETH', address); - expect(daiBalance.symbol).toEqual('MDAI'); + expect(daiBalance.symbol).toEqual('DAI'); expect(daiBalance.toBigNumber()).toEqual(BigNumber('1')); - expect(wethBalance.symbol).toEqual('MWETH'); + expect(wethBalance.symbol).toEqual('WETH'); expect(wethBalance.toBigNumber()).toEqual(BigNumber('0')); const dsrDaiBalance = await maker.latest(BALANCE, 'DSR-DAI', address); @@ -485,7 +485,7 @@ test(PROXY_OWNER, async () => { test(COLLATERAL_TYPE_DATA, async () => { const collateralType = 'ETH-A'; const expectedColTypePrice = createCurrencyRatio(USD, ETH)(180); - const expectedLiqRatio = createCurrencyRatio(USD, MDAI)(1.5); + const expectedLiqRatio = createCurrencyRatio(USD, DAI)(1.5); const expectedLiqPenalty = BigNumber('0.05'); const expectedAnnStabilityFee = 0.04999999999989363; const expectedPriceWithSafetyMargin = BigNumber('120'); diff --git a/packages/dai-plugin-mcd/test/schemas/getCdps.spec.js b/packages/dai-plugin-mcd/test/schemas/getCdps.spec.js index 0cca09417..9fba0e322 100644 --- a/packages/dai-plugin-mcd/test/schemas/getCdps.spec.js +++ b/packages/dai-plugin-mcd/test/schemas/getCdps.spec.js @@ -2,7 +2,7 @@ import { mcdMaker, setupCollateral } from '../helpers'; import { CDP_MANAGER } from '../../contracts/addresses/testnet'; import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; import { ServiceRoles } from '../../src/constants'; -import { ETH, BAT, MDAI } from '../../src'; +import { ETH, BAT, DAI } from '../../src'; import { USER_VAULT_IDS, @@ -15,11 +15,11 @@ import getCdpsSchemas from '../../src/schemas/getCdps'; let maker, snapshotData, proxyAddress, mgr, ethCdp, batCdp; const ETH_A_COLLATERAL_AMOUNT = ETH(1); -const ETH_A_DEBT_AMOUNT = MDAI(1); +const ETH_A_DEBT_AMOUNT = DAI(1); const ETH_A_PRICE = 180; const BAT_A_COLLATERAL_AMOUNT = BAT(1); -const BAT_A_DEBT_AMOUNT = MDAI(1); +const BAT_A_DEBT_AMOUNT = DAI(1); const BAT_A_PRICE = 40; beforeAll(async () => { @@ -27,7 +27,7 @@ beforeAll(async () => { multicall: true }); mgr = await maker.service(ServiceRoles.CDP_MANAGER); - const dai = maker.getToken(MDAI); + const dai = maker.getToken(DAI); snapshotData = await takeSnapshot(maker); proxyAddress = await maker.service('proxy').ensureProxy(); diff --git a/packages/dai-plugin-mcd/test/schemas/pot.spec.js b/packages/dai-plugin-mcd/test/schemas/pot.spec.js index dd91c054c..c80f9dbd1 100644 --- a/packages/dai-plugin-mcd/test/schemas/pot.spec.js +++ b/packages/dai-plugin-mcd/test/schemas/pot.spec.js @@ -1,6 +1,6 @@ import { mcdMaker, setupCollateral } from '../helpers'; import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; -import { ETH, MDAI } from '../../src'; +import { ETH, DAI } from '../../src'; import { ServiceRoles } from '../../src/constants'; import BigNumber from 'bignumber.js'; @@ -16,7 +16,7 @@ import potSchemas from '../../src/schemas/pot'; let maker, snapshotData, cdpMgr, saveService; const ETH_A_COLLATERAL_AMOUNT = ETH(1); -const ETH_A_DEBT_AMOUNT = MDAI(1); +const ETH_A_DEBT_AMOUNT = DAI(1); const ETH_A_PRICE = 180; beforeAll(async () => { @@ -36,7 +36,7 @@ beforeAll(async () => { cdpMgr = await maker.service(ServiceRoles.CDP_MANAGER); saveService = await maker.service(ServiceRoles.SAVINGS); - const dai = maker.getToken(MDAI); + const dai = maker.getToken(DAI); const _proxyAddress = await maker.service('proxy').ensureProxy(); await dai.approveUnlimited(_proxyAddress); @@ -46,7 +46,7 @@ beforeAll(async () => { ETH_A_DEBT_AMOUNT ); - await saveService.join(MDAI(1)); + await saveService.join(DAI(1)); }); afterAll(async () => { diff --git a/packages/dai-plugin-mcd/test/schemas/spot.spec.js b/packages/dai-plugin-mcd/test/schemas/spot.spec.js index 37e904a7c..17827a5be 100644 --- a/packages/dai-plugin-mcd/test/schemas/spot.spec.js +++ b/packages/dai-plugin-mcd/test/schemas/spot.spec.js @@ -51,8 +51,8 @@ test(LIQUIDATION_RATIO, async () => { const ethALiquidationRatio = await maker.latest(LIQUIDATION_RATIO, 'ETH-A'); const batALiquidationRatio = await maker.latest(LIQUIDATION_RATIO, 'BAT-A'); - expect(ethALiquidationRatio.symbol).toEqual('USD/MDAI'); - expect(batALiquidationRatio.symbol).toEqual('USD/MDAI'); + expect(ethALiquidationRatio.symbol).toEqual('USD/DAI'); + expect(batALiquidationRatio.symbol).toEqual('USD/DAI'); expect(ethALiquidationRatio.toNumber()).toEqual(1.5); expect(batALiquidationRatio.toNumber()).toEqual(2.0); @@ -66,6 +66,6 @@ test(LIQUIDATION_RATIO, async () => { test(RATIO_DAI_USD, async () => { const ratio = await maker.latest(RATIO_DAI_USD); - expect(ratio.symbol).toEqual('MDAI/USD'); + expect(ratio.symbol).toEqual('DAI/USD'); expect(ratio.toNumber()).toEqual(1); }); diff --git a/packages/dai-plugin-mcd/test/schemas/token.spec.js b/packages/dai-plugin-mcd/test/schemas/token.spec.js index b3d552d30..d68e9aefc 100644 --- a/packages/dai-plugin-mcd/test/schemas/token.spec.js +++ b/packages/dai-plugin-mcd/test/schemas/token.spec.js @@ -5,7 +5,7 @@ import { mineBlocks, TestAccountProvider } from '@makerdao/test-helpers'; -import { ETH, BAT, MDAI, MWETH, ALLOWANCE_AMOUNT } from '../../src'; +import { ETH, BAT, DAI, WETH, ALLOWANCE_AMOUNT } from '../../src'; import BigNumber from 'bignumber.js'; import { ServiceRoles } from '../../src/constants'; @@ -20,10 +20,10 @@ import tokenSchemas from '../../src/schemas/token'; let maker, snapshotData, address, address2, proxyAddress; const ETH_A_COLLATERAL_AMOUNT = ETH(1); -const ETH_A_DEBT_AMOUNT = MDAI(1); +const ETH_A_DEBT_AMOUNT = DAI(1); const BAT_A_COLLATERAL_AMOUNT = BAT(1); -const BAT_A_DEBT_AMOUNT = MDAI(1); +const BAT_A_DEBT_AMOUNT = DAI(1); beforeAll(async () => { maker = await mcdMaker({ @@ -63,8 +63,8 @@ test(TOKEN_BALANCE, async () => { const daiBalance = await maker.latest(TOKEN_BALANCE, address, 'DAI'); const wethBalance = await maker.latest(TOKEN_BALANCE, address, 'WETH'); - expect(daiBalance.symbol).toEqual('MDAI'); - expect(wethBalance.symbol).toEqual('MWETH'); + expect(daiBalance.symbol).toEqual('DAI'); + expect(wethBalance.symbol).toEqual('WETH'); try { await maker.latest(TOKEN_BALANCE, address, 'NON_MCD_TOKEN'); @@ -141,7 +141,7 @@ test(ADAPTER_BALANCE, async () => { const ethAdapterBalance = await maker.latest(ADAPTER_BALANCE, 'ETH-A'); const batAdapterBalance = await maker.latest(ADAPTER_BALANCE, 'BAT-A'); - expect(ethAdapterBalance.symbol).toEqual(MWETH.symbol); + expect(ethAdapterBalance.symbol).toEqual(WETH.symbol); expect(batAdapterBalance.symbol).toEqual(BAT.symbol); expect(ethAdapterBalance.toBigNumber()).toEqual(BigNumber('1')); diff --git a/packages/dai-plugin-mcd/test/schemas/vat.spec.js b/packages/dai-plugin-mcd/test/schemas/vat.spec.js index c90de01da..9c0a29a55 100644 --- a/packages/dai-plugin-mcd/test/schemas/vat.spec.js +++ b/packages/dai-plugin-mcd/test/schemas/vat.spec.js @@ -1,6 +1,6 @@ import { mcdMaker, setupCollateral } from '../helpers'; import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; -import { ETH, BAT, MDAI } from '../../src'; +import { ETH, BAT, DAI } from '../../src'; import { ServiceRoles } from '../../src/constants'; import { fromRay, fromWei, isBigNumber, isCurrency } from '../../src/utils'; import BigNumber from 'bignumber.js'; @@ -23,11 +23,11 @@ import vatSchemas from '../../src/schemas/vat'; let maker, snapshotData, ethAInfo, batAInfo, cdpMgr, cdpTypeService; const ETH_A_COLLATERAL_AMOUNT = ETH(1); -const ETH_A_DEBT_AMOUNT = MDAI(1); +const ETH_A_DEBT_AMOUNT = DAI(1); const ETH_A_PRICE = 180; const BAT_A_COLLATERAL_AMOUNT = BAT(1); -const BAT_A_DEBT_AMOUNT = MDAI(1); +const BAT_A_DEBT_AMOUNT = DAI(1); const BAT_A_PRICE = 40; beforeAll(async () => { @@ -49,7 +49,7 @@ beforeAll(async () => { await setupCollateral(maker, 'BAT-A', { price: BAT_A_PRICE }); cdpMgr = await maker.service(ServiceRoles.CDP_MANAGER); - const dai = maker.getToken(MDAI); + const dai = maker.getToken(DAI); const _proxyAddress = await maker.service('proxy').ensureProxy(); await dai.approveUnlimited(_proxyAddress); @@ -147,8 +147,8 @@ test(DEBT_CEILING, async () => { expect(isCurrency(ethADebtCeiling)).toEqual(true); expect(isCurrency(batADebtCeiling)).toEqual(true); - expect(ethADebtCeiling.isEqual(MDAI(100000))).toEqual(true); - expect(batADebtCeiling.isEqual(MDAI(5000))).toEqual(true); + expect(ethADebtCeiling.isEqual(DAI(100000))).toEqual(true); + expect(batADebtCeiling.isEqual(DAI(5000))).toEqual(true); }); test(DEBT_FLOOR, async () => { @@ -166,13 +166,13 @@ test(TOTAL_DAI_SUPPLY, async () => { const { Art: ethAArt, rate: ethARate } = ethAInfo; const { Art: batAArt, rate: batARate } = batAInfo; - const ethADaiGenerated = MDAI.rad(BigNumber(ethAArt).times(ethARate)); - const batADaiGenerated = MDAI.rad(BigNumber(batAArt).times(batARate)); + const ethADaiGenerated = DAI.rad(BigNumber(ethAArt).times(ethARate)); + const batADaiGenerated = DAI.rad(BigNumber(batAArt).times(batARate)); const sumOfDaiGeneratedFromIlks = ethADaiGenerated.plus(batADaiGenerated); const totalDaiAmount = await maker.latest(TOTAL_DAI_SUPPLY); - expect(totalDaiAmount.symbol).toEqual('MDAI'); + expect(totalDaiAmount.symbol).toEqual('DAI'); expect(totalDaiAmount.isEqual(sumOfDaiGeneratedFromIlks)).toEqual(true); }); @@ -213,6 +213,6 @@ test(UNLOCKED_COLLATERAL, async () => { test(GLOBAL_DEBT_CEILING, async () => { const globalDebtCeiling = await maker.latest(GLOBAL_DEBT_CEILING); - expect(globalDebtCeiling.symbol).toEqual(MDAI.symbol); + expect(globalDebtCeiling.symbol).toEqual(DAI.symbol); expect(globalDebtCeiling.toBigNumber()).toEqual(BigNumber('1000000')); }); diff --git a/packages/dai-plugin-migrations/contracts/abiMap.js b/packages/dai-plugin-migrations/contracts/abiMap.js index 01c785fcc..593d3bd4e 100644 --- a/packages/dai-plugin-migrations/contracts/abiMap.js +++ b/packages/dai-plugin-migrations/contracts/abiMap.js @@ -11,5 +11,14 @@ module.exports = { MIGRATION_PROXY_ACTIONS: require('./abis/MigrationProxyActions'), OLD_CHIEF: require('./abis/DSChief'), OLD_VOTE_PROXY_FACTORY: require('./abis/VoteProxyFactory'), - OLD_MKR: require('./abis/DSToken') + 'MCD_JOIN_*': require('./abis/GemJoin'), + PROXY_ACTIONS_END: require('./abis/DssProxyActionsEnd'), + SAI_CAGEFREE: require('./abis/CageFree'), + MCD_ESM: require('./abis/ESM'), + MCD_END: require('./abis/End'), + MCD_VAT: require('./abis/Vat'), + GET_CDPS: require('./abis/GetCdps'), + CDP_MANAGER: require('./abis/DssCdpManager'), + MCD_DAI: require('./abis/Dai'), + MCD_POT: require('./abis/Pot') }; diff --git a/packages/dai-plugin-migrations/contracts/abis/CageFree.json b/packages/dai-plugin-migrations/contracts/abis/CageFree.json new file mode 100644 index 000000000..f291b462a --- /dev/null +++ b/packages/dai-plugin-migrations/contracts/abis/CageFree.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"address","name":"_tap","type":"address"},{"internalType":"address","name":"_weth","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FreeCash","type":"event"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"constant":false,"inputs":[{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"freeCash","outputs":[{"internalType":"uint256","name":"cashoutBalance","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"sai","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tap","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/packages/dai-plugin-migrations/contracts/abis/DSValue.json b/packages/dai-plugin-migrations/contracts/abis/DSValue.json new file mode 100644 index 000000000..bb6b88387 --- /dev/null +++ b/packages/dai-plugin-migrations/contracts/abis/DSValue.json @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wut","type":"bytes32"}],"name":"poke","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"read","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"peek","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"void","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] \ No newline at end of file diff --git a/packages/dai-plugin-migrations/contracts/abis/DaiJoin.json b/packages/dai-plugin-migrations/contracts/abis/DaiJoin.json new file mode 100644 index 000000000..85a7d6e79 --- /dev/null +++ b/packages/dai-plugin-migrations/contracts/abis/DaiJoin.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"address","name":"vat_","type":"address"},{"internalType":"address","name":"dai_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":true,"inputs":[{"indexed":true,"internalType":"bytes4","name":"sig","type":"bytes4"},{"indexed":true,"internalType":"address","name":"usr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"arg1","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"arg2","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":false,"inputs":[],"name":"cage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"internalType":"contract DSTokenLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"exit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"join","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"live","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"vat","outputs":[{"internalType":"contract VatLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/packages/dai-plugin-migrations/contracts/abis/DssProxyActionsEnd.json b/packages/dai-plugin-migrations/contracts/abis/DssProxyActionsEnd.json new file mode 100644 index 000000000..5a52aee00 --- /dev/null +++ b/packages/dai-plugin-migrations/contracts/abis/DssProxyActionsEnd.json @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"internalType":"address","name":"ethJoin","type":"address"},{"internalType":"address","name":"end","type":"address"},{"internalType":"bytes32","name":"ilk","type":"bytes32"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"cashETH","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"gemJoin","type":"address"},{"internalType":"address","name":"end","type":"address"},{"internalType":"bytes32","name":"ilk","type":"bytes32"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"cashGem","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"apt","type":"address"},{"internalType":"address","name":"urn","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"daiJoin_join","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"manager","type":"address"},{"internalType":"address","name":"ethJoin","type":"address"},{"internalType":"address","name":"end","type":"address"},{"internalType":"uint256","name":"cdp","type":"uint256"}],"name":"freeETH","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"manager","type":"address"},{"internalType":"address","name":"gemJoin","type":"address"},{"internalType":"address","name":"end","type":"address"},{"internalType":"uint256","name":"cdp","type":"uint256"}],"name":"freeGem","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"daiJoin","type":"address"},{"internalType":"address","name":"end","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"pack","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/packages/dai-plugin-migrations/contracts/abis/ESM.json b/packages/dai-plugin-migrations/contracts/abis/ESM.json new file mode 100644 index 000000000..fad9de4b5 --- /dev/null +++ b/packages/dai-plugin-migrations/contracts/abis/ESM.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"address","name":"gem_","type":"address"},{"internalType":"address","name":"end_","type":"address"},{"internalType":"address","name":"pit_","type":"address"},{"internalType":"uint256","name":"min_","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":true,"inputs":[{"indexed":true,"internalType":"bytes4","name":"sig","type":"bytes4"},{"indexed":true,"internalType":"address","name":"usr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"arg1","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"arg2","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":true,"inputs":[],"name":"Sum","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"end","outputs":[{"internalType":"contract EndLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"fire","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"fired","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"internalType":"contract GemLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"join","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"min","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pit","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"sum","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/packages/dai-plugin-migrations/contracts/abis/GemJoin.json b/packages/dai-plugin-migrations/contracts/abis/GemJoin.json new file mode 100644 index 000000000..9967dcbaf --- /dev/null +++ b/packages/dai-plugin-migrations/contracts/abis/GemJoin.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"address","name":"vat_","type":"address"},{"internalType":"bytes32","name":"ilk_","type":"bytes32"},{"internalType":"address","name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":true,"inputs":[{"indexed":true,"internalType":"bytes4","name":"sig","type":"bytes4"},{"indexed":true,"internalType":"address","name":"usr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"arg1","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"arg2","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":false,"inputs":[],"name":"cage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"dec","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"exit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"internalType":"contract GemLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ilk","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"join","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"live","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"vat","outputs":[{"internalType":"contract VatLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/packages/dai-plugin-migrations/contracts/addresses/kovan.json b/packages/dai-plugin-migrations/contracts/addresses/kovan.json index 8629a31f7..f16883707 100644 --- a/packages/dai-plugin-migrations/contracts/addresses/kovan.json +++ b/packages/dai-plugin-migrations/contracts/addresses/kovan.json @@ -1,15 +1,21 @@ { "TUB": "0xa71937147b55Deb8a530C7229C442Fd3F31b7db2", - "GET_CDPS_1": "0x592301a23d37c591C5856f28726AF820AF8e7014", - "CDP_MANAGER_1": "0x1476483dD8C35F25e568113C5f70249D3976ba21", - "MCD_END_1": "0x24728AcF2E2C403F5d2db4Df6834B8998e56aA5F", - "MCD_VAT_1": "0xbA987bDB501d131f766fEe8180Da5d81b34b69d9", - "MCD_DAI_1": "0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa", - "MCD_POT_1": "0xEA190DBDC7adF265260ec4dA6e9675Fd4f5A78bb", + "GET_CDPS_1": "0x592301a23d37c591c5856f28726af820af8e7014", + "CDP_MANAGER_1": "0x1476483dd8c35f25e568113c5f70249d3976ba21", + "MCD_END_1": "0x24728acf2e2c403f5d2db4df6834b8998e56aa5f", + "MCD_VAT_1": "0xba987bdb501d131f766fee8180da5d81b34b69d9", + "MCD_DAI_1": "0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa", + "MCD_POT_1": "0xea190dbdc7adf265260ec4da6e9675fd4f5a78bb", "REDEEMER": "0x2c0f31271673cc29927be725104642aad65a253e", "OLD_MKR": "0x4bb514a7f83fbb13c2b41448208e89fabbcfe2fb", - "MIGRATION": "0x411B2Faa662C8e3E5cF8f01dFdae0aeE482ca7b0", - "MIGRATION_PROXY_ACTIONS": "0xF56765d255463139d3aff1613705a5520764Ab93", + "MIGRATION": "0x411b2faa662c8e3e5cf8f01dfdae0aee482ca7b0", + "MIGRATION_PROXY_ACTIONS": "0xf56765d255463139d3aff1613705a5520764ab93", "OLD_CHIEF": "0xbbffc76e94b34f72d96d054b31f6424249c1337d", - "OLD_VOTE_PROXY_FACTORY": null + "OLD_VOTE_PROXY_FACTORY": "0x3E08741A68c2d964d172793cD0Ad14292F658cd8", + "PROXY_ACTIONS_END": "0x7c3f28f174F2b0539C202a5307Ff48efa61De982", + "MCD_JOIN_ETH_A": "0x775787933e92b709f2a3c70aa87999696e74a9f8", + "MCD_JOIN_DAI": "0x5aa71a3ae1c0bd6ac27a1f28e1415fffb6f15b8c", + "MCD_JOIN_BAT_A": "0x2a4C485B1B8dFb46acCfbeCaF75b6188A59dBd0a", + "MCD_JOIN_USDC_A": "0x4c514656E7dB7B859E994322D2b511d99105C1Eb", + "SAI_CAGEFREE": "0xF3095A1822cA8fb3D0955595fA3888b68C4B8124" } diff --git a/packages/dai-plugin-migrations/contracts/addresses/mainnet.json b/packages/dai-plugin-migrations/contracts/addresses/mainnet.json index 266aba8ca..2a69e675d 100644 --- a/packages/dai-plugin-migrations/contracts/addresses/mainnet.json +++ b/packages/dai-plugin-migrations/contracts/addresses/mainnet.json @@ -9,5 +9,11 @@ "MCD_DAI_1": "0x6b175474e89094c44da98b954eedeac495271d0f", "MCD_POT_1": "0x197e90f9fad81970ba7976f33cbd77088e5d7cf7", "OLD_CHIEF": "0x8e2a84d6ade1e7fffee039a35ef5f19f13057152", - "OLD_VOTE_PROXY_FACTORY": "0xa63E145309cadaa6A903a19993868Ef7E85058BE" + "OLD_VOTE_PROXY_FACTORY": "0xa63E145309cadaa6A903a19993868Ef7E85058BE", + "PROXY_ACTIONS_END": "0x7AfF9FC9faD225e3c88cDA06BC56d8Aca774bC57", + "MCD_JOIN_ETH_A": "0x2f0b23f53734252bda2277357e97e1517d6b042a", + "MCD_JOIN_DAI": "0x9759a6ac90977b93b58547b4a71c78317f391a28", + "MCD_JOIN_BAT_A": "0x3D0B1912B66114d4096F48A8CEe3A56C231772cA", + "MCD_JOIN_USDC_A": "0xA191e578a6736167326d05c119CE0c90849E84B7", + "SAI_CAGEFREE": "0x9fdc15106da755f9FfD5b0BA9854Cfb89602E0fd" } diff --git a/packages/dai-plugin-migrations/contracts/addresses/testnet.json b/packages/dai-plugin-migrations/contracts/addresses/testnet.json index 3dc10a265..f78df368e 100644 --- a/packages/dai-plugin-migrations/contracts/addresses/testnet.json +++ b/packages/dai-plugin-migrations/contracts/addresses/testnet.json @@ -1,5 +1,6 @@ { "TUB": "0xE82CE3D6Bf40F2F9414C8d01A35E3d9eb16a1761", + "TAP": "0x6896659267c3c9fd055d764327199a98e571e00d", "GET_CDPS_1": "0x883c76966eA1D1AFEC54a1c20f84A57a287BB021", "CDP_MANAGER_1": "0xb3dc8De316349D8cE5168FE33C2E75c4f0cd0FFE", "MCD_END_1": "0xb002A319887185e56d787A5c90900e13834a85E3", @@ -11,5 +12,12 @@ "OLD_CHIEF": "0x1d24598fa8B77811E68243A2746CC553E68ca03B", "OLD_VOTE_PROXY_FACTORY": "0xa9D33Ce18803b0742460ffb1b33B6c40f95178BC", "MIGRATION": "0x2978B18F7c68B2957e701FC6D82C8De5B55833f2", - "MIGRATION_PROXY_ACTIONS": "0x19BDC4b950285a608E50F3b5E7DF154FacBda861" + "MIGRATION_PROXY_ACTIONS": "0x19BDC4b950285a608E50F3b5E7DF154FacBda861", + "PROXY_ACTIONS_END": "0x5E6085775Cd0B41fC70d1A6B48a0451bf7aCa801", + "MCD_JOIN_ETH_A": "0xF7Cbc73FE7d30c68AD7b64D293D4F52F76027261", + "MCD_JOIN_DAI": "0x55320248dC50Ef6dABc88ECbc294Fd5e2e1f4eC6", + "MCD_JOIN_BAT_A": "0xEB9d9336b4A89260bC4B94ee6a34e2faF46B0CA5", + "MCD_JOIN_USDC_A": "0x77d6250c22eCBA016a4F6D1a917BF5b2ED0704C5", + "SAI_CAGEFREE": "0xb0ae8c0856259C6fe000F8e2C14507E5FC167D48", + "MCD_ESM": "0x2125C30dA5DcA0819aEC5e4cdbF58Bfe91918e43" } diff --git a/packages/dai-plugin-migrations/package.json b/packages/dai-plugin-migrations/package.json index 8c78e4abd..78b6db151 100644 --- a/packages/dai-plugin-migrations/package.json +++ b/packages/dai-plugin-migrations/package.json @@ -1,7 +1,7 @@ { "name": "@makerdao/dai-plugin-migrations", "description": "Plugin to add migrations to dai.js", - "version": "1.1.0", + "version": "1.3.0", "license": "MIT", "main": "dist/index.js", "browser": "umd/index.js", diff --git a/packages/dai-plugin-migrations/scripts/install-testchain-outputs.sh b/packages/dai-plugin-migrations/scripts/install-testchain-outputs.sh index 4936ff5df..7d3e9c08f 100755 --- a/packages/dai-plugin-migrations/scripts/install-testchain-outputs.sh +++ b/packages/dai-plugin-migrations/scripts/install-testchain-outputs.sh @@ -8,7 +8,7 @@ CONTRACTS=$CWD/../contracts SOURCE=${1:-$CWD/../../../node_modules/@makerdao/testchain} # Relevant contracts from SCD: -for CONTRACT in "TUB","SaiTub" "REDEEMER","Redeemer" "OLD_MKR","DSToken" "OLD_CHIEF","DSChief" +for CONTRACT in "TUB","SaiTub" "REDEEMER","Redeemer" "OLD_MKR","DSToken" "OLD_CHIEF","DSChief" "SAI_CAGEFREE","CageFree" "OLD_VOTE_PROXY_FACTORY","VoteProxyFactory" do IFS=',' read NAME ABI <<< "${CONTRACT}" ADDRESS=`jq ".$NAME" "$SOURCE/out/addresses.json"` @@ -17,6 +17,15 @@ do done # Relevant contracts from MCD: +for CONTRACT in "MCD_JOIN_ETH_A","GemJoin" "MCD_JOIN_DAI","DaiJoin" "MCD_JOIN_BAT_A","GemJoin" "MIGRATION","ScdMcdMigration" "MIGRATION_PROXY_ACTIONS","MigrationProxyActions" "PROXY_ACTIONS_END","DssProxyActionsEnd" "MCD_JOIN_USDC_A","GemJoin" "MCD_ESM","ESM" +do + IFS=',' read NAME ABI <<< "${CONTRACT}" + ADDRESS=`jq ".$NAME" "$SOURCE/out/addresses-mcd.json"` + jq ".$NAME=$ADDRESS" $CONTRACTS/addresses/testnet.json > testnet.tmp && mv testnet.tmp $CONTRACTS/addresses/testnet.json + cp $SOURCE/out/mcd/$ABI.abi $CONTRACTS/abis/$ABI.json +done + +# Contracts (from MCD) with numbered versions: for CONTRACT in "MCD_END","END" "MCD_VAT","VAT" "GET_CDPS","GetCdps" "CDP_MANAGER","DssCdpManager" "MCD_DAI","Dai" "MCD_POT","Pot" do IFS=',' read NAME ABI <<< "${CONTRACT}" diff --git a/packages/dai-plugin-migrations/src/MigrationService.js b/packages/dai-plugin-migrations/src/MigrationService.js index d788feb36..13fdbca7b 100644 --- a/packages/dai-plugin-migrations/src/MigrationService.js +++ b/packages/dai-plugin-migrations/src/MigrationService.js @@ -8,6 +8,9 @@ import SaiToDai from './migrations/SaiToDai'; import MkrRedeemer from './migrations/MkrRedeemer'; import DaiToSai from './migrations/DaiToSai'; import ChiefMigrate from './migrations/ChiefMigrate'; +import RedeemSai from './migrations/RedeemSai'; +import RedeemCollateral from './migrations/RedeemCollateral'; + const { SINGLE_TO_MULTI_CDP, SAI_TO_DAI, @@ -24,7 +27,9 @@ const migrations = { [Migrations.GLOBAL_SETTLEMENT_SAVINGS_DAI]: GlobalSettlementSavingsDai, [Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS]: GlobalSettlementCollateralClaims, [Migrations.GLOBAL_SETTLEMENT_DAI_REDEEMER]: GlobalSettlementDaiRedeemer, - [Migrations.MKR_REDEEMER]: MkrRedeemer + [Migrations.MKR_REDEEMER]: MkrRedeemer, + [Migrations.REDEEM_SAI]: RedeemSai, + [Migrations.REDEEM_COLLATERAL]: RedeemCollateral }; export default class MigrationService extends PublicService { @@ -58,7 +63,10 @@ export default class MigrationService extends PublicService { [SAI_TO_DAI]: await this.getMigration(SAI_TO_DAI).check(), [DAI_TO_SAI]: await this.getMigration(DAI_TO_SAI).check(), [CHIEF_MIGRATE]: await this.getMigration(CHIEF_MIGRATE).check(), - [MKR_REDEEMER]: await this.getMigration(MKR_REDEEMER).check() + [MKR_REDEEMER]: await this.getMigration(MKR_REDEEMER).check(), + [Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS]: await this.getMigration( + Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS + ).check() }; } diff --git a/packages/dai-plugin-migrations/src/constants.js b/packages/dai-plugin-migrations/src/constants.js index 8b7520716..9dfbd6efe 100644 --- a/packages/dai-plugin-migrations/src/constants.js +++ b/packages/dai-plugin-migrations/src/constants.js @@ -12,7 +12,9 @@ export const Migrations = { GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS: 'global-settlement-collateral-claims', GLOBAL_SETTLEMENT_DAI_REDEEMER: 'global-settlement-dai-redeemer', MKR_REDEEMER: 'mkr-redeemer', - CHIEF_MIGRATE: 'chief-migrate' + CHIEF_MIGRATE: 'chief-migrate', + REDEEM_SAI: 'redeem-sai', + REDEEM_COLLATERAL: 'redeem-collateral' }; export const WAD = new BigNumber('1e18'); diff --git a/packages/dai-plugin-migrations/src/index.js b/packages/dai-plugin-migrations/src/index.js index 1688b0474..72bd46094 100644 --- a/packages/dai-plugin-migrations/src/index.js +++ b/packages/dai-plugin-migrations/src/index.js @@ -31,7 +31,7 @@ const allContracts = Object.entries(testnetAddresses).reduce( export const OLD_MKR = createCurrency('OLD_MKR'); export const SAI = createCurrency('SAI'); -export const DAI = createCurrency('MDAI'); +export const DAI = createCurrency('DAI'); export const MKR = createCurrency('MKR'); function overrideContractAddresses(addressOverrides, contracts) { @@ -44,7 +44,7 @@ function overrideContractAddresses(addressOverrides, contracts) { return contracts; } -export const MDAI_1 = createCurrency('MDAI_1'); +export const DAI_1 = createCurrency('DAI_1'); export default { addConfig: (_, { addressOverrides } = {}) => { @@ -61,7 +61,7 @@ export default { decimals: 18, address: addContracts.OLD_MKR.address }, - { currency: MDAI_1, address: addContracts.MCD_DAI_1.address } + { currency: DAI_1, address: addContracts.MCD_DAI_1.address } ] }, additionalServices: [MIGRATION], diff --git a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementCollateralClaims.js b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementCollateralClaims.js index 64ea021ff..05f0cf93c 100644 --- a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementCollateralClaims.js +++ b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementCollateralClaims.js @@ -9,28 +9,27 @@ export default class GlobalSettlementCollateralClaims { async check() { const end = this._container.get('smartContract').getContract('MCD_END_1'); - const isInGlobalSettlement = !(await end.live()); - if (!isInGlobalSettlement) return false; - - const address = - (await this._container.get('proxy').currentProxy()) || - this._container.get('accounts').currentAddress(); - + const live = await end.live(); + const emergencyShutdownActive = live.eq(0); + if (!emergencyShutdownActive) return false; + const address = await this._container.get('proxy').currentProxy(); + if (!address) return false; const cdpManager = this._container .get('smartContract') .getContract('CDP_MANAGER_1'); const vat = this._container.get('smartContract').getContract('MCD_VAT_1'); - const [ids, , ilks] = await this._container + const cdps = await this._container .get('smartContract') .getContract('GET_CDPS_1') .getCdpsDesc(cdpManager.address, address); + const { ids, ilks } = cdps; const freeCollateral = await Promise.all( ids.map(async (id, i) => { const urn = await cdpManager.urns(id); const vatUrn = await vat.urns(ilks[i], urn); - const tag = await end.tags(ilks[i]); + const tag = await end.tag(ilks[i]); const ilk = await vat.ilks(ilks[i]); const owed = new BigNumber(vatUrn.art) @@ -38,11 +37,67 @@ export default class GlobalSettlementCollateralClaims { .div(RAY) .times(tag) .div(RAY); - - return tag.gt(0) && new BigNumber(vatUrn.ink).minus(owed).gt(0); + const redeemable = + tag.gt(0) && new BigNumber(vatUrn.ink).minus(owed).gt(0); + const tagDivRay = new BigNumber(tag).div(RAY); + return { id, owed, redeemable, ilk, urn, tag: tagDivRay }; }) ); + if (!freeCollateral.some(v => v.redeemable)) return false; + return freeCollateral; + } + + freeEth(cdpId) { + const cdpManagerAddress = this._container + .get('smartContract') + .getContractAddress('CDP_MANAGER_1'); + const endAddress = this._container + .get('smartContract') + .getContractAddress('MCD_END_1'); + const ethJoinAddress = this._container + .get('smartContract') + .getContractAddress('MCD_JOIN_ETH_A'); + return this._container + .get('smartContract') + .getContract('PROXY_ACTIONS_END') + .freeETH(cdpManagerAddress, ethJoinAddress, endAddress, cdpId, { + dsProxy: true + }); + } - return freeCollateral.some(exists => exists); + freeBat(cdpId) { + const cdpManagerAddress = this._container + .get('smartContract') + .getContractAddress('CDP_MANAGER_1'); + const endAddress = this._container + .get('smartContract') + .getContractAddress('MCD_END_1'); + const gemJoinAddress = this._container + .get('smartContract') + .getContractAddress('MCD_JOIN_BAT_A'); + return this._container + .get('smartContract') + .getContract('PROXY_ACTIONS_END') + .freeGem(cdpManagerAddress, gemJoinAddress, endAddress, cdpId, { + dsProxy: true + }); + } + + freeUsdc(cdpId) { + const cdpManagerAddress = this._container + .get('smartContract') + .getContractAddress('CDP_MANAGER_1'); + const endAddress = this._container + .get('smartContract') + .getContractAddress('MCD_END_1'); + const gemJoinAddress = this._container + .get('smartContract') + .getContractAddress('MCD_JOIN_USDC_A'); + return this._container + .get('smartContract') + .getContract('PROXY_ACTIONS_END') + .freeGem(cdpManagerAddress, gemJoinAddress, endAddress, cdpId, { + dsProxy: true + }); } } diff --git a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementDaiRedeemer.js b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementDaiRedeemer.js index 633118862..161af92b8 100644 --- a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementDaiRedeemer.js +++ b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementDaiRedeemer.js @@ -1,4 +1,7 @@ -import { MDAI_1 } from '../index'; +import { DAI_1 } from '../index'; +import { stringToBytes } from '../utils'; +import BigNumber from 'bignumber.js'; +import { WAD } from '../constants'; export default class GlobalSettlementDaiRedeemer { constructor(container) { @@ -18,12 +21,13 @@ export default class GlobalSettlementDaiRedeemer { const daiBalance = await this._container .get('token') - .getToken(MDAI_1) + .getToken(DAI_1) .balance(); if (daiBalance.lte(0)) return false; const cdpManagerAddress = smartContract.getContractAddress('CDP_MANAGER_1'); + //TODO; don't just look at ilks related to the address's Vaults const [, , ilks] = await smartContract .getContract('GET_CDPS_1') .getCdpsDesc(cdpManagerAddress, address); @@ -37,4 +41,84 @@ export default class GlobalSettlementDaiRedeemer { return fixes.some(fix => fix.gt(0)); } + + async endGemBalance(ilk) { + const vat = this._container.get('smartContract').getContract('MCD_VAT_1'); + const endAddress = this._container + .get('smartContract') + .getContractAddress('MCD_END_1'); + const gemBalance = await vat.gem(stringToBytes(ilk), endAddress); + return BigNumber(gemBalance).div(WAD); + } + + async bagAmount(address) { + const end = this._container.get('smartContract').getContract('MCD_END_1'); + const bag = await end.bag(address); + return DAI_1.wei(bag); + } + + async packDai(daiAmount) { + const formattedAmount = DAI_1(daiAmount).toFixed('wei'); + const endAddress = this._container + .get('smartContract') + .getContractAddress('MCD_END_1'); + const daiJoinAddress = this._container + .get('smartContract') + .getContractAddress('MCD_JOIN_DAI'); + return this._container + .get('smartContract') + .getContract('PROXY_ACTIONS_END') + .pack(daiJoinAddress, endAddress, formattedAmount, { dsProxy: true }); + } + + async cashEth(daiAmount) { + const formattedAmount = DAI_1(daiAmount).toFixed('wei'); + const joinAddress = this._container + .get('smartContract') + .getContractAddress('MCD_JOIN_ETH_A'); + const endAddress = this._container + .get('smartContract') + .getContractAddress('MCD_END_1'); + const ilkBytes = stringToBytes('ETH-A'); + return this._container + .get('smartContract') + .getContract('PROXY_ACTIONS_END') + .cashETH(joinAddress, endAddress, ilkBytes, formattedAmount, { + dsProxy: true + }); + } + + async cashBat(daiAmount) { + const formattedAmount = DAI_1(daiAmount).toFixed('wei'); + const joinAddress = this._container + .get('smartContract') + .getContractAddress('MCD_JOIN_BAT_A'); + const endAddress = this._container + .get('smartContract') + .getContractAddress('MCD_END_1'); + const ilkBytes = stringToBytes('BAT-A'); + return this._container + .get('smartContract') + .getContract('PROXY_ACTIONS_END') + .cashGem(joinAddress, endAddress, ilkBytes, formattedAmount, { + dsProxy: true + }); + } + + async cashUsdc(daiAmount) { + const formattedAmount = DAI_1(daiAmount).toFixed('wei'); + const joinAddress = this._container + .get('smartContract') + .getContractAddress('MCD_JOIN_USDC_A'); + const endAddress = this._container + .get('smartContract') + .getContractAddress('MCD_END_1'); + const ilkBytes = stringToBytes('USDC-A'); + return this._container + .get('smartContract') + .getContract('PROXY_ACTIONS_END') + .cashGem(joinAddress, endAddress, ilkBytes, formattedAmount, { + dsProxy: true + }); + } } diff --git a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementSavingsDai.js b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementSavingsDai.js index 663a46186..1412fea9b 100644 --- a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementSavingsDai.js +++ b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementSavingsDai.js @@ -7,7 +7,7 @@ export default class GlobalSettlementSavingsDai { async check() { const smartContract = this._container.get('smartContract'); const end = smartContract.getContract('MCD_END_1'); - const isInGlobalSettlement = !(await end.live()); + const isInGlobalSettlement = (await end.live()).eq(0); if (!isInGlobalSettlement) return false; const address = diff --git a/packages/dai-plugin-migrations/src/migrations/RedeemCollateral.js b/packages/dai-plugin-migrations/src/migrations/RedeemCollateral.js new file mode 100644 index 000000000..ebfdec127 --- /dev/null +++ b/packages/dai-plugin-migrations/src/migrations/RedeemCollateral.js @@ -0,0 +1,25 @@ +export default class RedeemCollateral { + constructor(manager) { + this._manager = manager; + return this; + } + + _contract(name) { + return this._manager.get('smartContract').getContract(name); + } + + cooldown() { + return this._contract('SAI_TOP').cooldown(); + } + + async pethInTap() { + const fog = await this._contract('SAI_TAP').fog(); + return fog / Math.pow(10, 18); + } + + redeemCollateral(cdp, wad) { + // This will be replaced with the new contract method + // that atomically exits/unwraps + return cdp.freePeth(wad); + } +} diff --git a/packages/dai-plugin-migrations/src/migrations/RedeemSai.js b/packages/dai-plugin-migrations/src/migrations/RedeemSai.js new file mode 100644 index 000000000..3f105d538 --- /dev/null +++ b/packages/dai-plugin-migrations/src/migrations/RedeemSai.js @@ -0,0 +1,25 @@ +import { DAI } from '..'; + +export default class RedeemSai { + constructor(manager) { + this._manager = manager; + this._tap = this._manager.get('smartContract').getContract('SAI_TAP'); + return this; + } + + off() { + return this._tap.off(); + } + + async getRate() { + const fix = await this._tap.fix(); + return fix / Math.pow(10, 27); + } + + redeemSai(wad) { + const cageFree = this._manager + .get('smartContract') + .getContract('SAI_CAGEFREE'); + return cageFree.freeCash(DAI(wad).toFixed(18)); + } +} diff --git a/packages/dai-plugin-migrations/src/migrations/SingleToMultiCdp.js b/packages/dai-plugin-migrations/src/migrations/SingleToMultiCdp.js index f3a9e510e..2fad162f7 100644 --- a/packages/dai-plugin-migrations/src/migrations/SingleToMultiCdp.js +++ b/packages/dai-plugin-migrations/src/migrations/SingleToMultiCdp.js @@ -1,6 +1,7 @@ import { tracksTransactionsWithOptions } from '../utils'; import { getIdBytes, stringToBytes } from '../utils'; import { SAI, MKR } from '..'; +import dsValue from '../../contracts/abis/DSValue.json'; export default class SingleToMultiCdp { constructor(manager) { @@ -10,6 +11,36 @@ export default class SingleToMultiCdp { async check() { const address = this._manager.get('accounts').currentAddress(); + + if (global.scdESTest) { + if (global.testnet) { + console.log('fudging cdp id data for testnet'); + const proxyAddress = await this._manager.get('proxy').currentProxy(); + return { + [address]: [1], + [proxyAddress]: [2, 3, 4, 5, 6] + }; + } + + console.log('looking up cdp ids from logs; excludes proxy cdps'); + const scs = this._manager.get('smartContract'); + const ws = this._manager.get('web3'); + const { utils } = ws._web3; + const { LogNewCup } = scs.getContract('SAI_TUB').interface.events; + + const logs = await ws.getPastLogs({ + address: scs.getContractAddress('SAI_TUB'), + topics: [ + utils.keccak256(utils.toHex(LogNewCup.signature)), + '0x000000000000000000000000' + address.replace(/^0x/, '') + ], + fromBlock: 4750000 // Dec 17, 2017 on mainnet; earlier on Kovan + }); + return logs.length > 0 + ? { [address]: logs.map(l => parseInt(l.data, 16)) } + : {}; + } + const proxyAddress = await this._manager.get('proxy').currentProxy(); const idsFromProxy = proxyAddress ? await this._manager.get('cdp').getCdpIds(proxyAddress) @@ -46,6 +77,17 @@ export default class SingleToMultiCdp { } async _requireAllowance(cupId, payment) { + const pepAddress = await this._manager + .get('smartContract') + .getContract('SAI_TUB') + .pep(); + const mkrOracleActive = ( + await this._manager + .get('smartContract') + .getContractByAddressAndAbi(pepAddress, dsValue) + .peek() + )[1]; + if (payment === 'MKR' && !mkrOracleActive) return; const address = this._manager.get('web3').currentAddress(); const proxyAddress = await this._manager.get('proxy').currentProxy(); const cdp = await this._manager.get('cdp').getCdp(cupId); diff --git a/packages/dai-plugin-migrations/test/MigrationService.spec.js b/packages/dai-plugin-migrations/test/MigrationService.spec.js index 21973758d..654540e6b 100644 --- a/packages/dai-plugin-migrations/test/MigrationService.spec.js +++ b/packages/dai-plugin-migrations/test/MigrationService.spec.js @@ -7,6 +7,8 @@ import GlobalSettlementSavingsDai from '../src/migrations/GlobalSettlementSaving import GlobalSettlementCollateralClaims from '../src/migrations/GlobalSettlementCollateralClaims'; import GlobalSettlementDaiRedeemer from '../src/migrations/GlobalSettlementDaiRedeemer'; import MkrRedeemer from '../src/migrations/MkrRedeemer'; +import RedeemSai from '../src/migrations/RedeemSai'; +import RedeemCollateral from '../src/migrations/RedeemCollateral'; let maker, service; @@ -41,10 +43,12 @@ test('can fetch a list of all migrations', () => { Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS, Migrations.GLOBAL_SETTLEMENT_DAI_REDEEMER, Migrations.MKR_REDEEMER, - Migrations.CHIEF_MIGRATE + Migrations.CHIEF_MIGRATE, + Migrations.REDEEM_SAI, + Migrations.REDEEM_COLLATERAL ]) ); - expect(ids.length).toEqual(8); + expect(ids.length).toEqual(10); }); test('getting each migration returns a valid migration', () => { @@ -64,6 +68,10 @@ test('getting each migration returns a valid migration', () => { expect(service.getMigration(Migrations.MKR_REDEEMER)).toBeInstanceOf( MkrRedeemer ); + expect(service.getMigration(Migrations.REDEEM_SAI)).toBeInstanceOf(RedeemSai); + expect(service.getMigration(Migrations.REDEEM_COLLATERAL)).toBeInstanceOf( + RedeemCollateral + ); }); test('getting a non-existent migration returns undefined', () => { @@ -78,7 +86,8 @@ test('runAllChecks', async () => { [Migrations.DAI_TO_SAI]: expect.anything(), [Migrations.SINGLE_TO_MULTI_CDP]: {}, [Migrations.CHIEF_MIGRATE]: expect.anything(), - [Migrations.MKR_REDEEMER]: expect.anything() + [Migrations.MKR_REDEEMER]: expect.anything(), + [Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS]: expect.anything() }); - // expect(result[Migrations.SAI_TO_DAI].eq(0)).toBeTruthy(); + expect(result[Migrations.SAI_TO_DAI].eq(0)).toBeTruthy(); }); diff --git a/packages/dai-plugin-migrations/test/helpers/index.js b/packages/dai-plugin-migrations/test/helpers/index.js index c9dbed70f..96d727ab8 100644 --- a/packages/dai-plugin-migrations/test/helpers/index.js +++ b/packages/dai-plugin-migrations/test/helpers/index.js @@ -133,11 +133,40 @@ export async function migrateSaiToDai(amount, maker) { await daiMigration.execute(amount); } -// // Get wad amount of SAI from user's wallet: -// saiJoin.gem().transferFrom(msg.sender, address(this), wad); -// // Join the SAI wad amount to the `vat`: -// saiJoin.join(address(this), wad); -// // Lock the SAI wad amount to the CDP and generate the same wad amount of DAI -// vat.frob(saiJoin.ilk(), address(this), address(this), address(this), toInt(wad), toInt(wad)); -// // Send DAI wad amount as a ERC20 token to the user's wallet -// daiJoin.exit(msg.sender, wad); +export async function shutDown(randomize) { + const maker = await migrationMaker(); + const top = maker.service('smartContract').getContract('SAI_TOP'); + const proxy = await maker.service('proxy').ensureProxy(); + const normalCdp = await openLockAndDrawScdCdp(maker, randomize); + + const bites = []; + for (let i = 0; i < (randomize ? 5 : 1); i++) { + console.log('creating', i); + const proxyCdp = await maker + .service('cdp') + .openProxyCdpLockEthAndDrawSai( + 2 + (randomize ? Math.random() : 0), + 103 + (randomize ? Math.random() * 20 : 0), + proxy + ); + + bites.push(() => proxyCdp.bite()); + } + + await top.cage(); + await normalCdp.bite(); + for (let i = 0; i < bites.length; i++) { + console.log('biting', i); + await bites[i](); + } + await top.setCooldown(0); + await new Promise(r => setTimeout(r, 1000)); + await top.flow(); +} + +async function openLockAndDrawScdCdp(maker, randomize) { + const cdp = await maker.service('cdp').openCdp(); + await cdp.lockEth(1 + (randomize ? Math.random() : 0)); + await cdp.drawSai(111 + (randomize ? Math.random() * 20 : 0)); + return cdp; +} diff --git a/packages/dai-plugin-migrations/test/helpers/mocks.js b/packages/dai-plugin-migrations/test/helpers/mocks.js index 219e8010e..5a91e8fb1 100644 --- a/packages/dai-plugin-migrations/test/helpers/mocks.js +++ b/packages/dai-plugin-migrations/test/helpers/mocks.js @@ -19,18 +19,18 @@ export async function mockCdpIds(maker, { forAccount, forProxy } = {}) { export const globalSettlement = { beforeCage: () => ({ - live: async () => true, - tags: async () => new BigNumber(0), + live: async () => new BigNumber(1), + tag: async () => new BigNumber(0), fix: async () => new BigNumber(0) }), afterCage: () => ({ - live: async () => false, - tags: async () => new BigNumber(0), + live: async () => new BigNumber(0), + tag: async () => new BigNumber(0), fix: async () => new BigNumber(0) }), afterCageCollateral: tags => ({ - live: async () => false, - tags: async ilk => { + live: async () => new BigNumber(0), + tag: async ilk => { const ilkAsString = bytesToString(ilk); return tags[ilkAsString] ? RAY.times(new BigNumber(1).div(tags[ilkAsString])) @@ -39,7 +39,7 @@ export const globalSettlement = { fix: async () => new BigNumber(0) }), afterFlow: fixes => ({ - live: async () => false, + live: async () => new BigNumber(0), fix: async ilk => { const ilkAsString = bytesToString(ilk); return fixes[ilkAsString] diff --git a/packages/dai-plugin-migrations/test/kovan/kovan.test.js b/packages/dai-plugin-migrations/test/kovan/kovan.test.js index f44ebdc9d..6055bca8a 100644 --- a/packages/dai-plugin-migrations/test/kovan/kovan.test.js +++ b/packages/dai-plugin-migrations/test/kovan/kovan.test.js @@ -1,7 +1,6 @@ import Maker from '@makerdao/dai'; import McdPlugin from '@makerdao/dai-plugin-mcd'; import MigrationPlugin from '../../src'; -import { SAI, MKR } from '../../src'; import { ServiceRoles, Migrations } from '../../src/constants'; async function mcdMaker({ @@ -35,16 +34,14 @@ async function mcdMaker({ } async function openLockAndDrawScdCdp(drawAmount, maker) { - const cdp = await maker.openCdp({ dsProxy: true }); + const cdp = await maker.service('cdp').openCdp({ dsProxy: true }); await cdp.lockEth('0.1', { dsProxy: true }); - await cdp.drawDai(drawAmount, { dsProxy: true }); + await cdp.drawSai(drawAmount, { dsProxy: true }); return cdp; } xtest('kovan', async () => { const maker = await mcdMaker(); - const sai = maker.getToken(SAI); - const mkr = maker.getToken(MKR); const migrationContract = maker .service('smartContract') .getContract('MIGRATION'); @@ -59,7 +56,6 @@ xtest('kovan', async () => { // await mkr.approveUnlimited(proxyAddress); const cdp = await openLockAndDrawScdCdp('1', maker); - const info = await cdp.getInfo(); await cdp.give(proxyAddress); const id = cdp.id; await migrationContract.swapSaiToDai('5000000000000000000'); diff --git a/packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js b/packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js index 0fd210fa5..59ae543cd 100644 --- a/packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js +++ b/packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js @@ -31,7 +31,7 @@ describe('Chief Migration', () => { expect(mkrLockedViaProxy.toNumber()).toBe(0); }); - xtest('if the account has some MKR locked directly in old chief, return the amount', async () => { + test('if the account has some MKR locked directly in old chief, return the amount', async () => { const oldChief = maker .service('smartContract') .getContractByName('OLD_CHIEF'); @@ -45,11 +45,11 @@ describe('Chief Migration', () => { await oldChief.lock(LOCK_AMOUNT.toFixed('wei')); const { mkrLockedDirectly, mkrLockedViaProxy } = await migration.check(); - expect(mkrLockedViaProxy.toNumber()).toBe(0); expect(mkrLockedDirectly.isEqual(LOCK_AMOUNT)).toBeTruthy(); + expect(mkrLockedViaProxy.toNumber()).toBe(0); }); - xtest('if the account has some MKR locked via proxy in old chief, return the amount', async () => { + test('if the account has some MKR locked via proxy in old chief, return the amount', async () => { const oldVoteProxyFactory = maker .service('smartContract') .getContractByName('OLD_VOTE_PROXY_FACTORY'); @@ -85,7 +85,7 @@ describe('Chief Migration', () => { await voteProxy.lock(LOCK_AMOUNT.toFixed('wei')); const { mkrLockedDirectly, mkrLockedViaProxy } = await migration.check(); - expect(mkrLockedViaProxy.isEqual(LOCK_AMOUNT)).toBeTruthy(); expect(mkrLockedDirectly.toNumber()).toBe(0); + expect(mkrLockedViaProxy.isEqual(LOCK_AMOUNT)).toBeTruthy(); }); }); diff --git a/packages/dai-plugin-migrations/test/migrations/DaiToSai.spec.js b/packages/dai-plugin-migrations/test/migrations/DaiToSai.spec.js index 8d6d1fb70..f60e4db7a 100644 --- a/packages/dai-plugin-migrations/test/migrations/DaiToSai.spec.js +++ b/packages/dai-plugin-migrations/test/migrations/DaiToSai.spec.js @@ -20,7 +20,7 @@ describe('DAI to SAI Migration', () => { test('if the account has no DAI, return 0', async () => { const amount = await maker .service('token') - .getToken('MDAI') + .getToken('DAI') .balance(); expect(amount.toNumber()).toBe(0); @@ -32,7 +32,7 @@ describe('DAI to SAI Migration', () => { const amount = await maker .service('token') - .getToken('MDAI') + .getToken('DAI') .balance(); expect(amount.toNumber()).toBe(1); diff --git a/packages/dai-plugin-migrations/test/migrations/GlobalSettlementCollateralClaims.spec.js b/packages/dai-plugin-migrations/test/migrations/GlobalSettlementCollateralClaims.spec.js index c6d17dfac..540aca731 100644 --- a/packages/dai-plugin-migrations/test/migrations/GlobalSettlementCollateralClaims.spec.js +++ b/packages/dai-plugin-migrations/test/migrations/GlobalSettlementCollateralClaims.spec.js @@ -2,7 +2,7 @@ import { migrationMaker, setupCollateral } from '../helpers'; import { mockContracts, globalSettlement } from '../helpers/mocks'; import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; import { ServiceRoles, Migrations } from '../../src/constants'; -import { MDAI, ETH } from '@makerdao/dai-plugin-mcd'; +import { DAI, ETH } from '@makerdao/dai-plugin-mcd'; let maker, migration, smartContract, cdpManager, snapshot; @@ -10,7 +10,7 @@ describe('Global Settlement Collateral Claims migration', () => { beforeAll(async () => { maker = await migrationMaker(); - await maker.getToken(MDAI).approveUnlimited(await maker.currentProxy()); + await maker.getToken(DAI).approveUnlimited(await maker.currentProxy()); smartContract = maker.service('smartContract'); cdpManager = maker.service('mcd:cdpManager'); migration = maker @@ -29,61 +29,74 @@ describe('Global Settlement Collateral Claims migration', () => { test('if the system is NOT in global settlement and there is no collateral, return false', async () => { mockContracts(smartContract, { MCD_END_1: globalSettlement.beforeCage() }); - - expect(await migration.check()).toBeFalsy(); + const check = await migration.check(); + expect(check).toBe(false); }); test('if the system is NOT in global settlement and there is collateral, return false', async () => { mockContracts(smartContract, { MCD_END_1: globalSettlement.beforeCage() }); await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(1)); + await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(1)); expect(await migration.check()).toBeFalsy(); }); test('if the system IS in global settlement, but collateral is not caged, and there is no collateral, return false', async () => { mockContracts(smartContract, { MCD_END_1: globalSettlement.afterCage() }); - - expect(await migration.check()).toBeFalsy(); + const check = await migration.check(); + expect(check).toBe(false); }); test('if the system IS in global settlement, but collateral is not caged, and there is collateral, return false', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(1)); + await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(1)); mockContracts(smartContract, { MCD_END_1: globalSettlement.afterCage() }); - - expect(await migration.check()).toBeFalsy(); + const check = await migration.check(); + expect(check).toBe(false); }); test('if the system IS in global settlement and collateral is caged, and there is no collateral, return false', async () => { mockContracts(smartContract, { MCD_END_1: globalSettlement.afterCageCollateral({ 'ETH-A': 150 }) }); - - expect(await migration.check()).toBeFalsy(); + const check = await migration.check(); + expect(check).toBe(false); }); test('if the system IS in global settlement and collateral is caged, and there is NO collateral to skim, return false', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(9)); + await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(9)); mockContracts(smartContract, { MCD_END_1: globalSettlement.afterCageCollateral({ 'ETH-A': 80 }) }); - - expect(await migration.check()).toBeFalsy(); + const check = await migration.check(); + expect(check).toBe(false); }); test('if the system IS in global settlement and collateral is caged, and there IS collateral to skim, return true', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(1)); + await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(1)); mockContracts(smartContract, { MCD_END_1: globalSettlement.afterCageCollateral({ 'ETH-A': 150 }) }); + const num = (await migration.check()).filter(c => c.redeemable).length; + expect(num).toBe(1); + }); - expect(await migration.check()).toBeTruthy(); + xtest('freeEth', async () => { + await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); + const cdp = await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(1)); + mockContracts(smartContract, { + MCD_END_1: globalSettlement.afterCageCollateral({ 'ETH-A': 150 }) + }); + //somehow check eth balance to be returned + //check Eth balance + //call free eth + await migration.freeEth(cdp.id); + //confirm eth balance = prev eth balance - eth to be freed }); }); diff --git a/packages/dai-plugin-migrations/test/migrations/GlobalSettlementDaiRedeemer.spec.js b/packages/dai-plugin-migrations/test/migrations/GlobalSettlementDaiRedeemer.spec.js index 02b3e1f0c..db94170f3 100644 --- a/packages/dai-plugin-migrations/test/migrations/GlobalSettlementDaiRedeemer.spec.js +++ b/packages/dai-plugin-migrations/test/migrations/GlobalSettlementDaiRedeemer.spec.js @@ -1,9 +1,8 @@ import { migrationMaker, setupCollateral } from '../helpers'; import { mockContracts, globalSettlement } from '../helpers/mocks'; import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; -import TestAccountProvider from '@makerdao/test-helpers/src/TestAccountProvider'; import { ServiceRoles, Migrations } from '../../src/constants'; -import { MDAI, ETH } from '@makerdao/dai-plugin-mcd'; +import { DAI, ETH } from '@makerdao/dai-plugin-mcd'; let maker, migration, smartContract, cdpManager, snapshot; @@ -11,7 +10,7 @@ describe('Global Settlement Dai Redeemer migration', () => { beforeAll(async () => { maker = await migrationMaker(); - await maker.getToken(MDAI).approveUnlimited(await maker.currentProxy()); + await maker.getToken(DAI).approveUnlimited(await maker.currentProxy()); smartContract = maker.service('smartContract'); cdpManager = maker.service('mcd:cdpManager'); migration = maker @@ -42,7 +41,7 @@ describe('Global Settlement Dai Redeemer migration', () => { test('if the system is in global settlement, user owns some DAI, but collateral price has not been fixed, return false', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(9)); + await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(9)); mockContracts(smartContract, { MCD_END_1: globalSettlement.afterCage() }); @@ -59,9 +58,9 @@ describe('Global Settlement Dai Redeemer migration', () => { expect(await migration.check()).toBeFalsy(); }); - test('if the system IS in global settlement, collateral price has been fixed, the user owns DAI, and the user has locked collateral, return true', async () => { + xtest('if the system IS in global settlement, collateral price has been fixed, the user owns DAI, return true', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(9)); + await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(9)); mockContracts(smartContract, { MCD_END_1: globalSettlement.afterFlow({ @@ -71,26 +70,4 @@ describe('Global Settlement Dai Redeemer migration', () => { expect(await migration.check()).toBeTruthy(); }); - - test('if the system IS in global settlement, collateral price has been fixed, the user owns DAI, but the user does NOT have locked collateral, return false', async () => { - await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(9)); - - const account2 = TestAccountProvider.nextAccount(); - - const mdai = maker.service('token').getToken(MDAI); - await mdai.transfer(account2.address, 9); - - await maker.addAccount({ ...account2, type: 'privateKey' }); - maker.useAccount(account2.address); - expect((await mdai.balance()).toNumber()).toBe(9); - - mockContracts(smartContract, { - MCD_END_1: globalSettlement.afterFlow({ - 'ETH-A': 10 - }) - }); - - expect(await migration.check()).toBeFalsy(); - }); }); diff --git a/packages/dai-plugin-migrations/test/migrations/GlobalSettlementSavingsDai.spec.js b/packages/dai-plugin-migrations/test/migrations/GlobalSettlementSavingsDai.spec.js index 3b1b64a0c..b7993bb54 100644 --- a/packages/dai-plugin-migrations/test/migrations/GlobalSettlementSavingsDai.spec.js +++ b/packages/dai-plugin-migrations/test/migrations/GlobalSettlementSavingsDai.spec.js @@ -2,7 +2,7 @@ import { migrationMaker, setupCollateral } from '../helpers'; import { mockContracts, globalSettlement } from '../helpers/mocks'; import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; import { ServiceRoles, Migrations } from '../../src/constants'; -import { ETH, MDAI } from '@makerdao/dai-plugin-mcd'; +import { ETH, DAI } from '@makerdao/dai-plugin-mcd'; let maker, migration, cdpManager, smartContract, snapshot; @@ -25,7 +25,7 @@ describe('Global Settlement Savings DAI Migration', () => { cdpManager = maker.service('mcd:cdpManager'); smartContract = maker.service('smartContract'); - const dai = maker.getToken(MDAI); + const dai = maker.getToken(DAI); const proxyAddress = await maker.service('proxy').ensureProxy(); await dai.approveUnlimited(proxyAddress); @@ -49,8 +49,8 @@ describe('Global Settlement Savings DAI Migration', () => { test('if the system is in global settlement and there is DAI in savings DAI, return true', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(1)); - await joinSavings(MDAI(1)); + await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(1)); + await joinSavings(DAI(1)); mockContracts(smartContract, { MCD_END_1: globalSettlement.afterCage() }); @@ -65,9 +65,9 @@ describe('Global Settlement Savings DAI Migration', () => { test('if the system is NOT in global settlement and there is DAI in savings DAI, return false', async () => { await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); - await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), MDAI(1)); + await cdpManager.openLockAndDraw('ETH-A', ETH(0.1), DAI(1)); mockContracts(smartContract, { MCD_END_1: globalSettlement.beforeCage() }); - await joinSavings(MDAI(1)); + await joinSavings(DAI(1)); expect(await migration.check()).toBeFalsy(); }); diff --git a/packages/dai-plugin-migrations/test/migrations/RedeemCollateral.spec.js b/packages/dai-plugin-migrations/test/migrations/RedeemCollateral.spec.js new file mode 100644 index 000000000..c22758c9c --- /dev/null +++ b/packages/dai-plugin-migrations/test/migrations/RedeemCollateral.spec.js @@ -0,0 +1,41 @@ +import { migrationMaker, shutDown } from '../helpers'; +import { ServiceRoles, Migrations } from '../../src/constants'; +import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; + +let maker, migration, snapshotData; + +describe('Redeem collateral', () => { + beforeAll(async () => { + jest.setTimeout(30000); + + maker = await migrationMaker(); + snapshotData = await takeSnapshot(maker); + const service = maker.service(ServiceRoles.MIGRATION); + migration = service.getMigration(Migrations.REDEEM_COLLATERAL); + await shutDown(); + await migration._contract('SAI_TOP').setCooldown(0); + }); + + afterAll(async () => { + await restoreSnapshot(snapshotData, maker); + }); + + test('should get the remaining cooldown', async () => { + const cooldown = await migration.cooldown(); + expect(cooldown.toNumber()).toBe(0); + }); + + test('should get the total peth in tap', async () => { + expect(await migration.pethInTap()).toBe(0.535); + }); + + test('should redeem collateral', async () => { + const cdp = await maker.service('cdp').getCdp(1); + const peth = maker.getToken('PETH'); + const address = maker.service('web3').currentAddress(); + const collateral = await cdp.getCollateralValue(); + await migration.redeemCollateral(cdp, collateral); + const pethBalance = await peth.balanceOf(address); + expect(pethBalance.toNumber()).toBe(collateral.toNumber()); + }); +}); diff --git a/packages/dai-plugin-migrations/test/migrations/RedeemSai.spec.js b/packages/dai-plugin-migrations/test/migrations/RedeemSai.spec.js new file mode 100644 index 000000000..9fe24b63a --- /dev/null +++ b/packages/dai-plugin-migrations/test/migrations/RedeemSai.spec.js @@ -0,0 +1,57 @@ +import { migrationMaker, shutDown } from '../helpers'; +import { ServiceRoles, Migrations } from '../../src/constants'; +import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; +import { ETH } from '@makerdao/dai'; + +let maker, migration, snapshotData; + +describe('Redeem Sai', () => { + beforeAll(async () => { + jest.setTimeout(30000); + + maker = await migrationMaker(); + snapshotData = await takeSnapshot(maker); + const service = maker.service(ServiceRoles.MIGRATION); + migration = service.getMigration(Migrations.REDEEM_SAI); + await shutDown(); + }); + + afterAll(async () => { + await restoreSnapshot(snapshotData, maker); + }); + + test('should be off after shutdown', async () => { + const off = await migration.off(); + expect(off).toBe(true); + }); + + test('should get the exchange rate', async () => { + const rate = await migration.getRate(); + expect(rate).toBe(0.0025); + }); + + test('should redeem sai', async () => { + const sai = maker.getToken('SAI'); + const web3Service = maker.service('web3'); + const address = web3Service.currentAddress(); + const cageFree = maker.service('smartContract').getContract('SAI_CAGEFREE') + .address; + await sai.approveUnlimited(cageFree); + const saiBalanceBeforeRedemption = await sai.balanceOf(address); + const ethBalanceBeforeRedemption = ETH.wei( + await web3Service.getBalance(address) + ); + await migration.redeemSai(5); + const saiBalanceAfterRedemption = await sai.balanceOf(address); + const ethBalanceAfterRedemption = ETH.wei( + await web3Service.getBalance(address) + ); + + expect(saiBalanceAfterRedemption).toEqual( + saiBalanceBeforeRedemption.minus(5) + ); + expect(ethBalanceAfterRedemption.toNumber()).toBeGreaterThan( + ethBalanceBeforeRedemption.toNumber() + ); + }); +}); diff --git a/packages/dai-plugin-migrations/test/migrations/SaiToDai.spec.js b/packages/dai-plugin-migrations/test/migrations/SaiToDai.spec.js index f4f1cbd06..e744b8d06 100644 --- a/packages/dai-plugin-migrations/test/migrations/SaiToDai.spec.js +++ b/packages/dai-plugin-migrations/test/migrations/SaiToDai.spec.js @@ -46,7 +46,7 @@ describe('SAI to DAI Migration', () => { const saiBalanceBeforeMigration = await migration._sai.balanceOf(address); const daiBalanceBeforeMigration = await maker .service('token') - .getToken('MDAI') + .getToken('DAI') .balanceOf(address); await migration.execute(1); @@ -54,7 +54,7 @@ describe('SAI to DAI Migration', () => { const saiBalanceAfterMigration = await migration._sai.balanceOf(address); const daiBalanceAfterMigration = await maker .service('token') - .getToken('MDAI') + .getToken('DAI') .balanceOf(address); expect(saiBalanceBeforeMigration.toNumber()).toEqual( diff --git a/packages/dai-plugin-migrations/test/migrations/SingleToMultiCdp.spec.js b/packages/dai-plugin-migrations/test/migrations/SingleToMultiCdp.spec.js index 7ee66e6f1..a08fe5eab 100644 --- a/packages/dai-plugin-migrations/test/migrations/SingleToMultiCdp.spec.js +++ b/packages/dai-plugin-migrations/test/migrations/SingleToMultiCdp.spec.js @@ -12,7 +12,7 @@ import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; -import { USD, MDAI as DAI, ETH } from '@makerdao/dai-plugin-mcd'; +import { USD, DAI, ETH } from '@makerdao/dai-plugin-mcd'; import { SAI, MKR } from '../../src'; import { createCurrencyRatio } from '@makerdao/currency'; @@ -26,59 +26,60 @@ async function openLockAndDrawScdCdp(drawAmount) { await cdp.give(proxy); return cdp; } +beforeAll(async () => { + maker = await migrationMaker(); + migration = maker + .service(ServiceRoles.MIGRATION) + .getMigration(Migrations.SINGLE_TO_MULTI_CDP); +}); -describe('SCD to MCD CDP Migration', () => { - beforeEach(async () => { - maker = await migrationMaker(); - const service = maker.service(ServiceRoles.MIGRATION); - migration = service.getMigration(Migrations.SINGLE_TO_MULTI_CDP); +describe('checks', () => { + test('if there are no cdps, return false', async () => { + await mockCdpIds(maker); + + expect(await migration.check()).toMatchObject({}); }); - describe('checks', () => { - beforeEach(async () => { - snapshotData = await takeSnapshot(maker); + test('if there are cdps owned by a proxy, but no cdps owned by the account, return true', async () => { + await mockCdpIds(maker, { forProxy: [{ id: '123' }] }); + expect(await migration.check()).toMatchObject({ + [await maker.currentProxy()]: [{ id: '123' }], + [maker.currentAddress()]: [] }); + }); - afterEach(async () => { - await restoreSnapshot(snapshotData, maker); + test('if there are cdps owned by the account, but no cdps owned by a proxy, return true', async () => { + await mockCdpIds(maker, { forAccount: [{ id: '123' }] }); + expect(await migration.check()).toMatchObject({ + [await maker.currentProxy()]: [], + [maker.currentAddress()]: [{ id: '123' }] }); + }); - test('if there are no cdps, return false', async () => { - await mockCdpIds(maker); - - expect(await migration.check()).toMatchObject({}); + test('if there are both cdps owned by the account and proxy, return true', async () => { + await mockCdpIds(maker, { + forAccount: [{ id: '123' }], + forProxy: [{ id: '234' }] }); - - test('if there are cdps owned by a proxy, but no cdps owned by the account, return true', async () => { - await mockCdpIds(maker, { forProxy: [{ id: '123' }] }); - expect(await migration.check()).toMatchObject({ - [await maker.currentProxy()]: [{ id: '123' }], - [maker.currentAddress()]: [] - }); + expect(await migration.check()).toMatchObject({ + [await maker.currentProxy()]: [{ id: '234' }], + [maker.currentAddress()]: [{ id: '123' }] }); + }); - test('if there are cdps owned by the account, but no cdps owned by a proxy, return true', async () => { - await mockCdpIds(maker, { forAccount: [{ id: '123' }] }); - expect(await migration.check()).toMatchObject({ - [await maker.currentProxy()]: [], - [maker.currentAddress()]: [{ id: '123' }] - }); - }); + test('if there is no sai locked in the mcd migration cdp, return 0', async () => { + const saiLiquidity = await migration.migrationSaiAvailable(); + expect(saiLiquidity.toFixed('wei')).toBe('0'); + }); - test('if there are both cdps owned by the account and proxy, return true', async () => { - await mockCdpIds(maker, { - forAccount: [{ id: '123' }], - forProxy: [{ id: '234' }] - }); - expect(await migration.check()).toMatchObject({ - [await maker.currentProxy()]: [{ id: '234' }], - [maker.currentAddress()]: [{ id: '123' }] - }); + describe('with sai drawn', () => { + beforeEach(async () => { + jest.setTimeout(20000); + snapshotData = await takeSnapshot(maker); }); - test('if there is no sai locked in the mcd migration cdp, return 0', async () => { - const saiLiquidity = await migration.migrationSaiAvailable(); - expect(saiLiquidity.toFixed('wei')).toBe('0'); + afterEach(async () => { + await restoreSnapshot(snapshotData, maker); }); test('if there is sai locked in the mcd migration cdp, return the amount that is there', async () => { @@ -95,87 +96,92 @@ describe('SCD to MCD CDP Migration', () => { await maker .service('mcd:cdpManager') .openLockAndDraw('ETH-A', ETH(2), DAI(99998)); + const available = await migration.migrationSaiAvailable(); - // 999850480759163986 expect(available.toFixed('wei')).toBe('1999999999999999999'); }); - - test('saiAmountNeededToBuyMkr', async () => { - await placeLimitOrder(migration._manager); - const saiAmount = await migration.saiAmountNeededToBuyMkr(MKR(0.5)); - expect(saiAmount).toEqual(SAI(10)); - }); }); - describe.each(['DEBT', 'GEM'])('pay with %s', payment => { - let cdp, proxyAddress; + test('saiAmountNeededToBuyMkr', async () => { + await placeLimitOrder(migration._manager); + const saiAmount = await migration.saiAmountNeededToBuyMkr(MKR(0.5)); + expect(saiAmount).toEqual(SAI(10)); + }); +}); - beforeEach(async () => { - jest.setTimeout(20000); - snapshotData = await takeSnapshot(maker); - proxyAddress = await maker.service('proxy').currentProxy(); - await openLockAndDrawScdCdp(100); - cdp = await openLockAndDrawScdCdp(10); - await migrateSaiToDai(50, maker); - }); +describe.each(['MKR'])('pay with %s', payment => { + let cdp, proxyAddress; - afterEach(async () => { - await restoreSnapshot(snapshotData, maker); - }); + beforeEach(async () => { + jest.setTimeout(30000); + maker = await migrationMaker(); + migration = maker + .service(ServiceRoles.MIGRATION) + .getMigration(Migrations.SINGLE_TO_MULTI_CDP); + + snapshotData = await takeSnapshot(maker); + proxyAddress = await maker.service('proxy').currentProxy(); + await openLockAndDrawScdCdp(100); + cdp = await openLockAndDrawScdCdp(10); + await migrateSaiToDai(50, maker); + }); - test('execute', async () => { - let maxPayAmount, minRatio; + afterEach(async () => { + await restoreSnapshot(snapshotData, maker); + }); - if (payment !== 'MKR') { - await placeLimitOrder(migration._manager); - maxPayAmount = 10; - } - if (payment === 'DEBT') minRatio = 150; - await maker.service('price').setMkrPrice(100); + test('execute', async () => { + let maxPayAmount, minRatio; - const manager = maker.service('mcd:cdpManager'); - const scdCollateral = await cdp.getCollateralValue(); - const scdDebt = await cdp.getDebtValue(); - await mineBlocks(maker.service('web3'), 3); - await maker - .service('smartContract') - .getContract('MCD_POT') - .drip(); - - const mcdCdpsBeforeMigration = await manager.getCdpIds(proxyAddress); - - const newId = await migration.execute( - cdp.id, - payment, - maxPayAmount, - minRatio - ); - await manager.reset(); - - const mcdCdpsAfterMigration = await manager.getCdpIds(proxyAddress); - const mcdCdpId = mcdCdpsAfterMigration[0].id; - expect(newId).toEqual(mcdCdpId); - - maker.service('mcd:cdpType').reset(); - const mcdCdp = await manager.getCdp(mcdCdpId); - const mcdCollateral = mcdCdp.collateralAmount.toNumber(); - const mcdDebt = mcdCdp.debtValue.toNumber(); - - expect(mcdCollateral).toEqual(scdCollateral.toNumber()); - expect(mcdDebt).toBeCloseTo(scdDebt.toNumber(), 1); - - let message; - try { - await maker.service('cdp').getCdp(cdp.id); - } catch (err) { - message = err.message; - } - - expect(message).toEqual("That CDP doesn't exist--try opening a new one."); - - expect(mcdCdpsAfterMigration.length).toEqual( - mcdCdpsBeforeMigration.length + 1 - ); - }); + if (payment !== 'MKR') { + await placeLimitOrder(migration._manager); + maxPayAmount = 10; + } + if (payment === 'DEBT') minRatio = 150; + await maker.service('price').setMkrPrice(100); + + const manager = maker.service('mcd:cdpManager'); + const scdCollateral = await cdp.getCollateralValue(); + const scdDebt = await cdp.getDebtValue(); + await mineBlocks(maker.service('web3'), 3); + await maker + .service('smartContract') + .getContract('MCD_POT') + .drip(); + + const mcdCdpsBeforeMigration = await manager.getCdpIds(proxyAddress); + + const newId = await migration.execute( + cdp.id, + payment, + maxPayAmount, + minRatio + ); + await manager.reset(); + + const mcdCdpsAfterMigration = await manager.getCdpIds(proxyAddress); + const mcdCdpId = mcdCdpsAfterMigration[0].id; + expect(newId).toEqual(mcdCdpId); + + maker.service('mcd:cdpType').resetAllCdpTypes(); + const mcdCdp = await manager.getCdp(mcdCdpId); + const mcdCollateral = mcdCdp.collateralAmount.toNumber(); + const mcdDebt = mcdCdp.debtValue.toNumber(); + + expect(mcdCollateral).toEqual(scdCollateral.toNumber()); + expect(mcdDebt).toBeCloseTo(scdDebt.toNumber(), 1); + + let message; + try { + await maker.service('cdp').getCdp(cdp.id); + } catch (err) { + message = err.message; + } + + expect(message).toEqual("That CDP doesn't exist--try opening a new one."); + + expect(mcdCdpsAfterMigration.length).toEqual( + mcdCdpsBeforeMigration.length + 1 + ); }); }); diff --git a/packages/dai/contracts/tokens.js b/packages/dai/contracts/tokens.js index 3689e733c..be8a6c359 100644 --- a/packages/dai/contracts/tokens.js +++ b/packages/dai/contracts/tokens.js @@ -1,6 +1,4 @@ export default { - DAI: 'DAI', - SAI: 'SAI', MKR: 'MKR', WETH: 'WETH', PETH: 'PETH', diff --git a/packages/dai/src/eth/Currency.js b/packages/dai/src/eth/Currency.js index a58f6cd67..4160632d8 100644 --- a/packages/dai/src/eth/Currency.js +++ b/packages/dai/src/eth/Currency.js @@ -23,22 +23,18 @@ export const getCurrency = createGetCurrency(currencies); // the latter is convenient when you know what you want to use, and the former // is convenient when you are picking a currency based on a symbol from input -export const DAI = currencies.DAI; -export const SAI = currencies.SAI; export const ETH = currencies.ETH; export const MKR = currencies.MKR; export const PETH = currencies.PETH; export const WETH = currencies.WETH; export const USD = currencies.USD; -export const USD_DAI = createCurrencyRatio(USD, DAI); export const USD_ETH = createCurrencyRatio(USD, ETH); export const USD_MKR = createCurrencyRatio(USD, MKR); export const USD_PETH = createCurrencyRatio(USD, PETH); export const USD_WETH = createCurrencyRatio(USD, WETH); Object.assign(currencies, { - USD_DAI, USD_ETH, USD_MKR, USD_PETH, diff --git a/packages/dai/test/eth/AllowanceService.spec.js b/packages/dai/test/eth/AllowanceService.spec.js index 6771784e2..456a66617 100644 --- a/packages/dai/test/eth/AllowanceService.spec.js +++ b/packages/dai/test/eth/AllowanceService.spec.js @@ -1,16 +1,16 @@ import TestAccountProvider from '@makerdao/test-helpers/src/TestAccountProvider'; import { buildTestService } from '../helpers/serviceBuilders'; -import { SAI } from '../../src/eth/Currency'; +import { WETH } from '../../src/eth/Currency'; import { UINT256_MAX } from '../../src/utils/constants'; -let sai, testAddress, allowanceService, owner; +let token, testAddress, allowanceService, owner; async function buildTestAllowanceService(max = true) { allowanceService = buildTestService('allowance', { allowance: max ? true : { useMinimizeAllowancePolicy: true } }); await allowanceService.manager().authenticate(); - sai = allowanceService.get('token').getToken(SAI); + token = allowanceService.get('token').getToken('WETH'); owner = allowanceService .get('token') .get('web3') @@ -22,68 +22,68 @@ beforeEach(() => { }); afterEach(async () => { - if (sai) await sai.approve(testAddress, 0); + if (token) await token.approve(testAddress, 0); }); test('max allowance policy, no need to update', async () => { await buildTestAllowanceService(); - await sai.approveUnlimited(testAddress); - await allowanceService.requireAllowance(SAI, testAddress); + await token.approveUnlimited(testAddress); + await allowanceService.requireAllowance('WETH', testAddress); - const allowance = await sai.allowance(owner, testAddress); - expect(allowance).toEqual(SAI.wei(UINT256_MAX)); + const allowance = await token.allowance(owner, testAddress); + expect(allowance).toEqual(WETH.wei(UINT256_MAX)); }); test('max allowance policy, need to update', async () => { await buildTestAllowanceService(); - await sai.approve(testAddress, 0); + await token.approve(testAddress, 0); allowanceService.get('event').on('allowance/APPROVE', eventObj => { expect(eventObj.payload.transaction.hash).toBeDefined(); }); - await allowanceService.requireAllowance(SAI, testAddress); + await allowanceService.requireAllowance(WETH, testAddress); - const allowance = await sai.allowance(owner, testAddress); - expect(allowance).toEqual(SAI.wei(UINT256_MAX)); + const allowance = await token.allowance(owner, testAddress); + expect(allowance).toEqual(WETH.wei(UINT256_MAX)); }); test('min allowance policy, need to update', async () => { buildTestAllowanceService(false); - const estimate = SAI(100); - await sai.approve(testAddress, SAI(50)); + const estimate = WETH(100); + await token.approve(testAddress, WETH(50)); allowanceService.get('event').on('allowance/APPROVE', eventObj => { expect(eventObj.payload.transaction.hash).toBeDefined(); }); - await allowanceService.requireAllowance(SAI, testAddress, { estimate }); + await allowanceService.requireAllowance(WETH, testAddress, { estimate }); - const allowance = await sai.allowance(owner, testAddress); + const allowance = await token.allowance(owner, testAddress); expect(allowance).toEqual(estimate); }); test('min allowance policy, no need to update', async () => { await buildTestAllowanceService(false); - const estimate = SAI(100); - const initialAllowance = SAI(200); - await sai.approve(testAddress, initialAllowance); - await allowanceService.requireAllowance(SAI, testAddress, { estimate }); + const estimate = WETH(100); + const initialAllowance = WETH(200); + await token.approve(testAddress, initialAllowance); + await allowanceService.requireAllowance(WETH, testAddress, { estimate }); - const allowance = await sai.allowance(owner, testAddress); + const allowance = await token.allowance(owner, testAddress); expect(allowance).toEqual(initialAllowance); }); test('removeAllowance() works, need to update', async () => { await buildTestAllowanceService(false); - await sai.approve(testAddress, 300); - await allowanceService.removeAllowance(SAI, testAddress); + await token.approve(testAddress, 300); + await allowanceService.removeAllowance(WETH, testAddress); - const allowance = await sai.allowance(owner, testAddress); - expect(allowance).toEqual(SAI(0)); + const allowance = await token.allowance(owner, testAddress); + expect(allowance).toEqual(WETH(0)); }); test('removeAllowance() works, no need to update', async () => { await buildTestAllowanceService(false); - await sai.approve(testAddress, 0); - await allowanceService.removeAllowance(SAI, testAddress); + await token.approve(testAddress, 0); + await allowanceService.removeAllowance(WETH, testAddress); - const allowance = await sai.allowance(owner, testAddress); - expect(allowance).toEqual(SAI(0)); + const allowance = await token.allowance(owner, testAddress); + expect(allowance).toEqual(WETH(0)); }); diff --git a/packages/dai/test/eth/Currency.spec.js b/packages/dai/test/eth/Currency.spec.js index b9b5796ef..ca9b3c85a 100644 --- a/packages/dai/test/eth/Currency.spec.js +++ b/packages/dai/test/eth/Currency.spec.js @@ -1,10 +1,9 @@ // we just do some quick tests of the exports here, since the core functionality // is being tested in @makerdao/currency -import { getCurrency, ETH, PETH, WETH, DAI, MKR } from '../../src/eth/Currency'; +import { getCurrency, ETH, PETH, WETH, MKR } from '../../src/eth/Currency'; test('parses an amount and currency symbol', () => { - expect(getCurrency(1, 'dai').toString()).toBe('1.00 DAI'); expect(getCurrency(1, 'mkr').toString()).toBe('1.00 MKR'); expect(getCurrency(1, 'weth').toString()).toBe('1.00 WETH'); expect(getCurrency(1, 'peth').toString()).toBe('1.00 PETH'); @@ -15,6 +14,5 @@ test('parses an amount + currency class', () => { expect(getCurrency(1, ETH).toString()).toBe('1.00 ETH'); expect(getCurrency(1, PETH).toString()).toBe('1.00 PETH'); expect(getCurrency(1, WETH).toString()).toBe('1.00 WETH'); - expect(getCurrency(1, DAI).toString()).toBe('1.00 DAI'); expect(getCurrency(1, MKR).toString()).toBe('1.00 MKR'); }); diff --git a/packages/dai/test/eth/EthereumTokenService.spec.js b/packages/dai/test/eth/EthereumTokenService.spec.js index dc7c94683..bd1547902 100644 --- a/packages/dai/test/eth/EthereumTokenService.spec.js +++ b/packages/dai/test/eth/EthereumTokenService.spec.js @@ -11,7 +11,6 @@ beforeAll(async () => { test('getTokens returns tokens', () => { const tokensList = ethereumTokenService.getTokens(); - expect(tokensList.includes(tokens.DAI)).toBe(true); expect(tokensList.includes(tokens.MKR)).toBe(true); }); diff --git a/packages/dai/test/eth/TransactionManager.spec.js b/packages/dai/test/eth/TransactionManager.spec.js index c5fe4a61f..9ee0a8622 100644 --- a/packages/dai/test/eth/TransactionManager.spec.js +++ b/packages/dai/test/eth/TransactionManager.spec.js @@ -3,7 +3,6 @@ import { // buildTestEthereumCdpService, buildTestSmartContractService } from '../helpers/serviceBuilders'; -import tokens from '../../contracts/tokens'; import { uniqueId } from '../../src/utils'; import { mineBlocks } from '@makerdao/test-helpers'; import size from 'lodash/size'; @@ -70,7 +69,7 @@ test('reuse the same web3 and log service in test services', () => { test('wrapped contract call accepts a businessObject option', async () => { expect.assertions(3); - const sai = services.contract.getContract(tokens.SAI); + const token = services.contract.getContract('WETH'); const businessObject = { a: 1, @@ -79,7 +78,7 @@ test('wrapped contract call accepts a businessObject option', async () => { } }; - const txo = sai.approve(services.currentAddress, '1000000000000000000', { + const txo = token.approve(services.currentAddress, '1000000000000000000', { businessObject }); @@ -95,14 +94,14 @@ test('wrapped contract call accepts a businessObject option', async () => { test('wrapped contract call adds nonce, web3 settings', async () => { const { txMgr, currentAddress, contract } = services; - const sai = contract.getContract(tokens.SAI); + const token = contract.getContract('WETH'); const gasPrice = await txMgr.get('gas').getGasPrice(); jest.spyOn(txMgr, '_execute'); - await sai.approve(currentAddress, 20000); + await token.approve(currentAddress, 20000); expect(txMgr._execute).toHaveBeenCalledWith( - sai.wrappedContract, + token.wrappedContract, 'approve', [currentAddress, 20000], { diff --git a/packages/test-helpers/scripts/generateDai.js b/packages/test-helpers/scripts/generateDai.js index fa20718b8..8929ffaa2 100644 --- a/packages/test-helpers/scripts/generateDai.js +++ b/packages/test-helpers/scripts/generateDai.js @@ -2,7 +2,7 @@ // > node_modules/.bin/babel-node packages/test-helpers/scripts/generateDai.js
import { isAddress } from 'web3-utils'; -import { MDAI, ETH } from '@makerdao/dai-plugin-mcd/src/index'; +import { DAI, ETH } from '@makerdao/dai-plugin-mcd/src/index'; import { mcdMaker } from '@makerdao/dai-plugin-mcd/test/helpers'; async function main() { @@ -15,12 +15,12 @@ async function main() { } maker.service('accounts').useAccountWithAddress(address); - console.log(`Generating ${amount} MDAI for ${address}`); + console.log(`Generating ${amount} DAI for ${address}`); const cdpMgr = maker.service('mcd:cdpManager'); - await cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(amount)); + await cdpMgr.openLockAndDraw('ETH-A', ETH(1), DAI(amount)); - const dai = cdpMgr.get('token').getToken(MDAI); + const dai = cdpMgr.get('token').getToken(DAI); const balance = await dai.balanceOf(address) console.log(`Balance of ${address}: ${balance}`)