Skip to content

Commit

Permalink
Merge pull request #34 from octo-technology/FA2_chapter
Browse files Browse the repository at this point in the history
Fa2 chapter
  • Loading branch information
AymericBethencourt authored Jun 29, 2020
2 parents 00fcf6c + cc7ae20 commit 68cef39
Show file tree
Hide file tree
Showing 60 changed files with 6,577 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"babel-plugin-styled-components": "^1.10.7",
"cypress": "^4.7.0",
"eslint-config-react-app": "^5.2.1",
"jest": "^26.0.1",
"jest": "^24.9.0",
"mockdate": "^3.0.2",
"raw-loader": "^4.0.1",
"react-test-renderer": "^16.13.1",
Expand Down
196 changes: 124 additions & 72 deletions src/frontend/src/pages/Chapter/Chapter.data.tsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,88 @@
import { data as camelDataAddresses } from '../Chapters/Camel/ChapterAddresses'
import { data as camelDataBuiltIns } from '../Chapters/Camel/ChapterBuiltIns'
import { data as camelDataConditionals } from '../Chapters/Camel/ChapterConditionals'
import { data as camelDataDeployContract } from '../Chapters/Camel/ChapterDeployContract'
import { data as camelDataFA12 } from '../Chapters/Camel/ChapterFA12'
import { data as camelDataFunctions } from '../Chapters/Camel/ChapterFunctions'
import { data as camelDataInteractions } from '../Chapters/Camel/ChapterInteractions'
import { data as camelDataLambda } from '../Chapters/Camel/ChapterLambda'
import { data as camelDataLists } from '../Chapters/Camel/ChapterLists'
import { data as camelDataLoops } from '../Chapters/Camel/ChapterLoops'
import { data as camelDataMainFunction } from '../Chapters/Camel/ChapterMainFunction'
import { data as camelDataMaps } from '../Chapters/Camel/ChapterMaps'
import { data as camelDataMath } from '../Chapters/Camel/ChapterMath'
import { data as camelDataMultisig } from '../Chapters/Camel/ChapterMultisig'
import { data as camelDataOption } from '../Chapters/Camel/ChapterOption'
import { data as camelDataPolymorphism } from '../Chapters/Camel/ChapterPolymorphism'
import { data as camelDataRecords } from '../Chapters/Camel/ChapterRecords'
import { data as camelDataStrings } from '../Chapters/Camel/ChapterStrings'
import { data as camelDataTimestamps } from '../Chapters/Camel/ChapterTimestamps'
import { data as camelDataTransactions } from '../Chapters/Camel/ChapterTransactions'
import { data as camelDataTuples } from '../Chapters/Camel/ChapterTuples'
import { data as camelDataTypes } from '../Chapters/Camel/ChapterTypes'
import { data as camelDataVariables } from '../Chapters/Camel/ChapterVariables'
import { data as camelDataVariant } from '../Chapters/Camel/ChapterVariant'
import { data as pascalDataAddresses } from '../Chapters/Pascal/ChapterAddresses'
import { data as pascalDataBuiltIns } from '../Chapters/Pascal/ChapterBuiltIns'
import { data as pascalDataConditionals } from '../Chapters/Pascal/ChapterConditionals'
import { data as pascalDataDeployContract } from '../Chapters/Pascal/ChapterDeployContract'
import { data as pascalDataFA12 } from '../Chapters/Pascal/ChapterFA12'
import { data as pascalDataFunctions } from '../Chapters/Pascal/ChapterFunctions'
import { data as pascalDataInteractions } from '../Chapters/Pascal/ChapterInteractions'
import { data as pascalDataLambda } from '../Chapters/Pascal/ChapterLambda'
import { data as pascalDataLists } from '../Chapters/Pascal/ChapterLists'
import { data as pascalDataLoops } from '../Chapters/Pascal/ChapterLoops'
import { data as pascalDataMainFunction } from '../Chapters/Pascal/ChapterMainFunction'
import { data as pascalDataMaps } from '../Chapters/Pascal/ChapterMaps'
import { data as pascalDataMath } from '../Chapters/Pascal/ChapterMath'
import { data as pascalDataMultisig } from '../Chapters/Pascal/ChapterMultisig'
import { data as pascalDataOption } from '../Chapters/Pascal/ChapterOption'
import { data as pascalDataPolymorphism } from '../Chapters/Pascal/ChapterPolymorphism'
import { data as pascalDataRecords } from '../Chapters/Pascal/ChapterRecords'
import { data as pascalDataStrings } from '../Chapters/Pascal/ChapterStrings'
import { data as pascalDataTimestamps } from '../Chapters/Pascal/ChapterTimestamps'
import { data as pascalDataTransactions } from '../Chapters/Pascal/ChapterTransactions'
import { data as pascalDataTuples } from '../Chapters/Pascal/ChapterTuples'
import { data as pascalDataTypes } from '../Chapters/Pascal/ChapterTypes'
import { data as pascalDataVariables } from '../Chapters/Pascal/ChapterVariables'
import { data as pascalDataVariant } from '../Chapters/Pascal/ChapterVariant'
import { data as reasonDataAddresses } from '../Chapters/Reason/ChapterAddresses'
import { data as reasonDataBuiltIns } from '../Chapters/Reason/ChapterBuiltIns'
import { data as reasonDataConditionals } from '../Chapters/Reason/ChapterConditionals'
import { data as reasonDataDeployContract } from '../Chapters/Reason/ChapterDeployContract'
import { data as reasonDataFA12 } from '../Chapters/Reason/ChapterFA12'
import { data as reasonDataFunctions } from '../Chapters/Reason/ChapterFunctions'
import { data as reasonDataInteractions } from '../Chapters/Reason/ChapterInteractions'
import { data as reasonDataLambda } from '../Chapters/Reason/ChapterLambda'
import { data as reasonDataLists } from '../Chapters/Reason/ChapterLists'
import { data as reasonDataLoops } from '../Chapters/Reason/ChapterLoops'
import { data as reasonDataMainFunction } from '../Chapters/Reason/ChapterMainFunction'
import { data as reasonDataMaps } from '../Chapters/Reason/ChapterMaps'
import { data as reasonDataMath } from '../Chapters/Reason/ChapterMath'
import { data as reasonDataMultisig } from '../Chapters/Reason/ChapterMultisig'
import { data as reasonDataOption } from '../Chapters/Reason/ChapterOption'
import { data as reasonDataPolymorphism } from '../Chapters/Reason/ChapterPolymorphism'
import { data as reasonDataRecords } from '../Chapters/Reason/ChapterRecords'
import { data as reasonDataStrings } from '../Chapters/Reason/ChapterStrings'
import { data as reasonDataTimestamps } from '../Chapters/Reason/ChapterTimestamps'
import { data as reasonDataTransactions } from '../Chapters/Reason/ChapterTransactions'
import { data as reasonDataTuples } from '../Chapters/Reason/ChapterTuples'
import { data as reasonDataTypes } from '../Chapters/Reason/ChapterTypes'
import { data as reasonDataVariables } from '../Chapters/Reason/ChapterVariables'
import { data as reasonDataVariant } from '../Chapters/Reason/ChapterVariant'

/* prettier-ignore */

import { data as pascalDataAddresses } from "../Chapters/Pascal/ChapterAddresses";
import { data as pascalDataBuiltIns } from "../Chapters/Pascal/ChapterBuiltIns";
import { data as pascalDataConditionals } from "../Chapters/Pascal/ChapterConditionals";
import { data as pascalDataDeployContract } from "../Chapters/Pascal/ChapterDeployContract";
import { data as pascalDataFA12 } from "../Chapters/Pascal/ChapterFA12";
import { data as pascalDataFunctions } from "../Chapters/Pascal/ChapterFunctions";
import { data as pascalDataInteractions } from "../Chapters/Pascal/ChapterInteractions";
import { data as pascalDataInterop } from "../Chapters/Pascal/ChapterInterop";
import { data as pascalDataLambda } from "../Chapters/Pascal/ChapterLambda";
import { data as pascalDataLists } from "../Chapters/Pascal/ChapterLists";
import { data as pascalDataLoops } from "../Chapters/Pascal/ChapterLoops";
import { data as pascalDataMainFunction } from "../Chapters/Pascal/ChapterMainFunction";
import { data as pascalDataMaps } from "../Chapters/Pascal/ChapterMaps";
import { data as pascalDataMath } from "../Chapters/Pascal/ChapterMath";
import { data as pascalDataMultisig } from "../Chapters/Pascal/ChapterMultisig";
import { data as pascalDataOption } from "../Chapters/Pascal/ChapterOption";
import { data as pascalDataPolymorphism } from "../Chapters/Pascal/ChapterPolymorphism";
import { data as pascalDataRecords } from "../Chapters/Pascal/ChapterRecords";
import { data as pascalDataStrings } from "../Chapters/Pascal/ChapterStrings";
import { data as pascalDataTimestamps } from "../Chapters/Pascal/ChapterTimestamps";
import { data as pascalDataTransactions } from "../Chapters/Pascal/ChapterTransactions";
import { data as pascalDataTuples } from "../Chapters/Pascal/ChapterTuples";
import { data as pascalDataTypes } from "../Chapters/Pascal/ChapterTypes";
import { data as pascalDataVariables } from "../Chapters/Pascal/ChapterVariables";
import { data as pascalDataVariant } from "../Chapters/Pascal/ChapterVariant";

import { data as camelDataAddresses } from "../Chapters/Camel/ChapterAddresses";
import { data as camelDataBuiltIns } from "../Chapters/Camel/ChapterBuiltIns";
import { data as camelDataConditionals } from "../Chapters/Camel/ChapterConditionals";
import { data as camelDataDeployContract } from "../Chapters/Camel/ChapterDeployContract";
import { data as camelDataFA12 } from "../Chapters/Camel/ChapterFA12";
import { data as camelFA20 } from "../Chapters/Camel/ChapterFA20";
import { data as camelFA20Operator } from "../Chapters/Camel/ChapterFA20Operator";
import { data as camelFA20Hook } from "../Chapters/Camel/ChapterFA20Hook";
import { data as camelDataFunctions } from "../Chapters/Camel/ChapterFunctions";
import { data as camelDataInteractions } from "../Chapters/Camel/ChapterInteractions";
import { data as camelDataInterop } from "../Chapters/Camel/ChapterInterop";
import { data as camelDataLambda } from "../Chapters/Camel/ChapterLambda";
import { data as camelDataLists } from "../Chapters/Camel/ChapterLists";
import { data as camelDataLoops } from "../Chapters/Camel/ChapterLoops";
import { data as camelDataMainFunction } from "../Chapters/Camel/ChapterMainFunction";
import { data as camelDataMaps } from "../Chapters/Camel/ChapterMaps";
import { data as camelDataMath } from "../Chapters/Camel/ChapterMath";
import { data as camelDataMultisig } from "../Chapters/Camel/ChapterMultisig";
import { data as camelDataOption } from "../Chapters/Camel/ChapterOption";
import { data as camelDataPolymorphism } from "../Chapters/Camel/ChapterPolymorphism";
import { data as camelDataRecords } from "../Chapters/Camel/ChapterRecords";
import { data as camelDataStrings } from "../Chapters/Camel/ChapterStrings";
import { data as camelDataTimestamps } from "../Chapters/Camel/ChapterTimestamps";
import { data as camelDataTransactions } from "../Chapters/Camel/ChapterTransactions";
import { data as camelDataTuples } from "../Chapters/Camel/ChapterTuples";
import { data as camelDataTypes } from "../Chapters/Camel/ChapterTypes";
import { data as camelDataVariables } from "../Chapters/Camel/ChapterVariables";
import { data as camelDataVariant } from "../Chapters/Camel/ChapterVariant";

import { data as reasonDataAddresses } from "../Chapters/Reason/ChapterAddresses";
import { data as reasonDataBuiltIns } from "../Chapters/Reason/ChapterBuiltIns";
import { data as reasonDataConditionals } from "../Chapters/Reason/ChapterConditionals";
import { data as reasonDataDeployContract } from "../Chapters/Reason/ChapterDeployContract";
import { data as reasonDataFA12 } from "../Chapters/Reason/ChapterFA12";
import { data as reasonDataFunctions } from "../Chapters/Reason/ChapterFunctions";
import { data as reasonDataInteractions } from "../Chapters/Reason/ChapterInteractions";
import { data as reasonDataInterop } from "../Chapters/Reason/ChapterInterop";
import { data as reasonDataLambda } from "../Chapters/Reason/ChapterLambda";
import { data as reasonDataLists } from "../Chapters/Reason/ChapterLists";
import { data as reasonDataLoops } from "../Chapters/Reason/ChapterLoops";
import { data as reasonDataMainFunction } from "../Chapters/Reason/ChapterMainFunction";
import { data as reasonDataMaps } from "../Chapters/Reason/ChapterMaps";
import { data as reasonDataMath } from "../Chapters/Reason/ChapterMath";
import { data as reasonDataMultisig } from "../Chapters/Reason/ChapterMultisig";
import { data as reasonDataOption } from "../Chapters/Reason/ChapterOption";
import { data as reasonDataPolymorphism } from "../Chapters/Reason/ChapterPolymorphism";
import { data as reasonDataRecords } from "../Chapters/Reason/ChapterRecords";
import { data as reasonDataStrings } from "../Chapters/Reason/ChapterStrings";
import { data as reasonDataTimestamps } from "../Chapters/Reason/ChapterTimestamps";
import { data as reasonDataTransactions } from "../Chapters/Reason/ChapterTransactions";
import { data as reasonDataTuples } from "../Chapters/Reason/ChapterTuples";
import { data as reasonDataTypes } from "../Chapters/Reason/ChapterTypes";
import { data as reasonDataVariables } from "../Chapters/Reason/ChapterVariables";
import { data as reasonDataVariant } from "../Chapters/Reason/ChapterVariant";



export const chapterData = [
{
Expand Down Expand Up @@ -177,6 +190,13 @@ export const chapterData = [
name: '25 - Pascal - FA12',
data: pascalDataFA12,
},
{
pathname: '/pascal/chapter-interop',
language: 'PascaLIGO',
name: '26- Pascal - Interoperability',
data: pascalDataInterop,
},


{
pathname: '/camel/chapter-about',
Expand Down Expand Up @@ -272,12 +292,37 @@ export const chapterData = [
name: '24 - Camel - Multisignature',
data: camelDataMultisig,
},
{
pathname: '/camel/chapter-interop',
language: 'CameLIGO',
name: '25 - Camel - Interoperability',
data: camelDataInterop,
},

{
pathname: '/camel/chapter-fa12',
language: 'CameLIGO',
name: '25 - Camel - FA12',
data: camelDataFA12,
},
{
pathname: "/camel/chapter-fa2",
language: "CameLIGO",
name: "26 - Camel - FA2",
data: camelFA20,
},
{
pathname: "/camel/chapter-fa2-operator",
language: "CameLIGO",
name: "27 - Camel - FA2 Operator",
data: camelFA20Operator,
},
{
pathname: "/camel/chapter-fa2-hook",
language: "CameLIGO",
name: "28 - Camel - FA2 Hook",
data: camelFA20Hook,
},

{
pathname: '/reason/chapter-about',
Expand Down Expand Up @@ -394,4 +439,11 @@ export const chapterData = [
name: '25 - Reason - FA12',
data: reasonDataFA12,
},
{
pathname: '/reason/chapter-interop',
language: 'ReasonLIGO',
name: '25 - Reason - Interoperability',
data: reasonDataInterop,
},

]
72 changes: 72 additions & 0 deletions src/frontend/src/pages/Chapters/Camel/ChapterFA20/caller.mligo
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "tzip/proposals/tzip-12/lib/fa2_hook_lib.mligo"
#include "tzip/proposals/tzip-12/lib/fa2_behaviors.mligo"

type storage = {
fa2_registry : fa2_registry;
descriptor : permissions_descriptor;
rep : balance_of_response_michelson list
}

type request_balance_of_param = {
at : address;
requests : balance_of_request list;
}

type receive_balance_of_param = balance_of_response_michelson list

let request_balance (req, s : (request_balance_of_param * storage)) : operation list * storage =
// Get the TZIP-12 contract instance 'from' the chain
let token_contract_balance_entrypoint_opt : balance_of_param_michelson contract option = Tezos.get_entrypoint_opt "%balance_of" req.at in
let token_contract_balance_entrypoint : balance_of_param_michelson contract = match (token_contract_balance_entrypoint_opt) with
| Some (ci) -> ci
| None -> (failwith("Entrypoint not found"): balance_of_param_michelson contract)
in

// Callback (contract) for Balance_of will be the current contract's Receive_balance entrypoint
let balance_of_callback_contract_opt : receive_balance_of_param contract option = Tezos.get_entrypoint_opt "%receive_balance" Tezos.self_address in
let balance_of_callback_contract : receive_balance_of_param contract = match (balance_of_callback_contract_opt) with
| Some (ci) -> ci
| None -> (failwith("Entrypoint not found"): receive_balance_of_param contract)
in
//let balance_of_callback_contract : receive_balance_of_param contract = get_entrypoint("%receive_balance", Tezos.self_address) in
// Set up the parameter w/ data required for the Balance_of entrypoint
let convert = fun (i : balance_of_request) -> Layout.convert_to_right_comb(i) in
let request_michelson : balance_of_request_michelson list = List.map convert req.requests in
let balance_of_operation_param : balance_of_param_aux = {
requests = request_michelson;
callback = balance_of_callback_contract;
} in
let reqPayload : balance_of_param_michelson = Layout.convert_to_right_comb(balance_of_operation_param) in
// Forge an internal transaction to the TZIP-12 contract
// parametrised by the prieviously prepared `balance_of_operation_param`
// Note: We're sending 0mutez as part of this transaction
let balance_of_operation : operation = Tezos.transaction reqPayload 0mutez token_contract_balance_entrypoint in
([ balance_of_operation ], s)

let receive_balance (received, s: (receive_balance_of_param * storage)) : operation list * storage =
let new_store : storage = { s with rep = received } in
(([] : operation list), new_store)

type entry_points =
| Request_balance of request_balance_of_param
| Receive_balance of receive_balance_of_param
| Tokens_transferred_hook of transfer_descriptor_param_michelson
| Register_with_fa2 of fa2_with_hook_entry_points contract

let main (param, s : entry_points * storage)
: (operation list) * storage =
match param with
| Tokens_transferred_hook pm ->
let p = transfer_descriptor_param_from_michelson pm in
let u = validate_hook_call (p.fa2, s.fa2_registry) in
let ops = standard_transfer_hook (
{ligo_param = p; michelson_param = pm}, s.descriptor) in
ops, s

| Register_with_fa2 fa2 ->
let op , new_registry = register_with_fa2 (fa2, s.descriptor, s.fa2_registry) in
let new_s = { s with fa2_registry = new_registry; } in
[op], new_s

| Request_balance request_balance_of_param -> request_balance (request_balance_of_param, s)
| Receive_balance receive_balance_of_param -> receive_balance (receive_balance_of_param, s)
Loading

0 comments on commit 68cef39

Please sign in to comment.