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

Fix/arbitrum fees #577

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 4 additions & 13 deletions integration/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ if (process.env.NETWORK_NAME === 'testing') {
} as NeverminedOptions)
}

if (process.env.NETWORK_NAME === 'goerli') {
Object.assign(configBase, {
marketplaceUri: 'https://metadata.goerli.nevermined.network',
neverminedNodeUri: 'https://node.goerli.nevermined.network',
web3ProviderUri: `https://goerli.infura.io/v3/${infuraToken}`,
neverminedNodeAddress: '0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0',
} as NeverminedOptions)
}

if (process.env.NETWORK_NAME === 'mumbai') {
Object.assign(configBase, {
marketplaceUri: 'https://marketplace-api.mumbai.nevermined.app',
Expand Down Expand Up @@ -74,11 +65,11 @@ if (process.env.NETWORK_NAME === 'gnosis') {
} as NeverminedOptions)
}

if (process.env.NETWORK_NAME === 'nvm-one') {
if (process.env.NETWORK_NAME === 'one-staging') {
Object.assign(configBase, {
marketplaceUri: 'https://marketplace-api.mumbai.nevermined.one',
neverminedNodeUri: 'https://node.mumbai.nevermined.one',
web3ProviderUri: `https://polygon-mumbai.infura.io/v3/${infuraToken}`,
marketplaceUri: 'https://marketplace-api.goerli.nevermined.one',
neverminedNodeUri: 'https://node.goerli.nevermined.one',
web3ProviderUri: `https://arbitrum-goerli.infura.io/v3/${infuraToken}`,
neverminedNodeAddress: '0x5838B5512cF9f12FE9f2beccB20eb47211F9B0bc',
graphHttpUri: 'https://api.thegraph.com/subgraphs/name/nevermined-io/public',
} as NeverminedOptions)
Expand Down
4 changes: 2 additions & 2 deletions integration/nevermined/Assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('Assets', () => {

it('should be able to download the updated files', async () => {
const folder = '/tmp/sdk-js/updated-files'
if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true})
if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true })

const path = (await nevermined.assets.download(ddo.id, publisher, folder, -1)) as string
assert.include(path, folder, 'The storage path is not correct.')
Expand Down Expand Up @@ -229,7 +229,7 @@ describe('Assets', () => {
})

it('new rating must be between 0 and 1', async () => {
// Trying to add a vote with a rating out of range
// Trying to add a vote with a rating out of range
await assert.isRejected(nevermined.assets.addRating(ddo.shortId(), 2, 1, publisher))
})
})
Expand Down
1 change: 0 additions & 1 deletion integration/nevermined/ConsumeAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ describe('Consume Asset', () => {
assert.isTrue(paid, 'The asset has not been paid correctly')
})

// The test will fail because Nevermined Node grants the access faster
it('should grant the access by the publisher', async () => {
try {
const granted = await nevermined.agreements.conditions.grantAccess(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "1.6.1",
"version": "1.6.2",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion scripts/download-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

REPO_URL=https://artifacts.nevermined.network
declare -A NETWORKS_MAP
NETWORKS_MAP=( ["mainnet"]="1" ["rinkeby"]="4" ["kovan"]="42" ["matic"]="137" ["mumbai"]="80001" ["celo-alfajores"]="44787" ["celo"]="42220" ["aurora"]="1313161554" ["aurora-testnet"]="1313161555" )
NETWORKS_MAP=( ["mainnet"]="1" ["rinkeby"]="4" ["kovan"]="42" ["matic"]="137" ["mumbai"]="80001" ["celo-alfajores"]="44787" ["celo"]="42220" ["aurora"]="1313161554" ["aurora-testnet"]="1313161555" ["arbitrum-one"]="42161" ["arbitrum-goerli"]="421613" )

SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
UNPACK_DIR="$SCRIPT_DIR/../artifacts"
Expand Down
24 changes: 23 additions & 1 deletion src/keeper/ContractHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,19 @@ export class ContractHandler extends Instantiable {
maxFeePerGas?: BigNumber,
maxPriorityFeePerGas?: BigNumber,
) {
// Custom gas fee for polygon networks
// Custom gas fee calculation for different networks
const networkId = await this.nevermined.keeper.getNetworkId()

// polygon
if (networkId === 137 || networkId === 80001) {
return this.getFeeDataPolygon(networkId)
}

// arbitrum
if (networkId === 42161 || networkId === 421613) {
return this.getFeeDataArbitrum()
}

const feeData = await this.web3.getFeeData()

// EIP-1559 fee parameters
Expand Down Expand Up @@ -315,4 +322,19 @@ export class ContractHandler extends Instantiable {
type: 2,
}
}

private async getFeeDataArbitrum() {
/**
* See https://docs.arbitrum.io/arbos/gas
*
* The sequencer prioritizes transactions on a first-come first-served basis.
* Because tips do not make sense in this model, they are ignored.
* Arbitrum users always just pay the basefee regardless of the tip they choose.
*/
const feeData = await this.web3.getFeeData()

return {
gasPrice: feeData.gasPrice,
}
}
}
16 changes: 6 additions & 10 deletions src/keeper/Keeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Keeper extends Instantiable {
// Main contracts
dispenser: undefined, // Optional
token: undefined, // Optional
curveRoyalties: undefined, // Optional
curveRoyalties: undefined, // Optional
nvmConfig: NeverminedConfig.getInstance(this.instanceConfig),
didRegistry: DIDRegistry.getInstance(this.instanceConfig),
// Managers
Expand Down Expand Up @@ -101,8 +101,6 @@ export class Keeper extends Instantiable {
aaveRepayCondition: undefined,
aaveCreditTemplate: undefined,



nft721LockCondition: NFT721LockCondition.getInstance(this.instanceConfig),
distributeNftCollateralCondition: DistributeNFTCollateralCondition.getInstance(
this.instanceConfig,
Expand Down Expand Up @@ -207,7 +205,7 @@ export class Keeper extends Instantiable {
nft721AccessTemplate: this.instances.nft721AccessTemplate,
nftSalesTemplate: this.instances.nftSalesTemplate,
nft721SalesTemplate: this.instances.nft721SalesTemplate,
aaveCreditTemplate: undefined
aaveCreditTemplate: undefined,
}
this.templateList = [
this.instances.accessTemplate,
Expand Down Expand Up @@ -409,12 +407,10 @@ export class Keeper extends Instantiable {

this.logger.debug('Loading Aave contracts')
this.instances.aaveBorrowCondition = await AaveBorrowCondition.getInstance(this.instanceConfig)
this.instances.aaveCollateralDepositCondition = await AaveCollateralDepositCondition.getInstance(
this.instanceConfig,
)
this.instances.aaveCollateralWithdrawCondition = await AaveCollateralWithdrawCondition.getInstance(
this.instanceConfig,
)
this.instances.aaveCollateralDepositCondition =
await AaveCollateralDepositCondition.getInstance(this.instanceConfig)
this.instances.aaveCollateralWithdrawCondition =
await AaveCollateralWithdrawCondition.getInstance(this.instanceConfig)
this.instances.aaveRepayCondition = await AaveRepayCondition.getInstance(this.instanceConfig)

this.conditions.aaveBorrowCondition = this.instances.aaveBorrowCondition
Expand Down
2 changes: 1 addition & 1 deletion test/bookmarks/Bookmarks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Bookmarks', () => {
nevermined = await Nevermined.getInstance(config)
})

beforeEach(async () => {
beforeEach(async () => {
bookmarks = nevermined.services.bookmarks // eslint-disable-line prefer-destructuring

newBookmark = {
Expand Down
2 changes: 1 addition & 1 deletion test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LoggerInstance } from '../src/utils'

LoggerInstance.setLevel(LogLevel.Error)

export default {
export default {
marketplaceUri: 'http://localhost:3100',
neverminedNodeUri: 'http://localhost:8030',
neverminedNodeAddress: '0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0',
Expand Down
8 changes: 2 additions & 6 deletions test/keeper/conditions/AaveBorrowCondition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ describe('AaveBorrowCondition', () => {
nevermined = await Nevermined.getInstance(config)
;[user] = await nevermined.accounts.list()
;({ didRegistry } = nevermined.keeper)
condition =
(await (
await Nevermined.getInstance(config))
.keeper.loadAaveInstances())
.conditions.aaveBorrowCondition

condition = (await (await Nevermined.getInstance(config)).keeper.loadAaveInstances()).conditions
.aaveBorrowCondition
})

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ describe('AaveCollateralDepositCondition', () => {
nevermined = await Nevermined.getInstance(config)
;[user] = await nevermined.accounts.list()
;({ didRegistry } = nevermined.keeper)
condition =
(await (
await Nevermined.getInstance(config))
.keeper.loadAaveInstances())
.conditions.aaveCollateralDepositCondition
condition = (await (await Nevermined.getInstance(config)).keeper.loadAaveInstances()).conditions
.aaveCollateralDepositCondition
})

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ describe('AaveCollateralWithdrawCondition', () => {
nevermined = await Nevermined.getInstance(config)
;[user] = await nevermined.accounts.list()
;({ didRegistry } = nevermined.keeper)
condition =
(await (
await Nevermined.getInstance(config))
.keeper.loadAaveInstances())
.conditions.aaveCollateralWithdrawCondition
condition = (await (await Nevermined.getInstance(config)).keeper.loadAaveInstances()).conditions
.aaveCollateralWithdrawCondition
})

beforeEach(async () => {
Expand Down
7 changes: 2 additions & 5 deletions test/keeper/conditions/AaveRepayCondition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ describe('AaveRepayCondition', () => {
nevermined = await Nevermined.getInstance(config)
;[user] = await nevermined.accounts.list()
;({ didRegistry } = nevermined.keeper)
condition =
(await (
await Nevermined.getInstance(config))
.keeper.loadAaveInstances())
.conditions.aaveRepayCondition
condition = (await (await Nevermined.getInstance(config)).keeper.loadAaveInstances()).conditions
.aaveRepayCondition
})

beforeEach(async () => {
Expand Down