mculp / squares

1 stars 0 forks source link

Data Storage #1

Open mculp opened 2 years ago

mculp commented 2 years ago

I think we should go with decentralized document-based storage.

Storage Options

JSON Schema

{ 
  board_id: SecureRandom.uuid,
  league_name: "Chunky Squares",
  owner: 'Uy9yi3x35hgaHELBZXwwCVFiqMJC9z6ftj',
  options: {
    cost_per_square: 0.05,
    max_squares_per_address: 10,
    payout_options: { 
      type: 'custom',
      first_quarter: 10,
      second_quarter: 20,
      third_quarter: 10,
      fourth_quarter: 60
    }
  },
  teams: [
    { name: "Bengals", axis: "x" },
    { name: "Rams", axis: "y" }
  ],
  outer_axes: [
   { x: [ *[0..9].shuffle ] },
   { y: [ *[0..9].shuffle ] }
  ],
  grid: [
    [
      { row: 1, column: 1, address: 'Bbqg1M4YVVfbhEzwA9SpC9FhsaG83YMTYoR4a8oTDLX', claimed: true },
      { row: 1, column: 2, address: 'Uy9yi3x35hgaHELBZXwwCVFiqMJC9z6ftj', claimed: true },
      { row: 1, column: 3, address: nil, claimed: false },
      # ...
    ],
    [
      { row: 2, column: 1, address: nil, claimed: false },
      { row: 2, column: 2, address: 'Bbqg1M4YVVfbhEzwA9SpC9FhsaG83YMTYoR4a8oTDLX', claimed: true }
      # ...
    ],
    # ...
  ]
}.to_json

We don't need to add row/column values to the grid hashes, but probably makes the implementation of the app less complex.

Misc

Since we only have two weeks, if this is starts to become a time-sink, we just go with Mongo as a first iteration.

mculp commented 2 years ago

Another option is that we could store the board temporarily in Mongo until it's time to submit and then make it immutable after submission.

Edit: I think that's the best option. ☝️

We need to make the process of storing a board a gas-less operation. At the very least, use < $10 gas. Maybe if we just store the board ID on chain it wouldn't cost that much gas.

mculp commented 2 years ago

If it's on Solana, it'll be cheap anyway. But writing contracts in Rust looks intimidating. Solidity looks way easier. We could put it on Polygon (Ethereum Layer 2) and gas would be less than a dollar.