@paraswap/dex-lib 4.0.22 → 4.0.24-bal-v3-nested-erc4626.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.
Files changed (197) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/integral/factory.json +333 -0
  10. package/build/abi/integral/oracle.json +501 -0
  11. package/build/abi/{inception/inception-ineth-pool.json → integral/pool.json} +522 -543
  12. package/build/abi/{wombat/pool.json → integral/relayer.json} +720 -473
  13. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  14. package/build/dex/aave-v1/aave-v1.js +0 -23
  15. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  16. package/build/dex/balancer-v2/config.js +1 -1
  17. package/build/dex/balancer-v2/config.js.map +1 -1
  18. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +8 -2
  19. package/build/dex/balancer-v3/balancer-v3-pool.js +118 -72
  20. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -1
  21. package/build/dex/balancer-v3/balancer-v3.js +12 -2
  22. package/build/dex/balancer-v3/balancer-v3.js.map +1 -1
  23. package/build/dex/balancer-v3/getGasCost.js +15 -11
  24. package/build/dex/balancer-v3/getGasCost.js.map +1 -1
  25. package/build/dex/balancer-v3/getOnChainState.js +10 -1
  26. package/build/dex/balancer-v3/getOnChainState.js.map +1 -1
  27. package/build/dex/balancer-v3/getPoolsApi.js +2 -0
  28. package/build/dex/balancer-v3/getPoolsApi.js.map +1 -1
  29. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +1 -0
  30. package/build/dex/balancer-v3/getTopPoolsApi.js +1 -0
  31. package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -1
  32. package/build/dex/balancer-v3/types.d.ts +8 -4
  33. package/build/dex/balancer-v3/types.js +7 -0
  34. package/build/dex/balancer-v3/types.js.map +1 -1
  35. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +49 -0
  36. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +104 -0
  37. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +1 -0
  38. package/build/dex/generic-rfq/e2e-test-config.js +3 -3
  39. package/build/dex/generic-rfq/e2e-test-config.js.map +1 -1
  40. package/build/dex/integral/config.d.ts +4 -0
  41. package/build/dex/integral/config.js +20 -0
  42. package/build/dex/integral/config.js.map +1 -0
  43. package/build/dex/integral/context.d.ts +40 -0
  44. package/build/dex/integral/context.js +158 -0
  45. package/build/dex/integral/context.js.map +1 -0
  46. package/build/dex/integral/integral-factory.d.ts +24 -0
  47. package/build/dex/integral/integral-factory.js +95 -0
  48. package/build/dex/integral/integral-factory.js.map +1 -0
  49. package/build/dex/integral/integral-pool.d.ts +50 -0
  50. package/build/dex/integral/integral-pool.js +149 -0
  51. package/build/dex/integral/integral-pool.js.map +1 -0
  52. package/build/dex/integral/integral-pricing.d.ts +18 -0
  53. package/build/dex/integral/integral-pricing.js +114 -0
  54. package/build/dex/integral/integral-pricing.js.map +1 -0
  55. package/build/dex/integral/integral-relayer.d.ts +42 -0
  56. package/build/dex/integral/integral-relayer.js +192 -0
  57. package/build/dex/integral/integral-relayer.js.map +1 -0
  58. package/build/dex/integral/integral-token.d.ts +27 -0
  59. package/build/dex/integral/integral-token.js +59 -0
  60. package/build/dex/integral/integral-token.js.map +1 -0
  61. package/build/dex/integral/integral.d.ts +41 -0
  62. package/build/dex/integral/integral.js +376 -0
  63. package/build/dex/integral/integral.js.map +1 -0
  64. package/build/dex/integral/types.d.ts +85 -0
  65. package/build/dex/integral/types.js +9 -0
  66. package/build/dex/integral/types.js.map +1 -0
  67. package/build/dex/integral/utils-e2e.d.ts +9 -0
  68. package/build/dex/integral/utils-e2e.js +131 -0
  69. package/build/dex/integral/utils-e2e.js.map +1 -0
  70. package/build/dex/integral/utils.d.ts +17 -0
  71. package/build/dex/integral/utils.js +94 -0
  72. package/build/dex/integral/utils.js.map +1 -0
  73. package/build/dex/jarvis.d.ts +1 -2
  74. package/build/dex/jarvis.js +0 -58
  75. package/build/dex/jarvis.js.map +1 -1
  76. package/build/dex/maverick-v1/config.js +1 -1
  77. package/build/dex/maverick-v1/config.js.map +1 -1
  78. package/build/dex/platypus/platypus.d.ts +1 -2
  79. package/build/dex/platypus/platypus.js +0 -45
  80. package/build/dex/platypus/platypus.js.map +1 -1
  81. package/build/dex/stable-pool.js +8 -1
  82. package/build/dex/stable-pool.js.map +1 -1
  83. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  84. package/build/dex/swaap-v1/swaap-v1.js +0 -14
  85. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  86. package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
  87. package/build/dex/trader-joe-v2.1/optimizer.js +47 -0
  88. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
  89. package/build/dex/uniswap-v3/config.js +1 -1
  90. package/build/dex/uniswap-v3/config.js.map +1 -1
  91. package/build/dex/zerox/index.d.ts +26 -4
  92. package/build/dex/zerox/index.js +42 -50
  93. package/build/dex/zerox/index.js.map +1 -1
  94. package/build/dex/zerox/types.d.ts +0 -29
  95. package/build/dex/zerox/types.js +1 -8
  96. package/build/dex/zerox/types.js.map +1 -1
  97. package/package.json +1 -1
  98. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +165 -102
  99. package/src/dex/balancer-v2/balancer-v2-integration.test.ts +238 -80
  100. package/src/dex/balancer-v2/config.ts +1 -2
  101. package/src/dex/balancer-v3/balancer-v3-integration.test.ts +135 -2
  102. package/src/dex/balancer-v3/balancer-v3-pool.ts +161 -80
  103. package/src/dex/balancer-v3/balancer-v3.ts +13 -2
  104. package/src/dex/balancer-v3/getGasCost.ts +14 -9
  105. package/src/dex/balancer-v3/getOnChainState.ts +16 -3
  106. package/src/dex/balancer-v3/getPoolsApi.ts +5 -0
  107. package/src/dex/balancer-v3/getTopPoolsApi.ts +2 -0
  108. package/src/dex/balancer-v3/types.ts +9 -4
  109. package/src/dex/generic-rfq/e2e-test-config.ts +3 -3
  110. package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +2 -2
  111. package/src/dex/maverick-v1/config.ts +1 -2
  112. package/src/dex/uniswap-v3/config.ts +1 -2
  113. package/tests/constants-e2e.ts +16 -1
  114. package/tests/smart-tokens.ts +1 -3
  115. package/tests/tenderly-simulation.ts +149 -84
  116. package/tests/utils-e2e.ts +5 -2
  117. package/.vscode/launch.json +0 -53
  118. package/.vscode/settings.json +0 -2
  119. package/.vscode/tasks.json +0 -15
  120. package/build/abi/inception/inception-ratio-feed.json +0 -329
  121. package/build/abi/inception/inception-vault.json +0 -991
  122. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  123. package/build/abi/usual-m-smart-m/usualM.abi.json +0 -483
  124. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  125. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  126. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  127. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +0 -729
  128. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +0 -732
  129. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +0 -1
  130. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +0 -1406
  131. package/build/dex/balancer-v3/abi/balancerRouter.js +0 -1175
  132. package/build/dex/balancer-v3/abi/balancerRouter.js.map +0 -1
  133. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +0 -2081
  134. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +0 -1851
  135. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +0 -1
  136. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +0 -34
  137. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +0 -406
  138. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +0 -1
  139. package/build/dex/inception/config.d.ts +0 -4
  140. package/build/dex/inception/config.js +0 -109
  141. package/build/dex/inception/config.js.map +0 -1
  142. package/build/dex/inception/inception-event-pool.d.ts +0 -16
  143. package/build/dex/inception/inception-event-pool.js +0 -49
  144. package/build/dex/inception/inception-event-pool.js.map +0 -1
  145. package/build/dex/inception/inception.d.ts +0 -43
  146. package/build/dex/inception/inception.js +0 -180
  147. package/build/dex/inception/inception.js.map +0 -1
  148. package/build/dex/inception/tokens.d.ts +0 -9
  149. package/build/dex/inception/tokens.js +0 -28
  150. package/build/dex/inception/tokens.js.map +0 -1
  151. package/build/dex/inception/types.d.ts +0 -22
  152. package/build/dex/inception/types.js +0 -3
  153. package/build/dex/inception/types.js.map +0 -1
  154. package/build/dex/inception/utils.d.ts +0 -7
  155. package/build/dex/inception/utils.js +0 -58
  156. package/build/dex/inception/utils.js.map +0 -1
  157. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  158. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  159. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  160. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  161. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  162. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  163. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  164. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  165. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  166. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  167. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  168. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  169. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  170. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
  171. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +0 -4
  172. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +0 -43
  173. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +0 -1
  174. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +0 -1
  175. package/build/dex/uniswap-v3/uniswap-v3-worker.js +0 -10
  176. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +0 -1
  177. package/build/dex/usual/usual-m-smart-m.d.ts +0 -17
  178. package/build/dex/usual/usual-m-smart-m.js +0 -50
  179. package/build/dex/usual/usual-m-smart-m.js.map +0 -1
  180. package/build/dex/usual-m-smart-m/config.d.ts +0 -3
  181. package/build/dex/usual-m-smart-m/config.js +0 -13
  182. package/build/dex/usual-m-smart-m/config.js.map +0 -1
  183. package/build/dex/usual-m-smart-m/types.d.ts +0 -7
  184. package/build/dex/usual-m-smart-m/types.js +0 -3
  185. package/build/dex/usual-m-smart-m/types.js.map +0 -1
  186. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +0 -35
  187. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +0 -161
  188. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +0 -1
  189. package/build/dex/usual-m-usd0/config.d.ts +0 -3
  190. package/build/dex/usual-m-usd0/config.js +0 -14
  191. package/build/dex/usual-m-usd0/config.js.map +0 -1
  192. package/build/dex/usual-m-usd0/types.d.ts +0 -8
  193. package/build/dex/usual-m-usd0/types.js +0 -3
  194. package/build/dex/usual-m-usd0/types.js.map +0 -1
  195. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +0 -35
  196. package/build/dex/usual-m-usd0/usual-m-usd0.js +0 -159
  197. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +0 -1
@@ -30,11 +30,9 @@ async function getOnChainPricingForWeightedPool(
30
30
  return 0n;
31
31
  }
32
32
 
33
- const params = balancerV2.getBalancerParam(
33
+ const params = balancerV2.getBalancerV2BatchSwapParam(
34
34
  srcTokenAddress,
35
35
  destTokenAddress,
36
- '0',
37
- '0',
38
36
  {
39
37
  swaps: [
40
38
  {
@@ -44,6 +42,8 @@ async function getOnChainPricingForWeightedPool(
44
42
  ],
45
43
  },
46
44
  side,
45
+ balancerV2.dexHelper.config.data.augustusV6Address!,
46
+ balancerV2.dexHelper.config.data.augustusV6Address!,
47
47
  );
48
48
 
49
49
  const calldata = [
@@ -611,85 +611,243 @@ describe('BalancerV2', function () {
611
611
  });
612
612
 
613
613
  describe('GyroE', () => {
614
- // sDAI<>GYD - more likely to have continued liqudity
615
- const gyroEAddr = '0x1cce5169bde03f3d5ad0206f6bd057953539dae6';
616
-
617
- it('getPoolIdentifiers and getPricesVolume', async function () {
618
- const network = Network.MAINNET;
619
- const dexHelper = new DummyDexHelper(network);
620
- // const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
621
- const blocknumber = 19425305;
622
- const balancerV2 = new BalancerV2(network, dexKey, dexHelper);
623
- const tokens = Tokens[network];
624
-
625
- await balancerV2.initializePricing(blocknumber);
626
-
627
- const pools = await balancerV2.getPoolIdentifiers(
628
- tokens.GYD,
629
- tokens.sDAI,
630
- SwapSide.SELL,
631
- blocknumber,
632
- );
633
- console.log('GYD <> sDAI Pool Identifiers (Mainnet): ', pools);
634
-
635
- const isPool = pools.find(poolIdentifier =>
636
- poolIdentifier.includes(gyroEAddr),
637
- );
638
-
639
- expect(isPool).toBeDefined();
640
-
641
- const poolPrices = await balancerV2.getPricesVolume(
642
- tokens.GYD,
643
- tokens.sDAI,
644
- amounts,
645
- SwapSide.SELL,
646
- blocknumber,
647
- pools,
648
- );
649
- console.log('GYD <> sDAI Pool Prices (Mainnet): ', poolPrices);
650
-
651
- expect(poolPrices).not.toBeNull();
652
- checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
653
- const isPoolPrice = poolPrices!.find(price =>
654
- price.data.poolId.includes(gyroEAddr),
655
- );
656
- expect(isPoolPrice).toBeDefined();
657
-
658
- const onChainPrices = await getOnChainPricingForWeightedPool(
659
- balancerV2,
660
- blocknumber,
661
- isPoolPrice!,
662
- amounts,
663
- tokens.GYD.address,
664
- tokens.sDAI.address,
665
- SwapSide.SELL,
666
- );
667
-
668
- console.log('GYD <> sDAI on-chain prices: ', onChainPrices);
669
-
670
- expect(onChainPrices).toEqual(isPoolPrice!.prices);
671
-
672
- await balancerV2.releaseResources();
614
+ describe('sDAI > GYD', () => {
615
+ // sDAI<>GYD - more likely to have continued liqudity
616
+ const gyroEAddr = '0x1cce5169bde03f3d5ad0206f6bd057953539dae6';
617
+
618
+ it('getPoolIdentifiers and getPricesVolume', async function () {
619
+ const network = Network.MAINNET;
620
+ const dexHelper = new DummyDexHelper(network);
621
+ // const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
622
+ const blocknumber = 19425305;
623
+ const balancerV2 = new BalancerV2(network, dexKey, dexHelper);
624
+ const tokens = Tokens[network];
625
+
626
+ await balancerV2.initializePricing(blocknumber);
627
+
628
+ const pools = await balancerV2.getPoolIdentifiers(
629
+ tokens.GYD,
630
+ tokens.sDAI,
631
+ SwapSide.SELL,
632
+ blocknumber,
633
+ );
634
+ console.log('GYD <> sDAI Pool Identifiers (Mainnet): ', pools);
635
+
636
+ const isPool = pools.find(poolIdentifier =>
637
+ poolIdentifier.includes(gyroEAddr),
638
+ );
639
+
640
+ expect(isPool).toBeDefined();
641
+
642
+ const poolPrices = await balancerV2.getPricesVolume(
643
+ tokens.GYD,
644
+ tokens.sDAI,
645
+ amounts,
646
+ SwapSide.SELL,
647
+ blocknumber,
648
+ pools,
649
+ );
650
+ console.log('GYD <> sDAI Pool Prices (Mainnet): ', poolPrices);
651
+
652
+ expect(poolPrices).not.toBeNull();
653
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
654
+ const isPoolPrice = poolPrices!.find(price =>
655
+ price.data.poolId.includes(gyroEAddr),
656
+ );
657
+ expect(isPoolPrice).toBeDefined();
658
+
659
+ const onChainPrices = await getOnChainPricingForWeightedPool(
660
+ balancerV2,
661
+ blocknumber,
662
+ isPoolPrice!,
663
+ amounts,
664
+ tokens.GYD.address,
665
+ tokens.sDAI.address,
666
+ SwapSide.SELL,
667
+ );
668
+
669
+ console.log('GYD <> sDAI on-chain prices: ', onChainPrices);
670
+
671
+ expect(onChainPrices).toEqual(isPoolPrice!.prices);
672
+
673
+ await balancerV2.releaseResources();
674
+ });
675
+
676
+ it('getTopPoolsForToken', async function () {
677
+ const network = Network.MAINNET;
678
+ const dexHelper = new DummyDexHelper(network);
679
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
680
+ const balancerV2 = new BalancerV2(network, dexKey, dexHelper);
681
+ await balancerV2.initializePricing(blocknumber);
682
+ const tokens = Tokens[network];
683
+
684
+ const poolLiquidity = await balancerV2.getTopPoolsForToken(
685
+ tokens.sDAI.address.toLowerCase(),
686
+ 10,
687
+ );
688
+ console.log('sDAI Top Pools (Mainnet):', poolLiquidity);
689
+
690
+ checkPoolsLiquidity(poolLiquidity, tokens.sDAI.address, dexKey);
691
+ const isTopPool = poolLiquidity.find(
692
+ pool => pool.address === gyroEAddr,
693
+ );
694
+ expect(isTopPool).toBeDefined();
695
+ await balancerV2.releaseResources();
696
+ });
673
697
  });
674
698
 
675
- it('getTopPoolsForToken', async function () {
676
- const network = Network.MAINNET;
677
- const dexHelper = new DummyDexHelper(network);
678
- const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
679
- const balancerV2 = new BalancerV2(network, dexKey, dexHelper);
680
- await balancerV2.initializePricing(blocknumber);
681
- const tokens = Tokens[network];
682
-
683
- const poolLiquidity = await balancerV2.getTopPoolsForToken(
684
- tokens.sDAI.address.toLowerCase(),
685
- 10,
686
- );
687
- console.log('sDAI Top Pools (Mainnet):', poolLiquidity);
688
-
689
- checkPoolsLiquidity(poolLiquidity, tokens.sDAI.address, dexKey);
690
- const isTopPool = poolLiquidity.find(pool => pool.address === gyroEAddr);
691
- expect(isTopPool).toBeDefined();
692
- await balancerV2.releaseResources();
699
+ describe('WETH / USDC', () => {
700
+ const gyroEAddr = '0x4c42b5057a8663e2b1ac21685d1502c937a03817';
701
+
702
+ it('SELL WETH -> USDC getPoolIdentifiers and getPricesVolume', async function () {
703
+ const network = Network.BASE;
704
+
705
+ const dexHelper = new DummyDexHelper(network);
706
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
707
+ // const blocknumber = 19425305;
708
+ const balancerV2 = new BalancerV2(network, dexKey, dexHelper);
709
+ const tokens = Tokens[network];
710
+
711
+ const amounts = [
712
+ 0n,
713
+ BI_POWS[18],
714
+ 2n * BI_POWS[18],
715
+ 3n * BI_POWS[18],
716
+ 4n * BI_POWS[18],
717
+ 5n * BI_POWS[18],
718
+ 6n * BI_POWS[18],
719
+ 7n * BI_POWS[18],
720
+ 8n * BI_POWS[18],
721
+ 9n * BI_POWS[18],
722
+ 10n * BI_POWS[18],
723
+ ];
724
+
725
+ await balancerV2.initializePricing(blocknumber);
726
+
727
+ const pools = await balancerV2.getPoolIdentifiers(
728
+ tokens.WETH,
729
+ tokens.USDC,
730
+ SwapSide.SELL,
731
+ blocknumber,
732
+ );
733
+ console.log('WETH <> USDC Pool Identifiers (Mainnet): ', pools);
734
+
735
+ const isPool = pools.find(poolIdentifier =>
736
+ poolIdentifier.includes(gyroEAddr),
737
+ );
738
+
739
+ expect(isPool).toBeDefined();
740
+
741
+ const poolPrices = await balancerV2.getPricesVolume(
742
+ tokens.WETH,
743
+ tokens.USDC,
744
+ amounts,
745
+ SwapSide.SELL,
746
+ blocknumber,
747
+ pools,
748
+ );
749
+ console.log('WETH <> USDC Pool Prices (Base): ', poolPrices);
750
+
751
+ expect(poolPrices).not.toBeNull();
752
+
753
+ // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
754
+ const isPoolPrice = poolPrices!.find(price =>
755
+ price.data.poolId.includes(gyroEAddr),
756
+ );
757
+ expect(isPoolPrice).toBeDefined();
758
+
759
+ const onChainPrices = await getOnChainPricingForWeightedPool(
760
+ balancerV2,
761
+ blocknumber,
762
+ isPoolPrice!,
763
+ amounts,
764
+ tokens.WETH.address,
765
+ tokens.USDC.address,
766
+ SwapSide.SELL,
767
+ );
768
+
769
+ console.log('WETH <> USDC on-chain prices: ', onChainPrices);
770
+
771
+ expect(onChainPrices).toEqual(isPoolPrice!.prices);
772
+
773
+ await balancerV2.releaseResources();
774
+ });
775
+
776
+ it('SELL USDC -> WETH getPoolIdentifiers and getPricesVolume', async function () {
777
+ const network = Network.BASE;
778
+ const dexHelper = new DummyDexHelper(network);
779
+ // const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
780
+ const blocknumber = 24931862;
781
+ const balancerV2 = new BalancerV2(network, dexKey, dexHelper);
782
+ const tokens = Tokens[network];
783
+
784
+ const amounts = [
785
+ 0n,
786
+ 1000000n,
787
+ // BI_POWS[6],
788
+ // 2n * BI_POWS[6],
789
+ // 3n * BI_POWS[6],
790
+ // 4n * BI_POWS[6],
791
+ // 5n * BI_POWS[6],
792
+ // 6n * BI_POWS[6],
793
+ // 7n * BI_POWS[6],
794
+ // 8n * BI_POWS[6],
795
+ // 9n * BI_POWS[6],
796
+ // 10n * BI_POWS[6],
797
+ ];
798
+
799
+ await balancerV2.initializePricing(blocknumber);
800
+
801
+ const pools = await balancerV2.getPoolIdentifiers(
802
+ tokens.USDC,
803
+ tokens.WETH,
804
+ SwapSide.SELL,
805
+ blocknumber,
806
+ );
807
+ console.log('USDC -> WETH Pool Identifiers (Base): ', pools);
808
+
809
+ const isPool = pools.find(poolIdentifier =>
810
+ poolIdentifier.includes(gyroEAddr),
811
+ );
812
+
813
+ expect(isPool).toBeDefined();
814
+
815
+ const poolPrices = await balancerV2.getPricesVolume(
816
+ tokens.USDC,
817
+ tokens.WETH,
818
+ amounts,
819
+ SwapSide.SELL,
820
+ blocknumber,
821
+ pools,
822
+ );
823
+ console.log('USDC -> WETH Pool Prices (Base): ', poolPrices);
824
+
825
+ expect(poolPrices).not.toBeNull();
826
+
827
+ // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
828
+ const isPoolPrice = poolPrices!.find(price =>
829
+ price.data.poolId.includes(gyroEAddr),
830
+ );
831
+ expect(isPoolPrice).toBeDefined();
832
+
833
+ console.log('isPoolPrice: ', isPoolPrice);
834
+
835
+ const onChainPrices = await getOnChainPricingForWeightedPool(
836
+ balancerV2,
837
+ blocknumber,
838
+ isPoolPrice!,
839
+ amounts,
840
+ tokens.USDC.address,
841
+ tokens.WETH.address,
842
+ SwapSide.SELL,
843
+ );
844
+
845
+ console.log('USDC -> WETH on-chain prices: ', onChainPrices);
846
+
847
+ expect(onChainPrices).toEqual(isPoolPrice!.prices);
848
+
849
+ await balancerV2.releaseResources();
850
+ });
693
851
  });
694
852
  });
695
853
  });
@@ -21,8 +21,7 @@ export const BalancerConfig: DexConfigMap<DexParams> = {
21
21
  vaultAddress: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
22
22
  },
23
23
  [Network.BASE]: {
24
- subgraphURL:
25
- 'https://api.studio.thegraph.com/query/24660/balancer-base-v2/version/latest',
24
+ subgraphURL: 'E7XyutxXVLrp8njmjF16Hh38PCJuHm12RRyMt5ma4ctX',
26
25
  vaultAddress: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
27
26
  },
28
27
  [Network.GNOSIS]: {
@@ -205,10 +205,29 @@ async function checkOnChainPricingNonMulti(
205
205
  price,
206
206
  amounts,
207
207
  );
208
- expect(price.prices).toEqual(expectedPrices);
208
+ price.prices.forEach((p, i) => {
209
+ expect(areBigIntsWithinPercent(p, expectedPrices[i], 0.001)).toEqual(
210
+ true,
211
+ );
212
+ });
209
213
  }
210
214
  }
211
215
 
216
+ // Helper function to check if two BigInts are within a given percentage
217
+ export function areBigIntsWithinPercent(
218
+ value1: bigint,
219
+ value2: bigint,
220
+ percent: number,
221
+ ): boolean {
222
+ if (percent < 0) {
223
+ throw new Error('Percent must be non-negative');
224
+ }
225
+ const difference = value1 > value2 ? value1 - value2 : value2 - value1;
226
+ const percentFactor = BigInt(Math.floor(percent * 1e8));
227
+ const tolerance = (value2 * percentFactor) / BigInt(1e10);
228
+ return difference <= tolerance;
229
+ }
230
+
212
231
  async function testPricingOnNetwork(
213
232
  balancerV3: BalancerV3,
214
233
  network: Network,
@@ -901,7 +920,7 @@ describe('BalancerV3', function () {
901
920
  Note for maths: Instead of manually adding support for each ERC4626 implementation (e.g. stata with Ray maths) we always use an
902
921
  18 decimal scaled rate and do 18 decimal maths to convert. We may end up loosing 100% accuracy but thats deemed acceptable.
903
922
  */
904
- describe.only('Buffer wrap 6decimal>18decimal', () => {
923
+ describe('Buffer wrap 6decimal>18decimal', () => {
905
924
  const dexHelper = new DummyDexHelper(network);
906
925
 
907
926
  const tokens = Tokens[network];
@@ -1059,6 +1078,120 @@ describe('BalancerV3', function () {
1059
1078
  });
1060
1079
  });
1061
1080
  });
1081
+
1082
+ describe('Nested ERC4626', () => {
1083
+ /*
1084
+ Pool has csUSDL which has nested ERC4626. USDL swaps can be enabled by simply adding extra buffer step.
1085
+ https://balancer.fi/pools/ethereum/v3/0x10a04efba5b880e169920fd4348527c64fb29d4d
1086
+ csUSDC: 0x7204b7dbf9412567835633b6f00c3edc3a8d6330
1087
+ - USDC: 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
1088
+ csUSDL: 0xbeefc011e94f43b8b7b455ebab290c7ab4e216f1
1089
+ - wUSDL: 0x7751e2f4b8ae93ef6b79d86419d42fe3295a4559
1090
+ - USDL: 0xbdc7c08592ee4aa51d06c27ee23d5087d65adbcd
1091
+ */
1092
+ describe('Nested underlying as token in', () => {
1093
+ const dexHelper = new DummyDexHelper(network);
1094
+
1095
+ const tokens = Tokens[network];
1096
+ const srcTokenSymbol = 'USDL';
1097
+ const destTokenSymbol = 'USDC';
1098
+
1099
+ const amountsForSell = [
1100
+ 0n,
1101
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
1102
+ ];
1103
+
1104
+ const amountsForBuy = [
1105
+ 0n,
1106
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
1107
+ ];
1108
+
1109
+ beforeAll(async () => {
1110
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
1111
+ balancerV3 = new BalancerV3(network, dexKey, dexHelper);
1112
+ if (balancerV3.initializePricing) {
1113
+ await balancerV3.initializePricing(blockNumber);
1114
+ }
1115
+ });
1116
+
1117
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
1118
+ await testPricingOnNetwork(
1119
+ balancerV3,
1120
+ network,
1121
+ dexKey,
1122
+ blockNumber,
1123
+ srcTokenSymbol,
1124
+ destTokenSymbol,
1125
+ SwapSide.SELL,
1126
+ amountsForSell,
1127
+ );
1128
+ });
1129
+
1130
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
1131
+ await testPricingOnNetwork(
1132
+ balancerV3,
1133
+ network,
1134
+ dexKey,
1135
+ blockNumber,
1136
+ srcTokenSymbol,
1137
+ destTokenSymbol,
1138
+ SwapSide.BUY,
1139
+ amountsForBuy,
1140
+ );
1141
+ });
1142
+ });
1143
+ describe('Nested underlying as token out', () => {
1144
+ const dexHelper = new DummyDexHelper(network);
1145
+
1146
+ const tokens = Tokens[network];
1147
+ const srcTokenSymbol = 'USDC';
1148
+ const destTokenSymbol = 'USDL';
1149
+
1150
+ const amountsForSell = [
1151
+ 0n,
1152
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
1153
+ ];
1154
+
1155
+ const amountsForBuy = [
1156
+ 0n,
1157
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
1158
+ ];
1159
+
1160
+ beforeAll(async () => {
1161
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
1162
+ balancerV3 = new BalancerV3(network, dexKey, dexHelper);
1163
+ if (balancerV3.initializePricing) {
1164
+ await balancerV3.initializePricing(blockNumber);
1165
+ }
1166
+ });
1167
+
1168
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
1169
+ await testPricingOnNetwork(
1170
+ balancerV3,
1171
+ network,
1172
+ dexKey,
1173
+ blockNumber,
1174
+ srcTokenSymbol,
1175
+ destTokenSymbol,
1176
+ SwapSide.SELL,
1177
+ amountsForSell,
1178
+ );
1179
+ });
1180
+
1181
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
1182
+ await testPricingOnNetwork(
1183
+ balancerV3,
1184
+ network,
1185
+ dexKey,
1186
+ blockNumber,
1187
+ srcTokenSymbol,
1188
+ destTokenSymbol,
1189
+ SwapSide.BUY,
1190
+ amountsForBuy,
1191
+ );
1192
+ });
1193
+ });
1194
+ });
1062
1195
  });
1063
1196
  });
1064
1197