Skip to content

Commit

Permalink
v2.1.0 add sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajames committed Dec 6, 2023
1 parent d9be2be commit 8ea83e2
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 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
4 changes: 2 additions & 2 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 @@ -15,7 +15,7 @@

# 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
4 changes: 2 additions & 2 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 Down Expand Up @@ -27,7 +27,7 @@

# 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
12 changes: 6 additions & 6 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 Down Expand Up @@ -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
4 changes: 2 additions & 2 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 @@ -15,7 +15,7 @@

# 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
30 changes: 15 additions & 15 deletions tests/test_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dydx3 import Client
from dydx3.constants import NETWORK_ID_MAINNET
from dydx3.constants import NETWORK_ID_GOERLI
from dydx3.constants import NETWORK_ID_SEPOLIA

from tests.constants import DEFAULT_HOST

Expand All @@ -23,12 +23,12 @@
'private_key':
'0x170d807cafe3d8b5758f3f698331d292bf5aeb71f6fd282f0831dee094ee891',
}
EXPECTED_API_KEY_CREDENTIALS_GOERLI = {
EXPECTED_API_KEY_CREDENTIALS_SEPOLIA = {
'key': '1871d1ba-537c-7fe8-743c-172bcd4ae5c6',
'secret': 'tQxclqFWip0HL4Q-xkwZb_lTfOQz4GD5CHHpYzWa',
'passphrase': 'B8JFepDVn8eixnor7Imv',
}
EXPECTED_STARK_KEY_PAIR_WITH_Y_COORDINATE_GOERLI = {
EXPECTED_STARK_KEY_PAIR_WITH_Y_COORDINATE_SEPOLIA = {
'public_key':
'0x3ea05770b452df14427b3f07ff600faa132ecc3d7643275042cb4da6ad99972',
'public_key_y_coordinate':
Expand Down Expand Up @@ -69,25 +69,25 @@ def test_recover_default_api_key_credentials_on_mainnet_from_web3(self):
)
assert api_key_credentials == EXPECTED_API_KEY_CREDENTIALS_MAINNET

def test_derive_stark_key_on_GOERLI_from_web3(self):
def test_derive_stark_key_on_SEPOLIA_from_web3(self):
web3 = Web3() # Connect to a local Ethereum node.
client = Client(
host=DEFAULT_HOST,
network_id=NETWORK_ID_GOERLI,
network_id=NETWORK_ID_SEPOLIA,
web3=web3,
)
signer_address = web3.eth.accounts[0]
stark_key_pair_with_y_coordinate = client.onboarding.derive_stark_key(
signer_address,
)
assert stark_key_pair_with_y_coordinate == \
EXPECTED_STARK_KEY_PAIR_WITH_Y_COORDINATE_GOERLI
EXPECTED_STARK_KEY_PAIR_WITH_Y_COORDINATE_SEPOLIA

def test_recover_default_api_key_credentials_on_GOERLI_from_web3(self):
def test_recover_default_api_key_credentials_on_SEPOLIA_from_web3(self):
web3 = Web3() # Connect to a local Ethereum node.
client = Client(
host=DEFAULT_HOST,
network_id=NETWORK_ID_GOERLI,
network_id=NETWORK_ID_SEPOLIA,
web3=web3,
)
signer_address = web3.eth.accounts[0]
Expand All @@ -96,7 +96,7 @@ def test_recover_default_api_key_credentials_on_GOERLI_from_web3(self):
signer_address,
)
)
assert api_key_credentials == EXPECTED_API_KEY_CREDENTIALS_GOERLI
assert api_key_credentials == EXPECTED_API_KEY_CREDENTIALS_SEPOLIA

def test_derive_stark_key_on_mainnet_from_priv(self):
client = Client(
Expand Down Expand Up @@ -126,23 +126,23 @@ def test_recover_default_api_key_credentials_on_mainnet_from_priv(self):
)
assert api_key_credentials == EXPECTED_API_KEY_CREDENTIALS_MAINNET

def test_derive_stark_key_on_GOERLI_from_priv(self):
def test_derive_stark_key_on_SEPOLIA_from_priv(self):
client = Client(
host=DEFAULT_HOST,
network_id=NETWORK_ID_GOERLI,
network_id=NETWORK_ID_SEPOLIA,
eth_private_key=GANACHE_PRIVATE_KEY,
)
signer_address = client.default_address
stark_key_pair_with_y_coordinate = client.onboarding.derive_stark_key(
signer_address,
)
assert stark_key_pair_with_y_coordinate == \
EXPECTED_STARK_KEY_PAIR_WITH_Y_COORDINATE_GOERLI
EXPECTED_STARK_KEY_PAIR_WITH_Y_COORDINATE_SEPOLIA

def test_recover_default_api_key_credentials_on_GOERLI_from_priv(self):
def test_recover_default_api_key_credentials_on_SEPOLIA_from_priv(self):
client = Client(
host=DEFAULT_HOST,
network_id=NETWORK_ID_GOERLI,
network_id=NETWORK_ID_SEPOLIA,
eth_private_key=GANACHE_PRIVATE_KEY,
)
signer_address = client.default_address
Expand All @@ -151,4 +151,4 @@ def test_recover_default_api_key_credentials_on_GOERLI_from_priv(self):
signer_address,
)
)
assert api_key_credentials == EXPECTED_API_KEY_CREDENTIALS_GOERLI
assert api_key_credentials == EXPECTED_API_KEY_CREDENTIALS_SEPOLIA

0 comments on commit 8ea83e2

Please sign in to comment.