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

Add erc721.PrepareClaimTo #139

Merged
merged 8 commits into from
Aug 7, 2023
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 .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build & Test
env:
SDK_ALCHEMY_KEY: ${{ secrets.SDK_ALCHEMY_KEY }}
THIRDWEB_SECRET_KEY: ${{ secrets.THIRDWEB_SECRET_KEY }}

on: [push, pull_request]
jobs:
Expand All @@ -19,7 +20,7 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Use Node.js
uses: actions/setup-node@v1
with:
Expand All @@ -30,4 +31,3 @@ jobs:

- name: Test
run: yarn add hardhat && make test

4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.PHONY: abi docs publish local-test

export THIRDWEB_SECRET_KEY

SHELL := /bin/bash

abi:
Expand Down Expand Up @@ -127,7 +129,7 @@ stop-docker:

test: FORCE
docker build . -t hardhat-mainnet-fork
docker start hardhat-node || docker run --name hardhat-node -d -p 8545:8545 -e SDK_ALCHEMY_KEY=${SDK_ALCHEMY_KEY} hardhat-mainnet-fork
docker start hardhat-node || docker run --name hardhat-node -d -p 8545:8545 -e "THIRDWEB_SECRET_KEY=${THIRDWEB_SECRET_KEY}" -e "SDK_ALCHEMY_KEY=${SDK_ALCHEMY_KEY}" hardhat-mainnet-fork
sudo bash ./scripts/test/await-hardhat.sh
go clean -testcache
go test -v ./thirdweb
Expand Down
4 changes: 2 additions & 2 deletions thirdweb/erc1155.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ func (erc1155 *ERC1155) Claim(ctx context.Context, tokenId int, quantity int) (*
//
// tx, err := contract.ClaimTo(context.Background(), address, tokenId, quantity)
func (erc1155 *ERC1155) ClaimTo(ctx context.Context, destinationAddress string, tokenId int, quantity int) (*types.Transaction, error) {
claimVerification, err := erc1155.prepareClaim(ctx, tokenId, quantity)
claimVerification, err := erc1155.PrepareClaim(ctx, tokenId, quantity)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -787,7 +787,7 @@ func (erc1155 *ERC1155) ClaimTo(ctx context.Context, destinationAddress string,
return erc1155.helper.AwaitTx(ctx, tx.Hash())
}

func (erc1155 *ERC1155) prepareClaim(ctx context.Context, tokenId int, quantity int) (*ClaimVerification, error) {
func (erc1155 *ERC1155) PrepareClaim(ctx context.Context, tokenId int, quantity int) (*ClaimVerification, error) {
addressToClaim := erc1155.helper.GetSignerAddress().Hex()
claimCondition, err := erc1155.ClaimConditions.GetActive(ctx, tokenId)
if err != nil {
Expand Down
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
Loading