@relay-protocol/settlement-sdk 0.0.85 → 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 { SubmitWithdrawRequest, getSubmitWithdrawRequestHash, getWithdrawalAddress, getOrderAddress,
|
|
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, 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, 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.
|
|
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,7 +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, "
|
|
43
|
+
Object.defineProperty(exports, "normalizePayloadParams", { enumerable: true, get: function () { return withdrawal_execution_1.normalizePayloadParams; } });
|
|
44
44
|
const hub_utils_1 = require("./hub/hub-utils");
|
|
45
45
|
Object.defineProperty(exports, "generateAddress", { enumerable: true, get: function () { return hub_utils_1.generateAddress; } });
|
|
46
46
|
Object.defineProperty(exports, "generateTokenId", { enumerable: true, get: function () { return hub_utils_1.generateTokenId; } });
|
|
@@ -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,58 @@ 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;
|
|
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,9 +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;
|
|
6
|
-
exports.
|
|
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"));
|
|
7
47
|
const viem_1 = require("viem");
|
|
8
48
|
const hub_utils_1 = require("../../hub/hub-utils");
|
|
9
49
|
const utils_1 = require("../../utils");
|
|
@@ -17,7 +57,7 @@ const getSubmitWithdrawRequestHash = (request) => {
|
|
|
17
57
|
currency: request.currency,
|
|
18
58
|
amount: BigInt(request.amount),
|
|
19
59
|
spender: request.spender,
|
|
20
|
-
receiver: request.
|
|
60
|
+
receiver: request.recipient,
|
|
21
61
|
data: request.data,
|
|
22
62
|
nonce: request.nonce,
|
|
23
63
|
},
|
|
@@ -28,44 +68,169 @@ exports.getSubmitWithdrawRequestHash = getSubmitWithdrawRequestHash;
|
|
|
28
68
|
/**
|
|
29
69
|
* Compute deterministic withdrawal address
|
|
30
70
|
*
|
|
71
|
+
* @param vmType the vm type of the depository chain
|
|
72
|
+
* @param chainId the chain id of the depository contract currently holding the funds
|
|
31
73
|
* @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
74
|
* @param currency the id of the currency as expressed on origin chain (string)
|
|
34
75
|
* @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
|
|
76
|
+
* @param ownerAlias the address that owns the balance on the settlement chain before the withdrawal is initiated
|
|
77
|
+
* @param nonce nonce to prevent collisions for similar withdrawals
|
|
38
78
|
* @returns withdrawal address (in lower case)
|
|
39
79
|
*/
|
|
40
80
|
function getWithdrawalAddress(withdrawalParams) {
|
|
41
81
|
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.
|
|
82
|
+
withdrawalParams.chainId,
|
|
83
|
+
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.depository, withdrawalParams.vmType)),
|
|
84
|
+
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.currency, withdrawalParams.vmType)),
|
|
85
|
+
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(withdrawalParams.recipient, withdrawalParams.vmType)),
|
|
86
|
+
withdrawalParams.ownerAlias,
|
|
87
|
+
`0x${BigInt(withdrawalParams.nonce).toString(16).padStart(64, "0")}`,
|
|
48
88
|
]));
|
|
49
|
-
//
|
|
89
|
+
// Get 40 bytes for an address
|
|
50
90
|
const withdrawalAddress = hash.slice(2).slice(-40).toLowerCase();
|
|
51
91
|
return `0x${withdrawalAddress}`;
|
|
52
92
|
}
|
|
53
|
-
function getOrderAddress(
|
|
93
|
+
function getOrderAddress(orderParams) {
|
|
54
94
|
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
|
-
|
|
95
|
+
orderParams.chainId,
|
|
96
|
+
(0, hub_utils_1.arrayToHex)((0, utils_1.encodeAddress)(orderParams.depositor, orderParams.vmType)),
|
|
97
|
+
orderParams.timestamp,
|
|
98
|
+
orderParams.depositId,
|
|
59
99
|
]));
|
|
100
|
+
// Get 40 bytes for an address
|
|
60
101
|
const orderAddress = hash.slice(2).slice(-40);
|
|
61
102
|
return `0x${orderAddress}`;
|
|
62
103
|
}
|
|
63
|
-
|
|
64
|
-
// to be signed as auth proof for the oracle
|
|
65
|
-
function computeWithdrawerBalanceMessage(withdrawerAlias, amount, withdrawalNonce) {
|
|
104
|
+
function getWithdrawalInitiationHash(withdrawerAlias, amount, withdrawalNonce) {
|
|
66
105
|
return (0, viem_1.keccak256)((0, viem_1.encodePacked)(["address", "uint256", "bytes32"], [
|
|
67
106
|
withdrawerAlias,
|
|
68
107
|
BigInt(amount),
|
|
69
108
|
withdrawalNonce,
|
|
70
109
|
]));
|
|
71
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.
|
|
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",
|