Switchboard Functions allow you to verifiably execute your own Rust code off-chain and submit transactions either on a pre-defined cron schedule or on-demand. Switchboard Functions gives smart contracts greater flexibility as they can delegate execution to an off-chain computational layer.
Switchboard Functions are executed within its own Trusted Execution Environment (TEE) which provides verification that the code being executed matches the expected measurement (MrEnclave) authorized by the function's owner.
Functions can set a cron schedule to have it executed periodically. This is useful for automating tasks on-chain with custom conditional logic. You could use the scheduled functions to settle a perpetual 24 hour lottery. Or you could use a scheduled function to perform account maintenance and cleanup.
Functions can also be executed on-demand with custom parameters. This provides more "user-level" customizability allowing your smart contract to execute user centric actions off-chain. For example, if you are operating an on-chain exchange you are only as fast as your oracle can update which can have a number of bottlenecks depending on the chain architecture; so you're always striking a balance between oracle cost and oracle staleness while trying to manage a decent web3 UX. With Switchboard Functions you can off-load order settlement to a Switchboard Function which fetches the oracle price before settling the users order. This mitigates a large majority of oracle attack vectors allowing a trader to profit off of stale prices.
On Solana, on-demand functions use the
FunctionRequestAccount to store the
custom params and points to the parent
FunctionAccount. This allows you to
manage user params and management in isolated accounts.