diff --git a/chainConfig.ts b/chainConfig.ts new file mode 100644 index 00000000..5f95e948 --- /dev/null +++ b/chainConfig.ts @@ -0,0 +1,48 @@ +export type ChainConfig = { + chainSlug: number; + chainName: string; + timeout: number; + rpc: string; + transmitterAddress: string; + executorAddress: string; + watcherAddress: string; + feeUpdaterAddress: string; + ownerAddress: string; + msgValueMaxThreshold?: string | number; + overrides?: { + type?: number; + gasLimit?: string | number; + gasPrice?: string | number; + }; +}; + +export const chainConfig: { [chain: string]: ChainConfig } = { + "31337": { + chainSlug: 31337, + chainName: "hardhat", + timeout: 7200, + rpc: "http://127.0.0.1:8545/", + transmitterAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + executorAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + watcherAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + feeUpdaterAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + ownerAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + msgValueMaxThreshold: 10000000000000000, + overrides: { + type: 1, + gasLimit: 20000000, + gasPrice: 1000000000000, + }, + }, + "647": { + chainSlug: 647, + chainName: "sxn_testnet", + timeout: 7200, + rpc: "https://rpc.toronto.sx.technology/", + transmitterAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + executorAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + watcherAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + feeUpdaterAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + ownerAddress: "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + }, +}; diff --git a/contracts/socket/SocketBatcher.sol b/contracts/socket/SocketBatcher.sol index 070fa8a6..ce507a32 100644 --- a/contracts/socket/SocketBatcher.sol +++ b/contracts/socket/SocketBatcher.sol @@ -265,10 +265,10 @@ contract SocketBatcher is AccessControl { * @param socketAddress_ address of socket * @param sealRequests_ the list of requests with packets to be sealed on sourceChain */ - function _sealBatch( + function sealBatch( address socketAddress_, SealRequest[] calldata sealRequests_ - ) internal { + ) external { uint256 sealRequestLength = sealRequests_.length; for (uint256 index = 0; index < sealRequestLength; ) { ISocket(socketAddress_).seal( @@ -282,27 +282,15 @@ contract SocketBatcher is AccessControl { } } - /** - * @notice seal a batch of packets from capacitor on sourceChain mentioned in sealRequests - * @param socketAddress_ address of socket - * @param sealRequests_ the list of requests with packets to be sealed on sourceChain - */ - function sealBatch( - address socketAddress_, - SealRequest[] calldata sealRequests_ - ) external { - _sealBatch(socketAddress_, sealRequests_); - } - /** * @notice propose a batch of packets sequentially by socketDestination * @param socketAddress_ address of socket * @param proposeRequests_ the list of requests with packets to be proposed by socketDestination */ - function _proposeBatch( + function proposeBatch( address socketAddress_, ProposeRequest[] calldata proposeRequests_ - ) internal { + ) external { uint256 proposeRequestLength = proposeRequests_.length; for (uint256 index = 0; index < proposeRequestLength; ) { ISocket(socketAddress_).proposeForSwitchboard( @@ -317,26 +305,17 @@ contract SocketBatcher is AccessControl { } } - /** - * @notice propose a batch of packets sequentially by socketDestination - * @param socketAddress_ address of socket - * @param proposeRequests_ the list of requests with packets to be proposed by socketDestination - */ - function proposeBatch( - address socketAddress_, - ProposeRequest[] calldata proposeRequests_ - ) external { - _proposeBatch(socketAddress_, proposeRequests_); - } - /** * @notice attests a batch of Packets * @param attestRequests_ the list of requests with packets to be attested by switchboard in sequence */ - function _attestBatch(AttestRequest[] calldata attestRequests_) internal { + function attestBatch( + address switchboardAddress_, + AttestRequest[] calldata attestRequests_ + ) external { uint256 attestRequestLength = attestRequests_.length; for (uint256 index = 0; index < attestRequestLength; ) { - FastSwitchboard(attestRequests_[index].switchboard).attest( + FastSwitchboard(switchboardAddress_).attest( attestRequests_[index].packetId, attestRequests_[index].proposalCount, attestRequests_[index].root, @@ -348,34 +327,6 @@ contract SocketBatcher is AccessControl { } } - /** - * @notice attests a batch of Packets - * @param attestRequests_ the list of requests with packets to be attested by switchboard in sequence - */ - function attestBatch(AttestRequest[] calldata attestRequests_) external { - _attestBatch(attestRequests_); - } - - /** - * @notice send a batch of propose, attest and execute transactions - * @param socketAddress_ address of socket - * @param proposeRequests_ the list of requests with packets to be proposed - * @param attestRequests_ the list of requests with packets to be attested by switchboard - * @param executeRequests_ the list of requests with messages to be executed - */ - function sendBatch( - address socketAddress_, - SealRequest[] calldata sealRequests_, - ProposeRequest[] calldata proposeRequests_, - AttestRequest[] calldata attestRequests_, - ExecuteRequest[] calldata executeRequests_ - ) external payable { - _sealBatch(socketAddress_, sealRequests_); - _proposeBatch(socketAddress_, proposeRequests_); - _attestBatch(attestRequests_); - _executeBatch(socketAddress_, executeRequests_); - } - /** * @notice trip a batch of Proposals * @param proposalTripRequests_ the list of requests for tripping proposals @@ -412,10 +363,10 @@ contract SocketBatcher is AccessControl { * @param socketAddress_ address of socket * @param executeRequests_ the list of requests with messages to be executed in sequence */ - function _executeBatch( + function executeBatch( address socketAddress_, ExecuteRequest[] calldata executeRequests_ - ) internal { + ) external payable { uint256 executeRequestLength = executeRequests_.length; uint256 totalMsgValue = msg.value; for (uint256 index = 0; index < executeRequestLength; ) { @@ -443,18 +394,6 @@ contract SocketBatcher is AccessControl { } } - /** - * @notice executes a batch of messages - * @param socketAddress_ address of socket - * @param executeRequests_ the list of requests with messages to be executed in sequence - */ - function executeBatch( - address socketAddress_, - ExecuteRequest[] calldata executeRequests_ - ) external payable { - _executeBatch(socketAddress_, executeRequests_); - } - /** * @notice invoke receive Message on PolygonRootReceiver for a batch of messages in loop * @param polygonRootReceiverAddress_ address of polygonRootReceiver diff --git a/deploy.sh b/deploy.sh index fae74513..1c21a879 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,5 @@ -npx hardhat run scripts/deploy/index.ts && -npx ts-node scripts/deploy/checkRoles.ts --no-compile && -npx hardhat run scripts/deploy/configure.ts --no-compile && -npx hardhat run scripts/deploy/connect.ts --no-compile && -npx hardhat run scripts/deploy/verify.ts --no-compile +npx hardhat run scripts/deploy/1-deploy.ts && +npx ts-node scripts/deploy/2-check-roles.ts --no-compile && +npx hardhat run scripts/deploy/3-configure.ts --no-compile && +npx hardhat run scripts/deploy/4-connect.ts --no-compile && +npx hardhat run scripts/deploy/5-verify.ts --no-compile diff --git a/deployments/dev_addresses.json b/deployments/dev_addresses.json index f881dbd5..623f7cd1 100644 --- a/deployments/dev_addresses.json +++ b/deployments/dev_addresses.json @@ -29,6 +29,13 @@ "switchboard": "0xD2F16F574c7B4022192C53af9570b4b3C9B42f73" } }, + "647": { + "FAST2": { + "capacitor": "0xDaB21eD920cCf2E7277430aFAb19Cb6Dce1AA912", + "decapacitor": "0xF9F8c72E7027B37b8f5a56c0b3331F7497032Aa9", + "switchboard": "0xD2F16F574c7B4022192C53af9570b4b3C9B42f73" + } + }, "901": { "FAST": { "capacitor": "0xE23Ed3328c2ab5AE41eCE04EB13472276c88E292", @@ -267,6 +274,41 @@ "FastSwitchboard2": "0x7E7735e77574228C4F55d4B2F96Fe586dF10104e", "SocketBatcher": "0xc07216D0e55044572d6E3C08d8a8a86BD3D909e3" }, + "647": { + "SignatureVerifier": "0xE19cC72ad60d0aE127E2c8d7C016cf67e15c5493", + "Hasher": "0x08f47Af4FB9Ab119e6Dd2C43994B9131E2AA91e2", + "CapacitorFactory": "0xF4E477308ab2f30330cD3233e9b71Dc5d636EEe0", + "Socket": "0x78E9EcA8889A6b6016CE5b56cD872bfB6F1Ba41f", + "ExecutionManager": "0xFAE13FC12a111CD31Ea02Ae554A59Fb18fD45127", + "TransmitManager": "0x255f9F9aB7eE46cb59a2Ed57a852304faD701C8d", + "FastSwitchboard2": "0xd7D1dc1B8aB82E14b896fF980a0fd3B035E0c9E3", + "OptimisticSwitchboard": "0xF6bc9bC110464f7544507B574bEC357403171156", + "SocketBatcher": "0xf47103263296eFebc7B8DD4d5410e15d7B59FceF", + "Counter": "0x2a754670Ed76F892568EE6Ff690fc56ee38a2DC9", + "integrations": { + "5": { + "FAST2": { + "capacitor": "0x08C4805744B45C708a26d762594d5481c9dde885", + "decapacitor": "0x6e873C240896Bd96C2061C9Bed5489FB248608FC", + "switchboard": "0xd7D1dc1B8aB82E14b896fF980a0fd3B035E0c9E3" + } + }, + "80001": { + "FAST2": { + "capacitor": "0x024E195D5751Ae3D79e40F3aEdE742BF6E311BC1", + "decapacitor": "0xaE0EB47AFB854124EAe3cDe713592de90Dd56339", + "switchboard": "0xd7D1dc1B8aB82E14b896fF980a0fd3B035E0c9E3" + } + }, + "421613": { + "FAST2": { + "capacitor": "0xc416F0D400dFCBE5dA672BFC2f88b7b9AB218C82", + "decapacitor": "0xd5175A72b98eE7C86bBa76F0095Da683dB7C190e", + "switchboard": "0xd7D1dc1B8aB82E14b896fF980a0fd3B035E0c9E3" + } + } + } + }, "901": { "SignatureVerifier": "0x47140353947Bc127c9cf36fabd61112C8Fb8db2A", "Hasher": "0x9814d1E6751ADAE2D60fF16f987ae02a25C87224", @@ -438,6 +480,13 @@ "switchboard": "0x0dD648cdF51b7f7AdA68F84BB245D52172199F0d" } }, + "647": { + "FAST2": { + "capacitor": "0xABbcD246a79129A9850ae6bA8E862FD9f550afc5", + "decapacitor": "0x9F9E77c4B94fC244Eb58a005DbFDE07Ff1007E3d", + "switchboard": "0x0dD648cdF51b7f7AdA68F84BB245D52172199F0d" + } + }, "901": { "FAST": { "capacitor": "0xe75e3AdAac425b69e6aA8Be1502b1e0FcD9Eb529", @@ -567,6 +616,13 @@ "switchboard": "0xFD468fc7d23dA3e7466EE78327D4db5FcA232B2d" } }, + "647": { + "FAST2": { + "capacitor": "0x6d84ee5B59125cB4b608f50747de4E31CC4Cd7d9", + "decapacitor": "0xE981C76FC7D6252A46f94aee7CA97d7617f82489", + "switchboard": "0xFD468fc7d23dA3e7466EE78327D4db5FcA232B2d" + } + }, "901": { "FAST": { "capacitor": "0xc9f5FcEbb5414b4065d8E74C203aCfcF166E1Cda", diff --git a/deployments/dev_verification.json b/deployments/dev_verification.json index ed38b6da..d2c8e109 100644 --- a/deployments/dev_verification.json +++ b/deployments/dev_verification.json @@ -27,6 +27,184 @@ ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] ] ], + "647": [ + [ + "0x2a754670Ed76F892568EE6Ff690fc56ee38a2DC9", + "Counter", + "contracts/examples/Counter.sol", + ["0x78E9EcA8889A6b6016CE5b56cD872bfB6F1Ba41f"] + ], + [ + "0xf47103263296eFebc7B8DD4d5410e15d7B59FceF", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0xdE7f7a699F8504641eceF544B0fbc0740C37E69B"] + ], + [ + "0xF6bc9bC110464f7544507B574bEC357403171156", + "OptimisticSwitchboard", + "contracts/switchboard/default-switchboards/OptimisticSwitchboard.sol", + [ + "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + "0x78E9EcA8889A6b6016CE5b56cD872bfB6F1Ba41f", + 647, + 7200, + "0xE19cC72ad60d0aE127E2c8d7C016cf67e15c5493" + ] + ], + [ + "0xd7D1dc1B8aB82E14b896fF980a0fd3B035E0c9E3", + "FastSwitchboard", + "contracts/switchboard/default-switchboards/FastSwitchboard.sol", + [ + "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + "0x78E9EcA8889A6b6016CE5b56cD872bfB6F1Ba41f", + 647, + 7200, + "0xE19cC72ad60d0aE127E2c8d7C016cf67e15c5493" + ] + ], + [ + "0x255f9F9aB7eE46cb59a2Ed57a852304faD701C8d", + "TransmitManager", + "contracts/TransmitManager.sol", + [ + "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + 647, + "0x78E9EcA8889A6b6016CE5b56cD872bfB6F1Ba41f", + "0xE19cC72ad60d0aE127E2c8d7C016cf67e15c5493" + ] + ], + [ + "0xFAE13FC12a111CD31Ea02Ae554A59Fb18fD45127", + "ExecutionManager", + "contracts/ExecutionManager.sol", + [ + "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + 647, + "0x78E9EcA8889A6b6016CE5b56cD872bfB6F1Ba41f", + "0xE19cC72ad60d0aE127E2c8d7C016cf67e15c5493" + ] + ], + [ + "0x78E9EcA8889A6b6016CE5b56cD872bfB6F1Ba41f", + "Socket", + "contracts/socket/Socket.sol", + [ + 647, + "0x08f47Af4FB9Ab119e6Dd2C43994B9131E2AA91e2", + "0xF4E477308ab2f30330cD3233e9b71Dc5d636EEe0", + "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + "IMLI" + ] + ], + [ + "0xF4E477308ab2f30330cD3233e9b71Dc5d636EEe0", + "CapacitorFactory", + "contracts/CapacitorFactory.sol", + ["0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", 10] + ], + [ + "0x08f47Af4FB9Ab119e6Dd2C43994B9131E2AA91e2", + "Hasher", + "contracts/utils/Hasher.sol", + ["0xdE7f7a699F8504641eceF544B0fbc0740C37E69B"] + ], + [ + "0xE19cC72ad60d0aE127E2c8d7C016cf67e15c5493", + "SignatureVerifier", + "contracts/utils/SignatureVerifier.sol", + ["0xdE7f7a699F8504641eceF544B0fbc0740C37E69B"] + ], + [ + "0x9A4f5494d48581472619ec3f1aD8d323eA71b754", + "Counter", + "contracts/examples/Counter.sol", + ["0x7539351956f3271CdaF1fb1a440CA9BE2BfbF2ED"] + ], + [ + "0x87E54C7AF2Ed4f9e12a358484C03B3667A417a80", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], + [ + "0xd0580065858313f0300eBb6e7970cD3699323985", + "OptimisticSwitchboard", + "contracts/switchboard/default-switchboards/OptimisticSwitchboard.sol", + [ + "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + "0x7539351956f3271CdaF1fb1a440CA9BE2BfbF2ED", + 647, + 7200, + "0x320Cd79c54927Fe130427bD4492b6c6068D075E3" + ] + ], + [ + "0x337bD38dA8833ee5B7202e53315293A1776BB7e6", + "FastSwitchboard", + "contracts/switchboard/default-switchboards/FastSwitchboard.sol", + [ + "0xdE7f7a699F8504641eceF544B0fbc0740C37E69B", + "0x7539351956f3271CdaF1fb1a440CA9BE2BfbF2ED", + 647, + 7200, + "0x320Cd79c54927Fe130427bD4492b6c6068D075E3" + ] + ], + [ + "0x98bBfbdDA0f32c411b1cE821B495aAb1bD43C680", + "TransmitManager", + "contracts/TransmitManager.sol", + [ + "0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa", + 647, + "0x7539351956f3271CdaF1fb1a440CA9BE2BfbF2ED", + "0x320Cd79c54927Fe130427bD4492b6c6068D075E3" + ] + ], + [ + "0x3cD9C9Aa2f262339Cc994466a12F9A4c7A267827", + "ExecutionManager", + "contracts/ExecutionManager.sol", + [ + "0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa", + 647, + "0x7539351956f3271CdaF1fb1a440CA9BE2BfbF2ED", + "0x320Cd79c54927Fe130427bD4492b6c6068D075E3" + ] + ], + [ + "0x7539351956f3271CdaF1fb1a440CA9BE2BfbF2ED", + "Socket", + "contracts/socket/Socket.sol", + [ + 647, + "0xb515E9E6E6aBA44bBEC72FBF6B1a18DDB6bec68e", + "0x5bA62006442bC42e28E3E5147A5221Be723ca1DE", + "0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa", + "IMLI" + ] + ], + [ + "0x5bA62006442bC42e28E3E5147A5221Be723ca1DE", + "CapacitorFactory", + "contracts/CapacitorFactory.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa", 10] + ], + [ + "0xb515E9E6E6aBA44bBEC72FBF6B1a18DDB6bec68e", + "Hasher", + "contracts/utils/Hasher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], + [ + "0x320Cd79c54927Fe130427bD4492b6c6068D075E3", + "SignatureVerifier", + "contracts/utils/SignatureVerifier.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ] + ], "901": [ [ "0x6F1912DC9631E8aFC89e7D95Afd7e467845FF6F2", diff --git a/deployments/prod_addresses.json b/deployments/prod_addresses.json index b799d4ef..8decb069 100644 --- a/deployments/prod_addresses.json +++ b/deployments/prod_addresses.json @@ -98,7 +98,7 @@ "FastSwitchboard2": "0x6B5b7402e5bA4732D8A231552144384FC369Ce5e", "OptimisticSwitchboard": "0x3DFDc6DFa41FA64aa3a879254B41517e5ba50c56", "Counter": "0xEA33a8f11A719d728A42Ff5A860eBd7620683433", - "SocketBatcher": "0xB5f289a6Af87A65fddF1a7068F556E7d669c0D4b" + "SocketBatcher": "0x5a23e41c1ff969244eE2A5D563519b170F143AcD" }, "10": { "SignatureVerifier": "0xbb1f202095BE99000038D8d207C7E6f0F85a3925", @@ -448,7 +448,7 @@ "FastSwitchboard2": "0x7bFeb0bf17Da2eCFD3d897f11f87e0b80b3e5303", "OptimisticSwitchboard": "0xDFbf47607FBA3707E69B16576F653154a92d9B96", "Counter": "0x9d10C5D68C0878Ba255E62b3f2051f22E43A9b2f", - "SocketBatcher": "0xb80d97657277e24d70caee6dEF92BFaa7D884A7f" + "SocketBatcher": "0xE0DD154111D407Db671eAeC703CF472d3a2c5333" }, "901": { "SignatureVerifier": "0x19791877C020f7Cd5Ca1c97bdd5D268a52dbB0ff", @@ -534,7 +534,7 @@ "FastSwitchboard2": "0xB39Cb89dfD708115616fdA1a2735613931B14181", "OptimisticSwitchboard": "0x1d6E46fd4DFdfe063f9096Dc2C0862D36A25b1aD", "Counter": "0xfCa282147D5E9b14c208D09dbEbC7Eb5C3814dC5", - "SocketBatcher": "0xb2dA552c9Baa0e15b13302aBBF7B555aBc8eE4E8" + "SocketBatcher": "0xe54f19dCD6f855296F57BC26a899f278E369464e" }, "2999": { "SignatureVerifier": "0x6D290609b3F5F02D52F28d97C75a443ED8564cBf", @@ -796,7 +796,7 @@ "FastSwitchboard2": "0xedAC223C3Fe694A6d4c8407b4f6e95c299d6Eba6", "OptimisticSwitchboard": "0x6977afB0d9F041327D2C7d1E9d412685C1B202ea", "Counter": "0xAf8FcDA8536eBA1dDf2e6F8E405ADAd5C44b8568", - "SocketBatcher": "0x4941AE128a3d0d276d5ABA751B596f1173b2b762" + "SocketBatcher": "0x60dB9641eFee65c437aD8a44D3CEc7fB7934eD9c" }, "421613": { "SignatureVerifier": "0x52e987409522F2abeaD9A66B87B8914Dc5A071D9", @@ -887,7 +887,7 @@ "FastSwitchboard2": "0xB73f329E38265E6a619eeC198A8eC4DB0b9ebe21", "OptimisticSwitchboard": "0xb56e8417755685E6d01A11598f6a1229F11Cc9b5", "Counter": "0x07680Ca88B8Df538A5aB564BBBD3E4F3aBbF97eE", - "SocketBatcher": "0x3F8cdB2F8F61c31855cA6314FFA480F4dEe9574f" + "SocketBatcher": "0x762769E24b61800682B7a66C83835f9C23FB9955" }, "11155111": { "SignatureVerifier": "0x10d9DA6AE85eff6D582A91829f78bde2a3EC2dCC", @@ -899,8 +899,8 @@ "integrations": {}, "FastSwitchboard2": "0x501fCBa3e6F92b2D1d89038FeD56EdacaaF5f7c2", "OptimisticSwitchboard": "0xd84fabe06806270Fb2dDFC2255102206e3B36865", - "SocketBatcher": "0xBc3Ff3923b36F1590C16363b09c4759654d7B6d4", - "Counter": "0xE593288228d17a6D057D9a61a35F32166A6B4191" + "Counter": "0xE593288228d17a6D057D9a61a35F32166A6B4191", + "SocketBatcher": "0x6ba1161bbBC353F4173eB9f785E3A0513264769d" }, "11155112": { "SignatureVerifier": "0x7E3D0FAC82b9d5a67906f7028Aa4a70d582011b2", @@ -986,7 +986,7 @@ "FastSwitchboard2": "0x61438D1E9C9127F4996E2f74bb7BF62CC7f9B32F", "OptimisticSwitchboard": "0xFCd8ebA25c0e0973Fd131b6bF77fd8dAEcCaC75B", "Counter": "0x21abD53f1150b6DFA1111E4F2b7536F6eaA48538", - "SocketBatcher": "0xd17A64B37b432Bc344420D12eD086c5E6BEC1a30" + "SocketBatcher": "0xaE966C37eAb996B2bA55f0b3caD61564EBD691Fa" }, "1399904803": { "SignatureVerifier": "0x03D51955216a7E6F301e0613515fA86A6f3d59A9", @@ -997,7 +997,6 @@ "TransmitManager": "0x0777Ab388f065FC3CdB96008C701751827Ee171B", "FastSwitchboard2": "0x2735d5B15066049a709e680b2D400155aA5A91BE", "OptimisticSwitchboard": "0x59AcE34e5c47aEe3ec8feF2A89DcF14Ac98538C9", - "SocketBatcher": "0x0B35F40f13C3641bDed7654C9a7620cFa312aA7a", "Counter": "0x91C27Cad374246314E756f8Aa2f62F433d6F102C", "integrations": { "5": { @@ -1072,6 +1071,7 @@ "switchboard": "0x59AcE34e5c47aEe3ec8feF2A89DcF14Ac98538C9" } } - } + }, + "SocketBatcher": "0xaa95869960B4f783b17410a7E9e4b91DA3b371C4" } } diff --git a/deployments/prod_verification.json b/deployments/prod_verification.json index 807eda51..5b1a67d0 100644 --- a/deployments/prod_verification.json +++ b/deployments/prod_verification.json @@ -1,5 +1,11 @@ { "5": [ + [ + "0x5a23e41c1ff969244eE2A5D563519b170F143AcD", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xB5f289a6Af87A65fddF1a7068F556E7d669c0D4b", "SocketBatcher", @@ -479,6 +485,12 @@ ] ], "420": [ + [ + "0xE0DD154111D407Db671eAeC703CF472d3a2c5333", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xb80d97657277e24d70caee6dEF92BFaa7D884A7f", "SocketBatcher", @@ -600,6 +612,12 @@ ] ], "901": [ + [ + "0xe54f19dCD6f855296F57BC26a899f278E369464e", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xb2dA552c9Baa0e15b13302aBBF7B555aBc8eE4E8", "SocketBatcher", @@ -923,6 +941,12 @@ ] ], "80001": [ + [ + "0x60dB9641eFee65c437aD8a44D3CEc7fB7934eD9c", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0x4941AE128a3d0d276d5ABA751B596f1173b2b762", "SocketBatcher", @@ -1043,6 +1067,12 @@ ] ], "421613": [ + [ + "0x762769E24b61800682B7a66C83835f9C23FB9955", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0x3F8cdB2F8F61c31855cA6314FFA480F4dEe9574f", "SocketBatcher", @@ -1162,6 +1192,12 @@ ] ], "11155111": [ + [ + "0x6ba1161bbBC353F4173eB9f785E3A0513264769d", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xE593288228d17a6D057D9a61a35F32166A6B4191", "Counter", @@ -1264,6 +1300,12 @@ ] ], "11155112": [ + [ + "0xaE966C37eAb996B2bA55f0b3caD61564EBD691Fa", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xd17A64B37b432Bc344420D12eD086c5E6BEC1a30", "SocketBatcher", @@ -1372,6 +1414,12 @@ ] ], "1399904803": [ + [ + "0xaa95869960B4f783b17410a7E9e4b91DA3b371C4", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0x91C27Cad374246314E756f8Aa2f62F433d6F102C", "Counter", diff --git a/hardhat.config.ts b/hardhat.config.ts index 3f981087..c5a80983 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -111,7 +111,7 @@ const config: HardhatUserConfig = { }, networks: { hardhat: { - chainId: hardhatChainNameToSlug.hardhat, + chainId: hardhatChainNameToSlug[HardhatChainName.HARDHAT], }, ...liveNetworks, }, diff --git a/package.json b/package.json index 61022a89..f9391435 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@socket.tech/dl-core", "license": "UNLICENSED", - "version": "2.4.8", + "version": "2.4.9-test.0", "description": "Smart contracts for socket data layer.", "main": "./dist/src/index.js", "types": "./dist/src/index.d.ts", @@ -26,7 +26,7 @@ "@nomiclabs/hardhat-ethers": "^2.1.1", "@nomiclabs/hardhat-etherscan": "^3.1.0", "@nomiclabs/hardhat-waffle": "^2.0.3", - "@socket.tech/dl-core": "2.4.5", + "@socket.tech/dl-core": "2.4.9", "@typechain/ethers-v5": "^10.0.0", "@typechain/hardhat": "^6.0.0", "@types/chai": "^4.3.0", diff --git a/scripts/constants/config.ts b/scripts/constants/config.ts index d92b5581..3d44ee0b 100644 --- a/scripts/constants/config.ts +++ b/scripts/constants/config.ts @@ -1,31 +1,15 @@ -import { - ChainSlug, - IntegrationTypes, - NativeSwitchboard, -} from "../../src/types"; +import { ChainSlug, IntegrationTypes, NativeSwitchboard } from "../../src"; +import { chainConfig } from "../../chainConfig"; export const maxAllowedPacketLength = 10; -export const timeout: { - [key: string]: number; -} = { - [ChainSlug.BSC_TESTNET]: 7200, - [ChainSlug.POLYGON_MAINNET]: 7200, - [ChainSlug.BSC]: 7200, - [ChainSlug.POLYGON_MUMBAI]: 7200, - [ChainSlug.ARBITRUM_GOERLI]: 7200, - [ChainSlug.OPTIMISM_GOERLI]: 7200, - [ChainSlug.GOERLI]: 7200, - [ChainSlug.HARDHAT]: 7200, - [ChainSlug.ARBITRUM]: 7200, - [ChainSlug.OPTIMISM]: 7200, - [ChainSlug.MAINNET]: 7200, - [ChainSlug.SEPOLIA]: 7200, - [ChainSlug.AEVO_TESTNET]: 7200, - [ChainSlug.AEVO]: 7200, - [ChainSlug.LYRA_TESTNET]: 7200, - [ChainSlug.LYRA]: 7200, - [ChainSlug.XAI_TESTNET]: 7200, +const TIMEOUT = 7200; + +// return chain specific timeout if present else default value +export const timeout = (chain: number): number => { + if (chainConfig[chain] && chainConfig[chain].timeout) + return chainConfig[chain].timeout; + return TIMEOUT; }; export const getDefaultIntegrationType = ( diff --git a/scripts/constants/networks.ts b/scripts/constants/networks.ts index 5a0b1dca..576c53ae 100644 --- a/scripts/constants/networks.ts +++ b/scripts/constants/networks.ts @@ -6,13 +6,13 @@ import { HardhatChainName, ChainSlug, ChainSlugToKey, + hardhatChainNameToSlug, } from "../../src"; +import { chainConfig } from "../../chainConfig"; const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env"; dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) }); -export const chainSlugKeys: string[] = Object.values(ChainSlugToKey); - export function getJsonRpcUrl(chain: HardhatChainName | ChainId): string { let jsonRpcUrl: string; switch (chain) { @@ -107,7 +107,11 @@ export function getJsonRpcUrl(chain: HardhatChainName | ChainId): string { break; default: - throw new Error("JSON RPC URL not found!!"); + const config = + chainConfig[chain] || chainConfig[hardhatChainNameToSlug[chain]]; + if (config && config.rpc) { + jsonRpcUrl = config.rpc; + } else throw new Error("JSON RPC URL not found!!"); } return jsonRpcUrl; diff --git a/scripts/deploy/1-deploy.ts b/scripts/deploy/1-deploy.ts new file mode 100644 index 00000000..55b71e92 --- /dev/null +++ b/scripts/deploy/1-deploy.ts @@ -0,0 +1,20 @@ +import { chains } from "./config"; +import { deployForChains } from "./scripts/deploySocketFor"; + +/** + * Deploys network-independent socket contracts + */ +const deploy = async () => { + try { + await deployForChains(chains); + } catch (error) { + console.log("Error while deploying contracts"); + } +}; + +deploy() + .then(() => process.exit(0)) + .catch((error: Error) => { + console.error(error); + process.exit(1); + }); diff --git a/scripts/deploy/2-check-roles.ts b/scripts/deploy/2-check-roles.ts new file mode 100644 index 00000000..43062d9f --- /dev/null +++ b/scripts/deploy/2-check-roles.ts @@ -0,0 +1,234 @@ +import { config as dotenvConfig } from "dotenv"; +dotenvConfig(); + +import { ROLES, CORE_CONTRACTS } from "../../src"; +import { + executorAddresses, + filterChains, + filterSiblingChains, + mode, + newRoleStatus, + sendTransaction, + socketOwner, + transmitterAddresses, + watcherAddresses, + executionManagerVersion, +} from "./config"; +import { checkAndUpdateRoles } from "./scripts/roles"; + +const main = async () => { + let ownerAddress = socketOwner; + let executorAddress = executorAddresses[mode]; + let transmitterAddress = transmitterAddresses[mode]; + let watcherAddress = watcherAddresses[mode]; + + let summary: { params: any; roleStatus: any }[] = []; + + // Grant rescue,withdraw and governance role for Execution Manager to owner + let s = await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: ownerAddress, + filterRoles: [ + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: transmitterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + { + userAddress: executorAddress, + filterRoles: [ROLES.EXECUTOR_ROLE], + }, + ], + contractName: executionManagerVersion, + filterChains, + filterSiblingChains, + sendTransaction, + newRoleStatus, + }); + summary.push(s); + + // Grant owner roles for TransmitManager + s = await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: ownerAddress, + filterRoles: [ + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: transmitterAddress, + filterRoles: [ROLES.TRANSMITTER_ROLE, ROLES.FEES_UPDATER_ROLE], + }, + ], + contractName: CORE_CONTRACTS.TransmitManager, + filterChains, + filterSiblingChains, + sendTransaction, + newRoleStatus, + }); + summary.push(s); + + // Grant owner roles in socket + s = await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: ownerAddress, + filterRoles: [ROLES.RESCUE_ROLE, ROLES.GOVERNANCE_ROLE], + }, + ], + contractName: CORE_CONTRACTS.Socket, + filterChains, + filterSiblingChains, + sendTransaction, + newRoleStatus, + }); + summary.push(s); + + // Setup Fast Switchboard roles + s = await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: ownerAddress, + filterRoles: [ + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.TRIP_ROLE, + ROLES.UN_TRIP_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: transmitterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + { + userAddress: watcherAddress, + filterRoles: [ROLES.WATCHER_ROLE], + }, + ], + + contractName: CORE_CONTRACTS.FastSwitchboard, + filterChains, + filterSiblingChains, + sendTransaction, + newRoleStatus, + }); + summary.push(s); + + // Setup Fast Switchboard2 roles + s = await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: ownerAddress, + filterRoles: [ + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.TRIP_ROLE, + ROLES.UN_TRIP_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: transmitterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + { + userAddress: watcherAddress, + filterRoles: [ROLES.WATCHER_ROLE], + }, + ], + + contractName: CORE_CONTRACTS.FastSwitchboard2, + filterChains, + filterSiblingChains, + sendTransaction, + newRoleStatus, + }); + summary.push(s); + + // Grant watcher role to watcher for OptimisticSwitchboard + s = await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: ownerAddress, + filterRoles: [ + ROLES.TRIP_ROLE, + ROLES.UN_TRIP_ROLE, + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: transmitterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], // all roles + }, + { + userAddress: watcherAddress, + filterRoles: [ROLES.WATCHER_ROLE], + }, + ], + contractName: CORE_CONTRACTS.OptimisticSwitchboard, + filterChains, + filterSiblingChains, + sendTransaction, + newRoleStatus, + }); + summary.push(s); + + // Grant owner roles in NativeSwitchboard + s = await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: ownerAddress, + filterRoles: [ + ROLES.TRIP_ROLE, + ROLES.UN_TRIP_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.RESCUE_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], // all roles + }, + { + userAddress: transmitterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], // all roles + }, + ], + contractName: CORE_CONTRACTS.NativeSwitchboard, + filterChains, + filterSiblingChains, + sendTransaction, + newRoleStatus, + }); + summary.push(s); + + console.log( + "=========================== SUMMARY =================================" + ); + + summary.forEach((result) => { + console.log("============================================="); + console.log("params:", result.params); + console.log("role status: ", JSON.stringify(result.roleStatus)); + }); +}; + +main() + .then(() => process.exit(0)) + .catch((error: Error) => { + console.error(error); + process.exit(1); + }); diff --git a/scripts/deploy/3-configure.ts b/scripts/deploy/3-configure.ts new file mode 100644 index 00000000..4c3bacb6 --- /dev/null +++ b/scripts/deploy/3-configure.ts @@ -0,0 +1,143 @@ +import fs from "fs"; +import { Wallet } from "ethers"; + +import { getProviderFromChainSlug } from "../constants"; +import { + deployedAddressPath, + getSwitchboardAddress, + storeAllAddresses, +} from "./utils"; +import { + CORE_CONTRACTS, + ChainSlug, + ChainSocketAddresses, + DeploymentAddresses, + IntegrationTypes, + MainnetIds, + TestnetIds, + isTestnet, +} from "../../src"; +import registerSwitchboardForSibling from "./scripts/registerSwitchboard"; +import { + capacitorType, + chains, + maxPacketLength, + mode, + executionManagerVersion, +} from "./config"; +import { + configureExecutionManager, + registerSwitchboards, + setManagers, + setupPolygonNativeSwitchboard, +} from "./scripts/configureSocket"; + +export const main = async () => { + try { + if (!fs.existsSync(deployedAddressPath(mode))) { + throw new Error("addresses.json not found"); + } + let addresses: DeploymentAddresses = JSON.parse( + fs.readFileSync(deployedAddressPath(mode), "utf-8") + ); + + await Promise.all( + chains.map(async (chain) => { + if (!addresses[chain]) return; + + const providerInstance = getProviderFromChainSlug( + chain as any as ChainSlug + ); + const socketSigner: Wallet = new Wallet( + process.env.SOCKET_SIGNER_KEY as string, + providerInstance + ); + + let addr: ChainSocketAddresses = addresses[chain]!; + + const list = isTestnet(chain) ? TestnetIds : MainnetIds; + const siblingSlugs: ChainSlug[] = list.filter( + (chainSlug) => chainSlug !== chain && chains.includes(chainSlug) + ); + + await configureExecutionManager( + executionManagerVersion, + addr[executionManagerVersion]!, + addr[CORE_CONTRACTS.SocketBatcher], + chain, + siblingSlugs, + socketSigner + ); + + await setManagers(addr, socketSigner); + + const integrations = addr["integrations"] ?? {}; + const integrationList = Object.keys(integrations).filter((chain) => + chains.includes(parseInt(chain) as ChainSlug) + ); + + console.log(`Configuring for ${chain}`); + + for (let sibling of integrationList) { + const config = integrations[sibling][IntegrationTypes.native]; + if (!config) continue; + + const siblingSwitchboard = getSwitchboardAddress( + chain, + IntegrationTypes.native, + addresses?.[sibling] + ); + + if (!siblingSwitchboard) continue; + + addr = await registerSwitchboardForSibling( + config["switchboard"], + siblingSwitchboard, + sibling, + capacitorType, + maxPacketLength, + socketSigner, + IntegrationTypes.native, + addr + ); + } + + addr = await registerSwitchboards( + chain, + siblingSlugs, + CORE_CONTRACTS.FastSwitchboard2, + IntegrationTypes.fast2, + addr, + addresses, + socketSigner + ); + + addr = await registerSwitchboards( + chain, + siblingSlugs, + CORE_CONTRACTS.OptimisticSwitchboard, + IntegrationTypes.optimistic, + addr, + addresses, + socketSigner + ); + + addresses[chain] = addr; + + console.log(`Configuring for ${chain} - COMPLETED`); + }) + ); + + await storeAllAddresses(addresses, mode); + await setupPolygonNativeSwitchboard(addresses); + } catch (error) { + console.log("Error while sending transaction", error); + } +}; + +main() + .then(() => process.exit(0)) + .catch((error: Error) => { + console.error(error); + process.exit(1); + }); diff --git a/scripts/deploy/connect.ts b/scripts/deploy/4-connect.ts similarity index 95% rename from scripts/deploy/connect.ts rename to scripts/deploy/4-connect.ts index 24f128af..fd9b52da 100644 --- a/scripts/deploy/connect.ts +++ b/scripts/deploy/4-connect.ts @@ -12,7 +12,6 @@ import { TestnetIds, getAllAddresses, isTestnet, - ChainSlugToKey, } from "../../src"; import { chains, mode } from "./config"; import { Contract, Wallet } from "ethers"; @@ -46,10 +45,7 @@ export const main = async () => { const siblingIntegrationtype: IntegrationTypes[] = siblingSlugs.map( (chainSlug) => { - return getDefaultIntegrationType( - ChainSlugToKey[chain], - ChainSlugToKey[chainSlug] - ); + return getDefaultIntegrationType(chain, chainSlug); } ); diff --git a/scripts/deploy/verify.ts b/scripts/deploy/5-verify.ts similarity index 90% rename from scripts/deploy/verify.ts rename to scripts/deploy/5-verify.ts index 60b15487..2c2092a3 100644 --- a/scripts/deploy/verify.ts +++ b/scripts/deploy/5-verify.ts @@ -3,7 +3,7 @@ import fs from "fs"; import { deploymentsPath, verify } from "./utils/utils"; import { mode } from "./config"; -import { HardhatChainName, ChainSlugToKey } from "../../src"; +import { HardhatChainName, ChainSlugToKey, ChainSlug } from "../../src"; export type VerifyParams = { [chain in HardhatChainName]?: VerifyArgs[]; @@ -27,7 +27,7 @@ export const main = async () => { if (!chains) return; for (let chainIndex = 0; chainIndex < chains.length; chainIndex++) { - const chain = chains[chainIndex]; + const chain = parseInt(chains[chainIndex]) as ChainSlug; hre.changeNetwork(ChainSlugToKey[chain]); const chainParams: VerifyArgs[] = verificationParams[chain]; diff --git a/scripts/deploy/verifyDeployments.ts b/scripts/deploy/6-smoke-test.ts similarity index 99% rename from scripts/deploy/verifyDeployments.ts rename to scripts/deploy/6-smoke-test.ts index 31b156b8..3a5cd9db 100644 --- a/scripts/deploy/verifyDeployments.ts +++ b/scripts/deploy/6-smoke-test.ts @@ -439,10 +439,7 @@ export const main = async () => { remoteChain, localConfig, remoteConfig, - getDefaultIntegrationType( - ChainSlugToKey[chain], - ChainSlugToKey[remoteConfig] - ) + getDefaultIntegrationType(chain, remoteConfig) ); console.log("✅ Checked Counter"); diff --git a/scripts/deploy/config.ts b/scripts/deploy/config.ts index ac599839..db0444c2 100644 --- a/scripts/deploy/config.ts +++ b/scripts/deploy/config.ts @@ -3,6 +3,8 @@ dotenvConfig(); import { ChainSlug, DeploymentMode, CORE_CONTRACTS, version } from "../../src"; import { BigNumberish, utils } from "ethers"; +import { chainConfig } from "../../chainConfig"; + export const mode = process.env.DEPLOYMENT_MODE as | DeploymentMode | DeploymentMode.DEV; @@ -28,14 +30,16 @@ console.log( ); export const chains: Array = [ - // ChainSlug.GOERLI, + ChainSlug.GOERLI, ChainSlug.ARBITRUM_GOERLI, ChainSlug.OPTIMISM_GOERLI, ChainSlug.POLYGON_MUMBAI, + ChainSlug.SX_NETWORK_TESTNET, ChainSlug.BSC_TESTNET, ChainSlug.AEVO_TESTNET, ChainSlug.LYRA_TESTNET, ChainSlug.SEPOLIA, + ChainSlug.XAI_TESTNET, ChainSlug.AEVO, ChainSlug.MAINNET, ChainSlug.ARBITRUM, @@ -43,7 +47,6 @@ export const chains: Array = [ ChainSlug.LYRA, ChainSlug.BSC, ChainSlug.POLYGON_MAINNET, - ChainSlug.XAI_TESTNET, ]; export const executionManagerVersion = CORE_CONTRACTS.ExecutionManager; @@ -59,23 +62,11 @@ export const gasLimit = undefined; export const gasPrice = undefined; export const type = 0; -export const msgValueMaxThreshold: { [chain in ChainSlug]?: BigNumberish } = { - [ChainSlug.ARBITRUM_GOERLI]: utils.parseEther("0.001"), - [ChainSlug.OPTIMISM_GOERLI]: utils.parseEther("0.001"), - [ChainSlug.POLYGON_MUMBAI]: utils.parseEther("0.1"), - [ChainSlug.BSC_TESTNET]: utils.parseEther("0.001"), - [ChainSlug.GOERLI]: utils.parseEther("0.001"), - [ChainSlug.SEPOLIA]: utils.parseEther("0.001"), - [ChainSlug.ARBITRUM]: utils.parseEther("0.001"), - [ChainSlug.OPTIMISM]: utils.parseEther("0.001"), - [ChainSlug.POLYGON_MAINNET]: utils.parseEther("0.1"), - [ChainSlug.BSC]: utils.parseEther("0.001"), - [ChainSlug.MAINNET]: utils.parseEther("0.001"), - [ChainSlug.AEVO_TESTNET]: utils.parseEther("0.001"), - [ChainSlug.AEVO]: utils.parseEther("0.001"), - [ChainSlug.LYRA_TESTNET]: utils.parseEther("0.001"), - [ChainSlug.LYRA]: utils.parseEther("0.001"), - [ChainSlug.XAI_TESTNET]: utils.parseEther("0.001"), +const MSG_VALUE_MAX_THRESHOLD = utils.parseEther("0.001"); +export const msgValueMaxThreshold = (chain: ChainSlug): BigNumberish => { + if (chainConfig[chain] && chainConfig[chain].msgValueMaxThreshold) + return chainConfig[chain].msgValueMaxThreshold!; + return MSG_VALUE_MAX_THRESHOLD; }; export const transmitterAddresses = { @@ -97,91 +88,15 @@ export const executorAddresses = { [DeploymentMode.PROD]: "0x42639d8fd154b72472e149a7d5ac13fa280303d9", }; -export const overrides: { - [chain in ChainSlug | number]?: { - type?: number | undefined; - gasLimit?: BigNumberish | undefined; - gasPrice?: BigNumberish | undefined; - }; -} = { - [ChainSlug.ARBITRUM]: { - type, - gasLimit: 20_000_000, - gasPrice, - }, - [ChainSlug.ARBITRUM_GOERLI]: { - // type, - // gasLimit: 20_000_000, - // gasPrice, - }, - [ChainSlug.OPTIMISM]: { - type, - gasLimit: 2_000_000, - gasPrice, - }, - [ChainSlug.OPTIMISM_GOERLI]: { - // type, - // gasLimit: 20_000_000, - // gasPrice, - }, - [ChainSlug.BSC]: { - type, - gasLimit, - gasPrice, - }, - [ChainSlug.BSC_TESTNET]: { - type, - gasLimit, - gasPrice, - }, - [ChainSlug.MAINNET]: { - type, - gasLimit, - gasPrice, - }, - [ChainSlug.GOERLI]: { - type, - gasLimit: 3_000_000, - gasPrice, - }, - [ChainSlug.POLYGON_MAINNET]: { - type, - gasLimit, - gasPrice: 250_000_000_000, - }, - [ChainSlug.POLYGON_MUMBAI]: { - type: 0, - gasLimit: 2_000_000, - gasPrice, - }, - [ChainSlug.SEPOLIA]: { - type, - gasLimit, - gasPrice, - }, - [ChainSlug.AEVO_TESTNET]: { - type: 2, - // gasLimit, - // gasPrice, - }, - [ChainSlug.AEVO]: { - type: 1, - // gasLimit, - gasPrice: 100_000_000, - }, - [ChainSlug.LYRA_TESTNET]: { - type: 2, - // gasLimit, - // gasPrice: 100_000_000, - }, - [ChainSlug.LYRA]: { - // type: 1, - // gasLimit, - // gasPrice: 100_000_000, - }, - [ChainSlug.XAI_TESTNET]: { - // type: 1, - // gasLimit, - // gasPrice: 100_000_000, - }, +export const overrides = ( + chain: ChainSlug | number +): { + type?: number | undefined; + gasLimit?: BigNumberish | undefined; + gasPrice?: BigNumberish | undefined; +} => { + if (chainConfig[chain] && chainConfig[chain].overrides) + return chainConfig[chain].overrides!; + + return { type, gasLimit, gasPrice }; }; diff --git a/scripts/deploy/configure.ts b/scripts/deploy/configure.ts deleted file mode 100644 index 99c814b5..00000000 --- a/scripts/deploy/configure.ts +++ /dev/null @@ -1,362 +0,0 @@ -import fs from "fs"; -import { Wallet, constants } from "ethers"; - -import { getProviderFromChainSlug, switchboards } from "../constants"; -import { - deployedAddressPath, - getInstance, - getSwitchboardAddress, - storeAllAddresses, -} from "./utils"; -import { - CORE_CONTRACTS, - ChainSlug, - ChainSocketAddresses, - DeploymentAddresses, - IntegrationTypes, - MainnetIds, - NativeSwitchboard, - TestnetIds, - isTestnet, - ChainSlugToKey, -} from "../../src"; -import registerSwitchboardForSibling from "./scripts/registerSwitchboard"; -import { arrayify, defaultAbiCoder, keccak256, id } from "ethers/lib/utils"; -import { - capacitorType, - chains, - maxPacketLength, - mode, - executionManagerVersion, - overrides, - msgValueMaxThreshold, -} from "./config"; - -export const main = async () => { - try { - if (!fs.existsSync(deployedAddressPath(mode))) { - throw new Error("addresses.json not found"); - } - let addresses: DeploymentAddresses = JSON.parse( - fs.readFileSync(deployedAddressPath(mode), "utf-8") - ); - let chain: ChainSlug; - - await Promise.all( - chains.map(async (chain) => { - if (!addresses[chain]) return; - - const providerInstance = getProviderFromChainSlug( - chain as any as ChainSlug - ); - const socketSigner: Wallet = new Wallet( - process.env.SOCKET_SIGNER_KEY as string, - providerInstance - ); - - let addr: ChainSocketAddresses = addresses[chain]!; - - const list = isTestnet(chain) ? TestnetIds : MainnetIds; - const siblingSlugs: ChainSlug[] = list.filter( - (chainSlug) => chainSlug !== chain && chains.includes(chainSlug) - ); - - await configureExecutionManager( - addr, - executionManagerVersion, - chain, - siblingSlugs, - socketSigner - ); - - const socket = ( - await getInstance(CORE_CONTRACTS.Socket, addr.Socket) - ).connect(socketSigner); - - let tx; - const currentEM = await socket.executionManager__(); - if ( - currentEM.toLowerCase() !== - addr[executionManagerVersion]?.toLowerCase() - ) { - tx = await socket.setExecutionManager(addr[executionManagerVersion], { - ...overrides[await socketSigner.getChainId()], - }); - console.log("updateExecutionManager", tx.hash); - await tx.wait(); - } - - const currentTM = await socket.transmitManager__(); - if (currentTM.toLowerCase() !== addr.TransmitManager?.toLowerCase()) { - tx = await socket.setTransmitManager(addr.TransmitManager, { - ...overrides[await socketSigner.getChainId()], - }); - console.log("updateTransmitManager", tx.hash); - await tx.wait(); - } - - const integrations = addr["integrations"] ?? {}; - const integrationList = Object.keys(integrations).filter((chain) => - chains.includes(parseInt(chain) as ChainSlug) - ); - - console.log(`Configuring for ${chain}`); - - for (let sibling of integrationList) { - const config = integrations[sibling][IntegrationTypes.native]; - if (!config) continue; - - const siblingSwitchboard = getSwitchboardAddress( - chain, - IntegrationTypes.native, - addresses?.[sibling] - ); - - if (!siblingSwitchboard) continue; - - addr = await registerSwitchboardForSibling( - config["switchboard"], - siblingSwitchboard, - sibling, - capacitorType, - maxPacketLength, - socketSigner, - IntegrationTypes.native, - addr - ); - } - - // register fast2 - for (let sibling of siblingSlugs) { - const siblingSwitchboard = getSwitchboardAddress( - chain, - IntegrationTypes.fast2, - addresses?.[sibling] - ); - - if (!siblingSwitchboard || !addr[CORE_CONTRACTS.FastSwitchboard2]) - continue; - - addr = await registerSwitchboardForSibling( - addr[CORE_CONTRACTS.FastSwitchboard2], - siblingSwitchboard, - sibling, - capacitorType, - maxPacketLength, - socketSigner, - IntegrationTypes.fast2, - addr - ); - } - - // register optimistic - for (let sibling of siblingSlugs) { - const siblingSwitchboard = getSwitchboardAddress( - chain, - IntegrationTypes.optimistic, - addresses?.[sibling] - ); - - if (!siblingSwitchboard) continue; - - addr = await registerSwitchboardForSibling( - addr[CORE_CONTRACTS.OptimisticSwitchboard], - siblingSwitchboard, - sibling, - capacitorType, - maxPacketLength, - socketSigner, - IntegrationTypes.optimistic, - addr - ); - } - - addresses[chain] = addr; - - console.log(`Configuring for ${chain} - COMPLETED`); - }) - ); - - await storeAllAddresses(addresses, mode); - await setupPolygonNativeSwitchboard(addresses); - } catch (error) { - console.log("Error while sending transaction", error); - } -}; - -const configureExecutionManager = async ( - addr: ChainSocketAddresses, - contractName: string, - chain: ChainSlug, - siblingSlugs: ChainSlug[], - socketSigner: Wallet -) => { - try { - console.log( - "configuring execution manager for ", - chain, - addr[contractName] - ); - - let executionManagerContract, socketBatcherContract; - executionManagerContract = ( - await getInstance(contractName, addr[contractName]!) - ).connect(socketSigner); - - let nextNonce = ( - await executionManagerContract.nextNonce(socketSigner.address) - ).toNumber(); - // console.log({ nextNonce }); - - let requests: any = []; - - await Promise.all( - siblingSlugs.map(async (siblingSlug) => { - let currentValue = await executionManagerContract.msgValueMaxThreshold( - siblingSlug - ); - - if ( - currentValue.toString() == - msgValueMaxThreshold[siblingSlug]?.toString() - ) { - // console.log("already set, returning ", { currentValue }); - return; - } - - const digest = keccak256( - defaultAbiCoder.encode( - ["bytes32", "address", "uint32", "uint32", "uint256", "uint256"], - [ - id("MSG_VALUE_MAX_THRESHOLD_UPDATE"), - addr[contractName]!, - chain, - siblingSlug, - nextNonce, - msgValueMaxThreshold[siblingSlug], - ] - ) - ); - - const signature = await socketSigner.signMessage(arrayify(digest)); - - let request = { - signature, - dstChainSlug: siblingSlug, - nonce: nextNonce++, - fees: msgValueMaxThreshold[siblingSlug], - functionSelector: "0xa1885700", // setMsgValueMaxThreshold - }; - requests.push(request); - }) - ); - - if (requests.length === 0) return; - socketBatcherContract = ( - await getInstance("SocketBatcher", addr[CORE_CONTRACTS.SocketBatcher]!) - ).connect(socketSigner); - - let tx = await socketBatcherContract.setExecutionFeesBatch( - addr[contractName]!, - requests, - { ...overrides[chain] } - ); - console.log(chain, tx.hash); - await tx.wait(); - } catch (error) { - console.log("error while configuring execution manager: ", error); - } -}; - -const setupPolygonNativeSwitchboard = async (addresses) => { - try { - let srcChains = Object.keys(addresses).filter((chain) => - ["5", "1", "80001", "137"].includes(chain) - ); - - await Promise.all( - srcChains.map(async (srcChain) => { - console.log(`Configuring for ${srcChain}`); - - const providerInstance = getProviderFromChainSlug( - srcChain as any as ChainSlug - ); - const socketSigner: Wallet = new Wallet( - process.env.SOCKET_SIGNER_KEY as string, - providerInstance - ); - - for (let dstChain in addresses[srcChain]?.["integrations"]) { - const dstConfig = addresses[srcChain]["integrations"][dstChain]; - if (!dstConfig?.[IntegrationTypes.native]) continue; - - const srcSwitchboardType = - switchboards[ChainSlugToKey[srcChain]]?.[ - ChainSlugToKey[dstChain] - ]?.["switchboard"]; - - const dstSwitchboardAddress = getSwitchboardAddress( - srcChain, - IntegrationTypes.native, - addresses?.[dstChain] - ); - if (!dstSwitchboardAddress) continue; - - const srcSwitchboardAddress = - dstConfig?.[IntegrationTypes.native]["switchboard"]; - - if (srcSwitchboardType === NativeSwitchboard.POLYGON_L1) { - const sbContract = ( - await getInstance("PolygonL1Switchboard", srcSwitchboardAddress) - ).connect(socketSigner); - - const fxChild = await sbContract.fxChildTunnel(); - if (fxChild !== constants.AddressZero) continue; - console.log( - `Setting ${dstSwitchboardAddress} fx child tunnel in ${srcSwitchboardAddress} on networks ${srcChain}-${dstChain}` - ); - - const tx = await sbContract - .connect(socketSigner) - .setFxChildTunnel(dstSwitchboardAddress, { - ...overrides[await socketSigner.getChainId()], - }); - console.log(srcChain, tx.hash); - await tx.wait(); - } else if (srcSwitchboardType === NativeSwitchboard.POLYGON_L2) { - const sbContract = ( - await getInstance("PolygonL2Switchboard", srcSwitchboardAddress) - ).connect(socketSigner); - - const fxRoot = await sbContract.fxRootTunnel(); - if (fxRoot !== constants.AddressZero) continue; - console.log( - `Setting ${dstSwitchboardAddress} fx root tunnel in ${srcSwitchboardAddress} on networks ${srcChain}-${dstChain}` - ); - - const tx = await sbContract - .connect(socketSigner) - .setFxRootTunnel(dstSwitchboardAddress, { - ...overrides[await socketSigner.getChainId()], - }); - console.log(srcChain, tx.hash); - await tx.wait(); - } else continue; - } - - console.log( - `Configuring remote switchboards for ${srcChain} - COMPLETED` - ); - }) - ); - } catch (error) { - console.error(error); - } -}; - -main() - .then(() => process.exit(0)) - .catch((error: Error) => { - console.error(error); - process.exit(1); - }); diff --git a/scripts/deploy/scripts/capacitorCount.ts b/scripts/deploy/helpers/capacitorCount.ts similarity index 97% rename from scripts/deploy/scripts/capacitorCount.ts rename to scripts/deploy/helpers/capacitorCount.ts index e5ecda01..319ab06b 100644 --- a/scripts/deploy/scripts/capacitorCount.ts +++ b/scripts/deploy/helpers/capacitorCount.ts @@ -14,7 +14,7 @@ import { ChainSlug, IntegrationTypes, } from "../../../src"; -import deploySwitchboards from "./deploySwitchboard"; +import deploySwitchboards from "../scripts/deploySwitchboard"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { socketOwner, executionManagerVersion, mode, chains } from "../config"; import { diff --git a/scripts/deploy/scripts/checkBalance.ts b/scripts/deploy/helpers/checkBalance.ts similarity index 86% rename from scripts/deploy/scripts/checkBalance.ts rename to scripts/deploy/helpers/checkBalance.ts index bb26589d..0a48a4d7 100644 --- a/scripts/deploy/scripts/checkBalance.ts +++ b/scripts/deploy/helpers/checkBalance.ts @@ -6,7 +6,7 @@ import { ChainSlugToKey } from "../../../src"; import { utils } from "ethers"; import { chains, mode } from "../config"; -import { getProviderFromChainName } from "../../constants/networks"; +import { getProviderFromChainSlug } from "../../constants/networks"; // check balance of owner address on all chains export const checkBalance = async () => { @@ -14,9 +14,7 @@ export const checkBalance = async () => { // parallelize chains await Promise.all( chains.map(async (chainSlug) => { - const provider = await getProviderFromChainName( - ChainSlugToKey[chainSlug] - ); + const provider = await getProviderFromChainSlug(chainSlug); // let ownerAddress = process.env.SOCKET_OWNER_ADDRESS; let ownerAddress = "0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"; if (!ownerAddress) throw Error("owner address not present"); diff --git a/scripts/deploy/scripts/estimateGas.ts b/scripts/deploy/helpers/estimateGas.ts similarity index 100% rename from scripts/deploy/scripts/estimateGas.ts rename to scripts/deploy/helpers/estimateGas.ts diff --git a/scripts/deploy/scripts/fastSwitchboards.ts b/scripts/deploy/helpers/fastSwitchboards.ts similarity index 97% rename from scripts/deploy/scripts/fastSwitchboards.ts rename to scripts/deploy/helpers/fastSwitchboards.ts index dfd8db76..c216bf12 100644 --- a/scripts/deploy/scripts/fastSwitchboards.ts +++ b/scripts/deploy/helpers/fastSwitchboards.ts @@ -14,7 +14,7 @@ import { ChainSlug, IntegrationTypes, } from "../../../src"; -import deploySwitchboards from "./deploySwitchboard"; +import deploySwitchboards from "../scripts/deploySwitchboard"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { socketOwner, executionManagerVersion, mode, chains } from "../config"; import { diff --git a/scripts/deploy/scripts/allPathTest.ts b/scripts/deploy/helpers/send-msg/allPathTest.ts similarity index 94% rename from scripts/deploy/scripts/allPathTest.ts rename to scripts/deploy/helpers/send-msg/allPathTest.ts index e40ab07e..f84f5fed 100644 --- a/scripts/deploy/scripts/allPathTest.ts +++ b/scripts/deploy/helpers/send-msg/allPathTest.ts @@ -9,16 +9,14 @@ import { isTestnet, isMainnet, CORE_CONTRACTS, - ChainSlugToKey, - ChainId, -} from "../../../src"; -import { getAddresses, getRelayUrl, getRelayAPIKEY } from "../utils"; +} from "../../../../src"; +import { getAddresses, getRelayUrl, getRelayAPIKEY } from "../../utils"; import { BigNumber, Contract, ethers } from "ethers"; -import Counter from "../../../out/Counter.sol/Counter.json"; -import Socket from "../../../out/Socket.sol/Socket.json"; +import Counter from "../../../../out/Counter.sol/Counter.json"; +import Socket from "../../../../out/Socket.sol/Socket.json"; -import { chains, mode } from "../config"; -import { getProviderFromChainSlug } from "../../constants/networks"; +import { chains, mode } from "../../config"; +import { getProviderFromChainSlug } from "../../../constants/networks"; interface RequestObj { to: string; diff --git a/scripts/deploy/scripts/outbound-load-test.ts b/scripts/deploy/helpers/send-msg/outbound-load-test.ts similarity index 94% rename from scripts/deploy/scripts/outbound-load-test.ts rename to scripts/deploy/helpers/send-msg/outbound-load-test.ts index f8498718..d675020d 100644 --- a/scripts/deploy/scripts/outbound-load-test.ts +++ b/scripts/deploy/helpers/send-msg/outbound-load-test.ts @@ -7,12 +7,17 @@ import { ethers } from "ethers"; import { Contract } from "ethers"; require("dotenv").config(); import yargs from "yargs"; -import { getProviderFromChainSlug } from "../../constants"; -import SocketABI from "../../../out/Socket.sol/Socket.json"; +import { getProviderFromChainSlug } from "../../../constants"; +import SocketABI from "../../../../out/Socket.sol/Socket.json"; import path from "path"; -import { mode } from "../config"; -import { CORE_CONTRACTS, hardhatChainNameToSlug } from "../../../src"; +import { mode } from "../../config"; +import { + CORE_CONTRACTS, + ChainSlug, + HardhatChainName, + hardhatChainNameToSlug, +} from "../../../../src"; const deployedAddressPath = path.join( __dirname, @@ -102,7 +107,7 @@ export const main = async () => { }, }).argv; - const chain = argv.chain as keyof typeof hardhatChainNameToSlug; + const chain = argv.chain as HardhatChainName; const chainSlug = hardhatChainNameToSlug[chain]; const providerInstance = getProviderFromChainSlug(chainSlug); @@ -112,7 +117,7 @@ export const main = async () => { providerInstance ); - const remoteChain = argv.remoteChain as keyof typeof hardhatChainNameToSlug; + const remoteChain = argv.remoteChain as HardhatChainName; remoteChainSlug = hardhatChainNameToSlug[remoteChain]; const numOfRequests = argv.numOfRequests as number; diff --git a/scripts/deploy/scripts/outbound.ts b/scripts/deploy/helpers/send-msg/outbound.ts similarity index 96% rename from scripts/deploy/scripts/outbound.ts rename to scripts/deploy/helpers/send-msg/outbound.ts index 36d05ae9..9dcff8a2 100644 --- a/scripts/deploy/scripts/outbound.ts +++ b/scripts/deploy/helpers/send-msg/outbound.ts @@ -5,9 +5,9 @@ import fs from "fs"; import { ethers } from "hardhat"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { utils, constants } from "ethers"; -import { getInstance, getChainSlug, deployedAddressPath } from "../utils"; +import { getInstance, getChainSlug, deployedAddressPath } from "../../utils"; import { Contract } from "ethers"; -import { mode } from "../config"; +import { mode } from "../../config"; const remoteChainSlug = ""; diff --git a/scripts/deploy/scripts/switchboardData.ts b/scripts/deploy/helpers/switchboardData.ts similarity index 100% rename from scripts/deploy/scripts/switchboardData.ts rename to scripts/deploy/helpers/switchboardData.ts diff --git a/scripts/deploy/scripts/configureSocket.ts b/scripts/deploy/scripts/configureSocket.ts new file mode 100644 index 00000000..f67335e3 --- /dev/null +++ b/scripts/deploy/scripts/configureSocket.ts @@ -0,0 +1,249 @@ +import { Wallet, constants } from "ethers"; + +import { getProviderFromChainSlug, switchboards } from "../../constants"; +import { getInstance, getSwitchboardAddress } from "../utils"; +import { + CORE_CONTRACTS, + ChainSlug, + ChainSocketAddresses, + DeploymentAddresses, + IntegrationTypes, + NativeSwitchboard, + ChainSlugToKey, +} from "../../../src"; +import registerSwitchboardForSibling from "../scripts/registerSwitchboard"; +import { arrayify, defaultAbiCoder, keccak256, id } from "ethers/lib/utils"; +import { + capacitorType, + maxPacketLength, + executionManagerVersion, + overrides, + msgValueMaxThreshold, +} from "../config"; + +export const registerSwitchboards = async ( + chain: ChainSlug, + siblingSlugs: ChainSlug[], + switchboardContractName: string, + integrationType: IntegrationTypes, + addr: ChainSocketAddresses, + addresses: DeploymentAddresses, + socketSigner: Wallet +) => { + for (let sibling of siblingSlugs) { + const siblingSwitchboard = getSwitchboardAddress( + chain, + integrationType, + addresses?.[sibling] + ); + + if (!siblingSwitchboard || !addr[switchboardContractName]) continue; + + addr = await registerSwitchboardForSibling( + addr[switchboardContractName], + siblingSwitchboard, + sibling, + capacitorType, + maxPacketLength, + socketSigner, + integrationType, + addr + ); + } + + return addr; +}; + +export const setManagers = async ( + addr: ChainSocketAddresses, + socketSigner: Wallet +) => { + const socket = ( + await getInstance(CORE_CONTRACTS.Socket, addr.Socket) + ).connect(socketSigner); + + let tx; + const currentEM = await socket.executionManager__(); + if ( + currentEM.toLowerCase() !== addr[executionManagerVersion]?.toLowerCase() + ) { + tx = await socket.setExecutionManager(addr[executionManagerVersion], { + ...overrides[await socketSigner.getChainId()], + }); + console.log("updateExecutionManager", tx.hash); + await tx.wait(); + } + + const currentTM = await socket.transmitManager__(); + if (currentTM.toLowerCase() !== addr.TransmitManager?.toLowerCase()) { + tx = await socket.setTransmitManager(addr.TransmitManager, { + ...overrides[await socketSigner.getChainId()], + }); + console.log("updateTransmitManager", tx.hash); + await tx.wait(); + } +}; + +export const configureExecutionManager = async ( + contractName: string, + emAddress: string, + socketBatcherAddress: string, + chain: ChainSlug, + siblingSlugs: ChainSlug[], + socketSigner: Wallet +) => { + try { + console.log("configuring execution manager for ", chain, emAddress); + + let executionManagerContract, socketBatcherContract; + executionManagerContract = ( + await getInstance(contractName, emAddress!) + ).connect(socketSigner); + + let nextNonce = ( + await executionManagerContract.nextNonce(socketSigner.address) + ).toNumber(); + + let requests: any = []; + await Promise.all( + siblingSlugs.map(async (siblingSlug) => { + let currentValue = await executionManagerContract.msgValueMaxThreshold( + siblingSlug + ); + + if ( + currentValue.toString() == + msgValueMaxThreshold(siblingSlug)?.toString() + ) { + return; + } + + const digest = keccak256( + defaultAbiCoder.encode( + ["bytes32", "address", "uint32", "uint32", "uint256", "uint256"], + [ + id("MSG_VALUE_MAX_THRESHOLD_UPDATE"), + emAddress!, + chain, + siblingSlug, + nextNonce, + msgValueMaxThreshold(siblingSlug), + ] + ) + ); + + const signature = await socketSigner.signMessage(arrayify(digest)); + + let request = { + signature, + dstChainSlug: siblingSlug, + nonce: nextNonce++, + fees: msgValueMaxThreshold(siblingSlug), + functionSelector: "0xa1885700", // setMsgValueMaxThreshold + }; + requests.push(request); + }) + ); + + if (requests.length === 0) return; + socketBatcherContract = ( + await getInstance("SocketBatcher", socketBatcherAddress) + ).connect(socketSigner); + + let tx = await socketBatcherContract.setExecutionFeesBatch( + emAddress!, + requests, + { ...overrides[chain] } + ); + console.log(chain, tx.hash); + await tx.wait(); + } catch (error) { + console.log("error while configuring execution manager: ", error); + } +}; + +export const setupPolygonNativeSwitchboard = async (addresses) => { + try { + let srcChains = Object.keys(addresses) + .filter((chain) => ["5", "1", "80001", "137"].includes(chain)) + .map((c) => parseInt(c) as ChainSlug); + + await Promise.all( + srcChains.map(async (srcChain: ChainSlug) => { + console.log(`Configuring for ${srcChain}`); + + const providerInstance = getProviderFromChainSlug( + srcChain as any as ChainSlug + ); + const socketSigner: Wallet = new Wallet( + process.env.SOCKET_SIGNER_KEY as string, + providerInstance + ); + + for (let dstChain in addresses[srcChain]?.["integrations"]) { + const dstConfig = addresses[srcChain]["integrations"][dstChain]; + if (!dstConfig?.[IntegrationTypes.native]) continue; + + const srcSwitchboardType = + switchboards[ChainSlugToKey[srcChain]]?.[ + ChainSlugToKey[parseInt(dstChain) as ChainSlug] + ]?.["switchboard"]; + + const dstSwitchboardAddress = getSwitchboardAddress( + srcChain, + IntegrationTypes.native, + addresses?.[dstChain] + ); + if (!dstSwitchboardAddress) continue; + + const srcSwitchboardAddress = + dstConfig?.[IntegrationTypes.native]["switchboard"]; + + if (srcSwitchboardType === NativeSwitchboard.POLYGON_L1) { + const sbContract = ( + await getInstance("PolygonL1Switchboard", srcSwitchboardAddress) + ).connect(socketSigner); + + const fxChild = await sbContract.fxChildTunnel(); + if (fxChild !== constants.AddressZero) continue; + console.log( + `Setting ${dstSwitchboardAddress} fx child tunnel in ${srcSwitchboardAddress} on networks ${srcChain}-${dstChain}` + ); + + const tx = await sbContract + .connect(socketSigner) + .setFxChildTunnel(dstSwitchboardAddress, { + ...overrides[await socketSigner.getChainId()], + }); + console.log(srcChain, tx.hash); + await tx.wait(); + } else if (srcSwitchboardType === NativeSwitchboard.POLYGON_L2) { + const sbContract = ( + await getInstance("PolygonL2Switchboard", srcSwitchboardAddress) + ).connect(socketSigner); + + const fxRoot = await sbContract.fxRootTunnel(); + if (fxRoot !== constants.AddressZero) continue; + console.log( + `Setting ${dstSwitchboardAddress} fx root tunnel in ${srcSwitchboardAddress} on networks ${srcChain}-${dstChain}` + ); + + const tx = await sbContract + .connect(socketSigner) + .setFxRootTunnel(dstSwitchboardAddress, { + ...overrides[await socketSigner.getChainId()], + }); + console.log(srcChain, tx.hash); + await tx.wait(); + } else continue; + } + + console.log( + `Configuring remote switchboards for ${srcChain} - COMPLETED` + ); + }) + ); + } catch (error) { + console.error(error); + } +}; diff --git a/scripts/deploy/scripts/deploySocket.ts b/scripts/deploy/scripts/deploySocket.ts index 8ca11003..e922951b 100644 --- a/scripts/deploy/scripts/deploySocket.ts +++ b/scripts/deploy/scripts/deploySocket.ts @@ -5,7 +5,6 @@ import { CORE_CONTRACTS, ChainSocketAddresses, DeploymentMode, - ChainSlugToKey, version, } from "../../../src"; import deploySwitchboards from "./deploySwitchboard"; diff --git a/scripts/deploy/index.ts b/scripts/deploy/scripts/deploySocketFor.ts similarity index 74% rename from scripts/deploy/index.ts rename to scripts/deploy/scripts/deploySocketFor.ts index e5968518..1dfb596d 100644 --- a/scripts/deploy/index.ts +++ b/scripts/deploy/scripts/deploySocketFor.ts @@ -1,20 +1,19 @@ import { ethers } from "hardhat"; import { Wallet } from "ethers"; -import { ReturnObj, deploySocket } from "./scripts/deploySocket"; -import { getProviderFromChainSlug } from "../constants"; +import { ReturnObj, deploySocket } from "../scripts/deploySocket"; +import { getProviderFromChainSlug } from "../../constants"; import { ChainSlug, ChainSocketAddresses, DeploymentAddresses, getAllAddresses, - ChainSlugToKey, -} from "../../src"; -import { chains, mode } from "./config"; - -/** - * Deploys network-independent socket contracts - */ -export const main = async () => { +} from "../../../src"; +import { mode } from "../config"; + +export const deployForChains = async ( + chains: ChainSlug[] +): Promise => { + let deployedAddresses: ChainSocketAddresses[] = []; try { let addresses: DeploymentAddresses; try { @@ -47,17 +46,14 @@ export const main = async () => { allDeployed = results.allDeployed; chainAddresses = results.deployedAddresses; + + deployedAddresses[chain] = chainAddresses; } }) ); } catch (error) { console.log("Error in deploying setup contracts", error); } -}; -main() - .then(() => process.exit(0)) - .catch((error: Error) => { - console.error(error); - process.exit(1); - }); + return deployedAddresses; +}; diff --git a/scripts/deploy/checkRoles.ts b/scripts/deploy/scripts/roles.ts similarity index 72% rename from scripts/deploy/checkRoles.ts rename to scripts/deploy/scripts/roles.ts index eb9ab624..fcbd8e31 100644 --- a/scripts/deploy/checkRoles.ts +++ b/scripts/deploy/scripts/roles.ts @@ -14,24 +14,13 @@ import { isTestnet, isMainnet, getAddresses, -} from "../../src"; -import { getRoleHash, getChainRoleHash } from "./utils"; +} from "../../../src"; +import { getRoleHash, getChainRoleHash } from "../utils"; import { Contract, Wallet, ethers } from "ethers"; -import { getABI } from "./scripts/getABIs"; -import { getProviderFromChainSlug } from "../constants"; -import { - executorAddresses, - filterChains, - filterSiblingChains, - mode, - newRoleStatus, - sendTransaction, - socketOwner, - transmitterAddresses, - watcherAddresses, - executionManagerVersion, -} from "./config"; -import { overrides } from "./config"; +import { getABI } from "../utils/getABIs"; +import { getProviderFromChainSlug } from "../../constants"; +import { filterChains, mode } from "../config"; +import { overrides } from "../config"; let roleStatus: any = {}; @@ -289,9 +278,9 @@ export const checkNativeSwitchboardRoles = async ({ ); }; -let summary: { params: any; roleStatus: any }[] = []; - -export const checkAndUpdateRoles = async (params: checkAndUpdateRolesObj) => { +export const checkAndUpdateRoles = async ( + params: checkAndUpdateRolesObj +): Promise<{ params: checkAndUpdateRolesObj; roleStatus: any }> => { try { let { sendTransaction, @@ -320,7 +309,7 @@ export const checkAndUpdateRoles = async (params: checkAndUpdateRolesObj) => { // console.log( // "============= checking for network: ", - // ChainSlugToKey[chainSlug], + // ChainSlugToKey(chainSlug), // "=================" // ); let addresses: ChainSocketAddresses | undefined; @@ -510,217 +499,9 @@ export const checkAndUpdateRoles = async (params: checkAndUpdateRolesObj) => { if (sendTransaction) await executeTransactions(activeChainSlugs, newRoleStatus); - summary.push({ params, roleStatus }); + return { params, roleStatus }; } catch (error) { console.log("Error while checking roles", error); throw error; } }; - -const main = async () => { - let ownerAddress = socketOwner; - let executorAddress = executorAddresses[mode]; - let transmitterAddress = transmitterAddresses[mode]; - let watcherAddress = watcherAddresses[mode]; - - // Grant rescue,withdraw and governance role for Execution Manager to owner - await checkAndUpdateRoles({ - userSpecificRoles: [ - { - userAddress: ownerAddress, - filterRoles: [ - ROLES.RESCUE_ROLE, - ROLES.GOVERNANCE_ROLE, - ROLES.WITHDRAW_ROLE, - ROLES.FEES_UPDATER_ROLE, - ], - }, - { - userAddress: transmitterAddress, - filterRoles: [ROLES.FEES_UPDATER_ROLE], - }, - { - userAddress: executorAddress, - filterRoles: [ROLES.EXECUTOR_ROLE], - }, - ], - contractName: executionManagerVersion, - filterChains, - filterSiblingChains, - sendTransaction, - newRoleStatus, - }); - - // Grant owner roles for TransmitManager - await checkAndUpdateRoles({ - userSpecificRoles: [ - { - userAddress: ownerAddress, - filterRoles: [ - ROLES.RESCUE_ROLE, - ROLES.GOVERNANCE_ROLE, - ROLES.WITHDRAW_ROLE, - ROLES.FEES_UPDATER_ROLE, - ], - }, - { - userAddress: transmitterAddress, - filterRoles: [ROLES.TRANSMITTER_ROLE, ROLES.FEES_UPDATER_ROLE], - }, - ], - contractName: CORE_CONTRACTS.TransmitManager, - filterChains, - filterSiblingChains, - sendTransaction, - newRoleStatus, - }); - - // Grant owner roles in socket - await checkAndUpdateRoles({ - userSpecificRoles: [ - { - userAddress: ownerAddress, - filterRoles: [ROLES.RESCUE_ROLE, ROLES.GOVERNANCE_ROLE], - }, - ], - contractName: CORE_CONTRACTS.Socket, - filterChains, - filterSiblingChains, - sendTransaction, - newRoleStatus, - }); - - // Setup Fast Switchboard roles except WATCHER - await checkAndUpdateRoles({ - userSpecificRoles: [ - { - userAddress: ownerAddress, - filterRoles: [ - ROLES.RESCUE_ROLE, - ROLES.GOVERNANCE_ROLE, - ROLES.TRIP_ROLE, - ROLES.UN_TRIP_ROLE, - ROLES.WITHDRAW_ROLE, - ROLES.FEES_UPDATER_ROLE, - ], - }, - { - userAddress: transmitterAddress, - filterRoles: [ROLES.FEES_UPDATER_ROLE], - }, - { - userAddress: watcherAddress, - filterRoles: [ROLES.WATCHER_ROLE], - }, - ], - - contractName: CORE_CONTRACTS.FastSwitchboard, - filterChains, - filterSiblingChains, - sendTransaction, - newRoleStatus, - }); - - // Setup Fast Switchboard2 roles except WATCHER - await checkAndUpdateRoles({ - userSpecificRoles: [ - { - userAddress: ownerAddress, - filterRoles: [ - ROLES.RESCUE_ROLE, - ROLES.GOVERNANCE_ROLE, - ROLES.TRIP_ROLE, - ROLES.UN_TRIP_ROLE, - ROLES.WITHDRAW_ROLE, - ROLES.FEES_UPDATER_ROLE, - ], - }, - { - userAddress: transmitterAddress, - filterRoles: [ROLES.FEES_UPDATER_ROLE], - }, - { - userAddress: watcherAddress, - filterRoles: [ROLES.WATCHER_ROLE], - }, - ], - - contractName: CORE_CONTRACTS.FastSwitchboard2, - filterChains, - filterSiblingChains, - sendTransaction, - newRoleStatus, - }); - - // Grant watcher role to watcher for OptimisticSwitchboard - await checkAndUpdateRoles({ - userSpecificRoles: [ - { - userAddress: ownerAddress, - filterRoles: [ - ROLES.TRIP_ROLE, - ROLES.UN_TRIP_ROLE, - ROLES.RESCUE_ROLE, - ROLES.GOVERNANCE_ROLE, - ROLES.FEES_UPDATER_ROLE, - ], - }, - { - userAddress: transmitterAddress, - filterRoles: [ROLES.FEES_UPDATER_ROLE], // all roles - }, - { - userAddress: watcherAddress, - filterRoles: [ROLES.WATCHER_ROLE], - }, - ], - contractName: CORE_CONTRACTS.OptimisticSwitchboard, - filterChains, - filterSiblingChains, - sendTransaction, - newRoleStatus, - }); - - // Grant owner roles in NativeSwitchboard - await checkAndUpdateRoles({ - userSpecificRoles: [ - { - userAddress: ownerAddress, - filterRoles: [ - ROLES.TRIP_ROLE, - ROLES.UN_TRIP_ROLE, - ROLES.GOVERNANCE_ROLE, - ROLES.WITHDRAW_ROLE, - ROLES.RESCUE_ROLE, - ROLES.FEES_UPDATER_ROLE, - ], // all roles - }, - { - userAddress: transmitterAddress, - filterRoles: [ROLES.FEES_UPDATER_ROLE], // all roles - }, - ], - contractName: CORE_CONTRACTS.NativeSwitchboard, - filterChains, - filterSiblingChains, - sendTransaction, - newRoleStatus, - }); - - console.log( - "=========================== SUMMARY =================================" - ); - - summary.forEach((result) => { - console.log("============================================="); - console.log("params:", result.params); - console.log("role status: ", JSON.stringify(result.roleStatus)); - }); -}; - -main() - .then(() => process.exit(0)) - .catch((error: Error) => { - console.error(error); - process.exit(1); - }); diff --git a/scripts/deploy/single-click-deploy/addChain.ts b/scripts/deploy/single-click-deploy/addChain.ts new file mode 100644 index 00000000..d6303206 --- /dev/null +++ b/scripts/deploy/single-click-deploy/addChain.ts @@ -0,0 +1,250 @@ +import { Wallet } from "ethers"; +import fs from "fs"; + +import { + CORE_CONTRACTS, + ChainSlug, + DeploymentAddresses, + IntegrationTypes, + ROLES, +} from "../../../src"; +import { checkAndUpdateRoles } from "../scripts/roles"; +import { executionManagerVersion, mode } from "../config"; +import { + configureExecutionManager, + registerSwitchboards, + setManagers, +} from "../scripts/configureSocket"; +import { deployForChains } from "../scripts/deploySocketFor"; +import { getProviderFromChainSlug } from "../../constants"; +import { deployedAddressPath, storeAllAddresses } from "../utils"; +import { chainConfig } from "../../../chainConfig"; + +const chain = ChainSlug.SX_NETWORK_TESTNET; +const siblings = [ + ChainSlug.POLYGON_MUMBAI, + ChainSlug.GOERLI, + ChainSlug.ARBITRUM_GOERLI, +]; + +export const main = async () => { + const addresses = await deployForChains([chain]); + if (!addresses[chain]) throw new Error("Address not deployed!"); + + // grant all roles for new chain + await grantRoles(); + + const providerInstance = getProviderFromChainSlug(chain as any as ChainSlug); + const socketSigner: Wallet = new Wallet( + process.env.SOCKET_SIGNER_KEY as string, + providerInstance + ); + + // general configs for socket + await configureExecutionManager( + executionManagerVersion, + addresses[chain].ExecutionManager!, + addresses[chain].SocketBatcher, + chain, + siblings, + socketSigner + ); + + await setManagers(addresses[chain], socketSigner); + + let allAddresses: DeploymentAddresses = JSON.parse( + fs.readFileSync(deployedAddressPath(mode), "utf-8") + ); + + let addr = await registerSwitchboards( + chain, + siblings, + CORE_CONTRACTS.FastSwitchboard2, + IntegrationTypes.fast2, + addresses[chain], + allAddresses, + socketSigner + ); + + allAddresses[chain] = addr; + await storeAllAddresses(allAddresses, mode); +}; + +const grantRoles = async () => { + if (!chainConfig || !chainConfig[chain]) + throw new Error("Chain config not found!"); + const config = chainConfig[chain]; + + if ( + !config.executorAddress || + !config.transmitterAddress || + !config.watcherAddress || + !config.feeUpdaterAddress || + !config.ownerAddress + ) + throw new Error("Add all required addresses!"); + + // Grant rescue,withdraw and governance role for Execution Manager to owner + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.ownerAddress, + filterRoles: [ + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + { + userAddress: config.executorAddress, + filterRoles: [ROLES.EXECUTOR_ROLE], + }, + ], + contractName: executionManagerVersion, + filterChains: [chain], + filterSiblingChains: siblings, + sendTransaction: true, + newRoleStatus: true, + }); + + // Grant owner roles for TransmitManager + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.ownerAddress, + filterRoles: [ + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: config.transmitterAddress, + filterRoles: [ROLES.TRANSMITTER_ROLE], + }, + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + ], + contractName: CORE_CONTRACTS.TransmitManager, + filterChains: [chain], + filterSiblingChains: siblings, + sendTransaction: true, + newRoleStatus: true, + }); + + // Grant owner roles in socket + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.ownerAddress, + filterRoles: [ROLES.RESCUE_ROLE, ROLES.GOVERNANCE_ROLE], + }, + ], + contractName: CORE_CONTRACTS.Socket, + filterChains: [chain], + filterSiblingChains: siblings, + sendTransaction: true, + newRoleStatus: true, + }); + + // Setup Fast Switchboard roles + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.ownerAddress, + filterRoles: [ + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.TRIP_ROLE, + ROLES.UN_TRIP_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + { + userAddress: config.watcherAddress, + filterRoles: [ROLES.WATCHER_ROLE], + }, + ], + + contractName: CORE_CONTRACTS.FastSwitchboard, + filterChains: [chain], + filterSiblingChains: siblings, + sendTransaction: true, + newRoleStatus: true, + }); + + // Setup Fast Switchboard2 roles + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.ownerAddress, + filterRoles: [ + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.TRIP_ROLE, + ROLES.UN_TRIP_ROLE, + ROLES.WITHDRAW_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + { + userAddress: config.watcherAddress, + filterRoles: [ROLES.WATCHER_ROLE], + }, + ], + + contractName: CORE_CONTRACTS.FastSwitchboard2, + filterChains: [chain], + filterSiblingChains: siblings, + sendTransaction: true, + newRoleStatus: true, + }); + + // Grant watcher role to watcher for OptimisticSwitchboard + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.ownerAddress, + filterRoles: [ + ROLES.TRIP_ROLE, + ROLES.UN_TRIP_ROLE, + ROLES.RESCUE_ROLE, + ROLES.GOVERNANCE_ROLE, + ROLES.FEES_UPDATER_ROLE, + ], + }, + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], // all roles + }, + { + userAddress: config.watcherAddress, + filterRoles: [ROLES.WATCHER_ROLE], + }, + ], + contractName: CORE_CONTRACTS.OptimisticSwitchboard, + filterChains: [chain], + filterSiblingChains: siblings, + sendTransaction: true, + newRoleStatus: true, + }); +}; + +main(); diff --git a/scripts/deploy/single-click-deploy/configureChain.ts b/scripts/deploy/single-click-deploy/configureChain.ts new file mode 100644 index 00000000..de3029e8 --- /dev/null +++ b/scripts/deploy/single-click-deploy/configureChain.ts @@ -0,0 +1,168 @@ +import { Wallet } from "ethers"; +import fs from "fs"; + +import { + CORE_CONTRACTS, + ChainSlug, + DeploymentAddresses, + IntegrationTypes, + ROLES, +} from "../../../src"; +import { checkAndUpdateRoles } from "../scripts/roles"; +import { + executionManagerVersion, + mode, + newRoleStatus, + sendTransaction, +} from "../config"; +import { + configureExecutionManager, + registerSwitchboards, +} from "../scripts/configureSocket"; +import { getProviderFromChainSlug } from "../../constants"; +import { deployedAddressPath, storeAllAddresses } from "../utils"; +import { chainConfig } from "../../../chainConfig"; + +const chain = ChainSlug.SX_NETWORK_TESTNET; +const filterChains = [ + ChainSlug.POLYGON_MUMBAI, + ChainSlug.GOERLI, + ChainSlug.ARBITRUM_GOERLI, +]; + +export const main = async () => { + const addresses: DeploymentAddresses = JSON.parse( + fs.readFileSync(deployedAddressPath(mode), "utf-8") + ); + + // grant all roles for new chain + await grantRoles(); + + let addr; + for (let c = 0; c < filterChains.length; c++) { + const sibling = filterChains[c] as any as ChainSlug; + const providerInstance = getProviderFromChainSlug(sibling); + const socketSigner: Wallet = new Wallet( + process.env.SOCKET_SIGNER_KEY as string, + providerInstance + ); + + if (!addresses || !addresses[sibling]) + throw new Error(`Sibling addresses not found! ${sibling}`); + + // general configs for socket + await configureExecutionManager( + executionManagerVersion, + addresses[sibling]?.ExecutionManager!, + addresses[sibling]?.SocketBatcher!, + sibling, + [chain], + socketSigner + ); + + addr = await registerSwitchboards( + sibling, + [chain], + CORE_CONTRACTS.FastSwitchboard2, + IntegrationTypes.fast2, + addresses[sibling]!, + addresses, + socketSigner + ); + } + await storeAllAddresses(addresses, mode); +}; + +const grantRoles = async () => { + if (!chainConfig || !chainConfig[chain]) + throw new Error("Chain config not found!"); + const config = chainConfig[chain]; + + if ( + !config.executorAddress || + !config.transmitterAddress || + !config.watcherAddress || + !config.feeUpdaterAddress || + !config.ownerAddress + ) + throw new Error("Add all required addresses!"); + + // Grant rescue,withdraw and governance role for Execution Manager to owner + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + { + userAddress: config.executorAddress, + filterRoles: [ROLES.EXECUTOR_ROLE], + }, + ], + contractName: executionManagerVersion, + filterChains, + filterSiblingChains: [chain], + sendTransaction, + newRoleStatus, + }); + + // Grant owner roles for TransmitManager + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.TRANSMITTER_ROLE], + }, + { + userAddress: config.transmitterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + ], + contractName: CORE_CONTRACTS.TransmitManager, + filterChains, + filterSiblingChains: [chain], + sendTransaction, + newRoleStatus, + }); + + // Setup Fast Switchboard2 roles + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], + }, + { + userAddress: config.watcherAddress, + filterRoles: [ROLES.WATCHER_ROLE], + }, + ], + + contractName: CORE_CONTRACTS.FastSwitchboard2, + filterChains, + filterSiblingChains: [chain], + sendTransaction, + newRoleStatus, + }); + + // Grant watcher role to watcher for OptimisticSwitchboard + await checkAndUpdateRoles({ + userSpecificRoles: [ + { + userAddress: config.feeUpdaterAddress, + filterRoles: [ROLES.FEES_UPDATER_ROLE], // all roles + }, + { + userAddress: config.watcherAddress, + filterRoles: [ROLES.WATCHER_ROLE], + }, + ], + contractName: CORE_CONTRACTS.OptimisticSwitchboard, + filterChains, + filterSiblingChains: [chain], + sendTransaction, + newRoleStatus, + }); +}; + +main(); diff --git a/scripts/deploy/switchboards/fastSwitchboard.ts b/scripts/deploy/switchboards/fastSwitchboard.ts index 972e6e0e..3419e260 100644 --- a/scripts/deploy/switchboards/fastSwitchboard.ts +++ b/scripts/deploy/switchboards/fastSwitchboard.ts @@ -13,7 +13,7 @@ export const fastSwitchboard = ( signerAddress, socketAddress, chainSlug, - timeout[chainSlug], + timeout(chainSlug), sigVerifierAddress, ], path: "contracts/switchboard/default-switchboards/FastSwitchboard.sol", diff --git a/scripts/deploy/switchboards/optimisticSwitchboard.ts b/scripts/deploy/switchboards/optimisticSwitchboard.ts index 1d8af701..f33af565 100644 --- a/scripts/deploy/switchboards/optimisticSwitchboard.ts +++ b/scripts/deploy/switchboards/optimisticSwitchboard.ts @@ -13,7 +13,7 @@ export const optimisticSwitchboard = ( signerAddress, socketAddress, chainSlug, - timeout[chainSlug], + timeout(chainSlug), sigVerifierAddress, ], path: "contracts/switchboard/default-switchboards/OptimisticSwitchboard.sol", diff --git a/scripts/deploy/switchboards/polygonL2Switchboard.ts b/scripts/deploy/switchboards/polygonL2Switchboard.ts index d1b22e0a..23a20c79 100644 --- a/scripts/deploy/switchboards/polygonL2Switchboard.ts +++ b/scripts/deploy/switchboards/polygonL2Switchboard.ts @@ -1,4 +1,4 @@ -import { ChainSlug } from "../../../src/types"; +import { ChainSlug } from "../../../src"; import { bridgeConsts } from "../../constants"; export const polygonL2Switchboard = ( diff --git a/scripts/deploy/scripts/getABIs.ts b/scripts/deploy/utils/getABIs.ts similarity index 100% rename from scripts/deploy/scripts/getABIs.ts rename to scripts/deploy/utils/getABIs.ts diff --git a/scripts/deploy/utils/utils.ts b/scripts/deploy/utils/utils.ts index be181f9e..c3b1ca2b 100644 --- a/scripts/deploy/utils/utils.ts +++ b/scripts/deploy/utils/utils.ts @@ -88,7 +88,6 @@ export async function deployContractWithArgs( // gasLimit is set to undefined to not use the value set in overrides const contract: Contract = await Contract.connect(signer).deploy(...args, { ...overrides[await signer.getChainId()], - gasLimit: undefined, }); await contract.deployed(); return contract; diff --git a/scripts/limits-updater/initLimits.ts b/scripts/limits-updater/initLimits.ts index 633d9678..34e15c9a 100644 --- a/scripts/limits-updater/initLimits.ts +++ b/scripts/limits-updater/initLimits.ts @@ -44,7 +44,6 @@ export const setLimitsForAChainSlug = async (chainSlugCode: ChainSlug) => { const chainAddresses: ChainAddresses = values[i]; const chainSlugCode = "optimism-goerli"; - // ChainSlugToKey[dstChainId] } console.log(`-------------------------------------\n\n`); @@ -58,9 +57,6 @@ export const setLimitsForAChainSlug = async (chainSlugCode: ChainSlug) => { // npx ts-node scripts/limits-updater/initLimits.ts export const setLimits = async () => { try { - // for (let chainSlugKey of chainSlugKeys) { - // setLimitsForAChainSlug(chainSlugKey); - // } setLimitsForAChainSlug(ChainSlug.OPTIMISM_GOERLI); } catch (error) { console.log("Error while sending transaction", error); diff --git a/src/addresses.ts b/src/addresses.ts index 9c25ec56..adca7746 100644 --- a/src/addresses.ts +++ b/src/addresses.ts @@ -5,7 +5,7 @@ import { DeploymentMode, IntegrationTypes, DeploymentAddresses, -} from "./types"; +} from "./"; import dev_addresses from "../deployments/dev_addresses.json"; import prod_addresses from "../deployments/prod_addresses.json"; diff --git a/src/chain-types.ts b/src/chain-types.ts new file mode 100644 index 00000000..3e3d23c6 --- /dev/null +++ b/src/chain-types.ts @@ -0,0 +1,139 @@ +/*********************************************** + * * + * Update below values when new chain is added * + * * + ***********************************************/ + +export enum HardhatChainName { + ARBITRUM = "arbitrum", + ARBITRUM_GOERLI = "arbitrum-goerli", + OPTIMISM = "optimism", + OPTIMISM_GOERLI = "optimism-goerli", + AVALANCHE = "avalanche", + AVALANCHE_TESTNET = "avalanche-testnet", + BSC = "bsc", + BSC_TESTNET = "bsc-testnet", + MAINNET = "mainnet", + GOERLI = "goerli", + SEPOLIA = "sepolia", + POLYGON_MAINNET = "polygon-mainnet", + POLYGON_MUMBAI = "polygon-mumbai", + AEVO_TESTNET = "aevo-testnet", + AEVO = "aevo", + LYRA_TESTNET = "lyra-testnet", + LYRA = "lyra", + XAI_TESTNET = "xai_testnet", + SX_NETWORK_TESTNET = "sxn_testnet", + HARDHAT = "hardhat", +} + +export enum ChainId { + ARBITRUM = 42161, + ARBITRUM_GOERLI = 421613, + OPTIMISM = 10, + OPTIMISM_GOERLI = 420, + BSC = 56, + BSC_TESTNET = 97, + MAINNET = 1, + GOERLI = 5, + SEPOLIA = 11155111, + POLYGON_MAINNET = 137, + POLYGON_MUMBAI = 80001, + AEVO_TESTNET = 11155112, + AEVO = 2999, + HARDHAT = 31337, + AVALANCHE = 43114, + LYRA_TESTNET = 901, + LYRA = 0, // update this + XAI_TESTNET = 47279324479, + SX_NETWORK_TESTNET = 647, +} + +export enum ChainSlug { + ARBITRUM = ChainId.ARBITRUM, + ARBITRUM_GOERLI = ChainId.ARBITRUM_GOERLI, + OPTIMISM = ChainId.OPTIMISM, + OPTIMISM_GOERLI = ChainId.OPTIMISM_GOERLI, + BSC = ChainId.BSC, + BSC_TESTNET = ChainId.BSC_TESTNET, + MAINNET = ChainId.MAINNET, + GOERLI = ChainId.GOERLI, + SEPOLIA = ChainId.SEPOLIA, + POLYGON_MAINNET = ChainId.POLYGON_MAINNET, + POLYGON_MUMBAI = ChainId.POLYGON_MUMBAI, + AEVO_TESTNET = ChainId.AEVO_TESTNET, + AEVO = ChainId.AEVO, + HARDHAT = ChainId.HARDHAT, + AVALANCHE = ChainId.AVALANCHE, + LYRA_TESTNET = ChainId.LYRA_TESTNET, + LYRA = ChainId.LYRA, + XAI_TESTNET = 1399904803, + SX_NETWORK_TESTNET = ChainId.SX_NETWORK_TESTNET, +} + +export const hardhatChainNameToSlug = { + [HardhatChainName.ARBITRUM]: ChainSlug.ARBITRUM, + [HardhatChainName.ARBITRUM_GOERLI]: ChainSlug.ARBITRUM_GOERLI, + [HardhatChainName.OPTIMISM]: ChainSlug.OPTIMISM, + [HardhatChainName.OPTIMISM_GOERLI]: ChainSlug.OPTIMISM_GOERLI, + [HardhatChainName.BSC]: ChainSlug.BSC, + [HardhatChainName.BSC_TESTNET]: ChainSlug.BSC_TESTNET, + [HardhatChainName.MAINNET]: ChainSlug.MAINNET, + [HardhatChainName.GOERLI]: ChainSlug.GOERLI, + [HardhatChainName.SEPOLIA]: ChainSlug.SEPOLIA, + [HardhatChainName.POLYGON_MAINNET]: ChainSlug.POLYGON_MAINNET, + [HardhatChainName.POLYGON_MUMBAI]: ChainSlug.POLYGON_MUMBAI, + [HardhatChainName.AEVO_TESTNET]: ChainSlug.AEVO_TESTNET, + [HardhatChainName.AEVO]: ChainSlug.AEVO, + [HardhatChainName.HARDHAT]: ChainSlug.HARDHAT, + [HardhatChainName.AVALANCHE]: ChainSlug.AVALANCHE, + [HardhatChainName.LYRA_TESTNET]: ChainSlug.LYRA_TESTNET, + [HardhatChainName.LYRA]: ChainSlug.LYRA, + [HardhatChainName.XAI_TESTNET]: ChainSlug.XAI_TESTNET, + [HardhatChainName.SX_NETWORK_TESTNET]: ChainSlug.SX_NETWORK_TESTNET, +}; + +export const ChainSlugToKey = { + [ChainSlug.ARBITRUM]: HardhatChainName.ARBITRUM, + [ChainSlug.ARBITRUM_GOERLI]: HardhatChainName.ARBITRUM_GOERLI, + [ChainSlug.OPTIMISM]: HardhatChainName.OPTIMISM, + [ChainSlug.OPTIMISM_GOERLI]: HardhatChainName.OPTIMISM_GOERLI, + [ChainSlug.BSC]: HardhatChainName.BSC, + [ChainSlug.BSC_TESTNET]: HardhatChainName.BSC_TESTNET, + [ChainSlug.MAINNET]: HardhatChainName.MAINNET, + [ChainSlug.GOERLI]: HardhatChainName.GOERLI, + [ChainSlug.SEPOLIA]: HardhatChainName.SEPOLIA, + [ChainSlug.POLYGON_MAINNET]: HardhatChainName.POLYGON_MAINNET, + [ChainSlug.POLYGON_MUMBAI]: HardhatChainName.POLYGON_MUMBAI, + [ChainSlug.AEVO_TESTNET]: HardhatChainName.AEVO_TESTNET, + [ChainSlug.AEVO]: HardhatChainName.AEVO, + [ChainSlug.HARDHAT]: HardhatChainName.HARDHAT, + [ChainSlug.AVALANCHE]: HardhatChainName.AVALANCHE, + [ChainSlug.LYRA_TESTNET]: HardhatChainName.LYRA_TESTNET, + [ChainSlug.LYRA]: HardhatChainName.LYRA, + [ChainSlug.XAI_TESTNET]: HardhatChainName.XAI_TESTNET, + [ChainSlug.SX_NETWORK_TESTNET]: HardhatChainName.SX_NETWORK_TESTNET, +}; + +export const TestnetIds: ChainSlug[] = [ + ChainSlug.GOERLI, + ChainSlug.SEPOLIA, + ChainSlug.POLYGON_MUMBAI, + ChainSlug.ARBITRUM_GOERLI, + ChainSlug.OPTIMISM_GOERLI, + ChainSlug.BSC_TESTNET, + ChainSlug.AEVO_TESTNET, + ChainSlug.LYRA_TESTNET, + ChainSlug.XAI_TESTNET, + ChainSlug.SX_NETWORK_TESTNET, +]; + +export const MainnetIds: ChainSlug[] = [ + ChainSlug.MAINNET, + ChainSlug.POLYGON_MAINNET, + ChainSlug.ARBITRUM, + ChainSlug.OPTIMISM, + ChainSlug.BSC, + ChainSlug.AEVO, + ChainSlug.LYRA, +]; diff --git a/src/index.ts b/src/index.ts index 58968c3f..64e06ccd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ -import { DeploymentMode } from "./types"; +import { DeploymentMode } from "./socket-types"; -export * from "./types"; +export * from "./socket-types"; +export * from "./chain-types"; export * from "./addresses"; export const version = { diff --git a/src/types.ts b/src/socket-types.ts similarity index 53% rename from src/types.ts rename to src/socket-types.ts index 0d1cbc7d..a37d950f 100644 --- a/src/types.ts +++ b/src/socket-types.ts @@ -1,135 +1,4 @@ -/*********************************************** - * * - * Update below values when new chain is added * - * * - ***********************************************/ - -export enum HardhatChainName { - ARBITRUM = "arbitrum", - ARBITRUM_GOERLI = "arbitrum-goerli", - OPTIMISM = "optimism", - OPTIMISM_GOERLI = "optimism-goerli", - AVALANCHE = "avalanche", - AVALANCHE_TESTNET = "avalanche-testnet", - BSC = "bsc", - BSC_TESTNET = "bsc-testnet", - MAINNET = "mainnet", - GOERLI = "goerli", - SEPOLIA = "sepolia", - POLYGON_MAINNET = "polygon-mainnet", - POLYGON_MUMBAI = "polygon-mumbai", - AEVO_TESTNET = "aevo-testnet", - AEVO = "aevo", - LYRA_TESTNET = "lyra-testnet", - LYRA = "lyra", - XAI_TESTNET = "xai_testnet", - HARDHAT = "hardhat", -} - -export enum ChainId { - ARBITRUM = 42161, - ARBITRUM_GOERLI = 421613, - OPTIMISM = 10, - OPTIMISM_GOERLI = 420, - BSC = 56, - BSC_TESTNET = 97, - MAINNET = 1, - GOERLI = 5, - SEPOLIA = 11155111, - POLYGON_MAINNET = 137, - POLYGON_MUMBAI = 80001, - AEVO_TESTNET = 11155112, - AEVO = 2999, - HARDHAT = 31337, - AVALANCHE = 43114, - LYRA_TESTNET = 901, - LYRA = 0, // update this - XAI_TESTNET = 47279324479, -} - -export enum ChainSlug { - ARBITRUM = ChainId.ARBITRUM, - ARBITRUM_GOERLI = ChainId.ARBITRUM_GOERLI, - OPTIMISM = ChainId.OPTIMISM, - OPTIMISM_GOERLI = ChainId.OPTIMISM_GOERLI, - BSC = ChainId.BSC, - BSC_TESTNET = ChainId.BSC_TESTNET, - MAINNET = ChainId.MAINNET, - GOERLI = ChainId.GOERLI, - SEPOLIA = ChainId.SEPOLIA, - POLYGON_MAINNET = ChainId.POLYGON_MAINNET, - POLYGON_MUMBAI = ChainId.POLYGON_MUMBAI, - AEVO_TESTNET = ChainId.AEVO_TESTNET, - AEVO = ChainId.AEVO, - HARDHAT = ChainId.HARDHAT, - AVALANCHE = ChainId.AVALANCHE, - LYRA_TESTNET = ChainId.LYRA_TESTNET, - LYRA = ChainId.LYRA, - XAI_TESTNET = 1399904803, -} - -export const hardhatChainNameToSlug = { - [HardhatChainName.ARBITRUM]: ChainSlug.ARBITRUM, - [HardhatChainName.ARBITRUM_GOERLI]: ChainSlug.ARBITRUM_GOERLI, - [HardhatChainName.OPTIMISM]: ChainSlug.OPTIMISM, - [HardhatChainName.OPTIMISM_GOERLI]: ChainSlug.OPTIMISM_GOERLI, - [HardhatChainName.BSC]: ChainSlug.BSC, - [HardhatChainName.BSC_TESTNET]: ChainSlug.BSC_TESTNET, - [HardhatChainName.MAINNET]: ChainSlug.MAINNET, - [HardhatChainName.GOERLI]: ChainSlug.GOERLI, - [HardhatChainName.SEPOLIA]: ChainSlug.SEPOLIA, - [HardhatChainName.POLYGON_MAINNET]: ChainSlug.POLYGON_MAINNET, - [HardhatChainName.POLYGON_MUMBAI]: ChainSlug.POLYGON_MUMBAI, - [HardhatChainName.AEVO_TESTNET]: ChainSlug.AEVO_TESTNET, - [HardhatChainName.AEVO]: ChainSlug.AEVO, - [HardhatChainName.LYRA_TESTNET]: ChainSlug.LYRA_TESTNET, - [HardhatChainName.LYRA]: ChainSlug.LYRA, - [HardhatChainName.XAI_TESTNET]: ChainSlug.XAI_TESTNET, - [HardhatChainName.HARDHAT]: ChainSlug.HARDHAT, -}; - -export const ChainSlugToKey = { - [ChainSlug.AVALANCHE]: HardhatChainName.AVALANCHE, - [ChainSlug.BSC]: HardhatChainName.BSC, - [ChainSlug.GOERLI]: HardhatChainName.GOERLI, - [ChainSlug.SEPOLIA]: HardhatChainName.SEPOLIA, - [ChainSlug.HARDHAT]: HardhatChainName.HARDHAT, - [ChainSlug.MAINNET]: HardhatChainName.MAINNET, - [ChainSlug.BSC_TESTNET]: HardhatChainName.BSC_TESTNET, - [ChainSlug.ARBITRUM]: HardhatChainName.ARBITRUM, - [ChainSlug.ARBITRUM_GOERLI]: HardhatChainName.ARBITRUM_GOERLI, - [ChainSlug.OPTIMISM]: HardhatChainName.OPTIMISM, - [ChainSlug.OPTIMISM_GOERLI]: HardhatChainName.OPTIMISM_GOERLI, - [ChainSlug.POLYGON_MAINNET]: HardhatChainName.POLYGON_MAINNET, - [ChainSlug.POLYGON_MUMBAI]: HardhatChainName.POLYGON_MUMBAI, - [ChainSlug.AEVO_TESTNET]: HardhatChainName.AEVO_TESTNET, - [ChainSlug.LYRA_TESTNET]: HardhatChainName.LYRA_TESTNET, - [ChainSlug.LYRA]: HardhatChainName.LYRA, - [ChainSlug.AEVO]: HardhatChainName.AEVO, - [ChainSlug.XAI_TESTNET]: HardhatChainName.XAI_TESTNET, -}; - -export const TestnetIds: ChainSlug[] = [ - ChainSlug.GOERLI, - ChainSlug.SEPOLIA, - ChainSlug.POLYGON_MUMBAI, - ChainSlug.ARBITRUM_GOERLI, - ChainSlug.OPTIMISM_GOERLI, - ChainSlug.BSC_TESTNET, - ChainSlug.AEVO_TESTNET, - ChainSlug.LYRA_TESTNET, - ChainSlug.XAI_TESTNET, -]; - -export const MainnetIds: ChainSlug[] = [ - ChainSlug.MAINNET, - ChainSlug.POLYGON_MAINNET, - ChainSlug.ARBITRUM, - ChainSlug.OPTIMISM, - ChainSlug.BSC, - ChainSlug.AEVO, - ChainSlug.LYRA, -]; +import { ChainSlug, MainnetIds, TestnetIds } from "./chain-types"; export const L1Ids: ChainSlug[] = [ChainSlug.MAINNET, ChainSlug.GOERLI]; diff --git a/test/socket/SocketBatcher.t.sol b/test/socket/SocketBatcher.t.sol index edd33435..a7851a10 100644 --- a/test/socket/SocketBatcher.t.sol +++ b/test/socket/SocketBatcher.t.sol @@ -38,145 +38,6 @@ contract SocketBatcherTest is Setup { batcher__ = new SocketBatcher(address(this)); } - function testSendBatch() external { - uint256 amount = 100; - bytes memory payload = abi.encode( - keccak256("OP_ADD"), - amount, - _plugOwner - ); - bytes memory proof = abi.encode(0); - - address capacitor = address(_a.configs__[index].capacitor__); - uint256 executionFee; - { - (uint256 switchboardFees, uint256 verificationFee) = _a - .configs__[index] - .switchboard__ - .getMinFees(_b.chainSlug); - - uint256 socketFees; - (executionFee, socketFees) = _a - .executionManager__ - .getExecutionTransmissionMinFees( - _minMsgGasLimit, - 100, - bytes32(0), - _transmissionParams, - _b.chainSlug, - address(_a.transmitManager__) - ); - - uint256 value = switchboardFees + - socketFees + - verificationFee + - executionFee; - - // executionFees to be recomputed which is totalValue - (socketFees + switchboardFees) - // verificationOverheadFees also should go to Executor, hence we do the additional computation below - executionFee = verificationFee + executionFee; - - hoax(_plugOwner); - srcCounter__.remoteAddOperation{value: value}( - _b.chainSlug, - amount, - _minMsgGasLimit, - bytes32(0), - bytes32(0) - ); - } - - bytes32 packetId; - bytes32 root; - { - bytes memory sig_; - (root, packetId, sig_) = _getLatestSignature( - capacitor, - _a.chainSlug, - _b.chainSlug - ); - - _sealOnSrc(_a, capacitor, DEFAULT_BATCH_LENGTH, sig_); - - SocketBatcher.ProposeRequest memory proposeRequest = SocketBatcher - .ProposeRequest({ - packetId: packetId, - root: root, - switchboard: address(_b.configs__[0].switchboard__), - signature: sig_ - }); - SocketBatcher.ProposeRequest[] - memory proposeRequests = new SocketBatcher.ProposeRequest[](1); - proposeRequests[0] = proposeRequest; - - bytes32 digest = keccak256( - abi.encode( - address(_b.configs__[0].switchboard__), - _b.chainSlug, - packetId, - 0, - root - ) - ); - - // generate attest-signature - bytes memory attestSignature = _createSignature( - digest, - _watcherPrivateKey - ); - - SocketBatcher.AttestRequest memory attestRequest = SocketBatcher - .AttestRequest({ - switchboard: address(_b.configs__[0].switchboard__), - packetId: packetId, - proposalCount: 0, - root: root, - signature: attestSignature - }); - - SocketBatcher.AttestRequest[] - memory attestRequests = new SocketBatcher.AttestRequest[](1); - attestRequests[0] = attestRequest; - SocketBatcher.ExecuteRequest[] memory executeRequests; - SocketBatcher.SealRequest[] memory sealRequests; - - batcher__.sendBatch( - address(_b.socket__), - sealRequests, - proposeRequests, - attestRequests, - executeRequests - ); - } - - vm.expectEmit(true, false, false, false); - emit ExecutionSuccess( - _packMessageId(_a.chainSlug, address(dstCounter__), 0) - ); - _executePayloadOnDst( - _b, - ExecutePayloadOnDstParams( - packetId, - 0, - _packMessageId(_a.chainSlug, address(dstCounter__), 0), - _minMsgGasLimit, - bytes32(0), - executionFee, - root, - payload, - proof - ) - ); - - assertEq(dstCounter__.counter(), amount); - assertEq(srcCounter__.counter(), 0); - assertTrue( - _b.socket__.messageExecuted( - _packMessageId(_a.chainSlug, address(dstCounter__), 0) - ) - ); - } - function _deployPlugContracts() internal { vm.startPrank(_plugOwner); diff --git a/yarn.lock b/yarn.lock index c423f3e8..d28777a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -997,10 +997,10 @@ resolved "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz" integrity sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw== -"@socket.tech/dl-core@2.4.5": - version "2.4.5" - resolved "https://registry.yarnpkg.com/@socket.tech/dl-core/-/dl-core-2.4.5.tgz#93097e084fd4abbff7c8d00e8c37af006b83ce83" - integrity sha512-i9elPjrkbRZ1sUlvxNbhtDU7R+Yx7nIhoo4OVHDVqSSMtSrXdSVmQAMMiFdCoQP/NeV532aXIDo/PILo3PHEOw== +"@socket.tech/dl-core@2.4.9": + version "2.4.9" + resolved "https://registry.yarnpkg.com/@socket.tech/dl-core/-/dl-core-2.4.9.tgz#4d12ff34148bfcef85cb3c0240e941fee4d01027" + integrity sha512-nbuid8aq+cfYubU8mLtw2mZaZKjk9ZUsEcenpFF8EvvuS4YAriLoo0lOiGYRqXZNNfogh6wsXj4EbbXwxs7hGw== dependencies: axios "^1.3.6" yargs "^17.7.1"