"Till" pattern
Every interaction with Ekubo starts with a call to `#lock`
Ekubo is a singleton contract that utilizes the "till" pattern. All pools and tokens are represented as state in the singleton. The till pattern was publicly introduced at EthCC[5] and is also described here. When interacting with pools in Ekubo, all token payments to be deferred until the end of your transaction.
Every interaction with Ekubo starts with ICore#lock
. In order to interact with Ekubo, you must first implement the ILocker
interface in your calling contract:
#[starknet::interface]
trait ICore<TStorage> {
fn lock(ref self: TStorage, data: Array<felt252>) -> Array<felt252>;
fn swap(ref self: TStorage, pool_key: PoolKey, params: SwapParameters) -> Delta;
}
#[starknet::interface]
trait ILocker<TStorage> {
fn locked(ref self: TStorage, id: u32, data: Array<felt252>) -> Array<felt252>;
}
You must then make all your swaps and position updates within the #locked
callback. If you call any of these methods outside of a locked
callback, the call will revert.
To know what you must do within the callback, encode your parameters into the data argument of the call to lock. The shared_locker.cairo contains some useful functions for constructing the call to lock as well as consuming the locked callback data.
Last updated
Was this helpful?