Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
New Collaterals (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
Padraic-O-Mhuiris authored May 30, 2020
1 parent c7ea0d5 commit e8e3c15
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 26 deletions.
3 changes: 2 additions & 1 deletion packages/dai-plugin-mcd/contracts/abiMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ module.exports = {
MIGRATION: require('./abis/ScdMcdMigration.json'),
MIGRATION_PROXY_ACTIONS: require('./abis/MigrationProxyActions.json'),
USDC: require('./abis/USDC.json'),
WBTC: require('./abis/WBTC.json')
WBTC: require('./abis/WBTC.json'),
TUSD: require('./abis/DSToken.json')
};
23 changes: 13 additions & 10 deletions packages/dai-plugin-mcd/contracts/addresses/kovan.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@
"PIP_USDC": "0x4c51c2584309b7BF328F89609FDd03B3b95fC677",
"MCD_JOIN_USDC_A": "0x4c514656E7dB7B859E994322D2b511d99105C1Eb",
"MCD_FLIP_USDC_A": "0x45d5b4A304f554262539cfd167dd05e331Da686E",
"MCD_JOIN_USDC_B": "0xaca10483e7248453BB6C5afc3e403e8b7EeDF314",
"MCD_FLIP_USDC_B": "0x93AE217b0C6bF52E9FFea6Ab191cCD438d9EC0de",
"WBTC": "0x7419f744bBF35956020C1687fF68911cD777f865",
"PIP_WBTC": "0x2f38a1bD385A9B395D01f2Cbf767b4527663edDB",
"MCD_JOIN_WBTC_A": "0xB879c7d51439F8e7AC6b2f82583746A0d336e63F",
"MCD_FLIP_WBTC_A": "0xc45A1b76D3316D56a0225fB02Ab6b7637403fF67",
"TUSD": "0xD6CE59F06Ff2070Dd5DcAd0866A7D8cd9270041a",
"PIP_TUSD": "0xE4bAECdba7A8Ff791E14c6BF7e8089Dfdf75C7E7",
"MCD_JOIN_TUSD_A": "0xe53f6755A031708c87d80f5B1B43c43892551c17",
"MCD_FLIP_TUSD_A": "0x51a8fB578E830c932A2D49927584C643Ad08d9eC",
"PROXY_PAUSE_ACTIONS": "0x7c52826c1efEAE3199BDBe68e3916CC3eA222E29",
"PROXY_DEPLOYER": "0xA9fCcB07DD3f774d5b9d02e99DE1a27f47F91189",
"SAI": "0xC4375B7De8af5a38a93548eb8453a498222C4fF2",
"PIP_SAI": "0x62eaf847dfd5De95a09a2708366a0525749A1f6D",
"MCD_JOIN_SAI": "0x2d2672D655C95016e19909174d1fC72A6DE7D381",
"MCD_FLIP_SAI": "0x2F68D2A62ffeBF9Cf09b3908C6D423109b77254A",
"PROXY_PAUSE_ACTIONS": "0x7c52826c1efEAE3199BDBe68e3916CC3eA222E29",
"PROXY_DEPLOYER": "0xA9fCcB07DD3f774d5b9d02e99DE1a27f47F91189",
"SAI_TUB": "0xa71937147b55Deb8a530C7229C442Fd3F31b7db2",
"MIGRATION": "0x411B2Faa662C8e3E5cF8f01dFdae0aeE482ca7b0",
"MIGRATION_PROXY_ACTIONS": "0xF56765d255463139d3aff1613705a5520764Ab93",

"WBTC": "0x7419f744bBF35956020C1687fF68911cD777f865",
"MCD_JOIN_WBTC_A": "0xB879c7d51439F8e7AC6b2f82583746A0d336e63F",
"MCD_FLIP_WBTC_A": "0xc45A1b76D3316D56a0225fB02Ab6b7637403fF67",
"PIP_WBTC": "0x2f38a1bD385A9B395D01f2Cbf767b4527663"
"MIGRATION_PROXY_ACTIONS": "0xF56765d255463139d3aff1613705a5520764Ab93"
}
10 changes: 8 additions & 2 deletions packages/dai-plugin-mcd/contracts/addresses/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@
"SAI_TUB": "0x448a5065aeBB8E423F0896E6c5D525C040f59af3",
"MIGRATION": "0xc73e0383F3Aff3215E6f04B0331D58CeCf0Ab849",
"MIGRATION_PROXY_ACTIONS": "0x2E1F6062d9fB227069741E40f89186DF222FB426",

"WBTC": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
"PIP_WBTC": "0xf185d0682d50819263941e5f4EacC763CC5C6C42",
"MCD_JOIN_WBTC_A": "0xBF72Da2Bd84c5170618Fbe5914B0ECA9638d5eb5",
"MCD_FLIP_WBTC_A": "0x3E115d85D4d7253b05fEc9C0bB5b08383C2b0603"
"MCD_FLIP_WBTC_A": "0x3E115d85D4d7253b05fEc9C0bB5b08383C2b0603",

"TUSD":"0xCB9a11afDC6bDb92E4A6235959455F28758b34bA",
"MCD_JOIN_USDC_B":"0x2600004fd1585f7270756DDc88aD9cfA10dD0428",
"MCD_FLIP_USDC_B": "0xec25Ca3fFa512afbb1784E17f1D414E16D01794F",
"MCD_JOIN_TUSD_A": "0x4454aF7C8bb9463203b66C816220D41ED7837f44",
"PIP_TUSD": "0xeE13831ca96d191B688A670D47173694ba98f1e5",
"MCD_FLIP_TUSD_A": "0xba3f6a74BD12Cf1e48d4416c7b50963cA98AfD61"
}
10 changes: 9 additions & 1 deletion packages/dai-plugin-mcd/contracts/addresses/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,13 @@
"VAL_ZRX": "0x80f178c7b47cb635Ceb12aBB891338744e98365C",
"VOTE_PROXY_FACTORY": "0x9d0C1845c18bD93FB3514705715AAc54FB2135dd",
"WBTC": "0xcf4a441593Fbf1Bf56960674C5a3a18049C7bbe2",
"ZRX": "0xb13094D7341fA2F77aD8a5eD61A9bB7cF9F62093"
"ZRX": "0xb13094D7341fA2F77aD8a5eD61A9bB7cF9F62093",

"MCD_JOIN_USDC_B": "0x77d6250c22eCBA016a4F6D1a917BF5b2ED0704C5",
"MCD_FLIP_USDC_B": "0xb957a5d4113eC015AF73796099e6654d66A6115e",
"TUSD": "0xDa4EbE73ff9e11FC6f97cEf200199Ddb385d7982",
"PIP_TUSD": "0xA70B7c2a55a76f89b64b4b15381FfF87279dD3d7",
"MCD_JOIN_TUSD_A": "0x77d6250c22eCBA016a4F6D1a917BF5b2ED0704C5",
"MCD_FLIP_TUSD_A": "0xb957a5d4113eC015AF73796099e6654d66A6115e"

}
30 changes: 22 additions & 8 deletions packages/dai-plugin-mcd/src/CdpManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import tracksTransactions, {
import { ServiceRoles } from './constants';
import assert from 'assert';
import ManagedCdp from './ManagedCdp';
import { castAsCurrency, stringToBytes, bytesToString } from './utils';
import {
castAsCurrency,
stringToBytes,
bytesToString,
promiseWait
} from './utils';
import has from 'lodash/has';
import padStart from 'lodash/padStart';
import { DAI, ETH, GNT } from './index';
Expand Down Expand Up @@ -47,7 +52,16 @@ export default class CdpManager extends LocalService {
const cacheEnabled = !has(options, 'cache') || options.cache;
let cdp = this._getFromInstanceCache(id, cacheEnabled);
if (cdp) return cdp;
const ilk = await this.getIlkForCdp(id);

// This lookup can sometimes miss when a vault is created
// causing an assertion error on a missing ilk.
let ilk;
for (let i = 0; i < 5; i++) {
ilk = await this.getIlkForCdp(id);
if (ilk) break;
await promiseWait(5000);
}

cdp = new ManagedCdp(id, ilk, this, options);

this._putInInstanceCache(id, cdp, cacheEnabled);
Expand Down Expand Up @@ -133,7 +147,7 @@ export default class CdpManager extends LocalService {
this._adapterAddress(ilk),
this._adapterAddress('DAI'),
id || stringToBytes(ilk),
!isEth && lockAmount.toFixed(this._precision(lockAmount)),
!isEth && lockAmount.toFixed(this._precision(lockAmount, ilk)),
drawAmount.toFixed('wei'),
{
dsProxy: true,
Expand Down Expand Up @@ -169,7 +183,7 @@ export default class CdpManager extends LocalService {
this._managerAddress,
this._adapterAddress(ilk),
id,
!isEth && lockAmount.toFixed(this._precision(lockAmount)),
!isEth && lockAmount.toFixed(this._precision(lockAmount, ilk)),
owner,
{
dsProxy: true,
Expand Down Expand Up @@ -208,7 +222,7 @@ export default class CdpManager extends LocalService {
this._adapterAddress(ilk),
this._adapterAddress('DAI'),
this.getIdBytes(id),
freeAmount.toFixed(this._precision(freeAmount)),
freeAmount.toFixed(this._precision(freeAmount, ilk)),
wipeAmount.toFixed('wei'),
{ dsProxy: true, promise, metadata: { id, ilk, wipeAmount, freeAmount } }
);
Expand Down Expand Up @@ -269,7 +283,7 @@ export default class CdpManager extends LocalService {
this._adapterAddress(ilk),
this._adapterAddress('DAI'),
this.getIdBytes(id),
freeAmount.toFixed(this._precision(freeAmount)),
freeAmount.toFixed(this._precision(freeAmount, ilk)),
{ dsProxy: true, promise, metadata: { id, ilk, freeAmount } }
);
}
Expand Down Expand Up @@ -342,10 +356,10 @@ export default class CdpManager extends LocalService {
return this.get(SYSTEM_DATA).adapterAddress(ilk);
}

_precision(amount) {
_precision(amount, ilk) {
return amount.type.symbol === 'ETH'
? 'wei'
: this.get(CDP_TYPE).getCdpType(amount.type).decimals;
: this.get(CDP_TYPE).getCdpType(amount.type, ilk).decimals;
}

_getFromInstanceCache(id, enabled) {
Expand Down
5 changes: 4 additions & 1 deletion packages/dai-plugin-mcd/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ export const DGD = createCurrency('DGD');
export const GNT = createCurrency('GNT');
export const USDC = createCurrency('USDC');
export const WBTC = createCurrency('WBTC');
export const TUSD = createCurrency('TUSD');

export const defaultCdpTypes = [
{ currency: ETH, ilk: 'ETH-A' },
{ currency: BAT, ilk: 'BAT-A' },
{ currency: USDC, ilk: 'USDC-A', decimals: 6 },
{ currency: WBTC, ilk: 'WBTC-A', decimals: 8 }
{ currency: WBTC, ilk: 'WBTC-A', decimals: 8 },
{ currency: USDC, ilk: 'USDC-B', decimals: 6 },
{ currency: TUSD, ilk: 'TUSD-A', decimals: 18 }
];

export const SAI = createCurrency('SAI');
Expand Down
2 changes: 0 additions & 2 deletions packages/dai-plugin-mcd/src/schemas/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ export const tokenAllowance = {
export const adapterBalance = {
generate: collateralTypeName => ({
dependencies: ({ get }) => {
collateralTypeName =
collateralTypeName === 'DAI' ? 'DAI' : collateralTypeName;
let tokenSymbol = collateralTypeName.split('-')[0];
tokenSymbol = tokenSymbol === 'ETH' ? 'WETH' : tokenSymbol;
return [
Expand Down
5 changes: 4 additions & 1 deletion packages/dai-plugin-mcd/test/CdpTypeService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ describe('with default types', () => {

test('getCdpType with too many matches throws an error', async () => {
maker = await mcdMaker({
cdpTypes: [{ currency: ETH, ilk: 'ETH-A' }, { currency: ETH, ilk: 'ETH-B' }]
cdpTypes: [
{ currency: ETH, ilk: 'ETH-A' },
{ currency: ETH, ilk: 'ETH-B' }
]
});
service = maker.service(ServiceRoles.CDP_TYPE);

Expand Down

0 comments on commit e8e3c15

Please sign in to comment.