Skip to content

Switch from ExampleSale to SettlementSale contract#4

Merged
WillSewell merged 2 commits intomainfrom
01-26-switch_from_examplesale_to_settlementsale_contract
Jan 26, 2026
Merged

Switch from ExampleSale to SettlementSale contract#4
WillSewell merged 2 commits intomainfrom
01-26-switch_from_examplesale_to_settlementsale_contract

Conversation

@WillSewell
Copy link
Copy Markdown
Collaborator

@WillSewell WillSewell commented Jan 26, 2026

Switches from the very simple ExampleSale contract to the "proper" SettlementSale contract.

  • Switches to base sepolia
  • Use can now enter how much they want to commit
  • For now just supports erc20 approvals
  • Runs simulations before submitting transactions

Screen Recording 2026-01-26 at 15.34.48.mov (uploaded via Graphite)

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@WillSewell WillSewell marked this pull request as ready for review January 26, 2026 15:36
@WillSewell WillSewell force-pushed the 01-26-switch_from_examplesale_to_settlementsale_contract branch 2 times, most recently from f2547da to f1ac5e8 Compare January 26, 2026 15:43
Comment thread src/hooks.ts
Comment on lines -75 to -79
useEffect(() => {
if (txReceipt?.status === "success") {
refetchAmountInContract();
}
}, [txReceipt?.status, refetchAmountInContract]);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Struggled to get this working - seems like sometimes it would return the fresh state from the contract, but other times would return a stale value. I'm guessing that even after waiting for a successful tx receipt, there's no guarantee a subsequent read won't get a stale value.

So I've just switched to polling every 3 seconds.

But let me know if you have any suggestions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is a common problem. just polling is fine I think

@WillSewell WillSewell force-pushed the 01-26-switch_from_examplesale_to_settlementsale_contract branch from f1ac5e8 to 085e855 Compare January 26, 2026 16:09
WillSewell added a commit to sunrisedotdev/sonar-example-nextjs that referenced this pull request Jan 26, 2026
Comment thread .env.local
VITE_SALE_CONTRACT_ADDRESS=0x51BcE35d57833253EAccd6901e95eb6772aFfc8D

# Address of the payment token
VITE_PAYMENT_TOKEN_ADDRESS=0x036CbD53842c5426634e7929541eC2318f3dCF7e # USDC
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably also support multiple?

Comment thread src/components/sale/CommitCard.tsx Outdated
function ReadyToPurchaseSection({
walletAddress,
function CommitSection({
entityID,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth to differentiate sale specific vs client ID

Comment thread src/components/sale/CommitCard.tsx Outdated

const [loading, setLoading] = useState(false);
const [error, setError] = useState<Error | undefined>(undefined);
const [commitAmount, setCommitAmount] = useState<string>("1");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: humanReadableAmount

Comment thread src/components/sale/CommitCard.tsx Outdated
setError(undefined);
try {
const purchasePermitResp = await generatePurchasePermit();
const amountInMicroUnits = BigInt(Math.floor(parseFloat(commitAmount) * 1e6));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe just amount, which aligns it with the committedAmount below. I think let's try to get rid of the micro terminology since it's a bit misleading imo

Comment thread README.md

The example uses a [SettlementSale](https://github.com/sunrisedotdev/sonar/blob/main/contracts/src/SettlementSale.sol) contract on Base Sepolia.

In order to test committing funds, you will need to have USDC to commit and ETH to pay for the gas.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the contract now also supports USDT, so might be worth noting? USDT is a bit easier in practice since one can directly mint from the contract

Comment thread src/config.ts Outdated
export const saleContract =
(import.meta.env.VITE_SALE_CONTRACT_ADDRESS as Hex) ?? "0x0000000000000000000000000000000000000000";
export const paymentTokenAddress =
(import.meta.env.VITE_PAYMENT_TOKEN_ADDRESS as `0x${string}`) ?? "0x0000000000000000000000000000000000000000";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as Hex?

Comment thread src/hooks.ts
Comment on lines -75 to -79
useEffect(() => {
if (txReceipt?.status === "success") {
refetchAmountInContract();
}
}, [txReceipt?.status, refetchAmountInContract]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is a common problem. just polling is fine I think

@WillSewell WillSewell requested a review from cxkoda January 26, 2026 17:41
@WillSewell WillSewell merged commit 5637bbc into main Jan 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants