safe-global / safe-core-sdk

The Safe{Core} SDK allows builders to add account abstraction functionality into their apps.
https://docs.safe.global/sdk/overview
MIT License
243 stars 178 forks source link

feat(protocol-kit): Add EIP-1193 provider support #770

Closed yagopv closed 1 month ago

yagopv commented 2 months ago

What it solves

Resolves https://github.com/safe-global/safe-core-sdk/issues/651

How this PR fixes it

signer is optional so if not specified will try to get the first connected one in the provider (eth_accounts, eth_requestAccounts)

// before
await Safe.create({
   ethAdapter: new EthersAdapter({ ethers, signerOrProvider })
   safeAddress: '0xSafeAddress'
   ...
})

// now
await Safe.init({
   provider: window.ethereum, // Or any compatible EIP-1193 provider
   signer: 'signerAddressOrPrivateKey'
   safeAddress: '0xSafeAddress'
   ...
})

// ...or...
await Safe.init({
   provider: 'http://rpc.url', //Or websocket
   signer: 'signerAddressOrPrivateKey'
   safeAddress: '0xSafeAddress'
   ...
})

This change make the AccountAbstraction and Safe4337Pack instantiation different as well as the dependency with the EthAdapter is changed to provider + signer (Same as Safe.create)