ubiquibot / permit-generation

A standalone module to generate permits.
0 stars 6 forks source link

Permit data structure, encode / decode #8

Closed gentlementlegen closed 2 months ago

gentlementlegen commented 3 months ago

The website pay.ubq.fi currently decodes permits passed through an encoded base64 URL, in the form of an array of ECR20 / ECR721 permits, with the following structure https://github.com/ubiquity/pay.ubq.fi/blob/d193e6dbde2ef3fcd001c6940d50cd0d8b7d722d/scripts/typescript/generate-erc20-permit-url.ts#L37 https://github.com/ubiquity/pay.ubq.fi/blob/4a5d60b4c76855bfb9a800bfdbf0f2adb9955c8c/scripts/typescript/generate-erc721-permit-url.ts#L81

// ECR20
{
    type: "erc20-permit",
    permit: {
      permitted: {
        token: string,
        amount: string,
      },
      nonce: string,
      deadline: string,
    },
    transferDetails: {
      to: string,
      requestedAmount: string,
    },
    owner:  string,
    signature: string,
    networkId: number,
  };

// ECR721
{
    type: "erc721-permit",
    permit: {
      permitted: {
        token: string,
        amount: string,
      },
      nonce: string,
      deadline: string,
    },
    transferDetails: {
      to: string,
      requestedAmount: string,
    },
    owner: string,
    signature: string,
    networkId: number,
    nftMetadata: {
      GITHUB_ORGANIZATION_NAME,
      GITHUB_REPOSITORY_NAME,
      GITHUB_ISSUE_ID,
      GITHUB_USERNAME,
      GITHUB_CONTRIBUTION_TYPE,
    },
    request: {
      beneficiary: string,
      deadline: string,
      keys: [],
      nonce: string,
      values: [GITHUB_ORGANIZATION_NAME, GITHUB_REPOSITORY_NAME, GITHUB_ISSUE_ID, GITHUB_USERNAME, GITHUB_CONTRIBUTION_TYPE],
    },
  };

This repo provides a new structure for the data, as such: https://github.com/ubiquibot/permit-generation/blob/294cefc17b5dcd9aeb117e8b56d2c2820bce1133/src/types/permits.ts#L3

export interface Permit {
  tokenType: TokenType;
  tokenAddress: string;
  beneficiary: string;
  amount: string;
  nonce: string;
  deadline: string;
  owner: string;
  signature: string;
  networkId: number;
  erc721Request?: {
    keys: string[];
    values: string[];
    metadata: {
      GITHUB_ORGANIZATION_NAME: string;
      GITHUB_REPOSITORY_NAME: string;
      GITHUB_ISSUE_ID: string;
      GITHUB_USERNAME: string;
      GITHUB_CONTRIBUTION_TYPE: string;
    };
  };
}

The problem is that now pay.ubq.fi is not capable to read the generated permits properly. I believe that having this library handling encode / decode would provide a unique source of truth avoiding this situation. There would be two possible approaches:

Downside of the second option is that it would make all permits previously issued impossible to claim.

gentlementlegen commented 3 months ago

@pavlovcik for vis @whilefoo If you have any thoughts about this, would be helpful!

0x4007 commented 3 months ago

ERC is "Ethereum Request for Comment" so that you remember the acronym.

Downside of the second option is that it would make all permits previously issued impossible to claim.

Not a problem. Besides, worst case scenario we can pass along a URL to an old commit for pay.ubq.fi and its fine.

change pay.ubq.fi to read the new object data shape

This makes the most sense to me.


Reviewing the Permit interface now, here are some remarks:

enum TokenType {
    ERC20 = "ERC20",
    ERC721 = "ERC721",
}

export interface Permit {
    tokenType: TokenType.ERC20 | TokenType.ERC721;
    tokenAddress: string;
    beneficiary: string;
    amount: string;
    nonce: string;
    deadline: string;
    owner: string;
    signature: string;
    networkId: number;
    nft?: Record<string, string>;
}

Why don't we simplify the last property? Is it possible to generate an arbitrary NFT by passing in any key/value pair?

whilefoo commented 3 months ago

I simplified the permit structure so that it matches both erc20 and erc721 as much as possible so that we don't need union type but just one type. The last property contains keys and values which are hashed and are important for minting, but metadata is just for displaying on pay.ubq.fi

Is it possible to generate an arbitrary NFT by passing in any key/value pair?

No it's just for our NFTs

ubiquibot[bot] commented 2 months ago
! No price label has been set. Skipping permit generation.