Skip to content

Commit

Permalink
Showing 277 changed files with 5,494 additions and 6,723 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module.exports = {
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
rules: {
'max-len': ['error', { code: 120, ignoreUrls: true }],
'max-len': ['error', { code: 120, ignoreUrls: true, ignoreStrings: true, ignorePattern: 'class [a-zA-Z]+' }],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },
],
},
};
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@ jobs:
run: yarn install

- name: Run e2e test
run: yarn hardhat test
run: yarn test:e2e
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@ jobs:
run: yarn install

- name: Run unit test
run: yarn test src/**/*.ts
run: yarn test:unit
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.log
.DS_Store
node_modules
dist
tmp
cache
dist/*
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,32 +4,25 @@
[![Unit Test](https://github.com/dinngodev/protocol-logics/actions/workflows/unit-test.yml/badge.svg)](https://github.com/dinngodev/protocol-logics/actions/workflows/unit-test.yml)
[![E2E Test](https://github.com/dinngodev/protocol-logics/actions/workflows/e2e-test.yml/badge.svg)](https://github.com/dinngodev/protocol-logics/actions/workflows/e2e-test.yml)

An SDK that build protocol logics for Composable Router
SDK that build protocol logics for Composable Router

## CLI

- Generate core, router or protocol's abi TypeScript classes
- Generate protocol's abi TypeScript classes

```sh
# core
# - abi files: src/core/abis/*.json
# - contracts dir: src/core/contracts
# router
# - abi files: src/router/abis/*.json
# - contracts dir: src/router/contracts
# protocols
# - abi files: src/protocols/{protocol}/abis/*.json
# - contracts dir: src/protocols/{protocol}/contracts
yarn cli typechain
```

- Run core, router or protocol's tests
- Run protocol's tests

```sh
yarn cli test
```

- Run core, router or protocol's script
- Run protocol's script

```sh
yarn cli script
18 changes: 5 additions & 13 deletions cli/cmds/script.ts
Original file line number Diff line number Diff line change
@@ -8,26 +8,18 @@ export const command = 'script';
export const describe = "Execute core or protocol's script";

export async function handler() {
// 1. choose category
const { category } = await prompts.categoryPrompt('Whose script do you want to execute?');
// 1. get paths
const { protocol } = await prompts.protocolPrompt();
const scriptsPath = path.join(process.cwd(), 'src', 'protocols', protocol, 'scripts');

// 2. get paths
const dirs = [process.cwd(), 'src', category];
if (category === 'protocols') {
const { protocol } = await prompts.protocolPrompt();
dirs.push(protocol);
}
const rootPath = path.join(...dirs);
const scriptsPath = path.join(rootPath, 'scripts');

// 3. get scripts
// 2. get scripts
const scriptFiles = glob.sync('*.ts', { cwd: scriptsPath, dot: true });
if (scriptFiles.length === 0) {
console.log('No script files.');
return;
}

// 4. execute script
// 3. execute script
const { scriptFile } = await inquirer.prompt<{ scriptFile: string }>([
{
name: 'scriptFile',
15 changes: 4 additions & 11 deletions cli/cmds/test.ts
Original file line number Diff line number Diff line change
@@ -8,18 +8,11 @@ export const command = 'test';
export const describe = "Run core or protocol's tests";

export const handler = async () => {
// 1. choose category
const { category } = await prompts.categoryPrompt('Whose tests do you want to run?');
// 1. get root path
const { protocol } = await prompts.protocolPrompt();
const rootPath = path.join('src', 'protocols', protocol);

// 2. get root path
const dirs = ['src', category];
if (category === 'protocols') {
const { protocol } = await prompts.protocolPrompt();
dirs.push(protocol);
}
const rootPath = path.join(...dirs);

// 3. run test
// 2. run test
const mocha = new Mocha({ timeout: 30000 });
mocha.files = glob(rootPath, ['**/*.ts']);
mocha.run((failures) => {
17 changes: 5 additions & 12 deletions cli/cmds/typechain.ts
Original file line number Diff line number Diff line change
@@ -11,22 +11,15 @@ export const describe = "Generate core or protocol's abis TypeScript classes";
const outDir = 'contracts';

export async function handler() {
// 1. choose category
const { category } = await prompts.categoryPrompt('Whose abis do you want to typechain?');

// 2. get paths
const dirs = [process.cwd(), 'src', category];
if (category === 'protocols') {
const { protocol } = await prompts.protocolPrompt();
dirs.push(protocol);
}
const rootPath = path.join(...dirs);
// 1. get paths
const { protocol } = await prompts.protocolPrompt();
const rootPath = path.join(process.cwd(), 'src', 'protocols', protocol);
const contractsPath = path.join(rootPath, outDir);

// 3. remove old contracts dir
// 2. remove old contracts dir
fs.removeSync(contractsPath);

// 4. run typechain
// 3. run typechain
const allFiles = glob(rootPath, ['abis/*.json']);
if (allFiles.length === 0) {
console.log('No files passed.');
2 changes: 1 addition & 1 deletion cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'hardhat';
import '@typechain/hardhat';
import '@nomicfoundation/hardhat-chai-matchers';

import inquirer from 'inquirer';
import inquirerAutocomplete from 'inquirer-autocomplete-prompt';
11 changes: 0 additions & 11 deletions cli/prompts.ts
Original file line number Diff line number Diff line change
@@ -2,17 +2,6 @@ import fs from 'fs-extra';
import inquirer from 'inquirer';
import path from 'path';

export async function categoryPrompt(message: string) {
return inquirer.prompt<{ category: string }>([
{
name: 'category',
type: 'list',
message,
choices: ['core', 'router', 'protocols'],
},
]);
}

export async function protocolPrompt() {
const cwd = process.cwd();
const protocols = fs
10 changes: 7 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@nomicfoundation/hardhat-chai-matchers';
import '@typechain/hardhat';
import 'test/chai-matchers';

import { HardhatUserConfig } from 'hardhat/config';
import { deployContracts } from 'test/hooks';
import { revert, snapshot } from '@composable-router/test-helpers';

const config: HardhatUserConfig = {
solidity: {
@@ -29,7 +29,11 @@ const config: HardhatUserConfig = {
},
},
},
mocha: { timeout: 1200000 },
mocha: {
timeout: 1200000,
retries: 3,
rootHooks: { beforeAll: [deployContracts], beforeEach: [snapshot], afterEach: [revert] },
},
};

export default config;
31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -8,37 +8,40 @@
"repository": "https://github.com/dinngodev/protocol-logics.git",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"source": "src/index.ts",
"typings": "dist/index.d.ts",
"types": "dist/index.d.ts",
"files": [
"dist"
"dist/**/*"
],
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts",
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
"cli": "ts-node cli/index.ts",
"format": "pretty-quick && yarn sort-package-json",
"lint": "eslint --fix src",
"prepublishOnly": "yarn build",
"test": "mocha",
"cli": "ts-node cli/index.ts"
"test:e2e": "hardhat test",
"test:unit": "mocha --recursive src"
},
"dependencies": {
"@paraswap/sdk": "^6.1.2",
"@types/lodash": "^4.14.191",
"@uniswap/permit2-sdk": "^1.2.0",
"axios": "^1.2.6",
"axios": "^1.3.4",
"axios-retry": "^3.4.0",
"bignumber.js": "^9.1.1",
"ethers": "^5.7.2",
"lodash": "^4.17.21",
"tiny-invariant": "^1.3.1"
"tiny-invariant": "^1.3.1",
"type-fest": "^3.6.0"
},
"devDependencies": {
"@composable-router/common": "file:./packages/common",
"@composable-router/core": "file:./packages/core",
"@composable-router/test-helpers": "file:./packages/test-helpers",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@typechain/ethers-v5": "^10.2.0",
"@typechain/hardhat": "^6.1.5",
"@types/chai": "^4.3.4",
"@types/fs-extra": "^11.0.1",
"@types/glob": "^8.0.1",
@@ -49,8 +52,8 @@
"@types/pretty-quick": "^3.1.1",
"@types/sinon": "^10.0.13",
"@types/yargs": "^17.0.22",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"chai": "^4.3.7",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
@@ -67,13 +70,13 @@
"sinon": "^15.0.1",
"sort-package-json": "^2.4.1",
"ts-node": "^10.9.1",
"tsc-alias": "^1.8.2",
"tsconfig-paths": "^4.1.2",
"tsup": "^6.6.2",
"typechain": "^8.1.1",
"typescript": "^4.9.5",
"yargs": "^17.6.2"
"yargs": "^17.7.1"
},
"engines": {
"node": ">=14"
"node": ">=16"
}
}
1 change: 1 addition & 0 deletions packages/common/dist/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const BPS_BASE = 10000;
5 changes: 5 additions & 0 deletions packages/common/dist/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/common/dist/constants.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5532368

Please sign in to comment.