diff --git a/.github/workflows/aks.yml b/.github/workflows/aks.yml deleted file mode 100644 index fd18a82..0000000 --- a/.github/workflows/aks.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Build and deploy to AKS - -on: - push: - branches: - - "k8s" - -env: - AZURE_CONTAINER_REGISTRY: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }} - CLUSTER_NAME: ${{ secrets.AZURE_CLUSTER_NAME }} - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: ACR Docker Login - uses: Azure/docker-login@v1 - with: - login-server: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io - username: ${{ secrets.AZURE_ACR_USER }} - password: ${{ secrets.AZURE_ACR_PASSWORD }} - - - name: Build and Push to ACR - run: | - docker build . -t ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/v3-liq:${{ github.sha }} -t ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/v3-liq:latest - docker push --all-tags ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/v3-liq - deploy: - runs-on: ubuntu-latest - needs: build - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Azure Login - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Gets K8s context - uses: azure/aks-set-context@v2.0 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - resource-group: ${{ env.RESOURCE_GROUP }} - cluster-name: ${{ env.CLUSTER_NAME }} - - - name: Setup Kustomization - uses: azure/k8s-bake@v2.2 - with: - renderEngine: "kustomize" - kustomizationPath: "./aks/" - kubectl-version: "latest" - id: bake - - - name: Run Deployment - uses: Azure/k8s-deploy@v3.1 - with: - manifests: ${{ steps.bake.outputs.manifestsBundle }} \ No newline at end of file diff --git a/.github/workflows/gke.yml b/.github/workflows/gke.yml deleted file mode 100644 index dacd453..0000000 --- a/.github/workflows/gke.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Build and deploy to GKE - -on: - push: - branches: - - "k8s" - workflow_dispatch: - -env: - PROJECT_ID: ${{ secrets.GKE_PROJECT }} - GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }} - GKE_ZONE: ${{ secrets.GKE_ZONE }} - DEPLOYMENT_NAME: v3-liq - IMAGE: v3-liq - -jobs: - setup-build-publish-deploy: - name: Setup, Build, Publish, and Deploy - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - # Setup gcloud CLI - - uses: google-github-actions/setup-gcloud@v0 - with: - service_account_key: ${{ secrets.GKE_SA_KEY }} - project_id: ${{ secrets.GKE_PROJECT }} - - # Configure docker to use the gcloud command-line tool as a credential helper - - run: |- - gcloud --quiet auth configure-docker - - # Get the GKE credentials so we can deploy to the cluster - - uses: google-github-actions/get-gke-credentials@v0 - with: - cluster_name: ${{ env.GKE_CLUSTER }} - location: ${{ env.GKE_ZONE }} - credentials: ${{ secrets.GKE_SA_KEY }} - - # Build the Docker image - - name: Build - run: |- - docker build \ - --tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \ - --build-arg GITHUB_SHA="$GITHUB_SHA" \ - --build-arg GITHUB_REF="$GITHUB_REF" \ - . - - # Push the Docker image to gcr - - name: Publish - run: |- - docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" - # Set up kustomize - - name: Set up Kustomize - run: |- - curl --location https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.2.0/kustomize_v4.2.0_linux_amd64.tar.gz | tar xz - chmod u+x ./kustomize - # Deploy GKE cluster - - name: Deploy - run: |- - ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA - ./kustomize build . | kubectl apply -f - - kubectl rollout status deployment/$DEPLOYMENT_NAME - kubectl get services -o wide \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b3abf23..0000000 --- a/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM node:16 AS v3-ts - -# install dependencies -COPY package.json package.json -COPY yarn.lock yarn.lock -RUN yarn install --network-concurrency 1 - -# build typescript code -COPY src src -COPY test test -COPY tsconfig.json tsconfig.json -RUN yarn build - -FROM node:16 AS v3-liq - -COPY --from=v3-ts node_modules node_modules -COPY --from=v3-ts lib lib - -CMD node lib/liquidator.js \ No newline at end of file diff --git a/aks/deploy-v3-liq-1.yml b/aks/deploy-v3-liq-1.yml deleted file mode 100644 index 1e1f6e5..0000000 --- a/aks/deploy-v3-liq-1.yml +++ /dev/null @@ -1,62 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: v3-liq-1 - namespace: default -spec: - replicas: 1 - selector: - matchLabels: - app: v3-liq-1 - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - minReadySeconds: 5 - template: - metadata: - labels: - app: v3-liq-1 - spec: - containers: - - name: v3-liq - image: mango.azurecr.io/v3-liq:latest - imagePullPolicy: Always - resources: - limits: - cpu: 1250m - memory: 6Gi - requests: - cpu: 1000m - memory: 4Gi - securityContext: - allowPrivilegeEscalation: false - readOnlyRootFilesystem: true - runAsNonRoot: true - runAsUser: 1000 - env: - - name: NODE_OPTIONS - value: --max_old_space_size=4096 - - name: CLUSTER - value: mainnet - - name: GROUP - value: mainnet.1 - - name: INTERVAL - value: "3000" - - name: LIAB_LIMIT - value: "0.7" - - name: PRIVATE_KEY - valueFrom: - secretKeyRef: - name: v3-liq-aks - key: private-key - - name: ENDPOINT_URL - valueFrom: - secretKeyRef: - name: v3-liq-aks - key: endpoint-url - - name: WEBHOOK_URL - valueFrom: - secretKeyRef: - name: v3-liq-aks - key: webhook-url \ No newline at end of file diff --git a/aks/deploy-v3-liq.yml b/aks/deploy-v3-liq.yml deleted file mode 100644 index 47aeca2..0000000 --- a/aks/deploy-v3-liq.yml +++ /dev/null @@ -1,62 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: v3-liq - namespace: default -spec: - replicas: 1 - selector: - matchLabels: - app: v3-liq - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - minReadySeconds: 5 - template: - metadata: - labels: - app: v3-liq - spec: - containers: - - name: v3-liq - image: mango.azurecr.io/v3-liq:latest - imagePullPolicy: Always - resources: - limits: - cpu: 1250m - memory: 6Gi - requests: - cpu: 1000m - memory: 4Gi - securityContext: - allowPrivilegeEscalation: false - readOnlyRootFilesystem: true - runAsNonRoot: true - runAsUser: 1000 - env: - - name: NODE_OPTIONS - value: --max_old_space_size=4096 - - name: CLUSTER - value: mainnet - - name: GROUP - value: mainnet.1 - - name: INTERVAL - value: "3000" - - name: LIAB_LIMIT - value: "0.7" - - name: PRIVATE_KEY - valueFrom: - secretKeyRef: - name: v3-liq-aks - key: private-key - - name: ENDPOINT_URL - valueFrom: - secretKeyRef: - name: v3-liq-aks - key: endpoint-url - - name: WEBHOOK_URL - valueFrom: - secretKeyRef: - name: v3-liq-aks - key: webhook-url \ No newline at end of file diff --git a/aks/kustomization.yml b/aks/kustomization.yml deleted file mode 100644 index 5e50096..0000000 --- a/aks/kustomization.yml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: - - deploy-v3-liq.yml - - deploy-v3-liq-1.yml \ No newline at end of file diff --git a/gke/deploy-v3-liq-laf-1.yml b/gke/deploy-v3-liq-laf-1.yml deleted file mode 100644 index ea94499..0000000 --- a/gke/deploy-v3-liq-laf-1.yml +++ /dev/null @@ -1,64 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: v3-liq-laf-1 - namespace: default -spec: - replicas: 1 - selector: - matchLabels: - app: v3-liq-laf-1 - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - minReadySeconds: 5 - template: - metadata: - labels: - app: v3-liq-laf-1 - spec: - containers: - - name: v3-liq - image: gcr.io/PROJECT_ID/IMAGE:TAG - imagePullPolicy: Always - resources: - limits: - cpu: 500m - memory: 256Mi - requests: - cpu: 250m - memory: 128Mi - securityContext: - allowPrivilegeEscalation: false - readOnlyRootFilesystem: true - runAsNonRoot: true - runAsUser: 1000 - env: - - name: NODE_OPTIONS - value: --max_old_space_size=4096 - - name: CLUSTER - value: mainnet - - name: GROUP - value: mainnet.1 - - name: INTERVAL - value: "2500" - - name: LIAB_LIMIT - value: "0.7" - - name: LIQUIDATABLE_FEED_WEBSOCKET_ADDRESS - value: ws://10.121.128.69:9123 - - name: PRIVATE_KEY - valueFrom: - secretKeyRef: - name: v3-liq-laf - key: private-key - - name: ENDPOINT_URL - valueFrom: - secretKeyRef: - name: v3-liq-laf - key: endpoint-url - - name: WEBHOOK_URL - valueFrom: - secretKeyRef: - name: v3-liq-laf - key: webhook-url \ No newline at end of file diff --git a/gke/deploy-v3-liq-laf.yml b/gke/deploy-v3-liq-laf.yml deleted file mode 100644 index 9c79dec..0000000 --- a/gke/deploy-v3-liq-laf.yml +++ /dev/null @@ -1,64 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: v3-liq-laf - namespace: default -spec: - replicas: 1 - selector: - matchLabels: - app: v3-liq-laf - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - minReadySeconds: 5 - template: - metadata: - labels: - app: v3-liq-laf - spec: - containers: - - name: v3-liq - image: gcr.io/PROJECT_ID/IMAGE:TAG - imagePullPolicy: Always - resources: - limits: - cpu: 500m - memory: 256Mi - requests: - cpu: 250m - memory: 128Mi - securityContext: - allowPrivilegeEscalation: false - readOnlyRootFilesystem: true - runAsNonRoot: true - runAsUser: 1000 - env: - - name: NODE_OPTIONS - value: --max_old_space_size=4096 - - name: CLUSTER - value: mainnet - - name: GROUP - value: mainnet.1 - - name: INTERVAL - value: "2500" - - name: LIAB_LIMIT - value: "0.7" - - name: LIQUIDATABLE_FEED_WEBSOCKET_ADDRESS - value: ws://10.121.128.69:9123 - - name: PRIVATE_KEY - valueFrom: - secretKeyRef: - name: v3-liq-laf - key: private-key - - name: ENDPOINT_URL - valueFrom: - secretKeyRef: - name: v3-liq-laf - key: endpoint-url - - name: WEBHOOK_URL - valueFrom: - secretKeyRef: - name: v3-liq-laf - key: webhook-url \ No newline at end of file diff --git a/gke/deploy-v3-liq.yml b/gke/deploy-v3-liq.yml deleted file mode 100644 index e708696..0000000 --- a/gke/deploy-v3-liq.yml +++ /dev/null @@ -1,62 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: v3-liq - namespace: default -spec: - replicas: 1 - selector: - matchLabels: - app: v3-liq - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - minReadySeconds: 5 - template: - metadata: - labels: - app: v3-liq - spec: - containers: - - name: v3-liq - image: gcr.io/PROJECT_ID/IMAGE:TAG - imagePullPolicy: Always - resources: - limits: - cpu: 1250m - memory: 6Gi - requests: - cpu: 1000m - memory: 4Gi - securityContext: - allowPrivilegeEscalation: false - readOnlyRootFilesystem: true - runAsNonRoot: true - runAsUser: 1000 - env: - - name: NODE_OPTIONS - value: --max_old_space_size=4096 - - name: CLUSTER - value: mainnet - - name: GROUP - value: mainnet.1 - - name: INTERVAL - value: "3000" - - name: LIAB_LIMIT - value: "0.7" - - name: PRIVATE_KEY - valueFrom: - secretKeyRef: - name: v3-liq - key: private-key - - name: ENDPOINT_URL - valueFrom: - secretKeyRef: - name: v3-liq - key: endpoint-url - - name: WEBHOOK_URL - valueFrom: - secretKeyRef: - name: v3-liq - key: webhook-url \ No newline at end of file diff --git a/kustomization.yml b/kustomization.yml deleted file mode 100644 index c9b80f4..0000000 --- a/kustomization.yml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: - - gke/deploy-v3-liq-laf.yml - - gke/deploy-v3-liq-laf-1.yml \ No newline at end of file diff --git a/package.json b/package.json index 36d4441..760947f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { - "build": "tsc", "liquidator": "ts-node src/liquidator.ts", "test-liquidator": "ts-node test/liquidator.test.ts" }, @@ -58,4 +57,4 @@ "@types/bn.js": "5.1.0", "@solana/web3.js": "^1.31.0" } -} \ No newline at end of file +} diff --git a/src/liquidator.ts b/src/liquidator.ts index da3820b..d1b9428 100644 --- a/src/liquidator.ts +++ b/src/liquidator.ts @@ -603,10 +603,11 @@ async function liquidateAccount( } for (let r = 0; r < 5 && liqee.hasAnySpotOrders(); r++) { - for (let i = 0; i < mangoGroup.spotMarkets.length; i++) { + for (let i = 0; i < groupIds.spotMarkets.length; i++) { if (liqee.inMarginBasket[i]) { - const spotMarket = spotMarkets[i]; - const baseRootBank = rootBanks[i]; + const spotMarketConfig = groupIds.spotMarkets[i]; + const spotMarket = spotMarkets[spotMarketConfig.marketIndex]; + const baseRootBank = rootBanks[spotMarketConfig.marketIndex]; const quoteRootBank = rootBanks[QUOTE_INDEX]; if (baseRootBank && quoteRootBank) { @@ -1274,7 +1275,7 @@ async function closePositions( side, orderPrice, basePositionSize, - 'limit', + 'ioc', 0, bookSideInfo ? bookSideInfo : undefined, true, @@ -1326,4 +1327,4 @@ process.on('unhandledRejection', (err: any, p: any) => { console.error(`Unhandled rejection: ${err} promise: ${p})`, err); }); -main(); \ No newline at end of file +main(); diff --git a/yarn.lock b/yarn.lock index 54f8322..f00b2ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2242,4 +2242,4 @@ yn@3.1.1: yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" - integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== \ No newline at end of file + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==