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

ci: fix deploy staging/production subgraph #467

Open
wants to merge 6 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
10 changes: 10 additions & 0 deletions .github/workflows/deploy-prod-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ jobs:
with:
node-version: "16"
cache: "npm"
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v3
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ github.sha }}
restore-keys: |
turbo-${{ runner.os }}
- run: npm ci
- id: build
run: npm run build -- --cache-dir=".turbo"
- name: Authenticate The Graph CLI
run: npx graph auth --product hosted-service ${{ secrets.THE_GRAPH_ACCESS_TOKEN_PRODUCTION }}
- name: Deploy subgraph
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/deploy-staging-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ jobs:
with:
node-version: "16"
cache: "npm"
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v3
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ github.sha }}
restore-keys: |
turbo-${{ runner.os }}
- run: npm ci
- id: build
run: npm run build -- --cache-dir=".turbo"
- name: Authenticate The Graph CLI
run: npx graph auth --product hosted-service ${{ secrets.THE_GRAPH_ACCESS_TOKEN_STAGING }}
- name: Deploy subgraph
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/pin-to-pinata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: CI
on:
schedule:
- cron: "0 * * * *" # run every hour
workflow_dispatch:

jobs:
pin-to-pinata:
Expand Down Expand Up @@ -35,13 +36,6 @@ jobs:
INFURA_PROJECT_ID: ${{ secrets.INFURA_PROJECT_ID }}
INFURA_PROJECT_SECRET: ${{ secrets.INFURA_PROJECT_SECRET }}
run: |
echo "Pin for testing env..."
npm run pin-to-pinata -- \
-e testing \
-fd ${{ env.FROM_DATE }} \
-p ${{ env.PINATA_JWT }} \
-i ${{ env.INFURA_PROJECT_ID }}/${{ env.INFURA_PROJECT_SECRET }}

echo "Pin for staging env..."
npm run pin-to-pinata -- \
-e staging \
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"ipfs-upload": "ts-node -P tsconfig.base.json ./scripts/upload-to-ipfs.ts",
"explore-offer": "ts-node -P tsconfig.base.json ./scripts/explore-offer.ts",
"create-offer": "ts-node -P tsconfig.base.json ./scripts/create-offer.ts",
"create-offer-batch": "ts-node -P tsconfig.base.json ./scripts/create-offer-batch.ts",
"create-seller": "ts-node -P tsconfig.base.json ./scripts/create-seller.ts",
"update-seller": "ts-node -P tsconfig.base.json ./scripts/update-seller.ts",
"abi-signatures": "ts-node -P tsconfig.base.json ./scripts/abi-signatures.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bosonprotocol/core-sdk",
"version": "1.25.0-alpha.10",
"version": "1.25.0-mvfw23.1",
"description": "Facilitates interaction with the contracts and subgraphs of the Boson Protocol",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
31 changes: 13 additions & 18 deletions packages/core-sdk/src/native-meta-tx/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,19 @@ export async function getNonce(args: {
);
return String(nonce);
} catch (e) {
// Check if the error means the 'getNonce()' function does not exists in the contract
if (
(e.message as string)?.match(
/Transaction reverted without a reason string/
)
) {
// If so, call 'nonces()' instead (USDC case, for instance)
const result = await args.web3Lib.call({
to: args.contractAddress,
data: alternativeNonceIface.encodeFunctionData("nonces", [args.user])
});
const [nonce] = alternativeNonceIface.decodeFunctionResult(
"nonces",
result
);
return String(nonce);
}
throw e;
console.warn(
`Calling getNonce() for contract ${args.contractAddress} has failed. Try with 'nonces' instead`
);
// If so, call 'nonces()' instead (USDC case, for instance)
const result = await args.web3Lib.call({
to: args.contractAddress,
data: alternativeNonceIface.encodeFunctionData("nonces", [args.user])
});
const [nonce] = alternativeNonceIface.decodeFunctionResult(
"nonces",
result
);
return String(nonce);
}
}

Expand Down
82 changes: 82 additions & 0 deletions scripts/create-offer-batch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import fs from "fs";
import { EnvironmentType } from "@bosonprotocol/common/src/types/configs";
import { providers, Wallet } from "ethers";
import { program } from "commander";
import { getDefaultConfig } from "@bosonprotocol/common/src";
import { CoreSDK } from "../packages/core-sdk/src";
import { EthersAdapter } from "../packages/ethers-sdk/src";

program
.description("Create Offers (batch).")
.argument(
"<SELLER_PRIVATE_KEY>",
"Private key of the Seller account (assistant role)."
)
.argument("<OFFER_DATA>", "JSON file with the Offers specific parameters")
.option("-e, --env <ENV_NAME>", "Target environment", "testing")
.option(
"--template <TEMPLATE>",
"JSON file with the Offers common parameters"
)
.parse(process.argv);

async function main() {
const [sellerPrivateKey, offerDataJsonFile] = program.args;

const opts = program.opts();
const envName = opts.env || "testing";
const defaultConfig = getDefaultConfig(envName as EnvironmentType);
const chainId = defaultConfig.chainId;
const offersRawData = fs.readFileSync(offerDataJsonFile);
const offersDataJson = JSON.parse(offersRawData.toString());

if (!Array.isArray(offersDataJson)) {
throw `File '${offerDataJsonFile}' must define an array of offers`;
}

let offerTemplate = {};
if (opts.template) {
const templateRaw = fs.readFileSync(opts.template);
offerTemplate = JSON.parse(templateRaw.toString());
}

const offersFullDataJson = offersDataJson.map((specData) => {
const offerData = { ...offerTemplate, ...specData };
if (offerData["validFromDateInMS"] === undefined) {
offerData["validFromDateInMS"] = Date.now() + 5 * 60000;
}
if (offerData["voucherRedeemableFromDateInMS"] === undefined) {
offerData["voucherRedeemableFromDateInMS"] = Date.now() + 5 * 60000;
}
return offerData;
});

console.log(`Create Offer with Data ${JSON.stringify(offersFullDataJson)}`);
console.log("defaultConfig", defaultConfig);

const sellerWallet = new Wallet(sellerPrivateKey);
const coreSDK = CoreSDK.fromDefaultConfig({
web3Lib: new EthersAdapter(
new providers.JsonRpcProvider(defaultConfig.jsonRpcUrl),
sellerWallet
),
envName
});

console.log(`Creating offer on env ${envName} on chain ${chainId}...`);
const txResponse1 = await coreSDK.createOfferBatch(offersFullDataJson);
console.log(`Tx hash: ${txResponse1.hash}`);
const receipt = await txResponse1.wait();
const offerId = coreSDK.getCreatedOfferIdFromLogs(receipt.logs);
console.log(`Offer with id ${offerId} created.`);
}

main()
.then(() => {
console.log("success");
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
});