@paraswap/dex-lib 2.47.5 → 2.47.7
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/balancer-v2/gyro-e.abi.json +1595 -0
- package/build/dex/balancer-v2/balancer-v2.d.ts +6 -3
- package/build/dex/balancer-v2/balancer-v2.js +56 -35
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.d.ts +32 -0
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js +149 -0
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js.map +1 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.d.ts +37 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.js +222 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -0
- package/build/dex/balancer-v2/pools/gyro/gyro-helpers.d.ts +2 -0
- package/build/dex/balancer-v2/pools/gyro/gyro-helpers.js +19 -0
- package/build/dex/balancer-v2/pools/gyro/gyro-helpers.js.map +1 -0
- package/build/dex/balancer-v2/queryOnChain.d.ts +1 -0
- package/build/dex/balancer-v2/queryOnChain.js +40 -0
- package/build/dex/balancer-v2/queryOnChain.js.map +1 -0
- package/build/dex/balancer-v2/types.d.ts +24 -1
- package/build/dex/balancer-v2/types.js +2 -0
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/balancer-v2/utils.d.ts +8 -0
- package/build/dex/balancer-v2/utils.js +17 -1
- package/build/dex/balancer-v2/utils.js.map +1 -1
- package/package.json +2 -1
- package/src/abi/balancer-v2/gyro-e.abi.json +1595 -0
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +94 -0
- package/src/dex/balancer-v2/balancer-v2-gyro3.test.ts +268 -0
- package/src/dex/balancer-v2/balancer-v2-gyroE.test.ts +401 -0
- package/src/dex/balancer-v2/balancer-v2-integration.test.ts +253 -112
- package/src/dex/balancer-v2/balancer-v2.ts +107 -67
- package/src/dex/balancer-v2/pools/gyro/Gyro3Pool.ts +255 -0
- package/src/dex/balancer-v2/pools/gyro/GyroEPool.ts +403 -0
- package/src/dex/balancer-v2/pools/gyro/gyro-helpers.ts +15 -0
- package/src/dex/balancer-v2/queryOnChain.ts +48 -0
- package/src/dex/balancer-v2/types.ts +26 -0
- package/src/dex/balancer-v2/utils.ts +16 -0
- package/src/dex/synthetix/synthetix-state.ts +2 -2
- package/tests/constants-e2e.ts +26 -0
- package/build/abi/Redstone.json +0 -739
- package/build/abi/angle/stagToken.json +0 -963
- package/build/abi/angle-transmuter/Pyth.json +0 -1534
- package/build/abi/angle-transmuter/Transmuter.json +0 -1719
- package/build/abi/smardex/smardex-factory.json +0 -185
- package/build/abi/smardex/smardex-pool.json +0 -578
- package/build/abi/smardex/smardex-router.json +0 -648
- package/build/abi/trader-joe-v2_1/FactoryABI.json +0 -1208
- package/build/abi/trader-joe-v2_1/PairABI.json +0 -1493
- package/build/abi/trader-joe-v2_1/RouterABI.json +0 -1489
- package/build/abi/trader-joe-v2_1/StateMulticall.json +0 -193
- package/build/abi/wombat/pool.json +0 -1289
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.d.ts +0 -53
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.js +0 -175
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.js.map +0 -1
- package/build/dex/angle-staked-stable/angle-staked-stable.d.ts +0 -42
- package/build/dex/angle-staked-stable/angle-staked-stable.js +0 -232
- package/build/dex/angle-staked-stable/angle-staked-stable.js.map +0 -1
- package/build/dex/angle-staked-stable/config.d.ts +0 -4
- package/build/dex/angle-staked-stable/config.js +0 -26
- package/build/dex/angle-staked-stable/config.js.map +0 -1
- package/build/dex/angle-staked-stable/types.d.ts +0 -15
- package/build/dex/angle-staked-stable/types.js +0 -3
- package/build/dex/angle-staked-stable/types.js.map +0 -1
- package/build/dex/angle-transmuter/angle-transmuter-pool.d.ts +0 -43
- package/build/dex/angle-transmuter/angle-transmuter-pool.js +0 -309
- package/build/dex/angle-transmuter/angle-transmuter-pool.js.map +0 -1
- package/build/dex/angle-transmuter/angle-transmuter.d.ts +0 -46
- package/build/dex/angle-transmuter/angle-transmuter.js +0 -233
- package/build/dex/angle-transmuter/angle-transmuter.js.map +0 -1
- package/build/dex/angle-transmuter/backedOracle.d.ts +0 -19
- package/build/dex/angle-transmuter/backedOracle.js +0 -56
- package/build/dex/angle-transmuter/backedOracle.js.map +0 -1
- package/build/dex/angle-transmuter/config.d.ts +0 -4
- package/build/dex/angle-transmuter/config.js +0 -20
- package/build/dex/angle-transmuter/config.js.map +0 -1
- package/build/dex/angle-transmuter/constants.d.ts +0 -4
- package/build/dex/angle-transmuter/constants.js +0 -8
- package/build/dex/angle-transmuter/constants.js.map +0 -1
- package/build/dex/angle-transmuter/pyth.d.ts +0 -19
- package/build/dex/angle-transmuter/pyth.js +0 -71
- package/build/dex/angle-transmuter/pyth.js.map +0 -1
- package/build/dex/angle-transmuter/redstone.d.ts +0 -20
- package/build/dex/angle-transmuter/redstone.js +0 -73
- package/build/dex/angle-transmuter/redstone.js.map +0 -1
- package/build/dex/angle-transmuter/transmuter.d.ts +0 -50
- package/build/dex/angle-transmuter/transmuter.js +0 -314
- package/build/dex/angle-transmuter/transmuter.js.map +0 -1
- package/build/dex/angle-transmuter/types.d.ts +0 -144
- package/build/dex/angle-transmuter/types.js +0 -31
- package/build/dex/angle-transmuter/types.js.map +0 -1
- package/build/dex/angle-transmuter/utils.d.ts +0 -9
- package/build/dex/angle-transmuter/utils.js +0 -264
- package/build/dex/angle-transmuter/utils.js.map +0 -1
- package/build/dex/smardex/subgraph-queries.d.ts +0 -1
- package/build/dex/smardex/subgraph-queries.js +0 -17
- package/build/dex/smardex/subgraph-queries.js.map +0 -1
- package/build/dex/smardex/usd-reserves.d.ts +0 -23
- package/build/dex/smardex/usd-reserves.js +0 -86
- package/build/dex/smardex/usd-reserves.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/config.d.ts +0 -4
- package/build/dex/trader-joe-v2-1-2/config.js +0 -47
- package/build/dex/trader-joe-v2-1-2/config.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/constants.d.ts +0 -20
- package/build/dex/trader-joe-v2-1-2/constants.js +0 -22
- package/build/dex/trader-joe-v2-1-2/constants.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/math/index.d.ts +0 -37
- package/build/dex/trader-joe-v2-1-2/math/index.js +0 -291
- package/build/dex/trader-joe-v2-1-2/math/index.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.d.ts +0 -60
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js +0 -248
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.d.ts +0 -53
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js +0 -307
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/types.d.ts +0 -82
- package/build/dex/trader-joe-v2-1-2/types.js +0 -9
- package/build/dex/trader-joe-v2-1-2/types.js.map +0 -1
- package/build/dex/trader-joe-v2_1/config.d.ts +0 -4
- package/build/dex/trader-joe-v2_1/config.js +0 -47
- package/build/dex/trader-joe-v2_1/config.js.map +0 -1
- package/build/dex/trader-joe-v2_1/constants.d.ts +0 -20
- package/build/dex/trader-joe-v2_1/constants.js +0 -22
- package/build/dex/trader-joe-v2_1/constants.js.map +0 -1
- package/build/dex/trader-joe-v2_1/math/index.d.ts +0 -37
- package/build/dex/trader-joe-v2_1/math/index.js +0 -291
- package/build/dex/trader-joe-v2_1/math/index.js.map +0 -1
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.d.ts +0 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js +0 -384
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js.map +0 -1
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.d.ts +0 -60
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.js +0 -247
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.js.map +0 -1
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.d.ts +0 -53
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.js +0 -307
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.js.map +0 -1
- package/build/dex/trader-joe-v2_1/types.d.ts +0 -82
- package/build/dex/trader-joe-v2_1/types.js +0 -9
- package/build/dex/trader-joe-v2_1/types.js.map +0 -1
- package/build/dex/wombat/wombat-pool-poller.d.ts +0 -22
- package/build/dex/wombat/wombat-pool-poller.js +0 -164
- package/build/dex/wombat/wombat-pool-poller.js.map +0 -1
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
// npx jest src/dex/balancer-v2/balancer-v2-gyroE.test.ts
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
dotenv.config();
|
|
5
|
+
|
|
6
|
+
import { Interface } from '@ethersproject/abi';
|
|
7
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
8
|
+
|
|
9
|
+
import { Tokens } from '../../../tests/constants-e2e';
|
|
10
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
11
|
+
import { Network, SwapSide } from '../../constants';
|
|
12
|
+
import { BalancerV2EventPool } from './balancer-v2';
|
|
13
|
+
import { BalancerConfig } from './config';
|
|
14
|
+
import { PoolState, SubgraphPoolBase } from './types';
|
|
15
|
+
import { GyroEPool, GyroEPoolPairData } from './pools/gyro/GyroEPool';
|
|
16
|
+
import { queryOnChain } from './queryOnChain';
|
|
17
|
+
import VaultABI from '../../abi/balancer-v2/vault.json';
|
|
18
|
+
|
|
19
|
+
const rpcUrl = process.env.HTTP_PROVIDER_137 as string;
|
|
20
|
+
|
|
21
|
+
describe('BalancerV2', () => {
|
|
22
|
+
const dexKey = 'BalancerV2';
|
|
23
|
+
const network = Network.POLYGON;
|
|
24
|
+
const config = BalancerConfig[dexKey][network];
|
|
25
|
+
const vaultInterface = new Interface(VaultABI);
|
|
26
|
+
const gyroEPool = new GyroEPool(config.vaultAddress, vaultInterface);
|
|
27
|
+
const tokens = Tokens[network];
|
|
28
|
+
let GyroEPoolSg: SubgraphPoolBase;
|
|
29
|
+
let GyroEPoolState: PoolState;
|
|
30
|
+
const dexHelper = new DummyDexHelper(network);
|
|
31
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
32
|
+
const balancerPools = new BalancerV2EventPool(
|
|
33
|
+
dexKey,
|
|
34
|
+
network,
|
|
35
|
+
config.vaultAddress,
|
|
36
|
+
config.subgraphURL,
|
|
37
|
+
dexHelper,
|
|
38
|
+
logger,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
describe('GyroE Pool V1', () => {
|
|
42
|
+
describe('Pool Fetching', () => {
|
|
43
|
+
it('should be supported pool type', async function () {
|
|
44
|
+
expect(balancerPools.isSupportedPool('GyroE')).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should fetch GyroE Pool with correct fields from Subgraph', async function () {
|
|
48
|
+
const pools = await balancerPools.fetchAllSubgraphPools();
|
|
49
|
+
// USDC/TUSD
|
|
50
|
+
const GyroEPoolId =
|
|
51
|
+
'0x97469e6236bd467cd147065f77752b00efadce8a0002000000000000000008c0';
|
|
52
|
+
const GyroE = pools.filter(p => p.id === GyroEPoolId);
|
|
53
|
+
expect(GyroE.length).toBe(1);
|
|
54
|
+
GyroEPoolSg = GyroE[0];
|
|
55
|
+
expect(GyroEPoolSg.tokens.length).toBe(2);
|
|
56
|
+
expect(GyroEPoolSg.poolTypeVersion).toEqual(1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('getOnChainState', async function () {
|
|
60
|
+
const blocknumber = 40068730;
|
|
61
|
+
const state = await balancerPools.getOnChainState(
|
|
62
|
+
[GyroEPoolSg],
|
|
63
|
+
blocknumber,
|
|
64
|
+
);
|
|
65
|
+
GyroEPoolState = state[GyroEPoolSg.address];
|
|
66
|
+
expect(GyroEPoolState.swapFee).toBe(BigInt('200000000000000'));
|
|
67
|
+
expect(GyroEPoolState.tokens[tokens.USDC.address].balance).toBe(
|
|
68
|
+
BigInt('18186193501'),
|
|
69
|
+
);
|
|
70
|
+
expect(
|
|
71
|
+
GyroEPoolState.tokens[tokens.TUSD.address.toLowerCase()].balance,
|
|
72
|
+
).toBe(BigInt('26629907962671451455387'));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('parsePoolPairData', async function () {
|
|
76
|
+
const tokenIn = tokens.USDC.address;
|
|
77
|
+
const tokenOut = tokens.TUSD.address;
|
|
78
|
+
const pairData = gyroEPool.parsePoolPairData(
|
|
79
|
+
GyroEPoolSg,
|
|
80
|
+
GyroEPoolState,
|
|
81
|
+
tokenIn,
|
|
82
|
+
tokenOut,
|
|
83
|
+
);
|
|
84
|
+
expect(pairData.indexIn).toBe(0);
|
|
85
|
+
expect(pairData.indexOut).toBe(1);
|
|
86
|
+
expect(pairData.swapFee).toBe(BigInt('200000000000000'));
|
|
87
|
+
expect(pairData.balances).toStrictEqual([
|
|
88
|
+
BigNumber.from('18186193501000000000000'),
|
|
89
|
+
BigNumber.from('26629907962671451455387'),
|
|
90
|
+
]);
|
|
91
|
+
expect(pairData.tokenInIsToken0).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('Swap Functions', () => {
|
|
96
|
+
describe('Swap Functions - 6decimals>18decimals', () => {
|
|
97
|
+
const pairData: GyroEPoolPairData = {
|
|
98
|
+
tokenInIsToken0: true,
|
|
99
|
+
balances: [
|
|
100
|
+
BigNumber.from('18186193501000000000000'),
|
|
101
|
+
BigNumber.from('26629907962671451455387'),
|
|
102
|
+
],
|
|
103
|
+
indexIn: 0,
|
|
104
|
+
indexOut: 1,
|
|
105
|
+
scalingFactors: [
|
|
106
|
+
1000000000000000000000000000000n,
|
|
107
|
+
1000000000000000000n,
|
|
108
|
+
],
|
|
109
|
+
swapFee: 200000000000000n,
|
|
110
|
+
gyroDerivedParams: {
|
|
111
|
+
tauAlpha: {
|
|
112
|
+
x: BigNumber.from('-99921684096872623630266893017017590000'),
|
|
113
|
+
y: BigNumber.from('3956898690236155895758568963473897000'),
|
|
114
|
+
},
|
|
115
|
+
tauBeta: {
|
|
116
|
+
x: BigNumber.from('99921684096872623626859806443439160000'),
|
|
117
|
+
y: BigNumber.from('3956898690236155981796108700303143000'),
|
|
118
|
+
},
|
|
119
|
+
u: BigNumber.from('99921684096872623515276234437562470000'),
|
|
120
|
+
v: BigNumber.from('3956898690236155934291169066298950000'),
|
|
121
|
+
w: BigNumber.from('43018769868414623130'),
|
|
122
|
+
z: BigNumber.from('-1703543286789219094'),
|
|
123
|
+
dSq: BigNumber.from('99999999999999999886624093342106120000'),
|
|
124
|
+
},
|
|
125
|
+
gyroParams: {
|
|
126
|
+
alpha: BigNumber.from('980000000000000000'),
|
|
127
|
+
beta: BigNumber.from('1020408163265306122'),
|
|
128
|
+
c: BigNumber.from('707106781186547524'),
|
|
129
|
+
s: BigNumber.from('707106781186547524'),
|
|
130
|
+
lambda: BigNumber.from('2500000000000000000000'),
|
|
131
|
+
},
|
|
132
|
+
tokenRates: [],
|
|
133
|
+
rateProviders: [],
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
it('getSwapMaxAmount', async () => {
|
|
137
|
+
const swapMaxAmount = gyroEPool.getSwapMaxAmount(
|
|
138
|
+
pairData,
|
|
139
|
+
SwapSide.SELL,
|
|
140
|
+
);
|
|
141
|
+
expect(swapMaxAmount).toBe(BigInt('26629881332'));
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('swap', async function () {
|
|
145
|
+
const amountIn = BigInt('13500000');
|
|
146
|
+
const amountOut = gyroEPool.onSell([amountIn], pairData);
|
|
147
|
+
expect(amountOut.length).toBe(1);
|
|
148
|
+
expect(amountOut[0].toString()).toBe('13499365736688193741');
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('Swap Functions - 18decimals>6decimals', () => {
|
|
153
|
+
const pairData: GyroEPoolPairData = {
|
|
154
|
+
tokenInIsToken0: false,
|
|
155
|
+
balances: [
|
|
156
|
+
BigNumber.from('18186193501000000000000'),
|
|
157
|
+
BigNumber.from('26629907962671451455387'),
|
|
158
|
+
],
|
|
159
|
+
indexIn: 1,
|
|
160
|
+
indexOut: 0,
|
|
161
|
+
scalingFactors: [
|
|
162
|
+
1000000000000000000000000000000n,
|
|
163
|
+
1000000000000000000n,
|
|
164
|
+
],
|
|
165
|
+
swapFee: 200000000000000n,
|
|
166
|
+
gyroDerivedParams: {
|
|
167
|
+
tauAlpha: {
|
|
168
|
+
x: BigNumber.from('-99921684096872623630266893017017590000'),
|
|
169
|
+
y: BigNumber.from('3956898690236155895758568963473897000'),
|
|
170
|
+
},
|
|
171
|
+
tauBeta: {
|
|
172
|
+
x: BigNumber.from('99921684096872623626859806443439160000'),
|
|
173
|
+
y: BigNumber.from('3956898690236155981796108700303143000'),
|
|
174
|
+
},
|
|
175
|
+
u: BigNumber.from('99921684096872623515276234437562470000'),
|
|
176
|
+
v: BigNumber.from('3956898690236155934291169066298950000'),
|
|
177
|
+
w: BigNumber.from('43018769868414623130'),
|
|
178
|
+
z: BigNumber.from('-1703543286789219094'),
|
|
179
|
+
dSq: BigNumber.from('99999999999999999886624093342106120000'),
|
|
180
|
+
},
|
|
181
|
+
gyroParams: {
|
|
182
|
+
alpha: BigNumber.from('980000000000000000'),
|
|
183
|
+
beta: BigNumber.from('1020408163265306122'),
|
|
184
|
+
c: BigNumber.from('707106781186547524'),
|
|
185
|
+
s: BigNumber.from('707106781186547524'),
|
|
186
|
+
lambda: BigNumber.from('2500000000000000000000'),
|
|
187
|
+
},
|
|
188
|
+
tokenRates: [],
|
|
189
|
+
rateProviders: [],
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
it('getSwapMaxAmount', async () => {
|
|
193
|
+
const swapMaxAmount = gyroEPool.getSwapMaxAmount(
|
|
194
|
+
pairData,
|
|
195
|
+
SwapSide.SELL,
|
|
196
|
+
);
|
|
197
|
+
expect(swapMaxAmount).toBe(BigInt('18186175314806499000000'));
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('swap', async function () {
|
|
201
|
+
const amountIn = BigInt('13500000000000000000');
|
|
202
|
+
const amountOut = gyroEPool.onSell([amountIn], pairData);
|
|
203
|
+
expect(amountOut.length).toBe(1);
|
|
204
|
+
expect(amountOut[0].toString()).toBe('13495227');
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('Onchain Compare', () => {
|
|
210
|
+
it('exactIn', async function () {
|
|
211
|
+
const blocknumber = 54571344;
|
|
212
|
+
// USDC/TUSD
|
|
213
|
+
const poolId =
|
|
214
|
+
'0x97469e6236bd467cd147065f77752b00efadce8a0002000000000000000008c0';
|
|
215
|
+
const tokenIn = tokens.USDC.address;
|
|
216
|
+
const tokenOut = tokens.TUSD.address;
|
|
217
|
+
const amountIn = BigInt('1000000');
|
|
218
|
+
|
|
219
|
+
const pools = await balancerPools.fetchAllSubgraphPools();
|
|
220
|
+
const poolSg = pools.filter(p => p.id === poolId)[0];
|
|
221
|
+
const state = await balancerPools.getOnChainState(
|
|
222
|
+
[poolSg],
|
|
223
|
+
blocknumber,
|
|
224
|
+
);
|
|
225
|
+
const poolState = state[poolSg.address];
|
|
226
|
+
|
|
227
|
+
const pairData = gyroEPool.parsePoolPairData(
|
|
228
|
+
poolSg,
|
|
229
|
+
poolState,
|
|
230
|
+
tokenIn,
|
|
231
|
+
tokenOut,
|
|
232
|
+
);
|
|
233
|
+
const amountOut = gyroEPool.onSell([amountIn], pairData);
|
|
234
|
+
const deltas = await queryOnChain(
|
|
235
|
+
rpcUrl,
|
|
236
|
+
blocknumber,
|
|
237
|
+
poolId,
|
|
238
|
+
0,
|
|
239
|
+
tokenIn,
|
|
240
|
+
tokenOut,
|
|
241
|
+
amountIn,
|
|
242
|
+
);
|
|
243
|
+
expect(amountIn).toEqual(deltas[0]);
|
|
244
|
+
expect(amountOut[0] + deltas[1]).toEqual(0n);
|
|
245
|
+
});
|
|
246
|
+
it('exactOut', async function () {
|
|
247
|
+
const blocknumber = 54571344;
|
|
248
|
+
// USDC/TUSD
|
|
249
|
+
const poolId =
|
|
250
|
+
'0x97469e6236bd467cd147065f77752b00efadce8a0002000000000000000008c0';
|
|
251
|
+
const tokenIn = tokens.USDC.address;
|
|
252
|
+
const tokenOut = tokens.TUSD.address;
|
|
253
|
+
const amountOut = BigInt('2000000000000000000');
|
|
254
|
+
|
|
255
|
+
const pools = await balancerPools.fetchAllSubgraphPools();
|
|
256
|
+
const poolSg = pools.filter(p => p.id === poolId)[0];
|
|
257
|
+
const state = await balancerPools.getOnChainState(
|
|
258
|
+
[poolSg],
|
|
259
|
+
blocknumber,
|
|
260
|
+
);
|
|
261
|
+
const poolState = state[poolSg.address];
|
|
262
|
+
|
|
263
|
+
const pairData = gyroEPool.parsePoolPairData(
|
|
264
|
+
poolSg,
|
|
265
|
+
poolState,
|
|
266
|
+
tokenIn,
|
|
267
|
+
tokenOut,
|
|
268
|
+
);
|
|
269
|
+
const amountIn = gyroEPool.onBuy([amountOut], pairData);
|
|
270
|
+
const deltas = await queryOnChain(
|
|
271
|
+
rpcUrl,
|
|
272
|
+
blocknumber,
|
|
273
|
+
poolId,
|
|
274
|
+
1,
|
|
275
|
+
tokenIn,
|
|
276
|
+
tokenOut,
|
|
277
|
+
amountOut,
|
|
278
|
+
);
|
|
279
|
+
expect(amountIn[0]).toEqual(deltas[0]);
|
|
280
|
+
expect(amountOut + deltas[1]).toEqual(0n);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe('GyroE Pool V2', () => {
|
|
286
|
+
describe('Pool Fetching', () => {
|
|
287
|
+
it('should fetch GyroE Pool with correct fields from Subgraph', async function () {
|
|
288
|
+
const pools = await balancerPools.fetchAllSubgraphPools();
|
|
289
|
+
// wmatic/xmatic
|
|
290
|
+
const GyroEPoolId =
|
|
291
|
+
'0xee278d943584dd8640eaf4cc6c7a5c80c0073e85000200000000000000000bc7';
|
|
292
|
+
const GyroE = pools.filter(p => p.id === GyroEPoolId);
|
|
293
|
+
expect(GyroE.length).toBe(1);
|
|
294
|
+
GyroEPoolSg = GyroE[0];
|
|
295
|
+
expect(GyroEPoolSg.tokens.length).toBe(2);
|
|
296
|
+
expect(GyroEPoolSg.poolTypeVersion).toEqual(2);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('getOnChainState', async function () {
|
|
300
|
+
const blocknumber = 54571344;
|
|
301
|
+
const state = await balancerPools.getOnChainState(
|
|
302
|
+
[GyroEPoolSg],
|
|
303
|
+
blocknumber,
|
|
304
|
+
);
|
|
305
|
+
GyroEPoolState = state[GyroEPoolSg.address];
|
|
306
|
+
expect(GyroEPoolState.swapFee).toBe(BigInt('100000000000000'));
|
|
307
|
+
expect(
|
|
308
|
+
GyroEPoolState.tokens[tokens.WMATIC.address.toLowerCase()].balance,
|
|
309
|
+
).toBe(231918780712184629424641n);
|
|
310
|
+
expect(
|
|
311
|
+
GyroEPoolState.tokens[tokens.MATICX.address.toLowerCase()].balance,
|
|
312
|
+
).toBe(1614748628144003818699851n);
|
|
313
|
+
expect(GyroEPoolState.rateProviders![0]).toBe(
|
|
314
|
+
'0x0000000000000000000000000000000000000000',
|
|
315
|
+
);
|
|
316
|
+
expect(GyroEPoolState.rateProviders![1].toLowerCase()).toBe(
|
|
317
|
+
'0xee652bbf72689aa59f0b8f981c9c90e2a8af8d8f',
|
|
318
|
+
);
|
|
319
|
+
// Token has no rate provider so rate should be 1
|
|
320
|
+
expect(GyroEPoolState.tokenRates![0]).toBe(1000000000000000000n);
|
|
321
|
+
// Token has a rate provider so should use that rate
|
|
322
|
+
expect(GyroEPoolState.tokenRates![1]).toBe(1103299689517375348n);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe('Onchain Compare', () => {
|
|
327
|
+
it('exactIn', async function () {
|
|
328
|
+
const blocknumber = 54571344;
|
|
329
|
+
// wmatic/xmatic
|
|
330
|
+
const poolId =
|
|
331
|
+
'0xee278d943584dd8640eaf4cc6c7a5c80c0073e85000200000000000000000bc7';
|
|
332
|
+
const tokenIn = tokens.MATICX.address;
|
|
333
|
+
const tokenOut = tokens.WMATIC.address;
|
|
334
|
+
const amountIn = BigInt('110000000000000000');
|
|
335
|
+
|
|
336
|
+
const pools = await balancerPools.fetchAllSubgraphPools();
|
|
337
|
+
const poolSg = pools.filter(p => p.id === poolId)[0];
|
|
338
|
+
const state = await balancerPools.getOnChainState(
|
|
339
|
+
[poolSg],
|
|
340
|
+
blocknumber,
|
|
341
|
+
);
|
|
342
|
+
const poolState = state[poolSg.address];
|
|
343
|
+
|
|
344
|
+
const pairData = gyroEPool.parsePoolPairData(
|
|
345
|
+
poolSg,
|
|
346
|
+
poolState,
|
|
347
|
+
tokenIn,
|
|
348
|
+
tokenOut,
|
|
349
|
+
);
|
|
350
|
+
const amountOut = gyroEPool.onSell([amountIn], pairData);
|
|
351
|
+
const deltas = await queryOnChain(
|
|
352
|
+
rpcUrl,
|
|
353
|
+
blocknumber,
|
|
354
|
+
poolId,
|
|
355
|
+
0,
|
|
356
|
+
tokenIn,
|
|
357
|
+
tokenOut,
|
|
358
|
+
amountIn,
|
|
359
|
+
);
|
|
360
|
+
expect(amountIn).toEqual(deltas[0]);
|
|
361
|
+
expect(amountOut[0] + deltas[1]).toEqual(0n);
|
|
362
|
+
});
|
|
363
|
+
it('exactOut', async function () {
|
|
364
|
+
const blocknumber = 54571344;
|
|
365
|
+
// wmatic/xmatic
|
|
366
|
+
const poolId =
|
|
367
|
+
'0xee278d943584dd8640eaf4cc6c7a5c80c0073e85000200000000000000000bc7';
|
|
368
|
+
const tokenIn = tokens.MATICX.address;
|
|
369
|
+
const tokenOut = tokens.WMATIC.address;
|
|
370
|
+
const amountOut = BigInt('2000000000000000000');
|
|
371
|
+
|
|
372
|
+
const pools = await balancerPools.fetchAllSubgraphPools();
|
|
373
|
+
const poolSg = pools.filter(p => p.id === poolId)[0];
|
|
374
|
+
const state = await balancerPools.getOnChainState(
|
|
375
|
+
[poolSg],
|
|
376
|
+
blocknumber,
|
|
377
|
+
);
|
|
378
|
+
const poolState = state[poolSg.address];
|
|
379
|
+
|
|
380
|
+
const pairData = gyroEPool.parsePoolPairData(
|
|
381
|
+
poolSg,
|
|
382
|
+
poolState,
|
|
383
|
+
tokenIn,
|
|
384
|
+
tokenOut,
|
|
385
|
+
);
|
|
386
|
+
const amountIn = gyroEPool.onBuy([amountOut], pairData);
|
|
387
|
+
const deltas = await queryOnChain(
|
|
388
|
+
rpcUrl,
|
|
389
|
+
blocknumber,
|
|
390
|
+
poolId,
|
|
391
|
+
1,
|
|
392
|
+
tokenIn,
|
|
393
|
+
tokenOut,
|
|
394
|
+
amountOut,
|
|
395
|
+
);
|
|
396
|
+
expect(amountIn[0]).toEqual(deltas[0]);
|
|
397
|
+
expect(amountOut + deltas[1]).toEqual(0n);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
});
|