Architectural overview


Jam's off-chain TypeScript backend assists in generating blockchain transactions tailored for multi-step DeFi operations. The backend performs computations to output a series of actions (transaction steps) to be executed in a batch, which will then be invoked via an ERC-4337-compatible wallet using DELEGATECALL. This documentation covers the key classes and functions exposed by the backend for transaction generation.


The AssetStore class is responsible for managing and accessing information about different assets (tokens).


constructor(assets: Asset[])


  • assets: An array of Asset objects containing information like asset id, chain id, symbol, etc.


A type directly derived from asset' JSON objects, with the following parameters:

export interface Asset {
  id: string;
  name: string;
  chainId: number;
  active: boolean;
  address: string;
  color: string;
  decimals: number;
  symbol: string;
  type: AssetType;
  visible: boolean;
  linkedAssets?: LinkedAsset[];
  maxSize?: number;
  allowSlot?: number;
  balanceSlot?: number;
  callParams?: any;
  price?: number;
  isVyper?: boolean;


The function takes in details about input and output assets and generates a series of steps for a multi-step transaction.


async function generateTransaction({
}: {
  chainId: number;
  walletAddress: string;
  assetStore: AssetStore;
  inputAllocation: AbsoluteAllocation;
  outputAllocation: FractionAllocation;


  • chainId: Chain ID to specify on which blockchain network the transaction should occur.

  • walletAddress:

  • assetStore: An instance of the AssetStore class to fetch details about assets.

  • inputAllocation: An array describing which assets and how much of them should be used as input.

  • outputAllocation: An array describing how the output should be allocated among different assets.



Type used to define an item in the input allocation array.

interface AbsoluteAllocationItem {
  assetId: string;
  amountStr: BigNumberish;
  • assetId: Unique identifier for the asset.

  • amountStr: The amount of the asset in string format, compatible with BigNumber libraries.


Type used to define an item in the output allocation array.

interface FractionAllocationItem {
  assetId: string;
  fraction: number;
  rewards?: FractionAllocationItem[];
  • assetId: Unique identifier for the asset.

  • fraction: A float (0-1) representing the fraction of the output asset.

  • rewards: Optional, additional nested FractionAllocationItems for cases like staking rewards.

Utility Types

  • AbsoluteAllocation: Array of AbsoluteAllocationItem.

  • FractionAllocation: Array of FractionAllocationItem.

Last updated