Skip to content
Open
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ cache
artifacts

.idea

dist
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/*

!README.md
!dist/**/*
!typechain-types/**/*
!contracts/**/*
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.10.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and [@unique-nft/solidity-interfaces](https://github.com/UniqueNetwork/solidity-
- [UniqueRoyalty.sol](./contracts/UniqueRoyalty.sol) - core decoding/encoding logic library
- [UniqueRoyaltyHelper.sol](./contracts/UniqueRoyaltyHelper.sol) - helper contract to decode/encode royalty data, transform, calculate royalty amount etc

### Typescript implementation of the library located - [here](./ts-implementation)
### Typescript implementation of the library located - [here](./src)

### To check everything is working

Expand Down
71 changes: 45 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
{
"name": "unique-royalties",
"name": "@unique-nft/unique-royalties",
"version": "0.0.1",
"main": "index.js",
"main": "dist/index.js",
"license": "MIT",
"description": "Typescript library and smart contracts to work with Unique NFTs royalties",
"repository": {
"type": "git",
"url": "https://github.com/UniqueNetwork/unique-royalties"
},
"bugs": {
"url": "https://github.com/UniqueNetwork/unique-royalties/issues"
},
"homepage": "https://github.com/UniqueNetwork/unique-royalties#readme",
"scripts": {
"compile": "hardhat compile",
"build": "hardhat compile && hardhat typechain && tsup src/ --format cjs --format esm --dts --outDir dist",
"clean": "hardhat clean && rimraf ./dist",
"check:balances": "hardhat run ./scripts/check-balances.ts",
"deploy:everywhere": "hardhat run ./scripts/deploy-everywhere.ts",
"deploy": "hardhat run ./scripts/deploy.ts",
Expand All @@ -15,31 +26,39 @@
"deploy:unique": "hardhat run ./scripts/deploy.ts --network unique",
"test:uniqsu": "hardhat test --network uniqsu",
"test:opal": "hardhat test --network opal",
"test": "hardhat test",
"clean": "hardhat clean"
"test": "hardhat test"
},
"devDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@typechain/ethers-v5": "^10.2.0",
"@typechain/hardhat": "^6.1.5",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@unique-nft/solidity-interfaces": "^0.52.0",
"chai": "^4.3.7",
"dotenv": "^16.0.3",
"ethers": "5",
"hardhat": "^2.13.0",
"hardhat-gas-reporter": "^1.0.9",
"prettier": "^2.8.7",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
"typescript": "^5.0.2"
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@openzeppelin/contracts": "^5.0.1",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.2.0",
"@types/mocha": ">=9.1.0",
"@types/node": "^20.11.11",
"@unique-nft/solidity-interfaces": "^0.70.0",
"chai": "^4.2.0",
"cpy-cli": "^5.0.0",
"dotenv": "^16.4.1",
"ethers": "6",
"hardhat": "^2.19.5",
"hardhat-gas-reporter": "^1.0.8",
"mkdirp": "^3.0.1",
"rimraf": "^5.0.5",
"solidity-coverage": "^0.8.1",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"typechain": "^8.3.0",
"typescript": "^5.3.3"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@unique-nft/utils": "^0.3.14"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 15 additions & 7 deletions tests/GasPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@ import { expect } from 'chai';
import { ETH_DEFAULT, ROYALTY_ENCODED, SUB_PRIMARY_ONLY } from './_samples';
import { logGasDiff, structFromRoyaltyPart } from './_util';
import { Ethereum } from '@unique-nft/utils/extension';
import { ContractTransaction } from 'ethers';
import { ContractTransaction, ContractTransactionResponse } from 'ethers';
import { libTestingFixture, loadFixtureOrDeploy } from './_fixtures';

const compare = async (
name: string,
dummyTx: ContractTransaction,
realTx: ContractTransaction,
dummyTx: ContractTransactionResponse,
realTx: ContractTransactionResponse,
) => {
const dummyReceipt = Ethereum.parseEthersTxReceipt(await dummyTx.wait());
const realReceipt = Ethereum.parseEthersTxReceipt(await realTx.wait());
// const dummyReceipt = Ethereum.parseEthersTxReceipt(await dummyTx.wait());
// const realReceipt = Ethereum.parseEthersTxReceipt(await realTx.wait());

logGasDiff(name, { dummyReceipt, realReceipt });
const dummyReceipt = await dummyTx.wait();
const realReceipt = await realTx.wait();

expect(realReceipt.gasUsed).to.gt(dummyReceipt.gasUsed);
const gasUsed = {
dummy: dummyReceipt.gasUsed,
real: realReceipt.gasUsed,
};

logGasDiff(name, gasUsed);

expect(gasUsed.real).to.gt(gasUsed.dummy);
};

describe('Gas prices', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/LibPartAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { expect } from 'chai';
import { ETH_DEFAULT, SUB_PRIMARY_ONLY } from './_samples';
import { loadFixtureOrDeploy, libTestingFixture } from './_fixtures';

import { decodeRoyalty, fromLibParts } from '../ts-implementation';
import { decodeRoyalty, fromLibParts } from '../src';

const structToLibPart = (struct: any) => ({
account: struct.account,
value: struct.value.toBigInt(),
value: struct.value,
});

describe('LibPartAdapter', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/Typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
encodeRoyaltyPart,
toLibPart,
fromLibPart,
} from '../ts-implementation';
} from '../src';
import {
ETH_DEFAULT,
SUB_PRIMARY_ONLY,
Expand Down
38 changes: 24 additions & 14 deletions tests/UniqueRoyaltyHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import { ETH_DEFAULT, ROYALTY_ENCODED, SUB_PRIMARY_ONLY } from './_samples';
import { expect } from 'chai';
import { helperTestingFixture, loadFixtureOrDeploy } from './_fixtures';
import { structFromRoyaltyPart } from './_util';
import {
calculateRoyalty,
toLibPart,
ROYALTIES_PROPERTY,
} from '../ts-implementation';
import { calculateRoyalty, ROYALTIES_PROPERTY } from '../src';
import { Address } from '@unique-nft/utils/address';
import { UniqueRoyaltyHelper } from '../typechain-types';

describe('UniqueRoyaltyHelper', () => {
const deploy = loadFixtureOrDeploy(helperTestingFixture);

const getAllRoyalties = async (collection, uniqueRoyaltyHelper) => {
const getAllRoyalties = async (
collectionAddress: string,
uniqueRoyaltyHelper: UniqueRoyaltyHelper,
) => {
const collectionRoyalty = await uniqueRoyaltyHelper.getCollectionRoyalty(
collection.address,
collectionAddress,
);

const tokenRoyalty = await uniqueRoyaltyHelper.getTokenRoyalty(
collection.address,
collectionAddress,
1,
);

const royalty = await uniqueRoyaltyHelper.getRoyalty(collection.address, 1);
const royalty = await uniqueRoyaltyHelper.getRoyalty(collectionAddress, 1);

return { collectionRoyalty, tokenRoyalty, royalty };
};
Expand All @@ -31,8 +31,12 @@ describe('UniqueRoyaltyHelper', () => {
this.timeout(120_000);

const { collection, uniqueRoyaltyHelper } = await deploy;
const collectionAddress = await collection.getAddress();

let allRoyalties = await getAllRoyalties(collection, uniqueRoyaltyHelper);
let allRoyalties = await getAllRoyalties(
collectionAddress,
uniqueRoyaltyHelper,
);
expect(allRoyalties.collectionRoyalty.length).to.equal(0);
expect(allRoyalties.tokenRoyalty.length).to.equal(0);
expect(allRoyalties.royalty.length).to.equal(0);
Expand All @@ -43,7 +47,10 @@ describe('UniqueRoyaltyHelper', () => {
])
).wait();

allRoyalties = await getAllRoyalties(collection, uniqueRoyaltyHelper);
allRoyalties = await getAllRoyalties(
collectionAddress,
uniqueRoyaltyHelper,
);

expect(allRoyalties.collectionRoyalty.length).to.equal(2);
expect(allRoyalties.royalty).to.deep.equal(allRoyalties.collectionRoyalty);
Expand All @@ -59,7 +66,10 @@ describe('UniqueRoyaltyHelper', () => {
{ key: ROYALTIES_PROPERTY, value: SUB_PRIMARY_ONLY.encoded },
]);

allRoyalties = await getAllRoyalties(collection, uniqueRoyaltyHelper);
allRoyalties = await getAllRoyalties(
collectionAddress,
uniqueRoyaltyHelper,
);

expect(allRoyalties.collectionRoyalty.length).to.equal(2);
expect(allRoyalties.tokenRoyalty.length).to.equal(1);
Expand Down Expand Up @@ -116,11 +126,11 @@ describe('UniqueRoyaltyHelper', () => {
ETH_DEFAULT.decoded.address,
);

expect(sub.amount.toBigInt()).to.equal(
expect(sub.amount).to.equal(
calculateRoyalty(SUB_PRIMARY_ONLY.decoded, sellPrice).amount,
);

expect(eth.amount.toBigInt()).to.equal(
expect(eth.amount).to.equal(
calculateRoyalty(ETH_DEFAULT.decoded, sellPrice).amount,
);
});
Expand Down
8 changes: 6 additions & 2 deletions tests/_fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
CollectionHelpersFactory,
UniqueNFTFactory,
constants,
UniqueNFT,
} from '@unique-nft/solidity-interfaces';
import { Contract } from 'ethers';

export async function loadFixtureOrDeploy<T>(
fixture: () => Promise<T>,
Expand Down Expand Up @@ -40,6 +42,7 @@ export async function helperTestingFixture() {
if (collectionHelpersCode && collectionHelpersCode !== '0x') {
const [signer] = await ethers.getSigners();

// @ts-ignore - remove after ethers update
const collectionHelpers = await CollectionHelpersFactory(signer, ethers);

const collectionTx = await collectionHelpers.createNFTCollection(
Expand All @@ -53,11 +56,12 @@ export async function helperTestingFixture() {
CollectionCreated: { collectionId: string };
}>(await collectionTx.wait());

const collection = await UniqueNFTFactory(
const collection = (await UniqueNFTFactory(
parsed.events.CollectionCreated.collectionId,
// @ts-ignore - remove after ethers update
signer,
ethers,
);
)) as UniqueNFT & Contract;

await (await collection.mint(signer.address)).wait();

Expand Down
2 changes: 1 addition & 1 deletion tests/_samples.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UniqueRoyaltyPart, RoyaltyType } from '../ts-implementation';
import { UniqueRoyaltyPart, RoyaltyType } from '../src';

type Sample = {
decoded: UniqueRoyaltyPart;
Expand Down
10 changes: 5 additions & 5 deletions tests/_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
UniqueRoyaltyPartStruct,
UniqueRoyaltyPartStructOutput,
} from '../typechain-types/TestingContract';
import { RoyaltyType, UniqueRoyaltyPart } from '../ts-implementation';
import { RoyaltyType, UniqueRoyaltyPart } from '../src';
import { expect } from 'chai';
import { Address } from '@unique-nft/utils/address';

Expand Down Expand Up @@ -56,12 +56,12 @@ export const structFromRoyaltyPart = (

export const logGasDiff = (
name: string,
{ dummyReceipt, realReceipt }: { dummyReceipt: any; realReceipt: any },
gasUsed: { dummy: bigint; real: bigint },
) => {
console.dir({
name,
dummy: dummyReceipt.gasUsed,
real: realReceipt.gasUsed,
diff: realReceipt.gasUsed - dummyReceipt.gasUsed,
dummy: gasUsed.dummy,
real: gasUsed.real,
diff: gasUsed.real - gasUsed.dummy,
});
};
Loading