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

Commit

Permalink
Merge branch 'dev' of github.com:makerdao/dai.js into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
levity committed Feb 10, 2020
2 parents 1d34efd + 682b328 commit a376194
Show file tree
Hide file tree
Showing 44 changed files with 3,173 additions and 103 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
"@babel/plugin-proposal-function-sent": "^7.2.0",
"@babel/plugin-proposal-numeric-separator": "^7.2.0",
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.4.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/dai-plugin-governance/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@makerdao/dai-plugin-governance",
"description": "A dai.js plugin for adding MKR governance support to dapps.",
"version": "0.9.1-rc.2",
"version": "0.9.2",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/dai-plugin-mcd/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = function(api) {

const presets = ['@babel/preset-env'];
const plugins = [
'@babel/plugin-proposal-optional-chaining',
['@babel/plugin-proposal-decorators', { legacy: true }],
'@babel/plugin-proposal-function-sent',
'@babel/plugin-proposal-export-namespace-from',
Expand Down
3 changes: 2 additions & 1 deletion packages/dai-plugin-mcd/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/test/integration/'
]
],
moduleFileExtensions: ['js', 'json']
};
9 changes: 6 additions & 3 deletions packages/dai-plugin-mcd/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@makerdao/dai-plugin-mcd",
"description": "Plugin to add Multi-Collateral Dai support to dai.js",
"version": "1.0.6",
"version": "1.1.0-rc.1",
"license": "MIT",
"main": "dist",
"scripts": {
Expand All @@ -10,6 +10,7 @@
"testchain": "../../scripts/run-testchain.sh",
"coverage": "yarn test --coverage",
"test": "yarn testchain --ci jest --runInBand",
"test:debug": "yarn testchain --ci node --inspect-brk ../../node_modules/.bin/jest --runInBand",
"test:kovan": "export NETWORK='kovan' && yarn test --config ./test/config/jestIntegrationConfig.json",
"test:integration": "export NETWORK='test' && yarn test --config ./test/config/jestIntegrationConfig.json"
},
Expand All @@ -19,6 +20,8 @@
"dependencies": {
"@makerdao/currency": "^0.9.5",
"@makerdao/services-core": "^0.9.9",
"bignumber.js": "^8.1.1"
}
"bignumber.js": "^8.1.1",
"rxjs": "^6.5.4"
},
"types": "typings/index.d.ts"
}
21 changes: 20 additions & 1 deletion packages/dai-plugin-mcd/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,37 @@ export const USD_ETH = createCurrencyRatio(USD, ETH);
export const MWETH = createCurrency('MWETH');
export const MDAI = createCurrency('MDAI');

// Casting for savings dai
export const DSR_DAI = createCurrency('DSR-DAI');

export const REP = createCurrency('REP');
export const ZRX = createCurrency('ZRX');
export const OMG = createCurrency('OMG');
export const BAT = createCurrency('BAT');
export const DGD = createCurrency('DGD');
export const GNT = createCurrency('GNT');

const defaultCdpTypes = [
export const defaultCdpTypes = [
{ currency: ETH, ilk: 'ETH-A' },
{ currency: BAT, ilk: 'BAT-A' }
];

export const SAI = createCurrency('SAI');

export const ALLOWANCE_AMOUNT = BigNumber(
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
);

export const defaultTokens = [
...new Set([
...defaultCdpTypes.map(type => type.currency),
MDAI,
MWETH,
SAI,
DSR_DAI
])
];

export default {
addConfig: (
_,
Expand Down
32 changes: 32 additions & 0 deletions packages/dai-plugin-mcd/src/schemas/cat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { toHex, fromRay } from '../utils';
import BigNumber from 'bignumber.js';
import { RAY } from '../constants';

import {
LIQUIDATOR_ADDRESS,
LIQUIDATION_PENALTY,
MAX_AUCTION_LOT_SIZE
} from './constants';

const validateCollateralTypeName = name =>
!name && 'Invalid collateral type name';

export const catIlks = {
generate: collateralTypeName => ({
id: `MCD_CAT.ilks(${collateralTypeName})`,
contract: 'MCD_CAT',
call: ['ilks(bytes32)(address,uint256,uint256)', toHex(collateralTypeName)]
}),
validate: {
args: validateCollateralTypeName
},
returns: [
[LIQUIDATOR_ADDRESS],
[LIQUIDATION_PENALTY, v => fromRay(BigNumber(v).minus(RAY))],
[MAX_AUCTION_LOT_SIZE, v => BigNumber(v).shiftedBy(-18)]
]
};

export default {
catIlks
};
62 changes: 62 additions & 0 deletions packages/dai-plugin-mcd/src/schemas/cdpManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { bytesToString } from '../utils';
import BigNumber from 'bignumber.js';

import {
VAULT_ADDRESS,
VAULT_TYPE,
VAULTS_CREATED,
VAULT_OWNER
} from './constants';

export const cdpManagerUrns = {
generate: id => ({
id: `CDP_MANAGER.urns(${id})`,
contract: 'CDP_MANAGER',
call: ['urns(uint256)(address)', parseInt(id)]
}),
returns: [VAULT_ADDRESS]
};

const validateVaultId = id =>
!/^\d+$/.test(id) && 'Invalid vault id: must be a positive integer';

const validateVaultTypeResult = vaultType =>
!vaultType && 'Vault does not exist';

export const cdpManagerIlks = {
generate: id => ({
id: `CDP_MANAGER.ilks(${id})`,
contract: 'CDP_MANAGER',
call: ['ilks(uint256)(bytes32)', parseInt(id)]
}),
validate: {
args: validateVaultId,
[VAULT_TYPE]: validateVaultTypeResult
},
returns: [[VAULT_TYPE, bytesToString]]
};

export const cdpManagerCdpi = {
generate: () => ({
id: 'CDP_MANAGER.cdpi',
contract: 'CDP_MANAGER',
call: ['cdpi()(uint256)']
}),
returns: [[VAULTS_CREATED, v => BigNumber(v)]]
};

export const cdpManagerOwner = {
generate: id => ({
id: `CDP_MANAGER.owner(${id})`,
contract: 'CDP_MANAGER',
call: ['owns(uint256)(address)', id]
}),
returns: [[VAULT_OWNER]]
};

export default {
cdpManagerUrns,
cdpManagerIlks,
cdpManagerCdpi,
cdpManagerOwner
};
Loading

0 comments on commit a376194

Please sign in to comment.