@relay-protocol/settlement-sdk 0.0.80 → 0.0.81

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.
@@ -1,17 +1,18 @@
1
+ import { Address, Hex } from "viem";
1
2
  import { VmType } from "../utils";
2
3
  export interface TokenIdComponents {
3
4
  family: VmType;
4
- chainId: bigint;
5
+ chainId: string;
5
6
  address: string;
6
7
  }
7
8
  export interface VirtualAddressComponents {
8
9
  family: VmType;
9
- chainId: bigint;
10
+ chainId: string;
10
11
  address: string;
11
12
  }
12
13
  export type TokenId = bigint;
13
- export type VirtualAddress = `0x${string}`;
14
- export declare const getCheckSummedAddress: (family: string, address: string) => string;
14
+ export type VirtualAddress = Address;
15
+ export declare const arrayToHex: (arr: Uint8Array) => Hex;
15
16
  /**
16
17
  * Generates a virtual Ethereum address from token components
17
18
  * @param components The token components (family, chainId, address)
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCheckSummedAddress = void 0;
3
+ exports.arrayToHex = void 0;
4
4
  exports.generateAddress = generateAddress;
5
5
  exports.generateTokenId = generateTokenId;
6
6
  const viem_1 = require("viem");
7
- const getCheckSummedAddress = (family, address) => {
8
- const checksummedAddress = family === "ethereum-vm" ? (0, viem_1.getAddress)(address) : address;
9
- return checksummedAddress;
10
- };
11
- exports.getCheckSummedAddress = getCheckSummedAddress;
7
+ const utils_1 = require("../utils");
8
+ const arrayToHex = (arr) => `0x${Buffer.from(arr).toString("hex")}`;
9
+ exports.arrayToHex = arrayToHex;
12
10
  /**
13
11
  * Generates a virtual Ethereum address from token components
14
12
  * @param components The token components (family, chainId, address)
@@ -19,7 +17,7 @@ exports.getCheckSummedAddress = getCheckSummedAddress;
19
17
  */
20
18
  function generateAddress(components) {
21
19
  const { chainId, address, family } = components;
22
- const addressHash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string", "uint256", family === "ethereum-vm" ? "address" : "string"], [family, chainId, (0, exports.getCheckSummedAddress)(family, address)]));
20
+ const addressHash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string", "bytes"], [chainId, (0, exports.arrayToHex)((0, utils_1.encodeAddress)(address, family))]));
23
21
  const addressBytes = addressHash.slice(2).slice(-40);
24
22
  return (0, viem_1.getAddress)("0x" + addressBytes);
25
23
  }
@@ -30,6 +28,6 @@ function generateAddress(components) {
30
28
  */
31
29
  function generateTokenId(components) {
32
30
  const { family, chainId, address } = components;
33
- const packedData = (0, viem_1.encodePacked)(["string", "uint256", family === "ethereum-vm" ? "address" : "string"], [family, chainId, (0, exports.getCheckSummedAddress)(family, address)]);
31
+ const packedData = (0, viem_1.encodePacked)(["string", "bytes"], [chainId, (0, exports.arrayToHex)((0, utils_1.encodeAddress)(address, family))]);
34
32
  return BigInt((0, viem_1.keccak256)(packedData));
35
33
  }
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 { SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, WithdrawalAddressParams, WithdrawalInitiationMessage, WithdrawalInitiatedMessage, WithdrawalAddressRequest, computeWithdrawerBalanceMessage } from "./messages/v2.2/withdrawal-execution";
9
- import { TokenIdComponents, VirtualAddressComponents, TokenId, VirtualAddress, getCheckSummedAddress, generateAddress, generateTokenId } from "./hub/hub-utils";
8
+ import { SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, WithdrawalAddressParams, WithdrawalInitiationMessage, WithdrawalInitiatedMessage, WithdrawalAddressRequest, computeWithdrawerBalanceMessage, OnChainWithdrawalQuery, OnchainWithdrawalSignatureRequest, OnchainWithdrawalRequest } from "./messages/v2.2/withdrawal-execution";
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, getCheckSummedAddress, generateAddress, generateTokenId, SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, WithdrawalAddressParams, WithdrawalInitiationMessage, WithdrawalInitiatedMessage, WithdrawalAddressRequest, computeWithdrawerBalanceMessage, 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, SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, WithdrawalAddressParams, WithdrawalInitiationMessage, WithdrawalInitiatedMessage, WithdrawalAddressRequest, computeWithdrawerBalanceMessage, OnChainWithdrawalQuery, OnchainWithdrawalSignatureRequest, OnchainWithdrawalRequest, 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.computeWithdrawerBalanceMessage = exports.getWithdrawalAddress = exports.getSubmitWithdrawRequestHash = exports.generateTokenId = exports.generateAddress = exports.getCheckSummedAddress = 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.computeWithdrawerBalanceMessage = 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; } });
@@ -41,6 +41,5 @@ Object.defineProperty(exports, "getSubmitWithdrawRequestHash", { enumerable: tru
41
41
  Object.defineProperty(exports, "getWithdrawalAddress", { enumerable: true, get: function () { return withdrawal_execution_1.getWithdrawalAddress; } });
42
42
  Object.defineProperty(exports, "computeWithdrawerBalanceMessage", { enumerable: true, get: function () { return withdrawal_execution_1.computeWithdrawerBalanceMessage; } });
43
43
  const hub_utils_1 = require("./hub/hub-utils");
44
- Object.defineProperty(exports, "getCheckSummedAddress", { enumerable: true, get: function () { return hub_utils_1.getCheckSummedAddress; } });
45
44
  Object.defineProperty(exports, "generateAddress", { enumerable: true, get: function () { return hub_utils_1.generateAddress; } });
46
45
  Object.defineProperty(exports, "generateTokenId", { enumerable: true, get: function () { return hub_utils_1.generateTokenId; } });
@@ -74,7 +74,7 @@ const encodeAction = (action) => {
74
74
  };
75
75
  exports.encodeAction = encodeAction;
76
76
  const decodeAction = (action) => {
77
- // Decode just the uint8 type
77
+ // decode just the uint8 type
78
78
  const [type] = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)(["uint8 type"]), action);
79
79
  switch (type) {
80
80
  case ActionType.MINT: {
@@ -1,3 +1,4 @@
1
+ import { VmType } from "../../utils";
1
2
  export interface SubmitWithdrawRequest {
2
3
  chainId: string;
3
4
  depository: string;
@@ -11,7 +12,7 @@ export interface SubmitWithdrawRequest {
11
12
  export declare const getSubmitWithdrawRequestHash: (request: SubmitWithdrawRequest) => `0x${string}`;
12
13
  export type WithdrawalAddressParams = {
13
14
  depository: string;
14
- depositoryChainId: bigint;
15
+ depositoryChainId: string;
15
16
  currency: string;
16
17
  recipient: string;
17
18
  withdrawerAlias: string;
@@ -29,19 +30,26 @@ export type WithdrawalAddressParams = {
29
30
  * @param withdrawalNonce nonce to prevent collisions for similar withdrawals
30
31
  * @returns withdrawal address (in lower case)
31
32
  */
32
- export declare function getWithdrawalAddress(withdrawalParams: WithdrawalAddressParams): string;
33
- export declare const computeWithdrawerBalanceMessage: (withdrawerAlias: string, amount: bigint, withdrawalNonce: string) => `0x${string}`;
34
- export type WithdrawalAddressRequest = {
35
- chainId: string;
36
- currency: string;
37
- recipient: string;
38
- withdrawerChainId: string;
33
+ export declare function getWithdrawalAddress(withdrawalParams: WithdrawalAddressParams & {
34
+ depositoryVmType: VmType;
35
+ }): string;
36
+ export declare function getOrderAddress(data: {
37
+ depositChainVmType: VmType;
38
+ depositChainId: string;
39
+ depositor: string;
40
+ depositTimestamp: bigint;
41
+ depositId: string;
42
+ }): string;
43
+ export declare function computeWithdrawerBalanceMessage(withdrawerAlias: string, amount: bigint, withdrawalNonce: string): `0x${string}`;
44
+ export type WithdrawalAddressRequest = Omit<WithdrawalAddressParams, "depositoryChainId" | "amount" | "depository" | "withdrawerAlias"> & {
39
45
  withdrawer: string;
40
- withdrawalNonce: string;
46
+ withdrawerChainId: string;
47
+ chainId: string;
41
48
  };
42
49
  export type WithdrawalInitiationMessage = {
43
50
  data: WithdrawalAddressRequest & {
44
- amount: string;
51
+ expectedAmount: string;
52
+ settlementChainId: string;
45
53
  signature: string;
46
54
  };
47
55
  result: {
@@ -50,10 +58,58 @@ export type WithdrawalInitiationMessage = {
50
58
  };
51
59
  export type WithdrawalInitiatedMessage = {
52
60
  data: WithdrawalAddressRequest & {
53
- amount: string;
61
+ expectedAmount: string;
62
+ settlementChainId: string;
54
63
  };
55
64
  result: {
56
65
  proofOfWithdrawalAddressBalance: string;
57
66
  withdrawalAddress: string;
58
67
  };
59
68
  };
69
+ export type OnChainWithdrawalQuery = {
70
+ data: {
71
+ chainId: string;
72
+ payloadId: string;
73
+ payloadParams: SubmitWithdrawRequest;
74
+ };
75
+ result: {
76
+ encodedData: string;
77
+ signature?: string;
78
+ signer?: string;
79
+ };
80
+ };
81
+ export type OnchainWithdrawalRequest = {
82
+ data: {
83
+ chainId: string;
84
+ currency: string;
85
+ amount: string;
86
+ recipient: string;
87
+ spender: string;
88
+ nonce: string;
89
+ additionalData?: {
90
+ "hyperliquid-vm"?: {
91
+ currencyHyperliquidSymbol: string;
92
+ };
93
+ };
94
+ signature: string;
95
+ owner: string;
96
+ ownerChainId: string;
97
+ };
98
+ result: {
99
+ id: string;
100
+ encodedData: string;
101
+ payloadId: string;
102
+ submitWithdrawalRequestParams: SubmitWithdrawRequest;
103
+ signer: string;
104
+ };
105
+ };
106
+ export type OnchainWithdrawalSignatureRequest = {
107
+ data: {
108
+ chainId: string;
109
+ payloadId: string;
110
+ payloadParams: SubmitWithdrawRequest;
111
+ };
112
+ result: {
113
+ message: string;
114
+ };
115
+ };
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computeWithdrawerBalanceMessage = exports.getSubmitWithdrawRequestHash = void 0;
3
+ exports.getSubmitWithdrawRequestHash = void 0;
4
4
  exports.getWithdrawalAddress = getWithdrawalAddress;
5
+ exports.getOrderAddress = getOrderAddress;
6
+ exports.computeWithdrawerBalanceMessage = computeWithdrawerBalanceMessage;
5
7
  const viem_1 = require("viem");
8
+ const hub_utils_1 = require("../../hub/hub-utils");
9
+ const utils_1 = require("../../utils");
6
10
  const getSubmitWithdrawRequestHash = (request) => {
7
11
  const encoded = (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)([
8
12
  "(uint256 chainId, string depository, string currency, uint256 amount, address spender, string receiver, bytes data, bytes32 nonce)",
@@ -34,26 +38,34 @@ exports.getSubmitWithdrawRequestHash = getSubmitWithdrawRequestHash;
34
38
  * @returns withdrawal address (in lower case)
35
39
  */
36
40
  function getWithdrawalAddress(withdrawalParams) {
37
- // Pack and hash data
38
- const nonce = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string"], [withdrawalParams.withdrawalNonce]));
39
- const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string", "uint256", "string", "string", "address", "bytes32"], [
40
- withdrawalParams.depository,
41
+ const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string", "bytes", "bytes", "bytes", "address", "bytes32"], [
41
42
  withdrawalParams.depositoryChainId,
42
- withdrawalParams.currency,
43
- withdrawalParams.recipient,
43
+ (0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.depository, withdrawalParams.depositoryVmType)),
44
+ (0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.currency, withdrawalParams.depositoryVmType)),
45
+ (0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.recipient, withdrawalParams.depositoryVmType)),
44
46
  withdrawalParams.withdrawerAlias,
45
- nonce,
47
+ `0x${BigInt(withdrawalParams.withdrawalNonce).toString(16).padStart(64, "0")}`,
46
48
  ]));
47
- // Get the first 40 bytes for an address
49
+ // get 40 bytes for an address
48
50
  const withdrawalAddress = hash.slice(2).slice(-40).toLowerCase();
49
51
  return `0x${withdrawalAddress}`;
50
52
  }
51
- // Compute a message about withdrawer balance to be signed as auth proof for the oracle
52
- const computeWithdrawerBalanceMessage = (withdrawerAlias, amount, withdrawalNonce) => {
53
+ function getOrderAddress(data) {
54
+ const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string", "bytes", "uint256", "bytes32"], [
55
+ data.depositChainId,
56
+ (0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(data.depositor, data.depositChainVmType)),
57
+ BigInt(data.depositTimestamp),
58
+ data.depositId,
59
+ ]));
60
+ const orderAddress = hash.slice(2).slice(-40);
61
+ return `0x${orderAddress}`;
62
+ }
63
+ // compute a message about withdrawer balance
64
+ // to be signed as auth proof for the oracle
65
+ function computeWithdrawerBalanceMessage(withdrawerAlias, amount, withdrawalNonce) {
53
66
  return (0, viem_1.keccak256)((0, viem_1.encodePacked)(["address", "uint256", "bytes32"], [
54
67
  withdrawerAlias,
55
68
  BigInt(amount),
56
69
  withdrawalNonce,
57
70
  ]));
58
- };
59
- exports.computeWithdrawerBalanceMessage = computeWithdrawerBalanceMessage;
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relay-protocol/settlement-sdk",
3
- "version": "0.0.80",
3
+ "version": "0.0.81",
4
4
  "description": "Relay protocol SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",