@relay-protocol/settlement-sdk 0.0.84 → 0.0.86
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 { SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, getOrderAddress,
|
|
8
|
+
import { DenormalizedSubmitWithdrawRequest, SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, getOrderAddress, 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, SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, getOrderAddress,
|
|
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, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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;
|
|
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,7 +40,6 @@ 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, "computeWithdrawerBalanceMessage", { enumerable: true, get: function () { return withdrawal_execution_1.computeWithdrawerBalanceMessage; } });
|
|
44
43
|
const hub_utils_1 = require("./hub/hub-utils");
|
|
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; } });
|
|
@@ -606,7 +606,7 @@ const getDecodedWithdrawalAmount = (decodedWithdrawal) => {
|
|
|
606
606
|
}
|
|
607
607
|
case "bitcoin-vm": {
|
|
608
608
|
const psbt = bitcoin.Psbt.fromHex(decodedWithdrawal.withdrawal.psbt);
|
|
609
|
-
const fee = psbt.getFee();
|
|
609
|
+
const fee = psbt.finalizeAllInputs().getFee();
|
|
610
610
|
return (psbt.txOutputs[0].value + fee).toString();
|
|
611
611
|
}
|
|
612
612
|
case "hyperliquid-vm": {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Address } from "viem";
|
|
1
2
|
import { VmType } from "../../utils";
|
|
2
3
|
export interface SubmitWithdrawRequest {
|
|
3
4
|
chainId: string;
|
|
@@ -5,111 +6,54 @@ export interface SubmitWithdrawRequest {
|
|
|
5
6
|
currency: string;
|
|
6
7
|
amount: string;
|
|
7
8
|
spender: string;
|
|
8
|
-
|
|
9
|
-
data: string;
|
|
9
|
+
recipient: string;
|
|
10
10
|
nonce: string;
|
|
11
|
+
data: string;
|
|
11
12
|
}
|
|
13
|
+
export type DenormalizedSubmitWithdrawRequest = Omit<SubmitWithdrawRequest, "data"> & {
|
|
14
|
+
additionalData?: {
|
|
15
|
+
"bitcoin-vm"?: {
|
|
16
|
+
allocatorUtxos: {
|
|
17
|
+
txid: string;
|
|
18
|
+
vout: number;
|
|
19
|
+
value: string;
|
|
20
|
+
}[];
|
|
21
|
+
feeRate: number;
|
|
22
|
+
};
|
|
23
|
+
"hyperliquid-vm"?: {
|
|
24
|
+
currencyHyperliquidSymbol: string;
|
|
25
|
+
currentTime: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
12
29
|
export declare const getSubmitWithdrawRequestHash: (request: SubmitWithdrawRequest) => `0x${string}`;
|
|
13
30
|
export type WithdrawalAddressParams = {
|
|
31
|
+
vmType: VmType;
|
|
32
|
+
chainId: string;
|
|
14
33
|
depository: string;
|
|
15
|
-
depositoryChainId: string;
|
|
16
34
|
currency: string;
|
|
17
35
|
recipient: string;
|
|
18
|
-
|
|
19
|
-
|
|
36
|
+
ownerAlias: string;
|
|
37
|
+
nonce: string;
|
|
20
38
|
};
|
|
21
39
|
/**
|
|
22
40
|
* Compute deterministic withdrawal address
|
|
23
41
|
*
|
|
42
|
+
* @param vmType the vm type of the depository chain
|
|
43
|
+
* @param chainId the chain id of the depository contract currently holding the funds
|
|
24
44
|
* @param depository the depository contract holding the funds on origin chain (as string)
|
|
25
|
-
* @param depositoryChainId the chain id of the depository contract currently holding the funds
|
|
26
45
|
* @param currency the id of the currency as expressed on origin chain (string)
|
|
27
46
|
* @param recipient the address that will receive the withdrawn funds on destination chain
|
|
28
|
-
* @param
|
|
29
|
-
*
|
|
30
|
-
* @param withdrawalNonce nonce to prevent collisions for similar withdrawals
|
|
47
|
+
* @param ownerAlias the address that owns the balance on the settlement chain before the withdrawal is initiated
|
|
48
|
+
* @param nonce nonce to prevent collisions for similar withdrawals
|
|
31
49
|
* @returns withdrawal address (in lower case)
|
|
32
50
|
*/
|
|
33
|
-
export declare function getWithdrawalAddress(withdrawalParams: WithdrawalAddressParams
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
depositChainVmType: VmType;
|
|
38
|
-
depositChainId: string;
|
|
51
|
+
export declare function getWithdrawalAddress(withdrawalParams: WithdrawalAddressParams): Address;
|
|
52
|
+
export type OrderAddressParams = {
|
|
53
|
+
vmType: VmType;
|
|
54
|
+
chainId: string;
|
|
39
55
|
depositor: string;
|
|
40
|
-
|
|
56
|
+
timestamp: bigint;
|
|
41
57
|
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"> & {
|
|
45
|
-
withdrawer: string;
|
|
46
|
-
withdrawerChainId: string;
|
|
47
|
-
chainId: string;
|
|
48
|
-
};
|
|
49
|
-
export type WithdrawalInitiationMessage = {
|
|
50
|
-
data: WithdrawalAddressRequest & {
|
|
51
|
-
expectedAmount: string;
|
|
52
|
-
settlementChainId: string;
|
|
53
|
-
signature: string;
|
|
54
|
-
};
|
|
55
|
-
result: {
|
|
56
|
-
withdrawalAddress: string;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
export type WithdrawalInitiatedMessage = {
|
|
60
|
-
data: WithdrawalAddressRequest & {
|
|
61
|
-
expectedAmount: string;
|
|
62
|
-
settlementChainId: string;
|
|
63
|
-
};
|
|
64
|
-
result: {
|
|
65
|
-
proofOfWithdrawalAddressBalance: string;
|
|
66
|
-
withdrawalAddress: string;
|
|
67
|
-
};
|
|
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
58
|
};
|
|
59
|
+
export declare function getOrderAddress(orderParams: OrderAddressParams): Address;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getSubmitWithdrawRequestHash = void 0;
|
|
4
4
|
exports.getWithdrawalAddress = getWithdrawalAddress;
|
|
5
5
|
exports.getOrderAddress = getOrderAddress;
|
|
6
|
-
exports.computeWithdrawerBalanceMessage = computeWithdrawerBalanceMessage;
|
|
7
6
|
const viem_1 = require("viem");
|
|
8
7
|
const hub_utils_1 = require("../../hub/hub-utils");
|
|
9
8
|
const utils_1 = require("../../utils");
|
|
@@ -17,7 +16,7 @@ const getSubmitWithdrawRequestHash = (request) => {
|
|
|
17
16
|
currency: request.currency,
|
|
18
17
|
amount: BigInt(request.amount),
|
|
19
18
|
spender: request.spender,
|
|
20
|
-
receiver: request.
|
|
19
|
+
receiver: request.recipient,
|
|
21
20
|
data: request.data,
|
|
22
21
|
nonce: request.nonce,
|
|
23
22
|
},
|
|
@@ -28,44 +27,36 @@ exports.getSubmitWithdrawRequestHash = getSubmitWithdrawRequestHash;
|
|
|
28
27
|
/**
|
|
29
28
|
* Compute deterministic withdrawal address
|
|
30
29
|
*
|
|
30
|
+
* @param vmType the vm type of the depository chain
|
|
31
|
+
* @param chainId the chain id of the depository contract currently holding the funds
|
|
31
32
|
* @param depository the depository contract holding the funds on origin chain (as string)
|
|
32
|
-
* @param depositoryChainId the chain id of the depository contract currently holding the funds
|
|
33
33
|
* @param currency the id of the currency as expressed on origin chain (string)
|
|
34
34
|
* @param recipient the address that will receive the withdrawn funds on destination chain
|
|
35
|
-
* @param
|
|
36
|
-
*
|
|
37
|
-
* @param withdrawalNonce nonce to prevent collisions for similar withdrawals
|
|
35
|
+
* @param ownerAlias the address that owns the balance on the settlement chain before the withdrawal is initiated
|
|
36
|
+
* @param nonce nonce to prevent collisions for similar withdrawals
|
|
38
37
|
* @returns withdrawal address (in lower case)
|
|
39
38
|
*/
|
|
40
39
|
function getWithdrawalAddress(withdrawalParams) {
|
|
41
40
|
const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string", "bytes", "bytes", "bytes", "address", "bytes32"], [
|
|
42
|
-
withdrawalParams.
|
|
43
|
-
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.depository, withdrawalParams.
|
|
44
|
-
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.currency, withdrawalParams.
|
|
45
|
-
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.recipient, withdrawalParams.
|
|
46
|
-
withdrawalParams.
|
|
47
|
-
`0x${BigInt(withdrawalParams.
|
|
41
|
+
withdrawalParams.chainId,
|
|
42
|
+
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.depository, withdrawalParams.vmType)),
|
|
43
|
+
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.currency, withdrawalParams.vmType)),
|
|
44
|
+
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.recipient, withdrawalParams.vmType)),
|
|
45
|
+
withdrawalParams.ownerAlias,
|
|
46
|
+
`0x${BigInt(withdrawalParams.nonce).toString(16).padStart(64, "0")}`,
|
|
48
47
|
]));
|
|
49
|
-
//
|
|
48
|
+
// Get 40 bytes for an address
|
|
50
49
|
const withdrawalAddress = hash.slice(2).slice(-40).toLowerCase();
|
|
51
50
|
return `0x${withdrawalAddress}`;
|
|
52
51
|
}
|
|
53
|
-
function getOrderAddress(
|
|
52
|
+
function getOrderAddress(orderParams) {
|
|
54
53
|
const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string", "bytes", "uint256", "bytes32"], [
|
|
55
|
-
|
|
56
|
-
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
orderParams.chainId,
|
|
55
|
+
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(orderParams.depositor, orderParams.vmType)),
|
|
56
|
+
orderParams.timestamp,
|
|
57
|
+
orderParams.depositId,
|
|
59
58
|
]));
|
|
59
|
+
// Get 40 bytes for an address
|
|
60
60
|
const orderAddress = hash.slice(2).slice(-40);
|
|
61
61
|
return `0x${orderAddress}`;
|
|
62
62
|
}
|
|
63
|
-
// compute a message about withdrawer balance
|
|
64
|
-
// to be signed as auth proof for the oracle
|
|
65
|
-
function computeWithdrawerBalanceMessage(withdrawerAlias, amount, withdrawalNonce) {
|
|
66
|
-
return (0, viem_1.keccak256)((0, viem_1.encodePacked)(["address", "uint256", "bytes32"], [
|
|
67
|
-
withdrawerAlias,
|
|
68
|
-
BigInt(amount),
|
|
69
|
-
withdrawalNonce,
|
|
70
|
-
]));
|
|
71
|
-
}
|