Skip to content

Commit

Permalink
feat: support Arbitrum [SF-970]
Browse files Browse the repository at this point in the history
  • Loading branch information
biga816 committed Dec 26, 2023
1 parent 13a83e5 commit b832342
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 37 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/deploy-graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ on:
type: choice
options:
- development
- development-arb
- staging
- staging-arb
- sepolia
- mainnet
- arbitrum-one
push:
branches:
- main
Expand Down Expand Up @@ -92,7 +95,7 @@ jobs:
npm run auth ${{secrets.GRAPH_ACCESS_TOKEN}}
npm run update-subgraphrc ${{needs.identify-env.outputs.environment}}
version=$(cat deployment.json | jq -r .${{needs.identify-env.outputs.environment}}.version | tr -d '"')
npm run generate:${{needs.identify-env.outputs.environment}}
npm run generate ${{needs.identify-env.outputs.environment}}
npm run deploy:${{needs.identify-env.outputs.environment}} ${version}
- name: Commit and push
shell: bash
Expand Down
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ This subgraph tracks of the current state of Secured Finance Protocol smart cont
## Quick start

1. Use established node version by running `nvm use`
2. Set your personal access token issued on your Github account `export NPM_AUTH_TOKEN=<your access token>`
3. Install repository dependencies by running `npm install`
4. Execute `npm run test` to run the tests.
2. Install repository dependencies by running `npm install`
3. Execute `npm run test` to run the tests.


## Deployment
Follow the steps bellow to deploy the subgraph

1. Run `npm run generate:<ENV>` to create a migration file for the subgraph
1. Run `npm run generate <ENV>` to create a migration file for the subgraph
2. Run `npm run deploy:<ENV>` to deploy the subgraph

## License
Expand Down
10 changes: 10 additions & 0 deletions deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
"isMinorUpdate": false,
"version": "0.0.43"
},
"development-arb": {
"version": "0.0.1",
"isMajorUpdate": false,
"isMinorUpdate": false
},
"staging": {
"isMajorUpdate": false,
"isMinorUpdate": false,
"version": "0.0.12"
},
"staging-arb": {
"version": "0.0.1",
"isMajorUpdate": false,
"isMinorUpdate": false
},
"sepolia": {
"isMajorUpdate": false,
"isMinorUpdate": false,
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"version": "0.2.0-beta.34",
"private": "true",
"scripts": {
"generate:development": "ts-node ./scripts/generate.ts development sepolia",
"generate:staging": "ts-node ./scripts/generate.ts staging sepolia",
"generate:sepolia": "ts-node ./scripts/generate.ts production sepolia",
"generate:mainnet": "ts-node ./scripts/generate.ts production mainnet",
"generate": "ts-node ./scripts/generate.ts",
"codegen": "graph codegen ./subgraph.yaml",
"precodegen": "ts-node ./scripts/copy-abis.ts",
"build": "graph build ./subgraph.yaml",
Expand All @@ -15,9 +12,12 @@
"coverage": "graph test -- -c",
"auth": "graph auth --studio",
"deploy:development": "cat ./subgraph.development.yaml && graph deploy sf-protocol-dev-sepolia ./subgraph.development.yaml --studio --output-dir ./build/development --version-label",
"deploy:development-arb": "cat ./subgraph.development-arb.yaml && graph deploy sf-protocol-dev-arb-sepolia ./subgraph.development-arb.yaml --studio --output-dir ./build/development-arb --version-label",
"deploy:staging": "cat ./subgraph.staging.yaml && graph deploy sf-protocol-stg-sepolia ./subgraph.staging.yaml --studio --output-dir ./build/staging --version-label",
"deploy:staging-arb": "cat ./subgraph.staging-arb.yaml && graph deploy sf-protocol-stg-arb-sepolia ./subgraph.staging-arb.yaml --studio --output-dir ./build/staging-arb --version-label",
"deploy:sepolia": "cat ./subgraph.sepolia.yaml && graph deploy sf-protocol-prd-sepolia ./subgraph.sepolia.yaml --studio --output-dir ./build/sepolia --version-label",
"deploy:mainnet": "cat ./subgraph.mainnet.yaml && graph deploy sf-protocol-prd-mainnet ./subgraph.mainnet.yaml --studio --output-dir ./build/mainnet --version-label",
"deploy:arbitrum-one": "cat ./subgraph.arbitrum-one.yaml && graph deploy sf-protocol-prd-arbitrum-one ./subgraph.arbitrum-one.yaml --studio --output-dir ./build/arbitrum-one --version-label",
"prepublish": "npm run codegen",
"update-subgraphrc": "ts-node ./scripts/update-subgraphrc.ts",
"format": "prettier --config ./.prettierrc.json --check '**/*.{js,jsx,ts,tsx,json}' '*.{js,jsx,ts,tsx,json}'",
Expand All @@ -26,7 +26,7 @@
"devDependencies": {
"@graphprotocol/graph-cli": "0.62.0",
"@graphprotocol/graph-ts": "0.31.0",
"@secured-finance/contracts": "1.0.0",
"@secured-finance/contracts": "1.0.1-beta.1",
"@types/js-yaml": "4.0.5",
"@types/node": "16.18.67",
"js-yaml": "4.1.0",
Expand Down
50 changes: 29 additions & 21 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
import { readFileSync, writeFileSync } from 'fs';
import { dump, load } from 'js-yaml';

const arrowedEnvironments = ['development', 'staging', 'production'] as const;
const arrowedNetworks = ['sepolia', 'mainnet'] as const;
type Environment = (typeof arrowedEnvironments)[number];
const arrowedNetworks = [
'development',
'development-arb',
'staging',
'staging-arb',
'sepolia',
'mainnet',
'arbitrum-one',
] as const;
type Network = (typeof arrowedNetworks)[number];

const devNetworkMap: Partial<Record<Network, string>> = {
development: 'sepolia',
'development-arb': 'arbitrum-sepolia',
staging: 'sepolia',
'staging-arb': 'arbitrum-sepolia',
};

class Main {
private environment: Environment;
private network: Network;

constructor(environment: string, network: string) {
if (!arrowedEnvironments.includes(environment as Environment)) {
console.error('Invalid environment:', environment);
process.exit(1);
}

constructor(network: string) {
if (!arrowedNetworks.includes(network as Network)) {
console.error('Invalid network:', network);
process.exit(1);
}

this.environment = environment as Environment;
this.network = network as Network;
}

Expand All @@ -30,34 +36,36 @@ class Main {
const yamlText = readFileSync(`${rootDir}/subgraph.yaml`, 'utf8');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const data = load(yamlText) as any;
const networkName =
this.environment === 'development' || this.environment === 'staging'
? this.environment
: this.network;
const network = devNetworkMap[this.network] || this.network;

if (!network) {
console.error('Network not found:', this.network);
process.exit(1);
}

for (const dataSource of data.dataSources) {
const deployment = await import(
`@secured-finance/contracts/deployments/${networkName}/${dataSource.source.abi}.json`
`@secured-finance/contracts/deployments/${this.network}/${dataSource.source.abi}.json`
);

const proxyAddress = deployment.address;
dataSource.source.address = proxyAddress;
dataSource.network = this.network;
dataSource.network = network;
}

for (const template of data.templates) {
template.network = this.network;
template.network = network;
}

const newYamlText = dump(data);

writeFileSync(
`${rootDir}/subgraph.${networkName}.yaml`,
`${rootDir}/subgraph.${this.network}.yaml`,
newYamlText,
'utf8'
);
}
}

const [, , environment, network] = process.argv;
new Main(environment, network).run();
const [, , network] = process.argv;
new Main(network).run();
12 changes: 12 additions & 0 deletions scripts/update-subgraphrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import { readFileSync, writeFileSync } from 'fs';

const arrowedNetworks = [
'development',
'development-arb',
'staging',
'staging-arb',
'sepolia',
'mainnet',
] as const;
type Network = (typeof arrowedNetworks)[number];

const EMPTY_DEPLOYMENT = {
version: '0.0.0',
isMajorUpdate: false,
isMinorUpdate: false,
};

class Main {
private network: Network;

Expand All @@ -26,6 +34,10 @@ class Main {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const data = JSON.parse(jsonText) as any;

if (!data[this.network]) {
data[this.network] = EMPTY_DEPLOYMENT;
}

const { version, isMajorUpdate, isMinorUpdate } = data[this.network];
const versions: string[] = version.split('.');

Expand Down

0 comments on commit b832342

Please sign in to comment.