Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
24fcf31
Refactor: PublicKey, PrivateKey, Keypair, AccountMeta
aniketfuryrocks Oct 9, 2022
5e48784
Refactor: CompactU16. move static methods of empty struct to a namespace
aniketfuryrocks Oct 9, 2022
53982bc
fmt
aniketfuryrocks Oct 9, 2022
fac48af
Refactor: CompiledInstruction, CompiledTransaction; CompactU16 doc
aniketfuryrocks Oct 9, 2022
bdc2f04
Refactor: jsonRequest; removed `inline`
aniketfuryrocks Oct 9, 2022
2c821cd
from file
aniketfuryrocks Oct 9, 2022
a8a99be
Refactor: SendTransactionConfig::toJson()
aniketfuryrocks Oct 9, 2022
a6e3495
connection constructor doc style
aniketfuryrocks Oct 9, 2022
b2b8015
doc
aniketfuryrocks Oct 9, 2022
51cf97a
doc and fmt
aniketfuryrocks Oct 9, 2022
e73e77f
Refactor
aniketfuryrocks Oct 9, 2022
6494502
toJson doc
aniketfuryrocks Oct 9, 2022
4f31f60
reorder functions
aniketfuryrocks Oct 9, 2022
0b17904
Refactor: reorder
aniketfuryrocks Oct 9, 2022
a8ebea5
doc
aniketfuryrocks Oct 9, 2022
79579cb
Refactor: fix
aniketfuryrocks Oct 9, 2022
57073ed
ReUse: sendJsonRpcRequest
aniketfuryrocks Oct 9, 2022
f07f9b1
rm build request; sendJsonRpcRequest re-use
aniketfuryrocks Oct 9, 2022
347210e
update examples
aniketfuryrocks Oct 9, 2022
c83ee21
fmt
aniketfuryrocks Oct 9, 2022
fb7ac37
#46: added base structs
Lioncat2002 Oct 10, 2022
a449a0b
#46: refactor
Lioncat2002 Oct 10, 2022
bc059c6
updated Readme
aniketfuryrocks Oct 10, 2022
6756c0d
#43 Removed un-used import
aniketfuryrocks Oct 10, 2022
f996857
#46 working on getBalance
Lioncat2002 Oct 10, 2022
bd42379
#46 working on getBalance
Lioncat2002 Oct 10, 2022
5aa1d38
reafctor
Lioncat2002 Oct 10, 2022
bbb60ae
#46 parsed return of getBalance struct from json
Lioncat2002 Oct 10, 2022
a95b205
#46 parsed return of simulateTransaction
Lioncat2002 Oct 10, 2022
84d78ac
Merge pull request #2 from Lioncat2002/json
aniketfuryrocks Oct 10, 2022
d988fbe
Merge branch 'main' of https://github.com/aniketfuryrocks/solcpp
aniketfuryrocks Oct 10, 2022
f37ae7a
#46 adding the other fields into simulate transaction
Lioncat2002 Oct 10, 2022
1c3ae28
#46 added checks for null values in err, logs, accounts
Lioncat2002 Oct 10, 2022
ab7094a
refactor
Lioncat2002 Oct 10, 2022
9d227dc
Merge pull request #3 from Lioncat2002/json
aniketfuryrocks Oct 10, 2022
03ec6fa
#47 use undeprecated methods
aniketfuryrocks Oct 10, 2022
32aca51
unitsconsumed -> unitsConsumed
aniketfuryrocks Oct 11, 2022
c74418a
refactor lamports to u64 and SimulateTransactionResponse to Simulated…
Lioncat2002 Oct 11, 2022
8c92741
refactor lamports to u64 and SimulateTransactionResponse to Simulated…
Lioncat2002 Oct 11, 2022
9e86024
refactor
Lioncat2002 Oct 11, 2022
240443b
Merge branch 'main' into fixes
Lioncat2002 Oct 11, 2022
5265ef0
Fixes (#4)
Lioncat2002 Oct 11, 2022
97fc7c8
rewrite getSignatureStatuses function and requestAirdrop test
Lioncat2002 Oct 11, 2022
45c8057
Merge branch 'fixes' of github.com:Lioncat2002/solcpp into fixes
Lioncat2002 Oct 11, 2022
e56fd4d
Merge branch 'main' into fixes
Lioncat2002 Oct 11, 2022
c9caaec
refactor
Lioncat2002 Oct 11, 2022
3ae71ac
refactor
Lioncat2002 Oct 11, 2022
06299ac
refactor: requestAirdrop now passing
Lioncat2002 Oct 11, 2022
c229034
Fix requestAirdrop testcase (#5)
Lioncat2002 Oct 12, 2022
ca7feb7
format
aniketfuryrocks Oct 12, 2022
9ff5d5d
SimulatedTransactionResponse to_json and from_json
aniketfuryrocks Oct 12, 2022
1340a22
constant functions and replaced Balance struct with single uint_64
aniketfuryrocks Oct 12, 2022
04f5a40
new SignatureStatus
aniketfuryrocks Oct 12, 2022
d2665d7
deserialize getSignatureStatuses; new getSignatureStatus
aniketfuryrocks Oct 12, 2022
a2cc509
updated dependencies
aniketfuryrocks Oct 13, 2022
1df9133
RpcResponseAndContext and Context structs
aniketfuryrocks Oct 13, 2022
b73811d
RpcResponse null parse
aniketfuryrocks Oct 13, 2022
26a9807
RpcResponse
aniketfuryrocks Oct 13, 2022
67db47d
reafactor
Lioncat2002 Oct 13, 2022
27fe341
fix: add missing imports
Lioncat2002 Oct 13, 2022
d4c0c24
Merge pull request #6 from Lioncat2002/fixes
Lioncat2002 Oct 13, 2022
0a51840
toJson -> to_json
aniketfuryrocks Oct 14, 2022
6d0d033
docs
aniketfuryrocks Oct 14, 2022
894ec77
format
aniketfuryrocks Oct 14, 2022
fa96c74
#51 new: GetAccountInfoConfig
aniketfuryrocks Oct 14, 2022
3618443
Temp #51
aniketfuryrocks Oct 14, 2022
0b1f518
#51
aniketfuryrocks Oct 14, 2022
97aa9a6
use c_str
aniketfuryrocks Oct 14, 2022
ed57ca3
fix: added a timeout for requestAirdrop
Lioncat2002 Oct 14, 2022
3197f1b
doc: added temporary write comment
Lioncat2002 Oct 14, 2022
6450ca8
revert conanfile @mschneider
aniketfuryrocks Oct 16, 2022
0f143da
fix mac os compile error @mschneider
aniketfuryrocks Oct 16, 2022
9cf3266
Merge branch 'aniketfuryrocks:main' into fixes
Lioncat2002 Oct 16, 2022
07e5ec0
Merge pull request #7 from Lioncat2002/fixes
Lioncat2002 Oct 16, 2022
20fcab2
#48 DEFAULT_PUBLICKEY
aniketfuryrocks Oct 16, 2022
e64f6d2
Merge branch 'main' of https://github.com/aniketfuryrocks/solcpp
aniketfuryrocks Oct 16, 2022
fae881b
fix: remove redundant string constructor
aniketfuryrocks Oct 16, 2022
891bae0
TransactionReturnData
aniketfuryrocks Oct 16, 2022
d2c4c5c
rename getMultipleAccounts -> getMultipleAccountsInfo
aniketfuryrocks Oct 16, 2022
4f4fb66
method rename
aniketfuryrocks Oct 16, 2022
3d1d7a6
DataSlice
aniketfuryrocks Oct 16, 2022
62fd032
getMultipleAccountsInfo similar to web3.js
aniketfuryrocks Oct 16, 2022
4271bd0
handle null acountInfo
aniketfuryrocks Oct 16, 2022
e3f42ec
string -> PublicKey DEFAULT_PUBLICKEY
aniketfuryrocks Oct 16, 2022
d07ffcb
use smaller data type for temporary timeout fix
aniketfuryrocks Oct 16, 2022
88e5b91
check for error
aniketfuryrocks Oct 16, 2022
de7f876
fix: overflow error with timeout
Lioncat2002 Oct 17, 2022
11c6fd5
Merge pull request #8 from Lioncat2002/fixes
Lioncat2002 Oct 17, 2022
61137a5
Doc: getMultipleAccountsInfo
aniketfuryrocks Oct 21, 2022
687ab1e
fix: added timeout in sendtransaction example
Lioncat2002 Oct 21, 2022
36b7858
Merge pull request #9 from Lioncat2002/fixes
Lioncat2002 Oct 21, 2022
949e2fc
format pull
aniketfuryrocks Oct 21, 2022
19a6a09
revert c_str -> data
aniketfuryrocks Oct 21, 2022
2a5e6bd
remove place order example
aniketfuryrocks Oct 21, 2022
b3c814e
update Cmakelists to account for removed placeOrder example
aniketfuryrocks Oct 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const solana::CompiledTransaction tx = {
// 3. send & sign tx
const auto keypair =
solana::Keypair::fromFile("id.json");
const auto b58Sig = connection.signAndSendTransaction(keypair, tx);
const auto b58Sig = connection.sendTransaction(keypair, tx);
spdlog::info(
"sent tx. check: https://explorer.solana.com/tx/{}?cluster=devnet",
b58Sig);
Expand Down
2 changes: 1 addition & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ openssl/3.0.1
spdlog/1.9.2

[generators]
cmake
cmake
4 changes: 0 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ include_directories(${solcpp_SOURCE_DIR}/include)
add_executable(example-get-account-info getAccountInfo.cpp)
add_executable(example-account-subscribe accountSubscribe.cpp)
add_executable(example-send-transaction sendTransaction.cpp)
add_executable(example-place-order placeOrder.cpp)
add_executable(example-positions positions.cpp)

# link
target_link_libraries(example-get-account-info ${CONAN_LIBS} sol)
target_link_libraries(example-account-subscribe ${CONAN_LIBS} sol)
target_link_libraries(example-send-transaction ${CONAN_LIBS} sol)
target_link_libraries(example-place-order ${CONAN_LIBS} sol)
target_link_libraries(example-positions ${CONAN_LIBS} sol)

target_compile_definitions(example-place-order PUBLIC FIXTURES_DIR="${CMAKE_SOURCE_DIR}/tests/fixtures")
172 changes: 80 additions & 92 deletions examples/getAccountInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,100 @@
#include <spdlog/spdlog.h>

#include <nlohmann/json.hpp>
using json = nlohmann::json;

#include "mango_v3.hpp"
#include "solana.hpp"

const solana::PublicKey DEFAULT_PUBLICKEY =
solana::PublicKey::fromBase58("11111111111111111111111111111111");

int main() {
std::string rpc_url =
"https://mango.rpcpool.com/946ef7337da3f5b8d3e4a34e7f88";
Comment thread
aniketfuryrocks marked this conversation as resolved.
Resolved
auto connection = solana::rpc::Connection(rpc_url);
const json req = connection.getAccountInfoRequest(
"98pjRuQjK3qA6gXts96PqZT4Ze5QmnCmt3QYjhbUSPue");
const std::string jsonSerialized = req.dump();
spdlog::info("REQ: {}", jsonSerialized);

cpr::Response r =
cpr::Post(cpr::Url{rpc_url}, cpr::Body{jsonSerialized.c_str()},
cpr::Header{{"Content-Type", "application/json"}});

if (r.status_code == 0 || r.status_code >= 400) {
spdlog::error("Error: {}, {}", r.status_code, r.error.message);
return 1;
} else {
spdlog::info("RES: {}", r.text);
json res = json::parse(r.text);

const std::string encoded = res["result"]["value"]["data"][0];
const std::string decoded = solana::b64decode(encoded);
const mango_v3::MangoGroup *group =
reinterpret_cast<const mango_v3::MangoGroup *>(decoded.data());
spdlog::info("DEC:");
spdlog::info("numOracles: {}", group->numOracles);

for (int i = 0; i < mango_v3::MAX_TOKENS; ++i) {
if (i >= group->numOracles && i != mango_v3::QUOTE_INDEX) continue;

const auto &token = group->tokens[i];
const auto mintPk = token.mint.toBase58();

if (mintPk == std::string("11111111111111111111111111111111")) continue;

const auto rootBankPk = token.rootBank.toBase58();
if (i != mango_v3::QUOTE_INDEX) {
spdlog::info("TOK: {}", i);
} else {
spdlog::info("QUOTE: {}", i);
}
spdlog::info(" mint: {}", mintPk);
spdlog::info(" rootBank: {}", rootBankPk);
spdlog::info(" decimals: {}", static_cast<int>(token.decimals));
const std::string account = "98pjRuQjK3qA6gXts96PqZT4Ze5QmnCmt3QYjhbUSPue";
const mango_v3::MangoGroup grp =
connection
.getAccountInfo<mango_v3::MangoGroup>(
solana::PublicKey::fromBase58(account))
.value.value()
.data;
const auto group = &grp;

spdlog::info("DEC:");
spdlog::info("numOracles: {}", group->numOracles);

for (int i = 0; i < mango_v3::MAX_TOKENS; ++i) {
if (i >= group->numOracles && i != mango_v3::QUOTE_INDEX) continue;

const auto &token = group->tokens[i];
const auto mintPk = token.mint;

if (mintPk == DEFAULT_PUBLICKEY) continue;
Comment thread
aniketfuryrocks marked this conversation as resolved.
Resolved

const auto rootBankPk = token.rootBank;
if (i != mango_v3::QUOTE_INDEX) {
spdlog::info("TOK: {}", i);
} else {
spdlog::info("QUOTE: {}", i);
}
spdlog::info(" mint: {}", mintPk.toBase58());
spdlog::info(" rootBank: {}", rootBankPk.toBase58());
spdlog::info(" decimals: {}", static_cast<int>(token.decimals));
}

for (int i = 0; i < mango_v3::MAX_PAIRS; ++i) {
const auto &market = group->spotMarkets[i];
const auto marketPk = market.spotMarket.toBase58();
for (int i = 0; i < mango_v3::MAX_PAIRS; ++i) {
const auto &market = group->spotMarkets[i];
const auto marketPk = market.spotMarket;

if (marketPk == std::string("11111111111111111111111111111111")) continue;
if (marketPk == DEFAULT_PUBLICKEY) continue;

spdlog::info("SPOT: {}", i);
spdlog::info(" market: {}", marketPk);
spdlog::info(" maintAssetWeight: {}",
market.maintAssetWeight.to_double());
spdlog::info(" initAssetWeight: {}", market.initAssetWeight.to_double());
spdlog::info(" maintLiabWeight: {}", market.maintLiabWeight.to_double());
spdlog::info(" initLiabWeight: {}", market.initLiabWeight.to_double());
spdlog::info(" liquidationFee: {}", market.liquidationFee.to_double());
}

for (int i = 0; i < mango_v3::MAX_PAIRS; ++i) {
const auto &market = group->perpMarkets[i];
const auto marketPk = market.perpMarket.toBase58();

if (marketPk == std::string("11111111111111111111111111111111")) continue;

spdlog::info("PERP: {}", i);
spdlog::info(" market: {}", marketPk);
spdlog::info(" maintAssetWeight: {}",
market.maintAssetWeight.to_double());
spdlog::info(" initAssetWeight: {}", market.initAssetWeight.to_double());
spdlog::info(" maintLiabWeight: {}", market.maintLiabWeight.to_double());
spdlog::info(" initLiabWeight: {}", market.initLiabWeight.to_double());
spdlog::info(" liquidationFee: {}", market.liquidationFee.to_double());
spdlog::info(" makerFee: {}", market.makerFee.to_double());
spdlog::info(" takerFee: {}", market.takerFee.to_double());
spdlog::info(" baseLotSize: {}", market.baseLotSize);
spdlog::info(" quoteLotSize: {}", market.quoteLotSize);
}
spdlog::info("SPOT: {}", i);
spdlog::info(" market: {}", marketPk.toBase58());
spdlog::info(" maintAssetWeight: {}", market.maintAssetWeight.to_double());
spdlog::info(" initAssetWeight: {}", market.initAssetWeight.to_double());
spdlog::info(" maintLiabWeight: {}", market.maintLiabWeight.to_double());
spdlog::info(" initLiabWeight: {}", market.initLiabWeight.to_double());
spdlog::info(" liquidationFee: {}", market.liquidationFee.to_double());
}

for (int i = 0; i < mango_v3::MAX_PAIRS; ++i) {
const auto oraclePk = group->oracles[i].toBase58();
for (int i = 0; i < mango_v3::MAX_PAIRS; ++i) {
const auto &market = group->perpMarkets[i];
const auto marketPk = market.perpMarket;

if (marketPk == DEFAULT_PUBLICKEY) continue;

spdlog::info("PERP: {}", i);
spdlog::info(" market: {}", marketPk.toBase58());
spdlog::info(" maintAssetWeight: {}", market.maintAssetWeight.to_double());
spdlog::info(" initAssetWeight: {}", market.initAssetWeight.to_double());
spdlog::info(" maintLiabWeight: {}", market.maintLiabWeight.to_double());
spdlog::info(" initLiabWeight: {}", market.initLiabWeight.to_double());
spdlog::info(" liquidationFee: {}", market.liquidationFee.to_double());
spdlog::info(" makerFee: {}", market.makerFee.to_double());
spdlog::info(" takerFee: {}", market.takerFee.to_double());
spdlog::info(" baseLotSize: {}", market.baseLotSize);
spdlog::info(" quoteLotSize: {}", market.quoteLotSize);
}

if (oraclePk == std::string("11111111111111111111111111111111")) continue;
for (int i = 0; i < mango_v3::MAX_PAIRS; ++i) {
const auto oraclePk = group->oracles[i];

spdlog::info("ORACLE {}: {}", i, oraclePk);
}
if (oraclePk == DEFAULT_PUBLICKEY) continue;

spdlog::info("signerNonce: {}", group->signerNonce);
spdlog::info("signerKey: {}", group->signerKey.toBase58());
spdlog::info("admin: {}", group->admin.toBase58());
spdlog::info("dexProgramId: {}", group->dexProgramId.toBase58());
spdlog::info("mangoCache: {}", group->mangoCache.toBase58());
spdlog::info("validInterval: {}", group->validInterval);
spdlog::info("insuranceVault: {}", group->insuranceVault.toBase58());
spdlog::info("srmVault: {}", group->srmVault.toBase58());
spdlog::info("msrmVault: {}", group->msrmVault.toBase58());
spdlog::info("feesVault: {}", group->feesVault.toBase58());
spdlog::info("maxMangoAccounts: {}", group->maxMangoAccounts);
spdlog::info("numMangoAccounts: {}", group->numMangoAccounts);
spdlog::info("ORACLE {}: {}", i, oraclePk.toBase58());
}
return 0;

spdlog::info("signerNonce: {}", group->signerNonce);
spdlog::info("signerKey: {}", group->signerKey.toBase58());
spdlog::info("admin: {}", group->admin.toBase58());
spdlog::info("dexProgramId: {}", group->dexProgramId.toBase58());
spdlog::info("mangoCache: {}", group->mangoCache.toBase58());
spdlog::info("validInterval: {}", group->validInterval);
spdlog::info("insuranceVault: {}", group->insuranceVault.toBase58());
spdlog::info("srmVault: {}", group->srmVault.toBase58());
spdlog::info("msrmVault: {}", group->msrmVault.toBase58());
spdlog::info("feesVault: {}", group->feesVault.toBase58());
spdlog::info("maxMangoAccounts: {}", group->maxMangoAccounts);
spdlog::info("numMangoAccounts: {}", group->numMangoAccounts);
}
78 changes: 0 additions & 78 deletions examples/placeOrder.cpp

This file was deleted.

20 changes: 15 additions & 5 deletions examples/positions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <spdlog/spdlog.h>

#include "MangoAccount.hpp"
#include "solana.hpp"

using json = nlohmann::json;

Expand All @@ -9,13 +10,22 @@ int main() {
auto connection = solana::rpc::Connection(config.endpoint);
const auto accountPubkey = "F3TTrgxjrkAHdS9zEidtwU5VXyvMgr5poii4HYatZheH";
const auto& mangoAccountInfo =
connection.getAccountInfo<mango_v3::MangoAccountInfo>(accountPubkey);
connection
.getAccountInfo<mango_v3::MangoAccountInfo>(
solana::PublicKey::fromBase58(accountPubkey))
.value.value()
.data;
mango_v3::MangoAccount mangoAccount =
mango_v3::MangoAccount(mangoAccountInfo);
auto openOrders = mangoAccount.loadOpenOrders(connection);
auto group = connection.getAccountInfo<mango_v3::MangoGroup>(config.group);
auto cache = connection.getAccountInfo<mango_v3::MangoCache>(
group.mangoCache.toBase58());
auto group = connection
.getAccountInfo<mango_v3::MangoGroup>(
solana::PublicKey::fromBase58(config.group))
.value.value()
.data;
auto cache = connection.getAccountInfo<mango_v3::MangoCache>(group.mangoCache)
.value.value()
.data;
auto maintHealth =
mangoAccount.getHealth(group, cache, mango_v3::HealthType::Maint);
auto initHealth =
Expand All @@ -42,4 +52,4 @@ int main() {
spdlog::info("quoteTokenFree: {}", openOrder.second.quoteTokenFree);
spdlog::info("quoteTokenTotal: {}", openOrder.second.quoteTokenTotal);
}
}
}
Loading