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

Commit

Permalink
Merge pull request #226 from makerdao/umd-builds
Browse files Browse the repository at this point in the history
Add umd builds
  • Loading branch information
jparklev authored May 4, 2020
2 parents 6724755 + 962de23 commit 29c0542
Show file tree
Hide file tree
Showing 21 changed files with 1,368 additions and 1,137 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
coverage/
dist/
umd/
node_modules/
.idea/
*.iml
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@
"copyfiles": "^2.0.0",
"eslint": "^5.15.1",
"eslint-loader": "^2.1.2",
"html-webpack-plugin": "^2.30.1",
"husky": "^3.0.8",
"jest": "^24.5.0",
"lint-staged": "^7.1.0",
"minimist": "^1.2.0",
"prettier": "^1.12.1",
"sane": "^4.0.3",
"solc": "^0.4.23",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^3.11.0",
"webpack-bundle-analyzer": "^3.3.2"
"terser-webpack-plugin": "^2.3.6",
"webpack": "^4.43.0",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-cli": "^3.3.11"
}
}
36 changes: 23 additions & 13 deletions packages/dai-plugin-governance/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{
"name": "@makerdao/dai-plugin-governance",
"description": "A dai.js plugin for adding MKR governance support to dapps.",
"version": "0.9.6-rc.2",
"version": "0.10.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/makerdao/dai-plugin-governance.git"
},
"dependencies": {
"@babel/runtime": "^7.4.3",
"@makerdao/currency": "^0.9.5",
"@makerdao/services-core": "^0.9.5",
"assert": "^2.0.0",
"ramda": "^0.25.0",
"web3-utils": "^1.0.0-beta.36"
},
"main": "dist/index.js",
"browser": "umd/index.js",
"unpkg": "umd/index.js",
"jsdelivr": "umd/index.js",
"scripts": {
"build": "../../scripts/build.sh",
"build": "yarn clean && yarn build:cjs && yarn build:umd",
"build:umd": "webpack --config ../../webpack.config.js",
"clean": "rm -rf ./dist ./umd",
"build:cjs": "../../scripts/build.sh",
"prepublishOnly": "yarn build",
"testchain": "../../scripts/run-testchain.sh",
"test": "yarn testchain --ci jest --runInBand",
Expand All @@ -29,9 +28,20 @@
"git add"
]
},
"module": "dist/index.js",
"main": "dist/index.js",
"dependencies": {
"@makerdao/currency": ">=0.9.0",
"@makerdao/services-core": ">=0.9.0",
"assert": "^2.0.0",
"debug": "^4.1.1",
"ramda": "^0.25.0"
},
"peerDependencies": {
"@makerdao/dai": ">=0.18.9"
},
"devDependencies": {
"@makerdao/dai-plugin-config": "^0.2.14-rc.1"
"@babel/cli": "^7.8.4",
"@makerdao/dai": "^0.29.0",
"@makerdao/dai-plugin-config": "^0.2.14-rc.1",
"web3-utils": "^1.2.6"
}
}
10 changes: 8 additions & 2 deletions packages/dai-plugin-mcd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
"description": "Plugin to add Multi-Collateral Dai support to dai.js",
"version": "1.3.13" ,
"license": "MIT",
"main": "dist",
"main": "dist/index.js",
"browser": "umd/index.js",
"unpkg": "umd/index.js",
"jsdelivr": "umd/index.js",
"scripts": {
"build": "../../scripts/build.sh",
"build": "yarn clean && yarn build:cjs && yarn build:umd",
"build:umd": "webpack --config ../../webpack.config.js",
"build:cjs": "../../scripts/build.sh",
"clean": "rm -rf ./dist ./umd",
"prepublishOnly": "yarn build",
"testchain": "../../scripts/run-testchain.sh",
"coverage": "yarn test --coverage",
Expand Down
12 changes: 9 additions & 3 deletions packages/dai-plugin-migrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
"description": "Plugin to add migrations to dai.js",
"version": "1.0.12",
"license": "MIT",
"main": "dist",
"main": "dist/index.js",
"browser": "umd/index.js",
"unpkg": "umd/index.js",
"jsdelivr": "umd/index.js",
"scripts": {
"build": "../../scripts/build.sh",
"build": "yarn clean && yarn build:cjs && yarn build:umd",
"build:umd": "webpack --config ../../webpack.config.js",
"build:cjs": "../../scripts/build.sh",
"clean": "rm -rf ./dist ./umd",
"prepublishOnly": "yarn build",
"testchain": "../../scripts/run-testchain.sh",
"coverage": "yarn test --coverage",
Expand All @@ -16,7 +22,7 @@
},
"dependencies": {
"@makerdao/currency": "^0.9.5",
"@makerdao/services-core": "^0.9.5",
"@makerdao/services-core": "^0.9.9",
"bignumber.js": "^8.1.1"
}
}
2 changes: 1 addition & 1 deletion packages/dai-plugin-migrations/src/migrations/DaiToSai.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tracksTransactions from '@makerdao/dai/dist/src/utils/tracksTransactions';
import { tracksTransactions } from '../utils';
import { DAI } from '..';

export default class DaiToSai {
Expand Down
2 changes: 1 addition & 1 deletion packages/dai-plugin-migrations/src/migrations/SaiToDai.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tracksTransactions from '@makerdao/dai/dist/src/utils/tracksTransactions';
import { tracksTransactions } from '../utils';
import { SAI } from '..';

export default class SaiToDai {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tracksTransactionsWithOptions } from '@makerdao/dai/dist/src/utils/tracksTransactions';
import { tracksTransactionsWithOptions } from '../utils';
import { getIdBytes, stringToBytes } from '../utils';
import { SAI, MKR } from '..';

Expand Down Expand Up @@ -39,9 +39,10 @@ export default class SingleToMultiCdp {
);

if (payment !== 'DEBT') await this._requireAllowance(cupId, payment);
return migrationProxy[method](...args, { dsProxy: true, promise }).then(
txo => this._manager.get('mcd:cdpManager').getNewCdpId(txo)
);
return migrationProxy[method](...args, {
dsProxy: true,
promise
}).then(txo => this._manager.get('mcd:cdpManager').getNewCdpId(txo));
}

async _requireAllowance(cupId, payment) {
Expand Down
78 changes: 78 additions & 0 deletions packages/dai-plugin-migrations/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'assert';
import padStart from 'lodash/padStart';
import times from 'lodash/times';

export function stringToBytes(str) {
assert(!!str, 'argument is falsy');
Expand All @@ -11,3 +12,80 @@ export function getIdBytes(id, prefix = true) {
assert(typeof id === 'number', 'ID must be a number');
return (prefix ? '0x' : '') + padStart(id.toString(16), 64, '0');
}

// FIXME this is a duplicate of the file in the main dai.js source -- it should
// be moved to a utility library or something, but for now, this is the simplest
// way to avoid any issues with importing

/*
The default export is a decorator definition.
If a function is decorated with `@tracksTransactions`, it should expect its last
argument to be an object with a key named `promise`. It should pass that
`promise` argument along as a key in the last argument to any non-constant
function calls it makes to a smart contract (i.e. an instance returned from the
getContract method in SmartContractService), or any calls it makes to other
functions that will eventually call such smart contract functions.
This allows TransactionManager to let users input a promise and attach lifecycle
callbacks to all transactions that were created in the course of executing that
promise.
@tracksTransactions is only necessary when the function is async. If the
function returns a contract call and does not make any async calls before that,
then the async keyword can be removed, and it just needs to have an `options`
argument that it passes to its contract call.
If you need to apply this to a function that has any arguments with default
values, use `@tracksTransactionsWithOptions({ numArguments })` instead, where
`numArguments` is the total number of arguments to the function, including the
last object which contains a key named `promise`.
*/

export const tracksTransactions = tracksTransactionsWithOptions({});

export function tracksTransactionsWithOptions({ numArguments }) {
return (target, name, descriptor) => {
const original = descriptor.value;
const correctArgsLength = numArguments || original.length;
descriptor.value = function(...args) {
const last = args[args.length - 1];
let options;
if (
typeof last === 'object' &&
last !== null &&
last.constructor === Object
) {
args = args.slice(0, args.length - 1);
options = last;
} else {
options = {};
}

const promise = (async () => {
// this "no-op await" is necessary for the inner reference to the
// outer promise to become valid.
await 0;

// if there's already a promise, reuse it instead of setting this one--
// this allows the function we're running to behave differently when
// it's called directly vs. by another function. e.g. lockWeth
if (!options.promise) options.promise = promise;

// pad the list of arguments with `undefined` to account for any missing
// ones with default values.
const newArgs = [
...args,
...times(correctArgsLength - 1 - args.length, () => undefined),
options
];

return original.apply(this, newArgs);
})();
return promise;
};
return descriptor;
};
}
29 changes: 13 additions & 16 deletions packages/dai-plugin-scd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
[![Build Status][build]][build-url]
[![Coverage Status][cover]][cover-url]


**Dai.js** is a JavaScript library that makes it easy to build applications on top of [MakerDAO][makerdao]'s Dai Stablecoin System. You can use Maker's contracts to open Collateralized Debt Positions, withdraw loans in Dai, trade tokens on OasisDEX, and more.

The library features a pluggable, service-based architecture, which allows users maximal control when integrating the Maker functionality into existing infrastructures. It also includes convenient configuration presets for out-of-the-box usability, a powerful smart contract state inspector, and support for both front-end and back-end applications.

Maker's entire suite of contracts will eventually be accessible through this library—including the DAO governance and the upcoming multi-collateral release—but functionality is limited in the current alpha version to the following areas:

* Opening and shutting CDPs
* Locking and unlocking collateral
* Withdrawing and repaying Dai
* Automated token conversions
* Token contract functionality for WETH, PETH, MKR, Dai, and ETH
* Buying and selling MKR and Dai with built-in DEX integration
- Opening and shutting CDPs
- Locking and unlocking collateral
- Withdrawing and repaying Dai
- Automated token conversions
- Token contract functionality for WETH, PETH, MKR, Dai, and ETH
- Buying and selling MKR and Dai with built-in DEX integration

## Usage

Use NPM or Yarn to install the library:

```
npm install @makerdao/dai
```
Expand All @@ -35,6 +35,7 @@ const Maker = require('@makerdao/dai');
```

Example for transferring Dai:

```js
import Maker from '@makerdao/dai';
const maker = Maker.create('test');
Expand All @@ -47,6 +48,7 @@ transferDai(address, amount) {
```

Example for using CDPs:

```js
import Maker from '@makerdao/dai';
const maker = Maker.create('test');
Expand Down Expand Up @@ -95,8 +97,8 @@ If you have deployed contract code changes to the testchain, run `scripts/instal

### Commands

- `yarn build:backend` - create backend build in `dist` folder
- `yarn build:frontend` - create a UMD build in `dist` folder
- `yarn build:cjs` - create a commonJS build in `dist` folder
- `yarn build:umd` - create a UMD build in `umd` folder
- `yarn lint` - run an ESLint check
- `yarn coverage` - run code coverage and generate report in the `coverage` folder
- `yarn test` - start a test chain and run all tests
Expand All @@ -111,27 +113,22 @@ If you have deployed contract code changes to the testchain, run `scripts/instal
### 0.17.0

- **BREAKING CHANGE**: Importing a file directly from the package must now be done by
prefixing the path with `dist`. E.g. `/contracts/addresses/kovan.json` now becomes
`/dist/contract/addresses/kovan.json`.
prefixing the path with `dist`. E.g. `/contracts/addresses/kovan.json` now becomes
`/dist/contract/addresses/kovan.json`.

## License

**Dai.js** is available under the MIT license included with the code.

[npm]: https://img.shields.io/npm/v/@makerdao/dai.svg?style=flat
[npm-url]: https://www.npmjs.com/package/@makerdao/dai

[tests]: http://img.shields.io/travis/makerdao/dai.js.svg
[tests-url]: https://travis-ci.org/makerdao/dai.js

[license]: https://img.shields.io/badge/license-MIT-blue.svg
[license-url]: https://github.com/makerdao/dai.js/blob/dev/LICENSE

[build]: https://travis-ci.com/makerdao/dai.js.svg?branch=dev
[build-url]: https://travis-ci.com/makerdao/dai.js

[cover]: https://codecov.io/gh/makerdao/dai.js/branch/dev/graph/badge.svg
[cover-url]: https://codecov.io/github/makerdao/dai.js?branch=dev

[makerdao]: https://makerdao.com
[wiki]: https://github.com/makerdao/dai.js/wiki
10 changes: 9 additions & 1 deletion packages/dai-plugin-scd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
"version": "1.1.3",
"license": "MIT",
"main": "dist/src/index.js",
"browser": "umd/index.js",
"unpkg": "umd/index.js",
"jsdelivr": "umd/index.js",
"scripts": {
"build": "./scripts/build.sh",
"build": "yarn clean && yarn build:cjs && yarn build:umd",
"build:umd": "webpack --config ../../webpack.config.js",
"build:cjs": "./scripts/build.sh",
"clean": "rm -rf ./dist ./umd",
"prepublishOnly": "yarn build",
"testchain": "../../scripts/run-testchain.sh",
"coverage": "yarn test --coverage",
Expand All @@ -31,13 +37,15 @@
"@babel/preset-env": "^7.4.5",
"@makerdao/currency": "^0.9.5",
"@makerdao/services-core": "^0.9.9",
"assert": "^2.0.0",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.8.0",
"bignumber.js": "^8.1.1",
"chokidar": "^2.0.4",
"copyfiles": "^2.0.0",
"eslint-loader": "^2.1.2",
"husky": "^3.0.8",
"isomorphic-fetch": "^2.2.1",
"jest": "^24.5.0",
"lerna": "^3.15.0",
"lodash": "^4.17.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/dai-plugin-scd/src/QueryApiScd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ethUtil from 'ethereumjs-util';
import { getQueryResponse } from '@makerdao/dai/dist/src/QueryApi';
import { getQueryResponse } from './utils/getQueryResponse';

const MAINNET_SERVER_URL = 'https://sai-mainnet.makerfoundation.com/v1';
const KOVAN_SERVER_URL = 'https://sai-kovan.makerfoundation.com/v1';
Expand Down
20 changes: 20 additions & 0 deletions packages/dai-plugin-scd/src/utils/getQueryResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import assert from 'assert';
import fetch from 'isomorphic-fetch';

export async function getQueryResponse(serverUrl, query, variables) {
const resp = await fetch(serverUrl, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
query,
variables
})
});

const { data } = await resp.json();
assert(data, `error fetching data from ${serverUrl}`);
return data;
}
Loading

0 comments on commit 29c0542

Please sign in to comment.