@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,230 @@
|
|
|
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.decodeOrderExtraData = exports.encodeOrderExtraData = exports.decodeOrderCall = exports.encodeOrderCall = exports.getOrderId = exports.normalizeOrder = exports.ORDER_EIP712_TYPES = void 0;
|
|
37
|
+
const tronweb = __importStar(require("tronweb"));
|
|
38
|
+
const viem_1 = require("viem");
|
|
39
|
+
const utils_1 = require("../utils");
|
|
40
|
+
exports.ORDER_EIP712_TYPES = {
|
|
41
|
+
Order: [
|
|
42
|
+
{ name: "version", type: "string" },
|
|
43
|
+
{ name: "solverChainId", type: "string" },
|
|
44
|
+
{ name: "solver", type: "address" },
|
|
45
|
+
{ name: "salt", type: "uint256" },
|
|
46
|
+
{ name: "inputs", type: "Input[]" },
|
|
47
|
+
{ name: "output", type: "Output" },
|
|
48
|
+
{ name: "fees", type: "Fee[]" },
|
|
49
|
+
],
|
|
50
|
+
Input: [
|
|
51
|
+
{ name: "payment", type: "InputPayment" },
|
|
52
|
+
{ name: "refunds", type: "InputRefund[]" },
|
|
53
|
+
],
|
|
54
|
+
InputPayment: [
|
|
55
|
+
{ name: "chainId", type: "string" },
|
|
56
|
+
{ name: "currency", type: "bytes" },
|
|
57
|
+
{ name: "amount", type: "uint256" },
|
|
58
|
+
{ name: "weight", type: "uint256" },
|
|
59
|
+
],
|
|
60
|
+
InputRefund: [
|
|
61
|
+
{ name: "chainId", type: "string" },
|
|
62
|
+
{ name: "recipient", type: "bytes" },
|
|
63
|
+
{ name: "currency", type: "bytes" },
|
|
64
|
+
{ name: "minimumAmount", type: "uint256" },
|
|
65
|
+
{ name: "deadline", type: "uint32" },
|
|
66
|
+
{ name: "extraData", type: "bytes" },
|
|
67
|
+
],
|
|
68
|
+
Output: [
|
|
69
|
+
{ name: "chainId", type: "string" },
|
|
70
|
+
{ name: "payments", type: "OutputPayment[]" },
|
|
71
|
+
{ name: "deadline", type: "uint32" },
|
|
72
|
+
{ name: "calls", type: "bytes[]" },
|
|
73
|
+
{ name: "extraData", type: "bytes" },
|
|
74
|
+
],
|
|
75
|
+
OutputPayment: [
|
|
76
|
+
{ name: "recipient", type: "bytes" },
|
|
77
|
+
{ name: "currency", type: "bytes" },
|
|
78
|
+
{ name: "minimumAmount", type: "uint256" },
|
|
79
|
+
{ name: "expectedAmount", type: "uint256" },
|
|
80
|
+
],
|
|
81
|
+
Fee: [
|
|
82
|
+
{ name: "recipientChainId", type: "string" },
|
|
83
|
+
{ name: "recipient", type: "bytes" },
|
|
84
|
+
{ name: "currencyChainId", type: "string" },
|
|
85
|
+
{ name: "currency", type: "bytes" },
|
|
86
|
+
{ name: "amount", type: "uint256" },
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
const normalizeOrder = (order, chainsConfig) => {
|
|
90
|
+
const vmType = (chainId) => (0, utils_1.getChainVmType)(chainId, chainsConfig);
|
|
91
|
+
return {
|
|
92
|
+
version: order.version,
|
|
93
|
+
solverChainId: order.solverChainId,
|
|
94
|
+
solver: order.solver,
|
|
95
|
+
salt: order.salt,
|
|
96
|
+
inputs: order.inputs.map((input) => ({
|
|
97
|
+
payment: {
|
|
98
|
+
chainId: input.payment.chainId,
|
|
99
|
+
currency: (0, utils_1.encodeAddress)(input.payment.currency, vmType(input.payment.chainId)),
|
|
100
|
+
amount: input.payment.amount,
|
|
101
|
+
weight: input.payment.weight,
|
|
102
|
+
},
|
|
103
|
+
refunds: input.refunds.map((refund) => ({
|
|
104
|
+
chainId: refund.chainId,
|
|
105
|
+
recipient: (0, utils_1.encodeAddress)(refund.recipient, vmType(refund.chainId)),
|
|
106
|
+
currency: (0, utils_1.encodeAddress)(refund.currency, vmType(refund.chainId)),
|
|
107
|
+
minimumAmount: refund.minimumAmount,
|
|
108
|
+
deadline: refund.deadline,
|
|
109
|
+
extraData: (0, utils_1.encodeBytes)(refund.extraData),
|
|
110
|
+
})),
|
|
111
|
+
})),
|
|
112
|
+
output: {
|
|
113
|
+
chainId: order.output.chainId,
|
|
114
|
+
payments: order.output.payments.map((payment) => ({
|
|
115
|
+
recipient: (0, utils_1.encodeAddress)(payment.recipient, vmType(order.output.chainId)),
|
|
116
|
+
currency: (0, utils_1.encodeAddress)(payment.currency, vmType(order.output.chainId)),
|
|
117
|
+
minimumAmount: payment.minimumAmount,
|
|
118
|
+
expectedAmount: payment.expectedAmount,
|
|
119
|
+
})),
|
|
120
|
+
calls: order.output.calls.map(utils_1.encodeBytes),
|
|
121
|
+
deadline: order.output.deadline,
|
|
122
|
+
extraData: (0, utils_1.encodeBytes)(order.output.extraData),
|
|
123
|
+
},
|
|
124
|
+
fees: order.fees.map((fee) => ({
|
|
125
|
+
recipientChainId: fee.recipientChainId,
|
|
126
|
+
recipient: (0, utils_1.encodeAddress)(fee.recipient, vmType(fee.recipientChainId)),
|
|
127
|
+
currencyChainId: fee.currencyChainId,
|
|
128
|
+
currency: (0, utils_1.encodeAddress)(fee.currency, vmType(fee.currencyChainId)),
|
|
129
|
+
amount: fee.amount,
|
|
130
|
+
})),
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
exports.normalizeOrder = normalizeOrder;
|
|
134
|
+
const getOrderId = (order, config) => {
|
|
135
|
+
return (0, viem_1.hashStruct)({
|
|
136
|
+
types: exports.ORDER_EIP712_TYPES,
|
|
137
|
+
primaryType: "Order",
|
|
138
|
+
data: (0, exports.normalizeOrder)(order, config),
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
exports.getOrderId = getOrderId;
|
|
142
|
+
const encodeOrderCall = (call) => {
|
|
143
|
+
switch (call.vmType) {
|
|
144
|
+
case "ethereum-vm": {
|
|
145
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)(["(address to)", "(bytes data)", "(uint256 value)"]), [
|
|
146
|
+
{ to: call.call.to },
|
|
147
|
+
{ data: call.call.data },
|
|
148
|
+
{ value: BigInt(call.call.value) },
|
|
149
|
+
]);
|
|
150
|
+
}
|
|
151
|
+
default:
|
|
152
|
+
throw new Error("Unsupported vm type");
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
exports.encodeOrderCall = encodeOrderCall;
|
|
156
|
+
const decodeOrderCall = (call, vmType) => {
|
|
157
|
+
switch (vmType) {
|
|
158
|
+
case "ethereum-vm": {
|
|
159
|
+
try {
|
|
160
|
+
const result = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
161
|
+
"(address to)",
|
|
162
|
+
"(bytes data)",
|
|
163
|
+
"(uint256 value)",
|
|
164
|
+
]), call);
|
|
165
|
+
return {
|
|
166
|
+
vmType: "ethereum-vm",
|
|
167
|
+
call: {
|
|
168
|
+
to: result[0].to.toLowerCase(),
|
|
169
|
+
data: result[1].data.toLowerCase(),
|
|
170
|
+
value: result[2].value.toString(),
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
throw new Error("Failed to decode call");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
default:
|
|
179
|
+
throw new Error("Unsupported vm type");
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
exports.decodeOrderCall = decodeOrderCall;
|
|
183
|
+
const encodeOrderExtraData = (extraData) => {
|
|
184
|
+
switch (extraData.vmType) {
|
|
185
|
+
case "ethereum-vm": {
|
|
186
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)(["(address fillContract)"]), [{ fillContract: extraData.extraData.fillContract }]);
|
|
187
|
+
}
|
|
188
|
+
case "tron-vm": {
|
|
189
|
+
return tronweb.utils.abi.encodeParams(["address"], [extraData.extraData.fillContract]);
|
|
190
|
+
}
|
|
191
|
+
default:
|
|
192
|
+
throw new Error("Unsupported vm type");
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
exports.encodeOrderExtraData = encodeOrderExtraData;
|
|
196
|
+
const decodeOrderExtraData = (extraData, vmType) => {
|
|
197
|
+
switch (vmType) {
|
|
198
|
+
case "ethereum-vm": {
|
|
199
|
+
try {
|
|
200
|
+
const result = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)(["(address fillContract)"]), extraData);
|
|
201
|
+
return {
|
|
202
|
+
vmType: "ethereum-vm",
|
|
203
|
+
extraData: {
|
|
204
|
+
fillContract: result[0].fillContract.toLowerCase(),
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
throw new Error("Failed to decode extra data");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
case "tron-vm": {
|
|
213
|
+
try {
|
|
214
|
+
const result = tronweb.utils.abi.decodeParams(["fillContract"], ["address"], extraData);
|
|
215
|
+
return {
|
|
216
|
+
vmType: "tron-vm",
|
|
217
|
+
extraData: {
|
|
218
|
+
fillContract: tronweb.utils.address.fromHex(result.fillContract),
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
throw new Error("Failed to decode extra data");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
default:
|
|
227
|
+
throw new Error("Unsupported vm type");
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
exports.decodeOrderExtraData = decodeOrderExtraData;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type VmType = "bitcoin-vm" | "ethereum-vm" | "hyperliquid-vm" | "solana-vm" | "sui-vm" | "ton-vm" | "tron-vm" | "lighter-vm";
|
|
2
|
+
export type ChainIdToVmType = Record<string, VmType>;
|
|
3
|
+
export declare const getChainVmType: (chainId: string, chainsConfig: ChainIdToVmType) => VmType;
|
|
4
|
+
export declare const getVmTypeNativeCurrency: (vmType: VmType) => "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8" | "0x0000000000000000000000000000000000000000" | "0x00000000000000000000000000000000" | "11111111111111111111111111111111" | "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb" | "0";
|
|
5
|
+
export declare const encodeBytes: (bytes: string) => import("viem").ByteArray;
|
|
6
|
+
export declare const encodeAddress: (address: string, vmType: VmType) => Uint8Array;
|
|
7
|
+
export declare const decodeAddress: (address: Uint8Array, vmType: VmType) => string;
|
|
8
|
+
export declare const encodeTransactionId: (transactionId: string, vmType: VmType) => Uint8Array;
|
|
9
|
+
export declare const decodeTransactionId: (transactionId: Uint8Array, vmType: VmType) => string;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.decodeTransactionId = exports.encodeTransactionId = exports.decodeAddress = exports.encodeAddress = exports.encodeBytes = exports.getVmTypeNativeCurrency = exports.getChainVmType = void 0;
|
|
40
|
+
const viem_1 = require("viem");
|
|
41
|
+
const bech32_1 = require("bech32");
|
|
42
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
43
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
44
|
+
const tronweb = __importStar(require("tronweb"));
|
|
45
|
+
const getChainVmType = (chainId, chainsConfig) => {
|
|
46
|
+
if (!chainsConfig[chainId]) {
|
|
47
|
+
throw new Error(`Unknown vm type for chain ${chainId}`);
|
|
48
|
+
}
|
|
49
|
+
return chainsConfig[chainId];
|
|
50
|
+
};
|
|
51
|
+
exports.getChainVmType = getChainVmType;
|
|
52
|
+
// Native currencies
|
|
53
|
+
const getVmTypeNativeCurrency = (vmType) => {
|
|
54
|
+
switch (vmType) {
|
|
55
|
+
case "bitcoin-vm":
|
|
56
|
+
return "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8";
|
|
57
|
+
case "ethereum-vm":
|
|
58
|
+
return "0x0000000000000000000000000000000000000000";
|
|
59
|
+
case "hyperliquid-vm":
|
|
60
|
+
return "0x00000000000000000000000000000000";
|
|
61
|
+
case "solana-vm":
|
|
62
|
+
return "11111111111111111111111111111111";
|
|
63
|
+
case "tron-vm":
|
|
64
|
+
return "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb";
|
|
65
|
+
case "lighter-vm":
|
|
66
|
+
return "0";
|
|
67
|
+
default:
|
|
68
|
+
throw new Error(`Native currency not available for vm type ${vmType}`);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.getVmTypeNativeCurrency = getVmTypeNativeCurrency;
|
|
72
|
+
// Bytes encoding
|
|
73
|
+
const encodeBytes = (bytes) => (0, viem_1.hexToBytes)(bytes);
|
|
74
|
+
exports.encodeBytes = encodeBytes;
|
|
75
|
+
// Address encoding
|
|
76
|
+
const encodeAddress = (address, vmType) => {
|
|
77
|
+
switch (vmType) {
|
|
78
|
+
case "bitcoin-vm": {
|
|
79
|
+
const getBitcoinAddressType = (address) => {
|
|
80
|
+
if (address.startsWith("1")) {
|
|
81
|
+
return "p2pkh";
|
|
82
|
+
}
|
|
83
|
+
if (address.startsWith("3")) {
|
|
84
|
+
return "p2sh";
|
|
85
|
+
}
|
|
86
|
+
if (address.startsWith("bc1")) {
|
|
87
|
+
const lower = address.toLowerCase();
|
|
88
|
+
// Try Bech32 first (v0)
|
|
89
|
+
try {
|
|
90
|
+
const decoded = bech32_1.bech32.decode(lower, 90);
|
|
91
|
+
if (decoded.prefix === "bc" && decoded.words[0] === 0) {
|
|
92
|
+
return "bech32";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (_) { }
|
|
96
|
+
// Try Bech32m (v1+)
|
|
97
|
+
try {
|
|
98
|
+
const decoded = bech32_1.bech32m.decode(lower, 90);
|
|
99
|
+
if (decoded.prefix === "bc" && decoded.words[0] >= 1) {
|
|
100
|
+
return "bech32m";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (_) { }
|
|
104
|
+
}
|
|
105
|
+
throw new Error("Unsupported address format");
|
|
106
|
+
};
|
|
107
|
+
const type = getBitcoinAddressType(address);
|
|
108
|
+
if (type === "p2pkh" || type === "p2sh") {
|
|
109
|
+
const decoded = bs58_1.default.decode(address);
|
|
110
|
+
// Strip the checksum
|
|
111
|
+
return decoded.slice(0, -4);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const decoder = type === "bech32" ? bech32_1.bech32 : bech32_1.bech32m;
|
|
115
|
+
const { words } = decoder.decode(address);
|
|
116
|
+
const version = words[0];
|
|
117
|
+
const program = bech32_1.bech32.fromWords(words.slice(1));
|
|
118
|
+
return Uint8Array.from([version, ...program]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
case "ethereum-vm": {
|
|
122
|
+
return (0, viem_1.hexToBytes)(address);
|
|
123
|
+
}
|
|
124
|
+
case "hyperliquid-vm": {
|
|
125
|
+
return (0, viem_1.hexToBytes)(address);
|
|
126
|
+
}
|
|
127
|
+
case "solana-vm": {
|
|
128
|
+
return bs58_1.default.decode(address);
|
|
129
|
+
}
|
|
130
|
+
case "sui-vm": {
|
|
131
|
+
return (0, viem_1.hexToBytes)(address);
|
|
132
|
+
}
|
|
133
|
+
case "ton-vm": {
|
|
134
|
+
throw new Error("Vm type not implemented (encodeAddress)");
|
|
135
|
+
}
|
|
136
|
+
case "tron-vm": {
|
|
137
|
+
return (0, viem_1.hexToBytes)(`0x${tronweb.utils.address.toHex(address)}`);
|
|
138
|
+
}
|
|
139
|
+
case "lighter-vm": {
|
|
140
|
+
return (0, viem_1.hexToBytes)(`0x${Number(address).toString(16).padStart(32, "0")}`);
|
|
141
|
+
}
|
|
142
|
+
default: {
|
|
143
|
+
throw new Error(`Vm type not implemented (encodeAddress)`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
exports.encodeAddress = encodeAddress;
|
|
148
|
+
const decodeAddress = (address, vmType) => {
|
|
149
|
+
switch (vmType) {
|
|
150
|
+
case "bitcoin-vm": {
|
|
151
|
+
if (address.length === 21 &&
|
|
152
|
+
(address[0] === 0x00 || address[0] === 0x05)) {
|
|
153
|
+
// Base58Check (P2PKH/P2SH)
|
|
154
|
+
const checksum = bitcoin.crypto
|
|
155
|
+
.hash256(Buffer.from(address))
|
|
156
|
+
.slice(0, 4);
|
|
157
|
+
const full = Buffer.concat([Buffer.from(address), checksum]);
|
|
158
|
+
return bs58_1.default.encode(full);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// Bech32/Bech32m
|
|
162
|
+
const version = address[0];
|
|
163
|
+
const program = Array.from(address.slice(1));
|
|
164
|
+
const words = [version, ...bech32_1.bech32.toWords(Uint8Array.from(program))];
|
|
165
|
+
if (version === 0) {
|
|
166
|
+
return bech32_1.bech32.encode("bc", words);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return bech32_1.bech32m.encode("bc", words);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
case "ethereum-vm": {
|
|
174
|
+
return (0, viem_1.bytesToHex)(address);
|
|
175
|
+
}
|
|
176
|
+
case "hyperliquid-vm": {
|
|
177
|
+
return (0, viem_1.bytesToHex)(address);
|
|
178
|
+
}
|
|
179
|
+
case "solana-vm": {
|
|
180
|
+
return bs58_1.default.encode(address);
|
|
181
|
+
}
|
|
182
|
+
case "sui-vm": {
|
|
183
|
+
return (0, viem_1.bytesToHex)(address);
|
|
184
|
+
}
|
|
185
|
+
case "ton-vm": {
|
|
186
|
+
throw new Error("Vm type not implemented (decodeAddress)");
|
|
187
|
+
}
|
|
188
|
+
case "tron-vm": {
|
|
189
|
+
return tronweb.utils.address.fromHex((0, viem_1.bytesToHex)(address).slice(2));
|
|
190
|
+
}
|
|
191
|
+
case "lighter-vm": {
|
|
192
|
+
return Number("0x" + Buffer.from(address).toString("hex")).toString();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
exports.decodeAddress = decodeAddress;
|
|
197
|
+
// Transaction encoding
|
|
198
|
+
const encodeTransactionId = (transactionId, vmType) => {
|
|
199
|
+
switch (vmType) {
|
|
200
|
+
case "bitcoin-vm": {
|
|
201
|
+
return Uint8Array.from(Buffer.from(transactionId, "hex"));
|
|
202
|
+
}
|
|
203
|
+
case "ethereum-vm": {
|
|
204
|
+
return (0, viem_1.hexToBytes)(transactionId);
|
|
205
|
+
}
|
|
206
|
+
case "hyperliquid-vm": {
|
|
207
|
+
return (0, viem_1.hexToBytes)(transactionId);
|
|
208
|
+
}
|
|
209
|
+
case "solana-vm": {
|
|
210
|
+
return bs58_1.default.decode(transactionId);
|
|
211
|
+
}
|
|
212
|
+
case "sui-vm": {
|
|
213
|
+
throw new Error("Vm type not implemented (encodeTransactionId)");
|
|
214
|
+
}
|
|
215
|
+
case "ton-vm": {
|
|
216
|
+
throw new Error("Vm type not implemented (encodeTransactionId)");
|
|
217
|
+
}
|
|
218
|
+
case "tron-vm": {
|
|
219
|
+
return (0, viem_1.hexToBytes)(`0x${transactionId}`);
|
|
220
|
+
}
|
|
221
|
+
case "lighter-vm": {
|
|
222
|
+
return (0, viem_1.hexToBytes)(`0x${transactionId}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
exports.encodeTransactionId = encodeTransactionId;
|
|
227
|
+
const decodeTransactionId = (transactionId, vmType) => {
|
|
228
|
+
switch (vmType) {
|
|
229
|
+
case "bitcoin-vm": {
|
|
230
|
+
return Buffer.from(transactionId).toString("hex");
|
|
231
|
+
}
|
|
232
|
+
case "ethereum-vm": {
|
|
233
|
+
return (0, viem_1.bytesToHex)(transactionId);
|
|
234
|
+
}
|
|
235
|
+
case "hyperliquid-vm": {
|
|
236
|
+
return (0, viem_1.bytesToHex)(transactionId);
|
|
237
|
+
}
|
|
238
|
+
case "solana-vm": {
|
|
239
|
+
return bs58_1.default.encode(transactionId);
|
|
240
|
+
}
|
|
241
|
+
case "sui-vm": {
|
|
242
|
+
throw new Error("Vm type not implemented (decodeTransactionId)");
|
|
243
|
+
}
|
|
244
|
+
case "ton-vm": {
|
|
245
|
+
throw new Error("Vm type not implemented (decodeTransactionId)");
|
|
246
|
+
}
|
|
247
|
+
case "tron-vm": {
|
|
248
|
+
return (0, viem_1.bytesToHex)(transactionId).slice(2);
|
|
249
|
+
}
|
|
250
|
+
case "lighter-vm": {
|
|
251
|
+
return (0, viem_1.bytesToHex)(transactionId).slice(2);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
exports.decodeTransactionId = decodeTransactionId;
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@relay-protocol/settlement-sdk",
|
|
3
|
+
"version": "0.0.64",
|
|
4
|
+
"description": "Relay protocol SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"repository": "https://github.com/relayprotocol/settlement-protocol/packages/sdk",
|
|
8
|
+
"author": "Uneven Labs",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc -b",
|
|
12
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
13
|
+
"prepublishOnly": "yarn clean && yarn build",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^22.15.3",
|
|
19
|
+
"typescript": "^5.5.4",
|
|
20
|
+
"vitest": "^2.1.8"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@coral-xyz/anchor": "^0.31.1",
|
|
24
|
+
"@mysten/sui": "^1.24.0",
|
|
25
|
+
"bech32": "^2.0.0",
|
|
26
|
+
"bitcoinjs-lib": "^6.1.7",
|
|
27
|
+
"bs58": "^6.0.0",
|
|
28
|
+
"js-sha256": "^0.11.0",
|
|
29
|
+
"tronweb": "^6.0.4",
|
|
30
|
+
"viem": "^2.26.3"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/**/*"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
39
|
+
}
|