> For the complete documentation index, see [llms.txt](https://docs.sorrelbanq.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sorrelbanq.org/smart-contracts/bank-depository.md).

# Bank Depository

Mainnet\
<https://tronscan.org/#/contract/TMrak7rc3XnJykLwGfi1JkHooLfjbwibFc>

Nile\
<https://nile.tronscan.org/#/contract/TUR4za3qj9bZed33hJc9oBQrwTEz8JMq36>

Github\
<https://github.com/Paracosm-Labs/sorrel-contracts/blob/main/BankDepository.sol>

The `BankDepository` contract is a smart contract that facilitates the deposit, withdrawal, transfer, and exchange of gStable tokens. Here's an explanation of the contract's main functionalities:

1. `usddId`: This variable stores the ID of the USDD stablecoin.
2. `gStableTotalValueMap`: This mapping keeps track of the total value of gStable tokens for each gStable ID.
3. `gStableBalanceMap`: This mapping keeps track of the balance of gStable tokens for each gStable ID and user address.
4. `gStableAccumulatedFeeMap`: This mapping tracks the accumulated fees for each gStable ID.
5. `deposit`: This function allows users to deposit gStable tokens into the contract. It transfers the tokens from the user to the contract, deducts the fees, and updates the balances and total values accordingly.
6. `withdraw`: This function enables users to withdraw their gStable tokens from the contract. It deducts the requested amount from the user's balance, updates the total value, and transfers the tokens back to the user, after deducting the withdrawal fees.
7. `send`: This function allows users to send gStable tokens to another address. It deducts the tokens from the sender's balance, adds them to the recipient's balance (after deducting fees), and updates the accumulated fees.
8. `exchange`: This function allows users to exchange gStable tokens for another gStable token. It deducts the tokens from the sender's balance, calculates the equivalent amount of tokens for the target gStable token, updates the balances and accumulated fees, and mints/burns the necessary tokens based on the exchange rate.
9. `exchangeGL`: This function allows the admin to perform an exchange of gStable tokens on behalf of a user. It follows a similar logic to the `exchange` function but is only accessible to the admin.
10. `moveGL`: This function allows the admin to transfer gStable tokens from one user to another. It deducts the tokens from the sender's balance, adds them to the recipient's balance (after deducting fees), and updates the accumulated fees.
11. `claim`: This function allows the admin to claim rewards on behalf of users. It interacts with another contract (`rewards`) to claim the rewards and transfers the claimed USDD tokens to the admin.
12. Various modifiers and events are used to control access, validate inputs, and emit relevant events for deposit, withdrawal, transfer, exchange, and claim operations.

The contract also includes some setter functions (`setRewards`, `setUsddId`, `setGStableLookup`, and `setFeeBasisPoint`) to set various parameters and addresses, as well as functions to pause and unpause the contract. Additionally, the contract inherits from several other contracts (`AdminAuth`, `Pausable`, and `ReentrancyGuard`) to provide additional functionality related to administration, pausing, and preventing reentrancy attacks.

*Explanation Generated by Sorrel's AIA Team  - Powered by ChatGPT*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sorrelbanq.org/smart-contracts/bank-depository.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
