Skip to content

Commit

Permalink
fix: pass permit into permit2 and align 721 permit with anvil depl
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Feb 25, 2024
1 parent a4d0750 commit b5d1793
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
8 changes: 4 additions & 4 deletions scripts/typescript/generate-erc721-permit-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export async function generateERC721Permit() {
token: network == "localhost" ? NFT_REWARDS_ANVIL_DEPLOYMENT : NFT_ADDRESS,
amount: 1,
},
spender: network == "localhost" ? NFT_REWARDS_ANVIL_DEPLOYMENT : NFT_ADDRESS,
nonce: 3133748,
spender: network == "localhost" ? ANVIL_ACC_1_ADDRESS : myWallet.address,
nonce: 313327,
deadline: MaxUint256,
};

Expand Down Expand Up @@ -65,7 +65,7 @@ export async function generateERC721Permit() {
beneficiary: network == "localhost" ? ANVIL_ACC_1_ADDRESS : myWallet.address,
deadline: MaxUint256,
keys: valueBytes,
nonce: 3133748,
nonce: 313327,
values: [GITHUB_ORGANIZATION_NAME, GITHUB_REPOSITORY_NAME, GITHUB_ISSUE_ID, GITHUB_USERNAME, GITHUB_CONTRIBUTION_TYPE],
};

Expand Down Expand Up @@ -97,7 +97,7 @@ export async function generateERC721Permit() {
GITHUB_CONTRIBUTION_TYPE,
},
request: {
beneficiary: ANVIL_ACC_1_ADDRESS,
beneficiary: network == "localhost" ? ANVIL_ACC_1_ADDRESS : myWallet.address,
deadline: erc721TransferFromData.deadline.toString(),
keys: valueBytes,
nonce: erc721TransferFromData.nonce.toString(),
Expand Down
7 changes: 6 additions & 1 deletion static/scripts/rewards/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum NetworkIds {
Mainnet = 1,
Goerli = 5,
Gnosis = 100,
Anvil = 31337,
}

export enum Tokens {
Expand All @@ -19,12 +20,14 @@ export const networkNames = {
[NetworkIds.Mainnet]: "Ethereum Mainnet",
[NetworkIds.Goerli]: "Goerli Testnet",
[NetworkIds.Gnosis]: "Gnosis Chain",
[NetworkIds.Anvil]: "Anvil Development",
};

export const networkCurrencies: Record<number, object> = {
[NetworkIds.Mainnet]: { symbol: "ETH", decimals: 18 },
[NetworkIds.Goerli]: { symbol: "GoerliETH", decimals: 18 },
[NetworkIds.Gnosis]: { symbol: "XDAI", decimals: 18 },
[NetworkIds.Anvil]: { symbol: "XDAI", decimals: 18 },
};

export function getNetworkName(networkId?: number) {
Expand All @@ -39,13 +42,15 @@ export const networkExplorers: Record<number, string> = {
[NetworkIds.Mainnet]: "https://etherscan.io",
[NetworkIds.Goerli]: "https://goerli.etherscan.io",
[NetworkIds.Gnosis]: "https://gnosisscan.io",
[NetworkIds.Anvil]: "https://gnosisscan.io",
};

export const networkRpcs: Record<number, string[]> = {
[NetworkIds.Mainnet]: ["https://rpc-pay.ubq.fi/v1/mainnet", ...(extraRpcs[NetworkIds.Mainnet] || [])],
[NetworkIds.Goerli]: ["https://rpc-pay.ubq.fi/v1/goerli", ...(extraRpcs[NetworkIds.Goerli] || [])],
[NetworkIds.Gnosis]: [...(extraRpcs[NetworkIds.Gnosis] || [])],
[NetworkIds.Anvil]: ["http://localhost:8545"],
};

export const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
export const nftAddress = "0xAa1bfC0e51969415d64d6dE74f27CDa0587e645b";
export const nftAddress = "0xAa1bfC0e51969415d64d6dE74f27CDa0587e645b";
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function renderToFields(receiverAddress: string, explorerUrl: string) {
const toShort = document.querySelector("#rewardRecipient .short") as Element;

// after a single claim toFull returns null as creates a toaster error
if(!toFull || !toShort) return console.error("Could not find toFull or toShort");
if (!toFull || !toShort) return;

toFull.innerHTML = `<div>${receiverAddress}</div>`;
toShort.innerHTML = `<div>${shortenAddress(receiverAddress)}</div>`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Type } from "@sinclair/typebox";
import { Value } from "@sinclair/typebox/value";
import { AppState, app } from "../app-state";
import { useFastestRpc } from "../rpc-optimization/get-optimal-provider";
Expand Down Expand Up @@ -34,11 +33,22 @@ export async function readClaimDataFromUrl(app: AppState) {
}

function decodeClaimData(base64encodedTxData: string) {
let permit;

try {
permit = JSON.parse(atob(base64encodedTxData));
} catch (error) {
console.error(error);
setClaimMessage({ type: "Error", message: `1. Invalid claim data passed in URL` });
table.setAttribute(`data-claim`, "error");
throw error;
}

try {
return Value.Decode(Type.Array(claimTxT), JSON.parse(atob(base64encodedTxData)));
return [Value.Decode(claimTxT, permit[0])];
} catch (error) {
console.error(error);
setClaimMessage({ type: "Error", message: `Invalid claim data passed in URL` });
setClaimMessage({ type: "Error", message: `2. Invalid claim data passed in URL` });
table.setAttribute(`data-claim`, "error");
throw error;
}
Expand Down
9 changes: 4 additions & 5 deletions static/scripts/rewards/render-transaction/tx-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ const erc20PermitT = T.Object({

export type Erc20Permit = StaticDecode<typeof erc20PermitT>;

const erc721Permit = T.Object({
const erc721PermitT = T.Object({
type: T.Literal("erc721-permit"),
permit: T.Object({
permitted: T.Object({
token: addressT,
// explicitly state tokenId or keep as "amount" but pass in the tokenId anyway? I'm passing amount in test case
amount: bigNumberT,
amount: bigNumberT,
}),
nonce: bigNumberT,
deadline: bigNumberT,
Expand Down Expand Up @@ -74,8 +73,8 @@ const erc721Permit = T.Object({
}),
});

export type Erc721Permit = StaticDecode<typeof erc721Permit>;
export type Erc721Permit = StaticDecode<typeof erc721PermitT>;

export const claimTxT = T.Union([erc20PermitT, erc721Permit]);
export const claimTxT = T.Union([erc20PermitT, erc721PermitT]);

export type RewardPermit = StaticDecode<typeof claimTxT>;
2 changes: 1 addition & 1 deletion static/scripts/rewards/web3/erc20-permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function createEthersContract(signer: JsonRpcSigner) {
async function transferFromPermit(permit2Contract: Contract, app: AppState) {
const permit = app.permit;
try {
const tx = await permit2Contract.permitTransferFrom(permit, permit.transferDetails, permit.owner, permit.signature);
const tx = await permit2Contract.permitTransferFrom(permit.permit, permit.transferDetails, permit.owner, permit.signature);
toaster.create("info", `Transaction sent`);
return tx;
} catch (error: unknown) {
Expand Down

0 comments on commit b5d1793

Please sign in to comment.