Router
Generated transactions are executed using the Router smart contract.
Introduction
Requests made to the Jam API will be tailed to be executed on the Router contract. It is what enables execution of complex, multi-step DeFi transactions in a single call.
This documentation focuses on the runSteps function and its data structures.
Functions
function runSteps(Step[] calldata steps, uint256[] memory stores) externalExecutes a sequence of steps, each comprising a call to another contract and potentially modifying an array of "stores."
Parameters
steps: An array ofStepstructs that represent the steps in the multi-step transaction.stores: An array of uint256 numbers that serve as a store for values that can be used in the transaction steps.
Conditions
Must be invoked using
DELEGATECALL.The
stepsarray must not be empty.
Behavior
Executes the steps in sequence, modifying the calldata and using the
storesas needed.Reverts the transaction if any of the steps fail.
Data structures
Step
struct Step {
address stepAddress;
bytes stepEncodedCall;
StoreOperation[] storeOperations;
}Struct for representing a transaction step.
Fields
stepAddress: The target contract address for this step.stepEncodedCall: ABI-encoded calldata to be passed to the target contract.storeOperations: An array ofStoreOperationstructs detailing any store-related modifications required for this step.
StoreOperation
struct StoreOperation {
StoreOpType storeOpType;
uint256 storeNumber;
uint256 offset;
uint256 fraction;
}Struct that describes how to operate on stores or results of steps.
storeOpType: A numerical code representing the type of store operation, determined by the followingenum:
enum StoreOpType {
RetrieveStoreAssignValue,
RetrieveStoreAssignCall,
RetrieveResultAssignStore,
RetrieveResultSubtractStore,
RetrieveStoreAssignValueSubtract,
RetrieveStoreAssignCallSubtract,
SubtractStoreFromStore
}Type
RetrieveStoreAssignValue:Retrieve store value at
storeNumber, multiply byfractionand setvalue
Type
RetrieveStoreAssignCall:Retrieve store value at
storeNumber, multiply byfractionand setoffsetatstepEncodedCall
Type
RetrieveResultAssignStore:Retrieve result value at
offsetof function's result and add it to store atstoreNumber
Type
RetrieveResultSubtractStore:Retrieve result value at
offsetof function's result and subtracts it from store atstoreNumber
Type
RetrieveStoreAssignValueSubtract:Retrieve store value at
storeNumber, multiply byfractionand setvalue.Subtracts calculated value from store.
Type
RetrieveStoreAssignCallSubtract:Retrieve store value at
storeNumber, multiply byfractionand setoffsetatstepEncodedCall. Subtracts calculated value from store.
Type
SubtractStoreFromStore:Subtracts store value at store
storeNumberfrom store atoffset
Examples
Examples will be added here.
// Prepare a sequence of steps and an initial stores array.
Step[] memory steps = // ...
uint256[] memory stores = // ...
// Execute the steps via the Router contract.
routerContract.runSteps(steps, stores);Source code
Last updated