Skip to content

Commit

Permalink
Merge pull request #15 from gentlementlegen/fix/naming-convention
Browse files Browse the repository at this point in the history
fix!: naming convention
  • Loading branch information
gitcoindev authored Apr 18, 2024
2 parents e7ca0eb + a94aad8 commit e2633b3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
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

0 comments on commit e2633b3

Please sign in to comment.