Initial commit

This commit is contained in:
hyossid
2022-05-09 17:50:33 +09:00
parent 3541ee8948
commit b5d43bc33d
244 changed files with 27777 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
node_modules/
dist/
.yarn/
!.yarn/releases

View File

@@ -0,0 +1,25 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['prettier', '@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'prettier/prettier': 'error',
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
},
ignorePatterns: [
'node_modules/**',
'env/',
'src/config/',
'src/graphql/generated/',
],
env: {
node: true,
},
};

26
laplace-swagger/.gitignore vendored Normal file
View File

@@ -0,0 +1,26 @@
.DS_Store
.idea/
.env
node_modules
package-lock.json
cache
tsconfig.tsbuildinfo
/dist/
yarn-error.log
*-debug.log
/src/config/
/hasura-schema/config.yaml
/env/.current_project
/env/docker/
/bin/cli-hasura-*
/bin/docker/wait
# yarn v3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

View File

@@ -0,0 +1 @@
v16.15.0

View File

@@ -0,0 +1,2 @@
/src/config/
/src/graphql/generated/

27
laplace-swagger/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,27 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "typescript"],
"editor.formatOnSave": true,
"eslint.format.enable": true,
"files.insertFinalNewline": true,
"cSpell.words": [
"alexgo",
"apower",
"autoalex",
"codegen",
"CODEOWNERS",
"esbuild",
"esno",
"HASURA",
"memoizee",
"Mocknet",
"Parens",
"rebalancing",
"wban",
"wstx",
"yqueue"
],
"typescript.tsdk": "node_modules/typescript/lib"
}

785
laplace-swagger/.yarn/releases/yarn-3.2.0.cjs vendored Executable file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.2.0.cjs

View File

@@ -0,0 +1,56 @@
# Contributing
We follow a simple model to make contributing as straightforward as possible. These guidelines allow us to streamline the development process and achieve greater transparency.
## Proposing changes
The `main` branch is protected and cannot be committed to directly. It will always contain the latest version of the project that is considered to be stable. Development happens on the `dev` branch. In order to propose a change to the project, we have the following process:
1. Fork the repository if you do not have write access.
2. Create a branch from `dev`, using the following naming convention:
1. `feat/feature-name` when introducing a new feature.
2. `fix/fix-name` when fixing an existing issue.
3. `chore/chore-dec` for miscellaneous changes.
3. Stick to the project coding style. ([See below](#coding-style).)
4. Add your commits to the branch following Conventional Commits ([See below](#conventional-commits).)
5. Open a Pull Request targeting the `dev` branch and tag the right code owners for review. ([See below](#code-owners).)
6. Merge the PR into `dev` if you have write access or request a merge from a code owner after reviews and checks have passed.
Note that any new code must be covered by unit tests. Only PRs with checks successfully are eligible to be merged. The code owners reserve the right to accept or reject PRs.
Any contributions that are accepted become part of the code base under the same [license](LICENSE) that covers the project.
## Opening issues
You can open an issue via GitHub's issue tracker. You may tag one or more code owners for visibility if you think it fits the issue.
## Coding style
- Tabs instead of spaces.
- Closing brackets generally go on a new line.
## Conventional Commits
We follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard for commit messages. The pattern for such a commit message is as follows:
```
type(scope?): description
```
Where `type` is one of:
- `feat`: commits that add a feature.
- `fix`: commits that fix an issue.
- `refactor`: commits that (re)write code but do not change behavior.
- `chore`: miscellaneous commits or housekeeping.
- Or one of the other types described by the standard.
The `scope` portion is optional and valid options depend on the project.
Example Conventional Commit message:
```
fix(yield-token): unwrap memo and print if not none
```
## Code owners
All repositories should contain a `CODEOWNERS` file that automatically requests the right code owner(s) for review when a new PR is submitted. If it does not happen, or if you think someone else should be included, you can request a review manually.

View File

@@ -0,0 +1,26 @@
FROM node:16.15.0-bullseye
WORKDIR /build
COPY package.json /build/package.json
COPY yarn.lock /build/yarn.lock
COPY .yarn/releases /build/releases
RUN yarn install --production && \
mv node_modules /node_modules && \
yarn
COPY bin /build/bin
RUN ./bin/hasura-cli --skip-update-check version
COPY tsconfig.json /build/tsconfig.json
COPY env /build/env
COPY src /build/src
ARG TARGET_ENV
RUN yarn use $TARGET_ENV && \
yarn build && \
wc -l dist/main.js
FROM node:16.15.0-bullseye
WORKDIR /app
COPY package.json /app/package.json
COPY --from=0 /node_modules /app/node_modules
COPY --from=0 /build/dist /app/dist
COPY --from=0 /build/bin /app/bin
COPY hasura-schema /app/hasura-schema
ENTRYPOINT /app/bin/start-cli

View File

@@ -0,0 +1,3 @@
# Alex Laplace Sync
https://github.com/alexgo-io/alex-laplace-sync/wiki

9
laplace-swagger/bin/dev Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const project = path.join(__dirname, '..', 'tsconfig.json');
process.env.NODE_ENV = 'development';
require('ts-node').register({ project });
require('../src/main');

View File

@@ -0,0 +1,92 @@
version: '3.8'
services:
postgres:
image: 'postgres:14.2'
shm_size: 2gb
ports:
- '65432:5432'
environment:
POSTGRES_USER: laplace_dev
POSTGRES_PASSWORD: ed1dynCpdTreu5a
POSTGRES_DB: laplace_dev
POSTGRES_PORT: 5432
networks:
- laplace_dev_stacks_network
volumes:
- pgdata:/var/lib/postgresql/data
stacks-blockchain-api:
image: us-central1-docker.pkg.dev/fifth-compiler-334213/alexgo/stacks-blockchain-api:3.0.3
command: sh -c "/wait && node ./lib/index.js"
restart: always
ports:
- '63999:3999'
environment:
WAIT_HOSTS: 'postgres:5432'
SKIP_REFRESH_MATERIALIZED_VIEW: 'true'
PG_HOST: postgres
PG_PORT: 5432
PG_USER: laplace_dev
PG_PASSWORD: ed1dynCpdTreu5a
PG_DATABASE: laplace_dev
STACKS_CORE_EVENT_PORT: '3700'
STACKS_CORE_EVENT_HOST: http://0.0.0.0
STACKS_BLOCKCHAIN_API_PORT: '3999'
STACKS_BLOCKCHAIN_API_HOST: 0.0.0.0
STACKS_BLOCKCHAIN_API_DB: pg
STACKS_CORE_RPC_HOST: stacks-node-rpc.alexgo.dev
STACKS_CORE_RPC_PORT: '80'
STACKS_CHAIN_ID: '0x80000000'
NODE_ENV: development
volumes:
- $PWD/docker/wait:/wait
networks:
- laplace_dev_stacks_network
replicator:
image: us-central1-docker.pkg.dev/fifth-compiler-334213/alexgo/stacks-blockchain-api-replicator:v20220308-6fad681
container_name: laplace_dev_replicator
restart: always
environment:
WAIT_HOSTS: 'stacks-blockchain-api:3700'
PG_CONNECTION_STRING: 'postgresql://alex:ed1dynCpdTreu5a@stacks-node-rpc.alexgo.dev:54321/alexgo'
EVENT_API_ENDPOINT: http://stacks-blockchain-api:3700
volumes:
- $PWD/docker/wait:/wait
- replica:/srv/state
networks:
- laplace_dev_stacks_network
command: sh -c "/wait && node /srv/main.js"
hasura:
restart: always
image: hasura/graphql-engine:v2.6.0
ports:
- '60880:8080'
networks:
- laplace_dev_stacks_network
environment:
HASURA_GRAPHQL_METADATA_DATABASE_URL: 'postgresql://laplace_dev:ed1dynCpdTreu5a@postgres:5432/laplace_dev'
LAPLACE_DATABASE_URL: 'postgresql://laplace_dev:ed1dynCpdTreu5a@postgres:5432/laplace_dev'
HASURA_GRAPHQL_ENABLE_CONSOLE: 'true'
HASURA_GRAPHQL_LOG_LEVEL: 'info'
HASURA_GRAPHQL_ADMIN_SECRET: 'ed1dynCpdTreu5a'
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: 'public'
HASURA_GRAPHQL_ENABLED_LOG_TYPES: 'startup, http-log, webhook-log, websocket-log, query-log'
HASURA_GRAPHQL_DEV_MODE: 'true'
HASURA_GRAPHQL_SERVER_PORT: 8080
loader:
image: 'us-central1-docker.pkg.dev/fifth-compiler-334213/alexgo/alex-stacks-loader:v20220225-f2272443'
environment:
PG_CONNECTION_STRING: 'postgresql://laplace_dev:ed1dynCpdTreu5a@postgres:5432/laplace_dev'
WAIT_BEFORE: 3
WAIT_AFTER: 3
WAIT_HOSTS: 'stacks-blockchain-api:3700'
networks:
- laplace_dev_stacks_network
volumes:
- $PWD/docker/wait:/wait
command: sh -c "/wait && node /srv/main.js"
networks:
laplace_dev_stacks_network: {}
volumes:
pgdata: {}
replica: {}

46
laplace-swagger/bin/download Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
const { createWriteStream } = require('fs');
const axios = require('axios');
async function downloadFile(fileUrl, outputLocationPath) {
return axios({
method: 'get',
url: fileUrl,
responseType: 'stream',
}).then(response => {
return new Promise((resolve, reject) => {
const writer = createWriteStream(outputLocationPath);
response.data.pipe(writer);
let error = null;
writer.on('error', err => {
error = err;
writer.close();
reject(err);
});
writer.on('close', () => {
if (!error) {
resolve(true);
}
});
});
});
}
if (process.argv.length !== 4) {
console.error('Usage: ./download <url> <output-path>');
}
const url = process.argv[2];
const output = process.argv[3];
console.log(`Downloading ${url}`);
downloadFile(url, output).then(
() => {
console.log(`Saved ${url} to ${output}`);
process.exit(0);
},
e => {
console.error(`Fail to download file from ${url}, error: ${e}`);
process.exit(1);
},
);

52
laplace-swagger/bin/hasura Executable file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
pushd "$DIR" > /dev/null 2>&1 || exit
if [ ! -e "./docker/wait" ]; then
mkdir -p ./docker
wget -qO ./docker/wait https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait
chmod +x ./docker/wait
fi
popd > /dev/null 2>&1 || exit
_docker_compose() {
pushd "$DIR/docker" >/dev/null 2>&1 || exit
docker-compose --project-name laplace-dev \
-f docker-compose.laplace-dev.yaml \
$@
popd >/dev/null 2>&1 || exit
}
main() {
local cmd=$1
case $cmd in
up)
_docker_compose up -d
echo Local hasura console will be running at http://localhost:60880/console
echo ' with admin secret: ed1dynCpdTreu5a'
echo "If you're starting from fresh, run:"
echo ' yarn use local && yarn hasura metadata apply && yarn hasura migrate apply --all-databases && yarn hasura metadata reload'
echo "And if you need to see the replication status, run:"
echo ' docker logs -f --tail=100 laplace_dev_replicator'
;;
down)
_docker_compose down
;;
logs)
_docker_compose logs -f --tail=100
;;
clean)
_docker_compose down
docker volume rm laplace-dev_pgdata
docker volume rm laplace-dev_replica
;;
*)
echo "Usage: $0 {up|down|logs|clean}"
exit 1
;;
esac
}
main $@

13
laplace-swagger/bin/hasura-cli Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
export BINDIR="$( dirname "${BASH_SOURCE[0]}" )"
HASURA_VERSION=v2.6.1
CLI_PATH=cli-hasura-$($BINDIR/osarch)-${HASURA_VERSION}
if [ ! -e "${BINDIR}/${CLI_PATH}" ]; then
rm -f ${BINDIR}/cli-hasura-*
$BINDIR/download https://github.com/hasura/graphql-engine/releases/download/${HASURA_VERSION}/cli-hasura-$($BINDIR/osarch) ${BINDIR}/${CLI_PATH}
chmod +x ${BINDIR}/${CLI_PATH}
fi
${BINDIR}/${CLI_PATH} $@

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e
cd $(dirname "${BASH_SOURCE[0]}")
cd ..
export BASEDIR=$(pwd)
echo $BASEDIR
cd $BASEDIR/hasura-schema
echo staring hasura console...
$BASEDIR/bin/hasura-cli console

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
cd $(dirname "${BASH_SOURCE[0]}")
cd ..
export BASEDIR=$(pwd)
if [ ! -z "${RUN_HASURA_APPLY}" ]; then
cd $BASEDIR/hasura-schema
echo "version: 3
endpoint: ${HASURA_HOST}
admin_secret: ${X_HASURA_ADMIN_SECRET}
metadata_directory: metadata" > config.yaml
$BASEDIR/bin/hasura-cli --skip-update-check metadata apply
$BASEDIR/bin/hasura-cli --skip-update-check migrate apply --all-databases
$BASEDIR/bin/hasura-cli --skip-update-check metadata reload
fi

16
laplace-swagger/bin/osarch Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
const os = require('os');
function normalizeArch(arch) {
if (arch === 'x64') return 'amd64';
return arch;
}
function normalizePlatform(platform) {
if (platform === 'win32') return 'windows';
return platform;
}
console.log(normalizePlatform(os.platform()) + '-' + normalizeArch(os.arch()));

19
laplace-swagger/bin/start-cli Executable file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
cd $(dirname "${BASH_SOURCE[0]}")
cd ..
export BASEDIR=$(pwd)
if [ ! -z "${RUN_HASURA_APPLY}" ]; then
cd $BASEDIR/hasura-schema
echo "version: 3
endpoint: ${HASURA_HOST}
admin_secret: ${X_HASURA_ADMIN_SECRET}
metadata_directory: metadata" > config.yaml
$BASEDIR/bin/hasura-cli --skip-update-check metadata apply
$BASEDIR/bin/hasura-cli --skip-update-check migrate apply --all-databases
$BASEDIR/bin/hasura-cli --skip-update-check metadata reload
fi
cd $BASEDIR
node -r source-map-support/register dist/main.js

View File

@@ -0,0 +1,4 @@
version: 3
endpoint: {{HASURA_HOST}}
admin_secret: {{X_HASURA_ADMIN_SECRET}}
metadata_directory: metadata

View File

@@ -0,0 +1,24 @@
{
"name": "laplace:hasura",
"schemaPath": "../graphql/generated/graphql-schema.json",
"extensions": {
"endpoints": {
"dev": {
"url": "{{HASURA_HOST}}/v1/graphql",
"headers": {
"x-hasura-admin-secret": "{{X_HASURA_ADMIN_SECRET}}",
"x-hasura-role": "admin",
"user-agent": "JS GraphQL"
},
"subscription": {
"url": "{{HASURA_HOST_WS}}",
"headers": {
"x-hasura-admin-secret": "{{X_HASURA_ADMIN_SECRET}}",
"user-agent": "JS GraphQL"
}
},
"introspect": true
}
}
}
}

View File

@@ -0,0 +1,20 @@
overwrite: true
schema: "{{HASURA_HOST}}/v1/graphql"
headers:
x-hasura-admin-secret: "{{X_HASURA_ADMIN_SECRET}}"
x-hasura-role: "admin"
documents:
- src/**/*.graphql
generates:
src/graphql/generated/graphql-schema.json:
plugins:
- introspection
src/graphql/generated/graphql-request.ts:
plugins:
- typescript
- typescript-operations
- typescript-graphql-request
config:
namingConvention:
typeNames: change-case#pascalCase
transformUnderscore: true

View File

@@ -0,0 +1,4 @@
export const X_HASURA_ADMIN_SECRET =
process.env['X_HASURA_ADMIN_SECRET'] ?? '{{X_HASURA_ADMIN_SECRET}}';
export const HASURA_HOST = process.env['HASURA_HOST'] ?? '{{HASURA_HOST}}';
export const HASURA_GRAPHQL_ENDPOINT = HASURA_HOST + '/v1/graphql';

View File

@@ -0,0 +1,19 @@
import * as stacks from '@stacks/network';
export const STACKS_NODE_TYPE:
| 'StacksMainnet'
| 'StacksMocknet'
| 'StacksTestnet' = '{{STACKS_NODE_TYPE}}' as any;
export const STACKS_NETWORK = new stacks[STACKS_NODE_TYPE]({
url: process.env.STACKS_NODE_ADDRESS ?? '{{STACKS_NODE_ADDRESS}}',
});
export const STACKS_DEPLOYER_ADDRESS =
process.env.STACKS_DEPLOYER_ADDRESS ?? '{{STACKS_DEPLOYER_ADDRESS}}';
export const ESTIMATED_BLOCK_DURATION =
process.env.ESTIMATED_BLOCK_DURATION ?? '{{ESTIMATED_BLOCK_DURATION}}';
export const ALEX_CONTRACT_NAME_LAUNCHPAD =
process.env.ALEX_CONTRACT_NAME_LAUNCHPAD ?? '{{ALEX_CONTRACT_NAME_LAUNCHPAD}}';

1061
laplace-swagger/env/mo vendored Executable file

File diff suppressed because it is too large Load Diff

177
laplace-swagger/env/use.sh vendored Executable file
View File

@@ -0,0 +1,177 @@
#!/usr/bin/env bash
set -eo pipefail
BASE="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd .. && pwd )"
cd "$BASE"/../
main() {
ENV=$1
echo use $ENV env
case $ENV in
local)
export HASURA_ENV=local
export STACKS_ENV=local
;;
shared_dev)
export HASURA_ENV=shared_dev
export STACKS_ENV=regtest3
;;
dev|regtest3)
export HASURA_ENV=regtest3
export STACKS_ENV=regtest3
;;
prod|mainnet)
export HASURA_ENV=mainnet
export STACKS_ENV=mainnet
;;
current)
export HASURA_ENV=current
export STACKS_ENV=current
;;
*)
echo unkown env "$ENV"
exit 1
;;
esac
############################################# HASURA_ENV #############################################
case $HASURA_ENV in
local)
export HASURA_HOST="http://localhost:8080"
export X_HASURA_ADMIN_SECRET="ed1dynCpdTreu5a"
echo "You're using your local hasura instance."
echo " Hasura Console: http://localhost:8080/console"
;;
shared_dev)
export HASURA_HOST="https://gql-dev.alexgo.dev"
export X_HASURA_ADMIN_SECRET="ed1dynCpdTreu5a"
echo "You're using shared dev hasura instance, it's for development."
echo " Hasura Console: https://gql-dev.alexgo.dev"
;;
regtest3)
export HASURA_HOST="https://gql.alexgo.dev"
export X_HASURA_ADMIN_SECRET="ed1dynCpdTreu5a"
echo "You're using hasura-regtest3 instance."
echo " Hasura Console: https://gql.alexgo.dev"
;;
mainnet)
export HASURA_HOST="https://hasura-console-dks44dnbuq-uw.a.run.app"
export X_HASURA_ADMIN_SECRET="znstEB5VtFHv3WZ"
echo "You're using hasura-mainnet instance."
echo " Hasura Console: https://hasura-console.alexlab.co"
;;
current)
echo "You're using current env."
echo "-----------------------------"
echo "HASURA_HOST: $HASURA_HOST"
echo "X_HASURA_ADMIN_SECRET: $X_HASURA_ADMIN_SECRET"
echo "-----------------------------"
;;
*)
echo unkown hasura env "$HASURA_ENV"
exit 1
;;
esac
############################################# STACKS_ENV #############################################
case $STACKS_ENV in
local)
export STACKS_NODE_TYPE="StacksMocknet"
export STACKS_NODE_ADDRESS="http://localhost:3999"
export STACKS_DEPLOYER_ADDRESS="ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE"
export ESTIMATED_BLOCK_DURATION=15000
export ALEX_CONTRACT_NAME_LAUNCHPAD="alex-launchpad-v1-1"
;;
regtest3)
export STACKS_NODE_TYPE="StacksMocknet"
export STACKS_NODE_ADDRESS="https://stacks-node-api.alexgo.dev"
export STACKS_DEPLOYER_ADDRESS="ST1J2JTYXGRMZYNKE40GM87ZCACSPSSEEQVSNB7DC"
export ESTIMATED_BLOCK_DURATION=15000
export ALEX_CONTRACT_NAME_LAUNCHPAD="alex-launchpad-v1-1"
;;
mainnet)
export STACKS_NODE_TYPE="StacksMainnet"
export STACKS_NODE_ADDRESS="https://stacks-blockchain-mainnet-dks44dnbuq-uw.a.run.app"
export STACKS_DEPLOYER_ADDRESS="SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9"
export ESTIMATED_BLOCK_DURATION=600000
export ALEX_CONTRACT_NAME_LAUNCHPAD="alex-launchpad"
;;
current)
echo "You're using current stacks env."
echo "-----------------------------"
echo "STACKS_NODE_TYPE: $STACKS_NODE_TYPE"
echo "STACKS_NODE_ADDRESS: $STACKS_NODE_ADDRESS"
echo "STACKS_DEPLOYER_ADDRESS: $STACKS_DEPLOYER_ADDRESS"
echo "ESTIMATED_BLOCK_DURATION: $ESTIMATED_BLOCK_DURATION"
echo "ALEX_CONTRACT_NAME_LAUNCHPAD: $ALEX_CONTRACT_NAME_LAUNCHPAD"
echo "-----------------------------"
;;
*)
echo unkown stacks env "$STACKS_ENV"
exit 1
;;
esac
pushd env/base/
FILES=$(find . -type f)
popd
for f in $FILES
do
writeTemplateFile "$f"
done
echo "$ENV" > "$BASE"/.current_project
echo "switched to env $ENV"
}
linkFile() {
ORIGIN_FILE_PATH=$1
LINK_FILE_PATH=$2
rm -f $LINK_FILE_PATH
ln -s $ORIGIN_FILE_PATH $LINK_FILE_PATH
}
copyFile() {
ORIGIN_FILE_PATH=$1
COPY_FILE_PATH=$2
rm -f $COPY_FILE_PATH
cp $ORIGIN_FILE_PATH $COPY_FILE_PATH
chmod 400 $COPY_FILE_PATH
}
writeTemplateFile() {
FILE_PATH=$1
FILE_DIR=$(dirname "${FILE_PATH}")
mkdir -p "$FILE_DIR"
rm -f "$ROOT"/"$FILE_PATH"
"$BASE"/mo "$BASE"/base/"$FILE_PATH" > "$ROOT"/"$FILE_PATH"
chmod 400 "$ROOT"/"$FILE_PATH"
}
usage() {
echo 'Current env:'
if [ -e "$ROOT/env/.current_project" ]; then
cat $ROOT/env/.current_project
else
echo 'N/A'
fi
echo
echo './use.sh <ENV>'
echo ' Example: ./use.sh local'
echo ' Supported ENV: local, dev/regtest3, prod/mainnet'
echo ' Please refer to README.md for detail explanation.'
}
if [ "$1" == "-h" ]
then
usage
elif [ -n "${1-}" ]
then
main "$1"
else
usage
fi

View File

@@ -0,0 +1,3 @@
# Hasura Schema Version Control
https://github.com/alexgo-io/alex-laplace-sync/wiki#database-version-control

View File

@@ -0,0 +1,15 @@
type Query {
get_crp_simulation(
args: CRPSimulationInput!
): CRPSimulationOutput
}
input CRPSimulationInput {
start_date: String!
end_date: String!
}
type CRPSimulationOutput {
data: jsonb!
}

View File

@@ -0,0 +1,24 @@
actions:
- name: get_crp_simulation
definition:
kind: ""
handler: https://crp-simulator-dks44dnbuq-uw.a.run.app/simulation
request_transform:
body:
action: transform
template: |-
{
"start_date": {{$body.input.args.start_date}},
"end_date": {{$body.input.args.end_date}}
}
method: POST
version: 2
query_params: {}
template_engine: Kriti
custom_types:
enums: []
input_objects:
- name: CRPSimulationInput
objects:
- name: CRPSimulationOutput
scalars: []

View File

@@ -0,0 +1,3 @@
- collection: allowed-queries
scope:
global: true

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1,9 @@
- name: laplace
kind: postgres
configuration:
connection_info:
use_prepared_statements: false
database_url:
from_env: LAPLACE_DATABASE_URL
isolation_level: read-committed
tables: "!include laplace/tables/tables.yaml"

View File

@@ -0,0 +1,27 @@
table:
schema: laplace
name: alex_reserve_pools
select_permissions:
- role: public
permission:
columns:
- apower_multiplier
- coinbase_amount_1
- coinbase_amount_2
- coinbase_amount_3
- coinbase_amount_4
- coinbase_amount_5
- dual_yield_token_multiplier
- reserved_balance
- dual_yield_token_deployer_address
- dual_yield_token_name
- token_deployer_address
- token_name
- activation_block
- block_height
- current_cycle
- reward_cycle_length
- token_halving_cycle
- sync_at
- staking_stats
filter: {}

View File

@@ -0,0 +1,10 @@
table:
schema: laplace
name: alex_usd_pricing
select_permissions:
- role: public
permission:
columns:
- avg_price_usd
- token
filter: {}

View File

@@ -0,0 +1,15 @@
table:
schema: laplace
name: coin_gecko
select_permissions:
- role: public
permission:
columns:
- coin_gecko_id
- token
- avg_price_usd
- ccy
- market_cap
- prices_market
- timestamp
filter: {}

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: coin_gecko_archive

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: config_contracts

View File

@@ -0,0 +1,30 @@
table:
schema: laplace
name: contract_calls
select_permissions:
- role: public
permission:
columns:
- execution_cost_read_count
- execution_cost_read_length
- execution_cost_runtime
- execution_cost_write_count
- execution_cost_write_length
- fee_rate
- tx_id
- arg1
- arg2
- arg3
- arg4
- arg5
- contract_id
- contract_name
- function_name
- sender_address
- transaction_result_type
- block_height
- events
- function_args
- transaction_result
- anchor_mode
filter: {}

View File

@@ -0,0 +1,10 @@
table:
schema: laplace
name: current_token_price
select_permissions:
- role: public
permission:
columns:
- token
- avg_price_usd
filter: {}

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: deployed_contracts

View File

@@ -0,0 +1,11 @@
table:
schema: laplace
name: external_token_price
select_permissions:
- role: public
permission:
columns:
- token_name
- value
- time_stamp
filter: {}

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: fixed_weight_pool_v1_01

View File

@@ -0,0 +1,13 @@
table:
schema: laplace
name: history_staking_stats
select_permissions:
- role: public
permission:
columns:
- token
- cycle
- sync_at_block_height
- total_staked
- sync_at
filter: {}

View File

@@ -0,0 +1,22 @@
table:
schema: laplace
name: ido_pool_creation
select_permissions:
- role: public
permission:
columns:
- tx_id
- block_height
- ido_token
- payment_token
- ido_owner
- claim_end_height
- activation_threshold
- ido_tokens_per_ticket
- registration_end_height
- price_per_ticket_in_fixed
- registration_start_height
- apower_per_ticket_in_fixed
- transaction_result_type
- result_value
filter: {}

View File

@@ -0,0 +1,19 @@
table:
schema: laplace
name: ido_register
select_permissions:
- role: public
permission:
columns:
- amount
- apower
- registered_end
- registered_start
- contract_call_contract_id
- payment_token
- sender_address
- tx_id
- block_height
- ido_id
filter: {}
allow_aggregations: true

View File

@@ -0,0 +1,29 @@
table:
schema: laplace
name: latest_alex_reserve_pools
select_permissions:
- role: public
permission:
columns:
- token_deployer_address
- token_name
- block_height
- burn_block_time
- activation_block
- reward_cycle_length
- token_halving_cycle
- current_cycle
- reserved_balance
- coinbase_amount_1
- coinbase_amount_2
- coinbase_amount_3
- coinbase_amount_4
- coinbase_amount_5
- apower_multiplier
- staking_stats
- earning_preview
- dual_yield_token_deployer_address
- dual_yield_token_name
- dual_yield_token_multiplier
- sync_at
filter: {}

View File

@@ -0,0 +1,18 @@
table:
schema: laplace
name: latest_auto_alex
select_permissions:
- role: public
permission:
columns:
- token_name
- block_height
- burn_block_time
- current_cycle
- pool_user_id
- pool_total_staked_stats
- pool_to_return_stats
- pool_future_volume_stats
- apys
- sync_at
filter: {}

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: latest_fixed_weight_pool_v1_01

View File

@@ -0,0 +1,30 @@
table:
schema: laplace
name: latest_pool_stats
select_permissions:
- role: public
permission:
columns:
- pool_token
- block_height
- token_x
- token_y
- block_height
- volume_x_24h
- volume_y_24h
- volume_24h
- volume_x_7d
- volume_y_7d
- volume_7d
- fee_rebate_x_24h
- fee_rebate_y_24h
- fee_rebate_24h
- fee_rebate_x_7d
- fee_rebate_y_7d
- fee_rebate_7d
- liquidity
- total_supply
- apr_7d
- burn_block_time
- sync_at
filter: {}

View File

@@ -0,0 +1,28 @@
table:
schema: laplace
name: latest_simple_weight_pool_alex
select_permissions:
- role: public
permission:
columns:
- balance_x
- balance_y
- est_pool_token_price
- est_token_y_price
- fee_rate_x
- fee_rate_y
- fee_rebate
- oracle_average
- oracle_resilient
- total_supply
- oracle_enabled
- fee_to_address
- pool_token
- token_x
- token_y
- block_height
- burn_block_time
- end_block
- start_block
- sync_at
filter: {}

View File

@@ -0,0 +1,15 @@
table:
schema: laplace
name: latest_staking_data
select_permissions:
- role: public
permission:
columns:
- coinbase_amount
- staking_stats
- token
- block_height
- current_cycle
- cycle
- apr
filter: {}

View File

@@ -0,0 +1,10 @@
table:
schema: laplace
name: oracle_token_price
select_permissions:
- role: public
permission:
columns:
- avg_price_usd
- token
filter: {}

View File

@@ -0,0 +1,29 @@
table:
schema: laplace
name: pool_stats
select_permissions:
- role: public
permission:
columns:
- pool_token
- block_height
- token_x
- token_y
- block_height
- volume_x_24h
- volume_y_24h
- volume_24h
- volume_x_7d
- volume_y_7d
- volume_7d
- fee_rebate_x_24h
- fee_rebate_y_24h
- fee_rebate_24h
- fee_rebate_x_7d
- fee_rebate_y_7d
- fee_rebate_7d
- liquidity
- apr_7d
- burn_block_time
- sync_at
filter: {}

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: reward_cycle_stats

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: simple_weight_pool_alex

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: stacks_blockchain_events

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: swap_records

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: sync_status

View File

@@ -0,0 +1,3 @@
table:
schema: laplace
name: synced_blocks

View File

@@ -0,0 +1,13 @@
table:
schema: laplace
name: token_stats
select_permissions:
- role: public
permission:
columns:
- token_name
- block_height
- decimals
- total_supply
- block_height
filter: {}

View File

@@ -0,0 +1,3 @@
table:
schema: public
name: blocks

View File

@@ -0,0 +1,3 @@
table:
schema: public
name: contract_logs

View File

@@ -0,0 +1,3 @@
table:
schema: public_dbt
name: autoalex_apower_distribution

View File

@@ -0,0 +1,3 @@
table:
schema: public_dbt
name: autoalex_claim_and_stake

View File

@@ -0,0 +1,10 @@
table:
schema: public_dbt
name: autoalex_snapshot_config
select_permissions:
- role: public
permission:
columns:
- block_height
- rank
filter: {}

View File

@@ -0,0 +1,11 @@
table:
schema: public_dbt
name: dim_balance_alex_staked_lockdrop_offets
select_permissions:
- role: public
permission:
columns:
- staked_alex_amount
- block_height
- address
filter: {}

View File

@@ -0,0 +1,14 @@
table:
schema: public_dbt
name: dim_balance_autoalex_apower_distribution
select_permissions:
- role: public
permission:
columns:
- address
- apower_distribution
- block_height
- changed_block_height
- cycle_index
- total_autoalex_balance
filter: {}

View File

@@ -0,0 +1,3 @@
table:
schema: public_dbt
name: dim_balance_autoalex_rank_on_height_view

View File

@@ -0,0 +1,14 @@
table:
schema: public_dbt
name: dim_balance_autoalex_rank_snapshot_view
select_permissions:
- role: public
permission:
columns:
- multiplier
- total_autoalex_balance
- balance_block_height
- snapshot_rank
- target_block_height
- address
filter: {}

View File

@@ -0,0 +1,13 @@
table:
schema: public_dbt
name: dim_balance_autoalex_rank_view
select_permissions:
- role: public
permission:
columns:
- address
- name
- total_autoalex_balance
- rank_no
- current_multiplier
filter: {}

View File

@@ -0,0 +1,3 @@
table:
schema: public
name: ft_events

View File

@@ -0,0 +1,3 @@
table:
schema: public
name: smart_contracts

View File

@@ -0,0 +1,3 @@
table:
schema: public
name: stx_events

View File

@@ -0,0 +1,3 @@
table:
schema: public_transform
name: txs_view

View File

@@ -0,0 +1,41 @@
- "!include laplace_alex_reserve_pools.yaml"
- "!include laplace_alex_usd_pricing.yaml"
- "!include laplace_coin_gecko.yaml"
- "!include laplace_coin_gecko_archive.yaml"
- "!include laplace_config_contracts.yaml"
- "!include laplace_contract_calls.yaml"
- "!include laplace_current_token_price.yaml"
- "!include laplace_deployed_contracts.yaml"
- "!include laplace_external_token_price.yaml"
- "!include laplace_fixed_weight_pool_v1_01.yaml"
- "!include laplace_history_staking_stats.yaml"
- "!include laplace_ido_pool_creation.yaml"
- "!include laplace_ido_register.yaml"
- "!include laplace_latest_alex_reserve_pools.yaml"
- "!include laplace_latest_auto_alex.yaml"
- "!include laplace_latest_fixed_weight_pool_v1_01.yaml"
- "!include laplace_latest_pool_stats.yaml"
- "!include laplace_latest_simple_weight_pool_alex.yaml"
- "!include laplace_oracle_token_price.yaml"
- "!include laplace_pool_stats.yaml"
- "!include laplace_reward_cycle_stats.yaml"
- "!include laplace_simple_weight_pool_alex.yaml"
- "!include laplace_stacks_blockchain_events.yaml"
- "!include laplace_swap_records.yaml"
- "!include laplace_sync_status.yaml"
- "!include laplace_synced_blocks.yaml"
- "!include laplace_token_stats.yaml"
- "!include public_blocks.yaml"
- "!include public_contract_logs.yaml"
- "!include public_ft_events.yaml"
- "!include public_smart_contracts.yaml"
- "!include public_stx_events.yaml"
- "!include public_dbt_autoalex_apower_distribution.yaml"
- "!include public_dbt_autoalex_claim_and_stake.yaml"
- "!include public_dbt_autoalex_snapshot_config.yaml"
- "!include public_dbt_dim_balance_alex_staked_lockdrop_offets.yaml"
- "!include public_dbt_dim_balance_autoalex_apower_distribution.yaml"
- "!include public_dbt_dim_balance_autoalex_rank_on_height_view.yaml"
- "!include public_dbt_dim_balance_autoalex_rank_snapshot_view.yaml"
- "!include public_dbt_dim_balance_autoalex_rank_view.yaml"
- "!include public_transform_txs_view.yaml"

View File

@@ -0,0 +1 @@
disabled_for_roles: []

View File

@@ -0,0 +1 @@
[]

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,141 @@
- name: allowed-queries
definition:
queries:
- name: oracle_price/alex
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"age000-governance-token"}}) {
avg_price_usd
token
}
}
- name: oracle_price/banana
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wban"}}) {
avg_price_usd
token
}
}
- name: external_price/diko
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wdiko"}}) {
avg_price_usd
token
}
}
- name: external_price/btc
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wbtc"}}) {
avg_price_usd
token
}
}
- name: external_price/xbtc
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-xbtc"}}) {
avg_price_usd
token
}
}
- name: external_price/usda
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wusda"}}) {
avg_price_usd
token
}
}
- name: external_price/wmia
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wmia"}}) {
avg_price_usd
token
}
}
- name: external_price/usdc
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-usdc"}}) {
avg_price_usd
token
}
}
- name: external_price/stx
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wstx"}}) {
avg_price_usd
token
}
}
- name: oracle_price/wxusd
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wxusd-oracle"}}) {
avg_price_usd
token
}
}
- name: oracle_price/wslm
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wslm"}}) {
avg_price_usd
token
}
}
- name: external_price/wxusd
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wxusd"}}) {
avg_price_usd
token
}
}
- name: oracle_price/autoalex
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"auto-alex"}}) {
avg_price_usd
token
}
}
- name: pool_stats/total_supply/fwp-wstx-alex-50-50-v1-01
query: |
query get_total_supply {
laplace_latest_pool_stats(where: {pool_token:{_eq:"fwp-wstx-alex-50-50-v1-01"}}) {
pool_token
total_supply
}
}
- name: external_price/mia
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wmia"}}) {
avg_price_usd
token
}
}
- name: external_price/nycc
query: |
query get_price {
laplace_current_token_price(where: {token:{_eq:"token-wnycc"}}) {
avg_price_usd
token
}
}
- name: token_stats/total_supply
query: |
query getTotalSupply($token: String) {
laplace_token_stats(where: {token_name: {_eq: $token}}) {
token_name
block_height
decimals
total_supply
}
}

View File

@@ -0,0 +1,8 @@
- name: Contentful
definition:
url: https://graphql.contentful.com/content/v1/spaces/frwmwlognk87
timeout_seconds: 60
headers:
- value: Bearer riV3KvByaEvfPP9Ko_gUBMS9qRS3SPajXZ0nEoaZ4bY
name: Authorization
comment: ""

View File

@@ -0,0 +1,153 @@
- definition:
query:
collection_name: allowed-queries
query_name: external_price/btc
url: external_price/btc
methods:
- GET
name: external_price/btc
comment: external_price/btc
- definition:
query:
collection_name: allowed-queries
query_name: external_price/diko
url: external_price/diko
methods:
- GET
name: external_price/diko
comment: external_price/diko
- definition:
query:
collection_name: allowed-queries
query_name: external_price/wmia
url: external_price/wmia
methods:
- GET
name: external_price/wmia
comment: external_price/wmia
- definition:
query:
collection_name: allowed-queries
query_name: external_price/stx
url: external_price/stx
methods:
- GET
name: external_price/stx
comment: external_price/stx
- definition:
query:
collection_name: allowed-queries
query_name: external_price/usda
url: external_price/usda
methods:
- GET
name: external_price/usda
comment: external_price/usda
- definition:
query:
collection_name: allowed-queries
query_name: external_price/usdc
url: external_price/usdc
methods:
- GET
name: external_price/usdc
comment: external_price/usdc
- definition:
query:
collection_name: allowed-queries
query_name: external_price/xbtc
url: external_price/xbtc
methods:
- GET
name: external_price/xbtc
comment: external_price/xbtc
- definition:
query:
collection_name: allowed-queries
query_name: oracle_price/alex
url: oracle_price/alex
methods:
- GET
name: oracle_price/alex
comment: oracle_price/alex
- definition:
query:
collection_name: allowed-queries
query_name: oracle_price/banana
url: oracle_price/banana
methods:
- GET
name: oracle_price/banana
comment: oracle_price/banana
- definition:
query:
collection_name: allowed-queries
query_name: oracle_price/wxusd
url: oracle_price/wxusd
methods:
- GET
name: oracle_price/wxusd
comment: oracle_price/wxusd
- definition:
query:
collection_name: allowed-queries
query_name: oracle_price/wslm
url: oracle_price/wslm
methods:
- GET
name: oracle_price/wslm
comment: oracle_price/wslm
- definition:
query:
collection_name: allowed-queries
query_name: external_price/wxusd
url: external_price/wxusd
methods:
- GET
name: external_price/wxusd
comment: external_price/wxusd
- definition:
query:
collection_name: allowed-queries
query_name: external_price/mia
url: external_price/mia
methods:
- GET
name: external_price/mia
comment: external_price/mia
- definition:
query:
collection_name: allowed-queries
query_name: external_price/nycc
url: external_price/nycc
methods:
- GET
name: external_price/nycc
comment: external_price/nycc
- definition:
query:
collection_name: allowed-queries
query_name: oracle_price/autoalex
url: oracle_price/autoalex
methods:
- GET
name: oracle_price/autoalex
comment: oracle_price/autoalex
- definition:
query:
collection_name: allowed-queries
query_name: pool_stats/total_supply/fwp-wstx-alex-50-50-v1-01
url: pool_stats/total_supply/fwp-wstx-alex-50-50-v1-01
methods:
- GET
name: pool_stats/total_supply/fwp-wstx-alex-50-50-v1-01
comment: pool_stats/total_supply/fwp-wstx-alex-50-50-v1-01
- definition:
query:
collection_name: allowed-queries
query_name: token_stats/total_supply
url: token_stats/total_supply/:token
methods:
- GET
name: token_stats/total_supply
comment: token_stats/total_supply

View File

@@ -0,0 +1 @@
version: 3

View File

@@ -0,0 +1,680 @@
SET check_function_bodies = false;
CREATE SCHEMA laplace;
CREATE TABLE laplace.coin_gecko (
token character varying NOT NULL,
coin_gecko_id character varying NOT NULL,
market_cap jsonb NOT NULL,
prices_market jsonb NOT NULL,
ccy jsonb NOT NULL,
avg_price_usd double precision NOT NULL,
"timestamp" timestamp with time zone NOT NULL
);
CREATE TABLE laplace.oracle_instant_fwp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
token_x character varying NOT NULL,
token_y character varying NOT NULL,
weight_x character varying NOT NULL,
weight_y character varying NOT NULL,
value character varying NOT NULL,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.oracle_instant_fwp IS 'ALEX fixed-weight-pool oracle-instant price time series data';
CREATE VIEW laplace.alex_usd_pricing AS
SELECT 'age000-governance-token'::text AS token,
(( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)) / ( SELECT ((oracle_instant_fwp.value)::double precision / ('100000000'::numeric)::double precision)
FROM laplace.oracle_instant_fwp
WHERE (((oracle_instant_fwp.token_x)::text = 'token-wstx'::text) AND ((oracle_instant_fwp.token_y)::text = 'age000-governance-token'::text) AND ((oracle_instant_fwp.contract_name)::text = 'fixed-weight-pool-v1-01'::text) AND (oracle_instant_fwp.block_height = ( SELECT max(oracle_instant_fwp_1.block_height) AS max
FROM laplace.oracle_instant_fwp oracle_instant_fwp_1))))) AS avg_price_usd;
CREATE TABLE laplace.coin_gecko_archive (
token character varying NOT NULL,
coin_gecko_id character varying NOT NULL,
market_cap jsonb NOT NULL,
prices_market jsonb NOT NULL,
ccy jsonb NOT NULL,
avg_price_usd double precision NOT NULL,
"timestamp" timestamp with time zone NOT NULL
);
COMMENT ON TABLE laplace.coin_gecko_archive IS 'ALEX Coingecko price time series data';
CREATE TABLE laplace.config_contracts (
contract character varying,
full_name character varying
);
CREATE TABLE laplace.deployed_contracts (
tx_id character varying NOT NULL,
deployer_address character varying NOT NULL,
contract_type character varying NOT NULL,
contract_name character varying NOT NULL,
data_type character varying NOT NULL,
block_height character varying NOT NULL
);
COMMENT ON TABLE laplace.deployed_contracts IS 'ALEX deployed contracts relevant to ALEX app';
CREATE TABLE laplace.dynamic_ltv_crp (
contract_name character varying DEFAULT 'collateral-rebalancing-pool'::character varying NOT NULL,
function_name character varying DEFAULT 'get-ltv'::character varying NOT NULL,
token character varying NOT NULL,
collateral character varying NOT NULL,
expiry bigint NOT NULL,
value character varying NOT NULL,
clarity_type character varying NOT NULL,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.dynamic_ltv_crp IS 'ALEX LTV data from collateral-rebalancing-pool time series data';
CREATE TABLE laplace.dynamic_position_crp (
contract_name character varying DEFAULT 'collateral-rebalancing-pool'::character varying NOT NULL,
function_name character varying DEFAULT 'get-position-given-burn-key'::character varying NOT NULL,
token character varying NOT NULL,
collateral character varying NOT NULL,
expiry bigint NOT NULL,
dx character varying NOT NULL,
dy character varying NOT NULL,
clarity_type_dx character varying NOT NULL,
clarity_type_dy character varying NOT NULL,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.dynamic_position_crp IS 'ALEX position-given-burn-key data from collateral-rebalancing-pool time series data';
CREATE TABLE laplace.dynamic_price_ytp (
contract_name character varying DEFAULT 'yield-token-pool'::character varying NOT NULL,
function_name character varying DEFAULT 'get-price'::character varying NOT NULL,
yield_token character varying NOT NULL,
expiry bigint NOT NULL,
value character varying NOT NULL,
clarity_type character varying NOT NULL,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.dynamic_price_ytp IS 'ALEX price data from yield-token-pool time series data';
CREATE TABLE laplace.dynamic_y_given_x_fwp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
token_x character varying NOT NULL,
token_y character varying NOT NULL,
weight_x bigint NOT NULL,
weight_y bigint NOT NULL,
value character varying NOT NULL,
clarity_type character varying NOT NULL,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.dynamic_y_given_x_fwp IS 'ALEX y_given_x data from fixed-weight-pool time series data';
CREATE TABLE laplace.dynamic_yield_ytp (
contract_name character varying DEFAULT 'yield-token-pool'::character varying NOT NULL,
function_name character varying DEFAULT 'get-yield'::character varying NOT NULL,
yield_token character varying NOT NULL,
expiry bigint NOT NULL,
value character varying NOT NULL,
clarity_type character varying NOT NULL,
block_height integer NOT NULL,
apy character varying
);
COMMENT ON TABLE laplace.dynamic_yield_ytp IS 'ALEX yield data from yield-token-pool time series data';
CREATE TABLE laplace.pool_details_fwp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
block_height integer NOT NULL,
time_stamp timestamp with time zone NOT NULL,
token_x character varying NOT NULL,
token_y character varying NOT NULL,
weight_x character varying NOT NULL,
weight_y character varying NOT NULL,
pool_token character varying NOT NULL,
fee_to_address character varying NOT NULL,
oracle_enabled character varying NOT NULL,
balance_x bigint,
balance_y bigint,
fee_rate_x bigint,
fee_rate_y bigint,
fee_rebate bigint,
oracle_average bigint,
oracle_resilient bigint,
total_supply bigint
);
COMMENT ON TABLE laplace.pool_details_fwp IS 'ALEX fixed-weight-pool time series data';
CREATE MATERIALIZED VIEW laplace.fwp_liquidity AS
WITH fwp_detail AS (
SELECT pool_details_fwp.contract_name,
pool_details_fwp.function_name,
pool_details_fwp.block_height,
pool_details_fwp.time_stamp,
pool_details_fwp.token_x,
pool_details_fwp.token_y,
pool_details_fwp.weight_x,
pool_details_fwp.weight_y,
pool_details_fwp.pool_token,
pool_details_fwp.fee_to_address,
pool_details_fwp.oracle_enabled,
pool_details_fwp.balance_x,
pool_details_fwp.balance_y,
pool_details_fwp.fee_rate_x,
pool_details_fwp.fee_rate_y,
pool_details_fwp.fee_rebate,
pool_details_fwp.oracle_average,
pool_details_fwp.oracle_resilient,
pool_details_fwp.total_supply
FROM laplace.pool_details_fwp
WHERE (pool_details_fwp.block_height = ( SELECT max(pool_details_fwp_1.block_height) AS max
FROM laplace.pool_details_fwp pool_details_fwp_1))
), coin_gecko_view AS (
SELECT coin_gecko.token,
coin_gecko.avg_price_usd
FROM laplace.coin_gecko
UNION ALL
SELECT 'age000-governance-token'::character varying AS token,
(( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)) / ( SELECT ((oracle_instant_fwp.value)::double precision / ('100000000'::numeric)::double precision)
FROM laplace.oracle_instant_fwp
WHERE (((oracle_instant_fwp.token_x)::text = 'token-wstx'::text) AND ((oracle_instant_fwp.token_y)::text = 'age000-governance-token'::text) AND (oracle_instant_fwp.block_height = ( SELECT max(oracle_instant_fwp_1.block_height) AS max
FROM laplace.oracle_instant_fwp oracle_instant_fwp_1))))) AS avg_price_usd
)
SELECT fwp_detail.contract_name,
fwp_detail.token_x,
fwp_detail.token_y,
((fwp_detail.weight_x)::double precision / ('100000000'::numeric)::double precision) AS weight_x,
((fwp_detail.weight_y)::double precision / ('100000000'::numeric)::double precision) AS weight_y,
((((fwp_detail.balance_x)::double precision * ( SELECT coin_gecko_view.avg_price_usd
FROM coin_gecko_view
WHERE ((coin_gecko_view.token)::text = (fwp_detail.token_x)::text))) + ((fwp_detail.balance_y)::double precision * ( SELECT coin_gecko_view.avg_price_usd
FROM coin_gecko_view
WHERE ((coin_gecko_view.token)::text = (fwp_detail.token_y)::text)))) / ('100000000'::numeric)::double precision) AS liquidity
FROM fwp_detail
WITH NO DATA;
CREATE TABLE laplace.staking_data (
token character varying NOT NULL,
current_cycle integer NOT NULL,
cycle integer NOT NULL,
block_height integer NOT NULL,
staking_stats bigint NOT NULL,
coinbase_amount bigint NOT NULL,
apr numeric NOT NULL
);
COMMENT ON TABLE laplace.staking_data IS 'ALEX staking time series data';
CREATE MATERIALIZED VIEW laplace.farming_details AS
SELECT 'fwp-wstx-alex-50-50-v1-01'::text AS pool_token,
( SELECT fwp_liquidity.liquidity
FROM laplace.fwp_liquidity
WHERE (((fwp_liquidity.token_x)::text = 'token-wstx'::text) AND ((fwp_liquidity.token_y)::text = 'age000-governance-token'::text) AND ((fwp_liquidity.contract_name)::text = 'fixed-weight-pool-v1-01'::text))) AS liquidity,
( SELECT (sum((aprs.apr)::double precision) / (32)::double precision)
FROM ( SELECT staking_data.apr
FROM laplace.staking_data
WHERE (staking_data.block_height = ( SELECT max(staking_data_1.block_height) AS max
FROM laplace.staking_data staking_data_1))) aprs) AS apr,
'ALEX'::text AS reward
UNION
SELECT 'fwp-wstx-wbtc-50-50-v1-01'::text AS pool_token,
( SELECT fwp_liquidity.liquidity
FROM laplace.fwp_liquidity
WHERE (((fwp_liquidity.token_x)::text = 'token-wstx'::text) AND ((fwp_liquidity.token_y)::text = 'token-wbtc'::text) AND ((fwp_liquidity.contract_name)::text = 'fixed-weight-pool-v1-01'::text))) AS liquidity,
( SELECT (sum((aprs.apr)::double precision) / (32)::double precision)
FROM ( SELECT staking_data.apr
FROM laplace.staking_data
WHERE (staking_data.block_height = ( SELECT max(staking_data_1.block_height) AS max
FROM laplace.staking_data staking_data_1))) aprs) AS apr,
'ALEX'::text AS reward
WITH NO DATA;
CREATE TABLE laplace.static_data_fwp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
value character varying NOT NULL,
token_x character varying NOT NULL,
token_y character varying NOT NULL,
weight_x character varying NOT NULL,
weight_y character varying NOT NULL,
clarity_type character varying,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.static_data_fwp IS 'ALEX static data';
CREATE MATERIALIZED VIEW laplace.wstx_alex_pool_volume AS
WITH stx_in_alex_out_txs AS (
SELECT t.sender_address,
encode(t.tx_id, 'hex'::text) AS tx_id,
(((((t.function_args -> 'args'::text) -> 4) ->> 'value'::text))::double precision / (100000000)::double precision) AS input_amount,
CASE
WHEN (((t.transaction_result -> 'value'::text) ->> 'type'::text) = 'UInt'::text) THEN ((((t.transaction_result -> 'value'::text) ->> 'value'::text))::double precision / (100000000)::double precision)
WHEN (((t.transaction_result -> 'value'::text) ->> 'type'::text) = 'Tuple'::text) THEN ((((((t.transaction_result -> 'value'::text) -> 'value'::text) -> 'dy'::text) ->> 'value'::text))::double precision / (100000000)::double precision)
ELSE (0)::double precision
END AS output_amount,
t.transaction_result,
t.id,
(to_timestamp((t.burn_block_time)::double precision) AT TIME ZONE 'CCT'::text) AS burn_block_time,
t.block_height
FROM public_transform.txs_view t
WHERE (((t.transaction_result ->> 'type'::text) = 'ResponseOk'::text) AND (t.contract_call_contract_id = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'fixed-weight-pool-v1-01'::text)))::text) AND (((t.contract_call_function_name = 'swap-helper'::text) AND ((((t.function_args -> 'args'::text) -> 1) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'age000-governance-token'::text)))::text) AND ((((t.function_args -> 'args'::text) -> 0) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wstx'::text)))::text)) OR ((t.contract_call_function_name = 'swap-x-for-y'::text) AND ((((t.function_args -> 'args'::text) -> 1) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'age000-governance-token'::text)))::text) AND ((((t.function_args -> 'args'::text) -> 0) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wstx'::text)))::text))) AND (t.canonical = true) AND (t.microblock_canonical = true))
), stx_out_alex_in_txs AS (
SELECT t.sender_address,
encode(t.tx_id, 'hex'::text) AS tx_id,
(((((t.function_args -> 'args'::text) -> 4) ->> 'value'::text))::double precision / (100000000)::double precision) AS input_amount,
CASE
WHEN (((t.transaction_result -> 'value'::text) ->> 'type'::text) = 'UInt'::text) THEN ((((t.transaction_result -> 'value'::text) ->> 'value'::text))::double precision / (100000000)::double precision)
WHEN (((t.transaction_result -> 'value'::text) ->> 'type'::text) = 'Tuple'::text) THEN ((((((t.transaction_result -> 'value'::text) -> 'value'::text) -> 'dy'::text) ->> 'value'::text))::double precision / (100000000)::double precision)
ELSE (0)::double precision
END AS output_amount,
t.transaction_result,
t.id,
(to_timestamp((t.burn_block_time)::double precision) AT TIME ZONE 'CCT'::text) AS burn_block_time,
t.block_height
FROM public_transform.txs_view t
WHERE (((t.transaction_result ->> 'type'::text) = 'ResponseOk'::text) AND (t.contract_call_contract_id = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'fixed-weight-pool-v1-01'::text)))::text) AND (((t.contract_call_function_name = 'swap-helper'::text) AND ((((t.function_args -> 'args'::text) -> 1) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wstx'::text)))::text) AND ((((t.function_args -> 'args'::text) -> 0) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'age000-governance-token'::text)))::text)) OR ((t.contract_call_function_name = 'swap-y-for-x'::text) AND ((((t.function_args -> 'args'::text) -> 1) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wstx'::text)))::text) AND ((((t.function_args -> 'args'::text) -> 0) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'age000-governance-token'::text)))::text))) AND (t.canonical = true) AND (t.microblock_canonical = true))
)
SELECT 'wstx-alex-pool'::text AS pool_name,
volume.time_range,
sum(volume.wstx_volume) AS wstx_volume,
sum(volume.alex_volume) AS alex_volume,
sum((volume.wstx_volume + volume.alex_volume)) AS total_volume
FROM ((
SELECT sum((stx_in_alex_out_txs.input_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)))) AS wstx_volume,
sum((stx_in_alex_out_txs.output_amount * ( SELECT alex_usd_pricing.avg_price_usd
FROM laplace.alex_usd_pricing
WHERE (alex_usd_pricing.token = 'age000-governance-token'::text)))) AS alex_volume,
'24hrs'::text AS time_range
FROM stx_in_alex_out_txs
WHERE (stx_in_alex_out_txs.burn_block_time > (CURRENT_TIMESTAMP - '24:00:00'::interval))
UNION
SELECT sum((stx_in_alex_out_txs.input_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)))) AS wstx_volume,
sum((stx_in_alex_out_txs.output_amount * ( SELECT alex_usd_pricing.avg_price_usd
FROM laplace.alex_usd_pricing
WHERE (alex_usd_pricing.token = 'age000-governance-token'::text)))) AS alex_volume,
'7days'::text AS time_range
FROM stx_in_alex_out_txs
WHERE (stx_in_alex_out_txs.burn_block_time > (CURRENT_TIMESTAMP - '7 days'::interval))
) UNION ALL (
SELECT sum((stx_out_alex_in_txs.output_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)))) AS wstx_volume,
sum((stx_out_alex_in_txs.input_amount * ( SELECT alex_usd_pricing.avg_price_usd
FROM laplace.alex_usd_pricing
WHERE (alex_usd_pricing.token = 'age000-governance-token'::text)))) AS alex_volume,
'24hrs'::text AS time_range
FROM stx_out_alex_in_txs
WHERE (stx_out_alex_in_txs.burn_block_time > (CURRENT_TIMESTAMP - '24:00:00'::interval))
UNION
SELECT sum((stx_out_alex_in_txs.output_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)))) AS wstx_volume,
sum((stx_out_alex_in_txs.input_amount * ( SELECT alex_usd_pricing.avg_price_usd
FROM laplace.alex_usd_pricing
WHERE (alex_usd_pricing.token = 'age000-governance-token'::text)))) AS alex_volume,
'7days'::text AS time_range
FROM stx_out_alex_in_txs
WHERE (stx_out_alex_in_txs.burn_block_time > (CURRENT_TIMESTAMP - '7 days'::interval))
)) volume
GROUP BY volume.time_range
WITH NO DATA;
CREATE MATERIALIZED VIEW laplace.wstx_wbtc_pool_volume AS
WITH stx_in_btc_out_txs AS (
SELECT t.sender_address,
encode(t.tx_id, 'hex'::text) AS tx_id,
(((((t.function_args -> 'args'::text) -> 4) ->> 'value'::text))::double precision / (100000000)::double precision) AS input_amount,
CASE
WHEN (((t.transaction_result -> 'value'::text) ->> 'type'::text) = 'UInt'::text) THEN ((((t.transaction_result -> 'value'::text) ->> 'value'::text))::double precision / (100000000)::double precision)
WHEN (((t.transaction_result -> 'value'::text) ->> 'type'::text) = 'Tuple'::text) THEN ((((((t.transaction_result -> 'value'::text) -> 'value'::text) -> 'dy'::text) ->> 'value'::text))::double precision / (100000000)::double precision)
ELSE (0)::double precision
END AS output_amount,
t.transaction_result,
t.id,
(to_timestamp((t.burn_block_time)::double precision) AT TIME ZONE 'CCT'::text) AS burn_block_time,
t.block_height
FROM public_transform.txs_view t
WHERE (((t.transaction_result ->> 'type'::text) = 'ResponseOk'::text) AND (t.contract_call_contract_id = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'fixed-weight-pool-v1-01'::text)))::text) AND (((t.contract_call_function_name = 'swap-helper'::text) AND ((((t.function_args -> 'args'::text) -> 1) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wbtc'::text)))::text) AND ((((t.function_args -> 'args'::text) -> 0) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wstx'::text)))::text)) OR ((t.contract_call_function_name = 'swap-x-for-y'::text) AND ((((t.function_args -> 'args'::text) -> 1) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wbtc'::text)))::text) AND ((((t.function_args -> 'args'::text) -> 0) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wstx'::text)))::text))) AND (t.canonical = true) AND (t.microblock_canonical = true) AND (t.status = 1))
), stx_out_btc_in_txs AS (
SELECT t.sender_address,
encode(t.tx_id, 'hex'::text) AS tx_id,
(((((t.function_args -> 'args'::text) -> 4) ->> 'value'::text))::double precision / (100000000)::double precision) AS input_amount,
CASE
WHEN (((t.transaction_result -> 'value'::text) ->> 'type'::text) = 'UInt'::text) THEN ((((t.transaction_result -> 'value'::text) ->> 'value'::text))::double precision / (100000000)::double precision)
WHEN (((t.transaction_result -> 'value'::text) ->> 'type'::text) = 'Tuple'::text) THEN ((((((t.transaction_result -> 'value'::text) -> 'value'::text) -> 'dy'::text) ->> 'value'::text))::double precision / (100000000)::double precision)
ELSE (0)::double precision
END AS output_amount,
t.transaction_result,
t.id,
(to_timestamp((t.burn_block_time)::double precision) AT TIME ZONE 'CCT'::text) AS burn_block_time,
t.block_height
FROM public_transform.txs_view t
WHERE (((t.transaction_result ->> 'type'::text) = 'ResponseOk'::text) AND (t.contract_call_contract_id = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'fixed-weight-pool-v1-01'::text)))::text) AND (((t.contract_call_function_name = 'swap-helper'::text) AND ((((t.function_args -> 'args'::text) -> 1) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wstx'::text)))::text) AND ((((t.function_args -> 'args'::text) -> 0) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wbtc'::text)))::text)) OR ((t.contract_call_function_name = 'swap-y-for-x'::text) AND ((((t.function_args -> 'args'::text) -> 1) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wstx'::text)))::text) AND ((((t.function_args -> 'args'::text) -> 0) ->> 'value'::text) = (( SELECT config_contracts.full_name
FROM laplace.config_contracts
WHERE ((config_contracts.contract)::text = 'token-wbtc'::text)))::text))) AND (t.canonical = true) AND (t.microblock_canonical = true) AND (t.status = 1))
)
SELECT 'wstx-wbtc-pool'::text AS pool_name,
volume.time_range,
sum(volume.wstx_volume) AS wstx_volume,
sum(volume.alex_volume) AS alex_volume,
sum((volume.wstx_volume + volume.alex_volume)) AS total_volume
FROM ((
SELECT sum((stx_in_btc_out_txs.input_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)))) AS wstx_volume,
sum((stx_in_btc_out_txs.output_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-xbtc'::text)))) AS alex_volume,
'24hrs'::text AS time_range
FROM stx_in_btc_out_txs
WHERE (stx_in_btc_out_txs.burn_block_time > (CURRENT_TIMESTAMP - '24:00:00'::interval))
UNION
SELECT sum((stx_in_btc_out_txs.input_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)))) AS wstx_volume,
sum((stx_in_btc_out_txs.output_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-xbtc'::text)))) AS alex_volume,
'7days'::text AS time_range
FROM stx_in_btc_out_txs
WHERE (stx_in_btc_out_txs.burn_block_time > (CURRENT_TIMESTAMP - '7 days'::interval))
) UNION ALL (
SELECT sum((stx_out_btc_in_txs.output_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)))) AS wstx_volume,
sum((stx_out_btc_in_txs.input_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-xbtc'::text)))) AS alex_volume,
'24hrs'::text AS time_range
FROM stx_out_btc_in_txs
WHERE (stx_out_btc_in_txs.burn_block_time > (CURRENT_TIMESTAMP - '24:00:00'::interval))
UNION
SELECT sum((stx_out_btc_in_txs.output_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)))) AS wstx_volume,
sum((stx_out_btc_in_txs.input_amount * ( SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-xbtc'::text)))) AS alex_volume,
'7days'::text AS time_range
FROM stx_out_btc_in_txs
WHERE (stx_out_btc_in_txs.burn_block_time > (CURRENT_TIMESTAMP - '7 days'::interval))
)) volume
GROUP BY volume.time_range
WITH NO DATA;
CREATE MATERIALIZED VIEW laplace.liquidity_details AS
WITH liquidity_table AS (
SELECT 'fwp-wstx-alex-50-50-v1-01'::text AS token_name,
( SELECT wstx_alex_pool_volume.total_volume
FROM laplace.wstx_alex_pool_volume
WHERE (wstx_alex_pool_volume.time_range = '24hrs'::text)) AS volume_24h,
( SELECT wstx_alex_pool_volume.total_volume
FROM laplace.wstx_alex_pool_volume
WHERE (wstx_alex_pool_volume.time_range = '7days'::text)) AS volume_7d,
((((( SELECT static_data_fwp.value
FROM laplace.static_data_fwp
WHERE (((static_data_fwp.function_name)::text = 'get-fee-rate-x'::text) AND ((static_data_fwp.token_x)::text = 'token-wstx'::text) AND ((static_data_fwp.token_y)::text = 'age000-governance-token'::text) AND ((static_data_fwp.contract_name)::text = 'fixed-weight-pool-v1-01'::text))))::double precision / (1000000)::double precision) + ((( SELECT static_data_fwp.value
FROM laplace.static_data_fwp
WHERE (((static_data_fwp.function_name)::text = 'get-fee-rate-y'::text) AND ((static_data_fwp.token_x)::text = 'token-wstx'::text) AND ((static_data_fwp.token_y)::text = 'age000-governance-token'::text) AND ((static_data_fwp.contract_name)::text = 'fixed-weight-pool-v1-01'::text))))::double precision / (1000000)::double precision)) / (2)::double precision) AS item_fees,
( SELECT fwp_liquidity.liquidity
FROM laplace.fwp_liquidity
WHERE (((fwp_liquidity.token_x)::text = 'token-wstx'::text) AND ((fwp_liquidity.token_y)::text = 'age000-governance-token'::text) AND ((fwp_liquidity.contract_name)::text = 'fixed-weight-pool-v1-01'::text))) AS liquidity
UNION
SELECT 'fwp-wstx-wbtc-50-50-v1-01'::text AS token_name,
( SELECT wstx_wbtc_pool_volume.total_volume
FROM laplace.wstx_wbtc_pool_volume
WHERE (wstx_wbtc_pool_volume.time_range = '24hrs'::text)) AS volume_24h,
( SELECT wstx_wbtc_pool_volume.total_volume
FROM laplace.wstx_wbtc_pool_volume
WHERE (wstx_wbtc_pool_volume.time_range = '7days'::text)) AS volume_7d,
((((( SELECT static_data_fwp.value
FROM laplace.static_data_fwp
WHERE (((static_data_fwp.function_name)::text = 'get-fee-rate-x'::text) AND ((static_data_fwp.token_x)::text = 'token-wstx'::text) AND ((static_data_fwp.token_y)::text = 'token-wbtc'::text) AND ((static_data_fwp.contract_name)::text = 'fixed-weight-pool-v1-01'::text))))::double precision / (1000000)::double precision) + ((( SELECT static_data_fwp.value
FROM laplace.static_data_fwp
WHERE (((static_data_fwp.function_name)::text = 'get-fee-rate-y'::text) AND ((static_data_fwp.token_x)::text = 'token-wstx'::text) AND ((static_data_fwp.token_y)::text = 'token-wbtc'::text) AND ((static_data_fwp.contract_name)::text = 'fixed-weight-pool-v1-01'::text))))::double precision / (1000000)::double precision)) / (2)::double precision) AS item_fees,
( SELECT fwp_liquidity.liquidity
FROM laplace.fwp_liquidity
WHERE (((fwp_liquidity.token_x)::text = 'token-wstx'::text) AND ((fwp_liquidity.token_y)::text = 'token-wbtc'::text) AND ((fwp_liquidity.contract_name)::text = 'fixed-weight-pool-v1-01'::text))) AS liquidity
)
SELECT liquidity_table.token_name,
liquidity_table.volume_24h,
liquidity_table.volume_7d,
liquidity_table.item_fees,
liquidity_table.liquidity,
((liquidity_table.item_fees / liquidity_table.liquidity) * (52)::double precision) AS apr
FROM liquidity_table
WITH NO DATA;
CREATE TABLE laplace.oracle_instant_ytp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
yield_token character varying NOT NULL,
expiry character varying NOT NULL,
value character varying NOT NULL,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.oracle_instant_ytp IS 'ALEX yield-token-pool oracle-instant price time series data';
CREATE TABLE laplace.oracle_resilient_fwp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
token_x character varying NOT NULL,
token_y character varying NOT NULL,
weight_x character varying NOT NULL,
weight_y character varying NOT NULL,
value character varying NOT NULL,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.oracle_resilient_fwp IS 'ALEX fixed-weight-pool oracle-resilient price time series data';
CREATE TABLE laplace.oracle_resilient_ytp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
yield_token character varying NOT NULL,
expiry character varying NOT NULL,
value character varying NOT NULL,
block_height integer NOT NULL
);
COMMENT ON TABLE laplace.oracle_resilient_ytp IS 'ALEX yield-token-pool oracle-resilient price time series data';
CREATE TABLE laplace.pool_details_crp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
balance_x character varying NOT NULL,
balance_y character varying NOT NULL,
bs_vol character varying NOT NULL,
conversion_ltv character varying NOT NULL,
fee_rate_x character varying NOT NULL,
fee_rate_y character varying NOT NULL,
fee_rebate character varying NOT NULL,
fee_to_address character varying NOT NULL,
key_supply character varying NOT NULL,
key_token character varying NOT NULL,
ltv_0 character varying NOT NULL,
moving_average character varying NOT NULL,
token_to_maturity character varying NOT NULL,
weight_x character varying NOT NULL,
weight_y character varying NOT NULL,
yield_supply character varying NOT NULL,
yield_token character varying NOT NULL,
block_height integer NOT NULL,
time_stamp timestamp with time zone NOT NULL,
collateral character varying NOT NULL,
token character varying NOT NULL,
expiry character varying NOT NULL,
strike character varying
);
COMMENT ON TABLE laplace.pool_details_crp IS 'ALEX collateral-rebalancing-pool time series data';
CREATE TABLE laplace.pool_details_ytp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
block_height integer NOT NULL,
time_stamp timestamp with time zone NOT NULL,
yield_token character varying NOT NULL,
expiry character varying NOT NULL,
balance_token character varying NOT NULL,
balance_virtual character varying NOT NULL,
balance_yield_token character varying NOT NULL,
fee_rate_token character varying NOT NULL,
fee_rate_yield_token character varying NOT NULL,
fee_rebate character varying NOT NULL,
fee_to_address character varying NOT NULL,
listed character varying NOT NULL,
oracle_average character varying NOT NULL,
oracle_enabled character varying NOT NULL,
oracle_resilient character varying NOT NULL,
pool_token character varying NOT NULL,
token_trait character varying NOT NULL,
total_supply character varying NOT NULL
);
COMMENT ON TABLE laplace.pool_details_ytp IS 'ALEX yield-token-pool time series data';
CREATE TABLE laplace.reward_cycle_stats (
token character varying NOT NULL,
block_height bigint NOT NULL,
payload jsonb NOT NULL,
cycle bigint NOT NULL
);
CREATE TABLE laplace.stacks_blockchain_events (
id integer NOT NULL,
event_path character varying(450),
payload jsonb
);
CREATE SEQUENCE laplace.stacks_blockchain_events_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE laplace.stacks_blockchain_events_id_seq OWNED BY laplace.stacks_blockchain_events.id;
CREATE TABLE laplace.static_data_ytp (
contract_name character varying NOT NULL,
function_name character varying NOT NULL,
block_height integer NOT NULL,
yield_token character varying NOT NULL,
expiry bigint NOT NULL,
value character varying NOT NULL,
clarity_type character varying NOT NULL
);
COMMENT ON TABLE laplace.static_data_ytp IS 'ALEX yield-token pool static data ';
CREATE TABLE laplace.sync_status (
key character varying(64) NOT NULL,
value text NOT NULL
);
CREATE TABLE laplace.transaction_logs (
tx_id character varying NOT NULL,
block_height integer NOT NULL,
contract_id character varying NOT NULL,
function_name character varying NOT NULL,
sender character varying NOT NULL,
sold_token character varying,
bought_token character varying,
time_stamp timestamp with time zone NOT NULL,
id integer NOT NULL,
tx_cost bigint,
sold_quantity numeric,
bought_quantity numeric
);
COMMENT ON TABLE laplace.transaction_logs IS 'ALEX transaction logs for all relevant ALEX contract';
CREATE SEQUENCE laplace.transaction_logs_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE laplace.transaction_logs_id_seq OWNED BY laplace.transaction_logs.id;
CREATE MATERIALIZED VIEW laplace.ytp_liquidity AS
WITH ytp_detail AS (
SELECT pool_details_ytp.contract_name,
pool_details_ytp.function_name,
pool_details_ytp.block_height,
pool_details_ytp.time_stamp,
pool_details_ytp.yield_token,
pool_details_ytp.expiry,
pool_details_ytp.balance_token,
pool_details_ytp.balance_virtual,
pool_details_ytp.balance_yield_token,
pool_details_ytp.fee_rate_token,
pool_details_ytp.fee_rate_yield_token,
pool_details_ytp.fee_rebate,
pool_details_ytp.fee_to_address,
pool_details_ytp.listed,
pool_details_ytp.oracle_average,
pool_details_ytp.oracle_enabled,
pool_details_ytp.oracle_resilient,
pool_details_ytp.pool_token,
pool_details_ytp.token_trait,
pool_details_ytp.total_supply
FROM laplace.pool_details_ytp
WHERE (((pool_details_ytp.function_name)::text = 'get-pool-details'::text) AND (pool_details_ytp.block_height = ( SELECT max(pool_details_ytp_1.block_height) AS max
FROM laplace.pool_details_ytp pool_details_ytp_1)))
)
SELECT ytp_detail.yield_token,
coin_gecko.token,
(((((ytp_detail.balance_token)::bigint + (ytp_detail.balance_yield_token)::bigint))::double precision * coin_gecko.avg_price_usd) / ('100000000'::numeric)::double precision) AS liquidity
FROM (ytp_detail
JOIN laplace.coin_gecko ON (((ytp_detail.token_trait)::text = (coin_gecko.token)::text)))
WITH NO DATA;
ALTER TABLE ONLY laplace.stacks_blockchain_events ALTER COLUMN id SET DEFAULT nextval('laplace.stacks_blockchain_events_id_seq'::regclass);
ALTER TABLE ONLY laplace.transaction_logs ALTER COLUMN id SET DEFAULT nextval('laplace.transaction_logs_id_seq'::regclass);
ALTER TABLE ONLY laplace.coin_gecko_archive
ADD CONSTRAINT coin_gecko_archive_pkey PRIMARY KEY (token, "timestamp");
ALTER TABLE ONLY laplace.coin_gecko
ADD CONSTRAINT coin_gecko_pkey PRIMARY KEY (token);
ALTER TABLE ONLY laplace.deployed_contracts
ADD CONSTRAINT deployed_contracts_pkey PRIMARY KEY (deployer_address, tx_id, contract_name);
ALTER TABLE ONLY laplace.dynamic_ltv_crp
ADD CONSTRAINT dynamic_ltv_crp_pkey PRIMARY KEY (contract_name, function_name, token, collateral, expiry, block_height);
ALTER TABLE ONLY laplace.dynamic_position_crp
ADD CONSTRAINT dynamic_position_given_burn_key_crp_pkey PRIMARY KEY (contract_name, function_name, token, collateral, expiry, block_height);
ALTER TABLE ONLY laplace.dynamic_price_ytp
ADD CONSTRAINT dynamic_price_ytp_pkey PRIMARY KEY (contract_name, function_name, yield_token, expiry, block_height);
ALTER TABLE ONLY laplace.dynamic_y_given_x_fwp
ADD CONSTRAINT dynamic_y_given_x_fwp_pkey PRIMARY KEY (contract_name, function_name, token_x, token_y, weight_x, weight_y, block_height);
ALTER TABLE ONLY laplace.dynamic_yield_ytp
ADD CONSTRAINT dynamic_yield_ytp_pkey PRIMARY KEY (function_name, contract_name, yield_token, expiry, block_height);
ALTER TABLE ONLY laplace.oracle_instant_fwp
ADD CONSTRAINT oracle_instant_fwp_pkey PRIMARY KEY (token_y, token_x, contract_name, function_name, weight_y, weight_x, block_height);
ALTER TABLE ONLY laplace.oracle_instant_ytp
ADD CONSTRAINT oracle_instant_ytp_pkey PRIMARY KEY (contract_name, function_name, yield_token, expiry, block_height);
ALTER TABLE ONLY laplace.oracle_resilient_fwp
ADD CONSTRAINT oracle_resilient_fwp_pkey PRIMARY KEY (contract_name, function_name, token_x, token_y, weight_x, weight_y, block_height);
ALTER TABLE ONLY laplace.oracle_resilient_ytp
ADD CONSTRAINT oracle_resilient_ytp_pkey PRIMARY KEY (contract_name, function_name, expiry, yield_token, block_height);
ALTER TABLE ONLY laplace.pool_details_crp
ADD CONSTRAINT pool_details_crp_pkey PRIMARY KEY (contract_name, function_name, block_height, collateral, token, expiry);
ALTER TABLE ONLY laplace.pool_details_fwp
ADD CONSTRAINT pool_details_fwp_pkey PRIMARY KEY (token_x, weight_y, weight_x, token_y, block_height, contract_name, function_name);
ALTER TABLE ONLY laplace.pool_details_ytp
ADD CONSTRAINT pool_details_ytp_pkey PRIMARY KEY (expiry, block_height, yield_token);
ALTER TABLE ONLY laplace.static_data_fwp
ADD CONSTRAINT pool_static_data_pkey PRIMARY KEY (contract_name, function_name, token_x, token_y, weight_x, weight_y);
ALTER TABLE ONLY laplace.reward_cycle_stats
ADD CONSTRAINT reward_cycle_stats_pkey PRIMARY KEY (token, block_height);
ALTER TABLE ONLY laplace.staking_data
ADD CONSTRAINT staking_data_pkey PRIMARY KEY (token, current_cycle, cycle, block_height);
ALTER TABLE ONLY laplace.static_data_ytp
ADD CONSTRAINT static_data_ytp_pkey PRIMARY KEY (yield_token, expiry, contract_name, function_name);
ALTER TABLE ONLY laplace.sync_status
ADD CONSTRAINT sync_status_pk PRIMARY KEY (key);
ALTER TABLE ONLY laplace.transaction_logs
ADD CONSTRAINT transaction_logs_pkey PRIMARY KEY (id);

View File

@@ -0,0 +1 @@
alter table "laplace"."config_contracts" drop constraint "config_contracts_pkey";

View File

@@ -0,0 +1,3 @@
alter table "laplace"."config_contracts"
add constraint "config_contracts_pkey"
primary key ("contract");

View File

@@ -0,0 +1,60 @@
DROP VIEW IF EXISTS laplace.liquidity_provider_fee;
CREATE VIEW laplace.liquidity_provider_fee AS
select
'age000-governance-token' as token_to,
'token-wbtc' as token_from,
(
select
value :: numeric
from
laplace.oracle_resilient_fwp
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
and block_height = (
select
max(laplace.oracle_resilient_fwp.block_height)
from
laplace.oracle_resilient_fwp
)
) as wstx_to,
(
select
value :: numeric
from
laplace.oracle_resilient_fwp
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
and block_height = (
select
max(laplace.oracle_resilient_fwp.block_height)
from
laplace.oracle_resilient_fwp
)
) as wstx_from,
(
select
value :: numeric
from
laplace.static_data_fwp
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
and function_name = 'get-fee-rate-x'
) as fee_details_to,
(
select
value :: numeric
from
laplace.static_data_fwp
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
and function_name = 'get-fee-rate-y'
) as fee_details_from;

View File

@@ -0,0 +1,60 @@
DROP VIEW IF EXISTS laplace.liquidity_provider_fee;
CREATE VIEW laplace.liquidity_provider_fee AS
select
'age000-governance-token' as token_to,
'token-wbtc' as token_from,
(
select
value :: numeric
from
laplace.oracle_resilient_fwp
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
and block_height = (
select
max(laplace.oracle_resilient_fwp.block_height)
from
laplace.oracle_resilient_fwp
)
) as wstx_to,
(
select
value :: numeric
from
laplace.oracle_resilient_fwp
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
and block_height = (
select
max(laplace.oracle_resilient_fwp.block_height)
from
laplace.oracle_resilient_fwp
)
) as wstx_from,
(
select
value :: numeric
from
laplace.static_data_fwp
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
and function_name = 'get-fee-rate-x'
) as fee_details_to,
(
select
value :: numeric
from
laplace.static_data_fwp
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
and function_name = 'get-fee-rate-y'
) as fee_details_from;

View File

@@ -0,0 +1 @@
DROP TABLE "laplace"."pool_details_fwp_map_entry";

View File

@@ -0,0 +1,29 @@
CREATE TABLE "laplace"."pool_details_fwp_map_entry" (
"contract_name" varchar NOT NULL,
"block_height" integer NOT NULL,
"token_x" varchar NOT NULL,
"token_y" varchar NOT NULL,
"weight_x" bigint NOT NULL,
"weight_y" bigint NOT NULL,
"pool_token" varchar NOT NULL,
"fee_to_address" varchar NOT NULL,
"oracle_enabled" varchar NOT NULL,
"balance_x" bigint NOT NULL,
"balance_y" bigint NOT NULL,
"fee_rate_x" bigint NOT NULL,
"fee_rate_y" bigint NOT NULL,
"fee_rebate" bigint NOT NULL,
"oracle_average" bigint NOT NULL,
"oracle_resilient" bigint NOT NULL,
"total_supply" bigint NOT NULL,
PRIMARY KEY (
"contract_name",
"block_height",
"token_x",
"token_y",
"weight_x",
"weight_y"
)
);
COMMENT ON TABLE "laplace"."pool_details_fwp_map_entry" IS 'ALEX fixed-weight-pool time series data using map_entry api';

View File

@@ -0,0 +1 @@
DROP VIEW IF EXISTS laplace.liquidity_provider_fee;

View File

@@ -0,0 +1,118 @@
DROP VIEW IF EXISTS laplace.liquidity_provider_fee;
CREATE VIEW laplace.liquidity_provider_fee AS
select
'age000-governance-token' as token_to,
'token-wbtc' as token_from,
(
select
value :: numeric
from
laplace.oracle_resilient_fwp
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
and block_height = (
select
max(laplace.oracle_resilient_fwp.block_height)
from
laplace.oracle_resilient_fwp
)
) as wstx_to,
(
select
value :: numeric
from
laplace.oracle_resilient_fwp
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
and block_height = (
select
max(laplace.oracle_resilient_fwp.block_height)
from
laplace.oracle_resilient_fwp
)
) as wstx_from,
(
select
value :: numeric
from
laplace.static_data_fwp
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
and function_name = 'get-fee-rate-x'
) as fee_details_to,
(
select
value :: numeric
from
laplace.static_data_fwp
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
and function_name = 'get-fee-rate-y'
) as fee_details_from
union
select
'token-wbtc' as token_to,
'age000-governance-token' as token_from,
(
select
value :: numeric
from
laplace.oracle_resilient_fwp
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
and block_height = (
select
max(laplace.oracle_resilient_fwp.block_height)
from
laplace.oracle_resilient_fwp
)
) as wstx_to,
(
select
value :: numeric
from
laplace.oracle_resilient_fwp
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
and block_height = (
select
max(laplace.oracle_resilient_fwp.block_height)
from
laplace.oracle_resilient_fwp
)
) as wstx_from,
(
select
value :: numeric
from
laplace.static_data_fwp
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
and function_name = 'get-fee-rate-y'
) as fee_details_to,
(
select
value :: numeric
from
laplace.static_data_fwp
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
and function_name = 'get-fee-rate-x'
) as fee_details_from;

View File

@@ -0,0 +1,297 @@
DROP MATERIALIZED VIEW if exists "laplace"."liquidity_details";
DROP MATERIALIZED VIEW if exists "laplace"."farming_details";
DROP MATERIALIZED VIEW if exists "laplace"."fwp_liquidity";
CREATE MATERIALIZED VIEW "laplace"."fwp_liquidity" AS
WITH fwp_detail AS (
SELECT pool_details_fwp.contract_name,
pool_details_fwp.function_name,
pool_details_fwp.block_height,
pool_details_fwp.time_stamp,
pool_details_fwp.token_x,
pool_details_fwp.token_y,
pool_details_fwp.weight_x,
pool_details_fwp.weight_y,
pool_details_fwp.pool_token,
pool_details_fwp.fee_to_address,
pool_details_fwp.oracle_enabled,
pool_details_fwp.balance_x,
pool_details_fwp.balance_y,
pool_details_fwp.fee_rate_x,
pool_details_fwp.fee_rate_y,
pool_details_fwp.fee_rebate,
pool_details_fwp.oracle_average,
pool_details_fwp.oracle_resilient,
pool_details_fwp.total_supply
FROM laplace.pool_details_fwp
WHERE (pool_details_fwp.block_height = (SELECT max(pool_details_fwp_1.block_height) AS max
FROM laplace.pool_details_fwp pool_details_fwp_1))
),
coin_gecko_view AS (
SELECT coin_gecko.token,
coin_gecko.avg_price_usd
FROM laplace.coin_gecko
UNION ALL
SELECT 'age000-governance-token'::character varying AS token,
((SELECT coin_gecko.avg_price_usd
FROM laplace.coin_gecko
WHERE ((coin_gecko.token)::text = 'token-wstx'::text)) /
(SELECT ((oracle_instant_fwp.value)::double precision / ('100000000'::numeric)::double precision)
FROM laplace.oracle_instant_fwp
WHERE (((oracle_instant_fwp.token_x)::text = 'token-wstx'::text) AND
((oracle_instant_fwp.token_y)::text = 'age000-governance-token'::text) AND
(oracle_instant_fwp.block_height = (SELECT max(oracle_instant_fwp_1.block_height) AS max
FROM laplace.oracle_instant_fwp oracle_instant_fwp_1)) and
contract_name = 'fixed-weight-pool-v1-01'))) AS avg_price_usd
)
SELECT fwp_detail.contract_name,
fwp_detail.token_x,
fwp_detail.token_y,
((fwp_detail.weight_x)::double precision / ('100000000'::numeric)::double precision) AS weight_x,
((fwp_detail.weight_y)::double precision / ('100000000'::numeric)::double precision) AS weight_y,
((((fwp_detail.balance_x)::double precision * (SELECT coin_gecko_view.avg_price_usd
FROM coin_gecko_view
WHERE ((coin_gecko_view.token)::text = (fwp_detail.token_x)::text))) +
((fwp_detail.balance_y)::double precision * (SELECT coin_gecko_view.avg_price_usd
FROM coin_gecko_view
WHERE ((coin_gecko_view.token)::text = (fwp_detail.token_y)::text)))) /
('100000000'::numeric)::double precision) AS liquidity
FROM fwp_detail;
REFRESH MATERIALIZED VIEW laplace.wstx_alex_pool_volume;
REFRESH MATERIALIZED VIEW laplace.wstx_wbtc_pool_volume;
CREATE MATERIALIZED VIEW "laplace"."liquidity_details" AS
WITH liquidity_table AS (
SELECT 'fwp-wstx-alex-50-50-v1-01' :: text AS token_name,
(
SELECT wstx_alex_pool_volume.total_volume
FROM laplace.wstx_alex_pool_volume
WHERE (wstx_alex_pool_volume.time_range = '24hrs' :: text)
) AS volume_24h,
(
SELECT wstx_alex_pool_volume.total_volume
FROM laplace.wstx_alex_pool_volume
WHERE (wstx_alex_pool_volume.time_range = '7days' :: text)
) AS volume_7d,
(
(
(
(
(
SELECT static_data_fwp.value
FROM laplace.static_data_fwp
WHERE (
(
(static_data_fwp.function_name) :: text = 'get-fee-rate-x' :: text
)
AND (
(static_data_fwp.token_x) :: text = 'token-wstx' :: text
)
AND (
(static_data_fwp.token_y) :: text = 'age000-governance-token' :: text
)
AND (
(static_data_fwp.contract_name) :: text =
'fixed-weight-pool-v1-01' :: text
)
)
)
) :: double precision / (1000000) :: double precision
) + (
(
(
SELECT static_data_fwp.value
FROM laplace.static_data_fwp
WHERE (
(
(static_data_fwp.function_name) :: text = 'get-fee-rate-y' :: text
)
AND (
(static_data_fwp.token_x) :: text = 'token-wstx' :: text
)
AND (
(static_data_fwp.token_y) :: text = 'age000-governance-token' :: text
)
AND (
(static_data_fwp.contract_name) :: text =
'fixed-weight-pool-v1-01' :: text
)
)
)
) :: double precision / (1000000) :: double precision
)
) / (2) :: double precision
) AS item_fees,
(
SELECT fwp_liquidity.liquidity
FROM laplace.fwp_liquidity
WHERE (
(
(fwp_liquidity.token_x) :: text = 'token-wstx' :: text
)
AND (
(fwp_liquidity.token_y) :: text = 'age000-governance-token' :: text
)
AND (
(fwp_liquidity.contract_name) :: text = 'fixed-weight-pool-v1-01' :: text
)
)
) AS liquidity
UNION
SELECT 'fwp-wstx-wbtc-50-50-v1-01' :: text AS token_name,
(
SELECT wstx_wbtc_pool_volume.total_volume
FROM laplace.wstx_wbtc_pool_volume
WHERE (wstx_wbtc_pool_volume.time_range = '24hrs' :: text)
) AS volume_24h,
(
SELECT wstx_wbtc_pool_volume.total_volume
FROM laplace.wstx_wbtc_pool_volume
WHERE (wstx_wbtc_pool_volume.time_range = '7days' :: text)
) AS volume_7d,
(
(
(
(
(
SELECT static_data_fwp.value
FROM laplace.static_data_fwp
WHERE (
(
(static_data_fwp.function_name) :: text = 'get-fee-rate-x' :: text
)
AND (
(static_data_fwp.token_x) :: text = 'token-wstx' :: text
)
AND (
(static_data_fwp.token_y) :: text = 'token-wbtc' :: text
)
AND (
(static_data_fwp.contract_name) :: text =
'fixed-weight-pool-v1-01' :: text
)
)
)
) :: double precision / (1000000) :: double precision
) + (
(
(
SELECT static_data_fwp.value
FROM laplace.static_data_fwp
WHERE (
(
(static_data_fwp.function_name) :: text = 'get-fee-rate-y' :: text
)
AND (
(static_data_fwp.token_x) :: text = 'token-wstx' :: text
)
AND (
(static_data_fwp.token_y) :: text = 'token-wbtc' :: text
)
AND (
(static_data_fwp.contract_name) :: text =
'fixed-weight-pool-v1-01' :: text
)
)
)
) :: double precision / (1000000) :: double precision
)
) / (2) :: double precision
) AS item_fees,
(
SELECT fwp_liquidity.liquidity
FROM laplace.fwp_liquidity
WHERE (
(
(fwp_liquidity.token_x) :: text = 'token-wstx' :: text
)
AND (
(fwp_liquidity.token_y) :: text = 'token-wbtc' :: text
)
AND (
(fwp_liquidity.contract_name) :: text = 'fixed-weight-pool-v1-01' :: text
)
)
) AS liquidity
)
SELECT liquidity_table.token_name,
liquidity_table.volume_24h,
liquidity_table.volume_7d,
liquidity_table.item_fees,
liquidity_table.liquidity,
(
(
liquidity_table.item_fees / liquidity_table.liquidity
) * (52) :: double precision
) AS apr
FROM liquidity_table;
CREATE MATERIALIZED VIEW "laplace"."farming_details" AS
SELECT 'fwp-wstx-alex-50-50-v1-01' :: text AS pool_token,
(
SELECT fwp_liquidity.liquidity
FROM laplace.fwp_liquidity
WHERE (
(
(fwp_liquidity.token_x) :: text = 'token-wstx' :: text
)
AND (
(fwp_liquidity.token_y) :: text = 'age000-governance-token' :: text
)
AND (
(fwp_liquidity.contract_name) :: text = 'fixed-weight-pool-v1-01' :: text
)
)
) AS liquidity,
(
SELECT (
sum((aprs.apr) :: double precision) / (32) :: double precision
)
FROM (
SELECT staking_data.apr
FROM laplace.staking_data
WHERE (
staking_data.block_height = (
SELECT max(staking_data_1.block_height) AS max
FROM laplace.staking_data staking_data_1
)
)
) aprs
) AS apr,
'ALEX' :: text AS reward
UNION
SELECT 'fwp-wstx-wbtc-50-50-v1-01' :: text AS pool_token,
(
SELECT fwp_liquidity.liquidity
FROM laplace.fwp_liquidity
WHERE (
(
(fwp_liquidity.token_x) :: text = 'token-wstx' :: text
)
AND (
(fwp_liquidity.token_y) :: text = 'token-wbtc' :: text
)
AND (
(fwp_liquidity.contract_name) :: text = 'fixed-weight-pool-v1-01' :: text
)
)
) AS liquidity,
(
SELECT (
sum((aprs.apr) :: double precision) / (32) :: double precision
)
FROM (
SELECT staking_data.apr
FROM laplace.staking_data
WHERE (
staking_data.block_height = (
SELECT max(staking_data_1.block_height) AS max
FROM laplace.staking_data staking_data_1
)
)
) aprs
) AS apr,
'ALEX' :: text AS reward;

View File

@@ -0,0 +1 @@
DROP MATERIALIZED VIEW IF EXISTS laplace.farming_details;

View File

@@ -0,0 +1,69 @@
DROP MATERIALIZED VIEW IF EXISTS laplace.farming_details;
create materialized view laplace.farming_details as (
select
'fwp-wstx-alex-50-50-v1-01' as pool_token,
(
select
liquidity
from
laplace.fwp_liquidity
where
token_x = 'token-wstx'
and token_y = 'age000-governance-token'
and contract_name = 'fixed-weight-pool-v1-01'
) as liquidity,
(
select
sum(apr :: double precision) / 32
from
(
select
apr
from
laplace.staking_data
where
block_height = (
select
max(laplace.staking_data.block_height)
from
laplace.staking_data
)
and token = 'fwp-wstx-alex-50-50-v1-01'
) as aprs
) as apr,
'ALEX' as reward
union
select
'fwp-wstx-wbtc-50-50-v1-01' as pool_token,
(
select
liquidity
from
laplace.fwp_liquidity
where
token_x = 'token-wstx'
and token_y = 'token-wbtc'
and contract_name = 'fixed-weight-pool-v1-01'
) as liquidity,
(
select
sum(apr :: double precision) / 32
from
(
select
apr
from
laplace.staking_data
where
block_height = (
select
max(laplace.staking_data.block_height)
from
laplace.staking_data
)
and token = 'fwp-wstx-wbtc-50-50-v1-01'
) as aprs
) as apr,
'ALEX' as reward
);

View File

@@ -0,0 +1,3 @@
DROP INDEX IF EXISTS laplace.idx_token_blockheight;
DROP VIEW IF EXISTS laplace.latest_staking_data;

View File

@@ -0,0 +1,15 @@
DROP INDEX IF EXISTS laplace.idx_token_blockheight;
CREATE INDEX idx_token_blockheight
ON laplace.staking_data (token, block_height);
DROP VIEW IF EXISTS laplace.latest_staking_data;
CREATE VIEW laplace.latest_staking_data AS
SELECT laplace.staking_data.token, laplace.staking_data.current_cycle, laplace.staking_data.cycle, laplace.staking_data.block_height, laplace.staking_data.staking_stats, laplace.staking_data.coinbase_amount, laplace.staking_data.apr
FROM laplace.staking_data
JOIN (
SELECT token, max(block_height) as block_height
FROM laplace.staking_data
GROUP BY token
) as maxes_by_token
ON laplace.staking_data.token = maxes_by_token.token and laplace.staking_data.block_height = maxes_by_token.block_height
ORDER BY laplace.staking_data.cycle ASC;

View File

@@ -0,0 +1 @@
DROP TABLE "laplace"."ido_register";

View File

@@ -0,0 +1,17 @@
CREATE TABLE "laplace"."ido_register" (
"sender_address" varchar NOT NULL,
"block_height" integer NOT NULL,
"ido_id" integer NOT NULL,
"contract_call_contract_id" varchar NOT NULL,
"apower" bigint NOT NULL,
"payment_token" varchar NOT NULL,
"registered_start" bigint NOT NULL,
"registered_end" bigint NOT NULL,
"amount" bigint,
"tx_id" bytea NOT NULL,
PRIMARY KEY ("block_height", "tx_id")
);
CREATE INDEX idx_ido_id_sender_address ON laplace.ido_register (ido_id, sender_address);
COMMENT ON TABLE "laplace"."ido_register" IS 'ALEX ido register results from alex-launchpad.clar';

Some files were not shown because too many files have changed in this diff Show More