Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predictive Market (jsligo) #91

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
__pycache__/
.DS_Store
.env
.idea/
.vscode/
.ligo-work/
.ligoproject
.vscode/
node_modules/
venv/
__pycache__/
3 changes: 2 additions & 1 deletion betting/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ __pycache__

src/compiled/*
deploy/*.js
deployments/*
deployments/*
deploy/node_modules
2 changes: 1 addition & 1 deletion betting/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LIGO=docker run --platform linux/amd64 --rm -v "$(PWD)":"$(PWD)" -w "$(PWD)" ligolang/ligo:0.50.0
LIGO=docker run --platform linux/amd64 --rm -v "$(PWD)":"$(PWD)" -w "$(PWD)" ligolang/ligo:0.51.0
PROTOCOL_OPT=--protocol jakarta
JSON_OPT=--michelson-format json

Expand Down
2 changes: 1 addition & 1 deletion betting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type bet_config_type = {
3) Add an Event using the `storage.manager` address
4) Add a Bet to the Event using an address that is not `storage.manager` nor `storage.oracle_address`
5) _(optional)_ Add more bets to the first team or second team on the Event
6) Update the Bet to specify the outcome in `is_draw`, and the winning Team in `is_team_one_win` if it is not a draw, using `storage.manager` or `storage.oracle_address`
6) Update the Bet to specify the outcome in `game_status` if it is not a draw, using `storage.manager` or `storage.oracle_address`
7) Finalize the Bet using `storage.manager`

## Initial Storage example :
Expand Down
4 changes: 1 addition & 3 deletions betting/deploy/deploy_callback_betting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ let store = {
end_at: 1660741034 + 3600,
modified_at: 1660741034,
opponents: { team_one: '', team_two: '' },
is_finalized : false,
is_draw: false,
is_team_one_win: false,
game_status : Ongoing,
start_bet_time: 1660741034 + 1200,
closed_bet_time: 1660741034 + 2400,
bets_team_one: (new MichelsonMap()),
Expand Down
4 changes: 1 addition & 3 deletions betting/deploy/deploy_callback_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ let store = {
end_at: 1660741034 + 3600,
modified_at: 1660741034,
opponents: { team_one: '', team_two: '' },
is_finalized: false,
is_draw: false,
is_team_one_win: false,
game_status: Ongoing,
metadata: (MichelsonMap.fromLiteral({
'': char2Bytes('tezos-storage:contents'),
contents: char2Bytes(JSON.stringify(metadataJson))
Expand Down
1 change: 0 additions & 1 deletion betting/deployments/oracle.ts

This file was deleted.

87 changes: 0 additions & 87 deletions betting/src/contracts/cameligo/betting/callback/main.mligo

This file was deleted.

46 changes: 0 additions & 46 deletions betting/src/contracts/cameligo/oracle/callback/main.mligo

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import "errors.mligo" "Errors"

// --------------------------------------
// CONFIG RELATED AssertIONS
// CONFIG RELATED ASSERTIONS
// --------------------------------------

let is_manager (p_sender : address)(p_manager : address) : unit =
Expand All @@ -26,7 +26,7 @@ let not_previous_oracle (p_new_oracle : address)(p_prev_oracle : address) : unit
then failwith Errors.same_previous_oracle_address

// --------------------------------------
// EVENT RELATED AssertIONS
// EVENT RELATED ASSERTIONS
// --------------------------------------

let event_creation_not_paused (p_event_creation_paused : bool) : unit =
Expand All @@ -50,20 +50,20 @@ let event_bet_ends_after_end (p_event_bet_end : timestamp) (p_event_end : timest
then failwith Errors.event_betting_end_after_end

// --------------------------------------
// BETTING RELATED AssertIONS
// BETTING RELATED ASSERTIONS
// --------------------------------------

let betting_not_paused (p_betting_paused : bool) : unit =
if (p_betting_paused)
then failwith Errors.betting_paused

let betting_not_finalized (p_betting_finalized : bool) : unit =
if (p_betting_finalized)
then failwith Errors.bet_finished
let betting_not_finalized (p_s : Types.game_status) : unit = match p_s with
| Ongoing -> ()
| _ -> failwith Errors.bet_finished

let betting_finalized (p_betting_finalized : bool) : unit =
if (not p_betting_finalized)
then failwith Errors.bet_not_finished
let betting_finalized (p_s : Types.game_status) : unit = match p_s with
| Ongoing -> failwith Errors.bet_not_finished
| _ -> ()

let no_tez (p_asserted_amount : tez) : unit =
if (p_asserted_amount = 0mutez)
Expand Down
90 changes: 90 additions & 0 deletions betting/src/contracts/jsligo/betting/callback/main.jsligo
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#import "../types.mligo" "BETTING_Types"

type storage =
[@layout:comb] {
name : string,
videogame : string,
begin_at : timestamp,
end_at : timestamp,
modified_at : timestamp,
opponents : { team_one : string, team_two : string},
game_status : BETTING_Types.game_status,
start_bet_time : timestamp,
closed_bet_time : timestamp,
bets_team_one : (address, tez) map,
bets_team_one_index : nat,
bets_team_one_total : tez,
bets_team_two : (address, tez) map,
bets_team_two_index : nat,
bets_team_two_total : tez,
metadata : (string, bytes) map,
bettingAddr : address,
};

type requested_event_param =
[@layout:comb] {
name : string,
videogame : string,
begin_at : timestamp,
end_at : timestamp,
modified_at : timestamp,
opponents : { team_one : string, team_two : string},
game_status : BETTING_Types.game_status,
start_bet_time : timestamp,
closed_bet_time : timestamp,
bets_team_one : (address, tez) map,
bets_team_one_index : nat,
bets_team_one_total : tez,
bets_team_two : (address, tez) map,
bets_team_two_index : nat,
bets_team_two_total : tez,
};


type parameter = ["SaveEvent", requested_event_param] | ["RequestEvent", nat];

type return_ = [list<operation>, storage];

let saveEvent = (param: requested_event_param, store : storage) =>
[list([]), {...store,
name : param.name,
videogame : param.videogame,
begin_at : param.begin_at,
end_at : param.end_at,
modified_at : param.modified_at,
opponents : param.opponents,
game_status : param.game_status,
start_bet_time : param.start_bet_time,
closed_bet_time : param.closed_bet_time,
bets_team_one : param.bets_team_one,
bets_team_one_index : param.bets_team_one_index,
bets_team_one_total : param.bets_team_one_total,
bets_team_two : param.bets_team_two,
bets_team_two_index : param.bets_team_two_index,
bets_team_two_total : param.bets_team_two_total
}];

const main = (param: parameter, store: storage) : return_ =>
match (param, {
SaveEvent: param => saveEvent(param, store),
Nothing: _ => [list([]), store]
}),


// let requestEvent(param, store : nat * storage) : operation list * storage =
// let payload : BETTING_Types.callback_asked_parameter = {
// requested_event_id=param,
// callback=Tezos.get_self_address(),
// } in
// let destination : BETTING_Types.callback_asked_parameter contract =
// match (Tezos.get_entrypoint_opt "%getEvent" store.bettingAddr : BETTING_Types.callback_asked_parameter contract option) with
// | None -> failwith("Unknown entrypoint GetEvent")
// | Some ctr -> ctr
// in
// let op : operation = Tezos.transaction payload 0mutez destination in
// ([op], store)

// let main ((param, s):(parameter * storage)) : operation list * storage =
// match param with
// | SaveEvent p -> saveEvent(p, s)
// | RequestEvent p -> requestEvent(p, s)
Loading