rubi.contracts package
Subpackages
Submodules
rubi.contracts.base_contract module
- class rubi.contracts.base_contract.BaseContract(w3: web3.Web3, contract: web3.contract.Contract, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None)
Bases:
objectBase class representation of a contract which defines the structure of a contract and provides several helpful methods that can be used by subclass contracts that extend this contract.
- Parameters:
w3 (Web3) – Web3 instance
contract (Contract) – Contract instance
wallet (Optional[ChecksumAddress]) – a wallet address of the signer (optional, default is None)
key (Optional[str]) – the private key of the signer (optional, default is None)
- classmethod from_address_and_abi(w3: web3.Web3, address: eth_typing.ChecksumAddress, contract_abi: web3.types.ABI, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None) BaseContract
Create a BaseContract instance from the contract address and ABI.
- Parameters:
w3 (Web3) – The Web3 instance.
address (ChecksumAddress) – The address of the contract.
contract_abi (ABI) – The ABI of the contract.
wallet (Optional[ChecksumAddress]) – The wallet address to use for interacting with the contract (optional, default is None).
key (Optional[str]) – The private key of the wallet (optional, default is None).
- Returns:
An instance of BaseContract.
- Return type:
- start_event_poller(pair_name: str, event_type: Type[BaseEvent], argument_filters: Dict[str, Any] | None = None, event_handler: Callable | None = None, poll_time: int = 2) None
Start a thread which runs an event poller for a specific event type.
- Parameters:
pair_name (str) – The name of the pair we are monitoring events of.
event_type (Type[BaseEvent]) – The type of event to poll for.
argument_filters (Optional[Dict[str, Any]]) – Optional filters that the node will filter events on (optional, default is None).
event_handler (Optional[Callable]) – Optional event handler function. Defaults to using the events default handler.
poll_time (int) – The time interval between each poll in seconds. Defaults to 2 seconds.
rubi.contracts.erc20 module
- class rubi.contracts.erc20.ERC20(w3: web3.Web3, contract: web3.contract.Contract, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None)
Bases:
BaseContractthis class represents a contract that implements the ERC20 standard. it is used to read the contract instance. if a wallet and key are passed in instantiation then this class can also be used to write to the contract instance.
- Parameters:
w3 (Web3) – Web3 instance
contract (Contract) – Contract instance
wallet (Optional[ChecksumAddress]) – a wallet address of the signer (optional, default is None)
key (Optional[str]) – the private key of the signer (optional, default is None)
- allowance(owner: eth_typing.ChecksumAddress, spender: eth_typing.ChecksumAddress) int
Reads the allowance of the spender from the owner for the erc20 contract
- Parameters:
owner (str) – address that owns the erc20 tokens
spender (str) – address that is allowed to spend the erc20 tokens
- Returns:
the allowance of the spender from the owner for the contract, in the integer representation of the token
- Return type:
int
- approve(spender: eth_typing.ChecksumAddress, amount: int, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Approves the spender to spend the amount of the erc20 token from the signer’s wallet
- Parameters:
spender (ChecksumAddress) – address of the spender
amount (int) – amount of the erc20 token to approve the spender to spend
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- balance_of(account: eth_typing.ChecksumAddress) int
Reads the erc20 balance of the account
- Parameters:
account (str) – the address of the account to read the balance of
- Returns:
the balance of the account, in the integer representation of the token
- Return type:
int
- decimals() int
Reads the number of decimals of the erc20 token - warning this is not a constant function, so it may result in an error in its current implementation
- Returns:
the number of decimals of the erc20 token
- Return type:
int
- decrease_allowance(spender: eth_typing.ChecksumAddress, subtracted_value: int, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Decreases the allowance of the spender by the subtracted_value
- Parameters:
spender (ChecksumAddress) – address of the spender
subtracted_value (int) – amount to decrease the allowance by, in the integer representation of the erc20 token
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- classmethod from_address(w3: web3.Web3, address: eth_typing.ChecksumAddress, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None) ERC20
Create an ERC20 instance based on an address and a network connection.
- Parameters:
w3 (Web3) – Web3 instance.
address (ChecksumAddress) – The address of the contract.
wallet (Optional[ChecksumAddress]) – Optional wallet address to use for interacting with the contract (optional, default is None).
key (Optional[str]) – Optional private key for the wallet (optional, default is None).
- Returns:
An ERC20 instance based on the address and network connection.
- Return type:
- classmethod from_network(name: str, network: Network, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None) ERC20
Create an ERC20 instance based on a Network instance and token name.
- Parameters:
name (str) – The name of the token.
network (Network) – A Network instance.
wallet (Optional[ChecksumAddress]) – Optional wallet address to use for interacting with the contract (optional, default is None).
key (Optional[str]) – Optional private key for the wallet (optional, default is None).
- Returns:
An ERC20 instance based on the Network instance and token name.
- Return type:
- Raises:
Exception – If the token name does not exist in the network configuration.
Exception – If the ERC20.json ABI file is not found in the network_config folder.
- increase_allowance(spender: eth_typing.ChecksumAddress, added_value: int, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Increases the allowance of the spender by the added_value
- Parameters:
spender (ChecksumAddress) – address of the spender
added_value (int) – amount to increase the allowance by, in the integer representation of the erc20 token
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- max_approval_amount() Decimal
return the max uint256 token approval amount. Note: this is not very secure and if you give this approval you should revoke it when you are done!
- Returns:
the max approval amount of a uint256 token in Decimal representation
- Return type:
Decimal
- name() str
Reads the name of the erc20 token
- Returns:
the name of the erc20 token
- Return type:
str
- symbol() str
Reads the symbol of the erc20 token
- Returns:
the symbol of the erc20 token
- Return type:
str
- to_decimal(number: int) Decimal
Converts an integer representation of the token to a Decimal representation of the token by dividing the integer by 10 to the power of the number of decimals of the token
- Parameters:
number (int) – the integer representation of the token
- Returns:
the Decimal representation of the token
- Return type:
Decimal
- to_integer(number: Decimal) int
Converts a Decimal representation of the token to an integer representation of the token by multiplying the float by 10 to the power of the number of decimals of the token
- Parameters:
number (Decimal) – the Decimal representation of the token
- Returns:
the integer representation of the token
- Return type:
int
- total_supply() int
Reads the total supply of the erc20 token
- Returns:
the total supply of the erc20 token, in the integer representation of the token
- Return type:
int
- transfer(recipient: eth_typing.ChecksumAddress, amount: int, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Transfers the amount of the erc20 token to the recipient
- Parameters:
recipient (ChecksumAddress) – address of the recipient
amount (int) – amount of the erc20 token to transfer
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- transfer_from(sender: eth_typing.ChecksumAddress, recipient: eth_typing.ChecksumAddress, amount: int, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Transfers the amount of the erc20 token from the sender to the recipient
- Parameters:
sender (ChecksumAddress) – address of the sender
recipient (ChecksumAddress) – address of the recipient
amount (int) – amount of the erc20 token to transfer
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
rubi.contracts.market module
- class rubi.contracts.market.RubiconMarket(w3: web3.Web3, contract: web3.contract.Contract, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None)
Bases:
BaseContractThis class represents the RubiconMarket.sol contract and by default has read functionality. If a wallet and key are passed in instantiation then this class can also be used to write to the contract instance.
- Parameters:
w3 (Web3) – Web3 instance
contract (Contract) – Contract instance
wallet (Optional[ChecksumAddress]) – a wallet address of the signer (optional, default is None)
key (Optional[str]) – the private key of the signer (optional, default is None)
- batch_cancel(ids: List[int], nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Cancel a set offer by offer id in a single transaction
- Parameters:
ids (List[int]) – the ids of the offers to cancel
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- batch_offer(pay_amts: List[int], pay_gems: List[eth_typing.ChecksumAddress], buy_amts: List[int], buy_gems: List[eth_typing.ChecksumAddress], nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Batch the placement of a set of offers in one transaction
- Parameters:
pay_amts (List[int]) – the amounts of the token being sold
pay_gems (List[ChecksumAddress]) – the addresses of the tokens being sold
buy_amts (List[int]) – the amounts of the token being bought
buy_gems (List[ChecksumAddress]) – the addresses of the tokens being bought
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- batch_requote(ids: List[int], pay_amts: List[int], pay_gems: List[eth_typing.ChecksumAddress], buy_amts: List[int], buy_gems: List[eth_typing.ChecksumAddress], nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Batch update a set of offers in a single transaction and return a list of new offer ids
- Parameters:
ids (List[int]) – the ids of the offers to cancel
pay_amts (List[int]) – the amounts of the token being sold
pay_gems (List[ChecksumAddress]) – the addresses of the tokens being sold
buy_amts (List[int]) – the amounts of the token being bought
buy_gems (List[ChecksumAddress]) – the addresses of the tokens being bought
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- buy_all_amount(buy_gem: eth_typing.ChecksumAddress, buy_amt: int, pay_gem: eth_typing.ChecksumAddress, max_fill_amount: int, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Buy the buy_amt of the buy_gem token in exchange for pay_gem, on the condition that it does not exceed the max_fill_amount of the pay_gem token
- Parameters:
buy_gem (ChecksumAddress) – the address of the tokens being bought
buy_amt (int) – the amount of the token being bought
pay_gem (ChecksumAddress) – the address of the tokens being sold
max_fill_amount (int) – maximum amount of the pay_gem token you want to pay
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- calculate_fees(amount: int) int
Calculate fees on an amount
- Parameters:
amount (int) – the address of the token being bought
- Returns:
the calculated fees on the amount
- Return type:
int
- cancel(id: int, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Cancel an offer by offer id
- Parameters:
id (int) – the id of the offer to cancel
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- classmethod from_network(network: Network, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None) RubiconMarket
Create a RubiconMarket instance based on a Network instance.
- Parameters:
network (Network) – A Network instance.
wallet (Optional[ChecksumAddress]) – Optional wallet address to use for interacting with the contract (optional, default is None).
key (Optional[str]) – Optional private key for the wallet (optional, default is None).
- Returns:
A RubiconMarket instance based on the Network instance.
- Return type:
- get_best_offer(sell_gem: eth_typing.ChecksumAddress, buy_gem: eth_typing.ChecksumAddress) int
Returns the best offer for the given pair of tokens
- Parameters:
sell_gem (str) – the address of the token being sold by the maker
buy_gem (str) – the address of the token being bought by the maker
- Returns:
the id of the best offer on the book, None if there is no offer on the book
- Return type:
int
- get_better_offer(id: int) int
Returns the id of the offer that is better than the given offer
- Parameters:
id (int) – the id of the offer
- Returns:
the id of the offer that is better than the given offer, none if there is no better offer
- Return type:
int
- get_buy_amount_with_fee(buy_gem: eth_typing.ChecksumAddress, pay_gem: eth_typing.ChecksumAddress, pay_amt: int) Tuple[int, int]
Returns the amount of the buy_gem you will receive if you send the pay_amt to the contract along with the amount to approve for the transaction
- Parameters:
buy_gem (ChecksumAddress) – the address of the token being bought
pay_gem (ChecksumAddress) – the address of the token being sold
pay_amt (int) – the amount of the token being sold to receive the token being bought
- Returns:
(buy_amt, approvalAmount) the amount of tokens that will be received and the amount to approve for the transaction
- Return type:
Tuple[int, int]
- get_maker_fee() int
Returns the maker fee on Rubicon
- Returns:
the maker fee
- Return type:
int
- get_min_sell(pay_gem: eth_typing.ChecksumAddress) int
Returns the minimum sell amount for an offer
- Parameters:
pay_gem (str) – the address of the token being sold by the maker
- Returns:
the minimum amount of pay_gem that can be sold in an offer
- Return type:
int
- get_offer(id: int) Tuple[int, eth_typing.ChecksumAddress, int, eth_typing.ChecksumAddress]
Returns the offer associated with the provided id
- Parameters:
id (int) – the id of the offer being queried
- Returns:
a description of the offer as (pay_amt, pay_gem, buy_amt, buy_gem)
- Return type:
Tuple[int, ChecksumAddress, int, ChecksumAddress]
- get_offer_count(sell_gem: eth_typing.ChecksumAddress, buy_gem: eth_typing.ChecksumAddress) int
Returns the number of offers for a token pair
- Parameters:
sell_gem (ChecksumAddress) – the address of the token being sold by the maker
buy_gem (ChecksumAddress) – the address of the token being bought by the maker
- Returns:
the number of offers for a token pair, None if there are no offers for the token pair
- Return type:
int
- get_pay_amount_with_fee(pay_gem: eth_typing.ChecksumAddress, buy_gem: eth_typing.ChecksumAddress, buy_amt: int) Tuple[int, int]
Returns the amount of the pay_gem you will need to pay to the contract to receive the buy_amt along with the amount to approve for the transaction
- Parameters:
buy_gem (ChecksumAddress) – the address of the token being bought
pay_gem (ChecksumAddress) – the address of the token being sold
buy_amt (int) – the amount of the token being bought
- Returns:
(pay_amt, approvalAmount) the amount of tokens that will be paid and the amount to approve for the transaction
- Return type:
Tuple[int, int]
- get_worse_offer(id: int) int
Returns the id of the offer that is worse than the given offer
- Parameters:
id (int) – the id of the offer
- Returns:
the id of the offer that is worse than the given offer, none if there is no worse offer
- Return type:
int
- offer(pay_amt: int, pay_gem: eth_typing.ChecksumAddress, buy_amt: int, buy_gem: eth_typing.ChecksumAddress, pos: int = 0, rounding: bool = False, owner: eth_typing.ChecksumAddress | None = None, recipient: eth_typing.ChecksumAddress | None = None, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Make a new offer to buy the buy_amt of the buy_gem token in exchange for the pay_amt of the pay_gem token
- Parameters:
pay_amt (int) – the amount of the token being sold
pay_gem (ChecksumAddress) – the address of the token being sold
buy_amt (int) – the amount of the token being bought
buy_gem (ChecksumAddress) – the address of the token being bought
pos (int) – position of the offer in the linked list, default to 0 unless the maker knows the position they want to insert the offer at
rounding – add rounding to match “close enough” orders, defaults to False
owner (Optional[ChecksumAddress]) – the owner of the offer, defaults to the wallet that was provided in instantiating this class. (optional, default is None)
recipient (Optional[ChecksumAddress]) – the recipient of the offer’s fill, defaults to the wallet that was provided in instantiating this class (optional, default is None)
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Type:
rounding: bool
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- sell_all_amount(pay_gem: eth_typing.ChecksumAddress, pay_amt: int, buy_gem: eth_typing.ChecksumAddress, min_fill_amount: int, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Sell the pay_amt of the pay_gem token in exchange for buy_gem, on the condition that you receive at least the min_fill_amount of the buy_gem token
- Parameters:
pay_gem (ChecksumAddress) – the address of the tokens being sold
pay_amt (int) – the amount of the token being sold
buy_gem (ChecksumAddress) – the address of the tokens being bought
min_fill_amount (int) – minimum amount of the buy_gem token you want to receive
nonce (Optional[int]) – nonce of the transaction, defaults to calling the chain state to get the nonce. (optional, default is None)
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – max fee that can be paid for gas, defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None)
max_priority_fee_per_gas (Optional[int]) – max priority fee that can be paid for gas, defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None)
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
rubi.contracts.router module
- class rubi.contracts.router.RubiconRouter(w3: web3.Web3, contract: web3.contract.Contract, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None)
Bases:
BaseContractThis class represents the RubiconRouter.sol contract and by default has read functionality. If a wallet and key are passed in instantiation then this class can also be used to write to the contract instance.
- Parameters:
w3 (Web3) – Web3 instance
contract (Contract) – Contract instance
wallet (Optional[ChecksumAddress]) – a wallet address of the signer (optional, default is None)
key (Optional[str]) – the private key of the signer (optional, default is None)
- check_claim_all_user_bonus_tokens(user: eth_typing.ChecksumAddress, target_bath_tokens: List[eth_typing.ChecksumAddress], token: eth_typing.ChecksumAddress) int
Checks the all bonus tokens that can be claimed by a user earned across all specified rubicon pools.
- Parameters:
user (ChecksumAddress) – The address of the user.
target_bath_tokens (List[ChecksumAddress]) – The list of target bath tokens to claim bonus from.
token (ChecksumAddress) – The address of the token for which the bonus is claimed.
- Returns:
The total amount earned across all pools.
- Return type:
int
- classmethod from_network(network: Network, wallet: eth_typing.ChecksumAddress | None = None, key: str | None = None) RubiconRouter
Create a RubiconRouter instance based on a Network instance.
- Parameters:
network (Network) – A Network instance.
wallet (Optional[ChecksumAddress]) – Optional wallet address to use for interacting with the contract (optional, default is None).
key (Optional[str]) – Optional private key for the wallet (optional, default is None).
- Returns:
A RubiconRouter instance based on the Network instance.
- Return type:
- get_best_offer_and_info(asset: eth_typing.ChecksumAddress, quote: eth_typing.ChecksumAddress) Tuple[int, int, eth_typing.ChecksumAddress, int, eth_typing.ChecksumAddress]
Retrieves the information and id of the best offer for a specific asset/quote pair.
- Parameters:
asset (ChecksumAddress) – The address of the asset token.
quote (ChecksumAddress) – The address of the quote token.
- Returns:
A tuple containing the ID of the best offer, the pay_amt, the address of the pay_gem, the buy_amt, and the address of the buy_gem.
- Return type:
Tuple[int, int, ChecksumAddress, int, ChecksumAddress]
- get_book_depth(token_in: eth_typing.ChecksumAddress, token_out: eth_typing.ChecksumAddress) Tuple[int, int]
Retrieves the depth of one side of the order book for a specific token pair along with the id of the best offer.
- Parameters:
token_in (ChecksumAddress) – The address of the quote.
token_out (ChecksumAddress) – The address of the asset.
- Returns:
A tuple containing the depth of the order book and the ID of the best offer for token_out/token_in.
- Return type:
Tuple[int, int]
- get_book_from_pair(asset: eth_typing.ChecksumAddress, quote: eth_typing.ChecksumAddress) Tuple[List[List[int]], List[List[int]]]
Retrieves the order book for a specific asset/quote pair.
- Parameters:
asset (ChecksumAddress) – The address of the asset token.
quote (ChecksumAddress) – The address of the quote token.
- Returns:
A tuple containing two lists: asks and bids. Each list contains a sublist of length 3, representing the order book entries in the following format (pay_amt, buy_amt, id). The asks list represents the orders selling the asset, while the bids list represents the orders buying the asset.
- Return type:
Tuple[List[List[int]], List[List[int]]]
- get_expected_multiswap_fill(pay_amts: List[int], buy_amt_mins: List[int], routes: List[List[eth_typing.ChecksumAddress]]) int
Estimates the expected amount including fees when swapping multiple specified payment amount using multiple specified routes. reverts with an exception if the multiswap cannot achieve the buy_amt_mins along each route
- Parameters:
pay_amts (List[int]) – The list of payment amounts for each swap.
buy_amt_mins (List[int]) – The list of minimum buy amounts for each swap.
routes (List[List[ChecksumAddress]]) – The list of routes, where each route is a list of addresses representing the swap path.
- Returns:
The estimated multi-swap amount.
- Return type:
int
- get_expected_swap_fill(pay_amt: int, buy_amt_min: int, route: List[eth_typing.ChecksumAddress]) int
Estimates the expected amount including fees when swapping the specified payment amount using the specified route. reverts with an exception if the swap cannot achieve the buy_amt_min
- Parameters:
pay_amt (int) – The payment amount.
buy_amt_min (int) – The minimum buy amount.
route (List[ChecksumAddress]) – The route of addresses representing the swap path.
- Returns:
The estimated swap amount including fees.
- Return type:
int
- get_maker_balance(base_token: eth_typing.ChecksumAddress, tokens: List[eth_typing.ChecksumAddress], maker: eth_typing.ChecksumAddress) Tuple[int, int]
Iterates through all the base_token/tokens[i] offers of the maker and returns the balance of the base_token in the book and the balance of the base token.
- Parameters:
base_token (ChecksumAddress) – The address of the base token.
tokens (List[ChecksumAddress]) – A list of all the tokens to calculate the balance of
maker (ChecksumAddress) – The address of the maker to fet the balance for
- Returns:
balance in book, total token balance
- Return type:
Tuple[int, int]
- get_maker_balance_in_pair(asset: eth_typing.ChecksumAddress, quote: eth_typing.ChecksumAddress, maker: eth_typing.ChecksumAddress) int
Retrieves the balance of a specific maker for a given asset/quote pair.
- Parameters:
asset (ChecksumAddress) – The address of the asset token.
quote (ChecksumAddress) – The address of the quote token.
maker (ChecksumAddress) – The address of the maker.
- Returns:
The balance of the maker in the specified asset/quote pair.
- Return type:
int
- multiswap(routes: List[List[eth_typing.ChecksumAddress]], pay_amts: List[int], buy_amts_min: List[int], to: eth_typing.ChecksumAddress, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Perform a multiple swaps for the specified payment amounts using the specified routes. Reverts with an exception if any of the swaps cannot achieve the buy_amt_min along the specified route.
- Parameters:
routes (List[List[ChecksumAddress]]) – The list of routes, where each route is a list of addresses representing the swap path.
pay_amts (List[int]) – The list of payment amounts for each swap.
buy_amts_min (List[int]) – The list of minimum buy amounts for each swap.
to (ChecksumAddress) – The address of the recipient.
nonce (Optional[int]) – Nonce of the transaction. Defaults to calling the chain state to get the nonce. (optional, default is None).
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – Max fee that can be paid for gas. Defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None).
max_priority_fee_per_gas (Optional[int]) – Max priority fee that can be paid for gas. Defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None).
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt
- swap(pay_amt: int, buy_amt_min: int, route: List[eth_typing.ChecksumAddress], to: eth_typing.ChecksumAddress, nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None) TransactionReceipt
Perform a swap operation with the specified payment amount using the specified route and paying out to the recipient. Reverts if the swap does not result in the buy_min_amount.
- Parameters:
pay_amt (int) – The payment amount.
buy_amt_min (int) – The minimum buy amount.
route (List[ChecksumAddress]) – The route, represented as a list of addresses representing the swap path.
to (ChecksumAddress) – The address of the recipient.
nonce (Optional[int]) – Nonce of the transaction. Defaults to calling the chain state to get the nonce. (optional, default is None).
gas (Optional[int]) – gas limit for the transaction. If None is passed then w3.eth.estimate_gas is used.
max_fee_per_gas (Optional[int]) – Max fee that can be paid for gas. Defaults to max_priority_fee (from chain) + (2 * base fee per gas of latest block) (optional, default is None).
max_priority_fee_per_gas (Optional[int]) – Max priority fee that can be paid for gas. Defaults to calling the chain to estimate the max_priority_fee_per_gas (optional, default is None).
- Returns:
An object representing the transaction receipt
- Return type:
TransactionReceipt