Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit e6e275c

Browse files
committed
support treasury as clientReceiver in escrows (BuilderOSS#501)
* set treasury as clientReceiver in escrows * fixed proposal nav image * fixed escrow data decoding
1 parent ff53438 commit e6e275c

File tree

8 files changed

+278
-164
lines changed

8 files changed

+278
-164
lines changed

apps/web/src/modules/create-proposal/components/TransactionForm/Escrow/Escrow.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ import { useRouter } from 'next/router'
55
import { useState } from 'react'
66
import useSWR from 'swr'
77
import { encodeFunctionData, formatEther } from 'viem'
8+
import { useDaoStore } from 'src/modules/dao'
89

910
import SWR_KEYS from 'src/constants/swrKeys'
1011
import { ProposalsResponse } from 'src/data/subgraph/requests/proposalsQuery'
1112
import { getProposals } from 'src/data/subgraph/requests/proposalsQuery'
1213
import { TransactionType } from 'src/modules/create-proposal/constants'
1314
import { useProposalStore } from 'src/modules/create-proposal/stores'
1415
import { getChainFromLocalStorage } from 'src/utils/getChainFromLocalStorage'
16+
import { InvoiceMetadata, Milestone as MilestoneMetadata } from '@smartinvoicexyz/types'
1517

1618
import EscrowForm from './EscrowForm'
1719
import { EscrowFormValues } from './EscrowForm.schema'
1820
import {
19-
createEscrowData,
21+
encodeEscrowData,
2022
deployEscrowAbi,
2123
getEscrowBundler,
24+
ESCROW_TYPE,
2225
} from './EscrowUtils'
2326

2427
export const Escrow: React.FC = () => {
@@ -31,6 +34,10 @@ export const Escrow: React.FC = () => {
3134

3235
const addTransaction = useProposalStore((state) => state.addTransaction)
3336

37+
const {
38+
addresses: { treasury },
39+
} = useDaoStore()
40+
3441
const { data } = useSWR<ProposalsResponse>(
3542
isReady ? [SWR_KEYS.PROPOSALS, chainId, query.token, '0'] : null,
3643
(_, chainId, token, _page) => getProposals(chainId, token, 1, Number(0))
@@ -40,7 +47,10 @@ export const Escrow: React.FC = () => {
4047

4148
const handleEscrowTransaction = useCallback(
4249
async (values: EscrowFormValues) => {
43-
const ipfsDataToUpload = {
50+
if (!treasury) {
51+
return;
52+
}
53+
const ipfsDataToUpload: InvoiceMetadata = {
4454
title: 'Proposal #' + (lastProposalId + 1),
4555
description: window?.location.href.replace(
4656
'/proposal/create',
@@ -72,7 +82,7 @@ export const Escrow: React.FC = () => {
7282
],
7383
}
7484
: {}),
75-
})),
85+
} as MilestoneMetadata)),
7686
}
7787

7888
const jsonDataToUpload = JSON.stringify(ipfsDataToUpload, null, 2)
@@ -108,7 +118,7 @@ export const Escrow: React.FC = () => {
108118
}
109119

110120
// create bundler transaction data
111-
const escrowData = createEscrowData(values, cid, chainId)
121+
const escrowData = encodeEscrowData(values, treasury, cid, chainId)
112122
const milestoneAmounts = values.milestones.map((x) => x.amount * 10 ** 18)
113123
const fundAmount = milestoneAmounts.reduce((acc, x) => acc + x, 0)
114124

@@ -118,30 +128,25 @@ export const Escrow: React.FC = () => {
118128
calldata: encodeFunctionData({
119129
abi: deployEscrowAbi,
120130
functionName: 'deployEscrow',
121-
args: [milestoneAmounts, escrowData, fundAmount],
131+
args: [values.recipientAddress, milestoneAmounts, escrowData, ESCROW_TYPE, fundAmount],
122132
}),
123133
value: formatEther(BigInt(fundAmount)),
124134
}
125135

126136
try {
127-
// add 2.5s delay here before adding to queue
128-
setTimeout(
129-
() =>
130-
addTransaction({
131-
type: TransactionType.ESCROW,
132-
summary: `Create and fund new Escrow with ${formatEther(
133-
BigInt(fundAmount)
134-
)} ETH`,
135-
transactions: [escrow],
136-
}),
137-
2500
138-
)
137+
addTransaction({
138+
type: TransactionType.ESCROW,
139+
summary: `Create and fund new Escrow with ${formatEther(
140+
BigInt(fundAmount)
141+
)} ETH`,
142+
transactions: [escrow],
143+
})
139144
} catch (err) {
140-
console.log('Error', err)
145+
console.log('Error Adding Transaction', err)
141146
}
142147
setIsSubmitting(false)
143148
},
144-
[addTransaction, chainId, lastProposalId]
149+
[addTransaction, chainId, lastProposalId, treasury]
145150
)
146151

147152
return (

apps/web/src/modules/create-proposal/components/TransactionForm/Escrow/EscrowForm.tsx

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,26 @@ const EscrowForm: React.FC<EscrowFormProps> = ({
188188
: undefined
189189
}
190190
helperText={
191-
'The wallet address to which funds will be released on milestone completions.'
191+
`The wallet address that will receive funds when milestones are completed.`
192+
}
193+
/>
194+
<SmartInput
195+
type={TEXT}
196+
formik={formik}
197+
{...formik.getFieldProps('clientAddress')}
198+
id="clientAddress"
199+
inputLabel={'Controller'}
200+
placeholder={'0x... or .eth'}
201+
isAddress={true}
202+
errorMessage={
203+
formik.touched.clientAddress && formik.errors.clientAddress
204+
? formik.errors.clientAddress
205+
: undefined
206+
}
207+
helperText={
208+
`This wallet will control the escrow and release funds. It can be your DAO’s treasury or a working group’s multisig`
192209
}
193210
/>
194-
{!escrowDelegate && (
195-
<SmartInput
196-
type={TEXT}
197-
formik={formik}
198-
{...formik.getFieldProps('clientAddress')}
199-
id="clientAddress"
200-
inputLabel={'Client'}
201-
placeholder={'0x... or .eth'}
202-
isAddress={true}
203-
errorMessage={
204-
formik.touched.clientAddress && formik.errors.clientAddress
205-
? formik.errors.clientAddress
206-
: undefined
207-
}
208-
helperText={
209-
'This is the wallet address that will control the escrow for releasing funds. This can be DAO Governer Address or multisig of working group within the DAO.'
210-
}
211-
/>
212-
)}
213211

214212
<DatePicker
215213
{...formik.getFieldProps('safetyValveDate')}
@@ -223,7 +221,8 @@ const EscrowForm: React.FC<EscrowFormProps> = ({
223221
? formik.errors.safetyValveDate
224222
: undefined
225223
}
226-
helperText="This is the date funds can be pulled back from the escrow after by dao / multisig."
224+
helperText=
225+
{`The date after which the DAO or multisig can reclaim funds from escrow.`}
227226
/>
228227
<Box mt={'x5'}>
229228
<FieldArray name="milestones">

0 commit comments

Comments
 (0)