diff --git a/.github/actions/old_anvil_and_api/action.yml b/.github/actions/old_anvil_and_api/action.yml new file mode 100644 index 00000000..2e7c3e33 --- /dev/null +++ b/.github/actions/old_anvil_and_api/action.yml @@ -0,0 +1,141 @@ +name: "Start Anvil forks, fund wallet, and launch API" +description: "Starts Ethereum, Arbitrum, and Base Anvil forks, funds a wallet, clones mono repo, and runs the API." + +inputs: + ethereum_rpc_url: + description: "Ethereum Mainnet RPC URL" + required: true + arbitrum_rpc_url: + description: "Arbitrum Mainnet RPC URL" + required: true + base_rpc_url: + description: "Base Mainnet RPC URL" + required: true + private_key: + description: "Private key of the wallet to fund" + required: true + mono_app_id: + description: "GitHub App ID for mono repo" + required: true + mono_app_private_key: + description: "Private key for the GitHub App for mono repo" + required: true + fund_amount_eth: + description: "ETH amount to fund the wallet with" + default: "10" + +outputs: + ethereum_local_url: + description: "Localhost RPC URL for Ethereum Anvil instance" + arbitrum_local_url: + description: "Localhost RPC URL for Arbitrum Anvil instance" + base_local_url: + description: "Localhost RPC URL for Base Anvil instance" + +runs: + using: "composite" + steps: + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + cache: false + + - name: Start Anvil Fork Ethereum + shell: bash + run: | + anvil \ + --block-time 0.05 \ + --hardfork prague \ + --host 0.0.0.0 \ + --fork-url "${{ inputs.ethereum_rpc_url }}" \ + --port 8545 \ + --chain-id 1 \ + --no-rate-limit & + echo "ethereum_local_url=http://localhost:8545" >> $GITHUB_OUTPUT + + - name: Start Anvil Fork Arbitrum + shell: bash + run: | + anvil \ + --block-time 0.05 \ + --hardfork prague \ + --host 0.0.0.0 \ + --fork-url "${{ inputs.arbitrum_rpc_url }}" \ + --port 8547 \ + --chain-id 42161 \ + --no-rate-limit & + echo "arbitrum_local_url=http://localhost:8547" >> $GITHUB_OUTPUT + + - name: Start Anvil Fork Base + shell: bash + run: | + anvil \ + --block-time 0.05 \ + --hardfork prague \ + --host 0.0.0.0 \ + --fork-url "${{ inputs.base_rpc_url }}" \ + --port 8546 \ + --chain-id 8453 \ + --no-rate-limit & + sleep 5 + echo "base_local_url=http://localhost:8546" >> $GITHUB_OUTPUT + + - name: Fund Wallet + shell: bash + run: | + WALLET_ADDRESS=$(cast wallet address --private-key "${{ inputs.private_key }}") + echo "Funding wallet: $WALLET_ADDRESS" + WEI_AMOUNT=$(cast to-wei "${{ inputs.fund_amount_eth }}" ether) + cast rpc anvil_setBalance $WALLET_ADDRESS $WEI_AMOUNT --rpc-url http://localhost:8545 + cast rpc anvil_setBalance $WALLET_ADDRESS $WEI_AMOUNT --rpc-url http://localhost:8546 + cast rpc anvil_setBalance $WALLET_ADDRESS $WEI_AMOUNT --rpc-url http://localhost:8547 + + # - name: Verify Wallet Balance + # shell: bash + # run: | + # WALLET_ADDRESS=$(cast wallet address --private-key "${{ inputs.private_key }}") + # BALANCE=$(cast balance $WALLET_ADDRESS --rpc-url http://localhost:8547) + # BALANCE_ETH=$(cast from-wei $BALANCE ether) + # echo "Wallet balance: $BALANCE_ETH ETH" + # if [ "$(echo "$BALANCE_ETH >= ${{ inputs.fund_amount_eth }}" | bc)" -ne 1 ]; then + # echo "Balance verification failed: Wallet has less ETH than expected" + # exit 1 + # fi + + - name: Generate GitHub App Token + id: generate_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ inputs.mono_app_id }} + private_key: ${{ inputs.mono_app_private_key }} + + - name: Checkout mono repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ steps.generate_token.outputs.token }} + repository: "CompassLabs/mono" + path: "mono" + + - name: Install uv + shell: bash + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Start API + shell: bash + working-directory: mono/api + env: + ETHEREUM_MAINNET_RPC_URL: http://localhost:8545 + ARBITRUM_MAINNET_RPC_URL: http://localhost:8547 + BASE_MAINNET_RPC_URL: http://localhost:8546 + PENDLE_API_URL: https://api-v2.pendle.finance + MORPHO_GRAPHQL_API_URL: https://blue-api.morpho.org/graphql + THE_GRAPH_URL_AAVE_ARBITRUM: https://gateway.thegraph.com/api/subgraphs/id/notvalid + THE_GRAPH_URL_AAVE_ETHEREUM: https://gateway.thegraph.com/api/subgraphs/id/notvalid + THE_GRAPH_URL_AAVE_BASE: https://gateway.thegraph.com/api/subgraphs/id/notvalid + THE_GRAPH_API_KEY: notvalid + ENV: "production" + run: | + make install && make run & + until curl -s http://localhost:8000/health >/dev/null; do sleep 1; done + echo "API is running" \ No newline at end of file diff --git a/.github/workflows/EXPERIMENT.yml b/.github/workflows/EXPERIMENT.yml new file mode 100644 index 00000000..b0214efe --- /dev/null +++ b/.github/workflows/EXPERIMENT.yml @@ -0,0 +1,156 @@ +name: FAILING_TEST + +on: + schedule: + # Runs at 00:00 UTC every day + - cron: "0 0 * * *" + push: + branches: + - main + #- fix-failing-tests + workflow_dispatch: + inputs: + environment: + description: "Environment to test" + required: true + type: string + + workflow_call: + inputs: + environment: + description: "Environment to test" + required: true + type: string + +permissions: + id-token: write + contents: write + +env: + AWS_ECR_STS_ROLE: arn:aws:iam::688567264391:role/DojoApiCIRole + +jobs: + validate-environment: + runs-on: ubuntu-latest + outputs: + environment: ${{ steps.validate.outputs.environment }} + steps: + - name: Validate environment input + id: validate + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" || "${{ github.event_name }}" == "workflow_call" ]]; then + ENVIRONMENT="${{ inputs.environment }}" + else + ENVIRONMENT="local" + fi + if [[ "$ENVIRONMENT" != "staging" && "$ENVIRONMENT" != "prod" && "$ENVIRONMENT" != "local" ]]; then + echo "❌ Error: Invalid environment '$ENVIRONMENT'. Must be 'staging' or 'prod' or 'local'." + exit 1 + fi + echo "✅ Environment '$ENVIRONMENT' is valid" + echo "environment=staging" >> $GITHUB_OUTPUT + + set-versions: + needs: [validate-environment] + runs-on: ubuntu-latest + outputs: + npm_package_version: ${{ steps.set-versions.outputs.npm_package_version }} + uv_package_version: ${{ steps.set-versions.outputs.uv_package_version }} + steps: + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "20" + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Set versions + id: set-versions + run: | + if [[ "${{ needs.validate-environment.outputs.environment }}" == "staging" ]]; then + NPM_PACKAGE_VERSION=$(npm view @compass-labs/api-sdk versions --json | jq -r '.[]' | grep -E 'rc|alpha|beta' | sort -V | tail -1) + UV_PACKAGE_VERSION="$(curl -s https://pypi.org/pypi/compass-api-sdk/json | jq -r '.releases | keys | .[]' | grep -E 'rc|a|b|dev' | sort -V | tail -1)" + else + NPM_PACKAGE_VERSION="latest" + UV_PACKAGE_VERSION="latest" + fi + + echo "npm_package_version=$NPM_PACKAGE_VERSION" >> $GITHUB_OUTPUT + echo "uv_package_version=$UV_PACKAGE_VERSION" >> $GITHUB_OUTPUT + + + print-context: + needs: [validate-environment, set-versions] + runs-on: ubuntu-latest + steps: + - name: Show resolved values + run: | + echo "environment: ${{ needs.validate-environment.outputs.environment }}" + echo "uv_package_version: ${{ needs.set-versions.outputs.uv_package_version }}" + + + + run-python----basic-examples-deposit-on-morpho: # + needs: [validate-environment, set-versions] + + runs-on: ubuntu-latest + env: + COMPASS_API_KEY: ${{ secrets.COMPASS_API_KEY }} + PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} + BASE_RPC_URL: http://localhost:8546 + #BASE_RPC_URL: ${{ secrets.BASE_MAINNET_RPC_URL }} + SERVER_URL: http://localhost:80 + #SERVER_URL: https://api.compasslabs.ai # uncomment this to test against staging api + NPM_PACKAGE_VERSION: ${{ needs.set-versions.outputs.npm_package_version }} + UV_PACKAGE_VERSION: ${{ needs.set-versions.outputs.uv_package_version }} + #API_KEY: + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Start up full local API and anvil + uses: ./.github/actions/local_anvil_and_api + id: local_anvil_and_api + with: + ethereum_rpc_url: ${{ secrets.ETHEREUM_MAINNET_RPC_URL }} + arbitrum_rpc_url: ${{ secrets.ARBITRUM_MAINNET_RPC_URL }} + base_rpc_url: ${{ secrets.BASE_MAINNET_RPC_URL }} + private_key: ${{ secrets.PRIVATE_KEY }} + mono_app_id: ${{ secrets.MONOREPOAPP_ID }} + mono_app_private_key: ${{ secrets.MONOREPOAPP_PRIVATE_KEY }} + fund_amount_eth: "10" + environment: ${{ needs.validate-environment.outputs.environment }} + aws_ecr_sts_role: ${{ env.AWS_ECR_STS_ROLE }} + ecr_image_uri: 688567264391.dkr.ecr.eu-west-2.amazonaws.com/dojo_api + + - name: Install dependencies + working-directory: v1/basic_examples/deposit_on_morpho/python + run: | + if [[ "$UV_PACKAGE_VERSION" != "latest" ]]; then + echo "Installing compass-api-sdk==$UV_PACKAGE_VERSION" + uv add compass-api-sdk==$UV_PACKAGE_VERSION + fi + uv sync + uv pip freeze + + - name: Show pyproject.toml + working-directory: v1/basic_examples/deposit_on_morpho/python + run: cat pyproject.toml + + - name: Show compass-api-sdk version + working-directory: v1/basic_examples/deposit_on_morpho/python + run: uv pip show compass-api-sdk || echo "compass-api-sdk not installed" + + - name: Run example + working-directory: v1/basic_examples/deposit_on_morpho/python + run: ./.venv/bin/python main.py #src/main.py # + + + + + diff --git a/.github/workflows/OLD_ACTION.yml b/.github/workflows/OLD_ACTION.yml new file mode 100644 index 00000000..6356a620 --- /dev/null +++ b/.github/workflows/OLD_ACTION.yml @@ -0,0 +1,163 @@ +name: OLD_ACTION + +on: + schedule: + # Runs at 00:00 UTC every day + - cron: "0 0 * * *" + push: + branches: + - main + - fix-failing-tests + workflow_dispatch: + inputs: + environment: + description: "Environment to test" + required: true + type: string + + + + workflow_call: + inputs: + environment: + description: "Environment to test" + required: true + type: string + +# # ✅ Cancel previous runs on same branch or PR when a new run starts +# concurrency: +# group: ${{ github.workflow }}-${{ github.ref }} +# cancel-in-progress: true + +permissions: + id-token: write + contents: write + +env: + AWS_ECR_STS_ROLE: arn:aws:iam::688567264391:role/DojoApiCIRole + +jobs: + validate-environment: + runs-on: ubuntu-latest + outputs: + environment: ${{ steps.validate.outputs.environment }} + steps: + - name: Validate environment input + id: validate + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" || "${{ github.event_name }}" == "workflow_call" ]]; then + ENVIRONMENT="${{ inputs.environment }}" + else + ENVIRONMENT="local" + fi + if [[ "$ENVIRONMENT" != "staging" && "$ENVIRONMENT" != "prod" && "$ENVIRONMENT" != "local" ]]; then + echo "❌ Error: Invalid environment '$ENVIRONMENT'. Must be 'staging' or 'prod' or 'local'." + exit 1 + fi + echo "✅ Environment '$ENVIRONMENT' is valid" + echo "environment=staging" >> $GITHUB_OUTPUT + + set-versions: + needs: [validate-environment] + runs-on: ubuntu-latest + outputs: + npm_package_version: ${{ steps.set-versions.outputs.npm_package_version }} + uv_package_version: ${{ steps.set-versions.outputs.uv_package_version }} + steps: + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "20" + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Set versions + id: set-versions + run: | + if [[ "${{ needs.validate-environment.outputs.environment }}" == "staging" ]]; then + NPM_PACKAGE_VERSION=$(npm view @compass-labs/api-sdk versions --json | jq -r '.[]' | grep -E 'rc|alpha|beta' | sort -V | tail -1) + UV_PACKAGE_VERSION="$(curl -s https://pypi.org/pypi/compass-api-sdk/json | jq -r '.releases | keys | .[]' | grep -E 'rc|a|b|dev' | sort -V | tail -1)" + else + NPM_PACKAGE_VERSION="latest" + UV_PACKAGE_VERSION="latest" + fi + + echo "npm_package_version=$NPM_PACKAGE_VERSION" >> $GITHUB_OUTPUT + echo "uv_package_version=$UV_PACKAGE_VERSION" >> $GITHUB_OUTPUT + + + print-context: + needs: [validate-environment, set-versions] + runs-on: ubuntu-latest + steps: + - name: Show resolved values + run: | + echo "environment: ${{ needs.validate-environment.outputs.environment }}" + echo "uv_package_version: ${{ needs.set-versions.outputs.uv_package_version }}" + + + + run-python----basic-examples-deposit-on-morpho: # + needs: [validate-environment, set-versions] + + runs-on: ubuntu-latest + env: + COMPASS_API_KEY: ${{ secrets.COMPASS_API_KEY }} + PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} + BASE_RPC_URL: http://localhost:8546 + #BASE_RPC_URL: ${{ secrets.BASE_MAINNET_RPC_URL }} + SERVER_URL: http://localhost:8000 + #SERVER_URL: https://api.compasslabs.ai # uncomment this to test against staging api + NPM_PACKAGE_VERSION: ${{ needs.set-versions.outputs.npm_package_version }} + UV_PACKAGE_VERSION: ${{ needs.set-versions.outputs.uv_package_version }} + #API_KEY: + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Start up full local API and anvil + uses: ./.github/actions/old_anvil_and_api + id: old_anvil_and_api + with: + ethereum_rpc_url: ${{ secrets.ETHEREUM_MAINNET_RPC_URL }} + arbitrum_rpc_url: ${{ secrets.ARBITRUM_MAINNET_RPC_URL }} + base_rpc_url: ${{ secrets.BASE_MAINNET_RPC_URL }} + private_key: ${{ secrets.PRIVATE_KEY }} + mono_app_id: ${{ secrets.MONOREPOAPP_ID }} + mono_app_private_key: ${{ secrets.MONOREPOAPP_PRIVATE_KEY }} + fund_amount_eth: "10" + #environment: ${{ needs.validate-environment.outputs.environment }} + #aws_ecr_sts_role: ${{ env.AWS_ECR_STS_ROLE }} + #ecr_image_uri: 688567264391.dkr.ecr.eu-west-2.amazonaws.com/dojo_api + + - name: Install dependencies + working-directory: v1/basic_examples/deposit_on_morpho/python + run: | + if [[ "$UV_PACKAGE_VERSION" != "latest" ]]; then + echo "Installing compass-api-sdk==$UV_PACKAGE_VERSION" + uv add compass-api-sdk==$UV_PACKAGE_VERSION + fi + uv sync + uv pip freeze + + - name: Show pyproject.toml + working-directory: v1/basic_examples/deposit_on_morpho/python + run: cat pyproject.toml + + - name: Show compass-api-sdk version + working-directory: v1/basic_examples/deposit_on_morpho/python + run: uv pip show compass-api-sdk || echo "compass-api-sdk not installed" + + - name: Run example + working-directory: v1/basic_examples/deposit_on_morpho/python + run: ./.venv/bin/python main.py #src/main.py # + + + + + diff --git a/.github/workflows/test_usecases_v0.yml b/.github/workflows/test_usecases_v0.yml index 57e35d68..fbb61f79 100644 --- a/.github/workflows/test_usecases_v0.yml +++ b/.github/workflows/test_usecases_v0.yml @@ -4,9 +4,9 @@ on: schedule: # Runs at 00:00 UTC every day - cron: "0 0 * * *" - pull_request: - branches: - - main +# pull_request: +# branches: +# - main workflow_dispatch: permissions: diff --git a/.github/workflows/test_usecases_v1.yml b/.github/workflows/test_usecases_v1.yml index b0d08099..1a28830a 100644 --- a/.github/workflows/test_usecases_v1.yml +++ b/.github/workflows/test_usecases_v1.yml @@ -4,9 +4,10 @@ on: schedule: # Runs at 00:00 UTC every day - cron: "0 0 * * *" - pull_request: - branches: - - main +# pull_request: +# branches: +# - main +# - fix-failing-tests workflow_dispatch: inputs: environment: diff --git a/v1/basic_examples/deposit_on_morpho/python/main.py b/v1/basic_examples/deposit_on_morpho/python/main.py index 2b457f55..8f676a2e 100644 --- a/v1/basic_examples/deposit_on_morpho/python/main.py +++ b/v1/basic_examples/deposit_on_morpho/python/main.py @@ -12,6 +12,8 @@ load_dotenv() +print(os.getenv("SERVER_URL")) + PRIVATE_KEY = os.getenv("PRIVATE_KEY") assert PRIVATE_KEY BASE_RPC_URL = os.getenv("BASE_RPC_URL") @@ -51,6 +53,9 @@ amount=0.03 * one_USD_in_ETH, # amount in = 0.03 USD in ETH max_slippage_percent=1, ) +devtools.debug('tx') +devtools.debug(swap_tx) +devtools.debug('-------------') # Helper function to sign and broadcast unsigned transaction: diff --git a/v1/basic_examples/deposit_on_morpho/python/pyproject.toml b/v1/basic_examples/deposit_on_morpho/python/pyproject.toml index 1ff61d95..850a12d1 100644 --- a/v1/basic_examples/deposit_on_morpho/python/pyproject.toml +++ b/v1/basic_examples/deposit_on_morpho/python/pyproject.toml @@ -5,7 +5,7 @@ description = "Add your description here" readme = "README.md" requires-python = ">=3.12" dependencies = [ - "compass-api-sdk", + "compass-api-sdk==1.1.5rc0", "devtools", "dotenv", "web3",