For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/bridge.ts

Github link

Manifest

https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/manifest.bridge.yaml

Github link

2. Invest

Function

https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/invest.ts

Github link

Manifest

https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/manifest.invest.yaml

Github link

Backend

https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/create-trigger.invest.ts

Github link

The ABIs used for this example can be downloaded below:

Open
Open
Open

Last updated