├── .gitignore ├── README.md ├── SUMMARY.md ├── builder-ideas.md ├── deep-dives ├── anatomy-of-an-exchange.md ├── deep-dives.md ├── fund-management.md ├── market-management.md ├── order-management.md ├── protocol-fees.md ├── understanding-market-prices.md └── working-with-bns.md ├── examples ├── LICENSE ├── README.md ├── cli-admin │ ├── .env │ │ ├── .env.devnet-edge │ │ ├── .env.devnet-release │ │ └── .env.mainnet-release │ ├── .husky │ │ └── pre-commit │ ├── .prettierrc │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── market_close.ts │ │ ├── market_create.ts │ │ ├── market_get.ts │ │ ├── market_open.ts │ │ ├── market_settle.ts │ │ ├── market_types │ │ │ ├── create_market_type.ts │ │ │ ├── get_market_type_by_name.ts │ │ │ ├── get_market_type_by_pk.ts │ │ │ └── get_market_types.ts │ │ ├── market_update_status.ts │ │ ├── operator_add_market_operator.ts │ │ ├── operator_check_roles.ts │ │ ├── operator_get_operators.ts │ │ ├── price_ladder │ │ │ ├── add_prices_to_ladder.ts │ │ │ ├── create_ladder_account.ts │ │ │ ├── get_default_ladder.ts │ │ │ ├── get_ladder.ts │ │ │ └── get_ladders.ts │ │ └── utils.ts │ └── tsconfig.json ├── cli │ ├── .env │ │ ├── .env.devnet-edge │ │ ├── .env.devnet-release │ │ └── .env.mainnet-release │ ├── .husky │ │ └── pre-commit │ ├── .prettierrc │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── mappers │ │ │ ├── market_price_mapper.ts │ │ │ └── order_mapper.ts │ │ ├── markets │ │ │ ├── get_market.ts │ │ │ ├── get_market_accounts.ts │ │ │ ├── get_market_matching_pools.ts │ │ │ ├── get_market_outcome_titles.ts │ │ │ ├── get_market_outcomes.ts │ │ │ ├── get_market_position.ts │ │ │ ├── get_market_positions.ts │ │ │ ├── get_market_positions_for_wallet.ts │ │ │ ├── get_market_price_ladder.ts │ │ │ ├── get_market_status_count.ts │ │ │ ├── get_market_summary.ts │ │ │ ├── get_markets_by_event.ts │ │ │ ├── get_markets_by_mint_token.ts │ │ │ └── get_markets_by_status.ts │ │ ├── orders │ │ │ ├── build_and_place_order_with_fees.ts │ │ │ ├── cancel_order.ts │ │ │ ├── cancel_orders_for_market.ts │ │ │ ├── get_order.ts │ │ │ ├── get_orders_by_status.ts │ │ │ ├── get_orders_for_market_by_status.ts │ │ │ ├── place_against_order.ts │ │ │ ├── place_for_order.ts │ │ │ └── place_multiple_orders.ts │ │ ├── parsers │ │ │ └── parsers.ts │ │ ├── products │ │ │ ├── create_product.ts │ │ │ ├── get_all_product_balances_by_mint.ts │ │ │ ├── get_all_products.ts │ │ │ ├── get_all_products_by_authority.ts │ │ │ ├── get_all_products_by_payer.ts │ │ │ ├── update_product_auth.ts │ │ │ ├── update_product_escrow.ts │ │ │ └── update_product_rate.ts │ │ ├── trades │ │ │ ├── get_trades_for_market.ts │ │ │ └── get_trades_for_order.ts │ │ └── utils │ │ │ ├── get_balances.ts │ │ │ └── utils.ts │ ├── tsconfig.json │ └── wallet │ │ └── example.json └── nextjs │ ├── .eslintrc.js │ ├── .eslintrc.json │ ├── README.md │ ├── next-env.d.ts │ ├── next.config.js │ ├── package-lock.json │ ├── package.json │ ├── postcss.config.js │ ├── public │ ├── next.svg │ └── vercel.svg │ ├── src │ ├── app │ │ ├── favicon.ico │ │ ├── globals.css │ │ └── layout.tsx │ ├── components │ │ ├── events │ │ │ ├── event.tsx │ │ │ └── eventFilter.tsx │ │ ├── forms │ │ │ ├── mint.tsx │ │ │ └── nameAddress.tsx │ │ ├── markets │ │ │ ├── market.tsx │ │ │ ├── marketOutcomes.tsx │ │ │ ├── marketPosition.css │ │ │ ├── marketPosition.tsx │ │ │ └── marketPrices.tsx │ │ ├── navigation │ │ │ ├── explorerLink.tsx │ │ │ ├── footer.css │ │ │ ├── footer.tsx │ │ │ ├── loading.tsx │ │ │ ├── navBar.css │ │ │ └── navBar.tsx │ │ ├── orders │ │ │ ├── orderMatrix.css │ │ │ ├── orderMatrix.tsx │ │ │ ├── orderMatrixForAgainst.tsx │ │ │ └── placeOrder.tsx │ │ ├── priceMatrix │ │ │ ├── priceMatrix.css │ │ │ └── priceMatrix.tsx │ │ ├── products │ │ │ └── product.tsx │ │ ├── purchaser │ │ │ └── purchaser.tsx │ │ ├── seeder │ │ │ ├── seedMarket.tsx │ │ │ ├── seedMatrix.tsx │ │ │ ├── seedOutcome.tsx │ │ │ ├── seeder.tsx │ │ │ └── style.css │ │ ├── settings │ │ │ ├── activeSettings.tsx │ │ │ ├── mints.tsx │ │ │ ├── programAddresses.tsx │ │ │ ├── rpcNodes.tsx │ │ │ ├── savedWallets.tsx │ │ │ └── viewVersion.tsx │ │ ├── transactions │ │ │ ├── accountList.tsx │ │ │ ├── cancelOrderInstructionComponent.tsx │ │ │ ├── createOrderInstructionComponent.tsx │ │ │ ├── matchOrderInstructionComponent.tsx │ │ │ ├── processCommissionInstructionComponent.tsx │ │ │ ├── settleMarketInstructionComponent.tsx │ │ │ ├── settleMarketPositionInstructionComponent.tsx │ │ │ ├── settleOrderInstructionComponent.tsx │ │ │ ├── style.css │ │ │ ├── transactionComponent.tsx │ │ │ └── transactions.tsx │ │ └── ui │ │ │ ├── clock.tsx │ │ │ └── connect-wallet-button.tsx │ ├── config │ │ ├── appSettings.ts │ │ ├── approvedWallets.ts │ │ └── seederSettings.ts │ ├── const │ │ ├── markets.ts │ │ └── orders.ts │ ├── context │ │ ├── AutoConnectProvider.tsx │ │ ├── ProgramContext.tsx │ │ └── WalletContextProvider.tsx │ ├── database │ │ ├── database.js │ │ ├── endpoints │ │ │ ├── database.ts │ │ │ ├── events.ts │ │ │ └── products.ts │ │ └── types.d.ts │ ├── endpoints │ │ ├── balance │ │ │ └── fetchBalance.ts │ │ ├── events │ │ │ └── fetchEvents.ts │ │ ├── markets │ │ │ ├── fetchMarketMatchingPools.ts │ │ │ ├── fetchMarketOutcomes.ts │ │ │ ├── fetchMarketPosition.ts │ │ │ └── fetchMarkets.ts │ │ ├── orders │ │ │ ├── cancelOrder.ts │ │ │ ├── fetchOrders.ts │ │ │ └── placeOrder.ts │ │ ├── products │ │ │ └── fetchProducts.ts │ │ └── transactions │ │ │ └── fetchTransactions.ts │ ├── hooks │ │ └── walletRedirect.ts │ ├── idls │ │ └── monacoProtocol │ │ │ ├── 0.10.0.json │ │ │ ├── 0.10.1.json │ │ │ ├── 0.11.0.json │ │ │ ├── 0.12.0.json │ │ │ ├── 0.5.0.json │ │ │ ├── 0.6.0.json │ │ │ ├── 0.7.0.json │ │ │ ├── 0.8.0.json │ │ │ └── 0.9.0.json │ ├── pages │ │ ├── _app.tsx │ │ ├── events.js │ │ ├── index.js │ │ ├── market.js │ │ ├── markets.js │ │ ├── orders.js │ │ ├── products.js │ │ ├── settings.js │ │ ├── transactions.js │ │ └── walletInsight.js │ ├── types │ │ ├── forms.ts │ │ └── settings.ts │ └── utils │ │ ├── display.ts │ │ ├── events.ts │ │ ├── localStorage.ts │ │ ├── mappers │ │ ├── marketPrices.ts │ │ ├── markets.ts │ │ ├── orders.ts │ │ └── transactions.ts │ │ ├── navigation.ts │ │ ├── orders.ts │ │ ├── parsers.ts │ │ ├── seeder │ │ └── seederSettings.js │ │ ├── settings.js │ │ └── time.ts │ ├── tailwind.config.ts │ └── tsconfig.json ├── hackathons ├── README.md ├── monacode-2023.md ├── monacode-2023 │ └── general-terms-and-conditions-of-participation.md └── opos-hackathon-2023.md ├── media ├── images │ ├── anatomy_of_an_exchange │ │ ├── exchange_1.png │ │ ├── exchange_2_event.png │ │ ├── exchange_3_market.png │ │ ├── exchange_3_outcomes.png │ │ ├── exchange_4_matrix.png │ │ ├── exchange_5_orders.png │ │ ├── exchange_6_trades.png │ │ ├── exchange_7_position.png │ │ └── exchange_8_order_mgmt.png │ ├── architecture_overview_1.png │ ├── monaco_protocol_logo_black.png │ ├── monaco_protocol_logo_white.png │ ├── order_creation_1.png │ ├── order_creation_2.png │ ├── order_matching_1.png │ └── order_matching_2.png └── pdf │ └── sec3_audit_the_monaco_protocol_nov_2022.pdf └── readme ├── branding-assets.md ├── built-on-monaco.md ├── commission.md ├── events-program.md ├── order-management.md ├── points-terms-and-conditions.md ├── privacy-notice.md ├── terms-of-service.md ├── the-admin-client.md ├── the-client.md ├── the-cranks.md ├── the-dev-environment.md ├── the-protocol.md └── the-roadmap.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | colorpicker/.anchor 3 | .DS_Store 4 | target 5 | **/*.rs.bk 6 | node_modules 7 | .idea 8 | tmp 9 | wallet.json 10 | __pycache__/ 11 | 12 | # testing 13 | **/coverage 14 | 15 | # next.js 16 | **/.next/ 17 | **/out/ 18 | 19 | # production 20 | **/build 21 | 22 | # no example wallet for admin 23 | **/cli-admin/wallet/ 24 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Table of contents 2 | 3 | * [Monaco Protocol](README.md) 4 | * [The Protocol](readme/the-protocol.md) 5 | * [The Cranks](readme/the-cranks.md) 6 | * [The Client](readme/the-client.md) 7 | * [The Admin Client](readme/the-admin-client.md) 8 | * [The Dev Environment](readme/the-dev-environment.md) 9 | * [The Roadmap](readme/the-roadmap.md) 10 | * [Commission](readme/commission.md) 11 | * [Built on The Monaco Protocol](readme/built-on-monaco.md) 12 | * [Events Program](readme/events-program.md) 13 | * [Terms of Service](readme/terms-of-service.md) 14 | * [Privacy Notice](readme/privacy-notice.md) 15 | * [Points Terms and Conditions](readme/points-terms-and-conditions.md) 16 | * [Branding Assets](readme/branding-assets.md) 17 | * [Deep Dives](deep-dives/deep-dives.md) 18 | * [Protocol Fees](deep-dives/protocol-fees.md) 19 | * [Order Management](deep-dives/order-management.md) 20 | * [Market Management](deep-dives/market-management.md) 21 | * [Working with BNs](deep-dives/working-with-bns.md) 22 | * [Understanding Market Prices](deep-dives/understanding-market-prices.md) 23 | * [Fund Management](deep-dives/fund-management.md) 24 | * [Anatomy of an Exchange](deep-dives/anatomy-of-an-exchange.md) 25 | * [Hackathons](hackathons/README.md) 26 | * [Monacode 2023](hackathons/monacode-2023.md) 27 | * [General Terms and Conditions of Participation](hackathons/monacode-2023/general-terms-and-conditions-of-participation.md) 28 | * [OPOS Hackathon 2023](hackathons/opos-hackathon-2023.md) 29 | * [Builder Ideas](builder-ideas.md) 30 | -------------------------------------------------------------------------------- /deep-dives/deep-dives.md: -------------------------------------------------------------------------------- 1 | # Deep Dives 2 | 3 | This section contains a more in-depth look into the inner workings of the protocol. 4 | 5 | -------------------------------------------------------------------------------- /deep-dives/order-management.md: -------------------------------------------------------------------------------- 1 | # Order Management 2 | 3 | -------------------------------------------------------------------------------- /examples/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 MonacoProtocol 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Monaco Protocol SDK Examples 2 | 3 | This repository contains examples for working with the Monaco Protocol Client 4 | 5 | ## Client 6 | 7 | - [Command Line Interface](./cli) 8 | - [NextJS](./nextjs) 9 | 10 | ## Admin Client 11 | 12 | - [Command Line Interface](./cli-admin) 13 | 14 | # Getting Started - RPC Node 15 | 16 | With any of the examples, you will need an RPC node in order to make requests to the protocol. You can read more about the RPC infrastructure on https://solana.com/rpc. There are many services available (listed on the solana RPC page) so pick one that suits your needs. Two you may wish to consider: 17 | 18 | ## Helius 19 | 20 | - Navigate to https://www.helius.dev/ 21 | - Select `Launch Dev Portal` 22 | - Sign in with your preferred choice between: 23 | - A solana wallet 24 | - Github 25 | - Google 26 | - Select `Generate Helius API Key` 27 | - On https://dev.helius.xyz/dashboard/app you'll then see your `Helius RPC URLs` for both `mainnet` and `devnet` 28 | 29 | ## Shyft 30 | 31 | - Navigate to https://shyft.to/ 32 | - Select `Get API Key` 33 | - Sign in with your preferred choice between: 34 | - Email 35 | - Google 36 | - Copy your API key/RPC URL from https://shyft.to/dashboard/overview 37 | - Use the toggle to switch the URL between `mainnet` and `devnet` 38 | -------------------------------------------------------------------------------- /examples/cli-admin/.env/.env.devnet-edge: -------------------------------------------------------------------------------- 1 | CONFIG_NAME=devnet-edge 2 | PROTOCOL_ADDRESS=mpDEVnZKneBb4w1vQsoTgMkNqnFe1rwW8qjmf3NsrAU 3 | ANCHOR_WALLET=./wallet/example.json 4 | ANCHOR_PROVIDER_URL=https://api.devnet.solana.com -------------------------------------------------------------------------------- /examples/cli-admin/.env/.env.devnet-release: -------------------------------------------------------------------------------- 1 | CONFIG_NAME=devnet-release 2 | PROTOCOL_ADDRESS=monacoUXKtUi6vKsQwaLyxmXKSievfNWEcYXTgkbCih 3 | ANCHOR_WALLET=./wallet/example.json 4 | ANCHOR_PROVIDER_URL=https://api.devnet.solana.com -------------------------------------------------------------------------------- /examples/cli-admin/.env/.env.mainnet-release: -------------------------------------------------------------------------------- 1 | CONFIG_NAME=mainnet-release 2 | PROTOCOL_ADDRESS=monacoUXKtUi6vKsQwaLyxmXKSievfNWEcYXTgkbCih 3 | ANCHOR_WALLET=./wallet/example.json 4 | ANCHOR_PROVIDER_URL=https://api.mainnet-beta.solana.com -------------------------------------------------------------------------------- /examples/cli-admin/.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /examples/cli-admin/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "trailingComma": "none", 4 | "singleQuote": false, 5 | "printWidth": 80 6 | } 7 | -------------------------------------------------------------------------------- /examples/cli-admin/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | Unlike the examples for the primary client, no example wallet is included in with these admin-function examples. To get started, you will want to generate your own wallet for admin functionality. 4 | 5 | ``` 6 | mkdir wallet 7 | solana-keygen new -o wallet/example.json 8 | ``` 9 | 10 | To help ensure this wallet isn't accidentally committed, the path to the example wallet dir `**/cli-admin/wallet/` is included in the [.gitignore](../../.gitignore) file for this repository. 11 | 12 | As a general reminder, never include a keypair in your own repository. 13 | 14 | # Install 15 | 16 | ``` 17 | npm install 18 | ``` 19 | 20 | # Setting Environment 21 | 22 | Environmental settings are configured in `.env` files in `.env/.env-*` there are three environments that you can connect to by exporting one of the following values: 23 | 24 | ``` 25 | export ENVIRONMENT=mainnet-release 26 | export ENVIRONMENT=devnet-edge 27 | export ENVIRONMENT=devnet-release 28 | ``` 29 | 30 | The examples in this repo use [anchor](https://github.com/coral-xyz/anchor) and each `.env` file sets an RPC-node with `ANCHOR_PROVIDER_URL`. 31 | 32 | - The default one for `devnet` is a public example RPC-node subject to rate-limiting. 33 | - The `mainnet` one is a placeholders and will need to be changed for a `mainnet` rpc node. 34 | - For any development beyond casual call inspection on `devnet` you should set yourself up with your own RPC-node. 35 | 36 | ## RPC-Node 37 | 38 | Make sure you have your own RPC Node set up, check out [Getting Started - RPC Node](../README.md#getting-started---rpc-node) for more info. 39 | 40 | # Scripts 41 | 42 | - All example scripts have been added to the [package.json](package.json) for execution, to list them - `npm run` 43 | - Where arguments are needed, when you invoke a script, you will be informed what arguments are missing for example: 44 | 45 | ``` 46 | $ npm run getOperatorsByType 47 | 48 | > @monaco-protocol/admin-examples@0.0.1 getOperatorsByType 49 | > ts-node src/operator_get_operators.ts 50 | 51 | > Expected number of args: 1 52 | > Example invocation: npm run getOperatorsByType operatorType 53 | ``` 54 | 55 | When you run a script you will also be presented with information for debugging purposes: 56 | 57 | - The arguments provided 58 | - The set environment 59 | - The set RPC node 60 | - The set wallet publicKey 61 | 62 | # Operators 63 | 64 | In order to create a market, an authorised wallet is required. It is recommended that you create a new CLI wallet for this purpose. You can then make a request to be added as an authorised market operator on the [dev hub](https://github.com/MonacoProtocol/sdk/discussions). The `checkOperatorRoles` function included with the admin client allows you to check what operator roles a given wallet has. 65 | 66 | The example script, `checkRoles` returns roles for your set `ANCHOR_WALLET`. 67 | 68 | ``` 69 | npm run checkRoles 70 | 71 | > @monaco-protocol/admin-examples@0.0.1 checkRoles 72 | > ts-node src/operator_check_roles.ts 73 | 74 | Supplied arguments: 75 | {} 76 | { 77 | "success": true, 78 | "errors": [], 79 | "data": { 80 | "operatorPk": "98CVwMftrhm6zutmV29frqRPfXsocbFnwjXVxYo7xbHX", 81 | "admin": true, 82 | "market": true, 83 | "crank": false 84 | } 85 | } 86 | ``` 87 | -------------------------------------------------------------------------------- /examples/cli-admin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@monaco-protocol/admin-examples", 3 | "version": "1.0.0", 4 | "description": "Monaco Protocol Admin Client Examples", 5 | "author": "Monaco Protocol", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "scripts": { 9 | "checkRoles": "ts-node src/operator_check_roles.ts", 10 | "addMarketOperator": "ts-node src/operator_add_market_operator.ts", 11 | "getOperatorsByType": "ts-node src/operator_get_operators.ts", 12 | "createLadder": "ts-node src/price_ladder/create_ladder_account.ts", 13 | "addPricesToLadder": "ts-node src/price_ladder/add_prices_to_ladder.ts", 14 | "getLadder": "ts-node src/price_ladder/get_ladder.ts", 15 | "getLadders": "ts-node src/price_ladder/get_ladders.ts", 16 | "getDefaultLadder": "ts-node src/price_ladder/get_default_ladder.ts", 17 | "getMarketTypes": "ts-node src/market_types/get_market_types.ts", 18 | "getMarketTypeByName": "ts-node src/market_types/get_market_type_by_name.ts", 19 | "getMarketTypeByPk": "ts-node src/market_types/get_market_type_by_pk.ts", 20 | "createMarketType": "ts-node src/market_types/create_market_type.ts", 21 | "openMarket": "ts-node src/market_open.ts", 22 | "createMarket": "ts-node src/market_create.ts", 23 | "settleMarket": "ts-node src/market_settle.ts", 24 | "closeMarket": "ts-node src/market_close.ts", 25 | "getMarket": "ts-node src/market_get.ts", 26 | "updateMarketStatus": "ts-node src/market_update_status.ts", 27 | "format": "prettier --config .prettierrc 'src/**/*.(ts|js)' --write", 28 | "prepare": "husky install" 29 | }, 30 | "dependencies": { 31 | "@monaco-protocol/admin-client": "8.0.0", 32 | "@monaco-protocol/client": "^9.0.0", 33 | "bs58": "^4.0.1", 34 | "@coral-xyz/anchor": "~0.27.0", 35 | "@solana/spl-token": "^0.3.5", 36 | "@solana/web3.js": "^1.68.0", 37 | "typescript": "^4.5.4", 38 | "dotenv": "^16.0.3", 39 | "ts-node": "^10.7.0" 40 | }, 41 | "devDependencies": { 42 | "husky": "^8.0.3", 43 | "lint-staged": "^13.1.0", 44 | "prettier": "2.8.2" 45 | }, 46 | "lint-staged": { 47 | "**/*": "prettier --write --ignore-unknown" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_close.ts: -------------------------------------------------------------------------------- 1 | import { setMarketReadyToClose } from "@monaco-protocol/admin-client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "./utils"; 4 | 5 | async function closeMarket(marketPk: PublicKey) { 6 | const program = await getProgram(); 7 | const response = await setMarketReadyToClose(program, marketPk); 8 | logResponse(response); 9 | } 10 | 11 | const args = getProcessArgs(["marketPk"], "npm run closeMarket"); 12 | closeMarket(new PublicKey(args.marketPk)); 13 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_create.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey, Keypair } from "@solana/web3.js"; 2 | import { 3 | createMarket, 4 | initialiseOutcomes, 5 | checkOperatorRoles 6 | } from "@monaco-protocol/admin-client"; 7 | import { getProgram, log, getProcessArgs, logResponse, FULL_PRICE_LADDER_ACCOUNT } from "./utils"; 8 | 9 | async function createVerboseMarket(mintToken: PublicKey) { 10 | const program = await getProgram(); 11 | const checkRoles = await checkOperatorRoles( 12 | program, 13 | program.provider.publicKey 14 | ); 15 | 16 | if (!checkRoles.data.market) 17 | throw new Error( 18 | `Currently set wallet ${program.provider.publicKey} does not have the operator role` 19 | ); 20 | 21 | // Generate a publicKey to represent the event 22 | const eventAccountKeyPair = Keypair.generate(); 23 | const eventPk = eventAccountKeyPair.publicKey; 24 | 25 | const marketName = "Example Market"; 26 | const marketLock = 32503680000; 27 | const outcomes = ["Red", "Blue"]; 28 | 29 | log(`Creating market ⏱`); 30 | const marketResponse = await createMarket( 31 | program, 32 | marketName, 33 | 'EventResultWinner', 34 | mintToken, 35 | marketLock, 36 | eventPk 37 | ); 38 | logResponse(marketResponse); 39 | if (marketResponse.success) 40 | log(`Market ${marketResponse.data.marketPk.toString()} created ✅`); 41 | else return; 42 | 43 | const marketPk = marketResponse.data.marketPk; 44 | 45 | log(`Initialising market outcomes ⏱`); 46 | const initialiseOutcomePoolsResponse = await initialiseOutcomes( 47 | program, 48 | marketPk, 49 | outcomes, 50 | FULL_PRICE_LADDER_ACCOUNT() 51 | ); 52 | 53 | logResponse(initialiseOutcomePoolsResponse); 54 | if (initialiseOutcomePoolsResponse.success) 55 | log(`Outcomes added to market ✅`); 56 | else return; 57 | 58 | log(`Market ${marketPk.toString()} creation complete ✨`); 59 | } 60 | 61 | const args = getProcessArgs(["mintToken"], "npm run createMarket"); 62 | createVerboseMarket(new PublicKey(args.mintToken)); 63 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_get.ts: -------------------------------------------------------------------------------- 1 | import { getMarket } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "./utils"; 4 | 5 | async function getMarketByPk(marketPk: PublicKey) { 6 | const program = await getProgram(); 7 | const response = await getMarket(program, marketPk); 8 | logResponse(response); 9 | } 10 | 11 | const args = getProcessArgs(["marketPk"], "npm run getMarket"); 12 | getMarketByPk(new PublicKey(args.marketPk)); 13 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_open.ts: -------------------------------------------------------------------------------- 1 | import { openMarket } from "@monaco-protocol/admin-client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "./utils"; 4 | 5 | async function openNewMarket(marketPk: PublicKey) { 6 | const program = await getProgram(); 7 | const response = await openMarket(program, marketPk); 8 | logResponse(response); 9 | } 10 | 11 | const args = getProcessArgs(["marketPk"], "npm run openMarket"); 12 | openNewMarket(new PublicKey(args.marketPk)); 13 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_settle.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from "@solana/web3.js"; 2 | import { settleMarket } from "@monaco-protocol/admin-client"; 3 | import { getProgram, getProcessArgs, logResponse } from "./utils"; 4 | 5 | async function settlement(marketPk: PublicKey, winningOutcomeIndex: number) { 6 | const program = await getProgram(); 7 | const response = await settleMarket(program, marketPk, winningOutcomeIndex); 8 | logResponse(response); 9 | } 10 | 11 | const args = getProcessArgs( 12 | ["marketPk", "winningOutcomeIndex"], 13 | "npm run settleMarket" 14 | ); 15 | settlement(new PublicKey(args.marketPk), parseFloat(args.winningOutcomeIndex)); 16 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_types/create_market_type.ts: -------------------------------------------------------------------------------- 1 | import { getOrCreateMarketType } from "@monaco-protocol/admin-client"; 2 | import { getProgram, getProcessArgs, logResponse } from "../utils"; 3 | 4 | async function marketType() { 5 | const program = await getProgram(); 6 | const marketTypeName = 'SDK_WINNER' 7 | const requiresDiscriminator = false; 8 | const requiresValue = false; 9 | const response = await getOrCreateMarketType(program, marketTypeName, requiresDiscriminator, requiresValue); 10 | logResponse(response); 11 | } 12 | 13 | getProcessArgs([], "npm run createMarketType"); 14 | marketType(); 15 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_types/get_market_type_by_name.ts: -------------------------------------------------------------------------------- 1 | 2 | import { findMarketTypePda } from "@monaco-protocol/admin-client"; 3 | import { getProgram, getProcessArgs } from "../utils"; 4 | 5 | async function getMarketType(marketTypeName: string) { 6 | const program = await getProgram(); 7 | const pda = findMarketTypePda(program, marketTypeName); 8 | const response = await program.account.marketType.fetch(pda.data.pda); 9 | console.log(JSON.stringify(response, null, 3)); 10 | } 11 | 12 | const args = getProcessArgs(["marketTypeName"], "npm run getMarketTypeByName"); 13 | getMarketType(args.marketTypeName); 14 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_types/get_market_type_by_pk.ts: -------------------------------------------------------------------------------- 1 | 2 | import { getProgram, getProcessArgs } from "../utils"; 3 | import { PublicKey } from "@solana/web3.js"; 4 | 5 | async function getMarketType(publicKey: PublicKey) { 6 | const program = await getProgram(); 7 | const response = await program.account.marketType.fetch(publicKey); 8 | console.log(JSON.stringify(response, null, 3)); 9 | } 10 | 11 | const args = getProcessArgs(["marketTypePk"], "npm run getMarketTypeByPk"); 12 | getMarketType(new PublicKey(args.marketTypePk)); 13 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_types/get_market_types.ts: -------------------------------------------------------------------------------- 1 | 2 | import { getProgram, getProcessArgs } from "../utils"; 3 | 4 | async function getMarketTypes() { 5 | const program = await getProgram(); 6 | const response = await program.account.marketType.all(); 7 | console.log(JSON.stringify(response, null, 3)); 8 | } 9 | 10 | getProcessArgs([], "npm run getMarketTypes"); 11 | getMarketTypes(); 12 | -------------------------------------------------------------------------------- /examples/cli-admin/src/market_update_status.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from "@solana/web3.js"; 2 | import { 3 | publishMarket, 4 | unpublishMarket, 5 | suspendMarket, 6 | unsuspendMarket 7 | } from "@monaco-protocol/admin-client"; 8 | import { getProgram, logResponse, getProcessArgs } from "./utils"; 9 | 10 | async function updateStatus(marketPk: PublicKey, status: string) { 11 | const program = await getProgram(); 12 | let response; 13 | try { 14 | switch (status) { 15 | case "publish": 16 | response = await publishMarket(program, marketPk); 17 | logResponse(response); 18 | break; 19 | case "unpublish": 20 | response = await unpublishMarket(program, marketPk); 21 | logResponse(response); 22 | break; 23 | case "suspend": 24 | response = await suspendMarket(program, marketPk); 25 | logResponse(response); 26 | break; 27 | case "unsuspend": 28 | response = await unsuspendMarket(program, marketPk); 29 | logResponse(response); 30 | break; 31 | default: 32 | throw "Invalid status supplied. Available statuses: publish, unpublish, suspend, unsuspend"; 33 | } 34 | } catch (e) { 35 | console.log(e); 36 | } 37 | } 38 | 39 | const args = getProcessArgs( 40 | ["marketPk", "status"], 41 | "npm run updateMarketStatus" 42 | ); 43 | updateStatus(new PublicKey(args.marketPk), args.status); 44 | -------------------------------------------------------------------------------- /examples/cli-admin/src/operator_add_market_operator.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from "@solana/web3.js"; 2 | import { authoriseMarketOperator } from "@monaco-protocol/admin-client"; 3 | import { getProgram, getProcessArgs, logResponse } from "./utils"; 4 | 5 | async function addRole(newOperatorPk: PublicKey) { 6 | const program = await getProgram(); 7 | const response = await authoriseMarketOperator(program, newOperatorPk); 8 | logResponse(response); 9 | } 10 | 11 | const args = getProcessArgs(["newOperatorPk"], "npm run addMarketOperator"); 12 | addRole(new PublicKey(args.newOperatorPk)); 13 | -------------------------------------------------------------------------------- /examples/cli-admin/src/operator_check_roles.ts: -------------------------------------------------------------------------------- 1 | import { checkOperatorRoles } from "@monaco-protocol/admin-client"; 2 | import { getProgram, getProcessArgs, logResponse } from "./utils"; 3 | 4 | async function checkRoles() { 5 | const program = await getProgram(); 6 | const response = await checkOperatorRoles( 7 | program, 8 | program.provider.publicKey 9 | ); 10 | logResponse(response); 11 | } 12 | 13 | getProcessArgs([], "npm run checkRoles"); 14 | checkRoles(); 15 | -------------------------------------------------------------------------------- /examples/cli-admin/src/operator_get_operators.ts: -------------------------------------------------------------------------------- 1 | import { 2 | getOperatorsAccountByType, 3 | Operator 4 | } from "@monaco-protocol/admin-client"; 5 | import { 6 | getProgram, 7 | getProcessArgs, 8 | operatorTypeFromString, 9 | logResponse 10 | } from "./utils"; 11 | 12 | async function getOperators(operatorType: Operator) { 13 | const program = await getProgram(); 14 | const response = await getOperatorsAccountByType(program, operatorType); 15 | logResponse(response); 16 | } 17 | 18 | const args = getProcessArgs(["operatorType"], "npm run getOperatorsByType"); 19 | getOperators(operatorTypeFromString(args.operatorType)); 20 | -------------------------------------------------------------------------------- /examples/cli-admin/src/price_ladder/add_prices_to_ladder.ts: -------------------------------------------------------------------------------- 1 | import { DEFAULT_PRICE_LADDER, addPricesToPriceLadder, findPriceLadderPda } from "@monaco-protocol/admin-client"; 2 | import { getProgram, getProcessArgs, logResponse } from "../utils"; 3 | 4 | async function addPrices(priceLadderName: string) { 5 | const program = await getProgram(); 6 | const pda = findPriceLadderPda(program, priceLadderName); 7 | const batchSize = 15; 8 | const response = await addPricesToPriceLadder(program, pda.data.pda, DEFAULT_PRICE_LADDER, batchSize); 9 | logResponse(response); 10 | } 11 | 12 | const args = getProcessArgs(["priceLadderName"], "npm run addPricesToLadder"); 13 | addPrices(args.priceLadderName); 14 | -------------------------------------------------------------------------------- /examples/cli-admin/src/price_ladder/create_ladder_account.ts: -------------------------------------------------------------------------------- 1 | import { createPriceLadder, findPriceLadderPda } from "@monaco-protocol/admin-client"; 2 | import { getProgram, getProcessArgs, logResponse } from "../utils"; 3 | 4 | async function createPriceLadderAccount(priceLadderName: string) { 5 | const program = await getProgram(); 6 | const pda = findPriceLadderPda(program, priceLadderName); 7 | const response = await createPriceLadder(program, pda.data.pda, priceLadderName, 317); 8 | logResponse(response); 9 | } 10 | 11 | const args = getProcessArgs(["priceLadderName"], "npm run createLadder"); 12 | createPriceLadderAccount(args.priceLadderName); 13 | 14 | -------------------------------------------------------------------------------- /examples/cli-admin/src/price_ladder/get_default_ladder.ts: -------------------------------------------------------------------------------- 1 | import { findPriceLadderPda } from "@monaco-protocol/admin-client"; 2 | import { getProgram, getProcessArgs } from "../utils"; 3 | 4 | async function getLadder() { 5 | const program = await getProgram(); 6 | const pda = findPriceLadderPda(program, 'DEFAULT_PRICE_LADDER'); 7 | const response = await program.account.priceLadder.fetch(pda.data.pda); 8 | console.log(JSON.stringify(response)); 9 | } 10 | 11 | getProcessArgs([], "npm run getDefaultLadder"); 12 | getLadder(); 13 | 14 | -------------------------------------------------------------------------------- /examples/cli-admin/src/price_ladder/get_ladder.ts: -------------------------------------------------------------------------------- 1 | import { findPriceLadderPda } from "@monaco-protocol/admin-client"; 2 | import { getProgram, getProcessArgs } from "../utils"; 3 | 4 | async function getLadder(priceLadderName: string) { 5 | const program = await getProgram(); 6 | const pda = findPriceLadderPda(program, priceLadderName); 7 | const response = await program.account.priceLadder.fetch(pda.data.pda); 8 | console.log(JSON.stringify(response)); 9 | } 10 | 11 | const args = getProcessArgs(["priceLadderName"], "npm run getLadder"); 12 | getLadder(args.priceLadderName); 13 | 14 | -------------------------------------------------------------------------------- /examples/cli-admin/src/price_ladder/get_ladders.ts: -------------------------------------------------------------------------------- 1 | import { getProgram, getProcessArgs } from "../utils"; 2 | 3 | async function getLadders() { 4 | const program = await getProgram(); 5 | const response = await program.account.priceLadder.all(); 6 | console.log(JSON.stringify(response, null, 1)); 7 | } 8 | 9 | getProcessArgs([], "npm run getLadders"); 10 | getLadders(); 11 | -------------------------------------------------------------------------------- /examples/cli-admin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "typeRoots": ["./node_modules/@types"], 4 | "target": "es2022", 5 | "module": "commonjs", 6 | "esModuleInterop": true, 7 | "moduleResolution": "Node", 8 | "baseUrl": "scripts" 9 | }, 10 | "include": ["src/**/*"] 11 | } 12 | -------------------------------------------------------------------------------- /examples/cli/.env/.env.devnet-edge: -------------------------------------------------------------------------------- 1 | CONFIG_NAME=devnet-edge 2 | PROTOCOL_ADDRESS=mpDEVnZKneBb4w1vQsoTgMkNqnFe1rwW8qjmf3NsrAU 3 | PROTOCOL_PRODUCT_ADDRESS=mppFrYmM6A4Ud3AxRbGXsGisX1HUsbDfp1nrg9FQJEE 4 | ANCHOR_WALLET=./wallet/example.json 5 | ANCHOR_PROVIDER_URL=https://api.devnet.solana.com -------------------------------------------------------------------------------- /examples/cli/.env/.env.devnet-release: -------------------------------------------------------------------------------- 1 | CONFIG_NAME=devnet-release 2 | PROTOCOL_ADDRESS=monacoUXKtUi6vKsQwaLyxmXKSievfNWEcYXTgkbCih 3 | PROTOCOL_PRODUCT_ADDRESS=mppFrYmM6A4Ud3AxRbGXsGisX1HUsbDfp1nrg9FQJEE 4 | ANCHOR_WALLET=./wallet/example.json 5 | ANCHOR_PROVIDER_URL=https://api.devnet.solana.com -------------------------------------------------------------------------------- /examples/cli/.env/.env.mainnet-release: -------------------------------------------------------------------------------- 1 | CONFIG_NAME=mainnet-release 2 | PROTOCOL_ADDRESS=monacoUXKtUi6vKsQwaLyxmXKSievfNWEcYXTgkbCih 3 | PROTOCOL_PRODUCT_ADDRESS=mppFrYmM6A4Ud3AxRbGXsGisX1HUsbDfp1nrg9FQJEE 4 | ANCHOR_WALLET=./wallet/example.json 5 | ANCHOR_PROVIDER_URL=https://api.mainnet-beta.solana.com -------------------------------------------------------------------------------- /examples/cli/.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /examples/cli/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "trailingComma": "none", 4 | "singleQuote": false, 5 | "printWidth": 80 6 | } 7 | -------------------------------------------------------------------------------- /examples/cli/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | This repository contains a solana wallet keypair located in [/wallet/example.json](./wallet/example.json) in order to run the example scripts with minimal setup. Please be aware that this keypair is public and should never be used on `Mainnet`. Never include a keypair in your own repository. You can read more about CLI wallets [here](https://docs.solana.com/wallet-guide/cli). 4 | 5 | The publicKey for this wallet is `5BZWY6XWPxuWFxs2jagkmUkCoBWmJ6c4YEArr83hYBWk` 6 | 7 | :warning: As a reminder, these wallet keyPairs are stored within the repository for educational purposes only. Never include a keypair in your own repository. :warning: 8 | 9 | # Install 10 | 11 | ``` 12 | npm install 13 | ``` 14 | 15 | # Setting Environment 16 | 17 | Environmental settings are configured in `.env` files in `.env/.env-*` there are three environments that you can connect to by exporting one of the following values: 18 | 19 | ``` 20 | export ENVIRONMENT=mainnet-release 21 | export ENVIRONMENT=devnet-edge 22 | export ENVIRONMENT=devnet-release 23 | ``` 24 | 25 | The examples in this repo use [anchor](https://github.com/coral-xyz/anchor) and each `.env` file sets an RPC-node with `ANCHOR_PROVIDER_URL`. 26 | 27 | - The default one for `devnet` is a public example RPC-node subject to rate-limiting. 28 | - The `mainnet` one is a placeholders and will need to be changed for a `mainnet` rpc node. 29 | - For any development beyond casual call inspection on `devnet` you should set yourself up with your own RPC-node. 30 | 31 | ## RPC-Node 32 | 33 | Make sure you have your own RPC Node set up, check out [Getting Started - RPC Node](../README.md#getting-started---rpc-node) for more info. 34 | 35 | # Scripts 36 | 37 | - All example scripts have been added to the [package.json](package.json) for execution, to list them - `npm run` 38 | - Where arguments are needed, when you invoke a script, you will be informed what arguments are missing for example: 39 | 40 | ``` 41 | $ npm run getMarket 42 | 43 | > @monaco-protocol/examples@1.0.0 getMarket 44 | > ts-node src/get_market.ts 45 | 46 | > Expected number of args: 1 47 | > Example invocation: npm run getMarket marketPk 48 | ``` 49 | 50 | When you run a script you will also be presented with information for debugging purposes: 51 | 52 | - The arguments provided 53 | - The set environment 54 | - The set RPC node 55 | - The set wallet publicKey 56 | 57 | ## Match Orders & View Trades 58 | 59 | To get a matching order and view trade accounts (trade accounts contain the details for matched orders), run the following against the same market: 60 | 61 | ``` 62 | npm run placeForOrder 63 | ``` 64 | 65 | ``` 66 | npm run placeAgainstOrder 67 | ``` 68 | 69 | ``` 70 | npm run getTradesForMarket 71 | ``` 72 | -------------------------------------------------------------------------------- /examples/cli/src/mappers/market_price_mapper.ts: -------------------------------------------------------------------------------- 1 | import { MarketPrice } from "@monaco-protocol/client"; 2 | 3 | export function mapPricesToOutcomesAndForAgainst( 4 | outcomeTitles: string[], 5 | marketPrices: MarketPrice[] 6 | ) { 7 | const mapping = outcomeTitles.map((outcomeTitle) => { 8 | const forOutcome = marketPrices.filter( 9 | (marketPrice) => 10 | marketPrice.forOutcome && marketPrice.marketOutcome === outcomeTitle 11 | ); 12 | const againstOutcome = marketPrices.filter( 13 | (marketPrice) => 14 | !marketPrice.forOutcome && marketPrice.marketOutcome === outcomeTitle 15 | ); 16 | return { 17 | for: forOutcome.map((price) => { 18 | return { 19 | outcome: outcomeTitle, 20 | price: price.price, 21 | liquidity: price.matchingPool.liquidityAmount 22 | }; 23 | }), 24 | against: againstOutcome.map((price) => { 25 | return { 26 | outcome: outcomeTitle, 27 | price: price.price, 28 | liquidity: price.matchingPool.liquidityAmount 29 | }; 30 | }) 31 | }; 32 | }); 33 | return mapping; 34 | } 35 | -------------------------------------------------------------------------------- /examples/cli/src/mappers/order_mapper.ts: -------------------------------------------------------------------------------- 1 | import { Order } from "@monaco-protocol/client"; 2 | 3 | export function mapOrdersToOutcomesAndForAgainst( 4 | outcomeTitles: string[], 5 | orders: Order[] 6 | ) { 7 | const mapping = outcomeTitles.map((outcomeTitle) => { 8 | const forOutcome = orders.filter( 9 | (order) => 10 | order.forOutcome && 11 | order.marketOutcomeIndex === outcomeTitles.indexOf(outcomeTitle) 12 | ); 13 | const againstOutcome = orders.filter( 14 | (order) => 15 | !order.forOutcome && 16 | order.marketOutcomeIndex === outcomeTitles.indexOf(outcomeTitle) 17 | ); 18 | return { 19 | for: forOutcome.map((order) => { 20 | return { 21 | outcome: outcomeTitle, 22 | expectedPrice: order.expectedPrice, 23 | stake: order.stake 24 | }; 25 | }), 26 | against: againstOutcome.map((order) => { 27 | return { 28 | outcome: outcomeTitle, 29 | expectedPrice: order.expectedPrice, 30 | stake: order.stake 31 | }; 32 | }) 33 | }; 34 | }); 35 | return mapping; 36 | } 37 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market.ts: -------------------------------------------------------------------------------- 1 | import { getMarket } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { parseResponseData } from "../parsers/parsers"; 5 | 6 | async function getMarketByPk(marketPk: PublicKey) { 7 | const program = await getProgram(); 8 | const response = await getMarket(program, marketPk); 9 | response.data = parseResponseData(response.data); 10 | logResponse(response); 11 | } 12 | 13 | const args = getProcessArgs(["marketPk"], "npm run getMarket"); 14 | getMarketByPk(new PublicKey(args.marketPk)); 15 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_accounts.ts: -------------------------------------------------------------------------------- 1 | import { getMarketAccounts } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { parseResponseData } from "../parsers/parsers"; 5 | 6 | async function getAllMarketAccounts( 7 | marketPk: PublicKey, 8 | backing: boolean, 9 | marketOutcomeIndex: number, 10 | price: number 11 | ) { 12 | const program = await getProgram(); 13 | const response = await getMarketAccounts( 14 | program, 15 | marketPk, 16 | backing, 17 | marketOutcomeIndex, 18 | price 19 | ); 20 | response.data = parseResponseData(response.data); 21 | logResponse(response); 22 | } 23 | 24 | const args = getProcessArgs( 25 | ["marketPk", "forOutcome", "marketOutcomeIndex", "price"], 26 | "npm run getMarketAccounts" 27 | ); 28 | getAllMarketAccounts( 29 | new PublicKey(args.marketPk), 30 | args.forOutcome === "true", 31 | parseFloat(args.marketOutcomeIndex), 32 | parseFloat(args.price) 33 | ); 34 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_matching_pools.ts: -------------------------------------------------------------------------------- 1 | import { getAllMarketMatchingPools } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { 5 | parseResponseData 6 | } from "../parsers/parsers"; 7 | 8 | async function marketMatchingPools(marketPk: PublicKey) { 9 | const program = await getProgram(); 10 | const response = await getAllMarketMatchingPools(program, marketPk); 11 | response.data = parseResponseData(response.data); 12 | logResponse(response); 13 | } 14 | 15 | const args = getProcessArgs(["marketPk"], "npm run getMarketMatchingPools"); 16 | marketMatchingPools(new PublicKey(args.marketPk)); 17 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_outcome_titles.ts: -------------------------------------------------------------------------------- 1 | import { getMarketOutcomeTitlesByMarket } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs } from "../utils/utils"; 4 | 5 | async function marketOutcomeTitles(marketPk: PublicKey) { 6 | const program = await getProgram(); 7 | const response = await getMarketOutcomeTitlesByMarket(program, marketPk); 8 | console.table(response.data.marketOutcomeTitles); 9 | } 10 | 11 | const args = getProcessArgs(["marketPk"], "npm run getMarketOutcomeTitles"); 12 | marketOutcomeTitles(new PublicKey(args.marketPk)); 13 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_outcomes.ts: -------------------------------------------------------------------------------- 1 | import { getMarketOutcomesByMarket } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { parseResponseData } from "../parsers/parsers"; 5 | 6 | async function marketOutcomes(marketPk: PublicKey) { 7 | const program = await getProgram(); 8 | const response = await getMarketOutcomesByMarket(program, marketPk); 9 | response.data = parseResponseData(response.data); 10 | logResponse(response); 11 | } 12 | 13 | const args = getProcessArgs(["marketPk"], "npm run getMarketOutcomes"); 14 | marketOutcomes(new PublicKey(args.marketPk)); 15 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_position.ts: -------------------------------------------------------------------------------- 1 | import { getMarketPosition } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { AnchorProvider } from "@coral-xyz/anchor"; 5 | import { parseResponseData } from "../parsers/parsers"; 6 | 7 | async function getMarketPositionForProvider(marketPk: PublicKey) { 8 | const program = await getProgram(); 9 | const provider = program.provider as AnchorProvider; 10 | const response = await getMarketPosition( 11 | program, 12 | marketPk, 13 | provider.wallet.publicKey 14 | ); 15 | response.data = parseResponseData(response.data); 16 | logResponse(response); 17 | } 18 | 19 | const args = getProcessArgs(["marketPk"], "npm run getMarketPosition"); 20 | getMarketPositionForProvider(new PublicKey(args.marketPk)); 21 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_positions.ts: -------------------------------------------------------------------------------- 1 | import { MarketPositions } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { AnchorProvider } from "@coral-xyz/anchor"; 5 | import { parseResponseData } from "../parsers/parsers"; 6 | 7 | async function getMarketPositionForProvider(marketPk: PublicKey) { 8 | const program = await getProgram(); 9 | const provider = program.provider as AnchorProvider; 10 | const response = await MarketPositions.marketPositionQuery(program) 11 | .filterByMarket(marketPk) 12 | .fetch(); 13 | response.data = parseResponseData(response.data); 14 | logResponse(response); 15 | } 16 | 17 | const args = getProcessArgs( 18 | ["marketPk"], 19 | "npm run getMarketPositionsForMarket" 20 | ); 21 | getMarketPositionForProvider(new PublicKey(args.marketPk)); 22 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_positions_for_wallet.ts: -------------------------------------------------------------------------------- 1 | import { MarketPositions, getMarketOutcomeTitlesByMarket } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs } from "../utils/utils"; 4 | import { AnchorProvider } from "@coral-xyz/anchor"; 5 | import { parseResponseData } from "../parsers/parsers"; 6 | 7 | async function getMarketPositionForWallet(walletPk: PublicKey) { 8 | const program = await getProgram(); 9 | const provider = program.provider as AnchorProvider; 10 | const response = await MarketPositions.marketPositionQuery(program) 11 | .filterByPurchaser(walletPk) 12 | .filterByPaid(false) 13 | .fetch(); 14 | response.data = parseResponseData(response.data, 6); 15 | const positions = {}; 16 | for (const position of response.data.marketPositionAccounts) { 17 | const outcomeTitles = await getMarketOutcomeTitlesByMarket(program, position.account.market); 18 | const matchedPosition = position.account.marketOutcomeSums.map((exposure, index) => { 19 | return { 20 | outcome: outcomeTitles.data.marketOutcomeTitles[index], 21 | exposure: exposure, 22 | unmatched: position.account.unmatchedExposures[index] 23 | } 24 | }); 25 | 26 | positions[position.account.market.toBase58()] = { 27 | position: matchedPosition, 28 | } 29 | } 30 | for (const market in positions) { 31 | console.log(`Market: ${market}`); 32 | console.table(positions[market].position); 33 | } 34 | } 35 | 36 | const args = getProcessArgs( 37 | ["walletPk"], 38 | "npm run getMarketPositionsForWallet" 39 | ); 40 | getMarketPositionForWallet(new PublicKey(args.walletPk)); 41 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_price_ladder.ts: -------------------------------------------------------------------------------- 1 | import { getMarketOutcomesByMarket } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs } from "../utils/utils"; 4 | 5 | async function marketPriceLadder(marketPk: PublicKey) { 6 | const program = await getProgram(); 7 | const market = (await getMarketOutcomesByMarket(program, marketPk)) as any; 8 | // assuming market has been created with a price ladder account 9 | const pricesAccount = market.data.marketOutcomeAccounts[0].account.prices; 10 | const response = await program.account.priceLadder.fetch(pricesAccount); 11 | console.log(JSON.stringify(response, null, 3)); 12 | } 13 | 14 | const args = getProcessArgs(["marketPk"], "npm run getMarketPriceLadder"); 15 | marketPriceLadder(new PublicKey(args.marketPk)); 16 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_market_status_count.ts: -------------------------------------------------------------------------------- 1 | import { MarketStatusFilter, Markets } from "@monaco-protocol/client"; 2 | import { getProcessArgs, getProgram } from "../utils/utils"; 3 | 4 | const getStatusCount = async () => { 5 | const program = await getProgram(); 6 | const statuses = [ 7 | MarketStatusFilter.Initializing, 8 | MarketStatusFilter.Open, 9 | MarketStatusFilter.Settled, 10 | MarketStatusFilter.Voided, 11 | MarketStatusFilter.ReadyForSettlement, 12 | MarketStatusFilter.ReadyToVoid, 13 | MarketStatusFilter.ReadyToClose 14 | ]; 15 | const statusPromises = statuses.map((status) => 16 | Markets.marketQuery(program).filterByStatus(status).fetchPublicKeys() 17 | ); 18 | const resolvePromises = await Promise.all(statusPromises); 19 | const allStatuses = []; 20 | for (const marketStatus of statuses) { 21 | allStatuses.push({ 22 | status: MarketStatusFilter[marketStatus], 23 | count: resolvePromises[statuses.indexOf(marketStatus)].data.publicKeys.length 24 | }); 25 | } 26 | console.table(allStatuses); 27 | }; 28 | 29 | getProcessArgs([], "npm run getMarketCount"); 30 | getStatusCount(); 31 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_markets_by_event.ts: -------------------------------------------------------------------------------- 1 | import { getMarketAccountsByEvent } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { parseResponseData } from "../parsers/parsers"; 5 | 6 | async function getMarkets(eventAccountPk: PublicKey) { 7 | const program = await getProgram(); 8 | const response = await getMarketAccountsByEvent(program, eventAccountPk); 9 | response.data = parseResponseData(response.data); 10 | logResponse(response); 11 | } 12 | 13 | const args = getProcessArgs(["eventPk"], "npm run getMarketsByEvent"); 14 | getMarkets(new PublicKey(args.eventPk)); 15 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_markets_by_mint_token.ts: -------------------------------------------------------------------------------- 1 | import { 2 | getMarketAccountsByStatusAndMintAccount, 3 | MarketStatusFilter 4 | } from "@monaco-protocol/client"; 5 | import { PublicKey } from "@solana/web3.js"; 6 | import { 7 | getProgram, 8 | getProcessArgs, 9 | marketStatusFromString, 10 | logResponse 11 | } from "../utils/utils"; 12 | import { parseResponseData } from "../parsers/parsers"; 13 | 14 | async function getMarkets( 15 | mintToken: PublicKey, 16 | marketStatus: MarketStatusFilter 17 | ) { 18 | const program = await getProgram(); 19 | const response = await getMarketAccountsByStatusAndMintAccount( 20 | program, 21 | marketStatus, 22 | mintToken 23 | ); 24 | response.data = parseResponseData(response.data); 25 | logResponse(response); 26 | } 27 | 28 | // The Monaco Protocol example token: Aqw6KyChFm2jwAFND3K29QjUcKZ3Pk72ePe5oMxomwMH 29 | const args = getProcessArgs( 30 | ["mintToken", "marketStatus"], 31 | "npm run getMarketsByMintToken" 32 | ); 33 | getMarkets( 34 | new PublicKey(args.mintToken), 35 | marketStatusFromString(args.marketStatus) 36 | ); 37 | -------------------------------------------------------------------------------- /examples/cli/src/markets/get_markets_by_status.ts: -------------------------------------------------------------------------------- 1 | import { 2 | getMarketAccountsByStatus, 3 | MarketStatusFilter 4 | } from "@monaco-protocol/client"; 5 | import { 6 | getProgram, 7 | getProcessArgs, 8 | marketStatusFromString, 9 | logResponse 10 | } from "../utils/utils"; 11 | import { parseResponseData } from "../parsers/parsers"; 12 | 13 | async function getMarkets(status: MarketStatusFilter) { 14 | const program = await getProgram(); 15 | const response = await getMarketAccountsByStatus(program, status); 16 | response.data = parseResponseData(response.data); 17 | logResponse(response); 18 | } 19 | 20 | const args = getProcessArgs(["marketStatus"], "npm run getMarketsByStatus"); 21 | getMarkets(marketStatusFromString(args.marketStatus)); 22 | -------------------------------------------------------------------------------- /examples/cli/src/orders/cancel_order.ts: -------------------------------------------------------------------------------- 1 | import { cancelOrder } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | 5 | async function cancelOrderbyPk(orderPk: PublicKey) { 6 | const program = await getProgram(); 7 | const response = await cancelOrder(program, orderPk); 8 | logResponse(response); 9 | } 10 | 11 | const args = getProcessArgs(["orderPk"], "npm run cancelOrder"); 12 | cancelOrderbyPk(new PublicKey(args.orderPk)); 13 | -------------------------------------------------------------------------------- /examples/cli/src/orders/cancel_orders_for_market.ts: -------------------------------------------------------------------------------- 1 | import { cancelOrdersForMarket } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | 5 | async function cancelOrders(marketPk: PublicKey) { 6 | const program = await getProgram(); 7 | const response = await cancelOrdersForMarket(program, marketPk); 8 | logResponse(response); 9 | } 10 | 11 | const args = getProcessArgs(["marketPk"], "npm run cancelOrders"); 12 | cancelOrders(new PublicKey(args.marketPk)); 13 | -------------------------------------------------------------------------------- /examples/cli/src/orders/get_order.ts: -------------------------------------------------------------------------------- 1 | import { getOrder } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { parseResponseData } from "../parsers/parsers"; 5 | 6 | async function getBetOrderbyPk(betOrderPk: PublicKey) { 7 | const program = await getProgram(); 8 | const response = await getOrder(program, betOrderPk); 9 | response.data = parseResponseData(response.data); 10 | logResponse(response); 11 | } 12 | 13 | const args = getProcessArgs(["betOrderPk"], "npm run getOrder"); 14 | getBetOrderbyPk(new PublicKey(args.betOrderPk)); 15 | -------------------------------------------------------------------------------- /examples/cli/src/orders/get_orders_by_status.ts: -------------------------------------------------------------------------------- 1 | import { 2 | getOrdersByStatusForProviderWallet, 3 | OrderStatusFilter 4 | } from "@monaco-protocol/client"; 5 | import { 6 | getProgram, 7 | getProcessArgs, 8 | orderStatusFromString, 9 | logResponse 10 | } from "../utils/utils"; 11 | import { parseResponseData } from "../parsers/parsers"; 12 | 13 | async function getBetOrders(status: OrderStatusFilter) { 14 | const program = await getProgram(); 15 | const response = await getOrdersByStatusForProviderWallet(program, status); 16 | response.data = parseResponseData(response.data); 17 | logResponse(response); 18 | } 19 | 20 | const args = getProcessArgs(["orderStatus"], "npm run getOrdersByStatus"); 21 | getBetOrders(orderStatusFromString(args.orderStatus)); 22 | -------------------------------------------------------------------------------- /examples/cli/src/orders/get_orders_for_market_by_status.ts: -------------------------------------------------------------------------------- 1 | import { Orders, OrderStatusFilter } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { 4 | getProgram, 5 | getProcessArgs, 6 | orderStatusFromString, 7 | logResponse 8 | } from "../utils/utils"; 9 | import { parseResponseData } from "../parsers/parsers"; 10 | 11 | async function getBetOrders(marketPk: PublicKey, status: OrderStatusFilter) { 12 | const program = await getProgram(); 13 | const response = await Orders.orderQuery(program) 14 | .filterByMarket(marketPk) 15 | .filterByStatus(status) 16 | .fetch(); 17 | response.data = parseResponseData(response.data); 18 | logResponse(response); 19 | } 20 | 21 | const args = getProcessArgs( 22 | ["marketPk", "orderStatus"], 23 | "npm run getOrdersForMarketByStatus" 24 | ); 25 | getBetOrders( 26 | new PublicKey(args.marketPk), 27 | orderStatusFromString(args.orderStatus) 28 | ); 29 | -------------------------------------------------------------------------------- /examples/cli/src/orders/place_against_order.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from "@solana/web3.js"; 2 | import { getProcessArgs } from "../utils/utils"; 3 | import { placeOrder } from "./place_for_order"; 4 | 5 | const args = getProcessArgs(["marketPk"], "npm run placeAgainstOrder"); 6 | placeOrder(new PublicKey(args.marketPk), false); 7 | -------------------------------------------------------------------------------- /examples/cli/src/orders/place_for_order.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from "@solana/web3.js"; 2 | import { 3 | createOrderUiStake, 4 | getMarketOutcomesByMarket 5 | } from "@monaco-protocol/client"; 6 | import { 7 | getProgram, 8 | getProcessArgs, 9 | logResponse, 10 | SDK_PRODUCT 11 | } from "../utils/utils"; 12 | 13 | export async function placeOrder( 14 | marketPk: PublicKey, 15 | forOutcome: boolean = true 16 | ) { 17 | const program = await getProgram(); 18 | const marketOutcomeIndex = 0; 19 | const price = 2; 20 | const stake = 1; 21 | // temp as any due to missing field on type 22 | const market = (await getMarketOutcomesByMarket(program, marketPk)) as any; 23 | const response = await createOrderUiStake( 24 | program, 25 | marketPk, 26 | marketOutcomeIndex, 27 | forOutcome, 28 | price, 29 | stake, 30 | market.data.marketOutcomeAccounts[marketOutcomeIndex].account.prices, 31 | SDK_PRODUCT 32 | ); 33 | logResponse(response); 34 | } 35 | 36 | const args = getProcessArgs(["marketPk"], "npm run placeForOrder"); 37 | placeOrder(new PublicKey(args.marketPk)); 38 | -------------------------------------------------------------------------------- /examples/cli/src/orders/place_multiple_orders.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from "@solana/web3.js"; 2 | import { 3 | buildOrderInstructionUIStake, 4 | confirmTransaction, 5 | getMarketOutcomesByMarket, 6 | signAndSendInstructionsBatch 7 | } from "@monaco-protocol/client"; 8 | import { 9 | getProgram, 10 | getProcessArgs, 11 | logResponse, 12 | SDK_PRODUCT, 13 | log 14 | } from "../utils/utils"; 15 | 16 | export async function placeMultipleOrders(marketPk: PublicKey) { 17 | const program = await getProgram(); 18 | const marketOutcomeIndex = 0; 19 | const forOutcome = true; 20 | const price1 = 2; 21 | const price2 = 1.98; 22 | const stake = 1; 23 | // temp as any due to missing field on type 24 | const market = (await getMarketOutcomesByMarket(program, marketPk)) as any; 25 | const order1 = await buildOrderInstructionUIStake( 26 | program, 27 | marketPk, 28 | marketOutcomeIndex, 29 | forOutcome, 30 | price1, 31 | stake, 32 | market.data.marketOutcomeAccounts[marketOutcomeIndex].account.prices, 33 | SDK_PRODUCT 34 | ); 35 | const order2 = await buildOrderInstructionUIStake( 36 | program, 37 | marketPk, 38 | marketOutcomeIndex, 39 | forOutcome, 40 | price2, 41 | stake, 42 | market.data.marketOutcomeAccounts[marketOutcomeIndex].account.prices, 43 | SDK_PRODUCT 44 | ); 45 | const orders = [order1.data.instruction, order2.data.instruction]; 46 | const response = await signAndSendInstructionsBatch(program, orders, 2); 47 | // optional confirmation step, as we know there will only be one signature we are using the first one in the response array 48 | const confirm = await confirmTransaction( 49 | program, 50 | response.data.signatures[0] 51 | ); 52 | logResponse(response); 53 | logResponse(confirm); 54 | } 55 | 56 | const args = getProcessArgs(["marketPk"], "npm run placeMultipleOrders"); 57 | placeMultipleOrders(new PublicKey(args.marketPk)); 58 | -------------------------------------------------------------------------------- /examples/cli/src/parsers/parsers.ts: -------------------------------------------------------------------------------- 1 | import { BN } from "@coral-xyz/anchor"; 2 | 3 | export function parseResponseData( 4 | responseData: any, 5 | mintDecimals = 0, 6 | bnKeys: string[] = bigNumberKeys, 7 | bnMintKeys: string[] = bigNumberMintKeys, 8 | bnMintArrays: string[] = bigNumberMintArrays 9 | ): any { 10 | if (!responseData) return responseData; 11 | for (const [key, value] of Object.entries(responseData)) { 12 | if (value === null || value === undefined) { 13 | // no op 14 | } else if (bnKeys.includes(key)) { 15 | const timestamp = value as BN; 16 | responseData[key] = timestamp.toNumber(); 17 | } else if (bnMintKeys.includes(key)) { 18 | const mintValue = value as BN; 19 | if (mintDecimals) { 20 | responseData[key] = integerToUiValue(mintValue, mintDecimals); 21 | } else { 22 | responseData[key] = mintValue.toNumber(); 23 | } 24 | } else if (bnMintArrays.includes(key)) { 25 | for (const rawValue of value as []) { 26 | const index = responseData[key].indexOf(rawValue); 27 | const mintValue = rawValue as BN; 28 | if (mintDecimals) { 29 | responseData[key][index] = integerToUiValue(mintValue, mintDecimals); 30 | } else { 31 | responseData[key][index] = mintValue.toNumber(); 32 | } 33 | } 34 | } else if (typeof value === "object") { 35 | responseData[key] = parseResponseData(value, mintDecimals); 36 | } 37 | } 38 | return responseData; 39 | } 40 | 41 | export function integerToUiValue(integerValue: BN, mintDecimals: number) { 42 | return integerValue.toNumber() / 10 ** mintDecimals; 43 | } 44 | 45 | const emptyOrderString = "11111111111111111111111111111111"; 46 | 47 | /** All data keys for BNs */ 48 | export const bigNumberKeys = [ 49 | "marketLockTimestamp", 50 | "marketSettleTimestamp", 51 | "eventStartTimestamp", 52 | "creationTimestamp", 53 | "delayExpirationTimestamp" 54 | ]; 55 | 56 | /** All data keys for BNs returning mint values */ 57 | export const bigNumberMintKeys = [ 58 | "payout", 59 | "stake", 60 | "stakeUnmatched", 61 | "voidedStake", 62 | "matchedTotal", 63 | "liquidityAmount", 64 | "matchedAmount", 65 | "liquidityToAdd", 66 | "matchedRisk", 67 | "risk" 68 | ]; 69 | 70 | /** All data keys for BNs returning mint values in an array */ 71 | export const bigNumberMintArrays = ["marketOutcomeSums", "unmatchedExposures"]; 72 | -------------------------------------------------------------------------------- /examples/cli/src/products/create_product.ts: -------------------------------------------------------------------------------- 1 | import { createProduct } from "@monaco-protocol/client"; 2 | import { 3 | getProgram, 4 | getProcessArgs, 5 | logResponse, 6 | ProtocolTypes 7 | } from "../utils/utils"; 8 | import { parseResponseData } from "../parsers/parsers"; 9 | 10 | async function newProduct() { 11 | const program = await getProgram(ProtocolTypes.MONACO_PRODUCT); 12 | const productTitle = "SDK_EXAMPLE_PRODUCT"; 13 | const commissionRate = 0; 14 | const commissionEscrow = program.provider.publicKey; 15 | const response = await createProduct( 16 | program, 17 | productTitle, 18 | commissionRate, 19 | commissionEscrow 20 | ); 21 | response.data = parseResponseData(response.data); 22 | logResponse(response); 23 | } 24 | 25 | getProcessArgs([], "npm run createProduct"); 26 | newProduct(); 27 | -------------------------------------------------------------------------------- /examples/cli/src/products/get_all_product_balances_by_mint.ts: -------------------------------------------------------------------------------- 1 | import { Products } from "@monaco-protocol/client"; 2 | import { getProgram, getProcessArgs, ProtocolTypes, log } from "../utils/utils"; 3 | import { getAssociatedTokenAddress } from "@solana/spl-token"; 4 | import { PublicKey } from "@solana/web3.js"; 5 | 6 | async function getBalances(mintPk: PublicKey) { 7 | const allowOwnerOffCurve = true; 8 | const program = await getProgram(ProtocolTypes.MONACO_PRODUCT); 9 | const response = await Products.productQuery(program).fetch(); 10 | const uniqueEscrowAccounts = [ 11 | ...new Set( 12 | response.data.productAccounts.map((product) => 13 | product.account.commissionEscrow.toBase58() 14 | ) 15 | ) 16 | ]; 17 | log(`${"*".repeat(75)}`); 18 | uniqueEscrowAccounts.map(async (escrowAccount) => { 19 | try { 20 | const tokenAccount = await getAssociatedTokenAddress( 21 | mintPk, 22 | new PublicKey(escrowAccount), 23 | allowOwnerOffCurve 24 | ); 25 | const balance = await program.provider.connection.getTokenAccountBalance( 26 | tokenAccount 27 | ); 28 | log( 29 | `Products: ${response.data.productAccounts 30 | .filter( 31 | (product) => 32 | product.account.commissionEscrow.toBase58() === escrowAccount 33 | ) 34 | .map((product) => product.account.productTitle) 35 | .join(", ")}` 36 | ); 37 | log(`Escrow Account: ${escrowAccount}`); 38 | log(`Balance: ${balance.value.uiAmountString}`); 39 | log(`${"*".repeat(75)}`); 40 | } catch { 41 | log(`Unable to get balance for ${escrowAccount}`); 42 | log(`${"*".repeat(75)}`); 43 | } 44 | }); 45 | } 46 | 47 | const args = getProcessArgs(["mintPk"], "npm run getProductBalancesByMint"); 48 | getBalances(new PublicKey(args.mintPk)); 49 | -------------------------------------------------------------------------------- /examples/cli/src/products/get_all_products.ts: -------------------------------------------------------------------------------- 1 | import { Products } from "@monaco-protocol/client"; 2 | import { 3 | getProgram, 4 | getProcessArgs, 5 | logResponse, 6 | ProtocolTypes 7 | } from "../utils/utils"; 8 | import { parseResponseData } from "../parsers/parsers"; 9 | 10 | async function getAllProducts() { 11 | const program = await getProgram(ProtocolTypes.MONACO_PRODUCT); 12 | const response = await Products.productQuery(program).fetch(); 13 | response.data = parseResponseData(response.data); 14 | logResponse(response); 15 | } 16 | 17 | getProcessArgs([], "npm run getAllProducts"); 18 | getAllProducts(); 19 | -------------------------------------------------------------------------------- /examples/cli/src/products/get_all_products_by_authority.ts: -------------------------------------------------------------------------------- 1 | import { Products } from "@monaco-protocol/client"; 2 | import { 3 | getProgram, 4 | getProcessArgs, 5 | logResponse, 6 | ProtocolTypes 7 | } from "../utils/utils"; 8 | import { parseResponseData } from "../parsers/parsers"; 9 | import { PublicKey } from "@solana/web3.js"; 10 | 11 | async function getAllProductsByAuth(authorityPk: PublicKey) { 12 | const program = await getProgram(ProtocolTypes.MONACO_PRODUCT); 13 | const response = await Products.productQuery(program) 14 | .filterByAuthority(authorityPk) 15 | .fetch(); 16 | response.data = parseResponseData(response.data); 17 | logResponse(response); 18 | } 19 | 20 | const args = getProcessArgs( 21 | ["authorityPk"], 22 | "npm run getAllProductsByAuthority" 23 | ); 24 | getAllProductsByAuth(new PublicKey(args.authorityPk)); 25 | -------------------------------------------------------------------------------- /examples/cli/src/products/get_all_products_by_payer.ts: -------------------------------------------------------------------------------- 1 | import { Products } from "@monaco-protocol/client"; 2 | import { 3 | getProgram, 4 | getProcessArgs, 5 | logResponse, 6 | ProtocolTypes 7 | } from "../utils/utils"; 8 | import { parseResponseData } from "../parsers/parsers"; 9 | import { PublicKey } from "@solana/web3.js"; 10 | 11 | async function getAllProductsByPayer(payerPk: PublicKey) { 12 | const program = await getProgram(ProtocolTypes.MONACO_PRODUCT); 13 | const response = await Products.productQuery(program) 14 | .filterByPayer(payerPk) 15 | .fetch(); 16 | response.data = parseResponseData(response.data); 17 | logResponse(response); 18 | } 19 | 20 | const args = getProcessArgs(["payerPk"], "npm run getAllProductsByPayer"); 21 | getAllProductsByPayer(new PublicKey(args.payerPk)); 22 | -------------------------------------------------------------------------------- /examples/cli/src/products/update_product_auth.ts: -------------------------------------------------------------------------------- 1 | import { updateProductAuthority } from "@monaco-protocol/client"; 2 | import { 3 | getProgram, 4 | getProcessArgs, 5 | logResponse, 6 | ProtocolTypes 7 | } from "../utils/utils"; 8 | import { parseResponseData } from "../parsers/parsers"; 9 | import { AnchorProvider } from "@coral-xyz/anchor"; 10 | import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet"; 11 | 12 | async function updateAuth() { 13 | const program = await getProgram(ProtocolTypes.MONACO_PRODUCT); 14 | const provider = program.provider as AnchorProvider; 15 | const productTitle = "SDK_EXAMPLE_PRODUCT"; 16 | const authorityPk = program.provider.publicKey; 17 | // Setting as the same signer for example purposes 18 | const newAuthority = (provider.wallet as NodeWallet).payer; 19 | const response = await updateProductAuthority( 20 | program, 21 | productTitle, 22 | newAuthority, 23 | authorityPk 24 | ); 25 | response.data = parseResponseData(response.data); 26 | logResponse(response); 27 | } 28 | 29 | getProcessArgs([], "npm run updateProductAuth"); 30 | updateAuth(); 31 | -------------------------------------------------------------------------------- /examples/cli/src/products/update_product_escrow.ts: -------------------------------------------------------------------------------- 1 | import { updateProductCommissionEscrow } from "@monaco-protocol/client"; 2 | import { 3 | getProgram, 4 | getProcessArgs, 5 | logResponse, 6 | ProtocolTypes 7 | } from "../utils/utils"; 8 | import { parseResponseData } from "../parsers/parsers"; 9 | 10 | async function updateEscrow() { 11 | const program = await getProgram(ProtocolTypes.MONACO_PRODUCT); 12 | const productTitle = "SDK_EXAMPLE_PRODUCT"; 13 | const authorityPk = program.provider.publicKey; 14 | // Setting as the same Pk as this is just for example purposes 15 | const newEscrowPk = program.provider.publicKey; 16 | const response = await updateProductCommissionEscrow( 17 | program, 18 | productTitle, 19 | newEscrowPk, 20 | authorityPk 21 | ); 22 | response.data = parseResponseData(response.data); 23 | logResponse(response); 24 | } 25 | 26 | getProcessArgs([], "npm run updateProductEscrow"); 27 | updateEscrow(); 28 | -------------------------------------------------------------------------------- /examples/cli/src/products/update_product_rate.ts: -------------------------------------------------------------------------------- 1 | import { updateProductCommissionRate } from "@monaco-protocol/client"; 2 | import { 3 | getProgram, 4 | getProcessArgs, 5 | logResponse, 6 | ProtocolTypes 7 | } from "../utils/utils"; 8 | import { parseResponseData } from "../parsers/parsers"; 9 | 10 | async function updateRate(newRate: number) { 11 | const program = await getProgram(ProtocolTypes.MONACO_PRODUCT); 12 | const productTitle = "SDK_EXAMPLE_PRODUCT"; 13 | const authorityPk = program.provider.publicKey; 14 | const response = await updateProductCommissionRate( 15 | program, 16 | productTitle, 17 | newRate, 18 | authorityPk 19 | ); 20 | response.data = parseResponseData(response.data); 21 | logResponse(response); 22 | } 23 | 24 | const args = getProcessArgs(["newRate"], "npm run updateProductRate"); 25 | updateRate(parseFloat(args.newRate)); 26 | -------------------------------------------------------------------------------- /examples/cli/src/trades/get_trades_for_market.ts: -------------------------------------------------------------------------------- 1 | import { getTradesForMarket } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { parseResponseData } from "../parsers/parsers"; 5 | 6 | async function getTrades(marketPk: PublicKey) { 7 | const program = await getProgram(); 8 | const response = await getTradesForMarket(program, marketPk); 9 | response.data = parseResponseData(response.data); 10 | logResponse(response); 11 | } 12 | 13 | const args = getProcessArgs(["marketPk"], "npm run getTradesForMarket"); 14 | getTrades(new PublicKey(args.marketPk)); 15 | -------------------------------------------------------------------------------- /examples/cli/src/trades/get_trades_for_order.ts: -------------------------------------------------------------------------------- 1 | import { getTradesForOrder } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "../utils/utils"; 4 | import { parseResponseData } from "../parsers/parsers"; 5 | 6 | async function getTrades(marketPk: PublicKey) { 7 | const program = await getProgram(); 8 | const response = await getTradesForOrder(program, marketPk); 9 | response.data = parseResponseData(response.data); 10 | logResponse(response); 11 | } 12 | 13 | const args = getProcessArgs(["betOrderPk"], "npm run getTradesForOrder"); 14 | getTrades(new PublicKey(args.betOrderPk)); 15 | -------------------------------------------------------------------------------- /examples/cli/src/utils/get_balances.ts: -------------------------------------------------------------------------------- 1 | import { getWalletTokenBalancesWithSol } from "@monaco-protocol/client"; 2 | import { PublicKey } from "@solana/web3.js"; 3 | import { getProgram, getProcessArgs, logResponse } from "./utils"; 4 | 5 | async function getBalances(tokenMints: PublicKey[]) { 6 | const program = await getProgram(); 7 | const response = await getWalletTokenBalancesWithSol(program, tokenMints); 8 | logResponse(response); 9 | } 10 | 11 | const exampleTokens = [ 12 | new PublicKey("Qegj89Mzpx4foJJqkj6B4551aiGrgaV33Dtcm7WZ9kf"), 13 | new PublicKey("Aqw6KyChFm2jwAFND3K29QjUcKZ3Pk72ePe5oMxomwMH") 14 | ]; 15 | getProcessArgs([], "npm run getBalances"); 16 | getBalances(exampleTokens); 17 | -------------------------------------------------------------------------------- /examples/cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "typeRoots": ["./node_modules/@types"], 4 | "target": "es2022", 5 | "module": "commonjs", 6 | "esModuleInterop": true, 7 | "moduleResolution": "Node", 8 | "baseUrl": "scripts" 9 | }, 10 | "include": ["src/**/*"] 11 | } 12 | -------------------------------------------------------------------------------- /examples/cli/wallet/example.json: -------------------------------------------------------------------------------- 1 | [ 2 | 50, 157, 42, 122, 226, 244, 149, 254, 100, 111, 247, 206, 143, 41, 5, 228, 3 | 192, 17, 26, 170, 117, 173, 67, 198, 57, 227, 105, 244, 137, 33, 57, 91, 62, 4 | 35, 80, 105, 215, 139, 168, 113, 42, 22, 224, 36, 184, 118, 191, 83, 17, 152, 5 | 70, 92, 51, 35, 44, 151, 125, 251, 29, 83, 49, 194, 15, 253 6 | ] 7 | -------------------------------------------------------------------------------- /examples/nextjs/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | ecmaFeatures: { 5 | jsx: true, 6 | }, 7 | ecmaVersion: 2021, 8 | sourceType: 'module', 9 | }, 10 | env: { 11 | browser: true, 12 | node: true, 13 | }, 14 | plugins: ['react', '@typescript-eslint', 'prettier', 'import'], 15 | extends: [ 16 | 'eslint:recommended', 17 | 'plugin:react/recommended', 18 | 'plugin:@typescript-eslint/recommended', 19 | 'plugin:prettier/recommended', 20 | 'plugin:import/errors', 21 | 'plugin:import/warnings', 22 | ], 23 | rules: { 24 | 'prettier/prettier': 'error', 25 | 'react/react-in-jsx-scope': 'off', // for Next.js 26 | 'react/prop-types': 'off', // if you're using TypeScript 27 | '@typescript-eslint/no-unused-vars': ['warn'], 28 | 'import/order': [ 29 | 'error', 30 | { 31 | groups: [['builtin', 'external'], 'internal', ['parent', 'sibling', 'index']], 32 | 'newlines-between': 'always', 33 | alphabetize: { 34 | order: 'asc', 35 | caseInsensitive: true, 36 | }, 37 | }, 38 | ], 39 | }, 40 | settings: { 41 | react: { 42 | version: 'detect', 43 | }, 44 | 'import/resolver': { 45 | typescript: {}, 46 | }, 47 | }, 48 | }; 49 | -------------------------------------------------------------------------------- /examples/nextjs/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /examples/nextjs/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | // NOTE: This file should not be edited 6 | // see https://nextjs.org/docs/basic-features/typescript for more information. 7 | -------------------------------------------------------------------------------- /examples/nextjs/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | typescript: { 4 | ignoreBuildErrors: true, 5 | }, 6 | }; 7 | 8 | module.exports = nextConfig; 9 | -------------------------------------------------------------------------------- /examples/nextjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "monaco-protocol-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "eslint . --ext .js,.jsx,.ts,.tsx", 10 | "format": "prettier --write ." 11 | }, 12 | "dependencies": { 13 | "@coral-xyz/anchor": "^0.27.0", 14 | "@monaco-protocol/client": "^9.0.0", 15 | "@monaco-protocol/seed-calculator": "^0.1.0", 16 | "@solana/spl-token": "^0.3.8", 17 | "@solana/wallet-adapter-react": "^0.15.34", 18 | "@solana/wallet-adapter-react-ui": "^0.9.33", 19 | "@solana/wallet-adapter-wallets": "^0.19.20", 20 | "@solana/web3.js": "^1.78.4", 21 | "@types/node": "20.4.9", 22 | "autoprefixer": "10.4.14", 23 | "big.js": "^6.2.1", 24 | "bs58": "^4.0.1", 25 | "dexie": "^3.2.4", 26 | "eslint-config-next": "13.4.13", 27 | "next": "^13.4.13", 28 | "postcss": "8.4.27", 29 | "react": "18.2.0", 30 | "react-dom": "18.2.0", 31 | "tailwindcss": "3.3.3", 32 | "typescript": "^4.9.5" 33 | }, 34 | "devDependencies": { 35 | "@types/big.js": "^6.2.0", 36 | "@types/bs58": "^4.0.1", 37 | "@types/react": "^18.2.20", 38 | "@typescript-eslint/eslint-plugin": "^6.3.0", 39 | "@typescript-eslint/parser": "^6.5.0", 40 | "eslint": "^8.46.0", 41 | "eslint-config-prettier": "^9.0.0", 42 | "eslint-import-resolver-typescript": "^3.6.0", 43 | "eslint-plugin-import": "^2.28.1", 44 | "eslint-plugin-prettier": "^5.0.0", 45 | "eslint-plugin-react": "^7.33.1", 46 | "eslint-plugin-react-hooks": "^5.0.0-canary-7118f5dd7-20230705", 47 | "prettier": "^3.0.1" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/nextjs/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /examples/nextjs/public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/nextjs/public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/nextjs/src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MonacoProtocol/sdk/bce5a3ee874e379e2d9ef66476ef6ba9fc30b89e/examples/nextjs/src/app/favicon.ico -------------------------------------------------------------------------------- /examples/nextjs/src/app/globals.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | background-color: #000000; 4 | color: #ffffff; 5 | margin: 0; 6 | } 7 | 8 | a { 9 | color: #7732ef; 10 | text-decoration: none; 11 | } 12 | 13 | .main-wrapper { 14 | display: flex; 15 | width: 100%; 16 | box-sizing: border-box; 17 | margin: 0; 18 | height: calc(100vh - 6rem - 3rem); 19 | } 20 | 21 | .left-container { 22 | width: 80%; 23 | top:0; 24 | padding: 20px 20px 0; 25 | box-sizing: border-box; 26 | overflow-y: auto; 27 | } 28 | 29 | .right-container { 30 | background-color: rgb(25, 24, 24); 31 | position: sticky; 32 | top: 0; 33 | width: 20%; 34 | padding: 20px; 35 | overflow-y: auto; 36 | box-sizing: border-box; 37 | } 38 | 39 | 40 | .center-container { 41 | display: flex; 42 | justify-content: center; 43 | align-items: center; 44 | text-align: center; 45 | height: calc(100vh - 6rem - 3rem); 46 | } 47 | 48 | .centered-text { 49 | font-size: 2rem; 50 | } 51 | 52 | .eventHeader { 53 | background-color: #633ba8ac; 54 | padding: 30px 30px; 55 | } -------------------------------------------------------------------------------- /examples/nextjs/src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import React, { ReactNode } from 'react'; 2 | 3 | import Footer from '../components/navigation/footer'; 4 | import NavBar from '../components/navigation/navBar'; 5 | 6 | type LayoutProps = { 7 | children: ReactNode; 8 | }; 9 | 10 | const Layout: React.FC = ({ children }) => { 11 | return ( 12 | <> 13 | 14 |
{children}
15 |