git.delta.rocks / unique-network / refs/commits / 3624bf8b9fe6

difftreelog

fix reconfigure price-targeted coefficients

Yaroslav Bolyukin2021-11-23parent: #32023b1.patch.diff
in: master

3 files changed

modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -243,7 +243,7 @@
 impl FeeCalculator for FixedFee {
 	fn min_gas_price() -> U256 {
 		// Targeting 0.15 UNQ per transfer
-		(1 * MICROUNIQUE).into()
+		1_024_947_215u32.into()
 	}
 }
 
@@ -480,7 +480,8 @@
 
 	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
 		smallvec!(WeightToFeeCoefficient {
-			coeff_integer: 146_700u32.into(), // Targeting 0.1 Unique per NFT transfer
+			// Targeting 0.1 Unique per NFT transfer
+			coeff_integer: 142_688u32.into(),
 			coeff_frac: Perbill::zero(),
 			negative: false,
 			degree: 1,
modifiedtests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth
--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -170,11 +170,12 @@
       const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
       await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');
       const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+
       const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);
-
       const expectedTransferFee = 0.1;
-      const tolerance = 0.001;
-      expect(Number(fee) / Number(UNIQUE) - expectedTransferFee).to.be.lessThan(tolerance);
+      const tolerance = 0.00001;
+
+      expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance);
     });
   });
 
modifiedtests/src/eth/base.test.tsdiffbeforeafterboth
before · tests/src/eth/base.test.ts
12import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee} from './util/helpers';3import {expect} from 'chai';4import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';5import nonFungibleAbi from './nonFungibleAbi.json';6import privateKey from '../substrate/privateKey';78describe('Contract calls', () => {9  itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {10    const deployer = await createEthAccountWithBalance(api, web3);11    const flipper = await deployFlipper(web3, deployer);1213    const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));14    expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;15  });1617  itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {18    const userA = await createEthAccountWithBalance(api, web3);19    const userB = createEthAccount(web3);2021    const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));22    expect(cost - await ethBalanceViaSub(api, userB) < BigInt(0.2 * Number(UNIQUE))).to.be.true;23  });2425  itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {26    const caller = await createEthAccountWithBalance(api, web3);27    const receiver = createEthAccount(web3);2829    const alice = privateKey('//Alice');30    const collection = await createCollectionExpectSuccess({31      mode: {type: 'NFT'},32    });33    const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});3435    const address = collectionIdToAddress(collection);36    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});3738    const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));3940    const fee = Number(cost) / Number(UNIQUE);41    const expectedFee = 0.15;42    const tolerance = 0.002;4344    expect(Math.abs(fee - expectedFee) < tolerance).to.be.true;45  });46});
after · tests/src/eth/base.test.ts
12import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee} from './util/helpers';3import {expect} from 'chai';4import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';5import nonFungibleAbi from './nonFungibleAbi.json';6import privateKey from '../substrate/privateKey';78describe('Contract calls', () => {9  itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {10    const deployer = await createEthAccountWithBalance(api, web3);11    const flipper = await deployFlipper(web3, deployer);1213    const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));14    expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;15  });1617  itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {18    const userA = await createEthAccountWithBalance(api, web3);19    const userB = createEthAccount(web3);2021    const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));22    expect(cost - await ethBalanceViaSub(api, userB) < BigInt(0.2 * Number(UNIQUE))).to.be.true;23  });2425  itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {26    const caller = await createEthAccountWithBalance(api, web3);27    const receiver = createEthAccount(web3);2829    const alice = privateKey('//Alice');30    const collection = await createCollectionExpectSuccess({31      mode: {type: 'NFT'},32    });33    const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});3435    const address = collectionIdToAddress(collection);36    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});3738    const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));3940    const fee = Number(cost) / Number(UNIQUE);41    const expectedFee = 0.15;42    const tolerance = 0.00001;4344    expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);45  });46});