Skip to content

Commit

Permalink
fix: simulation type if native asset join
Browse files Browse the repository at this point in the history
  • Loading branch information
joehquak committed Jul 30, 2023
1 parent 1bd602b commit b54285d
Showing 1 changed file with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ export class GeneralisedJoinHandler implements JoinPoolHandler {
const poolId = this.pool.value.id;
const hasInvalidAmounts = amountsIn.some(item => !item.valid);

const isNativeAssetJoin = amountsIn.some(item =>
isSameAddress(item.address, configService.network.nativeAsset.address)
);

// Static call simulation is more accurate than VaultModel, but requires relayer approval,
// token approvals, and account to have enought token balance.
const simulationType: SimulationType =
!hasInvalidAmounts && !approvalActions.length
? SimulationType.Static
: SimulationType.VaultModel;
const simulationType = this.getSimulationType({
isNativeAssetJoin,
hasInvalidAmounts,
approvalActionsLength: approvalActions.length,
});

console.log({ simulationType });

Expand Down Expand Up @@ -101,6 +106,24 @@ export class GeneralisedJoinHandler implements JoinPoolHandler {
};
}

private getSimulationType({
isNativeAssetJoin,
hasInvalidAmounts,
approvalActionsLength,
}: {
isNativeAssetJoin: boolean;
hasInvalidAmounts: boolean;
approvalActionsLength: number;
}): SimulationType {
if (isNativeAssetJoin) {
return SimulationType.VaultModel;
}
if (!hasInvalidAmounts && !approvalActionsLength) {
return SimulationType.Static;
}
return SimulationType.VaultModel;
}

/**
* If native asset addres, replaces with zero address because the vault only checks
* for the zero address when joining with native asset.
Expand Down

0 comments on commit b54285d

Please sign in to comment.