Saltar a contenido

Silo V2

almanak.framework.connectors.silo_v2

Silo V2 connector for Almanak SDK.

Silo V2 is an isolated lending protocol on Avalanche where each market consists of exactly two assets paired together in separate ERC-4626 vaults.

Key concepts: - Each market is a pair of two Silo vaults (silo0 + silo1) - Depositing into one silo enables borrowing from the paired silo - No shared pool — bad debt is isolated per market - CollateralType: 0=Collateral (borrowable), 1=Protected (non-borrowable)

SiloV2Adapter

SiloV2Adapter(config: SiloV2Config)

Adapter for Silo V2 lending protocol on Avalanche.

Provides supply, withdraw, borrow, and repay operations for Silo V2 isolated lending markets.

find_market

find_market(
    asset0_symbol: str | None = None,
    asset1_symbol: str | None = None,
) -> SiloV2MarketInfo | None

Find a market by asset pair symbols.

Parameters:

Name Type Description Default
asset0_symbol str | None

First asset symbol (collateral side)

None
asset1_symbol str | None

Second asset symbol (borrow side)

None

Returns:

Type Description
SiloV2MarketInfo | None

Market info or None if not found

find_silo_for_asset

find_silo_for_asset(
    asset_symbol: str, market_name: str | None = None
) -> tuple[SiloV2MarketInfo, str, int] | None

Find the silo address for a given asset.

Parameters:

Name Type Description Default
asset_symbol str

Token symbol (e.g., "USDC", "WAVAX")

required
market_name str | None

Optional market name to narrow lookup

None

Returns:

Type Description
tuple[SiloV2MarketInfo, str, int] | None

Tuple of (market_info, checksummed_silo_address, asset_index) or None

supply

supply(
    asset: str,
    amount: Decimal,
    market_name: str | None = None,
    collateral_type: int = COLLATERAL_TYPE_COLLATERAL,
) -> TransactionResult

Build a deposit transaction for Silo V2.

Parameters:

Name Type Description Default
asset str

Token symbol to deposit (e.g., "USDC")

required
amount Decimal

Amount in human-readable units

required
market_name str | None

Optional market name (e.g., "WAVAX/USDC")

None
collateral_type int

0=Protected (non-borrowable), 1=Collateral (borrowable)

COLLATERAL_TYPE_COLLATERAL

Returns:

Type Description
TransactionResult

TransactionResult with encoded calldata

withdraw

withdraw(
    asset: str,
    amount: Decimal,
    market_name: str | None = None,
    withdraw_all: bool = False,
    collateral_type: int = COLLATERAL_TYPE_COLLATERAL,
) -> TransactionResult

Build a withdraw transaction for Silo V2.

Parameters:

Name Type Description Default
asset str

Token symbol to withdraw

required
amount Decimal

Amount in human-readable units (ignored if withdraw_all)

required
market_name str | None

Optional market name

None
withdraw_all bool

If True, withdraw all available balance

False
collateral_type int

0=Protected, 1=Collateral

COLLATERAL_TYPE_COLLATERAL

Returns:

Type Description
TransactionResult

TransactionResult with encoded calldata

borrow

borrow(
    collateral_asset: str,
    borrow_asset: str,
    borrow_amount: Decimal,
) -> TransactionResult

Build a borrow transaction for Silo V2.

The caller must deposit collateral separately before borrowing. This method only builds the borrow() call on the borrow silo.

Parameters:

Name Type Description Default
collateral_asset str

Collateral token symbol (identifies the market pair)

required
borrow_asset str

Token to borrow

required
borrow_amount Decimal

Amount to borrow in human-readable units

required

Returns:

Type Description
TransactionResult

TransactionResult with encoded calldata

repay

repay(
    asset: str,
    amount: Decimal,
    market_name: str | None = None,
    repay_all: bool = False,
) -> TransactionResult

Build a repay transaction for Silo V2.

Parameters:

Name Type Description Default
asset str

Token to repay

required
amount Decimal

Amount to repay (ignored if repay_all)

required
market_name str | None

Optional market name

None
repay_all bool

If True, repay using MAX_UINT256

False

Returns:

Type Description
TransactionResult

TransactionResult with encoded calldata

redeem_shares

redeem_shares(
    shares: int,
    market_name: str | None = None,
    silo_address: str | None = None,
    collateral_type: int = COLLATERAL_TYPE_COLLATERAL,
) -> TransactionResult

Build a redeem transaction using exact share amount.

Used for withdraw_all to avoid ERC-4626 rounding issues.

Parameters:

Name Type Description Default
shares int

Exact share amount to redeem

required
market_name str | None

Market name for metadata

None
silo_address str | None

The silo vault address

None
collateral_type int

0=Protected, 1=Collateral

COLLATERAL_TYPE_COLLATERAL

Returns:

Type Description
TransactionResult

TransactionResult with encoded calldata

get_market_info

get_market_info(
    asset_symbol: str, market_name: str | None = None
) -> SiloV2MarketInfo | None

Get market info for a given asset.

Parameters:

Name Type Description Default
asset_symbol str

Token symbol

required
market_name str | None

Optional market name to narrow lookup

None

Returns:

Type Description
SiloV2MarketInfo | None

SiloV2MarketInfo or None

get_silo_address

get_silo_address(
    asset_symbol: str, market_name: str | None = None
) -> str | None

Get the silo vault address for a given asset.

Parameters:

Name Type Description Default
asset_symbol str

Token symbol

required
market_name str | None

Optional market name

None

Returns:

Type Description
str | None

Checksummed silo address or None

SiloV2Config dataclass

SiloV2Config(
    chain: str = "avalanche", wallet_address: str = ""
)

Configuration for Silo V2 adapter.

SiloV2MarketInfo dataclass

SiloV2MarketInfo(
    market_name: str,
    silo_config: str,
    silo0_address: str,
    silo1_address: str,
    asset0_symbol: str,
    asset0_address: str,
    asset1_symbol: str,
    asset1_address: str,
)

Information about a Silo V2 market pair.

SiloV2Position dataclass

SiloV2Position(
    market_name: str,
    silo_address: str,
    asset_symbol: str,
    asset_address: str,
    amount: Decimal,
    is_collateral: bool = True,
)

A position in a Silo V2 market.

TransactionResult dataclass

TransactionResult(
    success: bool,
    tx_data: dict | None = None,
    gas_estimate: int = 0,
    description: str = "",
    error: str | None = None,
)

Result of building a Silo V2 transaction.

SiloV2ReceiptParser

SiloV2ReceiptParser(
    underlying_decimals: int = 6, **kwargs: Any
)

Parser for Silo V2 transaction receipts.

Extracts deposit, withdraw, borrow, and repay data from on-chain events.

parse_receipt

parse_receipt(
    receipt: dict, silo_address: str | None = None
) -> SiloV2ParseResult

Parse a transaction receipt for Silo V2 events.

Parameters:

Name Type Description Default
receipt dict

Transaction receipt dict with 'logs' list

required
silo_address str | None

Optional silo address to filter events. If filtering yields no events, automatically retries without the filter (handles proxy/router patterns).

None

Returns:

Type Description
SiloV2ParseResult

SiloV2ParseResult with extracted data

extract_supply_amount

extract_supply_amount(receipt: dict) -> int | None

Extract supply amount from receipt for ResultEnricher.

Called by ResultEnricher for SUPPLY intents (field: supply_amount).

extract_borrow_amount

extract_borrow_amount(receipt: dict) -> int | None

Extract borrow amount from receipt for ResultEnricher.

Called by ResultEnricher for BORROW intents (field: borrow_amount).

extract_withdraw_amount

extract_withdraw_amount(receipt: dict) -> int | None

Extract withdraw amount from receipt for ResultEnricher.

Called by ResultEnricher for WITHDRAW intents (field: withdraw_amount).

extract_repay_amount

extract_repay_amount(receipt: dict) -> int | None

Extract repay amount from receipt for ResultEnricher.

Called by ResultEnricher for REPAY intents (field: repay_amount).

extract_supply_data

extract_supply_data(
    receipt: dict, silo_address: str | None = None
) -> dict | None

Extract supply data from receipt (legacy API).

extract_borrow_data

extract_borrow_data(
    receipt: dict, silo_address: str | None = None
) -> dict | None

Extract borrow data from receipt (legacy API).

extract_withdraw_data

extract_withdraw_data(
    receipt: dict, silo_address: str | None = None
) -> dict | None

Extract withdraw data from receipt (legacy API).

extract_repay_data

extract_repay_data(
    receipt: dict, silo_address: str | None = None
) -> dict | None

Extract repay data from receipt (legacy API).