Bridge and invest in Aave
This example involves two functions. The goal of the first function is to bridge tokens from one chain to another, and the goal of the second function is to invest in Aave the tokens received on the destination chain.
To achieve this, the bridge must complete before the investment begins. Mimic enables this kind of function concatenation by allowing one function to emit a custom event that triggers other functions in response.
The first function should include something as follows:
SwapBuilder.forChains(ChainId.SOURCE, ChainId.DESTINATION)
.addTokenInFromStringDecimal(tokenIn, '1000')
.addTokenOutFromStringDecimal(tokenOut, '990', recipient)
.addEvent(Bytes.fromHexString('0xCustomId'), Bytes.fromHexString('0xDataForTheOtherFunction'))
.send()And the trigger for the second function should look like:
const config = {
type: TriggerType.Event
chainId: Chains.Optimism,
contract: MIMIC_PROTOCOL_SETTLER,
topics: [
[INTENT_EXECUTED_TOPIC],
[encode('0xUser')],
['0xCustomId'],
],
}
await client.triggers.signAndCreate({ ..., config })With this trigger configuration, the invest function will automatically execute every time an intent from user 0xUser emits an event containing 0xCustomId on Optimism.
1. Bridge
Function
Manifest
2. Invest
Function
Manifest
Backend
The ABIs used for this example can be downloaded below:
Last updated