Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] Add Pack extensions #4579

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .changeset/sixty-seals-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
"thirdweb": minor
---

Add Pack extensions
### Deploy Pack
```ts
import { deployPackContract } from "thirdweb/extensions/deploy";

const packAddress = await deployPackContract({
account,
client,
chain,
params: {
name: "Pack contract name",
symbol: "PACK1155",
},
});
```

### Create a Pack
```ts
import { createPack } from "thirdweb/extensions/pack";

const transaction = createPack({
contract: packContract,
client,
recipient: "0x...",
tokenOwner: "0x...",
packMetadata: {
name: "Pack #1",
image: "image-of-pack-1",
},
openStartTimestamp: new Date(),
erc20Rewards: [
{
contractAddress: "0x...",
quantityPerReward: 1,
totalRewards: 1,
},
],
erc721Rewards: [
{
contractAddress: "0x...",
tokenId: 0n,
},
],
erc1155Rewards: [
{
contractAddress: "0x...",
tokenId: 0n,
quantityPerReward: 1,
totalRewards: 1,
},
],
});
```
13 changes: 13 additions & 0 deletions packages/thirdweb/scripts/generate/abis/pack/IPack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
"event PackCreated(uint256 indexed packId, address recipient, uint256 totalPacksCreated)",
"event PackOpened(uint256 indexed packId, address indexed opener, uint256 numOfPacksOpened, (address assetContract, uint8 tokenType, uint256 tokenId, uint256 totalAmount)[] rewardUnitsDistributed)",
"event PackUpdated(uint256 indexed packId, address recipient, uint256 totalPacksCreated)",
"function createPack((address assetContract, uint8 tokenType, uint256 tokenId, uint256 totalAmount)[] contents, uint256[] numOfRewardUnits, string packUri, uint128 openStartTimestamp, uint128 amountDistributedPerOpen, address recipient) payable returns (uint256 packId, uint256 packTotalSupply)",
"function openPack(uint256 packId, uint256 amountToOpen) returns ((address assetContract, uint8 tokenType, uint256 tokenId, uint256 totalAmount)[])",
"function addPackContents(uint256 _packId, (address assetContract, uint8 tokenType, uint256 tokenId, uint256 totalAmount)[] _contents, uint256[] _numOfRewardUnits, address _recipient) payable returns (uint256 packTotalSupply, uint256 newSupplyAdded)",
"function getPackContents(uint256 _packId) view returns ((address assetContract, uint8 tokenType, uint256 tokenId, uint256 totalAmount)[] contents, uint256[] perUnitAmounts)",
"function getTokenCountOfBundle(uint256 _bundleId) view returns (uint256)",
"function getTokenOfBundle(uint256 _bundleId, uint256 index) view returns ((address assetContract, uint8 tokenType, uint256 tokenId, uint256 totalAmount))",
"function getUriOfBundle(uint256 _bundleId) view returns (string)",
"function canUpdatePack(uint256 _key) view returns (bool)"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
"event PackOpenRequested(address indexed opener, uint256 indexed packId, uint256 amountToOpen, uint256 requestId)",
"event PackRandomnessFulfilled(uint256 indexed packId, uint256 indexed requestId)",
"function canClaimRewards(address _opener) view returns (bool)",
"function claimRewards() returns ((address assetContract, uint8 tokenType, uint256 tokenId, uint256 totalAmount)[] rewardUnits)",
"function openPackAndClaimRewards(uint256 _packId, uint256 _amountToOpen, uint32 _callBackGasLimit) returns (uint256)"
]
3 changes: 3 additions & 0 deletions packages/thirdweb/scripts/generate/abis/prebuilts/Pack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"function initialize(address _defaultAdmin, string _name, string _symbol, string _contractURI, address[] _trustedForwarders, address _royaltyRecipient, uint256 _royaltyBps)"
]
6 changes: 6 additions & 0 deletions packages/thirdweb/src/exports/deploys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ export {
} from "../contract/deployment/deploy-with-abi.js";
export { computePublishedContractAddress } from "../utils/any-evm/compute-published-contract-address.js";
export { getRequiredTransactions } from "../extensions/prebuilts/get-required-transactions.js";

export {
type PackContractParams,
type DeployPackContractOptions,
deployPackContract,
} from "../extensions/prebuilts/deploy-pack.js";
42 changes: 42 additions & 0 deletions packages/thirdweb/src/exports/extensions/pack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Write
export {
createPack,
type CreatePackParams,
} from "../../extensions/pack/__generated__/IPack/write/createPack.js";
export {
PACK_TOKEN_TYPE,
type ERC20Reward,
type ERC721Reward,
type ERC1155Reward,
type CreateNewPackParams,
createNewPack,
} from "../../extensions/pack/createNewPack.js";

export {
openPack,
type OpenPackParams,
} from "../../extensions/pack/__generated__/IPack/write/openPack.js";

// Read
export {
getTokenCountOfBundle,
type GetTokenCountOfBundleParams,
} from "../../extensions/pack/__generated__/IPack/read/getTokenCountOfBundle.js";
export {
getPackContents,
type GetPackContentsParams,
} from "../../extensions/pack/__generated__/IPack/read/getPackContents.js";

// Events
export {
packCreatedEvent,
type PackCreatedEventFilters,
} from "../../extensions/pack/__generated__/IPack/events/PackCreated.js";
export {
packOpenedEvent,
type PackOpenedEventFilters,
} from "../../extensions/pack/__generated__/IPack/events/PackOpened.js";
export {
packUpdatedEvent,
type PackUpdatedEventFilters,
} from "../../extensions/pack/__generated__/IPack/events/PackUpdated.js";

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading