Skip to content

Commit

Permalink
Merge pull request #784 from hats-finance/develop
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
shayzluf authored Dec 2, 2024
2 parents ecad00a + ea42172 commit 0fd34e5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
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

0 comments on commit 0fd34e5

Please sign in to comment.