@pear-protocol/symmio-client 0.1.0

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,281 @@
1
+ # @pear-protocol/symmio-client
2
+
3
+ Pear Protocol's standalone SDK for **Symmio** — account management via MultiAccount, trading, deposits/withdrawals, batch operations, ClearingHouse, and administrative actions.
4
+
5
+ > Package rename: this SDK now publishes as `@pear-protocol/symmio-client`.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @pear-protocol/symmio-client viem
11
+ ```
12
+
13
+ `viem` is a peer dependency and must be installed alongside `@pear-protocol/symmio-client`.
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { SymmioSDK } from '@pear-protocol/symmio-client';
19
+ import { createPublicClient, createWalletClient, http, custom } from 'viem';
20
+ import { arbitrum } from 'viem/chains';
21
+
22
+ // Set up viem clients
23
+ const publicClient = createPublicClient({
24
+ chain: arbitrum,
25
+ transport: http(),
26
+ });
27
+
28
+ const walletClient = createWalletClient({
29
+ chain: arbitrum,
30
+ transport: custom(window.ethereum),
31
+ });
32
+
33
+ // Initialize the Symmio client SDK
34
+ const sdk = new SymmioSDK({
35
+ chainId: 42161,
36
+ publicClient,
37
+ walletClient,
38
+ });
39
+ ```
40
+
41
+ ## Core Actions
42
+
43
+ ### Account Management
44
+
45
+ ```typescript
46
+ // Create an account
47
+ const hash = await sdk.account.addAccount('Trading Account');
48
+
49
+ // Edit account name
50
+ await sdk.account.editName(accountAddress, 'New Name');
51
+
52
+ // Get all accounts for a user
53
+ const accounts = await sdk.account.getAll(userAddress);
54
+
55
+ // Get account count
56
+ const count = await sdk.account.getCount(userAddress);
57
+ ```
58
+
59
+ ### Token Approval
60
+
61
+ ```typescript
62
+ // Approve the MultiAccount contract to spend your USDC
63
+ await sdk.approval.approveCollateral(amount);
64
+
65
+ // Check approval state
66
+ import { ApprovalState } from '@pear-protocol/symmio-client';
67
+ const state = await sdk.approval.getState(tokenAddr, owner, spender, amount);
68
+ ```
69
+
70
+ ### Deposits
71
+
72
+ ```typescript
73
+ // Standard deposit
74
+ await sdk.deposit.standard({
75
+ account: '0x...',
76
+ amount: 100_000_000n, // 100 USDC (6 decimals)
77
+ });
78
+
79
+ // Deposit and allocate in a single transaction
80
+ await sdk.deposit.depositAndAllocate({
81
+ account: '0x...',
82
+ amount: 100_000_000n,
83
+ });
84
+ ```
85
+
86
+ ### Withdrawals
87
+
88
+ ```typescript
89
+ // Withdraw from an account
90
+ await sdk.withdraw.withdraw({
91
+ account: '0x...',
92
+ amount: 50_000_000n,
93
+ });
94
+ ```
95
+
96
+ ### Allocate / Deallocate
97
+
98
+ ```typescript
99
+ // Allocate collateral to trading
100
+ await sdk.collateral.allocate(subAccount, { amount: 50_000_000n });
101
+
102
+ // Deallocate with Muon signature
103
+ const deallocSig = await sdk.getDeallocateSig(subAccount);
104
+ await sdk.collateral.deallocate(subAccount, {
105
+ amount: 25_000_000n,
106
+ upnlSig: deallocSig,
107
+ });
108
+
109
+ // Internal transfer between accounts
110
+ await sdk.collateral.internalTransfer(subAccount, {
111
+ recipient: otherAccount,
112
+ amount: 10_000_000n,
113
+ });
114
+ ```
115
+
116
+ ### Trading
117
+
118
+ ```typescript
119
+ import { PositionType, OrderType, MARKET_ORDER_DEADLINE } from '@pear-protocol/symmio-client';
120
+
121
+ // Get Muon signature for opening a position
122
+ const quoteSig = await sdk.getQuoteSig(subAccount, symbolId);
123
+
124
+ // Open a position
125
+ await sdk.trade.sendQuote(subAccount, {
126
+ partyBsWhiteList: ['0x...'],
127
+ symbolId: 1,
128
+ positionType: PositionType.LONG,
129
+ orderType: OrderType.MARKET,
130
+ price: 50000_000000000000000000n,
131
+ quantity: 1_000000000000000000n,
132
+ cva: ...,
133
+ lf: ...,
134
+ partyAmm: ...,
135
+ partyBmm: ...,
136
+ maxFundingRate: ...,
137
+ deadline: BigInt(Math.floor(Date.now() / 1000)) + MARKET_ORDER_DEADLINE,
138
+ affiliate: '0x...',
139
+ upnlSig: quoteSig,
140
+ });
141
+
142
+ // Batch open multiple positions with one Muon sig
143
+ const batchSig = await sdk.getBatchSig(subAccount, [1, 2, 3]);
144
+ await sdk.trade.batchSendQuote(subAccount, {
145
+ quotes: [quote1, quote2, quote3],
146
+ upnlSig: batchSig,
147
+ });
148
+
149
+ // Close a position
150
+ await sdk.trade.closePosition(subAccount, {
151
+ quoteId: 1n,
152
+ closePrice: price,
153
+ quantityToClose: quantity,
154
+ orderType: OrderType.MARKET,
155
+ deadline: BigInt(Math.floor(Date.now() / 1000)) + MARKET_ORDER_DEADLINE,
156
+ });
157
+
158
+ // Cancel operations
159
+ await sdk.trade.cancelQuote(subAccount, quoteId);
160
+ await sdk.trade.cancelCloseRequest(subAccount, quoteId);
161
+ ```
162
+
163
+ ### Delegation
164
+
165
+ ```typescript
166
+ // Delegate access to trading selectors
167
+ await sdk.delegation.delegateAccess({
168
+ account: subAccount,
169
+ delegate: delegateAddress,
170
+ selectors: ALL_TRADING_SELECTORS,
171
+ });
172
+
173
+ // Propose to revoke access (starts cooldown)
174
+ await sdk.delegation.proposeRevoke({
175
+ account: subAccount,
176
+ delegate: delegateAddress,
177
+ selectors: ALL_TRADING_SELECTORS,
178
+ });
179
+
180
+ // Revoke access (after cooldown)
181
+ await sdk.delegation.revokeAccess({
182
+ account: subAccount,
183
+ delegate: delegateAddress,
184
+ selectors: ALL_TRADING_SELECTORS,
185
+ });
186
+ ```
187
+
188
+ ### Terms of Service
189
+
190
+ ```typescript
191
+ // Sign and store terms on-chain
192
+ const sig = await sdk.signature.signTerms();
193
+ await sdk.signature.storeSignature(sig);
194
+
195
+ // Check if user has signed
196
+ const hasSigned = await sdk.signature.hasSigned(userAddress);
197
+ ```
198
+
199
+ ## Direct Action Modules
200
+
201
+ For advanced usage, all action modules are exported individually:
202
+
203
+ ```typescript
204
+ import {
205
+ accountActions,
206
+ depositActions,
207
+ withdrawActions,
208
+ allocateActions,
209
+ tradeActions,
210
+ closeActions,
211
+ cancelActions,
212
+ approvalActions,
213
+ delegationActions,
214
+ signatureActions,
215
+ adminActions,
216
+ } from '@pear-protocol/symmio-client';
217
+
218
+ // Use prepare* functions for framework integration (wagmi, ethers, etc.)
219
+ const prepared = tradeActions.prepareSendQuote(
220
+ multiAccount,
221
+ account,
222
+ subAccount,
223
+ params
224
+ );
225
+ // prepared.config contains { account, to, data, value }
226
+ ```
227
+
228
+ ## Utilities
229
+
230
+ ```typescript
231
+ import { toWei, fromWei, formatPrice, applySlippage } from '@pear-protocol/symmio-client';
232
+
233
+ const amount = toWei('100', 6); // 100000000n
234
+ const display = fromWei(100000000n, 6); // "100"
235
+ const slipped = applySlippage(price, 1.0, true); // +1% for longs
236
+ ```
237
+
238
+ ## Architecture
239
+
240
+ ```
241
+ @pear-protocol/symmio-client
242
+ ├── client.ts → SymmioSDK class (main entry point)
243
+ ├── actions/ → All on-chain transaction builders + executors
244
+ │ ├── account.ts → Account management (MultiAccount)
245
+ │ ├── deposit.ts → Standard deposits
246
+ │ ├── withdraw.ts → Withdrawals
247
+ │ ├── allocate.ts → Allocate, deallocate, internal transfer
248
+ │ ├── trade.ts → Open positions, batch, pair trades
249
+ │ ├── close.ts → Close, batch close, ADL close
250
+ │ ├── cancel.ts → Cancel quotes and close requests
251
+ │ ├── approval.ts → ERC-20 token approvals
252
+ │ ├── delegation.ts → Delegation and access management
253
+ │ ├── signature.ts → Terms of service signing & storage
254
+ │ └── admin.ts → Role admin
255
+ ├── abis/ → Contract ABIs
256
+ ├── clients/ → External service clients (Muon)
257
+ ├── constants/ → Addresses, chains, selectors, defaults
258
+ ├── types/ → Full TypeScript type system
259
+ └── utils/ → Encoding, gas, validation, formatting
260
+ ```
261
+
262
+ ## Releases
263
+
264
+ This package uses Changesets for versioning and npm publishing.
265
+
266
+ ```bash
267
+ # create a release note for your change
268
+ npm run changeset
269
+
270
+ # apply pending version bumps and refresh package-lock.json
271
+ npm run version-packages
272
+
273
+ # publish the package to npm
274
+ npm run release
275
+ ```
276
+
277
+ The GitHub Actions release workflow expects an `NPM_TOKEN` repository secret with publish access to `@pear-protocol/symmio-client`.
278
+
279
+ ## License
280
+
281
+ MIT