-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(SMA-598): Smart Account Withdrawals #424
Conversation
* const { success } = await wait(); | ||
*/ | ||
public async withdraw( | ||
recipient: Hex, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could also make recipient per each withdraw request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optionally. if not provided use the main recipient given above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can always call withdraw multiple times too per recipient in a loop that'd have the same effect. Actually having a method named 'withdraw' that doesn't go to the owner is slightly confusing, but I couldn't think of a clear path to finding the recipient without it being provided by the dev. I would have hardcoded this if I could have...
Can you think of a way to reliably find the owner in this case? I think it would be best now that I'm thinking about it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm thinking. we could have method single withdraw (which also acts as withdrawERC20)
and also withdrawMultipleERC20 and give them an option to provide receiver for each withdrawal.
these methods are risky though cause if we make mistake in sdk or choose to go rough then all tokens would be transferred to us
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean
[
* { address: USDT, amount: BigInt(1) }
here they could also provide recipient address, instead of having common recipient..or maybe if not provided then fallback to common recipient given above.
I agree with you it could by default go to the owner in most cases where owner is another hot wallet metamask EOA. but they might want to send elsewhere or to a friend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK makes sense. Will add.
* const { wait } = await smartAccount.withdraw( | ||
* account.pubKey, // recipient | ||
* [ | ||
* { address: USDT, amount: BigInt(1) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are they supposed to give wei value?
or just like symbol 'USDT' and amount 0.5 is possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'd have to keep symbols and chain and token decimals mapping.
and then find out using current chainId..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I'm not using symbols here, it's a can of worms (we'd need a database of ticker mappings, and it'd have to be 100% reliable) as there's no easy way to match a symbol to an address. Happy to revisit this if people ask for it though. As it is here the dev will need to know the addresses - I think that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes they give gwei value. In the tsdoc here I've made this clear. I also think this is what devs will expect. Doing the opposite is more likely to cause confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
const balanceOfSABefore = (await checkBalance(publicClient, smartAccountAddress)) as bigint; | ||
const balanceOfRecipientBefore = (await checkBalance(publicClient, smartAccountOwner)) as bigint; | ||
|
||
const { wait } = await smartAccount.withdraw(smartAccountOwner, undefined /* null or undefined or [] */, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do you choose the amount to withdraw if paymaster is not involved?
if a paymaster call fails, we would withdraw all which will fail on chain again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They could call the getBalances method :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on this second point? I don't follow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I want to withdraw native tokens and max amount (say 1 Matic) what's there in SA
and if there is no paymaster or paymaster call fails then pnd goes '0x' which means account payas for gas in native tokens. so we can't transfer 1 and also pay 0.01 matic in gas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's right. I have thrown this error if a user does not provide his own amount in this case. dev will be expected to find his own amounts to withdraw if no paymaster is used. It'll be on the dev to find the right amount somehow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm basically telling the dev that it's up to them to pick the amount of dust they want to leave behind, assuming they're not using a paymaster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review ii
Auto stash before merge of "feature/SMA-599_balances" and "origin/develop" Add withdrawal tests jsdoc comments continued Fix comments comments continued Make `getBalance` available with no arguments rename tokenAdress -> address Throw when no amount + no paymaster is set Tweak comment
fecb066
to
e6cd7db
Compare
@joepegler the withdraw method implementation seems to be missing |
these are all new methods so let's send it and get more feedback. |
Summary
Public utility method which withdraws funds from Smart Account to recipient (usually EOA)
Related Issue: SMA-598
Change Type
Checklist
Additional Information
Branch Naming