Skip to content

Commit

Permalink
Restore CSP v5 deprecated task for ZKEVM. (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
jubeira authored Nov 28, 2023
1 parent 046a1e2 commit 42a7877
Show file tree
Hide file tree
Showing 10 changed files with 216,285 additions and 50 deletions.
101 changes: 51 additions & 50 deletions README.md

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions action-ids/zkevm/action-ids.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,31 @@
"updateTokenRateCache(address)": "0xd0547cf0b3b617880170eef83bcd448ffc9461adc5ce16e7d3317761caa857b5"
}
}
},
"20230711-zkevm-composable-stable-pool-v5": {
"ComposableStablePoolFactory": {
"useAdaptor": false,
"actionIds": {
"create(string,string,address[],uint256,address[],uint256[],bool,uint256,address,bytes32)": "0xec55a48979fccaafa3f4f81d987cc5aa26dfa67ce20b1cf608c13cc65459ed2f",
"disable()": "0x0ebf042d38f8e1bb630c3010c686232d7334f90360a82eb23623fd01fbe8e656"
}
},
"ComposableStablePool": {
"useAdaptor": false,
"factoryOutput": "0x7682e108Cd89d86303625c8478c21Ff86f401166",
"actionIds": {
"disableRecoveryMode()": "0xcfd45e344ead8485b80a5f9da66791663c8306984e9c6dc12eda2ee747cce604",
"enableRecoveryMode()": "0x6fa5acf6e6e303c2d281bf1af5f4d83642a125c5a3308cdf67e956bec276b69e",
"pause()": "0xa5d55e5978cb5ab0a8b23eed8889931ca33b54522edde10e348f4f96d35f0b35",
"setAssetManagerPoolConfig(address,bytes)": "0x1a08d4fef97815fd30114a34ff1dbaa267e682388735fb00569f31d02a4d0d9e",
"setSwapFeePercentage(uint256)": "0x04dd8b85ae9bff95ec24f18269d23bd2d04784d5f5d8b35261545b82ed754a85",
"setTokenRateCacheDuration(address,uint256)": "0x7b56c5989d833cd81dc8cdee3b496b2e2cdda79cf4d997ef95af7935fa9b95c9",
"startAmplificationParameterUpdate(uint256,uint256)": "0x1307ea331d8ab1feffafb967ddf20c66fd92ce496eda1de129a4608d4b40f313",
"stopAmplificationParameterUpdate()": "0xbd408e756684e5ea83089ee33aa05ce9410b392967bffc71c11fb394026e7a09",
"unpause()": "0x5e9c83a38e2aa43bce79848361fda74693ac9eca5e6ff6cf2ad39c86ecdfceb1",
"updateProtocolFeePercentageCache()": "0xa35ca9dc4af67afbb6992c78233d02daa500481d3cfed81539f595ce19bc505d",
"updateTokenRateCache(address)": "0x9226ad212b6e5d50f04b34634f2363e4ccbe08b7d4d3e9b8ec0733a66655af3b"
}
}
}
}
13 changes: 13 additions & 0 deletions addresses/zkevm.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,19 @@
],
"status": "ACTIVE"
},
"20230711-zkevm-composable-stable-pool-v5": {
"contracts": [
{
"name": "ComposableStablePoolFactory",
"address": "0x956CCab09898C0AF2aCa5e6C229c3aD4E93d9288"
},
{
"name": "MockComposableStablePool",
"address": "0x7682e108Cd89d86303625c8478c21Ff86f401166"
}
],
"status": "DEPRECATED"
},
"20230712-child-chain-gauge-checkpointer": {
"contracts": [
{
Expand Down
2 changes: 2 additions & 0 deletions deployment-txs/zkevm.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"0x522Ee506a2f63D0AE1D79D6F5Dbd9d0bCA32C866": "0xa79615f44a51744d7a88727c21cc2f2b32914cf06443e9299e83d7e67e8f67ec",
"0xEF454a7B3f965D3f6723E462405246f8Cd865425": "0xc67442b954b3bccff60bd9be4e34162db73b393eb5a42dfff9a793b48e0f5581",
"0xE39B5e3B6D74016b2F6A9673D7d7493B6DF549d5": "0x6de4c45bdbae63f43f8e6c7a98f14886e5c9a1c9209d3027dd84eb09d316322c",
"0x956CCab09898C0AF2aCa5e6C229c3aD4E93d9288": "0xbc3767b1d7160745b5a639f64b7b2e1ce846ccb4d752f1671de2c3f69e356ac8",
"0x7682e108Cd89d86303625c8478c21Ff86f401166": "0x4500a03073083022825d2b4ca917a61aabe4ce548e5e08347c31d3d3cec9c8fc",
"0x6d3197d069F8F9f1Fe7e23665Bc64CB77ED8b089": "0xb1edcb48a2d058a6954a2f7e9748413009a3e71e6fa766a8e92f36dceb5a561a",
"0x85a80afee867aDf27B50BdB7b76DA70f1E853062": "0x03f89cc9f24f9cf499c7cacc8bfe6b58ec10b0c2eb9f35bf93884156a0b36565",
"0x4132f7AcC9dB7A6cF7BE2Dd3A9DC8b30C7E6E6c8": "0xe868e012256f6fdf2c453012871555dc97e06388cf1b2252ad1ec6ffff4b3a31",
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions tasks/deprecated/20230711-zkevm-composable-stable-pool-v5/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Task, TaskMode, TaskRunOptions } from '@src';
import { ComposableStablePoolDeployment } from './input';

import { ZERO_ADDRESS, ZERO_BYTES32 } from '@helpers/constants';
import { bn } from '@helpers/numbers';
import * as expectEvent from '@helpers/expectEvent';
import { getContractDeploymentTransactionHash, saveContractDeploymentTransactionHash } from '@src';
import { ethers } from 'hardhat';

export default async (task: Task, { force, from }: TaskRunOptions = {}): Promise<void> => {
const input = task.input() as ComposableStablePoolDeployment;

const args = [input.Vault, input.ProtocolFeePercentagesProvider, input.FactoryVersion, input.PoolVersion];
const factory = await task.deployAndVerify('ComposableStablePoolFactory', args, from, force);

if (task.mode === TaskMode.LIVE) {
// We also create a Pool using the factory and verify it, to let us compute their action IDs and so that future
// Pools are automatically verified. We however don't run any of this code in CHECK mode, since we don't care about
// the contracts deployed here. The action IDs will be checked to be correct via a different mechanism.

// The pauseWindowDuration and bufferPeriodDuration will be filled in later, but we need to declare them here to
// appease the type system. Those are constructor arguments, but automatically provided by the factory.

const mockPoolArgs = {
vault: input.Vault,
protocolFeeProvider: input.ProtocolFeePercentagesProvider,
name: 'DO NOT USE - Mock Composable Stable Pool',
symbol: 'TEST',
tokens: [input.WETH, input.BAL].sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
}),
rateProviders: [ZERO_ADDRESS, ZERO_ADDRESS],
tokenRateCacheDurations: [0, 0],
exemptFromYieldProtocolFeeFlag: false,
amplificationParameter: bn(100),
swapFeePercentage: bn(1e12),
pauseWindowDuration: undefined,
bufferPeriodDuration: undefined,
owner: ZERO_ADDRESS,
version: input.PoolVersion,
};

// This mimics the logic inside task.deploy
if (force || !task.output({ ensure: false })['MockComposableStablePool']) {
const poolCreationReceipt = await (
await factory.create(
mockPoolArgs.name,
mockPoolArgs.symbol,
mockPoolArgs.tokens,
mockPoolArgs.amplificationParameter,
mockPoolArgs.rateProviders,
mockPoolArgs.tokenRateCacheDurations,
mockPoolArgs.exemptFromYieldProtocolFeeFlag,
mockPoolArgs.swapFeePercentage,
mockPoolArgs.owner,
ZERO_BYTES32
)
).wait();
const event = expectEvent.inReceipt(poolCreationReceipt, 'PoolCreated');
const mockPoolAddress = event.args.pool;

await saveContractDeploymentTransactionHash(mockPoolAddress, poolCreationReceipt.transactionHash, task.network);
await task.save({ MockComposableStablePool: mockPoolAddress });
}

const mockPool = await task.instanceAt('ComposableStablePool', task.output()['MockComposableStablePool']);

// In order to verify the Pool's code, we need to complete its constructor arguments by computing the factory
// provided arguments (pause durations).

// The durations require knowing when the Pool was created, so we look for the timestamp of its creation block.
const txHash = await getContractDeploymentTransactionHash(mockPool.address, task.network);
const tx = await ethers.provider.getTransactionReceipt(txHash);
const poolCreationBlock = await ethers.provider.getBlock(tx.blockNumber);

// With those and the period end times, we can compute the durations.
const { pauseWindowEndTime, bufferPeriodEndTime } = await mockPool.getPausedState();
mockPoolArgs.pauseWindowDuration = pauseWindowEndTime.sub(poolCreationBlock.timestamp);
mockPoolArgs.bufferPeriodDuration = bufferPeriodEndTime
.sub(poolCreationBlock.timestamp)
.sub(mockPoolArgs.pauseWindowDuration);

// We are now ready to verify the Pool
await task.verify('ComposableStablePool', mockPool.address, [mockPoolArgs]);
}
};
26 changes: 26 additions & 0 deletions tasks/deprecated/20230711-zkevm-composable-stable-pool-v5/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Task, TaskMode } from '@src';

export type ComposableStablePoolDeployment = {
Vault: string;
ProtocolFeePercentagesProvider: string;
FactoryVersion: string;
PoolVersion: string;
WETH: string;
BAL: string;
};

const Vault = new Task('20210418-vault', TaskMode.READ_ONLY);
const ProtocolFeePercentagesProvider = new Task('20220725-protocol-fee-percentages-provider', TaskMode.READ_ONLY);
const WETH = new Task('00000000-tokens', TaskMode.READ_ONLY);
const BAL = new Task('00000000-tokens', TaskMode.READ_ONLY);

const BaseVersion = { version: 5, deployment: '20230711-composable-stable-pool-v5' };

export default {
Vault,
ProtocolFeePercentagesProvider,
WETH,
BAL,
FactoryVersion: JSON.stringify({ name: 'ComposableStablePoolFactory', ...BaseVersion }),
PoolVersion: JSON.stringify({ name: 'ComposableStablePool', ...BaseVersion }),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ComposableStablePoolFactory": "0x956CCab09898C0AF2aCa5e6C229c3aD4E93d9288",
"MockComposableStablePool": "0x7682e108Cd89d86303625c8478c21Ff86f401166"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 2023-07-11 - Composable Stable Pool V5 (Polygon ZKEVM)

> ⚠️ **DEPRECATED** ⚠️
>
> This version has been replaced just for Polygon ZKEVM chain after the Dragon Fruit hard fork.
> The new deployment can be found [here](../../20230711-composable-stable-pool-v5/), and the build info is exactly the same. The deprecated task is kept to preserve a record of the old deployment addresses and action IDs.
Deployment of `ComposableStablePoolFactory`, which supersedes `20230320-composable-stable-pool-v4`.
This version is resilient to abrupt changes in the value reported by the pool tokens' rate providers, and calculates
protocol fees appropriately even with volatile or rapidly changing token rates.
It also disables individual flags for yield-exempt tokens; now the pool is either yield exempt or non-exempt for every
token.

## Useful Files

- [Polygon zkeVM mainnet addresses](./output/zkevm.json)
- [`ComposableStablePoolFactory` artifact](./artifact/ComposableStablePoolFactory.json)

0 comments on commit 42a7877

Please sign in to comment.