@paraswap/dex-lib 2.19.1 → 2.20.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/build/abi/DirectSwap.json +1018 -0
- package/build/dex/balancer-v2/balancer-v2.d.ts +9 -3
- package/build/dex/balancer-v2/balancer-v2.js +83 -0
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/constants.d.ts +4 -0
- package/build/dex/balancer-v2/constants.js +6 -1
- package/build/dex/balancer-v2/constants.js.map +1 -1
- package/build/dex/balancer-v2/types.d.ts +20 -1
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/curve-v1/constants.d.ts +1 -0
- package/build/dex/curve-v1/constants.js +2 -1
- package/build/dex/curve-v1/constants.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +9 -3
- package/build/dex/curve-v1/curve-v1.js +92 -4
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1/types.d.ts +24 -0
- package/build/dex/curve-v1/types.js +6 -1
- package/build/dex/curve-v1/types.js.map +1 -1
- package/build/dex/curve-v1-factory/constants.d.ts +1 -0
- package/build/dex/curve-v1-factory/constants.js +2 -1
- package/build/dex/curve-v1-factory/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +11 -4
- package/build/dex/curve-v1-factory/curve-v1-factory.js +87 -0
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +24 -0
- package/build/dex/curve-v1-factory/types.js +6 -1
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/curve-v2.d.ts +29 -7
- package/build/dex/curve-v2.js +91 -1
- package/build/dex/curve-v2.js.map +1 -1
- package/build/dex/idex.d.ts +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -2
- package/build/dex/pancakeswap-v3/utils.js.map +1 -1
- package/build/dex/simple-exchange.d.ts +2 -0
- package/build/dex/simple-exchange.js +1 -0
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/swaap-v2/swaap-v2.js +5 -1
- package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
- package/build/dex/swaap-v2/utils.js.map +1 -1
- package/build/dex/swaap-v2/validators.js +1 -2
- package/build/dex/swaap-v2/validators.js.map +1 -1
- package/build/dex/test-dex/config.d.ts +4 -0
- package/build/dex/test-dex/config.js +15 -0
- package/build/dex/test-dex/config.js.map +1 -0
- package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
- package/build/dex/test-dex/test-dex-pool.js +63 -0
- package/build/dex/test-dex/test-dex-pool.js.map +1 -0
- package/build/dex/test-dex/test-dex.d.ts +37 -0
- package/build/dex/test-dex/test-dex.js +126 -0
- package/build/dex/test-dex/test-dex.js.map +1 -0
- package/build/dex/test-dex/types.d.ts +6 -0
- package/build/dex/{pancakeswap-v3 → test-dex}/types.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.d.ts +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/constants.d.ts +4 -0
- package/build/dex/uniswap-v3/constants.js +6 -1
- package/build/dex/uniswap-v3/constants.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +20 -3
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +7 -1
- package/build/dex/uniswap-v3/uniswap-v3.js +85 -1
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
- package/build/dex/zerox/index.d.ts +1 -1
- package/build/dex/zerox/index.js +1 -1
- package/build/dex/zerox/index.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +5 -1
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/router/directswap.js +7 -1
- package/build/router/directswap.js.map +1 -1
- package/build/router/index.js.map +1 -1
- package/build/router/payload-encoder.js +14 -3
- package/build/router/payload-encoder.js.map +1 -1
- package/build/types.d.ts +1 -0
- package/build/utils.js.map +1 -1
- package/package.json +5 -3
- package/src/abi/DirectSwap.json +1018 -0
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +79 -0
- package/src/dex/balancer-v2/balancer-v2.ts +153 -4
- package/src/dex/balancer-v2/constants.ts +5 -0
- package/src/dex/balancer-v2/types.ts +21 -1
- package/src/dex/curve-v1/constants.ts +2 -0
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +57 -0
- package/src/dex/curve-v1/curve-v1.ts +144 -5
- package/src/dex/curve-v1/types.ts +26 -0
- package/src/dex/curve-v1-factory/constants.ts +2 -0
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +1 -0
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +140 -4
- package/src/dex/curve-v1-factory/types.ts +26 -0
- package/src/dex/curve-v2.ts +169 -8
- package/src/dex/idex.ts +6 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +3 -6
- package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +3 -14
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +3 -3
- package/src/dex/pancakeswap-v3/utils.ts +1 -4
- package/src/dex/simple-exchange.ts +6 -0
- package/src/dex/solidly/solidly-e2e.test.ts +31 -32
- package/src/dex/swaap-v2/swaap-v2.ts +19 -11
- package/src/dex/swaap-v2/types.ts +4 -4
- package/src/dex/swaap-v2/utils.ts +4 -4
- package/src/dex/swaap-v2/validators.ts +4 -7
- package/src/dex/uniswap-v2/uniswap-v2.ts +6 -0
- package/src/dex/uniswap-v3/constants.ts +5 -0
- package/src/dex/uniswap-v3/types.ts +23 -3
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +100 -2
- package/src/dex/uniswap-v3/uniswap-v3.ts +138 -3
- package/src/dex/zerox/index.ts +7 -0
- package/src/implementations/local-paraswap-sdk.ts +8 -1
- package/src/router/directswap.ts +23 -0
- package/src/router/index.ts +0 -2
- package/src/router/payload-encoder.ts +19 -3
- package/src/types.ts +1 -0
- package/src/utils.ts +1 -1
- package/tests/constants-e2e.ts +3 -3
- package/tests/utils-e2e.ts +136 -21
- package/tests/utils.ts +52 -0
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/vcs.xml +0 -6
- package/build/dex/pancakeswap-v3/types.d.ts +0 -14
- package/build/dex/solidly/forks-override/chronos.d.ts +0 -20
- package/build/dex/solidly/forks-override/chronos.js +0 -44
- package/build/dex/solidly/forks-override/chronos.js.map +0 -1
- /package/build/dex/{pancakeswap-v3 → test-dex}/types.js +0 -0
package/src/router/directswap.ts
CHANGED
|
@@ -3,6 +3,11 @@ import { IDex } from '../dex/idex';
|
|
|
3
3
|
import { Address, OptimalRate, TxInfo, Adapters } from '../types';
|
|
4
4
|
import { SwapSide } from '../constants';
|
|
5
5
|
import { DexAdapterService } from '../dex';
|
|
6
|
+
import { assert } from 'ts-essentials';
|
|
7
|
+
import {
|
|
8
|
+
encodeFeePercent,
|
|
9
|
+
encodeFeePercentForReferrer,
|
|
10
|
+
} from './payload-encoder';
|
|
6
11
|
|
|
7
12
|
export class DirectSwap<DexDirectReturn> implements IRouter<DexDirectReturn> {
|
|
8
13
|
// This is just psuedo name as the DirectSwap
|
|
@@ -51,6 +56,7 @@ export class DirectSwap<DexDirectReturn> implements IRouter<DexDirectReturn> {
|
|
|
51
56
|
);
|
|
52
57
|
|
|
53
58
|
const swapExchange = priceRoute.bestRoute[0].swaps[0].swapExchanges[0];
|
|
59
|
+
|
|
54
60
|
const srcAmount =
|
|
55
61
|
priceRoute.side === SwapSide.SELL ? swapExchange.srcAmount : minMaxAmount;
|
|
56
62
|
const destAmount =
|
|
@@ -58,14 +64,31 @@ export class DirectSwap<DexDirectReturn> implements IRouter<DexDirectReturn> {
|
|
|
58
64
|
? minMaxAmount
|
|
59
65
|
: swapExchange.destAmount;
|
|
60
66
|
|
|
67
|
+
const expectedAmount =
|
|
68
|
+
priceRoute.side === SwapSide.SELL
|
|
69
|
+
? priceRoute.destAmount
|
|
70
|
+
: priceRoute.srcAmount;
|
|
71
|
+
|
|
61
72
|
return dex.getDirectParam!(
|
|
62
73
|
priceRoute.srcToken,
|
|
63
74
|
priceRoute.destToken,
|
|
64
75
|
srcAmount,
|
|
65
76
|
destAmount,
|
|
77
|
+
expectedAmount,
|
|
66
78
|
swapExchange.data,
|
|
67
79
|
priceRoute.side,
|
|
68
80
|
permit,
|
|
81
|
+
uuid,
|
|
82
|
+
referrerAddress
|
|
83
|
+
? encodeFeePercentForReferrer(priceRoute.side)
|
|
84
|
+
: encodeFeePercent(
|
|
85
|
+
partnerFeePercent,
|
|
86
|
+
positiveSlippageToUser,
|
|
87
|
+
priceRoute.side,
|
|
88
|
+
),
|
|
89
|
+
deadline,
|
|
90
|
+
referrerAddress || partnerAddress,
|
|
91
|
+
beneficiary,
|
|
69
92
|
priceRoute.contractMethod,
|
|
70
93
|
);
|
|
71
94
|
}
|
package/src/router/index.ts
CHANGED
|
@@ -5,9 +5,7 @@ import { Buy } from './buy';
|
|
|
5
5
|
import { SimpleSwap, SimpleBuy } from './simpleswap';
|
|
6
6
|
import { SimpleBuyNFT } from './simpleswapnft';
|
|
7
7
|
import { DirectSwap } from './directswap';
|
|
8
|
-
import { Adapters } from '../types';
|
|
9
8
|
import { DexAdapterService } from '../dex';
|
|
10
|
-
import { SwapSide } from '../constants';
|
|
11
9
|
|
|
12
10
|
export class RouterService {
|
|
13
11
|
hybridRouters = [
|
|
@@ -16,20 +16,36 @@ import { convertToBasisPoints } from '../utils';
|
|
|
16
16
|
const OneShift14 = 1n << 14n;
|
|
17
17
|
const OneShift15 = 1n << 15n;
|
|
18
18
|
const OneShift16 = 1n << 16n;
|
|
19
|
+
const OneShift17 = 1n << 17n;
|
|
19
20
|
const OneShift248 = 1n << 248n;
|
|
20
21
|
|
|
21
|
-
// Referrer gets
|
|
22
|
+
// Referrer gets 25% of positive slippage
|
|
22
23
|
// Set 16th bit to indicate referral program
|
|
23
|
-
const REFERRER_FEE =
|
|
24
|
+
const REFERRER_FEE = 2500n | OneShift14 | OneShift16 | OneShift248;
|
|
25
|
+
|
|
26
|
+
const HALF_SPLIT = '5000';
|
|
24
27
|
|
|
25
28
|
export function encodeFeePercent(
|
|
26
29
|
partnerFeePercent: string,
|
|
27
30
|
positiveSlippageToUser: boolean,
|
|
28
31
|
side: SwapSide,
|
|
29
32
|
) {
|
|
30
|
-
|
|
33
|
+
const isNoFeeAndPositiveSlippageToPartner =
|
|
34
|
+
positiveSlippageToUser === false && BigInt(partnerFeePercent) === 0n;
|
|
35
|
+
|
|
36
|
+
let fee = isNoFeeAndPositiveSlippageToPartner
|
|
37
|
+
? BigInt(HALF_SPLIT)
|
|
38
|
+
: BigInt(partnerFeePercent);
|
|
39
|
+
|
|
31
40
|
if (fee > 10000) throw new Error('fee bps should be less than 10000');
|
|
32
41
|
|
|
42
|
+
// Set 16th bit as referrer to split positive slippage for partner and protocol
|
|
43
|
+
// Set 17th bit to flag on Subgraph that this is a special case
|
|
44
|
+
if (isNoFeeAndPositiveSlippageToPartner) {
|
|
45
|
+
fee |= OneShift16;
|
|
46
|
+
fee |= OneShift17;
|
|
47
|
+
}
|
|
48
|
+
|
|
33
49
|
// Set 14th bit if positiveSlippageToUser is true
|
|
34
50
|
if (positiveSlippageToUser) fee |= OneShift14;
|
|
35
51
|
|
package/src/types.ts
CHANGED
package/src/utils.ts
CHANGED
package/tests/constants-e2e.ts
CHANGED
|
@@ -898,7 +898,7 @@ export const Holders: {
|
|
|
898
898
|
[Network.POLYGON]: {
|
|
899
899
|
MATIC: '0xe7804c37c13166fF0b37F5aE0BB07A3aEbb6e245',
|
|
900
900
|
DAI: '0x06959153B974D0D5fDfd87D561db6d8d4FA0bb0B',
|
|
901
|
-
WETH: '
|
|
901
|
+
WETH: '0x62ac55b745f9b08f1a81dcbbe630277095cf4be1',
|
|
902
902
|
WMATIC: '0xFffbCD322cEace527C8ec6Da8de2461C6D9d4e6e',
|
|
903
903
|
AMWMATIC: '0x8832924854e3Cedb0a6Abf372e6CCFF9F7654332',
|
|
904
904
|
USDC: '0xf89d7b9c864f589bbf53a82105107622b35eaa40',
|
|
@@ -917,8 +917,8 @@ export const Holders: {
|
|
|
917
917
|
RADIO: '0x60531b9c3645546d864604ee0fc5b7d6adc81cc2',
|
|
918
918
|
HANZO: '0x8a151b6ec99c7b90b342ab401d511b480309b220',
|
|
919
919
|
RVLT: '0x815f87ca3db2b9491115a7769aeacb140361c5a9',
|
|
920
|
-
stMATIC: '
|
|
921
|
-
axlUSDC: '
|
|
920
|
+
stMATIC: '0x6725b8cd3cdbc82a6044689a8bbc64a915d200e7',
|
|
921
|
+
axlUSDC: '0xe743a49f04f2f77eb2d3b753ae3ad599de8cea84',
|
|
922
922
|
deUSDC: '0x94d5ead1f80cf0b4d3480ab59dff16d47c93e9fe',
|
|
923
923
|
amUSDT: '0x832b11846a27b3ba25d68ae80c39fab155d18c49',
|
|
924
924
|
amUSDC: '0x6e7f19cd23049c7118e14470e2bf85d2e26ee0ae',
|
package/tests/utils-e2e.ts
CHANGED
|
@@ -29,12 +29,37 @@ import { constructSimpleSDK, SimpleFetchSDK } from '@paraswap/sdk';
|
|
|
29
29
|
import axios from 'axios';
|
|
30
30
|
import { SmartToken, StateOverrides } from './smart-tokens';
|
|
31
31
|
import { GIFTER_ADDRESS } from './constants-e2e';
|
|
32
|
-
import { sleep } from './utils';
|
|
32
|
+
import { generateDeployBytecode, sleep } from './utils';
|
|
33
33
|
import { assert } from 'ts-essentials';
|
|
34
34
|
|
|
35
35
|
export const testingEndpoint = process.env.E2E_TEST_ENDPOINT;
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const testContractProjectRootPath = process.env.TEST_CONTRACT_PROJECT_ROOT_PATH;
|
|
38
|
+
const testContractName = process.env.TEST_CONTRACT_NAME;
|
|
39
|
+
const testContractConfigFileName = process.env.TEST_CONTRACT_CONFIG_FILE_NAME;
|
|
40
|
+
const testContractRelativePath = process.env.TEST_CONTRACT_RELATIVE_PATH;
|
|
41
|
+
// Comma separated fields from config or actual values
|
|
42
|
+
const testContractDeployArgs = process.env.TEST_CONTRACT_DEPLOY_ARGS;
|
|
43
|
+
|
|
44
|
+
// If you want to test against deployed and verified contract
|
|
45
|
+
const deployedTestContractAddress = process.env.DEPLOYED_TEST_CONTRACT_ADDRESS;
|
|
46
|
+
const testContractType = process.env.TEST_CONTRACT_TYPE;
|
|
47
|
+
|
|
48
|
+
// Only for router tests
|
|
49
|
+
const testDirectRouterAbiPath = process.env.TEST_DIRECT_ROUTER_ABI_PATH;
|
|
50
|
+
|
|
51
|
+
const directRouterIface = new Interface(
|
|
52
|
+
testDirectRouterAbiPath ? require(testDirectRouterAbiPath) : '[]',
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const testContractBytecode = generateDeployBytecode(
|
|
56
|
+
testContractProjectRootPath,
|
|
57
|
+
testContractName,
|
|
58
|
+
testContractConfigFileName,
|
|
59
|
+
testContractRelativePath,
|
|
60
|
+
testContractDeployArgs,
|
|
61
|
+
testContractType,
|
|
62
|
+
);
|
|
38
63
|
|
|
39
64
|
const erc20Interface = new Interface(Erc20ABI);
|
|
40
65
|
const augustusInterface = new Interface(AugustusABI);
|
|
@@ -146,7 +171,7 @@ function allowTokenTransferProxyParams(
|
|
|
146
171
|
};
|
|
147
172
|
}
|
|
148
173
|
|
|
149
|
-
function
|
|
174
|
+
function deployContractParams(bytecode: string, network = Network.MAINNET) {
|
|
150
175
|
const ownerAddress = DEPLOYER_ADDRESS[network];
|
|
151
176
|
if (!ownerAddress) throw new Error('No deployer address set for network');
|
|
152
177
|
return {
|
|
@@ -156,13 +181,51 @@ function deployAdapterParams(bytecode: string, network = Network.MAINNET) {
|
|
|
156
181
|
};
|
|
157
182
|
}
|
|
158
183
|
|
|
159
|
-
function
|
|
184
|
+
function augustusSetImplementationParams(
|
|
185
|
+
contractAddress: Address,
|
|
186
|
+
network: Network,
|
|
187
|
+
functionName: string,
|
|
188
|
+
) {
|
|
160
189
|
const augustusAddress = generateConfig(network).augustusAddress;
|
|
161
190
|
if (!augustusAddress) throw new Error('No whitelist address set for network');
|
|
162
191
|
const ownerAddress = MULTISIG[network];
|
|
163
192
|
if (!ownerAddress) throw new Error('No whitelist owner set for network');
|
|
164
|
-
|
|
165
|
-
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
from: ownerAddress,
|
|
196
|
+
to: augustusAddress,
|
|
197
|
+
data: augustusInterface.encodeFunctionData('setImplementation', [
|
|
198
|
+
directRouterIface.getSighash(functionName),
|
|
199
|
+
contractAddress,
|
|
200
|
+
]),
|
|
201
|
+
value: '0',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function augustusGrantRoleParams(
|
|
206
|
+
contractAddress: Address,
|
|
207
|
+
network: Network,
|
|
208
|
+
type: string = 'adapter',
|
|
209
|
+
) {
|
|
210
|
+
const augustusAddress = generateConfig(network).augustusAddress;
|
|
211
|
+
if (!augustusAddress) throw new Error('No whitelist address set for network');
|
|
212
|
+
const ownerAddress = MULTISIG[network];
|
|
213
|
+
if (!ownerAddress) throw new Error('No whitelist owner set for network');
|
|
214
|
+
|
|
215
|
+
let role: string;
|
|
216
|
+
switch (type) {
|
|
217
|
+
case 'adapter':
|
|
218
|
+
role =
|
|
219
|
+
'0x8429d542926e6695b59ac6fbdcd9b37e8b1aeb757afab06ab60b1bb5878c3b49';
|
|
220
|
+
break;
|
|
221
|
+
case 'router':
|
|
222
|
+
role =
|
|
223
|
+
'0x7a05a596cb0ce7fdea8a1e1ec73be300bdb35097c944ce1897202f7a13122eb2';
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
throw new Error(`Unrecognized type ${type}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
166
229
|
return {
|
|
167
230
|
from: ownerAddress,
|
|
168
231
|
to: augustusAddress,
|
|
@@ -174,6 +237,21 @@ function whiteListAdapterParams(contractAddress: Address, network: Network) {
|
|
|
174
237
|
};
|
|
175
238
|
}
|
|
176
239
|
|
|
240
|
+
export function formatDeployMessage(
|
|
241
|
+
type: 'router' | 'adapter',
|
|
242
|
+
address: Address,
|
|
243
|
+
forkId: string,
|
|
244
|
+
contractName: string,
|
|
245
|
+
contractPath: string,
|
|
246
|
+
) {
|
|
247
|
+
// This formatting is useful for verification on Tenderly
|
|
248
|
+
return `Deployed ${type} contract with env params:
|
|
249
|
+
TENDERLY_FORK_ID=${forkId}
|
|
250
|
+
TENDERLY_VERIFY_CONTRACT_ADDRESS=${address}
|
|
251
|
+
TENDERLY_VERIFY_CONTRACT_NAME=${contractName}
|
|
252
|
+
TENDERLY_VERIFY_CONTRACT_PATH=${contractPath}`;
|
|
253
|
+
}
|
|
254
|
+
|
|
177
255
|
export async function testE2E(
|
|
178
256
|
srcToken: Token,
|
|
179
257
|
destToken: Token,
|
|
@@ -183,7 +261,7 @@ export async function testE2E(
|
|
|
183
261
|
dexKey: string,
|
|
184
262
|
contractMethod: ContractMethod,
|
|
185
263
|
network: Network = Network.MAINNET,
|
|
186
|
-
|
|
264
|
+
_0: Provider,
|
|
187
265
|
poolIdentifiers?: string[],
|
|
188
266
|
limitOrderProvider?: DummyLimitOrderProvider,
|
|
189
267
|
transferFees?: TransferFeeParams,
|
|
@@ -203,26 +281,63 @@ export async function testE2E(
|
|
|
203
281
|
expect(allowanceTx!.success).toEqual(true);
|
|
204
282
|
}
|
|
205
283
|
|
|
206
|
-
if (
|
|
284
|
+
if (deployedTestContractAddress) {
|
|
285
|
+
const whitelistTx = await ts.simulate(
|
|
286
|
+
augustusGrantRoleParams(
|
|
287
|
+
deployedTestContractAddress,
|
|
288
|
+
network,
|
|
289
|
+
testContractType || 'adapter',
|
|
290
|
+
),
|
|
291
|
+
);
|
|
292
|
+
expect(whitelistTx.success).toEqual(true);
|
|
293
|
+
|
|
294
|
+
if (testContractType === 'router') {
|
|
295
|
+
const setImplementationTx = await ts.simulate(
|
|
296
|
+
augustusSetImplementationParams(
|
|
297
|
+
deployedTestContractAddress,
|
|
298
|
+
network,
|
|
299
|
+
contractMethod,
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
expect(setImplementationTx.success).toEqual(true);
|
|
303
|
+
}
|
|
304
|
+
} else if (testContractBytecode) {
|
|
207
305
|
const deployTx = await ts.simulate(
|
|
208
|
-
|
|
306
|
+
deployContractParams(testContractBytecode, network),
|
|
209
307
|
);
|
|
210
308
|
|
|
211
309
|
expect(deployTx.success).toEqual(true);
|
|
212
|
-
|
|
310
|
+
|
|
311
|
+
const contractAddress =
|
|
213
312
|
deployTx.transaction.transaction_info.contract_address;
|
|
214
313
|
console.log(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
314
|
+
formatDeployMessage(
|
|
315
|
+
'adapter',
|
|
316
|
+
contractAddress,
|
|
317
|
+
ts.forkId,
|
|
318
|
+
testContractName || '',
|
|
319
|
+
testContractRelativePath || '',
|
|
320
|
+
),
|
|
220
321
|
);
|
|
221
|
-
|
|
222
322
|
const whitelistTx = await ts.simulate(
|
|
223
|
-
|
|
323
|
+
augustusGrantRoleParams(
|
|
324
|
+
contractAddress,
|
|
325
|
+
network,
|
|
326
|
+
testContractType || 'adapter',
|
|
327
|
+
),
|
|
224
328
|
);
|
|
225
329
|
expect(whitelistTx.success).toEqual(true);
|
|
330
|
+
|
|
331
|
+
if (testContractType === 'router') {
|
|
332
|
+
const setImplementationTx = await ts.simulate(
|
|
333
|
+
augustusSetImplementationParams(
|
|
334
|
+
contractAddress,
|
|
335
|
+
network,
|
|
336
|
+
contractMethod,
|
|
337
|
+
),
|
|
338
|
+
);
|
|
339
|
+
expect(setImplementationTx.success).toEqual(true);
|
|
340
|
+
}
|
|
226
341
|
}
|
|
227
342
|
|
|
228
343
|
const useAPI = testingEndpoint && !poolIdentifiers;
|
|
@@ -232,7 +347,7 @@ export async function testE2E(
|
|
|
232
347
|
: new LocalParaswapSDK(network, dexKey, '', limitOrderProvider);
|
|
233
348
|
|
|
234
349
|
if (paraswap.initializePricing) await paraswap.initializePricing();
|
|
235
|
-
|
|
350
|
+
|
|
236
351
|
if (sleepMs) {
|
|
237
352
|
await sleep(sleepMs);
|
|
238
353
|
}
|
|
@@ -350,13 +465,13 @@ export async function newTestE2E({
|
|
|
350
465
|
await ts.setup();
|
|
351
466
|
}
|
|
352
467
|
|
|
353
|
-
if (useTenderly &&
|
|
468
|
+
if (useTenderly && testContractBytecode) {
|
|
354
469
|
assert(
|
|
355
470
|
ts instanceof TenderlySimulation,
|
|
356
471
|
'`ts` is not an instance of TenderlySimulation',
|
|
357
472
|
);
|
|
358
473
|
const deployTx = await ts.simulate(
|
|
359
|
-
|
|
474
|
+
deployContractParams(testContractBytecode, network),
|
|
360
475
|
);
|
|
361
476
|
|
|
362
477
|
expect(deployTx.success).toEqual(true);
|
|
@@ -371,7 +486,7 @@ export async function newTestE2E({
|
|
|
371
486
|
);
|
|
372
487
|
|
|
373
488
|
const whitelistTx = await ts.simulate(
|
|
374
|
-
|
|
489
|
+
augustusGrantRoleParams(adapterAddress, network),
|
|
375
490
|
);
|
|
376
491
|
expect(whitelistTx.success).toEqual(true);
|
|
377
492
|
}
|
package/tests/utils.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { ethers } from 'ethers';
|
|
1
3
|
import { PoolPrices, PoolLiquidity, Address } from '../src/types';
|
|
2
4
|
import { SwapSide } from '../src/constants';
|
|
5
|
+
import { assert } from 'ts-essentials';
|
|
3
6
|
|
|
4
7
|
// Assuming that the amounts are increasing at same interval, and start with 0
|
|
5
8
|
export function checkPoolPrices(
|
|
@@ -73,3 +76,52 @@ export const sleep = (time: number) =>
|
|
|
73
76
|
new Promise(resolve => {
|
|
74
77
|
setTimeout(resolve, time);
|
|
75
78
|
});
|
|
79
|
+
|
|
80
|
+
export const generateDeployBytecode = (
|
|
81
|
+
testContractProjectRootPath: string | undefined,
|
|
82
|
+
testContractName: string | undefined,
|
|
83
|
+
testContractConfigFileName: string | undefined,
|
|
84
|
+
testContractRelativePath: string | undefined,
|
|
85
|
+
testContractDeployArgs: string | undefined,
|
|
86
|
+
testContractType: string | undefined,
|
|
87
|
+
): string => {
|
|
88
|
+
if (
|
|
89
|
+
!testContractProjectRootPath ||
|
|
90
|
+
!testContractName ||
|
|
91
|
+
!testContractConfigFileName ||
|
|
92
|
+
!testContractRelativePath ||
|
|
93
|
+
!testContractDeployArgs ||
|
|
94
|
+
!testContractType
|
|
95
|
+
) {
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const artifactJsonPath = `${testContractProjectRootPath}/artifacts/${testContractName}.json`;
|
|
100
|
+
const configJsonPath = `${testContractProjectRootPath}/config/${testContractConfigFileName}.json`;
|
|
101
|
+
const fieldsToPickFromConfig = testContractDeployArgs.split(',');
|
|
102
|
+
|
|
103
|
+
const artifact = require(artifactJsonPath) as {
|
|
104
|
+
abi: ethers.ContractInterface;
|
|
105
|
+
bytecode: string;
|
|
106
|
+
};
|
|
107
|
+
// I don't want to type this testing thing. If something is wrong, I will just throw
|
|
108
|
+
const config = require(configJsonPath) as any;
|
|
109
|
+
const factory = new ethers.ContractFactory(artifact.abi, artifact.bytecode);
|
|
110
|
+
|
|
111
|
+
const args = fieldsToPickFromConfig.map(f => {
|
|
112
|
+
const value = config[f];
|
|
113
|
+
if (value === undefined) {
|
|
114
|
+
console.log(
|
|
115
|
+
`Field ${f} is not defined in configJsonPath=${configJsonPath}. Using value as it is`,
|
|
116
|
+
);
|
|
117
|
+
return f;
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const deployedBytecode = factory.getDeployTransaction(...args).data;
|
|
123
|
+
|
|
124
|
+
assert(deployedBytecode !== undefined, 'deployedBytecode is undefined');
|
|
125
|
+
|
|
126
|
+
return deployedBytecode.toString();
|
|
127
|
+
};
|
package/.idea/aws.xml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="accountSettings">
|
|
4
|
-
<option name="activeProfile" value="profile:default" />
|
|
5
|
-
<option name="activeRegion" value="us-east-1" />
|
|
6
|
-
<option name="recentlyUsedProfiles">
|
|
7
|
-
<list>
|
|
8
|
-
<option value="profile:default" />
|
|
9
|
-
</list>
|
|
10
|
-
</option>
|
|
11
|
-
<option name="recentlyUsedRegions">
|
|
12
|
-
<list>
|
|
13
|
-
<option value="us-east-1" />
|
|
14
|
-
</list>
|
|
15
|
-
</option>
|
|
16
|
-
</component>
|
|
17
|
-
</project>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
-
<code_scheme name="Project" version="173">
|
|
3
|
-
<ScalaCodeStyleSettings>
|
|
4
|
-
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
|
5
|
-
</ScalaCodeStyleSettings>
|
|
6
|
-
<TypeScriptCodeStyleSettings version="0">
|
|
7
|
-
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACKETS" value="true" />
|
|
8
|
-
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
9
|
-
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
10
|
-
</TypeScriptCodeStyleSettings>
|
|
11
|
-
<codeStyleSettings language="TypeScript">
|
|
12
|
-
<indentOptions>
|
|
13
|
-
<option name="INDENT_SIZE" value="2" />
|
|
14
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
15
|
-
<option name="TAB_SIZE" value="2" />
|
|
16
|
-
</indentOptions>
|
|
17
|
-
</codeStyleSettings>
|
|
18
|
-
</code_scheme>
|
|
19
|
-
</component>
|
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/paraswap-dex-lib.iml" filepath="$PROJECT_DIR$/.idea/paraswap-dex-lib.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|
package/.idea/vcs.xml
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Address } from '../../types';
|
|
2
|
-
export declare type DexParams = {
|
|
3
|
-
router: Address;
|
|
4
|
-
quoter: Address;
|
|
5
|
-
factory: Address;
|
|
6
|
-
stateMulticall: Address;
|
|
7
|
-
uniswapMulticall: Address;
|
|
8
|
-
supportedFees: bigint[];
|
|
9
|
-
feeProtocols: bigint[];
|
|
10
|
-
chunksCount: number;
|
|
11
|
-
deployer?: Address;
|
|
12
|
-
subgraphURL: string;
|
|
13
|
-
initHash: string;
|
|
14
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Solidly } from '../solidly';
|
|
2
|
-
import { SolidlyPair } from '../types';
|
|
3
|
-
import { Network } from '../../../constants';
|
|
4
|
-
import { IDexHelper } from '../../../dex-helper';
|
|
5
|
-
export declare class Chronos extends Solidly {
|
|
6
|
-
protected network: Network;
|
|
7
|
-
protected dexHelper: IDexHelper;
|
|
8
|
-
static dexKeysWithNetwork: {
|
|
9
|
-
key: string;
|
|
10
|
-
networks: Network[];
|
|
11
|
-
}[];
|
|
12
|
-
constructor(network: Network, dexKey: string, dexHelper: IDexHelper);
|
|
13
|
-
protected getFeesMultiCallData(pair: SolidlyPair): {
|
|
14
|
-
callEntry: {
|
|
15
|
-
target: string;
|
|
16
|
-
callData: string;
|
|
17
|
-
};
|
|
18
|
-
callDecoder: (values: any[]) => number;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Chronos = void 0;
|
|
7
|
-
const solidly_1 = require("../solidly");
|
|
8
|
-
const abi_1 = require("@ethersproject/abi");
|
|
9
|
-
const utils_1 = require("../../../utils");
|
|
10
|
-
const config_1 = require("../config");
|
|
11
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
12
|
-
const ChronosFactoryABI = [
|
|
13
|
-
{
|
|
14
|
-
inputs: [{ internalType: 'bool', name: '_stable', type: 'bool' }],
|
|
15
|
-
name: 'getFee',
|
|
16
|
-
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
17
|
-
stateMutability: 'view',
|
|
18
|
-
type: 'function',
|
|
19
|
-
},
|
|
20
|
-
];
|
|
21
|
-
const chronosFactoryIface = new abi_1.Interface(ChronosFactoryABI);
|
|
22
|
-
class Chronos extends solidly_1.Solidly {
|
|
23
|
-
constructor(network, dexKey, dexHelper) {
|
|
24
|
-
super(network, dexKey, dexHelper, true);
|
|
25
|
-
this.network = network;
|
|
26
|
-
this.dexHelper = dexHelper;
|
|
27
|
-
}
|
|
28
|
-
getFeesMultiCallData(pair) {
|
|
29
|
-
const callEntry = {
|
|
30
|
-
target: this.factoryAddress,
|
|
31
|
-
callData: chronosFactoryIface.encodeFunctionData('getFee', [pair.stable]),
|
|
32
|
-
};
|
|
33
|
-
const callDecoder = (values) => parseInt(chronosFactoryIface
|
|
34
|
-
.decodeFunctionResult('getFee', values)[0]
|
|
35
|
-
.toString());
|
|
36
|
-
return {
|
|
37
|
-
callEntry,
|
|
38
|
-
callDecoder,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.Chronos = Chronos;
|
|
43
|
-
Chronos.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(lodash_1.default.pick(config_1.SolidlyConfig, ['Chronos']));
|
|
44
|
-
//# sourceMappingURL=chronos.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chronos.js","sourceRoot":"","sources":["../../../../src/dex/solidly/forks-override/chronos.ts"],"names":[],"mappings":";;;;;;AAAA,wCAAqC;AAIrC,4CAA+C;AAC/C,0CAAuD;AACvD,sCAA0C;AAC1C,oDAAuB;AAEvB,MAAM,iBAAiB,GAAG;IACxB;QACE,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACjE,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjE,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACF,CAAC;AAEF,MAAM,mBAAmB,GAAG,IAAI,eAAS,CAAC,iBAAiB,CAAC,CAAC;AAE7D,MAAa,OAAQ,SAAQ,iBAAO;IAIlC,YACY,OAAgB,EAC1B,MAAc,EACJ,SAAqB;QAE/B,KAAK,CACH,OAAO,EACP,MAAM,EACN,SAAS,EACT,IAAI,CACL,CAAC;QATQ,YAAO,GAAP,OAAO,CAAS;QAEhB,cAAS,GAAT,SAAS,CAAY;IAQjC,CAAC;IAES,oBAAoB,CAAC,IAAiB;QAC9C,MAAM,SAAS,GAAG;YAChB,MAAM,EAAE,IAAI,CAAC,cAAc;YAC3B,QAAQ,EAAE,mBAAmB,CAAC,kBAAkB,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC1E,CAAC;QACF,MAAM,WAAW,GAAG,CAAC,MAAa,EAAE,EAAE,CACpC,QAAQ,CACN,mBAAmB;aAChB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;aACzC,QAAQ,EAAE,CACd,CAAC;QAEJ,OAAO;YACL,SAAS;YACT,WAAW;SACZ,CAAC;IACJ,CAAC;;AAjCH,0BAkCC;AAjCe,0BAAkB,GAC9B,IAAA,6BAAqB,EAAC,gBAAC,CAAC,IAAI,CAAC,sBAAa,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC"}
|
|
File without changes
|