From 9a58fd5c241f951bd4d99cc9c72048f57ff5b402 Mon Sep 17 00:00:00 2001 From: Jean Regisser Date: Tue, 4 Jul 2023 16:10:09 +0200 Subject: [PATCH 1/2] refactor!: add runtime + types folders --- docs/position-pricing-hooks.md | 2 +- scripts/getPositions.ts | 4 ++-- scripts/getShortcuts.ts | 2 +- scripts/triggerShortcut.ts | 2 +- src/apps/halofi/positions.ts | 4 ++-- src/apps/locked-celo/positions.ts | 7 +++++-- src/apps/moola/positions.ts | 7 +++++-- src/apps/ubeswap/positions.ts | 4 ++-- src/apps/ubeswap/shortcuts.ts | 2 +- src/data.json | 4 ---- src/index.test.ts | 7 ------- src/index.ts | 3 --- src/{ => runtime}/getHooks.ts | 4 ++-- src/{ => runtime}/getPositions.e2e.ts | 0 src/{ => runtime}/getPositions.ts | 6 +++--- src/{ => runtime}/getShortcuts.e2e.ts | 0 src/{ => runtime}/getShortcuts.ts | 0 src/{ => types}/numbers.ts | 0 src/{ => types}/positions.ts | 0 src/{ => types}/shortcuts.ts | 0 20 files changed, 25 insertions(+), 33 deletions(-) delete mode 100644 src/data.json delete mode 100644 src/index.test.ts delete mode 100644 src/index.ts rename src/{ => runtime}/getHooks.ts (94%) rename src/{ => runtime}/getPositions.e2e.ts (100%) rename src/{ => runtime}/getPositions.ts (99%) rename src/{ => runtime}/getShortcuts.e2e.ts (100%) rename src/{ => runtime}/getShortcuts.ts (100%) rename src/{ => types}/numbers.ts (100%) rename src/{ => types}/positions.ts (100%) rename src/{ => types}/shortcuts.ts (100%) diff --git a/docs/position-pricing-hooks.md b/docs/position-pricing-hooks.md index 7e145e58..4a62b95d 100644 --- a/docs/position-pricing-hooks.md +++ b/docs/position-pricing-hooks.md @@ -25,7 +25,7 @@ From the information provided by the hook, Valora can show the user the value of Hooks are organized by application. For instance Ubeswap hooks are located in [`https://github.com/valora-inc/hooks/tree/main/src/apps/ubeswap`](https://github.com/valora-inc/hooks/tree/main/src/apps/ubeswap). -Position pricing hooks must implement the [`PositionsHook`](https://github.com/valora-inc/hooks/blob/main/src/positions.ts) TypeScript interface. +Position pricing hooks must implement the [`PositionsHook`](https://github.com/valora-inc/hooks/blob/main/src/types/positions.ts) TypeScript interface. ### Creating a Position Pricing Hook diff --git a/scripts/getPositions.ts b/scripts/getPositions.ts index cc44093f..8063651d 100644 --- a/scripts/getPositions.ts +++ b/scripts/getPositions.ts @@ -2,8 +2,8 @@ /* eslint-disable no-console */ import yargs from 'yargs' import BigNumber from 'bignumber.js' -import { Token } from '../src/positions' -import { getPositions } from '../src/getPositions' +import { Token } from '../src/types/positions' +import { getPositions } from '../src/runtime/getPositions' const argv = yargs(process.argv.slice(2)) .usage('Usage: $0 --address
') diff --git a/scripts/getShortcuts.ts b/scripts/getShortcuts.ts index 8483a017..624a0bfc 100644 --- a/scripts/getShortcuts.ts +++ b/scripts/getShortcuts.ts @@ -1,7 +1,7 @@ // Helper script to get the shortcuts /* eslint-disable no-console */ import yargs from 'yargs' -import { getShortcuts } from '../src/getShortcuts' +import { getShortcuts } from '../src/runtime/getShortcuts' const argv = yargs(process.argv.slice(2)) .usage('Usage: $0 --apps app1[,app2]') diff --git a/scripts/triggerShortcut.ts b/scripts/triggerShortcut.ts index 38b90b64..3db68c34 100644 --- a/scripts/triggerShortcut.ts +++ b/scripts/triggerShortcut.ts @@ -4,7 +4,7 @@ import yargs from 'yargs' import { Address, createWalletClient, http, createPublicClient } from 'viem' import { mnemonicToAccount } from 'viem/accounts' import { celo } from 'viem/chains' -import { getShortcuts } from '../src/getShortcuts' +import { getShortcuts } from '../src/runtime/getShortcuts' const CELO_DERIVATION_PATH = "m/44'/52752'/0'/0/0" diff --git a/src/apps/halofi/positions.ts b/src/apps/halofi/positions.ts index 57936cc1..a4498c33 100644 --- a/src/apps/halofi/positions.ts +++ b/src/apps/halofi/positions.ts @@ -1,10 +1,10 @@ import BigNumber from 'bignumber.js' -import { DecimalNumber } from '../../numbers' +import { DecimalNumber } from '../../types/numbers' import { PositionsHook, ContractPositionDefinition, TokenDefinition, -} from '../../positions' +} from '../../types/positions' import got from 'got' // User-Agent header is required by the HaloFi API diff --git a/src/apps/locked-celo/positions.ts b/src/apps/locked-celo/positions.ts index 65c200f0..527b1b12 100644 --- a/src/apps/locked-celo/positions.ts +++ b/src/apps/locked-celo/positions.ts @@ -1,4 +1,7 @@ -import { PositionsHook, ContractPositionDefinition } from '../../positions' +import { + PositionsHook, + ContractPositionDefinition, +} from '../../types/positions' import { Address, ContractFunctionExecutionError, @@ -7,7 +10,7 @@ import { } from 'viem' import { celo } from 'viem/chains' import { LockedGoldAbi } from './abis/locked-gold' -import { toDecimalNumber } from '../../numbers' +import { toDecimalNumber } from '../../types/numbers' const CELO_ADDRESS = '0x471ece3750da237f93b8e339c536989b8978a438' const LOCKED_GOLD_ADDRESS = '0x6cc083aed9e3ebe302a6336dbc7c921c9f03349e' diff --git a/src/apps/moola/positions.ts b/src/apps/moola/positions.ts index c4e44246..6641014a 100644 --- a/src/apps/moola/positions.ts +++ b/src/apps/moola/positions.ts @@ -1,8 +1,11 @@ -import { PositionsHook, AppTokenPositionDefinition } from '../../positions' +import { + PositionsHook, + AppTokenPositionDefinition, +} from '../../types/positions' import { Address, createPublicClient, http } from 'viem' import { celo } from 'viem/chains' import { erc20Abi } from '../../abis/erc-20' -import { DecimalNumber } from '../../numbers' +import { DecimalNumber } from '../../types/numbers' import BigNumber from 'bignumber.js' import { DebtTokenDefinition, MOOLA_DEBT_TOKENS } from './debtTokens' diff --git a/src/apps/ubeswap/positions.ts b/src/apps/ubeswap/positions.ts index 4440d204..d7406cf1 100644 --- a/src/apps/ubeswap/positions.ts +++ b/src/apps/ubeswap/positions.ts @@ -5,14 +5,14 @@ import { ContractPositionDefinition, PositionDefinition, TokenDefinition, -} from '../../positions' +} from '../../types/positions' import got from 'got' import BigNumber from 'bignumber.js' import { uniswapV2PairAbi } from './abis/uniswap-v2-pair' import { Address, createPublicClient, http } from 'viem' import { celo } from 'viem/chains' import { erc20Abi } from '../../abis/erc-20' -import { DecimalNumber, toDecimalNumber } from '../../numbers' +import { DecimalNumber, toDecimalNumber } from '../../types/numbers' import { stakingRewardsAbi } from './abis/staking-rewards' import farms from './data/farms.json' diff --git a/src/apps/ubeswap/shortcuts.ts b/src/apps/ubeswap/shortcuts.ts index 768843d3..a596c325 100644 --- a/src/apps/ubeswap/shortcuts.ts +++ b/src/apps/ubeswap/shortcuts.ts @@ -1,6 +1,6 @@ import { Address, createPublicClient, http, encodeFunctionData } from 'viem' import { celo } from 'viem/chains' -import { ShortcutsHook } from '../../shortcuts' +import { ShortcutsHook } from '../../types/shortcuts' import { stakingRewardsAbi } from './abis/staking-rewards' const client = createPublicClient({ diff --git a/src/data.json b/src/data.json deleted file mode 100644 index 055124f5..00000000 --- a/src/data.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "some": "data", - "important": true -} diff --git a/src/index.test.ts b/src/index.test.ts deleted file mode 100644 index ff94e55f..00000000 --- a/src/index.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { main } from './index' - -describe(main, () => { - it("should return 'Hello, world!'", () => { - expect(main()).toBe('Hello, world!') - }) -}) diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 4b321d0a..00000000 --- a/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function main() { - return 'Hello, world!' -} diff --git a/src/getHooks.ts b/src/runtime/getHooks.ts similarity index 94% rename from src/getHooks.ts rename to src/runtime/getHooks.ts index e068c34d..51bd77e9 100644 --- a/src/getHooks.ts +++ b/src/runtime/getHooks.ts @@ -1,7 +1,7 @@ import { promises as fs } from 'fs' import path from 'path' -import { PositionsHook } from './positions' -import { ShortcutsHook } from './shortcuts' +import { PositionsHook } from '../types/positions' +import { ShortcutsHook } from '../types/shortcuts' type HookTypeName = 'positions' | 'shortcuts' diff --git a/src/getPositions.e2e.ts b/src/runtime/getPositions.e2e.ts similarity index 100% rename from src/getPositions.e2e.ts rename to src/runtime/getPositions.e2e.ts diff --git a/src/getPositions.ts b/src/runtime/getPositions.ts similarity index 99% rename from src/getPositions.ts rename to src/runtime/getPositions.ts index 39e6c31d..393aae74 100644 --- a/src/getPositions.ts +++ b/src/runtime/getPositions.ts @@ -9,7 +9,7 @@ import { http, } from 'viem' import { celo } from '@wagmi/chains' -import { erc20Abi } from './abis/erc-20' +import { erc20Abi } from '../abis/erc-20' import { AbstractToken, AppInfo, @@ -22,12 +22,12 @@ import { PositionDefinition, PricePerShareContext, Token, -} from './positions' +} from '../types/positions' import { DecimalNumber, toDecimalNumber, toSerializedDecimalNumber, -} from './numbers' +} from '../types/numbers' import { getHooks } from './getHooks' interface RawTokenInfo { diff --git a/src/getShortcuts.e2e.ts b/src/runtime/getShortcuts.e2e.ts similarity index 100% rename from src/getShortcuts.e2e.ts rename to src/runtime/getShortcuts.e2e.ts diff --git a/src/getShortcuts.ts b/src/runtime/getShortcuts.ts similarity index 100% rename from src/getShortcuts.ts rename to src/runtime/getShortcuts.ts diff --git a/src/numbers.ts b/src/types/numbers.ts similarity index 100% rename from src/numbers.ts rename to src/types/numbers.ts diff --git a/src/positions.ts b/src/types/positions.ts similarity index 100% rename from src/positions.ts rename to src/types/positions.ts diff --git a/src/shortcuts.ts b/src/types/shortcuts.ts similarity index 100% rename from src/shortcuts.ts rename to src/types/shortcuts.ts From f0c63f60d9f83c21f27a6c7539739d25e3342d16 Mon Sep 17 00:00:00 2001 From: Jean Regisser Date: Tue, 4 Jul 2023 16:17:40 +0200 Subject: [PATCH 2/2] Fix paths --- src/runtime/getHooks.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/getHooks.ts b/src/runtime/getHooks.ts index 51bd77e9..1a63d75a 100644 --- a/src/runtime/getHooks.ts +++ b/src/runtime/getHooks.ts @@ -15,7 +15,7 @@ const APP_ID_PATTERN = /^[a-zA-Z0-9-]+$/ async function getAllAppIds(): Promise { // Read all folders from the "apps" folder - const files = await fs.readdir(path.join(__dirname, 'apps'), { + const files = await fs.readdir(path.join(__dirname, '../apps'), { withFileTypes: true, }) const folders = files.filter((file) => file.isDirectory()) @@ -48,7 +48,7 @@ export async function getHooks( let hook: any try { - hook = await import(`./apps/${appId}/${hookType}`) + hook = await import(`../apps/${appId}/${hookType}`) } catch (e) { if (appIds.includes(appId)) { if ((e as any).code === 'MODULE_NOT_FOUND') {