# 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:

```tsx
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:

```typescript
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

{% @github-files/github-code-block url="<https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/bridge.ts>" visible="false" %}

[Github link](https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/bridge.ts)

### Manifest

{% @github-files/github-code-block url="<https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/manifest.bridge.yaml>" visible="false" %}

[Github link](https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/manifest.bridge.yaml)

## 2. Invest

### Function

{% @github-files/github-code-block url="<https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/invest.ts>" visible="false" %}

[Github link](http://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/invest.ts)

### Manifest

{% @github-files/github-code-block url="<https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/manifest.invest.yaml>" visible="false" %}

[Github link](https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/manifest.invest.yaml)

### Backend

{% @github-files/github-code-block url="<https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/create-trigger.invest.ts>" visible="false" %}

[Github link](https://github.com/mimic-protocol/examples/blob/main/examples/13-bridge-and-invest-aave/src/create-trigger.invest.ts)

The ABIs used for this example can be downloaded below:

{% file src="/files/kA4B51gR3jkSykvbxDsN" %}

{% file src="/files/RVbks3Xm1ai4RZWygXNX" %}

{% file src="/files/LpjN7GOWXK6oQfBhRdUF" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mimic.fi/use-cases/bridge-and-invest-in-aave.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
