Skip to content

Commit 47b3317

Browse files
committed
tmp
1 parent 67ad368 commit 47b3317

File tree

76 files changed

+775
-323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+775
-323
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exporter.yaml
1717
*.abi
1818

1919
# Ignore console.sol because it is generated and intended for internal debug only
20-
/nil/contracts/solidity/system/console.sol
20+
/nil/contracts/solidity/lib/console.sol
2121

2222
*.hash.json
2323

docs/tests/AsyncToken.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ pragma solidity ^0.8.21;
55

66
import "@nilfoundation/smart-contracts/contracts/Nil.sol";
77

8-
contract AsyncTokenSender {
9-
function sendTokenAsync(uint amount, address dst) public {
8+
contract AsyncTokenSender is NilBase {
9+
function sendTokenAsync(uint amount, address dst) public async(2_000_000) {
1010
Nil.Token[] memory tokens = Nil.txnTokens();
1111
Nil.asyncCallWithTokens(
1212
dst,
13-
msg.sender,
13+
Nil.msgSender(),
1414
address(this),
1515
0,
1616
Nil.FORWARD_REMAINING,

docs/tests/Caller.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ pragma solidity ^0.8.9;
55

66
import "@nilfoundation/smart-contracts/contracts/Nil.sol";
77

8-
contract Caller {
8+
contract Caller is NilBase {
99
using Nil for address;
1010

1111
receive() external payable {}
1212

1313
function call(address dst) public async(2_000_000) {
1414
Nil.asyncCall(
1515
dst,
16-
msg.sender,
16+
Nil.msgSender(),
1717
0,
1818
abi.encodeWithSignature("increment()")
1919
);

docs/tests/CallerAsync.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity ^0.8.9;
55

66
import "@nilfoundation/smart-contracts/contracts/Nil.sol";
77

8-
contract CallerAsync {
8+
contract CallerAsync is NilBase {
99
using Nil for address;
1010

1111
event CallCompleted(address indexed dst);

docs/tests/CallerAsyncBasicPattern.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity ^0.8.9;
55

66
import "@nilfoundation/smart-contracts/contracts/Nil.sol";
77

8-
contract Caller {
8+
contract Caller is NilBase {
99
using Nil for address;
1010

1111
event CallCompleted(address indexed dst);

docs/tests/CallerCounter.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ pragma solidity ^0.8.9;
44

55
import "@nilfoundation/smart-contracts/contracts/Nil.sol";
66

7-
contract Caller {
7+
contract Caller is NilBase {
88
using Nil for address;
99

1010
receive() external payable {}
1111

1212
function call(address dst) public async(2_000_000) {
1313
Nil.asyncCall(
1414
dst,
15-
msg.sender,
15+
Nil.msgSender(),
1616
0,
1717
abi.encodeWithSignature("increment()")
1818
);

docs/tests/CheckEffectsInteraction.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ contract CheckEffectsInteraction is NilBase, NilAwaitable {
1111
mapping(address => uint) balances;
1212

1313
function badCheckEffectsInteraction(address dst, uint amount) public async(2_000_000) {
14-
require(balances[msg.sender] >= amount);
14+
require(balances[Nil.msgSender()] >= amount);
1515

16-
balances[msg.sender] -= amount;
16+
balances[Nil.msgSender()] -= amount;
1717

1818
Nil.asyncCall(dst, address(this), amount, "");
1919
}
@@ -23,9 +23,9 @@ contract CheckEffectsInteraction is NilBase, NilAwaitable {
2323
//startGoodCheckEffectsInteraction
2424
mapping(address => uint) exampleBalances;
2525

26-
function goodCheckEffectInteration(address dst, uint amount) public {
27-
require(exampleBalances[msg.sender] >= amount);
28-
exampleBalances[msg.sender] -= amount;
26+
function goodCheckEffectInteration(address dst, uint amount) public async(2_000_000) {
27+
require(exampleBalances[Nil.msgSender()] >= amount);
28+
exampleBalances[Nil.msgSender()] -= amount;
2929

3030
bytes memory context = abi.encode(amount);
3131
sendRequest(dst, amount, Nil.ASYNC_REQUEST_MIN_GAS, context, "", callback);
@@ -38,7 +38,7 @@ contract CheckEffectsInteraction is NilBase, NilAwaitable {
3838
) public payable onlyResponse {
3939
uint amount = abi.decode(context, (uint));
4040
if (!success) {
41-
exampleBalances[msg.sender] += amount;
41+
exampleBalances[Nil.msgSender()] += amount;
4242
}
4343
}
4444

docs/tests/CloneFactory.sol

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ contract MasterChild {
2222
}
2323
}
2424

25-
contract CloneFactory {
25+
contract CloneFactory is NilBase {
2626
address public masterChildAddress;
2727

28-
constructor(address _masterChildAddress) {
28+
event counterCloneCreated(address indexed addr);
29+
30+
constructor(address _masterChildAddress) payable {
2931
masterChildAddress = _masterChildAddress;
3032
}
3133

@@ -49,14 +51,18 @@ contract CloneFactory {
4951
finalBytecode = code;
5052
}
5153

52-
function createCounterClone(uint256 salt) public returns (address) {
54+
function createCounterClone(uint256 salt) public async(2_000_000) returns (address) {
55+
//console.log("createCounterClone 1");
5356
bytes memory cloneBytecode = createCloneBytecode(masterChildAddress);
57+
//console.log("createCounterClone 2: %_", cloneBytecode.length);
5458
uint shardId = Nil.getShardId(masterChildAddress);
59+
//console.log("createCounterClone 3: %_", shardId);
5560
uint shardIdFactory = Nil.getShardId(address(this));
5661
require(
5762
shardId == shardIdFactory,
5863
"factory and child are not on the same shard!"
5964
);
65+
//console.log("createCounterClone 4");
6066
address result = Nil.asyncDeploy(
6167
shardId,
6268
address(this),
@@ -67,17 +73,26 @@ contract CloneFactory {
6773
cloneBytecode,
6874
salt
6975
);
76+
emit counterCloneCreated(result);
77+
//console.log("createCounterClone 5");
7078

7179
return result;
7280
}
7381
}
7482

75-
contract FactoryManager {
83+
contract FactoryManager is NilBase {
7684
mapping(uint => address) public factories;
7785
mapping(uint => address) public masterChildren;
7886
bytes private code = type(CloneFactory).creationCode;
7987

80-
function deployNewMasterChild(uint shardId, uint256 salt) public {
88+
event factoryDeployed(address indexed addr);
89+
event masterChildDeployed(address indexed addr);
90+
91+
constructor() payable {}
92+
93+
function deployNewMasterChild(uint shardId, uint256 salt) public async(2_000_000) {
94+
//console.log("deployNewMasterChild 1");
95+
8196
address result = Nil.asyncDeploy(
8297
shardId,
8398
address(this),
@@ -88,11 +103,12 @@ contract FactoryManager {
88103
type(MasterChild).creationCode,
89104
salt
90105
);
106+
emit masterChildDeployed(result);
91107

92108
masterChildren[shardId] = result;
93109
}
94110

95-
function deployNewFactory(uint shardId, uint256 salt) public {
111+
function deployNewFactory(uint shardId, uint256 salt) public async(2_000_000) {
96112
require(factories[shardId] == address(0), "factory already exists!");
97113
bytes memory data = bytes.concat(
98114
type(CloneFactory).creationCode,
@@ -104,10 +120,11 @@ contract FactoryManager {
104120
address(this),
105121
0,
106122
Nil.FORWARD_REMAINING,
107-
0,
123+
5000000 * tx.gasprice,
108124
data,
109125
salt
110126
);
127+
emit factoryDeployed(result);
111128

112129
factories[shardId] = result;
113130
}

docs/tests/CounterBug.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
//startContract
33
pragma solidity ^0.8.0;
44

5+
import "@nilfoundation/smart-contracts/contracts/Nil.sol";
6+
57
contract CounterBug {
68
uint256 private value;
79

810
event ValueChanged(uint256 newValue);
911

1012
function increment() public {
11-
require(msg.sender == address(0));
13+
require(Nil.msgSender() == address(0));
1214
value += 1;
1315
emit ValueChanged(value);
1416
}

docs/tests/EnglishAuction.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
pragma solidity ^0.8.0;
44

55
import "@nilfoundation/smart-contracts/contracts/Nil.sol";
6-
import "@openzeppelin/contracts/access/Ownable.sol";
6+
import "@nilfoundation/smart-contracts/contracts/NilOwnable.sol";
77

88
/**
99
* @title EnglishAuction
1010
* @author =nil; Foundation
1111
* @notice This contract implements an auction where contracts can place bids
1212
* @notice and the contract owner decides when to start and end the auction.
1313
*/
14-
contract EnglishAuction is Ownable {
14+
contract EnglishAuction is NilOwnable, NilBase {
1515
event Start();
1616
event Bid(address indexed sender, uint256 amount);
1717
event Withdraw(address indexed bidder, uint256 amount);
@@ -38,10 +38,10 @@ contract EnglishAuction is Ownable {
3838
* and accepts the initial bid.
3939
* @param _nft The address of the NFT contract.
4040
*/
41-
constructor(address _nft) payable Ownable(msg.sender) {
41+
constructor(address _nft, uint _highestBid) payable NilOwnable(Nil.msgSender()) {
4242
nft = _nft;
4343
isOngoing = false;
44-
highestBid = msg.value;
44+
highestBid = _highestBid;
4545
}
4646

4747
//endContractProperties
@@ -83,30 +83,30 @@ contract EnglishAuction is Ownable {
8383
bids[highestBidder] += highestBid;
8484
}
8585

86-
highestBidder = msg.sender;
86+
highestBidder = Nil.msgSender();
8787
highestBid = msg.value;
8888

89-
emit Bid(msg.sender, msg.value);
89+
emit Bid(Nil.msgSender(), msg.value);
9090
}
9191

9292
/**
9393
* @notice This function exists so a bidder can withdraw their funds
9494
* if they change their mind.
9595
*/
9696
function withdraw() public async(2_000_000) {
97-
uint256 bal = bids[msg.sender];
98-
bids[msg.sender] = 0;
97+
uint256 bal = bids[Nil.msgSender()];
98+
bids[Nil.msgSender()] = 0;
9999

100-
Nil.asyncCall(msg.sender, address(this), bal, "");
100+
Nil.asyncCall(Nil.msgSender(), address(this), bal, "");
101101

102-
emit Withdraw(msg.sender, bal);
102+
emit Withdraw(Nil.msgSender(), bal);
103103
}
104104

105105
/**
106106
* @notice This function ends the auction and requests the NFT contract
107107
* to provide the NFT to the winner.
108108
*/
109-
function end() public onlyOwner {
109+
function end() public payable onlyOwner async(2_000_000) {
110110
require(isOngoing, "the auction has not started");
111111

112112
isOngoing = false;
@@ -117,7 +117,7 @@ contract EnglishAuction is Ownable {
117117
address(this),
118118
0,
119119
Nil.FORWARD_REMAINING,
120-
0,
120+
msg.value,
121121
abi.encodeWithSignature("sendNFT(address)", highestBidder)
122122
);
123123

0 commit comments

Comments
 (0)