Skip to content

Commit

Permalink
Merge pull request #349 from masa-finance/h34d/chore/remove-soul-name…
Browse files Browse the repository at this point in the history
…-create

chore (soul-name): Remove all soulname create functions
  • Loading branch information
H34D committed Aug 6, 2024
2 parents 79f5e6e + e51a64a commit 1783a34
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 976 deletions.
138 changes: 2 additions & 136 deletions src/contracts/contract-modules/identity.ts
Original file line number Diff line number Diff line change
@@ -1,144 +1,10 @@
import {
BigNumber,
ContractTransaction,
PayableOverrides,
TypedDataDomain,
} from "ethers";
import { BigNumber } from "ethers";

import { Messages } from "../../collections";
import type { BaseResult, PaymentMethod } from "../../interface";
import { generateSignatureDomain, isNativeCurrency } from "../../utils";
import type { BaseResult } from "../../interface";
import { MasaSBTModuleBase } from "./sbt/masa-sbt-module-base";

export class Identity extends MasaSBTModuleBase {
/**
* purchase only identity
*/
public purchase = async (): Promise<ContractTransaction> => {
const {
estimateGas: { purchaseIdentity: estimateGas },
purchaseIdentity,
} = this.instances.SoulStoreContract;

// estimate gas
const gasLimit = await this.estimateGasWithSlippage(estimateGas);

return await purchaseIdentity({ gasLimit });
};

/**
* purchase identity with name
* @param paymentMethod
* @param name
* @param nameLength
* @param duration
* @param metadataURL
* @param authorityAddress
* @param signature
*/
public purchaseIdentityAndName = async (
paymentMethod: PaymentMethod,
name: string,
nameLength: number,
duration: number = 1,
metadataURL: string,
authorityAddress: string,
signature: string,
): Promise<ContractTransaction> => {
const domain: TypedDataDomain = await generateSignatureDomain(
this.masa.config.signer,
"SoulStore",
this.instances.SoulStoreContract.address,
);

const value: {
to: string;
name: string;
nameLength: number;
yearsPeriod: number;
tokenURI: string;
} = {
to: await this.masa.config.signer.getAddress(),
name,
nameLength,
yearsPeriod: duration,
tokenURI: metadataURL,
};

await this.verify(
"Verifying soul name failed!",
this.instances.SoulStoreContract,
domain,
this.masa.contracts.soulName.types,
value,
signature,
authorityAddress,
);

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

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

const purchaseIdentityAndNameParameters: [
string, // paymentMethod: PromiseOrValue<string>
string, // name: PromiseOrValue<string>
number, // nameLength: PromiseOrValue<BigNumberish>
number, // yearsPeriod: PromiseOrValue<BigNumberish>
string, // tokenURI: PromiseOrValue<string>
string, // authorityAddress: PromiseOrValue<string>
string, // signature: PromiseOrValue<BytesLike>
] = [
paymentAddress,
name,
nameLength,
duration,
metadataURL,
authorityAddress,
signature,
];

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

if (this.masa.config.verbose) {
console.log({
purchaseIdentityAndNameParameters,
purchaseIdentityAndNameOverrides,
});
}

// connect
const {
estimateGas: { purchaseIdentityAndName: estimateGas },
purchaseIdentityAndName,
} = this.instances.SoulStoreContract;

// estimate gas
const gasLimit = await this.estimateGasWithSlippage(
estimateGas,
purchaseIdentityAndNameParameters,
purchaseIdentityAndNameOverrides,
);

// execute tx
return purchaseIdentityAndName(...purchaseIdentityAndNameParameters, {
...purchaseIdentityAndNameOverrides,
gasLimit,
});
};

/**
*
* @param identityId
Expand Down
Loading

0 comments on commit 1783a34

Please sign in to comment.