@relay-protocol/settlement-sdk 0.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/hub/hub-utils.d.ts +29 -0
- package/dist/hub/hub-utils.js +35 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +45 -0
- package/dist/messages/common/solana-vm/idls/RelayDepositoryIdl.d.ts +383 -0
- package/dist/messages/common/solana-vm/idls/RelayDepositoryIdl.js +901 -0
- package/dist/messages/v2.1/depository-deposit.d.ts +16 -0
- package/dist/messages/v2.1/depository-deposit.js +44 -0
- package/dist/messages/v2.1/depository-withdrawal.d.ts +103 -0
- package/dist/messages/v2.1/depository-withdrawal.js +661 -0
- package/dist/messages/v2.1/solver-fill.d.ts +26 -0
- package/dist/messages/v2.1/solver-fill.js +61 -0
- package/dist/messages/v2.1/solver-refund.d.ts +28 -0
- package/dist/messages/v2.1/solver-refund.js +67 -0
- package/dist/messages/v2.2/execution.d.ts +48 -0
- package/dist/messages/v2.2/execution.js +135 -0
- package/dist/messages/v2.2/withdrawal-execution.d.ts +55 -0
- package/dist/messages/v2.2/withdrawal-execution.js +71 -0
- package/dist/order/index.d.ts +140 -0
- package/dist/order/index.js +230 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +255 -0
- package/package.json +39 -0
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getDecodedWithdrawalRecipient = exports.getDecodedWithdrawalAmount = exports.getDecodedWithdrawalCurrency = exports.getDecodedWithdrawalId = exports.decodeWithdrawal = exports.encodeWithdrawal = exports.getDepositoryWithdrawalMessageId = exports.DepositoryWithdrawalStatus = void 0;
|
|
37
|
+
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
38
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
39
|
+
const bcs_1 = require("@mysten/sui/bcs");
|
|
40
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
41
|
+
const js_sha256_1 = require("js-sha256");
|
|
42
|
+
const tronweb = __importStar(require("tronweb"));
|
|
43
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
44
|
+
const viem_1 = require("viem");
|
|
45
|
+
const utils_1 = require("../../utils");
|
|
46
|
+
const RelayDepositoryIdl_1 = require("../common/solana-vm/idls/RelayDepositoryIdl");
|
|
47
|
+
var DepositoryWithdrawalStatus;
|
|
48
|
+
(function (DepositoryWithdrawalStatus) {
|
|
49
|
+
DepositoryWithdrawalStatus[DepositoryWithdrawalStatus["PENDING"] = 0] = "PENDING";
|
|
50
|
+
DepositoryWithdrawalStatus[DepositoryWithdrawalStatus["EXECUTED"] = 1] = "EXECUTED";
|
|
51
|
+
DepositoryWithdrawalStatus[DepositoryWithdrawalStatus["EXPIRED"] = 2] = "EXPIRED";
|
|
52
|
+
})(DepositoryWithdrawalStatus || (exports.DepositoryWithdrawalStatus = DepositoryWithdrawalStatus = {}));
|
|
53
|
+
const getDepositoryWithdrawalMessageId = (message, chainsConfig) => {
|
|
54
|
+
const vmType = (chainId) => (0, utils_1.getChainVmType)(chainId, chainsConfig);
|
|
55
|
+
return (0, viem_1.hashStruct)({
|
|
56
|
+
types: {
|
|
57
|
+
DepositoryWithdrawal: [
|
|
58
|
+
{ name: "data", type: "Data" },
|
|
59
|
+
{ name: "result", type: "Result" },
|
|
60
|
+
],
|
|
61
|
+
Data: [
|
|
62
|
+
{ name: "chainId", type: "string" },
|
|
63
|
+
{ name: "withdrawal", type: "bytes" },
|
|
64
|
+
],
|
|
65
|
+
Result: [
|
|
66
|
+
{ name: "withdrawalId", type: "bytes32" },
|
|
67
|
+
{ name: "depository", type: "bytes" },
|
|
68
|
+
{ name: "status", type: "uint8" },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
primaryType: "DepositoryWithdrawal",
|
|
72
|
+
data: {
|
|
73
|
+
data: {
|
|
74
|
+
chainId: message.data.chainId,
|
|
75
|
+
withdrawal: (0, utils_1.encodeBytes)(message.data.withdrawal),
|
|
76
|
+
},
|
|
77
|
+
result: {
|
|
78
|
+
withdrawalId: (0, viem_1.bytesToHex)((0, utils_1.encodeBytes)(message.result.withdrawalId)),
|
|
79
|
+
depository: (0, utils_1.encodeAddress)(message.result.depository, vmType(message.data.chainId)),
|
|
80
|
+
status: message.result.status,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
exports.getDepositoryWithdrawalMessageId = getDepositoryWithdrawalMessageId;
|
|
86
|
+
const encodeWithdrawal = (decodedWithdrawal) => {
|
|
87
|
+
switch (decodedWithdrawal.vmType) {
|
|
88
|
+
case "ethereum-vm": {
|
|
89
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
90
|
+
"((address to, bytes data, uint256 value, bool allowFailure)[] calls, uint256 nonce, uint256 expiration)",
|
|
91
|
+
]), [
|
|
92
|
+
{
|
|
93
|
+
calls: decodedWithdrawal.withdrawal.calls.map((call) => ({
|
|
94
|
+
to: call.to,
|
|
95
|
+
data: call.data,
|
|
96
|
+
value: BigInt(call.value),
|
|
97
|
+
allowFailure: call.allowFailure,
|
|
98
|
+
})),
|
|
99
|
+
nonce: BigInt(decodedWithdrawal.withdrawal.nonce),
|
|
100
|
+
expiration: BigInt(decodedWithdrawal.withdrawal.expiration),
|
|
101
|
+
},
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
case "tron-vm": {
|
|
105
|
+
const callsArray = decodedWithdrawal.withdrawal.calls.map((c) => [
|
|
106
|
+
c.to.replace(tronweb.utils.address.ADDRESS_PREFIX_REGEX, "0x"),
|
|
107
|
+
c.data,
|
|
108
|
+
BigInt(c.value),
|
|
109
|
+
Boolean(c.allowFailure),
|
|
110
|
+
]);
|
|
111
|
+
const types = [
|
|
112
|
+
"tuple(tuple(address,bytes,uint256,bool)[],uint256,uint256)",
|
|
113
|
+
];
|
|
114
|
+
const values = [
|
|
115
|
+
[
|
|
116
|
+
callsArray,
|
|
117
|
+
BigInt(decodedWithdrawal.withdrawal.nonce),
|
|
118
|
+
BigInt(decodedWithdrawal.withdrawal.expiration),
|
|
119
|
+
],
|
|
120
|
+
];
|
|
121
|
+
return tronweb.utils.abi.encodeParams(types, values);
|
|
122
|
+
}
|
|
123
|
+
case "solana-vm": {
|
|
124
|
+
const coder = new anchor_1.BorshCoder(RelayDepositoryIdl_1.RelayDepositoryIdl);
|
|
125
|
+
return ("0x" +
|
|
126
|
+
coder.types
|
|
127
|
+
.encode("TransferRequest", {
|
|
128
|
+
domain: Buffer.from(decodedWithdrawal.withdrawal.domain.slice(2), "hex"),
|
|
129
|
+
recipient: new web3_js_1.PublicKey(decodedWithdrawal.withdrawal.recipient),
|
|
130
|
+
token: decodedWithdrawal.withdrawal.token ===
|
|
131
|
+
web3_js_1.SystemProgram.programId.toBase58()
|
|
132
|
+
? null
|
|
133
|
+
: new web3_js_1.PublicKey(decodedWithdrawal.withdrawal.token),
|
|
134
|
+
amount: new anchor.BN(decodedWithdrawal.withdrawal.amount),
|
|
135
|
+
nonce: new anchor.BN(decodedWithdrawal.withdrawal.nonce),
|
|
136
|
+
expiration: new anchor.BN(decodedWithdrawal.withdrawal.expiration),
|
|
137
|
+
vault_address: new web3_js_1.PublicKey(decodedWithdrawal.withdrawal.vaultAddress),
|
|
138
|
+
})
|
|
139
|
+
.toString("hex"));
|
|
140
|
+
}
|
|
141
|
+
case "sui-vm": {
|
|
142
|
+
return ("0x" +
|
|
143
|
+
Buffer.from(bcs_1.bcs
|
|
144
|
+
.struct("TransferRequest", {
|
|
145
|
+
recipient: bcs_1.bcs.Address,
|
|
146
|
+
amount: bcs_1.bcs.u64(),
|
|
147
|
+
coin_type: bcs_1.bcs.struct("TypeName", {
|
|
148
|
+
name: bcs_1.bcs.string(),
|
|
149
|
+
}),
|
|
150
|
+
nonce: bcs_1.bcs.u64(),
|
|
151
|
+
expiration: bcs_1.bcs.u64(),
|
|
152
|
+
})
|
|
153
|
+
.serialize({
|
|
154
|
+
recipient: decodedWithdrawal.withdrawal.recipient,
|
|
155
|
+
amount: BigInt(decodedWithdrawal.withdrawal.amount),
|
|
156
|
+
coin_type: {
|
|
157
|
+
name: decodedWithdrawal.withdrawal.coinType,
|
|
158
|
+
},
|
|
159
|
+
nonce: BigInt(decodedWithdrawal.withdrawal.nonce),
|
|
160
|
+
expiration: BigInt(decodedWithdrawal.withdrawal.expiration),
|
|
161
|
+
})
|
|
162
|
+
.toBytes()).toString("hex"));
|
|
163
|
+
}
|
|
164
|
+
case "bitcoin-vm": {
|
|
165
|
+
return "0x" + decodedWithdrawal.withdrawal.psbt;
|
|
166
|
+
}
|
|
167
|
+
case "hyperliquid-vm": {
|
|
168
|
+
const { txType, parameters } = decodedWithdrawal.withdrawal;
|
|
169
|
+
let encodedParameters;
|
|
170
|
+
switch (parameters.type) {
|
|
171
|
+
case "UsdSend": {
|
|
172
|
+
encodedParameters = (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
173
|
+
"(string hyperliquidChain, string destination, string amount, uint64 time)",
|
|
174
|
+
]), [
|
|
175
|
+
{
|
|
176
|
+
hyperliquidChain: parameters.hyperliquidChain,
|
|
177
|
+
destination: parameters.destination,
|
|
178
|
+
amount: parameters.amount,
|
|
179
|
+
time: BigInt(parameters.time),
|
|
180
|
+
},
|
|
181
|
+
]);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case "SendAsset": {
|
|
185
|
+
encodedParameters = (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
186
|
+
"(string hyperliquidChain, string destination, string sourceDex, string destinationDex, string token, string amount, string fromSubAccount, uint64 nonce)",
|
|
187
|
+
]), [
|
|
188
|
+
{
|
|
189
|
+
hyperliquidChain: parameters.hyperliquidChain,
|
|
190
|
+
destination: parameters.destination,
|
|
191
|
+
sourceDex: parameters.sourceDex,
|
|
192
|
+
destinationDex: parameters.destinationDex,
|
|
193
|
+
token: parameters.token,
|
|
194
|
+
amount: parameters.amount,
|
|
195
|
+
fromSubAccount: parameters.fromSubAccount,
|
|
196
|
+
nonce: BigInt(parameters.nonce),
|
|
197
|
+
},
|
|
198
|
+
]);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
default: {
|
|
202
|
+
throw new Error(`Unsupported Hyperliquid transaction type ${parameters.type}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)(["(uint8 txType, bytes parameters)"]), [
|
|
206
|
+
{
|
|
207
|
+
txType,
|
|
208
|
+
parameters: encodedParameters,
|
|
209
|
+
},
|
|
210
|
+
]);
|
|
211
|
+
}
|
|
212
|
+
default:
|
|
213
|
+
throw new Error("Unsupported vm type");
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
exports.encodeWithdrawal = encodeWithdrawal;
|
|
217
|
+
const decodeWithdrawal = (encodedWithdrawal, vmType) => {
|
|
218
|
+
switch (vmType) {
|
|
219
|
+
case "ethereum-vm": {
|
|
220
|
+
const result = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
221
|
+
"((address to, bytes data, uint256 value, bool allowFailure)[] calls, uint256 nonce, uint256 expiration)",
|
|
222
|
+
]), encodedWithdrawal);
|
|
223
|
+
return {
|
|
224
|
+
vmType: "ethereum-vm",
|
|
225
|
+
withdrawal: {
|
|
226
|
+
calls: result[0].calls.map((call) => ({
|
|
227
|
+
to: call.to.toLowerCase(),
|
|
228
|
+
data: call.data.toLowerCase(),
|
|
229
|
+
value: call.value.toString(),
|
|
230
|
+
allowFailure: call.allowFailure,
|
|
231
|
+
})),
|
|
232
|
+
nonce: result[0].nonce.toString(),
|
|
233
|
+
expiration: Number(result[0].expiration.toString()),
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
case "tron-vm": {
|
|
238
|
+
const types = [
|
|
239
|
+
"tuple(tuple(address,bytes,uint256,bool)[],uint256,uint256)",
|
|
240
|
+
];
|
|
241
|
+
const decoded = tronweb.utils.abi.decodeParams([], types, encodedWithdrawal);
|
|
242
|
+
const [argTuple] = decoded;
|
|
243
|
+
const [decodedCalls, decodedNonce, decodedExpiration] = argTuple;
|
|
244
|
+
return {
|
|
245
|
+
vmType: "tron-vm",
|
|
246
|
+
withdrawal: {
|
|
247
|
+
calls: decodedCalls.map(([to, data, value, allowFailure]) => ({
|
|
248
|
+
to: to
|
|
249
|
+
.toLowerCase()
|
|
250
|
+
.replace("0x", tronweb.utils.address.ADDRESS_PREFIX),
|
|
251
|
+
data: data.toLowerCase(),
|
|
252
|
+
value: BigInt(value).toString(),
|
|
253
|
+
allowFailure: Boolean(allowFailure),
|
|
254
|
+
})),
|
|
255
|
+
nonce: BigInt(decodedNonce).toString(),
|
|
256
|
+
expiration: Number(BigInt(decodedExpiration).toString()),
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
case "solana-vm": {
|
|
261
|
+
const buffer = Buffer.from(encodedWithdrawal.substring(2), "hex");
|
|
262
|
+
const coder = new anchor_1.BorshCoder(RelayDepositoryIdl_1.RelayDepositoryIdl);
|
|
263
|
+
const request = coder.types.decode("TransferRequest", buffer);
|
|
264
|
+
return {
|
|
265
|
+
vmType: "solana-vm",
|
|
266
|
+
withdrawal: {
|
|
267
|
+
domain: "0x" + Buffer.from(request.domain).toString("hex"),
|
|
268
|
+
recipient: request.recipient.toBase58(),
|
|
269
|
+
token: request.token
|
|
270
|
+
? request.token.toBase58()
|
|
271
|
+
: web3_js_1.SystemProgram.programId.toBase58(),
|
|
272
|
+
amount: request.amount.toString(),
|
|
273
|
+
nonce: request.nonce.toString(),
|
|
274
|
+
expiration: request.expiration.toNumber(),
|
|
275
|
+
vaultAddress: request.vault_address.toBase58(),
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
case "sui-vm": {
|
|
280
|
+
const buffer = Uint8Array.from(Buffer.from(encodedWithdrawal.substring(2), "hex"));
|
|
281
|
+
const request = bcs_1.bcs
|
|
282
|
+
.struct("TransferRequest", {
|
|
283
|
+
recipient: bcs_1.bcs.Address,
|
|
284
|
+
amount: bcs_1.bcs.u64(),
|
|
285
|
+
coin_type: bcs_1.bcs.struct("TypeName", {
|
|
286
|
+
name: bcs_1.bcs.string(),
|
|
287
|
+
}),
|
|
288
|
+
nonce: bcs_1.bcs.u64(),
|
|
289
|
+
expiration: bcs_1.bcs.u64(),
|
|
290
|
+
})
|
|
291
|
+
.parse(buffer);
|
|
292
|
+
return {
|
|
293
|
+
vmType: "sui-vm",
|
|
294
|
+
withdrawal: {
|
|
295
|
+
recipient: request.recipient,
|
|
296
|
+
coinType: request.coin_type.name,
|
|
297
|
+
amount: request.amount.toString(),
|
|
298
|
+
nonce: request.nonce.toString(),
|
|
299
|
+
expiration: Number(request.expiration.toString()),
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
case "bitcoin-vm": {
|
|
304
|
+
return {
|
|
305
|
+
vmType: "bitcoin-vm",
|
|
306
|
+
withdrawal: {
|
|
307
|
+
psbt: encodedWithdrawal.slice(2),
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
case "hyperliquid-vm": {
|
|
312
|
+
const result = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)(["(uint8 txType, bytes parameters)"]), encodedWithdrawal);
|
|
313
|
+
const { txType, parameters } = result[0];
|
|
314
|
+
switch (txType) {
|
|
315
|
+
case 0: {
|
|
316
|
+
// UsdSend
|
|
317
|
+
const paramResult = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
318
|
+
"(string hyperliquidChain, string destination, string amount, uint64 time)",
|
|
319
|
+
]), parameters);
|
|
320
|
+
const { hyperliquidChain, destination, amount, time } = paramResult[0];
|
|
321
|
+
return {
|
|
322
|
+
vmType: "hyperliquid-vm",
|
|
323
|
+
withdrawal: {
|
|
324
|
+
txType: Number(txType),
|
|
325
|
+
parameters: {
|
|
326
|
+
type: "UsdSend",
|
|
327
|
+
hyperliquidChain,
|
|
328
|
+
destination,
|
|
329
|
+
amount,
|
|
330
|
+
time: time.toString(),
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
case 1: {
|
|
336
|
+
// SendAsset
|
|
337
|
+
const paramResult = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
338
|
+
"(string hyperliquidChain, string destination, string sourceDex, string destinationDex, string token, string amount, string fromSubAccount, uint64 nonce)",
|
|
339
|
+
]), parameters);
|
|
340
|
+
const { hyperliquidChain, destination, sourceDex, destinationDex, token, amount, fromSubAccount, nonce, } = paramResult[0];
|
|
341
|
+
return {
|
|
342
|
+
vmType: "hyperliquid-vm",
|
|
343
|
+
withdrawal: {
|
|
344
|
+
txType: Number(txType),
|
|
345
|
+
parameters: {
|
|
346
|
+
type: "SendAsset",
|
|
347
|
+
hyperliquidChain,
|
|
348
|
+
destination,
|
|
349
|
+
sourceDex,
|
|
350
|
+
destinationDex,
|
|
351
|
+
token,
|
|
352
|
+
amount,
|
|
353
|
+
fromSubAccount,
|
|
354
|
+
nonce: nonce.toString(),
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
default: {
|
|
360
|
+
throw new Error(`Unsupported Hyperliquid transaction type: ${txType}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
default:
|
|
365
|
+
throw new Error("Unsupported vm type");
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
exports.decodeWithdrawal = decodeWithdrawal;
|
|
369
|
+
const getDecodedWithdrawalId = (decodedWithdrawal) => {
|
|
370
|
+
switch (decodedWithdrawal.vmType) {
|
|
371
|
+
case "ethereum-vm": {
|
|
372
|
+
return (0, viem_1.hashStruct)({
|
|
373
|
+
types: {
|
|
374
|
+
CallRequest: [
|
|
375
|
+
{ name: "calls", type: "Call[]" },
|
|
376
|
+
{ name: "nonce", type: "uint256" },
|
|
377
|
+
{ name: "expiration", type: "uint256" },
|
|
378
|
+
],
|
|
379
|
+
Call: [
|
|
380
|
+
{ name: "to", type: "address" },
|
|
381
|
+
{ name: "data", type: "bytes" },
|
|
382
|
+
{ name: "value", type: "uint256" },
|
|
383
|
+
{ name: "allowFailure", type: "bool" },
|
|
384
|
+
],
|
|
385
|
+
},
|
|
386
|
+
primaryType: "CallRequest",
|
|
387
|
+
data: {
|
|
388
|
+
calls: decodedWithdrawal.withdrawal.calls,
|
|
389
|
+
nonce: decodedWithdrawal.withdrawal.nonce,
|
|
390
|
+
expiration: decodedWithdrawal.withdrawal.expiration,
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
case "tron-vm": {
|
|
395
|
+
return tronweb.utils._TypedDataEncoder.hashStruct("CallRequest", {
|
|
396
|
+
CallRequest: [
|
|
397
|
+
{ name: "calls", type: "Call[]" },
|
|
398
|
+
{ name: "nonce", type: "uint256" },
|
|
399
|
+
{ name: "expiration", type: "uint256" },
|
|
400
|
+
],
|
|
401
|
+
Call: [
|
|
402
|
+
{ name: "to", type: "address" },
|
|
403
|
+
{ name: "data", type: "bytes" },
|
|
404
|
+
{ name: "value", type: "uint256" },
|
|
405
|
+
{ name: "allowFailure", type: "bool" },
|
|
406
|
+
],
|
|
407
|
+
}, {
|
|
408
|
+
calls: decodedWithdrawal.withdrawal.calls,
|
|
409
|
+
nonce: decodedWithdrawal.withdrawal.nonce,
|
|
410
|
+
expiration: decodedWithdrawal.withdrawal.expiration,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
case "solana-vm": {
|
|
414
|
+
const coder = new anchor_1.BorshCoder(RelayDepositoryIdl_1.RelayDepositoryIdl);
|
|
415
|
+
const encodedWithdrawal = coder.types.encode("TransferRequest", {
|
|
416
|
+
domain: Buffer.from(decodedWithdrawal.withdrawal.domain.slice(2), "hex"),
|
|
417
|
+
recipient: new web3_js_1.PublicKey(decodedWithdrawal.withdrawal.recipient),
|
|
418
|
+
token: decodedWithdrawal.withdrawal.token ===
|
|
419
|
+
web3_js_1.SystemProgram.programId.toBase58()
|
|
420
|
+
? null
|
|
421
|
+
: new web3_js_1.PublicKey(decodedWithdrawal.withdrawal.token),
|
|
422
|
+
amount: new anchor.BN(decodedWithdrawal.withdrawal.amount),
|
|
423
|
+
nonce: new anchor.BN(decodedWithdrawal.withdrawal.nonce),
|
|
424
|
+
expiration: new anchor.BN(decodedWithdrawal.withdrawal.expiration),
|
|
425
|
+
vault_address: new web3_js_1.PublicKey(decodedWithdrawal.withdrawal.vaultAddress),
|
|
426
|
+
});
|
|
427
|
+
return ("0x" +
|
|
428
|
+
Buffer.from(js_sha256_1.sha256.create().update(encodedWithdrawal).array()).toString("hex"));
|
|
429
|
+
}
|
|
430
|
+
case "sui-vm": {
|
|
431
|
+
const encodedWithdrawal = "0x" +
|
|
432
|
+
Buffer.from(bcs_1.bcs
|
|
433
|
+
.struct("TransferRequest", {
|
|
434
|
+
recipient: bcs_1.bcs.Address,
|
|
435
|
+
amount: bcs_1.bcs.u64(),
|
|
436
|
+
coin_type: bcs_1.bcs.struct("TypeName", {
|
|
437
|
+
name: bcs_1.bcs.string(),
|
|
438
|
+
}),
|
|
439
|
+
nonce: bcs_1.bcs.u64(),
|
|
440
|
+
expiration: bcs_1.bcs.u64(),
|
|
441
|
+
})
|
|
442
|
+
.serialize({
|
|
443
|
+
recipient: decodedWithdrawal.withdrawal.recipient,
|
|
444
|
+
amount: BigInt(decodedWithdrawal.withdrawal.amount),
|
|
445
|
+
coin_type: {
|
|
446
|
+
name: decodedWithdrawal.withdrawal.coinType,
|
|
447
|
+
},
|
|
448
|
+
nonce: BigInt(decodedWithdrawal.withdrawal.nonce),
|
|
449
|
+
expiration: BigInt(decodedWithdrawal.withdrawal.expiration),
|
|
450
|
+
})
|
|
451
|
+
.toBytes()).toString("hex");
|
|
452
|
+
return "0x" + js_sha256_1.sha256.create().update(encodedWithdrawal).hex();
|
|
453
|
+
}
|
|
454
|
+
case "bitcoin-vm": {
|
|
455
|
+
const encodedWithdrawal = "0x" + decodedWithdrawal.withdrawal.psbt;
|
|
456
|
+
return "0x" + js_sha256_1.sha256.create().update(encodedWithdrawal).hex();
|
|
457
|
+
}
|
|
458
|
+
case "hyperliquid-vm": {
|
|
459
|
+
const { parameters } = decodedWithdrawal.withdrawal;
|
|
460
|
+
switch (parameters.type) {
|
|
461
|
+
case "UsdSend": {
|
|
462
|
+
return (0, viem_1.hashStruct)({
|
|
463
|
+
types: {
|
|
464
|
+
"HyperliquidTransaction:UsdSend": [
|
|
465
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
466
|
+
{ name: "destination", type: "string" },
|
|
467
|
+
{ name: "amount", type: "string" },
|
|
468
|
+
{ name: "time", type: "uint64" },
|
|
469
|
+
],
|
|
470
|
+
},
|
|
471
|
+
primaryType: "HyperliquidTransaction:UsdSend",
|
|
472
|
+
data: {
|
|
473
|
+
hyperliquidChain: parameters.hyperliquidChain,
|
|
474
|
+
destination: parameters.destination,
|
|
475
|
+
amount: parameters.amount,
|
|
476
|
+
time: parameters.time,
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
case "SendAsset": {
|
|
481
|
+
return (0, viem_1.hashStruct)({
|
|
482
|
+
types: {
|
|
483
|
+
"HyperliquidTransaction:SendAsset": [
|
|
484
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
485
|
+
{ name: "destination", type: "string" },
|
|
486
|
+
{ name: "sourceDex", type: "string" },
|
|
487
|
+
{ name: "destinationDex", type: "string" },
|
|
488
|
+
{ name: "token", type: "string" },
|
|
489
|
+
{ name: "amount", type: "string" },
|
|
490
|
+
{ name: "fromSubAccount", type: "string" },
|
|
491
|
+
{ name: "nonce", type: "uint64" },
|
|
492
|
+
],
|
|
493
|
+
},
|
|
494
|
+
primaryType: "HyperliquidTransaction:SendAsset",
|
|
495
|
+
data: {
|
|
496
|
+
hyperliquidChain: parameters.hyperliquidChain,
|
|
497
|
+
destination: parameters.destination,
|
|
498
|
+
sourceDex: parameters.sourceDex,
|
|
499
|
+
destinationDex: parameters.destinationDex,
|
|
500
|
+
token: parameters.token,
|
|
501
|
+
amount: parameters.amount,
|
|
502
|
+
fromSubAccount: parameters.fromSubAccount,
|
|
503
|
+
nonce: parameters.nonce,
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
default: {
|
|
508
|
+
throw new Error(`Unsupported Hyperliquid transaction type ${parameters.type}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
default:
|
|
513
|
+
throw new Error("Unsupported vm type");
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
exports.getDecodedWithdrawalId = getDecodedWithdrawalId;
|
|
517
|
+
const getDecodedWithdrawalCurrency = (decodedWithdrawal) => {
|
|
518
|
+
switch (decodedWithdrawal.vmType) {
|
|
519
|
+
case "bitcoin-vm": {
|
|
520
|
+
return (0, utils_1.getVmTypeNativeCurrency)(decodedWithdrawal.vmType);
|
|
521
|
+
}
|
|
522
|
+
case "ethereum-vm": {
|
|
523
|
+
const firstCall = decodedWithdrawal.withdrawal.calls[0];
|
|
524
|
+
return firstCall.data === "0x"
|
|
525
|
+
? (0, utils_1.getVmTypeNativeCurrency)(decodedWithdrawal.vmType)
|
|
526
|
+
: firstCall.to;
|
|
527
|
+
}
|
|
528
|
+
case "tron-vm": {
|
|
529
|
+
const firstCall = decodedWithdrawal.withdrawal.calls[0];
|
|
530
|
+
return firstCall.data === "0x"
|
|
531
|
+
? (0, utils_1.getVmTypeNativeCurrency)(decodedWithdrawal.vmType)
|
|
532
|
+
: firstCall.to;
|
|
533
|
+
}
|
|
534
|
+
case "solana-vm": {
|
|
535
|
+
return decodedWithdrawal.withdrawal.token;
|
|
536
|
+
}
|
|
537
|
+
case "sui-vm": {
|
|
538
|
+
return decodedWithdrawal.withdrawal.coinType;
|
|
539
|
+
}
|
|
540
|
+
case "hyperliquid-vm": {
|
|
541
|
+
const { parameters } = decodedWithdrawal.withdrawal;
|
|
542
|
+
switch (parameters.type) {
|
|
543
|
+
case "UsdSend": {
|
|
544
|
+
return (0, utils_1.getVmTypeNativeCurrency)(decodedWithdrawal.vmType);
|
|
545
|
+
}
|
|
546
|
+
case "SendAsset": {
|
|
547
|
+
const SPOT_USDC = "0x6d1e7cde53ba9467b783cb7c530ce054";
|
|
548
|
+
const tokenAddress = parameters.token.split(":")[1].toLowerCase();
|
|
549
|
+
const tokenDex = parameters.sourceDex;
|
|
550
|
+
if (tokenDex === "" && tokenAddress !== SPOT_USDC) {
|
|
551
|
+
throw new Error("Only USDC is supported as a Perps token");
|
|
552
|
+
}
|
|
553
|
+
return tokenDex === "spot"
|
|
554
|
+
? tokenAddress.toLowerCase()
|
|
555
|
+
: tokenDex === ""
|
|
556
|
+
? (0, utils_1.getVmTypeNativeCurrency)(decodedWithdrawal.vmType)
|
|
557
|
+
: tokenAddress.toLowerCase() +
|
|
558
|
+
Buffer.from(tokenDex, "ascii").toString("hex");
|
|
559
|
+
}
|
|
560
|
+
default:
|
|
561
|
+
throw new Error(`Unsupported Hyperliquid transaction type ${parameters.type}`);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
exports.getDecodedWithdrawalCurrency = getDecodedWithdrawalCurrency;
|
|
567
|
+
const decodeERC20TransferParams = (data) => {
|
|
568
|
+
// ERC20 / TRC20 `transfer(address,uint256)` selector is 0xa9059cbb
|
|
569
|
+
const TRANSFER_SELECTOR = "0xa9059cbb";
|
|
570
|
+
if (data.toLowerCase().startsWith(TRANSFER_SELECTOR.toLowerCase())) {
|
|
571
|
+
const paramsData = ("0x" + data.slice(TRANSFER_SELECTOR.length));
|
|
572
|
+
const params = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)(["address", "uint256"]), paramsData);
|
|
573
|
+
return params;
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
throw new Error(`Unsupported function call data: ${data}`);
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
const getDecodedWithdrawalAmount = (decodedWithdrawal) => {
|
|
580
|
+
switch (decodedWithdrawal.vmType) {
|
|
581
|
+
case "ethereum-vm": {
|
|
582
|
+
const firstCall = decodedWithdrawal.withdrawal.calls[0];
|
|
583
|
+
if (firstCall.data === "0x") {
|
|
584
|
+
return firstCall.value;
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
const [, amount] = decodeERC20TransferParams(firstCall.data);
|
|
588
|
+
return amount.toString();
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
case "tron-vm": {
|
|
592
|
+
const firstCall = decodedWithdrawal.withdrawal.calls[0];
|
|
593
|
+
if (firstCall.data === "0x") {
|
|
594
|
+
return firstCall.value;
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
const [, amount] = decodeERC20TransferParams(firstCall.data);
|
|
598
|
+
return amount.toString();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
case "solana-vm": {
|
|
602
|
+
return decodedWithdrawal.withdrawal.amount;
|
|
603
|
+
}
|
|
604
|
+
case "sui-vm": {
|
|
605
|
+
return decodedWithdrawal.withdrawal.amount;
|
|
606
|
+
}
|
|
607
|
+
case "bitcoin-vm": {
|
|
608
|
+
const psbt = bitcoin.Psbt.fromHex(decodedWithdrawal.withdrawal.psbt);
|
|
609
|
+
return psbt.txOutputs[0].value.toString();
|
|
610
|
+
}
|
|
611
|
+
case "hyperliquid-vm": {
|
|
612
|
+
// The assumption here is that the amount is always encoded with the full decimals of the currency
|
|
613
|
+
const decimals = decodedWithdrawal.withdrawal.parameters.amount.split(".")[1].length;
|
|
614
|
+
return (0, viem_1.parseUnits)(decodedWithdrawal.withdrawal.parameters.amount, decimals).toString();
|
|
615
|
+
}
|
|
616
|
+
default:
|
|
617
|
+
throw new Error("Unsupported vm type");
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
exports.getDecodedWithdrawalAmount = getDecodedWithdrawalAmount;
|
|
621
|
+
const getDecodedWithdrawalRecipient = (decodedWithdrawal) => {
|
|
622
|
+
switch (decodedWithdrawal.vmType) {
|
|
623
|
+
case "ethereum-vm": {
|
|
624
|
+
const firstCall = decodedWithdrawal.withdrawal.calls[0];
|
|
625
|
+
if (firstCall.data === "0x") {
|
|
626
|
+
return firstCall.to;
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
const [to] = decodeERC20TransferParams(firstCall.data);
|
|
630
|
+
return to;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
case "tron-vm": {
|
|
634
|
+
const firstCall = decodedWithdrawal.withdrawal.calls[0];
|
|
635
|
+
if (firstCall.data === "0x") {
|
|
636
|
+
return firstCall.to;
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
const [to] = decodeERC20TransferParams(firstCall.data);
|
|
640
|
+
return to;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
case "solana-vm": {
|
|
644
|
+
return decodedWithdrawal.withdrawal.recipient;
|
|
645
|
+
}
|
|
646
|
+
case "sui-vm": {
|
|
647
|
+
return decodedWithdrawal.withdrawal.recipient;
|
|
648
|
+
}
|
|
649
|
+
case "bitcoin-vm": {
|
|
650
|
+
const psbt = bitcoin.Psbt.fromHex(decodedWithdrawal.withdrawal.psbt);
|
|
651
|
+
const firstOutput = psbt.txOutputs[0];
|
|
652
|
+
return bitcoin.address.fromOutputScript(firstOutput.script);
|
|
653
|
+
}
|
|
654
|
+
case "hyperliquid-vm": {
|
|
655
|
+
return decodedWithdrawal.withdrawal.parameters.destination;
|
|
656
|
+
}
|
|
657
|
+
default:
|
|
658
|
+
throw new Error("Unsupported vm type");
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
exports.getDecodedWithdrawalRecipient = getDecodedWithdrawalRecipient;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Order } from "../../order";
|
|
2
|
+
import { ChainIdToVmType } from "../../utils";
|
|
3
|
+
export declare enum SolverFillStatus {
|
|
4
|
+
FAILED = 0,
|
|
5
|
+
SUCCESSFUL = 1
|
|
6
|
+
}
|
|
7
|
+
export type SolverFillMessage = {
|
|
8
|
+
data: {
|
|
9
|
+
order: Order;
|
|
10
|
+
orderSignature: string;
|
|
11
|
+
inputs: {
|
|
12
|
+
transactionId: string;
|
|
13
|
+
onchainId: string;
|
|
14
|
+
inputIndex: number;
|
|
15
|
+
}[];
|
|
16
|
+
fill: {
|
|
17
|
+
transactionId: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
result: {
|
|
21
|
+
orderId: string;
|
|
22
|
+
status: SolverFillStatus;
|
|
23
|
+
totalWeightedInputPaymentBpsDiff: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare const getSolverFillMessageId: (message: SolverFillMessage, chainsConfig: ChainIdToVmType) => `0x${string}`;
|