@paraswap/dex-lib 3.8.1 → 3.8.3-integral-dex
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/.vscode/launch.json +9 -49
- package/.vscode/settings.json +2 -1
- package/build/abi/Uncompressor.json +250 -0
- package/build/abi/integral/factory.json +333 -0
- package/build/abi/integral/oracle.json +501 -0
- package/build/abi/integral/pool.json +1041 -0
- package/build/abi/{wombat/pool.json → integral/relayer.json} +720 -473
- package/build/abi/oswap/oswap.abi.json +452 -0
- package/build/config.js +1 -1
- package/build/dex/aave-v1/aave-v1.d.ts +1 -2
- package/build/dex/aave-v1/aave-v1.js +0 -23
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/compound.js +1 -1
- package/build/dex/compound.js.map +1 -1
- package/build/dex/curve-v1-factory/config.js +10 -47
- package/build/dex/curve-v1-factory/config.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +2 -2
- package/build/dex/curve-v1-factory/curve-v1-factory.js +36 -96
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js +1 -13
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +2 -2
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +3 -4
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js +9 -24
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +4 -20
- package/build/dex/curve-v1-factory/types.js +3 -11
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/curve-v1-stable-ng/config.js +0 -18
- package/build/dex/curve-v1-stable-ng/config.js.map +1 -1
- package/build/dex/etherfi/etherfi.d.ts +26 -0
- package/build/dex/etherfi/etherfi.js +96 -0
- package/build/dex/etherfi/etherfi.js.map +1 -0
- package/build/dex/index.js +21 -3
- package/build/dex/index.js.map +1 -1
- package/build/dex/integral/config.d.ts +4 -0
- package/build/dex/integral/config.js +20 -0
- package/build/dex/integral/config.js.map +1 -0
- package/build/dex/integral/context.d.ts +40 -0
- package/build/dex/integral/context.js +158 -0
- package/build/dex/integral/context.js.map +1 -0
- package/build/dex/integral/helpers.d.ts +17 -0
- package/build/dex/integral/helpers.js +157 -0
- package/build/dex/integral/helpers.js.map +1 -0
- package/build/dex/integral/integral-factory.d.ts +21 -0
- package/build/dex/integral/integral-factory.js +92 -0
- package/build/dex/integral/integral-factory.js.map +1 -0
- package/build/dex/integral/integral-pool.d.ts +46 -0
- package/build/dex/integral/integral-pool.js +143 -0
- package/build/dex/integral/integral-pool.js.map +1 -0
- package/build/dex/integral/integral-pricing.d.ts +18 -0
- package/build/dex/integral/integral-pricing.js +114 -0
- package/build/dex/integral/integral-pricing.js.map +1 -0
- package/build/dex/integral/integral-relayer.d.ts +39 -0
- package/build/dex/integral/integral-relayer.js +189 -0
- package/build/dex/integral/integral-relayer.js.map +1 -0
- package/build/dex/integral/integral-token.d.ts +24 -0
- package/build/dex/integral/integral-token.js +56 -0
- package/build/dex/integral/integral-token.js.map +1 -0
- package/build/dex/integral/integral.d.ts +41 -0
- package/build/dex/integral/integral.js +377 -0
- package/build/dex/integral/integral.js.map +1 -0
- package/build/dex/integral/types.d.ts +84 -0
- package/build/dex/integral/types.js +9 -0
- package/build/dex/integral/types.js.map +1 -0
- package/build/dex/integral/utils-e2e.d.ts +9 -0
- package/build/dex/integral/utils-e2e.js +131 -0
- package/build/dex/integral/utils-e2e.js.map +1 -0
- package/build/dex/integral/utils.d.ts +17 -0
- package/build/dex/integral/utils.js +94 -0
- package/build/dex/integral/utils.js.map +1 -0
- package/build/dex/oswap/config.d.ts +5 -0
- package/build/dex/oswap/config.js +31 -0
- package/build/dex/oswap/config.js.map +1 -0
- package/build/dex/oswap/oswap-pool.d.ts +51 -0
- package/build/dex/oswap/oswap-pool.js +150 -0
- package/build/dex/oswap/oswap-pool.js.map +1 -0
- package/build/dex/oswap/oswap.d.ts +46 -0
- package/build/dex/oswap/oswap.js +266 -0
- package/build/dex/oswap/oswap.js.map +1 -0
- package/build/dex/oswap/types.d.ts +20 -0
- package/build/dex/oswap/types.js +3 -0
- package/build/dex/oswap/types.js.map +1 -0
- package/build/dex/platypus/platypus.d.ts +1 -2
- package/build/dex/platypus/platypus.js +0 -45
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/sdai/config.d.ts +11 -0
- package/build/dex/sdai/config.js +21 -0
- package/build/dex/sdai/config.js.map +1 -0
- package/build/dex/sdai/constants.d.ts +2 -0
- package/build/dex/sdai/constants.js +6 -0
- package/build/dex/sdai/constants.js.map +1 -0
- package/build/dex/sdai/scripts/validate-state.js +102 -0
- package/build/dex/sdai/scripts/validate-state.js.map +1 -0
- package/build/dex/sdai/sdai-pool.d.ts +16 -0
- package/build/dex/sdai/sdai-pool.js +85 -0
- package/build/dex/sdai/sdai-pool.js.map +1 -0
- package/build/dex/sdai/sdai.d.ts +51 -0
- package/build/dex/sdai/sdai.js +172 -0
- package/build/dex/sdai/sdai.js.map +1 -0
- package/build/dex/sdai/types.d.ts +21 -0
- package/build/dex/sdai/types.js +11 -0
- package/build/dex/sdai/types.js.map +1 -0
- package/build/dex/sdai/utils.d.ts +4 -0
- package/build/dex/sdai/utils.js +39 -0
- package/build/dex/sdai/utils.js.map +1 -0
- package/build/dex/stable-pool.js +8 -1
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
- package/build/dex/swaap-v1/swaap-v1.js +0 -14
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/uniswap-v3/contract-math/Oracle.js +4 -4
- package/build/dex/uniswap-v3/contract-math/Oracle.js.map +1 -1
- package/build/executor/compressor/Compressor.d.ts +23 -0
- package/build/executor/compressor/Compressor.js +144 -0
- package/build/executor/compressor/Compressor.js.map +1 -0
- package/build/executor/compressor/compress.d.ts +17 -0
- package/build/executor/compressor/compress.js +187 -0
- package/build/executor/compressor/compress.js.map +1 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
- package/build/executor/compressor/fetchSaved.js +17 -0
- package/build/executor/compressor/fetchSaved.js.map +1 -0
- package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
- package/build/executor/compressor/utils/computeCostL2.js +14 -0
- package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
- package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
- package/build/executor/compressor/utils/getAllIndexes.js +12 -0
- package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
- package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
- package/build/executor/compressor/utils/getByteForAddress.js +14 -0
- package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
- package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
- package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
- package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
- package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
- package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
- package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
- package/build/executor/compressor/utils/intToByte.d.ts +2 -0
- package/build/executor/compressor/utils/intToByte.js +10 -0
- package/build/executor/compressor/utils/intToByte.js.map +1 -0
- package/build/generic-swap-transaction-builder.js +3 -1
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/build/router/simpleswap.js +3 -1
- package/build/router/simpleswap.js.map +1 -1
- package/package.json +2 -2
- package/src/abi/BProtocol.json +1155 -0
- package/src/abi/Jarvis.json +1172 -0
- package/src/abi/MStableAsset.json +1545 -0
- package/src/abi/OneInchLp.json +1304 -0
- package/src/abi/Onebit.json +736 -0
- package/src/abi/Shell.json +1294 -0
- package/src/abi/TraderJoeV2Router.json +50 -0
- package/src/abi/integral/factory.json +333 -0
- package/src/abi/integral/oracle.json +501 -0
- package/src/abi/integral/pool.json +1041 -0
- package/src/abi/integral/relayer.json +1536 -0
- package/src/abi/zrx.v2.json +1967 -0
- package/src/abi/zrx.v3.json +3454 -0
- package/src/abi/zrx.v4.json +2193 -0
- package/src/config.ts +1 -1
- package/src/dex/OneInchLp.ts +84 -0
- package/src/dex/bProtocol/bProtocol-e2e.test.ts +93 -0
- package/src/dex/bProtocol/bProtocol.ts +108 -0
- package/src/dex/bProtocol/types.ts +13 -0
- package/src/dex/curve-v1-factory/config.ts +10 -47
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +16 -92
- package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +5 -125
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +45 -137
- package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dx.ts +1 -24
- package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +2 -3
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +0 -1
- package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +10 -31
- package/src/dex/curve-v1-factory/types.ts +6 -22
- package/src/dex/curve-v1-stable-ng/config.ts +0 -18
- package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng-e2e.test.ts +0 -17
- package/src/dex/index.ts +20 -3
- package/src/dex/integral/config.ts +20 -0
- package/src/dex/integral/context.ts +287 -0
- package/src/dex/integral/integral-e2e.test.ts +86 -0
- package/src/dex/integral/integral-events.test.ts +412 -0
- package/src/dex/integral/integral-factory.ts +146 -0
- package/src/dex/integral/integral-integration.test.ts +221 -0
- package/src/dex/integral/integral-pool.ts +198 -0
- package/src/dex/integral/integral-pricing.ts +190 -0
- package/src/dex/integral/integral-relayer.ts +285 -0
- package/src/dex/integral/integral-token.ts +95 -0
- package/src/dex/integral/integral.ts +523 -0
- package/src/dex/integral/test-artifacts/configs.json +1 -0
- package/src/dex/integral/test-artifacts/logs.json +1 -0
- package/src/dex/integral/test-artifacts/states.json +1 -0
- package/src/dex/integral/types.ts +88 -0
- package/src/dex/integral/utils-e2e.ts +194 -0
- package/src/dex/integral/utils.ts +146 -0
- package/src/dex/jarvis.ts +262 -0
- package/src/dex/mStable.ts +147 -0
- package/src/dex/onebit/onebit.ts +113 -0
- package/src/dex/onebit/types.ts +17 -0
- package/src/dex/shell.ts +84 -0
- package/src/dex/trader-joe-v2.ts +148 -0
- package/src/dex/uniswap-v3/contract-math/Oracle.ts +5 -4
- package/src/dex/zerox/config.ts +31 -0
- package/src/dex/zerox/index.ts +328 -0
- package/src/dex/zerox/order.ts +62 -0
- package/src/dex/zerox/types.ts +82 -0
- package/src/dex/zerox/zerox-e2e.test.ts +110 -0
- package/src/generic-swap-transaction-builder.ts +3 -1
- package/src/router/simpleswap.ts +3 -1
- package/tests/constants-e2e.ts +1 -1
- package/tests/utils-e2e.ts +0 -2
- package/.vscode/tasks.json +0 -15
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
- package/build/dex/aave-v2/tokens-avalanche.json +0 -44
- package/build/dex/aave-v2/tokens-mainnet.json +0 -188
- package/build/dex/aave-v2/tokens-polygon.json +0 -44
- package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
- package/build/dex/maker-psm/scripts/validate-state.js +0 -185
- package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
- package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
- package/src/abi/curve-v1-factory/CurveV1Router.abi.json +0 -331
- package/src/dex/curve-v1-factory/optimizer.ts +0 -61
- /package/build/dex/{solidly-v3/scripts/check-event-pool-event.d.ts → sdai/scripts/validate-state.d.ts} +0 -0
- /package/build/{dex/maker-psm/scripts/validate-state.d.ts → executor/compressor/fetchSaved.d.ts} +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
+
import { Provider } from '@ethersproject/providers';
|
|
3
|
+
import { SwapSide } from '../constants';
|
|
4
|
+
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
5
|
+
import { IDexTxBuilder } from './idex';
|
|
6
|
+
import { SimpleExchange } from './simple-exchange';
|
|
7
|
+
import MStableAssetABI from '../abi/MStableAsset.json';
|
|
8
|
+
import Web3 from 'web3';
|
|
9
|
+
import { IDexHelper } from '../dex-helper';
|
|
10
|
+
|
|
11
|
+
enum MStableFunctions {
|
|
12
|
+
mint = 'mint',
|
|
13
|
+
swap = 'swap',
|
|
14
|
+
redeem = 'redeem',
|
|
15
|
+
}
|
|
16
|
+
type MStableData = {
|
|
17
|
+
exchange: string;
|
|
18
|
+
opType: MStableFunctions;
|
|
19
|
+
isAssetContract: boolean;
|
|
20
|
+
};
|
|
21
|
+
type MStableMint = [
|
|
22
|
+
_input: string,
|
|
23
|
+
_inputQuantity: string,
|
|
24
|
+
_minOutputQuantity: string,
|
|
25
|
+
_recipient: string,
|
|
26
|
+
];
|
|
27
|
+
type MStableSwap = [
|
|
28
|
+
_input: string,
|
|
29
|
+
_output: string,
|
|
30
|
+
_inputQuantity: string,
|
|
31
|
+
_minOutputQuantity: string,
|
|
32
|
+
_recipient: string,
|
|
33
|
+
];
|
|
34
|
+
type MStableRedeem = [
|
|
35
|
+
_output: string,
|
|
36
|
+
_mAssetQuantity: string,
|
|
37
|
+
_minOutputQuantity: string,
|
|
38
|
+
_recipient: string,
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
type MStableParam = MStableMint | MStableSwap | MStableRedeem;
|
|
42
|
+
|
|
43
|
+
export class MStable
|
|
44
|
+
extends SimpleExchange
|
|
45
|
+
implements IDexTxBuilder<MStableData, MStableParam>
|
|
46
|
+
{
|
|
47
|
+
static dexKeys = ['mStable'];
|
|
48
|
+
mStableAsset: Interface;
|
|
49
|
+
|
|
50
|
+
constructor(dexHelper: IDexHelper) {
|
|
51
|
+
super(dexHelper, 'mStable');
|
|
52
|
+
this.mStableAsset = new Interface(MStableAssetABI as JsonFragment[]);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getAdapterParam(
|
|
56
|
+
srcToken: string,
|
|
57
|
+
destToken: string,
|
|
58
|
+
srcAmount: string,
|
|
59
|
+
destAmount: string,
|
|
60
|
+
data: MStableData,
|
|
61
|
+
side: SwapSide,
|
|
62
|
+
): AdapterExchangeParam {
|
|
63
|
+
const { opType } = data;
|
|
64
|
+
const type = [
|
|
65
|
+
MStableFunctions.swap,
|
|
66
|
+
MStableFunctions.mint,
|
|
67
|
+
MStableFunctions.redeem,
|
|
68
|
+
].indexOf(opType);
|
|
69
|
+
|
|
70
|
+
if (type === undefined) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`mStable: Invalid OpType ${opType}, Should be one of ['mint', 'swap', 'redeem']`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const payload = this.abiCoder.encodeParameter(
|
|
77
|
+
{
|
|
78
|
+
ParentStruct: {
|
|
79
|
+
opType: 'uint',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
opType: type,
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
targetExchange: data.exchange,
|
|
89
|
+
payload,
|
|
90
|
+
networkFee: '0',
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async getSimpleParam(
|
|
95
|
+
srcToken: string,
|
|
96
|
+
destToken: string,
|
|
97
|
+
srcAmount: string,
|
|
98
|
+
destAmount: string,
|
|
99
|
+
data: MStableData,
|
|
100
|
+
side: SwapSide,
|
|
101
|
+
): Promise<SimpleExchangeParam> {
|
|
102
|
+
const { opType, isAssetContract } = data;
|
|
103
|
+
|
|
104
|
+
const [swapFunction, swapFunctionsParams] = ((): [
|
|
105
|
+
MStableFunctions,
|
|
106
|
+
MStableParam,
|
|
107
|
+
] => {
|
|
108
|
+
switch (opType) {
|
|
109
|
+
case MStableFunctions.mint:
|
|
110
|
+
return [
|
|
111
|
+
opType,
|
|
112
|
+
[srcToken, srcAmount, destAmount, this.augustusAddress],
|
|
113
|
+
];
|
|
114
|
+
case MStableFunctions.swap:
|
|
115
|
+
return [
|
|
116
|
+
opType,
|
|
117
|
+
[srcToken, destToken, srcAmount, destAmount, this.augustusAddress],
|
|
118
|
+
];
|
|
119
|
+
case MStableFunctions.redeem:
|
|
120
|
+
return [
|
|
121
|
+
opType,
|
|
122
|
+
[destToken, srcAmount, destAmount, this.augustusAddress],
|
|
123
|
+
];
|
|
124
|
+
default:
|
|
125
|
+
throw new Error(
|
|
126
|
+
`mStable's OpType ${opType} not supported, failed to build`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
|
|
131
|
+
// mStableAsset & mStablePool both have the same interface hence we can
|
|
132
|
+
// simply use mStableAsset contract
|
|
133
|
+
const swapData = this.mStableAsset.encodeFunctionData(
|
|
134
|
+
swapFunction,
|
|
135
|
+
swapFunctionsParams,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
return this.buildSimpleParamWithoutWETHConversion(
|
|
139
|
+
srcToken,
|
|
140
|
+
srcAmount,
|
|
141
|
+
destToken,
|
|
142
|
+
destAmount,
|
|
143
|
+
swapData,
|
|
144
|
+
data.exchange,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
+
import { Provider } from '@ethersproject/providers';
|
|
3
|
+
import { SwapSide } from '../../constants';
|
|
4
|
+
import {
|
|
5
|
+
AdapterExchangeParam,
|
|
6
|
+
Address,
|
|
7
|
+
DexExchangeParam,
|
|
8
|
+
NumberAsString,
|
|
9
|
+
SimpleExchangeParam,
|
|
10
|
+
} from '../../types';
|
|
11
|
+
import { IDexTxBuilder } from '../idex';
|
|
12
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
13
|
+
import OnebitABI from '../../abi/Onebit.json';
|
|
14
|
+
import { IDexHelper } from '../../dex-helper';
|
|
15
|
+
import { OnebitData, OnebitFunctions, OnebitParam } from './types';
|
|
16
|
+
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
17
|
+
|
|
18
|
+
export class Onebit
|
|
19
|
+
extends SimpleExchange
|
|
20
|
+
implements IDexTxBuilder<OnebitData, OnebitParam>
|
|
21
|
+
{
|
|
22
|
+
static dexKeys = ['omm1'];
|
|
23
|
+
exchangeRouterInterface: Interface;
|
|
24
|
+
needWrapNative = true;
|
|
25
|
+
|
|
26
|
+
constructor(dexHelper: IDexHelper) {
|
|
27
|
+
super(dexHelper, 'omm1');
|
|
28
|
+
this.exchangeRouterInterface = new Interface(OnebitABI as JsonFragment[]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getAdapterParam(
|
|
32
|
+
srcToken: string,
|
|
33
|
+
destToken: string,
|
|
34
|
+
srcAmount: string,
|
|
35
|
+
destAmount: string,
|
|
36
|
+
data: OnebitData,
|
|
37
|
+
side: SwapSide,
|
|
38
|
+
): AdapterExchangeParam {
|
|
39
|
+
return {
|
|
40
|
+
targetExchange: data.router,
|
|
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: OnebitData,
|
|
52
|
+
side: SwapSide,
|
|
53
|
+
): Promise<SimpleExchangeParam> {
|
|
54
|
+
const swapFunction = OnebitFunctions.swapTokensWithTrust;
|
|
55
|
+
const swapFunctionParams: OnebitParam = [
|
|
56
|
+
srcToken,
|
|
57
|
+
destToken,
|
|
58
|
+
srcAmount,
|
|
59
|
+
destAmount,
|
|
60
|
+
this.augustusAddress,
|
|
61
|
+
];
|
|
62
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
63
|
+
swapFunction,
|
|
64
|
+
swapFunctionParams,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return this.buildSimpleParamWithoutWETHConversion(
|
|
68
|
+
srcToken,
|
|
69
|
+
srcAmount,
|
|
70
|
+
destToken,
|
|
71
|
+
destAmount,
|
|
72
|
+
swapData,
|
|
73
|
+
data.router,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getDexParam(
|
|
78
|
+
srcToken: Address,
|
|
79
|
+
destToken: Address,
|
|
80
|
+
srcAmount: NumberAsString,
|
|
81
|
+
destAmount: NumberAsString,
|
|
82
|
+
recipient: Address,
|
|
83
|
+
data: OnebitData,
|
|
84
|
+
_side: SwapSide,
|
|
85
|
+
): DexExchangeParam {
|
|
86
|
+
const swapFunction = OnebitFunctions.swapTokensWithTrust;
|
|
87
|
+
const swapFunctionParams: OnebitParam = [
|
|
88
|
+
srcToken,
|
|
89
|
+
destToken,
|
|
90
|
+
srcAmount,
|
|
91
|
+
destAmount,
|
|
92
|
+
recipient,
|
|
93
|
+
];
|
|
94
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
95
|
+
swapFunction,
|
|
96
|
+
swapFunctionParams,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
needWrapNative: this.needWrapNative,
|
|
101
|
+
dexFuncHasRecipient: true,
|
|
102
|
+
exchangeData: swapData,
|
|
103
|
+
targetExchange: data.router,
|
|
104
|
+
returnAmountPos:
|
|
105
|
+
_side === SwapSide.SELL
|
|
106
|
+
? extractReturnAmountPosition(
|
|
107
|
+
this.exchangeRouterInterface,
|
|
108
|
+
swapFunction,
|
|
109
|
+
)
|
|
110
|
+
: undefined,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Address } from '@paraswap/core';
|
|
2
|
+
|
|
3
|
+
export type OnebitData = {
|
|
4
|
+
router: Address;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type OnebitParam = [
|
|
8
|
+
srcToken: string,
|
|
9
|
+
destToken: string,
|
|
10
|
+
srcAmount: string,
|
|
11
|
+
destAmountMin: string,
|
|
12
|
+
to: string,
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export enum OnebitFunctions {
|
|
16
|
+
swapTokensWithTrust = 'swapTokensWithTrust',
|
|
17
|
+
}
|
package/src/dex/shell.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
+
import { SwapSide } from '../constants';
|
|
3
|
+
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
4
|
+
import { IDexTxBuilder } from './idex';
|
|
5
|
+
import {
|
|
6
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
7
|
+
SimpleExchange,
|
|
8
|
+
} from './simple-exchange';
|
|
9
|
+
import ShellABI from '../abi/Shell.json';
|
|
10
|
+
import { IDexHelper } from '../dex-helper';
|
|
11
|
+
|
|
12
|
+
export type ShellData = {
|
|
13
|
+
exchange: Address;
|
|
14
|
+
deadline?: number;
|
|
15
|
+
};
|
|
16
|
+
type ShellParam = [
|
|
17
|
+
_origin: string,
|
|
18
|
+
_target: string,
|
|
19
|
+
_originAmount: string,
|
|
20
|
+
_minTargetAmount: string,
|
|
21
|
+
_deadline: string,
|
|
22
|
+
];
|
|
23
|
+
enum ShellFunctions {
|
|
24
|
+
originSwap = 'originSwap',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class Shell
|
|
28
|
+
extends SimpleExchange
|
|
29
|
+
implements IDexTxBuilder<ShellData, ShellParam>
|
|
30
|
+
{
|
|
31
|
+
static dexKeys = ['shell'];
|
|
32
|
+
exchangeRouterInterface: Interface;
|
|
33
|
+
|
|
34
|
+
constructor(dexHelper: IDexHelper) {
|
|
35
|
+
super(dexHelper, 'shell');
|
|
36
|
+
this.exchangeRouterInterface = new Interface(ShellABI as JsonFragment[]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getAdapterParam(
|
|
40
|
+
srcToken: string,
|
|
41
|
+
destToken: string,
|
|
42
|
+
srcAmount: string,
|
|
43
|
+
destAmount: string,
|
|
44
|
+
data: ShellData,
|
|
45
|
+
side: SwapSide,
|
|
46
|
+
): AdapterExchangeParam {
|
|
47
|
+
return {
|
|
48
|
+
targetExchange: data.exchange,
|
|
49
|
+
payload: '0x',
|
|
50
|
+
networkFee: '0',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getSimpleParam(
|
|
55
|
+
srcToken: string,
|
|
56
|
+
destToken: string,
|
|
57
|
+
srcAmount: string,
|
|
58
|
+
destAmount: string,
|
|
59
|
+
data: ShellData,
|
|
60
|
+
side: SwapSide,
|
|
61
|
+
): Promise<SimpleExchangeParam> {
|
|
62
|
+
const swapFunction = ShellFunctions.originSwap;
|
|
63
|
+
const swapFunctionParams: ShellParam = [
|
|
64
|
+
srcToken,
|
|
65
|
+
destToken,
|
|
66
|
+
srcAmount,
|
|
67
|
+
destAmount,
|
|
68
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
69
|
+
];
|
|
70
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
71
|
+
swapFunction,
|
|
72
|
+
swapFunctionParams,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return this.buildSimpleParamWithoutWETHConversion(
|
|
76
|
+
srcToken,
|
|
77
|
+
srcAmount,
|
|
78
|
+
destToken,
|
|
79
|
+
destAmount,
|
|
80
|
+
swapData,
|
|
81
|
+
data.exchange,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Network, SwapSide } from '../constants';
|
|
2
|
+
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
3
|
+
import { IDexTxBuilder } from './idex';
|
|
4
|
+
import { IDexHelper } from '../dex-helper';
|
|
5
|
+
import {
|
|
6
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
7
|
+
SimpleExchange,
|
|
8
|
+
} from './simple-exchange';
|
|
9
|
+
import { NumberAsString } from '@paraswap/core';
|
|
10
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
11
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
12
|
+
import TraderJoeV2RouterABI from '../abi/TraderJoeV2Router.json';
|
|
13
|
+
|
|
14
|
+
const TRADERJOE_V2_ROUTER_ADDRESS: { [network: number]: Address } = {
|
|
15
|
+
[Network.AVALANCHE]: '0xE3Ffc583dC176575eEA7FD9dF2A7c65F7E23f4C3',
|
|
16
|
+
[Network.ARBITRUM]: '0x7BFd7192E76D950832c77BB412aaE841049D8D9B',
|
|
17
|
+
[Network.BSC]: '0xb66A2704a0dabC1660941628BE987B4418f7a9E8',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type TraderJoeV2RouterSellParams = [
|
|
21
|
+
_amountIn: NumberAsString,
|
|
22
|
+
_amountOutMin: NumberAsString,
|
|
23
|
+
_pairBinSteps: NumberAsString[],
|
|
24
|
+
_tokenPath: Address[],
|
|
25
|
+
to: Address,
|
|
26
|
+
_deadline: number,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
type TraderJoeV2RouterBuyParams = [
|
|
30
|
+
_amountOut: NumberAsString,
|
|
31
|
+
_amountInMax: NumberAsString,
|
|
32
|
+
_pairBinSteps: NumberAsString[],
|
|
33
|
+
_tokenPath: Address[],
|
|
34
|
+
to: Address,
|
|
35
|
+
_deadline: string,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
type TraderJoeV2RouterParam =
|
|
39
|
+
| TraderJoeV2RouterSellParams
|
|
40
|
+
| TraderJoeV2RouterBuyParams;
|
|
41
|
+
|
|
42
|
+
export type TraderJoeV2Data = {
|
|
43
|
+
tokenIn: string; // redundant
|
|
44
|
+
tokenOut: string; // redundant
|
|
45
|
+
binStep: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
enum TraderJoeV2RouterFunctions {
|
|
49
|
+
swapExactTokensForTokens = 'swapExactTokensForTokens',
|
|
50
|
+
swapTokensForExactTokens = 'swapTokensForExactTokens',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class TraderJoeV2
|
|
54
|
+
extends SimpleExchange
|
|
55
|
+
implements IDexTxBuilder<TraderJoeV2Data, TraderJoeV2RouterParam>
|
|
56
|
+
{
|
|
57
|
+
static dexKeys = ['traderjoev2'];
|
|
58
|
+
protected routerAddress: string;
|
|
59
|
+
exchangeRouterInterface: Interface;
|
|
60
|
+
needWrapNative = true;
|
|
61
|
+
|
|
62
|
+
constructor(dexHelper: IDexHelper) {
|
|
63
|
+
super(dexHelper, 'traderjoev2');
|
|
64
|
+
|
|
65
|
+
this.routerAddress =
|
|
66
|
+
TRADERJOE_V2_ROUTER_ADDRESS[dexHelper.config.data.network];
|
|
67
|
+
|
|
68
|
+
this.exchangeRouterInterface = new Interface(
|
|
69
|
+
TraderJoeV2RouterABI as JsonFragment[],
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getAdapterParam(
|
|
74
|
+
srcToken: Address,
|
|
75
|
+
destToken: Address,
|
|
76
|
+
srcAmount: NumberAsString,
|
|
77
|
+
destAmount: NumberAsString,
|
|
78
|
+
data: TraderJoeV2Data,
|
|
79
|
+
side: SwapSide,
|
|
80
|
+
): AdapterExchangeParam {
|
|
81
|
+
const payload = this.abiCoder.encodeParameter(
|
|
82
|
+
{
|
|
83
|
+
ParentStruct: {
|
|
84
|
+
_pairBinSteps: 'uint256[]',
|
|
85
|
+
_tokenPath: 'address[]',
|
|
86
|
+
_deadline: 'uint256',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
_pairBinSteps: [data.binStep],
|
|
91
|
+
_tokenPath: [data.tokenIn, data.tokenOut], // FIXME: redundant, shoot & read from contract
|
|
92
|
+
_deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
targetExchange: this.routerAddress,
|
|
98
|
+
payload,
|
|
99
|
+
networkFee: '0',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getSimpleParam(
|
|
104
|
+
srcToken: Address,
|
|
105
|
+
destToken: Address,
|
|
106
|
+
srcAmount: NumberAsString,
|
|
107
|
+
destAmount: NumberAsString,
|
|
108
|
+
data: TraderJoeV2Data,
|
|
109
|
+
side: SwapSide,
|
|
110
|
+
): AsyncOrSync<SimpleExchangeParam> {
|
|
111
|
+
const swapFunction =
|
|
112
|
+
side === SwapSide.SELL
|
|
113
|
+
? TraderJoeV2RouterFunctions.swapExactTokensForTokens
|
|
114
|
+
: TraderJoeV2RouterFunctions.swapTokensForExactTokens;
|
|
115
|
+
|
|
116
|
+
const swapFunctionParams: TraderJoeV2RouterParam =
|
|
117
|
+
side === SwapSide.SELL
|
|
118
|
+
? [
|
|
119
|
+
srcAmount,
|
|
120
|
+
destAmount,
|
|
121
|
+
[data.binStep],
|
|
122
|
+
[srcToken, destToken],
|
|
123
|
+
this.augustusAddress,
|
|
124
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
125
|
+
]
|
|
126
|
+
: [
|
|
127
|
+
destAmount,
|
|
128
|
+
srcAmount,
|
|
129
|
+
[data.binStep],
|
|
130
|
+
[srcToken, destToken],
|
|
131
|
+
this.augustusAddress,
|
|
132
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
133
|
+
];
|
|
134
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
135
|
+
swapFunction,
|
|
136
|
+
swapFunctionParams,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return this.buildSimpleParamWithoutWETHConversion(
|
|
140
|
+
srcToken,
|
|
141
|
+
srcAmount,
|
|
142
|
+
destToken,
|
|
143
|
+
destAmount,
|
|
144
|
+
swapData,
|
|
145
|
+
this.routerAddress,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -23,7 +23,7 @@ export class Oracle {
|
|
|
23
23
|
): OracleObservation {
|
|
24
24
|
const delta = blockTimestamp - last.blockTimestamp;
|
|
25
25
|
return {
|
|
26
|
-
blockTimestamp
|
|
26
|
+
blockTimestamp,
|
|
27
27
|
tickCumulative: last.tickCumulative + BigInt.asIntN(56, tick) * delta,
|
|
28
28
|
secondsPerLiquidityCumulativeX128:
|
|
29
29
|
last.secondsPerLiquidityCumulativeX128 +
|
|
@@ -93,12 +93,12 @@ export class Oracle {
|
|
|
93
93
|
let beforeOrAt;
|
|
94
94
|
let atOrAfter;
|
|
95
95
|
while (true) {
|
|
96
|
-
i = (l + r) / 2;
|
|
96
|
+
i = Math.floor((l + r) / 2);
|
|
97
97
|
|
|
98
98
|
beforeOrAt = state.observations[i % cardinality];
|
|
99
99
|
|
|
100
100
|
// we've landed on an uninitialized tick, keep searching higher (more recently)
|
|
101
|
-
if (!beforeOrAt.initialized) {
|
|
101
|
+
if (!beforeOrAt || !beforeOrAt.initialized) {
|
|
102
102
|
l = i + 1;
|
|
103
103
|
continue;
|
|
104
104
|
}
|
|
@@ -150,7 +150,8 @@ export class Oracle {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
beforeOrAt = state.observations[(index + 1) % cardinality];
|
|
153
|
-
if (!beforeOrAt.initialized)
|
|
153
|
+
if (!beforeOrAt || !beforeOrAt.initialized)
|
|
154
|
+
beforeOrAt = state.observations[0];
|
|
154
155
|
|
|
155
156
|
_require(
|
|
156
157
|
Oracle.lte(time, beforeOrAt.blockTimestamp, target),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Network } from '../../constants';
|
|
2
|
+
|
|
3
|
+
export const ZRX_EXCHANGE: Record<number, Record<number, string>> = {
|
|
4
|
+
[Network.MAINNET]: {
|
|
5
|
+
2: '0x080bf510fcbf18b91105470639e9561022937712',
|
|
6
|
+
3: '0x61935CbDd02287B511119DDb11Aeb42F1593b7Ef',
|
|
7
|
+
4: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
|
|
8
|
+
},
|
|
9
|
+
[Network.BSC]: {
|
|
10
|
+
2: '0x3F93C3D9304a70c9104642AB8cD37b1E2a7c203A',
|
|
11
|
+
4: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
|
|
12
|
+
},
|
|
13
|
+
[Network.POLYGON]: {
|
|
14
|
+
4: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const ZRX_EXCHANGE_ERC20PROXY: Record<number, Record<number, string>> = {
|
|
19
|
+
[Network.MAINNET]: {
|
|
20
|
+
1: '0x95E6F48254609A6ee006F7D493c8e5fB97094ceF',
|
|
21
|
+
2: '0x95E6F48254609A6ee006F7D493c8e5fB97094ceF',
|
|
22
|
+
4: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
|
|
23
|
+
},
|
|
24
|
+
[Network.BSC]: {
|
|
25
|
+
2: '0xCF21d4b7a265FF779accBA55Ace0F56C8cE6e379',
|
|
26
|
+
4: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
|
|
27
|
+
},
|
|
28
|
+
[Network.POLYGON]: {
|
|
29
|
+
4: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
|
|
30
|
+
},
|
|
31
|
+
};
|