Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Add Fuji support, expand detailed errors (tradeparadigm#13)
Browse files Browse the repository at this point in the history
* chore: update gitignore
* feat: detailed error messages
* feat: fuji support
  • Loading branch information
stevenwal authored Jun 13, 2022
1 parent 606defc commit b74a5c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ dmypy.json
.pyre/

notebooks
*.ipynb
4 changes: 4 additions & 0 deletions ribbon/ribbon/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
17 changes: 16 additions & 1 deletion ribbon/ribbon/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
],
}
Expand Down

0 comments on commit b74a5c0

Please sign in to comment.