aboutsummaryrefslogtreecommitdiffstats
path: root/packages/migrations/src/utils
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-06-28 06:13:57 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-06-30 08:25:56 +0800
commit6e1a549fcb5cc9257ee984a906db78dd2568042b (patch)
tree08432dbc8a2e12c352030ed40f62f3bd44227f97 /packages/migrations/src/utils
parent5f0a2953c63c31daa975b587f5c5072b6f7e418c (diff)
downloaddexon-sol-tools-6e1a549fcb5cc9257ee984a906db78dd2568042b.tar
dexon-sol-tools-6e1a549fcb5cc9257ee984a906db78dd2568042b.tar.gz
dexon-sol-tools-6e1a549fcb5cc9257ee984a906db78dd2568042b.tar.bz2
dexon-sol-tools-6e1a549fcb5cc9257ee984a906db78dd2568042b.tar.lz
dexon-sol-tools-6e1a549fcb5cc9257ee984a906db78dd2568042b.tar.xz
dexon-sol-tools-6e1a549fcb5cc9257ee984a906db78dd2568042b.tar.zst
dexon-sol-tools-6e1a549fcb5cc9257ee984a906db78dd2568042b.zip
Use ledger subprovider
Diffstat (limited to 'packages/migrations/src/utils')
-rw-r--r--packages/migrations/src/utils/artifact_writer.ts26
-rw-r--r--packages/migrations/src/utils/constants.ts15
-rw-r--r--packages/migrations/src/utils/provider_factory.ts37
3 files changed, 78 insertions, 0 deletions
diff --git a/packages/migrations/src/utils/artifact_writer.ts b/packages/migrations/src/utils/artifact_writer.ts
new file mode 100644
index 000000000..2da5a09dd
--- /dev/null
+++ b/packages/migrations/src/utils/artifact_writer.ts
@@ -0,0 +1,26 @@
+import { BaseContract } from '@0xproject/base-contract';
+import { ContractArtifact } from '@0xproject/sol-compiler';
+import * as fs from 'fs';
+import * as path from 'path';
+
+export class ArtifactWriter {
+ private _artifactsDir: string;
+ private _networkId: number;
+ constructor(artifactsDir: string, networkId: number) {
+ this._artifactsDir = artifactsDir;
+ this._networkId = networkId;
+ }
+ // This updates the artifact file but does not update the `artifacts` module above. It will not
+ // contain the saved artifact changes.
+ public saveArtifact(contract: BaseContract): void {
+ const contractName = contract.contractName;
+ const artifactFile = path.join(this._artifactsDir, `${contractName}.json`);
+ const artifact: ContractArtifact = JSON.parse(fs.readFileSync(artifactFile).toString());
+ artifact.networks[this._networkId] = {
+ address: contract.address,
+ links: {},
+ constructorArgs: JSON.stringify(contract.constructorArgs),
+ };
+ fs.writeFileSync(artifactFile, JSON.stringify(artifact, null, '\t'));
+ }
+}
diff --git a/packages/migrations/src/utils/constants.ts b/packages/migrations/src/utils/constants.ts
new file mode 100644
index 000000000..21887ab16
--- /dev/null
+++ b/packages/migrations/src/utils/constants.ts
@@ -0,0 +1,15 @@
+import { BigNumber } from '@0xproject/utils';
+
+export const constants = {
+ ASSET_PROXY_OWNER_OWNERS: [
+ '0x9df8137872ac09a8fee71d0da5c7539923fb9bf0',
+ '0xcf34d44db312d188789f43a63d11cf2bebb4da15',
+ '0x73fd50f2a6beac9cdac9fe87ef68a18edc415831',
+ ],
+ ASSET_PROXY_OWNER_TIMELOCK: new BigNumber(0),
+ ASSET_PROXY_OWNER_CONFIRMATIONS: new BigNumber(1),
+ ERC20_PROXY_ID: '0xf47261b0',
+ ERC721_PROXY_ID: '0x08e937fa',
+ NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
+ RPC_URL: 'http://localhost:8545',
+};
diff --git a/packages/migrations/src/utils/provider_factory.ts b/packages/migrations/src/utils/provider_factory.ts
new file mode 100644
index 000000000..14b1be982
--- /dev/null
+++ b/packages/migrations/src/utils/provider_factory.ts
@@ -0,0 +1,37 @@
+import { LedgerSubprovider } from '@0xproject/subproviders';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import Eth from '@ledgerhq/hw-app-eth';
+import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
+import { Provider } from 'ethereum-types';
+import ProviderEngine = require('web3-provider-engine');
+import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
+
+import { LedgerEthereumClient } from '../types';
+
+import { constants } from './constants';
+
+async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> {
+ const ledgerConnection = await TransportNodeHid.create();
+ const ledgerEthClient = new Eth(ledgerConnection);
+ return ledgerEthClient;
+}
+export const providerFactory = {
+ async getLedgerProviderAsync(): Promise<Provider> {
+ const provider = new ProviderEngine();
+ provider.addProvider(
+ new RpcSubprovider({
+ rpcUrl: constants.RPC_URL,
+ }),
+ );
+ const web3Wrapper = new Web3Wrapper(provider);
+ const networkId = await web3Wrapper.getNetworkIdAsync();
+ const ledgerWalletConfigs = {
+ networkId,
+ ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
+ };
+ const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
+ provider.addProvider(ledgerSubprovider);
+ provider.start();
+ return provider;
+ },
+};