Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Rebasable token to Optimism #58

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
3256d9f
create new contract that represents stETH on L2
kovalgek Oct 10, 2023
e4b2cbd
add wrap/unwrap functions
kovalgek Oct 11, 2023
82038ea
add shares to rebasable token
kovalgek Oct 13, 2023
380caaa
add unit tests
kovalgek Oct 17, 2023
eab8718
add deposit flow for new rebasable token
kovalgek Nov 4, 2023
c3bc0db
add withdraw flow for rebasable token on optimism
kovalgek Nov 5, 2023
eb98d0b
send rate in data and time during deposit flow
kovalgek Nov 9, 2023
800e33f
add possibility to depost 0 tokens
kovalgek Nov 9, 2023
d9ac556
init structs
kovalgek Nov 9, 2023
ddb9ca3
add comments
kovalgek Dec 11, 2023
a73bcf4
add gas test
kovalgek Dec 11, 2023
6d37edc
update gas test
kovalgek Dec 12, 2023
8098fe1
fix tests
kovalgek Dec 16, 2023
3335339
add token rate oracle
kovalgek Dec 20, 2023
86037dc
add tests for new token, renaming
kovalgek Dec 24, 2023
86788b2
simplify oracle, remove warnings
kovalgek Dec 27, 2023
ddffe1f
update unit tests for token rate oracle
kovalgek Dec 28, 2023
7c79d2d
fix integration tests for rebasable token
kovalgek Jan 9, 2024
6174943
Merge branch 'main' into feature/add_stETH_token_to_optimism
kovalgek Jan 9, 2024
f0b891a
add test for push token rate method
kovalgek Jan 9, 2024
e314bb1
unused return values fix
kovalgek Jan 9, 2024
4b56ccf
fix deployment scripts for new oracle and token
kovalgek Jan 9, 2024
3b82da7
add hearbeat to oracle
kovalgek Jan 10, 2024
171db5a
pr fixes from first rount review: apply unstructured storage in token…
kovalgek Jan 22, 2024
76b4ff3
PR fixes: fix comments, rename interface, abstract wst
kovalgek Jan 29, 2024
7abf60f
use real implemnations of non rebasable token and oracle contracts in…
kovalgek Feb 2, 2024
707da9b
update unit tests for bridges
kovalgek Feb 8, 2024
1cb344a
fix evetns + formating
kovalgek Feb 13, 2024
f9463f0
Merge branch 'main' into feature/add_stETH_token_to_optimism
kovalgek Feb 29, 2024
3fd1e94
move token rate to the base contract
kovalgek Mar 6, 2024
66b2501
use inheritance for token rate in l1 bridge, fix e2e tests
kovalgek Mar 6, 2024
7badd9e
add rebasable token e2e tests
kovalgek Mar 6, 2024
72bc8f3
add bridging-to e2e tests for rebasable token
kovalgek Mar 6, 2024
83e292b
add token rate observer
kovalgek Mar 7, 2024
dbf2f92
add observers array
kovalgek Mar 14, 2024
47c50c6
add factory and tests
kovalgek Mar 18, 2024
7e45410
add unit tests for notifier
kovalgek Mar 19, 2024
55111b8
add token rate pusher
kovalgek Mar 22, 2024
d99a52f
update unit tests for token rate oracle
kovalgek Mar 22, 2024
fb3eb40
remove observer array
kovalgek Mar 22, 2024
b167ebd
fix token rate publicher and notifier unit tests
kovalgek Mar 22, 2024
55d2e3f
fix small comments from PR review
kovalgek Mar 22, 2024
13712ca
feat(steth): intermediate work on adding ERC-2612/EIP-1271 permit
arwer13 Mar 27, 2024
6a46704
update optimism sdk version to fix integration tests
kovalgek Mar 29, 2024
b9d5e56
update addresses to run e2e tests
kovalgek Mar 29, 2024
a3f4544
fix integration test
kovalgek Mar 29, 2024
e2c29e0
deployment scripts
kovalgek Apr 1, 2024
d28d53d
Merge branch 'feature/add_stETH_token_to_optimism' into feat/steth-pe…
arwer13 Apr 1, 2024
0d2df1d
add token rate oracle integration tests
kovalgek Apr 1, 2024
8dc246e
fix happy path test for permit for rebasable
arwer13 Apr 2, 2024
ba0b41e
test(rebasable permit): move the rest tests from core stethpermit.tes…
arwer13 Apr 2, 2024
18a1dc5
add e2e tests for oracle
kovalgek Apr 2, 2024
624219c
Merge pull request #74 from lidofinance/feat/steth-permit
kovalgek Apr 2, 2024
5f86091
remove increaseAllowance and decreaseAllowance from tokens
kovalgek Apr 3, 2024
cc868ef
change function names
kovalgek Apr 3, 2024
06d00c7
rename stETH to rebasable token in env
kovalgek Apr 3, 2024
0b22b0f
deploy all script, refactor other deploy scripts
kovalgek Apr 8, 2024
f563fab
add permit to non-rebasable token
kovalgek Apr 9, 2024
3332e30
add unit tests for non-rebasable token
kovalgek Apr 10, 2024
0545e33
PR fixes: fix comments, readme, rename bridges, notifier refactoring
kovalgek Apr 10, 2024
a55b5f0
use mapping for tokens in bridges
kovalgek Apr 15, 2024
f54eecd
fix bridge unit and integration tests, remove mapping in storing toke…
kovalgek Apr 15, 2024
bc1c56f
fix scripts
kovalgek Apr 15, 2024
b62fbee
PR fixes: add comments, rename constracts, more interfaces to contrac…
kovalgek Apr 15, 2024
f387de6
PR fixes: rename tokens, add sanity check to oracle update, add unit …
kovalgek Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change function names
  • Loading branch information
kovalgek committed Apr 3, 2024
commit cc868ef046985ed7b8e225bfe99f8f93a09e9fc5
4 changes: 2 additions & 2 deletions contracts/optimism/L2ERC20TokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract L2ERC20TokenBridge is
ITokenRateOracle tokenRateOracle = ERC20Rebasable(L2_TOKEN_REBASABLE).TOKEN_RATE_ORACLE();
tokenRateOracle.updateRate(depositData.rate, depositData.timestamp);

ERC20Rebasable(L2_TOKEN_REBASABLE).mintShares(to_, amount_);
ERC20Rebasable(L2_TOKEN_REBASABLE).bridgeMintShares(to_, amount_);

uint256 rebasableTokenAmount = ERC20Rebasable(L2_TOKEN_REBASABLE).getTokensByShares(amount_);
emit DepositFinalized(
Expand Down Expand Up @@ -131,7 +131,7 @@ contract L2ERC20TokenBridge is
) internal {
if (l2Token_ == L2_TOKEN_REBASABLE) {
uint256 shares = ERC20Rebasable(L2_TOKEN_REBASABLE).getSharesByTokens(amount_);
ERC20Rebasable(L2_TOKEN_REBASABLE).burnShares(msg.sender, shares);
ERC20Rebasable(L2_TOKEN_REBASABLE).bridgeBurnShares(msg.sender, shares);

_initiateWithdrawal(
L1_TOKEN_REBASABLE,
Expand Down
4 changes: 2 additions & 2 deletions contracts/token/ERC20Rebasable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ contract ERC20Rebasable is IERC20, IERC20Wrapper, IERC20BridgedShares, ERC20Meta
}

/// @inheritdoc IERC20BridgedShares
function mintShares(address account_, uint256 amount_) external onlyBridge {
function bridgeMintShares(address account_, uint256 amount_) external onlyBridge {
_mintShares(account_, amount_);
}

/// @inheritdoc IERC20BridgedShares
function burnShares(address account_, uint256 amount_) external onlyBridge {
function bridgeBurnShares(address account_, uint256 amount_) external onlyBridge {
_burnShares(account_, amount_);
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/token/interfaces/IERC20BridgedShares.sol
kovalgek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ interface IERC20BridgedShares is IERC20 {
/// @notice Creates amount_ shares and assigns them to account_, increasing the total shares supply
/// @param account_ An address of the account to mint shares
/// @param amount_ An amount of shares to mint
function mintShares(address account_, uint256 amount_) external;
function bridgeMintShares(address account_, uint256 amount_) external;

/// @notice Destroys amount_ shares from account_, reducing the total shares supply
/// @param account_ An address of the account to burn shares
/// @param amount_ An amount of shares to burn
function burnShares(address account_, uint256 amount_) external;
function bridgeBurnShares(address account_, uint256 amount_) external;
}
2 changes: 1 addition & 1 deletion test/token/ERC20Permit.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ function ctxFactoryFactory(signingAccountsFuncFactory: typeof getAccountsEIP1271
);

await tokenRateOracle.connect(owner).updateRate(rate, 1000);
await rebasableProxied.connect(owner).mintShares(holder.address, premintShares);
await rebasableProxied.connect(owner).bridgeMintShares(holder.address, premintShares);
const { alice, bob } = await signingAccountsFuncFactory();

return {
Expand Down
28 changes: 14 additions & 14 deletions test/token/ERC20Rebasable.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ unit("ERC20Rebasable", ctxFactory)
await assert.revertsWith(rebasableProxied.connect(user1).unwrap(wei`4 ether`), "ErrorNotEnoughBalance()");
})

.test("mintShares() :: happy path", async (ctx) => {
.test("bridgeMintShares() :: happy path", async (ctx) => {

const { rebasableProxied } = ctx.contracts;
const {user1, user2, owner } = ctx.accounts;
Expand All @@ -358,7 +358,7 @@ unit("ERC20Rebasable", ctxFactory)
assert.equalBN(await rebasableProxied.sharesOf(user1.address), 0);
assert.equalBN(await rebasableProxied.balanceOf(user1.address), 0);

const tx0 = await rebasableProxied.connect(owner).mintShares(user1.address, user1SharesToMint);
const tx0 = await rebasableProxied.connect(owner).bridgeMintShares(user1.address, user1SharesToMint);

assert.equalBN(await rebasableProxied.sharesOf(user1.address), user1SharesToMint);
assert.equalBN(await rebasableProxied.balanceOf(user1.address), user1TokensMinted);
Expand All @@ -374,7 +374,7 @@ unit("ERC20Rebasable", ctxFactory)
assert.equalBN(await rebasableProxied.sharesOf(user2.address), 0);
assert.equalBN(await rebasableProxied.balanceOf(user2.address), 0);

const tx1 = await rebasableProxied.connect(owner).mintShares(user2.address, user2SharesToMint);
const tx1 = await rebasableProxied.connect(owner).bridgeMintShares(user2.address, user2SharesToMint);

assert.equalBN(await rebasableProxied.sharesOf(user2.address), user2SharesToMint);
assert.equalBN(await rebasableProxied.balanceOf(user2.address), user2TokensMinted);
Expand All @@ -384,7 +384,7 @@ unit("ERC20Rebasable", ctxFactory)
assert.equalBN(await rebasableProxied.totalSupply(), premintTokens.add(user1TokensMinted).add(user2TokensMinted));
})

.test("burnShares() :: happy path", async (ctx) => {
.test("bridgeBurnShares() :: happy path", async (ctx) => {

const { rebasableProxied } = ctx.contracts;
const {user1, user2, owner } = ctx.accounts;
Expand All @@ -406,11 +406,11 @@ unit("ERC20Rebasable", ctxFactory)
assert.equalBN(await rebasableProxied.sharesOf(user1.address), 0);
assert.equalBN(await rebasableProxied.balanceOf(user1.address), 0);

await rebasableProxied.connect(owner).mintShares(user1.address, user1SharesToMint);
await rebasableProxied.connect(owner).bridgeMintShares(user1.address, user1SharesToMint);
assert.equalBN(await rebasableProxied.sharesOf(user1.address), user1SharesToMint);
assert.equalBN(await rebasableProxied.balanceOf(user1.address), user1TokensMinted);

await rebasableProxied.connect(owner).burnShares(user1.address, user1SharesToBurn);
await rebasableProxied.connect(owner).bridgeBurnShares(user1.address, user1SharesToBurn);
assert.equalBN(await rebasableProxied.sharesOf(user1.address), user1Shares);
assert.equalBN(await rebasableProxied.balanceOf(user1.address), user1Tokens);

Expand All @@ -431,10 +431,10 @@ unit("ERC20Rebasable", ctxFactory)
assert.equalBN(await rebasableProxied.sharesOf(user2.address), 0);
assert.equalBN(await rebasableProxied.balanceOf(user2.address), 0);

await rebasableProxied.connect(owner).mintShares(user2.address, user2SharesToMint);
await rebasableProxied.connect(owner).bridgeMintShares(user2.address, user2SharesToMint);
assert.equalBN(await rebasableProxied.sharesOf(user2.address), user2SharesToMint);
assert.equalBN(await rebasableProxied.balanceOf(user2.address), user2TokensMinted);
await rebasableProxied.connect(owner).burnShares(user2.address, user2SharesToBurn);
await rebasableProxied.connect(owner).bridgeBurnShares(user2.address, user2SharesToBurn);
assert.equalBN(await rebasableProxied.sharesOf(user2.address), user2Shares);
assert.equalBN(await rebasableProxied.balanceOf(user2.address), user2Tokens);

Expand Down Expand Up @@ -713,7 +713,7 @@ unit("ERC20Rebasable", ctxFactory)
await assert.revertsWith(
rebasableProxied
.connect(stranger)
.mintShares(stranger.address, wei`1000 ether`),
.bridgeMintShares(stranger.address, wei`1000 ether`),
"ErrorNotBridge()"
);
})
Expand All @@ -734,7 +734,7 @@ unit("ERC20Rebasable", ctxFactory)
// mint tokens
const tx = await rebasableProxied
.connect(owner)
.mintShares(recipient.address, mintAmount);
.bridgeMintShares(recipient.address, mintAmount);

// validate Transfer event was emitted
await assert.emits(rebasableProxied, tx, "Transfer", [
Expand Down Expand Up @@ -762,7 +762,7 @@ unit("ERC20Rebasable", ctxFactory)
const { holder, stranger } = ctx.accounts;

await assert.revertsWith(
rebasableProxied.connect(stranger).burnShares(holder.address, wei`100 ether`),
rebasableProxied.connect(stranger).bridgeBurnShares(holder.address, wei`100 ether`),
"ErrorNotBridge()"
);
})
Expand All @@ -775,7 +775,7 @@ unit("ERC20Rebasable", ctxFactory)
assert.equalBN(await rebasableProxied.balanceOf(stranger.address), 0);

await assert.revertsWith(
rebasableProxied.connect(owner).burnShares(stranger.address, wei`100 ether`),
rebasableProxied.connect(owner).bridgeBurnShares(stranger.address, wei`100 ether`),
"ErrorNotEnoughBalance()"
);
})
Expand All @@ -796,7 +796,7 @@ unit("ERC20Rebasable", ctxFactory)
// burn tokens
const tx = await rebasableProxied
.connect(owner)
.burnShares(holder.address, burnAmount);
.bridgeBurnShares(holder.address, burnAmount);

// validate Transfer event was emitted
await assert.emits(rebasableProxied, tx, "Transfer", [
Expand Down Expand Up @@ -886,7 +886,7 @@ async function ctxFactory() {
);

await tokenRateOracle.connect(owner).updateRate(rate, 1000);
await rebasableProxied.connect(owner).mintShares(holder.address, premintShares);
await rebasableProxied.connect(owner).bridgeMintShares(holder.address, premintShares);

return {
accounts: { deployer, owner, recipient, spender, holder, stranger, zero, user1, user2 },
Expand Down