-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: restructure supply parameters and validation #55
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
Open
murka
wants to merge
1
commit into
main
Choose a base branch
from
refactor/extend-supply-params
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,10 +62,10 @@ export interface EvaaParameters { | |
| } | ||
|
|
||
| /** | ||
| * Parameters for supply operations | ||
| * @interface SupplyParameters | ||
| * Base parameters for supply operations | ||
| * @type SupplyBaseParameters | ||
| */ | ||
| export interface SupplyParameters { | ||
| export type SupplyBaseParameters = { | ||
| /** Asset configuration for the supply operation */ | ||
| readonly asset: PoolAssetConfig; | ||
| /** Unique identifier for this operation */ | ||
|
|
@@ -82,16 +82,30 @@ export interface SupplyParameters { | |
| readonly forwardAmount?: bigint; | ||
| /** Operation payload cell */ | ||
| readonly payload: Cell; | ||
| /** Optional subaccount identifier (0-255) */ | ||
| readonly subaccountId?: number; | ||
| /** Whether to return repay remainings */ | ||
| readonly returnRepayRemainingsFlag?: boolean; | ||
| /** Optional custom payload recipient address */ | ||
| readonly customPayloadRecipient?: Address; | ||
| /** Whether to saturate custom payload */ | ||
| readonly customPayloadSaturationFlag?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Extended parameters for supply operations | ||
| * @type SupplyExtendParameters | ||
| */ | ||
| export type SupplyExtendParameters = SupplyBaseParameters & { | ||
| /** Optional subaccount identifier (0-255) */ | ||
| readonly subaccountId: number; | ||
| /** Whether to return repay remainings */ | ||
| readonly returnRepayRemainingsFlag: boolean; | ||
| /** Optional custom payload recipient address */ | ||
| readonly customPayloadRecipient: Address; | ||
| /** Whether to saturate custom payload */ | ||
| readonly customPayloadSaturationFlag: boolean; | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * Parameters for supply operations | ||
| * @type SupplyParameters | ||
| */ | ||
| export type SupplyParameters = SupplyBaseParameters | SupplyExtendParameters; | ||
|
|
||
| /** | ||
| * Parameters for withdraw operations | ||
| * @interface WithdrawParameters | ||
|
|
@@ -343,16 +357,29 @@ export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<Oracl | |
|
|
||
| // ========== MESSAGE BUILDERS ========== | ||
| /** | ||
| * Validates supply operation parameters | ||
| * Validates supply extend operation parameters | ||
| * @private | ||
| * @static | ||
| * @param parameters - Supply parameters to validate | ||
| * @param parameters - Extend supply parameters to validate | ||
| * @throws {Error} When amount is invalid or subaccount ID is out of range | ||
| */ | ||
| private static validateSupplyParameters(parameters: SupplyParameters): void { | ||
| if (parameters.subaccountId !== undefined && !isValidSubaccountId(parameters.subaccountId)) { | ||
| throw new Error(`Supply validation failed: ${VALIDATION.ERRORS.INVALID_SUBACCOUNT_ID}`); | ||
| private isValidSupplyExtendParameters(parameters: SupplyExtendParameters) { | ||
| if ( | ||
| "subaccountId" in parameters && | ||
| "returnRepayRemainingsFlag" in parameters && | ||
| "customPayloadRecipient" in parameters && | ||
| "customPayloadSaturationFlag" in parameters | ||
| ) { | ||
| if (parameters.subaccountId !== undefined && !isValidSubaccountId(parameters.subaccountId)) { | ||
| throw new Error( | ||
| `Extend supply validation failed: ${VALIDATION.ERRORS.INVALID_SUBACCOUNT_ID}`, | ||
| ); | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| throw new Error( | ||
| `Extend supply validation failed: ${VALIDATION.ERRORS.INVALID_EXTEND_SUPPLY_PARAMETERS}` | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -361,24 +388,32 @@ export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<Oracl | |
| * @returns {Cell} Complete supply message cell | ||
| * @throws {Error} When validation fails | ||
| */ | ||
| createSupplyMessage(parameters: SupplyParameters): Cell { | ||
| AbstractEvaaMaster.validateSupplyParameters(parameters); | ||
| createSupplyMessage(parameters: SupplyBaseParameters): Cell | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uses Function Overloads |
||
| createSupplyMessage(parameters: SupplyExtendParameters): Cell { | ||
|
|
||
| const subaccountId = parameters.subaccountId ?? 0; | ||
| const isTon = isTonAsset(parameters.asset); | ||
|
|
||
| const operationPayload = beginCell() | ||
| .storeUint(OPCODES.SUPPLY_MASTER, 32) | ||
| .storeBuilder(isTon ? beginCell().storeUint(parameters.queryID, 64) : beginCell()) | ||
| .storeInt(parameters.includeUserCode ? -1 : 0, 2) | ||
| .storeBuilder(isTon ? beginCell().storeUint(parameters.amount, 64) : beginCell()) | ||
| .storeAddress(parameters.userAddress) | ||
| .storeRef(parameters.payload) | ||
| .storeInt(subaccountId, 16) | ||
| .storeInt(parameters.returnRepayRemainingsFlag ? -1 : 0, 2) | ||
| .storeAddress(parameters.customPayloadRecipient) | ||
| .storeInt(parameters.customPayloadSaturationFlag ? -1 : 0, 2) | ||
| .endCell(); | ||
| let operationPayloadBuilder = beginCell() | ||
| .storeUint(OPCODES.SUPPLY_MASTER, 32) | ||
| .storeBuilder(isTon ? beginCell().storeUint(parameters.queryID, 64) : beginCell()) | ||
| .storeInt(parameters.includeUserCode ? -1 : 0, 2) | ||
| .storeBuilder(isTon ? beginCell().storeUint(parameters.amount, 64) : beginCell()) | ||
| .storeAddress(parameters.userAddress) | ||
| .storeRef(parameters.payload) | ||
|
|
||
|
|
||
| if (this.isValidSupplyExtendParameters(parameters)) { | ||
| operationPayloadBuilder = operationPayloadBuilder | ||
| .storeInt(parameters.subaccountId ?? 0, 16) | ||
| .storeInt(parameters.returnRepayRemainingsFlag ? -1 : 0, 2) | ||
| .storeAddress(parameters.customPayloadRecipient) | ||
| .storeInt( | ||
| parameters.customPayloadSaturationFlag ? -1 : 0, | ||
| 2, | ||
| ); | ||
| } | ||
|
|
||
| const operationPayload = operationPayloadBuilder.endCell(); | ||
|
|
||
| if (!isTon) { | ||
| return this.createJettonTransferMessage(parameters, FEES.SUPPLY, operationPayload); | ||
|
|
||
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.
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 couldn’t come up with anything better, waiting for your review.