# Babypie's Architecture

<figure><img src="https://3268690364-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE3qNOoRhP5AIwVDg8APE%2Fuploads%2FA68sabhbLKeAxbLWNNLz%2F2024-08-12%2013.54.48.jpg?alt=media&#x26;token=9a670ba0-966b-4e4c-97ed-8bd37b1d8fcc" alt=""><figcaption></figcaption></figure>

**1. Register Wallet:** User sends the following values to the Babypie Manager:

* User’s BTC address
* User’s EVM address
* Signature generated using the Bitcoin wallet by passing the EVM address as the message.

<figure><img src="https://3268690364-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE3qNOoRhP5AIwVDg8APE%2Fuploads%2Ffr7BitjrpjRZ7bjo4tmn%2Fregistration.png?alt=media&#x26;token=ba31490a-c0fa-4b8a-bc4e-89b34305f836" alt=""><figcaption></figcaption></figure>

**2. Babypie Manager Action:** The Babypie Manager calls the Chainlink Functions Consumer contract, passing the three values it received from the user.

* Babypie Manager: One of Babypie’s smart contracts.
* Functions Consumer: A smart contract that can send Functions requests to the Chainlink Oracle Network, where the oracle network returns the results of decentralized computation.

**3. Chainlink Functions Consumer Contract Action:** The Chainlink Functions Consumer contract sends a request to the Chainlink DON to run the script to verify the user's signature, using the EVM address as the message string.

* [DON - Decentralized Oracle Network](https://docs.chain.link/chainlink-functions/resources/architecture)

**4. Verification Result:** The DON returns the result of the verification to the Chainlink Functions Consumer contract by calling it with the result (this process takes around 30 seconds).<br>

**5. Update User Mapping:** The Chainlink Functions Consumer contract calls the Babypie Manager contract to update the user's BTC to EVM mapping if the signature is valid.

### Now, the user can transfer native BTC to Babypie’s MPC wallet (This step can even be done by user before mapping their BTC->EVM address)<br>

**6. BTC Transfer:** The user calls the Babypie Manager with the transaction hash of the BTC transfer to Babypie’s MPC wallet and the BTC address used for the transfer.

<figure><img src="https://3268690364-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE3qNOoRhP5AIwVDg8APE%2Fuploads%2FC6P6FxXqq2sZTTCTWQ5H%2FTransfer%20BTC%20to%20Magpie%20wallet.png?alt=media&#x26;token=14acdbf0-62cb-4b4f-abb2-8c20d88cb557" alt=""><figcaption></figcaption></figure>

**7. Requests to initiate mBTC mint for BTC transfer:** User calls babypie manager to initiate verification of user's BTC transfer in txn and mint mBTC to user's mapped EVM address.

**8. Babypie Manager Action:** The Babypie Manager calls another Chainlink Functions Consumer contract with the transaction hash and the user’s BTC chain address.

**9. BTC Amount Retrieval:** The Chainlink Functions Consumer contract sends a request to the Chainlink DON to run a script that will get the amount of BTC transferred to the Babypie MPC wallet in the transaction.

**10. Amount Confirmation:** The Chainlink Functions Consumer contract receives the result (amount of BTC transferred) of the script from the Chainlink DON.

**11. Validation and Processing:** The Chainlink Functions Consumer contract checks if the amount is greater than 0. If yes, it calls the Babypie Manager with the result.

**12. Mark txn paid:** The Babypie Manager will mark the txn as paid and call the mint function of the mBTC contract with value equal to BTC transferred by user.

**13. mBTC mint:** mBTC token will be minted to the user.

<figure><img src="https://3268690364-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE3qNOoRhP5AIwVDg8APE%2Fuploads%2Fi1HyFR908yeWyDJatQma%2FClaim%20mBTC%20(1).png?alt=media&#x26;token=fe690659-e24b-4011-80e2-23bd3a768578" alt=""><figcaption></figcaption></figure>
