Skip to content

feat: add direct donate button #3553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5b05409
wip
thelostone-mc Jul 11, 2024
8772885
feat: add directAllocation to allo-v2
bhargavaparoksham Jul 11, 2024
c457737
fix: build issue
bhargavaparoksham Jul 11, 2024
00ed5a6
feat: update allo sdk version
bhargavaparoksham Jul 11, 2024
629e8c4
feat: fetch txData from sdk
bhargavaparoksham Jul 11, 2024
77cbd90
fix: build issues
bhargavaparoksham Jul 11, 2024
64aea06
fix: other issues
bhargavaparoksham Jul 11, 2024
dae94ae
feat: update ui
bhargavaparoksham Jul 11, 2024
138348f
feat: add useDirectAllocation hook
bhargavaparoksham Jul 11, 2024
c21d8e5
feat: add progress modal cmponent in explorer
bhargavaparoksham Jul 12, 2024
75696b3
feat: add getDirectAllocationPoolId
bhargavaparoksham Jul 12, 2024
7b30f23
feat: add handleDonate to project
bhargavaparoksham Jul 12, 2024
ffcfd0d
update UI
thelostone-mc Jul 12, 2024
fb696cf
fix: zeroAddress bug
bhargavaparoksham Jul 15, 2024
b368771
feat: minor ui updates
bhargavaparoksham Jul 15, 2024
3560fbd
test: update tests
bhargavaparoksham Jul 15, 2024
5a6a7c6
update poolId (new contract deployed
thelostone-mc Jul 16, 2024
1ab7d4d
swap out fo sdk
thelostone-mc Jul 16, 2024
f748ac3
chore: code cleanup
bhargavaparoksham Jul 16, 2024
f755d5d
feat: handle case when wallet is not connected
bhargavaparoksham Jul 17, 2024
aacd3b8
feat: update max height
bhargavaparoksham Jul 17, 2024
512b41c
feat: handle error states
bhargavaparoksham Jul 17, 2024
16d2327
feat: show donate button only on chains that support direct donation
bhargavaparoksham Jul 17, 2024
c9a20b4
feat: add error modal
bhargavaparoksham Jul 17, 2024
81e8380
tests: fix failing tests
bhargavaparoksham Jul 17, 2024
67b24b1
fix: erc20 donation issue
bhargavaparoksham Jul 17, 2024
759354c
fix: decimal issue on donation modal
bhargavaparoksham Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@allo-team/allo-v2-sdk": "^1.0.76",
"@allo-team/allo-v2-sdk": "^1.0.77",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@gitcoin/gitcoin-chain-data": "^1.0.17",
Expand Down
17 changes: 17 additions & 0 deletions packages/common/src/allo/allo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,23 @@ export interface Allo {
indexingStatus: Result<null>;
}
>;

directAllocation: (args: {
tokenAddress: Address;
poolId: string;
amount: bigint;
recipient: Address;
nonce: bigint;
requireTokenApproval?: boolean;
}) => AlloOperation<
Result<null>,
{
tokenApprovalStatus: Result<TransactionReceipt | null>;
transaction: Result<Hex>;
transactionStatus: Result<TransactionReceipt>;
indexingStatus: Result<null>;
}
>;
}

export { AlloOperation };
Expand Down
22 changes: 22 additions & 0 deletions packages/common/src/allo/backends/allo-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,28 @@ export class AlloV1 implements Allo {
return error(result);
});
}

directAllocation(args: {
tokenAddress: Address;
poolId: string;
amount: bigint;
recipient: Address;
nonce: bigint;
requireTokenApproval?: boolean;
}): AlloOperation<
Result<null>,
{
tokenApprovalStatus: Result<TransactionReceipt | null>;
transaction: Result<Hex>;
transactionStatus: Result<TransactionReceipt>;
indexingStatus: Result<null>;
}
> {
return new AlloOperation(async () => {
const result = new AlloError(`Unsupported on v1 ${args}`);
return error(result);
});
}
}
// todo: move this out?
export type CreateRoundArgs = {
Expand Down
127 changes: 127 additions & 0 deletions packages/common/src/allo/backends/allo-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AlloAbi,
Allo as AlloV2Contract,
CreateProfileArgs,
DirectAllocationStrategy,
DirectGrantsLiteStrategy,
DirectGrantsLiteStrategyTypes,
DonationVotingMerkleDistributionDirectTransferStrategyAbi,
Expand Down Expand Up @@ -82,6 +83,24 @@ export function getAlloAddress(chainId: number) {
return allo.address();
}

export function getDirectAllocationPoolId(chainId: number) {
switch (chainId) {
case 11155111:
return 386;
default:
return undefined;
}
}

export function getDirectAllocationStrategyAddress(chainId: number) {
switch (chainId) {
case 11155111:
return "0xd60BCfa8714949c478d88da51A7450703A32Cf35";
default:
return undefined;
}
}

export class AlloV2 implements Allo {
private transactionSender: TransactionSender;
private ipfsUploader: IpfsUploader;
Expand Down Expand Up @@ -1435,6 +1454,114 @@ export class AlloV2 implements Allo {
return success(null);
});
}

directAllocation(args: {
tokenAddress: Address;
poolId: string;
amount: bigint;
recipient: Address;
nonce: bigint;
requireTokenApproval?: boolean;
}): AlloOperation<
Result<null>,
{
tokenApprovalStatus: Result<TransactionReceipt | null>;
transaction: Result<Hex>;
transactionStatus: Result<TransactionReceipt>;
indexingStatus: Result<null>;
}
> {
return new AlloOperation(async ({ emit }) => {
if (isNaN(Number(args.poolId))) {
return error(new AlloError("Pool ID is not a valid Allo V2 pool ID"));
}

const poolId = BigInt(args.poolId);

const strategy = new DirectAllocationStrategy({
chain: this.chainId,
poolId: poolId,
});

const strategyAddress = getDirectAllocationStrategyAddress(this.chainId);

if (strategyAddress === undefined) {
return error(new AlloError("Direct allocation strategy not found"));
}

if (args.tokenAddress === zeroAddress || !args.requireTokenApproval) {
emit("tokenApprovalStatus", success(null));
} else {
const approvalTx = await sendTransaction(this.transactionSender, {
address: args.tokenAddress,
abi: Erc20ABI,
functionName: "approve",
args: [strategyAddress, args.amount],
});

if (approvalTx.type === "error") {
const result = new AlloError(
"Failed to approve token transfer",
approvalTx.error
);
emit("tokenApprovalStatus", error(result));
return error(result);
}
try {
const receipt = await this.transactionSender.wait(approvalTx.value);
emit("tokenApprovalStatus", success(receipt));
} catch (err) {
const result = new AlloError("Failed to approve token transfer", err);
emit("tokenApprovalStatus", error(result));
return error(result);
}
}

let _token = args.tokenAddress;
if (_token === zeroAddress) {
_token = getAddress(NATIVE);
}

const txData = strategy.getAllocateData({
profileOwner: args.recipient,
amount: BigInt(args.amount.toString()),
token: _token,
nonce: args.nonce,
});

const tx = await sendRawTransaction(this.transactionSender, {
to: txData.to,
data: txData.data,
value: BigInt(txData.value),
});

emit("transaction", tx);

if (tx.type === "error") {
return tx;
}

let receipt: TransactionReceipt;

try {
receipt = await this.transactionSender.wait(tx.value);
emit("transactionStatus", success(receipt));
} catch (err) {
const result = new AlloError("Failed to fund round", err);
emit("transactionStatus", error(result));
return error(result);
}

await this.waitUntilIndexerSynced({
chainId: this.chainId,
blockNumber: receipt.blockNumber,
});

emit("indexingStatus", success(null));

return success(null);
});
}
}

export function serializeProject(project: ProjectWithMerkleProof) {
Expand Down
7 changes: 7 additions & 0 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ export type InputType =
export type DeepRequired<T> = {
[K in keyof T]: Required<DeepRequired<T[K]>>;
};

export type Allocation = {
profileOwner: `0x${string}`;
amount: bigint;
token: `0x${string}`;
nonce: bigint;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface InfoModalProps {
}

export default function InfoModal({
title = "Information Title",
title = "",
titleSize = "sm",
isOpen = false,
setIsOpen = () => {
Expand Down
Loading
Loading