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
- Replace the six
getPoolAddress/getWETHGatewayAddress + manual-throw sites with the shared require* accessors
- Share/introduce a named reserve-data decoder so
reserveData[8] is read by field name
- Confirm lend tests still pass
Motivation
The borrow side recently introduced guarded accessors in
packages/sdk/src/actions/shared/aave/addresses.ts:requireAavePoolAddress(chainId)→ returns the pool address or throwsChainNotSupportedErrorrequireAaveWethGatewayAddress(chainId)→ same for the WETH gatewayThe 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.tspackages/sdk/src/actions/lend/providers/aave/sdk.tsgetATokenAddress)Each can become a single
requireAavePoolAddress(chainId)/requireAaveWethGatewayAddress(chainId)call.Bonus: named reserve decoder
sdk.tsgetATokenAddressreaches the aToken by literal tuple index:The borrow side already has a named
decodeReserveDatahelper that readsgetReserveDatafields 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 invalidateAddresses.test.tsare already tracked by #328 (standardize provider contract address storage); this issue is only about the call-site DRY cleanup.Work
getPoolAddress/getWETHGatewayAddress+ manual-throw sites with the sharedrequire*accessorsreserveData[8]is read by field name