Skip to content

Commit

Permalink
SDK Publish and compatibility with Front-end (#152)
Browse files Browse the repository at this point in the history
Added sdk publish to npm for consumption by borrow front-end and added
necessary compatibility changes

---------

Co-authored-by: Cristian Dascalu <cristi.dascalu@gmail.com>
Co-authored-by: Roberto Cano <3525807+robercano@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 16, 2024
1 parent 083d6a9 commit 0837828
Show file tree
Hide file tree
Showing 22 changed files with 396 additions and 17 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/publish-client-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish Client Package

on:
workflow_call:
inputs:
npm_access_token:
required: true
type: secret
version_changed:
required: true
type: boolean

jobs:
publish-client-package:
if: ${{ inputs.version_changed }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
corepack: true

- name: Install pnpm
run: corepack enable && corepack prepare pnpm@latest --activate

- name: Install dependencies with pnpm
run: pnpm i

- name: Build with pnpm
run: pnpm build

- name: Publish package with pnpm
run: pnpm publish:npm
working-directory: sdk/sdk-client
env:
NPM_ACCESS_TOKEN: ${{ inputs.npm_access_token }}
38 changes: 38 additions & 0 deletions .github/workflows/publish-common-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish Common Package

on:
workflow_call:
inputs:
npm_access_token:
required: true
type: secret
version_changed:
required: true
type: boolean

jobs:
publish-common-package:
if: ${{ inputs.version_changed }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
corepack: true

- name: Install pnpm
run: corepack enable && corepack prepare pnpm@latest --activate

- name: Install dependencies with pnpm
run: pnpm i

- name: Build with pnpm
run: pnpm build

- name: Publish package with pnpm
run: pnpm publish:npm
working-directory: sdk/sdk-common
env:
NPM_ACCESS_TOKEN: ${{ inputs.npm_access_token }}
72 changes: 72 additions & 0 deletions .github/workflows/publish-packages-manually.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish Packages

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: false

on:
workflow_dispatch:
inputs:
branch:
description: 'Branch name'
required: true
type: choice
options:
- 'main'
- 'dev'
publish_option:
description: 'Select package(s) to publish'
required: true
type: choice
options:
- 'common'
- 'client'
- 'all'

jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
common_changed: ${{ steps.common-version-check.outputs.changed }}
client_changed: ${{ steps.client-version-check.outputs.changed }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.event.inputs.branch || github.ref_name }}
- id: common-version-check
run: |
if git diff HEAD^ HEAD -- sdk/sdk-common/bundle/package.json | grep '"version":'; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
- id: client-version-check
run: |
if git diff HEAD^ HEAD -- sdk/sdk-client/bundle/package.json | grep '"version":'; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
publish-common:
needs: prepare
if: >-
(needs.prepare.outputs.common_changed == 'true') &&
((github.event.inputs.publish_option == 'common') || (github.event.inputs.publish_option == 'all'))
uses: ./.github/workflows/publish-common-package.yaml
with:
npm_access_token: ${{ secrets.NPM_ACCESS_TOKEN }}
version_changed: ${{ needs.prepare.outputs.common_changed }}

publish-client:
needs: prepare
if: >-
(needs.prepare.outputs.client_changed == 'true') &&
((github.event.inputs.publish_option == 'client') || (github.event.inputs.publish_option == 'all'))
uses: ./.github/workflows/publish-client-package.yaml
with:
npm_access_token: ${{ secrets.NPM_ACCESS_TOKEN }}
version_changed: ${{ needs.prepare.outputs.client_changed }}
56 changes: 56 additions & 0 deletions .github/workflows/publish-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish Packages

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: false

on:
push:
branches:
- main
paths:
- 'sdk/sdk-common/bundle/package.json'
- 'sdk/sdk-client/bundle/package.json'

jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
common_changed: ${{ steps.common-version-check.outputs.changed }}
client_changed: ${{ steps.client-version-check.outputs.changed }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- id: common-version-check
run: |
if git diff HEAD^ HEAD -- sdk/sdk-common/bundle/package.json | grep '"version":'; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
- id: client-version-check
run: |
if git diff HEAD^ HEAD -- sdk/sdk-client/bundle/package.json | grep '"version":'; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
publish-common:
needs: prepare
if: ${{ needs.prepare.outputs.common_changed == 'true' }}
uses: ./.github/workflows/publish-common-package.yaml
with:
npm_access_token: ${{ secrets.NPM_ACCESS_TOKEN }}
version_changed: ${{ needs.prepare.outputs.common_changed }}

publish-client:
needs: prepare
if: ${{ needs.prepare.outputs.client_changed == 'true' }}
uses: ./.github/workflows/publish-client-package.yaml
with:
npm_access_token: ${{ secrets.NPM_ACCESS_TOKEN }}
version_changed: ${{ needs.prepare.outputs.client_changed }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ artifacts
.vscode

# private http envs
*.private.env.json
*.private.env.json
62 changes: 59 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sdk/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ ONE_INCH_API_URL='https://api-oasis.1inch.io'
ONE_INCH_ALLOWED_SWAP_PROTOCOLS='UNISWAP_V3,PMM1,PMM2,PMM3,PMM4,UNISWAP_V2,SUSHI,CURVE,CURVE_V2,PSM,WSTETH,BALANCER,BALANCER_V2,BALANCER_V2_WRAPPER,ST_ETH,WETH,ROCKET_POOL'

# ChainIDs where 1Inch swaps are allowed (comma separated)
ONE_INCH_SWAP_CHAIN_IDS='1'
ONE_INCH_SWAP_CHAIN_IDS='1'

SDK_LOGGING_ENABLED=
18 changes: 18 additions & 0 deletions sdk/protocol-plugins/bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "summerfi-protocol-plugins",
"version": "0.0.9",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"packageManager": "yarn@1.22.21",
"scripts": {},
"dependencies": {
"@summerfi/sdk-common": "workspace:*",
"@summerfi/deployment-utils": "workspace:*",
"@summerfi/deployment-types": "workspace:*",
"@summerfi/protocol-plugins-common": "workspace:*",
"@summerfi/testing-utils": "workspace:*",
"@summerfi/swap-common": "workspace:*",
"bignumber.js": "9.0.1",
"zod": "^3.22.4"
}
}
8 changes: 7 additions & 1 deletion sdk/protocol-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "@summerfi/protocol-plugins",
"version": "0.0.1",
"exports": {
".": {
"import": "./src/index.ts",
"types": "./src/index.d.ts"
},
"./*": {
"import": "./src/*/index.ts",
"types": "./src/*/index.d.ts"
Expand All @@ -16,7 +20,9 @@
"testw:integration": "jest tests/integration --watch",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"build": "tsc -b -v tsconfig.build.json"
"build": "tsc -b -v tsconfig.build.json",
"bundle:npm": "esbuild src/index.ts --platform=neutral --target=es2020 --conditions= --main-fields=main --bundle --sourcemap --outfile=bundle/dist/index.js --external:crypto --external:tls --external:https --external:net --external:http --external:stream --external:zlib --external:assert --keep-names && tsc --emitDeclarationOnly --outDir bundle/dist -p tsconfig.build.json",
"publish:npm": "pnpm bundle:npm && cd bundle && npm publish && cd .."
},
"dependencies": {
"@summerfi/sdk-common": "workspace:*",
Expand Down
5 changes: 5 additions & 0 deletions sdk/protocol-plugins/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './plugins/aave-v3'
export * from './plugins/spark'
export * from './plugins/maker'
export * from './plugins/common'
export * from './implementation'
14 changes: 14 additions & 0 deletions sdk/sdk-client/bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "summerfi-sdk-client",
"version": "0.0.9",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"packageManager": "yarn@1.22.21",
"scripts": {},
"dependencies": {
"@trpc/client": "11.0.0-next-beta.264",
"bignumber.js": "^9.1.2",
"superjson": "^1.13.3",
"viem": "^2.7.9"
}
}
Loading

0 comments on commit 0837828

Please sign in to comment.