作成日:2023-03-28 13:32:48,更新日:2024-11-11 22:28:24 更新日:2021-03-28 更新日:2021-01-11 更新日:2021-01-11 更新日:2021-01-11 更新日:2021-01-21 更新日:2021-01-21 更新日:2021-01-21 更新日:2021-01-21 更新日:2021-01-21 更新日:2021-01-21 更新日:2021-01-21 更新日:2021-01-21 更新日:2021-01-21 更新日:2021-01-21
rams,name:params,type:tuple],name:exactInput,outputs:[[internalType:uint256,name:amountOut,type:uint256],stateMutability:payable,type:function},{inputs:[{components:[internalType:params,type:tuple],name:tokenInput,type:address,outputs:[internalType:addaddress,name:amountOutput,type256],stateMutability:payable,type:type:type:type:type:type:type:type:type:type:type:type:type
var abiPool = [\\\inputs\:[],\stateMutability\:\\\nonpayable\,\\\\\type\:\\\constructor\,\\\\\\\\\anonymous\:\false,\\\inputs\:\\\\\\\\indexed\:true,\\\\internalType\:\inputs\:\inputs\:\:\inputs\:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
var abiFactory = [\\inputs\:[],\stateMutability\:\\nonpayable\,\\\\type\:\\\constructor\,\\\\\\anonymous\:\false,\\inputs\:\\\\\indexed\:true,\\internalType\:\uint24\,\\\name\:\\\fee\,\\\type\:\uint24\,\\type\:\type\:\type\:\uint24\:\type\:\uint24\:type\:\uint:type\:\:\uint:type\:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\uanthr:\
契約V3ファクトリー アドレス = 0x1F98431c8aD98523631AE4a59f267346ea31F984
var contractV3SwapRouterV2Address = 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45
function toAmount ((s,小数点) {
返信番号 (大数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数数
{ \ pos (192,220) }
main ((() {の関数について
//Uniswap工場契約のABIを登録する
exchange.IO ((abi, contractV3FactoryAddress, abiFactory) は,このサイトを運営している.
// 注册Uniswap路由合约的ABI
exchange.IO("abi", contractV3SwapRouterV2Address, abiRoute)
// 获取交易对的池地址
var tokenIn = {name : "1INCH", address: "0x111111111117dC0aa78b770fA6A738034120C302", decimals: exchange.IO("api", "0x111111111117dC0aa78b770fA6A738034120C302", "decimals")}
var tokenOut = {name : "WETH", address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", decimals: exchange.IO("api", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "decimals")}
var poolAddress = exchange.IO("api", contractV3FactoryAddress, "getPool", tokenIn.address, tokenOut.address, 10000)
// 注册池合约ABI
exchange.IO("abi", poolAddress, abiPool)
// 获取当前配置的钱包地址
var walletAddress = exchange.IO("address")
// 1INCH -> ETH, tokenIn: 1INCH
var allowanceAmount = exchange.IO("api", tokenIn.address, "allowance", walletAddress, contractV3SwapRouterV2Address)
Log("allowanceAmount:", allowanceAmount, ", 使用toAmount()函数转换为可读数值:", toAmount(allowanceAmount, tokenIn.decimals))
}
对于代码中的```toAmount()```函数我们应该比较熟悉,前几章课程中我们多次使用了这个自定义函数代码,用于把数据处理为方便人类阅读的数值。
```javascript
function toAmount(s, decimals) {
return Number((BigDecimal(BigInt(s)) / BigDecimal(Math.pow(10, decimals))).toString())
}
コードを実行すると,現在のライセンス数が0であることが判明し,交換を行うには,ルーティング契約に十分な数の権限が与えられなければなりません.
許可Uniswap V3
ルート契約
コンピュータが使われていますallowance
検索結果では,ライセンス数が不足していることが判明し,使用する必要があります.approve
許可Uniswap V3
ルーティング契約は,特定の数の操作を許可します.ERC20
トークン.
都市が1INCH -> ETH
交換の例としてERC20
ありがとうございました.approve
方法についてUniswap
ローティング契約は,現在設定されたウォレットで操作する権限を1INCH
トークン.
`ジャバスクリプト
アビルート = [{inputs:[{internalType:address,name:_WETHBYT9,type:address},{internalType:address,type:address},{internalType:address,name:factoryV3,type:address},{internalType:address,name:factoryV3,type:address},{internalType:address,name:positionManager,type:address},{internalType:address,type:address,address,address,address,address,address,address,address,address,address,address,address,
var abiPool = [\\\inputs\:[],\stateMutability\:\\\nonpayable\,\\\\\type\:\\\constructor\,\\\\\\\\\anonymous\:\false,\\\inputs\:\\\\\\\\indexed\:true,\\\\internalType\:\inputs\:\inputs\:\:\inputs\:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n