Tools Module
prediction_market_agent_tooling.tools
_generic_value
InputValueType
module-attribute
InputValueType = TypeVar(
"InputValueType",
bound=Union[str, int, float, Wei, Decimal],
)
InternalValueType
module-attribute
InternalValueType = TypeVar(
"InternalValueType", bound=Union[int, float, Wei]
)
balances
Balances
Bases: BaseModel
xdai
instance-attribute
xdai: xDai
wxdai
instance-attribute
wxdai: CollateralToken
sdai
instance-attribute
sdai: CollateralToken
total
property
total: CollateralToken
get_balances
get_balances(
address: ChecksumAddress, web3: Web3 | None = None
) -> Balances
Source code in prediction_market_agent_tooling/tools/balances.py
27 28 29 30 31 32 33 34 35 | |
betting_strategies
kelly_criterion
check_is_valid_probability
check_is_valid_probability(probability: float) -> None
Source code in prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py
6 7 8 | |
get_kelly_bet_simplified
get_kelly_bet_simplified(
max_bet: CollateralToken,
market_p_yes: float,
estimated_p_yes: float,
confidence: float,
) -> SimpleBet
Calculate the optimal bet amount using the Kelly Criterion for a binary outcome market.
From https://en.wikipedia.org/wiki/Kelly_criterion:
f* = p - q / b
where: - f* is the fraction of the current bankroll to wager - p is the probability of a win - q = 1-p is the probability of a loss - b is the proportion of the bet gained with a win
Note: this calculation does not factor in that the bet changes the market odds. This means the calculation is only accurate if the bet size is small compared to the market volume. See discussion here for more detail: https://github.com/gnosis/prediction-market-agent-tooling/pull/330#discussion_r1698269328
Source code in prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
get_kelly_bet_full
get_kelly_bet_full(
yes_outcome_pool_size: OutcomeToken,
no_outcome_pool_size: OutcomeToken,
estimated_p_yes: float,
confidence: float,
max_bet: CollateralToken,
fees: MarketFees,
) -> SimpleBet
Calculate the optimal bet amount using the Kelly Criterion for a binary outcome market.
'Full' as in it accounts for how the bet changes the market odds.
Taken from https://github.com/valory-xyz/trader/blob/main/strategies/kelly_criterion/kelly_criterion.py
with derivation in PR description: https://github.com/valory-xyz/trader/pull/119
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Source code in prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
stretch_bet_between
stretch_bet_between
stretch_bet_between(
probability: Probability, min_bet: float, max_bet: float
) -> float
Normalise the outcome probability into a bet amount between the minimum and maximum bet.
Source code in prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py
4 5 6 7 8 9 10 11 12 | |
utils
SimpleBet
Bases: BaseModel
direction
instance-attribute
direction: bool
size
instance-attribute
size: CollateralToken
caches
db_cache
DB_CACHE_LOG_PREFIX
module-attribute
DB_CACHE_LOG_PREFIX = '[db-cache]'
FunctionT
module-attribute
FunctionT = TypeVar('FunctionT', bound=Callable[..., Any])
FunctionCache
Bases: SQLModel
id
class-attribute
instance-attribute
id: int | None = Field(default=None, primary_key=True)
function_name
class-attribute
instance-attribute
function_name: str = Field(index=True)
full_function_name
class-attribute
instance-attribute
full_function_name: str = Field(index=True)
args
class-attribute
instance-attribute
args: Any = Field(sa_column=Column(JSONB, nullable=False))
args_hash
class-attribute
instance-attribute
args_hash: str = Field(index=True)
result
class-attribute
instance-attribute
result: Any = Field(sa_column=Column(JSONB, nullable=False))
created_at
class-attribute
instance-attribute
created_at: DatetimeUTC = Field(
default_factory=utcnow, index=True
)
db_cache
db_cache(
func: None = None,
*,
max_age: timedelta | None = None,
cache_none: bool = True,
api_keys: APIKeys | None = None,
ignore_args: Sequence[str] | None = None,
ignore_arg_types: Sequence[type] | None = None,
log_error_on_unsavable_data: bool = True,
) -> Callable[[FunctionT], FunctionT]
db_cache(
func: FunctionT,
*,
max_age: timedelta | None = None,
cache_none: bool = True,
api_keys: APIKeys | None = None,
ignore_args: Sequence[str] | None = None,
ignore_arg_types: Sequence[type] | None = None,
log_error_on_unsavable_data: bool = True,
) -> FunctionT
db_cache(
func: FunctionT | None = None,
*,
max_age: timedelta | None = None,
cache_none: bool = True,
api_keys: APIKeys | None = None,
ignore_args: Sequence[str] | None = None,
ignore_arg_types: Sequence[type] | None = None,
log_error_on_unsavable_data: bool = True,
) -> FunctionT | Callable[[FunctionT], FunctionT]
Source code in prediction_market_agent_tooling/tools/caches/db_cache.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
contains_pydantic_model
contains_pydantic_model(return_type: Any) -> bool
Check if the return type contains anything that's a Pydantic model (including nested structures, like list[BaseModel], dict[str, list[BaseModel]], etc.)
Source code in prediction_market_agent_tooling/tools/caches/db_cache.py
236 237 238 239 240 241 242 243 244 245 246 247 | |
convert_cached_output_to_pydantic
convert_cached_output_to_pydantic(
return_type: Any, data: Any
) -> Any
Used to initialize Pydantic models from anything cached that was originally a Pydantic model in the output. Including models in nested structures.
Source code in prediction_market_agent_tooling/tools/caches/db_cache.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
inmemory_cache
MEMORY
module-attribute
MEMORY = Memory(CACHE_DIR, verbose=0)
T
module-attribute
T = TypeVar('T', bound=Callable[..., Any])
persistent_inmemory_cache
persistent_inmemory_cache(
func: None = None, *, in_memory_cache: bool = True
) -> Callable[[T], T]
persistent_inmemory_cache(
func: T, *, in_memory_cache: bool = True
) -> T
persistent_inmemory_cache(
func: T | None = None, *, in_memory_cache: bool = True
) -> T | Callable[[T], T]
Wraps a function with both file cache (for persistent cache) and optional in-memory cache (for speed). Can be used as @persistent_inmemory_cache or @persistent_inmemory_cache(in_memory_cache=False)
Source code in prediction_market_agent_tooling/tools/caches/inmemory_cache.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
serializers
json_serializer
json_serializer(x: Any) -> str
Source code in prediction_market_agent_tooling/tools/caches/serializers.py
10 11 | |
json_serializer_default_fn
json_serializer_default_fn(
y: DatetimeUTC | timedelta | date | BaseModel,
) -> str | dict[str, t.Any]
Used to serialize objects that don't support it by default into a specific string that can be deserialized out later.
If this function returns a dictionary, it will be called recursively.
If you add something here, also add it to replace_custom_stringified_objects below.
Source code in prediction_market_agent_tooling/tools/caches/serializers.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
json_deserializer
json_deserializer(s: str) -> t.Any
Source code in prediction_market_agent_tooling/tools/caches/serializers.py
35 36 37 | |
replace_custom_stringified_objects
replace_custom_stringified_objects(obj: Any) -> t.Any
Used to deserialize objects from json_serializer_default_fn into their proper form.
Source code in prediction_market_agent_tooling/tools/caches/serializers.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
contract
ContractBaseClass
Bases: BaseModel
Base class holding the basic requirements and tools used for every contract.
CHAIN_ID
class-attribute
CHAIN_ID: ChainID
abi
instance-attribute
abi: ABI
address
instance-attribute
address: ChecksumAddress
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
ContractProxyBaseClass
Bases: ContractBaseClass
Contract base class for proxy contracts.
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/proxy.abi.json",
)
)
CHAIN_ID
class-attribute
CHAIN_ID: ChainID
address
instance-attribute
address: ChecksumAddress
implementation
implementation(web3: Web3 | None = None) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
184 185 186 | |
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
ContractERC20BaseClass
Bases: ContractBaseClass
Contract base class extended by ERC-20 standard methods.
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/erc20.abi.json",
)
)
CHAIN_ID
class-attribute
CHAIN_ID: ChainID
address
instance-attribute
address: ChecksumAddress
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
200 201 202 | |
symbol_cached
symbol_cached(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
204 205 206 207 208 209 210 | |
allowance
allowance(
owner: ChecksumAddress,
for_address: ChecksumAddress,
web3: Web3 | None = None,
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
212 213 214 215 216 217 218 219 220 221 | |
approve
approve(
api_keys: APIKeys,
for_address: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
transferFrom
transferFrom(
api_keys: APIKeys,
sender: ChecksumAddress,
recipient: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
balanceOf
balanceOf(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
259 260 261 | |
balance_of_in_tokens
balance_of_in_tokens(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> CollateralToken
Source code in prediction_market_agent_tooling/tools/contract.py
263 264 265 266 | |
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
ContractDepositableWrapperERC20BaseClass
Bases: ContractERC20BaseClass
ERC-20 standard base class extended for wrapper tokens. Although this is not a standard, it's seems to be a common pattern for wrapped tokens (at least it checks out for wxDai and wETH).
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/depositablewrapper_erc20.abi.json",
)
)
CHAIN_ID
class-attribute
CHAIN_ID: ChainID
address
instance-attribute
address: ChecksumAddress
deposit
deposit(
api_keys: APIKeys,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
withdraw
withdraw(
api_keys: APIKeys,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
200 201 202 | |
symbol_cached
symbol_cached(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
204 205 206 207 208 209 210 | |
allowance
allowance(
owner: ChecksumAddress,
for_address: ChecksumAddress,
web3: Web3 | None = None,
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
212 213 214 215 216 217 218 219 220 221 | |
approve
approve(
api_keys: APIKeys,
for_address: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
transferFrom
transferFrom(
api_keys: APIKeys,
sender: ChecksumAddress,
recipient: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
balanceOf
balanceOf(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
259 260 261 | |
balance_of_in_tokens
balance_of_in_tokens(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> CollateralToken
Source code in prediction_market_agent_tooling/tools/contract.py
263 264 265 266 | |
ContractERC4626BaseClass
Bases: ContractERC20BaseClass
Class for ERC-4626, which is a superset for ERC-20.
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/erc4626.abi.json",
)
)
CHAIN_ID
class-attribute
CHAIN_ID: ChainID
address
instance-attribute
address: ChecksumAddress
asset
asset(web3: Web3 | None = None) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
324 325 326 | |
deposit
deposit(
api_keys: APIKeys,
amount_wei: Wei,
receiver: ChecksumAddress | None = None,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
withdraw
withdraw(
api_keys: APIKeys,
assets_wei: Wei,
receiver: ChecksumAddress | None = None,
owner: ChecksumAddress | None = None,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
withdraw_in_shares
withdraw_in_shares(
api_keys: APIKeys,
shares_wei: Wei,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
365 366 367 368 369 370 | |
convertToShares
convertToShares(
assets: Wei, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
372 373 374 | |
convertToAssets
convertToAssets(
shares: Wei, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
376 377 378 | |
get_asset_token_contract
get_asset_token_contract(
web3: Web3 | None = None,
) -> (
ContractERC20BaseClass
| ContractDepositableWrapperERC20BaseClass
)
Source code in prediction_market_agent_tooling/tools/contract.py
380 381 382 383 384 385 386 387 388 | |
get_asset_token_balance
get_asset_token_balance(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
390 391 392 393 394 | |
deposit_asset_token
deposit_asset_token(
asset_value: Wei,
api_keys: APIKeys,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
get_in_shares
get_in_shares(amount: Wei, web3: Web3 | None = None) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
411 412 413 | |
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
200 201 202 | |
symbol_cached
symbol_cached(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
204 205 206 207 208 209 210 | |
allowance
allowance(
owner: ChecksumAddress,
for_address: ChecksumAddress,
web3: Web3 | None = None,
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
212 213 214 215 216 217 218 219 220 221 | |
approve
approve(
api_keys: APIKeys,
for_address: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
transferFrom
transferFrom(
api_keys: APIKeys,
sender: ChecksumAddress,
recipient: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
balanceOf
balanceOf(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
259 260 261 | |
balance_of_in_tokens
balance_of_in_tokens(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> CollateralToken
Source code in prediction_market_agent_tooling/tools/contract.py
263 264 265 266 | |
OwnableContract
Bases: ContractBaseClass
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/ownable.abi.json",
)
)
CHAIN_ID
class-attribute
CHAIN_ID: ChainID
address
instance-attribute
address: ChecksumAddress
owner
owner(web3: Web3 | None = None) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
424 425 426 | |
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
ContractERC721BaseClass
Bases: ContractBaseClass
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/erc721.abi.json",
)
)
CHAIN_ID
class-attribute
CHAIN_ID: ChainID
address
instance-attribute
address: ChecksumAddress
safeMint
safeMint(
api_keys: APIKeys,
to_address: ChecksumAddress,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
balanceOf
balanceOf(
owner: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
452 453 454 | |
owner_of
owner_of(
token_id: int, web3: Web3 | None = None
) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
456 457 458 | |
name
name(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
460 461 462 | |
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
464 465 466 | |
tokenURI
tokenURI(tokenId: int, web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
468 469 470 | |
safeTransferFrom
safeTransferFrom(
api_keys: APIKeys,
from_address: ChecksumAddress,
to_address: ChecksumAddress,
tokenId: int,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
ContractOwnableERC721BaseClass
Bases: ContractERC721BaseClass, OwnableContract
abi
class-attribute
instance-attribute
abi: ABI = merge_contract_abis(
[
ContractERC721BaseClass(
address=ChecksumAddress(CHECKSUM_ADDRESSS_ZERO)
),
OwnableContract(
address=ChecksumAddress(CHECKSUM_ADDRESSS_ZERO)
),
]
)
CHAIN_ID
class-attribute
CHAIN_ID: ChainID
address
instance-attribute
address: ChecksumAddress
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
owner
owner(web3: Web3 | None = None) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
424 425 426 | |
safeMint
safeMint(
api_keys: APIKeys,
to_address: ChecksumAddress,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
balanceOf
balanceOf(
owner: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
452 453 454 | |
owner_of
owner_of(
token_id: int, web3: Web3 | None = None
) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
456 457 458 | |
name
name(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
460 461 462 | |
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
464 465 466 | |
tokenURI
tokenURI(tokenId: int, web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
468 469 470 | |
safeTransferFrom
safeTransferFrom(
api_keys: APIKeys,
from_address: ChecksumAddress,
to_address: ChecksumAddress,
tokenId: int,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
ContractOnGnosisChain
Bases: ContractBaseClass
Contract base class with Gnosis Chain configuration.
CHAIN_ID
class-attribute
instance-attribute
CHAIN_ID = chain_id
abi
instance-attribute
abi: ABI
address
instance-attribute
address: ChecksumAddress
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
ContractProxyOnGnosisChain
Bases: ContractProxyBaseClass, ContractOnGnosisChain
Proxy contract base class with Gnosis Chain configuration.
CHAIN_ID
class-attribute
instance-attribute
CHAIN_ID = chain_id
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/proxy.abi.json",
)
)
address
instance-attribute
address: ChecksumAddress
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
implementation
implementation(web3: Web3 | None = None) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
184 185 186 | |
ContractERC20OnGnosisChain
Bases: ContractERC20BaseClass, ContractOnGnosisChain
ERC-20 standard base class with Gnosis Chain configuration.
CHAIN_ID
class-attribute
instance-attribute
CHAIN_ID = chain_id
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/erc20.abi.json",
)
)
address
instance-attribute
address: ChecksumAddress
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
200 201 202 | |
symbol_cached
symbol_cached(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
204 205 206 207 208 209 210 | |
allowance
allowance(
owner: ChecksumAddress,
for_address: ChecksumAddress,
web3: Web3 | None = None,
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
212 213 214 215 216 217 218 219 220 221 | |
approve
approve(
api_keys: APIKeys,
for_address: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
transferFrom
transferFrom(
api_keys: APIKeys,
sender: ChecksumAddress,
recipient: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
balanceOf
balanceOf(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
259 260 261 | |
balance_of_in_tokens
balance_of_in_tokens(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> CollateralToken
Source code in prediction_market_agent_tooling/tools/contract.py
263 264 265 266 | |
ContractOwnableERC721OnGnosisChain
Bases: ContractOwnableERC721BaseClass, ContractOnGnosisChain
Ownable ERC-721 standard base class with Gnosis Chain configuration.
CHAIN_ID
class-attribute
instance-attribute
CHAIN_ID = chain_id
abi
class-attribute
instance-attribute
abi: ABI = merge_contract_abis(
[
ContractERC721BaseClass(
address=ChecksumAddress(CHECKSUM_ADDRESSS_ZERO)
),
OwnableContract(
address=ChecksumAddress(CHECKSUM_ADDRESSS_ZERO)
),
]
)
address
instance-attribute
address: ChecksumAddress
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
owner
owner(web3: Web3 | None = None) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
424 425 426 | |
safeMint
safeMint(
api_keys: APIKeys,
to_address: ChecksumAddress,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
balanceOf
balanceOf(
owner: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
452 453 454 | |
owner_of
owner_of(
token_id: int, web3: Web3 | None = None
) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
456 457 458 | |
name
name(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
460 461 462 | |
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
464 465 466 | |
tokenURI
tokenURI(tokenId: int, web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
468 469 470 | |
safeTransferFrom
safeTransferFrom(
api_keys: APIKeys,
from_address: ChecksumAddress,
to_address: ChecksumAddress,
tokenId: int,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
ContractDepositableWrapperERC20OnGnosisChain
Bases: ContractDepositableWrapperERC20BaseClass, ContractERC20OnGnosisChain
Depositable Wrapper ERC-20 standard base class with Gnosis Chain configuration.
CHAIN_ID
class-attribute
instance-attribute
CHAIN_ID = chain_id
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/depositablewrapper_erc20.abi.json",
)
)
address
instance-attribute
address: ChecksumAddress
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
200 201 202 | |
symbol_cached
symbol_cached(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
204 205 206 207 208 209 210 | |
allowance
allowance(
owner: ChecksumAddress,
for_address: ChecksumAddress,
web3: Web3 | None = None,
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
212 213 214 215 216 217 218 219 220 221 | |
approve
approve(
api_keys: APIKeys,
for_address: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
transferFrom
transferFrom(
api_keys: APIKeys,
sender: ChecksumAddress,
recipient: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
balanceOf
balanceOf(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
259 260 261 | |
balance_of_in_tokens
balance_of_in_tokens(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> CollateralToken
Source code in prediction_market_agent_tooling/tools/contract.py
263 264 265 266 | |
deposit
deposit(
api_keys: APIKeys,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
withdraw
withdraw(
api_keys: APIKeys,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
ContractERC4626OnGnosisChain
Bases: ContractERC4626BaseClass, ContractERC20OnGnosisChain
ERC-4626 standard base class with Gnosis Chain configuration.
CHAIN_ID
class-attribute
instance-attribute
CHAIN_ID = chain_id
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/erc4626.abi.json",
)
)
address
instance-attribute
address: ChecksumAddress
get_asset_token_contract
get_asset_token_contract(
web3: Web3 | None = None,
) -> (
ContractERC20OnGnosisChain
| ContractDepositableWrapperERC20OnGnosisChain
)
Source code in prediction_market_agent_tooling/tools/contract.py
543 544 545 546 | |
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
symbol
symbol(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
200 201 202 | |
symbol_cached
symbol_cached(web3: Web3 | None = None) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
204 205 206 207 208 209 210 | |
allowance
allowance(
owner: ChecksumAddress,
for_address: ChecksumAddress,
web3: Web3 | None = None,
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
212 213 214 215 216 217 218 219 220 221 | |
approve
approve(
api_keys: APIKeys,
for_address: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
transferFrom
transferFrom(
api_keys: APIKeys,
sender: ChecksumAddress,
recipient: ChecksumAddress,
amount_wei: Wei,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
balanceOf
balanceOf(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
259 260 261 | |
balance_of_in_tokens
balance_of_in_tokens(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> CollateralToken
Source code in prediction_market_agent_tooling/tools/contract.py
263 264 265 266 | |
asset
asset(web3: Web3 | None = None) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/contract.py
324 325 326 | |
deposit
deposit(
api_keys: APIKeys,
amount_wei: Wei,
receiver: ChecksumAddress | None = None,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
withdraw
withdraw(
api_keys: APIKeys,
assets_wei: Wei,
receiver: ChecksumAddress | None = None,
owner: ChecksumAddress | None = None,
tx_params: Optional[TxParams] = None,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
withdraw_in_shares
withdraw_in_shares(
api_keys: APIKeys,
shares_wei: Wei,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
365 366 367 368 369 370 | |
convertToShares
convertToShares(
assets: Wei, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
372 373 374 | |
convertToAssets
convertToAssets(
shares: Wei, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
376 377 378 | |
get_asset_token_balance
get_asset_token_balance(
for_address: ChecksumAddress, web3: Web3 | None = None
) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
390 391 392 393 394 | |
deposit_asset_token
deposit_asset_token(
asset_value: Wei,
api_keys: APIKeys,
web3: Web3 | None = None,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
get_in_shares
get_in_shares(amount: Wei, web3: Web3 | None = None) -> Wei
Source code in prediction_market_agent_tooling/tools/contract.py
411 412 413 | |
DebuggingContract
Bases: ContractOnGnosisChain
abi
class-attribute
instance-attribute
abi: ABI = abi_field_validator(
join(
dirname(realpath(__file__)),
"../abis/debuggingcontract.abi.json",
)
)
address
class-attribute
instance-attribute
address: ChecksumAddress = to_checksum_address(
"0x5Aa82E068aE6a6a1C26c42E5a59520a74Cdb8998"
)
CHAIN_ID
class-attribute
instance-attribute
CHAIN_ID = chain_id
getNow
getNow(web3: Web3 | None = None) -> int
Source code in prediction_market_agent_tooling/tools/contract.py
561 562 563 564 565 566 567 568 569 | |
get_now
get_now(web3: Web3 | None = None) -> DatetimeUTC
Source code in prediction_market_agent_tooling/tools/contract.py
571 572 573 574 575 | |
inc
inc(
api_keys: APIKeys, web3: Web3 | None = None
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/contract.py
577 578 579 580 581 582 583 584 585 586 | |
merge_contract_abis
classmethod
merge_contract_abis(
contracts: list[ContractBaseClass],
) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
77 78 79 80 81 82 | |
get_web3_contract
get_web3_contract(web3: Web3 | None = None) -> Web3Contract
Source code in prediction_market_agent_tooling/tools/contract.py
84 85 86 | |
call
call(
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
web3: Web3 | None = None,
) -> t.Any
Used for reading from the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
send
send(
api_keys: APIKeys,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract.
Source code in prediction_market_agent_tooling/tools/contract.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
send_with_value
send_with_value(
api_keys: APIKeys,
function_name: str,
amount_wei: Wei,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
web3: Web3 | None = None,
) -> TxReceipt
Used for changing a state (writing) to the contract, including sending chain's native currency.
Source code in prediction_market_agent_tooling/tools/contract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_transaction_count
classmethod
get_transaction_count(
for_address: ChecksumAddress,
) -> Nonce
Source code in prediction_market_agent_tooling/tools/contract.py
164 165 166 | |
get_web3
classmethod
get_web3() -> Web3
Source code in prediction_market_agent_tooling/tools/contract.py
168 169 170 | |
abi_field_validator
abi_field_validator(value: str) -> ABI
Source code in prediction_market_agent_tooling/tools/contract.py
34 35 36 37 38 39 40 41 42 43 | |
wait_until_nonce_changed
wait_until_nonce_changed(
for_address: ChecksumAddress,
timeout: int = 10,
sleep_time: int = 1,
) -> t.Generator[None, None, None]
Source code in prediction_market_agent_tooling/tools/contract.py
46 47 48 49 50 51 52 53 54 55 56 57 | |
contract_implements_function
contract_implements_function(
contract_address: ChecksumAddress,
function_name: str,
web3: Web3,
function_arg_types: list[str] | None = None,
look_for_proxy_contract: bool = True,
) -> bool
Source code in prediction_market_agent_tooling/tools/contract.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
minimal_proxy_implements_function
minimal_proxy_implements_function(
contract_address: ChecksumAddress,
function_name: str,
web3: Web3,
function_arg_types: list[str] | None = None,
) -> bool
Source code in prediction_market_agent_tooling/tools/contract.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
init_collateral_token_contract
init_collateral_token_contract(
address: ChecksumAddress, web3: Web3 | None
) -> ContractERC20BaseClass
Checks if the given contract is Depositable ERC-20, ERC-20 or ERC-4626 and returns the appropriate class instance. Throws an error if the contract is neither of them.
Source code in prediction_market_agent_tooling/tools/contract.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | |
to_gnosis_chain_contract
to_gnosis_chain_contract(
contract: ContractERC20BaseClass,
) -> ContractERC20OnGnosisChain
Source code in prediction_market_agent_tooling/tools/contract.py
690 691 692 693 694 695 696 697 698 699 700 | |
create_contract_method_cache_key
create_contract_method_cache_key(
method: Callable[[Any], Any], web3: Web3
) -> str
Source code in prediction_market_agent_tooling/tools/contract.py
703 704 705 706 | |
costs
Costs
Bases: BaseModel
time
instance-attribute
time: float
cost
instance-attribute
cost: float
openai_costs
openai_costs(
model: str | None = None,
) -> t.Generator[Costs, None, None]
Source code in prediction_market_agent_tooling/tools/costs.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
custom_exceptions
CantPayForGasError
Bases: ValueError
OutOfFundsError
Bases: ValueError
datetime_utc
DatetimeUTC
Bases: datetime
As a subclass of datetime instead of NewType because otherwise it doesn't work with issubclass command which is required for SQLModel/Pydantic.
from_datetime
staticmethod
from_datetime(dt: datetime) -> DatetimeUTC
Converts a datetime object to DatetimeUTC, ensuring it is timezone-aware in UTC.
Source code in prediction_market_agent_tooling/tools/datetime_utc.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
to_datetime_utc
staticmethod
to_datetime_utc(value: datetime | int | str) -> DatetimeUTC
Source code in prediction_market_agent_tooling/tools/datetime_utc.py
63 64 65 66 67 68 69 70 71 72 73 74 | |
db
db_manager
DBManager
DBManager(sqlalchemy_db_url: str | None = None)
Source code in prediction_market_agent_tooling/tools/db/db_manager.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
cache_table_initialized
instance-attribute
cache_table_initialized: dict[str, bool] = {}
get_session
get_session() -> Generator[Session, None, None]
Source code in prediction_market_agent_tooling/tools/db/db_manager.py
45 46 47 48 | |
get_connection
get_connection() -> Generator[Connection, None, None]
Source code in prediction_market_agent_tooling/tools/db/db_manager.py
50 51 52 53 | |
create_tables
create_tables(
sqlmodel_tables: Sequence[type[SQLModel]] | None = None,
) -> None
Source code in prediction_market_agent_tooling/tools/db/db_manager.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
google_utils
search_google_gcp
search_google_gcp(
query: str | None = None,
num: int = 3,
exact_terms: str | None = None,
exclude_terms: str | None = None,
link_site: str | None = None,
site_search: str | None = None,
site_search_filter: Literal["e", "i"] | None = None,
) -> list[str]
Search Google using a custom search engine.
Source code in prediction_market_agent_tooling/tools/google_utils.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
search_google_serper
search_google_serper(q: str) -> list[str]
Search Google using the Serper API.
Source code in prediction_market_agent_tooling/tools/google_utils.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
hexbytes_custom
hex_serializer
module-attribute
hex_serializer = plain_serializer_function_ser_schema(
function=lambda x: hex()
)
BaseHex
schema_pattern
class-attribute
schema_pattern: str = '^0x([0-9a-f][0-9a-f])*$'
schema_examples
class-attribute
schema_examples: tuple[str, ...] = (
"0x",
"0xd4",
"0xd4e5",
"0xd4e56740",
"0xd4e56740f876aef8",
"0xd4e56740f876aef8c010b86a40d5f567",
"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
)
HexBytes
Bases: HexBytes, BaseHex
Use when receiving hexbytes.HexBytes values. Includes
a pydantic validator and serializer.
schema_pattern
class-attribute
schema_pattern: str = '^0x([0-9a-f][0-9a-f])*$'
schema_examples
class-attribute
schema_examples: tuple[str, ...] = (
"0x",
"0xd4",
"0xd4e5",
"0xd4e56740",
"0xd4e56740f876aef8",
"0xd4e56740f876aef8c010b86a40d5f567",
"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
)
fromhex
classmethod
fromhex(hex_str: str) -> HexBytes
Source code in prediction_market_agent_tooling/tools/hexbytes_custom.py
58 59 60 61 | |
as_int
as_int() -> int
Source code in prediction_market_agent_tooling/tools/hexbytes_custom.py
69 70 | |
httpx_cached_client
HttpxCachedClient
HttpxCachedClient()
Source code in prediction_market_agent_tooling/tools/httpx_cached_client.py
5 6 7 8 9 10 11 | |
client
instance-attribute
client = CacheClient(storage=storage, controller=controller)
get_client
get_client() -> hishel.CacheClient
Source code in prediction_market_agent_tooling/tools/httpx_cached_client.py
13 14 | |
image_gen
image_gen
generate_image
generate_image(
prompt: str,
model: str = "dall-e-3",
size: Literal[
"256x256",
"512x512",
"1024x1024",
"1792x1024",
"1024x1792",
] = "1024x1024",
quality: Literal["standard", "hd"] = "standard",
) -> ImageType
Source code in prediction_market_agent_tooling/tools/image_gen/image_gen.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
market_thumbnail_gen
rewrite_question_into_image_generation_prompt
rewrite_question_into_image_generation_prompt(
question: str,
) -> str
Source code in prediction_market_agent_tooling/tools/image_gen/market_thumbnail_gen.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
generate_image_for_market
generate_image_for_market(question: str) -> ImageType
Source code in prediction_market_agent_tooling/tools/image_gen/market_thumbnail_gen.py
34 35 36 | |
ipfs
ipfs_handler
IPFSHandler
IPFSHandler(api_keys: APIKeys)
Source code in prediction_market_agent_tooling/tools/ipfs/ipfs_handler.py
12 13 14 15 16 | |
pinata
instance-attribute
pinata = PinataPy(get_secret_value(), get_secret_value())
upload_file
upload_file(file_path: str) -> IPFSCIDVersion0
Source code in prediction_market_agent_tooling/tools/ipfs/ipfs_handler.py
18 19 20 21 22 23 | |
store_agent_result
store_agent_result(
agent_result: IPFSAgentResult,
) -> IPFSCIDVersion0
Source code in prediction_market_agent_tooling/tools/ipfs/ipfs_handler.py
25 26 27 28 29 30 | |
unpin_file
unpin_file(hash_to_remove: str) -> None
Source code in prediction_market_agent_tooling/tools/ipfs/ipfs_handler.py
32 33 | |
is_invalid
QUESTION_IS_INVALID_PROMPT
module-attribute
QUESTION_IS_INVALID_PROMPT = 'Main signs about an invalid question (sometimes referred to as a "market"):\n- The market\'s question is about immoral violence, death or assassination.\n- The violent event can be caused by a single conscious being.\n- The violent event is done illegally.\n- The market should not directly incentivize immoral violent (such as murder, rape or unjust imprisonment) actions which could likely be performed by any participant.\n- Invalid: Will Donald Trump be alive on the 01/12/2021? (Anyone could bet on "No" and kill him for a guaranteed profit. Anyone could bet on "Yes" to effectively put a bounty on his head).\n- Invalid: Will Hera be a victim of swatting in 2020? (Anyone could falsely call the emergency services on him in order to win the bet)\n- This does not prevent markets:\n - Whose topics are violent events not caused by conscious beings.\n - Valid: How many people will die from COVID19 in 2020? (Viruses don’t use prediction markets).\n - Whose main source of uncertainty is not related to a potential violent action.\n - Valid: Will Trump win the 2020 US presidential election? (The main source of uncertainty is the vote of US citizens, not a potential murder of a presidential candidate).\n - Which could give an incentive only to specific participants to commit an immoral violent action, but are in practice unlikely.\n - Valid: Will the US be engaged in a military conflict with a UN member state in 2021? (It’s unlikely for the US to declare war in order to win a bet on this market).\n - Valid: Will Derek Chauvin go to jail for the murder of George Flyod? (It’s unlikely that the jurors would collude to make a wrong verdict in order to win this market).\n- Questions with relative dates will resolve as invalid. Dates must be stated in absolute terms, not relative depending on the current time. But they can be relative to the event specified in the question itself.\n- Invalid: Who will be the president of the United States in 6 months? ("in 6 months depends on the current time").\n- Invalid: In the next 14 days, will Gnosis Chain gain another 1M users? ("in the next 14 days depends on the current time").\n- Valid: Will GNO price go up 10 days after Gnosis Pay cashback program is announced? ("10 days after" is relative to the event in the question, so we can determine absolute value).\n- Questions about moral values and not facts will be resolved as invalid.\n- Invalid: "Is it ethical to eat meat?".\n\nFollow a chain of thought to evaluate if the question is invalid:\n\nFirst, write the parts of the following question:\n\n"{question}"\n\nThen, write down what is the future event of the question, what it refers to and when that event will happen if the question contains it.\n\nThen, explain why do you think it is or isn\'t invalid.\n\nFinally, write your final decision, write `decision: ` followed by either "yes it is invalid" or "no it isn\'t invalid" about the question. Don\'t write anything else after that. You must include "yes" or "no".\n'
is_invalid
is_invalid(
question: str,
engine: str = "gpt-4o-2024-08-06",
temperature: float = LLM_SUPER_LOW_TEMPERATURE,
seed: int = LLM_SEED,
prompt_template: str = QUESTION_IS_INVALID_PROMPT,
max_tokens: int = 1024,
) -> bool
Evaluate if the question is actually answerable.
Source code in prediction_market_agent_tooling/tools/is_invalid.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
is_predictable
QUESTION_IS_PREDICTABLE_BINARY_PROMPT
module-attribute
QUESTION_IS_PREDICTABLE_BINARY_PROMPT = "Main signs about a fully qualified question (sometimes referred to as a \"market\"):\n- The market's question needs to be specific, without use of pronouns.\n- The market must refer to a future event — not something that already happened. This is a hard requirement. If the event has already occurred, the question is not fully qualified, even if it is specific and answerable.\n- The market's question needs to have a clear time frame.\n- The event in the market's question doesn't have to be ultra-specific, it will be decided by a crowd later on.\n- If the market's question contains date, but without an year, it's okay.\n- If the market's question contains year, but without an exact date, it's okay.\n- The market's question can not be about itself or refer to itself.\n- The answer is probably Google-able, after the event happened.\n\nFollow a chain of thought to evaluate if the question is fully qualified:\n\nFirst, write the parts of the following question:\n\n\"{question}\"\n\nThen, write down what is the future event of the question, what it refers to and when that event will happen if the question contains it.\n\nThen, explain why do you think it is or isn't fully qualified.\n\nFinally, write your final decision, write `decision: ` followed by either \"yes it is fully qualified\" or \"no it isn't fully qualified\" about the question. Don't write anything else after that. You must include \"yes\" or \"no\".\n"
QUESTION_IS_PREDICTABLE_WITHOUT_DESCRIPTION_PROMPT
module-attribute
QUESTION_IS_PREDICTABLE_WITHOUT_DESCRIPTION_PROMPT = 'Main signs about a fully self-contained question (sometimes referred to as a "market"):\n- Description of the question can not contain any additional information required to answer the question.\n\nFor the question:\n\n```\n{question}\n```\n\nAnd the description:\n\n```\n{description}\n```\n\nDescription refers only to the text above and nothing else. \n\nEven if the question is somewhat vague, but even the description does not contain enough of extra information, it\'s okay and the question is fully self-contained. \nIf the question is vague and the description contains the information required to answer the question, it\'s not fully self-contained and the answer is "no".\n\nFollow a chain of thought to evaluate if the question doesn\'t need the description to be answered.\n\nStart by examining the question and the description in detail. Write down their parts, what they refer to and what they contain. \n\nContinue by writing comparison of the question and the description content. Write down what the question contains and what the description contains.\n\nExplain, why do you think it does or doesn\'t need the description.\n\nDescription can contain additional information, but it can not contain any information required to answer the question.\n\nDescription can contain additional information about the exact resolution criteria, but the question should be answerable even without it.\n\nAs long as the question contains some time frame, it\'s okay if the description only specifies it in more detail.\n\nDescription usually contains the question in more detailed form, but the question on its own should be answerable.\n\nFor example, that means, description can not contain date if question doesn\'t contain it. Description can not contain target if the question doesn\'t contain it, etc.\n\nFinally, write your final decision, write `decision: ` followed by either "yes it is fully self-contained" or "no it isn\'t fully self-contained" about the question. Don\'t write anything else after that. You must include "yes" or "no".\n'
is_predictable_binary
is_predictable_binary(
question: str,
engine: str = "gpt-4o-2024-08-06",
prompt_template: str = QUESTION_IS_PREDICTABLE_BINARY_PROMPT,
max_tokens: int = 1024,
) -> bool
Evaluate if the question is actually answerable.
Source code in prediction_market_agent_tooling/tools/is_predictable.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
is_predictable_without_description
is_predictable_without_description(
question: str,
description: str,
engine: str = "gpt-4o-2024-08-06",
prompt_template: str = QUESTION_IS_PREDICTABLE_WITHOUT_DESCRIPTION_PROMPT,
max_tokens: int = 1024,
) -> bool
Evaluate if the question is fully self-contained.
Source code in prediction_market_agent_tooling/tools/is_predictable.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
parse_decision_yes_no_completion
parse_decision_yes_no_completion(
question: str, completion: str
) -> bool
Source code in prediction_market_agent_tooling/tools/is_predictable.py
161 162 163 164 165 166 167 168 169 170 171 172 173 | |
langfuse_
P
module-attribute
P = ParamSpec('P')
R
module-attribute
R = TypeVar('R')
observe
observe(
name: Optional[str] = None,
as_type: Optional[Literal["generation"]] = None,
capture_input: bool = True,
capture_output: bool = True,
transform_to_string: Optional[
Callable[[Iterable[Any]], str]
] = None,
) -> Callable[[Callable[P, R]], Callable[P, R]]
Source code in prediction_market_agent_tooling/tools/langfuse_.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
get_langfuse_langchain_config
get_langfuse_langchain_config() -> RunnableConfig
Source code in prediction_market_agent_tooling/tools/langfuse_.py
30 31 32 33 34 | |
langfuse_client_utils
ProcessMarketTrace
Bases: BaseModel
timestamp
instance-attribute
timestamp: int
market
instance-attribute
market: OmenAgentMarket
answer
instance-attribute
answer: CategoricalProbabilisticAnswer
trades
instance-attribute
trades: list[PlacedTrade]
timestamp_datetime
property
timestamp_datetime: DatetimeUTC
buy_trade
property
buy_trade: PlacedTrade | None
from_langfuse_trace
staticmethod
from_langfuse_trace(
trace: TraceWithDetails,
) -> t.Optional[ProcessMarketTrace]
Source code in prediction_market_agent_tooling/tools/langfuse_client_utils.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
ResolvedBetWithTrace
Bases: BaseModel
bet
instance-attribute
bet: ResolvedBet
trace
instance-attribute
trace: ProcessMarketTrace
get_traces_for_agent
get_traces_for_agent(
agent_name: str,
trace_name: str,
from_timestamp: DatetimeUTC,
has_output: bool,
client: Langfuse,
to_timestamp: DatetimeUTC | None = None,
tags: str | list[str] | None = None,
) -> list[TraceWithDetails]
Fetch agent traces using pagination
Source code in prediction_market_agent_tooling/tools/langfuse_client_utils.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
trace_to_omen_agent_market
trace_to_omen_agent_market(
trace: TraceWithDetails,
) -> OmenAgentMarket | None
Source code in prediction_market_agent_tooling/tools/langfuse_client_utils.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
trace_to_answer
trace_to_answer(
trace: TraceWithDetails,
) -> CategoricalProbabilisticAnswer
Source code in prediction_market_agent_tooling/tools/langfuse_client_utils.py
121 122 123 124 | |
trace_to_trades
trace_to_trades(
trace: TraceWithDetails,
) -> list[PlacedTrade]
Source code in prediction_market_agent_tooling/tools/langfuse_client_utils.py
127 128 129 130 | |
get_closest_datetime_from_list
get_closest_datetime_from_list(
ref_datetime: DatetimeUTC, datetimes: list[DatetimeUTC]
) -> int
Get the index of the closest datetime to the reference datetime
Source code in prediction_market_agent_tooling/tools/langfuse_client_utils.py
133 134 135 136 137 138 139 140 141 | |
get_trace_for_bet
get_trace_for_bet(
bet: ResolvedBet, traces: list[ProcessMarketTrace]
) -> ProcessMarketTrace | None
Source code in prediction_market_agent_tooling/tools/langfuse_client_utils.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
omen
reality_accuracy
RealityAccuracyReport
Bases: BaseModel
total
instance-attribute
total: int
correct
instance-attribute
correct: int
accuracy
property
accuracy: float
reality_accuracy
reality_accuracy(
user: ChecksumAddress, since: timedelta
) -> RealityAccuracyReport
Source code in prediction_market_agent_tooling/tools/omen/reality_accuracy.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
user_was_correct
user_was_correct(
user: ChecksumAddress, responses: list[RealityResponse]
) -> bool | None
Source code in prediction_market_agent_tooling/tools/omen/reality_accuracy.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
sell_positions
sell_all
sell_all(
api_keys: APIKeys,
closing_later_than_days: int,
auto_withdraw: bool = True,
) -> None
Helper function to sell all existing outcomes on Omen that would resolve later than in X days.
Source code in prediction_market_agent_tooling/tools/omen/sell_positions.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
parallelism
A
module-attribute
A = TypeVar('A')
B
module-attribute
B = TypeVar('B')
par_map
par_map(
items: list[A],
func: Callable[[A], B],
max_workers: int = 5,
) -> list[B]
Applies the function to each element using the specified executor. Awaits for all results.
Source code in prediction_market_agent_tooling/tools/parallelism.py
11 12 13 14 15 16 17 18 19 20 21 22 | |
par_generator
par_generator(
items: list[A],
func: Callable[[A], B],
max_workers: int = 5,
) -> Generator[B, None, None]
Applies the function to each element using the specified executor. Yields results as they come.
Source code in prediction_market_agent_tooling/tools/parallelism.py
25 26 27 28 29 30 31 32 33 | |
relevant_news_analysis
data_models
RelevantNewsAnalysis
Bases: BaseModel
reasoning
class-attribute
instance-attribute
reasoning: str = Field(
...,
description="The reason why the news contains information relevant to the given question. Or if no news is relevant, why not.",
)
contains_relevant_news
class-attribute
instance-attribute
contains_relevant_news: bool = Field(
...,
description="A boolean flag for whether the news contains information relevant to the given question.",
)
RelevantNews
Bases: BaseModel
question
instance-attribute
question: str
url
instance-attribute
url: str
summary
instance-attribute
summary: str
relevance_reasoning
instance-attribute
relevance_reasoning: str
days_ago
instance-attribute
days_ago: int
from_tavily_result_and_analysis
staticmethod
from_tavily_result_and_analysis(
question: str,
days_ago: int,
tavily_result: TavilyResult,
relevant_news_analysis: RelevantNewsAnalysis,
) -> RelevantNews
Source code in prediction_market_agent_tooling/tools/relevant_news_analysis/data_models.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
NoRelevantNews
Bases: BaseModel
A placeholder model for when no relevant news is found. Enables ability to distinguish between 'a cache hit with no news' and 'a cache miss'.
relevant_news_analysis
SUMMARISE_RELEVANT_NEWS_PROMPT_TEMPLATE
module-attribute
SUMMARISE_RELEVANT_NEWS_PROMPT_TEMPLATE = "\nYou are an expert news analyst, tracking stories that may affect your prediction to the outcome of a particular QUESTION.\n\nYour role is to identify only the relevant information from a scraped news site (RAW_CONTENT), analyse it, and determine whether it contains developments or announcements occurring **after** the DATE_OF_INTEREST that could affect the outcome of the QUESTION.\n\nNote that the news article may be published after the DATE_OF_INTEREST, but reference information that is older than the DATE_OF_INTEREST.\n\n[QUESTION]\n{question}\n\n[DATE_OF_INTEREST]\n{date_of_interest}\n\n[RAW_CONTENT]\n{raw_content}\n\nFor your analysis, you should:\n- Discard the 'noise' from the raw content (e.g. ads, irrelevant content)\n- Consider ONLY information that would have a notable impact on the outcome of the question.\n- Consider ONLY information relating to an announcement or development that occurred **after** the DATE_OF_INTEREST.\n- Present this information concisely in your reasoning.\n- In your reasoning, do not use the term 'DATE_OF_INTEREST' directly. Use the actual date you are referring to instead.\n- In your reasoning, do not use the term 'RAW_CONTENT' directly. Refer to it as 'the article', or quote the content you are referring to.\n\n{format_instructions}\n"
analyse_news_relevance
analyse_news_relevance(
raw_content: str,
question: str,
date_of_interest: date,
model: str,
temperature: float,
) -> RelevantNewsAnalysis
Analyse whether the news contains new (relative to the given date) information relevant to the given question.
Source code in prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
get_certified_relevant_news_since
get_certified_relevant_news_since(
question: str, days_ago: int
) -> RelevantNews | None
Get relevant news since a given date for a given question. Retrieves possibly relevant news from tavily, then checks that it is relevant via an LLM call.
Source code in prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
get_certified_relevant_news_since_cached
get_certified_relevant_news_since_cached(
question: str,
days_ago: int,
cache: RelevantNewsResponseCache,
) -> RelevantNews | None
Source code in prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
relevant_news_cache
RelevantNewsCacheModel
Bases: SQLModel
id
class-attribute
instance-attribute
id: int | None = Field(default=None, primary_key=True)
question
class-attribute
instance-attribute
question: str = Field(index=True)
datetime_
class-attribute
instance-attribute
datetime_: datetime = Field(index=True)
days_ago
instance-attribute
days_ago: int
json_dump
instance-attribute
json_dump: str | None
RelevantNewsResponseCache
RelevantNewsResponseCache(api_keys: APIKeys | None = None)
Source code in prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_cache.py
27 28 29 30 31 | |
db_manager
instance-attribute
db_manager = DBManager(get_secret_value())
find
find(
question: str, days_ago: int
) -> RelevantNews | NoRelevantNews | None
Source code in prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_cache.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
save
save(
question: str,
days_ago: int,
relevant_news: RelevantNews | None,
) -> None
Source code in prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_cache.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
safe
create_safe
create_safe(
ethereum_client: EthereumClient,
account: LocalAccount,
owners: list[str],
salt_nonce: int,
threshold: int = 1,
without_events: bool = False,
) -> ChecksumAddress | None
Source code in prediction_market_agent_tooling/tools/safe.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
singleton
SingletonMeta
Bases: type, Generic[_T]
The Singleton class can be implemented in different ways in Python. Some possible methods include: base class, decorator, metaclass. We will use the metaclass because it is best suited for this purpose.
streamlit_user_login
LoggedInUser
Bases: BaseModel
email
instance-attribute
email: str
password
instance-attribute
password: SecretStr
LoginSettings
Bases: BaseSettings
model_config
class-attribute
instance-attribute
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
free_for_everyone
class-attribute
instance-attribute
free_for_everyone: bool = False
free_access_codes
class-attribute
instance-attribute
free_access_codes: list[SecretStr] = []
users
class-attribute
instance-attribute
users: list[LoggedInUser] = []
LoggedEnum
Bases: str, Enum
SELF_PAYING
class-attribute
instance-attribute
SELF_PAYING = 'self_paying'
FREE_ACCESS
class-attribute
instance-attribute
FREE_ACCESS = 'free_access'
USER_LOGGED_IN
class-attribute
instance-attribute
USER_LOGGED_IN = 'user_logged_in'
find_logged_in_user
find_logged_in_user(
email: str, password: SecretStr
) -> LoggedInUser | None
Source code in prediction_market_agent_tooling/tools/streamlit_user_login.py
30 31 32 33 34 35 36 37 38 39 40 | |
streamlit_login
streamlit_login() -> tuple[LoggedEnum, LoggedInUser | None]
Source code in prediction_market_agent_tooling/tools/streamlit_user_login.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
tavily
tavily_models
TavilyResult
Bases: BaseModel
title
instance-attribute
title: str
url
instance-attribute
url: str
content
instance-attribute
content: str
score
instance-attribute
score: float
raw_content
instance-attribute
raw_content: str | None
TavilyResponse
Bases: BaseModel
query
instance-attribute
query: str
follow_up_questions
class-attribute
instance-attribute
follow_up_questions: str | None = None
answer
instance-attribute
answer: str
images
instance-attribute
images: list[str]
results
instance-attribute
results: list[TavilyResult]
response_time
instance-attribute
response_time: float
tavily_search
DEFAULT_SCORE_THRESHOLD
module-attribute
DEFAULT_SCORE_THRESHOLD = 0.75
tavily_search
tavily_search(
query: str,
search_depth: Literal["basic", "advanced"] = "advanced",
topic: Literal["general", "news"] = "general",
news_since: date | None = None,
max_results: int = 5,
include_domains: Sequence[str] | None = None,
exclude_domains: Sequence[str] | None = None,
include_answer: bool = True,
include_raw_content: bool = True,
include_images: bool = True,
use_cache: bool = False,
api_keys: APIKeys | None = None,
) -> TavilyResponse
Argument default values are different from the original method, to return everything by default, because it can be handy in the future and it doesn't increase the costs.
Source code in prediction_market_agent_tooling/tools/tavily/tavily_search.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
get_relevant_news_since
get_relevant_news_since(
question: str,
news_since: date,
score_threshold: float = DEFAULT_SCORE_THRESHOLD,
max_results: int = 3,
) -> list[TavilyResult]
Source code in prediction_market_agent_tooling/tools/tavily/tavily_search.py
106 107 108 109 110 111 112 113 114 115 116 117 118 | |
transaction_cache
TransactionBlockCache
TransactionBlockCache(web3: Web3)
Source code in prediction_market_agent_tooling/tools/transaction_cache.py
11 12 13 14 | |
block_number_cache
instance-attribute
block_number_cache = Cache('.cache/block_cache_dir')
block_timestamp_cache
instance-attribute
block_timestamp_cache = Cache('.cache/timestamp_cache_dir')
web3
instance-attribute
web3 = web3
fetch_block_number
fetch_block_number(transaction_hash: str) -> int
Source code in prediction_market_agent_tooling/tools/transaction_cache.py
16 17 18 19 20 21 22 23 | |
fetch_block_timestamp
fetch_block_timestamp(block_number: int) -> int
Source code in prediction_market_agent_tooling/tools/transaction_cache.py
25 26 27 28 29 30 31 32 | |
get_block_number
get_block_number(tx_hash: str) -> int
Source code in prediction_market_agent_tooling/tools/transaction_cache.py
34 35 36 37 38 39 40 | |
get_block_timestamp
get_block_timestamp(block_number: int) -> int
Source code in prediction_market_agent_tooling/tools/transaction_cache.py
42 43 44 45 46 47 48 | |
utils
T
module-attribute
T = TypeVar('T')
LLM_SUPER_LOW_TEMPERATURE
module-attribute
LLM_SUPER_LOW_TEMPERATURE = 1e-08
LLM_SEED
module-attribute
LLM_SEED = 0
BPS_CONSTANT
module-attribute
BPS_CONSTANT = 10000
BaseModelT
module-attribute
BaseModelT = TypeVar('BaseModelT', bound=BaseModel)
check_not_none
check_not_none(
value: Optional[T],
msg: str = "Value shouldn't be None.",
exp: Type[ValueError] = ValueError,
) -> T
Utility to remove optionality from a variable.
Useful for cases like this:
keys = pma.utils.get_keys()
pma.omen.omen_buy_outcome_tx(
from_address=check_not_none(keys.bet_from_address), # <-- No more Optional[HexAddress], so type checker will be happy.
...,
)
Source code in prediction_market_agent_tooling/tools/utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
should_not_happen
should_not_happen(
msg: str = "Should not happen.",
exp: Type[ValueError] = ValueError,
) -> NoReturn
Utility function to raise an exception with a message.
Handy for cases like this:
return (
1 if variable == X
else 2 if variable == Y
else 3 if variable == Z
else should_not_happen(f"Variable {variable} is unknown.")
)
To prevent silent bugs with useful error message.
Source code in prediction_market_agent_tooling/tools/utils.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
export_requirements_from_toml
export_requirements_from_toml(output_dir: str) -> None
Source code in prediction_market_agent_tooling/tools/utils.py
80 81 82 83 84 85 86 87 88 89 | |
utcnow
utcnow() -> DatetimeUTC
Source code in prediction_market_agent_tooling/tools/utils.py
92 93 | |
utc_datetime
utc_datetime(
year: int,
month: int,
day: int,
hour: int = 0,
minute: int = 0,
second: int = 0,
microsecond: int = 0,
*,
fold: int = 0,
) -> DatetimeUTC
Source code in prediction_market_agent_tooling/tools/utils.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_current_git_commit_sha
get_current_git_commit_sha() -> str
Source code in prediction_market_agent_tooling/tools/utils.py
121 122 123 124 125 | |
to_int_timestamp
to_int_timestamp(dt: datetime) -> int
Source code in prediction_market_agent_tooling/tools/utils.py
128 129 | |
get_current_git_branch
get_current_git_branch() -> str
Source code in prediction_market_agent_tooling/tools/utils.py
132 133 134 135 136 | |
get_current_git_url
get_current_git_url() -> str
Source code in prediction_market_agent_tooling/tools/utils.py
139 140 141 142 143 | |
response_to_json
response_to_json(response: Response) -> dict[str, Any]
Source code in prediction_market_agent_tooling/tools/utils.py
146 147 148 149 | |
response_to_model
response_to_model(
response: Response, model: Type[BaseModelT]
) -> BaseModelT
Source code in prediction_market_agent_tooling/tools/utils.py
155 156 157 158 159 160 161 162 | |
response_list_to_model
response_list_to_model(
response: Response, model: Type[BaseModelT]
) -> list[BaseModelT]
Source code in prediction_market_agent_tooling/tools/utils.py
165 166 167 168 169 170 171 172 | |
secret_str_from_env
secret_str_from_env(key: str) -> SecretStr | None
Source code in prediction_market_agent_tooling/tools/utils.py
175 176 177 | |
prob_uncertainty
prob_uncertainty(prob: Probability) -> float
Returns a value between 0 and 1, where 0 means the market is not uncertain at all and 1 means it's completely uncertain.
Examples:
- Market's probability is 0.5, so the market is completely uncertain: prob_uncertainty(0.5) == 1
- Market's probability is 0.1, so the market is quite certain about NO: prob_uncertainty(0.1) == 0.468
- Market's probability is 0.95, so the market is quite certain about YES: prob_uncertainty(0.95) == 0.286
Source code in prediction_market_agent_tooling/tools/utils.py
180 181 182 183 184 185 186 187 188 189 | |
calculate_sell_amount_in_collateral
calculate_sell_amount_in_collateral(
shares_to_sell: OutcomeToken,
outcome_index: int,
pool_balances: list[OutcomeToken],
fees: MarketFees,
) -> CollateralToken
Computes the amount of collateral that needs to be sold to get shares
amount of shares. Returns None if the amount can't be computed.
Taken from https://github.com/protofire/omen-exchange/blob/29d0ab16bdafa5cc0d37933c1c7608a055400c73/app/src/util/tools/fpmm/trading/index.ts#L99 Simplified for binary markets.
Source code in prediction_market_agent_tooling/tools/utils.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
extract_error_from_retry_error
extract_error_from_retry_error(
e: BaseException | RetryError,
) -> BaseException
Source code in prediction_market_agent_tooling/tools/utils.py
236 237 238 239 240 241 242 | |
web3_utils
ONE_NONCE
module-attribute
ONE_NONCE = Nonce(1)
ONE_XDAI
module-attribute
ONE_XDAI = xDai(1)
ZERO_BYTES
module-attribute
ZERO_BYTES = HexBytes(HASH_ZERO)
NOT_REVERTED_ICASE_REGEX_PATTERN
module-attribute
NOT_REVERTED_ICASE_REGEX_PATTERN = '(?i)(?!.*reverted.*)'
generate_private_key
generate_private_key() -> PrivateKey
Source code in prediction_market_agent_tooling/tools/web3_utils.py
39 40 | |
private_key_to_public_key
private_key_to_public_key(
private_key: SecretStr,
) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/web3_utils.py
43 44 45 | |
verify_address
verify_address(address: str) -> ChecksumAddress
Source code in prediction_market_agent_tooling/tools/web3_utils.py
48 49 50 51 52 53 | |
check_tx_receipt
check_tx_receipt(receipt: TxReceipt) -> None
Source code in prediction_market_agent_tooling/tools/web3_utils.py
56 57 58 59 60 | |
unwrap_generic_value
unwrap_generic_value(value: Any) -> Any
Source code in prediction_market_agent_tooling/tools/web3_utils.py
63 64 65 66 67 68 69 70 71 72 73 74 | |
parse_function_params
parse_function_params(
params: Optional[
list[Any] | tuple[Any] | dict[str, Any]
],
) -> list[Any] | tuple[Any]
Source code in prediction_market_agent_tooling/tools/web3_utils.py
77 78 79 80 81 82 83 84 85 86 87 88 89 | |
call_function_on_contract
call_function_on_contract(
web3: Web3,
contract_address: ChecksumAddress,
contract_abi: ABI,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
) -> Any
Source code in prediction_market_agent_tooling/tools/web3_utils.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
prepare_tx
prepare_tx(
web3: Web3,
contract_address: ChecksumAddress,
contract_abi: ABI,
from_address: ChecksumAddress | None,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
access_list: Optional[AccessList] = None,
tx_params: Optional[TxParams] = None,
) -> TxParams
Source code in prediction_market_agent_tooling/tools/web3_utils.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
send_function_on_contract_tx
send_function_on_contract_tx(
web3: Web3,
contract_address: ChecksumAddress,
contract_abi: ABI,
from_private_key: PrivateKey,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/web3_utils.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
send_function_on_contract_tx_using_safe
send_function_on_contract_tx_using_safe(
web3: Web3,
contract_address: ChecksumAddress,
contract_abi: ABI,
from_private_key: PrivateKey,
safe_address: ChecksumAddress,
function_name: str,
function_params: Optional[
list[Any] | dict[str, Any]
] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/web3_utils.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
sign_send_and_get_receipt_tx
sign_send_and_get_receipt_tx(
web3: Web3,
tx_params_new: TxParams,
from_private_key: PrivateKey,
timeout: int = 180,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/web3_utils.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
send_xdai_to
send_xdai_to(
web3: Web3,
from_private_key: PrivateKey,
to_address: ChecksumAddress,
value: xDaiWei,
data_text: Optional[str | bytes] = None,
tx_params: Optional[TxParams] = None,
timeout: int = 180,
) -> TxReceipt
Source code in prediction_market_agent_tooling/tools/web3_utils.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
ipfscidv0_to_byte32
ipfscidv0_to_byte32(cid: IPFSCIDVersion0) -> HexBytes
Convert ipfscidv0 to 32 bytes. Modified from https://github.com/emg110/ipfs2bytes32/blob/main/python/ipfs2bytes32.py
Source code in prediction_market_agent_tooling/tools/web3_utils.py
333 334 335 336 337 338 339 340 | |
byte32_to_ipfscidv0
byte32_to_ipfscidv0(hex: HexBytes) -> IPFSCIDVersion0
Convert 32 bytes hex to ipfscidv0. Modified from https://github.com/emg110/ipfs2bytes32/blob/main/python/ipfs2bytes32.py
Source code in prediction_market_agent_tooling/tools/web3_utils.py
343 344 345 346 347 348 349 | |
get_receipt_block_timestamp
get_receipt_block_timestamp(
receipt_tx: TxReceipt, web3: Web3
) -> int
Source code in prediction_market_agent_tooling/tools/web3_utils.py
352 353 354 355 356 357 358 359 360 361 362 363 | |
is_valid_wei
is_valid_wei(value: Web3Wei) -> bool
Source code in prediction_market_agent_tooling/tools/web3_utils.py
366 367 | |