lutianzhou001 / aa-sdk

2 stars 1 forks source link

[Suggestion] Pre-fetch account address for OKXSmartContractAccount #2

Closed matthewyu-okx closed 3 months ago

matthewyu-okx commented 3 months ago

Current Behavior

It requires one more async call to get the address of the account instance.

const account = await OKXSmartContractAccount.create({
  rpcProvider,
  signer,
  name: "SmartAccount",
  version: "3.0.2",
  index: 4n,
  bundlerClientConfig: {
    bundlerUrl: "https://beta.okex.org",
  },
  paymasterClientConfig: {
    paymasterUrl: "https://beta.okex.org",
  },
})

const address = await account.getAddress()

Suggested Behavior

Execute the getAddress() function in the create() function so that the future use of the OKXSmartContractAccount instance won't need another async call for getting the address value.

const account = await OKXSmartContractAccount.create({
  rpcProvider,
  signer,
  name: "SmartAccount",
  version: "3.0.2",
  index: 4n,
  bundlerClientConfig: {
    bundlerUrl: "https://beta.okex.org",
  },
  paymasterClientConfig: {
    paymasterUrl: "https://beta.okex.org",
  },
})

// getAddress() is executed in the create() step, 
// and stored the value in the account instance
// const address = await account.getAddress()

// No need async call for getting the address
const address = account.address
lutianzhou001 commented 3 months ago

cannot remove this function because it's a base smart account function required in the interface. this interface, however, is derived from alchemy team and I just want to keep pace with them. Instead, I added a new function called getOKXSmartAccountAddress() to realize our own requirement, because in our case, the account address is a necessity, whether it's created or imported. This function does not need a async/await.