@paraswap/dex-lib 3.4.2-balancer-v2-single-swap.0 → 3.4.2
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 +377 -377
- package/build/config.js +9 -5
- package/build/config.js.map +1 -1
- package/build/dex/algebra/algebra.js +25 -25
- package/build/dex/balancer-v1/balancer-v1.js +34 -34
- package/build/dex/balancer-v2/balancer-v2.d.ts +1 -1
- package/build/dex/balancer-v2/balancer-v2.js +65 -78
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/camelot/camelot.js +27 -27
- package/build/dex/kyberdmm/kyberdmm.js +27 -27
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +25 -25
- package/build/dex/solidly/solidly.js +27 -27
- package/build/dex/solidly-v3/solidly-v3.js +25 -25
- package/build/dex/swaap-v2/config.js +15 -0
- package/build/dex/swaap-v2/config.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +26 -26
- package/build/dex/uniswap-v3/uniswap-v3.js +25 -25
- package/funding.json +5 -5
- package/package.json +1 -1
- package/src/config.ts +500 -496
- package/src/constants.ts +67 -67
- package/src/dex/aave-v2/aave-v2.ts +409 -409
- package/src/dex/aave-v3/aave-v3.ts +320 -320
- package/src/dex/algebra/algebra.ts +1180 -1180
- package/src/dex/angle-staked-stable/angle-staked-stable.ts +347 -347
- package/src/dex/augustus-rfq.ts +180 -180
- package/src/dex/bProtocol/bProtocol.ts +108 -108
- package/src/dex/balancer-v1/balancer-v1.ts +572 -572
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +1699 -1699
- package/src/dex/balancer-v2/balancer-v2.ts +1669 -1701
- package/src/dex/bancor/bancor.ts +128 -128
- package/src/dex/camelot/camelot.ts +873 -873
- package/src/dex/compound/compound.ts +107 -107
- package/src/dex/curve-v1/config.ts +1179 -1179
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +507 -507
- package/src/dex/curve-v1/curve-v1.ts +1315 -1315
- package/src/dex/curve-v1-factory/config.ts +1018 -1018
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +1288 -1288
- package/src/dex/curve-v2/curve-v2.ts +440 -440
- package/src/dex/dexalot/dexalot.ts +1100 -1100
- package/src/dex/dodo-v1/dodo-v1.ts +132 -132
- package/src/dex/dodo-v2.ts +266 -266
- package/src/dex/etherfi.ts +239 -239
- package/src/dex/generic-rfq/generic-rfq.ts +431 -431
- package/src/dex/gmx/gmx.ts +321 -321
- package/src/dex/hashflow/hashflow.ts +1135 -1135
- package/src/dex/idex.ts +254 -254
- package/src/dex/index.ts +357 -357
- package/src/dex/jarvis-v6/jarvis-v6.ts +509 -509
- package/src/dex/jarvis.ts +262 -262
- package/src/dex/kyberdmm/kyberdmm.ts +649 -649
- package/src/dex/lido/lido.ts +110 -110
- package/src/dex/maker-psm/maker-psm.ts +592 -592
- package/src/dex/maverick-v1/maverick-v1.ts +537 -537
- package/src/dex/nerve/config.ts +635 -635
- package/src/dex/nerve/nerve-e2e.test.ts +731 -731
- package/src/dex/nerve/nerve-events.test.ts +911 -911
- package/src/dex/nerve/nerve.ts +467 -467
- package/src/dex/onebit/onebit.ts +113 -113
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1150 -1150
- package/src/dex/paraswap-limit-orders/config.ts +60 -60
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +137 -137
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-integration.test.ts +328 -328
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +631 -631
- package/src/dex/polygon-migrator/polygon-migrator.ts +194 -194
- package/src/dex/quick-perps/quick-perps.ts +337 -337
- package/src/dex/quickswap/config.ts +16 -16
- package/src/dex/quickswap/quickswap-e2e.test.ts +384 -384
- package/src/dex/smoothy/smoothy.ts +110 -110
- package/src/dex/solidly/config.ts +225 -225
- package/src/dex/solidly/solidly-e2e.test.ts +1421 -1421
- package/src/dex/solidly/solidly-integration.test.ts +1753 -1753
- package/src/dex/solidly/solidly.ts +687 -687
- package/src/dex/solidly-v3/solidly-v3.ts +968 -968
- package/src/dex/spark/spark.ts +284 -284
- package/src/dex/stable-pool/stable-pool.ts +129 -129
- package/src/dex/swaap-v2/config.ts +15 -0
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +233 -17
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +1 -1
- package/src/dex/swaap-v2/swaap-v2.ts +1056 -1056
- package/src/dex/swell/swell.ts +312 -312
- package/src/dex/synthetix/synthetix.ts +420 -420
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1.ts +180 -180
- package/src/dex/uniswap-v2/config.ts +637 -637
- package/src/dex/uniswap-v2/constants.ts +58 -58
- package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +1257 -1257
- package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +42 -42
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +1295 -1295
- package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +1834 -1834
- package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +871 -871
- package/src/dex/uniswap-v2/uniswap-v2.ts +1117 -1117
- package/src/dex/uniswap-v3/uniswap-v3.ts +1501 -1501
- package/src/dex/uniswap-v3.ts +242 -242
- package/src/dex/weth/config.ts +73 -73
- package/src/dex/weth/weth.ts +230 -230
- package/src/dex/wombat/wombat.ts +467 -467
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +529 -529
- package/src/dex/wsteth/wsteth.ts +304 -304
- package/src/dex/zerox/index.ts +328 -328
- package/src/executor/Executor01BytecodeBuilder.ts +474 -474
- package/src/executor/Executor02BytecodeBuilder.ts +1392 -1392
- package/src/executor/ExecutorBytecodeBuilder.ts +390 -390
- package/src/executor/ExecutorDetector.ts +131 -131
- package/src/executor/constants.ts +66 -66
- package/src/executor/executor01-bytecode-builder-e2e.test.ts +1478 -1478
- package/src/executor/utils.ts +62 -62
- package/src/router/simpleswap.ts +366 -366
- package/src/types.ts +342 -342
- package/tests/constants-e2e.ts +1632 -1622
- package/tests/generate-new-limit-order.ts +107 -107
package/src/dex/augustus-rfq.ts
CHANGED
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
-
import { isHexString, hexConcat } from '@ethersproject/bytes';
|
|
3
|
-
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
4
|
-
import { SwapSide, Network } from '../constants';
|
|
5
|
-
import { IDexTxBuilder } from './idex';
|
|
6
|
-
import { SimpleExchange } from './simple-exchange';
|
|
7
|
-
import AugustusRFQABI from '../abi/paraswap-limit-orders/AugustusRFQ.abi.json';
|
|
8
|
-
import PermitABI from '../abi/permit/IERC20Permit.json';
|
|
9
|
-
import PermitLegacyABI from '../abi/permit/IERC20PermitLegacy.json';
|
|
10
|
-
import { IDexHelper } from '../dex-helper';
|
|
11
|
-
|
|
12
|
-
const PERMIT_SIGHASH = new Interface(PermitABI).getSighash('permit');
|
|
13
|
-
const PERMIT_LEGACY_SIGHASH = new Interface(PermitLegacyABI).getSighash(
|
|
14
|
-
'permit',
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
export type AugustusRFQOrderData = {
|
|
18
|
-
nonceAndMeta: string;
|
|
19
|
-
expiry: number;
|
|
20
|
-
makerAsset: string; // For non-NFT order this is an Address
|
|
21
|
-
makerAssetId?: string; // NFT orders only
|
|
22
|
-
takerAsset: string; // For non-NFT order this is an Address
|
|
23
|
-
takerAssetId?: string; // NFT orders only
|
|
24
|
-
maker: Address;
|
|
25
|
-
taker: Address;
|
|
26
|
-
makerAmount: string;
|
|
27
|
-
takerAmount: string;
|
|
28
|
-
signature: string;
|
|
29
|
-
permitMakerAsset?: string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type AugustusRFQOrderParam = {
|
|
33
|
-
nonceAndMeta: string;
|
|
34
|
-
expiry: number;
|
|
35
|
-
makerAsset: Address;
|
|
36
|
-
takerAsset: Address;
|
|
37
|
-
maker: Address;
|
|
38
|
-
taker: Address;
|
|
39
|
-
makerAmount: string;
|
|
40
|
-
takerAmount: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type AugustusRFQOrderNFTParam = {
|
|
44
|
-
nonceAndMeta: string;
|
|
45
|
-
expiry: number;
|
|
46
|
-
makerAsset: string;
|
|
47
|
-
makerAssetId: string;
|
|
48
|
-
takerAsset: string;
|
|
49
|
-
takerAssetId: string;
|
|
50
|
-
maker: Address;
|
|
51
|
-
taker: Address;
|
|
52
|
-
makerAmount: string;
|
|
53
|
-
takerAmount: string;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
type FillOrderParam = [order: AugustusRFQOrderParam, signature: string];
|
|
57
|
-
type FillOrderNFTParam = [order: AugustusRFQOrderNFTParam, signature: string];
|
|
58
|
-
|
|
59
|
-
type AugustusRFQParam = FillOrderParam | FillOrderNFTParam;
|
|
60
|
-
|
|
61
|
-
enum AugustusRFQFunctions {
|
|
62
|
-
fillOrder = 'fillOrder',
|
|
63
|
-
fillOrderNFT = 'fillOrderNFT',
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const AUGUSTUS_RFQ_ADDRESS: { [network: number]: Address } = {
|
|
67
|
-
[Network.MAINNET]: '0xe92b586627ccA7a83dC919cc7127196d70f55a06',
|
|
68
|
-
[Network.BSC]: '0x8DcDfe88EF0351f27437284D0710cD65b20288bb',
|
|
69
|
-
[Network.POLYGON]: '0xF3CD476C3C4D3Ac5cA2724767f269070CA09A043',
|
|
70
|
-
[Network.AVALANCHE]: '0x34302c4267d0dA0A8c65510282Cc22E9e39df51f',
|
|
71
|
-
[Network.FANTOM]: '0x2DF17455B96Dde3618FD6B1C3a9AA06D6aB89347',
|
|
72
|
-
[Network.ARBITRUM]: '0x0927FD43a7a87E3E8b81Df2c44B03C4756849F6D',
|
|
73
|
-
[Network.OPTIMISM]: '0x0927FD43a7a87E3E8b81Df2c44B03C4756849F6D',
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export class AugustusRFQOrder
|
|
77
|
-
extends SimpleExchange
|
|
78
|
-
implements IDexTxBuilder<AugustusRFQOrderData, AugustusRFQParam>
|
|
79
|
-
{
|
|
80
|
-
static dexKeys = ['augustusrfqorder'];
|
|
81
|
-
rfqInterface: Interface;
|
|
82
|
-
needWrapNative = true;
|
|
83
|
-
|
|
84
|
-
constructor(dexHelper: IDexHelper) {
|
|
85
|
-
super(dexHelper, 'augustusrfqorder');
|
|
86
|
-
this.rfqInterface = new Interface(AugustusRFQABI as JsonFragment[]);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getAdapterParam(
|
|
90
|
-
srcToken: string,
|
|
91
|
-
destToken: string,
|
|
92
|
-
srcAmount: string,
|
|
93
|
-
destAmount: string,
|
|
94
|
-
data: AugustusRFQOrderData,
|
|
95
|
-
side: SwapSide,
|
|
96
|
-
): AdapterExchangeParam {
|
|
97
|
-
throw new Error('AugustusRFQOrder: getAdapterParam not implemented!');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async getSimpleParam(
|
|
101
|
-
srcToken: string,
|
|
102
|
-
destToken: string,
|
|
103
|
-
srcAmount: string,
|
|
104
|
-
destAmount: string,
|
|
105
|
-
data: AugustusRFQOrderData,
|
|
106
|
-
side: SwapSide,
|
|
107
|
-
): Promise<SimpleExchangeParam> {
|
|
108
|
-
const isNFTOrder = !!data.makerAssetId || !!data.takerAssetId;
|
|
109
|
-
|
|
110
|
-
const swapFunction = isNFTOrder
|
|
111
|
-
? AugustusRFQFunctions.fillOrderNFT
|
|
112
|
-
: AugustusRFQFunctions.fillOrder;
|
|
113
|
-
|
|
114
|
-
const swapFunctionParams: AugustusRFQParam = isNFTOrder
|
|
115
|
-
? [
|
|
116
|
-
{
|
|
117
|
-
nonceAndMeta: data.nonceAndMeta,
|
|
118
|
-
expiry: data.expiry,
|
|
119
|
-
makerAsset: data.makerAsset,
|
|
120
|
-
makerAssetId: data.makerAssetId!,
|
|
121
|
-
takerAsset: data.takerAsset,
|
|
122
|
-
takerAssetId: data.takerAssetId!,
|
|
123
|
-
maker: data.maker,
|
|
124
|
-
taker: data.taker,
|
|
125
|
-
makerAmount: data.makerAmount,
|
|
126
|
-
takerAmount: data.takerAmount,
|
|
127
|
-
},
|
|
128
|
-
data.signature,
|
|
129
|
-
]
|
|
130
|
-
: [
|
|
131
|
-
{
|
|
132
|
-
nonceAndMeta: data.nonceAndMeta,
|
|
133
|
-
expiry: data.expiry,
|
|
134
|
-
makerAsset: data.makerAsset,
|
|
135
|
-
takerAsset: data.takerAsset,
|
|
136
|
-
maker: data.maker,
|
|
137
|
-
taker: data.taker,
|
|
138
|
-
makerAmount: data.makerAmount,
|
|
139
|
-
takerAmount: data.takerAmount,
|
|
140
|
-
},
|
|
141
|
-
data.signature,
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
const swapData = this.rfqInterface.encodeFunctionData(
|
|
145
|
-
swapFunction,
|
|
146
|
-
swapFunctionParams,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
const simpleParam = await this.buildSimpleParamWithoutWETHConversion(
|
|
150
|
-
srcToken,
|
|
151
|
-
srcAmount,
|
|
152
|
-
destToken,
|
|
153
|
-
destAmount,
|
|
154
|
-
swapData,
|
|
155
|
-
AUGUSTUS_RFQ_ADDRESS[this.network],
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
if (data.permitMakerAsset) {
|
|
159
|
-
if (isNFTOrder) throw new Error('Permit not supported for NFTs');
|
|
160
|
-
|
|
161
|
-
let permitCalldata: string;
|
|
162
|
-
if (isHexString(data.permitMakerAsset, 7 * 32)) {
|
|
163
|
-
permitCalldata = hexConcat([PERMIT_SIGHASH, data.permitMakerAsset]);
|
|
164
|
-
} else if (isHexString(data.permitMakerAsset, 8 * 32)) {
|
|
165
|
-
permitCalldata = hexConcat([
|
|
166
|
-
PERMIT_LEGACY_SIGHASH,
|
|
167
|
-
data.permitMakerAsset,
|
|
168
|
-
]);
|
|
169
|
-
} else {
|
|
170
|
-
throw new Error('Invalid permitMakerAsset');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
simpleParam.callees.unshift(data.makerAsset);
|
|
174
|
-
simpleParam.calldata.unshift(permitCalldata);
|
|
175
|
-
simpleParam.values.unshift('0');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return simpleParam;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
1
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
+
import { isHexString, hexConcat } from '@ethersproject/bytes';
|
|
3
|
+
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
4
|
+
import { SwapSide, Network } from '../constants';
|
|
5
|
+
import { IDexTxBuilder } from './idex';
|
|
6
|
+
import { SimpleExchange } from './simple-exchange';
|
|
7
|
+
import AugustusRFQABI from '../abi/paraswap-limit-orders/AugustusRFQ.abi.json';
|
|
8
|
+
import PermitABI from '../abi/permit/IERC20Permit.json';
|
|
9
|
+
import PermitLegacyABI from '../abi/permit/IERC20PermitLegacy.json';
|
|
10
|
+
import { IDexHelper } from '../dex-helper';
|
|
11
|
+
|
|
12
|
+
const PERMIT_SIGHASH = new Interface(PermitABI).getSighash('permit');
|
|
13
|
+
const PERMIT_LEGACY_SIGHASH = new Interface(PermitLegacyABI).getSighash(
|
|
14
|
+
'permit',
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export type AugustusRFQOrderData = {
|
|
18
|
+
nonceAndMeta: string;
|
|
19
|
+
expiry: number;
|
|
20
|
+
makerAsset: string; // For non-NFT order this is an Address
|
|
21
|
+
makerAssetId?: string; // NFT orders only
|
|
22
|
+
takerAsset: string; // For non-NFT order this is an Address
|
|
23
|
+
takerAssetId?: string; // NFT orders only
|
|
24
|
+
maker: Address;
|
|
25
|
+
taker: Address;
|
|
26
|
+
makerAmount: string;
|
|
27
|
+
takerAmount: string;
|
|
28
|
+
signature: string;
|
|
29
|
+
permitMakerAsset?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type AugustusRFQOrderParam = {
|
|
33
|
+
nonceAndMeta: string;
|
|
34
|
+
expiry: number;
|
|
35
|
+
makerAsset: Address;
|
|
36
|
+
takerAsset: Address;
|
|
37
|
+
maker: Address;
|
|
38
|
+
taker: Address;
|
|
39
|
+
makerAmount: string;
|
|
40
|
+
takerAmount: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type AugustusRFQOrderNFTParam = {
|
|
44
|
+
nonceAndMeta: string;
|
|
45
|
+
expiry: number;
|
|
46
|
+
makerAsset: string;
|
|
47
|
+
makerAssetId: string;
|
|
48
|
+
takerAsset: string;
|
|
49
|
+
takerAssetId: string;
|
|
50
|
+
maker: Address;
|
|
51
|
+
taker: Address;
|
|
52
|
+
makerAmount: string;
|
|
53
|
+
takerAmount: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type FillOrderParam = [order: AugustusRFQOrderParam, signature: string];
|
|
57
|
+
type FillOrderNFTParam = [order: AugustusRFQOrderNFTParam, signature: string];
|
|
58
|
+
|
|
59
|
+
type AugustusRFQParam = FillOrderParam | FillOrderNFTParam;
|
|
60
|
+
|
|
61
|
+
enum AugustusRFQFunctions {
|
|
62
|
+
fillOrder = 'fillOrder',
|
|
63
|
+
fillOrderNFT = 'fillOrderNFT',
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const AUGUSTUS_RFQ_ADDRESS: { [network: number]: Address } = {
|
|
67
|
+
[Network.MAINNET]: '0xe92b586627ccA7a83dC919cc7127196d70f55a06',
|
|
68
|
+
[Network.BSC]: '0x8DcDfe88EF0351f27437284D0710cD65b20288bb',
|
|
69
|
+
[Network.POLYGON]: '0xF3CD476C3C4D3Ac5cA2724767f269070CA09A043',
|
|
70
|
+
[Network.AVALANCHE]: '0x34302c4267d0dA0A8c65510282Cc22E9e39df51f',
|
|
71
|
+
[Network.FANTOM]: '0x2DF17455B96Dde3618FD6B1C3a9AA06D6aB89347',
|
|
72
|
+
[Network.ARBITRUM]: '0x0927FD43a7a87E3E8b81Df2c44B03C4756849F6D',
|
|
73
|
+
[Network.OPTIMISM]: '0x0927FD43a7a87E3E8b81Df2c44B03C4756849F6D',
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export class AugustusRFQOrder
|
|
77
|
+
extends SimpleExchange
|
|
78
|
+
implements IDexTxBuilder<AugustusRFQOrderData, AugustusRFQParam>
|
|
79
|
+
{
|
|
80
|
+
static dexKeys = ['augustusrfqorder'];
|
|
81
|
+
rfqInterface: Interface;
|
|
82
|
+
needWrapNative = true;
|
|
83
|
+
|
|
84
|
+
constructor(dexHelper: IDexHelper) {
|
|
85
|
+
super(dexHelper, 'augustusrfqorder');
|
|
86
|
+
this.rfqInterface = new Interface(AugustusRFQABI as JsonFragment[]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getAdapterParam(
|
|
90
|
+
srcToken: string,
|
|
91
|
+
destToken: string,
|
|
92
|
+
srcAmount: string,
|
|
93
|
+
destAmount: string,
|
|
94
|
+
data: AugustusRFQOrderData,
|
|
95
|
+
side: SwapSide,
|
|
96
|
+
): AdapterExchangeParam {
|
|
97
|
+
throw new Error('AugustusRFQOrder: getAdapterParam not implemented!');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async getSimpleParam(
|
|
101
|
+
srcToken: string,
|
|
102
|
+
destToken: string,
|
|
103
|
+
srcAmount: string,
|
|
104
|
+
destAmount: string,
|
|
105
|
+
data: AugustusRFQOrderData,
|
|
106
|
+
side: SwapSide,
|
|
107
|
+
): Promise<SimpleExchangeParam> {
|
|
108
|
+
const isNFTOrder = !!data.makerAssetId || !!data.takerAssetId;
|
|
109
|
+
|
|
110
|
+
const swapFunction = isNFTOrder
|
|
111
|
+
? AugustusRFQFunctions.fillOrderNFT
|
|
112
|
+
: AugustusRFQFunctions.fillOrder;
|
|
113
|
+
|
|
114
|
+
const swapFunctionParams: AugustusRFQParam = isNFTOrder
|
|
115
|
+
? [
|
|
116
|
+
{
|
|
117
|
+
nonceAndMeta: data.nonceAndMeta,
|
|
118
|
+
expiry: data.expiry,
|
|
119
|
+
makerAsset: data.makerAsset,
|
|
120
|
+
makerAssetId: data.makerAssetId!,
|
|
121
|
+
takerAsset: data.takerAsset,
|
|
122
|
+
takerAssetId: data.takerAssetId!,
|
|
123
|
+
maker: data.maker,
|
|
124
|
+
taker: data.taker,
|
|
125
|
+
makerAmount: data.makerAmount,
|
|
126
|
+
takerAmount: data.takerAmount,
|
|
127
|
+
},
|
|
128
|
+
data.signature,
|
|
129
|
+
]
|
|
130
|
+
: [
|
|
131
|
+
{
|
|
132
|
+
nonceAndMeta: data.nonceAndMeta,
|
|
133
|
+
expiry: data.expiry,
|
|
134
|
+
makerAsset: data.makerAsset,
|
|
135
|
+
takerAsset: data.takerAsset,
|
|
136
|
+
maker: data.maker,
|
|
137
|
+
taker: data.taker,
|
|
138
|
+
makerAmount: data.makerAmount,
|
|
139
|
+
takerAmount: data.takerAmount,
|
|
140
|
+
},
|
|
141
|
+
data.signature,
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
const swapData = this.rfqInterface.encodeFunctionData(
|
|
145
|
+
swapFunction,
|
|
146
|
+
swapFunctionParams,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const simpleParam = await this.buildSimpleParamWithoutWETHConversion(
|
|
150
|
+
srcToken,
|
|
151
|
+
srcAmount,
|
|
152
|
+
destToken,
|
|
153
|
+
destAmount,
|
|
154
|
+
swapData,
|
|
155
|
+
AUGUSTUS_RFQ_ADDRESS[this.network],
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
if (data.permitMakerAsset) {
|
|
159
|
+
if (isNFTOrder) throw new Error('Permit not supported for NFTs');
|
|
160
|
+
|
|
161
|
+
let permitCalldata: string;
|
|
162
|
+
if (isHexString(data.permitMakerAsset, 7 * 32)) {
|
|
163
|
+
permitCalldata = hexConcat([PERMIT_SIGHASH, data.permitMakerAsset]);
|
|
164
|
+
} else if (isHexString(data.permitMakerAsset, 8 * 32)) {
|
|
165
|
+
permitCalldata = hexConcat([
|
|
166
|
+
PERMIT_LEGACY_SIGHASH,
|
|
167
|
+
data.permitMakerAsset,
|
|
168
|
+
]);
|
|
169
|
+
} else {
|
|
170
|
+
throw new Error('Invalid permitMakerAsset');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
simpleParam.callees.unshift(data.makerAsset);
|
|
174
|
+
simpleParam.calldata.unshift(permitCalldata);
|
|
175
|
+
simpleParam.values.unshift('0');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return simpleParam;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
-
import { SwapSide } from '../../constants';
|
|
3
|
-
import {
|
|
4
|
-
AdapterExchangeParam,
|
|
5
|
-
Address,
|
|
6
|
-
DexExchangeParam,
|
|
7
|
-
NumberAsString,
|
|
8
|
-
SimpleExchangeParam,
|
|
9
|
-
} from '../../types';
|
|
10
|
-
import { IDexTxBuilder } from '../idex';
|
|
11
|
-
import { SimpleExchange } from '../simple-exchange';
|
|
12
|
-
import BProtocolABI from '../../abi/BProtocol.json';
|
|
13
|
-
import { IDexHelper } from '../../dex-helper';
|
|
14
|
-
import { BProtocolData, BProtocolFunctions, BProtocolParam } from './types';
|
|
15
|
-
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
16
|
-
|
|
17
|
-
export class BProtocol
|
|
18
|
-
extends SimpleExchange
|
|
19
|
-
implements IDexTxBuilder<BProtocolData, BProtocolParam>
|
|
20
|
-
{
|
|
21
|
-
static dexKeys = ['bprotocol'];
|
|
22
|
-
exchangeRouterInterface: Interface;
|
|
23
|
-
|
|
24
|
-
constructor(dexHelper: IDexHelper) {
|
|
25
|
-
super(dexHelper, 'bprotocol');
|
|
26
|
-
this.exchangeRouterInterface = new Interface(
|
|
27
|
-
BProtocolABI as JsonFragment[],
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getAdapterParam(
|
|
32
|
-
srcToken: string,
|
|
33
|
-
destToken: string,
|
|
34
|
-
srcAmount: string,
|
|
35
|
-
destAmount: string,
|
|
36
|
-
data: BProtocolData,
|
|
37
|
-
side: SwapSide,
|
|
38
|
-
): AdapterExchangeParam {
|
|
39
|
-
return {
|
|
40
|
-
targetExchange: data.exchange,
|
|
41
|
-
payload: '0x',
|
|
42
|
-
networkFee: '0',
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getSimpleParam(
|
|
47
|
-
srcToken: string,
|
|
48
|
-
destToken: string,
|
|
49
|
-
srcAmount: string,
|
|
50
|
-
destAmount: string,
|
|
51
|
-
data: BProtocolData,
|
|
52
|
-
side: SwapSide,
|
|
53
|
-
): Promise<SimpleExchangeParam> {
|
|
54
|
-
const swapFunction = BProtocolFunctions.swap;
|
|
55
|
-
const swapFunctionParams: BProtocolParam = [
|
|
56
|
-
srcAmount,
|
|
57
|
-
destAmount,
|
|
58
|
-
this.augustusAddress,
|
|
59
|
-
];
|
|
60
|
-
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
61
|
-
swapFunction,
|
|
62
|
-
swapFunctionParams,
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return this.buildSimpleParamWithoutWETHConversion(
|
|
66
|
-
srcToken,
|
|
67
|
-
srcAmount,
|
|
68
|
-
destToken,
|
|
69
|
-
destAmount,
|
|
70
|
-
swapData,
|
|
71
|
-
data.exchange,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getDexParam(
|
|
76
|
-
_srcToken: Address,
|
|
77
|
-
_destToken: Address,
|
|
78
|
-
srcAmount: NumberAsString,
|
|
79
|
-
destAmount: NumberAsString,
|
|
80
|
-
recipient: Address,
|
|
81
|
-
data: BProtocolData,
|
|
82
|
-
_side: SwapSide,
|
|
83
|
-
): DexExchangeParam {
|
|
84
|
-
const swapFunction = BProtocolFunctions.swap;
|
|
85
|
-
const swapFunctionParams: BProtocolParam = [
|
|
86
|
-
srcAmount,
|
|
87
|
-
destAmount,
|
|
88
|
-
recipient,
|
|
89
|
-
];
|
|
90
|
-
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
91
|
-
swapFunction,
|
|
92
|
-
swapFunctionParams,
|
|
93
|
-
);
|
|
94
|
-
return {
|
|
95
|
-
needWrapNative: this.needWrapNative,
|
|
96
|
-
dexFuncHasRecipient: true,
|
|
97
|
-
exchangeData: swapData,
|
|
98
|
-
targetExchange: data.exchange,
|
|
99
|
-
returnAmountPos:
|
|
100
|
-
_side === SwapSide.SELL
|
|
101
|
-
? extractReturnAmountPosition(
|
|
102
|
-
this.exchangeRouterInterface,
|
|
103
|
-
swapFunction,
|
|
104
|
-
)
|
|
105
|
-
: undefined,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
1
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
+
import { SwapSide } from '../../constants';
|
|
3
|
+
import {
|
|
4
|
+
AdapterExchangeParam,
|
|
5
|
+
Address,
|
|
6
|
+
DexExchangeParam,
|
|
7
|
+
NumberAsString,
|
|
8
|
+
SimpleExchangeParam,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
import { IDexTxBuilder } from '../idex';
|
|
11
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
12
|
+
import BProtocolABI from '../../abi/BProtocol.json';
|
|
13
|
+
import { IDexHelper } from '../../dex-helper';
|
|
14
|
+
import { BProtocolData, BProtocolFunctions, BProtocolParam } from './types';
|
|
15
|
+
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
16
|
+
|
|
17
|
+
export class BProtocol
|
|
18
|
+
extends SimpleExchange
|
|
19
|
+
implements IDexTxBuilder<BProtocolData, BProtocolParam>
|
|
20
|
+
{
|
|
21
|
+
static dexKeys = ['bprotocol'];
|
|
22
|
+
exchangeRouterInterface: Interface;
|
|
23
|
+
|
|
24
|
+
constructor(dexHelper: IDexHelper) {
|
|
25
|
+
super(dexHelper, 'bprotocol');
|
|
26
|
+
this.exchangeRouterInterface = new Interface(
|
|
27
|
+
BProtocolABI as JsonFragment[],
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getAdapterParam(
|
|
32
|
+
srcToken: string,
|
|
33
|
+
destToken: string,
|
|
34
|
+
srcAmount: string,
|
|
35
|
+
destAmount: string,
|
|
36
|
+
data: BProtocolData,
|
|
37
|
+
side: SwapSide,
|
|
38
|
+
): AdapterExchangeParam {
|
|
39
|
+
return {
|
|
40
|
+
targetExchange: data.exchange,
|
|
41
|
+
payload: '0x',
|
|
42
|
+
networkFee: '0',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async getSimpleParam(
|
|
47
|
+
srcToken: string,
|
|
48
|
+
destToken: string,
|
|
49
|
+
srcAmount: string,
|
|
50
|
+
destAmount: string,
|
|
51
|
+
data: BProtocolData,
|
|
52
|
+
side: SwapSide,
|
|
53
|
+
): Promise<SimpleExchangeParam> {
|
|
54
|
+
const swapFunction = BProtocolFunctions.swap;
|
|
55
|
+
const swapFunctionParams: BProtocolParam = [
|
|
56
|
+
srcAmount,
|
|
57
|
+
destAmount,
|
|
58
|
+
this.augustusAddress,
|
|
59
|
+
];
|
|
60
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
61
|
+
swapFunction,
|
|
62
|
+
swapFunctionParams,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return this.buildSimpleParamWithoutWETHConversion(
|
|
66
|
+
srcToken,
|
|
67
|
+
srcAmount,
|
|
68
|
+
destToken,
|
|
69
|
+
destAmount,
|
|
70
|
+
swapData,
|
|
71
|
+
data.exchange,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getDexParam(
|
|
76
|
+
_srcToken: Address,
|
|
77
|
+
_destToken: Address,
|
|
78
|
+
srcAmount: NumberAsString,
|
|
79
|
+
destAmount: NumberAsString,
|
|
80
|
+
recipient: Address,
|
|
81
|
+
data: BProtocolData,
|
|
82
|
+
_side: SwapSide,
|
|
83
|
+
): DexExchangeParam {
|
|
84
|
+
const swapFunction = BProtocolFunctions.swap;
|
|
85
|
+
const swapFunctionParams: BProtocolParam = [
|
|
86
|
+
srcAmount,
|
|
87
|
+
destAmount,
|
|
88
|
+
recipient,
|
|
89
|
+
];
|
|
90
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
91
|
+
swapFunction,
|
|
92
|
+
swapFunctionParams,
|
|
93
|
+
);
|
|
94
|
+
return {
|
|
95
|
+
needWrapNative: this.needWrapNative,
|
|
96
|
+
dexFuncHasRecipient: true,
|
|
97
|
+
exchangeData: swapData,
|
|
98
|
+
targetExchange: data.exchange,
|
|
99
|
+
returnAmountPos:
|
|
100
|
+
_side === SwapSide.SELL
|
|
101
|
+
? extractReturnAmountPosition(
|
|
102
|
+
this.exchangeRouterInterface,
|
|
103
|
+
swapFunction,
|
|
104
|
+
)
|
|
105
|
+
: undefined,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|