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

Paymaster 구현 #6

Open
she110ff opened this issue Aug 7, 2023 · 1 comment
Open

Paymaster 구현 #6

she110ff opened this issue Aug 7, 2023 · 1 comment
Assignees

Comments

@she110ff
Copy link
Contributor

she110ff commented Aug 7, 2023

No description provided.

@she110ff she110ff self-assigned this Aug 7, 2023
@she110ff
Copy link
Contributor Author

she110ff commented Aug 14, 2023

사용 예

페이마스터는프로토콜 사용하는 다른 계정의 트랜잭션 위해 수수료를 대신 지불할 수 있는 계정입니다.
페이마스터의 또 다른 중요한 사용 사례는 ERC20 토큰으로 수수료를 간편하게 결제하는 것입니다.

  • ERC721gated
  • PayERC20ForFee
  • AllowList
  • FreeFee

페이마스터

  1. paymasterInput에서 token, amount(수수료 지급량) 디코딩
  2. 토큰 allowance 가 확인
  3. paymaster 에 토큰(amount)을 전송(transferFrom)
  4. 트랜잭션 기반 requiredETH 계산 (_transaction.gasLimit * _transaction.maxFeePerGas)
  5. requiredETH 를 BOOTLOADER_FORMAL_ADDRESS에 전달

배포

  1. 지갑을 준비
  2. ERC20 배포
  3. 지갑에 토큰 전송
  4. 페이마스터 배포
  5. 페이마스터에 ETH 전송

사용

  1. 호출할 컨트랙트.estimateGas.func 에 customData를 추가 인자로 전달하여 gasLimit 계산 : paymasterParams의 amount 임의값
  2. ApprovalBased 타입의 paymasterParams 생성(utils.getPaymasterParams) : gasLimit, gasPrice 등을 통한 fee가 amount에 포함
  3. customData 를 포함한 컨트랙트 함수 실행

*** 고정된 수수료 토큰량이 있다면 1, 2번은 한번에 가능

기타

  • 사용자가 페이마스터와 상호 작용하려면 EIP712 트랜잭션에 0이 아닌 페이마스터 주소를 제공해야 한다.
  • 사용 측면에서는 zkSync 트랜잭션에는 paymaster 정보를 추가하는 것으로 간단하게 구현할 수 있다.
  • EIP 4337 : Alternative Mempools, Bundling 을 골자로 하는 AA 제안

ETH/토큰 비율에 따른 수수료 계산

// Gas estimation:
const fee = gasPrice.mul(gasLimit.toString());

// Calling the dAPI to get the ETH price:
const ETHUSD = await PaymasterContract.readDapi("0x28ce555ee7a3daCdC305951974FcbA59F5BdF09b");
const USDCUSD = await PaymasterContract.readDapi("0x946E3232Cc18E812895A8e83CaE3d0caA241C2AB");

// Calculating the fee:
const usdFee = fee.mul(ETHUSD).div(USDCUSD);

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

No branches or pull requests

1 participant