├── public ├── favicon.ico ├── logo192.png ├── logo512.png ├── robots.txt ├── manifest.json └── index.html ├── src ├── assets │ ├── intro-chip.png │ ├── intro-chip.webm │ ├── web3Auth_logo.png │ ├── safe-header-logo.svg │ ├── safe-info-logo-light.svg │ ├── safe-info-logo-dark.svg │ └── safe-logo.svg ├── models │ ├── erc20token.ts │ └── chain.ts ├── react-app-env.d.ts ├── utils │ ├── isMoneriumRedirect.ts │ ├── getChain.ts │ ├── isContractAddress.ts │ ├── getERC20Info.ts │ ├── getMoneriumInfo.ts │ └── snippets.ts ├── index.tsx ├── setupTests.ts ├── App.test.tsx ├── components │ ├── providers │ │ └── Providers.tsx │ ├── styles.tsx │ ├── amount-label │ │ └── AmountLabel.tsx │ ├── monerium │ │ ├── MoneriumChainWarning.tsx │ │ ├── MoneriumDeploySafeAccount.tsx │ │ └── MoneriumInfo.tsx │ ├── chain-label │ │ └── ChainLabel.tsx │ ├── code │ │ └── Code.tsx │ ├── authenticate-message │ │ └── AuthenticateMessage.tsx │ ├── safe-core-info │ │ └── SafeCoreInfo.tsx │ ├── chain-selector │ │ └── ChainSelector.tsx │ ├── safes-owned-selector │ │ └── SafesOwnedSelector.tsx │ ├── connected-wallet-label │ │ └── ConnectedWalletLabel.tsx │ ├── header │ │ └── Header.tsx │ ├── safe-account │ │ └── SafeAccount.tsx │ ├── address-label │ │ └── AddressLabel.tsx │ ├── nav-menu │ │ └── NavMenu.tsx │ ├── gelato-task-status-label │ │ └── GelatoTaskStatusLabel.tsx │ └── safe-info │ │ └── SafeInfo.tsx ├── hooks │ ├── useMemoizedAddressLabel.ts │ ├── useLocalStorageState.tsx │ ├── useMemoizedAmountLabel.ts │ ├── usePolling.tsx │ └── useApi.tsx ├── api │ └── getSafeInfo.ts ├── store │ ├── themeContext.tsx │ └── accountAbstractionContext.tsx ├── pages │ ├── Intro.tsx │ ├── AuthKitDemo.tsx │ ├── RelayKitDemo.tsx │ └── OnRampKitDemo.tsx ├── constants │ ├── chains.ts │ └── erc20ABI.json └── App.tsx ├── .prettierrc.json ├── example.env ├── .gitignore ├── tsconfig.json ├── README.md ├── config-overrides.js ├── package.json └── LICENSE /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5afe/safe-core-sdk-demo/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5afe/safe-core-sdk-demo/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5afe/safe-core-sdk-demo/HEAD/public/logo512.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/assets/intro-chip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5afe/safe-core-sdk-demo/HEAD/src/assets/intro-chip.png -------------------------------------------------------------------------------- /src/assets/intro-chip.webm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5afe/safe-core-sdk-demo/HEAD/src/assets/intro-chip.webm -------------------------------------------------------------------------------- /src/assets/web3Auth_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5afe/safe-core-sdk-demo/HEAD/src/assets/web3Auth_logo.png -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "semi": false, 4 | "singleQuote": true, 5 | "trailingComma": "none" 6 | } 7 | -------------------------------------------------------------------------------- /src/models/erc20token.ts: -------------------------------------------------------------------------------- 1 | export type ERC20Token = { 2 | address: string 3 | symbol: string 4 | decimals: number 5 | balance?: string 6 | } 7 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module '*.webm' { 4 | const src: string 5 | export default src 6 | } 7 | -------------------------------------------------------------------------------- /src/utils/isMoneriumRedirect.ts: -------------------------------------------------------------------------------- 1 | const isMoneriumRedirect = () => { 2 | const authCode = new URLSearchParams(window.location.search).get('code') 3 | 4 | return !!authCode 5 | } 6 | 7 | export default isMoneriumRedirect 8 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App' 4 | 5 | const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement) 6 | 7 | root.render() 8 | -------------------------------------------------------------------------------- /src/utils/getChain.ts: -------------------------------------------------------------------------------- 1 | import chains from 'src/constants/chains' 2 | 3 | const getChain = (chainId?: string) => { 4 | const chain = chains.find((chain) => chain.id === chainId) 5 | 6 | return chain 7 | } 8 | 9 | export default getChain 10 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom' 6 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { render, screen } from '@testing-library/react' 3 | import App from './App' 4 | 5 | test('renders learn react link', () => { 6 | render() 7 | const linkElement = screen.getByText(/learn react/i) 8 | expect(linkElement).toBeInTheDocument() 9 | }) 10 | -------------------------------------------------------------------------------- /example.env: -------------------------------------------------------------------------------- 1 | REACT_APP_STRIPE_BACKEND_BASE_URL=https://aa-stripe.safe.global 2 | 3 | REACT_APP_STRIPE_PUBLIC_KEY=pk_test_51MZbmZKSn9ArdBimSyl5i8DqfcnlhyhJHD8bF2wKrGkpvNWyPvBAYtE211oHda0X3Ea1n4e9J9nh2JkpC7Sxm5a200Ug9ijfoO 4 | 5 | # see https://monerium.dev/docs/getting-started/create-app 6 | REACT_APP_MONERIUM_CLIENT_ID= 7 | REACT_APP_MONERIUM_REDIRECT_URL= -------------------------------------------------------------------------------- /src/utils/isContractAddress.ts: -------------------------------------------------------------------------------- 1 | import { Provider } from 'ethers' 2 | 3 | const isContractAddress = async (address: string, provider?: Provider): Promise => { 4 | try { 5 | const code = await provider?.getCode(address) 6 | 7 | return code !== '0x' 8 | } catch (error) { 9 | return false 10 | } 11 | } 12 | 13 | export default isContractAddress 14 | -------------------------------------------------------------------------------- /src/components/providers/Providers.tsx: -------------------------------------------------------------------------------- 1 | import { ThemeProvider } from 'src/store/themeContext' 2 | import { AccountAbstractionProvider } from 'src/store/accountAbstractionContext' 3 | 4 | const Providers = ({ children }: { children: JSX.Element }) => { 5 | return ( 6 | 7 | {children} 8 | 9 | ) 10 | } 11 | 12 | export default Providers 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | .env 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | 26 | # Yalc files 27 | .yalc 28 | yalc.lock 29 | 30 | # Local Netlify folder 31 | .netlify 32 | -------------------------------------------------------------------------------- /src/hooks/useMemoizedAddressLabel.ts: -------------------------------------------------------------------------------- 1 | import { useMemo } from 'react' 2 | 3 | const CHAR_DISPLAYED = 6 4 | 5 | const useMemoizedAddressLabel = (address: string) => { 6 | const addressLabel = useMemo(() => { 7 | if (address) { 8 | const firstPart = address.slice(0, CHAR_DISPLAYED) 9 | const lastPart = address.slice(address.length - CHAR_DISPLAYED) 10 | 11 | return `${firstPart}...${lastPart}` 12 | } 13 | 14 | return address 15 | }, [address]) 16 | 17 | return addressLabel 18 | } 19 | 20 | export default useMemoizedAddressLabel 21 | -------------------------------------------------------------------------------- /src/models/chain.ts: -------------------------------------------------------------------------------- 1 | type Chain = { 2 | id: string 3 | token: string 4 | rpcUrl: string 5 | shortName: string 6 | label: string 7 | color?: string 8 | icon?: string 9 | blockExplorerUrl: string 10 | transactionServiceUrl?: string 11 | isStripePaymentsEnabled: boolean // only available in Mumbai chain 12 | isMoneriumPaymentsEnabled: boolean // only available in Goerli chain 13 | faucetUrl?: string 14 | supportedErc20Tokens?: string[] // erc20 token contract addresses that can be used to pay transaction fees 15 | } 16 | 17 | export default Chain 18 | -------------------------------------------------------------------------------- /src/components/styles.tsx: -------------------------------------------------------------------------------- 1 | import styled from '@emotion/styled' 2 | import Box from '@mui/material/Box' 3 | import { Theme } from '@mui/material' 4 | 5 | export const ConnectContainer = styled(Box)<{ 6 | theme?: Theme 7 | }>( 8 | ({ theme }) => ` 9 | 10 | border-radius: 10px; 11 | border: 1px solid ${theme.palette.border.light}; 12 | padding: 50px; 13 | ` 14 | ) 15 | 16 | export const ConnectedContainer = styled(Box)<{ 17 | theme?: Theme 18 | }>( 19 | ({ theme }) => ` 20 | 21 | border-radius: 10px; 22 | border: 1px solid ${theme.palette.border.light}; 23 | padding: 40px 32px; 24 | ` 25 | ) 26 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "Safe AA POC", 3 | "name": "Safe Account Abstraction Sample App", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/components/amount-label/AmountLabel.tsx: -------------------------------------------------------------------------------- 1 | import Tooltip from '@mui/material/Tooltip' 2 | 3 | import useMemoizedAmountLabel from 'src/hooks/useMemoizedAmountLabel' 4 | 5 | type AmountLabelType = { 6 | amount: string 7 | tokenSymbol: string 8 | decimalsDisplayed?: number 9 | } 10 | 11 | function AmountLabel({ amount, tokenSymbol, decimalsDisplayed }: AmountLabelType) { 12 | const amountLabel = useMemoizedAmountLabel(amount, tokenSymbol, decimalsDisplayed) 13 | 14 | return ( 15 | 16 | {amountLabel} 17 | 18 | ) 19 | } 20 | 21 | export default AmountLabel 22 | -------------------------------------------------------------------------------- /src/components/monerium/MoneriumChainWarning.tsx: -------------------------------------------------------------------------------- 1 | import Link from '@mui/material/Link' 2 | import Typography from '@mui/material/Typography' 3 | 4 | type MoneriumChainWarningProps = { 5 | onUpdateChain: () => void 6 | } 7 | 8 | function MoneriumChainWarning({ onUpdateChain }: MoneriumChainWarningProps) { 9 | return ( 10 | 11 | The Monerium payments are only enabled in Goerli chain.{' '} 12 | 13 | Update the chosen chain 14 | {' '} 15 | 16 | ) 17 | } 18 | 19 | export default MoneriumChainWarning 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx", 22 | "baseUrl": "." 23 | }, 24 | "include": [ 25 | "src" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /src/hooks/useLocalStorageState.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react' 2 | 3 | type useLocalStorageStateReturnType = [ 4 | value: T, 5 | setValue: React.Dispatch> 6 | ] 7 | 8 | function useLocalStorageState( 9 | key: string, 10 | initialValue: T 11 | ): useLocalStorageStateReturnType { 12 | const reactState = useState(() => (localStorage.getItem(key) as T) || initialValue) 13 | 14 | const [value] = reactState 15 | 16 | // we also update the localstorage 17 | useEffect(() => { 18 | if (key) { 19 | localStorage.setItem(key, value) 20 | } 21 | }, [value, key]) 22 | 23 | return reactState 24 | } 25 | 26 | export default useLocalStorageState 27 | -------------------------------------------------------------------------------- /src/components/chain-label/ChainLabel.tsx: -------------------------------------------------------------------------------- 1 | import { styled } from '@mui/material/styles' 2 | 3 | import Chain from 'src/models/chain' 4 | 5 | type ChainLabelProps = { 6 | chain: Chain 7 | } 8 | 9 | const ChainLabel = ({ chain }: ChainLabelProps) => { 10 | const { label, color } = chain 11 | return 12 | } 13 | 14 | export default ChainLabel 15 | 16 | const Label = styled('span')( 17 | ({ theme, color }) => ` 18 | border-radius: 4px; 19 | font-size: 12px; 20 | padding: 0px 12px; 21 | border: 1px solid #fff; 22 | background-color: ${color}; 23 | color: ${theme.palette.getContrastText(color as string)}; 24 | text-align: center; 25 | width: 100%; 26 | ` 27 | ) 28 | -------------------------------------------------------------------------------- /src/components/code/Code.tsx: -------------------------------------------------------------------------------- 1 | import { CodeBlock, atomOneDark } from 'react-code-blocks' 2 | import Box from '@mui/material/Box' 3 | import { Theme } from '@mui/material' 4 | import styled from '@emotion/styled' 5 | 6 | type CodeType = { 7 | text: string 8 | language: string 9 | } 10 | 11 | function Code({ text, language }: CodeType) { 12 | return ( 13 | 14 | 15 | 16 | ) 17 | } 18 | 19 | export default Code 20 | 21 | const CodeContainer = styled(Box)<{ 22 | theme?: Theme 23 | }>( 24 | ({ theme }) => ` 25 | border-radius: 10px; 26 | border: 1px solid ${theme.palette.border.light}; 27 | padding: 16px; 28 | ` 29 | ) 30 | -------------------------------------------------------------------------------- /src/components/authenticate-message/AuthenticateMessage.tsx: -------------------------------------------------------------------------------- 1 | import Typography from '@mui/material/Typography' 2 | import Button from '@mui/material/Button' 3 | import { ConnectedContainer } from 'src/components/styles' 4 | 5 | type AuthenticateMessageProps = { 6 | message: string 7 | onConnect: () => void 8 | } 9 | 10 | function AuthenticateMessage({ message, onConnect }: AuthenticateMessageProps) { 11 | return ( 12 | 20 | 21 | {message} 22 | 23 | 24 | 27 | 28 | ) 29 | } 30 | 31 | export default AuthenticateMessage 32 | -------------------------------------------------------------------------------- /src/hooks/useMemoizedAmountLabel.ts: -------------------------------------------------------------------------------- 1 | import { useMemo } from 'react' 2 | 3 | const DEFAULT_DECIMALS_DISPLAYED = 4 4 | 5 | type useMemoizedAmountLabelType = ( 6 | amount: string, 7 | tokenSymbol: string, 8 | decimalsDisplayed?: number 9 | ) => string 10 | 11 | const useMemoizedAmountLabel: useMemoizedAmountLabelType = ( 12 | amount, 13 | tokenSymbol, 14 | decimalsDisplayed = DEFAULT_DECIMALS_DISPLAYED 15 | ) => { 16 | const amountLabel = useMemo(() => { 17 | if (amount) { 18 | const [integerPart, decimalPart] = amount.split('.') 19 | 20 | const hasDecimal = !!decimalPart 21 | const decimalLabel = hasDecimal ? `.${decimalPart.slice(0, decimalsDisplayed)}` : '' 22 | 23 | return `${integerPart}${decimalLabel} ${tokenSymbol}` 24 | } 25 | 26 | return `0 ${tokenSymbol}` 27 | }, [amount, tokenSymbol, decimalsDisplayed]) 28 | 29 | return amountLabel 30 | } 31 | 32 | export default useMemoizedAmountLabel 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Account Abstraction demo app 2 | 3 | [The Safe{Core} SDK](https://github.com/safe-global/safe-core-sdk) allows builders to add account abstraction functionality into their apps. This demo is an example on how to use our different packages (Auth Kit, OnRamp Kit & Relay Kit). 4 | 5 | See the [Safe{Core} Account Abstraction SDK Docs](https://docs.safe.global/learn/safe-core-account-abstraction-sdk) for more details. 6 | 7 | ## Installation 8 | 9 | To run this project locally: 10 | 11 | Install deps: 12 | 13 | ```bash 14 | yarn install 15 | ``` 16 | 17 | Create a `.env` file (see `example.env`) 18 | 19 | ``` 20 | REACT_APP_STRIPE_BACKEND_BASE_URL=https://aa-stripe.safe.global 21 | REACT_APP_STRIPE_PUBLIC_KEY=pk_test_51MZbmZKSn9ArdBimSyl5i8DqfcnlhyhJHD8bF2wKrGkpvNWyPvBAYtE211oHda0X3Ea1n4e9J9nh2JkpC7Sxm5a200Ug9ijfoO 22 | REACT_APP_MONERIUM_CLIENT_ID={YOUR_MONERIUM_CLIENT_ID} 23 | REACT_APP_MONERIUM_REDIRECT_URL={YOUR_MONERIUM_REDIRECT_URL} 24 | ``` 25 | 26 | Run the demo App: 27 | 28 | ```bash 29 | yarn start 30 | ``` 31 | -------------------------------------------------------------------------------- /src/api/getSafeInfo.ts: -------------------------------------------------------------------------------- 1 | import axios, { RawAxiosRequestConfig } from 'axios' 2 | import { ethers } from 'ethers' 3 | 4 | import getChain from 'src/utils/getChain' 5 | 6 | export type SafeInfoType = { 7 | address: string 8 | nonce: number 9 | threshold: number 10 | owners: string[] 11 | } 12 | 13 | const getSafeInfo = async ( 14 | safeAddress: string, 15 | connectedChainId: string, 16 | options?: RawAxiosRequestConfig 17 | ): Promise => { 18 | const chain = getChain(connectedChainId) 19 | 20 | const address = ethers.getAddress(safeAddress) 21 | 22 | // Mumbai has no transaction service because it is not part of our official UI https://app.safe.global/ 23 | if (!chain?.transactionServiceUrl) { 24 | throw new Error(`No transaction service for ${chain?.label} chain`) 25 | } 26 | 27 | const url = `${chain?.transactionServiceUrl}/api/v1/safes/${address}/` 28 | 29 | const { data: safeInfo } = await axios.get(url, options) 30 | 31 | return safeInfo 32 | } 33 | 34 | export default getSafeInfo 35 | -------------------------------------------------------------------------------- /src/components/monerium/MoneriumDeploySafeAccount.tsx: -------------------------------------------------------------------------------- 1 | import Link from '@mui/material/Link' 2 | import Typography from '@mui/material/Typography' 3 | 4 | type MoneriumDeploySafeAccountProps = { 5 | isSafeDeployed: boolean 6 | onDeploy: () => void 7 | } 8 | 9 | function MoneriumDeploySafeAccount({ isSafeDeployed, onDeploy }: MoneriumDeploySafeAccountProps) { 10 | if (isSafeDeployed) { 11 | return ( 12 | 13 | You can login with Monerium and link the selected Safe account{''} 14 | 15 | ) 16 | } 17 | 18 | return ( 19 | 20 | The Safe account is not deployed yet. To use "Login with Monerium", deploy the Safe first by 21 | sending your first transaction using the{' '} 22 | 23 | Relay Kit 24 | {' '} 25 | 26 | ) 27 | } 28 | 29 | export default MoneriumDeploySafeAccount 30 | -------------------------------------------------------------------------------- /src/hooks/usePolling.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react' 2 | 3 | type callbackType = () => Promise 4 | 5 | type usePollingHookReturnValue = T | undefined 6 | 7 | const DEFAULT_POLLING_TIME = 3_000 // 3 secs as default polling 8 | 9 | function usePolling( 10 | callback: callbackType, 11 | pollingTime = DEFAULT_POLLING_TIME 12 | ): usePollingHookReturnValue { 13 | const [data, setData] = useState() 14 | 15 | useEffect(() => { 16 | async function performCall() { 17 | try { 18 | const data = await callback() 19 | setData(data) 20 | } catch (exception) { 21 | console.log('polling error: ', exception) 22 | } 23 | } 24 | 25 | // perform the call 26 | performCall() 27 | 28 | // set the inteval to perform the polling 29 | const intervalId = setInterval(() => { 30 | performCall() 31 | }, pollingTime) 32 | 33 | return () => { 34 | clearInterval(intervalId) 35 | } 36 | }, [callback, pollingTime]) 37 | 38 | return data 39 | } 40 | 41 | export default usePolling 42 | -------------------------------------------------------------------------------- /config-overrides.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack') 2 | 3 | module.exports = function override(config) { 4 | const fallback = config.resolve.fallback || {} 5 | Object.assign(fallback, { 6 | crypto: require.resolve('crypto-browserify'), 7 | stream: require.resolve('stream-browserify'), 8 | assert: require.resolve('assert'), 9 | http: require.resolve('stream-http'), 10 | https: require.resolve('https-browserify'), 11 | os: require.resolve('os-browserify'), 12 | url: require.resolve('url'), 13 | zlib: require.resolve('browserify-zlib') 14 | }) 15 | config.resolve.fallback = fallback 16 | config.plugins = (config.plugins || []).concat([ 17 | new webpack.ProvidePlugin({ 18 | process: 'process/browser', 19 | Buffer: ['buffer', 'Buffer'] 20 | }) 21 | ]) 22 | config.ignoreWarnings = [/Failed to parse source map/] 23 | config.module.rules.push({ 24 | test: /\.(js|mjs|jsx)$/, 25 | enforce: 'pre', 26 | loader: require.resolve('source-map-loader'), 27 | resolve: { 28 | fullySpecified: false 29 | } 30 | }) 31 | return config 32 | } 33 | -------------------------------------------------------------------------------- /src/utils/getERC20Info.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import erc20ABI from 'src/constants/erc20ABI.json' 3 | import { ERC20Token } from 'src/models/erc20token' 4 | 5 | /** 6 | * Retrieve infos for an ERC20 token by its contract address. 7 | * @param erc20Address ERC20 token contract address 8 | * @param provider web3 provider 9 | * @param accountAddress address to get the ERC20 token balance for 10 | * @returns the infos for the given token or undefined if no valid ERC20 address was provided 11 | */ 12 | export const getERC20Info = async ( 13 | erc20Address: string, 14 | provider: ethers.BrowserProvider, 15 | accountAddress?: string 16 | ): Promise => { 17 | if (erc20Address === ethers.ZeroAddress) { 18 | return undefined 19 | } 20 | 21 | const contract = new ethers.Contract(erc20Address, erc20ABI, provider) 22 | 23 | const [balance, decimals, symbol] = await Promise.all([ 24 | accountAddress != null ? contract.balanceOf(accountAddress) : Promise.resolve(), 25 | contract.decimals(), 26 | contract.symbol() 27 | ]) 28 | 29 | return { address: erc20Address, balance, decimals, symbol } 30 | } 31 | -------------------------------------------------------------------------------- /src/utils/getMoneriumInfo.ts: -------------------------------------------------------------------------------- 1 | import { AuthContext, Profile, Balances, Balance, Currency } from '@monerium/sdk' 2 | 3 | export type MoneriumInfo = { 4 | name: string 5 | email: string 6 | iban: string 7 | balance?: string 8 | } 9 | 10 | function getAmountForCurrency(balances?: Balances): string { 11 | if (!balances) return '0' 12 | 13 | return ( 14 | balances.balances.find((balance: Balance) => balance.currency === Currency.eur)?.amount ?? '0' 15 | ) 16 | } 17 | 18 | function getIban(profile: Profile, safeAddress: string) { 19 | return ( 20 | profile.accounts.find((account) => account.address === safeAddress && account.iban)?.iban ?? '' 21 | ) 22 | } 23 | 24 | function getMoneriumInfo( 25 | safeAddress: string, 26 | authContext: AuthContext, 27 | profile: Profile, 28 | balances: Balances | Balances[] 29 | ): MoneriumInfo { 30 | return { 31 | name: authContext.name, 32 | email: authContext.name, 33 | iban: getIban(profile, safeAddress), 34 | balance: Array.isArray(balances) 35 | ? getAmountForCurrency(balances.find((balance: Balances) => balance.address === safeAddress)) 36 | : getAmountForCurrency(balances) 37 | } 38 | } 39 | 40 | export default getMoneriumInfo 41 | -------------------------------------------------------------------------------- /src/hooks/useApi.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react' 2 | 3 | type apiCallParam = (signal: AbortSignal) => Promise 4 | 5 | type useApiHookReturnValue = { 6 | isLoading: boolean 7 | data?: T 8 | } 9 | 10 | function useApi(apiCall: apiCallParam, pollingTime?: number): useApiHookReturnValue { 11 | const [isLoading, setIsLoading] = useState(true) 12 | const [data, setData] = useState() 13 | 14 | useEffect(() => { 15 | const abortController = new AbortController() 16 | 17 | async function performApiCall() { 18 | try { 19 | setIsLoading(true) 20 | const data = await apiCall(abortController.signal) 21 | setData(data) 22 | } catch (exception) { 23 | setData(undefined) 24 | } finally { 25 | setIsLoading(false) 26 | } 27 | } 28 | 29 | let intervalId: NodeJS.Timeout 30 | 31 | if (pollingTime) { 32 | intervalId = setInterval(() => { 33 | performApiCall() 34 | }, pollingTime) 35 | } 36 | 37 | performApiCall() 38 | 39 | return () => { 40 | abortController.abort() 41 | clearInterval(intervalId) 42 | } 43 | }, [apiCall, pollingTime]) 44 | 45 | return { 46 | isLoading, 47 | data 48 | } 49 | } 50 | 51 | export default useApi 52 | -------------------------------------------------------------------------------- /src/components/safe-core-info/SafeCoreInfo.tsx: -------------------------------------------------------------------------------- 1 | import Link from '@mui/material/Link' 2 | import Stack from '@mui/material/Stack' 3 | import Typography from '@mui/material/Typography' 4 | 5 | import introImage from 'src/assets/intro-chip.png' 6 | import introVideo from 'src/assets/intro-chip.webm' 7 | 8 | const SafeCoreInfo = () => { 9 | return ( 10 |
11 | {/* video loop */} 12 | 16 | 17 | {/* Links */} 18 | 19 | Learn more about the SDK: 20 | 21 | 22 | 23 | 24 | GitHub 25 | 26 | 27 | 28 | Documentation 29 | 30 | 31 | 32 | Discord 33 | 34 | 35 |
36 | ) 37 | } 38 | 39 | export default SafeCoreInfo 40 | -------------------------------------------------------------------------------- /src/components/monerium/MoneriumInfo.tsx: -------------------------------------------------------------------------------- 1 | import Typography from '@mui/material/Typography' 2 | import Button from '@mui/material/Button' 3 | import Tooltip from '@mui/material/Tooltip' 4 | import LogoutIcon from '@mui/icons-material/LogoutRounded' 5 | 6 | import { MoneriumInfo as Info } from 'src/utils/getMoneriumInfo' 7 | 8 | type MoneriumInfoProps = { 9 | moneriumInfo: Info 10 | onLogout: () => void 11 | } 12 | 13 | function MoneriumInfo({ moneriumInfo, onLogout }: MoneriumInfoProps) { 14 | return ( 15 | <> 16 | 17 | 🔥 {moneriumInfo.name}, you are logged in using Monerium !! 18 | 19 | 20 | Your account{' '} 21 | 22 | {moneriumInfo.iban.replace(/\s/g, '')} 23 | {' '} 24 | balance is{' '} 25 | 26 | {moneriumInfo.balance + 'EUR'} 27 | 28 | 29 | 30 | 33 | 34 | 35 | ) 36 | } 37 | 38 | export default MoneriumInfo 39 | -------------------------------------------------------------------------------- /src/assets/safe-header-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/components/chain-selector/ChainSelector.tsx: -------------------------------------------------------------------------------- 1 | import FormControl from '@mui/material/FormControl' 2 | import MenuItem from '@mui/material/MenuItem' 3 | import Select, { SelectChangeEvent } from '@mui/material/Select' 4 | 5 | import ChainLabel from 'src/components/chain-label/ChainLabel' 6 | import chains from 'src/constants/chains' 7 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 8 | 9 | const ChainSelector = () => { 10 | const { chain, setChainId } = useAccountAbstraction() 11 | 12 | return ( 13 |
14 | 15 | 34 | 35 |
36 | ) 37 | } 38 | 39 | export default ChainSelector 40 | -------------------------------------------------------------------------------- /src/assets/safe-info-logo-light.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/assets/safe-info-logo-dark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/components/safes-owned-selector/SafesOwnedSelector.tsx: -------------------------------------------------------------------------------- 1 | import InputLabel from '@mui/material/InputLabel' 2 | import MenuItem from '@mui/material/MenuItem' 3 | import FormControl from '@mui/material/FormControl' 4 | import Select from '@mui/material/Select' 5 | 6 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 7 | 8 | type SafesOwnedSelectorProps = { 9 | safeSelected: string 10 | onSelectSafe: React.Dispatch> 11 | } 12 | 13 | function SafesOwnedSelector({ safeSelected, onSelectSafe }: SafesOwnedSelectorProps) { 14 | const { safes } = useAccountAbstraction() 15 | 16 | const showDerivedSafeAddress = safes.length === 0 17 | 18 | if (showDerivedSafeAddress) { 19 | return null 20 | } 21 | 22 | return ( 23 | 24 | Safes owned 25 | 39 | 40 | ) 41 | } 42 | 43 | export default SafesOwnedSelector 44 | -------------------------------------------------------------------------------- /src/components/connected-wallet-label/ConnectedWalletLabel.tsx: -------------------------------------------------------------------------------- 1 | import Stack from '@mui/material/Stack' 2 | import Typography from '@mui/material/Typography' 3 | import IconButton from '@mui/material/IconButton' 4 | import Tooltip from '@mui/material/Tooltip' 5 | import { styled } from '@mui/material/styles' 6 | import { Theme } from '@mui/material' 7 | import LogoutIcon from '@mui/icons-material/LogoutRounded' 8 | 9 | import AddressLabel from 'src/components/address-label/AddressLabel' 10 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 11 | import authLogo from 'src/assets/web3Auth_logo.png' 12 | 13 | // TODO: rename this to connected owner? 14 | function ConnectedWalletLabel() { 15 | const { isAuthenticated, ownerAddress, logoutWeb3Auth } = useAccountAbstraction() 16 | 17 | if (!isAuthenticated) { 18 | // TODO: ADD NO CONNECTED WALLET LABEL 19 | return null 20 | } 21 | 22 | return ( 23 | 24 | 25 | 26 | 27 | 28 | {ownerAddress && } 29 | 30 | 31 | 32 | {/* logout button */} 33 | 34 | 35 | 36 | 37 | 38 | 39 | ) 40 | } 41 | 42 | export default ConnectedWalletLabel 43 | 44 | const StyledImg = styled('img')` 45 | border-radius: 50%; 46 | ` 47 | 48 | const LogoutIconButton = styled(IconButton)<{ 49 | theme?: Theme 50 | }>( 51 | ({ theme }) => ` 52 | border: 1px solid ${theme.palette.border.main}; 53 | ` 54 | ) 55 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 25 | 26 | React App 27 | 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/store/themeContext.tsx: -------------------------------------------------------------------------------- 1 | import { createContext, useContext, useEffect } from 'react' 2 | import { PaletteMode, Theme } from '@mui/material' 3 | import { ThemeProvider as MUIThemeProvider } from '@mui/material/styles' 4 | import { SafeThemeProvider, useThemeMode } from '@safe-global/safe-react-components' 5 | 6 | import useLocalStorageState from 'src/hooks/useLocalStorageState' 7 | 8 | const STORAGE_KEY_THEME_MODE = 'THEME_MODE_REACT_SERVICE_STATUS_KEY' 9 | 10 | export const DARK_THEME: PaletteMode = 'dark' 11 | export const LIGHT_THEME: PaletteMode = 'light' 12 | 13 | type themeContextValue = { 14 | themeMode: PaletteMode 15 | switchThemeMode: () => void 16 | isDarkTheme: boolean 17 | isLightTheme: boolean 18 | } 19 | 20 | const initialState = { 21 | themeMode: DARK_THEME, 22 | switchThemeMode: () => {}, 23 | isDarkTheme: true, 24 | isLightTheme: false 25 | } 26 | 27 | const themeContext = createContext(initialState) 28 | 29 | const useTheme = () => { 30 | const context = useContext(themeContext) 31 | 32 | if (!context) { 33 | throw new Error('useTheme should be used within a ThemeContext Provider') 34 | } 35 | 36 | return context 37 | } 38 | 39 | const ThemeProvider = ({ children }: { children: JSX.Element }) => { 40 | const [initialThemeMode, setInitialThemeMode] = useLocalStorageState( 41 | STORAGE_KEY_THEME_MODE, // local storage key 42 | DARK_THEME // default value 43 | ) 44 | 45 | const { themeMode, switchThemeMode } = useThemeMode(initialThemeMode) 46 | 47 | const isDarkTheme = themeMode === DARK_THEME 48 | const isLightTheme = themeMode === LIGHT_THEME 49 | 50 | useEffect(() => { 51 | setInitialThemeMode(themeMode) 52 | }, [themeMode, setInitialThemeMode]) 53 | 54 | const state = { 55 | themeMode, 56 | 57 | switchThemeMode, 58 | 59 | isDarkTheme, 60 | isLightTheme 61 | } 62 | 63 | return ( 64 | 65 | 66 | {(safeTheme: Theme) => {children}} 67 | 68 | 69 | ) 70 | } 71 | 72 | export { useTheme, ThemeProvider } 73 | -------------------------------------------------------------------------------- /src/components/header/Header.tsx: -------------------------------------------------------------------------------- 1 | import AppBar from '@mui/material/AppBar' 2 | import Toolbar from '@mui/material/Toolbar' 3 | import Container from '@mui/material/Container' 4 | import Box from '@mui/material/Box' 5 | import Tooltip from '@mui/material/Tooltip' 6 | import IconButton from '@mui/material/IconButton' 7 | import DarkThemeIcon from '@mui/icons-material/Brightness4' 8 | import LightThemeIcon from '@mui/icons-material/Brightness7' 9 | 10 | import ChainLabel from 'src/components/chain-label/ChainLabel' 11 | import safeHeaderLogo from 'src/assets/safe-header-logo.svg' 12 | import { useTheme } from 'src/store/themeContext' 13 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 14 | 15 | type HeaderProps = { 16 | setStep: (newStep: number) => void 17 | } 18 | 19 | function Header({ setStep }: HeaderProps) { 20 | const { switchThemeMode, isDarkTheme } = useTheme() 21 | 22 | const { chain } = useAccountAbstraction() 23 | 24 | return ( 25 | 26 | 27 | 28 | {/* App Logo */} 29 | setStep(0)} // go to Home 32 | id="app-logo-header" 33 | src={safeHeaderLogo} 34 | alt="app logo" 35 | /> 36 | 37 | 38 | {/* chain label */} 39 | {chain && ( 40 | 41 | 42 | 43 | )} 44 | 45 | {/* Switch Theme mode button */} 46 | 47 | 55 | {isDarkTheme ? : } 56 | 57 | 58 | 59 | 60 | 61 | 62 | ) 63 | } 64 | 65 | export default Header 66 | -------------------------------------------------------------------------------- /src/components/safe-account/SafeAccount.tsx: -------------------------------------------------------------------------------- 1 | import { BoxProps } from '@mui/material/Box' 2 | import FormControl from '@mui/material/FormControl' 3 | import MenuItem from '@mui/material/MenuItem' 4 | import Select, { SelectChangeEvent } from '@mui/material/Select' 5 | import Typography from '@mui/material/Typography' 6 | import AddressLabel from 'src/components/address-label/AddressLabel' 7 | import SafeInfo from 'src/components/safe-info/SafeInfo' 8 | 9 | import { InputLabel } from '@mui/material' 10 | import { ConnectedContainer } from 'src/components/styles' 11 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 12 | 13 | function SafeAccount(props: BoxProps) { 14 | const { safeSelected, chainId, safes, setSafeSelected } = useAccountAbstraction() 15 | 16 | return ( 17 | 18 | Safe Account 19 | 20 | 21 | Your Safe (smart contract account) holds and protects your assets. 22 | 23 | 24 | {!!safes && safes.length > 1 && ( 25 | 26 | Select Safe 27 | 53 | 54 | )} 55 | 56 | {/* Safe Info */} 57 | {safeSelected && } 58 | 59 | ) 60 | } 61 | 62 | export default SafeAccount 63 | -------------------------------------------------------------------------------- /src/components/address-label/AddressLabel.tsx: -------------------------------------------------------------------------------- 1 | import Stack from '@mui/material/Stack' 2 | import Tooltip from '@mui/material/Tooltip' 3 | import IconButton from '@mui/material/IconButton' 4 | import OpenInNew from '@mui/icons-material/OpenInNew' 5 | import FileCopyOutlinedIcon from '@mui/icons-material/FileCopyOutlined' 6 | 7 | import useMemoizedAddressLabel from 'src/hooks/useMemoizedAddressLabel' 8 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 9 | 10 | type AddressLabelProps = { 11 | address: string 12 | isTransactionAddress?: boolean 13 | showBlockExplorerLink?: boolean 14 | showCopyIntoClipboardButton?: boolean 15 | } 16 | 17 | const AddressLabel = ({ 18 | address, 19 | isTransactionAddress, 20 | showBlockExplorerLink, 21 | showCopyIntoClipboardButton = true 22 | }: AddressLabelProps) => { 23 | const { chain } = useAccountAbstraction() 24 | 25 | const addressLabel = useMemoizedAddressLabel(address) 26 | 27 | const blockExplorerLink = `${chain?.blockExplorerUrl}/${ 28 | isTransactionAddress ? 'tx' : 'address' 29 | }/${address}` 30 | 31 | return ( 32 | 33 | 34 | {addressLabel} 35 | 36 | 37 | {/* Button to copy into clipboard */} 38 | {showCopyIntoClipboardButton && ( 39 | 44 | navigator?.clipboard?.writeText?.(address)} 46 | size={'small'} 47 | color="inherit" 48 | > 49 | 50 | 51 | 52 | )} 53 | 54 | {/* Button to etherscan */} 55 | {showBlockExplorerLink && blockExplorerLink && ( 56 | 57 | 65 | 66 | 67 | 68 | )} 69 | 70 | ) 71 | } 72 | 73 | export default AddressLabel 74 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "account-abstraction-demo-ui", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/react": "^11.11.1", 7 | "@emotion/styled": "^11.11.0", 8 | "@mui/icons-material": "^5.14.19", 9 | "@mui/material": "^5.14.19", 10 | "@safe-global/account-abstraction-kit-poc": "2.0.0", 11 | "@safe-global/auth-kit": "2.0.0", 12 | "@safe-global/onramp-kit": "2.0.0", 13 | "@safe-global/protocol-kit": "2.0.0", 14 | "@safe-global/relay-kit": "2.0.0", 15 | "@safe-global/safe-react-components": "^2.0.6", 16 | "@stripe/crypto": "^0.0.4", 17 | "@stripe/stripe-js": "^1.52.1", 18 | "@web3auth/safeauth-embed": "^0.0.0", 19 | "axios": "^1.6.2", 20 | "ethers": "^6.9.0", 21 | "react": "^18.2.0", 22 | "react-code-blocks": "^0.1.5", 23 | "react-dom": "^18.2.0", 24 | "react-scripts": "5.0.1" 25 | }, 26 | "resolutions": { 27 | "@ethereumjs/tx": "4.0.2" 28 | }, 29 | "devDependencies": { 30 | "@testing-library/jest-dom": "^5.16.5", 31 | "@testing-library/react": "^13.4.0", 32 | "@testing-library/user-event": "^13.5.0", 33 | "@types/jest": "^27.5.2", 34 | "@types/node": "^18.18.11", 35 | "@types/react": "^18.2.39", 36 | "@types/react-dom": "^18.2.17", 37 | "assert": "^2.0.0", 38 | "browserify-zlib": "^0.2.0 ", 39 | "buffer": "^6.0.3", 40 | "crypto-browserify": "^3.12.0", 41 | "eslint-config-react-app": "^7.0.1", 42 | "https-browserify": "^1.0.0", 43 | "os-browserify": "^0.3.0", 44 | "prettier": "^2.8.8", 45 | "process": "^0.11.10", 46 | "react-app-rewired": "^2.2.1", 47 | "stream-browserify": "^3.0.0", 48 | "stream-http": "^3.2.0", 49 | "typescript": "^4.9.5", 50 | "url": "^0.11.3" 51 | }, 52 | "scripts": { 53 | "start": "react-app-rewired start", 54 | "build": "react-app-rewired build", 55 | "test": "react-app-rewired test", 56 | "format:check": "prettier --check \"*/**/*.{js,jsx,json,md,ts,tsx}\"", 57 | "format": "prettier --write \"*/**/*.{js,jsx,json,md,ts,tsx}\"" 58 | }, 59 | "eslintConfig": { 60 | "extends": [ 61 | "react-app", 62 | "react-app/jest" 63 | ] 64 | }, 65 | "browserslist": { 66 | "production": [ 67 | "chrome >= 67", 68 | "edge >= 79", 69 | "firefox >= 68", 70 | "opera >= 54", 71 | "safari >= 14" 72 | ], 73 | "development": [ 74 | "last 1 chrome version", 75 | "last 1 firefox version", 76 | "last 1 safari version" 77 | ] 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/components/nav-menu/NavMenu.tsx: -------------------------------------------------------------------------------- 1 | import styled from '@emotion/styled' 2 | import { Theme } from '@mui/material' 3 | import Box from '@mui/material/Box' 4 | import MenuItem from '@mui/material/MenuItem' 5 | import MenuList from '@mui/material/MenuList' 6 | import Typography from '@mui/material/Typography' 7 | 8 | type NavMenuProps = { 9 | setStep: (newStep: number) => void 10 | activeStep: number 11 | } 12 | 13 | const NavMenu = ({ setStep, activeStep }: NavMenuProps) => { 14 | return ( 15 | 16 | 17 | setStep(0)} active={activeStep === 0}> 18 | 19 | Intro 20 | 21 | 22 | 23 | setStep(1)} active={activeStep === 1}> 24 | 25 | 01 26 | 27 | 28 | Auth Kit 29 | 30 | 31 | 32 | setStep(2)} active={activeStep === 2}> 33 | 34 | 02 35 | 36 | 37 | Onramp Kit 38 | 39 | 40 | 41 | setStep(3)} active={activeStep === 3}> 42 | 43 | 03 44 | 45 | 46 | Relay Kit 47 | 48 | 49 | 50 | 51 | ) 52 | } 53 | 54 | export default NavMenu 55 | 56 | const NavMenuContainer = styled(Box)<{ 57 | theme?: Theme 58 | }>( 59 | ({ theme }) => ` 60 | 61 | border-radius: 10px; 62 | 63 | border: 1px solid ${theme.palette.border.light}; 64 | ` 65 | ) 66 | 67 | const NavItem = styled(MenuItem)<{ 68 | theme?: Theme 69 | active: boolean 70 | }>( 71 | ({ theme, active }) => ` 72 | 73 | border-radius: 10px; 74 | 75 | border: 1px solid ${active ? theme.palette.primary.dark : theme.palette.border.light}; 76 | 77 | margin-bottom: 16px; 78 | padding: 16px 22px; 79 | display: flex 80 | ` 81 | ) 82 | 83 | const OrderLabel = styled(Typography)<{ 84 | theme?: Theme 85 | }>( 86 | ({ theme }) => ` 87 | border: 1px solid ${theme.palette.text.primary}; 88 | border-radius: 4px; 89 | padding: 4px 6px; 90 | line-height: 12px; 91 | ` 92 | ) 93 | -------------------------------------------------------------------------------- /src/pages/Intro.tsx: -------------------------------------------------------------------------------- 1 | import styled from '@emotion/styled' 2 | import { Theme } from '@mui/material' 3 | import Box from '@mui/material/Box' 4 | import Button from '@mui/material/Button' 5 | import Divider from '@mui/material/Divider' 6 | import Typography from '@mui/material/Typography' 7 | 8 | import safeLogo from 'src/assets/safe-logo.svg' 9 | import ChainSelector from 'src/components/chain-selector/ChainSelector' 10 | 11 | type IntroProps = { 12 | setStep: (newStep: number) => void 13 | } 14 | 15 | const Intro = ({ setStep }: IntroProps) => { 16 | return ( 17 | 24 | safe logo 25 | 26 | 27 | Account Abstraction SDK 28 | 29 | 30 | 31 | Add account abstraction functionality into your apps. Here you can find examples on how to 32 | use our different kits: 33 | 34 | 35 | {/* Kit list */} 36 | 37 | 38 | 39 | 01 40 | 41 | 42 | Auth Kit 43 | 44 | 45 | 46 | 47 | 48 | 02 49 | 50 | 51 | Onramp Kit 52 | 53 | 54 | 55 | 56 | 57 | 03 58 | 59 | 60 | Relay Kit 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Select a network to start using the interactive demo: 69 | 70 | 71 | 72 | Please note that the Onramp Kit will only work in the EU on Görli and in the US on Mumbai test chains. 73 | 74 | 75 | 76 | 77 | 78 | 81 | 82 | 83 | ) 84 | } 85 | 86 | export default Intro 87 | 88 | const OrderLabel = styled(Typography)<{ 89 | theme?: Theme 90 | }>( 91 | ({ theme }) => ` 92 | border: 1px solid ${theme.palette.text.primary}; 93 | border-radius: 4px; 94 | padding: 4px 6px; 95 | line-height: 12px; 96 | ` 97 | ) 98 | -------------------------------------------------------------------------------- /src/pages/AuthKitDemo.tsx: -------------------------------------------------------------------------------- 1 | import Box from '@mui/material/Box' 2 | import Button from '@mui/material/Button' 3 | import Divider from '@mui/material/Divider' 4 | import Link from '@mui/material/Link' 5 | import Stack from '@mui/material/Stack' 6 | import Typography from '@mui/material/Typography' 7 | import Code from 'src/components/code/Code' 8 | 9 | import ConnectedWalletLabel from 'src/components/connected-wallet-label/ConnectedWalletLabel' 10 | import SafeAccount from 'src/components/safe-account/SafeAccount' 11 | import { ConnectContainer, ConnectedContainer } from 'src/components/styles' 12 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 13 | import { WEB3AUTH_SNIPPET } from 'src/utils/snippets' 14 | 15 | const AuthKitDemo = () => { 16 | const { loginWeb3Auth, isAuthenticated, chainId } = useAccountAbstraction() 17 | 18 | return ( 19 | <> 20 | 21 | The Auth Kit 22 | 23 | 24 | 25 | Generate or authenticate a blockchain account using an email address, social media account, 26 | or traditional crypto wallets like Metamask. 27 | 28 | 29 | 30 | Learn more: 31 | 32 | 33 | 34 | 38 | Github 39 | 40 | 41 | 42 | Documentation 43 | 44 | 45 | 46 | 47 | 48 | {/* Auth Demo */} 49 | 50 | Interactive demo 51 | 52 | 53 | {isAuthenticated ? ( 54 | 55 | {/* Safe account */} 56 | 57 | 58 | {/* owner ID */} 59 | 60 | Owner ID 61 | 62 | 63 | Your Owner account signs transactions to unlock your assets. 64 | 65 | 66 | {/* Owner details */} 67 | 68 | 69 | 70 | ) : ( 71 | 72 | 73 | Create a safe using the Auth Kit 74 | 75 | 76 | 79 | 80 | )} 81 | 82 | 83 | 84 | 85 | How to use it 86 | 87 | 88 | 89 | 90 | ) 91 | } 92 | 93 | export default AuthKitDemo 94 | -------------------------------------------------------------------------------- /src/constants/chains.ts: -------------------------------------------------------------------------------- 1 | import Chain from 'src/models/chain' 2 | 3 | export const gnosisChain: Chain = { 4 | id: '0x64', 5 | token: 'xDai', 6 | shortName: 'gno', 7 | label: 'Gnosis Chain', 8 | rpcUrl: 'https://rpc.gnosischain.com', 9 | blockExplorerUrl: 'https://gnosisscan.io', 10 | color: '#3e6957', 11 | transactionServiceUrl: 'https://safe-transaction-gnosis-chain.safe.global', 12 | isStripePaymentsEnabled: false, 13 | isMoneriumPaymentsEnabled: false, 14 | supportedErc20Tokens: [ 15 | '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83' // USDC 16 | ] 17 | } 18 | 19 | export const goerliChain: Chain = { 20 | id: '0x5', 21 | token: 'gETH', 22 | label: 'Görli', 23 | shortName: 'gor', 24 | rpcUrl: 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161', 25 | blockExplorerUrl: 'https://goerli.etherscan.io', 26 | color: '#fbc02d', 27 | transactionServiceUrl: 'https://safe-transaction-goerli.safe.global', 28 | isStripePaymentsEnabled: false, 29 | isMoneriumPaymentsEnabled: true, 30 | supportedErc20Tokens: [ 31 | '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6' // WETH 32 | ] 33 | } 34 | 35 | export const mainnetChain: Chain = { 36 | id: '0x1', 37 | token: 'ETH', 38 | label: 'Ethereum', 39 | shortName: 'eth', 40 | rpcUrl: 'https://cloudflare-eth.com', 41 | blockExplorerUrl: 'https://etherscan.io', 42 | color: '#DDDDDD', 43 | transactionServiceUrl: 'https://safe-transaction-mainnet.safe.global', 44 | isStripePaymentsEnabled: false, 45 | isMoneriumPaymentsEnabled: false, 46 | supportedErc20Tokens: [ 47 | '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' // USDC 48 | ] 49 | } 50 | 51 | export const polygonChain: Chain = { 52 | id: '0x89', 53 | token: 'matic', 54 | shortName: 'matic', 55 | label: 'Polygon', 56 | rpcUrl: 'https://polygon-rpc.com', 57 | blockExplorerUrl: 'https://polygonscan.com', 58 | color: '#8248E5', 59 | transactionServiceUrl: 'https://safe-transaction-polygon.safe.global', 60 | isStripePaymentsEnabled: false, 61 | isMoneriumPaymentsEnabled: false, 62 | supportedErc20Tokens: [ 63 | '0x2791bca1f2de4661ed88a30c99a7a9449aa84174' // USDC 64 | ] 65 | } 66 | 67 | export const mumbaiChain: Chain = { 68 | id: '0x13881', 69 | token: 'matic', 70 | shortName: 'matic', 71 | label: 'Mumbai', 72 | rpcUrl: 'https://rpc-mumbai.maticvigil.com/', 73 | blockExplorerUrl: 'https://mumbai.polygonscan.com', 74 | color: '#8248E5', 75 | isStripePaymentsEnabled: true, 76 | isMoneriumPaymentsEnabled: false, 77 | faucetUrl: 'https://mumbaifaucet.com/', 78 | supportedErc20Tokens: [ 79 | '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889' // WMATIC 80 | ] 81 | } 82 | 83 | export const sepoliaChain: Chain = { 84 | id: '0xaa36a7', 85 | token: 'SepoliaETH', 86 | shortName: 'eth', 87 | label: 'Sepolia', 88 | rpcUrl: 'https://ethereum-sepolia.publicnode.com/', 89 | blockExplorerUrl: 'https://sepolia.polygonscan.com', 90 | color: '#AA36A7', 91 | isStripePaymentsEnabled: false, 92 | isMoneriumPaymentsEnabled: false, 93 | faucetUrl: 'https://sepoliafaucet.com/', 94 | supportedErc20Tokens: ['0x8267cF9254734C6Eb452a7bb9AAF97B392258b21'] 95 | } 96 | 97 | const chains: Chain[] = [ 98 | gnosisChain, 99 | goerliChain, 100 | mainnetChain, 101 | mumbaiChain, 102 | polygonChain, 103 | sepoliaChain 104 | ] 105 | 106 | export const initialChain = mumbaiChain 107 | 108 | export default chains 109 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import { useCallback, useEffect, useState } from 'react' 2 | import Box from '@mui/material/Box' 3 | import Button from '@mui/material/Button' 4 | import CssBaseline from '@mui/material/CssBaseline' 5 | import Stack from '@mui/material/Stack' 6 | import Typography from '@mui/material/Typography' 7 | import '@safe-global/safe-react-components/dist/fonts.css' 8 | 9 | import Header from 'src/components/header/Header' 10 | import Providers from 'src/components/providers/Providers' 11 | import AuthKitDemo from 'src/pages/AuthKitDemo' 12 | import Intro from 'src/pages/Intro' 13 | import OnRampKitDemo from 'src/pages/OnRampKitDemo' 14 | import RelayKitDemo from 'src/pages/RelayKitDemo' 15 | import NavMenu from './components/nav-menu/NavMenu' 16 | import SafeCoreInfo from './components/safe-core-info/SafeCoreInfo' 17 | import { useAccountAbstraction } from './store/accountAbstractionContext' 18 | import isMoneriumRedirect from './utils/isMoneriumRedirect' 19 | 20 | function App() { 21 | const { setChainId } = useAccountAbstraction() 22 | const [activeStep, setActiveStep] = useState(0) 23 | 24 | useEffect(() => { 25 | if (isMoneriumRedirect()) { 26 | setActiveStep(2) 27 | } 28 | }, [setChainId]) 29 | 30 | const nextStep = useCallback(() => { 31 | setActiveStep((activeStep) => activeStep + 1) 32 | }, []) 33 | 34 | const previousStep = useCallback(() => { 35 | setActiveStep((activeStep) => activeStep - 1) 36 | }, []) 37 | 38 | const setStep = useCallback((newStep: number) => { 39 | setActiveStep(newStep) 40 | }, []) 41 | 42 | const isFirstStep = activeStep === 0 43 | const isLastStep = activeStep === steps.length - 1 44 | 45 | const showSafeCoreVideo = isFirstStep 46 | 47 | const ActiveStepComponent = steps[activeStep].component 48 | const nextLabel = steps[activeStep].nextLabel 49 | 50 | return ( 51 | 52 | <> 53 | 54 | 55 | {/* App header */} 56 |
57 | 58 | 65 | {showSafeCoreVideo ? ( 66 | 67 | ) : ( 68 | 69 | )} 70 | 71 |
72 | {/* Active Step Component */} 73 | 74 | 75 | {/* next & back Buttons */} 76 | {!isFirstStep && ( 77 | 78 | 81 | 82 | {!isLastStep && ( 83 | <> 84 | {nextLabel && ( 85 | 93 | {nextLabel} 94 | 95 | )} 96 | 97 | 100 | 101 | )} 102 | 103 | )} 104 |
105 |
106 | 107 | 108 | ) 109 | } 110 | 111 | export default App 112 | 113 | const steps = [ 114 | { 115 | // Intro step 116 | component: Intro 117 | }, 118 | { 119 | // Auth Kit step 120 | component: AuthKitDemo, 121 | nextLabel: 'to Onramp Kit' 122 | }, 123 | { 124 | // Onramp Kit step 125 | component: OnRampKitDemo, 126 | nextLabel: 'to Relay Kit' 127 | }, 128 | { 129 | // Relay Kit step 130 | component: RelayKitDemo 131 | } 132 | ] 133 | -------------------------------------------------------------------------------- /src/utils/snippets.ts: -------------------------------------------------------------------------------- 1 | export const WEB3AUTH_SNIPPET = (chainId: string) => `import { SafeAuthPack, SafeAuthInitOptions } from '@safe-global/auth-kit' 2 | 3 | const safeAuthPack = new SafeAuthPack() 4 | 5 | const options: SafeAuthInitOptions = { 6 | enableLogging: true, 7 | showWidgetButton: false, 8 | chainConfig: { 9 | chainId: ${chainId}, 10 | rpcTarget: 'https://your-rpc-url' 11 | } 12 | } 13 | 14 | await safeAuthPack.init(options) 15 | 16 | // Log in and get the derived EOA 17 | await safeAuthPack.signIn() 18 | 19 | // Logout 20 | await safeAuthPack.signOut() 21 | 22 | // Get the provider 23 | safeAuthPack.getProvider() 24 | ` 25 | 26 | export const STRIPE_SNIPPET = `import { StripePack } from '@safe-global/onramp-kit' 27 | 28 | const stripePack = new StripePack({ 29 | stripePublicKey: process.env.REACT_APP_STRIPE_PUBLIC_KEY, 30 | onRampBackendUrl: process.env.REACT_APP_STRIPE_BACKEND_BASE_URL 31 | }) 32 | 33 | await stripePack.init() 34 | 35 | const sessionData = await stripePack.open({ 36 | element: '#stripe-root', 37 | theme: 'light', 38 | defaultOptions: { 39 | transaction_details: { 40 | wallet_address: walletAddress, 41 | supported_destination_networks: ['ethereum', 'polygon'], 42 | supported_destination_currencies: ['usdc'], 43 | lock_wallet_address: true 44 | }, 45 | customer_information: { 46 | email: 'john@doe.com' 47 | } 48 | } 49 | })) 50 | 51 | stripePack.subscribe('onramp_ui_loaded', () => { 52 | console.log('UI loaded') 53 | }) 54 | 55 | stripePack.subscribe('onramp_session_updated', (e) => { 56 | console.log('Session Updated', e.payload) 57 | }) 58 | ` 59 | 60 | export const MONERIUM_SNIPPET = `import { MoneriumPack } from '@safe-global/onramp-kit' 61 | import Safe, { EthersAdapter } from '@safe-global/protocol-kit' 62 | import { OrderState } from '@monerium/sdk' 63 | 64 | const safeOwner = web3Provider.getSigner() 65 | const ethAdapter = new EthersAdapter({ ethers, signerOrProvider: safeOwner }) 66 | 67 | const safeSdk = await Safe.create({ 68 | ethAdapter: ethAdapter, 69 | safeAddress: safeSelected, 70 | isL1SafeMasterCopy: true 71 | }) 72 | 73 | const moneriumPack = new MoneriumPack({ 74 | clientId: process.env.REACT_APP_MONERIUM_CLIENT_ID || '', 75 | environment: 'sandbox' 76 | }) 77 | 78 | await moneriumPack.init({ 79 | safeSdk 80 | }) 81 | 82 | const moneriumClient = await moneriumPack.open({ 83 | redirectUrl: 'http://localhost:3000', 84 | authCode, 85 | refreshToken 86 | }) 87 | 88 | const authContext = await moneriumClient.getAuthContext() 89 | const profile = await moneriumClient.getProfile(authContext.defaultProfile) 90 | const balances = await moneriumClient.getBalances() 91 | const orders = await moneriumClient.getOrders() 92 | 93 | if (moneriumClient.bearerProfile) { 94 | localStorage.setItem(MONERIUM_TOKEN, moneriumClient.bearerProfile.refresh_token) 95 | } 96 | 97 | moneriumPack.subscribe(OrderState.pending, (notification) => { 98 | console.log(notification.meta.state) 99 | }) 100 | 101 | moneriumPack.subscribe(OrderState.placed, (notification) => { 102 | console.log(notification.meta.state) 103 | }) 104 | 105 | moneriumPack.close() 106 | ` 107 | 108 | export const GELATO_SNIPPET = `import { ethers } from 'ethers' 109 | import Safe, { EthersAdapter } from '@safe-global/protocol-kit' 110 | import { GelatoRelayPack } from '@safe-global/relay-kit' 111 | import { MetaTransactionData, OperationType } from '@safe-global/safe-core-sdk-types' 112 | 113 | const RPC_URL = 'https://...' 114 | const signerPrivateKey = process.env.OWNER_1_PRIVATE_KEY! 115 | const safeAddress = '0x...' // Safe from which the transaction will be sent 116 | 117 | const provider = new ethers.JsonRpcProvider(RPC_URL) 118 | const signer = new ethers.Wallet(signerPrivateKey, provider) 119 | const ethAdapter = new EthersAdapter({ ethers, signerOrProvider: signer }) 120 | 121 | // Initialize the kits 122 | const protocolKit = await Safe.create({ ethAdapter, safeAddress }) 123 | const relayKit = new GelatoRelayPack({ protocolKit, apiKey }) // apiKey is mandatory only for 1Balance 124 | 125 | // Prepare the transaction 126 | const transactions: MetaTransactionData[] = [{ 127 | to: '0x...', // the destination address 128 | data: '0x', 129 | value: withdrawAmount, 130 | operation: OperationType.Call 131 | }] 132 | 133 | const safeTransaction = await relayKit.createRelayedTransaction({ transactions }) 134 | const signedSafeTransaction = await protocolKit.signTransaction(safeTransaction) 135 | 136 | // Send the signed transaction to the relay 137 | relayKit.executeRelayTransaction(signedSafeTransaction)` 138 | -------------------------------------------------------------------------------- /src/components/gelato-task-status-label/GelatoTaskStatusLabel.tsx: -------------------------------------------------------------------------------- 1 | import { useCallback, useEffect } from 'react' 2 | import styled from '@emotion/styled' 3 | import { Theme } from '@mui/material' 4 | import Box from '@mui/material/Box' 5 | import LinearProgress from '@mui/material/LinearProgress' 6 | import Link from '@mui/material/Link' 7 | import Skeleton from '@mui/material/Skeleton' 8 | import Stack from '@mui/material/Stack' 9 | import Typography from '@mui/material/Typography' 10 | import { GelatoRelayPack } from '@safe-global/relay-kit' 11 | 12 | import { TransactionStatusResponse } from '@gelatonetwork/relay-sdk' 13 | import AddressLabel from 'src/components/address-label/AddressLabel' 14 | import useApi from 'src/hooks/useApi' 15 | import getChain from 'src/utils/getChain' 16 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 17 | 18 | type GelatoTaskStatusLabelProps = { 19 | gelatoTaskId: string 20 | chainId: string 21 | transactionHash?: string 22 | setTransactionHash: React.Dispatch> 23 | } 24 | 25 | const pollingTime = 4_000 // 4 seconds of polling time to update the Gelato task status 26 | 27 | // TODO: rename this to TrackGelatoTaskStatus 28 | const GelatoTaskStatusLabel = ({ 29 | gelatoTaskId, 30 | chainId, 31 | transactionHash, 32 | setTransactionHash 33 | }: GelatoTaskStatusLabelProps) => { 34 | const { accountAbstractionKit } = useAccountAbstraction() 35 | const fetchGelatoTaskInfo = useCallback(async () => { 36 | const gelatoRelayPack = accountAbstractionKit?.relayKit as GelatoRelayPack 37 | const taskStatusResponse = await gelatoRelayPack.getTaskStatus(gelatoTaskId) 38 | 39 | return taskStatusResponse 40 | }, [gelatoTaskId, accountAbstractionKit]) 41 | 42 | const { data: gelatoTaskInfo } = useApi(fetchGelatoTaskInfo, pollingTime) 43 | 44 | console.log('gelatoTaskInfo: ', gelatoTaskInfo) 45 | 46 | const chain = getChain(chainId) 47 | 48 | const isCancelled = gelatoTaskInfo?.taskState === 'Cancelled' 49 | const isSuccess = gelatoTaskInfo?.taskState === 'ExecSuccess' 50 | const isLoading = !isCancelled && !isSuccess 51 | 52 | useEffect(() => { 53 | if (gelatoTaskInfo?.transactionHash) { 54 | setTransactionHash(gelatoTaskInfo.transactionHash) 55 | } 56 | }, [gelatoTaskInfo, setTransactionHash]) 57 | 58 | return ( 59 | 60 | Gelato Task details 61 | 62 | {isLoading && } 63 | 64 | {/* Status label */} 65 | {gelatoTaskInfo?.taskState ? ( 66 | 67 | 68 | {getGelatoTaskStatusLabel(gelatoTaskInfo.taskState)} 69 | 70 | 71 | ) : ( 72 | 73 | )} 74 | 75 | {/* Transaction hash */} 76 | {!isCancelled && ( 77 | 84 | Transaction: 85 | 86 | {transactionHash ? ( 87 | 88 | 94 | 95 | ) : ( 96 | 97 | )} 98 | 99 | )} 100 | 101 | {/* Task extra info */} 102 | {gelatoTaskInfo?.lastCheckMessage && ( 103 | {gelatoTaskInfo.lastCheckMessage} 104 | )} 105 | 106 | ) 107 | } 108 | 109 | export default GelatoTaskStatusLabel 110 | 111 | const Container = styled(Box)` 112 | max-width: 800px; 113 | margin: 0 auto; 114 | margin-top: 12px; 115 | ` 116 | 117 | const StatusContainer = styled('div')<{ 118 | theme?: Theme 119 | taskStatus: TransactionStatusResponse['taskState'] 120 | }>( 121 | ({ theme, taskStatus }) => ` 122 | margin-right: 8px; 123 | border-radius: 4px; 124 | padding: 4px 12px; 125 | background-color: ${getGelatoTaskStatusColor(taskStatus, theme)}; 126 | color: ${theme.palette.getContrastText(getGelatoTaskStatusColor(taskStatus, theme))}; 127 | ` 128 | ) 129 | 130 | const getGelatoTaskStatusColor = ( 131 | taskStatus: TransactionStatusResponse['taskState'], 132 | theme: Theme 133 | ) => { 134 | const colors: Record = { 135 | CheckPending: theme.palette.warning.light, 136 | WaitingForConfirmation: theme.palette.info.light, 137 | ExecPending: theme.palette.info.light, 138 | ExecSuccess: theme.palette.success.light, 139 | Cancelled: theme.palette.error.light, 140 | ExecReverted: theme.palette.error.light 141 | } 142 | 143 | return colors[taskStatus] 144 | } 145 | 146 | const getGelatoTaskStatusLabel = (taskStatus: TransactionStatusResponse['taskState']) => { 147 | const label: Record = { 148 | CheckPending: 'Pending', 149 | WaitingForConfirmation: 'Waiting confirmations', 150 | ExecPending: 'Executing', 151 | ExecSuccess: 'Success', 152 | Cancelled: 'Cancelled', 153 | ExecReverted: 'Reverted' 154 | } 155 | 156 | return label[taskStatus] 157 | } 158 | -------------------------------------------------------------------------------- /src/pages/RelayKitDemo.tsx: -------------------------------------------------------------------------------- 1 | import ArrowRightAltRoundedIcon from '@mui/icons-material/ArrowRightAltRounded' 2 | import SendIcon from '@mui/icons-material/SendRounded' 3 | import Box from '@mui/material/Box' 4 | import Button from '@mui/material/Button' 5 | import Divider from '@mui/material/Divider' 6 | import LinearProgress from '@mui/material/LinearProgress' 7 | import Link from '@mui/material/Link' 8 | import Stack from '@mui/material/Stack' 9 | import Typography from '@mui/material/Typography' 10 | import { ethers } from 'ethers' 11 | import { useMemo, useState } from 'react' 12 | 13 | import AddressLabel from 'src/components/address-label/AddressLabel' 14 | import AuthenticateMessage from 'src/components/authenticate-message/AuthenticateMessage' 15 | import Code from 'src/components/code/Code' 16 | import GelatoTaskStatusLabel from 'src/components/gelato-task-status-label/GelatoTaskStatusLabel' 17 | import SafeAccount from 'src/components/safe-account/SafeAccount' 18 | import { ConnectedContainer } from 'src/components/styles' 19 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 20 | import { GELATO_SNIPPET } from 'src/utils/snippets' 21 | 22 | const transferAmount = 0.01 23 | 24 | const RelayKitDemo = () => { 25 | const { 26 | chainId, 27 | chain, 28 | 29 | safeSelected, 30 | safeBalance, 31 | erc20token, 32 | 33 | isRelayLoading, 34 | relayTransaction, 35 | gelatoTaskId, 36 | 37 | isAuthenticated, 38 | loginWeb3Auth 39 | } = useAccountAbstraction() 40 | 41 | const [transactionHash, setTransactionHash] = useState('') 42 | 43 | const hasNativeFunds = useMemo( 44 | () => !!safeBalance && Number(ethers.formatEther(safeBalance || '0')) > transferAmount, 45 | [safeBalance] 46 | ) 47 | 48 | const hasERC20Funds = useMemo( 49 | () => 50 | !!erc20token && 51 | Number(ethers.formatUnits(erc20token.balance || 0, erc20token.decimals)) > transferAmount, 52 | [erc20token] 53 | ) 54 | 55 | const hasFunds = hasERC20Funds || (!erc20token && hasNativeFunds) 56 | 57 | return ( 58 | <> 59 | 60 | The Relay Kit 61 | 62 | 63 | 64 | Allow users to pay fees using any ERC-20 token, without having to manage gas. Sponsor 65 | transactions on behalf of your users. On your first relayed transaction, a Safe account will 66 | be automatically deployed and your connected address will be assigned as the Safe owner. 67 | 68 | 69 | 70 | Learn more: 71 | 72 | 73 | 74 | 78 | Github 79 | 80 | 81 | 82 | Documentation 83 | 84 | 85 | 86 | 87 | 88 | {/* Relay Demo */} 89 | 90 | Interactive demo 91 | 92 | 93 | {!isAuthenticated ? ( 94 | 98 | ) : ( 99 | 100 | {/* Safe account */} 101 | 102 | 103 | {/* Relay Transaction */} 104 | 112 | Relayed transaction 113 | 114 | {/* Gelato status label */} 115 | {gelatoTaskId && ( 116 | 122 | )} 123 | 124 | {isRelayLoading && } 125 | 126 | {!isRelayLoading && !gelatoTaskId && ( 127 | <> 128 | 129 | Check the status of your relayed transaction. 130 | 131 | 132 | {/* send fake transaction to Gelato relay */} 133 | 141 | 142 | {!hasFunds && ( 143 | 144 | Insufficient funds. Send some funds to your Safe account. 145 | 146 | )} 147 | 148 | {!hasNativeFunds && !erc20token && chain?.faucetUrl && ( 149 | 150 | Request 0.5 {chain.token}. 151 | 152 | )} 153 | 154 | )} 155 | 156 | {/* Transaction details */} 157 | 158 | 159 | Transfer {transferAmount} {erc20token?.symbol || chain?.token} 160 | 161 | 162 | {safeSelected && ( 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | )} 171 | 172 | 173 | 174 | )} 175 | 176 | 177 | 178 | 179 | How to use it 180 | 181 | 182 | 183 | 184 | ) 185 | } 186 | 187 | export default RelayKitDemo 188 | -------------------------------------------------------------------------------- /src/components/safe-info/SafeInfo.tsx: -------------------------------------------------------------------------------- 1 | import { useCallback, useState } from 'react' 2 | import { ethers } from 'ethers' 3 | import styled from '@emotion/styled' 4 | import { Skeleton, Theme } from '@mui/material' 5 | import FormControl from '@mui/material/FormControl' 6 | import MenuItem from '@mui/material/MenuItem' 7 | import Select, { SelectChangeEvent } from '@mui/material/Select' 8 | import Stack from '@mui/material/Stack' 9 | import Tooltip from '@mui/material/Tooltip' 10 | import Typography from '@mui/material/Typography' 11 | 12 | import AddressLabel from 'src/components/address-label/AddressLabel' 13 | import AmountLabel from 'src/components/amount-label/AmountLabel' 14 | import getSafeInfo from 'src/api/getSafeInfo' 15 | import useApi from 'src/hooks/useApi' 16 | import safeLogoLight from 'src/assets/safe-info-logo-light.svg' 17 | import safeLogoDark from 'src/assets/safe-info-logo-dark.svg' 18 | import usePolling from 'src/hooks/usePolling' 19 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 20 | import { useTheme } from 'src/store/themeContext' 21 | import isContractAddress from 'src/utils/isContractAddress' 22 | 23 | type TokenBalanceProps = { 24 | value: string 25 | tokenSymbol: string 26 | } 27 | 28 | function TokenBalance({ value, tokenSymbol }: TokenBalanceProps) { 29 | return ( 30 | 31 | 32 | 33 | 34 | 35 | ) 36 | } 37 | 38 | type SafeInfoProps = { 39 | safeAddress: string 40 | chainId: string 41 | } 42 | 43 | // TODO: ADD USDC LABEL 44 | // TODO: ADD CHAIN LABEL 45 | 46 | function SafeInfo({ safeAddress, chainId }: SafeInfoProps) { 47 | const { 48 | chain, 49 | erc20Balances = {}, 50 | safeBalance, 51 | setTokenAddress, 52 | tokenAddress, 53 | web3Provider 54 | } = useAccountAbstraction() 55 | 56 | const [isDeployed, setIsDeployed] = useState(false) 57 | const [isDeployLoading, setIsDeployLoading] = useState(true) 58 | 59 | const { isDarkTheme } = useTheme() 60 | 61 | // detect if the safe is deployed with polling 62 | const detectSafeIsDeployed = useCallback(async () => { 63 | const isDeployed = await isContractAddress(safeAddress, web3Provider) 64 | 65 | setIsDeployed(isDeployed) 66 | setIsDeployLoading(false) 67 | }, [web3Provider, safeAddress]) 68 | 69 | usePolling(detectSafeIsDeployed) 70 | 71 | // safe info from Safe transaction service (used to know the threshold & owners of the Safe if its deployed) 72 | const fetchInfo = useCallback( 73 | (signal: AbortSignal) => getSafeInfo(safeAddress, chainId, { signal }), 74 | [safeAddress, chainId] 75 | ) 76 | 77 | const { data: safeInfo, isLoading: isGetSafeInfoLoading } = useApi(fetchInfo) 78 | 79 | const owners = safeInfo?.owners.length || 1 80 | const threshold = safeInfo?.threshold || 1 81 | const isLoading = isDeployLoading || isGetSafeInfoLoading 82 | 83 | return ( 84 | 85 |
86 | {/* Safe Logo */} 87 | {isLoading ? ( 88 | 89 | ) : ( 90 | connected Safe account logo 95 | )} 96 | 97 | {/* Threshold & owners label */} 98 | {isDeployed && ( 99 | 100 | 101 | {threshold}/{owners} 102 | 103 | 104 | )} 105 |
106 | 107 | 108 | {/* Safe address label */} 109 | 110 | 111 | 112 | 113 | {isLoading && } 114 | 115 | {!isDeployed && !isDeployLoading && ( 116 | 117 | 118 | 119 | Creation pending 120 | 121 | 122 | 123 | )} 124 | 125 | {!isLoading && ( 126 | <> 127 | {Object.values(erc20Balances).length > 0 ? ( 128 | 129 | 155 | 156 | ) : ( 157 | 161 | )} 162 | 163 | )} 164 | 165 |
166 | ) 167 | } 168 | 169 | export default SafeInfo 170 | 171 | const SafeSettingsLabel = styled('div')<{ 172 | theme?: Theme 173 | }>( 174 | ({ theme }) => ` 175 | position: absolute; 176 | top: -6px; 177 | right: -4px; 178 | border-radius: 50%; 179 | background-color: ${theme.palette.secondary.light}; 180 | color: ${theme.palette.getContrastText(theme.palette.secondary.light)}; 181 | padding: 5px 6px; 182 | ` 183 | ) 184 | 185 | const CreationPendingLabel = styled('div')<{ 186 | theme?: Theme 187 | }>( 188 | ({ theme }) => ` 189 | border-radius: 4px; 190 | background-color: ${theme.palette.info.light}; 191 | color: ${theme.palette.getContrastText(theme.palette.secondary.light)}; 192 | padding: 0px 10px; 193 | ` 194 | ) 195 | 196 | const AmountContainer = styled('div')<{ 197 | theme?: Theme 198 | }>( 199 | ({ theme, onClick }) => ` 200 | border-radius: 6px; 201 | background-color: ${theme.palette.background.light}; 202 | padding: 0px 8px; 203 | cursor: ${!!onClick ? 'pointer' : 'initial'}; 204 | ` 205 | ) 206 | -------------------------------------------------------------------------------- /src/pages/OnRampKitDemo.tsx: -------------------------------------------------------------------------------- 1 | import WalletIcon from '@mui/icons-material/AccountBalanceWalletRounded' 2 | import CloseIcon from '@mui/icons-material/CloseRounded' 3 | import LoginIcon from '@mui/icons-material/Login' 4 | import Box from '@mui/material/Box' 5 | import Button from '@mui/material/Button' 6 | import Divider from '@mui/material/Divider' 7 | import IconButton from '@mui/material/IconButton' 8 | import Link from '@mui/material/Link' 9 | import Stack from '@mui/material/Stack' 10 | import Tab from '@mui/material/Tab' 11 | import Tabs from '@mui/material/Tabs' 12 | import Tooltip from '@mui/material/Tooltip' 13 | import Typography from '@mui/material/Typography' 14 | import { useEffect, useState } from 'react' 15 | 16 | import AuthenticateMessage from 'src/components/authenticate-message/AuthenticateMessage' 17 | import Code from 'src/components/code/Code' 18 | import MoneriumChainWarning from 'src/components/monerium/MoneriumChainWarning' 19 | import MoneriumDeploySafeAccount from 'src/components/monerium/MoneriumDeploySafeAccount' 20 | import MoneriumInfo from 'src/components/monerium/MoneriumInfo' 21 | import SafeAccount from 'src/components/safe-account/SafeAccount' 22 | import { ConnectedContainer } from 'src/components/styles' 23 | import { useAccountAbstraction } from 'src/store/accountAbstractionContext' 24 | import isContractAddress from 'src/utils/isContractAddress' 25 | import { MONERIUM_SNIPPET, STRIPE_SNIPPET } from 'src/utils/snippets' 26 | 27 | type OnRampKitDemoProps = { 28 | setStep: (newStep: number) => void 29 | } 30 | 31 | const OnRampKitDemo = ({ setStep }: OnRampKitDemoProps) => { 32 | const { 33 | web3Provider, 34 | openStripeWidget, 35 | closeStripeWidget, 36 | safeSelected, 37 | chain, 38 | isAuthenticated, 39 | loginWeb3Auth, 40 | startMoneriumFlow, 41 | closeMoneriumFlow, 42 | moneriumInfo 43 | } = useAccountAbstraction() 44 | const [isSafeDeployed, setIsSafeDeployed] = useState(false) 45 | 46 | const [tabsValue, setTabsValue] = useState(0) 47 | 48 | useEffect(() => { 49 | ;(async () => { 50 | if (!safeSelected) return 51 | 52 | const isDeployed = await isContractAddress(safeSelected, web3Provider) 53 | 54 | setIsSafeDeployed(isDeployed) 55 | })() 56 | }, [web3Provider, safeSelected]) 57 | 58 | const handleTabChange = (_: React.SyntheticEvent, newValue: number) => { 59 | setTabsValue(newValue) 60 | } 61 | 62 | const [showStripeWidget, setShowStripeWidget] = useState(false) 63 | 64 | return ( 65 | <> 66 | 67 | The Onramp Kit 68 | 69 | 70 | 71 | Allow users to buy cryptocurrencies using a credit card and other payment options directly 72 | within your app. 73 | 74 | 75 | 76 | Learn more: 77 | 78 | 79 | 80 | 84 | Github 85 | 86 | 87 | 88 | Documentation 89 | 90 | 91 | 92 | 93 | 94 | {/* OnRamp Demo */} 95 | 96 | Interactive demo 97 | 98 | 99 | {!isAuthenticated ? ( 100 | 104 | ) : ( 105 | 106 | {/* Safe account */} 107 | 108 | 109 | {/* Provider widget */} 110 | 111 | 117 | 118 | 119 | 120 | 121 | {tabsValue === 0 && ( 122 | <> 123 | {moneriumInfo ? ( 124 | 125 | ) : ( 126 | <> 127 | {!chain?.isMoneriumPaymentsEnabled ? ( 128 | setStep(0)} /> 129 | ) : ( 130 | setStep(3)} 133 | /> 134 | )} 135 | 136 | 145 | 146 | 147 | )} 148 | 149 | )} 150 | 151 | {tabsValue === 1 && ( 152 | <> 153 | 154 | This widget is on testmode, you will need to use{' '} 155 | 159 | fake data 160 | {' '} 161 | in order to simulate the process. Available only in the United States. 162 | 163 | 164 | {!showStripeWidget ? ( 165 | 166 | {/* Buy USDC with our OnRamp kit */} 167 | 179 | 180 | ) : ( 181 | 182 | 183 | { 188 | setShowStripeWidget(false) 189 | await closeStripeWidget() 190 | }} 191 | > 192 | 193 | 194 | 195 | 196 | {/* Stripe root widget */} 197 |
198 |
199 | )} 200 | 201 | )} 202 |
203 |
204 | )} 205 | 206 | 207 | 208 | 209 | How to use it 210 | 211 | 212 | 213 | 214 | ) 215 | } 216 | 217 | export default OnRampKitDemo 218 | -------------------------------------------------------------------------------- /src/assets/safe-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/constants/erc20ABI.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": true, 7 | "internalType": "address", 8 | "name": "owner", 9 | "type": "address" 10 | }, 11 | { 12 | "indexed": true, 13 | "internalType": "address", 14 | "name": "spender", 15 | "type": "address" 16 | }, 17 | { 18 | "indexed": false, 19 | "internalType": "uint256", 20 | "name": "value", 21 | "type": "uint256" 22 | } 23 | ], 24 | "name": "Approval", 25 | "type": "event" 26 | }, 27 | { 28 | "anonymous": false, 29 | "inputs": [ 30 | { 31 | "indexed": true, 32 | "internalType": "address", 33 | "name": "_account", 34 | "type": "address" 35 | } 36 | ], 37 | "name": "Blacklisted", 38 | "type": "event" 39 | }, 40 | { 41 | "anonymous": false, 42 | "inputs": [ 43 | { 44 | "indexed": true, 45 | "internalType": "address", 46 | "name": "newBlacklister", 47 | "type": "address" 48 | } 49 | ], 50 | "name": "BlacklisterChanged", 51 | "type": "event" 52 | }, 53 | { 54 | "anonymous": false, 55 | "inputs": [ 56 | { 57 | "indexed": true, 58 | "internalType": "address", 59 | "name": "burner", 60 | "type": "address" 61 | }, 62 | { 63 | "indexed": false, 64 | "internalType": "uint256", 65 | "name": "amount", 66 | "type": "uint256" 67 | } 68 | ], 69 | "name": "Burn", 70 | "type": "event" 71 | }, 72 | { 73 | "anonymous": false, 74 | "inputs": [ 75 | { 76 | "indexed": true, 77 | "internalType": "address", 78 | "name": "newMasterMinter", 79 | "type": "address" 80 | } 81 | ], 82 | "name": "MasterMinterChanged", 83 | "type": "event" 84 | }, 85 | { 86 | "anonymous": false, 87 | "inputs": [ 88 | { 89 | "indexed": true, 90 | "internalType": "address", 91 | "name": "minter", 92 | "type": "address" 93 | }, 94 | { 95 | "indexed": true, 96 | "internalType": "address", 97 | "name": "to", 98 | "type": "address" 99 | }, 100 | { 101 | "indexed": false, 102 | "internalType": "uint256", 103 | "name": "amount", 104 | "type": "uint256" 105 | } 106 | ], 107 | "name": "Mint", 108 | "type": "event" 109 | }, 110 | { 111 | "anonymous": false, 112 | "inputs": [ 113 | { 114 | "indexed": true, 115 | "internalType": "address", 116 | "name": "minter", 117 | "type": "address" 118 | }, 119 | { 120 | "indexed": false, 121 | "internalType": "uint256", 122 | "name": "minterAllowedAmount", 123 | "type": "uint256" 124 | } 125 | ], 126 | "name": "MinterConfigured", 127 | "type": "event" 128 | }, 129 | { 130 | "anonymous": false, 131 | "inputs": [ 132 | { 133 | "indexed": true, 134 | "internalType": "address", 135 | "name": "oldMinter", 136 | "type": "address" 137 | } 138 | ], 139 | "name": "MinterRemoved", 140 | "type": "event" 141 | }, 142 | { 143 | "anonymous": false, 144 | "inputs": [ 145 | { 146 | "indexed": false, 147 | "internalType": "address", 148 | "name": "previousOwner", 149 | "type": "address" 150 | }, 151 | { 152 | "indexed": false, 153 | "internalType": "address", 154 | "name": "newOwner", 155 | "type": "address" 156 | } 157 | ], 158 | "name": "OwnershipTransferred", 159 | "type": "event" 160 | }, 161 | { "anonymous": false, "inputs": [], "name": "Pause", "type": "event" }, 162 | { 163 | "anonymous": false, 164 | "inputs": [ 165 | { 166 | "indexed": true, 167 | "internalType": "address", 168 | "name": "newAddress", 169 | "type": "address" 170 | } 171 | ], 172 | "name": "PauserChanged", 173 | "type": "event" 174 | }, 175 | { 176 | "anonymous": false, 177 | "inputs": [ 178 | { 179 | "indexed": true, 180 | "internalType": "address", 181 | "name": "from", 182 | "type": "address" 183 | }, 184 | { 185 | "indexed": true, 186 | "internalType": "address", 187 | "name": "to", 188 | "type": "address" 189 | }, 190 | { 191 | "indexed": false, 192 | "internalType": "uint256", 193 | "name": "value", 194 | "type": "uint256" 195 | } 196 | ], 197 | "name": "Transfer", 198 | "type": "event" 199 | }, 200 | { 201 | "anonymous": false, 202 | "inputs": [ 203 | { 204 | "indexed": true, 205 | "internalType": "address", 206 | "name": "_account", 207 | "type": "address" 208 | } 209 | ], 210 | "name": "UnBlacklisted", 211 | "type": "event" 212 | }, 213 | { "anonymous": false, "inputs": [], "name": "Unpause", "type": "event" }, 214 | { 215 | "inputs": [ 216 | { "internalType": "address", "name": "owner", "type": "address" }, 217 | { "internalType": "address", "name": "spender", "type": "address" } 218 | ], 219 | "name": "allowance", 220 | "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], 221 | "stateMutability": "view", 222 | "type": "function" 223 | }, 224 | { 225 | "inputs": [ 226 | { "internalType": "address", "name": "spender", "type": "address" }, 227 | { "internalType": "uint256", "name": "value", "type": "uint256" } 228 | ], 229 | "name": "approve", 230 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 231 | "stateMutability": "nonpayable", 232 | "type": "function" 233 | }, 234 | { 235 | "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], 236 | "name": "balanceOf", 237 | "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], 238 | "stateMutability": "view", 239 | "type": "function" 240 | }, 241 | { 242 | "inputs": [{ "internalType": "address", "name": "_account", "type": "address" }], 243 | "name": "blacklist", 244 | "outputs": [], 245 | "stateMutability": "nonpayable", 246 | "type": "function" 247 | }, 248 | { 249 | "inputs": [], 250 | "name": "blacklister", 251 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 252 | "stateMutability": "view", 253 | "type": "function" 254 | }, 255 | { 256 | "inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }], 257 | "name": "burn", 258 | "outputs": [], 259 | "stateMutability": "nonpayable", 260 | "type": "function" 261 | }, 262 | { 263 | "inputs": [ 264 | { "internalType": "address", "name": "minter", "type": "address" }, 265 | { 266 | "internalType": "uint256", 267 | "name": "minterAllowedAmount", 268 | "type": "uint256" 269 | } 270 | ], 271 | "name": "configureMinter", 272 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 273 | "stateMutability": "nonpayable", 274 | "type": "function" 275 | }, 276 | { 277 | "inputs": [], 278 | "name": "currency", 279 | "outputs": [{ "internalType": "string", "name": "", "type": "string" }], 280 | "stateMutability": "view", 281 | "type": "function" 282 | }, 283 | { 284 | "inputs": [], 285 | "name": "decimals", 286 | "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], 287 | "stateMutability": "view", 288 | "type": "function" 289 | }, 290 | { 291 | "inputs": [ 292 | { "internalType": "string", "name": "tokenName", "type": "string" }, 293 | { "internalType": "string", "name": "tokenSymbol", "type": "string" }, 294 | { "internalType": "string", "name": "tokenCurrency", "type": "string" }, 295 | { "internalType": "uint8", "name": "tokenDecimals", "type": "uint8" }, 296 | { 297 | "internalType": "address", 298 | "name": "newMasterMinter", 299 | "type": "address" 300 | }, 301 | { "internalType": "address", "name": "newPauser", "type": "address" }, 302 | { 303 | "internalType": "address", 304 | "name": "newBlacklister", 305 | "type": "address" 306 | }, 307 | { "internalType": "address", "name": "newOwner", "type": "address" } 308 | ], 309 | "name": "initialize", 310 | "outputs": [], 311 | "stateMutability": "nonpayable", 312 | "type": "function" 313 | }, 314 | { 315 | "inputs": [{ "internalType": "address", "name": "_account", "type": "address" }], 316 | "name": "isBlacklisted", 317 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 318 | "stateMutability": "view", 319 | "type": "function" 320 | }, 321 | { 322 | "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], 323 | "name": "isMinter", 324 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 325 | "stateMutability": "view", 326 | "type": "function" 327 | }, 328 | { 329 | "inputs": [], 330 | "name": "masterMinter", 331 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 332 | "stateMutability": "view", 333 | "type": "function" 334 | }, 335 | { 336 | "inputs": [ 337 | { "internalType": "address", "name": "_to", "type": "address" }, 338 | { "internalType": "uint256", "name": "_amount", "type": "uint256" } 339 | ], 340 | "name": "mint", 341 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 342 | "stateMutability": "nonpayable", 343 | "type": "function" 344 | }, 345 | { 346 | "inputs": [{ "internalType": "address", "name": "minter", "type": "address" }], 347 | "name": "minterAllowance", 348 | "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], 349 | "stateMutability": "view", 350 | "type": "function" 351 | }, 352 | { 353 | "inputs": [], 354 | "name": "name", 355 | "outputs": [{ "internalType": "string", "name": "", "type": "string" }], 356 | "stateMutability": "view", 357 | "type": "function" 358 | }, 359 | { 360 | "inputs": [], 361 | "name": "owner", 362 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 363 | "stateMutability": "view", 364 | "type": "function" 365 | }, 366 | { 367 | "inputs": [], 368 | "name": "pause", 369 | "outputs": [], 370 | "stateMutability": "nonpayable", 371 | "type": "function" 372 | }, 373 | { 374 | "inputs": [], 375 | "name": "paused", 376 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 377 | "stateMutability": "view", 378 | "type": "function" 379 | }, 380 | { 381 | "inputs": [], 382 | "name": "pauser", 383 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 384 | "stateMutability": "view", 385 | "type": "function" 386 | }, 387 | { 388 | "inputs": [{ "internalType": "address", "name": "minter", "type": "address" }], 389 | "name": "removeMinter", 390 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 391 | "stateMutability": "nonpayable", 392 | "type": "function" 393 | }, 394 | { 395 | "inputs": [], 396 | "name": "symbol", 397 | "outputs": [{ "internalType": "string", "name": "", "type": "string" }], 398 | "stateMutability": "view", 399 | "type": "function" 400 | }, 401 | { 402 | "inputs": [], 403 | "name": "totalSupply", 404 | "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], 405 | "stateMutability": "view", 406 | "type": "function" 407 | }, 408 | { 409 | "inputs": [ 410 | { "internalType": "address", "name": "to", "type": "address" }, 411 | { "internalType": "uint256", "name": "value", "type": "uint256" } 412 | ], 413 | "name": "transfer", 414 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 415 | "stateMutability": "nonpayable", 416 | "type": "function" 417 | }, 418 | { 419 | "inputs": [ 420 | { "internalType": "address", "name": "from", "type": "address" }, 421 | { "internalType": "address", "name": "to", "type": "address" }, 422 | { "internalType": "uint256", "name": "value", "type": "uint256" } 423 | ], 424 | "name": "transferFrom", 425 | "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], 426 | "stateMutability": "nonpayable", 427 | "type": "function" 428 | }, 429 | { 430 | "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], 431 | "name": "transferOwnership", 432 | "outputs": [], 433 | "stateMutability": "nonpayable", 434 | "type": "function" 435 | }, 436 | { 437 | "inputs": [{ "internalType": "address", "name": "_account", "type": "address" }], 438 | "name": "unBlacklist", 439 | "outputs": [], 440 | "stateMutability": "nonpayable", 441 | "type": "function" 442 | }, 443 | { 444 | "inputs": [], 445 | "name": "unpause", 446 | "outputs": [], 447 | "stateMutability": "nonpayable", 448 | "type": "function" 449 | }, 450 | { 451 | "inputs": [ 452 | { 453 | "internalType": "address", 454 | "name": "_newBlacklister", 455 | "type": "address" 456 | } 457 | ], 458 | "name": "updateBlacklister", 459 | "outputs": [], 460 | "stateMutability": "nonpayable", 461 | "type": "function" 462 | }, 463 | { 464 | "inputs": [ 465 | { 466 | "internalType": "address", 467 | "name": "_newMasterMinter", 468 | "type": "address" 469 | } 470 | ], 471 | "name": "updateMasterMinter", 472 | "outputs": [], 473 | "stateMutability": "nonpayable", 474 | "type": "function" 475 | }, 476 | { 477 | "inputs": [{ "internalType": "address", "name": "_newPauser", "type": "address" }], 478 | "name": "updatePauser", 479 | "outputs": [], 480 | "stateMutability": "nonpayable", 481 | "type": "function" 482 | } 483 | ] 484 | -------------------------------------------------------------------------------- /src/store/accountAbstractionContext.tsx: -------------------------------------------------------------------------------- 1 | import { createContext, useCallback, useContext, useEffect, useState } from 'react' 2 | import { ethers } from 'ethers' 3 | 4 | import AccountAbstraction from '@safe-global/account-abstraction-kit-poc' 5 | import { SafeAuthInitOptions, SafeAuthPack } from '@safe-global/auth-kit' 6 | import { MoneriumPack, StripePack } from '@safe-global/onramp-kit' 7 | import { GelatoRelayPack } from '@safe-global/relay-kit' 8 | import { RelayResponse as GelatoRelayResponse } from '@gelatonetwork/relay-sdk' 9 | import Safe, { EthersAdapter } from '@safe-global/protocol-kit' 10 | import { MetaTransactionData, MetaTransactionOptions } from '@safe-global/safe-core-sdk-types' 11 | 12 | import { initialChain } from 'src/constants/chains' 13 | import usePolling from 'src/hooks/usePolling' 14 | import Chain from 'src/models/chain' 15 | import { ERC20Token } from 'src/models/erc20token' 16 | import getChain from 'src/utils/getChain' 17 | import { getERC20Info } from 'src/utils/getERC20Info' 18 | import getMoneriumInfo, { MoneriumInfo } from 'src/utils/getMoneriumInfo' 19 | import isMoneriumRedirect from 'src/utils/isMoneriumRedirect' 20 | 21 | type accountAbstractionContextValue = { 22 | ownerAddress?: string 23 | chainId: string 24 | safes: string[] 25 | tokenAddress: string 26 | erc20token?: ERC20Token 27 | chain?: Chain 28 | isAuthenticated: boolean 29 | web3Provider?: ethers.BrowserProvider 30 | loginWeb3Auth: () => void 31 | logoutWeb3Auth: () => void 32 | setChainId: (chainId: string) => void 33 | safeSelected?: string 34 | safeBalance?: string 35 | erc20Balances?: Record 36 | setSafeSelected: React.Dispatch> 37 | setTokenAddress: React.Dispatch> 38 | isRelayLoading: boolean 39 | relayTransaction: () => Promise 40 | gelatoTaskId?: string 41 | openStripeWidget: () => Promise 42 | closeStripeWidget: () => Promise 43 | startMoneriumFlow: () => Promise 44 | closeMoneriumFlow: () => void 45 | moneriumInfo?: MoneriumInfo 46 | accountAbstractionKit?: AccountAbstraction 47 | } 48 | 49 | const initialState = { 50 | isAuthenticated: false, 51 | loginWeb3Auth: () => {}, 52 | logoutWeb3Auth: () => {}, 53 | relayTransaction: async () => {}, 54 | setChainId: () => {}, 55 | setSafeSelected: () => {}, 56 | setTokenAddress: () => {}, 57 | onRampWithStripe: async () => {}, 58 | safes: [], 59 | tokenAddress: ethers.ZeroAddress, 60 | chainId: initialChain.id, 61 | isRelayLoading: true, 62 | openStripeWidget: async () => {}, 63 | closeStripeWidget: async () => {}, 64 | startMoneriumFlow: async () => {}, 65 | closeMoneriumFlow: () => {} 66 | } 67 | 68 | const accountAbstractionContext = createContext(initialState) 69 | 70 | const useAccountAbstraction = () => { 71 | const context = useContext(accountAbstractionContext) 72 | 73 | if (!context) { 74 | throw new Error('useAccountAbstraction should be used within a AccountAbstraction Provider') 75 | } 76 | 77 | return context 78 | } 79 | 80 | const MONERIUM_TOKEN = 'monerium_token' 81 | const MONERIUM_SELECTED_SAFE = 'monerium_safe_selected' 82 | 83 | const AccountAbstractionProvider = ({ children }: { children: JSX.Element }) => { 84 | // owner address from the email (provided by web3Auth) 85 | const [ownerAddress, setOwnerAddress] = useState('') 86 | 87 | // safes owned by the user 88 | const [safes, setSafes] = useState([]) 89 | 90 | // selected token to be used for fee payments (native token by default) 91 | const [tokenAddress, setTokenAddress] = useState(ethers.ZeroAddress) 92 | 93 | // chain selected 94 | const [chainId, setChainId] = useState(() => { 95 | if (isMoneriumRedirect()) { 96 | return '0x5' 97 | } 98 | 99 | return initialChain.id 100 | }) 101 | 102 | // web3 provider to perform signatures 103 | const [web3Provider, setWeb3Provider] = useState() 104 | 105 | const [isAuthenticated, setIsAuthenticated] = useState(false) 106 | 107 | const chain = getChain(chainId) || initialChain 108 | 109 | // reset React state when you switch the chain 110 | useEffect(() => { 111 | setOwnerAddress('') 112 | setSafes([]) 113 | setChainId(chain.id) 114 | setWeb3Provider(undefined) 115 | setSafeSelected('') 116 | }, [chain]) 117 | 118 | // authClient 119 | const [safeAuthPack, setSafeAuthPack] = useState() 120 | 121 | // onRampClient 122 | const [stripePack, setStripePack] = useState() 123 | 124 | useEffect(() => { 125 | ;(async () => { 126 | if (safeAuthPack) { 127 | safeAuthPack.destroy() 128 | } 129 | 130 | const options: SafeAuthInitOptions = { 131 | enableLogging: true, 132 | showWidgetButton: false, 133 | chainConfig: { 134 | chainId: chain.id, 135 | rpcTarget: chain.rpcUrl 136 | } 137 | } 138 | 139 | const authPack = new SafeAuthPack({ 140 | txServiceUrl: chain.transactionServiceUrl 141 | }) 142 | 143 | await authPack.init(options) 144 | 145 | setSafeAuthPack(authPack) 146 | 147 | // If the provider has an account the we can try to sign in the user 148 | authPack.subscribe('accountsChanged', async (accounts) => { 149 | if (accounts.length > 0) { 150 | const { safes, eoa } = await authPack.signIn() 151 | const provider = authPack.getProvider() 152 | 153 | // we set react state with the provided values: owner (eoa address), chain, safes owned & web3 provider 154 | setChainId(chain.id) 155 | setOwnerAddress(eoa) 156 | setSafes(safes || []) 157 | if (provider) { 158 | setWeb3Provider(new ethers.BrowserProvider(provider)) 159 | } 160 | setIsAuthenticated(true) 161 | } 162 | }) 163 | })() 164 | // eslint-disable-next-line react-hooks/exhaustive-deps 165 | }, [chain]) 166 | 167 | // auth-kit implementation 168 | const loginWeb3Auth = useCallback(async () => { 169 | if (!safeAuthPack) return 170 | 171 | try { 172 | const { safes, eoa } = await safeAuthPack.signIn() 173 | const provider = safeAuthPack.getProvider()! 174 | 175 | // we set react state with the provided values: owner (eoa address), chain, safes owned & web3 provider 176 | setChainId(chain.id) 177 | setOwnerAddress(eoa) 178 | setSafes(safes || []) 179 | setWeb3Provider(new ethers.BrowserProvider(provider)) 180 | setIsAuthenticated(true) 181 | } catch (error) { 182 | console.log('error: ', error) 183 | } 184 | }, [chain, safeAuthPack]) 185 | 186 | const logoutWeb3Auth = () => { 187 | safeAuthPack?.signOut() 188 | setOwnerAddress('') 189 | setSafes([]) 190 | setChainId(chain.id) 191 | setWeb3Provider(undefined) 192 | setSafeSelected('') 193 | setGelatoTaskId(undefined) 194 | setIsAuthenticated(false) 195 | closeMoneriumFlow() 196 | } 197 | 198 | // current safe selected by the user 199 | const [safeSelected, setSafeSelected] = useState('') 200 | const [moneriumInfo, setMoneriumInfo] = useState() 201 | const [moneriumPack, setMoneriumPack] = useState() 202 | 203 | // Initialize MoneriumPack 204 | useEffect(() => { 205 | ;(async () => { 206 | if (!web3Provider || !safeSelected) return 207 | 208 | const safeOwner = await web3Provider.getSigner() 209 | const ethAdapter = new EthersAdapter({ ethers, signerOrProvider: safeOwner }) 210 | 211 | const safeSdk = await Safe.create({ 212 | ethAdapter, 213 | safeAddress: safeSelected, 214 | isL1SafeSingleton: true 215 | }) 216 | 217 | const pack = new MoneriumPack({ 218 | clientId: process.env.REACT_APP_MONERIUM_CLIENT_ID || '', 219 | environment: 'sandbox' 220 | }) 221 | 222 | await pack.init({ 223 | safeSdk 224 | }) 225 | 226 | setMoneriumPack(pack) 227 | })() 228 | }, [web3Provider, safeSelected]) 229 | 230 | const startMoneriumFlow = useCallback( 231 | async (authCode?: string, refreshToken?: string) => { 232 | if (!moneriumPack) return 233 | 234 | localStorage.setItem(MONERIUM_SELECTED_SAFE, safeSelected) 235 | 236 | const moneriumClient = await moneriumPack.open({ 237 | redirectUrl: process.env.REACT_APP_MONERIUM_REDIRECT_URL, 238 | authCode, 239 | refreshToken 240 | }) 241 | 242 | if (moneriumClient.bearerProfile) { 243 | localStorage.setItem(MONERIUM_TOKEN, moneriumClient.bearerProfile.refresh_token) 244 | 245 | const authContext = await moneriumClient.getAuthContext() 246 | const profile = await moneriumClient.getProfile(authContext.defaultProfile) 247 | const balances = await moneriumClient.getBalances(authContext.defaultProfile) 248 | 249 | setMoneriumInfo(getMoneriumInfo(safeSelected, authContext, profile, balances)) 250 | } 251 | }, 252 | [moneriumPack, safeSelected] 253 | ) 254 | 255 | const closeMoneriumFlow = useCallback(() => { 256 | moneriumPack?.close() 257 | localStorage.removeItem(MONERIUM_TOKEN) 258 | setMoneriumInfo(undefined) 259 | }, [moneriumPack]) 260 | 261 | useEffect(() => { 262 | const authCode = new URLSearchParams(window.location.search).get('code') || undefined 263 | const refreshToken = localStorage.getItem(MONERIUM_TOKEN) || undefined 264 | 265 | if (authCode || refreshToken) startMoneriumFlow(authCode, refreshToken) 266 | }, [startMoneriumFlow]) 267 | 268 | // TODO: add disconnect owner wallet logic ? 269 | 270 | const [accountAbstractionKit, setAccountAbstractionKit] = useState() 271 | 272 | // conterfactual safe Address if its not deployed yet 273 | useEffect(() => { 274 | const getSafeAddress = async () => { 275 | if (web3Provider) { 276 | const hasSafes = safes.length > 0 277 | const storedSafe = localStorage.getItem(MONERIUM_SELECTED_SAFE) || undefined 278 | 279 | const safeSelected = hasSafes 280 | ? storedSafe || safes[0] 281 | : await accountAbstractionKit?.protocolKit.getAddress() 282 | 283 | setSafeSelected(safeSelected || '') 284 | } 285 | } 286 | 287 | getSafeAddress() 288 | }, [accountAbstractionKit?.protocolKit, safes, web3Provider]) 289 | 290 | useEffect(() => { 291 | if (!web3Provider) return 292 | ;(async () => { 293 | // Instantiate AccountAbstraction kit 294 | const ethAdapter = new EthersAdapter({ 295 | ethers, 296 | signerOrProvider: await web3Provider.getSigner() 297 | }) 298 | const safeAccountAbstraction = new AccountAbstraction(ethAdapter) 299 | await safeAccountAbstraction.init() 300 | const gelatoRelayPack = new GelatoRelayPack({ 301 | protocolKit: safeAccountAbstraction.protocolKit 302 | }) 303 | safeAccountAbstraction.setRelayKit(gelatoRelayPack) 304 | 305 | setAccountAbstractionKit(safeAccountAbstraction) 306 | })() 307 | }, [web3Provider]) 308 | 309 | const [isRelayLoading, setIsRelayLoading] = useState(false) 310 | const [gelatoTaskId, setGelatoTaskId] = useState() 311 | 312 | // refresh the Gelato task id 313 | useEffect(() => { 314 | setIsRelayLoading(false) 315 | setGelatoTaskId(undefined) 316 | }, [chainId]) 317 | 318 | // relay-kit implementation using Gelato 319 | const relayTransaction = async () => { 320 | if (web3Provider) { 321 | setIsRelayLoading(true) 322 | 323 | // we use a dump safe transfer as a demo transaction 324 | const dumpSafeTransafer: MetaTransactionData[] = [ 325 | { 326 | to: safeSelected, 327 | data: '0x', 328 | value: ethers.parseUnits('0.01', 'ether').toString(), 329 | operation: 0 // OperationType.Call, 330 | } 331 | ] 332 | 333 | const options: MetaTransactionOptions = { 334 | isSponsored: false, 335 | gasLimit: '600000', // in this alfa version we need to manually set the gas limit 336 | gasToken: tokenAddress 337 | } 338 | 339 | const response = (await accountAbstractionKit?.relayTransaction( 340 | dumpSafeTransafer, 341 | options 342 | )) as GelatoRelayResponse 343 | 344 | setIsRelayLoading(false) 345 | console.log(response) 346 | setGelatoTaskId(response.taskId) 347 | } 348 | } 349 | 350 | // onramp-kit implementation 351 | const openStripeWidget = async () => { 352 | const stripePack = new StripePack({ 353 | stripePublicKey: process.env.REACT_APP_STRIPE_PUBLIC_KEY || '', 354 | onRampBackendUrl: process.env.REACT_APP_STRIPE_BACKEND_BASE_URL || '' 355 | }) 356 | 357 | await stripePack.init() 358 | 359 | const sessionData = await stripePack.open({ 360 | // sessionId: sessionId, optional parameter 361 | element: '#stripe-root', 362 | defaultOptions: { 363 | transaction_details: { 364 | wallet_address: safeSelected, 365 | supported_destination_networks: ['ethereum', 'polygon'], 366 | supported_destination_currencies: ['usdc'], 367 | lock_wallet_address: true 368 | }, 369 | customer_information: { 370 | email: 'john@doe.com' 371 | } 372 | } 373 | }) 374 | 375 | setStripePack(stripePack) 376 | 377 | console.log('Stripe sessionData: ', sessionData) 378 | } 379 | 380 | const closeStripeWidget = async () => { 381 | stripePack?.close() 382 | } 383 | 384 | // we can pay Gelato tx relay fees with native token & ERC20 385 | 386 | // fetch safe address balance with polling 387 | const fetchSafeBalance = useCallback(async () => { 388 | const balance = await web3Provider?.getBalance(safeSelected) 389 | 390 | return balance?.toString() 391 | }, [web3Provider, safeSelected]) 392 | 393 | const safeBalance = usePolling(fetchSafeBalance) 394 | 395 | // fetch safe's ERC20 balances 396 | const fetchErc20SafeBalances = useCallback(async (): Promise> => { 397 | if (!web3Provider) { 398 | return {} 399 | } 400 | 401 | return Promise.all( 402 | chain.supportedErc20Tokens?.map((erc20Address) => 403 | getERC20Info(erc20Address, web3Provider, safeSelected) 404 | ) || [] 405 | ).then((tokens) => 406 | tokens.reduce((acc, token) => (!!token ? { ...acc, [token.address]: token } : acc), {}) 407 | ) 408 | }, [web3Provider, safeSelected, chain]) 409 | 410 | const erc20Balances = usePolling(fetchErc20SafeBalances) 411 | const erc20token = erc20Balances?.[tokenAddress] 412 | 413 | const state = { 414 | ownerAddress, 415 | chainId, 416 | chain, 417 | safes, 418 | erc20token, 419 | tokenAddress, 420 | 421 | isAuthenticated, 422 | 423 | web3Provider, 424 | 425 | loginWeb3Auth, 426 | logoutWeb3Auth, 427 | 428 | setChainId, 429 | 430 | safeSelected, 431 | safeBalance, 432 | erc20Balances, 433 | setSafeSelected, 434 | setTokenAddress, 435 | 436 | isRelayLoading, 437 | relayTransaction, 438 | gelatoTaskId, 439 | 440 | openStripeWidget, 441 | closeStripeWidget, 442 | 443 | startMoneriumFlow, 444 | closeMoneriumFlow, 445 | moneriumInfo, 446 | 447 | accountAbstractionKit 448 | } 449 | 450 | return ( 451 | 452 | {children} 453 | 454 | ) 455 | } 456 | 457 | export { useAccountAbstraction, AccountAbstractionProvider } 458 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------