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
userBalanceMapwith the amount, under theuserBalanceMap[msg.sender].depositedstorage.update
userERC20smapping with new token address for first time deposits.onDepositevent 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
getWithdrawableBalancefunction. Withdrawable balance is drived as:userBalanceMap[msg.sender].deposited - userBalanceMap[msg.sender].withdrawn - userBalanceMap[msg.sender].lockedInUseTransferan amount < withdrawable balance from Vault Smart Contract.Pay cashier fees before withdrawal, debited from
userBalanceMap[msg.sender].depositedand credited to the Vault balance.update
userBalanceMap[msg.sender].withdrawnwith the amount.onWithdrawevent 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.
Last updated
Was this helpful?