From b74a5c09b7fbca3fb6a0a66af5d67c0c62966a2d Mon Sep 17 00:00:00 2001 From: Steven <92332853+stevenwal@users.noreply.github.com> Date: Tue, 14 Jun 2022 04:51:39 +0800 Subject: [PATCH] Add Fuji support, expand detailed errors (#13) * chore: update gitignore * feat: detailed error messages * feat: fuji support --- .gitignore | 1 + ribbon/ribbon/contract.py | 4 ++++ ribbon/ribbon/swap.py | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a8e15182..5d30239c 100644 --- a/.gitignore +++ b/.gitignore @@ -129,3 +129,4 @@ dmypy.json .pyre/ notebooks +*.ipynb diff --git a/ribbon/ribbon/contract.py b/ribbon/ribbon/contract.py index 3951207f..e0c368a9 100644 --- a/ribbon/ribbon/contract.py +++ b/ribbon/ribbon/contract.py @@ -14,6 +14,7 @@ import json from pathlib import Path from web3 import Web3 +from web3.middleware import geth_poa_middleware from ribbon.chains import Chains from ribbon.definitions import ContractConfig @@ -65,6 +66,9 @@ def __init__(self, config: ContractConfig): + f"({chain.value})" ) + if chain == Chains.FUJI: + self.w3.middleware_onion.inject(geth_poa_middleware, layer=0) + with open(self.abi_file_path) as f: abi = json.load(f) diff --git a/ribbon/ribbon/swap.py b/ribbon/ribbon/swap.py index 5a46b043..4c5973e7 100644 --- a/ribbon/ribbon/swap.py +++ b/ribbon/ribbon/swap.py @@ -21,6 +21,21 @@ from ribbon.encode import ADDRESS_ZERO from shutil import ExecError +# --------------------------------------------------------------------------- +# Constants +# --------------------------------------------------------------------------- +DETAILED_ERROR_MESSAGES = { + "SIGNATURE_INVALID": "Signature invalid.", + "SIGNATURE_MISMATCHED": "Signature's origin does not match signer's address. Ensure you are using the correct wallet.", + "NONCE_ALREADY_USED": "This nonce has been previously used.", + "BID_TOO_SMALL": "Bid size has to be larger than minimum bid.", + "BID_EXCEED_AVAILABLE_SIZE": "Bid size has to be smaller than available size.", + "PRICE_TOO_LOW": "Price per oToken has to be larger than minimum price.", + "SIGNER_ALLOWANCE_LOW": "Insufficient bidding token allowance. Ensure you have approved sufficient amount of bidding token.", + "SIGNER_BALANCE_LOW": "Insufficient bidding token balance. Ensure you have sufficient balance of bidding token in your wallet.", + "SELLER_ALLOWANCE_LOW": "Seller has insufficient oToken allowance.", + "SELLER_BALANCE_LOW": "Seller has insufficienct oToken balance.", +} # --------------------------------------------------------------------------- # Swap Contract @@ -93,7 +108,7 @@ def validate_bid(self, bid: SignedBid) -> str: return { "errors": errors, "messages": [ - Web3.toText(msg).replace("\x00", "") + DETAILED_ERROR_MESSAGES[Web3.toText(msg).replace("\x00", "")] for msg in response[1][:errors] ], }