From 090a099bf4891dfa3cd95f88b68dcfd5ea14bdea Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Mon, 1 Apr 2024 13:07:03 +0100 Subject: [PATCH] docs: clarify `callFrom` changelog (#2579) --- .changeset/nervous-nails-notice.md | 32 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/.changeset/nervous-nails-notice.md b/.changeset/nervous-nails-notice.md index cab1c47d4b..ac3e29b7e0 100644 --- a/.changeset/nervous-nails-notice.md +++ b/.changeset/nervous-nails-notice.md @@ -2,24 +2,36 @@ "@latticexyz/world": patch --- -This is an internal feature and is not ready for stable consumption yet. +Added a viem client decorator for account delegation. By extending viem clients with this function after delegation, the delegation is automatically applied to World contract writes. This means that these writes are made on behalf of the delegator. Internally, it transforms the write arguments to use `callFrom`. -Added viem custom client actions for delegation. By extending viem clients with this function after delegation, the delegation is automatically applied to World contract writes. This means that these writes are made on behalf of the delegator. Internally, it transforms the write arguments to use `callFrom`. +This is an internal feature and is not ready for stable consumption yet, so it's not yet exported. Its API may change. -Usage example: +When using with a viem public client, system function selectors will be fetched from the world: ```ts walletClient.extend( callFrom({ worldAddress, delegatorAddress, - publicClient, // Instead of using `publicClient`, you can pass a mapping function as shown below. This allows you to use your client store and avoid read requests. - // worldFunctionToSystemFunction: async (worldFunctionSelector) => { - // const systemFunction = useStore - // .getState() - // .getValue(tables.FunctionSelectors, { worldFunctionSelector })!; - // return { systemId: systemFunction.systemId, systemFunctionSelector: systemFunction.systemFunctionSelector }; - // }, + publicClient, + }), +); +``` + +Alternatively, a `worldFunctionToSystemFunction` handler can be passed in that will translate between world function selectors and system function selectors for cases where you want to provide your own behavior or use data already cached in e.g. Zustand or RECS. + +```ts +walletClient.extend( + callFrom({ + worldAddress, + delegatorAddress, + worldFunctionToSystemFunction: async (worldFunctionSelector) => { + const systemFunction = useStore.getState().getValue(tables.FunctionSelectors, { worldFunctionSelector })!; + return { + systemId: systemFunction.systemId, + systemFunctionSelector: systemFunction.systemFunctionSelector, + }; + }, }), ); ```