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

Update effect to stable version #25

Merged
merged 2 commits into from
Jan 12, 2024
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
5 changes: 5 additions & 0 deletions .changeset/chilly-kangaroos-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@3loop/transaction-decoder": minor
---

Update Effect to stable version
8 changes: 5 additions & 3 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
"effect": "^2.0.0-next.27",
"effect": "^2.0.3",
"eslint": "^8.47.0",
"eslint-config-next": "13.4.19",
"ethers": "^6.6.2",
Expand All @@ -46,7 +46,9 @@
"usehooks-ts": "^2.9.1"
},
"devDependencies": {
"bufferutil": "^4.0.8",
"prisma": "^5.2.0",
"typescript": "5.1.3"
"typescript": "5.1.3",
"utf-8-validate": "^6.0.3"
}
}
}
4 changes: 2 additions & 2 deletions apps/web/src/app/tx/[chainID]/[hash]/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export default function DecodingForm({

const router = useRouter();

const onSubmit = (e) => {
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const hash = e.target.hash.value;
const hash = (e.target as any).hash.value;
router.push(`/tx/${currentChainID}/${hash}`);
};

Expand Down
10 changes: 4 additions & 6 deletions apps/web/src/components/ui/network-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ export function NetworkSelect(props: SelectProps) {
const router = useRouter();
const params = useParams();

const onValueChange = (newChainID) => {
const onValueChange = (newChainID: string) => {
router.push(`/tx/${newChainID}`);
};

const chainID = (params.chainID as string) ?? props.defaultValue;

return (
<Select
defaultValue={props.defaultValue}
onValueChange={onValueChange}
value={params.chainID as string}
>
<Select onValueChange={onValueChange} value={chainID}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select a network" />
</SelectTrigger>
Expand Down
24 changes: 10 additions & 14 deletions apps/web/src/lib/decode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Effect, Layer, pipe } from "effect";
import { Effect, Layer, Runtime, Scope, pipe } from "effect";
import { RPCProviderLive } from "./rpc-provider";
import {
decodeTransactionByHash,
Expand All @@ -7,13 +7,7 @@ import {
import { AbiStoreLive, ContractMetaStoreLive } from "./contract-loader";

const LoadersLayer = Layer.mergeAll(AbiStoreLive, ContractMetaStoreLive);
const MainLayer = Layer.provideMerge(RPCProviderLive, LoadersLayer);

const customRuntime = pipe(
Layer.toRuntime(MainLayer),
Effect.scoped,
Effect.runSync,
);
const MainLayer = LoadersLayer.pipe(Layer.provideMerge(RPCProviderLive));

export async function decodeTransaction({
chainID,
Expand All @@ -22,10 +16,12 @@ export async function decodeTransaction({
chainID: number;
hash: string;
}): Promise<DecodedTx | undefined> {
return decodeTransactionByHash(hash, chainID)
.pipe(Effect.provideSomeRuntime(customRuntime), Effect.runPromise)
.catch((error: unknown) => {
console.error("Decode error", JSON.stringify(error, null, 2));
return undefined;
});
const runnable = Effect.provide(
decodeTransactionByHash(hash, chainID),
MainLayer,
);
return Effect.runPromise(runnable).catch((error: unknown) => {
console.error("Decode error", JSON.stringify(error, null, 2));
return undefined;
});
}
4 changes: 4 additions & 0 deletions apps/web/src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { PrismaClient } from "@prisma/client";

let prisma: PrismaClient;

declare global {
var prisma: PrismaClient;
}

if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient();
} else {
Expand Down
13 changes: 7 additions & 6 deletions apps/web/src/lib/rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { JsonRpcProvider } from "ethers";
import { Layer, Effect } from "effect";
import { supportedChains } from "@/app/data";

const providerConfigs = supportedChains.reduce((acc, config) => {
return {
...acc,
[config.chainID]: config,
};
}, {});
const providerConfigs: Record<string, (typeof supportedChains)[number]> =
supportedChains.reduce((acc, config) => {
return {
...acc,
[config.chainID]: config,
};
}, {});

const providers: Record<number, RPCProviderObject> = {};

Expand Down
18 changes: 5 additions & 13 deletions apps/web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
{
"extends": "tsconfig/nextjs.json",
"compilerOptions": {
"exactOptionalPropertyTypes": false,
"strict": true,
"target": "ES2015",
"isolatedModules": true,
"downlevelIteration": true,
"exactOptionalPropertyTypes": false,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./src/*"
]
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
4 changes: 2 additions & 2 deletions packages/transaction-decoder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Requirements

- TypeScript 5.x
- `exactOptionalPropertyTypes` and `strict` enabled in your tsconfig.json
- `strict` enabled in your tsconfig.json

## Getting Started

Expand Down Expand Up @@ -182,7 +182,7 @@ const program = Effect.gen(function* (_) {

```ts
const customRuntime = pipe(Layer.toRuntime(MainLayer), Effect.scoped, Effect.runSync)
const result = await program.pipe(Effect.provideSomeRuntime(customRuntime), Effect.runPromise)
const result = await program.pipe(Effect.provide(customRuntime), Effect.runPromise)
```

## ABI Strategies
Expand Down
8 changes: 4 additions & 4 deletions packages/transaction-decoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@
"README.md"
],
"peerDependencies": {
"@effect/schema": "^0.33.2",
"effect": "^2.0.0-next.31",
"@effect/schema": "^0.59.1",
"effect": "^2.0.3",
"ethers": "^6.6.2",
"jsonata": "^2.0.3"
},
"devDependencies": {
"@effect/schema": "^0.33.2",
"@effect/schema": "^0.59.1",
"@total-typescript/ts-reset": "^0.5.1",
"@types/node": "^20.6.0",
"@types/traverse": "^0.6.35",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"@vitest/coverage-v8": "0.34.2",
"effect": "2.0.0-next.31",
"effect": "2.0.3",
"eslint": "^8.49.0",
"eslint-config-custom": "workspace:*",
"eslint-config-prettier": "^8.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function fetchContractABI(
}

export const BlockscoutStrategyResolver = (config: { apikey?: string; endpoint: string }) =>
RequestResolver.fromFunctionEffect((req: RequestModel.GetContractABIStrategy) =>
RequestResolver.fromEffect((req: RequestModel.GetContractABIStrategy) =>
Effect.tryPromise({
try: () => fetchContractABI(req, config),
catch: () => new RequestModel.ResolveStrategyABIError('Blockscout', req.address, req.chainID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function fetchContractABI(
}

export const EtherscanStrategyResolver = (config?: { apikey?: string; endpoint?: string }) =>
RequestResolver.fromFunctionEffect((req: RequestModel.GetContractABIStrategy) =>
RequestResolver.fromEffect((req: RequestModel.GetContractABIStrategy) =>
Effect.tryPromise({
try: () => fetchContractABI(req, config),
catch: () => new RequestModel.ResolveStrategyABIError('etherscan', req.address, req.chainID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function fetchABI({
}

export const FourByteStrategyResolver = () =>
RequestResolver.fromFunctionEffect((req: RequestModel.GetContractABIStrategy) =>
RequestResolver.fromEffect((req: RequestModel.GetContractABIStrategy) =>
Effect.tryPromise({
try: () => fetchABI(req),
catch: () => new RequestModel.ResolveStrategyABIError('4byte.directory', req.address, req.chainID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function fetchABI({
}

export const OpenchainStrategyResolver = () =>
RequestResolver.fromFunctionEffect((req: RequestModel.GetContractABIStrategy) =>
RequestResolver.fromEffect((req: RequestModel.GetContractABIStrategy) =>
Effect.tryPromise({
try: () => fetchABI(req),
catch: () => new RequestModel.ResolveStrategyABIError('openchain', req.address, req.chainID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function fetchContractABI({ address, chainID }: RequestModel.GetContractAB
}

export const SourcifyStrategyResolver = () =>
RequestResolver.fromFunctionEffect((req: RequestModel.GetContractABIStrategy) =>
RequestResolver.fromEffect((req: RequestModel.GetContractABIStrategy) =>
Effect.tryPromise({
try: () => fetchContractABI(req),
catch: () => new RequestModel.ResolveStrategyABIError('sourcify', req.address, req.chainID),
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-decoder/src/decoding/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface GetStorageSlot extends Request.Request<RPCFetchError | UnknownN

export const GetStorageSlot = Request.tagged<GetStorageSlot>('GetStorageSlot')

export const GetStorageSlotResolver = RequestResolver.fromFunctionEffect((request: GetStorageSlot) =>
export const GetStorageSlotResolver = RequestResolver.fromEffect((request: GetStorageSlot) =>
Effect.gen(function* (_) {
const service = yield* _(RPCProvider)
const { provider } = yield* _(service.getProvider(request.chainID))
Expand Down
17 changes: 9 additions & 8 deletions packages/transaction-decoder/src/schema/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import * as Schema from '@effect/schema/Schema'
const CallType = Schema.literal('call', 'delegatecall', 'callcode', 'staticcall')

const Address = Schema.string // NOTE: Probably we can use a branded type
const bigintFromString = Schema.transform(

export const bigintFromString: Schema.Schema<string, bigint> = Schema.transform(
Schema.string,
Schema.bigint,
(val) => BigInt(val),
(s) => String(s),
Schema.bigintFromSelf,
(s) => BigInt(s),
(b) => String(b),
)

const EthTraceActionCall = Schema.struct({
Expand Down Expand Up @@ -102,14 +103,14 @@ export const EthDebugTraceBase = Schema.struct({
output: Schema.string,
})

type DebugTraceLog = Schema.To<typeof EthDebugTraceBase>
type DebugTraceLog = Schema.Schema.To<typeof EthDebugTraceBase>

export type TraceLogTree = {
calls?: Array<TraceLogTree>
} & DebugTraceLog

export const EthTrace = Schema.union(CallTrace, CreateTrace, RewardTrace, SuicideTrace)

export type TraceLog = Schema.To<typeof EthTrace>
export type CallTraceLog = Schema.To<typeof CallTrace>
export type CallType = Schema.To<typeof CallType>
export type TraceLog = Schema.Schema.To<typeof EthTrace>
export type CallTraceLog = Schema.Schema.To<typeof CallTrace>
export type CallType = Schema.Schema.To<typeof CallType>
2 changes: 1 addition & 1 deletion packages/transaction-decoder/src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class TransactionDecoder {
return yield* _(decodeTransactionByHash(hash, chainID))
}).pipe(Logger.withMinimumLogLevel(this.logging ? LogLevel.Debug : LogLevel.Error))

const runnable = Effect.provideContext(program, this.context)
const runnable = Effect.provide(program, this.context)

return Effect.runPromise(runnable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Transaction Decoder', () => {

const customRuntime = pipe(Layer.toRuntime(MainLayer), Effect.scoped, Effect.runSync)

const result = await program.pipe(Effect.provideSomeRuntime(customRuntime), Effect.runPromise)
const result = await program.pipe(Effect.provide(customRuntime), Effect.runPromise)

await expect(result).toMatchFileSnapshot(`./snapshots/decoder/${hash}.snapshot`)
})
Expand Down
1 change: 0 additions & 1 deletion packages/tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true,
"exactOptionalPropertyTypes": true,
"strictNullChecks": true
},
"exclude": [
Expand Down
Loading
Loading