Skip to content

Commit

Permalink
v2.1.0 add sepolia (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajames authored Dec 11, 2023
1 parent d9be2be commit 73252e3
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 71 deletions.
16 changes: 8 additions & 8 deletions dydx3/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ------------ API URLs ------------
API_HOST_MAINNET = 'https://api.dydx.exchange'
API_HOST_GOERLI = 'https://api.stage.dydx.exchange'
API_HOST_SEPOLIA = 'https://api.stage.dydx.exchange'
WS_HOST_MAINNET = 'wss://api.dydx.exchange/v3/ws'
WS_HOST_GOERLI = 'wss://api.stage.dydx.exchange/v3/ws'
WS_HOST_SEPOLIA = 'wss://api.stage.dydx.exchange/v3/ws'

# ------------ Ethereum Network IDs ------------
NETWORK_ID_MAINNET = 1
NETWORK_ID_GOERLI = 5
NETWORK_ID_SEPOLIA = 11155111

# ------------ Signature Types ------------
SIGNATURE_TYPE_NO_PREPEND = 0
Expand Down Expand Up @@ -188,8 +188,8 @@
'0x02893294412a4c8f915f75892b395ebbf6859ec246ec365c3b1f56f47c3a0a5d',
16,
),
NETWORK_ID_GOERLI: int(
'0x03bda2b4764039f2df44a00a9cf1d1569a83f95406a983ce4beb95791c376008',
NETWORK_ID_SEPOLIA: int(
'0x01e70c509c4c6bfafe8b73d2fc1819444b2c0b435d4b82c0f24addff9565ce25',
16,
),
}
Expand Down Expand Up @@ -295,16 +295,16 @@
MAX_SOLIDITY_UINT = 115792089237316195423570985008687907853269984665640564039457584007913129639935 # noqa: E501
FACT_REGISTRY_CONTRACT = {
NETWORK_ID_MAINNET: '0xBE9a129909EbCb954bC065536D2bfAfBd170d27A',
NETWORK_ID_GOERLI: '0xc5061C08cF892C79DDB106B777138982433C8865',
NETWORK_ID_SEPOLIA: '0xCD828e691cA23b66291ae905491Bb89aEe3Abd82',
}
STARKWARE_PERPETUALS_CONTRACT = {
NETWORK_ID_MAINNET: '0xD54f502e184B6B739d7D27a6410a67dc462D69c8',
NETWORK_ID_GOERLI: '0xFE76edf35648Cc733d57200646cb1Dc63d05462F',
NETWORK_ID_SEPOLIA: '0x3D05aaCd0fED84f65dE0D91e4621298E702911E2',
}
TOKEN_CONTRACTS = {
ASSET_USDC: {
NETWORK_ID_MAINNET: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
NETWORK_ID_GOERLI: '0xF7a2fa2c2025fFe64427dd40Dc190d47ecC8B36e',
NETWORK_ID_SEPOLIA: '0x7fC9C132268E0E414991449c003DbdB3E73E2059',
},
}
COLLATERAL_TOKEN_DECIMALS = 6
Expand Down
6 changes: 3 additions & 3 deletions dydx3/modules/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dydx3.constants import COLLATERAL_ASSET
from dydx3.constants import COLLATERAL_TOKEN_DECIMALS
from dydx3.constants import FACT_REGISTRY_CONTRACT
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import NETWORK_ID_SEPOLIA
from dydx3.constants import TIME_IN_FORCE_GTT
from dydx3.constants import TOKEN_CONTRACTS
from dydx3.helpers.db import get_account_id
Expand Down Expand Up @@ -1203,8 +1203,8 @@ def request_testnet_tokens(
:raises: DydxAPIError
'''
if (self.network_id != NETWORK_ID_GOERLI):
raise ValueError('network_id is not Goerli')
if (self.network_id != NETWORK_ID_SEPOLIA):
raise ValueError('network_id is not Sepolia')

return self._post('testnet/tokens', {})

Expand Down
8 changes: 4 additions & 4 deletions examples/onboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
'''

from dydx3 import Client
from dydx3.constants import API_HOST_GOERLI
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import API_HOST_SEPOLIA
from dydx3.constants import NETWORK_ID_SEPOLIA
from web3 import Web3

# Ganache test address.
Expand All @@ -15,8 +15,8 @@
WEB_PROVIDER_URL = 'http://localhost:8545'

client = Client(
network_id=NETWORK_ID_GOERLI,
host=API_HOST_GOERLI,
network_id=NETWORK_ID_SEPOLIA,
host=API_HOST_SEPOLIA,
default_ethereum_address=ETHEREUM_ADDRESS,
web3=Web3(Web3.HTTPProvider(WEB_PROVIDER_URL)),
)
Expand Down
8 changes: 4 additions & 4 deletions examples/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import time

from dydx3 import Client
from dydx3.constants import API_HOST_GOERLI
from dydx3.constants import API_HOST_SEPOLIA
from dydx3.constants import MARKET_BTC_USD
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import NETWORK_ID_SEPOLIA
from dydx3.constants import ORDER_SIDE_BUY
from dydx3.constants import ORDER_STATUS_OPEN
from dydx3.constants import ORDER_TYPE_LIMIT
Expand All @@ -21,8 +21,8 @@
WEB_PROVIDER_URL = 'http://localhost:8545'

client = Client(
network_id=NETWORK_ID_GOERLI,
host=API_HOST_GOERLI,
network_id=NETWORK_ID_SEPOLIA,
host=API_HOST_SEPOLIA,
default_ethereum_address=ETHEREUM_ADDRESS,
web3=Web3(Web3.HTTPProvider(WEB_PROVIDER_URL)),
)
Expand Down
12 changes: 6 additions & 6 deletions examples/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from dydx3 import Client
from dydx3.helpers.request_helpers import generate_now_iso
from dydx3.constants import API_HOST_GOERLI
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import WS_HOST_GOERLI
from dydx3.constants import API_HOST_SEPOLIA
from dydx3.constants import NETWORK_ID_SEPOLIA
from dydx3.constants import WS_HOST_SEPOLIA
from web3 import Web3

# Ganache test address.
Expand All @@ -21,8 +21,8 @@
WEB_PROVIDER_URL = 'http://localhost:8545'

client = Client(
network_id=NETWORK_ID_GOERLI,
host=API_HOST_GOERLI,
network_id=NETWORK_ID_SEPOLIA,
host=API_HOST_SEPOLIA,
default_ethereum_address=ETHEREUM_ADDRESS,
web3=Web3(Web3.HTTPProvider(WEB_PROVIDER_URL)),
)
Expand All @@ -47,7 +47,7 @@

async def main():
# Note: This doesn't work with Python 3.9.
async with websockets.connect(WS_HOST_GOERLI) as websocket:
async with websockets.connect(WS_HOST_SEPOLIA) as websocket:

await websocket.send(json.dumps(req))
print(f'> {req}')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='dydx-v3-python',
version='2.0.1',
version='2.1.0',
packages=find_packages(),
package_data={
'dydx3': [
Expand Down
8 changes: 4 additions & 4 deletions tests/starkex/test_conditional_transfer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import NETWORK_ID_SEPOLIA
from dydx3.helpers.request_helpers import iso_to_epoch_seconds
from dydx3.starkex.conditional_transfer import SignableConditionalTransfer

Expand All @@ -9,13 +9,13 @@
'58c7d5a90b1776bde86ebac077e053ed85b0f7164f53b080304a531947f46e3'
)
MOCK_SIGNATURE = (
'01b437ac15bb89417edcfb2d304c3efad6256def3cc24e60c4980a88d08cb953' +
'045df9fbe4a4895409e1011c60be439d65c1a2637013b74a19cb5b8ab62db434'
'030044e03ab5efbaeaa43f472aa637bca8542835da60e8dcda8d145a619546d2' +
'03c7f9007fd6b1963de156bfadf6e90fe4fe4b29674013b7de32f61527c70f00'
)

# Mock conditional transfer params.
CONDITIONAL_TRANSFER_PARAMS = {
"network_id": NETWORK_ID_GOERLI,
"network_id": NETWORK_ID_SEPOLIA,
'sender_position_id': 12345,
'receiver_position_id': 67890,
'receiver_public_key': (
Expand Down
19 changes: 12 additions & 7 deletions tests/starkex/test_order.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dydx3.constants import MARKET_ETH_USD
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import NETWORK_ID_SEPOLIA
from dydx3.constants import ORDER_SIDE_BUY
from dydx3.helpers.request_helpers import iso_to_epoch_seconds
from dydx3.starkex.order import SignableOrder
Expand All @@ -12,22 +12,25 @@
'58c7d5a90b1776bde86ebac077e053ed85b0f7164f53b080304a531947f46e3'
)
MOCK_SIGNATURE = (
'07670488d9d2c6ff980ca86e6d05b89414de0f2bfd462a1058fb05add68d034a' +
'036268ae33e8e21d324e975678f56b66dacb2502a7de1512a46b96fc0e106f79'
'0500a22a8c8b14fbb3b7d26366604c446b9d059420d7db2a8f94bc52691d2626' +
'003e38aa083f72c9db89a7a80b98a6eb92edce7294d917d8489767740affc6ed'
)

# Test data where the public key y-coordinate is even.
MOCK_PUBLIC_KEY_EVEN_Y = (
'5c749cd4c44bdc730bc90af9bfbdede9deb2c1c96c05806ce1bc1cb4fed64f7'
)
MOCK_PRIVATE_KEY_EVEN_Y = (
'65b7bb244e019b45a521ef990fb8a002f76695d1fc6c1e31911680f2ed78b84'
)
MOCK_SIGNATURE_EVEN_Y = (
'0618bcd2a8a027cf407116f88f2fa0d866154ee421cdf8a9deca0fecfda5277b' +
'03e42fa1d039522fc77c23906253e537cc5b2f392dba6f2dbb35d51cbe37273a'
'06f593fcec14720cd895e7edf0830b668b6104c0de4be6d22befe4ced0868dc3' +
'0507259e9634a140d83a8fcfc43b5a08af6cec7f85d3606cc7a974465aff334e'
)

# Mock order params.
ORDER_PARAMS = {
"network_id": NETWORK_ID_GOERLI,
"network_id": NETWORK_ID_SEPOLIA,
"market": MARKET_ETH_USD,
"side": ORDER_SIDE_BUY,
"position_id": 12345,
Expand Down Expand Up @@ -57,9 +60,11 @@ def test_verify_signature_odd_y(self):

def test_verify_signature_even_y(self):
order = SignableOrder(**ORDER_PARAMS)
signature = order.sign(MOCK_PRIVATE_KEY_EVEN_Y)
assert signature == MOCK_SIGNATURE_EVEN_Y
assert order.verify_signature(
MOCK_SIGNATURE_EVEN_Y,
MOCK_PUBLIC_KEY_EVEN_Y,
MOCK_PUBLIC_KEY_EVEN_Y
)

def test_starkware_representation(self):
Expand Down
16 changes: 8 additions & 8 deletions tests/starkex/test_transfer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import NETWORK_ID_SEPOLIA
from dydx3.helpers.request_helpers import iso_to_epoch_seconds
from dydx3.starkex.transfer import SignableTransfer

Expand All @@ -9,8 +9,8 @@
'58c7d5a90b1776bde86ebac077e053ed85b0f7164f53b080304a531947f46e3'
)
MOCK_SIGNATURE = (
'07a64843a0fb9bd455696139f6230d3152d9df2e863d54587f1f8bdbb07eb032' +
'0699b82593aa2e02915694ffc39c1001e81337b8fcc73f5b91f73ce5146c50bd'
'02b4d393ea955be0f53029e2f8a10d31671eb9d3ada015d973c903417264688a' +
'02ffb6b7f29870208f1f860b125de95b5444142a867be9dcd80128999518ddd3'
)

# Mock transfer params.
Expand All @@ -34,7 +34,7 @@ class TestTransfer():

def test_sign_transfer(self):
transfer = SignableTransfer(
**TRANSFER_PARAMS, network_id=NETWORK_ID_GOERLI)
**TRANSFER_PARAMS, network_id=NETWORK_ID_SEPOLIA)
signature = transfer.sign(MOCK_PRIVATE_KEY)
assert signature == MOCK_SIGNATURE

Expand All @@ -44,7 +44,7 @@ def test_sign_transfer_different_client_id(self):

transfer = SignableTransfer(
**alternative_transfer_params,
network_id=NETWORK_ID_GOERLI
network_id=NETWORK_ID_SEPOLIA
)
signature = transfer.sign(MOCK_PRIVATE_KEY)
assert signature != MOCK_SIGNATURE
Expand All @@ -55,19 +55,19 @@ def test_sign_transfer_different_receiver_position_id(self):

transfer = SignableTransfer(
**alternative_transfer_params,
network_id=NETWORK_ID_GOERLI
network_id=NETWORK_ID_SEPOLIA
)
signature = transfer.sign(MOCK_PRIVATE_KEY)
assert signature != MOCK_SIGNATURE

def test_verify_signature(self):
transfer = SignableTransfer(
**TRANSFER_PARAMS, network_id=NETWORK_ID_GOERLI)
**TRANSFER_PARAMS, network_id=NETWORK_ID_SEPOLIA)
assert transfer.verify_signature(MOCK_SIGNATURE, MOCK_PUBLIC_KEY)

def test_starkware_representation(self):
transfer = SignableTransfer(
**TRANSFER_PARAMS, network_id=NETWORK_ID_GOERLI)
**TRANSFER_PARAMS, network_id=NETWORK_ID_SEPOLIA)
starkware_transfer = transfer.to_starkware()
assert starkware_transfer.quantums_amount == 49478023

Expand Down
8 changes: 4 additions & 4 deletions tests/starkex/test_withdrawal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import NETWORK_ID_SEPOLIA
from dydx3.helpers.request_helpers import iso_to_epoch_seconds
from dydx3.starkex.withdrawal import SignableWithdrawal

Expand All @@ -9,13 +9,13 @@
'58c7d5a90b1776bde86ebac077e053ed85b0f7164f53b080304a531947f46e3'
)
MOCK_SIGNATURE = (
'0572e1628e196282ee246dbe5c8394251bf3fb1fab7be40e77b69b64c030920e' +
'025f94283b9f3b9aa18503f7c500db89cc1ac914cb84b00e2263552a3d31a479'
'01af771baee70bea9e5e0a5e600e29fa67171b32ee5d38c67c5a97630bcd8fab' +
'0563d154cd47dcf9c34e4ddf00d8fea353176807ba5f7ab62316133a8976a733'
)

# Mock withdrawal params.
WITHDRAWAL_PARAMS = {
"network_id": NETWORK_ID_GOERLI,
"network_id": NETWORK_ID_SEPOLIA,
"position_id": 12345,
"human_amount": '49.478023',
"client_id": (
Expand Down
Loading

1 comment on commit 73252e3

@kgoderis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an issue with onboarding after the upgrade. Pls see #220

Please sign in to comment.