Skip to main content

AllOrNothing Treasury

Crowdfunding treasury where funds are only released if the campaign goal is met. If the goal is not reached, backers can claim full refunds. Includes ERC-721 pledge NFTs.

const aon = oak.allOrNothingTreasury('0x...contractAddress');

Methods

Reads

MethodReturnsDescription
getRaisedAmount()bigintCurrent raised amount
getLifetimeRaisedAmount()bigintTotal ever raised
getRefundedAmount()bigintTotal refunded amount
getReward(rewardName)TieredRewardReward details by name
getPlatformHash()HexPlatform hash
getPlatformFeePercent()bigintPlatform fee in basis points
paused()booleanWhether the treasury is paused
cancelled()booleanWhether the treasury is cancelled

ERC-721 reads:

MethodReturnsDescription
balanceOf(owner)bigintNFT balance of an address
ownerOf(tokenId)AddressOwner of a pledge NFT
tokenURI(tokenId)stringMetadata URI for a pledge NFT
name()stringNFT collection name
symbol()stringNFT collection symbol
getApproved(tokenId)AddressApproved operator for a token
isApprovedForAll(owner, operator)booleanWhether operator is approved for all tokens
supportsInterface(interfaceId)booleanERC-165 interface check

Writes

All write methods return Promise<Hex> (transaction hash).

MethodDescription
addRewards(rewardNames, rewards)Register reward tiers
removeReward(rewardName)Remove a reward tier
pledgeForAReward(backer, pledgeToken, shippingFee, rewardNames)Pledge with reward selection
pledgeWithoutAReward(backer, pledgeToken, pledgeAmount)Pledge without selecting a reward
claimRefund(tokenId)Claim a refund using a pledge NFT
disburseFees()Disburse accumulated fees
withdraw()Withdraw funds (only if goal is met)
burn(tokenId)Burn a pledge NFT
pauseTreasury(message)Pause the treasury
unpauseTreasury(message)Unpause the treasury
cancelTreasury(message)Cancel the treasury

ERC-721 writes:

MethodDescription
approve(to, tokenId)Approve an operator for a token
setApprovalForAll(operator, approved)Approve/revoke operator for all tokens
safeTransferFrom(from, to, tokenId)Transfer a pledge NFT
transferFrom(from, to, tokenId)Transfer a pledge NFT (unsafe)

TieredReward type

interface TieredReward {
rewardValue: bigint; // minimum pledge for this tier
isRewardTier: boolean; // true for tiered, false for flat
itemId: readonly Hex[]; // item IDs included
itemValue: readonly bigint[]; // declared item values
itemQuantity: readonly bigint[]; // item quantities
}

Usage examples

Add rewards and pledge

import { keccak256, toHex } from '@oaknetwork/contracts';

const rewardName = keccak256(toHex('early-bird'));
const reward = {
rewardValue: 50_000n,
isRewardTier: true,
itemId: [keccak256(toHex('t-shirt'))],
itemValue: [25_000n],
itemQuantity: [1n],
};

// Add rewards
const addTx = await aon.addRewards([rewardName], [reward]);
await oak.waitForReceipt(addTx);

// Pledge for a reward
const pledgeTx = await aon.pledgeForAReward(
'0x...backerAddress',
'0x...tokenAddress',
5_000n, // shipping fee
[rewardName],
);
await oak.waitForReceipt(pledgeTx);

Pledge without a reward

const txHash = await aon.pledgeWithoutAReward(
'0x...backerAddress',
'0x...tokenAddress',
100_000n, // pledge amount
);
await oak.waitForReceipt(txHash);

Claim a refund

Backers can claim refunds if the goal is not met, using their pledge NFT token ID.

const txHash = await aon.claimRefund(1n); // tokenId
await oak.waitForReceipt(txHash);

Withdraw and disburse (goal met)

const disburseTx = await aon.disburseFees();
await oak.waitForReceipt(disburseTx);

const withdrawTx = await aon.withdraw();
await oak.waitForReceipt(withdrawTx);

Query pledge NFTs

const owner = await aon.ownerOf(1n);
const uri = await aon.tokenURI(1n);
const name = await aon.name();

console.log('NFT owner:', owner);
console.log('Token URI:', uri);
console.log('Collection:', name);