It is a smart contract written in Solidity to manage offers to exchange assets on INTMAX and other networks. The contract allows users to register new offers and update the taker of an existing offer. The offer can be activated by transferring the taker's asset to the maker in exchange for payment. The contract also includes events for tracking the registration, activation, and deactivation of offers. The function nextOfferId returns the ID of the next offer to be registered.
See also Concept.
Clone this repository.
# use SSH
git clone [email protected]:InternetMaximalism/intmax-interoperability-plugin.git
# or use HTTPS
git clone https://github.com/InternetMaximalism/intmax-interoperability-plugin.git
cd intmax-interoperability-plugin
Setup a local node.
git submodule init
git submodule update
cd contracts
npx hardhat node # port 8545
Open another terminal and return to this repository root. Next, setup environment variables.
cp -n example.env .env
In the .env file, PRIVATE_KEY
is required to deploy the contract.
The code below deploys the contract to the network specified by RPC_URL
,
so the account must have sufficient ETH in advance.
If you use Hardhat node at http://localhost:8545
,
the private key in example.env
may be used without modification.
cd contracts
npx hardhat --network localhost run ./scripts/deploy.ts
The address of the deployed contract can be found here.
Two characters appear below - Mike and Tom. Mike wants to receive tokens on Scroll from Tom instead of sending tokens on INTMAX to Tom.
intmax tx send -a <token-intmax-address> --amount 1 -i 0x00 --receiver-address <network-name>
For example, if you want to make an offer on Scroll Alpha Testnet:
intmax tx send -a 0x98c1fd6f55e2ccee --amount 1 -i 0x00 --receiver-address scroll
Currently supported networks are "scroll" (Scroll Alpha Testnet) and "polygon" (Polygon ZKEVM Testnet).
You must have a sufficient balance yourself to run the above command. You can check your balance with the following command.
intmax account assets
intmax account transaction-proof <tx-hash> <network-name>
Call the register()
function of OfferManager
contract using the witness obtained earlier.
This declares that he will transfer his burned assets to the account that has transferred ETH to him.
OfferManagerV2Interface offerManager;
uint256 offerId = offerManager.register(
makerIntmax,
makerAssetId,
makerAmount,
taker,
takerIntmax,
takerTokenAddress,
takerAmount,
witness
);
It requires:
makerAmount
must be less than or equal toMAX_REMITTANCE_AMOUNT
(about 64 bits).takerTokenAddress
must be a valid address.takerIntmax
must not be zero.- The offer ID must not be already registered.
- The offer must be valid.
- Given witness is valid.
Call the activate()
function of OfferManager
contract.
OfferManagerV2Interface offerManager;
bool success = offerManager.activate{
value: takerAmount
}(offerId);
require(success, "fail to activate offer");
It requires:
- The offer must exist.
- The offer must not be already activated.
- Only the taker can activate it.
- The payment must be equal to or greater than the taker's asset amount.
intmax tx merge
This time we will make an offer from Tom. Tom wants to receive a token on INTMAX from Mike instead of sending a token on Scroll to Mike.
Call the register()
function of OfferManagerReverse
contract.
This declares that he will transfer the locked assets to the account that has transferred the specified token on INTMAX to him.
OfferManagerReverseV2Interface offerManagerReverse;
uint256 offerId = offerManagerReverse.register(
takerIntmaxAddress,
takerTokenAddress,
takerAmount,
maker,
makerAssetId,
makerAmount
);
It requires:
- The offer ID must not be already registered.
makerAmount
must be less than or equal toMAX_REMITTANCE_AMOUNT
(about 64 bits).
ATTENTION: This offer cannot be cancelled.
intmax tx send --amount 1 -i 0x00 --receiver-address <tom-intmax-address>
intmax account transaction-proof <tx-hash> <tom-intmax-address>
The output of this command is "witness".
Call the activate()
function of OfferManagerReverse
contract using the witness obtained earlier.
After that, Mike received Tom's ETH.
OfferManagerReverseV2Interface offerManagerReverse;
bool success = offerManagerReverse.activate(
offerId,
witness
);
require(success, "fail to unlock offer");
It requires:
- The offer must exist.
- The offer must not be already activated.
- Only the maker can activate the offer.
- Given witness is valid.
See sample-auction-app.