generated from dev-protocol/template-repos-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
15 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
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,33 @@ | ||
import { ethereum } from '../util/endpoint' | ||
import { bent } from '../_lib/_defaultExport' | ||
import { call } from '@devprotocol/khaos-functions' | ||
import { PromiseValue } from 'type-fest' | ||
import { PromiseValue, SetOptional, Merge } from 'type-fest' | ||
import { Event } from '@ethersproject/contracts' | ||
|
||
const _pack = call()({ | ||
method: 'pack', | ||
options: { results: { status: 0, statusMessage: '', message: '' } }, | ||
}) | ||
|
||
export type KhaosEmulateOptions = Readonly< | ||
Record<string, string | number | boolean> | ||
> | ||
type ArgsWrap = { | ||
readonly args: Record<string, string | number | undefined | null> | ||
} | ||
|
||
type MergedEvent = Merge<Event, ArgsWrap> | ||
|
||
export type KhaosEmulateOptions = { | ||
readonly event: SetOptional<MergedEvent, keyof MergedEvent> | ||
} | ||
|
||
export type KhaosEmulateResponse = PromiseValue<typeof _pack> | ||
|
||
export const emulate = ( | ||
id: string, | ||
network: keyof typeof ethereum = 'mainnet' | ||
): ((options: KhaosEmulateOptions) => Promise<PromiseValue<typeof _pack>>) => { | ||
): ((options: KhaosEmulateOptions) => Promise<KhaosEmulateResponse>) => { | ||
const fetcher = bent(`${ethereum[network]}/emulate/${id}`, 'POST', 'json') | ||
return (options: KhaosEmulateOptions): typeof _pack => | ||
fetcher('/', options).then( | ||
(r) => (r as unknown) as PromiseValue<typeof _pack> | ||
return (options: KhaosEmulateOptions): Promise<KhaosEmulateResponse> => | ||
fetcher('/', { ...options, ...{ network } }).then( | ||
(r) => (r as unknown) as KhaosEmulateResponse | ||
) | ||
} |