Skip to content

Commit

Permalink
mantle goerli support (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
yruej301 authored Dec 8, 2023
1 parent f90add3 commit 00e348a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vertex-protocol"
version = "1.1.19"
version = "1.1.20"
description = "Vertex Protocol SDK"
authors = ["Jeury Mejia <jeury@vertexprotocol.com>"]
homepage = "https://vertexprotocol.com/"
Expand Down
37 changes: 30 additions & 7 deletions tests/vertex_client/test_create_vertex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,45 @@ def test_create_vertex_client(
assert mainnet_vertex_client.context.indexer_client.url == VertexBackendURL.MAINNET
assert mainnet_vertex_client.context.engine_client.signer == signer

testnet_vertex_client = create_vertex_client(
sepolia_testnet_vertex_client = create_vertex_client(
VertexClientMode.SEPOLIA_TESTNET, signer
)

assert testnet_vertex_client.context.engine_client.chain_id == chain_id
assert testnet_vertex_client.context.engine_client.endpoint_addr == endpoint_addr
assert testnet_vertex_client.context.engine_client.book_addrs == book_addrs
assert sepolia_testnet_vertex_client.context.engine_client.chain_id == chain_id
assert (
testnet_vertex_client.context.engine_client.url
sepolia_testnet_vertex_client.context.engine_client.endpoint_addr
== endpoint_addr
)
assert sepolia_testnet_vertex_client.context.engine_client.book_addrs == book_addrs
assert (
sepolia_testnet_vertex_client.context.engine_client.url
== VertexBackendURL.SEPOLIA_TESTNET
)
assert (
testnet_vertex_client.context.indexer_client.url
sepolia_testnet_vertex_client.context.indexer_client.url
== VertexBackendURL.SEPOLIA_TESTNET
)
assert testnet_vertex_client.context.engine_client.signer == signer
assert sepolia_testnet_vertex_client.context.engine_client.signer == signer

mantle_testnet_vertex_client = create_vertex_client(
VertexClientMode.MANTLE_TESTNET, signer
)

assert mantle_testnet_vertex_client.context.engine_client.chain_id == chain_id
assert (
mantle_testnet_vertex_client.context.engine_client.endpoint_addr
== endpoint_addr
)
assert mantle_testnet_vertex_client.context.engine_client.book_addrs == book_addrs
assert (
mantle_testnet_vertex_client.context.engine_client.url
== VertexBackendURL.MANTLET_TESTNET
)
assert (
mantle_testnet_vertex_client.context.indexer_client.url
== VertexBackendURL.MANTLET_TESTNET
)
assert mantle_testnet_vertex_client.context.engine_client.signer == signer

devnet_vertex_client = create_vertex_client(VertexClientMode.TESTING, signer)

Expand Down
13 changes: 12 additions & 1 deletion vertex_protocol/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ class VertexClientMode(StrEnum):
SEPOLIA_TESTNET: For operating in Vertex's testnet environment deployed on Arbitrum Sepolia.
MANTLE_TESTNET: For operating in Vertex's testnet environment deployed on Mantle Goerli.
DEVNET: For local development.
TESTING: For running tests.
"""

MAINNET = "mainnet"
SEPOLIA_TESTNET = "sepolia-testnet"
MANTLE_TESTNET = "mantle-testnet"
DEVNET = "devnet"
TESTING = "testing"

Expand Down Expand Up @@ -101,6 +104,7 @@ def create_vertex_client(
mode (VertexClientMode): The mode in which to operate the client. Can be one of the following:
VertexClientMode.MAINNET: For operating in Vertex's mainnet environment deployed on Arbitrum One.
VertexClientMode.SEPOLIA_TESTNET: For operating in Vertex's testnet environment deployed on Arbitrum Sepolia.
VertexClientMode.MANTLE_TESTNET: For operating in Vertex's testnet environment deployed on Mantle Goerli.
VertexClientMode.DEVNET: For local development.
signer (Signer, optional): An instance of LocalAccount or a private key string for signing transactions.
Expand All @@ -114,9 +118,11 @@ def create_vertex_client(
logging.info(f"Initializing default {mode} context")
engine_endpoint_url, indexer_endpoint_url, network_name = client_mode_to_setup(mode)
try:
deployment = load_deployment(VertexNetwork(network_name))
network = VertexNetwork(network_name)
deployment = load_deployment(network)
rpc_node_url = deployment.node_url
contracts_context = VertexContractsContext(
network=network,
endpoint_addr=deployment.endpoint_addr,
querier_addr=deployment.querier_addr,
perp_engine_addr=deployment.perp_engine_addr,
Expand Down Expand Up @@ -168,6 +174,11 @@ def client_mode_to_setup(
VertexBackendURL.MAINNET.value,
VertexNetwork.ARBITRUM_ONE.value,
),
VertexClientMode.MANTLE_TESTNET: (
VertexBackendURL.MANTLET_TESTNET.value,
VertexBackendURL.MANTLET_TESTNET.value,
VertexNetwork.MANTLE_GOERLI.value,
),
VertexClientMode.SEPOLIA_TESTNET: (
VertexBackendURL.SEPOLIA_TESTNET.value,
VertexBackendURL.SEPOLIA_TESTNET.value,
Expand Down
9 changes: 8 additions & 1 deletion vertex_protocol/contracts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class VertexContractsContext(BaseModel):
clearinghouse_addr (Optional[str]): The clearinghouse address. This may be None.
"""

network: Optional[VertexNetwork]
endpoint_addr: str
querier_addr: str
spot_engine_addr: Optional[str]
Expand All @@ -47,6 +48,7 @@ class VertexContracts:
"""

w3: Web3
network: Optional[VertexNetwork]
contracts_context: VertexContractsContext
querier: Contract
endpoint: Contract
Expand All @@ -66,6 +68,7 @@ def __init__(self, node_url: str, contracts_context: VertexContractsContext):
contracts_context (VertexContractsContext): The Vertex contracts context, holding the relevant addresses.
"""
self.network = contracts_context.network
self.w3 = Web3(Web3.HTTPProvider(node_url))

self.contracts_context = VertexContractsContext.parse_obj(contracts_context)
Expand Down Expand Up @@ -223,7 +226,11 @@ def _build_tx_params(self, signer: LocalAccount) -> TxParams:
"from": signer.address,
"nonce": self.w3.eth.get_transaction_count(signer.address),
}
if os.getenv("CLIENT_MODE") == "devnet":
needs_gas_price = self.network is not None and self.network.value in [
VertexNetwork.HARDHAT.value,
VertexNetwork.MANTLE_GOERLI.value,
]
if needs_gas_price or os.getenv("CLIENT_MODE") in ["devnet"]:
tx_params["gasPrice"] = self.w3.eth.gas_price
return tx_params

Expand Down
14 changes: 14 additions & 0 deletions vertex_protocol/contracts/deployments/deployment.mantleGoerli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"publicNodeUrl": "https://mantle-goerli.public.blastapi.io",
"explorerUrl": "https://explorer.testnet.mantle.xyz/",
"startBlock": 26921136,
"deployer": "0x3c06e307BA6Ab81E8Ff6661c1559ce8027744AE5",
"quote": "0xA7Fcb606611358afa388b6bd23b3B2F2c6abEd82",
"querier": "0x6f5F5d9Cb93062dd1d684c6694Fee7bbBE94eD6B",
"feeCalculator": "0xA1DbC395Cbaa8c7b74456697C42ADa8F2b08CAbb",
"clearinghouse": "0x1a77cB939B7C4fA5Cc90b09787260DABf5f05c41",
"endpoint": "0xB61B069d741C98DA3302986BF107aA9083b64133",
"spotEngine": "0xEC1149dF1559eaDB0Af4cf6d9BeAc7a08Aa9f694",
"perpEngine": "0x19a4B178654F42Ea994347D514ED9E4f99221Ba2",
"arbAirdrop": "0x0000000000000000000000000000000000000000"
}
1 change: 1 addition & 0 deletions vertex_protocol/contracts/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class VertexNetwork(StrEnum):

ARBITRUM_ONE = "arbitrumOne"
ARBITRUM_SEPOLIA = "arbitrumSepolia"
MANTLE_GOERLI = "mantleGoerli"
HARDHAT = "localhost"
TESTING = "test"

Expand Down
1 change: 1 addition & 0 deletions vertex_protocol/utils/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class VertexBackendURL(StrEnum):
"""Enum representing different Vertex backend URLs."""

MANTLET_TESTNET = "https://api.mantle-test.vertexprotocol.com"
SEPOLIA_TESTNET = "https://api.sepolia-test.vertexprotocol.com"
MAINNET = "https://api.prod.vertexprotocol.com"
DEVNET_ENGINE = "http://localhost:80"
Expand Down

0 comments on commit 00e348a

Please sign in to comment.