@paraswap/dex-lib 2.33.4-balancer-v2-multihop.2 → 2.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/abi/algebra/AlgebraPool.abi.json +727 -0
- package/build/composed-event-subscriber.js +8 -2
- package/build/composed-event-subscriber.js.map +1 -1
- package/build/config.js +27 -0
- package/build/config.js.map +1 -1
- package/build/dex/algebra/algebra-pool-v1_1.d.ts +16 -2
- package/build/dex/algebra/algebra-pool-v1_1.js +166 -4
- package/build/dex/algebra/algebra-pool-v1_1.js.map +1 -1
- package/build/dex/algebra/algebra-pool.d.ts +46 -0
- package/build/dex/algebra/algebra-pool.js +336 -0
- package/build/dex/algebra/algebra-pool.js.map +1 -0
- package/build/dex/algebra/algebra.js +9 -7
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/config.js +1 -0
- package/build/dex/algebra/config.js.map +1 -1
- package/build/dex/algebra/types.d.ts +3 -2
- package/build/dex/algebra/utils.d.ts +3 -1
- package/build/dex/algebra/utils.js +59 -1
- package/build/dex/algebra/utils.js.map +1 -1
- package/build/dex/balancer-v2/optimizer.d.ts +0 -1
- package/build/dex/balancer-v2/optimizer.js +21 -29
- package/build/dex/balancer-v2/optimizer.js.map +1 -1
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/solidly/forks-override/velodromeV2.js +4 -1
- package/build/dex/solidly/forks-override/velodromeV2.js.map +1 -1
- package/build/dex/uniswap-v2/nomiswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.js +7 -1
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/lib/decoders.d.ts +3 -0
- package/build/lib/decoders.js +9 -1
- package/build/lib/decoders.js.map +1 -1
- package/build/stateful-event-subscriber.d.ts +1 -0
- package/build/stateful-event-subscriber.js +6 -0
- package/build/stateful-event-subscriber.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/algebra/AlgebraFactory-v1_1.abi.json +250 -0
- package/src/abi/api3-proxy.json +46 -0
- package/src/abi/api3-server-v1.json +463 -0
- package/src/abi/quick-perps/fast-price-events.json +70 -0
- package/src/abi/quick-perps/fast-price-feed.json +741 -0
- package/src/abi/quick-perps/reader.json +313 -0
- package/src/abi/quick-perps/vault-price-feed.json +323 -0
- package/src/abi/quick-perps/vault.json +1953 -0
- package/src/composed-event-subscriber.ts +16 -11
- package/src/config.ts +30 -0
- package/src/dex/algebra/algebra-integration.test.ts +122 -0
- package/src/dex/algebra/algebra-pool-v1_1.ts +259 -8
- package/src/dex/algebra/algebra.ts +9 -6
- package/src/dex/algebra/config.ts +1 -0
- package/src/dex/algebra/types.ts +3 -2
- package/src/dex/algebra/utils.ts +83 -2
- package/src/dex/balancer-v2/optimizer.ts +23 -38
- package/src/dex/index.ts +2 -0
- package/src/dex/quick-perps/config.ts +31 -0
- package/src/dex/quick-perps/fast-price-feed.ts +279 -0
- package/src/dex/quick-perps/pool.ts +372 -0
- package/src/dex/quick-perps/quick-perps-e2e.test.ts +65 -0
- package/src/dex/quick-perps/quick-perps-events.test.ts +101 -0
- package/src/dex/quick-perps/quick-perps-integration.test.ts +153 -0
- package/src/dex/quick-perps/quick-perps.ts +292 -0
- package/src/dex/quick-perps/types.ts +97 -0
- package/src/dex/quick-perps/usdq.ts +83 -0
- package/src/dex/quick-perps/vault-price-feed.ts +322 -0
- package/src/dex/quick-perps/vault-utils.ts +53 -0
- package/src/dex/quick-perps/vault.ts +290 -0
- package/src/dex/solidly/forks-override/velodromeV2.ts +4 -2
- package/src/dex/uniswap-v2/nomiswap-v2.ts +2 -1
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +6 -8
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +52 -47
- package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +1 -9
- package/src/dex/uniswap-v3/uniswap-v3.ts +7 -1
- package/src/lib/api3-feed.ts +140 -0
- package/src/lib/decoders.ts +13 -0
- package/src/stateful-event-subscriber.ts +8 -0
- package/tests/constants-e2e.ts +29 -0
- package/tests/tenderly-simulation.ts +46 -2
- package/tests/utils-e2e.ts +18 -10
- package/build/abi/quickPerps/fast-price-events.json +0 -70
- package/build/abi/quickPerps/fast-price-feed.json +0 -748
- package/build/abi/quickPerps/reader.json +0 -313
- package/build/abi/quickPerps/vault-price-feed.json +0 -477
- package/build/abi/quickPerps/vault.json +0 -1953
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
- package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
- package/build/abi/woo-fi/WooPP.abi.json +0 -548
- package/build/abi/woo-fi/Wooracle.abi.json +0 -260
- package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
- package/build/dex/aave-v3/tokens/avalanche.json +0 -74
- package/build/dex/aave-v3/tokens/fantom.json +0 -62
- package/build/dex/aave-v3/tokens/optimism.json +0 -50
- package/build/dex/aave-v3/tokens/polygon.json +0 -116
- package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
- package/build/dex/balancer-v2/LinearMath.js +0 -179
- package/build/dex/balancer-v2/LinearMath.js.map +0 -1
- package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
- package/build/dex/balancer-v2/LinearPool.js +0 -324
- package/build/dex/balancer-v2/LinearPool.js.map +0 -1
- package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
- package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
- package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
- package/build/dex/balancer-v2/StableMath.d.ts +0 -9
- package/build/dex/balancer-v2/StableMath.js +0 -272
- package/build/dex/balancer-v2/StableMath.js.map +0 -1
- package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
- package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
- package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
- package/build/dex/quickswap-v3.d.ts +0 -21
- package/build/dex/quickswap-v3.js +0 -40
- package/build/dex/quickswap-v3.js.map +0 -1
- package/build/dex/test-dex/config.d.ts +0 -4
- package/build/dex/test-dex/config.js +0 -15
- package/build/dex/test-dex/config.js.map +0 -1
- package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
- package/build/dex/test-dex/test-dex-pool.js +0 -63
- package/build/dex/test-dex/test-dex-pool.js.map +0 -1
- package/build/dex/test-dex/test-dex.d.ts +0 -37
- package/build/dex/test-dex/test-dex.js +0 -126
- package/build/dex/test-dex/test-dex.js.map +0 -1
- package/build/dex/test-dex/types.d.ts +0 -6
- package/build/dex/test-dex/types.js +0 -3
- package/build/dex/test-dex/types.js.map +0 -1
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
- package/build/dex/woo-fi/config.d.ts +0 -4
- package/build/dex/woo-fi/config.js +0 -141
- package/build/dex/woo-fi/config.js.map +0 -1
- package/build/dex/woo-fi/constants.d.ts +0 -5
- package/build/dex/woo-fi/constants.js +0 -20
- package/build/dex/woo-fi/constants.js.map +0 -1
- package/build/dex/woo-fi/types.d.ts +0 -48
- package/build/dex/woo-fi/types.js +0 -3
- package/build/dex/woo-fi/types.js.map +0 -1
- package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
- package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
- package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
- package/build/dex/woo-fi/woo-fi-math.js +0 -300
- package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi.d.ts +0 -65
- package/build/dex/woo-fi/woo-fi.js +0 -480
- package/build/dex/woo-fi/woo-fi.js.map +0 -1
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
- package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
- package/src/dex/balancer-v2/balancer-v2-optimizer.test.ts +0 -226
|
@@ -2,7 +2,11 @@ import dotenv from 'dotenv';
|
|
|
2
2
|
dotenv.config();
|
|
3
3
|
|
|
4
4
|
import { testE2E } from '../../../tests/utils-e2e';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Tokens,
|
|
7
|
+
Holders,
|
|
8
|
+
NativeTokenSymbols,
|
|
9
|
+
} from '../../../tests/constants-e2e';
|
|
6
10
|
import { Network, ContractMethod, SwapSide } from '../../constants';
|
|
7
11
|
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
8
12
|
import { generateConfig } from '../../config';
|
|
@@ -34,13 +38,7 @@ function testForNetwork(
|
|
|
34
38
|
ContractMethod.megaSwap,
|
|
35
39
|
],
|
|
36
40
|
],
|
|
37
|
-
[
|
|
38
|
-
SwapSide.BUY,
|
|
39
|
-
[
|
|
40
|
-
ContractMethod.simpleBuy,
|
|
41
|
-
ContractMethod.buy,
|
|
42
|
-
],
|
|
43
|
-
],
|
|
41
|
+
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
44
42
|
]);
|
|
45
43
|
|
|
46
44
|
describe(`${network}`, () => {
|
|
@@ -113,7 +113,6 @@ function testForNetwork(
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
describe('UniswapV3 E2E', () => {
|
|
116
|
-
|
|
117
116
|
describe('UniswapV3', () => {
|
|
118
117
|
const dexKey = 'UniswapV3';
|
|
119
118
|
|
|
@@ -790,32 +789,33 @@ describe('UniswapV3 E2E', () => {
|
|
|
790
789
|
],
|
|
791
790
|
]);
|
|
792
791
|
|
|
793
|
-
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
794
|
-
[
|
|
795
|
-
{
|
|
796
|
-
name: 'USDC',
|
|
797
|
-
sellAmount: '100000000000000000000',
|
|
798
|
-
buyAmount: '100000000000000000000',
|
|
799
|
-
},
|
|
800
|
-
{
|
|
801
|
-
name: 'USDT',
|
|
802
|
-
sellAmount: '100000000000000000000',
|
|
803
|
-
buyAmount: '100000000000000000000',
|
|
804
|
-
},
|
|
805
|
-
],
|
|
792
|
+
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
806
793
|
[
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
794
|
+
[
|
|
795
|
+
{
|
|
796
|
+
name: 'USDC',
|
|
797
|
+
sellAmount: '100000000000000000000',
|
|
798
|
+
buyAmount: '100000000000000000000',
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
name: 'USDT',
|
|
802
|
+
sellAmount: '100000000000000000000',
|
|
803
|
+
buyAmount: '100000000000000000000',
|
|
804
|
+
},
|
|
805
|
+
],
|
|
806
|
+
[
|
|
807
|
+
{
|
|
808
|
+
name: 'BNB',
|
|
809
|
+
sellAmount: '1000000000000000000',
|
|
810
|
+
buyAmount: '10000000000000000000',
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
name: 'USDT',
|
|
814
|
+
sellAmount: '1000000000000000000000',
|
|
815
|
+
buyAmount: '20000000000000000',
|
|
816
|
+
},
|
|
817
|
+
],
|
|
818
|
+
];
|
|
819
819
|
|
|
820
820
|
sideToContractMethods.forEach((contractMethods, side) =>
|
|
821
821
|
describe(`${side}`, () => {
|
|
@@ -909,28 +909,33 @@ describe('UniswapV3 E2E', () => {
|
|
|
909
909
|
],
|
|
910
910
|
]);
|
|
911
911
|
|
|
912
|
-
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
913
|
-
[
|
|
914
|
-
{
|
|
915
|
-
name: 'FTM',
|
|
916
|
-
sellAmount: '100000000000000000',
|
|
917
|
-
buyAmount: '100000000',
|
|
918
|
-
},
|
|
919
|
-
{
|
|
920
|
-
name: 'USDC',
|
|
921
|
-
sellAmount: '100000000',
|
|
922
|
-
buyAmount: '100000000000000000',
|
|
923
|
-
},
|
|
924
|
-
],
|
|
912
|
+
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
925
913
|
[
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
914
|
+
[
|
|
915
|
+
{
|
|
916
|
+
name: 'FTM',
|
|
917
|
+
sellAmount: '100000000000000000',
|
|
918
|
+
buyAmount: '100000000',
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
name: 'USDC',
|
|
922
|
+
sellAmount: '100000000',
|
|
923
|
+
buyAmount: '100000000000000000',
|
|
924
|
+
},
|
|
925
|
+
],
|
|
926
|
+
[
|
|
927
|
+
{
|
|
928
|
+
name: 'WFTM',
|
|
929
|
+
sellAmount: '100000000000000',
|
|
930
|
+
buyAmount: '1000000000000000',
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
name: 'WETH',
|
|
934
|
+
sellAmount: '1000000000000000',
|
|
935
|
+
buyAmount: '100000000000000',
|
|
936
|
+
},
|
|
937
|
+
],
|
|
938
|
+
];
|
|
934
939
|
|
|
935
940
|
sideToContractMethods.forEach((contractMethods, side) =>
|
|
936
941
|
describe(`${side}`, () => {
|
|
@@ -629,15 +629,10 @@ describe('ChronosV3', () => {
|
|
|
629
629
|
beforeEach(async () => {
|
|
630
630
|
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
631
631
|
uniswapV3 = new UniswapV3(network, dexKey, dexHelper);
|
|
632
|
-
uniswapV3Mainnet = new UniswapV3(
|
|
633
|
-
Network.ARBITRUM,
|
|
634
|
-
dexKey,
|
|
635
|
-
dexHelper,
|
|
636
|
-
);
|
|
632
|
+
uniswapV3Mainnet = new UniswapV3(Network.ARBITRUM, dexKey, dexHelper);
|
|
637
633
|
});
|
|
638
634
|
|
|
639
635
|
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
640
|
-
|
|
641
636
|
const amounts = [0n, BI_POWS[6], 2000000n];
|
|
642
637
|
|
|
643
638
|
const pools = await uniswapV3.getPoolIdentifiers(
|
|
@@ -687,7 +682,6 @@ describe('ChronosV3', () => {
|
|
|
687
682
|
});
|
|
688
683
|
|
|
689
684
|
it('getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
690
|
-
|
|
691
685
|
const amounts = [0n, BI_POWS[6], 2000000n];
|
|
692
686
|
|
|
693
687
|
const pools = await uniswapV3.getPoolIdentifiers(
|
|
@@ -964,7 +958,5 @@ describe('SushiSwapV3', () => {
|
|
|
964
958
|
|
|
965
959
|
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
966
960
|
});
|
|
967
|
-
|
|
968
961
|
});
|
|
969
962
|
});
|
|
970
|
-
|
|
@@ -91,7 +91,13 @@ export class UniswapV3
|
|
|
91
91
|
|
|
92
92
|
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
93
93
|
getDexKeysWithNetwork(
|
|
94
|
-
_.pick(UniswapV3Config, [
|
|
94
|
+
_.pick(UniswapV3Config, [
|
|
95
|
+
'UniswapV3',
|
|
96
|
+
'SushiSwapV3',
|
|
97
|
+
'QuickSwapV3.1',
|
|
98
|
+
'RamsesV2',
|
|
99
|
+
'ChronosV3',
|
|
100
|
+
]),
|
|
95
101
|
);
|
|
96
102
|
|
|
97
103
|
logger: Logger;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
+
import { PartialEventSubscriber } from '../composed-event-subscriber';
|
|
3
|
+
import {
|
|
4
|
+
Address,
|
|
5
|
+
BlockHeader,
|
|
6
|
+
Log,
|
|
7
|
+
Logger,
|
|
8
|
+
MultiCallInput,
|
|
9
|
+
MultiCallOutput,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import { Lens } from '../lens';
|
|
12
|
+
import { Interface } from '@ethersproject/abi';
|
|
13
|
+
import ProxyABI from '../abi/api3-proxy.json';
|
|
14
|
+
import Api3ServerV1ABI from '../abi/api3-server-v1.json';
|
|
15
|
+
|
|
16
|
+
export type Api3FeedSubscriberState = {
|
|
17
|
+
value: bigint;
|
|
18
|
+
timestamp: bigint;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class Api3FeedSubscriber<State> extends PartialEventSubscriber<
|
|
22
|
+
State,
|
|
23
|
+
Api3FeedSubscriberState
|
|
24
|
+
> {
|
|
25
|
+
static readonly proxyInterface = new Interface(ProxyABI);
|
|
26
|
+
static readonly api3ServerV1Iface = new Interface(Api3ServerV1ABI);
|
|
27
|
+
static readonly ANSWER_UPDATED_SIGNED_DATA =
|
|
28
|
+
Api3FeedSubscriber.api3ServerV1Iface.getEventTopic(
|
|
29
|
+
'UpdatedBeaconWithSignedData',
|
|
30
|
+
);
|
|
31
|
+
static readonly ANSWER_UPDATED_BEACON_SET_DATA =
|
|
32
|
+
Api3FeedSubscriber.api3ServerV1Iface.getEventTopic(
|
|
33
|
+
'UpdatedBeaconSetWithBeacons',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
private proxy: Address,
|
|
38
|
+
api3Server: Address,
|
|
39
|
+
private dataFeedId: string,
|
|
40
|
+
lens: Lens<DeepReadonly<State>, DeepReadonly<Api3FeedSubscriberState>>,
|
|
41
|
+
logger: Logger,
|
|
42
|
+
) {
|
|
43
|
+
super([api3Server], lens, logger);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static getApi3ServerV1MultiCallInput(proxy: Address): MultiCallInput {
|
|
47
|
+
return {
|
|
48
|
+
target: proxy,
|
|
49
|
+
callData:
|
|
50
|
+
Api3FeedSubscriber.proxyInterface.encodeFunctionData('api3ServerV1'),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static getDataFeedId(proxy: Address): MultiCallInput {
|
|
55
|
+
return {
|
|
56
|
+
target: proxy,
|
|
57
|
+
callData:
|
|
58
|
+
Api3FeedSubscriber.proxyInterface.encodeFunctionData('dataFeedId'),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static decodeDataFeedId(multicallOutput: MultiCallOutput) {
|
|
63
|
+
return Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
|
|
64
|
+
'dataFeedId',
|
|
65
|
+
multicallOutput,
|
|
66
|
+
)[0];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static decodeApi3ServerV1Result(multicallOutput: MultiCallOutput): Address {
|
|
70
|
+
return Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
|
|
71
|
+
'api3ServerV1',
|
|
72
|
+
multicallOutput,
|
|
73
|
+
)[0];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public processLog(
|
|
77
|
+
state: DeepReadonly<Api3FeedSubscriberState>,
|
|
78
|
+
log: Readonly<Log>,
|
|
79
|
+
blockHeader: Readonly<BlockHeader>,
|
|
80
|
+
): DeepReadonly<Api3FeedSubscriberState> | null {
|
|
81
|
+
if (log.topics[0] === Api3FeedSubscriber.ANSWER_UPDATED_SIGNED_DATA) {
|
|
82
|
+
const decoded = Api3FeedSubscriber.api3ServerV1Iface.decodeEventLog(
|
|
83
|
+
'UpdatedBeaconWithSignedData',
|
|
84
|
+
log.data,
|
|
85
|
+
log.topics,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (decoded.beaconId !== this.dataFeedId) return null;
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
value: BigInt(decoded.value.toString()),
|
|
92
|
+
timestamp: BigInt(decoded.timestamp.toString()),
|
|
93
|
+
};
|
|
94
|
+
} else if (
|
|
95
|
+
log.topics[0] === Api3FeedSubscriber.ANSWER_UPDATED_BEACON_SET_DATA
|
|
96
|
+
) {
|
|
97
|
+
const decoded = Api3FeedSubscriber.api3ServerV1Iface.decodeEventLog(
|
|
98
|
+
'UpdatedBeaconSetWithBeacons',
|
|
99
|
+
log.data,
|
|
100
|
+
log.topics,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (decoded.beaconSetId !== this.dataFeedId) return null;
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
value: BigInt(decoded.value.toString()),
|
|
107
|
+
timestamp: BigInt(decoded.timestamp.toString()),
|
|
108
|
+
};
|
|
109
|
+
} else {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public getGenerateStateMultiCallInputs(): MultiCallInput[] {
|
|
115
|
+
return [
|
|
116
|
+
{
|
|
117
|
+
target: this.proxy,
|
|
118
|
+
callData: Api3FeedSubscriber.proxyInterface.encodeFunctionData('read'),
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public generateState(
|
|
124
|
+
multicallOutputs: MultiCallOutput[],
|
|
125
|
+
blockNumber?: number | 'latest',
|
|
126
|
+
): DeepReadonly<Api3FeedSubscriberState> {
|
|
127
|
+
const decoded = Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
|
|
128
|
+
'read',
|
|
129
|
+
multicallOutputs[0],
|
|
130
|
+
);
|
|
131
|
+
return {
|
|
132
|
+
value: BigInt(decoded.value.toString()),
|
|
133
|
+
timestamp: BigInt(decoded.timestamp.toString()),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public getLatestData(state: DeepReadonly<State>): bigint {
|
|
138
|
+
return this.lens.get()(state).value;
|
|
139
|
+
}
|
|
140
|
+
}
|
package/src/lib/decoders.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Result } from '@ethersproject/abi';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { BigNumber as EthersBigNumber } from 'ethers';
|
|
3
4
|
import { BytesLike, defaultAbiCoder } from 'ethers/lib/utils';
|
|
4
5
|
import _, { parseInt } from 'lodash';
|
|
5
6
|
import { BN_0 } from '../bignumber-constants';
|
|
@@ -50,6 +51,18 @@ export const uint256ToBigInt = (
|
|
|
50
51
|
return generalDecoder(result, ['uint256'], 0n, value => value[0].toBigInt());
|
|
51
52
|
};
|
|
52
53
|
|
|
54
|
+
export const uint128ToBigNumber = (
|
|
55
|
+
result: MultiResult<BytesLike> | BytesLike,
|
|
56
|
+
): EthersBigNumber => {
|
|
57
|
+
return generalDecoder(result, ['uint128'], 0n, value => value[0]);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const int24ToNumber = (
|
|
61
|
+
result: MultiResult<BytesLike> | BytesLike,
|
|
62
|
+
): number => {
|
|
63
|
+
return generalDecoder(result, ['int24'], 0n, value => value[0]);
|
|
64
|
+
};
|
|
65
|
+
|
|
53
66
|
export const uint256ArrayDecode = (
|
|
54
67
|
result: MultiResult<BytesLike> | BytesLike,
|
|
55
68
|
): bigint => {
|
|
@@ -18,6 +18,7 @@ type StateCache<State> = {
|
|
|
18
18
|
export type InitializeStateOptions<State> = {
|
|
19
19
|
state?: DeepReadonly<State>;
|
|
20
20
|
initCallback?: (state: DeepReadonly<State>) => void;
|
|
21
|
+
forceRegenerate?: boolean;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
export abstract class StatefulEventSubscriber<State>
|
|
@@ -89,6 +90,13 @@ export abstract class StatefulEventSubscriber<State>
|
|
|
89
90
|
let masterBn: undefined | number = undefined;
|
|
90
91
|
if (options && options.state) {
|
|
91
92
|
this.setState(options.state, blockNumber);
|
|
93
|
+
} else if (options && options.forceRegenerate) {
|
|
94
|
+
// ZkEVM forces to always regenerate state when it is old
|
|
95
|
+
this.logger.debug(
|
|
96
|
+
`${this.parentName}: ${this.name}: forced to regenerate state`,
|
|
97
|
+
);
|
|
98
|
+
const state = await this.generateState(blockNumber);
|
|
99
|
+
this.setState(state, blockNumber);
|
|
92
100
|
} else {
|
|
93
101
|
if (this.dexHelper.config.isSlave && this.masterPoolNeeded) {
|
|
94
102
|
let stateAsString = await this.dexHelper.cache.hget(
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -861,6 +861,28 @@ export const Tokens: {
|
|
|
861
861
|
decimals: 8,
|
|
862
862
|
},
|
|
863
863
|
},
|
|
864
|
+
[Network.ZKEVM]: {
|
|
865
|
+
ETH: {
|
|
866
|
+
address: ETHER_ADDRESS,
|
|
867
|
+
decimals: 18,
|
|
868
|
+
},
|
|
869
|
+
WETH: {
|
|
870
|
+
address: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9',
|
|
871
|
+
decimals: 18,
|
|
872
|
+
},
|
|
873
|
+
MATIC: {
|
|
874
|
+
address: '0xa2036f0538221a77a3937f1379699f44945018d0',
|
|
875
|
+
decimals: 18,
|
|
876
|
+
},
|
|
877
|
+
WBTC: {
|
|
878
|
+
address: '0xea034fb02eb1808c2cc3adbc15f447b93cbe08e1',
|
|
879
|
+
decimals: 8,
|
|
880
|
+
},
|
|
881
|
+
USDC: {
|
|
882
|
+
address: '0xa8ce8aee21bc2a48a5ef670afcc9274c7bbbc035',
|
|
883
|
+
decimals: 6,
|
|
884
|
+
},
|
|
885
|
+
},
|
|
864
886
|
};
|
|
865
887
|
|
|
866
888
|
export const Holders: {
|
|
@@ -1073,6 +1095,13 @@ export const Holders: {
|
|
|
1073
1095
|
rETH: '0x4c2e69e58b14de9afedfb94319519ce34e087283',
|
|
1074
1096
|
WBTC: '0xb9c8f0d3254007ee4b98970b94544e473cd610ec',
|
|
1075
1097
|
},
|
|
1098
|
+
[Network.ZKEVM]: {
|
|
1099
|
+
ETH: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9',
|
|
1100
|
+
WETH: '0xc44ad482f24fd750caeba387d2726d8653f8c4bb',
|
|
1101
|
+
MATIC: '0x8f2a1450c040b3c19efe9676165d8f30d8280019',
|
|
1102
|
+
WBTC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c',
|
|
1103
|
+
USDC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c',
|
|
1104
|
+
},
|
|
1076
1105
|
};
|
|
1077
1106
|
|
|
1078
1107
|
export const SmartTokens = Object.keys(Tokens).reduce((acc, _network) => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
import axios from 'axios';
|
|
2
3
|
import { Address } from '@paraswap/core';
|
|
4
|
+
import { Provider } from '@ethersproject/providers';
|
|
3
5
|
import { TxObject } from '../src/types';
|
|
4
6
|
import { StateOverrides, StateSimulateApiOverride } from './smart-tokens';
|
|
5
7
|
|
|
@@ -9,7 +11,50 @@ const TENDERLY_PROJECT = process.env.TENDERLY_PROJECT;
|
|
|
9
11
|
const TENDERLY_FORK_ID = process.env.TENDERLY_FORK_ID;
|
|
10
12
|
const TENDERLY_FORK_LAST_TX_ID = process.env.TENDERLY_FORK_LAST_TX_ID;
|
|
11
13
|
|
|
12
|
-
export
|
|
14
|
+
export type SimulationResult = {
|
|
15
|
+
success: boolean;
|
|
16
|
+
gasUsed?: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
transaction?: any;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export interface TransactionSimulator {
|
|
22
|
+
forkId: string;
|
|
23
|
+
setup(): Promise<void>;
|
|
24
|
+
|
|
25
|
+
simulate(
|
|
26
|
+
params: TxObject,
|
|
27
|
+
stateOverrides?: StateOverrides,
|
|
28
|
+
): Promise<SimulationResult>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class EstimateGasSimulation implements TransactionSimulator {
|
|
32
|
+
forkId: string = '0';
|
|
33
|
+
|
|
34
|
+
constructor(private provider: Provider) {}
|
|
35
|
+
|
|
36
|
+
async setup() {}
|
|
37
|
+
|
|
38
|
+
async simulate(
|
|
39
|
+
params: TxObject,
|
|
40
|
+
_: StateOverrides,
|
|
41
|
+
): Promise<SimulationResult> {
|
|
42
|
+
try {
|
|
43
|
+
const result = await this.provider.estimateGas(params);
|
|
44
|
+
return {
|
|
45
|
+
success: true,
|
|
46
|
+
gasUsed: result.toNumber().toString(),
|
|
47
|
+
};
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error(`Estimate gas simulation failed:`, e);
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class TenderlySimulation implements TransactionSimulator {
|
|
13
58
|
lastTx: string = '';
|
|
14
59
|
forkId: string = '';
|
|
15
60
|
maxGasLimit = 80000000;
|
|
@@ -118,7 +163,6 @@ export class TenderlySimulation {
|
|
|
118
163
|
console.error(`TenderlySimulation_simulate:`, e);
|
|
119
164
|
return {
|
|
120
165
|
success: false,
|
|
121
|
-
tenderlyUrl: '',
|
|
122
166
|
};
|
|
123
167
|
}
|
|
124
168
|
}
|
package/tests/utils-e2e.ts
CHANGED
|
@@ -5,7 +5,11 @@ import {
|
|
|
5
5
|
IParaSwapSDK,
|
|
6
6
|
LocalParaswapSDK,
|
|
7
7
|
} from '../src/implementations/local-paraswap-sdk';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
EstimateGasSimulation,
|
|
10
|
+
TenderlySimulation,
|
|
11
|
+
TransactionSimulator,
|
|
12
|
+
} from './tenderly-simulation';
|
|
9
13
|
import {
|
|
10
14
|
SwapSide,
|
|
11
15
|
ETHER_ADDRESS,
|
|
@@ -24,7 +28,7 @@ import {
|
|
|
24
28
|
import Erc20ABI from '../src/abi/erc20.json';
|
|
25
29
|
import AugustusABI from '../src/abi/augustus.json';
|
|
26
30
|
import { generateConfig } from '../src/config';
|
|
27
|
-
import { DummyLimitOrderProvider } from '../src/dex-helper';
|
|
31
|
+
import { DummyDexHelper, DummyLimitOrderProvider } from '../src/dex-helper';
|
|
28
32
|
import { constructSimpleSDK, SimpleFetchSDK } from '@paraswap/sdk';
|
|
29
33
|
import axios from 'axios';
|
|
30
34
|
import { SmartToken, StateOverrides } from './smart-tokens';
|
|
@@ -268,16 +272,20 @@ export async function testE2E(
|
|
|
268
272
|
// Specified in BPS: part of 10000
|
|
269
273
|
slippage?: number,
|
|
270
274
|
sleepMs?: number,
|
|
275
|
+
replaceTenderlyWithEstimateGas?: boolean,
|
|
271
276
|
) {
|
|
272
277
|
const amount = BigInt(_amount);
|
|
273
|
-
|
|
278
|
+
|
|
279
|
+
const ts: TransactionSimulator = replaceTenderlyWithEstimateGas
|
|
280
|
+
? new EstimateGasSimulation(new DummyDexHelper(network).provider)
|
|
281
|
+
: new TenderlySimulation(network);
|
|
274
282
|
await ts.setup();
|
|
275
283
|
|
|
276
284
|
if (srcToken.address.toLowerCase() !== ETHER_ADDRESS.toLowerCase()) {
|
|
277
285
|
const allowanceTx = await ts.simulate(
|
|
278
286
|
allowTokenTransferProxyParams(srcToken.address, senderAddress, network),
|
|
279
287
|
);
|
|
280
|
-
if (!allowanceTx.success) console.log(allowanceTx.
|
|
288
|
+
if (!allowanceTx.success) console.log(allowanceTx.url);
|
|
281
289
|
expect(allowanceTx!.success).toEqual(true);
|
|
282
290
|
}
|
|
283
291
|
|
|
@@ -309,7 +317,7 @@ export async function testE2E(
|
|
|
309
317
|
expect(deployTx.success).toEqual(true);
|
|
310
318
|
|
|
311
319
|
const contractAddress =
|
|
312
|
-
deployTx.transaction
|
|
320
|
+
deployTx.transaction?.transaction_info.contract_address;
|
|
313
321
|
console.log(
|
|
314
322
|
formatDeployMessage(
|
|
315
323
|
'adapter',
|
|
@@ -384,15 +392,15 @@ export async function testE2E(
|
|
|
384
392
|
|
|
385
393
|
const swapTx = await ts.simulate(swapParams);
|
|
386
394
|
// Only log gas estimate if testing against API
|
|
387
|
-
if (useAPI)
|
|
395
|
+
if (useAPI) {
|
|
396
|
+
const gasUsed = swapTx.gasUsed || '0';
|
|
388
397
|
console.log(
|
|
389
398
|
`Gas Estimate API: ${priceRoute.gasCost}, Simulated: ${
|
|
390
399
|
swapTx!.gasUsed
|
|
391
|
-
}, Difference: ${
|
|
392
|
-
parseInt(priceRoute.gasCost) - parseInt(swapTx!.gasUsed)
|
|
393
|
-
}`,
|
|
400
|
+
}, Difference: ${parseInt(priceRoute.gasCost) - parseInt(gasUsed)}`,
|
|
394
401
|
);
|
|
395
|
-
|
|
402
|
+
}
|
|
403
|
+
console.log(`Tenderly URL: ${swapTx!.url}`);
|
|
396
404
|
expect(swapTx!.success).toEqual(true);
|
|
397
405
|
} finally {
|
|
398
406
|
if (paraswap.releaseResources) {
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"anonymous": false,
|
|
4
|
-
"inputs": [
|
|
5
|
-
{
|
|
6
|
-
"indexed": false,
|
|
7
|
-
"internalType": "address",
|
|
8
|
-
"name": "token",
|
|
9
|
-
"type": "address"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"indexed": false,
|
|
13
|
-
"internalType": "uint256",
|
|
14
|
-
"name": "price",
|
|
15
|
-
"type": "uint256"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"indexed": false,
|
|
19
|
-
"internalType": "address",
|
|
20
|
-
"name": "priceFeed",
|
|
21
|
-
"type": "address"
|
|
22
|
-
}
|
|
23
|
-
],
|
|
24
|
-
"name": "PriceUpdate",
|
|
25
|
-
"type": "event"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"inputs": [
|
|
29
|
-
{ "internalType": "address", "name": "_token", "type": "address" },
|
|
30
|
-
{ "internalType": "uint256", "name": "_price", "type": "uint256" }
|
|
31
|
-
],
|
|
32
|
-
"name": "emitPriceEvent",
|
|
33
|
-
"outputs": [],
|
|
34
|
-
"stateMutability": "nonpayable",
|
|
35
|
-
"type": "function"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"inputs": [],
|
|
39
|
-
"name": "gov",
|
|
40
|
-
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
41
|
-
"stateMutability": "view",
|
|
42
|
-
"type": "function"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
46
|
-
"name": "isPriceFeed",
|
|
47
|
-
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
|
|
48
|
-
"stateMutability": "view",
|
|
49
|
-
"type": "function"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"inputs": [
|
|
53
|
-
{ "internalType": "address", "name": "_gov", "type": "address" }
|
|
54
|
-
],
|
|
55
|
-
"name": "setGov",
|
|
56
|
-
"outputs": [],
|
|
57
|
-
"stateMutability": "nonpayable",
|
|
58
|
-
"type": "function"
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
"inputs": [
|
|
62
|
-
{ "internalType": "address", "name": "_priceFeed", "type": "address" },
|
|
63
|
-
{ "internalType": "bool", "name": "_isPriceFeed", "type": "bool" }
|
|
64
|
-
],
|
|
65
|
-
"name": "setIsPriceFeed",
|
|
66
|
-
"outputs": [],
|
|
67
|
-
"stateMutability": "nonpayable",
|
|
68
|
-
"type": "function"
|
|
69
|
-
}
|
|
70
|
-
]
|