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

fix!: naming convention #15

Merged
Merged
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
6 changes: 3 additions & 3 deletions src/handlers/encode-decode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Permit, TokenType } from "../types";
import { PermitReward, TokenType } from "../types";
import { RewardPermit } from "./permit-type";

/**
* Returns a base64 encoded string containing all the permit data
*/
export function encodePermits(permits: Permit[]) {
export function encodePermits(permits: PermitReward[]) {
const permitsDto = permits
.map((permit) => {
if (permit.tokenType === TokenType.ERC20) {
Expand Down Expand Up @@ -66,7 +66,7 @@ export function encodePermits(permits: Permit[]) {
export function decodePermits(base64: string) {
const decoded = atob(base64);
const objs: Array<RewardPermit> = JSON.parse(decoded);
const result: Permit[] = [];
const result: PermitReward[] = [];
for (const obj of objs) {
const tokenType = obj.type === "erc20-permit" ? TokenType.ERC20 : TokenType.ERC721;
if (tokenType === TokenType.ERC721) {
Expand Down
10 changes: 5 additions & 5 deletions src/handlers/generate-erc20-permit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PERMIT2_ADDRESS, PermitTransferFrom, SignatureTransfer } from "@uniswap/permit2-sdk";
import { ethers, keccak256, MaxInt256, parseUnits, toUtf8Bytes } from "ethers";
import { Context, Logger } from "../types/context";
import { Permit, TokenType } from "../types";
import { PermitReward, TokenType } from "../types";
import { decryptKeys } from "../utils/keys";
import { getPayoutConfigByNetworkId } from "../utils/payoutConfigByNetworkId";

Expand All @@ -14,9 +14,9 @@ export interface Payload {
userId: number;
}

export async function generateErc20PermitSignature(payload: Payload, username: string, amount: number): Promise<Permit>;
export async function generateErc20PermitSignature(context: Context, username: string, amount: number): Promise<Permit>;
export async function generateErc20PermitSignature(contextOrPayload: Context | Payload, username: string, amount: number): Promise<Permit> {
export async function generateErc20PermitSignature(payload: Payload, username: string, amount: number): Promise<PermitReward>;
export async function generateErc20PermitSignature(context: Context, username: string, amount: number): Promise<PermitReward>;
export async function generateErc20PermitSignature(contextOrPayload: Context | Payload, username: string, amount: number): Promise<PermitReward> {
let _logger: Logger;
const _username = username;
let _walletAddress: string | null | undefined;
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function generateErc20PermitSignature(contextOrPayload: Context | P
throw new Error(errorMessage);
});

const erc20Permit: Permit = {
const erc20Permit: PermitReward = {
tokenType: TokenType.ERC20,
tokenAddress: permitTransferFromData.permitted.token,
beneficiary: permitTransferFromData.spender,
Expand Down
10 changes: 5 additions & 5 deletions src/handlers/generate-erc721-permit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaxUint256 } from "@uniswap/permit2-sdk";
import { ethers, keccak256, toUtf8Bytes } from "ethers";
import { Context, Logger } from "../types/context";
import { Permit, TokenType } from "../types";
import { PermitReward, TokenType } from "../types";
import { isIssueEvent } from "../types/typeguards";
import { getPayoutConfigByNetworkId } from "../utils/payoutConfigByNetworkId";

Expand Down Expand Up @@ -38,13 +38,13 @@ export interface PermitPayload {
userId: number;
}

export async function generateErc721PermitSignature(permitPayload: PermitPayload, username: string, contributionType: string): Promise<Permit>;
export async function generateErc721PermitSignature(context: Context, username: string, contributionType: string): Promise<Permit>;
export async function generateErc721PermitSignature(permitPayload: PermitPayload, username: string, contributionType: string): Promise<PermitReward>;
export async function generateErc721PermitSignature(context: Context, username: string, contributionType: string): Promise<PermitReward>;
export async function generateErc721PermitSignature(
contextOrPermitPayload: Context | PermitPayload,
username: string,
contributionType: string
): Promise<Permit> {
): Promise<PermitReward> {
let _logger: Logger;
let _nftContractAddress: string;
let _evmNetworkId: number;
Expand Down Expand Up @@ -153,7 +153,7 @@ export async function generateErc721PermitSignature(
throw new Error(`Failed to sign typed data: ${error}`);
});

const erc721Permit: Permit = {
const erc721Permit: PermitReward = {
tokenType: TokenType.ERC721,
tokenAddress: _nftContractAddress,
beneficiary: _walletAddress,
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/generate-payout-permit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Permit } from "../types";
import { PermitReward } from "../types";
import { Context } from "../types/context";
import { generateErc20PermitSignature } from "./generate-erc20-permit";
import { generateErc721PermitSignature } from "./generate-erc721-permit";
Expand All @@ -10,13 +10,13 @@ import { PermitRequest } from "../types/plugin-input";
* @param permitRequests
* @returns A Promise that resolves to the generated permit transaction data or an error message.
*/
export async function generatePayoutPermit(context: Context, permitRequests: PermitRequest[]): Promise<Permit[]> {
const permits: Permit[] = [];
export async function generatePayoutPermit(context: Context, permitRequests: PermitRequest[]): Promise<PermitReward[]> {
const permits: PermitReward[] = [];

for (const permitRequest of permitRequests) {
const { type, amount, username, contributionType } = permitRequest;

let permit: Permit;
let permit: PermitReward;
switch (type) {
case "ERC20":
permit = await generateErc20PermitSignature(context, username, amount);
Expand Down
6 changes: 3 additions & 3 deletions src/types/permits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ interface CommonFields {
networkId: number;
}

interface ERC20Permit extends CommonFields {
interface Erc20PermitReward extends CommonFields {
tokenType: TokenType.ERC20;
amount: BigNumberish;
erc721Request?: never;
}

interface ERC721Permit extends CommonFields {
interface Erc721PermitReward extends CommonFields {
tokenType: TokenType.ERC721;
amount: "0" | "1";
erc721Request?: {
Expand All @@ -38,4 +38,4 @@ interface ERC721Permit extends CommonFields {
};
}

export type Permit = ERC20Permit | ERC721Permit;
export type PermitReward = Erc20PermitReward | Erc721PermitReward;
6 changes: 3 additions & 3 deletions tests/encode-decode.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, expect, it } from "@jest/globals";
import { decodePermits, encodePermits } from "../src/handlers/encode-decode";
import { Permit, TokenType } from "../src/types";
import { PermitReward, TokenType } from "../src/types";

describe("Encoding / Decoding tests", () => {
it("Should properly encode and decode a list of permits", () => {
const permitErc20: Permit = {
const permitErc20: PermitReward = {
beneficiary: "ubiquity",
deadline: "1",
networkId: 100,
Expand All @@ -15,7 +15,7 @@ describe("Encoding / Decoding tests", () => {
tokenType: TokenType.ERC20,
amount: 100,
};
const permitErc721: Permit = {
const permitErc721: PermitReward = {
beneficiary: "ubiquity2",
deadline: "2",
networkId: 101,
Expand Down
Loading