Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Open
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
64 changes: 64 additions & 0 deletions cosmos/juno-cosmwasm-liquidity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
build/
generated/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
21 changes: 21 additions & 0 deletions cosmos/juno-cosmwasm-liquidity/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 The Graph

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions cosmos/juno-cosmwasm-liquidity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CosmWasm Liquidity Example

This example subgraph stores `Contract` objects that represent CosmWasm contract. In order to do that, the handler function decode all `MsgExecuteContract` messages.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the handler function decode all MsgExecuteContract messages.

decode => decodes

39 changes: 39 additions & 0 deletions cosmos/juno-cosmwasm-liquidity/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3'
services:
graph-node:
image: graphprotocol/graph-node:v0.22.0
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- ipfs
- postgres
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
# Change next line if you want to connect to a different JSON-RPC endpoint
ethereum: 'mainnet:http://host.docker.internal:8545'
GRAPH_LOG: info
ipfs:
image: ipfs/go-ipfs:v0.4.23
ports:
- '5001:5001'
volumes:
- ./data/ipfs:/data/ipfs
postgres:
image: postgres
ports:
- '5432:5432'
command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"]
environment:
POSTGRES_USER: graph-node
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
volumes:
- ./data/postgres:/var/lib/postgresql/data
25 changes: 25 additions & 0 deletions cosmos/juno-cosmwasm-liquidity/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "juno-cosmwasm-liquidity",
"version": "0.1.0",
"repository": "https://github.com/graphprotocol/example-subgraph",
"license": "MIT",
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"create-local": "graph create juno-cosmwasm-liquidity --node http://127.0.0.1:8020",
"deploy-local": "graph deploy juno-cosmwasm-liquidity -l v0.1.0 --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
"remove-local": "graph remove juno-cosmwasm-liquidity --node http://127.0.0.1:8020",
"create": "graph create juno-cosmwasm-liquidity --node https://api.thegraph.com/deploy/",
"deploy": "graph deploy juno-cosmwasm-liquidity --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/"
},
"devDependencies": {
"@graphprotocol/graph-cli": "https://github.com/figment-networks/graph-cli.git#cosmos-v1.1",
"@graphprotocol/graph-ts": "https://github.com/figment-networks/graph-ts.git#cosmos-v1.1"
},
"dependencies": {
"@graphprotocol/juno-ts": "https://github.com/figment-networks/graph-juno-ts.git",
"assemblyscript-json": "^1.1.0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove that now.

"babel-polyfill": "^6.26.0",
"babel-register": "^6.26.0"
}
}
4 changes: 4 additions & 0 deletions cosmos/juno-cosmwasm-liquidity/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type Contract @entity {
id: ID!
liquidity: BigInt!
}
60 changes: 60 additions & 0 deletions cosmos/juno-cosmwasm-liquidity/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { json, BigInt, cosmos, log, Bytes, typeConversion } from "@graphprotocol/graph-ts";
import { cosmwasm } from "@graphprotocol/juno-ts";
import { Contract } from "../generated/schema";


export function handleMsgExecuteContract(data: cosmos.MessageData): void {
const message = cosmwasm.wasm.v1.decodeMsgExecuteContract(data.message.value);
const id = message.contract;
let contract = Contract.load(id);

if (contract == null) {
contract = new Contract(id);
contract.liquidity = BigInt.fromI32(0);
}

const result = json.try_fromBytes(Bytes.fromUint8Array(message.msg));

if (result.isOk) {
const jsonMsg = result.value;
const add_liquidity = jsonMsg.toObject().getEntry("add_liquidity");
if (add_liquidity != null) {
const amount = add_liquidity.value.toObject().getEntry("token1_amount");
if (amount != null) {
if (validateBigInt(amount.value.toString())) {
contract.liquidity = contract.liquidity.plus(BigInt.fromString(amount.value.toString()));
} else {
log.warning("amount in not a valid number: {}", [amount.value.toString()])
}
}
}

const remove_liquidity = jsonMsg.toObject().getEntry("remove_liquidity");
if (remove_liquidity != null) {
const amount = remove_liquidity.value.toObject().getEntry("amount");
if (amount != null) {
if (validateBigInt(amount.value.toString())) {
contract.liquidity = contract.liquidity.minus(BigInt.fromString(amount.value.toString()));
} else {
log.warning("amount in not a valid number: {}", [amount.value.toString()])
}
}
}
} else {
log.warning("MsgExecuteContract.msg is not a valid json object: {}", [typeConversion.bytesToString(message.msg)])
}

contract.save();
}

function validateBigInt(str: string): boolean
{
for(let i = 0; i < str.length; i++) {
const num = parseInt(str[i])
if (num == NaN) {
return false;
}
};

return true;
}
20 changes: 20 additions & 0 deletions cosmos/juno-cosmwasm-liquidity/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
specVersion: 0.0.5
description: Juno CosmWasm Liquidity Example
repository: https://github.com/graphprotocol/example-subgraph
schema:
file: ./schema.graphql
dataSources:
- kind: cosmos
name: juno-cosmwasm-liquidity
network: juno-1
source:
startBlock: 0
mapping:
apiVersion: 0.0.5
language: wasm/assemblyscript
entities:
- Coin
messageHandlers:
- message: /cosmwasm.wasm.v1.MsgExecuteContract
handler: handleMsgExecuteContract
file: ./src/mapping.ts
Loading