Skip to content

Commit 36cde61

Browse files
authored
Update libs and ethers (#127)
* update libs and ethers * update tests * latest package lock * use node 20.19 * wallet from mnemonic * latest lib * update lib * wait for tx to be mined * fix flag bytes * use latest release
1 parent 8235700 commit 36cde61

8 files changed

Lines changed: 3678 additions & 15068 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Node.js
1717
uses: actions/setup-node@v2
1818
with:
19-
node-version: '18'
19+
node-version: '20.19.0'
2020

2121
- name: Install dependencies
2222
run: npm install
@@ -34,7 +34,7 @@ jobs:
3434
- name: Set up Node.js
3535
uses: actions/setup-node@v2
3636
with:
37-
node-version: '18'
37+
node-version: '20.19.0'
3838

3939
- name: Install dependencies
4040
run: npm install
@@ -52,7 +52,7 @@ jobs:
5252
- name: Set up Node.js
5353
uses: actions/setup-node@v2
5454
with:
55-
node-version: '18.19.0'
55+
node-version: '20.19.0'
5656

5757
- name: Cache node_modules
5858
uses: actions/cache@v3

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18.19.0
1+
v20.19

package-lock.json

Lines changed: 3629 additions & 15016 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@
4545
},
4646
"dependencies": {
4747
"@oasisprotocol/sapphire-paratime": "^1.3.2",
48-
"@oceanprotocol/contracts": "^2.3.1",
49-
"@oceanprotocol/ddo-js": "^0.1.1",
50-
"@oceanprotocol/lib": "^4.2.0",
48+
"@oceanprotocol/contracts": "^2.4.0",
49+
"@oceanprotocol/ddo-js": "^0.1.3",
50+
"@oceanprotocol/lib": "^5.0.0",
5151
"commander": "^13.1.0",
5252
"cross-fetch": "^3.1.5",
5353
"crypto-js": "^4.1.1",
5454
"decimal.js": "^10.4.1",
5555
"enquirer": "^2.4.1",
5656
"esm": "^3.2.25",
57-
"ethers": "^5.7.2",
57+
"ethers": "^6.15.0",
5858
"figlet": "^1.7.0",
5959
"ts-node": "^10.9.1",
6060
"tsx": "^4.19.3"

src/cli.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Command } from 'commander';
22
import { Commands } from './commands.js';
3-
import { ethers } from 'ethers';
3+
import { JsonRpcProvider, Signer, ethers } from 'ethers';
44
import chalk from 'chalk';
55
import { stdin as input, stdout as output } from 'node:process';
66
import { createInterface } from 'readline/promises';
@@ -9,18 +9,17 @@ import { toBoolean } from './helpers.js';
99

1010
async function initializeSigner() {
1111

12-
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC);
13-
let signer;
12+
const provider = new JsonRpcProvider(process.env.RPC);
13+
let signer: Signer;
1414

1515
if (process.env.PRIVATE_KEY) {
1616
signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
1717
} else {
18-
signer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC);
19-
signer = await signer.connect(provider);
18+
signer = ethers.Wallet.fromPhrase(process.env.MNEMONIC, provider);
2019
}
2120

2221
const { chainId } = await signer.provider.getNetwork();
23-
return { signer, chainId };
22+
return { signer, chainId: Number(chainId) };
2423
}
2524

2625
export async function createCLI() {

src/commands.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
getTokenDecimals
3131
} from "@oceanprotocol/lib";
3232
import { Asset } from '@oceanprotocol/ddo-js';
33-
import { Signer, ethers } from "ethers";
33+
import { Signer, ethers, getAddress } from "ethers";
3434
import { interactiveFlow } from "./interactiveFlow.js";
3535
import { publishAsset } from "./publishAsset.js";
3636
import chalk from 'chalk';
@@ -231,7 +231,7 @@ export class Commands {
231231
dataDdo.id,
232232
dataDdo.services[0].id,
233233
0,
234-
orderTx.transactionHash,
234+
orderTx.hash,
235235
this.oceanNodeUrl,
236236
this.signer
237237
);
@@ -400,7 +400,7 @@ export class Commands {
400400
);
401401
return;
402402
}
403-
const chainId = await this.signer.getChainId()
403+
const { chainId } = await this.signer.provider.getNetwork()
404404
if (!Object.keys(computeEnv.fees).includes(chainId.toString())) {
405405
console.error(
406406
"Error starting paid compute using dataset DID " +
@@ -453,7 +453,8 @@ export class Commands {
453453
supportedMaxJobDuration,
454454
providerURI,
455455
this.signer, // V1 was this.signer.getAddress()
456-
parsedResources
456+
parsedResources,
457+
Number(chainId)
457458
);
458459
if (
459460
!providerInitializeComputeJob ||
@@ -596,7 +597,7 @@ export class Commands {
596597
console.log("Ordering algorithm: ", args[2]);
597598
const datatoken = new Datatoken(
598599
this.signer,
599-
(await this.signer.provider.getNetwork()).chainId,
600+
(await this.signer.provider.getNetwork()).chainId.toString(),
600601
this.config
601602
);
602603
algo.transferTxId = await handleComputeOrder(
@@ -667,7 +668,7 @@ export class Commands {
667668
if (maxJobDuration > computeEnv.maxJobDuration) {
668669
supportedMaxJobDuration = computeEnv.maxJobDuration;
669670
}
670-
const chainId = await this.signer.getChainId()
671+
const { chainId } = await this.signer.provider.getNetwork()
671672
const paymentToken = args[6]
672673
if (!paymentToken) {
673674
console.error(
@@ -723,10 +724,11 @@ export class Commands {
723724
}
724725

725726
const escrow = new EscrowContract(
726-
ethers.utils.getAddress(parsedProviderInitializeComputeJob.payment.escrowAddress),
727+
getAddress(parsedProviderInitializeComputeJob.payment.escrowAddress),
727728
this.signer
728729
)
729730
console.log("Verifying payment...");
731+
await new Promise(resolve => setTimeout(resolve, 3000))
730732
const validationEscrow = await escrow.verifyFundsForEscrowPayment(
731733
paymentToken,
732734
computeEnv.consumerAddress,
@@ -785,7 +787,9 @@ export class Commands {
785787
supportedMaxJobDuration,
786788
paymentToken,
787789
JSON.parse(resources),
788-
await this.signer.getChainId(),
790+
Number((await this.signer.provider.getNetwork()).chainId),
791+
null,
792+
null,
789793
// additionalDatasets, only c2d v1
790794
output,
791795
);
@@ -964,6 +968,8 @@ export class Commands {
964968
assets, // assets[0] // only c2d v1,
965969
algo,
966970
null,
971+
null,
972+
null,
967973
output
968974
);
969975

@@ -991,20 +997,12 @@ export class Commands {
991997
);
992998
return;
993999
}
994-
const hasAgreementId = args.length === 4;
9951000

9961001
const jobId = args[2];
997-
let agreementId = null;
998-
if (hasAgreementId) {
999-
agreementId = args[3];
1000-
}
10011002
const jobStatus = await ProviderInstance.computeStop(
1002-
args[1],
1003-
await this.signer.getAddress(),
10041003
jobId,
10051004
this.oceanNodeUrl,
10061005
this.signer,
1007-
agreementId
10081006
);
10091007
console.log(jobStatus);
10101008
}
@@ -1275,7 +1273,7 @@ export class Commands {
12751273
minAbi,
12761274
this.signer
12771275
);
1278-
const estGasPublisher = await tokenContract.estimateGas.mint(
1276+
const estGasPublisher = await tokenContract.mint.estimateGas(
12791277
await this.signer.getAddress(),
12801278
await amountToUnits(null, null, "1000", 18)
12811279
);
@@ -1319,7 +1317,7 @@ export class Commands {
13191317
public async getEscrowBalance(token: string): Promise<number> {
13201318
const config = await getConfigByChainId(Number(this.config.chainId));
13211319
const escrow = new EscrowContract(
1322-
ethers.utils.getAddress(config.Escrow),
1320+
getAddress(config.Escrow),
13231321
this.signer,
13241322
Number(this.config.chainId)
13251323
);
@@ -1339,7 +1337,7 @@ export class Commands {
13391337
public async withdrawFromEscrow(token: string, amount: string): Promise<void> {
13401338
const config = await getConfigByChainId(Number(this.config.chainId));
13411339
const escrow = new EscrowContract(
1342-
ethers.utils.getAddress(config.Escrow),
1340+
getAddress(config.Escrow),
13431341
this.signer,
13441342
Number(this.config.chainId)
13451343
);
@@ -1368,7 +1366,7 @@ export class Commands {
13681366
);
13691367

13701368
const escrow = new EscrowContract(
1371-
ethers.utils.getAddress(escrowAddress),
1369+
getAddress(escrowAddress),
13721370
signer,
13731371
chainId
13741372
);
@@ -1402,14 +1400,14 @@ export class Commands {
14021400
const escrowAddress = config.Escrow;
14031401

14041402
const escrow = new EscrowContract(
1405-
ethers.utils.getAddress(escrowAddress),
1403+
getAddress(escrowAddress),
14061404
this.signer
14071405
);
14081406

14091407
console.log("Authorizing payee...");
14101408
const authorizeTx = await escrow.authorize(
1411-
ethers.utils.getAddress(token),
1412-
ethers.utils.getAddress(payee),
1409+
getAddress(token),
1410+
getAddress(payee),
14131411
maxLockedAmount,
14141412
maxLockSeconds,
14151413
maxLockCounts
@@ -1427,12 +1425,12 @@ export class Commands {
14271425
public async getAuthorizationsEscrow(token: string, payee: string) {
14281426
const config = await getConfigByChainId(Number(this.config.chainId));
14291427
const payer = await this.signer.getAddress();
1430-
const tokenAddress = ethers.utils.getAddress(token);
1431-
const payerAddress = ethers.utils.getAddress(payer);
1432-
const payeeAddress = ethers.utils.getAddress(payee);
1428+
const tokenAddress = getAddress(token);
1429+
const payerAddress = getAddress(payer);
1430+
const payeeAddress = getAddress(payee);
14331431
const decimals = await getTokenDecimals(this.signer, token);
14341432
const escrow = new EscrowContract(
1435-
ethers.utils.getAddress(config.Escrow),
1433+
getAddress(config.Escrow),
14361434
this.signer,
14371435
Number(this.config.chainId)
14381436
);

src/helpers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ethers, Signer } from "ethers";
1+
import { ethers, hexlify, Signer, toBeHex } from "ethers";
22
import fetch from "cross-fetch";
33
import { promises as fs, readFileSync } from "fs";
44
import * as path from "path";
@@ -26,7 +26,7 @@ import {
2626
} from "@oceanprotocol/lib";
2727
import { homedir } from "os";
2828

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

3131
export async function downloadFile(
3232
url: string,
@@ -83,7 +83,7 @@ export async function calculateActiveTemplateIndex(
8383

8484
// check for ID
8585
if (isTemplateID) {
86-
const id = await erc20Template.connect(owner).getId()
86+
const id = await (erc20Template as ethers.Contract & { getId(): Promise<number> }).getId()
8787
if (tokenTemplate.isActive && id.toString() === template.toString()) {
8888
return i
8989
}
@@ -131,7 +131,7 @@ export async function createAssetUtil(
131131

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

136136
// Create Allow List
137137
await accessListFactoryObj.deployAccessListContract(
@@ -156,7 +156,7 @@ export async function updateAssetMetadata(
156156
aquariusInstance: Aquarius,
157157
encryptDDO: boolean = true
158158
): Promise<any> {
159-
const nft = new Nft(owner, (await owner.provider.getNetwork()).chainId);
159+
const nft = new Nft(owner, Number((await owner.provider.getNetwork()).chainId));
160160
let flags;
161161
let metadata;
162162
const validateResult = await aquariusInstance.validate(updatedDdo, owner, oceanNodeUrl);
@@ -172,7 +172,7 @@ export async function updateAssetMetadata(
172172
else {
173173
const stringDDO = JSON.stringify(updatedDdo);
174174
const bytes = Buffer.from(stringDDO);
175-
metadata = ethers.utils.hexlify(bytes);
175+
metadata = hexlify(bytes);
176176
flags = 0
177177
}
178178

@@ -182,7 +182,7 @@ export async function updateAssetMetadata(
182182
0,
183183
oceanNodeUrl,
184184
"",
185-
ethers.utils.hexlify(flags),
185+
toBeHex(flags),
186186
metadata,
187187
validateResult.hash
188188
);

test/escrow.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from "chai";
22
import { homedir } from 'os';
33
import { runCommand } from "./util.js";
44
import { getConfigByChainId } from "../src/helpers.js";
5-
import { ethers } from "ethers";
5+
import { JsonRpcProvider, ethers, formatEther, getAddress } from "ethers";
66
import { EscrowContract } from "@oceanprotocol/lib";
77

88
describe("Ocean CLI Escrow", function () {
@@ -25,7 +25,7 @@ describe("Ocean CLI Escrow", function () {
2525
tokenAddress = chainConfig.Ocean;
2626
escrowAddress = chainConfig.Escrow;
2727

28-
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC);
28+
const provider = new JsonRpcProvider(process.env.RPC);
2929
payer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
3030
payee = new ethers.Wallet('0xef4b441145c1d0f3b4bc6d61d29f5c6e502359481152f869247c7a4244d45209', provider);
3131

@@ -82,7 +82,7 @@ describe("Ocean CLI Escrow", function () {
8282
);
8383

8484
const escrow = new EscrowContract(
85-
ethers.utils.getAddress(escrowAddress),
85+
getAddress(escrowAddress),
8686
payer,
8787
chainConfig.chainId
8888
);
@@ -94,7 +94,7 @@ describe("Ocean CLI Escrow", function () {
9494
);
9595

9696
const maxLockedAmountFromEscrowBN = authorizations[0].maxLockedAmount;
97-
const maxLockedAmountFromEscrow = ethers.utils.formatEther(maxLockedAmountFromEscrowBN);
97+
const maxLockedAmountFromEscrow = formatEther(maxLockedAmountFromEscrowBN);
9898

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

0 commit comments

Comments
 (0)