Last active
August 12, 2024 12:21
-
-
Save ajtransak/2aa1b64e36837267868ebe5636ec6eb4 to your computer and use it in GitHub Desktop.
Transak Sandbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import Stack from "@mui/material/Stack"; | |
import Box from "@mui/material/Box"; | |
import Button from "@mui/material/Button"; | |
import { Transak } from "@transak/transak-sdk"; | |
import Pusher from "pusher-js"; | |
import { parseUnits } from "@ethersproject/units"; | |
import { Interface, Logger } from "ethers/lib/utils"; | |
import envConfig from "../config"; | |
// Public channel for all transak order events | |
let pusher = new Pusher("1d9ffac87de599c61283", { cluster: "ap2" }); | |
/** | |
* Smart contract address of the partner | |
* Here we are using aave smart contract on polygon | |
* https://mumbai.polygonscan.com/address/0xcC6114B983E4Ed2737E9BD3961c9924e6216c704 | |
* We will use this to deposit funds to protocol | |
*/ | |
const SMART_CONTRACT_ADDRESS = "0xcC6114B983E4Ed2737E9BD3961c9924e6216c704"; | |
/** | |
* The address of the token which smart contract is going to receive | |
* Here we are using WBTC on polygon | |
* Transak will send this token address amount to the smart contract | |
*/ | |
const SOURCE_TOKEN = "0x2Fa2e7a6dEB7bb51B625336DBe1dA23511914a8A"; | |
/** | |
* The address of the user | |
* We will use this address to deposit funds to protocol | |
* CallData needs to be encoded using the ABI for this wallet address | |
*/ | |
const USER_WALLET_ADDRESS = "0xb21CB810816539d8371ef56A2E10731ADAed59DB"; | |
/** | |
* Supply function calldata | |
* We will use this calldata to deposit funds to protocol | |
* Data needs to be encoded using the ABI of the smart contract | |
*/ | |
const getSupplyCalldata = (contributor, amount) => { | |
if (!amount) return; | |
/** | |
* ABI for Supply function on aave SmartContract | |
* You can find ABI of aave contract here | |
* https://mumbai.polygonscan.com/address/0xbadd48c3eb42a10db791d7b02e3c07fbf95b3155#code | |
*/ | |
let ABI = [ | |
{ | |
inputs: [ | |
{ | |
internalType: "contract IPoolAddressesProvider", | |
name: "provider", | |
type: "address", | |
}, | |
], | |
stateMutability: "nonpayable", | |
type: "constructor", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "backer", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "amount", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "fee", | |
type: "uint256", | |
}, | |
], | |
name: "BackUnbacked", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "onBehalfOf", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "amount", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "enum DataTypes.InterestRateMode", | |
name: "interestRateMode", | |
type: "uint8", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "borrowRate", | |
type: "uint256", | |
}, | |
{ | |
indexed: true, | |
internalType: "uint16", | |
name: "referralCode", | |
type: "uint16", | |
}, | |
], | |
name: "Borrow", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "target", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "address", | |
name: "initiator", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "asset", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "amount", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "enum DataTypes.InterestRateMode", | |
name: "interestRateMode", | |
type: "uint8", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "premium", | |
type: "uint256", | |
}, | |
{ | |
indexed: true, | |
internalType: "uint16", | |
name: "referralCode", | |
type: "uint16", | |
}, | |
], | |
name: "FlashLoan", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "asset", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "totalDebt", | |
type: "uint256", | |
}, | |
], | |
name: "IsolationModeTotalDebtUpdated", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "collateralAsset", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "debtAsset", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "debtToCover", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "liquidatedCollateralAmount", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "address", | |
name: "liquidator", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "bool", | |
name: "receiveAToken", | |
type: "bool", | |
}, | |
], | |
name: "LiquidationCall", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "onBehalfOf", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "amount", | |
type: "uint256", | |
}, | |
{ | |
indexed: true, | |
internalType: "uint16", | |
name: "referralCode", | |
type: "uint16", | |
}, | |
], | |
name: "MintUnbacked", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "amountMinted", | |
type: "uint256", | |
}, | |
], | |
name: "MintedToTreasury", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
], | |
name: "RebalanceStableBorrowRate", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "repayer", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "amount", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "bool", | |
name: "useATokens", | |
type: "bool", | |
}, | |
], | |
name: "Repay", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "liquidityRate", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "stableBorrowRate", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "variableBorrowRate", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "liquidityIndex", | |
type: "uint256", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "variableBorrowIndex", | |
type: "uint256", | |
}, | |
], | |
name: "ReserveDataUpdated", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
], | |
name: "ReserveUsedAsCollateralDisabled", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
], | |
name: "ReserveUsedAsCollateralEnabled", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "onBehalfOf", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "amount", | |
type: "uint256", | |
}, | |
{ | |
indexed: true, | |
internalType: "uint16", | |
name: "referralCode", | |
type: "uint16", | |
}, | |
], | |
name: "Supply", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "enum DataTypes.InterestRateMode", | |
name: "interestRateMode", | |
type: "uint8", | |
}, | |
], | |
name: "SwapBorrowRateMode", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
internalType: "uint8", | |
name: "categoryId", | |
type: "uint8", | |
}, | |
], | |
name: "UserEModeSet", | |
type: "event", | |
}, | |
{ | |
anonymous: false, | |
inputs: [ | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "reserve", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
internalType: "address", | |
name: "user", | |
type: "address", | |
}, | |
{ indexed: true, internalType: "address", name: "to", type: "address" }, | |
{ | |
indexed: false, | |
internalType: "uint256", | |
name: "amount", | |
type: "uint256", | |
}, | |
], | |
name: "Withdraw", | |
type: "event", | |
}, | |
{ | |
inputs: [], | |
name: "ADDRESSES_PROVIDER", | |
outputs: [ | |
{ | |
internalType: "contract IPoolAddressesProvider", | |
name: "", | |
type: "address", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "BRIDGE_PROTOCOL_FEE", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "FLASHLOAN_PREMIUM_TOTAL", | |
outputs: [{ internalType: "uint128", name: "", type: "uint128" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "FLASHLOAN_PREMIUM_TO_PROTOCOL", | |
outputs: [{ internalType: "uint128", name: "", type: "uint128" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "MAX_NUMBER_RESERVES", | |
outputs: [{ internalType: "uint16", name: "", type: "uint16" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "MAX_STABLE_RATE_BORROW_SIZE_PERCENT", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "POOL_REVISION", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "uint256", name: "fee", type: "uint256" }, | |
], | |
name: "backUnbacked", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "uint256", name: "interestRateMode", type: "uint256" }, | |
{ internalType: "uint16", name: "referralCode", type: "uint16" }, | |
{ internalType: "address", name: "onBehalfOf", type: "address" }, | |
], | |
name: "borrow", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "uint8", name: "id", type: "uint8" }, | |
{ | |
components: [ | |
{ internalType: "uint16", name: "ltv", type: "uint16" }, | |
{ | |
internalType: "uint16", | |
name: "liquidationThreshold", | |
type: "uint16", | |
}, | |
{ | |
internalType: "uint16", | |
name: "liquidationBonus", | |
type: "uint16", | |
}, | |
{ internalType: "address", name: "priceSource", type: "address" }, | |
{ internalType: "string", name: "label", type: "string" }, | |
], | |
internalType: "struct DataTypes.EModeCategory", | |
name: "category", | |
type: "tuple", | |
}, | |
], | |
name: "configureEModeCategory", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "address", name: "onBehalfOf", type: "address" }, | |
{ internalType: "uint16", name: "referralCode", type: "uint16" }, | |
], | |
name: "deposit", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "asset", type: "address" }], | |
name: "dropReserve", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "address", name: "from", type: "address" }, | |
{ internalType: "address", name: "to", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "uint256", name: "balanceFromBefore", type: "uint256" }, | |
{ internalType: "uint256", name: "balanceToBefore", type: "uint256" }, | |
], | |
name: "finalizeTransfer", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "receiverAddress", type: "address" }, | |
{ internalType: "address[]", name: "assets", type: "address[]" }, | |
{ internalType: "uint256[]", name: "amounts", type: "uint256[]" }, | |
{ | |
internalType: "uint256[]", | |
name: "interestRateModes", | |
type: "uint256[]", | |
}, | |
{ internalType: "address", name: "onBehalfOf", type: "address" }, | |
{ internalType: "bytes", name: "params", type: "bytes" }, | |
{ internalType: "uint16", name: "referralCode", type: "uint16" }, | |
], | |
name: "flashLoan", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "receiverAddress", type: "address" }, | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "bytes", name: "params", type: "bytes" }, | |
{ internalType: "uint16", name: "referralCode", type: "uint16" }, | |
], | |
name: "flashLoanSimple", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "asset", type: "address" }], | |
name: "getConfiguration", | |
outputs: [ | |
{ | |
components: [ | |
{ internalType: "uint256", name: "data", type: "uint256" }, | |
], | |
internalType: "struct DataTypes.ReserveConfigurationMap", | |
name: "", | |
type: "tuple", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "uint8", name: "id", type: "uint8" }], | |
name: "getEModeCategoryData", | |
outputs: [ | |
{ | |
components: [ | |
{ internalType: "uint16", name: "ltv", type: "uint16" }, | |
{ | |
internalType: "uint16", | |
name: "liquidationThreshold", | |
type: "uint16", | |
}, | |
{ | |
internalType: "uint16", | |
name: "liquidationBonus", | |
type: "uint16", | |
}, | |
{ internalType: "address", name: "priceSource", type: "address" }, | |
{ internalType: "string", name: "label", type: "string" }, | |
], | |
internalType: "struct DataTypes.EModeCategory", | |
name: "", | |
type: "tuple", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "uint16", name: "id", type: "uint16" }], | |
name: "getReserveAddressById", | |
outputs: [{ internalType: "address", name: "", type: "address" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "asset", type: "address" }], | |
name: "getReserveData", | |
outputs: [ | |
{ | |
components: [ | |
{ | |
components: [ | |
{ internalType: "uint256", name: "data", type: "uint256" }, | |
], | |
internalType: "struct DataTypes.ReserveConfigurationMap", | |
name: "configuration", | |
type: "tuple", | |
}, | |
{ | |
internalType: "uint128", | |
name: "liquidityIndex", | |
type: "uint128", | |
}, | |
{ | |
internalType: "uint128", | |
name: "currentLiquidityRate", | |
type: "uint128", | |
}, | |
{ | |
internalType: "uint128", | |
name: "variableBorrowIndex", | |
type: "uint128", | |
}, | |
{ | |
internalType: "uint128", | |
name: "currentVariableBorrowRate", | |
type: "uint128", | |
}, | |
{ | |
internalType: "uint128", | |
name: "currentStableBorrowRate", | |
type: "uint128", | |
}, | |
{ | |
internalType: "uint40", | |
name: "lastUpdateTimestamp", | |
type: "uint40", | |
}, | |
{ internalType: "uint16", name: "id", type: "uint16" }, | |
{ internalType: "address", name: "aTokenAddress", type: "address" }, | |
{ | |
internalType: "address", | |
name: "stableDebtTokenAddress", | |
type: "address", | |
}, | |
{ | |
internalType: "address", | |
name: "variableDebtTokenAddress", | |
type: "address", | |
}, | |
{ | |
internalType: "address", | |
name: "interestRateStrategyAddress", | |
type: "address", | |
}, | |
{ | |
internalType: "uint128", | |
name: "accruedToTreasury", | |
type: "uint128", | |
}, | |
{ internalType: "uint128", name: "unbacked", type: "uint128" }, | |
{ | |
internalType: "uint128", | |
name: "isolationModeTotalDebt", | |
type: "uint128", | |
}, | |
], | |
internalType: "struct DataTypes.ReserveData", | |
name: "", | |
type: "tuple", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "asset", type: "address" }], | |
name: "getReserveNormalizedIncome", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "asset", type: "address" }], | |
name: "getReserveNormalizedVariableDebt", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "getReservesList", | |
outputs: [{ internalType: "address[]", name: "", type: "address[]" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "user", type: "address" }], | |
name: "getUserAccountData", | |
outputs: [ | |
{ | |
internalType: "uint256", | |
name: "totalCollateralBase", | |
type: "uint256", | |
}, | |
{ internalType: "uint256", name: "totalDebtBase", type: "uint256" }, | |
{ | |
internalType: "uint256", | |
name: "availableBorrowsBase", | |
type: "uint256", | |
}, | |
{ | |
internalType: "uint256", | |
name: "currentLiquidationThreshold", | |
type: "uint256", | |
}, | |
{ internalType: "uint256", name: "ltv", type: "uint256" }, | |
{ internalType: "uint256", name: "healthFactor", type: "uint256" }, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "user", type: "address" }], | |
name: "getUserConfiguration", | |
outputs: [ | |
{ | |
components: [ | |
{ internalType: "uint256", name: "data", type: "uint256" }, | |
], | |
internalType: "struct DataTypes.UserConfigurationMap", | |
name: "", | |
type: "tuple", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "user", type: "address" }], | |
name: "getUserEMode", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "address", name: "aTokenAddress", type: "address" }, | |
{ internalType: "address", name: "stableDebtAddress", type: "address" }, | |
{ | |
internalType: "address", | |
name: "variableDebtAddress", | |
type: "address", | |
}, | |
{ | |
internalType: "address", | |
name: "interestRateStrategyAddress", | |
type: "address", | |
}, | |
], | |
name: "initReserve", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ | |
internalType: "contract IPoolAddressesProvider", | |
name: "provider", | |
type: "address", | |
}, | |
], | |
name: "initialize", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "collateralAsset", type: "address" }, | |
{ internalType: "address", name: "debtAsset", type: "address" }, | |
{ internalType: "address", name: "user", type: "address" }, | |
{ internalType: "uint256", name: "debtToCover", type: "uint256" }, | |
{ internalType: "bool", name: "receiveAToken", type: "bool" }, | |
], | |
name: "liquidationCall", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address[]", name: "assets", type: "address[]" }, | |
], | |
name: "mintToTreasury", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "address", name: "onBehalfOf", type: "address" }, | |
{ internalType: "uint16", name: "referralCode", type: "uint16" }, | |
], | |
name: "mintUnbacked", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "address", name: "user", type: "address" }, | |
], | |
name: "rebalanceStableBorrowRate", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "uint256", name: "interestRateMode", type: "uint256" }, | |
{ internalType: "address", name: "onBehalfOf", type: "address" }, | |
], | |
name: "repay", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "uint256", name: "interestRateMode", type: "uint256" }, | |
], | |
name: "repayWithATokens", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "uint256", name: "interestRateMode", type: "uint256" }, | |
{ internalType: "address", name: "onBehalfOf", type: "address" }, | |
{ internalType: "uint256", name: "deadline", type: "uint256" }, | |
{ internalType: "uint8", name: "permitV", type: "uint8" }, | |
{ internalType: "bytes32", name: "permitR", type: "bytes32" }, | |
{ internalType: "bytes32", name: "permitS", type: "bytes32" }, | |
], | |
name: "repayWithPermit", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "token", type: "address" }, | |
{ internalType: "address", name: "to", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
], | |
name: "rescueTokens", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "address", name: "asset", type: "address" }], | |
name: "resetIsolationModeTotalDebt", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ | |
components: [ | |
{ internalType: "uint256", name: "data", type: "uint256" }, | |
], | |
internalType: "struct DataTypes.ReserveConfigurationMap", | |
name: "configuration", | |
type: "tuple", | |
}, | |
], | |
name: "setConfiguration", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ | |
internalType: "address", | |
name: "rateStrategyAddress", | |
type: "address", | |
}, | |
], | |
name: "setReserveInterestRateStrategyAddress", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [{ internalType: "uint8", name: "categoryId", type: "uint8" }], | |
name: "setUserEMode", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "bool", name: "useAsCollateral", type: "bool" }, | |
], | |
name: "setUserUseReserveAsCollateral", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "address", name: "onBehalfOf", type: "address" }, | |
{ internalType: "uint16", name: "referralCode", type: "uint16" }, | |
], | |
name: "supply", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "address", name: "onBehalfOf", type: "address" }, | |
{ internalType: "uint16", name: "referralCode", type: "uint16" }, | |
{ internalType: "uint256", name: "deadline", type: "uint256" }, | |
{ internalType: "uint8", name: "permitV", type: "uint8" }, | |
{ internalType: "bytes32", name: "permitR", type: "bytes32" }, | |
{ internalType: "bytes32", name: "permitS", type: "bytes32" }, | |
], | |
name: "supplyWithPermit", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "interestRateMode", type: "uint256" }, | |
], | |
name: "swapBorrowRateMode", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "uint256", name: "protocolFee", type: "uint256" }, | |
], | |
name: "updateBridgeProtocolFee", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ | |
internalType: "uint128", | |
name: "flashLoanPremiumTotal", | |
type: "uint128", | |
}, | |
{ | |
internalType: "uint128", | |
name: "flashLoanPremiumToProtocol", | |
type: "uint128", | |
}, | |
], | |
name: "updateFlashloanPremiums", | |
outputs: [], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ internalType: "address", name: "asset", type: "address" }, | |
{ internalType: "uint256", name: "amount", type: "uint256" }, | |
{ internalType: "address", name: "to", type: "address" }, | |
], | |
name: "withdraw", | |
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
]; | |
let parsedAmmount = parseUnits(amount.toString(), 8); | |
// Constructing the CallData | |
return new Interface(ABI).encodeFunctionData("supply", [ | |
SOURCE_TOKEN, // contract address for WBTC on mumbai testnet | |
parsedAmmount, // amount user wants to buy | |
contributor, // user who is depositing the funds | |
0, // referal code. Will be 0 in case of aave | |
]); | |
}; | |
export default function TransakOne() { | |
const [isTransakInitialized, setTransakInitialized] = useState(false); | |
const initializeTransak = () => { | |
const depositAmount = 0.0008; // amount user wants to deposit to protocol | |
const calldata = getSupplyCalldata( | |
USER_WALLET_ADDRESS, // user wallet address | |
depositAmount // amount user wants to deposit. Transak will convert it to the fiat equivalent and display it to the user | |
); | |
if (!calldata) return; | |
/** | |
* You can find list of all possible Transak config options here | |
* https://docs.transak.com/docs/transak-one-query-parameters | |
*/ | |
const settings = { | |
apiKey: envConfig.apiKeyStagingTransakOne, | |
environment: Transak.ENVIRONMENTS.STAGING, | |
defaultPaymentMethod: "credit_debit_card", | |
/** | |
* Wallet address of the user | |
* The blockchain address of the user's wallet that the receipt token will be sent to. | |
* | |
*/ | |
walletAddress: USER_WALLET_ADDRESS, | |
exchangeScreenTitle: "Deposit Funds", | |
disableWalletAddressForm: true, | |
smartContractAddress: SMART_CONTRACT_ADDRESS, | |
estimatedGasLimit: 70_000, | |
calldata, | |
/** | |
* Details of the token smart contract that is going to be used | |
* in the transaction we are supplying WBTC to Aave protocol | |
* So we are sending WBTC as sourceTokenData along with the amount | |
* we want to deposit on users behalf | |
*/ | |
sourceTokenData: [ | |
{ | |
sourceTokenCode: "WBTC", | |
sourceTokenAmount: depositAmount, | |
}, | |
], | |
/** | |
* Details of the crypto user is going to receive after they do the transaction. | |
* For example if you want to deposit WBTC, you will receive AWBTC in return. | |
* So in this case we are sending AWBTC as cryptoCurrencyData | |
* Along with name and image of the crypto currency. | |
* This will be shown to the user. | |
*/ | |
cryptoCurrencyData: [ | |
{ | |
cryptoCurrencyCode: "AWBTC", | |
cryptoCurrencyName: "Aave Polygon WBTC", | |
cryptoCurrencyImageURL: | |
"https://assets.coingecko.com/coins/images/11734/standard/aWBTC.png", | |
}, | |
], | |
network: "polygon", | |
isTransakOne: true, | |
}; | |
const transak = new Transak(settings); | |
transak.init(); | |
const subscribeToWebsockets = (orderId) => { | |
let channel = pusher.subscribe(orderId); | |
// Receive updates of all the events | |
pusher.bind_global((eventId, orderData) => { | |
console.log(`websocket Event: ${eventId} with order data:`, orderData); | |
}); | |
//receive updates of a specific event | |
channel.bind("ORDER_COMPLETED", (orderData) => { | |
console.log("ORDER COMPLETED websocket event", orderData); | |
}); | |
channel.bind("ORDER_FAILED", async (orderData) => { | |
console.log("ORDER FAILED websocket event", orderData); | |
}); | |
}; | |
Transak.on(Transak.EVENTS.TRANSAK_ORDER_CREATED, (orderData) => { | |
console.log("callback transak order created", orderData); | |
const eventData = orderData; | |
const orderId = eventData.status?.id; | |
if (!orderId) { | |
return; | |
} | |
subscribeToWebsockets(orderId); | |
}); | |
setTransakInitialized(true); | |
}; | |
return ( | |
<Stack direction="column" alignItems="center" sx={{ p: "4px" }}> | |
<Box | |
sx={{ | |
width: "100%", | |
minHeight: "100px", | |
p: "16px", | |
border: "1px dashed grey", | |
}} | |
> | |
<Stack direction="column" justifyContent="center" alignItems="center"> | |
<div | |
style={{ | |
height: "400px", | |
display: "flex", | |
justifyContent: "center", | |
alignItems: "center", | |
flexDirection: "column", | |
}} | |
> | |
<Button variant="contained" onClick={initializeTransak}> | |
Initialize Transak One | |
</Button> | |
</div> | |
</Stack> | |
</Box> | |
</Stack> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment