ERC20 Deposit/Withdraw

Neon Protocol's Vault smart contract can transfer any ERC20 token in and out.

Neon Protocol utilizes a Vault smart contract with the following functionality.

Deposit

The depositToken function allows msg.sender to:

  • Transfer an amount > 0 to Vault Smart Contract

  • Give allowance to the Vault to transfer the set amount of tokens on behalf of the msg.sender

  • update userBalanceMap with the amount, under the userBalanceMap[msg.sender].deposited storage.

  • update userERC20s mapping with new token address for first time deposits.

  • onDeposit event is emitted with the token, amount and msg.sender upon a successful deposit.

User will now have deposited tokens into the Neon Protocol Vault.

The user can go on to write or buy or take hedges and loans.

Withdraw

msg.sender has to have withdrawable balance > amount requested in withdrawToken function.

The withdrawToken function allows msg.sender:

  • Check token balance available for withdrawal using the getWithdrawableBalance function. Withdrawable balance is drived as: userBalanceMap[msg.sender].deposited - userBalanceMap[msg.sender].withdrawn - userBalanceMap[msg.sender].lockedInUse

  • Transfer an amount < withdrawable balance from Vault Smart Contract.

  • Pay cashier fees before withdrawal, debited from userBalanceMap[msg.sender].deposited and credited to the Vault balance.

  • update userBalanceMap[msg.sender].withdrawn with the amount.

  • onWithdraw event is emitted, with the token, amount and msg.sender upon a successful withdrawal.

User will now have succesfully withdrawn tokens from the Neon Protocol Vault.

Logo

Xeon Protocol © 2024