Skip to content

Commit

Permalink
feat: token linker with gas service (#8)
Browse files Browse the repository at this point in the history
* feature(token-linking): adding the gas service

* feature(token-linker): renaming contracts

* chore(build): removing interface copying from the artifacts

* chore(dist): removing dist from git

* chore(ignore): git and npm

* feature(linkers): support for refund address

* fix(workflow): test after build

* fix(Linkers): constant CONTRACT_ID for Upgradable
  • Loading branch information
re1ro authored Aug 26, 2022
1 parent c3c9905 commit 87d2524
Show file tree
Hide file tree
Showing 23 changed files with 563 additions and 429 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ jobs:
- name: Install Dependencies
run: npm ci

- name: Build
run: npm run build

- name: Test
run: npm run test
121 changes: 119 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,121 @@
node_modules
artifacts
typechain
examples/metamask/chain*.json
examples/metamask/abi/**.json
**/.DS_Store
./test.js
./quick.json
local.json
temp.js
temp2.js

#Hardhat files
cache
build

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
coverage.json
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Build
artifacts
22 changes: 22 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Modules
node_modules

# dotenv environment variables file
.env
.env.test
env
.credentials
credentials

# Logs
logs
*.log

# Optional npm cache directory
.npm

# builder cache
.cache

# workflows
.github
60 changes: 60 additions & 0 deletions contracts/nft-linker/NftLinkerBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { IAxelarGateway } from '../interfaces/IAxelarGateway.sol';
import { IAxelarGasService } from '../interfaces/IAxelarGasService.sol';
import { AxelarExecutable } from '../executables/AxelarExecutable.sol';
import { AddressToString, StringToAddress } from '../StringAddressUtils.sol';
import { Upgradable } from '../upgradables/Upgradable.sol';

abstract contract NftLinkerBase is AxelarExecutable, Upgradable {
using StringToAddress for string;
using AddressToString for address;

bytes32 internal constant CONTRACT_ID = keccak256('nft-linker');
IAxelarGasService public immutable gasService;

constructor(address gatewayAddress, address gasServiceAddress_) AxelarExecutable(gatewayAddress) {
gasService = IAxelarGasService(gasServiceAddress_);
}

function contractId() external pure override returns (bytes32) {
return CONTRACT_ID;
}

function sendNft(
string memory destinationChain,
address to,
uint256 tokenId,
address refundAddress
) external payable virtual {
string memory thisAddress = address(this).toString();
_takeNft(msg.sender, tokenId);
bytes memory payload = abi.encode(to, tokenId);
if (msg.value > 0) {
gasService.payNativeGasForContractCall{ value: msg.value }(
address(this),
destinationChain,
thisAddress,
payload,
refundAddress
);
}
gateway.callContract(destinationChain, thisAddress, payload);
}

function _execute(
string calldata, /*sourceChain*/
string calldata sourceAddress,
bytes calldata payload
) internal override {
if (sourceAddress.toAddress() != address(this)) return;
(address recipient, uint256 tokenId) = abi.decode(payload, (address, uint256));
_giveNft(recipient, tokenId);
}

function _giveNft(address to, uint256 tokenId) internal virtual;

function _takeNft(address from, uint256 tokenId) internal virtual;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
pragma solidity ^0.8.0;

import { IERC721 } from '../interfaces/IERC721.sol';
import { NftLinker } from './NftLinker.sol';
import { NftLinkerBase } from './NftLinkerBase.sol';

contract NftLinkerLockUnlock is NftLinker {
contract NftLinkerLockUnlock is NftLinkerBase {
error TransferFailed();
error TransferFromFailed();

address public immutable operatorAddress;

constructor(address gatewayAddress_, address operatorAddress_) NftLinker(gatewayAddress_) {
constructor(
address gatewayAddress_,
address gasServiceAddress_,
address operatorAddress_
) NftLinkerBase(gatewayAddress_, gasServiceAddress_) {
operatorAddress = operatorAddress_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
pragma solidity ^0.8.0;

import { IERC721MintableBurnable } from '../interfaces/IERC721MintableBurnable.sol';
import { NftLinker } from './NftLinker.sol';
import { NftLinkerBase } from './NftLinkerBase.sol';

contract NftLinkerMintBurn is NftLinker {
contract NftLinkerMintBurn is NftLinkerBase {
error TransferFailed();
error TransferFromFailed();

address public immutable operatorAddress;

constructor(address gatewayAddress_, address operatorAddress_) NftLinker(gatewayAddress_) {
constructor(
address gatewayAddress_,
address gasServiceAddress_,
address operatorAddress_
) NftLinkerBase(gatewayAddress_, gasServiceAddress_) {
operatorAddress = operatorAddress_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ pragma solidity ^0.8.0;
import { Proxy } from '../upgradables/Proxy.sol';

contract NftLinkerProxy is Proxy {
bytes32 internal constant CONTRACT_ID = keccak256('nft-linker');

function contractId() internal pure override returns (bytes32) {
return keccak256('nft-linker');
return CONTRACT_ID;
}

receive() external payable override {}
Expand Down
32 changes: 0 additions & 32 deletions contracts/nft-linking/NftLinker.sol

This file was deleted.

Loading

0 comments on commit 87d2524

Please sign in to comment.