@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,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSolverFillMessageId = exports.SolverFillStatus = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const order_1 = require("../../order");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
var SolverFillStatus;
|
|
8
|
+
(function (SolverFillStatus) {
|
|
9
|
+
SolverFillStatus[SolverFillStatus["FAILED"] = 0] = "FAILED";
|
|
10
|
+
SolverFillStatus[SolverFillStatus["SUCCESSFUL"] = 1] = "SUCCESSFUL";
|
|
11
|
+
})(SolverFillStatus || (exports.SolverFillStatus = SolverFillStatus = {}));
|
|
12
|
+
const getSolverFillMessageId = (message, chainsConfig) => {
|
|
13
|
+
const vmType = (chainId) => (0, utils_1.getChainVmType)(chainId, chainsConfig);
|
|
14
|
+
return (0, viem_1.hashStruct)({
|
|
15
|
+
types: {
|
|
16
|
+
SolverFill: [
|
|
17
|
+
{ name: "data", type: "Data" },
|
|
18
|
+
{ name: "result", type: "Result" },
|
|
19
|
+
],
|
|
20
|
+
Data: [
|
|
21
|
+
{ name: "order", type: "Order" },
|
|
22
|
+
{ name: "orderSignature", type: "bytes" },
|
|
23
|
+
{ name: "inputs", type: "InputEntry[]" },
|
|
24
|
+
{ name: "fill", type: "FillEntry" },
|
|
25
|
+
],
|
|
26
|
+
Result: [
|
|
27
|
+
{ name: "orderId", type: "bytes32" },
|
|
28
|
+
{ name: "status", type: "uint8" },
|
|
29
|
+
{ name: "totalWeightedInputPaymentBpsDiff", type: "int256" },
|
|
30
|
+
],
|
|
31
|
+
...order_1.ORDER_EIP712_TYPES,
|
|
32
|
+
InputEntry: [
|
|
33
|
+
{ name: "transactionId", type: "bytes" },
|
|
34
|
+
{ name: "onchainId", type: "bytes32" },
|
|
35
|
+
{ name: "inputIndex", type: "uint32" },
|
|
36
|
+
],
|
|
37
|
+
FillEntry: [{ name: "transactionId", type: "bytes" }],
|
|
38
|
+
},
|
|
39
|
+
primaryType: "SolverFill",
|
|
40
|
+
data: {
|
|
41
|
+
data: {
|
|
42
|
+
order: (0, order_1.normalizeOrder)(message.data.order, chainsConfig),
|
|
43
|
+
orderSignature: (0, utils_1.encodeBytes)(message.data.orderSignature),
|
|
44
|
+
inputs: message.data.inputs.map((input) => ({
|
|
45
|
+
transactionId: (0, utils_1.encodeTransactionId)(input.transactionId, vmType(message.data.order.inputs[input.inputIndex].payment.chainId)),
|
|
46
|
+
onchainId: (0, viem_1.bytesToHex)((0, utils_1.encodeBytes)(input.onchainId)),
|
|
47
|
+
inputIndex: input.inputIndex,
|
|
48
|
+
})),
|
|
49
|
+
fill: {
|
|
50
|
+
transactionId: (0, utils_1.encodeTransactionId)(message.data.fill.transactionId, vmType(message.data.order.output.chainId)),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
result: {
|
|
54
|
+
orderId: (0, viem_1.bytesToHex)((0, utils_1.encodeBytes)(message.result.orderId)),
|
|
55
|
+
status: message.result.status,
|
|
56
|
+
totalWeightedInputPaymentBpsDiff: message.result.totalWeightedInputPaymentBpsDiff,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
exports.getSolverFillMessageId = getSolverFillMessageId;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Order } from "../../order";
|
|
2
|
+
import { ChainIdToVmType } from "../../utils";
|
|
3
|
+
export declare enum SolverRefundStatus {
|
|
4
|
+
FAILED = 0,
|
|
5
|
+
SUCCESSFUL = 1
|
|
6
|
+
}
|
|
7
|
+
export type SolverRefundMessage = {
|
|
8
|
+
data: {
|
|
9
|
+
order: Order;
|
|
10
|
+
orderSignature: string;
|
|
11
|
+
inputs: {
|
|
12
|
+
transactionId: string;
|
|
13
|
+
onchainId: string;
|
|
14
|
+
inputIndex: number;
|
|
15
|
+
}[];
|
|
16
|
+
refunds: {
|
|
17
|
+
transactionId: string;
|
|
18
|
+
inputIndex: number;
|
|
19
|
+
refundIndex: number;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
result: {
|
|
23
|
+
orderId: string;
|
|
24
|
+
status: SolverRefundStatus;
|
|
25
|
+
totalWeightedInputPaymentBpsDiff: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare const getSolverRefundMessageId: (message: SolverRefundMessage, chainsConfig: ChainIdToVmType) => `0x${string}`;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSolverRefundMessageId = exports.SolverRefundStatus = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const order_1 = require("../../order");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
var SolverRefundStatus;
|
|
8
|
+
(function (SolverRefundStatus) {
|
|
9
|
+
SolverRefundStatus[SolverRefundStatus["FAILED"] = 0] = "FAILED";
|
|
10
|
+
SolverRefundStatus[SolverRefundStatus["SUCCESSFUL"] = 1] = "SUCCESSFUL";
|
|
11
|
+
})(SolverRefundStatus || (exports.SolverRefundStatus = SolverRefundStatus = {}));
|
|
12
|
+
const getSolverRefundMessageId = (message, chainsConfig) => {
|
|
13
|
+
const vmType = (chainId) => (0, utils_1.getChainVmType)(chainId, chainsConfig);
|
|
14
|
+
return (0, viem_1.hashStruct)({
|
|
15
|
+
types: {
|
|
16
|
+
SolverRefund: [
|
|
17
|
+
{ name: "data", type: "Data" },
|
|
18
|
+
{ name: "result", type: "Result" },
|
|
19
|
+
],
|
|
20
|
+
Data: [
|
|
21
|
+
{ name: "order", type: "Order" },
|
|
22
|
+
{ name: "orderSignature", type: "bytes" },
|
|
23
|
+
{ name: "inputs", type: "InputEntry[]" },
|
|
24
|
+
{ name: "refunds", type: "RefundEntry[]" },
|
|
25
|
+
],
|
|
26
|
+
Result: [
|
|
27
|
+
{ name: "orderId", type: "bytes32" },
|
|
28
|
+
{ name: "status", type: "uint8" },
|
|
29
|
+
{ name: "totalWeightedInputPaymentBpsDiff", type: "int256" },
|
|
30
|
+
],
|
|
31
|
+
...order_1.ORDER_EIP712_TYPES,
|
|
32
|
+
InputEntry: [
|
|
33
|
+
{ name: "transactionId", type: "bytes" },
|
|
34
|
+
{ name: "onchainId", type: "bytes32" },
|
|
35
|
+
{ name: "inputIndex", type: "uint32" },
|
|
36
|
+
],
|
|
37
|
+
RefundEntry: [
|
|
38
|
+
{ name: "transactionId", type: "bytes" },
|
|
39
|
+
{ name: "inputIndex", type: "uint32" },
|
|
40
|
+
{ name: "refundIndex", type: "uint32" },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
primaryType: "SolverRefund",
|
|
44
|
+
data: {
|
|
45
|
+
data: {
|
|
46
|
+
order: (0, order_1.normalizeOrder)(message.data.order, chainsConfig),
|
|
47
|
+
orderSignature: (0, utils_1.encodeBytes)(message.data.orderSignature),
|
|
48
|
+
inputs: message.data.inputs.map((input) => ({
|
|
49
|
+
transactionId: (0, utils_1.encodeTransactionId)(input.transactionId, vmType(message.data.order.inputs[input.inputIndex].payment.chainId)),
|
|
50
|
+
onchainId: (0, viem_1.bytesToHex)((0, utils_1.encodeBytes)(input.onchainId)),
|
|
51
|
+
inputIndex: input.inputIndex,
|
|
52
|
+
})),
|
|
53
|
+
refunds: message.data.refunds.map((refund) => ({
|
|
54
|
+
transactionId: (0, utils_1.encodeTransactionId)(refund.transactionId, vmType(message.data.order.inputs[refund.inputIndex].refunds[refund.refundIndex].chainId)),
|
|
55
|
+
inputIndex: refund.inputIndex,
|
|
56
|
+
refundIndex: refund.refundIndex,
|
|
57
|
+
})),
|
|
58
|
+
},
|
|
59
|
+
result: {
|
|
60
|
+
orderId: (0, viem_1.bytesToHex)((0, utils_1.encodeBytes)(message.result.orderId)),
|
|
61
|
+
status: message.result.status,
|
|
62
|
+
totalWeightedInputPaymentBpsDiff: message.result.totalWeightedInputPaymentBpsDiff,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
exports.getSolverRefundMessageId = getSolverRefundMessageId;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { VmType } from "../../utils";
|
|
2
|
+
export declare enum ActionType {
|
|
3
|
+
MINT = 0,
|
|
4
|
+
BURN = 1,
|
|
5
|
+
TRANSFER = 2
|
|
6
|
+
}
|
|
7
|
+
export type ExecutionMessageMetadata = {
|
|
8
|
+
hubTokenId: bigint;
|
|
9
|
+
origin: {
|
|
10
|
+
address: string;
|
|
11
|
+
chainId: bigint;
|
|
12
|
+
family: VmType;
|
|
13
|
+
};
|
|
14
|
+
oracleChainId: string;
|
|
15
|
+
oracleContract: `0x${string}`;
|
|
16
|
+
};
|
|
17
|
+
export type ExecutionMessage = {
|
|
18
|
+
idempotencyKey: string;
|
|
19
|
+
actions: string[];
|
|
20
|
+
metadata?: ExecutionMessageMetadata[];
|
|
21
|
+
};
|
|
22
|
+
export type ExecutionMetadata = Omit<ExecutionMessageMetadata, "oracleContract" | "oracleChainId">;
|
|
23
|
+
export declare const getExecutionMessageId: (message: ExecutionMessage) => `0x${string}`;
|
|
24
|
+
export type DecodedAction = {
|
|
25
|
+
type: ActionType.MINT;
|
|
26
|
+
data: {
|
|
27
|
+
hubToAddress: string;
|
|
28
|
+
hubTokenId: bigint;
|
|
29
|
+
amount: string;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
type: ActionType.BURN;
|
|
33
|
+
data: {
|
|
34
|
+
hubFromAddress: string;
|
|
35
|
+
hubTokenId: bigint;
|
|
36
|
+
amount: string;
|
|
37
|
+
};
|
|
38
|
+
} | {
|
|
39
|
+
type: ActionType.TRANSFER;
|
|
40
|
+
data: {
|
|
41
|
+
hubFromAddress: string;
|
|
42
|
+
hubToAddress: string;
|
|
43
|
+
hubTokenId: bigint;
|
|
44
|
+
amount: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export declare const encodeAction: (action: DecodedAction) => string;
|
|
48
|
+
export declare const decodeAction: (action: string) => DecodedAction;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeAction = exports.encodeAction = exports.getExecutionMessageId = exports.ActionType = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
var ActionType;
|
|
6
|
+
(function (ActionType) {
|
|
7
|
+
ActionType[ActionType["MINT"] = 0] = "MINT";
|
|
8
|
+
ActionType[ActionType["BURN"] = 1] = "BURN";
|
|
9
|
+
ActionType[ActionType["TRANSFER"] = 2] = "TRANSFER";
|
|
10
|
+
})(ActionType || (exports.ActionType = ActionType = {}));
|
|
11
|
+
const getExecutionMessageId = (message) => {
|
|
12
|
+
return (0, viem_1.hashStruct)({
|
|
13
|
+
types: {
|
|
14
|
+
Execution: [
|
|
15
|
+
{ name: "idempotencyKey", type: "bytes32" },
|
|
16
|
+
{ name: "actions", type: "bytes[]" },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
primaryType: "Execution",
|
|
20
|
+
data: {
|
|
21
|
+
idempotencyKey: message.idempotencyKey,
|
|
22
|
+
actions: message.actions,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
exports.getExecutionMessageId = getExecutionMessageId;
|
|
27
|
+
const encodeAction = (action) => {
|
|
28
|
+
switch (action.type) {
|
|
29
|
+
case ActionType.MINT: {
|
|
30
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
31
|
+
"uint8 type",
|
|
32
|
+
"address hubToAddress",
|
|
33
|
+
"uint256 hubTokenId",
|
|
34
|
+
"uint256 amount",
|
|
35
|
+
]), [
|
|
36
|
+
action.type,
|
|
37
|
+
action.data.hubToAddress,
|
|
38
|
+
action.data.hubTokenId,
|
|
39
|
+
BigInt(action.data.amount),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
case ActionType.BURN: {
|
|
43
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
44
|
+
"uint8 type",
|
|
45
|
+
"address hubFromAddress",
|
|
46
|
+
"uint256 hubTokenId",
|
|
47
|
+
"uint256 amount",
|
|
48
|
+
]), [
|
|
49
|
+
action.type,
|
|
50
|
+
action.data.hubFromAddress,
|
|
51
|
+
action.data.hubTokenId,
|
|
52
|
+
BigInt(action.data.amount),
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
case ActionType.TRANSFER: {
|
|
56
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
57
|
+
"uint8 type",
|
|
58
|
+
"address hubFromAddress",
|
|
59
|
+
"address hubToAddress",
|
|
60
|
+
"uint256 hubTokenId",
|
|
61
|
+
"uint256 amount",
|
|
62
|
+
]), [
|
|
63
|
+
action.type,
|
|
64
|
+
action.data.hubFromAddress,
|
|
65
|
+
action.data.hubToAddress,
|
|
66
|
+
action.data.hubTokenId,
|
|
67
|
+
BigInt(action.data.amount),
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
default: {
|
|
71
|
+
throw new Error("Unsupported action type");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.encodeAction = encodeAction;
|
|
76
|
+
const decodeAction = (action) => {
|
|
77
|
+
// decode just the uint8 type
|
|
78
|
+
const [type] = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)(["uint8 type"]), action);
|
|
79
|
+
switch (type) {
|
|
80
|
+
case ActionType.MINT: {
|
|
81
|
+
const result = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
82
|
+
"uint8 type",
|
|
83
|
+
"address hubToAddress",
|
|
84
|
+
"uint256 hubTokenId",
|
|
85
|
+
"uint256 amount",
|
|
86
|
+
]), action);
|
|
87
|
+
return {
|
|
88
|
+
type: ActionType.MINT,
|
|
89
|
+
data: {
|
|
90
|
+
hubToAddress: result[1].toString(),
|
|
91
|
+
hubTokenId: result[2],
|
|
92
|
+
amount: result[3].toString(),
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
case ActionType.BURN: {
|
|
97
|
+
const result = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
98
|
+
"uint8 type",
|
|
99
|
+
"address hubFromAddress",
|
|
100
|
+
"uint256 hubTokenId",
|
|
101
|
+
"uint256 amount",
|
|
102
|
+
]), action);
|
|
103
|
+
return {
|
|
104
|
+
type: ActionType.BURN,
|
|
105
|
+
data: {
|
|
106
|
+
hubFromAddress: result[1].toString(),
|
|
107
|
+
hubTokenId: result[2],
|
|
108
|
+
amount: result[3].toString(),
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
case ActionType.TRANSFER: {
|
|
113
|
+
const result = (0, viem_1.decodeAbiParameters)((0, viem_1.parseAbiParameters)([
|
|
114
|
+
"uint8 type",
|
|
115
|
+
"address hubFromAddress",
|
|
116
|
+
"address hubToAddress",
|
|
117
|
+
"uint256 hubTokenId",
|
|
118
|
+
"uint256 amount",
|
|
119
|
+
]), action);
|
|
120
|
+
return {
|
|
121
|
+
type: ActionType.TRANSFER,
|
|
122
|
+
data: {
|
|
123
|
+
hubFromAddress: result[1].toString(),
|
|
124
|
+
hubToAddress: result[2].toString(),
|
|
125
|
+
hubTokenId: result[3],
|
|
126
|
+
amount: result[4].toString(),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
default: {
|
|
131
|
+
throw new Error("Unsupported action type");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
exports.decodeAction = decodeAction;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface SubmitWithdrawRequest {
|
|
2
|
+
chainId: string;
|
|
3
|
+
depository: string;
|
|
4
|
+
currency: string;
|
|
5
|
+
amount: string;
|
|
6
|
+
spender: string;
|
|
7
|
+
receiver: string;
|
|
8
|
+
data: string;
|
|
9
|
+
nonce: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const getSubmitWithdrawRequestHash: (request: SubmitWithdrawRequest) => `0x${string}`;
|
|
12
|
+
export type WithdrawalAddressParams = {
|
|
13
|
+
depositoryAddress: string;
|
|
14
|
+
depositoryChainId: bigint;
|
|
15
|
+
currency: string;
|
|
16
|
+
recipientAddress: string;
|
|
17
|
+
withdrawerAlias: string;
|
|
18
|
+
amount: bigint;
|
|
19
|
+
withdrawalNonce: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Compute deterministic withdrawal address
|
|
23
|
+
*
|
|
24
|
+
* @param depositoryAddress the depository contract holding the funds on origin chain
|
|
25
|
+
* @param depositoryChainId the chain id of the depository contract currently holding the funds
|
|
26
|
+
* @param currency the id of the currency as expressed on origin chain (string)
|
|
27
|
+
* @param recipientAddress the address that will receive the withdrawn funds on destination chain
|
|
28
|
+
* @param withdrawerAlias the address that owns the balance on the settlement chain
|
|
29
|
+
* before the withdrawal is initiated
|
|
30
|
+
* @param amount the balance to withdraw
|
|
31
|
+
* @param withdrawalNonce nonce to prevent collisions for similar withdrawals
|
|
32
|
+
* @returns withdrawal address (in lower case)
|
|
33
|
+
*/
|
|
34
|
+
export declare function getWithdrawalAddress(withdrawalParams: WithdrawalAddressParams): string;
|
|
35
|
+
export type WithdrawalAddressRequest = Omit<WithdrawalAddressParams, "depositoryChainId" | "amount"> & {
|
|
36
|
+
depositoryChainSlug: string;
|
|
37
|
+
amount: string;
|
|
38
|
+
};
|
|
39
|
+
export type WithdrawalInitiationMessage = {
|
|
40
|
+
data: WithdrawalAddressRequest & {
|
|
41
|
+
settlementChainId: string;
|
|
42
|
+
};
|
|
43
|
+
result: {
|
|
44
|
+
withdrawalAddress: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type WithdrawalInitiatedMessage = {
|
|
48
|
+
data: WithdrawalAddressRequest & {
|
|
49
|
+
settlementChainId: string;
|
|
50
|
+
};
|
|
51
|
+
result: {
|
|
52
|
+
proofOfWithdrawalAddressBalance: string;
|
|
53
|
+
withdrawalAddress: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSubmitWithdrawRequestHash = void 0;
|
|
4
|
+
exports.getWithdrawalAddress = getWithdrawalAddress;
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const getSubmitWithdrawRequestHash = (request) => {
|
|
7
|
+
// EIP712 type from RelayAllocator
|
|
8
|
+
const PAYLOAD_TYPEHASH = (0, viem_1.keccak256)("SubmitWithdrawRequest(uint256 chainId,string depository,string currency,uint256 amount,address spender,string receiver,bytes data,bytes32 nonce)");
|
|
9
|
+
// Create EIP712 digest
|
|
10
|
+
const digest = (0, viem_1.keccak256)((0, viem_1.encodePacked)([
|
|
11
|
+
"bytes32",
|
|
12
|
+
"uint256",
|
|
13
|
+
"bytes32",
|
|
14
|
+
"bytes32",
|
|
15
|
+
"uint256",
|
|
16
|
+
"address",
|
|
17
|
+
"bytes32",
|
|
18
|
+
"bytes32",
|
|
19
|
+
"bytes32",
|
|
20
|
+
], [
|
|
21
|
+
PAYLOAD_TYPEHASH,
|
|
22
|
+
BigInt(request.chainId),
|
|
23
|
+
(0, viem_1.keccak256)(request.depository),
|
|
24
|
+
(0, viem_1.keccak256)(request.currency),
|
|
25
|
+
BigInt(request.amount),
|
|
26
|
+
request.spender,
|
|
27
|
+
(0, viem_1.keccak256)(request.receiver),
|
|
28
|
+
(0, viem_1.keccak256)(request.data),
|
|
29
|
+
request.nonce,
|
|
30
|
+
]));
|
|
31
|
+
// The withdrawal address is the digest itself (as a hex string)
|
|
32
|
+
return digest;
|
|
33
|
+
};
|
|
34
|
+
exports.getSubmitWithdrawRequestHash = getSubmitWithdrawRequestHash;
|
|
35
|
+
/**
|
|
36
|
+
* Compute deterministic withdrawal address
|
|
37
|
+
*
|
|
38
|
+
* @param depositoryAddress the depository contract holding the funds on origin chain
|
|
39
|
+
* @param depositoryChainId the chain id of the depository contract currently holding the funds
|
|
40
|
+
* @param currency the id of the currency as expressed on origin chain (string)
|
|
41
|
+
* @param recipientAddress the address that will receive the withdrawn funds on destination chain
|
|
42
|
+
* @param withdrawerAlias the address that owns the balance on the settlement chain
|
|
43
|
+
* before the withdrawal is initiated
|
|
44
|
+
* @param amount the balance to withdraw
|
|
45
|
+
* @param withdrawalNonce nonce to prevent collisions for similar withdrawals
|
|
46
|
+
* @returns withdrawal address (in lower case)
|
|
47
|
+
*/
|
|
48
|
+
function getWithdrawalAddress(withdrawalParams) {
|
|
49
|
+
// pack and hash data
|
|
50
|
+
const nonce = (0, viem_1.keccak256)((0, viem_1.encodePacked)(["string"], [withdrawalParams.withdrawalNonce]));
|
|
51
|
+
const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)([
|
|
52
|
+
"address",
|
|
53
|
+
"uint256",
|
|
54
|
+
"string",
|
|
55
|
+
"address",
|
|
56
|
+
"address",
|
|
57
|
+
"uint256",
|
|
58
|
+
"bytes32",
|
|
59
|
+
], [
|
|
60
|
+
withdrawalParams.depositoryAddress,
|
|
61
|
+
withdrawalParams.depositoryChainId,
|
|
62
|
+
withdrawalParams.currency,
|
|
63
|
+
withdrawalParams.recipientAddress,
|
|
64
|
+
withdrawalParams.withdrawerAlias,
|
|
65
|
+
withdrawalParams.amount,
|
|
66
|
+
nonce,
|
|
67
|
+
]));
|
|
68
|
+
// get 40 bytes for an address
|
|
69
|
+
const withdrawalAddress = hash.slice(2).slice(-40).toLowerCase();
|
|
70
|
+
return `0x${withdrawalAddress}`;
|
|
71
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ChainIdToVmType, VmType } from "../utils";
|
|
2
|
+
export type Order = {
|
|
3
|
+
version: "v1";
|
|
4
|
+
solverChainId: string;
|
|
5
|
+
solver: string;
|
|
6
|
+
salt: string;
|
|
7
|
+
inputs: {
|
|
8
|
+
payment: {
|
|
9
|
+
chainId: string;
|
|
10
|
+
currency: string;
|
|
11
|
+
amount: string;
|
|
12
|
+
weight: string;
|
|
13
|
+
};
|
|
14
|
+
refunds: {
|
|
15
|
+
chainId: string;
|
|
16
|
+
recipient: string;
|
|
17
|
+
currency: string;
|
|
18
|
+
minimumAmount: string;
|
|
19
|
+
deadline: number;
|
|
20
|
+
extraData: string;
|
|
21
|
+
}[];
|
|
22
|
+
}[];
|
|
23
|
+
output: {
|
|
24
|
+
chainId: string;
|
|
25
|
+
payments: {
|
|
26
|
+
recipient: string;
|
|
27
|
+
currency: string;
|
|
28
|
+
minimumAmount: string;
|
|
29
|
+
expectedAmount: string;
|
|
30
|
+
}[];
|
|
31
|
+
calls: string[];
|
|
32
|
+
deadline: number;
|
|
33
|
+
extraData: string;
|
|
34
|
+
};
|
|
35
|
+
fees: {
|
|
36
|
+
recipientChainId: string;
|
|
37
|
+
recipient: string;
|
|
38
|
+
currencyChainId: string;
|
|
39
|
+
currency: string;
|
|
40
|
+
amount: string;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
export declare const ORDER_EIP712_TYPES: {
|
|
44
|
+
Order: {
|
|
45
|
+
name: string;
|
|
46
|
+
type: string;
|
|
47
|
+
}[];
|
|
48
|
+
Input: {
|
|
49
|
+
name: string;
|
|
50
|
+
type: string;
|
|
51
|
+
}[];
|
|
52
|
+
InputPayment: {
|
|
53
|
+
name: string;
|
|
54
|
+
type: string;
|
|
55
|
+
}[];
|
|
56
|
+
InputRefund: {
|
|
57
|
+
name: string;
|
|
58
|
+
type: string;
|
|
59
|
+
}[];
|
|
60
|
+
Output: {
|
|
61
|
+
name: string;
|
|
62
|
+
type: string;
|
|
63
|
+
}[];
|
|
64
|
+
OutputPayment: {
|
|
65
|
+
name: string;
|
|
66
|
+
type: string;
|
|
67
|
+
}[];
|
|
68
|
+
Fee: {
|
|
69
|
+
name: string;
|
|
70
|
+
type: string;
|
|
71
|
+
}[];
|
|
72
|
+
};
|
|
73
|
+
export declare const normalizeOrder: (order: Order, chainsConfig: ChainIdToVmType) => {
|
|
74
|
+
version: "v1";
|
|
75
|
+
solverChainId: string;
|
|
76
|
+
solver: string;
|
|
77
|
+
salt: string;
|
|
78
|
+
inputs: {
|
|
79
|
+
payment: {
|
|
80
|
+
chainId: string;
|
|
81
|
+
currency: Uint8Array<ArrayBufferLike>;
|
|
82
|
+
amount: string;
|
|
83
|
+
weight: string;
|
|
84
|
+
};
|
|
85
|
+
refunds: {
|
|
86
|
+
chainId: string;
|
|
87
|
+
recipient: Uint8Array<ArrayBufferLike>;
|
|
88
|
+
currency: Uint8Array<ArrayBufferLike>;
|
|
89
|
+
minimumAmount: string;
|
|
90
|
+
deadline: number;
|
|
91
|
+
extraData: import("viem").ByteArray;
|
|
92
|
+
}[];
|
|
93
|
+
}[];
|
|
94
|
+
output: {
|
|
95
|
+
chainId: string;
|
|
96
|
+
payments: {
|
|
97
|
+
recipient: Uint8Array<ArrayBufferLike>;
|
|
98
|
+
currency: Uint8Array<ArrayBufferLike>;
|
|
99
|
+
minimumAmount: string;
|
|
100
|
+
expectedAmount: string;
|
|
101
|
+
}[];
|
|
102
|
+
calls: import("viem").ByteArray[];
|
|
103
|
+
deadline: number;
|
|
104
|
+
extraData: import("viem").ByteArray;
|
|
105
|
+
};
|
|
106
|
+
fees: {
|
|
107
|
+
recipientChainId: string;
|
|
108
|
+
recipient: Uint8Array<ArrayBufferLike>;
|
|
109
|
+
currencyChainId: string;
|
|
110
|
+
currency: Uint8Array<ArrayBufferLike>;
|
|
111
|
+
amount: string;
|
|
112
|
+
}[];
|
|
113
|
+
};
|
|
114
|
+
export declare const getOrderId: (order: Order, config: ChainIdToVmType) => `0x${string}`;
|
|
115
|
+
type DecodedCall = {
|
|
116
|
+
vmType: "ethereum-vm";
|
|
117
|
+
call: {
|
|
118
|
+
to: string;
|
|
119
|
+
data: string;
|
|
120
|
+
value: string;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export declare const encodeOrderCall: (call: DecodedCall) => string;
|
|
124
|
+
export declare const decodeOrderCall: (call: string, vmType: VmType) => DecodedCall;
|
|
125
|
+
type DecodedExtraDataEthereumVm = {
|
|
126
|
+
vmType: "ethereum-vm";
|
|
127
|
+
extraData: {
|
|
128
|
+
fillContract: string;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
type DecodedExtraDataTronVm = {
|
|
132
|
+
vmType: "tron-vm";
|
|
133
|
+
extraData: {
|
|
134
|
+
fillContract: string;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
type DecodedExtraData = DecodedExtraDataEthereumVm | DecodedExtraDataTronVm;
|
|
138
|
+
export declare const encodeOrderExtraData: (extraData: DecodedExtraData) => string;
|
|
139
|
+
export declare const decodeOrderExtraData: (extraData: string, vmType: VmType) => DecodedExtraData;
|
|
140
|
+
export {};
|