-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from masa-finance/h34d/chore/remove-sbt-create
chore (remove sbt create): removed all deploy, mint and sign methods
- Loading branch information
Showing
12 changed files
with
4 additions
and
1,439 deletions.
There are no files selected for viewing
209 changes: 1 addition & 208 deletions
209
src/contracts/contract-modules/sbt/ASBT/asbt-contract-wrapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Contract> { | ||
/** | ||
* | ||
* @param paymentMethod | ||
* @param receiver | ||
*/ | ||
public mint = async ( | ||
paymentMethod: PaymentMethod, | ||
receiver: string, | ||
): Promise<BaseResultWithTokenId> => { | ||
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<BaseResult[]> => { | ||
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<Contract> {} |
Oops, something went wrong.