thirdweb 5.64.4-nightly-c2a90542d7f870c799c297c59cd2b468816f7939-20241031000332 → 5.64.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.js +31 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.js.map +1 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.js +33 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.js.map +1 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js +149 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js.map +1 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.js +193 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.js.map +1 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.js +173 -0
- package/dist/cjs/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.js.map +1 -0
- package/dist/cjs/extensions/erc1155/drops/write/claimTo.js +5 -2
- package/dist/cjs/extensions/erc1155/drops/write/claimTo.js.map +1 -1
- package/dist/cjs/extensions/erc1155/drops/write/setClaimConditions.js +4 -1
- package/dist/cjs/extensions/erc1155/drops/write/setClaimConditions.js.map +1 -1
- package/dist/cjs/extensions/erc20/drops/write/claimTo.js +1 -0
- package/dist/cjs/extensions/erc20/drops/write/claimTo.js.map +1 -1
- package/dist/cjs/extensions/erc20/drops/write/setClaimConditions.js +1 -0
- package/dist/cjs/extensions/erc20/drops/write/setClaimConditions.js.map +1 -1
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.js +27 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.js.map +1 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.js +33 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.js.map +1 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.js +105 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.js.map +1 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/write/claim.js +184 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/write/claim.js.map +1 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.js +164 -0
- package/dist/cjs/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.js.map +1 -0
- package/dist/cjs/extensions/erc721/drops/write/claimTo.js +6 -3
- package/dist/cjs/extensions/erc721/drops/write/claimTo.js.map +1 -1
- package/dist/cjs/extensions/erc721/drops/write/setClaimConditions.js +4 -1
- package/dist/cjs/extensions/erc721/drops/write/setClaimConditions.js.map +1 -1
- package/dist/cjs/utils/extensions/drops/get-claim-params.js +20 -0
- package/dist/cjs/utils/extensions/drops/get-claim-params.js.map +1 -1
- package/dist/cjs/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js +39 -12
- package/dist/cjs/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/wallets/smart/index.js +3 -0
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.js +28 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.js.map +1 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.js +30 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.js.map +1 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js +141 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js.map +1 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.js +186 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.js.map +1 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.js +166 -0
- package/dist/esm/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.js.map +1 -0
- package/dist/esm/extensions/erc1155/drops/write/claimTo.js +5 -2
- package/dist/esm/extensions/erc1155/drops/write/claimTo.js.map +1 -1
- package/dist/esm/extensions/erc1155/drops/write/setClaimConditions.js +4 -1
- package/dist/esm/extensions/erc1155/drops/write/setClaimConditions.js.map +1 -1
- package/dist/esm/extensions/erc20/drops/write/claimTo.js +1 -0
- package/dist/esm/extensions/erc20/drops/write/claimTo.js.map +1 -1
- package/dist/esm/extensions/erc20/drops/write/setClaimConditions.js +1 -0
- package/dist/esm/extensions/erc20/drops/write/setClaimConditions.js.map +1 -1
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.js +24 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.js.map +1 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.js +30 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.js.map +1 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.js +99 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.js.map +1 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/write/claim.js +177 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/write/claim.js.map +1 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.js +157 -0
- package/dist/esm/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.js.map +1 -0
- package/dist/esm/extensions/erc721/drops/write/claimTo.js +6 -3
- package/dist/esm/extensions/erc721/drops/write/claimTo.js.map +1 -1
- package/dist/esm/extensions/erc721/drops/write/setClaimConditions.js +4 -1
- package/dist/esm/extensions/erc721/drops/write/setClaimConditions.js.map +1 -1
- package/dist/esm/utils/extensions/drops/get-claim-params.js +20 -0
- package/dist/esm/utils/extensions/drops/get-claim-params.js.map +1 -1
- package/dist/esm/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js +39 -12
- package/dist/esm/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/wallets/smart/index.js +3 -0
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.d.ts +72 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.d.ts.map +1 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.d.ts +64 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.d.ts.map +1 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.d.ts +101 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.d.ts.map +1 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.d.ts +139 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.d.ts.map +1 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.d.ts +127 -0
- package/dist/types/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.d.ts.map +1 -0
- package/dist/types/extensions/erc1155/drops/write/claimTo.d.ts +1 -0
- package/dist/types/extensions/erc1155/drops/write/claimTo.d.ts.map +1 -1
- package/dist/types/extensions/erc1155/drops/write/setClaimConditions.d.ts +1 -0
- package/dist/types/extensions/erc1155/drops/write/setClaimConditions.d.ts.map +1 -1
- package/dist/types/extensions/erc20/drops/write/claimTo.d.ts +1 -0
- package/dist/types/extensions/erc20/drops/write/claimTo.d.ts.map +1 -1
- package/dist/types/extensions/erc20/drops/write/setClaimConditions.d.ts +1 -0
- package/dist/types/extensions/erc20/drops/write/setClaimConditions.d.ts.map +1 -1
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.d.ts +54 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.d.ts.map +1 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.d.ts +64 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.d.ts.map +1 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.d.ts +62 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.d.ts.map +1 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/write/claim.d.ts +132 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/write/claim.d.ts.map +1 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.d.ts +120 -0
- package/dist/types/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.d.ts.map +1 -0
- package/dist/types/extensions/erc721/drops/write/claimTo.d.ts +1 -0
- package/dist/types/extensions/erc721/drops/write/claimTo.d.ts.map +1 -1
- package/dist/types/extensions/erc721/drops/write/setClaimConditions.d.ts +1 -0
- package/dist/types/extensions/erc721/drops/write/setClaimConditions.d.ts.map +1 -1
- package/dist/types/utils/extensions/drops/get-claim-params.d.ts +1 -0
- package/dist/types/utils/extensions/drops/get-claim-params.d.ts.map +1 -1
- package/dist/types/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.d.ts +1 -0
- package/dist/types/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/events/ClaimConditionUpdated.ts +43 -0
- package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/events/TokensClaimed.ts +53 -0
- package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.ts +160 -0
- package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/write/claim.ts +229 -0
- package/src/extensions/erc1155/__generated__/IDropSinglePhase1155/write/setClaimConditions.ts +213 -0
- package/src/extensions/erc1155/customDrop1155.test.ts +181 -0
- package/src/extensions/erc1155/drops/write/claimTo.ts +6 -2
- package/src/extensions/erc1155/drops/write/setClaimConditions.ts +5 -1
- package/src/extensions/erc20/customDrop20.test.ts +80 -0
- package/src/extensions/erc20/drops/write/claimTo.ts +2 -0
- package/src/extensions/erc20/drops/write/setClaimConditions.ts +2 -0
- package/src/extensions/erc721/__generated__/IDropSinglePhase/events/ClaimConditionUpdated.ts +25 -0
- package/src/extensions/erc721/__generated__/IDropSinglePhase/events/TokensClaimed.ts +53 -0
- package/src/extensions/erc721/__generated__/IDropSinglePhase/read/claimCondition.ts +105 -0
- package/src/extensions/erc721/__generated__/IDropSinglePhase/write/claim.ts +219 -0
- package/src/extensions/erc721/__generated__/IDropSinglePhase/write/setClaimConditions.ts +203 -0
- package/src/extensions/erc721/customDrop721.test.ts +115 -0
- package/src/extensions/erc721/drops/write/claimTo.ts +7 -3
- package/src/extensions/erc721/drops/write/setClaimConditions.ts +5 -1
- package/src/utils/extensions/drops/get-claim-params.ts +29 -2
- package/src/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.ts +46 -16
- package/src/version.ts +1 -1
- package/src/wallets/smart/index.ts +2 -0
- package/src/wallets/smart/smart-wallet-integration.test.ts +33 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
import { fetchDeployMetadata } from "../../utils/any-evm/deploy-metadata.js";
|
2
|
+
|
3
|
+
import { beforeAll, describe, expect, it } from "vitest";
|
4
|
+
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
|
5
|
+
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
|
6
|
+
import { TEST_ACCOUNT_C } from "../../../test/src/test-wallets.js";
|
7
|
+
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
|
8
|
+
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
|
9
|
+
import { toWei } from "../../utils/units.js";
|
10
|
+
import { deployContractfromDeployMetadata } from "../prebuilts/deploy-published.js";
|
11
|
+
import { balanceOf } from "./__generated__/IERC20/read/balanceOf.js";
|
12
|
+
import { claimTo } from "./drops/write/claimTo.js";
|
13
|
+
import { setClaimConditions } from "./drops/write/setClaimConditions.js";
|
14
|
+
|
15
|
+
describe.runIf(process.env.TW_SECRET_KEY)(
|
16
|
+
"CustomDropERC20",
|
17
|
+
{
|
18
|
+
retry: 0,
|
19
|
+
},
|
20
|
+
() => {
|
21
|
+
let contract: ThirdwebContract;
|
22
|
+
|
23
|
+
beforeAll(async () => {
|
24
|
+
const customDropDeployMetadata = await fetchDeployMetadata({
|
25
|
+
client: TEST_CLIENT,
|
26
|
+
uri: "ipfs://QmT6h6gZztc2G83gWkJBkNFeq1b9gKrFKnYwgagXMBHV1d",
|
27
|
+
});
|
28
|
+
const contractAddress = await deployContractfromDeployMetadata({
|
29
|
+
chain: ANVIL_CHAIN,
|
30
|
+
client: TEST_CLIENT,
|
31
|
+
account: TEST_ACCOUNT_C,
|
32
|
+
deployMetadata: customDropDeployMetadata,
|
33
|
+
initializeParams: {
|
34
|
+
defaultAdmin: TEST_ACCOUNT_C.address,
|
35
|
+
name: "TestCustomDropERC20",
|
36
|
+
symbol: "TT",
|
37
|
+
},
|
38
|
+
});
|
39
|
+
|
40
|
+
contract = getContract({
|
41
|
+
address: contractAddress,
|
42
|
+
chain: ANVIL_CHAIN,
|
43
|
+
client: TEST_CLIENT,
|
44
|
+
});
|
45
|
+
// this deploys a contract, it may take some time
|
46
|
+
}, 60_000);
|
47
|
+
|
48
|
+
it("should allow to claim tokens", async () => {
|
49
|
+
await expect(
|
50
|
+
balanceOf({ contract, address: TEST_ACCOUNT_C.address }),
|
51
|
+
).resolves.toBe(0n);
|
52
|
+
await sendAndConfirmTransaction({
|
53
|
+
transaction: setClaimConditions({
|
54
|
+
contract,
|
55
|
+
phases: [
|
56
|
+
{
|
57
|
+
startTime: new Date(0),
|
58
|
+
maxClaimableSupply: toWei("10"),
|
59
|
+
},
|
60
|
+
],
|
61
|
+
singlePhaseDrop: true,
|
62
|
+
}),
|
63
|
+
account: TEST_ACCOUNT_C,
|
64
|
+
});
|
65
|
+
const claimTx = claimTo({
|
66
|
+
contract,
|
67
|
+
to: TEST_ACCOUNT_C.address,
|
68
|
+
quantity: "1",
|
69
|
+
singlePhaseDrop: true,
|
70
|
+
});
|
71
|
+
await sendAndConfirmTransaction({
|
72
|
+
transaction: claimTx,
|
73
|
+
account: TEST_ACCOUNT_C,
|
74
|
+
});
|
75
|
+
await expect(
|
76
|
+
balanceOf({ contract, address: TEST_ACCOUNT_C.address }),
|
77
|
+
).resolves.toBe(toWei("1"));
|
78
|
+
});
|
79
|
+
},
|
80
|
+
);
|
@@ -13,6 +13,7 @@ import { isGetActiveClaimConditionSupported } from "../read/getActiveClaimCondit
|
|
13
13
|
export type ClaimToParams = {
|
14
14
|
to: Address;
|
15
15
|
from?: Address;
|
16
|
+
singlePhaseDrop?: boolean;
|
16
17
|
} & ({ quantityInWei: bigint } | { quantity: string });
|
17
18
|
|
18
19
|
/**
|
@@ -71,6 +72,7 @@ export function claimTo(options: BaseTransactionOptions<ClaimToParams>) {
|
|
71
72
|
quantity,
|
72
73
|
from: options.from,
|
73
74
|
tokenDecimals: await decimals({ contract: options.contract }),
|
75
|
+
singlePhaseDrop: options.singlePhaseDrop,
|
74
76
|
});
|
75
77
|
},
|
76
78
|
});
|
@@ -16,6 +16,7 @@ import { decimals, isDecimalsSupported } from "../../read/decimals.js";
|
|
16
16
|
export type SetClaimConditionsParams = {
|
17
17
|
phases: ClaimConditionsInput[];
|
18
18
|
resetClaimEligibility?: boolean;
|
19
|
+
singlePhaseDrop?: boolean;
|
19
20
|
};
|
20
21
|
|
21
22
|
/**
|
@@ -56,6 +57,7 @@ export function setClaimConditions(
|
|
56
57
|
phases: options.phases,
|
57
58
|
resetClaimEligibility: options.resetClaimEligibility,
|
58
59
|
tokenDecimals: await decimals({ contract: options.contract }),
|
60
|
+
singlePhase: options.singlePhaseDrop,
|
59
61
|
}),
|
60
62
|
};
|
61
63
|
},
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { prepareEvent } from "../../../../../event/prepare-event.js";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Creates an event object for the ClaimConditionUpdated event.
|
5
|
+
* @returns The prepared event object.
|
6
|
+
* @extension ERC721
|
7
|
+
* @example
|
8
|
+
* ```ts
|
9
|
+
* import { getContractEvents } from "thirdweb";
|
10
|
+
* import { claimConditionUpdatedEvent } from "thirdweb/extensions/erc721";
|
11
|
+
*
|
12
|
+
* const events = await getContractEvents({
|
13
|
+
* contract,
|
14
|
+
* events: [
|
15
|
+
* claimConditionUpdatedEvent()
|
16
|
+
* ],
|
17
|
+
* });
|
18
|
+
* ```
|
19
|
+
*/
|
20
|
+
export function claimConditionUpdatedEvent() {
|
21
|
+
return prepareEvent({
|
22
|
+
signature:
|
23
|
+
"event ClaimConditionUpdated((uint256 startTimestamp, uint256 maxClaimableSupply, uint256 supplyClaimed, uint256 quantityLimitPerWallet, bytes32 merkleRoot, uint256 pricePerToken, address currency, string metadata) condition, bool resetEligibility)",
|
24
|
+
});
|
25
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { prepareEvent } from "../../../../../event/prepare-event.js";
|
2
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Represents the filters for the "TokensClaimed" event.
|
6
|
+
*/
|
7
|
+
export type TokensClaimedEventFilters = Partial<{
|
8
|
+
claimer: AbiParameterToPrimitiveType<{
|
9
|
+
type: "address";
|
10
|
+
name: "claimer";
|
11
|
+
indexed: true;
|
12
|
+
}>;
|
13
|
+
receiver: AbiParameterToPrimitiveType<{
|
14
|
+
type: "address";
|
15
|
+
name: "receiver";
|
16
|
+
indexed: true;
|
17
|
+
}>;
|
18
|
+
startTokenId: AbiParameterToPrimitiveType<{
|
19
|
+
type: "uint256";
|
20
|
+
name: "startTokenId";
|
21
|
+
indexed: true;
|
22
|
+
}>;
|
23
|
+
}>;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Creates an event object for the TokensClaimed event.
|
27
|
+
* @param filters - Optional filters to apply to the event.
|
28
|
+
* @returns The prepared event object.
|
29
|
+
* @extension ERC721
|
30
|
+
* @example
|
31
|
+
* ```ts
|
32
|
+
* import { getContractEvents } from "thirdweb";
|
33
|
+
* import { tokensClaimedEvent } from "thirdweb/extensions/erc721";
|
34
|
+
*
|
35
|
+
* const events = await getContractEvents({
|
36
|
+
* contract,
|
37
|
+
* events: [
|
38
|
+
* tokensClaimedEvent({
|
39
|
+
* claimer: ...,
|
40
|
+
* receiver: ...,
|
41
|
+
* startTokenId: ...,
|
42
|
+
* })
|
43
|
+
* ],
|
44
|
+
* });
|
45
|
+
* ```
|
46
|
+
*/
|
47
|
+
export function tokensClaimedEvent(filters: TokensClaimedEventFilters = {}) {
|
48
|
+
return prepareEvent({
|
49
|
+
signature:
|
50
|
+
"event TokensClaimed(address indexed claimer, address indexed receiver, uint256 indexed startTokenId, uint256 quantityClaimed)",
|
51
|
+
filters,
|
52
|
+
});
|
53
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import { readContract } from "../../../../../transaction/read-contract.js";
|
2
|
+
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
|
3
|
+
|
4
|
+
import { decodeAbiParameters } from "viem";
|
5
|
+
import type { Hex } from "../../../../../utils/encoding/hex.js";
|
6
|
+
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
|
7
|
+
|
8
|
+
export const FN_SELECTOR = "0xd637ed59" as const;
|
9
|
+
const FN_INPUTS = [] as const;
|
10
|
+
const FN_OUTPUTS = [
|
11
|
+
{
|
12
|
+
type: "tuple",
|
13
|
+
name: "condition",
|
14
|
+
components: [
|
15
|
+
{
|
16
|
+
type: "uint256",
|
17
|
+
name: "startTimestamp",
|
18
|
+
},
|
19
|
+
{
|
20
|
+
type: "uint256",
|
21
|
+
name: "maxClaimableSupply",
|
22
|
+
},
|
23
|
+
{
|
24
|
+
type: "uint256",
|
25
|
+
name: "supplyClaimed",
|
26
|
+
},
|
27
|
+
{
|
28
|
+
type: "uint256",
|
29
|
+
name: "quantityLimitPerWallet",
|
30
|
+
},
|
31
|
+
{
|
32
|
+
type: "bytes32",
|
33
|
+
name: "merkleRoot",
|
34
|
+
},
|
35
|
+
{
|
36
|
+
type: "uint256",
|
37
|
+
name: "pricePerToken",
|
38
|
+
},
|
39
|
+
{
|
40
|
+
type: "address",
|
41
|
+
name: "currency",
|
42
|
+
},
|
43
|
+
{
|
44
|
+
type: "string",
|
45
|
+
name: "metadata",
|
46
|
+
},
|
47
|
+
],
|
48
|
+
},
|
49
|
+
] as const;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Checks if the `claimCondition` method is supported by the given contract.
|
53
|
+
* @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
|
54
|
+
* @returns A boolean indicating if the `claimCondition` method is supported.
|
55
|
+
* @extension ERC721
|
56
|
+
* @example
|
57
|
+
* ```ts
|
58
|
+
* import { isClaimConditionSupported } from "thirdweb/extensions/erc721";
|
59
|
+
* const supported = isClaimConditionSupported(["0x..."]);
|
60
|
+
* ```
|
61
|
+
*/
|
62
|
+
export function isClaimConditionSupported(availableSelectors: string[]) {
|
63
|
+
return detectMethod({
|
64
|
+
availableSelectors,
|
65
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Decodes the result of the claimCondition function call.
|
71
|
+
* @param result - The hexadecimal result to decode.
|
72
|
+
* @returns The decoded result as per the FN_OUTPUTS definition.
|
73
|
+
* @extension ERC721
|
74
|
+
* @example
|
75
|
+
* ```ts
|
76
|
+
* import { decodeClaimConditionResult } from "thirdweb/extensions/erc721";
|
77
|
+
* const result = decodeClaimConditionResultResult("...");
|
78
|
+
* ```
|
79
|
+
*/
|
80
|
+
export function decodeClaimConditionResult(result: Hex) {
|
81
|
+
return decodeAbiParameters(FN_OUTPUTS, result)[0];
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Calls the "claimCondition" function on the contract.
|
86
|
+
* @param options - The options for the claimCondition function.
|
87
|
+
* @returns The parsed result of the function call.
|
88
|
+
* @extension ERC721
|
89
|
+
* @example
|
90
|
+
* ```ts
|
91
|
+
* import { claimCondition } from "thirdweb/extensions/erc721";
|
92
|
+
*
|
93
|
+
* const result = await claimCondition({
|
94
|
+
* contract,
|
95
|
+
* });
|
96
|
+
*
|
97
|
+
* ```
|
98
|
+
*/
|
99
|
+
export async function claimCondition(options: BaseTransactionOptions) {
|
100
|
+
return readContract({
|
101
|
+
contract: options.contract,
|
102
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
103
|
+
params: [],
|
104
|
+
});
|
105
|
+
}
|
@@ -0,0 +1,219 @@
|
|
1
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
2
|
+
import type {
|
3
|
+
BaseTransactionOptions,
|
4
|
+
WithOverrides,
|
5
|
+
} from "../../../../../transaction/types.js";
|
6
|
+
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
|
7
|
+
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
|
8
|
+
import { once } from "../../../../../utils/promise/once.js";
|
9
|
+
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Represents the parameters for the "claim" function.
|
13
|
+
*/
|
14
|
+
export type ClaimParams = WithOverrides<{
|
15
|
+
receiver: AbiParameterToPrimitiveType<{ type: "address"; name: "receiver" }>;
|
16
|
+
quantity: AbiParameterToPrimitiveType<{ type: "uint256"; name: "quantity" }>;
|
17
|
+
currency: AbiParameterToPrimitiveType<{ type: "address"; name: "currency" }>;
|
18
|
+
pricePerToken: AbiParameterToPrimitiveType<{
|
19
|
+
type: "uint256";
|
20
|
+
name: "pricePerToken";
|
21
|
+
}>;
|
22
|
+
allowlistProof: AbiParameterToPrimitiveType<{
|
23
|
+
type: "tuple";
|
24
|
+
name: "allowlistProof";
|
25
|
+
components: [
|
26
|
+
{ type: "bytes32[]"; name: "proof" },
|
27
|
+
{ type: "uint256"; name: "quantityLimitPerWallet" },
|
28
|
+
{ type: "uint256"; name: "pricePerToken" },
|
29
|
+
{ type: "address"; name: "currency" },
|
30
|
+
];
|
31
|
+
}>;
|
32
|
+
data: AbiParameterToPrimitiveType<{ type: "bytes"; name: "data" }>;
|
33
|
+
}>;
|
34
|
+
|
35
|
+
export const FN_SELECTOR = "0x84bb1e42" as const;
|
36
|
+
const FN_INPUTS = [
|
37
|
+
{
|
38
|
+
type: "address",
|
39
|
+
name: "receiver",
|
40
|
+
},
|
41
|
+
{
|
42
|
+
type: "uint256",
|
43
|
+
name: "quantity",
|
44
|
+
},
|
45
|
+
{
|
46
|
+
type: "address",
|
47
|
+
name: "currency",
|
48
|
+
},
|
49
|
+
{
|
50
|
+
type: "uint256",
|
51
|
+
name: "pricePerToken",
|
52
|
+
},
|
53
|
+
{
|
54
|
+
type: "tuple",
|
55
|
+
name: "allowlistProof",
|
56
|
+
components: [
|
57
|
+
{
|
58
|
+
type: "bytes32[]",
|
59
|
+
name: "proof",
|
60
|
+
},
|
61
|
+
{
|
62
|
+
type: "uint256",
|
63
|
+
name: "quantityLimitPerWallet",
|
64
|
+
},
|
65
|
+
{
|
66
|
+
type: "uint256",
|
67
|
+
name: "pricePerToken",
|
68
|
+
},
|
69
|
+
{
|
70
|
+
type: "address",
|
71
|
+
name: "currency",
|
72
|
+
},
|
73
|
+
],
|
74
|
+
},
|
75
|
+
{
|
76
|
+
type: "bytes",
|
77
|
+
name: "data",
|
78
|
+
},
|
79
|
+
] as const;
|
80
|
+
const FN_OUTPUTS = [] as const;
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Checks if the `claim` method is supported by the given contract.
|
84
|
+
* @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
|
85
|
+
* @returns A boolean indicating if the `claim` method is supported.
|
86
|
+
* @extension ERC721
|
87
|
+
* @example
|
88
|
+
* ```ts
|
89
|
+
* import { isClaimSupported } from "thirdweb/extensions/erc721";
|
90
|
+
*
|
91
|
+
* const supported = isClaimSupported(["0x..."]);
|
92
|
+
* ```
|
93
|
+
*/
|
94
|
+
export function isClaimSupported(availableSelectors: string[]) {
|
95
|
+
return detectMethod({
|
96
|
+
availableSelectors,
|
97
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
98
|
+
});
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Encodes the parameters for the "claim" function.
|
103
|
+
* @param options - The options for the claim function.
|
104
|
+
* @returns The encoded ABI parameters.
|
105
|
+
* @extension ERC721
|
106
|
+
* @example
|
107
|
+
* ```ts
|
108
|
+
* import { encodeClaimParams } from "thirdweb/extensions/erc721";
|
109
|
+
* const result = encodeClaimParams({
|
110
|
+
* receiver: ...,
|
111
|
+
* quantity: ...,
|
112
|
+
* currency: ...,
|
113
|
+
* pricePerToken: ...,
|
114
|
+
* allowlistProof: ...,
|
115
|
+
* data: ...,
|
116
|
+
* });
|
117
|
+
* ```
|
118
|
+
*/
|
119
|
+
export function encodeClaimParams(options: ClaimParams) {
|
120
|
+
return encodeAbiParameters(FN_INPUTS, [
|
121
|
+
options.receiver,
|
122
|
+
options.quantity,
|
123
|
+
options.currency,
|
124
|
+
options.pricePerToken,
|
125
|
+
options.allowlistProof,
|
126
|
+
options.data,
|
127
|
+
]);
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Encodes the "claim" function into a Hex string with its parameters.
|
132
|
+
* @param options - The options for the claim function.
|
133
|
+
* @returns The encoded hexadecimal string.
|
134
|
+
* @extension ERC721
|
135
|
+
* @example
|
136
|
+
* ```ts
|
137
|
+
* import { encodeClaim } from "thirdweb/extensions/erc721";
|
138
|
+
* const result = encodeClaim({
|
139
|
+
* receiver: ...,
|
140
|
+
* quantity: ...,
|
141
|
+
* currency: ...,
|
142
|
+
* pricePerToken: ...,
|
143
|
+
* allowlistProof: ...,
|
144
|
+
* data: ...,
|
145
|
+
* });
|
146
|
+
* ```
|
147
|
+
*/
|
148
|
+
export function encodeClaim(options: ClaimParams) {
|
149
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
150
|
+
// we can do this because we know the specific formats of the values
|
151
|
+
return (FN_SELECTOR +
|
152
|
+
encodeClaimParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
|
153
|
+
}
|
154
|
+
|
155
|
+
/**
|
156
|
+
* Prepares a transaction to call the "claim" function on the contract.
|
157
|
+
* @param options - The options for the "claim" function.
|
158
|
+
* @returns A prepared transaction object.
|
159
|
+
* @extension ERC721
|
160
|
+
* @example
|
161
|
+
* ```ts
|
162
|
+
* import { sendTransaction } from "thirdweb";
|
163
|
+
* import { claim } from "thirdweb/extensions/erc721";
|
164
|
+
*
|
165
|
+
* const transaction = claim({
|
166
|
+
* contract,
|
167
|
+
* receiver: ...,
|
168
|
+
* quantity: ...,
|
169
|
+
* currency: ...,
|
170
|
+
* pricePerToken: ...,
|
171
|
+
* allowlistProof: ...,
|
172
|
+
* data: ...,
|
173
|
+
* overrides: {
|
174
|
+
* ...
|
175
|
+
* }
|
176
|
+
* });
|
177
|
+
*
|
178
|
+
* // Send the transaction
|
179
|
+
* await sendTransaction({ transaction, account });
|
180
|
+
* ```
|
181
|
+
*/
|
182
|
+
export function claim(
|
183
|
+
options: BaseTransactionOptions<
|
184
|
+
| ClaimParams
|
185
|
+
| {
|
186
|
+
asyncParams: () => Promise<ClaimParams>;
|
187
|
+
}
|
188
|
+
>,
|
189
|
+
) {
|
190
|
+
const asyncOptions = once(async () => {
|
191
|
+
return "asyncParams" in options ? await options.asyncParams() : options;
|
192
|
+
});
|
193
|
+
|
194
|
+
return prepareContractCall({
|
195
|
+
contract: options.contract,
|
196
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
197
|
+
params: async () => {
|
198
|
+
const resolvedOptions = await asyncOptions();
|
199
|
+
return [
|
200
|
+
resolvedOptions.receiver,
|
201
|
+
resolvedOptions.quantity,
|
202
|
+
resolvedOptions.currency,
|
203
|
+
resolvedOptions.pricePerToken,
|
204
|
+
resolvedOptions.allowlistProof,
|
205
|
+
resolvedOptions.data,
|
206
|
+
] as const;
|
207
|
+
},
|
208
|
+
value: async () => (await asyncOptions()).overrides?.value,
|
209
|
+
accessList: async () => (await asyncOptions()).overrides?.accessList,
|
210
|
+
gas: async () => (await asyncOptions()).overrides?.gas,
|
211
|
+
gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
|
212
|
+
maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
|
213
|
+
maxPriorityFeePerGas: async () =>
|
214
|
+
(await asyncOptions()).overrides?.maxPriorityFeePerGas,
|
215
|
+
nonce: async () => (await asyncOptions()).overrides?.nonce,
|
216
|
+
extraGas: async () => (await asyncOptions()).overrides?.extraGas,
|
217
|
+
erc20Value: async () => (await asyncOptions()).overrides?.erc20Value,
|
218
|
+
});
|
219
|
+
}
|