Skip to content

Commit

Permalink
Merge pull request #10 from RoboVault/fix/event-types
Browse files Browse the repository at this point in the history
fix event type
  • Loading branch information
hazelnutcloud authored Jun 30, 2023
2 parents df00f4f + 6798144 commit 009eafc
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 98 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# v0.4.15
- feat: populate relational entities on graphql endpoint
- feat: add overload to `manifest.addChain` and `chain.addContract` functions to pass in a callback function that takes in a DataSourceBuilder and ContractBuilder instance respectively
- feat: remove svn as a dependancy to run `arkiver init` command
- change: deprecate `manifest.chain` for `manifest.addChain`
- change: deprecate `manifest.contract` for `manifest.addContract`
- change: `transactionIndex` and `logIndex` field in event is now number type to align with viem's return types
- fix: missing event handler types due to updates to `viem` package

# v0.4.14
Expand Down
5 changes: 2 additions & 3 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ command
// init
command
.command('init', 'Initialize a new arkive project')
.option('--overwrite', 'Overwrite existing files')
.action(async (opts, ...args) => {
.action(async () => {
util.logHeader(version)
await checkVersion(version)
await init.action(opts, ...args)
await init.action()
})

// upgrade
Expand Down
103 changes: 68 additions & 35 deletions cli/init/mod.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { $, Input, join, prompt, Select, Toggle, wait } from '../deps.ts'
import { $, Input, join, prompt, Select, Toggle } from '../deps.ts'

export const action = async (
options: { overwrite?: boolean },
) => {
let spinner = wait('Fetching templates...').start()
export const action = async () => {
let pb = $.progress('Fetching templates...')

const templatesRes = await fetch(
'https://api.github.com/repos/RoboVault/robo-arkiver/contents/examples',
)
let templatesRes: Response

if (!templatesRes.ok) {
console.log('Error fetching templates')
await pb.with(async () => {
templatesRes = await fetch(
'https://api.github.com/repos/RoboVault/robo-arkiver/contents/examples',
)
})

if (!templatesRes!.ok) {
console.log('Error fetching templates: ', templatesRes!.statusText)
return
}

const templates = await templatesRes.json() as {
const templates = await templatesRes!.json() as {
name: string
type: string
}[]
Expand All @@ -28,8 +30,6 @@ export const action = async (
name: t.name,
}))

spinner.stop()

const defaultPath = './cool-new-arkive'

const arkive = await prompt([
Expand Down Expand Up @@ -62,31 +62,64 @@ export const action = async (
const newDir = join(Deno.cwd(), arkive.dir ?? defaultPath)
const template = arkive.template ?? templateNames[0].value

spinner = wait('Initializing arkive...').start()
pb = $.progress('Initializing arkive...')

const initRes = await $`svn export ${
options.overwrite ? `--force ` : ''
}https://github.com/RoboVault/robo-arkiver/trunk/examples/${template} ${newDir}`
.captureCombined(true)
try {
await $`git init ${newDir} && cd ${newDir} && git config core.sparseCheckout true`
.quiet('both')

if (initRes.code !== 0) {
spinner.fail(`Error initializing arkive: ${initRes.stderr}`)
return
}

if (arkive.vscode) {
const dir = arkive.dir ?? defaultPath
await Deno.mkdir(join(Deno.cwd(), dir, '.vscode'))

const vscode = `{
"deno.enable": true,
"deno.unstable": true
}`
await Deno.writeTextFile(
join(Deno.cwd(), dir, '.vscode', 'settings.json'),
vscode,
await Deno.writeFile(
join(newDir, '.git', 'info', 'sparse-checkout'),
new TextEncoder().encode(`examples/${template}`),
)

await $`git remote add origin https://github.com/RoboVault/robo-arkiver && git pull origin main && rm -rf .git`
.cwd(newDir)
.quiet('stdout')

// traverse the template directory and move all files to the root
for await (
const entry of Deno.readDir(join(newDir, `examples/${template}`))
) {
const source = join(newDir, `examples/${template}`, entry.name)
const destination = join(newDir, entry.name)
await Deno.rename(source, destination)
}

await Deno.remove(join(newDir, 'examples'), { recursive: true })

if (arkive.vscode) {
const dir = arkive.dir ?? defaultPath
await Deno.mkdir(join(Deno.cwd(), dir, '.vscode'))

const vscode = `{
"deno.enable": true,
"deno.unstable": true
}`
await Deno.writeTextFile(
join(Deno.cwd(), dir, '.vscode', 'settings.json'),
vscode,
)

const gitignore = `/.vscode
/.vscode/*
/.vscode/**/*
`
await Deno.writeTextFile(
join(Deno.cwd(), dir, '.gitignore'),
gitignore,
)
}

await $`git init && git add . && git commit -m "Initial commit"`
.cwd(newDir)
.quiet('stdout')
} catch (e) {
$.logError(`Error initializing arkive: ${e}`)
return
}

spinner.succeed('Initialized arkive')
// spinner.succeed('Initialized arkive')
pb.finish()
$.logStep('Initialized arkive')
}
2 changes: 1 addition & 1 deletion examples/block-handler-vaults/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export {
createEntity,
type EventHandlerFor,
Manifest,
} from 'https://deno.land/x/[email protected].14/mod.ts'
} from 'https://deno.land/x/[email protected].15/mod.ts'
2 changes: 1 addition & 1 deletion examples/block-handler-vaults/handlers/vault.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatUnits, getContract } from 'npm:viem'
import { type BlockHandler } from 'https://deno.land/x/[email protected].14/mod.ts'
import { type BlockHandler } from 'https://deno.land/x/[email protected].15/mod.ts'
import { VaultSnapshot } from '../entities/vault.ts'
import { YearnV2Abi } from '../abis/YearnV2.ts'

Expand Down
4 changes: 2 additions & 2 deletions examples/block-handler-vaults/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Manifest } from 'https://deno.land/x/[email protected].14/mod.ts'
import { Manifest } from 'https://deno.land/x/[email protected].15/mod.ts'
import { VaultSnapshot } from './entities/vault.ts'
import { snapshotVault } from './handlers/vault.ts'

const manifest = new Manifest('yearn-vaults')

manifest
.addEntity(VaultSnapshot)
.chain('mainnet')
.addChain('mainnet')
.addBlockHandler({
blockInterval: 1000,
startBlockHeight: 12790000n,
Expand Down
2 changes: 1 addition & 1 deletion examples/erc20-balance-history/entities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createEntity } from 'https://deno.land/x/[email protected].14/mod.ts'
import { createEntity } from 'https://deno.land/x/[email protected].15/mod.ts'

// @note: "Index: true" enhances graphql queries

Expand Down
2 changes: 1 addition & 1 deletion examples/erc20-balance-history/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatUnits } from 'npm:viem'
import { type EventHandlerFor } from 'https://deno.land/x/[email protected].14/mod.ts'
import { type EventHandlerFor } from 'https://deno.land/x/[email protected].15/mod.ts'
import erc20 from './erc20.ts'
import { Balance, BalanceHistory, Transfer } from './entities.ts'

Expand Down
6 changes: 3 additions & 3 deletions examples/erc20-balance-history/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Manifest } from 'https://deno.land/x/[email protected].14/mod.ts'
import { Manifest } from 'https://deno.land/x/[email protected].15/mod.ts'
import erc20 from './erc20.ts'
import { Entities } from './entities.ts'
import { onTransfer } from './handlers.ts'
Expand All @@ -7,8 +7,8 @@ const manifest = new Manifest('frax-balances')

manifest
.addEntities(Entities)
.chain('mainnet', { blockRange: 500n })
.contract(erc20)
.addChain('mainnet', { blockRange: 500n })
.addContract(erc20)
.addSources({ '0x853d955aCEf822Db058eb8505911ED77F175b99e': 11465581n })
.addEventHandlers({ 'Transfer': onTransfer })

Expand Down
2 changes: 1 addition & 1 deletion examples/erc20-events/entities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createEntity } from 'https://deno.land/x/[email protected].14/mod.ts'
import { createEntity } from 'https://deno.land/x/[email protected].15/mod.ts'

// @note: "Index: true" enhances graphql queries
export const Transfer = createEntity('Transfer', {
Expand Down
2 changes: 1 addition & 1 deletion examples/erc20-events/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatUnits } from 'npm:viem'
import { type EventHandlerFor } from 'https://deno.land/x/[email protected].14/mod.ts'
import { type EventHandlerFor } from 'https://deno.land/x/[email protected].15/mod.ts'
import erc20 from './erc20.ts'
import { Approval, Transfer } from './entities.ts'

Expand Down
6 changes: 3 additions & 3 deletions examples/erc20-events/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Manifest } from 'https://deno.land/x/[email protected].14/mod.ts'
import { Manifest } from 'https://deno.land/x/[email protected].15/mod.ts'
import erc20 from './erc20.ts'
import { Approval, Transfer } from './entities.ts'
import { onApproval, onTransfer } from './handlers.ts'
Expand All @@ -7,8 +7,8 @@ const manifest = new Manifest('weth-events')

manifest
.addEntities([Transfer, Approval])
.chain('mainnet', { blockRange: 500n })
.contract('ERC20', erc20)
.addChain('mainnet', { blockRange: 500n })
.addContract('ERC20', erc20)
.addSources({ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2': 4729568n })
.addEventHandlers({ 'Transfer': onTransfer })
.addEventHandlers({ 'Approval': onApproval })
Expand Down
2 changes: 1 addition & 1 deletion examples/event-wildcard/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export {
createEntity,
type EventHandlerFor,
Manifest,
} from 'https://deno.land/x/[email protected].14/mod.ts'
} from 'https://deno.land/x/[email protected].15/mod.ts'
4 changes: 2 additions & 2 deletions examples/event-wildcard/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { transferHandler } from './handlers/transfer.ts'
const manifest = new Manifest('agnostic-events')

manifest
.chain('avalanche', { blockRange: 100n })
.contract('ERC20', erc20)
.addChain('avalanche', { blockRange: 100n })
.addContract('ERC20', erc20)
.addSources({ '*': 27347402n })
.addEventHandlers({ 'Transfer': transferHandler })

Expand Down
2 changes: 1 addition & 1 deletion examples/simple/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export {
createEntity,
type EventHandlerFor,
Manifest,
} from 'https://deno.land/x/[email protected].14/mod.ts'
} from 'https://deno.land/x/[email protected].15/mod.ts'
4 changes: 2 additions & 2 deletions examples/simple/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const manifest = new Manifest('simple')

manifest
.addEntity(Balance)
.chain('mainnet', { blockRange: 100n })
.contract('ERC20', erc20)
.addChain('mainnet', { blockRange: 100n })
.addContract('ERC20', erc20)
.addSources({ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2': 16987011n })
.addEventHandlers({ 'Transfer': transferHandler })

Expand Down
6 changes: 3 additions & 3 deletions src/arkiver/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class DataSource extends EventTarget {
this.contracts = params.contracts
this.blockSources = params.blockSources
this.client = createPublicClient({
chain: getChainObjFromChainName(this.chain),
chain: getChainObjFromChainName(this.chain) as any,
transport: http(this.rpcUrl),
})
this.arkiveId = params.arkiveId
Expand Down Expand Up @@ -587,7 +587,7 @@ export class DataSource extends EventTarget {
eventName: event.eventName,
client: this.client,
store: this.store,
event: formatLog(log, event),
event: formatLog(log, event as any),
contract: getContract({
abi: handler.abi,
address: log.address,
Expand Down Expand Up @@ -682,7 +682,7 @@ export class DataSource extends EventTarget {
eventName: event.eventName,
client: this.client,
store: this.store,
event: formatLog(log, event),
event: formatLog(log, event as any),
contract: getContract({
abi: eventHandler.abi,
address: log.address,
Expand Down
Loading

1 comment on commit 009eafc

@vercel
Copy link

@vercel vercel bot commented on 009eafc Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.