myria-core-sdk
Version:
Latest version SDK
751 lines • 622 kB
JSON
{
"contractName": "Withdrawals",
"networks": {
"1": {
"links": {},
"address": "0x3071BE11F9e92A9eb28F305e1Fa033cD102714e7"
},
"5": {
"links": {},
"address": "0xF82C423a30E317f34f9b0997627F2F9c5d239Ad9"
},
"11155111": {
"links": {},
"address": "0xe99aFF31AD367Dcc45c60b237a2Ef096507d6095"
}
},
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "ownerKey",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "assetType",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "nonQuantizedAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "quantizedAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "assetId",
"type": "uint256"
}
],
"name": "LogMintWithdrawalPerformed",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "ownerKey",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "assetType",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "assetId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "recipient",
"type": "address"
}
],
"name": "LogNftWithdrawalPerformed",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "ownerKey",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "assetType",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "nonQuantizedAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "quantizedAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "recipient",
"type": "address"
}
],
"name": "LogWithdrawalPerformed",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "assetType",
"type": "uint256"
}
],
"name": "getAssetInfo",
"outputs": [
{
"internalType": "bytes",
"name": "assetInfo",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "ownerKey",
"type": "uint256"
}
],
"name": "getEthKey",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "presumedAssetType",
"type": "uint256"
}
],
"name": "getQuantum",
"outputs": [
{
"internalType": "uint256",
"name": "quantum",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "isFrozen",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "ownerKey",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "assetId",
"type": "uint256"
}
],
"name": "getWithdrawalBalance",
"outputs": [
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "ownerKey",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "assetType",
"type": "uint256"
}
],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "ownerKey",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "assetType",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "withdrawNft",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "ownerKey",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "assetType",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "mintingBlob",
"type": "bytes"
}
],
"name": "withdrawAndMint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"metadata": "{\"compiler\":{\"version\":\"0.6.11+commit.5ef660b1\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"ownerKey\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"assetType\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"nonQuantizedAmount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"quantizedAmount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"assetId\",\"type\":\"uint256\"}],\"name\":\"LogMintWithdrawalPerformed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"ownerKey\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"assetType\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"assetId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"}],\"name\":\"LogNftWithdrawalPerformed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"ownerKey\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"assetType\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"nonQuantizedAmount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"quantizedAmount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"}],\"name\":\"LogWithdrawalPerformed\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"assetType\",\"type\":\"uint256\"}],\"name\":\"getAssetInfo\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"assetInfo\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"ownerKey\",\"type\":\"uint256\"}],\"name\":\"getEthKey\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"presumedAssetType\",\"type\":\"uint256\"}],\"name\":\"getQuantum\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"quantum\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"ownerKey\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"assetId\",\"type\":\"uint256\"}],\"name\":\"getWithdrawalBalance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"balance\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"isFrozen\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"ownerKey\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"assetType\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"ownerKey\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"assetType\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"mintingBlob\",\"type\":\"bytes\"}],\"name\":\"withdrawAndMint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"ownerKey\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"assetType\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"withdrawNft\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"notice\":\"For a user to perform a withdrawal operation from the Stark Exchange during normal operation two calls are required: 1. A call to an offchain exchange API, requesting a withdrawal from a user account (vault). 2. A call to the on-chain :sol:func:`withdraw` function to perform the actual withdrawal of funds transferring them to the users Eth or ERC20 account (depending on the token type). For simplicity, hereafter it is assumed that all tokens are ERC20 tokens but the text below applies to Eth in the same manner. In the first call mentioned above, anyone can call the API to request the withdrawal of an amount from a given vault. Following the request, the exchange may include the withdrawal in a STARK proof. The submission of a proof then results in the addition of the amount(s) withdrawn to an on-chain pending withdrawals account under the stark key of the vault owner and the appropriate asset ID. At the same time, this also implies that this amount is deducted from the off-chain vault. Once the amount to be withdrawn has been transfered to the on-chain pending withdrawals account, the user may perform the second call mentioned above to complete the transfer of funds from the Stark Exchange contract to the appropriate ERC20 account. Only a user holding the Eth key corresponding to the Stark Key of a pending withdrawals account may perform this operation. It is possible that for multiple withdrawal calls to the API, a single withdrawal call to the contract may retrieve all funds, as long as they are all for the same asset ID. The result of the operation, assuming all requirements are met, is that an amount of ERC20 tokens in the pending withdrawal account times the quantization factor is transferred to the ERC20 account of the user. A withdrawal request cannot be cancelled. Once funds reach the pending withdrawals account on-chain, they cannot be moved back into an off-chain vault before completion of the withdrawal to the ERC20 account of the user. In the event that the exchange reaches a frozen state the user may perform a withdrawal operation via an alternative flow, known as the \\\"Escape\\\" flow. In this flow, the API call above is replaced with an :sol:func:`escape` call to the on-chain contract (see :sol:mod:`Escapes`) proving the ownership of off-chain funds. If such proof is accepted, the user may proceed as above with the :sol:func:`withdraw` call to the contract to complete the operation.\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"project:/contracts/interactions/Withdrawals.sol\":\"Withdrawals\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":999},\"remappings\":[]},\"sources\":{\"project:/contracts/components/GovernanceStorage.sol\":{\"keccak256\":\"0x6d0c2dc8379daf076f521c76adeba111a1a171a13b928d58d87906be0d94b7e3\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://15f522122b9ac853e6444d7011128daf2dad449fa84750f33423562e4382df05\",\"dweb:/ipfs/Qmd1ThEb7bnwtXjrfrHKeJ2YMRbUA5NiFR6gUGxKxnGjAT\"]},\"project:/contracts/components/MainStorage.sol\":{\"keccak256\":\"0xebf6122fbacb7077265792e9e83fb7901ce265cea9bfbc98102d2dbb7c39bc45\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://14e4fbff97f0f66cfaecf3f7ea24dd96dfe5fc92aa43fa33167f74c322a85ac4\",\"dweb:/ipfs/QmYzAvAvULxjrpMMKiKwpmcpWcSQXARg92VS9boESupLdw\"]},\"project:/contracts/interactions/Withdrawals.sol\":{\"keccak256\":\"0x31c589918829236289fbf0c1afea0b43648739c846aff425e9122295e284c5c9\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://6f9dfc02ae3f46f5b1665de67083a094152c2f4d8b6a743b678aa40817a524e3\",\"dweb:/ipfs/QmSNxVA4QgLKkmyBwFafRRJ24SezPydWe3us8ebAgAtyMd\"]},\"project:/contracts/interfaces/MAcceptModifications.sol\":{\"keccak256\":\"0x3a2468895ed2590b9691d09ca950fc3f3e16c8f4b0800c8dd2128ba79e687046\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://702a5b330a7f5cb8f27443159fd8bf5ad86f50d054cdf33bc40d386797b96696\",\"dweb:/ipfs/Qmdtv8RRn3BauLYKi16hTmgf6YuTYHBDtatewy3f2PDmmv\"]},\"project:/contracts/interfaces/MFreezable.sol\":{\"keccak256\":\"0x94e7141003cf59cf820ee82cc16120910852efaaeb0958c4b7026a237e6fa9f1\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://378ff1ca14ffdd6b4c94d93410852817319672ed0a45364cf37772581402b623\",\"dweb:/ipfs/QmYU6a9mJL4kUMFMhkJD261rZSDtMgudE4uRTMGVdzmMby\"]},\"project:/contracts/interfaces/MKeyGetters.sol\":{\"keccak256\":\"0xf817f1c3facd9bc9661f31431ce1868cabb6a8a2929918c735ddc992849e9e1a\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://0faf953a055ee591454de9e31a4e27b959839cca1a06b0b11bed1ca562a3f19d\",\"dweb:/ipfs/QmeBfK873xetJCUgMifFHeWVKCyFXXVm4y7DbmnAG7nZqh\"]},\"project:/contracts/interfaces/MTokenAssetData.sol\":{\"keccak256\":\"0xc57654a93b35a54d0779d43c42acaa0f0430f387706f155c316375d6e8f8a5be\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://3a2d1dbbdf1a5d23ae24cf4b3ae316265d195e58166c1d33ae48cd3d98cba668\",\"dweb:/ipfs/QmbvkEkc4A71e22MXUWdcWFHhwZyBvzSGdSUyVt2ygqVzx\"]},\"project:/contracts/interfaces/MTokenQuantization.sol\":{\"keccak256\":\"0xea24ca4b267a3e5310211c630546b450e69fe9f1a78f4ee992515135d3a3a03b\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://872e332f790fe15a93c0edc8788d299fa66ebfda58ca784da84232faf1fdc204\",\"dweb:/ipfs/QmdUgs8hqJBCzLrSnPNqpHCh97wYqsTA71yPGeYE9CKwRw\"]},\"project:/contracts/interfaces/MTokenTransfers.sol\":{\"keccak256\":\"0x29382bb8a08ec8177830a01ffb664bc7da94dbfa563104989eedf8497a4b4607\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://0fe199ad0300bbd4f0a842d16fdf89cdf42c9844116c9cfc9e71ba562ac817fc\",\"dweb:/ipfs/QmVRRfpemrayfqWXK7viaQj7cCwGBKX3379xEP3EVQwi1g\"]},\"project:/contracts/libraries/Common.sol\":{\"keccak256\":\"0x3e7fed303ff85d78f71c77d6efe21de918b0442cd181f57a76a383868ec7b2dc\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://601275732e82d0ab81a4d54d1127fb80d0e04621a3090b0343d1a727df7f35d5\",\"dweb:/ipfs/QmU1XZ8dyDAaXQtQyRC4gfp3UeVbKHS5Qf8e9ybx1aXdRU\"]},\"project:/contracts/upgrade/ProxyStorage.sol\":{\"keccak256\":\"0x9e70e3020fcd37354caaa848e99f5bfc8baf0128e5a8fd57901031b7ab2a3337\",\"license\":\"Apache-2.0.\",\"urls\":[\"bzz-raw://8ebc36197863e3cfaa8735420236d796e90e20465636ac7880f71694de6b9ced\",\"dweb:/ipfs/QmbFnJWP8ceTd2LuhyKhCFQXiniJ1PnYWRjArPE5bCcFbU\"]}},\"version\":1}",
"bytecode": "0x",
"deployedBytecode": "0x",
"immutableReferences": {},
"sourceMap": "",
"deployedSourceMap": "",
"source": "// SPDX-License-Identifier: Apache-2.0.\r\npragma solidity ^0.6.11;\r\n\r\nimport \"../interfaces/MAcceptModifications.sol\";\r\nimport \"../interfaces/MTokenQuantization.sol\";\r\nimport \"../interfaces/MTokenAssetData.sol\";\r\nimport \"../interfaces/MFreezable.sol\";\r\nimport \"../interfaces/MKeyGetters.sol\";\r\nimport \"../interfaces/MTokenTransfers.sol\";\r\nimport \"../components/MainStorage.sol\";\r\n\r\n/**\r\n For a user to perform a withdrawal operation from the Stark Exchange during normal operation\r\n two calls are required:\r\n\r\n 1. A call to an offchain exchange API, requesting a withdrawal from a user account (vault).\r\n 2. A call to the on-chain :sol:func:`withdraw` function to perform the actual withdrawal of funds transferring them to the users Eth or ERC20 account (depending on the token type).\r\n\r\n For simplicity, hereafter it is assumed that all tokens are ERC20 tokens but the text below\r\n applies to Eth in the same manner.\r\n\r\n In the first call mentioned above, anyone can call the API to request the withdrawal of an\r\n amount from a given vault. Following the request, the exchange may include the withdrawal in a\r\n STARK proof. The submission of a proof then results in the addition of the amount(s) withdrawn to\r\n an on-chain pending withdrawals account under the stark key of the vault owner and the appropriate\r\n asset ID. At the same time, this also implies that this amount is deducted from the off-chain\r\n vault.\r\n\r\n Once the amount to be withdrawn has been transfered to the on-chain pending withdrawals account,\r\n the user may perform the second call mentioned above to complete the transfer of funds from the\r\n Stark Exchange contract to the appropriate ERC20 account. Only a user holding the Eth key\r\n corresponding to the Stark Key of a pending withdrawals account may perform this operation.\r\n\r\n It is possible that for multiple withdrawal calls to the API, a single withdrawal call to the\r\n contract may retrieve all funds, as long as they are all for the same asset ID.\r\n\r\n The result of the operation, assuming all requirements are met, is that an amount of ERC20 tokens\r\n in the pending withdrawal account times the quantization factor is transferred to the ERC20\r\n account of the user.\r\n\r\n A withdrawal request cannot be cancelled. Once funds reach the pending withdrawals account\r\n on-chain, they cannot be moved back into an off-chain vault before completion of the withdrawal\r\n to the ERC20 account of the user.\r\n\r\n In the event that the exchange reaches a frozen state the user may perform a withdrawal operation\r\n via an alternative flow, known as the \"Escape\" flow. In this flow, the API call above is replaced\r\n with an :sol:func:`escape` call to the on-chain contract (see :sol:mod:`Escapes`) proving the\r\n ownership of off-chain funds. If such proof is accepted, the user may proceed as above with\r\n the :sol:func:`withdraw` call to the contract to complete the operation.\r\n*/\r\nabstract contract Withdrawals is\r\n MainStorage,\r\n MAcceptModifications,\r\n MTokenQuantization,\r\n MTokenAssetData,\r\n MFreezable,\r\n MKeyGetters,\r\n MTokenTransfers\r\n{\r\n event LogWithdrawalPerformed(\r\n uint256 ownerKey,\r\n uint256 assetType,\r\n uint256 nonQuantizedAmount,\r\n uint256 quantizedAmount,\r\n address recipient\r\n );\r\n\r\n event LogNftWithdrawalPerformed(\r\n uint256 ownerKey,\r\n uint256 assetType,\r\n uint256 tokenId,\r\n uint256 assetId,\r\n address recipient\r\n );\r\n\r\n event LogMintWithdrawalPerformed(\r\n uint256 ownerKey,\r\n uint256 assetType,\r\n uint256 nonQuantizedAmount,\r\n uint256 quantizedAmount,\r\n uint256 assetId\r\n );\r\n\r\n function getWithdrawalBalance(uint256 ownerKey, uint256 assetId)\r\n external\r\n view\r\n returns (uint256 balance)\r\n {\r\n uint256 presumedAssetType = assetId;\r\n balance = fromQuantized(presumedAssetType, pendingWithdrawals[ownerKey][assetId]);\r\n }\r\n\r\n /*\r\n Moves funds from the pending withdrawal account to the owner address.\r\n Note: this function can be called by anyone.\r\n Can be called normally while frozen.\r\n */\r\n function withdraw(uint256 ownerKey, uint256 assetType) external {\r\n address payable recipient = payable(strictGetEthKey(ownerKey));\r\n require(!isMintableAssetType(assetType), \"MINTABLE_ASSET_TYPE\");\r\n require(isFungibleAssetType(assetType), \"NON_FUNGIBLE_ASSET_TYPE\");\r\n uint256 assetId = assetType;\r\n // Fetch and clear quantized amount.\r\n uint256 quantizedAmount = pendingWithdrawals[ownerKey][assetId];\r\n pendingWithdrawals[ownerKey][assetId] = 0;\r\n\r\n // Transfer funds.\r\n transferOut(recipient, assetType, quantizedAmount);\r\n emit LogWithdrawalPerformed(\r\n ownerKey,\r\n assetType,\r\n fromQuantized(assetType, quantizedAmount),\r\n quantizedAmount,\r\n recipient\r\n );\r\n }\r\n\r\n /*\r\n Allows withdrawal of an NFT to its owner account.\r\n Note: this function can be called by anyone.\r\n This function can be called normally while frozen.\r\n */\r\n function withdrawNft(\r\n uint256 ownerKey,\r\n uint256 assetType,\r\n uint256 tokenId // No notFrozen modifier: This function can always be used, even when frozen.\r\n ) external {\r\n address recipient = strictGetEthKey(ownerKey);\r\n // Calculate assetId.\r\n uint256 assetId = calculateNftAssetId(assetType, tokenId);\r\n require(!isMintableAssetType(assetType), \"MINTABLE_ASSET_TYPE\");\r\n require(!isFungibleAssetType(assetType), \"FUNGIBLE_ASSET_TYPE\");\r\n require(pendingWithdrawals[ownerKey][assetId] == 1, \"ILLEGAL_NFT_BALANCE\");\r\n pendingWithdrawals[ownerKey][assetId] = 0;\r\n\r\n // Transfer funds.\r\n transferOutNft(recipient, assetType, tokenId);\r\n emit LogNftWithdrawalPerformed(ownerKey, assetType, tokenId, assetId, recipient);\r\n }\r\n\r\n function withdrawAndMint(\r\n uint256 ownerKey,\r\n uint256 assetType,\r\n bytes calldata mintingBlob\r\n ) external {\r\n address recipient = strictGetEthKey(ownerKey);\r\n require(registeredAssetType[assetType], \"INVALID_ASSET_TYPE\");\r\n require(isMintableAssetType(assetType), \"NON_MINTABLE_ASSET_TYPE\");\r\n uint256 assetId = calculateMintableAssetId(assetType, mintingBlob);\r\n require(pendingWithdrawals[ownerKey][assetId] > 0, \"NO_PENDING_WITHDRAWAL_BALANCE\");\r\n uint256 quantizedAmount = pendingWithdrawals[ownerKey][assetId];\r\n pendingWithdrawals[ownerKey][assetId] = 0;\r\n // Transfer funds.\r\n transferOutMint(assetType, quantizedAmount, recipient, mintingBlob);\r\n emit LogMintWithdrawalPerformed(\r\n ownerKey,\r\n assetType,\r\n fromQuantized(assetType, quantizedAmount),\r\n quantizedAmount,\r\n assetId\r\n );\r\n }\r\n}\r\n",
"sourcePath": "D:\\Myria\\starkex-contracts\\contracts\\interactions\\Withdrawals.sol",
"ast": {
"absolutePath": "project:/contracts/interactions/Withdrawals.sol",
"exportedSymbols": {
"Withdrawals": [
5024
]
},
"id": 5025,
"license": "Apache-2.0.",
"nodeType": "SourceUnit",
"nodes": [
{
"id": 4717,
"literals": [
"solidity",
"^",
"0.6",
".11"
],
"nodeType": "PragmaDirective",
"src": "41:24:30"
},
{
"absolutePath": "project:/contracts/interfaces/MAcceptModifications.sol",
"file": "../interfaces/MAcceptModifications.sol",
"id": 4718,
"nodeType": "ImportDirective",
"scope": 5025,
"sourceUnit": 5202,
"src": "69:48:30",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "project:/contracts/interfaces/MTokenQuantization.sol",
"file": "../interfaces/MTokenQuantization.sol",
"id": 4719,
"nodeType": "ImportDirective",
"scope": 5025,
"sourceUnit": 5544,
"src": "119:46:30",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "project:/contracts/interfaces/MTokenAssetData.sol",
"file": "../interfaces/MTokenAssetData.sol",
"id": 4720,
"nodeType": "ImportDirective",
"scope": 5025,
"sourceUnit": 5516,
"src": "167:43:30",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "project:/contracts/interfaces/MFreezable.sol",
"file": "../interfaces/MFreezable.sol",
"id": 4721,
"nodeType": "ImportDirective",
"scope": 5025,
"sourceUnit": 5320,
"src": "212:38:30",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "project:/contracts/interfaces/MKeyGetters.sol",
"file": "../interfaces/MKeyGetters.sol",
"id": 4722,
"nodeType": "ImportDirective",
"scope": 5025,
"sourceUnit": 5382,
"src": "252:39:30",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "project:/contracts/interfaces/MTokenTransfers.sol",
"file": "../interfaces/MTokenTransfers.sol",
"id": 4723,
"nodeType": "ImportDirective",
"scope": 5025,
"sourceUnit": 5590,
"src": "293:43:30",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "project:/contracts/components/MainStorage.sol",
"file": "../components/MainStorage.sol",
"id": 4724,
"nodeType": "ImportDirective",
"scope": 5025,
"sourceUnit": 1846,
"src": "338:39:30",
"symbolAliases": [],
"unitAlias": ""
},
{
"abstract": true,
"baseContracts": [
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 4726,
"name": "MainStorage",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 1845,
"src": "2968:11:30",
"typeDescriptions": {
"typeIdentifier": "t_contract$_MainStorage_$1845",
"typeString": "contract MainStorage"
}
},
"id": 4727,
"nodeType": "InheritanceSpecifier",
"src": "2968:11:30"
},
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 4728,
"name": "MAcceptModifications",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 5201,
"src": "2986:20:30",
"typeDescriptions": {
"typeIdentifier": "t_contract$_MAcceptModifications_$5201",
"typeString": "contract MAcceptModifications"
}
},
"id": 4729,
"nodeType": "InheritanceSpecifier",
"src": "2986:20:30"
},
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 4730,
"name": "MTokenQuantization",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 5543,
"src": "3013:18:30",
"typeDescriptions": {
"typeIdentifier": "t_contract$_MTokenQuantization_$5543",
"typeString": "contract MTokenQuantization"
}
},
"id": 4731,
"nodeType": "InheritanceSpecifier",
"src": "3013:18:30"
},
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 4732,
"name": "MTokenAssetData",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 5515,
"src": "3038:15:30",
"typeDescriptions": {
"typeIdentifier": "t_contract$_MTokenAssetData_$5515",
"typeString": "contract MTokenAssetData"
}
},
"id": 4733,
"nodeType": "InheritanceSpecifier",
"src": "3038:15:30"
},
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 4734,
"name": "MFreezable",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 5319,
"src": "3060:10:30",
"typeDescriptions": {
"typeIdentifier": "t_contract$_MFreezable_$5319",
"typeString": "contract MFreezable"
}
},
"id": 4735,
"nodeType": "InheritanceSpecifier",
"src": "3060:10:30"
},
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 4736,
"name": "MKeyGetters",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 5381,
"src": "3077:11:30",
"typeDescriptions": {
"typeIdentifier": "t_contract$_MKeyGetters_$5381",
"typeString": "contract MKeyGetters"
}
},
"id": 4737,
"nodeType": "InheritanceSpecifier",
"src": "3077:11:30"
},
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 4738,
"name": "MTokenTransfers",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 5589,
"src": "3095:15:30",
"typeDescriptions": {
"typeIdentifier": "t_contract$_MTokenTransfers_$5589",
"typeString": "contract MTokenTransfers"
}
},
"id": 4739,
"nodeType": "InheritanceSpecifier",
"src": "3095:15:30"
}
],
"contractDependencies": [
1479,
1845,
5201,
5319,
5381,
5515,
5543,
5589,
15176
],
"contractKind": "contract",
"documentation": {
"id": 4725,
"nodeType": "StructuredDocumentation",
"src": "381:2547:30",
"text": "For a user to perform a withdrawal operation from the Stark Exchange during normal operation\ntwo calls are required:\n1. A call to an offchain exchange API, requesting a withdrawal from a user account (vault).\n2. A call to the on-chain :sol:func:`withdraw` function to perform the actual withdrawal of funds transferring them to the users Eth or ERC20 account (depending on the token type).\nFor simplicity, hereafter it is assumed that all tokens are ERC20 tokens but the text below\napplies to Eth in the same manner.\nIn the first call mentioned above, anyone can call the API to request the withdrawal of an\namount from a given vault. Following the request, the exchange may include the withdrawal in a\nSTARK proof. The submission of a proof then results in the addition of the amount(s) withdrawn to\nan on-chain pending withdrawals account under the stark key of the vault owner and the appropriate\nasset ID. At the same time, this also implies that this amount is deducted from the off-chain\nvault.\nOnce the amount to be withdrawn has been transfered to the on-chain pending withdrawals account,\nthe user may perform the second call mentioned above to complete the transfer of funds from the\nStark Exchange contract to the appropriate ERC20 account. Only a user holding the Eth key\ncorresponding to the Stark Key of a pending withdrawals account may perform this operation.\nIt is possible that for multiple withdrawal calls to the API, a single withdrawal call to the\ncontract may retrieve all funds, as long as they are all for the same asset ID.\nThe result of the operation, assuming all requirements are met, is that an amount of ERC20 tokens\nin the pending withdrawal account times the quantization factor is transferred to the ERC20\naccount of the user.\nA withdrawal request cannot be cancelled. Once funds reach the pending withdrawals account\non-chain, they cannot be moved back into an off-chain vault before completion of the withdrawal\nto the ERC20 account of the user.\nIn the event that the exchange reaches a frozen state the user may perform a withdrawal operation\nvia an alternative flow, known as the \"Escape\" flow. In this flow, the API call above is replaced\nwith an :sol:func:`escape` call to the on-chain contract (see :sol:mod:`Escapes`) proving the\nownership of off-chain funds. If such proof is accepted, the user may proceed as above with\nthe :sol:func:`withdraw` call to the contract to complete the operation."
},
"fullyImplemented": false,
"id": 5024,
"linearizedBaseContracts": [
5024,
5589,
5381,
5319,
5515,
5543,
5201,
1845,
15176,
1479
],
"name": "Withdrawals",
"nodeType": "ContractDefinition",
"nodes": [
{
"anonymous": false,
"documentation": null,
"id": 4751,
"name": "LogWithdrawalPerformed",
"nodeType": "EventDefinition",
"parameters": {
"id": 4750,
"nodeType": "ParameterList",
"parameters": [
{
"constant": false,
"id": 4741,
"indexed": false,
"mutability": "mutable",
"name": "ownerKey",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 4751,
"src": "3158:16:30",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4740,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "3158:7:30",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
},
{
"constant": false,
"id": 4743,
"indexed": false,
"mutability": "mutable",
"name": "assetType",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 4751,
"src": "3185:17:30",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4742,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "3185:7:30",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
},
{
"constant": false,
"id": 4745,
"indexed": false,
"mutability": "mutable",
"name": "nonQuantizedAmount",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 4751,
"src": "3213:26:30",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4744,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "3213:7:30",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
},
{
"constant": false,
"id": 4747,
"indexed": false,
"mutability": "mutable",
"name": "quantizedAmount",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 4751,
"src": "3250:23:30",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4746,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "3250:7:30",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
},
{
"constant": false,
"id": 4749,
"indexed": false,
"mutability": "mutable",
"name": "recipient",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 4751,
"src": "3284:17:30",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
},
"typeName": {
"id": 4748,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "3284:7:30",
"stateMutability": "nonpayable",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"value": null,
"visibility": "internal"
}
],
"src": "3147:161:30"
},
"src": "3119:190:30"
},
{
"anonymous": false,
"documentation": null,
"id": 4763,
"name": "LogNftWithdrawalPerformed",
"nodeType": "EventDefinition",
"parameters": {
"id": 4762,
"nodeType": "ParameterList",
"parameters": [
{
"constant": false,
"id": 4753,
"indexed": false,
"mutability": "mutable",
"name": "ownerKey",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 4763,
"src": "3359:16:30",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4752,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src