Lib: Implement swapAndSplit function - #239
Open
lgalende wants to merge 8 commits into
Open
Conversation
|
|
||
| let totalPctBps: u32 = 0 | ||
| for (let i = 0; i < allocations.length; i++) totalPctBps += allocations[i].pctBps | ||
| if (totalPctBps !== MAX_PCT_BPS) throw new Error('Total allocation percentage must be 10_000 bps') |
Member
There was a problem hiding this comment.
Suggested change
| if (totalPctBps !== MAX_PCT_BPS) throw new Error('Total allocation percentage must be 10_000 bps') | |
| if (totalPctBps !== MAX_PCT_BPS) throw new Error('Total allocation percentage must add up to 10_000 bps') |
| for (let i = 0; i < allocations.length - 1; i++) { | ||
| const pctBps = allocations[i].pctBps | ||
| dynamicCall1.addCall(MIMIC_HELPER, PCT_SELECTOR, [ | ||
| EvmDynamicArg.variable(0, 0, false), // amount (swap output) |
Member
There was a problem hiding this comment.
this seems to be constant, maybe it can be abstracted into a variable to improve its readability
| const recipient = allocations[i].recipient | ||
| dynamicCall2.addCall(tokenOut, TRANSFER_SELECTOR, [ | ||
| EvmDynamicArg.literal([new EvmEncodeParam('address', recipient.toString())], false), // to | ||
| EvmDynamicArg.variable(1, i, false), // value (dynamicCall1 sub 'i' result) |
Member
There was a problem hiding this comment.
Same here, we can use a variable inside the loop to improve its readability, similar to recipient
| const dynamicCall4 = EvmDynamicCallBuilder.forChain(chainId).addUser(MIMIC_PUBLIC_SMART_ACCOUNT) | ||
| dynamicCall4.addCall(tokenOut, TRANSFER_SELECTOR, [ | ||
| EvmDynamicArg.literal([new EvmEncodeParam('address', lastRecipient.toString())], false), // to | ||
| EvmDynamicArg.variable(3, 0, false), // value (dynamicCall3 result) |
| EvmDynamicArg.variable(3, 0, false), // value (dynamicCall3 result) | ||
| ]) | ||
|
|
||
| builder.addOperationBuilder(dynamicCall4) |
Member
There was a problem hiding this comment.
I would name dynamicCall1, 2, 3, and 4 properly
|
|
||
| builder.addOperationBuilder(dynamicCall1) | ||
|
|
||
| // Transfer the corresponding amounts to each recipient, except the last one |
Member
There was a problem hiding this comment.
Same here, why "except the last one"
|
|
||
| builder.addOperationBuilder(swap) | ||
|
|
||
| // Calculate the corresponding amount for each allocation, except the last one |
Member
There was a problem hiding this comment.
I don't fully get why "except the last one"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on: