Escrow & Trade Contract
Escrow Vault()
This returns the EscrowVaultEntry
data of the escrowCount
ID passed in as a parameter. The return value stores the details of escrow vault entries.
Buy Lock Vaults: This returns the amount intended by a merchant to buy in a token address. This value gets updated as the merchant keeps buying.
Sell Lock Vaults: This returns the amount available for a merchant to sell in a token address. This value gets updated as the merchant keeps selling.
EscrowVaultEntry
This is used to store the details of an escrow vault entry, representing a trade between a user and a merchant.
user
: The address of the user initiating the trade.merchant
: The address of the merchant involved in the trade.completed
: A boolean indicating whether the trade is completed or not.tokenAddress
: The address of the token being traded.outcome
: A boolean indicating the outcome of the trade (true for successful, false for unsuccessful).isbuy
: A boolean indicating whether the trade is a buy trade (true) or a sell trade (false).amount
: The amount of tokens involved in the trade.
Escrow Count()
This method returns the id count of all the buys and sells in the contract that have been created in the smart contract. The current value shows the latest id that was created.
Sell Escrow Lock
This function is used to lock tokens from a merchant's balance for selling. It requires a signature from the merchant and is executed by the executor. Upon execution, it updates the value of sellLockVaults(tokenAddress, verifiedRequest.to). It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the merchant for the verified request.tokenAddress
: The address of the token to be escrowed.amount
: The amount of tokens to be locked.feeAmount
: The fee amount calculated off-chain is to be deducted from the amount as a fee.
emits LockVaultEntryUpdate
event.
Sell Escrow Lock Native
This function is used to lock native assets (ETH) from a merchant's balance for selling. It requires a verified request and signature from the verifiedSigner for the merchant. Upon execution, it updates the value of sellLockVaults(zero address, verifiedRequest.to). It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the verifiedSigner to the merchant for the verified request.feeAmount
: The fee amount calculated off-chain is to be deducted from the amount as a fee.amount
: The amount of native asset value to be locked. (payable).
emits LockVaultEntryUpdate
event.
Sell Escrow Cancel
This function is used to cancel asellEscrowLock and release the locked tokens back to the merchant's balance. It requires a signature by the merchant, and it can only be executed by the executor. Upon execution, it updates the value of sellLockVaults(tokenAddress, verifiedRequest.to). It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the merchant for the verified request.merchant
: address of merchant to cancel fortokenAddress
: The address of the token for which the sell lock will be canceled.amount
: The amount to cancel.
emits LockVaultEntryUpdate
event.
Buy Escrow Lock
This function is used to indicate the amount of tokens that a buyer wishes to buy. It locks the fee amount from a merchant's balance for buying. It requires a signature by the merchant and is executed by an executor. It updates the values of merchantToTokenFees(verifiedRequest.to, tokenAddress) and buyLockVaults(tokenAddress, verifiedRequest.to). It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the merchant for the verified request.tokenAddress
: The address of the token for which the sell lock will be canceled.amount
: The amount of tokens to be bought by the merchant.feeAmount
: The fee amount calculated off-chain is to be deducted from the amount as a fee.
emits LockVaultEntryUpdate
event.
Buy Escrow Lock Native
This function is used to indicate the amount of native assets that a buyer wishes to buy. It locks the fee amount from a merchant's balance for buying. It requires a verified request and signature from the merchant. It updates the values of merchantToTokenFees(verifiedRequest.to, tokenAddress) and buyLockVaults(tokenAddress, verifiedRequest.to). It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the merchant for the verified request.amount
: The amount of tokens to be bought by the merchant.feeAmount
: The fee amount calculated off-chain is to be deducted from the amount as a fee.(payable)
emits LockVaultEntryUpdate
event.
Buy Escrow Cancel
This function is used to cancel a buyEscrowLock and release the locked fees back to the merchant's balance. It requires a signature by the merchant, and it can only be executed by the executor. Upon execution, it updates the values of merchantToTokenFees(verifiedRequest.to, tokenAddress) and buyLockVaults(tokenAddress, verifiedRequest.to). It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the merchant for the verified request.merchant
: address of merchant to cancel fortokenAddress
: The address of the token for which the buy lock will be canceled.amount
: The amount to cancel.
emits LockVaultEntryUpdate
event.
Buy Escrow Approve
This method is used by the executor to approve buy trades if the Fiat was received by the merchant or not. If received, then verifiedRequest.to must be the user's address and a signature must be generated for the user whether the function is being called by the executor.
On the other hand, if FIAT was not sent, if the signature used would be from the merchant, then verifiedRequest.to must be the user's address. Since the executor triggers the action with either of the signatures, the system maintains its 2/3 quorum.
This call potentially updates claimableFees(token)
, merchantToTokenFees(merchant, tokenAddress)
**, and **sellLockVaults(tokenAddress, merchant)
**. It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the user for the verified request.id
: The escrowCount id of the trade.tokenAddress
: The address of the token for which the buy is intended.merchant
: The wallet address of the merchant who created the ad.user
: The wallet address of the traderamount
: The amount of tokens to be bought by the user.fee
: The fee amount to cover for gas.
emits EscrowVaultEntryUpdate
event.
Sell
This function is triggered by the executor. used to indicate interest by a user in the buy ad of the merchant. It locks the amount that the user wants to sell, awaiting fiat payment by the buyer. It updates the values of buyLockVaults(tokenAddress, merchant). It increments the escrowCount and updates the EscrowVaultEntry data of this id. It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the verified signer for the verified request.tokenAddress
: The address of the token for which the buy is intended.merchant
: The wallet address of the merchant who created the ad.amount
: The amount of tokens to be sold by the user.id
: unique id from the backendfee
: The fee amount to cover for approval/disapproval gas.
emits LockVaultEntryUpdate
and EscrowVaultEntryUpdate
events.
Sell Native
This function is used to indicate interest by a user in the buy ad of the merchant involving a native asset (eg ETH on Ethereum Network). It locks the amount that the user wants to sell, awaiting fiat payment by the buyer. It updates the values of buyLockVaults(tokenAddress, merchant). It increments the escrowCount and updates the EscrowVaultEntry data of this id. It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the user for the verified request.merchant
: The wallet address of the merchant who created the ad.amount
: The amount of tokens to be sold by the user. (payable).id
: unique id from the backendfee
: The fee amount to cover for approval/disapproval gas.
emits LockVaultEntryUpdate
and EscrowVaultEntryUpdate
events.
Sell Escrow Approve/Disapprove
This method is used by the executor to approve or disapprove sell trades if the Fiat was received by the user or not respectively. If received, then verifiedRequest.to must be the merchant's address and signature must be generated for the merchant whether the function is being called by the user or owner.
On the other hand, if FIAT was not sent, if the execution would be done by the user, then verifiedRequest.to must be the owner's address and a signature must be generated for the owner, else if a disapproval should be executed by the admin, it means that verifiedRequest.to must be the user's address and signature must be generated for the user. This is how the system maintains its 2/3 quorum.
This call potentially updates claimableFees(token)
, merchantToTokenFees(merchant, tokenAddress)
**, and **buyLockVaults(tokenAddress, merchant)
**. It takes the following parameters:
verifiedRequest
: A struct containing the verified request information.signature
: The signature provided by the user for the verified request.id
: The escrowCount id of the trade.approve
: true if approved, and false if disapproved.merchant
: the address of the merchant to deal with if the current merchant fails to comply. If this value is equal to the zero address, it will just close the trade without re-matching
emits EscrowVaultEntryUpdate
event.
Last updated