Prime Deals is an Interface for DAO to DAO interactions, such as token swaps, joint venture provision, and joint venture formation. An introduction to Prime Deals can be found here.
This prime-deals-dapp repository contains in its master branch the web user interface for the Prime Deals website that is deployed to https://deals.prime.xyz.
Smart contracts have their own repository here.
User documentation can be found at https://deals.prime.xyz/documentation/.
Make sure you have
Install dependencies with the following command:
npm ci
Prime Deals relies on solidity contract addresses and ABIs that it obtains from the PrimeDao contracts-v2 repository. You must clone the contracts-v2 repository in a folder sibling to this one.
Then run the following script to pull the required contract ABIs from contracts:
npm run fetchContracts
You only need run this script once, or else again when any of the contracts change.
The package.json file contains lots of commands for building or serving up the application.
Before building, make sure to have the following in your OS environment variables or in an ".env" file:
RIVET_ID=...
ETHERSCAN_KEY=...
PINATA_API_KEY=...
PINATA_SECRET_API_KEY=...
PINATA_API_KEY_TEST=...
PINATA_SECRET_API_KEY_TEST=...
IPFS_GATEWAY=https://primedao.mypinata.cloud/${protocol}/${hash}
COINGECKO_API_KEY=...
FIREBASE_API_KEY= # apiKey
FIREBASE_AUTH_DOMAIN= # authDomain
FIREBASE_PROJECT_ID= # projectId
FIREBASE_APP_ID= # appId
FIREBASE_FUNCTIONS_URL=http://localhost:5001/${projectId}/us-central1
When building for production, the build will look for variables in ".env.production".
Following are the three most commonly used commands:
Best for development and debugging, the output goes to webpack-dev-server for use with your favorate debugger, like VSCode:
npm run serve-dev
For fast and safe development use firebase emulator suite instead of connecting to a real project. App is going to use emulated firebase services automatically, but if some/all of them are not available it will call the real service instead.
npm run firebase
The production build, output goes to the dist
folder:
npm run build
After successfully building, run the following to serve up the output so you can see it in the browser:
npm run start
To confirm that lint succeeds before git commits run
npm run lint
To have lint automatically fix all fixable errors run
npm run lint.fix
Run
npm run test
To run in watch mode
npm run test --watch
Further readings:
To run the Webpack Bundle Analyzer for production build.
npm run analyze
Various code dependencies include:
Assuming that a Firebase Project is already setup and you have access to API key and other secrets (otherwise see how to setup a new project)
Add Firebase environment variables to .env
file. You can find them in the Firebase console https://console.firebase.google.com Under “Project settings” → “Your apps” → select the app you want to use
FIREBASE_API_KEY= # apiKey
FIREBASE_AUTH_DOMAIN= # authDomain
FIREBASE_PROJECT_ID= # projectId
FIREBASE_APP_ID= # appId
Use Firebase emulators for development
Run npm run firebase
to start firebase emulators
functions[us-central1-functionName]: http function initialized
(http://localhost:5001/${projectId}/us-central1/${functionName}).
When running it for the first time copy the outputted functions URL without the function name (with the last part), for example:
http://localhost:5001/${projectId}/us-central1
Add it to .env
as FIREBASE_FUNCTIONS_URL
variable:
FIREBASE_FUNCTIONS_URL=http://localhost:5001/${projectId}/us-central1
IMPORTANT Add FIREBASE_ENVIRONMENT=local
variable to .env
file
FIREBASE_ENVIRONMENT
variable is used to conditionally connect the app to firebase emulators.
If it's set to local
than app will connect to the running emulators, otherwise it will connect to
the live Firebase project with ID specified by FIREBASE_PROJECT_ID
Using Firebase emulators for local development is highly recommended,
however you are free to connect to the live project whether for convenience or for testing purposes.
You can do so by removing FIREBASE_ENVIRONMENT
variable.
Run npm run start-dev
the app should be now using firebase emulators
You should always run npm run firebase
and npm run start-dev
for local development
Deployment from you local machine (optional)
npm install -g firebase-tools
firebase login
Create a new Firebase project
Upgrade it to “Blaze” plan (or any plan that allows us to use Firestore, Functions and Authentication, as of 03/2022 Blaze is the only one)
Go to Firebase console https://console.firebase.google.com
Add new app for the Web
Copy provided secrets to environment variables (to your local .env or to Vercel Environment Variables)
FIREBASE_API_KEY= # apiKey
FIREBASE_AUTH_DOMAIN= # authDomain
FIREBASE_PROJECT_ID= # projectId
FIREBASE_APP_ID= # appId
Setup Authentication
Setup Firestore Database
Update Google Cloud IAM settings
Set API key restrictions https://cloud.google.com/docs/authentication/api-keys#adding_application_restrictions
Enable IAM Service Account Credentials API
Add FIREBASE_TOKEN
used to deploy firebase from CI to Github actions secrets
firebase login:ci
(make sure you have firebase-tools installed globally)FIREBASE_TOKEN
with value of the token copied from the terminal. If it belongs to all firebase projects make it “repository secret” otherwise scope it per branchAdd FIREBASE_FUNCTIONS_URL
to the Vercel Environment Variables
Assign following URL to it:
https://${region}-${projectId}.cloudfunctions.net
If you are not sure if the URL is correct, after firebase deployment is triggered, whether locally by running firebase deploy
or by Github Actions, you can see the URL in the console output:
Function URL (${functionName}(us-central1)):
https://us-central1-${projectId}.cloudfunctions.net/${functionName}
Omit the functionName (last part) and use
https://us-central1-${projectId}.cloudfunctions.net
Firebase is not automatically deployed when you create a PR, because all Vercel previews (deployments run for pull requests) are connected to the same firebase projects, and we want to avoid overwriting Firebase Functions or Rules when multiple PRs have conflicting Firebase Functions or Rules. Therefore if you want Vercel preview for your PR, to have access to the firebase functions and rules from your PR, you should deploy them from your local machine. Vercel previews are connected to firebase project with id prime-deals-6ace4
and name “prime-deals-local”. It’s the default project and you can see it assigned to default
alias in .firebaserc
file.
Deploy Firebase from you local machine to the default project (used by Vercel previews for PRs)
In the project directory (make sure you have firebase cli and you are authenticated) Run:
firebase deploy
It's advised to use post-merge git hook which builds firebase functions for you, so your local firebase emulators will have the latest functions after a pull/merge.
post-merge
file into .git/hooks
chmod +x post-merge
The project framework is Aurelia.
It is written mostly in Typescript, HTML and SCSS, and is bundled using Webpack.
Join our Discord and ask how you can get involved with PrimeDAO.