> For the complete documentation index, see [llms.txt](https://docs.pinto.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pinto.money/pinto-improvements/pi-0.md).

# PI-0: Fix the PINTO:USDC Multi Flow Pump and Update Multi Flow Pump Cap Parameters

Executed on November 20, 2024 at 01:31 UTC.

## Summary <a href="#id-555e4019-aad5-83d6-afac-0173c13bd6cb" id="id-555e4019-aad5-83d6-afac-0173c13bd6cb"></a>

1. [**Multi Flow Pump**](https://basin.exchange/multi-flow-pump.pdf) **Bug:** Fix a bug in the Multi Flow Pump that caused the Pump to return incorrect data for the [PINTO](https://docs.pinto.money/resources/glossary#pinto):USDC liquidity pool.
2. **Pump Parameters:** Update the [Wells](https://basin.exchange/basin.pdf) on the [Minting Whitelist](https://docs.pinto.money/resources/glossary#minting-whitelist) to use a new Multi Flow Pump with more forgiving LP token supply and exchange rate change caps of 25% per block (2-second cap interval) in order to allow the [Flood](https://docs.pinto.money/resources/glossary#flood) to return the price to the value target in instances of greater volatility.
3. [**Deposit**](https://docs.pinto.money/resources/glossary#deposit) **Metadata:** Update the Metadata Facet to return the correct metadata.

## Links <a href="#id-192e4019-aad5-833c-87ee-810c52cb9a9a" id="id-192e4019-aad5-833c-87ee-810c52cb9a9a"></a>

* [Implementation PR](https://github.com/pinto-org/protocol/pull/1)
* Implementation Commit: [37de6ba04e161b2f20916d777fb49825413d83d5](https://github.com/pinto-org/protocol/commit/37de6ba04e161b2f20916d777fb49825413d83d5)
* [Diamond Cut Transaction](https://basescan.org/tx/0xa1666c742912e3d2dc161e574c55a3bba5ca8df26c379b5c91566dc8832ab0ef)
* [Unpause Transaction](https://basescan.org/tx/0xe7cea7e34caef8e9013773c4741bd5553eaed703581f0f645d620fb2fdb8a7e2)

## Problems <a href="#id-5d8e4019-aad5-8266-aba9-8140ded5dc51" id="id-5d8e4019-aad5-8266-aba9-8140ded5dc51"></a>

### 1. Multi Flow Pump Bug <a href="#d0de4019-aad5-820c-9259-8109060e845e" id="d0de4019-aad5-820c-9259-8109060e845e"></a>

The implementation of the Multi Flow Pump resulted in the `tryCalcLpTokenSupply` helper returning `MAX_UINT256_SQRT` (the integer square root of `uint256.max`) when the Newtonian estimation in [Stable2](https://basescan.org/address/0xBA51055a97b40d7f41f3F64b57469b5D45B67c87#code)’s `calcLpTokenSupply` failed to converge at high prices, causing the function to revert. Using this failure value in LP token supply capping produced incorrect reserve data and excessive minting.

### 2. Pump Parameters <a href="#id-622e4019-aad5-83eb-9635-01e432475915" id="id-622e4019-aad5-83eb-9635-01e432475915"></a>

During the Flood, the Well reserves hit the LP token supply and exchange rate caps. Because it took \~2 [Seasons](https://docs.pinto.money/resources/glossary#season) for the Pump values to catch up to the Pinto price, the protocol would mint more than it should’ve during the Flood.

### 3. [Deposit](https://docs.pinto.money/resources/glossary#deposit) Metadata <a href="#id-616e4019-aad5-82df-847e-81f413a22cff" id="id-616e4019-aad5-82df-847e-81f413a22cff"></a>

The ERC-1155 Deposit token was erroneously named "Beanstalk [Silo](https://docs.pinto.money/resources/glossary#silo) Deposits".

## Solutions <a href="#id-616e4019-aad5-821a-b808-0105c3fe637f" id="id-616e4019-aad5-821a-b808-0105c3fe637f"></a>

### 1. Multi Flow Pump Bug <a href="#id-0dbe4019-aad5-8311-931c-816ef4a96a72" id="id-0dbe4019-aad5-8311-931c-816ef4a96a72"></a>

Upgrade the `_capLpTokenSupply` function in Multi Flow Pump to skip LP token supply capping if calculating the LP token supply from either the previous or current reserves fails, while continuing to apply exchange-rate capping to the current reserves.

### 2. Pump Parameters <a href="#bdfe4019-aad5-825c-96a3-81fa586f6297" id="bdfe4019-aad5-825c-96a3-81fa586f6297"></a>

Upgrade the whitelisted Wells to a new Multi Flow Pump with more forgiving LP token supply and exchange rate change caps of 25% per block (previously set to approximately 0.493862% and 0.083160%, respectively), enabling the Flood to return the Pinto price to its value target in the instance of greater upside price volatility.

### 3. Deposit Metadata <a href="#id-407e4019-aad5-82bd-8812-81ab4d6c2515" id="id-407e4019-aad5-82bd-8812-81ab4d6c2515"></a>

Update the Metadata Facet to rename the ERC-1155 Deposit token from "Beanstalk Silo Deposits" to "Pinto Silo Deposits" and update its description and trait labels to use Pinto terminology.

## Rationale <a href="#id-7c9e4019-aad5-8287-b4a4-8153b62e777f" id="id-7c9e4019-aad5-8287-b4a4-8153b62e777f"></a>

### 1. Multi Flow Pump Bug <a href="#f9ce4019-aad5-8369-9157-012ebe062a18" id="f9ce4019-aad5-8369-9157-012ebe062a18"></a>

The Stable2 Well Function uses Newtonian estimations to perform complex calculations on-chain in an efficient fashion. The further away from the value target, the greater the chance that the Newtonian estimation fails to converge, in which case the function reverts. In the instance of a reversion, it is better for the `_capLpTokenSupply` function in Multi Flow Pump to skip LP token supply capping when either calculation fails because `MAX_UINT256_SQRT` is an extremely high value which can lead to the protocol overminting Pinto. The Pump continues using the current reserve values, subject to exchange-rate capping.

### 2. Pump Parameters <a href="#id-0dbe4019-aad5-82db-9f8b-812ee7d742f8" id="id-0dbe4019-aad5-82db-9f8b-812ee7d742f8"></a>

The initial caps were designed to mitigate inter-block MEV on Ethereum, where control of consecutive blocks can enable oracle manipulation. On Base, there is no MEV performed by the sequencer, and so the risk of setting the parameters capping changes too high is almost non-existent. The Multi Flow Pump’s initial conservative caps limited how quickly its reserve values could respond to market changes. During a Flood with significant upward price volatility, this lag reduced the effectiveness of the Flood in returning the Pinto price to its value target. The higher caps allow the Pump to respond more quickly while retaining limits on changes in LP token supply and exchange rates.

### 3. Deposit Metadata <a href="#id-538e4019-aad5-8338-b0d8-012d7706a3bc" id="id-538e4019-aad5-8338-b0d8-012d7706a3bc"></a>

The Deposit token metadata should identify Pinto so that wallets and interfaces display the correct protocol name.

## Contract Changes <a href="#id-296e4019-aad5-830f-be2d-813d7cd34660" id="id-296e4019-aad5-830f-be2d-813d7cd34660"></a>

### Initialization <a href="#id-4d6e4019-aad5-8229-9772-81520b413bfc" id="id-4d6e4019-aad5-8229-9772-81520b413bfc"></a>

`InitZeroWell.init(WellData[])` was called on the following contract to upgrade the whitelisted Wells to the new Pump configuration and reset their oracle snapshots:

* [`0x22Fca3f83cD9938e6d3cF5Dc5013CdBb42824150`](https://basescan.org/address/0x22Fca3f83cD9938e6d3cF5Dc5013CdBb42824150#code)

### Facet Changes <a href="#c97e4019-aad5-835c-8097-81c1b7e8241e" id="c97e4019-aad5-835c-8097-81c1b7e8241e"></a>

| Facet           | Action  | Previous Implementation                                                                                                      | New Implementation                                                                                                           |
| --------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `MetadataFacet` | Replace | [`0xbC9bbe5226e92970272Db91a7168786528D83f8c`](https://basescan.org/address/0xbC9bbe5226e92970272Db91a7168786528D83f8c#code) | [`0xf6506176A027ed4d5CdBaB23d9DFcdEC2B35b2A8`](https://basescan.org/address/0xf6506176A027ed4d5CdBaB23d9DFcdEC2B35b2A8#code) |

### Other Contract / Parameter Changes <a href="#id-78de4019-aad5-8226-96c7-815059ad5aa3" id="id-78de4019-aad5-8226-96c7-815059ad5aa3"></a>

New Multi Flow Pump: [`0xBA51AAaA66DaB6c236B356ad713f759c206DcB93`](https://basescan.org/address/0xBA51AAaA66DaB6c236B356ad713f759c206DcB93#code). The whitelisted Wells use this Pump with LP token supply and exchange rate change caps of 25% per 2-second cap interval (previously approximately 0.493862% and 0.083160%, respectively).

* `MetadataFacet` has no externally linked libraries.

### Function Changes <a href="#e74e4019-aad5-83d0-8c10-01e84d3b0631" id="e74e4019-aad5-83d0-8c10-01e84d3b0631"></a>

* Updated `_capLpTokenSupply` to skip LP token supply capping when either supply calculation fails, while continuing to apply exchange-rate capping to the current reserves.
* Updated `MetadataFacet` metadata returned by `name()` and `uri(uint256)` to identify Pinto, including the name, description, and trait labels.

### Event Changes <a href="#ba4e4019-aad5-83f1-b06f-819f58eada98" id="ba4e4019-aad5-83f1-b06f-819f58eada98"></a>

* The initializer reset each upgraded Well’s oracle snapshot and emitted `WellOracle` with zero `deltaB` and empty cumulative reserves.
