-
Notifications
You must be signed in to change notification settings - Fork 203
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
30 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import { Abi, EncodeFunctionDataParameters, encodeFunctionData, type ContractFunctionName } from "viem"; | ||
import { Abi, encodeFunctionData, type ContractFunctionName } from "viem"; | ||
import { SystemCall } from "./encodeSystemCall"; | ||
import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"; | ||
import { worldCallAbi } from "./worldCallAbi"; | ||
import { internal_normalizeSystemFunctionName } from "./normalizeSystemFunctionName"; | ||
|
||
export type SystemCalls<abis extends readonly Abi[]> = { | ||
[k in keyof abis]: SystemCall<abis[k], ContractFunctionName<abis[k]>>; | ||
}; | ||
|
||
/** Encode system calls to be passed as arguments into `World.batchCall` */ | ||
export function encodeSystemCalls<abi extends Abi, functionName extends ContractFunctionName<abi>>( | ||
systemCalls: readonly SystemCall<abi, functionName>[], | ||
export function encodeSystemCalls<abis extends readonly Abi[]>( | ||
systemCalls: SystemCalls<abis>, | ||
): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "batchCall">["inputs"]> { | ||
return [ | ||
systemCalls.map(({ abi, systemId, functionName, args }) => ({ | ||
systemId, | ||
callData: encodeFunctionData<abi, functionName>({ | ||
callData: encodeFunctionData({ | ||
abi, | ||
functionName: internal_normalizeSystemFunctionName(systemId, functionName), | ||
args, | ||
} as EncodeFunctionDataParameters<abi, functionName>), | ||
}), | ||
})), | ||
]; | ||
} |
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,23 +1,23 @@ | ||
import { Abi, Address, EncodeFunctionDataParameters, encodeFunctionData, type ContractFunctionName } from "viem"; | ||
import { SystemCallFrom } from "./encodeSystemCallFrom"; | ||
import { Abi, Address, encodeFunctionData } from "viem"; | ||
import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"; | ||
import { worldCallAbi } from "./worldCallAbi"; | ||
import { internal_normalizeSystemFunctionName } from "./normalizeSystemFunctionName"; | ||
import { SystemCalls } from "./encodeSystemCalls"; | ||
|
||
/** Encode system calls to be passed as arguments into `World.batchCallFrom` */ | ||
export function encodeSystemCallsFrom<abi extends Abi, functionName extends ContractFunctionName<abi>>( | ||
export function encodeSystemCallsFrom<abis extends readonly Abi[]>( | ||
from: Address, | ||
systemCalls: readonly Omit<SystemCallFrom<abi, functionName>, "from">[], | ||
systemCalls: SystemCalls<abis>, | ||
): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "batchCallFrom">["inputs"]> { | ||
return [ | ||
systemCalls.map(({ abi, systemId, functionName, args }) => ({ | ||
from, | ||
systemId, | ||
callData: encodeFunctionData<abi, functionName>({ | ||
callData: encodeFunctionData({ | ||
abi, | ||
functionName: internal_normalizeSystemFunctionName(systemId, functionName), | ||
args, | ||
} as EncodeFunctionDataParameters<abi, functionName>), | ||
}), | ||
})), | ||
]; | ||
} |