-
ProblemWe would like to reuse certain loader implementations that are the same across different contracts. For example: */
SablierLockup_v2_0.CreateLockupTranchedStream.handlerWithLoader({
loader: async ({ context, event }) => {
const assetId = Id.asset(event.srcAddress, event.chainId);
const asset = await context.Asset.get(assetId);
const sender = event.params.commonParams[1];
const batchId = Id.batch(event, sender);
const batch = await context.Batch.get(batchId);
const batcherId = Id.batcher(event, sender);
const batcher = await context.Batcher.get(batcherId);
const watcherId = event.chainId.toString();
const watcher = await context.Watcher.get(watcherId);
return {
asset,
batch,
batcher,
watcher,
};
},
// <-- snip --> Current SolutionTo reuse the loader and define it separately, we have to perform the typing acrobatics shown below. The issue is that this is a lot of boilerplate that we need to maintain just to be able to define the loader and the handler separately, and it increases the maintenance cost in a non-trivial way. import type { LockupV23_CreateLockupTranchedStream_eventArgs as CreateTranchedMergedArgs } from "./generated/src/Types.gen";
import {
HandlerTypes_loaderArgs,
HandlerTypes_handlerArgs,
} from "./generated/src/Types.gen";
export type Loader<eventArgs> = HandlerTypes_loaderArgs<eventArgs>;
export type Handler<eventArgs, loaderReturn> = HandlerTypes_handlerArgs<
eventArgs,
loaderReturn
>;
export type CreateTranchedMergedLoader = Loader<CreateTranchedMergedArgs>;
export type CreateTranchedMergedHandler<
L extends (_1: Loader<E>) => Promise<object>,
E = CreateTranchedMergedArgs,
> = Handler<E, Awaited<ReturnType<L>>>; And then finally we can define the loader like so: async function loader(input: CreateTranchedMergedLoader) { ... } Expected SolutionEnvio should provide a dynamically generated loader and handler type for each function. Maybe you guys offer these types already, and we missed them? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hey @PaulRBerg, there will be a type in the Is that what you're looking for? Or specifically looking for the type for the arguments to the loader? |
Beta Was this translation helpful? Give feedback.
-
Hey @JonoPrest, is this the correct way of defining the types for a handler without a loader? Pass import type {
SablierFlow_v1_0_Transfer_handler as Handler_v1_0,
SablierFlow_v1_1_Transfer_handler as Handler_v1_1,
} from "../../bindings/src/Types.gen";
type Handler<T> = Handler_v1_0<T> & Handler_v1_1<T>;
const handler: Handler<undefined> = async ({ context, event }) => {
// ... rest of code ....
} edit 2: I made it work like this: type Handler<T> = Handler_v1_0<T> & Handler_v1_1<T>;
const handler: Handler<void> = async ({ context, event }) => {
// ...
}
Contract.Flow_v1_0.Transfer.handler(transfer.handler); |
Beta Was this translation helpful? Give feedback.
Hey @PaulRBerg, there will be a type in the
Types.gen
file calledLockupV23_CreateLockupTranchedStream_loader
andLockupV23_CreateLockupTranchedStream_handler
,Is that what you're looking for?
Or specifically looking for the type for the arguments to the loader?