@paraswap/dex-lib 3.8.13 → 3.8.15
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 +16 -0
- package/.vscode/settings.json +3 -0
- package/build/abi/Uncompressor.json +250 -0
- package/build/abi/concentrator/arUSD5115.json +1746 -0
- package/build/abi/fx-protocol/FxMarket.json +1284 -0
- package/build/abi/fx-protocol/weETHOralce.json +676 -0
- package/build/abi/integral/factory.json +333 -0
- package/build/abi/integral/oracle.json +501 -0
- package/build/abi/{inception/inception-ineth-pool.json → integral/pool.json} +522 -543
- package/build/abi/integral/relayer.json +1536 -0
- package/build/abi/maverick-v2/MaverickV2Router.json +778 -0
- package/build/dex/aave-v1/aave-v1.d.ts +1 -2
- package/build/dex/aave-v1/aave-v1.js +0 -22
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/bProtocol.d.ts +18 -0
- package/build/dex/bProtocol.js +39 -0
- package/build/dex/bProtocol.js.map +1 -0
- package/build/dex/bancor.d.ts +26 -0
- package/build/dex/bancor.js +58 -0
- package/build/dex/bancor.js.map +1 -0
- package/build/dex/compound.d.ts +18 -0
- package/build/dex/compound.js +46 -0
- package/build/dex/compound.js.map +1 -0
- package/build/dex/concentrator-arusd/concentrator-arusd-event.d.ts +17 -0
- package/build/dex/concentrator-arusd/concentrator-arusd-event.js +66 -0
- package/build/dex/concentrator-arusd/concentrator-arusd-event.js.map +1 -0
- package/build/dex/concentrator-arusd/concentrator-arusd.d.ts +6 -3
- package/build/dex/concentrator-arusd/concentrator-arusd.js +45 -41
- package/build/dex/concentrator-arusd/concentrator-arusd.js.map +1 -1
- package/build/dex/concentrator-arusd/config.d.ts +1 -2
- package/build/dex/concentrator-arusd/config.js +2 -6
- package/build/dex/concentrator-arusd/config.js.map +1 -1
- package/build/dex/concentrator-arusd/types.d.ts +7 -3
- package/build/dex/concentrator-arusd/utils.d.ts +4 -0
- package/build/dex/concentrator-arusd/utils.js +27 -0
- package/build/dex/concentrator-arusd/utils.js.map +1 -0
- package/build/dex/curve-v2.d.ts +58 -0
- package/build/dex/curve-v2.js +180 -0
- package/build/dex/curve-v2.js.map +1 -0
- package/build/dex/dodo-v1.d.ts +33 -0
- package/build/dex/dodo-v1.js +63 -0
- package/build/dex/dodo-v1.js.map +1 -0
- 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/fx-protocol-rusd/config.d.ts +1 -2
- package/build/dex/fx-protocol-rusd/config.js +3 -6
- package/build/dex/fx-protocol-rusd/config.js.map +1 -1
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.d.ts +18 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js +71 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js.map +1 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd.d.ts +10 -10
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js +75 -70
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js.map +1 -1
- package/build/dex/fx-protocol-rusd/types.d.ts +6 -3
- package/build/dex/fx-protocol-rusd/utils.d.ts +4 -0
- package/build/dex/fx-protocol-rusd/utils.js +26 -0
- package/build/dex/fx-protocol-rusd/utils.js.map +1 -0
- package/build/dex/index.js +4 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/{infusion → integral}/config.d.ts +1 -1
- 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 +24 -0
- package/build/dex/integral/integral-factory.js +95 -0
- package/build/dex/integral/integral-factory.js.map +1 -0
- package/build/dex/integral/integral-pool.d.ts +50 -0
- package/build/dex/integral/integral-pool.js +149 -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 +42 -0
- package/build/dex/integral/integral-relayer.js +192 -0
- package/build/dex/integral/integral-relayer.js.map +1 -0
- package/build/dex/integral/integral-token.d.ts +27 -0
- package/build/dex/integral/integral-token.js +59 -0
- package/build/dex/integral/integral-token.js.map +1 -0
- package/build/dex/{inception/inception-native.d.ts → integral/integral.d.ts} +19 -21
- 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/lido.d.ts +19 -0
- package/build/dex/lido.js +42 -0
- package/build/dex/lido.js.map +1 -0
- package/build/dex/onebit.d.ts +25 -0
- package/build/dex/onebit.js +42 -0
- package/build/dex/onebit.js.map +1 -0
- package/build/dex/oswap/oswap.js +4 -1
- package/build/dex/oswap/oswap.js.map +1 -1
- package/build/dex/platypus/platypus.d.ts +1 -2
- package/build/dex/platypus/platypus.js +0 -31
- 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.d.ts +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/smoothy.d.ts +26 -0
- package/build/dex/smoothy.js +48 -0
- package/build/dex/smoothy.js.map +1 -0
- package/build/dex/stable-pool.d.ts +28 -0
- package/build/dex/stable-pool.js +62 -0
- package/build/dex/stable-pool.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
- package/build/dex/swaap-v1/swaap-v1.js +0 -10
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/trader-joe-v2.1.d.ts +43 -0
- package/build/dex/trader-joe-v2.1.js +79 -0
- package/build/dex/trader-joe-v2.1.js.map +1 -0
- package/build/executor/Executor01BytecodeBuilder.js +4 -5
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.js +2 -3
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.js +24 -14
- package/build/executor/Executor03BytecodeBuilder.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.d.ts +0 -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.d.ts +1 -1
- package/build/generic-swap-transaction-builder.js +10 -10
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/concentrator/arUSD.json +568 -0
- package/src/abi/concentrator/arUSD5115.json +1746 -0
- package/src/abi/fx-protocol/FxMarket.json +1284 -0
- package/src/abi/fx-protocol/FxUSD.json +1227 -0
- package/src/abi/fx-protocol/weETHOralce.json +676 -0
- package/src/dex/concentrator-arusd/concentrator-arusd-e2e.test.ts +92 -0
- package/src/dex/concentrator-arusd/concentrator-arusd-event.ts +100 -0
- package/src/dex/concentrator-arusd/concentrator-arusd-integration.test.ts +104 -0
- package/src/dex/concentrator-arusd/concentrator-arusd.ts +269 -0
- package/src/dex/concentrator-arusd/concetrator-arusd-events.test.ts +97 -0
- package/src/dex/concentrator-arusd/config.ts +13 -0
- package/src/dex/concentrator-arusd/types.ts +16 -0
- package/src/dex/concentrator-arusd/utils.ts +36 -0
- package/src/dex/fx-protocol-rusd/config.ts +14 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-e2e.test.ts +96 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-events.test.ts +101 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-integration.test.ts +104 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-rusd-event.ts +112 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-rusd.ts +282 -0
- package/src/dex/fx-protocol-rusd/types.ts +16 -0
- package/src/dex/fx-protocol-rusd/utils.ts +47 -0
- package/src/dex/index.ts +4 -0
- package/src/dex/wsteth/wsteth-integration.test.ts +0 -1
- package/src/executor/Executor01BytecodeBuilder.ts +4 -8
- package/src/executor/Executor02BytecodeBuilder.ts +2 -7
- package/src/executor/Executor03BytecodeBuilder.ts +34 -19
- package/src/generic-swap-transaction-builder.ts +3 -5
- package/tests/constants-e2e.ts +10 -0
- package/build/abi/inception/inception-ineth.json +0 -609
- package/build/abi/inception/inception-ratio-feed.json +0 -93
- package/build/abi/inception/inception-vault.json +0 -991
- package/build/abi/infusion/InfusionFactory.json +0 -147
- package/build/abi/infusion/InfusionPair.json +0 -658
- package/build/abi/infusion/InfusionRouter.json +0 -442
- package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
- package/build/dex/idle-dao/idle-dao-pool.js +0 -176
- package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
- package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
- package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
- package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
- package/build/dex/idle-dao/scripts.d.ts +0 -9
- package/build/dex/idle-dao/scripts.js +0 -552
- package/build/dex/idle-dao/scripts.js.map +0 -1
- package/build/dex/inception/config.d.ts +0 -5
- package/build/dex/inception/config.js +0 -112
- package/build/dex/inception/config.js.map +0 -1
- package/build/dex/inception/inception-event-pool.d.ts +0 -23
- package/build/dex/inception/inception-event-pool.js +0 -34
- package/build/dex/inception/inception-event-pool.js.map +0 -1
- package/build/dex/inception/inception-native.js +0 -131
- package/build/dex/inception/inception-native.js.map +0 -1
- package/build/dex/inception/inception-pool.d.ts +0 -18
- package/build/dex/inception/inception-pool.js +0 -32
- package/build/dex/inception/inception-pool.js.map +0 -1
- package/build/dex/inception/inception-price-feed.d.ts +0 -19
- package/build/dex/inception/inception-price-feed.js +0 -51
- package/build/dex/inception/inception-price-feed.js.map +0 -1
- package/build/dex/inception/inception.d.ts +0 -44
- package/build/dex/inception/inception.js +0 -162
- package/build/dex/inception/inception.js.map +0 -1
- package/build/dex/inception/tokens.d.ts +0 -9
- package/build/dex/inception/tokens.js +0 -28
- package/build/dex/inception/tokens.js.map +0 -1
- package/build/dex/inception/types.d.ts +0 -22
- package/build/dex/inception/types.js +0 -3
- package/build/dex/inception/types.js.map +0 -1
- package/build/dex/inception/utils.d.ts +0 -7
- package/build/dex/inception/utils.js +0 -58
- package/build/dex/inception/utils.js.map +0 -1
- package/build/dex/infusion/config.js +0 -25
- package/build/dex/infusion/config.js.map +0 -1
- package/build/dex/infusion/infusion-stable-pool.d.ts +0 -4
- package/build/dex/infusion/infusion-stable-pool.js +0 -74
- package/build/dex/infusion/infusion-stable-pool.js.map +0 -1
- package/build/dex/infusion/infusion.d.ts +0 -54
- package/build/dex/infusion/infusion.js +0 -532
- package/build/dex/infusion/infusion.js.map +0 -1
- package/build/dex/infusion/types.d.ts +0 -47
- package/build/dex/infusion/types.js +0 -3
- package/build/dex/infusion/types.js.map +0 -1
- package/build/dex/infusion/utils/isStablePair.d.ts +0 -2
- package/build/dex/infusion/utils/isStablePair.js +0 -18
- package/build/dex/infusion/utils/isStablePair.js.map +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Contract } from 'web3-eth-contract';
|
|
2
|
+
import { ConcentratorArusdState, ConcentratorArusdNavState } from './types';
|
|
3
|
+
import { Interface, AbiCoder } from '@ethersproject/abi';
|
|
4
|
+
|
|
5
|
+
const coder = new AbiCoder();
|
|
6
|
+
|
|
7
|
+
export async function getOnChainState(
|
|
8
|
+
multiContract: Contract,
|
|
9
|
+
poolAddress: string,
|
|
10
|
+
poolInterface: Interface,
|
|
11
|
+
blockNumber: number | 'latest',
|
|
12
|
+
): Promise<ConcentratorArusdState> {
|
|
13
|
+
const data: { returnData: any[] } = await multiContract.methods
|
|
14
|
+
.aggregate([
|
|
15
|
+
{
|
|
16
|
+
target: poolAddress,
|
|
17
|
+
callData: poolInterface.encodeFunctionData('totalSupply', []),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
target: poolAddress,
|
|
21
|
+
callData: poolInterface.encodeFunctionData('getTotalAssets', []),
|
|
22
|
+
},
|
|
23
|
+
])
|
|
24
|
+
.call({}, blockNumber);
|
|
25
|
+
|
|
26
|
+
const totalSupply = BigInt(
|
|
27
|
+
poolInterface.decodeFunctionResult('totalSupply', data.returnData[0])[0],
|
|
28
|
+
).toString();
|
|
29
|
+
const totalAssets = BigInt(
|
|
30
|
+
poolInterface.decodeFunctionResult('getTotalAssets', data.returnData[1])[0],
|
|
31
|
+
).toString();
|
|
32
|
+
return {
|
|
33
|
+
totalSupply,
|
|
34
|
+
totalAssets,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DexParams } from './types';
|
|
2
|
+
import { DexConfigMap, AdapterMappings } from '../../types';
|
|
3
|
+
import { Network, SwapSide } from '../../constants';
|
|
4
|
+
|
|
5
|
+
export const FxProtocolConfig: DexConfigMap<DexParams> = {
|
|
6
|
+
FxProtocolRusd: {
|
|
7
|
+
[Network.MAINNET]: {
|
|
8
|
+
rUSDAddress: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18',
|
|
9
|
+
weETHAddress: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
|
|
10
|
+
rUSDWeETHMarketAddress: '0x267c6a96db7422faa60aa7198ffeeec4169cd65f',
|
|
11
|
+
weETHOracleAddress: '0xddb6f90ffb4d3257dd666b69178e5b3c5bf41136',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
import { testE2E } from '../../../tests/utils-e2e';
|
|
6
|
+
import {
|
|
7
|
+
Tokens,
|
|
8
|
+
Holders,
|
|
9
|
+
NativeTokenSymbols,
|
|
10
|
+
} from '../../../tests/constants-e2e';
|
|
11
|
+
import { Network, ContractMethod, SwapSide } from '../../constants';
|
|
12
|
+
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
13
|
+
import { generateConfig } from '../../config';
|
|
14
|
+
|
|
15
|
+
function testForNetwork(
|
|
16
|
+
network: Network,
|
|
17
|
+
dexKey: string,
|
|
18
|
+
tokenASymbol: string,
|
|
19
|
+
tokenBSymbol: string,
|
|
20
|
+
tokenAAmount: string,
|
|
21
|
+
tokenBAmount: string,
|
|
22
|
+
) {
|
|
23
|
+
const provider = new StaticJsonRpcProvider(
|
|
24
|
+
generateConfig(network).privateHttpProvider,
|
|
25
|
+
network,
|
|
26
|
+
);
|
|
27
|
+
const tokens = Tokens[network];
|
|
28
|
+
const holders = Holders[network];
|
|
29
|
+
|
|
30
|
+
const sideToContractMethods = new Map([
|
|
31
|
+
[SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
|
|
32
|
+
// [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
describe(`${network}`, () => {
|
|
36
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
37
|
+
describe(`${side}`, () => {
|
|
38
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
39
|
+
describe(`${contractMethod}`, () => {
|
|
40
|
+
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
|
|
41
|
+
await testE2E(
|
|
42
|
+
tokens[tokenASymbol],
|
|
43
|
+
tokens[tokenBSymbol],
|
|
44
|
+
holders[tokenASymbol],
|
|
45
|
+
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
|
|
46
|
+
side,
|
|
47
|
+
dexKey,
|
|
48
|
+
contractMethod,
|
|
49
|
+
network,
|
|
50
|
+
provider,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('FxProtocolRusd E2E', () => {
|
|
61
|
+
const dexKey = 'FxProtocolRusd';
|
|
62
|
+
const network = Network.MAINNET;
|
|
63
|
+
const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
|
|
64
|
+
[
|
|
65
|
+
{
|
|
66
|
+
name: 'weETH',
|
|
67
|
+
amount: '1000000000000000000',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'rUSD',
|
|
71
|
+
amount: '1000000000000000000',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
{
|
|
76
|
+
name: 'rUSD',
|
|
77
|
+
amount: '100000000000000',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'weETH',
|
|
81
|
+
amount: '1000000000000000000',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
pairs.forEach(pair => {
|
|
87
|
+
testForNetwork(
|
|
88
|
+
network,
|
|
89
|
+
dexKey,
|
|
90
|
+
pair[0].name,
|
|
91
|
+
pair[1].name,
|
|
92
|
+
pair[0].amount,
|
|
93
|
+
pair[1].amount,
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { FxProtocolRusdEvent } from './fx-protocol-rusd-event';
|
|
5
|
+
import { FxProtocolConfig } from './config';
|
|
6
|
+
import { Network } from '../../constants';
|
|
7
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
8
|
+
import { testEventSubscriber } from '../../../tests/utils-events';
|
|
9
|
+
import FxUSD_ABI from '../../abi/fx-protocol/FxUSD.json';
|
|
10
|
+
import FxMarket_ABI from '../../abi/fx-protocol/FxMarket.json';
|
|
11
|
+
import EthWeETHOralce_ABI from '../../abi/fx-protocol/weETHOralce.json';
|
|
12
|
+
|
|
13
|
+
import _ from 'lodash';
|
|
14
|
+
import { FxProtocolPoolState } from './types';
|
|
15
|
+
import { Interface } from 'ethers/lib/utils';
|
|
16
|
+
import { JsonFragment } from '@ethersproject/abi';
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
README
|
|
20
|
+
======
|
|
21
|
+
|
|
22
|
+
This test script adds unit tests for fxProtocol event based
|
|
23
|
+
system. This is done by fetching the state on-chain before the
|
|
24
|
+
event block, manually pushing the block logs to the event-subscriber,
|
|
25
|
+
comparing the local state with on-chain state.
|
|
26
|
+
|
|
27
|
+
Most of the logic for testing is abstracted by `testEventSubscriber`.
|
|
28
|
+
You need to do two things to make the tests work:
|
|
29
|
+
|
|
30
|
+
1. Fetch the block numbers where certain events were released. You
|
|
31
|
+
can modify the `./scripts/fetch-event-blocknumber.ts` to get the
|
|
32
|
+
block numbers for different events. Make sure to get sufficient
|
|
33
|
+
number of blockNumbers to cover all possible cases for the event
|
|
34
|
+
mutations.
|
|
35
|
+
|
|
36
|
+
2. Complete the implementation for fetchPoolState function. The
|
|
37
|
+
function should fetch the on-chain state of the event subscriber
|
|
38
|
+
using just the blocknumber.
|
|
39
|
+
|
|
40
|
+
The template tests only include the test for a single event
|
|
41
|
+
subscriber. There can be cases where multiple event subscribers
|
|
42
|
+
exist for a single DEX. In such cases additional tests should be
|
|
43
|
+
added.
|
|
44
|
+
|
|
45
|
+
You can run this individual test script by running:
|
|
46
|
+
`npx jest src/dex/<dex-name>/<dex-name>-events.test.ts`
|
|
47
|
+
|
|
48
|
+
(This comment should be removed from the final implementation)
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
jest.setTimeout(50 * 1000);
|
|
52
|
+
const dexKey = 'FxProtocolRusd';
|
|
53
|
+
const network = Network.MAINNET;
|
|
54
|
+
|
|
55
|
+
async function fetchPoolState(
|
|
56
|
+
fxProtocolPool: FxProtocolRusdEvent,
|
|
57
|
+
blockNumber: number,
|
|
58
|
+
): Promise<FxProtocolPoolState> {
|
|
59
|
+
return fxProtocolPool.generateState(blockNumber);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
describe('FxProtocolRusd Event', function () {
|
|
63
|
+
const blockNumbers: { [eventName: string]: number[] } = {
|
|
64
|
+
UpdateRedeemFeeRatioFToken: [19460858, 19465918, 19460857],
|
|
65
|
+
AnswerUpdated: [20482537, 20481328, 20480824, 20480670, 20480669],
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
describe('FxProtocolRusdPool', function () {
|
|
69
|
+
Object.keys(blockNumbers).forEach((event: string) => {
|
|
70
|
+
blockNumbers[event].forEach((blockNumber: number) => {
|
|
71
|
+
it(`Should return the correct state after the ${blockNumber}:${event}`, async function () {
|
|
72
|
+
const dexHelper = new DummyDexHelper(network);
|
|
73
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
74
|
+
const config = FxProtocolConfig[dexKey][network];
|
|
75
|
+
|
|
76
|
+
const fxProtocolPool = new FxProtocolRusdEvent(
|
|
77
|
+
dexKey,
|
|
78
|
+
dexHelper,
|
|
79
|
+
config.rUSDWeETHMarketAddress,
|
|
80
|
+
new Interface(FxMarket_ABI as JsonFragment[]),
|
|
81
|
+
config.weETHOracleAddress,
|
|
82
|
+
new Interface(EthWeETHOralce_ABI as JsonFragment[]),
|
|
83
|
+
logger,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
await fxProtocolPool.initialize(blockNumber);
|
|
87
|
+
|
|
88
|
+
await testEventSubscriber(
|
|
89
|
+
fxProtocolPool,
|
|
90
|
+
fxProtocolPool.addressesSubscribed,
|
|
91
|
+
(_blockNumber: number) =>
|
|
92
|
+
fetchPoolState(fxProtocolPool, _blockNumber),
|
|
93
|
+
blockNumber,
|
|
94
|
+
`${dexKey}_${fxProtocolPool}`,
|
|
95
|
+
dexHelper.provider,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
5
|
+
import { Network, SwapSide } from '../../constants';
|
|
6
|
+
import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
|
|
7
|
+
import { Tokens } from '../../../tests/constants-e2e';
|
|
8
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
9
|
+
import { FxProtocolRusd } from './fx-protocol-rusd';
|
|
10
|
+
|
|
11
|
+
const network = Network.MAINNET;
|
|
12
|
+
|
|
13
|
+
const rUSDSymbol = 'rUSD';
|
|
14
|
+
const rUSDToken = Tokens[network][rUSDSymbol];
|
|
15
|
+
|
|
16
|
+
const weETHSymbol = 'weETH';
|
|
17
|
+
const weETHToken = Tokens[network][weETHSymbol];
|
|
18
|
+
|
|
19
|
+
const amounts = [0n, BI_POWS[18], 2000000000000000000n];
|
|
20
|
+
|
|
21
|
+
const dexKey = 'FxProtocolRusd';
|
|
22
|
+
const dexHelper = new DummyDexHelper(network);
|
|
23
|
+
let blocknumber: number;
|
|
24
|
+
let fxProtocolRusd: FxProtocolRusd;
|
|
25
|
+
|
|
26
|
+
describe('FxProtocolRusd', function () {
|
|
27
|
+
beforeAll(async () => {
|
|
28
|
+
blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
29
|
+
fxProtocolRusd = new FxProtocolRusd(network, dexKey, dexHelper);
|
|
30
|
+
if (fxProtocolRusd.initializePricing) {
|
|
31
|
+
await fxProtocolRusd.initializePricing(blocknumber);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('getPoolIdentifiers and getPricesVolume weETH -> rUSD SELL', async function () {
|
|
36
|
+
const pools = await fxProtocolRusd.getPoolIdentifiers(
|
|
37
|
+
weETHToken,
|
|
38
|
+
rUSDToken,
|
|
39
|
+
SwapSide.SELL,
|
|
40
|
+
blocknumber,
|
|
41
|
+
);
|
|
42
|
+
console.log(`${weETHSymbol} <> ${rUSDSymbol} Pool Identifiers: `, pools);
|
|
43
|
+
|
|
44
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
45
|
+
|
|
46
|
+
const poolPrices = await fxProtocolRusd.getPricesVolume(
|
|
47
|
+
weETHToken,
|
|
48
|
+
rUSDToken,
|
|
49
|
+
amounts,
|
|
50
|
+
SwapSide.SELL,
|
|
51
|
+
blocknumber,
|
|
52
|
+
pools,
|
|
53
|
+
);
|
|
54
|
+
console.log(`${weETHSymbol} <> ${rUSDSymbol} Pool Prices: `, poolPrices);
|
|
55
|
+
|
|
56
|
+
expect(poolPrices).not.toBeNull();
|
|
57
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('getPoolIdentifiers and getPricesVolume rUSD -> weETH SELL', async function () {
|
|
61
|
+
const pools = await fxProtocolRusd.getPoolIdentifiers(
|
|
62
|
+
rUSDToken,
|
|
63
|
+
weETHToken,
|
|
64
|
+
SwapSide.SELL,
|
|
65
|
+
blocknumber,
|
|
66
|
+
);
|
|
67
|
+
console.log(`${rUSDSymbol} <> ${weETHSymbol} Pool Identifiers: `, pools);
|
|
68
|
+
|
|
69
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
70
|
+
|
|
71
|
+
const poolPrices = await fxProtocolRusd.getPricesVolume(
|
|
72
|
+
rUSDToken,
|
|
73
|
+
weETHToken,
|
|
74
|
+
amounts,
|
|
75
|
+
SwapSide.SELL,
|
|
76
|
+
blocknumber,
|
|
77
|
+
pools,
|
|
78
|
+
);
|
|
79
|
+
console.log(`${rUSDSymbol} <> ${weETHSymbol} Pool Prices: `, poolPrices);
|
|
80
|
+
|
|
81
|
+
expect(poolPrices).not.toBeNull();
|
|
82
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('weETH getTopPoolsForToken', async function () {
|
|
86
|
+
const poolLiquidity = await fxProtocolRusd.getTopPoolsForToken(
|
|
87
|
+
weETHToken.address,
|
|
88
|
+
10,
|
|
89
|
+
);
|
|
90
|
+
console.log(`${weETHSymbol} Top Pools:`, poolLiquidity);
|
|
91
|
+
|
|
92
|
+
checkPoolsLiquidity(poolLiquidity, weETHToken.address, dexKey);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('rUSD getTopPoolsForToken', async function () {
|
|
96
|
+
const poolLiquidity = await fxProtocolRusd.getTopPoolsForToken(
|
|
97
|
+
rUSDToken.address,
|
|
98
|
+
10,
|
|
99
|
+
);
|
|
100
|
+
console.log(`${rUSDSymbol} Top Pools:`, poolLiquidity);
|
|
101
|
+
|
|
102
|
+
checkPoolsLiquidity(poolLiquidity, rUSDToken.address, dexKey);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { defaultAbiCoder, Interface } from '@ethersproject/abi';
|
|
3
|
+
import { IDexHelper } from '../../dex-helper';
|
|
4
|
+
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
5
|
+
import { Address, Log, Logger } from '../../types';
|
|
6
|
+
import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
|
|
7
|
+
import { FxProtocolPoolState } from './types';
|
|
8
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
9
|
+
import { getOnChainState } from './utils';
|
|
10
|
+
|
|
11
|
+
const ANSWER_UPDATED_TOPICHASH = `0x0559884fd3a460db3073b7fc896cc77986f16e378210ded43186175bf646fc5f`;
|
|
12
|
+
const UPDATE_REDEEM_FEE_TOPICHASH = `0xb3d49e95905d108ea668ffe62a85ee16bdc4ff9f122a7137964327ea8e0585ff`;
|
|
13
|
+
|
|
14
|
+
export class FxProtocolRusdEvent extends StatefulEventSubscriber<FxProtocolPoolState> {
|
|
15
|
+
constructor(
|
|
16
|
+
parentName: string,
|
|
17
|
+
protected dexHelper: IDexHelper,
|
|
18
|
+
private marketAddress: Address,
|
|
19
|
+
private marketInterface: Interface,
|
|
20
|
+
private weETHOracleAddress: Address,
|
|
21
|
+
private weETHOracleIface: Interface,
|
|
22
|
+
logger: Logger,
|
|
23
|
+
) {
|
|
24
|
+
super(parentName, 'fxProtocolRusd', dexHelper, logger);
|
|
25
|
+
this.addressesSubscribed = [marketAddress, weETHOracleAddress];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected processLog(
|
|
29
|
+
state: DeepReadonly<FxProtocolPoolState>,
|
|
30
|
+
log: Readonly<Log>,
|
|
31
|
+
): AsyncOrSync<DeepReadonly<FxProtocolPoolState> | null> {
|
|
32
|
+
if (log.topics[0] === UPDATE_REDEEM_FEE_TOPICHASH) {
|
|
33
|
+
const [defaultFeeRatio] = defaultAbiCoder.decode(
|
|
34
|
+
['uint256', 'int256'],
|
|
35
|
+
log.data,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
...state,
|
|
40
|
+
redeemFee: BigInt(defaultFeeRatio).toString(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (log.topics[0] === ANSWER_UPDATED_TOPICHASH) {
|
|
45
|
+
return {
|
|
46
|
+
...state,
|
|
47
|
+
weETHPrice: BigInt(log.topics[1]).toString(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async generateState(
|
|
55
|
+
blockNumber: number | 'latest' = 'latest',
|
|
56
|
+
): Promise<DeepReadonly<FxProtocolPoolState>> {
|
|
57
|
+
const state = await getOnChainState(
|
|
58
|
+
this.dexHelper.multiContract,
|
|
59
|
+
this.marketAddress,
|
|
60
|
+
this.marketInterface,
|
|
61
|
+
this.weETHOracleAddress,
|
|
62
|
+
this.weETHOracleIface,
|
|
63
|
+
blockNumber,
|
|
64
|
+
);
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getPrice(
|
|
69
|
+
blockNumber: number,
|
|
70
|
+
amount: bigint,
|
|
71
|
+
isRedeem: boolean,
|
|
72
|
+
): Promise<bigint> {
|
|
73
|
+
const state = await this.getOrGenerateState(blockNumber);
|
|
74
|
+
if (!state) throw new Error('Cannot compute price');
|
|
75
|
+
|
|
76
|
+
const { nav, redeemFee, weETHPrice } = state;
|
|
77
|
+
const baseTokenPrice = BigInt(weETHPrice) * BI_POWS[10];
|
|
78
|
+
|
|
79
|
+
if (isRedeem) {
|
|
80
|
+
return BigInt(
|
|
81
|
+
(amount * BigInt(nav) * (BI_POWS[18] - BigInt(redeemFee))) /
|
|
82
|
+
BI_POWS[18] /
|
|
83
|
+
baseTokenPrice,
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
return BigInt((baseTokenPrice * amount) / BigInt(nav));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async getOrGenerateState(
|
|
91
|
+
blockNumber: number,
|
|
92
|
+
): Promise<DeepReadonly<FxProtocolPoolState> | null> {
|
|
93
|
+
const state = this.getState(blockNumber);
|
|
94
|
+
if (state) {
|
|
95
|
+
return state;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.logger.debug(
|
|
99
|
+
`No state found for ${this.addressesSubscribed[0]}, generating new one`,
|
|
100
|
+
);
|
|
101
|
+
const newState = await this.generateState(blockNumber);
|
|
102
|
+
|
|
103
|
+
if (!newState) {
|
|
104
|
+
this.logger.debug(
|
|
105
|
+
`Could not regenerate state for ${this.addressesSubscribed[0]}`,
|
|
106
|
+
);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
this.setState(newState, blockNumber);
|
|
110
|
+
return newState;
|
|
111
|
+
}
|
|
112
|
+
}
|