Part 1: Smart Contracts

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, 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.

Contract Addresses of Fiat24 Cash Tokens (ERC20):

// USD24 Contract
0xbE00f3db78688d9704BCb4e0a827aea3a9Cc0D62
// CHF24 Contract
0xd41F1f0cf89fD239ca4c1F8E8ADA46345c86b0a4
// EUR24 Contract
0x2c5d06f591D0d8cd43Ac232c2B654475a142c7DA

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.

Contract Addresses of Fiat24 NFT (ERC721):

// NFT Contract
0x133CAEecA096cA54889db71956c7f75862Ead7A0

Functions

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:

  1. 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 taken
try {
    owner = await nft.ownerOf(10365);
} catch(err) {
    owner = 0;
}

if(owner == 0) {
    await nft.mintByClient(10365); //called by the end user
}

//or

if(!(await nft.exists(10365))) {
   await nft.mintByClient(10365); //called by the end user
}
  1. 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:

// F24 Token Contract
0x22043fDdF353308B4F2e7dA2e5284E4D087449e1

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 taken
try {
    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);
}

//or

if(!(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:

  1. 2563, which is not a 5-digits-number

  2. 89052, which doesn't start with 1 to 7.

  3. 91023, which doesn't start with 1 to 7.

  4. 562314, which is not a 5-digits-number

2. 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 balances
parseFloat((parseInt(await usd24.balanceOf(address))/100).toFixed(2));
parseFloat((parseInt(await usd24.balanceOfByAccountId(10365))/100).toFixed(2));

3. 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:

  1. Soft-Blocked, the user can receive money only, but can't send/spend anything.

  2. Tourist status as unverifed user

  3. Hard-Blocked, the user can neither send nor receive any money.

  4. Closed. Closed account.

  5. Live. The user is fully verifed as client.

4. 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

5. 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 address
try {
    const tx = await usd24.transfer("0x123456789203123", 10000);
    const receipt = await tx.wait();
} catch(err) {
    console.error(err);
}

or by NFT id.

// JS code to send 200.00 USD24 to NFT id 10365
try {
    const tx = await usd24.transferByAccountId(10365, 20000);
    const receipt = await tx.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.

6. 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.

7. Card Approval

The card payments are booked by the contract Fiat24CardAuthorization at address 0xb5b97338078091cbd1a5b6362eeb625726109449 by the function

function authorize(string memory authorizationId_, string memory cardId_, uint256 tokenId_, address sender_, uint256 amount_)

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 card
try {
    const tx = await eur24.approve('0xb5b97338078091cbd1a5b6362eeb625726109449', 500000);
    const receipt = await tx.wait();
} catch(err) {
    console.error(err);
}

Once the approved amount is used, the approval nees to be repeated.

8. 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 EC-0000001, which can be retrieved from Get Client Profile

// JS code to payout cash (bank wire), withdraw 100.55 CHF
try {
    const tx = await chf24.clientPayout(10055, 'EC-0000001');
    const receipt = await tx.wait();
} catch(err) {
    console.error(err);
}

9. 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.

Here is the details for the integration:

Contract Address

0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F

Swap Ether into Fiat24 Cash Token

function depositETH(address _outputToken) external payable returns(uint256);
// JS code crypto top-up to deposit 0.003 ETH for EUR24
try {
    const tx = await fiat24cryptodeposit.depositETH(EUR24_ADDRESS, {value: "30000000000000000"})
    const receipt = await tx.wait();
} catch(err) {
    console.error(err);
}

Swap ERC20 into Fiat24 Cash Token, through ERC20/USDC Uniswap V3 Pool

function depositTokenViaUsdc(
    address _inputToken
  , address _outputToken
  , uint256 _amount
) external returns(uint256);
// JS code crypto-top to deposit 0.09 GMX for EUR24 via ERC20/USDC
try {
    var tx = await gmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, "90000000000000000");
    var receipt = tx.wait();
    tx = await fiat24cryptodeposit.depositTokenViaUsdc(GMX_ADDRESS, EUR24_ADDRESS, "90000000000000000");
    receipt = await tx.wait();
} catch(err) {
    console.error(err);
}

Swap ERC20 into Fiat24 Cash Token, through ERC20/ETH Uniswap V3 Pool

function depositTokenViaEth(
    address _inputToken
  , address _outputToken
  , uint256 _amount
) external returns(uint256);
// JS code crypto-top to deposit 0.09 GMX for EUR24 via ERC20/ETH/USDC
try {
    var tx = await gmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, "90000000000000000");
    var receipt = tx.wait();
    tx = await fiat24cryptodeposit.depositTokenViaEth(GMX_ADDRESS, EUR24_ADDRESS, "90000000000000000");
    receipt = await tx.wait();
} catch(err) {
    console.error(err);
}

10. 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.

function getExchangeRate(
    address _inputToken
  , address _outputToken
) public view returns(uint256);

Step 2. Executing the transaction

Method 1: You know the amount of currency to sell

function moneyExchangeExactIn(
    address _inputToken
  , address _outputToken
  , uint256 _inputAmount
) external returns(uint256);
// JS code to exchange money 10.00 USD24 for EUR24
try {
    var tx = await usd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, 1000);
    var receipt = tx.wait();
    tx = await fiat24cryptodeposit.moneyExchangeExactIn(USD24_ADDRESS, EUR24_ADDRESS, 1000);
    receipt = tx.wait();
} catch(err) {
    console.error(err);
}

Method 2: You know the amount of currency to buy

function moneyExchangeExactOut(
    address _inputToken
  , address _outputToken
  , uint256 _outputAmount
) external returns(uint256);
// JS code to exchange money EUR24 10.00 for xxx.xx USD24
// 1. Get exchange rate, here USD24/EUR24
const fx_eur24_usd24 = parseInt(await fiat24cryptodeposit.getExchangeRate(EUR24_ADDRESS, USD24_ADDRESS));
// 2. Get reversed spread
const reversespread_usd24_eur24 = parseInt(await fiat24cryptodeposit.getSpread(USD24_ADDRESS, EUR24_ADDRESS, true));
// Get estimated input amount in USD24 for 10.00 EUR
var 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 = await usd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, usd24_input_amount);
    var receipt = tx.wait();
    tx = await fiat24cryptodeposit.moneyExchangeExactOut(USD24_ADDRESS, EUR24_ADDRESS, 1000);
    receipt = tx.wait();
} catch(err) {
    console.error(err);
}

Appendix: A full example:

const ethers = require('ethers');
const fs = require('fs');
const alchemyKey = "<your Alchemy key>";
// private key of user
const userKey = '<the user wallet private key>';
// users wallet address 
const userAddress = '0xC0c8A5B44fa4b5a3dcECC5324cFE23B1A78FcBB8';
// to user address to receive xxx24 payments
const toUserAddress = '0x61Fff28B7115e41E1C537fa7e51352080B7Ff9B8'
// to user accountId (NFT) to receive xxx24 payments
const toUserTokenId = 901;

// FIAT24 addresses (ArbitrumOne)
const FIAT24ACCOUNT_ADDRESS = '0x133CAEecA096cA54889db71956c7f75862Ead7A0';
const USD24_ADDRESS = '0xbE00f3db78688d9704BCb4e0a827aea3a9Cc0D62';
const EUR24_ADDRESS = '0x2c5d06f591D0d8cd43Ac232c2B654475a142c7DA';
const CHF24_ADDRESS = '0xd41F1f0cf89fD239ca4c1F8E8ADA46345c86b0a4';
const FIAT24_CRYPTO_TOP_UP_ADDRESS = '0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F';

// Other contract addresses (ArbitrumOne)
const USDC_ADDRESS = '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8';
const GMX_ADDRESS = '0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a';
const WETH_ADDRESS = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1';




async function fiat24() {
    const provider = new ethers.providers.AlchemyProvider(
        "arbitrum",
        alchemyKey
    );
    const wallet = new ethers.Wallet(userKey, provider);

    
    // F I A T 2 4  A C C O U N T
    const abiFiat24Account = JSON.parse(fs.readFileSync('./contracts/Fiat24Account.json'));
    const fiat24account = new ethers.Contract(FIAT24ACCOUNT_ADDRESS, abiFiat24Account, wallet);
    
    // check availability of Fiat24 account NFT (max. NFT per address = 1)
    const balance = parseInt(await fiat24account.balanceOf(userAddress));
    // if balance = 1, get tokenId of Fiat24 account NFT
    const tokenId =  parseInt(await fiat24account.tokenOfOwnerByIndex(userAddress, 0));
    // get status of Fiat24 account: 0=Na, 1=SoftBlocked, 2=Tourist, 3=Blocked, 4=Closed, 5=Live
    const status = await fiat24account.status(tokenId);
    console.log("balance:", balance);
    console.log("tokenId:", tokenId);
    console.log("status:", status);

    // 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));



    // F I A T 2 4  X X X 2 4  T O K E N  R E A D
    const abiXXX24 = JSON.parse(fs.readFileSync('./contracts/xxx24.json'));
    const usd24 = new ethers.Contract(USD24_ADDRESS, abiXXX24, wallet);

    // get USD24 balance of tokenId
    const usd24Balance = parseFloat((parseInt(await usd24.balanceOfByAccountId(tokenId))/100).toFixed(2));
    console.log("USD24 balance:", usd24Balance);
    // check if tokenTransfer from, to, amount is allowed (various checks: balance, limits, sanctions, etc.)
    const tokenTransferAllowed = await usd24.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 user
    try {
        const tx = await usd24.transferByAccountId(toUserTokenId, 10000);
        const receipt = await tx.wait();
    } catch(err) {
        console.error(err);
    }

    // Cash Payout, send to 9102 USD24 100.00 from user account.
    try {
        const tx = await usd24.transferByAccountId(9102, 10000);
        const receipt = await tx.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 D
    const abiFiat24CryptoDeposit = JSON.parse(fs.readFileSync('./contracts/Fiat24CryptoDeposit.json'));
    const fiat24cryptodeposit = new ethers.Contract(FIAT24_CRYPTO_TOP_UP_ADDRESS, abiFiat24CryptoDeposit, wallet);
    const abiGmx = JSON.parse(fs.readFileSync('./contracts/gmx.json'));
    const gmx = new ethers.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/USDC
    const poolFee = await fiat24cryptodeposit.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 pool
    var poolFee_uniswap = await fiat24cryptodeposit.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/EUR24
    var fx_usd24_eur24 = parseInt(await fiat24cryptodeposit.getExchangeRate(USD24_ADDRESS, EUR24_ADDRESS));
    // 4. Get spread
    var spread_usd24_eur24 = parseInt(await fiat24cryptodeposit.getSpread(USD24_ADDRESS, EUR24_ADDRESS, false));
    // 5. Get fee
    var fee = parseInt(await fiat24cryptodeposit.getFee(tokenId, usdc_amount));
    // 6. Get estimated output amount in EUR24 for 0.09 GMX
    var 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 {
        const tx = await gmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, "90000000000000000");
        const receipt = await tx.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/WETH
    var poolFee_gmx_weth = await fiat24cryptodeposit.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/USDC
    var poolFee_weth_usdc = await fiat24cryptodeposit.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(await fiat24cryptodeposit.getExchangeRate(USD24_ADDRESS, EUR24_ADDRESS));
    // 4. Get spread
    spread_usd24_eur24 = parseInt(await fiat24cryptodeposit.getSpread(USD24_ADDRESS, EUR24_ADDRESS, false));
    // 5. Get fee
    fee = parseInt(await fiat24cryptodeposit.getFee(tokenId, usdc_amount));
    // 6. Get estimated output amount in EUR24 for 0.09 GMX
    var 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 {
        const tx = await gmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, "90000000000000000");
        const receipt = await tx.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/USDC
    var poolFee_weth_usdc = await fiat24cryptodeposit.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/EUR24
    var fx_usd24_eur24 = parseInt(await fiat24cryptodeposit.getExchangeRate(USD24_ADDRESS, EUR24_ADDRESS));
    // 4. Get spread
    var spread_usd24_eur24 = parseInt(await fiat24cryptodeposit.getSpread(USD24_ADDRESS, EUR24_ADDRESS, false));
    // 5. Get fee
    var fee = parseInt(await fiat24cryptodeposit.getFee(tokenId, usdc_amount));
    // 6. Get estimated output amount in EUR24 for 0.003 ETH
    var 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(await fiat24cryptodeposit.getExchangeRate(USD24_ADDRESS, EUR24_ADDRESS));
    // 2. Get spread
    spread_usd24_eur24 = parseInt(await fiat24cryptodeposit.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 {
        const tx = await usd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, 1000);
        const receipt = await tx.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/EUR24
    var fx_eur24_usd24 = parseInt(await fiat24cryptodeposit.getExchangeRate(EUR24_ADDRESS, USD24_ADDRESS));
    // 2. Get reversed spread
    var reversespread_usd24_eur24 = parseInt(await fiat24cryptodeposit.getSpread(USD24_ADDRESS, EUR24_ADDRESS, true));
    // Get estimated input amount in USD24 for 10.00 EUR
    var 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/EUR24
    try {
        var tx = await gmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, "90000000000000000");
        var receipt = tx.wait();
        tx = await fiat24cryptodeposit.depositTokenViaUsdc(GMX_ADDRESS, EUR24_ADDRESS, "90000000000000000");
        receipt = await tx.wait();
    } catch(err) {
        console.error(err);
    }


    // Top-up crypto for xxx24 using depositTokenViaEth(), here GMX/EUR24
    try {
        var tx = await gmx.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, "90000000000000000");
        var receipt = tx.wait();
        const tx = await fiat24cryptodeposit.depositTokenViaEth(GMX_ADDRESS, EUR24_ADDRESS, "90000000000000000");
        const receipt = await tx.wait();
    } catch(err) {
        console.error(err);
    }


    //Top-up ETH for xxx24 using depositETH(), here ETH/EUR24
    try {
        const tx = await fiat24cryptodeposit.depositETH(EUR24_ADDRESS, {value: "30000000000000000"})
        const receipt = await tx.wait();
    } catch(err) {
        console.error(err);
    }
    

    //Exchange money xxx24/xxx24 using moneyExchangeExactIn(), here USD24/EUR24
    try {
        var tx = await usd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, 1000);
        var receipt = tx.wait();
        tx = await fiat24cryptodeposit.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(await fiat24cryptodeposit.getExchangeRate(EUR24_ADDRESS, USD24_ADDRESS));
    // 2. Get reversed spread
    reversespread_usd24_eur24 = parseInt(await fiat24cryptodeposit.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 = await usd24.approve(FIAT24_CRYPTO_TOP_UP_ADDRESS, usd24_input_amount);
        var receipt = tx.wait();
        tx = await fiat24cryptodeposit.moneyExchangeExactOut(USD24_ADDRESS, EUR24_ADDRESS, 1000);
        receipt = tx.wait();
    } catch(err) {
        console.error(err);
    }
}

fiat24();



Last updated

© Fiat24. All rights reserved.