Skip to content

Commit 973460f

Browse files
fix: donating with erc20 issue during direct donations
1 parent e42c0d7 commit 973460f

File tree

8 files changed

+54
-19
lines changed

8 files changed

+54
-19
lines changed

packages/common/src/allo/allo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export interface Allo {
265265
recipient: Address;
266266
nonce: bigint;
267267
requireTokenApproval?: boolean;
268+
strategyAddress: Address;
268269
}) => AlloOperation<
269270
Result<null>,
270271
{

packages/common/src/allo/backends/allo-v1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,14 +1329,14 @@ export class AlloV1 implements Allo {
13291329
});
13301330
}
13311331

1332-
13331332
directAllocation(args: {
13341333
tokenAddress: Address;
13351334
poolId: string;
13361335
amount: bigint;
13371336
recipient: Address;
13381337
nonce: bigint;
13391338
requireTokenApproval?: boolean;
1339+
strategyAddress: Address;
13401340
}): AlloOperation<
13411341
Result<null>,
13421342
{

packages/common/src/allo/backends/allo-v2.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,9 @@ export class AlloV2 implements Allo {
15471547
emit("transactionStatus", success(receipt));
15481548
} catch (err) {
15491549
console.log(err);
1550-
const result = new AlloError(`Failed to ${args.addOrRemove} profile members`);
1550+
const result = new AlloError(
1551+
`Failed to ${args.addOrRemove} profile members`
1552+
);
15511553
emit("transactionStatus", error(result));
15521554
return error(result);
15531555
}
@@ -1570,6 +1572,7 @@ export class AlloV2 implements Allo {
15701572
recipient: Address;
15711573
nonce: bigint;
15721574
requireTokenApproval?: boolean;
1575+
strategyAddress: Address;
15731576
}): AlloOperation<
15741577
Result<null>,
15751578
{
@@ -1591,9 +1594,7 @@ export class AlloV2 implements Allo {
15911594
poolId: poolId,
15921595
});
15931596

1594-
const strategyAddress = getDirectAllocationStrategyAddress(this.chainId);
1595-
1596-
if (strategyAddress === undefined) {
1597+
if (args.strategyAddress === undefined) {
15971598
return error(new AlloError("Direct allocation strategy not found"));
15981599
}
15991600

@@ -1604,7 +1605,7 @@ export class AlloV2 implements Allo {
16041605
address: args.tokenAddress,
16051606
abi: Erc20ABI,
16061607
functionName: "approve",
1607-
args: [strategyAddress, args.amount],
1608+
args: [args.strategyAddress, args.amount],
16081609
});
16091610

16101611
if (approvalTx.type === "error") {

packages/data-layer/src/data-layer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,17 @@ export class DataLayer {
685685
async getRoundForExplorer({
686686
roundId,
687687
chainId,
688+
isDirectAllocationRound,
688689
}: {
689690
roundId: string;
690691
chainId: number;
692+
isDirectAllocationRound?: boolean;
691693
}): Promise<{ round: Round } | null> {
694+
const directAllocationRound = isDirectAllocationRound ?? false;
692695
const requestVariables = {
693696
roundId,
694697
chainId,
698+
isDirectAllocationRound: directAllocationRound,
695699
};
696700

697701
const response: { rounds: RoundForExplorer[] } = await request(

packages/data-layer/src/queries.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ export const getProjectsBySearchTerm = gql`
494494
searchProjects(
495495
searchTerm: $searchTerm
496496
filter: {
497-
metadata: {isNull: false }
497+
metadata: { isNull: false }
498498
tags: { equalTo: "allo-v2" }
499499
not: { tags: { contains: "program" } }
500500
chainId: {
@@ -609,9 +609,9 @@ export const getRoundByIdAndChainId = gql`
609609
query getRoundByIdAndChainId($roundId: String!, $chainId: Int!) {
610610
rounds(
611611
first: 1
612-
filter: {
613-
id: { equalTo: $roundId },
614-
chainId: { equalTo: $chainId },
612+
filter: {
613+
id: { equalTo: $roundId }
614+
chainId: { equalTo: $chainId }
615615
roundMetadata: { isNull: false }
616616
}
617617
) {
@@ -733,13 +733,17 @@ export const getRoundsForManagerByAddress = gql`
733733
`;
734734

735735
export const getRoundForExplorer = gql`
736-
query getRoundForExplorer($roundId: String!, $chainId: Int!) {
736+
query getRoundForExplorer(
737+
$roundId: String!
738+
$chainId: Int!
739+
$isDirectAllocationRound: Boolean!
740+
) {
737741
rounds(
738742
first: 1
739-
filter: {
740-
id: { equalTo: $roundId },
741-
chainId: { equalTo: $chainId },
742-
roundMetadata: { isNull: false }
743+
filter: {
744+
id: { equalTo: $roundId }
745+
chainId: { equalTo: $chainId }
746+
roundMetadata: { isNull: $isDirectAllocationRound }
743747
}
744748
) {
745749
id

packages/grant-explorer/src/context/RoundContext.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ function fetchRoundsById(
9595
dispatch: Dispatch,
9696
dataLayer: DataLayer,
9797
chainId: number,
98-
roundId: string
98+
roundId: string,
99+
isDirectAllocationRound?: boolean
99100
) {
100101
dispatch({ type: ActionType.SET_LOADING, payload: true });
101102

102103
dataLayer
103104
.getRoundForExplorer({
104105
roundId,
105106
chainId,
107+
isDirectAllocationRound,
106108
})
107109
.then((result) => {
108110
if (result === null) {
@@ -123,7 +125,8 @@ function fetchRoundsById(
123125

124126
export const useRoundById = (
125127
chainId: number,
126-
roundId: string
128+
roundId: string,
129+
isDirectAllocationRound?: boolean
127130
): {
128131
round?: Round;
129132
isLoading: boolean;
@@ -143,7 +146,13 @@ export const useRoundById = (
143146
);
144147

145148
if (!existingRound?.token) {
146-
fetchRoundsById(context.dispatch, dataLayer, chainId, roundId);
149+
fetchRoundsById(
150+
context.dispatch,
151+
dataLayer,
152+
chainId,
153+
roundId,
154+
isDirectAllocationRound
155+
);
147156
}
148157
}
149158
}, [chainId, roundId]); // eslint-disable-line react-hooks/exhaustive-deps

packages/grant-explorer/src/features/projects/ViewProject.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { ethers } from "ethers";
5959
import { useNavigate } from "react-router-dom";
6060
import { Logger } from "ethers/lib/utils";
6161
import SwitchNetworkModal from "../common/SwitchNetworkModal";
62+
import { useRoundById } from "../../context/RoundContext";
6263

6364
const CalendarIcon = (props: React.SVGProps<SVGSVGElement>) => {
6465
return (
@@ -113,6 +114,7 @@ export default function ViewProject() {
113114
const allo = useAllo();
114115
const navigate = useNavigate();
115116
const { switchChain } = useSwitchChain();
117+
const isDirectAllocationRound = true;
116118

117119
const {
118120
data: projectData,
@@ -136,6 +138,14 @@ export default function ViewProject() {
136138
dataLayer
137139
);
138140

141+
const { round } = useRoundById(
142+
chainId ?? 1,
143+
directAllocationPoolId?.toString() ?? "",
144+
isDirectAllocationRound
145+
);
146+
147+
const directAllocationStrategyAddress = round?.payoutStrategy.id;
148+
139149
const {
140150
directAllocation,
141151
tokenApprovalStatus,
@@ -455,7 +465,8 @@ export default function ViewProject() {
455465
if (
456466
directDonationAmount === undefined ||
457467
allo === null ||
458-
payoutToken === undefined
468+
payoutToken === undefined ||
469+
directAllocationStrategyAddress === undefined
459470
) {
460471
return;
461472
}
@@ -500,6 +511,7 @@ export default function ViewProject() {
500511
recipient,
501512
nonce,
502513
requireTokenApproval,
514+
strategyAddress: directAllocationStrategyAddress,
503515
});
504516
} catch (error) {
505517
if (error === Logger.errors.TRANSACTION_REPLACED) {

packages/grant-explorer/src/features/projects/hooks/useDirectAllocation.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type DirectAllocationParams = {
3333
recipient: string;
3434
nonce: bigint;
3535
requireTokenApproval?: boolean;
36+
strategyAddress: string;
3637
};
3738

3839
type SubmitFundParams = DirectAllocationParams & {
@@ -154,6 +155,7 @@ async function _directAllocation({
154155
recipient,
155156
nonce,
156157
requireTokenApproval,
158+
strategyAddress,
157159
}: SubmitFundParams) {
158160
resetToInitialState(context);
159161

@@ -163,6 +165,7 @@ async function _directAllocation({
163165
.toBigInt();
164166

165167
const recipientAddress = getAddress(recipient);
168+
const directAllocationStrategyAddress = getAddress(strategyAddress);
166169

167170
context.setTokenApprovalStatus(ProgressStatus.IN_PROGRESS);
168171

@@ -174,6 +177,7 @@ async function _directAllocation({
174177
recipient: recipientAddress,
175178
nonce,
176179
requireTokenApproval,
180+
strategyAddress: directAllocationStrategyAddress,
177181
})
178182
.on("tokenApprovalStatus", (tx) => {
179183
if (tx.type === "error") {

0 commit comments

Comments
 (0)