diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ee1579..9ffa4cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,27 +68,35 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Check if secrets are available + id: secrets-check + env: + RPC_SECRET: ${{ secrets.BASE_SEPOLIA_RPC_URL }} + run: | + if [ -z "$RPC_SECRET" ]; then + echo "::warning::Integration test secrets not configured - skipping" + echo "has_secrets=false" >> "$GITHUB_OUTPUT" + else + echo "Integration test configuration found - running tests" + echo "has_secrets=true" >> "$GITHUB_OUTPUT" + fi + + - name: Install Foundry + if: steps.secrets-check.outputs.has_secrets == 'true' + uses: foundry-rs/foundry-toolchain@v1 + - name: Setup Python + if: steps.secrets-check.outputs.has_secrets == 'true' uses: actions/setup-python@v5 with: python-version: "3.12" - name: Install dependencies + if: steps.secrets-check.outputs.has_secrets == 'true' run: pip install -e ".[dev]" - - name: Check if secrets are available - env: - RPC_SECRET: ${{ secrets.BASE_SEPOLIA_RPC_URL }} - run: | - if [ -z "$RPC_SECRET" ]; then - echo "::error::Integration test secrets are not configured!" - echo "::error::Configure required secrets: BASE_SEPOLIA_RPC_URL, TEST_PRIVATE_KEY" - echo "::error::Configure required variables: PERP_MANAGER_ADDRESS, USDC_ADDRESS, TEST_PERP_ID" - exit 1 - fi - echo "Integration test configuration found - running tests" - - name: Create .env.local for integration tests + if: steps.secrets-check.outputs.has_secrets == 'true' env: RPC_URL_VAL: ${{ secrets.BASE_SEPOLIA_RPC_URL }} PRIVATE_KEY_VAL: ${{ secrets.TEST_PRIVATE_KEY }} @@ -106,6 +114,7 @@ jobs: EOF - name: Run integration tests + if: steps.secrets-check.outputs.has_secrets == 'true' env: RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }} PRIVATE_KEY: ${{ secrets.TEST_PRIVATE_KEY }} diff --git a/examples/create_perp.py b/examples/create_perp.py index 56875a0..1b01892 100644 --- a/examples/create_perp.py +++ b/examples/create_perp.py @@ -17,7 +17,6 @@ def main(): print("Creating new perpetual market...") params = CreatePerpParams( - starting_price=1.0, beacon=beacon, ) diff --git a/src/perpcity_sdk/abis/perp_manager.json b/src/perpcity_sdk/abis/perp_manager.json index 17815c2..e8787b4 100644 --- a/src/perpcity_sdk/abis/perp_manager.json +++ b/src/perpcity_sdk/abis/perp_manager.json @@ -250,26 +250,19 @@ "anonymous": false, "inputs": [ { - "indexed": false, - "internalType": "contract IFees", - "name": "feesModule", - "type": "address" - } - ], - "name": "FeesModuleRegistered", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ + "indexed": true, + "internalType": "uint8", + "name": "moduleType", + "type": "uint8" + }, { - "indexed": false, - "internalType": "contract ILockupPeriod", - "name": "lockupPeriodModule", + "indexed": true, + "internalType": "address", + "name": "module", "type": "address" } ], - "name": "LockupPeriodModuleRegistered", + "name": "ModuleRegistered", "type": "event" }, { @@ -297,19 +290,6 @@ "name": "MarginAdjusted", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "contract IMarginRatios", - "name": "marginRatiosModule", - "type": "address" - } - ], - "name": "MarginRatiosModuleRegistered", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -483,13 +463,13 @@ { "indexed": false, "internalType": "int256", - "name": "perpDelta", + "name": "exitPerpDelta", "type": "int256" }, { "indexed": false, "internalType": "int256", - "name": "usdDelta", + "name": "exitUsdDelta", "type": "int256" }, { @@ -503,6 +483,42 @@ "internalType": "int24", "name": "tickUpper", "type": "int24" + }, + { + "indexed": false, + "internalType": "int256", + "name": "netUsdDelta", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "funding", + "type": "int256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "utilizationFee", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "adl", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "liquidationFee", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "netMargin", + "type": "int256" } ], "name": "PositionClosed", @@ -575,19 +591,6 @@ "name": "PositionOpened", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "contract ISqrtPriceImpactLimit", - "name": "sqrtPriceImpactLimitModule", - "type": "address" - } - ], - "name": "SqrtPriceImpactLimitModuleRegistered", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -714,12 +717,12 @@ }, { "internalType": "int256", - "name": "perpDelta", + "name": "usdDelta", "type": "int256" }, { "internalType": "uint128", - "name": "usdLimit", + "name": "perpLimit", "type": "uint128" } ], @@ -966,11 +969,6 @@ "internalType": "contract ISqrtPriceImpactLimit", "name": "sqrtPriceImpactLimit", "type": "address" - }, - { - "internalType": "uint160", - "name": "startingSqrtPriceX96", - "type": "uint160" } ], "internalType": "struct IPerpManager.CreatePerpParams", @@ -1091,69 +1089,17 @@ { "inputs": [ { - "internalType": "contract IFees", - "name": "", - "type": "address" - } - ], - "name": "isFeesRegistered", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "contract ILockupPeriod", - "name": "", - "type": "address" - } - ], - "name": "isLockupPeriodRegistered", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "contract IMarginRatios", - "name": "", - "type": "address" - } - ], - "name": "isMarginRatiosRegistered", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ + "internalType": "uint8", + "name": "moduleType", + "type": "uint8" + }, { - "internalType": "contract ISqrtPriceImpactLimit", - "name": "", + "internalType": "address", + "name": "module", "type": "address" } ], - "name": "isSqrtPriceImpactLimitRegistered", + "name": "isModuleRegistered", "outputs": [ { "internalType": "bool", @@ -1505,14 +1451,19 @@ "type": "int256" }, { - "internalType": "uint256", + "internalType": "int256", "name": "netMargin", - "type": "uint256" + "type": "int256" }, { "internalType": "bool", "name": "wasLiquidated", "type": "bool" + }, + { + "internalType": "uint256", + "name": "notional", + "type": "uint256" } ], "stateMutability": "nonpayable", @@ -1653,51 +1604,66 @@ { "inputs": [ { - "internalType": "contract IFees", - "name": "feesModule", - "type": "address" - } - ], - "name": "registerFeesModule", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ + "internalType": "PoolId", + "name": "perpId", + "type": "bytes32" + }, { - "internalType": "contract ILockupPeriod", - "name": "lockupPeriodModule", - "type": "address" + "internalType": "bool", + "name": "zeroForOne", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isExactIn", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint160", + "name": "sqrtPriceLimitX96", + "type": "uint160" } ], - "name": "registerLockupPeriodModule", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ + "name": "quoteSwap", + "outputs": [ { - "internalType": "contract IMarginRatios", - "name": "marginRatiosModule", - "type": "address" + "internalType": "bytes", + "name": "unexpectedReason", + "type": "bytes" + }, + { + "internalType": "int256", + "name": "perpDelta", + "type": "int256" + }, + { + "internalType": "int256", + "name": "usdDelta", + "type": "int256" } ], - "name": "registerMarginRatiosModule", - "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { - "internalType": "contract ISqrtPriceImpactLimit", - "name": "sqrtPriceImpactLimitModule", + "internalType": "uint8", + "name": "moduleType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "module", "type": "address" } ], - "name": "registerSqrtPriceImpactLimitModule", + "name": "registerModule", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1971,4 +1937,4 @@ "stateMutability": "view", "type": "function" } -] +] \ No newline at end of file diff --git a/src/perpcity_sdk/context.py b/src/perpcity_sdk/context.py index f8fb41c..3adf820 100644 --- a/src/perpcity_sdk/context.py +++ b/src/perpcity_sdk/context.py @@ -161,7 +161,7 @@ def _fetch_position_live_details(self, perp_id: str, position_id: int) -> LiveDe def _fetch() -> LiveDetails: result = self._perp_manager.functions.quoteClosePosition(position_id).call() - unexpected_reason, pnl, funding, net_margin, was_liquidated = result + unexpected_reason, pnl, funding, net_margin, was_liquidated, _notional = result if unexpected_reason != b"" and unexpected_reason != "0x": raise PerpCityError( diff --git a/src/perpcity_sdk/functions/perp_manager.py b/src/perpcity_sdk/functions/perp_manager.py index 2f05a84..020115a 100644 --- a/src/perpcity_sdk/functions/perp_manager.py +++ b/src/perpcity_sdk/functions/perp_manager.py @@ -6,7 +6,7 @@ from ..types import CreatePerpParams, OpenMakerPositionParams, OpenTakerPositionParams from ..utils.approve import approve_usdc from ..utils.constants import NUMBER_1E6 -from ..utils.conversions import price_to_sqrt_price_x96, price_to_tick, scale_6_decimals +from ..utils.conversions import price_to_tick, scale_6_decimals from ..utils.errors import PerpCityError, with_error_handling from .open_position import OpenPosition @@ -16,7 +16,6 @@ def create_perp(context: PerpCityContext, params: CreatePerpParams) -> str: def _create() -> str: - sqrt_price_x96 = price_to_sqrt_price_x96(params.starting_price) deployments = context.deployments() fees_addr = params.fees or deployments.fees_module @@ -37,7 +36,6 @@ def _create() -> str: margin_ratios_addr, lockup_period_addr, sqrt_price_impact_addr, - sqrt_price_x96, ) contract_fn = context._perp_manager.functions.createPerp(contract_params) diff --git a/src/perpcity_sdk/types.py b/src/perpcity_sdk/types.py index 24e0b6a..a2a4307 100644 --- a/src/perpcity_sdk/types.py +++ b/src/perpcity_sdk/types.py @@ -134,7 +134,6 @@ class ClosePositionResult: @dataclass class CreatePerpParams: - starting_price: float beacon: str fees: str | None = None margin_ratios: str | None = None