@kasufinance/kasu-sdk 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - develop
8
+ pull_request:
9
+ branches:
10
+ - main
11
+ - develop
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ quality-checks:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v4
22
+
23
+ - name: Set up Node.js
24
+ uses: actions/setup-node@v4
25
+ with:
26
+ node-version: 20
27
+ cache: npm
28
+
29
+ - name: Install dependencies
30
+ run: npm ci
31
+
32
+ - name: Generate contract typings
33
+ run: npm run build-tc
34
+
35
+ - name: Lint & type-check
36
+ run: npm run build
37
+
38
+ - name: Bundle library
39
+ run: npm run rollup-build
@@ -16,28 +16,32 @@ jobs:
16
16
 
17
17
  steps:
18
18
  - uses: actions/checkout@v3
19
- - name: Get the version
20
- id: get_version
21
- run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
22
19
 
23
- - name: Remove leading v
24
- id: replaced_version
25
- env:
26
- IMAGE_TAG: ${{ steps.get_version.outputs.VERSION }}
20
+ - name: Get tag version
21
+ id: tag_version
27
22
  run: |
28
- string=$IMAGE_TAG
29
- echo "VERSION=${string#v}" >> "$GITHUB_OUTPUT"
23
+ RAW_TAG="${GITHUB_REF#refs/tags/}"
24
+ echo "TAG_VERSION=${RAW_TAG#v}" >> "$GITHUB_OUTPUT"
30
25
 
31
- - name: Replace version inside package.json
32
- env:
33
- VERSION: ${{ steps.replaced_version.outputs.VERSION }}
34
- run: bash versioner.sh $VERSION
26
+ - name: Read package version
27
+ id: package_version
28
+ run: |
29
+ PKG_VERSION=$(node -p "require('./package.json').version")
30
+ echo "PACKAGE_VERSION=$PKG_VERSION" >> "$GITHUB_OUTPUT"
31
+
32
+ - name: Ensure tag matches package.json
33
+ run: |
34
+ if [ "${{ steps.tag_version.outputs.TAG_VERSION }}" != "${{ steps.package_version.outputs.PACKAGE_VERSION }}" ]; then
35
+ echo "Tag version ${{ steps.tag_version.outputs.TAG_VERSION }} does not match package.json version ${{ steps.package_version.outputs.PACKAGE_VERSION }}."
36
+ exit 1
37
+ fi
35
38
 
36
39
  - uses: actions/setup-node@v3
37
40
  with:
38
41
  node-version: 18
39
42
  registry-url: https://registry.npmjs.org/
40
43
  scope: '@kasufinance'
44
+
41
45
  - run: npm install && npm run build-tc && npm run build && npm run rollup-build && npm publish
42
46
  env:
43
47
  NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # Kasu SDK
2
+
3
+ `@kasufinance/kasu-sdk` is the shared TypeScript/JavaScript toolkit used by Kasu
4
+ frontends to interact with the Kasu protocol. It wraps the core smart
5
+ contracts, subgraphs, and Directus CMS in a single object so that dapps can
6
+ query pool data, compute portfolio statistics, and submit locking or lending
7
+ transactions without re-implementing the plumbing.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @kasufinance/kasu-sdk
13
+ # or
14
+ yarn add @kasufinance/kasu-sdk
15
+ ```
16
+
17
+ The SDK is built against `ethers@5`, so make sure your project already depends
18
+ on it (or install it alongside the SDK).
19
+
20
+ ## Runtime requirements
21
+
22
+ - **Node or browser environment with fetch/XHR** – when using the SDK on the
23
+ server (Next.js `app` router actions, serverless functions, etc.) you must
24
+ provide an XHR implementation because Directus uses it under the hood:
25
+
26
+ ```ts
27
+ // server.ts
28
+ import { XMLHttpRequest } from 'xhr2';
29
+ global.XMLHttpRequest = XMLHttpRequest;
30
+ ```
31
+
32
+ - **Provider/Signer** – pass an `ethers` `Signer` for write actions or a
33
+ `Provider` for read-only usage. The SDK does not create its own provider,
34
+ so you are free to reuse whatever the dapp already uses.
35
+
36
+ ## Configuring the SDK
37
+
38
+ The `SdkConfig` object wires the SDK to the right contracts and backends:
39
+
40
+ ```ts
41
+ import { JsonRpcProvider } from '@ethersproject/providers';
42
+ import { KasuSdk, SdkConfig } from '@kasufinance/kasu-sdk';
43
+ import { XMLHttpRequest } from 'xhr2';
44
+
45
+ global.XMLHttpRequest = XMLHttpRequest; // required on Node runtimes
46
+
47
+ const provider = new JsonRpcProvider(process.env.RPC_URL!, { skipFetchSetup: true });
48
+
49
+ const config: SdkConfig = {
50
+ contracts: {
51
+ KSUToken: '0x…',
52
+ IKSULocking: '0x…',
53
+ IKSULockBonus: '0x…',
54
+ UserManager: '0x…',
55
+ LendingPoolManager: '0x…',
56
+ KasuAllowList: '0x…',
57
+ SystemVariables: '0x…',
58
+ UserLoyaltyRewards: '0x…',
59
+ KsuPrice: '0x…',
60
+ ClearingCoordinator: '0x…',
61
+ KasuNFTs: '0x…',
62
+ ExternalTVL: '0x…',
63
+ },
64
+ // If certain pools should be hidden from users, provide their ids. Empty string
65
+ // keeps the Graph queries happy when nothing is filtered out.
66
+ UNUSED_LENDING_POOL_IDS: [''],
67
+ directusUrl: 'https://kasu-finance.directus.app/',
68
+ subgraphUrl: 'https://subgraph.satsuma-prod.com/.../api',
69
+ plumeSubgraphUrl: 'https://api.goldsky.com/.../kasu-plume/prod/gn',
70
+ };
71
+
72
+ export const kasuSdk = new KasuSdk(config, provider);
73
+ ```
74
+
75
+ See `kasu-fe-next/src/config/sdk` in the Kasu frontend repository for full
76
+ mainnet and testnet examples, including how Kasu fetches unused pool ids before
77
+ instantiating the SDK.
78
+
79
+ ## Quick start
80
+
81
+ ```ts
82
+ import { JsonRpcProvider } from '@ethersproject/providers';
83
+ import { KasuSdk } from '@kasufinance/kasu-sdk';
84
+
85
+ const provider = new JsonRpcProvider(RPC_URL);
86
+ const sdk = new KasuSdk(config, provider);
87
+
88
+ const pools = await sdk.DataService.getPoolOverview(currentEpochId);
89
+ const lockingPeriods = await sdk.Locking.getLockPeriods();
90
+ const userSummary = await sdk.Portfolio.getPortfolioSummary(userAddress);
91
+ await sdk.Locking.lockKSUTokens(amountBn, lockPeriodBn); // signer required
92
+ ```
93
+
94
+ The SDK exposes services as properties on `KasuSdk`. Each service contains the
95
+ methods for a single protocol facet:
96
+
97
+ | Service | Purpose |
98
+ | ------------- | ------------------------------------------------------------------------------------------------------------ |
99
+ | `DataService` | Aggregates on-chain data (subgraphs/external TVL) and off-chain content from Directus (pool descriptions, KPIs). |
100
+ | `Locking` | High-level helpers for KSU locking: read locking periods, calculate projected rewards, lock/unlock, claim fees. |
101
+ | `UserLending` | User-centric lending utilities (deposit/withdraw requests, transaction history, CSV builders). |
102
+ | `Portfolio` | Portfolio snapshots: balances, rewards, lending totals, APY calculations. |
103
+ | `Swapper` | Helpers for contract calls through the on-chain swapper. |
104
+
105
+ Every method is fully typed, so your editor can discover the shape of responses
106
+ (`PoolOverview`, `LockPeriod`, `PortfolioRewards`, etc.) without digging into
107
+ the implementation.
108
+
109
+ ### Working with pool filters
110
+
111
+ Many queries accept a list of pool ids to ignore (see `UNUSED_LENDING_POOL_IDS`
112
+ in the config). In the Kasu frontend we load this list from Directus before
113
+ creating the SDK:
114
+
115
+ ```ts
116
+ const unusedPools = await getUnusedPools(); // fetches Directus list
117
+ const sdk = new KasuSdk(
118
+ { ...config, UNUSED_LENDING_POOL_IDS: unusedPools.length ? unusedPools : [''] },
119
+ provider,
120
+ );
121
+ ```
122
+
123
+ Mirroring this pattern keeps your subgraph requests aligned with the official
124
+ UI and prevents deprecated pools from leaking into calculations.
125
+
126
+ ## Building & testing locally
127
+
128
+ ```bash
129
+ npm install
130
+ npm run build-tc # regenerate typechain factories
131
+ npm run build # type-check + compile
132
+ npm run rollup-build
133
+ npm test
134
+ ```
135
+
136
+ These are the same steps executed by the release workflow before publishing to
137
+ npm.
138
+
139
+ ## Support
140
+ For questions, issues, or contributions:
141
+ - GitHub Issues: [Create an issue](https://github.com/kasufinance/kasu-sdk/issues)
142
+ - Documentation: [View full docs](https://docs.kasu.finance)
143
+ - Discord: [Join our community](https://discord.gg/kasufinance)
144
+
145
+ ## License
146
+ This project is licensed under the MIT License - see the LICENSE file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kasufinance/kasu-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "dist/bundle.cjs.js",
6
6
  "module": "dist/bundle.esm.js",
@@ -1 +0,0 @@
1
- {"root":["./src/index.ts","./src/sdk-config.ts","./src/contracts/IClearingCoordinatorAbi.ts","./src/contracts/IERC20MetadataAbi.ts","./src/contracts/IFeeManagerAbi.ts","./src/contracts/IKSULockingAbi.ts","./src/contracts/IKasuAllowListAbi.ts","./src/contracts/IKasuControllerAbi.ts","./src/contracts/IKasuNFTsAbi.ts","./src/contracts/IKsuPriceAbi.ts","./src/contracts/ILendingPoolAbi.ts","./src/contracts/ILendingPoolFactoryAbi.ts","./src/contracts/ILendingPoolManagerAbi.ts","./src/contracts/ILendingPoolTrancheAbi.ts","./src/contracts/ISystemVariablesAbi.ts","./src/contracts/IUserLoyaltyRewardsAbi.ts","./src/contracts/IUserManagerAbi.ts","./src/contracts/KSULockBonusAbi.ts","./src/contracts/KasuPoolExternalTVLAbi.ts","./src/contracts/SwapperAbi.ts","./src/contracts/common.ts","./src/contracts/index.ts","./src/contracts/factories/IClearingCoordinatorAbi__factory.ts","./src/contracts/factories/IERC20MetadataAbi__factory.ts","./src/contracts/factories/IFeeManagerAbi__factory.ts","./src/contracts/factories/IKSULockingAbi__factory.ts","./src/contracts/factories/IKasuAllowListAbi__factory.ts","./src/contracts/factories/IKasuControllerAbi__factory.ts","./src/contracts/factories/IKasuNFTsAbi__factory.ts","./src/contracts/factories/IKsuPriceAbi__factory.ts","./src/contracts/factories/ILendingPoolAbi__factory.ts","./src/contracts/factories/ILendingPoolFactoryAbi__factory.ts","./src/contracts/factories/ILendingPoolManagerAbi__factory.ts","./src/contracts/factories/ILendingPoolTrancheAbi__factory.ts","./src/contracts/factories/ISystemVariablesAbi__factory.ts","./src/contracts/factories/IUserLoyaltyRewardsAbi__factory.ts","./src/contracts/factories/IUserManagerAbi__factory.ts","./src/contracts/factories/KSULockBonusAbi__factory.ts","./src/contracts/factories/KasuPoolExternalTVLAbi__factory.ts","./src/contracts/factories/SwapperAbi__factory.ts","./src/contracts/factories/index.ts","./src/services/shared.ts","./src/services/DataService/data-service.ts","./src/services/DataService/directus-types.ts","./src/services/DataService/queries.ts","./src/services/DataService/subgraph-types.ts","./src/services/DataService/types.ts","./src/services/Locking/locking.ts","./src/services/Locking/queries.ts","./src/services/Locking/types.ts","./src/services/Portfolio/portfolio.ts","./src/services/Portfolio/queries.ts","./src/services/Portfolio/types.ts","./src/services/Swapper/swapper.ts","./src/services/Swapper/types.ts","./src/services/UserLending/helper.ts","./src/services/UserLending/queries.ts","./src/services/UserLending/subgraph-types.ts","./src/services/UserLending/types.ts","./src/services/UserLending/user-lending.ts","./src/tests/sample.test.ts"],"version":"5.8.3"}
package/versioner.sh DELETED
@@ -1,6 +0,0 @@
1
- #!/bin/bash
2
-
3
- # This script replaces the version inside package.json
4
- version=$1
5
-
6
- sed -i "s/\"version\": \"[0-9]\+.[0-9]\+.[0-9]\+\"/\"version\": \"$version\"/" package.json