@@ -12,13 +12,44 @@ import (
1212 "github.com/rollchains/pchain/x/ue/types"
1313)
1414
15- func deployFactoryContract (ctx context.Context , evmKeeper types.EVMKeeper ) {
15+ func deployFactoryProxy (ctx context.Context , evmKeeper types.EVMKeeper ) {
1616 sdkCtx := sdk .UnwrapSDKContext (ctx )
17- factoryAddress := common .HexToAddress (types .FACTORY_ADDRESS_HEX )
18- owner := common .HexToAddress (types .FACTORY_OWNER_ADDRESS_HEX )
17+ proxyAddress := common .HexToAddress (types .FACTORY_PROXY_ADDRESS_HEX )
18+ proxyAdminOwner := common .HexToAddress (types .PROXY_ADMIN_ADDRESS_HEX )
19+ factoryImplAddress := common .HexToAddress (types .FACTORY_IMPL_ADDRESS_HEX )
1920
2021 // Compute the code hash from the runtime bytecode
21- codeHash := crypto .Keccak256 (types .FactoryRuntimeBytecode )
22+ codeHash := crypto .Keccak256 (types .ProxyRuntimeBytecode )
23+
24+ // Create the EVM account object
25+ evmAccount := statedb.Account {
26+ Nonce : 1 , // to prevent tx nonce=0 conflicts
27+ Balance : big .NewInt (0 ), // zero balance by default
28+ CodeHash : codeHash , // link to deployed code
29+ }
30+
31+ // Set the EVM account with the factory proxy contract
32+ err := evmKeeper .SetAccount (sdkCtx , proxyAddress , evmAccount )
33+ if err != nil {
34+ panic ("failed to set factory proxy contract account: " + err .Error ())
35+ }
36+
37+ // Store the runtime bytecode linked to the code hash
38+ evmKeeper .SetCode (sdkCtx , codeHash , types .ProxyRuntimeBytecode )
39+
40+ // Update proxyAdmin Slot with the proxyAdmin owner address (left padded to 32 bytes)
41+ evmKeeper .SetState (sdkCtx , proxyAddress , types .PROXY_ADMIN_SLOT , common .LeftPadBytes (proxyAdminOwner .Bytes (), 32 ))
42+
43+ // Update proxyImplementation Slot with the factory implementation address (left padded to 32 bytes)
44+ evmKeeper .SetState (sdkCtx , proxyAddress , types .PROXY_IMPLEMENTATION_SLOT , common .LeftPadBytes (factoryImplAddress .Bytes (), 32 ))
45+ }
46+
47+ func deployFactoryImplContract (ctx context.Context , evmKeeper types.EVMKeeper ) {
48+ sdkCtx := sdk .UnwrapSDKContext (ctx )
49+ factoryAddress := common .HexToAddress (types .FACTORY_IMPL_ADDRESS_HEX )
50+
51+ // Compute the code hash from the runtime bytecode
52+ codeHash := crypto .Keccak256 (types .FactoryImplRuntimeBytecode )
2253
2354 // Create the EVM account object
2455 evmAccount := statedb.Account {
@@ -34,8 +65,44 @@ func deployFactoryContract(ctx context.Context, evmKeeper types.EVMKeeper) {
3465 }
3566
3667 // Store the runtime bytecode linked to the code hash
37- evmKeeper .SetCode (sdkCtx , codeHash , types .FactoryRuntimeBytecode )
68+ evmKeeper .SetCode (sdkCtx , codeHash , types .FactoryImplRuntimeBytecode )
69+ }
70+
71+ func deployProxyAdminContract (ctx context.Context , evmKeeper types.EVMKeeper ) {
72+ sdkCtx := sdk .UnwrapSDKContext (ctx )
73+ proxyAdminAddress := common .HexToAddress (types .PROXY_ADMIN_ADDRESS_HEX )
74+ owner := common .HexToAddress (types .PROXY_ADMIN_OWNER_ADDRESS_HEX )
75+
76+ // Compute the code hash from the runtime bytecode
77+ codeHash := crypto .Keccak256 (types .ProxyAdminRuntimeBytecode )
78+
79+ // Create the EVM account object
80+ evmAccount := statedb.Account {
81+ Nonce : 1 , // to prevent tx nonce=0 conflicts
82+ Balance : big .NewInt (0 ), // zero balance by default
83+ CodeHash : codeHash , // link to deployed code
84+ }
85+
86+ // Set the EVM account with the proxy admin contract
87+ err := evmKeeper .SetAccount (sdkCtx , proxyAdminAddress , evmAccount )
88+ if err != nil {
89+ panic ("failed to set proxy admin contract account: " + err .Error ())
90+ }
91+
92+ // Store the runtime bytecode linked to the code hash
93+ evmKeeper .SetCode (sdkCtx , codeHash , types .ProxyAdminRuntimeBytecode )
3894
3995 // Initialize storage slot 0 (Ownable.owner) with the owner address (left padded to 32 bytes)
40- evmKeeper .SetState (sdkCtx , factoryAddress , common.Hash {}, common .LeftPadBytes (owner .Bytes (), 32 ))
96+ evmKeeper .SetState (sdkCtx , proxyAdminAddress , common.Hash {}, common .LeftPadBytes (owner .Bytes (), 32 ))
97+ }
98+
99+ func deployFactoryEA (ctx context.Context , evmKeeper types.EVMKeeper ) {
100+ // Deploy the factory implementation contract
101+ deployFactoryImplContract (ctx , evmKeeper )
102+
103+ // Deploy the proxy admin contract
104+ deployProxyAdminContract (ctx , evmKeeper )
105+
106+ // Deploy the factory proxy contract
107+ deployFactoryProxy (ctx , evmKeeper )
41108}
0 commit comments