SyncModel#
API documentation for tradeexecutor.strategy.sync_model.SyncModel Python class in Trading Strategy framework.
- class SyncModel[source]#
Bases:
ABC
Abstract class for syncing on-chain fund movements event to the strategy treasury.
- __init__()#
Methods
__init__
()Creates a transaction builder instance to make trades against this asset management model.
fetch_onchain_balances
(assets[, ...])Read the on-chain asset details.
Get the vault address we are using.
Get the address that identifies the vault/wallet we are using.
Get the address where tokens are stored.
Can deposit land only when we tell so.
Do we need to sync positions when we sync treasuty.
is_ready_for_live_trading
(state)Check that the state and sync model is ready for live trading.
reset_deposits
(state)Clear out pending withdrawals/deposits events.
Re-read hot wallet nonce before trade execution.
sync_initial
(state, **kwargs)Initialize the vault connection.
sync_interests
(timestamp, state, universe, ...)Update interest on all tokens that receive interest thru rebase.
sync_positions
(timestamp, state, ...)Detect any position balance changes due to deposit/redemptions of vault users.
sync_treasury
(strategy_cycle_ts, state[, ...])Apply the balance sync before each strategy cycle.
- get_key_address()[source]#
Get the address that identifies the vault/wallet we are using.
Vault smart contract address for Enzyme
Portfolio address for Velvet
- resync_nonce()[source]#
Re-read hot wallet nonce before trade execution.
Ensures that if the private key is used outside the trade executor, we are not getting wrong nonce error when broadcasting the transaction.
- is_ready_for_live_trading(state)[source]#
Check that the state and sync model is ready for live trading.
- has_position_sync()[source]#
Do we need to sync positions when we sync treasuty.
See
VelvetVaultSyncModel
- Return type:
- has_async_deposits()[source]#
Can deposit land only when we tell so.
See
LagoonVaultSyncModel
- Return type:
- abstract sync_initial(state, **kwargs)[source]#
Initialize the vault connection.
- Parameters:
kwargs –
Extra hints for the initial sync.
Because reading event from Ethereum blockchain is piss poor mess.
state (State) –
- abstract sync_treasury(strategy_cycle_ts, state, supported_reserves=None, end_block=None, post_valuation=False)[source]#
Apply the balance sync before each strategy cycle.
- Parameters:
strategy_cycle_ts (datetime) –
The current strategy cycle.
Resevers are synced before executing the strategy cycle.
state (State) – Current state of the execution.
supported_reverses –
List of assets the strategy module wants to use as its reserves.
May be None in testing.
end_block (int | None) – Sync until this block.
post_valuation –
For models where we need to manage the deposit queue ourselves, like Lagoon, make onchain transaction to update the new onchain valuation.
Disabled by default as this needs gas fees.
supported_reserves (Optional[List[AssetIdentifier]]) –
- Returns:
List of balance updates detected.
Deposits
Redemptions
- Return type:
- abstract fetch_onchain_balances(assets, filter_zero=True, block_identifier=None)[source]#
Read the on-chain asset details.
Mark the block we are reading at the start
Asset list is sorted to be by address to make sure the return order is deterministic
- Parameters:
filter_zero – Do not return zero balances
block_identifier (Union[Literal['latest', 'earliest', 'pending', 'safe', 'finalized'], ~eth_typing.evm.BlockNumber, ~eth_typing.evm.Hash32, ~eth_typing.encoding.HexStr, ~hexbytes.main.HexBytes, int]) – Cbeck at certain block height.
assets (Collection[AssetIdentifier]) –
- Returns:
Iterator for assets by the sort order.
- Return type:
- abstract create_transaction_builder()[source]#
Creates a transaction builder instance to make trades against this asset management model.
Only needed when trades are being executed.
- Returns:
Depending on the asset management mode.
- Return type:
- sync_interests(timestamp, state, universe, pricing_model)[source]#
Update interest on all tokens that receive interest thru rebase.
Credit supply positions: aToken
Short positions: aToken, vToken
- Parameters:
timestamp (datetime) –
Wall clock time.
This function can be called outside the strategy cycle.
state (State) – Current strategy state
universe (TradingStrategyUniverse) – Trading universe that must include lending data.
pricing_model (PricingModel) – Used to re-value loans
- Returns:
All triggered balance update events, one per asset per position
- Return type:
- reset_deposits(state)[source]#
Clear out pending withdrawals/deposits events.
- Parameters:
state (State) –
- sync_positions(timestamp, state, strategy_universe, pricing_model)[source]#
Detect any position balance changes due to deposit/redemptions of vault users.
Velvet directly trades any incoming tokens to user balances
USDC/reserve token is synced by
sync_treasury()
- Parameters:
timestamp (datetime) –
state (State) –
strategy_universe (TradingStrategyUniverse) –
pricing_model (PricingModel) –
- Return type: