Skip to content

Commit

Permalink
support protocol fee in price calculation for soul name
Browse files Browse the repository at this point in the history
  • Loading branch information
H34D committed May 19, 2023
1 parent c0f38cb commit fbaf1b6
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions src/contracts/modules/soul-name.ts
Expand Up @@ -164,30 +164,70 @@ export class SoulName extends MasaModuleBase {
// slippage in bps where 10000 is 100%. 250 would be 2,5%
slippage: number | undefined = 250
): Promise<{
price: BigNumber;
paymentAddress: string;
price: BigNumber;
formattedPrice: string;
mintFee: BigNumber;
formattedMintFee: string;
protocolFee: BigNumber;
formattedProtocolFee: string;
}> => {
const paymentAddress = this.getPaymentAddress(paymentMethod);

let price = await this.instances.SoulStoreContract.getPriceForMintingName(
paymentAddress,
nameLength,
duration
);
let mintFee: BigNumber | undefined,
protocolFee: BigNumber = BigNumber.from(0);
try {
// load protocol and mint fee
const fees =
await this.instances.SoulStoreContract.getPriceForMintingNameWithProtocolFee(
paymentAddress,
nameLength,
duration
);
mintFee = fees.price;
protocolFee = fees.protocolFee;
} catch {
// ignore this is a soul store 2.0 function and does not work on older contracts
}

if (!mintFee) {
// fallback to classical price calculation
mintFee = await this.instances.SoulStoreContract.getPriceForMintingName(
paymentAddress,
nameLength,
duration
);
}

// calculate total price
let price = mintFee.add(protocolFee);

if (slippage) {
if (isNativeCurrency(paymentMethod)) {
price = this.addSlippage(price, slippage);
}
}

// total price
const formattedPrice = await this.formatPrice(paymentAddress, price);

// mint fee
const formattedMintFee = await this.formatPrice(paymentAddress, mintFee);

// protocol fee
const formattedProtocolFee = await this.formatPrice(
paymentAddress,
protocolFee
);

return {
price,
paymentAddress,
price,
formattedPrice,
mintFee,
formattedMintFee,
protocolFee,
formattedProtocolFee,
};
};

Expand Down

0 comments on commit fbaf1b6

Please sign in to comment.