From f72f4d70623a2c5f66ff64ba4e444934a36cde7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Tkaczy=C5=84ski?= Date: Thu, 11 Apr 2024 11:03:42 +0200 Subject: [PATCH] feat: handle cross-chain dependencies in deployment (#218) * feat: allow retry on deployment steps * feat: handle cross-chain dependencies --- .changeset/swift-jokes-work.md | 5 + apps/ui/package.json | 1 + .../components/CreateDeploymentProgress.vue | 179 +++-- apps/ui/src/components/Modal/Connector.vue | 71 ++ apps/ui/src/composables/useActions.ts | 2 +- apps/ui/src/networks/starknet/actions.ts | 21 +- apps/ui/src/networks/starknet/constants.ts | 70 +- apps/ui/src/networks/starknet/index.ts | 2 +- apps/ui/src/networks/types.ts | 2 + .../abis/L1AvatarExecutionStrategy.json | 626 ++++++++++++++++++ .../src/clients/starknet/starknet-tx/index.ts | 36 + packages/sx.js/src/starknetNetworks.ts | 13 +- packages/sx.js/src/types/networkConfig.ts | 7 +- 13 files changed, 967 insertions(+), 68 deletions(-) create mode 100644 .changeset/swift-jokes-work.md create mode 100644 apps/ui/src/components/Modal/Connector.vue create mode 100644 packages/sx.js/src/clients/starknet/starknet-tx/abis/L1AvatarExecutionStrategy.json diff --git a/.changeset/swift-jokes-work.md b/.changeset/swift-jokes-work.md new file mode 100644 index 000000000..73cccd433 --- /dev/null +++ b/.changeset/swift-jokes-work.md @@ -0,0 +1,5 @@ +--- +"@snapshot-labs/sx": patch +--- + +add deployL1AvatarExecution function to StarknetTx diff --git a/apps/ui/package.json b/apps/ui/package.json index 38bb16552..7c0b8addc 100644 --- a/apps/ui/package.json +++ b/apps/ui/package.json @@ -31,6 +31,7 @@ "@braintree/sanitize-url": "^6.0.4", "@ensdomains/eth-ens-namehash": "^2.0.15", "@ethersproject/abi": "^5.7.0", + "@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/address": "^5.7.0", "@ethersproject/bignumber": "^5.7.0", "@ethersproject/constants": "^5.7.0", diff --git a/apps/ui/src/components/CreateDeploymentProgress.vue b/apps/ui/src/components/CreateDeploymentProgress.vue index 49b3ed323..28ebdd2d1 100644 --- a/apps/ui/src/components/CreateDeploymentProgress.vue +++ b/apps/ui/src/components/CreateDeploymentProgress.vue @@ -1,9 +1,27 @@ @@ -149,11 +211,14 @@ onMounted(() => deploy());

+ + Retry + {{ shorten(txIds[step.id]) }} @@ -172,4 +237,10 @@ onMounted(() => deploy()); />.

+ diff --git a/apps/ui/src/components/Modal/Connector.vue b/apps/ui/src/components/Modal/Connector.vue new file mode 100644 index 000000000..120308066 --- /dev/null +++ b/apps/ui/src/components/Modal/Connector.vue @@ -0,0 +1,71 @@ + + + diff --git a/apps/ui/src/composables/useActions.ts b/apps/ui/src/composables/useActions.ts index 8d69a67d4..0f06d6feb 100644 --- a/apps/ui/src/composables/useActions.ts +++ b/apps/ui/src/composables/useActions.ts @@ -170,7 +170,7 @@ export function useActions() { predictedSpaceAddress: predictSpaceAddress(networkId, salt) }); - return receipt.txId; + return receipt; } async function updateMetadata(space: Space, metadata: SpaceMetadata) { diff --git a/apps/ui/src/networks/starknet/actions.ts b/apps/ui/src/networks/starknet/actions.ts index 315628ecd..33b5e1690 100644 --- a/apps/ui/src/networks/starknet/actions.ts +++ b/apps/ui/src/networks/starknet/actions.ts @@ -82,8 +82,25 @@ export function createActions( async predictSpaceAddress(web3: any, { salt }) { return client.predictSpaceAddress({ account: web3.provider.account, saltNonce: salt }); }, - async deployDependency() { - throw new Error('Not implemented'); + async deployDependency( + web3: any, + params: { + controller: string; + spaceAddress: string; + strategy: StrategyConfig; + } + ) { + if (!params.strategy.deploy) { + throw new Error('This strategy is not deployable'); + } + + return params.strategy.deploy( + client, + web3.getSigner(), + params.controller, + params.spaceAddress, + params.strategy.params + ); }, async createSpace( web3: any, diff --git a/apps/ui/src/networks/starknet/constants.ts b/apps/ui/src/networks/starknet/constants.ts index f11448052..138b83e5f 100644 --- a/apps/ui/src/networks/starknet/constants.ts +++ b/apps/ui/src/networks/starknet/constants.ts @@ -1,5 +1,6 @@ +import { Signer } from '@ethersproject/abstract-signer'; import { CallData, uint256 } from 'starknet'; -import { utils, starknetNetworks } from '@snapshot-labs/sx'; +import { clients, utils, starknetNetworks } from '@snapshot-labs/sx'; import { getUrl, shorten } from '@/helpers/utils'; import { pinPineapple } from '@/helpers/pin'; import { StrategyConfig, StrategyTemplate } from '../types'; @@ -8,11 +9,13 @@ import IHCode from '~icons/heroicons-outline/code'; import IHCube from '~icons/heroicons-outline/cube'; import IHPencil from '~icons/heroicons-outline/pencil'; import IHLightningBolt from '~icons/heroicons-outline/lightning-bolt'; +import IHUserCircle from '~icons/heroicons-outline/user-circle'; import { MAX_SYMBOL_LENGTH } from '@/helpers/constants'; import { NetworkID, StrategyParsedMetadata } from '@/types'; +import { EVM_CONNECTORS } from '../common/constants'; -export function createConstants(networkId: NetworkID) { - const config = starknetNetworks[networkId]; +export function createConstants(networkId: NetworkID, baseNetworkId: NetworkID) { + const config = starknetNetworks[networkId as 'sn' | 'sn-tn' | 'sn-sep']; if (!config) throw new Error(`Unsupported network ${networkId}`); const SUPPORTED_AUTHENTICATORS = { @@ -398,9 +401,9 @@ export function createConstants(networkId: NetworkID) { const EDITOR_PROPOSAL_VALIDATION_VOTING_STRATEGIES = EDITOR_VOTING_STRATEGIES.filter( strategy => - ![config.Strategies.EVMSlotValue, config.Strategies.OZVotesStorageProof].includes( - strategy.address - ) + !( + [config.Strategies.EVMSlotValue, config.Strategies.OZVotesStorageProof] as string[] + ).includes(strategy.address) ); const EDITOR_EXECUTION_STRATEGIES = [ @@ -409,6 +412,61 @@ export function createConstants(networkId: NetworkID) { type: 'NoExecutionSimpleMajority', name: EXECUTORS.NoExecutionSimpleMajority, paramsDefinition: null + }, + { + address: config.ExecutionStrategies.EthRelayer, + type: 'EthRelayer', + name: EXECUTORS.EthRelayer, + about: + 'An execution strategy that allows proposals to execute transactions from a specified target Avatar contract on L1, the most popular one being a Safe.', + icon: IHUserCircle, + generateSummary: (params: Record) => + `(${params.quorum}, ${shorten(params.contractAddress)})`, + deployNetworkId: baseNetworkId, + deployConnectors: EVM_CONNECTORS, + deploy: async ( + client: clients.StarknetTx, + signer: Signer, + controller: string, + spaceAddress: string, + params: Record + ): Promise<{ address: string; txId: string }> => { + return client.deployL1AvatarExecution({ + signer, + params: { + controller: params.l1Controller, + target: params.contractAddress, + executionRelayer: config.ExecutionStrategies.EthRelayer, + spaces: [spaceAddress], + quorum: BigInt(params.quorum) + } + }); + }, + paramsDefinition: { + type: 'object', + title: 'Params', + additionalProperties: false, + required: ['l1Controller', 'quorum', 'contractAddress'], + properties: { + l1Controller: { + type: 'string', + format: 'address', + title: 'Controller address', + examples: ['0x0000…'] + }, + quorum: { + type: 'integer', + title: 'Quorum', + examples: ['1'] + }, + contractAddress: { + type: 'string', + format: 'address', + title: 'Avatar address', + examples: ['0x0000…'] + } + } + } } ]; diff --git a/apps/ui/src/networks/starknet/index.ts b/apps/ui/src/networks/starknet/index.ts index da0d2a6b2..e9c4823fa 100644 --- a/apps/ui/src/networks/starknet/index.ts +++ b/apps/ui/src/networks/starknet/index.ts @@ -65,7 +65,7 @@ export function createStarknetNetwork(networkId: NetworkID): Network { const provider = createProvider(rpcUrl); const api = createApi(apiUrl, networkId); - const constants = createConstants(networkId); + const constants = createConstants(networkId, baseNetworkId); const helpers = { isAuthenticatorSupported: (authenticator: string) => diff --git a/apps/ui/src/networks/types.ts b/apps/ui/src/networks/types.ts index a36f7cd25..d021aa1ff 100644 --- a/apps/ui/src/networks/types.ts +++ b/apps/ui/src/networks/types.ts @@ -49,6 +49,8 @@ export type StrategyTemplate = { params: string, metadata: StrategyParsedMetadata | null ) => Promise>; + deployConnectors?: Connector[]; + deployNetworkId?: NetworkID; deploy?: ( client: any, signer: Signer, diff --git a/packages/sx.js/src/clients/starknet/starknet-tx/abis/L1AvatarExecutionStrategy.json b/packages/sx.js/src/clients/starknet/starknet-tx/abis/L1AvatarExecutionStrategy.json new file mode 100644 index 000000000..2e8e587b2 --- /dev/null +++ b/packages/sx.js/src/clients/starknet/starknet-tx/abis/L1AvatarExecutionStrategy.json @@ -0,0 +1,626 @@ +{ + "abi": [ + { + "type": "constructor", + "inputs": [ + { + "name": "_owner", + "type": "address", + "internalType": "address" + }, + { + "name": "_target", + "type": "address", + "internalType": "address" + }, + { + "name": "_starknetCore", + "type": "address", + "internalType": "address" + }, + { + "name": "_executionRelayer", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_starknetSpaces", + "type": "uint256[]", + "internalType": "uint256[]" + }, + { + "name": "_quorum", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "disableSpace", + "inputs": [ + { + "name": "space", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "enableSpace", + "inputs": [ + { + "name": "space", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "execute", + "inputs": [ + { + "name": "space", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "proposal", + "type": "tuple", + "internalType": "struct Proposal", + "components": [ + { + "name": "startTimestamp", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "minEndTimestamp", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "maxEndTimestamp", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "finalizationStatus", + "type": "uint8", + "internalType": "enum FinalizationStatus" + }, + { + "name": "executionPayloadHash", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "executionStrategy", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "authorAddressType", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "author", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "activeVotingStrategies", + "type": "uint256", + "internalType": "uint256" + } + ] + }, + { + "name": "votesFor", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "votesAgainst", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "votesAbstain", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "executionHash", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "transactions", + "type": "tuple[]", + "internalType": "struct MetaTransaction[]", + "components": [ + { + "name": "to", + "type": "address", + "internalType": "address" + }, + { + "name": "value", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "data", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "operation", + "type": "uint8", + "internalType": "enum Enum.Operation" + }, + { + "name": "salt", + "type": "uint256", + "internalType": "uint256" + } + ] + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "executionRelayer", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getProposalStatus", + "inputs": [ + { + "name": "proposal", + "type": "tuple", + "internalType": "struct Proposal", + "components": [ + { + "name": "startTimestamp", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "minEndTimestamp", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "maxEndTimestamp", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "finalizationStatus", + "type": "uint8", + "internalType": "enum FinalizationStatus" + }, + { + "name": "executionPayloadHash", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "executionStrategy", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "authorAddressType", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "author", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "activeVotingStrategies", + "type": "uint256", + "internalType": "uint256" + } + ] + }, + { + "name": "votesFor", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "votesAgainst", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "votesAbstain", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint8", + "internalType": "enum ProposalStatus" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getStrategyType", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string", + "internalType": "string" + } + ], + "stateMutability": "pure" + }, + { + "type": "function", + "name": "isSpaceEnabled", + "inputs": [ + { + "name": "space", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "owner", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "quorum", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "renounceOwnership", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setExecutionRelayer", + "inputs": [ + { + "name": "_executionRelayer", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setQuorum", + "inputs": [ + { + "name": "_quorum", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setStarknetCore", + "inputs": [ + { + "name": "_starknetCore", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setTarget", + "inputs": [ + { + "name": "_target", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setUp", + "inputs": [ + { + "name": "initParams", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "starknetCore", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "target", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "transferOwnership", + "inputs": [ + { + "name": "newOwner", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "event", + "name": "ExecutionRelayerSet", + "inputs": [ + { + "name": "newExecutionRelayer", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Initialized", + "inputs": [ + { + "name": "version", + "type": "uint8", + "indexed": false, + "internalType": "uint8" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "L1AvatarExecutionStrategySetUp", + "inputs": [ + { + "name": "_owner", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "_target", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "_starknetCore", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "_executionRelayer", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "_starknetSpaces", + "type": "uint256[]", + "indexed": false, + "internalType": "uint256[]" + }, + { + "name": "_quorum", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "OwnershipTransferred", + "inputs": [ + { + "name": "previousOwner", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newOwner", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "QuorumUpdated", + "inputs": [ + { + "name": "newQuorum", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "SpaceDisabled", + "inputs": [ + { + "name": "space", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "SpaceEnabled", + "inputs": [ + { + "name": "space", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "StarknetCoreSet", + "inputs": [ + { + "name": "newStarknetCore", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "TargetSet", + "inputs": [ + { + "name": "newTarget", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "error", + "name": "ExecutionFailed", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidPayload", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidProposalStatus", + "inputs": [ + { + "name": "status", + "type": "uint8", + "internalType": "enum ProposalStatus" + } + ] + }, + { + "type": "error", + "name": "InvalidSpace", + "inputs": [] + } + ], + "bytecode": "0x60806040523480156200001157600080fd5b5060405162002148380380620021488339810160408190526200003491620006c9565b6000868686868686604051602001620000539695949392919062000799565b60408051601f19818403018152919052905062000070816200007d565b505050505050506200086e565b600054610100900460ff16158080156200009e5750600054600160ff909116105b80620000ba5750303b158015620000ba575060005460ff166001145b620001235760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff19166001179055801562000147576000805461ff0019166101001790555b60008060008060008087806020019051810190620001669190620006c9565b955095509550955095509550620001826200026d60201b60201c565b6200018d86620002d5565b620001988262000354565b620001a38162000483565b60c980546001600160a01b038088166001600160a01b03199283161790925560ca8054878416921691909117905560cb849055604051908716907f7cb11163b4e1309a1cadb740a7d8e8c92de9a2c26345fda2a776b419dc68dad490620002149088908890889088908890620007e9565b60405180910390a2505050505050801562000269576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050565b600054610100900460ff16620002c95760405162461bcd60e51b815260206004820152602b60248201526000805160206200212883398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200011a565b620002d3620004e4565b565b620002df6200054b565b6001600160a01b038116620003465760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016200011a565b6200035181620005a7565b50565b600054610100900460ff16620003b05760405162461bcd60e51b815260206004820152602b60248201526000805160206200212883398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200011a565b60005b81518110156200026957818181518110620003d257620003d262000830565b602002602001015160001480620004195750600060656000848481518110620003ff57620003ff62000830565b602002602001015181526020019081526020016000205414155b15620004385760405163c3b48cf160e01b815260040160405180910390fd5b60016065600084848151811062000453576200045362000830565b602002602001015181526020019081526020016000208190555080806200047a9062000846565b915050620003b3565b600054610100900460ff16620004df5760405162461bcd60e51b815260206004820152602b60248201526000805160206200212883398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200011a565b609755565b600054610100900460ff16620005405760405162461bcd60e51b815260206004820152602b60248201526000805160206200212883398151915260448201526a6e697469616c697a696e6760a81b60648201526084016200011a565b620002d333620005a7565b6033546001600160a01b03163314620002d35760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016200011a565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b03811681146200035157600080fd5b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200063757600080fd5b815160206001600160401b03808311156200065657620006566200060f565b8260051b604051601f19603f830116810181811084821117156200067e576200067e6200060f565b6040529384528581018301938381019250878511156200069d57600080fd5b83870191505b84821015620006be57815183529183019190830190620006a3565b979650505050505050565b60008060008060008060c08789031215620006e357600080fd5b8651620006f081620005f9565b60208801519096506200070381620005f9565b60408801519095506200071681620005f9565b6060880151608089015191955093506001600160401b038111156200073a57600080fd5b6200074889828a0162000625565b92505060a087015190509295509295509295565b600081518084526020808501945080840160005b838110156200078e5781518752958201959082019060010162000770565b509495945050505050565b6001600160a01b0387811682528681166020830152851660408201526060810184905260c060808201819052600090620007d6908301856200075c565b90508260a0830152979650505050505050565b6001600160a01b038681168252851660208201526040810184905260a0606082018190526000906200081e908301856200075c565b90508260808301529695505050505050565b634e487b7160e01b600052603260045260246000fd5b6000600182016200086757634e487b7160e01b600052601160045260246000fd5b5060010190565b6118aa806200087e6000396000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c80638da5cb5b116100a2578063cd17d92911610071578063cd17d92914610245578063d4b8399214610265578063db9926ef14610278578063e8aca4531461028b578063f2fde38b146102ab57600080fd5b80638da5cb5b14610205578063a4f9edbf14610216578063c1ba4e5914610229578063c5a3f5321461023c57600080fd5b806352915aa2116100e957806352915aa2146101b1578063626274c3146101c45780636c1067e9146101d7578063715018a6146101ea578063776d1a01146101f257600080fd5b80630eb9b15a1461011b5780631703a0181461015a57806337c709f91461017157806339e730ab14610186575b600080fd5b604080518082018252601481527329b4b6b83632a8bab7b93ab6a618a0bb30ba30b960611b602082015290516101519190611090565b60405180910390f35b61016360975481565b604051908152602001610151565b61018461017f3660046112a4565b6102be565b005b60ca54610199906001600160a01b031681565b6040516001600160a01b039091168152602001610151565b6101846101bf366004611445565b6103c4565b6101846101d236600461145e565b610446565b6101846101e5366004611445565b610498565b61018461051c565b61018461020036600461145e565b610530565b6033546001600160a01b0316610199565b61018461022436600461147b565b610582565b610184610237366004611445565b610755565b61016360cb5481565b6102586102533660046114b0565b610792565b6040516101519190611504565b60c954610199906001600160a01b031681565b610184610286366004611445565b610883565b610163610299366004611445565b60009081526065602052604090205490565b6101846102b936600461145e565b6108be565b60008781526065602052604090205487906102ec5760405163c3b48cf160e01b815260040160405180910390fd5b6102fa888888888888610937565b600061030888888888610792565b9050600381600681111561031e5761031e6114ee565b1415801561033e5750600281600681111561033b5761033b6114ee565b14155b15610367578060405163735671c760e11b815260040161035e9190611504565b60405180910390fd5b826040516020016103789190611532565b604051602081830303815290604052805190602001208460001b146103b057604051637c6953f960e01b815260040160405180910390fd5b6103b983610cc8565b505050505050505050565b6103cc610df9565b6000818152606560205260409020546103f85760405163c3b48cf160e01b815260040160405180910390fd5b60008181526065602052604080822091909155517f74d5daeae1a5cd3f007ca1551ac8699aa3098c866fd647b9e397120e98cb98a09061043b9083815260200190565b60405180910390a150565b61044e610df9565b60ca80546001600160a01b0319166001600160a01b0383169081179091556040517fa99d6c8329cbee48dc96d7328371672047039f28c4e6bf2a9780b15cd39e2b1390600090a250565b6104a0610df9565b8015806104ba575060008181526065602052604090205415155b156104d85760405163c3b48cf160e01b815260040160405180910390fd5b6000818152606560205260409081902060019055517f4b9bd286a0bdefb75bd30d4b6547c115882017ce775c1388e88e8dcedee05bc09061043b9083815260200190565b610524610df9565b61052e6000610e53565b565b610538610df9565b60c980546001600160a01b0319166001600160a01b0383169081179091556040517f3bfb4bbf112628248058745a3c57e35b13369386e474b8e56c552f3063a4a19690600090a250565b600054610100900460ff16158080156105a25750600054600160ff909116105b806105bc5750303b1580156105bc575060005460ff166001145b61061f5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161035e565b6000805460ff191660011790558015610642576000805461ff0019166101001790555b6000806000806000808780602001905181019061065f91906115dd565b955095509550955095509550610673610ea5565b61067c866108be565b61068582610ed4565b61068e81610fbf565b60c980546001600160a01b038088166001600160a01b03199283161790925560ca8054878416921691909117905560cb849055604051908716907f7cb11163b4e1309a1cadb740a7d8e8c92de9a2c26345fda2a776b419dc68dad4906106fd90889088908890889088906116f9565b60405180910390a25050505050508015610751576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050565b61075d610df9565b60978190556040518181527ff18f88786aae85a652aadb99a82462616489a33370c9bcc7b245906812ef7cd19060200161043b565b6000806107a3609754868686610feb565b80156107b457506107b48585611010565b90506002866060015160028111156107ce576107ce6114ee565b036107dd57600691505061087b565b6001866060015160028111156107f5576107f56114ee565b0361080457600491505061087b565b855163ffffffff1642101561081d57600091505061087b565b856020015163ffffffff1642101561083957600191505061087b565b856040015163ffffffff1642101561086557801561085b57600291505061087b565b600191505061087b565b801561087557600391505061087b565b60059150505b949350505050565b61088b610df9565b60cb81905560405181907f53aa68529dff3180c91e31b31e62906e030b1c11976c17e3741165c09aa127e090600090a250565b6108c6610df9565b6001600160a01b03811661092b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161035e565b61093481610e53565b50565b6040805160138082526102808201909252600091602082016102608036833701905050905086816000815181106109705761097061173e565b602002602001018181525050856000015163ffffffff168160018151811061099a5761099a61173e565b602002602001018181525050856020015163ffffffff16816002815181106109c4576109c461173e565b602002602001018181525050856040015163ffffffff16816003815181106109ee576109ee61173e565b60200260200101818152505085606001516002811115610a1057610a106114ee565b81600481518110610a2357610a2361173e565b602002602001018181525050856080015181600581518110610a4757610a4761173e565b6020026020010181815250508560a0015181600681518110610a6b57610a6b61173e565b6020026020010181815250508560c0015181600781518110610a8f57610a8f61173e565b6020026020010181815250508560e0015181600881518110610ab357610ab361173e565b6020026020010181815250508561010001516001600160801b031681600981518110610ae157610ae161173e565b6020026020010181815250506080866101000151901c81600a81518110610b0a57610b0a61173e565b602002602001018181525050846001600160801b031681600b81518110610b3357610b3361173e565b602002602001018181525050608085901c81600c81518110610b5757610b5761173e565b602002602001018181525050836001600160801b031681600d81518110610b8057610b8061173e565b602002602001018181525050608084901c81600e81518110610ba457610ba461173e565b602002602001018181525050826001600160801b031681600f81518110610bcd57610bcd61173e565b602002602001018181525050608083901c81601081518110610bf157610bf161173e565b602002602001018181525050816001600160801b031681601181518110610c1a57610c1a61173e565b602002602001018181525050608082901c81601281518110610c3e57610c3e61173e565b602090810291909101015260ca5460cb5460405162b2775760e61b81526001600160a01b0390921691632c9dd5c091610c7b918590600401611754565b6020604051808303816000875af1158015610c9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cbe919061176d565b5050505050505050565b60005b81518110156107515760c95482516000916001600160a01b03169063468721a790859085908110610cfe57610cfe61173e565b602002602001015160000151858581518110610d1c57610d1c61173e565b602002602001015160200151868681518110610d3a57610d3a61173e565b602002602001015160400151878781518110610d5857610d5861173e565b6020026020010151606001516040518563ffffffff1660e01b8152600401610d839493929190611786565b6020604051808303816000875af1158015610da2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dc691906117c5565b905080610de657604051632b3f6d1160e21b815260040160405180910390fd5b5080610df1816117fd565b915050610ccb565b6033546001600160a01b0316331461052e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161035e565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff16610ecc5760405162461bcd60e51b815260040161035e90611816565b61052e61101a565b600054610100900460ff16610efb5760405162461bcd60e51b815260040161035e90611816565b60005b815181101561075157818181518110610f1957610f1961173e565b602002602001015160001480610f5c5750600060656000848481518110610f4257610f4261173e565b602002602001015181526020019081526020016000205414155b15610f7a5760405163c3b48cf160e01b815260040160405180910390fd5b600160656000848481518110610f9257610f9261173e565b60200260200101518152602001908152602001600020819055508080610fb7906117fd565b915050610efe565b600054610100900460ff16610fe65760405162461bcd60e51b815260040161035e90611816565b609755565b60008082610ff98587611861565b6110039190611861565b9095111595945050505050565b8082115b92915050565b600054610100900460ff166110415760405162461bcd60e51b815260040161035e90611816565b61052e33610e53565b6000815180845260005b8181101561107057602081850181015186830182015201611054565b506000602082860101526020601f19601f83011685010191505092915050565b6020815260006110a3602083018461104a565b9392505050565b634e487b7160e01b600052604160045260246000fd5b604051610120810167ffffffffffffffff811182821017156110e4576110e46110aa565b60405290565b60405160a0810167ffffffffffffffff811182821017156110e4576110e46110aa565b604051601f8201601f1916810167ffffffffffffffff81118282101715611136576111366110aa565b604052919050565b803563ffffffff8116811461115257600080fd5b919050565b80356003811061115257600080fd5b6000610120828403121561117957600080fd5b6111816110c0565b905061118c8261113e565b815261119a6020830161113e565b60208201526111ab6040830161113e565b60408201526111bc60608301611157565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e082015261010080830135818301525092915050565b600067ffffffffffffffff821115611215576112156110aa565b5060051b60200190565b6001600160a01b038116811461093457600080fd5b600082601f83011261124557600080fd5b813567ffffffffffffffff81111561125f5761125f6110aa565b611272601f8201601f191660200161110d565b81815284602083860101111561128757600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060008060006101e0888a0312156112c057600080fd5b873596506112d18960208a01611166565b95506101408801359450610160880135935061018088013592506101a0880135915067ffffffffffffffff6101c0890135111561130d57600080fd5b6101c0880135880189601f82011261132457600080fd5b61133661133182356111fb565b61110d565b81358082526020808301929160051b8401018c101561135457600080fd5b602083015b6020843560051b8501018110156114325767ffffffffffffffff8135111561138057600080fd5b60a0813585018e03601f1901121561139757600080fd5b61139f6110ea565b6113af602083358701013561121f565b81358501602081810135835260408201359083015267ffffffffffffffff60609091013511156113de57600080fd5b6113f48e83358701606081013501602001611234565b6040820152600260808335870101351061140d57600080fd5b60808235860181810135606084015260a0013590820152835260209283019201611359565b5080935050505092959891949750929550565b60006020828403121561145757600080fd5b5035919050565b60006020828403121561147057600080fd5b81356110a38161121f565b60006020828403121561148d57600080fd5b813567ffffffffffffffff8111156114a457600080fd5b61087b84828501611234565b60008060008061018085870312156114c757600080fd5b6114d18686611166565b966101208601359650610140860135956101600135945092505050565b634e487b7160e01b600052602160045260246000fd5b6020810160078310611518576115186114ee565b91905290565b6002811061152e5761152e6114ee565b9052565b60006020808301818452808551808352604092508286019150828160051b87010184880160005b838110156115cf57888303603f19018552815180516001600160a01b0316845287810151888501528681015160a08886018190529061159a8287018261104a565b9150506060808301516115af8288018261151e565b505060809182015194909101939093529386019390860190600101611559565b509098975050505050505050565b60008060008060008060c087890312156115f657600080fd5b86516116018161121f565b809650506020808801516116148161121f565b60408901519096506116258161121f565b606089015160808a0151919650945067ffffffffffffffff81111561164957600080fd5b8801601f81018a1361165a57600080fd5b8051611668611331826111fb565b81815260059190911b8201830190838101908c83111561168757600080fd5b928401925b828410156116a55783518252928401929084019061168c565b809650505050505060a087015190509295509295509295565b600081518084526020808501945080840160005b838110156116ee578151875295820195908201906001016116d2565b509495945050505050565b6001600160a01b038681168252851660208201526040810184905260a06060820181905260009061172c908301856116be565b90508260808301529695505050505050565b634e487b7160e01b600052603260045260246000fd5b82815260406020820152600061087b60408301846116be565b60006020828403121561177f57600080fd5b5051919050565b60018060a01b03851681528360208201526080604082015260006117ad608083018561104a565b90506117bc606083018461151e565b95945050505050565b6000602082840312156117d757600080fd5b815180151581146110a357600080fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161180f5761180f6117e7565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b80820180821115611014576110146117e756fea2646970667358221220b59bf5b09abe52c4c01630982ec0830ebd3c96512245c731be2e77d496e3431064736f6c63430008130033496e697469616c697a61626c653a20636f6e7472616374206973206e6f742069" +} diff --git a/packages/sx.js/src/clients/starknet/starknet-tx/index.ts b/packages/sx.js/src/clients/starknet/starknet-tx/index.ts index 6f6198507..c674b8191 100644 --- a/packages/sx.js/src/clients/starknet/starknet-tx/index.ts +++ b/packages/sx.js/src/clients/starknet/starknet-tx/index.ts @@ -1,4 +1,6 @@ import { Account, CallData, shortString, uint256, hash } from 'starknet'; +import { ContractFactory } from '@ethersproject/contracts'; +import { Signer } from '@ethersproject/abstract-signer'; import { poseidonHashMany } from 'micro-starknet'; import randomBytes from 'randombytes'; import { getStrategiesWithParams } from '../../../utils/strategies'; @@ -6,6 +8,7 @@ import { getAuthenticator } from '../../../authenticators/starknet'; import { hexPadLeft } from '../../../utils/encoding'; import { defaultNetwork } from '../../../networks'; import SpaceAbi from './abis/Space.json'; +import L1AvatarExecutionStrategyAbi from './abis/L1AvatarExecutionStrategy.json'; import { Vote, Propose, @@ -30,6 +33,14 @@ type SpaceParams = { votingStrategiesMetadata: string[]; }; +type L1AvatarExecutionStrategyParams = { + controller: string; + target: string; + executionRelayer: string; + spaces: string[]; + quorum: bigint; +}; + type UpdateSettingsInput = { minVotingDuration?: number; maxVotingDuration?: number; @@ -120,6 +131,31 @@ export class StarknetTx { return { txId: res.transaction_hash, address }; } + async deployL1AvatarExecution({ + signer, + params: { controller, target, executionRelayer, spaces, quorum } + }: { + signer: Signer; + params: L1AvatarExecutionStrategyParams; + }): Promise<{ txId: string; address: string }> { + const l1AvatarExecutionStrategyContractFactor = new ContractFactory( + L1AvatarExecutionStrategyAbi.abi, + L1AvatarExecutionStrategyAbi.bytecode, + signer + ); + + const contract = await l1AvatarExecutionStrategyContractFactor.deploy( + controller, + target, + this.config.networkConfig.starknetCommit, + executionRelayer, + spaces, + quorum + ); + + return { address: contract.address, txId: contract.deployTransaction.hash }; + } + async getSalt({ sender, saltNonce }: { sender: string; saltNonce: string }) { return poseidonHashMany([BigInt(sender), BigInt(saltNonce)]); } diff --git a/packages/sx.js/src/starknetNetworks.ts b/packages/sx.js/src/starknetNetworks.ts index 97255a070..0a163f1cd 100644 --- a/packages/sx.js/src/starknetNetworks.ts +++ b/packages/sx.js/src/starknetNetworks.ts @@ -57,6 +57,7 @@ function createStarknetConfig(networkId: keyof typeof starknetNetworks): Network spaceFactory: network.Meta.spaceFactory, masterSpace: network.Meta.masterSpace, starknetCommit: network.Meta.starknetCommit, + starknetCore: network.Meta.starknetCore, authenticators, strategies }; @@ -70,7 +71,8 @@ export const starknetNetworks = { herodotusDeployedOnChain: 'STARKNET', spaceFactory: '0x0250e28c97e729842190c3672f9fcf8db0fc78b8080e87a894831dc69e4f4439', masterSpace: '0x00f20287bef9f46c6051e425a84094d2436bcc1fef804db353e60f93661961ac', - starknetCommit: '0xf1ec7b0276aa5af11ecefe56efb0f198a77016e9' + starknetCommit: '0xf1ec7b0276aa5af11ecefe56efb0f198a77016e9', + starknetCore: '0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4' }, Authenticators: { Vanilla: '0xc4b0a7d8626638e7dd410b16ccbc48fe36e68f864dec75b23ef41e3732d5d2', @@ -89,6 +91,7 @@ export const starknetNetworks = { VotingPower: '0x1b28f95cbc5bcbe52014ef974d609f14497517f31d3c9e079a2464edf988751' }, ExecutionStrategies: { + EthRelayer: '0x041c679daa4de984c72e2671405294b6064da964d1cee9db2fb26ba974f99fed', NoExecutionSimpleMajority: '0x180e1f4fcd875b35690b6771b30197867d39c893d5ba6e32c36616733ee37c4' } }, @@ -99,7 +102,8 @@ export const starknetNetworks = { herodotusDeployedOnChain: 'SN_GOERLI', spaceFactory: '0x063c62258e1ba4d9ad72eab809ea5c3d1a4545b721bc444d6068ced6246c2f3c', masterSpace: '0x00f20287bef9f46c6051e425a84094d2436bcc1fef804db353e60f93661961ac', - starknetCommit: '0x8bf85537c80becba711447f66a9a4452e3575e29' + starknetCommit: '0x8bf85537c80becba711447f66a9a4452e3575e29', + starknetCore: '0xde29d060D45901Fb19ED6C6e959EB22d8626708e' }, Authenticators: { Vanilla: '0x46ad946f22ac4e14e271f24309f14ac36f0fde92c6831a605813fefa46e0893', @@ -118,6 +122,7 @@ export const starknetNetworks = { VotingPower: '0x3ff398ab4e0aa9109c0cc889ff968c6215053a5e2176519b59f8ba87927c631' }, ExecutionStrategies: { + EthRelayer: '0xa0a4bcf464e29f46dfb103521f33807271b4300ac5cd3118b15f31f89ecd94', NoExecutionSimpleMajority: '0x4a5658d6b9fe62283147719a8b13d72f96e8959afacc716569b936c91089147' } }, @@ -128,7 +133,8 @@ export const starknetNetworks = { herodotusDeployedOnChain: 'SN_SEPOLIA', spaceFactory: '0x302d332e9aceb184e5f301cb62c85181e7fc3b30559935c5736e987de579f6e', masterSpace: '0x04b61126a7def0956cb4ff342ba72d850ea6b78b0ddb3e0b45f3a99bc9eb5995', - starknetCommit: '0xf1ec7b0276aa5af11ecefe56efb0f198a77016e9' + starknetCommit: '0xf1ec7b0276aa5af11ecefe56efb0f198a77016e9', + starknetCore: '0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057' }, Authenticators: { Vanilla: '0x51a4a1eb5ce28fc95edf408a847efccfb030d27314d9fbe82d82cb998ec1a0b', @@ -147,6 +153,7 @@ export const starknetNetworks = { VotingPower: '0x296e1a5ad28c9bf32b9570d6e1bedae77917866cd5d92aea4ef9271905ef549' }, ExecutionStrategies: { + EthRelayer: '0x72a0e53450c9c297225042d26b05ad62bf417c33ea30775e663538c0a29143a', NoExecutionSimpleMajority: '0x5327bdc6522d531b7770cd51aa641fb91c280a30cdece29edbf9edd970167f6' } } diff --git a/packages/sx.js/src/types/networkConfig.ts b/packages/sx.js/src/types/networkConfig.ts index 9e58b430e..dea7b4146 100644 --- a/packages/sx.js/src/types/networkConfig.ts +++ b/packages/sx.js/src/types/networkConfig.ts @@ -65,6 +65,7 @@ export type NetworkConfig = { spaceFactory: string; masterSpace: string; starknetCommit: string; + starknetCore: string; herodotusAccumulatesChainId: number; authenticators: { [key: string]: @@ -90,7 +91,11 @@ export type NetworkConfig = { export type EvmNetworkConfig = Omit< NetworkConfig, - 'eip712ChainId' | 'spaceFactory' | 'starknetCommit' | 'herodotusAccumulatesChainId' + | 'eip712ChainId' + | 'spaceFactory' + | 'starknetCommit' + | 'starknetCore' + | 'herodotusAccumulatesChainId' > & { eip712ChainId: number; proxyFactory: string;