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

Update VotesERC20Wrapper #1638

Merged
merged 19 commits into from
May 5, 2024
Merged

Update VotesERC20Wrapper #1638

merged 19 commits into from
May 5, 2024

Conversation

adamgall
Copy link
Member

@adamgall adamgall commented May 5, 2024

Main thing that this PR does is:

  • Remove all imports of the VotesERC20Wrapper TypeChain imports from fractal-contracts in the codebase.
  • In favor using typed contract objects from viem using getContract().

Additionally, this PR starts to do some refactoring cleanup, removing some layers of abstraction:

  • Remove votesERC20WrapperMasterCopyContract "asSigner / asProvider" object from useSafeContracts.
  • Remove votesERC20WrapperMasterCopyContract from AzoriusContracts type and FractalContracts type.

There was some other light cleanup, which I'll document in some inline PR review notes.

Copy link

netlify bot commented May 5, 2024

Deploy Preview for fractal-dev ready!

Name Link
🔨 Latest commit 273235d
🔍 Latest deploy log https://app.netlify.com/sites/fractal-dev/deploys/66379fb009af190008a10776
😎 Deploy Preview https://deploy-preview-1638.app.dev.fractalframework.xyz
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -1135,4 +1135,6 @@ export default [
stateMutability: 'payable',
type: 'receive',
},
];
] as const;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding as const here is necessary for viem's typescript support.

https://viem.sh/docs/typescript#type-inference

This small change resulted in some type cleanup in the one place where this ABI was being used!

Comment on lines +35 to +41
signers.map(signer => getAddress(signer)),
1n, // Threshold
zeroAddress,
zeroHash,
fallbackHandler,
getAddress(fallbackHandler),
zeroAddress,
0,
0n,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the previous comment, these needed to be updated because due to type errors, after adding as const to the GnosisSafeL2 ABI! So nice

@@ -44,7 +44,7 @@ export function DelegateModal({ close }: { close: Function }) {
validAddress = getAddress(await signer.resolveName(values.address));
}
const votingTokenContract =
baseContracts.votesERC20WrapperMasterCopyContract.asSigner.attach(votesTokenContractAddress);
baseContracts.votesTokenMasterCopyContract.asSigner.attach(votesTokenContractAddress);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a funny little update, worth narrowing in on.

Basically, why were we previously using the votesERC20WrapperMasterCopyContract object/type here?

I don't think it matters which contract object we use, because we're doing an .attach (which forces a new object instance of the same type but at a new address), and then the only contract function being called from this new votingTokenContract object is a function that exists on both the VotesToken and the VotesERC20Wrapper ABIs.

So, I don't really think it mattered which existing "baseContract" object we started from (between the two in this changeset), but I do think it makes more intentional sense to use the one that I changed to here.

Comment on lines +93 to +149
const contractCallViem = useCallback(
(params: ContractCallParamsViem) => {
if (!publicClient) return;

let toastId: React.ReactText;
toastId = toast(params.pendingMessage, {
autoClose: false,
closeOnClick: false,
draggable: false,
closeButton: false,
progress: 1,
});
setPending(true);
params
.contractFn()
.then(txReceipt => {
return Promise.all([
publicClient.waitForTransactionReceipt({ hash: txReceipt }),
toastId,
]);
})
.then(([txReceipt, toastID]) => {
toast.dismiss(toastID);
if (txReceipt.status === 'reverted') {
toast.error(params.failedMessage);
if (params.failedCallback) params.failedCallback();
} else if (txReceipt.status === 'success') {
toast(params.successMessage);
if (params.successCallback) params.successCallback(txReceipt);
} else {
toast.error(t('errorTransactionUnknown'));
if (params.failedCallback) params.failedCallback();
}
if (params.completedCallback) params.completedCallback();

// Give the block event emitter a couple seconds to play the latest
// block on the app state, before informing app that the transaction
// is completed.
setTimeout(() => {
setPending(false);
}, 2000);
})
.catch((error: ProviderRpcError) => {
logError(error);
toast.dismiss(toastId);
setPending(false);

if (error.code === 4001) {
toast.error(t('errorUserDeniedTransaction'));
return;
}

toast.error(t('errorGeneral', { ns: 'common' }));
});
},
[t, publicClient],
);
Copy link
Member Author

@adamgall adamgall May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new function here for the generic contractCall, but supporting viem-style contract calls. Was too messy to try to combine both ethers- and viem-style calls into one function. Eventually, the other function will be removed after we get through all of the PRs that this one is kicking off.

The code here does exactly the same thing as the other function, just with some different object types (viem stuff instead of ethers stuff)

const { address: account } = useAccount();
const baseContracts = useSafeContracts();
const { loadERC20TokenAccountData } = useERC20LinearToken({ onMount: false });

const [contractCall, pending] = useTransaction();
const [, pending, contractCallViem] = useTransaction();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an instance where we're using the new contractCallViem function instead of the original one, because we have a new viem-style contract object.

@@ -32,7 +33,7 @@ export function WrapToken({ close }: { close: () => void }) {
const baseContracts = useSafeContracts();

const { loadERC20TokenAccountData } = useERC20LinearToken({ onMount: false });
const [contractCall, pending] = useTransaction();
const [, pending, contractCallViem] = useTransaction();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another place where the new function is used.

Copy link
Contributor

@Da-Colon Da-Colon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, LGTM, Code reviewed looks good to me, not Live QAed

@adamgall adamgall merged commit f58a7f1 into develop May 5, 2024
7 checks passed
@adamgall adamgall deleted the update-voteserc20wrapper branch May 5, 2024 16:13
@adamgall adamgall self-assigned this May 8, 2024
adamgall added a commit that referenced this pull request May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants