{
  "id": "8AjLzeTXybWpR0UN",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Yeild Automation in Aave",
  "tags": [],
  "nodes": [
    {
      "id": "33e07d60-e67a-4c12-8410-04478afdcce3",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -176,
        256
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "04eab5ea-3c7a-4304-8922-eff9b7c8a0a4",
      "name": "Calculate Excess Funds",
      "type": "n8n-nodes-base.code",
      "position": [
        944,
        -256
      ],
      "parameters": {
        "jsCode": "const excessFunds = parseInt($('Check User\\'s USDC Balance').first().json.response) - parseInt($('Savings Configs').first().json.moveToSavingsThreshold)\n\n$input.first().json.excessFunds = excessFunds;\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "0783f25f-3d7f-4da3-8c51-13c6d4809725",
      "name": "Deposit Confirmation",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2064,
        -368
      ],
      "parameters": {
        "text": "=Excess funds in your wallet (`{{ $('Savings Configs').item.json.delegator }}`) have been moved to Aave (tx hash: `{{ $('Aave Supply').item.json.transactionHash }}`). \n\nYour wallet balance is now `${{ parseInt($('Confirm User\\'s USDC Balance After Deposit').item.json.response)/1000000 }}` and you have `${{ parseInt($('Confirm User\\'s Aave Savings After Deposit').item.json.response)/1000000 }}` saved in Aave.",
        "chatId": "={{ $('Savings Configs').first().json.telegramChatId }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4ca79fe8-8113-477e-99a2-a39b2ecc9663",
      "name": "Calculate Insufficient Funds",
      "type": "n8n-nodes-base.code",
      "position": [
        944,
        256
      ],
      "parameters": {
        "jsCode": "const fundGap = parseInt($('Savings Configs').first().json.topOffBalance) - parseInt($('Check User\\'s USDC Balance').first().json.response)\n\n// withdraw enough saving to put us halfway between the upper and lower balance settings\n// the amount must be an Integer, so floor it to be sure\nlet withdrawAmount = Math.floor((parseInt($('Savings Configs').first().json.moveToSavingsThreshold) - parseInt($('Savings Configs').first().json.topOffBalance))/2) + fundGap\n\n// if there are not enough savings, move as much as you can\nif (withdrawAmount > parseInt($('Check User\\'s Aave Savings').first().json.response)) {\n  withdrawAmount = parseInt($('Check User\\'s Aave Savings').first().json.response)\n}\n\n$input.first().json.fundGap = fundGap;\n$input.first().json.withdrawAmount = withdrawAmount;\n\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "de95239f-cd59-4e77-9120-2f2a0ac43ac1",
      "name": "Withdraw from Aave",
      "type": "n8n-nodes-1shot.oneShotSynch",
      "notes": "Point this node at the 'withdraw' function on the Aave: Pool (Base) contract.",
      "onError": "continueRegularOutput",
      "position": [
        1392,
        160
      ],
      "parameters": {
        "params": "={\n  \"asset\": \"{{ $('Savings Configs').first().json.token }}\",\n  \"amount\": \"{{ $('Calculate Insufficient Funds').first().json.withdrawAmount }}\",\n  \"to\": \"{{ $('Savings Configs').first().json.delegator }}\"\n}",
        "operation": "executeAsDelegator",
        "additionalFields": {
          "memo": "=Aave Withdraw: {{ $json.withdrawAmount }}",
          "gasLimit": "500000"
        },
        "contractMethodId": "={{ $('Savings Configs').first().json.contractMethodIds.aavePoolWithdraw }}",
        "delegatorWalletAddress": "={{ $('Savings Configs').first().json.delegator }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9bd29b2e-f6a2-4645-80c1-784a6cb7d40d",
      "name": "Withdraw Confirmation",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2064,
        64
      ],
      "parameters": {
        "text": "=You wallet (`{{ $('Savings Configs').item.json.delegator }}`) has been topped off from your Aave savings (tx hash: `{{ $('Withdraw from Aave').item.json.transactionHash }}`).\n\nYour wallet balance is `${{ parseInt($('Confirm User\\'s USDC Balance After Withdraw').item.json.response)/1000000 }}` and you have `${{ parseInt($('Confirm User\\'s Aave Savings After Withdraw').item.json.response)/1000000 }}` in savings in Aave.",
        "chatId": "={{ $('Savings Configs').first().json.telegramChatId }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0136bd67-16f3-48a8-a8ce-1911124b4872",
      "name": "Savings Configs",
      "type": "n8n-nodes-base.code",
      "position": [
        48,
        256
      ],
      "parameters": {
        "jsCode": "// Any USDC balance above this gets stored in Aave\nconst moveToSavingsThreshold = 8.50; // set limit in USD\n\n// If your balance drops below this, move funds from Aave into your account\n// IMPORTANT: this value must be less that moveToSavingsThreshold\nconst topOffBalance = 8.21; // set limit in USD\n\nconst delegator = \"0x9fead8b19c044c2f404dac38b925ea16adaa2954\"; // your delegated wallet address.\nconst telegramChatId = ; // the chat id between you and your Telegram bot\n\nconst token = \"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913\" // USDC on Base\nconst pool = \"0xA238Dd80C259a72e81d7e4664a9801593F98d1c5\" // L2Pool on Base\n\n// get your contract method ids from the subworkflow or the 1Shot API portal\nconst contractMethodIds = {\n  \"usdcBalanceOf\": \"\",\n  \"usdcApprove\": \"\",\n  \"aBasUSDCBalanceOf\": \"\",\n  \"aavePoolSupply\": \"\",\n  \"aavePoolWithdraw\": \"\"\n}\n\n$input.first().json.moveToSavingsThreshold = moveToSavingsThreshold * 1000000; // convert to atomic units\n$input.first().json.topOffBalance = topOffBalance * 1000000; // convert to atomic units\n$input.first().json.delegator = delegator;\n$input.first().json.token = token;\n$input.first().json.pool = pool;\n$input.first().json.telegramChatId = telegramChatId;\n$input.first().json.contractMethodIds = contractMethodIds;\n\nreturn $input.all();\n"
      },
      "typeVersion": 2
    },
    {
      "id": "1bf93721-2196-4d23-9ff2-1724f900b800",
      "name": "Check User's Aave Savings",
      "type": "n8n-nodes-1shot.oneShot",
      "notes": "Point this node at the 'balanceOf' function on aBasUSDC.",
      "position": [
        496,
        256
      ],
      "parameters": {
        "params": "={\n  \"user\": \"{{ $('Savings Configs').item.json.delegator }}\"\n} ",
        "operation": "read",
        "contractMethodId": "={{ $('Savings Configs').item.json.contractMethodIds.aBasUSDCBalanceOf }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5d6ffab1-cefb-448a-b386-f5acd50492ec",
      "name": "Check User's USDC Balance",
      "type": "n8n-nodes-1shot.oneShot",
      "notes": "Point this node at the 'balanceOf' funcion on USDC.",
      "position": [
        272,
        256
      ],
      "parameters": {
        "params": "={\n  \"account\": \"{{ $('Savings Configs').item.json.delegator }}\"\n} ",
        "operation": "read",
        "contractMethodId": "={{ $('Savings Configs').first().json.contractMethodIds.usdcBalanceOf }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5414557b-baa2-41b5-981c-c5df8edb445a",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        720,
        240
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "deposit",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b2cc4c9d-6b1a-42bb-8506-cbc085b354e4",
                    "operator": {
                      "type": "number",
                      "operation": "gt"
                    },
                    "leftValue": "={{ parseInt($('Check User\\'s USDC Balance').item.json.response) }}",
                    "rightValue": "={{ $('Savings Configs').item.json.moveToSavingsThreshold }}"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "withdraw",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d647444f-1efd-49a8-8319-47c9780e39b1",
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    },
                    "leftValue": "={{ parseInt($('Check User\\'s USDC Balance').item.json.response) }}",
                    "rightValue": "={{ $('Savings Configs').item.json.topOffBalance }}"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "087c1edd-24ee-4220-bc06-2c395e94e05f",
      "name": "No Change, Send Account Status",
      "type": "n8n-nodes-base.telegram",
      "position": [
        944,
        448
      ],
      "parameters": {
        "text": "=Your current account balance is `${{ parseInt($('Check User\\'s USDC Balance').item.json.response)/1000000 }}` and you have `${{ parseInt($('Check User\\'s Aave Savings').item.json.response)/1000000 }}` saved in Aave.",
        "chatId": "={{ $('Savings Configs').first().json.telegramChatId }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "37406636-1307-4e61-817d-5b1f26fd155b",
      "name": "Insufficient Savings Warning",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1392,
        352
      ],
      "parameters": {
        "text": "=Your current account balance is `${{ parseInt($('Check User\\'s USDC Balance').item.json.response)/1000000 }}` and you have `${{ parseInt($('Check User\\'s Aave Savings').item.json.response)/100000 }}` saved in Aave.",
        "chatId": "={{ $('Savings Configs').first().json.telegramChatId }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0cb12444-efb1-4941-bb7d-377767f8f37b",
      "name": "Deposit Failure Notification",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1616,
        -160
      ],
      "parameters": {
        "text": "Aave Deposit failed",
        "chatId": "={{ $('Savings Configs').first().json.telegramChatId }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "25de21c3-6983-4c74-9dd1-b62ccf1868b5",
      "name": "Withdraw Failure Notification",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1616,
        256
      ],
      "parameters": {
        "text": "=\u274c Aave withdraw failed. \n\nYour wallet balance is `${{ parseInt($('Check User\\'s USDC Balance').item.json.response)/1000000 }}` and you have `${{ parseInt($('Check User\\'s Aave Savings').item.json.response)/1000000 }}`",
        "chatId": "={{ $('Savings Configs').first().json.telegramChatId }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "53d90579-4e6c-4fa6-bba7-f70beb90d0fd",
      "name": "Confirm User's USDC Balance After Withdraw",
      "type": "n8n-nodes-1shot.oneShot",
      "notes": "Point this node at the 'balanceOf' function on USDC.",
      "position": [
        1616,
        64
      ],
      "parameters": {
        "params": "={\n  \"account\": \"{{ $('Savings Configs').item.json.delegator }}\"\n} ",
        "operation": "read",
        "contractMethodId": "={{ $('Savings Configs').first().json.contractMethodIds.usdcBalanceOf }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "05e23943-4659-4b85-a2e6-afa2966d722d",
      "name": "Confirm User's Aave Savings After Withdraw",
      "type": "n8n-nodes-1shot.oneShot",
      "notes": "Point this node at the 'balanceOf' function on aBasUSDC.",
      "position": [
        1840,
        64
      ],
      "parameters": {
        "params": "={\n  \"user\": \"{{ $('Savings Configs').item.json.delegator }}\"\n} ",
        "operation": "read",
        "contractMethodId": "={{ $('Savings Configs').item.json.contractMethodIds.aBasUSDCBalanceOf }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "64d40482-5e9b-415f-90df-e98a6c2170bd",
      "name": "Confirm User's USDC Balance After Deposit",
      "type": "n8n-nodes-1shot.oneShot",
      "notes": "Point this node at the 'balanceOf' function on USDC.",
      "position": [
        1616,
        -368
      ],
      "parameters": {
        "params": "={\n  \"account\": \"{{ $('Savings Configs').item.json.delegator }}\"\n} ",
        "operation": "read",
        "contractMethodId": "={{ $('Savings Configs').first().json.contractMethodIds.usdcBalanceOf }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "46a48628-53d2-46f1-a225-f56fa559da33",
      "name": "Confirm User's Aave Savings After Deposit",
      "type": "n8n-nodes-1shot.oneShot",
      "notes": "Point this node at the 'balanceOf' function on aBasUSDC.",
      "position": [
        1840,
        -368
      ],
      "parameters": {
        "params": "={\n  \"user\": \"{{ $('Savings Configs').item.json.delegator }}\"\n} ",
        "operation": "read",
        "contractMethodId": "={{ $('Savings Configs').item.json.contractMethodIds.aBasUSDCBalanceOf }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2c822ad6-15e3-48c1-a6c4-257c44b62c0c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        704
      ],
      "parameters": {
        "color": 3,
        "width": 1888,
        "height": 656,
        "content": "## Set up a 1Shot API Wallet & Import Required Methods:\n\nClick the sub-workflow trigger to setup you 1Shot API account with a server wallet and all required smart contract methods needed for range trading. You only need to run this once."
      },
      "typeVersion": 1
    },
    {
      "id": "8c970843-dc30-403e-a180-f0829d843066",
      "name": "List wallets",
      "type": "n8n-nodes-1shot.oneShot",
      "position": [
        480,
        1008
      ],
      "parameters": {
        "chainId": 8453,
        "resource": "wallets"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "e8fadb8b-3d55-4e1d-a0c8-3c697216a986",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        256,
        1008
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "bcdf03f7-750f-43ee-ae81-117be14996a6",
      "name": "Get Wallet ID",
      "type": "n8n-nodes-base.code",
      "position": [
        1152,
        1008
      ],
      "parameters": {
        "jsCode": "let walletId; \ntry {\n  walletId = $input.first().json.id;\n} catch {\n  walletId = $input.first().json.id;\n}\n\n$input.first().json.walletId = walletId; \n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "a78f994d-7621-4bb3-a6e2-8c1490d9340f",
      "name": "Assure aBasUSDC",
      "type": "n8n-nodes-1shot.oneShot",
      "position": [
        1376,
        816
      ],
      "parameters": {
        "chainId": 8453,
        "promptId": "020932d3-63e6-42a9-9ed3-786661b1d67f",
        "walletId": "={{ $('Get Wallet ID').item.json.walletId }}",
        "operation": "assureContractMethodsFromPrompt",
        "contractAddress": "0x4e65fE4DbA92790696d040ac24Aa414708F5c0AB"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8e629117-c43e-4bf9-98c5-6a0c2af8adde",
      "name": "Assure Aave: Pool Proxy (Base)",
      "type": "n8n-nodes-1shot.oneShot",
      "position": [
        1376,
        1008
      ],
      "parameters": {
        "chainId": 8453,
        "promptId": "0cff57e8-6f36-4d93-8025-45f0db5835ee",
        "walletId": "={{ $('Get Wallet ID').item.json.walletId }}",
        "operation": "assureContractMethodsFromPrompt",
        "contractAddress": "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "25eb457b-a210-4acf-9c4e-f7b3098912ff",
      "name": "Assure USDC (Base)",
      "type": "n8n-nodes-1shot.oneShot",
      "position": [
        1376,
        1200
      ],
      "parameters": {
        "chainId": 8453,
        "promptId": "e087662d-154a-4810-bebf-327a950e2414",
        "walletId": "={{ $('Get Wallet ID').item.json.walletId }}",
        "operation": "assureContractMethodsFromPrompt",
        "contractAddress": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "deda5d06-abfe-4637-b47b-5891ff9d0b37",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -256,
        -32
      ],
      "parameters": {
        "width": 480,
        "height": 448,
        "content": "## Set Your Savings Thresholds\n\nClick on the `Savings Configs` node and set:\n\n1. The threshold where excess funds in your wallet are stored in Aave.\n2. The threshold below where funds are removed from Aave and put back into your wallet.\n3. Your wallet address that you have delegated to 1Shot API.\n4. The Telegram chat ID of you bot to receive notifications.\n5. How often to rebalance."
      },
      "typeVersion": 1
    },
    {
      "id": "6c828556-e624-4447-a322-900cebfd77d8",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -672
      ],
      "parameters": {
        "width": 816,
        "height": 384,
        "content": "## Setup Instructions\n\nThis workflow will automatically balance your USDC funds on Base network so that you keep funds you aren't using in [Aave](https://aave.com/) to earn interest and automatically move funds out of savings back into your wallet when funds get low. \n\n1. Create a free [1Shot API](https://1shotapi.com) account.\n2. Generate an API key & secret and use these to create a credential for the 1Shot API nodes.\n3. Click the trigger on the subworkflow to automatically import the required smart contract functions and provision a 1Shot API server wallet on Base that will relay your transactions when you are not online. \n4. Retrieve the contract method IDs from the 1Shot API portal (or the browser console after running the setup subworkflow) and input them into the `Savings Configs` node.\n5. Set your upper and lower saving thresholds in the \"Savings Config\" node.\n6. Create a Telegram bot and use the bot's API key to generate a credential for the Telegram nodes. Get your chat id with the bot and input it into the \"Savings Config\" node. \n7. Configure your desired schedule in the \"Schedule\" trigger node (like every 24 hours)\n8. Activate the workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "d16d710c-442d-42f7-b070-d4902583c596",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        592
      ],
      "parameters": {
        "width": 768,
        "height": 560,
        "content": "## YouTube Tutorial\n\n@[youtube](Hppd04sM4xE)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2ade8ea7-ef80-4420-b2e8-534ce8e1c96a",
      "name": "Check User Has Sufficient Savings",
      "type": "n8n-nodes-base.if",
      "position": [
        1168,
        256
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f9c2403a-4163-4c26-8452-6d12af40115b",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ parseInt($json.withdrawAmount) }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "dfc65736-6995-4ad7-a9cc-609d32aa6f4f",
      "name": "Check for Base Wallet",
      "type": "n8n-nodes-base.if",
      "position": [
        704,
        1008
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b2f25fac-5a5d-4963-b1f6-05c8dfce25a6",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "801ee03f-a524-4e4b-a5ea-2e68899ee92b",
      "name": "Create Base wallet",
      "type": "n8n-nodes-1shot.oneShot",
      "position": [
        928,
        1088
      ],
      "parameters": {
        "name": "=\"{{ $today }}\"",
        "chainId": 8453,
        "resource": "wallets",
        "operation": "create",
        "description": "Range Trading Wallet"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "31c7af94-9e1b-4968-9601-7fd8fc3dadf1",
      "name": "USDC Approve",
      "type": "n8n-nodes-1shot.oneShotSynch",
      "position": [
        1168,
        -256
      ],
      "parameters": {
        "params": "={\n  \"spender\": \"{{ $('Savings Configs').item.json.pool }}\",\n  \"value\": \"{{ $('Calculate Excess Funds').item.json.excessFunds }}\"\n}",
        "operation": "executeAsDelegator",
        "additionalFields": {
          "memo": "=USDC Approve: {{ $('Calculate Excess Funds').item.json.excessFunds }}"
        },
        "contractMethodId": "={{ $('Savings Configs').item.json.contractMethodIds.usdcApprove }}",
        "delegatorWalletAddress": "={{ $('Savings Configs').item.json.delegator }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3bf1a6b0-2da8-4368-8146-71232432ee43",
      "name": "Aave Supply",
      "type": "n8n-nodes-1shot.oneShotSynch",
      "position": [
        1392,
        -320
      ],
      "parameters": {
        "params": "={\n  \"asset\": \"{{ $('Savings Configs').item.json.token }}\",\n  \"amount\": \"{{ $('Calculate Excess Funds').item.json.excessFunds }}\",\n  \"onBehalfOf\": \"{{ $('Savings Configs').item.json.delegator }}\",\n  \"referralCode\": \"0\"\n} ",
        "operation": "executeAsDelegator",
        "additionalFields": {
          "memo": "=Aave Supply: {{ $('Calculate Excess Funds').item.json.excessFunds }}"
        },
        "contractMethodId": "={{ $('Savings Configs').item.json.contractMethodIds.aavePoolSupply }}",
        "delegatorWalletAddress": "={{ $('Savings Configs').item.json.delegator }}"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "20cb778c-6486-426f-9640-957a34f9d1b2",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        1600,
        992
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3.2
    },
    {
      "id": "43154e4e-4692-4fd4-a96f-c227e7123a31",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        1824,
        1008
      ],
      "parameters": {
        "jsCode": "const usdcMethods = $('Assure USDC (Base)').all();\nconst aBasUSDCMethods = $('Assure aBasUSDC').all();\nconst aavePoolMethods = $('Assure Aave: Pool Proxy (Base)').all();\n\nconsole.log(\"usdcMethods:\", usdcMethods)\n\nconst usdcApprove = usdcMethods.find(m => m.json.functionName === \"approve\")?.json.id;\nconst usdcBalanceOf = usdcMethods.find(m => m.json.functionName === \"balanceOf\")?.json.id;\nconst aBasUSDCBalanceOf = aBasUSDCMethods.find(m => m.json.functionName === \"balanceOf\")?.json.id;\nconst aavePoolSupply = aavePoolMethods.find(m => m.json.functionName === \"supply\")?.json.id;\nconst aavePoolWithdraw = aavePoolMethods.find(m => m.json.functionName === \"withdraw\")?.json.id;\n\nconst contractMethodIds = {\n  \"usdcBalanceOf\": usdcBalanceOf,\n  \"usdcApprove\": usdcApprove,\n  \"aBasUSDCBalanceOf\": aBasUSDCBalanceOf,\n  \"aavePoolSupply\": aavePoolSupply,\n  \"aavePoolWithdraw\": aavePoolWithdraw\n}\n\nconsole.log(\"contractMethodIds:\", JSON.stringify(contractMethodIds));\n\nreturn $input.all();"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "73c7e3de-0807-4013-82a3-b846135f2a30",
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Calculate Excess Funds",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Calculate Insufficient Funds",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Change, Send Account Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aave Supply": {
      "main": [
        [
          {
            "node": "Confirm User's USDC Balance After Deposit",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Deposit Failure Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List wallets": {
      "main": [
        [
          {
            "node": "Check for Base Wallet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "USDC Approve": {
      "main": [
        [
          {
            "node": "Aave Supply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Deposit Failure Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Wallet ID": {
      "main": [
        [
          {
            "node": "Assure aBasUSDC",
            "type": "main",
            "index": 0
          },
          {
            "node": "Assure Aave: Pool Proxy (Base)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Assure USDC (Base)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Assure aBasUSDC": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Savings Configs": {
      "main": [
        [
          {
            "node": "Check User's USDC Balance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Savings Configs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Assure USDC (Base)": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Create Base wallet": {
      "main": [
        [
          {
            "node": "Get Wallet ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Withdraw from Aave": {
      "main": [
        [
          {
            "node": "Confirm User's USDC Balance After Withdraw",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Withdraw Failure Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Base Wallet": {
      "main": [
        [
          {
            "node": "Get Wallet ID",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Base wallet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Excess Funds": {
      "main": [
        [
          {
            "node": "USDC Approve",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check User's Aave Savings": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check User's USDC Balance": {
      "main": [
        [
          {
            "node": "Check User's Aave Savings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Insufficient Funds": {
      "main": [
        [
          {
            "node": "Check User Has Sufficient Savings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Assure Aave: Pool Proxy (Base)": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Check User Has Sufficient Savings": {
      "main": [
        [
          {
            "node": "Withdraw from Aave",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Insufficient Savings Warning",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "List wallets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirm User's Aave Savings After Deposit": {
      "main": [
        [
          {
            "node": "Deposit Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirm User's USDC Balance After Deposit": {
      "main": [
        [
          {
            "node": "Confirm User's Aave Savings After Deposit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirm User's Aave Savings After Withdraw": {
      "main": [
        [
          {
            "node": "Withdraw Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirm User's USDC Balance After Withdraw": {
      "main": [
        [
          {
            "node": "Confirm User's Aave Savings After Withdraw",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}