Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC: Create (and fund) Subaccounts #4456

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

PoC: Create (and fund) Subaccounts #4456

wants to merge 5 commits into from

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Oct 31, 2024

⚠️ This is demonstrative and adheres to no design/plan. It implements the key logic to create (and fund) a Subaccount by means of a new transaction flow and certainly has bugs.

What it solves

We want to make the deployment and usage of Subaccounts easier. Currently the methodology behind creating (and funding) a Subaccount is complex.

This adds a new transaction flow (accessible via a temporary button in the sidebar) to create (and fund) a Subaccount in one transaction.

How this PR fixes it

A new button located in the sidebar opens a flow where you can name and select the desired assets to fund a Subaccount with. After selection, a (batch) transaction achieving this can be queued/executed.

How to test it

  1. Open a Safe and observe the new "Create Subaccount" button in the sidebar.
  2. Following the flow with a variety of (not) funding should create (and fund) a Subaccount successfully.

Screenshots

image

image

image

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

@iamacook iamacook self-assigned this Oct 31, 2024
Copy link

Copy link

github-actions bot commented Oct 31, 2024

Copy link

github-actions bot commented Oct 31, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
73.36% (-0.24% 🔻)
13730/18716
🔴 Branches
51.25% (-0.17% 🔻)
3322/6482
🔴 Functions
56.67% (-0.48% 🔻)
1989/3510
🟡 Lines
75.04% (-0.27% 🔻)
12493/16649
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / index.tsx
55.56% 0% 0% 55.56%
🔴
... / ReviewSubaccount.tsx
36.84% 0% 0% 36.84%
🔴
... / create-subaccount-tx.ts
22.73% 0% 0% 22.73%
🔴
... / SetupSubaccount.tsx
38.78% 25% 11.11% 39.58%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / index.tsx
52.17% (-2.83% 🔻)
0% 0%
54.55% (-3.35% 🔻)

Test suite run success

1584 tests passing in 210 suites.

Report generated by 🧪jest coverage report action from 1f75787

Copy link

github-actions bot commented Oct 31, 2024

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 1.16 MB (🟡 +174.16 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Eighteen Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/apps 47.15 KB (🟢 -1.28 KB) 1.2 MB
/apps/custom 38.78 KB (🟢 -1.28 KB) 1.2 MB
/apps/open 51.06 KB (🟢 -4.13 KB) 1.21 MB
/balances 38.14 KB (🟢 -133 B) 1.2 MB
/home 57.64 KB (🟢 -1.88 KB) 1.21 MB
/new-safe/advanced-create 22.95 KB (🟢 -12.03 KB) 1.18 MB
/new-safe/create 22.21 KB (🟢 -12.03 KB) 1.18 MB
/new-safe/load 5.18 KB (🟢 -9.59 KB) 1.16 MB
/settings/environment-variables 8.87 KB (🟢 -304 B) 1.17 MB
/settings/notifications 26.88 KB (🟢 -176 B) 1.18 MB
/stake 591 B (🟢 -6 B) 1.16 MB
/swap 727 B (🟢 -6 B) 1.16 MB
/transactions 61.44 KB (🟢 -12.26 KB) 1.22 MB
/transactions/history 61.4 KB (🟢 -12.26 KB) 1.22 MB
/transactions/messages 34.23 KB (🟢 -4.98 KB) 1.19 MB
/transactions/msg 24.56 KB (🟢 -4.98 KB) 1.18 MB
/transactions/queue 27.78 KB (🟢 -3.53 KB) 1.19 MB
/transactions/tx 17.56 KB (🟢 -3.53 KB) 1.18 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link
Member

@schmanu schmanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking and working great 🔥
I added some comments regarding multichain compatibility

Feature wise:
I think we could already add a new page on e.g. route /subaccounts which fetches and lists all SubAccounts / owned Safes of the currently opened Safe and simply offers links to open those.
We could also include the Create button there.

params: SetupSubaccountForm
onSubmit: (params: SetupSubaccountForm) => void
}) {
const fallbackName = useMnemonicSafeName()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea:
Maybe the fallbackName should somehow relate to the current Safe's name if one is set?
E.g. If the Safe is called "Bob's Safe" we call it something like "Bob's Safe - Subaccount 1"

}
}, [safeVersion, safeAddress])

const [predictedSafeAddress] = useAsync(async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should display this address somewhere.
Otherwise it will be hard to verify that the target of the transactions that transfer assets is correct.

const { balances } = useBalances()
const safeVersion = getLatestSafeVersion(chain)

const [safeAccountConfig] = useAsync(async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a helper createNewUndeployedSafeWithoutSalt which will end up with SafeAccount configs that create multichain compatible Safes.

It is not compatible with the core-sdk though. So it comes with its own methods to deploy / predict the address:

  • predictAddressBasedOnReplayData
  • createNewSafe

There is a new version of the protocol-kit that could allow us to get rid of this workaround but it contains multiple breaking changes.

@iamacook
Copy link
Member Author

iamacook commented Nov 1, 2024

Looking and working great 🔥 I added some comments regarding multichain compatibility

Thank you for the thorough review (I agree with everything). Since this is a PoC and subject to change, I’ll leave your comments as unresolved for the time being and reference them when we plan this out properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants