Skip to content

Commit d93dfe7

Browse files
authored
ESP: Remove weight resync (#110)
1 parent 35d7eb5 commit d93dfe7

File tree

5 files changed

+41
-116
lines changed

5 files changed

+41
-116
lines changed

contracts/liquidity/ElasticSupplyPool.sol

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -96,67 +96,12 @@ contract ElasticSupplyPool is ConfigurableRightsPool {
9696
}
9797

9898
/*
99-
* @param token The address of the token in the underlying BPool to be weight adjusted.
100-
* @dev Checks if the token's current pool balance has deviated from cached balance,
101-
* if so it adjusts the token's weights proportional to the deviation.
102-
* The underlying BPool enforces bounds on MIN_WEIGHTS=1e18, MAX_WEIGHT=50e18 and TOTAL_WEIGHT=50e18.
103-
* NOTE: The BPool.rebind function CAN REVERT if the updated weights go beyond the enforced bounds.
99+
* @param token The address of the token in the underlying BPool to be resynced
104100
*/
105101
function resyncWeight(address token) external logs lock needsBPool {
106-
// NOTE: Skipping gradual update check
107-
// Pool will never go into gradual update state as `updateWeightsGradually` is disabled
108-
// require(
109-
// ConfigurableRightsPool.gradualUpdate.startBlock == 0,
110-
// "ERR_NO_UPDATE_DURING_GRADUAL");
111-
112102
require(IBPool(address(bPool)).isBound(token), "ERR_NOT_BOUND");
113103

114-
// get cached balance
115-
uint256 tokenBalanceBefore = IBPool(address(bPool)).getBalance(token);
116-
117104
// sync balance
118105
IBPool(address(bPool)).gulp(token);
119-
120-
// get new balance
121-
uint256 tokenBalanceAfter = IBPool(address(bPool)).getBalance(token);
122-
123-
// No-Op
124-
if (tokenBalanceBefore == tokenBalanceAfter) {
125-
return;
126-
}
127-
128-
// current token weight
129-
uint256 tokenWeightBefore = IBPool(address(bPool)).getDenormalizedWeight(token);
130-
131-
// target token weight = RebaseRatio * previous token weight
132-
uint256 tokenWeightTarget = BalancerSafeMath.bdiv(
133-
BalancerSafeMath.bmul(tokenWeightBefore, tokenBalanceAfter),
134-
tokenBalanceBefore
135-
);
136-
137-
// new token weight = sqrt(current token weight * target token weight)
138-
uint256 tokenWeightAfter = BalancerSafeMath.sqrt(
139-
BalancerSafeMath.bdiv(BalancerSafeMath.bmul(tokenWeightBefore, tokenWeightTarget), 1)
140-
);
141-
142-
address[] memory tokens = IBPool(address(bPool)).getCurrentTokens();
143-
for (uint256 i = 0; i < tokens.length; i++) {
144-
if (tokens[i] == token) {
145-
// adjust weight
146-
IBPool(address(bPool)).rebind(token, tokenBalanceAfter, tokenWeightAfter);
147-
} else {
148-
uint256 otherWeightBefore = IBPool(address(bPool)).getDenormalizedWeight(tokens[i]);
149-
uint256 otherBalance = bPool.getBalance(tokens[i]);
150-
151-
// other token weight = (new token weight * other token weight before) / target token weight
152-
uint256 otherWeightAfter = BalancerSafeMath.bdiv(
153-
BalancerSafeMath.bmul(tokenWeightAfter, otherWeightBefore),
154-
tokenWeightTarget
155-
);
156-
157-
// adjust weight
158-
IBPool(address(bPool)).rebind(tokens[i], otherBalance, otherWeightAfter);
159-
}
160-
}
161106
}
162107
}

test/integration/audius.test.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ describe('Audius Integration Test', () => {
167167
const protocolFees = percOf2(increase, protocolFeesPercent)
168168
const newStake = deposit.add(initialStake).add(increase)
169169
const newStakeMinusFees = newStake.sub(liquidityFees.add(protocolFees))
170-
const percDiv = ethers.utils.parseEther('1')
171170
let totalShares: BigNumber = ethers.utils.parseEther('1')
172171
let tx: ContractTransaction
173172

@@ -193,15 +192,12 @@ describe('Audius Integration Test', () => {
193192
expect(await TenderToken.balanceOf(BPool.address)).to.eq(sharesToTokens(shares, totalShares, await TenderToken.totalSupply()))
194193
})
195194

196-
it('changes the weights of the AMM', async () => {
197-
const tBal = await TenderToken.balanceOf(BPool.address)
198-
const bal = await AudiusToken.balanceOf(BPool.address)
199-
200-
const acceptableDelta = ethers.BigNumber.from('100')
195+
it('steak balance stays the same', async () => {
196+
expect(await AudiusToken.balanceOf(BPool.address)).to.eq(initialStake)
197+
})
201198

202-
const expected = tBal.mul(percDiv).div(tBal.add(bal))
203-
const actual = await BPool.getNormalizedWeight(TenderToken.address)
204-
expect(actual.sub(expected).abs()).to.be.lte(acceptableDelta)
199+
it('weights of the AMM stay 50-50', async () => {
200+
expect(await BPool.getNormalizedWeight(TenderToken.address)).to.be.eq(ethers.utils.parseEther('1').div(2))
205201
})
206202

207203
it('should emit RewardsClaimed event from Tenderizer', async () => {
@@ -212,7 +208,6 @@ describe('Audius Integration Test', () => {
212208
describe('stake decrease', () => {
213209
// The decrease will offset the increase from the previous test
214210
const newStake = deposit.add(initialStake)
215-
const percDiv = ethers.utils.parseEther('1')
216211
let totalShares: BigNumber
217212
let oldPrinciple: BigNumber
218213

@@ -246,12 +241,12 @@ describe('Audius Integration Test', () => {
246241
expect(await TenderToken.balanceOf(BPool.address)).to.eq(sharesToTokens(shares, totalShares, await TenderToken.totalSupply()))
247242
})
248243

249-
it('changes the weights of the AMM', async () => {
250-
const acceptableDelta = ethers.BigNumber.from('100')
244+
it('steak balance stays the same', async () => {
245+
expect(await AudiusToken.balanceOf(BPool.address)).to.eq(initialStake)
246+
})
251247

252-
const expected = percDiv.div(2)
253-
const actual = await BPool.getNormalizedWeight(TenderToken.address)
254-
expect(actual.sub(expected).abs()).to.be.lte(acceptableDelta)
248+
it('weights of the AMM stay 50-50', async () => {
249+
expect(await BPool.getNormalizedWeight(TenderToken.address)).to.be.eq(ethers.utils.parseEther('1').div(2))
255250
})
256251

257252
it('should emit RewardsClaimed event from Tenderizer with 0 rewards and currentPrinciple', async () => {

test/integration/graph.test.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ describe('Graph Integration Test', () => {
163163
const protocolFees = percOf2(increase, protocolFeesPercent)
164164
const newStake = deposit.add(initialStake).add(increase)
165165
const newStakeMinusFees = newStake.sub(liquidityFees.add(protocolFees))
166-
const percDiv = ethers.utils.parseEther('1')
167166
let totalShares: BigNumber = ethers.utils.parseEther('1')
168167
let tx: ContractTransaction
169168

@@ -203,15 +202,12 @@ describe('Graph Integration Test', () => {
203202
expect(await TenderToken.balanceOf(BPool.address)).to.eq(sharesToTokens(shares, totalShares, await TenderToken.totalSupply()))
204203
})
205204

206-
it('changes the weights of the AMM', async () => {
207-
const tBal = await TenderToken.balanceOf(BPool.address)
208-
const bal = await GraphToken.balanceOf(BPool.address)
209-
210-
const acceptableDelta = ethers.BigNumber.from('100')
205+
it('steak balance stays the same', async () => {
206+
expect(await GraphToken.balanceOf(BPool.address)).to.eq(initialStake)
207+
})
211208

212-
const expected = tBal.mul(percDiv).div(tBal.add(bal))
213-
const actual = await BPool.getNormalizedWeight(TenderToken.address)
214-
expect(actual.sub(expected).abs()).to.be.lte(acceptableDelta)
209+
it('weights of the AMM stay 50-50', async () => {
210+
expect(await BPool.getNormalizedWeight(TenderToken.address)).to.be.eq(ethers.utils.parseEther('1').div(2))
215211
})
216212

217213
it('should emit RewardsClaimed event from Tenderizer', async () => {
@@ -222,7 +218,6 @@ describe('Graph Integration Test', () => {
222218
describe('stake decrease', () => {
223219
// The decrease will offset the increase from the previous test
224220
const newStake = deposit.add(initialStake)
225-
const percDiv = ethers.utils.parseEther('1')
226221
let totalShares: BigNumber
227222
let oldPrinciple: BigNumber
228223

@@ -270,12 +265,12 @@ describe('Graph Integration Test', () => {
270265
expect(await TenderToken.balanceOf(BPool.address)).to.eq(sharesToTokens(shares, totalShares, await TenderToken.totalSupply()))
271266
})
272267

273-
it('changes the weights of the AMM', async () => {
274-
const acceptableDelta = ethers.BigNumber.from('100')
268+
it('steak balance stays the same', async () => {
269+
expect(await GraphToken.balanceOf(BPool.address)).to.eq(initialStake)
270+
})
275271

276-
const expected = percDiv.div(2)
277-
const actual = await BPool.getNormalizedWeight(TenderToken.address)
278-
expect(actual.sub(expected).abs()).to.be.lte(acceptableDelta)
272+
it('weights of the AMM stay 50-50', async () => {
273+
expect(await BPool.getNormalizedWeight(TenderToken.address)).to.be.eq(ethers.utils.parseEther('1').div(2))
279274
})
280275

281276
it('should emit RewardsClaimed event from Tenderizer with 0 rewards and currentPrinciple', async () => {

test/integration/livepeer.test.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ describe('Livepeer Integration Test', () => {
208208
const protocolFees = percOf2(increase.add(swappedLPTRewards), protocolFeesPercent)
209209
const newStake = deposit.add(initialStake).add(increase)
210210
const newStakeMinusFees = newStake.add(swappedLPTRewards).sub(liquidityFees.add(protocolFees))
211-
const percDiv = ethers.utils.parseEther('1')
212211
let totalShares: BigNumber = ethers.utils.parseEther('1')
213212

214213
before(async () => {
@@ -234,15 +233,12 @@ describe('Livepeer Integration Test', () => {
234233
expect(await TenderToken.balanceOf(BPool.address)).to.eq(sharesToTokens(shares, totalShares, await TenderToken.totalSupply()))
235234
})
236235

237-
it('changes the weights of the AMM', async () => {
238-
const tBal = await TenderToken.balanceOf(BPool.address)
239-
const bal = await LivepeerToken.balanceOf(BPool.address)
240-
241-
const acceptableDelta = ethers.BigNumber.from('100')
236+
it('steak balance stays the same', async () => {
237+
expect(await LivepeerToken.balanceOf(BPool.address)).to.eq(initialStake)
238+
})
242239

243-
const expected = tBal.mul(percDiv).div(tBal.add(bal))
244-
const actual = await BPool.getNormalizedWeight(TenderToken.address)
245-
expect(actual.sub(expected).abs()).to.be.lte(acceptableDelta)
240+
it('weights of the AMM stay 50-50', async () => {
241+
expect(await BPool.getNormalizedWeight(TenderToken.address)).to.be.eq(ethers.utils.parseEther('1').div(2))
246242
})
247243

248244
it('does not withdraw fees is less than threshold', async () => {
@@ -260,7 +256,6 @@ describe('Livepeer Integration Test', () => {
260256
describe('stake decrease', () => {
261257
// The decrease will offset the increase from the previous test
262258
const newStake = deposit.add(initialStake)
263-
const percDiv = ethers.utils.parseEther('1')
264259
let totalShares: BigNumber
265260
let oldPrinciple: BigNumber
266261

@@ -293,12 +288,12 @@ describe('Livepeer Integration Test', () => {
293288
expect(await TenderToken.balanceOf(BPool.address)).to.eq(sharesToTokens(shares, totalShares, await TenderToken.totalSupply()))
294289
})
295290

296-
it('changes the weights of the AMM', async () => {
297-
const acceptableDelta = ethers.BigNumber.from('100')
291+
it('steak balance stays the same', async () => {
292+
expect(await LivepeerToken.balanceOf(BPool.address)).to.eq(initialStake)
293+
})
298294

299-
const expected = percDiv.div(2)
300-
const actual = await BPool.getNormalizedWeight(TenderToken.address)
301-
expect(actual.sub(expected).abs()).to.be.lte(acceptableDelta)
295+
it('weights of the AMM stay 50-50', async () => {
296+
expect(await BPool.getNormalizedWeight(TenderToken.address)).to.be.eq(ethers.utils.parseEther('1').div(2))
302297
})
303298

304299
it('should emit RewardsClaimed event from Tenderizer with 0 rewards and currentPrinciple', async () => {

test/integration/matic.test.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ describe('Matic Integration Test', () => {
207207
const protocolFees = percOf2(increase, protocolFeesPercent)
208208
const newStake = deposit.add(initialStake).add(increase)
209209
const newStakeMinusFees = newStake.sub(liquidityFees.add(protocolFees))
210-
const percDiv = ethers.utils.parseEther('1')
211210
let totalShares: BigNumber
212211

213212
describe('stake increased', () => {
@@ -237,15 +236,12 @@ describe('Matic Integration Test', () => {
237236
expect(await TenderToken.balanceOf(BPool.address)).to.eq(sharesToTokens(shares, totalShares, await TenderToken.totalSupply()))
238237
})
239238

240-
it('changes the weights of the AMM', async () => {
241-
const tBal = await TenderToken.balanceOf(BPool.address)
242-
const bal = await MaticToken.balanceOf(BPool.address)
243-
244-
const acceptableDelta = ethers.BigNumber.from('100')
239+
it('steak balance stays the same', async () => {
240+
expect(await MaticToken.balanceOf(BPool.address)).to.eq(initialStake)
241+
})
245242

246-
const expected = tBal.mul(percDiv).div(tBal.add(bal))
247-
const actual = await BPool.getNormalizedWeight(TenderToken.address)
248-
expect(actual.sub(expected).abs()).to.be.lte(acceptableDelta)
243+
it('weights of the AMM stay 50-50', async () => {
244+
expect(await BPool.getNormalizedWeight(TenderToken.address)).to.be.eq(ethers.utils.parseEther('1').div(2))
249245
})
250246

251247
it('should emit RewardsClaimed event from Tenderizer', async () => {
@@ -256,7 +252,6 @@ describe('Matic Integration Test', () => {
256252
describe('stake decrease', () => {
257253
// The decrease will offset the increase from the previous test
258254
const newStake = deposit.add(initialStake)
259-
const percDiv = ethers.utils.parseEther('1')
260255
let totalShares: BigNumber
261256
let oldPrinciple: BigNumber
262257

@@ -291,12 +286,12 @@ describe('Matic Integration Test', () => {
291286
expect(await TenderToken.balanceOf(BPool.address)).to.eq(sharesToTokens(shares, totalShares, await TenderToken.totalSupply()))
292287
})
293288

294-
it('changes the weights of the AMM', async () => {
295-
const acceptableDelta = ethers.BigNumber.from('10')
289+
it('steak balance stays the same', async () => {
290+
expect(await MaticToken.balanceOf(BPool.address)).to.eq(initialStake)
291+
})
296292

297-
const expected = percDiv.div(2)
298-
const actual = await BPool.getNormalizedWeight(TenderToken.address)
299-
expect(actual.sub(expected).abs()).to.be.lte(acceptableDelta)
293+
it('weights of the AMM stay 50-50', async () => {
294+
expect(await BPool.getNormalizedWeight(TenderToken.address)).to.be.eq(ethers.utils.parseEther('1').div(2))
300295
})
301296

302297
it('should emit RewardsClaimed event from Tenderizer with 0 rewards and currentPrinciple', async () => {

0 commit comments

Comments
 (0)