-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support config.js, introduce context type for global state, and expor…
…t config types (#33) * Fix conflicts * Start refactoring client * Change fs to async * Introduce shared context and rework config logic * Check network symbols with Zod and add tests * Support config.js and cover config logic with tests * Add .vscode directory with tasks configuration * Make EthSdkCtx readonly * Address review comments * Make Address Opaque again * Ignore test files in tsconfig.build.json * Support configs written in TypeScript when ts-node is installed * Add changeset * Describe new config in README.md
- Loading branch information
Showing
60 changed files
with
894 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
'@dethcrypto/eth-sdk': minor | ||
--- | ||
|
||
**Breaking Changes:** | ||
|
||
1. Config files can now be named `config` or `eth-sdk.config` instead of `contracts`. Supported extensions are `.js`, `.ts`, `.cjs` and `.json`. | ||
|
||
```ts | ||
import { defineConfig } from '@dethcrypto/eth-sdk' | ||
|
||
export default defineConfig({ | ||
contracts: { | ||
mainnet: { | ||
dai: '0x6b175474e89094c44da98b954eedeac495271d0f', | ||
}, | ||
}, | ||
outputPath: './eth-sdk/client' | ||
}); | ||
``` | ||
|
||
2. `--out` flag in CLI is no longer supported in favor of `config.outputPath`. | ||
|
||
**How to migrate?** | ||
|
||
Rename your `contracts.json` file to `config.json` and paste it's contents under "contracts" property. | ||
|
||
Before: | ||
|
||
```json | ||
{ | ||
"mainnet": { /* your contracts */ } | ||
} | ||
``` | ||
|
||
After: | ||
|
||
```json | ||
{ | ||
"contracts": { | ||
"mainnet": { /* your contracts */ } | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "eth-sdk: typecheck", | ||
"type": "shell", | ||
"command": "yarn tsc -P ./packages/eth-sdk/tsconfig.json --noEmit --incremental false --composite false", | ||
"problemMatcher": [ | ||
"$tsc" | ||
] | ||
}, | ||
{ | ||
"label": "eth-sdk: lint:fix", | ||
"type": "npm", | ||
"script": "lint:fix", | ||
"path": "packages/eth-sdk/", | ||
"options": { | ||
"cwd": "packages/eth-sdk/" | ||
}, | ||
"problemMatcher": [ | ||
"$eslint-stylish" | ||
] | ||
}, | ||
{ | ||
"label": "eth-sdk: check", | ||
"dependsOn": [ | ||
"eth-sdk: typecheck", | ||
"eth-sdk: lint:fix" | ||
], | ||
"problemMatcher": [] | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"contracts": { | ||
"mainnet": { | ||
"tokens": { | ||
"comp": "0xc00e94cb662c3520282e6f5717214004a7f26888" | ||
}, | ||
"compound": { | ||
"comptroller": "0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B", | ||
"comptrollerImpl": "0x374ABb8cE19A73f2c4EFAd642bda76c797f19233", | ||
"treasury": "0x2775b1c75658be0f640272ccb8c72ac986009e38" | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { EthSdkConfig } from '@dethcrypto/eth-sdk' | ||
|
||
const config: EthSdkConfig = { | ||
contracts: { | ||
mainnet: { | ||
dai: '0x6b175474e89094c44da98b954eedeac495271d0f', | ||
}, | ||
}, | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/eth-sdk/src/abi-management/etherscan/getAbiFromEtherscan.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import debug from 'debug' | ||
import { dirname, join } from 'path' | ||
|
||
import { Fs } from '../helpers/fs' | ||
import { traverseSdkDefinition } from '../helpers/traverse' | ||
import { SdkDefinition } from '../sdk-def' | ||
import { Address } from '../sdk-def' | ||
import { Address } from '../config' | ||
import { traverseContractsMap } from '../config/traverse' | ||
import { EthSdkCtx } from '../types' | ||
import { getABIFromEtherscan } from './etherscan/getAbiFromEtherscan' | ||
import { GetAbi } from './types' | ||
const d = debug('@dethcrypto/eth-sdk:abi') | ||
|
||
export async function gatherABIs(def: SdkDefinition, outputRoot: string, fs: Fs, getAbi: GetAbi = getABIFromEtherscan) { | ||
await traverseSdkDefinition(def, async (network: string, key: string[], address: Address) => { | ||
const fullAbiPath = join(outputRoot, 'abis', network, ...key) + '.json' | ||
export async function gatherABIs(ctx: EthSdkCtx, getAbi: GetAbi = getABIFromEtherscan) { | ||
const { config, fs } = ctx | ||
|
||
await traverseContractsMap(config.contracts, async (network: string, key: string[], address: Address) => { | ||
const fullAbiPath = join(config.outputPath, 'abis', network, ...key) + '.json' | ||
d(`Getting ABI for ${key.join('.')}`) | ||
|
||
if (!fs.exists(fullAbiPath)) { | ||
d('ABI doesnt exist already. Querying etherscan') | ||
const abi = await getAbi(network, address) | ||
fs.ensureDir(dirname(fullAbiPath)) | ||
fs.write(fullAbiPath, JSON.stringify(abi)) | ||
await fs.ensureDir(dirname(fullAbiPath)) | ||
await fs.write(fullAbiPath, JSON.stringify(abi)) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { Address } from '../sdk-def' | ||
import { Address } from '../config' | ||
|
||
export type GetAbi = (network: string, address: Address) => Promise<Object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.