Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: add runtime + types folders #119

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/position-pricing-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions scripts/getPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <address>')
Expand Down
2 changes: 1 addition & 1 deletion scripts/getShortcuts.ts
Original file line number Diff line number Diff line change
@@ -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]')
Expand Down
2 changes: 1 addition & 1 deletion scripts/triggerShortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions src/apps/halofi/positions.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/apps/locked-celo/positions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { PositionsHook, ContractPositionDefinition } from '../../positions'
import {
PositionsHook,
ContractPositionDefinition,
} from '../../types/positions'
import {
Address,
ContractFunctionExecutionError,
Expand All @@ -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'
Expand Down
7 changes: 5 additions & 2 deletions src/apps/moola/positions.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
4 changes: 2 additions & 2 deletions src/apps/ubeswap/positions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/apps/ubeswap/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 0 additions & 4 deletions src/data.json

This file was deleted.

7 changes: 0 additions & 7 deletions src/index.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/index.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/getHooks.ts → src/runtime/getHooks.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -15,7 +15,7 @@ const APP_ID_PATTERN = /^[a-zA-Z0-9-]+$/

async function getAllAppIds(): Promise<string[]> {
// 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())
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function getHooks<T extends HookTypeName>(

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') {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/getPositions.ts → src/runtime/getPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.