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

Mainnet Spell 2024-10-31 #435

Merged
merged 27 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
70be6eb
chore: cleanup
0xdecr1pto Oct 25, 2024
7f5e8ac
chore: add spell content
0xdecr1pto Oct 25, 2024
eeb7249
chore: update dss-tests
0xdecr1pto Oct 25, 2024
c16d97a
chore: fix deprecated fail(msg)
0xdecr1pto Oct 25, 2024
93c4455
Update src/DssSpell.sol
0xdecr1pto Oct 25, 2024
8cedb8d
Update src/DssSpell.t.sol
0xdecr1pto Oct 25, 2024
4c9f948
chore: remove duplicated chainlog update
0xdecr1pto Oct 25, 2024
1817cdf
chore: add Spark ALM Proxy
0xdecr1pto Oct 25, 2024
64a899a
chore: fix revert method
0xdecr1pto Oct 25, 2024
5d79345
chore: add spark proxy
0xdecr1pto Oct 26, 2024
34398b3
chore: refactor tests for allocator
0xdecr1pto Oct 28, 2024
0aa8bba
chore: fix review comments
0xdecr1pto Oct 28, 2024
32b158e
chore: fix pr comments]
0xdecr1pto Oct 29, 2024
f0b7a18
chore: split gov relay interfaces
0xdecr1pto Oct 29, 2024
6471532
chore: fix pr comments
0xdecr1pto Oct 29, 2024
d4e8aaf
chore: more fixes
0xdecr1pto Oct 29, 2024
0908d6c
chore: refactor bridge tests & fix pr comments
0xdecr1pto Oct 30, 2024
bec261f
chore: add missing deps
0xdecr1pto Oct 30, 2024
c80a697
chore: fix comments
0xdecr1pto Oct 30, 2024
76528f9
chore: fix typo
0xdecr1pto Oct 30, 2024
36bb2d2
chore: fix comments
0xdecr1pto Oct 30, 2024
57a5fb7
chore: fix nits
0xdecr1pto Oct 30, 2024
4465576
add deployed spell info
0xdecr1pto Oct 31, 2024
7078295
archive
0xdecr1pto Oct 31, 2024
88207c7
chore: reorder var to be able to reverify contract on ethererscan
0xdecr1pto Oct 31, 2024
1f36bfa
deploy info
0xdecr1pto Oct 31, 2024
4e44a95
archive
0xdecr1pto Oct 31, 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
553 changes: 210 additions & 343 deletions src/DssSpell.sol

Large diffs are not rendered by default.

205 changes: 204 additions & 1 deletion src/DssSpell.t.base.sol
SidestreamColdMelon marked this conversation as resolved.
Show resolved Hide resolved
SidestreamColdMelon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ import {stdStorage, StdStorage} from "forge-std/Test.sol";

import "./test/rates.sol";
import "./test/addresses_mainnet.sol";
import "./test/addresses_base.sol";
import "./test/addresses_deployers.sol";
import "./test/addresses_wallets.sol";
import "./test/config.sol";

import {DssSpell} from "./DssSpell.sol";

import {RootDomain} from "dss-test/domains/RootDomain.sol";
import {OptimismDomain} from "dss-test/domains/OptimismDomain.sol";
import {ArbitrumDomain} from "dss-test/domains/ArbitrumDomain.sol";

struct TeleportGUID {
bytes32 sourceDomain;
bytes32 targetDomain;
Expand Down Expand Up @@ -309,11 +314,69 @@ interface VoteDelegateFactoryLike {
function create() external returns (address voteDelegate);
}

interface AllocatorVaultLike {
function buffer() external view returns (address);
function draw(uint256 wad) external;
function ilk() external view returns (bytes32);
function jug() external view returns (address);
function roles() external view returns (address);
function usdsJoin() external view returns (address);
function vat() external view returns (address);
function wards(address) external view returns (uint256);
function wipe(uint256 wad) external;
}

interface AllocatorRegistryLike {
function buffers(bytes32) external view returns (address);
}

interface AllocatorRolesLike {
function ilkAdmins(bytes32) external view returns (address);
}

interface L1TokenBridgeLike {
function l1ToL2Token(address) external view returns (address);
function isOpen() external view returns (uint256);
function escrow() external view returns (address);
function otherBridge() external view returns (address);
function messenger() external view returns (address);
function version() external view returns (string memory);
function getImplementation() external view returns (address);
function bridgeERC20To(
address _localToken,
address _remoteToken,
address _to,
uint256 _amount,
uint32 _minGasLimit,
bytes memory _extraData
) external;
}

interface L2TokenBridgeLike {
function l1ToL2Token(address) external view returns (address);
function isOpen() external view returns (uint256);
function escrow() external view returns (address);
function otherBridge() external view returns (address);
function messenger() external view returns (address);
function version() external view returns (string memory);
function maxWithdraws(address) external view returns (uint256);
function getImplementation() external view returns (address);
function bridgeERC20To(
address _localToken,
address _remoteToken,
address _to,
uint256 _amount,
uint32 _minGasLimit,
bytes memory _extraData
) external;
}

contract DssSpellTestBase is Config, DssTest {
using stdStorage for StdStorage;

Rates rates = new Rates();
Addresses addr = new Addresses();
BaseAddresses base = new BaseAddresses();
Deployers deployers = new Deployers();
Wallets wallets = new Wallets();

Expand Down Expand Up @@ -361,6 +424,12 @@ contract DssSpellTestBase is Config, DssTest {

DssSpell spell;

string config;
RootDomain rootDomain;
OptimismDomain optimismDomain;
ArbitrumDomain arbitrumDomain;
OptimismDomain baseDomain;

event Debug(uint256 index, uint256 val);
event Debug(uint256 index, address addr);
event Debug(uint256 index, bytes32 what);
Expand Down Expand Up @@ -1905,6 +1974,140 @@ contract DssSpellTestBase is Config, DssTest {
assertEq(litePsm.tin(), type(uint256).max, _concat("checkLitePsmIlkIntegration/mom-halt-invalid-tin-", p.ilk));
assertEq(litePsm.tout(), type(uint256).max, _concat("checkLitePsmIlkIntegration/mom-halt-invalid-tout-", p.ilk));
}
struct AllocatorIntegrationParams {
SidestreamStrongStrawberry marked this conversation as resolved.
Show resolved Hide resolved
bytes32 ilk;
address pip;
address registry;
address roles;
address buffer;
address vault;
address allocatorProxy;
}

function _checkAllocatorIntegration(AllocatorIntegrationParams memory p) internal {
(, uint256 rate, uint256 spot,,) = vat.ilks(p.ilk);
assertEq(rate, RAY);
assertEq(spot, 10**18 * RAY * 10**9 / spotter.par());

(address pip,) = spotter.ilks(p.ilk);
assertEq(pip, p.pip);

assertEq(vat.gem(p.ilk, p.vault), 0);
(uint256 ink, uint256 art) = vat.urns(p.ilk, p.vault);
assertEq(ink, 1_000_000_000_000 * WAD);
assertEq(art, 0);

assertEq(AllocatorRegistryLike(p.registry).buffers(p.ilk), p.buffer);
assertEq(address(AllocatorVaultLike(p.vault).jug()), address(jug));

assertEq(usds.allowance(p.buffer, p.vault), type(uint256).max);

assertEq(AllocatorRolesLike(p.roles).ilkAdmins(p.ilk), p.allocatorProxy);

assertEq(AllocatorVaultLike(p.vault).wards(pauseProxy), 0);
assertEq(AllocatorVaultLike(p.vault).wards(p.allocatorProxy), 1);

assertEq(WardsAbstract(p.buffer).wards(pauseProxy), 0);
assertEq(WardsAbstract(p.buffer).wards(p.allocatorProxy), 1);

assertEq(reg.join(p.ilk), address(0));
assertEq(reg.gem(p.ilk), address(0));
assertEq(reg.dec(p.ilk), 0);
assertEq(reg.class(p.ilk), 5);
assertEq(reg.pip(p.ilk), p.pip);
assertEq(reg.xlip(p.ilk), address(0));
assertEq(reg.name(p.ilk), _bytes32ToString(p.ilk));
assertEq(reg.symbol(p.ilk), _bytes32ToString(p.ilk));

// Draw & Wipe from Vault
vm.prank(address(p.allocatorProxy));
AllocatorVaultLike(p.vault).draw(1_000 * WAD);
assertEq(usds.balanceOf(p.buffer), 1_000 * WAD);

vm.warp(block.timestamp + 1);
jug.drip(p.ilk);

vm.prank(address(p.allocatorProxy));
AllocatorVaultLike(p.vault).wipe(1_000 * WAD);
assertEq(usds.balanceOf(p.buffer), 0);
}

struct BaseTokenBridgeParams {
SidestreamStrongStrawberry marked this conversation as resolved.
Show resolved Hide resolved
address l2bridge;
address l1bridge;
address l1escrow;
address[] tokens;
address[] l2tokens;
SidestreamStrongStrawberry marked this conversation as resolved.
Show resolved Hide resolved
uint256[] maxWithdrawals;
}

function _testBaseTokenBridgeIntegration(BaseTokenBridgeParams memory p) public {
for (uint i = 0; i < p.tokens.length; i ++) {
rootDomain.selectFork();

assertEq(GemAbstract(p.tokens[i]).allowance(p.l1escrow, p.l1bridge), type(uint256).max);
assertEq(L1TokenBridgeLike(p.l1bridge).l1ToL2Token(p.tokens[i]), p.l2tokens[i]);

// switch to Base domain and relay the spell from L1
// the `true` keeps us on Base rather than `rootDomain.selectFork()`
baseDomain.relayFromHost(true);

// test L2 side of initBridges
assertEq(L2TokenBridgeLike(p.l2bridge).l1ToL2Token(p.tokens[i]), p.l2tokens[i]);
assertEq(L2TokenBridgeLike(p.l2bridge).maxWithdraws(p.l2tokens[i]), p.maxWithdrawals[i]);

assertEq(WardsAbstract(p.l2tokens[i]).wards(p.l2bridge), 1);

// ------- Test Deposit -------

rootDomain.selectFork();

deal(p.tokens[i], address(this), 100 ether);
assertEq(GemAbstract(p.tokens[i]).balanceOf(address(this)), 100 ether);

GemAbstract(p.tokens[i]).approve(p.l1bridge, 100 ether);
uint256 escrowBeforeBalance = GemAbstract(p.tokens[i]).balanceOf(p.l1escrow);

L1TokenBridgeLike(p.l1bridge).bridgeERC20To(
p.tokens[i],
p.l2tokens[i],
address(0xb0b),
100 ether,
1_000_000,
""
);

assertEq(GemAbstract(p.tokens[i]).balanceOf(address(this)), 0);
assertEq(GemAbstract(p.tokens[i]).balanceOf(p.l1escrow), escrowBeforeBalance + 100 ether);

baseDomain.relayFromHost(true);

assertEq(GemAbstract(p.l2tokens[i]).balanceOf(address(0xb0b)), 100 ether);

// ------- Test Withdrawal -------

vm.startPrank(address(0xb0b));

GemAbstract(p.l2tokens[i]).approve(p.l2bridge, 100 ether);

L2TokenBridgeLike(p.l2bridge).bridgeERC20To(
p.l2tokens[i],
p.tokens[i],
address(0xced),
100 ether,
1_000_000,
""
);

vm.stopPrank();

assertEq(GemAbstract(p.l2tokens[i]).balanceOf(address(0xb0b)), 0);

baseDomain.relayToHost(true);

assertEq(GemAbstract(p.tokens[i]).balanceOf(address(0xced)), 100 ether);
}
}

function _to18ConversionFactor(LitePsmLike litePsm) internal view returns (uint256) {
return litePsm.to18ConversionFactor();
Expand Down Expand Up @@ -2341,7 +2544,7 @@ contract DssSpellTestBase is Config, DssTest {
if (ward > 0) {
emit log_named_address(" Deployer Address", deployer);
emit log_named_string(" Affected Contract", contractName);
fail("Error: Bad Auth");
SidestreamColdMelon marked this conversation as resolved.
Show resolved Hide resolved
revert("Error: Bad Auth");
}
}
}
Expand Down
Loading
Loading