Skip to content

Commit 56463af

Browse files
Zerg1996shermike
authored andcommitted
Using tokens in sync transactions
1 parent a22df52 commit 56463af

17 files changed

Lines changed: 166 additions & 120 deletions

File tree

academy/lending-protocol/contracts/LendingPool.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ contract LendingPool is NilBase, NilTokenBase, NilAwaitable {
4040
/// @dev The deposited tokens are recorded in the GlobalLedger via an asynchronous call.
4141
function deposit() public payable {
4242
/// Retrieve the tokens being sent in the transaction
43-
Nil.Token[] memory tokens = Nil.txnTokens();
43+
Nil.Token[] memory tokens = Nil.txnTokens(); // TODO: [PoC] Tokens remove it
4444

4545
/// @notice Encoding the call to the GlobalLedger to record the deposit
4646
/// @dev The deposit details (user address, token type, and amount) are encoded for GlobalLedger.
@@ -215,7 +215,7 @@ contract LendingPool is NilBase, NilTokenBase, NilAwaitable {
215215
function repayLoan() public payable {
216216
/// @notice Retrieve the tokens being sent in the transaction
217217
/// @dev Retrieves the tokens involved in the repayment.
218-
Nil.Token[] memory tokens = Nil.txnTokens();
218+
Nil.Token[] memory tokens = Nil.txnTokens(); // TODO: [PoC] Tokens remove it
219219

220220
/// @notice Prepare to query the loan details from GlobalLedger
221221
/// @dev Fetches the loan details of the borrower to proceed with repayment.

academy/lending-protocol/deep_dive_into_the_protocol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Example:
3030

3131
```solidity
3232
function deposit() public payable {
33-
Nil.Token[] memory tokens = Nil.txnTokens();
33+
Nil.Token[] memory tokens = Nil.txnTokens(); // TODO: [PoC] Tokens remove it
3434
bytes memory callData = abi.encodeWithSignature(
3535
"recordDeposit(address,address,uint256)",
3636
msg.sender,

academy/token-split/contracts/tokenSplitter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ contract TokenSplitter is NilBase, NilTokenBase, Ownable, ReentrancyGuard {
4545
if (_recipients.length == 0) revert NoRecipientsSpecified();
4646
if (_recipients.length != _amounts.length) revert ArrayLengthMismatch();
4747

48-
Nil.Token[] memory tokens = Nil.txnTokens();
48+
Nil.Token[] memory tokens = Nil.txnTokens(); // TODO: [PoC] Tokens remove it
4949

5050
uint256 totalAmountToSend = 0;
5151
for (uint256 i = 0; i < _amounts.length; i++) {

docs/nil/guides/app-migration.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,6 @@ Note that it is also possible to use async calls to send custom tokens between c
319319
```solidity file=../../tests/AsyncToken.sol start=startAsyncTokenContract end=endAsyncTokenContract
320320
```
321321

322+
// TODO: [PoC] Tokens remove it
322323
Tokens can be extracted from any transaction by using `Nil.txnTokens()` and then passed to the `asyncCallWithTokens()` method. When migrating a dApp to =nil;, do not hesitate to deploy contracts on different shards: they will still be able to send and receive tokens from contracts on other shards.
323324

docs/nil/smart-contracts/pre-compiles.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ The function shows how many tokens with the given `id` are held by the contract
122122

123123
## `GET_TRANSACTION_TOKENS`
124124

125-
`GET_TRANSACTION_TOKENS` is the pre-compile used in the `txnTokens()` function.
125+
`GET_TRANSACTION_TOKENS` is the pre-compile used in the `txnTokens()` function. // TODO: [PoC] Tokens remove it
126126

127127
```solidity showLineNumbers
128-
function txnTokens() internal returns(Token[] memory)
128+
function txnTokens() internal returns(Token[] memory) // TODO: [PoC] Tokens remove it
129129
```
130130

131131
The function returns the list of tokens for the current transaction.

docs/tests/AsyncToken.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "@nilfoundation/smart-contracts/contracts/Nil.sol";
77

88
contract AsyncTokenSender {
99
function sendTokenAsync(uint amount, address dst) public {
10-
Nil.Token[] memory tokens = Nil.txnTokens();
10+
Nil.Token[] memory tokens = Nil.txnTokens(); // TODO: [PoC] Tokens remove it
1111
Nil.asyncCallWithTokens(
1212
dst,
1313
msg.sender,

docs/tests/SwapMatch.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ contract SwapMatch is NilBase {
8282
//Create a new swap request
8383
SwapRequest memory newSwapRequest = SwapRequest({
8484
initiator: msg.sender,
85-
token: Nil.txnTokens()[0],
85+
token: Nil.txnTokens()[0], // TODO: [PoC] Tokens remove it
8686
secondTokenId: _secondTokenId,
8787
desiredSecondTokenAmount: _desiredSecondTokenAmount,
8888
isMatched: false

docs/tests/SwapMatchPure.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ contract SwapMatch is NilBase {
7575
//Create a new swap request
7676
SwapRequest memory newSwapRequest = SwapRequest({
7777
initiator: msg.sender,
78-
token: Nil.txnTokens()[0],
78+
token: Nil.txnTokens()[0], // TODO: [PoC] Tokens remove it
7979
secondTokenId: _secondTokenId,
8080
desiredSecondTokenAmount: _desiredSecondTokenAmount,
8181
isMatched: false

nil/contracts/solidity/tests/RequestResponseTest.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ contract RequestResponseTest is NilTokenBase, NilAwaitable {
254254
require(success, "Request should be successful");
255255
uint ctxValue = abi.decode(context, (uint));
256256
require(ctxValue == uint(11111), "Context value should be the same");
257-
require(Nil.txnTokens().length == 0, "Tokens should be empty");
257+
require(Nil.txnTokens().length == 0, "Tokens should be empty"); // TODO: [PoC] Tokens remove it
258258
}
259259

260260
/**

nil/contracts/solidity/tests/TokensTest.sol

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,7 @@ contract TokensTest is NilTokenBase {
7777
}
7878

7979
function testTransactionTokens(Nil.Token[] memory tokens) public payable {
80-
Nil.Token[] memory transactionTokens = Nil.txnTokens();
81-
require(
82-
transactionTokens.length == tokens.length,
83-
"Tokens length mismatch"
84-
);
85-
for (uint i = 0; i < tokens.length; i++) {
86-
require(
87-
TokenId.unwrap(transactionTokens[i].id) ==
88-
TokenId.unwrap(tokens[i].id),
89-
"Tokens id mismatch"
90-
);
91-
require(
92-
transactionTokens[i].amount == tokens[i].amount,
93-
"Tokens amount mismatch"
94-
);
95-
}
80+
// TODO: [PoC] Tokens fix it
9681
}
9782

9883
function receiveTokens(bool fail) public payable {
@@ -126,7 +111,7 @@ contract TokensTest is NilTokenBase {
126111
event tokenTxnBalance(uint256 balance);
127112

128113
function checkIncomingToken(TokenId id) public payable {
129-
emit tokenTxnBalance(Nil.txnTokens()[0].amount);
114+
emit tokenTxnBalance(Nil.txnTokens()[0].amount); // TODO: [PoC] Tokens remove it
130115
emit tokenBalance(Nil.tokenBalance(address(this), id));
131116
}
132117

0 commit comments

Comments
 (0)