This project enables keypers to accept payment for their service in SPT. It consists of a smart contract and a corresponding monitoring script. By deploying and configuring the contract, the keypers communicate the price in SPT per second they want to be paid. The keypers run the monitoring script on their machines. If it detects that the keyeprs have been insufficiently paid, it shuts down the node.
- Nodejs
- Docker
- Create an
.envfile in the/src/directory based on/src/.env.template. - Set the following variables:
RPC_URL: The URL of an Ethereum JSON RPC server to connect toPRIV_KEY: The private key of the deployer accountTOKEN_ADDRESS: The address of the SPT token contract used for paymentsKEYPER_ADDRESSES: The set of addresses that will be able to withdraw the paymentsREQUESTED_RATE: The number of SPT tokens per second the keypers shall be paid (in total, not per keyper)START_TIMESTAMP: The Unix timestamp from which on the keypers shall be paid
- Run
yarn installin the/src/directory to install the dependencies. - Run
yarn run deployin the/src/directory to deploy the contract. It will output the address.
The monitoring script will check if the keypers have been sufficiently paid given the contract parameters (START_TIMESTAMP and REQUESTED_RATE) and the current time. If so, the script will exit successfully. If not, the script will exit with an error code and, optionally, run a given command. Keypers can use this to shut down there node in the event of non-payment.
- Create an
.envfile in the/src/directory based on/src/.env.template. - Set the following variables:
RPC_URL: The URL of an Ethereum JSON RPC server to connect toCONTRACT_ADDRESS: The address of the payment contractUNPAID_COMMAND: A command to run in the event the keypers have not been sufficiently paid (optional)
- Run
yarn run monitorin the/src/directory.
If payment has been negotiated and the corresponding contract has been deployed, Shutter keypers should run the monitoring script and configure it such that it stops their node in the absence of payment. Assuming a docker compose setup is used, here's a way to do it:
- Build the docker image:
docker build . -t keyper-payment-monitor. - Add the following service to the
servicessection of your docker compose configuration:
keyper-payment-monitor:
image: keyper-payment-monitor
restart: always
environment:
RPC_URL: <Ethereum node JSON RPC URL>
CONTRACT_ADDRESS: <address of the payment contract>
UNPAID_COMMAND: docker stop keyper
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
Note that keyper payment monitor needs access to the docker.sock file on the host in order to shutdown the keyper service. Future versions of the keyper will enable shutting it down via HTTP.
- Make the keyper depend on the
keyper-payment-monitorbeing healthy:
keyper:
<...>
depends_on:
keyper-payment-monitor:
condition: service_healthy
This prevents the keyper from restarting when it is shutdown by the monitor as the latter stays unealthy as long as payment does not resume.
To run unit and integration tests, run yarn run tests in /src/.
- Make an allowance to the keyper payer contract at
addressby callingapprove(address, amount)on the SPT token contract, whereamountis the amount to pay. - Call
pay(amount)on the keyper payer contract.
Validators can check their balance with balanceOf and withdraw their share by calling withdraw().