Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subgraph multichain generation #24

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"homepage": "https://pangolin.exchange",
"dependencies": {
"@gnosis.pm/safe-core-sdk": "^1.3.0",
"@graphprotocol/graph-cli": "0.16.0",
"@graphprotocol/graph-ts": "0.16.0",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@pangolindex/sdk": "^1.4.0",
"chance": "^1.1.8",
Expand Down
88 changes: 88 additions & 0 deletions scripts/deploy-graph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const { ethers, network } = require("hardhat");
const fs = require("fs");
const { THEGRAPHS } = require("@pangolindex/sdk");

function writeSrcFile(fileName, data) {
fs.writeFileSync(
"subgraph/" + network.name + "/src/mappings/" + fileName,
data
);
}

function fetchChain() {
for (let i = 0; i < THEGRAPHS.length; i++) {
if (network.name === THEGRAPHS[i].id) {
return THEGRAPHS[i];
}
}
}

function replaceByArray(data, array) {
let string = '';
for (let i = 0; i < array.length; i++) {
string += '\'' + array[i] + '\',';
if (i != array.length - 1) {
string += '\n\t';
}
}
console.log(string);
data = data.replace(/"0x0000000000000000000000000000000000000000",/g, string);
return data
}

async function main() {
let dir = __dirname + "/../subgraph/" + network.name;
let chain = fetchChain();
let dataSubgraph = fs.readFileSync("subgraph/sample/subgraph.yaml", 'utf8');
dataSubgraph = dataSubgraph.replace(/DEPLOY_NETWORK/g, chain.name);
dataSubgraph = dataSubgraph.replace(/FACTORY_ADDRESS/g, chain.contracts.factory);
dataSubgraph = dataSubgraph.replace(/START_BLOCK/g, '1');
let dataSchema = fs.readFileSync("subgraph/sample/schema.graphql", 'utf8');
let dataCore = fs.readFileSync("subgraph/sample/src/mappings/core.ts", 'utf8');
dataCore = replaceByArray(dataCore, chain.theGraph.tokens_whitelist);
let dataDayUpdates = fs.readFileSync("subgraph/sample/src/mappings/dayUpdates.ts", 'utf8');
let dataFactory = fs.readFileSync("subgraph/sample/src/mappings/factory.ts", 'utf8');
let dataHelpers = fs.readFileSync("subgraph/sample/src/mappings/helpers.ts", 'utf8');
dataHelpers = dataHelpers.replace(/0x000000000000000000000000000000000factory/g, chain.contracts.factory);
dataHelpers = dataHelpers.replace(/0x0000000000000000000000000000000000router/g, chain.contracts.router);
let dataPricing = fs.readFileSync("subgraph/sample/src/mappings/pricing.ts", 'utf8');
dataPricing = dataPricing.replace(/0x000000000000000000000000000000000000wavax/g, chain.contracts.wrapped_native_token);
dataPricing = dataPricing.replace(/PRICE/g, chain.theGraph.native_price_pre_stable);
dataPricing = dataPricing.replace(/0x000000000000000000000000000000000AEBUSDT/g, chain.theGraph.stables_pair_AEB[0]);
dataPricing = dataPricing.replace(/0x0000000000000000000000000000000000AEBDAI/g, chain.theGraph.stables_pair_AEB[1]);
dataPricing = dataPricing.replace(/0x0000000000000000000000000000000000ABUSDT/g, chain.theGraph.stables_pair_AB[0]);
dataPricing = dataPricing.replace(/0x00000000000000000000000000000000000ABDAI/g, chain.theGraph.stables_pair_AB[1]);
dataPricing = dataPricing.replace(/2147483647/g, chain.theGraph.stables_pair_AEB_block[0]);
dataPricing = dataPricing.replace(/2147483646/g, chain.theGraph.stables_pair_AEB_block[1]);
dataPricing = dataPricing.replace(/2147483645/g, chain.theGraph.stables_pair_AB_block);
dataPricing = replaceByArray(dataPricing, chain.theGraph.mining_pools);
let dataPackage = fs.readFileSync("subgraph/sample/package.json", 'utf8');

if(!fs.existsSync(dir)) {
fs.mkdirSync(dir + "/src/mappings", {recursive: true});
}
fs.writeFileSync(
"subgraph/" + network.name + "/subgraph.yaml",
dataSubgraph
);
fs.writeFileSync(
"subgraph/" + network.name + "/schema.graphql",
dataSchema
);
fs.writeFileSync(
"subgraph/" + network.name + "/package.json",
dataPackage
);
writeSrcFile("core.ts", dataCore);
writeSrcFile("dayUpdates.ts", dataDayUpdates);
writeSrcFile("factory.ts", dataFactory);
writeSrcFile("helpers.ts", dataHelpers);
writeSrcFile("pricing.ts", dataPricing);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
78 changes: 53 additions & 25 deletions scripts/deploy-mainnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const {
PNG_NAME,
TOTAL_SUPPLY,
MULTISIG,
MULTISIG_ADDRESS,
FOUNDATION_ADDRESS,
USE_GNOSIS_SAFE,
PROPOSAL_THRESHOLD,
WRAPPED_NATIVE_TOKEN,
Expand Down Expand Up @@ -41,6 +43,16 @@ async function main() {
} else {
console.log("⚠️ Using legacy multisig.");
}
if (MULTISIG_ADDRESS) {
console.log("✅ Using Multisig already deploy.");
} else {
console.log("⚠️ No Multisig is defined.");
}
if (FOUNDATION_ADDRESS) {
console.log("✅ Using FoundationMultisig already deploy.");
} else {
console.log("⚠️ No Foundation Multisig is defined.");
}
if (WRAPPED_NATIVE_TOKEN === undefined || WRAPPED_NATIVE_TOKEN == "") {
console.log("⚠️ No wrapped gas token is defined.");
} else {
Expand Down Expand Up @@ -81,6 +93,14 @@ async function main() {
return contract;
}

async function attach(factory, address) {
var ContractFactory = await ethers.getContractFactory(factory);
var contract = await ContractFactory.attach(address);
contracts.push({ address: contract.address});
console.log(contract.address, ":", factory);
return contract;
}

console.log("\n============\n DEPLOYMENT \n============");

// Deploy WAVAX if not defined
Expand All @@ -104,36 +124,44 @@ async function main() {
]);

// Deploy this chain’s multisig
if (USE_GNOSIS_SAFE) {
const ethAdapter = new EthersAdapter({
ethers,
signer: deployer,
});
var Multisig = await SafeFactory.create({ ethAdapter });
var multisig = await Multisig.deploySafe(MULTISIG);
await confirmTransactionCount();
multisig.address = multisig.getAddress();
console.log(multisig.address, ": Gnosis");
if (MULTISIG_ADDRESS === undefined) {
if (USE_GNOSIS_SAFE) {
const ethAdapter = new EthersAdapter({
ethers,
signer: deployer,
});
var Multisig = await SafeFactory.create({ ethAdapter });
var multisig = await Multisig.deploySafe(MULTISIG);
await confirmTransactionCount();
multisig.address = multisig.getAddress();
console.log(multisig.address, ": Gnosis");
} else {
var multisig = await deploy("MultiSigWalletWithDailyLimit", [
MULTISIG.owners,
MULTISIG.threshold,
0,
]);
}
} else {
var multisig = await deploy("MultiSigWalletWithDailyLimit", [
MULTISIG.owners,
MULTISIG.threshold,
0,
]);
var multisig = await attach("MultiSigWalletWithDailyLimit", MULTISIG_ADDRESS);
}

// Deploy foundation multisig
if (USE_GNOSIS_SAFE) {
var foundation = await Multisig.deploySafe(FOUNDATION_MULTISIG);
await confirmTransactionCount();
foundation.address = foundation.getAddress();
console.log(foundation.address, ": Gnosis");
if (FOUNDATION_ADDRESS === undefined) {
if (USE_GNOSIS_SAFE) {
var foundation = await Multisig.deploySafe(FOUNDATION_MULTISIG);
await confirmTransactionCount();
foundation.address = foundation.getAddress();
console.log(foundation.address, ": Gnosis");
} else {
var foundation = await deploy("MultiSigWalletWithDailyLimit", [
FOUNDATION_MULTISIG.owners,
FOUNDATION_MULTISIG.threshold,
0,
]);
}
} else {
var foundation = await deploy("MultiSigWalletWithDailyLimit", [
FOUNDATION_MULTISIG.owners,
FOUNDATION_MULTISIG.threshold,
0,
]);
var foundation = await attach("MultiSigWalletWithDailyLimit", FOUNDATION_ADDRESS);
}

const timelock = await deploy("Timelock", [
Expand Down
25 changes: 25 additions & 0 deletions subgraph/sample/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@pangolindex/subgraph",
"version": "1.2.1",
"repository": "https://github.com/pangolindex/subgraph",
"license": "GPL-3.0-or-later",
"scripts": {
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"create-local": "graph create dasconnor/pangolin-dex --node http://127.0.0.1:8020",
"deploy-local": "graph deploy dasconnor/pangolin-dex --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy dasconnor/pangolin-dex --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy-staging": "graph deploy $THE_GRAPH_GITHUB_USER/$THE_GRAPH_SUBGRAPH_NAME /pangolin-dex --ipfs https://api.staging.thegraph.com/ipfs/ --node https://api.staging.thegraph.com/deploy/",
"watch-local": "graph deploy graphprotocol/pangolin-dex --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.16.0",
"@graphprotocol/graph-ts": "^0.16.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^6.2.2",
"eslint-config-prettier": "^6.1.0",
"prettier": "^1.18.2",
"typescript": "^3.5.2"
}
}
Loading