Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Add erc721.PrepareClaimTo
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-maj committed Aug 7, 2023
1 parent c05a9d1 commit 64d9504
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
51 changes: 34 additions & 17 deletions thirdweb/erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,7 @@ func (erc721 *ERC721) Claim(ctx context.Context, quantity int) (*types.Transacti
//
// tx, err := contract.ERC721.ClaimTo(context.Background(), address, quantity)
func (erc721 *ERC721) ClaimTo(ctx context.Context, destinationAddress string, quantity int) (*types.Transaction, error) {
addressToClaim := erc721.helper.GetSignerAddress().Hex()

claimVerification, err := erc721.PrepareClaim(ctx, addressToClaim, quantity, true)
preparedClaimTo, err := erc721.PrepareClaimTo(ctx, destinationAddress, quantity)
if err != nil {
return nil, err
}
Expand All @@ -879,23 +877,16 @@ func (erc721 *ERC721) ClaimTo(ctx context.Context, destinationAddress string, qu
return nil, err
}

txOpts.Value = claimVerification.Value

proof := abi.IDropAllowlistProof{
Proof: claimVerification.Proofs,
QuantityLimitPerWallet: claimVerification.MaxClaimable,
PricePerToken: claimVerification.PriceInProof,
Currency: common.HexToAddress(claimVerification.CurrencyAddressInProof),
}
txOpts.Value = preparedClaimTo.Value

tx, err := erc721.drop.Claim(
txOpts,
common.HexToAddress(destinationAddress),
big.NewInt(int64(quantity)),
common.HexToAddress(claimVerification.CurrencyAddress),
claimVerification.Price,
proof,
[]byte{},
preparedClaimTo.Receiver,
preparedClaimTo.Quantity,
preparedClaimTo.Currency,
preparedClaimTo.PricePerToken,
preparedClaimTo.AllowlistProof,
preparedClaimTo.Data,
)
if err != nil {
return nil, err
Expand All @@ -904,6 +895,32 @@ func (erc721 *ERC721) ClaimTo(ctx context.Context, destinationAddress string, qu
return erc721.helper.AwaitTx(ctx, tx.Hash())
}

func (erc721 *ERC721) PrepareClaimTo(ctx context.Context, destinationAddress string, quantity int) (*PreparedClaimTo, error) {
addressToClaim := erc721.helper.GetSignerAddress().Hex()

claimVerification, err := erc721.PrepareClaim(ctx, addressToClaim, quantity, true)
if err != nil {
return nil, err
}

proof := abi.IDropAllowlistProof{
Proof: claimVerification.Proofs,
QuantityLimitPerWallet: claimVerification.MaxClaimable,
PricePerToken: claimVerification.PriceInProof,
Currency: common.HexToAddress(claimVerification.CurrencyAddressInProof),
}

return &PreparedClaimTo{
Value: claimVerification.Value,
Receiver: common.HexToAddress(destinationAddress),
Quantity: big.NewInt(int64(quantity)),
Currency: common.HexToAddress(claimVerification.CurrencyAddress),
PricePerToken: claimVerification.Price,
AllowlistProof: proof,
Data: []byte{},
}, nil
}

func (erc721 *ERC721) GetClaimArguments(
ctx context.Context,
destinationAddress string,
Expand Down
10 changes: 10 additions & 0 deletions thirdweb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ type EditionMetadataInput struct {
Supply int
}

type PreparedClaimTo struct {
Receiver common.Address
Quantity *big.Int
Currency common.Address
PricePerToken *big.Int
AllowlistProof abi.IDropAllowlistProof
Data []byte
Value *big.Int
}

type ClaimVerification struct {
Value *big.Int
Proofs [][32]byte
Expand Down

0 comments on commit 64d9504

Please sign in to comment.