Skip to content
Draft
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: 1 addition & 1 deletion academy/lending-protocol/contracts/LendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract LendingPool is NilBase, NilTokenBase, NilAwaitable {

/// @notice Deposit function to deposit tokens into the lending pool.
/// @dev The deposited tokens are recorded in the GlobalLedger via an asynchronous call.
function deposit() public payable {
function deposit() public payable async(2_000_000) {
/// Retrieve the tokens being sent in the transaction
Nil.Token[] memory tokens = Nil.txnTokens();

Expand Down
2 changes: 1 addition & 1 deletion create-nil-hardhat-project/contracts/Caller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@nilfoundation/smart-contracts/contracts/Nil.sol";
contract Caller {
using Nil for address;

function call(address dst) public {
function call(address dst) public async(500_000) {
Nil.asyncCall(
dst,
msg.sender,
Expand Down
6 changes: 3 additions & 3 deletions docs/tests/AsyncToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ pragma solidity ^0.8.21;

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

contract AsyncTokenSender {
function sendTokenAsync(uint amount, address dst) public {
contract AsyncTokenSender is NilBase {
function sendTokenAsync(uint amount, address dst) public async(2_000_000) {
Nil.Token[] memory tokens = Nil.txnTokens();
Nil.asyncCallWithTokens(
dst,
msg.sender,
Nil.msgSender(),
address(this),
0,
Nil.FORWARD_REMAINING,
Expand Down
6 changes: 3 additions & 3 deletions docs/tests/Caller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ pragma solidity ^0.8.9;

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

contract Caller {
contract Caller is NilBase {
using Nil for address;

receive() external payable {}

function call(address dst) public {
function call(address dst) public async(2_000_000) {
Nil.asyncCall(
dst,
msg.sender,
Nil.msgSender(),
0,
abi.encodeWithSignature("increment()")
);
Expand Down
4 changes: 2 additions & 2 deletions docs/tests/CallerAsync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ pragma solidity ^0.8.9;

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

contract CallerAsync {
contract CallerAsync is NilBase {
using Nil for address;

event CallCompleted(address indexed dst);

function call(address dst) public payable {
function call(address dst) public payable async(2_000_000) {
dst.asyncCall(
address(0),
msg.value,
Expand Down
2 changes: 1 addition & 1 deletion docs/tests/CallerAsyncBasicPattern.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.9;

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

contract Caller {
contract Caller is NilBase {
using Nil for address;

event CallCompleted(address indexed dst);
Expand Down
6 changes: 3 additions & 3 deletions docs/tests/CallerCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity ^0.8.9;

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

contract Caller {
contract Caller is NilBase {
using Nil for address;

receive() external payable {}

function call(address dst) public {
function call(address dst) public async(2_000_000) {
Nil.asyncCall(
dst,
msg.sender,
Nil.msgSender(),
0,
abi.encodeWithSignature("increment()")
);
Expand Down
14 changes: 7 additions & 7 deletions docs/tests/CheckEffectsInteraction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ contract CheckEffectsInteraction is NilBase, NilAwaitable {
//startBadCheckEffectsInteraction
mapping(address => uint) balances;

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

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

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

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

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

Expand Down
24 changes: 17 additions & 7 deletions docs/tests/CloneFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ contract MasterChild {
}
}

contract CloneFactory {
contract CloneFactory is NilBase {
address public masterChildAddress;

constructor(address _masterChildAddress) {
event counterCloneCreated(address indexed addr);

constructor(address _masterChildAddress) payable {
masterChildAddress = _masterChildAddress;
}

Expand All @@ -49,7 +51,7 @@ contract CloneFactory {
finalBytecode = code;
}

function createCounterClone(uint256 salt) public returns (address) {
function createCounterClone(uint256 salt) public async(2_000_000) returns (address) {
bytes memory cloneBytecode = createCloneBytecode(masterChildAddress);
uint shardId = Nil.getShardId(masterChildAddress);
uint shardIdFactory = Nil.getShardId(address(this));
Expand All @@ -67,17 +69,23 @@ contract CloneFactory {
cloneBytecode,
salt
);
emit counterCloneCreated(result);

return result;
}
}

contract FactoryManager {
contract FactoryManager is NilBase {
mapping(uint => address) public factories;
mapping(uint => address) public masterChildren;
bytes private code = type(CloneFactory).creationCode;

function deployNewMasterChild(uint shardId, uint256 salt) public {
event factoryDeployed(address indexed addr);
event masterChildDeployed(address indexed addr);

constructor() payable {}

function deployNewMasterChild(uint shardId, uint256 salt) public async(2_000_000) {
address result = Nil.asyncDeploy(
shardId,
address(this),
Expand All @@ -88,11 +96,12 @@ contract FactoryManager {
type(MasterChild).creationCode,
salt
);
emit masterChildDeployed(result);

masterChildren[shardId] = result;
}

function deployNewFactory(uint shardId, uint256 salt) public {
function deployNewFactory(uint shardId, uint256 salt) public async(2_000_000) {
require(factories[shardId] == address(0), "factory already exists!");
bytes memory data = bytes.concat(
type(CloneFactory).creationCode,
Expand All @@ -104,10 +113,11 @@ contract FactoryManager {
address(this),
0,
Nil.FORWARD_REMAINING,
0,
5000000 * tx.gasprice,
data,
salt
);
emit factoryDeployed(result);

factories[shardId] = result;
}
Expand Down
28 changes: 14 additions & 14 deletions docs/tests/EnglishAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
pragma solidity ^0.8.0;

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

/**
* @title EnglishAuction
* @author =nil; Foundation
* @notice This contract implements an auction where contracts can place bids
* @notice and the contract owner decides when to start and end the auction.
*/
contract EnglishAuction is Ownable {
contract EnglishAuction is NilOwnable, NilBase {
event Start();
event Bid(address indexed sender, uint256 amount);
event Withdraw(address indexed bidder, uint256 amount);
Expand All @@ -38,10 +38,10 @@ contract EnglishAuction is Ownable {
* and accepts the initial bid.
* @param _nft The address of the NFT contract.
*/
constructor(address _nft) payable Ownable(msg.sender) {
constructor(address _nft, uint _highestBid) payable NilOwnable(Nil.msgSender()) {
nft = _nft;
isOngoing = false;
highestBid = msg.value;
highestBid = _highestBid;
}

//endContractProperties
Expand All @@ -50,7 +50,7 @@ contract EnglishAuction is Ownable {
* @notice This function starts the auction and sends a transaction
* for minting the NFT.
*/
function start() public onlyOwner {
function start() public onlyOwner async(2_000_000) {
require(!isOngoing, "the auction has already started");

Nil.asyncCall(
Expand Down Expand Up @@ -83,30 +83,30 @@ contract EnglishAuction is Ownable {
bids[highestBidder] += highestBid;
}

highestBidder = msg.sender;
highestBidder = Nil.msgSender();
highestBid = msg.value;

emit Bid(msg.sender, msg.value);
emit Bid(Nil.msgSender(), msg.value);
}

/**
* @notice This function exists so a bidder can withdraw their funds
* if they change their mind.
*/
function withdraw() public {
uint256 bal = bids[msg.sender];
bids[msg.sender] = 0;
function withdraw() public async(2_000_000) {
uint256 bal = bids[Nil.msgSender()];
bids[Nil.msgSender()] = 0;

Nil.asyncCall(msg.sender, address(this), bal, "");
Nil.asyncCall(Nil.msgSender(), address(this), bal, "");

emit Withdraw(msg.sender, bal);
emit Withdraw(Nil.msgSender(), bal);
}

/**
* @notice This function ends the auction and requests the NFT contract
* to provide the NFT to the winner.
*/
function end() public onlyOwner {
function end() public payable onlyOwner async(2_000_000) {
require(isOngoing, "the auction has not started");

isOngoing = false;
Expand All @@ -117,7 +117,7 @@ contract EnglishAuction is Ownable {
address(this),
0,
Nil.FORWARD_REMAINING,
0,
msg.value,
abi.encodeWithSignature("sendNFT(address)", highestBidder)
);

Expand Down
22 changes: 11 additions & 11 deletions docs/tests/EnglishAuctionPure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
* @notice This contract implements an auction where contracts can place bids
* @notice and the contract owner decides when to start and end the auction.
*/
contract EnglishAuction is Ownable {
contract EnglishAuction is Ownable, NilBase {
event Start();
event Bid(address indexed sender, uint256 amount);
event Withdraw(address indexed bidder, uint256 amount);
Expand All @@ -37,7 +37,7 @@ contract EnglishAuction is Ownable {
* and accepts the initial bid.
* @param _nft The address of the NFT contract.
*/
constructor(address _nft) payable Ownable(msg.sender) {
constructor(address _nft) payable Ownable(Nil.msgSender()) {
nft = _nft;
isOngoing = false;
highestBid = msg.value;
Expand All @@ -47,7 +47,7 @@ contract EnglishAuction is Ownable {
* @notice This function starts the auction and sends a transaction
* for minting the NFT.
*/
function start() public onlyOwner {
function start() public onlyOwner async(2_000_000) {
require(!isOngoing, "the auction has already started");

Nil.asyncCall(
Expand Down Expand Up @@ -79,30 +79,30 @@ contract EnglishAuction is Ownable {
bids[highestBidder] += highestBid;
}

highestBidder = msg.sender;
highestBidder = Nil.msgSender();
highestBid = msg.value;

emit Bid(msg.sender, msg.value);
emit Bid(Nil.msgSender(), msg.value);
}

/**
* @notice This function exists so a bidder can withdraw their funds
* if they change their mind.
*/
function withdraw() public {
uint256 bal = bids[msg.sender];
bids[msg.sender] = 0;
function withdraw() public async(2_000_000) {
uint256 bal = bids[Nil.msgSender()];
bids[Nil.msgSender()] = 0;

Nil.asyncCall(msg.sender, address(this), bal, "");
Nil.asyncCall(Nil.msgSender(), address(this), bal, "");

emit Withdraw(msg.sender, bal);
emit Withdraw(Nil.msgSender(), bal);
}

/**
* @notice This function ends the auction and requests the NFT contract
* to provide the NFT to the winner.
*/
function end() public onlyOwner {
function end() public onlyOwner async(2_000_000) {
require(isOngoing, "the auction has not started");

isOngoing = false;
Expand Down
4 changes: 2 additions & 2 deletions docs/tests/Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ contract Escrow is NilBase, NilAwaitable {
mapping(address => uint256) private deposits;

function deposit() public payable {
deposits[msg.sender] += msg.value;
deposits[Nil.msgSender()] += msg.value;
}

function submitForVerification(
address validator,
address participantOne,
address participantTwo
) public payable {
) public payable async(2_000_000) {
bytes memory context = abi.encode(
participantOne,
participantTwo,
Expand Down
4 changes: 2 additions & 2 deletions docs/tests/EscrowValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ contract Escrow is NilBase, NilAwaitable {
mapping(address => uint256) private deposits;

function deposit() public payable {
deposits[msg.sender] += msg.value;
deposits[Nil.msgSender()] += msg.value;
}

function submitForVerification(
address validator,
address participantOne,
address participantTwo
) public payable {
) public payable async(2_000_000) {
bytes memory context = abi.encode(
participantOne,
participantTwo,
Expand Down
Loading
Loading