Skip to content

Commit

Permalink
feat: initial support for zerodev
Browse files Browse the repository at this point in the history
  • Loading branch information
r-marques committed Sep 20, 2023
1 parent 118fac7 commit c061753
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# Build process
- uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: 18

- name: Set version to env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: 18
registry-url: https://registry.npmjs.org/
- run: yarn install --frozen-lockfile --ignore-engines
- run: npm publish --access public
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/testing-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Install dependencies
run: |
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- uses: nevermined-io/[email protected]
with:
token: ${{ secrets.API_TOKEN_GITHUB }}
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- uses: nevermined-io/[email protected]
with:
token: ${{ secrets.API_TOKEN_GITHUB }}
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- uses: nevermined-io/[email protected]
with:
token: ${{ secrets.API_TOKEN_GITHUB }}
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- uses: actions/checkout@v3
with:
repository: nevermined-io/node
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- uses: nevermined-io/[email protected]
with:
token: ${{ secrets.API_TOKEN_GITHUB }}
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
token: ${{ secrets.API_TOKEN_GITHUB }}
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Deploy contracts
run: |
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v12
18
90 changes: 90 additions & 0 deletions integration/external/Zerodev.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { HDNodeWallet, Wallet } from 'ethers'
import { assert } from 'chai'
import { ZeroDevEthersProvider, convertEthersSignerToAccountSigner } from '@zerodev/sdk'
import {
Account,
AssetAttributes,
AssetPrice,
EthSignJWT,
Nevermined,
NeverminedOptions,
} from '../../src'
import { getMetadata } from '../utils'

describe('Nevermined sdk with zerodev', () => {
let projectId: string
let owner: HDNodeWallet
let config: NeverminedOptions
let nevermined: Nevermined
let account: Account
let zerodevProvider: ZeroDevEthersProvider<'ECDSA'>

before(async () => {
projectId = process.env.PROJECT_ID!
owner = Wallet.createRandom()
account = new Account(await owner.getAddress())
const infuraToken = process.env.INFURA_TOKEN!

config = {
marketplaceUri: 'https://marketplace-api.mumbai.nevermined.app',
neverminedNodeUri: 'https://node.mumbai.nevermined.app',
graphHttpUri: 'https://api.thegraph.com/subgraphs/name/nevermined-io/public',
neverminedNodeAddress: '0x5838B5512cF9f12FE9f2beccB20eb47211F9B0bc',
artifactsFolder: './artifacts',
web3ProviderUri: `https://polygon-mumbai.infura.io/v3/${infuraToken}`,
}
})

it('should instantiate nevermined sdk with a zerodev provider', async () => {
zerodevProvider = await ZeroDevEthersProvider.init('ECDSA', {
projectId,
owner: convertEthersSignerToAccountSigner(owner as any),
})

nevermined = await Nevermined.getInstance({
...config,
zerodevProvider: zerodevProvider,
})

assert.isDefined(nevermined)
})

it('should login to the marketplace api', async () => {
const accountSigner = zerodevProvider.getAccountSigner()

const clientAssertion = await new EthSignJWT({
iss: account.getId(),
})
.setProtectedHeader({ alg: 'ES256K' })
.setIssuedAt()
.setExpirationTime('1h')
.ethSign(accountSigner as any)

await nevermined.services.marketplace.login(clientAssertion)
})

it('should request some nevermined tokens', async () => {
const accountSigner = zerodevProvider.getAccountSigner()
const accountAddress = await accountSigner.getAddress()

console.log('requesting tokens for account', accountAddress)
const result = await nevermined.keeper.dispenser.requestTokens(10, accountAddress)
assert.isDefined(result)
})

it('should create a new asset with zerodev provider', async () => {
const assetAttributes = AssetAttributes.getInstance({
metadata: getMetadata(),
services: [
{
serviceType: 'access',
price: new AssetPrice(await owner.getAddress(), 0n),
},
],
providers: [config.neverminedNodeAddress],
})

const ddo = await nevermined.assets.create(assetAttributes, account)
assert.isDefined(ddo)
})
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"homepage": "https://github.com/nevermined-io/sdk-js#readme",
"dependencies": {
"@apollo/client": "^3.7.16",
"@zerodev/sdk": "^4.0.17",
"assert": "^2.0.0",
"cross-fetch": "^4.0.0",
"crypto-browserify": "^3.12.0",
Expand Down
13 changes: 10 additions & 3 deletions src/keeper/contracts/ContractBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ContractEvent, EventHandler, SubgraphEvent } from '../../events'
import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract'
import { KeeperError } from '../../errors'
import {
Contract,
ContractTransactionReceipt,
ContractTransactionResponse,
FunctionFragment,
Expand Down Expand Up @@ -143,13 +144,13 @@ export abstract class ContractBase extends Instantiable {
})
}

const transactionReceipt: ContractTransactionReceipt = await transactionResponse.wait()
// const transactionReceipt: ContractTransactionReceipt = await transactionResponse.wait()

if (progress) {
progress({
stage: 'receipt',
args: this.searchMethodInputs(name, args),
transactionReceipt,
// transactionReceipt,
method: name,
from,
value,
Expand All @@ -159,7 +160,7 @@ export abstract class ContractBase extends Instantiable {
})
}

return transactionReceipt
return transactionResponse as any
}

public async send(
Expand All @@ -168,6 +169,12 @@ export abstract class ContractBase extends Instantiable {
args: any[],
params: TxParameters = {},
): Promise<ContractTransactionReceipt> {
if (this.config.zerodevProvider) {
const signer = this.config.zerodevProvider.getAccountSigner()
const contract = new Contract(this.address, this.contract.interface, signer as any)
return await this.internalSend(name, from, args, params, contract, params.progress)
}

if (params.signer) {
const paramsFixed = { ...params, signer: undefined }
const contract = this.contract.connect(params.signer)
Expand Down
3 changes: 3 additions & 0 deletions src/models/NeverminedOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers } from 'ethers'
import { LogLevel } from '../utils'
import { AaveConfig } from './'
import { ZeroDevEthersProvider } from '@zerodev/sdk'

export class NeverminedOptions {
/**
Expand Down Expand Up @@ -83,4 +84,6 @@ export class NeverminedOptions {
* Use a gas station to calculate transaction fees
*/
public gasStationUri?: string

public zerodevProvider?: ZeroDevEthersProvider<'ECDSA'>
}

0 comments on commit c061753

Please sign in to comment.