@surgecredit/earn-sdk 0.1.1

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.
package/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # Surge Earn SDK
2
+
3
+ TypeScript-first SDK for wallets and web apps that want to integrate Surge Earn markets.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @surgecredit/earn-sdk viem
9
+ ```
10
+
11
+ ## Quickstart
12
+
13
+ ```ts
14
+ import { baseSepolia } from "viem/chains";
15
+ import { createWalletClient, custom } from "viem";
16
+ import {
17
+ SurgeEarnClient,
18
+ SURGE_BASE_SEPOLIA_CONFIG,
19
+ createSurgeEarnPublicClient,
20
+ } from "@surgecredit/earn-sdk";
21
+
22
+ const publicClient = createSurgeEarnPublicClient("https://sepolia.base.org", baseSepolia);
23
+ const walletClient = createWalletClient({
24
+ chain: baseSepolia,
25
+ transport: custom(window.ethereum),
26
+ });
27
+
28
+ const earn = new SurgeEarnClient({
29
+ publicClient,
30
+ walletClient,
31
+ config: SURGE_BASE_SEPOLIA_CONFIG,
32
+ });
33
+
34
+ const markets = await earn.listMarkets();
35
+ console.log(markets);
36
+ ```
37
+
38
+ ## Core API
39
+
40
+ - `listMarkets({ includeInactive? })`
41
+ - `getUserPosition(address)`
42
+ - `getUserExposures(address)`
43
+ - `getWalletUsdcBalance(address)`
44
+ - `getAllowance(owner, spender?)`
45
+ - `approveMaxUsdc({ account?, waitForReceipt? })`
46
+ - `deposit({ amountUsdc, account?, waitForReceipt? })`
47
+ - `quoteWithdrawLpTokens(account, amountUsdc)`
48
+ - `withdrawByUsdc({ amountUsdc, account, waitForReceipt? })`
49
+ - `withdrawByLpTokens({ lpTokens, account?, waitForReceipt? })`
50
+ - `setExposure({ marketId, exposurePercent, account?, waitForReceipt? })`
51
+ - `listDepositEvents({ user?, fromBlock?, toBlock?, includeTimestamps?, limit? })`
52
+ - `listWithdrawEvents({ user?, fromBlock?, toBlock?, includeTimestamps?, limit? })`
53
+ - `listActivity({ user?, fromBlock?, toBlock?, includeTimestamps?, limit? })`
54
+ - `getUserActivity(user, { fromBlock?, toBlock?, includeTimestamps?, limit? })`
55
+
56
+ ## MetaMask Write Example (UI-ready)
57
+
58
+ ```ts
59
+ import { createWalletClient, custom } from "viem";
60
+ import { baseSepolia } from "viem/chains";
61
+ import {
62
+ SurgeEarnClient,
63
+ SURGE_BASE_SEPOLIA_CONFIG,
64
+ createSurgeEarnPublicClient,
65
+ } from "@surgecredit/earn-sdk";
66
+
67
+ async function connectMetaMask() {
68
+ if (!window.ethereum) throw new Error("MetaMask not found");
69
+ const [address] = await window.ethereum.request({ method: "eth_requestAccounts" });
70
+
71
+ const chainIdHex = await window.ethereum.request({ method: "eth_chainId" });
72
+ if (Number(chainIdHex) !== baseSepolia.id) {
73
+ await window.ethereum.request({
74
+ method: "wallet_switchEthereumChain",
75
+ params: [{ chainId: "0x14a34" }],
76
+ });
77
+ }
78
+
79
+ const walletClient = createWalletClient({
80
+ chain: baseSepolia,
81
+ transport: custom(window.ethereum),
82
+ });
83
+
84
+ return { address, walletClient };
85
+ }
86
+
87
+ export async function depositFlow(amountUsdc: string) {
88
+ const { address, walletClient } = await connectMetaMask();
89
+ const publicClient = createSurgeEarnPublicClient("https://sepolia.base.org", baseSepolia);
90
+
91
+ const earn = new SurgeEarnClient({
92
+ publicClient,
93
+ walletClient,
94
+ config: SURGE_BASE_SEPOLIA_CONFIG,
95
+ });
96
+
97
+ const allowance = await earn.getAllowance(address);
98
+ if (allowance === 0n) {
99
+ await earn.approveMaxUsdc({ account: address, waitForReceipt: true });
100
+ }
101
+
102
+ await earn.deposit({ amountUsdc, account: address, waitForReceipt: true });
103
+ }
104
+
105
+ export async function withdrawFlow(amountUsdc: string) {
106
+ const { address, walletClient } = await connectMetaMask();
107
+ const publicClient = createSurgeEarnPublicClient("https://sepolia.base.org", baseSepolia);
108
+
109
+ const earn = new SurgeEarnClient({
110
+ publicClient,
111
+ walletClient,
112
+ config: SURGE_BASE_SEPOLIA_CONFIG,
113
+ });
114
+
115
+ await earn.withdrawByUsdc({ amountUsdc, account: address, waitForReceipt: true });
116
+ }
117
+ ```
118
+
119
+ ## Activity Feed Example
120
+
121
+ ```ts
122
+ const activity = await earn.getUserActivity("0xYourWalletAddress", {
123
+ fromBlock: 0n,
124
+ includeTimestamps: true,
125
+ limit: 25,
126
+ });
127
+
128
+ // Each item includes: type, amount, lpTokens, txHash, blockNumber, timestamp
129
+ ```
130
+
131
+ ## React Hooks
132
+
133
+ ```ts
134
+ import { useEarnActivity, useEarnMarkets, useEarnPortfolio } from "@surgecredit/earn-sdk/react";
135
+ ```
136
+
137
+ - `useEarnMarkets(client, { includeInactive?, pollIntervalMs? })`
138
+ - `useEarnPortfolio(client, address)`
139
+ - `useEarnActivity(client, { user?, fromBlock?, toBlock?, includeTimestamps?, limit?, pollIntervalMs? })`
140
+
141
+ ## Local Example Wallet
142
+
143
+ Run the local demo wallet:
144
+
145
+ ```bash
146
+ npm install
147
+ npm run build
148
+ cd examples/test-wallet
149
+ npm install
150
+ npm run dev
151
+ ```
152
+
153
+ The example includes:
154
+
155
+ - Mnemonic create/import for a Base Sepolia account preview
156
+ - Mnemonic persistence across refresh (localStorage)
157
+ - Faucet helper panel (copy address + ETH/USDC faucet links)
158
+ - Base Sepolia USDC balance fetch + invest flow (approve + deposit)
159
+ - Earn position and recent deposit/withdraw activity
160
+
161
+ ## Publishing
162
+
163
+ Publishing checklist and tag format are documented in `PUBLISHING.md`.
164
+
165
+ - `prepublishOnly` runs `clean` + full `verify` (test, typecheck, build)
166
+ - Use `vX.Y.Z` for stable tags and `vX.Y.Z-beta.N` for prereleases