Skip to main content

KeepWhatsRaised Treasury

Crowdfunding treasury where the creator keeps all funds raised regardless of whether the goal is met. Includes configurable fee structures, withdrawal delays, and ERC-721 pledge NFTs.

const kwr = oak.keepWhatsRaisedTreasury('0x...contractAddress');

Methods

Reads

MethodReturnsDescription
getRaisedAmount()bigintCurrent raised amount
getLifetimeRaisedAmount()bigintTotal ever raised
getRefundedAmount()bigintTotal refunded amount
getAvailableRaisedAmount()bigintAvailable raised (raised minus refunded)
getReward(rewardName)TieredRewardReward details by name
getPlatformHash()HexPlatform hash
getPlatformFeePercent()bigintPlatform fee in basis points
getWithdrawalApprovalStatus()booleanWhether withdrawal is approved
getLaunchTime()bigintCampaign launch timestamp
getDeadline()bigintCampaign deadline timestamp
getGoalAmount()bigintFunding goal amount
getPaymentGatewayFee(pledgeId)bigintPayment gateway fee for a pledge
getFeeValue(feeKey)bigintFee value for a registry key
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
supportsInterface(interfaceId)booleanERC-165 interface check

Writes

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

Treasury management:

MethodDescription
configureTreasury(config, campaignData, feeKeys, feeValues)Configure the treasury
pauseTreasury(message)Pause the treasury
unpauseTreasury(message)Unpause the treasury
cancelTreasury(message)Cancel the treasury
updateDeadline(deadline)Update campaign deadline
updateGoalAmount(goalAmount)Update funding goal

Rewards and pledges:

MethodDescription
addRewards(rewardNames, rewards)Register reward tiers
removeReward(rewardName)Remove a reward tier
pledgeForAReward(pledgeId, backer, pledgeToken, tip, rewardNames)Pledge with reward selection and optional tip
pledgeWithoutAReward(pledgeId, backer, pledgeToken, pledgeAmount, tip)Pledge without a reward
setFeeAndPledge(pledgeId, backer, pledgeToken, pledgeAmount, tip, fee, reward, isPledgeForAReward)Set fee and pledge in one call
setPaymentGatewayFee(pledgeId, fee)Set payment gateway fee

Funds:

MethodDescription
approveWithdrawal()Approve fund withdrawal
claimFund()Claim raised funds
claimTip()Claim accumulated tips
claimRefund(tokenId)Claim a refund using a pledge NFT
disburseFees()Disburse accumulated fees
withdraw(token, amount)Withdraw a specific token amount

ERC-721:

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

Configuration types

KeepWhatsRaisedConfig

interface KeepWhatsRaisedConfig {
minimumWithdrawalForFeeExemption: bigint; // min amount exempt from withdrawal fee
withdrawalDelay: bigint; // seconds between approval and withdrawal
refundDelay: bigint; // seconds before backers can claim refunds
configLockPeriod: bigint; // seconds config is locked after setting
isColombianCreator: boolean; // Colombian creator tax treatment
}

KeepWhatsRaisedFeeKeys / FeeValues

interface KeepWhatsRaisedFeeKeys {
flatFeeKey: Hex; // registry key for flat withdrawal fee
cumulativeFlatFeeKey: Hex; // registry key for cumulative flat fee cap
grossPercentageFeeKeys: readonly Hex[]; // registry keys for percentage fees
}

interface KeepWhatsRaisedFeeValues {
flatFeeValue: bigint; // flat fee amount
cumulativeFlatFeeValue: bigint; // cumulative flat fee cap
grossPercentageFeeValues: readonly bigint[]; // percentage fee values
}

Usage examples

Configure the treasury

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

const now = getCurrentTimestamp();

const txHash = await kwr.configureTreasury(
{
minimumWithdrawalForFeeExemption: 100_000n,
withdrawalDelay: 86_400n, // 1 day
refundDelay: 604_800n, // 7 days
configLockPeriod: 259_200n, // 3 days
isColombianCreator: false,
},
{
launchTime: now + 3_600n,
deadline: addDays(now, 30),
goalAmount: 1_000_000n,
currency: toHex('USD', { size: 32 }),
},
{
flatFeeKey: keccak256(toHex('flatFee')),
cumulativeFlatFeeKey: keccak256(toHex('cumFlatFee')),
grossPercentageFeeKeys: [keccak256(toHex('percentFee'))],
},
{
flatFeeValue: 1_000n,
cumulativeFlatFeeValue: 10_000n,
grossPercentageFeeValues: [500n], // 5%
},
);
await oak.waitForReceipt(txHash);

Pledge with a reward

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

const pledgeId = keccak256(toHex('pledge-001'));
const rewardName = keccak256(toHex('gold-tier'));

const txHash = await kwr.pledgeForAReward(
pledgeId,
'0x...backerAddress',
'0x...tokenAddress',
5_000n, // tip
[rewardName],
);
await oak.waitForReceipt(txHash);

Withdraw funds

// Step 1: Approve withdrawal
const approveTx = await kwr.approveWithdrawal();
await oak.waitForReceipt(approveTx);

// Step 2: Wait for withdrawal delay, then claim
const claimTx = await kwr.claimFund();
await oak.waitForReceipt(claimTx);

// Claim tips separately
const tipTx = await kwr.claimTip();
await oak.waitForReceipt(tipTx);

Disburse and withdraw specific tokens

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

const withdrawTx = await kwr.withdraw('0x...tokenAddress', 50_000n);
await oak.waitForReceipt(withdrawTx);