Distribution Bundle Interface
Distribution bundles are the heart of the unique logic that gives Smart Rewards its incredible flexability. If you would like to create your own distribution bundle do read the how to write a distribution bundle documentation.
This interface must be adhered to in order to be compatible with the Steer Protocol.
Initialize
When the bundle is first pulled by the distribution schedular, the associated configuration file created from the input form of the config is passed into this function and the distribution execution context. The distribution execution context object contains various information about the campaign, the interval being managed for this execution, and other info. This context object is appended to the configuration object passed into the initialize funtion. Typically the configuration is stored in the WASM memory.
Distribution Exection Context
export class ExecutionContext {
// General info
campaign: Campaign;
blacklist: string[] = [];
description: string = "";
// schedule execution info
lastPublishedBlockNumber: u64;
lastPublishedTimestamp: u64;
lastDistributionExecutionTimestamp: u64;
lastDistributionExecutionBlock: u64;
currentExecutionTimestamp: u64;
currentExecutionBlock: u64;
// Campaign Info
campaign: {
id: number;
liquidityPool: string;
rewardToken: string;
creator: string;
startBlock: string;
endBlock: string;
distributionAmount: string;
abandonedDeadline: string;
cumulativeAllocated: string;
lastBlockUpdatedTo: number;
paused: boolean;
closed: boolean;
ipfsHash: string;
chainId: number;
ponderDbIdentifier: string;
executionBundle: string;
executionParams: string;
desc: string;
created_at: string;
updated_at: string;
campaignEventId: string;
campaignId: string;
// Market Making distribution context when applicable
poolContext: {
chainId: number;
poolAddress: string;
eventBlock: number;
dbIdentifier: string;
};
};
}
There is some flexability with numeric types, as long as objects can be parsed. I.e. if defining blocks all as f64 is more condusive to your project this will not cause issues.
Interface
export function initialize(config: string): void
Example (Assemblyscript)
export function initialize(config: string): void {
executionConfig = JSON.parse<ExecutionConfig>(config);
// if (!configObj!.isValid()) throw new Error("Config not properly formatted");
}
Interface
export function initialize(config: string): void
Config
export function config(): string
A config function should be implemented if there are any implementation parameters that will be unique to each campaign and not included in the context provided. We use react-json-schema for our forms.
Execute
The execute function is the main body of logic where data is fetched and processes, user information is aggregated with the associated allocations, and the resulting rewards for this interval are allocated for the users in the output.
Interface
export function execute(): string
Expected Output
The distribution bundle should return a stringified array of Claim
objects:
export class Claim {
user: string = "";
additionalAmount: string = ""
}
Data
Distribution bundles will handle their own fetching and processing of data (no data connectors). This is achieved through the use of synchronous fetching, which does away with the older and more confusing style of callback Logic and instead makes use of Asyncify to make the fetch()
calls synchronous. The as-fetch library is used to interact with this API.
Any public APIs can be called to be used for the distribution logic.
Implementation Considerations
When implementing a distribution bundle:
- Process the provided context to identify eligible users
- Calculate reward amounts based on the campaign parameters and user activity
- Create
Claim
objects for each eligible user - Return the stringified array of
Claim
objects
By following this interface, you can create custom distribution bundles tailored to specific incentivization strategies for various on-chain and off-chain actions.