Skip to content

refactor: deduplicate collectReward() and getUserRewards() using getPoolModule() helper #61

@jangid

Description

@jangid

Context

PR #60 introduced getPoolModule() and getUpdatePoolFn() helpers in AutobalanceLpStrategy to resolve the Move module name based on asset position. These are used in the new pendingRewardAmount() method but not yet applied to the existing collectReward() and getUserRewards() methods, which still have three nearly identical if/else branches differing only by module name.

What to change

collectReward() (lines 630-682)

Collapse three branches into one using getPoolModule():

private collectReward(tx: Transaction) {
  const moduleName = this.getPoolModule();
  for (const reward of this.parentPoolObject.rewardInfos) {
    const rewardType = '0x' + reward.rewardCoinType;
    tx.moveCall({
      target: `${this.poolLabel.packageId}::${moduleName}::collect_reward`,
      typeArguments: [this.poolLabel.assetA.type, this.poolLabel.assetB.type, rewardType],
      arguments: [ /* unchanged */ ],
    });
  }
}

getUserRewards() (lines 685-764)

Same pattern — collapse using getPoolModule() and a new getRewardsFn() helper (analogous to getUpdatePoolFn()) to resolve get_user_rewards_v4 vs get_user_rewards_v3.

Impact

Pure refactor, no behavioral change. Reduces ~130 lines to ~50.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions