Skip to main content

Runtime Operations

Once a Generator has joined a Market, they may use the functions listed in this section to update their Generator's state in the Kalypso Marketplace contracts. Certain functions are only relevant for Generators registered in Markets which support confidential inputs. Such functions are described in the next subsection.

Ensure that you have setup kalypso-sdk before proceeding further.

Request to leave Market

To be called when a generator wants to exit a market. This call ensures that generators receive no more requests but to completely exit the market, generators would have to complete all the pending tasks.

./kalypso-tutorial/index.ts
  // existing setup
tx = await kalypso.Generator().requestForExitMarket(marketId);
receipt = await tx.wait();
console.log("Request Exit Market Place Transaction: ", receipt?.hash);

return "Done";

If there are no requests assigned to market, this call will directly ensure the generator has exited market. If there existing any pending requests, it will ensure that generators no additional requests.

Leave Market

Once the generator has completed all the pending tasks, this call can be called to exit the market.

./kalypso-tutorial/index.ts
  // existing setup
tx = await kalypso.Generator().leaveMarketPlace(marketId);
receipt = await tx.wait();
console.log("Leave Market Place Transaction: ", receipt?.hash);

return "Done";
  • marketId: Market ID which the generator wants to leave

Add stake

To stake more tokens against the Generator

./kalypso-tutorial/index.ts

const generatorAddress = await wallet.getAddress();
const amountToStake = "1000000000";
// existing setup
tx = await kalypso.Generator().stake(generatorAddress, amountToStake);
receipt = await tx.wait();
console.log("Stake Transaction: ", receipt?.hash);

return "Done";

Request to reduce stake

The operation should be called when user wishes to reduce the stake. The matching engine then stops assigning the tasks and until the locked stake is reduced

./kalypso-tutorial/index.ts
  // existing setup
tx = await kalypso.Generator().requestToReduceStake(newTotalStake);
receipt = await tx.wait();
console.log("Request To Reduce Stake Tx: ", receipt?.hash);

return "Done Request To Reduce Stake Tx";
  • newTotalStake: Total Stake after the reduction.

Confirm the reduction of stake

Once the locked stake is reduced to desired levels. this function can be called to transfer the stake back to generator's account

./kalypso-tutorial/index.ts
  // existing setup
let refundAddress = await wallet.getAddress();
tx = await kalypso.Generator().unstake();
receipt = await tx.wait();
console.log("Unstake Tx: ", receipt?.hash);

return "Done Unstake";
  • refundAddress: Address that receives unstaked tokens

Request to reduce compute

The operation should be called when generator wishd to reduce the compute. This will result in getting less number of proofs assigned to him simultaneously.

./kalypso-tutorial/index.ts
  // existing setup
tx = await kalypso.Generator().requestToReduceCompute(newCompute);
receipt = await tx.wait();
console.log("Request To Reduce Compute Tx: ", receipt?.hash);

return "Done Request To Reduce Compute Tx";
  • newCompute: New Total Compute after reduction

Confirm the reduction of compute

Once the compute allocated is reduced to desired levels, this function can be called.

./kalypso-tutorial/index.ts
  tx = await kalypso.Generator().decreaseCompute();
receipt = await tx.wait();
console.log("Decrease Compute Tx: ", receipt?.hash);

return "Done Decrease Compute";