-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add WrappedToken class * Add docstring * Update payout module * Check zero balance * Update tests * Consistency * Inherit from Token class
- Loading branch information
Showing
4 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from pdr_backend.models.token import Token | ||
from pdr_backend.util.web3_config import Web3Config | ||
|
||
|
||
class WrappedToken(Token): | ||
def __init__(self, config: Web3Config, address: str): | ||
super().__init__(config, address) | ||
abi = [ | ||
{ | ||
"constant": False, | ||
"inputs": [{"type": "uint256"}], | ||
"name": "withdraw", | ||
"outputs": [], | ||
"payable": False, | ||
"stateMutability": "external", | ||
"type": "function", | ||
}, | ||
] | ||
self.contract_instance_wrapped = config.w3.eth.contract( | ||
address=self.contract_address, abi=abi | ||
) | ||
|
||
def withdraw(self, amount: int, wait_for_receipt=True): | ||
""" | ||
Converts Wrapped Token to Token, amount is in wei. | ||
""" | ||
gas_price = self.config.w3.eth.gas_price | ||
|
||
tx = self.contract_instance_wrapped.functions.withdraw(amount).transact( | ||
{"from": self.config.owner, "gasPrice": gas_price} | ||
) | ||
if not wait_for_receipt: | ||
return tx | ||
return self.config.w3.eth.wait_for_transaction_receipt(tx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters