The whole booking system of Fiat24 is managed transparently on the Arbitrum blockchain, which is the mainstream layer 2 rollup solution in Etheruem.
Tokens
Fiat24 users hold Fiat24 Cash Tokens, or USD24/EUR24/CHF24/CNH24, which are ERC20 tokens that is backed one-for-one by cash deposits and available through SR Saphirstein AG (Clearing Number 83051, SWIFT BIC SAHHCHZ2), the Swiss licensed deposit taking institution. The interaction of customers with their respective Fiat24 account takes place can be either from Fiat24 official dApp or from any other native crypto wallets.
Fiat24 uses ERC721 based NFT to represent a Bank Account. If a user owns the NFT in their wallet, the wallet have the control to all Fiat24 services. The id of the NFT represents the account number of Fiat24.
The JS code shown below is implemented using ethers.js.
1. Mint an NFT
Minting a Fiat24 NFT to the user is the first step to go. Wallet provider should generate a random 5-digits number for the user. Before minting it, wallet provider need to check whether the NFT id is taken, otherwise you will get a call error. A successful minting costs gas around 0.08 - 0.13 USD.
We have 2 ways to mint the NFT:
End user mints the NFT
Wallet users call the mintByClient function of the contract to mint the NFT. The NFT id is his/her account number, which maps to the unique Swiss IBAN account. In this approach, user pays the gas cost (0.08 - 0.13 USD).
// check whether the NFT id is takentry { owner =awaitnft.ownerOf(10365);} catch(err) { owner =0;}if(owner ==0) {awaitnft.mintByClient(10365); //called by the end user}//orif(!(awaitnft.exists(10365))) {awaitnft.mintByClient(10365); //called by the end user}
Wallet provider mints the NFT for the user
Wallet provider will choose this approach to enable 2 benefits:
Wallet Provider to issue a customised VISA debit card by Fiat24
Wallet Provider to receive referrer fee (in USDC) in each crypto conversion transaction
With this approach, each wallet provider needs
a Fiat24 business NFT, starting with digit 8 and less than 5 digits. We register that account NFT as wallet provider.
certain amount of F24 token
The F24 token is the ERC20 utility token from Fiat24 ecosystem, the contract address is:
According to the number of digits of the wallet provider NFT (8....), a certain amount of F24 is required to burn. So, an ERC20 F24 approve from the wallet provider address to the contract Fiat24Account is required. Therefore, the wallet provider NFT (8....) holder needs to hold F24 in the account. This function mintByWallet() sets the wallet provider id in the NFT Fiat24Account (NFT number of the wallet provider 8....) which can then be queried from the NFT contract Fiat24Account.
The mintByWallet() must be executed from the holder address of the wallet provider id.
// check whether the NFT id is takentry { owner = await nft.ownerOf(10365);} catch(err) { owner =0;}if(owner ==0) {//called by the wallet provider await f24.approve(0x133CAEecA096cA54889db71956c7f75862Ead7A0,100); await nft.mintByWallet(0xC85251d663E69f6296ED6ca46721e28fA15Cd0B1,10365);}//orif(!(await nft.exists(10365))) {//called by the wallet provider await f24.approve(0x133CAEecA096cA54889db71956c7f75862Ead7A0,100); await nft.mintByWallet(0xC85251d663E69f6296ED6ca46721e28fA15Cd0B1,10365);}
Please only call mintByClient or mintByWallet function with a 5-digits NFT number, and starts with 1..7.
So the following number should NOT be mint:
2563, which is not a 5-digits-number
89052, which doesn't start with 1 to 7.
91023, which doesn't start with 1 to 7.
562314, which is not a 5-digits-number
2. Upgrade to Premium NFT
The wallet provider is limited to minting NFTs with five or more digits for the standard client, who has a restricted transaction volume. To upgrade to a Premium client status, which is represented by an NFT with one to four digits, the user must use F24 tokens for the upgrade.
Typically, upgrading to a four-digit NFT necessitates the burning of 1,500 F24 tokens. The steps for this process are outlined in the script below:
// Check the NFT is still availableif(!(awaitnft.exists(1025))) {//approve the 1500 F24awaitf24.approve(0x133CAEecA096cA54889db71956c7f75862Ead7A0,150000);//upgrade the number and burn F24awaitnft.upgradeWithF24(1025);}
Notice: The function upgradeWithF24(tokenId) is called by client's address, not from wallet provider's address.
3. Get Balances
Retrieve the user's multi-currency account balance accounts. It returns all balance accounts from the address which holds the client NFT.
All Fiat24 cash tokens have decimal of 2.
// JS code to retrieve ERC20 balancesparseFloat((parseInt(awaitusd24.balanceOf(address))/100).toFixed(2));parseFloat((parseInt(awaitusd24.balanceOfByAccountId(10365))/100).toFixed(2));
4. Get Account Status
The user should be informed by their account status from the NFT.
const status = await fiat24account.status(tokenId);
The status number is an integer (1..5) and stands for:
Soft-Blocked, the user can receive money only, but can't send/spend anything.
Tourist status as unverifed user
Hard-Blocked, the user can neither send nor receive any money.
Closed. Closed account.
Live. The user is fully verifed as client.
5. Get 30d transactional limit
Each Fiat24 user will have an overall transactional limit for 30-days rolling basis. This limit value is given by Fiat24 internal risk function from our risk-based evaluation. A standard individual client with low risk profile will get 100,000 CHF (110,000 USD) limit for 30 days.
Partner can read this limit from NFT. Any transaction exceed this limit will throw an error from the smart contract calls.
// get client's 30 day limit numbers const limit = await fiat24account.limit(tokenId);// total 30 days client limit console.log("clientLimit:",parseFloat((limit.clientLimit/100).toFixed(2)));// current used client limit within 30 days console.log("usedLimit",parseFloat((limit.usedLimit/100).toFixed(2)));// start of the 30 days period. After 30 days gets the total 30 days client console.log("startLimitDate",parseInt(limit.startLimitDate));// Some code
6. Make a P2P Payments
Standard ERC20 tokens allow users to transfer money to the recipient or beneficiary directly by an Arbitrum address
// JS code to send 100.00 USD24 to an addresstry {consttx=awaitusd24.transfer("0x123456789203123",10000);constreceipt=awaittx.wait();} catch(err) {console.error(err);}
or by NFT id.
// JS code to send 200.00 USD24 to NFT id 10365try {consttx=awaitusd24.transferByAccountId(10365,20000);constreceipt=awaittx.wait();} catch(err) {console.error(err);}
Notice that Solidity doesn't support decimals, so always use the integer to specify the amount. All Fiat24 cash tokens have 2 decimals, so user the money amount * 100 to represent the solidity amount. For example, if you want to transfer 122.45 USD24, then the parameter in the call will be 12245.
7. Cash Deposit
Cash Deposit booking are managed by Fiat24 internal. Once a user makes a bank deposit, a Cash Deposit booking will be credited from #9101 Cash In Desk.
To calculate the deposit account, please refer the /iban API.
8. Card Approval
The card payments are booked by the contract Fiat24CardAuthorization at address 0xb5b97338078091cbd1a5b6362eeb625726109449 by the function
Therefore, the card owner (address) needs to approve a certain limit amount for future card spendings.
// JS code to approve (from owner address) EUR 5000.00 to spend by cardtry {consttx=awaiteur24.approve('0xb5b97338078091cbd1a5b6362eeb625726109449',500000);constreceipt=awaittx.wait();} catch(err) {console.error(err);}
Once the approved amount is used, the approval nees to be repeated.
9. Cash Payout
Cash Payout is a cash withdrawal transaction to move client's money from Fiat24 account to one of his/her associated bank accounts.
The following code shows how to withdraw 100.55 CHF to user's registered bank account, which has the id of EA-0000001, which can be retrieved from Get Client Profile
NOTE: there is a minimum amount for the payouts, currently the value is set to 10 EUR /CHF. But the value can be found in the minimalPayoutAmount method in the smart contract.
For most regulated trading platforms, such as Securities Borker or Crypto Exchanges, normally the cash in operation must be from the account with the same account holder, together with a Reference, which is given by the platform.
The special method clientPayoutRef() can send EUR or CHF with such reference to specific platforms.
Fiat24 maintains the list of whitelisted platforms, for the value of contactId above.
EUR Payouts
CHF Payouts
10. Crypto Top-up
This function is the main integration point between wallets and Fiat24, it converts the cryptocurrency from the wallet into our fiat holdings, which are in the form of ERC20 tokens (USD24, CHF24 and EUR24) in the Arbitrum network.
The minimal top-up value is 5 USD. If the total token has less than this minimal value, the smart contract call will revert.
The maximal top-up value is 50,000 USD. If the total token has great than this threshold, the smart contract call will revert.
We return 100% of the commission to the wallet provider. The commission is transferred as USDC (https://arbiscan.io/token/0xff970a61a04b1ca14834a43f5de4533ebddb5cc8) to the address of the wallet provider, the same address which is used to call mintByWallet(). The commission is paid by each single top-up transaction, so there won't be any settlement or reconciliation effort for the wallet provider.
// JS code crypto top-up to deposit 0.003 ETH for EUR24try {consttx=awaitfiat24cryptodeposit.depositETH(EUR24_ADDRESS, {value:"30000000000000000"})constreceipt=awaittx.wait();} catch(err) {console.error(err);}
Swap ERC20 into Fiat24 Cash Token, through ERC20/USDC Uniswap V3 Pool
// JS code crypto-top to deposit 0.09 GMX for EUR24 via ERC20/ETH/USDCtry {var tx =awaitgmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS,"90000000000000000");var receipt =tx.wait(); tx =awaitfiat24cryptodeposit.depositTokenViaEth(GMX_ADDRESS,EUR24_ADDRESS,"90000000000000000"); receipt =awaittx.wait();} catch(err) {console.error(err);}
Swap USDC into Fiat24 Cash Token by Wallet Provider
For certain wallet providers, there is a common requirement to convert assets not present on Arbitrum into Fiat24 cash tokens, which can be achieved in two steps.
In the first step, the wallet initiates a cross-chain swap to convert any token (such as Bitcoin or Solana) into USDC on Arbitrum, depositing it into the end-user's address.
The swapped token must specifically be OfficialUSDC on the Arbitrum network.
The second step involves the wallet provider initiating a smart contract call to convert the USDC into a Fiat24 token like EUR24. This action is performed by the wallet provider, requiring no user intervention for the top-up. Thus, from the user's perspective, the entire swap process appears seamless and is effectively completed in a single step.
Here is the smart contract function being called by wallet side:
Wallet Side: The following code will be executed by wallet provider's side.
The message sender (or caller) must hold the wallet provider's NFT.
// JS code crypto-top to deposit 100 USDC for EUR24, called by wallet providertry {var tx =awaitfiat24cryptodeposit.depositByWallet(CLIENT_ADDRESS,EUR24_ADDRESS,"100000000"); receipt =awaittx.wait();} catch(err) {console.error(err);}
11. Money Exchange
Within their Fiat24 account, users have the option of exchanging between the available currencies – i.e. CHF, EUR and USD.
You can exchange the money in either of the following cases:
You know the amount of currency to sell, for example, exchange 100.0 USD to some EUR. Then, specify the input amount to 100 USD.
You know the amount of currency to buy, for example, exchange some USD to 100.0 EUR. Then, specify the output amount to 100 EUR.
Smart Contract Address
0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F
To complete the transfer, follow these two steps:
Step 1. Get the exchange rate
Use the getExchangeRate() function to generate a quote of the exchange rate.
Creating the quote will require the input and output currency tokens' address, the result is the client rate, which the spread is calculated with the inter-bank market rate.
// JS code to exchange money EUR24 10.00 for xxx.xx USD24// 1. Get exchange rate, here USD24/EUR24constfx_eur24_usd24=parseInt(awaitfiat24cryptodeposit.getExchangeRate(EUR24_ADDRESS,USD24_ADDRESS));// 2. Get reversed spreadconstreversespread_usd24_eur24=parseInt(awaitfiat24cryptodeposit.getSpread(USD24_ADDRESS,EUR24_ADDRESS,true));// Get estimated input amount in USD24 for 10.00 EURvar usd24_input_amount =Math.floor((1000*fx_eur24_usd24)/10000);usd24_input_amount =Math.floor((usd24_input_amount*reversespread_usd24_eur24)/10000);try {var tx =awaitusd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, usd24_input_amount);var receipt =tx.wait(); tx =awaitfiat24cryptodeposit.moneyExchangeExactOut(USD24_ADDRESS,EUR24_ADDRESS,1000); receipt =tx.wait();} catch(err) {console.error(err);}
Appendix: A full example:
constethers=require('ethers');constfs=require('fs');constalchemyKey="<your Alchemy key>";// private key of userconstuserKey='<the user wallet private key>';// users wallet address constuserAddress='0xC0c8A5B44fa4b5a3dcECC5324cFE23B1A78FcBB8';// to user address to receive xxx24 paymentsconsttoUserAddress='0x61Fff28B7115e41E1C537fa7e51352080B7Ff9B8'// to user accountId (NFT) to receive xxx24 paymentsconsttoUserTokenId=901;// FIAT24 addresses (ArbitrumOne)constFIAT24ACCOUNT_ADDRESS='0x133CAEecA096cA54889db71956c7f75862Ead7A0';constUSD24_ADDRESS='0xbE00f3db78688d9704BCb4e0a827aea3a9Cc0D62';constEUR24_ADDRESS='0x2c5d06f591D0d8cd43Ac232c2B654475a142c7DA';constCHF24_ADDRESS='0xd41F1f0cf89fD239ca4c1F8E8ADA46345c86b0a4';constFIAT24_CRYPTO_TOP_UP_ADDRESS='0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F';// Other contract addresses (ArbitrumOne)constUSDC_ADDRESS='0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8';constGMX_ADDRESS='0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a';constWETH_ADDRESS='0x82aF49447D8a07e3bd95BD0d56f35241523fBab1';asyncfunctionfiat24() {constprovider=newethers.providers.AlchemyProvider("arbitrum", alchemyKey );constwallet=newethers.Wallet(userKey, provider);// F I A T 2 4 A C C O U N TconstabiFiat24Account=JSON.parse(fs.readFileSync('./contracts/Fiat24Account.json'));constfiat24account=newethers.Contract(FIAT24ACCOUNT_ADDRESS, abiFiat24Account, wallet);// check availability of Fiat24 account NFT (max. NFT per address = 1)constbalance=parseInt(awaitfiat24account.balanceOf(userAddress));// if balance = 1, get tokenId of Fiat24 account NFTconsttokenId=parseInt(awaitfiat24account.tokenOfOwnerByIndex(userAddress,0));// get status of Fiat24 account: 0=Na, 1=SoftBlocked, 2=Tourist, 3=Blocked, 4=Closed, 5=Liveconststatus=awaitfiat24account.status(tokenId);console.log("balance:", balance);console.log("tokenId:", tokenId);console.log("status:", status);// get client's 30 day limit numbers constlimit=awaitfiat24account.limit(tokenId);// total 30 days client limitconsole.log("clientLimit:",parseFloat((limit.clientLimit/100).toFixed(2)));// current used client limit within 30 daysconsole.log("usedLimit",parseFloat((limit.usedLimit/100).toFixed(2)));// start of the 30 days period. After 30 days gets the total 30 days client console.log("startLimitDate",parseInt(limit.startLimitDate));// F I A T 2 4 X X X 2 4 T O K E N R E A DconstabiXXX24=JSON.parse(fs.readFileSync('./contracts/xxx24.json'));constusd24=newethers.Contract(USD24_ADDRESS, abiXXX24, wallet);// get USD24 balance of tokenIdconstusd24Balance=parseFloat((parseInt(awaitusd24.balanceOfByAccountId(tokenId))/100).toFixed(2));console.log("USD24 balance:", usd24Balance);// check if tokenTransfer from, to, amount is allowed (various checks: balance, limits, sanctions, etc.)consttokenTransferAllowed=awaitusd24.tokenTransferAllowed(userAddress, toUserAddress,10000);console.log("tokenTransferAllowed:", tokenTransferAllowed)// F I A T 2 4 X X X 2 4 T O K E N W R I T E// P2P transfer USD24 100.00 from user to another Fiat24 usertry {consttx=awaitusd24.transferByAccountId(toUserTokenId,10000);constreceipt=awaittx.wait(); } catch(err) {console.error(err); }// Cash Payout, send to 9102 USD24 100.00 from user account.try {consttx=awaitusd24.transferByAccountId(9102,10000);constreceipt=awaittx.wait(); } catch(err) {console.error(err); }// F I A T 2 4 C R Y P T O T O P - U P R E A DconstabiFiat24CryptoDeposit=JSON.parse(fs.readFileSync('./contracts/Fiat24CryptoDeposit.json'));constfiat24cryptodeposit=newethers.Contract(FIAT24_CRYPTO_TOP_UP_ADDRESS, abiFiat24CryptoDeposit, wallet);constabiGmx=JSON.parse(fs.readFileSync('./contracts/gmx.json'));constgmx=newethers.Contract(GMX_ADDRESS, abiGmx, wallet);// Get FX rates of Fiat24 Cryto top-up contract const usd_eur = parseFloat(((await fiat24cryptodeposit.getExchangeRate(USD24_ADDRESS, EUR24_ADDRESS))/10000).toFixed(4));
console.log("USD24/EUR24:", usd_eur); const eur_usd = parseFloat(((await fiat24cryptodeposit.getExchangeRate(EUR24_ADDRESS, USD24_ADDRESS))/10000).toFixed(4));
console.log("EUR24/USD24:", eur_usd); const eur_chf = parseFloat(((await fiat24cryptodeposit.getExchangeRate(EUR24_ADDRESS, CHF24_ADDRESS))/10000).toFixed(4));
console.log("EUR24/CHF24:", eur_chf);// Get FX spread of Fiat24 crypto top-up contract for exact in, i.e. // moneyExchangeExactIn(inputToken, outputToken, amount) // or crypto top-up functions depositETH(), depositTokenViaUsdc(), depositTokenViaEth() to convert from USD to EUR,CHF
const spread = parseFloat(((await fiat24cryptodeposit.getSpread(EUR24_ADDRESS, USD24_ADDRESS, false))/10000).toFixed(4));
console.log("spread:", spread);// Get FX reversed spread of Fiat24 crypto top-up contract for exact out, i.e. // moneyExchangeExactOut(inputToken, outputToken, amount) const reversespread = parseFloat(((await fiat24cryptodeposit.getSpread(EUR24_ADDRESS, USD24_ADDRESS, true))/10000).toFixed(4));
console.log("reverse spread:", reversespread);// Get Uniswap pool fee to get the pool address with the most liquidity for a crypto/USDC or WETH/USDC pair,// here the fee of the most liquid pool for GMX/USDCconstpoolFee=awaitfiat24cryptodeposit.getPoolFeeOfMostLiquidPool(GMX_ADDRESS,USDC_ADDRESS);console.log("Uniswap pool fee:", poolFee); // Get Uniswap quote for crypto/USDC, here GMX/USDC. The pool address is identified by inputToken, outputToken and poolFee
const gmx_usdc_quote = parseFloat(((await fiat24cryptodeposit.callStatic.getQuote(GMX_ADDRESS, USDC_ADDRESS, poolFee, "90000000000000000"))/1000000).toFixed(2));
console.log("USDC for 0.09 GMX:",gmx_usdc_quote);// Get the correct xxx24 output amount of a crypto top-up depositTokenViaUsdc(), here GMX/EUR24// 1. Get Uniswap pool fee of most liquid poolvar poolFee_uniswap =awaitfiat24cryptodeposit.getPoolFeeOfMostLiquidPool(GMX_ADDRESS,USDC_ADDRESS);// 2. Get quote for Uniswap GMX/USDC var usdc_amount = Math.floor((await fiat24cryptodeposit.callStatic.getQuote(GMX_ADDRESS, USDC_ADDRESS, poolFee_uniswap, "90000000000000000"))/10000);
// 3. Get exchange rate USD24/EUR24var fx_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getExchangeRate(USD24_ADDRESS,EUR24_ADDRESS));// 4. Get spreadvar spread_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getSpread(USD24_ADDRESS,EUR24_ADDRESS,false));// 5. Get feevar fee =parseInt(awaitfiat24cryptodeposit.getFee(tokenId, usdc_amount));// 6. Get estimated output amount in EUR24 for 0.09 GMXvar eur24_amount =Math.floor((usdc_amount-fee)*fx_usd24_eur24/10000); eur24_amount =Math.floor(eur24_amount*spread_usd24_eur24/10000); eur24_amount =parseFloat((eur24_amount/100).toFixed(2));console.log("EUR24 amount for 0.09 GMX:", eur24_amount);// OR just do a static call of depositTokenViaUsdc()try {consttx=awaitgmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS,"90000000000000000");constreceipt=awaittx.wait(); } catch(err) {console.error(err); } eur24_amount = parseFloat((parseInt(await fiat24cryptodeposit.callStatic.depositTokenViaUsdc(GMX_ADDRESS, EUR24_ADDRESS, "90000000000000000"))/100).toFixed(2));
console.log("EUR24 amount for 0.09 GMX depositTokenViaUsdc() call:", eur24_amount);// Get the correct xxx24 output amount of a crypto top-up depositTokenViaEth(), here GMX/EUR24// 1. Get Uniswap pool fee of most liquid pool for GMX/WETHvar poolFee_gmx_weth =awaitfiat24cryptodeposit.getPoolFeeOfMostLiquidPool(GMX_ADDRESS,WETH_ADDRESS);// 2. Get quote for Uniswap GMX/USDC var weth_amount = await fiat24cryptodeposit.callStatic.getQuote(GMX_ADDRESS, WETH_ADDRESS, poolFee_gmx_weth, "90000000000000000");
// 3. Get Uniswap pool fee of most liquid pool for WETH/USDCvar poolFee_weth_usdc =awaitfiat24cryptodeposit.getPoolFeeOfMostLiquidPool(WETH_ADDRESS,USDC_ADDRESS);// 4. Get quote for Uniswap GMX/USDC usdc_amount = Math.floor((await fiat24cryptodeposit.callStatic.getQuote(WETH_ADDRESS, USDC_ADDRESS, poolFee_weth_usdc, weth_amount))/10000);
// 3. Get exchange rate USD24/EUR24 fx_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getExchangeRate(USD24_ADDRESS,EUR24_ADDRESS));// 4. Get spread spread_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getSpread(USD24_ADDRESS,EUR24_ADDRESS,false));// 5. Get fee fee =parseInt(awaitfiat24cryptodeposit.getFee(tokenId, usdc_amount));// 6. Get estimated output amount in EUR24 for 0.09 GMXvar eur24_amount =Math.floor((usdc_amount-fee)*fx_usd24_eur24/10000); eur24_amount =Math.floor(eur24_amount*spread_usd24_eur24/10000); eur24_amount =parseFloat((eur24_amount/100).toFixed(2));console.log("EUR24 amount for 0.09 GMX:", eur24_amount);// OR just do a static call of depositTokenViaUsdc()try {consttx=awaitgmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS,"90000000000000000");constreceipt=awaittx.wait(); } catch(err) {console.error(err); } eur24_amount = parseFloat((parseInt(await fiat24cryptodeposit.callStatic.depositTokenViaEth(GMX_ADDRESS, EUR24_ADDRESS, "90000000000000000"))/100).toFixed(2));
console.log("EUR24 amount for 0.09 GMX depositTokenViaUsdc() call:", eur24_amount);// Get the correct xxx24 output amount of a crypto top-up depositETH(), here ETH/EUR24// 1. Get Uniswap pool fee of most liquid pool for WETH/USDCvar poolFee_weth_usdc =awaitfiat24cryptodeposit.getPoolFeeOfMostLiquidPool(GMX_ADDRESS,WETH_ADDRESS);// 2. Get quote for Uniswap WETH/USDC usdc_amount = Math.floor(parseInt(await fiat24cryptodeposit.callStatic.getQuote(WETH_ADDRESS, USDC_ADDRESS, poolFee_weth_usdc, "30000000000000000"))/10000);
// 3. Get exchange rate USD24/EUR24var fx_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getExchangeRate(USD24_ADDRESS,EUR24_ADDRESS));// 4. Get spreadvar spread_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getSpread(USD24_ADDRESS,EUR24_ADDRESS,false));// 5. Get feevar fee =parseInt(awaitfiat24cryptodeposit.getFee(tokenId, usdc_amount));// 6. Get estimated output amount in EUR24 for 0.003 ETHvar eur24_amount =Math.floor((usdc_amount-fee)*fx_usd24_eur24/10000); eur24_amount =Math.floor(eur24_amount*spread_usd24_eur24/10000); eur24_amount =parseFloat((eur24_amount/100).toFixed(2));//var eur24_amount = parseFloat(((usdc_amount-fee)*fx_usd24_eur24*spread_usd24_eur24/10000/10000/100).toFixed(2));console.log("EUR24 amount for 0.09 GMX:", eur24_amount);// OR just do a static call of depositETH() eur24_amount = parseFloat((parseInt(await fiat24cryptodeposit.callStatic.depositETH(EUR24_ADDRESS, {value: "30000000000000000"}))/100).toFixed(2));
console.log("EUR24 amount for 0.003 ETH depositETH() call:", eur24_amount);// Get correct xxx24 output amount for money exchange moneExchangeExactIn(), here CHF24/EUR24// 1. Get exchange rate, here USD24/EUR24 fx_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getExchangeRate(USD24_ADDRESS,EUR24_ADDRESS));// 2. Get spread spread_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getSpread(USD24_ADDRESS,EUR24_ADDRESS,false));// 3. Get estimated output amount in EUR24 for 10 USD24 eur24_amount =Math.floor((1000*fx_usd24_eur24)/10000); eur24_amount =Math.floor((eur24_amount*spread_usd24_eur24)/10000); eur24_amount =parseFloat((eur24_amount/100).toFixed(2));console.log("EUR24 amount for 10 USD24:", eur24_amount);//OR just do a static call of moneyExchangeExactIn()try {consttx=awaitusd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS,1000);constreceipt=awaittx.wait(); } catch(err) {console.error(err); } eur24_amount = parseFloat((parseInt(await fiat24cryptodeposit.callStatic.moneyExchangeExactIn(USD24_ADDRESS, EUR24_ADDRESS, 1000))/100).toFixed(2));
console.log("EUR24 amount for 10.00 USD24 moneyExchangeExactIn() call:", eur24_amount);// Get correct xxx24 input amount for money exchange moneyExchangeExactOut(), here EUR24 (output) / USD24 (input)// 1. Get exchange rate, here USD24/EUR24var fx_eur24_usd24 =parseInt(awaitfiat24cryptodeposit.getExchangeRate(EUR24_ADDRESS,USD24_ADDRESS));// 2. Get reversed spreadvar reversespread_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getSpread(USD24_ADDRESS,EUR24_ADDRESS,true));// Get estimated input amount in USD24 for 10.00 EURvar usd24_input_amount =Math.floor((1000*fx_eur24_usd24)/10000); usd24_input_amount =Math.floor((usd24_input_amount*reversespread_usd24_eur24)/10000); usd24_input_amount =parseFloat((usd24_input_amount/100).toFixed(2));console.log("USD24 input amount for 10 EUR24:", usd24_input_amount);// F I A T 2 4 C R Y P T O T O P - U P W R I T E// Top-up crypto for xxx24 using depositTokenViaUsdc(), here GMX/EUR24try {var tx =awaitgmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS,"90000000000000000");var receipt =tx.wait(); tx =awaitfiat24cryptodeposit.depositTokenViaUsdc(GMX_ADDRESS,EUR24_ADDRESS,"90000000000000000"); receipt =awaittx.wait(); } catch(err) {console.error(err); }// Top-up crypto for xxx24 using depositTokenViaEth(), here GMX/EUR24try {var tx =awaitgmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS,"90000000000000000");var receipt =tx.wait();consttx=awaitfiat24cryptodeposit.depositTokenViaEth(GMX_ADDRESS,EUR24_ADDRESS,"90000000000000000");constreceipt=awaittx.wait(); } catch(err) {console.error(err); }//Top-up ETH for xxx24 using depositETH(), here ETH/EUR24try {consttx=awaitfiat24cryptodeposit.depositETH(EUR24_ADDRESS, {value:"30000000000000000"})constreceipt=awaittx.wait(); } catch(err) {console.error(err); }//Exchange money xxx24/xxx24 using moneyExchangeExactIn(), here USD24/EUR24try {var tx =awaitusd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS,1000);var receipt =tx.wait(); tx =awaitfiat24cryptodeposit.moneyExchangeExactIn(USD24_ADDRESS,EUR24_ADDRESS,1000); receipt =tx.wait(); } catch(err) {console.error(err); }//Exchange money xxx24/xxx24 for exact output using moneyExchangeExactIn(), USD24 (input) for 10 EUR24 (output)// 1. Get exchange rate, here USD24/EUR24 fx_eur24_usd24 =parseInt(awaitfiat24cryptodeposit.getExchangeRate(EUR24_ADDRESS,USD24_ADDRESS));// 2. Get reversed spread reversespread_usd24_eur24 =parseInt(awaitfiat24cryptodeposit.getSpread(USD24_ADDRESS,EUR24_ADDRESS,true));// Get estimated input amount in USD24 for 10.00 EUR usd24_input_amount =Math.floor((1000*fx_eur24_usd24)/10000); usd24_input_amount =Math.floor((usd24_input_amount*reversespread_usd24_eur24)/10000);try {var tx =awaitusd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, usd24_input_amount);var receipt =tx.wait(); tx =awaitfiat24cryptodeposit.moneyExchangeExactOut(USD24_ADDRESS,EUR24_ADDRESS,1000); receipt =tx.wait(); } catch(err) {console.error(err); }}fiat24();