The-Poolz / LockDealNFT.DispenserProvider

NFT Dispenser Provider
MIT License
0 stars 1 forks source link

xross chain element #18

Open Lomet opened 1 month ago

Lomet commented 1 month ago

we can use this : https://docs.omni.network/develop/contracts

to have it work cross-chain. for example, when the user clicks refund or withdraw, the token is on Matic and the USD is on BSC. Some flags appear in the other chain. and block the other option.

need to check:

  1. how fast it is ? Will the TX be in limbo for a long time?
  2. how much it cost?

It will add more Defi to the system. and can make part of the backend obsolete.

Lomet commented 1 month ago

this is the part to extend: https://github.com/The-Poolz/LockDealNFT.DispenserProvider/blob/4b37e68d43ff140a681c729d78fbc29ae565c0cb/contracts/DispenserState.sol#L8

idea404 commented 1 month ago

adding answers here too:

how fast it is ? Will the TX be in limbo for a long time?

Omni will support multiple streams for different "completion levels" of messages (finalisation levels).

xmsg (in finalised completion level cross chain message streams) will be relayed once it is finalised in L1. This means typically within one to two epochs and approximately 12.8 minutes (2 epochs x 6.4 minutes). Also means longer if the message comes from a rollup (that posts transactions in batches to L1). In which case the time taken to post the transaction batch to L1 is added to these 12.8 minutes.

xmsg for fastest completion level cross chain message streams will be relayed once they are finalised by the Omni consensus layer (almost instant) at one block after they have been transmitted on the source chain. On Ethereum, this would mean about 12 seconds after they have been transmitted (12 second block time). ⚠️ Warning: these transactions may possibly not be included in the finalised state of the blockchain, and it is the responsibility of your application to deal with this scenario if it makes use of these streams.

how much it cost?

fee for performing an xcall in contract code can be queried by calling feeFor helper function from the XApp helper contract:

uint256 fee = feeFor(
   destChainId,  // destination chain id
   data,         // abi encoded calldata, ex abi.encodeWithSignature("foo()")
   gasLimit      // gas limit to enforce on execution, if omitted uses default gas limit
)

This is the main interface returning the fee required for performing the cross-chain call at any time.

This is implemented as follows (currently, and subject to change):

/// @inheritdoc IFeeOracle
function feeFor(uint64 destChainId, bytes calldata, uint64 gasLimit) external view returns (uint256) {
    require(gasPriceOn[destChainId] > 0 && toNativeRate[destChainId] > 0, "FeeOracleV1: no fee params");
    uint256 gasPrice = gasPriceOn[destChainId] * toNativeRate[destChainId] / CONVERSION_RATE_DENOM;
    return protocolFee + (baseGasLimit * gasPrice) + (gasLimit * gasPrice);
}

protocolFee is currently set to 0 (pre-testnet) and baseGasLimit to 50K gas and gasLimit defaults to 200K gas. Costs should be expected to be at least 250K gas times 12 Gwei (average yearly) gas price, or 0.003 ETH per xmsg if sent from Ethereum (otherwise in other native from source chain). Note: 80% of this fee is attributed to gasLimit which may be override to any other value between 21K and 5M gas, it's best to evaluate gas consumption in testing to set this value to a level that closer resembles to the expected consumption.