Skip to content

Adopt shared Aave pool/gateway accessors in lend provider #497

Description

@its-everdred

Motivation

The borrow side recently introduced guarded accessors in packages/sdk/src/actions/shared/aave/addresses.ts:

  • requireAavePoolAddress(chainId) → returns the pool address or throws ChainNotSupportedError
  • requireAaveWethGatewayAddress(chainId) → same for the WETH gateway

The Aave lend provider still open-codes the getPoolAddress(...) + if (!x) throw new ChainNotSupportedError(...) pattern at six sites. Routing them through the shared accessors removes the repetition and keeps the null-check in one place.

Repeated null-check sites

packages/sdk/src/actions/lend/providers/aave/AaveLendProvider.ts

  • pool: lines ~61, ~97, ~165
  • gateway: lines ~221, ~296

packages/sdk/src/actions/lend/providers/aave/sdk.ts

  • pool: line ~235 (getATokenAddress)

Each can become a single requireAavePoolAddress(chainId) / requireAaveWethGatewayAddress(chainId) call.

Bonus: named reserve decoder

sdk.ts getATokenAddress reaches the aToken by literal tuple index:

// The return is a tuple where index 8 is aTokenAddress
const aTokenAddress = reserveData[8]

The borrow side already has a named decodeReserveData helper that reads getReserveData fields by name. Consider sharing it (or a small named accessor) so the magic index 8 disappears.

Out of scope

The redundant flat POOL_ADDRESSES_* / WETH_GATEWAY_ADDRESSES_* maps and the per-map imports in validateAddresses.test.ts are already tracked by #328 (standardize provider contract address storage); this issue is only about the call-site DRY cleanup.

Work

  1. Replace the six getPoolAddress/getWETHGatewayAddress + manual-throw sites with the shared require* accessors
  2. Share/introduce a named reserve-data decoder so reserveData[8] is read by field name
  3. Confirm lend tests still pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions