-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic vault interface, second batch of work (#238)
- Adding more vault interface structure - Optimise `fetch_erc20_details` caching in some use cases
- Loading branch information
Showing
7 changed files
with
214 additions
and
13 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
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,3 @@ | ||
|
||
|
||
VELVET_DEFAULT_API_URL = "https://eventsapi.velvetdao.xyz/api/v3" |
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,75 @@ | ||
"""Velvet deposit handling. | ||
- Need to call proprietary centralised API to make a deposit | ||
""" | ||
from pprint import pformat | ||
import logging | ||
|
||
import requests | ||
from eth_typing import HexAddress | ||
from requests import HTTPError | ||
from web3 import Web3 | ||
|
||
from eth_defi.velvet.config import VELVET_DEFAULT_API_URL | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class VelvetDepositError(Exception): | ||
"""Error reply from velvet txn API""" | ||
|
||
|
||
def deposit_to_velvet( | ||
portfolio: HexAddress | str, | ||
from_address: HexAddress | str, | ||
deposit_token_address: HexAddress | str, | ||
amount: int, | ||
chain_id: int, | ||
api_url=VELVET_DEFAULT_API_URL, | ||
) -> dict: | ||
"""Construct Velvet deposit payload. | ||
- See https://github.com/Velvet-Capital/3rd-party-integration/issues/2#issuecomment-2490845963 for details | ||
""" | ||
assert portfolio.startswith("0x") | ||
assert from_address.startswith("0x") | ||
assert deposit_token_address.startswith("0x") | ||
assert type(amount) == int | ||
# payload = { | ||
# "portfolio": "0x444ef5b66f3dc7f3d36fe607f84fcb2f3a666902", | ||
# "depositAmount": 1, | ||
# "depositToken": "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb", | ||
# "user": "0x3C96e2Fc58332746fbBAB5eC44f01572F99033ed", | ||
# "depositType": "batch", | ||
# "tokenType": "erc20" | ||
# } | ||
|
||
payload = { | ||
"portfolio": portfolio, | ||
"depositAmount": amount, | ||
"depositToken": deposit_token_address, | ||
"user": from_address, | ||
"depositType": "batch", | ||
"tokenType": "erc20" | ||
} | ||
|
||
url = f"{api_url}/portfolio/deposit" | ||
|
||
logger.info("Velvet deposit to %s with params:\n%s", url, pformat(payload)) | ||
|
||
resp = requests.post(url, json=payload) | ||
|
||
try: | ||
resp.raise_for_status() | ||
except HTTPError as e: | ||
raise VelvetDepositError(f"Velvet API error on {api_url}, code {resp.status_code}: {resp.text}") from e | ||
|
||
tx_data = resp.json() | ||
|
||
if "error" in tx_data: | ||
raise VelvetDepositError(str(tx_data)) | ||
|
||
tx_data["from"] = Web3.to_checksum_address(from_address) | ||
tx_data["chainId"] = chain_id | ||
return tx_data |
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