Skip to content
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

Dev #784

Merged
merged 2 commits into from
Dec 2, 2024
Merged

Dev #784

Show file tree
Hide file tree
Changes from all commits
Commits
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/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hats.finance/shared",
"version": "1.1.122",
"version": "1.1.124",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
5 changes: 2 additions & 3 deletions packages/shared/src/utils/payouts.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ export const createNewSplitPayoutBeneficiary = (): ISplitPayoutBeneficiary => {
};

export const getExecutePayoutSafeTransaction = async (
signer: Signer,
providerUrl: string,
committee: string,
payout: IPayoutResponse
): Promise<{ tx: SafeTransaction; txHash: string }> => {
const vaultInfo = payout.vaultInfo;

const protocolKit = await Safe.init({
provider: (signer.provider as any)?.provider as never,
provider: providerUrl,
safeAddress: committee,
signer: (await signer.getAddress()) as never,
});

const percentageToPay = Math.round(Number(payout.payoutData.percentageToPay) * 100);
Expand Down
8 changes: 6 additions & 2 deletions packages/web/src/contracts/write/ExecutePayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useState } from "react";
import { useTranslation } from "react-i18next";
import { IVault } from "types";
import { switchNetworkAndValidate } from "utils/switchNetwork.utils";
import { useNetwork, useSigner } from "wagmi";
import { useNetwork, useProvider, useSigner } from "wagmi";

export class ExecutePayoutContract {
/**
Expand All @@ -20,6 +20,7 @@ export class ExecutePayoutContract {
const { t } = useTranslation();
const { chain } = useNetwork();
const { data: signer } = useSigner();
const provider = useProvider();

const [data, setData] = useState<TransactionResult | undefined>();
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -49,8 +50,11 @@ export class ExecutePayoutContract {
console.log("Safe SDK done");

console.log("Getting safe TX");
const providerUrl = provider.chains?.find((c) => c.id === chain?.id)?.rpcUrls.default.http[0];
if (!providerUrl) return;

const { tx: safeTransaction, txHash: safeTransactionHash } = await getExecutePayoutSafeTransaction(
signer,
providerUrl,
vault.committee,
payout
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import SafeApiKit from "@safe-global/api-kit";
import Safe from "@safe-global/protocol-kit";
import { utils } from "ethers";
import { useState } from "react";
import { useAccount, useSigner } from "wagmi";
import { useAccount, useProvider, useSigner } from "wagmi";

export const useCreatePayoutProposal = (vault?: IVault, payout?: IPayoutResponse) => {
const { address: account } = useAccount();
const { data: signer } = useSigner();
const provider = useProvider();

const [isLoading, setIsLoading] = useState(false);

Expand Down Expand Up @@ -38,7 +39,10 @@ export const useCreatePayoutProposal = (vault?: IVault, payout?: IPayoutResponse
const txServiceUrl = getGnosisSafeTxServiceBaseUrl(vault.chainId);
const safeService = new SafeApiKit({ txServiceUrl: `${txServiceUrl}/api`, chainId: BigInt(vault.chainId) });

const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(signer, multisigAddress, payout);
const providerUrl = provider.chains?.find((c) => c.id === vault.chainId)?.rpcUrls.default.http[0];
if (!providerUrl) return;

const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(providerUrl, multisigAddress, payout);

const safeTxHash = await protocolKit.getTransactionHash(safeTransaction);
const senderSignature = await protocolKit.signTypedData(safeTransaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { IPayoutResponse, IVault, getExecutePayoutSafeTransaction } from "@hats.
import Safe from "@safe-global/protocol-kit";
import { useState } from "react";
import { switchNetworkAndValidate } from "utils/switchNetwork.utils";
import { useNetwork, useSignTypedData, useSigner } from "wagmi";
import { useNetwork, useProvider, useSignTypedData, useSigner } from "wagmi";

export const useSignPayout = (vault?: IVault, payout?: IPayoutResponse) => {
const { chain } = useNetwork();
const { data: signer } = useSigner();
const signPayout = useSignTypedData();
const provider = useProvider();

const [isLoading, setIsLoading] = useState(false);

Expand All @@ -24,7 +25,10 @@ export const useSignPayout = (vault?: IVault, payout?: IPayoutResponse) => {
signer: (await signer.getAddress()) as never,
});

const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(signer, vault.committee, payout);
const providerUrl = provider.chains?.find((c) => c.id === vault.chainId)?.rpcUrls.default.http[0];
if (!providerUrl) return;

const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(providerUrl, vault.committee, payout);

const signature = await protocolKit.signTypedData(safeTransaction);

Expand Down
Loading