# Service Script

## How to run Service Script

1. Download the [scads-service](https://github.com/zoinkswap/zoinks-service) folder on git repository.&#x20;

> -> git clone <https://github.com/zoinkswap/zoinks-service.git>

2\. Navigate to the source folder.

3\. Install packages

> -> npm install

![](/files/NLBSTOlZuIom2UGoc9WT)

4\. Run index.js

> -> node index.js

![](/files/RzEraxBYIAYTwieCnyqs)

## Service Script Architecture

1. index.js
2. controller/service.controller.js
3. package.json

### Start point - index.js

![](/files/o5tCXLPS5WRne16HVzeN)

There are 2 paragraph for test/production mode

#### Test mode

```
// test mode
const ret1 = service.checkRewards();
const ret2 = service.checkPulse();
```

#### Production mode

```
// production mode
 cron.schedule("* * * * *", function () {
   service.checkRewards();
 });

 cron.schedule("0 2,14 * * *", function () {
   service.checkPulse();
 });
```

### Main script - controller.js

![](/files/WJrcIwew1oF8TkK0bWcC)

#### Pool addresses

```
const pulseAddress = "0x2B0C377aDC12cFbb79a55D060eE3d7180C07e2bB";
const cakePulseAddress = "0x9D699DA95EA0AC833D01C965DB174c79FbcDDd78";
const masterAddress = "0x6CDA12D62E49F1BE7812a9EEeB59B43345b651A0";
const zoinksPoolAddress = "0xFec39c2B3FB9f606fC757972906f91f5Fe4348AA";
const snacksPoolAddress = "0xaE42213e2f73752208c7731cb98FEEd4F7813De0";
```

#### Wallet connect

```
const privateKey1 = "";
const privateKey2 = "";

const wallet1 = new ethers.Wallet(privateKey1, provider);
const wallet2 = new ethers.Wallet(privateKey2, provider);
```

#### Check Rewards

```
const account = await wallet1.connect(provider);

  const ifaceSnacksPool = new ethers.utils.Interface(snackspool_abi);
  const ifaceZoinksPool = new ethers.utils.Interface(zoinkspool_abi);
  const ifaceMaster = new ethers.utils.Interface(master_abi);

  const snackspool_data = ifaceSnacksPool.encodeFunctionData("updatePool", []);
  const snackspool_txObjs = {
    from: account.address,
    to: snacksPoolAddress,
    value: 0,
    gasLimit: 504264, // 100000
    gasPrice: 50000000000,
    data: snackspool_data,
  };
  await account.sendTransaction(snackspool_txObjs).then((transaction) => {
    try {
      console.dir(transaction);

      console.log("snacks pool update");
    } catch (err) {
      console.log("snacks pool update failed: " + err);
    }
  });

  const zoinkspool_data = ifaceZoinksPool.encodeFunctionData("updatePool", []);
  const zoinkspool_txObjs = {
    from: account.address,
    to: zoinksPoolAddress,
    value: 0,
    gasLimit: 504264, // 100000
    gasPrice: 50000000000,
    data: zoinkspool_data,
  };
  await account.sendTransaction(zoinkspool_txObjs).then((transaction) => {
    try {
      console.dir(transaction);

      console.log("zoinks pool update");
    } catch (err) {
      console.log("zoinks pool update failed: " + err);
    }
  });
  
  const master_data = ifaceMaster.encodeFunctionData("massUpdatePools", []);
  const master_txObjs = {
    from: account.address,
    to: masterAddress,
    value: 0,
    gasLimit: 504264, // 100000
    gasPrice: 50000000000,
    data: master_data,
  };
  await account.sendTransaction(master_txObjs).then((transaction) => {
    try {
      console.dir(transaction);

      console.log("Master(Farms) update");
    } catch (err) {
      console.log("Master(Farms) update failed: " + err);
    }
  });
```

#### Check Pulse

```
const account = await wallet2.connect(provider);

  const ifacePulse = new ethers.utils.Interface(pulse_abi);
  const ifaceCakePulse = new ethers.utils.Interface(cakepulse_abi);

  const pulse_data = ifacePulse.encodeFunctionData("circulate", []);
  const pulse_txObjs = {
    from: account.address,
    to: pulseAddress,
    value: 0,
    gasLimit: 504264, // 100000
    gasPrice: 50000000000,
    data: pulse_data,
  };
  await account.sendTransaction(pulse_txObjs).then((transaction) => {
    try {
      console.dir(transaction);

      console.log("Pulse circulate");
    } catch (err) {
      console.log("Pulse circulate failed: " + err);
    }
  });

  const cakepulse_data = ifaceCakePulse.encodeFunctionData("circulate", []);
  const cakepulse_txObjs = {
    from: account.address,
    to: cakePulseAddress,
    value: 0,
    gasLimit: 504264, // 100000
    gasPrice: 50000000000,
    data: cakepulse_data,
  };
  await account.sendTransaction(cakepulse_txObjs).then((transaction) => {
    try {
      console.dir(transaction);

      console.log("CakePulse circulate");
    } catch (err) {
      console.log("CakePulse circulate failed: " + err);
    }
  });
```

### Package.json

```
{
  "name": "zoinksservice",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ethers": "^5.6.1",
    "node-cron": "^3.0.0",
    "web3": "^1.7.1"
  }
}
```


---

# Agent Instructions: 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:

```
GET https://bcdev727.gitbook.io/zoinkswap/developers/service-script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
