Skip to content

Instantly share code, notes, and snippets.

@youfoundron
Created August 10, 2021 19:35
Show Gist options
  • Save youfoundron/705faaad0a9497a530b29f2037075148 to your computer and use it in GitHub Desktop.
Save youfoundron/705faaad0a9497a530b29f2037075148 to your computer and use it in GitHub Desktop.
Wrapped Balance Logic

Contrived assumptions:

  • USD value of 1 Ether = USD value of 1 Zcash
  • Wrapped Service Fee is a fixed 10%
  • Contract execution cost (gas) is 0.1 ETH
  • Zcash transaction execution cost is free

Wrapping Flow

  1. Starting state, Wrapped.com has put 1 ETH in the vault to pay for gas
Token Vault Balance User Balance
Zcash 0 0
Wrapped Zcash 0 0
Ether (for gas) 1 N/A
  1. User deposits 1 ZEC in order to create a wrap order for 1 WZEC
Token Vault Balance User Balance
Zcash 1 1
Wrapped Zcash 0 0
Ether (for gas) 1 N/A
  1. User executes the wrap order on their entire ZEC balance (1 ZEC)
  • service fee of 10% is deducted as 0.1 ZEC
  • execution fee of 0.1 ETH, priced as (0.1 ZEC) is deducted
  • WZEC tokens are minted
Token Vault Balance User Balance
Zcash 1 0
Wrapped Zcash 0.8 0.8
Ether (for gas) 0.9 N/A
  1. User withdraws their wrapped tokens, incurring an execution fee of 0.1 ETH (Wrapped.com simply pays for this)
Token Vault Balance User Balance
Zcash 1 0
Wrapped Zcash 0 0
Ether (for gas) 0.8 N/A

Unwrapping Flow

  1. Starting state, assumed to occur after the events of the above wrapping flow
Token Vault Balance User Balance
Zcash 1 0
Wrapped Zcash 0 0
Ether (for gas) 0.8 N/A
  1. User deposits 0.8 WZEC in order to unwrap into ZEC
Token Vault Balance User Balance
Zcash 1 0
Wrapped Zcash 0.8 0.8
Ether (for gas) 0.8 N/A
  1. User executes the unwrap order on their entire WZEC balance (0.8 WZEC)
  • service fee of 10% is deducted as 0.08 ZEC
  • execution fee of 0.1 ETH, priced as (0.1 ZEC) is deducted
  • wrapped tokens are burned
Token Vault Balance User Balance
Zcash 1 0.62
Wrapped Zcash 0 0
Ether (for gas) 0.7 N/A
  1. User withdraws their underlying tokens (0.62 ZEC)
Token Vault Balance User Balance
Zcash 0.38 0
Wrapped Zcash 0 0
Ether (for gas) 0.7 N/A

Limitations

  • We are required to maintain a higher balance of underlying tokens in the vault at all times
  • If we have a customer who is only unwrapping and they have their own vault... where do the underlying tokens to pay for fee's come from?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment