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

Add confidential EVM flag when creating a datatoken 4 in NFT class #1859

Merged
merged 29 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d2cc8f9
Add confidential EVM flag when creating a datatoken 4.
mariacarmina Oct 3, 2024
4551bc5
Add comments.
mariacarmina Oct 3, 2024
1b45c35
fix lint.
mariacarmina Oct 3, 2024
385d7d2
fix lint.
mariacarmina Oct 3, 2024
4d90f8f
Add chain id check to bundled functions.
mariacarmina Oct 3, 2024
d086738
fix conflicts.
mariacarmina Oct 7, 2024
3df4a45
Merge d086738122013e70dce225aeb6ad62f704a7338e into e6d7d7c60c3fdd335…
mariacarmina Oct 7, 2024
abafd1b
Updating CodeExamples.md
Oct 7, 2024
3974608
Updating ComputeExamples.md
Oct 7, 2024
964061b
Used config object.
mariacarmina Oct 7, 2024
ae1eed4
Added check for sapphire confidential EVM. Fix tests.
mariacarmina Oct 7, 2024
93c59b4
Added sapphire wrap signer for all contracts.
mariacarmina Oct 7, 2024
0577262
Make network mandatory field.
mariacarmina Oct 8, 2024
0863047
Undo making network mandatory.
mariacarmina Oct 8, 2024
c38a105
refactor condition.
mariacarmina Oct 8, 2024
775fee6
refactor condition.
mariacarmina Oct 8, 2024
0549248
Add condition when creating NFT.
mariacarmina Oct 8, 2024
2ed23b5
Merge branch 'main' into confidential-evm-nft-class
mariacarmina Oct 8, 2024
c16ee96
Refactor with sdk.
mariacarmina Oct 8, 2024
d4df466
fix lint.
mariacarmina Oct 8, 2024
2ce8bc5
tweak.
mariacarmina Oct 8, 2024
87e1f9a
tweak.
mariacarmina Oct 9, 2024
e45bad9
Created protected function to get vthe signer according to the sdk fr…
mariacarmina Oct 14, 2024
591ab24
Merge branch 'main' into confidential-evm-nft-class
mariacarmina Oct 14, 2024
a79b137
Fix lint. Add check for sdk within the config.
mariacarmina Oct 14, 2024
b58340e
Fix lint.
mariacarmina Oct 14, 2024
6ad9798
Merge b58340ed76973d903b98cc2a6b60df9dabba7e2f into cc91e1d376090137b…
mariacarmina Oct 14, 2024
9ffee5a
Updating CodeExamples.md
Oct 14, 2024
cf3fb40
Updating ComputeExamples.md
Oct 14, 2024
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
40 changes: 30 additions & 10 deletions CodeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ you need to mint oceans to mentioned accounts only if you are using barge to tes

### 6.1 Publish a dataset (create NFT + Datatoken) with a fixed rate exchange
```Typescript
const factory = new NftFactory(addresses.ERC721Factory, publisherAccount)
const factory = new NftFactory(
addresses.ERC721Factory,
publisherAccount,
await publisherAccount.getChainId()
)

const nftParams: NftCreateData = {
name: FRE_NFT_NAME,
Expand Down Expand Up @@ -409,7 +413,11 @@ Now let's console log the DID to check everything is working

### 6.3 Marketplace displays fixed rate asset for sale
```Typescript
const fixedRate = new FixedRateExchange(freAddress, publisherAccount)
const fixedRate = new FixedRateExchange(
freAddress,
publisherAccount,
await publisherAccount.getChainId()
)
const oceanAmount = await (
await fixedRate.calcBaseInGivenDatatokensOut(freId, '1')
).baseTokenAmount
Expand All @@ -424,7 +432,7 @@ Now that the market has fetched those values it can display the asset on the fro

### 7.1 Consumer buys a fixed rate asset data asset, and downloads it
```Typescript
datatoken = new Datatoken(publisherAccount)
datatoken = new Datatoken(publisherAccount, await publisherAccount.getChainId())
const DATATOKEN_AMOUNT = '10000'

await datatoken.mint(
Expand Down Expand Up @@ -473,7 +481,11 @@ Before we call the contract we have to call `approve` so that the contract can m
DATATOKEN_AMOUNT
)

const fixedRate = new FixedRateExchange(freAddress, consumerAccount)
const fixedRate = new FixedRateExchange(
freAddress,
consumerAccount,
await consumerAccount.getChainId()
)
```
Now we can make the contract call
```Typescript
Expand Down Expand Up @@ -517,7 +529,7 @@ Next, we need to initialize the provider
validUntil: initializeData.providerFee.validUntil
}

datatoken = new Datatoken(consumerAccount)
datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())

```
Lets now make the payment
Expand Down Expand Up @@ -574,7 +586,11 @@ Lets check that the download URL was successfully received

### 8.1 Publish a dataset (create NFT + Datatoken) with a dispenser
```Typescript
const factory = new NftFactory(addresses.ERC721Factory, publisherAccount)
const factory = new NftFactory(
addresses.ERC721Factory,
publisherAccount,
await publisherAccount.getChainId()
)

const nftParams: NftCreateData = {
name: DISP_NFT_NAME,
Expand Down Expand Up @@ -679,8 +695,12 @@ Now we need to encrypt file(s) using provider

### 9.1 Consumer gets a dispenser data asset, and downloads it
```Typescript
datatoken = new Datatoken(publisherAccount)
const dispenser = new Dispenser(addresses.Dispenser, consumerAccount)
datatoken = new Datatoken(publisherAccount, await publisherAccount.getChainId())
const dispenser = new Dispenser(
addresses.Dispenser,
consumerAccount,
await consumerAccount.getChainId()
)

let consumerDTBalance = await balance(
consumerAccount,
Expand Down Expand Up @@ -709,7 +729,7 @@ Now we need to encrypt file(s) using provider
const resolvedDDO = await aquarius.waitForAqua(fixedDDO.id)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')

datatoken = new Datatoken(consumerAccount)
datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())

```
At this point we need to encrypt file(s) using provider
Expand Down Expand Up @@ -791,7 +811,7 @@ Here are the steps:
### 10.1 Add key-value pair to data NFT
Let's start by using the `setData` method to update the nft key value store with some data
```Typescript
const nft = new Nft(publisherAccount)
const nft = new Nft(publisherAccount, await publisherAccount.getChainId())
const data = 'SomeData'
try {
await nft.setData(
Expand Down
6 changes: 5 additions & 1 deletion ComputeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ async function createAsset(
) {
const nft = new Nft(owner, (await owner.provider.getNetwork()).chainId)

const nftFactory = new NftFactory(addresses.ERC721Factory, owner)
const nftFactory = new NftFactory(
addresses.ERC721Factory,
owner,
await owner.getChainId()
)

const chain = (await owner.provider.getNetwork()).chainId

Expand Down
4 changes: 3 additions & 1 deletion src/config/Config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AbiItem } from '../@types'
import { LogLevel } from '../utils'

type SDK = 'evm' | 'oasis'

export class Config {
/**
* Ethereum node URL.
Expand Down Expand Up @@ -187,6 +189,6 @@ export class Config {
veFeeEstimate?: string

// is confidential evm
confidentialEVM?: boolean
sdk?: SDK
accessListFactory?: string
}
60 changes: 39 additions & 21 deletions src/config/ConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export const configHelperNetworks: Config[] = [
// comment th following configs if running on macOS
metadataCacheUri: 'http://172.15.0.5:5000',
providerUri: 'http://172.15.0.4:8030',
subgraphUri: 'https://172.15.0.15:8000'
subgraphUri: 'https://172.15.0.15:8000',
// uncomment the following configs if running on macOS
// metadataCacheUri: 'http://127.0.0.1:5000',
// providerUri: 'http://127.0.0.1:8030/',
// subgraphUri: 'http://127.0.0.1:9000/'
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -48,7 +49,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://sepolia.infura.io/v3',
subgraphUri: 'https://v4.subgraph.sepolia.oceanprotocol.com',
explorerUri: 'https://sepolia.etherscan.io',
gasFeeMultiplier: 1.1
gasFeeMultiplier: 1.1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -61,7 +63,8 @@ export const configHelperNetworks: Config[] = [
transactionBlockTimeout: 150,
transactionConfirmationBlocks: 5,
transactionPollingTimeout: 1750,
gasFeeMultiplier: 1.05
gasFeeMultiplier: 1.05,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -71,7 +74,8 @@ export const configHelperNetworks: Config[] = [
subgraphUri: 'https://v4.subgraph.polygon.oceanprotocol.com',
explorerUri: 'https://polygonscan.com',
oceanTokenSymbol: 'mOCEAN',
gasFeeMultiplier: 1.6
gasFeeMultiplier: 1.6,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -80,7 +84,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://rpc.gaiaxtestnet.oceanprotocol.com',
providerUri: 'https://v4.provider.gaiaxtestnet.oceanprotocol.com',
subgraphUri: 'https://v4.subgraph.gaiaxtestnet.oceanprotocol.com',
explorerUri: 'https://blockscout.gaiaxtestnet.oceanprotocol.com'
explorerUri: 'https://blockscout.gaiaxtestnet.oceanprotocol.com',
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -89,7 +94,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://polygon-mumbai.infura.io/v3',
subgraphUri: 'https://v4.subgraph.mumbai.oceanprotocol.com',
explorerUri: 'https://mumbai.polygonscan.com',
gasFeeMultiplier: 1.1
gasFeeMultiplier: 1.1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -98,7 +104,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://bsc-dataseed.binance.org',
subgraphUri: 'https://v4.subgraph.bsc.oceanprotocol.com',
explorerUri: 'https://bscscan.com/',
gasFeeMultiplier: 1.05
gasFeeMultiplier: 1.05,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -107,7 +114,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://rpc.energyweb.org',
subgraphUri: 'https://v4.subgraph.energyweb.oceanprotocol.com',
explorerUri: 'https://explorer.energyweb.org',
gasFeeMultiplier: 1.05
gasFeeMultiplier: 1.05,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -116,7 +124,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://moonriver.api.onfinality.io/public',
subgraphUri: 'https://v4.subgraph.moonriver.oceanprotocol.com',
explorerUri: 'https://moonriver.moonscan.io/',
gasFeeMultiplier: 1.05
gasFeeMultiplier: 1.05,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -127,7 +136,8 @@ export const configHelperNetworks: Config[] = [
providerUri: 'https://provider.v4.genx.delta-dao.com',
subgraphUri: 'https://subgraph.v4.genx.minimal-gaia-x.eu',
explorerUri: 'https://explorer.genx.minimal-gaia-x.eu/',
gasFeeMultiplier: 1
gasFeeMultiplier: 1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -136,7 +146,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://mainnet.optimism.io',
subgraphUri: 'https://v4.subgraph.optimism.oceanprotocol.com',
explorerUri: 'https://optimistic.etherscan.io/',
gasFeeMultiplier: 1.1
gasFeeMultiplier: 1.1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -145,7 +156,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://sepolia.optimism.io',
subgraphUri: 'https://v4.subgraph.optimism-sepolia.oceanprotocol.com',
explorerUri: 'https://sepolia-optimism.etherscan.io/',
gasFeeMultiplier: 1.1
gasFeeMultiplier: 1.1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
Expand All @@ -154,7 +166,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://sapphire.oasis.io',
subgraphUri: 'https://v4.subgraph.sapphire-mainnet.oceanprotocol.com/',
explorerUri: 'https://explorer.oasis.io/mainnet/sapphire/',
gasFeeMultiplier: 1
gasFeeMultiplier: 1,
sdk: 'oasis'
},
{
...configHelperNetworksBase,
Expand All @@ -164,7 +177,8 @@ export const configHelperNetworks: Config[] = [
subgraphUri:
'https://v4.subgraph.sapphire-testnet.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph',
explorerUri: 'https://explorer.oasis.io/testnet/sapphire/',
gasFeeMultiplier: 1
gasFeeMultiplier: 1,
sdk: 'oasis'
},
{
...configHelperNetworksBase,
Expand All @@ -174,7 +188,8 @@ export const configHelperNetworks: Config[] = [
metadataCacheUri: 'https://aquarius.dev.pontus-x.eu',
providerUri: 'https://provider.dev.pontus-x.eu',
subgraphUri: 'https://subgraph.dev.pontus-x.eu',
explorerUri: 'https://explorer.dev.pontus-x.eu/testnet/pontusx'
explorerUri: 'https://explorer.dev.pontus-x.eu/testnet/pontusx',
sdk: 'evm'
}
]

Expand Down Expand Up @@ -315,14 +330,17 @@ export class ConfigHelper {
addresses
)
}
config.confidentialEVM =
paulo-ocean marked this conversation as resolved.
Show resolved Hide resolved
filterBy === 'chainId'
? KNOWN_CONFIDENTIAL_EVMS.includes(Number(network))
: network.toString().includes('oasis_sap')
if (config.confidentialEVM) {
config.accessListFactory = contractAddressesConfig.accessListFactory

if (!('sdk' in config) || config.sdk === null) {
if (KNOWN_CONFIDENTIAL_EVMS.includes(config.chainId)) {
config.sdk = 'oasis'
} else {
config.sdk = 'evm'
}
}

config.accessListFactory = contractAddressesConfig.accessListFactory

config = { ...config, ...contractAddressesConfig }

const nodeUri = infuraProjectId
Expand Down
15 changes: 5 additions & 10 deletions src/contracts/AccessList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.mint(user, tokenUri)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.mint,
user,
Expand All @@ -122,10 +121,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.batchMint(users, tokenUris)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.batchMint,
users,
Expand All @@ -146,10 +144,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.burn(tokenId)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.burn,
tokenId
Expand All @@ -169,10 +166,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.transferOwnership(newOwner)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.transferOwnership,
newOwner
Expand All @@ -190,10 +186,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.renounceOwnership()
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.renounceOwnership
)
Expand Down
5 changes: 2 additions & 3 deletions src/contracts/AccessListFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class AccesslistFactory extends SmartContractWithAddress {
try {
const tx = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.deployAccessListContract,
nameAccessList,
Expand Down Expand Up @@ -144,10 +144,9 @@ export class AccesslistFactory extends SmartContractWithAddress {

const estGas = await this.contract.estimateGas.changeTemplateAddress(templateAddress)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.functions.changeTemplateAddress,
templateAddress
Expand Down
Loading