Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
node-version: '20.19.0'

- name: Install dependencies
run: npm install
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
node-version: '20.19.0'

- name: Install dependencies
run: npm install
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18.19.0'
node-version: '20.19.0'

- name: Cache node_modules
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.0
v20.19
18,645 changes: 3,629 additions & 15,016 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
},
"dependencies": {
"@oasisprotocol/sapphire-paratime": "^1.3.2",
"@oceanprotocol/contracts": "^2.3.1",
"@oceanprotocol/ddo-js": "^0.1.1",
"@oceanprotocol/lib": "^4.2.0",
"@oceanprotocol/contracts": "^2.4.0",
"@oceanprotocol/ddo-js": "^0.1.3",
"@oceanprotocol/lib": "^5.0.0",
"commander": "^13.1.0",
"cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1",
"decimal.js": "^10.4.1",
"enquirer": "^2.4.1",
"esm": "^3.2.25",
"ethers": "^5.7.2",
"ethers": "^6.15.0",
"figlet": "^1.7.0",
"ts-node": "^10.9.1",
"tsx": "^4.19.3"
Expand Down
11 changes: 5 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from 'commander';
import { Commands } from './commands.js';
import { ethers } from 'ethers';
import { JsonRpcProvider, Signer, ethers } from 'ethers';
import chalk from 'chalk';
import { stdin as input, stdout as output } from 'node:process';
import { createInterface } from 'readline/promises';
Expand All @@ -9,18 +9,17 @@ import { toBoolean } from './helpers.js';

async function initializeSigner() {

const provider = new ethers.providers.JsonRpcProvider(process.env.RPC);
let signer;
const provider = new JsonRpcProvider(process.env.RPC);
let signer: Signer;

if (process.env.PRIVATE_KEY) {
signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
} else {
signer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC);
signer = await signer.connect(provider);
signer = ethers.Wallet.fromPhrase(process.env.MNEMONIC, provider);
}

const { chainId } = await signer.provider.getNetwork();
return { signer, chainId };
return { signer, chainId: Number(chainId) };
}

export async function createCLI() {
Expand Down
52 changes: 25 additions & 27 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
getTokenDecimals
} from "@oceanprotocol/lib";
import { Asset } from '@oceanprotocol/ddo-js';
import { Signer, ethers } from "ethers";
import { Signer, ethers, getAddress } from "ethers";
import { interactiveFlow } from "./interactiveFlow.js";
import { publishAsset } from "./publishAsset.js";
import chalk from 'chalk';
Expand Down Expand Up @@ -231,7 +231,7 @@ export class Commands {
dataDdo.id,
dataDdo.services[0].id,
0,
orderTx.transactionHash,
orderTx.hash,
this.oceanNodeUrl,
this.signer
);
Expand Down Expand Up @@ -400,7 +400,7 @@ export class Commands {
);
return;
}
const chainId = await this.signer.getChainId()
const { chainId } = await this.signer.provider.getNetwork()
if (!Object.keys(computeEnv.fees).includes(chainId.toString())) {
console.error(
"Error starting paid compute using dataset DID " +
Expand Down Expand Up @@ -453,7 +453,8 @@ export class Commands {
supportedMaxJobDuration,
providerURI,
this.signer, // V1 was this.signer.getAddress()
parsedResources
parsedResources,
Number(chainId)
);
if (
!providerInitializeComputeJob ||
Expand Down Expand Up @@ -596,7 +597,7 @@ export class Commands {
console.log("Ordering algorithm: ", args[2]);
const datatoken = new Datatoken(
this.signer,
(await this.signer.provider.getNetwork()).chainId,
(await this.signer.provider.getNetwork()).chainId.toString(),
this.config
);
algo.transferTxId = await handleComputeOrder(
Expand Down Expand Up @@ -667,7 +668,7 @@ export class Commands {
if (maxJobDuration > computeEnv.maxJobDuration) {
supportedMaxJobDuration = computeEnv.maxJobDuration;
}
const chainId = await this.signer.getChainId()
const { chainId } = await this.signer.provider.getNetwork()
const paymentToken = args[6]
if (!paymentToken) {
console.error(
Expand Down Expand Up @@ -723,10 +724,11 @@ export class Commands {
}

const escrow = new EscrowContract(
ethers.utils.getAddress(parsedProviderInitializeComputeJob.payment.escrowAddress),
getAddress(parsedProviderInitializeComputeJob.payment.escrowAddress),
this.signer
)
console.log("Verifying payment...");
await new Promise(resolve => setTimeout(resolve, 3000))
const validationEscrow = await escrow.verifyFundsForEscrowPayment(
paymentToken,
computeEnv.consumerAddress,
Expand Down Expand Up @@ -785,7 +787,9 @@ export class Commands {
supportedMaxJobDuration,
paymentToken,
JSON.parse(resources),
await this.signer.getChainId(),
Number((await this.signer.provider.getNetwork()).chainId),
null,
null,
// additionalDatasets, only c2d v1
output,
);
Expand Down Expand Up @@ -964,6 +968,8 @@ export class Commands {
assets, // assets[0] // only c2d v1,
algo,
null,
null,
null,
output
);

Expand Down Expand Up @@ -991,20 +997,12 @@ export class Commands {
);
return;
}
const hasAgreementId = args.length === 4;

const jobId = args[2];
let agreementId = null;
if (hasAgreementId) {
agreementId = args[3];
}
const jobStatus = await ProviderInstance.computeStop(
args[1],
await this.signer.getAddress(),
jobId,
this.oceanNodeUrl,
this.signer,
agreementId
);
console.log(jobStatus);
}
Expand Down Expand Up @@ -1275,7 +1273,7 @@ export class Commands {
minAbi,
this.signer
);
const estGasPublisher = await tokenContract.estimateGas.mint(
const estGasPublisher = await tokenContract.mint.estimateGas(
await this.signer.getAddress(),
await amountToUnits(null, null, "1000", 18)
);
Expand Down Expand Up @@ -1319,7 +1317,7 @@ export class Commands {
public async getEscrowBalance(token: string): Promise<number> {
const config = await getConfigByChainId(Number(this.config.chainId));
const escrow = new EscrowContract(
ethers.utils.getAddress(config.Escrow),
getAddress(config.Escrow),
this.signer,
Number(this.config.chainId)
);
Expand All @@ -1339,7 +1337,7 @@ export class Commands {
public async withdrawFromEscrow(token: string, amount: string): Promise<void> {
const config = await getConfigByChainId(Number(this.config.chainId));
const escrow = new EscrowContract(
ethers.utils.getAddress(config.Escrow),
getAddress(config.Escrow),
this.signer,
Number(this.config.chainId)
);
Expand Down Expand Up @@ -1368,7 +1366,7 @@ export class Commands {
);

const escrow = new EscrowContract(
ethers.utils.getAddress(escrowAddress),
getAddress(escrowAddress),
signer,
chainId
);
Expand Down Expand Up @@ -1402,14 +1400,14 @@ export class Commands {
const escrowAddress = config.Escrow;

const escrow = new EscrowContract(
ethers.utils.getAddress(escrowAddress),
getAddress(escrowAddress),
this.signer
);

console.log("Authorizing payee...");
const authorizeTx = await escrow.authorize(
ethers.utils.getAddress(token),
ethers.utils.getAddress(payee),
getAddress(token),
getAddress(payee),
maxLockedAmount,
maxLockSeconds,
maxLockCounts
Expand All @@ -1427,12 +1425,12 @@ export class Commands {
public async getAuthorizationsEscrow(token: string, payee: string) {
const config = await getConfigByChainId(Number(this.config.chainId));
const payer = await this.signer.getAddress();
const tokenAddress = ethers.utils.getAddress(token);
const payerAddress = ethers.utils.getAddress(payer);
const payeeAddress = ethers.utils.getAddress(payee);
const tokenAddress = getAddress(token);
const payerAddress = getAddress(payer);
const payeeAddress = getAddress(payee);
const decimals = await getTokenDecimals(this.signer, token);
const escrow = new EscrowContract(
ethers.utils.getAddress(config.Escrow),
getAddress(config.Escrow),
this.signer,
Number(this.config.chainId)
);
Expand Down
14 changes: 7 additions & 7 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers, Signer } from "ethers";
import { ethers, hexlify, Signer, toBeHex } from "ethers";
import fetch from "cross-fetch";
import { promises as fs, readFileSync } from "fs";
import * as path from "path";
Expand Down Expand Up @@ -26,7 +26,7 @@
} from "@oceanprotocol/lib";
import { homedir } from "os";

const ERC20Template = readFileSync('./node_modules/@oceanprotocol/contracts/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json', 'utf8') as any;
const ERC20Template = readFileSync('./node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json', 'utf8') as any;

Check warning on line 29 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

export async function downloadFile(
url: string,
Expand Down Expand Up @@ -83,7 +83,7 @@

// check for ID
if (isTemplateID) {
const id = await erc20Template.connect(owner).getId()
const id = await (erc20Template as ethers.Contract & { getId(): Promise<number> }).getId()
if (tokenTemplate.isActive && id.toString() === template.toString()) {
return i
}
Expand All @@ -108,7 +108,7 @@
name: string,
symbol: string,
owner: Signer,
assetUrl: any,

Check warning on line 111 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
ddo: DDO,
oceanNodeUrl: string,
config: Config,
Expand All @@ -131,7 +131,7 @@

if (config.sdk === 'oasis') {
// Create Access List Factory
const accessListFactoryObj = new AccesslistFactory(config.accessListFactory, signer, chainId);
const accessListFactoryObj = new AccesslistFactory(config.accessListFactory, signer, Number(chainId));

// Create Allow List
await accessListFactoryObj.deployAccessListContract(
Expand All @@ -155,8 +155,8 @@
oceanNodeUrl: string,
aquariusInstance: Aquarius,
encryptDDO: boolean = true
): Promise<any> {

Check warning on line 158 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const nft = new Nft(owner, (await owner.provider.getNetwork()).chainId);
const nft = new Nft(owner, Number((await owner.provider.getNetwork()).chainId));
let flags;
let metadata;
const validateResult = await aquariusInstance.validate(updatedDdo, owner, oceanNodeUrl);
Expand All @@ -172,7 +172,7 @@
else {
const stringDDO = JSON.stringify(updatedDdo);
const bytes = Buffer.from(stringDDO);
metadata = ethers.utils.hexlify(bytes);
metadata = hexlify(bytes);
flags = 0
}

Expand All @@ -182,7 +182,7 @@
0,
oceanNodeUrl,
"",
ethers.utils.hexlify(flags),
toBeHex(flags),
metadata,
validateResult.hash
);
Expand Down Expand Up @@ -411,7 +411,7 @@
const addressFile = await fs.readFile(addressFilePath, 'utf8');

const data = JSON.parse(addressFile);
const chainConfig = Object.values(data).find((network: any) => network.chainId === chainId) as any;

Check warning on line 414 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 414 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

if (!chainConfig) {
throw new Error(`Chain ${chainId} not found in address file`);
Expand Down
8 changes: 4 additions & 4 deletions test/escrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import { homedir } from 'os';
import { runCommand } from "./util.js";
import { getConfigByChainId } from "../src/helpers.js";
import { ethers } from "ethers";
import { JsonRpcProvider, ethers, formatEther, getAddress } from "ethers";
import { EscrowContract } from "@oceanprotocol/lib";

describe("Ocean CLI Escrow", function () {
this.timeout(60000); // 60 second timeout

let chainConfig: any;

Check warning on line 11 in test/escrow.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
let tokenAddress: string;
let payee: ethers.Wallet;
let payer: ethers.Wallet;
Expand All @@ -25,7 +25,7 @@
tokenAddress = chainConfig.Ocean;
escrowAddress = chainConfig.Escrow;

const provider = new ethers.providers.JsonRpcProvider(process.env.RPC);
const provider = new JsonRpcProvider(process.env.RPC);
payer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
payee = new ethers.Wallet('0xef4b441145c1d0f3b4bc6d61d29f5c6e502359481152f869247c7a4244d45209', provider);

Expand Down Expand Up @@ -82,7 +82,7 @@
);

const escrow = new EscrowContract(
ethers.utils.getAddress(escrowAddress),
getAddress(escrowAddress),
payer,
chainConfig.chainId
);
Expand All @@ -94,7 +94,7 @@
);

const maxLockedAmountFromEscrowBN = authorizations[0].maxLockedAmount;
const maxLockedAmountFromEscrow = ethers.utils.formatEther(maxLockedAmountFromEscrowBN);
const maxLockedAmountFromEscrow = formatEther(maxLockedAmountFromEscrowBN);

expect(Number(maxLockedAmountFromEscrow)).to.equal(Number(maxLockedAmount));

Expand Down
Loading