Service Script

How to run Service Script

  1. Download the scads-service folder on git repository.

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

2. Navigate to the source folder.

3. Install packages

-> npm install

4. Run index.js

-> node index.js

Service Script Architecture

  1. index.js

  2. controller/service.controller.js

  3. package.json

Start point - index.js

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

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"
  }
}

Last updated