Skip to content

Instantly share code, notes, and snippets.

// The 'credits' program.
program my_credits.aleo {
record credits {
owner: address,
gates: u64
}
transition mint(receiver: address, amount: u64) -> credits {
return credits {
@prajwolrg
prajwolrg / acceptResource.sol
Created November 1, 2022 15:03
Accepts the Resource
pragma solidity ^0.8.15;
function _acceptResource(uint256 tokenId, uint256 index) internal {
if (index >= _pendingResources[tokenId].length)
revert RMRKIndexOutOfRange();
uint64 resourceId = _pendingResources[tokenId][index];
_pendingResources[tokenId].removeItemByIndex(index);
uint64 overwrite = _resourceOverwrites[tokenId][resourceId];
if (overwrite != uint64(0)) {
@prajwolrg
prajwolrg / addResourceToToken.sol
Created November 1, 2022 15:00
Add Resource To Token
pragma solidity ^0.8.15;
function _addResourceToToken(
uint256 tokenId,
uint64 resourceId,
uint64 overwrites
) internal {
if (_tokenResources[tokenId][resourceId])
revert RMRKResourceAlreadyExists();
@prajwolrg
prajwolrg / addResourceEntry.sol
Created November 1, 2022 14:58
Add new resource to the NFT
pragma solidity ^0.8.15;
function addResourceEntry(string memory metadataURI)
external
onlyOwnerOrContributor
{
unchecked {
_totalResources += 1;
}
_addResourceEntry(uint64(_totalResources), metadataURI);
@prajwolrg
prajwolrg / addChild.sol
Created November 1, 2022 11:04
Add child
pragma solidity ^0.8.15;
function addChild(uint256 parentTokenId, uint256 childTokenId)
public
virtual
{
_requireMinted(parentTokenId);
if (!_msgSender().isContract()) revert RMRKIsNotContract();
@prajwolrg
prajwolrg / sendToNft.sol
Created November 1, 2022 10:56
Send To NFT
pragma solidity ^0.8.15;
function _sendToNFT(
uint256 tokenId,
uint256 destinationId,
address from,
address to
) private {
IRMRKNesting destContract = IRMRKNesting(to);
destContract.addChild(destinationId, tokenId);
@prajwolrg
prajwolrg / checkForInheritanceLoop.sol
Last active November 1, 2022 10:50
RMRK checkForInheritanceLoop function
pragma solidity ^0.8.15;
uint256 private constant _MAX_LEVELS_TO_CHECK_FOR_INHERITANCE_LOOP = 100;
function _checkForInheritanceLoop(
uint256 currentId,
address targetContract,
uint256 targetId
) private view {
for (uint256 i; i < _MAX_LEVELS_TO_CHECK_FOR_INHERITANCE_LOOP; ) {
@prajwolrg
prajwolrg / nestTransfer.sol
Last active November 1, 2022 08:52
RMRK nestTransfer function
pragma solidity ^0.8.15;
function _nestTransfer(
address from,
address to,
uint256 tokenId,
uint256 destinationId
) internal virtual {
(address immediateOwner, , ) = rmrkOwnerOf(tokenId);
if (immediateOwner != from) revert ERC721TransferFromIncorrectOwner();
pragma solidity >=0.4.21 <0.7.0;
function repay(address _reserve, uint256 _amount)
external
onlyAmountGreaterThanZero(_amount)
{
(, uint256 currentBorrowBalance, , , ) = dataProvider.getUserReserveData(
_reserve,
msg.sender
);
pragma solidity >=0.4.21 <0.7.0;
function redeem(
address _reserve,
address payable _user,
uint256 _amount
) external onlyActiveReserve(_reserve) onlyAmountGreaterThanZero(_amount) {
(
,
,