@pear-protocol/symmio-client 0.2.4 → 0.2.5
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/dist/index.d.mts +295 -4886
- package/dist/index.d.ts +295 -4886
- package/dist/index.js +1709 -2047
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1710 -2047
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +64 -4867
- package/dist/react/index.d.ts +64 -4867
- package/dist/react/index.js +5883 -6646
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +5887 -6649
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider-xhUge8b7.d.mts +34 -0
- package/dist/react/provider-xhUge8b7.d.ts +34 -0
- package/dist/react/provider.d.mts +3 -0
- package/dist/react/provider.d.ts +3 -0
- package/dist/react/provider.js +195 -0
- package/dist/react/provider.js.map +1 -0
- package/dist/react/provider.mjs +193 -0
- package/dist/react/provider.mjs.map +1 -0
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -8,294 +8,72 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
// src/
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
|
|
11
|
+
// src/types/common.ts
|
|
12
|
+
var PositionType = /* @__PURE__ */ ((PositionType2) => {
|
|
13
|
+
PositionType2[PositionType2["LONG"] = 0] = "LONG";
|
|
14
|
+
PositionType2[PositionType2["SHORT"] = 1] = "SHORT";
|
|
15
|
+
return PositionType2;
|
|
16
|
+
})(PositionType || {});
|
|
17
|
+
var OrderType = /* @__PURE__ */ ((OrderType2) => {
|
|
18
|
+
OrderType2[OrderType2["LIMIT"] = 0] = "LIMIT";
|
|
19
|
+
OrderType2[OrderType2["MARKET"] = 1] = "MARKET";
|
|
20
|
+
return OrderType2;
|
|
21
|
+
})(OrderType || {});
|
|
22
|
+
var QuoteStatus = /* @__PURE__ */ ((QuoteStatus2) => {
|
|
23
|
+
QuoteStatus2[QuoteStatus2["PENDING"] = 0] = "PENDING";
|
|
24
|
+
QuoteStatus2[QuoteStatus2["LOCKED"] = 1] = "LOCKED";
|
|
25
|
+
QuoteStatus2[QuoteStatus2["CANCEL_PENDING"] = 2] = "CANCEL_PENDING";
|
|
26
|
+
QuoteStatus2[QuoteStatus2["CANCELED"] = 3] = "CANCELED";
|
|
27
|
+
QuoteStatus2[QuoteStatus2["OPENED"] = 4] = "OPENED";
|
|
28
|
+
QuoteStatus2[QuoteStatus2["CLOSE_PENDING"] = 5] = "CLOSE_PENDING";
|
|
29
|
+
QuoteStatus2[QuoteStatus2["CANCEL_CLOSE_PENDING"] = 6] = "CANCEL_CLOSE_PENDING";
|
|
30
|
+
QuoteStatus2[QuoteStatus2["CLOSED"] = 7] = "CLOSED";
|
|
31
|
+
QuoteStatus2[QuoteStatus2["LIQUIDATED"] = 8] = "LIQUIDATED";
|
|
32
|
+
QuoteStatus2[QuoteStatus2["EXPIRED"] = 9] = "EXPIRED";
|
|
33
|
+
return QuoteStatus2;
|
|
34
|
+
})(QuoteStatus || {});
|
|
35
|
+
var LiquidationStatus = /* @__PURE__ */ ((LiquidationStatus2) => {
|
|
36
|
+
LiquidationStatus2[LiquidationStatus2["NONE"] = 0] = "NONE";
|
|
37
|
+
LiquidationStatus2[LiquidationStatus2["PENDING"] = 1] = "PENDING";
|
|
38
|
+
LiquidationStatus2[LiquidationStatus2["ACTIVE"] = 2] = "ACTIVE";
|
|
39
|
+
LiquidationStatus2[LiquidationStatus2["COMPLETED"] = 3] = "COMPLETED";
|
|
40
|
+
return LiquidationStatus2;
|
|
41
|
+
})(LiquidationStatus || {});
|
|
42
|
+
var SoftLiquidationLevel = /* @__PURE__ */ ((SoftLiquidationLevel2) => {
|
|
43
|
+
SoftLiquidationLevel2[SoftLiquidationLevel2["NONE"] = 0] = "NONE";
|
|
44
|
+
SoftLiquidationLevel2[SoftLiquidationLevel2["WARNING"] = 1] = "WARNING";
|
|
45
|
+
SoftLiquidationLevel2[SoftLiquidationLevel2["CRITICAL"] = 2] = "CRITICAL";
|
|
46
|
+
SoftLiquidationLevel2[SoftLiquidationLevel2["EMERGENCY"] = 3] = "EMERGENCY";
|
|
47
|
+
return SoftLiquidationLevel2;
|
|
48
|
+
})(SoftLiquidationLevel || {});
|
|
32
49
|
|
|
33
|
-
// src/
|
|
34
|
-
var
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
var COLLATERAL_ADDRESS = {
|
|
43
|
-
[42161 /* ARBITRUM */]: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
44
|
-
[8453 /* BASE */]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
45
|
-
};
|
|
46
|
-
var CLEARING_HOUSE_ADDRESS = {
|
|
47
|
-
[42161 /* ARBITRUM */]: "0x0000000000000000000000000000000000000000",
|
|
48
|
-
[8453 /* BASE */]: "0x0000000000000000000000000000000000000000"
|
|
49
|
-
};
|
|
50
|
-
var SIGNATURE_STORE_ADDRESS = {
|
|
51
|
-
[42161 /* ARBITRUM */]: "0x94eEa58De1C8945c342dB4bE9670301638E403e2"
|
|
52
|
-
};
|
|
53
|
-
var DEFAULT_PARTY_B_ADDRESS = {
|
|
54
|
-
[42161 /* ARBITRUM */]: "0x00c069d68bc7420740460DBC3cc3fFF9b3742421",
|
|
55
|
-
[8453 /* BASE */]: "0x1EcAbF0Eba136920677C9575FAccee36f30592cf"
|
|
56
|
-
};
|
|
57
|
-
var COLLATERAL_DECIMALS = {
|
|
58
|
-
[42161 /* ARBITRUM */]: 6,
|
|
59
|
-
[8453 /* BASE */]: 6
|
|
60
|
-
};
|
|
61
|
-
function getAddress(addressMap, chainId, name) {
|
|
62
|
-
const addr = addressMap[chainId];
|
|
63
|
-
if (!addr || addr === "0x0000000000000000000000000000000000000000") {
|
|
64
|
-
throw new Error(`${name} address not configured for chain ${chainId}`);
|
|
65
|
-
}
|
|
66
|
-
return addr;
|
|
67
|
-
}
|
|
50
|
+
// src/types/affiliate.ts
|
|
51
|
+
var AffiliateFeeLevel = /* @__PURE__ */ ((AffiliateFeeLevel2) => {
|
|
52
|
+
AffiliateFeeLevel2[AffiliateFeeLevel2["USER_SYMBOL"] = 0] = "USER_SYMBOL";
|
|
53
|
+
AffiliateFeeLevel2[AffiliateFeeLevel2["USER_DEFAULT"] = 1] = "USER_DEFAULT";
|
|
54
|
+
AffiliateFeeLevel2[AffiliateFeeLevel2["SYMBOL"] = 2] = "SYMBOL";
|
|
55
|
+
AffiliateFeeLevel2[AffiliateFeeLevel2["AFFILIATE_DEFAULT"] = 3] = "AFFILIATE_DEFAULT";
|
|
56
|
+
return AffiliateFeeLevel2;
|
|
57
|
+
})(AffiliateFeeLevel || {});
|
|
68
58
|
|
|
69
|
-
// src/
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"https://muon-oracle1.rasa.capital/v1/",
|
|
79
|
-
"https://muon-oracle2.rasa.capital/v1/",
|
|
80
|
-
"https://muon-oracle3.rasa.capital/v1/",
|
|
81
|
-
"https://muon-oracle4.rasa.capital/v1/"
|
|
82
|
-
];
|
|
83
|
-
var MUON_APP_NAME = "symmio";
|
|
84
|
-
var MUON_REQUEST_TIMEOUT = 15e3;
|
|
85
|
-
var HEDGER_BASE_URLS = {
|
|
86
|
-
[42161 /* ARBITRUM */]: "https://www.perps-streaming.com/v1/42161a/0x6273242a7E88b3De90822b31648C212215caaFE4",
|
|
87
|
-
[8453 /* BASE */]: "https://www.perps-streaming.com/v1/8453a/0x6273242a7E88b3De90822b31648C212215caaFE4"
|
|
88
|
-
};
|
|
89
|
-
var SymmioSDKError = class extends Error {
|
|
90
|
-
constructor(message, code) {
|
|
91
|
-
super(message);
|
|
92
|
-
this.code = code;
|
|
93
|
-
this.name = "SymmioSDKError";
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
function validateAddress(address, name) {
|
|
97
|
-
if (!viem.isAddress(address)) {
|
|
98
|
-
throw new SymmioSDKError(
|
|
99
|
-
`Invalid ${name} address: ${address}`,
|
|
100
|
-
"INVALID_ADDRESS"
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
return address;
|
|
104
|
-
}
|
|
105
|
-
function validateAmount(amount, name) {
|
|
106
|
-
if (amount <= 0n) {
|
|
107
|
-
throw new SymmioSDKError(
|
|
108
|
-
`${name} must be a positive amount, got ${amount}`,
|
|
109
|
-
"INVALID_AMOUNT"
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function validateChainId(chainId, supportedChains) {
|
|
114
|
-
if (!supportedChains.includes(chainId)) {
|
|
115
|
-
throw new SymmioSDKError(
|
|
116
|
-
`Chain ${chainId} is not supported. Supported: ${supportedChains.join(", ")}`,
|
|
117
|
-
"UNSUPPORTED_CHAIN"
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function validateDeadline(deadline) {
|
|
122
|
-
const now = BigInt(Math.floor(Date.now() / 1e3));
|
|
123
|
-
if (deadline <= now) {
|
|
124
|
-
throw new SymmioSDKError(
|
|
125
|
-
`Deadline ${deadline} is in the past (current: ${now})`,
|
|
126
|
-
"EXPIRED_DEADLINE"
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function validateQuantity(quantity) {
|
|
131
|
-
if (quantity <= 0n) {
|
|
132
|
-
throw new SymmioSDKError(
|
|
133
|
-
`Quantity must be positive, got ${quantity}`,
|
|
134
|
-
"INVALID_QUANTITY"
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
59
|
+
// src/types/clearingHouse.ts
|
|
60
|
+
var ClearingHouseLiquidationStatus = /* @__PURE__ */ ((ClearingHouseLiquidationStatus2) => {
|
|
61
|
+
ClearingHouseLiquidationStatus2[ClearingHouseLiquidationStatus2["INITIATED"] = 0] = "INITIATED";
|
|
62
|
+
ClearingHouseLiquidationStatus2[ClearingHouseLiquidationStatus2["DEALLOCATED"] = 1] = "DEALLOCATED";
|
|
63
|
+
ClearingHouseLiquidationStatus2[ClearingHouseLiquidationStatus2["POSITIONS_CLOSED"] = 2] = "POSITIONS_CLOSED";
|
|
64
|
+
ClearingHouseLiquidationStatus2[ClearingHouseLiquidationStatus2["SETTLED"] = 3] = "SETTLED";
|
|
65
|
+
ClearingHouseLiquidationStatus2[ClearingHouseLiquidationStatus2["COMPLETED"] = 4] = "COMPLETED";
|
|
66
|
+
return ClearingHouseLiquidationStatus2;
|
|
67
|
+
})(ClearingHouseLiquidationStatus || {});
|
|
138
68
|
|
|
139
|
-
// src/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
function parseSingleUpnlSig(result) {
|
|
148
|
-
const data = result["result"];
|
|
149
|
-
if (!data) {
|
|
150
|
-
throw new SymmioSDKError("Invalid Muon response: missing result", "MUON_PARSE_ERROR");
|
|
151
|
-
}
|
|
152
|
-
const sigData = data["data"];
|
|
153
|
-
const signParams = sigData?.["signParams"] ?? data["signParams"];
|
|
154
|
-
const signatures = sigData?.["signatures"] ?? data["signatures"];
|
|
155
|
-
return {
|
|
156
|
-
reqId: signParams["reqId"],
|
|
157
|
-
timestamp: BigInt(signParams["timestamp"]),
|
|
158
|
-
upnl: BigInt(signParams["upnl"]),
|
|
159
|
-
gatewaySignature: signatures?.[0]?.["signature"] ?? "0x",
|
|
160
|
-
sigs: parseSchnorrSign(
|
|
161
|
-
signParams["sigs"] ?? signatures?.[1]
|
|
162
|
-
)
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function parseSingleUpnlAndPriceSig(result) {
|
|
166
|
-
const data = result["result"];
|
|
167
|
-
if (!data) {
|
|
168
|
-
throw new SymmioSDKError("Invalid Muon response: missing result", "MUON_PARSE_ERROR");
|
|
169
|
-
}
|
|
170
|
-
const sigData = data["data"];
|
|
171
|
-
const signParams = sigData?.["signParams"] ?? data["signParams"];
|
|
172
|
-
const signatures = sigData?.["signatures"] ?? data["signatures"];
|
|
173
|
-
return {
|
|
174
|
-
reqId: signParams["reqId"],
|
|
175
|
-
timestamp: BigInt(signParams["timestamp"]),
|
|
176
|
-
upnl: BigInt(signParams["upnl"]),
|
|
177
|
-
price: BigInt(signParams["price"]),
|
|
178
|
-
gatewaySignature: signatures?.[0]?.["signature"] ?? "0x",
|
|
179
|
-
sigs: parseSchnorrSign(
|
|
180
|
-
signParams["sigs"] ?? signatures?.[1]
|
|
181
|
-
)
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function parseBatchSig(result) {
|
|
185
|
-
const data = result["result"];
|
|
186
|
-
if (!data) {
|
|
187
|
-
throw new SymmioSDKError("Invalid Muon response: missing result", "MUON_PARSE_ERROR");
|
|
188
|
-
}
|
|
189
|
-
const sigData = data["data"];
|
|
190
|
-
const signParams = sigData?.["signParams"] ?? data["signParams"];
|
|
191
|
-
const signatures = sigData?.["signatures"] ?? data["signatures"];
|
|
192
|
-
return {
|
|
193
|
-
reqId: signParams["reqId"],
|
|
194
|
-
timestamp: BigInt(signParams["timestamp"]),
|
|
195
|
-
upnl: BigInt(signParams["upnl"]),
|
|
196
|
-
prices: signParams["prices"].map((p) => BigInt(p)),
|
|
197
|
-
symbolIds: signParams["symbolIds"].map((s) => BigInt(s)),
|
|
198
|
-
gatewaySignature: signatures?.[0]?.["signature"] ?? "0x",
|
|
199
|
-
sigs: parseSchnorrSign(
|
|
200
|
-
signParams["sigs"] ?? signatures?.[1]
|
|
201
|
-
)
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
var MuonClient = class {
|
|
205
|
-
baseUrls;
|
|
206
|
-
appName;
|
|
207
|
-
timeout;
|
|
208
|
-
constructor(config) {
|
|
209
|
-
this.baseUrls = config?.baseUrls ?? MUON_BASE_URLS;
|
|
210
|
-
this.appName = config?.appName ?? MUON_APP_NAME;
|
|
211
|
-
this.timeout = config?.timeout ?? MUON_REQUEST_TIMEOUT;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Sends a request to Muon, trying each base URL in order until one succeeds.
|
|
215
|
-
*/
|
|
216
|
-
async sendRequest(method, params) {
|
|
217
|
-
let lastError = null;
|
|
218
|
-
for (const baseUrl of this.baseUrls) {
|
|
219
|
-
try {
|
|
220
|
-
const searchParams = new URLSearchParams({
|
|
221
|
-
app: this.appName,
|
|
222
|
-
method
|
|
223
|
-
});
|
|
224
|
-
for (const [key, value] of Object.entries(params)) {
|
|
225
|
-
searchParams.set(`params[${key}]`, value);
|
|
226
|
-
}
|
|
227
|
-
const url = `${baseUrl}?${searchParams.toString()}`;
|
|
228
|
-
const controller = new AbortController();
|
|
229
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
230
|
-
const response = await fetch(url, { signal: controller.signal });
|
|
231
|
-
clearTimeout(timeoutId);
|
|
232
|
-
if (!response.ok) {
|
|
233
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
234
|
-
}
|
|
235
|
-
const json = await response.json();
|
|
236
|
-
if (json["error"]) {
|
|
237
|
-
throw new Error(`Muon error: ${JSON.stringify(json["error"])}`);
|
|
238
|
-
}
|
|
239
|
-
return json;
|
|
240
|
-
} catch (err) {
|
|
241
|
-
lastError = err instanceof Error ? err : new Error(String(err));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
throw new SymmioSDKError(
|
|
245
|
-
`All Muon nodes failed. Last error: ${lastError?.message}`,
|
|
246
|
-
"MUON_REQUEST_FAILED"
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Gets a UPnL + Price signature for opening a position (sendQuote).
|
|
251
|
-
*/
|
|
252
|
-
async getQuoteSig(params) {
|
|
253
|
-
const result = await this.sendRequest("uPnl_A_withSymbolPrice", {
|
|
254
|
-
partyA: params.partyA,
|
|
255
|
-
chainId: params.chainId.toString(),
|
|
256
|
-
symmio: params.symmioAddress,
|
|
257
|
-
symbolId: params.symbolId.toString()
|
|
258
|
-
});
|
|
259
|
-
return parseSingleUpnlAndPriceSig(result);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Gets a UPnL signature for deallocating funds.
|
|
263
|
-
* v0.8.5: Now includes pendingBalance for safe deallocate.
|
|
264
|
-
*/
|
|
265
|
-
async getDeallocateSig(params) {
|
|
266
|
-
const result = await this.sendRequest("uPnl_A", {
|
|
267
|
-
partyA: params.partyA,
|
|
268
|
-
chainId: params.chainId.toString(),
|
|
269
|
-
symmio: params.symmioAddress
|
|
270
|
-
});
|
|
271
|
-
return parseSingleUpnlSig(result);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Gets a batch signature for multiple positions (v0.8.5).
|
|
275
|
-
* Single signature covers multiple symbol prices for batch open/close.
|
|
276
|
-
*/
|
|
277
|
-
async getBatchSig(params) {
|
|
278
|
-
const result = await this.sendRequest("uPnl_A_withSymbolPrices", {
|
|
279
|
-
partyA: params.partyA,
|
|
280
|
-
chainId: params.chainId.toString(),
|
|
281
|
-
symmio: params.symmioAddress,
|
|
282
|
-
symbolIds: params.symbolIds.join(",")
|
|
283
|
-
});
|
|
284
|
-
return parseBatchSig(result);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
// src/actions/account.ts
|
|
289
|
-
var account_exports = {};
|
|
290
|
-
__export(account_exports, {
|
|
291
|
-
addAccount: () => addAccount,
|
|
292
|
-
editAccountName: () => editAccountName,
|
|
293
|
-
getAccounts: () => getAccounts,
|
|
294
|
-
getAccountsLength: () => getAccountsLength,
|
|
295
|
-
getOwner: () => getOwner,
|
|
296
|
-
prepareAddAccount: () => prepareAddAccount,
|
|
297
|
-
prepareEditAccountName: () => prepareEditAccountName
|
|
298
|
-
});
|
|
69
|
+
// src/types/instant.ts
|
|
70
|
+
var InstantCloseStatus = /* @__PURE__ */ ((InstantCloseStatus2) => {
|
|
71
|
+
InstantCloseStatus2[InstantCloseStatus2["STARTED"] = 0] = "STARTED";
|
|
72
|
+
InstantCloseStatus2[InstantCloseStatus2["PROCESSING"] = 1] = "PROCESSING";
|
|
73
|
+
InstantCloseStatus2[InstantCloseStatus2["FAILED"] = 2] = "FAILED";
|
|
74
|
+
InstantCloseStatus2[InstantCloseStatus2["FINISHED"] = 3] = "FINISHED";
|
|
75
|
+
return InstantCloseStatus2;
|
|
76
|
+
})(InstantCloseStatus || {});
|
|
299
77
|
|
|
300
78
|
// src/abis/MultiAccount.ts
|
|
301
79
|
var MultiAccountABI = [
|
|
@@ -702,188 +480,6 @@ var MultiAccountABI = [
|
|
|
702
480
|
{ name: "RoleRevoked", type: "event", inputs: [{ name: "role", type: "bytes32", indexed: true }, { name: "account", type: "address", indexed: true }, { name: "sender", type: "address", indexed: true }] }
|
|
703
481
|
];
|
|
704
482
|
|
|
705
|
-
// src/utils/gas.ts
|
|
706
|
-
function calculateGasMargin(estimatedGas) {
|
|
707
|
-
return estimatedGas * (100n + GAS_MARGIN_PERCENTAGE) / 100n;
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
// src/actions/account.ts
|
|
711
|
-
function prepareAddAccount(multiAccount, account, name) {
|
|
712
|
-
const data = viem.encodeFunctionData({
|
|
713
|
-
abi: MultiAccountABI,
|
|
714
|
-
functionName: "addAccount",
|
|
715
|
-
args: [name]
|
|
716
|
-
});
|
|
717
|
-
return {
|
|
718
|
-
functionName: "addAccount",
|
|
719
|
-
args: [name],
|
|
720
|
-
config: { account, to: multiAccount, data, value: 0n }
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
function prepareEditAccountName(multiAccount, account, accountAddress, name) {
|
|
724
|
-
const data = viem.encodeFunctionData({
|
|
725
|
-
abi: MultiAccountABI,
|
|
726
|
-
functionName: "editAccountName",
|
|
727
|
-
args: [accountAddress, name]
|
|
728
|
-
});
|
|
729
|
-
return {
|
|
730
|
-
functionName: "editAccountName",
|
|
731
|
-
args: [accountAddress, name],
|
|
732
|
-
config: { account, to: multiAccount, data, value: 0n }
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
async function addAccount(walletClient, publicClient, multiAccount, name) {
|
|
736
|
-
const account = walletClient.account?.address;
|
|
737
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
738
|
-
const prepared = prepareAddAccount(multiAccount, account, name);
|
|
739
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
740
|
-
return walletClient.sendTransaction({
|
|
741
|
-
...prepared.config,
|
|
742
|
-
gas: calculateGasMargin(gas),
|
|
743
|
-
chain: walletClient.chain
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
async function editAccountName(walletClient, publicClient, multiAccount, accountAddress, name) {
|
|
747
|
-
const account = walletClient.account?.address;
|
|
748
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
749
|
-
const prepared = prepareEditAccountName(multiAccount, account, accountAddress, name);
|
|
750
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
751
|
-
return walletClient.sendTransaction({
|
|
752
|
-
...prepared.config,
|
|
753
|
-
gas: calculateGasMargin(gas),
|
|
754
|
-
chain: walletClient.chain
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
async function getAccounts(publicClient, multiAccount, user, start = 0, size = 100) {
|
|
758
|
-
const result = await publicClient.readContract({
|
|
759
|
-
address: multiAccount,
|
|
760
|
-
abi: MultiAccountABI,
|
|
761
|
-
functionName: "getAccounts",
|
|
762
|
-
args: [user, BigInt(start), BigInt(size)]
|
|
763
|
-
});
|
|
764
|
-
return result;
|
|
765
|
-
}
|
|
766
|
-
async function getAccountsLength(publicClient, multiAccount, user) {
|
|
767
|
-
const result = await publicClient.readContract({
|
|
768
|
-
address: multiAccount,
|
|
769
|
-
abi: MultiAccountABI,
|
|
770
|
-
functionName: "getAccountsLength",
|
|
771
|
-
args: [user]
|
|
772
|
-
});
|
|
773
|
-
return Number(result);
|
|
774
|
-
}
|
|
775
|
-
async function getOwner(publicClient, multiAccount, accountAddress) {
|
|
776
|
-
const result = await publicClient.readContract({
|
|
777
|
-
address: multiAccount,
|
|
778
|
-
abi: MultiAccountABI,
|
|
779
|
-
functionName: "owners",
|
|
780
|
-
args: [accountAddress]
|
|
781
|
-
});
|
|
782
|
-
return result;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
// src/actions/deposit.ts
|
|
786
|
-
var deposit_exports = {};
|
|
787
|
-
__export(deposit_exports, {
|
|
788
|
-
deposit: () => deposit,
|
|
789
|
-
depositAndAllocate: () => depositAndAllocate,
|
|
790
|
-
prepareDeposit: () => prepareDeposit,
|
|
791
|
-
prepareDepositAndAllocate: () => prepareDepositAndAllocate
|
|
792
|
-
});
|
|
793
|
-
function prepareDeposit(multiAccount, account, params) {
|
|
794
|
-
validateAmount(params.amount, "deposit amount");
|
|
795
|
-
validateAddress(params.account, "account");
|
|
796
|
-
const data = viem.encodeFunctionData({
|
|
797
|
-
abi: MultiAccountABI,
|
|
798
|
-
functionName: "depositForAccount",
|
|
799
|
-
args: [params.account, params.amount]
|
|
800
|
-
});
|
|
801
|
-
return {
|
|
802
|
-
functionName: "depositForAccount",
|
|
803
|
-
args: [params.account, params.amount],
|
|
804
|
-
config: { account, to: multiAccount, data, value: 0n }
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
function prepareDepositAndAllocate(multiAccount, account, params) {
|
|
808
|
-
validateAmount(params.amount, "deposit amount");
|
|
809
|
-
validateAddress(params.account, "account");
|
|
810
|
-
const data = viem.encodeFunctionData({
|
|
811
|
-
abi: MultiAccountABI,
|
|
812
|
-
functionName: "depositAndAllocateForAccount",
|
|
813
|
-
args: [params.account, params.amount]
|
|
814
|
-
});
|
|
815
|
-
return {
|
|
816
|
-
functionName: "depositAndAllocateForAccount",
|
|
817
|
-
args: [params.account, params.amount],
|
|
818
|
-
config: { account, to: multiAccount, data, value: 0n }
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
async function deposit(walletClient, publicClient, multiAccount, params) {
|
|
822
|
-
const account = walletClient.account?.address;
|
|
823
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
824
|
-
const prepared = prepareDeposit(multiAccount, account, params);
|
|
825
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
826
|
-
return walletClient.sendTransaction({
|
|
827
|
-
...prepared.config,
|
|
828
|
-
gas: calculateGasMargin(gas),
|
|
829
|
-
chain: walletClient.chain
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
async function depositAndAllocate(walletClient, publicClient, multiAccount, params) {
|
|
833
|
-
const account = walletClient.account?.address;
|
|
834
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
835
|
-
const prepared = prepareDepositAndAllocate(multiAccount, account, params);
|
|
836
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
837
|
-
return walletClient.sendTransaction({
|
|
838
|
-
...prepared.config,
|
|
839
|
-
gas: calculateGasMargin(gas),
|
|
840
|
-
chain: walletClient.chain
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
// src/actions/withdraw.ts
|
|
845
|
-
var withdraw_exports = {};
|
|
846
|
-
__export(withdraw_exports, {
|
|
847
|
-
prepareWithdraw: () => prepareWithdraw,
|
|
848
|
-
withdraw: () => withdraw
|
|
849
|
-
});
|
|
850
|
-
function prepareWithdraw(multiAccount, account, params) {
|
|
851
|
-
validateAmount(params.amount, "withdraw amount");
|
|
852
|
-
validateAddress(params.account, "account");
|
|
853
|
-
const data = viem.encodeFunctionData({
|
|
854
|
-
abi: MultiAccountABI,
|
|
855
|
-
functionName: "withdrawFromAccount",
|
|
856
|
-
args: [params.account, params.amount]
|
|
857
|
-
});
|
|
858
|
-
return {
|
|
859
|
-
functionName: "withdrawFromAccount",
|
|
860
|
-
args: [params.account, params.amount],
|
|
861
|
-
config: { account, to: multiAccount, data, value: 0n }
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
865
|
-
const account = walletClient.account?.address;
|
|
866
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
867
|
-
const prepared = prepareWithdraw(multiAccount, account, params);
|
|
868
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
869
|
-
return walletClient.sendTransaction({
|
|
870
|
-
...prepared.config,
|
|
871
|
-
gas: calculateGasMargin(gas),
|
|
872
|
-
chain: walletClient.chain
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
// src/actions/allocate.ts
|
|
877
|
-
var allocate_exports = {};
|
|
878
|
-
__export(allocate_exports, {
|
|
879
|
-
allocate: () => allocate,
|
|
880
|
-
deallocate: () => deallocate,
|
|
881
|
-
internalTransfer: () => internalTransfer,
|
|
882
|
-
prepareAllocate: () => prepareAllocate,
|
|
883
|
-
prepareDeallocate: () => prepareDeallocate,
|
|
884
|
-
prepareInternalTransfer: () => prepareInternalTransfer
|
|
885
|
-
});
|
|
886
|
-
|
|
887
483
|
// src/abis/SymmioDiamond.ts
|
|
888
484
|
var SymmioDiamondABI = [
|
|
889
485
|
{
|
|
@@ -23268,1687 +22864,1754 @@ var SymmioDiamondABI = [
|
|
|
23268
22864
|
type: "function"
|
|
23269
22865
|
}
|
|
23270
22866
|
];
|
|
23271
|
-
function encodeCall(abi, functionName, args) {
|
|
23272
|
-
return viem.encodeFunctionData({
|
|
23273
|
-
abi,
|
|
23274
|
-
functionName,
|
|
23275
|
-
args
|
|
23276
|
-
});
|
|
23277
|
-
}
|
|
23278
|
-
function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
|
|
23279
|
-
const data = viem.encodeFunctionData({
|
|
23280
|
-
abi: accountDiamondAbi,
|
|
23281
|
-
functionName: "_call",
|
|
23282
|
-
args: [subAccount, callDatas]
|
|
23283
|
-
});
|
|
23284
|
-
return {
|
|
23285
|
-
functionName: "_call",
|
|
23286
|
-
args: [subAccount, callDatas],
|
|
23287
|
-
data
|
|
23288
|
-
};
|
|
23289
|
-
}
|
|
23290
|
-
|
|
23291
|
-
// src/actions/allocate.ts
|
|
23292
|
-
function prepareAllocate(multiAccount, account, subAccount, params) {
|
|
23293
|
-
validateAmount(params.amount, "allocate amount");
|
|
23294
|
-
const innerData = viem.encodeFunctionData({
|
|
23295
|
-
abi: SymmioDiamondABI,
|
|
23296
|
-
functionName: "allocate",
|
|
23297
|
-
args: [params.amount]
|
|
23298
|
-
});
|
|
23299
|
-
const proxy = wrapInProxyCall(
|
|
23300
|
-
MultiAccountABI,
|
|
23301
|
-
subAccount,
|
|
23302
|
-
[innerData]
|
|
23303
|
-
);
|
|
23304
|
-
return {
|
|
23305
|
-
functionName: "_call",
|
|
23306
|
-
args: proxy.args,
|
|
23307
|
-
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23308
|
-
};
|
|
23309
|
-
}
|
|
23310
|
-
function prepareDeallocate(multiAccount, account, subAccount, params) {
|
|
23311
|
-
validateAmount(params.amount, "deallocate amount");
|
|
23312
|
-
const muonSig = {
|
|
23313
|
-
reqId: params.upnlSig.reqId,
|
|
23314
|
-
timestamp: params.upnlSig.timestamp,
|
|
23315
|
-
upnl: params.upnlSig.upnl,
|
|
23316
|
-
gatewaySignature: params.upnlSig.gatewaySignature,
|
|
23317
|
-
sigs: {
|
|
23318
|
-
signature: params.upnlSig.sigs.signature,
|
|
23319
|
-
owner: params.upnlSig.sigs.owner,
|
|
23320
|
-
nonce: params.upnlSig.sigs.nonce
|
|
23321
|
-
}
|
|
23322
|
-
};
|
|
23323
|
-
const innerData = viem.encodeFunctionData({
|
|
23324
|
-
abi: SymmioDiamondABI,
|
|
23325
|
-
functionName: "deallocate",
|
|
23326
|
-
args: [params.amount, muonSig]
|
|
23327
|
-
});
|
|
23328
|
-
const proxy = wrapInProxyCall(
|
|
23329
|
-
MultiAccountABI,
|
|
23330
|
-
subAccount,
|
|
23331
|
-
[innerData]
|
|
23332
|
-
);
|
|
23333
|
-
return {
|
|
23334
|
-
functionName: "_call",
|
|
23335
|
-
args: proxy.args,
|
|
23336
|
-
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23337
|
-
};
|
|
23338
|
-
}
|
|
23339
|
-
function prepareInternalTransfer(multiAccount, account, subAccount, params) {
|
|
23340
|
-
validateAmount(params.amount, "transfer amount");
|
|
23341
|
-
validateAddress(params.recipient, "recipient");
|
|
23342
|
-
const innerData = viem.encodeFunctionData({
|
|
23343
|
-
abi: SymmioDiamondABI,
|
|
23344
|
-
functionName: "internalTransfer",
|
|
23345
|
-
args: [params.recipient, params.amount]
|
|
23346
|
-
});
|
|
23347
|
-
const proxy = wrapInProxyCall(
|
|
23348
|
-
MultiAccountABI,
|
|
23349
|
-
subAccount,
|
|
23350
|
-
[innerData]
|
|
23351
|
-
);
|
|
23352
|
-
return {
|
|
23353
|
-
functionName: "_call",
|
|
23354
|
-
args: proxy.args,
|
|
23355
|
-
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23356
|
-
};
|
|
23357
|
-
}
|
|
23358
|
-
async function allocate(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23359
|
-
const account = walletClient.account?.address;
|
|
23360
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23361
|
-
const prepared = prepareAllocate(multiAccount, account, subAccount, params);
|
|
23362
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23363
|
-
return walletClient.sendTransaction({
|
|
23364
|
-
...prepared.config,
|
|
23365
|
-
gas: calculateGasMargin(gas),
|
|
23366
|
-
chain: walletClient.chain
|
|
23367
|
-
});
|
|
23368
|
-
}
|
|
23369
|
-
async function deallocate(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23370
|
-
const account = walletClient.account?.address;
|
|
23371
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23372
|
-
const prepared = prepareDeallocate(multiAccount, account, subAccount, params);
|
|
23373
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23374
|
-
return walletClient.sendTransaction({
|
|
23375
|
-
...prepared.config,
|
|
23376
|
-
gas: calculateGasMargin(gas),
|
|
23377
|
-
chain: walletClient.chain
|
|
23378
|
-
});
|
|
23379
|
-
}
|
|
23380
|
-
async function internalTransfer(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23381
|
-
const account = walletClient.account?.address;
|
|
23382
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23383
|
-
const prepared = prepareInternalTransfer(multiAccount, account, subAccount, params);
|
|
23384
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23385
|
-
return walletClient.sendTransaction({
|
|
23386
|
-
...prepared.config,
|
|
23387
|
-
gas: calculateGasMargin(gas),
|
|
23388
|
-
chain: walletClient.chain
|
|
23389
|
-
});
|
|
23390
|
-
}
|
|
23391
|
-
|
|
23392
|
-
// src/actions/trade.ts
|
|
23393
|
-
var trade_exports = {};
|
|
23394
|
-
__export(trade_exports, {
|
|
23395
|
-
preparePairTrade: () => preparePairTrade,
|
|
23396
|
-
prepareSendQuote: () => prepareSendQuote,
|
|
23397
|
-
sendQuote: () => sendQuote
|
|
23398
|
-
});
|
|
23399
|
-
function buildUpnlSigTuple(sig) {
|
|
23400
|
-
return {
|
|
23401
|
-
reqId: sig.reqId,
|
|
23402
|
-
timestamp: sig.timestamp,
|
|
23403
|
-
upnl: sig.upnl,
|
|
23404
|
-
price: sig.price,
|
|
23405
|
-
gatewaySignature: sig.gatewaySignature,
|
|
23406
|
-
sigs: {
|
|
23407
|
-
signature: sig.sigs.signature,
|
|
23408
|
-
owner: sig.sigs.owner,
|
|
23409
|
-
nonce: sig.sigs.nonce
|
|
23410
|
-
}
|
|
23411
|
-
};
|
|
23412
|
-
}
|
|
23413
|
-
function prepareSendQuote(multiAccount, account, subAccount, params) {
|
|
23414
|
-
validateQuantity(params.quantity);
|
|
23415
|
-
const innerData = viem.encodeFunctionData({
|
|
23416
|
-
abi: SymmioDiamondABI,
|
|
23417
|
-
functionName: "sendQuoteWithAffiliate",
|
|
23418
|
-
args: [
|
|
23419
|
-
params.partyBsWhiteList,
|
|
23420
|
-
BigInt(params.symbolId),
|
|
23421
|
-
params.positionType,
|
|
23422
|
-
params.orderType,
|
|
23423
|
-
params.price,
|
|
23424
|
-
params.quantity,
|
|
23425
|
-
params.cva,
|
|
23426
|
-
params.lf,
|
|
23427
|
-
params.partyAmm,
|
|
23428
|
-
params.partyBmm,
|
|
23429
|
-
params.maxFundingRate,
|
|
23430
|
-
params.deadline,
|
|
23431
|
-
params.affiliate,
|
|
23432
|
-
buildUpnlSigTuple(params.upnlSig)
|
|
23433
|
-
]
|
|
23434
|
-
});
|
|
23435
|
-
const proxy = wrapInProxyCall(
|
|
23436
|
-
MultiAccountABI,
|
|
23437
|
-
subAccount,
|
|
23438
|
-
[innerData]
|
|
23439
|
-
);
|
|
23440
|
-
return {
|
|
23441
|
-
functionName: "_call",
|
|
23442
|
-
args: proxy.args,
|
|
23443
|
-
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23444
|
-
};
|
|
23445
|
-
}
|
|
23446
|
-
function preparePairTrade(multiAccount, account, subAccount, longParams, shortParams) {
|
|
23447
|
-
const longData = viem.encodeFunctionData({
|
|
23448
|
-
abi: SymmioDiamondABI,
|
|
23449
|
-
functionName: "sendQuoteWithAffiliate",
|
|
23450
|
-
args: [
|
|
23451
|
-
longParams.partyBsWhiteList,
|
|
23452
|
-
BigInt(longParams.symbolId),
|
|
23453
|
-
longParams.positionType,
|
|
23454
|
-
longParams.orderType,
|
|
23455
|
-
longParams.price,
|
|
23456
|
-
longParams.quantity,
|
|
23457
|
-
longParams.cva,
|
|
23458
|
-
longParams.lf,
|
|
23459
|
-
longParams.partyAmm,
|
|
23460
|
-
longParams.partyBmm,
|
|
23461
|
-
longParams.maxFundingRate,
|
|
23462
|
-
longParams.deadline,
|
|
23463
|
-
longParams.affiliate,
|
|
23464
|
-
buildUpnlSigTuple(longParams.upnlSig)
|
|
23465
|
-
]
|
|
23466
|
-
});
|
|
23467
|
-
const shortData = viem.encodeFunctionData({
|
|
23468
|
-
abi: SymmioDiamondABI,
|
|
23469
|
-
functionName: "sendQuoteWithAffiliate",
|
|
23470
|
-
args: [
|
|
23471
|
-
shortParams.partyBsWhiteList,
|
|
23472
|
-
BigInt(shortParams.symbolId),
|
|
23473
|
-
shortParams.positionType,
|
|
23474
|
-
shortParams.orderType,
|
|
23475
|
-
shortParams.price,
|
|
23476
|
-
shortParams.quantity,
|
|
23477
|
-
shortParams.cva,
|
|
23478
|
-
shortParams.lf,
|
|
23479
|
-
shortParams.partyAmm,
|
|
23480
|
-
shortParams.partyBmm,
|
|
23481
|
-
shortParams.maxFundingRate,
|
|
23482
|
-
shortParams.deadline,
|
|
23483
|
-
shortParams.affiliate,
|
|
23484
|
-
buildUpnlSigTuple(shortParams.upnlSig)
|
|
23485
|
-
]
|
|
23486
|
-
});
|
|
23487
|
-
const proxy = wrapInProxyCall(
|
|
23488
|
-
MultiAccountABI,
|
|
23489
|
-
subAccount,
|
|
23490
|
-
[longData, shortData]
|
|
23491
|
-
);
|
|
23492
|
-
return {
|
|
23493
|
-
functionName: "_call",
|
|
23494
|
-
args: proxy.args,
|
|
23495
|
-
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23496
|
-
};
|
|
23497
|
-
}
|
|
23498
|
-
async function sendQuote(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23499
|
-
const account = walletClient.account?.address;
|
|
23500
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23501
|
-
const prepared = prepareSendQuote(multiAccount, account, subAccount, params);
|
|
23502
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23503
|
-
return walletClient.sendTransaction({
|
|
23504
|
-
...prepared.config,
|
|
23505
|
-
gas: calculateGasMargin(gas),
|
|
23506
|
-
chain: walletClient.chain
|
|
23507
|
-
});
|
|
23508
|
-
}
|
|
23509
22867
|
|
|
23510
|
-
// src/
|
|
23511
|
-
var
|
|
23512
|
-
|
|
23513
|
-
closePosition: () => closePosition,
|
|
23514
|
-
prepareClosePosition: () => prepareClosePosition,
|
|
23515
|
-
preparePairClose: () => preparePairClose
|
|
23516
|
-
});
|
|
23517
|
-
function prepareClosePosition(multiAccount, account, subAccount, params) {
|
|
23518
|
-
const innerData = viem.encodeFunctionData({
|
|
23519
|
-
abi: SymmioDiamondABI,
|
|
23520
|
-
functionName: "requestToClosePosition",
|
|
23521
|
-
args: [
|
|
23522
|
-
params.quoteId,
|
|
23523
|
-
params.closePrice,
|
|
23524
|
-
params.quantityToClose,
|
|
23525
|
-
params.orderType,
|
|
23526
|
-
params.deadline
|
|
23527
|
-
]
|
|
23528
|
-
});
|
|
23529
|
-
const proxy = wrapInProxyCall(
|
|
23530
|
-
MultiAccountABI,
|
|
23531
|
-
subAccount,
|
|
23532
|
-
[innerData]
|
|
23533
|
-
);
|
|
23534
|
-
return {
|
|
23535
|
-
functionName: "_call",
|
|
23536
|
-
args: proxy.args,
|
|
23537
|
-
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23538
|
-
};
|
|
23539
|
-
}
|
|
23540
|
-
function preparePairClose(multiAccount, account, subAccount, longClose, shortClose) {
|
|
23541
|
-
const longData = viem.encodeFunctionData({
|
|
23542
|
-
abi: SymmioDiamondABI,
|
|
23543
|
-
functionName: "requestToClosePosition",
|
|
23544
|
-
args: [
|
|
23545
|
-
longClose.quoteId,
|
|
23546
|
-
longClose.closePrice,
|
|
23547
|
-
longClose.quantityToClose,
|
|
23548
|
-
longClose.orderType,
|
|
23549
|
-
longClose.deadline
|
|
23550
|
-
]
|
|
23551
|
-
});
|
|
23552
|
-
const shortData = viem.encodeFunctionData({
|
|
23553
|
-
abi: SymmioDiamondABI,
|
|
23554
|
-
functionName: "requestToClosePosition",
|
|
23555
|
-
args: [
|
|
23556
|
-
shortClose.quoteId,
|
|
23557
|
-
shortClose.closePrice,
|
|
23558
|
-
shortClose.quantityToClose,
|
|
23559
|
-
shortClose.orderType,
|
|
23560
|
-
shortClose.deadline
|
|
23561
|
-
]
|
|
23562
|
-
});
|
|
23563
|
-
const proxy = wrapInProxyCall(
|
|
23564
|
-
MultiAccountABI,
|
|
23565
|
-
subAccount,
|
|
23566
|
-
[longData, shortData]
|
|
23567
|
-
);
|
|
23568
|
-
return {
|
|
23569
|
-
functionName: "_call",
|
|
23570
|
-
args: proxy.args,
|
|
23571
|
-
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23572
|
-
};
|
|
23573
|
-
}
|
|
23574
|
-
async function closePosition(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23575
|
-
const account = walletClient.account?.address;
|
|
23576
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23577
|
-
const prepared = prepareClosePosition(multiAccount, account, subAccount, params);
|
|
23578
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23579
|
-
return walletClient.sendTransaction({
|
|
23580
|
-
...prepared.config,
|
|
23581
|
-
gas: calculateGasMargin(gas),
|
|
23582
|
-
chain: walletClient.chain
|
|
23583
|
-
});
|
|
23584
|
-
}
|
|
23585
|
-
|
|
23586
|
-
// src/actions/cancel.ts
|
|
23587
|
-
var cancel_exports = {};
|
|
23588
|
-
__export(cancel_exports, {
|
|
23589
|
-
cancelCloseRequest: () => cancelCloseRequest,
|
|
23590
|
-
cancelQuote: () => cancelQuote,
|
|
23591
|
-
forceCancelCloseRequest: () => forceCancelCloseRequest,
|
|
23592
|
-
forceCancelQuote: () => forceCancelQuote,
|
|
23593
|
-
prepareCancelCloseRequest: () => prepareCancelCloseRequest,
|
|
23594
|
-
prepareCancelQuote: () => prepareCancelQuote,
|
|
23595
|
-
prepareForceCancelCloseRequest: () => prepareForceCancelCloseRequest,
|
|
23596
|
-
prepareForceCancelQuote: () => prepareForceCancelQuote
|
|
23597
|
-
});
|
|
23598
|
-
function prepareCancelAction(accountDiamond, account, subAccount, functionName, quoteId) {
|
|
23599
|
-
const innerData = viem.encodeFunctionData({
|
|
23600
|
-
abi: SymmioDiamondABI,
|
|
23601
|
-
functionName,
|
|
23602
|
-
args: [quoteId]
|
|
23603
|
-
});
|
|
23604
|
-
const proxy = wrapInProxyCall(
|
|
23605
|
-
MultiAccountABI,
|
|
23606
|
-
subAccount,
|
|
23607
|
-
[innerData]
|
|
23608
|
-
);
|
|
23609
|
-
return {
|
|
23610
|
-
functionName: "_call",
|
|
23611
|
-
args: proxy.args,
|
|
23612
|
-
config: { account, to: accountDiamond, data: proxy.data, value: 0n }
|
|
23613
|
-
};
|
|
23614
|
-
}
|
|
23615
|
-
async function executeCancelAction(walletClient, publicClient, accountDiamond, subAccount, functionName, quoteId) {
|
|
23616
|
-
const account = walletClient.account?.address;
|
|
23617
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23618
|
-
const prepared = prepareCancelAction(
|
|
23619
|
-
accountDiamond,
|
|
23620
|
-
account,
|
|
23621
|
-
subAccount,
|
|
23622
|
-
functionName,
|
|
23623
|
-
quoteId
|
|
23624
|
-
);
|
|
23625
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23626
|
-
return walletClient.sendTransaction({
|
|
23627
|
-
...prepared.config,
|
|
23628
|
-
gas: calculateGasMargin(gas),
|
|
23629
|
-
chain: walletClient.chain
|
|
23630
|
-
});
|
|
23631
|
-
}
|
|
23632
|
-
function prepareCancelQuote(accountDiamond, account, subAccount, quoteId) {
|
|
23633
|
-
return prepareCancelAction(
|
|
23634
|
-
accountDiamond,
|
|
23635
|
-
account,
|
|
23636
|
-
subAccount,
|
|
23637
|
-
"requestToCancelQuote",
|
|
23638
|
-
quoteId
|
|
23639
|
-
);
|
|
23640
|
-
}
|
|
23641
|
-
function prepareCancelCloseRequest(accountDiamond, account, subAccount, quoteId) {
|
|
23642
|
-
return prepareCancelAction(
|
|
23643
|
-
accountDiamond,
|
|
23644
|
-
account,
|
|
23645
|
-
subAccount,
|
|
23646
|
-
"requestToCancelCloseRequest",
|
|
23647
|
-
quoteId
|
|
23648
|
-
);
|
|
23649
|
-
}
|
|
23650
|
-
function prepareForceCancelQuote(accountDiamond, account, subAccount, quoteId) {
|
|
23651
|
-
return prepareCancelAction(
|
|
23652
|
-
accountDiamond,
|
|
23653
|
-
account,
|
|
23654
|
-
subAccount,
|
|
23655
|
-
"forceCancelQuote",
|
|
23656
|
-
quoteId
|
|
23657
|
-
);
|
|
23658
|
-
}
|
|
23659
|
-
function prepareForceCancelCloseRequest(accountDiamond, account, subAccount, quoteId) {
|
|
23660
|
-
return prepareCancelAction(
|
|
23661
|
-
accountDiamond,
|
|
23662
|
-
account,
|
|
23663
|
-
subAccount,
|
|
23664
|
-
"forceCancelCloseRequest",
|
|
23665
|
-
quoteId
|
|
23666
|
-
);
|
|
23667
|
-
}
|
|
23668
|
-
async function cancelQuote(walletClient, publicClient, accountDiamond, subAccount, quoteId) {
|
|
23669
|
-
return executeCancelAction(
|
|
23670
|
-
walletClient,
|
|
23671
|
-
publicClient,
|
|
23672
|
-
accountDiamond,
|
|
23673
|
-
subAccount,
|
|
23674
|
-
"requestToCancelQuote",
|
|
23675
|
-
quoteId
|
|
23676
|
-
);
|
|
23677
|
-
}
|
|
23678
|
-
async function cancelCloseRequest(walletClient, publicClient, accountDiamond, subAccount, quoteId) {
|
|
23679
|
-
return executeCancelAction(
|
|
23680
|
-
walletClient,
|
|
23681
|
-
publicClient,
|
|
23682
|
-
accountDiamond,
|
|
23683
|
-
subAccount,
|
|
23684
|
-
"requestToCancelCloseRequest",
|
|
23685
|
-
quoteId
|
|
23686
|
-
);
|
|
23687
|
-
}
|
|
23688
|
-
async function forceCancelQuote(walletClient, publicClient, accountDiamond, subAccount, quoteId) {
|
|
23689
|
-
return executeCancelAction(
|
|
23690
|
-
walletClient,
|
|
23691
|
-
publicClient,
|
|
23692
|
-
accountDiamond,
|
|
23693
|
-
subAccount,
|
|
23694
|
-
"forceCancelQuote",
|
|
23695
|
-
quoteId
|
|
23696
|
-
);
|
|
23697
|
-
}
|
|
23698
|
-
async function forceCancelCloseRequest(walletClient, publicClient, accountDiamond, subAccount, quoteId) {
|
|
23699
|
-
return executeCancelAction(
|
|
23700
|
-
walletClient,
|
|
23701
|
-
publicClient,
|
|
23702
|
-
accountDiamond,
|
|
23703
|
-
subAccount,
|
|
23704
|
-
"forceCancelCloseRequest",
|
|
23705
|
-
quoteId
|
|
23706
|
-
);
|
|
23707
|
-
}
|
|
23708
|
-
|
|
23709
|
-
// src/actions/approval.ts
|
|
23710
|
-
var approval_exports = {};
|
|
23711
|
-
__export(approval_exports, {
|
|
23712
|
-
ApprovalState: () => ApprovalState,
|
|
23713
|
-
approve: () => approve,
|
|
23714
|
-
getAllowance: () => getAllowance,
|
|
23715
|
-
getApprovalState: () => getApprovalState,
|
|
23716
|
-
getBalance: () => getBalance,
|
|
23717
|
-
getDecimals: () => getDecimals,
|
|
23718
|
-
prepareApprove: () => prepareApprove
|
|
23719
|
-
});
|
|
23720
|
-
|
|
23721
|
-
// src/abis/ERC20.ts
|
|
23722
|
-
var ERC20ABI = [
|
|
22868
|
+
// src/abis/ClearingHouse.ts
|
|
22869
|
+
var ClearingHouseABI = [
|
|
22870
|
+
// ─── Liquidation Lifecycle ────────────────────────────────────
|
|
23723
22871
|
{
|
|
23724
|
-
name: "
|
|
22872
|
+
name: "initiateLiquidation",
|
|
23725
22873
|
type: "function",
|
|
23726
22874
|
stateMutability: "nonpayable",
|
|
23727
22875
|
inputs: [
|
|
23728
|
-
{ name: "
|
|
23729
|
-
{ name: "
|
|
22876
|
+
{ name: "partyA", type: "address" },
|
|
22877
|
+
{ name: "partyB", type: "address" }
|
|
23730
22878
|
],
|
|
23731
|
-
outputs: [{ name: "
|
|
22879
|
+
outputs: [{ name: "liquidationId", type: "uint256" }]
|
|
23732
22880
|
},
|
|
23733
22881
|
{
|
|
23734
|
-
name: "
|
|
22882
|
+
name: "deallocateLiquidation",
|
|
23735
22883
|
type: "function",
|
|
23736
|
-
stateMutability: "
|
|
23737
|
-
inputs: [
|
|
23738
|
-
|
|
23739
|
-
{ name: "spender", type: "address" }
|
|
23740
|
-
],
|
|
23741
|
-
outputs: [{ name: "remaining", type: "uint256" }]
|
|
22884
|
+
stateMutability: "nonpayable",
|
|
22885
|
+
inputs: [{ name: "liquidationId", type: "uint256" }],
|
|
22886
|
+
outputs: []
|
|
23742
22887
|
},
|
|
23743
22888
|
{
|
|
23744
|
-
name: "
|
|
22889
|
+
name: "closePositionsInLiquidation",
|
|
23745
22890
|
type: "function",
|
|
23746
|
-
stateMutability: "
|
|
23747
|
-
inputs: [
|
|
23748
|
-
|
|
22891
|
+
stateMutability: "nonpayable",
|
|
22892
|
+
inputs: [
|
|
22893
|
+
{ name: "liquidationId", type: "uint256" },
|
|
22894
|
+
{ name: "quoteIds", type: "uint256[]" },
|
|
22895
|
+
{ name: "closePrices", type: "uint256[]" }
|
|
22896
|
+
],
|
|
22897
|
+
outputs: []
|
|
23749
22898
|
},
|
|
23750
22899
|
{
|
|
23751
|
-
name: "
|
|
22900
|
+
name: "distributeLiquidation",
|
|
23752
22901
|
type: "function",
|
|
23753
|
-
stateMutability: "
|
|
23754
|
-
inputs: [],
|
|
23755
|
-
outputs: [
|
|
22902
|
+
stateMutability: "nonpayable",
|
|
22903
|
+
inputs: [{ name: "liquidationId", type: "uint256" }],
|
|
22904
|
+
outputs: []
|
|
23756
22905
|
},
|
|
23757
22906
|
{
|
|
23758
|
-
name: "
|
|
22907
|
+
name: "settleLiquidation",
|
|
23759
22908
|
type: "function",
|
|
23760
|
-
stateMutability: "
|
|
23761
|
-
inputs: [],
|
|
23762
|
-
outputs: [
|
|
22909
|
+
stateMutability: "nonpayable",
|
|
22910
|
+
inputs: [{ name: "liquidationId", type: "uint256" }],
|
|
22911
|
+
outputs: []
|
|
23763
22912
|
},
|
|
22913
|
+
// ─── Soft Liquidation (v0.8.5) ────────────────────────────────
|
|
23764
22914
|
{
|
|
23765
|
-
name: "
|
|
22915
|
+
name: "applySoftLiquidationPenalty",
|
|
23766
22916
|
type: "function",
|
|
23767
|
-
stateMutability: "
|
|
23768
|
-
inputs: [
|
|
23769
|
-
|
|
22917
|
+
stateMutability: "nonpayable",
|
|
22918
|
+
inputs: [
|
|
22919
|
+
{ name: "partyB", type: "address" },
|
|
22920
|
+
{ name: "level", type: "uint8" }
|
|
22921
|
+
],
|
|
22922
|
+
outputs: []
|
|
23770
22923
|
},
|
|
23771
22924
|
{
|
|
23772
|
-
name: "
|
|
22925
|
+
name: "setSoftLiquidationThreshold",
|
|
23773
22926
|
type: "function",
|
|
23774
22927
|
stateMutability: "nonpayable",
|
|
23775
22928
|
inputs: [
|
|
23776
|
-
{ name: "
|
|
23777
|
-
{ name: "
|
|
22929
|
+
{ name: "level", type: "uint8" },
|
|
22930
|
+
{ name: "ratio", type: "uint256" },
|
|
22931
|
+
{ name: "penalty", type: "uint256" }
|
|
23778
22932
|
],
|
|
23779
|
-
outputs: [
|
|
22933
|
+
outputs: []
|
|
23780
22934
|
},
|
|
22935
|
+
// ─── Auto-Takeover ────────────────────────────────────────────
|
|
23781
22936
|
{
|
|
23782
|
-
name: "
|
|
22937
|
+
name: "autoTakeover",
|
|
23783
22938
|
type: "function",
|
|
23784
22939
|
stateMutability: "nonpayable",
|
|
23785
22940
|
inputs: [
|
|
23786
|
-
{ name: "
|
|
23787
|
-
{ name: "
|
|
22941
|
+
{ name: "liquidationId", type: "uint256" },
|
|
22942
|
+
{ name: "newPartyB", type: "address" }
|
|
23788
22943
|
],
|
|
23789
22944
|
outputs: []
|
|
23790
|
-
}
|
|
23791
|
-
|
|
23792
|
-
|
|
23793
|
-
// src/actions/approval.ts
|
|
23794
|
-
var ApprovalState = /* @__PURE__ */ ((ApprovalState2) => {
|
|
23795
|
-
ApprovalState2["UNKNOWN"] = "UNKNOWN";
|
|
23796
|
-
ApprovalState2["NOT_APPROVED"] = "NOT_APPROVED";
|
|
23797
|
-
ApprovalState2["PENDING"] = "PENDING";
|
|
23798
|
-
ApprovalState2["APPROVED"] = "APPROVED";
|
|
23799
|
-
return ApprovalState2;
|
|
23800
|
-
})(ApprovalState || {});
|
|
23801
|
-
function prepareApprove(tokenAddress, account, spender, amount) {
|
|
23802
|
-
validateAddress(spender, "spender");
|
|
23803
|
-
const data = viem.encodeFunctionData({
|
|
23804
|
-
abi: ERC20ABI,
|
|
23805
|
-
functionName: "approve",
|
|
23806
|
-
args: [spender, amount]
|
|
23807
|
-
});
|
|
23808
|
-
return {
|
|
23809
|
-
functionName: "approve",
|
|
23810
|
-
args: [spender, amount],
|
|
23811
|
-
config: { account, to: tokenAddress, data, value: 0n }
|
|
23812
|
-
};
|
|
23813
|
-
}
|
|
23814
|
-
async function approve(walletClient, publicClient, tokenAddress, spender, amount) {
|
|
23815
|
-
const account = walletClient.account?.address;
|
|
23816
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23817
|
-
const prepared = prepareApprove(tokenAddress, account, spender, amount);
|
|
23818
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23819
|
-
return walletClient.sendTransaction({
|
|
23820
|
-
...prepared.config,
|
|
23821
|
-
gas: calculateGasMargin(gas),
|
|
23822
|
-
chain: walletClient.chain
|
|
23823
|
-
});
|
|
23824
|
-
}
|
|
23825
|
-
async function getAllowance(publicClient, tokenAddress, owner, spender) {
|
|
23826
|
-
return await publicClient.readContract({
|
|
23827
|
-
address: tokenAddress,
|
|
23828
|
-
abi: ERC20ABI,
|
|
23829
|
-
functionName: "allowance",
|
|
23830
|
-
args: [owner, spender]
|
|
23831
|
-
});
|
|
23832
|
-
}
|
|
23833
|
-
async function getBalance(publicClient, tokenAddress, account) {
|
|
23834
|
-
return await publicClient.readContract({
|
|
23835
|
-
address: tokenAddress,
|
|
23836
|
-
abi: ERC20ABI,
|
|
23837
|
-
functionName: "balanceOf",
|
|
23838
|
-
args: [account]
|
|
23839
|
-
});
|
|
23840
|
-
}
|
|
23841
|
-
async function getDecimals(publicClient, tokenAddress) {
|
|
23842
|
-
return await publicClient.readContract({
|
|
23843
|
-
address: tokenAddress,
|
|
23844
|
-
abi: ERC20ABI,
|
|
23845
|
-
functionName: "decimals"
|
|
23846
|
-
});
|
|
23847
|
-
}
|
|
23848
|
-
async function getApprovalState(publicClient, tokenAddress, owner, spender, requiredAmount) {
|
|
23849
|
-
try {
|
|
23850
|
-
const allowance = await getAllowance(publicClient, tokenAddress, owner, spender);
|
|
23851
|
-
if (allowance >= requiredAmount) {
|
|
23852
|
-
return "APPROVED" /* APPROVED */;
|
|
23853
|
-
}
|
|
23854
|
-
return "NOT_APPROVED" /* NOT_APPROVED */;
|
|
23855
|
-
} catch {
|
|
23856
|
-
return "UNKNOWN" /* UNKNOWN */;
|
|
23857
|
-
}
|
|
23858
|
-
}
|
|
23859
|
-
|
|
23860
|
-
// src/actions/delegation.ts
|
|
23861
|
-
var delegation_exports = {};
|
|
23862
|
-
__export(delegation_exports, {
|
|
23863
|
-
delegateAccess: () => delegateAccess,
|
|
23864
|
-
hasDelegatedAccess: () => hasDelegatedAccess,
|
|
23865
|
-
prepareDelegateAccess: () => prepareDelegateAccess,
|
|
23866
|
-
prepareProposeRevoke: () => prepareProposeRevoke,
|
|
23867
|
-
prepareRevokeAccess: () => prepareRevokeAccess,
|
|
23868
|
-
proposeRevoke: () => proposeRevoke,
|
|
23869
|
-
revokeAccess: () => revokeAccess
|
|
23870
|
-
});
|
|
23871
|
-
function prepareDelegateAccess(multiAccount, account, params) {
|
|
23872
|
-
validateAddress(params.account, "subAccount");
|
|
23873
|
-
validateAddress(params.target, "target");
|
|
23874
|
-
const data = viem.encodeFunctionData({
|
|
23875
|
-
abi: MultiAccountABI,
|
|
23876
|
-
functionName: "delegateAccesses",
|
|
23877
|
-
args: [params.account, params.target, params.selectors, params.activate]
|
|
23878
|
-
});
|
|
23879
|
-
return {
|
|
23880
|
-
functionName: "delegateAccesses",
|
|
23881
|
-
args: [params.account, params.target, params.selectors, params.activate],
|
|
23882
|
-
config: { account, to: multiAccount, data, value: 0n }
|
|
23883
|
-
};
|
|
23884
|
-
}
|
|
23885
|
-
function prepareProposeRevoke(multiAccount, account, params) {
|
|
23886
|
-
const data = viem.encodeFunctionData({
|
|
23887
|
-
abi: MultiAccountABI,
|
|
23888
|
-
functionName: "proposeToRevokeAccesses",
|
|
23889
|
-
args: [params.account, params.target, params.selectors]
|
|
23890
|
-
});
|
|
23891
|
-
return {
|
|
23892
|
-
functionName: "proposeToRevokeAccesses",
|
|
23893
|
-
args: [params.account, params.target, params.selectors],
|
|
23894
|
-
config: { account, to: multiAccount, data, value: 0n }
|
|
23895
|
-
};
|
|
23896
|
-
}
|
|
23897
|
-
function prepareRevokeAccess(multiAccount, account, params) {
|
|
23898
|
-
const data = viem.encodeFunctionData({
|
|
23899
|
-
abi: MultiAccountABI,
|
|
23900
|
-
functionName: "revokeAccesses",
|
|
23901
|
-
args: [params.account, params.target, params.selectors]
|
|
23902
|
-
});
|
|
23903
|
-
return {
|
|
23904
|
-
functionName: "revokeAccesses",
|
|
23905
|
-
args: [params.account, params.target, params.selectors],
|
|
23906
|
-
config: { account, to: multiAccount, data, value: 0n }
|
|
23907
|
-
};
|
|
23908
|
-
}
|
|
23909
|
-
async function delegateAccess(walletClient, publicClient, multiAccount, params) {
|
|
23910
|
-
const account = walletClient.account?.address;
|
|
23911
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23912
|
-
const prepared = prepareDelegateAccess(multiAccount, account, params);
|
|
23913
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23914
|
-
return walletClient.sendTransaction({
|
|
23915
|
-
...prepared.config,
|
|
23916
|
-
gas: calculateGasMargin(gas),
|
|
23917
|
-
chain: walletClient.chain
|
|
23918
|
-
});
|
|
23919
|
-
}
|
|
23920
|
-
async function proposeRevoke(walletClient, publicClient, multiAccount, params) {
|
|
23921
|
-
const account = walletClient.account?.address;
|
|
23922
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23923
|
-
const prepared = prepareProposeRevoke(multiAccount, account, params);
|
|
23924
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23925
|
-
return walletClient.sendTransaction({
|
|
23926
|
-
...prepared.config,
|
|
23927
|
-
gas: calculateGasMargin(gas),
|
|
23928
|
-
chain: walletClient.chain
|
|
23929
|
-
});
|
|
23930
|
-
}
|
|
23931
|
-
async function revokeAccess(walletClient, publicClient, multiAccount, params) {
|
|
23932
|
-
const account = walletClient.account?.address;
|
|
23933
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
23934
|
-
const prepared = prepareRevokeAccess(multiAccount, account, params);
|
|
23935
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
23936
|
-
return walletClient.sendTransaction({
|
|
23937
|
-
...prepared.config,
|
|
23938
|
-
gas: calculateGasMargin(gas),
|
|
23939
|
-
chain: walletClient.chain
|
|
23940
|
-
});
|
|
23941
|
-
}
|
|
23942
|
-
async function hasDelegatedAccess(publicClient, multiAccount, params) {
|
|
23943
|
-
validateAddress(params.account, "subAccount");
|
|
23944
|
-
validateAddress(params.target, "target");
|
|
23945
|
-
const result = await publicClient.readContract({
|
|
23946
|
-
address: multiAccount,
|
|
23947
|
-
abi: MultiAccountABI,
|
|
23948
|
-
functionName: "delegatedAccesses",
|
|
23949
|
-
args: [params.account, params.target, params.selector]
|
|
23950
|
-
});
|
|
23951
|
-
return Boolean(result);
|
|
23952
|
-
}
|
|
23953
|
-
|
|
23954
|
-
// src/actions/signature.ts
|
|
23955
|
-
var signature_exports = {};
|
|
23956
|
-
__export(signature_exports, {
|
|
23957
|
-
getCurrentMessage: () => getCurrentMessage,
|
|
23958
|
-
hasSignedCurrentVersion: () => hasSignedCurrentVersion,
|
|
23959
|
-
prepareStoreSignature: () => prepareStoreSignature,
|
|
23960
|
-
signTermsMessage: () => signTermsMessage,
|
|
23961
|
-
storeSignature: () => storeSignature
|
|
23962
|
-
});
|
|
23963
|
-
|
|
23964
|
-
// src/abis/SignatureStore.ts
|
|
23965
|
-
var SignatureStoreABI = [
|
|
22945
|
+
},
|
|
22946
|
+
// ─── ADL Assurance ────────────────────────────────────────────
|
|
23966
22947
|
{
|
|
23967
|
-
name: "
|
|
22948
|
+
name: "depositADLAssurance",
|
|
23968
22949
|
type: "function",
|
|
23969
22950
|
stateMutability: "nonpayable",
|
|
23970
|
-
inputs: [
|
|
22951
|
+
inputs: [
|
|
22952
|
+
{ name: "partyB", type: "address" },
|
|
22953
|
+
{ name: "amount", type: "uint256" }
|
|
22954
|
+
],
|
|
23971
22955
|
outputs: []
|
|
23972
22956
|
},
|
|
23973
22957
|
{
|
|
23974
|
-
name: "
|
|
22958
|
+
name: "slashADLAssurance",
|
|
23975
22959
|
type: "function",
|
|
23976
|
-
stateMutability: "
|
|
23977
|
-
inputs: [{ name: "
|
|
23978
|
-
outputs: [
|
|
22960
|
+
stateMutability: "nonpayable",
|
|
22961
|
+
inputs: [{ name: "partyB", type: "address" }],
|
|
22962
|
+
outputs: []
|
|
23979
22963
|
},
|
|
22964
|
+
// ─── Insurance Vault ──────────────────────────────────────────
|
|
23980
22965
|
{
|
|
23981
|
-
name: "
|
|
22966
|
+
name: "setMaxLiquidatorProfit",
|
|
23982
22967
|
type: "function",
|
|
23983
|
-
stateMutability: "
|
|
23984
|
-
inputs: [
|
|
23985
|
-
|
|
23986
|
-
{ name: "user", type: "address" }
|
|
23987
|
-
],
|
|
23988
|
-
outputs: [{ name: "signature", type: "bytes" }]
|
|
22968
|
+
stateMutability: "nonpayable",
|
|
22969
|
+
inputs: [{ name: "maxProfit", type: "uint256" }],
|
|
22970
|
+
outputs: []
|
|
23989
22971
|
},
|
|
23990
22972
|
{
|
|
23991
|
-
name: "
|
|
22973
|
+
name: "reimbursePartyB",
|
|
23992
22974
|
type: "function",
|
|
23993
|
-
stateMutability: "
|
|
23994
|
-
inputs: [
|
|
23995
|
-
|
|
22975
|
+
stateMutability: "nonpayable",
|
|
22976
|
+
inputs: [
|
|
22977
|
+
{ name: "partyB", type: "address" },
|
|
22978
|
+
{ name: "amount", type: "uint256" }
|
|
22979
|
+
],
|
|
22980
|
+
outputs: []
|
|
23996
22981
|
},
|
|
22982
|
+
// ─── View Functions ───────────────────────────────────────────
|
|
23997
22983
|
{
|
|
23998
|
-
name: "
|
|
22984
|
+
name: "getLiquidation",
|
|
23999
22985
|
type: "function",
|
|
24000
22986
|
stateMutability: "view",
|
|
24001
|
-
inputs: [],
|
|
24002
|
-
outputs: [
|
|
22987
|
+
inputs: [{ name: "liquidationId", type: "uint256" }],
|
|
22988
|
+
outputs: [
|
|
22989
|
+
{
|
|
22990
|
+
name: "liquidation",
|
|
22991
|
+
type: "tuple",
|
|
22992
|
+
components: [
|
|
22993
|
+
{ name: "id", type: "uint256" },
|
|
22994
|
+
{ name: "partyA", type: "address" },
|
|
22995
|
+
{ name: "partyB", type: "address" },
|
|
22996
|
+
{ name: "status", type: "uint8" },
|
|
22997
|
+
{ name: "deallocatedAmount", type: "uint256" },
|
|
22998
|
+
{ name: "settledAmount", type: "uint256" },
|
|
22999
|
+
{ name: "createdAt", type: "uint256" }
|
|
23000
|
+
]
|
|
23001
|
+
}
|
|
23002
|
+
]
|
|
23003
|
+
},
|
|
23004
|
+
// ─── Events ───────────────────────────────────────────────────
|
|
23005
|
+
{
|
|
23006
|
+
name: "LiquidationInitiated",
|
|
23007
|
+
type: "event",
|
|
23008
|
+
inputs: [
|
|
23009
|
+
{ name: "liquidationId", type: "uint256", indexed: true },
|
|
23010
|
+
{ name: "partyA", type: "address", indexed: true },
|
|
23011
|
+
{ name: "partyB", type: "address", indexed: true }
|
|
23012
|
+
]
|
|
23013
|
+
},
|
|
23014
|
+
{
|
|
23015
|
+
name: "LiquidationSettled",
|
|
23016
|
+
type: "event",
|
|
23017
|
+
inputs: [
|
|
23018
|
+
{ name: "liquidationId", type: "uint256", indexed: true }
|
|
23019
|
+
]
|
|
23020
|
+
},
|
|
23021
|
+
{
|
|
23022
|
+
name: "SoftLiquidationPenalty",
|
|
23023
|
+
type: "event",
|
|
23024
|
+
inputs: [
|
|
23025
|
+
{ name: "partyB", type: "address", indexed: true },
|
|
23026
|
+
{ name: "level", type: "uint8", indexed: false },
|
|
23027
|
+
{ name: "penalty", type: "uint256", indexed: false }
|
|
23028
|
+
]
|
|
24003
23029
|
}
|
|
24004
23030
|
];
|
|
24005
23031
|
|
|
24006
|
-
// src/
|
|
24007
|
-
|
|
24008
|
-
|
|
24009
|
-
|
|
24010
|
-
|
|
24011
|
-
|
|
24012
|
-
|
|
24013
|
-
|
|
24014
|
-
|
|
24015
|
-
|
|
24016
|
-
|
|
24017
|
-
}
|
|
24018
|
-
|
|
24019
|
-
|
|
24020
|
-
|
|
24021
|
-
|
|
24022
|
-
|
|
24023
|
-
|
|
24024
|
-
|
|
24025
|
-
|
|
24026
|
-
|
|
24027
|
-
|
|
24028
|
-
|
|
24029
|
-
|
|
24030
|
-
|
|
24031
|
-
|
|
24032
|
-
|
|
24033
|
-
|
|
24034
|
-
|
|
24035
|
-
|
|
24036
|
-
|
|
24037
|
-
|
|
24038
|
-
|
|
24039
|
-
|
|
24040
|
-
|
|
24041
|
-
}
|
|
24042
|
-
|
|
24043
|
-
|
|
24044
|
-
|
|
24045
|
-
|
|
24046
|
-
|
|
24047
|
-
|
|
24048
|
-
|
|
24049
|
-
|
|
24050
|
-
}
|
|
24051
|
-
async function getCurrentMessage(publicClient, signatureStore) {
|
|
24052
|
-
return await publicClient.readContract({
|
|
24053
|
-
address: signatureStore,
|
|
24054
|
-
abi: SignatureStoreABI,
|
|
24055
|
-
functionName: "getCurrentVersionMessage"
|
|
24056
|
-
});
|
|
24057
|
-
}
|
|
24058
|
-
|
|
24059
|
-
// src/actions/admin.ts
|
|
24060
|
-
var admin_exports = {};
|
|
24061
|
-
__export(admin_exports, {
|
|
24062
|
-
grantRole: () => grantRole,
|
|
24063
|
-
prepareGrantRole: () => prepareGrantRole,
|
|
24064
|
-
prepareRevokeRole: () => prepareRevokeRole,
|
|
24065
|
-
revokeRole: () => revokeRole
|
|
24066
|
-
});
|
|
24067
|
-
function prepareGrantRole(symmioDiamond, account, role, grantee) {
|
|
24068
|
-
validateAddress(grantee, "grantee");
|
|
24069
|
-
const data = viem.encodeFunctionData({
|
|
24070
|
-
abi: SymmioDiamondABI,
|
|
24071
|
-
functionName: "grantRole",
|
|
24072
|
-
args: [grantee, role]
|
|
24073
|
-
});
|
|
24074
|
-
return {
|
|
24075
|
-
functionName: "grantRole",
|
|
24076
|
-
args: [grantee, role],
|
|
24077
|
-
config: { account, to: symmioDiamond, data, value: 0n }
|
|
24078
|
-
};
|
|
24079
|
-
}
|
|
24080
|
-
function prepareRevokeRole(symmioDiamond, account, role, revokee) {
|
|
24081
|
-
validateAddress(revokee, "revokee");
|
|
24082
|
-
const data = viem.encodeFunctionData({
|
|
24083
|
-
abi: SymmioDiamondABI,
|
|
24084
|
-
functionName: "revokeRole",
|
|
24085
|
-
args: [revokee, role]
|
|
24086
|
-
});
|
|
24087
|
-
return {
|
|
24088
|
-
functionName: "revokeRole",
|
|
24089
|
-
args: [revokee, role],
|
|
24090
|
-
config: { account, to: symmioDiamond, data, value: 0n }
|
|
24091
|
-
};
|
|
24092
|
-
}
|
|
24093
|
-
async function grantRole(walletClient, publicClient, symmioDiamond, role, grantee) {
|
|
24094
|
-
const account = walletClient.account?.address;
|
|
24095
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
24096
|
-
const prepared = prepareGrantRole(symmioDiamond, account, role, grantee);
|
|
24097
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
24098
|
-
return walletClient.sendTransaction({
|
|
24099
|
-
...prepared.config,
|
|
24100
|
-
gas: calculateGasMargin(gas),
|
|
24101
|
-
chain: walletClient.chain
|
|
24102
|
-
});
|
|
24103
|
-
}
|
|
24104
|
-
async function revokeRole(walletClient, publicClient, symmioDiamond, role, revokee) {
|
|
24105
|
-
const account = walletClient.account?.address;
|
|
24106
|
-
if (!account) throw new Error("Wallet client has no account");
|
|
24107
|
-
const prepared = prepareRevokeRole(symmioDiamond, account, role, revokee);
|
|
24108
|
-
const gas = await publicClient.estimateGas(prepared.config);
|
|
24109
|
-
return walletClient.sendTransaction({
|
|
24110
|
-
...prepared.config,
|
|
24111
|
-
gas: calculateGasMargin(gas),
|
|
24112
|
-
chain: walletClient.chain
|
|
24113
|
-
});
|
|
24114
|
-
}
|
|
23032
|
+
// src/abis/MuonVerifier.ts
|
|
23033
|
+
var MuonVerifierABI = [
|
|
23034
|
+
{
|
|
23035
|
+
name: "addSignatureKey",
|
|
23036
|
+
type: "function",
|
|
23037
|
+
stateMutability: "nonpayable",
|
|
23038
|
+
inputs: [
|
|
23039
|
+
{ name: "publicKey", type: "address" },
|
|
23040
|
+
{ name: "nodeId", type: "bytes32" }
|
|
23041
|
+
],
|
|
23042
|
+
outputs: []
|
|
23043
|
+
},
|
|
23044
|
+
{
|
|
23045
|
+
name: "removeSignatureKey",
|
|
23046
|
+
type: "function",
|
|
23047
|
+
stateMutability: "nonpayable",
|
|
23048
|
+
inputs: [{ name: "publicKey", type: "address" }],
|
|
23049
|
+
outputs: []
|
|
23050
|
+
},
|
|
23051
|
+
{
|
|
23052
|
+
name: "rotateSignatureKey",
|
|
23053
|
+
type: "function",
|
|
23054
|
+
stateMutability: "nonpayable",
|
|
23055
|
+
inputs: [
|
|
23056
|
+
{ name: "oldKey", type: "address" },
|
|
23057
|
+
{ name: "newKey", type: "address" }
|
|
23058
|
+
],
|
|
23059
|
+
outputs: []
|
|
23060
|
+
},
|
|
23061
|
+
{
|
|
23062
|
+
name: "isValidKey",
|
|
23063
|
+
type: "function",
|
|
23064
|
+
stateMutability: "view",
|
|
23065
|
+
inputs: [{ name: "publicKey", type: "address" }],
|
|
23066
|
+
outputs: [{ name: "valid", type: "bool" }]
|
|
23067
|
+
},
|
|
23068
|
+
{
|
|
23069
|
+
name: "getActiveKeys",
|
|
23070
|
+
type: "function",
|
|
23071
|
+
stateMutability: "view",
|
|
23072
|
+
inputs: [],
|
|
23073
|
+
outputs: [{ name: "keys", type: "address[]" }]
|
|
23074
|
+
}
|
|
23075
|
+
];
|
|
24115
23076
|
|
|
24116
|
-
// src/
|
|
24117
|
-
var
|
|
24118
|
-
|
|
24119
|
-
|
|
24120
|
-
|
|
24121
|
-
|
|
24122
|
-
|
|
24123
|
-
|
|
24124
|
-
|
|
24125
|
-
|
|
24126
|
-
|
|
24127
|
-
function
|
|
24128
|
-
|
|
24129
|
-
|
|
24130
|
-
|
|
23077
|
+
// src/abis/SignatureStore.ts
|
|
23078
|
+
var SignatureStoreABI = [
|
|
23079
|
+
{
|
|
23080
|
+
name: "storeSignatureForCurrentVersion",
|
|
23081
|
+
type: "function",
|
|
23082
|
+
stateMutability: "nonpayable",
|
|
23083
|
+
inputs: [{ name: "signature", type: "bytes" }],
|
|
23084
|
+
outputs: []
|
|
23085
|
+
},
|
|
23086
|
+
{
|
|
23087
|
+
name: "hasCurrentVersionSignature",
|
|
23088
|
+
type: "function",
|
|
23089
|
+
stateMutability: "view",
|
|
23090
|
+
inputs: [{ name: "user", type: "address" }],
|
|
23091
|
+
outputs: [{ name: "hasSigned", type: "bool" }]
|
|
23092
|
+
},
|
|
23093
|
+
{
|
|
23094
|
+
name: "getSignature",
|
|
23095
|
+
type: "function",
|
|
23096
|
+
stateMutability: "view",
|
|
23097
|
+
inputs: [
|
|
23098
|
+
{ name: "version", type: "uint256" },
|
|
23099
|
+
{ name: "user", type: "address" }
|
|
23100
|
+
],
|
|
23101
|
+
outputs: [{ name: "signature", type: "bytes" }]
|
|
23102
|
+
},
|
|
23103
|
+
{
|
|
23104
|
+
name: "getCurrentVersionMessage",
|
|
23105
|
+
type: "function",
|
|
23106
|
+
stateMutability: "view",
|
|
23107
|
+
inputs: [],
|
|
23108
|
+
outputs: [{ name: "message", type: "string" }]
|
|
23109
|
+
},
|
|
23110
|
+
{
|
|
23111
|
+
name: "getCurrentVersion",
|
|
23112
|
+
type: "function",
|
|
23113
|
+
stateMutability: "view",
|
|
23114
|
+
inputs: [],
|
|
23115
|
+
outputs: [{ name: "version", type: "uint256" }]
|
|
24131
23116
|
}
|
|
24132
|
-
|
|
24133
|
-
|
|
24134
|
-
|
|
24135
|
-
|
|
24136
|
-
|
|
24137
|
-
|
|
24138
|
-
|
|
24139
|
-
|
|
24140
|
-
|
|
24141
|
-
|
|
24142
|
-
|
|
24143
|
-
|
|
24144
|
-
|
|
24145
|
-
|
|
24146
|
-
|
|
24147
|
-
|
|
24148
|
-
|
|
24149
|
-
|
|
24150
|
-
|
|
24151
|
-
|
|
24152
|
-
|
|
24153
|
-
|
|
24154
|
-
}
|
|
24155
|
-
|
|
24156
|
-
|
|
24157
|
-
|
|
24158
|
-
|
|
24159
|
-
|
|
24160
|
-
|
|
23117
|
+
];
|
|
23118
|
+
|
|
23119
|
+
// src/abis/ERC20.ts
|
|
23120
|
+
var ERC20ABI = [
|
|
23121
|
+
{
|
|
23122
|
+
name: "approve",
|
|
23123
|
+
type: "function",
|
|
23124
|
+
stateMutability: "nonpayable",
|
|
23125
|
+
inputs: [
|
|
23126
|
+
{ name: "spender", type: "address" },
|
|
23127
|
+
{ name: "amount", type: "uint256" }
|
|
23128
|
+
],
|
|
23129
|
+
outputs: [{ name: "success", type: "bool" }]
|
|
23130
|
+
},
|
|
23131
|
+
{
|
|
23132
|
+
name: "allowance",
|
|
23133
|
+
type: "function",
|
|
23134
|
+
stateMutability: "view",
|
|
23135
|
+
inputs: [
|
|
23136
|
+
{ name: "owner", type: "address" },
|
|
23137
|
+
{ name: "spender", type: "address" }
|
|
23138
|
+
],
|
|
23139
|
+
outputs: [{ name: "remaining", type: "uint256" }]
|
|
23140
|
+
},
|
|
23141
|
+
{
|
|
23142
|
+
name: "balanceOf",
|
|
23143
|
+
type: "function",
|
|
23144
|
+
stateMutability: "view",
|
|
23145
|
+
inputs: [{ name: "account", type: "address" }],
|
|
23146
|
+
outputs: [{ name: "balance", type: "uint256" }]
|
|
23147
|
+
},
|
|
23148
|
+
{
|
|
23149
|
+
name: "decimals",
|
|
23150
|
+
type: "function",
|
|
23151
|
+
stateMutability: "view",
|
|
23152
|
+
inputs: [],
|
|
23153
|
+
outputs: [{ name: "decimals", type: "uint8" }]
|
|
23154
|
+
},
|
|
23155
|
+
{
|
|
23156
|
+
name: "symbol",
|
|
23157
|
+
type: "function",
|
|
23158
|
+
stateMutability: "view",
|
|
23159
|
+
inputs: [],
|
|
23160
|
+
outputs: [{ name: "symbol", type: "string" }]
|
|
23161
|
+
},
|
|
23162
|
+
{
|
|
23163
|
+
name: "totalSupply",
|
|
23164
|
+
type: "function",
|
|
23165
|
+
stateMutability: "view",
|
|
23166
|
+
inputs: [],
|
|
23167
|
+
outputs: [{ name: "supply", type: "uint256" }]
|
|
23168
|
+
},
|
|
23169
|
+
{
|
|
23170
|
+
name: "transfer",
|
|
23171
|
+
type: "function",
|
|
23172
|
+
stateMutability: "nonpayable",
|
|
23173
|
+
inputs: [
|
|
23174
|
+
{ name: "to", type: "address" },
|
|
23175
|
+
{ name: "amount", type: "uint256" }
|
|
23176
|
+
],
|
|
23177
|
+
outputs: [{ name: "success", type: "bool" }]
|
|
23178
|
+
},
|
|
23179
|
+
{
|
|
23180
|
+
name: "mint",
|
|
23181
|
+
type: "function",
|
|
23182
|
+
stateMutability: "nonpayable",
|
|
23183
|
+
inputs: [
|
|
23184
|
+
{ name: "to", type: "address" },
|
|
23185
|
+
{ name: "amount", type: "uint256" }
|
|
23186
|
+
],
|
|
23187
|
+
outputs: []
|
|
24161
23188
|
}
|
|
24162
|
-
|
|
24163
|
-
|
|
23189
|
+
];
|
|
23190
|
+
|
|
23191
|
+
// src/constants/chains.ts
|
|
23192
|
+
var SupportedChainId = /* @__PURE__ */ ((SupportedChainId2) => {
|
|
23193
|
+
SupportedChainId2[SupportedChainId2["ARBITRUM"] = 42161] = "ARBITRUM";
|
|
23194
|
+
SupportedChainId2[SupportedChainId2["BASE"] = 8453] = "BASE";
|
|
23195
|
+
SupportedChainId2[SupportedChainId2["BSC"] = 56] = "BSC";
|
|
23196
|
+
SupportedChainId2[SupportedChainId2["POLYGON"] = 137] = "POLYGON";
|
|
23197
|
+
SupportedChainId2[SupportedChainId2["MAINNET"] = 1] = "MAINNET";
|
|
23198
|
+
return SupportedChainId2;
|
|
23199
|
+
})(SupportedChainId || {});
|
|
23200
|
+
var V3_CHAIN_IDS = [
|
|
23201
|
+
42161 /* ARBITRUM */,
|
|
23202
|
+
8453 /* BASE */
|
|
23203
|
+
];
|
|
23204
|
+
var FALLBACK_CHAIN_ID = 42161 /* ARBITRUM */;
|
|
23205
|
+
var CHAIN_NAMES = {
|
|
23206
|
+
[42161 /* ARBITRUM */]: "Arbitrum One",
|
|
23207
|
+
[8453 /* BASE */]: "Base",
|
|
23208
|
+
[56 /* BSC */]: "BNB Chain",
|
|
23209
|
+
[137 /* POLYGON */]: "Polygon",
|
|
23210
|
+
[1 /* MAINNET */]: "Ethereum"
|
|
23211
|
+
};
|
|
23212
|
+
|
|
23213
|
+
// src/constants/addresses.ts
|
|
23214
|
+
var MULTI_ACCOUNT_ADDRESS = {
|
|
23215
|
+
[42161 /* ARBITRUM */]: "0x6273242a7E88b3De90822b31648C212215caaFE4",
|
|
23216
|
+
[8453 /* BASE */]: "0xE43166cE17d3511B09438a359dAa53513225101D"
|
|
23217
|
+
};
|
|
23218
|
+
var SYMMIO_DIAMOND_ADDRESS = {
|
|
23219
|
+
[42161 /* ARBITRUM */]: "0x8F06459f184553e5d04F07F868720BDaCAB39395",
|
|
23220
|
+
[8453 /* BASE */]: "0x91Cf2D8Ed503EC52768999aA6D8DBeA6e52dbe43"
|
|
23221
|
+
};
|
|
23222
|
+
var COLLATERAL_ADDRESS = {
|
|
23223
|
+
[42161 /* ARBITRUM */]: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
23224
|
+
[8453 /* BASE */]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
23225
|
+
};
|
|
23226
|
+
var CLEARING_HOUSE_ADDRESS = {
|
|
23227
|
+
[42161 /* ARBITRUM */]: "0x0000000000000000000000000000000000000000",
|
|
23228
|
+
[8453 /* BASE */]: "0x0000000000000000000000000000000000000000"
|
|
23229
|
+
};
|
|
23230
|
+
var SIGNATURE_STORE_ADDRESS = {
|
|
23231
|
+
[42161 /* ARBITRUM */]: "0x94eEa58De1C8945c342dB4bE9670301638E403e2"
|
|
23232
|
+
};
|
|
23233
|
+
var DEFAULT_PARTY_B_ADDRESS = {
|
|
23234
|
+
[42161 /* ARBITRUM */]: "0x00c069d68bc7420740460DBC3cc3fFF9b3742421",
|
|
23235
|
+
[8453 /* BASE */]: "0x1EcAbF0Eba136920677C9575FAccee36f30592cf"
|
|
23236
|
+
};
|
|
23237
|
+
var COLLATERAL_DECIMALS = {
|
|
23238
|
+
[42161 /* ARBITRUM */]: 6,
|
|
23239
|
+
[8453 /* BASE */]: 6
|
|
23240
|
+
};
|
|
23241
|
+
function getAddress(addressMap, chainId, name) {
|
|
23242
|
+
const addr = addressMap[chainId];
|
|
23243
|
+
if (!addr || addr === "0x0000000000000000000000000000000000000000") {
|
|
23244
|
+
throw new Error(`${name} address not configured for chain ${chainId}`);
|
|
23245
|
+
}
|
|
23246
|
+
return addr;
|
|
24164
23247
|
}
|
|
24165
|
-
|
|
24166
|
-
|
|
24167
|
-
|
|
24168
|
-
|
|
24169
|
-
|
|
24170
|
-
|
|
24171
|
-
|
|
24172
|
-
|
|
24173
|
-
|
|
24174
|
-
|
|
24175
|
-
|
|
24176
|
-
|
|
24177
|
-
|
|
24178
|
-
|
|
24179
|
-
|
|
24180
|
-
|
|
24181
|
-
|
|
24182
|
-
|
|
24183
|
-
|
|
24184
|
-
|
|
23248
|
+
|
|
23249
|
+
// src/constants/selectors.ts
|
|
23250
|
+
var SEND_QUOTE_WITH_AFFILIATE_SELECTOR = "0x40f1310c";
|
|
23251
|
+
var CLOSE_QUOTE_SELECTOR = "0x501e891f";
|
|
23252
|
+
var ALL_TRADING_SELECTORS = [
|
|
23253
|
+
SEND_QUOTE_WITH_AFFILIATE_SELECTOR,
|
|
23254
|
+
CLOSE_QUOTE_SELECTOR
|
|
23255
|
+
];
|
|
23256
|
+
|
|
23257
|
+
// src/constants/defaults.ts
|
|
23258
|
+
var MARKET_ORDER_DEADLINE = 300n;
|
|
23259
|
+
var LIMIT_ORDER_DEADLINE = 311040120n;
|
|
23260
|
+
var MARKET_PRICE_COEFFICIENT = 1.01;
|
|
23261
|
+
var MAX_LEVERAGE = 50;
|
|
23262
|
+
var DEFAULT_PRECISION = 2;
|
|
23263
|
+
var GAS_MARGIN_PERCENTAGE = 20n;
|
|
23264
|
+
var STANDARD_WITHDRAW_COOLDOWN = 43200;
|
|
23265
|
+
var MUON_BASE_URLS = [
|
|
23266
|
+
"https://muon-oracle1.rasa.capital/v1/",
|
|
23267
|
+
"https://muon-oracle2.rasa.capital/v1/",
|
|
23268
|
+
"https://muon-oracle3.rasa.capital/v1/",
|
|
23269
|
+
"https://muon-oracle4.rasa.capital/v1/"
|
|
23270
|
+
];
|
|
23271
|
+
var MUON_APP_NAME = "symmio";
|
|
23272
|
+
var MUON_REQUEST_TIMEOUT = 15e3;
|
|
23273
|
+
var HEDGER_BASE_URLS = {
|
|
23274
|
+
[42161 /* ARBITRUM */]: "https://www.perps-streaming.com/v1/42161a/0x6273242a7E88b3De90822b31648C212215caaFE4",
|
|
23275
|
+
[8453 /* BASE */]: "https://www.perps-streaming.com/v1/8453a/0x6273242a7E88b3De90822b31648C212215caaFE4"
|
|
23276
|
+
};
|
|
23277
|
+
var SymmioSDKError = class extends Error {
|
|
23278
|
+
constructor(message, code) {
|
|
23279
|
+
super(message);
|
|
23280
|
+
this.code = code;
|
|
23281
|
+
this.name = "SymmioSDKError";
|
|
24185
23282
|
}
|
|
24186
|
-
|
|
24187
|
-
|
|
24188
|
-
|
|
23283
|
+
};
|
|
23284
|
+
function validateAddress(address, name) {
|
|
23285
|
+
if (!viem.isAddress(address)) {
|
|
23286
|
+
throw new SymmioSDKError(
|
|
23287
|
+
`Invalid ${name} address: ${address}`,
|
|
23288
|
+
"INVALID_ADDRESS"
|
|
23289
|
+
);
|
|
24189
23290
|
}
|
|
24190
|
-
return
|
|
24191
|
-
accessToken: data.access_token,
|
|
24192
|
-
expirationTime: params.expirationTime,
|
|
24193
|
-
issuedAt: params.issuedAt
|
|
24194
|
-
};
|
|
23291
|
+
return address;
|
|
24195
23292
|
}
|
|
24196
|
-
|
|
24197
|
-
|
|
24198
|
-
|
|
24199
|
-
|
|
24200
|
-
|
|
24201
|
-
positionType: params.positionType,
|
|
24202
|
-
orderType: params.orderType,
|
|
24203
|
-
price: params.price,
|
|
24204
|
-
quantity: params.quantity,
|
|
24205
|
-
cva: params.cva,
|
|
24206
|
-
lf: params.lf,
|
|
24207
|
-
partyAmm: params.partyAmm,
|
|
24208
|
-
partyBmm: params.partyBmm,
|
|
24209
|
-
maxFundingRate: params.maxFundingRate,
|
|
24210
|
-
deadline: params.deadline
|
|
24211
|
-
};
|
|
24212
|
-
const response = await fetch(url, {
|
|
24213
|
-
method: "POST",
|
|
24214
|
-
headers: {
|
|
24215
|
-
"Content-Type": "application/json",
|
|
24216
|
-
Authorization: `Bearer ${accessToken}`
|
|
24217
|
-
},
|
|
24218
|
-
body: JSON.stringify(body)
|
|
24219
|
-
});
|
|
24220
|
-
if (!response.ok) {
|
|
24221
|
-
const errorData = await response.json().catch(() => null);
|
|
24222
|
-
throw new Error(
|
|
24223
|
-
errorData?.error_message ?? `Instant open failed: ${response.statusText}`
|
|
23293
|
+
function validateAmount(amount, name) {
|
|
23294
|
+
if (amount <= 0n) {
|
|
23295
|
+
throw new SymmioSDKError(
|
|
23296
|
+
`${name} must be a positive amount, got ${amount}`,
|
|
23297
|
+
"INVALID_AMOUNT"
|
|
24224
23298
|
);
|
|
24225
23299
|
}
|
|
24226
|
-
return response.json();
|
|
24227
23300
|
}
|
|
24228
|
-
|
|
24229
|
-
|
|
24230
|
-
|
|
24231
|
-
|
|
24232
|
-
|
|
24233
|
-
quantity_to_close: params.quantityToClose,
|
|
24234
|
-
close_price: params.closePrice
|
|
24235
|
-
};
|
|
24236
|
-
const response = await fetch(url, {
|
|
24237
|
-
method: "POST",
|
|
24238
|
-
headers: {
|
|
24239
|
-
"Content-Type": "application/json",
|
|
24240
|
-
Authorization: `Bearer ${accessToken}`
|
|
24241
|
-
},
|
|
24242
|
-
body: JSON.stringify(body)
|
|
24243
|
-
});
|
|
24244
|
-
if (!response.ok) {
|
|
24245
|
-
const errorData = await response.json().catch(() => null);
|
|
24246
|
-
throw new Error(
|
|
24247
|
-
errorData?.error_message ?? `Instant close failed: ${response.statusText}`
|
|
23301
|
+
function validateChainId(chainId, supportedChains) {
|
|
23302
|
+
if (!supportedChains.includes(chainId)) {
|
|
23303
|
+
throw new SymmioSDKError(
|
|
23304
|
+
`Chain ${chainId} is not supported. Supported: ${supportedChains.join(", ")}`,
|
|
23305
|
+
"UNSUPPORTED_CHAIN"
|
|
24248
23306
|
);
|
|
24249
23307
|
}
|
|
24250
|
-
return response.json();
|
|
24251
23308
|
}
|
|
24252
|
-
|
|
24253
|
-
const
|
|
24254
|
-
|
|
24255
|
-
|
|
24256
|
-
|
|
24257
|
-
|
|
24258
|
-
"Content-Type": "application/json",
|
|
24259
|
-
Authorization: `Bearer ${accessToken}`
|
|
24260
|
-
}
|
|
24261
|
-
});
|
|
24262
|
-
if (!response.ok) {
|
|
24263
|
-
const errorData = await response.json().catch(() => null);
|
|
24264
|
-
throw new Error(
|
|
24265
|
-
errorData?.error_message ?? `Cancel instant close failed: ${response.statusText}`
|
|
23309
|
+
function validateDeadline(deadline) {
|
|
23310
|
+
const now = BigInt(Math.floor(Date.now() / 1e3));
|
|
23311
|
+
if (deadline <= now) {
|
|
23312
|
+
throw new SymmioSDKError(
|
|
23313
|
+
`Deadline ${deadline} is in the past (current: ${now})`,
|
|
23314
|
+
"EXPIRED_DEADLINE"
|
|
24266
23315
|
);
|
|
24267
23316
|
}
|
|
24268
23317
|
}
|
|
24269
|
-
|
|
24270
|
-
|
|
24271
|
-
|
|
24272
|
-
|
|
24273
|
-
|
|
24274
|
-
Authorization: `Bearer ${accessToken}`
|
|
24275
|
-
}
|
|
24276
|
-
});
|
|
24277
|
-
if (!response.ok) {
|
|
24278
|
-
const errorData = await response.json().catch(() => null);
|
|
24279
|
-
throw new Error(
|
|
24280
|
-
errorData?.error_message ?? `Failed to fetch instant closes: ${response.statusText}`
|
|
23318
|
+
function validateQuantity(quantity) {
|
|
23319
|
+
if (quantity <= 0n) {
|
|
23320
|
+
throw new SymmioSDKError(
|
|
23321
|
+
`Quantity must be positive, got ${quantity}`,
|
|
23322
|
+
"INVALID_QUANTITY"
|
|
24281
23323
|
);
|
|
24282
23324
|
}
|
|
24283
|
-
return response.json();
|
|
24284
23325
|
}
|
|
24285
23326
|
|
|
24286
|
-
// src/
|
|
24287
|
-
|
|
24288
|
-
__export(stats_exports, {
|
|
24289
|
-
calculateAvailableForOrder: () => calculateAvailableForOrder,
|
|
24290
|
-
getPartyAStats: () => getPartyAStats
|
|
24291
|
-
});
|
|
24292
|
-
async function getPartyAStats(publicClient, symmioDiamond, partyA) {
|
|
24293
|
-
const result = await publicClient.readContract({
|
|
24294
|
-
address: symmioDiamond,
|
|
24295
|
-
abi: SymmioDiamondABI,
|
|
24296
|
-
functionName: "partyAStats",
|
|
24297
|
-
args: [partyA]
|
|
24298
|
-
});
|
|
23327
|
+
// src/clients/muon.ts
|
|
23328
|
+
function parseSchnorrSign(sigs) {
|
|
24299
23329
|
return {
|
|
24300
|
-
|
|
24301
|
-
|
|
24302
|
-
|
|
24303
|
-
lockedCVA: result[4],
|
|
24304
|
-
lockedLF: result[5],
|
|
24305
|
-
lockedPartyAMM: result[6],
|
|
24306
|
-
lockedPartyBMM: result[7],
|
|
24307
|
-
pendingLockedCVA: result[8],
|
|
24308
|
-
pendingLockedLF: result[9],
|
|
24309
|
-
pendingLockedPartyAMM: result[10],
|
|
24310
|
-
pendingLockedPartyBMM: result[11],
|
|
24311
|
-
positionsCount: Number(result[12]),
|
|
24312
|
-
pendingCount: Number(result[13]),
|
|
24313
|
-
nonces: 0
|
|
23330
|
+
signature: BigInt(sigs.signature),
|
|
23331
|
+
owner: sigs.owner,
|
|
23332
|
+
nonce: sigs.nonce
|
|
24314
23333
|
};
|
|
24315
23334
|
}
|
|
24316
|
-
function
|
|
24317
|
-
const
|
|
24318
|
-
|
|
24319
|
-
|
|
24320
|
-
lockedLF,
|
|
24321
|
-
lockedPartyAMM,
|
|
24322
|
-
pendingLockedCVA,
|
|
24323
|
-
pendingLockedLF,
|
|
24324
|
-
pendingLockedPartyAMM
|
|
24325
|
-
} = stats;
|
|
24326
|
-
const totalPendingLocked = pendingLockedCVA + pendingLockedLF + pendingLockedPartyAMM;
|
|
24327
|
-
if (upnl >= 0n) {
|
|
24328
|
-
const totalLocked = lockedCVA + lockedLF + lockedPartyAMM;
|
|
24329
|
-
return allocatedBalance + upnl - totalLocked - totalPendingLocked;
|
|
23335
|
+
function parseSingleUpnlSig(result) {
|
|
23336
|
+
const data = result["result"];
|
|
23337
|
+
if (!data) {
|
|
23338
|
+
throw new SymmioSDKError("Invalid Muon response: missing result", "MUON_PARSE_ERROR");
|
|
24330
23339
|
}
|
|
24331
|
-
const
|
|
24332
|
-
const
|
|
24333
|
-
|
|
23340
|
+
const sigData = data["data"];
|
|
23341
|
+
const signParams = sigData?.["signParams"] ?? data["signParams"];
|
|
23342
|
+
const signatures = sigData?.["signatures"] ?? data["signatures"];
|
|
23343
|
+
return {
|
|
23344
|
+
reqId: signParams["reqId"],
|
|
23345
|
+
timestamp: BigInt(signParams["timestamp"]),
|
|
23346
|
+
upnl: BigInt(signParams["upnl"]),
|
|
23347
|
+
gatewaySignature: signatures?.[0]?.["signature"] ?? "0x",
|
|
23348
|
+
sigs: parseSchnorrSign(
|
|
23349
|
+
signParams["sigs"] ?? signatures?.[1]
|
|
23350
|
+
)
|
|
23351
|
+
};
|
|
24334
23352
|
}
|
|
24335
|
-
|
|
24336
|
-
|
|
24337
|
-
|
|
24338
|
-
|
|
24339
|
-
muon;
|
|
24340
|
-
_publicClient;
|
|
24341
|
-
_walletClient;
|
|
24342
|
-
_multiAccount;
|
|
24343
|
-
_symmioDiamond;
|
|
24344
|
-
_collateral;
|
|
24345
|
-
_clearingHouse;
|
|
24346
|
-
_signatureStore;
|
|
24347
|
-
constructor(options) {
|
|
24348
|
-
this.chainId = options.chainId;
|
|
24349
|
-
this._publicClient = options.publicClient;
|
|
24350
|
-
this._walletClient = options.walletClient;
|
|
24351
|
-
const cfg = options.config ?? {};
|
|
24352
|
-
this._multiAccount = cfg.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, this.chainId, "MultiAccount");
|
|
24353
|
-
this._symmioDiamond = cfg.symmioDiamondAddress ?? getAddress(SYMMIO_DIAMOND_ADDRESS, this.chainId, "SymmioDiamond");
|
|
24354
|
-
this._collateral = cfg.collateralAddress ?? getAddress(COLLATERAL_ADDRESS, this.chainId, "Collateral");
|
|
24355
|
-
try {
|
|
24356
|
-
this._clearingHouse = cfg.clearingHouseAddress ?? getAddress(CLEARING_HOUSE_ADDRESS, this.chainId, "ClearingHouse");
|
|
24357
|
-
} catch {
|
|
24358
|
-
}
|
|
24359
|
-
try {
|
|
24360
|
-
this._signatureStore = cfg.signatureStoreAddress ?? getAddress(SIGNATURE_STORE_ADDRESS, this.chainId, "SignatureStore");
|
|
24361
|
-
} catch {
|
|
24362
|
-
}
|
|
24363
|
-
this.muon = new MuonClient({
|
|
24364
|
-
baseUrls: cfg.muonBaseUrls ?? MUON_BASE_URLS,
|
|
24365
|
-
appName: cfg.muonAppName ?? MUON_APP_NAME
|
|
24366
|
-
});
|
|
23353
|
+
function parseSingleUpnlAndPriceSig(result) {
|
|
23354
|
+
const data = result["result"];
|
|
23355
|
+
if (!data) {
|
|
23356
|
+
throw new SymmioSDKError("Invalid Muon response: missing result", "MUON_PARSE_ERROR");
|
|
24367
23357
|
}
|
|
24368
|
-
|
|
24369
|
-
|
|
23358
|
+
const sigData = data["data"];
|
|
23359
|
+
const signParams = sigData?.["signParams"] ?? data["signParams"];
|
|
23360
|
+
const signatures = sigData?.["signatures"] ?? data["signatures"];
|
|
23361
|
+
return {
|
|
23362
|
+
reqId: signParams["reqId"],
|
|
23363
|
+
timestamp: BigInt(signParams["timestamp"]),
|
|
23364
|
+
upnl: BigInt(signParams["upnl"]),
|
|
23365
|
+
price: BigInt(signParams["price"]),
|
|
23366
|
+
gatewaySignature: signatures?.[0]?.["signature"] ?? "0x",
|
|
23367
|
+
sigs: parseSchnorrSign(
|
|
23368
|
+
signParams["sigs"] ?? signatures?.[1]
|
|
23369
|
+
)
|
|
23370
|
+
};
|
|
23371
|
+
}
|
|
23372
|
+
function parseBatchSig(result) {
|
|
23373
|
+
const data = result["result"];
|
|
23374
|
+
if (!data) {
|
|
23375
|
+
throw new SymmioSDKError("Invalid Muon response: missing result", "MUON_PARSE_ERROR");
|
|
24370
23376
|
}
|
|
24371
|
-
|
|
24372
|
-
|
|
23377
|
+
const sigData = data["data"];
|
|
23378
|
+
const signParams = sigData?.["signParams"] ?? data["signParams"];
|
|
23379
|
+
const signatures = sigData?.["signatures"] ?? data["signatures"];
|
|
23380
|
+
return {
|
|
23381
|
+
reqId: signParams["reqId"],
|
|
23382
|
+
timestamp: BigInt(signParams["timestamp"]),
|
|
23383
|
+
upnl: BigInt(signParams["upnl"]),
|
|
23384
|
+
prices: signParams["prices"].map((p) => BigInt(p)),
|
|
23385
|
+
symbolIds: signParams["symbolIds"].map((s) => BigInt(s)),
|
|
23386
|
+
gatewaySignature: signatures?.[0]?.["signature"] ?? "0x",
|
|
23387
|
+
sigs: parseSchnorrSign(
|
|
23388
|
+
signParams["sigs"] ?? signatures?.[1]
|
|
23389
|
+
)
|
|
23390
|
+
};
|
|
23391
|
+
}
|
|
23392
|
+
var MuonClient = class {
|
|
23393
|
+
baseUrls;
|
|
23394
|
+
appName;
|
|
23395
|
+
timeout;
|
|
23396
|
+
constructor(config) {
|
|
23397
|
+
this.baseUrls = config?.baseUrls ?? MUON_BASE_URLS;
|
|
23398
|
+
this.appName = config?.appName ?? MUON_APP_NAME;
|
|
23399
|
+
this.timeout = config?.timeout ?? MUON_REQUEST_TIMEOUT;
|
|
24373
23400
|
}
|
|
24374
|
-
|
|
24375
|
-
|
|
24376
|
-
|
|
23401
|
+
/**
|
|
23402
|
+
* Sends a request to Muon, trying each base URL in order until one succeeds.
|
|
23403
|
+
*/
|
|
23404
|
+
async sendRequest(method, params) {
|
|
23405
|
+
let lastError = null;
|
|
23406
|
+
for (const baseUrl of this.baseUrls) {
|
|
23407
|
+
try {
|
|
23408
|
+
const searchParams = new URLSearchParams({
|
|
23409
|
+
app: this.appName,
|
|
23410
|
+
method
|
|
23411
|
+
});
|
|
23412
|
+
for (const [key, value] of Object.entries(params)) {
|
|
23413
|
+
searchParams.set(`params[${key}]`, value);
|
|
23414
|
+
}
|
|
23415
|
+
const url = `${baseUrl}?${searchParams.toString()}`;
|
|
23416
|
+
const controller = new AbortController();
|
|
23417
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
23418
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
23419
|
+
clearTimeout(timeoutId);
|
|
23420
|
+
if (!response.ok) {
|
|
23421
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
23422
|
+
}
|
|
23423
|
+
const json = await response.json();
|
|
23424
|
+
if (json["error"]) {
|
|
23425
|
+
throw new Error(`Muon error: ${JSON.stringify(json["error"])}`);
|
|
23426
|
+
}
|
|
23427
|
+
return json;
|
|
23428
|
+
} catch (err) {
|
|
23429
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
23430
|
+
}
|
|
24377
23431
|
}
|
|
24378
|
-
|
|
24379
|
-
|
|
24380
|
-
|
|
24381
|
-
|
|
24382
|
-
return {
|
|
24383
|
-
multiAccount: this._multiAccount,
|
|
24384
|
-
symmioDiamond: this._symmioDiamond,
|
|
24385
|
-
collateral: this._collateral,
|
|
24386
|
-
clearingHouse: this._clearingHouse,
|
|
24387
|
-
signatureStore: this._signatureStore
|
|
24388
|
-
};
|
|
24389
|
-
}
|
|
24390
|
-
// ─── Account Module (MultiAccount) ─────────────────────────────
|
|
24391
|
-
get account() {
|
|
24392
|
-
const pc = this._publicClient;
|
|
24393
|
-
const ma = this._multiAccount;
|
|
24394
|
-
return {
|
|
24395
|
-
/** Creates a new account. */
|
|
24396
|
-
addAccount: (name) => addAccount(this.requireWalletClient(), pc, ma, name),
|
|
24397
|
-
/** Edits an account's name. */
|
|
24398
|
-
editName: (accountAddress, name) => editAccountName(
|
|
24399
|
-
this.requireWalletClient(),
|
|
24400
|
-
pc,
|
|
24401
|
-
ma,
|
|
24402
|
-
accountAddress,
|
|
24403
|
-
name
|
|
24404
|
-
),
|
|
24405
|
-
/** Gets all accounts for a user (paginated). */
|
|
24406
|
-
getAll: (user, start, size) => getAccounts(pc, ma, user, start, size),
|
|
24407
|
-
/** Gets the number of accounts for a user. */
|
|
24408
|
-
getCount: (user) => getAccountsLength(pc, ma, user),
|
|
24409
|
-
/** Gets the owner of an account. */
|
|
24410
|
-
getOwner: (accountAddress) => getOwner(pc, ma, accountAddress)
|
|
24411
|
-
};
|
|
24412
|
-
}
|
|
24413
|
-
// ─── Deposit Module (MultiAccount) ─────────────────────────────
|
|
24414
|
-
get deposit() {
|
|
24415
|
-
const pc = this._publicClient;
|
|
24416
|
-
const ma = this._multiAccount;
|
|
24417
|
-
return {
|
|
24418
|
-
/** Standard deposit to an account. */
|
|
24419
|
-
standard: (params) => deposit(this.requireWalletClient(), pc, ma, params),
|
|
24420
|
-
/** Deposit and allocate in a single transaction. */
|
|
24421
|
-
depositAndAllocate: (params) => depositAndAllocate(
|
|
24422
|
-
this.requireWalletClient(),
|
|
24423
|
-
pc,
|
|
24424
|
-
ma,
|
|
24425
|
-
params
|
|
24426
|
-
)
|
|
24427
|
-
};
|
|
24428
|
-
}
|
|
24429
|
-
// ─── Withdraw Module (MultiAccount) ────────────────────────────
|
|
24430
|
-
get withdraw() {
|
|
24431
|
-
const pc = this._publicClient;
|
|
24432
|
-
const ma = this._multiAccount;
|
|
24433
|
-
return {
|
|
24434
|
-
/** Withdraws collateral from an account. */
|
|
24435
|
-
withdraw: (params) => withdraw(this.requireWalletClient(), pc, ma, params)
|
|
24436
|
-
};
|
|
24437
|
-
}
|
|
24438
|
-
// ─── Allocate / Deallocate Module (via _call proxy) ────────────
|
|
24439
|
-
get collateral() {
|
|
24440
|
-
const pc = this._publicClient;
|
|
24441
|
-
const ma = this._multiAccount;
|
|
24442
|
-
return {
|
|
24443
|
-
/** Allocate collateral to a trading account. */
|
|
24444
|
-
allocate: (subAccount, params) => allocate(
|
|
24445
|
-
this.requireWalletClient(),
|
|
24446
|
-
pc,
|
|
24447
|
-
ma,
|
|
24448
|
-
subAccount,
|
|
24449
|
-
params
|
|
24450
|
-
),
|
|
24451
|
-
/** Deallocate collateral (requires Muon signature). */
|
|
24452
|
-
deallocate: (subAccount, params) => deallocate(
|
|
24453
|
-
this.requireWalletClient(),
|
|
24454
|
-
pc,
|
|
24455
|
-
ma,
|
|
24456
|
-
subAccount,
|
|
24457
|
-
params
|
|
24458
|
-
),
|
|
24459
|
-
/** Transfer funds to recipient's allocated balance. */
|
|
24460
|
-
internalTransfer: (subAccount, params) => internalTransfer(
|
|
24461
|
-
this.requireWalletClient(),
|
|
24462
|
-
pc,
|
|
24463
|
-
ma,
|
|
24464
|
-
subAccount,
|
|
24465
|
-
params
|
|
24466
|
-
)
|
|
24467
|
-
};
|
|
24468
|
-
}
|
|
24469
|
-
// ─── Trade Module ──────────────────────────────────────────────
|
|
24470
|
-
get trade() {
|
|
24471
|
-
const pc = this._publicClient;
|
|
24472
|
-
const ma = this._multiAccount;
|
|
24473
|
-
return {
|
|
24474
|
-
/** Opens a position via sendQuoteWithAffiliate. */
|
|
24475
|
-
sendQuote: (subAccount, params) => sendQuote(
|
|
24476
|
-
this.requireWalletClient(),
|
|
24477
|
-
pc,
|
|
24478
|
-
ma,
|
|
24479
|
-
subAccount,
|
|
24480
|
-
params
|
|
24481
|
-
),
|
|
24482
|
-
/** Close a position. */
|
|
24483
|
-
closePosition: (subAccount, params) => closePosition(
|
|
24484
|
-
this.requireWalletClient(),
|
|
24485
|
-
pc,
|
|
24486
|
-
ma,
|
|
24487
|
-
subAccount,
|
|
24488
|
-
params
|
|
24489
|
-
),
|
|
24490
|
-
/** Cancel a pending quote. */
|
|
24491
|
-
cancelQuote: (subAccount, quoteId) => cancelQuote(
|
|
24492
|
-
this.requireWalletClient(),
|
|
24493
|
-
pc,
|
|
24494
|
-
ma,
|
|
24495
|
-
subAccount,
|
|
24496
|
-
quoteId
|
|
24497
|
-
),
|
|
24498
|
-
/** Cancel a pending close request. */
|
|
24499
|
-
cancelCloseRequest: (subAccount, quoteId) => cancelCloseRequest(
|
|
24500
|
-
this.requireWalletClient(),
|
|
24501
|
-
pc,
|
|
24502
|
-
ma,
|
|
24503
|
-
subAccount,
|
|
24504
|
-
quoteId
|
|
24505
|
-
),
|
|
24506
|
-
/** Force cancel a quote. */
|
|
24507
|
-
forceCancelQuote: (subAccount, quoteId) => forceCancelQuote(
|
|
24508
|
-
this.requireWalletClient(),
|
|
24509
|
-
pc,
|
|
24510
|
-
ma,
|
|
24511
|
-
subAccount,
|
|
24512
|
-
quoteId
|
|
24513
|
-
),
|
|
24514
|
-
/** Force cancel a close request. */
|
|
24515
|
-
forceCancelCloseRequest: (subAccount, quoteId) => forceCancelCloseRequest(
|
|
24516
|
-
this.requireWalletClient(),
|
|
24517
|
-
pc,
|
|
24518
|
-
ma,
|
|
24519
|
-
subAccount,
|
|
24520
|
-
quoteId
|
|
24521
|
-
)
|
|
24522
|
-
};
|
|
24523
|
-
}
|
|
24524
|
-
// ─── Approval Module ───────────────────────────────────────────
|
|
24525
|
-
get approval() {
|
|
24526
|
-
const pc = this._publicClient;
|
|
24527
|
-
const collateral = this._collateral;
|
|
24528
|
-
const ma = this._multiAccount;
|
|
24529
|
-
return {
|
|
24530
|
-
/** Approve the MultiAccount contract to spend collateral. */
|
|
24531
|
-
approveCollateral: (amount) => approve(
|
|
24532
|
-
this.requireWalletClient(),
|
|
24533
|
-
pc,
|
|
24534
|
-
collateral,
|
|
24535
|
-
ma,
|
|
24536
|
-
amount
|
|
24537
|
-
),
|
|
24538
|
-
/** Approve any spender for any token. */
|
|
24539
|
-
approve: (token, spender, amount) => approve(
|
|
24540
|
-
this.requireWalletClient(),
|
|
24541
|
-
pc,
|
|
24542
|
-
token,
|
|
24543
|
-
spender,
|
|
24544
|
-
amount
|
|
24545
|
-
),
|
|
24546
|
-
/** Get current allowance. */
|
|
24547
|
-
getAllowance: (token, owner, spender) => getAllowance(pc, token, owner, spender),
|
|
24548
|
-
/** Get token balance. */
|
|
24549
|
-
getBalance: (token, account) => getBalance(pc, token, account),
|
|
24550
|
-
/** Get approval state for a required amount. */
|
|
24551
|
-
getState: (token, owner, spender, requiredAmount) => getApprovalState(pc, token, owner, spender, requiredAmount)
|
|
24552
|
-
};
|
|
24553
|
-
}
|
|
24554
|
-
// ─── Delegation Module ─────────────────────────────────────────
|
|
24555
|
-
get delegation() {
|
|
24556
|
-
const pc = this._publicClient;
|
|
24557
|
-
const ma = this._multiAccount;
|
|
24558
|
-
return {
|
|
24559
|
-
/** Delegate access to selectors. */
|
|
24560
|
-
delegateAccess: (params) => delegateAccess(
|
|
24561
|
-
this.requireWalletClient(),
|
|
24562
|
-
pc,
|
|
24563
|
-
ma,
|
|
24564
|
-
params
|
|
24565
|
-
),
|
|
24566
|
-
/** Propose to revoke delegated access (starts cooldown). */
|
|
24567
|
-
proposeRevoke: (params) => proposeRevoke(
|
|
24568
|
-
this.requireWalletClient(),
|
|
24569
|
-
pc,
|
|
24570
|
-
ma,
|
|
24571
|
-
params
|
|
24572
|
-
),
|
|
24573
|
-
/** Revoke delegated access (after cooldown). */
|
|
24574
|
-
revokeAccess: (params) => revokeAccess(
|
|
24575
|
-
this.requireWalletClient(),
|
|
24576
|
-
pc,
|
|
24577
|
-
ma,
|
|
24578
|
-
params
|
|
24579
|
-
),
|
|
24580
|
-
/** Reads whether a selector is delegated to a target for a sub-account. */
|
|
24581
|
-
hasAccess: (params) => hasDelegatedAccess(pc, ma, params)
|
|
24582
|
-
};
|
|
24583
|
-
}
|
|
24584
|
-
// ─── Signature Module ──────────────────────────────────────────
|
|
24585
|
-
get signature() {
|
|
24586
|
-
const pc = this._publicClient;
|
|
24587
|
-
const ss = this._signatureStore;
|
|
24588
|
-
return {
|
|
24589
|
-
signTerms: () => {
|
|
24590
|
-
if (!ss) throw new Error("SignatureStore not configured for this chain");
|
|
24591
|
-
return signTermsMessage(this.requireWalletClient(), pc, ss);
|
|
24592
|
-
},
|
|
24593
|
-
storeSignature: (sig) => {
|
|
24594
|
-
if (!ss) throw new Error("SignatureStore not configured for this chain");
|
|
24595
|
-
return storeSignature(
|
|
24596
|
-
this.requireWalletClient(),
|
|
24597
|
-
pc,
|
|
24598
|
-
ss,
|
|
24599
|
-
sig
|
|
24600
|
-
);
|
|
24601
|
-
},
|
|
24602
|
-
hasSigned: (user) => {
|
|
24603
|
-
if (!ss) throw new Error("SignatureStore not configured for this chain");
|
|
24604
|
-
return hasSignedCurrentVersion(pc, ss, user);
|
|
24605
|
-
},
|
|
24606
|
-
getMessage: () => {
|
|
24607
|
-
if (!ss) throw new Error("SignatureStore not configured for this chain");
|
|
24608
|
-
return getCurrentMessage(pc, ss);
|
|
24609
|
-
}
|
|
24610
|
-
};
|
|
24611
|
-
}
|
|
24612
|
-
// ─── Admin Module ──────────────────────────────────────────────
|
|
24613
|
-
get admin() {
|
|
24614
|
-
const pc = this._publicClient;
|
|
24615
|
-
const sd = this._symmioDiamond;
|
|
24616
|
-
return {
|
|
24617
|
-
grantRole: (role, grantee) => grantRole(this.requireWalletClient(), pc, sd, role, grantee),
|
|
24618
|
-
revokeRole: (role, revokee) => revokeRole(this.requireWalletClient(), pc, sd, role, revokee)
|
|
24619
|
-
};
|
|
24620
|
-
}
|
|
24621
|
-
// ─── Instant Trading Module ──────────────────────────────────
|
|
24622
|
-
get instant() {
|
|
24623
|
-
return {
|
|
24624
|
-
/** Creates a SIWE message for instant trading authentication. */
|
|
24625
|
-
createSiweMessage: (params) => createSiweMessage(params),
|
|
24626
|
-
/** Fetches a nonce from the hedger for SIWE authentication. */
|
|
24627
|
-
getNonce: (subAccount) => getNonce(this.chainId, subAccount),
|
|
24628
|
-
/** Exchanges a signed SIWE message for an access token. */
|
|
24629
|
-
login: (params) => login(this.chainId, params),
|
|
24630
|
-
/** Opens a position instantly via the hedger (off-chain). */
|
|
24631
|
-
open: (params, accessToken) => instantOpen(this.chainId, params, accessToken),
|
|
24632
|
-
/** Closes a position instantly via the hedger (off-chain). */
|
|
24633
|
-
close: (params, accessToken) => instantClose(this.chainId, params, accessToken),
|
|
24634
|
-
/** Cancels a pending instant close request. */
|
|
24635
|
-
cancelClose: (quoteId, accessToken) => cancelInstantClose(this.chainId, quoteId, accessToken),
|
|
24636
|
-
/** Fetches the list of open instant close requests for an account. */
|
|
24637
|
-
getOpenCloses: (account, accessToken) => getOpenInstantCloses(this.chainId, account, accessToken)
|
|
24638
|
-
};
|
|
23432
|
+
throw new SymmioSDKError(
|
|
23433
|
+
`All Muon nodes failed. Last error: ${lastError?.message}`,
|
|
23434
|
+
"MUON_REQUEST_FAILED"
|
|
23435
|
+
);
|
|
24639
23436
|
}
|
|
24640
|
-
|
|
24641
|
-
|
|
24642
|
-
|
|
24643
|
-
|
|
24644
|
-
|
|
24645
|
-
|
|
24646
|
-
|
|
24647
|
-
|
|
24648
|
-
|
|
24649
|
-
};
|
|
23437
|
+
/**
|
|
23438
|
+
* Gets a UPnL + Price signature for opening a position (sendQuote).
|
|
23439
|
+
*/
|
|
23440
|
+
async getQuoteSig(params) {
|
|
23441
|
+
const result = await this.sendRequest("uPnl_A_withSymbolPrice", {
|
|
23442
|
+
partyA: params.partyA,
|
|
23443
|
+
chainId: params.chainId.toString(),
|
|
23444
|
+
symmio: params.symmioAddress,
|
|
23445
|
+
symbolId: params.symbolId.toString()
|
|
23446
|
+
});
|
|
23447
|
+
return parseSingleUpnlAndPriceSig(result);
|
|
24650
23448
|
}
|
|
24651
|
-
|
|
24652
|
-
|
|
24653
|
-
|
|
24654
|
-
|
|
24655
|
-
|
|
24656
|
-
|
|
24657
|
-
|
|
23449
|
+
/**
|
|
23450
|
+
* Gets a UPnL signature for deallocating funds.
|
|
23451
|
+
* v0.8.5: Now includes pendingBalance for safe deallocate.
|
|
23452
|
+
*/
|
|
23453
|
+
async getDeallocateSig(params) {
|
|
23454
|
+
const result = await this.sendRequest("uPnl_A", {
|
|
23455
|
+
partyA: params.partyA,
|
|
23456
|
+
chainId: params.chainId.toString(),
|
|
23457
|
+
symmio: params.symmioAddress
|
|
24658
23458
|
});
|
|
23459
|
+
return parseSingleUpnlSig(result);
|
|
24659
23460
|
}
|
|
24660
|
-
|
|
24661
|
-
|
|
24662
|
-
|
|
24663
|
-
|
|
24664
|
-
|
|
23461
|
+
/**
|
|
23462
|
+
* Gets a batch signature for multiple positions (v0.8.5).
|
|
23463
|
+
* Single signature covers multiple symbol prices for batch open/close.
|
|
23464
|
+
*/
|
|
23465
|
+
async getBatchSig(params) {
|
|
23466
|
+
const result = await this.sendRequest("uPnl_A_withSymbolPrices", {
|
|
23467
|
+
partyA: params.partyA,
|
|
23468
|
+
chainId: params.chainId.toString(),
|
|
23469
|
+
symmio: params.symmioAddress,
|
|
23470
|
+
symbolIds: params.symbolIds.join(",")
|
|
24665
23471
|
});
|
|
23472
|
+
return parseBatchSig(result);
|
|
24666
23473
|
}
|
|
24667
23474
|
};
|
|
24668
23475
|
|
|
24669
|
-
// src/
|
|
24670
|
-
var
|
|
24671
|
-
|
|
24672
|
-
|
|
24673
|
-
|
|
24674
|
-
|
|
24675
|
-
|
|
24676
|
-
|
|
24677
|
-
|
|
24678
|
-
|
|
24679
|
-
})
|
|
24680
|
-
var QuoteStatus = /* @__PURE__ */ ((QuoteStatus2) => {
|
|
24681
|
-
QuoteStatus2[QuoteStatus2["PENDING"] = 0] = "PENDING";
|
|
24682
|
-
QuoteStatus2[QuoteStatus2["LOCKED"] = 1] = "LOCKED";
|
|
24683
|
-
QuoteStatus2[QuoteStatus2["CANCEL_PENDING"] = 2] = "CANCEL_PENDING";
|
|
24684
|
-
QuoteStatus2[QuoteStatus2["CANCELED"] = 3] = "CANCELED";
|
|
24685
|
-
QuoteStatus2[QuoteStatus2["OPENED"] = 4] = "OPENED";
|
|
24686
|
-
QuoteStatus2[QuoteStatus2["CLOSE_PENDING"] = 5] = "CLOSE_PENDING";
|
|
24687
|
-
QuoteStatus2[QuoteStatus2["CANCEL_CLOSE_PENDING"] = 6] = "CANCEL_CLOSE_PENDING";
|
|
24688
|
-
QuoteStatus2[QuoteStatus2["CLOSED"] = 7] = "CLOSED";
|
|
24689
|
-
QuoteStatus2[QuoteStatus2["LIQUIDATED"] = 8] = "LIQUIDATED";
|
|
24690
|
-
QuoteStatus2[QuoteStatus2["EXPIRED"] = 9] = "EXPIRED";
|
|
24691
|
-
return QuoteStatus2;
|
|
24692
|
-
})(QuoteStatus || {});
|
|
24693
|
-
var LiquidationStatus = /* @__PURE__ */ ((LiquidationStatus2) => {
|
|
24694
|
-
LiquidationStatus2[LiquidationStatus2["NONE"] = 0] = "NONE";
|
|
24695
|
-
LiquidationStatus2[LiquidationStatus2["PENDING"] = 1] = "PENDING";
|
|
24696
|
-
LiquidationStatus2[LiquidationStatus2["ACTIVE"] = 2] = "ACTIVE";
|
|
24697
|
-
LiquidationStatus2[LiquidationStatus2["COMPLETED"] = 3] = "COMPLETED";
|
|
24698
|
-
return LiquidationStatus2;
|
|
24699
|
-
})(LiquidationStatus || {});
|
|
24700
|
-
var SoftLiquidationLevel = /* @__PURE__ */ ((SoftLiquidationLevel2) => {
|
|
24701
|
-
SoftLiquidationLevel2[SoftLiquidationLevel2["NONE"] = 0] = "NONE";
|
|
24702
|
-
SoftLiquidationLevel2[SoftLiquidationLevel2["WARNING"] = 1] = "WARNING";
|
|
24703
|
-
SoftLiquidationLevel2[SoftLiquidationLevel2["CRITICAL"] = 2] = "CRITICAL";
|
|
24704
|
-
SoftLiquidationLevel2[SoftLiquidationLevel2["EMERGENCY"] = 3] = "EMERGENCY";
|
|
24705
|
-
return SoftLiquidationLevel2;
|
|
24706
|
-
})(SoftLiquidationLevel || {});
|
|
23476
|
+
// src/actions/account.ts
|
|
23477
|
+
var account_exports = {};
|
|
23478
|
+
__export(account_exports, {
|
|
23479
|
+
addAccount: () => addAccount,
|
|
23480
|
+
editAccountName: () => editAccountName,
|
|
23481
|
+
getAccounts: () => getAccounts,
|
|
23482
|
+
getAccountsLength: () => getAccountsLength,
|
|
23483
|
+
getOwner: () => getOwner,
|
|
23484
|
+
prepareAddAccount: () => prepareAddAccount,
|
|
23485
|
+
prepareEditAccountName: () => prepareEditAccountName
|
|
23486
|
+
});
|
|
24707
23487
|
|
|
24708
|
-
// src/
|
|
24709
|
-
|
|
24710
|
-
|
|
24711
|
-
|
|
24712
|
-
AffiliateFeeLevel2[AffiliateFeeLevel2["SYMBOL"] = 2] = "SYMBOL";
|
|
24713
|
-
AffiliateFeeLevel2[AffiliateFeeLevel2["AFFILIATE_DEFAULT"] = 3] = "AFFILIATE_DEFAULT";
|
|
24714
|
-
return AffiliateFeeLevel2;
|
|
24715
|
-
})(AffiliateFeeLevel || {});
|
|
23488
|
+
// src/utils/gas.ts
|
|
23489
|
+
function calculateGasMargin(estimatedGas) {
|
|
23490
|
+
return estimatedGas * (100n + GAS_MARGIN_PERCENTAGE) / 100n;
|
|
23491
|
+
}
|
|
24716
23492
|
|
|
24717
|
-
// src/
|
|
24718
|
-
|
|
24719
|
-
|
|
24720
|
-
|
|
24721
|
-
|
|
24722
|
-
|
|
24723
|
-
|
|
24724
|
-
return
|
|
24725
|
-
|
|
23493
|
+
// src/actions/account.ts
|
|
23494
|
+
function prepareAddAccount(multiAccount, account, name) {
|
|
23495
|
+
const data = viem.encodeFunctionData({
|
|
23496
|
+
abi: MultiAccountABI,
|
|
23497
|
+
functionName: "addAccount",
|
|
23498
|
+
args: [name]
|
|
23499
|
+
});
|
|
23500
|
+
return {
|
|
23501
|
+
functionName: "addAccount",
|
|
23502
|
+
args: [name],
|
|
23503
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
23504
|
+
};
|
|
23505
|
+
}
|
|
23506
|
+
function prepareEditAccountName(multiAccount, account, accountAddress, name) {
|
|
23507
|
+
const data = viem.encodeFunctionData({
|
|
23508
|
+
abi: MultiAccountABI,
|
|
23509
|
+
functionName: "editAccountName",
|
|
23510
|
+
args: [accountAddress, name]
|
|
23511
|
+
});
|
|
23512
|
+
return {
|
|
23513
|
+
functionName: "editAccountName",
|
|
23514
|
+
args: [accountAddress, name],
|
|
23515
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
23516
|
+
};
|
|
23517
|
+
}
|
|
23518
|
+
async function addAccount(walletClient, publicClient, multiAccount, name) {
|
|
23519
|
+
const account = walletClient.account?.address;
|
|
23520
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23521
|
+
const prepared = prepareAddAccount(multiAccount, account, name);
|
|
23522
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23523
|
+
return walletClient.sendTransaction({
|
|
23524
|
+
...prepared.config,
|
|
23525
|
+
gas: calculateGasMargin(gas),
|
|
23526
|
+
chain: walletClient.chain
|
|
23527
|
+
});
|
|
23528
|
+
}
|
|
23529
|
+
async function editAccountName(walletClient, publicClient, multiAccount, accountAddress, name) {
|
|
23530
|
+
const account = walletClient.account?.address;
|
|
23531
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23532
|
+
const prepared = prepareEditAccountName(multiAccount, account, accountAddress, name);
|
|
23533
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23534
|
+
return walletClient.sendTransaction({
|
|
23535
|
+
...prepared.config,
|
|
23536
|
+
gas: calculateGasMargin(gas),
|
|
23537
|
+
chain: walletClient.chain
|
|
23538
|
+
});
|
|
23539
|
+
}
|
|
23540
|
+
async function getAccounts(publicClient, multiAccount, user, start = 0, size = 100) {
|
|
23541
|
+
const result = await publicClient.readContract({
|
|
23542
|
+
address: multiAccount,
|
|
23543
|
+
abi: MultiAccountABI,
|
|
23544
|
+
functionName: "getAccounts",
|
|
23545
|
+
args: [user, BigInt(start), BigInt(size)]
|
|
23546
|
+
});
|
|
23547
|
+
return result;
|
|
23548
|
+
}
|
|
23549
|
+
async function getAccountsLength(publicClient, multiAccount, user) {
|
|
23550
|
+
const result = await publicClient.readContract({
|
|
23551
|
+
address: multiAccount,
|
|
23552
|
+
abi: MultiAccountABI,
|
|
23553
|
+
functionName: "getAccountsLength",
|
|
23554
|
+
args: [user]
|
|
23555
|
+
});
|
|
23556
|
+
return Number(result);
|
|
23557
|
+
}
|
|
23558
|
+
async function getOwner(publicClient, multiAccount, accountAddress) {
|
|
23559
|
+
const result = await publicClient.readContract({
|
|
23560
|
+
address: multiAccount,
|
|
23561
|
+
abi: MultiAccountABI,
|
|
23562
|
+
functionName: "owners",
|
|
23563
|
+
args: [accountAddress]
|
|
23564
|
+
});
|
|
23565
|
+
return result;
|
|
23566
|
+
}
|
|
24726
23567
|
|
|
24727
|
-
// src/
|
|
24728
|
-
var
|
|
24729
|
-
|
|
24730
|
-
|
|
24731
|
-
|
|
24732
|
-
|
|
24733
|
-
|
|
24734
|
-
})
|
|
23568
|
+
// src/actions/deposit.ts
|
|
23569
|
+
var deposit_exports = {};
|
|
23570
|
+
__export(deposit_exports, {
|
|
23571
|
+
deposit: () => deposit,
|
|
23572
|
+
depositAndAllocate: () => depositAndAllocate,
|
|
23573
|
+
prepareDeposit: () => prepareDeposit,
|
|
23574
|
+
prepareDepositAndAllocate: () => prepareDepositAndAllocate
|
|
23575
|
+
});
|
|
23576
|
+
function prepareDeposit(multiAccount, account, params) {
|
|
23577
|
+
validateAmount(params.amount, "deposit amount");
|
|
23578
|
+
validateAddress(params.account, "account");
|
|
23579
|
+
const data = viem.encodeFunctionData({
|
|
23580
|
+
abi: MultiAccountABI,
|
|
23581
|
+
functionName: "depositForAccount",
|
|
23582
|
+
args: [params.account, params.amount]
|
|
23583
|
+
});
|
|
23584
|
+
return {
|
|
23585
|
+
functionName: "depositForAccount",
|
|
23586
|
+
args: [params.account, params.amount],
|
|
23587
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
23588
|
+
};
|
|
23589
|
+
}
|
|
23590
|
+
function prepareDepositAndAllocate(multiAccount, account, params) {
|
|
23591
|
+
validateAmount(params.amount, "deposit amount");
|
|
23592
|
+
validateAddress(params.account, "account");
|
|
23593
|
+
const data = viem.encodeFunctionData({
|
|
23594
|
+
abi: MultiAccountABI,
|
|
23595
|
+
functionName: "depositAndAllocateForAccount",
|
|
23596
|
+
args: [params.account, params.amount]
|
|
23597
|
+
});
|
|
23598
|
+
return {
|
|
23599
|
+
functionName: "depositAndAllocateForAccount",
|
|
23600
|
+
args: [params.account, params.amount],
|
|
23601
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
23602
|
+
};
|
|
23603
|
+
}
|
|
23604
|
+
async function deposit(walletClient, publicClient, multiAccount, params) {
|
|
23605
|
+
const account = walletClient.account?.address;
|
|
23606
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23607
|
+
const prepared = prepareDeposit(multiAccount, account, params);
|
|
23608
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23609
|
+
return walletClient.sendTransaction({
|
|
23610
|
+
...prepared.config,
|
|
23611
|
+
gas: calculateGasMargin(gas),
|
|
23612
|
+
chain: walletClient.chain
|
|
23613
|
+
});
|
|
23614
|
+
}
|
|
23615
|
+
async function depositAndAllocate(walletClient, publicClient, multiAccount, params) {
|
|
23616
|
+
const account = walletClient.account?.address;
|
|
23617
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23618
|
+
const prepared = prepareDepositAndAllocate(multiAccount, account, params);
|
|
23619
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23620
|
+
return walletClient.sendTransaction({
|
|
23621
|
+
...prepared.config,
|
|
23622
|
+
gas: calculateGasMargin(gas),
|
|
23623
|
+
chain: walletClient.chain
|
|
23624
|
+
});
|
|
23625
|
+
}
|
|
24735
23626
|
|
|
24736
|
-
// src/
|
|
24737
|
-
var
|
|
24738
|
-
|
|
24739
|
-
|
|
24740
|
-
|
|
24741
|
-
|
|
24742
|
-
|
|
24743
|
-
|
|
24744
|
-
|
|
24745
|
-
|
|
24746
|
-
|
|
24747
|
-
|
|
24748
|
-
|
|
24749
|
-
|
|
24750
|
-
|
|
24751
|
-
|
|
24752
|
-
|
|
24753
|
-
|
|
24754
|
-
|
|
24755
|
-
|
|
24756
|
-
|
|
24757
|
-
|
|
24758
|
-
|
|
24759
|
-
|
|
24760
|
-
|
|
24761
|
-
|
|
24762
|
-
|
|
24763
|
-
|
|
24764
|
-
|
|
24765
|
-
|
|
24766
|
-
|
|
24767
|
-
|
|
24768
|
-
|
|
24769
|
-
|
|
24770
|
-
|
|
24771
|
-
|
|
24772
|
-
|
|
24773
|
-
|
|
24774
|
-
|
|
24775
|
-
|
|
24776
|
-
|
|
24777
|
-
|
|
24778
|
-
|
|
24779
|
-
|
|
24780
|
-
|
|
24781
|
-
|
|
24782
|
-
|
|
24783
|
-
|
|
24784
|
-
|
|
24785
|
-
|
|
24786
|
-
|
|
24787
|
-
|
|
24788
|
-
|
|
24789
|
-
]
|
|
24790
|
-
|
|
24791
|
-
|
|
24792
|
-
|
|
24793
|
-
|
|
24794
|
-
|
|
24795
|
-
|
|
24796
|
-
|
|
24797
|
-
|
|
24798
|
-
|
|
24799
|
-
|
|
24800
|
-
|
|
24801
|
-
|
|
24802
|
-
|
|
24803
|
-
|
|
24804
|
-
|
|
24805
|
-
|
|
24806
|
-
|
|
24807
|
-
|
|
24808
|
-
|
|
24809
|
-
|
|
24810
|
-
|
|
24811
|
-
|
|
24812
|
-
|
|
24813
|
-
|
|
24814
|
-
|
|
24815
|
-
|
|
24816
|
-
|
|
24817
|
-
|
|
24818
|
-
|
|
24819
|
-
|
|
24820
|
-
|
|
24821
|
-
|
|
24822
|
-
|
|
24823
|
-
|
|
24824
|
-
|
|
24825
|
-
|
|
24826
|
-
|
|
24827
|
-
|
|
24828
|
-
|
|
24829
|
-
|
|
24830
|
-
|
|
24831
|
-
|
|
24832
|
-
|
|
24833
|
-
|
|
24834
|
-
|
|
24835
|
-
|
|
24836
|
-
|
|
24837
|
-
|
|
24838
|
-
|
|
24839
|
-
|
|
24840
|
-
{
|
|
24841
|
-
|
|
24842
|
-
|
|
24843
|
-
|
|
24844
|
-
|
|
24845
|
-
|
|
24846
|
-
|
|
24847
|
-
|
|
24848
|
-
|
|
24849
|
-
|
|
24850
|
-
|
|
24851
|
-
|
|
24852
|
-
|
|
24853
|
-
|
|
24854
|
-
|
|
24855
|
-
|
|
24856
|
-
|
|
24857
|
-
|
|
24858
|
-
|
|
24859
|
-
|
|
24860
|
-
|
|
24861
|
-
|
|
24862
|
-
|
|
24863
|
-
|
|
24864
|
-
|
|
24865
|
-
|
|
24866
|
-
|
|
24867
|
-
|
|
24868
|
-
|
|
24869
|
-
|
|
23627
|
+
// src/actions/withdraw.ts
|
|
23628
|
+
var withdraw_exports = {};
|
|
23629
|
+
__export(withdraw_exports, {
|
|
23630
|
+
prepareWithdraw: () => prepareWithdraw,
|
|
23631
|
+
withdraw: () => withdraw
|
|
23632
|
+
});
|
|
23633
|
+
function prepareWithdraw(multiAccount, account, params) {
|
|
23634
|
+
validateAmount(params.amount, "withdraw amount");
|
|
23635
|
+
validateAddress(params.account, "account");
|
|
23636
|
+
const data = viem.encodeFunctionData({
|
|
23637
|
+
abi: MultiAccountABI,
|
|
23638
|
+
functionName: "withdrawFromAccount",
|
|
23639
|
+
args: [params.account, params.amount]
|
|
23640
|
+
});
|
|
23641
|
+
return {
|
|
23642
|
+
functionName: "withdrawFromAccount",
|
|
23643
|
+
args: [params.account, params.amount],
|
|
23644
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
23645
|
+
};
|
|
23646
|
+
}
|
|
23647
|
+
async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
23648
|
+
const account = walletClient.account?.address;
|
|
23649
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23650
|
+
const prepared = prepareWithdraw(multiAccount, account, params);
|
|
23651
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23652
|
+
return walletClient.sendTransaction({
|
|
23653
|
+
...prepared.config,
|
|
23654
|
+
gas: calculateGasMargin(gas),
|
|
23655
|
+
chain: walletClient.chain
|
|
23656
|
+
});
|
|
23657
|
+
}
|
|
23658
|
+
|
|
23659
|
+
// src/actions/allocate.ts
|
|
23660
|
+
var allocate_exports = {};
|
|
23661
|
+
__export(allocate_exports, {
|
|
23662
|
+
allocate: () => allocate,
|
|
23663
|
+
deallocate: () => deallocate,
|
|
23664
|
+
internalTransfer: () => internalTransfer,
|
|
23665
|
+
prepareAllocate: () => prepareAllocate,
|
|
23666
|
+
prepareDeallocate: () => prepareDeallocate,
|
|
23667
|
+
prepareInternalTransfer: () => prepareInternalTransfer
|
|
23668
|
+
});
|
|
23669
|
+
function encodeCall(abi, functionName, args) {
|
|
23670
|
+
return viem.encodeFunctionData({
|
|
23671
|
+
abi,
|
|
23672
|
+
functionName,
|
|
23673
|
+
args
|
|
23674
|
+
});
|
|
23675
|
+
}
|
|
23676
|
+
function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
|
|
23677
|
+
const data = viem.encodeFunctionData({
|
|
23678
|
+
abi: accountDiamondAbi,
|
|
23679
|
+
functionName: "_call",
|
|
23680
|
+
args: [subAccount, callDatas]
|
|
23681
|
+
});
|
|
23682
|
+
return {
|
|
23683
|
+
functionName: "_call",
|
|
23684
|
+
args: [subAccount, callDatas],
|
|
23685
|
+
data
|
|
23686
|
+
};
|
|
23687
|
+
}
|
|
23688
|
+
|
|
23689
|
+
// src/actions/allocate.ts
|
|
23690
|
+
function prepareAllocate(multiAccount, account, subAccount, params) {
|
|
23691
|
+
validateAmount(params.amount, "allocate amount");
|
|
23692
|
+
const innerData = viem.encodeFunctionData({
|
|
23693
|
+
abi: SymmioDiamondABI,
|
|
23694
|
+
functionName: "allocate",
|
|
23695
|
+
args: [params.amount]
|
|
23696
|
+
});
|
|
23697
|
+
const proxy = wrapInProxyCall(
|
|
23698
|
+
MultiAccountABI,
|
|
23699
|
+
subAccount,
|
|
23700
|
+
[innerData]
|
|
23701
|
+
);
|
|
23702
|
+
return {
|
|
23703
|
+
functionName: "_call",
|
|
23704
|
+
args: proxy.args,
|
|
23705
|
+
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23706
|
+
};
|
|
23707
|
+
}
|
|
23708
|
+
function prepareDeallocate(multiAccount, account, subAccount, params) {
|
|
23709
|
+
validateAmount(params.amount, "deallocate amount");
|
|
23710
|
+
const muonSig = {
|
|
23711
|
+
reqId: params.upnlSig.reqId,
|
|
23712
|
+
timestamp: params.upnlSig.timestamp,
|
|
23713
|
+
upnl: params.upnlSig.upnl,
|
|
23714
|
+
gatewaySignature: params.upnlSig.gatewaySignature,
|
|
23715
|
+
sigs: {
|
|
23716
|
+
signature: params.upnlSig.sigs.signature,
|
|
23717
|
+
owner: params.upnlSig.sigs.owner,
|
|
23718
|
+
nonce: params.upnlSig.sigs.nonce
|
|
23719
|
+
}
|
|
23720
|
+
};
|
|
23721
|
+
const innerData = viem.encodeFunctionData({
|
|
23722
|
+
abi: SymmioDiamondABI,
|
|
23723
|
+
functionName: "deallocate",
|
|
23724
|
+
args: [params.amount, muonSig]
|
|
23725
|
+
});
|
|
23726
|
+
const proxy = wrapInProxyCall(
|
|
23727
|
+
MultiAccountABI,
|
|
23728
|
+
subAccount,
|
|
23729
|
+
[innerData]
|
|
23730
|
+
);
|
|
23731
|
+
return {
|
|
23732
|
+
functionName: "_call",
|
|
23733
|
+
args: proxy.args,
|
|
23734
|
+
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23735
|
+
};
|
|
23736
|
+
}
|
|
23737
|
+
function prepareInternalTransfer(multiAccount, account, subAccount, params) {
|
|
23738
|
+
validateAmount(params.amount, "transfer amount");
|
|
23739
|
+
validateAddress(params.recipient, "recipient");
|
|
23740
|
+
const innerData = viem.encodeFunctionData({
|
|
23741
|
+
abi: SymmioDiamondABI,
|
|
23742
|
+
functionName: "internalTransfer",
|
|
23743
|
+
args: [params.recipient, params.amount]
|
|
23744
|
+
});
|
|
23745
|
+
const proxy = wrapInProxyCall(
|
|
23746
|
+
MultiAccountABI,
|
|
23747
|
+
subAccount,
|
|
23748
|
+
[innerData]
|
|
23749
|
+
);
|
|
23750
|
+
return {
|
|
23751
|
+
functionName: "_call",
|
|
23752
|
+
args: proxy.args,
|
|
23753
|
+
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23754
|
+
};
|
|
23755
|
+
}
|
|
23756
|
+
async function allocate(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23757
|
+
const account = walletClient.account?.address;
|
|
23758
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23759
|
+
const prepared = prepareAllocate(multiAccount, account, subAccount, params);
|
|
23760
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23761
|
+
return walletClient.sendTransaction({
|
|
23762
|
+
...prepared.config,
|
|
23763
|
+
gas: calculateGasMargin(gas),
|
|
23764
|
+
chain: walletClient.chain
|
|
23765
|
+
});
|
|
23766
|
+
}
|
|
23767
|
+
async function deallocate(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23768
|
+
const account = walletClient.account?.address;
|
|
23769
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23770
|
+
const prepared = prepareDeallocate(multiAccount, account, subAccount, params);
|
|
23771
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23772
|
+
return walletClient.sendTransaction({
|
|
23773
|
+
...prepared.config,
|
|
23774
|
+
gas: calculateGasMargin(gas),
|
|
23775
|
+
chain: walletClient.chain
|
|
23776
|
+
});
|
|
23777
|
+
}
|
|
23778
|
+
async function internalTransfer(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23779
|
+
const account = walletClient.account?.address;
|
|
23780
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23781
|
+
const prepared = prepareInternalTransfer(multiAccount, account, subAccount, params);
|
|
23782
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23783
|
+
return walletClient.sendTransaction({
|
|
23784
|
+
...prepared.config,
|
|
23785
|
+
gas: calculateGasMargin(gas),
|
|
23786
|
+
chain: walletClient.chain
|
|
23787
|
+
});
|
|
23788
|
+
}
|
|
23789
|
+
|
|
23790
|
+
// src/actions/trade.ts
|
|
23791
|
+
var trade_exports = {};
|
|
23792
|
+
__export(trade_exports, {
|
|
23793
|
+
preparePairTrade: () => preparePairTrade,
|
|
23794
|
+
prepareSendQuote: () => prepareSendQuote,
|
|
23795
|
+
sendQuote: () => sendQuote
|
|
23796
|
+
});
|
|
23797
|
+
function buildUpnlSigTuple(sig) {
|
|
23798
|
+
return {
|
|
23799
|
+
reqId: sig.reqId,
|
|
23800
|
+
timestamp: sig.timestamp,
|
|
23801
|
+
upnl: sig.upnl,
|
|
23802
|
+
price: sig.price,
|
|
23803
|
+
gatewaySignature: sig.gatewaySignature,
|
|
23804
|
+
sigs: {
|
|
23805
|
+
signature: sig.sigs.signature,
|
|
23806
|
+
owner: sig.sigs.owner,
|
|
23807
|
+
nonce: sig.sigs.nonce
|
|
23808
|
+
}
|
|
23809
|
+
};
|
|
23810
|
+
}
|
|
23811
|
+
function prepareSendQuote(multiAccount, account, subAccount, params) {
|
|
23812
|
+
validateQuantity(params.quantity);
|
|
23813
|
+
const innerData = viem.encodeFunctionData({
|
|
23814
|
+
abi: SymmioDiamondABI,
|
|
23815
|
+
functionName: "sendQuoteWithAffiliate",
|
|
23816
|
+
args: [
|
|
23817
|
+
params.partyBsWhiteList,
|
|
23818
|
+
BigInt(params.symbolId),
|
|
23819
|
+
params.positionType,
|
|
23820
|
+
params.orderType,
|
|
23821
|
+
params.price,
|
|
23822
|
+
params.quantity,
|
|
23823
|
+
params.cva,
|
|
23824
|
+
params.lf,
|
|
23825
|
+
params.partyAmm,
|
|
23826
|
+
params.partyBmm,
|
|
23827
|
+
params.maxFundingRate,
|
|
23828
|
+
params.deadline,
|
|
23829
|
+
params.affiliate,
|
|
23830
|
+
buildUpnlSigTuple(params.upnlSig)
|
|
24870
23831
|
]
|
|
24871
|
-
}
|
|
24872
|
-
|
|
24873
|
-
|
|
24874
|
-
|
|
24875
|
-
|
|
24876
|
-
|
|
24877
|
-
|
|
24878
|
-
|
|
24879
|
-
|
|
23832
|
+
});
|
|
23833
|
+
const proxy = wrapInProxyCall(
|
|
23834
|
+
MultiAccountABI,
|
|
23835
|
+
subAccount,
|
|
23836
|
+
[innerData]
|
|
23837
|
+
);
|
|
23838
|
+
return {
|
|
23839
|
+
functionName: "_call",
|
|
23840
|
+
args: proxy.args,
|
|
23841
|
+
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23842
|
+
};
|
|
23843
|
+
}
|
|
23844
|
+
function preparePairTrade(multiAccount, account, subAccount, longParams, shortParams) {
|
|
23845
|
+
const longData = viem.encodeFunctionData({
|
|
23846
|
+
abi: SymmioDiamondABI,
|
|
23847
|
+
functionName: "sendQuoteWithAffiliate",
|
|
23848
|
+
args: [
|
|
23849
|
+
longParams.partyBsWhiteList,
|
|
23850
|
+
BigInt(longParams.symbolId),
|
|
23851
|
+
longParams.positionType,
|
|
23852
|
+
longParams.orderType,
|
|
23853
|
+
longParams.price,
|
|
23854
|
+
longParams.quantity,
|
|
23855
|
+
longParams.cva,
|
|
23856
|
+
longParams.lf,
|
|
23857
|
+
longParams.partyAmm,
|
|
23858
|
+
longParams.partyBmm,
|
|
23859
|
+
longParams.maxFundingRate,
|
|
23860
|
+
longParams.deadline,
|
|
23861
|
+
longParams.affiliate,
|
|
23862
|
+
buildUpnlSigTuple(longParams.upnlSig)
|
|
23863
|
+
]
|
|
23864
|
+
});
|
|
23865
|
+
const shortData = viem.encodeFunctionData({
|
|
23866
|
+
abi: SymmioDiamondABI,
|
|
23867
|
+
functionName: "sendQuoteWithAffiliate",
|
|
23868
|
+
args: [
|
|
23869
|
+
shortParams.partyBsWhiteList,
|
|
23870
|
+
BigInt(shortParams.symbolId),
|
|
23871
|
+
shortParams.positionType,
|
|
23872
|
+
shortParams.orderType,
|
|
23873
|
+
shortParams.price,
|
|
23874
|
+
shortParams.quantity,
|
|
23875
|
+
shortParams.cva,
|
|
23876
|
+
shortParams.lf,
|
|
23877
|
+
shortParams.partyAmm,
|
|
23878
|
+
shortParams.partyBmm,
|
|
23879
|
+
shortParams.maxFundingRate,
|
|
23880
|
+
shortParams.deadline,
|
|
23881
|
+
shortParams.affiliate,
|
|
23882
|
+
buildUpnlSigTuple(shortParams.upnlSig)
|
|
23883
|
+
]
|
|
23884
|
+
});
|
|
23885
|
+
const proxy = wrapInProxyCall(
|
|
23886
|
+
MultiAccountABI,
|
|
23887
|
+
subAccount,
|
|
23888
|
+
[longData, shortData]
|
|
23889
|
+
);
|
|
23890
|
+
return {
|
|
23891
|
+
functionName: "_call",
|
|
23892
|
+
args: proxy.args,
|
|
23893
|
+
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23894
|
+
};
|
|
23895
|
+
}
|
|
23896
|
+
async function sendQuote(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23897
|
+
const account = walletClient.account?.address;
|
|
23898
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23899
|
+
const prepared = prepareSendQuote(multiAccount, account, subAccount, params);
|
|
23900
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23901
|
+
return walletClient.sendTransaction({
|
|
23902
|
+
...prepared.config,
|
|
23903
|
+
gas: calculateGasMargin(gas),
|
|
23904
|
+
chain: walletClient.chain
|
|
23905
|
+
});
|
|
23906
|
+
}
|
|
23907
|
+
|
|
23908
|
+
// src/actions/close.ts
|
|
23909
|
+
var close_exports = {};
|
|
23910
|
+
__export(close_exports, {
|
|
23911
|
+
closePosition: () => closePosition,
|
|
23912
|
+
prepareClosePosition: () => prepareClosePosition,
|
|
23913
|
+
preparePairClose: () => preparePairClose
|
|
23914
|
+
});
|
|
23915
|
+
function prepareClosePosition(multiAccount, account, subAccount, params) {
|
|
23916
|
+
const innerData = viem.encodeFunctionData({
|
|
23917
|
+
abi: SymmioDiamondABI,
|
|
23918
|
+
functionName: "requestToClosePosition",
|
|
23919
|
+
args: [
|
|
23920
|
+
params.quoteId,
|
|
23921
|
+
params.closePrice,
|
|
23922
|
+
params.quantityToClose,
|
|
23923
|
+
params.orderType,
|
|
23924
|
+
params.deadline
|
|
24880
23925
|
]
|
|
24881
|
-
}
|
|
24882
|
-
|
|
24883
|
-
|
|
24884
|
-
|
|
24885
|
-
|
|
24886
|
-
|
|
23926
|
+
});
|
|
23927
|
+
const proxy = wrapInProxyCall(
|
|
23928
|
+
MultiAccountABI,
|
|
23929
|
+
subAccount,
|
|
23930
|
+
[innerData]
|
|
23931
|
+
);
|
|
23932
|
+
return {
|
|
23933
|
+
functionName: "_call",
|
|
23934
|
+
args: proxy.args,
|
|
23935
|
+
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23936
|
+
};
|
|
23937
|
+
}
|
|
23938
|
+
function preparePairClose(multiAccount, account, subAccount, longClose, shortClose) {
|
|
23939
|
+
const longData = viem.encodeFunctionData({
|
|
23940
|
+
abi: SymmioDiamondABI,
|
|
23941
|
+
functionName: "requestToClosePosition",
|
|
23942
|
+
args: [
|
|
23943
|
+
longClose.quoteId,
|
|
23944
|
+
longClose.closePrice,
|
|
23945
|
+
longClose.quantityToClose,
|
|
23946
|
+
longClose.orderType,
|
|
23947
|
+
longClose.deadline
|
|
24887
23948
|
]
|
|
24888
|
-
}
|
|
24889
|
-
{
|
|
24890
|
-
|
|
24891
|
-
|
|
24892
|
-
|
|
24893
|
-
|
|
24894
|
-
|
|
24895
|
-
|
|
23949
|
+
});
|
|
23950
|
+
const shortData = viem.encodeFunctionData({
|
|
23951
|
+
abi: SymmioDiamondABI,
|
|
23952
|
+
functionName: "requestToClosePosition",
|
|
23953
|
+
args: [
|
|
23954
|
+
shortClose.quoteId,
|
|
23955
|
+
shortClose.closePrice,
|
|
23956
|
+
shortClose.quantityToClose,
|
|
23957
|
+
shortClose.orderType,
|
|
23958
|
+
shortClose.deadline
|
|
24896
23959
|
]
|
|
23960
|
+
});
|
|
23961
|
+
const proxy = wrapInProxyCall(
|
|
23962
|
+
MultiAccountABI,
|
|
23963
|
+
subAccount,
|
|
23964
|
+
[longData, shortData]
|
|
23965
|
+
);
|
|
23966
|
+
return {
|
|
23967
|
+
functionName: "_call",
|
|
23968
|
+
args: proxy.args,
|
|
23969
|
+
config: { account, to: multiAccount, data: proxy.data, value: 0n }
|
|
23970
|
+
};
|
|
23971
|
+
}
|
|
23972
|
+
async function closePosition(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
23973
|
+
const account = walletClient.account?.address;
|
|
23974
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
23975
|
+
const prepared = prepareClosePosition(multiAccount, account, subAccount, params);
|
|
23976
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
23977
|
+
return walletClient.sendTransaction({
|
|
23978
|
+
...prepared.config,
|
|
23979
|
+
gas: calculateGasMargin(gas),
|
|
23980
|
+
chain: walletClient.chain
|
|
23981
|
+
});
|
|
23982
|
+
}
|
|
23983
|
+
|
|
23984
|
+
// src/actions/cancel.ts
|
|
23985
|
+
var cancel_exports = {};
|
|
23986
|
+
__export(cancel_exports, {
|
|
23987
|
+
cancelCloseRequest: () => cancelCloseRequest,
|
|
23988
|
+
cancelQuote: () => cancelQuote,
|
|
23989
|
+
forceCancelCloseRequest: () => forceCancelCloseRequest,
|
|
23990
|
+
forceCancelQuote: () => forceCancelQuote,
|
|
23991
|
+
prepareCancelCloseRequest: () => prepareCancelCloseRequest,
|
|
23992
|
+
prepareCancelQuote: () => prepareCancelQuote,
|
|
23993
|
+
prepareForceCancelCloseRequest: () => prepareForceCancelCloseRequest,
|
|
23994
|
+
prepareForceCancelQuote: () => prepareForceCancelQuote
|
|
23995
|
+
});
|
|
23996
|
+
function prepareCancelAction(accountDiamond, account, subAccount, functionName, quoteId) {
|
|
23997
|
+
const innerData = viem.encodeFunctionData({
|
|
23998
|
+
abi: SymmioDiamondABI,
|
|
23999
|
+
functionName,
|
|
24000
|
+
args: [quoteId]
|
|
24001
|
+
});
|
|
24002
|
+
const proxy = wrapInProxyCall(
|
|
24003
|
+
MultiAccountABI,
|
|
24004
|
+
subAccount,
|
|
24005
|
+
[innerData]
|
|
24006
|
+
);
|
|
24007
|
+
return {
|
|
24008
|
+
functionName: "_call",
|
|
24009
|
+
args: proxy.args,
|
|
24010
|
+
config: { account, to: accountDiamond, data: proxy.data, value: 0n }
|
|
24011
|
+
};
|
|
24012
|
+
}
|
|
24013
|
+
async function executeCancelAction(walletClient, publicClient, accountDiamond, subAccount, functionName, quoteId) {
|
|
24014
|
+
const account = walletClient.account?.address;
|
|
24015
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24016
|
+
const prepared = prepareCancelAction(
|
|
24017
|
+
accountDiamond,
|
|
24018
|
+
account,
|
|
24019
|
+
subAccount,
|
|
24020
|
+
functionName,
|
|
24021
|
+
quoteId
|
|
24022
|
+
);
|
|
24023
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
24024
|
+
return walletClient.sendTransaction({
|
|
24025
|
+
...prepared.config,
|
|
24026
|
+
gas: calculateGasMargin(gas),
|
|
24027
|
+
chain: walletClient.chain
|
|
24028
|
+
});
|
|
24029
|
+
}
|
|
24030
|
+
function prepareCancelQuote(accountDiamond, account, subAccount, quoteId) {
|
|
24031
|
+
return prepareCancelAction(
|
|
24032
|
+
accountDiamond,
|
|
24033
|
+
account,
|
|
24034
|
+
subAccount,
|
|
24035
|
+
"requestToCancelQuote",
|
|
24036
|
+
quoteId
|
|
24037
|
+
);
|
|
24038
|
+
}
|
|
24039
|
+
function prepareCancelCloseRequest(accountDiamond, account, subAccount, quoteId) {
|
|
24040
|
+
return prepareCancelAction(
|
|
24041
|
+
accountDiamond,
|
|
24042
|
+
account,
|
|
24043
|
+
subAccount,
|
|
24044
|
+
"requestToCancelCloseRequest",
|
|
24045
|
+
quoteId
|
|
24046
|
+
);
|
|
24047
|
+
}
|
|
24048
|
+
function prepareForceCancelQuote(accountDiamond, account, subAccount, quoteId) {
|
|
24049
|
+
return prepareCancelAction(
|
|
24050
|
+
accountDiamond,
|
|
24051
|
+
account,
|
|
24052
|
+
subAccount,
|
|
24053
|
+
"forceCancelQuote",
|
|
24054
|
+
quoteId
|
|
24055
|
+
);
|
|
24056
|
+
}
|
|
24057
|
+
function prepareForceCancelCloseRequest(accountDiamond, account, subAccount, quoteId) {
|
|
24058
|
+
return prepareCancelAction(
|
|
24059
|
+
accountDiamond,
|
|
24060
|
+
account,
|
|
24061
|
+
subAccount,
|
|
24062
|
+
"forceCancelCloseRequest",
|
|
24063
|
+
quoteId
|
|
24064
|
+
);
|
|
24065
|
+
}
|
|
24066
|
+
async function cancelQuote(walletClient, publicClient, accountDiamond, subAccount, quoteId) {
|
|
24067
|
+
return executeCancelAction(
|
|
24068
|
+
walletClient,
|
|
24069
|
+
publicClient,
|
|
24070
|
+
accountDiamond,
|
|
24071
|
+
subAccount,
|
|
24072
|
+
"requestToCancelQuote",
|
|
24073
|
+
quoteId
|
|
24074
|
+
);
|
|
24075
|
+
}
|
|
24076
|
+
async function cancelCloseRequest(walletClient, publicClient, accountDiamond, subAccount, quoteId) {
|
|
24077
|
+
return executeCancelAction(
|
|
24078
|
+
walletClient,
|
|
24079
|
+
publicClient,
|
|
24080
|
+
accountDiamond,
|
|
24081
|
+
subAccount,
|
|
24082
|
+
"requestToCancelCloseRequest",
|
|
24083
|
+
quoteId
|
|
24084
|
+
);
|
|
24085
|
+
}
|
|
24086
|
+
async function forceCancelQuote(walletClient, publicClient, accountDiamond, subAccount, quoteId) {
|
|
24087
|
+
return executeCancelAction(
|
|
24088
|
+
walletClient,
|
|
24089
|
+
publicClient,
|
|
24090
|
+
accountDiamond,
|
|
24091
|
+
subAccount,
|
|
24092
|
+
"forceCancelQuote",
|
|
24093
|
+
quoteId
|
|
24094
|
+
);
|
|
24095
|
+
}
|
|
24096
|
+
async function forceCancelCloseRequest(walletClient, publicClient, accountDiamond, subAccount, quoteId) {
|
|
24097
|
+
return executeCancelAction(
|
|
24098
|
+
walletClient,
|
|
24099
|
+
publicClient,
|
|
24100
|
+
accountDiamond,
|
|
24101
|
+
subAccount,
|
|
24102
|
+
"forceCancelCloseRequest",
|
|
24103
|
+
quoteId
|
|
24104
|
+
);
|
|
24105
|
+
}
|
|
24106
|
+
|
|
24107
|
+
// src/actions/approval.ts
|
|
24108
|
+
var approval_exports = {};
|
|
24109
|
+
__export(approval_exports, {
|
|
24110
|
+
ApprovalState: () => ApprovalState,
|
|
24111
|
+
approve: () => approve,
|
|
24112
|
+
getAllowance: () => getAllowance,
|
|
24113
|
+
getApprovalState: () => getApprovalState,
|
|
24114
|
+
getBalance: () => getBalance,
|
|
24115
|
+
getDecimals: () => getDecimals,
|
|
24116
|
+
prepareApprove: () => prepareApprove
|
|
24117
|
+
});
|
|
24118
|
+
var ApprovalState = /* @__PURE__ */ ((ApprovalState2) => {
|
|
24119
|
+
ApprovalState2["UNKNOWN"] = "UNKNOWN";
|
|
24120
|
+
ApprovalState2["NOT_APPROVED"] = "NOT_APPROVED";
|
|
24121
|
+
ApprovalState2["PENDING"] = "PENDING";
|
|
24122
|
+
ApprovalState2["APPROVED"] = "APPROVED";
|
|
24123
|
+
return ApprovalState2;
|
|
24124
|
+
})(ApprovalState || {});
|
|
24125
|
+
function prepareApprove(tokenAddress, account, spender, amount) {
|
|
24126
|
+
validateAddress(spender, "spender");
|
|
24127
|
+
const data = viem.encodeFunctionData({
|
|
24128
|
+
abi: ERC20ABI,
|
|
24129
|
+
functionName: "approve",
|
|
24130
|
+
args: [spender, amount]
|
|
24131
|
+
});
|
|
24132
|
+
return {
|
|
24133
|
+
functionName: "approve",
|
|
24134
|
+
args: [spender, amount],
|
|
24135
|
+
config: { account, to: tokenAddress, data, value: 0n }
|
|
24136
|
+
};
|
|
24137
|
+
}
|
|
24138
|
+
async function approve(walletClient, publicClient, tokenAddress, spender, amount) {
|
|
24139
|
+
const account = walletClient.account?.address;
|
|
24140
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24141
|
+
const prepared = prepareApprove(tokenAddress, account, spender, amount);
|
|
24142
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
24143
|
+
return walletClient.sendTransaction({
|
|
24144
|
+
...prepared.config,
|
|
24145
|
+
gas: calculateGasMargin(gas),
|
|
24146
|
+
chain: walletClient.chain
|
|
24147
|
+
});
|
|
24148
|
+
}
|
|
24149
|
+
async function getAllowance(publicClient, tokenAddress, owner, spender) {
|
|
24150
|
+
return await publicClient.readContract({
|
|
24151
|
+
address: tokenAddress,
|
|
24152
|
+
abi: ERC20ABI,
|
|
24153
|
+
functionName: "allowance",
|
|
24154
|
+
args: [owner, spender]
|
|
24155
|
+
});
|
|
24156
|
+
}
|
|
24157
|
+
async function getBalance(publicClient, tokenAddress, account) {
|
|
24158
|
+
return await publicClient.readContract({
|
|
24159
|
+
address: tokenAddress,
|
|
24160
|
+
abi: ERC20ABI,
|
|
24161
|
+
functionName: "balanceOf",
|
|
24162
|
+
args: [account]
|
|
24163
|
+
});
|
|
24164
|
+
}
|
|
24165
|
+
async function getDecimals(publicClient, tokenAddress) {
|
|
24166
|
+
return await publicClient.readContract({
|
|
24167
|
+
address: tokenAddress,
|
|
24168
|
+
abi: ERC20ABI,
|
|
24169
|
+
functionName: "decimals"
|
|
24170
|
+
});
|
|
24171
|
+
}
|
|
24172
|
+
async function getApprovalState(publicClient, tokenAddress, owner, spender, requiredAmount) {
|
|
24173
|
+
try {
|
|
24174
|
+
const allowance = await getAllowance(publicClient, tokenAddress, owner, spender);
|
|
24175
|
+
if (allowance >= requiredAmount) {
|
|
24176
|
+
return "APPROVED" /* APPROVED */;
|
|
24177
|
+
}
|
|
24178
|
+
return "NOT_APPROVED" /* NOT_APPROVED */;
|
|
24179
|
+
} catch {
|
|
24180
|
+
return "UNKNOWN" /* UNKNOWN */;
|
|
24181
|
+
}
|
|
24182
|
+
}
|
|
24183
|
+
|
|
24184
|
+
// src/actions/delegation.ts
|
|
24185
|
+
var delegation_exports = {};
|
|
24186
|
+
__export(delegation_exports, {
|
|
24187
|
+
delegateAccess: () => delegateAccess,
|
|
24188
|
+
hasDelegatedAccess: () => hasDelegatedAccess,
|
|
24189
|
+
prepareDelegateAccess: () => prepareDelegateAccess,
|
|
24190
|
+
prepareProposeRevoke: () => prepareProposeRevoke,
|
|
24191
|
+
prepareRevokeAccess: () => prepareRevokeAccess,
|
|
24192
|
+
proposeRevoke: () => proposeRevoke,
|
|
24193
|
+
revokeAccess: () => revokeAccess
|
|
24194
|
+
});
|
|
24195
|
+
function prepareDelegateAccess(multiAccount, account, params) {
|
|
24196
|
+
validateAddress(params.account, "subAccount");
|
|
24197
|
+
validateAddress(params.target, "target");
|
|
24198
|
+
const data = viem.encodeFunctionData({
|
|
24199
|
+
abi: MultiAccountABI,
|
|
24200
|
+
functionName: "delegateAccesses",
|
|
24201
|
+
args: [params.account, params.target, params.selectors, params.activate]
|
|
24202
|
+
});
|
|
24203
|
+
return {
|
|
24204
|
+
functionName: "delegateAccesses",
|
|
24205
|
+
args: [params.account, params.target, params.selectors, params.activate],
|
|
24206
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
24207
|
+
};
|
|
24208
|
+
}
|
|
24209
|
+
function prepareProposeRevoke(multiAccount, account, params) {
|
|
24210
|
+
const data = viem.encodeFunctionData({
|
|
24211
|
+
abi: MultiAccountABI,
|
|
24212
|
+
functionName: "proposeToRevokeAccesses",
|
|
24213
|
+
args: [params.account, params.target, params.selectors]
|
|
24214
|
+
});
|
|
24215
|
+
return {
|
|
24216
|
+
functionName: "proposeToRevokeAccesses",
|
|
24217
|
+
args: [params.account, params.target, params.selectors],
|
|
24218
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
24219
|
+
};
|
|
24220
|
+
}
|
|
24221
|
+
function prepareRevokeAccess(multiAccount, account, params) {
|
|
24222
|
+
const data = viem.encodeFunctionData({
|
|
24223
|
+
abi: MultiAccountABI,
|
|
24224
|
+
functionName: "revokeAccesses",
|
|
24225
|
+
args: [params.account, params.target, params.selectors]
|
|
24226
|
+
});
|
|
24227
|
+
return {
|
|
24228
|
+
functionName: "revokeAccesses",
|
|
24229
|
+
args: [params.account, params.target, params.selectors],
|
|
24230
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
24231
|
+
};
|
|
24232
|
+
}
|
|
24233
|
+
async function delegateAccess(walletClient, publicClient, multiAccount, params) {
|
|
24234
|
+
const account = walletClient.account?.address;
|
|
24235
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24236
|
+
const prepared = prepareDelegateAccess(multiAccount, account, params);
|
|
24237
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
24238
|
+
return walletClient.sendTransaction({
|
|
24239
|
+
...prepared.config,
|
|
24240
|
+
gas: calculateGasMargin(gas),
|
|
24241
|
+
chain: walletClient.chain
|
|
24242
|
+
});
|
|
24243
|
+
}
|
|
24244
|
+
async function proposeRevoke(walletClient, publicClient, multiAccount, params) {
|
|
24245
|
+
const account = walletClient.account?.address;
|
|
24246
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24247
|
+
const prepared = prepareProposeRevoke(multiAccount, account, params);
|
|
24248
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
24249
|
+
return walletClient.sendTransaction({
|
|
24250
|
+
...prepared.config,
|
|
24251
|
+
gas: calculateGasMargin(gas),
|
|
24252
|
+
chain: walletClient.chain
|
|
24253
|
+
});
|
|
24254
|
+
}
|
|
24255
|
+
async function revokeAccess(walletClient, publicClient, multiAccount, params) {
|
|
24256
|
+
const account = walletClient.account?.address;
|
|
24257
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24258
|
+
const prepared = prepareRevokeAccess(multiAccount, account, params);
|
|
24259
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
24260
|
+
return walletClient.sendTransaction({
|
|
24261
|
+
...prepared.config,
|
|
24262
|
+
gas: calculateGasMargin(gas),
|
|
24263
|
+
chain: walletClient.chain
|
|
24264
|
+
});
|
|
24265
|
+
}
|
|
24266
|
+
async function hasDelegatedAccess(publicClient, multiAccount, params) {
|
|
24267
|
+
validateAddress(params.account, "subAccount");
|
|
24268
|
+
validateAddress(params.target, "target");
|
|
24269
|
+
const result = await publicClient.readContract({
|
|
24270
|
+
address: multiAccount,
|
|
24271
|
+
abi: MultiAccountABI,
|
|
24272
|
+
functionName: "delegatedAccesses",
|
|
24273
|
+
args: [params.account, params.target, params.selector]
|
|
24274
|
+
});
|
|
24275
|
+
return Boolean(result);
|
|
24276
|
+
}
|
|
24277
|
+
|
|
24278
|
+
// src/actions/signature.ts
|
|
24279
|
+
var signature_exports = {};
|
|
24280
|
+
__export(signature_exports, {
|
|
24281
|
+
getCurrentMessage: () => getCurrentMessage,
|
|
24282
|
+
hasSignedCurrentVersion: () => hasSignedCurrentVersion,
|
|
24283
|
+
prepareStoreSignature: () => prepareStoreSignature,
|
|
24284
|
+
signTermsMessage: () => signTermsMessage,
|
|
24285
|
+
storeSignature: () => storeSignature
|
|
24286
|
+
});
|
|
24287
|
+
function prepareStoreSignature(signatureStore, account, signature) {
|
|
24288
|
+
const data = viem.encodeFunctionData({
|
|
24289
|
+
abi: SignatureStoreABI,
|
|
24290
|
+
functionName: "storeSignatureForCurrentVersion",
|
|
24291
|
+
args: [signature]
|
|
24292
|
+
});
|
|
24293
|
+
return {
|
|
24294
|
+
functionName: "storeSignatureForCurrentVersion",
|
|
24295
|
+
args: [signature],
|
|
24296
|
+
config: { account, to: signatureStore, data, value: 0n }
|
|
24297
|
+
};
|
|
24298
|
+
}
|
|
24299
|
+
async function storeSignature(walletClient, publicClient, signatureStore, signature) {
|
|
24300
|
+
const account = walletClient.account?.address;
|
|
24301
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24302
|
+
const prepared = prepareStoreSignature(signatureStore, account, signature);
|
|
24303
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
24304
|
+
return walletClient.sendTransaction({
|
|
24305
|
+
...prepared.config,
|
|
24306
|
+
gas: calculateGasMargin(gas),
|
|
24307
|
+
chain: walletClient.chain
|
|
24308
|
+
});
|
|
24309
|
+
}
|
|
24310
|
+
async function signTermsMessage(walletClient, publicClient, signatureStore) {
|
|
24311
|
+
const account = walletClient.account;
|
|
24312
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24313
|
+
const message = await publicClient.readContract({
|
|
24314
|
+
address: signatureStore,
|
|
24315
|
+
abi: SignatureStoreABI,
|
|
24316
|
+
functionName: "getCurrentVersionMessage"
|
|
24317
|
+
});
|
|
24318
|
+
return walletClient.signMessage({
|
|
24319
|
+
account,
|
|
24320
|
+
message
|
|
24321
|
+
});
|
|
24322
|
+
}
|
|
24323
|
+
async function hasSignedCurrentVersion(publicClient, signatureStore, user) {
|
|
24324
|
+
return await publicClient.readContract({
|
|
24325
|
+
address: signatureStore,
|
|
24326
|
+
abi: SignatureStoreABI,
|
|
24327
|
+
functionName: "hasCurrentVersionSignature",
|
|
24328
|
+
args: [user]
|
|
24329
|
+
});
|
|
24330
|
+
}
|
|
24331
|
+
async function getCurrentMessage(publicClient, signatureStore) {
|
|
24332
|
+
return await publicClient.readContract({
|
|
24333
|
+
address: signatureStore,
|
|
24334
|
+
abi: SignatureStoreABI,
|
|
24335
|
+
functionName: "getCurrentVersionMessage"
|
|
24336
|
+
});
|
|
24337
|
+
}
|
|
24338
|
+
|
|
24339
|
+
// src/actions/admin.ts
|
|
24340
|
+
var admin_exports = {};
|
|
24341
|
+
__export(admin_exports, {
|
|
24342
|
+
grantRole: () => grantRole,
|
|
24343
|
+
prepareGrantRole: () => prepareGrantRole,
|
|
24344
|
+
prepareRevokeRole: () => prepareRevokeRole,
|
|
24345
|
+
revokeRole: () => revokeRole
|
|
24346
|
+
});
|
|
24347
|
+
function prepareGrantRole(symmioDiamond, account, role, grantee) {
|
|
24348
|
+
validateAddress(grantee, "grantee");
|
|
24349
|
+
const data = viem.encodeFunctionData({
|
|
24350
|
+
abi: SymmioDiamondABI,
|
|
24351
|
+
functionName: "grantRole",
|
|
24352
|
+
args: [grantee, role]
|
|
24353
|
+
});
|
|
24354
|
+
return {
|
|
24355
|
+
functionName: "grantRole",
|
|
24356
|
+
args: [grantee, role],
|
|
24357
|
+
config: { account, to: symmioDiamond, data, value: 0n }
|
|
24358
|
+
};
|
|
24359
|
+
}
|
|
24360
|
+
function prepareRevokeRole(symmioDiamond, account, role, revokee) {
|
|
24361
|
+
validateAddress(revokee, "revokee");
|
|
24362
|
+
const data = viem.encodeFunctionData({
|
|
24363
|
+
abi: SymmioDiamondABI,
|
|
24364
|
+
functionName: "revokeRole",
|
|
24365
|
+
args: [revokee, role]
|
|
24366
|
+
});
|
|
24367
|
+
return {
|
|
24368
|
+
functionName: "revokeRole",
|
|
24369
|
+
args: [revokee, role],
|
|
24370
|
+
config: { account, to: symmioDiamond, data, value: 0n }
|
|
24371
|
+
};
|
|
24372
|
+
}
|
|
24373
|
+
async function grantRole(walletClient, publicClient, symmioDiamond, role, grantee) {
|
|
24374
|
+
const account = walletClient.account?.address;
|
|
24375
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24376
|
+
const prepared = prepareGrantRole(symmioDiamond, account, role, grantee);
|
|
24377
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
24378
|
+
return walletClient.sendTransaction({
|
|
24379
|
+
...prepared.config,
|
|
24380
|
+
gas: calculateGasMargin(gas),
|
|
24381
|
+
chain: walletClient.chain
|
|
24382
|
+
});
|
|
24383
|
+
}
|
|
24384
|
+
async function revokeRole(walletClient, publicClient, symmioDiamond, role, revokee) {
|
|
24385
|
+
const account = walletClient.account?.address;
|
|
24386
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
24387
|
+
const prepared = prepareRevokeRole(symmioDiamond, account, role, revokee);
|
|
24388
|
+
const gas = await publicClient.estimateGas(prepared.config);
|
|
24389
|
+
return walletClient.sendTransaction({
|
|
24390
|
+
...prepared.config,
|
|
24391
|
+
gas: calculateGasMargin(gas),
|
|
24392
|
+
chain: walletClient.chain
|
|
24393
|
+
});
|
|
24394
|
+
}
|
|
24395
|
+
|
|
24396
|
+
// src/actions/instant.ts
|
|
24397
|
+
var instant_exports = {};
|
|
24398
|
+
__export(instant_exports, {
|
|
24399
|
+
cancelInstantClose: () => cancelInstantClose,
|
|
24400
|
+
createSiweMessage: () => createSiweMessage,
|
|
24401
|
+
getNonce: () => getNonce,
|
|
24402
|
+
getOpenInstantCloses: () => getOpenInstantCloses,
|
|
24403
|
+
instantClose: () => instantClose,
|
|
24404
|
+
instantOpen: () => instantOpen,
|
|
24405
|
+
login: () => login
|
|
24406
|
+
});
|
|
24407
|
+
function getHedgerBaseUrl(chainId) {
|
|
24408
|
+
const baseUrl = HEDGER_BASE_URLS[chainId];
|
|
24409
|
+
if (!baseUrl) {
|
|
24410
|
+
throw new Error(`No hedger base URL configured for chain ${chainId}.`);
|
|
24897
24411
|
}
|
|
24898
|
-
|
|
24899
|
-
|
|
24900
|
-
|
|
24901
|
-
|
|
24902
|
-
|
|
24903
|
-
|
|
24904
|
-
|
|
24905
|
-
|
|
24906
|
-
|
|
24907
|
-
|
|
24908
|
-
|
|
24909
|
-
|
|
24910
|
-
|
|
24911
|
-
|
|
24912
|
-
|
|
24913
|
-
|
|
24914
|
-
|
|
24915
|
-
|
|
24916
|
-
|
|
24917
|
-
|
|
24918
|
-
|
|
24919
|
-
{
|
|
24920
|
-
|
|
24921
|
-
|
|
24922
|
-
|
|
24923
|
-
|
|
24924
|
-
|
|
24925
|
-
|
|
24926
|
-
|
|
24927
|
-
outputs: []
|
|
24928
|
-
},
|
|
24929
|
-
{
|
|
24930
|
-
name: "isValidKey",
|
|
24931
|
-
type: "function",
|
|
24932
|
-
stateMutability: "view",
|
|
24933
|
-
inputs: [{ name: "publicKey", type: "address" }],
|
|
24934
|
-
outputs: [{ name: "valid", type: "bool" }]
|
|
24935
|
-
},
|
|
24936
|
-
{
|
|
24937
|
-
name: "getActiveKeys",
|
|
24938
|
-
type: "function",
|
|
24939
|
-
stateMutability: "view",
|
|
24940
|
-
inputs: [],
|
|
24941
|
-
outputs: [{ name: "keys", type: "address[]" }]
|
|
24412
|
+
return baseUrl;
|
|
24413
|
+
}
|
|
24414
|
+
function createSiweMessage(params) {
|
|
24415
|
+
const version = params.version ?? "1";
|
|
24416
|
+
const issuedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
24417
|
+
const expirationTime = new Date(
|
|
24418
|
+
Date.now() + 30 * 24 * 60 * 60 * 1e3
|
|
24419
|
+
).toISOString();
|
|
24420
|
+
const message = [
|
|
24421
|
+
`${params.domain} wants you to sign in with your Ethereum account:`,
|
|
24422
|
+
params.address,
|
|
24423
|
+
"",
|
|
24424
|
+
params.statement,
|
|
24425
|
+
"",
|
|
24426
|
+
`URI: ${params.uri}`,
|
|
24427
|
+
`Version: ${version}`,
|
|
24428
|
+
`Chain ID: ${params.chainId}`,
|
|
24429
|
+
`Nonce: ${params.nonce}`,
|
|
24430
|
+
`Issued At: ${issuedAt}`,
|
|
24431
|
+
`Expiration Time: ${expirationTime}`
|
|
24432
|
+
].join("\n");
|
|
24433
|
+
return { message, issuedAt, expirationTime };
|
|
24434
|
+
}
|
|
24435
|
+
async function getNonce(chainId, subAccount) {
|
|
24436
|
+
const hedgerBaseUrl = getHedgerBaseUrl(chainId);
|
|
24437
|
+
const url = new URL(`nonce/${subAccount}`, hedgerBaseUrl).href;
|
|
24438
|
+
const response = await fetch(url);
|
|
24439
|
+
if (!response.ok) {
|
|
24440
|
+
throw new Error(`Failed to fetch nonce: ${response.statusText}`);
|
|
24942
24441
|
}
|
|
24943
|
-
|
|
24442
|
+
const data = await response.json();
|
|
24443
|
+
return data.nonce;
|
|
24444
|
+
}
|
|
24445
|
+
async function login(chainId, params) {
|
|
24446
|
+
const hedgerBaseUrl = getHedgerBaseUrl(chainId);
|
|
24447
|
+
const url = new URL("login", hedgerBaseUrl).href;
|
|
24448
|
+
const body = {
|
|
24449
|
+
account_address: params.accountAddress,
|
|
24450
|
+
expiration_time: params.expirationTime,
|
|
24451
|
+
issued_at: params.issuedAt,
|
|
24452
|
+
signature: params.signature,
|
|
24453
|
+
nonce: params.nonce
|
|
24454
|
+
};
|
|
24455
|
+
const response = await fetch(url, {
|
|
24456
|
+
method: "POST",
|
|
24457
|
+
headers: { "Content-Type": "application/json" },
|
|
24458
|
+
body: JSON.stringify(body)
|
|
24459
|
+
});
|
|
24460
|
+
if (!response.ok) {
|
|
24461
|
+
const errorData = await response.json().catch(() => null);
|
|
24462
|
+
throw new Error(
|
|
24463
|
+
errorData?.error_message ?? `Login failed: ${response.statusText}`
|
|
24464
|
+
);
|
|
24465
|
+
}
|
|
24466
|
+
const data = await response.json();
|
|
24467
|
+
if (!data.access_token) {
|
|
24468
|
+
throw new Error("No access token received");
|
|
24469
|
+
}
|
|
24470
|
+
return {
|
|
24471
|
+
accessToken: data.access_token,
|
|
24472
|
+
expirationTime: params.expirationTime,
|
|
24473
|
+
issuedAt: params.issuedAt
|
|
24474
|
+
};
|
|
24475
|
+
}
|
|
24476
|
+
async function instantOpen(chainId, params, accessToken) {
|
|
24477
|
+
const hedgerBaseUrl = getHedgerBaseUrl(chainId);
|
|
24478
|
+
const url = new URL("instant_open", hedgerBaseUrl).href;
|
|
24479
|
+
const body = {
|
|
24480
|
+
symbolId: params.symbolId,
|
|
24481
|
+
positionType: params.positionType,
|
|
24482
|
+
orderType: params.orderType,
|
|
24483
|
+
price: params.price,
|
|
24484
|
+
quantity: params.quantity,
|
|
24485
|
+
cva: params.cva,
|
|
24486
|
+
lf: params.lf,
|
|
24487
|
+
partyAmm: params.partyAmm,
|
|
24488
|
+
partyBmm: params.partyBmm,
|
|
24489
|
+
maxFundingRate: params.maxFundingRate,
|
|
24490
|
+
deadline: params.deadline
|
|
24491
|
+
};
|
|
24492
|
+
const response = await fetch(url, {
|
|
24493
|
+
method: "POST",
|
|
24494
|
+
headers: {
|
|
24495
|
+
"Content-Type": "application/json",
|
|
24496
|
+
Authorization: `Bearer ${accessToken}`
|
|
24497
|
+
},
|
|
24498
|
+
body: JSON.stringify(body)
|
|
24499
|
+
});
|
|
24500
|
+
if (!response.ok) {
|
|
24501
|
+
const errorData = await response.json().catch(() => null);
|
|
24502
|
+
throw new Error(
|
|
24503
|
+
errorData?.error_message ?? `Instant open failed: ${response.statusText}`
|
|
24504
|
+
);
|
|
24505
|
+
}
|
|
24506
|
+
return response.json();
|
|
24507
|
+
}
|
|
24508
|
+
async function instantClose(chainId, params, accessToken) {
|
|
24509
|
+
const hedgerBaseUrl = getHedgerBaseUrl(chainId);
|
|
24510
|
+
const url = new URL("instant_close", hedgerBaseUrl).href;
|
|
24511
|
+
const body = {
|
|
24512
|
+
quote_id: params.quoteId,
|
|
24513
|
+
quantity_to_close: params.quantityToClose,
|
|
24514
|
+
close_price: params.closePrice
|
|
24515
|
+
};
|
|
24516
|
+
const response = await fetch(url, {
|
|
24517
|
+
method: "POST",
|
|
24518
|
+
headers: {
|
|
24519
|
+
"Content-Type": "application/json",
|
|
24520
|
+
Authorization: `Bearer ${accessToken}`
|
|
24521
|
+
},
|
|
24522
|
+
body: JSON.stringify(body)
|
|
24523
|
+
});
|
|
24524
|
+
if (!response.ok) {
|
|
24525
|
+
const errorData = await response.json().catch(() => null);
|
|
24526
|
+
throw new Error(
|
|
24527
|
+
errorData?.error_message ?? `Instant close failed: ${response.statusText}`
|
|
24528
|
+
);
|
|
24529
|
+
}
|
|
24530
|
+
return response.json();
|
|
24531
|
+
}
|
|
24532
|
+
async function cancelInstantClose(chainId, quoteId, accessToken) {
|
|
24533
|
+
const hedgerBaseUrl = getHedgerBaseUrl(chainId);
|
|
24534
|
+
const url = new URL(`instant_close/${quoteId}`, hedgerBaseUrl).href;
|
|
24535
|
+
const response = await fetch(url, {
|
|
24536
|
+
method: "DELETE",
|
|
24537
|
+
headers: {
|
|
24538
|
+
"Content-Type": "application/json",
|
|
24539
|
+
Authorization: `Bearer ${accessToken}`
|
|
24540
|
+
}
|
|
24541
|
+
});
|
|
24542
|
+
if (!response.ok) {
|
|
24543
|
+
const errorData = await response.json().catch(() => null);
|
|
24544
|
+
throw new Error(
|
|
24545
|
+
errorData?.error_message ?? `Cancel instant close failed: ${response.statusText}`
|
|
24546
|
+
);
|
|
24547
|
+
}
|
|
24548
|
+
}
|
|
24549
|
+
async function getOpenInstantCloses(chainId, account, accessToken) {
|
|
24550
|
+
const hedgerBaseUrl = getHedgerBaseUrl(chainId);
|
|
24551
|
+
const url = new URL(`instant_close/${account}`, hedgerBaseUrl).href;
|
|
24552
|
+
const response = await fetch(url, {
|
|
24553
|
+
headers: {
|
|
24554
|
+
Authorization: `Bearer ${accessToken}`
|
|
24555
|
+
}
|
|
24556
|
+
});
|
|
24557
|
+
if (!response.ok) {
|
|
24558
|
+
const errorData = await response.json().catch(() => null);
|
|
24559
|
+
throw new Error(
|
|
24560
|
+
errorData?.error_message ?? `Failed to fetch instant closes: ${response.statusText}`
|
|
24561
|
+
);
|
|
24562
|
+
}
|
|
24563
|
+
return response.json();
|
|
24564
|
+
}
|
|
24944
24565
|
|
|
24945
|
-
// src/
|
|
24946
|
-
var
|
|
24947
|
-
|
|
24948
|
-
|
|
24949
|
-
|
|
24950
|
-
|
|
24951
|
-
|
|
24566
|
+
// src/actions/stats.ts
|
|
24567
|
+
var stats_exports = {};
|
|
24568
|
+
__export(stats_exports, {
|
|
24569
|
+
calculateAvailableForOrder: () => calculateAvailableForOrder,
|
|
24570
|
+
getPartyAStats: () => getPartyAStats
|
|
24571
|
+
});
|
|
24572
|
+
async function getPartyAStats(publicClient, symmioDiamond, partyA) {
|
|
24573
|
+
const result = await publicClient.readContract({
|
|
24574
|
+
address: symmioDiamond,
|
|
24575
|
+
abi: SymmioDiamondABI,
|
|
24576
|
+
functionName: "partyAStats",
|
|
24577
|
+
args: [partyA]
|
|
24578
|
+
});
|
|
24579
|
+
return {
|
|
24580
|
+
collateralBalance: result[1],
|
|
24581
|
+
allocatedBalance: result[2],
|
|
24582
|
+
availableBalance: result[3],
|
|
24583
|
+
lockedCVA: result[4],
|
|
24584
|
+
lockedLF: result[5],
|
|
24585
|
+
lockedPartyAMM: result[6],
|
|
24586
|
+
lockedPartyBMM: result[7],
|
|
24587
|
+
pendingLockedCVA: result[8],
|
|
24588
|
+
pendingLockedLF: result[9],
|
|
24589
|
+
pendingLockedPartyAMM: result[10],
|
|
24590
|
+
pendingLockedPartyBMM: result[11],
|
|
24591
|
+
positionsCount: Number(result[12]),
|
|
24592
|
+
pendingCount: Number(result[13]),
|
|
24593
|
+
nonces: 0
|
|
24594
|
+
};
|
|
24595
|
+
}
|
|
24596
|
+
function calculateAvailableForOrder(stats, upnl) {
|
|
24597
|
+
const {
|
|
24598
|
+
allocatedBalance,
|
|
24599
|
+
lockedCVA,
|
|
24600
|
+
lockedLF,
|
|
24601
|
+
lockedPartyAMM,
|
|
24602
|
+
pendingLockedCVA,
|
|
24603
|
+
pendingLockedLF,
|
|
24604
|
+
pendingLockedPartyAMM
|
|
24605
|
+
} = stats;
|
|
24606
|
+
const totalPendingLocked = pendingLockedCVA + pendingLockedLF + pendingLockedPartyAMM;
|
|
24607
|
+
if (upnl >= 0n) {
|
|
24608
|
+
const totalLocked = lockedCVA + lockedLF + lockedPartyAMM;
|
|
24609
|
+
return allocatedBalance + upnl - totalLocked - totalPendingLocked;
|
|
24610
|
+
}
|
|
24611
|
+
const absUpnl = -upnl;
|
|
24612
|
+
const consideringMm = absUpnl > lockedPartyAMM ? absUpnl : lockedPartyAMM;
|
|
24613
|
+
return allocatedBalance - lockedCVA - lockedLF - totalPendingLocked - consideringMm;
|
|
24614
|
+
}
|
|
24952
24615
|
|
|
24953
24616
|
// src/utils/formatting.ts
|
|
24954
24617
|
function toWei(amount, decimals) {
|
|
@@ -25018,7 +24681,6 @@ exports.SignatureStoreABI = SignatureStoreABI;
|
|
|
25018
24681
|
exports.SoftLiquidationLevel = SoftLiquidationLevel;
|
|
25019
24682
|
exports.SupportedChainId = SupportedChainId;
|
|
25020
24683
|
exports.SymmioDiamondABI = SymmioDiamondABI;
|
|
25021
|
-
exports.SymmioSDK = SymmioSDK;
|
|
25022
24684
|
exports.SymmioSDKError = SymmioSDKError;
|
|
25023
24685
|
exports.V3_CHAIN_IDS = V3_CHAIN_IDS;
|
|
25024
24686
|
exports.accountActions = account_exports;
|