From c728575f14e4cc084034e2a9cdc2a59a5e154bcc Mon Sep 17 00:00:00 2001 From: Martin Ndeto Date: Thu, 26 May 2022 20:23:44 +0300 Subject: [PATCH] Initialize Class --- package.json | 2 +- src/common/role.ts | 1 + src/contracts/multiwrap.ts | 110 ++++++++++++++++++++++++++++++++++++ src/core/classes/erc-721.ts | 8 ++- yarn.lock | 8 +-- 5 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 src/contracts/multiwrap.ts diff --git a/package.json b/package.json index 90d52d52e..6fcc2364d 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "ethers": "^5" }, "dependencies": { - "@thirdweb-dev/contracts": "2.3.9-1", + "@thirdweb-dev/contracts": "^2.3.8", "@web-std/file": "^3.0.0", "buffer": "^6.0.3", "cross-fetch": "^3.1.5", diff --git a/src/common/role.ts b/src/common/role.ts index e82edb64b..858d5e407 100644 --- a/src/common/role.ts +++ b/src/common/role.ts @@ -12,6 +12,7 @@ const roleMap = { editor: "EDITOR_ROLE", lister: "LISTER_ROLE", asset: "ASSET_ROLE", + unwrap: "UNWRAP_ROLE", } as const; /** diff --git a/src/contracts/multiwrap.ts b/src/contracts/multiwrap.ts new file mode 100644 index 000000000..0f4b950f5 --- /dev/null +++ b/src/contracts/multiwrap.ts @@ -0,0 +1,110 @@ +import { + ContractEncoder, + ContractEvents, + ContractMetadata, + ContractPlatformFee, + ContractPrimarySale, + ContractRoles, + ContractRoyalty, + Erc721, + GasCostEstimator, + IStorage, + NetworkOrSignerOrProvider, +} from "../core"; +import { SDKOptions, TokenErc721ContractSchema } from "../schema"; +import { + Multiwrap as MultiwrapContract, + MultiwrapContract, + SignatureDrop as SignatureDropContract, +} from "contracts"; +import { ContractWrapper } from "../core/classes/contract-wrapper"; +import { ITokenBundle } from "../../lib/Multiwrap"; +import TokenStruct = ITokenBundle.TokenStruct; + +/** + * Multiwrap lets you wrap arbitrary ERC20, ERC721 and ERC1155 tokens you own into a single wrapped token / NFT. + * + * @example + * + * ```javascript + * import { ThirdwebSDK } from "@thirdweb-dev/sdk"; + * + * const sdk = new ThirdwebSDK("rinkeby"); + * const contract = sdk.getMultiwrap("{{contract_address}}"); + * ``` + * + * @public + */ +export class Multiwrap extends Erc721 { + static contractType = "multiwrap" as const; + static contractRoles = ["transfer", "minter", "unwrap", "asset"] as const; + static contractAbi = require("../../abis/Multiwrap.json"); + + /** + * @internal + */ + static schema = TokenErc721ContractSchema; + + public encoder: ContractEncoder; + public estimator: GasCostEstimator; + public metadata: ContractMetadata; + public events: ContractEvents; + public roles: ContractRoles< + MultiwrapContract, + typeof Multiwrap.contractRoles[number] + >; + + /** + * Configure royalties + * @remarks Set your own royalties for the entire contract or per token + * @example + * ```javascript + * // royalties on the whole contract + * contract.royalty.setDefaultRoyaltyInfo({ + * seller_fee_basis_points: 100, // 1% + * fee_recipient: "0x..." + * }); + * // override royalty for a particular token + * contract.royalty.setTokenRoyaltyInfo(tokenId, { + * seller_fee_basis_points: 500, // 5% + * fee_recipient: "0x..." + * }); + * ``` + */ + public royalty: ContractRoyalty; + + constructor( + network: NetworkOrSignerOrProvider, + address: string, + storage: IStorage, + options: SDKOptions = {}, + contractWrapper = new ContractWrapper( + network, + address, + Multiwrap.contractAbi, + options, + ), + ) { + super(contractWrapper, storage, options); + this.metadata = new ContractMetadata( + this.contractWrapper, + Multiwrap.schema, + this.storage, + ); + + this.roles = new ContractRoles( + this.contractWrapper, + Multiwrap.contractRoles, + ); + this.encoder = new ContractEncoder(this.contractWrapper); + this.estimator = new GasCostEstimator(this.contractWrapper); + this.events = new ContractEvents(this.contractWrapper); + this.royalty = new ContractRoyalty(this.contractWrapper, this.metadata); + } + + public async wrap( + tokens: TokenStruct, + wrappedTokenUri: string + recipient: + ) +} diff --git a/src/core/classes/erc-721.ts b/src/core/classes/erc-721.ts index 8c2c00f99..8ed306cc2 100644 --- a/src/core/classes/erc-721.ts +++ b/src/core/classes/erc-721.ts @@ -11,6 +11,7 @@ import { DropERC721, IERC721Supply, IMintableERC721, + Multiwrap, SignatureDrop, TokenERC721, } from "contracts"; @@ -31,7 +32,12 @@ import { DetectableFeature } from "../interfaces/DetectableFeature"; * @public */ export class Erc721< - T extends SignatureDrop | DropERC721 | TokenERC721 | BaseERC721 = BaseERC721, + T extends + | Multiwrap + | SignatureDrop + | DropERC721 + | TokenERC721 + | BaseERC721 = BaseERC721, > implements UpdateableNetwork, DetectableFeature { featureName = FEATURE_NFT.name; diff --git a/yarn.lock b/yarn.lock index c8de650e1..b2b3e3357 100644 --- a/yarn.lock +++ b/yarn.lock @@ -802,10 +802,10 @@ "@swc/core-win32-ia32-msvc" "1.2.194" "@swc/core-win32-x64-msvc" "1.2.194" -"@thirdweb-dev/contracts@2.3.9-1": - version "2.3.9-1" - resolved "https://registry.yarnpkg.com/@thirdweb-dev/contracts/-/contracts-2.3.9-1.tgz#98dd38ed67ee505a38cf888d5ccd36e27c606674" - integrity sha512-AMbTw92sKZgIS5udTClX+RNRVASbcrVNjQzlivLoxJR25Zhi91Ul+OcllYFANI0WTslYR6Riq9NGsAZRW8I1FA== +"@thirdweb-dev/contracts@^2.3.8": + version "2.3.8" + resolved "https://registry.yarnpkg.com/@thirdweb-dev/contracts/-/contracts-2.3.8.tgz#7c565b4d4f1917bbbc76dc48c9f6bffc8c6eabdd" + integrity sha512-cSVwIzPSYaS8gFlkq4r+G9UyVwr/62uE+p6SzrZFXYCbeCJwJTml3VnrVEptJ7g8RukL4Lh6uwQ6IPtgMTY4cQ== "@tsconfig/node10@^1.0.7": version "1.0.8"