@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
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConstructProviderFetchInput,
|
|
3
|
+
RequestParameters,
|
|
4
|
+
} from '../../types';
|
|
5
|
+
import { DeltaAuction } from './helpers/types';
|
|
6
|
+
import {
|
|
7
|
+
buildCancelDeltaOrderSignableData,
|
|
8
|
+
CancelDeltaOrderData,
|
|
9
|
+
} from './helpers/buildCancelDeltaOrderData';
|
|
10
|
+
import { constructGetDeltaContract } from '../..';
|
|
11
|
+
|
|
12
|
+
type SuccessResponse = { success: true };
|
|
13
|
+
|
|
14
|
+
type CancelDeltaOrderRequestParams = {
|
|
15
|
+
orderIds: string[];
|
|
16
|
+
signature: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type SignCancelDeltaOrderRequest = (
|
|
20
|
+
params: CancelDeltaOrderData,
|
|
21
|
+
requestParams?: RequestParameters
|
|
22
|
+
) => Promise<string>;
|
|
23
|
+
|
|
24
|
+
export type PostCancelDeltaOrderRequest = (
|
|
25
|
+
params: CancelDeltaOrderRequestParams,
|
|
26
|
+
requestParams?: RequestParameters
|
|
27
|
+
) => Promise<SuccessResponse>;
|
|
28
|
+
|
|
29
|
+
export type CancelDeltaOrder = (
|
|
30
|
+
params: Pick<DeltaAuction, 'id'>[],
|
|
31
|
+
requestParams?: RequestParameters
|
|
32
|
+
) => Promise<SuccessResponse>;
|
|
33
|
+
|
|
34
|
+
export type CancelDeltaOrderFunctions = {
|
|
35
|
+
signCancelLimitDeltaOrderRequest: SignCancelDeltaOrderRequest;
|
|
36
|
+
postCancelLimitDeltaOrderRequest: PostCancelDeltaOrderRequest;
|
|
37
|
+
/** @description Cancel a Limit Delta order */
|
|
38
|
+
cancelLimitDeltaOrders: CancelDeltaOrder;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const constructCancelDeltaOrder = (
|
|
42
|
+
options: Pick<
|
|
43
|
+
ConstructProviderFetchInput<any, 'signTypedDataCall'>,
|
|
44
|
+
'contractCaller' | 'fetcher' | 'apiURL' | 'chainId'
|
|
45
|
+
>
|
|
46
|
+
): CancelDeltaOrderFunctions => {
|
|
47
|
+
// cached internally
|
|
48
|
+
const { getDeltaContract } = constructGetDeltaContract(options);
|
|
49
|
+
|
|
50
|
+
const signCancelLimitDeltaOrderRequest: SignCancelDeltaOrderRequest = async (
|
|
51
|
+
params,
|
|
52
|
+
requestParams
|
|
53
|
+
) => {
|
|
54
|
+
const ParaswapDelta = await getDeltaContract(requestParams);
|
|
55
|
+
if (!ParaswapDelta) {
|
|
56
|
+
throw new Error(`Delta is not available on chain ${options.chainId}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const typedData = buildCancelDeltaOrderSignableData({
|
|
60
|
+
orderInput: params,
|
|
61
|
+
paraswapDeltaAddress: ParaswapDelta,
|
|
62
|
+
chainId: options.chainId,
|
|
63
|
+
});
|
|
64
|
+
const signature = await options.contractCaller.signTypedDataCall(typedData);
|
|
65
|
+
|
|
66
|
+
return signature;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const postCancelLimitDeltaOrderRequest: PostCancelDeltaOrderRequest = async (
|
|
70
|
+
params,
|
|
71
|
+
requestParams
|
|
72
|
+
) => {
|
|
73
|
+
const cancelUrl = `${options.apiURL}/delta/orders/cancel` as const;
|
|
74
|
+
|
|
75
|
+
const res = await options.fetcher<SuccessResponse>({
|
|
76
|
+
url: cancelUrl,
|
|
77
|
+
method: 'POST',
|
|
78
|
+
data: params,
|
|
79
|
+
requestParams,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return res;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const cancelLimitDeltaOrders: CancelDeltaOrder = async (
|
|
86
|
+
params,
|
|
87
|
+
requestParams
|
|
88
|
+
) => {
|
|
89
|
+
const orderIds = params.map(({ id }) => id);
|
|
90
|
+
const signature = await signCancelLimitDeltaOrderRequest(
|
|
91
|
+
{ orderIds },
|
|
92
|
+
requestParams
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const res = await postCancelLimitDeltaOrderRequest(
|
|
96
|
+
{
|
|
97
|
+
orderIds,
|
|
98
|
+
signature,
|
|
99
|
+
},
|
|
100
|
+
requestParams
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return res;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
signCancelLimitDeltaOrderRequest,
|
|
108
|
+
postCancelLimitDeltaOrderRequest,
|
|
109
|
+
cancelLimitDeltaOrders,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -26,6 +26,10 @@ type OrdersFilter = {
|
|
|
26
26
|
page?: number;
|
|
27
27
|
/** @description Pagination option, limit. Default 100 */
|
|
28
28
|
limit?: number;
|
|
29
|
+
/** @description Filter by chainId, without this filter, orders from all chains are returned */
|
|
30
|
+
chainId?: number; // @TODO currently not working
|
|
31
|
+
/** @description Filter by type. MARKET, LIMIT, or ALL. Default is ALL */
|
|
32
|
+
type?: 'MARKET' | 'LIMIT' | 'ALL';
|
|
29
33
|
};
|
|
30
34
|
type OrderFiltersQuery = OrdersFilter;
|
|
31
35
|
|
|
@@ -34,15 +38,27 @@ type GetDeltaOrders = (
|
|
|
34
38
|
requestParams?: RequestParameters
|
|
35
39
|
) => Promise<OrderFromAPI[]>;
|
|
36
40
|
|
|
41
|
+
type GetRequiredBalanceParams = {
|
|
42
|
+
userAddress: Address;
|
|
43
|
+
tokenAddress?: Address;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type GetRequiredBalance = (
|
|
47
|
+
userParams: GetRequiredBalanceParams,
|
|
48
|
+
requestParams?: RequestParameters
|
|
49
|
+
) => Promise<Record<string, string>>; // token -> balance in Limit Orders
|
|
50
|
+
|
|
37
51
|
export type GetDeltaOrdersFunctions = {
|
|
38
52
|
getDeltaOrderById: GetDeltaOrderById;
|
|
39
53
|
getDeltaOrderByHash: GetDeltaOrderByHash;
|
|
40
54
|
getDeltaOrders: GetDeltaOrders;
|
|
55
|
+
getRequiredBalanceForDeltaLimitOrders: GetRequiredBalance;
|
|
41
56
|
};
|
|
42
57
|
|
|
43
58
|
export const constructGetDeltaOrders = ({
|
|
44
59
|
apiURL = API_URL,
|
|
45
60
|
fetcher,
|
|
61
|
+
chainId,
|
|
46
62
|
}: ConstructFetchInput): GetDeltaOrdersFunctions => {
|
|
47
63
|
const baseUrl = `${apiURL}/delta/orders` as const;
|
|
48
64
|
|
|
@@ -81,6 +97,8 @@ export const constructGetDeltaOrders = ({
|
|
|
81
97
|
userAddress: options.userAddress,
|
|
82
98
|
page: options.page,
|
|
83
99
|
limit: options.limit,
|
|
100
|
+
chainId: options.chainId,
|
|
101
|
+
type: options.type,
|
|
84
102
|
});
|
|
85
103
|
|
|
86
104
|
const fetchURL = `${baseUrl}${search}` as const;
|
|
@@ -94,9 +112,29 @@ export const constructGetDeltaOrders = ({
|
|
|
94
112
|
return orders;
|
|
95
113
|
};
|
|
96
114
|
|
|
115
|
+
const getRequiredBalanceForDeltaLimitOrders: GetRequiredBalance = async (
|
|
116
|
+
userParams,
|
|
117
|
+
requestParams
|
|
118
|
+
) => {
|
|
119
|
+
const userURL =
|
|
120
|
+
`${baseUrl}/fillablebalance/${chainId}/${userParams.userAddress}` as const;
|
|
121
|
+
const fetchURL = userParams.tokenAddress
|
|
122
|
+
? (`${userURL}/${userParams.tokenAddress}` as const)
|
|
123
|
+
: userURL;
|
|
124
|
+
|
|
125
|
+
const response = await fetcher<Record<string, string>>({
|
|
126
|
+
url: fetchURL,
|
|
127
|
+
method: 'GET',
|
|
128
|
+
requestParams,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return response;
|
|
132
|
+
};
|
|
133
|
+
|
|
97
134
|
return {
|
|
98
135
|
getDeltaOrderById,
|
|
99
136
|
getDeltaOrderByHash,
|
|
100
137
|
getDeltaOrders,
|
|
138
|
+
getRequiredBalanceForDeltaLimitOrders,
|
|
101
139
|
};
|
|
102
140
|
};
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { Bridge } from '../..';
|
|
1
2
|
import { API_URL, SwapSide } from '../../constants';
|
|
2
3
|
import { constructSearchString } from '../../helpers/misc';
|
|
3
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
ConstructFetchInput,
|
|
6
|
+
EnumerateLiteral,
|
|
7
|
+
RequestParameters,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
import { ZERO_ADDRESS } from '../common/orders/buildOrderData';
|
|
10
|
+
import { BridgePriceInfo } from './helpers/types';
|
|
11
|
+
|
|
12
|
+
type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
|
|
4
13
|
|
|
5
14
|
export type DeltaPriceParams = {
|
|
6
15
|
/** @description Source Token Address. Not Native Token */
|
|
@@ -13,44 +22,70 @@ export type DeltaPriceParams = {
|
|
|
13
22
|
srcDecimals: number;
|
|
14
23
|
/** @description Destination Token Decimals */
|
|
15
24
|
destDecimals: number;
|
|
16
|
-
// side?: SwapSide; // no BUY side for now
|
|
17
25
|
/** @description User's Wallet Address */
|
|
18
26
|
userAddress?: string;
|
|
19
27
|
/** @description Partner string. */
|
|
20
28
|
partner?: string;
|
|
21
29
|
/** @description Destination Chain ID for Crosschain Orders */
|
|
22
30
|
destChainId?: number;
|
|
31
|
+
/** @description SELL or BUY, default is SELL */
|
|
32
|
+
side?: SwapSideUnion;
|
|
33
|
+
|
|
34
|
+
includeAgents?: string[];
|
|
35
|
+
excludeAgents?: string[];
|
|
23
36
|
};
|
|
24
37
|
|
|
25
|
-
type DeltaPriceQueryOptions =
|
|
38
|
+
type DeltaPriceQueryOptions = Omit<
|
|
39
|
+
DeltaPriceParams,
|
|
40
|
+
'includeAgents' | 'excludeAgents'
|
|
41
|
+
> & {
|
|
26
42
|
chainId: number; // will return error from API on unsupported chains
|
|
27
|
-
|
|
43
|
+
includeAgents?: string;
|
|
44
|
+
excludeAgents?: string;
|
|
28
45
|
};
|
|
29
46
|
|
|
47
|
+
// for same-chain Orders, all 0 params
|
|
48
|
+
export const DEFAULT_BRIDGE = {
|
|
49
|
+
protocolSelector: '0x00000000', // 4 bytes
|
|
50
|
+
destinationChainId: 0,
|
|
51
|
+
outputToken: ZERO_ADDRESS,
|
|
52
|
+
scalingFactor: 0,
|
|
53
|
+
protocolData: '0x',
|
|
54
|
+
} as const satisfies Bridge;
|
|
55
|
+
|
|
30
56
|
export type DeltaPrice = {
|
|
31
57
|
srcToken: string;
|
|
32
58
|
destToken: string;
|
|
33
59
|
srcAmount: string;
|
|
60
|
+
/** @description Available for BUY side */
|
|
61
|
+
srcAmountBeforeFee?: string;
|
|
34
62
|
destAmount: string;
|
|
35
|
-
|
|
63
|
+
/** @description Available for SELL side */
|
|
64
|
+
destAmountBeforeFee?: string;
|
|
36
65
|
gasCost: string;
|
|
37
66
|
gasCostBeforeFee: string;
|
|
38
67
|
gasCostUSD: string;
|
|
39
68
|
gasCostUSDBeforeFee: string;
|
|
40
69
|
srcUSD: string;
|
|
70
|
+
/** @description Available for BUY side */
|
|
71
|
+
srcUSDBeforeFee?: string;
|
|
41
72
|
destUSD: string;
|
|
42
|
-
|
|
73
|
+
/** @description Available for SELL side */
|
|
74
|
+
destUSDBeforeFee?: string;
|
|
43
75
|
partner: string;
|
|
44
76
|
partnerFee: number; // in %
|
|
45
77
|
hmac: string;
|
|
78
|
+
bridge: Bridge; // for single-chain DeltaPrice, it's DEFAULT_BRIDGE
|
|
46
79
|
};
|
|
47
80
|
|
|
48
|
-
export type BridgePrice = DeltaPrice & {
|
|
49
|
-
destAmountAfterBridge: string;
|
|
50
|
-
destUSDAfterBridge: string;
|
|
51
|
-
bridgeFee: string;
|
|
52
|
-
bridgeFeeUSD: string;
|
|
53
|
-
poolAddress: string;
|
|
81
|
+
export type BridgePrice = Omit<DeltaPrice, 'bridge'> & {
|
|
82
|
+
// destAmountAfterBridge: string; // became bridgeInfo.destAmountAfterBridge
|
|
83
|
+
// destUSDAfterBridge: string; // became bridgeInfo.destUSDAfterBridge
|
|
84
|
+
// bridgeFee: string; // became bridgeInfo.fees[0].amount
|
|
85
|
+
// bridgeFeeUSD: string; // became bridgeInfo.fees[0].amountInUSD
|
|
86
|
+
// poolAddress: string;
|
|
87
|
+
bridge: Bridge;
|
|
88
|
+
bridgeInfo: BridgePriceInfo;
|
|
54
89
|
};
|
|
55
90
|
|
|
56
91
|
type DeltaPriceResponse = {
|
|
@@ -99,10 +134,20 @@ export const constructGetDeltaPrice = ({
|
|
|
99
134
|
options: DeltaPriceParams,
|
|
100
135
|
requestParams?: RequestParameters
|
|
101
136
|
): Promise<DeltaPrice | BridgePrice> {
|
|
137
|
+
const { includeAgents, excludeAgents, ...rest } = options;
|
|
138
|
+
const includeAgentsString = includeAgents
|
|
139
|
+
? includeAgents.join(',')
|
|
140
|
+
: undefined;
|
|
141
|
+
const excludeAgentsString = excludeAgents
|
|
142
|
+
? excludeAgents.join(',')
|
|
143
|
+
: undefined;
|
|
144
|
+
|
|
102
145
|
const search = constructSearchString<DeltaPriceQueryOptions>({
|
|
103
|
-
...
|
|
146
|
+
...rest,
|
|
104
147
|
chainId,
|
|
105
|
-
side: SwapSide.SELL,
|
|
148
|
+
side: options.side ?? SwapSide.SELL,
|
|
149
|
+
includeAgents: includeAgentsString,
|
|
150
|
+
excludeAgents: excludeAgentsString,
|
|
106
151
|
});
|
|
107
152
|
|
|
108
153
|
const fetchURL = `${pricesUrl}/${search}` as const;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assert } from 'ts-essentials';
|
|
2
2
|
import { ZERO_ADDRESS } from '../../common/orders/buildOrderData';
|
|
3
3
|
import { BeneficiaryType } from '../../common/orders/types';
|
|
4
|
-
import { Bridge
|
|
4
|
+
import { Bridge } from './types';
|
|
5
5
|
|
|
6
6
|
export const ACROSS_WETH_ADDRESSES_MAP: Record<number, string> = {
|
|
7
7
|
// Mainnet
|
|
@@ -32,6 +32,8 @@ export const ACROSS_WETH_ADDRESSES_MAP: Record<number, string> = {
|
|
|
32
32
|
81457: '0x4300000000000000000000000000000000000004',
|
|
33
33
|
// Blast Sepolia
|
|
34
34
|
168587773: '0x4200000000000000000000000000000000000023',
|
|
35
|
+
// BSC
|
|
36
|
+
56: '0x2170Ed0880ac9A755fd29B2688956BD959F933F8',
|
|
35
37
|
// Ink
|
|
36
38
|
57073: '0x4200000000000000000000000000000000000006',
|
|
37
39
|
// Ink Sepolia
|
|
@@ -98,11 +100,10 @@ export function isETHaddress(tokenAddress: string): boolean {
|
|
|
98
100
|
// https://developers.velora.xyz/api/velora-api/velora-delta-api/build-a-delta-order-to-sign
|
|
99
101
|
|
|
100
102
|
export type GetDeltaBridgeAndDestTokenInput = {
|
|
101
|
-
destTokenDestChain: string;
|
|
103
|
+
destTokenDestChain: string; // the token user wants to ultimately receive
|
|
102
104
|
destChainId: number;
|
|
103
|
-
destTokenSrcChain: string;
|
|
104
|
-
srcChainId: number;
|
|
105
105
|
bridgeFee: string;
|
|
106
|
+
bridgeOutputToken: string; // the token on the destination chain, in case of WETH -> ETH, will be different from destTokenDestChain and unwrapped
|
|
106
107
|
beneficiaryType: BeneficiaryType;
|
|
107
108
|
getMulticallHandler: (chainId: number) => Promise<string>;
|
|
108
109
|
};
|
|
@@ -110,16 +111,13 @@ export type GetDeltaBridgeAndDestTokenInput = {
|
|
|
110
111
|
export type GetDeltaBridgeAndDestTokenOutput = {
|
|
111
112
|
/** @description The bridge object to be used for Order.bridge */
|
|
112
113
|
bridge: Bridge;
|
|
113
|
-
/** @description The changes to be made to the Order */
|
|
114
|
-
orderChanges: Pick<DeltaAuctionOrder, 'destToken'>;
|
|
115
114
|
};
|
|
116
115
|
|
|
117
|
-
export async function
|
|
116
|
+
export async function getDeltaBridge({
|
|
118
117
|
destTokenDestChain,
|
|
119
118
|
destChainId,
|
|
120
|
-
destTokenSrcChain,
|
|
121
|
-
srcChainId,
|
|
122
119
|
bridgeFee,
|
|
120
|
+
bridgeOutputToken,
|
|
123
121
|
beneficiaryType,
|
|
124
122
|
getMulticallHandler,
|
|
125
123
|
}: GetDeltaBridgeAndDestTokenInput): Promise<GetDeltaBridgeAndDestTokenOutput> {
|
|
@@ -127,48 +125,20 @@ export async function getDeltaBridgeAndDestToken({
|
|
|
127
125
|
beneficiaryType === 'EOA' || beneficiaryType === 'SmartContract',
|
|
128
126
|
'beneficiaryType must be EOA or SmartContract'
|
|
129
127
|
);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!WETH_SRC_CHAIN || !WETH_DEST_CHAIN) {
|
|
135
|
-
// this should never happen as we only expect crosschain Delta Orders for supported chains
|
|
136
|
-
const bridge: Bridge = {
|
|
137
|
-
maxRelayerFee: bridgeFee,
|
|
138
|
-
destinationChainId: destChainId,
|
|
139
|
-
outputToken: destTokenDestChain,
|
|
140
|
-
multiCallHandler: ZERO_ADDRESS,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
bridge,
|
|
145
|
-
orderChanges: {
|
|
146
|
-
destToken: destTokenSrcChain,
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}
|
|
128
|
+
|
|
129
|
+
const outputToken = bridgeOutputToken.toLowerCase(); // for uniformity
|
|
130
|
+
|
|
131
|
+
let multiCallHandler: string = ZERO_ADDRESS;
|
|
150
132
|
|
|
151
133
|
if (beneficiaryType === 'EOA' && isETHaddress(destTokenDestChain)) {
|
|
152
134
|
/*
|
|
153
135
|
if beneficiary is an EOA and destToken on destChain = ETH
|
|
154
|
-
order.destToken=ETH
|
|
155
|
-
order.bridge.outputToken=WETH_DEST_CHAIN
|
|
136
|
+
order.destToken=ETH (deltaPrice already contains correct destToken)
|
|
137
|
+
order.bridge.outputToken=WETH_DEST_CHAIN (deltaPrice already contains correct bridge.outputToken)
|
|
156
138
|
order.bridge.multiCallHandler=NULL_ADDRESS
|
|
157
139
|
*/
|
|
158
140
|
|
|
159
|
-
|
|
160
|
-
maxRelayerFee: bridgeFee,
|
|
161
|
-
destinationChainId: destChainId,
|
|
162
|
-
outputToken: WETH_DEST_CHAIN,
|
|
163
|
-
multiCallHandler: ZERO_ADDRESS,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
bridge,
|
|
168
|
-
orderChanges: {
|
|
169
|
-
destToken: ETH_ADDRESS,
|
|
170
|
-
},
|
|
171
|
-
};
|
|
141
|
+
multiCallHandler = ZERO_ADDRESS;
|
|
172
142
|
}
|
|
173
143
|
if (
|
|
174
144
|
beneficiaryType === 'EOA' &&
|
|
@@ -176,43 +146,21 @@ export async function getDeltaBridgeAndDestToken({
|
|
|
176
146
|
) {
|
|
177
147
|
/*
|
|
178
148
|
if beneficiary is an EOA and destToken on destChain = WETH
|
|
179
|
-
order.destToken=WETH
|
|
180
|
-
order.bridge.outputToken=WETH_DEST_CHAIN
|
|
149
|
+
order.destToken=WETH (deltaPrice already contains correct destToken)
|
|
150
|
+
order.bridge.outputToken=WETH_DEST_CHAIN (deltaPrice already contains correct bridge.outputToken)
|
|
181
151
|
order.bridge.multiCallHandler=MULTI_CALL_HANDLER
|
|
182
152
|
*/
|
|
183
|
-
|
|
184
|
-
maxRelayerFee: bridgeFee,
|
|
185
|
-
destinationChainId: destChainId,
|
|
186
|
-
outputToken: WETH_DEST_CHAIN,
|
|
187
|
-
multiCallHandler: await getMulticallHandler(destChainId),
|
|
188
|
-
};
|
|
189
|
-
return {
|
|
190
|
-
bridge,
|
|
191
|
-
orderChanges: {
|
|
192
|
-
destToken: WETH_SRC_CHAIN,
|
|
193
|
-
},
|
|
194
|
-
};
|
|
153
|
+
multiCallHandler = await getMulticallHandler(destChainId);
|
|
195
154
|
}
|
|
196
155
|
|
|
197
156
|
if (beneficiaryType === 'SmartContract' && isETHaddress(destTokenDestChain)) {
|
|
198
157
|
/*
|
|
199
158
|
if beneficiary is a contract and destToken on destChain = ETH
|
|
200
|
-
order.destToken=ETH
|
|
201
|
-
order.bridge.outputToken=WETH_DEST_CHAIN
|
|
159
|
+
order.destToken=ETH (deltaPrice already contains correct destToken)
|
|
160
|
+
order.bridge.outputToken=WETH_DEST_CHAIN (deltaPrice already contains correct bridge.outputToken)
|
|
202
161
|
order.bridge.multiCallHandler=MULTI_CALL_HANDLER
|
|
203
162
|
*/
|
|
204
|
-
|
|
205
|
-
maxRelayerFee: bridgeFee,
|
|
206
|
-
destinationChainId: destChainId,
|
|
207
|
-
outputToken: WETH_DEST_CHAIN,
|
|
208
|
-
multiCallHandler: await getMulticallHandler(destChainId),
|
|
209
|
-
};
|
|
210
|
-
return {
|
|
211
|
-
bridge,
|
|
212
|
-
orderChanges: {
|
|
213
|
-
destToken: ETH_ADDRESS,
|
|
214
|
-
},
|
|
215
|
-
};
|
|
163
|
+
multiCallHandler = await getMulticallHandler(destChainId);
|
|
216
164
|
}
|
|
217
165
|
|
|
218
166
|
if (
|
|
@@ -221,35 +169,21 @@ export async function getDeltaBridgeAndDestToken({
|
|
|
221
169
|
) {
|
|
222
170
|
/*
|
|
223
171
|
if beneficiary is a contract and destToken on destChain = WETH
|
|
224
|
-
order.destToken=WETH
|
|
225
|
-
order.bridge.outputToken=WETH_DEST_CHAIN
|
|
172
|
+
order.destToken=WETH (deltaPrice already contains correct destToken)
|
|
173
|
+
order.bridge.outputToken=WETH_DEST_CHAIN (deltaPrice already contains correct bridge.outputToken)
|
|
226
174
|
order.bridge.multiCallHandler=NULL_ADDRESS
|
|
227
175
|
*/
|
|
228
|
-
|
|
229
|
-
maxRelayerFee: bridgeFee,
|
|
230
|
-
destinationChainId: destChainId,
|
|
231
|
-
outputToken: WETH_DEST_CHAIN,
|
|
232
|
-
multiCallHandler: ZERO_ADDRESS,
|
|
233
|
-
};
|
|
234
|
-
return {
|
|
235
|
-
bridge,
|
|
236
|
-
orderChanges: {
|
|
237
|
-
destToken: WETH_SRC_CHAIN,
|
|
238
|
-
},
|
|
239
|
-
};
|
|
176
|
+
multiCallHandler = ZERO_ADDRESS;
|
|
240
177
|
}
|
|
241
178
|
|
|
242
179
|
const bridge: Bridge = {
|
|
243
180
|
maxRelayerFee: bridgeFee,
|
|
244
181
|
destinationChainId: destChainId,
|
|
245
|
-
outputToken
|
|
246
|
-
multiCallHandler
|
|
247
|
-
};
|
|
182
|
+
outputToken,
|
|
183
|
+
multiCallHandler,
|
|
184
|
+
} as any; // @TODO remove the whole getDeltaBridge() when API provides BridgePrice.bridge = whole Bridge object
|
|
248
185
|
|
|
249
186
|
return {
|
|
250
187
|
bridge,
|
|
251
|
-
orderChanges: {
|
|
252
|
-
destToken: destTokenSrcChain,
|
|
253
|
-
},
|
|
254
188
|
};
|
|
255
189
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Domain } from '../../common/orders/buildOrderData';
|
|
2
|
+
|
|
3
|
+
const ORDER_CANCELLATIONS_EIP_712_TYPES = {
|
|
4
|
+
OrderCancellations: [{ name: 'orderIds', type: 'string[]' }],
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type CancelDeltaOrderData = {
|
|
8
|
+
orderIds: string[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type SignableCancelDeltaOrderData = {
|
|
12
|
+
types: {
|
|
13
|
+
OrderCancellations: (typeof ORDER_CANCELLATIONS_EIP_712_TYPES)['OrderCancellations'];
|
|
14
|
+
};
|
|
15
|
+
domain: Domain;
|
|
16
|
+
data: CancelDeltaOrderData;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type BuildCancelDeltaOrderInput = {
|
|
20
|
+
orderInput: CancelDeltaOrderData;
|
|
21
|
+
paraswapDeltaAddress: string;
|
|
22
|
+
chainId: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function buildCancelDeltaOrderSignableData({
|
|
26
|
+
orderInput,
|
|
27
|
+
chainId,
|
|
28
|
+
paraswapDeltaAddress,
|
|
29
|
+
}: BuildCancelDeltaOrderInput): SignableCancelDeltaOrderData {
|
|
30
|
+
const typedData = {
|
|
31
|
+
types: {
|
|
32
|
+
OrderCancellations: ORDER_CANCELLATIONS_EIP_712_TYPES.OrderCancellations,
|
|
33
|
+
},
|
|
34
|
+
domain: {
|
|
35
|
+
name: 'Portikus',
|
|
36
|
+
version: '2.0.0',
|
|
37
|
+
chainId,
|
|
38
|
+
verifyingContract: paraswapDeltaAddress,
|
|
39
|
+
},
|
|
40
|
+
data: {
|
|
41
|
+
// explicityly pick only the necessary fields,
|
|
42
|
+
// otherwise signing will break if more is present
|
|
43
|
+
orderIds: orderInput.orderIds,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return typedData;
|
|
48
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { MarkOptional } from 'ts-essentials';
|
|
2
2
|
import { Domain, ZERO_ADDRESS } from '../../common/orders/buildOrderData';
|
|
3
3
|
import { Bridge, DeltaAuctionOrder } from './types';
|
|
4
|
-
import { composeDeltaOrderPermit } from './composePermit';
|
|
5
4
|
|
|
6
5
|
// Order(address owner,address beneficiary,address srcToken,address destToken,uint256 srcAmount,uint256 destAmount,uint256 deadline,uint256 nonce,bytes permit, bridge Bridge)";
|
|
7
6
|
const SWAP_ORDER_EIP_712_TYPES = {
|
|
@@ -12,18 +11,36 @@ const SWAP_ORDER_EIP_712_TYPES = {
|
|
|
12
11
|
{ name: 'destToken', type: 'address' },
|
|
13
12
|
{ name: 'srcAmount', type: 'uint256' },
|
|
14
13
|
{ name: 'destAmount', type: 'uint256' },
|
|
15
|
-
{ name: '
|
|
14
|
+
{ name: 'expectedAmount', type: 'uint256' },
|
|
16
15
|
{ name: 'deadline', type: 'uint256' },
|
|
16
|
+
{ name: 'kind', type: 'uint8' },
|
|
17
17
|
{ name: 'nonce', type: 'uint256' },
|
|
18
18
|
{ name: 'partnerAndFee', type: 'uint256' },
|
|
19
19
|
{ name: 'permit', type: 'bytes' },
|
|
20
|
+
{ name: 'metadata', type: 'bytes' },
|
|
20
21
|
{ name: 'bridge', type: 'Bridge' },
|
|
21
22
|
],
|
|
22
23
|
Bridge: [
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
{
|
|
25
|
+
name: 'protocolSelector',
|
|
26
|
+
type: 'bytes4',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'destinationChainId',
|
|
30
|
+
type: 'uint256',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'outputToken',
|
|
34
|
+
type: 'address',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'scalingFactor',
|
|
38
|
+
type: 'int8',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'protocolData',
|
|
42
|
+
type: 'bytes',
|
|
43
|
+
},
|
|
27
44
|
],
|
|
28
45
|
};
|
|
29
46
|
|
|
@@ -69,7 +86,10 @@ export type DeltaOrderDataInput = MarkOptional<
|
|
|
69
86
|
'beneficiary' | 'deadline' | 'nonce' | 'permit'
|
|
70
87
|
>;
|
|
71
88
|
|
|
72
|
-
export type BuildDeltaOrderDataInput =
|
|
89
|
+
export type BuildDeltaOrderDataInput = MarkOptional<
|
|
90
|
+
DeltaOrderDataInput,
|
|
91
|
+
'metadata'
|
|
92
|
+
> & {
|
|
73
93
|
partnerAddress: string;
|
|
74
94
|
paraswapDeltaAddress: string;
|
|
75
95
|
partnerFeeBps: number;
|
|
@@ -78,7 +98,7 @@ export type BuildDeltaOrderDataInput = DeltaOrderDataInput & {
|
|
|
78
98
|
bridge: Bridge;
|
|
79
99
|
};
|
|
80
100
|
|
|
81
|
-
// default deadline = 1 hour
|
|
101
|
+
// default deadline = 1 hour for now (may be changed later)
|
|
82
102
|
export const DELTA_DEFAULT_EXPIRY = 60 * 60; // seconds
|
|
83
103
|
|
|
84
104
|
export function buildDeltaSignableOrderData({
|
|
@@ -89,13 +109,16 @@ export function buildDeltaSignableOrderData({
|
|
|
89
109
|
destToken,
|
|
90
110
|
srcAmount,
|
|
91
111
|
destAmount,
|
|
92
|
-
|
|
112
|
+
expectedAmount,
|
|
93
113
|
|
|
94
114
|
deadline = Math.floor(Date.now() / 1000 + DELTA_DEFAULT_EXPIRY),
|
|
95
115
|
nonce = Date.now().toString(10), // random enough to not cause collisions
|
|
96
116
|
|
|
97
117
|
permit = '0x',
|
|
98
118
|
|
|
119
|
+
kind,
|
|
120
|
+
metadata = '0x',
|
|
121
|
+
|
|
99
122
|
partnerAddress,
|
|
100
123
|
partnerFeeBps,
|
|
101
124
|
partnerTakesSurplus = false,
|
|
@@ -111,16 +134,18 @@ export function buildDeltaSignableOrderData({
|
|
|
111
134
|
destToken,
|
|
112
135
|
srcAmount,
|
|
113
136
|
destAmount,
|
|
114
|
-
|
|
137
|
+
expectedAmount,
|
|
115
138
|
deadline,
|
|
116
139
|
nonce,
|
|
117
|
-
permit
|
|
140
|
+
permit,
|
|
118
141
|
partnerAndFee: producePartnerAndFee({
|
|
119
142
|
partnerFeeBps,
|
|
120
143
|
partnerAddress,
|
|
121
144
|
partnerTakesSurplus,
|
|
122
145
|
}),
|
|
123
146
|
bridge,
|
|
147
|
+
kind,
|
|
148
|
+
metadata,
|
|
124
149
|
};
|
|
125
150
|
|
|
126
151
|
return produceDeltaOrderTypedData({
|
|
@@ -7,12 +7,14 @@ export function sanitizeDeltaOrderData({
|
|
|
7
7
|
destToken,
|
|
8
8
|
srcAmount,
|
|
9
9
|
destAmount,
|
|
10
|
-
|
|
10
|
+
expectedAmount,
|
|
11
11
|
deadline,
|
|
12
12
|
nonce,
|
|
13
13
|
permit,
|
|
14
14
|
partnerAndFee,
|
|
15
15
|
bridge,
|
|
16
|
+
kind,
|
|
17
|
+
metadata,
|
|
16
18
|
}: SignableDeltaOrderData['data'] &
|
|
17
19
|
Record<string, any>): SignableDeltaOrderData['data'] {
|
|
18
20
|
return {
|
|
@@ -22,11 +24,13 @@ export function sanitizeDeltaOrderData({
|
|
|
22
24
|
destToken,
|
|
23
25
|
srcAmount,
|
|
24
26
|
destAmount,
|
|
25
|
-
|
|
27
|
+
expectedAmount,
|
|
26
28
|
deadline,
|
|
27
29
|
nonce,
|
|
28
30
|
permit,
|
|
29
31
|
partnerAndFee,
|
|
30
32
|
bridge,
|
|
33
|
+
kind,
|
|
34
|
+
metadata,
|
|
31
35
|
};
|
|
32
36
|
}
|