Skip to content

Commit

Permalink
Adding price info in Soulname creation response
Browse files Browse the repository at this point in the history
  • Loading branch information
hide-on-bush-x committed Aug 7, 2023
1 parent 01298ad commit 9ad4c06
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
66 changes: 34 additions & 32 deletions src/contracts/contract-modules/soul-name.ts
Expand Up @@ -59,14 +59,14 @@ export class SoulName extends MasaModuleBase {
metadataURL: string,
authorityAddress: string,
signature: string,
receiver?: string,
): Promise<ContractTransaction> => {
receiver?: string
): Promise<ContractTransaction & { price: BigNumber }> => {
const to = receiver || (await this.masa.config.signer.getAddress());

const domain: TypedDataDomain = await generateSignatureDomain(
this.masa.config.signer,
"SoulStore",
this.instances.SoulStoreContract.address,
this.instances.SoulStoreContract.address
);

const value: {
Expand All @@ -90,20 +90,20 @@ export class SoulName extends MasaModuleBase {
this.types,
value,
signature,
authorityAddress,
authorityAddress
);

const { price, paymentAddress } = await this.getPrice(
paymentMethod,
nameLength,
duration,
duration
);

await this.checkOrGiveAllowance(
paymentAddress,
paymentMethod,
this.instances.SoulStoreContract.address,
price,
price
);

const purchaseNameParameters: [
Expand All @@ -114,7 +114,7 @@ export class SoulName extends MasaModuleBase {
number, // yearsPeriod: PromiseOrValue<BigNumberish>
string, // tokenURI: PromiseOrValue<string>
string, // authorityAddress: PromiseOrValue<string>
string, // signature: PromiseOrValue<BytesLike>
string // signature: PromiseOrValue<BytesLike>
] = [
paymentAddress,
to,
Expand All @@ -127,7 +127,7 @@ export class SoulName extends MasaModuleBase {
];

const purchaseNameOverrides: PayableOverrides = await this.createOverrides(
isNativeCurrency(paymentMethod) ? price : undefined,
isNativeCurrency(paymentMethod) ? price : undefined
);

if (this.masa.config.verbose) {
Expand All @@ -143,21 +143,23 @@ export class SoulName extends MasaModuleBase {
// estimate gas
let gasLimit: BigNumber = await estimateGas(
...purchaseNameParameters,
purchaseNameOverrides,
purchaseNameOverrides
);

if (this.masa.config.network?.gasSlippagePercentage) {
gasLimit = SoulName.addSlippage(
gasLimit,
this.masa.config.network.gasSlippagePercentage,
this.masa.config.network.gasSlippagePercentage
);
}

// execute
return await purchaseName(...purchaseNameParameters, {
const execution = await purchaseName(...purchaseNameParameters, {
...purchaseNameOverrides,
gasLimit,
});

return { ...execution, price };
};

/**
Expand All @@ -172,7 +174,7 @@ export class SoulName extends MasaModuleBase {
nameLength: number,
duration: number = 1,
// slippage in bps where 10000 is 100%. 250 would be 2,5%
slippage: number | undefined = 250,
slippage: number | undefined = 250
): Promise<PriceInformation> => {
const paymentAddress = this.getPaymentAddress(paymentMethod);

Expand All @@ -185,7 +187,7 @@ export class SoulName extends MasaModuleBase {
await this.instances.SoulStoreContract.getPriceForMintingNameWithProtocolFee(
paymentAddress,
nameLength,
duration,
duration
);
mintFee = fees.price;
protocolFee = fees.protocolFee;
Expand All @@ -198,7 +200,7 @@ export class SoulName extends MasaModuleBase {
mintFee = await this.instances.SoulStoreContract.getPriceForMintingName(
paymentAddress,
nameLength,
duration,
duration
);
}

Expand All @@ -220,7 +222,7 @@ export class SoulName extends MasaModuleBase {
// protocol fee
const formattedProtocolFee = await this.formatPrice(
paymentAddress,
protocolFee,
protocolFee
);

return {
Expand All @@ -239,10 +241,10 @@ export class SoulName extends MasaModuleBase {
* @param soulName
*/
public getSoulnameData = async (
soulName: string,
soulName: string
): Promise<{ exists: boolean; tokenId: BigNumber }> => {
return await this.instances.SoulNameContract.nameData(
soulName.toLowerCase(),
soulName.toLowerCase()
);
};

Expand All @@ -259,7 +261,7 @@ export class SoulName extends MasaModuleBase {
soulNameLength: number,
duration: number,
metadataUrl: string,
receiver: string,
receiver: string
): Promise<
| {
signature: string;
Expand All @@ -286,7 +288,7 @@ export class SoulName extends MasaModuleBase {
this.masa.config.signer,
"SoulStore",
this.types,
value,
value
);

const authorityAddress = await this.masa.config.signer.getAddress();
Expand All @@ -298,7 +300,7 @@ export class SoulName extends MasaModuleBase {
this.types,
value,
signature,
authorityAddress,
authorityAddress
);

return { signature, authorityAddress };
Expand All @@ -311,7 +313,7 @@ export class SoulName extends MasaModuleBase {
*/
public transfer = async (
soulName: string,
receiver: string,
receiver: string
): Promise<boolean> => {
const [soulNameData, extension] = await Promise.all([
this.getSoulnameData(soulName),
Expand All @@ -320,7 +322,7 @@ export class SoulName extends MasaModuleBase {

if (soulNameData.exists) {
console.log(
`Sending '${soulName}${extension}' with token ID '${soulNameData.tokenId}' to '${receiver}'!`,
`Sending '${soulName}${extension}' with token ID '${soulNameData.tokenId}' to '${receiver}'!`
);

try {
Expand All @@ -329,20 +331,20 @@ export class SoulName extends MasaModuleBase {
const { wait, hash } = await transferFrom(
this.masa.config.signer.getAddress(),
receiver,
soulNameData.tokenId,
soulNameData.tokenId
);

console.log(
Messages.WaitingToFinalize(
hash,
this.masa.config.network?.blockExplorerUrls?.[0],
),
this.masa.config.network?.blockExplorerUrls?.[0]
)
);

await wait();

console.log(
`Soulname '${soulName}${extension}' with token ID '${soulNameData.tokenId}' sent!`,
`Soulname '${soulName}${extension}' with token ID '${soulNameData.tokenId}' sent!`
);

return true;
Expand Down Expand Up @@ -370,7 +372,7 @@ export class SoulName extends MasaModuleBase {

if (soulNameData.exists) {
console.log(
`Burning '${soulName}${extension}' with token ID '${soulNameData.tokenId}'!`,
`Burning '${soulName}${extension}' with token ID '${soulNameData.tokenId}'!`
);

try {
Expand All @@ -385,7 +387,7 @@ export class SoulName extends MasaModuleBase {
if (this.masa.config.network?.gasSlippagePercentage) {
gasLimit = SoulName.addSlippage(
gasLimit,
this.masa.config.network.gasSlippagePercentage,
this.masa.config.network.gasSlippagePercentage
);
}

Expand All @@ -396,21 +398,21 @@ export class SoulName extends MasaModuleBase {
console.log(
Messages.WaitingToFinalize(
hash,
this.masa.config.network?.blockExplorerUrls?.[0],
),
this.masa.config.network?.blockExplorerUrls?.[0]
)
);

await wait();

console.log(
`Burned Soulname '${soulName}${extension}' with ID '${soulNameData.tokenId}'!`,
`Burned Soulname '${soulName}${extension}' with ID '${soulNameData.tokenId}'!`
);

return true;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(
`Burning Soulname '${soulName}${extension}' Failed! ${error.message}`,
`Burning Soulname '${soulName}${extension}' Failed! ${error.message}`
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/interface/token/soul-name.ts
Expand Up @@ -47,6 +47,7 @@ export interface SoulNameResultBase extends BaseResult {

export interface CreateSoulNameResult extends SoulNameResultBase {
soulName?: string;
price?: BigNumber;
}

export interface SoulNameMetadataStoreResult extends SoulNameResultBase {
Expand Down
3 changes: 2 additions & 1 deletion src/modules/soul-name/create.ts
Expand Up @@ -50,7 +50,7 @@ const purchaseSoulName = async (
}`;
console.log(`Soul Name Metadata URL: '${soulNameMetadataUrl}'`);

const { wait, hash } = await masa.contracts.soulName.purchase(
const { wait, hash, price } = await masa.contracts.soulName.purchase(
paymentMethod,
soulName,
soulNameLength,
Expand Down Expand Up @@ -96,6 +96,7 @@ const purchaseSoulName = async (
errorCode: SoulNameErrorCodes.NoError,
tokenId,
soulName,
price
};
}
}
Expand Down

0 comments on commit 9ad4c06

Please sign in to comment.