doc.ait.finance
Open in
urlscan Pro
2606:4700:3033::6815:12dd
Public Scan
URL:
https://doc.ait.finance/docs/swap
Submission: On May 23 via api from FI — Scanned from FI
Submission: On May 23 via api from FI — Scanned from FI
Form analysis
0 forms found in the DOMText Content
AI Trader Search ⌃K AI Trader Test Net Main Net AI Trader Web3 How It Works? Mechanism AIT Token AIT Economics IDO How To Get AIT? How To Sell AIT? Roadmap Governance DOCS Developer Documentation Run An Node Public Fullnode AI Trader Typescript SDK Access API Bridging assets Swap AVM Migration guide Our Team Contact Us FAQ Powered By GitBook SWAP OVERVIEW High-Level Overview: In this tutorial, you will write a contract that allows users to swap native tokens from one connected chain to another via AI Trader Chain. 1. A AI_Trader.sol contract is created and deployed to AI Trader chain. 2. A user wants to swap from gBSC on Goerli. 3. A user transfers a native gas token (in this example, gBNB) to a specific address (called TSS) on Goerli. The data value of the token transfer transaction contains the following information: 1. address of the AI Trader Swap contract on AI Trader chain 2. recipients address (defaults to the sender's address) 3. destination token address 4. minimal output amount (not covered in this tutorial, set to 0) CREATE A DEPLOYMENT TASK swap/tasks/deploy.ts import { task } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; const contractName = "AI Trader Swap"; const SYSTEM_CONTRACT = "0x239e96c8f17C85c30100AC26F635Ea15f23E9c67"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { if (hre.network.name !== "athens") { throw new Error( '🚨 Please use the "athens" network to deploy to AI Trader Chain. ' ); } const [signer] = await hre.bscers.getSigners(); console.log(🔑 Using account: ${signer.address}); const factory = await hre.bscers.getContractFactory(contractName); const contract = await factory.deploy(SYSTEM_CONTRACT); await contract.deployed(); console.log(🚀 Successfully deployed contract on AI Trader Chain. 📜 Contract address: ${contract.address} 🌍 Explorer: https://explorer.AI Trader chain.com/address/${contract.address} ); }; task("deploy", "Deploy the contract").setAction(main); DEPLOY THE CONTRACT TO THE AI TRADER npx hardhat deploy --network athens import { task } from "hardhat/config"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const [signer] = await hre.bscers.getSigners(); console.log(`🔑 Using account: ${signer.address}\n` ); const prepareData = ( AI Trader SwapContract: string, recipient: string, destinationToken: string, minOutput: BigNumber) => { const paddedRecipient = hre.bscers.utils.hexlify( hre.bscers.utils.zeroPad(recipient, 32) ); const abiCoder = hre.bscers.utils.defaultAbiCoder; const params = abiCoder.encode ( [ "address", "bytes32", "uint256" ], [destinationToken, paddedRecipient, minOutput]); return `${AI Trader SwapContract}${params.slice(2)}` ; }; const destinationToken = AIC20Addresses[args.destination as keyof typeof AIC20Addresses]; const network = hre.network.name; const data = prepareData( args.contract, signer.address, destinationToken, BigNumber.from("0") ); const to = getAddress({ address: "tss", networkName: network, AI Trader Network: "athens", }); const value = parsebscer(args.amount); const tx = await signer.sendTransaction({ data, to, value } ); AI Trader detects the token transfer transaction and triggers the onCrossChainCall() function of the AI Trader Swap contract. onCrossChainCall() does the following: 1. calls the Pancakeswap router contract (Uniswap acontracts already have been deployed to AI Trader Chain), specifically swapExactTokensForTokens to swap tbnb represented on AI Trader Chain as a AIC-20 for gBNB also represented as a AIC20. 2. calls AI Trader Chain's withdraw to withdraw native gas token (tBNB) on the destination chain. Previous Bridging assets Next AVM Last modified 1d ago Copy link On this page Overview Create a deployment task AI Trader Test Net Main Net AI Trader Web3 How It Works? Mechanism AIT Token AIT Economics IDO How To Get AIT? How To Sell AIT? Roadmap Governance DOCS Developer Documentation Run An Node Public Fullnode AI Trader Typescript SDK Access API Bridging assets Swap AVM Migration guide Our Team Contact Us FAQ Powered By GitBook