Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.
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
4 changes: 2 additions & 2 deletions docs/sdk.dropclaimconditions._constructor_.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Constructs a new instance of the `DropClaimConditions` class
<b>Signature:</b>

```typescript
constructor(contractWrapper: ContractWrapper<TContract>, metadata: ContractMetadata<TContract, typeof DropErc721ContractSchema | typeof DropErc20ContractSchema>, storage: IStorage);
constructor(contractWrapper: ContractWrapper<TContract>, metadata: ContractMetadata<TContract, any>, storage: IStorage);
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| contractWrapper | ContractWrapper&lt;TContract&gt; | |
| metadata | [ContractMetadata](./sdk.contractmetadata.md)<!-- -->&lt;TContract, typeof DropErc721ContractSchema \| typeof DropErc20ContractSchema&gt; | |
| metadata | [ContractMetadata](./sdk.contractmetadata.md)<!-- -->&lt;TContract, any&gt; | |
| storage | [IStorage](./sdk.istorage.md) | |

32 changes: 5 additions & 27 deletions etc/sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,7 @@ export interface DirectListing {
//
// @public
export class DropClaimConditions<TContract extends DropERC721 | DropERC20> {
// Warning: (ae-forgotten-export) The symbol "DropErc721ContractSchema" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DropErc20ContractSchema" needs to be exported by the entry point index.d.ts
constructor(contractWrapper: ContractWrapper<TContract>, metadata: ContractMetadata<TContract, typeof DropErc721ContractSchema | typeof DropErc20ContractSchema>, storage: IStorage);
constructor(contractWrapper: ContractWrapper<TContract>, metadata: ContractMetadata<TContract, any>, storage: IStorage);
canClaim(quantity: Amount, addressToCheck?: string): Promise<boolean>;
getActive(): Promise<ClaimCondition>;
getAll(): Promise<ClaimCondition[]>;
Expand All @@ -885,6 +883,7 @@ export class DropClaimConditions<TContract extends DropERC721 | DropERC20> {
// @public
export class DropErc1155ClaimConditions {
// Warning: (ae-forgotten-export) The symbol "DropERC1155" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DropErc721ContractSchema" needs to be exported by the entry point index.d.ts
constructor(contractWrapper: ContractWrapper<DropERC1155>, metadata: ContractMetadata<DropERC1155, typeof DropErc721ContractSchema>, storage: IStorage);
canClaim(tokenId: BigNumberish, quantity: BigNumberish, addressToCheck?: string): Promise<boolean>;
getActive(tokenId: BigNumberish): Promise<ClaimCondition>;
Expand Down Expand Up @@ -4485,15 +4484,12 @@ export class TokenDrop extends Erc20<DropERC20> {
sales: ContractPrimarySale<DropERC20>;
// (undocumented)
static schema: {
deploy: ZodObject<extendShape<extendShape<extendShape<extendShape<extendShape<extendShape< {
deploy: ZodObject<extendShape<extendShape<extendShape<extendShape<extendShape< {
name: ZodString;
description: ZodOptional<ZodString>;
image: ZodOptional<ZodUnion<[ZodTypeAny, ZodString]>>;
external_link: ZodOptional<ZodString>;
}, {
seller_fee_basis_points: ZodDefault<ZodNumber>;
fee_recipient: ZodDefault<ZodEffects<ZodString, string, string>>;
}>, {
merkle: ZodDefault<ZodRecord<ZodString, ZodString>>;
}>, {
symbol: ZodDefault<ZodOptional<ZodString>>;
Expand All @@ -4511,8 +4507,6 @@ export class TokenDrop extends Erc20<DropERC20> {
merkle: Record<string, string>;
image?: any;
external_link?: string | undefined;
seller_fee_basis_points: number;
fee_recipient: string;
primary_sale_recipient: string;
platform_fee_basis_points: number;
platform_fee_recipient: string;
Expand All @@ -4524,24 +4518,19 @@ export class TokenDrop extends Erc20<DropERC20> {
merkle?: Record<string, string> | undefined;
image?: any;
external_link?: string | undefined;
seller_fee_basis_points?: number | undefined;
fee_recipient?: string | undefined;
primary_sale_recipient: string;
platform_fee_basis_points?: number | undefined;
platform_fee_recipient?: string | undefined;
trusted_forwarders?: string[] | undefined;
}>;
output: ZodObject<extendShape<extendShape<extendShape<extendShape< {
output: ZodObject<extendShape<extendShape<extendShape< {
name: ZodString;
description: ZodOptional<ZodString>;
image: ZodOptional<ZodUnion<[ZodTypeAny, ZodString]>>;
external_link: ZodOptional<ZodString>;
}, {
image: ZodOptional<ZodString>;
}>, {
seller_fee_basis_points: ZodDefault<ZodNumber>;
fee_recipient: ZodDefault<ZodEffects<ZodString, string, string>>;
}>, {
merkle: ZodDefault<ZodRecord<ZodString, ZodString>>;
}>, {
symbol: ZodDefault<ZodOptional<ZodString>>;
Expand All @@ -4552,8 +4541,6 @@ export class TokenDrop extends Erc20<DropERC20> {
merkle: Record<string, string>;
image?: string | undefined;
external_link?: string | undefined;
seller_fee_basis_points: number;
fee_recipient: string;
symbol: string;
}, {
[x: string]: Json;
Expand All @@ -4562,19 +4549,14 @@ export class TokenDrop extends Erc20<DropERC20> {
merkle?: Record<string, string> | undefined;
image?: string | undefined;
external_link?: string | undefined;
seller_fee_basis_points?: number | undefined;
fee_recipient?: string | undefined;
symbol?: string | undefined;
}>;
input: ZodObject<extendShape<extendShape<extendShape< {
input: ZodObject<extendShape<extendShape< {
name: ZodString;
description: ZodOptional<ZodString>;
image: ZodOptional<ZodUnion<[ZodTypeAny, ZodString]>>;
external_link: ZodOptional<ZodString>;
}, {
seller_fee_basis_points: ZodDefault<ZodNumber>;
fee_recipient: ZodDefault<ZodEffects<ZodString, string, string>>;
}>, {
merkle: ZodDefault<ZodRecord<ZodString, ZodString>>;
}>, {
symbol: ZodDefault<ZodOptional<ZodString>>;
Expand All @@ -4584,17 +4566,13 @@ export class TokenDrop extends Erc20<DropERC20> {
merkle: Record<string, string>;
image?: any;
external_link?: string | undefined;
seller_fee_basis_points: number;
fee_recipient: string;
symbol: string;
}, {
name: string;
description?: string | undefined;
merkle?: Record<string, string> | undefined;
image?: any;
external_link?: string | undefined;
seller_fee_basis_points?: number | undefined;
fee_recipient?: string | undefined;
symbol?: string | undefined;
}>;
};
Expand Down
5 changes: 4 additions & 1 deletion src/common/claim-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@ export async function prepareClaim(
const currencyAddress = activeClaimCondition.currencyAddress;
if (price.gt(0)) {
if (isNativeToken(currencyAddress)) {
overrides["value"] = BigNumber.from(price).mul(quantity);
overrides["value"] = BigNumber.from(price)
.mul(quantity)
.div(ethers.utils.parseUnits("1", tokenDecimals));
} else {
await approveErc20Allowance(
contractWrapper,
currencyAddress,
price,
quantity,
tokenDecimals,
);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/common/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
constants,
providers,
utils,
ethers,
} from "ethers";
import {
getNativeTokenByChainId,
Expand Down Expand Up @@ -112,6 +113,7 @@ export async function approveErc20Allowance(
currencyAddress: string,
price: BigNumber,
quantity: BigNumberish,
tokenDecimals: number,
) {
const signer = contractToApprove.getSigner();
const provider = contractToApprove.getProvider();
Expand All @@ -124,7 +126,9 @@ export async function approveErc20Allowance(
const owner = await contractToApprove.getSignerAddress();
const spender = contractToApprove.readContract.address;
const allowance = await erc20.readContract.allowance(owner, spender);
const totalPrice = BigNumber.from(price).mul(BigNumber.from(quantity));
const totalPrice = BigNumber.from(price)
.mul(BigNumber.from(quantity))
.div(ethers.utils.parseUnits("1", tokenDecimals));
if (allowance.lt(totalPrice)) {
await erc20.sendTransaction("approve", [
spender,
Expand Down
9 changes: 2 additions & 7 deletions src/core/classes/drop-claim-conditions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { IStorage } from "../interfaces/IStorage";
import { DropErc721ContractSchema } from "../../schema/contracts/drop-erc721";
import { ContractMetadata } from "./contract-metadata";
import { DropERC20, DropERC721, IERC20, IERC20Metadata } from "contracts";
import { BigNumber, ethers, constants } from "ethers";
import { BigNumber, constants, ethers } from "ethers";
import { isNativeToken } from "../../common/currency";
import { ContractWrapper } from "./contract-wrapper";
import { Amount, ClaimCondition, ClaimConditionInput } from "../../types";
Expand All @@ -17,7 +16,6 @@ import {
} from "../../common/claim-conditions";

import { isBrowser } from "../../common/utils";
import { DropErc20ContractSchema } from "../../schema/contracts/drop-erc20";
import { detectContractFeature } from "../../common/feature-detection";
import { PriceSchema } from "../../schema";
import { includesErrorMessage } from "../../common";
Expand All @@ -34,10 +32,7 @@ export class DropClaimConditions<TContract extends DropERC721 | DropERC20> {

constructor(
contractWrapper: ContractWrapper<TContract>,
metadata: ContractMetadata<
TContract,
typeof DropErc721ContractSchema | typeof DropErc20ContractSchema
>,
metadata: ContractMetadata<TContract, any>,
storage: IStorage,
) {
this.storage = storage;
Expand Down
15 changes: 4 additions & 11 deletions src/schema/contracts/drop-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,16 @@ import {
CommonContractSchema,
CommonPlatformFeeSchema,
CommonPrimarySaleSchema,
CommonRoyaltySchema,
CommonSymbolSchema,
CommonTrustedForwarderSchema,
} from "./common";
import { MerkleSchema } from "./common/snapshots";

export const DropErc20ContractInput = CommonContractSchema.merge(
CommonRoyaltySchema,
)
.merge(MerkleSchema)
.merge(CommonSymbolSchema);
export const DropErc20ContractInput =
CommonContractSchema.merge(MerkleSchema).merge(CommonSymbolSchema);

export const DropErc20ContractOutput = CommonContractOutputSchema.merge(
CommonRoyaltySchema,
)
.merge(MerkleSchema)
.merge(CommonSymbolSchema);
export const DropErc20ContractOutput =
CommonContractOutputSchema.merge(MerkleSchema).merge(CommonSymbolSchema);

export const DropErc20ContractDeploy = DropErc20ContractInput.merge(
CommonPlatformFeeSchema,
Expand Down
11 changes: 11 additions & 0 deletions test/token-drop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ describe("Token Drop Contract", async () => {
expect(balance.displayValue).to.eq("142.69");
});

it("should allow claiming with a price", async () => {
await dropContract.claimConditions.set([
{
price: 0.1,
},
]);
await dropContract.claim(100);
const balance = await dropContract.balance();
expect(balance.displayValue).to.eq("100.0");
});

it("should allow setting max claims per wallet", async () => {
await dropContract.claimConditions.set([
{
Expand Down