initialize() :
This function is used to initialize the BancorNetwork contract. It takes three parameters: an instance of the IBNTPool contract, an instance of the IPendingWithdrawals contract, and an instance of the IPoolMigrator contract. It then calls the __BancorNetwork_init function, which sets the addresses of the three contracts as internal variables. This allows the BancorNetwork contract to interact with the other contracts. (autogenerated documentation)
__BancorNetwork_init() :
This function is the initializer for the BancorNetwork contract. It is responsible for setting up the contract and its components, including the Upgradeable, ReentrancyGuard, and Pausable components. It also calls the __BancorNetwork_init_unchained function, which sets up the BNTPool, PendingWithdrawals, and PoolMigrator components. (autogenerated documentation)
__BancorNetwork_init_unchained() :
This function is used to initialize the Bancor Network smart contract. It sets up the BNT Pool, Pending Withdrawals, and Pool Migrator contracts, and assigns the roles of Migration Manager, Emergency Stopper, and Network Fee Manager to the admin. It also sets the depositingEnabled flag to true, allowing users to deposit funds into the Bancor Network. (autogenerated documentation)
_depositsEnabled() :
This function is used to check if deposits are enabled for a particular contract. It works by checking the boolean value of the _depositingEnabled variable. If the value is false, the function will revert with an error message. Otherwise, it will allow the deposit to proceed. (autogenerated documentation)
version() :
This function is an override of the IVersioned and Upgradeable contracts. It returns a version number (in this case, 7) which is used to track the version of the contract. This allows for the contract to be upgraded and for users to know which version of the contract they are interacting with. (autogenerated documentation)
roleMigrationManager() :
This function is a getter function that returns the bytes32 value of the ROLE_MIGRATION_MANAGER constant. This constant is used to define the role of the Migration Manager, which is responsible for managing the migration of data from one system to another. The function simply returns the value of the constant, allowing other functions to access it. (autogenerated documentation)
roleEmergencyStopper() :
This function returns the bytes32 value of the ROLE_EMERGENCY_STOPPER constant. This constant is used to identify the role of an address that has the ability to stop the contract in an emergency situation. This function is declared as external and pure, meaning that it does not modify the state of the contract and does not interact with the blockchain. (autogenerated documentation)
roleNetworkFeeManager() :
This function returns the bytes32 value of the ROLE_NETWORK_FEE_MANAGER constant. This constant is used to identify the role of a user as a network fee manager, which allows them to manage the fees associated with transactions on the network. (autogenerated documentation)
pendingNetworkFeeAmount() :
This function returns the amount of pending network fees. It works by accessing the _pendingNetworkFeeAmount variable, which stores the amount of pending network fees, and returning its value. (autogenerated documentation)
registerPoolCollection() :
This function registers a new PoolCollection contract with the PoolManager contract. It first checks that the address of the new PoolCollection is valid and that the caller is the admin. It then checks that the PoolCollection is not already registered by searching for it in the _poolCollections mapping. If it is not found, it is added to the mapping and the _setAccessRoles function is called to set the access roles for the new PoolCollection. Finally, an event is emitted to signal that the PoolCollection has been added. (autogenerated documentation)
unregisterPoolCollection() :
This function unregisters a PoolCollection contract from the PoolManager. It first checks that the PoolCollection is not empty, and then removes it from the list of registered PoolCollections. It then sets the access roles for the PoolCollection to false, and emits an event to signal that the PoolCollection has been removed. (autogenerated documentation)
poolCollections() :
This function is used to retrieve a list of all the IPoolCollection contracts that have been deployed on the blockchain. It does this by looping through the _poolCollections array, which stores the addresses of all the IPoolCollection contracts, and creating a new array of IPoolCollection objects with the same length as the _poolCollections array. It then returns this new array. (autogenerated documentation)
liquidityPools() :
This function is used to retrieve a list of all the liquidity pools stored in the smart contract. It takes no parameters and returns an array of Token objects. It does this by looping through the _liquidityPools array and creating a new Token object for each entry in the array. The Token objects are then added to the list array which is then returned. (autogenerated documentation)
collectionByPool() :
This function returns an IPoolCollection object associated with a given Token pool. It works by accessing the _collectionByPool mapping, which stores the IPoolCollection object associated with each Token pool. (autogenerated documentation)
createPools() :
This function creates pools in a given IPoolCollection contract. It takes an array of Token contracts as an argument and loops through them, calling the _createPool() function for each one. The _createPool() function is responsible for creating the pool and adding it to the IPoolCollection contract. The function is only accessible to the admin of the contract and requires a valid address for the IPoolCollection contract. It also has a non-reentrant modifier to prevent re-entrancy attacks. (autogenerated documentation)
_createPool() :
This function creates a new pool for a given token. It first checks that the token is a valid address and that it is not the BNT token. It then adds the token to the list of liquidity pools and creates a new pool collection for it. Finally, it emits two events, PoolCreated and PoolAdded, to notify the rest of the system that a new pool has been created. (autogenerated documentation)
migratePools() :
This function is used to migrate pools from one IPoolCollection to another. It takes an array of Token pools and an IPoolCollection as parameters. It then iterates through the array of pools and calls the migratePool() function from the _poolMigrator contract to migrate each pool to the new IPoolCollection. It then updates the _collectionByPool mapping to reflect the new IPoolCollection for each pool and emits PoolRemoved and PoolAdded events. (autogenerated documentation)
depositFor(address,uint256) :
This function allows a user to deposit a specified amount of tokens into a pool contract. The function requires the address of the provider, the address of the pool, and the amount of tokens to be deposited. The function also checks that the address of the provider and the pool are valid, that the amount of tokens is greater than zero, that the contract is not paused, and that the function is not being re-entered. If all of these conditions are met, the function will return the amount of tokens deposited. (autogenerated documentation)
deposit(uint256) :
This function allows users to deposit a specified amount of tokens into a token pool. It requires that deposits are enabled, the address of the pool is valid, the token amount is greater than zero, the contract is not paused, and that the function is not reentrant. The function returns the amount of tokens deposited. (autogenerated documentation)
initWithdrawal(uint256) :
This function allows a user to initiate a withdrawal from the pool. It takes two parameters: an IPoolToken contract address and a uint256 amount of pool tokens. It checks that the address is valid, that the amount is greater than zero, that the contract is not paused, and that the function is not being re-entered. If all of these conditions are met, it calls the internal _initWithdrawal function, passing in the user's address and the two parameters. This function then sets the user's withdrawal amount and marks the withdrawal as pending. (autogenerated documentation)
cancelWithdrawal(uint256) :
This function allows a user to cancel a pending withdrawal from their account. It takes an id parameter, which is the unique identifier of the withdrawal, and uses the _pendingWithdrawals mapping to cancel the withdrawal. The function returns the amount of the withdrawal that was cancelled. (autogenerated documentation)
withdraw(uint256) :
This function allows a user to withdraw a specified amount of tokens from the pool. It takes an id as an argument, which is used to identify the withdrawal request. The function first checks the sender address to ensure that it is the same as the address that made the withdrawal request. It then uses the _withdrawContextId() function to generate a unique identifier for the withdrawal request. The _pendingWithdrawals.completeWithdrawal() function is then used to complete the withdrawal request. If the pool token is BNT, the _withdrawBNT() function is used to transfer the tokens to the user's address. Otherwise, the _withdrawBaseToken() function is used to transfer the tokens. (autogenerated documentation)
tradeBySourceAmount(uint256,uint256,uint256,address) :
This function allows a user to trade tokens from one token to another. The user specifies the source token, the target token, the source amount, the minimum return amount, the deadline, and the beneficiary. The function verifies the trade parameters, and then calls the _trade function to execute the trade. The _trade function takes in the trade tokens, trade parameters, trader info, and the deadline as parameters. (autogenerated documentation)
tradeByTargetAmount(uint256,uint256,uint256,address) :
This function allows a user to trade one token for another token, based on a target amount of the target token. The user must specify the source token, the target token, the target amount of the target token, the maximum amount of the source token, a deadline, and a beneficiary. The function verifies the trade parameters, and then calls the _trade function, passing in the trade tokens, trade parameters, trader info, and deadline. The _trade function then executes the trade, and returns the amount of the source token that was traded. (autogenerated documentation)
flashLoan(uint256) :
This function allows a user to borrow a certain amount of a given token from the Master Vault and then transfer it to a recipient. The user pays a fee for the loan, which is calculated as a percentage of the loan amount. The function then checks if the token is whitelisted, withdraws the funds from the Master Vault, calls the recipient's onFlashLoan function, and then returns the borrowed funds to the Master Vault. Finally, it emits an event to indicate that the flash loan has been completed. (autogenerated documentation)
migrateLiquidity(address,uint256,uint256,uint256) :
This function allows a user to migrate liquidity from one token to another. It takes in the token to be migrated, the provider address, the amount to be migrated, the available amount, and the original amount. It then calculates a contextId based on the parameters passed in and calls either the _depositBNTFor or _depositBaseTokenFor function depending on the token being migrated. Finally, it emits a FundsMigrated event with the contextId, token, provider, amount, available amount, and original amount. (autogenerated documentation)
withdrawNetworkFees(address) :
This function allows the Network Fee Manager to withdraw the pending network fees from the Bancor Network. It first checks if there are any pending network fees, and if there are, it sets the pending network fee amount to 0 and withdraws the funds from the Master Vault to the recipient address. Finally, it emits an event to log the withdrawal and returns the amount of network fees withdrawn. (autogenerated documentation)
pause() :
This function pauses the contract by calling the _pause() function. It can only be called by a user with the ROLE_EMERGENCY_STOPPER role. This role is typically assigned to a trusted user or group of users who can pause the contract in the event of an emergency. (autogenerated documentation)
resume() :
This function resumes the contract by calling the internal _unpause() function. It can only be called by a member with the ROLE_EMERGENCY_STOPPER role. This role is used to ensure that only authorized members can resume the contract. (autogenerated documentation)
depositingEnabled() :
This function is a view function that returns a boolean value indicating whether or not deposits are enabled. It works by accessing the internal state variable "_depositingEnabled" and returning its value. (autogenerated documentation)
enableDepositing(bool) :
This function enables or disables the ability to deposit funds into the contract. It can only be called by an admin and takes a boolean parameter to indicate whether depositing should be enabled or disabled. If the status is the same as the current status, the function does nothing. Otherwise, it sets the _depositingEnabled variable to the new status. (autogenerated documentation)
_depositContextId(address,uint256,address) :
This function is a private view function that takes in an address of a provider, a Token pool, a uint256 token amount, and an address of a caller. It returns a bytes32 value that is the keccak256 hash of the parameters passed in. This function is used to generate a unique identifier for a deposit context, which is used to track deposits and withdrawals. (autogenerated documentation)
_withdrawContextId(uint256,address) :
This function is used to generate a unique identifier for a given context. It takes an id (uint256) and a caller (address) as parameters and returns a bytes32 value. The function works by taking the caller address, the current time, and the id and combining them using the keccak256 hashing algorithm. This generates a unique identifier that can be used to identify the context. (autogenerated documentation)
_depositFor(address,uint256,address) :
This function is used to deposit tokens into a pool. It takes in the address of the provider, the token pool, the amount of tokens to deposit, and the address of the caller. It first generates a context ID based on the parameters provided. If the pool is BNT, it calls the _depositBNTFor function, otherwise it calls the _depositBaseTokenFor function. Both of these functions are used to deposit tokens into the pool, with the _depositBaseTokenFor function also allowing for the caller to specify a different amount of tokens to receive in return. (autogenerated documentation)
_depositBNTFor(bytes32,address,uint256,address,bool,uint256) :
This function is used to deposit BNT tokens into a pool for a given context ID, provider, and BNT amount. It first checks that the msg.value is 0, then it transfers the BNT amount from the caller to the BNT pool. Finally, it calls the depositFor function on the BNT pool, passing in the context ID, provider, BNT amount, isMigrating flag, and original amount. (autogenerated documentation)
_depositBaseTokenFor(bytes32,address,uint256,address,uint256) :
This function is used to deposit a base token into a pool for a given contextId, provider, and pool. It first deposits the available amount of the token into the master vault, and then deposits the tokenAmount into the poolCollection for the given contextId, provider, and pool. It returns the amount of the token deposited. (autogenerated documentation)
_withdrawBNT(bytes32,address) :
This function is used to withdraw BNT from the BNT Pool. It takes in three parameters: a contextId, a provider address, and a CompletedWithdrawal memory. It first retrieves the IBNTPool contract from the _bntPool variable. It then transfers the poolToken from the _pendingWithdrawals address to the IBNTPool contract. It then transfers the VBNT from the provider address to the IBNTPool contract. Finally, it calls the withdraw function on the IBNTPool contract, passing in the contextId, provider address, poolTokenAmount, and reserveTokenAmount from the CompletedWithdrawal memory. The function returns the amount of BNT withdrawn. (autogenerated documentation)
_withdrawBaseToken(bytes32,address) :
This function is used to withdraw a base token from a pool. It takes in a contextId, provider address, and a CompletedWithdrawal memory object as parameters. It first creates a Token object from the CompletedWithdrawal memory object, and then creates an IPoolCollection object from the Token object. It then transfers the pool token amount from the pendingWithdrawals address to the poolCollection address. Finally, it calls the withdraw function on the poolCollection object, passing in the contextId, provider address, pool token, pool token amount, and reserve token amount as parameters. (autogenerated documentation)
_verifyTradeParams(uint256,uint256,uint256) :
This function is used to verify the parameters of a trade. It checks that the source and target tokens are valid addresses, that the source and target tokens are not the same, that the amount, limit, and deadline are all greater than zero, and that the deadline has not expired. (autogenerated documentation)
_trade(uint256) :
This function is used to facilitate a trade between two tokens, using Bancor Network as an intermediary. It takes in a set of tokens to be traded, trade parameters, trader information, and a deadline, and returns the amount of the target token that was traded. The function first checks if the beneficiary is set to 0, and if so, sets it to the trader. It then calculates a context ID based on the trade parameters and trader information. If the source token is BNT, it calls the _tradeBNT function to execute the trade, and emits a TokensTraded event with the relevant information. If the target token is BNT, it calls the _tradeBNT function to execute (autogenerated documentation)
_tradeBNT(bytes32,bool) :
This function is used to trade BNT tokens. It takes in a contextId, a pool, a boolean value indicating whether the trade is from BNT, and a TradeParams memory object containing the amount and limit of the trade. It then creates a TradeTokens memory object containing the source and target tokens of the trade. It then uses the _poolCollection function to calculate the trade amounts and fees, and if the trade is not from BNT, it calls the onFeesCollected function to collect the fees. Finally, it returns a TradeResult memory object containing the source and target amounts, as well as the trading and network fees. (autogenerated documentation)
_tradeBaseTokens(bytes32) :
This function is used to trade between two tokens, using Bancor Network Token (BNT) as an intermediary. It takes in a contextId, two tokens to trade between, and a set of trade parameters. Depending on the parameters, it will either trade from the source token to the target token, or from the target token to the source token. In either case, it will use BNT as an intermediary. The function will first trade from the source token to BNT, and then from BNT to the target token. It will return two TradeResult objects, one for each hop of the trade. (autogenerated documentation)
_depositToMasterVault(address,uint256) :
This function is used to deposit tokens or Ether into the Master Vault. It first checks if the token is native (Ether) or not. If it is native, it checks if the amount sent is equal to the amount specified. If it is, it sends the amount to the Master Vault and sends any remaining Ether back to the caller. If the token is not native, it checks if any Ether was sent and reverts if it was. It then transfers the specified amount of tokens from the caller to the Master Vault. (autogenerated documentation)
_poolCollection() :
This function is a private view function that retrieves the IPoolCollection associated with a given Token. It takes in a Token as an argument and returns an IPoolCollection. It first checks if the address of the IPoolCollection associated with the Token is valid, and if it is, it returns the IPoolCollection. If the address is not valid, it reverts with an InvalidToken error. (autogenerated documentation)
_initWithdrawal(address,uint256) :
This function is used to initiate a withdrawal from a pool. It takes in three parameters: the address of the provider, the IPoolToken contract, and the amount of pool tokens to be withdrawn. It first checks that the pool token is valid, and then transfers the pool token amount from the provider to the pending withdrawals contract. Finally, it calls the initWithdrawal function of the pending withdrawals contract, passing in the provider address, the pool token contract, and the amount of pool tokens to be withdrawn. (autogenerated documentation)
_setAccessRoles(bool) :
This function sets or revokes access roles for a given IPoolCollection contract. It does this by granting or revoking the ROLE_BNT_MANAGER, ROLE_VAULT_MANAGER, ROLE_FUNDING_MANAGER, ROLE_ASSET_MANAGER roles from the _bntPool, _masterVault, and _externalProtectionVault contracts. The function takes in a boolean parameter to determine whether to set or revoke the roles. (autogenerated documentation)
_findPoolCollection(uint16,uint16) :
This function is used to find a pool collection based on the pool type and version. It iterates through the list of pool collections stored in the _poolCollections array and checks if the pool type and version match the parameters passed in. If a match is found, the pool collection is returned. If no match is found, an address of 0 is returned. (autogenerated documentation)