Skip to content

Commit 9f8410a

Browse files
Merge pull request #557 from qubic/develop (Release v1.261.0)
Release v1.261.0
2 parents fb72ae2 + 48c869d commit 9f8410a

File tree

12 files changed

+735
-217
lines changed

12 files changed

+735
-217
lines changed

.github/workflows/contract-verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
echo "contract-filepaths=$files" >> "$GITHUB_OUTPUT"
3333
- name: Contract verify action step
3434
id: verify
35-
uses: Franziska-Mueller/qubic-contract-verify@v0.3.3-beta
35+
uses: Franziska-Mueller/qubic-contract-verify@v1.0.0
3636
with:
3737
filepaths: '${{ steps.filepaths.outputs.contract-filepaths }}'

doc/contracts.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ After going through this validation process, a contract can be integrated in off
107107

108108
Steps for deploying a contract:
109109

110-
1. Finish development, review, and tests as written above.
110+
1. Finish development, review, and tests as written above. This includes waiting for approval of your PR by the core dev team. If you need to make any significant changes to the code after the computors accepted your proposal, you will need to make a second proposal.
111111
2. A proposal for including your contract into the Qubic Core needs to be prepared.
112112
We recommend to add your proposal description to https://github.com/qubic/proposal/tree/main/SmartContracts via a pull request (this directory also contains files from other contracts added before, which can be used as a template).
113113
The proposal description should include a detailed description of your contract (see point 1 of the [Development section](#development)) and the final source code of the contract.
@@ -635,3 +635,4 @@ The function `castVote()` is a more complex example combining both, calling a co
635635

636636

637637

638+

doc/contributing.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# How to Contribute
22

3+
## Table of contents
4+
5+
1. [Contributing as an external developer](#contributing-as-an-external-developer)
6+
2. [Development workflow / branches](#development-workflow--branches)
7+
3. [Coding guidelines](#coding-guidelines)
8+
1. [Most important principles](#most-important-principles)
9+
2. [General guidelines](#general-guidelines)
10+
3. [Style guidelines](#style-guidelines)
11+
4. [Version naming scheme](#version-naming-scheme)
12+
5. [Profiling](#profiling)
13+
314
## Contributing as an external developer
415

516
If you find bugs, typos, or other problems that can be fixed with a few changes, you are more than welcome to contribute these fixes with a pull request as follows.
@@ -391,3 +402,4 @@ Even when bound by serializing instructions, the system environment at the time
391402

392403
Another rich source: [Intel® 64 and IA-32 Architectures Software Developer's Manual Combined Volumes: 1, 2A, 2B, 2C, 2D, 3A, 3B, 3C, 3D, and 4](https://cdrdv2.intel.com/v1/dl/getContent/671200)
393404

405+

src/contracts/Nostromo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,6 @@ struct NOST : public ContractBase
11471147
{
11481148
// success
11491149
output.transferredNumberOfShares = input.numberOfShares;
1150-
qpi.transfer(id(QX_CONTRACT_INDEX, 0, 0, 0), state.transferRightsFee);
11511150
if (qpi.invocationReward() > state.transferRightsFee)
11521151
{
11531152
qpi.transfer(qpi.invocator(), qpi.invocationReward() - state.transferRightsFee);

src/contracts/Qbay.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,6 @@ struct QBAY : public ContractBase
21712171
{
21722172
// success
21732173
output.transferredNumberOfShares = input.numberOfShares;
2174-
qpi.transfer(id(QX_CONTRACT_INDEX, 0, 0, 0), state.transferRightsFee);
21752174
if (qpi.invocationReward() > state.transferRightsFee)
21762175
{
21772176
qpi.transfer(qpi.invocator(), qpi.invocationReward() - state.transferRightsFee);
@@ -2502,6 +2501,11 @@ struct QBAY : public ContractBase
25022501

25032502
}
25042503

2504+
BEGIN_EPOCH()
2505+
{
2506+
state.transferRightsFee = 100;
2507+
}
2508+
25052509
struct END_EPOCH_locals
25062510
{
25072511
QX::TransferShareManagementRights_input transferShareManagementRights_input;

src/contracts/Qswap.h

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
using namespace QPI;
22

3+
// Log types enum for QSWAP contract
4+
enum QSWAPLogInfo {
5+
QSWAPAddLiquidity = 4,
6+
QSWAPRemoveLiquidity = 5,
7+
QSWAPSwapExactQuForAsset = 6,
8+
QSWAPSwapQuForExactAsset = 7,
9+
QSWAPSwapExactAssetForQu = 8,
10+
QSWAPSwapAssetForExactQu = 9
11+
};
12+
313
// FIXED CONSTANTS
414
constexpr uint64 QSWAP_INITIAL_MAX_POOL = 16384;
515
constexpr uint64 QSWAP_MAX_POOL = QSWAP_INITIAL_MAX_POOL * X_MULTIPLIER;
@@ -12,6 +22,39 @@ struct QSWAP2
1222
{
1323
};
1424

25+
// Logging message structures for QSWAP procedures
26+
struct QSWAPAddLiquidityMessage
27+
{
28+
uint32 _contractIndex;
29+
uint32 _type;
30+
id assetIssuer;
31+
uint64 assetName;
32+
sint64 userIncreaseLiquidity;
33+
sint64 quAmount;
34+
sint64 assetAmount;
35+
sint8 _terminator;
36+
};
37+
38+
struct QSWAPRemoveLiquidityMessage
39+
{
40+
uint32 _contractIndex;
41+
uint32 _type;
42+
sint64 quAmount;
43+
sint64 assetAmount;
44+
sint8 _terminator;
45+
};
46+
47+
struct QSWAPSwapMessage
48+
{
49+
uint32 _contractIndex;
50+
uint32 _type;
51+
id assetIssuer;
52+
uint64 assetName;
53+
sint64 assetAmountIn;
54+
sint64 assetAmountOut;
55+
sint8 _terminator;
56+
};
57+
1558
struct QSWAP : public ContractBase
1659
{
1760
public:
@@ -230,6 +273,17 @@ struct QSWAP : public ContractBase
230273
sint64 assetAmountIn;
231274
};
232275

276+
struct TransferShareManagementRights_input
277+
{
278+
Asset asset;
279+
sint64 numberOfShares;
280+
uint32 newManagingContractIndex;
281+
};
282+
struct TransferShareManagementRights_output
283+
{
284+
sint64 transferredNumberOfShares;
285+
};
286+
233287
protected:
234288
uint32 swapFeeRate; // e.g. 30: 0.3% (base: 10_000)
235289
uint32 teamFeeRate; // e.g. 20: 20% (base: 100)
@@ -895,6 +949,7 @@ struct QSWAP : public ContractBase
895949

896950
struct AddLiquidity_locals
897951
{
952+
QSWAPAddLiquidityMessage addLiquidityMessage;
898953
id poolID;
899954
sint64 poolSlot;
900955
PoolBasicState poolBasicState;
@@ -1210,6 +1265,16 @@ struct QSWAP : public ContractBase
12101265

12111266
state.mPoolBasicStates.set(locals.poolSlot, locals.poolBasicState);
12121267

1268+
// Log AddLiquidity procedure
1269+
locals.addLiquidityMessage._contractIndex = SELF_INDEX;
1270+
locals.addLiquidityMessage._type = QSWAPAddLiquidity;
1271+
locals.addLiquidityMessage.assetIssuer = input.assetIssuer;
1272+
locals.addLiquidityMessage.assetName = input.assetName;
1273+
locals.addLiquidityMessage.userIncreaseLiquidity = output.userIncreaseLiquidity;
1274+
locals.addLiquidityMessage.quAmount = output.quAmount;
1275+
locals.addLiquidityMessage.assetAmount = output.assetAmount;
1276+
LOG_INFO(locals.addLiquidityMessage);
1277+
12131278
if (qpi.invocationReward() > locals.quTransferAmount)
12141279
{
12151280
qpi.transfer(qpi.invocator(), qpi.invocationReward() - locals.quTransferAmount);
@@ -1218,6 +1283,7 @@ struct QSWAP : public ContractBase
12181283

12191284
struct RemoveLiquidity_locals
12201285
{
1286+
QSWAPRemoveLiquidityMessage removeLiquidityMessage;
12211287
id poolID;
12221288
PoolBasicState poolBasicState;
12231289
sint64 userLiquidityElementIndex;
@@ -1346,10 +1412,18 @@ struct QSWAP : public ContractBase
13461412
locals.poolBasicState.reservedAssetAmount -= locals.burnAssetAmount;
13471413

13481414
state.mPoolBasicStates.set(locals.poolSlot, locals.poolBasicState);
1415+
1416+
// Log RemoveLiquidity procedure
1417+
locals.removeLiquidityMessage._contractIndex = SELF_INDEX;
1418+
locals.removeLiquidityMessage._type = QSWAPRemoveLiquidity;
1419+
locals.removeLiquidityMessage.quAmount = output.quAmount;
1420+
locals.removeLiquidityMessage.assetAmount = output.assetAmount;
1421+
LOG_INFO(locals.removeLiquidityMessage);
13491422
}
13501423

13511424
struct SwapExactQuForAsset_locals
13521425
{
1426+
QSWAPSwapMessage swapMessage;
13531427
id poolID;
13541428
sint64 poolSlot;
13551429
sint64 quAmountIn;
@@ -1466,10 +1540,20 @@ struct QSWAP : public ContractBase
14661540
locals.poolBasicState.reservedQuAmount += locals.quAmountIn - sint64(locals.feeToTeam.low) - sint64(locals.feeToProtocol.low);
14671541
locals.poolBasicState.reservedAssetAmount -= locals.assetAmountOut;
14681542
state.mPoolBasicStates.set(locals.poolSlot, locals.poolBasicState);
1543+
1544+
// Log SwapExactQuForAsset procedure
1545+
locals.swapMessage._contractIndex = SELF_INDEX;
1546+
locals.swapMessage._type = QSWAPSwapExactQuForAsset;
1547+
locals.swapMessage.assetIssuer = input.assetIssuer;
1548+
locals.swapMessage.assetName = input.assetName;
1549+
locals.swapMessage.assetAmountIn = locals.quAmountIn;
1550+
locals.swapMessage.assetAmountOut = output.assetAmountOut;
1551+
LOG_INFO(locals.swapMessage);
14691552
}
14701553

14711554
struct SwapQuForExactAsset_locals
14721555
{
1556+
QSWAPSwapMessage swapMessage;
14731557
id poolID;
14741558
sint64 poolSlot;
14751559
PoolBasicState poolBasicState;
@@ -1601,10 +1685,20 @@ struct QSWAP : public ContractBase
16011685
locals.poolBasicState.reservedQuAmount += locals.quAmountIn - sint64(locals.feeToTeam.low) - sint64(locals.feeToProtocol.low);
16021686
locals.poolBasicState.reservedAssetAmount -= input.assetAmountOut;
16031687
state.mPoolBasicStates.set(locals.poolSlot, locals.poolBasicState);
1688+
1689+
// Log SwapQuForExactAsset procedure
1690+
locals.swapMessage._contractIndex = SELF_INDEX;
1691+
locals.swapMessage._type = QSWAPSwapQuForExactAsset;
1692+
locals.swapMessage.assetIssuer = input.assetIssuer;
1693+
locals.swapMessage.assetName = input.assetName;
1694+
locals.swapMessage.assetAmountIn = output.quAmountIn;
1695+
locals.swapMessage.assetAmountOut = input.assetAmountOut;
1696+
LOG_INFO(locals.swapMessage);
16041697
}
16051698

16061699
struct SwapExactAssetForQu_locals
16071700
{
1701+
QSWAPSwapMessage swapMessage;
16081702
id poolID;
16091703
sint64 poolSlot;
16101704
PoolBasicState poolBasicState;
@@ -1755,10 +1849,20 @@ struct QSWAP : public ContractBase
17551849
state.protocolEarnedFee += locals.feeToProtocol.low;
17561850

17571851
state.mPoolBasicStates.set(locals.poolSlot, locals.poolBasicState);
1852+
1853+
// Log SwapExactAssetForQu procedure
1854+
locals.swapMessage._contractIndex = SELF_INDEX;
1855+
locals.swapMessage._type = QSWAPSwapExactAssetForQu;
1856+
locals.swapMessage.assetIssuer = input.assetIssuer;
1857+
locals.swapMessage.assetName = input.assetName;
1858+
locals.swapMessage.assetAmountIn = input.assetAmountIn;
1859+
locals.swapMessage.assetAmountOut = output.quAmountOut;
1860+
LOG_INFO(locals.swapMessage);
17581861
}
17591862

17601863
struct SwapAssetForExactQu_locals
17611864
{
1865+
QSWAPSwapMessage swapMessage;
17621866
id poolID;
17631867
sint64 poolSlot;
17641868
PoolBasicState poolBasicState;
@@ -1903,6 +2007,15 @@ struct QSWAP : public ContractBase
19032007
locals.poolBasicState.reservedQuAmount -= sint64(locals.feeToTeam.low);
19042008
locals.poolBasicState.reservedQuAmount -= sint64(locals.feeToProtocol.low);
19052009
state.mPoolBasicStates.set(locals.poolSlot, locals.poolBasicState);
2010+
2011+
// Log SwapAssetForExactQu procedure
2012+
locals.swapMessage._contractIndex = SELF_INDEX;
2013+
locals.swapMessage._type = QSWAPSwapAssetForExactQu;
2014+
locals.swapMessage.assetIssuer = input.assetIssuer;
2015+
locals.swapMessage.assetName = input.assetName;
2016+
locals.swapMessage.assetAmountIn = output.assetAmountIn;
2017+
locals.swapMessage.assetAmountOut = input.quAmountOut;
2018+
LOG_INFO(locals.swapMessage);
19062019
}
19072020

19082021
struct TransferShareOwnershipAndPossession_locals
@@ -1982,6 +2095,46 @@ struct QSWAP : public ContractBase
19822095
output.success = true;
19832096
}
19842097

2098+
PUBLIC_PROCEDURE(TransferShareManagementRights)
2099+
{
2100+
if (qpi.invocationReward() < QSWAP_FEE_BASE_100)
2101+
{
2102+
return ;
2103+
}
2104+
2105+
if (qpi.numberOfPossessedShares(input.asset.assetName, input.asset.issuer,qpi.invocator(), qpi.invocator(), SELF_INDEX, SELF_INDEX) < input.numberOfShares)
2106+
{
2107+
// not enough shares available
2108+
output.transferredNumberOfShares = 0;
2109+
if (qpi.invocationReward() > 0)
2110+
{
2111+
qpi.transfer(qpi.invocator(), qpi.invocationReward());
2112+
}
2113+
}
2114+
else
2115+
{
2116+
if (qpi.releaseShares(input.asset, qpi.invocator(), qpi.invocator(), input.numberOfShares,
2117+
input.newManagingContractIndex, input.newManagingContractIndex, QSWAP_FEE_BASE_100) < 0)
2118+
{
2119+
// error
2120+
output.transferredNumberOfShares = 0;
2121+
if (qpi.invocationReward() > 0)
2122+
{
2123+
qpi.transfer(qpi.invocator(), qpi.invocationReward());
2124+
}
2125+
}
2126+
else
2127+
{
2128+
// success
2129+
output.transferredNumberOfShares = input.numberOfShares;
2130+
if (qpi.invocationReward() > QSWAP_FEE_BASE_100)
2131+
{
2132+
qpi.transfer(qpi.invocator(), qpi.invocationReward() - QSWAP_FEE_BASE_100);
2133+
}
2134+
}
2135+
}
2136+
}
2137+
19852138
REGISTER_USER_FUNCTIONS_AND_PROCEDURES()
19862139
{
19872140
// functions
@@ -2005,6 +2158,7 @@ struct QSWAP : public ContractBase
20052158
REGISTER_USER_PROCEDURE(SwapExactAssetForQu, 8);
20062159
REGISTER_USER_PROCEDURE(SwapAssetForExactQu, 9);
20072160
REGISTER_USER_PROCEDURE(SetTeamInfo, 10);
2161+
REGISTER_USER_PROCEDURE(TransferShareManagementRights, 11);
20082162
}
20092163

20102164
INITIALIZE()
@@ -2036,4 +2190,8 @@ struct QSWAP : public ContractBase
20362190
}
20372191
}
20382192
}
2193+
PRE_ACQUIRE_SHARES()
2194+
{
2195+
output.allowTransfer = true;
2196+
}
20392197
};

src/logging/logging.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,14 @@ class qLogger
576576
#endif
577577
}
578578

579+
// updateTick is called right after _tick is processed
579580
static void updateTick(unsigned int _tick)
580581
{
581582
#if ENABLED_LOGGING
582583
ASSERT((_tick == lastUpdatedTick + 1) || (_tick == tickBegin));
584+
ASSERT(_tick >= tickBegin);
583585
#if LOG_STATE_DIGEST
584-
unsigned long long index = lastUpdatedTick - tickBegin;
586+
unsigned long long index = _tick - tickBegin;
585587
XKCP::KangarooTwelve_Final(&k12, digests[index].m256i_u8, (const unsigned char*)"", 0);
586588
XKCP::KangarooTwelve_Initialize(&k12, 128, 32); // init new k12
587589
XKCP::KangarooTwelve_Update(&k12, digests[index].m256i_u8, 32); // feed the prev hash back to this

src/public_settings.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
// The tick duration used to calculate the size of memory buffers.
3030
// This determines the memory footprint of the application.
31-
#define TICK_DURATION_FOR_ALLOCATION_MS 500
31+
#define TICK_DURATION_FOR_ALLOCATION_MS 750
3232
#define TRANSACTION_SPARSENESS 1
3333

3434
// Below are 2 variables that are used for auto-F5 feature:
@@ -61,12 +61,12 @@ static_assert(AUTO_FORCE_NEXT_TICK_THRESHOLD* TARGET_TICK_DURATION >= PEER_REFRE
6161
// Config options that should NOT be changed by operators
6262

6363
#define VERSION_A 1
64-
#define VERSION_B 260
64+
#define VERSION_B 261
6565
#define VERSION_C 0
6666

6767
// Epoch and initial tick for node startup
68-
#define EPOCH 179
69-
#define TICK 32742000
68+
#define EPOCH 180
69+
#define TICK 33232000
7070
#define TICK_IS_FIRST_TICK_OF_EPOCH 1 // Set to 0 if the network is restarted during the EPOCH with a new initial TICK
7171

7272
#define ARBITRATOR "AFZPUAIYVPNUYGJRQVLUKOPPVLHAZQTGLYAAUUNBXFTVTAMSBKQBLEIEPCVJ"
@@ -84,7 +84,7 @@ static unsigned short CUSTOM_MINING_V2_CACHE_FILE_NAME[] = L"custom_mining_v2_ca
8484

8585
static constexpr unsigned long long NUMBER_OF_INPUT_NEURONS = 512; // K
8686
static constexpr unsigned long long NUMBER_OF_OUTPUT_NEURONS = 512; // L
87-
static constexpr unsigned long long NUMBER_OF_TICKS = 600; // N
87+
static constexpr unsigned long long NUMBER_OF_TICKS = 1000; // N
8888
static constexpr unsigned long long NUMBER_OF_NEIGHBORS = 728; // 2M. Must be divided by 2
8989
static constexpr unsigned long long NUMBER_OF_MUTATIONS = 150;
9090
static constexpr unsigned long long POPULATION_THRESHOLD = NUMBER_OF_INPUT_NEURONS + NUMBER_OF_OUTPUT_NEURONS + NUMBER_OF_MUTATIONS; // P

0 commit comments

Comments
 (0)