@dolomite-exchange/dolomite-margin
Version:
Ethereum Smart Contracts and TypeScript library used for the DolomiteMargin trading protocol
681 lines • 1.11 MB
JSON
{
"contractName": "AccountActionLib",
"abi": [],
"metadata": "{\"compiler\":{\"version\":\"0.5.16+commit.9c3226ce\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"author\":\"Dolomite * Library contract that makes specific actions easy to call\",\"methods\":{},\"title\":\"AccountActionLib\"},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/cdc218/projects/dolomite-protocol-v2/contracts/external/lib/AccountActionLib.sol\":\"AccountActionLib\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"/home/cdc218/projects/dolomite-protocol-v2/contracts/external/interfaces/IExpiry.sol\":{\"keccak256\":\"0xa7b197139e570e823cab42c3b8500c9c5edc8a40110970a7d6fe60f05864ba10\",\"urls\":[\"bzz-raw://4f469be063d8f694c5277650bc53ac2c0d164f62e36c6a9ab7dad126479990a9\",\"dweb:/ipfs/Qme4sTbGi4T2QhsJSweqGzqm5rxQkypy27g1vLy8ipVijV\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/external/lib/AccountActionLib.sol\":{\"keccak256\":\"0x5488dd7eae5ce96e479445f19301d9dd44d292a2d6739b9da1fe948eeb41edc4\",\"urls\":[\"bzz-raw://06977e07aea4d893db696173f3ee01a84008770c4e0d81fb5eb82af3a597ceaa\",\"dweb:/ipfs/QmYiH8CsXEbHypJ2gN31LnZv2tfzd2RBuSKoRgx2EbBw26\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/external/lib/AccountBalanceLib.sol\":{\"keccak256\":\"0x76fd16d615fe7cfceaf775b4e6524fd0462606c802b082498c768a7a4ca01a20\",\"urls\":[\"bzz-raw://56068145e300cde1c77c22e38cb753378abf2f0d4613dcb203e33ff101f169e2\",\"dweb:/ipfs/QmXvMzr9n7vzMHdUPgnc58KX4mrbQAqkq4kDETaj5Y55ZY\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IAccountRiskOverrideSetter.sol\":{\"keccak256\":\"0x5b9fde139ddfdaae7b650b3c3f6699e0e44605f0d9d3daadc1622eb06ad4c3f8\",\"urls\":[\"bzz-raw://2dfd5af24b6de63f94519c99fd8777a264d7cd11266fa2d525c7d72d96a9c7cf\",\"dweb:/ipfs/QmPg9fjhbnmBayZMh6yTG79xsK1PWSoAHA5pfwSXfnKKjF\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IDolomiteMargin.sol\":{\"keccak256\":\"0x7e86ed1ed04dc205245db9f4e7cf7cca60c3bfc46c57ade8129a463780647967\",\"urls\":[\"bzz-raw://f8fbd85afd334c12bdccbb6523ebea9172b27b7b4b132c4a48b4b4dd03ceeb2b\",\"dweb:/ipfs/QmU1srfSqBTz3kw7oz1KEzfTUJvphZiE4K8MRZcy9uJjv1\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IERC20Detailed.sol\":{\"keccak256\":\"0x22a62e2a8155e70300773721902f4b9118e17aa0bb5d9d1b046050a014cfb223\",\"urls\":[\"bzz-raw://03af737a33c552fbe58f6f1fbd5496854fdc28dd57be4365d56663725c083a18\",\"dweb:/ipfs/QmbgLqGAQEd6tXsZB8QaPNCAMiU6nNzP75wNbKdS65BuUF\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IInterestSetter.sol\":{\"keccak256\":\"0x546825f65490a30e29d0f6446acec49c1e895ce6b33d48ca5c05092725a63a57\",\"urls\":[\"bzz-raw://6ad3013aed985bdf6e6234ae0f7f37e6bba76c3470c33bfa24678cf19b3b412c\",\"dweb:/ipfs/QmfYaSBzxGpgiHoR7ontMJY66S5L26XwkLYoEuzsEjpbQH\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IOracleSentinel.sol\":{\"keccak256\":\"0xa94499fda55ef112640daed2cb1d06062e72c51c7b925c323b4e0ffa9b456ce5\",\"urls\":[\"bzz-raw://18b4a16acac577590a57f34f7ec6583e3cb35f575c948abb928b308d29cac1ab\",\"dweb:/ipfs/QmR1jLkzj6w7SjrdZ7GVW4V2vofSdMJwzjTqKpeUKABvxu\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IPriceOracle.sol\":{\"keccak256\":\"0x3f7c3d1397390ea44c6d5e5730d49476431c3df3b28334fe38218de5edc31138\",\"urls\":[\"bzz-raw://63ebf926fca9ce33aaabaf93805686acc25daded1648d6dab59c8c4d05116918\",\"dweb:/ipfs/QmeGkDp7ycYstpfqCYBiqoCYwy876gabx8r42o5koj3H5A\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Account.sol\":{\"keccak256\":\"0x2059276ea5e478bd5ac7f2712e7b1b6c85d291c647a54b264909044844828e67\",\"urls\":[\"bzz-raw://f153777051d12131b13a57e5c3af10a2670927cfc7d22c9519ab20c9b4b9bc89\",\"dweb:/ipfs/QmQMP3qS5xDAVGYKDfNkbkSqBKozQGQsGqX4e8VyjRtxPS\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Actions.sol\":{\"keccak256\":\"0x7b2fcf441c034952dd042b6c8b20b148359db771e7c9ac07d06369560a9f0301\",\"urls\":[\"bzz-raw://84665ee4a780360fe6160d197ba98f0bf0ab0d7c6ad87bfed6226bf2f88d8d30\",\"dweb:/ipfs/QmRDfRdAd8hSXeu4SAeeYKkKoXBhStu7n4uReYBce2JD5Z\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Bits.sol\":{\"keccak256\":\"0x6d9a641163b2dd25e648c65f5d9e4949a57938e29ddc4c9dddefd74a9964aeef\",\"urls\":[\"bzz-raw://67e5a04ed4055faafbc100d6ccca9c54448ed378a1a8c71171562edda7bcbf7c\",\"dweb:/ipfs/QmYRikK3Xbgiq3UBJkgoo2zNUSSrShVabpRHmQj6iQHhrc\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Cache.sol\":{\"keccak256\":\"0xe57c80a7621a77fcb2acb9f883fb5248e71a6dce03bc2db56df0db3fee332950\",\"urls\":[\"bzz-raw://28e221c04629674490b9a0041d4f9a5f15e669dc0cc192a5df6e2c701c36369f\",\"dweb:/ipfs/QmaL3oh8c7v9cx91pB175pyCEuzxnhNTab4UxmBMsDYfUx\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Decimal.sol\":{\"keccak256\":\"0xd9a348c2b1eec076609ba12bbec6b9c2e4ea135790a7ef4f5411feb050af2144\",\"urls\":[\"bzz-raw://d5bcff29e47d5cd02d7a9966e9f44c46ccbb4f0e4adfc4b0b86646880677db39\",\"dweb:/ipfs/QmRKfJD4FFM1AvTynSFNx1NcDg94o9SAcjz7dvMaJCfecp\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/DolomiteMarginMath.sol\":{\"keccak256\":\"0x53f205f6a779d579be29faa9412c806a892b3e605fff092dfd9d14d936fa019f\",\"urls\":[\"bzz-raw://0ff936f89602a63b8e6a4eb4ce8f87673c0f45b7ce29694920905a3f0b5a6a69\",\"dweb:/ipfs/QmbYME9BeEvPC1ndV8EaUDX5fDMghLc3rocNUxFtgHmg8m\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/EnumerableSet.sol\":{\"keccak256\":\"0x41a3460e34b7b8635d936e35e6568ceb5354b638f53b884530e0d4875fa0f151\",\"urls\":[\"bzz-raw://d1a5ba866ee95d455afe5075dadd91fc71c2806371f2c1b358a1f67c632bb0df\",\"dweb:/ipfs/QmW4qCjmsG8J3UJv97GwDLDM7wt1K4yLDKAwzWMY7TFYi5\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Interest.sol\":{\"keccak256\":\"0x141a0ecb4a746f0e5767df4b99dbe33c6362df507ae9d5c02da1c1c17bc26df3\",\"urls\":[\"bzz-raw://9ff03e64a8ce5231acde07788624bf8c7a8ff55d90b157fa32f62fa887a0eff0\",\"dweb:/ipfs/QmUVxxWeE954RDXbmHJAYnHsXcit6rSXGqZUigu8t9oH2z\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Monetary.sol\":{\"keccak256\":\"0x5257274f2d4d3605f3e97ec45fb902111fe9a22506f0b4cf308ea933bc81bfe2\",\"urls\":[\"bzz-raw://85b8023b78805063a2ec8d376f1f5983994eabd96efd8ceadb0224dbb71c5678\",\"dweb:/ipfs/QmaDhzCzRqsuHuJfhToEC4pATQHwhh7yWWsjwfuRzFT1kG\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Require.sol\":{\"keccak256\":\"0x05a2a90b41b6a5f42f0a72da63d015fb0b406a9ba2172823352e522e8bf3a606\",\"urls\":[\"bzz-raw://19883f0c6d33266f756ec5c3d17539524aa24b993c46c33f8400801d09373a6c\",\"dweb:/ipfs/QmYX2fwK3vQQDSZLMrc5wMfeb8RWrcC9CGX8XECLty8QDk\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Storage.sol\":{\"keccak256\":\"0x9c27f3cd52af28c9b6bca18097b1793f114d08284d78417467d0d05f67e9e2a9\",\"urls\":[\"bzz-raw://d1ed0e7a7f76d59f30572996d4e164ab8fb5b2ec4bfca127983f9e936b904813\",\"dweb:/ipfs/QmePVYbgrY8Yw3Vf76pmEvE9pX916Jaa9we4kjM8tGM4J1\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Time.sol\":{\"keccak256\":\"0x87ee8d3c1d6e315a116426d8c8fc6f083e220fd14dda27fad4e8d7cab3dc7305\",\"urls\":[\"bzz-raw://7c20f2c52da682c3b5917fb6a19e81f43699b1d13c62b569ed723f34da72e766\",\"dweb:/ipfs/QmbXWYXi67nHBVNDKYUpo2E9ZaEVcHLvmXQkpYLMm1d5Vm\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Token.sol\":{\"keccak256\":\"0x095b5f8eb3665f6e246200311efc8a654fa3e90f9a1a522e27a4d089e8ab3917\",\"urls\":[\"bzz-raw://5db812b752a03d601d424e6e21be38153477082af0acf51b5c98eefa5553ed18\",\"dweb:/ipfs/QmbE549QUXYTurpx8hSMLBJvuBpfYqyNE6FBCgHJDY8PLf\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Types.sol\":{\"keccak256\":\"0xe1bab8c8799d83e86c7a49aaf815d8e3bc8d09562d46d44d921500db5e98de0e\",\"urls\":[\"bzz-raw://8ea3d0cc4fdab6dd9bba545a792170f939b342d8d1a7051c1c6365009af72658\",\"dweb:/ipfs/QmaLJgbavu88eEit6JPqfWnw6NmGBDZfveMXxumgWywBFG\"]},\"@openzeppelin/contracts/math/SafeMath.sol\":{\"keccak256\":\"0x640b6dee7a4b830bdfd52b5031a07fc2b12209f5b2e29e5d364a7d37f69d8076\",\"urls\":[\"bzz-raw://31113152e1ddb78fe7a4197f247591ca894e93f916867beb708d8e747b6cc74f\",\"dweb:/ipfs/QmbZaJyXdpsYGykVhHH9qpVGQg9DGCxE2QufbCUy3daTgq\"]},\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"keccak256\":\"0xe5bb0f57cff3e299f360052ba50f1ea0fff046df2be070b6943e0e3c3fdad8a9\",\"urls\":[\"bzz-raw://59fd025151435da35faa8093a5c7a17de02de9d08ad27275c5cdf05050820d91\",\"dweb:/ipfs/QmQMvwEcPhoRXzbXyrdoeRtvLoifUW9Qh7Luho7bmUPRkc\"]}},\"version\":1}",
"bytecode": "0x60636023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea365627a7a72315820ec544de373ebe03451404d81dec6ece090c0b1cfeca8c4e71289d62c945f36bf6c6578706572696d656e74616cf564736f6c63430005100040",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea365627a7a72315820ec544de373ebe03451404d81dec6ece090c0b1cfeca8c4e71289d62c945f36bf6c6578706572696d656e74616cf564736f6c63430005100040",
"sourceMap": "1201:13898:34:-;;132:2:-1;166:7;155:9;146:7;137:37;255:7;249:14;246:1;241:23;235:4;232:33;222:2;;269:9;222:2;293:9;290:1;283:20;323:4;314:7;306:22;347:7;338;331:24",
"deployedSourceMap": "1201:13898:34:-;;;;;;;;",
"source": "/*\n\n Copyright 2022 Dolomite.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.5.7;\npragma experimental ABIEncoderV2;\n\nimport { IDolomiteMargin } from \"../../protocol/interfaces/IDolomiteMargin.sol\";\n\nimport { Account } from \"../../protocol/lib/Account.sol\";\nimport { Actions } from \"../../protocol/lib/Actions.sol\";\nimport { Require } from \"../../protocol/lib/Require.sol\";\nimport { Types } from \"../../protocol/lib/Types.sol\";\n\nimport { IExpiry } from \"../interfaces/IExpiry.sol\";\n\nimport { AccountBalanceLib } from \"./AccountBalanceLib.sol\";\n\n\n/**\n * @title AccountActionLib\n * @author Dolomite\n *\n * Library contract that makes specific actions easy to call\n */\nlibrary AccountActionLib {\n\n // ============ Constants ============\n\n bytes32 private constant FILE = \"AccountActionLib\";\n\n uint256 constant ALL = uint256(-1);\n\n // ============ Functions ============\n\n function all() internal pure returns (uint256) {\n return ALL;\n }\n\n // ========================= Operation Functions =========================\n\n function deposit(\n IDolomiteMargin _dolomiteMargin,\n address _accountOwner,\n address _fromAccount,\n uint256 _toAccountNumber,\n uint256 _marketId,\n Types.AssetAmount memory _amount\n ) internal {\n Account.Info[] memory accounts = new Account.Info[](1);\n accounts[0] = Account.Info({\n owner: _accountOwner,\n number: _toAccountNumber\n });\n\n Actions.ActionArgs[] memory actions = new Actions.ActionArgs[](1);\n actions[0] = encodeDepositAction(\n /* _accountId = */ 0, // solium-disable-line indentation\n _marketId,\n _amount,\n _fromAccount\n );\n\n _dolomiteMargin.operate(accounts, actions);\n }\n\n /**\n * Withdraws `_marketId` from `_fromAccount` to `_toAccount`\n */\n function withdraw(\n IDolomiteMargin _dolomiteMargin,\n address _accountOwner,\n uint256 _fromAccountNumber,\n address _toAccount,\n uint256 _marketId,\n Types.AssetAmount memory _amount,\n AccountBalanceLib.BalanceCheckFlag _balanceCheckFlag\n ) internal {\n Account.Info[] memory accounts = new Account.Info[](1);\n accounts[0] = Account.Info({\n owner: _accountOwner,\n number: _fromAccountNumber\n });\n\n Actions.ActionArgs[] memory actions = new Actions.ActionArgs[](1);\n actions[0] = encodeWithdrawalAction(\n /* _accountId = */ 0, // solium-disable-line indentation\n _marketId,\n _amount,\n _toAccount\n );\n\n _dolomiteMargin.operate(accounts, actions);\n\n if (\n _balanceCheckFlag == AccountBalanceLib.BalanceCheckFlag.Both\n || _balanceCheckFlag == AccountBalanceLib.BalanceCheckFlag.From\n ) {\n AccountBalanceLib.verifyBalanceIsNonNegative(\n _dolomiteMargin,\n accounts[0].owner,\n _fromAccountNumber,\n _marketId\n );\n }\n }\n\n /**\n * Transfers `_marketId` from `_fromAccount` to `_toAccount`\n */\n function transfer(\n IDolomiteMargin _dolomiteMargin,\n address _fromAccountOwner,\n uint256 _fromAccountNumber,\n address _toAccountOwner,\n uint256 _toAccountNumber,\n uint256 _marketId,\n Types.AssetAmount memory _amount,\n AccountBalanceLib.BalanceCheckFlag _balanceCheckFlag\n ) internal {\n Account.Info[] memory accounts = new Account.Info[](2);\n accounts[0] = Account.Info({\n owner: _fromAccountOwner,\n number: _fromAccountNumber\n });\n accounts[1] = Account.Info({\n owner: _toAccountOwner,\n number: _toAccountNumber\n });\n\n Actions.ActionArgs[] memory actions = new Actions.ActionArgs[](1);\n actions[0] = Actions.ActionArgs({\n actionType: Actions.ActionType.Transfer,\n accountId: 0,\n amount: _amount,\n primaryMarketId: _marketId,\n secondaryMarketId: 0,\n otherAddress: address(0),\n otherAccountId: 1,\n data: bytes(\"\")\n });\n\n _dolomiteMargin.operate(accounts, actions);\n\n if (\n _balanceCheckFlag == AccountBalanceLib.BalanceCheckFlag.Both\n || _balanceCheckFlag == AccountBalanceLib.BalanceCheckFlag.From\n ) {\n AccountBalanceLib.verifyBalanceIsNonNegative(\n _dolomiteMargin,\n _fromAccountOwner,\n _fromAccountNumber,\n _marketId\n );\n }\n\n if (\n _balanceCheckFlag == AccountBalanceLib.BalanceCheckFlag.Both\n || _balanceCheckFlag == AccountBalanceLib.BalanceCheckFlag.To\n ) {\n AccountBalanceLib.verifyBalanceIsNonNegative(\n _dolomiteMargin,\n _toAccountOwner,\n _toAccountNumber,\n _marketId\n );\n }\n }\n\n // ========================= Encoding Functions =========================\n\n function encodeCallAction(\n uint256 _accountId,\n address _callee,\n bytes memory _callData\n ) internal pure returns (Actions.ActionArgs memory) {\n return Actions.ActionArgs({\n actionType : Actions.ActionType.Call,\n accountId : _accountId,\n amount : Types.AssetAmount({\n sign: true,\n denomination: Types.AssetDenomination.Wei,\n ref: Types.AssetReference.Delta,\n value: 0\n }),\n primaryMarketId : 0,\n secondaryMarketId : 0,\n otherAddress : _callee,\n otherAccountId : 0,\n data : _callData\n });\n }\n\n function encodeDepositAction(\n uint256 _accountId,\n uint256 _marketId,\n Types.AssetAmount memory _amount,\n address _fromAccount\n ) internal pure returns (Actions.ActionArgs memory) {\n return Actions.ActionArgs({\n actionType: Actions.ActionType.Deposit,\n accountId: _accountId,\n amount: _amount,\n primaryMarketId: _marketId,\n secondaryMarketId: 0,\n otherAddress: _fromAccount,\n otherAccountId: 0,\n data: bytes(\"\")\n });\n }\n\n function encodeExpirationAction(\n Account.Info memory _account,\n uint256 _accountId,\n uint256 _owedMarketId,\n address _expiry,\n uint32 _expiryTimeDelta\n ) internal pure returns (Actions.ActionArgs memory) {\n IExpiry.SetExpiryArg[] memory expiryArgs = new IExpiry.SetExpiryArg[](1);\n expiryArgs[0] = IExpiry.SetExpiryArg({\n account : _account,\n marketId : _owedMarketId,\n timeDelta : _expiryTimeDelta,\n forceUpdate : true\n });\n\n return encodeCallAction(\n _accountId,\n _expiry,\n abi.encode(IExpiry.CallFunctionType.SetExpiry, expiryArgs)\n );\n }\n\n function encodeExpiryLiquidateAction(\n uint256 _solidAccountId,\n uint256 _liquidAccountId,\n uint256 _owedMarketId,\n uint256 _heldMarketId,\n address _expiryProxy,\n uint32 _expiry,\n uint256 _solidHeldUpdateWithReward,\n uint256 _owedWeiToLiquidate,\n bool _flipMarkets\n ) internal pure returns (Actions.ActionArgs memory) {\n Types.AssetAmount memory assetAmount;\n if (!_flipMarkets) {\n // Make the amount positive so the liquid account's owedMarket goes up (gets repaid).\n assetAmount = Types.AssetAmount({\n sign: true,\n denomination: Types.AssetDenomination.Wei,\n ref: Types.AssetReference.Delta,\n value: _owedWeiToLiquidate\n });\n } else {\n assert(_flipMarkets);\n // Make the amount negative so the liquid account's heldMarket goes down (gets spent to repay owedMarket).\n assetAmount = Types.AssetAmount({\n sign: false,\n denomination: Types.AssetDenomination.Wei,\n ref: Types.AssetReference.Delta,\n value: _solidHeldUpdateWithReward\n });\n }\n\n return Actions.ActionArgs({\n actionType: Actions.ActionType.Trade,\n accountId: _solidAccountId,\n amount: assetAmount,\n primaryMarketId: !_flipMarkets ? _owedMarketId : _heldMarketId,\n secondaryMarketId: !_flipMarkets ? _heldMarketId : _owedMarketId,\n otherAddress: _expiryProxy,\n otherAccountId: _liquidAccountId,\n data: abi.encode(\n /* calculateAmountWithMakerAccount = */ true,\n abi.encode(_owedMarketId, _expiry)\n )\n });\n }\n\n function encodeInternalTradeActionWithCustomData(\n uint256 _fromAccountId,\n uint256 _toAccountId,\n uint256 _primaryMarketId,\n uint256 _secondaryMarketId,\n address _traderAddress,\n uint256 _amountInWei,\n bytes memory _orderData\n ) internal pure returns (Actions.ActionArgs memory) {\n // internal trades calculate inputAmount based on `_toAccountId` (the maker account), so the sign should be\n // positive to reflect this\n return Actions.ActionArgs({\n actionType: Actions.ActionType.Trade,\n accountId: _fromAccountId,\n amount: Types.AssetAmount({\n sign: false,\n denomination: Types.AssetDenomination.Wei,\n ref: _amountInWei == ALL ? Types.AssetReference.Target : Types.AssetReference.Delta,\n value: _amountInWei == ALL ? 0 : _amountInWei\n }),\n primaryMarketId: _primaryMarketId,\n secondaryMarketId: _secondaryMarketId,\n otherAddress: _traderAddress,\n otherAccountId: _toAccountId,\n data: abi.encode(\n /* calculateAmountWithMakerAccount = */ false,\n _orderData\n )\n });\n }\n\n function encodeLiquidateAction(\n uint256 _solidAccountId,\n uint256 _liquidAccountId,\n uint256 _owedMarketId,\n uint256 _heldMarketId,\n uint256 _owedWeiToLiquidate\n ) internal pure returns (Actions.ActionArgs memory) {\n return Actions.ActionArgs({\n actionType: Actions.ActionType.Liquidate,\n accountId: _solidAccountId,\n amount: Types.AssetAmount({\n sign: true,\n denomination: Types.AssetDenomination.Wei,\n ref: Types.AssetReference.Delta,\n value: _owedWeiToLiquidate\n }),\n primaryMarketId: _owedMarketId,\n secondaryMarketId: _heldMarketId,\n otherAddress: address(0),\n otherAccountId: _liquidAccountId,\n data: new bytes(0)\n });\n }\n\n function encodeExternalSellAction(\n uint256 _fromAccountId,\n uint256 _primaryMarketId,\n uint256 _secondaryMarketId,\n address _trader,\n uint256 _amountInWei,\n uint256 _amountOutMinWei,\n bytes memory _orderData\n ) internal pure returns (Actions.ActionArgs memory) {\n return Actions.ActionArgs({\n actionType : Actions.ActionType.Sell,\n accountId : _fromAccountId,\n amount : Types.AssetAmount({\n sign : false,\n denomination : Types.AssetDenomination.Wei,\n ref : _amountInWei == ALL ? Types.AssetReference.Target : Types.AssetReference.Delta,\n value : _amountInWei == ALL ? 0 : _amountInWei\n }),\n primaryMarketId : _primaryMarketId,\n secondaryMarketId : _secondaryMarketId,\n otherAddress : _trader,\n otherAccountId : 0,\n data : abi.encode(_amountOutMinWei, _orderData)\n });\n }\n\n function encodeTransferAction(\n uint256 _fromAccountId,\n uint256 _toAccountId,\n uint256 _marketId,\n uint256 _amountWei\n ) internal pure returns (Actions.ActionArgs memory) {\n Types.AssetAmount memory assetAmount;\n if (_amountWei == uint(- 1)) {\n assetAmount = Types.AssetAmount({\n sign: true,\n denomination: Types.AssetDenomination.Wei,\n ref: Types.AssetReference.Target,\n value: 0\n });\n } else {\n assetAmount = Types.AssetAmount({\n sign: false,\n denomination: Types.AssetDenomination.Wei,\n ref: Types.AssetReference.Delta,\n value: _amountWei\n });\n }\n return Actions.ActionArgs({\n actionType : Actions.ActionType.Transfer,\n accountId : _fromAccountId,\n amount : assetAmount,\n primaryMarketId : _marketId,\n secondaryMarketId : 0,\n otherAddress : address(0),\n otherAccountId : _toAccountId,\n data : bytes(\"\")\n });\n }\n\n function encodeTransferToTargetAmountAction(\n uint256 _fromAccountId,\n uint256 _toAccountId,\n uint256 _marketId,\n Types.Wei memory _targetAmountWei\n ) internal pure returns (Actions.ActionArgs memory) {\n return Actions.ActionArgs({\n actionType : Actions.ActionType.Transfer,\n accountId : _fromAccountId,\n amount : Types.AssetAmount({\n sign: _targetAmountWei.sign,\n denomination: Types.AssetDenomination.Wei,\n ref: Types.AssetReference.Target,\n value: _targetAmountWei.value\n }),\n primaryMarketId : _marketId,\n secondaryMarketId : 0,\n otherAddress : address(0),\n otherAccountId : _toAccountId,\n data : bytes(\"\")\n });\n }\n\n function encodeWithdrawalAction(\n uint256 _accountId,\n uint256 _marketId,\n Types.AssetAmount memory _amount,\n address _toAccount\n ) internal pure returns (Actions.ActionArgs memory) {\n return Actions.ActionArgs({\n actionType: Actions.ActionType.Withdraw,\n accountId: _accountId,\n amount: _amount,\n primaryMarketId: _marketId,\n secondaryMarketId: 0,\n otherAddress: _toAccount,\n otherAccountId: 0,\n data: bytes(\"\")\n });\n }\n}\n",
"sourcePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/external/lib/AccountActionLib.sol",
"ast": {
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/external/lib/AccountActionLib.sol",
"exportedSymbols": {
"AccountActionLib": [
5819
]
},
"id": 5820,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 4966,
"literals": [
"solidity",
"^",
"0.5",
".7"
],
"nodeType": "PragmaDirective",
"src": "595:23:34"
},
{
"id": 4967,
"literals": [
"experimental",
"ABIEncoderV2"
],
"nodeType": "PragmaDirective",
"src": "619:33:34"
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IDolomiteMargin.sol",
"file": "../../protocol/interfaces/IDolomiteMargin.sol",
"id": 4969,
"nodeType": "ImportDirective",
"scope": 5820,
"sourceUnit": 24694,
"src": "654:80:34",
"symbolAliases": [
{
"foreign": 4968,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Account.sol",
"file": "../../protocol/lib/Account.sol",
"id": 4971,
"nodeType": "ImportDirective",
"scope": 5820,
"sourceUnit": 24886,
"src": "736:57:34",
"symbolAliases": [
{
"foreign": 4970,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Actions.sol",
"file": "../../protocol/lib/Actions.sol",
"id": 4973,
"nodeType": "ImportDirective",
"scope": 5820,
"sourceUnit": 25370,
"src": "794:57:34",
"symbolAliases": [
{
"foreign": 4972,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Require.sol",
"file": "../../protocol/lib/Require.sol",
"id": 4975,
"nodeType": "ImportDirective",
"scope": 5820,
"sourceUnit": 28453,
"src": "852:57:34",
"symbolAliases": [
{
"foreign": 4974,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Types.sol",
"file": "../../protocol/lib/Types.sol",
"id": 4977,
"nodeType": "ImportDirective",
"scope": 5820,
"sourceUnit": 31362,
"src": "910:53:34",
"symbolAliases": [
{
"foreign": 4976,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/external/interfaces/IExpiry.sol",
"file": "../interfaces/IExpiry.sol",
"id": 4979,
"nodeType": "ImportDirective",
"scope": 5820,
"sourceUnit": 4566,
"src": "965:52:34",
"symbolAliases": [
{
"foreign": 4978,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/external/lib/AccountBalanceLib.sol",
"file": "./AccountBalanceLib.sol",
"id": 4981,
"nodeType": "ImportDirective",
"scope": 5820,
"sourceUnit": 5892,
"src": "1019:60:34",
"symbolAliases": [
{
"foreign": 4980,
"local": null
}
],
"unitAlias": ""
},
{
"baseContracts": [],
"contractDependencies": [],
"contractKind": "library",
"documentation": "@title AccountActionLib\n@author Dolomite\n * Library contract that makes specific actions easy to call",
"fullyImplemented": true,
"id": 5819,
"linearizedBaseContracts": [
5819
],
"name": "AccountActionLib",
"nodeType": "ContractDefinition",
"nodes": [
{
"constant": true,
"id": 4984,
"name": "FILE",
"nodeType": "VariableDeclaration",
"scope": 5819,
"src": "1277:50:34",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_bytes32",
"typeString": "bytes32"
},
"typeName": {
"id": 4982,
"name": "bytes32",
"nodeType": "ElementaryTypeName",
"src": "1277:7:34",
"typeDescriptions": {
"typeIdentifier": "t_bytes32",
"typeString": "bytes32"
}
},
"value": {
"argumentTypes": null,
"hexValue": "4163636f756e74416374696f6e4c6962",
"id": 4983,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "string",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1309:18:34",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_stringliteral_cb611cb2c473ac6e7e3e9bc4eba34202a80736340900e1166f2b7bc309e36d5f",
"typeString": "literal_string \"AccountActionLib\""
},
"value": "AccountActionLib"
},
"visibility": "private"
},
{
"constant": true,
"id": 4990,
"name": "ALL",
"nodeType": "VariableDeclaration",
"scope": 5819,
"src": "1334:34:34",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4985,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1334:7:34",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": {
"argumentTypes": null,
"arguments": [
{
"argumentTypes": null,
"id": 4988,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"nodeType": "UnaryOperation",
"operator": "-",
"prefix": true,
"src": "1365:2:34",
"subExpression": {
"argumentTypes": null,
"hexValue": "31",
"id": 4987,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1366:1:34",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_1_by_1",
"typeString": "int_const 1"
},
"value": "1"
},
"typeDescriptions": {
"typeIdentifier": "t_rational_minus_1_by_1",
"typeString": "int_const -1"
}
}
],
"expression": {
"argumentTypes": [
{
"typeIdentifier": "t_rational_minus_1_by_1",
"typeString": "int_const -1"
}
],
"id": 4986,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"nodeType": "ElementaryTypeNameExpression",
"src": "1357:7:34",
"typeDescriptions": {
"typeIdentifier": "t_type$_t_uint256_$",
"typeString": "type(uint256)"
},
"typeName": "uint256"
},
"id": 4989,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "typeConversion",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "1357:11:34",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "internal"
},
{
"body": {
"id": 4997,
"nodeType": "Block",
"src": "1466:27:34",
"statements": [
{
"expression": {
"argumentTypes": null,
"id": 4995,
"name": "ALL",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4990,
"src": "1483:3:34",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"functionReturnParameters": 4994,
"id": 4996,
"nodeType": "Return",
"src": "1476:10:34"
}
]
},
"documentation": null,
"id": 4998,
"implemented": true,
"kind": "function",
"modifiers": [],
"name": "all",
"nodeType": "FunctionDefinition",
"parameters": {
"id": 4991,
"nodeType": "ParameterList",
"parameters": [],
"src": "1431:2:34"
},
"returnParameters": {
"id": 4994,
"nodeType": "ParameterList",
"parameters": [
{
"constant": false,
"id": 4993,
"name": "",
"nodeType": "VariableDeclaration",
"scope": 4998,
"src": "1457:7:34",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4992,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1457:7:34",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
}
],
"src": "1456:9:34"
},
"scope": 5819,
"src": "1419:74:34",
"stateMutability": "pure",
"superFunction": null,
"visibility": "internal"
},
{
"body": {
"id": 5063,
"nodeType": "Block",
"src": "1816:511:34",
"statements": [
{
"assignments": [
5017
],
"declarations": [
{
"constant": false,
"id": 5017,
"name": "accounts",
"nodeType": "VariableDeclaration",
"scope": 5063,
"src": "1826:30:34",
"stateVariable": false,
"storageLocation": "memory",
"typeDescriptions": {
"typeIdentifier": "t_array$_t_struct$_Info_$24851_memory_$dyn_memory_ptr",
"typeString": "struct Account.Info[]"
},
"typeName": {
"baseType": {
"contractScope": null,
"id": 5015,
"name": "Account.Info",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 24851,
"src": "1826:12:34",
"typeDescriptions": {
"typeIdentifier": "t_struct$_Info_$24851_storage_ptr",
"typeString": "struct Account.Info"
}
},
"id": 5016,
"length": null,
"nodeType": "ArrayTypeName",
"src": "1826:14:34",
"typeDescriptions": {
"typeIdentifier": "t_array$_t_struct$_Info_$24851_storage_$dyn_storage_ptr",
"typeString": "struct Account.Info[]"
}
},
"value": null,
"visibility": "internal"
}
],
"id": 5023,
"initialValue": {
"argumentTypes": null,
"arguments": [
{
"argumentTypes": null,
"hexValue": "31",
"id": 5021,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1878:1:34",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_1_by_1",
"typeString": "int_const 1"
},
"value": "1"
}
],
"expression": {
"argumentTypes": [
{
"typeIdentifier": "t_rational_1_by_1",
"typeString": "int_const 1"
}
],
"id": 5020,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"nodeType": "NewExpression",
"src": "1859:18:34",
"typeDescriptions": {
"typeIdentifier": "t_function_objectcreation_pure$_t_uint256_$returns$_t_array$_t_struct$_Info_$24851_memory_$dyn_memory_$",
"typeString": "function (uint256) pure returns (struct Account.Info memory[] memory)"
},
"typeName": {
"baseType": {
"contractScope": null,
"id": 5018,
"name": "Account.Info",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 24851,
"src": "1863:12:34",
"typeDescriptions": {
"typeIdentifier": "t_struct$_Info_$24851_storage_ptr",
"typeString": "struct Account.Info"
}
},
"id": 5019,
"length": null,
"nodeType": "ArrayTypeName",
"src": "1863:14:34",
"typeDescriptions": {
"typeIdentifier": "t_array$_t_struct$_Info_$24851_storage_$dyn_storage_ptr",
"typeString": "struct Account.Info[]"
}
}
},
"id": 5022,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "1859:21:34",
"typeDescriptions": {
"typeIdentifier": "t_array$_t_struct$_Info_$24851_memory_$dyn_memory",
"typeString": "struct Account.Info memory[] memory"
}
},
"nodeType": "VariableDeclarationStatement",
"src": "1826:54:34"
},
{
"expression": {
"argumentTypes": null,
"id": 5032,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftHandSide": {
"argumentTypes": null,
"baseExpression": {
"argumentTypes": null,
"id": 5024,
"name": "accounts",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 5017,
"src": "1890:8:34",
"typeDescriptions": {
"typeIdentifier": "t_array$_t_struct$_Info_$24851_memory_$dyn_memory_ptr",
"typeString": "struct Account.Info memory[] memory"
}
},
"id": 5026,
"indexExpression": {
"argumentTypes": null,
"hexValue": "30",
"id": 5025,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1899:1:34",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_0_by_1",
"typeString": "int_const 0"
},
"value": "0"
},
"isConstant": false,
"isLValue": true,
"isPure": false,
"lValueRequested": true,
"nodeType": "IndexAccess",
"src": "1890:11:34",
"typeDescriptions": {
"typeIdentifier": "t_struct$_Info_$24851_memory",
"typeString": "struct Account.Info memory"
}
},
"nodeType": "Assignment",
"operator": "=",
"rightHandSide": {
"argumentTypes": null,
"arguments": [
{
"argumentTypes": null,
"id": 5029,
"name": "_accountOwner",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 5002,
"src": "1938:13:34",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
{
"argumentTypes": null,
"id": 5030,
"name": "_toAccountNumber",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 5006,
"src": "1973:16:34",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
}
],
"expression": {
"argumentTypes": [
{
"typeIdentifier": "t_address",
"typeString": "address"
},
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
],
"expression": {
"argumentTypes": null,
"id": 5027,
"name": "Account",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 24885,
"src": "1904:7:34",
"typeDescriptions": {
"typeIdentifier": "t_type$_t_contract$_Account_$24885_$",
"typeString": "type(library Account)"
}
},
"id": 5028,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "Info",
"nodeType": "MemberAccess",
"referencedDeclaration": 24851,
"src": "1904:12:34",
"typeDescriptions": {
"typeIdentifier": "t_type$_t_struct$_Info_$24851_storage_ptr_$",
"typeString": "type(struct Account.Info storage pointer)"
}
},
"id": 5031,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "structConstructorCall",
"lValueRequested": false,
"names": [
"owner",
"number"
],
"nodeType": "FunctionCall",
"src": "1904:96:34",
"typeDescriptions": {
"typeIdentifier": "t_struct$_Info_$24851_memory",
"typeString": "struct Account.Info memory"
}
},
"src": "1890:110:34",
"typeDescriptions": {
"typeIdentifier": "t_struct$_Info_$24851_memory",
"typeString": "struct Account.Info memory"
}
},
"id": 5033,
"nodeType": "ExpressionStatement",
"src": "1890:110:34"
},
{
"assignments": [
5038
],
"declarations": [
{
"constant": false,
"id": 5038,
"name": "actions",
"nodeType": "VariableDeclaration",
"scope": 5063,
"src": "2011:35:34",
"stateVariable": false,
"storageLocation": "memory",
"typeDescriptions": {
"typeIdentifier": "t_array$_t_struct$_ActionArgs_$24930_memory_$