@paraswap/dex-lib 2.20.3 → 2.21.1-chronos
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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +19 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/paraswap-dex-lib.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/build/config.js +2 -4
- package/build/config.js.map +1 -1
- package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
- package/build/dex/aave-v3/tokens/avalanche.json +74 -0
- package/build/dex/aave-v3/tokens/fantom.json +62 -0
- package/build/dex/aave-v3/tokens/optimism.json +50 -0
- package/build/dex/aave-v3/tokens/polygon.json +116 -0
- package/build/dex/balancer-v2/balancer-v2.d.ts +3 -9
- package/build/dex/balancer-v2/balancer-v2.js +0 -83
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/constants.d.ts +0 -4
- package/build/dex/balancer-v2/constants.js +1 -6
- package/build/dex/balancer-v2/constants.js.map +1 -1
- package/build/dex/balancer-v2/types.d.ts +1 -20
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/curve-v1/constants.d.ts +0 -1
- package/build/dex/curve-v1/constants.js +1 -2
- package/build/dex/curve-v1/constants.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +3 -9
- package/build/dex/curve-v1/curve-v1.js +4 -92
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1/types.d.ts +0 -24
- package/build/dex/curve-v1/types.js +1 -6
- package/build/dex/curve-v1/types.js.map +1 -1
- package/build/dex/curve-v1-factory/constants.d.ts +0 -1
- package/build/dex/curve-v1-factory/constants.js +1 -2
- package/build/dex/curve-v1-factory/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +4 -11
- package/build/dex/curve-v1-factory/curve-v1-factory.js +0 -87
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +0 -24
- package/build/dex/curve-v1-factory/types.js +1 -6
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/curve-v2.d.ts +7 -29
- package/build/dex/curve-v2.js +1 -91
- package/build/dex/curve-v2.js.map +1 -1
- package/build/dex/idex.d.ts +1 -1
- package/build/dex/index.js +2 -2
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -2
- package/build/dex/pancakeswap-v3/types.d.ts +14 -0
- package/build/dex/pancakeswap-v3/types.js +3 -0
- package/build/dex/pancakeswap-v3/types.js.map +1 -0
- package/build/dex/pancakeswap-v3/utils.js.map +1 -1
- package/build/dex/quickswap/camelot-v3.d.ts +6 -0
- package/build/dex/quickswap/camelot-v3.js +19 -0
- package/build/dex/quickswap/camelot-v3.js.map +1 -0
- package/build/dex/simple-exchange.d.ts +0 -2
- package/build/dex/simple-exchange.js +0 -1
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/solidly/config.js +13 -0
- package/build/dex/solidly/config.js.map +1 -1
- package/build/dex/solidly/forks-override/chronos.d.ts +23 -0
- package/build/dex/solidly/forks-override/chronos.js +132 -0
- package/build/dex/solidly/forks-override/chronos.js.map +1 -0
- package/build/dex/solidly/solidly.js +1 -0
- package/build/dex/solidly/solidly.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 +0 -4
- package/build/dex/uniswap-v3/constants.js +1 -6
- package/build/dex/uniswap-v3/constants.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +3 -20
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +1 -7
- package/build/dex/uniswap-v3/uniswap-v3.js +1 -85
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/woo-fi-v2/config.js +6 -6
- 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 +1 -5
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/router/directswap.js +1 -7
- package/build/router/directswap.js.map +1 -1
- package/build/router/index.js.map +1 -1
- package/build/router/payload-encoder.js +6 -16
- package/build/router/payload-encoder.js.map +1 -1
- package/build/types.d.ts +0 -2
- package/build/utils.d.ts +0 -2
- package/build/utils.js +1 -5
- package/build/utils.js.map +1 -1
- package/package.json +4 -6
- package/src/config.ts +2 -5
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -79
- package/src/dex/balancer-v2/balancer-v2.ts +4 -153
- package/src/dex/balancer-v2/constants.ts +0 -5
- package/src/dex/balancer-v2/types.ts +1 -21
- package/src/dex/curve-v1/constants.ts +0 -2
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -57
- package/src/dex/curve-v1/curve-v1.ts +5 -144
- package/src/dex/curve-v1/types.ts +0 -26
- package/src/dex/curve-v1-factory/constants.ts +0 -2
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +0 -1
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +4 -140
- package/src/dex/curve-v1-factory/types.ts +0 -26
- package/src/dex/curve-v2.ts +8 -169
- package/src/dex/idex.ts +0 -6
- package/src/dex/index.ts +2 -2
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +6 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +14 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +3 -3
- package/src/dex/pancakeswap-v3/utils.ts +4 -1
- package/src/dex/simple-exchange.ts +0 -6
- package/src/dex/solidly/config.ts +14 -0
- package/src/dex/solidly/forks-override/chronos.ts +206 -0
- package/src/dex/solidly/solidly-e2e.test.ts +205 -31
- package/src/dex/solidly/solidly-integration.test.ts +141 -0
- package/src/dex/solidly/solidly.ts +1 -0
- package/src/dex/uniswap-v2/uniswap-v2.ts +0 -6
- package/src/dex/uniswap-v3/constants.ts +0 -5
- package/src/dex/uniswap-v3/types.ts +3 -23
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +2 -100
- package/src/dex/uniswap-v3/uniswap-v3.ts +3 -138
- package/src/dex/woo-fi-v2/config.ts +6 -6
- package/src/dex/zerox/index.ts +0 -7
- package/src/implementations/local-paraswap-sdk.ts +1 -8
- package/src/router/directswap.ts +0 -23
- package/src/router/index.ts +2 -0
- package/src/router/payload-encoder.ts +5 -22
- package/src/types.ts +0 -2
- package/src/utils.ts +0 -5
- package/tests/constants-e2e.ts +9 -4
- package/tests/utils-e2e.ts +20 -140
- package/tests/utils.ts +0 -52
- package/src/abi/DirectSwap.json +0 -1018
- package/src/abi/swaap-v2/vault.json +0 -918
- package/src/dex/swaap-v2/config.ts +0 -19
- package/src/dex/swaap-v2/constants.ts +0 -37
- package/src/dex/swaap-v2/rate-fetcher.ts +0 -214
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +0 -172
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +0 -142
- package/src/dex/swaap-v2/swaap-v2.ts +0 -901
- package/src/dex/swaap-v2/types.ts +0 -95
- package/src/dex/swaap-v2/utils.ts +0 -36
- package/src/dex/swaap-v2/validators.ts +0 -128
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { Interface, AbiCoder, JsonFragment } from '@ethersproject/abi';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import { NumberAsString, OptimalSwapExchange } from '@paraswap/core';
|
|
4
|
-
import { assert } from 'ts-essentials';
|
|
5
2
|
import BigNumber from 'bignumber.js';
|
|
6
3
|
import CurveABI from '../../abi/Curve.json';
|
|
7
|
-
import DirectSwapABI from '../../abi/DirectSwap.json';
|
|
8
4
|
import { Adapters, CurveV1Config } from './config';
|
|
9
5
|
|
|
10
6
|
import {
|
|
11
7
|
AdapterExchangeParam,
|
|
12
8
|
Address,
|
|
13
9
|
ExchangePrices,
|
|
14
|
-
ExchangeTxInfo,
|
|
15
10
|
PoolLiquidity,
|
|
16
11
|
PoolPrices,
|
|
17
|
-
PreprocessTransactionOptions,
|
|
18
12
|
SimpleExchangeParam,
|
|
19
13
|
Token,
|
|
20
14
|
TransferFeeParams,
|
|
21
|
-
TxInfo,
|
|
22
15
|
} from '../../types';
|
|
23
16
|
import {
|
|
24
17
|
Network,
|
|
@@ -55,6 +48,8 @@ import { TBTCPool, address as TBTCPoolAddress } from './pools/tBTCpool';
|
|
|
55
48
|
import { USDKPool, address as USDKPoolAddress } from './pools/usdkpool';
|
|
56
49
|
import { USTPool, address as USTPoolAddress } from './pools/ustpool';
|
|
57
50
|
import { SLINKPool, address as SLINKPoolAddress } from './pools/sLinkpool';
|
|
51
|
+
|
|
52
|
+
import * as _ from 'lodash';
|
|
58
53
|
import {
|
|
59
54
|
getBigIntPow,
|
|
60
55
|
getDexKeysWithNetwork,
|
|
@@ -62,13 +57,9 @@ import {
|
|
|
62
57
|
isDestTokenTransferFeeToBeExchanged,
|
|
63
58
|
isSrcTokenTransferFeeToBeExchanged,
|
|
64
59
|
Utils,
|
|
65
|
-
uuidToBytes16,
|
|
66
60
|
} from '../../utils';
|
|
67
61
|
import { BN_0 } from '../../bignumber-constants';
|
|
68
|
-
import {
|
|
69
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
70
|
-
SimpleExchange,
|
|
71
|
-
} from '../simple-exchange';
|
|
62
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
72
63
|
import { IDex } from '../idex';
|
|
73
64
|
import { IDexHelper } from '../../dex-helper';
|
|
74
65
|
import { Logger } from 'log4js';
|
|
@@ -80,12 +71,9 @@ import {
|
|
|
80
71
|
CurveV1Data,
|
|
81
72
|
TokenWithReasonableVolume,
|
|
82
73
|
CurveSwapFunctions,
|
|
83
|
-
CurveV1SwapType,
|
|
84
|
-
DirectCurveV1Param,
|
|
85
74
|
} from './types';
|
|
86
75
|
import { erc20Iface } from '../../lib/utils-interfaces';
|
|
87
76
|
import { applyTransferFee } from '../../lib/token-transfer-fee';
|
|
88
|
-
import { DIRECT_METHOD_NAME } from './constants';
|
|
89
77
|
|
|
90
78
|
const CURVE_DEFAULT_CHUNKS = 10;
|
|
91
79
|
|
|
@@ -94,10 +82,7 @@ const CURVE_POOL_GAS = 200 * 1000;
|
|
|
94
82
|
|
|
95
83
|
const coder = new AbiCoder();
|
|
96
84
|
|
|
97
|
-
export class CurveV1
|
|
98
|
-
extends SimpleExchange
|
|
99
|
-
implements IDex<CurveV1Data, DirectCurveV1Param>
|
|
100
|
-
{
|
|
85
|
+
export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
101
86
|
exchangeRouterInterface: Interface;
|
|
102
87
|
minConversionRate = '1';
|
|
103
88
|
|
|
@@ -117,8 +102,6 @@ export class CurveV1
|
|
|
117
102
|
|
|
118
103
|
protected disableFeeOnTransferTokenAddresses: Set<string>;
|
|
119
104
|
|
|
120
|
-
readonly directSwapIface = new Interface(DirectSwapABI);
|
|
121
|
-
|
|
122
105
|
readonly SRC_TOKEN_DEX_TRANSFERS = 1;
|
|
123
106
|
readonly DEST_TOKEN_DEX_TRANSFERS = 1;
|
|
124
107
|
|
|
@@ -857,128 +840,6 @@ export class CurveV1
|
|
|
857
840
|
return this.adapters[side];
|
|
858
841
|
}
|
|
859
842
|
|
|
860
|
-
static getDirectFunctionName(): string[] {
|
|
861
|
-
return [DIRECT_METHOD_NAME];
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
getTokenFromAddress(address: Address): Token {
|
|
865
|
-
// In this Dex decimals are not used
|
|
866
|
-
return { address, decimals: 0 };
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
async preProcessTransaction(
|
|
870
|
-
optimalSwapExchange: OptimalSwapExchange<CurveV1Data>,
|
|
871
|
-
srcToken: Token,
|
|
872
|
-
_0: Token,
|
|
873
|
-
_1: SwapSide,
|
|
874
|
-
options: PreprocessTransactionOptions,
|
|
875
|
-
): Promise<[OptimalSwapExchange<CurveV1Data>, ExchangeTxInfo]> {
|
|
876
|
-
if (!options.isDirectMethod) {
|
|
877
|
-
return [
|
|
878
|
-
optimalSwapExchange,
|
|
879
|
-
{
|
|
880
|
-
deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
|
|
881
|
-
},
|
|
882
|
-
];
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
assert(
|
|
886
|
-
optimalSwapExchange.data !== undefined,
|
|
887
|
-
`preProcessTransaction: data field is missing`,
|
|
888
|
-
);
|
|
889
|
-
|
|
890
|
-
let isApproved: boolean | undefined;
|
|
891
|
-
|
|
892
|
-
try {
|
|
893
|
-
this.erc20Contract.options.address =
|
|
894
|
-
this.dexHelper.config.wrapETH(srcToken).address;
|
|
895
|
-
const allowance = await this.erc20Contract.methods
|
|
896
|
-
.allowance(this.augustusAddress, optimalSwapExchange.data.exchange)
|
|
897
|
-
.call(undefined, 'latest');
|
|
898
|
-
isApproved =
|
|
899
|
-
BigInt(allowance.toString()) >= BigInt(optimalSwapExchange.srcAmount);
|
|
900
|
-
} catch (e) {
|
|
901
|
-
this.logger.error(
|
|
902
|
-
`preProcessTransaction failed to retrieve allowance info: `,
|
|
903
|
-
e,
|
|
904
|
-
);
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
return [
|
|
908
|
-
{
|
|
909
|
-
...optimalSwapExchange,
|
|
910
|
-
data: {
|
|
911
|
-
...optimalSwapExchange.data,
|
|
912
|
-
isApproved,
|
|
913
|
-
},
|
|
914
|
-
},
|
|
915
|
-
{
|
|
916
|
-
deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
|
|
917
|
-
},
|
|
918
|
-
];
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
getDirectParam(
|
|
922
|
-
srcToken: Address,
|
|
923
|
-
destToken: Address,
|
|
924
|
-
srcAmount: NumberAsString,
|
|
925
|
-
destAmount: NumberAsString,
|
|
926
|
-
expectedAmount: NumberAsString,
|
|
927
|
-
data: CurveV1Data,
|
|
928
|
-
side: SwapSide,
|
|
929
|
-
permit: string,
|
|
930
|
-
uuid: string,
|
|
931
|
-
feePercent: NumberAsString,
|
|
932
|
-
deadline: NumberAsString,
|
|
933
|
-
partner: string,
|
|
934
|
-
beneficiary: string,
|
|
935
|
-
contractMethod?: string,
|
|
936
|
-
): TxInfo<DirectCurveV1Param> {
|
|
937
|
-
if (contractMethod !== DIRECT_METHOD_NAME) {
|
|
938
|
-
throw new Error(`Invalid contract method ${contractMethod}`);
|
|
939
|
-
}
|
|
940
|
-
assert(side === SwapSide.SELL, 'Buy not supported');
|
|
941
|
-
|
|
942
|
-
let isApproved: boolean = !!data.isApproved;
|
|
943
|
-
if (data.isApproved === undefined) {
|
|
944
|
-
this.logger.warn(`isApproved is undefined, defaulting to false`);
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
const swapParams: DirectCurveV1Param = [
|
|
948
|
-
srcToken,
|
|
949
|
-
destToken,
|
|
950
|
-
data.exchange,
|
|
951
|
-
srcAmount,
|
|
952
|
-
destAmount,
|
|
953
|
-
expectedAmount,
|
|
954
|
-
feePercent,
|
|
955
|
-
data.i.toString(),
|
|
956
|
-
data.j.toString(),
|
|
957
|
-
partner,
|
|
958
|
-
isApproved,
|
|
959
|
-
data.underlyingSwap
|
|
960
|
-
? CurveV1SwapType.EXCHANGE_UNDERLYING
|
|
961
|
-
: CurveV1SwapType.EXCHANGE,
|
|
962
|
-
beneficiary,
|
|
963
|
-
// For CurveV1 we work as it is, without wrapping and unwrapping
|
|
964
|
-
false,
|
|
965
|
-
permit,
|
|
966
|
-
uuidToBytes16(uuid),
|
|
967
|
-
];
|
|
968
|
-
|
|
969
|
-
const encoder = (...params: DirectCurveV1Param) => {
|
|
970
|
-
return this.directSwapIface.encodeFunctionData(DIRECT_METHOD_NAME, [
|
|
971
|
-
params,
|
|
972
|
-
]);
|
|
973
|
-
};
|
|
974
|
-
|
|
975
|
-
return {
|
|
976
|
-
params: swapParams,
|
|
977
|
-
encoder,
|
|
978
|
-
networkFee: '0',
|
|
979
|
-
};
|
|
980
|
-
}
|
|
981
|
-
|
|
982
843
|
async getSimpleParam(
|
|
983
844
|
srcToken: string,
|
|
984
845
|
destToken: string,
|
|
@@ -1082,7 +943,7 @@ export class CurveV1
|
|
|
1082
943
|
// the balances array in the pool as it was a mess to have each curve abi
|
|
1083
944
|
// Some have balances[uint128] some have balances[uint256]
|
|
1084
945
|
// One of the consequence for such a hack is below for ETH Pools
|
|
1085
|
-
// TODO: below can be highly
|
|
946
|
+
// TODO: below can be highly optimised
|
|
1086
947
|
// * we don't need to query token decimals every iteration
|
|
1087
948
|
// * we can use the decimals from the tokens list using the api
|
|
1088
949
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { NumberAsString } from '@paraswap/core';
|
|
2
1
|
import { Address, Token } from '../../types';
|
|
3
2
|
|
|
4
3
|
export type CurveV1Data = {
|
|
@@ -7,7 +6,6 @@ export type CurveV1Data = {
|
|
|
7
6
|
j: number;
|
|
8
7
|
underlyingSwap: boolean;
|
|
9
8
|
deadline: number;
|
|
10
|
-
isApproved?: boolean;
|
|
11
9
|
};
|
|
12
10
|
|
|
13
11
|
export type PoolConfig = {
|
|
@@ -44,27 +42,3 @@ export enum CurveSwapFunctions {
|
|
|
44
42
|
exchange = 'exchange',
|
|
45
43
|
exchange_underlying = 'exchange_underlying',
|
|
46
44
|
}
|
|
47
|
-
|
|
48
|
-
export enum CurveV1SwapType {
|
|
49
|
-
EXCHANGE,
|
|
50
|
-
EXCHANGE_UNDERLYING,
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type DirectCurveV1Param = [
|
|
54
|
-
fromToken: Address,
|
|
55
|
-
toToken: Address,
|
|
56
|
-
exchange: Address,
|
|
57
|
-
fromAmount: NumberAsString,
|
|
58
|
-
toAmount: NumberAsString,
|
|
59
|
-
expectedAmount: NumberAsString,
|
|
60
|
-
feePercent: NumberAsString,
|
|
61
|
-
i: NumberAsString,
|
|
62
|
-
j: NumberAsString,
|
|
63
|
-
partner: Address,
|
|
64
|
-
isApproved: boolean,
|
|
65
|
-
swapType: CurveV1SwapType,
|
|
66
|
-
beneficiary: Address,
|
|
67
|
-
needWrapNative: boolean,
|
|
68
|
-
permit: string,
|
|
69
|
-
uuid: string,
|
|
70
|
-
];
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import {
|
|
3
|
-
import { NumberAsString, OptimalSwapExchange } from '@paraswap/core';
|
|
4
|
-
import { assert, AsyncOrSync } from 'ts-essentials';
|
|
2
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
5
3
|
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
6
4
|
import {
|
|
7
5
|
Token,
|
|
@@ -13,9 +11,6 @@ import {
|
|
|
13
11
|
PoolLiquidity,
|
|
14
12
|
Logger,
|
|
15
13
|
TransferFeeParams,
|
|
16
|
-
TxInfo,
|
|
17
|
-
PreprocessTransactionOptions,
|
|
18
|
-
ExchangeTxInfo,
|
|
19
14
|
} from '../../types';
|
|
20
15
|
import {
|
|
21
16
|
SwapSide,
|
|
@@ -28,7 +23,6 @@ import {
|
|
|
28
23
|
getBigIntPow,
|
|
29
24
|
getDexKeysWithNetwork,
|
|
30
25
|
isSrcTokenTransferFeeToBeExchanged,
|
|
31
|
-
uuidToBytes16,
|
|
32
26
|
} from '../../utils';
|
|
33
27
|
import { IDex } from '../idex';
|
|
34
28
|
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
@@ -36,19 +30,13 @@ import {
|
|
|
36
30
|
CurveSwapFunctions,
|
|
37
31
|
CurveV1FactoryData,
|
|
38
32
|
CurveV1FactoryIfaces,
|
|
39
|
-
CurveV1SwapType,
|
|
40
33
|
CustomImplementationNames,
|
|
41
34
|
ImplementationNames,
|
|
42
35
|
PoolConstants,
|
|
43
|
-
DirectCurveV1Param,
|
|
44
36
|
} from './types';
|
|
45
|
-
import {
|
|
46
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
47
|
-
SimpleExchange,
|
|
48
|
-
} from '../simple-exchange';
|
|
37
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
49
38
|
import { CurveV1FactoryConfig, Adapters } from './config';
|
|
50
39
|
import {
|
|
51
|
-
DIRECT_METHOD_NAME,
|
|
52
40
|
FACTORY_MAX_PLAIN_COINS,
|
|
53
41
|
FACTORY_MAX_PLAIN_IMPLEMENTATIONS_FOR_COIN,
|
|
54
42
|
MIN_AMOUNT_TO_RECEIVE,
|
|
@@ -56,7 +44,6 @@ import {
|
|
|
56
44
|
} from './constants';
|
|
57
45
|
import { CurveV1FactoryPoolManager } from './curve-v1-pool-manager';
|
|
58
46
|
import CurveABI from '../../abi/Curve.json';
|
|
59
|
-
import DirectSwapABI from '../../abi/DirectSwap.json';
|
|
60
47
|
import FactoryCurveV1ABI from '../../abi/curve-v1-factory/FactoryCurveV1.json';
|
|
61
48
|
import ThreePoolABI from '../../abi/curve-v1-factory/ThreePool.json';
|
|
62
49
|
import ERC20ABI from '../../abi/erc20.json';
|
|
@@ -74,6 +61,7 @@ import { CustomBasePoolForFactory } from './state-polling-pools/custom-pool-poll
|
|
|
74
61
|
import ImplementationConstants from './price-handlers/functions/constants';
|
|
75
62
|
import { applyTransferFee } from '../../lib/token-transfer-fee';
|
|
76
63
|
import { PriceHandler } from './price-handlers/price-handler';
|
|
64
|
+
import { AbiItem } from 'web3-utils';
|
|
77
65
|
|
|
78
66
|
const DefaultCoinsABI: AbiItem = {
|
|
79
67
|
type: 'function',
|
|
@@ -94,7 +82,7 @@ const DefaultCoinsABI: AbiItem = {
|
|
|
94
82
|
|
|
95
83
|
export class CurveV1Factory
|
|
96
84
|
extends SimpleExchange
|
|
97
|
-
implements IDex<CurveV1FactoryData
|
|
85
|
+
implements IDex<CurveV1FactoryData>
|
|
98
86
|
{
|
|
99
87
|
readonly hasConstantPriceLargeAmounts = false;
|
|
100
88
|
readonly needWrapNative = false;
|
|
@@ -110,8 +98,6 @@ export class CurveV1Factory
|
|
|
110
98
|
readonly SRC_TOKEN_DEX_TRANSFERS = 1;
|
|
111
99
|
readonly DEST_TOKEN_DEX_TRANSFERS = 1;
|
|
112
100
|
|
|
113
|
-
readonly directSwapIface = new Interface(DirectSwapABI);
|
|
114
|
-
|
|
115
101
|
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
116
102
|
getDexKeysWithNetwork(CurveV1FactoryConfig);
|
|
117
103
|
|
|
@@ -828,128 +814,6 @@ export class CurveV1Factory
|
|
|
828
814
|
};
|
|
829
815
|
}
|
|
830
816
|
|
|
831
|
-
getTokenFromAddress(address: Address): Token {
|
|
832
|
-
// In this Dex decimals are not used
|
|
833
|
-
return { address, decimals: 0 };
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
async preProcessTransaction(
|
|
837
|
-
optimalSwapExchange: OptimalSwapExchange<CurveV1FactoryData>,
|
|
838
|
-
srcToken: Token,
|
|
839
|
-
_0: Token,
|
|
840
|
-
_1: SwapSide,
|
|
841
|
-
options: PreprocessTransactionOptions,
|
|
842
|
-
): Promise<[OptimalSwapExchange<CurveV1FactoryData>, ExchangeTxInfo]> {
|
|
843
|
-
if (!options.isDirectMethod) {
|
|
844
|
-
return [
|
|
845
|
-
optimalSwapExchange,
|
|
846
|
-
{
|
|
847
|
-
deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
|
|
848
|
-
},
|
|
849
|
-
];
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
assert(
|
|
853
|
-
optimalSwapExchange.data !== undefined,
|
|
854
|
-
`preProcessTransaction: data field is missing`,
|
|
855
|
-
);
|
|
856
|
-
|
|
857
|
-
let isApproved: boolean | undefined;
|
|
858
|
-
|
|
859
|
-
try {
|
|
860
|
-
this.erc20Contract.options.address =
|
|
861
|
-
this.dexHelper.config.wrapETH(srcToken).address;
|
|
862
|
-
const allowance = await this.erc20Contract.methods
|
|
863
|
-
.allowance(this.augustusAddress, optimalSwapExchange.data.exchange)
|
|
864
|
-
.call(undefined, 'latest');
|
|
865
|
-
isApproved =
|
|
866
|
-
BigInt(allowance.toString()) >= BigInt(optimalSwapExchange.srcAmount);
|
|
867
|
-
} catch (e) {
|
|
868
|
-
this.logger.error(
|
|
869
|
-
`preProcessTransaction failed to retrieve allowance info: `,
|
|
870
|
-
e,
|
|
871
|
-
);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
return [
|
|
875
|
-
{
|
|
876
|
-
...optimalSwapExchange,
|
|
877
|
-
data: {
|
|
878
|
-
...optimalSwapExchange.data,
|
|
879
|
-
isApproved,
|
|
880
|
-
},
|
|
881
|
-
},
|
|
882
|
-
{
|
|
883
|
-
deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
|
|
884
|
-
},
|
|
885
|
-
];
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
getDirectParam(
|
|
889
|
-
srcToken: Address,
|
|
890
|
-
destToken: Address,
|
|
891
|
-
srcAmount: NumberAsString,
|
|
892
|
-
destAmount: NumberAsString,
|
|
893
|
-
expectedAmount: NumberAsString,
|
|
894
|
-
data: CurveV1FactoryData,
|
|
895
|
-
side: SwapSide,
|
|
896
|
-
permit: string,
|
|
897
|
-
uuid: string,
|
|
898
|
-
feePercent: NumberAsString,
|
|
899
|
-
deadline: NumberAsString,
|
|
900
|
-
partner: string,
|
|
901
|
-
beneficiary: string,
|
|
902
|
-
contractMethod?: string,
|
|
903
|
-
): TxInfo<DirectCurveV1Param> {
|
|
904
|
-
if (contractMethod !== DIRECT_METHOD_NAME) {
|
|
905
|
-
throw new Error(`Invalid contract method ${contractMethod}`);
|
|
906
|
-
}
|
|
907
|
-
assert(side === SwapSide.SELL, 'Buy not supported');
|
|
908
|
-
|
|
909
|
-
let isApproved: boolean = !!data.isApproved;
|
|
910
|
-
if (data.isApproved === undefined) {
|
|
911
|
-
this.logger.warn(`isApproved is undefined, defaulting to false`);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
const swapParams: DirectCurveV1Param = [
|
|
915
|
-
srcToken,
|
|
916
|
-
destToken,
|
|
917
|
-
data.exchange,
|
|
918
|
-
srcAmount,
|
|
919
|
-
destAmount,
|
|
920
|
-
expectedAmount,
|
|
921
|
-
feePercent,
|
|
922
|
-
data.i.toString(),
|
|
923
|
-
data.j.toString(),
|
|
924
|
-
partner,
|
|
925
|
-
isApproved,
|
|
926
|
-
data.underlyingSwap
|
|
927
|
-
? CurveV1SwapType.EXCHANGE_UNDERLYING
|
|
928
|
-
: CurveV1SwapType.EXCHANGE,
|
|
929
|
-
beneficiary,
|
|
930
|
-
// For CurveV1 we work as it is, without wrapping and unwrapping
|
|
931
|
-
false,
|
|
932
|
-
permit,
|
|
933
|
-
uuidToBytes16(uuid),
|
|
934
|
-
];
|
|
935
|
-
|
|
936
|
-
const encoder = (...params: DirectCurveV1Param) => {
|
|
937
|
-
return this.directSwapIface.encodeFunctionData(DIRECT_METHOD_NAME, [
|
|
938
|
-
params,
|
|
939
|
-
]);
|
|
940
|
-
};
|
|
941
|
-
|
|
942
|
-
return {
|
|
943
|
-
params: swapParams,
|
|
944
|
-
encoder,
|
|
945
|
-
networkFee: '0',
|
|
946
|
-
};
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
static getDirectFunctionName(): string[] {
|
|
950
|
-
return [DIRECT_METHOD_NAME];
|
|
951
|
-
}
|
|
952
|
-
|
|
953
817
|
async getSimpleParam(
|
|
954
818
|
srcToken: string,
|
|
955
819
|
destToken: string,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import { NumberAsString } from '@paraswap/core';
|
|
3
2
|
import { Address } from '../../types';
|
|
4
3
|
|
|
5
4
|
// The difference between PoolContextConstants and PoolConstants lies in the fact
|
|
@@ -70,7 +69,6 @@ export type CurveV1FactoryData = {
|
|
|
70
69
|
i: number;
|
|
71
70
|
j: number;
|
|
72
71
|
underlyingSwap: boolean;
|
|
73
|
-
isApproved?: boolean;
|
|
74
72
|
};
|
|
75
73
|
|
|
76
74
|
export enum FactoryImplementationNames {
|
|
@@ -183,27 +181,3 @@ export type CurveV1FactoryIfaces = {
|
|
|
183
181
|
};
|
|
184
182
|
|
|
185
183
|
export type LiquidityInCache = Record<string, number>;
|
|
186
|
-
|
|
187
|
-
export enum CurveV1SwapType {
|
|
188
|
-
EXCHANGE,
|
|
189
|
-
EXCHANGE_UNDERLYING,
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export type DirectCurveV1Param = [
|
|
193
|
-
fromToken: Address,
|
|
194
|
-
toToken: Address,
|
|
195
|
-
exchange: Address,
|
|
196
|
-
fromAmount: NumberAsString,
|
|
197
|
-
toAmount: NumberAsString,
|
|
198
|
-
expectedAmount: NumberAsString,
|
|
199
|
-
feePercent: NumberAsString,
|
|
200
|
-
i: NumberAsString,
|
|
201
|
-
j: NumberAsString,
|
|
202
|
-
partner: Address,
|
|
203
|
-
isApproved: boolean,
|
|
204
|
-
swapType: CurveV1SwapType,
|
|
205
|
-
beneficiary: Address,
|
|
206
|
-
needWrapNative: boolean,
|
|
207
|
-
permit: string,
|
|
208
|
-
uuid: string,
|
|
209
|
-
];
|