From 8eca6011f9c6dc375acfd206951061250b870f12 Mon Sep 17 00:00:00 2001 From: Jakub Swierczek Date: Tue, 9 Apr 2024 09:48:04 +0200 Subject: [PATCH 1/7] feat: [sc-14958] CI/CD For monorepo (#161) --- .github/workflows/deploy-production.yaml | 67 ++++++++++++++++++++++++ .github/workflows/deploy-staging.yaml | 6 +++ 2 files changed, 73 insertions(+) create mode 100644 .github/workflows/deploy-production.yaml diff --git a/.github/workflows/deploy-production.yaml b/.github/workflows/deploy-production.yaml new file mode 100644 index 0000000000..a0eca20530 --- /dev/null +++ b/.github/workflows/deploy-production.yaml @@ -0,0 +1,67 @@ +name: 'Deploy Production' +concurrency: prod +on: + push: + branches: + - main +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout +jobs: + deploy: + name: Build & Deploy production using SST + environment: production + runs-on: ubuntu-latest + env: + ONE_INCH_API_KEY: ${{ secrets.ONE_INCH_API_KEY }} + ONE_INCH_API_VERSION: ${{ secrets.ONE_INCH_API_VERSION }} + ONE_INCH_API_URL: ${{ secrets.ONE_INCH_API_URL }} + ONE_INCH_ALLOWED_SWAP_PROTOCOLS: ${{ secrets.ONE_INCH_ALLOWED_SWAP_PROTOCOLS }} + ONE_INCH_SWAP_CHAIN_IDS: ${{ secrets.ONE_INCH_SWAP_CHAIN_IDS }} + MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }} + SUBGRAPH_BASE: ${{ secrets.SUBGRAPH_BASE }} + RPC_GATEWAY: ${{ secrets.RPC_GATEWAY }} + DEBANK_API_KEY: ${{ secrets.DEBANK_API_KEY }} + DEBANK_API_URL: ${{ secrets.DEBANK_API_URL }} + POWERTOOLS_LOG_LEVEL: ${{ vars.POWERTOOLS_LOG_LEVEL }} + + steps: + - name: Git clone the repository + uses: actions/checkout@v3 + + - name: Cache turbo build setup + uses: actions/cache@v3 + with: + path: .turbo + key: ${{ runner.os }}-turbo-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-turbo- + + - uses: pnpm/action-setup@v2.0.1 + with: + version: 8.14.1 + + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'pnpm' + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_ROLE }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Install dependencies + run: pnpm install + + - name: Prebuild + run: pnpm prebuild + + - name: Build + run: pnpm build + + - name: Deploy app + run: | + pnpm run sst:deploy:prod diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml index 28a31ea68b..bd01a19f4c 100644 --- a/.github/workflows/deploy-staging.yaml +++ b/.github/workflows/deploy-staging.yaml @@ -57,6 +57,12 @@ jobs: - name: Install dependencies run: pnpm install + - name: Prebuild + run: pnpm prebuild + + - name: Build + run: pnpm build + - name: Deploy app run: | pnpm run sst:deploy:staging From ccd5120118c6bd4dcd2e06903932f11f83cc560b Mon Sep 17 00:00:00 2001 From: Jakub Swierczek Date: Thu, 11 Apr 2024 09:55:13 +0200 Subject: [PATCH 2/7] Fix Merge GitHub Action (#162) --- .github/workflows/merge-main.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/merge-main.yaml b/.github/workflows/merge-main.yaml index bbcc8ffc83..1dec436fde 100644 --- a/.github/workflows/merge-main.yaml +++ b/.github/workflows/merge-main.yaml @@ -15,9 +15,9 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 20 - name: git config @@ -25,10 +25,13 @@ jobs: git config user.name ${{ github.actor }} - name: Merge dev -> main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} run: | git status - git pull git fetch + git checkout dev + git pull git checkout main git rebase dev git push origin main From fb3015204ec77a66b4f2b4b29698734cf6fb4f99 Mon Sep 17 00:00:00 2001 From: Jakub Swierczek Date: Fri, 12 Apr 2024 09:34:49 +0200 Subject: [PATCH 3/7] Update merge process in GitHub workflow (#164) The merge operation from 'dev' to 'main' has been refactored to use the 'merge-fast-forward-action'. This change simplifies the GitHub workflow by replacing the manual git commands with a dedicated action. In addition, custom success and failure messages have been provided for better visibility of merge status. --- .github/workflows/merge-main.yaml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/merge-main.yaml b/.github/workflows/merge-main.yaml index 1dec436fde..673da8c504 100644 --- a/.github/workflows/merge-main.yaml +++ b/.github/workflows/merge-main.yaml @@ -25,14 +25,11 @@ jobs: git config user.name ${{ github.actor }} - name: Merge dev -> main - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - run: | - git status - git fetch - git checkout dev - git pull - git checkout main - git rebase dev - git push origin main - git status + uses: pascalgn/merge-fast-forward-action@v1.3.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SUCCESS_MESSAGE: "Release merged successfully via fast-forward" + FAILURE_MESSAGE: "Failed to merge release via fast-forward" + UPDATE_STATUS: "true" + PRODUCTION_BRANCH: "main" + STAGING_BRANCH: "dev" From bbe4ae78ae55ba68c7782411f5d79d95903ed4f8 Mon Sep 17 00:00:00 2001 From: Jakub Swierczek Date: Fri, 12 Apr 2024 10:28:28 +0200 Subject: [PATCH 4/7] Update merge-main.yaml to improve merge process (#165) The merge-main.yaml file in the GitHub workflows directory has been updated to streamline the process of merging from 'dev' into 'main'. This includes fetching the 'dev' branch with no depth limit during the checkout process. Moreover, it explicitly outlines the individual steps of the git merge process replacing the fast-forward merge action previously used. --- .github/workflows/merge-main.yaml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/merge-main.yaml b/.github/workflows/merge-main.yaml index 673da8c504..6af2d589f6 100644 --- a/.github/workflows/merge-main.yaml +++ b/.github/workflows/merge-main.yaml @@ -16,6 +16,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + ref: dev + fetch-depth: 0 - uses: actions/setup-node@v4 with: @@ -25,11 +28,12 @@ jobs: git config user.name ${{ github.actor }} - name: Merge dev -> main - uses: pascalgn/merge-fast-forward-action@v1.3.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SUCCESS_MESSAGE: "Release merged successfully via fast-forward" - FAILURE_MESSAGE: "Failed to merge release via fast-forward" - UPDATE_STATUS: "true" - PRODUCTION_BRANCH: "main" - STAGING_BRANCH: "dev" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + run: | + git checkout main + git pull origin main + git checkout main + git merge --ff-only dev + git push origin main + git status From 031bb9a725cddeae8046021b639483c647f1914c Mon Sep 17 00:00:00 2001 From: Jakub Swierczek Date: Fri, 12 Apr 2024 10:52:06 +0200 Subject: [PATCH 5/7] Add bash shell in merge-main workflow (#166) The git merge operation in the "merge-main.yaml" GitHub Actions workflow was updated to explicitly declare the shell as bash. This change ensures that the workflow will run correctly, even in environments where bash is not the default shell. --- .github/workflows/merge-main.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/merge-main.yaml b/.github/workflows/merge-main.yaml index 6af2d589f6..e7f2439eed 100644 --- a/.github/workflows/merge-main.yaml +++ b/.github/workflows/merge-main.yaml @@ -19,6 +19,7 @@ jobs: with: ref: dev fetch-depth: 0 + github-token: ${{ secrets.GITHUB_TOKEN }} - uses: actions/setup-node@v4 with: @@ -28,8 +29,7 @@ jobs: git config user.name ${{ github.actor }} - name: Merge dev -> main - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + shell: bash run: | git checkout main git pull origin main From eef1fff9a3a673766e46140593d057a41ca331d4 Mon Sep 17 00:00:00 2001 From: Damian Paszkowski Date: Fri, 12 Apr 2024 11:54:46 +0200 Subject: [PATCH 6/7] feat: add handler for any pair (#163) --- sdk/sdk-common/src/common/utils/TokenUtils.ts | 5 +++++ sdk/sdk-common/src/common/utils/index.ts | 1 + .../src/handlers/getRefinanceSimulation.ts | 22 ++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 sdk/sdk-common/src/common/utils/TokenUtils.ts diff --git a/sdk/sdk-common/src/common/utils/TokenUtils.ts b/sdk/sdk-common/src/common/utils/TokenUtils.ts new file mode 100644 index 0000000000..bafd4d8e20 --- /dev/null +++ b/sdk/sdk-common/src/common/utils/TokenUtils.ts @@ -0,0 +1,5 @@ +import { IToken } from '../interfaces/IToken' + +export function isSameTokens(a: IToken, b: IToken): boolean { + return a.address === b.address && a.chainInfo.chainId === b.chainInfo.chainId +} diff --git a/sdk/sdk-common/src/common/utils/index.ts b/sdk/sdk-common/src/common/utils/index.ts index b3b8441d0b..c89f3ce010 100644 --- a/sdk/sdk-common/src/common/utils/index.ts +++ b/sdk/sdk-common/src/common/utils/index.ts @@ -1,2 +1,3 @@ export * from './PositionUtils' export * from './PercentageUtils' +export * from './TokenUtils' diff --git a/sdk/sdk-server/src/handlers/getRefinanceSimulation.ts b/sdk/sdk-server/src/handlers/getRefinanceSimulation.ts index 2d4724c4ed..bd21be09a3 100644 --- a/sdk/sdk-server/src/handlers/getRefinanceSimulation.ts +++ b/sdk/sdk-server/src/handlers/getRefinanceSimulation.ts @@ -3,12 +3,27 @@ import type { ISimulation, SimulationType } from '@summerfi/sdk-common/simulatio import { refinanceLendingToLendingSamePair, type IRefinanceDependencies, + refinanceLendingToLendingAnyPair, } from '@summerfi/simulator-service/strategies' import type { IRefinanceParameters } from '@summerfi/sdk-common/orders' import { publicProcedure } from '../TRPC' +import { isSameTokens } from '@summerfi/sdk-common/common' const inputSchema = z.custom((parameters) => parameters !== undefined) +function isToSamePair(parameters: IRefinanceParameters): boolean { + return ( + isSameTokens( + parameters.sourcePosition.debtAmount.token, + parameters.targetPosition.debtAmount.token, + ) && + isSameTokens( + parameters.sourcePosition.collateralAmount.token, + parameters.targetPosition.collateralAmount.token, + ) + ) +} + export const getRefinanceSimulation = publicProcedure .input(inputSchema) .query(async (opts): Promise> => { @@ -19,5 +34,10 @@ export const getRefinanceSimulation = publicProcedure protocolManager: opts.ctx.protocolManager, } - return await refinanceLendingToLendingSamePair(args, dependencies) + // TODO: in the end we should use just any pair + if (isToSamePair(opts.input)) { + return refinanceLendingToLendingSamePair(args, dependencies) + } + + return refinanceLendingToLendingAnyPair(args, dependencies) }) From 77b76a148596cc05b0385247049dbca129a96bc6 Mon Sep 17 00:00:00 2001 From: Jakub Swierczek Date: Fri, 12 Apr 2024 12:00:09 +0200 Subject: [PATCH 7/7] Remove merge-main.yaml workflow (#169) The .github/workflows/merge-main.yaml workflow has been removed from the project. This file controlled the manual merge process from the development branch to the main branch, but it is no longer necessary and has been deleted. --- .github/workflows/merge-main.yaml | 39 ------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 .github/workflows/merge-main.yaml diff --git a/.github/workflows/merge-main.yaml b/.github/workflows/merge-main.yaml deleted file mode 100644 index e7f2439eed..0000000000 --- a/.github/workflows/merge-main.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# This is a basic workflow that is manually triggered - -name: Merge DEV -> Main - -# Controls when the action will run. Workflow runs when manually triggered using the UI -# or API. -on: - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "greet" - release: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: dev - fetch-depth: 0 - github-token: ${{ secrets.GITHUB_TOKEN }} - - - uses: actions/setup-node@v4 - with: - node-version: 20 - - name: git config - run: | - git config user.name ${{ github.actor }} - - - name: Merge dev -> main - shell: bash - run: | - git checkout main - git pull origin main - git checkout main - git merge --ff-only dev - git push origin main - git status