diff --git a/dydx3/constants.py b/dydx3/constants.py index 6a5045e..13a615c 100644 --- a/dydx3/constants.py +++ b/dydx3/constants.py @@ -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 @@ -188,8 +188,8 @@ '0x02893294412a4c8f915f75892b395ebbf6859ec246ec365c3b1f56f47c3a0a5d', 16, ), - NETWORK_ID_GOERLI: int( - '0x03bda2b4764039f2df44a00a9cf1d1569a83f95406a983ce4beb95791c376008', + NETWORK_ID_SEPOLIA: int( + '0x01e70c509c4c6bfafe8b73d2fc1819444b2c0b435d4b82c0f24addff9565ce25', 16, ), } @@ -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 diff --git a/dydx3/modules/private.py b/dydx3/modules/private.py index 98d0051..7c46980 100644 --- a/dydx3/modules/private.py +++ b/dydx3/modules/private.py @@ -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 @@ -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', {}) diff --git a/examples/onboard.py b/examples/onboard.py index 7bd85e5..86114ec 100644 --- a/examples/onboard.py +++ b/examples/onboard.py @@ -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. @@ -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)), ) diff --git a/examples/orders.py b/examples/orders.py index 2d58c42..04c0036 100644 --- a/examples/orders.py +++ b/examples/orders.py @@ -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 @@ -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)), ) diff --git a/examples/websockets.py b/examples/websockets.py index 3e89419..700a3d5 100644 --- a/examples/websockets.py +++ b/examples/websockets.py @@ -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. @@ -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)), ) @@ -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}') diff --git a/setup.py b/setup.py index a648d5b..0e5311e 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ setup( name='dydx-v3-python', - version='2.0.1', + version='2.1.0', packages=find_packages(), package_data={ 'dydx3': [ diff --git a/tests/starkex/test_conditional_transfer.py b/tests/starkex/test_conditional_transfer.py index 857d14e..506e285 100644 --- a/tests/starkex/test_conditional_transfer.py +++ b/tests/starkex/test_conditional_transfer.py @@ -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 @@ -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': ( diff --git a/tests/starkex/test_order.py b/tests/starkex/test_order.py index f382aea..fb139c1 100644 --- a/tests/starkex/test_order.py +++ b/tests/starkex/test_order.py @@ -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 @@ -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, @@ -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): diff --git a/tests/starkex/test_transfer.py b/tests/starkex/test_transfer.py index 87cf1ec..7dcc063 100644 --- a/tests/starkex/test_transfer.py +++ b/tests/starkex/test_transfer.py @@ -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 @@ -9,8 +9,8 @@ '58c7d5a90b1776bde86ebac077e053ed85b0f7164f53b080304a531947f46e3' ) MOCK_SIGNATURE = ( - '07a64843a0fb9bd455696139f6230d3152d9df2e863d54587f1f8bdbb07eb032' + - '0699b82593aa2e02915694ffc39c1001e81337b8fcc73f5b91f73ce5146c50bd' + '02b4d393ea955be0f53029e2f8a10d31671eb9d3ada015d973c903417264688a' + + '02ffb6b7f29870208f1f860b125de95b5444142a867be9dcd80128999518ddd3' ) # Mock transfer params. @@ -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 @@ -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 @@ -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 diff --git a/tests/starkex/test_withdrawal.py b/tests/starkex/test_withdrawal.py index 9e8630d..d5ca109 100644 --- a/tests/starkex/test_withdrawal.py +++ b/tests/starkex/test_withdrawal.py @@ -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 @@ -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": ( diff --git a/tests/test_onboarding.py b/tests/test_onboarding.py index c639c35..03f0a0d 100644 --- a/tests/test_onboarding.py +++ b/tests/test_onboarding.py @@ -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 @@ -23,18 +23,18 @@ 'private_key': '0x170d807cafe3d8b5758f3f698331d292bf5aeb71f6fd282f0831dee094ee891', } -EXPECTED_API_KEY_CREDENTIALS_GOERLI = { - 'key': '1871d1ba-537c-7fe8-743c-172bcd4ae5c6', - 'secret': 'tQxclqFWip0HL4Q-xkwZb_lTfOQz4GD5CHHpYzWa', - 'passphrase': 'B8JFepDVn8eixnor7Imv', +EXPECTED_API_KEY_CREDENTIALS_SEPOLIA = { + 'key': '30cb6046-8f4a-5677-a19c-a494ccb7c7e5', + 'secret': '4Yd_6JtH_-I2taoNQKAhkCifnVHQ2Unue88sIeuc', + 'passphrase': 'Db1GQK5KpI_qeddgjF66', } -EXPECTED_STARK_KEY_PAIR_WITH_Y_COORDINATE_GOERLI = { +EXPECTED_STARK_KEY_PAIR_WITH_Y_COORDINATE_SEPOLIA = { 'public_key': - '0x3ea05770b452df14427b3f07ff600faa132ecc3d7643275042cb4da6ad99972', + '0x15e2e074a7ac9e78edb2ee9f11a0c0c0a080c79758ab81616eea9c032c75265', 'public_key_y_coordinate': - '0x7310e2ab01978806a6fb6e51a9ee1c9a5c5117c63530ad7dead2b9f72094cc3', + '0x360408546b64238f80d7a8a336d7304d75f122a7e5bb22cbb7a14f550eac5a8', 'private_key': - '0x1019187d91b8effe153ab1932930e27c8d01c56ad9cc937c777633c0ffc5a7e' + '0x2d21c094fedea3e72bef27fbcdceaafd34e88fc4b7586859e26e98b21e63a60' } @@ -69,11 +69,11 @@ 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] @@ -81,13 +81,13 @@ def test_derive_stark_key_on_GOERLI_from_web3(self): 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] @@ -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( @@ -126,10 +126,10 @@ 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 @@ -137,12 +137,12 @@ def test_derive_stark_key_on_GOERLI_from_priv(self): 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 @@ -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 diff --git a/tests/test_public.py b/tests/test_public.py index 98d1fff..1ee3134 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -26,7 +26,7 @@ def test_check_if_user_exists(self): def test_check_if_username_exists(self): public = Client(API_HOST).public resp = public.check_if_username_exists('foo') - assert resp.data == {'exists': False} + assert resp.data == {'exists': True} assert resp.headers != {} def test_get_markets(self):