From 1f85ac6e4f9769e07a8d76c51a135fb1e2a893f0 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Mon, 16 Dec 2024 12:44:56 +0100 Subject: [PATCH 1/5] feat: add controls and logic --- packages/core-cairo/src/account.ts | 33 +++++++++++++++++++- packages/core-cairo/src/generate/account.ts | 1 + packages/ui/src/cairo/AccountControls.svelte | 8 +++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/core-cairo/src/account.ts b/packages/core-cairo/src/account.ts index bfbeaca2..91c0a0dd 100644 --- a/packages/core-cairo/src/account.ts +++ b/packages/core-cairo/src/account.ts @@ -17,6 +17,7 @@ export const defaults: Required = { declare: true, deploy: true, pubkey: true, + outsideExecution: false, upgradeable: commonDefaults.upgradeable, info: commonDefaults.info } as const; @@ -31,6 +32,7 @@ export interface AccountOptions extends CommonOptions { declare?: boolean; deploy?: boolean; pubkey?: boolean; + outsideExecution?: boolean; } function withDefaults(opts: AccountOptions): Required { @@ -39,7 +41,8 @@ function withDefaults(opts: AccountOptions): Required { ...withCommonDefaults(opts), declare: opts.declare ?? defaults.declare, deploy: opts.deploy ?? defaults.deploy, - pubkey: opts.pubkey ?? defaults.pubkey + pubkey: opts.pubkey ?? defaults.pubkey, + outsideExecution: opts.outsideExecution ?? defaults.outsideExecution } } @@ -79,6 +82,10 @@ export function buildAccount(opts: AccountOptions): Contract { } } + if (allOpts.outsideExecution) { + addOutsideExecution(c); + } + setAccountUpgradeable(c, allOpts.upgradeable, allOpts.type); setInfo(c, allOpts.info); @@ -131,6 +138,11 @@ function addPublicKey(c: ContractBuilder, accountType: Account) { }); } +function addOutsideExecution(c: ContractBuilder) { + c.addUseClause('openzeppelin::account::extensions', 'SRC9Component'); + c.addComponent(components.SRC9Component, [], true); +} + function addAccountMixin(c: ContractBuilder, accountType: Account) { const accountMixinImpl = accountType === 'stark' ? 'AccountMixinImpl' : 'EthAccountMixinImpl'; const [baseComponent, componentType] = getBaseCompAndCompType(accountType); @@ -182,4 +194,23 @@ const components = defineComponents( { value: 'EthAccountComponent::InternalImpl', }] }, + SRC9Component: { + path: 'openzeppelin::account::extensions', + substorage: { + name: 'src9', + type: 'SRC9Component::Storage', + }, + event: { + name: 'SRC9Event', + type: 'SRC9Component::Event', + }, + impls: [{ + name: 'OutsideExecutionV2Impl', + value: 'SRC9Component::OutsideExecutionV2Impl', + }, { + name: 'OutsideExecutionInternalImpl', + embed: false, + value: 'SRC9Component::InternalImpl', + }] + } }); diff --git a/packages/core-cairo/src/generate/account.ts b/packages/core-cairo/src/generate/account.ts index aeca5c76..175ba8df 100644 --- a/packages/core-cairo/src/generate/account.ts +++ b/packages/core-cairo/src/generate/account.ts @@ -11,6 +11,7 @@ const blueprint = { declare: booleans, deploy: booleans, pubkey: booleans, + outsideExecution: booleans, upgradeable: upgradeableOptions, info: infoOptions, }; diff --git a/packages/ui/src/cairo/AccountControls.svelte b/packages/ui/src/cairo/AccountControls.svelte index faf3d829..c5aaa7db 100644 --- a/packages/ui/src/cairo/AccountControls.svelte +++ b/packages/ui/src/cairo/AccountControls.svelte @@ -51,6 +51,14 @@

Features

+ +