diff --git a/src/contracts/contract-modules/sbt/ASBT/asbt-contract-wrapper.ts b/src/contracts/contract-modules/sbt/ASBT/asbt-contract-wrapper.ts index 1788c083..554f4d3c 100644 --- a/src/contracts/contract-modules/sbt/ASBT/asbt-contract-wrapper.ts +++ b/src/contracts/contract-modules/sbt/ASBT/asbt-contract-wrapper.ts @@ -1,214 +1,7 @@ -import { LogDescription } from "@ethersproject/abi"; -import { BigNumber } from "@ethersproject/bignumber"; import { ReferenceSBTAuthority } from "@masa-finance/masa-contracts-identity"; -import { PayableOverrides } from "ethers"; -import { Messages } from "../../../../collections"; -import type { - BaseResult, - BaseResultWithTokenId, - PaymentMethod, -} from "../../../../interface"; -import { isNativeCurrency } from "../../../../utils"; import { SBTContractWrapper } from "../SBT/sbt-contract-wrapper"; export class ASBTContractWrapper< Contract extends ReferenceSBTAuthority, -> extends SBTContractWrapper { - /** - * - * @param paymentMethod - * @param receiver - */ - public mint = async ( - paymentMethod: PaymentMethod, - receiver: string, - ): Promise => { - const result: BaseResultWithTokenId = { success: false }; - - // current limit for ASBT is 1 on the default installation - let limit: number = 1; - - try { - limit = (await this.contract.maxSBTToMint()).toNumber(); - } catch { - if (this.masa.config.verbose) { - console.info("Loading limit failed, falling back to 1!"); - } - } - - try { - const balance: BigNumber = await this.contract.balanceOf(receiver); - - if (limit > 0 && balance.gte(limit)) { - result.message = `Minting of ASBT failed: '${receiver}' exceeded the limit of '${limit}'!`; - console.error(result.message); - return result; - } - } catch (error: unknown) { - if (error instanceof Error) { - console.warn(`Loading SBT balance failed! ${error.message}`); - } - } - - const { price, paymentAddress } = await this.getPrice(paymentMethod); - - const mintASBTArguments: [ - string, // paymentAddress string - string, // receiver string - ] = [paymentAddress, receiver]; - - const mintASBTOverrides: PayableOverrides = await this.createOverrides( - isNativeCurrency(paymentMethod) ? price : undefined, - ); - - if (this.masa.config.verbose) { - console.info(mintASBTArguments, mintASBTOverrides); - } - - const { - "mint(address,address)": mint, - estimateGas: { "mint(address,address)": estimateGas }, - } = this.contract; - - try { - const gasLimit = await this.estimateGasWithSlippage( - estimateGas, - mintASBTArguments, - mintASBTOverrides, - ); - - const { wait, hash } = await mint(...mintASBTArguments, { - ...mintASBTOverrides, - gasLimit, - }); - - console.log( - Messages.WaitingToFinalize( - hash, - this.masa.config.network?.blockExplorerUrls?.[0], - ), - ); - - const { logs } = await wait(); - - const parsedLogs = this.masa.contracts.parseLogs(logs, [this.contract]); - - const mintEvent = parsedLogs.find( - (log: LogDescription) => log.name === "Mint", - ); - - if (mintEvent) { - const { args } = mintEvent; - console.log( - `Minted to token with ID: ${args._tokenId} receiver '${args._owner}'`, - ); - - result.success = true; - } - } catch (error: unknown) { - if (error instanceof Error) { - result.message = `Minting ASBT failed! ${error.message}`; - console.error(result.message); - } - } - - return result; - }; - - /** - * - * @param paymentMethod - * @param receivers - */ - public bulkMint = async ( - paymentMethod: PaymentMethod, - receivers: string[], - ): Promise => { - const result: BaseResult[] = []; - - // current limit for ASBT is 1 on the default installation - let limit: number = 1; - - try { - limit = (await this.contract.maxSBTToMint()).toNumber(); - } catch { - if (this.masa.config.verbose) { - console.info("Loading limit failed, falling back to 1!"); - } - } - - for (const receiver of receivers) { - try { - const balance: BigNumber = await this.contract.balanceOf(receiver); - - if (limit > 0 && balance.gte(limit)) { - const errorMessage = `Minting of ASBT failed: '${receiver}' exceeded the limit of '${limit}'!`; - console.error(errorMessage); - result.push({ success: false, message: errorMessage }); - } - } catch (error: unknown) { - if (error instanceof Error) { - console.warn(`Loading SBT balance failed! ${error.message}`); - } - } - } - - const { price, paymentAddress } = await this.getPrice(paymentMethod); - - const mintASBTArguments: [ - string, // paymentAddress string - string[], // receivers string[] - ] = [paymentAddress, receivers]; - - const mintASBTOverrides: PayableOverrides = await this.createOverrides( - isNativeCurrency(paymentMethod) ? price : undefined, - ); - - if (this.masa.config.verbose) { - console.info(mintASBTArguments, mintASBTOverrides); - } - - const { - "mint(address,address[])": mint, - estimateGas: { "mint(address,address[])": estimateGas }, - } = this.contract; - - const gasLimit = await this.estimateGasWithSlippage( - estimateGas, - mintASBTArguments, - mintASBTOverrides, - ); - - const { wait, hash } = await mint(...mintASBTArguments, { - ...mintASBTOverrides, - gasLimit, - }); - - console.log( - Messages.WaitingToFinalize( - hash, - this.masa.config.network?.blockExplorerUrls?.[0], - ), - ); - - const { logs } = await wait(); - - const parsedLogs = this.masa.contracts.parseLogs(logs, [this.contract]); - - const mintEvent = parsedLogs.find( - (log: LogDescription) => log.name === "Mint", - ); - - if (mintEvent) { - const { args } = mintEvent; - console.log( - `Minted to token with ID: ${args._tokenId} receiver '${args._owner}'`, - ); - - result.push({ success: true }); - } - - return result; - }; -} +> extends SBTContractWrapper {} diff --git a/src/contracts/contract-modules/sbt/SSSBT/sssbt-contract-wrapper.ts b/src/contracts/contract-modules/sbt/SSSBT/sssbt-contract-wrapper.ts index 754fdb6e..e3b77f94 100644 --- a/src/contracts/contract-modules/sbt/SSSBT/sssbt-contract-wrapper.ts +++ b/src/contracts/contract-modules/sbt/SSSBT/sssbt-contract-wrapper.ts @@ -1,20 +1,6 @@ -import { LogDescription } from "@ethersproject/abi"; -import { BigNumber } from "@ethersproject/bignumber"; import { ReferenceSBTSelfSovereign } from "@masa-finance/masa-contracts-identity"; import type { TypedDataField } from "ethers"; -import { PayableOverrides, TypedDataDomain } from "ethers"; -import { Messages } from "../../../../collections"; -import type { - BaseResultWithTokenId, - PaymentMethod, - PriceInformation, -} from "../../../../interface"; -import { - generateSignatureDomain, - isNativeCurrency, - signTypedData, -} from "../../../../utils"; import { SBTContractWrapper } from "../SBT/sbt-contract-wrapper"; export class SSSBTContractWrapper< @@ -30,231 +16,4 @@ export class SSSBTContractWrapper< { name: "signatureDate", type: "uint256" }, ], }; - - /** - * Signs an SBT based on its address - * @param name - * @param types - * @param value - */ - public sign = async ( - name: string, - types: Record>, - value: Record, - ): Promise<{ - signature: string; - authorityAddress: string; - }> => { - const authorityAddress = await this.masa.config.signer.getAddress(); - - const { signature, domain } = await signTypedData({ - contract: this.contract, - signer: this.masa.config.signer, - name, - types, - value, - }); - - await this.verify( - "Signing SBT failed!", - this.contract, - domain, - types, - value, - signature, - authorityAddress, - ); - - return { signature, authorityAddress }; - }; - - /** - * - * @param paymentMethod - * @param name - * @param types - * @param value - * @param signature - * @param authorityAddress - * @param slippage - */ - protected prepareMint = async ( - paymentMethod: PaymentMethod, - name: string, - types: Record>, - value: Record, - signature: string, - authorityAddress: string, - slippage: number | undefined = 250, - ): Promise => { - const domain: TypedDataDomain = await generateSignatureDomain( - this.masa.config.signer, - name, - this.contract.address, - ); - - await this.verify( - "Verifying SBT failed!", - this.contract, - domain, - types, - value, - signature, - authorityAddress, - ); - - const sssbtMintPriceInfo = await this.getPrice(paymentMethod, slippage); - - if (this.masa.config.verbose) { - console.dir( - { - sssbtMintPriceInfo, - }, - { - depth: null, - }, - ); - } - - return sssbtMintPriceInfo; - }; - - /** - * - * @param paymentMethod - * @param receiver - * @param signature - * @param signatureDate - * @param authorityAddress - */ - public mint = async ( - paymentMethod: PaymentMethod, - receiver: string, - signature: string, - signatureDate: number, - authorityAddress: string, - ): Promise => { - const result: BaseResultWithTokenId = { success: false }; - - // current limit for SSSBT is 1 on the default installation - let limit: number = 1; - - try { - limit = (await this.contract.maxSBTToMint()).toNumber(); - } catch { - if (this.masa.config.verbose) { - console.info("Loading limit failed, falling back to 1!"); - } - } - - try { - const balance: BigNumber = await this.contract.balanceOf(receiver); - - if (limit > 0 && balance.gte(limit)) { - result.message = `Minting of SSSBT failed: '${receiver}' exceeded the limit of '${limit}'!`; - console.error(result.message); - return result; - } - } catch (error: unknown) { - if (error instanceof Error) { - console.warn(`Loading SBT balance failed! ${error.message}`); - } - } - - // fill the collection with data - const value: { - to: string; - authorityAddress: string; - signatureDate: number; - } = { - to: receiver, - authorityAddress, - signatureDate, - }; - - const { price, paymentAddress } = await this.prepareMint( - paymentMethod, - "ReferenceSBTSelfSovereign", - this.types, - value, - signature, - authorityAddress, - ); - - const mintSSSBTArguments: [ - string, // paymentMethod string - string, // to string - string, // authorityAddress string - number, // authorityAddress number - string, // signature string - ] = [paymentAddress, receiver, authorityAddress, signatureDate, signature]; - - const mintSSSBTOverrides: PayableOverrides = await this.createOverrides( - isNativeCurrency(paymentMethod) ? price : undefined, - ); - - if (this.masa.config.verbose) { - console.dir( - { - mintSSSBTArguments, - mintSSSBTOverrides, - }, - { - depth: null, - }, - ); - } - - const { - "mint(address,address,address,uint256,bytes)": mint, - estimateGas: { - "mint(address,address,address,uint256,bytes)": estimateGas, - }, - } = this.contract; - - try { - const gasLimit = await this.estimateGasWithSlippage( - estimateGas, - mintSSSBTArguments, - mintSSSBTOverrides, - ); - - const { wait, hash } = await mint(...mintSSSBTArguments, { - ...mintSSSBTOverrides, - gasLimit, - }); - - console.log( - Messages.WaitingToFinalize( - hash, - this.masa.config.network?.blockExplorerUrls?.[0], - ), - ); - - const { logs } = await wait(); - - const parsedLogs = this.masa.contracts.parseLogs(logs, [this.contract]); - - const mintEvent = parsedLogs.find( - (log: LogDescription) => log.name === "Mint", - ); - - if (mintEvent) { - const { args } = mintEvent; - console.log( - `Minted to token with ID: ${args._tokenId} receiver '${args._owner}'`, - ); - - result.success = true; - result.tokenId = args._tokenId; - } - } catch (error: unknown) { - if (error instanceof Error) { - result.message = `Minting SSSBT failed! ${error.message}`; - console.error(result.message); - } - } - - return result; - }; } diff --git a/src/contracts/contract-modules/sbt/dynamic/SSSBT/dynamic-sssbt-contract-wrapper.ts b/src/contracts/contract-modules/sbt/dynamic/SSSBT/dynamic-sssbt-contract-wrapper.ts index e6cc1282..5083abb8 100644 --- a/src/contracts/contract-modules/sbt/dynamic/SSSBT/dynamic-sssbt-contract-wrapper.ts +++ b/src/contracts/contract-modules/sbt/dynamic/SSSBT/dynamic-sssbt-contract-wrapper.ts @@ -1,16 +1,6 @@ -import { LogDescription } from "@ethersproject/abi"; -import { BigNumber } from "@ethersproject/bignumber"; import { MasaDynamicSSSBT } from "@masa-finance/masa-contracts-identity"; import type { TypedDataField } from "ethers"; -import { PayableOverrides, TypedDataDomain } from "ethers"; -import { Messages } from "../../../../../collections"; -import type { BaseResult, PaymentMethod } from "../../../../../interface"; -import { - generateSignatureDomain, - isNativeCurrency, - signTypedData, -} from "../../../../../utils"; import { DynamicSBTContractWrapper } from "../dynamic-sbt-contract-wrapper"; export class DynamicSSSBTContractWrapper< @@ -28,300 +18,4 @@ export class DynamicSSSBTContractWrapper< { name: "signatureDate", type: "uint256" }, ], }; - - /** - * Signs an SBT based on its address - * @param types - * @param value - */ - public signSetState = async ( - types: Record>, - value: Record, - ): Promise<{ - signature: string; - authorityAddress: string; - }> => { - const authorityAddress = await this.masa.config.signer.getAddress(); - - const { signature, domain } = await signTypedData({ - contract: this.contract, - signer: this.masa.config.signer, - types, - value, - }); - - await this.verify( - "Signing Dynamic SBT failed!", - this.contract, - domain, - types, - value, - signature, - authorityAddress, - ); - - return { signature, authorityAddress }; - }; - - /** - * - * @param types - * @param value - * @param signature - * @param authorityAddress - */ - protected prepareSetState = async ( - types: Record>, - value: Record, - signature: string, - authorityAddress: string, - ): Promise => { - const result: BaseResult = { success: false }; - - const { name, version, verifyingContract } = - await this.contract.eip712Domain(); - - const domain: TypedDataDomain = await generateSignatureDomain( - this.masa.config.signer, - name, - verifyingContract, - version, - ); - - await this.verify( - "Verifying Dynamic SBT failed!", - this.contract, - domain, - types, - value, - signature, - authorityAddress, - ); - - result.success = true; - - return result; - }; - - /** - * - * @param receiver - * @param state - * @param stateValue - * @param signature - * @param signatureDate - * @param authorityAddress - */ - public setState = async ( - receiver: string, - state: string, - stateValue: boolean, - signature: string, - signatureDate: number, - authorityAddress: string, - ): Promise => { - const result: BaseResult = { success: false }; - - const [possibleStates, stateAlreadySet, name] = await Promise.all([ - this.contract.getBeforeMintStates(), - this.contract.beforeMintState(receiver, state), - this.contract.name(), - ]); - - if (stateAlreadySet) { - result.message = `State '${state}' already set on ${name} for ${receiver}`; - console.error(result.message); - return result; - } - - if ( - !possibleStates - .map((state: string) => state.toLowerCase()) - .includes(state.toLowerCase()) - ) { - result.message = `State '${state}' unknown to contract ${name}`; - console.error(result.message); - return result; - } - - const value: { - account: string; - state: string; - value: boolean; - authorityAddress: string; - signatureDate: number; - } = { - account: receiver, - state, - value: stateValue, - authorityAddress, - signatureDate, - }; - - const { - "setState(address,string,bool,address,uint256,bytes)": setState, - estimateGas: { - "setState(address,string,bool,address,uint256,bytes)": estimateGas, - }, - } = this.contract; - - await this.prepareSetState(this.types, value, signature, authorityAddress); - - const dynamicSSSBTSetStateArguments: [ - account: string, - state: string, - value: boolean, - authorityAddress: string, - signatureDate: number, - signature: string, - ] = [ - receiver, - state, - stateValue, - authorityAddress, - signatureDate, - signature, - ]; - - const mintSSSBTOverrides: PayableOverrides = await this.createOverrides(); - - try { - const gasLimit = await this.estimateGasWithSlippage( - estimateGas, - dynamicSSSBTSetStateArguments, - mintSSSBTOverrides, - ); - - const { wait, hash } = await setState(...dynamicSSSBTSetStateArguments, { - ...mintSSSBTOverrides, - gasLimit, - }); - - console.log( - Messages.WaitingToFinalize( - hash, - this.masa.config.network?.blockExplorerUrls?.[0], - ), - ); - - await wait(); - result.success = true; - } catch (error: unknown) { - if (error instanceof Error) { - result.message = `Setting state failed! ${error.message}`; - console.error(result.message); - } - } - - return result; - }; - - /** - * - * @param paymentMethod - * @param receiver - */ - public mint = async ( - paymentMethod: PaymentMethod, - receiver: string, - ): Promise => { - const result: BaseResult = { success: false }; - - // current limit for SSSBT is 1 on the default installation - let limit: number = 1; - - try { - limit = (await this.contract.maxSBTToMint()).toNumber(); - } catch { - if (this.masa.config.verbose) { - console.info("Loading limit failed, falling back to 1!"); - } - } - - try { - const balance: BigNumber = await this.contract.balanceOf(receiver); - - if (limit > 0 && balance.gte(limit)) { - result.message = `Minting of SSSBT failed: '${receiver}' exceeded the limit of '${limit}'!`; - console.error(result.message); - return result; - } - } catch (error: unknown) { - if (error instanceof Error) { - console.warn(`Unable to load balance ${error.message}`); - } - } - - const { price, paymentAddress } = await this.getPrice(paymentMethod); - - const mintSSSBTArguments: [ - string, // paymentMethod string - string, // receiver string - ] = [paymentAddress, receiver]; - - const mintSSSBTOverrides: PayableOverrides = await this.createOverrides( - isNativeCurrency(paymentMethod) ? price : undefined, - ); - - if (this.masa.config.verbose) { - console.dir( - { - mintSSSBTArguments, - mintSSSBTOverrides, - }, - { - depth: null, - }, - ); - } - - const { - "mint(address,address)": mint, - estimateGas: { "mint(address,address)": estimateGas }, - } = this.contract; - - try { - const gasLimit = await this.estimateGasWithSlippage( - estimateGas, - mintSSSBTArguments, - mintSSSBTOverrides, - ); - - const { wait, hash } = await mint(...mintSSSBTArguments, { - ...mintSSSBTOverrides, - gasLimit, - }); - - console.log( - Messages.WaitingToFinalize( - hash, - this.masa.config.network?.blockExplorerUrls?.[0], - ), - ); - - const { logs } = await wait(); - - const parsedLogs = this.masa.contracts.parseLogs(logs, [this.contract]); - - const mintEvent = parsedLogs.find( - (log: LogDescription) => log.name === "Mint", - ); - - if (mintEvent) { - const { args } = mintEvent; - console.log( - `Minted to token with ID: ${args._tokenId} receiver '${args._owner}'`, - ); - - result.success = true; - } - } catch (error: unknown) { - if (error instanceof Error) { - result.message = `Minting failed! ${error.message}`; - console.error(result.message); - } - } - - return result; - }; } diff --git a/src/modules/sbt/ASBT/deploy.ts b/src/modules/sbt/ASBT/deploy.ts deleted file mode 100644 index 8eeb9edb..00000000 --- a/src/modules/sbt/ASBT/deploy.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { - abi, - bytecode, -} from "@masa-finance/masa-contracts-identity/artifacts/contracts/reference/ReferenceSBTAuthority.sol/ReferenceSBTAuthority.json"; -import { PaymentGateway } from "@masa-finance/masa-contracts-identity/dist/typechain/contracts/reference/ReferenceSBTAuthority"; -import { constants, ContractFactory } from "ethers"; - -import { Messages } from "../../../collections"; -import type { DeployResult, MasaInterface } from "../../../interface"; -import PaymentParamsStruct = PaymentGateway.PaymentParamsStruct; - -export const deployASBT = async ({ - masa, - name, - symbol, - baseTokenUri, - limit = 1, - adminAddress, - paymentOptions, -}: { - masa: MasaInterface; - name: string; - symbol: string; - baseTokenUri: string; - limit?: number; - adminAddress?: string; - paymentOptions?: { - projectFeeReceiver: string; - }; -}): Promise | undefined> => { - let result: DeployResult | undefined; - - adminAddress = adminAddress || (await masa.config.signer.getAddress()); - - console.log( - `Deploying ASBT contract to network '${masa.config.networkName}'`, - ); - - if ( - masa.contracts.instances.SoulboundIdentityContract.address === - constants.AddressZero || - !masa.contracts.instances.SoulboundIdentityContract.hasAddress - ) { - console.warn("Identity contract is not deployed to this network!"); - } - - const contractFactory: ContractFactory = new ContractFactory( - abi, - bytecode, - masa.config.signer, - ); - - const deployASBTArguments: [ - string, // address admin - string, // string name - string, // string symbol - string, // string baseTokenURI - string, // address soulboundIdentity - PaymentParamsStruct, // PaymentParams paymentParams, - number, // number _maxSBTToMint - ] = [ - adminAddress, - name, - symbol, - baseTokenUri, - masa.contracts.instances.SoulboundIdentityContract.address || - constants.AddressZero, - { - // get this from the sdk - swapRouter: constants.AddressZero, - // get this from the sdk - wrappedNativeToken: constants.AddressZero, - // get this from the sdk - stableCoin: constants.AddressZero, - masaToken: - masa.config.network?.addresses.tokens?.MASA || constants.AddressZero, - projectFeeReceiver: - paymentOptions?.projectFeeReceiver || constants.AddressZero, - // get this from the sdk - protocolFeeReceiver: constants.AddressZero, - protocolFeeAmount: 0, - protocolFeePercent: 0, - protocolFeePercentSub: 0, - }, - limit, - ]; - - const abiEncodedDeployASBTArguments = - contractFactory.interface.encodeDeploy(deployASBTArguments); - if (masa.config.verbose) { - console.dir( - { - deployASBTArguments, - abiEncodedDeployASBTArguments, - }, - { depth: null }, - ); - } - - try { - const { - deployTransaction: { wait, hash }, - address, - } = await contractFactory.deploy(...deployASBTArguments); - console.log( - Messages.WaitingToFinalize( - hash, - masa.config.network?.blockExplorerUrls?.[0], - ), - ); - - await wait(); - - console.log( - `ASBT successfully deployed to '${masa.config.networkName}' with contract address: '${address}'`, - ); - - result = { - address, - constructorArguments: deployASBTArguments, - abiEncodedConstructorArguments: abiEncodedDeployASBTArguments, - }; - } catch (error: unknown) { - if (error instanceof Error) { - console.error("ASBT deployment failed!", error.message); - } - } - - return result; -}; diff --git a/src/modules/sbt/ASBT/index.ts b/src/modules/sbt/ASBT/index.ts index 06fe7694..abeb17e0 100644 --- a/src/modules/sbt/ASBT/index.ts +++ b/src/modules/sbt/ASBT/index.ts @@ -1,3 +1,2 @@ -export * from "./deploy"; export * from "./masa-asbt"; export * from "./masa-asbt-wrapper"; diff --git a/src/modules/sbt/ASBT/masa-asbt-wrapper.ts b/src/modules/sbt/ASBT/masa-asbt-wrapper.ts index f460656b..941ca492 100644 --- a/src/modules/sbt/ASBT/masa-asbt-wrapper.ts +++ b/src/modules/sbt/ASBT/masa-asbt-wrapper.ts @@ -1,58 +1,7 @@ import type { ReferenceSBTAuthority } from "@masa-finance/masa-contracts-identity"; -import type { BaseResultWithTokenId, PaymentMethod } from "../../../interface"; import { MasaSBTWrapper } from "../SBT/masa-sbt-wrapper"; export class MasaASBTWrapper< Contract extends ReferenceSBTAuthority, -> extends MasaSBTWrapper { - /** - * - * @param receiver - * @param paymentMethod - */ - mint = async ( - receiver: string, - paymentMethod: PaymentMethod = "ETH", - ): Promise => { - const [name, symbol] = await Promise.all([ - this.contract.name(), - this.contract.symbol(), - ]); - - console.log(`Minting ASBT on: '${this.masa.config.networkName}'`); - console.log(`Contract Name: '${name}'`); - console.log(`Contract Symbol: '${symbol}'`); - console.log(`Contract Address: '${this.contract.address}'`); - console.log(`To receiver: '${receiver}'`); - - const { mint } = this.masa.contracts.asbt.attach(this.contract); - - return mint(paymentMethod, receiver); - }; - - /** - * - * @param receivers - * @param paymentMethod - */ - bulkMint = async ( - receivers: string[], - paymentMethod: PaymentMethod = "ETH", - ) => { - const [name, symbol] = await Promise.all([ - this.contract.name(), - this.contract.symbol(), - ]); - - console.log(`Bulk Minting ASBT on: '${this.masa.config.networkName}'`); - console.log(`Contract Name: '${name}'`); - console.log(`Contract Symbol: '${symbol}'`); - console.log(`Contract Address: '${this.contract.address}'`); - console.log(`To receiver: '${receivers}'`); - - const { bulkMint } = this.masa.contracts.asbt.attach(this.contract); - - return bulkMint(paymentMethod, receivers); - }; -} +> extends MasaSBTWrapper {} diff --git a/src/modules/sbt/ASBT/masa-asbt.ts b/src/modules/sbt/ASBT/masa-asbt.ts index 32b28083..53ad8ed1 100644 --- a/src/modules/sbt/ASBT/masa-asbt.ts +++ b/src/modules/sbt/ASBT/masa-asbt.ts @@ -3,40 +3,9 @@ import { ReferenceSBTAuthority__factory } from "@masa-finance/masa-contracts-ide import type { ContractFactory } from "../../../interface/contract-factory"; import { MasaBase } from "../../../masa-base"; -import { deployASBT } from "./deploy"; import { MasaASBTWrapper } from "./masa-asbt-wrapper"; export class MasaASBT extends MasaBase { - /** - * - * @param name - * @param symbol - * @param baseTokenUri - * @param limit - * @param adminAddress - */ - public deploy = ({ - name, - symbol, - baseTokenUri, - limit = 1, - adminAddress, - }: { - name: string; - symbol: string; - baseTokenUri: string; - limit?: number; - adminAddress?: string; - }) => - deployASBT({ - masa: this.masa, - name, - symbol, - baseTokenUri, - limit, - adminAddress, - }); - /** * * @param contract diff --git a/src/modules/sbt/SSSBT/deploy.ts b/src/modules/sbt/SSSBT/deploy.ts deleted file mode 100644 index 57eaea79..00000000 --- a/src/modules/sbt/SSSBT/deploy.ts +++ /dev/null @@ -1,160 +0,0 @@ -import type { ReferenceSBTSelfSovereign } from "@masa-finance/masa-contracts-identity"; -import { - abi, - bytecode, -} from "@masa-finance/masa-contracts-identity/artifacts/contracts/reference/ReferenceSBTSelfSovereign.sol/ReferenceSBTSelfSovereign.json"; -import { PaymentGateway } from "@masa-finance/masa-contracts-identity/dist/typechain/contracts/reference/ReferenceSBTSelfSovereign"; -import { constants, ContractFactory } from "ethers"; - -import { Messages } from "../../../collections"; -import type { DeployResult, MasaInterface } from "../../../interface"; -import PaymentParamsStruct = PaymentGateway.PaymentParamsStruct; - -export const deploySSSBT = async ({ - masa, - name, - symbol, - baseTokenUri, - limit = 1, - authorityAddress, - adminAddress, - paymentOptions, -}: { - masa: MasaInterface; - name: string; - symbol: string; - baseTokenUri: string; - limit: number; - authorityAddress?: string; - adminAddress?: string; - paymentOptions?: { - projectFeeReceiver: string; - }; -}): Promise | undefined> => { - let result: DeployResult | undefined; - const signerAddress = await masa.config.signer.getAddress(); - - adminAddress = adminAddress || signerAddress; - authorityAddress = authorityAddress || signerAddress; - - console.log( - `Deploying SSSBT contract to network '${masa.config.networkName}'`, - ); - - if ( - masa.contracts.instances.SoulboundIdentityContract.address === - constants.AddressZero || - !masa.contracts.instances.SoulboundIdentityContract.hasAddress - ) { - console.warn("Identity contract is not deployed to this network!"); - } - - const contractFactory: ContractFactory = new ContractFactory( - abi, - bytecode, - masa.config.signer, - ); - - const deploySSSBTArguments: [ - string, // address admin - string, // string name - string, // string symbol - string, // string baseTokenURI - string, // address soulboundIdentity - PaymentParamsStruct, // PaymentParams paymentParams - number, - ] = [ - adminAddress, - name, - symbol, - baseTokenUri, - masa.contracts.instances.SoulboundIdentityContract.address || - constants.AddressZero, - { - // get this from the sdk - swapRouter: constants.AddressZero, - // get this from the sdk - wrappedNativeToken: constants.AddressZero, - // get this from the sdk - stableCoin: constants.AddressZero, - masaToken: - masa.config.network?.addresses.tokens?.MASA || constants.AddressZero, - projectFeeReceiver: - paymentOptions?.projectFeeReceiver || constants.AddressZero, - // get this from the sdk - protocolFeeReceiver: constants.AddressZero, - protocolFeeAmount: 0, - protocolFeePercent: 0, - protocolFeePercentSub: 0, - }, - limit, - ]; - - const abiEncodedDeploySSSBTArguments = - contractFactory.interface.encodeDeploy(deploySSSBTArguments); - if (masa.config.verbose) { - console.dir( - { - deploySSSBTArguments, - abiEncodedDeploySSSBTArguments, - }, - { depth: null }, - ); - } - - try { - const { - addAuthority, - deployTransaction: { wait, hash }, - address, - } = (await contractFactory.deploy( - ...deploySSSBTArguments, - )) as ReferenceSBTSelfSovereign; - - console.log( - Messages.WaitingToFinalize( - hash, - masa.config.network?.blockExplorerUrls?.[0], - ), - ); - - await wait(); - - if (adminAddress === signerAddress) { - console.log(`Adding authority: '${authorityAddress}' to '${address}'`); - - const { wait, hash } = await addAuthority(authorityAddress); - - console.log( - Messages.WaitingToFinalize( - hash, - masa.config.network?.blockExplorerUrls?.[0], - ), - ); - - await wait(); - } else { - console.log( - `Authority: ${authorityAddress} could not be added because ${signerAddress} is not the admin!`, - ); - - console.log(`Please add authority manually from ${adminAddress}`); - } - - console.log( - `SSSBT successfully deployed to '${masa.config.networkName}' with contract address: '${address}'`, - ); - - result = { - address, - constructorArguments: deploySSSBTArguments, - abiEncodedConstructorArguments: abiEncodedDeploySSSBTArguments, - }; - } catch (error: unknown) { - if (error instanceof Error) { - console.error("SSSBT deployment failed!", error.message); - } - } - - return result; -}; diff --git a/src/modules/sbt/SSSBT/index.ts b/src/modules/sbt/SSSBT/index.ts index 746237db..ae26f0c6 100644 --- a/src/modules/sbt/SSSBT/index.ts +++ b/src/modules/sbt/SSSBT/index.ts @@ -1,3 +1,2 @@ -export * from "./deploy"; export * from "./masa-sssbt"; export * from "./masa-sssbt-wrapper"; diff --git a/src/modules/sbt/SSSBT/masa-sssbt-wrapper.ts b/src/modules/sbt/SSSBT/masa-sssbt-wrapper.ts index c99660c9..8c09bfad 100644 --- a/src/modules/sbt/SSSBT/masa-sssbt-wrapper.ts +++ b/src/modules/sbt/SSSBT/masa-sssbt-wrapper.ts @@ -1,106 +1,7 @@ import type { ReferenceSBTSelfSovereign } from "@masa-finance/masa-contracts-identity"; -import type { BaseResultWithTokenId, PaymentMethod } from "../../../interface"; import { MasaSBTWrapper } from "../SBT/masa-sbt-wrapper"; export class MasaSSSBTWrapper< Contract extends ReferenceSBTSelfSovereign, -> extends MasaSBTWrapper { - /** - * - * @param receiver - */ - sign = async (receiver: string) => { - let result: - | { - authorityAddress: string; - signatureDate: number; - signature: string; - } - | undefined; - - const [name, symbol] = await Promise.all([ - this.contract.name(), - this.contract.symbol(), - ]); - - console.log(`Signing SSSBT on: '${this.masa.config.networkName}'`); - console.log(`Contract Name: '${name}'`); - console.log(`Contract Symbol: '${symbol}'`); - console.log(`Contract Address: '${this.contract.address}'`); - console.log(`To receiver: '${receiver}'`); - - const signatureDate = Date.now(); - - // fill the collection with data - const value: { - to: string; - authorityAddress: string; - signatureDate: number; - } = { - to: receiver, - authorityAddress: await this.masa.config.signer.getAddress(), - signatureDate, - }; - - const { sign, types } = this.masa.contracts.sssbt.attach(this.contract); - - // sign to create a signature - const signResult = await sign("ReferenceSBTSelfSovereign", types, value); - - if (signResult) { - const { signature, authorityAddress } = signResult; - if (this.masa.config.verbose) { - console.info({ - signature, - authorityAddress, - signatureDate, - }); - } - result = { - authorityAddress, - signatureDate, - signature, - }; - } - - return result; - }; - - /** - * - * @param authorityAddress - * @param signatureDate - * @param signature - * @param paymentMethod - */ - mint = async ( - authorityAddress: string, - signatureDate: number, - signature: string, - paymentMethod: PaymentMethod = "ETH", - ): Promise => { - const receiver = await this.masa.config.signer.getAddress(); - - const [name, symbol] = await Promise.all([ - this.contract.name(), - this.contract.symbol(), - ]); - - console.log(`Minting SSSBT on: '${this.masa.config.networkName}'`); - console.log(`Contract Name: '${name}'`); - console.log(`Contract Symbol: '${symbol}'`); - console.log(`Contract Address: '${this.contract.address}'`); - console.log(`To receiver: '${receiver}'`); - - const { mint } = this.masa.contracts.sssbt.attach(this.contract); - - return mint( - paymentMethod, - receiver, - signature, - signatureDate, - authorityAddress, - ); - }; -} +> extends MasaSBTWrapper {} diff --git a/src/modules/sbt/SSSBT/masa-sssbt.ts b/src/modules/sbt/SSSBT/masa-sssbt.ts index edfd0831..c7b1bd76 100644 --- a/src/modules/sbt/SSSBT/masa-sssbt.ts +++ b/src/modules/sbt/SSSBT/masa-sssbt.ts @@ -3,44 +3,9 @@ import { ReferenceSBTSelfSovereign__factory } from "@masa-finance/masa-contracts import type { ContractFactory } from "../../../interface/contract-factory"; import { MasaBase } from "../../../masa-base"; -import { deploySSSBT } from "./deploy"; import { MasaSSSBTWrapper } from "./masa-sssbt-wrapper"; export class MasaSSSBT extends MasaBase { - /** - * - * @param name - * @param symbol - * @param baseTokenUri - * @param authorityAddress - * @param limit - * @param adminAddress - */ - deploy = ({ - name, - symbol, - baseTokenUri, - limit = 1, - authorityAddress, - adminAddress, - }: { - name: string; - symbol: string; - baseTokenUri: string; - limit?: number; - authorityAddress: string; - adminAddress?: string; - }) => - deploySSSBT({ - masa: this.masa, - name, - symbol, - baseTokenUri, - limit, - authorityAddress, - adminAddress, - }); - /** * * @param contract diff --git a/src/modules/sbt/dynamic/SSSBT/masa-dynamic-sssbt-wrapper.ts b/src/modules/sbt/dynamic/SSSBT/masa-dynamic-sssbt-wrapper.ts index 203482ae..089b7e40 100644 --- a/src/modules/sbt/dynamic/SSSBT/masa-dynamic-sssbt-wrapper.ts +++ b/src/modules/sbt/dynamic/SSSBT/masa-dynamic-sssbt-wrapper.ts @@ -1,180 +1,7 @@ import type { MasaDynamicSSSBT } from "@masa-finance/masa-contracts-identity"; -import type { - BaseResult, - BaseResultWithTokenId, - PaymentMethod, -} from "../../../../interface"; import { MasaDynamicSBTWrapper } from "../masa-dynamic-sbt-wrapper"; -type SignSetStateResult = BaseResult & { - authorityAddress?: string; - signatureDate?: number; - signature?: string; -}; - export class MasaDynamicSSSBTWrapper< Contract extends MasaDynamicSSSBT, -> extends MasaDynamicSBTWrapper { - /** - * - * @param receiver - * @param state - * @param stateValue - */ - public signSetState = async ( - receiver: string, - state: string, - stateValue: boolean, - ): Promise => { - const result: SignSetStateResult = { success: false }; - - const [name, symbol] = await Promise.all([ - this.contract.name(), - this.contract.symbol(), - ]); - - console.log( - `Signing Set State for Dynamic SSSBT on: '${this.masa.config.networkName}'`, - ); - console.log(`Contract Name: '${name}'`); - console.log(`Contract Symbol: '${symbol}'`); - console.log(`Contract Address: '${this.contract.address}'`); - console.log(`State: '${state}': ${stateValue}`); - console.log(`To receiver: '${receiver}'`); - - const signatureDate = Date.now(); - - // fill the collection with data - const value: { - account: string; - state: string; - value: boolean; - authorityAddress: string; - signatureDate: number; - } = { - account: receiver, - state, - value: stateValue, - authorityAddress: await this.masa.config.signer.getAddress(), - signatureDate, - }; - - const { signSetState, types } = this.masa.contracts["dynamic-sssbt"].attach( - this.contract, - ); - - const [possibleStates, stateAlreadySet] = await Promise.all([ - this.contract.getBeforeMintStates(), - this.contract.beforeMintState(receiver, state), - ]); - - if (stateAlreadySet) { - result.message = `State '${state}' already set on ${name} for ${receiver}`; - console.error(result.message); - return result; - } - - if ( - !possibleStates - .map((state: string) => state.toLowerCase()) - .includes(state.toLowerCase()) - ) { - result.message = `State '${state}' unknown to contract ${name}`; - console.error(result.message); - return result; - } - - // sign to create a signature - const signResult = await signSetState(types, value); - - if (signResult) { - const { signature, authorityAddress } = signResult; - - if (this.masa.config.verbose) { - console.info({ - signature, - authorityAddress, - signatureDate, - }); - } - - result.success = true; - result.authorityAddress = authorityAddress; - result.signatureDate = signatureDate; - result.signature = signature; - } - - return result; - }; - - /** - * - * @param paymentMethod - */ - public mint = async ( - paymentMethod: PaymentMethod = "ETH", - ): Promise => { - const receiver = await this.masa.config.signer.getAddress(); - - const [name, symbol] = await Promise.all([ - this.contract.name(), - this.contract.symbol(), - ]); - - console.log(`Minting Dynamic SSSBT on: '${this.masa.config.networkName}'`); - console.log(`Contract Name: '${name}'`); - console.log(`Contract Symbol: '${symbol}'`); - console.log(`Contract Address: '${this.contract.address}'`); - console.log(`To receiver: '${receiver}'`); - - const { mint } = this.masa.contracts["dynamic-sssbt"].attach(this.contract); - - return mint(paymentMethod, receiver); - }; - - /** - * - * @param state - * @param stateValue - * @param signature - * @param signatureDate - * @param authorityAddress - */ - public setState = async ( - state: string, - stateValue: boolean, - signature: string, - signatureDate: number, - authorityAddress: string, - ): Promise => { - const receiver = await this.masa.config.signer.getAddress(); - - const [name, symbol] = await Promise.all([ - this.contract.name(), - this.contract.symbol(), - ]); - - console.log( - `Setting State for Dynamic SSSBT on: '${this.masa.config.networkName}'`, - ); - console.log(`Contract Name: '${name}'`); - console.log(`Contract Symbol: '${symbol}'`); - console.log(`Contract Address: '${this.contract.address}'`); - console.log(`State: '${state}': ${stateValue}`); - console.log(`To receiver: '${receiver}'`); - - const { setState } = this.masa.contracts["dynamic-sssbt"].attach( - this.contract, - ); - - return setState( - receiver, - state, - stateValue, - signature, - signatureDate, - authorityAddress, - ); - }; -} +> extends MasaDynamicSBTWrapper {}