@baseline-markets/sdk 0.0.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.
@@ -0,0 +1,221 @@
1
+ import { Address, Hex, PublicClient, WalletClient } from 'viem';
2
+
3
+ type CreateParams = {
4
+ bToken: Address;
5
+ initialPoolBTokens: bigint;
6
+ reserve: Address;
7
+ initialPoolReserves: bigint;
8
+ initialActivePrice: bigint;
9
+ initialBLV: bigint;
10
+ creator: Address;
11
+ feeRecipient: Address;
12
+ creatorFeePct: bigint;
13
+ swapFeePct: bigint;
14
+ createHook: boolean;
15
+ claimMerkleRoot: Hex;
16
+ initialCollateral: bigint;
17
+ initialDebt: bigint;
18
+ };
19
+ type PoolKey = {
20
+ currency0: Address;
21
+ currency1: Address;
22
+ fee: bigint;
23
+ tickSpacing: number;
24
+ hooks: Address;
25
+ };
26
+ type QuoteBuyBToken = {
27
+ reservesIn: bigint;
28
+ fee: bigint;
29
+ price: bigint;
30
+ };
31
+ type QuoteSellBToken = {
32
+ reservesOut: bigint;
33
+ fee: bigint;
34
+ price: bigint;
35
+ };
36
+ type QuoteBuyReserves = {
37
+ tokensIn: bigint;
38
+ fee: bigint;
39
+ price: bigint;
40
+ };
41
+ type QuoteSellReserves = {
42
+ tokensOut: bigint;
43
+ fee: bigint;
44
+ price: bigint;
45
+ };
46
+ type StakedAccount = {
47
+ amount: bigint;
48
+ locked: bigint;
49
+ earned: bigint;
50
+ userAccumulator: bigint;
51
+ };
52
+ type CreditAccount = {
53
+ collateral: bigint;
54
+ debt: bigint;
55
+ };
56
+ type TxOpts = {
57
+ account?: Address;
58
+ confirmations?: number;
59
+ onSimulateError?: (e: unknown) => void;
60
+ };
61
+ type ApprovalPolicy = 'infinite' | 'exact';
62
+ type ApprovalOpts = {
63
+ approvals?: ApprovalPolicy;
64
+ };
65
+ type NativeOpts = {
66
+ useNative?: boolean;
67
+ outputNative?: boolean;
68
+ };
69
+ type SwapOpts = TxOpts & NativeOpts & ApprovalOpts & {
70
+ slippageBps?: number;
71
+ };
72
+ type LeverageResult = {
73
+ hash: Hex;
74
+ reservesIn: bigint;
75
+ refund: bigint;
76
+ };
77
+ type DeleverageResult = {
78
+ hash: Hex;
79
+ reservesOut: bigint;
80
+ };
81
+ type SDKConfig = {
82
+ approvals?: ApprovalPolicy;
83
+ defaultUseNative?: boolean;
84
+ wrappedNative?: Address;
85
+ };
86
+
87
+ declare class BaselineSDK {
88
+ readonly publicClient: PublicClient;
89
+ readonly walletClient?: WalletClient;
90
+ readonly config?: SDKConfig;
91
+ private readonly readFactory;
92
+ private getAccount;
93
+ private requireWallet;
94
+ constructor(publicClient: PublicClient, walletClient?: WalletClient, config?: SDKConfig);
95
+ get chainId(): number;
96
+ get proxy(): Address;
97
+ get hasWallet(): boolean;
98
+ withWallet(wallet: WalletClient): BaselineSDK;
99
+ createBToken(name: string, symbol: string, totalSupply: bigint, salt: Hex, opts?: TxOpts): Promise<{
100
+ hash: Hex;
101
+ bToken: Address;
102
+ }>;
103
+ createPool(params: CreateParams, opts?: TxOpts): Promise<{
104
+ hash: Hex;
105
+ }>;
106
+ quoteBuyExactIn(bToken: Address, reservesIn: bigint): Promise<{
107
+ tokensOut: bigint;
108
+ fee: bigint;
109
+ slippage: bigint;
110
+ }>;
111
+ quoteBuyExactOut(bToken: Address, amountOut: bigint): Promise<{
112
+ amountIn: bigint;
113
+ fee: bigint;
114
+ slippage: bigint;
115
+ }>;
116
+ quoteSellExactIn(bToken: Address, amountIn: bigint): Promise<{
117
+ amountOut: bigint;
118
+ fee: bigint;
119
+ slippage: bigint;
120
+ }>;
121
+ quoteSellExactOut(bToken: Address, reservesOut: bigint): Promise<{
122
+ tokensIn: bigint;
123
+ fee: bigint;
124
+ slippage: bigint;
125
+ }>;
126
+ buyTokensExactOut(bToken: Address, amountOut: bigint, limitAmount: bigint, opts?: SwapOpts): Promise<Hex>;
127
+ sellTokensExactIn(bToken: Address, amountIn: bigint, limitAmount: bigint, opts?: SwapOpts): Promise<Hex>;
128
+ sellTokensExactOut(bToken: Address, amountOut: bigint, limitAmount: bigint, opts?: SwapOpts): Promise<Hex>;
129
+ buyTokensExactIn(bToken: Address, amountIn: bigint, limitAmount: bigint, opts?: SwapOpts): Promise<Hex>;
130
+ deposit(bToken: Address, amount: bigint, opts?: TxOpts & {
131
+ user?: Address;
132
+ }): Promise<Hex>;
133
+ withdraw(bToken: Address, amount: bigint, opts?: TxOpts): Promise<Hex>;
134
+ claim(bToken: Address, opts?: TxOpts & {
135
+ user?: Address;
136
+ asNative?: boolean;
137
+ }): Promise<{
138
+ hash: Hex;
139
+ amount: bigint;
140
+ }>;
141
+ getBorrowForCollateral(bToken: Address, collateral: bigint): Promise<{
142
+ borrowAmount: bigint;
143
+ fee: bigint;
144
+ }>;
145
+ getMaxBorrow(bToken: Address, user: Address): Promise<bigint>;
146
+ previewBorrow(bToken: Address, user: Address, borrowAmount: bigint): Promise<{
147
+ collateral: bigint;
148
+ debt: bigint;
149
+ fee: bigint;
150
+ }>;
151
+ previewRepay(bToken: Address, recipient: Address, reservesIn: bigint): Promise<{
152
+ collateralRedeemed: bigint;
153
+ debtRepaid: bigint;
154
+ }>;
155
+ borrow(bToken: Address, amount: bigint, recipient: Address, opts?: TxOpts & {
156
+ outputNative?: boolean;
157
+ }): Promise<Hex>;
158
+ repay(bToken: Address, reservesIn: bigint, recipient: Address, opts?: TxOpts & {
159
+ useNative?: boolean;
160
+ }): Promise<Hex>;
161
+ simulateLeverage(bToken: Address, totalCollateral: bigint, collateralIn: bigint, maxSwapReservesIn: bigint, opts?: TxOpts): Promise<{
162
+ debtAdded: bigint;
163
+ }>;
164
+ leverage(bToken: Address, totalCollateral: bigint, collateralIn: bigint, maxSwapReservesIn: bigint, opts?: TxOpts): Promise<{
165
+ hash: `0x${string}`;
166
+ debtAdded: bigint;
167
+ }>;
168
+ simulateDeleverage(bToken: Address, collateralToSell: bigint, minSwapReservesOut: bigint, opts?: TxOpts & {
169
+ outputNative?: boolean;
170
+ }): Promise<{
171
+ collateralRedeemed: bigint;
172
+ debtRepaid: bigint;
173
+ refund: bigint;
174
+ }>;
175
+ deleverage(bToken: Address, collateralToSell: bigint, minSwapReservesOut: bigint, opts?: TxOpts & {
176
+ outputNative?: boolean;
177
+ }): Promise<{
178
+ hash: `0x${string}`;
179
+ collateralRedeemed: bigint;
180
+ debtRepaid: bigint;
181
+ refund: bigint;
182
+ }>;
183
+ getStakedAccount(bToken: Address, user: Address): Promise<StakedAccount>;
184
+ getCreditAccount(bToken: Address, user: Address): Promise<CreditAccount>;
185
+ getTokenBalance(token: Address, user: Address): Promise<bigint>;
186
+ approve(token: Address, spender: Address, amount: bigint, opts?: TxOpts): Promise<Hex>;
187
+ getAllowance(token: Address, owner: Address, spender: Address): Promise<bigint>;
188
+ ensureApproval(token: Address, spender: Address, required: bigint, opts?: TxOpts & {
189
+ policy?: 'infinite' | 'exact';
190
+ }): Promise<void>;
191
+ getReserve(bToken: Address): Promise<Address>;
192
+ activePrice(bToken: Address): Promise<bigint>;
193
+ quoteLeverage(bToken: Address, collateralIn: bigint, leverageFactor: bigint): Promise<{
194
+ targetCollateral: bigint;
195
+ maxSwapReservesIn: bigint;
196
+ expectedDebt: bigint;
197
+ slippage: bigint;
198
+ }>;
199
+ }
200
+
201
+ /**
202
+ * Coarse-grained category for an SDKError. Consumers should branch on this
203
+ * instead of sniffing the message string or unwrapping `cause`.
204
+ *
205
+ * - `user_rejected`: user cancelled from their wallet UI
206
+ * - `reverted`: contract reverted on-chain (message carries decoded reason)
207
+ * - `insufficient_funds`: not enough native balance for gas/value
208
+ * - `network`: RPC/HTTP/socket/timeout — transient, retry-worthy
209
+ * - `wallet`: SDK misuse (no wallet client, no account)
210
+ * - `unknown`: anything we couldn't classify
211
+ */
212
+ type SDKErrorKind = 'user_rejected' | 'reverted' | 'insufficient_funds' | 'network' | 'wallet' | 'unknown';
213
+ declare class SDKError extends Error {
214
+ kind: SDKErrorKind;
215
+ component?: string;
216
+ args?: readonly unknown[];
217
+ cause?: unknown;
218
+ constructor(message: string, params?: Partial<SDKError>);
219
+ }
220
+
221
+ export { type ApprovalOpts, type ApprovalPolicy, BaselineSDK, type CreateParams, type CreditAccount, type DeleverageResult, type LeverageResult, type NativeOpts, type PoolKey, type QuoteBuyBToken, type QuoteBuyReserves, type QuoteSellBToken, type QuoteSellReserves, type SDKConfig, SDKError, type StakedAccount, type SwapOpts, type TxOpts };
@@ -0,0 +1,221 @@
1
+ import { Address, Hex, PublicClient, WalletClient } from 'viem';
2
+
3
+ type CreateParams = {
4
+ bToken: Address;
5
+ initialPoolBTokens: bigint;
6
+ reserve: Address;
7
+ initialPoolReserves: bigint;
8
+ initialActivePrice: bigint;
9
+ initialBLV: bigint;
10
+ creator: Address;
11
+ feeRecipient: Address;
12
+ creatorFeePct: bigint;
13
+ swapFeePct: bigint;
14
+ createHook: boolean;
15
+ claimMerkleRoot: Hex;
16
+ initialCollateral: bigint;
17
+ initialDebt: bigint;
18
+ };
19
+ type PoolKey = {
20
+ currency0: Address;
21
+ currency1: Address;
22
+ fee: bigint;
23
+ tickSpacing: number;
24
+ hooks: Address;
25
+ };
26
+ type QuoteBuyBToken = {
27
+ reservesIn: bigint;
28
+ fee: bigint;
29
+ price: bigint;
30
+ };
31
+ type QuoteSellBToken = {
32
+ reservesOut: bigint;
33
+ fee: bigint;
34
+ price: bigint;
35
+ };
36
+ type QuoteBuyReserves = {
37
+ tokensIn: bigint;
38
+ fee: bigint;
39
+ price: bigint;
40
+ };
41
+ type QuoteSellReserves = {
42
+ tokensOut: bigint;
43
+ fee: bigint;
44
+ price: bigint;
45
+ };
46
+ type StakedAccount = {
47
+ amount: bigint;
48
+ locked: bigint;
49
+ earned: bigint;
50
+ userAccumulator: bigint;
51
+ };
52
+ type CreditAccount = {
53
+ collateral: bigint;
54
+ debt: bigint;
55
+ };
56
+ type TxOpts = {
57
+ account?: Address;
58
+ confirmations?: number;
59
+ onSimulateError?: (e: unknown) => void;
60
+ };
61
+ type ApprovalPolicy = 'infinite' | 'exact';
62
+ type ApprovalOpts = {
63
+ approvals?: ApprovalPolicy;
64
+ };
65
+ type NativeOpts = {
66
+ useNative?: boolean;
67
+ outputNative?: boolean;
68
+ };
69
+ type SwapOpts = TxOpts & NativeOpts & ApprovalOpts & {
70
+ slippageBps?: number;
71
+ };
72
+ type LeverageResult = {
73
+ hash: Hex;
74
+ reservesIn: bigint;
75
+ refund: bigint;
76
+ };
77
+ type DeleverageResult = {
78
+ hash: Hex;
79
+ reservesOut: bigint;
80
+ };
81
+ type SDKConfig = {
82
+ approvals?: ApprovalPolicy;
83
+ defaultUseNative?: boolean;
84
+ wrappedNative?: Address;
85
+ };
86
+
87
+ declare class BaselineSDK {
88
+ readonly publicClient: PublicClient;
89
+ readonly walletClient?: WalletClient;
90
+ readonly config?: SDKConfig;
91
+ private readonly readFactory;
92
+ private getAccount;
93
+ private requireWallet;
94
+ constructor(publicClient: PublicClient, walletClient?: WalletClient, config?: SDKConfig);
95
+ get chainId(): number;
96
+ get proxy(): Address;
97
+ get hasWallet(): boolean;
98
+ withWallet(wallet: WalletClient): BaselineSDK;
99
+ createBToken(name: string, symbol: string, totalSupply: bigint, salt: Hex, opts?: TxOpts): Promise<{
100
+ hash: Hex;
101
+ bToken: Address;
102
+ }>;
103
+ createPool(params: CreateParams, opts?: TxOpts): Promise<{
104
+ hash: Hex;
105
+ }>;
106
+ quoteBuyExactIn(bToken: Address, reservesIn: bigint): Promise<{
107
+ tokensOut: bigint;
108
+ fee: bigint;
109
+ slippage: bigint;
110
+ }>;
111
+ quoteBuyExactOut(bToken: Address, amountOut: bigint): Promise<{
112
+ amountIn: bigint;
113
+ fee: bigint;
114
+ slippage: bigint;
115
+ }>;
116
+ quoteSellExactIn(bToken: Address, amountIn: bigint): Promise<{
117
+ amountOut: bigint;
118
+ fee: bigint;
119
+ slippage: bigint;
120
+ }>;
121
+ quoteSellExactOut(bToken: Address, reservesOut: bigint): Promise<{
122
+ tokensIn: bigint;
123
+ fee: bigint;
124
+ slippage: bigint;
125
+ }>;
126
+ buyTokensExactOut(bToken: Address, amountOut: bigint, limitAmount: bigint, opts?: SwapOpts): Promise<Hex>;
127
+ sellTokensExactIn(bToken: Address, amountIn: bigint, limitAmount: bigint, opts?: SwapOpts): Promise<Hex>;
128
+ sellTokensExactOut(bToken: Address, amountOut: bigint, limitAmount: bigint, opts?: SwapOpts): Promise<Hex>;
129
+ buyTokensExactIn(bToken: Address, amountIn: bigint, limitAmount: bigint, opts?: SwapOpts): Promise<Hex>;
130
+ deposit(bToken: Address, amount: bigint, opts?: TxOpts & {
131
+ user?: Address;
132
+ }): Promise<Hex>;
133
+ withdraw(bToken: Address, amount: bigint, opts?: TxOpts): Promise<Hex>;
134
+ claim(bToken: Address, opts?: TxOpts & {
135
+ user?: Address;
136
+ asNative?: boolean;
137
+ }): Promise<{
138
+ hash: Hex;
139
+ amount: bigint;
140
+ }>;
141
+ getBorrowForCollateral(bToken: Address, collateral: bigint): Promise<{
142
+ borrowAmount: bigint;
143
+ fee: bigint;
144
+ }>;
145
+ getMaxBorrow(bToken: Address, user: Address): Promise<bigint>;
146
+ previewBorrow(bToken: Address, user: Address, borrowAmount: bigint): Promise<{
147
+ collateral: bigint;
148
+ debt: bigint;
149
+ fee: bigint;
150
+ }>;
151
+ previewRepay(bToken: Address, recipient: Address, reservesIn: bigint): Promise<{
152
+ collateralRedeemed: bigint;
153
+ debtRepaid: bigint;
154
+ }>;
155
+ borrow(bToken: Address, amount: bigint, recipient: Address, opts?: TxOpts & {
156
+ outputNative?: boolean;
157
+ }): Promise<Hex>;
158
+ repay(bToken: Address, reservesIn: bigint, recipient: Address, opts?: TxOpts & {
159
+ useNative?: boolean;
160
+ }): Promise<Hex>;
161
+ simulateLeverage(bToken: Address, totalCollateral: bigint, collateralIn: bigint, maxSwapReservesIn: bigint, opts?: TxOpts): Promise<{
162
+ debtAdded: bigint;
163
+ }>;
164
+ leverage(bToken: Address, totalCollateral: bigint, collateralIn: bigint, maxSwapReservesIn: bigint, opts?: TxOpts): Promise<{
165
+ hash: `0x${string}`;
166
+ debtAdded: bigint;
167
+ }>;
168
+ simulateDeleverage(bToken: Address, collateralToSell: bigint, minSwapReservesOut: bigint, opts?: TxOpts & {
169
+ outputNative?: boolean;
170
+ }): Promise<{
171
+ collateralRedeemed: bigint;
172
+ debtRepaid: bigint;
173
+ refund: bigint;
174
+ }>;
175
+ deleverage(bToken: Address, collateralToSell: bigint, minSwapReservesOut: bigint, opts?: TxOpts & {
176
+ outputNative?: boolean;
177
+ }): Promise<{
178
+ hash: `0x${string}`;
179
+ collateralRedeemed: bigint;
180
+ debtRepaid: bigint;
181
+ refund: bigint;
182
+ }>;
183
+ getStakedAccount(bToken: Address, user: Address): Promise<StakedAccount>;
184
+ getCreditAccount(bToken: Address, user: Address): Promise<CreditAccount>;
185
+ getTokenBalance(token: Address, user: Address): Promise<bigint>;
186
+ approve(token: Address, spender: Address, amount: bigint, opts?: TxOpts): Promise<Hex>;
187
+ getAllowance(token: Address, owner: Address, spender: Address): Promise<bigint>;
188
+ ensureApproval(token: Address, spender: Address, required: bigint, opts?: TxOpts & {
189
+ policy?: 'infinite' | 'exact';
190
+ }): Promise<void>;
191
+ getReserve(bToken: Address): Promise<Address>;
192
+ activePrice(bToken: Address): Promise<bigint>;
193
+ quoteLeverage(bToken: Address, collateralIn: bigint, leverageFactor: bigint): Promise<{
194
+ targetCollateral: bigint;
195
+ maxSwapReservesIn: bigint;
196
+ expectedDebt: bigint;
197
+ slippage: bigint;
198
+ }>;
199
+ }
200
+
201
+ /**
202
+ * Coarse-grained category for an SDKError. Consumers should branch on this
203
+ * instead of sniffing the message string or unwrapping `cause`.
204
+ *
205
+ * - `user_rejected`: user cancelled from their wallet UI
206
+ * - `reverted`: contract reverted on-chain (message carries decoded reason)
207
+ * - `insufficient_funds`: not enough native balance for gas/value
208
+ * - `network`: RPC/HTTP/socket/timeout — transient, retry-worthy
209
+ * - `wallet`: SDK misuse (no wallet client, no account)
210
+ * - `unknown`: anything we couldn't classify
211
+ */
212
+ type SDKErrorKind = 'user_rejected' | 'reverted' | 'insufficient_funds' | 'network' | 'wallet' | 'unknown';
213
+ declare class SDKError extends Error {
214
+ kind: SDKErrorKind;
215
+ component?: string;
216
+ args?: readonly unknown[];
217
+ cause?: unknown;
218
+ constructor(message: string, params?: Partial<SDKError>);
219
+ }
220
+
221
+ export { type ApprovalOpts, type ApprovalPolicy, BaselineSDK, type CreateParams, type CreditAccount, type DeleverageResult, type LeverageResult, type NativeOpts, type PoolKey, type QuoteBuyBToken, type QuoteBuyReserves, type QuoteSellBToken, type QuoteSellReserves, type SDKConfig, SDKError, type StakedAccount, type SwapOpts, type TxOpts };