This commit is contained in:
czl1378 2020-12-09 10:39:39 +08:00
parent 5334a4ebfb
commit 4b320fff2f
23 changed files with 1090 additions and 72 deletions

5
.gitignore vendored
View File

@ -1,3 +1,2 @@
/target
Cargo.lock
build
/node_modules
/program/target

View File

@ -1,2 +1,36 @@
# solana-flux-aggregator
Solnana Flux Aggregator
## Install
`npm install`
`sudo npm run build:program`
## Create Payer
`npm run create:payer`
request some airdrop:
`npm run airdrop:payer`
## Deploy
`npm run deploy`
## Create Aggregator
`npm run create:aggregator`
request some airdrop:
`npm run airdrop:aggregator`
## Create Oracle
`npm run create:oracle`
request some airdrop:
`npm run airdrop:oracle`

BIN
build/flux_aggregator.so Executable file

Binary file not shown.

View File

@ -1,5 +0,0 @@
# Network: local|main|dev
NETWORK=local
# Payer wallet
SOLANA_PAYER_MNEMONIC=spin canyon tuition upset pioneer celery liquid conduct boy bargain dust seed

2
client/.gitignore vendored
View File

@ -1,2 +0,0 @@
node_modules
dist

View File

@ -1,6 +0,0 @@
{
"programAccount": {
"pubkey": "FfR1CiA4i2xvYLycCU8kv9mLpcT7Woyqkgvkz7hzjEfN",
"secret": "5b0d673d12b9a811eb9f1a770f86e4c516879f95cf60191c78b3a8c5d6fb6f1ed9dad41af1513e8ab932aab3f56bafcdb84c5fedc9df8a299e7bf53ec84784a5"
}
}

View File

@ -1,21 +0,0 @@
{
"name": "client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"solray": "git+https://github.com/czl1378/solray.git"
},
"devDependencies": {
"@tsconfig/recommended": "^1.0.1",
"@types/node": "^14.14.10",
"typescript": "^4.1.2"
}
}

39
package.json Normal file
View File

@ -0,0 +1,39 @@
{
"name": "client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"testnetDefaultChannel": "v1.4.8",
"scripts": {
"deploy": "cd src && ts-node cli.ts deploy",
"role-info": "cd src && ts-node cli.ts role-info",
"create:payer": "cd src && ts-node cli.ts create payer",
"create:aggregator": "cd src && ts-node cli.ts create aggregator",
"create:oracle": "cd src && ts-node cli.ts create oracle",
"remove:payer": "cd src && ts-node cli.ts remove payer",
"remove:aggregator": "cd src && ts-node cli.ts remove aggregator",
"remove:oracle": "cd src && ts-node cli.ts remove oracle",
"airdrop:payer": "cd src && ts-node cli.ts airdrop payer",
"airdrop:aggregator": "cd src && ts-node cli.ts airdrop aggregator",
"airdrop:oracle": "cd src && ts-node cli.ts airdrop oracle",
"localnet:update": "solana-localnet update",
"localnet:up": "set -x; solana-localnet down; set -e; solana-localnet up",
"localnet:down": "solana-localnet down",
"clean": "rm -rf src/deployed.md && rm -rf src/wallets/*",
"build:program": "solray build program"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"commander": "^6.2.0",
"dotenv": "^8.2.0",
"solray": "git+https://github.com/czl1378/solray.git"
},
"devDependencies": {
"@tsconfig/recommended": "^1.0.1",
"@types/node": "^14.14.10",
"ts-node": "^9.1.1",
"typescript": "^4.1.2"
}
}

722
program/Cargo.lock generated Normal file
View File

@ -0,0 +1,722 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "arrayref"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hermit-abi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bincode"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "block-padding"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bs58"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bv"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"feature-probe 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "curve25519-dalek"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"subtle 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"zeroize 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "derivative"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "digest"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "env_logger"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "feature-probe"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "flux-aggregator"
version = "0.1.0"
dependencies = [
"arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"num_enum 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-program 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"spl-token 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "generic-array"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "generic-array"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
"typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "getrandom"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)",
"wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hermit-abi"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hex"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"either 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memmap"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-derive"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num_enum"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"derivative 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_enum_derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num_enum_derive"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-crate 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro-crate"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"toml 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro2"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"getrandom 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ppv-lite86 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"getrandom 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustversion"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde_derive 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_bytes"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive"
version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sha2"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-frozen-abi"
version = "1.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bs58 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bv 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-frozen-abi-macro 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-frozen-abi-macro"
version = "1.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-logger"
version = "1.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-program"
version = "1.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bincode 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bs58 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bv 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
"curve25519-dalek 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustversion 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-frozen-abi 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-frozen-abi-macro 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-sdk-macro 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-sdk-macro"
version = "1.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bs58 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rustversion 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "spl-token"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"num_enum 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-program 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "subtle"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "1.0.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thiserror"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"thiserror-impl 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thiserror-impl"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "typenum"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "zeroize"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
"checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
"checksum autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
"checksum bincode 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
"checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
"checksum bs58 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb"
"checksum bv 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8834bb1d8ee5dc048ee3124f2c7c1afcc6bc9aed03f11e9dfd8c69470a5db340"
"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum curve25519-dalek 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d85653f070353a16313d0046f173f70d1aadd5b42600a14de626f0dfb3473a5"
"checksum derivative 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f"
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
"checksum either 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
"checksum feature-probe 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da"
"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
"checksum generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
"checksum getrandom 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
"checksum hermit-abi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
"checksum hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
"checksum itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)" = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
"checksum log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
"checksum memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
"checksum num-derive 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
"checksum num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
"checksum num_enum 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "226b45a5c2ac4dd696ed30fa6b94b057ad909c7b7fc2e0d0808192bced894066"
"checksum num_enum_derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1c0fd9eba1d5db0994a239e09c1be402d35622277e35468ba891aa5e3188ce7e"
"checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
"checksum ppv-lite86 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
"checksum proc-macro-crate 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785"
"checksum proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
"checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
"checksum rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
"checksum regex 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
"checksum regex-syntax 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum rustversion 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)" = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
"checksum serde_bytes 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)" = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9"
"checksum serde_derive 1.0.118 (registry+https://github.com/rust-lang/crates.io-index)" = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
"checksum sha2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69"
"checksum solana-frozen-abi 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5ab6ad3dda6a3d95d19603eeedc65689d8125eafb3e23c6a1e01ab8a6ba60c"
"checksum solana-frozen-abi-macro 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ffaa09aa938a67501479ed8a785071c6993f72c34e43f680db3ea7a2dadad9e7"
"checksum solana-logger 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0d949157d0b23eaf5758b427d90741d2a90751c4e3dfee028f5726ab8b36e769"
"checksum solana-program 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)" = "8e9c6cb16e8aa986bc0d2af8ec50628f7451bef9dac89924adf48302bd4fc755"
"checksum solana-sdk-macro 1.4.14 (registry+https://github.com/rust-lang/crates.io-index)" = "475a680cd175f2e256452e007c6f8622d3a1ab97ab36d26303b35576e24f340c"
"checksum spl-token 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f77fa0b41cbc82d1d7c8f2d914b49e9a1a7b6e32af952d03383fb989c42bc89"
"checksum subtle 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd"
"checksum syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
"checksum termcolor 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
"checksum thiserror 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e"
"checksum thiserror-impl 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
"checksum toml 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "75cf45bb0bef80604d001caaec0d09da99611b3c0fd39d3080468875cdb65645"
"checksum typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
"checksum version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum zeroize 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05f33972566adbd2d3588b0491eb94b98b43695c4ef897903470ede4f3f5a28a"

234
src/cli.ts Normal file
View File

@ -0,0 +1,234 @@
import { Command, option } from "commander"
import { PublicKey, Connection } from "@solana/web3.js"
import { BPFLoader, Wallet } from "solray"
import {
newWallet, calculatePayfees, connectTo, sleep
} from "./utils"
import fs from "fs"
import path from "path"
const cli = new Command()
const roles = ["payer", "aggregator", "oracle"]
const sofilePath = path.resolve(__dirname, "../build/flux_aggregator.so")
const deployedPath = path.resolve(__dirname, "./deployed.md")
function checkRole(role) {
if (roles.indexOf(role) < 0) {
console.error("invalid role")
return false
}
const walletPath = path.resolve(`./wallets/${role}.json`)
return {
exist: fs.existsSync(walletPath),
walletPath
}
}
// 30m Black, 31m Red, 32m Green, 33m Yellow, 34m Blue, 35m Magenta, 36m Cyanic, 37m White
function color(s, c="black", b=false): string {
const cArr = ["black", "red", "green", "yellow", "blue", "megenta", "cyanic", "white"]
let cIdx = cArr.indexOf(c)
let bold = b ? "\x1b[1m" : ""
return `\x1b[${30 + (cIdx > -1 ? cIdx : 0)}m${bold}${s}\x1b[0m`
}
async function showRoleInfo(role, conn: Connection): Promise<void> {
const res = checkRole(role)
if (!res) return
if (!res.exist) {
return console.error(`role ${color(role, "red")} not created.`)
}
const fileData = fs.readFileSync(res.walletPath)
const wallet = JSON.parse(fileData.toString())
console.log(color(`[${role}]`, "cyanic", true))
console.log(color("public key: ", "blue"), `${wallet.publicKey}`)
console.log(color("mnemonic: ", "blue"), `${wallet.mnemonic}`)
process.stdout.write(`${color("balance: ", "blue")}...`)
const balance = await conn.getBalance(new PublicKey(wallet.publicKey))
process.stdout.clearLine(-1)
process.stdout.cursorTo(0)
process.stdout.write(`${color("balance: ", "blue")}${balance} \n\n`)
}
cli
.command("create <role>")
.description(`create role account, roles: ${roles.join("|")}`)
.action(async (role) => {
const res = checkRole(role)
if (!res) return
if (res.exist) {
let fileData = fs.readFileSync(res.walletPath)
let wallet = JSON.parse(fileData.toString())
console.error(`role ${color(role, "red")} already created, public key: ${color(wallet.publicKey, "blue")}`)
return
} else {
const wallet = await newWallet()
fs.writeFileSync(res.walletPath, JSON.stringify({
publicKey: wallet.account.publicKey.toBase58(),
secretKey: "["+wallet.account.secretKey.toString()+"]",
mnemonic: wallet.mnemonic,
}))
console.log(`create role ${color(role, "blue)")} success!`)
}
})
cli
.command("remove <role>")
.description(`remove role account, roles: ${roles.join("|")}`)
.action((role) => {
const res = checkRole(role)
if (!res) return
if (!res.exist) {
return console.error(`role ${color(role, "red")} not created.`)
}
fs.unlinkSync(res.walletPath)
console.log(`remove role ${color(role, "blue")} success!`)
})
cli
.command("role-info [role]")
.description(`show role info, or all if no role supplied`)
.option(
"-n, --network <network_name>",
"deploy on which network (local|devnet|mainnet), default is localnet",
"local"
)
.action(async (role, opts) => {
const { network } = opts
const conn = await connectTo(network)
if (role) {
showRoleInfo(role, conn)
} else {
for (let i = 0; i < roles.length; i++) {
await showRoleInfo(roles[i], conn)
}
}
})
cli
.command("airdrop <role>")
.description(`request airdrop to the role account, roles: ${roles.join("|")}`)
.option(
"-n, --network <network_name>",
"deploy on which network (local|devnet|mainnet), default is localnet",
"local"
)
.option("-m, --amount <amount>", "request amount, default is 10e8", "100000000")
.action(async (role, opts) => {
const res = checkRole(role)
if (!res) return
if (!res.exist) {
return console.error(`role ${color(role, "red")} not created.`)
}
const fileData = fs.readFileSync(res.walletPath)
const wallet = JSON.parse(fileData.toString())
console.log(`payer public key: ${color(wallet.publicKey, "blue")}, request airdop...`)
const { network, amount } = opts
const conn = await connectTo(network)
await conn.requestAirdrop(new PublicKey(wallet.publicKey), amount*1)
await sleep(1000)
const balance = await conn.getBalance(new PublicKey(wallet.publicKey))
console.log(`airdop success, balance: ${color(balance, "blue")}`)
})
cli
.command("deploy")
.description("deploy the aggregator program")
.option(
"-n,--network <network_name>",
"deploy on which network (local|devnet|mainnet), default is localnet",
"local"
)
.action(async (opts) => {
if (fs.existsSync(deployedPath)) {
const programId = fs.readFileSync(deployedPath).toString()
console.log("already deployed, program id: ", color(programId, "blue"))
console.log(color("if you want to deployed agian, try `npm run clean`", "red", true))
return
}
const { network } = opts
const res = checkRole("payer")
if (!res || !res.exist) {
return console.error(`role ${color("payer", "blue")} not created`)
}
const fileData = fs.readFileSync(res.walletPath)
const payer = JSON.parse(fileData.toString())
if (!fs.existsSync(sofilePath)) {
return console.error(`${color("program file not exists", "red")}`)
}
const programBinary = fs.readFileSync(sofilePath)
const conn = await connectTo(network)
const fees = await calculatePayfees(programBinary.length, conn)
let balance = await conn.getBalance(new PublicKey(payer.publicKey))
console.log(`payer wallet: ${color(payer.publicKey, "blue")}, balance: ${color(balance, "blue")}`)
console.log(`deploy payfees: ${color(fees, "blue")}`)
if (balance < fees) {
return console.log(color("insufficient balance to pay fees", "red"))
}
console.log("deploying...")
const wallet = await Wallet.fromMnemonic(payer.mnemonic, conn)
const bpfLoader = new BPFLoader(wallet)
const programAccount = await bpfLoader.load(programBinary)
console.log(`deploy success, program id: ${color(programAccount.publicKey.toBase58(), "blue")}`)
fs.writeFileSync(deployedPath, programAccount.publicKey.toBase58())
})
cli
.command("init-aggregator")
.description("initialize aggregator to the program")
.option(
"-n,--network <network_name>",
"deploy on which network (local|devnet|mainnet), default is localnet",
"local"
)
.action(async (opts) => {
const { network } = opts
const res = checkRole("aggregator")
if (!res || !res.exist) {
return console.error(`role ${color("aggregator", "blue")} not created`)
}
})
cli.parse(process.argv)

View File

@ -14,6 +14,11 @@ dotenv.config()
const { NETWORK, SOLANA_PAYER_MNEMONIC } = process.env
const args = process.argv.splice(2)
const cmd = args[0]
const params = args[1]
// so file path
const soPath = "../build/flux_aggregator.so"
@ -37,7 +42,7 @@ async function main() {
let fees = await calculatePayfees(programBinary.length, conn)
const programAccount = await deployer.ensure("programAccount", async () => {
console.log("loading program...")
console.log("loading program... Network:", NETWORK)
if (walletBalance < fees) {
// throw new Error("Insufficient balance to pay fees");

0
src/oracle.ts Normal file
View File

View File

@ -2,36 +2,39 @@ import { Connection, BpfLoader, PublicKey } from "@solana/web3.js"
import { AggregatorLayout, SubmissionLayout } from "./FluxAggregator"
export async function calculatePayfees(dataLength: number, connection: Connection): Promise<number> {
let fees = 0;
const {feeCalculator} = await connection.getRecentBlockhash();
import { solana, Wallet, NetworkName } from "solray"
const NUM_RETRIES = 500; // allow some number of retries
export async function calculatePayfees(dataLength: number, conn: Connection): Promise<number> {
let fees = 0
const { feeCalculator } = await conn.getRecentBlockhash()
const NUM_RETRIES = 500
fees +=
feeCalculator.lamportsPerSignature *
(BpfLoader.getMinNumSignatures(dataLength) + NUM_RETRIES) +
(await connection.getMinimumBalanceForRentExemption(dataLength));
(await conn.getMinimumBalanceForRentExemption(dataLength))
// Calculate the cost of sending the transactions
fees += feeCalculator.lamportsPerSignature * 100; // wag
fees += feeCalculator.lamportsPerSignature * 100
return fees;
return fees
}
export function getSubmissionValue(submissions: []): number {
const values = submissions
.filter((s: any) => s.value != 0)
.map((s: any) => s.value)
.sort((a, b) => a - b);
.sort((a, b) => a - b)
let len = values.length;
let len = values.length
if (len == 0) {
return 0;
return 0
} else if (len == 1) {
return values[0];
return values[0]
} else {
let i = len / 2;
return len % 2 == 0 ? (values[i] + values[i-1])/2 : values[i];
let i = len / 2
return len % 2 == 0 ? (values[i] + values[i-1])/2 : values[i]
}
}
@ -39,42 +42,42 @@ export function getSubmissionValue(submissions: []): number {
export function sleep(ms: number): Promise<void> {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms);
});
resolve()
}, ms)
})
}
export function decodeAggregatorInfo(accountInfo) {
const data = Buffer.from(accountInfo.data);
const aggregator = AggregatorLayout.decode(data);
const data = Buffer.from(accountInfo.data)
const aggregator = AggregatorLayout.decode(data)
const minSubmissionValue = aggregator.minSubmissionValue.readBigUInt64LE().toString();
const maxSubmissionValue = aggregator.maxSubmissionValue.readBigUInt64LE().toString();
const submitInterval = aggregator.submitInterval.readInt32LE();
const description = aggregator.description.toString();
const minSubmissionValue = aggregator.minSubmissionValue.readBigUInt64LE().toString()
const maxSubmissionValue = aggregator.maxSubmissionValue.readBigUInt64LE().toString()
const submitInterval = aggregator.submitInterval.readInt32LE()
const description = aggregator.description.toString()
// decode oracles
let submissions: [] = [];
let oracles: [] = [];
let submissionSpace = SubmissionLayout.span;
let updateTime = '0';
let submissions: [] = []
let oracles: [] = []
let submissionSpace = SubmissionLayout.span
let updateTime = '0'
for (let i = 0; i < aggregator.submissions.length / submissionSpace; i++) {
let submission = SubmissionLayout.decode(
aggregator.submissions.slice(i*submissionSpace, (i+1)*submissionSpace)
);
submission.oracle = new PublicKey(submission.oracle);
)
submission.oracle = new PublicKey(submission.oracle)
submission.time = submission.time.readBigInt64LE().toString();
submission.value = submission.value.readBigInt64LE().toString()*1;
submission.time = submission.time.readBigInt64LE().toString()
submission.value = submission.value.readBigInt64LE().toString()*1
if (!submission.oracle.equals(new PublicKey(0))) {
submissions.push(submission as never);
oracles.push(submission.oracle.toBase58() as never);
submissions.push(submission as never)
oracles.push(submission.oracle.toBase58() as never)
}
if (submission.time > updateTime) {
updateTime = submission.time;
updateTime = submission.time
}
}
@ -87,4 +90,20 @@ export function decodeAggregatorInfo(accountInfo) {
oracles,
updateTime,
}
}
}
export async function connectTo(network: NetworkName): Promise<Connection> {
const conn = solana.connect(network as NetworkName)
return conn
}
export async function newWallet(): Promise<any> {
const mnemonic = Wallet.generateMnemonic()
const wallet = await Wallet.fromMnemonic(mnemonic, null as any)
return {
mnemonic,
account: wallet.account
}
}