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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ jobs:
if: ${{ failure() }}
run: |
echo "========== Ocean Node Logs =========="
tac ${{ github.workspace }}/ocean-node/ocean-node.log || echo "Log file not found"
docker logs --tail 1000 ocean-node-1 2>&1 | tac || echo "Ocean Node container logs not available"
24 changes: 12 additions & 12 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
},
"dependencies": {
"@oasisprotocol/sapphire-paratime": "^1.3.2",
"@oceanprotocol/contracts": "^2.4.0",
"@oceanprotocol/ddo-js": "^0.1.3",
"@oceanprotocol/lib": "^5.0.0",
"@oceanprotocol/contracts": "^2.4.1",
"@oceanprotocol/ddo-js": "^0.1.4",
"@oceanprotocol/lib": "^5.0.3",
"commander": "^13.1.0",
"cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1",
Expand Down
71 changes: 71 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,5 +490,76 @@ export async function createCLI() {
await commands.getAuthorizationsEscrow(token || options.token, payee || options.payee);
});

program
.command('createAccessList')
.description('Create a new access list contract')
.argument('<name>', 'Name for the access list')
.argument('<symbol>', 'Symbol for the access list')
.argument('[transferable]', 'Whether tokens are transferable (true/false)', 'false')
.argument('[initialUsers]', 'Comma-separated list of initial user addresses', '')
.option('-n, --name <name>', 'Name for the access list')
.option('-s, --symbol <symbol>', 'Symbol for the access list')
.option('-t, --transferable [transferable]', 'Whether tokens are transferable (true/false)', 'false')
.option('-u, --users [initialUsers]', 'Comma-separated list of initial user addresses', '')
.action(async (name, symbol, transferable, initialUsers, options) => {
const { signer, chainId } = await initializeSigner();
const commands = new Commands(signer, chainId);
await commands.createAccessList([
options.name || name,
options.symbol || symbol,
options.transferable || transferable,
options.users || initialUsers
]);
});

program
.command('addToAccessList')
.description('Add user(s) to an access list')
.argument('<accessListAddress>', 'Address of the access list contract')
.argument('<users>', 'Comma-separated list of user addresses to add')
.option('-a, --address <accessListAddress>', 'Address of the access list contract')
.option('-u, --users <users>', 'Comma-separated list of user addresses to add')
.action(async (accessListAddress, users, options) => {
const { signer, chainId } = await initializeSigner();
const commands = new Commands(signer, chainId);
await commands.addToAccessList([
options.address || accessListAddress,
options.users || users
]);
});

program
.command('checkAccessList')
.description('Check if user(s) are on an access list')
.argument('<accessListAddress>', 'Address of the access list contract')
.argument('<users>', 'Comma-separated list of user addresses to check')
.option('-a, --address <accessListAddress>', 'Address of the access list contract')
.option('-u, --users <users>', 'Comma-separated list of user addresses to check')
.action(async (accessListAddress, users, options) => {
const { signer, chainId } = await initializeSigner();
const commands = new Commands(signer, chainId);
await commands.checkAccessList([
options.address || accessListAddress,
options.users || users
]);
});

program
.command('removeFromAccessList')
.description('Remove user(s) from an access list')
.argument('<accessListAddress>', 'Address of the access list contract')
.argument('<users>', 'Comma-separated list of user addresses to remove')
.option('-a, --address <accessListAddress>', 'Address of the access list contract')
.option('-u, --users <users>', 'Comma-separated list of user addresses to remove')
.action(async (accessListAddress, users, options) => {
const { signer, chainId } = await initializeSigner();
const commands = new Commands(signer, chainId);
await commands.removeFromAccessList([
options.address || accessListAddress,
options.users || users
]);
});


return program;
}
181 changes: 178 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
sendTx,
unitsToAmount,
EscrowContract,
getTokenDecimals
getTokenDecimals,
AccesslistFactory,
AccessListContract
} from "@oceanprotocol/lib";
import { Asset } from '@oceanprotocol/ddo-js';
import { Signer, ethers, getAddress } from "ethers";
Expand Down Expand Up @@ -729,6 +731,7 @@
)
console.log("Verifying payment...");
await new Promise(resolve => setTimeout(resolve, 3000))

const validationEscrow = await escrow.verifyFundsForEscrowPayment(
paymentToken,
computeEnv.consumerAddress,
Expand Down Expand Up @@ -791,10 +794,10 @@
null,
null,
// additionalDatasets, only c2d v1
output,
output
);

console.log("compute jobs: ", computeJobs);
console.log("computeJobs: ", computeJobs);

if (computeJobs && computeJobs[0]) {
const { jobId, payment } = computeJobs[0];
Expand Down Expand Up @@ -1454,4 +1457,176 @@

return authorizations;
}

public async createAccessList(args: string[]): Promise<void> {
try {
const name = args[0];
const symbol = args[1];
const transferable = args[2] === 'true';
const initialUsers = args[3] ? args[3].split(',').map(u => u.trim()) : [];

if (!name || !symbol) {
console.error(chalk.red('Name and symbol are required'));
return;
}

const config = await getConfigByChainId(Number(this.config.chainId));
if (!config.AccessListFactory) {
console.error(chalk.red('Access list factory not found. Check local address.json file'));
return;
}
const accessListFactory = new AccesslistFactory(
config.AccessListFactory,
this.signer,
Number(this.config.chainId)
);

const owner = await this.signer.getAddress();
const tokenURIs = initialUsers.map(() => 'https://oceanprotocol.com/nft/');

console.log(chalk.cyan('Creating new access list...'));
console.log(`Name: ${name}`);
console.log(`Symbol: ${symbol}`);
console.log(`Transferable: ${transferable}`);
console.log(`Owner: ${owner}`);
console.log(`Initial users: ${initialUsers.length > 0 ? initialUsers.join(', ') : 'none'}`);

const accessListAddress = await accessListFactory.deployAccessListContract(
name,
symbol,
tokenURIs,
transferable,
owner,
initialUsers
);

console.log(chalk.green(`\nAccess list created successfully!`));
console.log(chalk.green(`Contract address: ${accessListAddress}`));
} catch (error) {
console.error(chalk.red('Error creating access list:'), error);
}
}

public async addToAccessList(args: string[]): Promise<void> {
try {
const accessListAddress = args[0];
const users = args[1].split(',').map(u => u.trim());

if (!accessListAddress || users.length === 0) {
console.error(chalk.red('Access list address and at least one user are required'));
return;
}

const accessList = new AccessListContract(
accessListAddress,
this.signer,
Number(this.config.chainId)
);

console.log(chalk.cyan(`Adding ${users.length} user(s) to access list...`));

if (users.length === 1) {
const tx = await accessList.mint(users[0], 'https://oceanprotocol.com/nft/');
await tx.wait();
console.log(chalk.green(`Successfully added user ${users[0]} to access list`));
return;
}

const tokenURIs = users.map(() => 'https://oceanprotocol.com/nft/');
const tx = await accessList.batchMint(users, tokenURIs);
await tx.wait();
console.log(chalk.green(`Successfully added ${users.length} users to access list:`));
users.forEach(user => console.log(` - ${user}`));
} catch (error) {
console.error(chalk.red('Error adding users to access list:'), error);
}
}


public async checkAccessList(args: string[]): Promise<void> {
try {
const accessListAddress = args[0];
const users = args[1].split(',').map(u => u.trim());

if (!accessListAddress || users.length === 0) {
console.error(chalk.red('Access list address and at least one user are required'));
return;
}

const accessList = new AccessListContract(
accessListAddress,
this.signer,
Number(this.config.chainId)
);

console.log(chalk.cyan(`Checking access list for ${users.length} user(s)...\n`));

for (const user of users) {
const balance = await accessList.balance(user);
const hasAccess = Number(balance) > 0;

if (hasAccess) {
console.log(chalk.green(`✓ ${user}: Has access (balance: ${balance})`));
} else {
console.log(chalk.red(`✗ ${user}: No access`));
}
}
} catch (error) {
console.error(chalk.red('Error checking access list:'), error);
}
}


public async removeFromAccessList(args: string[]): Promise<void> {
try {
const accessListAddress = args[0];
const users = args[1].split(',').map(u => u.trim());

if (!accessListAddress || users.length === 0) {
console.error(chalk.red('Access list address and at least one user address are required'));
return;
}

const accessList = new AccessListContract(
accessListAddress,
this.signer,
Number(this.config.chainId)
);

console.log(chalk.cyan(`Removing ${users.length} user(s) from access list...`));
for (const user of users) {
const balance = await accessList.balance(user);

if (Number(balance) === 0) {
console.log(chalk.yellow(`⚠ User ${user} is not on the access list, skipping...`));
continue;
}

const balanceNum = Number(balance);
const contract = accessList.contract;

let removedCount = 0;
for (let index = 0; index < balanceNum; index++) {
try {
const tokenId = await contract.tokenOfOwnerByIndex(user, index);
const tx = await accessList.burn(Number(tokenId));
await tx.wait();

console.log(chalk.green(`✓ Successfully removed user ${user} (token ID: ${tokenId})`));
removedCount++;
} catch (e: any) {

Check warning on line 1617 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
console.log(chalk.yellow(`⚠ Could not remove token at index ${index} for user ${user}: ${e.message}`));
}
}

if (removedCount === 0) {
console.log(chalk.yellow(`⚠ Could not remove any tokens for user ${user}`));
} else if (removedCount < balanceNum) {
console.log(chalk.yellow(`⚠ Only removed ${removedCount} of ${balanceNum} tokens for user ${user}`));
}
}
} catch (error) {
console.error(chalk.red('Error removing users from access list:'), error);
}
}
}
3 changes: 1 addition & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import * as sapphire from '@oasisprotocol/sapphire-paratime';
import { Asset, DDO } from '@oceanprotocol/ddo-js';
import {
AccesslistFactory,
Aquarius,
AccesslistFactory, Aquarius,
Nft,
NftFactory,
ProviderInstance,
Expand All @@ -26,7 +25,7 @@
} from "@oceanprotocol/lib";
import { homedir } from "os";

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

Check warning on line 28 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 @@ -108,7 +107,7 @@
name: string,
symbol: string,
owner: Signer,
assetUrl: any,

Check warning on line 110 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 Down Expand Up @@ -155,7 +154,7 @@
oceanNodeUrl: string,
aquariusInstance: Aquarius,
encryptDDO: boolean = true
): Promise<any> {

Check warning on line 157 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const nft = new Nft(owner, Number((await owner.provider.getNetwork()).chainId));
let flags;
let metadata;
Expand Down Expand Up @@ -411,7 +410,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 413 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 413 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
Loading