Skip to content

Commit

Permalink
feat(contracts): contract upgradeability and predeploy setup (#28)
Browse files Browse the repository at this point in the history
* feat(contracts): upgradeable, visibility, and predeploys

* chore(contracts): modify script for upgradeability

* test(contracts): upgradeability contracts mod tests

* chore(contracts): update bindings

* fix: update tests and add event

* fix upgradeability and most tests

* test(contracts): fix constructor test

* lint(contracts): lint tests & fix imports

* lint(contracts): fmt bindings

---------

Co-authored-by: Raul <[email protected]>
  • Loading branch information
jdubpark and Ramarti authored Aug 23, 2024
1 parent 373cd59 commit 18f3bfb
Show file tree
Hide file tree
Showing 22 changed files with 2,425 additions and 514 deletions.
524 changes: 520 additions & 4 deletions contracts/bindings/iptokenslashing.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/iptokenslashing_more.go

Large diffs are not rendered by default.

25 changes: 2 additions & 23 deletions contracts/bindings/iptokenslashing_storage_layout.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
{
"storage": [
{
"astId": 8,
"contract": "src/protocol/IPTokenSlashing.sol:IPTokenSlashing",
"label": "_owner",
"offset": 0,
"slot": "0",
"type": "t_address"
},
{
"astId": 156,
"contract": "src/protocol/IPTokenSlashing.sol:IPTokenSlashing",
"label": "_pendingOwner",
"offset": 0,
"slot": "1",
"type": "t_address"
},
{
"astId": 40320,
"astId": 2592,
"contract": "src/protocol/IPTokenSlashing.sol:IPTokenSlashing",
"label": "unjailFee",
"offset": 0,
"slot": "2",
"slot": "0",
"type": "t_uint256"
}
],
"types": {
"t_address": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
},
"t_uint256": {
"encoding": "inplace",
"label": "uint256",
Expand Down
1,350 changes: 1,134 additions & 216 deletions contracts/bindings/iptokenstaking.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/iptokenstaking_more.go

Large diffs are not rendered by default.

95 changes: 37 additions & 58 deletions contracts/bindings/iptokenstaking_storage_layout.json
Original file line number Diff line number Diff line change
@@ -1,100 +1,79 @@
{
"storage": [
{
"astId": 8,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "_owner",
"offset": 0,
"slot": "0",
"type": "t_address"
},
{
"astId": 156,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "_pendingOwner",
"offset": 0,
"slot": "1",
"type": "t_address"
},
{
"astId": 40493,
"astId": 2581,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "minStakeAmount",
"offset": 0,
"slot": "2",
"slot": "0",
"type": "t_uint256"
},
{
"astId": 40496,
"astId": 2584,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "minUnstakeAmount",
"offset": 0,
"slot": "3",
"slot": "1",
"type": "t_uint256"
},
{
"astId": 40499,
"astId": 2587,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "minRedelegateAmount",
"offset": 0,
"slot": "4",
"slot": "2",
"type": "t_uint256"
},
{
"astId": 40502,
"astId": 2590,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "withdrawalAddressChangeInterval",
"offset": 0,
"slot": "5",
"slot": "3",
"type": "t_uint256"
},
{
"astId": 40508,
"astId": 2596,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "validatorMetadata",
"offset": 0,
"slot": "6",
"type": "t_mapping(t_bytes_memory_ptr,t_struct(ValidatorMetadata)40039_storage)"
"slot": "4",
"type": "t_mapping(t_bytes_memory_ptr,t_struct(ValidatorMetadata)2257_storage)"
},
{
"astId": 40513,
"astId": 2601,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "delegatorTotalStakes",
"offset": 0,
"slot": "7",
"slot": "5",
"type": "t_mapping(t_bytes_memory_ptr,t_uint256)"
},
{
"astId": 40520,
"astId": 2608,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "delegatorValidatorStakes",
"offset": 0,
"slot": "8",
"slot": "6",
"type": "t_mapping(t_bytes_memory_ptr,t_mapping(t_bytes_memory_ptr,t_uint256))"
},
{
"astId": 40526,
"astId": 2614,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "delegatorOperators",
"offset": 0,
"slot": "9",
"type": "t_mapping(t_bytes_memory_ptr,t_struct(AddressSet)589_storage)"
"slot": "7",
"type": "t_mapping(t_bytes_memory_ptr,t_struct(AddressSet)1954_storage)"
},
{
"astId": 40531,
"astId": 2619,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "withdrawalAddressChange",
"offset": 0,
"slot": "10",
"slot": "8",
"type": "t_mapping(t_bytes_memory_ptr,t_uint256)"
}
],
"types": {
"t_address": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
},
"t_array(t_bytes32)dyn_storage": {
"encoding": "dynamic_array",
"label": "bytes32[]",
Expand Down Expand Up @@ -130,19 +109,19 @@
"numberOfBytes": "32",
"value": "t_mapping(t_bytes_memory_ptr,t_uint256)"
},
"t_mapping(t_bytes_memory_ptr,t_struct(AddressSet)589_storage)": {
"t_mapping(t_bytes_memory_ptr,t_struct(AddressSet)1954_storage)": {
"encoding": "mapping",
"key": "t_bytes_memory_ptr",
"label": "mapping(bytes => struct EnumerableSet.AddressSet)",
"numberOfBytes": "32",
"value": "t_struct(AddressSet)589_storage"
"value": "t_struct(AddressSet)1954_storage"
},
"t_mapping(t_bytes_memory_ptr,t_struct(ValidatorMetadata)40039_storage)": {
"t_mapping(t_bytes_memory_ptr,t_struct(ValidatorMetadata)2257_storage)": {
"encoding": "mapping",
"key": "t_bytes_memory_ptr",
"label": "mapping(bytes => struct IIPTokenStaking.ValidatorMetadata)",
"numberOfBytes": "32",
"value": "t_struct(ValidatorMetadata)40039_storage"
"value": "t_struct(ValidatorMetadata)2257_storage"
},
"t_mapping(t_bytes_memory_ptr,t_uint256)": {
"encoding": "mapping",
Expand All @@ -156,36 +135,36 @@
"label": "string",
"numberOfBytes": "32"
},
"t_struct(AddressSet)589_storage": {
"t_struct(AddressSet)1954_storage": {
"encoding": "inplace",
"label": "struct EnumerableSet.AddressSet",
"numberOfBytes": "64",
"members": [
{
"astId": 588,
"astId": 1953,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "_inner",
"offset": 0,
"slot": "0",
"type": "t_struct(Set)274_storage"
"type": "t_struct(Set)1639_storage"
}
]
},
"t_struct(Set)274_storage": {
"t_struct(Set)1639_storage": {
"encoding": "inplace",
"label": "struct EnumerableSet.Set",
"numberOfBytes": "64",
"members": [
{
"astId": 269,
"astId": 1634,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "_values",
"offset": 0,
"slot": "0",
"type": "t_array(t_bytes32)dyn_storage"
},
{
"astId": 273,
"astId": 1638,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "_positions",
"offset": 0,
Expand All @@ -194,53 +173,53 @@
}
]
},
"t_struct(ValidatorMetadata)40039_storage": {
"t_struct(ValidatorMetadata)2257_storage": {
"encoding": "inplace",
"label": "struct IIPTokenStaking.ValidatorMetadata",
"numberOfBytes": "128",
"members": [
{
"astId": 40028,
"astId": 2246,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "exists",
"offset": 0,
"slot": "0",
"type": "t_bool"
},
{
"astId": 40030,
"astId": 2248,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "moniker",
"offset": 0,
"slot": "1",
"type": "t_string_storage"
},
{
"astId": 40032,
"astId": 2250,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "totalStake",
"offset": 0,
"slot": "2",
"type": "t_uint256"
},
{
"astId": 40034,
"astId": 2252,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "commissionRate",
"offset": 0,
"slot": "3",
"type": "t_uint32"
},
{
"astId": 40036,
"astId": 2254,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "maxCommissionRate",
"offset": 4,
"slot": "3",
"type": "t_uint32"
},
{
"astId": 40038,
"astId": 2256,
"contract": "src/protocol/IPTokenStaking.sol:IPTokenStaking",
"label": "maxCommissionChangeRate",
"offset": 8,
Expand Down
390 changes: 386 additions & 4 deletions contracts/bindings/upgradeentrypoint.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/upgradeentrypoint_more.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
UpgradeEntrypointDeployedBytecode = "0x608060405234801561001057600080fd5b50600436106100625760003560e01c8063715018a61461006757806379ba5097146100715780638da5cb5b14610079578063e30c3978146100a2578063ef176e0e146100b3578063f2fde38b146100c6575b600080fd5b61006f6100d9565b005b61006f6100ed565b6000546001600160a01b03165b6040516001600160a01b03909116815260200160405180910390f35b6001546001600160a01b0316610086565b61006f6100c13660046102cf565b610136565b61006f6100d436600461035b565b610184565b6100e16101f5565b6100eb6000610222565b565b60015433906001600160a01b0316811461012a5760405163118cdaa760e01b81526001600160a01b03821660048201526024015b60405180910390fd5b61013381610222565b50565b61013e6101f5565b7f112749e79b2098b58eab36c21f123b2883c3ecbbb4f41623a744fa6d9b3e37c685858585856040516101759594939291906103b4565b60405180910390a15050505050565b61018c6101f5565b600180546001600160a01b0383166001600160a01b031990911681179091556101bd6000546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b6000546001600160a01b031633146100eb5760405163118cdaa760e01b8152336004820152602401610121565b600180546001600160a01b031916905561013381600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60008083601f84011261029857600080fd5b50813567ffffffffffffffff8111156102b057600080fd5b6020830191508360208285010111156102c857600080fd5b9250929050565b6000806000806000606086880312156102e757600080fd5b853567ffffffffffffffff808211156102ff57600080fd5b61030b89838a01610286565b909750955060208801359150600782900b821461032757600080fd5b9093506040870135908082111561033d57600080fd5b5061034a88828901610286565b969995985093965092949392505050565b60006020828403121561036d57600080fd5b81356001600160a01b038116811461038457600080fd5b9392505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6060815260006103c860608301878961038b565b8560070b602084015282810360408401526103e481858761038b565b9897505050505050505056fea2646970667358221220b5368e57893f3d7629f1e008c242a82e4675b883e77bab8dd19a2293fdfbae5464736f6c63430008180033"
UpgradeEntrypointDeployedBytecode = "0x6080604052600436106100915760003560e01c8063ad3cb1cc11610059578063ad3cb1cc1461012a578063c4d66de814610168578063e30c397814610188578063ef176e0e1461019d578063f2fde38b146101bd57600080fd5b80634f1ef2861461009657806352d1902d146100ab578063715018a6146100d357806379ba5097146100e85780638da5cb5b146100fd575b600080fd5b6100a96100a4366004610a70565b6101dd565b005b3480156100b757600080fd5b506100c06101fc565b6040519081526020015b60405180910390f35b3480156100df57600080fd5b506100a9610219565b3480156100f457600080fd5b506100a961022d565b34801561010957600080fd5b5061011261027a565b6040516001600160a01b0390911681526020016100ca565b34801561013657600080fd5b5061015b604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516100ca9190610b56565b34801561017457600080fd5b506100a9610183366004610b89565b6102af565b34801561019457600080fd5b50610112610443565b3480156101a957600080fd5b506100a96101b8366004610bed565b61046c565b3480156101c957600080fd5b506100a96101d8366004610b89565b6104ba565b6101e561053f565b6101ee826105e4565b6101f882826105ec565b5050565b60006102066106ae565b50600080516020610d1483398151915290565b6102216106f7565b61022b6000610729565b565b3380610237610443565b6001600160a01b03161461026e5760405163118cdaa760e01b81526001600160a01b03821660048201526024015b60405180910390fd5b61027781610729565b50565b6000807f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005b546001600160a01b031692915050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff166000811580156102f55750825b905060008267ffffffffffffffff1660011480156103125750303b155b905081158015610320575080155b1561033e5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561036857845460ff60401b1916600160401b1785555b6001600160a01b0386166103e45760405162461bcd60e51b815260206004820152603760248201527f55706772616465456e747279706f696e743a206163636573734d616e6167657260448201527f2063616e6e6f74206265207a65726f20616464726573730000000000000000006064820152608401610265565b6103ec610761565b6103f586610769565b831561043b57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050565b6000807f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0061029f565b6104746106f7565b7f112749e79b2098b58eab36c21f123b2883c3ecbbb4f41623a744fa6d9b3e37c685858585856040516104ab959493929190610ca2565b60405180910390a15050505050565b6104c26106f7565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0080546001600160a01b0319166001600160a01b038316908117825561050661027a565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a35050565b306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614806105c657507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166105ba600080516020610d14833981519152546001600160a01b031690565b6001600160a01b031614155b1561022b5760405163703e46dd60e11b815260040160405180910390fd5b6102776106f7565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610646575060408051601f3d908101601f1916820190925261064391810190610cde565b60015b61066e57604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610265565b600080516020610d14833981519152811461069f57604051632a87526960e21b815260048101829052602401610265565b6106a9838361077a565b505050565b306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461022b5760405163703e46dd60e11b815260040160405180910390fd5b3361070061027a565b6001600160a01b03161461022b5760405163118cdaa760e01b8152336004820152602401610265565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0080546001600160a01b03191681556101f8826107d0565b61022b610841565b610771610841565b6102778161088a565b610783826108bc565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a28051156107c8576106a98282610921565b6101f8610997565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661022b57604051631afcd79f60e31b815260040160405180910390fd5b610892610841565b6001600160a01b03811661026e57604051631e4fbdf760e01b815260006004820152602401610265565b806001600160a01b03163b6000036108f257604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610265565b600080516020610d1483398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060600080846001600160a01b03168460405161093e9190610cf7565b600060405180830381855af49150503d8060008114610979576040519150601f19603f3d011682016040523d82523d6000602084013e61097e565b606091505b509150915061098e8583836109b6565b95945050505050565b341561022b5760405163b398979f60e01b815260040160405180910390fd5b6060826109cb576109c682610a15565b610a0e565b81511580156109e257506001600160a01b0384163b155b15610a0b57604051639996b31560e01b81526001600160a01b0385166004820152602401610265565b50805b9392505050565b805115610a255780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b80356001600160a01b0381168114610a5557600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60008060408385031215610a8357600080fd5b610a8c83610a3e565b9150602083013567ffffffffffffffff80821115610aa957600080fd5b818501915085601f830112610abd57600080fd5b813581811115610acf57610acf610a5a565b604051601f8201601f19908116603f01168101908382118183101715610af757610af7610a5a565b81604052828152886020848701011115610b1057600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b60005b83811015610b4d578181015183820152602001610b35565b50506000910152565b6020815260008251806020840152610b75816040850160208701610b32565b601f01601f19169190910160400192915050565b600060208284031215610b9b57600080fd5b610a0e82610a3e565b60008083601f840112610bb657600080fd5b50813567ffffffffffffffff811115610bce57600080fd5b602083019150836020828501011115610be657600080fd5b9250929050565b600080600080600060608688031215610c0557600080fd5b853567ffffffffffffffff80821115610c1d57600080fd5b610c2989838a01610ba4565b909750955060208801359150600782900b8214610c4557600080fd5b90935060408701359080821115610c5b57600080fd5b50610c6888828901610ba4565b969995985093965092949392505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b606081526000610cb6606083018789610c79565b8560070b60208401528281036040840152610cd2818587610c79565b98975050505050505050565b600060208284031215610cf057600080fd5b5051919050565b60008251610d09818460208701610b32565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca2646970667358221220d75dd098236b926683dd323449cf80275a972566f8513e91af7fe88e8bd100d364736f6c63430008180033"
)

//go:embed upgradeentrypoint_storage_layout.json
Expand Down
27 changes: 2 additions & 25 deletions contracts/bindings/upgradeentrypoint_storage_layout.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
{
"storage": [
{
"astId": 8,
"contract": "src/protocol/UpgradeEntrypoint.sol:UpgradeEntrypoint",
"label": "_owner",
"offset": 0,
"slot": "0",
"type": "t_address"
},
{
"astId": 156,
"contract": "src/protocol/UpgradeEntrypoint.sol:UpgradeEntrypoint",
"label": "_pendingOwner",
"offset": 0,
"slot": "1",
"type": "t_address"
}
],
"types": {
"t_address": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
"storage": [],
"types": {}
}
12 changes: 6 additions & 6 deletions contracts/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 18f3bfb

Please sign in to comment.