Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 0 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ jobs:
- name: Run Ganache with Barge
working-directory: ${{ github.workspace }}/barge
run: |
export CONTRACTS_VERSION=v2.3.0
bash -x start_ocean.sh --with-typesense 2>&1 > start_ocean.log &
- name: Install deps & build
run: npm ci && npm run build:metadata
Expand Down Expand Up @@ -118,19 +117,6 @@ jobs:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Delete default runner images
run: |
docker image rm -f node:20
docker image rm -f node:20-alpine
docker image rm -f node:18
docker image rm -f node:18-alpine
docker image rm -f debian:10
docker image rm -f debian:11
docker image rm -f ubuntu:22.04
docker image rm -f ubuntu:20.04
docker image rm -f moby/buildkit:latest
rm -rf /usr/share/swift/

- name: Run Barge
working-directory: ${{ github.workspace }}/barge
run: |
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"@oasisprotocol/sapphire-paratime": "^1.3.2",
"@oceanprotocol/contracts": "^2.4.0",
"@oceanprotocol/contracts": "^2.4.1",
"@oceanprotocol/ddo-js": "^0.1.4",
"@rdfjs/dataset": "^2.0.2",
"@rdfjs/formats-common": "^3.1.0",
Expand Down
60 changes: 60 additions & 0 deletions src/contracts/EnterpriseFeeCollector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Signer } from 'ethers'
import ContractABI from '@oceanprotocol/contracts/artifacts/contracts/communityFee/EnterpriseFeeCollector.sol/EnterpriseFeeCollector.json'
import { AbiItem } from '../@types'
import { Config } from '../config'
import { SmartContractWithAddress } from './SmartContractWithAddress'

export class EnterpriseFeeCollectorContract extends SmartContractWithAddress {
public abi: AbiItem[]

getDefaultAbi() {
return ContractABI.abi as AbiItem[]
}

/**
* Instantiate EnterpriseFeeCollectorContract class
* @param {string} address The contract address.
* @param {Signer} signer The signer object.
* @param {string | number} [network] Network id or name
* @param {Config} [config] The configuration object.
* @param {AbiItem[]} [abi] ABI array of the smart contract
*/
constructor(
address: string,
signer: Signer,
network?: string | number,
config?: Config,
abi?: AbiItem[]
) {
super(address, signer, network, config, abi)
this.abi = abi || this.getDefaultAbi()
}

/**
* Check if token is allowed
* @return {Promise<any>} Boolean indicating if token is allowed
*/
public async isTokenAllowed(token: string): Promise<boolean> {
return await this.contract.isTokenAllowed(token)
}

/**
* Get Token details
* @return {Promise<any>} Token details
*/
public async getToken(token: string): Promise<any> {
return await this.contract.getToken(token)
}

/**
* Calculate fee
* @param {string} token Token address
* @param {string} amount Amount
* @return {Promise<string>} Fee amount
*/
public async calculateFee(token: string, amount: number): Promise<any> {
const weiAmount = this.amountToUnits(token, amount.toString())
const amountWithFee = await this.contract.calculateFee(token, weiAmount)
return this.unitsToAmount(token, amountWithFee)
}
}
38 changes: 38 additions & 0 deletions test/unit/EnterpriseFeeCollector.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { assert } from 'chai'
import { provider, getAddresses } from '../config'
import { Signer } from 'ethers'

import { Datatoken, amountToUnits, unitsToAmount } from '../../src/'
import { EnterpriseFeeCollectorContract } from '../../src/contracts/EnterpriseFeeCollector'
import BigNumber from 'bignumber.js'

describe('EnterpriseFeeCollector payments flow', () => {
let user1: Signer
let user2: Signer
let EnterpriseFeeCollector: EnterpriseFeeCollectorContract
let addresses
let OCEAN

before(async () => {
user1 = (await provider.getSigner(3)) as Signer
user2 = (await provider.getSigner(4)) as Signer

addresses = await getAddresses()
OCEAN = addresses.Ocean
})

it('should initialize EnterpriseFeeCollectorContract class', async () => {
const { chainId } = await user2.provider.getNetwork()
EnterpriseFeeCollector = new EnterpriseFeeCollectorContract(
addresses.EnterpriseFeeCollector,
user2,
Number(chainId)
)
assert(EnterpriseFeeCollector !== null)
})

it('Get token', async () => {
const tx = await EnterpriseFeeCollector.getToken(OCEAN)
assert(tx, 'failed to get token')
})
})
Loading