Submitted by immeas, also found by bin2chen
marginTo/From is a way to both cover your position and increase your premium when opening a position. There is however a unintended limit on how much marginTo you can provide when opening a position.
When doing the swap to increase leverage, the amountToMinimum (minimum received amount) is calculated:
ParticlePositionManager::openPosition:
As you see here, a marginTo > collateralTo - cache.amountToBorrowed will underflow this calculation. Thus there is no way to provide a bigger margin than this.
A user cannot supply more margin than collateralTo - amountToBorrowed before the opening of the position reverts.
There is a workaround to supply no marginTo and then use addPremium to increase the premium but I believe this issue still breaks the intended purpose of marginTo in the openPosition call.
Test in OpenPosition.t.sol:
Consider not counting marginTo towards expected output from the swap. As shown in another issue, there are further problems with this. marginTo is the premium for the to-side of the position. Hence should not be part of the expected output of the swap as it is the safety for the position.
wukong-particle (Particle) confirmed and commented:
