Skip to content

Commit

Permalink
Update deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlovdog committed Nov 7, 2024
1 parent a476bbe commit 5efe942
Show file tree
Hide file tree
Showing 10 changed files with 2,691 additions and 389 deletions.
430 changes: 430 additions & 0 deletions broadcast/MagicSpend.s.sol/11155111/run-1730988773.json

Large diffs are not rendered by default.

366 changes: 185 additions & 181 deletions broadcast/MagicSpend.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

432 changes: 432 additions & 0 deletions broadcast/MagicSpend.s.sol/421614/run-1730978730.json

Large diffs are not rendered by default.

436 changes: 436 additions & 0 deletions broadcast/MagicSpend.s.sol/421614/run-1730988871.json

Large diffs are not rendered by default.

436 changes: 436 additions & 0 deletions broadcast/MagicSpend.s.sol/421614/run-latest.json

Large diffs are not rendered by default.

466 changes: 466 additions & 0 deletions broadcast/MagicSpend.s.sol/84532/run-1730988849.json

Large diffs are not rendered by default.

406 changes: 205 additions & 201 deletions broadcast/MagicSpend.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"build:abi": "./generate-abi.sh",
"build:contracts": "forge clean && forge build",
"test": "pnpm build && forge test",
"deploy:magic-spend": "pnpm build && pnpm deploy:magic-spend:sepolia && pnpm deploy:magic-spend:base-sepolia",
"deploy:magic-spend:all": "pnpm build && pnpm deploy:magic-spend:sepolia && pnpm deploy:magic-spend:base-sepolia && pnpm deploy:magic-spend:arbitrium-sepolia",
"deploy:magic-spend:sepolia": "pnpm deploy:magic-spend:script --rpc-url https://11155111.rpc.thirdweb.com",
"deploy:magic-spend:arbitrium-sepolia": "pnpm deploy:magic-spend:script --rpc-url https://421614.rpc.thirdweb.com",
"deploy:magic-spend:base-sepolia": "pnpm deploy:magic-spend:script --rpc-url https://84532.rpc.thirdweb.com",
"deploy:magic-spend:script": "forge script script/MagicSpend.s.sol:MagicSpend_Deploy --broadcast"
},
Expand Down
2 changes: 1 addition & 1 deletion script/MagicSpend.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract MagicSpend_Deploy is Script, MagicSpendFactory {
vm.stopBroadcast();

vm.startBroadcast(owner);
withdrawalManager.addLiquidity{value: 0.01 ether}(ETH, 0.01 ether);
withdrawalManager.addLiquidity{value: 0.5 ether}(ETH, 0.5 ether);
vm.stopBroadcast();

vm.startBroadcast(alice);
Expand Down
103 changes: 98 additions & 5 deletions src/MagicSpendFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,118 @@ pragma solidity ^0.8.0;

import {MagicSpendStakeManager} from "./MagicSpendStakeManager.sol";
import {MagicSpendWithdrawalManager} from "./MagicSpendWithdrawalManager.sol";

import {Vm} from "forge-std/Vm.sol";
import {Options} from "@openzeppelin-0.3.6/foundry-upgrades/Options.sol";
import {Core} from "@openzeppelin-0.3.6/foundry-upgrades/internal/Core.sol";
import {Upgrades} from "@openzeppelin-0.3.6/foundry-upgrades/Upgrades.sol";
import {Utils} from "@openzeppelin-0.3.6/foundry-upgrades/internal/Utils.sol";


abstract contract MagicSpendFactory {
address constant DETERMINISTIC_DEPLOYER = 0x4e59b44847b379578588920cA78FbF26c0B4956C;

function deployStakeManager(address owner) internal returns (MagicSpendStakeManager) {
address proxy = Upgrades.deployTransparentProxy(
"MagicSpendStakeManager.sol", owner, abi.encodeCall(MagicSpendStakeManager.initialize, (owner))
Options memory opts;

address proxy = deployTransparentProxy(
"MagicSpendStakeManager.sol",
owner,
abi.encodeCall(MagicSpendStakeManager.initialize, (owner)),
opts
);

return MagicSpendStakeManager(payable(proxy));
}

function deployWithdrawalManager(address owner, address signer) internal returns (MagicSpendWithdrawalManager) {
address proxy = Upgrades.deployTransparentProxy(
Options memory opts;

address proxy = deployTransparentProxy(
"MagicSpendWithdrawalManager.sol",
owner,
abi.encodeCall(MagicSpendWithdrawalManager.initialize, (owner, signer))
abi.encodeCall(MagicSpendWithdrawalManager.initialize, (owner, signer)),
opts
);

return MagicSpendWithdrawalManager(payable(proxy));
}

function deployTransparentProxy(
string memory contractName,
address initialOwner,
bytes memory initializerData,
Options memory opts
) private returns(address) {
if (!opts.unsafeSkipAllChecks && !opts.unsafeSkipProxyAdminCheck && Core.inferProxyAdmin(initialOwner)) {
revert(
string.concat(
"`initialOwner` must not be a ProxyAdmin contract. If the contract at address ",
Vm(Utils.CHEATCODE_ADDRESS).toString(initialOwner),
" is not a ProxyAdmin contract and you are sure that this contract is able to call functions on an actual ProxyAdmin, skip this check with the `unsafeSkipProxyAdminCheck` option."
)
);
}

Core.validateImplementation(contractName, opts);

address impl = _deploy(
contractName,
opts.constructorData,
opts.defender.salt
);

return _deploy(
"TransparentUpgradeableProxy.sol:TransparentUpgradeableProxy",
abi.encode(impl, initialOwner, initializerData),
opts.defender.salt
);
}

function _deploy(
string memory contractName,
bytes memory constructorData,
bytes32 salt
) private returns (address) {
bytes memory creationCode = Vm(Utils.CHEATCODE_ADDRESS).getCode(contractName);
address deployedAddress = _deployDeterminisitc(
abi.encodePacked(creationCode, constructorData),
salt
);

if (deployedAddress == address(0)) {
revert(
string(
abi.encodePacked(
"Failed to deploy contract ",
contractName,
' using constructor data "',
string(constructorData),
'"'
)
)
);
}
return deployedAddress;
}

function _deployDeterminisitc(bytes memory bytecode, bytes32 salt) private returns (address) {
(bool success, bytes memory data) = DETERMINISTIC_DEPLOYER.call(
abi.encodePacked(salt, bytecode)
);

if (!success) {
revert (
string(
abi.encodePacked(
"Failed to deploy contract using deterministic deployment with salt ",
salt,
". Error: ",
data
)
)
);
}

return address(uint160(bytes20(data)));
}
}

0 comments on commit 5efe942

Please sign in to comment.