Skip to content

Commit 1cef8a7

Browse files
committed
chore: embelish bridge and invest example
1 parent 7b267a7 commit 1cef8a7

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

examples/12-bridge-and-invest-aave/src/bridge.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ export default function main(): void {
2020
if (sourceChain == destinationChain) throw new Error('Single-chain swap not supported')
2121

2222
const tokenIn = getUsdc(sourceChain)
23-
const tokenOut = getUsdc(destinationChain)
24-
2523
const tokenAmountIn = TokenAmount.fromStringDecimal(tokenIn, inputs.amount)
24+
25+
const tokenOut = getUsdc(destinationChain)
2626
const tokenAmountOut = TokenAmount.fromStringDecimal(tokenOut, inputs.minAmountOut)
2727

2828
const feeToken = new ERC20Token(inputs.feeToken, inputs.destinationChain)
2929
const maxFee = TokenAmount.fromStringDecimal(feeToken, inputs.maxFee)
3030

31+
// Set topic hash and encode tokenOut address as extra data
3132
const topic = evm.keccak('Bridged USDC')
3233
const data = evm.encode([EvmEncodeParam.fromValue('address', tokenAmountOut.token.address)])
3334

examples/12-bridge-and-invest-aave/src/create-config.invest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function main() {
4747
type: TriggerType.Event as const,
4848
contract: MIMIC_PROTOCOL_SETTLER,
4949
topics: [
50-
[INTENT_EXECUTED_TOPIC],
50+
[INTENT_EXECUTED_TOPIC], // The event emitted by the Settler
5151
[USER_TOPIC], // Important: To prevent other users from triggering this task
5252
[BRIDGED_TOPIC], // Emitted by the bridge task
5353
],

examples/12-bridge-and-invest-aave/src/invest.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,19 @@ export default function main(): void {
3333
// Get the token and the amount from the event emitted by the task that triggered this one
3434
const tokenStr = evm.decode(new EvmDecodeParam('address', event.data.toHexString()))
3535
const token = Address.fromString(tokenStr)
36-
const output = evm.decode(new EvmDecodeParam('uint256[]', event.output.toHexString()))
37-
const amountsOut = JSON.parse<string[]>(output)
38-
const amount = BigInt.fromString(amountsOut[0])
36+
37+
const amountsStr = evm.decode(new EvmDecodeParam('uint256[]', event.output.toHexString()))
38+
const amounts = JSON.parse<string[]>(amountsStr)
39+
if (amounts.length == 0) throw new Error('Empty amounts array')
40+
const amount = BigInt.fromString(amounts[0])
3941

4042
const feeToken = new ERC20Token(inputs.feeToken, chainId)
4143
const maxFee = TokenAmount.fromStringDecimal(feeToken, inputs.maxFee)
4244

4345
const approveData = ERC20Utils.encodeApprove(aaveV3Pool, amount)
4446
const supplyData = AavePoolUtils.encodeSupply(token, amount, smartAccount, 0)
4547

46-
// Deposit USDC owned by the smart account
48+
// Give approval and deposit the tokens, owned by the smart account
4749
EvmCallBuilder.forChain(chainId)
4850
.addCall(token, approveData)
4951
.addCall(aaveV3Pool, supplyData)

0 commit comments

Comments
 (0)