diff --git a/packages/@magic-ext/smart-account/package.json b/packages/@magic-ext/smart-account/package.json new file mode 100644 index 000000000..49fb0a4b4 --- /dev/null +++ b/packages/@magic-ext/smart-account/package.json @@ -0,0 +1,35 @@ +{ + "name": "@magic-ext/smart-account", + "version": "0.1.0", + "description": "Magic smart account extension for AA support via Rhinestone", + "author": "Magic (https://magic.link/)", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/magiclabs/magic-js" + }, + "files": [ + "dist" + ], + "target": "neutral", + "cdnGlobalName": "MagicSmartAccountExtension", + "main": "./dist/cjs/index.js", + "module": "./dist/es/index.js", + "types": "./dist/types/index.d.ts", + "jsdelivr": "./dist/extension.js", + "exports": { + "import": "./dist/es/index.mjs", + "types": "./dist/types/index.d.ts", + "require": "./dist/cjs/index.js" + }, + "externals": { + "include": [ + "@magic-sdk/provider", + "@magic-sdk/types" + ] + }, + "devDependencies": { + "@magic-sdk/provider": "^33.4.0", + "@magic-sdk/types": "^27.4.0" + } +} diff --git a/packages/@magic-ext/smart-account/src/index.cdn.ts b/packages/@magic-ext/smart-account/src/index.cdn.ts new file mode 100644 index 000000000..e63555188 --- /dev/null +++ b/packages/@magic-ext/smart-account/src/index.cdn.ts @@ -0,0 +1,3 @@ +import { SmartAccountExtension } from './index'; + +export default SmartAccountExtension; diff --git a/packages/@magic-ext/smart-account/src/index.native.ts b/packages/@magic-ext/smart-account/src/index.native.ts new file mode 100644 index 000000000..ea465c2a3 --- /dev/null +++ b/packages/@magic-ext/smart-account/src/index.native.ts @@ -0,0 +1 @@ +export * from './index'; diff --git a/packages/@magic-ext/smart-account/src/index.ts b/packages/@magic-ext/smart-account/src/index.ts new file mode 100644 index 000000000..71c8676ae --- /dev/null +++ b/packages/@magic-ext/smart-account/src/index.ts @@ -0,0 +1,29 @@ +import { Extension } from '@magic-sdk/provider'; +import { + SmartAccountPayloadMethod, + SmartAccountDelegateParams, + SmartAccountDelegateResponse, + SmartAccountSendTransactionParams, + SmartAccountSendTransactionResponse, +} from './types'; + +export class SmartAccountExtension extends Extension.Internal<'smartAccount'> { + name = 'smartAccount' as const; + config = {}; + + constructor() { + super(); + } + + public delegate(params?: SmartAccountDelegateParams): Promise { + const requestPayload = this.utils.createJsonRpcRequestPayload(SmartAccountPayloadMethod.Delegate, [params]); + return this.request(requestPayload); + } + + public sendTransaction(params: SmartAccountSendTransactionParams): Promise { + const requestPayload = this.utils.createJsonRpcRequestPayload(SmartAccountPayloadMethod.SendTransaction, [params]); + return this.request(requestPayload); + } +} + +export * from './types'; diff --git a/packages/@magic-ext/smart-account/src/types.ts b/packages/@magic-ext/smart-account/src/types.ts new file mode 100644 index 000000000..d6a36708a --- /dev/null +++ b/packages/@magic-ext/smart-account/src/types.ts @@ -0,0 +1,41 @@ +export enum SmartAccountPayloadMethod { + Delegate = 'magic_smart_account_delegate', + SendTransaction = 'magic_smart_account_send_transaction', +} + +export interface SmartAccountDelegateParams { + chainId?: number; + sponsored?: boolean; +} + +export interface SmartAccountDelegateResponse { + smartAccountAddress: string; + isDeployed: boolean; + eoaAddress: string; +} + +export interface SmartAccountCallInput { + to: string; + data?: string; + value?: string; +} + +export interface SmartAccountTokenRequest { + address: string; + amount?: string; +} + +export interface SmartAccountSendTransactionParams { + chainId: number; + calls: SmartAccountCallInput[]; + sourceChainIds?: number[]; + tokenRequests?: SmartAccountTokenRequest[]; + sponsored?: boolean; +} + +export interface SmartAccountSendTransactionResponse { + intentId: string; + fillHash: string | undefined; + claimHashes: string[]; + targetChainId: number; +} diff --git a/packages/@magic-ext/smart-account/tsconfig.json b/packages/@magic-ext/smart-account/tsconfig.json new file mode 100644 index 000000000..5981f3c2e --- /dev/null +++ b/packages/@magic-ext/smart-account/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../tsconfig.settings.json" +} diff --git a/yarn.lock b/yarn.lock index 7ad20b526..9b8240157 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3505,6 +3505,15 @@ __metadata: languageName: unknown linkType: soft +"@magic-ext/smart-account@workspace:packages/@magic-ext/smart-account": + version: 0.0.0-use.local + resolution: "@magic-ext/smart-account@workspace:packages/@magic-ext/smart-account" + dependencies: + "@magic-sdk/provider": ^33.4.0 + "@magic-sdk/types": ^27.4.0 + languageName: unknown + linkType: soft + "@magic-ext/solana@workspace:packages/@magic-ext/solana": version: 0.0.0-use.local resolution: "@magic-ext/solana@workspace:packages/@magic-ext/solana"