@relay-protocol/settlement-sdk 0.0.86 → 0.0.87

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.ts CHANGED
@@ -5,7 +5,7 @@ import { SolverRefundMessage, SolverRefundStatus, getSolverRefundMessageId } fro
5
5
  import { SolverFillMessage, SolverFillStatus, getSolverFillMessageId } from "./messages/v2.1/solver-fill";
6
6
  import { ActionType, ExecutionMessage, ExecutionMessageMetadata, getExecutionMessageId, encodeAction, decodeAction } from "./messages/v2.2/execution";
7
7
  import { VmType, decodeAddress, decodeTransactionId, encodeAddress, encodeBytes, encodeTransactionId, getVmTypeNativeCurrency } from "./utils";
8
- import { DenormalizedSubmitWithdrawRequest, SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, getOrderAddress, OrderAddressParams, WithdrawalAddressParams } from "./messages/v2.2/withdrawal-execution";
8
+ import { DenormalizedSubmitWithdrawRequest, SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, getOrderAddress, normalizePayloadParams, OrderAddressParams, WithdrawalAddressParams } from "./messages/v2.2/withdrawal-execution";
9
9
  import { TokenIdComponents, VirtualAddressComponents, TokenId, VirtualAddress, generateAddress, generateTokenId } from "./hub/hub-utils";
10
10
  import type { NetworkConfig, NetworkConfigs, ProtocolContracts } from "./networks";
11
- export { Order, encodeOrderCall, decodeOrderCall, encodeOrderExtraData, decodeOrderExtraData, getOrderId, VmType, decodeAddress, decodeTransactionId, encodeAddress, encodeBytes, encodeTransactionId, getVmTypeNativeCurrency, DepositoryDepositMessage, getDepositoryDepositMessageId, DecodedBitcoinVmWithdrawal, DecodedEthereumVmWithdrawal, DecodedSolanaVmWithdrawal, DecodedSuiVmWithdrawal, DecodedHyperliquidVmWithdrawal, DepositoryWithdrawalMessage, DepositoryWithdrawalStatus, getDepositoryWithdrawalMessageId, encodeWithdrawal, decodeWithdrawal, getDecodedWithdrawalId, getDecodedWithdrawalCurrency, getDecodedWithdrawalAmount, getDecodedWithdrawalRecipient, SolverRefundMessage, SolverRefundStatus, getSolverRefundMessageId, SolverFillMessage, SolverFillStatus, getSolverFillMessageId, ExecutionMessage, ExecutionMessageMetadata, ActionType, getExecutionMessageId, encodeAction, decodeAction, TokenIdComponents, VirtualAddressComponents, TokenId, VirtualAddress, generateAddress, generateTokenId, DenormalizedSubmitWithdrawRequest, SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, getOrderAddress, OrderAddressParams, WithdrawalAddressParams, NetworkConfigs, ProtocolContracts, NetworkConfig, };
11
+ export { Order, encodeOrderCall, decodeOrderCall, encodeOrderExtraData, decodeOrderExtraData, getOrderId, VmType, decodeAddress, decodeTransactionId, encodeAddress, encodeBytes, encodeTransactionId, getVmTypeNativeCurrency, DepositoryDepositMessage, getDepositoryDepositMessageId, DecodedBitcoinVmWithdrawal, DecodedEthereumVmWithdrawal, DecodedSolanaVmWithdrawal, DecodedSuiVmWithdrawal, DecodedHyperliquidVmWithdrawal, DepositoryWithdrawalMessage, DepositoryWithdrawalStatus, getDepositoryWithdrawalMessageId, encodeWithdrawal, decodeWithdrawal, getDecodedWithdrawalId, getDecodedWithdrawalCurrency, getDecodedWithdrawalAmount, getDecodedWithdrawalRecipient, SolverRefundMessage, SolverRefundStatus, getSolverRefundMessageId, SolverFillMessage, SolverFillStatus, getSolverFillMessageId, ExecutionMessage, ExecutionMessageMetadata, ActionType, getExecutionMessageId, encodeAction, decodeAction, TokenIdComponents, VirtualAddressComponents, TokenId, VirtualAddress, generateAddress, generateTokenId, DenormalizedSubmitWithdrawRequest, SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, getOrderAddress, normalizePayloadParams, OrderAddressParams, WithdrawalAddressParams, NetworkConfigs, ProtocolContracts, NetworkConfig, };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOrderAddress = exports.getWithdrawalAddress = exports.getSubmitWithdrawRequestHash = exports.generateTokenId = exports.generateAddress = exports.decodeAction = exports.encodeAction = exports.getExecutionMessageId = exports.ActionType = exports.getSolverFillMessageId = exports.SolverFillStatus = exports.getSolverRefundMessageId = exports.SolverRefundStatus = exports.getDecodedWithdrawalRecipient = exports.getDecodedWithdrawalAmount = exports.getDecodedWithdrawalCurrency = exports.getDecodedWithdrawalId = exports.decodeWithdrawal = exports.encodeWithdrawal = exports.getDepositoryWithdrawalMessageId = exports.DepositoryWithdrawalStatus = exports.getDepositoryDepositMessageId = exports.getVmTypeNativeCurrency = exports.encodeTransactionId = exports.encodeBytes = exports.encodeAddress = exports.decodeTransactionId = exports.decodeAddress = exports.getOrderId = exports.decodeOrderExtraData = exports.encodeOrderExtraData = exports.decodeOrderCall = exports.encodeOrderCall = void 0;
3
+ exports.normalizePayloadParams = exports.getOrderAddress = exports.getWithdrawalAddress = exports.getSubmitWithdrawRequestHash = exports.generateTokenId = exports.generateAddress = exports.decodeAction = exports.encodeAction = exports.getExecutionMessageId = exports.ActionType = exports.getSolverFillMessageId = exports.SolverFillStatus = exports.getSolverRefundMessageId = exports.SolverRefundStatus = exports.getDecodedWithdrawalRecipient = exports.getDecodedWithdrawalAmount = exports.getDecodedWithdrawalCurrency = exports.getDecodedWithdrawalId = exports.decodeWithdrawal = exports.encodeWithdrawal = exports.getDepositoryWithdrawalMessageId = exports.DepositoryWithdrawalStatus = exports.getDepositoryDepositMessageId = exports.getVmTypeNativeCurrency = exports.encodeTransactionId = exports.encodeBytes = exports.encodeAddress = exports.decodeTransactionId = exports.decodeAddress = exports.getOrderId = exports.decodeOrderExtraData = exports.encodeOrderExtraData = exports.decodeOrderCall = exports.encodeOrderCall = void 0;
4
4
  const order_1 = require("./order");
5
5
  Object.defineProperty(exports, "encodeOrderCall", { enumerable: true, get: function () { return order_1.encodeOrderCall; } });
6
6
  Object.defineProperty(exports, "decodeOrderCall", { enumerable: true, get: function () { return order_1.decodeOrderCall; } });
@@ -40,6 +40,7 @@ const withdrawal_execution_1 = require("./messages/v2.2/withdrawal-execution");
40
40
  Object.defineProperty(exports, "getSubmitWithdrawRequestHash", { enumerable: true, get: function () { return withdrawal_execution_1.getSubmitWithdrawRequestHash; } });
41
41
  Object.defineProperty(exports, "getWithdrawalAddress", { enumerable: true, get: function () { return withdrawal_execution_1.getWithdrawalAddress; } });
42
42
  Object.defineProperty(exports, "getOrderAddress", { enumerable: true, get: function () { return withdrawal_execution_1.getOrderAddress; } });
43
+ Object.defineProperty(exports, "normalizePayloadParams", { enumerable: true, get: function () { return withdrawal_execution_1.normalizePayloadParams; } });
43
44
  const hub_utils_1 = require("./hub/hub-utils");
44
45
  Object.defineProperty(exports, "generateAddress", { enumerable: true, get: function () { return hub_utils_1.generateAddress; } });
45
46
  Object.defineProperty(exports, "generateTokenId", { enumerable: true, get: function () { return hub_utils_1.generateTokenId; } });
@@ -57,3 +57,7 @@ export type OrderAddressParams = {
57
57
  depositId: string;
58
58
  };
59
59
  export declare function getOrderAddress(orderParams: OrderAddressParams): Address;
60
+ export declare function getWithdrawalInitiationHash(withdrawerAlias: string, amount: bigint, withdrawalNonce: string): `0x${string}`;
61
+ export declare function normalizePayloadParams(request: DenormalizedSubmitWithdrawRequest & {
62
+ vmType: VmType;
63
+ }): SubmitWithdrawRequest;
@@ -1,8 +1,49 @@
1
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
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.getSubmitWithdrawRequestHash = void 0;
4
40
  exports.getWithdrawalAddress = getWithdrawalAddress;
5
41
  exports.getOrderAddress = getOrderAddress;
42
+ exports.getWithdrawalInitiationHash = getWithdrawalInitiationHash;
43
+ exports.normalizePayloadParams = normalizePayloadParams;
44
+ const web3_js_1 = require("@solana/web3.js");
45
+ const bitcoin = __importStar(require("bitcoinjs-lib"));
46
+ const tronweb_1 = __importDefault(require("tronweb"));
6
47
  const viem_1 = require("viem");
7
48
  const hub_utils_1 = require("../../hub/hub-utils");
8
49
  const utils_1 = require("../../utils");
@@ -60,3 +101,136 @@ function getOrderAddress(orderParams) {
60
101
  const orderAddress = hash.slice(2).slice(-40);
61
102
  return `0x${orderAddress}`;
62
103
  }
104
+ function getWithdrawalInitiationHash(withdrawerAlias, amount, withdrawalNonce) {
105
+ return (0, viem_1.keccak256)((0, viem_1.encodePacked)(["address", "uint256", "bytes32"], [
106
+ withdrawerAlias,
107
+ BigInt(amount),
108
+ withdrawalNonce,
109
+ ]));
110
+ }
111
+ function normalizePayloadParams(request) {
112
+ const defaultParams = {
113
+ chainId: request.chainId,
114
+ depository: request.depository,
115
+ currency: request.currency,
116
+ spender: request.spender,
117
+ recipient: request.recipient,
118
+ amount: request.amount,
119
+ nonce: request.nonce,
120
+ data: "0x",
121
+ };
122
+ switch (request.vmType) {
123
+ case "ethereum-vm": {
124
+ return {
125
+ ...defaultParams,
126
+ depository: defaultParams.depository.toLowerCase(),
127
+ currency: defaultParams.currency.toLowerCase(),
128
+ spender: defaultParams.spender.toLowerCase(),
129
+ recipient: defaultParams.recipient.toLowerCase(),
130
+ };
131
+ }
132
+ case "bitcoin-vm": {
133
+ const bitcoinAdditionalData = request.additionalData?.["bitcoin-vm"];
134
+ if (!bitcoinAdditionalData) {
135
+ throw new Error("Additional data is required for bitcoin-vm");
136
+ }
137
+ const allocatorScriptPubKey = `0x${bitcoin.address
138
+ .toOutputScript(request.depository, bitcoin.networks.bitcoin)
139
+ .toString("hex")}`;
140
+ const toLittleEndianTxid = (txid) => {
141
+ const normalizedTxid = txid.startsWith("0x") ? txid.slice(2) : txid;
142
+ if (!/^[0-9a-fA-F]{64}$/.test(normalizedTxid)) {
143
+ throw new Error("Invalid bitcoin UTXO txid");
144
+ }
145
+ return `0x${Buffer.from(normalizedTxid, "hex")
146
+ .reverse()
147
+ .toString("hex")}`;
148
+ };
149
+ const data = (0, viem_1.encodeAbiParameters)([
150
+ {
151
+ type: "tuple",
152
+ components: [
153
+ {
154
+ type: "tuple[]",
155
+ name: "utxos",
156
+ components: [
157
+ { type: "bytes32", name: "txid" },
158
+ { type: "uint32", name: "index" },
159
+ { type: "uint64", name: "value" },
160
+ { type: "bytes", name: "scriptPubKey" },
161
+ ],
162
+ },
163
+ { type: "uint64", name: "feeRate" },
164
+ ],
165
+ },
166
+ ], [
167
+ {
168
+ utxos: bitcoinAdditionalData.allocatorUtxos.map((utxo) => ({
169
+ txid: toLittleEndianTxid(utxo.txid),
170
+ index: utxo.vout,
171
+ value: BigInt(utxo.value),
172
+ scriptPubKey: allocatorScriptPubKey,
173
+ })),
174
+ feeRate: BigInt(bitcoinAdditionalData.feeRate),
175
+ },
176
+ ]);
177
+ return {
178
+ ...defaultParams,
179
+ recipient: bitcoin.address
180
+ .toOutputScript(request.recipient, bitcoin.networks.bitcoin)
181
+ .toString("base64"),
182
+ data,
183
+ };
184
+ }
185
+ case "tron-vm": {
186
+ // The "tron-vm" payload builder (which is the "ethereum-vm" one) expects addresses to be hex-encoded
187
+ const toHex = (address) => tronweb_1.default.utils.address
188
+ .toHex(address)
189
+ .replace(tronweb_1.default.utils.address.ADDRESS_PREFIX_REGEX, "0x");
190
+ return {
191
+ ...defaultParams,
192
+ depository: toHex(request.depository),
193
+ currency: toHex(request.currency),
194
+ recipient: toHex(request.recipient),
195
+ };
196
+ }
197
+ case "solana-vm": {
198
+ // The "solana-vm" payload builder expects addresses to be hex-encoded
199
+ const toHexString = (address) => new web3_js_1.PublicKey(address).toBuffer().toString("hex");
200
+ return {
201
+ ...defaultParams,
202
+ currency: request.currency === (0, utils_1.getVmTypeNativeCurrency)(request.vmType)
203
+ ? ""
204
+ : toHexString(request.currency),
205
+ recipient: toHexString(request.recipient),
206
+ };
207
+ }
208
+ case "hyperliquid-vm": {
209
+ const hyperliquidAdditionalData = request.additionalData?.["hyperliquid-vm"];
210
+ if (!hyperliquidAdditionalData) {
211
+ throw new Error("Additional data is required for hyperliquid-vm");
212
+ }
213
+ const isNativeCurrency = request.currency === (0, utils_1.getVmTypeNativeCurrency)(request.vmType);
214
+ // TODO: We probably shouldn't be letting the user choose the time in order
215
+ // to preserve the assumption that the time is always incrementing. However
216
+ // at the moment we need these for deterministic payload ids.
217
+ const currentTime = BigInt(request.additionalData["hyperliquid-vm"].currentTime ?? Date.now());
218
+ const currencyDex = request.currency.slice(34) === ""
219
+ ? "spot"
220
+ : Buffer.from(request.currency.slice(34), "hex").toString("ascii");
221
+ const data = isNativeCurrency
222
+ ? (0, viem_1.encodeAbiParameters)([{ type: "uint64" }], [currentTime])
223
+ : (0, viem_1.encodeAbiParameters)([{ type: "uint64" }, { type: "string" }, { type: "string" }], [currentTime, currencyDex, currencyDex]);
224
+ return {
225
+ ...defaultParams,
226
+ currency: isNativeCurrency
227
+ ? ""
228
+ : `${hyperliquidAdditionalData.currencyHyperliquidSymbol}:${request.currency.toLowerCase()}`,
229
+ data,
230
+ };
231
+ }
232
+ default: {
233
+ throw new Error("Vm type not implemented for payload params");
234
+ }
235
+ }
236
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relay-protocol/settlement-sdk",
3
- "version": "0.0.86",
3
+ "version": "0.0.87",
4
4
  "description": "Relay protocol SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,6 +22,7 @@
22
22
  "dependencies": {
23
23
  "@coral-xyz/anchor": "^0.31.1",
24
24
  "@mysten/sui": "^1.24.0",
25
+ "@solana/web3.js": "1.98.4",
25
26
  "bech32": "^2.0.0",
26
27
  "bitcoinjs-lib": "^6.1.7",
27
28
  "bs58": "^6.0.0",