@velora-dex/sdk 8.0.0 → 8.1.1-dev.0
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 +73 -11
- package/dist/examples/helpers/delta.d.ts +5 -0
- package/dist/examples/helpers/delta.d.ts.map +1 -0
- package/dist/helpers/misc.d.ts +4 -0
- package/dist/helpers/misc.d.ts.map +1 -1
- package/dist/helpers/providers/viem.d.ts +1 -1
- package/dist/helpers/providers/viem.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/methods/delta/buildCrosschainOrderBridge.d.ts +1 -1
- package/dist/methods/delta/buildCrosschainOrderBridge.d.ts.map +1 -1
- package/dist/methods/delta/buildDeltaOrder.d.ts +9 -6
- package/dist/methods/delta/buildDeltaOrder.d.ts.map +1 -1
- package/dist/methods/delta/cancelDeltaOrder.d.ts +22 -0
- package/dist/methods/delta/cancelDeltaOrder.d.ts.map +1 -0
- package/dist/methods/delta/getDeltaOrders.d.ts +11 -1
- package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
- package/dist/methods/delta/getDeltaPrice.d.ts +28 -9
- package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
- package/dist/methods/delta/helpers/across.d.ts +3 -6
- package/dist/methods/delta/helpers/across.d.ts.map +1 -1
- package/dist/methods/delta/helpers/buildCancelDeltaOrderData.d.ts +25 -0
- package/dist/methods/delta/helpers/buildCancelDeltaOrderData.d.ts.map +1 -0
- package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts +3 -3
- package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts.map +1 -1
- package/dist/methods/delta/helpers/misc.d.ts +1 -1
- package/dist/methods/delta/helpers/misc.d.ts.map +1 -1
- package/dist/methods/delta/helpers/types.d.ts +34 -6
- package/dist/methods/delta/helpers/types.d.ts.map +1 -1
- package/dist/methods/delta/index.d.ts +7 -5
- package/dist/methods/delta/index.d.ts.map +1 -1
- package/dist/methods/delta/postDeltaOrder.d.ts +9 -1
- package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -1
- package/dist/methods/quote/getQuote.d.ts +27 -6
- package/dist/methods/quote/getQuote.d.ts.map +1 -1
- package/dist/sdk.cjs.development.js +364 -490
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +364 -491
- package/dist/sdk.esm.js.map +1 -1
- package/docs/DELTA.md +69 -7
- package/package.json +1 -1
- package/src/examples/delta.ts +5 -10
- package/src/examples/helpers/delta.ts +39 -0
- package/src/examples/quote.ts +6 -8
- package/src/examples/simpleQuote.ts +3 -5
- package/src/helpers/misc.ts +8 -0
- package/src/helpers/providers/viem.ts +4 -1
- package/src/index.ts +6 -0
- package/src/methods/delta/buildCrosschainOrderBridge.ts +25 -13
- package/src/methods/delta/buildDeltaOrder.ts +36 -66
- package/src/methods/delta/cancelDeltaOrder.ts +111 -0
- package/src/methods/delta/getDeltaOrders.ts +38 -0
- package/src/methods/delta/getDeltaPrice.ts +59 -14
- package/src/methods/delta/helpers/across.ts +26 -92
- package/src/methods/delta/helpers/buildCancelDeltaOrderData.ts +48 -0
- package/src/methods/delta/helpers/buildDeltaOrderData.ts +36 -11
- package/src/methods/delta/helpers/misc.ts +6 -2
- package/src/methods/delta/helpers/types.ts +55 -7
- package/src/methods/delta/index.ts +19 -4
- package/src/methods/delta/postDeltaOrder.ts +11 -1
- package/src/methods/quote/getQuote.ts +60 -9
- package/dist/methods/delta/helpers/composePermit.d.ts +0 -5
- package/dist/methods/delta/helpers/composePermit.d.ts.map +0 -1
- package/src/methods/delta/helpers/composePermit.ts +0 -76
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import { SwapSide } from '../../../constants';
|
|
2
|
+
|
|
3
|
+
enum OrderKind {
|
|
4
|
+
Sell = 0,
|
|
5
|
+
Buy = 1,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const SwapSideToOrderKind = {
|
|
9
|
+
[SwapSide.SELL]: OrderKind.Sell,
|
|
10
|
+
[SwapSide.BUY]: OrderKind.Buy,
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
1
13
|
export type DeltaAuctionOrder = {
|
|
2
14
|
/** @description The address of the order owner */
|
|
3
15
|
owner: string;
|
|
@@ -11,8 +23,12 @@ export type DeltaAuctionOrder = {
|
|
|
11
23
|
srcAmount: string; // wei
|
|
12
24
|
/** @description The minimum amount of dest token to receive */
|
|
13
25
|
destAmount: string; // wei
|
|
14
|
-
/** @description The expected amount of
|
|
15
|
-
|
|
26
|
+
/** @description The expected amount of token to receive */
|
|
27
|
+
expectedAmount: string; // wei
|
|
28
|
+
/** @description The kind of the order */
|
|
29
|
+
kind: OrderKind;
|
|
30
|
+
/** @description Metadata for the order, hex string */
|
|
31
|
+
metadata: string;
|
|
16
32
|
/** @description The deadline for the order */
|
|
17
33
|
deadline: number; // seconds
|
|
18
34
|
/** @description The nonce of the order */
|
|
@@ -26,22 +42,28 @@ export type DeltaAuctionOrder = {
|
|
|
26
42
|
};
|
|
27
43
|
|
|
28
44
|
export type Bridge = {
|
|
29
|
-
|
|
45
|
+
protocolSelector: string; // Hex string
|
|
30
46
|
destinationChainId: number;
|
|
31
47
|
/** @description The address of the output token. Same as Order.destToken but on destination chain, so can still be a different address */
|
|
32
48
|
outputToken: string;
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
scalingFactor: number;
|
|
50
|
+
|
|
51
|
+
/** @description Data specific to the protocol */
|
|
52
|
+
protocolData: string; // Hex string
|
|
35
53
|
};
|
|
36
54
|
|
|
37
55
|
type DeltaAuctionStatus =
|
|
38
56
|
| 'NOT_STARTED'
|
|
39
|
-
| 'POSTED'
|
|
40
57
|
| 'RUNNING'
|
|
41
58
|
| 'EXECUTING'
|
|
42
59
|
| 'EXECUTED'
|
|
43
60
|
| 'FAILED'
|
|
44
|
-
| 'EXPIRED'
|
|
61
|
+
| 'EXPIRED'
|
|
62
|
+
| 'CANCELLED'; // @TODO check if added
|
|
63
|
+
// these are not exposed, but are coerced into FAILED
|
|
64
|
+
// | 'INSUFFICIENT_BALANCE'
|
|
65
|
+
// | 'INSUFFICIENT_ALLOWANCE'
|
|
66
|
+
// | 'INVALIDATED';
|
|
45
67
|
|
|
46
68
|
type DeltaAuctionTransaction = {
|
|
47
69
|
id: string;
|
|
@@ -91,6 +113,12 @@ export type DeltaAuction = {
|
|
|
91
113
|
|
|
92
114
|
bridgeMetadata: BridgeMetadata | null;
|
|
93
115
|
bridgeStatus: BridgeStatus | null;
|
|
116
|
+
|
|
117
|
+
// @TODO only returned after POST Order so far
|
|
118
|
+
// orderVersion: string; // "2.0.0"
|
|
119
|
+
// deltaGasOverhead: number;
|
|
120
|
+
|
|
121
|
+
type: 'MARKET' | 'LIMIT'; // @TODO when available in API for individual /order/:hash|:id
|
|
94
122
|
};
|
|
95
123
|
|
|
96
124
|
export type BridgeMetadata = {
|
|
@@ -108,3 +136,23 @@ export type BridgeMetadata = {
|
|
|
108
136
|
|
|
109
137
|
// refunded is basically failed
|
|
110
138
|
export type BridgeStatus = 'pending' | 'filled' | 'expired' | 'refunded';
|
|
139
|
+
|
|
140
|
+
//// available on BridgePrice ////
|
|
141
|
+
|
|
142
|
+
// so far
|
|
143
|
+
type ProtocolName = 'Across' | 'StargateBus' | 'StargateTaxi';
|
|
144
|
+
|
|
145
|
+
type BridgeQuoteFee = {
|
|
146
|
+
feeToken: string;
|
|
147
|
+
amount: string;
|
|
148
|
+
amountInSrcToken: string;
|
|
149
|
+
amountInUSD: string;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export type BridgePriceInfo = {
|
|
153
|
+
protocolName: ProtocolName;
|
|
154
|
+
destAmountAfterBridge: string;
|
|
155
|
+
destUSDAfterBridge: string;
|
|
156
|
+
fees: BridgeQuoteFee[];
|
|
157
|
+
estimatedTimeMs: number;
|
|
158
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ConstructProviderFetchInput } from '../../types';
|
|
2
|
-
import type { DeltaAuction } from './helpers/types';
|
|
3
2
|
import {
|
|
4
3
|
BuildDeltaOrderDataParams,
|
|
5
4
|
BuildDeltaOrderFunctions,
|
|
@@ -7,6 +6,8 @@ import {
|
|
|
7
6
|
} from './buildDeltaOrder';
|
|
8
7
|
import {
|
|
9
8
|
constructPostDeltaOrder,
|
|
9
|
+
DeltaOrderApiResponse,
|
|
10
|
+
DeltaOrderToPost,
|
|
10
11
|
PostDeltaOrderFunctions,
|
|
11
12
|
} from './postDeltaOrder';
|
|
12
13
|
import {
|
|
@@ -49,15 +50,21 @@ import {
|
|
|
49
50
|
BuildCrosschainOrderBridgeFunctions,
|
|
50
51
|
constructBuildCrosschainOrderBridge,
|
|
51
52
|
} from './buildCrosschainOrderBridge';
|
|
53
|
+
import {
|
|
54
|
+
CancelDeltaOrderFunctions,
|
|
55
|
+
constructCancelDeltaOrder,
|
|
56
|
+
} from './cancelDeltaOrder';
|
|
52
57
|
|
|
53
58
|
export type SubmitDeltaOrderParams = BuildDeltaOrderDataParams & {
|
|
54
59
|
/** @description designates the Order as being able to be partially filled, as opposed to fill-or-kill */
|
|
55
60
|
partiallyFillable?: boolean;
|
|
56
|
-
|
|
61
|
+
/** @description Referrer address */
|
|
62
|
+
referrerAddress?: string;
|
|
63
|
+
} & Pick<DeltaOrderToPost, 'type' | 'includeAgents' | 'excludeAgents'>;
|
|
57
64
|
|
|
58
65
|
type SubmitDeltaOrder = (
|
|
59
66
|
orderParams: SubmitDeltaOrderParams
|
|
60
|
-
) => Promise<
|
|
67
|
+
) => Promise<DeltaOrderApiResponse>;
|
|
61
68
|
|
|
62
69
|
export type SubmitDeltaOrderFuncs = {
|
|
63
70
|
submitDeltaOrder: SubmitDeltaOrder;
|
|
@@ -79,6 +86,10 @@ export const constructSubmitDeltaOrder = (
|
|
|
79
86
|
partner: orderParams.partner,
|
|
80
87
|
order: orderData.data,
|
|
81
88
|
partiallyFillable: orderParams.partiallyFillable,
|
|
89
|
+
referrerAddress: orderParams.referrerAddress,
|
|
90
|
+
type: orderParams.type,
|
|
91
|
+
includeAgents: orderParams.includeAgents,
|
|
92
|
+
excludeAgents: orderParams.excludeAgents,
|
|
82
93
|
});
|
|
83
94
|
|
|
84
95
|
return response;
|
|
@@ -99,7 +110,8 @@ export type DeltaOrderHandlers<T> = SubmitDeltaOrderFuncs &
|
|
|
99
110
|
GetBridgeInfoFunctions &
|
|
100
111
|
IsTokenSupportedInDeltaFunctions &
|
|
101
112
|
PostDeltaOrderFunctions &
|
|
102
|
-
SignDeltaOrderFunctions
|
|
113
|
+
SignDeltaOrderFunctions &
|
|
114
|
+
CancelDeltaOrderFunctions;
|
|
103
115
|
|
|
104
116
|
/** @description construct SDK with every Delta Order-related method, fetching from API and Order signing */
|
|
105
117
|
export const constructAllDeltaOrdersHandlers = <TxResponse>(
|
|
@@ -128,6 +140,8 @@ export const constructAllDeltaOrdersHandlers = <TxResponse>(
|
|
|
128
140
|
const deltaOrdersSign = constructSignDeltaOrder(options);
|
|
129
141
|
const deltaOrdersPost = constructPostDeltaOrder(options);
|
|
130
142
|
|
|
143
|
+
const deltaOrdersCancel = constructCancelDeltaOrder(options);
|
|
144
|
+
|
|
131
145
|
return {
|
|
132
146
|
...deltaOrdersGetters,
|
|
133
147
|
...deltaOrdersContractGetter,
|
|
@@ -141,6 +155,7 @@ export const constructAllDeltaOrdersHandlers = <TxResponse>(
|
|
|
141
155
|
...deltaOrdersBuild,
|
|
142
156
|
...deltaOrdersSign,
|
|
143
157
|
...deltaOrdersPost,
|
|
158
|
+
...deltaOrdersCancel,
|
|
144
159
|
...buildCrosschainOrderBridge,
|
|
145
160
|
};
|
|
146
161
|
};
|
|
@@ -13,11 +13,21 @@ export type DeltaOrderToPost = {
|
|
|
13
13
|
chainId: number;
|
|
14
14
|
/** @description designates the Order as being able to partially filled, as opposed to fill-or-kill */
|
|
15
15
|
partiallyFillable?: boolean;
|
|
16
|
+
|
|
17
|
+
/** @description Type of the order. MARKET or LIMIT. Default is MARKET */
|
|
18
|
+
type?: 'MARKET' | 'LIMIT';
|
|
19
|
+
|
|
20
|
+
includeAgents?: string[];
|
|
21
|
+
excludeAgents?: string[];
|
|
16
22
|
};
|
|
17
23
|
|
|
18
24
|
export type PostDeltaOrderParams = Omit<DeltaOrderToPost, 'chainId'>;
|
|
19
25
|
|
|
20
|
-
type DeltaOrderApiResponse = DeltaAuction
|
|
26
|
+
export type DeltaOrderApiResponse = Omit<DeltaAuction, 'transactions'> & {
|
|
27
|
+
orderVersion: string; // "2.0.0"
|
|
28
|
+
deltaGasOverhead: number; // @TODO may be removed
|
|
29
|
+
type: 'MARKET' | 'LIMIT';
|
|
30
|
+
};
|
|
21
31
|
|
|
22
32
|
type PostDeltaOrder = (
|
|
23
33
|
postData: PostDeltaOrderParams,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { API_URL, SwapSide } from '../../constants';
|
|
2
2
|
import { constructSearchString } from '../../helpers/misc';
|
|
3
|
-
import type { DeltaPrice } from '../delta/getDeltaPrice';
|
|
3
|
+
import type { BridgePrice, DeltaPrice } from '../delta/getDeltaPrice';
|
|
4
4
|
import type {
|
|
5
5
|
ConstructFetchInput,
|
|
6
6
|
EnumerateLiteral,
|
|
@@ -23,8 +23,8 @@ export type QuoteParams<M extends TradeMode = TradeMode> = {
|
|
|
23
23
|
srcDecimals: number;
|
|
24
24
|
/** @description Destination Token Decimals */
|
|
25
25
|
destDecimals: number;
|
|
26
|
-
/** @description SELL or BUY */
|
|
27
|
-
side
|
|
26
|
+
/** @description SELL or BUY, default is SELL */
|
|
27
|
+
side?: SwapSideUnion;
|
|
28
28
|
/** @description User's Wallet Address */
|
|
29
29
|
userAddress?: string;
|
|
30
30
|
/** @description Partner string */
|
|
@@ -48,6 +48,17 @@ export type QuoteWithMarketPrice = {
|
|
|
48
48
|
|
|
49
49
|
export type QuoteWithDeltaPrice = {
|
|
50
50
|
delta: DeltaPrice;
|
|
51
|
+
deltaAddress: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type QuoteWithBridgePrice = {
|
|
55
|
+
delta: BridgePrice;
|
|
56
|
+
deltaAddress: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type QuoteWithDeltaPriceAndBridgePrice = {
|
|
60
|
+
delta: DeltaPrice | BridgePrice;
|
|
61
|
+
deltaAddress: string;
|
|
51
62
|
};
|
|
52
63
|
|
|
53
64
|
export type QuoteWithMarketPriceAsFallback = QuoteWithMarketPrice & {
|
|
@@ -57,20 +68,40 @@ export type QuoteWithMarketPriceAsFallback = QuoteWithMarketPrice & {
|
|
|
57
68
|
export type QuoteResponse =
|
|
58
69
|
| QuoteWithDeltaPrice
|
|
59
70
|
| QuoteWithMarketPrice
|
|
60
|
-
|
|
|
71
|
+
| QuoteWithBridgePrice
|
|
72
|
+
| QuoteWithMarketPriceAsFallback
|
|
73
|
+
| QuoteWithDeltaPriceAndBridgePrice;
|
|
61
74
|
|
|
62
75
|
interface GetQuoteFunc {
|
|
63
76
|
(
|
|
64
|
-
options: QuoteParams<'delta'
|
|
77
|
+
options: QuoteParams<'delta'> & { destChainId?: undefined },
|
|
65
78
|
requestParams?: RequestParameters
|
|
66
79
|
): Promise<QuoteWithDeltaPrice>;
|
|
80
|
+
(
|
|
81
|
+
options: QuoteParams<'delta'> & { destChainId: number },
|
|
82
|
+
requestParams?: RequestParameters
|
|
83
|
+
): Promise<QuoteWithBridgePrice>;
|
|
84
|
+
(
|
|
85
|
+
options: QuoteParams<'delta'>,
|
|
86
|
+
requestParams?: RequestParameters
|
|
87
|
+
): Promise<QuoteWithDeltaPriceAndBridgePrice>;
|
|
67
88
|
(
|
|
68
89
|
options: QuoteParams<'market'>,
|
|
69
90
|
requestParams?: RequestParameters
|
|
70
91
|
): Promise<QuoteWithMarketPrice>;
|
|
71
|
-
(
|
|
92
|
+
(
|
|
93
|
+
options: QuoteParams<'all'> & { destChainId?: undefined },
|
|
94
|
+
requestParams?: RequestParameters
|
|
95
|
+
): Promise<
|
|
72
96
|
QuoteWithDeltaPrice | QuoteWithMarketPriceAsFallback // "all" mode tries for deltaPrice and falls back to market priceRoute
|
|
73
97
|
>;
|
|
98
|
+
(
|
|
99
|
+
options: QuoteParams<'all'> & { destChainId: number },
|
|
100
|
+
requestParams?: RequestParameters
|
|
101
|
+
): Promise<QuoteWithBridgePrice>;
|
|
102
|
+
(options: QuoteParams<'all'>, requestParams?: RequestParameters): Promise<
|
|
103
|
+
QuoteWithDeltaPriceAndBridgePrice | QuoteWithMarketPriceAsFallback // "all" mode tries for deltaPrice and falls back to market priceRoute
|
|
104
|
+
>;
|
|
74
105
|
(
|
|
75
106
|
options: QuoteParams,
|
|
76
107
|
requestParams?: RequestParameters
|
|
@@ -89,17 +120,37 @@ export const constructGetQuote = ({
|
|
|
89
120
|
const pricesUrl = `${apiURL}/quote` as const;
|
|
90
121
|
|
|
91
122
|
function getQuote(
|
|
92
|
-
options: QuoteParams<'delta'
|
|
123
|
+
options: QuoteParams<'delta'> & { destChainId?: undefined },
|
|
93
124
|
requestParams?: RequestParameters
|
|
94
125
|
): Promise<QuoteWithDeltaPrice>;
|
|
126
|
+
function getQuote(
|
|
127
|
+
options: QuoteParams<'delta'> & { destChainId: number },
|
|
128
|
+
requestParams?: RequestParameters
|
|
129
|
+
): Promise<QuoteWithBridgePrice>;
|
|
130
|
+
function getQuote(
|
|
131
|
+
options: QuoteParams<'delta'>,
|
|
132
|
+
requestParams?: RequestParameters
|
|
133
|
+
): Promise<QuoteWithDeltaPriceAndBridgePrice>;
|
|
95
134
|
function getQuote(
|
|
96
135
|
options: QuoteParams<'market'>,
|
|
97
136
|
requestParams?: RequestParameters
|
|
98
137
|
): Promise<QuoteWithMarketPrice>;
|
|
138
|
+
function getQuote(
|
|
139
|
+
options: QuoteParams<'all'> & { destChainId?: undefined },
|
|
140
|
+
requestParams?: RequestParameters
|
|
141
|
+
): Promise<
|
|
142
|
+
QuoteWithDeltaPrice | QuoteWithMarketPriceAsFallback // "all" mode tries for deltaPrice and falls back to market priceRoute
|
|
143
|
+
>;
|
|
144
|
+
function getQuote(
|
|
145
|
+
options: QuoteParams<'all'> & { destChainId: number },
|
|
146
|
+
requestParams?: RequestParameters
|
|
147
|
+
): Promise<QuoteWithBridgePrice>;
|
|
99
148
|
function getQuote(
|
|
100
149
|
options: QuoteParams<'all'>,
|
|
101
150
|
requestParams?: RequestParameters
|
|
102
|
-
): Promise<
|
|
151
|
+
): Promise<
|
|
152
|
+
QuoteWithDeltaPriceAndBridgePrice | QuoteWithMarketPriceAsFallback
|
|
153
|
+
>;
|
|
103
154
|
function getQuote(
|
|
104
155
|
options: QuoteParams,
|
|
105
156
|
requestParams?: RequestParameters
|
|
@@ -111,7 +162,7 @@ export const constructGetQuote = ({
|
|
|
111
162
|
const search = constructSearchString<QuoteQueryOptions>({
|
|
112
163
|
...options,
|
|
113
164
|
chainId,
|
|
114
|
-
|
|
165
|
+
side: options.side ?? SwapSide.SELL,
|
|
115
166
|
});
|
|
116
167
|
|
|
117
168
|
const fetchURL = `${pricesUrl}/${search}` as const;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DeltaAuctionOrder } from './types';
|
|
2
|
-
type DeltaOrderPermitInput = Pick<DeltaAuctionOrder, 'permit' | 'nonce'>;
|
|
3
|
-
export declare function composeDeltaOrderPermit({ permit, nonce, }: DeltaOrderPermitInput): string;
|
|
4
|
-
export {};
|
|
5
|
-
//# sourceMappingURL=composePermit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"composePermit.d.ts","sourceRoot":"","sources":["../../../../src/methods/delta/helpers/composePermit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C,KAAK,qBAAqB,GAAG,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC;AAEzE,wBAAgB,uBAAuB,CAAC,EACtC,MAAM,EACN,KAAK,GACN,EAAE,qBAAqB,GAAG,MAAM,CAiBhC"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { DeltaAuctionOrder } from './types';
|
|
2
|
-
|
|
3
|
-
type DeltaOrderPermitInput = Pick<DeltaAuctionOrder, 'permit' | 'nonce'>;
|
|
4
|
-
|
|
5
|
-
export function composeDeltaOrderPermit({
|
|
6
|
-
permit,
|
|
7
|
-
nonce,
|
|
8
|
-
}: DeltaOrderPermitInput): string {
|
|
9
|
-
// Can be empty Permit if allowance is available for srcToken
|
|
10
|
-
if (permit === '0x' || permit === '0x01') {
|
|
11
|
-
// 0x01 is a special permit value that signifies existing Permit2 allowance.
|
|
12
|
-
return permit;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// In the Contract, specifically for Permit2 transferFrom, we have signature consisting of
|
|
16
|
-
// bytes32(permit2nonce) + bytes64(compacted signature) = bytes96 Permit2 Transfer format
|
|
17
|
-
|
|
18
|
-
if (permit.length >= 194) {
|
|
19
|
-
// "0x".length + 96bytes*2 = 194, means permit already concatenated with nonce
|
|
20
|
-
// or it's a different type of Permit all together
|
|
21
|
-
return permit;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return encodePermit2Transfer(BigInt(nonce), permit);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function uintTo32ByteArrayBuffer(nonce: number | bigint) {
|
|
28
|
-
// Create a 32-byte ArrayBuffer
|
|
29
|
-
const buffer = new Uint8Array(32);
|
|
30
|
-
|
|
31
|
-
// Convert nonce to hex string and pad it to 64 hex characters (32 bytes)
|
|
32
|
-
let nonceHex = nonce.toString(16).padStart(64, '0');
|
|
33
|
-
|
|
34
|
-
// Convert the hex string to bytes and fill the ArrayBuffer
|
|
35
|
-
for (let i = 0; i < 32; i++) {
|
|
36
|
-
buffer[i] = parseInt(nonceHex.slice(i * 2, i * 2 + 2), 16);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return buffer;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function hexToByteArray(hexString: string) {
|
|
43
|
-
// Remove "0x" prefix if present
|
|
44
|
-
hexString = hexString.replace(/^0x/, '');
|
|
45
|
-
|
|
46
|
-
// Convert hex string to Uint8Array
|
|
47
|
-
const byteArray = new Uint8Array(hexString.length / 2);
|
|
48
|
-
for (let i = 0; i < hexString.length; i += 2) {
|
|
49
|
-
byteArray[i / 2] = parseInt(hexString.slice(i, i + 2), 16);
|
|
50
|
-
}
|
|
51
|
-
return byteArray;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function encodePermit2Transfer(nonce: number | bigint, signature: string) {
|
|
55
|
-
// Get 32-byte ArrayBuffer for nonce
|
|
56
|
-
const nonceBuffer = uintTo32ByteArrayBuffer(nonce);
|
|
57
|
-
|
|
58
|
-
// Convert signature hex string to Uint8Array (64 bytes)
|
|
59
|
-
const signatureBuffer = hexToByteArray(signature);
|
|
60
|
-
if (signatureBuffer.length !== 64) {
|
|
61
|
-
throw new Error('Signature must be exactly 64 bytes');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Concatenate nonceBuffer and signatureBuffer
|
|
65
|
-
const packedBuffer = new Uint8Array(32 + 64);
|
|
66
|
-
packedBuffer.set(nonceBuffer, 0); // Copy nonceBuffer at the start
|
|
67
|
-
packedBuffer.set(signatureBuffer, 32); // Copy signatureBuffer after nonce
|
|
68
|
-
|
|
69
|
-
// Convert to hex string for output
|
|
70
|
-
return (
|
|
71
|
-
'0x' +
|
|
72
|
-
Array.from(packedBuffer)
|
|
73
|
-
.map((b) => b.toString(16).padStart(2, '0'))
|
|
74
|
-
.join('')
|
|
75
|
-
);
|
|
76
|
-
}
|